This commit is contained in:
monitor1394
2021-06-20 17:05:15 +08:00
parent 49fd642885
commit 81de33e11b
9 changed files with 47 additions and 35 deletions

View File

@@ -575,19 +575,20 @@ namespace XCharts
if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight()))
{
txt = ChartHelper.AddAxisLabelObject(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, true);
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
}
else
{
txt = ChartHelper.AddAxisLabelObject(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, true);
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
}
var labelWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom);
if (i == 0) yAxis.axisLabel.SetRelatedText(txt.label, labelWidth);
txt.SetPosition(GetLabelYPosition(totalWidth + gapWidth, i, yAxisIndex, yAxis));
txt.SetText(labelName);
yAxis.runtimeAxisLabelList.Add(txt);
totalWidth += labelWidth;
}
@@ -693,14 +694,15 @@ namespace XCharts
var labelWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom);
var inside = xAxis.axisLabel.inside;
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);
new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, textHeight),
xAxis, theme.axis,labelName, true);
if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter));
label.SetPosition(GetLabelXPosition(totalWidth + textWidth / 2 + gapWidth, i, xAxisIndex, xAxis));
label.SetText(AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, dataZoom,
isPercentStack));
xAxis.runtimeAxisLabelList.Add(label);
totalWidth += labelWidth;
}
@@ -1286,7 +1288,7 @@ namespace XCharts
}
}
protected void DrawXTooltipIndicator(VertexHelper vh)
{

View File

@@ -12,7 +12,6 @@ namespace XCharts
{
public class ChartLabel : ChartObject
{
private bool m_EmptyStringHideIcon = false;
private bool m_LabelAutoSize = true;
private float m_LabelPaddingLeftRight = 3f;
private float m_LabelPaddingTopBottom = 3f;
@@ -49,8 +48,6 @@ namespace XCharts
}
}
public bool emptyStringHideIcon { set { m_EmptyStringHideIcon = value; } }
public ChartLabel()
{
}
@@ -182,10 +179,6 @@ namespace XCharts
return sizeChange;
}
AdjustIconPos();
if (m_EmptyStringHideIcon)
{
ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text));
}
}
return false;
}

View File

@@ -400,12 +400,11 @@ namespace XCharts
}
public static ChartLabel AddAxisLabelObject(int index, string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme)
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme, string content, bool autoHideWhenContentEmpty = false)
{
var textStyle = axis.axisLabel.textStyle;
var iconStyle = axis.iconStyle;
var label = new ChartLabel();
label.emptyStringHideIcon = true;
label.gameObject = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
// TODO: 为了兼容旧版本,这里后面版本可以去掉
@@ -414,11 +413,17 @@ namespace XCharts
{
GameObject.DestroyImmediate(oldText);
}
var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0);
if (autoHideWhenContentEmpty && string.IsNullOrEmpty(content))
{
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);
label.UpdateIcon(iconStyle, axis.GetIcon(index));
label.label.SetActive(axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0));
label.label.SetActive(labelShow);
label.SetText(content);
return label;
}