mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
[bug][axis] fix showStartLabel and showEndLabel not work
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题
|
||||
* (2022.07.19) 增加`Axis`的`MinorSplitLine`设置坐标轴次分割线
|
||||
* (2022.07.19) 增加`Axis`的`MinorTick`设置坐标轴次刻度
|
||||
* (2022.07.17) 增加`Radar`的`smooth`参数设置平滑曲线
|
||||
|
||||
@@ -555,6 +555,21 @@ namespace XCharts.Runtime
|
||||
return m_Position == AxisPosition.Bottom;
|
||||
}
|
||||
|
||||
public bool IsNeedShowLabel(int index, int total = 0)
|
||||
{
|
||||
if (total == 0)
|
||||
{
|
||||
total = context.labelValueList.Count;
|
||||
}
|
||||
var labelShow = axisLabel.show && (axisLabel.interval == 0 || index % (axisLabel.interval + 1) == 0);
|
||||
if (labelShow)
|
||||
{
|
||||
if (!axisLabel.showStartLabel && index == 0) labelShow = false;
|
||||
else if (!axisLabel.showEndLabel && index == total - 1) labelShow = false;
|
||||
}
|
||||
return labelShow;
|
||||
}
|
||||
|
||||
public void SetNeedUpdateFilterData()
|
||||
{
|
||||
context.isNeedUpdateFilterData = true;
|
||||
@@ -831,7 +846,7 @@ namespace XCharts.Runtime
|
||||
|
||||
public void UpdateZeroOffset(float axisLength)
|
||||
{
|
||||
context.offset = context.minValue > 0 || context.minMaxRange == 0?
|
||||
context.offset = context.minValue > 0 || context.minMaxRange == 0 ?
|
||||
0 :
|
||||
(context.maxValue < 0 ?
|
||||
axisLength :
|
||||
|
||||
@@ -296,12 +296,12 @@ namespace XCharts
|
||||
if (i == 0)
|
||||
{
|
||||
var dist = GetLabelPosition(0, 1).x - pos.x;
|
||||
label.SetTextActive(dist > label.text.GetPreferredWidth());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth());
|
||||
}
|
||||
else if (i == axis.context.labelValueList.Count - 1)
|
||||
{
|
||||
var dist = pos.x - GetLabelPosition(0, i - 1).x;
|
||||
label.SetTextActive(dist > label.text.GetPreferredWidth());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -309,12 +309,12 @@ namespace XCharts
|
||||
if (i == 0)
|
||||
{
|
||||
var dist = GetLabelPosition(0, 1).y - pos.y;
|
||||
label.SetTextActive(dist > label.text.GetPreferredHeight());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight());
|
||||
}
|
||||
else if (i == axis.context.labelValueList.Count - 1)
|
||||
{
|
||||
var dist = pos.y - GetLabelPosition(0, i - 1).y;
|
||||
label.SetTextActive(dist > label.text.GetPreferredHeight());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace XCharts.Runtime
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
UpdateAxisMinMaxValue(component.index, component);
|
||||
UpdatePointerValue(component);
|
||||
}
|
||||
@@ -31,7 +30,7 @@ namespace XCharts.Runtime
|
||||
private void UpdatePosition(XAxis axis)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
||||
if (grid != null && axis is XAxis && axis.IsValue())
|
||||
if (grid != null)
|
||||
{
|
||||
var relativedAxis = chart.GetChartComponent<YAxis>(axis.gridIndex);
|
||||
axis.context.x = grid.context.x;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace XCharts.Runtime
|
||||
private void UpdatePosition(YAxis axis)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
||||
if (grid != null && axis.IsValue())
|
||||
if (grid != null)
|
||||
{
|
||||
var relativedAxis = chart.GetChartComponent<XAxis>(axis.gridIndex);
|
||||
axis.context.x = AxisHelper.GetYAxisXOrY(grid, axis, relativedAxis);
|
||||
|
||||
@@ -336,12 +336,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var textStyle = axis.axisLabel.textStyle;
|
||||
var label = AddChartLabel(name, parent, axis.axisLabel, theme, content, autoColor, autoAlignment);
|
||||
var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0);
|
||||
if (labelShow)
|
||||
{
|
||||
if (!axis.axisLabel.showStartLabel && index == 0) labelShow = false;
|
||||
else if (!axis.axisLabel.showEndLabel && index == total - 1) labelShow = false;
|
||||
}
|
||||
var labelShow = axis.IsNeedShowLabel(index, total);
|
||||
label.UpdateIcon(axis.axisLabel.icon, axis.GetIcon(index));
|
||||
label.text.SetActive(labelShow);
|
||||
return label;
|
||||
|
||||
Reference in New Issue
Block a user