mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 18:30:14 +00:00
增加AxisLabel的showStartLabel和showEndLabel参数设置首尾的Label是否显示
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
## master
|
## 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 `formatter` delegate method to `AxisLabel` and `SerieLabel` (#145)
|
||||||
* (2021.06.27) Added `DataZoom`'s `orient` parameter to set horizontal or vertical styles
|
* (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
|
* (2021.06.21) Added `iconStyle`'s `AutoHideWhenLabelEmpty` to set whether the icon is automatically hidden when `label` is empty
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2021.06.27) 增加`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置首尾的`Label`是否显示
|
||||||
* (2021.06.27) 增加`AxisLabel`和`SerieLabel`的`formatter`委托方法 (#145)
|
* (2021.06.27) 增加`AxisLabel`和`SerieLabel`的`formatter`委托方法 (#145)
|
||||||
* (2021.06.27) 增加`DataZoom`的`orient`参数设置水平或垂直样式
|
* (2021.06.27) 增加`DataZoom`的`orient`参数设置水平或垂直样式
|
||||||
* (2021.06.21) 增加`IconStyle`的`autoHideWhenLabelEmpty`参数设置当`label`为空时是否自动隐藏图标
|
* (2021.06.21) 增加`IconStyle`的`autoHideWhenLabelEmpty`参数设置当`label`为空时是否自动隐藏图标
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ namespace XCharts
|
|||||||
PropertyField(prop, "m_NumericFormatter");
|
PropertyField(prop, "m_NumericFormatter");
|
||||||
PropertyField(prop, "m_ShowAsPositiveNumber");
|
PropertyField(prop, "m_ShowAsPositiveNumber");
|
||||||
PropertyField(prop, "m_OnZero");
|
PropertyField(prop, "m_OnZero");
|
||||||
|
PropertyField(prop, "m_ShowStartLabel");
|
||||||
|
PropertyField(prop, "m_ShowEndLabel");
|
||||||
PropertyField(prop, "m_TextLimit");
|
PropertyField(prop, "m_TextLimit");
|
||||||
PropertyField(prop, "m_TextStyle");
|
PropertyField(prop, "m_TextStyle");
|
||||||
--EditorGUI.indentLevel;
|
--EditorGUI.indentLevel;
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ namespace XCharts
|
|||||||
[SerializeField] private bool m_OnZero = false;
|
[SerializeField] private bool m_OnZero = false;
|
||||||
[SerializeField] private float m_Width = 0f;
|
[SerializeField] private float m_Width = 0f;
|
||||||
[SerializeField] private float m_Height = 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 TextLimit m_TextLimit = new TextLimit();
|
||||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||||
private DelegateAxisLabelFormatter m_FormatterFunction;
|
private DelegateAxisLabelFormatter m_FormatterFunction;
|
||||||
@@ -125,7 +127,24 @@ namespace XCharts
|
|||||||
get { return m_Height; }
|
get { return m_Height; }
|
||||||
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
|
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to display the first label.
|
||||||
|
/// 是否显示第一个文本。
|
||||||
|
/// </summary>
|
||||||
|
public bool showStartLabel
|
||||||
|
{
|
||||||
|
get { return m_ShowStartLabel; }
|
||||||
|
set { if (PropertyUtil.SetStruct(ref m_ShowStartLabel, value)) SetComponentDirty(); }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to display the last label.
|
||||||
|
/// 是否显示最后一个文本。
|
||||||
|
/// </summary>
|
||||||
|
public bool showEndLabel
|
||||||
|
{
|
||||||
|
get { return m_ShowEndLabel; }
|
||||||
|
set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); }
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文本限制。
|
/// 文本限制。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -183,6 +202,8 @@ namespace XCharts
|
|||||||
axisLabel.numericFormatter = numericFormatter;
|
axisLabel.numericFormatter = numericFormatter;
|
||||||
axisLabel.width = width;
|
axisLabel.width = width;
|
||||||
axisLabel.height = height;
|
axisLabel.height = height;
|
||||||
|
axisLabel.showStartLabel = showStartLabel;
|
||||||
|
axisLabel.showEndLabel = showEndLabel;
|
||||||
axisLabel.textLimit = textLimit.Clone();
|
axisLabel.textLimit = textLimit.Clone();
|
||||||
axisLabel.textStyle.Copy(textStyle);
|
axisLabel.textStyle.Copy(textStyle);
|
||||||
return axisLabel;
|
return axisLabel;
|
||||||
@@ -198,6 +219,8 @@ namespace XCharts
|
|||||||
numericFormatter = axisLabel.numericFormatter;
|
numericFormatter = axisLabel.numericFormatter;
|
||||||
width = axisLabel.width;
|
width = axisLabel.width;
|
||||||
height = axisLabel.height;
|
height = axisLabel.height;
|
||||||
|
showStartLabel = axisLabel.showStartLabel;
|
||||||
|
showEndLabel = axisLabel.showEndLabel;
|
||||||
textLimit.Copy(axisLabel.textLimit);
|
textLimit.Copy(axisLabel.textLimit);
|
||||||
textStyle.Copy(axisLabel.textStyle);
|
textStyle.Copy(axisLabel.textStyle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -599,14 +599,14 @@ namespace XCharts
|
|||||||
yAxis.runtimeMaxValue, dataZoom, isPercentStack);
|
yAxis.runtimeMaxValue, dataZoom, isPercentStack);
|
||||||
if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight()))
|
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,
|
Vector2.zero, new Vector2(0, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
|
||||||
labelName);
|
labelName);
|
||||||
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
|
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
|
||||||
}
|
}
|
||||||
else
|
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,
|
Vector2.zero, new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
|
||||||
labelName);
|
labelName);
|
||||||
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
|
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
|
||||||
@@ -722,9 +722,9 @@ namespace XCharts
|
|||||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||||
var labelName = AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue,
|
var labelName = AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue,
|
||||||
xAxis.runtimeMaxValue, dataZoom, isPercentStack);
|
xAxis.runtimeMaxValue, dataZoom, isPercentStack);
|
||||||
var label = ChartHelper.AddAxisLabelObject(i, ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform,
|
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, ChartCached.GetXAxisName(xAxisIndex, i),
|
||||||
new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, textHeight),
|
axisObj.transform, new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f),
|
||||||
xAxis, theme.axis, labelName);
|
new Vector2(textWidth, textHeight), xAxis, theme.axis, labelName);
|
||||||
|
|
||||||
if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
|
if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
|
||||||
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter));
|
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||||
|
|||||||
@@ -399,8 +399,9 @@ namespace XCharts
|
|||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChartLabel AddAxisLabelObject(int index, string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
|
public static ChartLabel AddAxisLabelObject(int total, int index, string name, Transform parent,
|
||||||
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme, string content)
|
Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme,
|
||||||
|
string content)
|
||||||
{
|
{
|
||||||
var textStyle = axis.axisLabel.textStyle;
|
var textStyle = axis.axisLabel.textStyle;
|
||||||
var iconStyle = axis.iconStyle;
|
var iconStyle = axis.iconStyle;
|
||||||
@@ -414,6 +415,11 @@ namespace XCharts
|
|||||||
GameObject.DestroyImmediate(oldText);
|
GameObject.DestroyImmediate(oldText);
|
||||||
}
|
}
|
||||||
var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0);
|
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.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.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, iconStyle.width, iconStyle.height);
|
||||||
label.SetAutoSize(false);
|
label.SetAutoSize(false);
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ namespace XCharts
|
|||||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||||
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
||||||
null, isPercentStack);
|
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,
|
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), axis, theme.axis,
|
||||||
labelName);
|
labelName);
|
||||||
if (i == 0) axis.axisLabel.SetRelatedText(label.label, labelWidth);
|
if (i == 0) axis.axisLabel.SetRelatedText(label.label, labelWidth);
|
||||||
@@ -229,7 +229,7 @@ namespace XCharts
|
|||||||
bool inside = axis.axisLabel.inside;
|
bool inside = axis.axisLabel.inside;
|
||||||
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
||||||
null, isPercentStack);
|
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,
|
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis,
|
||||||
theme.axis, labelName);
|
theme.axis, labelName);
|
||||||
label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
|
label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||||
@@ -272,11 +272,13 @@ namespace XCharts
|
|||||||
float tempMaxValue = 0;
|
float tempMaxValue = 0;
|
||||||
if (axis is RadiusAxis)
|
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
|
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);
|
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
|
||||||
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
|
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
|
||||||
|
|||||||
Reference in New Issue
Block a user