修复增删XY轴时可能异常的问题

This commit is contained in:
monitor1394
2021-03-22 20:32:19 +08:00
parent ea13f674bc
commit e8fdea764c
2 changed files with 21 additions and 8 deletions

View File

@@ -152,7 +152,7 @@ namespace XCharts
base.DrawPainterSerie(vh, serie); base.DrawPainterSerie(vh, serie);
serie.dataPoints.Clear(); serie.dataPoints.Clear();
var colorIndex = m_LegendRealShowName.IndexOf(serie.legendName); var colorIndex = m_LegendRealShowName.IndexOf(serie.legendName);
bool yCategory = m_YAxes[0].IsCategory() || m_YAxes[1].IsCategory(); bool yCategory = IsAnyYAxisIsCategory();
switch (serie.type) switch (serie.type)
{ {
case SerieType.Line: case SerieType.Line:
@@ -194,7 +194,7 @@ namespace XCharts
DrawLineArrow(vh, serie); DrawLineArrow(vh, serie);
} }
} }
bool yCategory = m_YAxes[0].IsCategory() || m_YAxes[1].IsCategory(); bool yCategory = IsAnyYAxisIsCategory();
if (yCategory) DrawYTooltipIndicator(vh); if (yCategory) DrawYTooltipIndicator(vh);
else DrawXTooltipIndicator(vh); else DrawXTooltipIndicator(vh);
} }
@@ -544,7 +544,8 @@ namespace XCharts
var axisNameTextStyle = yAxis.axisName.textStyle; var axisNameTextStyle = yAxis.axisName.textStyle;
var offset = axisNameTextStyle.offset; var offset = axisNameTextStyle.offset;
ChartText axisName = null; ChartText axisName = null;
var zeroPos = new Vector3(grid.runtimeX + m_XAxes[yAxisIndex].runtimeZeroXOffset, grid.runtimeY); var xAxis = GetXAxis(yAxisIndex);
var zeroPos = new Vector3(grid.runtimeX + (xAxis == null ? 0 : xAxis.runtimeZeroXOffset), grid.runtimeY);
switch (yAxis.axisName.location) switch (yAxis.axisName.location)
{ {
case AxisName.Location.Start: case AxisName.Location.Start:
@@ -642,7 +643,8 @@ namespace XCharts
var axisNameTextStyle = xAxis.axisName.textStyle; var axisNameTextStyle = xAxis.axisName.textStyle;
var offset = axisNameTextStyle.offset; var offset = axisNameTextStyle.offset;
ChartText axisName = null; ChartText axisName = null;
var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + m_YAxes[xAxisIndex].runtimeZeroYOffset); var yAxis = GetYAxis(xAxisIndex);
var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + (yAxis == null ? 0 : yAxis.runtimeZeroYOffset));
switch (xAxis.axisName.location) switch (xAxis.axisName.location)
{ {
case AxisName.Location.Start: case AxisName.Location.Start:
@@ -1473,10 +1475,21 @@ namespace XCharts
} }
} }
private bool IsAnyYAxisIsCategory()
{
foreach (var yAxis in m_YAxes)
{
if (yAxis.type == Axis.AxisType.Category)
{
return true;
}
}
return false;
}
protected void DrawLabelBackground(VertexHelper vh) protected void DrawLabelBackground(VertexHelper vh)
{ {
var isYAxis = m_YAxes[0].type == Axis.AxisType.Category var isYAxis = IsAnyYAxisIsCategory();
|| m_YAxes[1].type == Axis.AxisType.Category;
for (int n = 0; n < m_Series.Count; n++) for (int n = 0; n < m_Series.Count; n++)
{ {
var serie = m_Series.GetSerie(n); var serie = m_Series.GetSerie(n);

View File

@@ -100,8 +100,8 @@ namespace XCharts
Color32 highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_Theme, colorIndex, true); Color32 highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_Theme, colorIndex, true);
Color32 areaColor, areaToColor; Color32 areaColor, areaToColor;
Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero; Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero;
var yAxis = m_YAxes[serie.yAxisIndex]; var yAxis = GetSerieYAxisOrDefault(serie);
var xAxis = m_XAxes[serie.xAxisIndex]; var xAxis = GetSerieXAxisOrDefault(serie);
var grid = GetSerieGridOrDefault(serie); var grid = GetSerieGridOrDefault(serie);
var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset); var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line); var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line);