增加AxisLabelshowStartLabelshowEndLabel参数设置首尾的Label是否显示

This commit is contained in:
monitor1394
2021-06-27 21:45:17 +08:00
parent e7be2adbc9
commit 7b87ff1024
7 changed files with 47 additions and 12 deletions

View File

@@ -399,8 +399,9 @@ namespace XCharts
return img;
}
public static ChartLabel AddAxisLabelObject(int index, string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme, string content)
public static ChartLabel AddAxisLabelObject(int total, int index, string name, Transform parent,
Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme,
string content)
{
var textStyle = axis.axisLabel.textStyle;
var iconStyle = axis.iconStyle;
@@ -414,6 +415,11 @@ namespace XCharts
GameObject.DestroyImmediate(oldText);
}
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;
}
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme);
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, iconStyle.width, iconStyle.height);
label.SetAutoSize(false);