mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
完善TextStyle的alignment的支持 (#150)
This commit is contained in:
@@ -34,10 +34,11 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.05.25) Improved `TextStyle` support for `alignment`
|
||||
* (2021.05.24) Fixed the problem that `Label` could not display properly when `PieChart` data were all `0`
|
||||
* (2021.05.24) Fixed an issue where `Serie Name` was not working on the `Add Serie` panel (#149)
|
||||
* (2021.05.23) Added `TextStyle` `wrap` to set whether to wrap lines
|
||||
* (2021.05.23) Added` axisLabel `to` autoAlign `whether to set alignment automatically
|
||||
* (2021.05.23) Added `TextStyle` `autoWrap` to set whether to wrap lines
|
||||
* (2021.05.23) Added `TextStyle` `autoAlign` whether to set alignment automatically
|
||||
* (2021.05.23) Added `width` and `height` of `axisLabel` to support custom text length and width
|
||||
* (2021.05.23) Added `Axis` `iconStyle` and `icons` to support setting coordinate Axis labels to display icons
|
||||
* (2021.05.20) Added the `insertDataHead` parameter to `Serie` and `Axis` to control whether data is inserted into the head or tail
|
||||
|
||||
@@ -34,10 +34,11 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.05.25) 完善`TextStyle`的`alignment`的支持 (#150)
|
||||
* (2021.05.24) 修复`PieChart`数据全为`0`时`Label`无法正常显示的问题
|
||||
* (2021.05.24) 修复`Add Serie`面板上`Serie Name`不生效的问题 (#149)
|
||||
* (2021.05.23) 增加`TextStyle`的`wrap`设置是否自动换行
|
||||
* (2021.05.23) 增加`AxisLabel`的`autoAlign`设置是否让系统自动设置对齐方式
|
||||
* (2021.05.23) 增加`TextStyle`的`autoWrap`设置是否自动换行
|
||||
* (2021.05.23) 增加`TextStyle`的`autoAlign`设置是否让系统自动设置对齐方式
|
||||
* (2021.05.23) 增加`AxisLabel`的`width`和`height`支持自定义文本的长宽
|
||||
* (2021.05.23) 增加`Axis`的`iconStyle`和`icons`支持设置坐标轴标签显示图标
|
||||
* (2021.05.20) 增加`Serie`和`Axis`的`insertDataToHead`参数控制数据插入头部还是尾部
|
||||
|
||||
@@ -205,7 +205,9 @@
|
||||
* `fontSize`:字体大小。
|
||||
* `fontStyle`:字体风格。
|
||||
* `lineSpacing`:行间距。
|
||||
* `wrap`:是否自动换行。
|
||||
* `alignment`:对齐方式。
|
||||
* `autoWrap`:是否自动换行。
|
||||
* `autoAlign`:是否让系统自动设置对齐方式。为true时系统自动选择对齐方式,为false时用alignment。
|
||||
|
||||
## `Tooltip`
|
||||
|
||||
@@ -834,7 +836,6 @@ K线图系列。
|
||||
* `onZero`:刻度标签显示在`0`刻度上。
|
||||
* `width`:刻度标签的宽。当为0时系统自动设置。
|
||||
* `height`:刻度标签的高。当为0时系统自动设置。
|
||||
* `autoAlign`:是否让系统自动设置对齐方式。为true时系统自动选择对齐方式,为false时用textStyle的对齐方式。
|
||||
* `textLimit`:文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。
|
||||
* `textStyle`:文本样式 [TextStyle](#TextStyle)。
|
||||
|
||||
|
||||
@@ -212,7 +212,8 @@ The component of settings related to text.
|
||||
* `fontSize`: the size of text. [default: `18`].
|
||||
* `fontStyle`: the font style of text. [default: `FontStyle.Normal`].
|
||||
* `lineSpacing`: the space of text line. [default: `1f`].
|
||||
* `wrap`: Whether to wrap lines.
|
||||
* `autoWrap`: Whether to wrap lines.
|
||||
* `autoAlign`: Whether to let the system automatically set alignment. If true, the system automatically selects alignment, and if false, use alignment.
|
||||
|
||||
## `Tooltip`
|
||||
|
||||
@@ -728,7 +729,7 @@ K线图系列。
|
||||
* `onZero`: 刻度标签显示在`0`刻度上。
|
||||
* `width`:刻度标签的宽。当为0时系统自动设置。
|
||||
* `height`:刻度标签的高。当为0时系统自动设置。
|
||||
* `autoAlign`:是否让系统自动设置对齐方式。为true时系统自动选择对齐方式,为false时用textStyle的对齐方式。
|
||||
|
||||
* `textLimit`: 文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。
|
||||
* `textStyle`: The style of text [TextStyle](#TextStyle).
|
||||
|
||||
|
||||
@@ -143,7 +143,6 @@ namespace XCharts
|
||||
PropertyField(prop, "m_NumericFormatter");
|
||||
PropertyField(prop, "m_ShowAsPositiveNumber");
|
||||
PropertyField(prop, "m_OnZero");
|
||||
PropertyField(prop, "m_AutoAlign");
|
||||
PropertyField(prop, "m_TextLimit");
|
||||
PropertyField(prop, "m_TextStyle");
|
||||
--EditorGUI.indentLevel;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace XCharts
|
||||
#else
|
||||
PropertyField(prop, "m_Font");
|
||||
#endif
|
||||
PropertyField(prop, "m_Wrap");
|
||||
PropertyField(prop, "m_Rotate");
|
||||
PropertyField(prop, "m_Offset");
|
||||
PropertyField(prop, "m_Color");
|
||||
@@ -41,6 +40,8 @@ namespace XCharts
|
||||
#else
|
||||
PropertyField(prop, "m_FontStyle");
|
||||
PropertyField(prop, "m_Alignment");
|
||||
PropertyField(prop, "m_AutoWrap");
|
||||
PropertyField(prop, "m_AutoAlign");
|
||||
#endif
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace XCharts
|
||||
[SerializeField] private bool m_OnZero = false;
|
||||
[SerializeField] private float m_Width = 0f;
|
||||
[SerializeField] private float m_Height = 0f;
|
||||
[SerializeField] private bool m_AutoAlign = true;
|
||||
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
@@ -125,14 +124,6 @@ namespace XCharts
|
||||
get { return m_Height; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 文本是否自动选对齐方式。为false时会用TextStyle下的alignment。
|
||||
/// </summary>
|
||||
public bool autoAlign
|
||||
{
|
||||
get { return m_AutoAlign; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_AutoAlign, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文本限制。
|
||||
@@ -186,7 +177,6 @@ namespace XCharts
|
||||
axisLabel.numericFormatter = numericFormatter;
|
||||
axisLabel.width = width;
|
||||
axisLabel.height = height;
|
||||
axisLabel.autoAlign = autoAlign;
|
||||
axisLabel.textLimit = textLimit.Clone();
|
||||
axisLabel.textStyle.Copy(textStyle);
|
||||
return axisLabel;
|
||||
@@ -202,7 +192,6 @@ namespace XCharts
|
||||
numericFormatter = axisLabel.numericFormatter;
|
||||
width = axisLabel.width;
|
||||
height = axisLabel.height;
|
||||
autoAlign = axisLabel.autoAlign;
|
||||
textLimit.Copy(axisLabel.textLimit);
|
||||
textStyle.Copy(axisLabel.textStyle);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace XCharts
|
||||
public class TextStyle : SubComponent
|
||||
{
|
||||
[SerializeField] private Font m_Font;
|
||||
|
||||
[SerializeField] private bool m_Wrap = true;
|
||||
[SerializeField] private bool m_AutoWrap = true;
|
||||
[SerializeField] private bool m_AutoAlign = true;
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
[SerializeField] private Vector2 m_Offset = Vector2.zero;
|
||||
[SerializeField] private Color m_Color = Color.clear;
|
||||
@@ -122,10 +122,18 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 是否自动换行。
|
||||
/// </summary>
|
||||
public bool wrap
|
||||
public bool autoWrap
|
||||
{
|
||||
get { return m_Wrap; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Wrap, value)) SetComponentDirty(); }
|
||||
get { return m_AutoWrap; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_AutoWrap, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 文本是否让系统自动选对齐方式。为false时才会用alignment。
|
||||
/// </summary>
|
||||
public bool autoAlign
|
||||
{
|
||||
get { return m_AutoAlign; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_AutoAlign, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 对齐方式。
|
||||
@@ -195,7 +203,8 @@ namespace XCharts
|
||||
fontStyle = textStyle.fontStyle;
|
||||
lineSpacing = textStyle.lineSpacing;
|
||||
alignment = textStyle.alignment;
|
||||
wrap = textStyle.wrap;
|
||||
autoWrap = textStyle.autoWrap;
|
||||
autoAlign = textStyle.autoAlign;
|
||||
#if dUI_TextMeshPro
|
||||
m_TMPFont = textStyle.tmpFont;
|
||||
m_TMPAlignment = textStyle.tmpAlignment;
|
||||
@@ -223,5 +232,10 @@ namespace XCharts
|
||||
if (fontSize == 0) return defaultTheme.fontSize;
|
||||
else return fontSize;
|
||||
}
|
||||
|
||||
public TextAnchor GetAlignment(TextAnchor systemAlignment)
|
||||
{
|
||||
return m_AutoAlign ? systemAlignment : alignment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace XCharts
|
||||
ChartHelper.GetOrAddComponent<Image>(contentObj);
|
||||
var txt = ChartHelper.AddTextObject("Text", contentObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
|
||||
textStyle, theme.legend);
|
||||
txt.SetAlignment(TextAnchor.MiddleLeft);
|
||||
txt.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleLeft));
|
||||
txt.SetColor(contentColor);
|
||||
var item = new LegendItem();
|
||||
item.index = i;
|
||||
|
||||
@@ -570,19 +570,13 @@ namespace XCharts
|
||||
{
|
||||
txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
|
||||
Vector2.zero, new Vector2(0, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis);
|
||||
if (yAxis.axisLabel.autoAlign)
|
||||
{
|
||||
txt.label.SetAlignment(TextAnchor.MiddleLeft);
|
||||
}
|
||||
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);
|
||||
if (yAxis.axisLabel.autoAlign)
|
||||
{
|
||||
txt.label.SetAlignment(TextAnchor.MiddleRight);
|
||||
}
|
||||
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);
|
||||
@@ -604,7 +598,7 @@ namespace XCharts
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), axisNameTextStyle,
|
||||
m_Theme.axis);
|
||||
axisName.SetAlignment(TextAnchor.MiddleCenter);
|
||||
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
axisName.SetLocalPosition(yAxis.position == Axis.AxisPosition.Right ?
|
||||
new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x + yAxis.offset, grid.runtimeY - offset.y) :
|
||||
new Vector2(zeroPos.x + offset.x + yAxis.offset, grid.runtimeY - offset.y));
|
||||
@@ -613,7 +607,7 @@ namespace XCharts
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(1, 0.5f),
|
||||
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), axisNameTextStyle,
|
||||
m_Theme.axis);
|
||||
axisName.SetAlignment(TextAnchor.MiddleRight);
|
||||
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleRight));
|
||||
axisName.SetLocalPosition(yAxis.position == Axis.AxisPosition.Right ?
|
||||
new Vector2(grid.runtimeX + grid.runtimeWidth - offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight / 2 + offset.y) :
|
||||
new Vector2(grid.runtimeX - offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight / 2 + offset.y));
|
||||
@@ -622,7 +616,7 @@ namespace XCharts
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), axisNameTextStyle,
|
||||
m_Theme.axis);
|
||||
axisName.SetAlignment(TextAnchor.MiddleCenter);
|
||||
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
axisName.SetLocalPosition(yAxis.position == Axis.AxisPosition.Right ?
|
||||
new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight + offset.y) :
|
||||
new Vector2(zeroPos.x + offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight + offset.y));
|
||||
@@ -697,10 +691,7 @@ namespace XCharts
|
||||
new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), xAxis, theme.axis);
|
||||
|
||||
if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
|
||||
if (xAxis.axisLabel.autoAlign)
|
||||
{
|
||||
label.label.SetAlignment(TextAnchor.MiddleCenter);
|
||||
}
|
||||
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));
|
||||
@@ -719,7 +710,7 @@ namespace XCharts
|
||||
case AxisName.Location.Start:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(1, 0.5f),
|
||||
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), axisNameTextStyle, theme.axis);
|
||||
axisName.SetAlignment(TextAnchor.MiddleRight);
|
||||
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleRight));
|
||||
axisName.SetLocalPosition(xAxis.position == Axis.AxisPosition.Top ?
|
||||
new Vector2(zeroPos.x - offset.x, grid.runtimeY + grid.runtimeHeight + offset.y + xAxis.offset) :
|
||||
new Vector2(zeroPos.x - offset.x, zeroPos.y + offset.y + xAxis.offset));
|
||||
@@ -727,7 +718,7 @@ namespace XCharts
|
||||
case AxisName.Location.Middle:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), axisNameTextStyle, theme.axis);
|
||||
axisName.SetAlignment(TextAnchor.MiddleCenter);
|
||||
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
axisName.SetLocalPosition(xAxis.position == Axis.AxisPosition.Top ?
|
||||
new Vector2(grid.runtimeX + grid.runtimeWidth / 2 + offset.x, grid.runtimeY + grid.runtimeHeight - offset.y + xAxis.offset) :
|
||||
new Vector2(grid.runtimeX + grid.runtimeWidth / 2 + offset.x, grid.runtimeY - offset.y + xAxis.offset));
|
||||
@@ -735,7 +726,7 @@ namespace XCharts
|
||||
case AxisName.Location.End:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0, 0.5f),
|
||||
new Vector2(0, 0.5f), new Vector2(0, 0.5f), new Vector2(100, 20), axisNameTextStyle, theme.axis);
|
||||
axisName.SetAlignment(TextAnchor.MiddleLeft);
|
||||
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleLeft));
|
||||
axisName.SetLocalPosition(xAxis.position == Axis.AxisPosition.Top ?
|
||||
new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x, grid.runtimeY + grid.runtimeHeight + offset.y + xAxis.offset) :
|
||||
new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x, zeroPos.y + offset.y + xAxis.offset));
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace XCharts
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig),
|
||||
textStyle, chart.theme.radar);
|
||||
txt.gameObject.hideFlags = chart.chartHideFlags;
|
||||
txt.SetAlignment(TextAnchor.MiddleCenter);
|
||||
txt.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
txt.SetText(radar.indicatorList[i].name);
|
||||
txt.SetActive(radar.indicator);
|
||||
var offset = new Vector3(textStyle.offset.x, textStyle.offset.y);
|
||||
|
||||
@@ -253,7 +253,7 @@ namespace XCharts
|
||||
chartText.text.font = textStyle.font == null ? theme.font : textStyle.font;
|
||||
chartText.text.fontStyle = textStyle.fontStyle;
|
||||
chartText.text.alignment = textStyle.alignment;
|
||||
chartText.text.horizontalOverflow = textStyle.wrap ? HorizontalWrapMode.Wrap : HorizontalWrapMode.Overflow;
|
||||
chartText.text.horizontalOverflow = textStyle.autoWrap ? HorizontalWrapMode.Wrap : HorizontalWrapMode.Overflow;
|
||||
chartText.text.verticalOverflow = VerticalWrapMode.Overflow;
|
||||
chartText.text.supportRichText = true;
|
||||
chartText.text.raycastTarget = false;
|
||||
@@ -371,7 +371,7 @@ namespace XCharts
|
||||
img.color = Color.black;
|
||||
var txt = AddTextObject("Text", tooltipObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
|
||||
textStyle, theme.tooltip);
|
||||
txt.SetAlignment(TextAnchor.UpperLeft);
|
||||
txt.SetAlignment(textStyle.GetAlignment(TextAnchor.UpperLeft));
|
||||
txt.SetText("Text");
|
||||
txt.SetLocalPosition(new Vector2(3, -3));
|
||||
tooltipObj.transform.localPosition = Vector3.zero;
|
||||
@@ -434,7 +434,7 @@ namespace XCharts
|
||||
var txt = AddTextObject("Text", labelObj.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle,
|
||||
theme.common);
|
||||
txt.SetColor(color);
|
||||
txt.SetAlignment(TextAnchor.MiddleCenter);
|
||||
txt.SetAlignment(textStyle.alignment);
|
||||
txt.SetText("Text");
|
||||
txt.SetLocalPosition(new Vector2(0, 0));
|
||||
txt.SetLocalEulerAngles(Vector3.zero);
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace XCharts
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
||||
null, isPercentStack);
|
||||
label.label.SetAlignment(TextAnchor.MiddleCenter);
|
||||
label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
label.SetText(labelName);
|
||||
var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor;
|
||||
label.SetPosition(pos);
|
||||
@@ -230,7 +230,7 @@ namespace XCharts
|
||||
var label = ChartHelper.AddAxisLabelObject(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);
|
||||
|
||||
label.label.SetAlignment(TextAnchor.MiddleCenter);
|
||||
label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
label.SetText(AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
|
||||
null, isPercentStack));
|
||||
var pos = ChartHelper.GetPos(cenPos, radius + margin,
|
||||
|
||||
Reference in New Issue
Block a user