diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md
index 31bc7848..50005d1c 100644
--- a/CHANGELOG-EN.md
+++ b/CHANGELOG-EN.md
@@ -38,6 +38,7 @@
## master
+* (2021.06.27) Add `showStartLabel` and `showEndLabel` arguments to `AxisLabel` to set whether the `Label` should be displayed at the beginning and end of the `AxisLabel`
* (2021.06.27) Added `formatter` delegate method to `AxisLabel` and `SerieLabel` (#145)
* (2021.06.27) Added `DataZoom`'s `orient` parameter to set horizontal or vertical styles
* (2021.06.21) Added `iconStyle`'s `AutoHideWhenLabelEmpty` to set whether the icon is automatically hidden when `label` is empty
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71e138ce..4c928b15 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@
## master
+* (2021.06.27) 增加`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置首尾的`Label`是否显示
* (2021.06.27) 增加`AxisLabel`和`SerieLabel`的`formatter`委托方法 (#145)
* (2021.06.27) 增加`DataZoom`的`orient`参数设置水平或垂直样式
* (2021.06.21) 增加`IconStyle`的`autoHideWhenLabelEmpty`参数设置当`label`为空时是否自动隐藏图标
diff --git a/Editor/PropertyDrawers/AxisDrawer.cs b/Editor/PropertyDrawers/AxisDrawer.cs
index 8760b656..45721f6a 100644
--- a/Editor/PropertyDrawers/AxisDrawer.cs
+++ b/Editor/PropertyDrawers/AxisDrawer.cs
@@ -143,6 +143,8 @@ namespace XCharts
PropertyField(prop, "m_NumericFormatter");
PropertyField(prop, "m_ShowAsPositiveNumber");
PropertyField(prop, "m_OnZero");
+ PropertyField(prop, "m_ShowStartLabel");
+ PropertyField(prop, "m_ShowEndLabel");
PropertyField(prop, "m_TextLimit");
PropertyField(prop, "m_TextStyle");
--EditorGUI.indentLevel;
diff --git a/Runtime/Component/Sub/AxisLabel.cs b/Runtime/Component/Sub/AxisLabel.cs
index b67d6dc2..c35ea34f 100644
--- a/Runtime/Component/Sub/AxisLabel.cs
+++ b/Runtime/Component/Sub/AxisLabel.cs
@@ -28,6 +28,8 @@ namespace XCharts
[SerializeField] private bool m_OnZero = false;
[SerializeField] private float m_Width = 0f;
[SerializeField] private float m_Height = 0f;
+ [SerializeField] private bool m_ShowStartLabel = true;
+ [SerializeField] private bool m_ShowEndLabel = true;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
private DelegateAxisLabelFormatter m_FormatterFunction;
@@ -125,7 +127,24 @@ namespace XCharts
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
}
-
+ ///
+ /// Whether to display the first label.
+ /// 是否显示第一个文本。
+ ///
+ public bool showStartLabel
+ {
+ get { return m_ShowStartLabel; }
+ set { if (PropertyUtil.SetStruct(ref m_ShowStartLabel, value)) SetComponentDirty(); }
+ }
+ ///
+ /// Whether to display the last label.
+ /// 是否显示最后一个文本。
+ ///
+ public bool showEndLabel
+ {
+ get { return m_ShowEndLabel; }
+ set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); }
+ }
///
/// 文本限制。
///
@@ -183,6 +202,8 @@ namespace XCharts
axisLabel.numericFormatter = numericFormatter;
axisLabel.width = width;
axisLabel.height = height;
+ axisLabel.showStartLabel = showStartLabel;
+ axisLabel.showEndLabel = showEndLabel;
axisLabel.textLimit = textLimit.Clone();
axisLabel.textStyle.Copy(textStyle);
return axisLabel;
@@ -198,6 +219,8 @@ namespace XCharts
numericFormatter = axisLabel.numericFormatter;
width = axisLabel.width;
height = axisLabel.height;
+ showStartLabel = axisLabel.showStartLabel;
+ showEndLabel = axisLabel.showEndLabel;
textLimit.Copy(axisLabel.textLimit);
textStyle.Copy(axisLabel.textStyle);
}
diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs
index ddf95de3..0ba9837d 100644
--- a/Runtime/Internal/CoordinateChart.cs
+++ b/Runtime/Internal/CoordinateChart.cs
@@ -599,14 +599,14 @@ namespace XCharts
yAxis.runtimeMaxValue, dataZoom, isPercentStack);
if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight()))
{
- txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
+ txt = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, Vector2.zero,
Vector2.zero, new Vector2(0, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
labelName);
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
}
else
{
- txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
+ txt = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, Vector2.zero,
Vector2.zero, new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
labelName);
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
@@ -722,9 +722,9 @@ namespace XCharts
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
var labelName = AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue,
xAxis.runtimeMaxValue, dataZoom, isPercentStack);
- var label = ChartHelper.AddAxisLabelObject(i, ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform,
- new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, textHeight),
- xAxis, theme.axis, labelName);
+ var label = ChartHelper.AddAxisLabelObject(splitNumber, i, ChartCached.GetXAxisName(xAxisIndex, i),
+ axisObj.transform, new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f),
+ new Vector2(textWidth, textHeight), xAxis, theme.axis, labelName);
if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter));
diff --git a/Runtime/Internal/Utility/ChartHelper.cs b/Runtime/Internal/Utility/ChartHelper.cs
index a739ae77..52012228 100644
--- a/Runtime/Internal/Utility/ChartHelper.cs
+++ b/Runtime/Internal/Utility/ChartHelper.cs
@@ -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);
diff --git a/Runtime/PolarChart.cs b/Runtime/PolarChart.cs
index 28d8b8a8..ddde054f 100644
--- a/Runtime/PolarChart.cs
+++ b/Runtime/PolarChart.cs
@@ -148,7 +148,7 @@ namespace XCharts
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue,
null, isPercentStack);
- var label = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
+ var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), axis, theme.axis,
labelName);
if (i == 0) axis.axisLabel.SetRelatedText(label.label, labelWidth);
@@ -229,7 +229,7 @@ namespace XCharts
bool inside = axis.axisLabel.inside;
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
null, isPercentStack);
- var label = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
+ var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis,
theme.axis, labelName);
label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
@@ -272,11 +272,13 @@ namespace XCharts
float tempMaxValue = 0;
if (axis is RadiusAxis)
{
- SeriesHelper.GetXMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true);
+ SeriesHelper.GetXMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue,
+ out tempMaxValue, true);
}
else
{
- SeriesHelper.GetYMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true);
+ SeriesHelper.GetYMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue,
+ out tempMaxValue, true);
}
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)