mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +00:00
修复Bar在同一个Chart不同Grid里时绘制有些异常的问题
This commit is contained in:
@@ -79,6 +79,7 @@ slug: /changelog
|
||||
|
||||
## master
|
||||
|
||||
* (2025.03.09) 修复`Bar`在同一个`Chart`不同`Grid`里时绘制有些异常的问题
|
||||
* (2025.03.07) 增加`Animation`的`speed`可指定动画速度
|
||||
* (2025.03.06) 优化`Animation`的新增动画表现
|
||||
* (2025.03.04) 修复`Treemap`的`label`显示异常的问题
|
||||
|
||||
@@ -851,7 +851,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public float GetSerieBarGap<T>() where T : Serie
|
||||
public float GetSerieBarGap<T>(int gridIndex) where T : Serie
|
||||
{
|
||||
float gap = 0f;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
@@ -859,6 +859,7 @@ namespace XCharts.Runtime
|
||||
var serie = m_Series[i];
|
||||
if (serie.show && serie is T)
|
||||
{
|
||||
if (!CheckSerieGridIndex(serie, gridIndex)) continue;
|
||||
if (serie.barGap != 0)
|
||||
{
|
||||
gap = serie.barGap;
|
||||
@@ -868,7 +869,7 @@ namespace XCharts.Runtime
|
||||
return gap;
|
||||
}
|
||||
|
||||
public double GetSerieSameStackTotalValue<T>(string stack, int dataIndex) where T : Serie
|
||||
public double GetSerieSameStackTotalValue<T>(string stack, int dataIndex, int gridIndex) where T : Serie
|
||||
{
|
||||
if (string.IsNullOrEmpty(stack)) return 0;
|
||||
double total = 0;
|
||||
@@ -876,6 +877,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (serie is T)
|
||||
{
|
||||
if (!CheckSerieGridIndex(serie, gridIndex)) continue;
|
||||
if (stack.Equals(serie.stack))
|
||||
{
|
||||
total += serie.data[dataIndex].data[1];
|
||||
@@ -885,7 +887,7 @@ namespace XCharts.Runtime
|
||||
return total;
|
||||
}
|
||||
|
||||
public int GetSerieBarRealCount<T>() where T : Serie
|
||||
public int GetSerieBarRealCount<T>(int gridIndex) where T : Serie
|
||||
{
|
||||
var count = 0;
|
||||
barStackSet.Clear();
|
||||
@@ -895,6 +897,7 @@ namespace XCharts.Runtime
|
||||
if (!serie.show) continue;
|
||||
if (serie is T)
|
||||
{
|
||||
if (!CheckSerieGridIndex(serie, gridIndex)) continue;
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (barStackSet.Contains(serie.stack)) continue;
|
||||
@@ -907,8 +910,26 @@ namespace XCharts.Runtime
|
||||
return count;
|
||||
}
|
||||
|
||||
private bool CheckSerieGridIndex(Serie serie, int gridIndex)
|
||||
{
|
||||
if (gridIndex >= 0)
|
||||
{
|
||||
if (serie.xAxisIndex >= 0 && serie.xAxisIndex < m_XAxes.Count)
|
||||
{
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
if (xAxis.gridIndex != gridIndex) return false;
|
||||
}
|
||||
if (serie.yAxisIndex >= 0 && serie.yAxisIndex < m_YAxes.Count)
|
||||
{
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
if (yAxis.gridIndex != gridIndex) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private HashSet<string> barStackSet = new HashSet<string>();
|
||||
public float GetSerieTotalWidth<T>(float categoryWidth, float gap, int realBarCount) where T : Serie
|
||||
public float GetSerieTotalWidth<T>(float categoryWidth, float gap, int realBarCount, int gridIndex) where T : Serie
|
||||
{
|
||||
float total = 0;
|
||||
float lastGap = 0;
|
||||
@@ -919,6 +940,7 @@ namespace XCharts.Runtime
|
||||
if (!serie.show) continue;
|
||||
if (serie is T)
|
||||
{
|
||||
if (!CheckSerieGridIndex(serie, gridIndex)) continue;
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (barStackSet.Contains(serie.stack)) continue;
|
||||
@@ -941,12 +963,12 @@ namespace XCharts.Runtime
|
||||
return total;
|
||||
}
|
||||
|
||||
public float GetSerieTotalGap<T>(float categoryWidth, float gap, int index) where T : Serie
|
||||
public float GetSerieTotalGap<T>(float categoryWidth, float gap, int index, int gridIndex) where T : Serie
|
||||
{
|
||||
if (index <= 0) return 0;
|
||||
var total = 0f;
|
||||
var count = 0;
|
||||
var totalRealBarCount = GetSerieBarRealCount<T>();
|
||||
var totalRealBarCount = GetSerieBarRealCount<T>(gridIndex);
|
||||
barStackSet.Clear();
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
@@ -954,6 +976,7 @@ namespace XCharts.Runtime
|
||||
if (!serie.show) continue;
|
||||
if (serie is T)
|
||||
{
|
||||
if (!CheckSerieGridIndex(serie, gridIndex)) continue;
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (barStackSet.Contains(serie.stack)) continue;
|
||||
@@ -1003,7 +1026,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
private List<string> tempList = new List<string>();
|
||||
public int GetSerieIndexIfStack<T>(Serie currSerie) where T : Serie
|
||||
public int GetSerieIndexIfStack<T>(Serie currSerie, int gridIndex) where T : Serie
|
||||
{
|
||||
tempList.Clear();
|
||||
int index = 0;
|
||||
@@ -1012,6 +1035,7 @@ namespace XCharts.Runtime
|
||||
var serie = m_Series[i];
|
||||
if (!serie.show) continue;
|
||||
if (!(serie is T)) continue;
|
||||
if (!CheckSerieGridIndex(serie, gridIndex)) continue;
|
||||
if (string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (serie.index == currSerie.index) return index;
|
||||
|
||||
@@ -125,16 +125,17 @@ namespace XCharts.Runtime
|
||||
if (isStack)
|
||||
SeriesHelper.UpdateStackDataList(chart.series, serie, null, m_StackSerieData);
|
||||
|
||||
var barCount = chart.GetSerieBarRealCount<Bar>();
|
||||
var barCount = chart.GetSerieBarRealCount<Bar>(-1);
|
||||
var categoryWidth = m_AngleAxis.IsCategory() ?
|
||||
AxisHelper.GetDataWidth(m_AngleAxis, 360, datas.Count, null) :
|
||||
AxisHelper.GetDataWidth(m_RadiusAxis, m_SeriePolar.context.radius, datas.Count, null);
|
||||
var barGap = chart.GetSerieBarGap<Bar>();
|
||||
var totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap, barCount);
|
||||
var barGap = chart.GetSerieBarGap<Bar>(-1);
|
||||
var totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap, barCount, -1);
|
||||
var barWidth = serie.GetBarWidth(categoryWidth, barCount);
|
||||
var offset = (categoryWidth - totalBarWidth) * 0.5f;
|
||||
var serieReadIndex = chart.GetSerieIndexIfStack<Bar>(serie);
|
||||
float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieTotalGap<Bar>(categoryWidth, barGap, serieReadIndex);
|
||||
var serieReadIndex = chart.GetSerieIndexIfStack<Bar>(serie, -1);
|
||||
float gap = serie.barGap == -1 ? offset :
|
||||
offset + chart.GetSerieTotalGap<Bar>(categoryWidth, barGap, serieReadIndex, -1);
|
||||
|
||||
var areaColor = ColorUtil.clearColor32;
|
||||
var areaToColor = ColorUtil.clearColor32;
|
||||
@@ -157,7 +158,7 @@ namespace XCharts.Runtime
|
||||
angleValue = serieData.GetData(1);
|
||||
if (m_AngleAxis.IsCategory())
|
||||
{
|
||||
start = (float) (startAngle + categoryWidth * angleValue + gap);
|
||||
start = (float)(startAngle + categoryWidth * angleValue + gap);
|
||||
end = start + barWidth;
|
||||
inside = m_SeriePolar.context.insideRadius;
|
||||
if (isStack)
|
||||
@@ -178,7 +179,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
end = start + m_AngleAxis.GetValueLength(angleValue, 360);
|
||||
serieData.context.stackHeight = end - start;
|
||||
inside = m_SeriePolar.context.insideRadius + categoryWidth * (float) radiusValue + gap;
|
||||
inside = m_SeriePolar.context.insideRadius + categoryWidth * (float)radiusValue + gap;
|
||||
outside = inside + barWidth;
|
||||
}
|
||||
serieData.context.startAngle = start;
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace XCharts.Runtime
|
||||
m_SerieGrid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
||||
if (m_SerieGrid == null)
|
||||
return;
|
||||
if(serie.useSortData)
|
||||
if (serie.useSortData)
|
||||
{
|
||||
SerieHelper.UpdateSerieRuntimeFilterData(serie);
|
||||
}
|
||||
@@ -180,15 +180,16 @@ namespace XCharts.Runtime
|
||||
if (isStack)
|
||||
SeriesHelper.UpdateStackDataList(chart.series, serie, dataZoom, m_StackSerieData);
|
||||
|
||||
var barCount = chart.GetSerieBarRealCount<Bar>();
|
||||
var barCount = chart.GetSerieBarRealCount<Bar>(m_SerieGrid.index);
|
||||
float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
|
||||
float relativedCategoryWidth = AxisHelper.GetDataWidth(relativedAxis, relativedAxisLength, showData.Count, dataZoom);
|
||||
float barGap = chart.GetSerieBarGap<Bar>();
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap, barCount);
|
||||
float barGap = chart.GetSerieBarGap<Bar>(m_SerieGrid.index);
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap, barCount, m_SerieGrid.index);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth, barCount);
|
||||
float offset = (categoryWidth - totalBarWidth) * 0.5f;
|
||||
var serieReadIndex = chart.GetSerieIndexIfStack<Bar>(serie);
|
||||
float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieTotalGap<Bar>(categoryWidth, barGap, serieReadIndex);
|
||||
var serieReadIndex = chart.GetSerieIndexIfStack<Bar>(serie, m_SerieGrid.index);
|
||||
float gap = serie.barGap == -1 ? offset :
|
||||
offset + chart.GetSerieTotalGap<Bar>(categoryWidth, barGap, serieReadIndex, m_SerieGrid.index);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
|
||||
showData.Count;
|
||||
@@ -240,7 +241,7 @@ namespace XCharts.Runtime
|
||||
var barHig = 0f;
|
||||
if (isPercentStack)
|
||||
{
|
||||
var valueTotal = chart.GetSerieSameStackTotalValue<Bar>(serie.stack, i);
|
||||
var valueTotal = chart.GetSerieSameStackTotalValue<Bar>(serie.stack, i, m_SerieGrid.index);
|
||||
barHig = valueTotal != 0 ? (float)(relativedValue / valueTotal * relativedAxisLength) : 0;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -122,11 +122,11 @@ namespace XCharts.Runtime
|
||||
var relativedAxisLength = isY ? m_SerieGrid.context.width : m_SerieGrid.context.height;
|
||||
var axisXY = isY ? m_SerieGrid.context.y : m_SerieGrid.context.x;
|
||||
|
||||
var barCount = chart.GetSerieBarRealCount<SimplifiedBar>();
|
||||
var barCount = chart.GetSerieBarRealCount<SimplifiedBar>(m_SerieGrid.index);
|
||||
float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
|
||||
float relativedCategoryWidth = AxisHelper.GetDataWidth(relativedAxis, relativedAxisLength, showData.Count, dataZoom);
|
||||
float barGap = chart.GetSerieBarGap<SimplifiedBar>();
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<SimplifiedBar>(categoryWidth, barGap, barCount);
|
||||
float barGap = chart.GetSerieBarGap<SimplifiedBar>(m_SerieGrid.index);
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<SimplifiedBar>(categoryWidth, barGap, barCount,m_SerieGrid.index);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth, barCount);
|
||||
float offset = (categoryWidth - totalBarWidth) * 0.5f;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
|
||||
Reference in New Issue
Block a user