From 9dedc1db6801cb6d32f650950628d630f8b4830d Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 26 Apr 2022 08:24:45 +0800 Subject: [PATCH] v3.0.0-preivew8 --- CHANGELOG.md | 6 + Documentation/CHANGELOG-EN.md | 6 + Documentation/SUPPORT.md | 44 +-- Documentation/XChartsAPI-EN.md | 28 +- Documentation/XChartsAPI-ZH.md | 28 +- Documentation/XChartsConfiguration-EN.md | 117 +++++--- Documentation/XChartsConfiguration-ZH.md | 117 +++++--- Editor/ChildComponents/DebugInfoDrawer.cs | 2 +- Editor/ChildComponents/IconStyleDrawer.cs | 1 + Editor/ChildComponents/ImageStyleDrawer.cs | 28 ++ .../ChildComponents/ImageStyleDrawer.cs.meta | 11 + Editor/ChildComponents/LabelStyleDrawer.cs | 19 +- Editor/ChildComponents/TextPaddingDrawer.cs | 26 ++ .../ChildComponents/TextPaddingDrawer.cs.meta | 11 + Editor/ChildComponents/TextStyleDrawer.cs | 8 +- Editor/ChildComponents/TitleStyleDrawer.cs | 13 +- Editor/MainComponents/AxisEditor.cs | 22 +- Editor/MainComponents/DataZoomEditor.cs | 2 +- Editor/MainComponents/LegendEditor.cs | 2 +- Editor/MainComponents/TitleEditor.cs | 4 +- Editor/MainComponents/TooltipEditor.cs | 10 +- Editor/Series/SerieEditor.cs | 13 +- Examples/Runtime/Example10_LineChart.cs | 2 +- Examples/Runtime/Example13_LineSimple.cs | 11 +- Runtime/Chart/PolarChart.cs | 2 + .../Axis/AngleAxis/AngleAxisHandler.cs | 10 +- Runtime/Component/Axis/Axis.cs | 11 - Runtime/Component/Axis/AxisContext.cs | 7 +- Runtime/Component/Axis/AxisHandler.cs | 186 ++++--------- Runtime/Component/Axis/AxisHelper.cs | 38 +-- Runtime/Component/Axis/AxisLabel.cs | 84 +----- Runtime/Component/Axis/AxisName.cs | 52 +--- .../Axis/ParallelAxis/ParallelAxis.cs | 1 - .../Axis/RadiusAxis/RadiusAxisHandler.cs | 11 +- .../Component/Axis/SingleAxis/SingleAxis.cs | 1 - Runtime/Component/Axis/XAxis/XAxis.cs | 1 - Runtime/Component/Axis/YAxis/YAxis.cs | 1 - Runtime/Component/Child/IconStyle.cs | 24 +- Runtime/Component/Child/ImageStyle.cs | 82 ++++++ Runtime/Component/Child/ImageStyle.cs.meta | 11 + Runtime/Component/Child/LabelStyle.cs | 150 ++++++----- Runtime/Component/Child/TextPadding.cs | 61 +++++ Runtime/Component/Child/TextPadding.cs.meta | 11 + Runtime/Component/Child/TextStyle.cs | 67 +---- Runtime/Component/DataZoom/DataZoom.cs | 36 ++- Runtime/Component/DataZoom/DataZoomHandler.cs | 14 +- Runtime/Component/Debug/DebugInfo.cs | 35 ++- Runtime/Component/Legend/Legend.cs | 12 +- Runtime/Component/Legend/LegendHandler.cs | 2 +- Runtime/Component/Legend/LegendHelper.cs | 18 +- Runtime/Component/Mark/MarkAreaHandler.cs | 24 +- Runtime/Component/Mark/MarkLineHandler.cs | 23 +- Runtime/Component/Mark/MarkLineHelper.cs | 6 +- Runtime/Component/Radar/RadarCoord.cs | 4 +- Runtime/Component/Radar/RadarCoordHandler.cs | 19 +- Runtime/Component/Title/Title.cs | 24 +- Runtime/Component/Title/TitleHandler.cs | 23 +- Runtime/Component/Title/TitleStyle.cs | 50 +--- Runtime/Component/Tooltip/Tooltip.cs | 55 ++-- Runtime/Component/Tooltip/TooltipHandler.cs | 22 +- Runtime/Component/Tooltip/TooltipView.cs | 34 ++- Runtime/Helper/SerieHelper.cs | 15 +- Runtime/Helper/SerieLabelHelper.cs | 22 +- Runtime/Internal/Misc/DelegateFunction.cs | 13 +- Runtime/Internal/Object/ChartLabel.cs | 200 +++++++++----- Runtime/Internal/Object/ChartText.cs | 36 +-- Runtime/Internal/Pools/SerieLabelPool.cs | 10 +- Runtime/Internal/Utilities/ChartHelper.cs | 251 +++++++----------- Runtime/Internal/XChartsMgr.cs | 4 +- Runtime/Serie/Bar/Bar.cs | 5 +- Runtime/Serie/Line/Line.cs | 2 - Runtime/Serie/Line/LineHandler.cs | 4 +- Runtime/Serie/Pie/Pie.cs | 2 +- Runtime/Serie/Pie/PieHandler.cs | 3 +- Runtime/Serie/Ring/Ring.cs | 2 +- Runtime/Serie/Serie.ExtraComponent.cs | 7 - Runtime/Serie/Serie.cs | 34 --- Runtime/Serie/SerieData.cs | 26 +- Runtime/Serie/SerieHandler.cs | 111 +++----- package.json | 6 +- 80 files changed, 1189 insertions(+), 1307 deletions(-) create mode 100644 Editor/ChildComponents/ImageStyleDrawer.cs create mode 100644 Editor/ChildComponents/ImageStyleDrawer.cs.meta create mode 100644 Editor/ChildComponents/TextPaddingDrawer.cs create mode 100644 Editor/ChildComponents/TextPaddingDrawer.cs.meta create mode 100644 Runtime/Component/Child/ImageStyle.cs create mode 100644 Runtime/Component/Child/ImageStyle.cs.meta create mode 100644 Runtime/Component/Child/TextPadding.cs create mode 100644 Runtime/Component/Child/TextPadding.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index c5097c81..b3d2ea9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # 更新日志 [master](#master) +[v3.0.0-preivew8](#v3.0.0-preivew8) [v3.0.0-preivew7](#v3.0.0-preivew7) [v3.0.0-preivew6](#v3.0.0-preivew6) [v3.0.0-preivew5](#v3.0.0-preivew5) @@ -50,6 +51,11 @@ ## master +## v3.0.0-preivew8 + +* (2022.04.26) 发布`v3.0.0-preivew8`版本 +* (2022.04.23) 移除`Serie`的`IconStyle`组件 +* (2022.04.23) 强化`LabelStyle`,所有组件的`TextStyle`都升级为`LabelStyle` * (2022.04.19) 增加`Label`的`rotate`支持设置旋转 * (2022.04.17) 修复`Bar`在数值为负数时动画无效的问题 * (2022.04.17) 增加`ItemStyle`的`BorderGap`支持设置边框间距 diff --git a/Documentation/CHANGELOG-EN.md b/Documentation/CHANGELOG-EN.md index e0912c16..a71f1ecd 100644 --- a/Documentation/CHANGELOG-EN.md +++ b/Documentation/CHANGELOG-EN.md @@ -39,6 +39,12 @@ ## master +* (2022.04.23) Remove `Serie` `IconStyle` component +* (2022.04.23) Enhance `LabelStyle`, all components `TextStyle` will be upgraded to `LabelStyle` +* (2022.04.19) Added `Label` `rotate` to support setting rotation +* (2022.04.17) Fixed animation invalidation of `Bar` when the value is negative +* (2022.04.17) Added `BorderGap` support for `ItemStyle` to set border spacing +* (2022.04.16) Optimize the `Border` and `Capsule` histogram of `Bar` * (2021.08.15) Fixed the problem of displaying exceptions after adding data again when `DataZoom` is enable (#163) * (2021.08.15) Improved `Axis`'s `AxisLabel` text rotate setting to avoid inconsistency offset in `DataZoom` (#163) * (2021.08.14) Added `Legend`'s `textAutoColor` to set the text color match with `Serie` color (#163) diff --git a/Documentation/SUPPORT.md b/Documentation/SUPPORT.md index bb14bbe0..8b7ad6a3 100644 --- a/Documentation/SUPPORT.md +++ b/Documentation/SUPPORT.md @@ -4,34 +4,34 @@ ## 订阅服务 -| |免费用户|个人`1`年`VIP`|个人`2`年`VIP` | 个人长期`VIP` | -| ----- |--|--|--|--| -| 订阅费用 | -- | `298`¥ | `498`¥ | `888`¥ | -| 席位时长 | -- | `1`个席位
`1`年 | `1`个席位
`2`年 | `1`个席位
`长期` | -|| +| |免费用户|付费咨询|个人`1`年`VIP`|个人`2`年`VIP` | 个人长期`VIP` | +| ----- |--|--|--|--|--| +| 订阅费用 | -- | `98`¥ | `298`¥ | `498`¥ | `888`¥ | +| 席位时长 | -- | `1`个席位
`7`天,`7`小时* | `1`个席位
`1`年 | `1`个席位
`2`年 | `1`个席位
`长期` | | `服务方式:`| -| 官方QQ群交流 | √ | √ | √ | √ | -| 专属VIP群交流 | | √ | √ | √ | -| 即时一对一交流 | | √ | √ | √ | -|| +| 官方QQ群交流 | √ | √ | √ | √ | √ | +| 即时一对一交流 | | √ | √ | √ | √ | +| 专属VIP群交流 | | | √ | √ | √ | | `服务内容:`| -| 可商用 | √ | √ | √ | √ | -| 可二次开发 | √ | √ | √ | √ | -| 有问必答 | | √ | √ | √ | -| 新手指导 | | √ | √ | √ | -| 开发指导 | | √ | √ | √ | -| 优化指导 | | √ | √ | √ | -| 其他技术支持 | | √ | √ | √ | -| 问题及时处理 | | √ | √ | √ | -| 需求优先考虑 | | √ | √ | √ | -| 可另付费定制 | | √ | √ | √ | -| 可另付费加急 | | √ | √ | √ | -| 付费模块85折 | | | | √ | +| 可商用 | √ | √ | √ | √ | √ | +| 可二次开发 | √ | √ | √ | √ | √ | +| 有问必答 | | √ | √ | √ | √ | +| 即时回应 | | √ | √ | √ | √ | +| 新手指导 | | √ | √ | √ | √ | +| 开发指导 | | √ | √ | √ | √ | +| 优化指导 | | √ | √ | √ | √ | +| 其他技术支持 | | | √ | √ | √ | +| 问题及时处理 | | | √ | √ | √ | +| 需求优先考虑 | | | √ | √ | √ | +| 可另付费定制 | | | √ | √ | √ | +| 可另付费加急 | | | √ | √ | √ | +| 付费图表优惠 | | | 95折 | 95折 | 85折 | ## 备注说明 1. __`付费定制`__ 是指用户可根据自己的需求定制不同的图表或新功能,只有`VIP`用户才享有`付费定制`权利。 -2. __`付费加急`__ 是指用户可对自己非常紧急的需求进行付费,将开发优先级提到最高,并指定`Deadline`内交付,只有`VIP`用户才享有`付费加急`权利。 +2. __`付费加急`__ 是指用户可对自己非常紧急的需求进行付费,将开发优先级提到最高,并可要求在`Deadline`内交付,只有`VIP`用户才享有`付费加急`权利。 +3. __`付费咨询`__ 付费咨询有效期`7`天,且总咨询时长不超过`7`个小时。 ## 捐助支持 diff --git a/Documentation/XChartsAPI-EN.md b/Documentation/XChartsAPI-EN.md index 1eb68c71..21a962b7 100644 --- a/Documentation/XChartsAPI-EN.md +++ b/Documentation/XChartsAPI-EN.md @@ -34,7 +34,6 @@ - [GridCoordContext](#GridCoordContext) - [HeatmapChart](#HeatmapChart) - [InteractData](#InteractData) -- [ItemStyleHelper](#ItemStyleHelper) - [LayerHelper](#LayerHelper) - [LegendContext](#LegendContext) - [LegendHelper](#LegendHelper) @@ -117,9 +116,8 @@ Inherits or Implemented: [MainComponentHandler](#MainComponentHandler) |public method|description| |--|--| | `AdjustCircleLabelPos()` |public static void AdjustCircleLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| -| `AdjustCircleLabelPos()` |public static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| | `AdjustMinMaxValue()` |public static void AdjustMinMaxValue(Axis axis, ref double minValue, ref double maxValue, bool needFormat, int ceilRate = 0)
调整最大最小值 | -| `AdjustRadiusAxisLabelPos()` |public static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| +| `AdjustRadiusAxisLabelPos()` |public static void AdjustRadiusAxisLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| | `GetAxisLineArrowOffset()` |public static float GetAxisLineArrowOffset(Axis axis)
包含箭头偏移的轴线长度 | | `GetAxisPosition()` |public static float GetAxisPosition(GridCoord grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null)
| | `GetAxisPositionValue()` |public static double GetAxisPositionValue(float xy, float axisLength, double axisRange, float axisStart, float axisOffset)
| @@ -314,6 +312,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) |public method|description| |--|--| | `ActiveAllObject()` |public static void ActiveAllObject(Transform parent, bool active, string match = null)
| +| `AddIcon()` |public static Image AddIcon(string name, Transform parent, IconStyle iconStyle)
| | `Cancat()` |public static string Cancat(string str1, int i)
| | `Cancat()` |public static string Cancat(string str1, string str2)
| | `ClearEventListener()` |public static void ClearEventListener(GameObject obj)
| @@ -372,23 +371,23 @@ Inherits or Implemented: [Image](#Image) |public method|description| |--|--| -| `GetLabelHeight()` |public float GetLabelHeight()
| -| `GetLabelWidth()` |public float GetLabelWidth()
| | `GetPosition()` |public Vector3 GetPosition()
| +| `GetTextHeight()` |public float GetTextHeight()
| +| `GetTextWidth()` |public float GetTextWidth()
| | `SetActive()` |public void SetActive(bool flag)
| -| `SetAutoSize()` |public void SetAutoSize(bool flag)
| | `SetIcon()` |public void SetIcon(Image image)
| | `SetIconActive()` |public void SetIconActive(bool flag)
| | `SetIconSize()` |public void SetIconSize(float width, float height)
| | `SetIconSprite()` |public void SetIconSprite(Sprite sprite)
| -| `SetLabel()` |public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
| -| `SetLabelActive()` |public void SetLabelActive(bool flag)
| -| `SetLabelBackground()` |public void SetLabelBackground(Image image)
| -| `SetLabelPosition()` |public void SetLabelPosition(Vector3 position)
| -| `SetLabelRotate()` |public void SetLabelRotate(float rotate)
| +| `SetPadding()` |public void SetPadding(float[] padding)
| | `SetPosition()` |public void SetPosition(Vector3 position)
| +| `SetRectPosition()` |public void SetRectPosition(Vector3 position)
| +| `SetSize()` |public void SetSize(float width, float height)
| | `SetText()` |public bool SetText(string text)
| +| `SetTextActive()` |public void SetTextActive(bool flag)
| | `SetTextColor()` |public void SetTextColor(Color color)
| +| `SetTextPadding()` |public void SetTextPadding(TextPadding padding)
| +| `SetTextRotate()` |public void SetTextRotate(float rotate)
| | `UpdateIcon()` |public void UpdateIcon(IconStyle iconStyle, Sprite sprite = null)
| ## `ChartObject` @@ -506,12 +505,6 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `TryGetValue()` |public bool TryGetValue(ref float value, ref bool interacting, float animationDuration = 250)
| | `TryGetValueAndColor()` |public bool TryGetValueAndColor(ref float value, ref Color32 color, ref Color32 toColor, ref bool interacting, float animationDuration = 250)
| -## `ItemStyleHelper` - -|public method|description| -|--|--| -| `IsNeedCorner()` |public static bool IsNeedCorner(ItemStyle itemStyle)
| - ## `LayerHelper` |public method|description| @@ -764,7 +757,6 @@ Inherits or Implemented: [Attribute](#Attribute) | `GetAreaStyle()` |public static AreaStyle GetAreaStyle(Serie serie, SerieData serieData)
| | `GetAreaToColor()` |public static Color32 GetAreaToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetAverageData()` |public static double GetAverageData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| -| `GetIconStyle()` |public static IconStyle GetIconStyle(Serie serie, SerieData serieData)
| | `GetItemColor()` |public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetItemColor0()` |public static Color32 GetItemColor0(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, Color32 defaultColor)
| | `GetItemFormatter()` |public static string GetItemFormatter(Serie serie, SerieData serieData, string defaultFormatter = null)
| diff --git a/Documentation/XChartsAPI-ZH.md b/Documentation/XChartsAPI-ZH.md index 619780fb..97878008 100644 --- a/Documentation/XChartsAPI-ZH.md +++ b/Documentation/XChartsAPI-ZH.md @@ -34,7 +34,6 @@ - [GridCoordContext](#GridCoordContext) - [HeatmapChart](#HeatmapChart) - [InteractData](#InteractData) -- [ItemStyleHelper](#ItemStyleHelper) - [LayerHelper](#LayerHelper) - [LegendContext](#LegendContext) - [LegendHelper](#LegendHelper) @@ -117,9 +116,8 @@ Inherits or Implemented: [MainComponentHandler](#MainComponentHandler) |public method|description| |--|--| | `AdjustCircleLabelPos()` |public static void AdjustCircleLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| -| `AdjustCircleLabelPos()` |public static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| | `AdjustMinMaxValue()` |public static void AdjustMinMaxValue(Axis axis, ref double minValue, ref double maxValue, bool needFormat, int ceilRate = 0)
调整最大最小值 | -| `AdjustRadiusAxisLabelPos()` |public static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| +| `AdjustRadiusAxisLabelPos()` |public static void AdjustRadiusAxisLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
| | `GetAxisLineArrowOffset()` |public static float GetAxisLineArrowOffset(Axis axis)
包含箭头偏移的轴线长度 | | `GetAxisPosition()` |public static float GetAxisPosition(GridCoord grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null)
| | `GetAxisPositionValue()` |public static double GetAxisPositionValue(float xy, float axisLength, double axisRange, float axisStart, float axisOffset)
| @@ -314,6 +312,7 @@ Inherits or Implemented: [BaseChart](#BaseChart) |public method|description| |--|--| | `ActiveAllObject()` |public static void ActiveAllObject(Transform parent, bool active, string match = null)
| +| `AddIcon()` |public static Image AddIcon(string name, Transform parent, IconStyle iconStyle)
| | `Cancat()` |public static string Cancat(string str1, int i)
| | `Cancat()` |public static string Cancat(string str1, string str2)
| | `ClearEventListener()` |public static void ClearEventListener(GameObject obj)
| @@ -372,23 +371,23 @@ Inherits or Implemented: [Image](#Image) |public method|description| |--|--| -| `GetLabelHeight()` |public float GetLabelHeight()
| -| `GetLabelWidth()` |public float GetLabelWidth()
| | `GetPosition()` |public Vector3 GetPosition()
| +| `GetTextHeight()` |public float GetTextHeight()
| +| `GetTextWidth()` |public float GetTextWidth()
| | `SetActive()` |public void SetActive(bool flag)
| -| `SetAutoSize()` |public void SetAutoSize(bool flag)
| | `SetIcon()` |public void SetIcon(Image image)
| | `SetIconActive()` |public void SetIconActive(bool flag)
| | `SetIconSize()` |public void SetIconSize(float width, float height)
| | `SetIconSprite()` |public void SetIconSprite(Sprite sprite)
| -| `SetLabel()` |public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
| -| `SetLabelActive()` |public void SetLabelActive(bool flag)
| -| `SetLabelBackground()` |public void SetLabelBackground(Image image)
| -| `SetLabelPosition()` |public void SetLabelPosition(Vector3 position)
| -| `SetLabelRotate()` |public void SetLabelRotate(float rotate)
| +| `SetPadding()` |public void SetPadding(float[] padding)
| | `SetPosition()` |public void SetPosition(Vector3 position)
| +| `SetRectPosition()` |public void SetRectPosition(Vector3 position)
| +| `SetSize()` |public void SetSize(float width, float height)
| | `SetText()` |public bool SetText(string text)
| +| `SetTextActive()` |public void SetTextActive(bool flag)
| | `SetTextColor()` |public void SetTextColor(Color color)
| +| `SetTextPadding()` |public void SetTextPadding(TextPadding padding)
| +| `SetTextRotate()` |public void SetTextRotate(float rotate)
| | `UpdateIcon()` |public void UpdateIcon(IconStyle iconStyle, Sprite sprite = null)
| ## `ChartObject` @@ -506,12 +505,6 @@ Inherits or Implemented: [BaseChart](#BaseChart) | `TryGetValue()` |public bool TryGetValue(ref float value, ref bool interacting, float animationDuration = 250)
| | `TryGetValueAndColor()` |public bool TryGetValueAndColor(ref float value, ref Color32 color, ref Color32 toColor, ref bool interacting, float animationDuration = 250)
| -## `ItemStyleHelper` - -|public method|description| -|--|--| -| `IsNeedCorner()` |public static bool IsNeedCorner(ItemStyle itemStyle)
| - ## `LayerHelper` |public method|description| @@ -764,7 +757,6 @@ Inherits or Implemented: [Attribute](#Attribute) | `GetAreaStyle()` |public static AreaStyle GetAreaStyle(Serie serie, SerieData serieData)
| | `GetAreaToColor()` |public static Color32 GetAreaToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetAverageData()` |public static double GetAverageData(Serie serie, int dimension = 1, DataZoom dataZoom = null)
| -| `GetIconStyle()` |public static IconStyle GetIconStyle(Serie serie, SerieData serieData)
| | `GetItemColor()` |public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
| | `GetItemColor0()` |public static Color32 GetItemColor0(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, Color32 defaultColor)
| | `GetItemFormatter()` |public static string GetItemFormatter(Serie serie, SerieData serieData, string defaultFormatter = null)
| diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index 83b00646..cede153a 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -87,6 +87,7 @@ - [Emphasis](#Emphasis) - [EndLabelStyle](#EndLabelStyle) - [IconStyle](#IconStyle) +- [ImageStyle](#ImageStyle) - [ItemStyle](#ItemStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) @@ -95,6 +96,7 @@ - [LevelStyle](#LevelStyle) - [LineArrow](#LineArrow) - [LineStyle](#LineStyle) +- [Location](#Location) - [MarkAreaData](#MarkAreaData) - [MarkLineData](#MarkLineData) - [PolarAxisTheme](#PolarAxisTheme) @@ -106,6 +108,7 @@ - [SubTitleTheme](#SubTitleTheme) - [SymbolStyle](#SymbolStyle) - [TextLimit](#TextLimit) +- [TextPadding](#TextPadding) - [TextStyle](#TextStyle) - [ThemeStyle](#ThemeStyle) - [TitleStyle](#TitleStyle) @@ -118,7 +121,7 @@ - [AreaStyle](#AreaStyle) - [Emphasis](#Emphasis) -- [IconStyle](#IconStyle) +- [ImageStyle](#ImageStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) - [LineArrow](#LineArrow) @@ -128,7 +131,7 @@ - [AreaStyle](#AreaStyle) - [Emphasis](#Emphasis) -- [IconStyle](#IconStyle) +- [ImageStyle](#ImageStyle) - [ItemStyle](#ItemStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) @@ -242,7 +245,6 @@ The axis in rectangular coordinate. | `inverse` |false | Whether the axis are reversed or not. Invalid in `Category` axis. | | `clockwise` |true | Whether the positive position of axis is in clockwise. True for clockwise by default. | | `insertDataToHead` | | Whether to add new data at the head or at the end of the list. | -| `iconStyle` | | 图标样式。 [IconStyle](IconStyle)| | `icons` | | 类目数据对应的图标。 | | `data` | | Category data, available in type: 'Category' axis. | | `axisLine` | | [AxisLine](AxisLine)| @@ -254,26 +256,19 @@ The axis in rectangular coordinate. ## `AxisLabel` -Inherits or Implemented: [ChildComponent](#ChildComponent) +Inherits or Implemented: [LabelStyle](#LabelStyle) Settings related to axis label. |field|default|comment| |--|--|--| -| `show` |true | Set this to false to prevent the axis label from appearing. | -| `formatter` | | | | `interval` |0 | The display interval of the axis label. | | `inside` |false | Set this to true so the axis labels face the inside direction. | -| `distance` | | The distance between the axis label and the axis line. | -| `numericFormatter` | | Standard numeric format strings. | | `showAsPositiveNumber` |false | Show negative number as positive number. | | `onZero` |false | 刻度标签显示在0刻度上。 | -| `width` |0f | 文本的宽。为0时会自动匹配。 | -| `height` |0f | 文本的高。为0时会自动匹配。 | | `showStartLabel` |true | Whether to display the first label. | | `showEndLabel` |true | Whether to display the last label. | | `textLimit` | | 文本限制。 [TextLimit](TextLimit)| -| `textStyle` | | The text style of axis name. [TextStyle](TextStyle)| ## `AxisLine` @@ -297,9 +292,7 @@ the name of axis. |--|--|--| | `show` | | Whether to show axis name. | | `name` | | the name of axis. | -| `formatter` | | The formatter of indicator's name. | -| `location` | | Location of axis name.
`AxisName.Location`:
- `Start`: the location of axis name.
- `Middle`: the location of axis name.
- `End`: the location of axis name.
- `align`: 对齐方式。
- `left`: Distance between component and the left side of the container.
- `right`: Distance between component and the left side of the container.
- `top`: Distance between component and the left side of the container.
- `bottom`: Distance between component and the left side of the container.
| -| `textStyle` | | The text style of axis name. [TextStyle](TextStyle)| +| `labelStyle` | | The text style of axis name. [LabelStyle](LabelStyle)| ## `AxisSplitArea` @@ -474,7 +467,7 @@ DataZoom component is used for zooming a specific area, which enables user to in | `minShowNum` |1 | Minimum number of display data. Minimum number of data displayed when DataZoom is enlarged to maximum. | | `scrollSensitivity` |1.1f | The sensitivity of dataZoom scroll. The larger the number, the more sensitive it is. | | `orient` | | Specify whether the layout of dataZoom component is horizontal or vertical. What's more, it indicates whether the horizontal axis or vertical axis is controlled by default in catesian coordinate system.
`Orient`:
- `Horizonal`: 水平
- `Vertical`: 垂直
| -| `textStyle` | | font style. [TextStyle](TextStyle)| +| `labelStyle` | | label style. [LabelStyle](LabelStyle)| | `lineStyle` | | 阴影线条样式。 [LineStyle](LineStyle)| | `areaStyle` | | 阴影填充样式。 [AreaStyle](AreaStyle)| @@ -500,7 +493,7 @@ Inherits or Implemented: [ComponentTheme](#ComponentTheme) | `showDebugInfo` |false | | | `showAllChartObject` |false | | | `foldSeries` |false | | -| `debugInfoTextStyle` | | [TextStyle](TextStyle)| +| `labelStyle` | | [LabelStyle](LabelStyle)| ## `EffectScatter` @@ -550,20 +543,35 @@ Inherits or Implemented: [Serie](#Serie),[INeedSerieContainer](#INeedSerieContai ## `IconStyle` -Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) +Inherits or Implemented: [ChildComponent](#ChildComponent) |field|default|comment| |--|--|--| | `show` |false | Whether the data icon is show. | -| `layer` | | 显示在上层还是在下层。
`IconStyle.Layer`:
- `UnderLabel`:
- `AboveLabel`:
| +| `layer` | | 显示在上层还是在下层。
`IconStyle.Layer`:
- `UnderText`: The icon is display under the label text. 图标在标签文字下
- `AboveText`: The icon is display above the label text. 图标在标签文字上
| | `align` | | 水平方向对齐方式。
`Align`:
- `Center`: 对齐方式
- `Left`: 对齐方式
- `Right`: 对齐方式
| | `sprite` | | The image of icon. | +| `type` | | How to display the icon. | | `color` | | 图标颜色。 | | `width` |20 | 图标宽。 | | `height` |20 | 图标高。 | | `offset` | | 图标偏移。 | | `autoHideWhenLabelEmpty` |false | 当label内容为空时是否自动隐藏图标 | +## `ImageStyle` + +Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) + +|field|default|comment| +|--|--|--| +| `show` |true | Whether the data icon is show. | +| `sprite` | | The image of icon. | +| `type` | | How to display the image. | +| `autoColor` | | 是否自动颜色。 | +| `color` | | 图标颜色。 | +| `width` |0 | 图标宽。 | +| `height` |0 | 图标高。 | + ## `Indicator` Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart. @@ -611,6 +619,7 @@ Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieDataComponent] | `centerColor` | | 中心区域颜色。 | | `centerGap` | | 中心区域间隙。 | | `borderWidth` |0 | 边框宽。 | +| `borderGap` |0 | 边框间隙。 | | `borderColor` | | 边框的颜色。 | | `borderColor0` | | 边框的颜色。 | | `borderToColor` | | 边框的渐变色。 | @@ -644,15 +653,17 @@ Text label of chart, to explain some data information about graphic item like va |--|--|--| | `show` |true | Whether the label is showed. | | `Position` | | | +| `autoOffset` |false | 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。 | | `offset` | | offset to the host graphic element. | +| `rotate` | | Rotation of label. | | `distance` | | 距离轴线的距离。 | | `formatter` | | | -| `paddingLeftRight` |2f | the text padding of left and right. defaut:2. | -| `paddingTopBottom` |2f | the text padding of top and bottom. defaut:2. | -| `backgroundWidth` |0 | the width of background. If set as default value 0, it means than the background width auto set as the text width. | -| `backgroundHeight` |0 | the height of background. If set as default value 0, it means than the background height auto set as the text height. | | `numericFormatter` | | Standard numeric format strings. | -| `autoOffset` |false | 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。 | +| `width` |0 | the width of label. If set as default value 0, it means than the label width auto set as the text width. | +| `height` |0 | the height of label. If set as default value 0, it means than the label height auto set as the text height. | +| `icon` | | the sytle of icon. [IconStyle](IconStyle)| +| `background` | | the sytle of background. [ImageStyle](ImageStyle)| +| `textPadding` | | the text padding of label. [TextPadding](TextPadding)| | `textStyle` | | the sytle of text. [TextStyle](TextStyle)| ## `Lang` @@ -680,14 +691,14 @@ Legend component.The legend component shows different sets of tags, colors, and | `iconType` | | Type of legend.
`Painter.Type`:
- `Base`:
- `Serie`:
- `Top`:
| | `selectedMode` | | Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
`VisualMap.SelectedMode`:
- `Multiple`: 多选。
- `Single`: 单选。
| | `orient` | | Specify whether the layout of legend component is horizontal or vertical.
`Orient`:
- `Horizonal`: 水平
- `Vertical`: 垂直
| -| `location` | | The location of legend.
`AxisName.Location`:
- `Start`: the location of axis name.
- `Middle`: the location of axis name.
- `End`: the location of axis name.
- `align`: 对齐方式。
- `left`: Distance between component and the left side of the container.
- `right`: Distance between component and the left side of the container.
- `top`: Distance between component and the left side of the container.
- `bottom`: Distance between component and the left side of the container.
| +| `location` | | The location of legend. [Location](Location)| | `itemWidth` |25.0f | Image width of legend symbol. | | `itemHeight` |12.0f | Image height of legend symbol. | | `itemGap` |10f | The distance between each legend, horizontal distance in horizontal layout, and vertical distance in vertical layout. | | `itemAutoColor` |true | Whether the legend symbol matches the color automatically. | | `textAutoColor` |false | Whether the legend text matches the color automatically. | | `formatter` | | | -| `textStyle` | | the style of text. [TextStyle](TextStyle)| +| `labelStyle` | | the style of text. [LabelStyle](LabelStyle)| | `data` | | Data array of legend. An array item is usually a name representing string. (If it is a pie chart, it could also be the name of a single data in the pie chart) of a series. | | `icons` | | 自定义的图例标记图形。 | @@ -750,6 +761,20 @@ The style of line. | `length` |0 | | | `opacity` |1 | Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0. | +## `Location` + +Inherits or Implemented: [ChildComponent](#ChildComponent),[IPropertyChanged](#IPropertyChanged) + +Location type. Quick to set the general location. + +|field|default|comment| +|--|--|--| +| `align` | | 对齐方式。
`Align`:
- `Center`: 对齐方式
- `Left`: 对齐方式
- `Right`: 对齐方式
| +| `left` | | Distance between component and the left side of the container. | +| `right` | | Distance between component and the left side of the container. | +| `top` | | Distance between component and the left side of the container. | +| `bottom` | | Distance between component and the left side of the container. | + ## `MainComponent` Inherits or Implemented: [IComparable](#IComparable) @@ -920,7 +945,6 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) | `endLabels` | | | | `lineArrows` | | | | `areaStyles` | | | -| `iconStyles` | | | | `titleStyles` | | | | `emphases` | | | | `index` | | The index of serie. | @@ -1008,7 +1032,6 @@ A data item of serie. | `labelLines` | | | | `emphases` | | | | `symbols` | | | -| `iconStyles` | | | | `lineStyles` | | | | `areaStyles` | | | | `titleStyles` | | | @@ -1145,6 +1168,20 @@ Text character limitation and adaptation component. When the length of the text | `gap` |1 | White pixel distance at both ends. | | `suffix` | | Suffixes when the length exceeds. | +## `TextPadding` + +Inherits or Implemented: [ChildComponent](#ChildComponent) + +Settings related to text. + +|field|default|comment| +|--|--|--| +| `show` |true | | +| `top` |2 | | +| `right` |4 | | +| `left` |4 | | +| `bottom` |2 | | + ## `TextStyle` Inherits or Implemented: [ChildComponent](#ChildComponent) @@ -1153,16 +1190,13 @@ Settings related to text. |field|default|comment| |--|--|--| +| `show` |true | Settings related to text. | | `font` | | the font of text. When `null`, the theme's font is used by default. | | `autoWrap` |false | 是否自动换行。 | | `autoAlign` |true | 文本是否让系统自动选对齐方式。为false时才会用alignment。 | | `rotate` |0 | Rotation of text. | -| `extraWidth` |0 | Extra width of text preferred width. | -| `offset` |Vector2.zero | the offset of position. | | `autoColor` |false | 是否开启自动颜色。当开启时,会自动设置颜色。 | | `color` | | the color of text. | -| `autoBackgroundColor` |false | | -| `backgroundColor` | | the color of text. | | `fontSize` |0 | font size. | | `fontStyle` | | font style. | | `lineSpacing` |1f | text line spacing. | @@ -1222,23 +1256,18 @@ Title component, including main title and subtitle. |--|--|--| | `show` |true | [default:true] Set this to false to prevent the title from showing. | | `text` | | The main title text, supporting \n for newlines. | -| `textStyle` | | The text style of main title. [TextStyle](TextStyle)| | `subText` | | Subtitle text, supporting for \n for newlines. | -| `subTextStyle` | | The text style of sub title. [TextStyle](TextStyle)| +| `labelStyle` | | The text style of main title. [LabelStyle](LabelStyle)| +| `subLabelStyle` | | The text style of sub title. [LabelStyle](LabelStyle)| | `itemGap` |0 | [default:8] The gap between the main title and subtitle. | -| `location` | | The location of title component.
`AxisName.Location`:
- `Start`: the location of axis name.
- `Middle`: the location of axis name.
- `End`: the location of axis name.
- `align`: 对齐方式。
- `left`: Distance between component and the left side of the container.
- `right`: Distance between component and the left side of the container.
- `top`: Distance between component and the left side of the container.
- `bottom`: Distance between component and the left side of the container.
| +| `location` | | The location of title component. [Location](Location)| ## `TitleStyle` -Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieDataComponent](#ISerieDataComponent),[ISerieExtraComponent](#ISerieExtraComponent) +Inherits or Implemented: [LabelStyle](#LabelStyle),[ISerieDataComponent](#ISerieDataComponent),[ISerieExtraComponent](#ISerieExtraComponent) the title of serie. -|field|default|comment| -|--|--|--| -| `show` |true | Whether to show title. | -| `offsetCenter` |Vector2(0, -0.2f) | The offset position relative to the center. | -| `textStyle` | | the color of text. [TextStyle](TextStyle)| ## `TitleTheme` @@ -1282,9 +1311,9 @@ Tooltip component. | `itemHeight` |25f | | | `borderColor` |Color32(230, 230, 230, 255) | the color of tooltip border. | | `lineStyle` | | the line style of indicator line. [LineStyle](LineStyle)| -| `labelTextStyle` | | the text style of content. [TextStyle](TextStyle)| -| `titleTextStyle` | | 标题的文本样式。 [TextStyle](TextStyle)| -| `columnsTextStyle` | | | +| `indicatorLabelStyle` | | the label style of tooltip axis indicator label. [LabelStyle](LabelStyle)| +| `titleLabelStyle` | | 标题的文本样式。 [LabelStyle](LabelStyle)| +| `contentLabelStyles` | | | ## `TooltipTheme` @@ -1328,7 +1357,7 @@ VisualMap component. Mapping data to visual elements such as colors. | `hoverLink` |true | When the hoverLink function is turned on, when the mouse hovers over the visualMap component, the corresponding value of the mouse position is highlighted in the corresponding graphic element in the diagram. | | `autoMinMax` |true | Automatically set min, Max value 自动设置min,max的值 | | `orient` | | Specify whether the layout of component is horizontal or vertical.
`Orient`:
- `Horizonal`: 水平
- `Vertical`: 垂直
| -| `location` | | The location of component.
`AxisName.Location`:
- `Start`: the location of axis name.
- `Middle`: the location of axis name.
- `End`: the location of axis name.
- `align`: 对齐方式。
- `left`: Distance between component and the left side of the container.
- `right`: Distance between component and the left side of the container.
- `top`: Distance between component and the left side of the container.
- `bottom`: Distance between component and the left side of the container.
| +| `location` | | The location of component. [Location](Location)| | `workOnLine` |true | Whether the visualmap is work on linestyle of linechart. | | `workOnArea` |false | Whether the visualmap is work on areaStyle of linechart. | | `inRange` | | Defines the visual color in the selected range. | diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index 5f53e1e1..bb62d8f7 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -87,6 +87,7 @@ - [Emphasis](#Emphasis) - [EndLabelStyle](#EndLabelStyle) - [IconStyle](#IconStyle) +- [ImageStyle](#ImageStyle) - [ItemStyle](#ItemStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) @@ -95,6 +96,7 @@ - [LevelStyle](#LevelStyle) - [LineArrow](#LineArrow) - [LineStyle](#LineStyle) +- [Location](#Location) - [MarkAreaData](#MarkAreaData) - [MarkLineData](#MarkLineData) - [PolarAxisTheme](#PolarAxisTheme) @@ -106,6 +108,7 @@ - [SubTitleTheme](#SubTitleTheme) - [SymbolStyle](#SymbolStyle) - [TextLimit](#TextLimit) +- [TextPadding](#TextPadding) - [TextStyle](#TextStyle) - [ThemeStyle](#ThemeStyle) - [TitleStyle](#TitleStyle) @@ -118,7 +121,7 @@ - [AreaStyle](#AreaStyle) - [Emphasis](#Emphasis) -- [IconStyle](#IconStyle) +- [ImageStyle](#ImageStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) - [LineArrow](#LineArrow) @@ -128,7 +131,7 @@ - [AreaStyle](#AreaStyle) - [Emphasis](#Emphasis) -- [IconStyle](#IconStyle) +- [ImageStyle](#ImageStyle) - [ItemStyle](#ItemStyle) - [LabelLine](#LabelLine) - [LabelStyle](#LabelStyle) @@ -242,7 +245,6 @@ Inherits or Implemented: [MainComponent](#MainComponent) | `inverse` |false | 是否反向坐标轴。在类目轴中无效。 | | `clockwise` |true | 刻度增长是否按顺时针,默认顺时针。 | | `insertDataToHead` | | 添加新数据时是在列表的头部还是尾部加入。 | -| `iconStyle` | | 图标样式。 [IconStyle](IconStyle)| | `icons` | | 类目数据对应的图标。 | | `data` | | 类目数据,在类目轴(type: 'category')中有效。 | | `axisLine` | | [AxisLine](AxisLine)| @@ -254,26 +256,19 @@ Inherits or Implemented: [MainComponent](#MainComponent) ## `AxisLabel` -Inherits or Implemented: [ChildComponent](#ChildComponent) +Inherits or Implemented: [LabelStyle](#LabelStyle) 坐标轴刻度标签的相关设置。 |field|default|comment| |--|--|--| -| `show` |true | 是否显示刻度标签。 | -| `formatter` | | | | `interval` |0 | 坐标轴刻度标签的显示间隔,在类目轴中有效。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。 | | `inside` |false | 刻度标签是否朝内,默认朝外。 | -| `distance` | | 刻度标签与轴线之间的距离。 | -| `numericFormatter` | | 标准数字格式字符串。用于将数值格式化显示为字符串。 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings | | `showAsPositiveNumber` |false | 将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。 | | `onZero` |false | 刻度标签显示在0刻度上。 | -| `width` |0f | 文本的宽。为0时会自动匹配。 | -| `height` |0f | 文本的高。为0时会自动匹配。 | | `showStartLabel` |true | 是否显示第一个文本。 | | `showEndLabel` |true | 是否显示最后一个文本。 | | `textLimit` | | 文本限制。 [TextLimit](TextLimit)| -| `textStyle` | | 文本样式。 [TextStyle](TextStyle)| ## `AxisLine` @@ -297,9 +292,7 @@ Inherits or Implemented: [ChildComponent](#ChildComponent) |--|--|--| | `show` | | 是否显示坐标名称。 | | `name` | | 坐标轴名称。 | -| `formatter` | | 指示器名称显示的格式器。可用在雷达图。 | -| `location` | | 坐标轴名称显示位置。
`AxisName.Location`:
- `Start`: 坐标轴名称显示位置。
- `Middle`: 坐标轴名称显示位置。
- `End`: 坐标轴名称显示位置。
- `align`: 对齐方式。
- `left`: 离容器左侧的距离。
- `right`: 离容器右侧的距离。
- `top`: 离容器上侧的距离。
- `bottom`: 离容器下侧的距离。
| -| `textStyle` | | 文本样式。 [TextStyle](TextStyle)| +| `labelStyle` | | 文本样式。 [LabelStyle](LabelStyle)| ## `AxisSplitArea` @@ -474,7 +467,7 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息 | `minShowNum` |1 | 最小显示数据个数。当DataZoom放大到最大时,最小显示的数据个数。 | | `scrollSensitivity` |1.1f | 缩放区域组件的敏感度。值越高每次缩放所代表的数据越多。 | | `orient` | | 布局方式是横还是竖。不仅是布局方式,对于直角坐标系而言,也决定了,缺省情况控制横向数轴还是纵向数轴。
`Orient`:
- `Horizonal`: 水平
- `Vertical`: 垂直
| -| `textStyle` | | 文字格式。 [TextStyle](TextStyle)| +| `labelStyle` | | 文本标签格式。 [LabelStyle](LabelStyle)| | `lineStyle` | | 阴影线条样式。 [LineStyle](LineStyle)| | `areaStyle` | | 阴影填充样式。 [AreaStyle](AreaStyle)| @@ -500,7 +493,7 @@ Inherits or Implemented: [ComponentTheme](#ComponentTheme) | `showDebugInfo` |false | | | `showAllChartObject` |false | | | `foldSeries` |false | | -| `debugInfoTextStyle` | | [TextStyle](TextStyle)| +| `labelStyle` | | [LabelStyle](LabelStyle)| ## `EffectScatter` @@ -550,20 +543,35 @@ Inherits or Implemented: [Serie](#Serie),[INeedSerieContainer](#INeedSerieContai ## `IconStyle` -Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) +Inherits or Implemented: [ChildComponent](#ChildComponent) |field|default|comment| |--|--|--| | `show` |false | 是否显示图标。 | -| `layer` | | 显示在上层还是在下层。
`IconStyle.Layer`:
- `UnderLabel`:
- `AboveLabel`:
| +| `layer` | | 显示在上层还是在下层。
`IconStyle.Layer`:
- `UnderText`: The icon is display under the label text. 图标在标签文字下
- `AboveText`: The icon is display above the label text. 图标在标签文字上
| | `align` | | 水平方向对齐方式。
`Align`:
- `Center`: 对齐方式
- `Left`: 对齐方式
- `Right`: 对齐方式
| | `sprite` | | 图标的图片。 | +| `type` | | 图片的显示类型。 | | `color` | | 图标颜色。 | | `width` |20 | 图标宽。 | | `height` |20 | 图标高。 | | `offset` | | 图标偏移。 | | `autoHideWhenLabelEmpty` |false | 当label内容为空时是否自动隐藏图标 | +## `ImageStyle` + +Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent](#ISerieExtraComponent),[ISerieDataComponent](#ISerieDataComponent) + +|field|default|comment| +|--|--|--| +| `show` |true | 是否显示图标。 | +| `sprite` | | 图标的图片。 | +| `type` | | 图片的显示类型。 | +| `autoColor` | | 是否自动颜色。 | +| `color` | | 图标颜色。 | +| `width` |0 | 图标宽。 | +| `height` |0 | 图标高。 | + ## `Indicator` 雷达图的指示器,用来指定雷达图中的多个变量(维度)。 @@ -611,6 +619,7 @@ Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieDataComponent] | `centerColor` | | 中心区域颜色。 | | `centerGap` | | 中心区域间隙。 | | `borderWidth` |0 | 边框宽。 | +| `borderGap` |0 | 边框间隙。 | | `borderColor` | | 边框的颜色。 | | `borderColor0` | | 边框的颜色。 | | `borderToColor` | | 边框的渐变色。 | @@ -644,15 +653,17 @@ Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieExtraComponent |--|--|--| | `show` |true | 是否显示文本标签。 | | `Position` | | | +| `autoOffset` |false | 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。 | | `offset` | | 距离图形元素的偏移 | +| `rotate` | | 文本的旋转。 | | `distance` | | 距离轴线的距离。 | | `formatter` | | | -| `paddingLeftRight` |2f | 左右边距。 | -| `paddingTopBottom` |2f | 上下边距。 | -| `backgroundWidth` |0 | 标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。 | -| `backgroundHeight` |0 | 标签的背景高度。一般不用指定,不指定时则自动是文字的高度。 | | `numericFormatter` | | 标准数字格式字符串。用于将数值格式化显示为字符串。 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings | -| `autoOffset` |false | 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。 | +| `width` |0 | 标签的宽度。一般不用指定,不指定时则自动是文字的宽度。 | +| `height` |0 | 标签的高度。一般不用指定,不指定时则自动是文字的高度。 | +| `icon` | | 图标样式。 [IconStyle](IconStyle)| +| `background` | | 背景图样式。 [ImageStyle](ImageStyle)| +| `textPadding` | | 文本的边距。 [TextPadding](TextPadding)| | `textStyle` | | 文本样式。 [TextStyle](TextStyle)| ## `Lang` @@ -680,14 +691,14 @@ Inherits or Implemented: [MainComponent](#MainComponent),[IPropertyChanged](#IPr | `iconType` | | 图例类型。 [default:Type.Auto]
`Painter.Type`:
- `Base`:
- `Serie`:
- `Top`:
| | `selectedMode` | | 选择模式。控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。 [default:SelectedMode.Multiple]
`VisualMap.SelectedMode`:
- `Multiple`: 多选。
- `Single`: 单选。
| | `orient` | | 布局方式是横还是竖。 [default:Orient.Horizonal]
`Orient`:
- `Horizonal`: 水平
- `Vertical`: 垂直
| -| `location` | | 图例显示的位置。 [default:Location.defaultTop]
`AxisName.Location`:
- `Start`: 坐标轴名称显示位置。
- `Middle`: 坐标轴名称显示位置。
- `End`: 坐标轴名称显示位置。
- `align`: 对齐方式。
- `left`: 离容器左侧的距离。
- `right`: 离容器右侧的距离。
- `top`: 离容器上侧的距离。
- `bottom`: 离容器下侧的距离。
| +| `location` | | 图例显示的位置。 [default:Location.defaultTop] [Location](Location)| | `itemWidth` |25.0f | 图例标记的图形宽度。 [default:24f] | | `itemHeight` |12.0f | 图例标记的图形高度。 [default:12f] | | `itemGap` |10f | 图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。 [default:10f] | | `itemAutoColor` |true | 图例标记的图形是否自动匹配颜色。 [default:true] | | `textAutoColor` |false | 图例标记的文本是否自动匹配颜色。 [default:false] | | `formatter` | | | -| `textStyle` | | 文本样式。 [TextStyle](TextStyle)| +| `labelStyle` | | 文本样式。 [LabelStyle](LabelStyle)| | `data` | | If data is not specified, it will be auto collected from series. | | `icons` | | 自定义的图例标记图形。 | @@ -750,6 +761,20 @@ Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieDataComponent] | `length` |0 | | | `opacity` |1 | 线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 | +## `Location` + +Inherits or Implemented: [ChildComponent](#ChildComponent),[IPropertyChanged](#IPropertyChanged) + +位置类型。通过Align快速设置大体位置,再通过left,right,top,bottom微调具体位置。 + +|field|default|comment| +|--|--|--| +| `align` | | 对齐方式。
`Align`:
- `Center`: 对齐方式
- `Left`: 对齐方式
- `Right`: 对齐方式
| +| `left` | | 离容器左侧的距离。 | +| `right` | | 离容器右侧的距离。 | +| `top` | | 离容器上侧的距离。 | +| `bottom` | | 离容器下侧的距离。 | + ## `MainComponent` Inherits or Implemented: [IComparable](#IComparable) @@ -920,7 +945,6 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable) | `endLabels` | | | | `lineArrows` | | | | `areaStyles` | | | -| `iconStyles` | | | | `titleStyles` | | | | `emphases` | | | | `index` | | 系列索引。 | @@ -1008,7 +1032,6 @@ Inherits or Implemented: [ChildComponent](#ChildComponent) | `labelLines` | | | | `emphases` | | | | `symbols` | | | -| `iconStyles` | | | | `lineStyles` | | | | `areaStyles` | | | | `titleStyles` | | | @@ -1145,6 +1168,20 @@ Inherits or Implemented: [ChildComponent](#ChildComponent) | `gap` |1 | 两边留白像素距离。 [default:10f] | | `suffix` | | 长度超出时的后缀。 [default: "..."] | +## `TextPadding` + +Inherits or Implemented: [ChildComponent](#ChildComponent) + +文本的内边距设置。 + +|field|default|comment| +|--|--|--| +| `show` |true | | +| `top` |2 | | +| `right` |4 | | +| `left` |4 | | +| `bottom` |2 | | + ## `TextStyle` Inherits or Implemented: [ChildComponent](#ChildComponent) @@ -1153,16 +1190,13 @@ Inherits or Implemented: [ChildComponent](#ChildComponent) |field|default|comment| |--|--|--| +| `show` |true | 文本的相关设置。 | | `font` | | 文本字体。 [default: null] | | `autoWrap` |false | 是否自动换行。 | | `autoAlign` |true | 文本是否让系统自动选对齐方式。为false时才会用alignment。 | | `rotate` |0 | 文本的旋转。 [default: `0f`] | -| `extraWidth` |0 | 额外的宽度 | -| `offset` |Vector2.zero | 坐标偏移。 [Default: `Vector2.zero`] | | `autoColor` |false | 是否开启自动颜色。当开启时,会自动设置颜色。 | | `color` | | 文本的颜色。 [default: `Color.clear`] | -| `autoBackgroundColor` |false | | -| `backgroundColor` | | 文本的背景颜色。 [default: `Color.clear`] | | `fontSize` |0 | 文本字体大小。 [default: 18] | | `fontStyle` | | 文本字体的风格。 [default: FontStyle.Normal] | | `lineSpacing` |1f | 行间距。 [default: 1f] | @@ -1222,23 +1256,18 @@ Inherits or Implemented: [MainComponent](#MainComponent),[IPropertyChanged](#IPr |--|--|--| | `show` |true | 是否显示标题组件。 | | `text` | | 主标题文本,支持使用 \n 换行。 | -| `textStyle` | | 主标题文本样式。 [TextStyle](TextStyle)| | `subText` | | 副标题文本,支持使用 \n 换行。 | -| `subTextStyle` | | 副标题文本样式。 [TextStyle](TextStyle)| +| `labelStyle` | | 主标题文本样式。 [LabelStyle](LabelStyle)| +| `subLabelStyle` | | 副标题文本样式。 [LabelStyle](LabelStyle)| | `itemGap` |0 | 主副标题之间的间距。 | -| `location` | | 标题显示位置。
`AxisName.Location`:
- `Start`: 坐标轴名称显示位置。
- `Middle`: 坐标轴名称显示位置。
- `End`: 坐标轴名称显示位置。
- `align`: 对齐方式。
- `left`: 离容器左侧的距离。
- `right`: 离容器右侧的距离。
- `top`: 离容器上侧的距离。
- `bottom`: 离容器下侧的距离。
| +| `location` | | 标题显示位置。 [Location](Location)| ## `TitleStyle` -Inherits or Implemented: [ChildComponent](#ChildComponent),[ISerieDataComponent](#ISerieDataComponent),[ISerieExtraComponent](#ISerieExtraComponent) +Inherits or Implemented: [LabelStyle](#LabelStyle),[ISerieDataComponent](#ISerieDataComponent),[ISerieExtraComponent](#ISerieExtraComponent) 标题相关设置。 -|field|default|comment| -|--|--|--| -| `show` |true | 是否显示标题。 | -| `offsetCenter` |Vector2(0, -0.2f) | 相对于中心的偏移位置。 | -| `textStyle` | | 文本的颜色。 [TextStyle](TextStyle)| ## `TitleTheme` @@ -1282,9 +1311,9 @@ Inherits or Implemented: [MainComponent](#MainComponent) | `itemHeight` |25f | | | `borderColor` |Color32(230, 230, 230, 255) | 边框颜色。 | | `lineStyle` | | 指示线样式。 [LineStyle](LineStyle)| -| `labelTextStyle` | | 提示框标签的文本样式。 [TextStyle](TextStyle)| -| `titleTextStyle` | | 标题的文本样式。 [TextStyle](TextStyle)| -| `columnsTextStyle` | | | +| `indicatorLabelStyle` | | 提示框的坐标轴指示器文本的样式。 [LabelStyle](LabelStyle)| +| `titleLabelStyle` | | 标题的文本样式。 [LabelStyle](LabelStyle)| +| `contentLabelStyles` | | | ## `TooltipTheme` @@ -1328,7 +1357,7 @@ Inherits or Implemented: [MainComponent](#MainComponent) | `hoverLink` |true | Conversely, when the mouse hovers over a graphic element in a diagram, the corresponding value of the visualMap component is triangulated in the corresponding position. | | `autoMinMax` |true | Automatically set min, Max value 自动设置min,max的值 | | `orient` | | 布局方式是横还是竖。
`Orient`:
- `Horizonal`: 水平
- `Vertical`: 垂直
| -| `location` | | 组件显示的位置。
`AxisName.Location`:
- `Start`: 坐标轴名称显示位置。
- `Middle`: 坐标轴名称显示位置。
- `End`: 坐标轴名称显示位置。
- `align`: 对齐方式。
- `left`: 离容器左侧的距离。
- `right`: 离容器右侧的距离。
- `top`: 离容器上侧的距离。
- `bottom`: 离容器下侧的距离。
| +| `location` | | 组件显示的位置。 [Location](Location)| | `workOnLine` |true | 组件是否对LineChart的LineStyle有效。 | | `workOnArea` |false | 组件是否对LineChart的AreaStyle有效。 | | `inRange` | | 定义 在选中范围中 的视觉颜色。 | diff --git a/Editor/ChildComponents/DebugInfoDrawer.cs b/Editor/ChildComponents/DebugInfoDrawer.cs index b3eb0fd3..5159dec1 100644 --- a/Editor/ChildComponents/DebugInfoDrawer.cs +++ b/Editor/ChildComponents/DebugInfoDrawer.cs @@ -18,7 +18,7 @@ namespace XCharts.Editor PropertyField(prop, "m_FoldSeries"); PropertyField(prop, "m_ShowDebugInfo"); PropertyField(prop, "m_ShowAllChartObject"); - PropertyField(prop, "m_DebugInfoTextStyle"); + PropertyField(prop, "m_LabelStyle"); --EditorGUI.indentLevel; } } diff --git a/Editor/ChildComponents/IconStyleDrawer.cs b/Editor/ChildComponents/IconStyleDrawer.cs index f63d9ee2..803179d5 100644 --- a/Editor/ChildComponents/IconStyleDrawer.cs +++ b/Editor/ChildComponents/IconStyleDrawer.cs @@ -18,6 +18,7 @@ namespace XCharts.Editor PropertyField(prop, "m_Layer"); PropertyField(prop, "m_Align"); PropertyField(prop, "m_Sprite"); + PropertyField(prop, "m_Type"); PropertyField(prop, "m_Color"); PropertyField(prop, "m_Width"); PropertyField(prop, "m_Height"); diff --git a/Editor/ChildComponents/ImageStyleDrawer.cs b/Editor/ChildComponents/ImageStyleDrawer.cs new file mode 100644 index 00000000..973d923d --- /dev/null +++ b/Editor/ChildComponents/ImageStyleDrawer.cs @@ -0,0 +1,28 @@ + +using UnityEditor; +using UnityEngine; +using XCharts.Runtime; + +namespace XCharts.Editor +{ + [CustomPropertyDrawer(typeof(ImageStyle), true)] + public class ImageStyleDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "ImageStyle"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeComponentFoldout(prop, "m_Show", true)) + { + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Sprite"); + PropertyField(prop, "m_Type"); + PropertyField(prop, "m_AutoColor"); + PropertyField(prop, "m_Color"); + PropertyField(prop, "m_Width"); + PropertyField(prop, "m_Height"); + --EditorGUI.indentLevel; + } + } + } +} \ No newline at end of file diff --git a/Editor/ChildComponents/ImageStyleDrawer.cs.meta b/Editor/ChildComponents/ImageStyleDrawer.cs.meta new file mode 100644 index 00000000..6907fec4 --- /dev/null +++ b/Editor/ChildComponents/ImageStyleDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4649856b17dfd4f628eb975040fb791c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ChildComponents/LabelStyleDrawer.cs b/Editor/ChildComponents/LabelStyleDrawer.cs index 07ac205f..04117877 100644 --- a/Editor/ChildComponents/LabelStyleDrawer.cs +++ b/Editor/ChildComponents/LabelStyleDrawer.cs @@ -16,17 +16,18 @@ namespace XCharts.Editor { ++EditorGUI.indentLevel; PropertyField(prop, "m_Position"); - PropertyField(prop, "m_Offset"); - PropertyField(prop, "m_AutoOffset"); - PropertyField(prop, "m_Rotate"); - PropertyField(prop, "m_Distance"); PropertyField(prop, "m_Formatter"); PropertyField(prop, "m_NumericFormatter"); - PropertyField(prop, "m_BackgroundWidth"); - PropertyField(prop, "m_BackgroundHeight"); - PropertyField(prop, "m_PaddingLeftRight"); - PropertyField(prop, "m_PaddingTopBottom"); + PropertyField(prop, "m_AutoOffset"); + PropertyField(prop, "m_Offset"); + PropertyField(prop, "m_Distance"); + PropertyField(prop, "m_Rotate"); + PropertyField(prop, "m_Width"); + PropertyField(prop, "m_Height"); + PropertyField(prop, "m_Icon"); + PropertyField(prop, "m_Background"); PropertyField(prop, "m_TextStyle"); + PropertyField(prop, "m_TextPadding"); --EditorGUI.indentLevel; } } @@ -35,6 +36,6 @@ namespace XCharts.Editor [CustomPropertyDrawer(typeof(EndLabelStyle), true)] public class EndLabelStyleDrawer : LabelStyleDrawer { - public override string ClassName { get { return "EndLabel"; } } + public override string ClassName { get { return "End Label"; } } } } \ No newline at end of file diff --git a/Editor/ChildComponents/TextPaddingDrawer.cs b/Editor/ChildComponents/TextPaddingDrawer.cs new file mode 100644 index 00000000..e6821a40 --- /dev/null +++ b/Editor/ChildComponents/TextPaddingDrawer.cs @@ -0,0 +1,26 @@ + +using UnityEditor; +using UnityEngine; +using XCharts.Runtime; + +namespace XCharts.Editor +{ + [CustomPropertyDrawer(typeof(TextPadding), true)] + public class TextPaddingDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "Padding"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeComponentFoldout(prop, "m_Show", true)) + { + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Top"); + PropertyField(prop, "m_Right"); + PropertyField(prop, "m_Bottom"); + PropertyField(prop, "m_Left"); + --EditorGUI.indentLevel; + } + } + } +} \ No newline at end of file diff --git a/Editor/ChildComponents/TextPaddingDrawer.cs.meta b/Editor/ChildComponents/TextPaddingDrawer.cs.meta new file mode 100644 index 00000000..dccf74b0 --- /dev/null +++ b/Editor/ChildComponents/TextPaddingDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 46cc25f4c9fc846938a06cf3b8fc75bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ChildComponents/TextStyleDrawer.cs b/Editor/ChildComponents/TextStyleDrawer.cs index 4774a159..800a58f0 100644 --- a/Editor/ChildComponents/TextStyleDrawer.cs +++ b/Editor/ChildComponents/TextStyleDrawer.cs @@ -15,7 +15,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "", true)) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; #if dUI_TextMeshPro @@ -24,12 +24,8 @@ namespace XCharts.Editor PropertyField(prop, "m_Font"); #endif PropertyField(prop, "m_Rotate"); - PropertyField(prop, "m_Offset"); - PropertyField(prop, "m_ExtraWidth"); PropertyField(prop, "m_AutoColor"); PropertyField(prop, "m_Color"); - PropertyField(prop, "m_AutoBackgroundColor"); - PropertyField(prop, "m_BackgroundColor"); PropertyField(prop, "m_FontSize"); PropertyField(prop, "m_LineSpacing"); #if dUI_TextMeshPro @@ -38,8 +34,8 @@ namespace XCharts.Editor #else PropertyField(prop, "m_FontStyle"); PropertyField(prop, "m_Alignment"); - PropertyField(prop, "m_AutoWrap"); PropertyField(prop, "m_AutoAlign"); + PropertyField(prop, "m_AutoWrap"); #endif --EditorGUI.indentLevel; } diff --git a/Editor/ChildComponents/TitleStyleDrawer.cs b/Editor/ChildComponents/TitleStyleDrawer.cs index 3ee73441..98c4384c 100644 --- a/Editor/ChildComponents/TitleStyleDrawer.cs +++ b/Editor/ChildComponents/TitleStyleDrawer.cs @@ -5,19 +5,8 @@ using XCharts.Runtime; namespace XCharts.Editor { [CustomPropertyDrawer(typeof(TitleStyle), true)] - public class TitleStyleDrawer : BasePropertyDrawer + public class TitleStyleDrawer : LabelStyleDrawer { public override string ClassName { get { return "TitleStyle"; } } - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show", true)) - { - ++EditorGUI.indentLevel; - PropertyField(prop, "m_OffsetCenter"); - PropertyField(prop, "m_TextStyle"); - --EditorGUI.indentLevel; - } - } } } \ No newline at end of file diff --git a/Editor/MainComponents/AxisEditor.cs b/Editor/MainComponents/AxisEditor.cs index d1d0fb6b..15e57f17 100644 --- a/Editor/MainComponents/AxisEditor.cs +++ b/Editor/MainComponents/AxisEditor.cs @@ -80,7 +80,6 @@ namespace XCharts.Editor PropertyField("m_AxisLabel"); PropertyField("m_SplitLine"); PropertyField("m_SplitArea"); - PropertyField("m_IconStyle"); PropertyListField("m_Icons", true); if (type == Axis.AxisType.Category) { @@ -153,17 +152,22 @@ namespace XCharts.Editor ++EditorGUI.indentLevel; PropertyField(prop, "m_Inside"); PropertyField(prop, "m_Interval"); - PropertyField(prop, "m_Distance"); - PropertyField(prop, "m_Width"); - PropertyField(prop, "m_Height"); - PropertyField(prop, "m_Formatter"); - 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_Rotate"); + PropertyField(prop, "m_Distance"); + PropertyField(prop, "m_Formatter"); + PropertyField(prop, "m_NumericFormatter"); + PropertyField(prop, "m_Width"); + PropertyField(prop, "m_Height"); + PropertyField(prop, "m_Icon"); + PropertyField(prop, "m_Background"); PropertyField(prop, "m_TextStyle"); + PropertyField(prop, "m_Padding"); --EditorGUI.indentLevel; } } @@ -180,9 +184,7 @@ namespace XCharts.Editor { ++EditorGUI.indentLevel; PropertyField(prop, "m_Name"); - PropertyField(prop, "m_Formatter"); - PropertyField(prop, "m_Location"); - PropertyField(prop, "m_TextStyle"); + PropertyField(prop, "m_LabelStyle"); --EditorGUI.indentLevel; } } diff --git a/Editor/MainComponents/DataZoomEditor.cs b/Editor/MainComponents/DataZoomEditor.cs index d67461e5..81ca348e 100644 --- a/Editor/MainComponents/DataZoomEditor.cs +++ b/Editor/MainComponents/DataZoomEditor.cs @@ -46,9 +46,9 @@ namespace XCharts.Editor PropertyField("m_Bottom"); PropertyField("m_LineStyle"); PropertyField("m_AreaStyle"); + PropertyField("m_LabelStyle"); PropertyListField("m_XAxisIndexs", true); PropertyListField("m_YAxisIndexs", true); - PropertyField("m_TextStyle"); } else { diff --git a/Editor/MainComponents/LegendEditor.cs b/Editor/MainComponents/LegendEditor.cs index fd19f578..b9835e0f 100644 --- a/Editor/MainComponents/LegendEditor.cs +++ b/Editor/MainComponents/LegendEditor.cs @@ -19,7 +19,7 @@ namespace XCharts.Editor PropertyField("m_Orient"); PropertyField("m_Formatter"); PropertyField("m_Location"); - PropertyField("m_TextStyle"); + PropertyField("m_LabelStyle"); PropertyListField("m_Icons"); PropertyListField("m_Data"); --EditorGUI.indentLevel; diff --git a/Editor/MainComponents/TitleEditor.cs b/Editor/MainComponents/TitleEditor.cs index 2abf411b..5a275efa 100644 --- a/Editor/MainComponents/TitleEditor.cs +++ b/Editor/MainComponents/TitleEditor.cs @@ -14,8 +14,8 @@ namespace XCharts.Editor PropertyField("m_SubText"); PropertyField("m_ItemGap"); PropertyField("m_Location"); - PropertyField("m_TextStyle"); - PropertyField("m_SubTextStyle"); + PropertyField("m_LabelStyle"); + PropertyField("m_SubLabelStyle"); --EditorGUI.indentLevel; } } diff --git a/Editor/MainComponents/TooltipEditor.cs b/Editor/MainComponents/TooltipEditor.cs index fbb53cc6..902d7511 100644 --- a/Editor/MainComponents/TooltipEditor.cs +++ b/Editor/MainComponents/TooltipEditor.cs @@ -17,10 +17,10 @@ namespace XCharts.Editor PropertyField("m_TitleFormatter"); PropertyField("m_ItemFormatter"); PropertyField("m_NumericFormatter"); - PropertyField("m_TitleHeight"); - PropertyField("m_ItemHeight"); PropertyFiledMore(() => { + PropertyField("m_TitleHeight"); + PropertyField("m_ItemHeight"); PropertyField("m_Marker"); PropertyField("m_BorderWidth"); PropertyField("m_BorderColor"); @@ -40,9 +40,9 @@ namespace XCharts.Editor PropertyField("m_FixedY"); }); PropertyField("m_LineStyle"); - PropertyField("m_LabelTextStyle"); - PropertyField("m_TitleTextStyle"); - PropertyListField("m_ColumnsTextStyle"); + PropertyField("m_IndicatorLabelStyle"); + PropertyField("m_TitleLabelStyle"); + PropertyListField("m_ContentLabelStyles"); --EditorGUI.indentLevel; } } diff --git a/Editor/Series/SerieEditor.cs b/Editor/Series/SerieEditor.cs index 7d006c7d..b914381b 100644 --- a/Editor/Series/SerieEditor.cs +++ b/Editor/Series/SerieEditor.cs @@ -195,7 +195,6 @@ namespace XCharts.Editor var m_Id = serieData.FindPropertyRelative("m_Id"); var m_ParentId = serieData.FindPropertyRelative("m_ParentId"); - var m_IconStyle = serieData.FindPropertyRelative("m_IconStyles"); var m_Label = serieData.FindPropertyRelative("m_Labels"); var m_ItemStyle = serieData.FindPropertyRelative("m_ItemStyles"); var m_Emphasis = serieData.FindPropertyRelative("m_Emphases"); @@ -208,7 +207,7 @@ namespace XCharts.Editor PropertyField(m_Id); PropertyField(m_ParentId); - var componentNum = m_IconStyle.arraySize + m_Label.arraySize + m_ItemStyle.arraySize + m_Emphasis.arraySize + var componentNum = m_Label.arraySize + m_ItemStyle.arraySize + m_Emphasis.arraySize + m_Symbol.arraySize + m_LineStyle.arraySize + m_AreaStyle.arraySize; var title = "Component"; if (componentNum == 0) title += " (None)"; @@ -217,10 +216,6 @@ namespace XCharts.Editor { serie.GetSerieData(index).GetOrAddComponent(); }, m_ItemStyle.arraySize == 0), - new HeaderMenuInfo("Add IconStyle", () => - { - serie.GetSerieData(index).GetOrAddComponent(); - }, m_IconStyle.arraySize == 0), new HeaderMenuInfo("Add Label", () => { serie.GetSerieData(index).GetOrAddComponent(); @@ -249,10 +244,6 @@ namespace XCharts.Editor { serie.GetSerieData(index).RemoveComponent(); }, m_ItemStyle.arraySize > 0), - new HeaderMenuInfo("Remove IconStyle", () => - { - serie.GetSerieData(index).RemoveComponent(); - }, m_IconStyle.arraySize > 0), new HeaderMenuInfo("Remove Label", () => { serie.GetSerieData(index).RemoveComponent(); @@ -283,8 +274,6 @@ namespace XCharts.Editor }, componentNum > 0)); if (m_DataComponentFoldout) { - if (m_IconStyle.arraySize > 0) - PropertyField(m_IconStyle.GetArrayElementAtIndex(0)); if (m_Label.arraySize > 0) PropertyField(m_Label.GetArrayElementAtIndex(0)); if (m_ItemStyle.arraySize > 0) diff --git a/Examples/Runtime/Example10_LineChart.cs b/Examples/Runtime/Example10_LineChart.cs index a1eec75b..ed566ad3 100644 --- a/Examples/Runtime/Example10_LineChart.cs +++ b/Examples/Runtime/Example10_LineChart.cs @@ -222,7 +222,7 @@ namespace XCharts.Example yield return new WaitForSeconds(1); serie.label.textStyle.color = Color.white; - serie.label.textStyle.backgroundColor = Color.grey; + serie.label.background.color = Color.grey; serie.labelDirty = true; chart.RefreshChart(); yield return new WaitForSeconds(1); diff --git a/Examples/Runtime/Example13_LineSimple.cs b/Examples/Runtime/Example13_LineSimple.cs index ab3c177c..ed5b94ca 100644 --- a/Examples/Runtime/Example13_LineSimple.cs +++ b/Examples/Runtime/Example13_LineSimple.cs @@ -8,7 +8,16 @@ namespace XCharts.Example [ExecuteInEditMode] public class Example13_LineSimple : MonoBehaviour { - void Awake() + void Update() + { + if (Input.GetKeyDown(KeyCode.Space)) + { + AddData(); + //OnTestBtn(); + } + } + + void AddData() { var chart = gameObject.GetComponent(); if (chart == null) diff --git a/Runtime/Chart/PolarChart.cs b/Runtime/Chart/PolarChart.cs index 4c0b5258..77e24b2d 100644 --- a/Runtime/Chart/PolarChart.cs +++ b/Runtime/Chart/PolarChart.cs @@ -13,6 +13,8 @@ namespace XCharts.Runtime protected override void DefaultChart() { AddChartComponentWhenNoExist(); + AddChartComponentWhenNoExist(); + AddChartComponentWhenNoExist(); var tooltip = GetChartComponent(); tooltip.type = Tooltip.Type.Corss; diff --git a/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs b/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs index c2a2ee0a..5a06cbad 100644 --- a/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs +++ b/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs @@ -86,14 +86,14 @@ namespace XCharts.Runtime bool inside = axis.axisLabel.inside; var labelName = AxisHelper.GetLabelName(axis, total, i, axis.context.minValue, axis.context.maxValue, null, isPercentStack); - 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, - chart.theme.axis, labelName); - label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter)); + var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, + new Vector2(scaleAngle, txtHig), axis, + chart.theme.axis, labelName, Color.clear); + label.text.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter)); var pos = ChartHelper.GetPos(cenPos, radius + margin, isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true); AxisHelper.AdjustCircleLabelPos(label, pos, cenPos, txtHig, Vector3.zero); - if (i == 0) axis.axisLabel.SetRelatedText(label.label, scaleAngle); + if (i == 0) axis.axisLabel.SetRelatedText(label.text, scaleAngle); axis.context.labelObjectList.Add(label); totalAngle += scaleAngle; diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index aa1fef18..92ad2866 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -94,7 +94,6 @@ namespace XCharts.Runtime [SerializeField] protected bool m_Inverse = false; [SerializeField] private bool m_Clockwise = true; [SerializeField] private bool m_InsertDataToHead; - [SerializeField] private IconStyle m_IconStyle = new IconStyle(); [SerializeField] protected List m_Icons = new List(); [SerializeField] protected List m_Data = new List(); [SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine; @@ -362,14 +361,6 @@ namespace XCharts.Runtime get { return m_InsertDataToHead; } set { if (PropertyUtil.SetStruct(ref m_InsertDataToHead, value)) SetAllDirty(); } } - /// - /// 图标样式。 - /// - public IconStyle iconStyle - { - get { return m_IconStyle; } - set { if (PropertyUtil.SetClass(ref m_IconStyle, value)) SetAllDirty(); } - } public override bool vertsDirty { @@ -432,7 +423,6 @@ namespace XCharts.Runtime axis.logBaseE = logBaseE; axis.ceilRate = ceilRate; axis.insertDataToHead = insertDataToHead; - axis.iconStyle = iconStyle.Clone(); axis.axisLine = axisLine.Clone(); axis.axisName = axisName.Clone(); axis.axisTick = axisTick.Clone(); @@ -461,7 +451,6 @@ namespace XCharts.Runtime logBaseE = axis.logBaseE; ceilRate = axis.ceilRate; insertDataToHead = axis.insertDataToHead; - iconStyle.Copy(axis.iconStyle); axisLine.Copy(axis.axisLine); axisName.Copy(axis.axisName); axisTick.Copy(axis.axisTick); diff --git a/Runtime/Component/Axis/AxisContext.cs b/Runtime/Component/Axis/AxisContext.cs index 890fdbca..4ff255aa 100644 --- a/Runtime/Component/Axis/AxisContext.cs +++ b/Runtime/Component/Axis/AxisContext.cs @@ -104,7 +104,12 @@ namespace XCharts.Runtime else range = dataZoom.minShowNum; } - filterData = data.GetRange(start, range); + if (range > data.Count - start - 1) + start = data.Count - range - 1; + if (start >= 0) + filterData = data.GetRange(start, range); + else + filterData = data; } else { diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 007d165e..4b59206e 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -296,12 +296,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).x - pos.x; - label.SetLabelActive(dist > label.label.GetPreferredWidth()); + label.SetTextActive(dist > label.text.GetPreferredWidth()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.x - GetLabelPosition(0, i - 1).x; - label.SetLabelActive(dist > label.label.GetPreferredWidth()); + label.SetTextActive(dist > label.text.GetPreferredWidth()); } } else @@ -309,12 +309,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).y - pos.y; - label.SetLabelActive(dist > label.label.GetPreferredHeight()); + label.SetTextActive(dist > label.text.GetPreferredHeight()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.y - GetLabelPosition(0, i - 1).y; - label.SetLabelActive(dist > label.label.GetPreferredHeight()); + label.SetTextActive(dist > label.text.GetPreferredHeight()); } } } @@ -361,82 +361,36 @@ namespace XCharts ? axis.axisLabel.height : 20f; + var isPercentStack = SeriesHelper.IsPercentStack(chart.series); + var inside = axis.axisLabel.inside; + var defaultAlignment = orient == Orient.Horizonal ? TextAnchor.MiddleCenter : + ((inside && axis.IsLeft()) || (!inside && axis.IsRight()) + ? TextAnchor.MiddleLeft + : TextAnchor.MiddleRight); + if (axis.IsCategory() && axis.boundaryGap) - { splitNumber -= 1; - } for (int i = 0; i < splitNumber; i++) { - ChartLabel label; - var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom); - var inside = axis.axisLabel.inside; - var isPercentStack = SeriesHelper.IsPercentStack(chart.series); - var labelName = AxisHelper.GetLabelName(axis, axisLength, i, axis.context.minValue, axis.context.maxValue, dataZoom, isPercentStack); - if (orient == Orient.Horizonal) - { - label = ChartHelper.AddAxisLabelObject(splitNumber, i, - ChartCached.GetAxisLabelName(i), - axisObj.transform, - new Vector2(0.5f, 0.5f), - new Vector2(0.5f, 0.5f), - new Vector2(0.5f, 0.5f), - new Vector2(textWidth, textHeight), - axis, chart.theme.axis, labelName); - } - else - { - if ((inside && axis.IsLeft()) || (!inside && axis.IsRight())) - { - label = ChartHelper.AddAxisLabelObject(splitNumber, i, - ChartCached.GetAxisLabelName(i), - axisObj.transform, - Vector2.zero, - Vector2.zero, - new Vector2(0, 0.5f), - new Vector2(textWidth, textHeight), - axis, chart.theme.axis, labelName); - - label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft)); - } - else - { - label = ChartHelper.AddAxisLabelObject(splitNumber, i, - ChartCached.GetAxisLabelName(i), - axisObj.transform, - Vector2.zero, - Vector2.zero, - new Vector2(1, 0.5f), - new Vector2(textWidth, textHeight), - axis, chart.theme.axis, labelName); - - label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight)); - } - } + var label = ChartHelper.AddAxisLabelObject(splitNumber, i, + ChartCached.GetAxisLabelName(i), + axisObj.transform, + new Vector2(textWidth, textHeight), + axis, chart.theme.axis, labelName, + Color.clear, + defaultAlignment); if (i == 0) - axis.axisLabel.SetRelatedText(label.label, labelWidth); + axis.axisLabel.SetRelatedText(label.text, labelWidth); var pos = handler.GetLabelPosition(totalWidth + gapWidth, i); - - if (orient == Orient.Horizonal) - { - label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter)); - } - else - { - if (axis.IsRight()) - label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft)); - else - label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight)); - } - label.SetPosition(pos); handler.CheckValueLabelActive(axis, i, label, pos); @@ -446,59 +400,41 @@ namespace XCharts } if (axis.axisName.show) { - ChartText axisName = null; - - var axisNameTextStyle = axis.axisName.textStyle; - var offset = axisNameTextStyle.offset; - + ChartLabel label = null; var relativedDist = (relativedAxis == null ? 0 : relativedAxis.context.offset); var zeroPos = new Vector3(axisStartX, axisStartY + relativedDist); - + var offset = axis.axisName.labelStyle.offset; + var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor); if (orient == Orient.Horizonal) { - switch (axis.axisName.location) + switch (axis.axisName.labelStyle.position) { - case AxisName.Location.Start: + case LabelStyle.Position.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, chart.theme.axis); - - axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleRight)); - axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Top + label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, + chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleRight); + label.SetActive(axis.axisName.labelStyle.show); + label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(zeroPos.x - offset.x, axisStartY + relativedLength + offset.y + axis.offset) : new Vector2(zeroPos.x - offset.x, zeroPos.y + offset.y + axis.offset)); break; - case AxisName.Location.Middle: + case LabelStyle.Position.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, chart.theme.axis); - - axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter)); - axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Top + label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, + chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); + label.SetActive(axis.axisName.labelStyle.show); + label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY + relativedLength - offset.y + axis.offset) : new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY - offset.y + axis.offset)); break; - case AxisName.Location.End: + default: - 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, chart.theme.axis); - - axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleLeft)); - axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Top + label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, + chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleLeft); + label.SetActive(axis.axisName.labelStyle.show); + label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(axisStartX + axisLength + offset.x, axisStartY + relativedLength + offset.y + axis.offset) : new Vector2(axisStartX + axisLength + offset.x, zeroPos.y + offset.y + axis.offset)); break; @@ -506,43 +442,39 @@ namespace XCharts } else { - switch (axis.axisName.location) + switch (axis.axisName.labelStyle.position) { - case AxisName.Location.Start: + case LabelStyle.Position.Start: - 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, - chart.theme.axis); - axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter)); - axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Right ? + label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, + chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); + label.SetActive(axis.axisName.labelStyle.show); + label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY - offset.y) : new Vector2(zeroPos.x + offset.x + axis.offset, axisStartY - offset.y)); break; - case AxisName.Location.Middle: + case LabelStyle.Position.Middle: - 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, - chart.theme.axis); - axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleRight)); - axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Right ? - new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) : - new Vector2(axisStartX - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y)); + label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, + chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); + label.SetActive(axis.axisName.labelStyle.show); + label.SetPosition(axis.position == Axis.AxisPosition.Right ? + new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) : + new Vector2(axisStartX - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y)); break; - case AxisName.Location.End: - - 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, - chart.theme.axis); - axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter)); - axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Right ? + default: + //LabelStyle.Position + label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, + chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); + label.SetActive(axis.axisName.labelStyle.show); + label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY + axisLength + offset.y) : new Vector2(zeroPos.x + offset.x + axis.offset, axisStartY + axisLength + offset.y)); break; } } - axisName.SetText(axis.axisName.name); } } @@ -573,7 +505,7 @@ namespace XCharts else current += axisStartY - axis.axisLabel.distance - fontSize / 2; - return new Vector3(axisStartX + scaleWid, current) + axis.axisLabel.textStyle.offsetv3; + return new Vector3(axisStartX + scaleWid, current); } else { @@ -588,7 +520,7 @@ namespace XCharts else current += axisStartX - axis.axisLabel.distance; - return new Vector3(current, axisStartY + scaleWid) + axis.axisLabel.textStyle.offsetv3; + return new Vector3(current, axisStartY + scaleWid); } } diff --git a/Runtime/Component/Axis/AxisHelper.cs b/Runtime/Component/Axis/AxisHelper.cs index 5e9b1570..d25d8489 100644 --- a/Runtime/Component/Axis/AxisHelper.cs +++ b/Runtime/Component/Axis/AxisHelper.cs @@ -403,33 +403,11 @@ namespace XCharts.Runtime return true; } - public static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) - { - var txtWidth = txt.GetPreferredWidth(); - var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight()); - txt.SetSizeDelta(sizeDelta); - var diff = pos.x - cenPos.x; - if (diff < -1f) //left - { - pos = new Vector3(pos.x - txtWidth / 2, pos.y); - } - else if (diff > 1f) //right - { - pos = new Vector3(pos.x + txtWidth / 2, pos.y); - } - else - { - float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2; - pos = new Vector3(pos.x, y); - } - txt.SetLocalPosition(pos + offset); - } - public static void AdjustCircleLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) { - var txtWidth = txt.label.GetPreferredWidth(); - var sizeDelta = new Vector2(txtWidth, txt.label.GetPreferredHeight()); - txt.label.SetSizeDelta(sizeDelta); + var txtWidth = txt.text.GetPreferredWidth(); + var sizeDelta = new Vector2(txtWidth, txt.text.GetPreferredHeight()); + txt.text.SetSizeDelta(sizeDelta); var diff = pos.x - cenPos.x; if (diff < -1f) //left { @@ -447,11 +425,11 @@ namespace XCharts.Runtime txt.SetPosition(pos + offset); } - public static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) + public static void AdjustRadiusAxisLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) { - var txtWidth = txt.GetPreferredWidth(); - var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight()); - txt.SetSizeDelta(sizeDelta); + var txtWidth = txt.text.GetPreferredWidth(); + var sizeDelta = new Vector2(txtWidth, txt.text.GetPreferredHeight()); + txt.text.SetSizeDelta(sizeDelta); var diff = pos.y - cenPos.y; if (diff > 20f) //left { @@ -466,7 +444,7 @@ namespace XCharts.Runtime float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2; pos = new Vector3(pos.x, y); } - txt.SetLocalPosition(pos); + txt.SetPosition(pos); } public static float GetAxisPosition(GridCoord grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null) diff --git a/Runtime/Component/Axis/AxisLabel.cs b/Runtime/Component/Axis/AxisLabel.cs index 12298d9c..f90773ef 100644 --- a/Runtime/Component/Axis/AxisLabel.cs +++ b/Runtime/Component/Axis/AxisLabel.cs @@ -10,33 +10,16 @@ namespace XCharts.Runtime /// |坐标轴刻度标签的相关设置。 /// [Serializable] - public class AxisLabel : ChildComponent + public class AxisLabel : LabelStyle { - [SerializeField] private bool m_Show = true; - [SerializeField] private string m_Formatter; [SerializeField] private int m_Interval = 0; [SerializeField] private bool m_Inside = false; - [SerializeField] private float m_Distance; - [SerializeField] private string m_NumericFormatter = ""; [SerializeField] private bool m_ShowAsPositiveNumber = false; [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 AxisLabelFormatterFunction m_FormatterFunction; - /// - /// Set this to false to prevent the axis label from appearing. - /// |是否显示刻度标签。 - /// - public bool show - { - get { return m_Show; } - set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } - } /// /// The display interval of the axis label. /// |坐标轴刻度标签的显示间隔,在类目轴中有效。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。 @@ -55,38 +38,6 @@ namespace XCharts.Runtime get { return m_Inside; } set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetComponentDirty(); } } - /// - /// The distance between the axis label and the axis line. - /// |刻度标签与轴线之间的距离。 - /// - public float distance - { - get { return m_Distance; } - set { if (PropertyUtil.SetStruct(ref m_Distance, value)) SetComponentDirty(); } - } - /// - /// 图例内容字符串模版格式器。支持用 \n 换行。 - /// 模板变量为图例名称 {value}。 - /// - public string formatter - { - get { return m_Formatter; } - set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); } - } - - /// - /// Standard numeric format strings. - /// |标准数字格式字符串。用于将数值格式化显示为字符串。 - /// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。 - /// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings - /// - /// - public string numericFormatter - { - get { return m_NumericFormatter; } - set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } - } - /// /// Show negative number as positive number. /// |将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。 @@ -106,22 +57,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); } } /// - /// 文本的宽。为0时会自动匹配。 - /// - public float width - { - get { return m_Width; } - set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetComponentDirty(); } - } - /// - /// 文本的高。为0时会自动匹配。 - /// - public float height - { - get { return m_Height; } - set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); } - } - /// /// Whether to display the first label. /// |是否显示第一个文本。 /// @@ -148,21 +83,6 @@ namespace XCharts.Runtime set { if (value != null) { m_TextLimit = value; SetComponentDirty(); } } } - /// - /// The text style of axis name. - /// |文本样式。 - /// - public TextStyle textStyle - { - get { return m_TextStyle; } - set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } - } - - public AxisLabelFormatterFunction formatterFunction - { - set { m_FormatterFunction = value; } - } - public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } } public override void ClearComponentDirty() { @@ -185,7 +105,7 @@ namespace XCharts.Runtime } } - public AxisLabel Clone() + public new AxisLabel Clone() { var axisLabel = new AxisLabel(); axisLabel.show = show; diff --git a/Runtime/Component/Axis/AxisName.cs b/Runtime/Component/Axis/AxisName.cs index bf81085b..2e148644 100644 --- a/Runtime/Component/Axis/AxisName.cs +++ b/Runtime/Component/Axis/AxisName.cs @@ -11,21 +11,9 @@ namespace XCharts.Runtime [Serializable] public class AxisName : ChildComponent { - /// - /// the location of axis name. - /// |坐标轴名称显示位置。 - /// - public enum Location - { - Start, - Middle, - End - } [SerializeField] private bool m_Show; [SerializeField] private string m_Name; - [SerializeField] private string m_Formatter; - [SerializeField] private Location m_Location; - [SerializeField] private TextStyle m_TextStyle = new TextStyle(); + [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); /// /// Whether to show axis name. @@ -45,46 +33,28 @@ namespace XCharts.Runtime get { return m_Name; } set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); } } - /// - /// The formatter of indicator's name. - /// |指示器名称显示的格式器。可用在雷达图。 - /// - public string formatter - { - get { return m_Formatter; } - set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); } - } - /// - /// Location of axis name. - /// |坐标轴名称显示位置。 - /// - public Location location - { - get { return m_Location; } - set { if (PropertyUtil.SetStruct(ref m_Location, value)) SetComponentDirty(); } - } - /// /// The text style of axis name. /// |文本样式。 /// - public TextStyle textStyle + public LabelStyle labelStyle { - get { return m_TextStyle; } - set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + get { return m_LabelStyle; } + set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); } } public static AxisName defaultAxisName { get { - return new AxisName() + var axisName = new AxisName() { m_Show = false, m_Name = "axisName", - m_Location = Location.End, - m_TextStyle = new TextStyle(), + m_LabelStyle = new LabelStyle() }; + axisName.labelStyle.position = LabelStyle.Position.End; + return axisName; } } @@ -93,8 +63,7 @@ namespace XCharts.Runtime var axisName = new AxisName(); axisName.show = show; axisName.name = name; - axisName.location = location; - axisName.textStyle.Copy(textStyle); + axisName.m_LabelStyle.Copy(m_LabelStyle); return axisName; } @@ -102,8 +71,7 @@ namespace XCharts.Runtime { show = axisName.show; name = axisName.name; - location = axisName.location; - textStyle.Copy(axisName.textStyle); + m_LabelStyle.Copy(axisName.labelStyle); } } } \ No newline at end of file diff --git a/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs b/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs index 97615c82..6ffe00ed 100644 --- a/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs +++ b/Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs @@ -24,7 +24,6 @@ namespace XCharts.Runtime splitLine.show = false; splitLine.lineStyle.type = LineStyle.Type.None; axisLabel.textLimit.enable = true; - iconStyle.show = false; } diff --git a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs index c5e0d742..d33b5fae 100644 --- a/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs +++ b/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs @@ -109,18 +109,17 @@ namespace XCharts.Runtime var isPercentStack = SeriesHelper.IsPercentStack(chart.series); var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.context.minValue, axis.context.maxValue, null, isPercentStack); - 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, chart.theme.axis, - labelName); + var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, + new Vector2(labelWidth, txtHig), axis, chart.theme.axis, labelName, Color.clear); if (i == 0) - axis.axisLabel.SetRelatedText(label.label, labelWidth); + axis.axisLabel.SetRelatedText(label.text, labelWidth); - label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter)); + label.text.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter)); label.SetText(labelName); label.SetPosition(GetLabelPosition(polar, axis, angleAxis.context.startAngle, totalWidth)); label.SetActive(true); - label.SetLabelActive(true); + label.SetTextActive(true); axis.context.labelObjectList.Add(label); diff --git a/Runtime/Component/Axis/SingleAxis/SingleAxis.cs b/Runtime/Component/Axis/SingleAxis/SingleAxis.cs index 6a1f7b51..d167bed1 100644 --- a/Runtime/Component/Axis/SingleAxis/SingleAxis.cs +++ b/Runtime/Component/Axis/SingleAxis/SingleAxis.cs @@ -140,7 +140,6 @@ namespace XCharts.Runtime axisLabel.textLimit.enable = true; axisTick.showStartTick = true; axisTick.showEndTick = true; - iconStyle.show = false; } } } \ No newline at end of file diff --git a/Runtime/Component/Axis/XAxis/XAxis.cs b/Runtime/Component/Axis/XAxis/XAxis.cs index bd31a6c2..ed94ff14 100644 --- a/Runtime/Component/Axis/XAxis/XAxis.cs +++ b/Runtime/Component/Axis/XAxis/XAxis.cs @@ -28,7 +28,6 @@ namespace XCharts.Runtime splitLine.show = false; splitLine.lineStyle.type = LineStyle.Type.None; axisLabel.textLimit.enable = true; - iconStyle.show = false; } } } \ No newline at end of file diff --git a/Runtime/Component/Axis/YAxis/YAxis.cs b/Runtime/Component/Axis/YAxis/YAxis.cs index f24ad12e..003672e2 100644 --- a/Runtime/Component/Axis/YAxis/YAxis.cs +++ b/Runtime/Component/Axis/YAxis/YAxis.cs @@ -26,7 +26,6 @@ namespace XCharts.Runtime splitLine.lineStyle.type = LineStyle.Type.None; axisLabel.textLimit.enable = false; axisTick.showStartTick = true; - iconStyle.show = false; } } } \ No newline at end of file diff --git a/Runtime/Component/Child/IconStyle.cs b/Runtime/Component/Child/IconStyle.cs index 2569d8d0..1a8206b8 100644 --- a/Runtime/Component/Child/IconStyle.cs +++ b/Runtime/Component/Child/IconStyle.cs @@ -5,17 +5,26 @@ using UnityEngine.UI; namespace XCharts.Runtime { [System.Serializable] - public class IconStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent + public class IconStyle : ChildComponent { public enum Layer { - UnderLabel, - AboveLabel + /// + /// The icon is display under the label text. + /// 图标在标签文字下 + /// + UnderText, + /// + /// The icon is display above the label text. + /// 图标在标签文字上 + /// + AboveText } [SerializeField] private bool m_Show = false; [SerializeField] private Layer m_Layer; [SerializeField] private Align m_Align = Align.Left; [SerializeField] private Sprite m_Sprite; + [SerializeField] private Image.Type m_Type; [SerializeField] private Color m_Color = Color.white; [SerializeField] private float m_Width = 20; [SerializeField] private float m_Height = 20; @@ -25,7 +34,7 @@ namespace XCharts.Runtime public void Reset() { m_Show = false; - m_Layer = Layer.UnderLabel; + m_Layer = Layer.UnderText; m_Sprite = null; m_Color = Color.white; m_Width = 20; @@ -48,6 +57,11 @@ namespace XCharts.Runtime /// public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } } /// + /// How to display the icon. + /// |图片的显示类型。 + /// + public Image.Type type { get { return m_Type; } set { m_Type = value; } } + /// /// 图标颜色。 /// public Color color { get { return m_Color; } set { m_Color = value; } } @@ -77,6 +91,7 @@ namespace XCharts.Runtime iconStyle.show = show; iconStyle.layer = layer; iconStyle.sprite = sprite; + iconStyle.type = type; iconStyle.color = color; iconStyle.width = width; iconStyle.height = height; @@ -91,6 +106,7 @@ namespace XCharts.Runtime show = iconStyle.show; layer = iconStyle.layer; sprite = iconStyle.sprite; + type = iconStyle.type; color = iconStyle.color; width = iconStyle.width; height = iconStyle.height; diff --git a/Runtime/Component/Child/ImageStyle.cs b/Runtime/Component/Child/ImageStyle.cs new file mode 100644 index 00000000..6771b7fe --- /dev/null +++ b/Runtime/Component/Child/ImageStyle.cs @@ -0,0 +1,82 @@ + +using UnityEngine; +using UnityEngine.UI; + +namespace XCharts.Runtime +{ + [System.Serializable] + public class ImageStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent + { + [SerializeField] private bool m_Show = true; + [SerializeField] private Sprite m_Sprite; + [SerializeField] private Image.Type m_Type; + [SerializeField] private bool m_AutoColor; + [SerializeField] private Color m_Color = Color.clear; + [SerializeField] private float m_Width = 0; + [SerializeField] private float m_Height = 0; + + public void Reset() + { + m_Show = false; + m_Type = Image.Type.Simple; + m_Sprite = null; + m_AutoColor = false; + m_Color = Color.white; + m_Width = 0; + m_Height = 0; + } + + /// + /// Whether the data icon is show. + /// |是否显示图标。 + /// + public bool show { get { return m_Show; } set { m_Show = value; } } + /// + /// The image of icon. + /// |图标的图片。 + /// + public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } } + /// + /// How to display the image. + /// |图片的显示类型。 + /// + public Image.Type type { get { return m_Type; } set { m_Type = value; } } + /// + /// 是否自动颜色。 + /// + public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } } + /// + /// 图标颜色。 + /// + public Color color { get { return m_Color; } set { m_Color = value; } } + /// + /// 图标宽。 + /// + public float width { get { return m_Width; } set { m_Width = value; } } + /// + /// 图标高。 + /// + public float height { get { return m_Height; } set { m_Height = value; } } + public ImageStyle Clone() + { + var imageStyle = new ImageStyle(); + imageStyle.type = type; + imageStyle.sprite = sprite; + imageStyle.autoColor = autoColor; + imageStyle.color = color; + imageStyle.width = width; + imageStyle.height = height; + return imageStyle; + } + + public void Copy(ImageStyle imageStyle) + { + type = imageStyle.type; + sprite = imageStyle.sprite; + autoColor = imageStyle.autoColor; + color = imageStyle.color; + width = imageStyle.width; + height = imageStyle.height; + } + } +} diff --git a/Runtime/Component/Child/ImageStyle.cs.meta b/Runtime/Component/Child/ImageStyle.cs.meta new file mode 100644 index 00000000..8e9356e3 --- /dev/null +++ b/Runtime/Component/Child/ImageStyle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5a76d1129783c4f55b0773da2eda9b67 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Child/LabelStyle.cs b/Runtime/Component/Child/LabelStyle.cs index 0f941db2..ef0e3b41 100644 --- a/Runtime/Component/Child/LabelStyle.cs +++ b/Runtime/Component/Child/LabelStyle.cs @@ -15,6 +15,7 @@ namespace XCharts.Runtime /// public enum Position { + Default, /// /// Outside of sectors of pie chart, which relates to corresponding sector through visual guide line. /// |饼图扇区外侧,通过视觉引导线连到相应的扇区。 @@ -68,32 +69,31 @@ namespace XCharts.Runtime } [SerializeField] protected bool m_Show = true; - [SerializeField] Position m_Position = Position.Outside; + [SerializeField] Position m_Position = Position.Default; + [SerializeField] protected bool m_AutoOffset = false; [SerializeField] protected Vector3 m_Offset; [SerializeField] protected float m_Rotate; [SerializeField] protected float m_Distance; [SerializeField] protected string m_Formatter; - [SerializeField] protected float m_PaddingLeftRight = 2f; - [SerializeField] protected float m_PaddingTopBottom = 2f; - [SerializeField] protected float m_BackgroundWidth = 0; - [SerializeField] protected float m_BackgroundHeight = 0; [SerializeField] protected string m_NumericFormatter = ""; - [SerializeField] protected bool m_AutoOffset = false; - + [SerializeField] protected float m_Width = 0; + [SerializeField] protected float m_Height = 0; + + [SerializeField] protected IconStyle m_Icon = new IconStyle(); + [SerializeField] protected ImageStyle m_Background = new ImageStyle(); + [SerializeField] protected TextPadding m_TextPadding = new TextPadding(); [SerializeField] protected TextStyle m_TextStyle = new TextStyle(); - protected SerieLabelFormatterFunction m_FormatterFunction; + protected LabelFormatterFunction m_FormatterFunction; public void Reset() { m_Show = false; - m_Position = Position.Outside; + m_Position = Position.Default; m_Offset = Vector3.zero; m_Distance = 0; m_Rotate = 0; - m_PaddingLeftRight = 2f; - m_PaddingTopBottom = 2f; - m_BackgroundWidth = 0; - m_BackgroundHeight = 0; + m_Width = 0; + m_Height = 0; m_NumericFormatter = ""; m_AutoOffset = false; } @@ -161,42 +161,33 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Distance, value)) SetVerticesDirty(); } } /// - /// the width of background. If set as default value 0, it means than the background width auto set as the text width. - /// |标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。 + /// the width of label. If set as default value 0, it means than the label width auto set as the text width. + /// |标签的宽度。一般不用指定,不指定时则自动是文字的宽度。 /// /// - public float backgroundWidth + public float width { - get { return m_BackgroundWidth; } - set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); } + get { return m_Width; } + set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetComponentDirty(); } } /// - /// the height of background. If set as default value 0, it means than the background height auto set as the text height. - /// |标签的背景高度。一般不用指定,不指定时则自动是文字的高度。 + /// the height of label. If set as default value 0, it means than the label height auto set as the text height. + /// |标签的高度。一般不用指定,不指定时则自动是文字的高度。 /// /// - public float backgroundHeight + public float height { - get { return m_BackgroundHeight; } - set { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); } + get { return m_Height; } + set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); } } /// - /// the text padding of left and right. defaut:2. - /// |左右边距。 + /// the text padding of label. + /// |文本的边距。 /// - public float paddingLeftRight + public TextPadding textPadding { - get { return m_PaddingLeftRight; } - set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); } - } - /// - /// the text padding of top and bottom. defaut:2. - /// |上下边距。 - /// - public float paddingTopBottom - { - get { return m_PaddingTopBottom; } - set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); } + get { return m_TextPadding; } + set { if (PropertyUtil.SetClass(ref m_TextPadding, value)) SetComponentDirty(); } } /// /// Standard numeric format strings. @@ -218,8 +209,24 @@ namespace XCharts.Runtime get { return m_AutoOffset; } set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); } } - - + /// + /// the sytle of background. + /// |背景图样式。 + /// + public ImageStyle background + { + get { return m_Background; } + set { if (PropertyUtil.SetClass(ref m_Background, value)) SetAllDirty(); } + } + /// + /// the sytle of icon. + /// |图标样式。 + /// + public IconStyle icon + { + get { return m_Icon; } + set { if (PropertyUtil.SetClass(ref m_Icon, value)) SetAllDirty(); } + } /// /// the sytle of text. /// |文本样式。 @@ -229,8 +236,7 @@ namespace XCharts.Runtime get { return m_TextStyle; } set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); } } - - public SerieLabelFormatterFunction formatterFunction + public LabelFormatterFunction formatterFunction { get { return m_FormatterFunction; } set { m_FormatterFunction = value; } @@ -241,6 +247,11 @@ namespace XCharts.Runtime return position == Position.Inside || position == Position.Center; } + public bool IsAutoSize() + { + return width == 0 && height == 0; + } + public Vector3 GetOffset(float radius) { var x = ChartHelper.GetActualValue(m_Offset.x, radius); @@ -261,29 +272,42 @@ namespace XCharts.Runtime } } - public TextAnchor GetAutoAlignment() + public virtual LabelStyle Clone() { - if (textStyle.autoAlign) return textStyle.alignment; - else - { - switch (position) - { - case LabelStyle.Position.Inside: - case LabelStyle.Position.Center: - case LabelStyle.Position.Top: - case LabelStyle.Position.Bottom: - return TextAnchor.MiddleCenter; - case LabelStyle.Position.Outside: - case LabelStyle.Position.Right: - return TextAnchor.MiddleLeft; - case LabelStyle.Position.Left: - return TextAnchor.MiddleRight; - default: - return TextAnchor.MiddleCenter; - } - } + var label = new LabelStyle(); + label.m_Show = m_Show; + label.m_Position = m_Position; + label.m_Offset = m_Offset; + label.m_Rotate = m_Rotate; + label.m_Distance = m_Distance; + label.m_Formatter = m_Formatter; + label.m_Width = m_Width; + label.m_Height = m_Height; + label.m_NumericFormatter = m_NumericFormatter; + label.m_AutoOffset = m_AutoOffset; + label.m_Icon.Copy(m_Icon); + label.m_Background.Copy(m_Background); + label.m_TextPadding = m_TextPadding; + label.m_TextStyle.Copy(m_TextStyle); + return label; + } + + public virtual void Copy(LabelStyle label) + { + m_Show = label.m_Show; + m_Position = label.m_Position; + m_Offset = label.m_Offset; + m_Rotate = label.m_Rotate; + m_Distance = label.m_Distance; + m_Formatter = label.m_Formatter; + m_Width = label.m_Width; + m_Height = label.m_Height; + m_NumericFormatter = label.m_NumericFormatter; + m_AutoOffset = label.m_AutoOffset; + m_Icon.Copy(label.m_Icon); + m_Background.Copy(label.m_Background); + m_TextPadding = label.m_TextPadding; + m_TextStyle.Copy(label.m_TextStyle); } } - - } diff --git a/Runtime/Component/Child/TextPadding.cs b/Runtime/Component/Child/TextPadding.cs new file mode 100644 index 00000000..94dc7e52 --- /dev/null +++ b/Runtime/Component/Child/TextPadding.cs @@ -0,0 +1,61 @@ + +using System; +using UnityEngine; + +namespace XCharts.Runtime +{ + /// + /// Settings related to text. + /// |文本的内边距设置。 + /// + [Serializable] + public class TextPadding : ChildComponent + { + [SerializeField] private bool m_Show = true; + [SerializeField] private float m_Top = 2; + [SerializeField] private float m_Right = 4; + [SerializeField] private float m_Left = 4; + [SerializeField] private float m_Bottom = 2; + + public TextPadding() { } + + public TextPadding(float top, float right, float bottom, float left) + { + SetPadding(top, right, bottom, left); + } + + public void SetPadding(float top, float right, float bottom, float left) + { + m_Top = top; ; + m_Right = right; + m_Bottom = bottom; + m_Left = left; + } + + public bool show + { + get { return m_Show; } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } + } + public float top + { + get { return m_Top; } + set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetComponentDirty(); } + } + public float right + { + get { return m_Right; } + set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetComponentDirty(); } + } + public float bottom + { + get { return m_Bottom; } + set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetComponentDirty(); } + } + public float left + { + get { return m_Left; } + set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetComponentDirty(); } + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Child/TextPadding.cs.meta b/Runtime/Component/Child/TextPadding.cs.meta new file mode 100644 index 00000000..cff9472d --- /dev/null +++ b/Runtime/Component/Child/TextPadding.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 407bba126a0854199a4686b44cc9407e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Child/TextStyle.cs b/Runtime/Component/Child/TextStyle.cs index 5d5154e9..5b83798b 100644 --- a/Runtime/Component/Child/TextStyle.cs +++ b/Runtime/Component/Child/TextStyle.cs @@ -14,16 +14,13 @@ namespace XCharts.Runtime [Serializable] public class TextStyle : ChildComponent { + [SerializeField] private bool m_Show = true; [SerializeField] private Font m_Font; [SerializeField] private bool m_AutoWrap = false; [SerializeField] private bool m_AutoAlign = true; [SerializeField] private float m_Rotate = 0; - [SerializeField] private float m_ExtraWidth = 0; - [SerializeField] private Vector2 m_Offset = Vector2.zero; [SerializeField] private bool m_AutoColor = false; [SerializeField] private Color m_Color = Color.clear; - [SerializeField] private bool m_AutoBackgroundColor = false; - [SerializeField] private Color m_BackgroundColor = Color.clear; [SerializeField] private int m_FontSize = 0; [SerializeField] private FontStyle m_FontStyle = FontStyle.Normal; [SerializeField] private float m_LineSpacing = 1f; @@ -33,6 +30,11 @@ namespace XCharts.Runtime [SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal; [SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left; #endif + public bool show + { + get { return m_Show; } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } + } /// /// Rotation of text. /// |文本的旋转。 @@ -44,26 +46,6 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); } } /// - /// Extra width of text preferred width. - /// |额外的宽度 - /// - public float extraWidth - { - get { return m_ExtraWidth; } - set { if (PropertyUtil.SetStruct(ref m_ExtraWidth, value)) SetComponentDirty(); } - } - /// - /// the offset of position. - /// |坐标偏移。 - /// [Default: `Vector2.zero`] - /// - public Vector2 offset - { - get { return m_Offset; } - set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); } - } - public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } } - /// /// 是否开启自动颜色。当开启时,会自动设置颜色。 /// public bool autoColor @@ -81,21 +63,6 @@ namespace XCharts.Runtime get { return m_Color; } set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); } } - public bool autoBackgroundColor - { - get { return m_AutoBackgroundColor; } - set { if (PropertyUtil.SetStruct(ref m_AutoBackgroundColor, value)) SetComponentDirty(); } - } - /// - /// the color of text. - /// |文本的背景颜色。 - /// [default: `Color.clear`] - /// - public Color backgroundColor - { - get { return m_BackgroundColor; } - set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); } - } /// /// the font of text. When `null`, the theme's font is used by default. /// |文本字体。 @@ -172,11 +139,6 @@ namespace XCharts.Runtime get { return m_TMPFontStyle; } set { if (PropertyUtil.SetStruct(ref m_TMPFontStyle, value)) SetComponentDirty(); } } - public TextAlignmentOptions tmpAlignment - { - get { return m_TMPAlignment; } - set { if (PropertyUtil.SetStruct(ref m_TMPAlignment, value)) SetComponentDirty(); } - } #endif public TextStyle() @@ -213,11 +175,7 @@ namespace XCharts.Runtime { font = textStyle.font; rotate = textStyle.rotate; - offset = textStyle.offset; - autoColor = textStyle.autoColor; color = textStyle.color; - autoBackgroundColor = textStyle.autoBackgroundColor; - backgroundColor = textStyle.backgroundColor; fontSize = textStyle.fontSize; fontStyle = textStyle.fontStyle; lineSpacing = textStyle.lineSpacing; @@ -226,7 +184,6 @@ namespace XCharts.Runtime autoAlign = textStyle.autoAlign; #if dUI_TextMeshPro m_TMPFont = textStyle.tmpFont; - m_TMPAlignment = textStyle.tmpAlignment; m_TMPFontStyle = textStyle.tmpFontStyle; #endif } @@ -256,17 +213,9 @@ namespace XCharts.Runtime return fontSize; } - public TextAnchor GetAlignment(TextAnchor systemAlignment) + public TextAnchor GetAlignment(TextAnchor defaultAlignment) { - return m_AutoAlign ? systemAlignment : alignment; - } - - public Color32 GetBackgroundColor(Color32 chartBackgroundColor) - { - if (m_AutoColor || ChartHelper.IsClearColor(m_BackgroundColor)) - return chartBackgroundColor; - else - return m_BackgroundColor; + return m_AutoAlign ? defaultAlignment : alignment; } } } \ No newline at end of file diff --git a/Runtime/Component/DataZoom/DataZoom.cs b/Runtime/Component/DataZoom/DataZoom.cs index 6a31540c..da2399ec 100644 --- a/Runtime/Component/DataZoom/DataZoom.cs +++ b/Runtime/Component/DataZoom/DataZoom.cs @@ -87,7 +87,7 @@ namespace XCharts.Runtime [Range(1f, 20f)] [SerializeField] private float m_ScrollSensitivity = 1.1f; [SerializeField] private Orient m_Orient = Orient.Horizonal; - [SerializeField] private TextStyle m_TextStyle = new TextStyle(); + [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid); [SerializeField] private AreaStyle m_AreaStyle = new AreaStyle(); @@ -339,13 +339,13 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); } } /// - /// font style. - /// |文字格式。 + /// label style. + /// |文本标签格式。 /// - public TextStyle textStyle + public LabelStyle labelStyle { - get { return m_TextStyle; } - set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + get { return m_LabelStyle; } + set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); } } /// /// 阴影线条样式。 @@ -376,12 +376,12 @@ namespace XCharts.Runtime /// The start label. /// |组件的开始信息文本。 /// - private ChartText m_StartLabel { get; set; } + private ChartLabel m_StartLabel { get; set; } /// /// The end label. /// |组件的结束信息文本。 /// - private ChartText m_EndLabel { get; set; } + private ChartLabel m_EndLabel { get; set; } public override void SetDefaultValue() { @@ -402,7 +402,7 @@ namespace XCharts.Runtime end = 70; m_Orient = Orient.Horizonal; m_ScrollSensitivity = 10; - m_TextStyle = new TextStyle(); + m_LabelStyle = new LabelStyle(); m_LineStyle = new LineStyle(LineStyle.Type.Solid) { opacity = 0.3f @@ -562,14 +562,8 @@ namespace XCharts.Runtime /// internal void SetLabelActive(bool flag) { - if (m_StartLabel != null && m_StartLabel.gameObject.activeInHierarchy != flag) - { - m_StartLabel.gameObject.SetActive(flag); - } - if (m_EndLabel != null && m_EndLabel.gameObject.activeInHierarchy != flag) - { - m_EndLabel.gameObject.SetActive(flag); - } + m_StartLabel.SetActive(flag); + m_EndLabel.SetActive(flag); } /// @@ -590,24 +584,24 @@ namespace XCharts.Runtime if (m_EndLabel != null) m_EndLabel.SetText(text); } - internal void SetStartLabel(ChartText startLabel) + internal void SetStartLabel(ChartLabel startLabel) { m_StartLabel = startLabel; } - internal void SetEndLabel(ChartText endLabel) + internal void SetEndLabel(ChartLabel endLabel) { m_EndLabel = endLabel; } internal void UpdateStartLabelPosition(Vector3 pos) { - m_StartLabel.SetLocalPosition(pos); + m_StartLabel.SetPosition(pos); } internal void UpdateEndLabelPosition(Vector3 pos) { - m_EndLabel.SetLocalPosition(pos); + m_EndLabel.SetPosition(pos); } public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight) diff --git a/Runtime/Component/DataZoom/DataZoomHandler.cs b/Runtime/Component/DataZoom/DataZoomHandler.cs index 254a2599..0391233f 100644 --- a/Runtime/Component/DataZoom/DataZoomHandler.cs +++ b/Runtime/Component/DataZoom/DataZoomHandler.cs @@ -29,15 +29,13 @@ namespace XCharts.Runtime dataZoomObject.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(dataZoomObject); - var startLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "start", dataZoomObject.transform, - Vector2.zero, Vector2.zero, new Vector2(1, 0.5f), new Vector2(200, 20), dataZoom.textStyle, - chart.theme.dataZoom); - startLabel.SetAlignment(TextAnchor.MiddleRight); + var startLabel = ChartHelper.AddChartLabel(s_DefaultDataZoom + "start", dataZoomObject.transform, + dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleRight); + startLabel.gameObject.SetActive(true); - var endLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "end", dataZoomObject.transform, - Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20), dataZoom.textStyle, - chart.theme.dataZoom); - endLabel.SetAlignment(TextAnchor.MiddleLeft); + var endLabel = ChartHelper.AddChartLabel(s_DefaultDataZoom + "end", dataZoomObject.transform, + dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleLeft); + endLabel.gameObject.SetActive(true); dataZoom.SetStartLabel(startLabel); dataZoom.SetEndLabel(endLabel); diff --git a/Runtime/Component/Debug/DebugInfo.cs b/Runtime/Component/Debug/DebugInfo.cs index 7914e42b..9fd6fec1 100644 --- a/Runtime/Component/Debug/DebugInfo.cs +++ b/Runtime/Component/Debug/DebugInfo.cs @@ -9,18 +9,24 @@ namespace XCharts.Runtime [Serializable] public class DebugInfo { - #pragma warning disable 0414 +#pragma warning disable 0414 [SerializeField] private bool m_Show = true; - #pragma warning restore 0414 +#pragma warning restore 0414 [SerializeField] private bool m_ShowDebugInfo = false; [SerializeField] protected bool m_ShowAllChartObject = false; [SerializeField] protected bool m_FoldSeries = false; [SerializeField] - private TextStyle m_DebugInfoTextStyle = new TextStyle() + private LabelStyle m_LabelStyle = new LabelStyle() { - fontSize = 18, - backgroundColor = new Color32(32, 32, 32, 170), - color = Color.white + background = new ImageStyle() + { + color = new Color32(32, 32, 32, 170) + }, + textStyle = new TextStyle() + { + fontSize = 18, + color = Color.white + } }; private static StringBuilder s_Sb = new StringBuilder(); @@ -45,7 +51,7 @@ namespace XCharts.Runtime public void Init(BaseChart chart) { m_Chart = chart; - m_Label = AddDebugInfoObject("debug", chart.transform, m_DebugInfoTextStyle, chart.theme); + m_Label = AddDebugInfoObject("debug", chart.transform, m_LabelStyle, chart.theme); } public void Update() @@ -124,7 +130,7 @@ namespace XCharts.Runtime return total / list.Count; } - private ChartLabel AddDebugInfoObject(string name, Transform parent, TextStyle textStyle, + private ChartLabel AddDebugInfoObject(string name, Transform parent, LabelStyle labelStyle, ThemeStyle theme) { var anchorMax = new Vector2(0, 1); @@ -137,16 +143,9 @@ namespace XCharts.Runtime labelGameObject.hideFlags = m_Chart.chartHideFlags; ChartHelper.SetActive(labelGameObject, m_ShowDebugInfo); - var label = ChartHelper.GetOrAddComponent(labelGameObject); - label.labelBackground = label; - label.labelBackground.color = textStyle.backgroundColor; - label.labelBackground.raycastTarget = false; - label.label = ChartHelper.AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme.common); - label.SetAutoSize(true); - label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.UpperLeft)); - label.label.SetLocalPosition(new Vector2(3, -3)); - label.SetText("30"); - label.SetTextColor(textStyle.color); + var label = ChartHelper.AddChartLabel("info", labelGameObject.transform, labelStyle, theme.common, + "", Color.clear, TextAnchor.UpperLeft); + label.SetActive(labelStyle.show); return label; } } diff --git a/Runtime/Component/Legend/Legend.cs b/Runtime/Component/Legend/Legend.cs index f09489ae..f9842e1b 100644 --- a/Runtime/Component/Legend/Legend.cs +++ b/Runtime/Component/Legend/Legend.cs @@ -75,7 +75,7 @@ namespace XCharts.Runtime [SerializeField] private bool m_ItemAutoColor = true; [SerializeField] private bool m_TextAutoColor = false; [SerializeField] private string m_Formatter; - [SerializeField] private TextStyle m_TextStyle = new TextStyle() { offset = new Vector2(2f, 0), fontSize = 0 }; + [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); [SerializeField] private List m_Data = new List(); [SerializeField] private List m_Icons = new List(); @@ -195,10 +195,10 @@ namespace XCharts.Runtime /// the style of text. /// |文本样式。 /// - public TextStyle textStyle + public LabelStyle labelStyle { - get { return m_TextStyle; } - set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + get { return m_LabelStyle; } + set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); } } /// /// Data array of legend. An array item is usually a name representing string. (If it is a pie chart, @@ -229,14 +229,14 @@ namespace XCharts.Runtime /// public override bool componentDirty { - get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty; } + get { return m_ComponentDirty || location.componentDirty || labelStyle.componentDirty; } } public override void ClearComponentDirty() { base.ClearComponentDirty(); location.ClearComponentDirty(); - textStyle.ClearComponentDirty(); + labelStyle.ClearComponentDirty(); } /// diff --git a/Runtime/Component/Legend/LegendHandler.cs b/Runtime/Component/Legend/LegendHandler.cs index fce7fc36..f923aca9 100644 --- a/Runtime/Component/Legend/LegendHandler.cs +++ b/Runtime/Component/Legend/LegendHandler.cs @@ -21,7 +21,7 @@ namespace XCharts.Runtime public override void CheckComponent(System.Text.StringBuilder sb) { var legend = component; - if (ChartHelper.IsColorAlphaZero(legend.textStyle.color)) + if (ChartHelper.IsColorAlphaZero(legend.labelStyle.textStyle.color)) sb.AppendFormat("warning:legend{0}->textStyle->color alpha is 0\n", legend.index); var serieNameList = SeriesHelper.GetLegalSerieNameList(chart.series); if (serieNameList.Count == 0) diff --git a/Runtime/Component/Legend/LegendHelper.cs b/Runtime/Component/Legend/LegendHelper.cs index 9b82353d..297f56a1 100644 --- a/Runtime/Component/Legend/LegendHelper.cs +++ b/Runtime/Component/Legend/LegendHelper.cs @@ -8,7 +8,7 @@ namespace XCharts.Runtime { public static Color GetContentColor(int legendIndex, Legend legend, ThemeStyle theme, bool active) { - var textStyle = legend.textStyle; + var textStyle = legend.labelStyle.textStyle; if (active) { if (legend.textAutoColor) return theme.GetColor(legendIndex); @@ -40,7 +40,7 @@ namespace XCharts.Runtime var pivot = new Vector2(0, 0.5f); var sizeDelta = new Vector2(100, 30); var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight); - var textStyle = legend.textStyle; + var textStyle = legend.labelStyle.textStyle; var contentColor = GetContentColor(legendIndex, legend, theme, active); var objAnchorMin = new Vector2(0, 1); @@ -48,16 +48,15 @@ namespace XCharts.Runtime var objPivot = new Vector2(0, 1); var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta, i); var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta); - var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta); var img = ChartHelper.GetOrAddComponent(btnObj); img.color = Color.clear; ChartHelper.GetOrAddComponent - public TextStyle textStyle + public LabelStyle labelStyle { - get { return m_TextStyle; } - set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + get { return m_LabelStyle; } + set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); } } /// /// Subtitle text, supporting for \n for newlines. @@ -53,10 +53,10 @@ namespace XCharts.Runtime /// The text style of sub title. /// |副标题文本样式。 /// - public TextStyle subTextStyle + public LabelStyle subLabelStyle { - get { return m_SubTextStyle; } - set { if (PropertyUtil.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); } + get { return m_SubLabelStyle; } + set { if (PropertyUtil.SetClass(ref m_SubLabelStyle, value)) SetComponentDirty(); } } /// /// [default:8] @@ -85,8 +85,8 @@ namespace XCharts.Runtime { return m_ComponentDirty || location.componentDirty - || textStyle.componentDirty - || subTextStyle.componentDirty; + || m_LabelStyle.componentDirty + || m_SubLabelStyle.componentDirty; } } @@ -94,8 +94,8 @@ namespace XCharts.Runtime { base.ClearComponentDirty(); location.ClearComponentDirty(); - textStyle.ClearComponentDirty(); - subTextStyle.ClearComponentDirty(); + m_LabelStyle.ClearComponentDirty(); + m_SubLabelStyle.ClearComponentDirty(); } public void OnChanged() diff --git a/Runtime/Component/Title/TitleHandler.cs b/Runtime/Component/Title/TitleHandler.cs index 37fc37fc..98f252b8 100644 --- a/Runtime/Component/Title/TitleHandler.cs +++ b/Runtime/Component/Title/TitleHandler.cs @@ -27,30 +27,23 @@ namespace XCharts.Runtime anchorMin = title.location.runtimeAnchorMin; anchorMax = title.location.runtimeAnchorMax; pivot = title.location.runtimePivot; - title.textStyle.UpdateAlignmentByLocation(title.location); - title.subTextStyle.UpdateAlignmentByLocation(title.location); - var fontSize = title.textStyle.GetFontSize(chart.theme.title); + var fontSize = title.labelStyle.textStyle.GetFontSize(chart.theme.title); ChartHelper.UpdateRectTransform(titleObject, anchorMin, anchorMax, pivot, new Vector2(chart.chartWidth, chart.chartHeight)); var titlePosition = chart.GetTitlePosition(title); var subTitlePosition = -new Vector3(0, fontSize + title.itemGap, 0); - var titleWid = chart.chartWidth; titleObject.transform.localPosition = titlePosition; titleObject.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(titleObject); - var titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, anchorMin, anchorMax, - pivot, new Vector2(titleWid, fontSize), title.textStyle, chart.theme.title); - titleText.SetActive(title.show); - titleText.SetLocalPosition(Vector3.zero + title.textStyle.offsetv3); - titleText.SetText(title.text); + var label = ChartHelper.AddChartLabel(s_TitleObjectName, titleObject.transform, title.labelStyle, chart.theme.title, + title.text, Color.clear, title.location.runtimeTextAlignment); + label.SetActive(title.show && title.labelStyle.show); - var subText = ChartHelper.AddTextObject(s_SubTitleObjectName, titleObject.transform, anchorMin, anchorMax, - pivot, new Vector2(titleWid, title.subTextStyle.GetFontSize(chart.theme.subTitle)), title.subTextStyle, - chart.theme.subTitle); - subText.SetActive(title.show && !string.IsNullOrEmpty(title.subText)); - subText.SetLocalPosition(subTitlePosition + title.subTextStyle.offsetv3); - subText.SetText(title.subText); + var subLabel = ChartHelper.AddChartLabel(s_SubTitleObjectName, titleObject.transform, title.subLabelStyle, chart.theme.subTitle, + title.subText, Color.clear, title.location.runtimeTextAlignment); + subLabel.SetActive(title.show && title.subLabelStyle.show); + subLabel.transform.localPosition = subTitlePosition + title.subLabelStyle.offset; }; title.refreshComponent(); } diff --git a/Runtime/Component/Title/TitleStyle.cs b/Runtime/Component/Title/TitleStyle.cs index 7353b31d..711e7498 100644 --- a/Runtime/Component/Title/TitleStyle.cs +++ b/Runtime/Component/Title/TitleStyle.cs @@ -9,54 +9,8 @@ namespace XCharts.Runtime /// |标题相关设置。 /// [Serializable] - public class TitleStyle : ChildComponent, ISerieDataComponent, ISerieExtraComponent + public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieExtraComponent { - [SerializeField] private bool m_Show = true; - [SerializeField] private Vector2 m_OffsetCenter = new Vector2(0, -0.2f); - [SerializeField] private TextStyle m_TextStyle = new TextStyle(); - - /// - /// Whether to show title. - /// |是否显示标题。 - /// - public bool show - { - get { return m_Show; } - set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } - } - /// - /// The offset position relative to the center. - /// |相对于中心的偏移位置。 - /// - public Vector2 offsetCenter - { - get { return m_OffsetCenter; } - set { if (PropertyUtil.SetStruct(ref m_OffsetCenter, value)) SetComponentDirty(); } - } - - /// - /// the color of text. - /// |文本的颜色。 - /// - public TextStyle textStyle - { - get { return m_TextStyle; } - set { if (PropertyUtil.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); } - } - - public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } } - - public override void ClearComponentDirty() - { - base.ClearComponentDirty(); - textStyle.ClearComponentDirty(); - } - - public Vector3 GetOffset(float radius) - { - var x = ChartHelper.GetActualValue(m_OffsetCenter.x, radius); - var y = ChartHelper.GetActualValue(m_OffsetCenter.y, radius); - return new Vector3(x, y, 0); - } + } } \ No newline at end of file diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs index 35e2d16a..a4434d5a 100644 --- a/Runtime/Component/Tooltip/Tooltip.cs +++ b/Runtime/Component/Tooltip/Tooltip.cs @@ -91,13 +91,18 @@ namespace XCharts.Runtime [SerializeField] private float m_ItemHeight = 25f; [SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255); [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None); - [SerializeField] private TextStyle m_LabelTextStyle = new TextStyle(); - [SerializeField] private TextStyle m_TitleTextStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }; + [SerializeField] private LabelStyle m_IndicatorLabelStyle = new LabelStyle(); [SerializeField] - private List m_ColumnsTextStyle = new List() { - new TextStyle() { alignment = TextAnchor.MiddleLeft, extraWidth = 5 }, - new TextStyle() { alignment = TextAnchor.MiddleLeft, extraWidth = 20 }, - new TextStyle() { alignment = TextAnchor.MiddleRight, extraWidth = 5 } + private LabelStyle m_TitleLabelStyle = new LabelStyle() + { + textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft } + }; + [SerializeField] + private List m_ContentLabelStyles = new List() + { + new LabelStyle(){ textPadding = new TextPadding(0,5,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }}, + new LabelStyle(){ textPadding = new TextPadding(0,20,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }}, + new LabelStyle(){ textPadding = new TextPadding(0,0,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleRight }} }; public TooltipContext context = new TooltipContext(); @@ -305,27 +310,27 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); } } /// - /// the text style of content. - /// |提示框标签的文本样式。 + /// the label style of tooltip axis indicator label. + /// |提示框的坐标轴指示器文本的样式。 /// - public TextStyle labelTextStyle + public LabelStyle indicatorLabelStyle { - get { return m_LabelTextStyle; } - set { if (value != null) { m_LabelTextStyle = value; SetComponentDirty(); } } + get { return m_IndicatorLabelStyle; } + set { if (value != null) { m_IndicatorLabelStyle = value; SetComponentDirty(); } } } /// /// 标题的文本样式。 /// - public TextStyle titleTextStyle + public LabelStyle titleLabelStyle { - get { return m_TitleTextStyle; } - set { if (value != null) { m_TitleTextStyle = value; SetComponentDirty(); } } + get { return m_TitleLabelStyle; } + set { if (value != null) { m_TitleLabelStyle = value; SetComponentDirty(); } } } - public List columnsTextStyle + public List contentLabelStyles { - get { return m_ColumnsTextStyle; } - set { if (value != null) { m_ColumnsTextStyle = value; SetComponentDirty(); } } + get { return m_ContentLabelStyles; } + set { if (value != null) { m_ContentLabelStyles = value; SetComponentDirty(); } } } /// @@ -343,14 +348,14 @@ namespace XCharts.Runtime /// public override bool componentDirty { - get { return m_ComponentDirty || lineStyle.componentDirty || labelTextStyle.componentDirty; } + get { return m_ComponentDirty || lineStyle.componentDirty || indicatorLabelStyle.componentDirty; } } public override void ClearComponentDirty() { base.ClearComponentDirty(); lineStyle.ClearComponentDirty(); - labelTextStyle.ClearComponentDirty(); + indicatorLabelStyle.ClearComponentDirty(); } /// /// 当前提示框所指示的Serie索引(目前只对散点图有效)。 @@ -429,7 +434,7 @@ namespace XCharts.Runtime { if (view == null) return; - + view.SetActive(alwayShowContent ? true : flag); } @@ -492,17 +497,17 @@ namespace XCharts.Runtime return trigger == Trigger.Axis; } - public TextStyle GetColumnTextStyle(int index) + public LabelStyle GetContentLabelStyle(int index) { - if (m_ColumnsTextStyle.Count == 0) + if (m_ContentLabelStyles.Count == 0) return null; if (index < 0) index = 0; - else if (index > m_ColumnsTextStyle.Count - 1) - index = m_ColumnsTextStyle.Count - 1; + else if (index > m_ContentLabelStyles.Count - 1) + index = m_ContentLabelStyles.Count - 1; - return m_ColumnsTextStyle[index]; + return m_ContentLabelStyles[index]; } } } \ No newline at end of file diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index 62569098..acee6078 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -56,7 +56,8 @@ namespace XCharts.Runtime for (int i = 0; i < 2; i++) { var labelName = "label_" + i; - var item = ChartHelper.AddTooltipLabel(component, labelName, m_LabelRoot.transform, chart.theme, new Vector2(0.5f, 0.5f)); + var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform, + chart.theme, TextAnchor.MiddleCenter); item.SetActive(false); m_IndicatorLabels.Add(item); } @@ -71,7 +72,8 @@ namespace XCharts.Runtime else { var labelName = "label_" + index; - var item = ChartHelper.AddTooltipLabel(component, labelName, m_LabelRoot.transform, chart.theme, new Vector2(0.5f, 0.5f)); + var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform, + chart.theme, TextAnchor.MiddleCenter); m_IndicatorLabels.Add(item); return item; } @@ -150,7 +152,7 @@ namespace XCharts.Runtime if (axis.gridIndex == grid.index) { var label = GetIndicatorLabel(labelCount++); - SetTooltipIndicatorLabel(axis, label); + SetTooltipIndicatorLabel(tooltip, axis, label); } } } @@ -167,7 +169,7 @@ namespace XCharts.Runtime if (axis.polarIndex == polar.index) { var label = GetIndicatorLabel(labelCount++); - SetTooltipIndicatorLabel(axis, label); + SetTooltipIndicatorLabel(tooltip, axis, label); } } } @@ -176,19 +178,22 @@ namespace XCharts.Runtime } } - private void SetTooltipIndicatorLabel(Axis axis, ChartLabel label) + private void SetTooltipIndicatorLabel(Tooltip tooltip, Axis axis, ChartLabel label) { if (label == null) return; if (double.IsPositiveInfinity(axis.context.pointerValue)) return; label.SetActive(true); - label.SetLabelActive(true); + label.SetTextActive(true); label.SetPosition(axis.context.pointerLabelPosition); if (axis.IsCategory()) label.SetText(axis.GetData((int)axis.context.pointerValue)); else label.SetText(axis.context.pointerValue.ToString("f2")); var textColor = axis.axisLabel.textStyle.GetColor(chart.theme.axis.textColor); - label.labelBackground.color = textColor; + if (ChartHelper.IsClearColor(tooltip.indicatorLabelStyle.background.color)) + label.color = textColor; + else + label.color = tooltip.indicatorLabelStyle.background.color; label.SetTextColor(Color.white); } @@ -415,7 +420,8 @@ namespace XCharts.Runtime if (tooltip.context.data.param.Count > 0) { tooltip.SetActive(true); - tooltip.view.Refresh(); + if (tooltip.view != null) + tooltip.view.Refresh(); TooltipHelper.LimitInRect(tooltip, chart.chartRect); return true; } diff --git a/Runtime/Component/Tooltip/TooltipView.cs b/Runtime/Component/Tooltip/TooltipView.cs index e1a9123e..d8f417da 100644 --- a/Runtime/Component/Tooltip/TooltipView.cs +++ b/Runtime/Component/Tooltip/TooltipView.cs @@ -10,7 +10,7 @@ namespace XCharts.Runtime public class TooltipViewItem { public GameObject gameObject; - public List columns = new List(); + public List columns = new List(); } public class TooltipView { @@ -26,7 +26,7 @@ namespace XCharts.Runtime public Image background; public Outline border; public VerticalLayoutGroup layout; - public ChartText title; + public ChartLabel title; private List m_Items = new List(); private List m_ColumnMaxWidth = new List(); private bool m_Active = false; @@ -89,12 +89,12 @@ namespace XCharts.Runtime column.SetText(param.columns[j]); if (j == 0) - column.SetColor(param.color); + column.text.SetColor(param.color); if (j >= m_ColumnMaxWidth.Count) m_ColumnMaxWidth.Add(0); - var columnWidth = column.GetPreferredWidth(); + var columnWidth = column.GetWidth(); if (m_ColumnMaxWidth[j] < columnWidth) m_ColumnMaxWidth[j] = columnWidth; } @@ -128,7 +128,7 @@ namespace XCharts.Runtime else { maxWid = TotalMaxWidth(); - var titleWid = title.GetPreferredWidth(); + var titleWid = title.GetTextWidth(); if (maxWid < titleWid) maxWid = titleWid; } @@ -139,7 +139,7 @@ namespace XCharts.Runtime } else { - if (!string.IsNullOrEmpty(title.GetText())) + if (!string.IsNullOrEmpty(title.text.GetText())) maxHig += tooltip.titleHeight; maxHig += tooltip.itemHeight * tooltip.context.data.param.Count; maxHig += tooltip.paddingTopBottom * 2; @@ -159,7 +159,7 @@ namespace XCharts.Runtime for (int j = 0; j < m_ColumnMaxWidth.Count; j++) { var deltaX = j == m_ColumnMaxWidth.Count - 1 ? maxWid - xPos : m_ColumnMaxWidth[j]; - item.columns[j].SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight)); + item.columns[j].text.SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight)); item.columns[j].SetRectPosition(new Vector3(xPos, 0)); xPos += m_ColumnMaxWidth[j]; } @@ -192,7 +192,7 @@ namespace XCharts.Runtime } } - private ChartText GetItemColumn(TooltipViewItem item, int i) + private ChartLabel GetItemColumn(TooltipViewItem item, int i) { if (i < 0) i = 0; if (i < item.columns.Count) @@ -236,10 +236,8 @@ namespace XCharts.Runtime tooltip.paddingTopBottom, tooltip.paddingTopBottom); - view.title = ChartHelper.AddTextObject("title", view.gameObject.transform, anchorMin, anchorMax, v2_0_05, - new Vector2(10, tooltip.titleHeight), tooltip.titleTextStyle, theme.tooltip); - view.title.SetText(""); - view.title.SetLocalPosition(new Vector2(3, -3)); + view.title = ChartHelper.AddChartLabel("title", view.gameObject.transform, tooltip.titleLabelStyle, theme.tooltip, + "", Color.clear, TextAnchor.MiddleLeft); var item = CreateViewItem(0, view.gameObject.transform, tooltip, theme.tooltip); view.m_Items.Add(item); @@ -261,14 +259,12 @@ namespace XCharts.Runtime return item; } - private static ChartText CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme) + private static ChartLabel CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme) { - var value = ChartHelper.AddTextObject("column" + i, parent, - v2_0_05, v2_0_05, v2_0_05, new Vector2(100, tooltip.itemHeight), - tooltip.GetColumnTextStyle(i), theme); - value.SetRectPosition(new Vector3(0, 0)); - value.SetText(""); - return value; + var labelStyle = tooltip.GetContentLabelStyle(i); + var label = ChartHelper.AddChartLabel("column" + i, parent, labelStyle, theme, + "", Color.clear, TextAnchor.MiddleLeft); + return label; } } } \ No newline at end of file diff --git a/Runtime/Helper/SerieHelper.cs b/Runtime/Helper/SerieHelper.cs index efd45160..3fcdc237 100644 --- a/Runtime/Helper/SerieHelper.cs +++ b/Runtime/Helper/SerieHelper.cs @@ -403,7 +403,7 @@ namespace XCharts.Runtime } else { - if (!serie.IsPerformanceMode() && serieData.label != null) return serieData.label; + if (!serie.IsPerformanceMode() && serieData.labelStyle != null) return serieData.labelStyle; else return serie.label; } } @@ -432,12 +432,6 @@ namespace XCharts.Runtime } } - public static IconStyle GetIconStyle(Serie serie, SerieData serieData) - { - if (serieData != null && serieData.iconStyle != null) return serieData.iconStyle; - else return serie.iconStyle; - } - public static SymbolStyle GetSerieSymbol(Serie serie, SerieData serieData) { if (!serie.IsPerformanceMode() && serieData.symbol != null) return serieData.symbol; @@ -710,7 +704,12 @@ namespace XCharts.Runtime if (dataZoom.minShowNum > data.Count) range = data.Count; else range = dataZoom.minShowNum; } - serie.m_FilterData = data.GetRange(start, range); + if (range > data.Count - start - 1) + start = data.Count - range - 1; + if (start >= 0) + serie.m_FilterData = data.GetRange(start, range); + else + serie.m_FilterData = data; } else { diff --git a/Runtime/Helper/SerieLabelHelper.cs b/Runtime/Helper/SerieLabelHelper.cs index 984eae2a..bcf32f48 100644 --- a/Runtime/Helper/SerieLabelHelper.cs +++ b/Runtime/Helper/SerieLabelHelper.cs @@ -45,7 +45,7 @@ namespace XCharts.Runtime var dataName = serieData != null ? serieData.name : null; if (serieLabel.formatterFunction != null) { - return serieLabel.formatterFunction(serieData.index, dataValue); + return serieLabel.formatterFunction(serieData.index, dataValue, null); } if (string.IsNullOrEmpty(serieLabel.formatter)) return ChartCached.NumberToStr(dataValue, numericFormatter); @@ -69,10 +69,10 @@ namespace XCharts.Runtime var total = serie.max; var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear); serieData.labelObject.SetText(content); - serieData.labelObject.SetLabelPosition(serie.context.center + label.offset); + serieData.labelObject.SetPosition(serie.context.center + label.offset); if (!ChartHelper.IsClearColor(label.textStyle.color)) { - serieData.labelObject.label.SetColor(label.textStyle.color); + serieData.labelObject.text.SetColor(label.textStyle.color); } } @@ -98,7 +98,8 @@ namespace XCharts.Runtime serie.context.center.y + labelRadius * Mathf.Cos(currRad)); serieData.context.labelPosition = labelCenter; break; - case LabelStyle.Position.Outside: + default: + //LabelStyle.Position.Outside if (labelLine != null && labelLine.lineType == LabelLine.LineType.HorizontalLine) { var radius1 = serie.context.outsideRadius; @@ -113,7 +114,7 @@ namespace XCharts.Runtime } var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; r4 += labelLine.lineLength1 + labelLine.lineWidth * 4; - r4 += serieData.labelObject.label.GetPreferredWidth() / 2; + r4 += serieData.labelObject.text.GetPreferredWidth() / 2; serieData.context.labelPosition = pos0 + ((currAngle - startAngle) % 360 > 180 ? Vector3.left : Vector3.right) * r4; } else @@ -165,8 +166,10 @@ namespace XCharts.Runtime var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); var labelLine = SerieHelper.GetSerieLabelLine(serie, serieData); var fontSize = serieLabel.textStyle.GetFontSize(theme); + var isOutside = serieLabel.position == LabelStyle.Position.Outside + || serieLabel.position == LabelStyle.Position.Default; if (!serieLabel.show) return; - if (serieLabel.position != LabelStyle.Position.Outside) return; + if (!isOutside) return; if (lastCheckPos == Vector3.zero) { lastCheckPos = serieData.context.labelPosition; @@ -193,11 +196,12 @@ namespace XCharts.Runtime { if (label == null || labelLine == null) return serieData.context.labelPosition; - - if (label.position == LabelStyle.Position.Outside && labelLine.lineType != LabelLine.LineType.HorizontalLine) + var isOutside = label.position == LabelStyle.Position.Outside + || label.position == LabelStyle.Position.Default; + if (isOutside && labelLine.lineType != LabelLine.LineType.HorizontalLine) { var currAngle = serieData.context.halfAngle; - var offset = labelLine.lineLength2 + serieData.labelObject.GetLabelWidth() / 2; + var offset = labelLine.lineLength2 + serieData.labelObject.GetTextWidth() / 2; if ((currAngle - serie.context.startAngle) % 360 > 180) return serieData.context.labelPosition + new Vector3(-offset, 0, 0); else diff --git a/Runtime/Internal/Misc/DelegateFunction.cs b/Runtime/Internal/Misc/DelegateFunction.cs index 16d9e3f7..af6b57c3 100644 --- a/Runtime/Internal/Misc/DelegateFunction.cs +++ b/Runtime/Internal/Misc/DelegateFunction.cs @@ -6,22 +6,13 @@ using UnityEngine.UI; namespace XCharts.Runtime { /// - /// The delegate function for AxisLabel's formatter. - /// |AxisLabel的formatter自定义委托。 - /// - /// label索引 - /// 当前label对应的数值数据,Value轴或Time轴有效 - /// 当前label对应的类目数据,Category轴有效 - /// 最终显示的文本内容 - public delegate string AxisLabelFormatterFunction(int labelIndex, double value, string category); - /// - /// The delegate function for SerieLabel‘s formatter. + /// The delegate function for LabelStyle‘s formatter. /// |SerieLabel的formatter自定义委托。 /// /// 数据索引 /// 数值 /// 最终显示的文本内容 - public delegate string SerieLabelFormatterFunction(int dataIndex, double value); + public delegate string LabelFormatterFunction(int dataIndex, double value, string category); public delegate float AnimationDelayFunction(int dataIndex); public delegate float AnimationDurationFunction(int dataIndex); /// diff --git a/Runtime/Internal/Object/ChartLabel.cs b/Runtime/Internal/Object/ChartLabel.cs index 057a728a..ed114b5f 100644 --- a/Runtime/Internal/Object/ChartLabel.cs +++ b/Runtime/Internal/Object/ChartLabel.cs @@ -8,67 +8,87 @@ namespace XCharts.Runtime { [SerializeField] private ChartText m_LabelText; - private bool m_AutoHideIconWhenLabelEmpty = false; - private bool m_LabelAutoSize = true; - private float m_LabelPaddingLeftRight = 3f; - private float m_LabelPaddingTopBottom = 3f; - private RectTransform m_LabelRect; - private RectTransform m_LabelBackgroundRect; + private bool m_HideIconIfTextEmpty = false; + private bool m_AutoSize = true; + private float m_PaddingLeft = 0; + private float m_PaddingRight = 0; + private float m_PaddingTop = 0; + private float m_PaddingBottom = 0; + private float m_Width = 0; + private float m_Height = 0; + private RectTransform m_TextRect; private RectTransform m_IconRect; private RectTransform m_ObjectRect; private Vector3 m_IconOffest; private Align m_Align = Align.Left; private Image m_IconImage; - private Image m_LabelBackgroundImage; public Image icon { get { return m_IconImage; } set { SetIcon(value); } } - public Image labelBackground - { - get { return m_LabelBackgroundImage; } - set { SetLabelBackground(value); } - } - public ChartText label + public ChartText text { get { return m_LabelText; } set { m_LabelText = value; - if (value != null) m_LabelRect = m_LabelText.gameObject.GetComponent(); + if (value != null) m_TextRect = m_LabelText.gameObject.GetComponent(); } } - public bool autoHideIconWhenLabelEmpty { set { m_AutoHideIconWhenLabelEmpty = value; } } + public bool hideIconIfTextEmpty { set { m_HideIconIfTextEmpty = value; } } public bool isIconActive { get; private set; } public bool isAnimationEnd { get; internal set; } + internal RectTransform objectRect + { + get + { + if (m_ObjectRect == null) + m_ObjectRect = gameObject.GetComponent(); + return m_ObjectRect; + } + } + protected override void Awake() { - m_ObjectRect = gameObject.GetComponent(); raycastTarget = false; } - public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom) + public void SetTextPadding(TextPadding padding) { - m_LabelAutoSize = autoSize; - m_LabelPaddingLeftRight = paddingLeftRight; - m_LabelPaddingTopBottom = paddingTopBottom; - m_LabelText = new ChartText(labelObj); - m_LabelRect = m_LabelText.gameObject.GetComponent(); - - m_Align = Align.Left; + m_PaddingLeft = padding.left; + m_PaddingRight = padding.right; + m_PaddingTop = padding.top; + m_PaddingBottom = padding.bottom; + UpdatePadding(); } - - public void SetLabelBackground(Image image) + public void SetPadding(float[] padding) { - m_LabelBackgroundImage = image; - if (image != null) + if (padding.Length >= 4) { - m_LabelBackgroundRect = m_LabelBackgroundImage.GetComponent(); + m_PaddingLeft = padding[3]; + m_PaddingRight = padding[1]; + m_PaddingTop = padding[0]; + m_PaddingBottom = padding[2]; } + else if (padding.Length >= 2) + { + m_PaddingLeft = padding[1]; + m_PaddingRight = padding[1]; + m_PaddingTop = padding[0]; + m_PaddingBottom = padding[0]; + } + else if (padding.Length == 1) + { + m_PaddingLeft = padding[0]; + m_PaddingRight = padding[0]; + m_PaddingTop = padding[0]; + m_PaddingBottom = padding[0]; + } + UpdatePadding(); } public void SetIcon(Image image) @@ -80,9 +100,22 @@ namespace XCharts.Runtime } } - public void SetAutoSize(bool flag) + public float GetWidth() { - m_LabelAutoSize = flag; + return m_Width; + } + + public float GetHeight() + { + return m_Height; + } + + public void SetSize(float width, float height) + { + this.m_Width = width; + this.m_Height = height; + m_AutoSize = width == 0 && height == 0; + objectRect.sizeDelta = new Vector2(width, height); } public void SetIconSprite(Sprite sprite) @@ -108,24 +141,24 @@ namespace XCharts.Runtime m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height); m_IconOffest = iconStyle.offset; m_Align = iconStyle.align; - m_AutoHideIconWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty; + m_HideIconIfTextEmpty = iconStyle.autoHideWhenLabelEmpty; AdjustIconPos(); - if (iconStyle.layer == IconStyle.Layer.UnderLabel) + if (iconStyle.layer == IconStyle.Layer.UnderText) m_IconRect.SetSiblingIndex(0); else m_IconRect.SetSiblingIndex(transform.childCount - 1); } } - public float GetLabelWidth() + public float GetTextWidth() { - if (m_LabelRect) return m_LabelRect.sizeDelta.x; + if (m_TextRect) return m_TextRect.sizeDelta.x; else return 0; } - public float GetLabelHeight() + public float GetTextHeight() { - if (m_LabelRect) return m_LabelRect.sizeDelta.y; + if (m_TextRect) return m_TextRect.sizeDelta.y; return 0; } @@ -134,7 +167,7 @@ namespace XCharts.Runtime if (m_LabelText != null) m_LabelText.SetColor(color); } - public void SetLabelRotate(float rotate) + public void SetTextRotate(float rotate) { if (m_LabelText != null) m_LabelText.SetLocalEulerAngles(new Vector3(0, 0, rotate)); } @@ -144,21 +177,21 @@ namespace XCharts.Runtime transform.localPosition = position; } + public void SetRectPosition(Vector3 position) + { + objectRect.anchoredPosition3D = position; + } + public Vector3 GetPosition() { return transform.localPosition; } - public void SetLabelPosition(Vector3 position) - { - if (m_LabelRect) m_LabelRect.localPosition = position; - } - public void SetActive(bool flag) { ChartHelper.SetActive(gameObject, flag); } - public void SetLabelActive(bool flag) + public void SetTextActive(bool flag) { if (m_LabelText != null) m_LabelText.SetActive(flag); } @@ -170,7 +203,7 @@ namespace XCharts.Runtime public bool SetText(string text) { - if (m_LabelRect == null || m_LabelText == null) + if (m_TextRect == null || m_LabelText == null) return false; if (text == null) @@ -178,26 +211,25 @@ namespace XCharts.Runtime if (!m_LabelText.GetText().Equals(text)) { m_LabelText.SetText(text); - if (m_LabelAutoSize) + if (m_AutoSize) { var newSize = string.IsNullOrEmpty(text) ? Vector2.zero : - new Vector2(m_LabelText.GetPreferredWidth() + m_LabelPaddingLeftRight * 2, - m_LabelText.GetPreferredHeight() + m_LabelPaddingTopBottom * 2); - var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y; + new Vector2(m_LabelText.GetPreferredWidth(), + m_LabelText.GetPreferredHeight()); + var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y; + this.m_Width = newSize.x; + this.m_Height = newSize.y; if (sizeChange) { - m_LabelRect.sizeDelta = newSize; - if (m_LabelBackgroundRect != null) - m_LabelBackgroundRect.sizeDelta = newSize; - if (!isIconActive && m_ObjectRect != null) - m_ObjectRect.sizeDelta = newSize; + m_TextRect.sizeDelta = newSize; + UpdateSize(); + UpdatePadding(); AdjustIconPos(); - } return sizeChange; } AdjustIconPos(); - if (m_AutoHideIconWhenLabelEmpty && isIconActive) + if (m_HideIconIfTextEmpty && isIconActive) { ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text)); } @@ -205,9 +237,57 @@ namespace XCharts.Runtime return false; } + private void UpdateSize() + { + if (m_AutoSize) + { + var sizeDelta = m_TextRect.sizeDelta; + m_Width = sizeDelta.x + m_PaddingLeft + m_PaddingRight; + m_Height = sizeDelta.y + m_PaddingTop + m_PaddingBottom; + objectRect.sizeDelta = new Vector2(m_Width, m_Height); + } + } + + private void UpdatePadding() + { + if (m_TextRect == null) return; + switch (text.alignment) + { + case TextAnchor.LowerLeft: + m_TextRect.anchoredPosition = new Vector2(m_PaddingLeft, m_PaddingBottom); + break; + case TextAnchor.UpperLeft: + m_TextRect.anchoredPosition = new Vector2(m_PaddingLeft, -m_PaddingTop); + break; + case TextAnchor.MiddleLeft: + m_TextRect.anchoredPosition = new Vector2(m_PaddingLeft, m_Height / 2 - m_PaddingTop - m_TextRect.sizeDelta.y / 2); + break; + case TextAnchor.LowerRight: + m_TextRect.anchoredPosition = new Vector2(-m_PaddingRight, m_PaddingBottom); + break; + case TextAnchor.UpperRight: + m_TextRect.anchoredPosition = new Vector2(-m_PaddingRight, -m_PaddingTop); + break; + case TextAnchor.MiddleRight: + m_TextRect.anchoredPosition = new Vector2(-m_PaddingRight, m_Height / 2 - m_PaddingTop - m_TextRect.sizeDelta.y / 2); + break; + case TextAnchor.LowerCenter: + m_TextRect.anchoredPosition = new Vector2(-(m_Width / 2 - m_PaddingLeft - m_TextRect.sizeDelta.x / 2), m_PaddingBottom); + break; + case TextAnchor.UpperCenter: + m_TextRect.anchoredPosition = new Vector2(-(m_Width / 2 - m_PaddingLeft - m_TextRect.sizeDelta.x / 2), -m_PaddingTop); + break; + case TextAnchor.MiddleCenter: + m_TextRect.anchoredPosition = new Vector2(-(m_Width / 2 - m_PaddingLeft - m_TextRect.sizeDelta.x / 2), m_Height / 2 - m_PaddingTop - m_TextRect.sizeDelta.y / 2); + break; + default: + break; + } + } + private void AdjustIconPos() { - if (m_IconImage && m_IconRect && m_LabelText != null && m_ObjectRect != null) + if (m_IconImage && m_IconRect && m_LabelText != null && m_TextRect != null) { var iconX = 0f; switch (m_Align) @@ -218,12 +298,12 @@ namespace XCharts.Runtime case TextAnchor.LowerLeft: case TextAnchor.UpperLeft: case TextAnchor.MiddleLeft: - iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2; + iconX = -m_TextRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2; break; case TextAnchor.LowerRight: case TextAnchor.UpperRight: case TextAnchor.MiddleRight: - iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2; + iconX = m_TextRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2; break; case TextAnchor.LowerCenter: case TextAnchor.UpperCenter: @@ -238,7 +318,7 @@ namespace XCharts.Runtime case TextAnchor.LowerLeft: case TextAnchor.UpperLeft: case TextAnchor.MiddleLeft: - iconX = m_ObjectRect.sizeDelta.x / 2 + m_IconRect.sizeDelta.x / 2; + iconX = m_TextRect.sizeDelta.x / 2 + m_IconRect.sizeDelta.x / 2; break; case TextAnchor.LowerRight: case TextAnchor.UpperRight: diff --git a/Runtime/Internal/Object/ChartText.cs b/Runtime/Internal/Object/ChartText.cs index 25e862e4..2ae19f8b 100644 --- a/Runtime/Internal/Object/ChartText.cs +++ b/Runtime/Internal/Object/ChartText.cs @@ -10,8 +10,8 @@ namespace XCharts.Runtime [System.Serializable] public class ChartText { - private float m_ExtraWidth; private Text m_Text; + private TextAnchor m_TextAlignment; public Text text { get { return m_Text; } @@ -38,25 +38,7 @@ namespace XCharts.Runtime { get { -#if dUI_TextMeshPro - if (m_TMPText == null) return TextAnchor.MiddleCenter; - switch (m_TMPText.alignment) - { - case TextAlignmentOptions.Bottom: return TextAnchor.LowerCenter; - case TextAlignmentOptions.BottomLeft: return TextAnchor.LowerLeft; - case TextAlignmentOptions.BottomRight: return TextAnchor.LowerRight; - case TextAlignmentOptions.Center: return TextAnchor.MiddleCenter; - case TextAlignmentOptions.Left: return TextAnchor.MiddleLeft; - case TextAlignmentOptions.Right: return TextAnchor.MiddleRight; - case TextAlignmentOptions.Top: return TextAnchor.UpperCenter; - case TextAlignmentOptions.TopLeft: return TextAnchor.UpperLeft; - case TextAlignmentOptions.TopRight: return TextAnchor.UpperRight; - default: return TextAnchor.MiddleCenter; - } -#else - if (m_Text != null) return m_Text.alignment; - else return TextAnchor.MiddleCenter; -#endif + return m_TextAlignment; } set { @@ -133,11 +115,6 @@ namespace XCharts.Runtime #endif } - public void SetExtraWidth(float width) - { - m_ExtraWidth = width; - } - public void SetActive(bool flag) { #if dUI_TextMeshPro @@ -187,6 +164,7 @@ namespace XCharts.Runtime public void SetAlignment(TextAnchor alignment) { + m_TextAlignment = alignment; #if dUI_TextMeshPro if (m_TMPText == null) return; switch (alignment) @@ -200,6 +178,10 @@ namespace XCharts.Runtime case TextAnchor.UpperCenter: m_TMPText.alignment = TextAlignmentOptions.Top; break; case TextAnchor.UpperLeft: m_TMPText.alignment = TextAlignmentOptions.TopLeft; break; case TextAnchor.UpperRight: m_TMPText.alignment = TextAlignmentOptions.TopRight; break; + default: + m_TMPText.alignment = TextAlignmentOptions.Center; + m_TextAlignment = TextAnchor.MiddleCenter; + break; } #else if (m_Text != null) m_Text.alignment = alignment; @@ -262,9 +244,9 @@ namespace XCharts.Runtime public float GetPreferredWidth() { #if dUI_TextMeshPro - if (m_TMPText != null) return m_TMPText.preferredWidth + m_ExtraWidth; + if (m_TMPText != null) return m_TMPText.preferredWidth; #else - if (m_Text != null) return m_Text.preferredWidth + m_ExtraWidth; + if (m_Text != null) return m_Text.preferredWidth; #endif return 0; } diff --git a/Runtime/Internal/Pools/SerieLabelPool.cs b/Runtime/Internal/Pools/SerieLabelPool.cs index 5eee1690..0bb7d1de 100644 --- a/Runtime/Internal/Pools/SerieLabelPool.cs +++ b/Runtime/Internal/Pools/SerieLabelPool.cs @@ -63,13 +63,13 @@ namespace XCharts.Runtime m_ReleaseDic.Clear(); } - private static GameObject CreateSerieLabel(string name, Transform parent, LabelStyle label, Color color, + private static GameObject CreateSerieLabel(string name, Transform parent, LabelStyle labelStyle, Color color, float iconWidth, float iconHeight, ThemeStyle theme) { - var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight, - color, label.textStyle, theme); - ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight); - return element; + var label = ChartHelper.AddChartLabel(name, parent, labelStyle, theme.common, + "", color, TextAnchor.MiddleCenter); + label.SetActive(labelStyle.show); + return label.gameObject; } } } diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index f0eb1159..2a9f9e5d 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -232,10 +232,11 @@ namespace XCharts.Runtime rect.pivot = pivot; } - public static ChartText AddTextObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, - Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme, ChartText chartText = null) + public static ChartText AddTextObject(string objectName, Transform parent, Vector2 anchorMin, Vector2 anchorMax, + Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme, Color autoColor, + TextAnchor autoAlignment, ChartText chartText = null) { - GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); + GameObject txtObj = AddObject(objectName, parent, anchorMin, anchorMax, pivot, sizeDelta); txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate); if (chartText == null) chartText = new ChartText(); @@ -244,7 +245,6 @@ namespace XCharts.Runtime chartText.tmpText = GetOrAddComponent(txtObj); chartText.tmpText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont; chartText.tmpText.fontStyle = textStyle.tmpFontStyle; - chartText.tmpText.alignment = textStyle.tmpAlignment; chartText.tmpText.richText = true; chartText.tmpText.raycastTarget = false; chartText.tmpText.enableWordWrapping = textStyle.autoWrap; @@ -252,17 +252,21 @@ namespace XCharts.Runtime chartText.text = GetOrAddComponent(txtObj); chartText.text.font = textStyle.font == null ? theme.font : textStyle.font; chartText.text.fontStyle = textStyle.fontStyle; - chartText.text.alignment = textStyle.alignment; chartText.text.horizontalOverflow = textStyle.autoWrap ? HorizontalWrapMode.Wrap : HorizontalWrapMode.Overflow; chartText.text.verticalOverflow = VerticalWrapMode.Overflow; chartText.text.supportRichText = true; chartText.text.raycastTarget = false; #endif - chartText.SetColor(textStyle.GetColor(theme.textColor)); + if (textStyle.autoColor && autoColor != Color.clear) + chartText.SetColor(autoColor); + else + chartText.SetColor(textStyle.GetColor(theme.textColor)); + + chartText.SetAlignment(textStyle.autoAlign ? autoAlignment : textStyle.alignment); chartText.SetFontSize(textStyle.GetFontSize(theme)); chartText.SetText("Text"); chartText.SetLineSpacing(textStyle.lineSpacing); - chartText.SetExtraWidth(textStyle.extraWidth); + chartText.SetActive(textStyle.show); RectTransform rect = GetOrAddComponent(txtObj); rect.localPosition = Vector3.zero; @@ -273,93 +277,6 @@ namespace XCharts.Runtime return chartText; } - public static Text AddTextObject(string name, Transform parent, Font font, Color color, - TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, - int fontSize = 14, float rotate = 0, FontStyle fontStyle = FontStyle.Normal, float lineSpacing = 1) - { - GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); - var txt = GetOrAddComponent(txtObj); - txt.font = font; - txt.fontSize = fontSize; - txt.fontStyle = fontStyle; - txt.text = "Text"; - txt.alignment = anchor; - txt.horizontalOverflow = HorizontalWrapMode.Overflow; - txt.verticalOverflow = VerticalWrapMode.Overflow; - txt.color = color; - txt.lineSpacing = lineSpacing; - txt.raycastTarget = false; - txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate); - - RectTransform rect = GetOrAddComponent(txtObj); - rect.localPosition = Vector3.zero; - rect.sizeDelta = sizeDelta; - rect.anchorMin = anchorMin; - rect.anchorMax = anchorMax; - rect.pivot = pivot; - return txt; - } - -#if dUI_TextMeshPro - public static TextMeshProUGUI AddTMPTextObject(string name, Transform parent, TMP_FontAsset font, Color color, - TextAlignmentOptions anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, - int fontSize = 14, float rotate = 0, FontStyles fontStyle = FontStyles.Normal, float lineSpacing = 1) - { - GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); - var txt = GetOrAddComponent(txtObj); - txt.font = font; - txt.fontSize = fontSize; - txt.fontStyle = fontStyle; - txt.text = "Text"; - txt.alignment = anchor; - txt.color = color; - txt.lineSpacing = lineSpacing; - txt.raycastTarget = false; - txt.enableWordWrapping = false; - txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate); - - RectTransform rect = GetOrAddComponent(txtObj); - rect.localPosition = Vector3.zero; - rect.sizeDelta = sizeDelta; - rect.anchorMin = anchorMin; - rect.anchorMax = anchorMax; - rect.pivot = pivot; - return txt; - } -#endif - - public static Button AddButtonObject(string name, Transform parent, Font font, int fontSize, - Color color, TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, - Vector2 sizeDelta, float lineSpacing) - { - GameObject btnObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); - GetOrAddComponent(btnObj); - GetOrAddComponent public bool selected { get { return m_Selected; } set { m_Selected = value; } } /// - /// the icon of data. - /// |数据项图标样式。 - /// - public IconStyle iconStyle { get { return m_IconStyles.Count > 0 ? m_IconStyles[0] : null; } } - /// /// 单个数据项的标签设置。 /// - public LabelStyle label { get { return m_Labels.Count > 0 ? m_Labels[0] : null; } } + public LabelStyle labelStyle { get { return m_Labels.Count > 0 ? m_Labels[0] : null; } } public LabelLine labelLine { get { return m_LabelLines.Count > 0 ? m_LabelLines[0] : null; } } /// /// 单个数据项的样式设置。 @@ -127,7 +121,6 @@ namespace XCharts.Runtime m_PreviousData.Clear(); m_DataUpdateTime.Clear(); m_DataUpdateFlag.Clear(); - m_IconStyles.Clear(); m_Labels.Clear(); m_LabelLines.Clear(); m_ItemStyles.Clear(); @@ -147,12 +140,6 @@ namespace XCharts.Runtime m_ItemStyles.Add(new ItemStyle() { show = true }); return m_ItemStyles[0] as T; } - else if (type == typeof(IconStyle)) - { - if (m_IconStyles.Count == 0) - m_IconStyles.Add(new IconStyle() { show = true }); - return m_IconStyles[0] as T; - } else if (type == typeof(LabelStyle)) { if (m_Labels.Count == 0) @@ -204,7 +191,6 @@ namespace XCharts.Runtime public void RemoveAllComponent() { m_ItemStyles.Clear(); - m_IconStyles.Clear(); m_Labels.Clear(); m_LabelLines.Clear(); m_Symbols.Clear(); @@ -219,8 +205,6 @@ namespace XCharts.Runtime var type = typeof(T); if (type == typeof(ItemStyle)) m_ItemStyles.Clear(); - else if (type == typeof(IconStyle)) - m_IconStyles.Clear(); else if (type == typeof(LabelStyle)) m_Labels.Clear(); else if (type == typeof(LabelLine)) @@ -415,23 +399,23 @@ namespace XCharts.Runtime public float GetLabelWidth() { - if (labelObject != null) return labelObject.GetLabelWidth(); + if (labelObject != null) return labelObject.GetTextWidth(); else return 0; } public float GetLabelHeight() { - if (labelObject != null) return labelObject.GetLabelHeight(); + if (labelObject != null) return labelObject.GetTextHeight(); return 0; } public void SetLabelActive(bool flag) { - if (labelObject != null) labelObject.SetLabelActive(flag); + if (labelObject != null) labelObject.SetActive(flag); } public void SetIconActive(bool flag) { - if (labelObject != null) labelObject.SetIconActive(flag); + if (labelObject != null) labelObject.SetActive(flag); } public void SetPolygon(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index b46941c2..ca2665a6 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -236,32 +236,17 @@ namespace XCharts.Runtime return false; var serieEmphasisLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData); - var iconStyle = SerieHelper.GetIconStyle(serie, serieData); if (!serieLabel.show - && (serieEmphasisLabel == null || !serieEmphasisLabel.show) - && (iconStyle == null || !iconStyle.show)) + && (serieEmphasisLabel == null || !serieEmphasisLabel.show)) return false; - var dataAutoColor = (Color)chart.theme.GetColor(serieData.index); - + var dataAutoColor = (Color)chart.theme.GetColor(serie.useDataNameForColor ? serieData.index : serie.index); var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index); - var color = serieLabel.textStyle.autoColor ? dataAutoColor : chart.theme.common.textColor; - var iconWidth = iconStyle != null ? iconStyle.width : 20; - var iconHeight = iconStyle != null ? iconStyle.height : 20; - var labelObj = SerieLabelPool.Get(textName, serieLabelRoot.transform, serieLabel, color, - iconWidth, iconHeight, chart.theme); - var iconImage = labelObj.transform.Find("Icon").GetComponent(); - var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; - var item = ChartHelper.GetOrAddComponent(labelObj); - item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); - item.SetIcon(iconImage); - item.SetIconActive(iconStyle != null && iconStyle.show); - if (serieLabel.textStyle.autoBackgroundColor) - item.color = dataAutoColor; - else - item.color = serieLabel.textStyle.backgroundColor; - serieData.labelObject = item; + var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common, + "", dataAutoColor, TextAnchor.MiddleCenter); + label.SetActive(serieLabel.show); + serieData.labelObject = label; if (serieData.context.children.Count > 0) { @@ -287,30 +272,10 @@ namespace XCharts.Runtime } if (m_SerieRoot == null) InitRoot(); - var serieLabel = serie.endLabel; - var textStyle = serieLabel.textStyle; var dataAutoColor = (Color)chart.theme.GetColor(serie.index); - - var color = serieLabel.textStyle.autoColor ? dataAutoColor : chart.theme.common.textColor; - - var anchorMin = new Vector2(0f, 0.5f); - var anchorMax = new Vector2(0f, 0.5f); - var pivot = new Vector2(0f, 0.5f); - var sizeDelta = new Vector2(50, textStyle.GetFontSize(chart.theme.common) + 2); - var labelObj = ChartHelper.AddObject(s_SerieEndLabelObjectName, m_SerieRoot.transform, anchorMin, anchorMax, pivot, sizeDelta); - var txt = ChartHelper.AddTextObject("Text", labelObj.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, - chart.theme.common); - txt.SetColor(color); - txt.SetAlignment(textStyle.alignment); - txt.SetText("Text"); - txt.SetLocalPosition(new Vector2(0, 0)); - txt.SetLocalEulerAngles(Vector3.zero); - - var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; - m_EndLabel = ChartHelper.GetOrAddComponent(labelObj); - m_EndLabel.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); - m_EndLabel.SetIconActive(false); - m_EndLabel.SetActive(true); + m_EndLabel = ChartHelper.AddChartLabel(s_SerieEndLabelObjectName, m_SerieRoot.transform, serie.endLabel, + chart.theme.common, "", dataAutoColor, TextAnchor.MiddleLeft); + m_EndLabel.SetActive(serie.endLabel.show); RefreshEndLabelInternal(); } @@ -325,28 +290,20 @@ namespace XCharts.Runtime ChartHelper.RemoveComponent(serieTitleRoot); SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); - var anchorMin = new Vector2(0.5f, 0.5f); - var anchorMax = new Vector2(0.5f, 0.5f); - var pivot = new Vector2(0.5f, 0.5f); - var fontSize = 10; - var sizeDelta = new Vector2(50, fontSize + 2); for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.data[i]; var titleStyle = SerieHelper.GetTitleStyle(serie, serieData); if (titleStyle == null) continue; var color = chart.GetLegendRealShowNameColor(serieData.name); - var label = ChartHelper.AddDefaultChartLabel("title_" + i, serieTitleRoot.transform, anchorMin, anchorMax, - pivot, sizeDelta, titleStyle.textStyle, chart.theme.common, serieData.name); + + var label = ChartHelper.AddChartLabel("title_" + i, serieTitleRoot.transform, titleStyle, chart.theme.common, + serieData.name, color, TextAnchor.MiddleCenter); serieData.titleObject = label; label.SetActive(titleStyle.show); var labelPosition = GetSerieDataTitlePosition(serieData, titleStyle); var offset = titleStyle.GetOffset(serie.context.insideRadius); label.SetPosition(labelPosition + offset); - if (titleStyle.textStyle.autoBackgroundColor) - label.color = color; - else - label.color = titleStyle.textStyle.backgroundColor; } } @@ -366,10 +323,8 @@ namespace XCharts.Runtime var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); var emphasisLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData); var isHighlight = (serieData.context.highlight && emphasisLabel != null && emphasisLabel.show); - var iconStyle = SerieHelper.GetIconStyle(serie, serieData); var isIgnore = serie.IsIgnoreIndex(serieData.index, defaultDimension); var currLabel = isHighlight && emphasisLabel != null ? emphasisLabel : serieLabel; - serieData.labelObject.UpdateIcon(iconStyle); if (serie.show && currLabel != null && (currLabel.show || isHighlight) @@ -382,28 +337,28 @@ namespace XCharts.Runtime ? ChartCached.NumberToStr(value, serieLabel.numericFormatter) : SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, currLabel, chart.theme.GetColor(colorIndex)); - var isInsidePosition = currLabel.position == LabelStyle.Position.Inside; - //text color - var textColor = chart.theme.common.textColor; - if (!ChartHelper.IsClearColor(currLabel.textStyle.color)) - textColor = currLabel.textStyle.color; - else if (isInsidePosition) - textColor = Color.white; - if (currLabel.textStyle.autoColor && serie.useDataNameForColor) - textColor = chart.theme.GetColor(serieData.index); - //text rotate - var rotate = currLabel.textStyle.rotate; - if (currLabel.textStyle.rotate > 0 && isInsidePosition) - { - var currAngle = serieData.context.halfAngle; - if (currAngle > 0) - { - if (currAngle > 180) rotate += 270 - currAngle; - else rotate += -(currAngle - 90); - } - } - SerieLabelHelper.ResetLabel(serieData.labelObject.label, currLabel, chart.theme, textColor, rotate); + // var isInsidePosition = currLabel.position == LabelStyle.Position.Inside; + // //text color + // var textColor = chart.theme.common.textColor; + // if (!ChartHelper.IsClearColor(currLabel.textStyle.color)) + // textColor = currLabel.textStyle.color; + // else if (isInsidePosition) + // textColor = Color.white; + // if (currLabel.textStyle.autoColor && serie.useDataNameForColor) + // textColor = chart.theme.GetColor(serieData.index); + // //text rotate + // var rotate = currLabel.textStyle.rotate; + // if (currLabel.textStyle.rotate > 0 && isInsidePosition) + // { + // var currAngle = serieData.context.halfAngle; + // if (currAngle > 0) + // { + // if (currAngle > 180) rotate += 270 - currAngle; + // else rotate += -(currAngle - 90); + // } + // } + // SerieLabelHelper.ResetLabel(serieData.labelObject.text, currLabel, chart.theme, textColor, rotate); serieData.SetLabelActive(!isIgnore); serieData.labelObject.SetText(content); diff --git a/package.json b/package.json index dcff77ff..6ca1a01b 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "com.monitor1394.xcharts", "displayName": "XCharts", - "version": "3.0.0-preview7", - "date": "20220407", - "checkdate": "20220407", + "version": "3.0.0-preview8", + "date": "20220426", + "checkdate": "20220426", "desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!", "unity": "2018.3", "description": "A charting and data visualization library for Unity.",