修复Bar在同一个Chart不同Grid里时绘制有些异常的问题

This commit is contained in:
monitor1394
2025-03-09 23:14:26 +08:00
parent ffd2521360
commit e4923ea598
5 changed files with 51 additions and 24 deletions

View File

@@ -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;