From 489095865dc8bf85d1d6ab85a40f1240fd81fd73 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 11 Jan 2021 08:54:28 +0800 Subject: [PATCH] XCharts 2.0 --- CHANGELOG-EN.md | 2 +- CHANGELOG.md | 2 +- Documentation/XChartsAPI.md | 18 +- Documentation/XCharts配置项手册.md | 47 +- Documentation/xcharts-api-EN.md | 12 +- Documentation/xcharts-configuration-EN.md | 65 +- Editor/BarChartEditor.cs | 16 +- Editor/BaseChartEditor.cs | 172 +- Editor/CoordinateChartEditor.cs | 65 +- Editor/GaugeChartEditor.cs | 23 +- Editor/HeatmapChartEditor.cs | 20 +- Editor/LineChartEditor.cs | 15 +- Editor/LiquidChartEditor.cs | 14 - Editor/PieChartEditor.cs | 22 +- Editor/PolarChartEditor.cs | 34 +- Editor/PropertyDrawers/AngleAxisDrawer.cs | 40 - Editor/PropertyDrawers/AnimationDrawer.cs | 82 +- Editor/PropertyDrawers/AreaStyleDrawer.cs | 69 +- Editor/PropertyDrawers/AxisDrawer.cs | 287 ++- Editor/PropertyDrawers/AxisLabelDrawer.cs | 81 - Editor/PropertyDrawers/AxisLineDrawer.cs | 65 - Editor/PropertyDrawers/AxisNameDrawer.cs | 75 - Editor/PropertyDrawers/AxisSplitAreaDrawer.cs | 61 - .../AxisSplitAreaDrawer.cs.meta | 11 - Editor/PropertyDrawers/AxisSplitLineDrawer.cs | 55 - .../AxisSplitLineDrawer.cs.meta | 11 - Editor/PropertyDrawers/AxisTickDrawer.cs | 55 - Editor/PropertyDrawers/AxisTickDrawer.cs.meta | 11 - Editor/PropertyDrawers/BackgroundDrawer.cs | 64 +- Editor/PropertyDrawers/BasePropertyDrawer.cs | 149 ++ ...wer.cs.meta => BasePropertyDrawer.cs.meta} | 2 +- .../PropertyDrawers/ComponentThemeDrawer.cs | 186 ++ ...r.cs.meta => ComponentThemeDrawer.cs.meta} | 2 +- Editor/PropertyDrawers/DataZoomDrawer.cs | 131 +- Editor/PropertyDrawers/EmphasisStyleDrawer.cs | 49 +- Editor/PropertyDrawers/GaugeAxisDrawer.cs | 104 +- Editor/PropertyDrawers/GaugeAxisLineDrawer.cs | 76 - .../GaugeAxisLineDrawer.cs.meta | 11 - .../GaugeAxisLineStageColorDrawer.cs | 33 - .../GaugeAxisLineStageColorDrawer.cs.meta | 11 - .../PropertyDrawers/GaugeAxisSplitDrawer.cs | 54 - .../GaugeAxisSplitDrawer.cs.meta | 11 - Editor/PropertyDrawers/GaugeAxisTickDrawer.cs | 57 - .../GaugeAxisTickDrawer.cs.meta | 11 - Editor/PropertyDrawers/GaugePointerDrawer.cs | 51 - .../GaugePointerDrawer.cs.meta | 11 - Editor/PropertyDrawers/GridDrawer.cs | 56 +- Editor/PropertyDrawers/IconStyleDrawer.cs | 65 +- Editor/PropertyDrawers/ItemStyleDrawer.cs | 106 +- Editor/PropertyDrawers/LegendDrawer.cs | 118 +- Editor/PropertyDrawers/LineArrowDrawer.cs | 70 +- Editor/PropertyDrawers/LineDrawer.cs | 94 + ...eAxisDrawer.cs.meta => LineDrawer.cs.meta} | 2 +- Editor/PropertyDrawers/LineStyleDrawer.cs | 63 +- Editor/PropertyDrawers/LocationDrawer.cs | 107 +- Editor/PropertyDrawers/PolarDrawer.cs | 49 +- Editor/PropertyDrawers/RadarDrawer.cs | 153 +- .../PropertyDrawers/RadarIndicatorDrawer.cs | 64 - .../RadarIndicatorDrawer.cs.meta | 11 - Editor/PropertyDrawers/RadiusAxisDrawer.cs | 24 - .../PropertyDrawers/RadiusAxisDrawer.cs.meta | 11 - Editor/PropertyDrawers/SerieDrawer.cs | 67 +- Editor/PropertyDrawers/SerieLabelDrawer.cs | 135 +- Editor/PropertyDrawers/SerieSymbolDrawer.cs | 99 +- Editor/PropertyDrawers/SeriesDrawer.cs | 14 +- Editor/PropertyDrawers/SettingsDrawer.cs | 70 +- Editor/PropertyDrawers/TextLimitDrawer.cs | 48 +- Editor/PropertyDrawers/TextStyleDrawer.cs | 85 +- Editor/PropertyDrawers/ThemeDrawer.cs | 182 ++ ...NameDrawer.cs.meta => ThemeDrawer.cs.meta} | 2 +- Editor/PropertyDrawers/ThemeInfoDrawer.cs | 369 ---- .../PropertyDrawers/ThemeInfoDrawer.cs.meta | 11 - Editor/PropertyDrawers/TitleDrawer.cs | 68 +- Editor/PropertyDrawers/TitleStyleDrawer.cs | 44 +- Editor/PropertyDrawers/TooltipDrawer.cs | 105 +- Editor/PropertyDrawers/VesselDrawer.cs | 74 +- Editor/PropertyDrawers/VisualMapDrawer.cs | 163 +- Editor/PropertyDrawers/XAxisDrawer.cs | 24 - Editor/PropertyDrawers/XAxisDrawer.cs.meta | 11 - Editor/PropertyDrawers/YAxisDrawer.cs | 24 - Editor/PropertyDrawers/YAxisDrawer.cs.meta | 11 - Editor/RadarChartEditor.cs | 15 - Editor/RingChartEditor.cs | 18 +- Editor/ScatterChartEditor.cs | 20 +- Editor/Tools/UpgradeChartColor.cs | 377 ---- Editor/Tools/UpgradeChartColor.cs.meta | 11 - Editor/Utility/ChartEditorHelper.cs | 203 +- Editor/{Tools.meta => Window.meta} | 2 +- Editor/Window/AddSerieEditor.cs | 56 + Editor/Window/AddSerieEditor.cs.meta | 11 + Editor/{ => Window}/CheckVersionEditor.cs | 48 +- .../{ => Window}/CheckVersionEditor.cs.meta | 2 +- Editor/XChartEditor.cs | 32 +- Editor/XChartMgrEditor.cs | 20 +- Editor/XCharts.Editor.asmdef | 8 +- Editor/XChartsSettingsEditor.cs | 69 + Editor/XChartsSettingsEditor.cs.meta | 11 + Examples/Runtime/Example00_CheatSheet.cs | 15 +- Examples/Runtime/Example01_UpdateData.cs | 12 +- Examples/Runtime/Example02_ChartEvent.cs | 12 +- Examples/Runtime/Example03_ChartAnimation.cs | 12 +- Examples/Runtime/Example10_LineChart.cs | 16 +- Examples/Runtime/Example11_AddSinCurve.cs | 33 +- Examples/Runtime/Example12_CustomDrawing.cs | 21 +- Examples/Runtime/Example13_LineSimple.cs | 30 +- Examples/Runtime/Example20_BarChart.cs | 16 +- Examples/Runtime/Example30_PieChart.cs | 23 +- Examples/Runtime/Example31_PieUpdateName.cs | 12 +- Examples/Runtime/Example40_Radar.cs | 12 +- Examples/Runtime/Example41_RadarUpdate.cs | 12 +- Examples/Runtime/Example50_Scatter.cs | 12 +- Examples/Runtime/Example60_Heatmap.cs | 30 +- Examples/Runtime/Example70_Gauge.cs | 14 +- Examples/Runtime/Example80_Polar.cs | 12 +- Examples/Runtime/Example_Dynamic.cs | 14 +- Examples/Runtime/Example_LargeData.cs | 12 +- Examples/Runtime/Example_PieChart.cs | 12 +- Examples/Runtime/Example_Test.cs | 24 +- Resources.meta | 8 + Resources/XChartsSettings.asset | 48 + Resources/XChartsSettings.asset.meta | 8 + Runtime/API/BarChart_API.cs | 12 +- Runtime/API/BaseChart_API.cs | 146 +- Runtime/API/BaseGraph_API.cs | 24 +- Runtime/API/CoordinateChart_API.cs | 163 +- Runtime/API/LiquidChart_API.cs | 15 +- Runtime/API/PieChart_API.cs | 22 - Runtime/API/PieChart_API.cs.meta | 11 - Runtime/API/PolarChart_API.cs | 21 +- Runtime/API/RadarChart_API.cs | 29 +- Runtime/API/RingChart_API.cs | 15 +- Runtime/BarChart.cs | 23 +- Runtime/Component/ChartComponent.cs | 50 +- Runtime/Component/Main/Axis.cs | 155 +- Runtime/Component/Main/Background.cs | 27 +- Runtime/Component/Main/DataZoom.cs | 297 ++- Runtime/Component/Main/Legend.cs | 55 +- Runtime/Component/Main/Polar.cs | 20 +- Runtime/Component/Main/Radar.cs | 83 +- Runtime/Component/Main/Serie.cs | 188 +- Runtime/Component/Main/Series.cs | 29 +- Runtime/Component/Main/Settings.cs | 75 +- Runtime/Component/Main/Theme.cs | 629 ------ Runtime/Component/Main/Theme.cs.meta | 11 - Runtime/Component/Main/Title.cs | 56 +- Runtime/Component/Main/Tooltip.cs | 65 +- Runtime/Component/Main/Vessel.cs | 30 +- Runtime/Component/Main/VisualMap.cs | 46 +- Runtime/Component/Main/XGrid.cs | 41 +- Runtime/Component/MainComponent.cs | 13 - Runtime/Component/MainComponent.cs.meta | 11 - Runtime/Component/Sub/AreaStyle.cs | 52 +- Runtime/Component/Sub/Arrow.cs | 97 + Runtime/Component/Sub/Arrow.cs.meta | 11 + Runtime/Component/Sub/AxisLabel.cs | 94 +- Runtime/Component/Sub/AxisLine.cs | 116 +- Runtime/Component/Sub/AxisName.cs | 88 +- Runtime/Component/Sub/AxisSplitArea.cs | 33 +- Runtime/Component/Sub/AxisSplitLine.cs | 52 +- Runtime/Component/Sub/AxisTick.cs | 55 +- Runtime/Component/Sub/BaseLine.cs | 89 + Runtime/Component/Sub/BaseLine.cs.meta | 11 + Runtime/Component/Sub/Emphasis.cs | 16 +- Runtime/Component/Sub/GaugeAxis.cs | 194 +- Runtime/Component/Sub/GaugeAxisLine.cs | 63 + Runtime/Component/Sub/GaugeAxisLine.cs.meta | 11 + Runtime/Component/Sub/GaugeAxisSplitLine.cs | 20 + .../Component/Sub/GaugeAxisSplitLine.cs.meta | 11 + Runtime/Component/Sub/GaugeAxisTick.cs | 27 + Runtime/Component/Sub/GaugeAxisTick.cs.meta | 11 + Runtime/Component/Sub/GaugePointer.cs | 18 +- Runtime/Component/Sub/IconStyle.cs | 12 +- Runtime/Component/Sub/ItemStyle.cs | 42 +- Runtime/Component/Sub/LineArrow.cs | 66 +- Runtime/Component/Sub/LineStyle.cs | 73 +- Runtime/Component/Sub/Location.cs | 81 +- Runtime/Component/Sub/SerieAnimation.cs | 12 +- Runtime/Component/Sub/SerieData.cs | 15 +- Runtime/Component/Sub/SerieLabel.cs | 117 +- Runtime/Component/Sub/SerieSymbol.cs | 78 +- Runtime/Component/Sub/TextLimit.cs | 32 +- Runtime/Component/Sub/TextStyle.cs | 110 +- Runtime/Component/Sub/TitleStyle.cs | 36 +- Runtime/Component/SubComponent.cs | 13 - Runtime/Component/SubComponent.cs.meta | 11 - Runtime/Component/Theme.meta | 8 + Runtime/Component/Theme/AxisTheme.cs | 255 +++ Runtime/Component/Theme/AxisTheme.cs.meta | 11 + Runtime/Component/Theme/ChartTheme.cs | 527 +++++ Runtime/Component/Theme/ChartTheme.cs.meta | 11 + Runtime/Component/Theme/ComponentTheme.cs | 109 + .../Component/Theme/ComponentTheme.cs.meta | 11 + Runtime/Component/Theme/DataZoomTheme.cs | 132 ++ Runtime/Component/Theme/DataZoomTheme.cs.meta | 11 + Runtime/Component/Theme/GaugeAxisTheme.cs | 83 + .../Component/Theme/GaugeAxisTheme.cs.meta | 11 + Runtime/Component/Theme/LegendTheme.cs | 43 + Runtime/Component/Theme/LegendTheme.cs.meta | 11 + Runtime/Component/Theme/SerieTheme.cs | 93 + Runtime/Component/Theme/SerieTheme.cs.meta | 11 + Runtime/Component/Theme/SubTitleTheme.cs | 32 + Runtime/Component/Theme/SubTitleTheme.cs.meta | 11 + Runtime/Component/Theme/TitleTheme.cs | 31 + Runtime/Component/Theme/TitleTheme.cs.meta | 11 + Runtime/Component/Theme/TooltipTheme.cs | 123 ++ Runtime/Component/Theme/TooltipTheme.cs.meta | 11 + Runtime/Component/Theme/VisualMapTheme.cs | 93 + .../Component/Theme/VisualMapTheme.cs.meta | 11 + Runtime/GaugeChart.cs | 340 +--- Runtime/HeatmapChart.cs | 96 +- Runtime/Helper/CheckHelper.cs | 86 +- Runtime/Helper/FormatterHelper.cs | 18 +- Runtime/Helper/LayoutHelper.cs | 16 +- Runtime/Helper/SerieHelper.cs | 19 +- Runtime/Internal/APIException.cs | 20 - Runtime/Internal/APIException.cs.meta | 11 - Runtime/Internal/BaseChart.cs | 873 ++++---- Runtime/Internal/BaseGraph.cs | 152 +- Runtime/Internal/CoordinateChart.cs | 1779 +++++++++-------- Runtime/Internal/CoordinateChart_DrawBar.cs | 396 ++-- .../Internal/CoordinateChart_DrawHeatmap.cs | 240 +-- Runtime/Internal/CoordinateChart_DrawLine.cs | 549 ++--- .../Internal/CoordinateChart_DrawScatter.cs | 43 +- Runtime/Internal/DrawSerieGauge.cs | 408 ++++ Runtime/Internal/DrawSerieGauge.cs.meta | 11 + Runtime/Internal/DrawSerieLiquid.cs | 259 +++ Runtime/Internal/DrawSerieLiquid.cs.meta | 11 + Runtime/Internal/DrawSeriePie.cs | 559 ++++++ Runtime/Internal/DrawSeriePie.cs.meta | 11 + Runtime/Internal/DrawSerieRadar.cs | 762 +++++++ Runtime/Internal/DrawSerieRadar.cs.meta | 11 + Runtime/Internal/DrawSerieRing.cs | 361 ++++ Runtime/Internal/DrawSerieRing.cs.meta | 11 + Runtime/Internal/DrawSerieTemplate.cs | 71 + Runtime/Internal/DrawSerieTemplate.cs.meta | 11 + Runtime/Internal/Helper/AxisHelper.cs | 45 +- Runtime/Internal/Helper/ItemStyleHelper.cs | 12 +- Runtime/Internal/Helper/LegendHelper.cs | 63 +- Runtime/Internal/Helper/PolarHelper.cs | 12 +- Runtime/Internal/Helper/SerieHelper.cs | 29 +- Runtime/Internal/Helper/SerieLabelHelper.cs | 56 +- Runtime/Internal/Helper/SeriesHelper.cs | 70 +- Runtime/Internal/Helper/ThemeHelper.cs | 18 +- Runtime/Internal/Helper/TitleHelper.cs | 34 - Runtime/Internal/Helper/TitleHelper.cs.meta | 11 - Runtime/Internal/Helper/TitleStyleHelper.cs | 12 +- Runtime/Internal/Helper/TooltipHelper.cs | 156 +- Runtime/Internal/Helper/VesselHelper.cs | 16 +- Runtime/Internal/Helper/VisualMapHelper.cs | 28 +- Runtime/Internal/Interface/IDrawSerie.cs | 28 + Runtime/Internal/Interface/IDrawSerie.cs.meta | 11 + Runtime/Internal/Interface/IJsonData.cs | 17 - Runtime/Internal/Interface/IJsonData.cs.meta | 11 - .../Internal/Interface/IPropertyChanged.cs | 12 +- .../Object/{LabelObject.cs => ChartLabel.cs} | 39 +- Runtime/Internal/Object/ChartLabel.cs.meta | 11 + Runtime/Internal/Object/ChartObject.cs | 12 +- Runtime/Internal/Object/ChartText.cs | 255 +++ Runtime/Internal/Object/ChartText.cs.meta | 11 + Runtime/Internal/Object/LabelObject.cs.meta | 11 - Runtime/Internal/Object/LegendItem.cs | 32 +- Runtime/Internal/Painter.cs | 79 + Runtime/Internal/Painter.cs.meta | 11 + Runtime/Internal/Pools/AxisPool.cs | 12 +- Runtime/Internal/Pools/ListPool.cs | 12 +- Runtime/Internal/Pools/ObjectPool.cs | 12 +- Runtime/Internal/Pools/SerieDataPool.cs | 12 +- Runtime/Internal/Pools/SerieLabelPool.cs | 39 +- Runtime/Internal/Utility/ChartCached.cs | 14 +- Runtime/Internal/Utility/ChartConst.cs | 12 +- Runtime/Internal/Utility/ChartDrawer.cs | 1363 +------------ Runtime/Internal/Utility/ChartHelper.cs | 210 +- .../Internal/Utility/PropertyUtility.cs.meta | 11 - Runtime/LineChart.cs | 34 +- Runtime/LiquidChart.cs | 243 +-- Runtime/PieChart.cs | 530 +---- Runtime/PolarChart.cs | 514 +++-- Runtime/RadarChart.cs | 768 +------ Runtime/RingChart.cs | 327 +-- Runtime/ScatterChart.cs | 62 +- Runtime/Template.meta | 8 + Runtime/Template/SerieTemplate.cs | 172 ++ Runtime/Template/SerieTemplate.cs.meta | 11 + Runtime/Utils.meta | 8 + Runtime/Utils/ColorUtil.cs | 29 + Runtime/Utils/ColorUtil.cs.meta | 11 + Runtime/Utils/DefineSymbolsUtil.cs | 93 + Runtime/Utils/DefineSymbolsUtil.cs.meta | 11 + .../PropertyUtil.cs} | 14 +- Runtime/Utils/PropertyUtil.cs.meta | 11 + Runtime/XCharts.Runtime.asmdef | 4 +- Runtime/{Internal/Utility => }/XChartsMgr.cs | 182 +- .../{Internal/Utility => }/XChartsMgr.cs.meta | 2 +- Runtime/XChartsPackageResourceImporter.cs | 209 ++ .../XChartsPackageResourceImporter.cs.meta | 11 + Runtime/XChartsSettings.cs | 143 ++ Runtime/XChartsSettings.cs.meta | 11 + Runtime/XUGL.meta | 8 + Runtime/XUGL/UGL.cs | 1505 ++++++++++++++ Runtime/XUGL/UGL.cs.meta | 11 + Runtime/XUGL/UGLExample.cs | 62 + Runtime/XUGL/UGLExample.cs.meta | 11 + Runtime/XUGL/UGLHelper.cs | 219 ++ Runtime/XUGL/UGLHelper.cs.meta | 11 + 304 files changed, 14799 insertions(+), 12503 deletions(-) delete mode 100644 Editor/PropertyDrawers/AngleAxisDrawer.cs delete mode 100644 Editor/PropertyDrawers/AxisLabelDrawer.cs delete mode 100644 Editor/PropertyDrawers/AxisLineDrawer.cs delete mode 100644 Editor/PropertyDrawers/AxisNameDrawer.cs delete mode 100644 Editor/PropertyDrawers/AxisSplitAreaDrawer.cs delete mode 100644 Editor/PropertyDrawers/AxisSplitAreaDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/AxisSplitLineDrawer.cs delete mode 100644 Editor/PropertyDrawers/AxisSplitLineDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/AxisTickDrawer.cs delete mode 100644 Editor/PropertyDrawers/AxisTickDrawer.cs.meta create mode 100644 Editor/PropertyDrawers/BasePropertyDrawer.cs rename Editor/PropertyDrawers/{AxisLabelDrawer.cs.meta => BasePropertyDrawer.cs.meta} (83%) create mode 100644 Editor/PropertyDrawers/ComponentThemeDrawer.cs rename Editor/PropertyDrawers/{AxisLineDrawer.cs.meta => ComponentThemeDrawer.cs.meta} (83%) delete mode 100644 Editor/PropertyDrawers/GaugeAxisLineDrawer.cs delete mode 100644 Editor/PropertyDrawers/GaugeAxisLineDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs delete mode 100644 Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs delete mode 100644 Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/GaugeAxisTickDrawer.cs delete mode 100644 Editor/PropertyDrawers/GaugeAxisTickDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/GaugePointerDrawer.cs delete mode 100644 Editor/PropertyDrawers/GaugePointerDrawer.cs.meta create mode 100644 Editor/PropertyDrawers/LineDrawer.cs rename Editor/PropertyDrawers/{AngleAxisDrawer.cs.meta => LineDrawer.cs.meta} (83%) delete mode 100644 Editor/PropertyDrawers/RadarIndicatorDrawer.cs delete mode 100644 Editor/PropertyDrawers/RadarIndicatorDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/RadiusAxisDrawer.cs delete mode 100644 Editor/PropertyDrawers/RadiusAxisDrawer.cs.meta create mode 100644 Editor/PropertyDrawers/ThemeDrawer.cs rename Editor/PropertyDrawers/{AxisNameDrawer.cs.meta => ThemeDrawer.cs.meta} (83%) delete mode 100644 Editor/PropertyDrawers/ThemeInfoDrawer.cs delete mode 100644 Editor/PropertyDrawers/ThemeInfoDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/XAxisDrawer.cs delete mode 100644 Editor/PropertyDrawers/XAxisDrawer.cs.meta delete mode 100644 Editor/PropertyDrawers/YAxisDrawer.cs delete mode 100644 Editor/PropertyDrawers/YAxisDrawer.cs.meta delete mode 100644 Editor/Tools/UpgradeChartColor.cs delete mode 100644 Editor/Tools/UpgradeChartColor.cs.meta rename Editor/{Tools.meta => Window.meta} (77%) create mode 100644 Editor/Window/AddSerieEditor.cs create mode 100644 Editor/Window/AddSerieEditor.cs.meta rename Editor/{ => Window}/CheckVersionEditor.cs (62%) rename Editor/{ => Window}/CheckVersionEditor.cs.meta (83%) create mode 100644 Editor/XChartsSettingsEditor.cs create mode 100644 Editor/XChartsSettingsEditor.cs.meta create mode 100644 Resources.meta create mode 100644 Resources/XChartsSettings.asset create mode 100644 Resources/XChartsSettings.asset.meta delete mode 100644 Runtime/API/PieChart_API.cs delete mode 100644 Runtime/API/PieChart_API.cs.meta delete mode 100644 Runtime/Component/Main/Theme.cs delete mode 100644 Runtime/Component/Main/Theme.cs.meta delete mode 100644 Runtime/Component/MainComponent.cs delete mode 100644 Runtime/Component/MainComponent.cs.meta create mode 100644 Runtime/Component/Sub/Arrow.cs create mode 100644 Runtime/Component/Sub/Arrow.cs.meta create mode 100644 Runtime/Component/Sub/BaseLine.cs create mode 100644 Runtime/Component/Sub/BaseLine.cs.meta create mode 100644 Runtime/Component/Sub/GaugeAxisLine.cs create mode 100644 Runtime/Component/Sub/GaugeAxisLine.cs.meta create mode 100644 Runtime/Component/Sub/GaugeAxisSplitLine.cs create mode 100644 Runtime/Component/Sub/GaugeAxisSplitLine.cs.meta create mode 100644 Runtime/Component/Sub/GaugeAxisTick.cs create mode 100644 Runtime/Component/Sub/GaugeAxisTick.cs.meta delete mode 100644 Runtime/Component/SubComponent.cs delete mode 100644 Runtime/Component/SubComponent.cs.meta create mode 100644 Runtime/Component/Theme.meta create mode 100644 Runtime/Component/Theme/AxisTheme.cs create mode 100644 Runtime/Component/Theme/AxisTheme.cs.meta create mode 100644 Runtime/Component/Theme/ChartTheme.cs create mode 100644 Runtime/Component/Theme/ChartTheme.cs.meta create mode 100644 Runtime/Component/Theme/ComponentTheme.cs create mode 100644 Runtime/Component/Theme/ComponentTheme.cs.meta create mode 100644 Runtime/Component/Theme/DataZoomTheme.cs create mode 100644 Runtime/Component/Theme/DataZoomTheme.cs.meta create mode 100644 Runtime/Component/Theme/GaugeAxisTheme.cs create mode 100644 Runtime/Component/Theme/GaugeAxisTheme.cs.meta create mode 100644 Runtime/Component/Theme/LegendTheme.cs create mode 100644 Runtime/Component/Theme/LegendTheme.cs.meta create mode 100644 Runtime/Component/Theme/SerieTheme.cs create mode 100644 Runtime/Component/Theme/SerieTheme.cs.meta create mode 100644 Runtime/Component/Theme/SubTitleTheme.cs create mode 100644 Runtime/Component/Theme/SubTitleTheme.cs.meta create mode 100644 Runtime/Component/Theme/TitleTheme.cs create mode 100644 Runtime/Component/Theme/TitleTheme.cs.meta create mode 100644 Runtime/Component/Theme/TooltipTheme.cs create mode 100644 Runtime/Component/Theme/TooltipTheme.cs.meta create mode 100644 Runtime/Component/Theme/VisualMapTheme.cs create mode 100644 Runtime/Component/Theme/VisualMapTheme.cs.meta delete mode 100644 Runtime/Internal/APIException.cs delete mode 100644 Runtime/Internal/APIException.cs.meta create mode 100644 Runtime/Internal/DrawSerieGauge.cs create mode 100644 Runtime/Internal/DrawSerieGauge.cs.meta create mode 100644 Runtime/Internal/DrawSerieLiquid.cs create mode 100644 Runtime/Internal/DrawSerieLiquid.cs.meta create mode 100644 Runtime/Internal/DrawSeriePie.cs create mode 100644 Runtime/Internal/DrawSeriePie.cs.meta create mode 100644 Runtime/Internal/DrawSerieRadar.cs create mode 100644 Runtime/Internal/DrawSerieRadar.cs.meta create mode 100644 Runtime/Internal/DrawSerieRing.cs create mode 100644 Runtime/Internal/DrawSerieRing.cs.meta create mode 100644 Runtime/Internal/DrawSerieTemplate.cs create mode 100644 Runtime/Internal/DrawSerieTemplate.cs.meta delete mode 100644 Runtime/Internal/Helper/TitleHelper.cs delete mode 100644 Runtime/Internal/Helper/TitleHelper.cs.meta create mode 100644 Runtime/Internal/Interface/IDrawSerie.cs create mode 100644 Runtime/Internal/Interface/IDrawSerie.cs.meta delete mode 100644 Runtime/Internal/Interface/IJsonData.cs delete mode 100644 Runtime/Internal/Interface/IJsonData.cs.meta rename Runtime/Internal/Object/{LabelObject.cs => ChartLabel.cs} (76%) create mode 100644 Runtime/Internal/Object/ChartLabel.cs.meta create mode 100644 Runtime/Internal/Object/ChartText.cs create mode 100644 Runtime/Internal/Object/ChartText.cs.meta delete mode 100644 Runtime/Internal/Object/LabelObject.cs.meta create mode 100644 Runtime/Internal/Painter.cs create mode 100644 Runtime/Internal/Painter.cs.meta delete mode 100644 Runtime/Internal/Utility/PropertyUtility.cs.meta create mode 100644 Runtime/Template.meta create mode 100644 Runtime/Template/SerieTemplate.cs create mode 100644 Runtime/Template/SerieTemplate.cs.meta create mode 100644 Runtime/Utils.meta create mode 100644 Runtime/Utils/ColorUtil.cs create mode 100644 Runtime/Utils/ColorUtil.cs.meta create mode 100644 Runtime/Utils/DefineSymbolsUtil.cs create mode 100644 Runtime/Utils/DefineSymbolsUtil.cs.meta rename Runtime/{Internal/Utility/PropertyUtility.cs => Utils/PropertyUtil.cs} (82%) create mode 100644 Runtime/Utils/PropertyUtil.cs.meta rename Runtime/{Internal/Utility => }/XChartsMgr.cs (62%) rename Runtime/{Internal/Utility => }/XChartsMgr.cs.meta (83%) create mode 100644 Runtime/XChartsPackageResourceImporter.cs create mode 100644 Runtime/XChartsPackageResourceImporter.cs.meta create mode 100644 Runtime/XChartsSettings.cs create mode 100644 Runtime/XChartsSettings.cs.meta create mode 100644 Runtime/XUGL.meta create mode 100644 Runtime/XUGL/UGL.cs create mode 100644 Runtime/XUGL/UGL.cs.meta create mode 100644 Runtime/XUGL/UGLExample.cs create mode 100644 Runtime/XUGL/UGLExample.cs.meta create mode 100644 Runtime/XUGL/UGLHelper.cs create mode 100644 Runtime/XUGL/UGLHelper.cs.meta diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index ed2bb9dc..9a9020f0 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -176,7 +176,7 @@ * (2019.11.02) 优化非配置参数变量命名和访问权限,简化`API` * (2019.10.31) 发布`v1.0.2`版本 * (2019.10.31) 修复`prefab`预设制作报错的问题 -* (2019.10.31) 增加访问主题组件API:`BaseChart.themeInfo` +* (2019.10.31) 增加访问主题组件API:`BaseChart.theme` * (2019.10.26) 发布`v1.0.1`版本 * (2019.10.26) 修复版本检查功能在非运行时异常的问题 * (2019.10.26) 增加科学计数法显示数值的支持(查阅`forceENotation`参数) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41bcf7a6..05bd67b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -177,7 +177,7 @@ * (2019.11.02) 优化非配置参数变量命名和访问权限,简化`API` * (2019.10.31) 发布`v1.0.2`版本 * (2019.10.31) 修复`prefab`预设制作报错的问题 -* (2019.10.31) 增加访问主题组件API:`BaseChart.themeInfo` +* (2019.10.31) 增加访问主题组件API:`BaseChart.theme` * (2019.10.26) 发布`v1.0.1`版本 * (2019.10.26) 修复版本检查功能在非运行时异常的问题 * (2019.10.26) 增加科学计数法显示数值的支持(查阅`forceENotation`参数) diff --git a/Documentation/XChartsAPI.md b/Documentation/XChartsAPI.md index a0f39b1c..26e7fd4c 100644 --- a/Documentation/XChartsAPI.md +++ b/Documentation/XChartsAPI.md @@ -6,7 +6,7 @@ ## `BaseChart` -* `BaseChart.themeInfo`:主题组件`ThemeInfo`。 +* `BaseChart.theme`:主题组件`ThemeInfo`。 * `BaseChart.title`:标题组件`Title`。 * `BaseChart.legend`:图例组件`Legend`。 * `BaseChart.tooltip`:提示框组件`Tooltip`。 @@ -25,6 +25,7 @@ * `BaseChart.onDrag`:鼠标拖拽回调。 * `BaseChart.onEndDrag`:鼠标结束拖拽回调。 * `BaseChart.onScroll`:鼠标滚动回调。 +* `BaseChart.onPointerClickPie`:点击柱条回调。参数:`eventData`, `serieIndex`, `dataIndex` * `BaseChart.SetSize(float width, float height)`: 设置图表的宽高(在非stretch pivot下才有效,其他情况需要自己调整RectTransform)。 * `BaseChart.ClearData()`:清除所有数据,系列列表会保留,只是移除列表中系列的数据。 * `BaseChart.RemoveData()`:清除所有系列和图例数据,系列列表也会被清除。 @@ -67,17 +68,13 @@ ## `CoordinateChart` * `CoordinateChart.grid`:网格组件 `Grid`。 -* `CoordinateChart.xAxises`:左右两个 `X` 轴组件 `XAxis`。 -* `CoordinateChart.yAxises`:左右两个 `Y` 轴组件 `YAxis`。 +* `CoordinateChart.xAxes`:左右两个 `X` 轴组件 `XAxis`。 +* `CoordinateChart.yAxes`:左右两个 `Y` 轴组件 `YAxis`。 * `CoordianteChart.xAxis0`:X轴(下)。 * `CoordianteChart.xAxis1`:X轴(上)。 * `CoordianteChart.xAxis0`:Y轴(左)。 * `CoordianteChart.yAxis1`:Y轴(右)。 * `CoordinateChart.dataZoom`:区域缩放组件 `DataZoom`。 -* `CoordinateChart.coordinateX`:坐标系的左下角坐标 `X`。 -* `CoordinateChart.coordinateY`:坐标系的左下角坐标 `Y`。 -* `CoordinateChart.coordinateWidth`:坐标系的宽。 -* `CoordinateChart.coordinateHeight`:坐标系的高。 * `CoordinateChart.ClearAxisData()`:清除所有x轴和y轴的类目数据。 * `CoordinateChart.AddXAxisData(string category, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。 * `CoordinateChart.AddYAxisData(string category, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。 @@ -88,7 +85,7 @@ * `CoordinateChart.IsInCooridate(Vector3 local)`:坐标是否在坐标轴内。 * `CoordinateChart.IsInCooridate(float x, float y)`:坐标是否在坐标轴内。 * `CoordinateChart.IsInCooridate(Vector2 local)`:坐标是否在坐标轴内。 -* `CoordinateChart.ClampInCoordinate(Vector3 pos)`:将坐标限制在坐标系内。 +* `CoordinateChart.ClampInGrid(grid, Vector3 pos)`:将坐标限制在坐标系内。 * `CoordinateChart.CovertXYAxis(int index)`:转换X轴和Y轴的配置。 * `CoordinateChart.UpdateCoordinate()`:更新坐标系原点和宽高。一般内部会自动更新,也可强制更新。 * `CoordinateChart.SetMaxCache(int maxCache)`:设置可缓存的最大数据量。当数据量超过该值时,会自动删除第一个值再加入最新值。 @@ -105,11 +102,6 @@ * `BarChart.onPointerClickBar`:点击柱条回调。参数:`eventData`, `dataIndex` -## `PieChart` - -* 继承自 `BaseChart`。 - -* `PieChart.onPointerClickPie`:点击柱条回调。参数:`eventData`, `serieIndex`, `dataIndex` ## `RadarChart` diff --git a/Documentation/XCharts配置项手册.md b/Documentation/XCharts配置项手册.md index 6be1a744..e62d4d71 100644 --- a/Documentation/XCharts配置项手册.md +++ b/Documentation/XCharts配置项手册.md @@ -276,16 +276,19 @@ * `showDetail`:是否显示 `detail`,即拖拽时候显示详细数值信息。 * `zoomLock`:是否锁定选择区域(或叫做数据窗口)的大小。如果设置为 `true` 则锁定选择区域的大小,也就是说,只能平移,不能缩放。 * ~~`realtime`:拖动时,是否实时更新系列的视图。如果设置为 `false`,则只在拖拽结束的时候更新。~~ -* ~~`backgroundColor`:组件的背景颜色。~~ +* `backgroundColor`:组件的背景颜色。 +* `selectedAreaColor`:框选区域颜色。 * `bottom`:组件离容器下侧的距离。 +* `top`:组件离容器上侧的距离。 +* `left`:组件离容器左侧的距离。 +* `right`:组件离容器右侧的距离。 * `height`:组件高度。 * `rangeMode`:取值类型是取绝对值还是百分比。 * `Percent`:百分比。 * `start`:数据窗口范围的起始百分比。范围是:0 ~ 100。 * `end`:数据窗口范围的结束百分比。范围是:0 ~ 100。 * `scrollSensitivity`:缩放区域组件的敏感度。值越高每次缩放所代表的数据越多。 -* `fontSize`:字体大小。 -* `fontStyle`:字体样式。 +* `textStyle`:字体风格。 * `minShowNum`:最小显示数据个数。当DataZoom放大到最大时,最小显示的数据个数。 ## `VisualMap` @@ -351,15 +354,22 @@ ## `XAxis` -直角坐标系 `grid` 中的 `X` 轴。单个 `grid` 组件最多只能放上下两个 `X` 轴。两个 `X` 轴存储在 `xAxises` 中。 +直角坐标系 `grid` 中的 `X` 轴。单个 `grid` 组件最多只能放上下两个 `X` 轴。两个 `X` 轴存储在 `xAxes` 中。 相关参数: -* `show`:是否显示 `X` 轴。默认 `xAxises[0]` 为 `true`,`xAxises[1]` 为 `false`。 +* `show`:是否显示 `X` 轴。默认 `xAxes[0]` 为 `true`,`xAxes[1]` 为 `false`。 +* `gridIndex`:坐标轴所在的 grid 的索引,默认位于第一个 grid。 * `type`:坐标轴类型。默认为 `Category`。支持以下类型: * `Value`:数值轴,用于连续数据。 * `Category`:类目轴,适用于离散的类目数据,为该类型时必须通过 `data` 设置类目数据。 * `Log`:对数轴,适用于对数数据。 +* `position`:坐标轴在Grid中的位置`AxisPosition`。支持以下类型: + * `Left`:左边。 + * `Right`:右边。 + * `Bottom`:底部。 + * `Top`:顶部。 +* `offset`:坐标轴相对默认位置的偏移。在相同position有多个坐标轴时有用。 * `logBaseE`:对数轴是否以自然数 `e` 为底数,为 `true` 时 `logBase` 失效,只在对数轴(`type:'Log'`)中有效。 * `logBase`:对数轴的底数,只在对数轴(`type:'Log'`)中有效。 * `minMaxType`:坐标轴刻度最大最小值显示类型。默认为 `Default`。有以下三种类型: @@ -407,11 +417,11 @@ ## `YAxis` -直角坐标系 `grid` 中的 `Y` 轴。单个 `grid` 组件最多只能放左右两个 `Y` 轴。两个 `Y` 轴存储在 `yAxises` 中。 +直角坐标系 `grid` 中的 `Y` 轴。单个 `grid` 组件最多只能放左右两个 `Y` 轴。两个 `Y` 轴存储在 `yAxes` 中。 相关参数: -* `show`:是否显示 `Y` 轴。默认 `yAxises[0]` 为 `true`,`yAxises[1]` 为 `false`。 +* `show`:是否显示 `Y` 轴。默认 `yAxes[0]` 为 `true`,`yAxes[1]` 为 `false`。 * `type`:坐标轴类型。默认为 `Value`。有以下两种类型: * `Value`:数值轴,用于连续数据。 * `Category`:类目轴,适用于离散的类目数据,为该类型时必须通过 `data` 设置类目数据。 @@ -518,7 +528,8 @@ * `type`:`Line`。 * `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。 * `stack`:数据堆叠。同个类目轴上系列配置相同的 `stack` 值后,后一个系列的值会在前一个系列的值上相加。 -* `axisIndex`:使用的坐标轴轴的 `index`,在单个图表实例中存在多个坐标轴轴的时候有用。 +* `xAxisIndex`:使用的坐标轴X轴的 `index`,在单个图表实例中存在多个坐标轴的时候有用。 +* `yAxisIndex`:使用的坐标轴Y轴的 `index`,在单个图表实例中存在多个坐标轴的时候有用。 * `minShow`:系列显示数据的最小索引。 * `maxShow`:系列显示数据的最大索引。 * `maxCache`:系列中可缓存的最大数据量。默认为`0`没有限制,大于0时超过指定值会移除旧数据再插入新数据。 @@ -564,7 +575,8 @@ * `type`:`Bar`。 * `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。 * `stack`:数据堆叠。同个类目轴上系列配置相同的 `stack` 值后,后一个系列的值会在前一个系列的值上相加。 -* `axisIndex`:使用的坐标轴轴的 `index`,在单个图表实例中存在多个坐标轴轴的时候有用。 +* `xAxisIndex`:使用的坐标轴X轴的 `index`,在单个图表实例中存在多个坐标轴的时候有用。 +* `yAxisIndex`:使用的坐标轴Y轴的 `index`,在单个图表实例中存在多个坐标轴的时候有用。 * `minShow`:系列显示数据的最小索引。 * `maxShow`:系列显示数据的最大索引。 * `maxCache`:系列中可缓存的最大数据量。默认为`0`没有限制,大于0时超过指定值会移除旧数据再插入新数据。 @@ -767,16 +779,13 @@ * `show`:是否显示刻度标签。 * `interval`:坐标轴刻度标签的显示间隔,在类目轴中有效。`0`表示显示所有标签,`1`表示隔一个隔显示一个标签,以此类推。 * `inside`:刻度标签是否朝内,默认朝外。 -* `rotate`:刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。 * `margin`:刻度标签与轴线之间的距离。 -* `color`:刻度标签文字的颜色,默认取主题`Theme`的`axisTextColor`。 -* `fontSize`:文字的字体大小。 -* `fontStyle`:文字字体的风格。 * `formatter`:图例内容字符串模版格式器。支持用 `\n` 换行。模板变量为图例名称 `{value}`,数值格式化通过`numericFormatter`。 * `numericFormatter`:标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式:`A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99`。 * `showAsPositiveNumber`:将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。 * `onZero`:刻度标签显示在`0`刻度上。 * `textLimit`:文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。 +* `textStyle`:文本样式 [TextStyle](#TextStyle)。 ## `AxisLine` @@ -797,11 +806,7 @@ * `Start`:坐标轴起始处。 * `Middle`:坐标轴中间。 * `End`:坐标轴末端。 -* `offset`:坐标轴名称与轴线之间的偏移。 -* `rotate`:坐标轴名字旋转,角度值。 -* `color`:坐标轴名称的文字颜色。 -* `fontSize`:坐标轴名称的文字大小。 -* `fontStyle`:坐标轴名称的文字风格。 +* `textStyle`:显示内容文本样式 [TextStyle](#TextStyle)。 ## `AxisSplitLine` @@ -919,15 +924,10 @@ * `numericFormatter`:标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式:`A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99`。 * `offset`:距离图形元素的偏移。 * `autoOffset`:是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。 -* `color`:自定义文字颜色,默认和系列的颜色一致。 -* `backgroundColor`:标签的背景色,默认无颜色。 * `backgroundWidth`:标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。 * `backgroundHeight`:标签的背景高度。一般不用指定,不指定时则自动是文字的高度。 -* `rotate`:标签的旋转。 * `paddingLeftRight`:标签文字和边框的左右边距。 * `paddingTopBottom`:标签文字和边框的上下边距。 -* `fontSize`:标签文字的字体大小。 -* `fontStyle`:标签文字的字体风格。 * `line`:是否显示视觉引导线。在 `label` 位置 设置为 `'Outside'` 的时候会显示视觉引导线。 * `lineType`:视觉引导线类型。支持以下几种类型: * `BrokenLine`:折线。 @@ -940,6 +940,7 @@ * `border`:是否显示边框。 * `borderWidth`:边框宽度。 * `borderColor`:边框颜色。 +* `textStyle`:显示内容文本样式 [TextStyle](#TextStyle)。 ## `SerieSymbol` diff --git a/Documentation/xcharts-api-EN.md b/Documentation/xcharts-api-EN.md index a0f39b1c..8e4658e6 100644 --- a/Documentation/xcharts-api-EN.md +++ b/Documentation/xcharts-api-EN.md @@ -6,7 +6,7 @@ ## `BaseChart` -* `BaseChart.themeInfo`:主题组件`ThemeInfo`。 +* `BaseChart.theme`:主题组件`ThemeInfo`。 * `BaseChart.title`:标题组件`Title`。 * `BaseChart.legend`:图例组件`Legend`。 * `BaseChart.tooltip`:提示框组件`Tooltip`。 @@ -67,17 +67,13 @@ ## `CoordinateChart` * `CoordinateChart.grid`:网格组件 `Grid`。 -* `CoordinateChart.xAxises`:左右两个 `X` 轴组件 `XAxis`。 -* `CoordinateChart.yAxises`:左右两个 `Y` 轴组件 `YAxis`。 +* `CoordinateChart.xAxes`:左右两个 `X` 轴组件 `XAxis`。 +* `CoordinateChart.yAxes`:左右两个 `Y` 轴组件 `YAxis`。 * `CoordianteChart.xAxis0`:X轴(下)。 * `CoordianteChart.xAxis1`:X轴(上)。 * `CoordianteChart.xAxis0`:Y轴(左)。 * `CoordianteChart.yAxis1`:Y轴(右)。 * `CoordinateChart.dataZoom`:区域缩放组件 `DataZoom`。 -* `CoordinateChart.coordinateX`:坐标系的左下角坐标 `X`。 -* `CoordinateChart.coordinateY`:坐标系的左下角坐标 `Y`。 -* `CoordinateChart.coordinateWidth`:坐标系的宽。 -* `CoordinateChart.coordinateHeight`:坐标系的高。 * `CoordinateChart.ClearAxisData()`:清除所有x轴和y轴的类目数据。 * `CoordinateChart.AddXAxisData(string category, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。 * `CoordinateChart.AddYAxisData(string category, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。 @@ -88,7 +84,7 @@ * `CoordinateChart.IsInCooridate(Vector3 local)`:坐标是否在坐标轴内。 * `CoordinateChart.IsInCooridate(float x, float y)`:坐标是否在坐标轴内。 * `CoordinateChart.IsInCooridate(Vector2 local)`:坐标是否在坐标轴内。 -* `CoordinateChart.ClampInCoordinate(Vector3 pos)`:将坐标限制在坐标系内。 +* `CoordinateChart.ClampInGrid(grid, Vector3 pos)`:将坐标限制在坐标系内。 * `CoordinateChart.CovertXYAxis(int index)`:转换X轴和Y轴的配置。 * `CoordinateChart.UpdateCoordinate()`:更新坐标系原点和宽高。一般内部会自动更新,也可强制更新。 * `CoordinateChart.SetMaxCache(int maxCache)`:设置可缓存的最大数据量。当数据量超过该值时,会自动删除第一个值再加入最新值。 diff --git a/Documentation/xcharts-configuration-EN.md b/Documentation/xcharts-configuration-EN.md index 8f90b625..825f60f0 100644 --- a/Documentation/xcharts-configuration-EN.md +++ b/Documentation/xcharts-configuration-EN.md @@ -6,7 +6,7 @@ The translation work is still in progress. -Main component: +__Main component:__ * [Axis](#XAxis) * [Background](#Background) @@ -32,7 +32,7 @@ Main component: * [Vessel](#Vessel) * [VisualMap](#VisualMap) -Sub component: +__Sub component:__ * [AreaStyle](#AreaStyle) * [AxisLabel](#AxisLabel) @@ -128,7 +128,7 @@ Parameters: * `formatter`: Legend content string template formatter. Support for wrapping lines with `\n`. Template:`{name}`. * `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. If data is not specified, it will be auto collected from series. * `icons`: The list of cunstomize icons. -* `textStyle`: The text style of legend content [TextStyle](#TextStyle). +* `textStyle`: The style of text [TextStyle](#TextStyle). API: @@ -275,16 +275,19 @@ Currently only the control 'X' axis is supported. * `showDetail`: Whether to show detail, that is, show the detailed data information when dragging. [default: `false`] * `zoomLock`: Specify whether to lock the size of window (selected area). [default: `false`] * ~~`realtime`: Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief. [default: `true`]~~ -* ~~`backgroundColor`: The background color of the component.~~ -* `bottom`: Distance between dataZoom component and the bottom side of the container. bottom value is a instant pixel value like 10. [default: `10f`] +* `backgroundColor`: The background color of the component. +* `selectedAreaColor`: The color of the selected area. +* `bottom`: Distance between dataZoom component and the bottom side of the container. [default: `10f`] +* `top`: Distance between dataZoom component and the top side of the container. [default: `0`] +* `left`: Distance between dataZoom component and the left side of the container. [default: `0`] +* `right`: Distance between dataZoom component and the right side of the container. [default: `0`] * `height`: The height of dataZoom component. height value is a instant pixel value like 10. [default: `50f`] * `rangeMode`: Use absolute value or percent value in `DataZoom.start` and `DataZoom.end`. [default: `RangeMode.Percent`]. * `Percent`: percent. * `start`: The start percentage of the window out of the data extent, in the range of `0 ~ 100`. [default: `30f`] * `end`: The end percentage of the window out of the data extent, in the range of 0 ~ 100. [default: `70f`] * `scrollSensitivity`: The sensitivity of dataZoom scroll. The larger the number, the more sensitive it is. [default: `10f`] -* `fontSize`: font size of datazoom label. -* `fontStyle`: font style of datazoom label. +* `textStyle`: style of datazoom label. * `minShowNum`: Minimum number of display data. Minimum number of data displayed when DataZoom is enlarged to maximum. [default: `1`] ## `VisualMap` @@ -352,11 +355,18 @@ GaugePointer sub component. Settings related to gauge pointer. The x axis in cartesian(rectangular) coordinate. a grid component can place at most 2 x axis, one on the bottom and another on the top. -* `show`: Whether to show axis. By default `xAxises[0]` is `true` and `xAxises[1]` is `false`. +* `show`: Whether to show axis. By default `xAxes[0]` is `true` and `xAxes[1]` is `false`. +* `gridIndex`: The index of the grid on which the axis are located, by default, is in the first grid. * `type`: the type of axis. The default is `Category`. * `Value`: Numerical axis for continuous data. * `Category`: Category axis, applicable to discrete category data, category data must be set through `data` for this type. * `Log`: Log axis, it applies to logarithmic data. +* `position`: the position of axis in grid. + * `Left`: left of grid. + * `Right`: right of grid. + * `Bottom`: bottom of grid. + * `Top`: top of grid. +* `offset`: the offset of axis from the default position. Useful when the same position has multiple axes. * `logBaseE`: On the log axis, if base e is the natural number, and is true, logBase fails. * `logBase`: Base of logarithm, which is valid only for numeric axes with type: `Log`. * `minMaxType`: the type of axis minmax.The default is `Default`. @@ -411,7 +421,8 @@ Line chart serie. * `type`: `Line`. * `name`: Series name used for displaying in tooltip and filtering with legend. * `stack`: If stack the value. On the same category axis, the series with the same stack name would be put on top of each other. -* `axisIndex`: Index of axis to combine with, which is useful for multiple x axes in one chart. +* `xAxisIndex`: Index of x axis to combine with, which is useful for multiple axes in one chart. +* `yAxisIndex`: Index of y axis to combine with, which is useful for multiple axes in one chart. * `minShow`: The min number of data to show in chart. * `maxShow`: The max number of data to show in chart. * `maxCache`: The max number of serie data cache. The first data will be remove when the size of serie data is larger then maxCache. @@ -431,7 +442,7 @@ Line chart serie. * `largeThreshold`: 开启大数量优化的阈值。只有当开启了large并且数据量大于该阀值时才进入性能模式。 * `areaStyle`: 区域填充样式 [AreaStyle](#AreaStyle)。 * `symbol`: 标记的图形 [SerieSymbol](#SerieSymbol)。 -* `lineType`: 折线图样式类型。支持以下十种类型: +* `lineType`: 折线图样式类型。支持以下十种类型: * `Normal`: 普通折线图。 * `Smooth`: 平滑曲线。 * `SmoothDash`: 平滑虚线。 @@ -457,7 +468,8 @@ Line chart serie. * `type`: `Bar`。 * `name`: 系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。 * `stack`: 数据堆叠。同个类目轴上系列配置相同的 `stack` 值后,后一个系列的值会在前一个系列的值上相加。 -* `axisIndex`: 使用的坐标轴轴的 `index`,在单个图表实例中存在多个坐标轴轴的时候有用。 +* `xAxisIndex`: Index of x axis to combine with, which is useful for multiple axes in one chart. +* `yAxisIndex`: Index of y axis to combine with, which is useful for multiple axes in one chart. * `minShow`: 系列显示数据的最小索引。 * `maxShow`: 系列显示数据的最大索引。 * `maxCache`: 系列中可缓存的最大数据量。默认为`0`没有限制,大于0时超过指定值会移除旧数据再插入新数据。 @@ -492,7 +504,7 @@ Line chart serie. * `show`: 系列是否显示在图表上。 * `type`: `Pie`。 * `name`: 系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。 -* `pieRoseType`: 南丁格尔玫瑰图类型,支持以下类型: +* `pieRoseType`: 南丁格尔玫瑰图类型,支持以下类型: * `None`: 不展示成南丁格尔玫瑰图。 * `Radius`: 扇区圆心角展现数据的百分比,半径展现数据的大小。 * `Area`: 所有扇区圆心角相同,仅通过半径展现数据大小。 @@ -562,7 +574,7 @@ Line chart serie. * `show`: 系列是否显示在图表上。 * `type`: `Gauge`。 * `name`: 系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。 -* `gaugeType`: 仪表盘类型,支持以下类型: +* `gaugeType`: 仪表盘类型,支持以下类型: * `Pointer`: 指针类型。 * `ProgressBar`: 进度条类型。 * `center`: 中心点坐标。当值为0-1的浮点数时表示百分比。 @@ -644,7 +656,7 @@ Line chart serie. ## `AreaStyle` * `show`: 是否显示区域填充。 -* `origin`: 区域填充的起始位置 `AreaOrigin`。有以下三种填充方式: +* `origin`: 区域填充的起始位置 `AreaOrigin`。有以下三种填充方式: * `Auto`: 填充坐标轴轴线到数据间的区域。 * `Start`: 填充坐标轴底部到数据间的区域。 * `End`: 填充坐标轴顶部到数据间的区域。 @@ -660,16 +672,13 @@ Line chart serie. * `show`: 是否显示刻度标签。 * `interval`: 坐标轴刻度标签的显示间隔,在类目轴中有效。`0`表示显示所有标签,`1`表示隔一个隔显示一个标签,以此类推。 * `inside`: 刻度标签是否朝内,默认朝外。 -* `rotate`: 刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。 * `margin`: 刻度标签与轴线之间的距离。 -* `color`: 刻度标签文字的颜色,默认取主题`Theme`的`axisTextColor`。 -* `fontSize`: 文字的字体大小。 -* `fontStyle`: 文字字体的风格。 * `formatter`: 图例内容字符串模版格式器。支持用 `\n` 换行。模板变量为图例名称 `{value}`,数值格式化通过`numericFormatter`。 * `numericFormatter`: 标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式: `A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99`。 * `showAsPositiveNumber`: 将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。 * `onZero`: 刻度标签显示在`0`刻度上。 * `textLimit`: 文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。 +* `textStyle`: The style of text [TextStyle](#TextStyle). ## `AxisLine` @@ -686,15 +695,11 @@ Line chart serie. * `show`: 是否显示坐标名称。 * `name`: 坐标轴名称。 -* `location`: 坐标轴名称的位置。支持以下类型: +* `location`: 坐标轴名称的位置。支持以下类型: * `Start`: 坐标轴起始处。 * `Middle`: 坐标轴中间。 * `End`: 坐标轴末端。 -* `offset`: 坐标轴名称与轴线之间的偏移。 -* `rotate`: 坐标轴名字旋转,角度值。 -* `color`: 坐标轴名称的文字颜色。 -* `fontSize`: 坐标轴名称的文字大小。 -* `fontStyle`: 坐标轴名称的文字风格。 +* `textStyle`: The style of text [TextStyle](#TextStyle). ## `AxisSplitLine` @@ -742,7 +747,7 @@ Line chart serie. ## `LineArrow` * `show`: 是否显示箭头。 -* `position`: 箭头显示位置。支持以下两种位置: +* `position`: 箭头显示位置。支持以下两种位置: * `End`: 末端显示。最后一个数据上显示箭头。 * `Start`: 起始端显示。第一个数据上显示箭头。 * `width`: 箭头宽。 @@ -802,7 +807,7 @@ Line chart serie. ## `SerieLabel` * `show`: 是否显示文本标签。 -* `position`: 标签的位置。折线图时强制默认为 `Center`,支持以下 `5` 种位置: +* `position`: 标签的位置。折线图时强制默认为 `Center`,支持以下 `5` 种位置: * `Outside`: 饼图扇区外侧,通过视觉引导线连到相应的扇区。只在饼图种可用。 * `Inside`: 饼图扇区内部。只在饼图可用。 * `Center`: 在中心位置(折线图,柱状图,饼图)。 @@ -812,17 +817,12 @@ Line chart serie. * `numericFormatter`: 标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式: `A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99`。 * `offset`: 距离图形元素的偏移。 * `autoOffset`: 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。 -* `color`: 自定义文字颜色,默认和系列的颜色一致。 -* `backgroundColor`: 标签的背景色,默认无颜色。 * `backgroundWidth`: 标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。 * `backgroundHeight`: 标签的背景高度。一般不用指定,不指定时则自动是文字的高度。 -* `rotate`: 标签的旋转。 * `paddingLeftRight`: 标签文字和边框的左右边距。 * `paddingTopBottom`: 标签文字和边框的上下边距。 -* `fontSize`: 标签文字的字体大小。 -* `fontStyle`: 标签文字的字体风格。 * `line`: 是否显示视觉引导线。在 `label` 位置 设置为 `'Outside'` 的时候会显示视觉引导线。 -* `lineType`: 视觉引导线类型。支持以下几种类型: +* `lineType`: 视觉引导线类型。支持以下几种类型: * `BrokenLine`: 折线。 * `Curves`: 曲线。 * `HorizontalLine`: 水平线。 @@ -833,6 +833,7 @@ Line chart serie. * `border`: 是否显示边框。 * `borderWidth`: 边框宽度。 * `borderColor`: 边框颜色。 +* `textStyle`: The style of text [TextStyle](#TextStyle). ## `SerieSymbol` diff --git a/Editor/BarChartEditor.cs b/Editor/BarChartEditor.cs index 354ab270..96435653 100644 --- a/Editor/BarChartEditor.cs +++ b/Editor/BarChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -19,13 +19,13 @@ namespace XCharts protected override void OnEnable() { base.OnEnable(); - m_Target = (BarChart)target; + m_Chart = (BarChart)target; } protected override void OnEndInspectorGUI() { base.OnEndInspectorGUI(); - if (m_Target == null && target == null) + if (m_Chart == null && target == null) { return; } diff --git a/Editor/BaseChartEditor.cs b/Editor/BaseChartEditor.cs index 5e9c1bbb..6da03eb9 100644 --- a/Editor/BaseChartEditor.cs +++ b/Editor/BaseChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -14,22 +14,24 @@ namespace XCharts /// /// Editor class used to edit UI BaseChart. /// - [CustomEditor(typeof(BaseChart), false)] public class BaseChartEditor : Editor { - protected BaseChart m_Target; + protected BaseChart m_Chart; protected SerializedProperty m_Script; + protected SerializedProperty m_MultiComponentMode; + protected SerializedProperty m_EnableTextMeshPro; protected SerializedProperty m_ChartWidth; protected SerializedProperty m_ChartHeight; - protected SerializedProperty m_Theme; - protected SerializedProperty m_ThemeInfo; - protected SerializedProperty m_Background; - protected SerializedProperty m_Title; - protected SerializedProperty m_Legend; - protected SerializedProperty m_Tooltip; - protected SerializedProperty m_Series; protected SerializedProperty m_Settings; + protected SerializedProperty m_Theme; + protected SerializedProperty m_Background; + protected SerializedProperty m_Titles; + protected SerializedProperty m_Legends; + protected SerializedProperty m_Tooltips; + protected SerializedProperty m_Vessels; + protected SerializedProperty m_Radars; + protected SerializedProperty m_Series; protected SerializedProperty m_Large; protected SerializedProperty m_ChartName; protected SerializedProperty m_DebugMode; @@ -41,29 +43,36 @@ namespace XCharts private bool m_CheckWarning = false; private StringBuilder sb = new StringBuilder(); + private bool m_BaseFoldout; + protected bool m_ShowAllComponent; + protected virtual void OnEnable() { - m_Target = (BaseChart)target; + if (target == null) return; + m_Chart = (BaseChart)target; m_Script = serializedObject.FindProperty("m_Script"); + m_MultiComponentMode = serializedObject.FindProperty("m_MultiComponentMode"); + m_EnableTextMeshPro = serializedObject.FindProperty("m_EnableTextMeshPro"); m_ChartName = serializedObject.FindProperty("m_ChartName"); m_ChartWidth = serializedObject.FindProperty("m_ChartWidth"); m_ChartHeight = serializedObject.FindProperty("m_ChartHeight"); m_Theme = serializedObject.FindProperty("m_Theme"); - m_ThemeInfo = serializedObject.FindProperty("m_ThemeInfo"); + m_Settings = serializedObject.FindProperty("m_Settings"); m_Background = serializedObject.FindProperty("m_Background"); - m_Title = serializedObject.FindProperty("m_Title"); - m_Legend = serializedObject.FindProperty("m_Legend"); - m_Tooltip = serializedObject.FindProperty("m_Tooltip"); + m_Titles = serializedObject.FindProperty("m_Titles"); + m_Legends = serializedObject.FindProperty("m_Legends"); + m_Tooltips = serializedObject.FindProperty("m_Tooltips"); + m_Vessels = serializedObject.FindProperty("m_Vessels"); m_Series = serializedObject.FindProperty("m_Series"); + m_Radars = serializedObject.FindProperty("m_Radars"); m_Large = serializedObject.FindProperty("m_Large"); - m_Settings = serializedObject.FindProperty("m_Settings"); m_DebugMode = serializedObject.FindProperty("m_DebugMode"); } public override void OnInspectorGUI() { - if (m_Target == null && target == null) + if (m_Chart == null && target == null) { base.OnInspectorGUI(); return; @@ -75,50 +84,120 @@ namespace XCharts OnStartInspectorGUI(); OnMiddleInspectorGUI(); OnEndInspectorGUI(); + OnDebugInspectorGUI(); - CheckWarning(); + EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); } protected virtual void OnStartInspectorGUI() { - EditorGUILayout.PropertyField(m_Script); - - EditorGUILayout.PropertyField(m_ChartName); - EditorGUILayout.PropertyField(m_ThemeInfo, true); - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(m_Background, true); - - var m_Show = m_Background.FindPropertyRelative("m_Show"); - if (m_Show.boolValue && !m_Target.CanShowBackgroundComponent()) + BlockStart(); + EditorGUILayout.BeginHorizontal(); + var version = string.Format("V{0}_{1}", XChartsMgr.version, XChartsMgr.versionDate); + if (m_EnableTextMeshPro.boolValue) { - var msg = "The background component cannot be activated because chart is controlled by LayoutGroup," - + " or its parent have more than one child."; - EditorGUILayout.HelpBox(msg, MessageType.Error); + version += " TMP"; } - EditorGUILayout.PropertyField(m_Title, true); - EditorGUILayout.PropertyField(m_Legend, true); - EditorGUILayout.PropertyField(m_Tooltip, true); + EditorGUILayout.LabelField(version); + + if (GUILayout.Button("Github")) + { + Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts"); + } + EditorGUILayout.EndHorizontal(); + BlockEnd(); + + BlockStart(); + m_BaseFoldout = EditorGUILayout.Foldout(m_BaseFoldout, "Base"); + if (m_BaseFoldout) + { + EditorGUILayout.PropertyField(m_Script); + EditorGUILayout.PropertyField(m_ChartName); + } + BlockEnd(); + + BlockField(m_Theme); + BlockField(m_Settings); + BlockField(m_Background); + + m_ShowAllComponent = m_MultiComponentMode.boolValue; + BlockListField(m_ShowAllComponent, m_Titles); + BlockListField(m_ShowAllComponent, m_Legends); + BlockListField(m_ShowAllComponent, m_Tooltips); + BlockListField(m_ShowAllComponent, SerieType.Liquid, m_Vessels); + BlockListField(m_ShowAllComponent, SerieType.Radar, m_Radars); } protected virtual void OnMiddleInspectorGUI() { - EditorGUILayout.PropertyField(m_Series, true); - EditorGUILayout.PropertyField(m_Settings, true); + BlockField(m_Series); } protected virtual void OnEndInspectorGUI() + { + } + + protected virtual void OnDebugInspectorGUI() { EditorGUILayout.Space(); EditorGUILayout.Space(); + BlockStart(); EditorGUILayout.PropertyField(m_DebugMode); + EditorGUILayout.PropertyField(m_MultiComponentMode); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + MoreDebugInspector(); + CheckWarning(); + BlockEnd(); + } + + protected virtual void MoreDebugInspector() + { + } + + protected void BlockStart() + { + if (XChartsSettings.editorBlockEnable) EditorGUILayout.BeginVertical(EditorStyles.helpBox); + } + + protected void BlockEnd() + { + if (XChartsSettings.editorBlockEnable) EditorGUILayout.EndVertical(); + } + + protected void BlockField(params SerializedProperty[] props) + { + if (props.Length == 0) return; + BlockStart(); + foreach (var prop in props) + EditorGUILayout.PropertyField(prop, true); + BlockEnd(); + } + + protected void BlockListField(bool all, params SerializedProperty[] props) + { + if (props.Length == 0) return; + BlockStart(); + foreach (var prop in props) + { + if (all) EditorGUILayout.PropertyField(prop, true); + else if (prop.arraySize > 0) EditorGUILayout.PropertyField(prop.GetArrayElementAtIndex(0), true); + } + BlockEnd(); + } + + protected void BlockListField(bool all, SerieType serieType, params SerializedProperty[] props) + { + if (!m_Chart.ContainsSerie(serieType)) return; + BlockListField(all, props); } private void CheckWarning() { if (GUILayout.Button("Remove All Chart Object")) { - m_Target.RemoveChartObject(); + m_Chart.RemoveChartObject(); } if (GUILayout.Button("Check XCharts Update ")) { @@ -130,7 +209,7 @@ namespace XCharts if (GUILayout.Button("Check Warning")) { m_CheckWarning = true; - m_Target.CheckWarning(); + m_Chart.CheckWarning(); } if (GUILayout.Button("Hide Warning")) { @@ -138,11 +217,11 @@ namespace XCharts } EditorGUILayout.EndHorizontal(); sb.Length = 0; - sb.AppendFormat("version:{0}", XChartsMgr.Instance.nowVersion); - if (!string.IsNullOrEmpty(m_Target.warningInfo)) + sb.AppendFormat("v{0}", XChartsMgr.fullVersion); + if (!string.IsNullOrEmpty(m_Chart.warningInfo)) { sb.AppendLine(); - sb.Append(m_Target.warningInfo); + sb.Append(m_Chart.warningInfo); } else { @@ -156,11 +235,10 @@ namespace XCharts if (GUILayout.Button("Check warning")) { m_CheckWarning = true; - m_Target.CheckWarning(); + m_Chart.CheckWarning(); } } EditorGUILayout.Space(); - EditorGUILayout.Space(); } } } \ No newline at end of file diff --git a/Editor/CoordinateChartEditor.cs b/Editor/CoordinateChartEditor.cs index 257d9d2b..437b5f2e 100644 --- a/Editor/CoordinateChartEditor.cs +++ b/Editor/CoordinateChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -13,56 +13,41 @@ namespace XCharts /// /// Editor class used to edit UI CoordinateChart. /// - [CustomEditor(typeof(CoordinateChart), false)] public class CoordinateChartEditor : BaseChartEditor { - protected SerializedProperty m_Grid; + protected SerializedProperty m_Grids; protected SerializedProperty m_MultipleXAxis; - protected SerializedProperty m_XAxises; + protected SerializedProperty m_XAxes; protected SerializedProperty m_MultipleYAxis; - protected SerializedProperty m_YAxises; - protected SerializedProperty m_DataZoom; - protected SerializedProperty m_VisualMap; + protected SerializedProperty m_YAxes; + protected SerializedProperty m_DataZooms; + protected SerializedProperty m_VisualMaps; protected override void OnEnable() { base.OnEnable(); - m_Target = (CoordinateChart)target; - m_Grid = serializedObject.FindProperty("m_Grid"); - m_XAxises = serializedObject.FindProperty("m_XAxises"); - m_YAxises = serializedObject.FindProperty("m_YAxises"); - m_DataZoom = serializedObject.FindProperty("m_DataZoom"); - m_VisualMap = serializedObject.FindProperty("m_VisualMap"); + m_Chart = (CoordinateChart)target; + m_Grids = serializedObject.FindProperty("m_Grids"); + m_XAxes = serializedObject.FindProperty("m_XAxes"); + m_YAxes = serializedObject.FindProperty("m_YAxes"); + m_DataZooms = serializedObject.FindProperty("m_DataZooms"); + m_VisualMaps = serializedObject.FindProperty("m_VisualMaps"); } protected override void OnStartInspectorGUI() { base.OnStartInspectorGUI(); - if (m_Target is LineChart || m_Target is BarChart) - { - EditorGUILayout.PropertyField(m_DataZoom); - } - if (m_Target is HeatmapChart || m_Target is LineChart) - { - EditorGUILayout.PropertyField(m_VisualMap); - } - EditorGUILayout.PropertyField(m_Grid); - for (int i = 0; i < m_XAxises.arraySize; i++) - { - SerializedProperty axis = m_XAxises.GetArrayElementAtIndex(i); - EditorGUILayout.PropertyField(axis); - } - for (int i = 0; i < m_YAxises.arraySize; i++) - { - SerializedProperty axis = m_YAxises.GetArrayElementAtIndex(i); - EditorGUILayout.PropertyField(axis); - } + BlockListField(m_ShowAllComponent, m_DataZooms); + BlockListField(m_ShowAllComponent, m_VisualMaps); + BlockListField(m_ShowAllComponent, m_Grids); + BlockListField(m_ShowAllComponent, m_XAxes); + BlockListField(m_ShowAllComponent, m_YAxes); } - protected override void OnEndInspectorGUI() + protected override void MoreDebugInspector() { - base.OnEndInspectorGUI(); + base.MoreDebugInspector(); CovertXYAxis(); } @@ -70,7 +55,7 @@ namespace XCharts { if (GUILayout.Button("Covert XY Axis")) { - (m_Target as CoordinateChart).CovertXYAxis(0); + (m_Chart as CoordinateChart).CovertXYAxis(0); } } } diff --git a/Editor/GaugeChartEditor.cs b/Editor/GaugeChartEditor.cs index a53cbd7f..a89de203 100644 --- a/Editor/GaugeChartEditor.cs +++ b/Editor/GaugeChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -12,22 +12,13 @@ namespace XCharts /// /// Editor class used to edit UI GaugeChart. /// - [CustomEditor(typeof(GaugeChart), false)] public class GaugeChartEditor : BaseChartEditor { - protected SerializedProperty m_Radar; - protected SerializedProperty m_Radars; - protected override void OnEnable() { base.OnEnable(); - m_Target = (GaugeChart)target; - } - - protected override void OnEndInspectorGUI() - { - base.OnEndInspectorGUI(); + m_Chart = (GaugeChart)target; } } } \ No newline at end of file diff --git a/Editor/HeatmapChartEditor.cs b/Editor/HeatmapChartEditor.cs index f71b1314..b1e81067 100644 --- a/Editor/HeatmapChartEditor.cs +++ b/Editor/HeatmapChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -12,19 +12,13 @@ namespace XCharts /// /// Editor class used to edit UI HeatmapChart. /// - [CustomEditor(typeof(HeatmapChart), false)] public class HeatmapChartEditor : CoordinateChartEditor { protected override void OnEnable() { base.OnEnable(); - m_Target = (HeatmapChart)target; - } - - protected override void OnEndInspectorGUI() - { - base.OnEndInspectorGUI(); + m_Chart = (HeatmapChart)target; } } } \ No newline at end of file diff --git a/Editor/LineChartEditor.cs b/Editor/LineChartEditor.cs index 80433772..d321bb74 100644 --- a/Editor/LineChartEditor.cs +++ b/Editor/LineChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -12,14 +12,13 @@ namespace XCharts /// /// Editor class used to edit UI LineChart. /// - [CustomEditor(typeof(LineChart), false)] public class LineChartEditor : CoordinateChartEditor { protected override void OnEnable() { base.OnEnable(); - m_Target = (LineChart)target; + m_Chart = (LineChart)target; } } } \ No newline at end of file diff --git a/Editor/LiquidChartEditor.cs b/Editor/LiquidChartEditor.cs index 874436da..cf985df9 100644 --- a/Editor/LiquidChartEditor.cs +++ b/Editor/LiquidChartEditor.cs @@ -16,19 +16,5 @@ namespace XCharts [CustomEditor(typeof(LiquidChart), false)] public class LiquidChartEditor : BaseChartEditor { - protected SerializedProperty m_Vessels; - - protected override void OnEnable() - { - base.OnEnable(); - m_Target = (LiquidChart)target; - m_Vessels = serializedObject.FindProperty("m_Vessels"); - } - - protected override void OnStartInspectorGUI() - { - base.OnStartInspectorGUI(); - EditorGUILayout.PropertyField(m_Vessels, true); - } } } \ No newline at end of file diff --git a/Editor/PieChartEditor.cs b/Editor/PieChartEditor.cs index 897991cd..d410a4b7 100644 --- a/Editor/PieChartEditor.cs +++ b/Editor/PieChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -12,21 +12,13 @@ namespace XCharts /// /// Editor class used to edit UI PieChart. /// - [CustomEditor(typeof(PieChart), false)] public class PieChartEditor : BaseChartEditor { - protected SerializedProperty m_Pie; - protected override void OnEnable() { base.OnEnable(); - m_Target = (PieChart)target; - } - - protected override void OnEndInspectorGUI() - { - base.OnEndInspectorGUI(); + m_Chart = (PieChart)target; } } } \ No newline at end of file diff --git a/Editor/PolarChartEditor.cs b/Editor/PolarChartEditor.cs index 3c8e4d00..57b3b476 100644 --- a/Editor/PolarChartEditor.cs +++ b/Editor/PolarChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -12,29 +12,29 @@ namespace XCharts /// /// Editor class used to edit UI PolarChart. /// - [CustomEditor(typeof(PolarChart), false)] public class PolarChartEditor : BaseChartEditor { - protected SerializedProperty m_Polar; - protected SerializedProperty m_RadiusAxis; - protected SerializedProperty m_AngleAxis; + protected SerializedProperty m_Polars; + protected SerializedProperty m_RadiusAxes; + protected SerializedProperty m_AngleAxes; protected override void OnEnable() { base.OnEnable(); - m_Target = (PolarChart)target; - m_Polar = serializedObject.FindProperty("m_Polar"); - m_RadiusAxis = serializedObject.FindProperty("m_RadiusAxis"); - m_AngleAxis = serializedObject.FindProperty("m_AngleAxis"); + m_Chart = (PolarChart)target; + m_Polars = serializedObject.FindProperty("m_Polars"); + m_RadiusAxes = serializedObject.FindProperty("m_RadiusAxes"); + m_AngleAxes = serializedObject.FindProperty("m_AngleAxes"); } protected override void OnStartInspectorGUI() { base.OnStartInspectorGUI(); - EditorGUILayout.PropertyField(m_Polar, true); - EditorGUILayout.PropertyField(m_RadiusAxis, true); - EditorGUILayout.PropertyField(m_AngleAxis, true); + var showAll = m_MultiComponentMode.boolValue; + BlockListField(showAll, m_Polars); + BlockListField(showAll, m_RadiusAxes); + BlockListField(showAll, m_AngleAxes); } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/AngleAxisDrawer.cs b/Editor/PropertyDrawers/AngleAxisDrawer.cs deleted file mode 100644 index 233ddfc6..00000000 --- a/Editor/PropertyDrawers/AngleAxisDrawer.cs +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(AngleAxis), true)] - public class AngleAxisDrawer : AxisDrawer - { - protected override void DrawExtended(ref Rect drawRect, SerializedProperty prop) - { - SerializedProperty m_StartAngle = prop.FindPropertyRelative("m_StartAngle"); - SerializedProperty m_Clockwise = prop.FindPropertyRelative("m_Clockwise"); - EditorGUI.PropertyField(drawRect, m_StartAngle); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Clockwise); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - - protected override string GetDisplayName(string displayName) - { - if (displayName.StartsWith("Element")) - { - displayName = displayName.Replace("Element", "Angle Axis"); - } - return displayName; - } - - protected override float GetExtendedHeight() - { - return 2 * EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AnimationDrawer.cs b/Editor/PropertyDrawers/AnimationDrawer.cs index e8b59979..234fd137 100644 --- a/Editor/PropertyDrawers/AnimationDrawer.cs +++ b/Editor/PropertyDrawers/AnimationDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,72 +12,24 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(SerieAnimation), true)] - public class AnimationDrawer : PropertyDrawer + public class AnimationDrawer : BasePropertyDrawer { - private Dictionary m_AnimationModuleToggle = new Dictionary(); - + public override string ClassName { get { return "Animation"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - - SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable"); - //SerializedProperty m_Easting = prop.FindPropertyRelative("m_Easting"); - SerializedProperty m_FadeInDuration = prop.FindPropertyRelative("m_FadeInDuration"); - SerializedProperty m_FadeOutDuration = prop.FindPropertyRelative("m_FadeOutDuration"); - SerializedProperty m_DataChangeEnable = prop.FindPropertyRelative("m_DataChangeEnable"); - SerializedProperty m_DataChangeDuration = prop.FindPropertyRelative("m_DataChangeDuration"); - SerializedProperty m_FadeInDelay = prop.FindPropertyRelative("m_FadeInDelay"); - //SerializedProperty m_Threshold = prop.FindPropertyRelative("m_Threshold"); - SerializedProperty m_ActualDuration = prop.FindPropertyRelative("m_ActualDuration"); - SerializedProperty m_FadeOutDelay = prop.FindPropertyRelative("m_FadeOutDelay"); - // SerializedProperty m_CurrDetailProgress = prop.FindPropertyRelative("m_CurrDetailProgress"); - // SerializedProperty m_DestDetailProgress = prop.FindPropertyRelative("m_DestDetailProgress"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AnimationModuleToggle, prop, null, m_Enable, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_AnimationModuleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Enable")) { ++EditorGUI.indentLevel; - //EditorGUI.PropertyField(drawRect, m_Easting); - //drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, m_Threshold); - // if (m_Threshold.intValue < 0) m_Threshold.intValue = 0; - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FadeInDelay); - if (m_FadeInDelay.floatValue < 0) m_FadeInDelay.floatValue = 0; - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FadeInDuration); - if (m_FadeInDuration.floatValue < 0) m_FadeInDuration.floatValue = 0; - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FadeOutDelay); - if (m_FadeOutDelay.floatValue < 0) m_FadeOutDelay.floatValue = 0; - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FadeOutDuration); - if (m_FadeOutDuration.floatValue < 0) m_FadeOutDuration.floatValue = 0; - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_DataChangeEnable); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_DataChangeDuration); - if (m_DataChangeDuration.floatValue < 0) m_DataChangeDuration.floatValue = 0; - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - // EditorGUI.LabelField(drawRect, "CurrDetailProgress:" + m_CurrDetailProgress.floatValue); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.LabelField(drawRect, "DestDetailProgress:" + m_DestDetailProgress.floatValue); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.LabelField(drawRect, "Actual duration:" + m_ActualDuration.floatValue + " ms"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_FadeInDuration"); + PropertyField(prop, "m_FadeInDelay"); + PropertyField(prop, "m_FadeOutDuration"); + PropertyField(prop, "m_FadeOutDelay"); + PropertyField(prop, "m_DataChangeEnable"); + PropertyField(prop, "m_DataChangeDuration"); + PropertyField(prop, "m_ActualDuration"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_AnimationModuleToggle, prop)) - return 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing; - else - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/AreaStyleDrawer.cs b/Editor/PropertyDrawers/AreaStyleDrawer.cs index 30863eea..d31e6509 100644 --- a/Editor/PropertyDrawers/AreaStyleDrawer.cs +++ b/Editor/PropertyDrawers/AreaStyleDrawer.cs @@ -1,69 +1,34 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(AreaStyle), true)] - public class AreaStyleDrawer : PropertyDrawer + public class AreaStyleDrawer : BasePropertyDrawer { - private Dictionary m_AreaStyleToggle = new Dictionary(); - + public override string ClassName { get { return "AreaStyle"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Origin = prop.FindPropertyRelative("m_Origin"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_ToColor = prop.FindPropertyRelative("m_ToColor"); - SerializedProperty m_HighlightColor = prop.FindPropertyRelative("m_HighlightColor"); - SerializedProperty m_HighlightToColor = prop.FindPropertyRelative("m_HighlightToColor"); - SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity"); - SerializedProperty m_TooltipHighlight = prop.FindPropertyRelative("m_TooltipHighlight"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AreaStyleToggle, prop, "Area Style", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_AreaStyleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Origin); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ToColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_HighlightColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_HighlightToColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Opacity); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_TooltipHighlight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Origin"); + PropertyField(prop, "m_Color"); + PropertyField(prop, "m_ToColor"); + PropertyField(prop, "m_HighlightColor"); + PropertyField(prop, "m_HighlightToColor"); + PropertyField(prop, "m_Opacity"); + PropertyField(prop, "m_TooltipHighlight"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_AreaStyleToggle, prop)) - { - height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing; - } - else - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisDrawer.cs b/Editor/PropertyDrawers/AxisDrawer.cs index 8107432c..be0437b5 100644 --- a/Editor/PropertyDrawers/AxisDrawer.cs +++ b/Editor/PropertyDrawers/AxisDrawer.cs @@ -1,84 +1,53 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Axis), true)] - public class AxisDrawer : PropertyDrawer + public class AxisDrawer : BasePropertyDrawer { - private List m_AxisModuleToggle = new List(); - private List m_DataFoldout = new List(); - private int m_DataSize = 0; - private bool m_ShowJsonDataArea = false; private string m_JsonDataAreaText; - - protected virtual string GetDisplayName(string displayName) - { - return displayName; - } + public override string ClassName { get { return "Axis"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - - SerializedProperty m_Show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Type = prop.FindPropertyRelative("m_Type"); - SerializedProperty m_LogBaseE = prop.FindPropertyRelative("m_LogBaseE"); - SerializedProperty m_LogBase = prop.FindPropertyRelative("m_LogBase"); - SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber"); - SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval"); - SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel"); - SerializedProperty m_BoundaryGap = prop.FindPropertyRelative("m_BoundaryGap"); - SerializedProperty m_Data = prop.FindPropertyRelative("m_Data"); - SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine"); - SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName"); - SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick"); - SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea"); - SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine"); - SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType"); - SerializedProperty m_Min = prop.FindPropertyRelative("m_Min"); - SerializedProperty m_Max = prop.FindPropertyRelative("m_Max"); - SerializedProperty m_CeilRate = prop.FindPropertyRelative("m_CeilRate"); - SerializedProperty m_Inverse = prop.FindPropertyRelative("m_Inverse"); - - int index = InitToggle(prop); - bool toggle = m_AxisModuleToggle[index]; - m_AxisModuleToggle[index] = ChartEditorHelper.MakeFoldout(ref drawRect, ref toggle, - GetDisplayName(prop.displayName), m_Show); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_AxisModuleToggle[index]) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { + SerializedProperty m_Type = prop.FindPropertyRelative("m_Type"); + SerializedProperty m_LogBase = prop.FindPropertyRelative("m_LogBase"); + SerializedProperty m_Data = prop.FindPropertyRelative("m_Data"); + SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType"); Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex; + var chart = prop.serializedObject.targetObject as BaseChart; + var isPolar = chart is PolarChart; EditorGUI.indentLevel++; - EditorGUI.PropertyField(drawRect, m_Type); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, isPolar ? "m_PolarIndex" : "m_GridIndex"); + PropertyField(prop, "m_Type"); + PropertyField(prop, "m_Position"); + PropertyField(prop, "m_Offset"); if (type == Axis.AxisType.Log) { - EditorGUI.PropertyField(drawRect, m_LogBaseE); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_LogBaseE"); EditorGUI.BeginChangeCheck(); - EditorGUI.PropertyField(drawRect, m_LogBase); + PropertyField(prop, "m_LogBase"); if (m_LogBase.floatValue <= 0 || m_LogBase.floatValue == 1) { m_LogBase.floatValue = 10; } EditorGUI.EndChangeCheck(); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } if (type == Axis.AxisType.Value) { - EditorGUI.PropertyField(drawRect, m_MinMaxType); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_MinMaxType"); Axis.AxisMinMaxType minMaxType = (Axis.AxisMinMaxType)m_MinMaxType.enumValueIndex; switch (minMaxType) { @@ -88,154 +57,136 @@ namespace XCharts break; case Axis.AxisMinMaxType.Custom: EditorGUI.indentLevel++; - EditorGUI.PropertyField(drawRect, m_Min); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Max); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Min"); + PropertyField(prop, "m_Max"); EditorGUI.indentLevel--; break; } - EditorGUI.PropertyField(drawRect, m_CeilRate); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Inverse); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_CeilRate"); + PropertyField(prop, "m_Inverse"); } - EditorGUI.PropertyField(drawRect, m_SplitNumber); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_SplitNumber"); if (type == Axis.AxisType.Category) { - EditorGUI.PropertyField(drawRect, m_BoundaryGap); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_BoundaryGap"); } else { - EditorGUI.PropertyField(drawRect, m_Interval); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Interval"); } - DrawExtended(ref drawRect, prop); - EditorGUI.PropertyField(drawRect, m_AxisLine); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLine); - EditorGUI.PropertyField(drawRect, m_AxisName); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.y += EditorGUI.GetPropertyHeight(m_AxisName); - EditorGUI.PropertyField(drawRect, m_AxisTick); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.y += EditorGUI.GetPropertyHeight(m_AxisTick); - EditorGUI.PropertyField(drawRect, m_AxisLabel); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLabel); - EditorGUI.PropertyField(drawRect, m_SplitLine); - drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine); - EditorGUI.PropertyField(drawRect, m_SplitArea); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea); + DrawExtendeds(prop); + PropertyField(prop, "m_AxisLine"); + PropertyField(prop, "m_AxisName"); + PropertyField(prop, "m_AxisTick"); + PropertyField(prop, "m_AxisLabel"); + PropertyField(prop, "m_SplitLine"); + PropertyField(prop, "m_SplitArea"); if (type == Axis.AxisType.Category) { - drawRect.width = EditorGUIUtility.labelWidth + 10; - m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data"); - ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width); - drawRect.width = pos.width; - if (m_DataFoldout[index]) + m_DrawRect.width = EditorGUIUtility.labelWidth + 10; + m_DataToggles[m_KeyName] = EditorGUI.Foldout(m_DrawRect, m_DataToggles[m_KeyName], "Data"); + AddSingleLineHeight(); + m_DrawRect.width = pos.width; + if (m_DataToggles[m_KeyName]) { - ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data); + var height = m_Heights[m_KeyName]; + ChartEditorHelper.MakeList(ref m_DrawRect, ref height, ref m_DataSize, m_Data); + m_Heights[m_KeyName] = height; } } EditorGUI.indentLevel--; } } + } - protected virtual void DrawExtended(ref Rect drawRect, SerializedProperty prop) + [CustomPropertyDrawer(typeof(XAxis), true)] + public class XAxisDrawer : AxisDrawer + { + public override string ClassName { get { return "XAxis"; } } + } + + [CustomPropertyDrawer(typeof(YAxis), true)] + public class YAxisDrawer : AxisDrawer + { + public override string ClassName { get { return "YAxis"; } } + } + + [CustomPropertyDrawer(typeof(AngleAxis), true)] + public class AngleAxisDrawer : AxisDrawer + { + public override string ClassName { get { return "AngleAxis"; } } + protected override void DrawExtendeds(SerializedProperty prop) { - + base.DrawExtendeds(prop); + PropertyField(prop, "m_StartAngle"); + PropertyField(prop, "m_Clockwise"); } + } - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) + [CustomPropertyDrawer(typeof(RadiusAxis), true)] + public class RadiusAxisDrawer : AxisDrawer + { + public override string ClassName { get { return "RadiusAxis"; } } + } + + [CustomPropertyDrawer(typeof(AxisLabel), true)] + public class AxisLabelDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "AxisLabel"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - int index = InitToggle(prop); - if (!m_AxisModuleToggle[index]) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - else - { - SerializedProperty m_Type = prop.FindPropertyRelative("m_Type"); - SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick"); - SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine"); - SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName"); - SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel"); - SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea"); - SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine"); - float height = 0; - height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; - Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex; - if (type == Axis.AxisType.Category) - { - if (m_DataFoldout[index]) - { - SerializedProperty m_Data = prop.FindPropertyRelative("m_Data"); - int num = m_Data.arraySize + 2; - if (num > 30) num = 14; - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUIUtility.standardVerticalSpacing; - } - else - { - height += 0 * EditorGUIUtility.singleLineHeight + 0 * EditorGUIUtility.standardVerticalSpacing; - } - if (m_ShowJsonDataArea) - { - height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing; - } - } - else if (type == Axis.AxisType.Value) - { - height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType"); - if (m_MinMaxType.enumValueIndex == (int)Axis.AxisMinMaxType.Custom) - { - height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing; - } - } - else if (type == Axis.AxisType.Log) - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType"); - if (m_MinMaxType.enumValueIndex == (int)Axis.AxisMinMaxType.Custom) - { - height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing; - } - } - height += EditorGUI.GetPropertyHeight(m_AxisName); - height += EditorGUI.GetPropertyHeight(m_AxisLine); - height += EditorGUI.GetPropertyHeight(m_AxisTick); - height += EditorGUI.GetPropertyHeight(m_AxisLabel); - height += EditorGUI.GetPropertyHeight(m_SplitArea); - height += EditorGUI.GetPropertyHeight(m_SplitLine); - height += GetExtendedHeight(); - return height; + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Formatter"); + PropertyField(prop, "m_Inside"); + PropertyField(prop, "m_Interval"); + PropertyField(prop, "m_Margin"); + PropertyField(prop, "m_NumericFormatter"); + PropertyField(prop, "m_ShowAsPositiveNumber"); + PropertyField(prop, "m_OnZero"); + PropertyField(prop, "m_TextLimit"); + PropertyField(prop, "m_TextStyle"); + PropertyField(prop, "m_OnZero"); + PropertyField(prop, "m_OnZero"); + --EditorGUI.indentLevel; } } + } - protected virtual float GetExtendedHeight() + [CustomPropertyDrawer(typeof(AxisName), true)] + public class AxisNameDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "AxisName"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - return 0; + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) + { + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Name"); + PropertyField(prop, "m_Location"); + PropertyField(prop, "m_TextStyle"); + --EditorGUI.indentLevel; + } } + } - private int InitToggle(SerializedProperty prop) + [CustomPropertyDrawer(typeof(AxisSplitArea), true)] + public class AxisSplitAreaDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "SplitArea"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - int index = 0; - int.TryParse(prop.displayName.Split(' ')[1], out index); - if (index >= m_DataFoldout.Count) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - m_DataFoldout.Add(false); + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Color"); + --EditorGUI.indentLevel; } - if (index >= m_AxisModuleToggle.Count) - { - m_AxisModuleToggle.Add(false); - } - return index; } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisLabelDrawer.cs b/Editor/PropertyDrawers/AxisLabelDrawer.cs deleted file mode 100644 index 017325ce..00000000 --- a/Editor/PropertyDrawers/AxisLabelDrawer.cs +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(AxisLabel), true)] - public class AxisLabelDrawer : PropertyDrawer - { - private Dictionary m_AxisLabelToggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter"); - SerializedProperty m_Inside = prop.FindPropertyRelative("m_Inside"); - SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval"); - SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate"); - SerializedProperty m_Margin = prop.FindPropertyRelative("m_Margin"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); - SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); - SerializedProperty m_NumericFormatter = prop.FindPropertyRelative("m_NumericFormatter"); - SerializedProperty m_ShowAsPositiveNumber = prop.FindPropertyRelative("m_ShowAsPositiveNumber"); - SerializedProperty m_OnZero = prop.FindPropertyRelative("m_OnZero"); - SerializedProperty m_TextLimit = prop.FindPropertyRelative("m_TextLimit"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLabelToggle, prop, "Axis Label", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_AxisLabelToggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_OnZero); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Inside); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Interval); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Rotate); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Margin); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontSize); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontStyle); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Formatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_NumericFormatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ShowAsPositiveNumber); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_TextLimit); - drawRect.y += EditorGUI.GetPropertyHeight(m_TextLimit); - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_AxisLabelToggle, prop)) - { - height += 12 * EditorGUIUtility.singleLineHeight + 11 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextLimit")); - } - return height; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisLineDrawer.cs b/Editor/PropertyDrawers/AxisLineDrawer.cs deleted file mode 100644 index 7c7d05c8..00000000 --- a/Editor/PropertyDrawers/AxisLineDrawer.cs +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(AxisLine), true)] - public class AxisLineDrawer : PropertyDrawer - { - private Dictionary m_AxisLineToggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_OnZero = prop.FindPropertyRelative("m_OnZero"); - SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); - SerializedProperty m_Symbol = prop.FindPropertyRelative("m_Symbol"); - SerializedProperty m_SymbolWidth = prop.FindPropertyRelative("m_SymbolWidth"); - SerializedProperty m_SymbolHeight = prop.FindPropertyRelative("m_SymbolHeight"); - SerializedProperty m_SymbolOffset = prop.FindPropertyRelative("m_SymbolOffset"); - SerializedProperty m_SymbolDent = prop.FindPropertyRelative("m_SymbolDent"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLineToggle, prop, "Axis Line", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_AxisLineToggle,prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_OnZero); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Width); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Symbol); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SymbolWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SymbolHeight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SymbolOffset); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SymbolDent); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_AxisLineToggle,prop)) - { - height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisNameDrawer.cs b/Editor/PropertyDrawers/AxisNameDrawer.cs deleted file mode 100644 index de1f5d6f..00000000 --- a/Editor/PropertyDrawers/AxisNameDrawer.cs +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(AxisName), true)] - public class AxisNameDrawer : PropertyDrawer - { - private Dictionary m_AxisNameToggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Name = prop.FindPropertyRelative("m_Name"); - SerializedProperty m_Location = prop.FindPropertyRelative("m_Location"); - SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); - SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); - SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisNameToggle, prop, "Axis Name", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_AxisNameToggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Name); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Location); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Offset); - drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); - // EditorGUI.LabelField(drawRect, "Offset"); - // var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15; - // var tempWidth = (pos.width - startX + 35) / 2; - // var xRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height); - // var yRect = new Rect(xRect.x + tempWidth - 20, drawRect.y, tempWidth, drawRect.height); - // var x = EditorGUI.FloatField(xRect, m_Offset.vector2Value.x); - // var y = EditorGUI.FloatField(yRect, m_Offset.vector2Value.y); - // m_Offset.vector2Value = new Vector2(x,y); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Rotate); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontSize); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontStyle); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_AxisNameToggle, prop)) - { - height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")); - } - return height; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisSplitAreaDrawer.cs b/Editor/PropertyDrawers/AxisSplitAreaDrawer.cs deleted file mode 100644 index ffb636ce..00000000 --- a/Editor/PropertyDrawers/AxisSplitAreaDrawer.cs +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(AxisSplitArea), true)] - public class AxisSplitAreaDrawer : PropertyDrawer - { - private bool m_ColorFoldout = false; - private int m_ColorSize = 0; - private Dictionary m_SplitAreaToggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SplitAreaToggle, prop, "Split Area", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_SplitAreaToggle, prop)) - { - ++EditorGUI.indentLevel; - m_ColorFoldout = EditorGUI.Foldout(drawRect, m_ColorFoldout, "Color"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.width = pos.width; - if (m_ColorFoldout) - { - ChartEditorHelper.MakeList(ref drawRect, ref m_ColorSize, m_Color); - } - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_SplitAreaToggle, prop)) - { - height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_ColorFoldout) - { - SerializedProperty m_Data = prop.FindPropertyRelative("m_Color"); - int num = m_Data.arraySize + 1; - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUIUtility.standardVerticalSpacing; - } - } - return height; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisSplitAreaDrawer.cs.meta b/Editor/PropertyDrawers/AxisSplitAreaDrawer.cs.meta deleted file mode 100644 index 1490325c..00000000 --- a/Editor/PropertyDrawers/AxisSplitAreaDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 988570bd6485942da9879649ed4adb5b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/AxisSplitLineDrawer.cs b/Editor/PropertyDrawers/AxisSplitLineDrawer.cs deleted file mode 100644 index 0c758236..00000000 --- a/Editor/PropertyDrawers/AxisSplitLineDrawer.cs +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(AxisSplitLine), true)] - public class AxisSplitLineDrawer : PropertyDrawer - { - private Dictionary m_AxisSplitLineToggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval"); - SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisSplitLineToggle, prop, "Split Line", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_AxisSplitLineToggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Interval); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_AxisSplitLineToggle, prop)) - { - height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); - } - else - { - height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - return height; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisSplitLineDrawer.cs.meta b/Editor/PropertyDrawers/AxisSplitLineDrawer.cs.meta deleted file mode 100644 index 5fc81841..00000000 --- a/Editor/PropertyDrawers/AxisSplitLineDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: af473e9aba20f4f168b8f83a4db13f81 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/AxisTickDrawer.cs b/Editor/PropertyDrawers/AxisTickDrawer.cs deleted file mode 100644 index 53bc28b9..00000000 --- a/Editor/PropertyDrawers/AxisTickDrawer.cs +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(AxisTick), true)] - public class AxisTickDrawer : PropertyDrawer - { - private bool m_AxisTickToggle = false; - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_AlignWithLabel = prop.FindPropertyRelative("m_AlignWithLabel"); - SerializedProperty m_Inside = prop.FindPropertyRelative("m_Inside"); - SerializedProperty m_Length = prop.FindPropertyRelative("m_Length"); - SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisTickToggle, "Axis Tick", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_AxisTickToggle) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_AlignWithLabel); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Inside); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Length); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Width); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (m_AxisTickToggle) - { - height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisTickDrawer.cs.meta b/Editor/PropertyDrawers/AxisTickDrawer.cs.meta deleted file mode 100644 index 42093f1e..00000000 --- a/Editor/PropertyDrawers/AxisTickDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7c7d45bc59dedc140b08f6e9d26ccd9d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/BackgroundDrawer.cs b/Editor/PropertyDrawers/BackgroundDrawer.cs index 26f24c08..67fd8144 100644 --- a/Editor/PropertyDrawers/BackgroundDrawer.cs +++ b/Editor/PropertyDrawers/BackgroundDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,57 +11,21 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Background), true)] - public class BackgroundDrawer : PropertyDrawer + public class BackgroundDrawer : BasePropertyDrawer { - private bool m_BackgroundModuleToggle = false; - + public override string ClassName { get { return "Background"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - - SerializedProperty m_Show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Image = prop.FindPropertyRelative("m_Image"); - SerializedProperty m_ImageType = prop.FindPropertyRelative("m_ImageType"); - // SerializedProperty m_Left = prop.FindPropertyRelative("m_Left"); - // SerializedProperty m_Right = prop.FindPropertyRelative("m_Right"); - // SerializedProperty m_Top = prop.FindPropertyRelative("m_Top"); - // SerializedProperty m_Bottom = prop.FindPropertyRelative("m_Bottom"); - SerializedProperty m_ImageColor = prop.FindPropertyRelative("m_ImageColor"); - SerializedProperty m_HideThemeBackgroundColor = prop.FindPropertyRelative("m_HideThemeBackgroundColor"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_BackgroundModuleToggle, "Background", m_Show); - EditorGUI.LabelField(drawRect, "Background", EditorStyles.boldLabel); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_BackgroundModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Image); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ImageType); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, m_Left); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, m_Right); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, m_Top); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, m_Bottom); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ImageColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_HideThemeBackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Image"); + PropertyField(prop, "m_ImageType"); + PropertyField(prop, "m_ImageColor"); + PropertyField(prop, "m_HideThemeBackgroundColor"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (m_BackgroundModuleToggle) - return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; - else - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/BasePropertyDrawer.cs b/Editor/PropertyDrawers/BasePropertyDrawer.cs new file mode 100644 index 00000000..2034f3e3 --- /dev/null +++ b/Editor/PropertyDrawers/BasePropertyDrawer.cs @@ -0,0 +1,149 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace XCharts +{ + [CustomPropertyDrawer(typeof(Settings), true)] + public class BasePropertyDrawer : PropertyDrawer + { + protected int m_Index; + protected int m_DataSize; + protected float m_DefaultWidth; + protected string m_DisplayName; + protected string m_KeyName; + protected Rect m_DrawRect; + protected Dictionary m_Heights = new Dictionary(); + protected Dictionary m_PropToggles = new Dictionary(); + protected Dictionary m_DataToggles = new Dictionary(); + + public virtual string ClassName { get { return ""; } } + public virtual List IngorePropertys { get { return new List { }; } } + + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + m_DrawRect = pos; + m_DrawRect.height = EditorGUIUtility.singleLineHeight; + m_DefaultWidth = pos.width; + var list = prop.displayName.Split(' '); + if (list.Length > 0) + { + if (!int.TryParse(list[list.Length - 1], out m_Index)) + { + m_Index = 0; + m_DisplayName = prop.displayName; + m_KeyName = prop.propertyPath + "_" + m_Index; + } + else + { + m_DisplayName = ClassName + " " + m_Index; + m_KeyName = prop.propertyPath + "_" + m_Index; + } + } + else + { + m_DisplayName = prop.displayName; + } + if (!m_PropToggles.ContainsKey(m_KeyName)) + { + m_PropToggles.Add(m_KeyName, false); + } + if (!m_DataToggles.ContainsKey(m_KeyName)) + { + m_DataToggles.Add(m_KeyName, false); + } + if (!m_Heights.ContainsKey(m_KeyName)) + { + m_Heights.Add(m_KeyName, 0); + } + else + { + m_Heights[m_KeyName] = 0; + } + } + + private string GetKeyName(SerializedProperty prop) + { + var index = 0; + var list = prop.displayName.Split(' '); + if (list.Length > 0) + { + int.TryParse(list[list.Length - 1], out index); + } + return prop.propertyPath + "_" + index; + } + + protected void AddSingleLineHeight() + { + m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + m_DrawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } + + protected void PropertyField(SerializedProperty prop, string relativePropName) + { + if (IngorePropertys.Contains(relativePropName)) return; + if (!ChartEditorHelper.PropertyField(ref m_DrawRect, m_Heights, m_KeyName, prop, relativePropName)) + { + Debug.LogError("PropertyField ERROR:" + prop.displayName + ", " + relativePropName); + } + } + + protected void PropertyField(SerializedProperty prop, SerializedProperty relativeProp) + { + if (!ChartEditorHelper.PropertyField(ref m_DrawRect, m_Heights, m_KeyName, relativeProp)) + { + Debug.LogError("PropertyField ERROR:" + prop.displayName + ", " + relativeProp); + } + } + + protected void PropertyTwoFiled(SerializedProperty prop, string relativeListProp, string labelName = null) + { + PropertyTwoFiled(prop, prop.FindPropertyRelative(relativeListProp), labelName); + } + protected void PropertyTwoFiled(SerializedProperty prop, SerializedProperty relativeListProp, string labelName = null) + { + if (string.IsNullOrEmpty(labelName)) + { + labelName = relativeListProp.displayName; + } + ChartEditorHelper.MakeTwoField(ref m_DrawRect, m_DefaultWidth, relativeListProp, labelName); + m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } + + protected bool MakeFoldout(SerializedProperty prop, string relativePropName) + { + if (string.IsNullOrEmpty(relativePropName)) + { + return ChartEditorHelper.MakeFoldout(ref m_DrawRect, m_Heights, m_PropToggles, m_KeyName, m_DisplayName, null); + } + else + { + var relativeProp = prop.FindPropertyRelative(relativePropName); + return ChartEditorHelper.MakeFoldout(ref m_DrawRect, m_Heights, m_PropToggles, m_KeyName, m_DisplayName, relativeProp); + } + } + + protected virtual void DrawExtendeds(SerializedProperty prop) + { + } + + public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) + { + var key = GetKeyName(prop); + if (m_Heights.ContainsKey(key)) return m_Heights[key] + GetExtendedHeight(); + else return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } + + protected virtual float GetExtendedHeight() + { + return 0; + } + } +} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisLabelDrawer.cs.meta b/Editor/PropertyDrawers/BasePropertyDrawer.cs.meta similarity index 83% rename from Editor/PropertyDrawers/AxisLabelDrawer.cs.meta rename to Editor/PropertyDrawers/BasePropertyDrawer.cs.meta index b463817f..51f7228d 100644 --- a/Editor/PropertyDrawers/AxisLabelDrawer.cs.meta +++ b/Editor/PropertyDrawers/BasePropertyDrawer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 88f38952bcbcd448dbe12f98e9c9110d +guid: 4e5a04ce1f0a841b9b966a6d74de00e4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/PropertyDrawers/ComponentThemeDrawer.cs b/Editor/PropertyDrawers/ComponentThemeDrawer.cs new file mode 100644 index 00000000..57e1bda4 --- /dev/null +++ b/Editor/PropertyDrawers/ComponentThemeDrawer.cs @@ -0,0 +1,186 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + [CustomPropertyDrawer(typeof(ComponentTheme), true)] + public class ComponentThemeDrawer : BasePropertyDrawer + { + public override string ClassName { get { return ""; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "")) + { + ++EditorGUI.indentLevel; +#if dUI_TextMeshPro + PropertyField(prop, "m_TMPFont"); +#else + PropertyField(prop, "m_Font"); +#endif + PropertyField(prop, "m_FontSize"); + PropertyField(prop, "m_TextColor"); + //PropertyField(prop, "m_TextBackgroundColor"); + DrawExtendeds(prop); + --EditorGUI.indentLevel; + } + } + } + + [CustomPropertyDrawer(typeof(BaseAxisTheme), true)] + public class BaseAxisThemeDrawer : ComponentThemeDrawer + { + public override string ClassName { get { return "Axis"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_LineType"); + PropertyField(prop, "m_LineWidth"); + PropertyField(prop, "m_LineLength"); + PropertyField(prop, "m_LineColor"); + PropertyField(prop, "m_SplitLineType"); + PropertyField(prop, "m_SplitLineWidth"); + PropertyField(prop, "m_SplitLineLength"); + PropertyField(prop, "m_SplitLineColor"); + PropertyField(prop, "m_TickWidth"); + PropertyField(prop, "m_TickLength"); + PropertyField(prop, "m_TickColor"); + PropertyField(prop, "m_SplitAreaColors"); + } + } + + [CustomPropertyDrawer(typeof(AxisTheme), true)] + public class AxisThemeDrawer : BaseAxisThemeDrawer + { + public override string ClassName { get { return "Axis"; } } + } + [CustomPropertyDrawer(typeof(RadiusAxisTheme), true)] + public class RadiusAxisThemeDrawer : BaseAxisThemeDrawer + { + public override string ClassName { get { return "Radius Axis"; } } + public override List IngorePropertys + { + get + { + return new List { + "m_TextBackgroundColor" , + "m_LineLength", + "m_SplitLineLength", + }; + } + } + } + [CustomPropertyDrawer(typeof(GaugeAxisTheme), true)] + public class GaugeAxisThemeDrawer : AxisThemeDrawer + { + public override string ClassName { get { return "Gauge Axis"; } } + public override List IngorePropertys + { + get + { + return new List { + "m_TextBackgroundColor" , + "m_LineLength", + "m_SplitLineLength", + }; + } + } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_BarBackgroundColor"); + PropertyField(prop, "m_StageColor"); + } + } + + [CustomPropertyDrawer(typeof(DataZoomTheme), true)] + public class DataZoomThemeDrawer : ComponentThemeDrawer + { + public override string ClassName { get { return "DataZoom"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_BackgroundColor"); + PropertyField(prop, "m_BorderWidth"); + PropertyField(prop, "m_BorderColor"); + PropertyField(prop, "m_DataLineWidth"); + PropertyField(prop, "m_DataLineColor"); + PropertyField(prop, "m_FillerColor"); + PropertyField(prop, "m_DataAreaColor"); + + } + } + + [CustomPropertyDrawer(typeof(LegendTheme), true)] + public class LegendThemeDrawer : ComponentThemeDrawer + { + public override string ClassName { get { return "Legend"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_UnableColor"); + } + } + + [CustomPropertyDrawer(typeof(TooltipTheme), true)] + public class TooltipThemeDrawer : ComponentThemeDrawer + { + public override string ClassName { get { return "Tooltip"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_LineType"); + PropertyField(prop, "m_LineWidth"); + PropertyField(prop, "m_LineColor"); + PropertyField(prop, "m_AreaColor"); + PropertyField(prop, "m_LabelTextColor"); + PropertyField(prop, "m_LabelBackgroundColor"); + } + } + + [CustomPropertyDrawer(typeof(VisualMapTheme), true)] + public class VisualMapThemeDrawer : ComponentThemeDrawer + { + public override string ClassName { get { return "VisualMap"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + // PropertyField(prop, "m_BorderWidth"); + // PropertyField(prop, "m_BorderColor"); + // PropertyField(prop, "m_BackgroundColor"); + } + } + + [CustomPropertyDrawer(typeof(SerieTheme), true)] + public class SerieThemeDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "Serie"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "")) + { + ++EditorGUI.indentLevel; + PropertyField(prop, "m_LineWidth"); + PropertyField(prop, "m_LineSymbolSize"); + PropertyField(prop, "m_LineSymbolSelectedSize"); + PropertyField(prop, "m_ScatterSymbolSize"); + PropertyField(prop, "m_ScatterSymbolSelectedSize"); + PropertyField(prop, "m_PieTooltipExtraRadius"); + PropertyField(prop, "m_PieSelectedOffset"); + --EditorGUI.indentLevel; + } + } + } +} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisLineDrawer.cs.meta b/Editor/PropertyDrawers/ComponentThemeDrawer.cs.meta similarity index 83% rename from Editor/PropertyDrawers/AxisLineDrawer.cs.meta rename to Editor/PropertyDrawers/ComponentThemeDrawer.cs.meta index 6865bb9d..5ddef759 100644 --- a/Editor/PropertyDrawers/AxisLineDrawer.cs.meta +++ b/Editor/PropertyDrawers/ComponentThemeDrawer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 866eefe266c3c47809d9dff3e89be0ab +guid: c7937a2a7addd42299e960c5cfb75e34 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/PropertyDrawers/DataZoomDrawer.cs b/Editor/PropertyDrawers/DataZoomDrawer.cs index c42c8342..85967490 100644 --- a/Editor/PropertyDrawers/DataZoomDrawer.cs +++ b/Editor/PropertyDrawers/DataZoomDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,96 +11,55 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(DataZoom), true)] - public class DataZoomDrawer : PropertyDrawer + public class DataZoomDrawer : BasePropertyDrawer { - private bool m_DataZoomModuleToggle = false; - + public override string ClassName { get { return "DataZoom"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Enable"); - //SerializedProperty m_FilterMode = prop.FindPropertyRelative("m_FilterMode"); - //SerializedProperty m_Orient = prop.FindPropertyRelative("m_Orient"); - SerializedProperty m_SupportInside = prop.FindPropertyRelative("m_SupportInside"); - SerializedProperty m_SupportSlider = prop.FindPropertyRelative("m_SupportSlider"); - //SerializedProperty m_SupportSelect = prop.FindPropertyRelative("m_SupportSelect"); - SerializedProperty m_ShowDataShadow = prop.FindPropertyRelative("m_ShowDataShadow"); - SerializedProperty m_ShowDetail = prop.FindPropertyRelative("m_ShowDetail"); - SerializedProperty m_ZoomLock = prop.FindPropertyRelative("m_ZoomLock"); - // SerializedProperty m_Realtime = prop.FindPropertyRelative("m_Realtime"); - // SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - SerializedProperty m_Height = prop.FindPropertyRelative("m_Height"); - SerializedProperty m_Bottom = prop.FindPropertyRelative("m_Bottom"); - SerializedProperty m_RangeMode = prop.FindPropertyRelative("m_RangeMode"); - SerializedProperty m_Start = prop.FindPropertyRelative("m_Start"); - SerializedProperty m_End = prop.FindPropertyRelative("m_End"); - SerializedProperty m_MinShowNum = prop.FindPropertyRelative("m_MinShowNum"); - SerializedProperty m_ScrollSensitivity = prop.FindPropertyRelative("m_ScrollSensitivity"); - SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); - SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_DataZoomModuleToggle, "DataZoom", show); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_DataZoomModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Enable")) { + var m_SupportSlider = prop.FindPropertyRelative("m_SupportSlider"); + var m_Start = prop.FindPropertyRelative("m_Start"); + var m_End = prop.FindPropertyRelative("m_End"); + var m_MinShowNum = prop.FindPropertyRelative("m_MinShowNum"); ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_SupportInside); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SupportSlider); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_SupportSlider.boolValue) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_ShowDataShadow); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ShowDetail); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontSize); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontStyle); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, m_Realtime); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Height); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Bottom); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - --EditorGUI.indentLevel; - } - //EditorGUI.PropertyField(drawRect, m_SupportSelect); - //drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ZoomLock); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ScrollSensitivity); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_RangeMode); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Start); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_End); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_MinShowNum); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_SupportInside"); + PropertyField(prop, m_SupportSlider); + PropertyField(prop, "m_ZoomLock"); + PropertyField(prop, "m_ScrollSensitivity"); + PropertyField(prop, "m_RangeMode"); + PropertyField(prop, m_Start); + PropertyField(prop, m_End); + PropertyField(prop, m_MinShowNum); if (m_Start.floatValue < 0) m_Start.floatValue = 0; if (m_End.floatValue > 100) m_End.floatValue = 100; if (m_MinShowNum.intValue < 0) m_MinShowNum.intValue = 0; + if (m_SupportSlider.boolValue) + { + PropertyField(prop, "m_ShowDataShadow"); + PropertyField(prop, "m_ShowDetail"); + PropertyField(prop, "m_BackgroundColor"); + PropertyField(prop, "m_BorderWidth"); + PropertyField(prop, "m_BorderColor"); + PropertyField(prop, "m_FillerColor"); + PropertyField(prop, "m_Left"); + PropertyField(prop, "m_Right"); + PropertyField(prop, "m_Top"); + PropertyField(prop, "m_Bottom"); + PropertyField(prop, "m_LineStyle"); + PropertyField(prop, "m_AreaStyle"); + PropertyField(prop, "m_XAxisIndexs"); + PropertyField(prop, "m_YAxisIndexs"); + PropertyField(prop, "m_TextStyle"); + } + else + { + PropertyField(prop, "m_XAxisIndexs"); + PropertyField(prop, "m_YAxisIndexs"); + } --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - int num = 1; - if (m_DataZoomModuleToggle) - { - num += 8; - if (prop.FindPropertyRelative("m_SupportSlider").boolValue) num += 6; - - } - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/EmphasisStyleDrawer.cs b/Editor/PropertyDrawers/EmphasisStyleDrawer.cs index ea2153ce..c31efb61 100644 --- a/Editor/PropertyDrawers/EmphasisStyleDrawer.cs +++ b/Editor/PropertyDrawers/EmphasisStyleDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,44 +12,19 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Emphasis), true)] - public class EmphasisDrawer : PropertyDrawer + public class EmphasisDrawer : BasePropertyDrawer { - private Dictionary m_EmphasisToggle = new Dictionary(); - + public override string ClassName { get { return "Emphasis"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Label = prop.FindPropertyRelative("m_Label"); - SerializedProperty m_ItemStyle = prop.FindPropertyRelative("m_ItemStyle"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_EmphasisToggle, prop, "Emphasis", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_EmphasisToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Label); - drawRect.y += EditorGUI.GetPropertyHeight(m_Label); - EditorGUI.PropertyField(drawRect, m_ItemStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle); + PropertyField(prop, "m_Label"); + PropertyField(prop, "m_ItemStyle"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_EmphasisToggle, prop)) - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label")); - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle")); - } - else - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/GaugeAxisDrawer.cs b/Editor/PropertyDrawers/GaugeAxisDrawer.cs index 672b9930..92472017 100644 --- a/Editor/PropertyDrawers/GaugeAxisDrawer.cs +++ b/Editor/PropertyDrawers/GaugeAxisDrawer.cs @@ -1,81 +1,69 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(GaugeAxis), true)] - public class GaugeAxisDrawer : PropertyDrawer + public class GaugeAxisDrawer : BasePropertyDrawer { - private bool m_DataFoldout = false; - private int m_DataSize = 0; - private Dictionary m_AxisLineToggle = new Dictionary(); + public override string ClassName { get { return "Gauge Axis"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) + { + ++EditorGUI.indentLevel; + PropertyField(prop, "m_AxisLine"); + PropertyField(prop, "m_SplitLine"); + PropertyField(prop, "m_AxisTick"); + PropertyField(prop, "m_AxisLabel"); + PropertyField(prop, "m_AxisLabelText"); + --EditorGUI.indentLevel; + } + } + } + + [CustomPropertyDrawer(typeof(StageColor), true)] + public class GaugeAxisLineStageColorDrawer : BasePropertyDrawer + { public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { Rect drawRect = pos; drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine"); - SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine"); - SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick"); - SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel"); - SerializedProperty m_AxisLabelText = prop.FindPropertyRelative("m_AxisLabelText"); + SerializedProperty m_Percent = prop.FindPropertyRelative("m_Percent"); + SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLineToggle, prop, "Gauge Axis", show, false); + ChartEditorHelper.MakeTwoField(ref drawRect, drawRect.width, m_Percent, m_Color, "Stage"); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_AxisLineToggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_AxisLine); - drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLine); - EditorGUI.PropertyField(drawRect, m_SplitLine); - drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine); - EditorGUI.PropertyField(drawRect, m_AxisTick); - drawRect.y += EditorGUI.GetPropertyHeight(m_AxisTick); - EditorGUI.PropertyField(drawRect, m_AxisLabel); - drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLabel); - drawRect.width = EditorGUIUtility.labelWidth + 10; - m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Axis Label Text"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.width = pos.width; - if (m_DataFoldout) - { - ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_AxisLabelText); - } - --EditorGUI.indentLevel; - } } public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) { - float height = 0; - if (ChartEditorHelper.IsToggle(m_AxisLineToggle, prop)) + return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; + } + } + + [CustomPropertyDrawer(typeof(GaugePointer), true)] + public class GaugePointerDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "Gauge Pointer"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AxisLine")); - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitLine")); - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AxisTick")); - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AxisLabel")); - if (m_DataFoldout) - { - SerializedProperty m_Data = prop.FindPropertyRelative("m_AxisLabelText"); - int num = m_Data.arraySize + 1; - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUIUtility.standardVerticalSpacing; - } - return height; - } - else - { - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Width"); + PropertyField(prop, "m_Length"); + --EditorGUI.indentLevel; } } } diff --git a/Editor/PropertyDrawers/GaugeAxisLineDrawer.cs b/Editor/PropertyDrawers/GaugeAxisLineDrawer.cs deleted file mode 100644 index 5222b97c..00000000 --- a/Editor/PropertyDrawers/GaugeAxisLineDrawer.cs +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(GaugeAxis.AxisLine), true)] - public class GaugeAxisLineDrawer : PropertyDrawer - { - private bool m_DataFoldout = false; - private int m_DataSize = 0; - private Dictionary m_Toggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); - SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity"); - SerializedProperty m_BarBackgroundColor = prop.FindPropertyRelative("m_BarBackgroundColor"); - SerializedProperty m_BarColor = prop.FindPropertyRelative("m_BarColor"); - SerializedProperty m_StageColor = prop.FindPropertyRelative("m_StageColor"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Axis Line", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Width); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Opacity); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BarColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BarBackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Stage Color"); - drawRect.width = pos.width; - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_DataFoldout) - { - ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_StageColor); - } - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - float height = 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing; - if (m_DataFoldout) - { - var arraySize = prop.FindPropertyRelative("m_StageColor").arraySize + 1; - height += arraySize * EditorGUIUtility.singleLineHeight + (arraySize) * EditorGUIUtility.standardVerticalSpacing; - height += 2 * EditorGUIUtility.standardVerticalSpacing; - return height; - } - return height; - } - else - { - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/GaugeAxisLineDrawer.cs.meta b/Editor/PropertyDrawers/GaugeAxisLineDrawer.cs.meta deleted file mode 100644 index b3d087ca..00000000 --- a/Editor/PropertyDrawers/GaugeAxisLineDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: eb7a86643ea2349c8ac2475ab81cb2f9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs b/Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs deleted file mode 100644 index babdea94..00000000 --- a/Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(GaugeAxis.AxisLine.StageColor), true)] - public class GaugeAxisLineStageColorDrawer : PropertyDrawer - { - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty m_Percent = prop.FindPropertyRelative("m_Percent"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - - ChartEditorHelper.MakeTwoField(ref drawRect, drawRect.width, m_Percent, m_Color, "Stage"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs.meta b/Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs.meta deleted file mode 100644 index 3f4bc31b..00000000 --- a/Editor/PropertyDrawers/GaugeAxisLineStageColorDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cc7cae70713a74fb496ef686296bc46b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs b/Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs deleted file mode 100644 index 0f90567b..00000000 --- a/Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(GaugeAxis.SplitLine), true)] - public class GaugeAxisSplitDrawer : PropertyDrawer - { - private Dictionary m_Toggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Length = prop.FindPropertyRelative("m_Length"); - SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Split Line", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Length); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - float height = 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); - return height; - } - else - { - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs.meta b/Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs.meta deleted file mode 100644 index f2dc069b..00000000 --- a/Editor/PropertyDrawers/GaugeAxisSplitDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d11eb7847e5c74746a570a7c9f6b339a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/GaugeAxisTickDrawer.cs b/Editor/PropertyDrawers/GaugeAxisTickDrawer.cs deleted file mode 100644 index e2d3b08d..00000000 --- a/Editor/PropertyDrawers/GaugeAxisTickDrawer.cs +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(GaugeAxis.AxisTick), true)] - public class GaugeAxisTickDrawer : PropertyDrawer - { - private Dictionary m_Toggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Length = prop.FindPropertyRelative("m_Length"); - SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber"); - SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Axis Tick", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Length); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SplitNumber); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - float height = 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); - return height; - } - else - { - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/GaugeAxisTickDrawer.cs.meta b/Editor/PropertyDrawers/GaugeAxisTickDrawer.cs.meta deleted file mode 100644 index f4903e5e..00000000 --- a/Editor/PropertyDrawers/GaugeAxisTickDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5f561506277b949c1b22116a3f3d3f4f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/GaugePointerDrawer.cs b/Editor/PropertyDrawers/GaugePointerDrawer.cs deleted file mode 100644 index b10f300c..00000000 --- a/Editor/PropertyDrawers/GaugePointerDrawer.cs +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(GaugePointer), true)] - public class GaugePointerDrawer : PropertyDrawer - { - private Dictionary m_Toggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); - SerializedProperty m_Length = prop.FindPropertyRelative("m_Length"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_Toggle, prop, "Gauge Pointer", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Width); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Length); - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_Toggle, prop)) - { - return 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; - } - else - { - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/GaugePointerDrawer.cs.meta b/Editor/PropertyDrawers/GaugePointerDrawer.cs.meta deleted file mode 100644 index c5b67446..00000000 --- a/Editor/PropertyDrawers/GaugePointerDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a3d180de37dd24cfc9bcbb46f650c902 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/GridDrawer.cs b/Editor/PropertyDrawers/GridDrawer.cs index 46cf7d05..1be2328a 100644 --- a/Editor/PropertyDrawers/GridDrawer.cs +++ b/Editor/PropertyDrawers/GridDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,48 +11,22 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Grid), true)] - public class GridDrawer : PropertyDrawer + public class GridDrawer : BasePropertyDrawer { - private bool m_GridModuleToggle = false; - + public override string ClassName { get { return "Grid"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - - SerializedProperty m_Show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Left = prop.FindPropertyRelative("m_Left"); - SerializedProperty m_Right = prop.FindPropertyRelative("m_Right"); - SerializedProperty m_Top = prop.FindPropertyRelative("m_Top"); - SerializedProperty m_Bottom = prop.FindPropertyRelative("m_Bottom"); - SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_GridModuleToggle, "Grid",m_Show); - EditorGUI.LabelField(drawRect, "Grid", EditorStyles.boldLabel); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_GridModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Left); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Right); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Top); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Bottom); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Left"); + PropertyField(prop, "m_Right"); + PropertyField(prop, "m_Top"); + PropertyField(prop, "m_Bottom"); + PropertyField(prop, "m_BackgroundColor"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (m_GridModuleToggle) - return 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing; - else - return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/IconStyleDrawer.cs b/Editor/PropertyDrawers/IconStyleDrawer.cs index b90773fc..e1e5dd1b 100644 --- a/Editor/PropertyDrawers/IconStyleDrawer.cs +++ b/Editor/PropertyDrawers/IconStyleDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,56 +12,23 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(IconStyle), true)] - public class IconStyleDrawer : PropertyDrawer + public class IconStyleDrawer : BasePropertyDrawer { - private Dictionary m_IconStyleToggle = new Dictionary(); - + public override string ClassName { get { return "IconStyle"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty m_Show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Layer = prop.FindPropertyRelative("m_Layer"); - SerializedProperty m_Sprite = prop.FindPropertyRelative("m_Sprite"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); - SerializedProperty m_Height = prop.FindPropertyRelative("m_Height"); - SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_IconStyleToggle, prop, null, m_Show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_IconStyleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - - EditorGUI.PropertyField(drawRect, m_Layer); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Sprite); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Width); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Height); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Offset); - drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); + PropertyField(prop, "m_Layer"); + PropertyField(prop, "m_Sprite"); + PropertyField(prop, "m_Color"); + PropertyField(prop, "m_Width"); + PropertyField(prop, "m_Height"); + PropertyField(prop, "m_Offset"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_IconStyleToggle, prop)) - { - var hight = 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing; - hight += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")); - hight += EditorGUIUtility.standardVerticalSpacing; - return hight; - } - else - { - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/ItemStyleDrawer.cs b/Editor/PropertyDrawers/ItemStyleDrawer.cs index 27ae3452..ee2d5e2a 100644 --- a/Editor/PropertyDrawers/ItemStyleDrawer.cs +++ b/Editor/PropertyDrawers/ItemStyleDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,89 +12,31 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(ItemStyle), true)] - public class ItemStyleDrawer : PropertyDrawer + public class ItemStyleDrawer : BasePropertyDrawer { - private int m_CornerRadius = 0; - private Dictionary m_ItemStyleToggle = new Dictionary(); - private Dictionary m_CornerRadiusToggle = new Dictionary(); - + public override string ClassName { get { return "ItemStyle"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_ToColor = prop.FindPropertyRelative("m_ToColor"); - SerializedProperty m_ToColor2 = prop.FindPropertyRelative("m_ToColor2"); - SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - SerializedProperty m_BackgroundWidth = prop.FindPropertyRelative("m_BackgroundWidth"); - SerializedProperty m_CenterColor = prop.FindPropertyRelative("m_CenterColor"); - SerializedProperty m_CenterGap = prop.FindPropertyRelative("m_CenterGap"); - SerializedProperty m_BorderType = prop.FindPropertyRelative("m_BorderType"); - SerializedProperty m_BorderWidth = prop.FindPropertyRelative("m_BorderWidth"); - SerializedProperty m_BorderColor = prop.FindPropertyRelative("m_BorderColor"); - SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity"); - SerializedProperty m_TooltipFormatter = prop.FindPropertyRelative("m_TooltipFormatter"); - SerializedProperty m_NumericFormatter = prop.FindPropertyRelative("m_NumericFormatter"); - SerializedProperty m_CornerRadius = prop.FindPropertyRelative("m_CornerRadius"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_ItemStyleToggle, prop, "Item Style", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_ItemStyleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ToColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ToColor2); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_CenterColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_CenterGap); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BorderType); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BorderWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BorderColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Opacity); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_TooltipFormatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_NumericFormatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_CornerRadiusToggle, m_CornerRadius, "Corner Radius", null, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_CornerRadiusToggle, m_CornerRadius)) - { - ChartEditorHelper.MakeList(ref drawRect, ref this.m_CornerRadius, m_CornerRadius, false, false); - } + PropertyField(prop, "m_Color"); + PropertyField(prop, "m_ToColor"); + PropertyField(prop, "m_ToColor2"); + PropertyField(prop, "m_BackgroundColor"); + PropertyField(prop, "m_BackgroundWidth"); + PropertyField(prop, "m_CenterColor"); + PropertyField(prop, "m_CenterGap"); + PropertyField(prop, "m_BorderType"); + PropertyField(prop, "m_BorderWidth"); + PropertyField(prop, "m_BorderColor"); + PropertyField(prop, "m_Opacity"); + PropertyField(prop, "m_TooltipFormatter"); + PropertyField(prop, "m_NumericFormatter"); + PropertyField(prop, "m_CornerRadius"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_ItemStyleToggle, prop)) - { - height += 15 * EditorGUIUtility.singleLineHeight + 14 * EditorGUIUtility.standardVerticalSpacing; - var m_CornerRadius = prop.FindPropertyRelative("m_CornerRadius"); - if (ChartEditorHelper.IsToggle(m_CornerRadiusToggle, m_CornerRadius)) - { - height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; - } - } - else - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/LegendDrawer.cs b/Editor/PropertyDrawers/LegendDrawer.cs index 87ec617f..b7c3723b 100644 --- a/Editor/PropertyDrawers/LegendDrawer.cs +++ b/Editor/PropertyDrawers/LegendDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,105 +11,27 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Legend), true)] - public class LegendDrawer : PropertyDrawer + public class LegendDrawer : BasePropertyDrawer { - private bool m_DataFoldout = false; - private bool m_IconsFoldout = false; - private int m_DataSize = 0; - private int m_IconsSize = 0; - private bool m_ShowJsonDataArea = false; - private string m_JsonDataAreaText; - private bool m_LegendModuleToggle = false; - + public override string ClassName { get { return "Legend"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_SelectedMode = prop.FindPropertyRelative("m_SelectedMode"); - SerializedProperty orient = prop.FindPropertyRelative("m_Orient"); - SerializedProperty location = prop.FindPropertyRelative("m_Location"); - SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth"); - SerializedProperty itemHeight = prop.FindPropertyRelative("m_ItemHeight"); - SerializedProperty itemGap = prop.FindPropertyRelative("m_ItemGap"); - SerializedProperty m_ItemAutoColor = prop.FindPropertyRelative("m_ItemAutoColor"); - SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter"); - SerializedProperty m_Data = prop.FindPropertyRelative("m_Data"); - SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons"); - SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LegendModuleToggle, "Legend", show); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_LegendModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, itemWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, itemHeight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, itemGap); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ItemAutoColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SelectedMode); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, orient); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, location); - drawRect.y += EditorGUI.GetPropertyHeight(location); - EditorGUI.PropertyField(drawRect, m_Formatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.width = EditorGUIUtility.labelWidth + 10; - m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data"); - ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width); - drawRect.width = pos.width; - if (m_DataFoldout) - { - ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data); - } - m_IconsFoldout = EditorGUI.Foldout(drawRect, m_IconsFoldout, "Icons"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_IconsFoldout) - { - ChartEditorHelper.MakeList(ref drawRect, ref m_IconsSize, m_Icons); - } - EditorGUI.PropertyField(drawRect, m_TextStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle); + PropertyField(prop, "m_ItemWidth"); + PropertyField(prop, "m_ItemHeight"); + PropertyField(prop, "m_ItemGap"); + PropertyField(prop, "m_ItemAutoColor"); + PropertyField(prop, "m_SelectedMode"); + PropertyField(prop, "m_Orient"); + PropertyField(prop, "m_Location"); + PropertyField(prop, "m_Formatter"); + PropertyField(prop, "m_TextStyle"); + PropertyField(prop, "m_Icons"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (m_LegendModuleToggle) - { - SerializedProperty location = prop.FindPropertyRelative("m_Location"); - height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(location); - height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_DataFoldout) - { - SerializedProperty m_Data = prop.FindPropertyRelative("m_Data"); - int num = m_Data.arraySize + 1; - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUIUtility.standardVerticalSpacing; - } - if (m_IconsFoldout) - { - SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons"); - int num = m_Icons.arraySize + 1; - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUIUtility.standardVerticalSpacing; - } - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle")); - } - if (m_ShowJsonDataArea) - { - height += EditorGUIUtility.singleLineHeight * 4 + EditorGUIUtility.standardVerticalSpacing; - } - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/LineArrowDrawer.cs b/Editor/PropertyDrawers/LineArrowDrawer.cs index 82240d38..ebbc3d2c 100644 --- a/Editor/PropertyDrawers/LineArrowDrawer.cs +++ b/Editor/PropertyDrawers/LineArrowDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -11,52 +11,40 @@ using UnityEngine; namespace XCharts { - [CustomPropertyDrawer(typeof(LineArrow), true)] - public class LineArrowStyleDrawer : PropertyDrawer + [CustomPropertyDrawer(typeof(Arrow), true)] + public class ArrowDrawer : BasePropertyDrawer { - private Dictionary m_LineArrowToggle = new Dictionary(); - + public override string ClassName { get { return "Arrow"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Position = prop.FindPropertyRelative("m_Position"); - SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); - SerializedProperty m_Height = prop.FindPropertyRelative("m_Height"); - SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); - SerializedProperty m_Dent = prop.FindPropertyRelative("m_Dent"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LineArrowToggle, prop, "Line Arrow", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_LineArrowToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Position); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Width); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Height); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Offset); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Dent); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Width"); + PropertyField(prop, "m_Height"); + PropertyField(prop, "m_Offset"); + PropertyField(prop, "m_Dent"); + PropertyField(prop, "m_Color"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) + } + + [CustomPropertyDrawer(typeof(LineArrow), true)] + public class LineArrowStyleDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "LineArrow"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - float height = 0; - if (ChartEditorHelper.IsToggle(m_LineArrowToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing; + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Position"); + PropertyField(prop, "m_Arrow"); + --EditorGUI.indentLevel; } - else - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - return height; } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/LineDrawer.cs b/Editor/PropertyDrawers/LineDrawer.cs new file mode 100644 index 00000000..d8c29447 --- /dev/null +++ b/Editor/PropertyDrawers/LineDrawer.cs @@ -0,0 +1,94 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEditor; +using UnityEngine; + +namespace XCharts +{ + [CustomPropertyDrawer(typeof(BaseLine), true)] + public class BaseLineDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "Line"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) + { + ++EditorGUI.indentLevel; + DrawExtendeds(prop); + PropertyField(prop, "m_LineStyle"); + --EditorGUI.indentLevel; + } + } + } + + [CustomPropertyDrawer(typeof(AxisLine), true)] + public class AxisLineDrawer : BaseLineDrawer + { + public override string ClassName { get { return "AxisLine"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_OnZero"); + PropertyField(prop, "m_ShowArrow"); + PropertyField(prop, "m_Arrow"); + } + } + + [CustomPropertyDrawer(typeof(AxisSplitLine), true)] + public class AxisSplitLineDrawer : BaseLineDrawer + { + public override string ClassName { get { return "SplitLine"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_Interval"); + } + } + [CustomPropertyDrawer(typeof(AxisTick), true)] + public class AxisTickDrawer : BaseLineDrawer + { + public override string ClassName { get { return "AxisTick"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_Interval"); + PropertyField(prop, "m_Inside"); + } + } + + [CustomPropertyDrawer(typeof(GaugeAxisSplitLine), true)] + public class GaugeAxisSplitDrawer : BaseLineDrawer + { + public override string ClassName { get { return "Split Line"; } } + } + + [CustomPropertyDrawer(typeof(GaugeAxisTick), true)] + public class GaugeAxisTickDrawer : BaseLineDrawer + { + public override string ClassName { get { return "Axis Tick"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_SplitNumber"); + } + } + + [CustomPropertyDrawer(typeof(GaugeAxisLine), true)] + public class GaugeAxisLineDrawer : BaseLineDrawer + { + public override string ClassName { get { return "Axis Line"; } } + protected override void DrawExtendeds(SerializedProperty prop) + { + base.DrawExtendeds(prop); + PropertyField(prop, "m_BarColor"); + PropertyField(prop, "m_BarBackgroundColor"); + PropertyField(prop, "m_StageColor"); + } + } +} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AngleAxisDrawer.cs.meta b/Editor/PropertyDrawers/LineDrawer.cs.meta similarity index 83% rename from Editor/PropertyDrawers/AngleAxisDrawer.cs.meta rename to Editor/PropertyDrawers/LineDrawer.cs.meta index 993985d5..5830eeb6 100644 --- a/Editor/PropertyDrawers/AngleAxisDrawer.cs.meta +++ b/Editor/PropertyDrawers/LineDrawer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 521ea44136ea74a2f82a4c0c46edfd32 +guid: 2e69f60c7d200439abcf3407c15f8c4d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/PropertyDrawers/LineStyleDrawer.cs b/Editor/PropertyDrawers/LineStyleDrawer.cs index e103c5e0..378e3157 100644 --- a/Editor/PropertyDrawers/LineStyleDrawer.cs +++ b/Editor/PropertyDrawers/LineStyleDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,54 +12,23 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(LineStyle), true)] - public class LineStyleDrawer : PropertyDrawer + public class LineStyleDrawer : BasePropertyDrawer { - private Dictionary m_LineStyleToggle = new Dictionary(); - + public override string ClassName { get { return "LineStyle"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Type = prop.FindPropertyRelative("m_Type"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_ToColor = prop.FindPropertyRelative("m_ToColor"); - SerializedProperty m_ToColor2 = prop.FindPropertyRelative("m_ToColor2"); - SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); - SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LineStyleToggle, prop, "Line Style", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_LineStyleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Type); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ToColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ToColor2); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Width); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Opacity); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Type"); + PropertyField(prop, "m_Color"); + PropertyField(prop, "m_ToColor"); + PropertyField(prop, "m_ToColor2"); + PropertyField(prop, "m_Width"); + PropertyField(prop, "m_Opacity"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_LineStyleToggle, prop)) - { - height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing; - } - else - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/LocationDrawer.cs b/Editor/PropertyDrawers/LocationDrawer.cs index b8819f2a..34e2027b 100644 --- a/Editor/PropertyDrawers/LocationDrawer.cs +++ b/Editor/PropertyDrawers/LocationDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,92 +11,21 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Location), true)] - public class LocationDrawer : PropertyDrawer + public class LocationDrawer : BasePropertyDrawer { + public override string ClassName { get { return "Location"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty align = prop.FindPropertyRelative("m_Align"); - SerializedProperty left = prop.FindPropertyRelative("m_Left"); - SerializedProperty right = prop.FindPropertyRelative("m_Right"); - SerializedProperty top = prop.FindPropertyRelative("m_Top"); - SerializedProperty bottom = prop.FindPropertyRelative("m_Bottom"); - EditorGUI.PropertyField(drawRect, align, new GUIContent("Location")); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, top); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, bottom); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, left); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, right); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // switch ((Location.Align)align.enumValueIndex) - // { - // case Location.Align.TopCenter: - // EditorGUI.PropertyField(drawRect, top); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // case Location.Align.TopLeft: - // EditorGUI.PropertyField(drawRect, top); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, left); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // case Location.Align.TopRight: - // EditorGUI.PropertyField(drawRect, top); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, right); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // case Location.Align.BottomCenter: - // EditorGUI.PropertyField(drawRect, bottom); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // case Location.Align.BottomLeft: - // EditorGUI.PropertyField(drawRect, bottom); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, left); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // case Location.Align.BottomRight: - // EditorGUI.PropertyField(drawRect, bottom); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // EditorGUI.PropertyField(drawRect, right); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // case Location.Align.Center: - // break; - // case Location.Align.CenterLeft: - // EditorGUI.PropertyField(drawRect, left); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // case Location.Align.CenterRight: - // EditorGUI.PropertyField(drawRect, right); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // break; - // } - --EditorGUI.indentLevel; - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; - // SerializedProperty align = prop.FindPropertyRelative("m_Align"); - // switch ((Location.Align)align.enumValueIndex) - // { - // case Location.Align.Center: - // return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - // case Location.Align.TopCenter: - // case Location.Align.BottomCenter: - // case Location.Align.CenterLeft: - // case Location.Align.CenterRight: - // return 2 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; - // default: - // return 3 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; - // } + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Align")) + { + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Top"); + PropertyField(prop, "m_Bottom"); + PropertyField(prop, "m_Left"); + PropertyField(prop, "m_Right"); + --EditorGUI.indentLevel; + } } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/PolarDrawer.cs b/Editor/PropertyDrawers/PolarDrawer.cs index 3be62a3c..4f721b62 100644 --- a/Editor/PropertyDrawers/PolarDrawer.cs +++ b/Editor/PropertyDrawers/PolarDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,39 +11,20 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Polar), true)] - public class PolarDrawer : PropertyDrawer + public class PolarDrawer : BasePropertyDrawer { - private bool m_PolarModuleToggle = false; - + public override string ClassName { get { return "Polar"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Center = prop.FindPropertyRelative("m_Center"); - SerializedProperty m_Radius = prop.FindPropertyRelative("m_Radius"); - SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_PolarModuleToggle, "Polar", show); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_PolarModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - EditorGUI.indentLevel++; - ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Center, "Center"); - EditorGUI.PropertyField(drawRect, m_Radius); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.indentLevel--; + ++EditorGUI.indentLevel; + PropertyTwoFiled(prop, "m_Center"); + PropertyField(prop, "m_Radius"); + PropertyField(prop, "m_BackgroundColor"); + --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (m_PolarModuleToggle) - return 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; - else - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/RadarDrawer.cs b/Editor/PropertyDrawers/RadarDrawer.cs index 26474946..a3dc5493 100644 --- a/Editor/PropertyDrawers/RadarDrawer.cs +++ b/Editor/PropertyDrawers/RadarDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,129 +12,46 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Radar), true)] - public class RadarDrawer : PropertyDrawer + public class RadarDrawer : BasePropertyDrawer { - SerializedProperty m_Shape; - SerializedProperty m_PositionType; - SerializedProperty m_Radius; - SerializedProperty m_SplitNumber; - SerializedProperty m_Center; - SerializedProperty m_SplitLine; - SerializedProperty m_SplitArea; - SerializedProperty m_Indicator; - SerializedProperty m_IndicatorGap; - SerializedProperty m_CeilRate; - SerializedProperty m_IndicatorList; - SerializedProperty m_IsAxisTooltip; - - private Dictionary m_RadarModuleToggle = new Dictionary(); - private Dictionary m_IndicatorToggle = new Dictionary(); - private bool m_IndicatorJsonAreaToggle = false; - private string m_IndicatorJsonAreaText; - private int m_IndicatorSize; - private int m_BackgroundColorSize; - - private void InitProperty(SerializedProperty prop) - { - m_Shape = prop.FindPropertyRelative("m_Shape"); - m_PositionType = prop.FindPropertyRelative("m_PositionType"); - m_Radius = prop.FindPropertyRelative("m_Radius"); - m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber"); - m_Center = prop.FindPropertyRelative("m_Center"); - m_SplitLine = prop.FindPropertyRelative("m_SplitLine"); - m_SplitArea = prop.FindPropertyRelative("m_SplitArea"); - m_Indicator = prop.FindPropertyRelative("m_Indicator"); - m_IndicatorGap = prop.FindPropertyRelative("m_IndicatorGap"); - m_CeilRate = prop.FindPropertyRelative("m_CeilRate"); - m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList"); - m_IsAxisTooltip = prop.FindPropertyRelative("m_IsAxisTooltip"); - } - + public override string ClassName { get { return "Radar"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - InitProperty(prop); - Rect drawRect = pos; - float defaultLabelWidth = EditorGUIUtility.labelWidth; - float defaultFieldWidth = EditorGUIUtility.fieldWidth; - drawRect.height = EditorGUIUtility.singleLineHeight; - int index = ChartEditorHelper.GetIndexFromPath(prop); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, prop, "Radar " + index, null, true); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - - EditorGUIUtility.labelWidth = defaultLabelWidth; - EditorGUIUtility.fieldWidth = defaultFieldWidth; - EditorGUI.PropertyField(drawRect, m_Shape); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_PositionType); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.LabelField(drawRect, "Center"); - var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15; - var tempWidth = (pos.width - startX + 35) / 2; - var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height); - var centerYRect = new Rect(centerXRect.x + tempWidth - 20, drawRect.y, tempWidth, drawRect.height); - while (m_Center.arraySize < 2) m_Center.arraySize++; - EditorGUI.PropertyField(centerXRect, m_Center.GetArrayElementAtIndex(0), GUIContent.none); - EditorGUI.PropertyField(centerYRect, m_Center.GetArrayElementAtIndex(1), GUIContent.none); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.PropertyField(drawRect, m_Radius); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SplitNumber); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_CeilRate); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_IsAxisTooltip); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.PropertyField(drawRect, m_SplitLine); - drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine); - EditorGUI.PropertyField(drawRect, m_SplitArea); - drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_IndicatorToggle, prop, "Indicators", m_Indicator, false); - ChartEditorHelper.MakeJsonData(ref drawRect, ref m_IndicatorJsonAreaToggle, ref m_IndicatorJsonAreaText, prop, pos.width, 20); - drawRect.width = pos.width; - drawRect.x = pos.x; - if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop)) - { - EditorGUI.PropertyField(drawRect, m_IndicatorGap); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - ChartEditorHelper.MakeList(ref drawRect, ref m_IndicatorSize, m_IndicatorList); - } + PropertyField(prop, "m_Shape"); + PropertyField(prop, "m_PositionType"); + PropertyTwoFiled(prop, "m_Center"); + PropertyField(prop, "m_Radius"); + PropertyField(prop, "m_SplitNumber"); + PropertyField(prop, "m_CeilRate"); + PropertyField(prop, "m_IsAxisTooltip"); + PropertyField(prop, "m_AxisLine"); + PropertyField(prop, "m_SplitLine"); + PropertyField(prop, "m_SplitArea"); + PropertyField(prop, "m_IndicatorList"); --EditorGUI.indentLevel; } } + } - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) + [CustomPropertyDrawer(typeof(Radar.Indicator), true)] + public class RadarIndicatorDrawer : BasePropertyDrawer + { + public override string ClassName { get { return "Indicator"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - int propNum = 1; - if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "")) { - propNum += 9; - if (m_IndicatorJsonAreaToggle) propNum += 4; - float height = propNum * EditorGUIUtility.singleLineHeight + (propNum - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitLine")); - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitArea")); - - if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop)) - { - m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList"); - height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing; - - for (int i = 0; i < m_IndicatorList.arraySize; i++) - { - height += EditorGUI.GetPropertyHeight(m_IndicatorList.GetArrayElementAtIndex(i)); - } - } - return height; - } - else - { - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Name"); + PropertyField(prop, "m_Min"); + PropertyField(prop, "m_Max"); + PropertyField(prop, "m_TextStyle"); + --EditorGUI.indentLevel; } } } diff --git a/Editor/PropertyDrawers/RadarIndicatorDrawer.cs b/Editor/PropertyDrawers/RadarIndicatorDrawer.cs deleted file mode 100644 index 3330775e..00000000 --- a/Editor/PropertyDrawers/RadarIndicatorDrawer.cs +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(Radar.Indicator), true)] - public class RadarIndicatorDrawer : PropertyDrawer - { - private Dictionary m_RadarModuleToggle = new Dictionary(); - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - SerializedProperty m_Name = prop.FindPropertyRelative("m_Name"); - SerializedProperty m_Max = prop.FindPropertyRelative("m_Max"); - SerializedProperty m_Min = prop.FindPropertyRelative("m_Min"); - SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle"); - Rect drawRect = pos; - float defaultLabelWidth = EditorGUIUtility.labelWidth; - float defaultFieldWidth = EditorGUIUtility.fieldWidth; - drawRect.height = EditorGUIUtility.singleLineHeight; - - int index = ChartEditorHelper.GetIndexFromPath(prop); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, prop, "Indicator " + index, m_Name, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop)) - { - ++EditorGUI.indentLevel; - - EditorGUI.PropertyField(drawRect, m_Name); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Min); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Max); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_TextStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle); - - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop)) - { - var height = 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle")); - return height; - } - else - { - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/RadarIndicatorDrawer.cs.meta b/Editor/PropertyDrawers/RadarIndicatorDrawer.cs.meta deleted file mode 100644 index 4b144235..00000000 --- a/Editor/PropertyDrawers/RadarIndicatorDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7fb5d2a98871919459956dc252632435 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/RadiusAxisDrawer.cs b/Editor/PropertyDrawers/RadiusAxisDrawer.cs deleted file mode 100644 index 3b86e7f6..00000000 --- a/Editor/PropertyDrawers/RadiusAxisDrawer.cs +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using UnityEditor; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(RadiusAxis), true)] - public class RadiusAxisDrawer : AxisDrawer - { - protected override string GetDisplayName(string displayName) - { - if (displayName.StartsWith("Element")) - { - displayName = displayName.Replace("Element", "Radius Axis"); - } - return displayName; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/RadiusAxisDrawer.cs.meta b/Editor/PropertyDrawers/RadiusAxisDrawer.cs.meta deleted file mode 100644 index 9d0b08e7..00000000 --- a/Editor/PropertyDrawers/RadiusAxisDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 433e6c679c39c4bf988a0447fd2e3775 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/SerieDrawer.cs b/Editor/PropertyDrawers/SerieDrawer.cs index c7cb36bc..685dd74d 100644 --- a/Editor/PropertyDrawers/SerieDrawer.cs +++ b/Editor/PropertyDrawers/SerieDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -18,6 +18,7 @@ namespace XCharts private List m_DataFoldout = new List(); private bool m_ShowJsonDataArea = false; private string m_JsonDataAreaText; + private bool m_IsPolar = false; public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { @@ -28,9 +29,12 @@ namespace XCharts SerializedProperty name = prop.FindPropertyRelative("m_Name"); SerializedProperty stack = prop.FindPropertyRelative("m_Stack"); SerializedProperty m_AxisIndex = prop.FindPropertyRelative("m_AxisIndex"); + SerializedProperty m_XAxisIndex = prop.FindPropertyRelative("m_XAxisIndex"); + SerializedProperty m_YAxisIndex = prop.FindPropertyRelative("m_YAxisIndex"); SerializedProperty m_RadarType = prop.FindPropertyRelative("m_RadarType"); SerializedProperty m_RadarIndex = prop.FindPropertyRelative("m_RadarIndex"); SerializedProperty m_VesselIndex = prop.FindPropertyRelative("m_VesselIndex"); + SerializedProperty m_PolarIndex = prop.FindPropertyRelative("m_PolarIndex"); SerializedProperty m_MinShow = prop.FindPropertyRelative("m_MinShow"); SerializedProperty m_MaxShow = prop.FindPropertyRelative("m_MaxShow"); SerializedProperty m_MaxCache = prop.FindPropertyRelative("m_MaxCache"); @@ -90,7 +94,7 @@ namespace XCharts var toggle = ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieModuleToggle, prop, moduleName, show); if (!toggle) { - var orderButton = 46; + var orderButton = 48; var gap = 4; drawRect.x += EditorGUIUtility.labelWidth + gap; drawRect.width = pos.width - drawRect.x + ChartEditorHelper.BOOL_WIDTH - orderButton; @@ -99,8 +103,9 @@ namespace XCharts } else { + var chart = prop.serializedObject.targetObject as BaseChart; + m_IsPolar = chart is PolarChart; var serieType = (SerieType)type.enumValueIndex; - ++EditorGUI.indentLevel; drawRect.x = pos.x; drawRect.width = pos.width; @@ -115,8 +120,18 @@ namespace XCharts case SerieType.Line: EditorGUI.PropertyField(drawRect, stack); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_AxisIndex); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + if (m_IsPolar) + { + EditorGUI.PropertyField(drawRect, m_PolarIndex); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } + else + { + EditorGUI.PropertyField(drawRect, m_XAxisIndex); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_YAxisIndex); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } EditorGUI.PropertyField(drawRect, m_MinShow); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_MaxShow); @@ -164,8 +179,18 @@ namespace XCharts case SerieType.Bar: EditorGUI.PropertyField(drawRect, stack); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_AxisIndex); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + if (m_IsPolar) + { + EditorGUI.PropertyField(drawRect, m_PolarIndex); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } + else + { + EditorGUI.PropertyField(drawRect, m_XAxisIndex); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_YAxisIndex); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } EditorGUI.PropertyField(drawRect, m_MinShow); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_MaxShow); @@ -352,27 +377,35 @@ namespace XCharts drawRect.y += EditorGUI.GetPropertyHeight(m_Animation); drawRect.width = EditorGUIUtility.labelWidth + 10; m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data"); - ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width); drawRect.width = pos.width; + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; if (m_DataFoldout[index]) { EditorGUI.indentLevel++; float nameWid = 45; #if UNITY_2019_3_OR_NEWER - var gap = 2; - var namegap = 3; + var gap = 2; + var namegap = 3; #else var gap = 0; var namegap = 0; #endif EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height), m_DataDimension); var nameRect = new Rect(pos.width - 2 * nameWid + 14 + gap, drawRect.y, nameWid - gap, pos.height); + if (XChartsSettings.editorBlockEnable) + { + nameRect.x += ChartEditorHelper.BLOCK_WIDTH; + } if (GUI.Button(nameRect, new GUIContent("Name"))) { m_ShowDataName.boolValue = !m_ShowDataName.boolValue; } var iconRect = new Rect(pos.width - nameWid + 14, drawRect.y, nameWid + namegap, pos.height); + if (XChartsSettings.editorBlockEnable) + { + iconRect.x += ChartEditorHelper.BLOCK_WIDTH; + } if (GUI.Button(iconRect, new GUIContent("More..."))) { m_ShowDataIcon.boolValue = !m_ShowDataIcon.boolValue; @@ -546,7 +579,7 @@ namespace XCharts switch (serieType) { case SerieType.Line: - height += 19 * EditorGUIUtility.singleLineHeight + 18 * EditorGUIUtility.standardVerticalSpacing; + height += 20 * EditorGUIUtility.singleLineHeight + 19 * EditorGUIUtility.standardVerticalSpacing; height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow")); @@ -557,7 +590,7 @@ namespace XCharts height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation")); break; case SerieType.Bar: - height += 21 * EditorGUIUtility.singleLineHeight + 20 * EditorGUIUtility.standardVerticalSpacing; + height += 22 * EditorGUIUtility.singleLineHeight + 21 * EditorGUIUtility.standardVerticalSpacing; height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis")); diff --git a/Editor/PropertyDrawers/SerieLabelDrawer.cs b/Editor/PropertyDrawers/SerieLabelDrawer.cs index f93a9aae..f9e9c34c 100644 --- a/Editor/PropertyDrawers/SerieLabelDrawer.cs +++ b/Editor/PropertyDrawers/SerieLabelDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,112 +12,37 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(SerieLabel), true)] - public class SerieLabelDrawer : PropertyDrawer + public class SerieLabelDrawer : BasePropertyDrawer { - private Dictionary m_SerieLabelToggle = new Dictionary(); - + public override string ClassName { get { return "Label"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Position = prop.FindPropertyRelative("m_Position"); - SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter"); - SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); - SerializedProperty m_Margin = prop.FindPropertyRelative("m_Margin"); - SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate"); - SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight"); - SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - SerializedProperty m_BackgroundWidth = prop.FindPropertyRelative("m_BackgroundWidth"); - SerializedProperty m_BackgroundHeight = prop.FindPropertyRelative("m_BackgroundHeight"); - SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); - SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); - SerializedProperty m_Line = prop.FindPropertyRelative("m_Line"); - SerializedProperty m_LineType = prop.FindPropertyRelative("m_LineType"); - SerializedProperty m_LineColor = prop.FindPropertyRelative("m_LineColor"); - SerializedProperty m_LineWidth = prop.FindPropertyRelative("m_LineWidth"); - SerializedProperty m_LineLength1 = prop.FindPropertyRelative("m_LineLength1"); - SerializedProperty m_LineLength2 = prop.FindPropertyRelative("m_LineLength2"); - SerializedProperty m_Border = prop.FindPropertyRelative("m_Border"); - SerializedProperty m_BorderWidth = prop.FindPropertyRelative("m_BorderWidth"); - SerializedProperty m_BorderColor = prop.FindPropertyRelative("m_BorderColor"); - SerializedProperty m_NumericFormatter = prop.FindPropertyRelative("m_NumericFormatter"); - SerializedProperty m_AutoOffset = prop.FindPropertyRelative("m_AutoOffset"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieLabelToggle, prop, null, show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_SerieLabelToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Position); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.PropertyField(drawRect, m_Offset); - drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); - - EditorGUI.PropertyField(drawRect, m_AutoOffset); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Margin); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Formatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_NumericFormatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundHeight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Rotate); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_PaddingLeftRight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_PaddingTopBottom); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontSize); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontStyle); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Border); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BorderWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BorderColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Line); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineType); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineLength1); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineLength2); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Position"); + PropertyField(prop, "m_Offset"); + PropertyField(prop, "m_AutoOffset"); + PropertyField(prop, "m_Margin"); + 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_Border"); + PropertyField(prop, "m_BorderWidth"); + PropertyField(prop, "m_BorderColor"); + PropertyField(prop, "m_Line"); + PropertyField(prop, "m_LineType"); + PropertyField(prop, "m_LineColor"); + PropertyField(prop, "m_LineWidth"); + PropertyField(prop, "m_LineLength1"); + PropertyField(prop, "m_LineLength2"); + PropertyField(prop, "m_TextStyle"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_SerieLabelToggle, prop)) - { - height += 24 * EditorGUIUtility.singleLineHeight + 23 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")); - } - else - { - height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/SerieSymbolDrawer.cs b/Editor/PropertyDrawers/SerieSymbolDrawer.cs index 557d211a..db7f3dde 100644 --- a/Editor/PropertyDrawers/SerieSymbolDrawer.cs +++ b/Editor/PropertyDrawers/SerieSymbolDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,92 +12,37 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(SerieSymbol), true)] - public class SerieSymbolDrawer : PropertyDrawer + public class SerieSymbolDrawer : BasePropertyDrawer { - private Dictionary m_SerieSymbolToggle = new Dictionary(); - + public override string ClassName { get { return "Symbol"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty m_Show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Type = prop.FindPropertyRelative("m_Type"); - SerializedProperty m_SizeType = prop.FindPropertyRelative("m_SizeType"); - SerializedProperty m_Size = prop.FindPropertyRelative("m_Size"); - SerializedProperty m_SelectedSize = prop.FindPropertyRelative("m_SelectedSize"); - SerializedProperty m_DataIndex = prop.FindPropertyRelative("m_DataIndex"); - SerializedProperty m_DataScale = prop.FindPropertyRelative("m_DataScale"); - SerializedProperty m_SelectedDataScale = prop.FindPropertyRelative("m_SelectedDataScale"); - SerializedProperty m_StartIndex = prop.FindPropertyRelative("m_StartIndex"); - SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval"); - SerializedProperty m_ForceShowLast = prop.FindPropertyRelative("m_ForceShowLast"); - SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieSymbolToggle, prop, null, m_Show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_SerieSymbolToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - - EditorGUI.PropertyField(drawRect, m_Type); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Gap); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SizeType); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - SerieSymbolSizeType sizeType = (SerieSymbolSizeType)m_SizeType.enumValueIndex; - switch (sizeType) + PropertyField(prop, "m_Type"); + PropertyField(prop, "m_Gap"); + PropertyField(prop, "m_SizeType"); + switch ((SerieSymbolSizeType)prop.FindPropertyRelative("m_SizeType").enumValueIndex) { case SerieSymbolSizeType.Custom: - EditorGUI.PropertyField(drawRect, m_Size); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SelectedSize); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_Size"); + PropertyField(prop, "m_SelectedSize"); break; case SerieSymbolSizeType.FromData: - EditorGUI.PropertyField(drawRect, m_DataIndex); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_DataScale); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SelectedDataScale); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_DataIndex"); + PropertyField(prop, "m_DataScale"); + PropertyField(prop, "m_SelectedDataScale"); break; case SerieSymbolSizeType.Callback: break; } - EditorGUI.PropertyField(drawRect, m_StartIndex); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Interval); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ForceShowLast); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_StartIndex"); + PropertyField(prop, "m_Interval"); + PropertyField(prop, "m_ForceShowLast"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (ChartEditorHelper.IsToggle(m_SerieSymbolToggle, prop)) - { - SerializedProperty m_SizeType = prop.FindPropertyRelative("m_SizeType"); - SerieSymbolSizeType sizeType = (SerieSymbolSizeType)m_SizeType.enumValueIndex; - var hig = 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; - switch (sizeType) - { - case SerieSymbolSizeType.Custom: - break; - case SerieSymbolSizeType.FromData: - hig += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - break; - case SerieSymbolSizeType.Callback: - break; - } - return hig; - } - else - { - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/SeriesDrawer.cs b/Editor/PropertyDrawers/SeriesDrawer.cs index b871fab0..c6acd9f5 100644 --- a/Editor/PropertyDrawers/SeriesDrawer.cs +++ b/Editor/PropertyDrawers/SeriesDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -43,7 +43,7 @@ namespace XCharts height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; for (int i = 0; i < m_Data.arraySize; i++) { - height += EditorGUI.GetPropertyHeight(m_Data.GetArrayElementAtIndex(i)); + height += EditorGUI.GetPropertyHeight(m_Data.GetArrayElementAtIndex(i)) + EditorGUIUtility.standardVerticalSpacing; } } if (m_ShowJsonDataArea) diff --git a/Editor/PropertyDrawers/SettingsDrawer.cs b/Editor/PropertyDrawers/SettingsDrawer.cs index b7c24aef..016492be 100644 --- a/Editor/PropertyDrawers/SettingsDrawer.cs +++ b/Editor/PropertyDrawers/SettingsDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,54 +11,30 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Settings), true)] - public class SettingsDrawer : PropertyDrawer + public class SettingsDrawer : BasePropertyDrawer { - private bool m_SettingsModuleToggle = false; - + public override string ClassName { get { return "Settings"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - - SerializedProperty m_LineSmoothStyle = prop.FindPropertyRelative("m_LineSmoothStyle"); - SerializedProperty m_LineSmoothness = prop.FindPropertyRelative("m_LineSmoothness"); - SerializedProperty m_LineSegmentDistance = prop.FindPropertyRelative("m_LineSegmentDistance"); - SerializedProperty m_CicleSmoothness = prop.FindPropertyRelative("m_CicleSmoothness"); - SerializedProperty m_VisualMapTriangeLen = prop.FindPropertyRelative("m_VisualMapTriangeLen"); - SerializedProperty m_PieTooltipExtraRadius = prop.FindPropertyRelative("m_PieTooltipExtraRadius"); - SerializedProperty m_PieSelectedOffset = prop.FindPropertyRelative("m_PieSelectedOffset"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SettingsModuleToggle, "Settings"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_SettingsModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "")) { + var btnWidth = 50; + var btnRect = new Rect(pos.x + pos.width - btnWidth, pos.y, btnWidth, EditorGUIUtility.singleLineHeight); + if (GUI.Button(btnRect, new GUIContent("Reset", "Reset to default settings"))) + { + var chart = prop.serializedObject.targetObject as BaseChart; + chart.settings.Reset(); + } ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_LineSmoothStyle); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineSmoothness); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineSegmentDistance); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_CicleSmoothness); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_VisualMapTriangeLen); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_PieTooltipExtraRadius); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_PieSelectedOffset); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_MaxPainter"); + PropertyField(prop, "m_LineSmoothStyle"); + PropertyField(prop, "m_LineSmoothness"); + PropertyField(prop, "m_LineSegmentDistance"); + PropertyField(prop, "m_CicleSmoothness"); + --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - int num = 1; - if (m_SettingsModuleToggle) - { - num = 8; - } - return num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/TextLimitDrawer.cs b/Editor/PropertyDrawers/TextLimitDrawer.cs index bfc52500..eebdc47f 100644 --- a/Editor/PropertyDrawers/TextLimitDrawer.cs +++ b/Editor/PropertyDrawers/TextLimitDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,42 +12,20 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(TextLimit), true)] - public class TextLimitDrawer : PropertyDrawer + public class TextLimitDrawer : BasePropertyDrawer { - private Dictionary m_TextLimitToggle = new Dictionary(); - + public override string ClassName { get { return "TextLimit"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable"); - SerializedProperty m_MaxWidth = prop.FindPropertyRelative("m_MaxWidth"); - SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap"); - SerializedProperty m_LimitSuffix = prop.FindPropertyRelative("m_Suffix"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextLimitToggle, prop, "Text Limit", m_Enable, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_TextLimitToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Enable")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_MaxWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Gap); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LimitSuffix); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyField(prop, "m_MaxWidth"); + PropertyField(prop, "m_Gap"); + PropertyField(prop, "m_LimitSuffix"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_TextLimitToggle, prop)) - { - height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/TextStyleDrawer.cs b/Editor/PropertyDrawers/TextStyleDrawer.cs index 1aa7831c..dfddb82f 100644 --- a/Editor/PropertyDrawers/TextStyleDrawer.cs +++ b/Editor/PropertyDrawers/TextStyleDrawer.cs @@ -1,71 +1,48 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System.Collections.Generic; using UnityEditor; using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif namespace XCharts { [CustomPropertyDrawer(typeof(TextStyle), true)] - public class TextStyleDrawer : PropertyDrawer + public class TextStyleDrawer : BasePropertyDrawer { - private Dictionary m_TextStyleToggle = new Dictionary(); - + public override string ClassName { get { return "TextStyle"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty m_Font = prop.FindPropertyRelative("m_Font"); - SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); - SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); - SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); - SerializedProperty m_LineSpacing = prop.FindPropertyRelative("m_LineSpacing"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, null,null,false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Font); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Rotate); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Offset); - drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontSize); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FontStyle); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineSpacing); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; +#if dUI_TextMeshPro + PropertyField(prop, "m_TMPFont"); +#else + PropertyField(prop, "m_Font"); +#endif + PropertyField(prop, "m_Rotate"); + PropertyField(prop, "m_Offset"); + PropertyField(prop, "m_Color"); + PropertyField(prop, "m_BackgroundColor"); + PropertyField(prop, "m_FontSize"); + PropertyField(prop, "m_LineSpacing"); +#if dUI_TextMeshPro + PropertyField(prop, "m_TMPFontStyle"); + PropertyField(prop, "m_TMPAlignment"); +#else + PropertyField(prop, "m_FontStyle"); + PropertyField(prop, "m_Alignment"); +#endif --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop)) - { - height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")); - } - else - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/ThemeDrawer.cs b/Editor/PropertyDrawers/ThemeDrawer.cs new file mode 100644 index 00000000..9f126b46 --- /dev/null +++ b/Editor/PropertyDrawers/ThemeDrawer.cs @@ -0,0 +1,182 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.IO; +using UnityEditor; +using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + [CustomPropertyDrawer(typeof(ChartTheme), true)] + public class ThemeDrawer : BasePropertyDrawer + { + private bool m_ThemeModuleToggle = false; + public override string ClassName { get { return "Theme"; } } + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + if (prop.objectReferenceValue == null) + { + EditorGUI.ObjectField(pos, prop, new GUIContent("Theme")); + return; + } + base.OnGUI(pos, prop, label); + var defaultWidth = pos.width; + var defaultX = pos.x; + var btnWidth = 45; + ChartEditorHelper.MakeFoldout(ref m_DrawRect, ref m_ThemeModuleToggle, "Theme"); + m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + if (m_ThemeModuleToggle) + { + m_DrawRect.x = defaultX + defaultWidth - 2 * btnWidth - 2; + m_DrawRect.width = btnWidth; + var chart = prop.serializedObject.targetObject as BaseChart; + var lastFont = chart.theme.font; +#if dUI_TextMeshPro + var lastTMPFont = chart.theme.tmpFont; +#endif + if (GUI.Button(m_DrawRect, new GUIContent("Reset", "Reset to theme default color"))) + { + chart.theme.ResetTheme(); + chart.RefreshAllComponent(); + } + m_DrawRect.x = defaultX + defaultWidth - btnWidth; + m_DrawRect.width = btnWidth; + if (GUI.Button(m_DrawRect, new GUIContent("Export", "Export theme to asset for a new theme"))) + { + ExportThemeWindow.target = chart; + EditorWindow.GetWindow(typeof(ExportThemeWindow)); + } + + var data = (ScriptableObject)prop.objectReferenceValue; + SerializedObject serializedObject = new SerializedObject(data); + SerializedProperty newProp = serializedObject.GetIterator(); + float y = pos.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + ++EditorGUI.indentLevel; + + var chartNameList = XChartsMgr.GetAllThemeNames(); + var lastIndex = chartNameList.IndexOf(chart.theme.themeName); + var selectedIndex = EditorGUI.Popup(new Rect(pos.x, y, pos.width, EditorGUIUtility.singleLineHeight), + "Theme", lastIndex, chartNameList.ToArray()); + m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + if (lastIndex != selectedIndex) + { + GUI.changed = true; + XChartsMgr.SwitchTheme(chart, chartNameList[selectedIndex]); + } + if (newProp.NextVisible(true)) + { + do + { + if (newProp.name == "m_Script") continue; + if (newProp.name == "m_ThemeName") continue; + if (newProp.name == "m_Theme") continue; + AddPropertyField(pos, newProp, ref y); + } while (newProp.NextVisible(false)); + } + if (GUI.changed) + { + chart.RefreshAllComponent(); + serializedObject.ApplyModifiedProperties(); + } + if (chart.theme.font != lastFont) + { + chart.theme.SyncFontToSubComponent(); + } +#if dUI_TextMeshPro + if (chart.theme.tmpFont != lastTMPFont) + { + chart.theme.SyncTMPFontToSubComponent(); + } +#endif + --EditorGUI.indentLevel; + } + } + + private void AddPropertyField(Rect pos, SerializedProperty prop, ref float y) + { + float height = EditorGUI.GetPropertyHeight(prop, new GUIContent(prop.displayName), true); + EditorGUI.PropertyField(new Rect(pos.x, y, pos.width, height), prop, true); + y += height + EditorGUIUtility.standardVerticalSpacing; + m_Heights[m_KeyName] += height + EditorGUIUtility.standardVerticalSpacing; + } + } + + public class ExportThemeWindow : EditorWindow + { + public static BaseChart target; + private static ExportThemeWindow window; + private string m_ChartName; + static void Init() + { + window = (ExportThemeWindow)EditorWindow.GetWindow(typeof(ExportThemeWindow), false, "Export Theme", true); + window.minSize = new Vector2(600, 50); + window.maxSize = new Vector2(600, 50); + window.Show(); + } + + void OnInspectorUpdate() + { + Repaint(); + } + + private void OnGUI() + { + if (target == null) + { + Close(); + return; + } + GUILayout.Space(10); + GUILayout.Label("Input a new name for theme:"); + m_ChartName = GUILayout.TextField(m_ChartName); + + GUILayout.Space(10); + GUILayout.Label("Export path:"); + if (string.IsNullOrEmpty(m_ChartName)) + { + GUILayout.Label("Need input a new name."); + } + else + { + GUILayout.Label(XChartsMgr.GetThemeAssetPath(m_ChartName)); + } + + GUILayout.Space(20); + if (GUILayout.Button("Export")) + { + if (string.IsNullOrEmpty(m_ChartName)) + { + ShowNotification(new GUIContent("ERROR:Need input a new name!")); + } + else if (XChartsMgr.ContainsTheme(m_ChartName)) + { + ShowNotification(new GUIContent("ERROR:The name you entered is already in use!")); + } + else if (IsAssetsExist(XChartsMgr.GetThemeAssetPath(m_ChartName))) + { + ShowNotification(new GUIContent("ERROR:The asset is exist! \npath=" + + XChartsMgr.GetThemeAssetPath(m_ChartName)), 5); + } + else + { + XChartsMgr.ExportTheme(target.theme, m_ChartName); + ShowNotification(new GUIContent("SUCCESS:The theme is exported. \npath=" + + XChartsMgr.GetThemeAssetPath(m_ChartName)), 5); + } + } + } + + private bool IsAssetsExist(string path) + { + return File.Exists(Application.dataPath + "/../" + path); + } + } +} \ No newline at end of file diff --git a/Editor/PropertyDrawers/AxisNameDrawer.cs.meta b/Editor/PropertyDrawers/ThemeDrawer.cs.meta similarity index 83% rename from Editor/PropertyDrawers/AxisNameDrawer.cs.meta rename to Editor/PropertyDrawers/ThemeDrawer.cs.meta index 128a0c95..107eab6b 100644 --- a/Editor/PropertyDrawers/AxisNameDrawer.cs.meta +++ b/Editor/PropertyDrawers/ThemeDrawer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 93f4873273d9c4d76bd651c8d774637f +guid: 704e7c2793bca4050821c6e0756c8316 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/PropertyDrawers/ThemeInfoDrawer.cs b/Editor/PropertyDrawers/ThemeInfoDrawer.cs deleted file mode 100644 index a96a69b9..00000000 --- a/Editor/PropertyDrawers/ThemeInfoDrawer.cs +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using UnityEditor; -using UnityEditorInternal; -using UnityEngine; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(ThemeInfo), true)] - public class ThemeInfoDrawer : PropertyDrawer - { - ReorderableList m_ColorPaletteList; - bool m_ColorPaletteFoldout; - bool m_ThemeModuleToggle = false; - - public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) - { - Rect drawRect = pos; - var defaultWidth = drawRect.width; - var defaultX = drawRect.x; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty m_Theme = prop.FindPropertyRelative("m_Theme"); - SerializedProperty m_Font = prop.FindPropertyRelative("m_Font"); - SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - SerializedProperty m_TextColor = prop.FindPropertyRelative("m_TitleTextColor"); - SerializedProperty m_SubTextColor = prop.FindPropertyRelative("m_TitleSubTextColor"); - SerializedProperty m_LegendTextColor = prop.FindPropertyRelative("m_LegendTextColor"); - SerializedProperty m_LegendUnableColor = prop.FindPropertyRelative("m_LegendUnableColor"); - SerializedProperty m_AxisTextColor = prop.FindPropertyRelative("m_AxisTextColor"); - SerializedProperty m_AxisLineColor = prop.FindPropertyRelative("m_AxisLineColor"); - SerializedProperty m_AxisSplitLineColor = prop.FindPropertyRelative("m_AxisSplitLineColor"); - SerializedProperty m_TooltipBackgroundColor = prop.FindPropertyRelative("m_TooltipBackgroundColor"); - SerializedProperty m_TooltipFlagAreaColor = prop.FindPropertyRelative("m_TooltipFlagAreaColor"); - SerializedProperty m_TooltipTextColor = prop.FindPropertyRelative("m_TooltipTextColor"); - SerializedProperty m_TooltipLabelColor = prop.FindPropertyRelative("m_TooltipLabelColor"); - SerializedProperty m_TooltipLineColor = prop.FindPropertyRelative("m_TooltipLineColor"); - SerializedProperty m_DataZoomLineColor = prop.FindPropertyRelative("m_DataZoomLineColor"); - SerializedProperty m_DataZoomSelectedColor = prop.FindPropertyRelative("m_DataZoomSelectedColor"); - SerializedProperty m_DataZoomTextColor = prop.FindPropertyRelative("m_DataZoomTextColor"); - SerializedProperty m_VisualMapBackgroundColor = prop.FindPropertyRelative("m_VisualMapBackgroundColor"); - SerializedProperty m_VisualMapBorderColor = prop.FindPropertyRelative("m_VisualMapBorderColor"); - SerializedProperty m_ColorPalette = prop.FindPropertyRelative("m_ColorPalette"); - - SerializedProperty m_CustomFont = prop.FindPropertyRelative("m_CustomFont"); - SerializedProperty m_CustomBackgroundColor = prop.FindPropertyRelative("m_CustomBackgroundColor"); - SerializedProperty m_CustomTextColor = prop.FindPropertyRelative("m_CustomTitleTextColor"); - SerializedProperty m_CustomSubTextColor = prop.FindPropertyRelative("m_CustomTitleSubTextColor"); - SerializedProperty m_CustomLegendTextColor = prop.FindPropertyRelative("m_CustomLegendTextColor"); - SerializedProperty m_CustomLegendUnableColor = prop.FindPropertyRelative("m_CustomLegendUnableColor"); - SerializedProperty m_CustomAxisTextColor = prop.FindPropertyRelative("m_CustomAxisTextColor"); - SerializedProperty m_CustomAxisLineColor = prop.FindPropertyRelative("m_CustomAxisLineColor"); - SerializedProperty m_CustomAxisSplitLineColor = prop.FindPropertyRelative("m_CustomAxisSplitLineColor"); - SerializedProperty m_CustomTooltipBackgroundColor = prop.FindPropertyRelative("m_CustomTooltipBackgroundColor"); - SerializedProperty m_CustomTooltipFlagAreaColor = prop.FindPropertyRelative("m_CustomTooltipFlagAreaColor"); - SerializedProperty m_CustomTooltipTextColor = prop.FindPropertyRelative("m_CustomTooltipTextColor"); - SerializedProperty m_CustomTooltipLabelColor = prop.FindPropertyRelative("m_CustomTooltipLabelColor"); - SerializedProperty m_CustomTooltipLineColor = prop.FindPropertyRelative("m_CustomTooltipLineColor"); - SerializedProperty m_CustomDataZoomLineColor = prop.FindPropertyRelative("m_CustomDataZoomLineColor"); - SerializedProperty m_CustomDataZoomSelectedColor = prop.FindPropertyRelative("m_CustomDataZoomSelectedColor"); - SerializedProperty m_CustomDataZoomTextColor = prop.FindPropertyRelative("m_CustomDataZoomTextColor"); - SerializedProperty m_CustomVisualMapBackgroundColor = prop.FindPropertyRelative("m_CustomVisualMapBackgroundColor"); - SerializedProperty m_CustomVisualMapBorderColor = prop.FindPropertyRelative("m_CustomVisualMapBorderColor"); - SerializedProperty m_CustomColorPalette = prop.FindPropertyRelative("m_CustomColorPalette"); - - var btnWidth = 45; - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_ThemeModuleToggle, "Theme"); - drawRect.x += EditorGUIUtility.labelWidth + ChartEditorHelper.GAP_WIDTH; - drawRect.width = defaultWidth - EditorGUIUtility.labelWidth - ChartEditorHelper.GAP_WIDTH - - (m_ThemeModuleToggle ? btnWidth + 3 : 0); - EditorGUI.PropertyField(drawRect, m_Theme, GUIContent.none); - if (m_ThemeModuleToggle) - { - drawRect.x = defaultX + defaultWidth - btnWidth; - drawRect.width = btnWidth; - if (GUI.Button(drawRect, new GUIContent("Reset", "Reset to theme default color"))) - { - m_CustomFont.objectReferenceValue = null; - m_CustomBackgroundColor.colorValue = Color.clear; - m_CustomTextColor.colorValue = Color.clear; - m_CustomSubTextColor.colorValue = Color.clear; - m_CustomLegendTextColor.colorValue = Color.clear; - m_CustomLegendUnableColor.colorValue = Color.clear; - m_CustomAxisTextColor.colorValue = Color.clear; - m_CustomAxisLineColor.colorValue = Color.clear; - m_CustomAxisSplitLineColor.colorValue = Color.clear; - m_CustomTooltipBackgroundColor.colorValue = Color.clear; - m_CustomTooltipFlagAreaColor.colorValue = Color.clear; - m_CustomTooltipTextColor.colorValue = Color.clear; - m_CustomTooltipLabelColor.colorValue = Color.clear; - m_CustomTooltipLineColor.colorValue = Color.clear; - m_CustomDataZoomLineColor.colorValue = Color.clear; - m_CustomDataZoomSelectedColor.colorValue = Color.clear; - m_CustomDataZoomTextColor.colorValue = Color.clear; - m_CustomVisualMapBackgroundColor.colorValue = Color.clear; - m_CustomVisualMapBorderColor.colorValue = Color.clear; - for (int i = 0; i < m_CustomColorPalette.arraySize; i++) - { - m_CustomColorPalette.GetArrayElementAtIndex(i).colorValue = Color.clear; - } - - ThemeInfo defaultThemeInfo = ThemeInfo.Default; - switch (m_Theme.enumValueIndex) - { - case ((int)Theme.Default): defaultThemeInfo = ThemeInfo.Default; break; - case ((int)Theme.Light): defaultThemeInfo = ThemeInfo.Light; break; - case ((int)Theme.Dark): defaultThemeInfo = ThemeInfo.Dark; break; - } - m_Font.objectReferenceValue = defaultThemeInfo.font; - m_BackgroundColor.colorValue = defaultThemeInfo.backgroundColor; - m_TextColor.colorValue = defaultThemeInfo.titleTextColor; - m_SubTextColor.colorValue = defaultThemeInfo.titleSubTextColor; - m_LegendTextColor.colorValue = defaultThemeInfo.legendTextColor; - m_LegendUnableColor.colorValue = defaultThemeInfo.legendUnableColor; - m_AxisTextColor.colorValue = defaultThemeInfo.axisTextColor; - m_AxisLineColor.colorValue = defaultThemeInfo.axisLineColor; - m_AxisSplitLineColor.colorValue = defaultThemeInfo.axisSplitLineColor; - m_TooltipBackgroundColor.colorValue = defaultThemeInfo.tooltipBackgroundColor; - m_TooltipFlagAreaColor.colorValue = defaultThemeInfo.tooltipFlagAreaColor; - m_TooltipTextColor.colorValue = defaultThemeInfo.tooltipTextColor; - m_TooltipLabelColor.colorValue = defaultThemeInfo.tooltipLabelColor; - m_TooltipLineColor.colorValue = defaultThemeInfo.tooltipLineColor; - m_DataZoomLineColor.colorValue = defaultThemeInfo.dataZoomLineColor; - m_DataZoomSelectedColor.colorValue = defaultThemeInfo.dataZoomSelectedColor; - m_DataZoomTextColor.colorValue = defaultThemeInfo.dataZoomTextColor; - m_VisualMapBackgroundColor.colorValue = defaultThemeInfo.visualMapBackgroundColor; - m_VisualMapBorderColor.colorValue = defaultThemeInfo.visualMapBorderColor; - for (int i = 0; i < m_ColorPalette.arraySize; i++) - { - m_ColorPalette.GetArrayElementAtIndex(i).colorValue = defaultThemeInfo.GetColor(i); - } - } - - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - drawRect.x = defaultX; - drawRect.width = defaultWidth; - - ++EditorGUI.indentLevel; - EditorGUI.BeginChangeCheck(); - var font = m_CustomFont.objectReferenceValue != null ? m_CustomFont : m_Font; - EditorGUI.PropertyField(drawRect, font); - if (EditorGUI.EndChangeCheck()) - { - m_CustomFont.objectReferenceValue = font.objectReferenceValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - var color = m_CustomBackgroundColor.colorValue != Color.clear ? m_CustomBackgroundColor : m_BackgroundColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Background Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomBackgroundColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomTextColor.colorValue != Color.clear ? m_CustomTextColor : m_TextColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Title Text Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomTextColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomSubTextColor.colorValue != Color.clear ? m_CustomSubTextColor : m_SubTextColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Title SubText Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomSubTextColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomLegendTextColor.colorValue != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("LegendText Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomLegendTextColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomLegendUnableColor.colorValue != Color.clear ? m_CustomLegendUnableColor : m_LegendUnableColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("LegendUnable Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomLegendUnableColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomAxisTextColor.colorValue != Color.clear ? m_CustomAxisTextColor : m_AxisTextColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("AxisText Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomAxisTextColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomAxisLineColor.colorValue != Color.clear ? m_CustomAxisLineColor : m_AxisLineColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("AxisLine Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomAxisLineColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomAxisSplitLineColor.colorValue != Color.clear ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("AxisSplitLine Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomAxisSplitLineColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomTooltipBackgroundColor.colorValue != Color.clear ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Background Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomTooltipBackgroundColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomTooltipFlagAreaColor.colorValue != Color.clear ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip FlagArea Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomTooltipFlagAreaColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomTooltipTextColor.colorValue != Color.clear ? m_CustomTooltipTextColor : m_TooltipTextColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Text Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomTooltipTextColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomTooltipLabelColor.colorValue != Color.clear ? m_CustomTooltipLabelColor : m_TooltipLabelColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Label Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomTooltipLabelColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomTooltipLineColor.colorValue != Color.clear ? m_CustomTooltipLineColor : m_TooltipLineColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Line Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomTooltipLineColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomDataZoomLineColor.colorValue != Color.clear ? m_CustomDataZoomLineColor : m_DataZoomLineColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("DataZoom Line Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomDataZoomLineColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomDataZoomSelectedColor.colorValue != Color.clear ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("DataZoom Selected Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomDataZoomSelectedColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomDataZoomTextColor.colorValue != Color.clear ? m_CustomDataZoomTextColor : m_DataZoomTextColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("DataZoom Text Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomDataZoomTextColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomVisualMapBackgroundColor.colorValue != Color.clear ? m_CustomVisualMapBackgroundColor : m_VisualMapBackgroundColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("VisualMap Background Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomVisualMapBackgroundColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.BeginChangeCheck(); - color = m_CustomVisualMapBorderColor.colorValue != Color.clear ? m_CustomVisualMapBorderColor : m_VisualMapBorderColor; - EditorGUI.PropertyField(drawRect, color, new GUIContent("VisualMap Border Color")); - if (EditorGUI.EndChangeCheck()) - { - m_CustomVisualMapBorderColor.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - m_ColorPaletteFoldout = EditorGUI.Foldout(drawRect, m_ColorPaletteFoldout, "ColorPalette"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_ColorPaletteFoldout) - { - EditorGUI.indentLevel++; - for (int i = 0; i < m_ColorPalette.arraySize; i++) - { - while (i > m_CustomColorPalette.arraySize - 1) - { - m_CustomColorPalette.arraySize++; - } - var customElement = m_CustomColorPalette.GetArrayElementAtIndex(i); - color = !ChartHelper.IsClearColor(customElement.colorValue) ? - customElement : - m_ColorPalette.GetArrayElementAtIndex(i); - EditorGUI.BeginChangeCheck(); - EditorGUI.PropertyField(drawRect, color); - if (EditorGUI.EndChangeCheck()) - { - customElement.colorValue = color.colorValue; - } - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - EditorGUI.indentLevel--; - } - - --EditorGUI.indentLevel; - } - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (!m_ThemeModuleToggle) - { - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } - else - { - float height = 0; - int propertyCount = 20; - if (m_ColorPaletteFoldout) - { - SerializedProperty m_ColorPalette = prop.FindPropertyRelative("m_ColorPalette"); - propertyCount += m_ColorPalette.arraySize + 1; - } - else - { - propertyCount += 1; - } - height += propertyCount * EditorGUIUtility.singleLineHeight + (propertyCount - 1) * EditorGUIUtility.standardVerticalSpacing; - return height; - } - - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/ThemeInfoDrawer.cs.meta b/Editor/PropertyDrawers/ThemeInfoDrawer.cs.meta deleted file mode 100644 index bcc58b44..00000000 --- a/Editor/PropertyDrawers/ThemeInfoDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bcac1baa719179549b24d7056f7e0cb5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/TitleDrawer.cs b/Editor/PropertyDrawers/TitleDrawer.cs index 0b774860..ae48e56e 100644 --- a/Editor/PropertyDrawers/TitleDrawer.cs +++ b/Editor/PropertyDrawers/TitleDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,55 +11,23 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Title), true)] - public class TitleDrawer : PropertyDrawer + public class TitleDrawer : BasePropertyDrawer { - private bool m_TitleModuleToggle = false; - + public override string ClassName { get { return "Title"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty text = prop.FindPropertyRelative("m_Text"); - SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle"); - SerializedProperty subText = prop.FindPropertyRelative("m_SubText"); - SerializedProperty m_SubTextStyle = prop.FindPropertyRelative("m_SubTextStyle"); - SerializedProperty m_ItemGap = prop.FindPropertyRelative("m_ItemGap"); - SerializedProperty location = prop.FindPropertyRelative("m_Location"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TitleModuleToggle, "Title", show); - ++EditorGUI.indentLevel; - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_TitleModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - EditorGUI.PropertyField(drawRect, text); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, subText); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap")); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, location); - drawRect.y += EditorGUI.GetPropertyHeight(location); - EditorGUI.PropertyField(drawRect, m_TextStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle); - EditorGUI.PropertyField(drawRect, m_SubTextStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle); + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Text"); + PropertyField(prop, "m_SubText"); + PropertyField(prop, "m_ItemGap"); + PropertyField(prop, "m_Location"); + PropertyField(prop, "m_TextStyle"); + PropertyField(prop, "m_SubTextStyle"); + --EditorGUI.indentLevel; } - --EditorGUI.indentLevel; - } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (m_TitleModuleToggle) - { - height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle")); - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SubTextStyle")); - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Location")); - } - height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - return height; } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/TitleStyleDrawer.cs b/Editor/PropertyDrawers/TitleStyleDrawer.cs index 28cedfa9..43af13d3 100644 --- a/Editor/PropertyDrawers/TitleStyleDrawer.cs +++ b/Editor/PropertyDrawers/TitleStyleDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEditor; @@ -12,40 +12,18 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(TitleStyle), true)] - public class TitleStyleDrawer : PropertyDrawer + public class TitleStyleDrawer : BasePropertyDrawer { - private Dictionary m_TitleStyleToggle = new Dictionary(); - + public override string ClassName { get { return "TitleStyle"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle"); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TitleStyleToggle, prop, "Title Style", show, false); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (ChartEditorHelper.IsToggle(m_TitleStyleToggle, prop)) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_TextStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle); + PropertyField(prop, "m_TextStyle"); --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - if (ChartEditorHelper.IsToggle(m_TitleStyleToggle, prop)) - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle")); - } - else - { - height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - } - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/TooltipDrawer.cs b/Editor/PropertyDrawers/TooltipDrawer.cs index 3b440467..f93ca84f 100644 --- a/Editor/PropertyDrawers/TooltipDrawer.cs +++ b/Editor/PropertyDrawers/TooltipDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,82 +11,33 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Tooltip), true)] - public class TooltipDrawer : PropertyDrawer + public class TooltipDrawer : BasePropertyDrawer { - private bool m_TooltipModuleToggle = false; - + public override string ClassName { get { return "Tooltip"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty type = prop.FindPropertyRelative("m_Type"); - SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter"); - SerializedProperty m_TitleFormatter = prop.FindPropertyRelative("m_TitleFormatter"); - SerializedProperty m_ItemFormatter = prop.FindPropertyRelative("m_ItemFormatter"); - SerializedProperty m_FixedWidth = prop.FindPropertyRelative("m_FixedWidth"); - SerializedProperty m_FixedHeight = prop.FindPropertyRelative("m_FixedHeight"); - SerializedProperty m_MinWidth = prop.FindPropertyRelative("m_MinWidth"); - SerializedProperty m_MinHeight = prop.FindPropertyRelative("m_MinHeight"); - SerializedProperty m_NumericFormatter = prop.FindPropertyRelative("m_NumericFormatter"); - SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight"); - SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom"); - SerializedProperty m_BackgroundImage = prop.FindPropertyRelative("m_BackgroundImage"); - SerializedProperty m_IgnoreDataDefaultContent = prop.FindPropertyRelative("m_IgnoreDataDefaultContent"); - SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle"); - SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle"); - SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_TooltipModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - EditorGUI.indentLevel++; - EditorGUI.PropertyField(drawRect, type); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Formatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_TitleFormatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ItemFormatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_NumericFormatter); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FixedWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_FixedHeight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_MinWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_MinHeight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_PaddingLeftRight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_PaddingTopBottom); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundImage); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_IgnoreDataDefaultContent); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Offset); - drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); - EditorGUI.PropertyField(drawRect, m_LineStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); - EditorGUI.PropertyField(drawRect, m_TextStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle); - EditorGUI.indentLevel--; + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Type"); + PropertyField(prop, "m_Formatter"); + PropertyField(prop, "m_TitleFormatter"); + PropertyField(prop, "m_ItemFormatter"); + PropertyField(prop, "m_NumericFormatter"); + PropertyField(prop, "m_FixedWidth"); + PropertyField(prop, "m_FixedHeight"); + PropertyField(prop, "m_MinWidth"); + PropertyField(prop, "m_MinHeight"); + PropertyField(prop, "m_PaddingLeftRight"); + PropertyField(prop, "m_PaddingTopBottom"); + PropertyField(prop, "m_BackgroundImage"); + PropertyField(prop, "m_IgnoreDataDefaultContent"); + PropertyField(prop, "m_Offset"); + PropertyField(prop, "m_LineStyle"); + PropertyField(prop, "m_TextStyle"); + --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (m_TooltipModuleToggle) - return 14 * EditorGUIUtility.singleLineHeight + 13 * EditorGUIUtility.standardVerticalSpacing + - EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")) + - EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")) + - EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle")); - else - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/VesselDrawer.cs b/Editor/PropertyDrawers/VesselDrawer.cs index 782c05de..c2bbdf48 100644 --- a/Editor/PropertyDrawers/VesselDrawer.cs +++ b/Editor/PropertyDrawers/VesselDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,58 +11,26 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(Vessel), true)] - public class VesselDrawer : PropertyDrawer + public class VesselDrawer : BasePropertyDrawer { - private bool m_VesselModuleToggle = false; - + public override string ClassName { get { return "Vessel"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_Shape = prop.FindPropertyRelative("m_Shape"); - SerializedProperty m_Center = prop.FindPropertyRelative("m_Center"); - SerializedProperty m_Radius = prop.FindPropertyRelative("m_Radius"); - SerializedProperty m_ShapeWidth = prop.FindPropertyRelative("m_ShapeWidth"); - SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap"); - SerializedProperty m_Smoothness = prop.FindPropertyRelative("m_Smoothness"); - SerializedProperty m_AutoColor = prop.FindPropertyRelative("m_AutoColor"); - SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); - SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); - - int index = ChartEditorHelper.GetIndexFromPath(prop); - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_VesselModuleToggle, "Vessel " + index, show); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_VesselModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Show")) { - EditorGUI.indentLevel++; - EditorGUI.PropertyField(drawRect, m_Shape); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ShapeWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Gap); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Center, "Center"); - EditorGUI.PropertyField(drawRect, m_Radius); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BackgroundColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Color); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_AutoColor); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Smoothness); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.indentLevel--; + ++EditorGUI.indentLevel; + PropertyField(prop, "m_Shape"); + PropertyField(prop, "m_ShapeWidth"); + PropertyField(prop, "m_Gap"); + PropertyTwoFiled(prop, "m_Center"); + PropertyField(prop, "m_Radius"); + PropertyField(prop, "m_BackgroundColor"); + PropertyField(prop, "m_Color"); + PropertyField(prop, "m_AutoColor"); + PropertyField(prop, "m_Smoothness"); + --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - if (m_VesselModuleToggle) - return 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; - else - return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/VisualMapDrawer.cs b/Editor/PropertyDrawers/VisualMapDrawer.cs index aee7ca82..d2110e9f 100644 --- a/Editor/PropertyDrawers/VisualMapDrawer.cs +++ b/Editor/PropertyDrawers/VisualMapDrawer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -11,140 +11,41 @@ using UnityEngine; namespace XCharts { [CustomPropertyDrawer(typeof(VisualMap), true)] - public class VisualMapDrawer : PropertyDrawer + public class VisualMapDrawer : BasePropertyDrawer { - private bool m_VisualMapModuleToggle = false; - private bool m_InRangeFoldout; - private bool m_OutOfRangeFoldout; - private int m_InRangeSize; - private int m_OutOfRangeSize; - + public override string ClassName { get { return "VisualMap"; } } public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { - Rect drawRect = pos; - drawRect.height = EditorGUIUtility.singleLineHeight; - SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable"); - SerializedProperty m_Type = prop.FindPropertyRelative("m_Type"); - SerializedProperty m_Show = prop.FindPropertyRelative("m_Show"); - SerializedProperty m_SelectedMode = prop.FindPropertyRelative("m_SelectedMode"); - SerializedProperty m_Min = prop.FindPropertyRelative("m_Min"); - SerializedProperty m_Max = prop.FindPropertyRelative("m_Max"); - SerializedProperty m_Range = prop.FindPropertyRelative("m_Range"); - SerializedProperty m_Text = prop.FindPropertyRelative("m_Text"); - // SerializedProperty m_TextGap = prop.FindPropertyRelative("m_TextGap"); - SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber"); - SerializedProperty m_Calculable = prop.FindPropertyRelative("m_Calculable"); - SerializedProperty m_ItemWidth = prop.FindPropertyRelative("m_ItemWidth"); - SerializedProperty m_ItemHeight = prop.FindPropertyRelative("m_ItemHeight"); - SerializedProperty m_BorderWidth = prop.FindPropertyRelative("m_BorderWidth"); - SerializedProperty m_Dimension = prop.FindPropertyRelative("m_Dimension"); - SerializedProperty m_HoverLink = prop.FindPropertyRelative("m_HoverLink"); - SerializedProperty m_Orient = prop.FindPropertyRelative("m_Orient"); - SerializedProperty m_Location = prop.FindPropertyRelative("m_Location"); - SerializedProperty m_InRange = prop.FindPropertyRelative("m_InRange"); - SerializedProperty m_AutoMinMax = prop.FindPropertyRelative("m_AutoMinMax"); - SerializedProperty m_Direction = prop.FindPropertyRelative("m_Direction"); - SerializedProperty m_OutOfRange = prop.FindPropertyRelative("m_OutOfRange"); - - ChartEditorHelper.MakeFoldout(ref drawRect, ref m_VisualMapModuleToggle, "Visual Map", m_Enable); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_VisualMapModuleToggle) + base.OnGUI(pos, prop, label); + if (MakeFoldout(prop, "m_Enable")) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Type); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Direction); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_AutoMinMax); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Min); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Max); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_SplitNumber); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Dimension); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - m_InRangeFoldout = EditorGUI.Foldout(drawRect, m_InRangeFoldout, "InRange"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_InRangeFoldout) + PropertyField(prop, "m_Type"); + PropertyField(prop, "m_Direction"); + PropertyField(prop, "m_AutoMinMax"); + PropertyField(prop, "m_Min"); + PropertyField(prop, "m_Max"); + PropertyField(prop, "m_SplitNumber"); + PropertyField(prop, "m_Dimension"); + PropertyField(prop, "m_InRange"); + PropertyField(prop, "m_OutOfRange"); + PropertyField(prop, "m_Show"); + if (prop.FindPropertyRelative("m_Show").boolValue) { - ChartEditorHelper.MakeList(ref drawRect, ref m_InRangeSize, m_InRange); - } - - // drawRect.width = pos.width; - m_OutOfRangeFoldout = EditorGUI.Foldout(drawRect, m_OutOfRangeFoldout, "OutOfRange"); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_OutOfRangeFoldout) - { - ChartEditorHelper.MakeList(ref drawRect, ref m_OutOfRangeSize, m_OutOfRange); - } - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.PropertyField(drawRect, m_Show); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - if (m_Show.boolValue) - { - EditorGUI.PropertyField(drawRect, m_SelectedMode); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Range, "Range"); - ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Text, "Text"); - ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Text, "TextGap"); - EditorGUI.PropertyField(drawRect, m_HoverLink); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Calculable); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ItemWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_ItemHeight); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_BorderWidth); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Orient); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Location); - drawRect.y += EditorGUI.GetPropertyHeight(m_Location); + PropertyField(prop, "m_SelectedMode"); + PropertyTwoFiled(prop, "m_Range"); + PropertyTwoFiled(prop, "m_Text"); + PropertyTwoFiled(prop, "m_TextGap"); + PropertyField(prop, "m_HoverLink"); + PropertyField(prop, "m_Calculable"); + PropertyField(prop, "m_ItemWidth"); + PropertyField(prop, "m_ItemHeight"); + PropertyField(prop, "m_BorderWidth"); + PropertyField(prop, "m_Orient"); + PropertyField(prop, "m_Location"); } --EditorGUI.indentLevel; } } - - public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) - { - float height = 0; - int num = 1; - if (m_VisualMapModuleToggle) - { - num += 10; - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - - if (m_InRangeFoldout) - { - SerializedProperty m_InRange = prop.FindPropertyRelative("m_InRange"); - int size = m_InRange.arraySize + 1; - height += size * EditorGUIUtility.singleLineHeight + (size - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUIUtility.standardVerticalSpacing; - } - if (m_OutOfRangeFoldout) - { - SerializedProperty m_OutOfRange = prop.FindPropertyRelative("m_OutOfRange"); - int size = m_OutOfRange.arraySize + 1; - height += size * EditorGUIUtility.singleLineHeight + (size - 1) * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUIUtility.standardVerticalSpacing; - } - if (prop.FindPropertyRelative("m_Show").boolValue) - { - height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Location")); - } - } - else - { - height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; - } - - return height; - } } } \ No newline at end of file diff --git a/Editor/PropertyDrawers/XAxisDrawer.cs b/Editor/PropertyDrawers/XAxisDrawer.cs deleted file mode 100644 index 13fb36c8..00000000 --- a/Editor/PropertyDrawers/XAxisDrawer.cs +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using UnityEditor; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(XAxis), true)] - public class XAxisDrawer : AxisDrawer - { - protected override string GetDisplayName(string displayName) - { - if (displayName.StartsWith("Element")) - { - displayName = displayName.Replace("Element", "X Axis"); - } - return displayName; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/XAxisDrawer.cs.meta b/Editor/PropertyDrawers/XAxisDrawer.cs.meta deleted file mode 100644 index 6ade3a91..00000000 --- a/Editor/PropertyDrawers/XAxisDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 723807bbaeaa64991a421011ce530266 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/PropertyDrawers/YAxisDrawer.cs b/Editor/PropertyDrawers/YAxisDrawer.cs deleted file mode 100644 index 861da12f..00000000 --- a/Editor/PropertyDrawers/YAxisDrawer.cs +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using UnityEditor; - -namespace XCharts -{ - [CustomPropertyDrawer(typeof(YAxis), true)] - public class YAxisDrawer : AxisDrawer - { - protected override string GetDisplayName(string displayName) - { - if (displayName.StartsWith("Element")) - { - displayName = displayName.Replace("Element", "Y Axis"); - } - return displayName; - } - } -} \ No newline at end of file diff --git a/Editor/PropertyDrawers/YAxisDrawer.cs.meta b/Editor/PropertyDrawers/YAxisDrawer.cs.meta deleted file mode 100644 index ae6c7483..00000000 --- a/Editor/PropertyDrawers/YAxisDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6d1fca6c98f3d41fd989d0e41fbd4eb9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/RadarChartEditor.cs b/Editor/RadarChartEditor.cs index 1cfe72eb..b08be0f1 100644 --- a/Editor/RadarChartEditor.cs +++ b/Editor/RadarChartEditor.cs @@ -16,20 +16,5 @@ namespace XCharts [CustomEditor(typeof(RadarChart), false)] public class RadarChartEditor : BaseChartEditor { - protected SerializedProperty m_Radar; - protected SerializedProperty m_Radars; - - protected override void OnEnable() - { - base.OnEnable(); - m_Target = (RadarChart)target; - m_Radars = serializedObject.FindProperty("m_Radars"); - } - - protected override void OnEndInspectorGUI() - { - EditorGUILayout.PropertyField(m_Radars, true); - base.OnEndInspectorGUI(); - } } } \ No newline at end of file diff --git a/Editor/RingChartEditor.cs b/Editor/RingChartEditor.cs index f480e370..cf054b61 100644 --- a/Editor/RingChartEditor.cs +++ b/Editor/RingChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -12,17 +12,13 @@ namespace XCharts /// /// Editor class used to edit UI RingChart. /// - [CustomEditor(typeof(RingChart), false)] public class RingChartEditor : BaseChartEditor { - protected SerializedProperty m_Radar; - protected SerializedProperty m_Radars; - protected override void OnEnable() { base.OnEnable(); - m_Target = (RingChart)target; + m_Chart = (RingChart)target; } } } \ No newline at end of file diff --git a/Editor/ScatterChartEditor.cs b/Editor/ScatterChartEditor.cs index 5c2da689..e6c0494b 100644 --- a/Editor/ScatterChartEditor.cs +++ b/Editor/ScatterChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; @@ -12,19 +12,13 @@ namespace XCharts /// /// Editor class used to edit UI ScatterChart. /// - [CustomEditor(typeof(ScatterChart), false)] public class ScatterChartEditor : CoordinateChartEditor { protected override void OnEnable() { base.OnEnable(); - m_Target = (ScatterChart)target; - } - - protected override void OnEndInspectorGUI() - { - base.OnEndInspectorGUI(); + m_Chart = (ScatterChart)target; } } } \ No newline at end of file diff --git a/Editor/Tools/UpgradeChartColor.cs b/Editor/Tools/UpgradeChartColor.cs deleted file mode 100644 index 3ca52184..00000000 --- a/Editor/Tools/UpgradeChartColor.cs +++ /dev/null @@ -1,377 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using System.IO; -using System.Text; -using UnityEditor; -using UnityEngine; - -namespace XCharts -{ - /// - /// 升级旧版本的颜色配置到1.6.0以上版本,参考[问答29](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XCharts问答.md)进行升级 - /// 导出:菜单栏->XCharts->ExportColorConfig - /// 导入:菜单栏->XCharts->ImportColorConfig - /// - public static class UpgradeChartColor - { - private const string CONFIG_PATH = "/colors.config"; // /Assets/ - - [MenuItem("XCharts/ExportColorConfig")] - /// - /// Export all the color configuration associated with drawing. - /// 导出所有图表的和绘制相关的颜色配置。保存在Assets目录下的colors.config文件里。 - /// - public static void ExportColorConfig() - { - Debug.Log("ExportColorConfig"); - var charts = Resources.FindObjectsOfTypeAll(typeof(BaseChart)); - var sb = new StringBuilder(); - foreach (var chart in charts) - { - if (chart is CoordinateChart) ExportCoordinateChart(sb, chart as CoordinateChart); - else if (chart is LiquidChart) ExportLiquidChart(sb, chart as LiquidChart); //如果这里编译失败,说明该版本不存在LiquidChart,可以整行注释掉。 - else if (chart is RadarChart) ExportRadarChart(sb, chart as RadarChart); - else ExportSeries(sb, chart as BaseChart); - sb.Append("\n"); - } - Debug.LogFormat("ExportColorConfig DONE: {0} charts.", charts.Length); - File.WriteAllText(Application.dataPath + CONFIG_PATH, sb.ToString()); - } - - [MenuItem("XCharts/ImportColorConfig")] - /// - /// 导入旧版本的颜色配置。 - /// - public static void ImportColorConfig() - { - Debug.Log("ImportColorConfig"); - var configPath = Application.dataPath + CONFIG_PATH; - if (!File.Exists(configPath)) - { - Debug.LogError("ImportColorConfig ERROR:can't found config:" + configPath); - return; - } - var charts = Resources.FindObjectsOfTypeAll(typeof(BaseChart)); - var chartDic = new Dictionary(); - foreach (var chart in charts) - { - chartDic[chart.GetInstanceID()] = chart as BaseChart; - } - var allLines = File.ReadAllLines(configPath); - var chartSet = new HashSet(); - foreach (var line in allLines) - { - if (string.IsNullOrEmpty(line)) continue; - var temp = line.Split('='); - var instanceId = int.Parse(temp[0]); - if (!chartDic.ContainsKey(instanceId)) - { - Debug.LogError("can't find chart:" + instanceId); - continue; - } - if (!chartSet.Contains(instanceId)) chartSet.Add(instanceId); - var chart = chartDic[instanceId]; - var colorList = ConvertToColorList(temp[2]); - var temp2 = temp[1].Split('_'); - var allType = temp[1]; - var strType = temp2[0]; - if (allType.Equals("visualMap")) ImportColorList((chart as CoordinateChart).visualMap.inRange, colorList); - else if (allType.Equals("xAxis0_splitArea")) ImportColorList((chart as CoordinateChart).xAxis0.splitArea.color, colorList); - else if (allType.Equals("xAxis1_splitArea")) ImportColorList((chart as CoordinateChart).xAxis1.splitArea.color, colorList); - else if (allType.Equals("yAxis0_splitArea")) ImportColorList((chart as CoordinateChart).yAxis0.splitArea.color, colorList); - else if (allType.Equals("yAxis1_splitArea")) ImportColorList((chart as CoordinateChart).yAxis1.splitArea.color, colorList); - else if (allType.Equals("xAxis0_splitLine")) (chart as CoordinateChart).xAxis0.splitLine.lineStyle.color = colorList[0]; - else if (allType.Equals("xAxis1_splitLine")) (chart as CoordinateChart).xAxis1.splitLine.lineStyle.color = colorList[0]; - else if (allType.Equals("yAxis0_splitLine")) (chart as CoordinateChart).yAxis0.splitLine.lineStyle.color = colorList[0]; - else if (allType.Equals("yAxis1_splitLine")) (chart as CoordinateChart).yAxis1.splitLine.lineStyle.color = colorList[0]; - else if (strType.Equals("vessel")) ImportVesselColor(chart, int.Parse(temp2[1]), colorList); //没有LiquidChart的版本该行可以注释掉。 - else if (strType.Equals("radarSplitLine")) ImportRadarSplitLineColor(chart, int.Parse(temp2[1]), colorList); - else if (strType.Equals("radarSplitArea")) ImportRadarSplitAreaColor(chart, int.Parse(temp2[1]), colorList); - else if (strType.Equals("serie")) - { - var index = int.Parse(temp2[1]); - var strSubType = temp2[2]; - var serie = chart.series.GetSerie(index); - if (strSubType.Equals("lineStyle")) serie.lineStyle.color = colorList[0]; - else if (strSubType.Equals("areaStyle")) ImportSerieAreaColor(serie.areaStyle, colorList); - else if (strSubType.Equals("label")) ImportLabelColor(serie.label, colorList); - else if (strSubType.Equals("labelEmphasis")) ImportLabelColor(serie.emphasis.label, colorList); - else if (strSubType.Equals("itemStyle")) ImportItemStyleColor(serie.itemStyle, colorList); - else if (strSubType.Equals("itemStyleEmphasis")) ImportItemStyleColor(serie.emphasis.itemStyle, colorList); - else if (strSubType.Equals("gaugeAxisLine")) ImportGaugeAxisLineColor(serie.gaugeAxis, colorList); - else if (strSubType.Equals("gaugeSplitLine")) serie.gaugeAxis.splitLine.lineStyle.color = colorList[0]; - else if (strSubType.Equals("gaugeAxisTick")) serie.gaugeAxis.axisTick.lineStyle.color = colorList[0]; - } - else if (strType.Equals("serieData")) - { - var index = int.Parse(temp2[1]); - var dataIndex = int.Parse(temp2[2]); - var strSubType = temp2[3]; - var serieData = chart.series.GetSerie(index).GetSerieData(dataIndex); - if (strSubType.Equals("label")) ImportLabelColor(serieData.label, colorList); - else if (strSubType.Equals("labelEmphasis")) ImportLabelColor(serieData.emphasis.label, colorList); - else if (strSubType.Equals("itemStyle")) ImportItemStyleColor(serieData.itemStyle, colorList); - else if (strSubType.Equals("itemStyleEmphasis")) ImportItemStyleColor(serieData.emphasis.itemStyle, colorList); - } - chart.RefreshChart(); - } - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - Debug.LogFormat("ImportColorConfig DONE: {0} charts.", chartSet.Count); - } - - private static void ExportCoordinateChart(StringBuilder sb, CoordinateChart chart) - { - var instanceId = chart.GetInstanceID(); - if (chart.visualMap.show) - { - AppendColor(sb, instanceId, "visualMap", chart.visualMap.inRange); - } - if (chart.xAxis0.show) - { - if (chart.xAxis0.splitArea.show) - AppendColor(sb, instanceId, "xAxis0_splitArea", chart.xAxis0.splitArea.color); - if (chart.xAxis0.splitLine.show) - AppendColor(sb, instanceId, "xAxis0_splitLine", chart.xAxis0.splitLine.lineStyle.color); - } - if (chart.xAxis1.show) - { - if (chart.xAxis1.splitArea.show) - AppendColor(sb, instanceId, "xAxis1_splitArea", chart.xAxis1.splitArea.color); - if (chart.xAxis1.splitLine.show) - AppendColor(sb, instanceId, "xAxis1_splitLine", chart.xAxis1.splitLine.lineStyle.color); - } - if (chart.yAxis0.show) - { - if (chart.yAxis0.splitArea.show) - AppendColor(sb, instanceId, "yAxis0_splitArea", chart.yAxis0.splitArea.color); - if (chart.yAxis0.splitLine.show) - AppendColor(sb, instanceId, "yAxis0_splitLine", chart.yAxis0.splitLine.lineStyle.color); - } - if (chart.yAxis1.show) - { - if (chart.yAxis1.splitArea.show) - AppendColor(sb, instanceId, "yAxis1_splitArea", chart.yAxis1.splitArea.color); - if (chart.yAxis1.splitLine.show) - AppendColor(sb, instanceId, "yAxis1_splitLine", chart.yAxis1.splitLine.lineStyle.color); - } - ExportSeries(sb, chart); - } - - /// - /// LiquidChart不在该版本时整个函数可以注释掉 - /// - private static void ExportLiquidChart(StringBuilder sb, LiquidChart chart) - { - var instanceId = chart.GetInstanceID(); - var key = "vessel_"; - for (int i = 0; i < chart.vessels.Count; i++) - { - var vessel = chart.vessels[i]; - AppendColor(sb, instanceId, key + i, vessel.color, vessel.backgroundColor); - } - ExportSeries(sb, chart); - } - - private static void ExportRadarChart(StringBuilder sb, RadarChart chart) - { - var instanceId = chart.GetInstanceID(); - for (int i = 0; i < chart.radars.Count; i++) - { - var radar = chart.radars[i]; - AppendColor(sb, instanceId, "radarSplitLine_" + i, radar.splitLine.lineStyle.color); - AppendColor(sb, instanceId, "radarSplitArea_" + i, radar.splitArea.color); - } - ExportSeries(sb, chart); - } - - private static void ExportSeries(StringBuilder sb, BaseChart chart) - { - var instanceId = chart.GetInstanceID(); - for (int i = 0; i < chart.series.list.Count; i++) - { - var serie = chart.series.GetSerie(i); - var key = "serie_" + i; - AppendColor(sb, instanceId, key + "_itemStyle", serie.itemStyle.color, serie.itemStyle.toColor, serie.itemStyle.toColor2, serie.itemStyle.backgroundColor, serie.itemStyle.borderColor); - AppendColor(sb, instanceId, key + "_label", serie.label.backgroundColor, serie.label.borderColor); - AppendColor(sb, instanceId, key + "_itemStyleEmphasis", serie.emphasis.itemStyle.color, serie.emphasis.itemStyle.toColor, serie.emphasis.itemStyle.toColor2, serie.emphasis.itemStyle.backgroundColor, serie.emphasis.itemStyle.borderColor); - AppendColor(sb, instanceId, key + "_labelEmphasis", serie.emphasis.label.backgroundColor, serie.emphasis.label.borderColor); - if (serie.type == SerieType.Line) - { - AppendColor(sb, instanceId, key + "_lineStyle", serie.lineStyle.color); - AppendColor(sb, instanceId, key + "_areaStyle", serie.areaStyle.color, serie.areaStyle.toColor, serie.areaStyle.highlightColor, serie.areaStyle.highlightToColor); - } - if (serie.type == SerieType.Gauge) - { - var axisLineColors = new List(); - axisLineColors.Add(serie.gaugeAxis.axisLine.barColor); - axisLineColors.Add(serie.gaugeAxis.axisLine.barBackgroundColor); - for (int n = 0; n < serie.gaugeAxis.axisLine.stageColor.Count; n++) - { - axisLineColors.Add(serie.gaugeAxis.axisLine.stageColor[n].color); - } - AppendColor(sb, instanceId, key + "_gaugeAxisLine", axisLineColors); - AppendColor(sb, instanceId, key + "_gaugeSplitLine", serie.gaugeAxis.splitLine.lineStyle.color); - AppendColor(sb, instanceId, key + "_gaugeAxisTick", serie.gaugeAxis.axisTick.lineStyle.color); - } - for (int j = 0; j < serie.dataCount; j++) - { - key = string.Format("serieData_{0}_{1}", i, j); - var serieData = serie.GetSerieData(j); - if (serieData.enableItemStyle) - AppendColor(sb, instanceId, key + "_itemStyle", serieData.itemStyle.color, serieData.itemStyle.toColor, serieData.itemStyle.toColor2, serieData.itemStyle.backgroundColor, serieData.itemStyle.borderColor); - if (serieData.enableLabel) - AppendColor(sb, instanceId, key + "_label", serieData.label.backgroundColor, serieData.label.borderColor); - if (serieData.enableEmphasis) - AppendColor(sb, instanceId, key + "_itemStyleEmphasis", serieData.emphasis.itemStyle.color, serieData.emphasis.itemStyle.toColor, serieData.emphasis.itemStyle.toColor2, serieData.emphasis.itemStyle.backgroundColor, serieData.emphasis.itemStyle.borderColor); - if (serieData.enableEmphasis) - AppendColor(sb, instanceId, key + "_labelEmphasis", serieData.emphasis.label.backgroundColor, serieData.emphasis.label.borderColor); - } - } - } - - private static void ExportGague(GaugeAxis gauge, StringBuilder sb) - { - - } - - private static void AppendColor(StringBuilder sb, int instanceId, string key, List list) - { - if (list.Count <= 0) return; - sb.AppendFormat("{0}={1}=", instanceId, key); - for (int i = 0; i < list.Count; i++) - { - sb.AppendFormat("{0}|", GetColorRGBA(list[i])); - } - sb.Append("\n"); - } - - private static void AppendColor(StringBuilder sb, int instanceId, string key, params Color[] color) - { - sb.AppendFormat("{0}={1}=", instanceId, key); - for (int i = 0; i < color.Length; i++) - { - sb.AppendFormat("{0}|", GetColorRGBA(color[i])); - } - sb.Append("\n"); - } - - private static void AppendColor(StringBuilder sb, int instanceId, string key, List list) - { - if (list.Count <= 0) return; - sb.AppendFormat("{0}={1}=", instanceId, key); - for (int i = 0; i < list.Count; i++) - { - sb.AppendFormat("{0}|", GetColorRGBA(list[i])); - } - sb.Append("\n"); - } - - private static string GetColorRGBA(Color color) - { - Color32 color32 = color; - return string.Format("{0},{1},{2},{3}", color32.r, color32.g, color32.b, color32.a); - } - - private static List ConvertToColorList(string strInfo) - { - var temp = strInfo.Split('|'); - var list = new List(); - for (int i = 0; i < temp.Length; i++) - { - if (!string.IsNullOrEmpty(temp[i])) - { - var temp2 = temp[i].Split(','); - var r = byte.Parse(temp2[0]); - var g = byte.Parse(temp2[1]); - var b = byte.Parse(temp2[2]); - var a = byte.Parse(temp2[3]); - list.Add(new Color32(r, g, b, a)); - } - } - return list; - } - - private static void ImportColorList(List target, List colorList) - { - target.Clear(); - for (int i = 0; i < colorList.Count; i++) - { - target.Add(colorList[i]); - } - } - - private static void ImportColorList(List target, List colorList) - { - target.Clear(); - for (int i = 0; i < colorList.Count; i++) - { - target.Add(colorList[i]); - } - } - - private static void ImportSerieAreaColor(AreaStyle areaStyle, List colorList) - { - areaStyle.color = colorList[0]; - areaStyle.toColor = colorList[1]; - areaStyle.highlightColor = colorList[2]; - areaStyle.highlightToColor = colorList[3]; - } - - private static void ImportLabelColor(SerieLabel label, List colorList) - { - label.backgroundColor = colorList[0]; - label.borderColor = colorList[1]; - } - - private static void ImportItemStyleColor(ItemStyle itemStyle, List colorList) - { - itemStyle.color = colorList[0]; - itemStyle.toColor = colorList[1]; - itemStyle.toColor2 = colorList[2];//没有toColor2的版本可以注释掉改行 - itemStyle.backgroundColor = colorList[3]; - itemStyle.borderColor = colorList[4]; - } - - private static void ImportGaugeAxisLineColor(GaugeAxis gauge, List colorList) - { - gauge.axisLine.barColor = colorList[0]; - gauge.axisLine.barBackgroundColor = colorList[1]; - for (int i = 2; i < colorList.Count; i++) - { - gauge.axisLine.stageColor[i - 2].color = colorList[i]; - } - } - - /// - /// 没有LiquidChart的版本这个函数可以注释掉 - /// - /// - /// - /// - private static void ImportVesselColor(BaseChart chart, int index, List colorList) - { - var vessel = (chart as LiquidChart).GetVessel(index); - vessel.color = colorList[0]; - vessel.backgroundColor = colorList[1]; - } - - private static void ImportRadarSplitLineColor(BaseChart chart, int index, List colorList) - { - var radar = (chart as RadarChart).GetRadar(index); - radar.splitLine.lineStyle.color = colorList[0]; - } - - private static void ImportRadarSplitAreaColor(BaseChart chart, int index, List colorList) - { - var radar = (chart as RadarChart).GetRadar(index); - ImportColorList(radar.splitArea.color, colorList); - } - } -} \ No newline at end of file diff --git a/Editor/Tools/UpgradeChartColor.cs.meta b/Editor/Tools/UpgradeChartColor.cs.meta deleted file mode 100644 index 6490c9b9..00000000 --- a/Editor/Tools/UpgradeChartColor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0c7ad8674f7b24e82a92138976f5e969 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Utility/ChartEditorHelper.cs b/Editor/Utility/ChartEditorHelper.cs index 13b2822a..0f3835d9 100644 --- a/Editor/Utility/ChartEditorHelper.cs +++ b/Editor/Utility/ChartEditorHelper.cs @@ -1,6 +1,7 @@ using UnityEngine; using UnityEditor; using System.Collections.Generic; +using XCharts; public class ChartEditorHelper { @@ -8,7 +9,8 @@ public class ChartEditorHelper public const float INDENT_WIDTH = 15; public const float BOOL_WIDTH = 15; public const float ARROW_WIDTH = 20; - public const float GAP_WIDTH =2; + public const float BLOCK_WIDTH = 4; + public const float GAP_WIDTH = 2; #else public const float INDENT_WIDTH = 15; public const float BOOL_WIDTH = 15; @@ -119,7 +121,7 @@ public class ChartEditorHelper } public static bool MakeFoldout(ref Rect drawRect, ref bool moduleToggle, string content, - SerializedProperty prop = null, bool bold = true) + SerializedProperty prop = null, bool bold = false) { float defaultWidth = drawRect.width; float defaultX = drawRect.x; @@ -131,12 +133,49 @@ public class ChartEditorHelper return moduleToggle; } + public static bool MakeFoldout(ref Rect drawRect, Dictionary heights, Dictionary moduleToggle, + string key, string content, SerializedProperty prop, bool bold = false) + { + float defaultWidth = drawRect.width; + float defaultX = drawRect.x; + drawRect.width = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH; + moduleToggle[key] = EditorGUI.Foldout(drawRect, moduleToggle[key], content, bold ? foldoutStyle : EditorStyles.foldout); + if (prop != null) + { + if (prop.propertyType == SerializedPropertyType.Boolean) + { + MakeBool(drawRect, prop); + } + else + { + drawRect.x = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + ARROW_WIDTH; + drawRect.width = defaultWidth - drawRect.x + ARROW_WIDTH - 2; + if (XChartsSettings.editorBlockEnable) + { + drawRect.x += BLOCK_WIDTH; + } + + EditorGUI.PropertyField(drawRect, prop, GUIContent.none); + } + } + + drawRect.width = defaultWidth; + drawRect.x = defaultX; + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + heights[key] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + return moduleToggle[key]; + } + public static void MakeBool(Rect drawRect, SerializedProperty boolProp, int index = 0, string name = null) { float defaultWidth = drawRect.width; float defaultX = drawRect.x; float boolWidth = index * (BOOL_WIDTH + GAP_WIDTH); drawRect.x = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + ARROW_WIDTH + boolWidth; + if (XChartsSettings.editorBlockEnable) + { + drawRect.x += BLOCK_WIDTH; + } drawRect.width = (EditorGUI.indentLevel + 1) * BOOL_WIDTH + index * 110; if (boolProp != null) { @@ -152,8 +191,17 @@ public class ChartEditorHelper drawRect.x = defaultX; } + public static bool MakeFoldout(ref Rect drawRect, ref float height, ref Dictionary moduleToggle, SerializedProperty prop, + string moduleName, string showPropName, bool bold = false) + { + var flag = MakeFoldout(ref drawRect, ref moduleToggle, prop, moduleName, prop.FindPropertyRelative(showPropName), bold); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + return flag; + } + public static bool MakeFoldout(ref Rect drawRect, ref Dictionary moduleToggle, SerializedProperty prop, - string moduleName, SerializedProperty showProp = null, bool bold = true) + string moduleName, SerializedProperty showProp = null, bool bold = false) { var key = prop.propertyPath; if (!moduleToggle.ContainsKey(key)) @@ -187,6 +235,10 @@ public class ChartEditorHelper { drawRect.width = defaultWidth - drawRect.x + ARROW_WIDTH - GAP_WIDTH; } + if (XChartsSettings.editorBlockEnable) + { + drawRect.x += BLOCK_WIDTH; + } EditorGUI.PropertyField(drawRect, showProp, GUIContent.none); } drawRect.width = defaultWidth; @@ -195,6 +247,12 @@ public class ChartEditorHelper } public static void MakeList(ref Rect drawRect, ref int listSize, SerializedProperty listProp, bool showOrder = false, bool showSize = true) + { + var height = 0f; + MakeList(ref drawRect, ref height, ref listSize, listProp, showOrder, showSize); + } + + public static void MakeList(ref Rect drawRect, ref float height, ref int listSize, SerializedProperty listProp, bool showOrder = false, bool showSize = true) { EditorGUI.indentLevel++; listSize = listProp.arraySize; @@ -202,13 +260,25 @@ public class ChartEditorHelper { if (showOrder) { - var nameWid = 15; + var nameWid = 18; var temp = INDENT_WIDTH + GAP_WIDTH; var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - nameWid - 1, drawRect.height); var iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height); + if (XChartsSettings.editorBlockEnable) + { + iconRect.x += BLOCK_WIDTH; + } if (GUI.Button(iconRect, new GUIContent("+", "add"))) { - listProp.arraySize++; + if (listProp.displayName.Equals("Series")) + { + AddSerieEditor.chart = listProp.serializedObject.targetObject as BaseChart; + AddSerieEditor.ShowWindow(); + } + else + { + listProp.arraySize++; + } } listSize = listProp.arraySize; listSize = EditorGUI.IntField(elementRect, "Size", listSize); @@ -219,6 +289,7 @@ public class ChartEditorHelper } if (listSize < 0) listSize = 0; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; if (listSize != listProp.arraySize) { @@ -235,14 +306,17 @@ public class ChartEditorHelper element = listProp.GetArrayElementAtIndex(i); EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i)); drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; + height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; } if (num >= 10) { EditorGUI.LabelField(drawRect, "..."); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; element = listProp.GetArrayElementAtIndex(listSize - 1); EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + (listSize - 1))); drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; + height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; } } else @@ -252,22 +326,34 @@ public class ChartEditorHelper SerializedProperty element = listProp.GetArrayElementAtIndex(i); if (showOrder) { - var nameWid = 15; + var nameWid = 18; var temp = INDENT_WIDTH + GAP_WIDTH; var isSerie = "Serie".Equals(element.type); var elementRect = isSerie ? drawRect : new Rect(drawRect.x, drawRect.y, drawRect.width - 2 * nameWid, drawRect.height); EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i)); var iconRect = new Rect(drawRect.width - 3 * nameWid + temp, drawRect.y, nameWid, drawRect.height); + if (XChartsSettings.editorBlockEnable) + { + iconRect.x += BLOCK_WIDTH; + } if (GUI.Button(iconRect, new GUIContent("↑", "up"))) { if (i > 0) listProp.MoveArrayElement(i, i - 1); } iconRect = new Rect(drawRect.width - 2 * nameWid + temp, drawRect.y, nameWid, drawRect.height); + if (XChartsSettings.editorBlockEnable) + { + iconRect.x += BLOCK_WIDTH; + } if (GUI.Button(iconRect, new GUIContent("↓", "down"))) { if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1); } iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height); + if (XChartsSettings.editorBlockEnable) + { + iconRect.x += BLOCK_WIDTH; + } if (GUI.Button(iconRect, new GUIContent("-", "delete"))) { if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i); @@ -275,52 +361,113 @@ public class ChartEditorHelper else { drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; + height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; } } else { EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i)); drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; + height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; } } } EditorGUI.indentLevel--; } - public static int InitModuleToggle(ref List moduleToggle, SerializedProperty prop) + public static void MakeList(ref int listSize, SerializedProperty listProp, bool showOrder = false, bool showSize = true) { - int index = 0; - var temp = prop.displayName.Split(' '); - if (temp == null || temp.Length < 2) + EditorGUI.indentLevel++; + listSize = listProp.arraySize; + if (showSize) { - index = 0; + if (showOrder) + { + EditorGUILayout.BeginHorizontal(); + listSize = EditorGUILayout.IntField("Size", listSize); + if (GUILayout.Button(new GUIContent("+", "add"), GUILayout.MinWidth(15), GUILayout.MaxWidth(15))) + { + listProp.arraySize++; + } + listSize = listProp.arraySize; + EditorGUILayout.EndHorizontal(); + } + else + { + listSize = EditorGUILayout.IntField("Size", listSize); + } + if (listSize < 0) listSize = 0; + if (listSize != listProp.arraySize) + { + while (listSize > listProp.arraySize) listProp.arraySize++; + while (listSize < listProp.arraySize) listProp.arraySize--; + } + } + if (listSize > 30) + { + SerializedProperty element; + int num = listSize > 10 ? 10 : listSize; + for (int i = 0; i < num; i++) + { + element = listProp.GetArrayElementAtIndex(i); + EditorGUILayout.PropertyField(element, true); + } + if (num >= 10) + { + EditorGUILayout.LabelField("..."); + element = listProp.GetArrayElementAtIndex(listSize - 1); + EditorGUILayout.PropertyField(element, true); + } } else { - int.TryParse(temp[1], out index); + for (int i = 0; i < listProp.arraySize; i++) + { + SerializedProperty element = listProp.GetArrayElementAtIndex(i); + if (showOrder) + { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(element, true); + if (GUILayout.Button(new GUIContent("↑", "up"), GUILayout.MinWidth(15), GUILayout.MaxWidth(15))) + { + if (i > 0) listProp.MoveArrayElement(i, i - 1); + } + if (GUILayout.Button(new GUIContent("↓", "down"), GUILayout.MinWidth(15), GUILayout.MaxWidth(15))) + { + if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1); + } + if (GUILayout.Button(new GUIContent("-", "delete"), GUILayout.MinWidth(15), GUILayout.MaxWidth(15))) + { + if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i); + } + EditorGUILayout.EndHorizontal(); + } + else + { + EditorGUILayout.PropertyField(element, true); + } + } } - if (index >= moduleToggle.Count) - { - moduleToggle.Add(false); - } - return index; + EditorGUI.indentLevel--; } - public static int GetIndexFromPath(SerializedProperty prop) + public static bool PropertyField(ref Rect drawRect, Dictionary heights, string key, SerializedProperty prop) { - int index = 0; - var sindex = prop.propertyPath.LastIndexOf('['); - var eindex = prop.propertyPath.LastIndexOf(']'); - if (sindex >= 0 && eindex >= 0) + if (prop == null) { - var str = prop.propertyPath.Substring(sindex + 1, eindex - sindex - 1); - int.TryParse(str, out index); + return false; } - return index; + EditorGUI.PropertyField(drawRect, prop, true); + var hig = EditorGUI.GetPropertyHeight(prop); + // var hig = prop.hasVisibleChildren + // ? EditorGUI.GetPropertyHeight(prop) + // : EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + drawRect.y += hig; + heights[key] += hig; + return true; } - - public static bool IsToggle(Dictionary toggle, SerializedProperty prop) + public static bool PropertyField(ref Rect drawRect, Dictionary heights, string key, SerializedProperty parentProp, string relativeName) { - return toggle.ContainsKey(prop.propertyPath) && toggle[prop.propertyPath] == true; + return PropertyField(ref drawRect, heights, key, parentProp.FindPropertyRelative(relativeName)); } } \ No newline at end of file diff --git a/Editor/Tools.meta b/Editor/Window.meta similarity index 77% rename from Editor/Tools.meta rename to Editor/Window.meta index 69765965..6e597abe 100644 --- a/Editor/Tools.meta +++ b/Editor/Window.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5f8c1764407aa478892ac9355ec71934 +guid: ac8865193d4f548d2aaf66163c4192d9 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Editor/Window/AddSerieEditor.cs b/Editor/Window/AddSerieEditor.cs new file mode 100644 index 00000000..08fe7bd8 --- /dev/null +++ b/Editor/Window/AddSerieEditor.cs @@ -0,0 +1,56 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace XCharts +{ + public class AddSerieEditor : EditorWindow + { + public static BaseChart chart; + private static AddSerieEditor window; + private SerieType serieType; + private string serieName; + + public static void ShowWindow() + { + window = GetWindow(); + window.titleContent = new GUIContent("Add Serie"); + window.minSize = new Vector2(350, window.minSize.y); + window.Focus(); + window.Show(); + } + + void OnInspectorUpdate() + { + Repaint(); + } + + private void OnGUI() + { + if (chart == null) + { + Close(); + return; + } + var iconRect = new Rect(5, 10, position.width - 10, EditorGUIUtility.singleLineHeight); + serieType = (SerieType)EditorGUI.EnumPopup(iconRect, "Serie Type", serieType); + iconRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + serieName = "serie" + (chart.series.Count + 1); + serieName = EditorGUI.TextField(iconRect, "Serie Name", serieName); + iconRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + GUILayout.Space(iconRect.y + 5); + if (GUILayout.Button("Add")) + { + SerieTemplate.AddDefaultSerie(chart, serieType, serieName); + chart.RefreshAllComponent(); + } + } + } +} \ No newline at end of file diff --git a/Editor/Window/AddSerieEditor.cs.meta b/Editor/Window/AddSerieEditor.cs.meta new file mode 100644 index 00000000..b7ae73c1 --- /dev/null +++ b/Editor/Window/AddSerieEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 450c3b4decd234f1894f1a8fd1161af8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CheckVersionEditor.cs b/Editor/Window/CheckVersionEditor.cs similarity index 62% rename from Editor/CheckVersionEditor.cs rename to Editor/Window/CheckVersionEditor.cs index 1769f053..4611b606 100644 --- a/Editor/CheckVersionEditor.cs +++ b/Editor/Window/CheckVersionEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -15,11 +15,11 @@ namespace XCharts private Vector2 scrollPos; private static CheckVersionEditor window; - [MenuItem("XCharts/Check For Update")] + [MenuItem("XCharts/Upgrade Check")] public static void ShowWindow() { window = GetWindow(); - window.titleContent = new GUIContent("XCharts Check For Update"); + window.titleContent = new GUIContent("XCharts Upgrade Check"); window.minSize = new Vector2(550, window.minSize.y); window.Show(); XChartsMgr.Instance.CheckVersion(); @@ -34,16 +34,16 @@ namespace XCharts { var mgr = XChartsMgr.Instance; GUILayout.Label(""); - GUILayout.Label("当前版本:" + mgr.nowVersion); + GUILayout.Label("The current version: " + mgr.nowVersion); if (mgr.needUpdate && !mgr.isCheck) { - GUILayout.Label("最新版本:" + mgr.newVersion); + GUILayout.Label("The latest version: " + mgr.newVersion); GUILayout.Label(""); - if (mgr.isCheck) GUILayout.Label("检测中..."); - else if (mgr.isNetworkError) GUILayout.Label("检测失败:" + mgr.networkError); + if (mgr.isCheck) GUILayout.Label("check ..."); + else if (mgr.isNetworkError) GUILayout.Label("check failed: " + mgr.networkError); else { - GUILayout.Label("有更新!"); + GUILayout.Label("There is a new version to upgrade!"); } GUILayout.Label(""); @@ -51,15 +51,15 @@ namespace XCharts { GUILayout.Label(mgr.desc); } - if (GUILayout.Button("去Github主页")) + if (GUILayout.Button("Github Homepage")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts"); } - if (GUILayout.Button("点Star支持")) + if (GUILayout.Button("Star Support")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/stargazers"); } - if (GUILayout.Button("问题反馈")) + if (GUILayout.Button("Issues")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/issues"); } @@ -72,33 +72,33 @@ namespace XCharts } else { - if (mgr.isCheck) GUILayout.Label("最新版本:检测中..."); - else if (mgr.isNetworkError) GUILayout.Label("检测失败:" + mgr.networkError); - else GUILayout.Label("最新版本:" + mgr.newVersion); + if (mgr.isCheck) GUILayout.Label("The latest version: checking ..."); + else if (mgr.isNetworkError) GUILayout.Label("check failed: " + mgr.networkError); + else GUILayout.Label("The latest version: " + mgr.newVersion); GUILayout.Label(""); if (!mgr.isNetworkError && !mgr.needUpdate && !mgr.isCheck) { - GUILayout.Label("已是最新版本!"); + GUILayout.Label("It is the latest version!"); } GUILayout.Label(""); if (!string.IsNullOrEmpty(mgr.desc)) { GUILayout.Label(mgr.desc); } - if (GUILayout.Button("去Github主页")) + if (GUILayout.Button("Github Homepage")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts"); } - if (GUILayout.Button("点Star支持")) + if (GUILayout.Button("Star Support")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/stargazers"); } - if (GUILayout.Button("问题反馈")) + if (GUILayout.Button("Issues")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/issues"); } - if (mgr.isNetworkError && GUILayout.Button("重新检测")) + if (mgr.isNetworkError && GUILayout.Button("Check Again")) { XChartsMgr.Instance.CheckVersion(); } diff --git a/Editor/CheckVersionEditor.cs.meta b/Editor/Window/CheckVersionEditor.cs.meta similarity index 83% rename from Editor/CheckVersionEditor.cs.meta rename to Editor/Window/CheckVersionEditor.cs.meta index aaf61b93..0fdb0d68 100644 --- a/Editor/CheckVersionEditor.cs.meta +++ b/Editor/Window/CheckVersionEditor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 98d1061c4167c4fff8ed25c3e8be8756 +guid: b2a04cd68c07645d9bb4234680c5200a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/XChartEditor.cs b/Editor/XChartEditor.cs index b3f967a2..a0e437bf 100644 --- a/Editor/XChartEditor.cs +++ b/Editor/XChartEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -12,7 +12,7 @@ using UnityEngine.EventSystems; namespace XCharts { - public class XChartEditor : EditorWindow + public class XChartEditor : Editor { private static Transform GetParent() { @@ -141,5 +141,23 @@ namespace XCharts { AddChart("LiquidChart"); } + + [MenuItem("XCharts/Themes Reload")] + public static void ReloadTheme() + { + XChartsMgr.Instance.LoadThemesFromResources(); + } + + [MenuItem("XCharts/TextMeshPro Enable")] + public static void EnableTextMeshPro() + { + XChartsMgr.EnableTextMeshPro(); + } + + [MenuItem("XCharts/TextMeshPro Disable")] + public static void DisableTextMeshPro() + { + XChartsMgr.DisableTextMeshPro(); + } } } \ No newline at end of file diff --git a/Editor/XChartMgrEditor.cs b/Editor/XChartMgrEditor.cs index 17be52e7..b08f9d82 100644 --- a/Editor/XChartMgrEditor.cs +++ b/Editor/XChartMgrEditor.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEditor; using UnityEngine; @@ -40,19 +40,19 @@ namespace XCharts serializedObject.Update(); EditorGUILayout.PropertyField(m_NowVersion); EditorGUILayout.PropertyField(m_NewVersion); - if (GUILayout.Button("检测更新")) + if (GUILayout.Button("Check Update")) { CheckVersionEditor.ShowWindow(); } - if (GUILayout.Button("去Github主页")) + if (GUILayout.Button("Github Homepage")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts"); } - if (GUILayout.Button("点Star支持")) + if (GUILayout.Button("Star Support")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/stargazers"); } - if (GUILayout.Button("问题反馈")) + if (GUILayout.Button("Issues")) { Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/issues"); } diff --git a/Editor/XCharts.Editor.asmdef b/Editor/XCharts.Editor.asmdef index 99bc30a0..d7c041af 100644 --- a/Editor/XCharts.Editor.asmdef +++ b/Editor/XCharts.Editor.asmdef @@ -1,9 +1,9 @@ { "name": "XCharts.Editor", "references": [ - "XCharts.Runtime" + "XCharts.Runtime", + "Unity.TextMeshPro" ], - "optionalUnityReferences": [], "includePlatforms": [ "Editor" ], @@ -12,5 +12,7 @@ "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, - "defineConstraints": [] + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false } \ No newline at end of file diff --git a/Editor/XChartsSettingsEditor.cs b/Editor/XChartsSettingsEditor.cs new file mode 100644 index 00000000..20262ea4 --- /dev/null +++ b/Editor/XChartsSettingsEditor.cs @@ -0,0 +1,69 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace XCharts +{ + [CustomEditor(typeof(XChartsSettings))] + public class XChartsSettingsEditor : Editor + { + internal class Styles + { + public static readonly GUIContent defaultFontAssetLabel = new GUIContent("Default Font Asset", "The Font Asset that will be assigned by default to newly created text objects when no Font Asset is specified."); + public static readonly GUIContent defaultFontAssetPathLabel = new GUIContent("Path: Resources/", "The relative path to a Resources folder where the Font Assets and Material Presets are located.\nExample \"Fonts & Materials/\""); + } + } + +#if UNITY_2018_3_OR_NEWER + class XChartsResourceImporterProvider : SettingsProvider + { + XChartsPackageResourceImporter m_ResourceImporter; + + public XChartsResourceImporterProvider() + : base("Project/XCharts", SettingsScope.Project) + { + } + + public override void OnGUI(string searchContext) + { + if (m_ResourceImporter == null) + m_ResourceImporter = new XChartsPackageResourceImporter(); + + m_ResourceImporter.OnGUI(); + } + + public override void OnDeactivate() + { + if (m_ResourceImporter != null) + m_ResourceImporter.OnDestroy(); + } + + static UnityEngine.Object GetSettings() + { + return Resources.Load("XChartsSettings"); + } + + [SettingsProviderGroup] + static SettingsProvider[] CreateXChartsSettingsProvider() + { + var providers = new List { new XChartsResourceImporterProvider() }; + + if (GetSettings() != null) + { + var provider = new AssetSettingsProvider("Project/XCharts/Settings", GetSettings); + provider.PopulateSearchKeywordsFromGUIContentProperties(); + providers.Add(provider); + } + + return providers.ToArray(); + } + } +#endif +} \ No newline at end of file diff --git a/Editor/XChartsSettingsEditor.cs.meta b/Editor/XChartsSettingsEditor.cs.meta new file mode 100644 index 00000000..953018f6 --- /dev/null +++ b/Editor/XChartsSettingsEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8353edb72702e4cdda6af0248101d2cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples/Runtime/Example00_CheatSheet.cs b/Examples/Runtime/Example00_CheatSheet.cs index 356c26a9..9db4a511 100644 --- a/Examples/Runtime/Example00_CheatSheet.cs +++ b/Examples/Runtime/Example00_CheatSheet.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections; using System.Collections.Generic; @@ -207,7 +207,6 @@ namespace XCharts.Examples chart.dataZoom.enable = true; chart.dataZoom.supportInside = true; chart.dataZoom.supportSlider = true; - chart.dataZoom.height = 30; chart.dataZoom.start = 0; chart.dataZoom.end = 100; @@ -279,7 +278,7 @@ namespace XCharts.Examples chart.visualMap.inRange.Clear(); foreach (var str in colors) { - chart.visualMap.inRange.Add(ThemeInfo.GetColor(str)); + chart.visualMap.inRange.Add(ChartTheme.GetColor(str)); } chart.grid.left = 80; chart.grid.bottom = 100; diff --git a/Examples/Runtime/Example01_UpdateData.cs b/Examples/Runtime/Example01_UpdateData.cs index 41139a51..2c53c1ac 100644 --- a/Examples/Runtime/Example01_UpdateData.cs +++ b/Examples/Runtime/Example01_UpdateData.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Examples/Runtime/Example02_ChartEvent.cs b/Examples/Runtime/Example02_ChartEvent.cs index c1e93af6..b739171b 100644 --- a/Examples/Runtime/Example02_ChartEvent.cs +++ b/Examples/Runtime/Example02_ChartEvent.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.EventSystems; diff --git a/Examples/Runtime/Example03_ChartAnimation.cs b/Examples/Runtime/Example03_ChartAnimation.cs index 0c261be3..f54f9091 100644 --- a/Examples/Runtime/Example03_ChartAnimation.cs +++ b/Examples/Runtime/Example03_ChartAnimation.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Examples/Runtime/Example10_LineChart.cs b/Examples/Runtime/Example10_LineChart.cs index 230f2d2d..38c994ff 100644 --- a/Examples/Runtime/Example10_LineChart.cs +++ b/Examples/Runtime/Example10_LineChart.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections; using UnityEngine; @@ -225,8 +225,8 @@ namespace XCharts.Examples chart.RefreshChart(); yield return new WaitForSeconds(1); - serie.label.color = Color.white; - serie.label.backgroundColor = Color.grey; + serie.label.textStyle.color = Color.white; + serie.label.textStyle.backgroundColor = Color.grey; chart.RefreshLabel(); chart.RefreshChart(); yield return new WaitForSeconds(1); diff --git a/Examples/Runtime/Example11_AddSinCurve.cs b/Examples/Runtime/Example11_AddSinCurve.cs index 344635f8..651c2eae 100644 --- a/Examples/Runtime/Example11_AddSinCurve.cs +++ b/Examples/Runtime/Example11_AddSinCurve.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -20,27 +20,26 @@ namespace XCharts.Examples void Awake() { chart = gameObject.GetComponent(); - if (chart != null) + if (chart == null) { - GameObject.DestroyImmediate(chart); + chart = gameObject.AddComponent(); } - chart = gameObject.AddComponent(); chart.title.show = true; chart.title.text = "Sin Curve"; chart.tooltip.show = true; chart.legend.show = false; - chart.xAxises[0].show = true; - chart.xAxises[1].show = false; - chart.yAxises[0].show = true; - chart.yAxises[1].show = false; + chart.xAxes[0].show = true; + chart.xAxes[1].show = false; + chart.yAxes[0].show = true; + chart.yAxes[1].show = false; - chart.xAxises[0].type = Axis.AxisType.Value; - chart.yAxises[0].type = Axis.AxisType.Value; + chart.xAxes[0].type = Axis.AxisType.Value; + chart.yAxes[0].type = Axis.AxisType.Value; - chart.xAxises[0].boundaryGap = false; - chart.xAxises[0].maxCache = 0; + chart.xAxes[0].boundaryGap = false; + chart.xAxes[0].maxCache = 0; chart.series.list[0].maxCache = 0; chart.RemoveData(); diff --git a/Examples/Runtime/Example12_CustomDrawing.cs b/Examples/Runtime/Example12_CustomDrawing.cs index e8c88e12..a99800a9 100644 --- a/Examples/Runtime/Example12_CustomDrawing.cs +++ b/Examples/Runtime/Example12_CustomDrawing.cs @@ -1,12 +1,13 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; +using XUGL; namespace XCharts.Examples @@ -27,11 +28,11 @@ namespace XCharts.Examples if (dataPoints.Count > 0) { var pos = dataPoints[3]; - var zeroPos = new Vector3(chart.coordinateX, chart.coordinateY); + var zeroPos = new Vector3(chart.grid.runtimeX, chart.grid.runtimeY); var startPos = new Vector3(pos.x, zeroPos.y); - var endPos = new Vector3(pos.x, zeroPos.y + chart.coordinateHeight); - ChartDrawer.DrawLine(vh, startPos, endPos, 1, Color.blue); - ChartDrawer.DrawCricle(vh, pos, 5, Color.blue); + var endPos = new Vector3(pos.x, zeroPos.y + chart.grid.runtimeWidth); + UGL.DrawLine(vh, startPos, endPos, 1, Color.blue); + UGL.DrawCricle(vh, pos, 5, Color.blue); } }; } diff --git a/Examples/Runtime/Example13_LineSimple.cs b/Examples/Runtime/Example13_LineSimple.cs index 95ceb6b4..b76eb79c 100644 --- a/Examples/Runtime/Example13_LineSimple.cs +++ b/Examples/Runtime/Example13_LineSimple.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -27,20 +27,20 @@ namespace XCharts.Examples chart.tooltip.show = true; chart.legend.show = false; - chart.xAxises[0].show = true; - chart.xAxises[1].show = false; - chart.yAxises[0].show = true; - chart.yAxises[1].show = false; - chart.xAxises[0].type = Axis.AxisType.Category; - chart.yAxises[0].type = Axis.AxisType.Value; + chart.xAxes[0].show = true; + chart.xAxes[1].show = false; + chart.yAxes[0].show = true; + chart.yAxes[1].show = false; + chart.xAxes[0].type = Axis.AxisType.Category; + chart.yAxes[0].type = Axis.AxisType.Value; - chart.xAxises[0].splitNumber = 10; - chart.xAxises[0].boundaryGap = true; + chart.xAxes[0].splitNumber = 10; + chart.xAxes[0].boundaryGap = true; chart.RemoveData(); chart.AddSerie(SerieType.Line); chart.AddSerie(SerieType.Line); - for (int i = 0; i < 10; i++) + for (int i = 0; i < 2000; i++) { chart.AddXAxisData("x" + i); chart.AddData(0, Random.Range(10, 20)); diff --git a/Examples/Runtime/Example20_BarChart.cs b/Examples/Runtime/Example20_BarChart.cs index a2c8f85c..38c139e7 100644 --- a/Examples/Runtime/Example20_BarChart.cs +++ b/Examples/Runtime/Example20_BarChart.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections; using UnityEngine; @@ -150,13 +150,13 @@ namespace XCharts.Examples serie.label.show = true; serie.label.position = SerieLabel.Position.Center; serie.label.border = false; - serie.label.color = Color.white; + serie.label.textStyle.color = Color.white; serie.label.formatter = "{d:f0}%"; serie2.label.show = true; serie2.label.position = SerieLabel.Position.Center; serie2.label.border = false; - serie2.label.color = Color.white; + serie2.label.textStyle.color = Color.white; serie2.label.formatter = "{d:f0}%"; chart.RefreshLabel(); diff --git a/Examples/Runtime/Example30_PieChart.cs b/Examples/Runtime/Example30_PieChart.cs index 2038b494..5e3774dc 100644 --- a/Examples/Runtime/Example30_PieChart.cs +++ b/Examples/Runtime/Example30_PieChart.cs @@ -1,12 +1,13 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections; using UnityEngine; +using UnityEngine.EventSystems; namespace XCharts.Examples { @@ -76,6 +77,10 @@ namespace XCharts.Examples chart.AddData(0, 135, "视频广告"); chart.AddData(0, 1548, "搜索引擎"); chart.RefreshLabel(); + + chart.onPointerClickPie = delegate(PointerEventData e, int serieIndex, int dataIndex){ + + }; yield return new WaitForSeconds(1); } @@ -148,8 +153,8 @@ namespace XCharts.Examples serie1.label.show = true; serie1.label.position = SerieLabel.Position.Inside; - serie1.label.color = Color.white; - serie1.label.fontSize = 14; + serie1.label.textStyle.color = Color.white; + serie1.label.textStyle.fontSize = 14; serie1.label.border = false; chart.RefreshLabel(); @@ -166,7 +171,7 @@ namespace XCharts.Examples serie1.radius = serie.radius = new float[2] { 0, 80 }; serie1.label.position = SerieLabel.Position.Outside; serie1.label.lineType = SerieLabel.LineType.Curves; - serie1.label.color = Color.clear; + serie1.label.textStyle.color = Color.clear; for (int i = 0; i < 2; i++) { chart.AddData(i, 10, "rose1"); diff --git a/Examples/Runtime/Example31_PieUpdateName.cs b/Examples/Runtime/Example31_PieUpdateName.cs index e8e49edc..2e0a5bac 100644 --- a/Examples/Runtime/Example31_PieUpdateName.cs +++ b/Examples/Runtime/Example31_PieUpdateName.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; diff --git a/Examples/Runtime/Example40_Radar.cs b/Examples/Runtime/Example40_Radar.cs index 45a023c0..e838efa9 100644 --- a/Examples/Runtime/Example40_Radar.cs +++ b/Examples/Runtime/Example40_Radar.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections; using System.Collections.Generic; diff --git a/Examples/Runtime/Example41_RadarUpdate.cs b/Examples/Runtime/Example41_RadarUpdate.cs index 5d86ade1..c6d9bd16 100644 --- a/Examples/Runtime/Example41_RadarUpdate.cs +++ b/Examples/Runtime/Example41_RadarUpdate.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; diff --git a/Examples/Runtime/Example50_Scatter.cs b/Examples/Runtime/Example50_Scatter.cs index ac5a2690..0cb57ed1 100644 --- a/Examples/Runtime/Example50_Scatter.cs +++ b/Examples/Runtime/Example50_Scatter.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; diff --git a/Examples/Runtime/Example60_Heatmap.cs b/Examples/Runtime/Example60_Heatmap.cs index 3f62f27d..8b64d8f3 100644 --- a/Examples/Runtime/Example60_Heatmap.cs +++ b/Examples/Runtime/Example60_Heatmap.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -29,14 +29,14 @@ namespace XCharts.Examples chart.grid.right = 60; chart.grid.bottom = 60; //目前只支持Category - chart.xAxises[0].type = Axis.AxisType.Category; - chart.yAxises[0].type = Axis.AxisType.Category; + chart.xAxes[0].type = Axis.AxisType.Category; + chart.yAxes[0].type = Axis.AxisType.Category; - chart.xAxises[0].boundaryGap = true; - chart.xAxises[0].boundaryGap = true; + chart.xAxes[0].boundaryGap = true; + chart.xAxes[0].boundaryGap = true; - chart.xAxises[0].splitNumber = 10; - chart.yAxises[0].splitNumber = 10; + chart.xAxes[0].splitNumber = 10; + chart.yAxes[0].splitNumber = 10; //清空数据重新添加 chart.RemoveData(); @@ -68,13 +68,13 @@ namespace XCharts.Examples chart.visualMap.inRange.Clear(); var heatmapGridWid = 10f; - int xSplitNumber = (int)(chart.coordinateWidth / heatmapGridWid); - int ySplitNumber = (int)(chart.coordinateHeight / heatmapGridWid); + int xSplitNumber = (int)(chart.grid.runtimeWidth / heatmapGridWid); + int ySplitNumber = (int)(chart.grid.runtimeHeight / heatmapGridWid); var colors = new List{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf", "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"}; foreach (var str in colors) { - chart.visualMap.inRange.Add(ThemeInfo.GetColor(str)); + chart.visualMap.inRange.Add(ChartTheme.GetColor(str)); } //添加xAxis的数据 for (int i = 0; i < xSplitNumber; i++) diff --git a/Examples/Runtime/Example70_Gauge.cs b/Examples/Runtime/Example70_Gauge.cs index c38a899c..bc32b80c 100644 --- a/Examples/Runtime/Example70_Gauge.cs +++ b/Examples/Runtime/Example70_Gauge.cs @@ -1,10 +1,10 @@ using System.Runtime.InteropServices; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -47,7 +47,7 @@ namespace XCharts.Examples serie.label.offset = new Vector3(0, -20); serie.gaugeAxis.show = true; - serie.gaugeAxis.axisLine.width = 15; + serie.gaugeAxis.axisLine.lineStyle.width = 15; serie.gaugePointer.show = true; serie.gaugePointer.width = 15; diff --git a/Examples/Runtime/Example80_Polar.cs b/Examples/Runtime/Example80_Polar.cs index e644786b..4e695d0c 100644 --- a/Examples/Runtime/Example80_Polar.cs +++ b/Examples/Runtime/Example80_Polar.cs @@ -1,10 +1,10 @@ using System.Runtime.InteropServices; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Examples/Runtime/Example_Dynamic.cs b/Examples/Runtime/Example_Dynamic.cs index 09b68a40..62c489a3 100644 --- a/Examples/Runtime/Example_Dynamic.cs +++ b/Examples/Runtime/Example_Dynamic.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -33,7 +33,7 @@ namespace XCharts.Examples var serie = chart.AddSerie(SerieType.Line); serie.symbol.show = false; serie.maxCache = maxCacheDataNumber; - chart.xAxises[0].maxCache = maxCacheDataNumber; + chart.xAxes[0].maxCache = maxCacheDataNumber; timeNow = DateTime.Now; timeNow = timeNow.AddSeconds(-maxCacheDataNumber); } diff --git a/Examples/Runtime/Example_LargeData.cs b/Examples/Runtime/Example_LargeData.cs index cbcf94fc..da10cf79 100644 --- a/Examples/Runtime/Example_LargeData.cs +++ b/Examples/Runtime/Example_LargeData.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Examples/Runtime/Example_PieChart.cs b/Examples/Runtime/Example_PieChart.cs index e122ead9..0b043eb7 100644 --- a/Examples/Runtime/Example_PieChart.cs +++ b/Examples/Runtime/Example_PieChart.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Examples/Runtime/Example_Test.cs b/Examples/Runtime/Example_Test.cs index 2f661449..39034abd 100644 --- a/Examples/Runtime/Example_Test.cs +++ b/Examples/Runtime/Example_Test.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; @@ -14,10 +14,10 @@ namespace XCharts.Examples [ExecuteInEditMode] public class Example_Test : MonoBehaviour { - BaseChart chart; + LineChart chart; void Awake() { - chart = gameObject.GetComponent(); + chart = gameObject.GetComponent(); var btnTrans = transform.parent.Find("Button"); if (btnTrans) { @@ -29,14 +29,16 @@ namespace XCharts.Examples { if (Input.GetKeyDown(KeyCode.Space)) { - AddData(); + //AddData(); + OnTestBtn(); } } void OnTestBtn() { - //chart.ClearData(); - chart.SetSize(800,400); + int index = Random.Range(0, chart.series.Count); + var serie = chart.series.GetSerie(index); + chart.UpdateData(index, Random.Range(0, serie.dataCount), Random.Range(50, 100)); } void AddData() diff --git a/Resources.meta b/Resources.meta new file mode 100644 index 00000000..f5614c78 --- /dev/null +++ b/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0e3168b99564b477a83640c24b713f0c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/XChartsSettings.asset b/Resources/XChartsSettings.asset new file mode 100644 index 00000000..0e5b7337 --- /dev/null +++ b/Resources/XChartsSettings.asset @@ -0,0 +1,48 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3694d869548264b718bdfc6c8009dcf1, type: 3} + m_Name: XChartsSettings + m_EditorClassIdentifier: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSizeLv1: 24 + m_FontSizeLv2: 22 + m_FontSizeLv3: 20 + m_FontSizeLv4: 18 + m_AxisLineType: 0 + m_AxisLineWidth: 0.8 + m_AxisSplitLineType: 0 + m_AxisSplitLineWidth: 0.8 + m_AxisTickWidth: 0.8 + m_AxisTickLength: 5 + m_GaugeAxisLineWidth: 15 + m_GaugeAxisSplitLineWidth: 0.8 + m_GaugeAxisSplitLineLength: 15 + m_GaugeAxisTickWidth: 0.8 + m_GaugeAxisTickLength: 5 + m_TootipLineWidth: 0.8 + m_DataZoomBorderWidth: 0.5 + m_DataZoomDataLineWidth: 0.5 + m_VisualMapBorderWidth: 0 + m_SerieLineWidth: 1.4 + m_SerieLineSymbolSize: 4 + m_SerieLineSymbolSelectedSize: 8 + m_SerieScatterSymbolSize: 20 + m_SerieScatterSymbolSelectedSize: 30 + m_EditorBlockEnable: 1 + m_MaxPainter: 10 + m_LineSmoothStyle: 3 + m_LineSmoothness: 2 + m_LineSegmentDistance: 3 + m_CicleSmoothness: 2 + m_VisualMapTriangeLen: 20 + m_PieTooltipExtraRadius: 8 + m_PieSelectedOffset: 8 diff --git a/Resources/XChartsSettings.asset.meta b/Resources/XChartsSettings.asset.meta new file mode 100644 index 00000000..c83763d1 --- /dev/null +++ b/Resources/XChartsSettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 676e1e322123d4fe2a761de3ef14235f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/API/BarChart_API.cs b/Runtime/API/BarChart_API.cs index 6ba5b351..8cbe135d 100644 --- a/Runtime/API/BarChart_API.cs +++ b/Runtime/API/BarChart_API.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using System; diff --git a/Runtime/API/BaseChart_API.cs b/Runtime/API/BaseChart_API.cs index b8bd16dc..8f31e40e 100644 --- a/Runtime/API/BaseChart_API.cs +++ b/Runtime/API/BaseChart_API.cs @@ -1,14 +1,15 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using System.Collections.Generic; using System; using UnityEngine.UI; +using UnityEngine.EventSystems; namespace XCharts { @@ -37,24 +38,26 @@ namespace XCharts } } /// - /// The theme info. + /// The theme. /// - public ThemeInfo themeInfo { get { return m_ThemeInfo; } set { m_ThemeInfo = value; } } + public ChartTheme theme { get { return m_Theme; } set { m_Theme = value; } } /// /// The title setting of chart. /// 标题组件 /// - public Title title { get { return m_Title; } } + public Title title { get { return m_Titles.Count > 0 ? m_Titles[0] : null; } } + public List titles { get { return m_Titles; } } /// <summary> /// The legend setting of chart. /// 图例组件 /// </summary> - public Legend legend { get { return m_Legend; } } + public Legend legend { get { return m_Legends.Count > 0 ? m_Legends[0] : null; } } + public List<Legend> legends { get { return m_Legends; } } /// <summary> /// The tooltip setting of chart. /// 提示框组件 /// </summary> - public Tooltip tooltip { get { return m_Tooltip; } } + public Tooltip tooltip { get { return m_Tooltips.Count > 0 ? m_Tooltips[0] : null; } } /// <summary> /// The series setting of chart. /// 系列列表 @@ -85,6 +88,10 @@ namespace XCharts /// 图表的高 /// </summary> public float chartHeight { get { return m_ChartHeight; } } + public Vector2 chartMinAnchor { get { return m_ChartMinAnchor; } } + public Vector2 chartMaxAnchor { get { return m_ChartMaxAnchor; } } + public Vector2 chartPivot { get { return m_ChartPivot; } } + public Vector2 chartSizeDelta { get { return m_ChartSizeDelta; } } /// <summary> /// The position of chart. /// 图表的左下角起始坐标。 @@ -96,6 +103,11 @@ namespace XCharts /// 自定义绘制回调。 /// </summary> public Action<VertexHelper> onCustomDraw { set { m_OnCustomDrawCallback = value; } } + /// <summary> + /// the callback function of click pie area. + /// 点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex + /// </summary> + public Action<PointerEventData, int, int> onPointerClickPie { set { m_OnPointerClickPie = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerClickPie; } } /// <summary> /// Redraw chart in next frame. @@ -104,6 +116,7 @@ namespace XCharts public void RefreshChart() { m_RefreshChart = true; + if (m_Painter) m_Painter.Refresh(); } /// <summary> @@ -114,8 +127,8 @@ namespace XCharts public virtual void ClearData() { m_Series.ClearData(); - m_Legend.ClearData(); - m_Tooltip.ClearValue(); + foreach (var legend in m_Legends) legend.ClearData(); + tooltip.ClearValue(); m_CheckAnimation = false; m_ReinitLabel = true; RefreshChart(); @@ -128,9 +141,10 @@ namespace XCharts /// </summary> public virtual void RemoveData() { - m_Legend.ClearData(); + foreach (var legend in m_Legends) legend.ClearData(); + foreach (var radar in m_Radars) radar.indicatorList.Clear(); m_Series.RemoveAll(); - m_Tooltip.ClearValue(); + tooltip.ClearValue(); m_CheckAnimation = false; m_ReinitLabel = true; m_SerieLabelRoot = null; @@ -145,7 +159,7 @@ namespace XCharts public virtual void RemoveData(string serieName) { m_Series.Remove(serieName); - m_Legend.RemoveData(serieName); + foreach (var legend in m_Legends) legend.RemoveData(serieName); m_SerieLabelRoot = null; RefreshChart(); } @@ -182,7 +196,7 @@ namespace XCharts { RefreshLabel(); } - RefreshChart(); + RefreshPainter(serie); } return serieData; } @@ -205,7 +219,7 @@ namespace XCharts { RefreshLabel(); } - RefreshChart(); + RefreshPainter(serie); } return serieData; } @@ -228,7 +242,7 @@ namespace XCharts { RefreshLabel(); } - RefreshChart(); + RefreshPainter(serie); } return serieData; } @@ -251,7 +265,7 @@ namespace XCharts { RefreshLabel(); } - RefreshChart(); + RefreshPainter(serie); } return serieData; } @@ -275,7 +289,7 @@ namespace XCharts { RefreshLabel(); } - RefreshChart(); + RefreshPainter(serie); } return serieData; } @@ -299,7 +313,7 @@ namespace XCharts { RefreshLabel(); } - RefreshChart(); + RefreshPainter(serie); } return serieData; } @@ -315,7 +329,7 @@ namespace XCharts { if (m_Series.UpdateData(serieName, dataIndex, value)) { - RefreshChart(); + RefreshPainter(m_Series.GetSerie(serieName)); return true; } return false; @@ -332,7 +346,7 @@ namespace XCharts { if (m_Series.UpdateData(serieIndex, dataIndex, value)) { - RefreshChart(); + RefreshPainter(m_Series.GetSerie(serieIndex)); return true; } return false; @@ -348,7 +362,7 @@ namespace XCharts { if (m_Series.UpdateData(serieName, dataIndex, multidimensionalData)) { - RefreshChart(); + RefreshPainter(m_Series.GetSerie(serieName)); return true; } return false; @@ -364,7 +378,7 @@ namespace XCharts { if (m_Series.UpdateData(serieIndex, dataIndex, multidimensionalData)) { - RefreshChart(); + RefreshPainter(m_Series.GetSerie(serieIndex)); return true; } return false; @@ -381,7 +395,7 @@ namespace XCharts { if (m_Series.UpdateData(serieName, dataIndex, dimension, value)) { - RefreshChart(); + RefreshPainter(m_Series.GetSerie(serieName)); return true; } return false; @@ -398,7 +412,7 @@ namespace XCharts { if (m_Series.UpdateData(serieIndex, dataIndex, dimension, value)) { - RefreshChart(); + RefreshPainter(m_Series.GetSerie(serieIndex)); return true; } return false; @@ -459,15 +473,18 @@ namespace XCharts } } - protected virtual void UpdateLegendColor(string legendName, bool active) + internal virtual void UpdateLegendColor(string legendName, bool active) { var legendIndex = m_LegendRealShowName.IndexOf(legendName); if (legendIndex >= 0) { - var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_ThemeInfo, m_Series, legendName, active); - var contentColor = LegendHelper.GetContentColor(legend, m_ThemeInfo, active); - m_Legend.UpdateButtonColor(legendName, iconColor); - m_Legend.UpdateContentColor(legendName, contentColor); + foreach (var legend in m_Legends) + { + var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_Theme, m_Series, legendName, active); + var contentColor = LegendHelper.GetContentColor(legend, m_Theme, active); + legend.UpdateButtonColor(legendName, iconColor); + legend.UpdateContentColor(legendName, contentColor); + } } } @@ -541,25 +558,28 @@ namespace XCharts /// <summary> /// Update chart theme. - /// 切换图表主题。 + /// 切换内置主题。 /// </summary> /// <param name="theme">theme</param> - public void UpdateTheme(Theme theme) + public bool UpdateTheme(Theme theme) { - m_ThemeInfo.theme = theme; - OnThemeChanged(); - RefreshChart(); + if (theme == Theme.Custom) + { + Debug.LogError("UpdateTheme: not support switch to Custom theme."); + return false; + } + m_Theme.theme = theme; + return true; } /// <summary> /// Update chart theme info. /// 切换图表主题。 /// </summary> - /// <param name="themeInfo">themeInfo</param> - public void UpdateThemeInfo(ThemeInfo themeInfo) + /// <param name="theme">theme</param> + public void UpdateTheme(ChartTheme theme) { - m_ThemeInfo = themeInfo; - UpdateTheme(m_ThemeInfo.theme); + m_Theme.CopyTheme(theme); } /// <summary> @@ -572,8 +592,6 @@ namespace XCharts m_Series.AnimationEnable(flag); } - - /// <summary> /// fadeIn animation. /// 开始渐入动画。 @@ -667,46 +685,14 @@ namespace XCharts } } - /// <summary> - /// 是否可以开启背景组件。背景组件在chart受上层布局控制时无法开启。 - /// </summary> - /// <returns></returns> - public bool CanShowBackgroundComponent() + public Vector3 GetTitlePosition(Title title) { - return !m_IsControlledByLayout && m_Background.runtimeActive; + return chartPosition + title.location.GetPosition(chartWidth, chartHeight); } - /// <summary> - /// 开启背景组件。背景组件在chart受上层布局控制时不适用。 - /// </summary> - /// <param name="flag"></param> - public void EnableBackground(bool flag) + public bool ContainsSerie(SerieType serieType) { - if (flag && !CanShowBackgroundComponent()) - { - var msg = "The background component cannot be activated because chart is controlled by LayoutGroup," - + " or its parent have more than one child."; - Debug.LogError(msg); - return; - } - m_Background.show = flag; + return SeriesHelper.ContainsSerie(m_Series, serieType); } - - public Vector3 GetTitlePosition() - { - return chartPosition + m_Title.location.GetPosition(chartWidth, chartHeight); - } - - [Obsolete("Use BaseChart.RefreshLabel() instead.", true)] - public void ReinitChartLabel() { } - - [Obsolete("Use BaseChart.AnimationFadeIn() instead.", true)] - public void AnimationStart() { } - - [Obsolete("Use BaseChart.AnimationFadeOut() instead.", true)] - public void MissAnimationStart() { } - - [Obsolete("Use onCustomDraw instead.", false)] - public Action<VertexHelper> customDrawCallback { set { m_OnCustomDrawCallback = value; } } } } diff --git a/Runtime/API/BaseGraph_API.cs b/Runtime/API/BaseGraph_API.cs index 3853f2bd..fe954bdb 100644 --- a/Runtime/API/BaseGraph_API.cs +++ b/Runtime/API/BaseGraph_API.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using System; @@ -17,6 +17,12 @@ namespace XCharts /// </summary> public partial class BaseGraph { + /// <summary> + /// The background component. + /// 背景组件。 + /// </summary> + /// <value></value> + public Background background { get { return m_Background; } } /// <summary> /// The x of graph. /// 图形的X @@ -125,6 +131,11 @@ namespace XCharts m_RefreshChart = true; } + public void RefreshAllComponent() + { + SetAllComponentDirty(); + } + /// <summary> /// 检测警告信息。 /// </summary> @@ -141,6 +152,7 @@ namespace XCharts public void RemoveChartObject() { ChartHelper.DestroyAllChildren(transform); + //SetAllComponentDirty(); } } } diff --git a/Runtime/API/CoordinateChart_API.cs b/Runtime/API/CoordinateChart_API.cs index 7d2218ec..c42289ae 100644 --- a/Runtime/API/CoordinateChart_API.cs +++ b/Runtime/API/CoordinateChart_API.cs @@ -1,11 +1,10 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System; using System.Collections.Generic; using UnityEngine; @@ -18,68 +17,48 @@ namespace XCharts /// </summary> public partial class CoordinateChart { - /// <summary> - /// The lower left position x of coordinate system. - /// 坐标系的左下角坐标X。 - /// </summary> - public float coordinateX { get { return m_CoordinateX; } } - /// <summary> - /// The lower left position y of coordinate system. - /// 坐标系的左下角坐标Y。 - /// </summary> - public float coordinateY { get { return m_CoordinateY; } } - - /// <summary> - /// the width of coordinate system。 - /// 坐标系的宽。 - /// </summary> - public float coordinateWidth { get { return m_CoordinateWidth; } } - /// <summary> - /// the height of coordinate system。 - /// 坐标系的高。 - /// </summary> - public float coordinateHeight { get { return m_CoordinateHeight; } } /// <summary> /// grid component. /// 网格组件。 /// </summary> - public Grid grid { get { return m_Grid; } } + public Grid grid { get { return m_Grids.Count > 0 ? m_Grids[0] : null; } } + public List<Grid> grids { get { return m_Grids; } } /// <summary> - /// the x axises,xAxises[0] is the first x axis, xAxises[1] is the second x axis. + /// the x Axes,xAxes[0] is the first x axis, xAxes[1] is the second x axis. /// 两个x轴。 /// </summary> - public List<XAxis> xAxises { get { return m_XAxises; } } + public List<XAxis> xAxes { get { return m_XAxes; } } /// <summary> - /// the y axises, yAxises[0] is the first y axis, yAxises[1] is the second y axis. + /// the y Axes, yAxes[0] is the first y axis, yAxes[1] is the second y axis. /// 两个y轴。 /// </summary> - public List<YAxis> yAxises { get { return m_YAxises; } } + public List<YAxis> yAxes { get { return m_YAxes; } } /// <summary> /// dataZoom component. /// 区域缩放组件。 /// </summary> - public DataZoom dataZoom { get { return m_DataZoom; } } + public DataZoom dataZoom { get { return m_DataZooms.Count > 0 ? m_DataZooms[0] : null; } } /// <summary> /// visualMap component. /// 视觉映射组件。 /// </summary> - public VisualMap visualMap { get { return m_VisualMap; } } + public VisualMap visualMap { get { return m_VisualMaps.Count > 0 ? m_VisualMaps[0] : null; } } /// <summary> /// X轴(下) /// </summary> - public XAxis xAxis0 { get { return m_XAxises[0]; } } + public XAxis xAxis0 { get { return m_XAxes.Count > 0 ? m_XAxes[0] : null; } } /// <summary> /// X轴(上) /// </summary> - public XAxis xAxis1 { get { return m_XAxises[1]; } } + public XAxis xAxis1 { get { return m_XAxes.Count > 1 ? m_XAxes[1] : null; } } /// <summary> /// Y轴(左) /// </summary> - public YAxis yAxis0 { get { return m_YAxises[0]; } } + public YAxis yAxis0 { get { return m_YAxes.Count > 0 ? m_YAxes[0] : null; } } /// <summary> /// Y轴(右) /// </summary> - public YAxis yAxis1 { get { return m_YAxises[1]; } } + public YAxis yAxis1 { get { return m_YAxes.Count > 1 ? m_YAxes[1] : null; } } /// <summary> @@ -105,13 +84,13 @@ namespace XCharts } /// <summary> - /// Remove all data of axises. + /// Remove all data of Axes. /// 清除所有x轴和y轴的类目数据。 /// </summary> public void ClearAxisData() { - foreach (var item in m_XAxises) item.data.Clear(); - foreach (var item in m_YAxises) item.data.Clear(); + foreach (var item in m_XAxes) item.data.Clear(); + foreach (var item in m_YAxes) item.data.Clear(); } /// <summary> @@ -122,7 +101,7 @@ namespace XCharts /// <param name="xAxisIndex">which xAxis should category add to</param> public void AddXAxisData(string category, int xAxisIndex = 0) { - m_XAxises[xAxisIndex].AddData(category); + m_XAxes[xAxisIndex].AddData(category); } /// <summary> @@ -133,7 +112,7 @@ namespace XCharts /// <param name="yAxisIndex">which yAxis should category add to</param> public void AddYAxisData(string category, int yAxisIndex = 0) { - m_YAxises[yAxisIndex].AddData(category); + m_YAxes[yAxisIndex].AddData(category); } /// <summary> @@ -142,11 +121,11 @@ namespace XCharts /// </summary> public bool IsValue() { - foreach (var axis in m_XAxises) + foreach (var axis in m_XAxes) { if (axis.show && !axis.IsValue() && !axis.IsLog()) return false; } - foreach (var axis in m_YAxises) + foreach (var axis in m_YAxes) { if (axis.show && !axis.IsValue() && !axis.IsLog()) return false; } @@ -158,11 +137,11 @@ namespace XCharts /// </summary> public bool IsCategory() { - foreach (var axis in m_XAxises) + foreach (var axis in m_XAxes) { if (axis.show && !axis.IsCategory()) return false; } - foreach (var axis in m_YAxises) + foreach (var axis in m_YAxes) { if (axis.show && !axis.IsCategory()) return false; } @@ -172,26 +151,46 @@ namespace XCharts /// <summary> /// 坐标是否在坐标轴内。 /// </summary> - public bool IsInCooridate(Vector2 local) + public bool IsInGrid(Grid grid, Vector2 local) { - return IsInCooridate(local.x, local.y); + return IsInGrid(grid, local.x, local.y); } - public bool IsInCooridate(Vector3 local) + public bool IsInGrid(Grid grid, Vector3 local) { - return IsInCooridate(local.x, local.y); + return IsInGrid(grid, local.x, local.y); } - public bool IsInCooridate(float x, float y) + public bool IsInGrid(Grid grid, float x, float y) { - if (x < m_CoordinateX - 1 || x > m_CoordinateX + m_CoordinateWidth + 1 || - y < m_CoordinateY - 1 || y > m_CoordinateY + m_CoordinateHeight + 1) + if (x < grid.runtimeX - 1 || x > grid.runtimeX + grid.runtimeWidth + 1 || + y < grid.runtimeY - 1 || y > grid.runtimeY + grid.runtimeHeight + 1) { return false; } return true; } + public bool IsInAnyGrid(Vector2 local) + { + foreach (var grid in m_Grids) + { + if (IsInGrid(grid, local)) return true; + } + return false; + } + + public Grid GetGrid(Vector2 local) + { + for (int i = 0; i < m_Grids.Count; i++) + { + var grid = m_Grids[i]; + grid.index = i; + if (IsInGrid(grid, local)) return grid; + } + return null; + } + /// <summary> /// 在下一帧刷新DataZoom /// </summary> @@ -208,16 +207,16 @@ namespace XCharts CheckMinMaxValue(); } - public Vector3 ClampInCoordinate(Vector3 pos) + public Vector3 ClampInGrid(Grid grid, Vector3 pos) { - if (IsInCooridate(pos)) return pos; + if (IsInGrid(grid, pos)) return pos; else { // var pos = new Vector3(pos.x, pos.y); - if (pos.x < m_CoordinateX) pos.x = m_CoordinateX; - if (pos.x > m_CoordinateX + m_CoordinateWidth) pos.x = m_CoordinateX + m_CoordinateWidth; - if (pos.y < m_CoordinateY) pos.y = m_CoordinateY; - if (pos.y > m_CoordinateY + m_CoordinateHeight) pos.y = m_CoordinateY + m_CoordinateHeight; + if (pos.x < grid.runtimeX) pos.x = grid.runtimeX; + if (pos.x > grid.runtimeX + grid.runtimeWidth) pos.x = grid.runtimeX + grid.runtimeWidth; + if (pos.y < grid.runtimeY) pos.y = grid.runtimeY; + if (pos.y > grid.runtimeY + grid.runtimeHeight) pos.y = grid.runtimeY + grid.runtimeHeight; return pos; } } @@ -230,10 +229,10 @@ namespace XCharts { if (index >= 0 && index <= 1) { - var xAxis = m_XAxises[index]; - var yAxis = m_YAxises[index]; - var tempX = m_XAxises[index].Clone(); - xAxis.Copy(m_YAxises[index]); + var xAxis = m_XAxes[index]; + var yAxis = m_YAxes[index]; + var tempX = m_XAxes[index].Clone(); + xAxis.Copy(m_YAxes[index]); yAxis.Copy(tempX); xAxis.runtimeZeroXOffset = 0; xAxis.runtimeZeroYOffset = 0; @@ -252,10 +251,14 @@ namespace XCharts /// </summary> public void UpdateCoordinate() { - m_CoordinateX = m_ChartX + m_Grid.left; - m_CoordinateY = m_ChartY + m_Grid.bottom; - m_CoordinateWidth = m_ChartWidth - m_Grid.left - m_Grid.right; - m_CoordinateHeight = m_ChartHeight - m_Grid.top - m_Grid.bottom; + foreach (var grid in m_Grids) + { + grid.UpdateRuntimeData(m_ChartX, m_ChartY, m_ChartWidth, m_ChartHeight); + } + foreach (var dataZoom in m_DataZooms) + { + dataZoom.UpdateRuntimeData(m_ChartX, m_ChartY, m_ChartWidth, m_ChartHeight); + } } /// <summary> @@ -264,8 +267,26 @@ namespace XCharts public void SetMaxCache(int maxCache) { foreach (var serie in m_Series.list) serie.maxCache = maxCache; - foreach (var axis in m_XAxises) axis.maxCache = maxCache; - foreach (var axis in m_YAxises) axis.maxCache = maxCache; + foreach (var axis in m_XAxes) axis.maxCache = maxCache; + foreach (var axis in m_YAxes) axis.maxCache = maxCache; + } + + public Grid GetGrid(int index) + { + if (index >= 0 && index < m_Grids.Count) return m_Grids[index]; + else return null; + } + + public XAxis GetXAxis(int index) + { + if (index >= 0 && index < m_XAxes.Count) return m_XAxes[index]; + else return null; + } + + public YAxis GetYAxis(int index) + { + if (index >= 0 && index < m_YAxes.Count) return m_YAxes[index]; + else return null; } } } diff --git a/Runtime/API/LiquidChart_API.cs b/Runtime/API/LiquidChart_API.cs index faec6f50..13d5c930 100644 --- a/Runtime/API/LiquidChart_API.cs +++ b/Runtime/API/LiquidChart_API.cs @@ -1,17 +1,18 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; namespace XCharts { - public partial class LiquidChart + public partial class BaseChart { + public Vessel vessel { get { return m_Vessels.Count > 0 ? m_Vessels[0] : null; } } /// <summary> /// 容器组件列表。 /// </summary> diff --git a/Runtime/API/PieChart_API.cs b/Runtime/API/PieChart_API.cs deleted file mode 100644 index a4ecfc7b..00000000 --- a/Runtime/API/PieChart_API.cs +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using UnityEngine; -using System; -using UnityEngine.EventSystems; - -namespace XCharts -{ - public partial class PieChart - { - /// <summary> - /// the callback function of click pie area. - /// 点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex - /// </summary> - public Action<PointerEventData, int, int> onPointerClickPie { set { m_OnPointerClickPie = value; m_ForceOpenRaycastTarget = true; } } - } -} \ No newline at end of file diff --git a/Runtime/API/PieChart_API.cs.meta b/Runtime/API/PieChart_API.cs.meta deleted file mode 100644 index 4507e9ad..00000000 --- a/Runtime/API/PieChart_API.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 85c7f8858dca444f88830d61b9af3700 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/API/PolarChart_API.cs b/Runtime/API/PolarChart_API.cs index 18347905..6f1d045a 100644 --- a/Runtime/API/PolarChart_API.cs +++ b/Runtime/API/PolarChart_API.cs @@ -1,12 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEngine; +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ namespace XCharts { @@ -15,16 +12,16 @@ namespace XCharts /// <summary> /// 极坐标。 /// </summary> - public Polar polar { get { return m_Polar; } } + public Polar polar { get { return m_Polars.Count > 0 ? m_Polars[0] : null; } } /// <summary> /// Angle axis of Polar Coordinate. /// 极坐标系的角度轴。 /// </summary> - public AngleAxis angleAxis { get { return m_AngleAxis; } } + public AngleAxis angleAxis { get { return m_AngleAxes.Count > 0 ? m_AngleAxes[0] : null; } } /// <summary> /// Radial axis of polar coordinate. /// 极坐标系的径向轴。 /// </summary> - public RadiusAxis radiusAxis { get { return m_RadiusAxis; } } + public RadiusAxis radiusAxis { get { return m_RadiusAxes.Count > 0 ? m_RadiusAxes[0] : null; } } } } \ No newline at end of file diff --git a/Runtime/API/RadarChart_API.cs b/Runtime/API/RadarChart_API.cs index d91a900a..2090cf12 100644 --- a/Runtime/API/RadarChart_API.cs +++ b/Runtime/API/RadarChart_API.cs @@ -1,34 +1,23 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; namespace XCharts { - public partial class RadarChart + public partial class BaseChart { + public Radar radar { get { return m_Radars.Count > 0 ? m_Radars[0] : null; } } /// <summary> /// 雷达坐标系组件列表。 /// </summary> public List<Radar> radars { get { return m_Radars; } } - /// <summary> - /// 移除所有数据,包含雷达坐标系指示器数据。 - /// </summary> - public override void RemoveData() - { - base.RemoveData(); - foreach (var radar in m_Radars) - { - radar.indicatorList.Clear(); - } - } - /// <summary> /// 移除所有雷达坐标系组件。 /// </summary> @@ -57,7 +46,7 @@ namespace XCharts /// <param name="showSplitArea">是否显示分割区域</param> /// <returns></returns> public Radar AddRadar(Radar.Shape shape, Vector2 center, float radius, int splitNumber = 5, - float lineWidth = 0.6f, bool showIndicator = true, bool showSplitArea = true) + float lineWidth = 0f, bool showIndicator = true, bool showSplitArea = true) { var radar = new Radar(); radar.shape = shape; diff --git a/Runtime/API/RingChart_API.cs b/Runtime/API/RingChart_API.cs index 245dd802..264b1f77 100644 --- a/Runtime/API/RingChart_API.cs +++ b/Runtime/API/RingChart_API.cs @@ -1,12 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEngine; +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ namespace XCharts { diff --git a/Runtime/BarChart.cs b/Runtime/BarChart.cs index 789c9d3f..27718013 100644 --- a/Runtime/BarChart.cs +++ b/Runtime/BarChart.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -17,8 +17,6 @@ namespace XCharts [DisallowMultipleComponent] public partial class BarChart : CoordinateChart { - protected Action<PointerEventData, int> m_OnPointerClickBar; - protected override void Awake() { base.Awake(); @@ -28,14 +26,13 @@ namespace XCharts protected override void Reset() { base.Reset(); - m_Title.text = "BarChart"; - m_Tooltip.type = Tooltip.Type.Shadow; + title.text = "BarChart"; + tooltip.type = Tooltip.Type.Shadow; RemoveData(); - AddSerie(SerieType.Bar, "serie1"); + SerieTemplate.AddDefaultBarSerie(this, "serie1"); for (int i = 0; i < 5; i++) { AddXAxisData("x" + (i + 1)); - AddData(0, UnityEngine.Random.Range(10, 90)); } } #endif @@ -46,7 +43,7 @@ namespace XCharts if (m_OnPointerClickBar == null) return; if (pointerPos == Vector2.zero) return; UpdateTooltipValue(pointerPos); - var dataIndex = m_Tooltip.runtimeDataIndex[0]; + var dataIndex = tooltip.runtimeDataIndex[0]; if (dataIndex >= 0) { m_OnPointerClickBar(eventData, dataIndex); diff --git a/Runtime/Component/ChartComponent.cs b/Runtime/Component/ChartComponent.cs index 2b766bd2..f49c6107 100644 --- a/Runtime/Component/ChartComponent.cs +++ b/Runtime/Component/ChartComponent.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -12,17 +12,9 @@ namespace XCharts { public class ChartComponent { - [SerializeField] protected string m_JsonData; - [SerializeField] protected bool m_DataFromJson; - [NonSerialized] protected bool m_VertsDirty; [NonSerialized] protected bool m_ComponentDirty; - - /// <summary> - /// json格式的字符串数据 - /// </summary> - /// <returns></returns> - public string jsonData { get { return m_JsonData; } set { m_JsonData = value; ParseJsonData(value); } } + [NonSerialized] protected Painter m_Painter; /// <summary> /// 图表重绘标记。 /// </summary> @@ -35,23 +27,9 @@ namespace XCharts /// 需要重绘图表或重新初始化组件。 /// </summary> public bool anyDirty { get { return vertsDirty || componentDirty; } } - internal void OnAfterDeserialize() - { - if (m_DataFromJson) - { - ParseJsonData(m_JsonData); - m_DataFromJson = false; - } - } - - internal void OnBeforeSerialize() - { - } - - public virtual void ParseJsonData(string json) - { - throw new Exception("no support yet"); - } + public Painter painter { get { return m_Painter; } set { m_Painter = value; } } + public Action refreshComponent { get; set; } + public GameObject gameObject { get; set; } internal virtual void SetVerticesDirty() { @@ -85,4 +63,12 @@ namespace XCharts SetComponentDirty(); } } + + public class MainComponent : ChartComponent + { + } + + public class SubComponent : ChartComponent + { + } } \ No newline at end of file diff --git a/Runtime/Component/Main/Axis.cs b/Runtime/Component/Main/Axis.cs index aac96e45..da7078dd 100644 --- a/Runtime/Component/Main/Axis.cs +++ b/Runtime/Component/Main/Axis.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using System.Collections.Generic; @@ -64,10 +64,25 @@ namespace XCharts /// </summary> Custom } + /// <summary> + /// the position of axis in grid. + /// 坐标轴在Grid中的位置 + /// </summary> + public enum AxisPosition + { + Left, + Right, + Bottom, + Top + } [SerializeField] protected bool m_Show = true; [SerializeField] protected AxisType m_Type; [SerializeField] protected AxisMinMaxType m_MinMaxType; + [SerializeField] protected int m_GridIndex; + [SerializeField] protected int m_PolarIndex; + [SerializeField] protected AxisPosition m_Position; + [SerializeField] protected float m_Offset; [SerializeField] protected float m_Min; [SerializeField] protected float m_Max; [SerializeField] protected int m_SplitNumber = 5; @@ -97,7 +112,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); } } /// <summary> /// the type of axis. @@ -106,7 +121,7 @@ namespace XCharts public AxisType type { get { return m_Type; } - set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetAllDirty(); } } /// <summary> /// the type of axis minmax. @@ -115,7 +130,43 @@ namespace XCharts public AxisMinMaxType minMaxType { get { return m_MinMaxType; } - set { if (PropertyUtility.SetStruct(ref m_MinMaxType, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_MinMaxType, value)) SetAllDirty(); } + } + /// <summary> + /// The index of the grid on which the axis are located, by default, is in the first grid. + /// 坐标轴所在的 grid 的索引,默认位于第一个 grid。 + /// </summary> + public int gridIndex + { + get { return m_GridIndex; } + set { if (PropertyUtil.SetStruct(ref m_GridIndex, value)) SetAllDirty(); } + } + /// <summary> + /// The index of the polar on which the axis are located, by default, is in the first polar. + /// 坐标轴所在的 ploar 的索引,默认位于第一个 polar。 + /// </summary> + public int polarIndex + { + get { return m_PolarIndex; } + set { if (PropertyUtil.SetStruct(ref m_PolarIndex, value)) SetAllDirty(); } + } + /// <summary> + /// the position of axis in grid. + /// 坐标轴在Grid中的位置。 + /// </summary> + public AxisPosition position + { + get { return m_Position; } + set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetAllDirty(); } + } + /// <summary> + /// the offset of axis from the default position. Useful when the same position has multiple axes. + /// 坐标轴相对默认位置的偏移。在相同position有多个坐标轴时有用。 + /// </summary> + public float offset + { + get { return m_Offset; } + set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); } } /// <summary> /// The minimun value of axis.Valid when `minMaxType` is `Custom` @@ -124,7 +175,7 @@ namespace XCharts public float min { get { return m_Min; } - set { if (PropertyUtility.SetStruct(ref m_Min, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetAllDirty(); } } /// <summary> /// The maximum value of axis.Valid when `minMaxType` is `Custom` @@ -133,7 +184,7 @@ namespace XCharts public float max { get { return m_Max; } - set { if (PropertyUtility.SetStruct(ref m_Max, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Max, value)) SetAllDirty(); } } /// <summary> /// Number of segments that the axis is split into. @@ -142,7 +193,7 @@ namespace XCharts public int splitNumber { get { return m_SplitNumber; } - set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); } } /// <summary> /// Compulsively set segmentation interval for axis.This is unavailable for category axis. @@ -151,7 +202,7 @@ namespace XCharts public float interval { get { return m_Interval; } - set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetAllDirty(); } } /// <summary> /// The boundary gap on both sides of a coordinate axis, which is valid only for category axis with type: 'Category'. @@ -160,7 +211,7 @@ namespace XCharts public bool boundaryGap { get { return IsCategory() ? m_BoundaryGap : false; } - set { if (PropertyUtility.SetStruct(ref m_BoundaryGap, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BoundaryGap, value)) SetAllDirty(); } } /// <summary> /// Base of logarithm, which is valid only for numeric axes with type: 'Log'. @@ -172,7 +223,7 @@ namespace XCharts set { if (value <= 0 || value == 1) value = 10; - if (PropertyUtility.SetStruct(ref m_LogBase, value)) SetAllDirty(); + if (PropertyUtil.SetStruct(ref m_LogBase, value)) SetAllDirty(); } } /// <summary> @@ -182,7 +233,7 @@ namespace XCharts public bool logBaseE { get { return m_LogBaseE; } - set { if (PropertyUtility.SetStruct(ref m_LogBaseE, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LogBaseE, value)) SetAllDirty(); } } /// <summary> /// The max number of axis data cache. @@ -192,7 +243,7 @@ namespace XCharts public int maxCache { get { return m_MaxCache; } - set { if (PropertyUtility.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) SetAllDirty(); } } /// <summary> /// The ratio of maximum and minimum values rounded upward. The default is 0, which is automatically calculated. @@ -201,7 +252,7 @@ namespace XCharts public int ceilRate { get { return m_CeilRate; } - set { if (PropertyUtility.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); } } /// <summary> /// Whether the axis are reversed or not. Invalid in `Category` axis. @@ -210,7 +261,7 @@ namespace XCharts public bool inverse { get { return m_Inverse; } - set { if (m_Type == AxisType.Value && PropertyUtility.SetStruct(ref m_Inverse, value)) SetAllDirty(); } + set { if (m_Type == AxisType.Value && PropertyUtil.SetStruct(ref m_Inverse, value)) SetAllDirty(); } } /// <summary> /// Whether the positive position of axis is in clockwise. True for clockwise by default. @@ -219,7 +270,7 @@ namespace XCharts public bool clockwise { get { return m_Clockwise; } - set { if (PropertyUtility.SetStruct(ref m_Clockwise, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); } } /// <summary> /// Category data, available in type: 'Category' axis. @@ -312,7 +363,7 @@ namespace XCharts /// the axis label text list. /// 坐标轴刻度标签的Text列表。 /// </summary> - public List<Text> axisLabelTextList { get { return m_AxisLabelTextList; } set { m_AxisLabelTextList = value; } } + public List<ChartText> axisLabelTextList { get { return m_AxisLabelTextList; } set { m_AxisLabelTextList = value; } } /// <summary> /// the current minimun value. /// 当前最小值。 @@ -361,9 +412,9 @@ namespace XCharts private int filterEnd; private int filterMinShow; private List<string> filterData; - private List<Text> m_AxisLabelTextList = new List<Text>(); + private List<ChartText> m_AxisLabelTextList = new List<ChartText>(); private GameObject m_TooltipLabel; - private Text m_TooltipLabelText; + private ChartText m_TooltipLabelText; private RectTransform m_TooltipLabelRect; private float m_RuntimeMinValue; private float m_RuntimeLastMinValue; @@ -381,6 +432,7 @@ namespace XCharts var axis = new Axis(); axis.show = show; axis.type = type; + axis.gridIndex = 0; axis.minMaxType = minMaxType; axis.min = min; axis.max = max; @@ -407,6 +459,7 @@ namespace XCharts show = axis.show; type = axis.type; minMaxType = axis.minMaxType; + gridIndex = axis.gridIndex; min = axis.min; max = axis.max; splitNumber = axis.splitNumber; @@ -514,7 +567,7 @@ namespace XCharts /// <returns></returns> internal List<string> GetDataList(DataZoom dataZoom) { - if (dataZoom != null && dataZoom.enable) + if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxisIndex(index)) { UpdateFilterData(dataZoom); return filterData; @@ -532,7 +585,7 @@ namespace XCharts /// <param name="dataZoom"></param> internal void UpdateFilterData(DataZoom dataZoom) { - if (dataZoom != null && dataZoom.enable) + if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxisIndex(index)) { var startIndex = (int)((data.Count - 1) * dataZoom.start / 100); var endIndex = (int)((data.Count - 1) * dataZoom.end / 100); @@ -593,7 +646,7 @@ namespace XCharts if (axisLabelTextList[i] != null) { var text = AxisHelper.GetLabelName(this, coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent); - axisLabelTextList[i].text = text; + axisLabelTextList[i].SetText(text); } } } @@ -602,31 +655,28 @@ namespace XCharts { m_TooltipLabel = label; m_TooltipLabelRect = label.GetComponent<RectTransform>(); - m_TooltipLabelText = label.GetComponentInChildren<Text>(); + m_TooltipLabelText = new ChartText(label); ChartHelper.SetActive(m_TooltipLabel, true); } internal void SetTooltipLabelColor(Color bgColor, Color textColor) { m_TooltipLabel.GetComponent<Image>().color = bgColor; - m_TooltipLabelText.color = textColor; + m_TooltipLabelText.SetColor(textColor); } internal void SetTooltipLabelActive(bool flag) { - if (m_TooltipLabel && m_TooltipLabel.activeInHierarchy != flag) - { - ChartHelper.SetActive(m_TooltipLabel, flag); - } + ChartHelper.SetActive(m_TooltipLabel, flag); } internal void UpdateTooptipLabelText(string text) { - if (m_TooltipLabelText) + if (m_TooltipLabelText != null) { - m_TooltipLabelText.text = text; - m_TooltipLabelRect.sizeDelta = new Vector2(m_TooltipLabelText.preferredWidth + 8, - m_TooltipLabelText.preferredHeight + 8); + m_TooltipLabelText.SetText(text); + m_TooltipLabelRect.sizeDelta = new Vector2(m_TooltipLabelText.GetPreferredWidth() + 8, + m_TooltipLabelText.GetPreferredHeight() + 8); } } @@ -753,10 +803,24 @@ namespace XCharts return logBaseE ? Mathf.Log(value) : Mathf.Log(value, logBase); } - public override void ParseJsonData(string jsonData) + public bool IsLeft() { - if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return; - m_Data = ChartHelper.ParseStringFromString(jsonData); + return position == AxisPosition.Left; + } + + public bool IsRight() + { + return position == AxisPosition.Right; + } + + public bool IsTop() + { + return position == AxisPosition.Top; + } + + public bool IsBottom() + { + return position == AxisPosition.Bottom; } } @@ -780,13 +844,15 @@ namespace XCharts m_Max = 0, m_SplitNumber = 5, m_BoundaryGap = true, + m_Position = AxisPosition.Bottom, + m_Offset = 0, m_Data = new List<string>() { "x1","x2","x3","x4","x5" } }; axis.splitLine.show = false; - axis.splitLine.lineStyle.type = LineStyle.Type.Dashed; + axis.splitLine.lineStyle.type = LineStyle.Type.None; axis.axisLabel.textLimit.enable = true; return axis; } @@ -813,10 +879,11 @@ namespace XCharts m_Max = 0, m_SplitNumber = 5, m_BoundaryGap = false, + m_Position = AxisPosition.Left, m_Data = new List<string>(5), }; axis.splitLine.show = true; - axis.splitLine.lineStyle.type = LineStyle.Type.Dashed; + axis.splitLine.lineStyle.type = LineStyle.Type.None; axis.axisLabel.textLimit.enable = false; return axis; } @@ -868,7 +935,7 @@ namespace XCharts public float startAngle { get { return m_StartAngle; } - set { if (PropertyUtility.SetStruct(ref m_StartAngle, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_StartAngle, value)) SetAllDirty(); } } public float runtimeStartAngle { get; set; } @@ -881,9 +948,9 @@ namespace XCharts { m_Show = true, m_Type = AxisType.Value, - m_SplitNumber = 13, + m_SplitNumber = 12, m_BoundaryGap = false, - m_Data = new List<string>(13), + m_Data = new List<string>(12), }; axis.splitLine.show = true; axis.splitLine.lineStyle.type = LineStyle.Type.Solid; diff --git a/Runtime/Component/Main/Background.cs b/Runtime/Component/Main/Background.cs index 34ba6288..c18c1074 100644 --- a/Runtime/Component/Main/Background.cs +++ b/Runtime/Component/Main/Background.cs @@ -1,10 +1,10 @@ using System.Net.Mime; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -41,7 +41,7 @@ namespace XCharts public bool show { get { return m_Show; } - internal set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); } + internal set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// <summary> /// the image of background. @@ -50,7 +50,7 @@ namespace XCharts public Sprite image { get { return m_Image; } - set { if (PropertyUtility.SetClass(ref m_Image, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Image, value)) SetComponentDirty(); } } /// <summary> @@ -60,7 +60,7 @@ namespace XCharts public Image.Type imageType { get { return m_ImageType; } - set { if (PropertyUtility.SetStruct(ref m_ImageType, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetComponentDirty(); } } /// <summary> @@ -69,7 +69,7 @@ namespace XCharts public Color imageColor { get { return m_ImageColor; } - set { if (PropertyUtility.SetColor(ref m_ImageColor, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetColor(ref m_ImageColor, value)) SetComponentDirty(); } } /// <summary> @@ -79,14 +79,9 @@ namespace XCharts public bool hideThemeBackgroundColor { get { return m_HideThemeBackgroundColor; } - set { if (PropertyUtility.SetStruct(ref m_HideThemeBackgroundColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_HideThemeBackgroundColor, value)) SetVerticesDirty(); } } - /// <summary> - /// 是否已激活 - /// </summary> - public bool runtimeActive { get; internal set; } - public static Background defaultBackground { get diff --git a/Runtime/Component/Main/DataZoom.cs b/Runtime/Component/Main/DataZoom.cs index bfb259b6..6296a3df 100644 --- a/Runtime/Component/Main/DataZoom.cs +++ b/Runtime/Component/Main/DataZoom.cs @@ -1,10 +1,11 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ +using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -68,8 +69,8 @@ namespace XCharts } [SerializeField] private bool m_Enable; [SerializeField] private FilterMode m_FilterMode; - [SerializeField] private int m_XAxisIndex; - [SerializeField] private int m_YAxisIndex; + [SerializeField] private List<int> m_XAxisIndexs = new List<int>() { 0 }; + [SerializeField] private List<int> m_YAxisIndexs = new List<int>() { }; [SerializeField] private bool m_SupportInside; [SerializeField] private bool m_SupportSlider; [SerializeField] private bool m_SupportSelect; @@ -77,8 +78,13 @@ namespace XCharts [SerializeField] private bool m_ShowDetail; [SerializeField] private bool m_ZoomLock; [SerializeField] private bool m_Realtime; - [SerializeField] private Color m_BackgroundColor; - [SerializeField] private float m_Height; + [SerializeField] protected Color32 m_FillerColor; + [SerializeField] protected Color32 m_BorderColor; + [SerializeField] protected float m_BorderWidth; + [SerializeField] protected Color32 m_BackgroundColor; + [SerializeField] private float m_Left; + [SerializeField] private float m_Right; + [SerializeField] private float m_Top; [SerializeField] private float m_Bottom; [SerializeField] private RangeMode m_RangeMode; [SerializeField] private float m_Start; @@ -88,8 +94,9 @@ namespace XCharts [SerializeField] private int m_MinShowNum = 1; [Range(1f, 20f)] [SerializeField] private float m_ScrollSensitivity = 1.1f; - [SerializeField] private int m_FontSize = 18; - [SerializeField] private FontStyle m_FontStyle; + [SerializeField] private TextStyle m_TextStyle; + [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid); + [SerializeField] private AreaStyle m_AreaStyle = new AreaStyle(); /// <summary> /// Whether to show dataZoom. @@ -98,7 +105,7 @@ namespace XCharts public bool enable { get { return m_Enable; } - set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetVerticesDirty(); } } /// <summary> /// The mode of data filter. @@ -107,25 +114,25 @@ namespace XCharts public FilterMode filterMode { get { return m_FilterMode; } - set { if (PropertyUtility.SetStruct(ref m_FilterMode, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_FilterMode, value)) SetVerticesDirty(); } } /// <summary> /// Specify which xAxis is controlled by the dataZoom. - /// 控制哪一个 x 轴。 + /// 控制的 x 轴索引列表。 /// </summary> - public int xAxisIndex + public List<int> xAxisIndexs { - get { return m_XAxisIndex; } - set { if (PropertyUtility.SetStruct(ref m_XAxisIndex, value)) SetVerticesDirty(); } + get { return m_XAxisIndexs; } + set { if (PropertyUtil.SetClass(ref m_XAxisIndexs, value)) SetVerticesDirty(); } } /// <summary> /// Specify which yAxis is controlled by the dataZoom. - /// 控制哪一个 y 轴。 + /// 控制的 y 轴索引列表。 /// </summary> - public int yAxisIndex + public List<int> yAxisIndexs { - get { return m_YAxisIndex; } - set { if (PropertyUtility.SetStruct(ref m_YAxisIndex, value)) SetVerticesDirty(); } + get { return m_YAxisIndexs; } + set { if (PropertyUtil.SetClass(ref m_YAxisIndexs, value)) SetVerticesDirty(); } } /// <summary> /// Whether built-in support is supported. @@ -137,7 +144,7 @@ namespace XCharts public bool supportInside { get { return m_SupportInside; } - set { if (PropertyUtility.SetStruct(ref m_SupportInside, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SupportInside, value)) SetVerticesDirty(); } } /// <summary> /// Whether a slider is supported. There are separate sliders on which the user zooms or roams. @@ -146,7 +153,7 @@ namespace XCharts public bool supportSlider { get { return m_SupportSlider; } - set { if (PropertyUtility.SetStruct(ref m_SupportSlider, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SupportSlider, value)) SetVerticesDirty(); } } /// <summary> /// 是否支持框选。提供一个选框进行数据区域缩放。 @@ -154,7 +161,7 @@ namespace XCharts private bool supportSelect { get { return m_SupportSelect; } - set { if (PropertyUtility.SetStruct(ref m_SupportSelect, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SupportSelect, value)) SetVerticesDirty(); } } /// <summary> /// Whether to show data shadow, to indicate the data tendency in brief. @@ -164,7 +171,7 @@ namespace XCharts public bool showDataShadow { get { return m_ShowDataShadow; } - set { if (PropertyUtility.SetStruct(ref m_ShowDataShadow, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ShowDataShadow, value)) SetVerticesDirty(); } } /// <summary> /// Whether to show detail, that is, show the detailed data information when dragging. @@ -174,7 +181,7 @@ namespace XCharts public bool showDetail { get { return m_ShowDetail; } - set { if (PropertyUtility.SetStruct(ref m_ShowDetail, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ShowDetail, value)) SetVerticesDirty(); } } /// <summary> /// Specify whether to lock the size of window (selected area). @@ -185,7 +192,7 @@ namespace XCharts public bool zoomLock { get { return m_ZoomLock; } - set { if (PropertyUtility.SetStruct(ref m_ZoomLock, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ZoomLock, value)) SetVerticesDirty(); } } /// <summary> /// Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief. @@ -197,32 +204,81 @@ namespace XCharts /// The background color of the component. /// 组件的背景颜色。 /// </summary> - private Color backgroundColor + public Color backgroundColor { get { return m_BackgroundColor; } - set { if (PropertyUtility.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of dataZoom data area. + /// 数据区域颜色。 + /// </summary> + public Color32 fillerColor + { + get { return m_FillerColor; } + set { if (PropertyUtil.SetColor(ref m_FillerColor, value)) SetVerticesDirty(); } + } + + /// <summary> + /// the color of dataZoom border. + /// 边框颜色。 + /// </summary> + public Color32 borderColor + { + get { return m_BorderColor; } + set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetComponentDirty(); } + } + /// <summary> + /// 边框宽。 + /// </summary> + public float borderWidth + { + get { return m_BorderWidth; } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetComponentDirty(); } } /// <summary> /// Distance between dataZoom component and the bottom side of the container. - /// bottom value is a instant pixel value like 10. + /// bottom value is a instant pixel value like 10 or float value [0-1]. /// default:10 /// 组件离容器下侧的距离。 /// </summary> public float bottom { get { return m_Bottom; } - set { if (PropertyUtility.SetStruct(ref m_Bottom, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetVerticesDirty(); } } /// <summary> - /// The height of dataZoom component. - /// height value is a instant pixel value like 10. - /// default:50 - /// 组件高度。 + /// Distance between dataZoom component and the top side of the container. + /// top value is a instant pixel value like 10 or float value [0-1]. + /// default:10 + /// 组件离容器上侧的距离。 /// </summary> - public float height + public float top { - get { return m_Height; } - set { if (PropertyUtility.SetStruct(ref m_Height, value)) SetVerticesDirty(); } + get { return m_Top; } + set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetVerticesDirty(); } + } + /// <summary> + /// Distance between dataZoom component and the left side of the container. + /// left value is a instant pixel value like 10 or float value [0-1]. + /// default:10 + /// 组件离容器左侧的距离。 + /// </summary> + public float left + { + get { return m_Left; } + set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetVerticesDirty(); } + } + /// <summary> + /// Distance between dataZoom component and the right side of the container. + /// right value is a instant pixel value like 10 or float value [0-1]. + /// default:10 + /// 组件离容器右侧的距离。 + /// </summary> + public float right + { + get { return m_Right; } + set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetVerticesDirty(); } } /// <summary> /// Use absolute value or percent value in DataZoom.start and DataZoom.end. @@ -232,7 +288,7 @@ namespace XCharts public RangeMode rangeMode { get { return m_RangeMode; } - set { if (PropertyUtility.SetStruct(ref m_RangeMode, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_RangeMode, value)) SetVerticesDirty(); } } /// <summary> /// The start percentage of the window out of the data extent, in the range of 0 ~ 100. @@ -261,7 +317,7 @@ namespace XCharts public int minShowNum { get { return m_MinShowNum; } - set { if (PropertyUtility.SetStruct(ref m_MinShowNum, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_MinShowNum, value)) SetVerticesDirty(); } } /// <summary> /// The sensitivity of dataZoom scroll. @@ -272,37 +328,49 @@ namespace XCharts public float scrollSensitivity { get { return m_ScrollSensitivity; } - set { if (PropertyUtility.SetStruct(ref m_ScrollSensitivity, value)) SetVerticesDirty(); } - } - /// <summary> - /// font size. - /// 文字的字体大小。 - /// </summary> - public int fontSize - { - get { return m_FontSize; } - set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ScrollSensitivity, value)) SetVerticesDirty(); } } /// <summary> /// font style. - /// 文字字体的风格。 + /// 文字格式。 /// </summary> - public FontStyle fontStyle + public TextStyle textStyle { - get { return m_FontStyle; } - set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); } + get { return m_TextStyle; } + set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } } + /// <summary> + /// 阴影线条样式。 + /// </summary> + public LineStyle lineStyle + { + get { return m_LineStyle; } + set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetComponentDirty(); } + } + /// <summary> + /// 阴影填充样式。 + /// </summary> + public AreaStyle areaStyle + { + get { return m_AreaStyle; } + set { if (PropertyUtil.SetClass(ref m_AreaStyle, value)) SetComponentDirty(); } + } + public int index { get; internal set; } + public float runtimeX { get; private set; } + public float runtimeY { get; private set; } + public float runtimeWidth { get; private set; } + public float runtimeHeight { get; private set; } /// <summary> /// The start label. /// 组件的开始信息文本。 /// </summary> - private Text m_StartLabel { get; set; } + private ChartText m_StartLabel { get; set; } /// <summary> /// The end label. /// 组件的结束信息文本。 /// </summary> - private Text m_EndLabel { get; set; } + private ChartText m_EndLabel { get; set; } public static DataZoom defaultDataZoom { @@ -310,18 +378,31 @@ namespace XCharts { return new DataZoom() { + supportInside = true, + supportSlider = true, filterMode = FilterMode.None, - xAxisIndex = 0, - yAxisIndex = 0, + xAxisIndexs = new List<int>() { 0 }, + yAxisIndexs = new List<int>() { }, showDataShadow = true, showDetail = false, zoomLock = false, - m_Height = 0, m_Bottom = 10, + m_Left = 10, + m_Right = 10, + m_Top = 0.9f, rangeMode = RangeMode.Percent, start = 30, end = 70, m_ScrollSensitivity = 10, + m_TextStyle = new TextStyle(), + m_LineStyle = new LineStyle(LineStyle.Type.Solid){ + opacity = 0.3f + }, + m_AreaStyle = new AreaStyle() + { + show = true, + opacity = 0.3f, + }, }; } } @@ -333,10 +414,14 @@ namespace XCharts /// <param name="startX"></param> /// <param name="width"></param> /// <returns></returns> - public bool IsInZoom(Vector2 pos, float startX, float startY, float width) + public bool IsInZoom(Vector2 pos) { - Rect rect = Rect.MinMaxRect(startX, startY + m_Bottom, startX + width, startY + m_Bottom + m_Height); - return rect.Contains(pos); + if (pos.x < runtimeX - 1 || pos.x > runtimeX + runtimeWidth + 1 || + pos.y < runtimeY - 1 || pos.y > runtimeY + runtimeHeight + 1) + { + return false; + } + return false; } /// <summary> @@ -346,11 +431,11 @@ namespace XCharts /// <param name="startX"></param> /// <param name="width"></param> /// <returns></returns> - public bool IsInSelectedZoom(Vector2 pos, float startX, float startY, float width) + public bool IsInSelectedZoom(Vector2 pos) { - var start = startX + width * m_Start / 100; - var end = startX + width * m_End / 100; - Rect rect = Rect.MinMaxRect(start, startY + m_Bottom, end, startY + m_Bottom + m_Height); + var start = runtimeX + runtimeWidth * m_Start / 100; + var end = runtimeX + runtimeWidth * m_End / 100; + Rect rect = Rect.MinMaxRect(start, runtimeY, end, runtimeY + runtimeHeight); return rect.Contains(pos); } @@ -361,10 +446,10 @@ namespace XCharts /// <param name="startX"></param> /// <param name="width"></param> /// <returns></returns> - public bool IsInStartZoom(Vector2 pos, float startX, float startY, float width) + public bool IsInStartZoom(Vector2 pos) { - var start = startX + width * m_Start / 100; - Rect rect = Rect.MinMaxRect(start - 10, startY + m_Bottom, start + 10, startY + m_Bottom + m_Height); + var start = runtimeX + runtimeWidth * m_Start / 100; + Rect rect = Rect.MinMaxRect(start - 10, runtimeY, start + 10, runtimeY + runtimeHeight); return rect.Contains(pos); } @@ -375,24 +460,29 @@ namespace XCharts /// <param name="startX"></param> /// <param name="width"></param> /// <returns></returns> - public bool IsInEndZoom(Vector2 pos, float startX, float startY, float width) + public bool IsInEndZoom(Vector2 pos) { - var end = startX + width * m_End / 100; - Rect rect = Rect.MinMaxRect(end - 10, startY + m_Bottom, end + 10, startY + m_Bottom + m_Height); + var end = runtimeX + runtimeWidth * m_End / 100; + Rect rect = Rect.MinMaxRect(end - 10, runtimeY, end + 10, runtimeY + runtimeHeight); return rect.Contains(pos); } + public bool IsContainsAxisIndex(int index) + { + return xAxisIndexs.Contains(index);// || yAxisIndexs.Contains(index); + } + /// <summary> /// 是否显示文本 /// </summary> /// <param name="flag"></param> internal void SetLabelActive(bool flag) { - if (m_StartLabel && m_StartLabel.gameObject.activeInHierarchy != flag) + if (m_StartLabel != null && m_StartLabel.gameObject.activeInHierarchy != flag) { m_StartLabel.gameObject.SetActive(flag); } - if (m_EndLabel && m_EndLabel.gameObject.activeInHierarchy != flag) + if (m_EndLabel != null && m_EndLabel.gameObject.activeInHierarchy != flag) { m_EndLabel.gameObject.SetActive(flag); } @@ -404,7 +494,7 @@ namespace XCharts /// <param name="text"></param> internal void SetStartLabelText(string text) { - if (m_StartLabel) m_StartLabel.text = text; + if (m_StartLabel != null) m_StartLabel.SetText(text); } /// <summary> @@ -413,43 +503,56 @@ namespace XCharts /// <param name="text"></param> internal void SetEndLabelText(string text) { - if (m_EndLabel) m_EndLabel.text = text; + if (m_EndLabel != null) m_EndLabel.SetText(text); } - /// <summary> - /// 获取DataZoom的高,当height设置为0时,自动计算合适的偏移。 - /// </summary> - /// <param name="gridBottom"></param> - /// <returns></returns> - internal float GetHeight(float gridBottom) - { - if (height <= 0) - { - height = gridBottom - bottom - 30; - if (height < 10) height = 10; - return height; - } - else return height; - } - - internal void SetStartLabel(Text startLabel) + internal void SetStartLabel(ChartText startLabel) { m_StartLabel = startLabel; } - internal void SetEndLabel(Text endLabel) + internal void SetEndLabel(ChartText endLabel) { m_EndLabel = endLabel; } internal void UpdateStartLabelPosition(Vector3 pos) { - m_StartLabel.transform.localPosition = pos; + m_StartLabel.SetLocalPosition(pos); } internal void UpdateEndLabelPosition(Vector3 pos) { - m_EndLabel.transform.localPosition = pos; + m_EndLabel.SetLocalPosition(pos); + } + + internal void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight) + { + var runtimeLeft = left <= 1 ? left * chartWidth : left; + var runtimeBottom = bottom <= 1 ? bottom * chartHeight : bottom; + var runtimeTop = top <= 1 ? top * chartHeight : top; + var runtimeRight = right <= 1 ? right * chartWidth : right; + runtimeX = chartX + runtimeLeft; + runtimeY = chartY + runtimeBottom; + runtimeWidth = chartWidth - runtimeLeft - runtimeRight; + runtimeHeight = chartHeight - runtimeTop - runtimeBottom; + } + + public Color32 GetFillerColor(Color32 themeColor) + { + if (ChartHelper.IsClearColor(fillerColor)) return themeColor; + else return fillerColor; + } + + public Color32 GetBackgroundColor(Color32 themeColor) + { + if (ChartHelper.IsClearColor(backgroundColor)) return themeColor; + else return backgroundColor; + } + public Color32 GetBorderColor(Color32 themeColor) + { + if (ChartHelper.IsClearColor(borderColor)) return themeColor; + else return borderColor; } } } \ No newline at end of file diff --git a/Runtime/Component/Main/Legend.cs b/Runtime/Component/Main/Legend.cs index 6065c80b..8c5d5cef 100644 --- a/Runtime/Component/Main/Legend.cs +++ b/Runtime/Component/Main/Legend.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -47,11 +47,12 @@ namespace XCharts [SerializeField] private float m_ItemGap = 10f; [SerializeField] private bool m_ItemAutoColor = true; [SerializeField] private string m_Formatter; - [SerializeField] private TextStyle m_TextStyle = new TextStyle(18); + [SerializeField] private TextStyle m_TextStyle = new TextStyle(); [SerializeField] private List<string> m_Data = new List<string>(); [SerializeField] private List<Sprite> m_Icons = new List<Sprite>(); private Dictionary<string, LegendItem> m_DataBtnList = new Dictionary<string, LegendItem>(); + private Dictionary<int, float> m_RuntimeEachWidth = new Dictionary<int, float>(); /// <summary> /// Whether to show legend component. @@ -60,7 +61,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// <summary> /// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends. @@ -71,7 +72,7 @@ namespace XCharts public SelectedMode selectedMode { get { return m_SelectedMode; } - set { if (PropertyUtility.SetStruct(ref m_SelectedMode, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SelectedMode, value)) SetComponentDirty(); } } /// <summary> /// Specify whether the layout of legend component is horizontal or vertical. @@ -81,7 +82,7 @@ namespace XCharts public Orient orient { get { return m_Orient; } - set { if (PropertyUtility.SetStruct(ref m_Orient, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetComponentDirty(); } } /// <summary> /// The location of legend. @@ -91,7 +92,7 @@ namespace XCharts public Location location { get { return m_Location; } - set { if (PropertyUtility.SetClass(ref m_Location, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); } } /// <summary> /// Image width of legend symbol. @@ -101,7 +102,7 @@ namespace XCharts public float itemWidth { get { return m_ItemWidth; } - set { if (PropertyUtility.SetStruct(ref m_ItemWidth, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ItemWidth, value)) SetComponentDirty(); } } /// <summary> /// Image height of legend symbol. @@ -111,7 +112,7 @@ namespace XCharts public float itemHeight { get { return m_ItemHeight; } - set { if (PropertyUtility.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); } } /// <summary> /// The distance between each legend, horizontal distance in horizontal layout, and vertical distance in vertical layout. @@ -121,7 +122,7 @@ namespace XCharts public float itemGap { get { return m_ItemGap; } - set { if (PropertyUtility.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); } } /// <summary> /// Whether the legend symbol matches the color automatically. @@ -131,7 +132,7 @@ namespace XCharts public bool itemAutoColor { get { return m_ItemAutoColor; } - set { if (PropertyUtility.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); } } /// <summary> /// Legend content string template formatter. Support for wrapping lines with \n. Template:{name}. @@ -142,7 +143,7 @@ namespace XCharts public string formatter { get { return m_Formatter; } - set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); } } /// <summary> /// the style of text. @@ -151,7 +152,7 @@ namespace XCharts public TextStyle textStyle { get { return m_TextStyle; } - set { if (PropertyUtility.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } } /// <summary> /// Data array of legend. An array item is usually a name representing string. (If it is a pie chart, @@ -173,6 +174,7 @@ namespace XCharts get { return m_Icons; } set { if (value != null) { m_Icons = value; SetComponentDirty(); } } } + public int index { get; internal set; } /// <summary> /// 图表是否需要刷新(图例组件不需要刷新图表) /// </summary> @@ -209,7 +211,7 @@ namespace XCharts /// <summary> /// 多列时每列的宽度 /// </summary> - public Dictionary<int, float> runtimeEachWidth { get; internal set; } + public Dictionary<int, float> runtimeEachWidth { get { return m_RuntimeEachWidth; }} /// <summary> /// 单列高度 /// </summary> @@ -231,11 +233,10 @@ namespace XCharts m_ItemWidth = 24.0f, m_ItemHeight = 12.0f, m_ItemGap = 10f, - runtimeEachWidth = new Dictionary<int, float>() }; - legend.location.top = 30; + legend.location.top = 35; legend.textStyle.offset = new Vector2(2, 0); - legend.textStyle.fontSize = 18; + legend.textStyle.fontSize = 0; return legend; } } @@ -393,18 +394,6 @@ namespace XCharts m_Location.OnChanged(); } - /// <summary> - /// Parsing the data from the JSON string. - /// 从json字符串解析数据,json格式如:['legend1','legend2','legend3','legend4','legend5'] - /// </summary> - /// <param name="jsonData"></param> - public override void ParseJsonData(string jsonData) - { - if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return; - m_Data = ChartHelper.ParseStringFromString(jsonData); - SetComponentDirty(); - } - /// <summary> /// 获得图例格式化后的显示内容。 /// </summary> diff --git a/Runtime/Component/Main/Polar.cs b/Runtime/Component/Main/Polar.cs index 4f57b7e5..8188cbe2 100644 --- a/Runtime/Component/Main/Polar.cs +++ b/Runtime/Component/Main/Polar.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -33,7 +33,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// [default:[0.5f,0.45f]]The center of ploar. The center[0] is the x-coordinate, and the center[1] is the y-coordinate. @@ -53,7 +53,7 @@ namespace XCharts public float radius { get { return m_Radius; } - set { if (PropertyUtility.SetStruct(ref m_Radius, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); } } /// <summary> /// [default:Color.clear]Background color of polar, which is transparent by default. @@ -62,9 +62,9 @@ namespace XCharts public Color backgroundColor { get { return m_BackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } } - + public int index { get; internal set; } /// <summary> /// the center position of polar in container. /// 极坐标在容器中的具体中心点。 diff --git a/Runtime/Component/Main/Radar.cs b/Runtime/Component/Main/Radar.cs index e432f0d7..0cab5c6b 100644 --- a/Runtime/Component/Main/Radar.cs +++ b/Runtime/Component/Main/Radar.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using System.Collections.Generic; @@ -84,10 +84,12 @@ namespace XCharts /// </summary> public Text text { get; set; } } + [SerializeField] private bool m_Show; [SerializeField] private Shape m_Shape; [SerializeField] private float m_Radius = 100; [SerializeField] private int m_SplitNumber = 5; [SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f }; + [SerializeField] private AxisLine m_AxisLine = AxisLine.defaultAxisLine; [SerializeField] private AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine; [SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea; [SerializeField] private bool m_Indicator = true; @@ -97,6 +99,12 @@ namespace XCharts [SerializeField] private bool m_IsAxisTooltip; [SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>(); /// <summary> + /// [default:true] + /// Set this to false to prevent the radar from showing. + /// 是否显示雷达坐标系组件。 + /// </summary> + public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } + /// <summary> /// Radar render type, in which 'Polygon' and 'Circle' are supported. /// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。 /// </summary> @@ -104,7 +112,7 @@ namespace XCharts public Shape shape { get { return m_Shape; } - set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Shape, value)) SetAllDirty(); } } /// <summary> /// the radius of radar. @@ -113,7 +121,7 @@ namespace XCharts public float radius { get { return m_Radius; } - set { if (PropertyUtility.SetStruct(ref m_Radius, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); } } /// <summary> /// Segments of indicator axis. @@ -122,7 +130,7 @@ namespace XCharts public int splitNumber { get { return m_SplitNumber; } - set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); } } /// <summary> /// the center of radar chart. @@ -135,13 +143,22 @@ namespace XCharts set { if (value != null) { m_Center = value; SetAllDirty(); } } } /// <summary> + /// axis line. + /// 轴线。 + /// </summary> + public AxisLine axisLine + { + get { return m_AxisLine; } + set { if (PropertyUtil.SetClass(ref m_AxisLine, value, true)) SetAllDirty(); } + } + /// <summary> /// split line. /// 分割线。 /// </summary> public AxisSplitLine splitLine { get { return m_SplitLine; } - set { if (PropertyUtility.SetClass(ref m_SplitLine, value, true)) SetAllDirty(); } + set { if (PropertyUtil.SetClass(ref m_SplitLine, value, true)) SetAllDirty(); } } /// <summary> /// Split area of axis in grid area. @@ -150,7 +167,7 @@ namespace XCharts public AxisSplitArea splitArea { get { return m_SplitArea; } - set { if (PropertyUtility.SetClass(ref m_SplitArea, value, true)) SetAllDirty(); } + set { if (PropertyUtil.SetClass(ref m_SplitArea, value, true)) SetAllDirty(); } } /// <summary> /// Whether to show indicator. @@ -159,7 +176,7 @@ namespace XCharts public bool indicator { get { return m_Indicator; } - set { if (PropertyUtility.SetStruct(ref m_Indicator, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Indicator, value)) SetComponentDirty(); } } /// <summary> /// The gap of indicator and radar. @@ -168,7 +185,7 @@ namespace XCharts public float indicatorGap { get { return m_IndicatorGap; } - set { if (PropertyUtility.SetStruct(ref m_IndicatorGap, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_IndicatorGap, value)) SetComponentDirty(); } } /// <summary> /// The ratio of maximum and minimum values rounded upward. The default is 0, which is automatically calculated. @@ -177,7 +194,7 @@ namespace XCharts public int ceilRate { get { return m_CeilRate; } - set { if (PropertyUtility.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); } } /// <summary> /// 是否Tooltip显示轴线上的所有数据。 @@ -185,7 +202,7 @@ namespace XCharts public bool isAxisTooltip { get { return m_IsAxisTooltip; } - set { if (PropertyUtility.SetStruct(ref m_IsAxisTooltip, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_IsAxisTooltip, value)) SetAllDirty(); } } /// <summary> /// The position type of indicator. @@ -194,7 +211,7 @@ namespace XCharts public PositionType positionType { get { return m_PositionType; } - set { if (PropertyUtility.SetStruct(ref m_PositionType, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_PositionType, value)) SetAllDirty(); } } /// <summary> /// the indicator list. @@ -226,6 +243,7 @@ namespace XCharts { var radar = new Radar { + m_Show = true, m_Shape = Shape.Polygon, m_Radius = 0.35f, m_SplitNumber = 5, @@ -242,7 +260,6 @@ namespace XCharts radar.center[1] = 0.4f; radar.splitLine.show = true; radar.splitArea.show = true; - radar.splitLine.lineStyle.width = 0.6f; return radar; } } @@ -259,38 +276,6 @@ namespace XCharts return true; } - public override void ParseJsonData(string jsonData) - { - if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return; - string pattern = "[\"|'](.*?)[\"|']"; - if (Regex.IsMatch(jsonData, pattern)) - { - m_IndicatorList.Clear(); - MatchCollection m = Regex.Matches(jsonData, pattern); - foreach (Match match in m) - { - m_IndicatorList.Add(new Indicator() - { - name = match.Groups[1].Value - }); - } - } - pattern = "(\\d+)"; - if (Regex.IsMatch(jsonData, pattern)) - { - MatchCollection m = Regex.Matches(jsonData, pattern); - int index = 0; - foreach (Match match in m) - { - if (m_IndicatorList[index] != null) - { - m_IndicatorList[index].max = int.Parse(match.Groups[1].Value); - } - index++; - } - } - } - public float GetIndicatorMin(int index) { if (index >= 0 && index < m_IndicatorList.Count) diff --git a/Runtime/Component/Main/Serie.cs b/Runtime/Component/Main/Serie.cs index 1b94ab18..35a2abbd 100644 --- a/Runtime/Component/Main/Serie.cs +++ b/Runtime/Component/Main/Serie.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using System.Collections.Generic; @@ -226,9 +226,11 @@ namespace XCharts [SerializeField] private SerieType m_Type; [SerializeField] private string m_Name; [SerializeField] private string m_Stack; - [SerializeField] [Range(0, 1)] private int m_AxisIndex = 0; + [SerializeField] private int m_XAxisIndex = 0; + [SerializeField] private int m_YAxisIndex = 0; [SerializeField] private int m_RadarIndex = 0; [SerializeField] private int m_VesselIndex = 0; + [SerializeField] private int m_PolarIndex = 0; [SerializeField] protected int m_MinShow; [SerializeField] protected int m_MaxShow; [SerializeField] protected int m_MaxCache; @@ -267,7 +269,7 @@ namespace XCharts [SerializeField] private bool m_ClickOffset = true; [SerializeField] private RoseType m_RoseType = RoseType.None; [SerializeField] private float m_Space; - [SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f }; + [SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.45f }; [SerializeField] private float[] m_Radius = new float[2] { 0, 80 }; [SerializeField] private SerieLabel m_Label = new SerieLabel(); [SerializeField] private SerieAnimation m_Animation = new SerieAnimation(); @@ -310,7 +312,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) { SetVerticesDirty(); SetNameDirty(); } } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) { SetVerticesDirty(); SetNameDirty(); } } } /// <summary> /// the chart type of serie. @@ -319,7 +321,7 @@ namespace XCharts public SerieType type { get { return m_Type; } - set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); } } /// <summary> /// Series name used for displaying in tooltip and filtering with legend. @@ -328,7 +330,7 @@ namespace XCharts public string name { get { return m_Name; } - set { if (PropertyUtility.SetClass(ref m_Name, value)) { SetVerticesDirty(); SetNameDirty(); } } + set { if (PropertyUtil.SetClass(ref m_Name, value)) { SetVerticesDirty(); SetNameDirty(); } } } /// <summary> /// Legend name. When the serie name is not empty, the legend name is the series name; Otherwise, it is index. @@ -342,16 +344,25 @@ namespace XCharts public string stack { get { return m_Stack; } - set { if (PropertyUtility.SetClass(ref m_Stack, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_Stack, value)) SetVerticesDirty(); } } /// <summary> - /// Index of axis to combine with, which is useful for multiple x axes in one chart. - /// 使用的坐标轴轴的 index,在单个图表实例中存在多个坐标轴轴的时候有用。 + /// the index of XAxis. + /// 使用X轴的index。 /// </summary> - public int axisIndex + public int xAxisIndex { - get { return m_AxisIndex; } - set { if (PropertyUtility.SetStruct(ref m_AxisIndex, value)) SetVerticesDirty(); } + get { return m_XAxisIndex; } + set { if (PropertyUtil.SetStruct(ref m_XAxisIndex, value)) SetVerticesDirty(); } + } + /// <summary> + /// the index of YAxis. + /// 使用Y轴的index。 + /// </summary> + public int yAxisIndex + { + get { return m_YAxisIndex; } + set { if (PropertyUtil.SetStruct(ref m_YAxisIndex, value)) SetVerticesDirty(); } } /// <summary> /// Index of radar component that radar chart uses. @@ -360,7 +371,7 @@ namespace XCharts public int radarIndex { get { return m_RadarIndex; } - set { if (PropertyUtility.SetStruct(ref m_RadarIndex, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_RadarIndex, value)) SetVerticesDirty(); } } /// <summary> /// Index of vesel component that liquid chart uses. @@ -369,7 +380,16 @@ namespace XCharts public int vesselIndex { get { return m_VesselIndex; } - set { if (PropertyUtility.SetStruct(ref m_VesselIndex, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_VesselIndex, value)) SetVerticesDirty(); } + } + /// <summary> + /// Index of polar component that serie uses. + /// 所使用的 polar 组件的 index。 + /// </summary> + public int polarIndex + { + get { return m_PolarIndex; } + set { if (PropertyUtil.SetStruct(ref m_PolarIndex, value)) SetVerticesDirty(); } } /// <summary> /// The min number of data to show in chart. @@ -378,7 +398,7 @@ namespace XCharts public int minShow { get { return m_MinShow; } - set { if (PropertyUtility.SetStruct(ref m_MinShow, value < 0 ? 0 : value)) { SetVerticesDirty(); } } + set { if (PropertyUtil.SetStruct(ref m_MinShow, value < 0 ? 0 : value)) { SetVerticesDirty(); } } } /// <summary> /// The max number of data to show in chart. @@ -387,7 +407,7 @@ namespace XCharts public int maxShow { get { return m_MaxShow; } - set { if (PropertyUtility.SetStruct(ref m_MaxShow, value < 0 ? 0 : value)) { SetVerticesDirty(); } } + set { if (PropertyUtil.SetStruct(ref m_MaxShow, value < 0 ? 0 : value)) { SetVerticesDirty(); } } } /// <summary> /// The max number of serie data cache. @@ -398,7 +418,7 @@ namespace XCharts public int maxCache { get { return m_MaxCache; } - set { if (PropertyUtility.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) { SetVerticesDirty(); } } + set { if (PropertyUtil.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) { SetVerticesDirty(); } } } /// <summary> /// The style of area. @@ -407,7 +427,7 @@ namespace XCharts public AreaStyle areaStyle { get { return m_AreaStyle; } - set { if (PropertyUtility.SetClass(ref m_AreaStyle, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_AreaStyle, value, true)) SetVerticesDirty(); } } /// <summary> /// the symbol of serie data item. @@ -416,7 +436,7 @@ namespace XCharts public SerieSymbol symbol { get { return m_Symbol; } - set { if (PropertyUtility.SetClass(ref m_Symbol, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_Symbol, value, true)) SetVerticesDirty(); } } /// <summary> /// The type of line chart. @@ -425,7 +445,7 @@ namespace XCharts public LineType lineType { get { return m_LineType; } - set { if (PropertyUtility.SetStruct(ref m_LineType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); } } /// <summary> /// the min pixel dist of sample. @@ -434,7 +454,7 @@ namespace XCharts public float sampleDist { get { return m_SampleDist; } - set { if (PropertyUtility.SetStruct(ref m_SampleDist, value < 0 ? 0 : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SampleDist, value < 0 ? 0 : value)) SetVerticesDirty(); } } /// <summary> /// the type of sample. @@ -443,7 +463,7 @@ namespace XCharts public SampleType sampleType { get { return m_SampleType; } - set { if (PropertyUtility.SetStruct(ref m_SampleType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SampleType, value)) SetVerticesDirty(); } } /// <summary> /// 设定的采样平均值。当sampleType 为 Peak 时,用于和过滤数据的平均值做对比是取最大值还是最小值。默认为0时会实时计算所有数据的平均值。 @@ -451,7 +471,7 @@ namespace XCharts public float sampleAverage { get { return m_SampleAverage; } - set { if (PropertyUtility.SetStruct(ref m_SampleAverage, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SampleAverage, value)) SetVerticesDirty(); } } /// <summary> /// The style of line. @@ -460,7 +480,7 @@ namespace XCharts public LineStyle lineStyle { get { return m_LineStyle; } - set { if (PropertyUtility.SetClass(ref m_LineStyle, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_LineStyle, value, true)) SetVerticesDirty(); } } /// <summary> /// 柱形图类型。 @@ -468,7 +488,7 @@ namespace XCharts public BarType barType { get { return m_BarType; } - set { if (PropertyUtility.SetStruct(ref m_BarType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BarType, value)) SetVerticesDirty(); } } /// <summary> /// 柱形图是否为百分比堆积。相同stack的serie只要有一个barPercentStack为true,则就显示成百分比堆叠柱状图。 @@ -476,7 +496,7 @@ namespace XCharts public bool barPercentStack { get { return m_BarPercentStack; } - set { if (PropertyUtility.SetStruct(ref m_BarPercentStack, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BarPercentStack, value)) SetVerticesDirty(); } } /// <summary> /// The width of the bar. Adaptive when default 0. @@ -485,7 +505,7 @@ namespace XCharts public float barWidth { get { return m_BarWidth; } - set { if (PropertyUtility.SetStruct(ref m_BarWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BarWidth, value)) SetVerticesDirty(); } } /// <summary> /// The gap between bars between different series, is a percent value like '0.3f' , which means 30% of the bar width, can be set as a fixed value. @@ -500,7 +520,7 @@ namespace XCharts public float barGap { get { return m_BarGap; } - set { if (PropertyUtility.SetStruct(ref m_BarGap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BarGap, value)) SetVerticesDirty(); } } /// <summary> /// The bar gap of a single series, defaults to be 20% of the category gap, can be set as a fixed value. @@ -513,7 +533,7 @@ namespace XCharts public float barCategoryGap { get { return m_BarCategoryGap; } - set { if (PropertyUtility.SetStruct(ref m_BarCategoryGap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BarCategoryGap, value)) SetVerticesDirty(); } } /// <summary> /// 斑马线的粗细。 @@ -521,7 +541,7 @@ namespace XCharts public float barZebraWidth { get { return m_BarZebraWidth; } - set { if (PropertyUtility.SetStruct(ref m_BarZebraWidth, value < 0 ? 0 : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BarZebraWidth, value < 0 ? 0 : value)) SetVerticesDirty(); } } /// <summary> /// 斑马线的间距。 @@ -529,7 +549,7 @@ namespace XCharts public float barZebraGap { get { return m_BarZebraGap; } - set { if (PropertyUtility.SetStruct(ref m_BarZebraGap, value < 0 ? 0 : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BarZebraGap, value < 0 ? 0 : value)) SetVerticesDirty(); } } /// <summary> @@ -539,7 +559,7 @@ namespace XCharts public bool pieClickOffset { get { return m_ClickOffset; } - set { if (PropertyUtility.SetStruct(ref m_ClickOffset, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ClickOffset, value)) SetVerticesDirty(); } } /// <summary> /// Whether to show as Nightingale chart. @@ -548,7 +568,7 @@ namespace XCharts public RoseType pieRoseType { get { return m_RoseType; } - set { if (PropertyUtility.SetStruct(ref m_RoseType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_RoseType, value)) SetVerticesDirty(); } } /// <summary> /// the space of pie chart item. @@ -557,7 +577,7 @@ namespace XCharts public float pieSpace { get { return m_Space; } - set { if (PropertyUtility.SetStruct(ref m_Space, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Space, value)) SetVerticesDirty(); } } /// <summary> /// the center of chart. @@ -577,25 +597,13 @@ namespace XCharts get { return m_Radius; } set { if (value != null && value.Length == 2) { m_Radius = value; SetVerticesDirty(); } } } - [Obsolete("Use Serie.center instead.", true)] - public float[] pieCenter - { - get { return center; } - set { center = value; } - } - [Obsolete("Use Serie.radius instead.", true)] - public float[] pieRadius - { - get { return radius; } - set { radius = value; } - } /// <summary> /// 最小值,映射到 startAngle。 /// </summary> public float min { get { return m_Min; } - set { if (PropertyUtility.SetStruct(ref m_Min, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); } } /// <summary> /// 最大值,映射到 endAngle。 @@ -603,7 +611,7 @@ namespace XCharts public float max { get { return m_Max; } - set { if (PropertyUtility.SetStruct(ref m_Max, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Max, value)) SetVerticesDirty(); } } /// <summary> /// 起始角度。和时钟一样,12点钟位置是0度,顺时针到360度。 @@ -611,7 +619,7 @@ namespace XCharts public float startAngle { get { return m_StartAngle; } - set { if (PropertyUtility.SetStruct(ref m_StartAngle, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_StartAngle, value)) SetVerticesDirty(); } } /// <summary> /// 结束角度。和时钟一样,12点钟位置是0度,顺时针到360度。 @@ -619,7 +627,7 @@ namespace XCharts public float endAngle { get { return m_EndAngle; } - set { if (PropertyUtility.SetStruct(ref m_EndAngle, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_EndAngle, value)) SetVerticesDirty(); } } /// <summary> /// 是否顺时针。 @@ -627,7 +635,7 @@ namespace XCharts public bool clockwise { get { return m_Clockwise; } - set { if (PropertyUtility.SetStruct(ref m_Clockwise, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetVerticesDirty(); } } /// <summary> @@ -636,7 +644,7 @@ namespace XCharts public float ringGap { get { return m_RingGap; } - set { if (PropertyUtility.SetStruct(ref m_RingGap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_RingGap, value)) SetVerticesDirty(); } } /// <summary> /// 刻度分割段数。最大可设置36。 @@ -644,7 +652,7 @@ namespace XCharts public int splitNumber { get { return m_SplitNumber; } - set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value > 36 ? 36 : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value > 36 ? 36 : value)) SetVerticesDirty(); } } /// <summary> /// 是否开启圆弧效果。 @@ -652,7 +660,7 @@ namespace XCharts public bool roundCap { get { return m_RoundCap; } - set { if (PropertyUtility.SetStruct(ref m_RoundCap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_RoundCap, value)) SetVerticesDirty(); } } /// <summary> /// 是否开启忽略数据。当为 true 时,数据值为 ignoreValue 时不进行绘制。 @@ -660,7 +668,7 @@ namespace XCharts public bool ignore { get { return m_Ignore; } - set { if (PropertyUtility.SetStruct(ref m_Ignore, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Ignore, value)) SetVerticesDirty(); } } /// <summary> /// 忽略数据的默认值。当ignore为true才有效。 @@ -668,7 +676,7 @@ namespace XCharts public float ignoreValue { get { return m_IgnoreValue; } - set { if (PropertyUtility.SetStruct(ref m_IgnoreValue, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_IgnoreValue, value)) SetVerticesDirty(); } } /// <summary> /// 雷达图类型。 @@ -676,7 +684,7 @@ namespace XCharts public RadarType radarType { get { return m_RadarType; } - set { if (PropertyUtility.SetStruct(ref m_RadarType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_RadarType, value)) SetVerticesDirty(); } } /// <summary> /// 仪表盘轴线。 @@ -684,7 +692,7 @@ namespace XCharts public GaugeAxis gaugeAxis { get { return m_GaugeAxis; } - set { if (PropertyUtility.SetClass(ref m_GaugeAxis, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_GaugeAxis, value, true)) SetVerticesDirty(); } } /// <summary> /// 仪表盘指针。 @@ -692,7 +700,7 @@ namespace XCharts public GaugePointer gaugePointer { get { return m_GaugePointer; } - set { if (PropertyUtility.SetClass(ref m_GaugePointer, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_GaugePointer, value, true)) SetVerticesDirty(); } } /// <summary> /// 仪表盘类型。 @@ -700,7 +708,7 @@ namespace XCharts public GaugeType gaugeType { get { return m_GaugeType; } - set { if (PropertyUtility.SetStruct(ref m_GaugeType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_GaugeType, value)) SetVerticesDirty(); } } /// <summary> /// Text label of graphic element,to explain some data information about graphic item like value, name and so on. @@ -709,7 +717,7 @@ namespace XCharts public SerieLabel label { get { return m_Label; } - set { if (PropertyUtility.SetClass(ref m_Label, value, true)) SetAllDirty(); } + set { if (PropertyUtil.SetClass(ref m_Label, value, true)) SetAllDirty(); } } /// <summary> /// The start animation. @@ -718,7 +726,7 @@ namespace XCharts public SerieAnimation animation { get { return m_Animation; } - set { if (PropertyUtility.SetClass(ref m_Animation, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_Animation, value, true)) SetVerticesDirty(); } } /// <summary> /// The arrow of line. @@ -727,7 +735,7 @@ namespace XCharts public LineArrow lineArrow { get { return m_LineArrow; } - set { if (PropertyUtility.SetClass(ref m_LineArrow, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_LineArrow, value, true)) SetVerticesDirty(); } } /// <summary> /// The style of data item. @@ -736,7 +744,7 @@ namespace XCharts public ItemStyle itemStyle { get { return m_ItemStyle; } - set { if (PropertyUtility.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); } } /// <summary> /// 高亮的图形样式和文本标签样式。 @@ -744,7 +752,7 @@ namespace XCharts public Emphasis emphasis { get { return m_Emphasis; } - set { if (PropertyUtility.SetClass(ref m_Emphasis, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_Emphasis, value, true)) SetVerticesDirty(); } } /// <summary> /// 标题样式。 @@ -752,7 +760,7 @@ namespace XCharts public TitleStyle titleStyle { get { return m_TitleStyle; } - set { if (PropertyUtility.SetClass(ref m_TitleStyle, value, true)) SetAllDirty(); } + set { if (PropertyUtil.SetClass(ref m_TitleStyle, value, true)) SetAllDirty(); } } /// <summary> /// 数据项里的数据维数。 @@ -769,7 +777,7 @@ namespace XCharts public bool clip { get { return m_Clip; } - set { if (PropertyUtility.SetStruct(ref m_Clip, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Clip, value)) SetVerticesDirty(); } } /// <summary> /// Show negative number as positive number. @@ -778,7 +786,7 @@ namespace XCharts public bool showAsPositiveNumber { get { return m_ShowAsPositiveNumber; } - set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); } } /// <summary> /// 是否开启大数据量优化,在数据图形特别多而出现卡顿时候可以开启。 @@ -790,7 +798,7 @@ namespace XCharts get { return m_Large; } set { - if (PropertyUtility.SetStruct(ref m_Large, value)) + if (PropertyUtil.SetStruct(ref m_Large, value)) { SetAllDirty(); label.SetComponentDirty(); @@ -805,7 +813,7 @@ namespace XCharts get { return m_LargeThreshold; } set { - if (PropertyUtility.SetStruct(ref m_LargeThreshold, value)) + if (PropertyUtil.SetStruct(ref m_LargeThreshold, value)) { SetAllDirty(); label.SetComponentDirty(); @@ -818,7 +826,7 @@ namespace XCharts public bool avoidLabelOverlap { get { return m_AvoidLabelOverlap; } - set { if (PropertyUtility.SetStruct(ref m_AvoidLabelOverlap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_AvoidLabelOverlap, value)) SetVerticesDirty(); } } /// <summary> /// Wave length of the wave, which is relative to the diameter. @@ -827,7 +835,7 @@ namespace XCharts public float waveLength { get { return m_WaveLength; } - set { if (PropertyUtility.SetStruct(ref m_WaveLength, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_WaveLength, value)) SetVerticesDirty(); } } /// <summary> /// 波高。 @@ -835,7 +843,7 @@ namespace XCharts public float waveHeight { get { return m_WaveHeight; } - set { if (PropertyUtility.SetStruct(ref m_WaveHeight, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_WaveHeight, value)) SetVerticesDirty(); } } /// <summary> /// 波偏移。 @@ -843,7 +851,7 @@ namespace XCharts public float waveOffset { get { return m_WaveOffset; } - set { if (PropertyUtility.SetStruct(ref m_WaveOffset, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_WaveOffset, value)) SetVerticesDirty(); } } /// <summary> /// 波速。正数时左移,负数时右移。 @@ -851,7 +859,7 @@ namespace XCharts public float waveSpeed { get { return m_WaveSpeed; } - set { if (PropertyUtility.SetStruct(ref m_WaveSpeed, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_WaveSpeed, value)) SetVerticesDirty(); } } /// <summary> /// 系列中的数据内容数组。SerieData可以设置1到n维数据。 @@ -950,7 +958,9 @@ namespace XCharts /// </summary> public float runtimePieDataTotal { get; internal set; } public float runtimeWaveSpeed { get; internal set; } + public Painter runtimeCanvas { get; internal set; } internal float runtimeCheckValue { get; set; } + public int runtimeGridIndex { get; internal set; } public bool nameDirty { get { return m_NameDirty; } } private void SetNameDirty() @@ -1413,7 +1423,8 @@ namespace XCharts /// <returns></returns> public List<SerieData> GetDataList(DataZoom dataZoom = null) { - if (dataZoom != null && dataZoom.enable) + if (dataZoom != null && dataZoom.enable + && (dataZoom.xAxisIndexs.Contains(xAxisIndex) || dataZoom.yAxisIndexs.Contains(yAxisIndex))) { UpdateFilterData(dataZoom); return m_FilterData; @@ -1431,7 +1442,8 @@ namespace XCharts /// <param name="dataZoom"></param> internal void UpdateFilterData(DataZoom dataZoom) { - if (dataZoom != null && dataZoom.enable) + if (dataZoom != null && dataZoom.enable + && (dataZoom.xAxisIndexs.Contains(xAxisIndex) || dataZoom.yAxisIndexs.Contains(yAxisIndex))) { var startIndex = (int)((data.Count - 1) * dataZoom.start / 100); var endIndex = (int)((data.Count - 1) * dataZoom.end / 100); @@ -1674,6 +1686,14 @@ namespace XCharts return false; } + public bool IsCoordinateSerie() + { + return type == SerieType.Line + || type == SerieType.Bar + || type == SerieType.Scatter + || type == SerieType.Heatmap; + } + /// <summary> /// 设置指定index的数据图标的尺寸 /// </summary> @@ -1708,9 +1728,9 @@ namespace XCharts /// 从json中导入数据 /// </summary> /// <param name="jsonData"></param> - public override void ParseJsonData(string jsonData) + public void ParseJsonData(string jsonData) { - if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return; + if (string.IsNullOrEmpty(jsonData)) return; jsonData = jsonData.Replace("\r\n", ""); jsonData = jsonData.Replace(" ", ""); jsonData = jsonData.Replace("\n", ""); diff --git a/Runtime/Component/Main/Series.cs b/Runtime/Component/Main/Series.cs index 18db6070..946f9a8e 100644 --- a/Runtime/Component/Main/Series.cs +++ b/Runtime/Component/Main/Series.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using System.Collections.Generic; @@ -21,10 +21,6 @@ namespace XCharts [SerializeField] protected List<Serie> m_Series; [NonSerialized] private bool m_LabelDirty; - [Obsolete("Use Series.list instead.", true)] - public List<Serie> series { get { return m_Series; } } - - /// <summary> /// the list of serie /// 系列列表。 @@ -261,15 +257,11 @@ namespace XCharts { serie.symbol.show = true; serie.symbol.type = SerieSymbolType.Circle; - serie.symbol.size = 20f; - serie.symbol.selectedSize = 30f; } else if (type == SerieType.Line) { serie.symbol.show = true; serie.symbol.type = SerieSymbolType.EmptyCircle; - serie.symbol.size = 2.5f; - serie.symbol.selectedSize = 5f; } else { @@ -698,14 +690,5 @@ namespace XCharts if (serie.animation.enable) serie.animation.Reset(); } } - - /// <summary> - /// 从json中解析数据 - /// </summary> - /// <param name="jsonData"></param> - public override void ParseJsonData(string jsonData) - { - //TODO: - } } } diff --git a/Runtime/Component/Main/Settings.cs b/Runtime/Component/Main/Settings.cs index 50b8a248..d81c6737 100644 --- a/Runtime/Component/Main/Settings.cs +++ b/Runtime/Component/Main/Settings.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using System; @@ -17,14 +17,21 @@ namespace XCharts [Serializable] public class Settings : MainComponent { + [SerializeField] [Range(1, 20)] protected int m_MaxPainter = 10; [SerializeField] [Range(1, 10)] protected float m_LineSmoothStyle = 3f; [SerializeField] [Range(1f, 20)] protected float m_LineSmoothness = 2f; [SerializeField] [Range(1f, 20)] protected float m_LineSegmentDistance = 3f; [SerializeField] [Range(1, 10)] protected float m_CicleSmoothness = 2f; - [SerializeField] [Range(10, 50)] protected float m_VisualMapTriangeLen = 20f; - [SerializeField] [Range(1, 20)] protected float m_PieTooltipExtraRadius = 8f; - [SerializeField] [Range(1, 20)] protected float m_PieSelectedOffset = 8f; + /// <summary> + /// max painter. + /// 设定的painter数量。 + /// </summary> + public int maxPainter + { + get { return m_MaxPainter; } + set { if (PropertyUtil.SetStruct(ref m_MaxPainter, value < 0 ? 1 : value)) SetVerticesDirty(); } + } /// <summary> /// Curve smoothing factor. By adjusting the smoothing coefficient, the curvature of the curve can be changed, /// and different curves with slightly different appearance can be obtained. @@ -33,7 +40,7 @@ namespace XCharts public float lineSmoothStyle { get { return m_LineSmoothStyle; } - set { if (PropertyUtility.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); } } /// <summary> /// Smoothness of curve. The smaller the value, the smoother the curve, but the number of vertices will increase. @@ -44,7 +51,7 @@ namespace XCharts public float lineSmoothness { get { return m_LineSmoothness; } - set { if (PropertyUtility.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); } } /// <summary> /// The partition distance of a line segment. A line in a normal line chart is made up of many segments, @@ -56,7 +63,7 @@ namespace XCharts public float lineSegmentDistance { get { return m_LineSegmentDistance; } - set { if (PropertyUtility.SetStruct(ref m_LineSegmentDistance, value < 0 ? 1f : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineSegmentDistance, value < 0 ? 1f : value)) SetVerticesDirty(); } } /// <summary> /// the smoothess of cricle. @@ -65,32 +72,36 @@ namespace XCharts public float cicleSmoothness { get { return m_CicleSmoothness; } - set { if (PropertyUtility.SetStruct(ref m_CicleSmoothness, value < 0 ? 1f : value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_CicleSmoothness, value < 0 ? 1f : value)) SetVerticesDirty(); } } - /// <summary> - /// 可视化组件的调节三角形边长。 - /// </summary> - /// <value></value> - public float visualMapTriangeLen + + public void Copy(Settings settings) { - get { return m_VisualMapTriangeLen; } - set { if (PropertyUtility.SetStruct(ref m_VisualMapTriangeLen, value < 0 ? 1f : value)) SetVerticesDirty(); } + m_MaxPainter = settings.maxPainter; + m_LineSmoothStyle = settings.lineSmoothStyle; + m_LineSmoothness = settings.lineSmoothness; + m_LineSegmentDistance = settings.lineSegmentDistance; + m_CicleSmoothness = settings.cicleSmoothness; } - /// <summary> - /// 饼图鼠标移到高亮时的额外半径 - /// </summary> - public float pieTooltipExtraRadius + + public void Reset() { - get { return m_PieTooltipExtraRadius; } - set { if (PropertyUtility.SetStruct(ref m_PieTooltipExtraRadius, value < 0 ? 0f : value)) SetVerticesDirty(); } + Copy(DefaultSettings); } - /// <summary> - /// 饼图选中时的中心点偏移 - /// </summary> - public float pieSelectedOffset + + public static Settings DefaultSettings { - get { return m_PieSelectedOffset; } - set { if (PropertyUtility.SetStruct(ref m_PieSelectedOffset, value < 0 ? 0f : value)) SetVerticesDirty(); } + get + { + return new Settings() + { + m_MaxPainter = XChartsSettings.maxPainter, + m_LineSmoothStyle = XChartsSettings.lineSmoothStyle, + m_LineSmoothness = XChartsSettings.lineSmoothness, + m_LineSegmentDistance = XChartsSettings.lineSegmentDistance, + m_CicleSmoothness = XChartsSettings.cicleSmoothness, + }; + } } } } \ No newline at end of file diff --git a/Runtime/Component/Main/Theme.cs b/Runtime/Component/Main/Theme.cs deleted file mode 100644 index 20591f68..00000000 --- a/Runtime/Component/Main/Theme.cs +++ /dev/null @@ -1,629 +0,0 @@ -using System.Text; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; -using UnityEngine; -using System; -using UnityEngine.Serialization; - -namespace XCharts -{ - /// <summary> - /// 主题 - /// </summary> - public enum Theme - { - /// <summary> - /// 默认主题。 - /// </summary> - Default, - /// <summary> - /// 亮主题。 - /// </summary> - Light, - /// <summary> - /// 暗主题。 - /// </summary> - Dark - } - - [Serializable] - /// <summary> - /// Theme. - /// 主题相关配置。 - /// </summary> - public class ThemeInfo : MainComponent - { - [SerializeField] private Theme m_Theme = Theme.Default; - [SerializeField] private Font m_Font; - [SerializeField] private Color32 m_BackgroundColor; - [FormerlySerializedAs("m_TextColor")] - [SerializeField] private Color32 m_TitleTextColor; - [SerializeField] private Color32 m_TitleSubTextColor; - [SerializeField] private Color32 m_LegendTextColor; - [SerializeField] private Color32 m_LegendUnableColor; - [SerializeField] private Color32 m_AxisTextColor; - [SerializeField] private Color32 m_AxisLineColor; - [SerializeField] private Color32 m_AxisSplitLineColor; - [SerializeField] private Color32 m_TooltipBackgroundColor; - [SerializeField] private Color32 m_TooltipFlagAreaColor; - [SerializeField] private Color32 m_TooltipTextColor; - [SerializeField] private Color32 m_TooltipLabelColor; - [SerializeField] private Color32 m_TooltipLineColor; - [SerializeField] private Color32 m_DataZoomTextColor; - [SerializeField] private Color32 m_DataZoomLineColor; - [SerializeField] private Color32 m_DataZoomSelectedColor; - [SerializeField] private Color32 m_VisualMapBackgroundColor; - [SerializeField] private Color32 m_VisualMapBorderColor; - [SerializeField] private Color32[] m_ColorPalette; - - [SerializeField] private Font m_CustomFont; - [SerializeField] private Color32 m_CustomBackgroundColor; - [FormerlySerializedAs("m_CustomTextColor")] - [SerializeField] private Color32 m_CustomTitleTextColor; - [SerializeField] private Color32 m_CustomTitleSubTextColor; - [SerializeField] private Color32 m_CustomLegendTextColor; - [SerializeField] private Color32 m_CustomLegendUnableColor; - [SerializeField] private Color32 m_CustomAxisTextColor; - [SerializeField] private Color32 m_CustomAxisLineColor; - [SerializeField] private Color32 m_CustomAxisSplitLineColor; - [SerializeField] private Color32 m_CustomTooltipBackgroundColor; - [SerializeField] private Color32 m_CustomTooltipFlagAreaColor; - [SerializeField] private Color32 m_CustomTooltipTextColor; - [SerializeField] private Color32 m_CustomTooltipLabelColor; - [SerializeField] private Color32 m_CustomTooltipLineColor; - [SerializeField] private Color32 m_CustomDataZoomTextColor; - [SerializeField] private Color32 m_CustomDataZoomLineColor; - [SerializeField] private Color32 m_CustomDataZoomSelectedColor; - [SerializeField] private Color32 m_CustomVisualMapBackgroundColor; - [SerializeField] private Color32 m_CustomVisualMapBorderColor; - [SerializeField] private List<Color32> m_CustomColorPalette = new List<Color32>(13); - /// <summary> - /// the theme of chart. - /// 主题类型。 - /// </summary> - public Theme theme - { - get { return m_Theme; } - set { if (PropertyUtility.SetStruct(ref m_Theme, value)) SetComponentDirty(); } - } - /// <summary> - /// the font of chart text。 - /// 字体。 - /// </summary> - public Font font - { - get { return m_CustomFont != null ? m_CustomFont : m_Font; } - set { if (PropertyUtility.SetClass(ref m_CustomFont, value)) SetComponentDirty(); } - } - /// <summary> - /// the background color of chart. - /// 背景颜色。 - /// </summary> - public Color32 backgroundColor - { - get { return !ChartHelper.IsClearColor(m_CustomBackgroundColor) ? m_CustomBackgroundColor : m_BackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_CustomBackgroundColor, value)) SetVerticesDirty(); } - } - /// <summary> - /// the main title text color. - /// 主标题颜色。 - /// </summary> - public Color32 titleTextColor - { - get { return !ChartHelper.IsClearColor(m_CustomTitleTextColor) ? m_CustomTitleTextColor : m_TitleTextColor; } - set { if (PropertyUtility.SetColor(ref m_CustomTitleTextColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the subtitie text color. - /// 副标题颜色。 - /// </summary> - public Color32 titleSubTextColor - { - get { return !ChartHelper.IsClearColor(m_CustomTitleSubTextColor) ? m_CustomTitleSubTextColor : m_TitleSubTextColor; } - set { if (PropertyUtility.SetColor(ref m_CustomTitleSubTextColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the legend text color. - /// 图例文字的颜色。 - /// </summary> - public Color32 legendTextColor - { - get { return !ChartHelper.IsClearColor(m_CustomLegendTextColor) ? m_CustomLegendTextColor : m_LegendTextColor; } - set { if (PropertyUtility.SetColor(ref m_CustomLegendTextColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the legend unable text color. - /// 图例变为不可用时的按钮颜色。 - /// </summary> - public Color32 legendUnableColor - { - get { return !ChartHelper.IsClearColor(m_CustomLegendUnableColor) ? m_CustomLegendUnableColor : m_LegendUnableColor; } - set { if (PropertyUtility.SetColor(ref m_CustomLegendUnableColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the axis text color. - /// 坐标轴上标签的颜色。 - /// </summary> - public Color32 axisTextColor - { - get { return !ChartHelper.IsClearColor(m_CustomAxisTextColor) ? m_CustomAxisTextColor : m_AxisTextColor; } - set { if (PropertyUtility.SetColor(ref m_CustomAxisTextColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the color of axis line. - /// 坐标轴轴线的颜色。 - /// </summary> - public Color32 axisLineColor - { - get { return !ChartHelper.IsClearColor(m_CustomAxisLineColor) ? m_CustomAxisLineColor : m_AxisLineColor; } - set { if (PropertyUtility.SetColor(ref m_CustomAxisLineColor, value)) SetVerticesDirty(); } - } - /// <summary> - /// the color of axis split line. - /// 分割线的颜色,默认和坐标轴轴线颜色一致。 - /// </summary> - public Color32 axisSplitLineColor - { - get { return !ChartHelper.IsClearColor(m_CustomAxisSplitLineColor) ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor; } - set { if (PropertyUtility.SetColor(ref m_CustomAxisSplitLineColor, value)) SetVerticesDirty(); } - } - /// <summary> - /// the tooltip background color. - /// 提示框背景颜色。 - /// </summary> - public Color32 tooltipBackgroundColor - { - get { return !ChartHelper.IsClearColor(m_CustomTooltipBackgroundColor) ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_CustomTooltipBackgroundColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the color of tooltip shadow crosshair indicator. - /// 提示框阴影指示器的颜色。 - /// </summary> - public Color32 tooltipFlagAreaColor - { - get { return !ChartHelper.IsClearColor(m_CustomTooltipFlagAreaColor) ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor; } - set { if (PropertyUtility.SetColor(ref m_CustomTooltipFlagAreaColor, value)) SetVerticesDirty(); } - } - /// <summary> - /// the color of tooltip text. - /// 提示框文字颜色。 - /// </summary> - public Color32 tooltipTextColor - { - get { return !ChartHelper.IsClearColor(m_CustomTooltipTextColor) ? m_CustomTooltipTextColor : m_TooltipTextColor; } - set { if (PropertyUtility.SetColor(ref m_CustomTooltipTextColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the background color of tooltip cross indicator's axis label. - /// 提示框的十字指示器坐标轴标签的背景颜色。 - /// </summary> - public Color32 tooltipLabelColor - { - get { return !ChartHelper.IsClearColor(m_CustomTooltipLabelColor) ? m_CustomTooltipLabelColor : m_TooltipLabelColor; } - set { if (PropertyUtility.SetColor(ref m_CustomTooltipLabelColor, value)) SetVerticesDirty(); } - } - /// <summary> - /// the color tooltip indicator line. - /// 提示框的指示线的颜色。 - /// </summary> - public Color32 tooltipLineColor - { - get { return !ChartHelper.IsClearColor(m_CustomTooltipLineColor) ? m_CustomTooltipLineColor : m_TooltipLineColor; } - set { if (PropertyUtility.SetColor(ref m_CustomTooltipLineColor, value)) SetVerticesDirty(); } - } - /// <summary> - /// the color of datazoom text. - /// 区域缩放的文字颜色。 - /// </summary> - public Color32 dataZoomTextColor - { - get { return !ChartHelper.IsClearColor(m_CustomDataZoomTextColor) ? m_CustomDataZoomTextColor : m_DataZoomTextColor; } - set { if (PropertyUtility.SetColor(ref m_CustomDataZoomTextColor, value)) SetComponentDirty(); } - } - /// <summary> - /// the color of datazoom line. - /// 区域缩放的线条颜色。 - /// </summary> - public Color32 dataZoomLineColor - { - get { return !ChartHelper.IsClearColor(m_CustomDataZoomLineColor) ? m_CustomDataZoomLineColor : m_DataZoomLineColor; } - set { if (PropertyUtility.SetColor(ref m_CustomDataZoomLineColor, value)) SetVerticesDirty(); } - } - /// <summary> - /// the color of datazoom selected area. - /// 区域缩放的选中区域颜色。 - /// </summary> - public Color32 dataZoomSelectedColor - { - get { return !ChartHelper.IsClearColor(m_CustomDataZoomSelectedColor) ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor; } - set { if (PropertyUtility.SetColor(ref m_CustomDataZoomSelectedColor, value)) SetVerticesDirty(); } - } - - /// <summary> - /// 视觉映射组件的背景色。 - /// </summary> - public Color32 visualMapBackgroundColor - { - get { return !ChartHelper.IsClearColor(m_CustomVisualMapBackgroundColor) ? m_CustomVisualMapBackgroundColor : m_VisualMapBackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_CustomVisualMapBackgroundColor, value)) SetVerticesDirty(); } - } - - /// <summary> - /// 视觉映射的边框色。 - /// </summary> - public Color32 visualMapBorderColor - { - get { return !ChartHelper.IsClearColor(m_CustomVisualMapBorderColor) ? m_CustomVisualMapBorderColor : m_VisualMapBorderColor; } - set { if (PropertyUtility.SetColor(ref m_CustomVisualMapBorderColor, value)) SetVerticesDirty(); } - } - - /// <summary> - /// The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series. - /// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。 - /// </summary> - public List<Color32> colorPalette { set { m_CustomColorPalette = value; SetVerticesDirty(); } } - - /// <summary> - /// Gets the color of the specified index from the palette. - /// 获得调色盘对应系列索引的颜色值。 - /// </summary> - /// <param name="index">编号索引</param> - /// <returns>the color,or Color.clear when failed.颜色值,失败时返回Color.clear</returns> - public Color32 GetColor(int index) - { - if (index < 0) index = 0; - if (m_CustomColorPalette.Count > 0) - { - var customIndex = index < m_CustomColorPalette.Count ? index : index % m_CustomColorPalette.Count; - if (customIndex < m_CustomColorPalette.Count - && !ChartHelper.IsClearColor(m_CustomColorPalette[customIndex])) - { - return m_CustomColorPalette[customIndex]; - } - } - var newIndex = index < m_ColorPalette.Length ? index : index % m_ColorPalette.Length; - if (newIndex < m_ColorPalette.Length) - return m_ColorPalette[newIndex]; - else return Color.clear; - } - - public void CheckWarning(StringBuilder sb) - { - if (m_Font == null && m_CustomFont == null) - { - sb.AppendFormat("warning:theme->font is null\n"); - } - if (m_ColorPalette.Length == 0 && m_CustomColorPalette.Count == 0) - { - sb.AppendFormat("warning:theme->colorPalette is empty\n"); - } - for (int i = 0; i < m_ColorPalette.Length; i++) - { - if (!ChartHelper.IsClearColor(m_ColorPalette[i]) && m_ColorPalette[i].a == 0) - sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i); - } - for (int i = 0; i < m_CustomColorPalette.Count; i++) - { - if (!ChartHelper.IsClearColor(m_CustomColorPalette[i]) && m_CustomColorPalette[i].a == 0) - sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i); - } - } - - Dictionary<int, string> _colorDic = new Dictionary<int, string>(); - /// <summary> - /// Gets the hexadecimal color string of the specified index from the palette. - /// 获得指定索引的十六进制颜色值字符串。 - /// </summary> - /// <param name="index"></param> - /// <returns></returns> - public string GetColorStr(int index) - { - if (index < 0) - { - index = 0; - } - index = index % m_ColorPalette.Length; - if (_colorDic.ContainsKey(index)) return _colorDic[index]; - else - { - _colorDic[index] = ColorUtility.ToHtmlStringRGBA(GetColor(index)); - return _colorDic[index]; - } - } - - public void Copy(Theme theme) - { - switch (theme) - { - case Theme.Dark: - Copy(ThemeInfo.Dark); - break; - case Theme.Default: - Copy(ThemeInfo.Default); - break; - case Theme.Light: - Copy(ThemeInfo.Light); - break; - } - } - - /// <summary> - /// copy all configurations from theme. - /// 复制主题的所有配置。 - /// </summary> - /// <param name="theme"></param> - public void Copy(ThemeInfo theme) - { - m_Theme = theme.theme; - m_Font = theme.m_Font; - m_BackgroundColor = theme.m_BackgroundColor; - m_LegendUnableColor = theme.m_LegendUnableColor; - m_TitleTextColor = theme.m_TitleTextColor; - m_TitleSubTextColor = theme.m_TitleSubTextColor; - m_LegendTextColor = theme.m_LegendTextColor; - m_AxisTextColor = theme.m_AxisTextColor; - m_AxisLineColor = theme.m_AxisLineColor; - m_AxisSplitLineColor = theme.m_AxisSplitLineColor; - m_TooltipBackgroundColor = theme.m_TooltipBackgroundColor; - m_TooltipTextColor = theme.m_TooltipTextColor; - m_TooltipLabelColor = theme.m_TooltipLabelColor; - m_TooltipLineColor = theme.m_TooltipLineColor; - m_DataZoomLineColor = theme.m_DataZoomLineColor; - m_DataZoomSelectedColor = theme.m_DataZoomSelectedColor; - m_DataZoomTextColor = theme.m_DataZoomTextColor; - m_VisualMapBackgroundColor = theme.m_VisualMapBackgroundColor; - m_VisualMapBorderColor = theme.m_VisualMapBorderColor; - m_ColorPalette = new Color32[theme.m_ColorPalette.Length]; - for (int i = 0; i < theme.m_ColorPalette.Length; i++) - { - m_ColorPalette[i] = theme.m_ColorPalette[i]; - } - } - - /// <summary> - /// Clear all custom configurations. - /// 重置,清除所有自定义配置。 - /// </summary> - public void Reset() - { - m_Theme = Theme.Default; - m_Font = null; - m_BackgroundColor = Color.clear; - m_LegendUnableColor = Color.clear; - m_TitleTextColor = Color.clear; - m_TitleSubTextColor = Color.clear; - m_LegendTextColor = Color.clear; - m_AxisTextColor = Color.clear; - m_AxisLineColor = Color.clear; - m_AxisSplitLineColor = Color.clear; - m_TooltipBackgroundColor = Color.clear; - m_TooltipTextColor = Color.clear; - m_TooltipLabelColor = Color.clear; - m_TooltipLineColor = Color.clear; - m_DataZoomLineColor = Color.clear; - m_DataZoomSelectedColor = Color.clear; - m_DataZoomTextColor = Color.clear; - m_VisualMapBackgroundColor = Color.clear; - m_VisualMapBorderColor = Color.clear; - for (int i = 0; i < m_CustomColorPalette.Count; i++) - { - m_CustomColorPalette[i] = Color.clear; - } - } - - /// <summary> - /// default theme. - /// 默认主题。 - /// </summary> - /// <value></value> - public static ThemeInfo Default - { - get - { - return new ThemeInfo() - { - m_Theme = Theme.Default, - m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"), - m_BackgroundColor = new Color32(255, 255, 255, 255), - m_LegendUnableColor = GetColor("#cccccc"), - m_TitleTextColor = GetColor("#514D4D"), - m_TitleSubTextColor = GetColor("#514D4D"), - m_LegendTextColor = GetColor("#514D4D"), - m_AxisTextColor = GetColor("#514D4D"), - m_AxisLineColor = GetColor("#514D4D"), - m_AxisSplitLineColor = GetColor("#51515120"), - m_TooltipBackgroundColor = GetColor("#515151C8"), - m_TooltipTextColor = GetColor("#FFFFFFFF"), - m_TooltipFlagAreaColor = GetColor("#51515120"), - m_TooltipLabelColor = GetColor("#292929FF"), - m_TooltipLineColor = GetColor("#29292964"), - m_DataZoomLineColor = GetColor("#51515120"), - m_DataZoomSelectedColor = GetColor("#51515120"), - m_DataZoomTextColor = GetColor("#514D4D"), - m_VisualMapBackgroundColor = GetColor("#51515120"), - m_VisualMapBorderColor = GetColor("#cccccc"), - m_ColorPalette = new Color32[] - { - new Color32(194, 53, 49, 255), - new Color32(47, 69, 84, 255), - new Color32(97, 160, 168, 255), - new Color32(212, 130, 101, 255), - new Color32(145, 199, 174, 255), - new Color32(116, 159, 131, 255), - new Color32(202, 134, 34, 255), - new Color32(189, 162, 154, 255), - new Color32(110, 112, 116, 255), - new Color32(84, 101, 112, 255), - new Color32(196, 204, 211, 255) - }, - m_CustomColorPalette = new List<Color32>{ - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear - } - }; - } - } - - /// <summary> - /// light theme. - /// 亮主题。 - /// </summary> - /// <value></value> - public static ThemeInfo Light - { - get - { - return new ThemeInfo() - { - m_Theme = Theme.Light, - m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"), - m_BackgroundColor = new Color32(255, 255, 255, 255), - m_LegendUnableColor = GetColor("#cccccc"), - m_TitleTextColor = GetColor("#514D4D"), - m_TitleSubTextColor = GetColor("#514D4D"), - m_LegendTextColor = GetColor("#514D4D"), - m_AxisTextColor = GetColor("#514D4D"), - m_AxisLineColor = GetColor("#514D4D"), - m_AxisSplitLineColor = GetColor("#51515120"), - m_TooltipBackgroundColor = GetColor("#515151C8"), - m_TooltipTextColor = GetColor("#FFFFFFFF"), - m_TooltipFlagAreaColor = GetColor("#51515120"), - m_TooltipLabelColor = GetColor("#292929FF"), - m_TooltipLineColor = GetColor("#29292964"), - m_DataZoomLineColor = GetColor("#51515120"), - m_DataZoomSelectedColor = GetColor("#51515120"), - m_DataZoomTextColor = GetColor("#514D4D"), - m_VisualMapBackgroundColor = GetColor("#51515120"), - m_VisualMapBorderColor = GetColor("#cccccc"), - m_ColorPalette = new Color32[] - { - new Color32(55, 162, 218, 255), - new Color32(255, 159, 127, 255), - new Color32(50, 197, 233, 255), - new Color32(251, 114, 147, 255), - new Color32(103, 224, 227, 255), - new Color32(224, 98, 174, 255), - new Color32(159, 230, 184, 255), - new Color32(230, 144, 209, 255), - new Color32(255, 219, 92, 255), - new Color32(230, 188, 243, 255), - new Color32(157, 150, 245, 255), - new Color32(131, 120, 234, 255), - new Color32(150, 191, 255, 255) - }, - m_CustomColorPalette = new List<Color32>{ - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear - } - }; - } - } - - /// <summary> - /// dark theme. - /// 暗主题。 - /// </summary> - /// <value></value> - public static ThemeInfo Dark - { - get - { - return new ThemeInfo() - { - m_Theme = Theme.Dark, - m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"), - m_LegendUnableColor = GetColor("#cccccc"), - m_BackgroundColor = new Color32(34, 34, 34, 255), - m_TitleTextColor = GetColor("#eee"), - m_TitleSubTextColor = GetColor("#eee"), - m_LegendTextColor = GetColor("#eee"), - m_AxisTextColor = GetColor("#eee"), - m_AxisLineColor = GetColor("#eee"), - m_AxisSplitLineColor = GetColor("#aaa"), - m_TooltipBackgroundColor = GetColor("#515151C8"), - m_TooltipTextColor = GetColor("#FFFFFFFF"), - m_TooltipFlagAreaColor = GetColor("#51515120"), - m_TooltipLabelColor = GetColor("#A7A7A7FF"), - m_TooltipLineColor = GetColor("#eee"), - m_DataZoomLineColor = GetColor("#FFFFFF45"), - m_DataZoomSelectedColor = GetColor("#D0D0D03D"), - m_DataZoomTextColor = GetColor("#FFFFFFFF"), - m_VisualMapBackgroundColor = GetColor("#aaa"), - m_VisualMapBorderColor = GetColor("#cccccc"), - m_ColorPalette = new Color32[] - { - new Color32(221, 107, 102, 255), - new Color32(117, 154, 160, 255), - new Color32(230, 157, 135, 255), - new Color32(141, 193, 169, 255), - new Color32(234, 126, 83, 255), - new Color32(238, 221, 120, 255), - new Color32(115, 163, 115, 255), - new Color32(115, 185, 188, 255), - new Color32(114, 137, 171, 255), - new Color32(145, 202, 140, 255), - new Color32(244, 159, 66, 255) - }, - m_CustomColorPalette = new List<Color32>{ - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear, - Color.clear - } - }; - } - } - - /// <summary> - /// Convert the html string to color. - /// 将字符串颜色值转成Color。 - /// </summary> - /// <param name="hexColorStr"></param> - /// <returns></returns> - public static Color32 GetColor(string hexColorStr) - { - Color color; - ColorUtility.TryParseHtmlString(hexColorStr, out color); - return (Color32)color; - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -} \ No newline at end of file diff --git a/Runtime/Component/Main/Theme.cs.meta b/Runtime/Component/Main/Theme.cs.meta deleted file mode 100644 index 382bd891..00000000 --- a/Runtime/Component/Main/Theme.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7fa63cd119419441789620060693a7cb -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Main/Title.cs b/Runtime/Component/Main/Title.cs index 263c4637..efb3fdf0 100644 --- a/Runtime/Component/Main/Title.cs +++ b/Runtime/Component/Main/Title.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using System; @@ -19,9 +19,9 @@ namespace XCharts { [SerializeField] private bool m_Show = true; [SerializeField] private string m_Text; - [SerializeField] private TextStyle m_TextStyle = new TextStyle(16); + [SerializeField] private TextStyle m_TextStyle = new TextStyle(); [SerializeField] private string m_SubText; - [SerializeField] private TextStyle m_SubTextStyle = new TextStyle(14); + [SerializeField] private TextStyle m_SubTextStyle = new TextStyle(); [SerializeField] private float m_ItemGap = 8; [SerializeField] private Location m_Location = Location.defaultTop; @@ -30,19 +30,12 @@ namespace XCharts /// Set this to false to prevent the title from showing. /// 是否显示标题组件。 /// </summary> - public bool show { get { return m_Show; } set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); } } + public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// <summary> /// The main title text, supporting \n for newlines. /// 主标题文本,支持使用 \n 换行。 /// </summary> - public string text { get { return m_Text; } set { if (PropertyUtility.SetClass(ref m_Text, value)) SetComponentDirty(); } } - /// <summary> - /// [default:16] - /// main title font size. - /// 主标题文字的字体大小。 - /// </summary> - [Obsolete("use textStyle instead.", true)] - public int textFontSize { get { return m_TextStyle.fontSize; } set { m_TextStyle.fontSize = value; } } + public string text { get { return m_Text; } set { if (PropertyUtil.SetClass(ref m_Text, value)) SetComponentDirty(); } } /// <summary> /// The text style of main title. /// 主标题文本样式。 @@ -50,7 +43,7 @@ namespace XCharts public TextStyle textStyle { get { return m_TextStyle; } - set { if (PropertyUtility.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } } /// <summary> /// Subtitle text, supporting for \n for newlines. @@ -59,7 +52,7 @@ namespace XCharts public string subText { get { return m_SubText; } - set { if (PropertyUtility.SetClass(ref m_SubText, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_SubText, value)) SetComponentDirty(); } } /// <summary> /// The text style of sub title. @@ -68,18 +61,7 @@ namespace XCharts public TextStyle subTextStyle { get { return m_SubTextStyle; } - set { if (PropertyUtility.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); } - } - /// <summary> - /// [default:14] - /// subtitle font size. - /// 副标题文字的字体大小。 - /// </summary> - [Obsolete("use subTextStyle instead.", true)] - public int subTextFontSize - { - get { return m_SubTextStyle.fontSize; } - set { m_SubTextStyle.fontSize = value; } + set { if (PropertyUtil.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); } } /// <summary> /// [default:8] @@ -89,7 +71,7 @@ namespace XCharts public float itemGap { get { return m_ItemGap; } - set { if (PropertyUtility.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); } } /// <summary> /// The location of title component. @@ -98,9 +80,11 @@ namespace XCharts public Location location { get { return m_Location; } - set { if (PropertyUtility.SetClass(ref m_Location, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); } } + public int index { get; internal set; } + public override bool vertsDirty { get { return false; } } public override bool componentDirty { @@ -123,10 +107,10 @@ namespace XCharts { m_Show = true, m_Text = "Chart Title", - m_TextStyle = new TextStyle(16), + m_TextStyle = new TextStyle(), m_SubText = "", - m_SubTextStyle = new TextStyle(14), - m_ItemGap = 8, + m_SubTextStyle = new TextStyle(), + m_ItemGap = 0, m_Location = Location.defaultTop }; return title; diff --git a/Runtime/Component/Main/Tooltip.cs b/Runtime/Component/Main/Tooltip.cs index ae48f286..9833b8dc 100644 --- a/Runtime/Component/Main/Tooltip.cs +++ b/Runtime/Component/Main/Tooltip.cs @@ -1,17 +1,15 @@ using System.Linq; using System.Collections.ObjectModel; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; -using System; -using UnityEngine.EventSystems; namespace XCharts { @@ -66,12 +64,12 @@ namespace XCharts [SerializeField] private bool m_AlwayShow = false; [SerializeField] private Vector2 m_Offset = new Vector2(18f, -25f); [SerializeField] private Sprite m_BackgroundImage; - [SerializeField] private TextStyle m_TextStyle = new TextStyle(18, FontStyle.Normal); - [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid, 0.7f); + [SerializeField] private TextStyle m_TextStyle = new TextStyle(); + [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None); private GameObject m_GameObject; private GameObject m_Content; - private Text m_ContentText; + private ChartText m_ContentText; private Image m_ContentImage; private RectTransform m_ContentRect; private RectTransform m_ContentTextRect; @@ -84,7 +82,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) { SetAllDirty(); SetActive(value); } } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) { SetAllDirty(); SetActive(value); } } } /// <summary> /// Indicator type. @@ -93,7 +91,7 @@ namespace XCharts public Type type { get { return m_Type; } - set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetAllDirty(); } } /// <summary> /// A string template formatter for the total content of the prompt box. Support for wrapping lines with \n. @@ -161,10 +159,6 @@ namespace XCharts /// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。 /// </summary> public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } } - [Obsolete("Use Tooltip.textStyle.fontSize instead.", true)] - public int fontSize { get; set; } - [Obsolete("Use Tooltip.textStyle.fontStyle instead.", true)] - public FontStyle fontStyle { get; set; } /// <summary> /// Standard numeric format string. Used to format numeric values to display as strings. /// Using 'Axx' form: 'A' is the single character of the format specifier, supporting 'C' currency, @@ -178,7 +172,7 @@ namespace XCharts public string numericFormatter { get { return m_NumericFormatter; } - set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } } /// <summary> /// the text padding of left and right. defaut:5. @@ -291,6 +285,11 @@ namespace XCharts /// 当前指示的角度。 /// </summary> public float runtimeAngle { get; internal set; } + /// <summary> + /// 当前指示的Grid索引。 + /// </summary> + public int runtimeGridIndex { get; internal set; } + public int runtimePolarIndex { get; internal set; } public static Tooltip defaultTooltip { @@ -329,7 +328,7 @@ namespace XCharts m_ContentRect = m_Content.GetComponent<RectTransform>(); m_ContentImage = m_Content.GetComponent<Image>(); m_ContentImage.raycastTarget = false; - m_ContentText = m_Content.GetComponentInChildren<Text>(); + m_ContentText = new ChartText(m_Content); if (m_ContentText != null) { m_ContentTextRect = m_ContentText.gameObject.GetComponentInChildren<RectTransform>(); @@ -343,6 +342,7 @@ namespace XCharts /// </summary> public void UpdateToTop() { + if (m_GameObject == null) return; int count = m_GameObject.transform.parent.childCount; m_GameObject.GetComponent<RectTransform>().SetSiblingIndex(count - 1); } @@ -376,9 +376,9 @@ namespace XCharts /// <param name="color"></param> public void SetContentTextColor(Color color) { - if (m_ContentText) + if (m_ContentText != null) { - m_ContentText.color = color; + m_ContentText.SetColor(color); } } @@ -388,16 +388,16 @@ namespace XCharts /// <param name="txt"></param> public void UpdateContentText(string txt) { - if (m_ContentText) + if (m_ContentText != null) { - m_ContentText.text = txt; + m_ContentText.SetText(txt); float wid, hig; if (m_FixedWidth > 0) wid = m_FixedWidth; - else if (m_MinWidth > 0 && m_ContentText.preferredWidth < m_MinWidth) wid = m_MinWidth; - else wid = m_ContentText.preferredWidth + m_PaddingLeftRight * 2; + else if (m_MinWidth > 0 && m_ContentText.GetPreferredWidth() < m_MinWidth) wid = m_MinWidth; + else wid = m_ContentText.GetPreferredWidth() + m_PaddingLeftRight * 2; if (m_FixedHeight > 0) hig = m_FixedHeight; - else if (m_MinHeight > 0 && m_ContentText.preferredHeight < m_MinHeight) hig = m_MinHeight; - else hig = m_ContentText.preferredHeight + m_PaddingTopBottom * 2; + else if (m_MinHeight > 0 && m_ContentText.GetPreferredHeight() < m_MinHeight) hig = m_MinHeight; + else hig = m_ContentText.GetPreferredHeight() + m_PaddingTopBottom * 2; if (m_ContentRect != null) m_ContentRect.sizeDelta = new Vector2(wid, hig); if (m_ContentTextRect != null) { @@ -476,7 +476,8 @@ namespace XCharts internal void UpdateLastDataIndex() { lastDataIndex[0] = runtimeDataIndex[0]; - lastDataIndex[1] = runtimeDataIndex[1]; + if (runtimeDataIndex.Count > 1) + lastDataIndex[1] = runtimeDataIndex[1]; } /// <summary> @@ -485,7 +486,9 @@ namespace XCharts /// <returns></returns> public bool IsSelected() { - return runtimeDataIndex[0] >= 0 || runtimeDataIndex[1] >= 0; + foreach (var index in runtimeDataIndex) + if (index >= 0) return true; + return false; } /// <summary> @@ -495,7 +498,9 @@ namespace XCharts /// <returns></returns> public bool IsSelected(int index) { - return runtimeDataIndex[0] == index || runtimeDataIndex[1] == index; + foreach (var temp in runtimeDataIndex) + if (temp == index) return true; + return false; } public void ClearSerieDataIndex() diff --git a/Runtime/Component/Main/Vessel.cs b/Runtime/Component/Main/Vessel.cs index 5baceb5a..e8d48d15 100644 --- a/Runtime/Component/Main/Vessel.cs +++ b/Runtime/Component/Main/Vessel.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -62,7 +62,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// The shape of vessel. @@ -72,7 +72,7 @@ namespace XCharts public Shape shape { get { return m_Shape; } - set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Shape, value)) SetVerticesDirty(); } } /// <summary> /// Thickness of vessel. @@ -82,7 +82,7 @@ namespace XCharts public float shapeWidth { get { return m_ShapeWidth; } - set { if (PropertyUtility.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); } } /// <summary> /// The gap between the vessel and the liquid. @@ -92,7 +92,7 @@ namespace XCharts public float gap { get { return m_Gap; } - set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); } } /// <summary> /// The center of vesselß. The center[0] is the x-coordinate, and the center[1] is the y-coordinate. @@ -115,7 +115,7 @@ namespace XCharts public float radius { get { return m_Radius; } - set { if (PropertyUtility.SetStruct(ref m_Radius, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); } } /// <summary> /// The smoothness of wave. @@ -125,7 +125,7 @@ namespace XCharts public float smoothness { get { return m_Smoothness; } - set { if (PropertyUtility.SetStruct(ref m_Smoothness, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Smoothness, value)) SetAllDirty(); } } /// <summary> /// Background color of polar, which is transparent by default. @@ -135,7 +135,7 @@ namespace XCharts public Color32 backgroundColor { get { return m_BackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } } /// <summary> /// Vessel color. The default is consistent with Serie. @@ -144,7 +144,7 @@ namespace XCharts public Color32 color { get { return m_Color; } - set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); } } /// <summary> /// Whether automatic color. If true, the color matches serie. @@ -154,7 +154,7 @@ namespace XCharts public bool autoColor { get { return m_AutoColor; } - set { if (PropertyUtility.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); } } public int index { get; internal set; } /// <summary> diff --git a/Runtime/Component/Main/VisualMap.cs b/Runtime/Component/Main/VisualMap.cs index ab08cafa..1b77a6ec 100644 --- a/Runtime/Component/Main/VisualMap.cs +++ b/Runtime/Component/Main/VisualMap.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -101,7 +101,7 @@ namespace XCharts public bool enable { get { return m_Enable; } - set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetVerticesDirty(); } } /// <summary> /// Whether to display components. If set to false, it will not show up, but the data mapping function still exists. @@ -113,7 +113,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// the type of visualmap component. @@ -122,7 +122,7 @@ namespace XCharts public Type type { get { return m_Type; } - set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); } } /// <summary> /// 映射方向。 @@ -130,7 +130,7 @@ namespace XCharts public Direction direction { get { return m_Direction; } - set { if (PropertyUtility.SetStruct(ref m_Direction, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Direction, value)) SetVerticesDirty(); } } /// <summary> /// the selected mode for Piecewise visualMap. @@ -139,7 +139,7 @@ namespace XCharts public SelectedMode selectedMode { get { return m_SelectedMode; } - set { if (PropertyUtility.SetStruct(ref m_SelectedMode, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SelectedMode, value)) SetVerticesDirty(); } } /// <summary> /// The minimum allowed. 'min' must be user specified. [visualmap.min, visualmap.max] forms the "domain" of the visualMap. @@ -149,7 +149,7 @@ namespace XCharts public float min { get { return m_Min; } - set { if (PropertyUtility.SetStruct(ref m_Min, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); } } /// <summary> /// The maximum allowed. 'max' must be user specified. [visualmap.min, visualmap.max] forms the "domain" of the visualMap. @@ -187,7 +187,7 @@ namespace XCharts public int splitNumber { get { return m_SplitNumber; } - set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetVerticesDirty(); } } /// <summary> /// Whether the handle used for dragging is displayed (the handle can be dragged to adjust the selected range). @@ -197,7 +197,7 @@ namespace XCharts public bool calculable { get { return m_Calculable; } - set { if (PropertyUtility.SetStruct(ref m_Calculable, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Calculable, value)) SetVerticesDirty(); } } /// <summary> /// Whether to update in real time while dragging. @@ -207,7 +207,7 @@ namespace XCharts public bool realtime { get { return m_Realtime; } - set { if (PropertyUtility.SetStruct(ref m_Realtime, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Realtime, value)) SetVerticesDirty(); } } /// <summary> /// The width of the figure, that is, the width of the color bar. @@ -217,7 +217,7 @@ namespace XCharts public float itemWidth { get { return m_ItemWidth; } - set { if (PropertyUtility.SetStruct(ref m_ItemWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ItemWidth, value)) SetVerticesDirty(); } } /// <summary> /// The height of the figure, that is, the height of the color bar. @@ -227,7 +227,7 @@ namespace XCharts public float itemHeight { get { return m_ItemHeight; } - set { if (PropertyUtility.SetStruct(ref m_ItemHeight, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetVerticesDirty(); } } /// <summary> /// Border line width. @@ -237,7 +237,7 @@ namespace XCharts public float borderWidth { get { return m_BorderWidth; } - set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } } /// <summary> /// Specifies "which dimension" of the data to map to the visual element. "Data" is series.data. @@ -248,7 +248,7 @@ namespace XCharts public int dimension { get { return m_Dimension; } - set { if (PropertyUtility.SetStruct(ref m_Dimension, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Dimension, value)) SetVerticesDirty(); } } /// <summary> /// When the hoverLink function is turned on, when the mouse hovers over the visualMap component, @@ -263,7 +263,7 @@ namespace XCharts public bool hoverLink { get { return m_HoverLink; } - set { if (PropertyUtility.SetStruct(ref m_HoverLink, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_HoverLink, value)) SetVerticesDirty(); } } /// <summary> /// Automatically set min, Max value @@ -272,7 +272,7 @@ namespace XCharts public bool autoMinMax { get { return m_AutoMinMax; } - set { if (PropertyUtility.SetStruct(ref m_AutoMinMax, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_AutoMinMax, value)) SetVerticesDirty(); } } /// <summary> /// Specify whether the layout of component is horizontal or vertical. @@ -282,7 +282,7 @@ namespace XCharts public Orient orient { get { return m_Orient; } - set { if (PropertyUtility.SetStruct(ref m_Orient, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); } } /// <summary> /// The location of component. @@ -291,7 +291,7 @@ namespace XCharts public Location location { get { return m_Location; } - set { if (PropertyUtility.SetClass(ref m_Location, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_Location, value)) SetVerticesDirty(); } } /// <summary> /// Defines the visual color in the selected range. diff --git a/Runtime/Component/Main/XGrid.cs b/Runtime/Component/Main/XGrid.cs index 8c51ded8..46e57df9 100644 --- a/Runtime/Component/Main/XGrid.cs +++ b/Runtime/Component/Main/XGrid.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -38,7 +38,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// Distance between grid component and the left side of the container. @@ -47,7 +47,7 @@ namespace XCharts public float left { get { return m_Left; } - set { if (PropertyUtility.SetStruct(ref m_Left, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); } } /// <summary> /// Distance between grid component and the right side of the container. @@ -56,7 +56,7 @@ namespace XCharts public float right { get { return m_Right; } - set { if (PropertyUtility.SetStruct(ref m_Right, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); } } /// <summary> /// Distance between grid component and the top side of the container. @@ -65,7 +65,7 @@ namespace XCharts public float top { get { return m_Top; } - set { if (PropertyUtility.SetStruct(ref m_Top, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); } } /// <summary> /// Distance between grid component and the bottom side of the container. @@ -74,7 +74,7 @@ namespace XCharts public float bottom { get { return m_Bottom; } - set { if (PropertyUtility.SetStruct(ref m_Bottom, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); } } /// <summary> /// Background color of grid, which is transparent by default. @@ -83,7 +83,24 @@ namespace XCharts public Color backgroundColor { get { return m_BackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } + } + public int index { get; internal set; } + public float runtimeX { get; private set; } + public float runtimeY { get; private set; } + public float runtimeWidth { get; private set; } + public float runtimeHeight { get; private set; } + + internal void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight) + { + var runtimeLeft = left <= 1 ? left * chartWidth : left; + var runtimeBottom = bottom <= 1 ? bottom * chartHeight : bottom; + var runtimeTop = top <= 1 ? top * chartHeight : top; + var runtimeRight = right <= 1 ? right * chartWidth : right; + runtimeX = chartX + runtimeLeft; + runtimeY = chartY + runtimeBottom; + runtimeWidth = chartWidth - runtimeLeft - runtimeRight; + runtimeHeight = chartHeight - runtimeTop - runtimeBottom; } public static Grid defaultGrid diff --git a/Runtime/Component/MainComponent.cs b/Runtime/Component/MainComponent.cs deleted file mode 100644 index 8b9ca797..00000000 --- a/Runtime/Component/MainComponent.cs +++ /dev/null @@ -1,13 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -namespace XCharts -{ - public class MainComponent : ChartComponent - { - } -} \ No newline at end of file diff --git a/Runtime/Component/MainComponent.cs.meta b/Runtime/Component/MainComponent.cs.meta deleted file mode 100644 index 4da89c6e..00000000 --- a/Runtime/Component/MainComponent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a0b05891df2284bc588cf6b668bfeb7b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Sub/AreaStyle.cs b/Runtime/Component/Sub/AreaStyle.cs index ce0abe0c..1f6265d0 100644 --- a/Runtime/Component/Sub/AreaStyle.cs +++ b/Runtime/Component/Sub/AreaStyle.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -55,7 +55,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// the origin of area. @@ -64,7 +64,7 @@ namespace XCharts public AreaOrigin origin { get { return m_Origin; } - set { if (PropertyUtility.SetStruct(ref m_Origin, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Origin, value)) SetVerticesDirty(); } } /// <summary> /// the color of area,default use serie color. @@ -73,7 +73,7 @@ namespace XCharts public Color32 color { get { return m_Color; } - set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); } } /// <summary> /// Gradient color, start color to toColor. @@ -82,7 +82,7 @@ namespace XCharts public Color32 toColor { get { return m_ToColor; } - set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); } } /// <summary> /// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0. @@ -91,7 +91,7 @@ namespace XCharts public float opacity { get { return m_Opacity; } - set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } } /// <summary> /// 鼠标悬浮时是否高亮之前的区域 @@ -99,7 +99,7 @@ namespace XCharts public bool tooltipHighlight { get { return m_TooltipHighlight; } - set { if (PropertyUtility.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); } } /// <summary> /// the color of area,default use serie color. @@ -108,7 +108,7 @@ namespace XCharts public Color32 highlightColor { get { return m_HighlightColor; } - set { if (PropertyUtility.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); } } /// <summary> /// Gradient color, start highlightColor to highlightToColor. @@ -117,7 +117,7 @@ namespace XCharts public Color32 highlightToColor { get { return m_HighlightToColor; } - set { if (PropertyUtility.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); } } public static AreaStyle defaultAreaStyle @@ -129,10 +129,32 @@ namespace XCharts m_Show = false, m_Color = Color.clear, m_ToColor = Color.clear, - m_Opacity = 1 + m_Opacity = 0.6f }; return area; } } + + public Color32 GetColor() + { + if (m_Opacity == 1) return m_Color; + var color = m_Color; + color.a = (byte)(color.a * m_Opacity); + return color; + } + + public Color32 GetColor(Color32 themeColor) + { + if (!ChartHelper.IsClearColor(color)) + { + return GetColor(); + } + else + { + var color = themeColor; + color.a = (byte)(color.a * opacity); + return color; + } + } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/Arrow.cs b/Runtime/Component/Sub/Arrow.cs new file mode 100644 index 00000000..4f5be5a6 --- /dev/null +++ b/Runtime/Component/Sub/Arrow.cs @@ -0,0 +1,97 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using UnityEngine; + +namespace XCharts +{ + /// <summary> + /// </summary> + [Serializable] + public class Arrow : SubComponent + { + [SerializeField] private float m_Width = 10; + [SerializeField] private float m_Height = 15; + [SerializeField] private float m_Offset = 0; + [SerializeField] private float m_Dent = 3; + [SerializeField] private Color32 m_Color = Color.clear; + + /// <summary> + /// The widht of arrow. + /// 箭头宽。 + /// </summary> + public float width + { + get { return m_Width; } + set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); } + } + /// <summary> + /// The height of arrow. + /// 箭头高。 + /// </summary> + public float height + { + get { return m_Height; } + set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetVerticesDirty(); } + } + /// <summary> + /// The offset of arrow. + /// 箭头偏移。 + /// </summary> + public float offset + { + get { return m_Offset; } + set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); } + } + /// <summary> + /// The dent of arrow. + /// 箭头的凹度。 + /// </summary> + public float dent + { + get { return m_Dent; } + set { if (PropertyUtil.SetStruct(ref m_Dent, value)) SetVerticesDirty(); } + } + + /// <summary> + /// the color of arrow. + /// 箭头颜色。 + /// </summary> + public Color32 color + { + get { return m_Color; } + set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); } + } + + public Arrow Clone() + { + var arrow = new Arrow(); + arrow.width = width; + arrow.height = height; + arrow.offset = offset; + arrow.dent = dent; + arrow.color = color; + return arrow; + } + + public void Copy(Arrow arrow) + { + width = arrow.width; + height = arrow.height; + offset = arrow.offset; + dent = arrow.dent; + color = arrow.color; + } + + public Color32 GetColor(Color32 defaultColor) + { + if (ChartHelper.IsClearColor(color)) return defaultColor; + else return color; + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Sub/Arrow.cs.meta b/Runtime/Component/Sub/Arrow.cs.meta new file mode 100644 index 00000000..e1d2918b --- /dev/null +++ b/Runtime/Component/Sub/Arrow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf0a2263a511d4348a256df8e732bb1b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Sub/AxisLabel.cs b/Runtime/Component/Sub/AxisLabel.cs index 36c7fa35..148351d9 100644 --- a/Runtime/Component/Sub/AxisLabel.cs +++ b/Runtime/Component/Sub/AxisLabel.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -22,15 +22,12 @@ namespace XCharts [SerializeField] private string m_Formatter; [SerializeField] private int m_Interval = 0; [SerializeField] private bool m_Inside = false; - [SerializeField] private float m_Rotate; [SerializeField] private float m_Margin; - [SerializeField] private Color m_Color; - [SerializeField] private int m_FontSize; - [SerializeField] private FontStyle m_FontStyle; [SerializeField] private string m_NumericFormatter = ""; [SerializeField] private bool m_ShowAsPositiveNumber = false; [SerializeField] private bool m_OnZero = false; [SerializeField] private TextLimit m_TextLimit = new TextLimit(); + [SerializeField] private TextStyle m_TextStyle = new TextStyle(); /// <summary> /// Set this to false to prevent the axis label from appearing. @@ -39,7 +36,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// <summary> /// The display interval of the axis label. @@ -48,7 +45,7 @@ namespace XCharts public int interval { get { return m_Interval; } - set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetComponentDirty(); } } /// <summary> /// Set this to true so the axis labels face the inside direction. @@ -57,16 +54,7 @@ namespace XCharts public bool inside { get { return m_Inside; } - set { if (PropertyUtility.SetStruct(ref m_Inside, value)) SetComponentDirty(); } - } - /// <summary> - /// Rotation degree of axis label, which is especially useful when there is no enough space for category axis. - /// 刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。 - /// </summary> - public float rotate - { - get { return m_Rotate; } - set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetComponentDirty(); } } /// <summary> /// The margin between the axis label and the axis line. @@ -75,34 +63,7 @@ namespace XCharts public float margin { get { return m_Margin; } - set { if (PropertyUtility.SetStruct(ref m_Margin, value)) SetComponentDirty(); } - } - /// <summary> - /// the color of axis label text. - /// 刻度标签文字的颜色,默认取Theme的axisTextColor。 - /// </summary> - public Color color - { - get { return m_Color; } - set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); } - } - /// <summary> - /// font size. - /// 文字的字体大小。 - /// </summary> - public int fontSize - { - get { return m_FontSize; } - set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); } - } - /// <summary> - /// font style. - /// 文字字体的风格。 - /// </summary> - public FontStyle fontStyle - { - get { return m_FontStyle; } - set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetComponentDirty(); } } /// <summary> /// 图例内容字符串模版格式器。支持用 \n 换行。 @@ -111,7 +72,7 @@ namespace XCharts public string formatter { get { return m_Formatter; } - set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); } } /// <summary> @@ -124,7 +85,7 @@ namespace XCharts public string numericFormatter { get { return m_NumericFormatter; } - set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } } /// <summary> @@ -134,7 +95,7 @@ namespace XCharts public bool showAsPositiveNumber { get { return m_ShowAsPositiveNumber; } - set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); } } /// <summary> @@ -143,7 +104,7 @@ namespace XCharts public bool onZero { get { return m_OnZero; } - set { if (PropertyUtility.SetStruct(ref m_OnZero, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); } } /// <summary> @@ -155,6 +116,16 @@ namespace XCharts set { if (value != null) { m_TextLimit = value; SetComponentDirty(); } } } + /// <summary> + /// The text style of axis name. + /// 文本样式。 + /// </summary> + public TextStyle textStyle + { + get { return m_TextStyle; } + set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + } + public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } } internal override void ClearComponentDirty() { @@ -171,11 +142,8 @@ namespace XCharts m_Show = true, m_Interval = 0, m_Inside = false, - m_Rotate = 0, m_Margin = 8, - m_Color = Color.clear, - m_FontSize = 18, - m_FontStyle = FontStyle.Normal + m_TextStyle = new TextStyle(), }; } } @@ -187,12 +155,10 @@ namespace XCharts axisLable.formatter = formatter; axisLable.interval = interval; axisLable.inside = inside; - axisLable.rotate = rotate; axisLable.margin = margin; - axisLable.color = color; - axisLable.fontSize = fontSize; axisLable.numericFormatter = numericFormatter; axisLable.textLimit = textLimit.Clone(); + axisLable.textStyle.Copy(textStyle); return axisLable; } @@ -202,15 +168,13 @@ namespace XCharts formatter = axisLable.formatter; interval = axisLable.interval; inside = axisLable.inside; - rotate = axisLable.rotate; margin = axisLable.margin; - color = axisLable.color; - fontSize = axisLable.fontSize; numericFormatter = axisLable.numericFormatter; textLimit.Copy(axisLable.textLimit); + textStyle.Copy(axisLable.textStyle); } - public void SetRelatedText(Text txt, float labelWidth) + public void SetRelatedText(ChartText txt, float labelWidth) { m_TextLimit.SetRelatedText(txt, labelWidth); } diff --git a/Runtime/Component/Sub/AxisLine.cs b/Runtime/Component/Sub/AxisLine.cs index da375095..9c28b80d 100644 --- a/Runtime/Component/Sub/AxisLine.cs +++ b/Runtime/Component/Sub/AxisLine.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -11,29 +11,15 @@ namespace XCharts { /// <summary> /// Settings related to axis line. - /// 坐标轴的分隔线。 + /// 坐标轴轴线。 /// </summary> [System.Serializable] - public class AxisLine : SubComponent + public class AxisLine : BaseLine { - [SerializeField] private bool m_Show; [SerializeField] private bool m_OnZero; - [SerializeField] private float m_Width = 0.6f; - [SerializeField] private bool m_Symbol; - [SerializeField] private float m_SymbolWidth; - [SerializeField] private float m_SymbolHeight; - [SerializeField] private float m_SymbolOffset; - [SerializeField] private float m_SymbolDent; + [SerializeField] private bool m_ShowArrow; + [SerializeField] private Arrow m_Arrow = new Arrow(); - /// <summary> - /// Set this to false to prevent the axis line from showing. - /// 是否显示坐标轴轴线。 - /// </summary> - public bool show - { - get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } - } /// <summary> /// When mutiple axes exists, this option can be used to specify which axis can be "onZero" to. /// X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上,只有在另一个轴为数值轴且包含 0 刻度时有效。 @@ -41,63 +27,26 @@ namespace XCharts public bool onZero { get { return m_OnZero; } - set { if (PropertyUtility.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); } - } - /// <summary> - /// line style line width. - /// 坐标轴线线宽。 - /// </summary> - public float width - { - get { return m_Width; } - set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); } } /// <summary> /// Whether to show the arrow symbol of axis. /// 是否显示箭头。 /// </summary> - public bool symbol + public bool showArrow { - get { return m_Symbol; } - set { if (PropertyUtility.SetStruct(ref m_Symbol, value)) SetVerticesDirty(); } + get { return m_ShowArrow; } + set { if (PropertyUtil.SetStruct(ref m_ShowArrow, value)) SetVerticesDirty(); } } /// <summary> - /// the width of arrow symbol. - /// 箭头宽。 + /// the arrow of line. + /// 轴线箭头。 /// </summary> - public float symbolWidth + public Arrow arrow { - get { return m_SymbolWidth; } - set { if (PropertyUtility.SetStruct(ref m_SymbolWidth, value)) SetVerticesDirty(); } + get { return m_Arrow; } + set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); } } - /// <summary> - /// the height of arrow symbol. - /// 箭头高。 - /// </summary> - public float symbolHeight - { - get { return m_SymbolHeight; } - set { if (PropertyUtility.SetStruct(ref m_SymbolHeight, value)) SetVerticesDirty(); } - } - /// <summary> - /// the offset of arrow symbol. - /// 箭头偏移。 - /// </summary> - public float symbolOffset - { - get { return m_SymbolOffset; } - set { if (PropertyUtility.SetStruct(ref m_SymbolOffset, value)) SetVerticesDirty(); } - } - /// <summary> - /// the dent of arrow symbol. - /// 箭头的凹陷程度。 - /// </summary> - public float symbolDent - { - get { return m_SymbolDent; } - set { if (PropertyUtility.SetStruct(ref m_SymbolDent, value)) SetVerticesDirty(); } - } - public static AxisLine defaultAxisLine { get @@ -106,12 +55,9 @@ namespace XCharts { m_Show = true, m_OnZero = true, - m_Width = 0.7f, - m_Symbol = false, - m_SymbolWidth = 10, - m_SymbolHeight = 15, - m_SymbolOffset = -5f, - m_SymbolDent = 3, + m_ShowArrow = false, + m_Arrow = new Arrow(), + m_LineStyle = new LineStyle(LineStyle.Type.None), }; return axisLine; } @@ -122,25 +68,17 @@ namespace XCharts var axisLine = new AxisLine(); axisLine.show = show; axisLine.onZero = onZero; - axisLine.width = width; - axisLine.symbol = symbol; - axisLine.symbolWidth = symbolWidth; - axisLine.symbolHeight = symbolHeight; - axisLine.symbolOffset = symbolOffset; - axisLine.symbolDent = symbolDent; + axisLine.showArrow = showArrow; + axisLine.arrow = arrow.Clone(); return axisLine; } public void Copy(AxisLine axisLine) { - show = axisLine.show; + base.Copy(axisLine); onZero = axisLine.onZero; - width = axisLine.width; - symbol = axisLine.symbol; - symbolWidth = axisLine.symbolWidth; - symbolHeight = axisLine.symbolHeight; - symbolOffset = axisLine.symbolOffset; - symbolDent = axisLine.symbolDent; + showArrow = axisLine.showArrow; + arrow.Copy(axisLine.arrow); } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/AxisName.cs b/Runtime/Component/Sub/AxisName.cs index b4dbb5b7..c27358f0 100644 --- a/Runtime/Component/Sub/AxisName.cs +++ b/Runtime/Component/Sub/AxisName.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -30,11 +30,7 @@ namespace XCharts [SerializeField] private bool m_Show; [SerializeField] private string m_Name; [SerializeField] private Location m_Location; - [SerializeField] private Vector2 m_Offset; - [SerializeField] private float m_Rotate; - [SerializeField] private Color m_Color; - [SerializeField] private int m_FontSize; - [SerializeField] private FontStyle m_FontStyle; + [SerializeField] private TextStyle m_TextStyle = new TextStyle(); /// <summary> /// Whether to show axis name. @@ -43,7 +39,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// <summary> /// the name of axis. @@ -52,7 +48,7 @@ namespace XCharts public string name { get { return m_Name; } - set { if (PropertyUtility.SetClass(ref m_Name, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); } } /// <summary> /// Location of axis name. @@ -61,52 +57,17 @@ namespace XCharts public Location location { get { return m_Location; } - set { if (PropertyUtility.SetStruct(ref m_Location, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Location, value)) SetComponentDirty(); } } + /// <summary> - /// the offset of axis name and axis line. - /// 坐标轴名称与轴线之间的偏移。 + /// The text style of axis name. + /// 文本样式。 /// </summary> - public Vector2 offset + public TextStyle textStyle { - get { return m_Offset; } - set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetComponentDirty(); } - } - /// <summary> - /// Rotation of axis name. - /// 坐标轴名字旋转,角度值。 - /// </summary> - public float rotate - { - get { return m_Rotate; } - set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); } - } - /// <summary> - /// Color of axis name. - /// 坐标轴名称的文字颜色。 - /// </summary> - public Color color - { - get { return m_Color; } - set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); } - } - /// <summary> - /// axis name font size. - /// 坐标轴名称的文字大小。 - /// </summary> - public int fontSize - { - get { return m_FontSize; } - set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); } - } - /// <summary> - /// axis name font style. - /// 坐标轴名称的文字风格。 - /// </summary> - public FontStyle fontStyle - { - get { return m_FontStyle; } - set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); } + get { return m_TextStyle; } + set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } } public static AxisName defaultAxisName @@ -118,10 +79,7 @@ namespace XCharts m_Show = false, m_Name = "axisName", m_Location = Location.End, - m_Rotate = 0, - m_Color = Color.clear, - m_FontSize = 18, - m_FontStyle = FontStyle.Normal + m_TextStyle = new TextStyle(), }; } } @@ -132,11 +90,7 @@ namespace XCharts axisName.show = show; axisName.name = name; axisName.location = location; - axisName.offset = offset; - axisName.rotate = rotate; - axisName.color = color; - axisName.fontSize = fontSize; - axisName.fontStyle = fontStyle; + axisName.textStyle.Copy(textStyle); return axisName; } @@ -145,11 +99,7 @@ namespace XCharts show = axisName.show; name = axisName.name; location = axisName.location; - offset = axisName.offset; - rotate = axisName.rotate; - color = axisName.color; - fontSize = axisName.fontSize; - fontStyle = axisName.fontStyle; + textStyle.Copy(axisName.textStyle); } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/AxisSplitArea.cs b/Runtime/Component/Sub/AxisSplitArea.cs index fbcc920e..f1c8040f 100644 --- a/Runtime/Component/Sub/AxisSplitArea.cs +++ b/Runtime/Component/Sub/AxisSplitArea.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using System.Collections.Generic; @@ -28,7 +28,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// Color of split area. SplitArea color could also be set in color array, @@ -49,10 +49,7 @@ namespace XCharts return new AxisSplitArea() { m_Show = false, - m_Color = new List<Color32>(){ - new Color32(250,250,250,77), - new Color32(200,200,200,77) - } + m_Color = new List<Color32>() { } }; } } @@ -73,10 +70,18 @@ namespace XCharts ChartHelper.CopyList(color, splitArea.color); } - public Color32 getColor(int index) + public Color32 GetColor(int index, BaseAxisTheme theme) { - var i = index % color.Count; - return color[i]; + if (color.Count > 0) + { + var i = index % color.Count; + return color[i]; + } + else + { + var i = index % theme.splitAreaColors.Count; + return theme.splitAreaColors[i]; + } } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/AxisSplitLine.cs b/Runtime/Component/Sub/AxisSplitLine.cs index 3944115a..2e0dcbec 100644 --- a/Runtime/Component/Sub/AxisSplitLine.cs +++ b/Runtime/Component/Sub/AxisSplitLine.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -15,33 +15,14 @@ namespace XCharts /// 坐标轴在 grid 区域中的分隔线。 /// </summary> [Serializable] - public class AxisSplitLine : SubComponent + public class AxisSplitLine : BaseLine { - [SerializeField] private bool m_Show; [SerializeField] private int m_Interval; - [SerializeField] private LineStyle m_LineStyle = new LineStyle(0.7f); - /// <summary> - /// Set this to true to show the split line. - /// 是否显示分隔线。 - /// </summary> - public bool show - { - get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } - } public int interval { get { return m_Interval; } - set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetVerticesDirty(); } - } - /// <summary> - /// 线条样式 - /// </summary> - public LineStyle lineStyle - { - get { return m_LineStyle; } - set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } } + set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); } } public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } } @@ -72,23 +53,8 @@ namespace XCharts public void Copy(AxisSplitLine splitLine) { - show = splitLine.show; + base.Copy(splitLine); interval = splitLine.interval; - lineStyle.Copy(splitLine.lineStyle); - } - - internal Color32 GetColor(ThemeInfo theme) - { - if (!ChartHelper.IsClearColor(lineStyle.color)) - { - return lineStyle.GetColor(); - } - else - { - var color = theme.axisSplitLineColor; - color.a = (byte)(color.a * lineStyle.opacity); - return color; - } } internal bool NeedShow(int index) diff --git a/Runtime/Component/Sub/AxisTick.cs b/Runtime/Component/Sub/AxisTick.cs index 62284d65..94a51d26 100644 --- a/Runtime/Component/Sub/AxisTick.cs +++ b/Runtime/Component/Sub/AxisTick.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -15,23 +15,11 @@ namespace XCharts /// 坐标轴刻度相关设置。 /// </summary> [System.Serializable] - public class AxisTick : SubComponent + public class AxisTick : BaseLine { - [SerializeField] private bool m_Show; [SerializeField] private bool m_AlignWithLabel; [SerializeField] private bool m_Inside; - [SerializeField] private float m_Length; - [SerializeField] private float m_Width; - /// <summary> - /// Set this to false to prevent the axis tick from showing. - /// 是否显示坐标轴刻度。 - /// </summary> - public bool show - { - get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } - } /// <summary> /// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis. /// 类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。 @@ -39,7 +27,7 @@ namespace XCharts public bool alignWithLabel { get { return m_AlignWithLabel; } - set { if (PropertyUtility.SetStruct(ref m_AlignWithLabel, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_AlignWithLabel, value)) SetVerticesDirty(); } } /// <summary> /// Set this to true so the axis labels face the inside direction. @@ -48,25 +36,7 @@ namespace XCharts public bool inside { get { return m_Inside; } - set { if (PropertyUtility.SetStruct(ref m_Inside, value)) SetVerticesDirty(); } - } - /// <summary> - /// The length of the axis tick. - /// 坐标轴刻度的长度。 - /// </summary> - public float length - { - get { return m_Length; } - set { if (PropertyUtility.SetStruct(ref m_Length, value)) SetVerticesDirty(); } - } - /// <summary> - /// The width of the axis tick.Keep the same width with axis line when default 0. - /// 坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。 - /// </summary> - public float width - { - get { return m_Width; } - set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetVerticesDirty(); } } public static AxisTick defaultTick @@ -78,8 +48,6 @@ namespace XCharts m_Show = true, m_AlignWithLabel = false, m_Inside = false, - m_Width = 0f, - m_Length = 5f }; return tick; } @@ -91,8 +59,7 @@ namespace XCharts axisTick.show = show; axisTick.alignWithLabel = alignWithLabel; axisTick.inside = inside; - axisTick.length = length; - axisTick.width = width; + axisTick.lineStyle = lineStyle.Clone(); return axisTick; } @@ -101,8 +68,6 @@ namespace XCharts show = axisTick.show; alignWithLabel = axisTick.alignWithLabel; inside = axisTick.inside; - length = axisTick.length; - width = axisTick.width; } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/BaseLine.cs b/Runtime/Component/Sub/BaseLine.cs new file mode 100644 index 00000000..afd201cb --- /dev/null +++ b/Runtime/Component/Sub/BaseLine.cs @@ -0,0 +1,89 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; + +namespace XCharts +{ + /// <summary> + /// Settings related to base line. + /// 线条基础配置。 + /// </summary> + [System.Serializable] + public class BaseLine : SubComponent + { + [SerializeField] protected bool m_Show; + [SerializeField] protected LineStyle m_LineStyle = new LineStyle(); + + /// <summary> + /// Set this to false to prevent the axis line from showing. + /// 是否显示坐标轴轴线。 + /// </summary> + public bool show + { + get { return m_Show; } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + } + /// <summary> + /// 线条样式 + /// </summary> + public LineStyle lineStyle + { + get { return m_LineStyle; } + set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } } + } + + public static BaseLine defaultBaseLine + { + get + { + var axisLine = new BaseLine + { + m_Show = true, + m_LineStyle = new LineStyle() + }; + return axisLine; + } + } + + public BaseLine() + { + lineStyle = new LineStyle(); + } + + public BaseLine(bool show) : base() + { + m_Show = show; + } + + public void Copy(BaseLine axisLine) + { + show = axisLine.show; + lineStyle.Copy(axisLine.lineStyle); + } + + public LineStyle.Type GetType(LineStyle.Type themeType) + { + return lineStyle.GetType(themeType); + } + + public float GetWidth(float themeWidth) + { + return lineStyle.GetWidth(themeWidth); + } + + public float GetLength(float themeLength) + { + return lineStyle.GetLength(themeLength); + } + + public Color32 GetColor(Color32 themeColor) + { + return lineStyle.GetColor(themeColor); + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Sub/BaseLine.cs.meta b/Runtime/Component/Sub/BaseLine.cs.meta new file mode 100644 index 00000000..de0a9fa6 --- /dev/null +++ b/Runtime/Component/Sub/BaseLine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4c431b00ccffe4db4b61179b6df06eb2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Sub/Emphasis.cs b/Runtime/Component/Sub/Emphasis.cs index 0b734981..1e5310a9 100644 --- a/Runtime/Component/Sub/Emphasis.cs +++ b/Runtime/Component/Sub/Emphasis.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -41,7 +41,7 @@ namespace XCharts public SerieLabel label { get { return m_Label; } - set { if (PropertyUtility.SetClass(ref m_Label, value, true)) SetAllDirty(); } + set { if (PropertyUtil.SetClass(ref m_Label, value, true)) SetAllDirty(); } } /// <summary> /// 图形样式。 @@ -49,7 +49,7 @@ namespace XCharts public ItemStyle itemStyle { get { return m_ItemStyle; } - set { if (PropertyUtility.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); } } public override bool vertsDirty { get { return m_VertsDirty || label.vertsDirty || itemStyle.vertsDirty; } } diff --git a/Runtime/Component/Sub/GaugeAxis.cs b/Runtime/Component/Sub/GaugeAxis.cs index d14c980d..25dafdca 100644 --- a/Runtime/Component/Sub/GaugeAxis.cs +++ b/Runtime/Component/Sub/GaugeAxis.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -17,135 +17,10 @@ namespace XCharts [System.Serializable] public class GaugeAxis : SubComponent { - [System.Serializable] - public class AxisLine - { - [System.Serializable] - public class StageColor - { - [SerializeField] private float m_Percent; - [SerializeField] private Color32 m_Color; - /// <summary> - /// 结束位置百分比。 - /// </summary> - public float percent { get { return m_Percent; } set { m_Percent = value; } } - /// <summary> - /// 颜色。 - /// </summary> - public Color32 color { get { return m_Color; } set { m_Color = value; } } - - public StageColor(float percent, Color32 color) - { - m_Percent = percent; - m_Color = color; - } - } - [SerializeField] private bool m_Show = true; - [SerializeField] private float m_Width = 15f; - [SerializeField] private float m_Opacity = 1f; - [SerializeField] private Color32 m_BarColor; - [SerializeField] private Color32 m_BarBackgroundColor = new Color32(200, 200, 200, 255); - [SerializeField] - private List<StageColor> m_StageColor = new List<StageColor>() - { - new StageColor(0.2f,new Color32(145,199,174,255)), - new StageColor(0.8f,new Color32(99,134,158,255)), - new StageColor(1.0f,new Color32(194,53,49,255)), - }; - - /// <summary> - /// Set this to false to prevent the axis line from showing. - /// 是否显示坐标轴轴线。 - /// </summary> - public bool show { get { return m_Show; } set { m_Show = value; } } - /// <summary> - /// line style line width. - /// 坐标轴线线宽。 - /// </summary> - public float width { get { return m_Width; } set { m_Width = value; } } - /// <summary> - /// The opacity of axis line. - /// 透明度。 - /// </summary> - public float opacity { get { return m_Opacity; } set { m_Opacity = value; } } - /// <summary> - /// 进度条颜色。 - /// </summary> - public Color32 barColor { get { return m_BarColor; } set { m_BarColor = value; } } - /// <summary> - /// 进度条背景颜色。 - /// </summary> - public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } } - /// <summary> - /// 阶段颜色。 - /// </summary> - public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } } - } - /// <summary> - /// 分割线 - /// </summary> - [System.Serializable] - public class SplitLine - { - [SerializeField] private bool m_Show = true; - [SerializeField] private float m_Length = 15; - [SerializeField] - private LineStyle m_LineStyle = new LineStyle() - { - width = 1.5f, - type = LineStyle.Type.Solid, - color = new Color32(238, 238, 238, 255) - }; - /// <summary> - /// 是否显示分割线。 - /// </summary> - public bool show { get { return m_Show; } set { m_Show = value; } } - /// <summary> - /// 分割线长度。 - /// </summary> - public float length { get { return m_Length; } set { m_Length = value; } } - /// <summary> - /// 分割线样式。 - /// </summary> - public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } } - } - /// <summary> - /// 刻度 - /// </summary> - [System.Serializable] - public class AxisTick - { - [SerializeField] private bool m_Show = true; - [SerializeField] private float m_Length = 5; - [SerializeField] private float m_SplitNumber = 5; - [SerializeField] - private LineStyle m_LineStyle = new LineStyle() - { - width = 1f, - type = LineStyle.Type.Solid, - color = new Color32(238, 238, 238, 255) - }; - /// <summary> - /// 是否显示刻度。 - /// </summary> - public bool show { get { return m_Show; } set { m_Show = value; } } - /// <summary> - /// 刻度长度。当为0-1的浮点数时表示半径的百分比。 - /// </summary> - public float length { get { return m_Length; } set { m_Length = value; } } - /// <summary> - /// 分割线之间的分割段数。 - /// </summary> - public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } } - /// <summary> - /// 刻度线样式。 - /// </summary> - public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } } - } [SerializeField] private bool m_Show = true; - [SerializeField] private AxisLine m_AxisLine = new AxisLine(); - [SerializeField] private SplitLine m_SplitLine = new SplitLine(); - [SerializeField] private AxisTick m_AxisTick = new AxisTick(); + [SerializeField] private GaugeAxisLine m_AxisLine = new GaugeAxisLine(true); + [SerializeField] private GaugeAxisSplitLine m_SplitLine = new GaugeAxisSplitLine(true); + [SerializeField] private GaugeAxisTick m_AxisTick = new GaugeAxisTick(true); [SerializeField] private SerieLabel m_AxisLabel = new SerieLabel(); [SerializeField] private List<string> m_AxisLabelText = new List<string>(); @@ -154,17 +29,17 @@ namespace XCharts /// axis line style. /// 仪表盘轴线样式。 /// </summary> - public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } } + public GaugeAxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } } /// <summary> /// slit line style. /// 分割线。 /// </summary> - public SplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } } + public GaugeAxisSplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } } /// <summary> /// axis tick style. /// 刻度。 /// </summary> - public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } } + public GaugeAxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } } /// <summary> /// axis label style. /// 文本标签。 @@ -181,23 +56,24 @@ namespace XCharts public List<float> runtimeStageAngle = new List<float>(); public List<Vector3> runtimeLabelPosition = new List<Vector3>(); - private List<LabelObject> m_RuntimeLabelList = new List<LabelObject>(); + private List<ChartLabel> m_RuntimeLabelList = new List<ChartLabel>(); - internal Color32 GetAxisLineColor(ThemeInfo theme, int index) + internal Color32 GetAxisLineColor(ChartTheme theme, int index) { var color = !ChartHelper.IsClearColor(axisLine.barColor) ? axisLine.barColor : theme.GetColor(index); - ChartHelper.SetColorOpacity(ref color, axisLine.opacity); + ChartHelper.SetColorOpacity(ref color, axisLine.lineStyle.opacity); return color; } - internal Color32 GetAxisLineBackgroundColor(ThemeInfo theme, int index) + internal Color32 GetAxisLineBackgroundColor(ChartTheme theme, int index) { - var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor) ? axisLine.barBackgroundColor : ChartConst.greyColor32; - ChartHelper.SetColorOpacity(ref color, axisLine.opacity); + var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor) + ? axisLine.barBackgroundColor : ChartConst.greyColor32; + ChartHelper.SetColorOpacity(ref color, axisLine.lineStyle.opacity); return color; } - internal Color32 GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle) + internal Color32 GetSplitLineColor(Color32 themeColor, int serieIndex, float angle) { Color32 color; if (!ChartHelper.IsClearColor(splitLine.lineStyle.color)) @@ -206,21 +82,12 @@ namespace XCharts ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity); return color; } - for (int i = 0; i < runtimeStageAngle.Count; i++) - { - if (angle < runtimeStageAngle[i]) - { - color = axisLine.stageColor[i].color; - ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity); - return color; - } - } - color = theme.GetColor(serieIndex); + color = themeColor; ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity); return color; } - internal Color32 GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle) + internal Color32 GetAxisTickColor(Color32 themeColor, int serieIndex, float angle) { Color32 color; if (!ChartHelper.IsClearColor(axisTick.lineStyle.color)) @@ -229,21 +96,12 @@ namespace XCharts ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity); return color; } - for (int i = 0; i < runtimeStageAngle.Count; i++) - { - if (angle < runtimeStageAngle[i]) - { - color = axisLine.stageColor[i].color; - ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity); - return color; - } - } - color = theme.GetColor(serieIndex); + color = themeColor; ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity); return color; } - internal Color32 GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle) + internal Color32 GetPointerColor(ChartTheme theme, int serieIndex, float angle, ItemStyle itemStyle) { Color32 color; if (!ChartHelper.IsClearColor(itemStyle.color)) @@ -269,12 +127,12 @@ namespace XCharts m_RuntimeLabelList.Clear(); } - public void AddLabelObject(LabelObject label) + public void AddLabelObject(ChartLabel label) { m_RuntimeLabelList.Add(label); } - public LabelObject GetLabelObject(int index) + public ChartLabel GetLabelObject(int index) { if (index >= 0 && index < m_RuntimeLabelList.Count) { diff --git a/Runtime/Component/Sub/GaugeAxisLine.cs b/Runtime/Component/Sub/GaugeAxisLine.cs new file mode 100644 index 00000000..2a1cdf30 --- /dev/null +++ b/Runtime/Component/Sub/GaugeAxisLine.cs @@ -0,0 +1,63 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEngine; + +namespace XCharts +{ + [System.Serializable] + public class StageColor + { + [SerializeField] private float m_Percent; + [SerializeField] private Color32 m_Color; + /// <summary> + /// 结束位置百分比。 + /// </summary> + public float percent { get { return m_Percent; } set { m_Percent = value; } } + /// <summary> + /// 颜色。 + /// </summary> + public Color32 color { get { return m_Color; } set { m_Color = value; } } + + public StageColor(float percent, Color32 color) + { + m_Percent = percent; + m_Color = color; + } + } + + [System.Serializable] + public class GaugeAxisLine : BaseLine + { + [SerializeField] private Color32 m_BarColor; + [SerializeField] private Color32 m_BarBackgroundColor = new Color32(200, 200, 200, 255); + [SerializeField] + private List<StageColor> m_StageColor = new List<StageColor>() + { + new StageColor(0.2f,new Color32(145,199,174,255)), + new StageColor(0.8f,new Color32(99,134,158,255)), + new StageColor(1.0f,new Color32(194,53,49,255)), + }; + /// <summary> + /// 进度条颜色。 + /// </summary> + public Color32 barColor { get { return m_BarColor; } set { m_BarColor = value; } } + /// <summary> + /// 进度条背景颜色。 + /// </summary> + public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } } + /// <summary> + /// 阶段颜色。 + /// </summary> + public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } } + + public GaugeAxisLine(bool show) : base(show) + { + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Sub/GaugeAxisLine.cs.meta b/Runtime/Component/Sub/GaugeAxisLine.cs.meta new file mode 100644 index 00000000..3f530703 --- /dev/null +++ b/Runtime/Component/Sub/GaugeAxisLine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2c35880091e5a4382876c47bd843a99f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Sub/GaugeAxisSplitLine.cs b/Runtime/Component/Sub/GaugeAxisSplitLine.cs new file mode 100644 index 00000000..94f149d9 --- /dev/null +++ b/Runtime/Component/Sub/GaugeAxisSplitLine.cs @@ -0,0 +1,20 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +namespace XCharts +{ + /// <summary> + /// 分割线 + /// </summary> + [System.Serializable] + public class GaugeAxisSplitLine : BaseLine + { + public GaugeAxisSplitLine(bool show) : base(show) + { + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Sub/GaugeAxisSplitLine.cs.meta b/Runtime/Component/Sub/GaugeAxisSplitLine.cs.meta new file mode 100644 index 00000000..c272b7da --- /dev/null +++ b/Runtime/Component/Sub/GaugeAxisSplitLine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27a5f68720fa741ddbd50217b585a9e8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Sub/GaugeAxisTick.cs b/Runtime/Component/Sub/GaugeAxisTick.cs new file mode 100644 index 00000000..5a2f47ba --- /dev/null +++ b/Runtime/Component/Sub/GaugeAxisTick.cs @@ -0,0 +1,27 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; + +namespace XCharts +{ + /// <summary> + /// 刻度 + /// </summary> + [System.Serializable] + public class GaugeAxisTick : BaseLine + { + [SerializeField] private float m_SplitNumber = 5; + /// <summary> + /// 分割线之间的分割段数。 + /// </summary> + public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } } + public GaugeAxisTick(bool show) : base(show) + { + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Sub/GaugeAxisTick.cs.meta b/Runtime/Component/Sub/GaugeAxisTick.cs.meta new file mode 100644 index 00000000..bd9711a1 --- /dev/null +++ b/Runtime/Component/Sub/GaugeAxisTick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e9ace80811494ca5aad05b59c61a74f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Sub/GaugePointer.cs b/Runtime/Component/Sub/GaugePointer.cs index 53ca4cbd..e36052b5 100644 --- a/Runtime/Component/Sub/GaugePointer.cs +++ b/Runtime/Component/Sub/GaugePointer.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -29,7 +29,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// Pointer length. It can be an absolute value, or it can be a percentage relative to the radius (0-1). @@ -38,7 +38,7 @@ namespace XCharts public float length { get { return m_Length; } - set { if (PropertyUtility.SetStruct(ref m_Length, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); } } /// <summary> /// Pointer width. @@ -47,7 +47,7 @@ namespace XCharts public float width { get { return m_Width; } - set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); } } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/IconStyle.cs b/Runtime/Component/Sub/IconStyle.cs index 9c5a7730..3f9cd4c4 100644 --- a/Runtime/Component/Sub/IconStyle.cs +++ b/Runtime/Component/Sub/IconStyle.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; diff --git a/Runtime/Component/Sub/ItemStyle.cs b/Runtime/Component/Sub/ItemStyle.cs index a04f5f68..13beb697 100644 --- a/Runtime/Component/Sub/ItemStyle.cs +++ b/Runtime/Component/Sub/ItemStyle.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using System.Collections.Generic; @@ -84,7 +84,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// 数据项颜色。 @@ -92,7 +92,7 @@ namespace XCharts public Color32 color { get { return m_Color; } - set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); } } /// <summary> /// Gradient color1. @@ -101,7 +101,7 @@ namespace XCharts public Color32 toColor { get { return m_ToColor; } - set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); } } /// <summary> /// Gradient color2.Only valid in line diagrams. @@ -110,7 +110,7 @@ namespace XCharts public Color32 toColor2 { get { return m_ToColor2; } - set { if (PropertyUtility.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); } } /// <summary> /// 数据项背景颜色。 @@ -118,7 +118,7 @@ namespace XCharts public Color32 backgroundColor { get { return m_BackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } } /// <summary> /// 中心区域颜色。 @@ -126,7 +126,7 @@ namespace XCharts public Color32 centerColor { get { return m_CenterColor; } - set { if (PropertyUtility.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); } } /// <summary> /// 中心区域间隙。 @@ -134,7 +134,7 @@ namespace XCharts public float centerGap { get { return m_CenterGap; } - set { if (PropertyUtility.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); } } /// <summary> /// 数据项背景宽度。 @@ -142,7 +142,7 @@ namespace XCharts public float backgroundWidth { get { return m_BackgroundWidth; } - set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); } } /// <summary> /// 边框的类型。 @@ -150,7 +150,7 @@ namespace XCharts public Type borderType { get { return m_BorderType; } - set { if (PropertyUtility.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); } } /// <summary> /// 边框的颜色。 @@ -158,7 +158,7 @@ namespace XCharts public Color32 borderColor { get { return m_BorderColor; } - set { if (PropertyUtility.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); } } /// <summary> /// 边框宽。 @@ -166,7 +166,7 @@ namespace XCharts public float borderWidth { get { return m_BorderWidth; } - set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } } /// <summary> /// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 @@ -174,7 +174,7 @@ namespace XCharts public float opacity { get { return m_Opacity; } - set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } } /// <summary> /// 提示框单项的字符串模版格式器。具体配置参考`Tooltip`的`formatter` @@ -182,7 +182,7 @@ namespace XCharts public string tooltipFormatter { get { return m_TooltipFormatter; } - set { if (PropertyUtility.SetClass(ref m_TooltipFormatter, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_TooltipFormatter, value)) SetVerticesDirty(); } } /// <summary> /// Standard numeric format strings. @@ -194,7 +194,7 @@ namespace XCharts public string numericFormatter { get { return m_NumericFormatter; } - set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } } /// <summary> /// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)). @@ -203,7 +203,7 @@ namespace XCharts public float[] cornerRadius { get { return m_CornerRadius; } - set { if (PropertyUtility.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); } } /// <summary> /// 实际边框宽。边框不显示时为0。 diff --git a/Runtime/Component/Sub/LineArrow.cs b/Runtime/Component/Sub/LineArrow.cs index 40442603..d66b8a0b 100644 --- a/Runtime/Component/Sub/LineArrow.cs +++ b/Runtime/Component/Sub/LineArrow.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -28,10 +28,14 @@ namespace XCharts } [SerializeField] private bool m_Show; [SerializeField] Position m_Position; - [SerializeField] private float m_Width = 10; - [SerializeField] private float m_Height = 15; - [SerializeField] private float m_Offset = 0; - [SerializeField] private float m_Dent = 3; + [SerializeField] + private Arrow m_Arrow = new Arrow() + { + width = 10, + height = 15, + offset = 0, + dent = 3 + }; /// <summary> /// Whether to show the arrow. @@ -40,7 +44,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// The position of arrow. @@ -49,43 +53,17 @@ namespace XCharts public Position position { get { return m_Position; } - set { if (PropertyUtility.SetStruct(ref m_Position, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); } } + /// <summary> - /// The widht of arrow. - /// 箭头宽。 + /// the arrow of line. + /// 箭头。 /// </summary> - public float width + public Arrow arrow { - get { return m_Width; } - set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); } - } - /// <summary> - /// The height of arrow. - /// 箭头高。 - /// </summary> - public float height - { - get { return m_Height; } - set { if (PropertyUtility.SetStruct(ref m_Height, value)) SetVerticesDirty(); } - } - /// <summary> - /// The offset of arrow. - /// 箭头偏移。 - /// </summary> - public float offset - { - get { return m_Offset; } - set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetVerticesDirty(); } - } - /// <summary> - /// The dent of arrow. - /// 箭头的凹度。 - /// </summary> - public float dent - { - get { return m_Dent; } - set { if (PropertyUtility.SetStruct(ref m_Dent, value)) SetVerticesDirty(); } + get { return m_Arrow; } + set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); } } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/LineStyle.cs b/Runtime/Component/Sub/LineStyle.cs index 4334cf3a..92af3fe6 100644 --- a/Runtime/Component/Sub/LineStyle.cs +++ b/Runtime/Component/Sub/LineStyle.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -44,13 +44,15 @@ namespace XCharts /// 双点划线 /// </summary> DashDotDot, + None, } [SerializeField] private bool m_Show = true; [SerializeField] private Type m_Type = Type.Solid; [SerializeField] private Color32 m_Color; [SerializeField] private Color32 m_ToColor; [SerializeField] private Color32 m_ToColor2; - [SerializeField] private float m_Width = 0.8f; + [SerializeField] private float m_Width = 0; + [SerializeField] private float m_Length = 0; [SerializeField] [Range(0, 1)] private float m_Opacity = 1; /// <summary> @@ -60,7 +62,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } } /// <summary> /// the type of line. @@ -69,7 +71,7 @@ namespace XCharts public Type type { get { return m_Type; } - set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); } } /// <summary> /// the color of line, default use serie color. @@ -78,7 +80,7 @@ namespace XCharts public Color32 color { get { return m_Color; } - set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); } } /// <summary> /// the middle color of line, default use serie color. @@ -87,7 +89,7 @@ namespace XCharts public Color32 toColor { get { return m_ToColor; } - set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); } } /// <summary> /// the end color of line, default use serie color. @@ -96,7 +98,7 @@ namespace XCharts public Color32 toColor2 { get { return m_ToColor2; } - set { if (PropertyUtility.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); } } /// <summary> /// the width of line. @@ -105,7 +107,16 @@ namespace XCharts public float width { get { return m_Width; } - set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); } + } + /// <summary> + /// the length of line. + /// 线长。 + /// /// </summary> + public float length + { + get { return m_Length; } + set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); } } /// <summary> /// Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0. @@ -114,7 +125,7 @@ namespace XCharts public float opacity { get { return m_Opacity; } - set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); } } public LineStyle() @@ -126,6 +137,11 @@ namespace XCharts this.width = width; } + public LineStyle(LineStyle.Type type) + { + this.type = type; + } + public LineStyle(LineStyle.Type type, float width) { this.type = type; @@ -190,5 +206,34 @@ namespace XCharts } return color; } + + public Type GetType(Type themeType) + { + return type == Type.None ? themeType : type; + } + + public float GetWidth(float themeWidth) + { + return width == 0 ? themeWidth : width; + } + + public float GetLength(float themeLength) + { + return length == 0 ? themeLength : length; + } + + public Color32 GetColor(Color32 themeColor) + { + if (!ChartHelper.IsClearColor(color)) + { + return GetColor(); + } + else + { + var color = themeColor; + color.a = (byte)(color.a * opacity); + return color; + } + } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/Location.cs b/Runtime/Component/Sub/Location.cs index 56b8470d..cac4b330 100644 --- a/Runtime/Component/Sub/Location.cs +++ b/Runtime/Component/Sub/Location.cs @@ -1,12 +1,15 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif namespace XCharts { @@ -39,7 +42,10 @@ namespace XCharts [SerializeField] private float m_Top; [SerializeField] private float m_Bottom; - private TextAnchor m_TextAnchor; + private TextAnchor m_TextAlignment; +#if dUI_TextMeshPro + private TextAlignmentOptions m_TMPTextAlignment; +#endif private Vector2 m_AnchorMin; private Vector2 m_AnchorMax; private Vector2 m_Pivot; @@ -50,7 +56,7 @@ namespace XCharts public Align align { get { return m_Align; } - set { if (PropertyUtility.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } } + set { if (PropertyUtil.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } } } /// <summary> /// Distance between component and the left side of the container. @@ -59,7 +65,7 @@ namespace XCharts public float left { get { return m_Left; } - set { if (PropertyUtility.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } } + set { if (PropertyUtil.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } } } /// <summary> /// Distance between component and the left side of the container. @@ -68,7 +74,7 @@ namespace XCharts public float right { get { return m_Right; } - set { if (PropertyUtility.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } } + set { if (PropertyUtil.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } } } /// <summary> /// Distance between component and the left side of the container. @@ -77,7 +83,7 @@ namespace XCharts public float top { get { return m_Top; } - set { if (PropertyUtility.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } } + set { if (PropertyUtil.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } } } /// <summary> /// Distance between component and the left side of the container. @@ -86,7 +92,7 @@ namespace XCharts public float bottom { get { return m_Bottom; } - set { if (PropertyUtility.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } } + set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } } } /// <summary> @@ -94,7 +100,11 @@ namespace XCharts /// Location对应的Anchor锚点 /// </summary> /// <value></value> - public TextAnchor runtimeTextAnchor { get { return m_TextAnchor; } } + public TextAnchor runtimeTextAlignment { get { return m_TextAlignment; } } + +#if dUI_TextMeshPro + public TextAlignmentOptions runtimeTMPTextAlignment { get { return m_TMPTextAlignment; } } +#endif /// <summary> /// the minimum achor. /// Location对应的anchorMin。 @@ -179,55 +189,82 @@ namespace XCharts switch (m_Align) { case Align.BottomCenter: - m_TextAnchor = TextAnchor.LowerCenter; + m_TextAlignment = TextAnchor.LowerCenter; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.Bottom; +#endif m_AnchorMin = new Vector2(0.5f, 0); m_AnchorMax = new Vector2(0.5f, 0); m_Pivot = new Vector2(0.5f, 0); break; case Align.BottomLeft: - m_TextAnchor = TextAnchor.LowerLeft; + m_TextAlignment = TextAnchor.LowerLeft; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.BottomLeft; +#endif m_AnchorMin = new Vector2(0, 0); m_AnchorMax = new Vector2(0, 0); m_Pivot = new Vector2(0, 0); break; case Align.BottomRight: - m_TextAnchor = TextAnchor.LowerRight; + m_TextAlignment = TextAnchor.LowerRight; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.BottomRight; +#endif m_AnchorMin = new Vector2(1, 0); m_AnchorMax = new Vector2(1, 0); m_Pivot = new Vector2(1, 0); break; case Align.Center: - m_TextAnchor = TextAnchor.MiddleCenter; + m_TextAlignment = TextAnchor.MiddleCenter; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.Center; +#endif m_AnchorMin = new Vector2(0.5f, 0.5f); m_AnchorMax = new Vector2(0.5f, 0.5f); m_Pivot = new Vector2(0.5f, 0.5f); break; case Align.CenterLeft: - m_TextAnchor = TextAnchor.MiddleLeft; + m_TextAlignment = TextAnchor.MiddleLeft; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.Left; +#endif m_AnchorMin = new Vector2(0, 0.5f); m_AnchorMax = new Vector2(0, 0.5f); m_Pivot = new Vector2(0, 0.5f); break; case Align.CenterRight: - m_TextAnchor = TextAnchor.MiddleRight; + m_TextAlignment = TextAnchor.MiddleRight; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.Right; +#endif m_AnchorMin = new Vector2(1, 0.5f); m_AnchorMax = new Vector2(1, 0.5f); m_Pivot = new Vector2(1, 0.5f); break; case Align.TopCenter: - m_TextAnchor = TextAnchor.UpperCenter; + m_TextAlignment = TextAnchor.UpperCenter; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.Top; +#endif m_AnchorMin = new Vector2(0.5f, 1); m_AnchorMax = new Vector2(0.5f, 1); m_Pivot = new Vector2(0.5f, 1); break; case Align.TopLeft: - m_TextAnchor = TextAnchor.UpperLeft; + m_TextAlignment = TextAnchor.UpperLeft; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.TopLeft; +#endif m_AnchorMin = new Vector2(0, 1); m_AnchorMax = new Vector2(0, 1); m_Pivot = new Vector2(0, 1); break; case Align.TopRight: - m_TextAnchor = TextAnchor.UpperRight; + m_TextAlignment = TextAnchor.UpperRight; +#if dUI_TextMeshPro + m_TMPTextAlignment = TextAlignmentOptions.TopRight; +#endif m_AnchorMin = new Vector2(1, 1); m_AnchorMax = new Vector2(1, 1); m_Pivot = new Vector2(1, 1); diff --git a/Runtime/Component/Sub/SerieAnimation.cs b/Runtime/Component/Sub/SerieAnimation.cs index 45c2f32c..13c08f64 100644 --- a/Runtime/Component/Sub/SerieAnimation.cs +++ b/Runtime/Component/Sub/SerieAnimation.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/Component/Sub/SerieData.cs b/Runtime/Component/Sub/SerieData.cs index 958978af..6a641e80 100644 --- a/Runtime/Component/Sub/SerieData.cs +++ b/Runtime/Component/Sub/SerieData.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Linq; using System.Collections.Generic; @@ -34,7 +34,7 @@ namespace XCharts [SerializeField] private SerieSymbol m_Symbol = new SerieSymbol(); [SerializeField] private List<float> m_Data = new List<float>(); - public LabelObject labelObject { get; set; } + public ChartLabel labelObject { get; set; } private bool m_Show = true; private float m_RtPieOutsideRadius; @@ -169,6 +169,7 @@ namespace XCharts public Vector3 runtimePosition { get; internal set; } public float runtimeAngle { get; internal set; } public Vector3 runtiemPieOffsetCenter { get; internal set; } + public float runtimeStackHig { get; internal set; } private List<float> m_PreviousData = new List<float>(); private List<float> m_DataUpdateTime = new List<float>(); private List<bool> m_DataUpdateFlag = new List<bool>(); diff --git a/Runtime/Component/Sub/SerieLabel.cs b/Runtime/Component/Sub/SerieLabel.cs index eb1aec85..18043186 100644 --- a/Runtime/Component/Sub/SerieLabel.cs +++ b/Runtime/Component/Sub/SerieLabel.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -83,15 +83,10 @@ namespace XCharts [SerializeField] private Vector3 m_Offset; [SerializeField] private float m_Margin; [SerializeField] private string m_Formatter; - [SerializeField] private float m_Rotate = 0; [SerializeField] private float m_PaddingLeftRight = 2f; [SerializeField] private float m_PaddingTopBottom = 2f; - [SerializeField] private Color m_Color; - [SerializeField] private Color32 m_BackgroundColor; [SerializeField] private float m_BackgroundWidth = 0; [SerializeField] private float m_BackgroundHeight = 0; - [SerializeField] private int m_FontSize = 18; - [SerializeField] private FontStyle m_FontStyle = FontStyle.Normal; [SerializeField] private bool m_Line = true; [SerializeField] private LineType m_LineType = LineType.BrokenLine; [SerializeField] private Color32 m_LineColor = ChartConst.clearColor32; @@ -103,6 +98,7 @@ namespace XCharts [SerializeField] private Color32 m_BorderColor = ChartConst.greyColor32; [SerializeField] private string m_NumericFormatter = ""; [SerializeField] private bool m_AutoOffset = false; + [SerializeField] private TextStyle m_TextStyle = new TextStyle(); public void Reset() { @@ -112,12 +108,8 @@ namespace XCharts m_Margin = 0; m_PaddingLeftRight = 2f; m_PaddingTopBottom = 2f; - m_Color = Color.clear; - m_BackgroundColor = Color.clear; m_BackgroundWidth = 0; m_BackgroundHeight = 0; - m_FontSize = 18; - m_FontStyle = FontStyle.Normal; m_Line = true; m_LineType = LineType.BrokenLine; m_LineColor = Color.clear; @@ -138,7 +130,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); } } /// <summary> /// The position of label. @@ -147,7 +139,7 @@ namespace XCharts public Position position { get { return m_Position; } - set { if (PropertyUtility.SetStruct(ref m_Position, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); } } /// <summary> /// 标签内容字符串模版格式器。支持用 \n 换行。 @@ -165,7 +157,7 @@ namespace XCharts public string formatter { get { return m_Formatter; } - set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetVerticesDirty(); } } /// <summary> /// offset to the host graphic element. @@ -174,7 +166,7 @@ namespace XCharts public Vector3 offset { get { return m_Offset; } - set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); } } /// <summary> /// 距离轴线的距离。 @@ -182,25 +174,7 @@ namespace XCharts public float margin { get { return m_Margin; } - set { if (PropertyUtility.SetStruct(ref m_Margin, value)) SetVerticesDirty(); } - } - /// <summary> - /// Text color,If set as default ,the color will assigned as series color. - /// 自定义文字颜色,默认和系列的颜色一致。 - /// </summary> - public Color color - { - get { return m_Color; } - set { if (PropertyUtility.SetStruct(ref m_Color, value)) SetComponentDirty(); } - } - /// <summary> - /// the background color. If set as default, it means than don't show background. - /// 标签的背景色,默认无颜色。 - /// </summary> - public Color32 backgroundColor - { - get { return m_BackgroundColor; } - set { if (PropertyUtility.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetVerticesDirty(); } } /// <summary> /// the width of background. If set as default value 0, it means than the background width auto set as the text width. @@ -210,7 +184,7 @@ namespace XCharts public float backgroundWidth { get { return m_BackgroundWidth; } - set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); } } /// <summary> /// the height of background. If set as default value 0, it means than the background height auto set as the text height. @@ -220,16 +194,7 @@ namespace XCharts public float backgroundHeight { get { return m_BackgroundHeight; } - set { if (PropertyUtility.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); } - } - /// <summary> - /// Rotate label. - /// 标签旋转。 - /// </summary> - public float rotate - { - get { return m_Rotate; } - set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); } } /// <summary> /// the text padding of left and right. defaut:2. @@ -238,7 +203,7 @@ namespace XCharts public float paddingLeftRight { get { return m_PaddingLeftRight; } - set { if (PropertyUtility.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); } } /// <summary> /// the text padding of top and bottom. defaut:2. @@ -247,25 +212,7 @@ namespace XCharts public float paddingTopBottom { get { return m_PaddingTopBottom; } - set { if (PropertyUtility.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); } - } - /// <summary> - /// font size. - /// 文字的字体大小。 - /// </summary> - public int fontSize - { - get { return m_FontSize; } - set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetAllDirty(); } - } - /// <summary> - /// font style. - /// 文字的字体风格。 - /// </summary> - public FontStyle fontStyle - { - get { return m_FontStyle; } - set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); } } /// <summary> /// Whether to show visual guide line.Will show when label position is set as 'outside'. @@ -274,7 +221,7 @@ namespace XCharts public bool line { get { return m_Line; } - set { if (PropertyUtility.SetStruct(ref m_Line, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Line, value)) SetComponentDirty(); } } /// <summary> /// the type of visual guide line. @@ -283,7 +230,7 @@ namespace XCharts public LineType lineType { get { return m_LineType; } - set { if (PropertyUtility.SetStruct(ref m_LineType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); } } /// <summary> /// the color of visual guild line. @@ -292,7 +239,7 @@ namespace XCharts public Color32 lineColor { get { return m_LineColor; } - set { if (PropertyUtility.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); } } /// <summary> /// the width of visual guild line. @@ -301,7 +248,7 @@ namespace XCharts public float lineWidth { get { return m_LineWidth; } - set { if (PropertyUtility.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); } } /// <summary> /// The length of the first segment of visual guide line. @@ -310,7 +257,7 @@ namespace XCharts public float lineLength1 { get { return m_LineLength1; } - set { if (PropertyUtility.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); } } /// <summary> /// The length of the second segment of visual guide line. @@ -319,7 +266,7 @@ namespace XCharts public float lineLength2 { get { return m_LineLength2; } - set { if (PropertyUtility.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); } } /// <summary> /// Whether to show border. @@ -328,7 +275,7 @@ namespace XCharts public bool border { get { return m_Border; } - set { if (PropertyUtility.SetStruct(ref m_Border, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Border, value)) SetVerticesDirty(); } } /// <summary> /// the width of border. @@ -337,7 +284,7 @@ namespace XCharts public float borderWidth { get { return m_BorderWidth; } - set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } } /// <summary> /// the color of border. @@ -346,7 +293,7 @@ namespace XCharts public Color32 borderColor { get { return m_BorderColor; } - set { if (PropertyUtility.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); } } /// <summary> /// Standard numeric format strings. @@ -358,7 +305,7 @@ namespace XCharts public string numericFormatter { get { return m_NumericFormatter; } - set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } } /// <summary> /// 是否开启自动偏移。当开启时,Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。 @@ -366,7 +313,17 @@ namespace XCharts public bool autoOffset { get { return m_AutoOffset; } - set { if (PropertyUtility.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); } + } + + /// <summary> + /// the sytle of text. + /// 文本样式。 + /// </summary> + public TextStyle textStyle + { + get { return m_TextStyle; } + set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); } } } } diff --git a/Runtime/Component/Sub/SerieSymbol.cs b/Runtime/Component/Sub/SerieSymbol.cs index 862c5a13..0d051cef 100644 --- a/Runtime/Component/Sub/SerieSymbol.cs +++ b/Runtime/Component/Sub/SerieSymbol.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -81,8 +81,8 @@ namespace XCharts [SerializeField] private bool m_Show = true; [SerializeField] private SerieSymbolType m_Type = SerieSymbolType.EmptyCircle; [SerializeField] private SerieSymbolSizeType m_SizeType = SerieSymbolSizeType.Custom; - [SerializeField] private float m_Size = 6f; - [SerializeField] private float m_SelectedSize = 10f; + [SerializeField] private float m_Size = 0f; + [SerializeField] private float m_SelectedSize = 0f; [SerializeField] private int m_DataIndex = 1; [SerializeField] private float m_DataScale = 1; [SerializeField] private float m_SelectedDataScale = 1.5f; @@ -98,8 +98,8 @@ namespace XCharts m_Show = false; m_Type = SerieSymbolType.EmptyCircle; m_SizeType = SerieSymbolSizeType.Custom; - m_Size = 6f; - m_SelectedDataScale = 10f; + m_Size = 0f; + m_SelectedSize = 0f; m_DataIndex = 1; m_DataScale = 1; m_SelectedDataScale = 1.5f; @@ -118,7 +118,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); } } /// <summary> /// the type of symbol. @@ -127,7 +127,7 @@ namespace XCharts public SerieSymbolType type { get { return m_Type; } - set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); } } /// <summary> /// the type of symbol size. @@ -136,7 +136,7 @@ namespace XCharts public SerieSymbolSizeType sizeType { get { return m_SizeType; } - set { if (PropertyUtility.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); } } /// <summary> /// the size of symbol. @@ -145,7 +145,7 @@ namespace XCharts public float size { get { return m_Size; } - set { if (PropertyUtility.SetStruct(ref m_Size, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Size, value)) SetVerticesDirty(); } } /// <summary> /// the size of selected symbol. @@ -154,7 +154,7 @@ namespace XCharts public float selectedSize { get { return m_SelectedSize; } - set { if (PropertyUtility.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); } } /// <summary> /// whitch data index is when the sizeType assined as FromData. @@ -163,7 +163,7 @@ namespace XCharts public int dataIndex { get { return m_DataIndex; } - set { if (PropertyUtility.SetStruct(ref m_DataIndex, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_DataIndex, value)) SetVerticesDirty(); } } /// <summary> /// the scale of data when sizeType assined as FromData. @@ -172,7 +172,7 @@ namespace XCharts public float dataScale { get { return m_DataScale; } - set { if (PropertyUtility.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); } } /// <summary> /// the scale of selected data when sizeType assined as FromData. @@ -181,7 +181,7 @@ namespace XCharts public float selectedDataScale { get { return m_SelectedDataScale; } - set { if (PropertyUtility.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); } } /// <summary> /// the callback of size when sizeType assined as Callback. @@ -190,7 +190,7 @@ namespace XCharts public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } - set { if (PropertyUtility.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); } } /// <summary> /// the callback of size when sizeType assined as Callback. @@ -199,7 +199,7 @@ namespace XCharts public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } - set { if (PropertyUtility.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); } } /// <summary> /// the index start to show symbol. @@ -208,7 +208,7 @@ namespace XCharts public int startIndex { get { return m_StartIndex; } - set { if (PropertyUtility.SetStruct(ref m_StartIndex, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_StartIndex, value)) SetVerticesDirty(); } } /// <summary> /// the interval of show symbol. @@ -217,7 +217,7 @@ namespace XCharts public int interval { get { return m_Interval; } - set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); } } /// <summary> /// whether to show the last symbol. @@ -226,7 +226,7 @@ namespace XCharts public bool forceShowLast { get { return m_ForceShowLast; } - set { if (PropertyUtility.SetStruct(ref m_ForceShowLast, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_ForceShowLast, value)) SetVerticesDirty(); } } /// <summary> /// the gap of symbol and line segment. @@ -235,7 +235,7 @@ namespace XCharts public float gap { get { return m_Gap; } - set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetVerticesDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); } } private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 }; /// <summary> @@ -249,26 +249,25 @@ namespace XCharts /// </summary> /// <param name="data"></param> /// <returns></returns> - public float GetSize(List<float> data) + public float GetSize(List<float> data, float themeSize) { - if (data == null) return size; switch (m_SizeType) { case SerieSymbolSizeType.Custom: - return size; + return size == 0 ? themeSize : size; case SerieSymbolSizeType.FromData: - if (dataIndex >= 0 && dataIndex < data.Count) + if (data != null && dataIndex >= 0 && dataIndex < data.Count) { return data[dataIndex] * m_DataScale; } else { - return size; + return size == 0 ? themeSize : size; } case SerieSymbolSizeType.Callback: - if (sizeCallback != null) return sizeCallback(data); - else return size; - default: return size; + if (data != null && sizeCallback != null) return sizeCallback(data); + else return size == 0 ? themeSize : size; + default: return size == 0 ? themeSize : size; } } @@ -277,26 +276,25 @@ namespace XCharts /// </summary> /// <param name="data"></param> /// <returns></returns> - public float GetSelectedSize(List<float> data) + public float GetSelectedSize(List<float> data, float themeSelectedSize) { - if (data == null) return selectedSize; switch (m_SizeType) { case SerieSymbolSizeType.Custom: - return selectedSize; + return selectedSize == 0 ? themeSelectedSize : selectedSize; case SerieSymbolSizeType.FromData: - if (dataIndex >= 0 && dataIndex < data.Count) + if (data != null && dataIndex >= 0 && dataIndex < data.Count) { return data[dataIndex] * m_SelectedDataScale; } else { - return selectedSize; + return selectedSize == 0 ? themeSelectedSize : selectedSize; } case SerieSymbolSizeType.Callback: - if (selectedSizeCallback != null) return selectedSizeCallback(data); - else return selectedSize; - default: return selectedSize; + if (data != null && selectedSizeCallback != null) return selectedSizeCallback(data); + else return selectedSize == 0 ? themeSelectedSize : selectedSize; + default: return selectedSize == 0 ? themeSelectedSize : selectedSize; } } diff --git a/Runtime/Component/Sub/TextLimit.cs b/Runtime/Component/Sub/TextLimit.cs index c33d1575..15c05dd1 100644 --- a/Runtime/Component/Sub/TextLimit.cs +++ b/Runtime/Component/Sub/TextLimit.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -33,7 +33,7 @@ namespace XCharts public bool enable { get { return m_Enable; } - set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetComponentDirty(); } } /// <summary> /// Set the maximum width. A default of 0 indicates automatic fetch; otherwise, custom. @@ -43,7 +43,7 @@ namespace XCharts public float maxWidth { get { return m_MaxWidth; } - set { if (PropertyUtility.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); } } /// <summary> /// White pixel distance at both ends. @@ -53,7 +53,7 @@ namespace XCharts public float gap { get { return m_Gap; } - set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetComponentDirty(); } } /// <summary> /// Suffixes when the length exceeds. @@ -63,11 +63,10 @@ namespace XCharts public string suffix { get { return m_Suffix; } - set { if (PropertyUtility.SetClass(ref m_Suffix, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Suffix, value)) SetComponentDirty(); } } - private Text m_RelatedText; - private TextGenerationSettings m_RelatedTextSettings; + private ChartText m_RelatedText; private float m_RelatedTextWidth = 0; public TextLimit Clone() @@ -88,10 +87,9 @@ namespace XCharts suffix = textLimit.suffix; } - public void SetRelatedText(Text txt, float labelWidth) + public void SetRelatedText(ChartText txt, float labelWidth) { m_RelatedText = txt; - m_RelatedTextSettings = txt.GetGenerationSettings(Vector2.zero); m_RelatedTextWidth = labelWidth; } @@ -104,8 +102,8 @@ namespace XCharts { if (m_Enable) { - float len = m_RelatedText.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings); - float suffixLen = m_RelatedText.cachedTextGenerator.GetPreferredWidth(suffix, m_RelatedTextSettings); + float len = m_RelatedText.GetPreferredWidth(content); + float suffixLen = m_RelatedText.GetPreferredWidth(suffix); if (len >= checkWidth - m_Gap * 2) { return content.Substring(0, GetAdaptLength(content, suffixLen)) + suffix; @@ -133,7 +131,7 @@ namespace XCharts float len = 0; while (len != limit && middle != start) { - len = m_RelatedText.cachedTextGenerator.GetPreferredWidth(content.Substring(0, middle), m_RelatedTextSettings); + len = m_RelatedText.GetPreferredWidth(content.Substring(0, middle)); if (len < limit) { start = middle; diff --git a/Runtime/Component/Sub/TextStyle.cs b/Runtime/Component/Sub/TextStyle.cs index 1f9de707..bde1a9fb 100644 --- a/Runtime/Component/Sub/TextStyle.cs +++ b/Runtime/Component/Sub/TextStyle.cs @@ -1,12 +1,15 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif namespace XCharts { @@ -18,18 +21,20 @@ namespace XCharts public class TextStyle : SubComponent { [SerializeField] private Font m_Font; + [SerializeField] private float m_Rotate = 0; [SerializeField] private Vector2 m_Offset = Vector2.zero; [SerializeField] private Color m_Color = Color.clear; [SerializeField] private Color m_BackgroundColor = Color.clear; - [SerializeField] private int m_FontSize = 18; + [SerializeField] private int m_FontSize = 0; [SerializeField] private FontStyle m_FontStyle = FontStyle.Normal; [SerializeField] private float m_LineSpacing = 1f; - // [SerializeField] private float m_PaddingLeft = 0f; - // [SerializeField] private float m_PaddingRight = 0f; - // [SerializeField] private float m_PaddingTop = 0f; - // [SerializeField] private float m_PaddingBottom = 0f; - + [SerializeField] private TextAnchor m_Alignment = TextAnchor.MiddleCenter; +#if dUI_TextMeshPro + [SerializeField] private TMP_FontAsset m_TMPFont; + [SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal; + [SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left; +#endif /// <summary> /// Rotation of text. /// 文本的旋转。 @@ -38,7 +43,7 @@ namespace XCharts public float rotate { get { return m_Rotate; } - set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); } } /// <summary> /// the offset of position. @@ -48,7 +53,7 @@ namespace XCharts public Vector2 offset { get { return m_Offset; } - set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); } } public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } } @@ -61,7 +66,7 @@ namespace XCharts public Color color { get { return m_Color; } - set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); } } /// <summary> /// the color of text. @@ -71,7 +76,7 @@ namespace XCharts public Color backgroundColor { get { return m_BackgroundColor; } - set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); } } /// <summary> /// the font of text. When `null`, the theme's font is used by default. @@ -81,7 +86,7 @@ namespace XCharts public Font font { get { return m_Font; } - set { if (PropertyUtility.SetClass(ref m_Font, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); } } /// <summary> /// font size. @@ -91,7 +96,7 @@ namespace XCharts public int fontSize { get { return m_FontSize; } - set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); } } /// <summary> /// font style. @@ -101,7 +106,7 @@ namespace XCharts public FontStyle fontStyle { get { return m_FontStyle; } - set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); } } /// <summary> /// text line spacing. @@ -111,8 +116,34 @@ namespace XCharts public float lineSpacing { get { return m_LineSpacing; } - set { if (PropertyUtility.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); } } + /// <summary> + /// 对齐方式。 + /// </summary> + public TextAnchor alignment + { + get { return m_Alignment; } + set { if (PropertyUtil.SetStruct(ref m_Alignment, value)) SetComponentDirty(); } + } +#if dUI_TextMeshPro + public TMP_FontAsset tmpFont + { + get { return m_TMPFont; } + set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); } + } + + public FontStyles tmpFontStyle + { + 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() { @@ -143,5 +174,44 @@ namespace XCharts this.color = color; this.rotate = rotate; } + + public void Copy(TextStyle textStyle) + { + font = textStyle.font; + rotate = textStyle.rotate; + offset = textStyle.offset; + color = textStyle.color; + backgroundColor = textStyle.backgroundColor; + fontSize = textStyle.fontSize; + fontStyle = textStyle.fontStyle; + lineSpacing = textStyle.lineSpacing; + alignment = textStyle.alignment; +#if dUI_TextMeshPro + m_TMPFont = textStyle.tmpFont; + m_TMPAlignment = textStyle.tmpAlignment; + m_TMPFontStyle = textStyle.tmpFontStyle; +#endif + } + + public void UpdateAlignmentByLocation(Location location) + { +#if dUI_TextMeshPro + m_TMPAlignment = location.runtimeTMPTextAlignment; +#else + m_Alignment = location.runtimeTextAlignment; +#endif + } + + public Color GetColor(Color defaultColor) + { + if (ChartHelper.IsClearColor(color)) return defaultColor; + else return color; + } + + public int GetFontSize(ComponentTheme defaultTheme) + { + if(fontSize == 0) return defaultTheme.fontSize; + else return fontSize; + } } } \ No newline at end of file diff --git a/Runtime/Component/Sub/TitleStyle.cs b/Runtime/Component/Sub/TitleStyle.cs index 7d398120..fd532327 100644 --- a/Runtime/Component/Sub/TitleStyle.cs +++ b/Runtime/Component/Sub/TitleStyle.cs @@ -1,10 +1,10 @@ /* -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; @@ -22,7 +22,7 @@ namespace XCharts { [SerializeField] private bool m_Show; [FormerlySerializedAs("m_textStyle")] - [SerializeField] private TextStyle m_TextStyle = new TextStyle(18); + [SerializeField] private TextStyle m_TextStyle = new TextStyle(); /// <summary> /// Whether to show title. @@ -31,7 +31,7 @@ namespace XCharts public bool show { get { return m_Show; } - set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); } + set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// <summary> @@ -41,7 +41,7 @@ namespace XCharts public TextStyle textStyle { get { return m_TextStyle; } - set { if (PropertyUtility.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); } + set { if (PropertyUtil.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); } } public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } } @@ -52,7 +52,7 @@ namespace XCharts textStyle.ClearComponentDirty(); } - public Text runtimeText { get; set; } + public ChartText runtimeText { get; set; } public bool IsInited() { @@ -61,26 +61,28 @@ namespace XCharts public void SetActive(bool active) { - if (runtimeText) + if (runtimeText != null) { - ChartHelper.SetActive(runtimeText, active); + runtimeText.SetActive(active); } } public void UpdatePosition(Vector3 pos) { - if (runtimeText) + if (runtimeText != null) { - runtimeText.transform.localPosition = pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y); + runtimeText.SetLocalPosition(pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y)); } } public void SetText(string text) { - if (runtimeText && !runtimeText.text.Equals(text)) + if (runtimeText == null) return; + var oldText = runtimeText.GetText(); + if (oldText != null && !oldText.Equals(text)) { - if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.color = textStyle.color; - runtimeText.text = text; + if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.SetColor(textStyle.color); + runtimeText.SetText(text); } } } diff --git a/Runtime/Component/SubComponent.cs b/Runtime/Component/SubComponent.cs deleted file mode 100644 index e88d7f87..00000000 --- a/Runtime/Component/SubComponent.cs +++ /dev/null @@ -1,13 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -namespace XCharts -{ - public class SubComponent : ChartComponent - { - } -} \ No newline at end of file diff --git a/Runtime/Component/SubComponent.cs.meta b/Runtime/Component/SubComponent.cs.meta deleted file mode 100644 index e1543960..00000000 --- a/Runtime/Component/SubComponent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 94e905091d07140de987a531a6ff90d9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Theme.meta b/Runtime/Component/Theme.meta new file mode 100644 index 00000000..b494a4f3 --- /dev/null +++ b/Runtime/Component/Theme.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cf2fdcbe222404d7b869946ef6fee032 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/AxisTheme.cs b/Runtime/Component/Theme/AxisTheme.cs new file mode 100644 index 00000000..53ecb39a --- /dev/null +++ b/Runtime/Component/Theme/AxisTheme.cs @@ -0,0 +1,255 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using System.Collections.Generic; +using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + [Serializable] + public class BaseAxisTheme : ComponentTheme + { + [SerializeField] protected LineStyle.Type m_LineType = LineStyle.Type.Solid; + [SerializeField] protected float m_LineWidth = 1f; + [SerializeField] protected float m_LineLength = 0f; + [SerializeField] protected Color32 m_LineColor; + [SerializeField] protected LineStyle.Type m_SplitLineType = LineStyle.Type.Dashed; + [SerializeField] protected float m_SplitLineWidth = 1f; + [SerializeField] protected float m_SplitLineLength = 0f; + [SerializeField] protected Color32 m_SplitLineColor; + [SerializeField] protected float m_TickWidth = 1f; + [SerializeField] protected float m_TickLength = 5f; + [SerializeField] protected Color32 m_TickColor; + [SerializeField] protected List<Color32> m_SplitAreaColors = new List<Color32>(); + + /// <summary> + /// the type of line. + /// 坐标轴线类型。 + /// </summary> + public LineStyle.Type lineType + { + get { return m_LineType; } + set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); } + } + /// <summary> + /// the width of line. + /// 坐标轴线宽。 + /// </summary> + public float lineWidth + { + get { return m_LineWidth; } + set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); } + } + /// <summary> + /// the length of line. + /// 坐标轴线长。 + /// </summary> + public float lineLength + { + get { return m_LineLength; } + set { if (PropertyUtil.SetStruct(ref m_LineLength, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of line. + /// 坐标轴线颜色。 + /// </summary> + public Color32 lineColor + { + get { return m_LineColor; } + set { if (PropertyUtil.SetColor(ref m_LineColor, value)) SetVerticesDirty(); } + } + /// <summary> + /// the type of split line. + /// 分割线线类型。 + /// </summary> + public LineStyle.Type splitLineType + { + get { return m_SplitLineType; } + set { if (PropertyUtil.SetStruct(ref m_SplitLineType, value)) SetVerticesDirty(); } + } + /// <summary> + /// the width of split line. + /// 分割线线宽。 + /// </summary> + public float splitLineWidth + { + get { return m_SplitLineWidth; } + set { if (PropertyUtil.SetStruct(ref m_SplitLineWidth, value)) SetVerticesDirty(); } + } + /// <summary> + /// the length of split line. + /// 分割线线长。 + /// </summary> + public float splitLineLength + { + get { return m_SplitLineLength; } + set { if (PropertyUtil.SetStruct(ref m_SplitLineLength, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of line. + /// 分割线线颜色。 + /// </summary> + public Color32 splitLineColor + { + get { return m_SplitLineColor; } + set { if (PropertyUtil.SetColor(ref m_SplitLineColor, value)) SetVerticesDirty(); } + } + /// <summary> + /// the length of tick. + /// 刻度线线长。 + /// </summary> + public float tickLength + { + get { return m_TickLength; } + set { if (PropertyUtil.SetStruct(ref m_TickLength, value)) SetVerticesDirty(); } + } + /// <summary> + /// the width of tick. + /// 刻度线线宽。 + /// </summary> + public float tickWidth + { + get { return m_TickWidth; } + set { if (PropertyUtil.SetStruct(ref m_TickWidth, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of tick. + /// 坐标轴线颜色。 + /// </summary> + public Color32 tickColor + { + get { return m_TickColor; } + set { if (PropertyUtil.SetColor(ref m_TickColor, value)) SetVerticesDirty(); } + } + + public List<Color32> splitAreaColors + { + get { return m_SplitAreaColors; } + set { if (value != null) { m_SplitAreaColors = value; SetVerticesDirty(); } } + } + + public BaseAxisTheme(Theme theme) : base(theme) + { + m_FontSize = XChartsSettings.fontSizeLv4; + m_LineType = XChartsSettings.axisLineType; + m_LineWidth = XChartsSettings.axisLineWidth; + m_LineLength = 0; + m_SplitLineType = XChartsSettings.axisSplitLineType; + m_SplitLineWidth = XChartsSettings.axisSplitLineWidth; + m_SplitLineLength = 0; + m_TickWidth = XChartsSettings.axisTickWidth; + m_TickLength = XChartsSettings.axisTickLength; + switch (theme) + { + case Theme.Default: + m_LineColor = ColorUtil.GetColor("#514D4D"); + m_TickColor = ColorUtil.GetColor("#514D4D"); + m_SplitLineColor = ColorUtil.GetColor("#51515120"); + m_SplitAreaColors = new List<Color32>{ + new Color32(250,250,250,77), + new Color32(200,200,200,77) + }; + break; + case Theme.Light: + m_LineColor = ColorUtil.GetColor("#514D4D"); + m_TickColor = ColorUtil.GetColor("#514D4D"); + m_SplitLineColor = ColorUtil.GetColor("#51515120"); + m_SplitAreaColors = new List<Color32>{ + new Color32(250,250,250,77), + new Color32(200,200,200,77) + }; + break; + case Theme.Dark: + m_LineColor = ColorUtil.GetColor("#B9B8CE"); + m_TickColor = ColorUtil.GetColor("#B9B8CE"); + m_SplitLineColor = ColorUtil.GetColor("#484753"); + m_SplitAreaColors = new List<Color32>{ + new Color32(255,255,255,(byte)(0.02f * 255)), + new Color32(255,255,255,(byte)(0.05f * 255)) + }; + break; + } + } + + public void Copy(BaseAxisTheme theme) + { + base.Copy(theme); + m_LineType = theme.lineType; + m_LineWidth = theme.lineWidth; + m_LineLength = theme.lineLength; + m_LineColor = theme.lineColor; + m_SplitLineType = theme.splitLineType; + m_SplitLineWidth = theme.splitLineWidth; + m_SplitLineLength = theme.splitLineLength; + m_SplitLineColor = theme.splitLineColor; + m_TickWidth = theme.tickWidth; + m_TickLength = theme.tickLength; + m_TickColor = theme.tickColor; + ChartHelper.CopyList(m_SplitAreaColors, theme.splitAreaColors); + } + } + + [Serializable] + public class AxisTheme : BaseAxisTheme + { + public AxisTheme(Theme theme) : base(theme) + { + } + } + + [Serializable] + public class RadiusAxisTheme : BaseAxisTheme + { + public RadiusAxisTheme(Theme theme) : base(theme) + { + } + } + + [Serializable] + public class AngleAxisTheme : BaseAxisTheme + { + public AngleAxisTheme(Theme theme) : base(theme) + { + } + } + + [Serializable] + public class PolarAxisTheme : BaseAxisTheme + { + public PolarAxisTheme(Theme theme) : base(theme) + { + } + } + + [Serializable] + public class RadarAxisTheme : BaseAxisTheme + { + public RadarAxisTheme(Theme theme) : base(theme) + { + m_SplitAreaColors.Clear(); + switch (theme) + { + case Theme.Dark: + m_SplitAreaColors.Add(ChartTheme.GetColor("#6f6f6f")); + m_SplitAreaColors.Add(ChartTheme.GetColor("#606060")); + break; + case Theme.Default: + m_SplitAreaColors.Add(ChartTheme.GetColor("#f6f6f6")); + m_SplitAreaColors.Add(ChartTheme.GetColor("#e7e7e7")); + break; + case Theme.Light: + m_SplitAreaColors.Add(ChartTheme.GetColor("#f6f6f6")); + m_SplitAreaColors.Add(ChartTheme.GetColor("#e7e7e7")); + break; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/AxisTheme.cs.meta b/Runtime/Component/Theme/AxisTheme.cs.meta new file mode 100644 index 00000000..cc88ab9e --- /dev/null +++ b/Runtime/Component/Theme/AxisTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aefd22e76a6f642c9985b1a29e389858 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/ChartTheme.cs b/Runtime/Component/Theme/ChartTheme.cs new file mode 100644 index 00000000..5ff32bdc --- /dev/null +++ b/Runtime/Component/Theme/ChartTheme.cs @@ -0,0 +1,527 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEngine; +using System; +using System.Text; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + /// <summary> + /// 主题 + /// </summary> + public enum Theme + { + /// <summary> + /// 默认主题。 + /// </summary> + Default, + /// <summary> + /// 亮主题。 + /// </summary> + Light, + /// <summary> + /// 暗主题。 + /// </summary> + Dark, + /// <summary> + /// 自定义主题。 + /// </summary> + Custom, + } + + [Serializable] + /// <summary> + /// Theme. + /// 主题相关配置。 + /// </summary> + public class ChartTheme : ScriptableObject + { + [SerializeField] private Theme m_Theme = Theme.Default; + [SerializeField] private string m_ThemeName = Theme.Default.ToString(); + [SerializeField] private Font m_Font; +#if dUI_TextMeshPro + [SerializeField] private TMP_FontAsset m_TMPFont; +#endif + + [SerializeField] private Color32 m_ContrastColor; + [SerializeField] private Color32 m_BackgroundColor; + + [SerializeField] private List<Color32> m_ColorPalette = new List<Color32>(13); + + [SerializeField] private ComponentTheme m_Common; + [SerializeField] private TitleTheme m_Title; + [SerializeField] private SubTitleTheme m_SubTitle; + [SerializeField] private LegendTheme m_Legend; + [SerializeField] private AxisTheme m_Axis; + [SerializeField] private RadiusAxisTheme m_RadiusAxis; + [SerializeField] private AngleAxisTheme m_AngleAxis; + [SerializeField] private PolarAxisTheme m_Polar; + [SerializeField] private GaugeAxisTheme m_Gauge; + [SerializeField] private RadarAxisTheme m_Radar; + [SerializeField] private TooltipTheme m_Tooltip; + [SerializeField] private DataZoomTheme m_DataZoom; + [SerializeField] private VisualMapTheme m_VisualMap; + [SerializeField] private SerieTheme m_Serie; + + /// <summary> + /// the theme of chart. + /// 主题类型。 + /// </summary> + public Theme theme + { + get { return m_Theme; } + set { if (PropertyUtil.SetStruct(ref m_Theme, value)) SetComponentDirty(); } + } + public string themeName + { + get { return m_ThemeName; } + set { if (PropertyUtil.SetClass(ref m_ThemeName, value)) SetComponentDirty(); } + } + + + /// <summary> + /// the contrast color of chart. + /// 对比色。 + /// </summary> + public Color32 contrastColor + { + get { return m_ContrastColor; } + set { if (PropertyUtil.SetColor(ref m_ContrastColor, value)) SetVerticesDirty(); } + } + /// <summary> + /// the background color of chart. + /// 背景颜色。 + /// </summary> + public Color32 backgroundColor + { + get { return m_BackgroundColor; } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } + } + + /// <summary> + /// The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series. + /// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。 + /// </summary> + public List<Color32> colorPalette { get { return m_ColorPalette; } set { m_ColorPalette = value; SetVerticesDirty(); } } + public ComponentTheme common { get { return m_Common; } set { m_Common = value; SetComponentDirty(); } } + public TitleTheme title { get { return m_Title; } set { m_Title = value; SetComponentDirty(); } } + public SubTitleTheme subTitle { get { return m_SubTitle; } set { m_SubTitle = value; SetComponentDirty(); } } + public LegendTheme legend { get { return m_Legend; } set { m_Legend = value; SetComponentDirty(); } } + public AxisTheme axis { get { return m_Axis; } set { m_Axis = value; SetAllDirty(); } } + public RadiusAxisTheme radiusAxis { get { return m_RadiusAxis; } set { m_RadiusAxis = value; SetAllDirty(); } } + public AngleAxisTheme angleAxis { get { return m_AngleAxis; } set { m_AngleAxis = value; SetAllDirty(); } } + public PolarAxisTheme polar { get { return m_Polar; } set { m_Polar = value; SetAllDirty(); } } + public GaugeAxisTheme gauge { get { return m_Gauge; } set { m_Gauge = value; SetAllDirty(); } } + public RadarAxisTheme radar { get { return m_Radar; } set { m_Radar = value; SetAllDirty(); } } + public TooltipTheme tooltip { get { return m_Tooltip; } set { m_Tooltip = value; SetAllDirty(); } } + public DataZoomTheme dataZoom { get { return m_DataZoom; } set { m_DataZoom = value; SetAllDirty(); } } + public VisualMapTheme visualMap { get { return m_VisualMap; } set { m_VisualMap = value; SetAllDirty(); } } + public SerieTheme serie { get { return m_Serie; } set { m_Serie = value; SetVerticesDirty(); } } +#if dUI_TextMeshPro + /// <summary> + /// the font of chart text。 + /// 字体。 + /// </summary> + public TMP_FontAsset tmpFont + { + get { return m_TMPFont; } + set + { + if (PropertyUtil.SetClass(ref m_TMPFont, value)) + { + SetComponentDirty(); + SyncTMPFontToSubComponent(); + } + } + } +#endif + /// <summary> + /// the font of chart text。 + /// 字体。 + /// </summary> + public Font font + { + get { return m_Font; } + set + { + if (PropertyUtil.SetClass(ref m_Font, value)) + { + SetComponentDirty(); + SyncFontToSubComponent(); + } + } + } + + [NonSerialized] protected bool m_VertsDirty; + [NonSerialized] protected bool m_ComponentDirty; + public virtual bool vertsDirty { get { return m_VertsDirty; } } + public virtual bool componentDirty { get { return m_ComponentDirty; } } + public bool anyDirty { get { return vertsDirty || componentDirty; } } + + public void SetDefaultFont() + { +#if dUI_TextMeshPro + tmpFont = XChartsSettings.tmpFont; + SyncTMPFontToSubComponent(); +#else + font = XChartsSettings.font; + SyncFontToSubComponent(); +#endif + } + + /// <summary> + /// Gets the color of the specified index from the palette. + /// 获得调色盘对应系列索引的颜色值。 + /// </summary> + /// <param name="index">编号索引</param> + /// <returns>the color,or Color.clear when failed.颜色值,失败时返回Color.clear</returns> + public Color32 GetColor(int index) + { + if (index < 0) index = 0; + var newIndex = index < m_ColorPalette.Count ? index : index % m_ColorPalette.Count; + if (newIndex < m_ColorPalette.Count) + return m_ColorPalette[newIndex]; + else return Color.clear; + } + + public void CheckWarning(StringBuilder sb) + { +#if dUI_TextMeshPro + if (m_TMPFont == null) + { + sb.AppendFormat("warning:theme->tmpFont is null\n"); + } +#else + if (m_Font == null) + { + sb.AppendFormat("warning:theme->font is null\n"); + } +#endif + if (m_ColorPalette.Count == 0) + { + sb.AppendFormat("warning:theme->colorPalette is empty\n"); + } + for (int i = 0; i < m_ColorPalette.Count; i++) + { + if (!ChartHelper.IsClearColor(m_ColorPalette[i]) && m_ColorPalette[i].a == 0) + sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i); + } + } + + Dictionary<int, string> _colorDic = new Dictionary<int, string>(); + /// <summary> + /// Gets the hexadecimal color string of the specified index from the palette. + /// 获得指定索引的十六进制颜色值字符串。 + /// </summary> + /// <param name="index"></param> + /// <returns></returns> + public string GetColorStr(int index) + { + if (index < 0) + { + index = 0; + } + index = index % m_ColorPalette.Count; + if (_colorDic.ContainsKey(index)) return _colorDic[index]; + else + { + _colorDic[index] = ColorUtility.ToHtmlStringRGBA(GetColor(index)); + return _colorDic[index]; + } + } + + public void CopyTheme(Theme theme) + { + switch (theme) + { + case Theme.Dark: + CopyTheme(ChartTheme.Dark); + break; + case Theme.Default: + CopyTheme(ChartTheme.Default); + break; + case Theme.Light: + CopyTheme(ChartTheme.Light); + break; + } + } + + /// <summary> + /// copy all configurations from theme. + /// 复制主题的所有配置。 + /// </summary> + /// <param name="theme"></param> + public void CopyTheme(ChartTheme theme) + { + m_Theme = theme.theme; + m_ThemeName = theme.themeName; +#if dUI_TextMeshPro + m_TMPFont = theme.tmpFont; +#endif + m_Font = theme.m_Font; + m_ContrastColor = theme.contrastColor; + m_BackgroundColor = theme.m_BackgroundColor; + m_Common.Copy(theme.common); + m_Legend.Copy(theme.m_Legend); + m_Title.Copy(theme.m_Title); + m_SubTitle.Copy(theme.m_SubTitle); + m_Axis.Copy(theme.axis); + m_RadiusAxis.Copy(theme.radiusAxis); + m_AngleAxis.Copy(theme.angleAxis); + m_Polar.Copy(theme.polar); + m_Gauge.Copy(theme.gauge); + m_Tooltip.Copy(theme.tooltip); + m_DataZoom.Copy(theme.dataZoom); + m_VisualMap.Copy(theme.visualMap); + m_Serie.Copy(theme.serie); + ChartHelper.CopyList(m_ColorPalette, theme.colorPalette); + SetAllDirty(); + } + + /// <summary> + /// Clear all custom configurations. + /// 重置,清除所有自定义配置。 + /// </summary> + public void ResetTheme() + { + switch (m_Theme) + { + case Theme.Default: CopyTheme(Default); break; + case Theme.Light: CopyTheme(Light); break; + case Theme.Dark: CopyTheme(Dark); break; + } + } + + + + /// <summary> + /// default theme. + /// 默认主题。 + /// </summary> + /// <value></value> + public static ChartTheme Default + { + get + { + var theme = ScriptableObject.CreateInstance<ChartTheme>(); + theme.theme = Theme.Default; + theme.themeName = Theme.Default.ToString(); + theme.contrastColor = ColorUtil.GetColor("#514D4D"); + theme.backgroundColor = new Color32(255, 255, 255, 255); + theme.colorPalette = new List<Color32> + { + new Color32(194, 53, 49, 255), + new Color32(47, 69, 84, 255), + new Color32(97, 160, 168, 255), + new Color32(212, 130, 101, 255), + new Color32(145, 199, 174, 255), + new Color32(116, 159, 131, 255), + new Color32(202, 134, 34, 255), + new Color32(189, 162, 154, 255), + new Color32(110, 112, 116, 255), + new Color32(84, 101, 112, 255), + new Color32(196, 204, 211, 255) + }; + InitChartComponentTheme(theme); + return theme; + } + } + + /// <summary> + /// light theme. + /// 亮主题。 + /// </summary> + /// <value></value> + public static ChartTheme Light + { + get + { + var theme = ScriptableObject.CreateInstance<ChartTheme>(); + theme.theme = Theme.Light; + theme.themeName = Theme.Light.ToString(); + theme.contrastColor = ColorUtil.GetColor("#514D4D"); + theme.backgroundColor = new Color32(255, 255, 255, 255); + theme.colorPalette = new List<Color32> + { + ColorUtil.GetColor("#37A2DA"), + ColorUtil.GetColor("#32C5E9"), + ColorUtil.GetColor("#67E0E3"), + ColorUtil.GetColor("#9FE6B8"), + ColorUtil.GetColor("#FFDB5C"), + ColorUtil.GetColor("#ff9f7f"), + ColorUtil.GetColor("#fb7293"), + ColorUtil.GetColor("#E062AE"), + ColorUtil.GetColor("#E690D1"), + ColorUtil.GetColor("#e7bcf3"), + ColorUtil.GetColor("#9d96f5"), + ColorUtil.GetColor("#8378EA"), + ColorUtil.GetColor("#96BFFF"), + }; + InitChartComponentTheme(theme); + return theme; + } + } + + /// <summary> + /// dark theme. + /// 暗主题。 + /// </summary> + /// <value></value> + public static ChartTheme Dark + { + get + { + var theme = ScriptableObject.CreateInstance<ChartTheme>(); + theme.name = Theme.Dark.ToString(); + theme.theme = Theme.Dark; + theme.themeName = Theme.Dark.ToString(); + theme.contrastColor = ColorUtil.GetColor("#B9B8CE"); + theme.backgroundColor = ColorUtil.GetColor("#100C2A"); + theme.colorPalette = new List<Color32> + { + ColorUtil.GetColor("#4992ff"), + ColorUtil.GetColor("#7cffb2"), + ColorUtil.GetColor("#fddd60"), + ColorUtil.GetColor("#ff6e76"), + ColorUtil.GetColor("#58d9f9"), + ColorUtil.GetColor("#05c091"), + ColorUtil.GetColor("#ff8a45"), + ColorUtil.GetColor("#8d48e3"), + ColorUtil.GetColor("#dd79ff"), + }; + InitChartComponentTheme(theme); + return theme; + } + } + + public static ChartTheme EmptyTheme + { + get + { + var theme = ScriptableObject.CreateInstance<ChartTheme>(); + theme.name = Theme.Custom.ToString(); + theme.theme = Theme.Custom; + theme.themeName = Theme.Custom.ToString(); + theme.contrastColor = Color.clear; + theme.backgroundColor = Color.clear; + theme.colorPalette = new List<Color32>(); + InitChartComponentTheme(theme); + return theme; + } + } + + public void SyncFontToSubComponent() + { + common.font = font; + title.font = font; + subTitle.font = font; + legend.font = font; + axis.font = font; + radiusAxis.font = font; + angleAxis.font = font; + polar.font = font; + gauge.font = font; + radar.font = font; + tooltip.font = font; + dataZoom.font = font; + visualMap.font = font; + } + +#if dUI_TextMeshPro + public void SyncTMPFontToSubComponent() + { + common.tmpFont = tmpFont; + title.tmpFont = tmpFont; + subTitle.tmpFont = tmpFont; + legend.tmpFont = tmpFont; + axis.tmpFont = tmpFont; + radiusAxis.tmpFont = tmpFont; + angleAxis.tmpFont = tmpFont; + polar.tmpFont = tmpFont; + gauge.tmpFont = tmpFont; + radar.tmpFont = tmpFont; + tooltip.tmpFont = tmpFont; + dataZoom.tmpFont = tmpFont; + visualMap.tmpFont = tmpFont; + } +#endif + + private static void InitChartComponentTheme(ChartTheme theme) + { + theme.common = new ComponentTheme(theme.theme); + theme.title = new TitleTheme(theme.theme); + theme.subTitle = new SubTitleTheme(theme.theme); + theme.legend = new LegendTheme(theme.theme); + theme.axis = new AxisTheme(theme.theme); + theme.radiusAxis = new RadiusAxisTheme(theme.theme); + theme.angleAxis = new AngleAxisTheme(theme.theme); + theme.polar = new PolarAxisTheme(theme.theme); + theme.gauge = new GaugeAxisTheme(theme.theme); + theme.radar = new RadarAxisTheme(theme.theme); + theme.tooltip = new TooltipTheme(theme.theme); + theme.dataZoom = new DataZoomTheme(theme.theme); + theme.visualMap = new VisualMapTheme(theme.theme); + theme.serie = new SerieTheme(theme.theme); + theme.SetDefaultFont(); + } + + /// <summary> + /// Convert the html string to color. + /// 将字符串颜色值转成Color。 + /// </summary> + /// <param name="hexColorStr"></param> + /// <returns></returns> + public static Color32 GetColor(string hexColorStr) + { + Color color; + ColorUtility.TryParseHtmlString(hexColorStr, out color); + return (Color32)color; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + internal virtual void SetVerticesDirty() + { + m_VertsDirty = true; + } + + internal virtual void ClearVerticesDirty() + { + m_VertsDirty = false; + } + + internal virtual void SetComponentDirty() + { + m_ComponentDirty = true; + } + + internal virtual void ClearComponentDirty() + { + m_ComponentDirty = false; + } + + public virtual void ClearDirty() + { + ClearVerticesDirty(); + ClearComponentDirty(); + } + + public virtual void SetAllDirty() + { + SetVerticesDirty(); + SetComponentDirty(); + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/ChartTheme.cs.meta b/Runtime/Component/Theme/ChartTheme.cs.meta new file mode 100644 index 00000000..9b00c9dc --- /dev/null +++ b/Runtime/Component/Theme/ChartTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f28c6b3fb24d49afbe348cfadd0e1c7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/ComponentTheme.cs b/Runtime/Component/Theme/ComponentTheme.cs new file mode 100644 index 00000000..43059732 --- /dev/null +++ b/Runtime/Component/Theme/ComponentTheme.cs @@ -0,0 +1,109 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + [Serializable] + public class ComponentTheme : MainComponent + { + [SerializeField] protected Font m_Font; + [SerializeField] protected Color m_TextColor; + [SerializeField] protected Color m_TextBackgroundColor; + [SerializeField] protected int m_FontSize = 18; +#if dUI_TextMeshPro + [SerializeField] protected TMP_FontAsset m_TMPFont; +#endif + + /// <summary> + /// the font of text。 + /// 字体。 + /// </summary> + public Font font + { + get { return m_Font; } + set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); } + } + /// <summary> + /// the color of text. + /// 文本颜色。 + /// </summary> + public Color textColor + { + get { return m_TextColor; } + set { if (PropertyUtil.SetColor(ref m_TextColor, value)) SetComponentDirty(); } + } + /// <summary> + /// the color of text. + /// 文本颜色。 + /// </summary> + public Color textBackgroundColor + { + get { return m_TextBackgroundColor; } + set { if (PropertyUtil.SetColor(ref m_TextBackgroundColor, value)) SetComponentDirty(); } + } + /// <summary> + /// the font size of text. + /// 文本字体大小。 + /// </summary> + public int fontSize + { + get { return m_FontSize; } + set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); } + } + +#if dUI_TextMeshPro + /// <summary> + /// the font of chart text。 + /// 字体。 + /// </summary> + public TMP_FontAsset tmpFont + { + get { return m_TMPFont; } + set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); } + } +#endif + + public ComponentTheme(Theme theme) + { + m_FontSize = XChartsSettings.fontSizeLv3; + switch (theme) + { + case Theme.Default: + m_TextColor = ColorUtil.GetColor("#514D4D"); + break; + case Theme.Light: + m_TextColor = ColorUtil.GetColor("#514D4D"); + break; + case Theme.Dark: + m_TextColor = ColorUtil.GetColor("#B9B8CE"); + break; + } + } + + public virtual void Copy(ComponentTheme theme) + { + m_Font = theme.font; + m_FontSize = theme.fontSize; + m_TextColor = theme.textColor; + m_TextBackgroundColor = theme.textBackgroundColor; +#if dUI_TextMeshPro + m_TMPFont = theme.tmpFont; +#endif + } + + public virtual void Reset(ComponentTheme defaultTheme) + { + Copy(defaultTheme); + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/ComponentTheme.cs.meta b/Runtime/Component/Theme/ComponentTheme.cs.meta new file mode 100644 index 00000000..e401a886 --- /dev/null +++ b/Runtime/Component/Theme/ComponentTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e78d1c80572324fc0b5cc5c935a2e34c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/DataZoomTheme.cs b/Runtime/Component/Theme/DataZoomTheme.cs new file mode 100644 index 00000000..544400f2 --- /dev/null +++ b/Runtime/Component/Theme/DataZoomTheme.cs @@ -0,0 +1,132 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using UnityEngine; + +namespace XCharts +{ + [Serializable] + public class DataZoomTheme : ComponentTheme + { + [SerializeField] protected float m_BorderWidth; + [SerializeField] protected float m_DataLineWidth; + [SerializeField] protected Color32 m_FillerColor; + [SerializeField] protected Color32 m_BorderColor; + [SerializeField] protected Color32 m_DataLineColor; + [SerializeField] protected Color32 m_DataAreaColor; + [SerializeField] protected Color32 m_BackgroundColor; + + /// <summary> + /// the width of border line. + /// 边框线宽。 + /// </summary> + public float borderWidth + { + get { return m_BorderWidth; } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } + } + /// <summary> + /// the width of data line. + /// 数据阴影线宽。 + /// </summary> + public float dataLineWidth + { + get { return m_DataLineWidth; } + set { if (PropertyUtil.SetStruct(ref m_DataLineWidth, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of dataZoom data area. + /// 数据区域颜色。 + /// </summary> + public Color32 fillerColor + { + get { return m_FillerColor; } + set { if (PropertyUtil.SetColor(ref m_FillerColor, value)) SetVerticesDirty(); } + } + + /// <summary> + /// the color of dataZoom border. + /// 边框颜色。 + /// </summary> + public Color32 borderColor + { + get { return m_BorderColor; } + set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetComponentDirty(); } + } + /// <summary> + /// the color of data area line. + /// 数据阴影的线条颜色。 + /// </summary> + public Color32 dataLineColor + { + get { return m_DataLineColor; } + set { if (PropertyUtil.SetColor(ref m_DataLineColor, value)) SetComponentDirty(); } + } + /// <summary> + /// the color of data area line. + /// 数据阴影的填充颜色。 + /// </summary> + public Color32 dataAreaColor + { + get { return m_DataAreaColor; } + set { if (PropertyUtil.SetColor(ref m_DataAreaColor, value)) SetComponentDirty(); } + } + /// <summary> + /// the background color of datazoom. + /// 背景颜色。 + /// </summary> + public Color32 backgroundColor + { + get { return m_BackgroundColor; } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); } + } + + public DataZoomTheme(Theme theme) : base(theme) + { + m_BorderWidth = XChartsSettings.dataZoomBorderWidth; + m_DataLineWidth = XChartsSettings.dataZoomDataLineWidth; + m_BackgroundColor = Color.clear; + switch (theme) + { + case Theme.Default: + m_TextColor = ColorUtil.GetColor("#333"); + m_FillerColor = new Color32(167, 183, 204, 110); + m_BorderColor = ColorUtil.GetColor("#ddd"); + m_DataLineColor = ColorUtil.GetColor("#2f4554"); + m_DataAreaColor = new Color32(47, 69, 84, 85); + break; + case Theme.Light: + m_TextColor = ColorUtil.GetColor("#333"); + m_FillerColor = new Color32(167, 183, 204, 110); + m_BorderColor = ColorUtil.GetColor("#ddd"); + m_DataLineColor = ColorUtil.GetColor("#2f4554"); + m_DataAreaColor = new Color32(47, 69, 84, 85); + break; + case Theme.Dark: + m_TextColor = ColorUtil.GetColor("#B9B8CE"); + m_FillerColor = new Color32(135, 163, 206, (byte)(0.2f * 255)); + m_BorderColor = ColorUtil.GetColor("#71708A"); + m_DataLineColor = ColorUtil.GetColor("#71708A"); + m_DataAreaColor = ColorUtil.GetColor("#71708A"); + break; + } + } + + public void Copy(DataZoomTheme theme) + { + base.Copy(theme); + m_BorderWidth = theme.borderWidth; + m_DataLineWidth = theme.dataLineWidth; + m_FillerColor = theme.fillerColor; + m_BorderColor = theme.borderColor; + m_DataLineColor = theme.dataLineColor; + m_DataAreaColor = theme.dataAreaColor; + m_BackgroundColor = theme.backgroundColor; + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/DataZoomTheme.cs.meta b/Runtime/Component/Theme/DataZoomTheme.cs.meta new file mode 100644 index 00000000..9545b7f0 --- /dev/null +++ b/Runtime/Component/Theme/DataZoomTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ba535ef75742b4825b3cc2be4df6716f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/GaugeAxisTheme.cs b/Runtime/Component/Theme/GaugeAxisTheme.cs new file mode 100644 index 00000000..afeef0b4 --- /dev/null +++ b/Runtime/Component/Theme/GaugeAxisTheme.cs @@ -0,0 +1,83 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace XCharts +{ + [Serializable] + public class GaugeAxisTheme : BaseAxisTheme + { + [SerializeField] private Color32 m_BarBackgroundColor; + [SerializeField] + private List<StageColor> m_StageColor = new List<StageColor>() + { + new StageColor(0.2f,new Color32(145,199,174,255)), + new StageColor(0.8f,new Color32(99,134,158,255)), + new StageColor(1.0f,new Color32(194,53,49,255)), + }; + /// <summary> + /// 进度条背景颜色。 + /// </summary> + public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } } + /// <summary> + /// 阶段颜色。 + /// </summary> + public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } } + + public GaugeAxisTheme(Theme theme) : base(theme) + { + m_LineWidth = XChartsSettings.gaugeAxisLineWidth; + m_LineLength = 0; + m_SplitLineWidth = XChartsSettings.gaugeAxisSplitLineWidth; + m_SplitLineLength = XChartsSettings.gaugeAxisSplitLineLength; + m_TickWidth = XChartsSettings.gaugeAxisTickWidth; + m_TickLength = XChartsSettings.gaugeAxisTickLength; + m_SplitLineColor = Color.white; + m_TickColor = Color.white; + switch (theme) + { + case Theme.Default: + m_BarBackgroundColor = new Color32(200, 200, 200, 255); + m_StageColor = new List<StageColor>() + { + new StageColor(0.2f,new Color32(145,199,174,255)), + new StageColor(0.8f,new Color32(99,134,158,255)), + new StageColor(1.0f,new Color32(194,53,49,255)), + }; + break; + case Theme.Light: + m_BarBackgroundColor = new Color32(200, 200, 200, 255); + m_StageColor = new List<StageColor>() + { + new StageColor(0.2f,new Color32(145,199,174,255)), + new StageColor(0.8f,new Color32(99,134,158,255)), + new StageColor(1.0f,new Color32(194,53,49,255)), + }; + break; + case Theme.Dark: + m_BarBackgroundColor = new Color32(200, 200, 200, 255); + m_StageColor = new List<StageColor>() + { + new StageColor(0.2f,new Color32(145,199,174,255)), + new StageColor(0.8f,new Color32(99,134,158,255)), + new StageColor(1.0f,new Color32(194,53,49,255)), + }; + break; + } + } + + public void Copy(GaugeAxisTheme theme) + { + base.Copy(theme); + m_BarBackgroundColor = theme.barBackgroundColor; + ChartHelper.CopyList(m_StageColor, theme.stageColor); + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/GaugeAxisTheme.cs.meta b/Runtime/Component/Theme/GaugeAxisTheme.cs.meta new file mode 100644 index 00000000..d1484db3 --- /dev/null +++ b/Runtime/Component/Theme/GaugeAxisTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b38e4b45ec20b4c65a6dc82891c5c39a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/LegendTheme.cs b/Runtime/Component/Theme/LegendTheme.cs new file mode 100644 index 00000000..52bc8f5c --- /dev/null +++ b/Runtime/Component/Theme/LegendTheme.cs @@ -0,0 +1,43 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using UnityEngine; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + [Serializable] + public class LegendTheme : ComponentTheme + { + [SerializeField] protected Color m_UnableColor; + + /// <summary> + /// the color of text. + /// 文本颜色。 + /// </summary> + public Color unableColor + { + get { return m_UnableColor; } + set { if (PropertyUtil.SetColor(ref m_UnableColor, value)) SetComponentDirty(); } + } + + public void Copy(LegendTheme theme) + { + base.Copy(theme); + m_UnableColor = theme.unableColor; + } + + public LegendTheme(Theme theme) : base(theme) + { + m_UnableColor = ColorUtil.GetColor("#cccccc"); + + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/LegendTheme.cs.meta b/Runtime/Component/Theme/LegendTheme.cs.meta new file mode 100644 index 00000000..d544c654 --- /dev/null +++ b/Runtime/Component/Theme/LegendTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a86fb06a6b71c4735b87769ee0708293 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/SerieTheme.cs b/Runtime/Component/Theme/SerieTheme.cs new file mode 100644 index 00000000..5a30899b --- /dev/null +++ b/Runtime/Component/Theme/SerieTheme.cs @@ -0,0 +1,93 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using UnityEngine; + +namespace XCharts +{ + [Serializable] + public class SerieTheme : MainComponent + { + [SerializeField] protected float m_LineWidth; + [SerializeField] protected float m_LineSymbolSize; + [SerializeField] protected float m_LineSymbolSelectedSize; + [SerializeField] protected float m_ScatterSymbolSize; + [SerializeField] protected float m_ScatterSymbolSelectedSize; + [SerializeField] protected float m_PieTooltipExtraRadius; + [SerializeField] protected float m_PieSelectedOffset; + + /// <summary> + /// the color of text. + /// 文本颜色。 + /// </summary> + public float lineWidth + { + get { return m_LineWidth; } + set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); } + } + public float lineSymbolSize + { + get { return m_LineSymbolSize; } + set { if (PropertyUtil.SetStruct(ref m_LineSymbolSize, value)) SetVerticesDirty(); } + } + public float lineSymbolSelectedSize + { + get { return m_LineSymbolSelectedSize; } + set { if (PropertyUtil.SetStruct(ref m_LineSymbolSelectedSize, value)) SetVerticesDirty(); } + } + public float scatterSymbolSize + { + get { return m_ScatterSymbolSize; } + set { if (PropertyUtil.SetStruct(ref m_ScatterSymbolSize, value)) SetVerticesDirty(); } + } + public float scatterSymbolSelectedSize + { + get { return m_ScatterSymbolSelectedSize; } + set { if (PropertyUtil.SetStruct(ref m_ScatterSymbolSelectedSize, value)) SetVerticesDirty(); } + } + + /// <summary> + /// 饼图鼠标移到高亮时的额外半径 + /// </summary> + public float pieTooltipExtraRadius + { + get { return m_PieTooltipExtraRadius; } + set { if (PropertyUtil.SetStruct(ref m_PieTooltipExtraRadius, value < 0 ? 0f : value)) SetVerticesDirty(); } + } + /// <summary> + /// 饼图选中时的中心点偏移 + /// </summary> + public float pieSelectedOffset + { + get { return m_PieSelectedOffset; } + set { if (PropertyUtil.SetStruct(ref m_PieSelectedOffset, value < 0 ? 0f : value)) SetVerticesDirty(); } + } + + public void Copy(SerieTheme theme) + { + m_LineWidth = theme.lineWidth; + m_LineSymbolSize = theme.lineSymbolSize; + m_LineSymbolSelectedSize = theme.lineSymbolSelectedSize; + m_ScatterSymbolSize = theme.scatterSymbolSize; + m_ScatterSymbolSelectedSize = theme.scatterSymbolSelectedSize; + m_PieTooltipExtraRadius = theme.pieTooltipExtraRadius; + m_PieSelectedOffset = theme.pieSelectedOffset; + } + + public SerieTheme(Theme theme) + { + m_LineWidth = XChartsSettings.serieLineWidth; + m_LineSymbolSize = XChartsSettings.serieLineSymbolSize; + m_LineSymbolSelectedSize = XChartsSettings.serieLineSymbolSelectedSize; + m_ScatterSymbolSize = XChartsSettings.serieScatterSymbolSize; + m_ScatterSymbolSelectedSize = XChartsSettings.serieScatterSymbolSelectedSize; + m_PieTooltipExtraRadius = XChartsSettings.pieTooltipExtraRadius; + m_PieSelectedOffset = XChartsSettings.pieSelectedOffset; + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/SerieTheme.cs.meta b/Runtime/Component/Theme/SerieTheme.cs.meta new file mode 100644 index 00000000..66492388 --- /dev/null +++ b/Runtime/Component/Theme/SerieTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9030b0e4afb164967b4991247947b195 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/SubTitleTheme.cs b/Runtime/Component/Theme/SubTitleTheme.cs new file mode 100644 index 00000000..71e125a2 --- /dev/null +++ b/Runtime/Component/Theme/SubTitleTheme.cs @@ -0,0 +1,32 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; + +namespace XCharts +{ + [Serializable] + public class SubTitleTheme : ComponentTheme + { + public SubTitleTheme(Theme theme) : base(theme) + { + m_FontSize = XChartsSettings.fontSizeLv2; + switch (theme) + { + case Theme.Default: + m_TextColor = ColorUtil.GetColor("#969696"); + break; + case Theme.Light: + m_TextColor = ColorUtil.GetColor("#969696"); + break; + case Theme.Dark: + m_TextColor = ColorUtil.GetColor("#B9B8CE"); + break; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/SubTitleTheme.cs.meta b/Runtime/Component/Theme/SubTitleTheme.cs.meta new file mode 100644 index 00000000..c296a352 --- /dev/null +++ b/Runtime/Component/Theme/SubTitleTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c642293f2d6674cbb85d1f081b9d89e8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/TitleTheme.cs b/Runtime/Component/Theme/TitleTheme.cs new file mode 100644 index 00000000..909f8fd6 --- /dev/null +++ b/Runtime/Component/Theme/TitleTheme.cs @@ -0,0 +1,31 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; + +namespace XCharts +{ + [Serializable] + public class TitleTheme : ComponentTheme + { + public TitleTheme(Theme theme) : base(theme) + { + m_FontSize = XChartsSettings.fontSizeLv1; + switch (theme) + { + case Theme.Default: + m_TextColor = ColorUtil.GetColor("#514D4D"); + break; + case Theme.Light: + break; + case Theme.Dark: + m_TextColor = ColorUtil.GetColor("#EEF1FA"); + break; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/TitleTheme.cs.meta b/Runtime/Component/Theme/TitleTheme.cs.meta new file mode 100644 index 00000000..a409e267 --- /dev/null +++ b/Runtime/Component/Theme/TitleTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6649bc33964624c14a13ce34dd7eae77 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/TooltipTheme.cs b/Runtime/Component/Theme/TooltipTheme.cs new file mode 100644 index 00000000..f668bdf4 --- /dev/null +++ b/Runtime/Component/Theme/TooltipTheme.cs @@ -0,0 +1,123 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using UnityEngine; + +namespace XCharts +{ + [Serializable] + public class TooltipTheme : ComponentTheme + { + [SerializeField] protected LineStyle.Type m_LineType = LineStyle.Type.Solid; + [SerializeField] protected float m_LineWidth = 1f; + [SerializeField] protected Color32 m_LineColor; + [SerializeField] protected Color32 m_AreaColor; + [SerializeField] protected Color32 m_LabelTextColor; + [SerializeField] protected Color32 m_LabelBackgroundColor; + + /// <summary> + /// the type of line. + /// 坐标轴线类型。 + /// </summary> + public LineStyle.Type lineType + { + get { return m_LineType; } + set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); } + } + /// <summary> + /// the width of line. + /// 指示线线宽。 + /// </summary> + public float lineWidth + { + get { return m_LineWidth; } + set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of line. + /// 指示线颜色。 + /// </summary> + public Color32 lineColor + { + get { return m_LineColor; } + set { if (PropertyUtil.SetColor(ref m_LineColor, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of line. + /// 区域指示的颜色。 + /// </summary> + public Color32 areaColor + { + get { return m_AreaColor; } + set { if (PropertyUtil.SetColor(ref m_AreaColor, value)) SetVerticesDirty(); } + } + /// <summary> + /// the text color of tooltip cross indicator's axis label. + /// 十字指示器坐标轴标签的文本颜色。 + /// </summary> + public Color32 labelTextColor + { + get { return m_LabelTextColor; } + set { if (PropertyUtil.SetColor(ref m_LabelTextColor, value)) SetComponentDirty(); } + } + + /// <summary> + /// the background color of tooltip cross indicator's axis label. + /// 十字指示器坐标轴标签的背景颜色。 + /// </summary> + public Color32 labelBackgroundColor + { + get { return m_LabelBackgroundColor; } + set { if (PropertyUtil.SetColor(ref m_LabelBackgroundColor, value)) SetComponentDirty(); } + } + + public TooltipTheme(Theme theme) : base(theme) + { + m_LineType = LineStyle.Type.Solid; + m_LineWidth = XChartsSettings.tootipLineWidth; + switch (theme) + { + case Theme.Default: + m_TextBackgroundColor = ColorUtil.GetColor("#515151C8"); + m_TextColor = ColorUtil.GetColor("#FFFFFFFF"); + m_AreaColor = ColorUtil.GetColor("#51515120"); + m_LabelTextColor = ColorUtil.GetColor("#FFFFFFFF"); + m_LabelBackgroundColor = ColorUtil.GetColor("#292929FF"); + m_LineColor = ColorUtil.GetColor("#29292964"); + break; + case Theme.Light: + m_TextBackgroundColor = ColorUtil.GetColor("#515151C8"); + m_TextColor = ColorUtil.GetColor("#FFFFFFFF"); + m_AreaColor = ColorUtil.GetColor("#51515120"); + m_LabelTextColor = ColorUtil.GetColor("#FFFFFFFF"); + m_LabelBackgroundColor = ColorUtil.GetColor("#292929FF"); + m_LineColor = ColorUtil.GetColor("#29292964"); + break; + case Theme.Dark: + m_TextBackgroundColor = ColorUtil.GetColor("#515151C8"); + m_TextColor = ColorUtil.GetColor("#FFFFFFFF"); + m_AreaColor = ColorUtil.GetColor("#51515120"); + m_LabelTextColor = ColorUtil.GetColor("#FFFFFFFF"); + m_LabelBackgroundColor = ColorUtil.GetColor("#A7A7A7FF"); + m_LineColor = ColorUtil.GetColor("#eee"); + break; + } + } + + public void Copy(TooltipTheme theme) + { + base.Copy(theme); + m_LineType = theme.lineType; + m_LineWidth = theme.lineWidth; + m_LineColor = theme.lineColor; + m_AreaColor = theme.areaColor; + m_LabelTextColor = theme.labelTextColor; + m_LabelBackgroundColor = theme.labelBackgroundColor; + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/TooltipTheme.cs.meta b/Runtime/Component/Theme/TooltipTheme.cs.meta new file mode 100644 index 00000000..534835ce --- /dev/null +++ b/Runtime/Component/Theme/TooltipTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f38f041e827e042a88338628b2b2c0db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Component/Theme/VisualMapTheme.cs b/Runtime/Component/Theme/VisualMapTheme.cs new file mode 100644 index 00000000..f3486f41 --- /dev/null +++ b/Runtime/Component/Theme/VisualMapTheme.cs @@ -0,0 +1,93 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using UnityEngine; + +namespace XCharts +{ + [Serializable] + public class VisualMapTheme : ComponentTheme + { + [SerializeField] protected float m_BorderWidth; + [SerializeField] protected Color32 m_BorderColor; + [SerializeField] protected Color32 m_BackgroundColor; + [SerializeField] [Range(10, 50)] protected float m_TriangeLen = 20f; + + /// <summary> + /// the width of border. + /// 边框线宽。 + /// </summary> + public float borderWidth + { + get { return m_BorderWidth; } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } + } + /// <summary> + /// the color of dataZoom border. + /// 边框颜色。 + /// </summary> + public Color32 borderColor + { + get { return m_BorderColor; } + set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetComponentDirty(); } + } + + /// <summary> + /// the background color of visualmap. + /// 背景颜色。 + /// </summary> + public Color32 backgroundColor + { + get { return m_BackgroundColor; } + set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); } + } + /// <summary> + /// 可视化组件的调节三角形边长。 + /// </summary> + /// <value></value> + public float triangeLen + { + get { return m_TriangeLen; } + set { if (PropertyUtil.SetStruct(ref m_TriangeLen, value < 0 ? 1f : value)) SetVerticesDirty(); } + } + + public VisualMapTheme(Theme theme) : base(theme) + { + m_BorderWidth = XChartsSettings.visualMapBorderWidth; + m_TriangeLen = XChartsSettings.visualMapTriangeLen; + m_FontSize = XChartsSettings.fontSizeLv4; + switch (theme) + { + case Theme.Default: + m_TextColor = ColorUtil.GetColor("#333"); + m_BorderColor = ColorUtil.GetColor("#ccc"); + m_BackgroundColor = ColorUtil.clearColor32; + break; + case Theme.Light: + m_TextColor = ColorUtil.GetColor("#333"); + m_BorderColor = ColorUtil.GetColor("#ccc"); + m_BackgroundColor = ColorUtil.clearColor32; + break; + case Theme.Dark: + m_TextColor = ColorUtil.GetColor("#B9B8CE"); + m_BorderColor = ColorUtil.GetColor("#ccc"); + m_BackgroundColor = ColorUtil.clearColor32; + break; + } + } + + public void Copy(VisualMapTheme theme) + { + base.Copy(theme); + m_TriangeLen = theme.triangeLen; + m_BorderWidth = theme.borderWidth; + m_BorderColor = theme.borderColor; + m_BackgroundColor = theme.backgroundColor; + } + } +} \ No newline at end of file diff --git a/Runtime/Component/Theme/VisualMapTheme.cs.meta b/Runtime/Component/Theme/VisualMapTheme.cs.meta new file mode 100644 index 00000000..e737722e --- /dev/null +++ b/Runtime/Component/Theme/VisualMapTheme.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35e5797039b994b23850aaa7ca827766 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/GaugeChart.cs b/Runtime/GaugeChart.cs index fdbdf92e..c327bf7b 100644 --- a/Runtime/GaugeChart.cs +++ b/Runtime/GaugeChart.cs @@ -1,13 +1,12 @@ using System; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; -using UnityEngine.UI; namespace XCharts { @@ -17,49 +16,12 @@ namespace XCharts [DisallowMultipleComponent] public class GaugeChart : BaseChart { - private static readonly string s_AxisLabelObjectName = "axis_label"; - private bool m_UpdateTitleText = false; - private bool m_UpdateLabelText = false; - - protected override void Awake() - { - base.Awake(); - InitAxisLabel(); - } - - protected override void Start() - { - base.Start(); - foreach (var serie in m_Series.list) - { - TitleStyleHelper.CheckTitle(serie, ref m_ReinitTitle, ref m_UpdateTitleText); - SerieLabelHelper.CheckLabel(serie, ref m_ReinitLabel, ref m_UpdateLabelText); - } - UpdateAxisLabel(); - } - - protected override void Update() - { - base.Update(); - if (m_UpdateTitleText) - { - m_UpdateTitleText = false; - TitleStyleHelper.UpdateTitleText(m_Series); - } - if (m_UpdateLabelText) - { - m_UpdateLabelText = false; - SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName); - UpdateAxisLabel(); - } - } - #if UNITY_EDITOR protected override void Reset() { base.Reset(); RemoveData(); - m_Title.text = "GuageChart"; + title.text = "GuageChart"; var serie = AddSerie(SerieType.Gauge, "serie1"); serie.min = 0; serie.max = 100; @@ -78,295 +40,7 @@ namespace XCharts serie.gaugeAxis.axisLabel.show = true; serie.gaugeAxis.axisLabel.margin = 18; AddData(0, UnityEngine.Random.Range(10, 90), "title"); - InitAxisLabel(); } #endif - - private void InitAxisLabel() - { - var labelObject = ChartHelper.AddObject(s_AxisLabelObjectName, transform, m_ChartMinAnchor, - m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta); - SerieLabelPool.ReleaseAll(labelObject.transform); - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.list[i]; - var serieLabel = serie.gaugeAxis.axisLabel; - var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1); - var startAngle = serie.startAngle; - serie.gaugeAxis.ClearLabelObject(); - SerieHelper.UpdateCenter(serie, chartPosition, chartWidth, chartHeight); - for (int j = 0; j < count; j++) - { - var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j); - var color = Color.grey; - var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, m_ThemeInfo.font, color, 100, 100); - var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>(); - var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; - var item = new LabelObject(); - item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); - item.SetIcon(iconImage); - item.SetIconActive(false); - serie.gaugeAxis.AddLabelObject(item); - } - UpdateAxisLabel(serie); - } - } - - protected override void DrawChart(VertexHelper vh) - { - base.DrawChart(vh); - DrawData(vh); - } - - protected override void OnThemeChanged() - { - base.OnThemeChanged(); - } - - protected override void OnSizeChanged() - { - base.OnSizeChanged(); - InitAxisLabel(); - } - - private void DrawData(VertexHelper vh) - { - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.list[i]; - if (serie.type != SerieType.Gauge) continue; - DrawGauge(vh, serie); - } - } - - private void DrawGauge(VertexHelper vh, Serie serie) - { - SerieHelper.UpdateCenter(serie, chartPosition, chartWidth, chartHeight); - var destAngle = GetCurrAngle(serie, true); - serie.animation.InitProgress(0, serie.startAngle, destAngle); - var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); - DrawProgressBar(vh, serie, currAngle); - DrawStageColor(vh, serie); - DrawLineStyle(vh, serie); - DrawAxisTick(vh, serie); - DrawPointer(vh, serie, currAngle); - TitleStyleHelper.CheckTitle(serie, ref m_ReinitTitle, ref m_UpdateTitleText); - SerieLabelHelper.CheckLabel(serie, ref m_ReinitLabel, ref m_UpdateLabelText); - CheckAnimation(serie); - if (!serie.animation.IsFinish()) - { - serie.animation.CheckProgress(destAngle - serie.startAngle); - RefreshChart(); - } - else if (NeedRefresh(serie)) - { - RefreshChart(); - } - } - - private void DrawProgressBar(VertexHelper vh, Serie serie, float currAngle) - { - if (serie.gaugeType != GaugeType.ProgressBar) return; - if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return; - var color = serie.gaugeAxis.GetAxisLineColor(m_ThemeInfo, serie.index); - var backgroundColor = serie.gaugeAxis.GetAxisLineBackgroundColor(m_ThemeInfo, serie.index); - var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width; - var borderWidth = serie.itemStyle.borderWidth; - var borderColor = serie.itemStyle.borderColor; - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius, - backgroundColor, backgroundColor, Color.clear, serie.startAngle, serie.endAngle, 0, Color.clear, - 0, m_Settings.cicleSmoothness, serie.roundCap); - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius, - color, color, Color.clear, serie.startAngle, currAngle, 0, Color.clear, - 0, m_Settings.cicleSmoothness, serie.roundCap); - } - - private void DrawStageColor(VertexHelper vh, Serie serie) - { - if (serie.gaugeType != GaugeType.Pointer) return; - if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return; - var totalAngle = serie.endAngle - serie.startAngle; - var tempStartAngle = serie.startAngle; - var tempEndAngle = serie.startAngle; - var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width; - serie.gaugeAxis.runtimeStageAngle.Clear(); - for (int i = 0; i < serie.gaugeAxis.axisLine.stageColor.Count; i++) - { - var stageColor = serie.gaugeAxis.axisLine.stageColor[i]; - tempEndAngle = serie.startAngle + totalAngle * stageColor.percent; - serie.gaugeAxis.runtimeStageAngle.Add(tempEndAngle); - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius, - stageColor.color, stageColor.color, Color.clear, tempStartAngle, tempEndAngle, 0, Color.clear, - 0, m_Settings.cicleSmoothness); - tempStartAngle = tempEndAngle; - } - } - - private void DrawPointer(VertexHelper vh, Serie serie, float currAngle) - { - if (!serie.gaugePointer.show) return; - var pointerColor = serie.gaugeAxis.GetPointerColor(m_ThemeInfo, serie.index, currAngle, serie.itemStyle); - var pointerToColor = !ChartHelper.IsClearColor(serie.itemStyle.toColor) ? serie.itemStyle.toColor : pointerColor; - var len = serie.gaugePointer.length < 1 && serie.gaugePointer.length > -1 ? - serie.runtimeInsideRadius * serie.gaugePointer.length : - serie.gaugePointer.length; - var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len); - var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width); - var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2); - var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2); - ChartDrawer.DrawTriangle(vh, p2, p3, p1, pointerColor, pointerColor, pointerToColor); - ChartDrawer.DrawTriangle(vh, p4, p2, p1, pointerColor, pointerColor, pointerToColor); - } - - private void DrawLineStyle(VertexHelper vh, Serie serie) - { - if (serie.gaugeType != GaugeType.Pointer) return; - if (!serie.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return; - if (serie.splitNumber <= 0) return; - var splitLine = serie.gaugeAxis.splitLine; - var totalAngle = serie.endAngle - serie.startAngle; - var diffAngle = totalAngle / serie.splitNumber; - var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width; - var insideRadius = outsideRadius - splitLine.length; - var lineWidth = splitLine.lineStyle.width; - for (int i = 0; i < serie.splitNumber + 1; i++) - { - var angle = serie.startAngle + i * diffAngle; - var lineColor = serie.gaugeAxis.GetSplitLineColor(m_ThemeInfo, serie.index, angle); - var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius); - var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius); - ChartDrawer.DrawLine(vh, p1, p2, lineWidth, lineColor); - } - } - - private void DrawAxisTick(VertexHelper vh, Serie serie) - { - if (serie.gaugeType != GaugeType.Pointer) return; - if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisTick.show) return; - if (serie.splitNumber <= 0) return; - var axisTick = serie.gaugeAxis.axisTick; - var totalAngle = serie.endAngle - serie.startAngle; - var diffAngle = totalAngle / serie.splitNumber; - var outsideRadius = serie.runtimeInsideRadius + serie.gaugeAxis.axisLine.width; - var insideRadius = outsideRadius - (axisTick.length < 1 ? serie.gaugeAxis.axisLine.width * axisTick.length : axisTick.length); - var lineWidth = axisTick.lineStyle.width; - for (int i = 0; i < serie.splitNumber; i++) - { - for (int j = 1; j < axisTick.splitNumber; j++) - { - var angle = serie.startAngle + i * diffAngle + j * (diffAngle / axisTick.splitNumber); - var lineColor = serie.gaugeAxis.GetSplitLineColor(m_ThemeInfo, serie.index, angle); - var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius); - var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius); - ChartDrawer.DrawLine(vh, p1, p2, lineWidth, lineColor); - } - } - } - - - private bool NeedRefresh(Serie serie) - { - if (serie.type == SerieType.Gauge) - { - var serieData = serie.GetSerieData(0); - if (serieData != null) - { - var destValue = serieData.GetData(1); - var currValue = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration()); - return destValue != currValue; - } - } - return false; - } - - private void DrawRoundCap(VertexHelper vh, Serie serie, float angle, Color color, bool invert = false) - { - var radius = serie.gaugeAxis.axisLine.width / 2; - var len = serie.runtimeInsideRadius + radius; - var pos = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, len); - var startAngle = invert ? angle + 180 : angle; - var endAngle = invert ? angle + 360 : angle + 180; - ChartDrawer.DrawSector(vh, pos, radius, color, startAngle, endAngle); - } - - private void CheckAnimation(Serie serie) - { - var serieData = serie.GetSerieData(0); - if (serieData != null) - { - var value = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration()); - var data = serieData.GetData(1); - if (value != data) m_RefreshChart = true; - } - } - - private void UpdateAxisLabel(Serie serie) - { - var show = serie.gaugeAxis.show && serie.gaugeAxis.axisLabel.show; - serie.gaugeAxis.SetLabelObjectActive(show); - if (!show) - { - return; - } - var count = serie.splitNumber > 36 ? 36 : serie.splitNumber; - var startAngle = serie.startAngle; - var totalAngle = serie.endAngle - serie.startAngle; - var totalValue = serie.max - serie.min; - var diffAngle = totalAngle / count; - var diffValue = totalValue / count; - var radius = serie.runtimeInsideRadius - serie.gaugeAxis.axisLabel.margin; - var serieData = serie.GetSerieData(0); - var customLabelText = serie.gaugeAxis.axisLabelText; - for (int j = 0; j <= count; j++) - { - var angle = serie.startAngle + j * diffAngle; - var value = serie.min + j * diffValue; - var pos = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, radius); - var text = customLabelText != null && j < customLabelText.Count ? customLabelText[j] : - SerieLabelHelper.GetFormatterContent(serie, serieData, value, totalValue, serie.gaugeAxis.axisLabel); - serie.gaugeAxis.SetLabelObjectText(j, text); - serie.gaugeAxis.SetLabelObjectPosition(j, pos); - } - } - - private void UpdateAxisLabel() - { - foreach (var serie in m_Series.list) - { - if (serie.type == SerieType.Gauge) - { - UpdateAxisLabel(serie); - } - } - } - - private float GetCurrAngle(Serie serie, bool dest) - { - if (serie.animation.HasFadeOut()) - { - return serie.animation.GetCurrDetail(); - } - float rangeValue = serie.max - serie.min; - float rangeAngle = serie.endAngle - serie.startAngle; - float value = 0; - float angle = serie.startAngle; - if (serie.dataCount > 0) - { - var serieData = serie.data[0]; - serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset; - value = dest ? serieData.GetData(1) : serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration()); - value = Mathf.Clamp(value, serie.min, serie.max); - } - if (rangeValue > 0) - { - angle += rangeAngle * value / rangeValue; - } - return angle; - } - - protected override void OnRefreshLabel() - { - //TODO: - } } } diff --git a/Runtime/HeatmapChart.cs b/Runtime/HeatmapChart.cs index 9e9ac543..879fdd2c 100644 --- a/Runtime/HeatmapChart.cs +++ b/Runtime/HeatmapChart.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -21,54 +21,48 @@ namespace XCharts protected override void Reset() { base.Reset(); - m_Title.text = "HeatmapChart"; - m_Tooltip.type = Tooltip.Type.None; - m_Grid.left = 100; - m_Grid.right = 60; - m_Grid.bottom = 60; + title.text = "HeatmapChart"; + tooltip.type = Tooltip.Type.None; + grid.left = 100; + grid.right = 60; + grid.bottom = 60; - m_XAxises[0].type = Axis.AxisType.Category; - m_XAxises[0].boundaryGap = false; - m_YAxises[0].type = Axis.AxisType.Category; - m_YAxises[0].boundaryGap = false; - m_XAxises[0].splitNumber = 10; - m_YAxises[0].splitNumber = 10; + m_XAxes[0].type = Axis.AxisType.Category; + m_XAxes[0].boundaryGap = false; + m_YAxes[0].type = Axis.AxisType.Category; + m_YAxes[0].boundaryGap = false; + m_XAxes[0].splitNumber = 10; + m_YAxes[0].splitNumber = 10; RemoveData(); - var serie = AddSerie(SerieType.Heatmap, "serie1"); var heatmapGridWid = 10f; - int xSplitNumber = (int)(m_CoordinateWidth / heatmapGridWid); - int ySplitNumber = (int)(m_CoordinateHeight / heatmapGridWid); - serie.itemStyle.show = true; - serie.itemStyle.borderWidth = 1; - serie.itemStyle.borderColor = Color.clear; - serie.emphasis.show = true; - serie.emphasis.itemStyle.show = true; - serie.emphasis.itemStyle.borderWidth = 1; - serie.emphasis.itemStyle.borderColor = Color.black; + int xSplitNumber = (int)(grid.runtimeWidth / heatmapGridWid); + int ySplitNumber = (int)(grid.runtimeHeight / heatmapGridWid); - m_VisualMap.enable = true; - m_VisualMap.max = 10; - m_VisualMap.range[0] = 0f; - m_VisualMap.range[1] = 10f; - m_VisualMap.orient = Orient.Vertical; - m_VisualMap.calculable = true; - m_VisualMap.location.align = Location.Align.BottomLeft; - m_VisualMap.location.bottom = 100; - m_VisualMap.location.left = 30; + SerieTemplate.AddDefaultHeatmapSerie(this, "serie1"); + + visualMap.enable = true; + visualMap.max = 10; + visualMap.range[0] = 0f; + visualMap.range[1] = 10f; + visualMap.orient = Orient.Vertical; + visualMap.calculable = true; + visualMap.location.align = Location.Align.BottomLeft; + visualMap.location.bottom = 100; + visualMap.location.left = 30; var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf", "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"}; - m_VisualMap.inRange.Clear(); + visualMap.inRange.Clear(); foreach (var str in colors) { - m_VisualMap.inRange.Add(ThemeInfo.GetColor(str)); + visualMap.inRange.Add(ChartTheme.GetColor(str)); } for (int i = 0; i < xSplitNumber; i++) { - m_XAxises[0].data.Add((i + 1).ToString()); + m_XAxes[0].data.Add((i + 1).ToString()); } for (int i = 0; i < ySplitNumber; i++) { - m_YAxises[0].data.Add((i + 1).ToString()); + m_YAxes[0].data.Add((i + 1).ToString()); } for (int i = 0; i < xSplitNumber; i++) { @@ -87,15 +81,15 @@ namespace XCharts protected override void UpdateTooltip() { - var xData = m_Tooltip.runtimeXValues[0]; - var yData = m_Tooltip.runtimeYValues[0]; + var xData = tooltip.runtimeXValues[0]; + var yData = tooltip.runtimeYValues[0]; if (IsCategory() && (xData < 0 || yData < 0)) return; sb.Length = 0; for (int i = 0; i < m_Series.Count; i++) { var serie = m_Series.GetSerie(i); - var xAxis = m_XAxises[serie.axisIndex]; - var yAxis = m_YAxises[serie.axisIndex]; + var xAxis = m_XAxes[serie.xAxisIndex]; + var yAxis = m_YAxes[serie.yAxisIndex]; var xCount = xAxis.data.Count; var yCount = yAxis.data.Count; if (serie.show && serie.type == SerieType.Heatmap) @@ -105,8 +99,8 @@ namespace XCharts string key = serie.name; var serieData = serie.data[(int)xData * yCount + (int)yData]; var value = serieData.data[2]; - var color = m_VisualMap.enable ? m_VisualMap.GetColor(value) : - m_ThemeInfo.GetColor(serie.index); + var color = visualMap.enable ? visualMap.GetColor(value) : + m_Theme.GetColor(serie.index); sb.Append("\n") .Append(key).Append(!string.IsNullOrEmpty(key) ? "\n" : "") .Append("<color=#").Append(ChartCached.ColorToStr(color)).Append(">● </color>") @@ -116,15 +110,15 @@ namespace XCharts } } TooltipHelper.SetContentAndPosition(tooltip, sb.ToString().Trim(), chartRect); - m_Tooltip.SetActive(true); + tooltip.SetActive(true); - for (int i = 0; i < m_XAxises.Count; i++) + for (int i = 0; i < m_XAxes.Count; i++) { - UpdateAxisTooltipLabel(i, m_XAxises[i]); + UpdateAxisTooltipLabel(i, m_XAxes[i]); } - for (int i = 0; i < m_YAxises.Count; i++) + for (int i = 0; i < m_YAxes.Count; i++) { - UpdateAxisTooltipLabel(i, m_YAxises[i]); + UpdateAxisTooltipLabel(i, m_YAxes[i]); } } } diff --git a/Runtime/Helper/CheckHelper.cs b/Runtime/Helper/CheckHelper.cs index fa23cf19..d579f67f 100644 --- a/Runtime/Helper/CheckHelper.cs +++ b/Runtime/Helper/CheckHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Text; using UnityEngine; @@ -56,33 +56,41 @@ namespace XCharts private static void CheckTheme(BaseChart chart, StringBuilder sb) { - var themeInfo = chart.themeInfo; - themeInfo.CheckWarning(sb); + var theme = chart.theme; + theme.CheckWarning(sb); } private static void CheckTitle(BaseChart chart, StringBuilder sb) { - var title = chart.title; - if (!title.show) return; - if (string.IsNullOrEmpty(title.text)) sb.Append("warning:title->text is null\n"); - if (IsColorAlphaZero(title.textStyle.color)) - sb.Append("warning:title->textStyle->color alpha is 0\n"); - if (IsColorAlphaZero(title.subTextStyle.color)) - sb.Append("warning:title->subTextStyle->color alpha is 0\n"); + foreach (var title in chart.titles) + { + if (!title.show) return; + if (string.IsNullOrEmpty(title.text)) sb.AppendFormat("warning:title{0}->text is null\n", title.index); + if (IsColorAlphaZero(title.textStyle.color)) + sb.AppendFormat("warning:title{0}->textStyle->color alpha is 0\n", title.index); + if (IsColorAlphaZero(title.subTextStyle.color)) + sb.AppendFormat("warning:title{0}->subTextStyle->color alpha is 0\n", title.index); + } } private static void CheckLegend(BaseChart chart, StringBuilder sb) { - var legend = chart.legend; - if (!legend.show) return; - if (IsColorAlphaZero(legend.textStyle.color)) - sb.Append("warning:legend->textStyle->color alpha is 0\n"); - var serieNameList = SeriesHelper.GetLegalSerieNameList(chart.series); - if (serieNameList.Count == 0) sb.Append("warning:legend need serie.name or serieData.name not empty\n"); - foreach (var category in legend.data) + foreach (var legend in chart.legends) { - if (!serieNameList.Contains(category)) - sb.AppendFormat("warning:legend [{0}] is invalid, must be one of serie.name or serieData.name\n", category); + if (!legend.show) return; + if (IsColorAlphaZero(legend.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) + sb.AppendFormat("warning:legend{0} need serie.name or serieData.name not empty\n", legend.index); + foreach (var category in legend.data) + { + if (!serieNameList.Contains(category)) + { + sb.AppendFormat("warning:legend{0} [{1}] is invalid, must be one of serie.name or serieData.name\n", + legend.index, category); + } + } } } @@ -90,19 +98,21 @@ namespace XCharts { if (chart is CoordinateChart) { - var grid = (chart as CoordinateChart).grid; - if (grid.left >= chart.chartWidth) - sb.Append("warning:grid->left > chartWidth\n"); - if (grid.right >= chart.chartWidth) - sb.Append("warning:grid->right > chartWidth\n"); - if (grid.top >= chart.chartHeight) - sb.Append("warning:grid->top > chartHeight\n"); - if (grid.bottom >= chart.chartHeight) - sb.Append("warning:grid->bottom > chartHeight\n"); - if (grid.left + grid.right >= chart.chartWidth) - sb.Append("warning:grid.left + grid.right > chartWidth\n"); - if (grid.top + grid.bottom >= chart.chartHeight) - sb.Append("warning:grid.top + grid.bottom > chartHeight\n"); + foreach (var grid in (chart as CoordinateChart).grids) + { + if (grid.left >= chart.chartWidth) + sb.Append("warning:grid->left > chartWidth\n"); + if (grid.right >= chart.chartWidth) + sb.Append("warning:grid->right > chartWidth\n"); + if (grid.top >= chart.chartHeight) + sb.Append("warning:grid->top > chartHeight\n"); + if (grid.bottom >= chart.chartHeight) + sb.Append("warning:grid->bottom > chartHeight\n"); + if (grid.left + grid.right >= chart.chartWidth) + sb.Append("warning:grid.left + grid.right > chartWidth\n"); + if (grid.top + grid.bottom >= chart.chartHeight) + sb.Append("warning:grid.top + grid.bottom > chartHeight\n"); + } } } @@ -148,8 +158,6 @@ namespace XCharts switch (serie.type) { case SerieType.Line: - if (serie.lineStyle.width == 0) - sb.AppendFormat("warning:serie {0} lineStyle->width is 0\n", serie.index); if (serie.lineStyle.opacity == 0) sb.AppendFormat("warning:serie {0} lineStyle->opacity is 0\n", serie.index); if (IsColorAlphaZero(serie.lineStyle.color)) diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index aef41c84..d3fef71b 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Text; using System.Text.RegularExpressions; @@ -34,12 +34,12 @@ namespace XCharts /// <param name="numericFormatter">默认的数字格式化</param> /// <param name="serie">选中的serie</param> /// <param name="series">所有serie</param> - /// <param name="themeInfo">用来获取指定index的颜色</param> + /// <param name="theme">用来获取指定index的颜色</param> /// <param name="category">选中的类目,一般用在折线图和柱状图</param> /// <param name="dataZoom">dataZoom</param> /// <returns></returns> public static bool ReplaceContent(ref string content, int dataIndex, string numericFormatter, Serie serie, Series series, - ThemeInfo themeInfo, string category = null, DataZoom dataZoom = null) + ChartTheme theme, string category = null, DataZoom dataZoom = null) { var foundDot = false; var mc = s_Regex.Matches(content); @@ -74,7 +74,7 @@ namespace XCharts var args1Str = args[1].ToString(); if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str); } - content = content.Replace(old, ChartCached.ColorToDotStr(themeInfo.GetColor(bIndex))); + content = content.Replace(old, ChartCached.ColorToDotStr(theme.GetColor(bIndex))); foundDot = true; } else if (p == 'a' || p == 'A') diff --git a/Runtime/Helper/LayoutHelper.cs b/Runtime/Helper/LayoutHelper.cs index 583f927a..f7c3ee72 100644 --- a/Runtime/Helper/LayoutHelper.cs +++ b/Runtime/Helper/LayoutHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -21,8 +21,8 @@ namespace XCharts private static Vector2 s_Vector1And0Dot5 = new Vector2(1f, 0.5f); private static Vector2 s_Vector1And0 = new Vector2(1f, 0); - internal static Vector2 ResetChartPositionAndPivot(Vector2 minAnchor, Vector2 maxAnchor, float width, float height, ref float chartX, - ref float chartY) + internal static Vector2 ResetChartPositionAndPivot(Vector2 minAnchor, Vector2 maxAnchor, float width, + float height, ref float chartX, ref float chartY) { if (IsLeftTop(minAnchor, maxAnchor)) { diff --git a/Runtime/Helper/SerieHelper.cs b/Runtime/Helper/SerieHelper.cs index 0b97c5ea..77a5b036 100644 --- a/Runtime/Helper/SerieHelper.cs +++ b/Runtime/Helper/SerieHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Text; using UnityEngine; @@ -21,7 +21,8 @@ namespace XCharts /// <param name="min">最小值</param> /// <param name="max">最大值</param> /// <param name="dataZoom">缩放组件,默认null</param> - public static void GetMinMaxData(Serie serie, int dimension, out float min, out float max, DataZoom dataZoom = null) + public static void GetMinMaxData(Serie serie, int dimension, out float min, out float max, + DataZoom dataZoom = null) { max = float.MinValue; min = float.MaxValue; @@ -56,7 +57,9 @@ namespace XCharts var serieData = dataList[i]; if (serieData.show) { - var count = serie.showDataDimension > serieData.data.Count ? serieData.data.Count : serie.showDataDimension; + var count = serie.showDataDimension > serieData.data.Count + ? serieData.data.Count + : serie.showDataDimension; for (int j = 0; j < count; j++) { var value = serieData.data[j]; diff --git a/Runtime/Internal/APIException.cs b/Runtime/Internal/APIException.cs deleted file mode 100644 index 30ccb415..00000000 --- a/Runtime/Internal/APIException.cs +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - - -namespace XCharts -{ - public class APIException : System.Exception - { - public APIException() { } - public APIException(string message) : base(message) { } - public APIException(string message, System.Exception inner) : base(message, inner) { } - protected APIException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } -} \ No newline at end of file diff --git a/Runtime/Internal/APIException.cs.meta b/Runtime/Internal/APIException.cs.meta deleted file mode 100644 index da90be97..00000000 --- a/Runtime/Internal/APIException.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 62abeafe2ed4141d69bdb9ad76c02e41 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 45aa5f31..5b6f0c53 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Linq; using UnityEngine; @@ -11,6 +11,7 @@ using UnityEngine.UI; using System.Collections.Generic; using System; using UnityEngine.EventSystems; +using XUGL; namespace XCharts { @@ -32,7 +33,6 @@ namespace XCharts public partial class BaseChart : BaseGraph { - protected static readonly string s_BackgroundObjectName = "background"; protected static readonly string s_TitleObjectName = "title"; protected static readonly string s_SubTitleObjectName = "title_sub"; protected static readonly string s_LegendObjectName = "legend"; @@ -40,14 +40,24 @@ namespace XCharts protected static readonly string s_SerieTitleObjectName = "serie"; [SerializeField] protected string m_ChartName; + [SerializeField] protected ChartTheme m_Theme; + [SerializeField] protected Settings m_Settings; + [SerializeField] protected List<Title> m_Titles = new List<Title>() { Title.defaultTitle }; + [SerializeField] protected List<Legend> m_Legends = new List<Legend>() { Legend.defaultLegend }; + [SerializeField] protected List<Tooltip> m_Tooltips = new List<Tooltip>() { Tooltip.defaultTooltip }; + + [SerializeField] protected List<Grid> m_Grids = new List<Grid>(); + [SerializeField] protected List<XAxis> m_XAxes = new List<XAxis>(); + [SerializeField] protected List<YAxis> m_YAxes = new List<YAxis>(); + [SerializeField] protected List<DataZoom> m_DataZooms = new List<DataZoom>(); + [SerializeField] protected List<VisualMap> m_VisualMaps = new List<VisualMap>(); + [SerializeField] protected List<Vessel> m_Vessels = new List<Vessel>(); + [SerializeField] protected List<Polar> m_Polars = new List<Polar>(); + [SerializeField] protected List<RadiusAxis> m_RadiusAxes = new List<RadiusAxis>(); + [SerializeField] protected List<AngleAxis> m_AngleAxes = new List<AngleAxis>(); + [SerializeField] protected List<Radar> m_Radars = new List<Radar>(); - [SerializeField] protected ThemeInfo m_ThemeInfo; - [SerializeField] protected Title m_Title = Title.defaultTitle; - [SerializeField] protected Background m_Background = Background.defaultBackground; - [SerializeField] protected Legend m_Legend = Legend.defaultLegend; - [SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip; [SerializeField] protected Series m_Series = Series.defaultSeries; - [SerializeField] protected Settings m_Settings = new Settings(); protected float m_ChartWidth; protected float m_ChartHeight; @@ -60,50 +70,82 @@ namespace XCharts protected Vector2 m_ChartSizeDelta; protected Rect m_ChartRect = new Rect(0, 0, 0, 0); protected Action<VertexHelper> m_OnCustomDrawCallback; + protected Action<PointerEventData, int, int> m_OnPointerClickPie; - protected bool m_RefreshLabel = false; - protected bool m_ReinitLabel = false; - protected bool m_ReinitTitle = false; - protected bool m_CheckAnimation = false; - protected bool m_IsPlayingAnimation = false; - protected List<string> m_LegendRealShowName = new List<string>(); + internal bool m_RefreshLabel = false; + internal bool m_ReinitLabel = false; + internal bool m_ReinitTitle = false; + internal bool m_CheckAnimation = false; + internal bool m_IsPlayingAnimation = false; + internal protected List<string> m_LegendRealShowName = new List<string>(); + protected List<Painter> m_PainterList = new List<Painter>(); + protected Painter m_PainterTop; protected GameObject m_SerieLabelRoot; - protected GameObject m_BackgroundRoot; - private Theme m_CheckTheme = 0; + private List<IDrawSerie> m_DrawSeries = new List<IDrawSerie>(); + protected override void InitComponent() { base.InitComponent(); - InitBackground(); - InitTitle(); - InitLegend(); + InitTitles(); + InitLegends(); InitSerieLabel(); InitSerieTitle(); InitTooltip(); + m_DrawSeries.Clear(); + m_DrawSeries.Add(new DrawSeriePie(this)); + m_DrawSeries.Add(new DrawSerieRing(this)); + m_DrawSeries.Add(new DrawSerieGauge(this)); + m_DrawSeries.Add(new DrawSerieLiquid(this)); + m_DrawSeries.Add(new DrawSerieRadar(this)); + foreach (var drawSerie in m_DrawSeries) drawSerie.InitComponent(); } protected override void Awake() { - if (m_ThemeInfo == null) + if (m_Theme == null) { - m_ThemeInfo = ThemeInfo.Default; + m_Theme = ChartTheme.Default; } - if (transform.parent != null) + else { - m_IsControlledByLayout = transform.parent.GetComponent<LayoutGroup>() != null; + if (m_Theme.font == null) + { + m_Theme.font = XChartsSettings.font; + } } - raycastTarget = false; - m_CheckTheme = m_ThemeInfo.theme; - m_LastLocalPosition = transform.localPosition; - CheckIsInScrollRect(); - UpdateSize(); - InitComponent(); + base.Awake(); m_Series.AnimationReset(); m_Series.AnimationFadeIn(); XChartsMgr.Instance.AddChart(this); } +#if UNITY_EDITOR + protected override void Reset() + { + base.Reset(); + m_Theme = ChartTheme.Default; + m_Settings = Settings.DefaultSettings; + m_Titles = new List<Title>() { Title.defaultTitle }; + m_Legends = new List<Legend>() { Legend.defaultLegend }; + m_Tooltips = new List<Tooltip>() { Tooltip.defaultTooltip }; + + var sizeDelta = rectTransform.sizeDelta; + if (sizeDelta.x < 580 && sizeDelta.y < 300) + { + rectTransform.sizeDelta = new Vector2(580, 300); + } + ChartHelper.HideAllObject(transform); + m_Theme = ChartTheme.Default; + m_Titles = new List<Title>() { Title.defaultTitle }; + m_Legends = new List<Legend>() { Legend.defaultLegend }; + m_Tooltips = new List<Tooltip>() { Tooltip.defaultTooltip }; + m_Series = Series.defaultSeries; + Awake(); + } +#endif + protected override void Start() { RefreshChart(); @@ -111,18 +153,72 @@ namespace XCharts protected override void Update() { + CheckTheme(); base.Update(); + CheckPainter(); CheckTooltip(); CheckRefreshChart(); CheckRefreshLabel(); CheckAnimation(); + foreach (var draw in m_DrawSeries) draw.Update(); } + internal Painter GetPainter(int index) + { + if (index >= 0 && index < m_PainterList.Count) + { + return m_PainterList[index]; + } + return null; + } + + internal void RefreshBasePainter() + { + m_Painter.Refresh(); + } + + internal void RefreshPainter(int index) + { + var painter = GetPainter(index); + RefreshPainter(painter); + } + + internal void RefreshPainter(Serie serie) + { + RefreshPainter(GetPainterIndexBySerie(serie)); + } + + internal override void RefreshPainter(Painter painter) + { + base.RefreshPainter(painter); + if (painter != null && painter.type == Painter.Type.Serie) + { + m_PainterTop.Refresh(); + } + } + + internal void SetPainterActive(int index, bool flag) + { + var painter = GetPainter(index); + if (painter == null) return; + painter.SetActive(flag, m_DebugMode); + } + + protected virtual void CheckTheme() + { + if (m_Theme != null && m_CheckTheme != m_Theme.theme) + { + m_CheckTheme = m_Theme.theme; + m_Theme.CopyTheme(m_CheckTheme); + SetAllComponentDirty(); + OnThemeChanged(); + } + } protected override void CheckComponent() { + base.CheckComponent(); if (m_Series.anyDirty) { - if (m_Series.vertsDirty) RefreshChart(); if (SeriesHelper.IsLabelDirty(m_Series)) m_ReinitLabel = true; if (SeriesHelper.IsNeedLabelUpdate(m_Series) && !m_RefreshChart) m_RefreshLabel = true; foreach (var serie in m_Series.list) @@ -130,59 +226,40 @@ namespace XCharts if (serie.titleStyle.componentDirty) m_ReinitTitle = true; if (serie.nameDirty) { - m_Legend.SetAllDirty(); + foreach (var legend in m_Legends) legend.SetAllDirty(); RefreshChart(); serie.ClearNameDirty(); } + if (serie.vertsDirty) + { + RefreshPainter(serie); + } } m_Series.ClearDirty(); } - if (m_ThemeInfo.anyDirty) + if (m_Theme.anyDirty) { - if (m_CheckTheme != m_ThemeInfo.theme) + if (m_Theme.componentDirty) { - m_CheckTheme = m_ThemeInfo.theme; - m_ThemeInfo.Copy(m_CheckTheme); - OnThemeChanged(); + foreach (var title in m_Titles) title.SetAllDirty(); + foreach (var legend in m_Legends) legend.SetAllDirty(); + tooltip.SetAllDirty(); } - if (m_ThemeInfo.componentDirty) - { - m_Title.SetAllDirty(); - m_Legend.SetAllDirty(); - m_Tooltip.SetAllDirty(); - } - if (m_ThemeInfo.vertsDirty) RefreshChart(); - m_ThemeInfo.ClearDirty(); - } - if (m_Background.anyDirty) - { - if (m_Background.componentDirty) InitBackground(); - if (m_Background.vertsDirty) RefreshChart(); - m_Background.ClearDirty(); - } - if (m_Title.anyDirty) - { - if (m_Title.componentDirty) InitTitle(); - if (m_Title.vertsDirty) RefreshChart(); - m_Title.ClearDirty(); - } - if (m_Legend.anyDirty) - { - if (m_Legend.componentDirty) InitLegend(); - if (m_Legend.vertsDirty) RefreshChart(); - m_Legend.ClearDirty(); - } - if (m_Tooltip.anyDirty) - { - if (m_Tooltip.componentDirty) InitTooltip(); - if (m_Tooltip.vertsDirty) RefreshChart(); - m_Tooltip.ClearDirty(); - } - if (m_Settings.vertsDirty) - { - RefreshChart(); - m_Settings.ClearDirty(); + if (m_Theme.vertsDirty) RefreshChart(); + m_Theme.ClearDirty(); } + CheckComponentDirty(tooltip); + foreach (var title in m_Titles) CheckComponentDirty(title); + foreach (var legend in m_Legends) CheckComponentDirty(legend); + foreach (var dataZoom in m_DataZooms) CheckComponentDirty(dataZoom); + foreach (var visualMap in m_VisualMaps) CheckComponentDirty(visualMap); + foreach (var grid in m_Grids) CheckComponentDirty(grid); + foreach (var axis in m_XAxes) CheckComponentDirty(axis); + foreach (var axis in m_YAxes) CheckComponentDirty(axis); + foreach (var polar in m_Polars) CheckComponentDirty(polar); + foreach (var axis in m_AngleAxes) CheckComponentDirty(axis); + foreach (var axis in m_RadiusAxes) CheckComponentDirty(axis); + foreach (var drawSerie in m_DrawSeries) drawSerie.CheckComponent(); } protected override void OnEnable() @@ -197,34 +274,16 @@ namespace XCharts ChartHelper.ActiveAllObject(transform, false); } -#if UNITY_EDITOR - protected override void Reset() + protected override void SetAllComponentDirty() { - var sizeDelta = rectTransform.sizeDelta; - if (sizeDelta.x < 580 && sizeDelta.y < 300) - { - rectTransform.sizeDelta = new Vector2(580, 300); - } - ChartHelper.HideAllObject(transform); - m_ThemeInfo = ThemeInfo.Default; - m_Title = Title.defaultTitle; - m_Legend = Legend.defaultLegend; - m_Tooltip = Tooltip.defaultTooltip; - m_Series = Series.defaultSeries; - Awake(); - } - - protected override void OnValidate() - { - m_ThemeInfo.SetAllDirty(); - m_Background.SetAllDirty(); - m_Title.SetAllDirty(); - m_Legend.SetAllDirty(); - m_Tooltip.SetAllDirty(); + base.SetAllComponentDirty(); + m_Theme.SetAllDirty(); + foreach (var title in m_Titles) title.SetAllDirty(); + foreach (var legend in m_Legends) legend.SetAllDirty(); + tooltip.SetAllDirty(); m_ReinitLabel = true; m_ReinitTitle = true; } -#endif protected override void OnDestroy() { @@ -234,195 +293,210 @@ namespace XCharts } } - private void InitBackground() + protected virtual void CheckPainter() { - if (!transform.parent) return; - int childCount = transform.parent.childCount; - if (childCount > 2) m_Background.runtimeActive = false; - else if (childCount == 1) m_Background.runtimeActive = true; - else + for (int i = 0; i < m_Series.Count; i++) { - m_Background.runtimeActive = false; - for (int i = 0; i < childCount; i++) - { - if (transform.parent.GetChild(i).name.StartsWith(s_BackgroundObjectName)) - { - m_Background.runtimeActive = true; - break; - } - } - } - if (!m_Background.runtimeActive || m_IsControlledByLayout) - { - //find old gameobject and delete - var objName = s_BackgroundObjectName + GetInstanceID(); - ChartHelper.DestoryGameObject(transform.parent, objName); - ChartHelper.DestoryGameObject(m_BackgroundRoot); - return; - } - if (!m_Background.show) - { - ChartHelper.DestoryGameObject(m_BackgroundRoot); - return; - } - var backgroundName = s_BackgroundObjectName; - m_BackgroundRoot = ChartHelper.AddObject(backgroundName, transform.parent, m_ChartMinAnchor, - m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta); - m_BackgroundRoot.hideFlags = chartHideFlags; - var backgroundImage = ChartHelper.GetOrAddComponent<Image>(m_BackgroundRoot); - var backgroundRect = m_BackgroundRoot.GetComponent<RectTransform>(); - backgroundRect.position = rectTransform.position; - backgroundImage.sprite = m_Background.image; - backgroundImage.type = m_Background.imageType; - backgroundImage.color = m_Background.imageColor; - m_BackgroundRoot.SetActive(m_Background.show); - var siblindIndex = rectTransform.GetSiblingIndex(); - if (siblindIndex == 0) - { - backgroundRect.SetSiblingIndex(0); - } - else - { - backgroundRect.SetSiblingIndex(rectTransform.GetSiblingIndex() - 1); + var serie = m_Series.GetSerie(i); + serie.index = i; + SetPainterActive(i, true); } } - private void InitTitle() + protected override void InitPainter() { - m_Title.OnChanged(); - TextAnchor anchor = m_Title.location.runtimeTextAnchor; - Vector2 anchorMin = m_Title.location.runtimeAnchorMin; - Vector2 anchorMax = m_Title.location.runtimeAnchorMax; - Vector2 pivot = m_Title.location.runtimePivot; - Vector3 titlePosition = GetTitlePosition(); - Vector3 subTitlePosition = -new Vector3(0, m_Title.textStyle.fontSize + m_Title.itemGap, 0); - float titleWid = chartWidth; - - var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax, - pivot, new Vector2(chartWidth, chartHeight)); - titleObject.transform.localPosition = titlePosition; - titleObject.hideFlags = chartHideFlags; - ChartHelper.HideAllObject(titleObject); - - var textFont = TitleHelper.GetTextFont(title, themeInfo); - var textColor = TitleHelper.GetTextColor(title, themeInfo); - Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, - textFont, textColor, anchor, anchorMin, anchorMax, pivot, - new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize, - m_Title.textStyle.rotate, m_Title.textStyle.fontStyle, m_Title.textStyle.lineSpacing); - - titleText.alignment = anchor; - titleText.gameObject.SetActive(m_Title.show); - titleText.transform.localPosition = Vector3.zero + m_Title.textStyle.offsetv3; - titleText.text = m_Title.text.Replace("\\n", "\n"); - - var subTextFont = TitleHelper.GetSubTextFont(title, themeInfo); - var subTextColor = TitleHelper.GetSubTextColor(title, themeInfo); - Text subText = ChartHelper.AddTextObject(s_SubTitleObjectName, titleObject.transform, - subTextFont, subTextColor, anchor, anchorMin, anchorMax, pivot, - new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize, - m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle, m_Title.subTextStyle.lineSpacing); - - subText.alignment = anchor; - subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText)); - subText.transform.localPosition = subTitlePosition + m_Title.subTextStyle.offsetv3; - subText.text = m_Title.subText.Replace("\\n", "\n"); + base.InitPainter(); + m_PainterList.Clear(); + if (settings == null) return; + for (int i = 0; i < settings.maxPainter; i++) + { + var painterObj = ChartHelper.AddObject("painter_" + i, transform, m_GraphMinAnchor, m_GraphMaxAnchor, + m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight)); + painterObj.hideFlags = chartHideFlags; + painterObj.transform.SetSiblingIndex(2 + i); + var painter = ChartHelper.GetOrAddComponent<Painter>(painterObj); + painter.index = m_PainterList.Count; + painter.type = Painter.Type.Serie; + painter.onPopulateMesh = OnDrawPainterSerie; + painter.SetActive(false, m_DebugMode); + m_PainterList.Add(painter); + } + var painterTopObj = ChartHelper.AddObject("painter_t", transform, m_GraphMinAnchor, m_GraphMaxAnchor, + m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight)); + painterTopObj.hideFlags = chartHideFlags; + painterTopObj.transform.SetSiblingIndex(2 + settings.maxPainter); + m_PainterTop = ChartHelper.GetOrAddComponent<Painter>(painterTopObj); + m_PainterTop.type = Painter.Type.Top; + m_PainterTop.onPopulateMesh = OnDrawPainterTop; + m_PainterTop.SetActive(true, m_DebugMode); } - private void InitLegend() + private void InitTitles() { - m_Legend.OnChanged(); - var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, m_ChartMinAnchor, - m_ChartMaxAnchor, m_ChartPivot, new Vector2(chartWidth, chartHeight)); - legendObject.hideFlags = chartHideFlags; - SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName); - List<string> datas; - if (m_Legend.show && m_Legend.data.Count > 0) + for (int i = 0; i < m_Titles.Count; i++) { - datas = new List<string>(); - for (int i = 0; i < m_LegendRealShowName.Count; i++) + var title = m_Titles[i]; + title.index = i; + InitTitle(title); + } + } + private void InitTitle(Title title) + { + title.OnChanged(); + var anchorMin = title.location.runtimeAnchorMin; + var anchorMax = title.location.runtimeAnchorMax; + var pivot = title.location.runtimePivot; + var titleObject = ChartHelper.AddObject(s_TitleObjectName + title.index, transform, anchorMin, anchorMax, + pivot, m_ChartSizeDelta); + title.gameObject = titleObject; + title.painter = null; + title.refreshComponent = delegate () + { + if (titleObject == null) return; + title.OnChanged(); + 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(theme.title); + ChartHelper.UpdateRectTransform(titleObject, anchorMin, anchorMax, pivot, new Vector2(chartWidth, chartHeight)); + var titlePosition = GetTitlePosition(title); + var subTitlePosition = -new Vector3(0, fontSize + title.itemGap, 0); + var titleWid = chartWidth; + + titleObject.transform.localPosition = titlePosition; + titleObject.hideFlags = chartHideFlags; + ChartHelper.HideAllObject(titleObject); + + var titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, anchorMin, anchorMax, + pivot, new Vector2(titleWid, fontSize), title.textStyle, theme.title); + titleText.SetActive(title.show); + titleText.SetLocalPosition(Vector3.zero + title.textStyle.offsetv3); + titleText.SetText(title.text); + + var subText = ChartHelper.AddTextObject(s_SubTitleObjectName, titleObject.transform, anchorMin, anchorMax, + pivot, new Vector2(titleWid, title.subTextStyle.GetFontSize(theme.subTitle)), title.subTextStyle, + theme.subTitle); + subText.SetActive(title.show && !string.IsNullOrEmpty(title.subText)); + subText.SetLocalPosition(subTitlePosition + title.subTextStyle.offsetv3); + subText.SetText(title.subText); + }; + title.refreshComponent(); + } + + private void InitLegends() + { + for (int i = 0; i < m_Legends.Count; i++) + { + var legend = m_Legends[i]; + legend.index = i; + InitLegend(legend); + } + } + + private void InitLegend(Legend legend) + { + legend.OnChanged(); + var legendObject = ChartHelper.AddObject(s_LegendObjectName + legend.index, transform, m_ChartMinAnchor, + m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta); + legend.gameObject = legendObject; + legend.painter = null; // legend component does not need to paint + legend.refreshComponent = delegate () + { + if (legendObject == null) return; + legend.OnChanged(); + legendObject.hideFlags = chartHideFlags; + SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName); + List<string> datas; + if (legend.show && legend.data.Count > 0) { - if (m_Legend.data.Contains(m_LegendRealShowName[i])) datas.Add(m_LegendRealShowName[i]); - } - } - else - { - datas = m_LegendRealShowName; - } - int totalLegend = 0; - for (int i = 0; i < datas.Count; i++) - { - if (!SeriesHelper.IsLegalLegendName(datas[i])) continue; - totalLegend++; - } - m_Legend.RemoveButton(); - ChartHelper.HideAllObject(legendObject); - if (!m_Legend.show) return; - for (int i = 0; i < datas.Count; i++) - { - if (!SeriesHelper.IsLegalLegendName(datas[i])) continue; - string legendName = m_Legend.GetFormatterContent(datas[i]); - var readIndex = m_LegendRealShowName.IndexOf(datas[i]); - var active = IsActiveByLegend(datas[i]); - var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, m_Series, datas[i], active); - var item = LegendHelper.AddLegendItem(m_Legend, i, datas[i], legendObject.transform, m_ThemeInfo, - legendName, bgColor, active); - m_Legend.SetButton(legendName, item, totalLegend); - ChartHelper.ClearEventListener(item.button.gameObject); - ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) => - { - if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) return; - var temp = data.selectedObject.name.Split('_'); - string selectedName = temp[1]; - int clickedIndex = int.Parse(temp[0]); - if (m_Legend.selectedMode == Legend.SelectedMode.Multiple) + datas = new List<string>(); + for (int i = 0; i < m_LegendRealShowName.Count; i++) { - OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName)); + if (legend.data.Contains(m_LegendRealShowName[i])) datas.Add(m_LegendRealShowName[i]); } - else + } + else + { + datas = m_LegendRealShowName; + } + int totalLegend = 0; + for (int i = 0; i < datas.Count; i++) + { + if (!SeriesHelper.IsLegalLegendName(datas[i])) continue; + totalLegend++; + } + legend.RemoveButton(); + ChartHelper.HideAllObject(legendObject); + if (!legend.show) return; + for (int i = 0; i < datas.Count; i++) + { + if (!SeriesHelper.IsLegalLegendName(datas[i])) continue; + string legendName = legend.GetFormatterContent(datas[i]); + var readIndex = m_LegendRealShowName.IndexOf(datas[i]); + var active = IsActiveByLegend(datas[i]); + var bgColor = LegendHelper.GetIconColor(legend, readIndex, theme, m_Series, datas[i], active); + var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, m_Theme, + legendName, bgColor, active); + legend.SetButton(legendName, item, totalLegend); + ChartHelper.ClearEventListener(item.button.gameObject); + ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) => { - var btnList = m_Legend.buttonList.Values.ToArray(); - if (btnList.Length == 1) + if (data.selectedObject == null || legend.selectedMode == Legend.SelectedMode.None) return; + var temp = data.selectedObject.name.Split('_'); + string selectedName = temp[1]; + int clickedIndex = int.Parse(temp[0]); + if (legend.selectedMode == Legend.SelectedMode.Multiple) { - OnLegendButtonClick(0, selectedName, !IsActiveByLegend(selectedName)); + OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName)); } else { - for (int n = 0; n < btnList.Length; n++) + var btnList = legend.buttonList.Values.ToArray(); + if (btnList.Length == 1) { - temp = btnList[n].name.Split('_'); - selectedName = btnList[n].legendName; - var index = btnList[n].index; - OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); + OnLegendButtonClick(0, selectedName, !IsActiveByLegend(selectedName)); + } + else + { + for (int n = 0; n < btnList.Length; n++) + { + temp = btnList[n].name.Split('_'); + selectedName = btnList[n].legendName; + var index = btnList[n].index; + OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); + } } } - } - }); - ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) => - { - if (item.button == null) return; - var temp = item.button.name.Split('_'); - string selectedName = temp[1]; - int index = int.Parse(temp[0]); - OnLegendButtonEnter(index, selectedName); - }); - ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) => - { - if (item.button == null) return; - var temp = item.button.name.Split('_'); - string selectedName = temp[1]; - int index = int.Parse(temp[0]); - OnLegendButtonExit(index, selectedName); - }); - } - if (m_Legend.selectedMode == Legend.SelectedMode.Single) - { - for (int n = 0; n < m_LegendRealShowName.Count; n++) - { - OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false); + }); + ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) => + { + if (item.button == null) return; + var temp = item.button.name.Split('_'); + string selectedName = temp[1]; + int index = int.Parse(temp[0]); + OnLegendButtonEnter(index, selectedName); + }); + ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) => + { + if (item.button == null) return; + var temp = item.button.name.Split('_'); + string selectedName = temp[1]; + int index = int.Parse(temp[0]); + OnLegendButtonExit(index, selectedName); + }); } - } - LegendHelper.ResetItemPosition(m_Legend, m_ChartPosition, m_ChartWidth, m_ChartHeight); + if (legend.selectedMode == Legend.SelectedMode.Single) + { + for (int n = 0; n < m_LegendRealShowName.Count; n++) + { + OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false); + } + } + LegendHelper.ResetItemPosition(legend, m_ChartPosition, m_ChartWidth, m_ChartHeight); + }; + legend.refreshComponent(); } private void InitSerieLabel() @@ -446,7 +520,7 @@ namespace XCharts count++; } } - SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName); + SerieLabelHelper.UpdateLabelText(m_Series, m_Theme, m_LegendRealShowName); } protected void AddSerieLabel(Serie serie, SerieData serieData, int count = -1) @@ -461,18 +535,18 @@ namespace XCharts if (serie.type == SerieType.Pie) { color = (serieLabel.position == SerieLabel.Position.Inside) ? Color.white : - (Color)m_ThemeInfo.GetColor(count); + (Color)m_Theme.GetColor(count); } else { - color = !ChartHelper.IsClearColor(serieLabel.color) ? serieLabel.color : - (Color)m_ThemeInfo.GetColor(serie.index); + color = !ChartHelper.IsClearColor(serieLabel.textStyle.color) ? serieLabel.textStyle.color : + (Color)m_Theme.GetColor(serie.index); } - var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, m_ThemeInfo.font, color, - serieData.iconStyle.width, serieData.iconStyle.height); + var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, color, + serieData.iconStyle.width, serieData.iconStyle.height, theme); var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>(); var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; - var item = new LabelObject(); + var item = new ChartLabel(); item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); item.SetIcon(iconImage); item.SetIconActive(false); @@ -489,115 +563,141 @@ namespace XCharts { var serie = m_Series.list[i]; var textStyle = serie.titleStyle.textStyle; - var color = ChartHelper.IsClearColor(textStyle.color) ? m_ThemeInfo.GetColor(i) : (Color32)textStyle.color; + var titleColor = ChartHelper.IsClearColor(textStyle.color) ? m_Theme.GetColor(i) : (Color32)textStyle.color; 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); - var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color, - TextAnchor.MiddleCenter, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate, - textStyle.fontStyle, textStyle.lineSpacing); - txt.text = ""; - txt.transform.localPosition = new Vector2(0, 0); - txt.transform.localEulerAngles = Vector2.zero; - ChartHelper.SetActive(txt, serie.titleStyle.show); + var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, anchorMin, anchorMax, + pivot, sizeDelta, textStyle, theme.common); + txt.SetText(""); + txt.SetColor(titleColor); + txt.SetLocalPosition(Vector2.zero); + txt.SetLocalEulerAngles(Vector2.zero); + txt.SetActive(serie.titleStyle.show); serie.titleStyle.runtimeText = txt; serie.titleStyle.UpdatePosition(serie.runtimeCenterPos); var serieData = serie.GetSerieData(0); if (serieData != null) { - txt.text = serieData.name; + txt.SetText(serieData.name); } } } private void InitTooltip() { - var tooltipObject = ChartHelper.AddObject("tooltip", transform, m_ChartMinAnchor, + tooltip.gameObject = ChartHelper.AddObject("tooltip", transform, m_ChartMinAnchor, m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta); - tooltipObject.transform.localPosition = Vector3.zero; - tooltipObject.hideFlags = chartHideFlags; - DestroyImmediate(tooltipObject.GetComponent<Image>()); - var parent = tooltipObject.transform; - var textStyle = m_Tooltip.textStyle; - ChartHelper.HideAllObject(tooltipObject.transform); - GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font, - textStyle.fontSize, textStyle.fontStyle, textStyle.lineSpacing); - m_Tooltip.SetObj(tooltipObject); - m_Tooltip.SetContentObj(content); - m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor); - m_Tooltip.SetContentTextColor(m_ThemeInfo.tooltipTextColor); - m_Tooltip.SetActive(false); + tooltip.painter = m_PainterTop; + tooltip.refreshComponent = delegate () + { + if (tooltip.gameObject == null) return; + var tooltipObject = tooltip.gameObject; + tooltipObject.transform.localPosition = Vector3.zero; + tooltipObject.hideFlags = chartHideFlags; + DestroyImmediate(tooltipObject.GetComponent<Image>()); + var parent = tooltipObject.transform; + var textStyle = tooltip.textStyle; + ChartHelper.HideAllObject(tooltipObject.transform); + GameObject content = ChartHelper.AddTooltipContent("content", parent, textStyle, m_Theme); + tooltip.SetObj(tooltipObject); + tooltip.SetContentObj(content); + tooltip.SetContentBackgroundColor(TooltipHelper.GetTexBackgroundColor(tooltip, m_Theme.tooltip)); + tooltip.SetContentTextColor(TooltipHelper.GetTexColor(tooltip, m_Theme.tooltip)); + tooltip.SetActive(false); + }; + tooltip.refreshComponent(); } - private Vector3 GetLegendPosition(int i) + private Vector3 GetLegendPosition(Legend legend, int i) { - return m_Legend.location.GetPosition(chartWidth, chartHeight); + return legend.location.GetPosition(chartWidth, chartHeight); } protected override bool IsNeedCheckPointerPos() { - return (m_Tooltip.show && m_Tooltip.runtimeInited) + return (tooltip.show && tooltip.runtimeInited) || raycastTarget; } private void CheckTooltip() { - if (!isPointerInChart || !m_Tooltip.show || !m_Tooltip.runtimeInited) + if (!isPointerInChart || !tooltip.show || !tooltip.runtimeInited) { - if (m_Tooltip.IsActive()) + if (tooltip.IsActive()) { - m_Tooltip.ClearValue(); - m_Tooltip.SetActive(false); - RefreshChart(); + tooltip.ClearValue(); + tooltip.SetActive(false); + m_PainterTop.Refresh(); } return; } - for (int i = 0; i < m_Tooltip.runtimeDataIndex.Count; i++) + for (int i = 0; i < tooltip.runtimeDataIndex.Count; i++) { - m_Tooltip.runtimeDataIndex[i] = -1; + tooltip.runtimeDataIndex[i] = -1; } Vector2 local = pointerPos; if (canvas == null) return; if (local == Vector2.zero) { - if (m_Tooltip.IsActive()) + if (tooltip.IsActive()) { - m_Tooltip.SetActive(false); - RefreshChart(); + tooltip.SetActive(false); + m_PainterTop.Refresh(); } return; } if (!IsInChart(local)) { - if (m_Tooltip.IsActive()) + if (tooltip.IsActive()) { - m_Tooltip.SetActive(false); - RefreshChart(); + tooltip.SetActive(false); + m_PainterTop.Refresh(); } return; } - m_Tooltip.runtimePointerPos = local; - CheckTootipArea(local); + tooltip.runtimePointerPos = local; + CheckAllTooptip(local); } - protected virtual void CheckTootipArea(Vector2 localPostion) + private void CheckAllTooptip(Vector2 localPostion) + { + tooltip.runtimeGridIndex = -1; + var actived = false; + foreach (var draw in m_DrawSeries) + actived = actived || draw.CheckTootipArea(localPostion); + CheckTootipArea(localPostion, actived); + } + + protected virtual void CheckTootipArea(Vector2 localPostion, bool isActivedOther) { } protected override void CheckRefreshChart() { - if (m_RefreshChart || m_Series.vertsDirty) + if (m_Painter == null) return; + if (m_RefreshChart) { + m_Painter.Refresh(); + foreach (var painter in m_PainterList) painter.Refresh(); + m_PainterTop.Refresh(); //SetAllDirty(); - SetVerticesDirty(); + //SetVerticesDirty(); m_RefreshChart = false; - m_Series.ClearVerticesDirty(); } } + protected override void CheckRefreshPainter() + { + if (m_Painter == null) return; + m_Painter.CheckRefresh(); + foreach (var painter in m_PainterList) painter.CheckRefresh(); + m_PainterTop.CheckRefresh(); + } + protected void CheckRefreshLabel() { if (m_ReinitLabel) @@ -629,6 +729,7 @@ namespace XCharts protected virtual void OnRefreshLabel() { + foreach (var drawSerie in m_DrawSeries) drawSerie.RefreshLabel(); } protected override void OnSizeChanged() @@ -646,9 +747,9 @@ namespace XCharts m_ChartRect = m_GraphRect; m_Background.SetAllDirty(); - m_Title.SetAllDirty(); - m_Legend.SetAllDirty(); - m_Tooltip.SetAllDirty(); + foreach (var title in m_Titles) title.SetAllDirty(); + foreach (var legend in m_Legends) legend.SetAllDirty(); + tooltip.SetAllDirty(); m_Series.SetLabelDirty(); m_ReinitLabel = true; RefreshChart(); @@ -667,48 +768,106 @@ namespace XCharts { } + public override void OnPointerDown(PointerEventData eventData) + { + base.OnPointerDown(eventData); + foreach (var drawSerie in m_DrawSeries) drawSerie.OnPointerDown(eventData); + } + protected virtual void OnLegendButtonClick(int index, string legendName, bool show) { - foreach (var serie in m_Series.GetSeries(legendName)) + var clicked = false; + foreach (var drawSerie in m_DrawSeries) + clicked = clicked || drawSerie.OnLegendButtonClick(index, legendName, show); + if (!clicked) { - SetActive(serie.index, show); + foreach (var serie in m_Series.GetSeries(legendName)) + { + SetActive(serie.index, show); + RefreshPainter(serie); + } + OnYMaxValueChanged(); } - OnYMaxValueChanged(); - RefreshChart(); } protected virtual void OnLegendButtonEnter(int index, string legendName) { - var serie = m_Series.GetSerie(index); - serie.highlighted = true; - RefreshChart(); + var enter = false; + foreach (var drawSerie in m_DrawSeries) + enter = enter || drawSerie.OnLegendButtonEnter(index, legendName); + if (!enter) + { + foreach (var serie in m_Series.GetSeries(legendName)) + { + serie.highlighted = true; + RefreshPainter(serie); + } + } } protected virtual void OnLegendButtonExit(int index, string legendName) { - var serie = m_Series.GetSerie(index); - serie.highlighted = false; - RefreshChart(); + var exit = false; + foreach (var drawSerie in m_DrawSeries) + exit = exit || drawSerie.OnLegendButtonExit(index, legendName); + if (!exit) + { + foreach (var serie in m_Series.GetSeries(legendName)) + { + serie.highlighted = false; + RefreshPainter(serie); + } + } } protected virtual void UpdateTooltip() { } - protected override void OnPopulateMesh(VertexHelper vh) + protected override void OnDrawPainterBase(VertexHelper vh, Painter painter) { + //Debug.LogError("OnDrawPainterBase:" + Time.frameCount + "," + painter.name); vh.Clear(); DrawBackground(vh); - DrawChart(vh); + DrawPainterBase(vh); + foreach (var drawSerie in m_DrawSeries) drawSerie.DrawBase(vh); + } + + protected virtual void OnDrawPainterSerie(VertexHelper vh, Painter painter) + { + //Debug.LogError("OnDrawPainterSerie:" + Time.frameCount + "," + painter.name); + vh.Clear(); + var maxPainter = settings.maxPainter; + var maxSeries = m_Series.Count; + var rate = Mathf.CeilToInt(maxSeries * 1.0f / maxPainter); + m_PainterTop.Refresh(); + for (int i = painter.index * rate; i < (painter.index + 1) * rate && i < maxSeries; i++) + { + var serie = m_Series.GetSerie(i); + DrawPainterSerie(vh, serie); + } + m_RefreshLabel = true; + } + + protected virtual void OnDrawPainterTop(VertexHelper vh, Painter painter) + { + //Debug.LogError("OnDrawPainterTop:" + Time.frameCount + "," + painter.name); + vh.Clear(); if (m_OnCustomDrawCallback != null) { m_OnCustomDrawCallback(vh); } + DrawPainterTop(vh); DrawTooltip(vh); - m_RefreshLabel = true; } - protected virtual void DrawChart(VertexHelper vh) + protected virtual void DrawPainterSerie(VertexHelper vh, Serie serie) + { + foreach (var drawSerie in m_DrawSeries) + drawSerie.DrawSerie(vh, serie); + } + + protected virtual void DrawPainterTop(VertexHelper vh) { } @@ -722,20 +881,20 @@ namespace XCharts Vector3 p2 = new Vector3(chartX + chartWidth, chartY + chartHeight); Vector3 p3 = new Vector3(chartX + chartWidth, chartY); Vector3 p4 = new Vector3(chartX, chartY); - var backgroundColor = ThemeHelper.GetBackgroundColor(m_ThemeInfo, m_Background); - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, backgroundColor); + var backgroundColor = ThemeHelper.GetBackgroundColor(m_Theme, m_Background); + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, backgroundColor); } public void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius) { - var backgroundColor = ThemeHelper.GetBackgroundColor(m_ThemeInfo, m_Background); - var smoothness = m_Settings.cicleSmoothness; + var backgroundColor = ThemeHelper.GetBackgroundColor(m_Theme, m_Background); + var smoothness = settings.cicleSmoothness; ChartDrawer.DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap, cornerRadius, backgroundColor, smoothness); } - protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData) + internal void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData) { if (serieData == null || serieData.labelObject == null) return; var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); @@ -756,20 +915,32 @@ namespace XCharts var p3 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig); var p4 = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig); - if (serieLabel.rotate > 0) + if (serieLabel.textStyle.rotate > 0) { - p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate); - p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate); - p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate); - p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate); + p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.textStyle.rotate); + p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.textStyle.rotate); + p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.textStyle.rotate); + p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.textStyle.rotate); } - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor); + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, serieLabel.textStyle.backgroundColor); if (serieLabel.border) { - ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(), - serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate); + UGL.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(), + serieLabel.borderWidth, serieLabel.borderColor, serieLabel.textStyle.rotate); + } + } + + protected int GetPainterIndexBySerie(Serie serie) + { + var maxPainter = settings.maxPainter; + var maxSeries = m_Series.Count; + if (maxPainter >= maxSeries) return serie.index; + else + { + var rate = Mathf.CeilToInt(maxSeries * 1.0f / maxPainter); + return serie.index / rate; } } } diff --git a/Runtime/Internal/BaseGraph.cs b/Runtime/Internal/BaseGraph.cs index 9dee46b5..917be668 100644 --- a/Runtime/Internal/BaseGraph.cs +++ b/Runtime/Internal/BaseGraph.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; @@ -17,7 +17,13 @@ namespace XCharts IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler, IDragHandler, IEndDragHandler, IScrollHandler { + protected static readonly string s_BackgroundObjectName = "background"; + [SerializeField] protected bool m_MultiComponentMode = false; [SerializeField] protected bool m_DebugMode = false; + [SerializeField] protected bool m_EnableTextMeshPro = false; + [SerializeField] protected Background m_Background = Background.defaultBackground; + protected Painter m_Painter; + protected int m_SiblingIndex; protected float m_GraphWidth; protected float m_GraphHeight; @@ -32,6 +38,8 @@ namespace XCharts protected bool m_RefreshChart = false; protected bool m_ForceOpenRaycastTarget; protected bool m_IsControlledByLayout = false; + protected bool m_PainerDirty = false; + protected bool m_IsOnValidate = false; protected Vector3 m_LastLocalPosition; protected Action<PointerEventData, BaseGraph> m_OnPointerClick; @@ -44,20 +52,24 @@ namespace XCharts protected Action<PointerEventData, BaseGraph> m_OnEndDrag; protected Action<PointerEventData, BaseGraph> m_OnScroll; - protected Vector2 chartAnchorMax { get { return m_GraphMinAnchor; } } - protected Vector2 chartAnchorMin { get { return m_GraphMaxAnchor; } } - protected Vector2 chartPivot { get { return m_GraphPivot; } } - protected HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } } + protected Vector2 graphAnchorMax { get { return m_GraphMinAnchor; } } + protected Vector2 graphAnchorMin { get { return m_GraphMaxAnchor; } } + protected Vector2 graphPivot { get { return m_GraphPivot; } } + internal HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } } private ScrollRect m_ScrollRect; protected virtual void InitComponent() { + InitPainter(); + InitBackground(); } protected override void Awake() { + CheckTextMeshPro(); + m_SiblingIndex = 0; if (transform.parent != null) { m_IsControlledByLayout = transform.parent.GetComponent<LayoutGroup>() != null; @@ -77,13 +89,76 @@ namespace XCharts protected virtual void Update() { CheckSize(); - CheckComponent(); + if (m_IsOnValidate) + { + m_IsOnValidate = false; + m_RefreshChart = true; + CheckTextMeshPro(); + InitComponent(); + } + else + { + CheckComponent(); + } CheckPointerPos(); CheckRefreshChart(); + CheckRefreshPainter(); + } + + protected virtual void SetAllComponentDirty() + { +#if UNITY_EDITOR + if (!Application.isPlaying) + { + m_IsOnValidate = true; + Update(); + } +#endif + m_PainerDirty = true; + m_Background.SetAllDirty(); } protected virtual void CheckComponent() { + CheckComponentDirty(m_Background); + if (m_PainerDirty) + { + InitPainter(); + m_PainerDirty = false; + } + } + + private void CheckTextMeshPro() + { +#if dUI_TextMeshPro + var enableTextMeshPro = true; +#else + var enableTextMeshPro = false; +#endif + if (m_EnableTextMeshPro != enableTextMeshPro) + { + m_EnableTextMeshPro = enableTextMeshPro; + RemoveChartObject(); + } + } + + protected void CheckComponentDirty(ChartComponent component) + { + if (component.anyDirty) + { + if (component.componentDirty) + { + component.refreshComponent?.Invoke(); + } + if (component.vertsDirty) + { + if (component.painter != null) + { + RefreshPainter(component.painter); + } + } + component.ClearDirty(); + } } protected override void OnEnable() @@ -103,6 +178,7 @@ namespace XCharts protected override void OnValidate() { + m_IsOnValidate = true; } #endif @@ -114,6 +190,39 @@ namespace XCharts } } + private void InitBackground() + { + var backgroundObj = ChartHelper.AddObject(s_BackgroundObjectName, transform, m_GraphMinAnchor, + m_GraphMaxAnchor, m_GraphPivot, m_GraphSizeDelta); + m_Background.gameObject = backgroundObj; + m_Background.painter = m_Painter; + m_Background.refreshComponent = delegate () + { + if (backgroundObj == null) return; + backgroundObj.hideFlags = chartHideFlags; + var backgroundImage = ChartHelper.GetOrAddComponent<Image>(backgroundObj); + ChartHelper.UpdateRectTransform(backgroundObj, m_GraphMinAnchor, + m_GraphMaxAnchor, m_GraphPivot, m_GraphSizeDelta); + backgroundImage.sprite = m_Background.image; + backgroundImage.type = m_Background.imageType; + backgroundImage.color = m_Background.imageColor; + backgroundObj.transform.SetSiblingIndex(0); + backgroundObj.SetActive(m_Background.show); + }; + m_Background.refreshComponent(); + } + + protected virtual void InitPainter() + { + var painterObj = ChartHelper.AddObject("painter_b", transform, m_GraphMinAnchor, m_GraphMaxAnchor, + m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight)); + painterObj.transform.SetSiblingIndex(1); + painterObj.hideFlags = chartHideFlags; + m_Painter = ChartHelper.GetOrAddComponent<Painter>(painterObj); + m_Painter.type = Painter.Type.Base; + m_Painter.onPopulateMesh = OnDrawPainterBase; + } + private void CheckSize() { var currWidth = rectTransform.rect.width; @@ -198,11 +307,22 @@ namespace XCharts { if (m_RefreshChart) { - SetVerticesDirty(); + m_Painter.Refresh(); m_RefreshChart = false; } } + protected virtual void CheckRefreshPainter() + { + m_Painter.CheckRefresh(); + } + + internal virtual void RefreshPainter(Painter painter) + { + if (painter == null) return; + painter.Refresh(); + } + protected virtual void OnSizeChanged() { m_RefreshChart = true; @@ -212,14 +332,14 @@ namespace XCharts { } - protected override void OnPopulateMesh(VertexHelper vh) + protected virtual void OnDrawPainterBase(VertexHelper vh, Painter painter) { - vh.Clear(); + Debug.LogError("OnDrawPainterBase:" + Time.frameCount + "," + painter.name); DrawBackground(vh); - DrawGraphic(vh); + DrawPainterBase(vh); } - protected virtual void DrawGraphic(VertexHelper vh) + protected virtual void DrawPainterBase(VertexHelper vh) { } diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs index 6a619519..442de467 100644 --- a/Runtime/Internal/CoordinateChart.cs +++ b/Runtime/Internal/CoordinateChart.cs @@ -1,15 +1,16 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; using System.Text; using UnityEngine.EventSystems; +using XUGL; namespace XCharts { @@ -18,39 +19,25 @@ namespace XCharts private static readonly string s_DefaultDataZoom = "datazoom"; private static readonly string s_DefaultAxisName = "name"; - [SerializeField] protected Grid m_Grid = Grid.defaultGrid; - [SerializeField] protected List<XAxis> m_XAxises = new List<XAxis>(); - [SerializeField] protected List<YAxis> m_YAxises = new List<YAxis>(); - [SerializeField] protected DataZoom m_DataZoom = DataZoom.defaultDataZoom; - [SerializeField] protected VisualMap m_VisualMap = new VisualMap(); - - protected float m_CoordinateX; - protected float m_CoordinateY; - protected float m_CoordinateWidth; - protected float m_CoordinateHeight; private bool m_DataZoomDrag; private bool m_DataZoomCoordinateDrag; private bool m_DataZoomStartDrag; private bool m_DataZoomEndDrag; private float m_DataZoomLastStartIndex; private float m_DataZoomLastEndIndex; - private bool m_CheckMinMaxValue; private bool m_CheckDataZoomLabel; - private bool m_XAxisesDirty; - private bool m_YAxisesDirty; private Dictionary<int, List<Serie>> m_StackSeries = new Dictionary<int, List<Serie>>(); - private List<float> m_SeriesCurrHig = new List<float>(); - protected override void Awake() + protected override void InitComponent() { - base.Awake(); - m_CheckMinMaxValue = false; - InitDefaultAxises(); + base.InitComponent(); + InitDefaultAxes(); CheckMinMaxValue(); + InitGrid(); InitDataZoom(); InitAxisX(); InitAxisY(); - m_Tooltip.UpdateToTop(); + tooltip.UpdateToTop(); } protected override void Update() @@ -62,82 +49,54 @@ namespace XCharts base.Update(); } - protected override void CheckComponent() - { - if (m_DataZoom.anyDirty) - { - if (m_DataZoom.componentDirty) InitDataZoom(); - if (m_DataZoom.vertsDirty) RefreshChart(); - m_DataZoom.ClearDirty(); - } - if (m_VisualMap.anyDirty) - { - if (m_VisualMap.vertsDirty) RefreshChart(); - m_VisualMap.ClearDirty(); - } - if (m_Grid.anyDirty) - { - if (m_Grid.componentDirty) - { - m_XAxisesDirty = true; - m_YAxisesDirty = true; - OnCoordinateChanged(); - } - if (m_Grid.vertsDirty) RefreshChart(); - m_Grid.ClearDirty(); - } - for (int i = 0; i < m_XAxises.Count; i++) - { - var axis = m_XAxises[i]; - if (m_XAxisesDirty || axis.anyDirty) - { - if (axis.componentDirty || m_XAxisesDirty) InitXAxis(i, axis); - if (axis.vertsDirty || m_XAxisesDirty) RefreshChart(); - axis.ClearDirty(); - } - } - for (int i = 0; i < m_YAxises.Count; i++) - { - var axis = m_YAxises[i]; - if (m_YAxisesDirty || axis.anyDirty) - { - if (axis.componentDirty || m_YAxisesDirty) InitYAxis(i, axis); - if (axis.vertsDirty || m_YAxisesDirty) RefreshChart(); - axis.ClearDirty(); - } - } - m_XAxisesDirty = false; - m_YAxisesDirty = false; - base.CheckComponent(); - } - #if UNITY_EDITOR protected override void Reset() { base.Reset(); - m_Grid = Grid.defaultGrid; - m_XAxises.Clear(); - m_YAxises.Clear(); + m_Grids = new List<Grid>() { Grid.defaultGrid }; + m_DataZooms = new List<DataZoom>() { DataZoom.defaultDataZoom }; + m_VisualMaps = new List<VisualMap> { new VisualMap() }; + m_XAxes.Clear(); + m_YAxes.Clear(); Awake(); } - - protected override void OnValidate() - { - base.OnValidate(); - m_XAxisesDirty = true; - m_YAxisesDirty = true; - m_Grid.SetAllDirty(); - m_DataZoom.SetAllDirty(); - m_VisualMap.SetAllDirty(); - } #endif - - protected override void DrawChart(VertexHelper vh) + protected override void SetAllComponentDirty() { - base.DrawChart(vh); + base.SetAllComponentDirty(); + foreach (var dataZoom in m_DataZooms) dataZoom.SetAllDirty(); + foreach (var visualMap in m_VisualMaps) visualMap.SetAllDirty(); + foreach (var grid in m_Grids) grid.SetAllDirty(); + foreach (var axis in m_XAxes) axis.SetAllDirty(); + foreach (var axis in m_YAxes) axis.SetAllDirty(); + } + + private void RefreshSeriePainterByGridIndex(int gridIndex) + { + foreach (var serie in m_Series.list) + { + var axis = GetXAxis(serie.xAxisIndex); + if (axis == null) continue; + var grid = GetGrid(axis.index); + if (grid == null) continue; + if (grid.index == gridIndex) + { + RefreshPainter(serie); + } + } + } + + private void RefreshSeriePainterByAxisIndex(Axis axis) + { + var grid = GetGrid(axis.index); + if (grid == null) return; + RefreshSeriePainterByGridIndex(grid.index); + } + + protected override void DrawPainterBase(VertexHelper vh) + { + base.DrawPainterBase(vh); DrawCoordinate(vh); - DrawSerie(vh); - DrawAxisTick(vh); DrawDataZoomSlider(vh); DrawVisualMap(vh); } @@ -146,18 +105,20 @@ namespace XCharts { if (SeriesHelper.IsAnyClipSerie(m_Series)) { - var xLineDiff = xAxis0.axisLine.width; - var yLineDiff = yAxis0.axisLine.width; - var xSplitDiff = xAxis0.splitLine.lineStyle.width; - var ySplitDiff = yAxis0.splitLine.lineStyle.width; - - var cpty = m_CoordinateY + m_CoordinateHeight + ySplitDiff; - var cp1 = new Vector3(m_CoordinateX - yLineDiff, m_CoordinateY - xLineDiff); - var cp2 = new Vector3(m_CoordinateX - yLineDiff, cpty); - var cp3 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, cpty); - var cp4 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_CoordinateY - xLineDiff); - var backgroundColor = ThemeHelper.GetBackgroundColor(m_ThemeInfo, m_Background); - ChartDrawer.DrawPolygon(vh, cp1, cp2, cp3, cp4, backgroundColor); + var xLineDiff = xAxis0.axisLine.GetWidth(m_Theme.axis.lineWidth); + var yLineDiff = yAxis0.axisLine.GetWidth(m_Theme.axis.lineWidth); + var xSplitDiff = xAxis0.splitLine.GetWidth(m_Theme.axis.splitLineWidth); + var ySplitDiff = yAxis0.splitLine.GetWidth(m_Theme.axis.splitLineWidth); + foreach (var grid in m_Grids) + { + var cpty = grid.runtimeY + grid.runtimeHeight + ySplitDiff; + var cp1 = new Vector3(grid.runtimeX - yLineDiff, grid.runtimeY - xLineDiff); + var cp2 = new Vector3(grid.runtimeX - yLineDiff, cpty); + var cp3 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, cpty); + var cp4 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, grid.runtimeY - xLineDiff); + var backgroundColor = ThemeHelper.GetBackgroundColor(m_Theme, m_Background); + UGL.DrawQuadrilateral(vh, cp1, cp2, cp3, cp4, backgroundColor); + } } else { @@ -168,126 +129,144 @@ namespace XCharts protected void DrawClip(VertexHelper vh) { if (!SeriesHelper.IsAnyClipSerie(m_Series)) return; - var xLineDiff = xAxis0.axisLine.width; - var yLineDiff = yAxis0.axisLine.width; - var xSplitDiff = xAxis0.splitLine.lineStyle.width; - var ySplitDiff = yAxis0.splitLine.lineStyle.width; - var backgroundColor = ThemeHelper.GetBackgroundColor(m_ThemeInfo, m_Background); + var xLineDiff = xAxis0.axisLine.GetWidth(m_Theme.axis.lineWidth); + var yLineDiff = yAxis0.axisLine.GetWidth(m_Theme.axis.lineWidth); + var xSplitDiff = xAxis0.splitLine.GetWidth(m_Theme.axis.splitLineWidth); + var ySplitDiff = yAxis0.splitLine.GetWidth(m_Theme.axis.splitLineWidth); + var backgroundColor = ThemeHelper.GetBackgroundColor(m_Theme, m_Background); var lp1 = new Vector3(m_ChartX, m_ChartY); var lp2 = new Vector3(m_ChartX, m_ChartY + chartHeight); - var lp3 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY + chartHeight); - var lp4 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY); - ChartDrawer.DrawPolygon(vh, lp1, lp2, lp3, lp4, backgroundColor); - var rp1 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY); - var rp2 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY + chartHeight); + var lp3 = new Vector3(grid.runtimeX - yLineDiff, m_ChartY + chartHeight); + var lp4 = new Vector3(grid.runtimeX - yLineDiff, m_ChartY); + UGL.DrawQuadrilateral(vh, lp1, lp2, lp3, lp4, backgroundColor); + var rp1 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, m_ChartY); + var rp2 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, m_ChartY + chartHeight); var rp3 = new Vector3(m_ChartX + chartWidth, m_ChartY + chartHeight); var rp4 = new Vector3(m_ChartX + chartWidth, m_ChartY); - ChartDrawer.DrawPolygon(vh, rp1, rp2, rp3, rp4, backgroundColor); - var up1 = new Vector3(m_CoordinateX - yLineDiff, m_CoordinateY + m_CoordinateHeight + ySplitDiff); - var up2 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY + chartHeight); - var up3 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY + chartHeight); - var up4 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_CoordinateY + m_CoordinateHeight + ySplitDiff); - ChartDrawer.DrawPolygon(vh, up1, up2, up3, up4, backgroundColor); - var dp1 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY); - var dp2 = new Vector3(m_CoordinateX - yLineDiff, m_CoordinateY - xLineDiff); - var dp3 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_CoordinateY - xLineDiff); - var dp4 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY); - ChartDrawer.DrawPolygon(vh, dp1, dp2, dp3, dp4, backgroundColor); + UGL.DrawQuadrilateral(vh, rp1, rp2, rp3, rp4, backgroundColor); + var up1 = new Vector3(grid.runtimeX - yLineDiff, grid.runtimeY + grid.runtimeHeight + ySplitDiff); + var up2 = new Vector3(grid.runtimeX - yLineDiff, m_ChartY + chartHeight); + var up3 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, m_ChartY + chartHeight); + var up4 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, + grid.runtimeY + grid.runtimeHeight + ySplitDiff); + UGL.DrawQuadrilateral(vh, up1, up2, up3, up4, backgroundColor); + var dp1 = new Vector3(grid.runtimeX - yLineDiff, m_ChartY); + var dp2 = new Vector3(grid.runtimeX - yLineDiff, grid.runtimeY - xLineDiff); + var dp3 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, grid.runtimeY - xLineDiff); + var dp4 = new Vector3(grid.runtimeX + grid.runtimeWidth + xSplitDiff, m_ChartY); + UGL.DrawQuadrilateral(vh, dp1, dp2, dp3, dp4, backgroundColor); } - protected virtual void DrawSerie(VertexHelper vh) + protected override void DrawPainterSerie(VertexHelper vh, Serie serie) { - base.DrawChart(vh); - if (!m_CheckMinMaxValue) return; - m_IsPlayingAnimation = false; - bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory(); - SeriesHelper.GetStackSeries(m_Series, ref m_StackSeries); - int seriesCount = m_StackSeries.Count; - m_BarLastOffset = 0; - for (int j = 0; j < seriesCount; j++) + base.DrawPainterSerie(vh, serie); + serie.dataPoints.Clear(); + var colorIndex = m_LegendRealShowName.IndexOf(serie.legendName); + bool yCategory = m_YAxes[0].IsCategory() || m_YAxes[1].IsCategory(); + switch (serie.type) { - var serieList = m_StackSeries[j]; - m_SeriesCurrHig.Clear(); - for (int n = 0; n < serieList.Count; n++) - { - Serie serie = serieList[n]; - serie.dataPoints.Clear(); - var colorIndex = m_LegendRealShowName.IndexOf(serie.legendName); - switch (serie.type) + case SerieType.Line: + if (yCategory) DrawYLineSerie(vh, serie, colorIndex); + else DrawXLineSerie(vh, serie, colorIndex); + if (!SeriesHelper.IsStack(m_Series)) { - case SerieType.Line: - if (yCategory) DrawYLineSerie(vh, serie, colorIndex, ref m_SeriesCurrHig); - else DrawXLineSerie(vh, serie, colorIndex, ref m_SeriesCurrHig); - break; - case SerieType.Bar: - if (yCategory) DrawYBarSerie(vh, serie, colorIndex, ref m_SeriesCurrHig); - else DrawXBarSerie(vh, serie, colorIndex, ref m_SeriesCurrHig); - break; - case SerieType.Scatter: - case SerieType.EffectScatter: - DrawScatterSerie(vh, colorIndex, serie); - break; - case SerieType.Heatmap: - DrawHeatmapSerie(vh, colorIndex, serie); - break; + DrawLinePoint(vh, serie); + DrawLineArrow(vh, serie); } - } + break; + case SerieType.Bar: + if (yCategory) DrawYBarSerie(vh, serie, colorIndex); + else DrawXBarSerie(vh, serie, colorIndex); + break; + case SerieType.Scatter: + case SerieType.EffectScatter: + DrawScatterSerie(vh, colorIndex, serie); + break; + case SerieType.Heatmap: + DrawHeatmapSerie(vh, colorIndex, serie); + break; } + } + + protected override void DrawPainterTop(VertexHelper vh) + { + DrawAxisTick(vh); DrawClip(vh); DrawLabelBackground(vh); - DrawLinePoint(vh); - DrawLineArrow(vh); + if (SeriesHelper.IsStack(m_Series)) + { + foreach (var serie in m_Series.list) + { + DrawLinePoint(vh, serie); + DrawLineArrow(vh, serie); + } + } + bool yCategory = m_YAxes[0].IsCategory() || m_YAxes[1].IsCategory(); if (yCategory) DrawYTooltipIndicator(vh); else DrawXTooltipIndicator(vh); } - protected override void CheckTootipArea(Vector2 local) + protected override void CheckTootipArea(Vector2 local, bool isActivedOther) { - if (!IsInCooridate(local)) + if (isActivedOther) { - m_Tooltip.ClearValue(); + foreach (var axis in m_XAxes) axis.SetTooltipLabelActive(false); + foreach (var axis in m_YAxes) axis.SetTooltipLabelActive(false); + return; + } + var grid = GetGrid(local); + if (grid == null) + { + tooltip.runtimeGridIndex = -1; + tooltip.ClearValue(); UpdateTooltip(); } else { + if (tooltip.runtimeGridIndex != grid.index) + { + tooltip.runtimeGridIndex = grid.index; + RefreshSeriePainterByGridIndex(grid.index); + } UpdateTooltipValue(local); } - if (m_Tooltip.IsSelected()) + if (tooltip.IsSelected()) { - m_Tooltip.UpdateContentPos(local + m_Tooltip.offset); + tooltip.UpdateContentPos(local + tooltip.offset); UpdateTooltip(); - if (m_Tooltip.IsDataIndexChanged() || m_Tooltip.type == Tooltip.Type.Corss) + if (tooltip.IsDataIndexChanged() || tooltip.type == Tooltip.Type.Corss) { - m_Tooltip.UpdateLastDataIndex(); - RefreshChart(); + tooltip.UpdateLastDataIndex(); + m_PainterTop.Refresh(); } } - else if (m_Tooltip.IsActive()) + else if (tooltip.IsActive()) { - m_Tooltip.SetActive(false); - RefreshChart(); + tooltip.SetActive(false); + m_PainterTop.Refresh(); } } protected void UpdateTooltipValue(Vector2 local) { var isCartesian = IsValue(); - int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0; - for (int i = 0; i < m_XAxises.Count; i++) + var dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0; + var grid = GetGrid(tooltip.runtimeGridIndex); + for (int i = 0; i < m_XAxes.Count; i++) { - var xAxis = m_XAxises[i]; - var yAxis = m_YAxises[i]; + var xAxis = m_XAxes[i]; + var yAxis = m_YAxes[i]; if (!xAxis.show && !yAxis.show) continue; if (isCartesian && xAxis.show && yAxis.show) { - var yRate = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) / m_CoordinateHeight; - var xRate = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) / m_CoordinateWidth; - var yValue = yRate * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset); + var yRate = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) / grid.runtimeHeight; + var xRate = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) / grid.runtimeWidth; + var yValue = yRate * (local.y - grid.runtimeY - yAxis.runtimeZeroYOffset); if (yAxis.runtimeMinValue > 0) yValue += yAxis.runtimeMinValue; - m_Tooltip.runtimeYValues[i] = yValue; - var xValue = xRate * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset); + tooltip.runtimeYValues[i] = yValue; + var xValue = xRate * (local.x - grid.runtimeX - xAxis.runtimeZeroXOffset); if (xAxis.runtimeMinValue > 0) xValue += xAxis.runtimeMinValue; - m_Tooltip.runtimeXValues[i] = xValue; + tooltip.runtimeXValues[i] = xValue; for (int j = 0; j < m_Series.Count; j++) { @@ -298,11 +277,13 @@ namespace XCharts var xdata = serieData.GetData(0, xAxis.inverse); var ydata = serieData.GetData(1, yAxis.inverse); var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - var symbolSize = symbol.GetSize(serieData == null ? null : serieData.data); + var symbolSize = symbol.GetSize(serieData == null ? null : serieData.data, + m_Theme.serie.lineSymbolSize); if (Mathf.Abs(xValue - xdata) / xRate < symbolSize && Mathf.Abs(yValue - ydata) / yRate < symbolSize) { - m_Tooltip.runtimeDataIndex[i] = n; + tooltip.runtimeDataIndex[i] = n; + RefreshPainter(serie); serieData.highlighted = true; } else @@ -314,63 +295,64 @@ namespace XCharts } else if (IsCategory()) { - - for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++) + for (int j = 0; j < xAxis.GetDataNumber(dataZoom); j++) { - float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom); - float pX = m_CoordinateX + j * splitWid; + float splitWid = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, dataCount, dataZoom); + float pX = grid.runtimeX + j * splitWid; if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) || (!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2))) { - m_Tooltip.runtimeXValues[i] = j; - m_Tooltip.runtimeDataIndex[i] = j; + tooltip.runtimeXValues[i] = j; + tooltip.runtimeDataIndex[i] = j; break; } } - for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++) + for (int j = 0; j < yAxis.GetDataNumber(dataZoom); j++) { - float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom); - float pY = m_CoordinateY + j * splitWid; + float splitWid = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, dataCount, dataZoom); + float pY = grid.runtimeY + j * splitWid; if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) || (!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2))) { - m_Tooltip.runtimeYValues[i] = j; + tooltip.runtimeYValues[i] = j; break; } } } else if (xAxis.IsCategory()) { - var value = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset) / m_CoordinateHeight; + var value = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * (local.y - grid.runtimeY - yAxis.runtimeZeroYOffset) / grid.runtimeHeight; if (yAxis.runtimeMinValue > 0) value += yAxis.runtimeMinValue; - m_Tooltip.runtimeYValues[i] = value; - for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++) + tooltip.runtimeYValues[i] = value; + for (int j = 0; j < xAxis.GetDataNumber(dataZoom); j++) { - float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom); - float pX = m_CoordinateX + j * splitWid; + float splitWid = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, dataCount, dataZoom); + float pX = grid.runtimeX + j * splitWid; if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) || (!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2))) { - m_Tooltip.runtimeXValues[i] = j; - m_Tooltip.runtimeDataIndex[i] = j; + tooltip.runtimeXValues[i] = j; + tooltip.runtimeDataIndex[i] = j; + RefreshSeriePainterByAxisIndex(xAxis); break; } } } else if (yAxis.IsCategory()) { - var value = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset) / m_CoordinateWidth; + var value = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * (local.x - grid.runtimeX - xAxis.runtimeZeroXOffset) / grid.runtimeWidth; if (xAxis.runtimeMinValue > 0) value += xAxis.runtimeMinValue; - m_Tooltip.runtimeXValues[i] = value; - for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++) + tooltip.runtimeXValues[i] = value; + for (int j = 0; j < yAxis.GetDataNumber(dataZoom); j++) { - float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom); - float pY = m_CoordinateY + j * splitWid; + float splitWid = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, dataCount, dataZoom); + float pY = grid.runtimeY + j * splitWid; if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) || (!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2))) { - m_Tooltip.runtimeYValues[i] = j; - m_Tooltip.runtimeDataIndex[i] = j; + tooltip.runtimeYValues[i] = j; + tooltip.runtimeDataIndex[i] = j; + RefreshSeriePainterByAxisIndex(yAxis); break; } } @@ -387,84 +369,89 @@ namespace XCharts bool isCartesian = IsValue(); if (isCartesian) { - index = m_Tooltip.runtimeDataIndex[0]; - tempAxis = m_XAxises[0]; + index = tooltip.runtimeDataIndex[0]; + tempAxis = m_XAxes[0]; } - else if (m_XAxises[0].type == Axis.AxisType.Value) + else if (m_XAxes[0].type == Axis.AxisType.Value) { - index = (int)m_Tooltip.runtimeYValues[0]; - tempAxis = m_YAxises[0]; + index = (int)tooltip.runtimeYValues[0]; + tempAxis = m_YAxes[0]; } else { - index = (int)m_Tooltip.runtimeXValues[0]; - tempAxis = m_XAxises[0]; + index = (int)tooltip.runtimeXValues[0]; + tempAxis = m_XAxes[0]; } if (index < 0) { - if (m_Tooltip.IsActive()) + if (tooltip.IsActive()) { - m_Tooltip.SetActive(false); + tooltip.SetActive(false); RefreshChart(); } return; } - var category = tempAxis.GetData(index, m_DataZoom); - var content = TooltipHelper.GetFormatterContent(m_Tooltip, index, m_Series, m_ThemeInfo, category, - m_DataZoom, isCartesian); - TooltipHelper.SetContentAndPosition(m_Tooltip, content, chartRect); - m_Tooltip.SetActive(true); + UpdateSerieGridIndex(); + RefreshSeriePainterByGridIndex(grid.index); + var category = tempAxis.GetData(index, dataZoom); + var content = TooltipHelper.GetFormatterContent(tooltip, index, m_Series, m_Theme, category, + dataZoom, isCartesian); + TooltipHelper.SetContentAndPosition(tooltip, content, chartRect); + tooltip.SetActive(true); - for (int i = 0; i < m_XAxises.Count; i++) + for (int i = 0; i < m_XAxes.Count; i++) { - UpdateAxisTooltipLabel(i, m_XAxises[i]); + UpdateAxisTooltipLabel(i, m_XAxes[i]); } - for (int i = 0; i < m_YAxises.Count; i++) + for (int i = 0; i < m_YAxes.Count; i++) { - UpdateAxisTooltipLabel(i, m_YAxises[i]); + UpdateAxisTooltipLabel(i, m_YAxes[i]); } } protected void UpdateAxisTooltipLabel(int axisIndex, Axis axis) { - var showTooltipLabel = axis.show && m_Tooltip.type == Tooltip.Type.Corss; + var showTooltipLabel = axis.show && tooltip.type == Tooltip.Type.Corss; axis.SetTooltipLabelActive(showTooltipLabel); if (!showTooltipLabel) return; - string labelText = ""; - Vector2 labelPos = Vector2.zero; + var labelText = ""; + var labelPos = Vector2.zero; + var grid = GetAxisGridOrDefault(axis); if (axis is XAxis) { - var posY = axisIndex > 0 ? m_CoordinateY + m_CoordinateHeight : m_CoordinateY; - var diff = axisIndex > 0 ? -axis.axisLabel.fontSize - axis.axisLabel.margin - 3.5f : axis.axisLabel.margin / 2 + 1; + var posY = axisIndex > 0 ? grid.runtimeY + grid.runtimeHeight : grid.runtimeY; + var diff = axisIndex > 0 + ? -axis.axisLabel.textStyle.GetFontSize(m_Theme.tooltip) - axis.axisLabel.margin - 3.5f + : axis.axisLabel.margin / 2 + 1; if (axis.IsValue()) { - labelText = ChartCached.NumberToStr(m_Tooltip.runtimeXValues[axisIndex], axis.axisLabel.numericFormatter); - labelPos = new Vector2(m_Tooltip.runtimePointerPos.x, posY - diff); + labelText = ChartCached.NumberToStr(tooltip.runtimeXValues[axisIndex], axis.axisLabel.numericFormatter); + labelPos = new Vector2(tooltip.runtimePointerPos.x, posY - diff); } else { - labelText = axis.GetData((int)m_Tooltip.runtimeXValues[axisIndex], m_DataZoom); - float splitWidth = AxisHelper.GetSplitWidth(axis, m_CoordinateWidth, m_DataZoom); - int index = (int)m_Tooltip.runtimeXValues[axisIndex]; - float px = m_CoordinateX + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0) + 0.5f; + labelText = axis.GetData((int)tooltip.runtimeXValues[axisIndex], dataZoom); + float splitWidth = AxisHelper.GetSplitWidth(axis, grid.runtimeWidth, dataZoom); + int index = (int)tooltip.runtimeXValues[axisIndex]; + float px = grid.runtimeX + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0) + 0.5f; labelPos = new Vector2(px, posY - diff); } } else if (axis is YAxis) { - var posX = axisIndex > 0 ? m_CoordinateX + m_CoordinateWidth : m_CoordinateX; + var posX = axisIndex > 0 ? grid.runtimeX + grid.runtimeWidth : grid.runtimeX; var diff = axisIndex > 0 ? -axis.axisLabel.margin + 3 : axis.axisLabel.margin - 3; if (axis.IsValue()) { - labelText = ChartCached.NumberToStr(m_Tooltip.runtimeYValues[axisIndex], axis.axisLabel.numericFormatter); - labelPos = new Vector2(posX - diff, m_Tooltip.runtimePointerPos.y); + labelText = ChartCached.NumberToStr(tooltip.runtimeYValues[axisIndex], axis.axisLabel.numericFormatter); + labelPos = new Vector2(posX - diff, tooltip.runtimePointerPos.y); } else { - labelText = axis.GetData((int)m_Tooltip.runtimeYValues[axisIndex], m_DataZoom); - float splitWidth = AxisHelper.GetSplitWidth(axis, m_CoordinateHeight, m_DataZoom); - int index = (int)m_Tooltip.runtimeYValues[axisIndex]; - float py = m_CoordinateY + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0); + labelText = axis.GetData((int)tooltip.runtimeYValues[axisIndex], dataZoom); + float splitWidth = AxisHelper.GetSplitWidth(axis, grid.runtimeHeight, dataZoom); + int index = (int)tooltip.runtimeYValues[axisIndex]; + float py = grid.runtimeY + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0); labelPos = new Vector2(posX - diff, py); } } @@ -472,26 +459,20 @@ namespace XCharts axis.UpdateTooltipLabelPos(labelPos); } - protected override void OnThemeChanged() + private void InitDefaultAxes() { - base.OnThemeChanged(); - m_DataZoom.SetAllDirty(); - m_XAxisesDirty = true; - m_YAxisesDirty = true; - } - - private void InitDefaultAxises() - { - if (m_XAxises.Count <= 0) + if (m_XAxes.Count <= 0) { var axis1 = XAxis.defaultXAxis; var axis2 = XAxis.defaultXAxis; axis1.show = true; axis2.show = false; - m_XAxises.Add(axis1); - m_XAxises.Add(axis2); + axis1.position = Axis.AxisPosition.Bottom; + axis2.position = Axis.AxisPosition.Top; + m_XAxes.Add(axis1); + m_XAxes.Add(axis2); } - if (m_YAxises.Count <= 0) + if (m_YAxes.Count <= 0) { var axis1 = YAxis.defaultYAxis; var axis2 = YAxis.defaultYAxis; @@ -499,251 +480,287 @@ namespace XCharts axis1.splitNumber = 5; axis1.boundaryGap = false; axis2.show = false; - m_YAxises.Add(axis1); - m_YAxises.Add(axis2); + axis1.position = Axis.AxisPosition.Left; + axis2.position = Axis.AxisPosition.Right; + m_YAxes.Add(axis1); + m_YAxes.Add(axis2); } - foreach (var axis in m_XAxises) axis.runtimeMinValue = axis.runtimeMaxValue = 0; - foreach (var axis in m_YAxises) axis.runtimeMinValue = axis.runtimeMaxValue = 0; + foreach (var axis in m_XAxes) axis.runtimeMinValue = axis.runtimeMaxValue = 0; + foreach (var axis in m_YAxes) axis.runtimeMinValue = axis.runtimeMaxValue = 0; } private void InitAxisY() { - for (int i = 0; i < m_YAxises.Count; i++) + for (int i = 0; i < m_YAxes.Count; i++) { - InitYAxis(i, m_YAxises[i]); + InitYAxis(i, m_YAxes[i]); } } private void InitYAxis(int yAxisIndex, YAxis yAxis) { - yAxis.axisLabelTextList.Clear(); string objName = ChartCached.GetYAxisName(yAxisIndex); - var axisObj = ChartHelper.AddObject(objName, transform, chartAnchorMin, - chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); - axisObj.transform.localPosition = Vector3.zero; - axisObj.SetActive(yAxis.show && yAxis.axisLabel.show); - axisObj.hideFlags = chartHideFlags; - ChartHelper.HideAllObject(axisObj); - var labelColor = ChartHelper.IsClearColor(yAxis.axisLabel.color) ? - (Color)m_ThemeInfo.axisTextColor : - yAxis.axisLabel.color; - int splitNumber = AxisHelper.GetScaleNumber(yAxis, m_CoordinateHeight, m_DataZoom); - float totalWidth = 0; - float eachWidth = AxisHelper.GetEachWidth(yAxis, m_CoordinateHeight, m_DataZoom); - float gapWidth = yAxis.boundaryGap ? eachWidth / 2 : 0; - for (int i = 0; i < splitNumber; i++) + var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, + graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); + yAxis.gameObject = axisObj; + yAxis.painter = m_Painter; + yAxis.refreshComponent = delegate () { - Text txt; - bool inside = yAxis.axisLabel.inside; - if ((inside && yAxisIndex == 0) || (!inside && yAxisIndex == 1)) + if (axisObj == null) return; + yAxis.axisLabelTextList.Clear(); + axisObj.SetActive(yAxis.show && yAxis.axisLabel.show); + axisObj.hideFlags = chartHideFlags; + ChartHelper.HideAllObject(axisObj); + var grid = GetAxisGridOrDefault(yAxis); + if (grid == null) return; + var axisLabelTextStyle = yAxis.axisLabel.textStyle; + int splitNumber = AxisHelper.GetScaleNumber(yAxis, grid.runtimeHeight, dataZoom); + float totalWidth = 0; + float eachWidth = AxisHelper.GetEachWidth(yAxis, grid.runtimeHeight, dataZoom); + float gapWidth = yAxis.boundaryGap ? eachWidth / 2 : 0; + for (int i = 0; i < splitNumber; i++) { - txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, - m_ThemeInfo.font, labelColor, TextAnchor.MiddleLeft, Vector2.zero, - Vector2.zero, new Vector2(0, 0.5f), new Vector2(m_Grid.left, 20), - yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle); + ChartText txt; + var inside = yAxis.axisLabel.inside; + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); + var labelName = AxisHelper.GetLabelName(yAxis, grid.runtimeHeight, i, yAxis.runtimeMinValue, + yAxis.runtimeMaxValue, dataZoom, isPercentStack); + if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight())) + { + txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, Vector2.zero, + Vector2.zero, new Vector2(0, 0.5f), new Vector2(grid.left, 20), axisLabelTextStyle, + m_Theme.axis); + txt.SetAlignment(TextAnchor.MiddleLeft); + } + else + { + txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, Vector2.zero, + Vector2.zero, new Vector2(1, 0.5f), new Vector2(grid.left, 20), axisLabelTextStyle, + m_Theme.axis); + txt.SetAlignment(TextAnchor.MiddleRight); + } + var labelWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom); + if (i == 0) yAxis.axisLabel.SetRelatedText(txt, labelWidth); + txt.SetLocalPosition(GetLabelYPosition(totalWidth + gapWidth, i, yAxisIndex, yAxis)); + txt.SetText(labelName); + txt.SetActive(yAxis.show && (yAxis.axisLabel.interval == 0 || i % (yAxis.axisLabel.interval + 1) == 0)); + yAxis.axisLabelTextList.Add(txt); + totalWidth += labelWidth; } - else + if (yAxis.axisName.show) { - txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, - m_ThemeInfo.font, labelColor, TextAnchor.MiddleRight, Vector2.zero, - Vector2.zero, new Vector2(1, 0.5f), new Vector2(m_Grid.left, 20), - yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle); + var axisNameTextStyle = yAxis.axisName.textStyle; + var offset = axisNameTextStyle.offset; + ChartText axisName = null; + var zeroPos = new Vector3(grid.runtimeX + m_XAxes[yAxisIndex].runtimeZeroXOffset, grid.runtimeY); + switch (yAxis.axisName.location) + { + case AxisName.Location.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, + m_Theme.axis); + axisName.SetAlignment(TextAnchor.MiddleCenter); + axisName.SetLocalPosition(yAxis.position == Axis.AxisPosition.Right ? + new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x + yAxis.offset, grid.runtimeY - offset.y) : + new Vector2(zeroPos.x + offset.x + yAxis.offset, grid.runtimeY - offset.y)); + break; + case AxisName.Location.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, + m_Theme.axis); + axisName.SetAlignment(TextAnchor.MiddleRight); + axisName.SetLocalPosition(yAxis.position == Axis.AxisPosition.Right ? + new Vector2(grid.runtimeX + grid.runtimeWidth - offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight / 2 + offset.y) : + new Vector2(grid.runtimeX - offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight / 2 + offset.y)); + 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, + m_Theme.axis); + axisName.SetAlignment(TextAnchor.MiddleCenter); + axisName.SetLocalPosition(yAxis.position == Axis.AxisPosition.Right ? + new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight + offset.y) : + new Vector2(zeroPos.x + offset.x + yAxis.offset, grid.runtimeY + grid.runtimeHeight + offset.y)); + break; + } + axisName.SetText(yAxis.axisName.name); } - - float labelWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i + 1, m_DataZoom); - if (i == 0) yAxis.axisLabel.SetRelatedText(txt, labelWidth); - txt.transform.localPosition = GetLabelYPosition(totalWidth + gapWidth, i, yAxisIndex, yAxis); - - var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); - txt.text = AxisHelper.GetLabelName(yAxis, m_CoordinateHeight, i, yAxis.runtimeMinValue, yAxis.runtimeMaxValue, m_DataZoom, isPercentStack); - txt.gameObject.SetActive(yAxis.show && - (yAxis.axisLabel.interval == 0 || i % (yAxis.axisLabel.interval + 1) == 0)); - yAxis.axisLabelTextList.Add(txt); - totalWidth += labelWidth; - } - if (yAxis.axisName.show) - { - var color = ChartHelper.IsClearColor(yAxis.axisName.color) ? (Color)m_ThemeInfo.axisTextColor : - yAxis.axisName.color; - var fontSize = yAxis.axisName.fontSize; - var offset = yAxis.axisName.offset; - Text axisName = null; - var zeroPos = new Vector3(m_CoordinateX + m_XAxises[yAxisIndex].runtimeZeroXOffset, m_CoordinateY); - switch (yAxis.axisName.location) + //init tooltip label + if (tooltip.runtimeGameObject) { - case AxisName.Location.Start: - axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, - m_ThemeInfo.font, color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), - new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize, - yAxis.axisName.rotate, yAxis.axisName.fontStyle); - axisName.transform.localPosition = yAxisIndex > 0 ? - new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, m_CoordinateY - offset.y) : - new Vector2(zeroPos.x + offset.x, m_CoordinateY - offset.y); - break; - case AxisName.Location.Middle: - axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, - m_ThemeInfo.font, color, TextAnchor.MiddleRight, new Vector2(1, 0.5f), - new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), fontSize, - yAxis.axisName.rotate, yAxis.axisName.fontStyle); - axisName.transform.localPosition = yAxisIndex > 0 ? - new Vector2(m_CoordinateX + m_CoordinateWidth - offset.x, m_CoordinateY + m_CoordinateHeight / 2 + offset.y) : - new Vector2(m_CoordinateX - offset.x, m_CoordinateY + m_CoordinateHeight / 2 + offset.y); - break; - case AxisName.Location.End: - axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, - m_ThemeInfo.font, color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), - new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize, - yAxis.axisName.rotate, yAxis.axisName.fontStyle); - axisName.transform.localPosition = yAxisIndex > 0 ? - new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, m_CoordinateY + m_CoordinateHeight + offset.y) : - new Vector2(zeroPos.x + offset.x, m_CoordinateY + m_CoordinateHeight + offset.y); - break; + Vector2 privot = yAxis.position == Axis.AxisPosition.Right ? new Vector2(0, 0.5f) : new Vector2(1, 0.5f); + var labelParent = tooltip.runtimeGameObject.transform; + var labelName = ChartCached.GetAxisTooltipLabel(objName); + GameObject labelObj = ChartHelper.AddTooltipLabel(labelName, labelParent, m_Theme, privot); + yAxis.SetTooltipLabel(labelObj); + yAxis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor); + yAxis.SetTooltipLabelActive(yAxis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); } - axisName.text = yAxis.axisName.name; - } - //init tooltip label - if (m_Tooltip.runtimeGameObject) - { - Vector2 privot = yAxisIndex > 0 ? new Vector2(0, 0.5f) : new Vector2(1, 0.5f); - var labelParent = m_Tooltip.runtimeGameObject.transform; - GameObject labelObj = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, m_ThemeInfo.font, privot); - yAxis.SetTooltipLabel(labelObj); - yAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor); - yAxis.SetTooltipLabelActive(yAxis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss); - } + }; + yAxis.refreshComponent(); } private void InitAxisX() { - for (int i = 0; i < m_XAxises.Count; i++) + for (int i = 0; i < m_XAxes.Count; i++) { - InitXAxis(i, m_XAxises[i]); + InitXAxis(i, m_XAxes[i]); } } private void InitXAxis(int xAxisIndex, XAxis xAxis) { - xAxis.axisLabelTextList.Clear(); - string objName = ChartCached.GetXAxisName(xAxisIndex); - var axisObj = ChartHelper.AddObject(objName, transform, chartAnchorMin, - chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); - axisObj.transform.localPosition = Vector3.zero; - axisObj.SetActive(xAxis.show && xAxis.axisLabel.show); - axisObj.hideFlags = chartHideFlags; - ChartHelper.HideAllObject(axisObj); - var labelColor = ChartHelper.IsClearColor(xAxis.axisLabel.color) ? - (Color)m_ThemeInfo.axisTextColor : - xAxis.axisLabel.color; - int splitNumber = AxisHelper.GetScaleNumber(xAxis, m_CoordinateWidth, m_DataZoom); - float totalWidth = 0; - float eachWidth = AxisHelper.GetEachWidth(xAxis, m_CoordinateWidth, m_DataZoom); - float gapWidth = xAxis.boundaryGap ? eachWidth / 2 : 0; - float textWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, 0, m_DataZoom); - for (int i = 0; i < splitNumber; i++) + var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, + graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); + xAxis.gameObject = axisObj; + xAxis.painter = m_Painter; + xAxis.refreshComponent = delegate () { - float labelWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i + 1, m_DataZoom); - bool inside = xAxis.axisLabel.inside; - Text txt = ChartHelper.AddTextObject(ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform, - m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0, 1), - new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, 20), - xAxis.axisLabel.fontSize, xAxis.axisLabel.rotate, xAxis.axisLabel.fontStyle); - if (i == 0) xAxis.axisLabel.SetRelatedText(txt, labelWidth); - txt.transform.localPosition = GetLabelXPosition(totalWidth + textWidth / 2 + gapWidth, - i, xAxisIndex, xAxis); - totalWidth += labelWidth; - var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); - txt.text = AxisHelper.GetLabelName(xAxis, m_CoordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom, - isPercentStack); - txt.gameObject.SetActive(xAxis.show && - (xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0)); - xAxis.axisLabelTextList.Add(txt); - } - if (xAxis.axisName.show) - { - var color = ChartHelper.IsClearColor(xAxis.axisName.color) ? (Color)m_ThemeInfo.axisTextColor : - xAxis.axisName.color; - var fontSize = xAxis.axisName.fontSize; - var offset = xAxis.axisName.offset; - Text axisName = null; - var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + m_YAxises[xAxisIndex].runtimeZeroYOffset); - switch (xAxis.axisName.location) + if (axisObj == null) return; + xAxis.axisLabelTextList.Clear(); + axisObj.SetActive(xAxis.show && xAxis.axisLabel.show); + axisObj.hideFlags = chartHideFlags; + ChartHelper.HideAllObject(axisObj); + var grid = GetAxisGridOrDefault(xAxis); + if (grid == null) return; + var axisLabelTextStyle = xAxis.axisLabel.textStyle; + int splitNumber = AxisHelper.GetScaleNumber(xAxis, grid.runtimeWidth, dataZoom); + float totalWidth = 0; + float eachWidth = AxisHelper.GetEachWidth(xAxis, grid.runtimeWidth, dataZoom); + float gapWidth = xAxis.boundaryGap ? eachWidth / 2 : 0; + float textWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, 0, dataZoom); + for (int i = 0; i < splitNumber; i++) { - case AxisName.Location.Start: - axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, - m_ThemeInfo.font, color, TextAnchor.MiddleRight, new Vector2(1, 0.5f), - new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), fontSize, - xAxis.axisName.rotate, xAxis.axisName.fontStyle); - axisName.transform.localPosition = xAxisIndex > 0 ? - new Vector2(zeroPos.x - offset.x, m_CoordinateY + m_CoordinateHeight + offset.y) : - new Vector2(zeroPos.x - offset.x, zeroPos.y + offset.y); - break; - case AxisName.Location.Middle: - axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, - m_ThemeInfo.font, color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), - new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize, - xAxis.axisName.rotate, xAxis.axisName.fontStyle); - axisName.transform.localPosition = xAxisIndex > 0 ? - new Vector2(m_CoordinateX + m_CoordinateWidth / 2 + offset.x, m_CoordinateY + m_CoordinateHeight - offset.y) : - new Vector2(m_CoordinateX + m_CoordinateWidth / 2 + offset.x, m_CoordinateY - offset.y); - break; - case AxisName.Location.End: - axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, - m_ThemeInfo.font, color, TextAnchor.MiddleLeft, new Vector2(0, 0.5f), - new Vector2(0, 0.5f), new Vector2(0, 0.5f), new Vector2(100, 20), fontSize, - xAxis.axisName.rotate, xAxis.axisName.fontStyle); - axisName.transform.localPosition = xAxisIndex > 0 ? - new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, m_CoordinateY + m_CoordinateHeight + offset.y) : - new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, zeroPos.y + offset.y); - break; + var labelWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom); + var inside = xAxis.axisLabel.inside; + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); + var txt = ChartHelper.AddTextObject(ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform, new Vector2(0, 1), + new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, 20), axisLabelTextStyle, theme.axis); + if (i == 0) xAxis.axisLabel.SetRelatedText(txt, labelWidth); + txt.SetAlignment(TextAnchor.MiddleCenter); + txt.SetLocalPosition(GetLabelXPosition(totalWidth + textWidth / 2 + gapWidth, i, xAxisIndex, xAxis)); + txt.SetText(AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, dataZoom, + isPercentStack)); + txt.SetActive(xAxis.show && (xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0)); + xAxis.axisLabelTextList.Add(txt); + totalWidth += labelWidth; } - axisName.text = xAxis.axisName.name; - } - if (m_Tooltip.runtimeGameObject) + if (xAxis.axisName.show) + { + var axisNameTextStyle = xAxis.axisName.textStyle; + var offset = axisNameTextStyle.offset; + ChartText axisName = null; + var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + m_YAxes[xAxisIndex].runtimeZeroYOffset); + switch (xAxis.axisName.location) + { + case AxisName.Location.Start: + axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(1, 0.5f), + new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), axisNameTextStyle, theme.axis); + axisName.SetAlignment(TextAnchor.MiddleRight); + axisName.SetLocalPosition(xAxis.position == Axis.AxisPosition.Top ? + new Vector2(zeroPos.x - offset.x, grid.runtimeY + grid.runtimeHeight + offset.y + xAxis.offset) : + new Vector2(zeroPos.x - offset.x, zeroPos.y + offset.y + xAxis.offset)); + break; + case AxisName.Location.Middle: + axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0.5f, 0.5f), + new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), axisNameTextStyle, theme.axis); + axisName.SetAlignment(TextAnchor.MiddleCenter); + axisName.SetLocalPosition(xAxis.position == Axis.AxisPosition.Top ? + new Vector2(grid.runtimeX + grid.runtimeWidth / 2 + offset.x, grid.runtimeY + grid.runtimeHeight - offset.y + xAxis.offset) : + new Vector2(grid.runtimeX + grid.runtimeWidth / 2 + offset.x, grid.runtimeY - offset.y + xAxis.offset)); + break; + case AxisName.Location.End: + axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0, 0.5f), + new Vector2(0, 0.5f), new Vector2(0, 0.5f), new Vector2(100, 20), axisNameTextStyle, theme.axis); + axisName.SetAlignment(TextAnchor.MiddleLeft); + axisName.SetLocalPosition(xAxis.position == Axis.AxisPosition.Top ? + new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x, grid.runtimeY + grid.runtimeHeight + offset.y + xAxis.offset) : + new Vector2(grid.runtimeX + grid.runtimeWidth + offset.x, zeroPos.y + offset.y + xAxis.offset)); + break; + } + axisName.SetText(xAxis.axisName.name); + } + if (tooltip.runtimeGameObject) + { + Vector2 privot = xAxis.position != Axis.AxisPosition.Top ? new Vector2(0.5f, 1) : new Vector2(0.5f, 1); + var labelParent = tooltip.runtimeGameObject.transform; + var labelName = ChartCached.GetAxisTooltipLabel(objName); + GameObject labelObj = ChartHelper.AddTooltipLabel(labelName, labelParent, theme, privot); + xAxis.SetTooltipLabel(labelObj); + xAxis.SetTooltipLabelColor(theme.tooltip.labelBackgroundColor, theme.tooltip.labelTextColor); + xAxis.SetTooltipLabelActive(xAxis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); + } + }; + xAxis.refreshComponent(); + } + + private void InitGrid() + { + for (int i = 0; i < m_Grids.Count; i++) { - Vector2 privot = xAxisIndex > 0 ? new Vector2(0.5f, 1) : new Vector2(0.5f, 1); - var labelParent = m_Tooltip.runtimeGameObject.transform; - GameObject labelObj = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, m_ThemeInfo.font, privot); - xAxis.SetTooltipLabel(labelObj); - xAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor); - xAxis.SetTooltipLabelActive(xAxis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss); + var grid = m_Grids[i]; + grid.index = i; + grid.painter = m_Painter; + grid.refreshComponent = delegate () + { + OnCoordinateChanged(); + }; + grid.refreshComponent(); } } private void InitDataZoom() { - var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom, transform, chartAnchorMin, - chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); - dataZoomObject.transform.localPosition = Vector3.zero; - dataZoomObject.hideFlags = chartHideFlags; - ChartHelper.HideAllObject(dataZoomObject); - var startLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "start", - dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleRight, - Vector2.zero, Vector2.zero, new Vector2(1, 0.5f), new Vector2(200, 20), m_DataZoom.fontSize, 0, m_DataZoom.fontStyle); - var endLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "end", - dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleLeft, - Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20), m_DataZoom.fontSize, 0, m_DataZoom.fontStyle); - m_DataZoom.SetStartLabel(startLabel); - m_DataZoom.SetEndLabel(endLabel); - m_DataZoom.SetLabelActive(false); - CheckRaycastTarget(); - var xAxis = m_XAxises[m_DataZoom.xAxisIndex]; - if (xAxis != null) + for (int i = 0; i < m_DataZooms.Count; i++) { - xAxis.UpdateFilterData(m_DataZoom); - } - if (m_Series != null) - { - m_Series.UpdateFilterData(m_DataZoom); + var dataZoom = m_DataZooms[i]; + dataZoom.index = i; + var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom + i, transform, graphAnchorMin, + graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); + dataZoom.gameObject = dataZoomObject; + dataZoom.painter = m_PainterTop; + dataZoom.refreshComponent = delegate () + { + if (dataZoomObject == null) return; + dataZoomObject.hideFlags = 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, + m_Theme.dataZoom); + startLabel.SetAlignment(TextAnchor.MiddleRight); + var endLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "end", dataZoomObject.transform, + Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20), dataZoom.textStyle, + m_Theme.dataZoom); + endLabel.SetAlignment(TextAnchor.MiddleLeft); + dataZoom.SetStartLabel(startLabel); + dataZoom.SetEndLabel(endLabel); + dataZoom.SetLabelActive(false); + CheckRaycastTarget(); + foreach (var index in dataZoom.xAxisIndexs) + { + var xAxis = m_XAxes[index]; + if (xAxis != null) + { + xAxis.UpdateFilterData(dataZoom); + } + } + if (m_Series != null) + { + m_Series.UpdateFilterData(dataZoom); + } + }; + dataZoom.refreshComponent(); } } private Vector3 GetLabelYPosition(float scaleWid, int i, int yAxisIndex, YAxis yAxis) { - var startX = yAxisIndex == 0 ? m_CoordinateX : m_CoordinateX + m_CoordinateWidth; + var grid = GetAxisGridOrDefault(yAxis); + var startX = yAxis.IsLeft() ? grid.runtimeX : grid.runtimeX + grid.runtimeWidth; var posX = 0f; var inside = yAxis.axisLabel.inside; - if ((inside && yAxisIndex == 0) || (!inside && yAxisIndex == 1)) + if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight())) { posX = startX + yAxis.axisLabel.margin; } @@ -751,36 +768,38 @@ namespace XCharts { posX = startX - yAxis.axisLabel.margin; } - return new Vector3(posX, m_CoordinateY + scaleWid, 0); + return new Vector3(posX, grid.runtimeY + scaleWid, 0); } private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis) { - var startY = m_CoordinateY + (xAxis.axisLabel.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0); - if (xAxisIndex > 0) startY += m_CoordinateHeight; + var grid = GetAxisGridOrDefault(xAxis); + var startY = grid.runtimeY + xAxis.offset + (xAxis.axisLabel.onZero ? m_YAxes[xAxisIndex].runtimeZeroYOffset : 0); + if (xAxis.IsTop()) startY += grid.runtimeHeight; var posY = 0f; var inside = xAxis.axisLabel.inside; - if ((inside && xAxisIndex == 0) || (!inside && xAxisIndex == 1)) + var fontSize = xAxis.axisLabel.textStyle.GetFontSize(m_Theme.axis); + if ((inside && xAxis.IsBottom()) || (!inside && xAxis.IsTop())) { - posY = startY + xAxis.axisLabel.margin + xAxis.axisLabel.fontSize / 2; + posY = startY + xAxis.axisLabel.margin + fontSize / 2; } else { - posY = startY - xAxis.axisLabel.margin - xAxis.axisLabel.fontSize / 2; + posY = startY - xAxis.axisLabel.margin - fontSize / 2; } - return new Vector3(m_CoordinateX + scaleWid, posY); + return new Vector3(grid.runtimeX + scaleWid, posY); } private void CheckMinMaxValue() { - if (m_XAxises == null || m_YAxises == null) return; - for (int i = 0; i < m_XAxises.Count; i++) + if (m_XAxes == null || m_YAxes == null) return; + for (int i = 0; i < m_XAxes.Count; i++) { - UpdateAxisMinMaxValue(i, m_XAxises[i]); + UpdateAxisMinMaxValue(i, m_XAxes[i]); } - for (int i = 0; i < m_YAxises.Count; i++) + for (int i = 0; i < m_YAxes.Count; i++) { - UpdateAxisMinMaxValue(i, m_YAxises[i]); + UpdateAxisMinMaxValue(i, m_YAxes[i]); } } @@ -789,7 +808,6 @@ namespace XCharts if (!axis.show) return; if (axis.IsCategory()) { - m_CheckMinMaxValue = true; axis.runtimeMinValue = 0; axis.runtimeMaxValue = SeriesHelper.GetMaxSerieDataCount(m_Series); return; @@ -815,7 +833,6 @@ namespace XCharts AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue) { - m_CheckMinMaxValue = true; m_IsPlayingAnimation = true; var needCheck = !m_IsPlayingAnimation && axis.runtimeLastCheckInverse == axis.inverse; axis.UpdateMinValue(tempMinValue, needCheck); @@ -825,17 +842,18 @@ namespace XCharts axis.runtimeLastCheckInverse = axis.inverse; if (tempMinValue != 0 || tempMaxValue != 0) { + var grid = GetAxisGridOrDefault(axis); if (axis is XAxis && axis.IsValue()) { axis.runtimeZeroXOffset = axis.runtimeMinValue > 0 ? 0 : - axis.runtimeMaxValue < 0 ? this.m_CoordinateWidth : - Mathf.Abs(axis.runtimeMinValue) * (this.m_CoordinateWidth / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue))); + axis.runtimeMaxValue < 0 ? grid.runtimeWidth : + Mathf.Abs(axis.runtimeMinValue) * (grid.runtimeWidth / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue))); } if (axis is YAxis && axis.IsValue()) { axis.runtimeZeroYOffset = axis.runtimeMinValue > 0 ? 0 : - axis.runtimeMaxValue < 0 ? m_CoordinateHeight : - Mathf.Abs(axis.runtimeMinValue) * (m_CoordinateHeight / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue))); + axis.runtimeMaxValue < 0 ? grid.runtimeHeight : + Mathf.Abs(axis.runtimeMinValue) * (grid.runtimeHeight / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue))); } } if (updateChart) @@ -853,16 +871,23 @@ namespace XCharts protected void UpdateAxisLabelText(Axis axis) { - float m_CoordinateWidth = axis is XAxis ? this.m_CoordinateWidth : m_CoordinateHeight; + var grid = GetAxisGridOrDefault(axis); + float runtimeWidth = axis is XAxis ? grid.runtimeWidth : grid.runtimeHeight; var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); - axis.UpdateLabelText(m_CoordinateWidth, m_DataZoom, isPercentStack, 500); + axis.UpdateLabelText(runtimeWidth, dataZoom, isPercentStack, 500); } protected virtual void OnCoordinateChanged() { UpdateCoordinate(); - m_XAxisesDirty = true; - m_YAxisesDirty = true; + for (int i = 0; i < m_XAxes.Count; i++) + { + m_XAxes[i].SetAllDirty(); + } + for (int i = 0; i < m_YAxes.Count; i++) + { + m_YAxes[i].SetAllDirty(); + } } protected override void OnSizeChanged() @@ -874,47 +899,50 @@ namespace XCharts private void DrawCoordinate(VertexHelper vh) { DrawGrid(vh); - for (int i = 0; i < m_XAxises.Count; i++) + for (int i = 0; i < m_XAxes.Count; i++) { - m_XAxises[i].index = i; - DrawXAxisSplit(vh, i, m_XAxises[i]); + m_XAxes[i].index = i; + DrawXAxisSplit(vh, i, m_XAxes[i]); } - for (int i = 0; i < m_YAxises.Count; i++) + for (int i = 0; i < m_YAxes.Count; i++) { - m_YAxises[i].index = i; - DrawYAxisSplit(vh, i, m_YAxises[i]); + m_YAxes[i].index = i; + DrawYAxisSplit(vh, i, m_YAxes[i]); } - for (int i = 0; i < m_XAxises.Count; i++) + for (int i = 0; i < m_XAxes.Count; i++) { - DrawXAxisLine(vh, i, m_XAxises[i]); + DrawXAxisLine(vh, i, m_XAxes[i]); } - for (int i = 0; i < m_YAxises.Count; i++) + for (int i = 0; i < m_YAxes.Count; i++) { - DrawYAxisLine(vh, i, m_YAxises[i]); + DrawYAxisLine(vh, i, m_YAxes[i]); } } private void DrawAxisTick(VertexHelper vh) { - for (int i = 0; i < m_XAxises.Count; i++) + for (int i = 0; i < m_XAxes.Count; i++) { - DrawXAxisTick(vh, i, m_XAxises[i]); + DrawXAxisTick(vh, i, m_XAxes[i]); } - for (int i = 0; i < m_YAxises.Count; i++) + for (int i = 0; i < m_YAxes.Count; i++) { - DrawYAxisTick(vh, i, m_YAxises[i]); + DrawYAxisTick(vh, i, m_YAxes[i]); } } private void DrawGrid(VertexHelper vh) { - if (m_Grid.show && !ChartHelper.IsClearColor(m_Grid.backgroundColor)) + foreach (var grid in m_Grids) { - var p1 = new Vector2(m_CoordinateX, m_CoordinateY); - var p2 = new Vector2(m_CoordinateX, m_CoordinateY + m_CoordinateHeight); - var p3 = new Vector2(m_CoordinateX + m_CoordinateWidth, m_CoordinateY + m_CoordinateHeight); - var p4 = new Vector2(m_CoordinateX + m_CoordinateWidth, m_CoordinateY); - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_Grid.backgroundColor); + if (grid.show && !ChartHelper.IsClearColor(grid.backgroundColor)) + { + var p1 = new Vector2(grid.runtimeX, grid.runtimeY); + var p2 = new Vector2(grid.runtimeX, grid.runtimeY + grid.runtimeHeight); + var p3 = new Vector2(grid.runtimeX + grid.runtimeWidth, grid.runtimeY + grid.runtimeHeight); + var p4 = new Vector2(grid.runtimeX + grid.runtimeWidth, grid.runtimeY); + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, grid.backgroundColor); + } } } @@ -922,13 +950,17 @@ namespace XCharts { if (AxisHelper.NeedShowSplit(yAxis)) { - var size = AxisHelper.GetScaleNumber(yAxis, m_CoordinateWidth, m_DataZoom); - var totalWidth = m_CoordinateY; - var xAxis = m_XAxises[yAxisIndex]; - var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY + yAxis.runtimeZeroYOffset); + var grid = GetAxisGridOrDefault(yAxis); + var size = AxisHelper.GetScaleNumber(yAxis, grid.runtimeWidth, dataZoom); + var totalWidth = grid.runtimeY; + var xAxis = GetRelatedXAxis(yAxis); + var zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY + yAxis.runtimeZeroYOffset); + var lineColor = yAxis.splitLine.GetColor(m_Theme.axis.splitLineColor); + var lineWidth = yAxis.splitLine.GetWidth(m_Theme.axis.lineWidth); + var lineType = yAxis.splitLine.GetType(m_Theme.axis.splitLineType); for (int i = 0; i < size; i++) { - var scaleWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i + 1, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom); float pY = totalWidth; if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel) { @@ -936,11 +968,11 @@ namespace XCharts } if (yAxis.splitArea.show && i < size - 1) { - ChartDrawer.DrawPolygon(vh, new Vector2(m_CoordinateX, pY), - new Vector2(m_CoordinateX + m_CoordinateWidth, pY), - new Vector2(m_CoordinateX + m_CoordinateWidth, pY + scaleWidth), - new Vector2(m_CoordinateX, pY + scaleWidth), - yAxis.splitArea.getColor(i)); + UGL.DrawQuadrilateral(vh, new Vector2(grid.runtimeX, pY), + new Vector2(grid.runtimeX + grid.runtimeWidth, pY), + new Vector2(grid.runtimeX + grid.runtimeWidth, pY + scaleWidth), + new Vector2(grid.runtimeX, pY + scaleWidth), + yAxis.splitArea.GetColor(i, m_Theme.axis)); } if (yAxis.splitLine.show) { @@ -948,8 +980,8 @@ namespace XCharts { if (yAxis.splitLine.NeedShow(i)) { - ChartDrawer.DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(m_CoordinateX, pY), - new Vector3(m_CoordinateX + m_CoordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo)); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, new Vector3(grid.runtimeX, pY), + new Vector3(grid.runtimeX + grid.runtimeWidth, pY), lineColor); } } } @@ -962,12 +994,12 @@ namespace XCharts { if (AxisHelper.NeedShowSplit(yAxis)) { - var size = AxisHelper.GetScaleNumber(yAxis, m_CoordinateWidth, m_DataZoom); - var totalWidth = m_CoordinateY; - var xAxis = m_XAxises[yAxisIndex]; + var grid = GetAxisGridOrDefault(yAxis); + var size = AxisHelper.GetScaleNumber(yAxis, grid.runtimeWidth, dataZoom); + var totalWidth = grid.runtimeY; for (int i = 0; i < size; i++) { - var scaleWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i + 1, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom); float pX = 0; float pY = totalWidth; if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel) @@ -976,44 +1008,45 @@ namespace XCharts } if (yAxis.axisTick.show && i > 0) { - var startX = m_CoordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0); - startX -= yAxis.axisLine.width; - if (yAxis.IsValue() && yAxisIndex > 0) startX += m_CoordinateWidth; + var startX = grid.runtimeX + GetYAxisOnZeroOffset(yAxis); + startX -= yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + if (yAxis.IsValue() && yAxis.IsRight()) startX += grid.runtimeWidth; bool inside = yAxis.axisTick.inside; - if ((inside && yAxisIndex == 0) || (!inside && yAxisIndex == 1)) + if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight())) { - pX += startX + yAxis.axisTick.length; + pX += startX + yAxis.axisTick.GetLength(m_Theme.axis.tickLength); } else { - pX += startX - yAxis.axisTick.length; + pX += startX - yAxis.axisTick.GetLength(m_Theme.axis.tickLength); } - ChartDrawer.DrawLine(vh, new Vector3(startX, pY), new Vector3(pX, pY), - AxisHelper.GetTickWidth(yAxis), m_ThemeInfo.axisLineColor); + UGL.DrawLine(vh, new Vector3(startX, pY), new Vector3(pX, pY), + yAxis.axisTick.GetWidth(m_Theme.axis.tickWidth), m_Theme.axis.tickColor); } totalWidth += scaleWidth; } } - if (yAxis.show && yAxis.axisLine.show && yAxis.axisLine.symbol) + if (yAxis.show && yAxis.axisLine.show && yAxis.axisLine.showArrow) { - var lineX = m_CoordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0); - if (yAxis.IsValue() && yAxisIndex > 0) lineX += m_CoordinateWidth; + var grid = GetAxisGridOrDefault(yAxis); + var lineX = grid.runtimeX + GetYAxisOnZeroOffset(yAxis); + if (yAxis.IsValue() && yAxis.IsRight()) lineX += grid.runtimeWidth; var inverse = yAxis.IsValue() && yAxis.inverse; + var axisArrow = yAxis.axisLine.arrow; if (inverse) { - var startPos = new Vector3(lineX, m_CoordinateY + m_CoordinateHeight); - var arrowPos = new Vector3(lineX, m_CoordinateY); - var axisLine = yAxis.axisLine; - ChartDrawer.DrawArrow(vh, startPos, arrowPos, axisLine.symbolWidth, axisLine.symbolHeight, - axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor); + var startPos = new Vector3(lineX, grid.runtimeY + grid.runtimeHeight); + var arrowPos = new Vector3(lineX, grid.runtimeY); + UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, + axisArrow.offset, axisArrow.dent, axisArrow.GetColor(m_Theme.axis.lineColor)); } else { - var startPos = new Vector3(lineX, m_CoordinateX); - var arrowPos = new Vector3(lineX, m_CoordinateY + m_CoordinateHeight + yAxis.axisLine.width); - var axisLine = yAxis.axisLine; - ChartDrawer.DrawArrow(vh, startPos, arrowPos, axisLine.symbolWidth, axisLine.symbolHeight, - axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor); + var lineWidth = yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + var startPos = new Vector3(lineX, grid.runtimeX); + var arrowPos = new Vector3(lineX, grid.runtimeY + grid.runtimeHeight + lineWidth); + UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, + axisArrow.offset, axisArrow.dent, axisArrow.GetColor(m_Theme.axis.lineColor)); } } } @@ -1022,13 +1055,17 @@ namespace XCharts { if (AxisHelper.NeedShowSplit(xAxis)) { - var size = AxisHelper.GetScaleNumber(xAxis, m_CoordinateWidth, m_DataZoom); - var totalWidth = m_CoordinateX; - var yAxis = m_YAxises[xAxisIndex]; - var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset); + var grid = GetAxisGridOrDefault(xAxis); + var size = AxisHelper.GetScaleNumber(xAxis, grid.runtimeWidth, dataZoom); + var totalWidth = grid.runtimeX; + var yAxis = m_YAxes[xAxisIndex]; + var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset); + var lineColor = xAxis.splitLine.GetColor(m_Theme.axis.splitLineColor); + var lineWidth = xAxis.splitLine.GetWidth(m_Theme.axis.lineWidth); + var lineType = xAxis.splitLine.GetType(m_Theme.axis.splitLineType); for (int i = 0; i < size; i++) { - var scaleWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i + 1, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom); float pX = totalWidth; if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel) { @@ -1036,11 +1073,11 @@ namespace XCharts } if (xAxis.splitArea.show && i < size - 1) { - ChartDrawer.DrawPolygon(vh, new Vector2(pX, m_CoordinateY), - new Vector2(pX, m_CoordinateY + m_CoordinateHeight), - new Vector2(pX + scaleWidth, m_CoordinateY + m_CoordinateHeight), - new Vector2(pX + scaleWidth, m_CoordinateY), - xAxis.splitArea.getColor(i)); + UGL.DrawQuadrilateral(vh, new Vector2(pX, grid.runtimeY), + new Vector2(pX, grid.runtimeY + grid.runtimeHeight), + new Vector2(pX + scaleWidth, grid.runtimeY + grid.runtimeHeight), + new Vector2(pX + scaleWidth, grid.runtimeY), + xAxis.splitArea.GetColor(i, m_Theme.axis)); } if (xAxis.splitLine.show) { @@ -1048,26 +1085,27 @@ namespace XCharts { if (xAxis.splitLine.NeedShow(i)) { - ChartDrawer.DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, m_CoordinateY), - new Vector3(pX, m_CoordinateY + m_CoordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo)); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, new Vector3(pX, grid.runtimeY), + new Vector3(pX, grid.runtimeY + grid.runtimeHeight), lineColor); } } } - totalWidth += AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i + 1, m_DataZoom); + totalWidth += AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom); } } } private void DrawXAxisTick(VertexHelper vh, int xAxisIndex, XAxis xAxis) { + var grid = GetAxisGridOrDefault(xAxis); if (AxisHelper.NeedShowSplit(xAxis)) { - var size = AxisHelper.GetScaleNumber(xAxis, m_CoordinateWidth, m_DataZoom); - var totalWidth = m_CoordinateX; - var yAxis = m_YAxises[xAxisIndex]; + var size = AxisHelper.GetScaleNumber(xAxis, grid.runtimeWidth, dataZoom); + var totalWidth = grid.runtimeX; + var yAxis = m_YAxes[xAxisIndex]; for (int i = 0; i < size; i++) { - var scaleWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i + 1, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom); float pX = totalWidth; float pY = 0; if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel) @@ -1076,44 +1114,44 @@ namespace XCharts } if (xAxis.axisTick.show && i > 0) { - var startY = m_CoordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0); - startY -= xAxis.axisLine.width; - if (xAxis.IsValue() && xAxisIndex > 0) startY += m_CoordinateHeight; + var startY = grid.runtimeY + xAxis.offset - xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + if (xAxis.IsTop()) startY += grid.runtimeHeight; + else startY += GetXAxisOnZeroOffset(xAxis); bool inside = xAxis.axisTick.inside; - if ((inside && xAxisIndex == 0) || (!inside && xAxisIndex == 1)) + if ((inside && xAxis.IsBottom()) || (!inside && xAxis.IsTop())) { - pY += startY + xAxis.axisTick.length; + pY += startY + xAxis.axisTick.GetLength(m_Theme.axis.tickLength); } else { - pY += startY - xAxis.axisTick.length; + pY += startY - xAxis.axisTick.GetLength(m_Theme.axis.tickLength); } - ChartDrawer.DrawLine(vh, new Vector3(pX, startY), new Vector3(pX, pY), - AxisHelper.GetTickWidth(xAxis), m_ThemeInfo.axisLineColor); + UGL.DrawLine(vh, new Vector3(pX, startY), new Vector3(pX, pY), + xAxis.axisTick.GetWidth(m_Theme.axis.tickWidth), m_Theme.axis.tickColor); } totalWidth += scaleWidth; } } - if (xAxis.show && xAxis.axisLine.show && xAxis.axisLine.symbol) + if (xAxis.show && xAxis.axisLine.show && xAxis.axisLine.showArrow) { - var lineY = m_CoordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0); - if (xAxis.IsValue() && xAxisIndex > 0) lineY += m_CoordinateHeight; + var lineY = grid.runtimeY + xAxis.offset; + if (xAxis.IsTop()) lineY += grid.runtimeHeight; + else lineY += GetXAxisOnZeroOffset(xAxis); var inverse = xAxis.IsValue() && xAxis.inverse; + var axisArrow = xAxis.axisLine.arrow; if (inverse) { - var startPos = new Vector3(m_CoordinateX + m_CoordinateWidth, lineY); - var arrowPos = new Vector3(m_CoordinateX, lineY); - var axisLine = xAxis.axisLine; - ChartDrawer.DrawArrow(vh, startPos, arrowPos, axisLine.symbolWidth, axisLine.symbolHeight, - axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor); + var startPos = new Vector3(grid.runtimeX + grid.runtimeWidth, lineY); + var arrowPos = new Vector3(grid.runtimeX, lineY); + UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, + axisArrow.offset, axisArrow.dent, axisArrow.GetColor(m_Theme.axis.lineColor)); } else { - var startPos = new Vector3(m_CoordinateX, lineY); - var arrowPos = new Vector3(m_CoordinateX + m_CoordinateWidth + xAxis.axisLine.width, lineY); - var axisLine = xAxis.axisLine; - ChartDrawer.DrawArrow(vh, startPos, arrowPos, axisLine.symbolWidth, axisLine.symbolHeight, - axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor); + var startPos = new Vector3(grid.runtimeX, lineY); + var arrowPos = new Vector3(grid.runtimeX + grid.runtimeWidth + xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth), lineY); + UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, + axisArrow.offset, axisArrow.dent, axisArrow.GetColor(m_Theme.axis.lineColor)); } } } @@ -1122,13 +1160,18 @@ namespace XCharts { if (xAxis.show && xAxis.axisLine.show) { + var grid = GetAxisGridOrDefault(xAxis); var inverse = xAxis.IsValue() && xAxis.inverse; var offset = AxisHelper.GetAxisLineSymbolOffset(xAxis); - var lineY = m_CoordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0); - if (xAxisIndex > 0) lineY += m_CoordinateHeight; - var left = new Vector3(m_CoordinateX - xAxis.axisLine.width - (inverse ? offset : 0), lineY); - var right = new Vector3(m_CoordinateX + m_CoordinateWidth + xAxis.axisLine.width + (!inverse ? offset : 0), lineY); - ChartDrawer.DrawLine(vh, left, right, xAxis.axisLine.width, m_ThemeInfo.axisLineColor); + var lineY = grid.runtimeY + xAxis.offset; + if (xAxis.IsTop()) lineY += grid.runtimeHeight; + else lineY += GetXAxisOnZeroOffset(xAxis); + var lineWidth = xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + var lineType = xAxis.axisLine.GetType(m_Theme.axis.lineType); + var lineColor = xAxis.axisLine.GetColor(m_Theme.axis.lineColor); + var left = new Vector3(grid.runtimeX - lineWidth - (inverse ? offset : 0), lineY); + var right = new Vector3(grid.runtimeX + grid.runtimeWidth + lineWidth + (!inverse ? offset : 0), lineY); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, left, right, lineColor); } } @@ -1136,35 +1179,45 @@ namespace XCharts { if (yAxis.show && yAxis.axisLine.show) { + var grid = GetAxisGridOrDefault(yAxis); var offset = AxisHelper.GetAxisLineSymbolOffset(yAxis); var inverse = yAxis.IsValue() && yAxis.inverse; - var lineX = m_CoordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0); - if (yAxisIndex > 0) lineX += m_CoordinateWidth; - var bottom = new Vector3(lineX, m_CoordinateY - yAxis.axisLine.width - (inverse ? offset : 0)); - var top = new Vector3(lineX, m_CoordinateY + m_CoordinateHeight + yAxis.axisLine.width + (!inverse ? offset : 0)); - ChartDrawer.DrawLine(vh, bottom, top, yAxis.axisLine.width, m_ThemeInfo.axisLineColor); + var lineX = grid.runtimeX + yAxis.offset; + if (yAxis.IsRight()) lineX += grid.runtimeWidth; + else lineX += GetYAxisOnZeroOffset(yAxis); + var lineWidth = yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + var lineType = yAxis.axisLine.GetType(m_Theme.axis.lineType); + var lineColor = yAxis.axisLine.GetColor(m_Theme.axis.lineColor); + var bottom = new Vector3(lineX, grid.runtimeY - lineWidth - (inverse ? offset : 0)); + var top = new Vector3(lineX, grid.runtimeY + grid.runtimeHeight + lineWidth + (!inverse ? offset : 0)); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, bottom, top, lineColor); } } private void DrawDataZoomSlider(VertexHelper vh) { - if (!m_DataZoom.enable || !m_DataZoom.supportSlider) return; - var hig = m_DataZoom.GetHeight(grid.bottom); - var p1 = new Vector3(m_CoordinateX, m_ChartY + m_DataZoom.bottom); - var p2 = new Vector3(m_CoordinateX, m_ChartY + m_DataZoom.bottom + hig); - var p3 = new Vector3(m_CoordinateX + m_CoordinateWidth, m_ChartY + m_DataZoom.bottom + hig); - var p4 = new Vector3(m_CoordinateX + m_CoordinateWidth, m_ChartY + m_DataZoom.bottom); - var xAxis = xAxises[0]; - ChartDrawer.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor); - ChartDrawer.DrawLine(vh, p2, p3, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor); - ChartDrawer.DrawLine(vh, p3, p4, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor); - ChartDrawer.DrawLine(vh, p4, p1, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor); - if (m_DataZoom.showDataShadow && m_Series.Count > 0) + if (!dataZoom.enable || !dataZoom.supportSlider) return; + var p1 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY); + var p2 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY + dataZoom.runtimeHeight); + var p3 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY + dataZoom.runtimeHeight); + var p4 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY); + var xAxis = xAxes[0]; + var lineColor = dataZoom.lineStyle.GetColor(m_Theme.dataZoom.dataLineColor); + var lineWidth = dataZoom.lineStyle.GetWidth(m_Theme.dataZoom.dataLineWidth); + var borderWidth = dataZoom.borderWidth == 0 ? m_Theme.dataZoom.borderWidth : dataZoom.borderWidth; + var borderColor = dataZoom.GetBorderColor(m_Theme.dataZoom.borderColor); + var backgroundColor = dataZoom.GetBackgroundColor(m_Theme.dataZoom.backgroundColor); + var areaColor = dataZoom.areaStyle.GetColor(m_Theme.dataZoom.dataAreaColor); + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, backgroundColor); + var centerPos = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth / 2, + dataZoom.runtimeY + dataZoom.runtimeHeight / 2); + UGL.DrawBorder(vh, centerPos, dataZoom.runtimeWidth, dataZoom.runtimeHeight, borderWidth, borderColor); + if (dataZoom.showDataShadow && m_Series.Count > 0) { Serie serie = m_Series.list[0]; - Axis axis = yAxises[0]; + Axis axis = yAxes[0]; var showData = serie.GetDataList(null); - float scaleWid = m_CoordinateWidth / (showData.Count - 1); + float scaleWid = dataZoom.runtimeWidth / (showData.Count - 1); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; float minValue = 0; @@ -1175,7 +1228,7 @@ namespace XCharts int rate = 1; var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist; var maxCount = showData.Count; - if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (m_CoordinateWidth / sampleDist)); + if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (dataZoom.runtimeWidth / sampleDist)); if (rate < 1) rate = 1; var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage : DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate); @@ -1184,22 +1237,19 @@ namespace XCharts { float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis); - float pX = m_CoordinateX + i * scaleWid; + float pX = dataZoom.runtimeX + i * scaleWid; float dataHig = (maxValue - minValue) == 0 ? 0 : - (value - minValue) / (maxValue - minValue) * hig; - np = new Vector3(pX, m_ChartY + m_DataZoom.bottom + dataHig); + (value - minValue) / (maxValue - minValue) * dataZoom.runtimeHeight; + np = new Vector3(pX, m_ChartY + dataZoom.bottom + dataHig); if (i > 0) { - var color = m_ThemeInfo.dataZoomLineColor; - ChartDrawer.DrawLine(vh, lp, np, xAxis.axisLine.width, color); - Vector3 alp = new Vector3(lp.x, lp.y - xAxis.axisLine.width); - Vector3 anp = new Vector3(np.x, np.y - xAxis.axisLine.width); + UGL.DrawLine(vh, lp, np, lineWidth, lineColor); + Vector3 alp = new Vector3(lp.x, lp.y - lineWidth); + Vector3 anp = new Vector3(np.x, np.y - lineWidth); - var areaColor = color; - areaColor.a = (byte)(areaColor.a * 0.75f); - Vector3 tnp = new Vector3(np.x, m_ChartY + m_DataZoom.bottom + xAxis.axisLine.width); - Vector3 tlp = new Vector3(lp.x, m_ChartY + m_DataZoom.bottom + xAxis.axisLine.width); - ChartDrawer.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor); + Vector3 tnp = new Vector3(np.x, m_ChartY + dataZoom.bottom + lineWidth); + Vector3 tlp = new Vector3(lp.x, m_ChartY + dataZoom.bottom + lineWidth); + UGL.DrawQuadrilateral(vh, alp, anp, tnp, tlp, areaColor); } lp = np; } @@ -1208,63 +1258,69 @@ namespace XCharts RefreshChart(); } } - switch (m_DataZoom.rangeMode) + switch (dataZoom.rangeMode) { case DataZoom.RangeMode.Percent: - var start = m_CoordinateX + m_CoordinateWidth * m_DataZoom.start / 100; - var end = m_CoordinateX + m_CoordinateWidth * m_DataZoom.end / 100; - p1 = new Vector2(start, m_ChartY + m_DataZoom.bottom); - p2 = new Vector2(start, m_ChartY + m_DataZoom.bottom + hig); - p3 = new Vector2(end, m_ChartY + m_DataZoom.bottom + hig); - p4 = new Vector2(end, m_ChartY + m_DataZoom.bottom); - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.dataZoomSelectedColor); - ChartDrawer.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomSelectedColor); - ChartDrawer.DrawLine(vh, p3, p4, xAxis.axisLine.width, m_ThemeInfo.dataZoomSelectedColor); + var start = dataZoom.runtimeX + dataZoom.runtimeWidth * dataZoom.start / 100; + var end = dataZoom.runtimeX + dataZoom.runtimeWidth * dataZoom.end / 100; + var fillerColor = dataZoom.GetFillerColor(m_Theme.dataZoom.fillerColor); + + p1 = new Vector2(start, dataZoom.runtimeY); + p2 = new Vector2(start, dataZoom.runtimeY + dataZoom.runtimeHeight); + p3 = new Vector2(end, dataZoom.runtimeY + dataZoom.runtimeHeight); + p4 = new Vector2(end, dataZoom.runtimeY); + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, fillerColor); + UGL.DrawLine(vh, p1, p2, lineWidth, fillerColor); + UGL.DrawLine(vh, p3, p4, lineWidth, fillerColor); break; } } protected void DrawXTooltipIndicator(VertexHelper vh) { - if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return; - if (m_Tooltip.type == Tooltip.Type.None) return; + if (!tooltip.show || !tooltip.IsSelected()) return; + if (tooltip.type == Tooltip.Type.None) return; + if (tooltip.runtimeGridIndex < 0) return; int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0; - for (int i = 0; i < m_XAxises.Count; i++) + var grid = GetGrid(tooltip.runtimeGridIndex); + if (grid == null) return; + var lineType = tooltip.lineStyle.GetType(m_Theme.tooltip.lineType); + var lineWidth = tooltip.lineStyle.GetWidth(m_Theme.tooltip.lineWidth); + for (int i = 0; i < m_XAxes.Count; i++) { - var xAxis = m_XAxises[i]; - var yAxis = m_YAxises[i]; + var xAxis = m_XAxes[i]; if (!xAxis.show) continue; - if (m_Tooltip.runtimeXValues[i] < 0) continue; - float splitWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom); - switch (m_Tooltip.type) + if (tooltip.runtimeXValues[i] < 0) continue; + float splitWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, dataCount, dataZoom); + switch (tooltip.type) { case Tooltip.Type.Corss: case Tooltip.Type.Line: - float pX = m_CoordinateX + m_Tooltip.runtimeXValues[i] * splitWidth + float pX = grid.runtimeX + tooltip.runtimeXValues[i] * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0); - if (xAxis.IsValue()) pX = m_Tooltip.runtimePointerPos.x; - Vector2 sp = new Vector2(pX, m_CoordinateY); - Vector2 ep = new Vector2(pX, m_CoordinateY + m_CoordinateHeight); - var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo); - ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); - if (m_Tooltip.type == Tooltip.Type.Corss) + if (xAxis.IsValue()) pX = tooltip.runtimePointerPos.x; + Vector2 sp = new Vector2(pX, grid.runtimeY); + Vector2 ep = new Vector2(pX, grid.runtimeY + grid.runtimeHeight); + var lineColor = TooltipHelper.GetLineColor(tooltip, m_Theme); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor); + if (tooltip.type == Tooltip.Type.Corss) { - sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y); - ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y); - ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + sp = new Vector2(grid.runtimeX, tooltip.runtimePointerPos.y); + ep = new Vector2(grid.runtimeX + grid.runtimeWidth, tooltip.runtimePointerPos.y); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor); } break; case Tooltip.Type.Shadow: float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth; - pX = m_CoordinateX + splitWidth * m_Tooltip.runtimeXValues[i] - + pX = grid.runtimeX + splitWidth * tooltip.runtimeXValues[i] - (xAxis.boundaryGap ? 0 : splitWidth / 2); - if (xAxis.IsValue()) pX = m_Tooltip.runtimeXValues[i]; - float pY = m_CoordinateY + m_CoordinateHeight; - Vector3 p1 = new Vector3(pX, m_CoordinateY); + if (xAxis.IsValue()) pX = tooltip.runtimeXValues[i]; + float pY = grid.runtimeY + grid.runtimeHeight; + Vector3 p1 = new Vector3(pX, grid.runtimeY); Vector3 p2 = new Vector3(pX, pY); Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY); - Vector3 p4 = new Vector3(pX + tooltipSplitWid, m_CoordinateY); - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor); + Vector3 p4 = new Vector3(pX + tooltipSplitWid, grid.runtimeY); + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, m_Theme.tooltip.areaColor); break; } } @@ -1272,42 +1328,46 @@ namespace XCharts protected void DrawYTooltipIndicator(VertexHelper vh) { - if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return; - if (m_Tooltip.type == Tooltip.Type.None) return; + if (!tooltip.show || !tooltip.IsSelected()) return; + if (tooltip.type == Tooltip.Type.None) return; + if (tooltip.runtimeGridIndex < 0) return; int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0; - for (int i = 0; i < m_YAxises.Count; i++) + var grid = GetGrid(tooltip.runtimeGridIndex); + if (grid == null) return; + var lineType = tooltip.lineStyle.GetType(m_Theme.tooltip.lineType); + var lineWidth = tooltip.lineStyle.GetWidth(m_Theme.tooltip.lineWidth); + for (int i = 0; i < m_YAxes.Count; i++) { - var yAxis = m_YAxises[i]; - var xAxis = m_XAxises[i]; + var yAxis = m_YAxes[i]; if (!yAxis.show) continue; - if (m_Tooltip.runtimeYValues[i] < 0) continue; - float splitWidth = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom); - switch (m_Tooltip.type) + if (tooltip.runtimeYValues[i] < 0) continue; + float splitWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, dataCount, dataZoom); + switch (tooltip.type) { case Tooltip.Type.Corss: case Tooltip.Type.Line: - float pY = m_CoordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0); - Vector2 sp = new Vector2(m_CoordinateX, pY); - Vector2 ep = new Vector2(m_CoordinateX + m_CoordinateWidth, pY); - var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo); - ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); - if (m_Tooltip.type == Tooltip.Type.Corss) + float pY = grid.runtimeY + tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0); + Vector2 sp = new Vector2(grid.runtimeX, pY); + Vector2 ep = new Vector2(grid.runtimeX + grid.runtimeWidth, pY); + var lineColor = TooltipHelper.GetLineColor(tooltip, m_Theme); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor); + if (tooltip.type == Tooltip.Type.Corss) { - sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y); - ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y); - ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + sp = new Vector2(grid.runtimeX, tooltip.runtimePointerPos.y); + ep = new Vector2(grid.runtimeX + grid.runtimeWidth, tooltip.runtimePointerPos.y); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor); } break; case Tooltip.Type.Shadow: float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth; - float pX = m_CoordinateX + m_CoordinateWidth; - pY = m_CoordinateY + splitWidth * m_Tooltip.runtimeYValues[i] - + float pX = grid.runtimeX + grid.runtimeWidth; + pY = grid.runtimeY + splitWidth * tooltip.runtimeYValues[i] - (yAxis.boundaryGap ? 0 : splitWidth / 2); - Vector3 p1 = new Vector3(m_CoordinateX, pY); - Vector3 p2 = new Vector3(m_CoordinateX, pY + tooltipSplitWid); + Vector3 p1 = new Vector3(grid.runtimeX, pY); + Vector3 p2 = new Vector3(grid.runtimeX, pY + tooltipSplitWid); Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid); Vector3 p4 = new Vector3(pX, pY); - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor); + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, m_Theme.tooltip.areaColor); break; } } @@ -1315,7 +1375,7 @@ namespace XCharts private void CheckRaycastTarget() { - var ray = m_DataZoom.enable || (m_VisualMap.enable && m_VisualMap.show && m_VisualMap.calculable); + var ray = dataZoom.enable || (visualMap.enable && visualMap.show && visualMap.calculable); if (raycastTarget != ray) { raycastTarget = ray; @@ -1324,7 +1384,7 @@ namespace XCharts private void CheckDataZoom() { - if (!m_DataZoom.enable) return; + if (!dataZoom.enable) return; CheckDataZoomScale(); CheckDataZoomLabel(); } @@ -1335,7 +1395,7 @@ namespace XCharts private Vector2 m_LastTouchPos1; private void CheckDataZoomScale() { - if (!m_DataZoom.enable || m_DataZoom.zoomLock || !m_DataZoom.supportInside) return; + if (!dataZoom.enable || dataZoom.zoomLock || !dataZoom.supportInside) return; if (Input.touchCount == 2) { @@ -1353,7 +1413,7 @@ namespace XCharts var currDist = Vector2.Distance(tempPos0, tempPos1); var lastDist = Vector2.Distance(m_LastTouchPos0, m_LastTouchPos1); var delta = (currDist - lastDist); - ScaleDataZoom(delta / m_DataZoom.scrollSensitivity); + ScaleDataZoom(delta / dataZoom.scrollSensitivity); m_LastTouchPos0 = tempPos0; m_LastTouchPos1 = tempPos1; } @@ -1362,61 +1422,65 @@ namespace XCharts private void CheckDataZoomLabel() { - if (m_DataZoom.supportSlider && m_DataZoom.showDetail) + if (dataZoom.supportSlider && dataZoom.showDetail) { Vector2 local; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, canvas.worldCamera, out local)) { - m_DataZoom.SetLabelActive(false); + foreach (var datazoom in m_DataZooms) datazoom.SetLabelActive(false); return; } - if (m_DataZoom.IsInSelectedZoom(local, m_CoordinateX, chartY, m_CoordinateWidth) - || m_DataZoom.IsInStartZoom(local, m_CoordinateX, chartY, m_CoordinateWidth) - || m_DataZoom.IsInEndZoom(local, m_CoordinateX, chartY, m_CoordinateWidth)) + foreach (var dataZoom in m_DataZooms) { - m_DataZoom.SetLabelActive(true); - RefreshDataZoomLabel(); - } - else - { - - m_DataZoom.SetLabelActive(false); + if (dataZoom.IsInSelectedZoom(local) + || dataZoom.IsInStartZoom(local) + || dataZoom.IsInEndZoom(local)) + { + dataZoom.SetLabelActive(true); + RefreshDataZoomLabel(); + } + else + { + dataZoom.SetLabelActive(false); + } } } if (m_CheckDataZoomLabel) { m_CheckDataZoomLabel = false; - var xAxis = m_XAxises[m_DataZoom.xAxisIndex]; - var startIndex = (int)((xAxis.data.Count - 1) * m_DataZoom.start / 100); - var endIndex = (int)((xAxis.data.Count - 1) * m_DataZoom.end / 100); + var xAxis = m_XAxes[dataZoom.xAxisIndexs[0]]; + var startIndex = (int)((xAxis.data.Count - 1) * dataZoom.start / 100); + var endIndex = (int)((xAxis.data.Count - 1) * dataZoom.end / 100); if (m_DataZoomLastStartIndex != startIndex || m_DataZoomLastEndIndex != endIndex) { m_DataZoomLastStartIndex = startIndex; m_DataZoomLastEndIndex = endIndex; if (xAxis.data.Count > 0) { - m_DataZoom.SetStartLabelText(xAxis.data[startIndex]); - m_DataZoom.SetEndLabelText(xAxis.data[endIndex]); + dataZoom.SetStartLabelText(xAxis.data[startIndex]); + dataZoom.SetEndLabelText(xAxis.data[endIndex]); } InitAxisX(); } - var start = m_CoordinateX + m_CoordinateWidth * m_DataZoom.start / 100; - var end = m_CoordinateX + m_CoordinateWidth * m_DataZoom.end / 100; - var hig = m_DataZoom.GetHeight(grid.bottom); - m_DataZoom.UpdateStartLabelPosition(new Vector3(start - 10, chartY + m_DataZoom.bottom + hig / 2)); - m_DataZoom.UpdateEndLabelPosition(new Vector3(end + 10, chartY + m_DataZoom.bottom + hig / 2)); + var start = dataZoom.runtimeX + dataZoom.runtimeWidth * dataZoom.start / 100; + var end = dataZoom.runtimeX + dataZoom.runtimeWidth * dataZoom.end / 100; + var hig = dataZoom.runtimeHeight; + dataZoom.UpdateStartLabelPosition(new Vector3(start - 10, chartY + dataZoom.bottom + hig / 2)); + dataZoom.UpdateEndLabelPosition(new Vector3(end + 10, chartY + dataZoom.bottom + hig / 2)); } } protected void DrawLabelBackground(VertexHelper vh) { - var isYAxis = m_YAxises[0].type == Axis.AxisType.Category - || m_YAxises[1].type == Axis.AxisType.Category; + var isYAxis = m_YAxes[0].type == Axis.AxisType.Category + || m_YAxes[1].type == Axis.AxisType.Category; for (int n = 0; n < m_Series.Count; n++) { var serie = m_Series.GetSerie(n); if (!serie.show) continue; + if (serie.IsPerformanceMode()) continue; + if (!serie.IsCoordinateSerie()) continue; for (int j = 0; j < serie.data.Count; j++) { @@ -1449,13 +1513,15 @@ namespace XCharts { if (isYAxis) { - var xAxis = m_XAxises[serie.axisIndex]; - zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY); + var xAxis = m_XAxes[serie.xAxisIndex]; + var grid = GetAxisGridOrDefault(xAxis); + zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY); } else { - var yAxis = m_YAxises[serie.axisIndex]; - zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset); + var yAxis = m_YAxes[serie.yAxisIndex]; + var grid = GetAxisGridOrDefault(yAxis); + zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset); } } } @@ -1488,11 +1554,13 @@ namespace XCharts protected override void OnRefreshLabel() { + base.OnRefreshLabel(); var anyPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); for (int i = 0; i < m_Series.Count; i++) { var serie = m_Series.GetSerie(i); if (serie.IsPerformanceMode()) continue; + if (!serie.IsCoordinateSerie()) continue; var total = serie.yTotal; var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); for (int j = 0; j < serie.data.Count; j++) @@ -1516,10 +1584,10 @@ namespace XCharts if (serie.type == SerieType.Heatmap) { - dimension = VisualMapHelper.GetDimension(m_VisualMap, serieData.data.Count); + dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count); } - SerieLabelHelper.ResetLabel(serieData, serieLabel, themeInfo, i); + SerieLabelHelper.ResetLabel(serieData, serieLabel, theme, i); value = serieData.data[dimension]; var content = ""; @@ -1558,24 +1626,25 @@ namespace XCharts { return; } - if (m_DataZoom.supportInside) + var grid = GetDataZoomGridOrDefault(dataZoom); + if (dataZoom.supportInside) { - if (IsInCooridate(pos)) + if (IsInGrid(grid, pos)) { m_DataZoomCoordinateDrag = true; } } - if (m_DataZoom.supportSlider) + if (dataZoom.supportSlider) { - if (m_DataZoom.IsInStartZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth)) + if (dataZoom.IsInStartZoom(pos)) { m_DataZoomStartDrag = true; } - else if (m_DataZoom.IsInEndZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth)) + else if (dataZoom.IsInEndZoom(pos)) { m_DataZoomEndDrag = true; } - else if (m_DataZoom.IsInSelectedZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth)) + else if (dataZoom.IsInSelectedZoom(pos)) { m_DataZoomDrag = true; } @@ -1587,8 +1656,9 @@ namespace XCharts { base.OnDrag(eventData); if (Input.touchCount > 1) return; + var grid = GetDataZoomGridOrDefault(dataZoom); float deltaX = eventData.delta.x; - float deltaPercent = deltaX / m_CoordinateWidth * 100; + float deltaPercent = deltaX / grid.runtimeWidth * 100; OnDragInside(deltaPercent); OnDragSlider(deltaPercent); OnDragVisualMap(); @@ -1597,18 +1667,18 @@ namespace XCharts private void OnDragInside(float deltaPercent) { if (Input.touchCount > 1) return; - if (!m_DataZoom.supportInside) return; + if (!dataZoom.supportInside) return; if (!m_DataZoomCoordinateDrag) return; - var diff = m_DataZoom.end - m_DataZoom.start; + var diff = dataZoom.end - dataZoom.start; if (deltaPercent > 0) { - m_DataZoom.start -= deltaPercent; - m_DataZoom.end = m_DataZoom.start + diff; + dataZoom.start -= deltaPercent; + dataZoom.end = dataZoom.start + diff; } else { - m_DataZoom.end += -deltaPercent; - m_DataZoom.start = m_DataZoom.end - diff; + dataZoom.end += -deltaPercent; + dataZoom.start = dataZoom.end - diff; } RefreshDataZoomLabel(); RefreshChart(); @@ -1617,17 +1687,17 @@ namespace XCharts private void OnDragSlider(float deltaPercent) { if (Input.touchCount > 1) return; - if (!m_DataZoom.supportSlider) return; + if (!dataZoom.supportSlider) return; if (m_DataZoomStartDrag) { - m_DataZoom.start += deltaPercent; - if (m_DataZoom.start > m_DataZoom.end) + dataZoom.start += deltaPercent; + if (dataZoom.start > dataZoom.end) { - m_DataZoom.start = m_DataZoom.end; + dataZoom.start = dataZoom.end; m_DataZoomEndDrag = true; m_DataZoomStartDrag = false; } - if (m_DataZoom.realtime) + if (dataZoom.realtime) { RefreshDataZoomLabel(); RefreshChart(); @@ -1635,14 +1705,14 @@ namespace XCharts } else if (m_DataZoomEndDrag) { - m_DataZoom.end += deltaPercent; - if (m_DataZoom.end < m_DataZoom.start) + dataZoom.end += deltaPercent; + if (dataZoom.end < dataZoom.start) { - m_DataZoom.end = m_DataZoom.start; + dataZoom.end = dataZoom.start; m_DataZoomStartDrag = true; m_DataZoomEndDrag = false; } - if (m_DataZoom.realtime) + if (dataZoom.realtime) { RefreshDataZoomLabel(); RefreshChart(); @@ -1652,21 +1722,21 @@ namespace XCharts { if (deltaPercent > 0) { - if (m_DataZoom.end + deltaPercent > 100) + if (dataZoom.end + deltaPercent > 100) { - deltaPercent = 100 - m_DataZoom.end; + deltaPercent = 100 - dataZoom.end; } } else { - if (m_DataZoom.start + deltaPercent < 0) + if (dataZoom.start + deltaPercent < 0) { - deltaPercent = -m_DataZoom.start; + deltaPercent = -dataZoom.start; } } - m_DataZoom.start += deltaPercent; - m_DataZoom.end += deltaPercent; - if (m_DataZoom.realtime) + dataZoom.start += deltaPercent; + dataZoom.end += deltaPercent; + if (dataZoom.realtime) { RefreshDataZoomLabel(); RefreshChart(); @@ -1703,31 +1773,31 @@ namespace XCharts { return; } - - if (m_DataZoom.IsInStartZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth) || - m_DataZoom.IsInEndZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth)) + var grid = GetDataZoomGridOrDefault(dataZoom); + if (dataZoom.IsInStartZoom(localPos) || + dataZoom.IsInEndZoom(localPos)) { return; } - if (m_DataZoom.IsInZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth) - && !m_DataZoom.IsInSelectedZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth)) + if (dataZoom.IsInZoom(localPos) + && !dataZoom.IsInSelectedZoom(localPos)) { var pointerX = localPos.x; - var selectWidth = m_CoordinateWidth * (m_DataZoom.end - m_DataZoom.start) / 100; + var selectWidth = grid.runtimeWidth * (dataZoom.end - dataZoom.start) / 100; var startX = pointerX - selectWidth / 2; var endX = pointerX + selectWidth / 2; - if (startX < m_CoordinateX) + if (startX < grid.runtimeX) { - startX = m_CoordinateX; - endX = m_CoordinateX + selectWidth; + startX = grid.runtimeX; + endX = grid.runtimeX + selectWidth; } - else if (endX > m_CoordinateX + m_CoordinateWidth) + else if (endX > grid.runtimeX + grid.runtimeWidth) { - endX = m_CoordinateX + m_CoordinateWidth; - startX = m_CoordinateX + m_CoordinateWidth - selectWidth; + endX = grid.runtimeX + grid.runtimeWidth; + startX = grid.runtimeX + grid.runtimeWidth - selectWidth; } - m_DataZoom.start = (startX - m_CoordinateX) / m_CoordinateWidth * 100; - m_DataZoom.end = (endX - m_CoordinateX) / m_CoordinateWidth * 100; + dataZoom.start = (startX - grid.runtimeX) / grid.runtimeWidth * 100; + dataZoom.end = (endX - grid.runtimeX) / grid.runtimeWidth * 100; RefreshDataZoomLabel(); RefreshChart(); } @@ -1737,60 +1807,62 @@ namespace XCharts { base.OnScroll(eventData); if (Input.touchCount > 1) return; - if (!m_DataZoom.enable || m_DataZoom.zoomLock) return; + if (!dataZoom.enable || dataZoom.zoomLock) return; Vector2 pos; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, eventData.position, canvas.worldCamera, out pos)) { return; } - if (!IsInCooridate(pos) && !m_DataZoom.IsInSelectedZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth)) + var grid = GetDataZoomGridOrDefault(dataZoom); + if (!IsInGrid(grid, pos) && !dataZoom.IsInSelectedZoom(pos)) { return; } - ScaleDataZoom(eventData.scrollDelta.y * m_DataZoom.scrollSensitivity); + ScaleDataZoom(eventData.scrollDelta.y * dataZoom.scrollSensitivity); } private void ScaleDataZoom(float delta) { - float deltaPercent = Mathf.Abs(delta / m_CoordinateWidth * 100); + var grid = GetDataZoomGridOrDefault(dataZoom); + float deltaPercent = Mathf.Abs(delta / grid.runtimeWidth * 100); if (delta > 0) { - if (m_DataZoom.end <= m_DataZoom.start) return; - m_DataZoom.end -= deltaPercent; - m_DataZoom.start += deltaPercent; - if (m_DataZoom.end <= m_DataZoom.start) + if (dataZoom.end <= dataZoom.start) return; + dataZoom.end -= deltaPercent; + dataZoom.start += deltaPercent; + if (dataZoom.end <= dataZoom.start) { - m_DataZoom.end = m_DataZoom.start; + dataZoom.end = dataZoom.start; } } else { - m_DataZoom.end += deltaPercent; - m_DataZoom.start -= deltaPercent; - if (m_DataZoom.end > 100) m_DataZoom.end = 100; - if (m_DataZoom.start < 0) m_DataZoom.start = 0; + dataZoom.end += deltaPercent; + dataZoom.start -= deltaPercent; + if (dataZoom.end > 100) dataZoom.end = 100; + if (dataZoom.start < 0) dataZoom.start = 0; } RefreshDataZoomLabel(); RefreshChart(); } protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, - Color32 color, bool clip) + Color32 color, bool clip, Grid grid) { - CheckClipAndDrawPolygon(vh, p1, p2, p3, p4, color, color, clip); + CheckClipAndDrawPolygon(vh, p1, p2, p3, p4, color, color, clip, grid); } protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color, - bool clip, bool vertical = true) + bool clip, bool vertical, Grid grid) { if (!IsInChart(p)) return; - if (!clip || (clip && (IsInCooridate(p)))) - ChartDrawer.DrawPolygon(vh, p, radius, color, vertical); + if (!clip || (clip && (IsInGrid(grid, p)))) + UGL.DrawSquare(vh, p, radius, color); } protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, - Color32 startColor, Color32 toColor, bool clip) + Color32 startColor, Color32 toColor, bool clip, Grid grid) { ClampInChart(ref p1); ClampInChart(ref p2); @@ -1798,17 +1870,17 @@ namespace XCharts ClampInChart(ref p4); if (clip) { - p1 = ClampInCoordinate(p1); - p2 = ClampInCoordinate(p2); - p3 = ClampInCoordinate(p3); - p4 = ClampInCoordinate(p4); + p1 = ClampInGrid(grid, p1); + p2 = ClampInGrid(grid, p2); + p3 = ClampInGrid(grid, p3); + p4 = ClampInGrid(grid, p4); } - if (!clip || (clip && (IsInCooridate(p1) && IsInCooridate(p2) && IsInCooridate(p3) && IsInCooridate(p4)))) - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor); + if (!clip || (clip && (IsInGrid(grid, p1) && IsInGrid(grid, p2) && IsInGrid(grid, p3) && IsInGrid(grid, p4)))) + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, startColor, toColor); } protected void CheckClipAndDrawPolygon(VertexHelper vh, ref Vector3 p1, ref Vector3 p2, ref Vector3 p3, ref Vector3 p4, - Color32 startColor, Color32 toColor, bool clip) + Color32 startColor, Color32 toColor, bool clip, Grid grid) { ClampInChart(ref p1); ClampInChart(ref p2); @@ -1816,63 +1888,182 @@ namespace XCharts ClampInChart(ref p4); if (clip) { - p1 = ClampInCoordinate(p1); - p2 = ClampInCoordinate(p2); - p3 = ClampInCoordinate(p3); - p4 = ClampInCoordinate(p4); + p1 = ClampInGrid(grid, p1); + p2 = ClampInGrid(grid, p2); + p3 = ClampInGrid(grid, p3); + p4 = ClampInGrid(grid, p4); } - if (!clip || (clip && (IsInCooridate(p1) && IsInCooridate(p2) && IsInCooridate(p3) && IsInCooridate(p4)))) - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor); + if (!clip + || (clip && (IsInGrid(grid, p1) && IsInGrid(grid, p2) && IsInGrid(grid, p3) && IsInGrid(grid, p4)))) + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, startColor, toColor); } - protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, - Color32 color, bool clip) + protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color, + bool clip, Grid grid) { - CheckClipAndDrawTriangle(vh, p1, p2, p3, color, color, color, clip); + CheckClipAndDrawTriangle(vh, p1, p2, p3, color, color, color, clip, grid); } - protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, - Vector3 p2, Vector3 p3, Color32 color, Color32 color2, Color32 color3, bool clip) + protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color, + Color32 color2, Color32 color3, bool clip, Grid grid) { if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3)) return; - if (!clip || (clip && (IsInCooridate(p1) || IsInCooridate(p2) || IsInCooridate(p3)))) - ChartDrawer.DrawTriangle(vh, p1, p2, p3, color, color2, color3); + if (!clip || (clip && (IsInGrid(grid, p1) || IsInGrid(grid, p2) || IsInGrid(grid, p3)))) + UGL.DrawTriangle(vh, p1, p2, p3, color, color2, color3); } - protected void CheckClipAndDrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, - Color32 color, bool clip) + protected void CheckClipAndDrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color, + bool clip, Grid grid) { if (!IsInChart(p1) || !IsInChart(p2)) return; - if (!clip || (clip && (IsInCooridate(p1) || IsInCooridate(p2)))) - ChartDrawer.DrawLine(vh, p1, p2, size, color); + if (!clip || (clip && (IsInGrid(grid, p1) || IsInGrid(grid, p2)))) + UGL.DrawLine(vh, p1, p2, size, color); } - protected void CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, - float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, bool clip, float[] cornerRadius) + protected void CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness, + Vector3 pos, Color32 color, Color32 toColor, float gap, bool clip, float[] cornerRadius, Grid grid) { if (!IsInChart(pos)) return; - if (!clip || (clip && (IsInCooridate(pos)))) + if (!clip || (clip && (IsInGrid(grid, pos)))) DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap, cornerRadius); } - protected void CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, - float zebraWidth, float zebraGap, Color32 color, bool clip) + protected void CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth, + float zebraGap, Color32 color, bool clip, Grid grid) { ClampInChart(ref p1); ClampInChart(ref p2); - ChartDrawer.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color); + UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color); } - protected Color32 GetXLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos) + protected Color32 GetXLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos, Grid grid) { if (ChartHelper.IsValueEqualsColor(areaColor, areaToColor)) return areaColor; - return Color32.Lerp(areaToColor, areaColor, (pos.y - m_CoordinateY) / m_CoordinateHeight); + return Color32.Lerp(areaToColor, areaColor, (pos.y - grid.runtimeY) / grid.runtimeHeight); } - protected Color32 GetYLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos) + protected Color32 GetYLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos, Grid grid) { if (ChartHelper.IsValueEqualsColor(areaColor, areaToColor)) return areaColor; - return Color32.Lerp(areaToColor, areaColor, (pos.x - m_CoordinateX) / m_CoordinateWidth); + return Color32.Lerp(areaToColor, areaColor, (pos.x - grid.runtimeX) / grid.runtimeWidth); + } + + internal Grid GetAxisGridOrDefault(Axis axis) + { + var index = axis.gridIndex; + if (index >= 0 && index < m_Grids.Count) + { + return m_Grids[index]; + } + else if (m_Grids.Count > 0) + { + return m_Grids[0]; + } + else + { + return null; + } + } + + protected Grid GetDataZoomGridOrDefault(DataZoom dataZoom) + { + var xAxis = GetXAxis(dataZoom.xAxisIndexs[0]); + Grid grid = GetGrid(xAxis.gridIndex); + if (grid == null) return m_Grids[0]; + else return grid; + } + + protected Grid GetSerieGridOrDefault(Serie serie) + { + var xAxis = GetSerieXAxisOrDefault(serie); + var yAxis = GetSerieYAxisOrDefault(serie); + Grid grid = GetGrid(xAxis.gridIndex); + if (xAxis.gridIndex != yAxis.gridIndex) + { + Debug.LogErrorFormat("serie {0}:{1} xAxisIndex:{2} and yAxisIndex:{3} not in the same grid.", + serie.index, serie.name, serie.xAxisIndex, serie.yAxisIndex); + } + if (grid == null) + { + grid = m_Grids[0]; + grid.index = 0; + } + else + { + grid.index = xAxis.gridIndex; + } + return grid; + } + + protected XAxis GetSerieXAxisOrDefault(Serie serie) + { + var axis = GetXAxis(serie.xAxisIndex); + if (axis == null) + { + Debug.LogErrorFormat("serie {0}:{1} xAxisIndex:{2} not exist.", serie.index, serie.name, serie.xAxisIndex); + axis = m_XAxes[0]; + } + return axis; + } + + protected YAxis GetSerieYAxisOrDefault(Serie serie) + { + var axis = GetYAxis(serie.yAxisIndex); + if (axis == null) + { + Debug.LogErrorFormat("serie {0}:{1} yAxisIndex:{2} not exist.", serie.index, serie.name, serie.xAxisIndex); + return m_YAxes[0]; + } + return axis; + } + + protected void UpdateSerieGridIndex() + { + for (int i = 0; i < m_Series.Count; i++) + { + var serie = m_Series.GetSerie(i); + serie.index = i; + var grid = GetSerieGridOrDefault(serie); + serie.runtimeGridIndex = grid.index; + } + } + + private float GetXAxisOnZeroOffset(XAxis axis) + { + if (!axis.axisLine.onZero) return 0; + foreach (var yAxis in m_YAxes) + { + if (yAxis.IsValue() && yAxis.gridIndex == axis.gridIndex) return yAxis.runtimeZeroYOffset; + } + return 0; + } + + private float GetYAxisOnZeroOffset(YAxis axis) + { + if (!axis.axisLine.onZero) return 0; + foreach (var xAxis in m_XAxes) + { + if (xAxis.IsValue() && xAxis.gridIndex == axis.gridIndex) return xAxis.runtimeZeroYOffset; + } + return 0; + } + + private YAxis GetRelatedYAxis(XAxis axis) + { + foreach (var yAxis in m_YAxes) + { + if (yAxis.gridIndex == axis.gridIndex) return yAxis; + } + return m_YAxes[0]; + } + + private XAxis GetRelatedXAxis(YAxis axis) + { + foreach (var xAxis in m_XAxes) + { + if (xAxis.gridIndex == axis.gridIndex) return xAxis; + } + return m_XAxes[0]; } } } diff --git a/Runtime/Internal/CoordinateChart_DrawBar.cs b/Runtime/Internal/CoordinateChart_DrawBar.cs index 94b8974e..5defaeb0 100644 --- a/Runtime/Internal/CoordinateChart_DrawBar.cs +++ b/Runtime/Internal/CoordinateChart_DrawBar.cs @@ -1,48 +1,45 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ +using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.EventSystems; using UnityEngine.UI; +using XUGL; namespace XCharts { public partial class CoordinateChart { - protected float m_BarLastOffset = 0; + protected Action<PointerEventData, int> m_OnPointerClickBar; - protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) + protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex) { if (!IsActive(serie.name)) return; if (serie.animation.HasFadeOut()) return; - var xAxis = m_XAxises[serie.axisIndex]; - var yAxis = m_YAxises[serie.axisIndex]; - if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count]; - - var showData = serie.GetDataList(m_DataZoom); - float categoryWidth = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, showData.Count, m_DataZoom); + var xAxis = m_XAxes[serie.xAxisIndex]; + var yAxis = m_YAxes[serie.yAxisIndex]; + var grid = GetSerieGridOrDefault(serie); + var showData = serie.GetDataList(dataZoom); + float categoryWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom); float barGap = GetBarGap(); float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap); float barWidth = serie.GetBarWidth(categoryWidth); float offset = (categoryWidth - totalBarWidth) / 2; float barGapWidth = barWidth + barWidth * barGap; - float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset; - + float space = serie.barGap == -1 ? offset : offset + GetBarIndex(serie) * barGapWidth; + var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar); + m_StackSerieData.Clear(); + if (isStack) SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData); int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; - if (seriesHig.Count < serie.minShow) - { - for (int i = 0; i < serie.minShow; i++) - { - seriesHig.Add(0); - } - } var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); @@ -51,17 +48,13 @@ namespace XCharts var isAllBarEnd = true; for (int i = serie.minShow; i < maxCount; i++) { - if (i >= seriesHig.Count) - { - seriesHig.Add(0); - } var serieData = showData[i]; if (serie.IsIgnoreValue(serieData.GetData(1))) { serie.dataPoints.Add(Vector3.zero); continue; } - var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) + var highlight = (tooltip.show && tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); @@ -70,28 +63,34 @@ namespace XCharts float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue); float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth; if (showData[i].IsDataChanged()) dataChanging = true; - float axisLineWidth = (value < 0 ? -1 : 1) * yAxis.axisLine.width; - float pX = seriesHig[i] + m_CoordinateX + xAxis.runtimeZeroXOffset + axisLineWidth; - float pY = m_CoordinateY + i * categoryWidth; + float axisLineWidth = (value < 0 ? -1 : 1) * yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + + float pY = grid.runtimeY + i * categoryWidth; if (!yAxis.boundaryGap) pY -= categoryWidth / 2; + float pX = grid.runtimeX + xAxis.runtimeZeroXOffset + axisLineWidth; + if (isStack) + { + for (int n = 0; n < m_StackSerieData.Count - 1; n++) + { + pX += m_StackSerieData[n][i].runtimeStackHig; + } + } var barHig = 0f; var valueTotal = 0f; if (isPercentStack) { valueTotal = GetSameStackTotalValue(serie.stack, i); - barHig = valueTotal != 0 ? (value / valueTotal * m_CoordinateWidth) : 0; - seriesHig[i] += barHig; + barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0; } else { valueTotal = xMaxValue - xMinValue; if (valueTotal != 0) barHig = (xMinValue > 0 ? value - xMinValue : value) - / valueTotal * m_CoordinateWidth; - seriesHig[i] += barHig; + / valueTotal * grid.runtimeWidth; } - + serieData.runtimeStackHig = barHig; var isBarEnd = false; float currHig = CheckAnimation(serie, i, barHig, out isBarEnd); if (!isBarEnd) isAllBarEnd = false; @@ -111,11 +110,11 @@ namespace XCharts plb = new Vector3(pX + borderWidth, pY + space + borderWidth); } top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2); - plt = ClampInCoordinate(plt); - prt = ClampInCoordinate(prt); - prb = ClampInCoordinate(prb); - plb = ClampInCoordinate(plb); - top = ClampInCoordinate(top); + plt = ClampInGrid(grid, plt); + prt = ClampInGrid(grid, prt); + prb = ClampInGrid(grid, prb); + plb = ClampInGrid(grid, plb); + top = ClampInGrid(grid, top); serie.dataPoints.Add(top); if (serie.show) { @@ -123,27 +122,23 @@ namespace XCharts { case BarType.Normal: DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, true); + pX, pY, plb, plt, prt, prb, true, grid); break; case BarType.Zebra: DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, true); + pX, pY, plb, plt, prt, prb, true, grid); break; case BarType.Capsule: DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, true); + pX, pY, plb, plt, prt, prb, true, grid); break; } } } if (isAllBarEnd) serie.animation.AllBarEnd(); - if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar)) - { - m_BarLastOffset += barGapWidth; - } if (dataChanging) { - RefreshChart(); + RefreshPainter(serie); } } @@ -152,40 +147,34 @@ namespace XCharts float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount, out isBarEnd); if (!serie.animation.IsFinish()) { - RefreshChart(); + RefreshPainter(serie); m_IsPlayingAnimation = true; } return currHig; } - protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) + protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex) { if (!IsActive(serie.index)) return; if (serie.animation.HasFadeOut()) return; - var showData = serie.GetDataList(m_DataZoom); - var yAxis = m_YAxises[serie.axisIndex]; - var xAxis = m_XAxises[serie.axisIndex]; - if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count]; - - float categoryWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom); + var showData = serie.GetDataList(dataZoom); + var yAxis = m_YAxes[serie.yAxisIndex]; + var xAxis = m_XAxes[serie.xAxisIndex]; + var grid = GetSerieGridOrDefault(serie); + var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar); + m_StackSerieData.Clear(); + if (isStack) SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData); + float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom); float barGap = GetBarGap(); float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap); float barWidth = serie.GetBarWidth(categoryWidth); float offset = (categoryWidth - totalBarWidth) / 2; float barGapWidth = barWidth + barWidth * barGap; - float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset; - int maxCount = serie.maxShow > 0 ? - (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) + float space = serie.barGap == -1 ? offset : offset + GetBarIndex(serie) * barGapWidth; + int maxCount = serie.maxShow > 0 + ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; - if (seriesHig.Count < serie.minShow) - { - for (int i = 0; i < serie.minShow; i++) - { - seriesHig.Add(0); - } - } - var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); @@ -194,45 +183,48 @@ namespace XCharts var isAllBarEnd = true; for (int i = serie.minShow; i < maxCount; i++) { - if (i >= seriesHig.Count) - { - seriesHig.Add(0); - } var serieData = showData[i]; if (serie.IsIgnoreValue(serieData.GetData(1))) { serie.dataPoints.Add(Vector3.zero); continue; } - var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) + var highlight = (tooltip.show && tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); float value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth; if (serieData.IsDataChanged()) dataChanging = true; - float pX = m_CoordinateX + i * categoryWidth; - float zeroY = m_CoordinateY + yAxis.runtimeZeroYOffset; + float pX = grid.runtimeX + i * categoryWidth; + float zeroY = grid.runtimeY + yAxis.runtimeZeroYOffset; if (!xAxis.boundaryGap) pX -= categoryWidth / 2; - float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.width; - float pY = seriesHig[i] + zeroY + axisLineWidth; + float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + float pY = zeroY + axisLineWidth; + if (isStack) + { + for (int n = 0; n < m_StackSerieData.Count - 1; n++) + { + pY += m_StackSerieData[n][i].runtimeStackHig; + } + } var barHig = 0f; var valueTotal = 0f; if (isPercentStack) { valueTotal = GetSameStackTotalValue(serie.stack, i); - barHig = valueTotal != 0 ? (value / valueTotal * m_CoordinateHeight) : 0; - seriesHig[i] += barHig; + barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeHeight) : 0; } else { valueTotal = yMaxValue - yMinValue; if (valueTotal != 0) - barHig = (yMinValue > 0 ? value - yMinValue : value) - / valueTotal * m_CoordinateHeight; - seriesHig[i] += barHig; + { + barHig = (yMinValue > 0 ? value - yMinValue : value) / valueTotal * grid.runtimeHeight; + } } + serieData.runtimeStackHig = barHig; var isBarEnd = false; float currHig = CheckAnimation(serie, i, barHig, out isBarEnd); if (!isBarEnd) isAllBarEnd = false; @@ -254,11 +246,11 @@ namespace XCharts top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); if (serie.clip) { - plb = ClampInCoordinate(plb); - plt = ClampInCoordinate(plt); - prt = ClampInCoordinate(prt); - prb = ClampInCoordinate(prb); - top = ClampInCoordinate(top); + plb = ClampInGrid(grid, plb); + plt = ClampInGrid(grid, plt); + prt = ClampInGrid(grid, prt); + prb = ClampInGrid(grid, prb); + top = ClampInGrid(grid, top); } serie.dataPoints.Add(top); if (serie.show && currHig != 0) @@ -267,15 +259,15 @@ namespace XCharts { case BarType.Normal: DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, false); + pX, pY, plb, plt, prt, prb, false, grid); break; case BarType.Zebra: DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, false); + pX, pY, plb, plt, prt, prb, false, grid); break; case BarType.Capsule: DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, false); + pX, pY, plb, plt, prt, prb, false, grid); break; } } @@ -286,30 +278,26 @@ namespace XCharts } if (dataChanging) { - RefreshChart(); - } - if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar)) - { - m_BarLastOffset += barGapWidth; + RefreshPainter(serie); } } private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, - Vector3 prb, bool isYAxis) + Vector3 prb, bool isYAxis, Grid grid) { - var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); - var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis); + var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight); + var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight); + DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid); var borderWidth = itemStyle.runtimeBorderWidth; if (isYAxis) { if (serie.clip) { - prb = ClampInCoordinate(prb); - plb = ClampInCoordinate(plb); - plt = ClampInCoordinate(plt); - prt = ClampInCoordinate(prt); + prb = ClampInGrid(grid, prb); + plb = ClampInGrid(grid, plb); + plt = ClampInGrid(grid, plt); + prt = ClampInGrid(grid, prt); } var borderColor = itemStyle.borderColor; var itemWidth = Mathf.Abs(prb.x - plt.x); @@ -319,23 +307,25 @@ namespace XCharts { if (ItemStyleHelper.IsNeedCorner(itemStyle)) { - ChartDrawer.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis); + UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, + itemStyle.cornerRadius, isYAxis); } else { - CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip); + CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid); } - ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis); + UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, + itemStyle.cornerRadius, isYAxis); } } else { if (serie.clip) { - prb = ClampInCoordinate(prb); - plb = ClampInCoordinate(plb); - plt = ClampInCoordinate(plt); - prt = ClampInCoordinate(prt); + prb = ClampInGrid(grid, prb); + plb = ClampInGrid(grid, plb); + plt = ClampInGrid(grid, plt); + prt = ClampInGrid(grid, prt); } var borderColor = itemStyle.borderColor; var itemWidth = Mathf.Abs(prt.x - plb.x); @@ -345,46 +335,49 @@ namespace XCharts { if (ItemStyleHelper.IsNeedCorner(itemStyle)) { - ChartDrawer.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis); + UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, + itemStyle.cornerRadius, isYAxis); } else { - CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, serie.clip); + CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, + serie.clip, grid); } - ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis); + UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, + itemStyle.cornerRadius, isYAxis); } } } private void DrawZebraBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, - Vector3 prb, bool isYAxis) + Vector3 prb, bool isYAxis, Grid grid) { - var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis); + var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight); + DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid); if (isYAxis) { plt = (plb + plt) / 2; prt = (prt + prb) / 2; CheckClipAndDrawZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, - areaColor, serie.clip); + areaColor, serie.clip, grid); } else { plb = (prb + plb) / 2; plt = (plt + prt) / 2; CheckClipAndDrawZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, - areaColor, serie.clip); + areaColor, serie.clip, grid); } } private void DrawCapsuleBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, - Vector3 prb, bool isYAxis) + Vector3 prb, bool isYAxis, Grid grid) { - var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); - var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis); + var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight); + var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight); + DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid); var borderWidth = itemStyle.runtimeBorderWidth; var radius = barWidth / 2 - borderWidth; var isGradient = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor); @@ -402,15 +395,17 @@ namespace XCharts var barLen = prt.x - plt.x; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor, rectEndColor, serie.clip); - ChartDrawer.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis); - ChartDrawer.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis); + CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor, + rectEndColor, serie.clip, grid); + UGL.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis); + UGL.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis); } else { - CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, areaColor, areaToColor, serie.clip); - ChartDrawer.DrawSector(vh, pcl, radius, areaColor, 180, 360); - ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, 0, 180); + CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, areaColor, + areaToColor, serie.clip, grid); + UGL.DrawSector(vh, pcl, radius, areaColor, 180, 360); + UGL.DrawSector(vh, pcr, radius, areaToColor, 0, 180); } } } @@ -425,15 +420,17 @@ namespace XCharts var barLen = plt.x - prt.x; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor, rectEndColor, serie.clip); - ChartDrawer.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis); - ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis); + CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor, + rectEndColor, serie.clip, grid); + UGL.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis); + UGL.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis); } else { - CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, areaColor, areaToColor, serie.clip); - ChartDrawer.DrawSector(vh, pcl, radius, areaColor, 0, 180); - ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, 180, 360); + CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, areaColor, + areaToColor, serie.clip, grid); + UGL.DrawSector(vh, pcl, radius, areaColor, 0, 180); + UGL.DrawSector(vh, pcr, radius, areaToColor, 180, 360); } } } @@ -452,15 +449,17 @@ namespace XCharts var barLen = plt.y - plb.y; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor, rectEndColor, serie.clip); - ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis); - ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis); + CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor, + rectEndColor, serie.clip, grid); + UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis); + UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis); } else { - CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, areaColor, areaToColor, serie.clip); - ChartDrawer.DrawSector(vh, pct, radius, areaToColor, 270, 450); - ChartDrawer.DrawSector(vh, pcb, radius, areaColor, 90, 270); + CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, areaColor, + areaToColor, serie.clip, grid); + UGL.DrawSector(vh, pct, radius, areaToColor, 270, 450); + UGL.DrawSector(vh, pcb, radius, areaColor, 90, 270); } } } @@ -475,102 +474,109 @@ namespace XCharts var barLen = plb.y - plt.y; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor, rectEndColor, serie.clip); - ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis); - ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis); + CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor, + rectEndColor, serie.clip, grid); + UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis); + UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis); } else { - CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, areaColor, areaToColor, serie.clip); - ChartDrawer.DrawSector(vh, pct, radius, areaToColor, 90, 270); - ChartDrawer.DrawSector(vh, pcb, radius, areaColor, 270, 450); + CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, areaColor, + areaToColor, serie.clip, grid); + UGL.DrawSector(vh, pct, radius, areaToColor, 90, 270); + UGL.DrawSector(vh, pcb, radius, areaColor, 270, 450); } } } } } - private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis) + private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, + int colorIndex, bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis, Grid grid) { - var color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, colorIndex, highlight, false); + var color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_Theme, colorIndex, highlight, false); if (ChartHelper.IsClearColor(color)) return; if (isYAxis) { - var axis = m_YAxises[serie.axisIndex]; - var axisWidth = axis.axisLine.width; - Vector3 plt = new Vector3(m_CoordinateX + axisWidth, pY + space + barWidth); - Vector3 prt = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space + barWidth); - Vector3 prb = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space); - Vector3 plb = new Vector3(m_CoordinateX + axisWidth, pY + space); + var axis = m_YAxes[serie.yAxisIndex]; + var axisWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth); + Vector3 plt = new Vector3(grid.runtimeX + axisWidth, pY + space + barWidth); + Vector3 prt = new Vector3(grid.runtimeX + axisWidth + grid.runtimeWidth, pY + space + barWidth); + Vector3 prb = new Vector3(grid.runtimeX + axisWidth + grid.runtimeWidth, pY + space); + Vector3 plb = new Vector3(grid.runtimeX + axisWidth, pY + space); if (serie.barType == BarType.Capsule) { var radius = barWidth / 2; var diff = Vector3.right * radius; var pcl = (plt + plb) / 2 + diff; var pcr = (prt + prb) / 2 - diff; - CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, color, color, serie.clip); - ChartDrawer.DrawSector(vh, pcl, radius, color, 180, 360); - ChartDrawer.DrawSector(vh, pcr, radius, color, 0, 180); + CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, color, color, serie.clip, grid); + UGL.DrawSector(vh, pcl, radius, color, 180, 360); + UGL.DrawSector(vh, pcr, radius, color, 0, 180); if (itemStyle.NeedShowBorder()) { var borderWidth = itemStyle.borderWidth; var borderColor = itemStyle.borderColor; - var smoothness = m_Settings.cicleSmoothness; + var smoothness = settings.cicleSmoothness; var inRadius = radius - borderWidth; var outRadius = radius; var p1 = plb + diff + Vector3.up * borderWidth / 2; var p2 = prb - diff + Vector3.up * borderWidth / 2; var p3 = plt + diff - Vector3.up * borderWidth / 2; var p4 = prt - diff - Vector3.up * borderWidth / 2; - ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); - ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); - ChartDrawer.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, ChartConst.clearColor32, 180, 360, smoothness); - ChartDrawer.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, ChartConst.clearColor32, 0, 180, smoothness); + UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); + UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); + UGL.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, ChartConst.clearColor32, + 180, 360, smoothness); + UGL.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, ChartConst.clearColor32, + 0, 180, smoothness); } } else { - CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip); + CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip, grid); } } else { - var axis = m_XAxises[serie.axisIndex]; - var axisWidth = axis.axisLine.width; - Vector3 plb = new Vector3(pX + space, m_CoordinateY + axisWidth); - Vector3 plt = new Vector3(pX + space, m_CoordinateY + m_CoordinateHeight + axisWidth); - Vector3 prt = new Vector3(pX + space + barWidth, m_CoordinateY + m_CoordinateHeight + axisWidth); - Vector3 prb = new Vector3(pX + space + barWidth, m_CoordinateY + axisWidth); + var axis = m_XAxes[serie.xAxisIndex]; + var axisWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth); + Vector3 plb = new Vector3(pX + space, grid.runtimeY + axisWidth); + Vector3 plt = new Vector3(pX + space, grid.runtimeY + grid.runtimeHeight + axisWidth); + Vector3 prt = new Vector3(pX + space + barWidth, grid.runtimeY + grid.runtimeHeight + axisWidth); + Vector3 prb = new Vector3(pX + space + barWidth, grid.runtimeY + axisWidth); if (serie.barType == BarType.Capsule) { var radius = barWidth / 2; var diff = Vector3.up * radius; var pct = (plt + prt) / 2 - diff; var pcb = (plb + prb) / 2 + diff; - CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, color, color, serie.clip); - ChartDrawer.DrawSector(vh, pct, radius, color, 270, 450); - ChartDrawer.DrawSector(vh, pcb, radius, color, 90, 270); + CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, color, color, + serie.clip, grid); + UGL.DrawSector(vh, pct, radius, color, 270, 450); + UGL.DrawSector(vh, pcb, radius, color, 90, 270); if (itemStyle.NeedShowBorder()) { var borderWidth = itemStyle.borderWidth; var borderColor = itemStyle.borderColor; - var smoothness = m_Settings.cicleSmoothness; + var smoothness = settings.cicleSmoothness; var inRadius = radius - borderWidth; var outRadius = radius; var p1 = plb + diff + Vector3.right * borderWidth / 2; var p2 = plt - diff + Vector3.right * borderWidth / 2; var p3 = prb + diff - Vector3.right * borderWidth / 2; var p4 = prt - diff - Vector3.right * borderWidth / 2; - ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); - ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); - ChartDrawer.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, ChartConst.clearColor32, 270, 450, smoothness); - ChartDrawer.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, ChartConst.clearColor32, 90, 270, smoothness); + UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); + UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); + UGL.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, ChartConst.clearColor32, + 270, 450, smoothness); + UGL.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, ChartConst.clearColor32, + 90, 270, smoothness); } } else { - CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip); + CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip, grid); } } } @@ -658,5 +664,37 @@ namespace XCharts if (barWidth > 1) return barWidth; else return barWidth * categoryWidth; } + + private List<string> tempList = new List<string>(); + private int GetBarIndex(Serie currSerie) + { + tempList.Clear(); + int index = 0; + for (int i = 0; i < m_Series.Count; i++) + { + var serie = m_Series.GetSerie(i); + if (serie.type != SerieType.Bar) continue; + if (string.IsNullOrEmpty(serie.stack)) + { + if (serie.index == currSerie.index) return index; + tempList.Add(string.Empty); + index++; + } + else + { + if (!tempList.Contains(serie.stack)) + { + if (serie.index == currSerie.index) return index; + tempList.Add(serie.stack); + index++; + } + else + { + if (serie.index == currSerie.index) return tempList.IndexOf(serie.stack); + } + } + } + return 0; + } } } \ No newline at end of file diff --git a/Runtime/Internal/CoordinateChart_DrawHeatmap.cs b/Runtime/Internal/CoordinateChart_DrawHeatmap.cs index 72b17023..4fdd51c4 100644 --- a/Runtime/Internal/CoordinateChart_DrawHeatmap.cs +++ b/Runtime/Internal/CoordinateChart_DrawHeatmap.cs @@ -1,12 +1,13 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; +using XUGL; namespace XCharts { @@ -17,62 +18,62 @@ namespace XCharts protected void CheckVisualMap() { - if (!m_VisualMap.enable || !m_VisualMap.show) return; + if (!visualMap.enable || !visualMap.show) return; Vector2 local; if (canvas == null) return; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, canvas.worldCamera, out local)) { - if (m_VisualMap.runtimeSelectedIndex >= 0) + if (visualMap.runtimeSelectedIndex >= 0) { - m_VisualMap.runtimeSelectedIndex = -1; + visualMap.runtimeSelectedIndex = -1; RefreshChart(); } return; } if (local.x < chartX || local.x > chartX + chartWidth || local.y < chartY || local.y > chartY + chartHeight || - !m_VisualMap.IsInRangeRect(local, chartRect)) + !visualMap.IsInRangeRect(local, chartRect)) { - if (m_VisualMap.runtimeSelectedIndex >= 0) + if (visualMap.runtimeSelectedIndex >= 0) { - m_VisualMap.runtimeSelectedIndex = -1; + visualMap.runtimeSelectedIndex = -1; RefreshChart(); } return; } var pos1 = Vector3.zero; var pos2 = Vector3.zero; - var halfHig = m_VisualMap.itemHeight / 2; - var centerPos = chartPosition + m_VisualMap.location.GetPosition(chartWidth, chartHeight); + var halfHig = visualMap.itemHeight / 2; + var centerPos = chartPosition + visualMap.location.GetPosition(chartWidth, chartHeight); var selectedIndex = -1; var value = 0f; - switch (m_VisualMap.orient) + switch (visualMap.orient) { case Orient.Horizonal: pos1 = centerPos + Vector3.left * halfHig; pos2 = centerPos + Vector3.right * halfHig; - value = m_VisualMap.min + (local.x - pos1.x) / (pos2.x - pos1.x) * (m_VisualMap.max - m_VisualMap.min); - selectedIndex = m_VisualMap.GetIndex(value); + value = visualMap.min + (local.x - pos1.x) / (pos2.x - pos1.x) * (visualMap.max - visualMap.min); + selectedIndex = visualMap.GetIndex(value); break; case Orient.Vertical: pos1 = centerPos + Vector3.down * halfHig; pos2 = centerPos + Vector3.up * halfHig; - value = m_VisualMap.min + (local.y - pos1.y) / (pos2.y - pos1.y) * (m_VisualMap.max - m_VisualMap.min); - selectedIndex = m_VisualMap.GetIndex(value); + value = visualMap.min + (local.y - pos1.y) / (pos2.y - pos1.y) * (visualMap.max - visualMap.min); + selectedIndex = visualMap.GetIndex(value); break; } - m_VisualMap.runtimeSelectedValue = value; - m_VisualMap.runtimeSelectedIndex = selectedIndex; + visualMap.runtimeSelectedValue = value; + visualMap.runtimeSelectedIndex = selectedIndex; RefreshChart(); } protected void OnDragVisualMapStart() { - if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return; - var inMinRect = m_VisualMap.IsInRangeMinRect(pointerPos, chartRect, m_Settings.visualMapTriangeLen); - var inMaxRect = m_VisualMap.IsInRangeMaxRect(pointerPos, chartRect, m_Settings.visualMapTriangeLen); + if (!visualMap.enable || !visualMap.show || !visualMap.calculable) return; + var inMinRect = visualMap.IsInRangeMinRect(pointerPos, chartRect, m_Theme.visualMap.triangeLen); + var inMaxRect = visualMap.IsInRangeMaxRect(pointerPos, chartRect, m_Theme.visualMap.triangeLen); if (inMinRect || inMaxRect) { if (inMinRect) @@ -88,24 +89,24 @@ namespace XCharts protected void OnDragVisualMap() { - if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return; + if (!visualMap.enable || !visualMap.show || !visualMap.calculable) return; if (!m_VisualMapMinDrag && !m_VisualMapMaxDrag) return; - var value = m_VisualMap.GetValue(pointerPos, chartRect); + var value = visualMap.GetValue(pointerPos, chartRect); if (m_VisualMapMinDrag) { - m_VisualMap.rangeMin = value; + visualMap.rangeMin = value; } else { - m_VisualMap.rangeMax = value; + visualMap.rangeMax = value; } RefreshChart(); } protected void OnDragVisualMapEnd() { - if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return; + if (!visualMap.enable || !visualMap.show || !visualMap.calculable) return; if (m_VisualMapMinDrag || m_VisualMapMaxDrag) { RefreshChart(); @@ -117,19 +118,20 @@ namespace XCharts protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie) { if (serie.animation.HasFadeOut()) return; - var yAxis = m_YAxises[serie.axisIndex]; - var xAxis = m_XAxises[serie.axisIndex]; + var yAxis = m_YAxes[serie.yAxisIndex]; + var xAxis = m_XAxes[serie.xAxisIndex]; + var grid = GetSerieGridOrDefault(serie); var xCount = xAxis.data.Count; var yCount = yAxis.data.Count; - var xWidth = m_CoordinateWidth / xCount; - var yWidth = m_CoordinateHeight / yCount; + var xWidth = grid.runtimeWidth / xCount; + var yWidth = grid.runtimeHeight / yCount; - var zeroX = m_CoordinateX; - var zeroY = m_CoordinateY; + var zeroX = grid.runtimeX; + var zeroY = grid.runtimeY; var dataList = serie.GetDataList(); - var rangeMin = m_VisualMap.rangeMin; - var rangeMax = m_VisualMap.rangeMax; - var color = m_ThemeInfo.GetColor(serie.index); + var rangeMin = visualMap.rangeMin; + var rangeMax = visualMap.rangeMax; + var color = m_Theme.GetColor(serie.index); var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0; var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32; borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity); @@ -145,7 +147,7 @@ namespace XCharts var dataIndex = i * yCount + j; if (dataIndex >= dataList.Count) continue; var serieData = dataList[dataIndex]; - var dimension = VisualMapHelper.GetDimension(m_VisualMap, serieData.data.Count); + var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count); if (serie.IsIgnoreIndex(dataIndex, dimension)) { serie.dataPoints.Add(Vector3.zero); @@ -157,32 +159,32 @@ namespace XCharts serie.dataPoints.Add(pos); serieData.canShowLabel = false; if (value == 0) continue; - if (m_VisualMap.enable) + if (visualMap.enable) { - if ((value < rangeMin && rangeMin != m_VisualMap.min) - || (value > rangeMax && rangeMax != m_VisualMap.max)) + if ((value < rangeMin && rangeMin != visualMap.min) + || (value > rangeMax && rangeMax != visualMap.max)) { continue; } - if (!m_VisualMap.IsInSelectedValue(value)) continue; - color = m_VisualMap.GetColor(value); + if (!visualMap.IsInSelectedValue(value)) continue; + color = visualMap.GetColor(value); } if (animationIndex >= 0 && i > animationIndex) continue; serieData.canShowLabel = true; - var emphasis = (m_Tooltip.show && i == (int)m_Tooltip.runtimeXValues[0] && j == (int)m_Tooltip.runtimeYValues[0]) - || m_VisualMap.runtimeSelectedIndex > 0; + var emphasis = (tooltip.show && i == (int)tooltip.runtimeXValues[0] && j == (int)tooltip.runtimeYValues[0]) + || visualMap.runtimeSelectedIndex > 0; var rectWid = xWidth - 2 * borderWidth; var rectHig = yWidth - 2 * borderWidth; - ChartDrawer.DrawPolygon(vh, pos, rectWid / 2, rectHig / 2, color); + UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color); if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor)) { - ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor); + UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor); } - if (m_VisualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0) + if (visualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0) { var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth; var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32; - ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor); + UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor); } } } @@ -190,32 +192,32 @@ namespace XCharts { serie.animation.CheckProgress(xCount); m_IsPlayingAnimation = true; - RefreshChart(); + RefreshPainter(serie); } if (dataChanging) { - RefreshChart(); + RefreshPainter(serie); } } protected void DrawVisualMap(VertexHelper vh) { - if (!m_VisualMap.enable || !m_VisualMap.show) return; - var centerPos = chartPosition + m_VisualMap.location.GetPosition(chartWidth, chartHeight); + if (!visualMap.enable || !visualMap.show) return; + var centerPos = chartPosition + visualMap.location.GetPosition(chartWidth, chartHeight); var pos1 = Vector3.zero; var pos2 = Vector3.zero; var dir = Vector3.zero; - var halfWid = m_VisualMap.itemWidth / 2; - var halfHig = m_VisualMap.itemHeight / 2; + var halfWid = visualMap.itemWidth / 2; + var halfHig = visualMap.itemHeight / 2; var xRadius = 0f; var yRadius = 0f; - var splitNum = m_VisualMap.runtimeInRange.Count; - var splitWid = m_VisualMap.itemHeight / (splitNum - 1); + var splitNum = visualMap.runtimeInRange.Count; + var splitWid = visualMap.itemHeight / (splitNum - 1); var isVertical = false; - var colors = m_VisualMap.runtimeInRange; - var triangeLen = m_Settings.visualMapTriangeLen; - switch (m_VisualMap.orient) + var colors = visualMap.runtimeInRange; + var triangeLen = m_Theme.visualMap.triangeLen; + switch (visualMap.orient) { case Orient.Horizonal: pos1 = centerPos + Vector3.left * halfHig; @@ -224,20 +226,20 @@ namespace XCharts xRadius = splitWid / 2; yRadius = halfWid; isVertical = false; - if (m_VisualMap.calculable) + if (visualMap.calculable) { - var p0 = pos1 + Vector3.right * m_VisualMap.runtimeRangeMinHeight; + var p0 = pos1 + Vector3.right * visualMap.runtimeRangeMinHeight; var p1 = p0 + Vector3.up * halfWid; var p2 = p0 + Vector3.up * (halfWid + triangeLen); var p3 = p2 + Vector3.left * triangeLen; - var color = m_VisualMap.GetColor(m_VisualMap.rangeMin); - ChartDrawer.DrawTriangle(vh, p1, p2, p3, color); - p0 = pos1 + Vector3.right * m_VisualMap.runtimeRangeMaxHeight; + var color = visualMap.GetColor(visualMap.rangeMin); + UGL.DrawTriangle(vh, p1, p2, p3, color); + p0 = pos1 + Vector3.right * visualMap.runtimeRangeMaxHeight; p1 = p0 + Vector3.up * halfWid; p2 = p0 + Vector3.up * (halfWid + triangeLen); p3 = p2 + Vector3.right * triangeLen; - color = m_VisualMap.GetColor(m_VisualMap.rangeMax); - ChartDrawer.DrawTriangle(vh, p1, p2, p3, color); + color = visualMap.GetColor(visualMap.rangeMax); + UGL.DrawTriangle(vh, p1, p2, p3, color); } break; case Orient.Vertical: @@ -247,32 +249,32 @@ namespace XCharts xRadius = halfWid; yRadius = splitWid / 2; isVertical = true; - if (m_VisualMap.calculable) + if (visualMap.calculable) { - var p0 = pos1 + Vector3.up * m_VisualMap.runtimeRangeMinHeight; + var p0 = pos1 + Vector3.up * visualMap.runtimeRangeMinHeight; var p1 = p0 + Vector3.right * halfWid; var p2 = p0 + Vector3.right * (halfWid + triangeLen); var p3 = p2 + Vector3.down * triangeLen; - var color = m_VisualMap.GetColor(m_VisualMap.rangeMin); - ChartDrawer.DrawTriangle(vh, p1, p2, p3, color); - p0 = pos1 + Vector3.up * m_VisualMap.runtimeRangeMaxHeight; + var color = visualMap.GetColor(visualMap.rangeMin); + UGL.DrawTriangle(vh, p1, p2, p3, color); + p0 = pos1 + Vector3.up * visualMap.runtimeRangeMaxHeight; p1 = p0 + Vector3.right * halfWid; p2 = p0 + Vector3.right * (halfWid + triangeLen); p3 = p2 + Vector3.up * triangeLen; - color = m_VisualMap.GetColor(m_VisualMap.rangeMax); - ChartDrawer.DrawTriangle(vh, p1, p2, p3, color); + color = visualMap.GetColor(visualMap.rangeMax); + UGL.DrawTriangle(vh, p1, p2, p3, color); } break; } - if (m_VisualMap.calculable && (m_VisualMap.rangeMin > m_VisualMap.min - || m_VisualMap.rangeMax < m_VisualMap.max)) + if (visualMap.calculable && (visualMap.rangeMin > visualMap.min + || visualMap.rangeMax < visualMap.max)) { - var rangeMin = m_VisualMap.rangeMin; - var rangeMax = m_VisualMap.rangeMax; - var diff = (m_VisualMap.max - m_VisualMap.min) / (splitNum - 1); + var rangeMin = visualMap.rangeMin; + var rangeMax = visualMap.rangeMax; + var diff = (visualMap.max - visualMap.min) / (splitNum - 1); for (int i = 1; i < splitNum; i++) { - var splitMin = m_VisualMap.min + (i - 1) * diff; + var splitMin = visualMap.min + (i - 1) * diff; var splitMax = splitMin + diff; if (rangeMin > splitMax || rangeMax < splitMin) { @@ -282,47 +284,47 @@ namespace XCharts { var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid; var startColor = colors[i - 1]; - var toColor = m_VisualMap.IsPiecewise() ? startColor : colors[i]; - ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); + var toColor = visualMap.IsPiecewise() ? startColor : colors[i]; + UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); } else if (rangeMin > splitMin && rangeMax >= splitMax) { - var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight; + var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; var splitMaxPos = pos1 + dir * i * splitWid; var splitPos = p0 + (splitMaxPos - p0) / 2; - var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin); - var toColor = m_VisualMap.IsPiecewise() ? startColor : colors[i]; + var startColor = visualMap.GetColor(visualMap.rangeMin); + var toColor = visualMap.IsPiecewise() ? startColor : colors[i]; var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2; - if (m_VisualMap.orient == Orient.Vertical) - ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); + if (visualMap.orient == Orient.Vertical) + UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); else - ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); + UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } else if (rangeMax < splitMax && rangeMin <= splitMin) { - var p0 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight; + var p0 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var splitMinPos = pos1 + dir * (i - 1) * splitWid; var splitPos = splitMinPos + (p0 - splitMinPos) / 2; var startColor = colors[i - 1]; - var toColor = m_VisualMap.IsPiecewise() ? startColor : m_VisualMap.GetColor(m_VisualMap.rangeMax); + var toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(visualMap.rangeMax); var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2; - if (m_VisualMap.orient == Orient.Vertical) - ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); + if (visualMap.orient == Orient.Vertical) + UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); else - ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); + UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } else { - var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight; - var p1 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight; + var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; + var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var splitPos = (p0 + p1) / 2; - var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin); - var toColor = m_VisualMap.GetColor(m_VisualMap.rangeMax); + var startColor = visualMap.GetColor(visualMap.rangeMin); + var toColor = visualMap.GetColor(visualMap.rangeMax); var yRadius1 = Vector3.Distance(p0, p1) / 2; - if (m_VisualMap.orient == Orient.Vertical) - ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); + if (visualMap.orient == Orient.Vertical) + UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); else - ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); + UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } } } @@ -332,45 +334,45 @@ namespace XCharts { var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid; var startColor = colors[i - 1]; - var toColor = m_VisualMap.IsPiecewise() ? startColor : colors[i]; - ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); + var toColor = visualMap.IsPiecewise() ? startColor : colors[i]; + UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); } } - if (m_VisualMap.rangeMin > m_VisualMap.min) + if (visualMap.rangeMin > visualMap.min) { - var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight; - ChartDrawer.DrawPolygon(vh, pos1, p0, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor); + var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; + UGL.DrawRectangle(vh, pos1, p0, visualMap.itemWidth / 2, m_Theme.visualMap.backgroundColor); } - if (m_VisualMap.rangeMax < m_VisualMap.max) + if (visualMap.rangeMax < visualMap.max) { - var p1 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight; - ChartDrawer.DrawPolygon(vh, p1, pos2, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor); + var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; + UGL.DrawRectangle(vh, p1, pos2, visualMap.itemWidth / 2, m_Theme.visualMap.backgroundColor); } - if (m_VisualMap.hoverLink) + if (visualMap.hoverLink) { - if (m_VisualMap.runtimeSelectedIndex >= 0) + if (visualMap.runtimeSelectedIndex >= 0) { - var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight; - var p1 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight; + var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; + var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; - if (m_VisualMap.orient == Orient.Vertical) + if (visualMap.orient == Orient.Vertical) { var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y)); var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y)); var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y); - ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.runtimeSelectedIndex]); + UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]); } else { var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid); var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid); var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2); - ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.runtimeSelectedIndex]); + UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]); } } - else if (m_Tooltip.show && m_Tooltip.runtimeXValues[0] >= 0 && m_Tooltip.runtimeYValues[0] >= 0) + else if (tooltip.show && tooltip.runtimeXValues[0] >= 0 && tooltip.runtimeYValues[0] >= 0) { // var p0 = pos1 + dir * m_VisualMap.rangeMinHeight; // var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight; @@ -379,14 +381,14 @@ namespace XCharts // var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y)); // var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y)); // var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y); - // ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]); + // UGL.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]); // } // else // { // var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid); // var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid); // var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2); - // ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]); + // UGL.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]); // } } } diff --git a/Runtime/Internal/CoordinateChart_DrawLine.cs b/Runtime/Internal/CoordinateChart_DrawLine.cs index 064a0edb..a44bf043 100644 --- a/Runtime/Internal/CoordinateChart_DrawLine.cs +++ b/Runtime/Internal/CoordinateChart_DrawLine.cs @@ -1,128 +1,121 @@ using System.Runtime.InteropServices.ComTypes; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using XUGL; namespace XCharts { public partial class CoordinateChart { - protected void DrawLinePoint(VertexHelper vh) + protected void DrawLinePoint(VertexHelper vh, Serie serie) { + if (!serie.show || serie.IsPerformanceMode()) return; + if (serie.type != SerieType.Line) return; + var count = serie.dataPoints.Count; var clip = SeriesHelper.IsAnyClipSerie(m_Series); - for (int n = 0; n < m_Series.Count; n++) + var grid = GetSerieGridOrDefault(serie); + for (int i = 0; i < count; i++) { - var serie = m_Series.GetSerie(n); - if (!serie.show || serie.IsPerformanceMode()) continue; - if (serie.type != SerieType.Line) continue; - var count = serie.dataPoints.Count; - for (int i = 0; i < count; i++) + var serieData = serie.GetSerieData(i); + var symbol = SerieHelper.GetSerieSymbol(serie, serieData); + if (!symbol.show || !symbol.ShowSymbol(i, count)) continue; + if (serie.lineArrow.show) { - var serieData = serie.GetSerieData(i); - var symbol = SerieHelper.GetSerieSymbol(serie, serieData); - if (!symbol.show || !symbol.ShowSymbol(i, count)) continue; - if (serie.lineArrow.show) - { - if (serie.lineArrow.position == LineArrow.Position.Start && i == 0) continue; - if (serie.lineArrow.position == LineArrow.Position.End && i == count - 1) continue; - } - if (ChartHelper.IsIngore(serie.dataPoints[i])) continue; - bool highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) - || serie.data[i].highlighted || serie.highlighted; - float symbolSize = highlight ? symbol.selectedSize : symbol.size; - var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, n, highlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, n, highlight); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); - symbolSize = serie.animation.GetSysmbolSize(symbolSize); - CheckClipAndDrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serie.dataPoints[i], symbolColor, - symbolToColor, symbol.gap, clip, cornerRadius); + if (serie.lineArrow.position == LineArrow.Position.Start && i == 0) continue; + if (serie.lineArrow.position == LineArrow.Position.End && i == count - 1) continue; } + if (ChartHelper.IsIngore(serie.dataPoints[i])) continue; + bool highlight = (tooltip.show && tooltip.IsSelected(i)) + || serie.data[i].highlighted || serie.highlighted; + float symbolSize = highlight + ? symbol.GetSelectedSize(serie.data[i].data, m_Theme.serie.lineSymbolSelectedSize) + : symbol.GetSize(serie.data[i].data, m_Theme.serie.lineSymbolSize); + var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, serie.index, highlight); + + var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, serie.index, highlight); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); + symbolSize = serie.animation.GetSysmbolSize(symbolSize); + CheckClipAndDrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serie.dataPoints[i], symbolColor, + symbolToColor, symbol.gap, clip, cornerRadius, grid); } } - protected void DrawLineArrow(VertexHelper vh) + protected void DrawLineArrow(VertexHelper vh, Serie serie) { - for (int n = 0; n < m_Series.Count; n++) + if (serie.type != SerieType.Line) return; + if (!serie.show || !serie.lineArrow.show) return; + if (serie.dataPoints.Count < 2) return; + Color32 lineColor = SerieHelper.GetLineColor(serie, m_Theme, serie.index, false); + Vector3 startPos, arrowPos; + var lineArrow = serie.lineArrow.arrow; + switch (serie.lineArrow.position) { - var serie = m_Series.GetSerie(n); - if (serie.type != SerieType.Line) continue; - if (!serie.show || !serie.lineArrow.show) continue; - if (serie.dataPoints.Count < 2) return; - Color32 lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, n, false); - Vector3 startPos, arrowPos; - switch (serie.lineArrow.position) - { - case LineArrow.Position.End: - var dataPoints = serie.GetUpSmoothList(serie.dataCount - 1); - if (dataPoints.Count < 3) - { - dataPoints = serie.dataPoints; - startPos = dataPoints[dataPoints.Count - 2]; - arrowPos = dataPoints[dataPoints.Count - 1]; - } - else - { - startPos = dataPoints[dataPoints.Count - 3]; - arrowPos = dataPoints[dataPoints.Count - 2]; - } - ChartDrawer.DrawArrow(vh, startPos, arrowPos, serie.lineArrow.width, - serie.lineArrow.height, serie.lineArrow.offset, serie.lineArrow.dent, lineColor); - break; - case LineArrow.Position.Start: - dataPoints = serie.GetUpSmoothList(1); - if (dataPoints.Count < 2) dataPoints = serie.dataPoints; - startPos = dataPoints[1]; - arrowPos = dataPoints[0]; - ChartDrawer.DrawArrow(vh, startPos, arrowPos, serie.lineArrow.width, - serie.lineArrow.height, serie.lineArrow.offset, serie.lineArrow.dent, lineColor); - break; - } + case LineArrow.Position.End: + var dataPoints = serie.GetUpSmoothList(serie.dataCount - 1); + if (dataPoints.Count < 3) + { + dataPoints = serie.dataPoints; + startPos = dataPoints[dataPoints.Count - 2]; + arrowPos = dataPoints[dataPoints.Count - 1]; + } + else + { + startPos = dataPoints[dataPoints.Count - 3]; + arrowPos = dataPoints[dataPoints.Count - 2]; + } + UGL.DrawArrow(vh, startPos, arrowPos, lineArrow.width, lineArrow.height, + lineArrow.offset, lineArrow.dent, lineArrow.GetColor(lineColor)); + break; + case LineArrow.Position.Start: + dataPoints = serie.GetUpSmoothList(1); + if (dataPoints.Count < 2) dataPoints = serie.dataPoints; + startPos = dataPoints[1]; + arrowPos = dataPoints[0]; + UGL.DrawArrow(vh, startPos, arrowPos, lineArrow.width, lineArrow.height, + lineArrow.offset, lineArrow.dent, lineArrow.GetColor(lineColor)); + break; } } - protected void DrawXLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) + protected void DrawXLineSerie(VertexHelper vh, Serie serie, int colorIndex) { if (!IsActive(serie.index)) return; if (serie.animation.HasFadeOut()) return; - var showData = serie.GetDataList(m_DataZoom); + var showData = serie.GetDataList(dataZoom); if (showData.Count <= 0) return; - Color32 lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted); - Color32 srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false); - Color32 srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false); - Color32 highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true); - Color32 highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true); + Color32 lineColor = SerieHelper.GetLineColor(serie, m_Theme, colorIndex, serie.highlighted); + Color32 srcAreaColor = SerieHelper.GetAreaColor(serie, m_Theme, colorIndex, false); + Color32 srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_Theme, colorIndex, false); + Color32 highlightAreaColor = SerieHelper.GetAreaColor(serie, m_Theme, colorIndex, true); + Color32 highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_Theme, colorIndex, true); Color32 areaColor, areaToColor; Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero; - var yAxis = m_YAxises[serie.axisIndex]; - var xAxis = m_XAxises[serie.axisIndex]; - var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset); + var yAxis = m_YAxes[serie.yAxisIndex]; + var xAxis = m_XAxes[serie.xAxisIndex]; + var grid = GetSerieGridOrDefault(serie); + var zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset); var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line); - if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count]; - float scaleWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom); - float startX = m_CoordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0); + m_StackSerieData.Clear(); + if (isStack) SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData); + float scaleWid = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom); + float startX = grid.runtimeX + (xAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; int i; - if (seriesHig.Count < serie.minShow) - { - for (i = 0; i < serie.minShow; i++) - { - seriesHig.Add(0); - } - } int rate = 1; var sampleDist = serie.sampleDist; - if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (m_CoordinateWidth / sampleDist)); + if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (grid.runtimeWidth / sampleDist)); if (rate < 1) rate = 1; var includeLastData = false; var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage : @@ -132,39 +125,36 @@ namespace XCharts for (i = serie.minShow; i < maxCount; i += rate) { if (i == maxCount - 1) includeLastData = true; - if (i >= seriesHig.Count) - { - for (int j = 0; j < rate; j++) seriesHig.Add(0); - } if (serie.IsIgnoreValue(showData[i].GetData(1))) { serie.dataPoints.Add(Vector3.zero); + showData[i].runtimeStackHig = 0; } else { float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, dataChangeDuration, ref dataChanging, yAxis); - seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np, - dataChangeDuration); + showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, + ref np, dataChangeDuration); serie.dataPoints.Add(np); } } if (dataChanging) { - RefreshChart(); + RefreshPainter(serie); } if (!includeLastData) { i = maxCount - 1; - seriesHig.Add(0); if (serie.IsIgnoreValue(showData[i].GetData(1))) { serie.dataPoints.Add(Vector3.zero); + showData[i].runtimeStackHig = 0; } else { float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); - seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np, + showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref np, dataChangeDuration); serie.dataPoints.Add(np); } @@ -192,11 +182,12 @@ namespace XCharts if (serie.IsIgnoreValue(showData[i].GetData(1))) { serie.dataPoints.Add(Vector3.zero); + showData[i].runtimeStackHig = 0; } else { float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); - GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos, dataChangeDuration); + showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref firstLastPos, dataChangeDuration); } } else @@ -209,11 +200,12 @@ namespace XCharts if (serie.IsIgnoreValue(showData[i].GetData(1))) { serie.dataPoints.Add(Vector3.zero); + showData[i].runtimeStackHig = 0; } else { float yValue = showData[i].GetCurrData(1, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); - GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos, dataChangeDuration); + showData[i].runtimeStackHig = GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, isStack, ref lastNextPos, dataChangeDuration); } } else @@ -232,7 +224,7 @@ namespace XCharts } if (!serie.animation.NeedAnimation(i)) break; bool isFinish = true; - if (serie.areaStyle.tooltipHighlight && m_Tooltip.show && i <= m_Tooltip.runtimeDataIndex[0]) + if (serie.areaStyle.tooltipHighlight && tooltip.show && i <= tooltip.runtimeDataIndex[0]) { areaColor = highlightAreaColor; areaToColor = highlightAreaToColor; @@ -277,9 +269,9 @@ namespace XCharts if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(totalDetailProgress - currDetailProgress); - serie.animation.CheckSymbol(serie.symbol.size); + serie.animation.CheckSymbol(serie.symbol.GetSize(null, m_Theme.serie.lineSymbolSize)); m_IsPlayingAnimation = true; - RefreshChart(); + RefreshPainter(serie); } } @@ -418,7 +410,7 @@ namespace XCharts } private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i, - float scaleWid, float serieHig, ref Vector3 np, float duration, bool isIngoreValue = false) + float scaleWid, bool isStack, ref Vector3 np, float duration, bool isIngoreValue = false) { if (isIngoreValue) { @@ -432,89 +424,104 @@ namespace XCharts float yMaxValue = yAxis.GetCurrMaxValue(duration); if (xAxis.IsValue() || xAxis.IsLog()) { + var grid = GetAxisGridOrDefault(xAxis); + var axisLineWidth = xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); float xValue = i > showData.Count - 1 ? 0 : showData[i].GetData(0, xAxis.inverse); - float pX = m_CoordinateX + xAxis.axisLine.width; - float pY = serieHig + m_CoordinateY + xAxis.axisLine.width; + float pX = grid.runtimeX + axisLineWidth; + float pY = grid.runtimeY + axisLineWidth; + if (isStack) + { + for (int n = 0; n < m_StackSerieData.Count - 1; n++) + { + pY += m_StackSerieData[n][i].runtimeStackHig; + } + } if (xAxis.IsLog()) { int minIndex = xAxis.runtimeMinLogIndex; float nowIndex = xAxis.GetLogValue(xValue); - xDataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * m_CoordinateWidth; + xDataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * grid.runtimeWidth; } else { if ((xMaxValue - xMinValue) <= 0) xDataHig = 0; - else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * m_CoordinateWidth; + else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth; } if (yAxis.IsLog()) { int minIndex = yAxis.runtimeMinLogIndex; float nowIndex = yAxis.GetLogValue(yValue); - yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * m_CoordinateHeight; + yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * grid.runtimeHeight; } else { if ((yMaxValue - yMinValue) <= 0) yDataHig = 0; - else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * m_CoordinateHeight; + else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * grid.runtimeHeight; } np = new Vector3(pX + xDataHig, pY + yDataHig); } else { + var grid = GetAxisGridOrDefault(yAxis); + var axisLineWidth = yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); float pX = startX + i * scaleWid; - float pY = serieHig + m_CoordinateY + yAxis.axisLine.width; + float pY = grid.runtimeY + axisLineWidth; + if (isStack) + { + for (int n = 0; n < m_StackSerieData.Count - 1; n++) + { + pY += m_StackSerieData[n][i].runtimeStackHig; + } + } if (yAxis.IsLog()) { int minIndex = yAxis.runtimeMinLogIndex; float nowIndex = yAxis.GetLogValue(yValue); - yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * m_CoordinateHeight; + yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * grid.runtimeHeight; } else { if ((yMaxValue - yMinValue) <= 0) yDataHig = 0; - else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * m_CoordinateHeight; + else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * grid.runtimeHeight; } np = new Vector3(pX, pY + yDataHig); } return yDataHig; } - protected void DrawYLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) + List<List<SerieData>> m_StackSerieData = new List<List<SerieData>>(); + protected void DrawYLineSerie(VertexHelper vh, Serie serie, int colorIndex) { if (!IsActive(serie.index)) return; if (serie.animation.HasFadeOut()) return; - var showData = serie.GetDataList(m_DataZoom); + var showData = serie.GetDataList(dataZoom); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; Vector3 llp = Vector3.zero; Vector3 nnp = Vector3.zero; - var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted); - var srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false); - var srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false); - var highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true); - var highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true); + var lineColor = SerieHelper.GetLineColor(serie, m_Theme, colorIndex, serie.highlighted); + var srcAreaColor = SerieHelper.GetAreaColor(serie, m_Theme, colorIndex, false); + var srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_Theme, colorIndex, false); + var highlightAreaColor = SerieHelper.GetAreaColor(serie, m_Theme, colorIndex, true); + var highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_Theme, colorIndex, true); Color32 areaColor, areaToColor; - var xAxis = m_XAxises[serie.axisIndex]; - var yAxis = m_YAxises[serie.axisIndex]; - var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY); + var xAxis = m_XAxes[serie.xAxisIndex]; + var yAxis = m_YAxes[serie.yAxisIndex]; + var grid = GetSerieGridOrDefault(serie); + var zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY); var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line); - if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count]; - float scaleWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, showData.Count, m_DataZoom); - float startY = m_CoordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0); + m_StackSerieData.Clear(); + if (isStack) SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData); + if (!yAxis.show) yAxis = m_YAxes[(serie.yAxisIndex + 1) % m_YAxes.Count]; + float scaleWid = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom); + float startY = grid.runtimeY + (yAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; int i = 0; - if (seriesHig.Count < serie.minShow) - { - for (i = 0; i < serie.minShow; i++) - { - seriesHig.Add(0); - } - } int rate = 1; var sampleDist = serie.sampleDist; - if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (m_CoordinateWidth / sampleDist)); + if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (grid.runtimeWidth / sampleDist)); if (rate < 1) rate = 1; var dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); @@ -522,54 +529,63 @@ namespace XCharts float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration); for (i = serie.minShow; i < maxCount; i += rate) { - if (i >= seriesHig.Count) - { - for (int j = 0; j < rate; j++) seriesHig.Add(0); - } float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); float pY = startY + i * scaleWid; - float pX = seriesHig[i] + m_CoordinateX + yAxis.axisLine.width; + float pX = grid.runtimeX + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + if (isStack) + { + for (int n = 0; n < m_StackSerieData.Count - 1; n++) + { + pX += m_StackSerieData[n][i].runtimeStackHig; + } + } float dataHig = 0; if (xAxis.IsLog()) { int minIndex = xAxis.runtimeMinLogIndex; float nowIndex = xAxis.GetLogValue(value); - dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * m_CoordinateWidth; + dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * grid.runtimeWidth; } else { - dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * m_CoordinateWidth; + dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth; } + showData[i].runtimeStackHig = dataHig; np = new Vector3(pX + dataHig, pY); serie.dataPoints.Add(np); - seriesHig[i] += dataHig; if (showData[i].IsDataChanged()) dataChanging = true; } if (dataChanging) { - RefreshChart(); + RefreshPainter(serie); } if (maxCount % rate != 0) { i = maxCount - 1; - seriesHig.Add(0); float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); float pY = startY + i * scaleWid; - float pX = seriesHig[i] + m_CoordinateX + yAxis.axisLine.width; + float pX = grid.runtimeX + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + if (isStack) + { + for (int n = 0; n < m_StackSerieData.Count - 1; n++) + { + pX += m_StackSerieData[n][i].runtimeStackHig; + } + } float dataHig = 0; if (xAxis.IsLog()) { int minIndex = xAxis.runtimeMinLogIndex; float nowIndex = xAxis.GetLogValue(value); - dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * m_CoordinateWidth; + dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * grid.runtimeWidth; } else { - dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * m_CoordinateWidth; + dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * grid.runtimeWidth; } + showData[i].runtimeStackHig = dataHig; np = new Vector3(pX + dataHig, pY); serie.dataPoints.Add(np); - seriesHig[i] += dataHig; } lp = serie.dataPoints[0]; int dataCount = serie.dataPoints.Count; @@ -582,7 +598,7 @@ namespace XCharts serie.ClearSmoothList(i); if (!serie.animation.NeedAnimation(i)) break; bool isFinish = true; - if (serie.areaStyle.tooltipHighlight && m_Tooltip.show && i < m_Tooltip.runtimeDataIndex[0]) + if (serie.areaStyle.tooltipHighlight && tooltip.show && i < tooltip.runtimeDataIndex[0]) { areaColor = highlightAreaColor; areaToColor = highlightAreaToColor; @@ -614,19 +630,19 @@ namespace XCharts areaColor, areaToColor, zeroPos); break; case LineType.Dash: - ChartDrawer.DrawDashLine(vh, lp, np, serie.lineStyle.width, lineColor); + UGL.DrawDashLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor); isFinish = true; break; case LineType.Dot: - ChartDrawer.DrawDotLine(vh, lp, np, serie.lineStyle.width, lineColor); + UGL.DrawDotLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor); isFinish = true; break; case LineType.DashDot: - ChartDrawer.DrawDashDotLine(vh, lp, np, serie.lineStyle.width, lineColor); + UGL.DrawDashDotLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor); isFinish = true; break; case LineType.DashDotDot: - ChartDrawer.DrawDashDotDotLine(vh, lp, np, serie.lineStyle.width, lineColor); + UGL.DrawDashDotDotLine(vh, lp, np, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor); isFinish = true; break; } @@ -635,14 +651,24 @@ namespace XCharts } if (!serie.animation.IsFinish()) { - float total = totalDetailProgress - currDetailProgress - dataCount * serie.lineStyle.width * 0.5f; + float total = totalDetailProgress - currDetailProgress - dataCount * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth) * 0.5f; serie.animation.CheckProgress(total); - serie.animation.CheckSymbol(serie.symbol.size); + serie.animation.CheckSymbol(serie.symbol.GetSize(null, m_Theme.serie.lineSymbolSize)); m_IsPlayingAnimation = true; - RefreshChart(); + RefreshPainter(serie); } } + private float GetStackValue(List<List<SerieData>> stackDataList, int dataIndex, float dataChangeDuration, Axis xAxis) + { + float value = 0; + foreach (var dataList in stackDataList) + { + value += dataList[dataIndex].GetCurrData(1, dataChangeDuration, xAxis.inverse, xAxis.runtimeMinValue, xAxis.runtimeMaxValue); + } + return value; + } + private Vector3 stPos1, stPos2, lastDir, lastDnPos; private bool lastIsDown; private bool DrawNormalLine(VertexHelper vh, Serie serie, Axis axis, Vector3 lp, Vector3 np, Vector3 nnp, @@ -654,7 +680,8 @@ namespace XCharts var isTheLastPos = np == nnp; bool isYAxis = axis is YAxis; var isTurnBack = IsInRightOrUp(isYAxis, np, lp); - var lineWidth = serie.lineStyle.width; + var lineWidth = serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); + var grid = GetSerieGridOrDefault(serie); Vector3 dnPos, upPos1, upPos2, dir1v, dir2v; bool isDown; @@ -667,12 +694,12 @@ namespace XCharts var normal = Vector3.Cross(dir1, dir2); isDown = isYAxis ? normal.z >= 0 : normal.z <= 0; var angle = (180 - Vector3.Angle(dir1, dir2)) * Mathf.Deg2Rad / 2; - var diff = serie.lineStyle.width / Mathf.Sin(angle); + var diff = serie.lineStyle.GetWidth(m_Theme.serie.lineWidth) / Mathf.Sin(angle); var dirDp = Vector3.Cross(dir3, Vector3.forward).normalized * (isYAxis ? -1 : 1); dir2v = Vector3.Cross(dir2, Vector3.forward).normalized * (isYAxis ? -1 : 1); dnPos = np + (isDown ? dirDp : -dirDp) * diff; - upPos1 = np + (isDown ? -dir1v : dir1v) * serie.lineStyle.width; - upPos2 = np + (isDown ? -dir2v : dir2v) * serie.lineStyle.width; + upPos1 = np + (isDown ? -dir1v : dir1v) * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); + upPos2 = np + (isDown ? -dir2v : dir2v) * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); lastDir = dir1; if (isDown) { @@ -690,22 +717,22 @@ namespace XCharts isDown = Vector3.Cross(dir1, lastDir).z <= 0; if (isYAxis) isDown = !isDown; dir1v = Vector3.Cross(dir1, Vector3.forward).normalized * (isYAxis ? -1 : 1); - upPos1 = np - dir1v * serie.lineStyle.width; - upPos2 = np + dir1v * serie.lineStyle.width; + upPos1 = np - dir1v * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); + upPos2 = np + dir1v * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); dnPos = isDown ? upPos2 : upPos1; } if (isSecond) { - stPos1 = lp - dir1v * serie.lineStyle.width; - stPos2 = lp + dir1v * serie.lineStyle.width; + stPos1 = lp - dir1v * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); + stPos2 = lp + dir1v * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); } var smoothPoints = serie.GetUpSmoothList(dataIndex); var smoothDownPoints = serie.GetDownSmoothList(dataIndex); var dist = Vector3.Distance(lp, np); var lastSmoothPoint = Vector3.zero; var lastSmoothDownPoint = Vector3.zero; - int segment = (int)(dist / m_Settings.lineSegmentDistance); + int segment = (int)(dist / settings.lineSegmentDistance); if (segment <= 3) segment = (int)(dist / lineWidth); if (segment < 2) segment = 2; if (dataIndex > startIndex) @@ -733,8 +760,8 @@ namespace XCharts var isEndPos = i == segment - 1; var cp = lp + dir1 * (dist * i / segment); if (serie.animation.CheckDetailBreak(cp, isYAxis)) isBreak = true; - var tp1 = cp - dir1v * serie.lineStyle.width; - var tp2 = cp + dir1v * serie.lineStyle.width; + var tp1 = cp - dir1v * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); + var tp2 = cp + dir1v * serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); CheckLineGradientColor(cp, serie.lineStyle, axis, defaultLineColor, ref lineColor); if (isDown) { @@ -746,8 +773,8 @@ namespace XCharts { isShort = true; isStart = true; - CheckClipAndDrawPolygon(vh, stPos1, upPos1, upPos2, stPos2, lineColor, serie.clip); - CheckClipAndDrawTriangle(vh, stPos2, upPos2, dnPos, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, stPos1, upPos1, upPos2, stPos2, lineColor, serie.clip, grid); + CheckClipAndDrawTriangle(vh, stPos2, upPos2, dnPos, lineColor, serie.clip, grid); TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, stPos1, isEndPos); TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, upPos1, isEndPos); TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, dnPos, isEndPos); @@ -757,7 +784,7 @@ namespace XCharts (!lastIsDown && IsInRightOrUp(isYAxis, lastDnPos, tp1))) { isStart = true; - CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid); } } else @@ -766,24 +793,24 @@ namespace XCharts { if (np != nnp) { - CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip); - CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip, grid); + CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip, grid); } else { - CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip, grid); } } else { if (IsInRightOrUp(isYAxis, tp2, dnPos) || isTurnBack) { - CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.width, lineColor, serie.clip); + CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, serie.clip, grid); } else { - CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip); - CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip, grid); + CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip, grid); i = segment; } } @@ -807,11 +834,11 @@ namespace XCharts isStart = true; isShort = true; if (np == nnp) - CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos2, stPos2, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos2, stPos2, lineColor, serie.clip, grid); else { - CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos1, stPos2, lineColor, serie.clip); - CheckClipAndDrawTriangle(vh, dnPos, upPos1, upPos2, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos1, stPos2, lineColor, serie.clip, grid); + CheckClipAndDrawTriangle(vh, dnPos, upPos1, upPos2, lineColor, serie.clip, grid); } TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, dnPos, isEndPos); TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, stPos2, isEndPos); @@ -824,7 +851,7 @@ namespace XCharts isStart = true; if (stPos2 != Vector3.zero) { - CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid); } } } @@ -834,21 +861,21 @@ namespace XCharts { if (np != nnp) { - CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip); - CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip, grid); + CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip, grid); } - else CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip); + else CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip, grid); } else { if (IsInRightOrUp(isYAxis, tp1, dnPos) || isTurnBack) { - CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.width, lineColor, serie.clip); + CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, serie.clip, grid); } else { - CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip); - CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip, grid); + CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip, grid); i = segment; } } @@ -906,7 +933,7 @@ namespace XCharts else { var points = ((isYAxis && lp.x < zeroPos.x) || (!isYAxis && lp.y < zeroPos.y)) ? smoothPoints : smoothDownPoints; - Vector3 aep = isYAxis ? new Vector3(zeroPos.x, zeroPos.y + m_CoordinateHeight) : new Vector3(zeroPos.x + m_CoordinateWidth, zeroPos.y); + Vector3 aep = isYAxis ? new Vector3(zeroPos.x, zeroPos.y + grid.runtimeHeight) : new Vector3(zeroPos.x + grid.runtimeWidth, zeroPos.y); var sindex = 0; var eindex = 0; var sp = GetStartPos(points, ref sindex); @@ -927,10 +954,11 @@ namespace XCharts { var sp1 = smoothDownPoints[0]; var ep1 = smoothDownPoints[smoothDownPoints.Count - 1]; - var axisUpStart = zeroPos + (isYAxis ? Vector3.right : Vector3.up) * axis.axisLine.width; - var axisUpEnd = axisUpStart + (isYAxis ? Vector3.up * m_CoordinateHeight : Vector3.right * m_CoordinateWidth); - var axisDownStart = zeroPos - (isYAxis ? Vector3.right : Vector3.up) * axis.axisLine.width; - var axisDownEnd = axisDownStart + (isYAxis ? Vector3.up * m_CoordinateHeight : Vector3.right * m_CoordinateWidth); + var axisLineWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth); + var axisUpStart = zeroPos + (isYAxis ? Vector3.right : Vector3.up) * axisLineWidth; + var axisUpEnd = axisUpStart + (isYAxis ? Vector3.up * grid.runtimeHeight : Vector3.right * grid.runtimeWidth); + var axisDownStart = zeroPos - (isYAxis ? Vector3.right : Vector3.up) * axisLineWidth; + var axisDownEnd = axisDownStart + (isYAxis ? Vector3.up * grid.runtimeHeight : Vector3.right * grid.runtimeWidth); var luPos = ChartHelper.GetIntersection(sp1, ep1, axisUpStart, axisUpEnd); sp1 = smoothPoints[0]; ep1 = smoothPoints[smoothPoints.Count - 2]; @@ -951,7 +979,7 @@ namespace XCharts if ((isYAxis && ep.y > luPos.y) || (!isYAxis && ep.x > luPos.x)) { var tp = isYAxis ? new Vector3(luPos.x, sp.y) : new Vector3(sp.x, luPos.y); - CheckClipAndDrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid); break; } DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero); @@ -973,7 +1001,7 @@ namespace XCharts { first = true; var tp = isYAxis ? new Vector3(rdPos.x, ep.y) : new Vector3(ep.x, rdPos.y); - CheckClipAndDrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor, serie.clip); + CheckClipAndDrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor, serie.clip, grid); sp = ep; continue; } @@ -997,7 +1025,7 @@ namespace XCharts if ((isYAxis && ep.y > rdPos.y) || (!isYAxis && ep.x > rdPos.x)) { var tp = isYAxis ? new Vector3(rdPos.x, sp.y) : new Vector3(sp.x, rdPos.y); - CheckClipAndDrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid); break; } if (rdPos != Vector3.zero) DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero); @@ -1019,7 +1047,7 @@ namespace XCharts { first = true; var tp = isYAxis ? new Vector3(luPos.x, ep.y) : new Vector3(ep.x, luPos.y); - CheckClipAndDrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid); sp = ep; continue; } @@ -1068,8 +1096,8 @@ namespace XCharts private void CheckLineGradientColor(Vector3 cp, LineStyle lineStyle, Axis axis, Color32 defaultLineColor, ref Color32 lineColor) { - if (VisualMapHelper.IsNeedGradient(m_VisualMap)) - lineColor = VisualMapHelper.GetLineGradientColor(m_VisualMap, cp, this, axis, defaultLineColor); + if (VisualMapHelper.IsNeedGradient(visualMap)) + lineColor = VisualMapHelper.GetLineGradientColor(visualMap, cp, this, axis, defaultLineColor); else if (lineStyle.IsNeedGradient()) lineColor = VisualMapHelper.GetLineStyleGradientColor(lineStyle, cp, this, axis, defaultLineColor); } @@ -1096,30 +1124,32 @@ namespace XCharts Color32 areaColor, Color32 areaToColor, Vector3 areaDiff, bool clip = false) { float diff = 0; + var grid = GetAxisGridOrDefault(axis); + var lineWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth); if (axis is YAxis) { var isLessthan0 = (sp.x < zeroPos.x || ep.x < zeroPos.x); - diff = isLessthan0 ? -axis.axisLine.width : axis.axisLine.width; - areaColor = GetYLerpColor(areaColor, areaToColor, sp); + diff = isLessthan0 ? -lineWidth : lineWidth; + areaColor = GetYLerpColor(areaColor, areaToColor, sp, grid); if (isLessthan0) areaDiff = -areaDiff; CheckClipAndDrawPolygon(vh, new Vector3(zeroPos.x + diff, sp.y), new Vector3(zeroPos.x + diff, ep.y), - ep + areaDiff, sp + areaDiff, areaToColor, areaColor, clip); + ep + areaDiff, sp + areaDiff, areaToColor, areaColor, clip, grid); } else { var isLessthan0 = (sp.y < zeroPos.y || ep.y < zeroPos.y); - diff = isLessthan0 ? -axis.axisLine.width : axis.axisLine.width; - areaColor = GetXLerpColor(areaColor, areaToColor, sp); + diff = isLessthan0 ? -lineWidth : lineWidth; + areaColor = GetXLerpColor(areaColor, areaToColor, sp, grid); if (isLessthan0) areaDiff = -areaDiff; if (isLessthan0) { CheckClipAndDrawPolygon(vh, ep + areaDiff, sp + areaDiff, new Vector3(sp.x, zeroPos.y + diff), - new Vector3(ep.x, zeroPos.y + diff), areaColor, areaToColor, clip); + new Vector3(ep.x, zeroPos.y + diff), areaColor, areaToColor, clip, grid); } else { CheckClipAndDrawPolygon(vh, sp + areaDiff, ep + areaDiff, new Vector3(ep.x, zeroPos.y + diff), - new Vector3(sp.x, zeroPos.y + diff), areaColor, areaToColor, clip); + new Vector3(sp.x, zeroPos.y + diff), areaColor, areaToColor, clip, grid); } } } @@ -1132,21 +1162,21 @@ namespace XCharts //lp = ClampInChart(lp); //np = ClampInChart(np); bool isYAxis = axis is YAxis; - var lineWidth = serie.lineStyle.width; + var lineWidth = serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); posList.Clear(); switch (serie.lineType) { case LineType.Dash: - ChartDrawer.DrawDashLine(vh, lp, np, lineWidth, lineColor, 15, 7, posList); + UGL.DrawDashLine(vh, lp, np, lineWidth, lineColor, 0, 0, posList); break; case LineType.Dot: - ChartDrawer.DrawDotLine(vh, lp, np, lineWidth, lineColor, 5, 5, posList); + UGL.DrawDotLine(vh, lp, np, lineWidth, lineColor, 0, 0, posList); break; case LineType.DashDot: - ChartDrawer.DrawDashDotLine(vh, lp, np, lineWidth, lineColor, 15, 15, posList); + UGL.DrawDashDotLine(vh, lp, np, lineWidth, lineColor, 0, 0, 0, posList); break; case LineType.DashDotDot: - ChartDrawer.DrawDashDotDotLine(vh, lp, np, lineWidth, lineColor, 15, 20, posList); + UGL.DrawDashDotDotLine(vh, lp, np, lineWidth, lineColor, 0, 0, 0, posList); break; } if (serie.areaStyle.show && !isYAxis && posList.Count > 0) @@ -1174,11 +1204,12 @@ namespace XCharts var defaultLineColor = lineColor; bool isYAxis = xAxis is YAxis; var isTurnBack = IsInRightOrUp(isYAxis, np, lp); - var lineWidth = serie.lineStyle.width; + var lineWidth = serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); var smoothPoints = serie.GetUpSmoothList(dataIndex); var smoothDownPoints = serie.GetDownSmoothList(dataIndex); var lastSmoothPoint = Vector3.zero; var lastSmoothDownPoint = Vector3.zero; + var grid = GetSerieGridOrDefault(serie); if (dataIndex > startIndex) { lastSmoothPoint = ChartHelper.GetLastPoint(serie.GetUpSmoothList(dataIndex - 1)); @@ -1186,8 +1217,8 @@ namespace XCharts TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, lastSmoothPoint, true); TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, lastSmoothDownPoint, true); } - if (isYAxis) ChartHelper.GetBezierListVertical(ref bezierPoints, lp, np, m_Settings.lineSmoothness, m_Settings.lineSmoothStyle); - else ChartHelper.GetBezierList(ref bezierPoints, lp, np, llp, nnp, m_Settings.lineSmoothness, m_Settings.lineSmoothStyle); + if (isYAxis) ChartHelper.GetBezierListVertical(ref bezierPoints, lp, np, settings.lineSmoothness, settings.lineSmoothStyle); + else ChartHelper.GetBezierList(ref bezierPoints, lp, np, llp, nnp, settings.lineSmoothness, settings.lineSmoothStyle); Vector3 start, to; if (serie.lineType == LineType.SmoothDash) @@ -1197,7 +1228,7 @@ namespace XCharts start = bezierPoints[i]; to = bezierPoints[i + 1]; CheckLineGradientColor(start, serie.lineStyle, xAxis, defaultLineColor, ref lineColor); - CheckClipAndDrawLine(vh, start, to, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, start, to, lineWidth, lineColor, serie.clip, grid); } return true; } @@ -1220,8 +1251,8 @@ namespace XCharts if (!serie.animation.IsInFadeOut()) { CheckLineGradientColor(lp, serie.lineStyle, xAxis, defaultLineColor, ref lineColor); - CheckClipAndDrawTriangle(vh, smoothStartPosUp, startUp, lp, lineColor, serie.clip); - CheckClipAndDrawTriangle(vh, smoothStartPosDn, startDn, lp, lineColor, serie.clip); + CheckClipAndDrawTriangle(vh, smoothStartPosUp, startUp, lp, lineColor, serie.clip, grid); + CheckClipAndDrawTriangle(vh, smoothStartPosDn, startDn, lp, lineColor, serie.clip, grid); TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, smoothStartPosUp, false); TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, smoothStartPosDn, false); } @@ -1248,8 +1279,8 @@ namespace XCharts toUp = to - diff; toDn = to + diff; CheckLineGradientColor(to, serie.lineStyle, xAxis, defaultLineColor, ref lineColor); - if (isYAxis) CheckClipAndDrawPolygon(vh, startDn, toDn, toUp, startUp, lineColor, serie.clip); - else CheckClipAndDrawPolygon(vh, startUp, toUp, toDn, startDn, lineColor, serie.clip); + if (isYAxis) CheckClipAndDrawPolygon(vh, startDn, toDn, toUp, startUp, lineColor, serie.clip, grid); + else CheckClipAndDrawPolygon(vh, startUp, toUp, toDn, startDn, lineColor, serie.clip, grid); TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, toUp, true); TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, toDn, true); if (isEndPos) @@ -1338,25 +1369,26 @@ namespace XCharts var lastCount = 1; start = smoothPoints[0]; var sourAreaColor = areaColor; + var grid = GetAxisGridOrDefault(axis); for (int k = 1; k < smoothPoints.Count; k++) { to = smoothPoints[k]; if (!IsInRightOrUp(isYAxis, start, to)) continue; if (serie.animation.CheckDetailBreak(to, isYAxis)) break; Vector3 tnp, tlp; - if (isYAxis) areaColor = GetYLerpColor(sourAreaColor, areaToColor, to); - else areaColor = GetXLerpColor(sourAreaColor, areaToColor, to); + if (isYAxis) areaColor = GetYLerpColor(sourAreaColor, areaToColor, to, grid); + else areaColor = GetXLerpColor(sourAreaColor, areaToColor, to, grid); if (k == smoothPoints.Count - 1) { if (k < lastSmoothPoints.Count - 1) { tnp = lastSmoothPoints[lastCount - 1]; - CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip, grid); while (lastCount < lastSmoothPoints.Count) { tlp = lastSmoothPoints[lastCount]; if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break; - CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip, grid); lastCount++; tnp = tlp; } @@ -1368,7 +1400,7 @@ namespace XCharts { tlp = lastSmoothPoints[lastSmoothPoints.Count - 1]; if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break; - CheckClipAndDrawTriangle(vh, to, start, tlp, areaColor, areaColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, to, start, tlp, areaColor, areaColor, areaToColor, serie.clip, grid); start = to; continue; } @@ -1378,7 +1410,7 @@ namespace XCharts { tlp = lastSmoothPoints[lastCount - 1]; if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break; - CheckClipAndDrawPolygon(vh, start, to, tnp, tlp, areaColor, areaToColor, serie.clip); + CheckClipAndDrawPolygon(vh, start, to, tnp, tlp, areaColor, areaToColor, serie.clip, grid); lastCount++; } else @@ -1386,12 +1418,12 @@ namespace XCharts if (diff < 0) { tnp = lastSmoothPoints[lastCount - 1]; - CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip, grid); while (diff < 0 && lastCount < lastSmoothPoints.Count) { tlp = lastSmoothPoints[lastCount]; if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break; - CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip, grid); lastCount++; diff = isYAxis ? tlp.y - to.y : tlp.x - to.x; tnp = tlp; @@ -1401,7 +1433,7 @@ namespace XCharts { tlp = lastSmoothPoints[lastCount - 1]; if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break; - CheckClipAndDrawTriangle(vh, start, to, tlp, areaColor, areaColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, start, to, tlp, areaColor, areaColor, areaToColor, serie.clip, grid); } } start = to; @@ -1410,9 +1442,9 @@ namespace XCharts { var p1 = lastSmoothPoints[lastCount - 1]; var p2 = lastSmoothPoints[lastSmoothPoints.Count - 1]; - if (!serie.animation.CheckDetailBreak(p1, isYAxis)) + if (!serie.animation.CheckDetailBreak(p1, isYAxis) && !serie.animation.CheckDetailBreak(p2, isYAxis)) { - CheckClipAndDrawTriangle(vh, p1, start, p2, areaToColor, areaColor, areaToColor, serie.clip); + CheckClipAndDrawTriangle(vh, p1, start, p2, areaToColor, areaColor, areaToColor, serie.clip, grid); } } } @@ -1422,10 +1454,11 @@ namespace XCharts Vector3 nnp, int dataIndex, Color32 lineColor, Color32 areaColor, Color32 areaToColor, Vector3 zeroPos) { bool isYAxis = axis is YAxis; - float lineWidth = serie.lineStyle.width; + float lineWidth = serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); Vector3 start, end, middle, middleZero, middle1, middle2; Vector3 sp, ep, diff1, diff2; var areaDiff = isYAxis ? Vector3.left * lineWidth : Vector3.down * lineWidth; + var grid = GetAxisGridOrDefault(axis); switch (serie.lineType) { case LineType.StepStart: @@ -1438,21 +1471,21 @@ namespace XCharts if (Vector3.Distance(lp, middle) > 2 * lineWidth) { - ChartHelper.GetPointList(ref linePointList, start, middle - diff1, m_Settings.lineSegmentDistance); + ChartHelper.GetPointList(ref linePointList, start, middle - diff1, settings.lineSegmentDistance); sp = linePointList[0]; for (int i = 1; i < linePointList.Count; i++) { ep = linePointList[i]; if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false; - CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid); sp = ep; } - CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip, true, grid); } else { - if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip); - CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip); + if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid); + CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip, grid); } if (serie.areaStyle.show) { @@ -1466,13 +1499,13 @@ namespace XCharts } } - ChartHelper.GetPointList(ref linePointList, middle + diff2, end, m_Settings.lineSegmentDistance); + ChartHelper.GetPointList(ref linePointList, middle + diff2, end, settings.lineSegmentDistance); sp = linePointList[0]; for (int i = 1; i < linePointList.Count; i++) { ep = linePointList[i]; if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false; - CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid); if (serie.areaStyle.show) { DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1483,7 +1516,7 @@ namespace XCharts if (nnp != np) { if (serie.animation.CheckDetailBreak(np, isYAxis)) return false; - CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid); bool flag = ((isYAxis && nnp.x > np.x && np.x > zeroPos.x) || (!isYAxis && nnp.y > np.y && np.y > zeroPos.y)); if (serie.areaStyle.show && flag) { @@ -1503,13 +1536,13 @@ namespace XCharts //draw lp to middle1 if (Vector3.Distance(lp, middle1) > 2 * lineWidth) { - ChartHelper.GetPointList(ref linePointList, start, middle1 - diff1, m_Settings.lineSegmentDistance); + ChartHelper.GetPointList(ref linePointList, start, middle1 - diff1, settings.lineSegmentDistance); sp = linePointList[0]; for (int i = 1; i < linePointList.Count; i++) { ep = linePointList[i]; if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false; - CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid); if (serie.areaStyle.show) { DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1517,7 +1550,7 @@ namespace XCharts sp = ep; } if (serie.animation.CheckDetailBreak(middle1, isYAxis)) return false; - CheckClipAndDrawPolygon(vh, middle1, lineWidth, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, middle1, lineWidth, lineColor, serie.clip, true, grid); if (serie.areaStyle.show && Vector3.Dot(middleZero - middle1, middle2 - middle1) <= 0) { DrawPolygonToZero(vh, middle1 - diff1, middle1 + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1525,22 +1558,22 @@ namespace XCharts } else { - if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip); - CheckClipAndDrawLine(vh, lp + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip); + if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid); + CheckClipAndDrawLine(vh, lp + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip, grid); } //draw middle1 to middle2 if (Vector3.Distance(middle1, middle2) > 2 * lineWidth) { - ChartHelper.GetPointList(ref linePointList, middle1 + diff2, middle2 - diff2, m_Settings.lineSegmentDistance); + ChartHelper.GetPointList(ref linePointList, middle1 + diff2, middle2 - diff2, settings.lineSegmentDistance); sp = linePointList[0]; for (int i = 1; i < linePointList.Count; i++) { ep = linePointList[i]; - CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid); sp = ep; } - CheckClipAndDrawPolygon(vh, middle2, lineWidth, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, middle2, lineWidth, lineColor, serie.clip, true, grid); if (serie.areaStyle.show && Vector3.Dot(middleZero - middle2, middle2 - middle1) >= 0) { DrawPolygonToZero(vh, middle2 - diff1, middle2 + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1548,18 +1581,18 @@ namespace XCharts } else { - CheckClipAndDrawLine(vh, middle1 + diff2, middle2 + diff2, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, middle1 + diff2, middle2 + diff2, lineWidth, lineColor, serie.clip, grid); } //draw middle2 to np if (Vector3.Distance(middle2, np) > 2 * lineWidth) { - ChartHelper.GetPointList(ref linePointList, middle2 + diff1, np - diff1, m_Settings.lineSegmentDistance); + ChartHelper.GetPointList(ref linePointList, middle2 + diff1, np - diff1, settings.lineSegmentDistance); sp = linePointList[0]; for (int i = 1; i < linePointList.Count; i++) { ep = linePointList[i]; if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false; - CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid); if (serie.areaStyle.show) { DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1567,7 +1600,7 @@ namespace XCharts sp = ep; } if (serie.animation.CheckDetailBreak(np, isYAxis)) return false; - CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid); if (serie.areaStyle.show) { DrawPolygonToZero(vh, np - diff1, np + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1575,7 +1608,7 @@ namespace XCharts } else { - CheckClipAndDrawLine(vh, middle1 + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, middle1 + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip, grid); } break; case LineType.StepEnd: @@ -1588,13 +1621,13 @@ namespace XCharts if (Vector3.Distance(lp, middle) > 2 * lineWidth) { - ChartHelper.GetPointList(ref linePointList, start, middle - diff1, m_Settings.lineSegmentDistance); + ChartHelper.GetPointList(ref linePointList, start, middle - diff1, settings.lineSegmentDistance); sp = linePointList[0]; for (int i = 1; i < linePointList.Count; i++) { ep = linePointList[i]; if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false; - CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid); if (serie.areaStyle.show) { DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1602,7 +1635,7 @@ namespace XCharts sp = ep; } if (serie.animation.CheckDetailBreak(middle, isYAxis)) return false; - CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip); + CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip, true, grid); if (serie.areaStyle.show && Vector3.Dot(np - middle, middleZero - middle) <= 0) { DrawPolygonToZero(vh, middle - diff1, middle + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff); @@ -1610,25 +1643,25 @@ namespace XCharts } else { - if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip); - CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip); + if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid); + CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip, grid); } if (Vector3.Distance(middle, np) > 2 * lineWidth) { - ChartHelper.GetPointList(ref linePointList, middle + diff2, end, m_Settings.lineSegmentDistance); + ChartHelper.GetPointList(ref linePointList, middle + diff2, end, settings.lineSegmentDistance); sp = linePointList[0]; for (int i = 1; i < linePointList.Count; i++) { ep = linePointList[i]; - CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid); sp = ep; } - if (nnp != np) CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip); + if (nnp != np) CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid); } else { - CheckClipAndDrawLine(vh, middle + diff2, np + diff2, lineWidth, lineColor, serie.clip); + CheckClipAndDrawLine(vh, middle + diff2, np + diff2, lineWidth, lineColor, serie.clip, grid); } bool flag2 = ((isYAxis && middle.x > np.x && np.x > zeroPos.x) || (!isYAxis && middle.y > np.y && np.y > zeroPos.y)); if (serie.areaStyle.show && flag2) diff --git a/Runtime/Internal/CoordinateChart_DrawScatter.cs b/Runtime/Internal/CoordinateChart_DrawScatter.cs index 852eb014..b74f47e6 100644 --- a/Runtime/Internal/CoordinateChart_DrawScatter.cs +++ b/Runtime/Internal/CoordinateChart_DrawScatter.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; @@ -16,8 +16,9 @@ namespace XCharts { if (serie.animation.HasFadeOut()) return; if (!serie.show) return; - var yAxis = m_YAxises[serie.axisIndex]; - var xAxis = m_XAxises[serie.axisIndex]; + var yAxis = m_YAxes[serie.yAxisIndex]; + var xAxis = m_XAxes[serie.xAxisIndex]; + var grid = GetSerieGridOrDefault(serie); int maxCount = serie.maxShow > 0 ? (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow) : serie.dataCount; @@ -27,21 +28,21 @@ namespace XCharts var dataChanging = false; for (int n = serie.minShow; n < maxCount; n++) { - var serieData = serie.GetDataList(m_DataZoom)[n]; + var serieData = serie.GetDataList(dataZoom)[n]; var symbol = SerieHelper.GetSerieSymbol(serie, serieData); if (!symbol.ShowSymbol(n, maxCount)) continue; var highlight = serie.highlighted || serieData.highlighted; - var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); - var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight); + var color = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight); + var toColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight); var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); float xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse); float yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse); if (serieData.IsDataChanged()) dataChanging = true; - float pX = m_CoordinateX + xAxis.axisLine.width; - float pY = m_CoordinateY + yAxis.axisLine.width; - float xDataHig = GetDataHig(xAxis, xValue, m_CoordinateWidth); - float yDataHig = GetDataHig(yAxis, yValue, m_CoordinateHeight); + float pX = grid.runtimeX + xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + float pY = grid.runtimeY + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); + float xDataHig = GetDataHig(xAxis, xValue, grid.runtimeWidth); + float yDataHig = GetDataHig(yAxis, yValue, grid.runtimeHeight); var pos = new Vector3(pX + xDataHig, pY + yDataHig); serie.dataPoints.Add(pos); serieData.runtimePosition = pos; @@ -49,11 +50,11 @@ namespace XCharts float symbolSize = 0; if (serie.highlighted || serieData.highlighted) { - symbolSize = symbol.GetSelectedSize(datas); + symbolSize = symbol.GetSelectedSize(datas, m_Theme.serie.scatterSymbolSelectedSize); } else { - symbolSize = symbol.GetSize(datas); + symbolSize = symbol.GetSize(datas, m_Theme.serie.scatterSymbolSize); } symbolSize *= rate; if (symbolSize > 100) symbolSize = 100; @@ -65,7 +66,7 @@ namespace XCharts color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize); DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius); } - RefreshChart(); + RefreshPainter(serie); } else { @@ -76,11 +77,11 @@ namespace XCharts { serie.animation.CheckProgress(1); m_IsPlayingAnimation = true; - RefreshChart(); + RefreshPainter(serie); } if (dataChanging) { - RefreshChart(); + RefreshPainter(serie); } } diff --git a/Runtime/Internal/DrawSerieGauge.cs b/Runtime/Internal/DrawSerieGauge.cs new file mode 100644 index 00000000..09ddf457 --- /dev/null +++ b/Runtime/Internal/DrawSerieGauge.cs @@ -0,0 +1,408 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using XUGL; + +namespace XCharts +{ + internal class DrawSerieGauge : IDrawSerie + { + public BaseChart chart; + + private static readonly string s_SerieLabelObjectName = "label"; + private static readonly string s_AxisLabelObjectName = "axis_label"; + private bool m_UpdateTitleText = false; + private bool m_UpdateLabelText = false; + + public DrawSerieGauge(BaseChart chart) + { + this.chart = chart; + } + + public void InitComponent() + { + InitAxisLabel(); + } + + public void CheckComponent() + { + } + + public void Update() + { + if (m_UpdateTitleText) + { + m_UpdateTitleText = false; + + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Gauge) + { + TitleStyleHelper.UpdateTitleText(serie); + } + } + } + if (m_UpdateLabelText) + { + m_UpdateLabelText = false; + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Gauge) + { + SerieLabelHelper.SetGaugeLabelText(serie); + UpdateAxisLabel(serie); + } + } + } + } + + public void DrawBase(VertexHelper vh) + { + } + + public void DrawSerie(VertexHelper vh, Serie serie) + { + if (serie.type != SerieType.Gauge) return; + DrawGauge(vh, serie); + } + + public void RefreshLabel() + { + } + + public bool CheckTootipArea(Vector2 local) + { + var serie = GetPointerInSerieIndex(chart.series, local); + if (serie != null) + { + chart.tooltip.runtimeDataIndex.Clear(); + chart.tooltip.runtimeDataIndex.Add(serie.index); + chart.tooltip.UpdateContentPos(local + chart.tooltip.offset); + UpdateTooltip(); + return true; + } + else if (chart.tooltip.IsActive()) + { + chart.tooltip.SetActive(false); + chart.RefreshChart(); + } + return false; + } + + public bool OnLegendButtonClick(int index, string legendName, bool show) + { + return false; + } + + public bool OnLegendButtonEnter(int index, string legendName) + { + return false; + } + + public bool OnLegendButtonExit(int index, string legendName) + { + return false; + } + + public void OnPointerDown(PointerEventData eventData) + { + } + + private void InitAxisLabel() + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Gauge)) return; + var labelObject = ChartHelper.AddObject(s_AxisLabelObjectName, chart.transform, chart.chartMinAnchor, + chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); + labelObject.hideFlags = chart.chartHideFlags; + SerieLabelPool.ReleaseAll(labelObject.transform); + for (int i = 0; i < chart.series.Count; i++) + { + var serie = chart.series.list[i]; + var serieLabel = serie.gaugeAxis.axisLabel; + var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1); + var startAngle = serie.startAngle; + serie.gaugeAxis.ClearLabelObject(); + SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); + for (int j = 0; j < count; j++) + { + var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j); + var color = Color.grey; + var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, color, 100, 100, chart.theme); + var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>(); + var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; + var item = new ChartLabel(); + item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); + item.SetIcon(iconImage); + item.SetIconActive(false); + serie.gaugeAxis.AddLabelObject(item); + } + UpdateAxisLabel(serie); + } + } + + private void UpdateAxisLabel() + { + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Gauge) + { + UpdateAxisLabel(serie); + } + } + } + + private void UpdateAxisLabel(Serie serie) + { + var show = serie.gaugeAxis.show && serie.gaugeAxis.axisLabel.show; + serie.gaugeAxis.SetLabelObjectActive(show); + if (!show) + { + return; + } + var count = serie.splitNumber > 36 ? 36 : serie.splitNumber; + var startAngle = serie.startAngle; + var totalAngle = serie.endAngle - serie.startAngle; + var totalValue = serie.max - serie.min; + var diffAngle = totalAngle / count; + var diffValue = totalValue / count; + var radius = serie.runtimeInsideRadius - serie.gaugeAxis.axisLabel.margin; + var serieData = serie.GetSerieData(0); + var customLabelText = serie.gaugeAxis.axisLabelText; + for (int j = 0; j <= count; j++) + { + var angle = serie.startAngle + j * diffAngle; + var value = serie.min + j * diffValue; + var pos = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, radius); + var text = customLabelText != null && j < customLabelText.Count ? customLabelText[j] : + SerieLabelHelper.GetFormatterContent(serie, serieData, value, totalValue, serie.gaugeAxis.axisLabel); + serie.gaugeAxis.SetLabelObjectText(j, text); + serie.gaugeAxis.SetLabelObjectPosition(j, pos); + } + } + + private void DrawGauge(VertexHelper vh, Serie serie) + { + SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); + var destAngle = GetCurrAngle(serie, true); + serie.animation.InitProgress(0, serie.startAngle, destAngle); + var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); + DrawProgressBar(vh, serie, currAngle); + DrawStageColor(vh, serie); + DrawLineStyle(vh, serie); + DrawAxisTick(vh, serie); + DrawPointer(vh, serie, currAngle); + TitleStyleHelper.CheckTitle(serie, ref chart.m_ReinitTitle, ref m_UpdateTitleText); + SerieLabelHelper.CheckLabel(serie, ref chart.m_ReinitLabel, ref m_UpdateLabelText); + CheckAnimation(serie); + if (!serie.animation.IsFinish()) + { + serie.animation.CheckProgress(destAngle - serie.startAngle); + chart.RefreshPainter(serie); + } + else if (NeedRefresh(serie)) + { + chart.RefreshPainter(serie); + } + } + + private void DrawProgressBar(VertexHelper vh, Serie serie, float currAngle) + { + if (serie.gaugeType != GaugeType.ProgressBar) return; + if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return; + var color = serie.gaugeAxis.GetAxisLineColor(chart.theme, serie.index); + var backgroundColor = serie.gaugeAxis.GetAxisLineBackgroundColor(chart.theme, serie.index); + var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth); + var outsideRadius = serie.runtimeInsideRadius + lineWidth; + var borderWidth = serie.itemStyle.borderWidth; + var borderColor = serie.itemStyle.borderColor; + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius, + backgroundColor, backgroundColor, Color.clear, serie.startAngle, serie.endAngle, 0, Color.clear, + 0, chart.settings.cicleSmoothness, serie.roundCap); + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius, + color, color, Color.clear, serie.startAngle, currAngle, 0, Color.clear, + 0, chart.settings.cicleSmoothness, serie.roundCap); + } + + private void DrawStageColor(VertexHelper vh, Serie serie) + { + if (serie.gaugeType != GaugeType.Pointer) return; + if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return; + var totalAngle = serie.endAngle - serie.startAngle; + var tempStartAngle = serie.startAngle; + var tempEndAngle = serie.startAngle; + var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth); + var outsideRadius = serie.runtimeInsideRadius + lineWidth; + serie.gaugeAxis.runtimeStageAngle.Clear(); + for (int i = 0; i < serie.gaugeAxis.axisLine.stageColor.Count; i++) + { + var stageColor = serie.gaugeAxis.axisLine.stageColor[i]; + tempEndAngle = serie.startAngle + totalAngle * stageColor.percent; + serie.gaugeAxis.runtimeStageAngle.Add(tempEndAngle); + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius, + stageColor.color, stageColor.color, Color.clear, tempStartAngle, tempEndAngle, 0, Color.clear, + 0, chart.settings.cicleSmoothness); + tempStartAngle = tempEndAngle; + } + } + + private void DrawPointer(VertexHelper vh, Serie serie, float currAngle) + { + if (!serie.gaugePointer.show) return; + var pointerColor = serie.gaugeAxis.GetPointerColor(chart.theme, serie.index, currAngle, serie.itemStyle); + var pointerToColor = !ChartHelper.IsClearColor(serie.itemStyle.toColor) ? serie.itemStyle.toColor : pointerColor; + var len = serie.gaugePointer.length < 1 && serie.gaugePointer.length > -1 ? + serie.runtimeInsideRadius * serie.gaugePointer.length : + serie.gaugePointer.length; + var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len); + var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width); + var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2); + var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2); + UGL.DrawTriangle(vh, p2, p3, p1, pointerColor, pointerColor, pointerToColor); + UGL.DrawTriangle(vh, p4, p2, p1, pointerColor, pointerColor, pointerToColor); + } + + private void DrawLineStyle(VertexHelper vh, Serie serie) + { + if (serie.gaugeType != GaugeType.Pointer) return; + if (!serie.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return; + if (serie.splitNumber <= 0) return; + var splitLine = serie.gaugeAxis.splitLine; + var totalAngle = serie.endAngle - serie.startAngle; + var diffAngle = totalAngle / serie.splitNumber; + var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth); + var splitLineWidth = splitLine.GetWidth(chart.theme.gauge.splitLineWidth); + var splitLineLength = splitLine.GetLength(chart.theme.gauge.splitLineLength); + var outsideRadius = serie.runtimeInsideRadius + lineWidth; + var insideRadius = outsideRadius - splitLineLength; + for (int i = 0; i < serie.splitNumber + 1; i++) + { + var angle = serie.startAngle + i * diffAngle; + var lineColor = serie.gaugeAxis.GetSplitLineColor(chart.theme.gauge.splitLineColor, serie.index, angle); + var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius); + var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius); + UGL.DrawLine(vh, p1, p2, splitLineWidth, lineColor); + } + } + + private void DrawAxisTick(VertexHelper vh, Serie serie) + { + if (serie.gaugeType != GaugeType.Pointer) return; + if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisTick.show) return; + if (serie.splitNumber <= 0) return; + var axisTick = serie.gaugeAxis.axisTick; + var totalAngle = serie.endAngle - serie.startAngle; + var diffAngle = totalAngle / serie.splitNumber; + var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth); + var tickWidth = axisTick.GetWidth(chart.theme.gauge.tickWidth); + var tickLength = axisTick.GetLength(chart.theme.gauge.tickLength); + var outsideRadius = serie.runtimeInsideRadius + lineWidth; + + var insideRadius = outsideRadius - (tickLength < 1 ? lineWidth * tickLength : tickLength); + for (int i = 0; i < serie.splitNumber; i++) + { + for (int j = 1; j < axisTick.splitNumber; j++) + { + var angle = serie.startAngle + i * diffAngle + j * (diffAngle / axisTick.splitNumber); + var lineColor = serie.gaugeAxis.GetSplitLineColor(chart.theme.gauge.tickColor, serie.index, angle); + var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius); + var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius); + UGL.DrawLine(vh, p1, p2, tickWidth, lineColor); + } + } + } + + private float GetCurrAngle(Serie serie, bool dest) + { + if (serie.animation.HasFadeOut()) + { + return serie.animation.GetCurrDetail(); + } + float rangeValue = serie.max - serie.min; + float rangeAngle = serie.endAngle - serie.startAngle; + float value = 0; + float angle = serie.startAngle; + if (serie.dataCount > 0) + { + var serieData = serie.data[0]; + serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset; + value = dest ? serieData.GetData(1) + : serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration()); + value = Mathf.Clamp(value, serie.min, serie.max); + } + if (rangeValue > 0) + { + angle += rangeAngle * value / rangeValue; + } + return angle; + } + + private void CheckAnimation(Serie serie) + { + var serieData = serie.GetSerieData(0); + if (serieData != null) + { + var value = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration()); + var data = serieData.GetData(1); + if (value != data) chart.RefreshPainter(serie); + } + } + + private bool NeedRefresh(Serie serie) + { + if (serie.type == SerieType.Gauge) + { + var serieData = serie.GetSerieData(0); + if (serieData != null) + { + var destValue = serieData.GetData(1); + var currValue = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration()); + return destValue != currValue; + } + } + return false; + } + + private Serie GetPointerInSerieIndex(Series series, Vector2 local) + { + foreach (var serie in series.list) + { + if (serie.type != SerieType.Gauge) continue; + if (!serie.gaugePointer.show) continue; + var len = serie.gaugePointer.length < 1 && serie.gaugePointer.length > -1 + ? serie.runtimeInsideRadius * serie.gaugePointer.length + : serie.gaugePointer.length; + if (Vector3.Distance(local, serie.runtimeCenterPos) > len) continue; + var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); + var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len); + var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width); + var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2); + var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2); + if (ChartHelper.IsPointInQuadrilateral(local, p1, p3, p2, p4)) + { + return serie; + } + } + return null; + } + + private void UpdateTooltip() + { + int index = chart.tooltip.runtimeDataIndex[0]; + if (index < 0) + { + chart.tooltip.SetActive(false); + return; + } + var content = TooltipHelper.GetFormatterContent(chart.tooltip, index, chart.series, chart.theme); + TooltipHelper.SetContentAndPosition(chart.tooltip, content.TrimStart(), chart.chartRect); + chart.tooltip.SetActive(true); + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/DrawSerieGauge.cs.meta b/Runtime/Internal/DrawSerieGauge.cs.meta new file mode 100644 index 00000000..3acfc748 --- /dev/null +++ b/Runtime/Internal/DrawSerieGauge.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ca6e74d36e80c4daabf80b165986dfbb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/DrawSerieLiquid.cs b/Runtime/Internal/DrawSerieLiquid.cs new file mode 100644 index 00000000..1995345f --- /dev/null +++ b/Runtime/Internal/DrawSerieLiquid.cs @@ -0,0 +1,259 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using XUGL; + +namespace XCharts +{ + internal class DrawSerieLiquid : IDrawSerie + { + public BaseChart chart; + private bool m_UpdateLabelText = false; + + public DrawSerieLiquid(BaseChart chart) + { + this.chart = chart; + } + + public void InitComponent() + { + //UpdateRuntimeData(); + //SerieLabelHelper.UpdateLabelText(chart.series, chart.theme, m_LegendRealShowName); + } + + public void CheckComponent() + { + } + + public void Update() + { + if (m_UpdateLabelText) + { + m_UpdateLabelText = false; + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Liquid) + { + var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name); + SerieLabelHelper.SetLiquidLabelText(serie, chart.theme, colorIndex); + } + } + } + } + + public void DrawBase(VertexHelper vh) + { + } + + public void DrawSerie(VertexHelper vh, Serie serie) + { + if (serie.type != SerieType.Liquid) return; + UpdateRuntimeData(serie); + DrawVesselBackground(vh, serie); + DrawLiquid(vh, serie); + DrawVessel(vh, serie); + } + + public void RefreshLabel() + { + } + + public bool CheckTootipArea(Vector2 local) + { + return false; + } + + public bool OnLegendButtonClick(int index, string legendName, bool show) + { + return false; + } + + public bool OnLegendButtonEnter(int index, string legendName) + { + return false; + } + + public bool OnLegendButtonExit(int index, string legendName) + { + return false; + } + + public void OnPointerDown(PointerEventData eventData) + { + } + + private void UpdateRuntimeData() + { + foreach (var vessel in chart.vessels) + { + VesselHelper.UpdateVesselCenter(vessel, chart.chartPosition, chart.chartWidth, chart.chartHeight); + } + } + + private void UpdateRuntimeData(Serie serie) + { + var vessel = chart.GetVessel(serie.vesselIndex); + if (vessel != null) + { + VesselHelper.UpdateVesselCenter(vessel, chart.chartPosition, chart.chartWidth, chart.chartHeight); + } + } + + private void DrawVesselBackground(VertexHelper vh, Serie serie) + { + var vessel = chart.GetVessel(serie.vesselIndex); + if (vessel != null) + { + if (vessel.backgroundColor.a != 0) + { + var cenPos = vessel.runtimeCenterPos; + var radius = vessel.runtimeRadius; + UGL.DrawCricle(vh, cenPos, vessel.runtimeInnerRadius, vessel.backgroundColor, chart.settings.cicleSmoothness); + } + } + } + + private void DrawVessel(VertexHelper vh, Serie serie) + { + var vessel = chart.GetVessel(serie.vesselIndex); + if (vessel != null) + { + DrawCirleVessel(vh, vessel); + } + } + + private void DrawCirleVessel(VertexHelper vh, Vessel vessel) + { + var cenPos = vessel.runtimeCenterPos; + var radius = vessel.runtimeRadius; + var serie = SeriesHelper.GetSerieByVesselIndex(chart.series, vessel.index); + var vesselColor = VesselHelper.GetColor(vessel, serie, chart.theme, chart.m_LegendRealShowName); + UGL.DrawDoughnut(vh, cenPos, radius - vessel.shapeWidth, radius, vesselColor, Color.clear, chart.settings.cicleSmoothness); + } + + private void DrawLiquid(VertexHelper vh, Serie serie) + { + if (!serie.show) return; + if (serie.animation.HasFadeOut()) return; + var vessel = chart.GetVessel(serie.vesselIndex); + if (vessel == null) return; + var cenPos = vessel.runtimeCenterPos; + var radius = vessel.runtimeInnerRadius; + var serieData = serie.GetSerieData(0); + if (serieData == null) return; + var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); + var value = serieData.GetCurrData(1, dataChangeDuration); + if (serie.runtimeCheckValue != value) + { + serie.runtimeCheckValue = value; + m_UpdateLabelText = true; + } + if (serieData.labelPosition != cenPos) + { + serieData.labelPosition = cenPos; + m_UpdateLabelText = true; + } + if (value == 0) return; + var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name); + + var realHig = (value - serie.min) / (serie.max - serie.min) * radius * 2; + serie.animation.InitProgress(1, 0, realHig); + + var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); + var a = Mathf.Abs(radius - hig + (hig > radius ? serie.waveHeight : -serie.waveHeight)); + var diff = Mathf.Sqrt(radius * radius - Mathf.Pow(a, 2)); + + var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false); + var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false); + var isNeedGradient = !ChartHelper.IsValueEqualsColor(color, toColor); + var isFull = hig >= 2 * radius; + if (hig >= 2 * radius) hig = 2 * radius; + if (isFull && !isNeedGradient) + { + UGL.DrawCricle(vh, cenPos, radius, toColor, chart.settings.cicleSmoothness); + } + else + { + var startY = cenPos.y - radius + hig; + var waveStartPos = new Vector3(cenPos.x - diff, startY); + var waveEndPos = new Vector3(cenPos.x + diff, startY); + var startX = hig > radius ? cenPos.x - radius : waveStartPos.x; + var endX = hig > radius ? cenPos.x + radius : waveEndPos.x; + + var step = vessel.smoothness; + if (step < 0.5f) step = 0.5f; + var lup = hig > radius ? new Vector3(cenPos.x - radius, cenPos.y) : waveStartPos; + var ldp = lup; + var nup = Vector3.zero; + var ndp = Vector3.zero; + var angle = 0f; + serie.runtimeWaveSpeed += serie.waveSpeed * Time.deltaTime; + var isStarted = false; + var isEnded = false; + var waveHeight = isFull ? 0 : serie.waveHeight; + while (startX < endX) + { + startX += step; + if (startX > endX) startX = endX; + if (startX > waveStartPos.x && !isStarted) + { + startX = waveStartPos.x; + isStarted = true; + } + if (startX > waveEndPos.x && !isEnded) + { + startX = waveEndPos.x; + isEnded = true; + } + var py = Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2)); + if (startX < waveStartPos.x || startX > waveEndPos.x) + { + nup = new Vector3(startX, cenPos.y + py); + } + else + { + var py2 = waveHeight * Mathf.Sin(1 / serie.waveLength * angle + serie.runtimeWaveSpeed + serie.waveOffset); + var nupY = waveStartPos.y + py2; + if (nupY > cenPos.y + py) nupY = cenPos.y + py; + else if (nupY < cenPos.y - py) nupY = cenPos.y - py; + nup = new Vector3(startX, nupY); + angle += step; + } + ndp = new Vector3(startX, cenPos.y - py); + if (!ChartHelper.IsValueEqualsColor(color, toColor)) + { + var colorMin = cenPos.y - radius; + var colorMax = startY + serie.waveHeight; + var tcolor1 = Color32.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin)); + var tcolor2 = Color32.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin)); + UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, tcolor1, tcolor2); + } + else + { + UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, color); + } + lup = nup; + ldp = ndp; + } + } + + if (serie.waveSpeed != 0 && Application.isPlaying && !isFull) + { + chart.RefreshPainter(serie); + } + if (!serie.animation.IsFinish()) + { + serie.animation.CheckProgress(realHig); + chart.m_IsPlayingAnimation = true; + chart.RefreshPainter(serie); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/DrawSerieLiquid.cs.meta b/Runtime/Internal/DrawSerieLiquid.cs.meta new file mode 100644 index 00000000..2873033b --- /dev/null +++ b/Runtime/Internal/DrawSerieLiquid.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e68718d39a3042ffb8162149246ef5e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/DrawSeriePie.cs b/Runtime/Internal/DrawSeriePie.cs new file mode 100644 index 00000000..9053e073 --- /dev/null +++ b/Runtime/Internal/DrawSeriePie.cs @@ -0,0 +1,559 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using XUGL; + +namespace XCharts +{ + internal class DrawSeriePie : IDrawSerie + { + public BaseChart chart; + protected bool m_IsEnterPieLegendButtom; + + public DrawSeriePie(BaseChart chart) + { + this.chart = chart; + } + + public void InitComponent() + { + } + + public void CheckComponent() + { + } + + public void Update() + { + } + + public void DrawBase(VertexHelper vh) + { + } + + public void DrawSerie(VertexHelper vh, Serie serie) + { + if (serie.type != SerieType.Pie) return; + UpdateRuntimeData(serie); + DrawPieLabelLine(vh, serie); + DrawPie(vh, serie); + DrawPieLabelBackground(vh, serie); + } + + public void RefreshLabel() + { + int serieNameCount = -1; + for (int i = 0; i < chart.series.Count; i++) + { + var serie = chart.series.list[i]; + serie.index = i; + if (!serie.show || serie.type != SerieType.Pie) continue; + var data = serie.data; + for (int n = 0; n < data.Count; n++) + { + var serieData = data[n]; + if (!serieData.canShowLabel || serie.IsIgnoreValue(serieData.GetData(1))) + { + serieData.SetLabelActive(false); + continue; + } + if (!serieData.show) continue; + + serieNameCount = chart.m_LegendRealShowName.IndexOf(serieData.name); + Color color = chart.theme.GetColor(serieNameCount); + DrawPieLabel(serie, n, serieData, color); + } + } + } + + public bool CheckTootipArea(Vector2 local) + { + if (!PointerIsInPieSerie(chart.series, local)) return false; + bool selected = false; + chart.tooltip.runtimeDataIndex.Clear(); + foreach (var serie in chart.series.list) + { + int index = GetPiePosIndex(serie, local); + chart.tooltip.runtimeDataIndex.Add(index); + if (serie.type != SerieType.Pie) continue; + bool refresh = false; + for (int j = 0; j < serie.data.Count; j++) + { + var serieData = serie.data[j]; + if (serieData.highlighted != (j == index)) refresh = true; + serieData.highlighted = j == index; + } + if (index >= 0) selected = true; + if (refresh) chart.RefreshChart(); + } + if (selected) + { + chart.tooltip.UpdateContentPos(local + chart.tooltip.offset); + UpdatePieTooltip(); + } + else if (chart.tooltip.IsActive()) + { + chart.tooltip.SetActive(false); + chart.RefreshChart(); + } + return true; + } + + public bool OnLegendButtonClick(int index, string legendName, bool show) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Pie)) return false; + LegendHelper.CheckDataShow(chart.series, legendName, show); + chart.UpdateLegendColor(legendName, show); + chart.RefreshChart(); + return true; + } + + public bool OnLegendButtonEnter(int index, string legendName) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Pie)) return false; + m_IsEnterPieLegendButtom = true; + LegendHelper.CheckDataHighlighted(chart.series, legendName, true); + chart.RefreshChart(); + return true; + } + + public bool OnLegendButtonExit(int index, string legendName) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Pie)) return false; + m_IsEnterPieLegendButtom = false; + LegendHelper.CheckDataHighlighted(chart.series, legendName, false); + chart.RefreshChart(); + return true; + } + + public void OnPointerDown(PointerEventData eventData) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return; + if (chart.pointerPos == Vector2.zero) return; + var refresh = false; + for (int i = 0; i < chart.series.Count; i++) + { + var serie = chart.series.GetSerie(i); + if (serie.type != SerieType.Pie) continue; + var index = GetPiePosIndex(serie, chart.pointerPos); + if (index >= 0) + { + refresh = true; + for (int j = 0; j < serie.data.Count; j++) + { + if (j == index) serie.data[j].selected = !serie.data[j].selected; + else serie.data[j].selected = false; + } + if (chart.onPointerClickPie != null) + { + chart.onPointerClickPie(eventData, i, index); + } + } + } + if (refresh) chart.RefreshChart(); + } + + private void UpdateRuntimeData(Serie serie) + { + var data = serie.data; + serie.runtimeDataMax = serie.yMax; + serie.runtimePieDataTotal = serie.yTotal; + serie.animation.InitProgress(data.Count, 0, 360); + SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); + float totalDegree = 360f; + float startDegree = 0; + int showdataCount = 0; + foreach (var sd in serie.data) + { + if (sd.show && serie.pieRoseType == RoseType.Area) showdataCount++; + sd.canShowLabel = false; + } + float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); + bool isAllZeroValue = SerieHelper.IsAllZeroValue(serie, 1); + float zeroReplaceValue = totalDegree / data.Count; + if (isAllZeroValue) + { + serie.runtimeDataMax = zeroReplaceValue; + serie.runtimePieDataTotal = totalDegree; + } + for (int n = 0; n < data.Count; n++) + { + var serieData = data[n]; + serieData.index = n; + float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration); + serieData.runtimePieStartAngle = startDegree; + serieData.runtimePieToAngle = startDegree; + serieData.runtimePieHalfAngle = startDegree; + serieData.runtimePieCurrAngle = startDegree; + if (!serieData.show) + { + continue; + } + float degree = serie.pieRoseType == RoseType.Area ? + (totalDegree / showdataCount) : (totalDegree * value / serie.runtimePieDataTotal); + serieData.runtimePieToAngle = startDegree + degree; + + serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ? + serie.runtimeInsideRadius + (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax : + serie.runtimeOutsideRadius; + if (serieData.highlighted) + { + serieData.runtimePieOutsideRadius += chart.theme.serie.pieTooltipExtraRadius; + } + var offset = 0f; + if (serie.pieClickOffset && serieData.selected) + { + offset += chart.theme.serie.pieSelectedOffset; + } + if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle)) + { + serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail(); + } + else + { + serieData.runtimePieCurrAngle = serieData.runtimePieToAngle; + } + var halfDegree = (serieData.runtimePieToAngle - startDegree) / 2; + serieData.runtimePieHalfAngle = startDegree + halfDegree; + serieData.runtiemPieOffsetCenter = serie.runtimeCenterPos; + serieData.runtimePieInsideRadius = serie.runtimeInsideRadius; + if (offset > 0) + { + var currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad; + var currSin = Mathf.Sin(currRad); + var currCos = Mathf.Cos(currRad); + serieData.runtimePieOffsetRadius = 0; + serieData.runtimePieInsideRadius -= serieData.runtimePieOffsetRadius; + serieData.runtimePieOutsideRadius -= serieData.runtimePieOffsetRadius; + if (serie.pieClickOffset && serieData.selected) + { + serieData.runtimePieOffsetRadius += chart.theme.serie.pieSelectedOffset; + if (serieData.runtimePieInsideRadius > 0) serieData.runtimePieInsideRadius += chart.theme.serie.pieSelectedOffset; + serieData.runtimePieOutsideRadius += chart.theme.serie.pieSelectedOffset; + } + serieData.runtiemPieOffsetCenter = new Vector3(serie.runtimeCenterPos.x + serieData.runtimePieOffsetRadius * currSin, + serie.runtimeCenterPos.y + serieData.runtimePieOffsetRadius * currCos); + } + serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle; + startDegree = serieData.runtimePieToAngle; + SerieLabelHelper.UpdatePieLabelPosition(serie, serieData); + } + SerieLabelHelper.AvoidLabelOverlap(serie); + } + + private void DrawPieCenter(VertexHelper vh, Serie serie, ItemStyle itemStyle, float insideRadius) + { + if (!ChartHelper.IsClearColor(itemStyle.centerColor)) + { + var radius = insideRadius - itemStyle.centerGap; + UGL.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, chart.settings.cicleSmoothness); + } + } + + private void DrawPie(VertexHelper vh, Serie serie) + { + var data = serie.data; + serie.animation.InitProgress(data.Count, 0, 360); + if (!serie.show || serie.animation.HasFadeOut()) + { + return; + } + bool dataChanging = false; + for (int n = 0; n < data.Count; n++) + { + var serieData = data[n]; + if (!serieData.show) + { + continue; + } + var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted); + if (serieData.IsDataChanged()) dataChanging = true; + var serieNameCount = chart.m_LegendRealShowName.IndexOf(serieData.legendName); + var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieNameCount, serieData.highlighted); + var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieNameCount, serieData.highlighted); + var borderWidth = itemStyle.borderWidth; + var borderColor = itemStyle.borderColor; + + if (serie.pieClickOffset && serieData.selected) + { + var drawEndDegree = serieData.runtimePieCurrAngle; + var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0; + UGL.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius, + serieData.runtimePieOutsideRadius, color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree, + borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness, needRoundCap, true); + } + else + { + var drawEndDegree = serieData.runtimePieCurrAngle; + var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0; + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius, + color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, + chart.settings.cicleSmoothness, needRoundCap, true); + DrawPieCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius); + } + if (!serie.animation.CheckDetailBreak(serieData.runtimePieToAngle)) serie.animation.SetDataFinish(n); + else break; + } + if (!serie.animation.IsFinish()) + { + serie.animation.CheckProgress(360); + serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize)); + chart.RefreshPainter(serie); + } + if (dataChanging) + { + chart.RefreshPainter(serie); + } + chart.raycastTarget = IsAnyPieClickOffset() || IsAnyPieDataHighlight(); + } + + private bool IsAnyPieClickOffset() + { + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Pie && serie.pieClickOffset) return true; + } + return false; + } + + private bool IsAnyPieDataHighlight() + { + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Pie) + { + foreach (var serieData in serie.data) + { + if (serieData.highlighted) return true; + } + } + } + return false; + } + + private void DrawPieLabelLine(VertexHelper vh, Serie serie) + { + foreach (var serieData in serie.data) + { + var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); + if (SerieLabelHelper.CanShowLabel(serie, serieData, serieLabel, 1)) + { + int colorIndex = chart.m_LegendRealShowName.IndexOf(serieData.name); + Color color = chart.theme.GetColor(colorIndex); + DrawPieLabelLine(vh, serie, serieData, color); + } + } + } + + private void DrawPieLabelBackground(VertexHelper vh, Serie serie) + { + if (serie.avoidLabelOverlap) return; + foreach (var serieData in serie.data) + { + var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); + if (SerieLabelHelper.CanShowLabel(serie, serieData, serieLabel, 1)) + { + SerieLabelHelper.UpdatePieLabelPosition(serie, serieData); + chart.DrawLabelBackground(vh, serie, serieData); + } + } + } + + private void DrawPieLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color) + { + var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); + if (serieLabel.show + && serieLabel.position == SerieLabel.Position.Outside + && serieLabel.line) + { + var insideRadius = serieData.runtimePieInsideRadius; + var outSideRadius = serieData.runtimePieOutsideRadius; + var center = serie.runtimeCenterPos; + var currAngle = serieData.runtimePieHalfAngle; + if (!ChartHelper.IsClearColor(serieLabel.lineColor)) color = serieLabel.lineColor; + else if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine) color *= color; + float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad); + float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad); + var radius1 = serieLabel.lineType == SerieLabel.LineType.HorizontalLine ? + serie.runtimeOutsideRadius : outSideRadius; + var radius2 = serie.runtimeOutsideRadius + serieLabel.lineLength1; + var radius3 = insideRadius + (outSideRadius - insideRadius) / 2; + if (radius1 < serie.runtimeInsideRadius) radius1 = serie.runtimeInsideRadius; + radius1 -= 0.1f; + var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos); + var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos); + var pos2 = serieData.labelPosition; + if (pos2.x == 0) + { + pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos); + } + Vector3 pos4, pos6; + var horizontalLineCircleRadius = serieLabel.lineWidth * 4f; + var lineCircleDiff = horizontalLineCircleRadius - 0.3f; + if (currAngle < 90) + { + var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; + r4 += serieLabel.lineLength1 - lineCircleDiff; + pos6 = pos0 + Vector3.right * lineCircleDiff; + pos4 = pos6 + Vector3.right * r4; + } + else if (currAngle < 180) + { + var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; + r4 += serieLabel.lineLength1 - lineCircleDiff; + pos6 = pos0 + Vector3.right * lineCircleDiff; + pos4 = pos6 + Vector3.right * r4; + } + else if (currAngle < 270) + { + var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad); + var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad); + var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3; + r4 += serieLabel.lineLength1 - lineCircleDiff; + pos6 = pos0 + Vector3.left * lineCircleDiff; + pos4 = pos6 + Vector3.left * r4; + } + else + { + var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad); + var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad); + var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3; + r4 += serieLabel.lineLength1 - lineCircleDiff; + pos6 = pos0 + Vector3.left * lineCircleDiff; + pos4 = pos6 + Vector3.left * r4; + } + var pos5 = new Vector3(currAngle > 180 ? pos2.x - serieLabel.lineLength2 : pos2.x + serieLabel.lineLength2, pos2.y); + switch (serieLabel.lineType) + { + case SerieLabel.LineType.BrokenLine: + UGL.DrawLine(vh, pos1, pos2, pos5, serieLabel.lineWidth, color); + break; + case SerieLabel.LineType.Curves: + UGL.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, chart.settings.lineSmoothness); + break; + case SerieLabel.LineType.HorizontalLine: + UGL.DrawCricle(vh, pos0, horizontalLineCircleRadius, color); + UGL.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color); + break; + } + } + } + + + + private void DrawPieLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor) + { + if (serieData.labelObject == null) return; + var currAngle = serieData.runtimePieHalfAngle; + var isHighlight = (serieData.highlighted && serie.emphasis.label.show); + var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); + var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel); + + if (showLabel || serieData.iconStyle.show) + { + serieData.SetLabelActive(showLabel); + float rotate = 0; + bool isInsidePosition = serieLabel.position == SerieLabel.Position.Inside; + if (serieLabel.textStyle.rotate > 0 && isInsidePosition) + { + if (currAngle > 180) rotate += 270 - currAngle; + else rotate += -(currAngle - 90); + } + Color color = serieColor; + if (isHighlight) + { + if (!ChartHelper.IsClearColor(serie.emphasis.label.textStyle.color)) color = serie.emphasis.label.textStyle.color; + } + else if (!ChartHelper.IsClearColor(serieLabel.textStyle.color)) + { + color = serieLabel.textStyle.color; + } + else + { + color = isInsidePosition ? Color.white : serieColor; + } + var fontSize = isHighlight + ? serie.emphasis.label.textStyle.GetFontSize(chart.theme.common) + : serieLabel.textStyle.GetFontSize(chart.theme.common); + var fontStyle = isHighlight ? serie.emphasis.label.textStyle.fontStyle : serieLabel.textStyle.fontStyle; + + serieData.labelObject.label.SetColor(color); + serieData.labelObject.label.SetFontSize(fontSize); + serieData.labelObject.label.SetFontStyle(fontStyle); + serieData.labelObject.SetLabelRotate(rotate); + if (!string.IsNullOrEmpty(serieLabel.formatter)) + { + var value = serieData.data[1]; + var total = serie.yTotal; + var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, serieLabel); + if (serieData.labelObject.SetText(content)) chart.RefreshPainter(serie); + } + else + { + if (serieData.labelObject.SetText(serieData.name)) chart.RefreshPainter(serie); + } + serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel)); + if (showLabel) serieData.labelObject.SetLabelPosition(serieLabel.offset); + else serieData.SetLabelActive(false); + } + else + { + serieData.SetLabelActive(false); + } + serieData.labelObject.UpdateIcon(serieData.iconStyle); + } + + protected int GetPiePosIndex(Serie serie, Vector2 local) + { + if (serie.type != SerieType.Pie) return -1; + var dist = Vector2.Distance(local, serie.runtimeCenterPos); + if (dist < serie.runtimeInsideRadius || dist > serie.runtimeOutsideRadius) return -1; + Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y); + float angle = ChartHelper.GetAngle360(Vector2.up, dir); + for (int i = 0; i < serie.data.Count; i++) + { + var serieData = serie.data[i]; + if (angle >= serieData.runtimePieStartAngle && angle <= serieData.runtimePieToAngle) + { + return i; + } + } + return -1; + } + + private bool PointerIsInPieSerie(Series series, Vector2 local) + { + foreach (var serie in series.list) + { + if (serie.type != SerieType.Pie) continue; + var dist = Vector2.Distance(local, serie.runtimeCenterPos); + if (dist >= serie.runtimeInsideRadius && dist <= serie.runtimeOutsideRadius) return true; + } + return false; + } + + protected void UpdatePieTooltip() + { + bool showTooltip = false; + foreach (var serie in chart.series.list) + { + int index = chart.tooltip.runtimeDataIndex[serie.index]; + if (index < 0) continue; + showTooltip = true; + var content = TooltipHelper.GetFormatterContent(chart.tooltip, index, chart.series, chart.theme); + TooltipHelper.SetContentAndPosition(chart.tooltip, content.TrimStart(), chart.chartRect); + } + chart.tooltip.SetActive(showTooltip); + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/DrawSeriePie.cs.meta b/Runtime/Internal/DrawSeriePie.cs.meta new file mode 100644 index 00000000..75bcb92c --- /dev/null +++ b/Runtime/Internal/DrawSeriePie.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d5fa46fc54af9401796fc8691221e526 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/DrawSerieRadar.cs b/Runtime/Internal/DrawSerieRadar.cs new file mode 100644 index 00000000..9120a8f2 --- /dev/null +++ b/Runtime/Internal/DrawSerieRadar.cs @@ -0,0 +1,762 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using XUGL; +using System.Collections.Generic; + +namespace XCharts +{ + internal class DrawSerieRadar : IDrawSerie + { + public BaseChart chart; + private const string INDICATOR_TEXT = "indicator"; + private bool m_IsEnterLegendButtom; + private bool m_RadarsDirty; + Dictionary<string, int> serieNameSet = new Dictionary<string, int>(); + + public DrawSerieRadar(BaseChart chart) + { + this.chart = chart; + } + + public void InitComponent() + { + InitIndicator(); + } + + public void CheckComponent() + { + var anyDirty = IsAnyRadarDirty(); + if (m_RadarsDirty || anyDirty) + { + InitIndicator(); + chart.RefreshBasePainter(); + chart.tooltip.UpdateToTop(); + if (anyDirty) + { + foreach (var radar in chart.radars) + { + radar.ClearDirty(); + } + } + m_RadarsDirty = false; + } + } + + public void Update() + { + } + + public void DrawBase(VertexHelper vh) + { + serieNameSet.Clear(); + for (int i = 0; i < chart.radars.Count; i++) + { + var radar = chart.radars[i]; + if (!radar.show) continue; + radar.index = i; + radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight); + if (radar.shape == Radar.Shape.Circle) + { + DrawCricleRadar(vh, radar); + } + else + { + DrawRadar(vh, radar); + } + } + } + + public void DrawSerie(VertexHelper vh, Serie serie) + { + if (serie.type != SerieType.Radar) return; + if (!serie.show) return; + switch (serie.radarType) + { + case RadarType.Multiple: + DrawMutipleRadar(vh, serie, serie.index); + break; + case RadarType.Single: + DrawSingleRadar(vh, serie, serie.index); + break; + } + } + + public void RefreshLabel() + { + for (int i = 0; i < chart.series.Count; i++) + { + var serie = chart.series.GetSerie(i); + if (serie.type != SerieType.Radar) continue; + if (!serie.show && serie.radarType != RadarType.Single) continue; + var radar = chart.GetRadar(serie.radarIndex); + if (radar == null) continue; + var center = radar.runtimeCenterPos; + for (int n = 0; n < serie.dataCount; n++) + { + var serieData = serie.data[n]; + if (serieData.labelObject == null) continue; + var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); + var labelPos = serieData.labelPosition; + if (serieLabel.margin != 0) + { + labelPos += serieLabel.margin * (labelPos - center).normalized; + } + serieData.labelObject.SetPosition(labelPos); + serieData.labelObject.UpdateIcon(serieData.iconStyle); + if (serie.show && serieLabel.show && serieData.canShowLabel) + { + var value = serieData.GetCurrData(1); + var max = radar.GetIndicatorMax(n); + SerieLabelHelper.ResetLabel(serieData, serieLabel, chart.theme, i); + serieData.SetLabelActive(serieData.labelPosition != Vector3.zero); + serieData.labelObject.SetLabelPosition(serieLabel.offset); + var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, max, serieLabel); + if (serieData.labelObject.SetText(content)) + { + chart.RefreshPainter(serie); + } + } + else + { + serieData.SetLabelActive(false); + } + } + } + } + + public bool CheckTootipArea(Vector2 local) + { + if (m_IsEnterLegendButtom) return false; + if (!IsInRadar(local)) return false; + bool highlight = false; + chart.tooltip.ClearValue(); + for (int i = 0; i < chart.series.Count; i++) + { + var serie = chart.series.GetSerie(i); + if (!serie.show || serie.type != SerieType.Radar) continue; + var radar = chart.radars[serie.radarIndex]; + var dist = Vector2.Distance(radar.runtimeCenterPos, local); + if (dist > radar.runtimeRadius + serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize)) + { + continue; + } + switch (serie.radarType) + { + case RadarType.Multiple: + for (int n = 0; n < serie.data.Count; n++) + { + var posKey = i * 1000 + n; + if (radar.runtimeDataPosList.ContainsKey(posKey)) + { + var posList = radar.runtimeDataPosList[posKey]; + var symbolSize = serie.symbol.GetSize(serie.data[n].data, chart.theme.serie.lineSymbolSize); + for (int k = 0; k < posList.Count; k++) + { + if (Vector2.Distance(posList[k], local) <= symbolSize * 1.3f) + { + chart.tooltip.runtimeDataIndex[0] = i; + chart.tooltip.runtimeDataIndex[1] = n; + if (chart.tooltip.runtimeDataIndex.Count >= 3) + chart.tooltip.runtimeDataIndex[2] = k; + else + chart.tooltip.runtimeDataIndex.Add(k); + highlight = true; + break; + } + } + } + } + break; + case RadarType.Single: + for (int n = 0; n < serie.data.Count; n++) + { + var serieData = serie.data[n]; + var symbolSize = serie.symbol.GetSize(serie.data[n].data, chart.theme.serie.lineSymbolSize); + if (Vector2.Distance(serieData.labelPosition, local) <= symbolSize * 1.3f) + { + chart.tooltip.runtimeDataIndex[0] = i; + chart.tooltip.runtimeDataIndex[1] = n; + highlight = true; + break; + } + } + break; + } + + } + + if (!highlight) + { + if (chart.tooltip.IsActive()) + { + chart.tooltip.SetActive(false); + chart.RefreshChart(); + } + } + else + { + chart.tooltip.UpdateContentPos(local + chart.tooltip.offset); + UpdateTooltip(); + chart.RefreshChart(); + } + return highlight; + } + + public bool OnLegendButtonClick(int index, string legendName, bool show) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Radar)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Radar)) return false; + LegendHelper.CheckDataShow(chart.series, legendName, show); + chart.UpdateLegendColor(legendName, show); + chart.RefreshChart(); + return true; + } + + public bool OnLegendButtonEnter(int index, string legendName) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Radar)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Radar)) return false; + m_IsEnterLegendButtom = true; + LegendHelper.CheckDataHighlighted(chart.series, legendName, true); + chart.RefreshChart(); + return true; + } + + public bool OnLegendButtonExit(int index, string legendName) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Radar)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Radar)) return false; + m_IsEnterLegendButtom = false; + LegendHelper.CheckDataHighlighted(chart.series, legendName, false); + chart.RefreshChart(); + return true; + } + + public void OnPointerDown(PointerEventData eventData) + { + } + + private void InitIndicator() + { + ChartHelper.HideAllObject(chart.transform, INDICATOR_TEXT); + for (int n = 0; n < chart.radars.Count; n++) + { + Radar radar = chart.radars[n]; + radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight); + int indicatorNum = radar.indicatorList.Count; + float txtWid = 100; + float txtHig = 20; + for (int i = 0; i < indicatorNum; i++) + { + var indicator = radar.indicatorList[i]; + var pos = radar.GetIndicatorPosition(i); + var textStyle = indicator.textStyle; + var objName = INDICATOR_TEXT + "_" + n + "_" + i; + var txt = ChartHelper.AddTextObject(objName, chart.transform, new Vector2(0.5f, 0.5f), + new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig), + textStyle, chart.theme.radar); + txt.gameObject.hideFlags = chart.chartHideFlags; + txt.SetAlignment(TextAnchor.MiddleCenter); + txt.SetText(radar.indicatorList[i].name); + txt.SetActive(radar.indicator); + var offset = new Vector3(textStyle.offset.x, textStyle.offset.y); + AxisHelper.AdjustCircleLabelPos(txt, pos, radar.runtimeCenterPos, txtHig, offset); + } + } + } + + private void DrawMutipleRadar(VertexHelper vh, Serie serie, int i) + { + if (!serie.show) return; + var radar = chart.GetRadar(serie.radarIndex); + if (radar == null) return; + var startPoint = Vector3.zero; + var toPoint = Vector3.zero; + var firstPoint = Vector3.zero; + var indicatorNum = radar.indicatorList.Count; + var angle = 2 * Mathf.PI / indicatorNum; + var centerPos = radar.runtimeCenterPos; + var serieNameCount = -1; + serie.animation.InitProgress(1, 0, 1); + if (!chart.IsActive(i) || serie.animation.HasFadeOut()) + { + return; + } + var rate = serie.animation.GetCurrRate(); + var dataChanging = false; + var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); + SerieHelper.GetAllMinMaxData(serie, radar.ceilRate); + for (int j = 0; j < serie.data.Count; j++) + { + var serieData = serie.data[j]; + int key = i * 1000 + j; + if (!radar.runtimeDataPosList.ContainsKey(key)) + { + radar.runtimeDataPosList.Add(i * 1000 + j, new List<Vector3>(serieData.data.Count)); + } + else + { + radar.runtimeDataPosList[key].Clear(); + } + string dataName = serieData.name; + int serieIndex = 0; + if (string.IsNullOrEmpty(dataName)) + { + serieNameCount++; + serieIndex = serieNameCount; + } + else if (!serieNameSet.ContainsKey(dataName)) + { + serieNameSet.Add(dataName, serieNameCount); + serieNameCount++; + serieIndex = serieNameCount; + } + else + { + serieIndex = serieNameSet[dataName]; + } + if (!serieData.show) + { + continue; + } + var isHighlight = IsHighlight(radar, serie, serieData, j, 0); + var areaColor = SerieHelper.GetAreaColor(serie, chart.theme, serieIndex, isHighlight); + var areaToColor = SerieHelper.GetAreaToColor(serie, chart.theme, serieIndex, isHighlight); + var lineColor = SerieHelper.GetLineColor(serie, chart.theme, serieIndex, isHighlight); + var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth); + int dataCount = radar.indicatorList.Count; + List<Vector3> pointList = radar.runtimeDataPosList[key]; + for (int n = 0; n < dataCount; n++) + { + if (n >= serieData.data.Count) break; + float max = radar.GetIndicatorMax(n); + float value = serieData.GetCurrData(n, dataChangeDuration); + if (serieData.IsDataChanged()) dataChanging = true; + if (max == 0) + { + max = serie.runtimeDataMax; + } + var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max + : radar.runtimeDataRadius * value / max; + var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle; + radius *= rate; + if (n == 0) + { + startPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle), + centerPos.y + radius * Mathf.Cos(currAngle)); + firstPoint = startPoint; + } + else + { + toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle), + centerPos.y + radius * Mathf.Cos(currAngle)); + if (serie.areaStyle.show) + { + UGL.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor); + } + if (serie.lineStyle.show) + { + ChartDrawer.DrawLineStyle(vh, serie.lineStyle.type, lineWidth, startPoint, toPoint, lineColor); + } + startPoint = toPoint; + } + pointList.Add(startPoint); + } + if (serie.areaStyle.show) + { + UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); + } + if (serie.lineStyle.show) + { + ChartDrawer.DrawLineStyle(vh, serie.lineStyle.type, lineWidth, startPoint, firstPoint, lineColor); + } + if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None) + { + for (int m = 0; m < pointList.Count; m++) + { + var point = pointList[m]; + isHighlight = IsHighlight(radar, serie, serieData, j, m); + var symbolSize = isHighlight + ? serie.symbol.GetSelectedSize(null, chart.theme.serie.lineSymbolSelectedSize) + : serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize); + var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight); + var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); + chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor, + symbolToColor, serie.symbol.gap, cornerRadius); + } + } + } + if (!serie.animation.IsFinish()) + { + serie.animation.CheckProgress(1); + chart.RefreshPainter(serie); + } + if (dataChanging) + { + chart.RefreshPainter(serie); + } + } + + private bool IsHighlight(Radar radar, Serie serie, SerieData serieData, int dataIndex, int dimension) + { + if (serie.highlighted || serieData.highlighted) return true; + if (!chart.tooltip.show) return false; + var selectedSerieIndex = chart.tooltip.runtimeDataIndex[0]; + if (selectedSerieIndex < 0) return false; + if (chart.series.GetSerie(selectedSerieIndex).radarIndex != serie.radarIndex) return false; + switch (serie.radarType) + { + case RadarType.Multiple: + if (radar.isAxisTooltip) + { + var selectedDimension = chart.tooltip.runtimeDataIndex[2]; + return selectedDimension == dimension; + } + else if (chart.tooltip.runtimeDataIndex.Count >= 2) + { + return chart.tooltip.runtimeDataIndex[0] == serie.index && chart.tooltip.runtimeDataIndex[1] == dataIndex; + } + else + { + return false; + } + case RadarType.Single: + return chart.tooltip.runtimeDataIndex[1] == dataIndex; + } + return false; + } + + private void DrawSingleRadar(VertexHelper vh, Serie serie, int i) + { + var startPoint = Vector3.zero; + var toPoint = Vector3.zero; + var firstPoint = Vector3.zero; + + var radar = chart.radars[serie.radarIndex]; + var indicatorNum = radar.indicatorList.Count; + var angle = 2 * Mathf.PI / indicatorNum; + var centerPos = radar.runtimeCenterPos; + var serieNameCount = -1; + serie.animation.InitProgress(1, 0, 1); + if (!chart.IsActive(i) || serie.animation.HasFadeOut()) + { + return; + } + var rate = serie.animation.GetCurrRate(); + var dataChanging = false; + var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); + int key = i * 1000; + if (!radar.runtimeDataPosList.ContainsKey(key)) + { + radar.runtimeDataPosList.Add(i * 1000, new List<Vector3>(serie.dataCount)); + } + else + { + radar.runtimeDataPosList[key].Clear(); + } + var pointList = radar.runtimeDataPosList[key]; + var startIndex = GetStartShowIndex(serie); + var endIndex = GetEndShowIndex(serie); + SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate); + for (int j = 0; j < serie.data.Count; j++) + { + var serieData = serie.data[j]; + serieData.index = j; + string dataName = serieData.name; + int serieIndex = 0; + if (string.IsNullOrEmpty(dataName)) + { + serieNameCount++; + serieIndex = serieNameCount; + } + else if (!serieNameSet.ContainsKey(dataName)) + { + serieNameSet.Add(dataName, serieNameCount); + serieNameCount++; + serieIndex = serieNameCount; + } + else + { + serieIndex = serieNameSet[dataName]; + } + if (!serieData.show) + { + serieData.labelPosition = Vector3.zero; + continue; + } + var isHighlight = IsHighlight(radar, serie, serieData, j, 0); + var areaColor = SerieHelper.GetAreaColor(serie, chart.theme, serieIndex, isHighlight); + var areaToColor = SerieHelper.GetAreaToColor(serie, chart.theme, serieIndex, isHighlight); + var lineColor = SerieHelper.GetLineColor(serie, chart.theme, serieIndex, isHighlight); + int dataCount = radar.indicatorList.Count; + var index = serieData.index; + var p = radar.runtimeCenterPos; + var max = radar.GetIndicatorMax(index); + var value = serieData.GetCurrData(1, dataChangeDuration); + if (serieData.IsDataChanged()) dataChanging = true; + if (max == 0) + { + max = serie.runtimeDataMax; + } + var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max + : radar.runtimeDataRadius * value / max; + var currAngle = (index + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle; + radius *= rate; + if (index == startIndex) + { + startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), + p.y + radius * Mathf.Cos(currAngle)); + firstPoint = startPoint; + } + else + { + toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), + p.y + radius * Mathf.Cos(currAngle)); + if (serie.areaStyle.show) + { + UGL.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor); + } + if (serie.lineStyle.show) + { + ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor, + chart.theme.serie.lineWidth, LineStyle.Type.Solid); + } + startPoint = toPoint; + } + serieData.labelPosition = startPoint; + pointList.Add(startPoint); + + if (serie.areaStyle.show && j == endIndex) + { + UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); + } + if (serie.lineStyle.show && j == endIndex) + { + ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor, + chart.theme.serie.lineWidth, LineStyle.Type.Solid); + } + } + if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None) + { + for (int j = 0; j < serie.data.Count; j++) + { + var serieData = serie.data[j]; + if (!serieData.show) continue; + var isHighlight = serie.highlighted || serieData.highlighted || + (chart.tooltip.show && chart.tooltip.runtimeDataIndex[0] == i && chart.tooltip.runtimeDataIndex[1] == j); + var serieIndex = serieData.index; + var symbolSize = isHighlight + ? serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize) + : serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize); + var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight); + var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); + chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.labelPosition, symbolColor, + symbolToColor, serie.symbol.gap, cornerRadius); + } + } + if (!serie.animation.IsFinish()) + { + serie.animation.CheckProgress(1); + chart.RefreshPainter(serie); + } + if (dataChanging) + { + chart.RefreshPainter(serie); + } + } + + private int GetStartShowIndex(Serie serie) + { + for (int i = 0; i < serie.dataCount; i++) + { + if (serie.data[i].show) return i; + } + return 0; + } + private int GetEndShowIndex(Serie serie) + { + for (int i = serie.dataCount - 1; i >= 0; i--) + { + if (serie.data[i].show) return i; + } + return 0; + } + + private void DrawRadarSymbol(VertexHelper vh, Serie serie, SerieData serieData, int serieIndex, bool isHighlight, + List<Vector3> pointList) + { + if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None) + { + var symbolSize = isHighlight + ? serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize) + : serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize); + var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight); + var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight); + var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); + foreach (var point in pointList) + { + chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor, + symbolToColor, serie.symbol.gap, cornerRadius); + } + } + } + + private void DrawRadar(VertexHelper vh, Radar radar) + { + if (!radar.splitLine.show && !radar.splitArea.show) + { + return; + } + float insideRadius = 0, outsideRadius = 0; + float block = radar.runtimeRadius / radar.splitNumber; + int indicatorNum = radar.indicatorList.Count; + Vector3 p1, p2, p3, p4; + Vector3 p = radar.runtimeCenterPos; + float angle = 2 * Mathf.PI / indicatorNum; + var lineColor = radar.axisLine.GetColor(chart.theme.radar.lineColor); + var lineWidth = radar.axisLine.GetWidth(chart.theme.radar.lineWidth); + var lineType = radar.axisLine.GetType(chart.theme.radar.lineType); + var splitLineColor = radar.splitLine.GetColor(chart.theme.radar.splitLineColor); + var splitLineWidth = radar.splitLine.GetWidth(chart.theme.radar.splitLineWidth); + var splitLineType = radar.splitLine.GetType(chart.theme.radar.splitLineType); + for (int i = 0; i < radar.splitNumber; i++) + { + var isLast = i == radar.splitNumber - 1; + var color = radar.splitArea.GetColor(i, chart.theme.radar); + outsideRadius = insideRadius + block; + p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0)); + p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0)); + for (int j = 0; j <= indicatorNum; j++) + { + float currAngle = j * angle; + p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), + p.y + outsideRadius * Mathf.Cos(currAngle)); + p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle), + p.y + insideRadius * Mathf.Cos(currAngle)); + if (radar.splitArea.show) + { + UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, color); + } + if (radar.splitLine.NeedShow(i)) + { + if (isLast) + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, p2, p3, lineColor); + else + ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p2, p3, splitLineColor); + } + p1 = p4; + p2 = p3; + } + insideRadius = outsideRadius; + } + for (int j = 0; j <= indicatorNum; j++) + { + float currAngle = j * angle; + p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), + p.y + outsideRadius * Mathf.Cos(currAngle)); + if (radar.splitLine.show) + { + ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p, p3, splitLineColor); + } + } + } + + private void DrawCricleRadar(VertexHelper vh, Radar radar) + { + if (!radar.splitLine.show && !radar.splitArea.show) + { + return; + } + float insideRadius = 0, outsideRadius = 0; + float block = radar.runtimeRadius / radar.splitNumber; + int indicatorNum = radar.indicatorList.Count; + Vector3 p = radar.runtimeCenterPos; + Vector3 p1; + float angle = 2 * Mathf.PI / indicatorNum; + var lineColor = radar.axisLine.GetColor(chart.theme.radar.lineColor); + var lineWidth = radar.splitLine.GetWidth(chart.theme.radar.splitLineWidth); + for (int i = 0; i < radar.splitNumber; i++) + { + Color color = radar.splitArea.color[i % radar.splitArea.color.Count]; + outsideRadius = insideRadius + block; + if (radar.splitArea.show) + { + UGL.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear, + 0, 360, chart.settings.cicleSmoothness); + } + if (radar.splitLine.show) + { + UGL.DrawEmptyCricle(vh, p, outsideRadius, lineWidth, lineColor, + Color.clear, chart.settings.cicleSmoothness); + } + insideRadius = outsideRadius; + } + for (int j = 0; j <= indicatorNum; j++) + { + float currAngle = j * angle; + p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), + p.y + outsideRadius * Mathf.Cos(currAngle)); + if (radar.splitLine.show) + { + UGL.DrawLine(vh, p, p1, lineWidth / 2, lineColor); + } + } + } + + private bool IsInRadar(Vector2 local) + { + foreach (var radar in chart.radars) + { + var dist = Vector2.Distance(radar.runtimeCenterPos, local); + if (dist < radar.runtimeRadius + chart.theme.serie.lineSymbolSize) + { + return true; + } + } + return false; + } + + protected void UpdateTooltip() + { + int serieIndex = chart.tooltip.runtimeDataIndex[0]; + if (serieIndex < 0) + { + if (chart.tooltip.IsActive()) + { + chart.tooltip.SetActive(false); + chart.RefreshChart(); + } + return; + } + chart.tooltip.SetActive(true); + var serie = chart.series.GetSerie(serieIndex); + var radar = chart.radars[serie.radarIndex]; + var dataIndex = chart.tooltip.runtimeDataIndex[1]; + var content = TooltipHelper.GetFormatterContent(chart.tooltip, dataIndex, chart.series, chart.theme, + null, null, false, radar); + TooltipHelper.SetContentAndPosition(chart.tooltip, content, chart.chartRect); + } + + private bool IsAnyRadarDirty() + { + foreach (var radar in chart.radars) + { + if (radar.anyDirty) return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/DrawSerieRadar.cs.meta b/Runtime/Internal/DrawSerieRadar.cs.meta new file mode 100644 index 00000000..38e2568c --- /dev/null +++ b/Runtime/Internal/DrawSerieRadar.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8b5a823d3c59a461f872211f9580a28c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/DrawSerieRing.cs b/Runtime/Internal/DrawSerieRing.cs new file mode 100644 index 00000000..21cc9e26 --- /dev/null +++ b/Runtime/Internal/DrawSerieRing.cs @@ -0,0 +1,361 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using XUGL; + +namespace XCharts +{ + internal class DrawSerieRing : IDrawSerie + { + public BaseChart chart; + private bool m_UpdateTitleText = false; + private bool m_UpdateLabelText = false; + private bool m_IsEnterLegendButtom; + + public DrawSerieRing(BaseChart chart) + { + this.chart = chart; + } + + public void InitComponent() + { + } + + public void CheckComponent() + { + } + + public void Update() + { + if (m_UpdateTitleText) + { + m_UpdateTitleText = false; + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Ring) + { + TitleStyleHelper.UpdateTitleText(serie); + } + } + } + if (m_UpdateLabelText) + { + m_UpdateLabelText = false; + foreach (var serie in chart.series.list) + { + if (serie.type == SerieType.Ring) + { + SerieLabelHelper.SetRingLabelText(serie, chart.theme); + } + } + } + } + + public void DrawBase(VertexHelper vh) + { + } + + public void DrawSerie(VertexHelper vh, Serie serie) + { + if (serie.type != SerieType.Ring) return; + if (!serie.show || serie.animation.HasFadeOut()) return; + var data = serie.data; + serie.animation.InitProgress(data.Count, serie.startAngle, serie.startAngle + 360); + SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); + TitleStyleHelper.CheckTitle(serie, ref chart.m_ReinitTitle, ref m_UpdateTitleText); + SerieLabelHelper.CheckLabel(serie, ref chart.m_ReinitLabel, ref m_UpdateLabelText); + var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); + var ringWidth = serie.runtimeOutsideRadius - serie.runtimeInsideRadius; + var dataChanging = false; + for (int j = 0; j < data.Count; j++) + { + var serieData = data[j]; + if (!serieData.show) continue; + if (serieData.IsDataChanged()) dataChanging = true; + var value = serieData.GetFirstData(dataChangeDuration); + var max = serieData.GetLastData(); + var degree = 360 * value / max; + var startDegree = GetStartAngle(serie); + var toDegree = GetToAngle(serie, degree); + var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted); + var itemColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, j, serieData.highlighted); + var itemToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, j, serieData.highlighted); + var outsideRadius = serie.runtimeOutsideRadius - j * (ringWidth + serie.ringGap); + var insideRadius = outsideRadius - ringWidth; + var centerRadius = (outsideRadius + insideRadius) / 2; + var borderWidth = itemStyle.borderWidth; + var borderColor = itemStyle.borderColor; + var roundCap = serie.roundCap && insideRadius > 0; + + serieData.runtimePieStartAngle = serie.clockwise ? startDegree : toDegree; + serieData.runtimePieToAngle = serie.clockwise ? toDegree : startDegree; + serieData.runtimePieInsideRadius = insideRadius; + serieData.runtimePieOutsideRadius = outsideRadius; + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, outsideRadius, itemColor, itemToColor, + Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, chart.settings.cicleSmoothness, + roundCap, serie.clockwise); + DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1); + UpateLabelPosition(serie, serieData, j, startDegree, toDegree, centerRadius); + } + if (!serie.animation.IsFinish()) + { + serie.animation.CheckProgress(360); + chart.RefreshChart(); + } + if (dataChanging) + { + chart.RefreshChart(); + } + } + + public void RefreshLabel() + { + } + + public bool CheckTootipArea(Vector2 local) + { + if (!PointerIsInRingSerie(chart.series, local)) return false; + if (m_IsEnterLegendButtom) return false; + bool selected = false; + chart.tooltip.runtimeDataIndex.Clear(); + foreach (var serie in chart.series.list) + { + int index = GetRingIndex(serie, local); + chart.tooltip.runtimeDataIndex.Add(index); + if (serie.type != SerieType.Ring) continue; + bool refresh = false; + for (int j = 0; j < serie.data.Count; j++) + { + var serieData = serie.data[j]; + if (serieData.highlighted != (j == index)) refresh = true; + serieData.highlighted = j == index; + } + if (index >= 0) selected = true; + if (refresh) chart.RefreshChart(); + } + if (selected) + { + chart.tooltip.UpdateContentPos(local + chart.tooltip.offset); + UpdateTooltip(); + } + else if (chart.tooltip.IsActive()) + { + chart.tooltip.SetActive(false); + chart.RefreshChart(); + } + return true; + } + + public bool OnLegendButtonClick(int index, string legendName, bool show) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Ring)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Ring)) return false; + LegendHelper.CheckDataShow(chart.series, legendName, show); + chart.UpdateLegendColor(legendName, show); + chart.RefreshChart(); + return true; + } + + public bool OnLegendButtonEnter(int index, string legendName) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Ring)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Ring)) return false; + m_IsEnterLegendButtom = true; + LegendHelper.CheckDataHighlighted(chart.series, legendName, true); + chart.RefreshChart(); + return true; + } + + public bool OnLegendButtonExit(int index, string legendName) + { + if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Ring)) return false; + if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Ring)) return false; + m_IsEnterLegendButtom = false; + LegendHelper.CheckDataHighlighted(chart.series, legendName, false); + chart.RefreshChart(); + return true; + } + + public void OnPointerDown(PointerEventData eventData) + { + } + + private float GetStartAngle(Serie serie) + { + return serie.clockwise ? serie.startAngle : 360 - serie.startAngle; + } + + private float GetToAngle(Serie serie, float angle) + { + var toAngle = angle + serie.startAngle; + if (!serie.clockwise) + { + toAngle = 360 - angle - serie.startAngle; + } + if (!serie.animation.IsFinish()) + { + var currAngle = serie.animation.GetCurrDetail(); + if (serie.clockwise) + { + toAngle = toAngle > currAngle ? currAngle : toAngle; + } + else + { + toAngle = toAngle < 360 - currAngle ? 360 - currAngle : toAngle; + } + } + return toAngle; + } + + private void DrawCenter(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, bool last) + { + var itemStyle = SerieHelper.GetItemStyle(serie, serieData); + if (!ChartHelper.IsClearColor(itemStyle.centerColor) && last) + { + var radius = insideRadius - itemStyle.centerGap; + var smoothness = chart.settings.cicleSmoothness; + UGL.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, smoothness); + } + } + + private void UpateLabelPosition(Serie serie, SerieData serieData, int index, float startAngle, + float toAngle, float centerRadius) + { + if (!serie.label.show) return; + if (serieData.labelObject == null) return; + switch (serie.label.position) + { + case SerieLabel.Position.Center: + serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset; + break; + case SerieLabel.Position.Bottom: + var px1 = Mathf.Sin(startAngle * Mathf.Deg2Rad) * centerRadius; + var py1 = Mathf.Cos(startAngle * Mathf.Deg2Rad) * centerRadius; + var xDiff = serie.clockwise ? -serie.label.margin : serie.label.margin; + serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px1 + xDiff, py1); + break; + case SerieLabel.Position.Top: + startAngle += serie.clockwise ? -serie.label.margin : serie.label.margin; + toAngle += serie.clockwise ? serie.label.margin : -serie.label.margin; + var px2 = Mathf.Sin(toAngle * Mathf.Deg2Rad) * centerRadius; + var py2 = Mathf.Cos(toAngle * Mathf.Deg2Rad) * centerRadius; + serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px2, py2); + break; + } + serieData.labelObject.SetLabelPosition(serieData.labelPosition); + } + + private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius) + { + var itemStyle = SerieHelper.GetItemStyle(serie, serieData); + var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, index, false); + if (itemStyle.backgroundWidth != 0) + { + var centerRadius = (outsideRadius + insideRadius) / 2; + var inradius = centerRadius - itemStyle.backgroundWidth / 2; + var outradius = centerRadius + itemStyle.backgroundWidth / 2; + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, inradius, + outradius, backgroundColor, Color.clear, chart.settings.cicleSmoothness); + } + else + { + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, + outsideRadius, backgroundColor, Color.clear, chart.settings.cicleSmoothness); + } + } + + private void DrawBorder(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, float outsideRadius) + { + var itemStyle = SerieHelper.GetItemStyle(serie, serieData); + if (itemStyle.show && itemStyle.borderWidth > 0 && !ChartHelper.IsClearColor(itemStyle.borderColor)) + { + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, outsideRadius, + outsideRadius + itemStyle.borderWidth, itemStyle.borderColor, + Color.clear, chart.settings.cicleSmoothness); + UGL.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, + insideRadius + itemStyle.borderWidth, itemStyle.borderColor, + Color.clear, chart.settings.cicleSmoothness); + } + } + + + private void DrawRoundCap(VertexHelper vh, Serie serie, Vector3 centerPos, Color color, + float insideRadius, float outsideRadius, ref float drawStartDegree, ref float drawEndDegree) + { + if (serie.roundCap && insideRadius > 0 && drawStartDegree != drawEndDegree) + { + var width = (outsideRadius - insideRadius) / 2; + var radius = insideRadius + width; + + var diffDegree = Mathf.Asin(width / radius) * Mathf.Rad2Deg; + drawStartDegree += serie.clockwise ? diffDegree : -diffDegree; + drawEndDegree -= serie.clockwise ? diffDegree : -diffDegree; + UGL.DrawRoundCap(vh, centerPos, width, radius, drawStartDegree, serie.clockwise, color, false); + UGL.DrawRoundCap(vh, centerPos, width, radius, drawEndDegree, serie.clockwise, color, true); + } + } + + private int GetRingIndex(Serie serie, Vector2 local) + { + if (serie.type != SerieType.Ring) return -1; + var dist = Vector2.Distance(local, serie.runtimeCenterPos); + if (dist > serie.runtimeOutsideRadius) return -1; + Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y); + float angle = VectorAngle(Vector2.up, dir); + for (int i = 0; i < serie.data.Count; i++) + { + var serieData = serie.data[i]; + if (dist >= serieData.runtimePieInsideRadius && + dist <= serieData.runtimePieOutsideRadius && + angle >= serieData.runtimePieStartAngle && + angle <= serieData.runtimePieToAngle) + { + return i; + } + } + return -1; + } + + private bool PointerIsInRingSerie(Series series, Vector2 local) + { + foreach (var serie in series.list) + { + if (serie.type != SerieType.Ring) continue; + if (GetRingIndex(serie, local) >= 0) return true; + } + return false; + } + + private float VectorAngle(Vector2 from, Vector2 to) + { + float angle; + + Vector3 cross = Vector3.Cross(from, to); + angle = Vector2.Angle(from, to); + angle = cross.z > 0 ? -angle : angle; + angle = (angle + 360) % 360; + return angle; + } + + private void UpdateTooltip() + { + bool showTooltip = false; + foreach (var serie in chart.series.list) + { + int index = chart.tooltip.runtimeDataIndex[serie.index]; + if (index < 0) continue; + showTooltip = true; + var content = TooltipHelper.GetFormatterContent(chart.tooltip, index, chart.series, chart.theme); + TooltipHelper.SetContentAndPosition(chart.tooltip, content.TrimStart(), chart.chartRect); + } + chart.tooltip.SetActive(showTooltip); + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/DrawSerieRing.cs.meta b/Runtime/Internal/DrawSerieRing.cs.meta new file mode 100644 index 00000000..a66a4b20 --- /dev/null +++ b/Runtime/Internal/DrawSerieRing.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27eff3714a61b44d2968104598e3566e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/DrawSerieTemplate.cs b/Runtime/Internal/DrawSerieTemplate.cs new file mode 100644 index 00000000..6483e037 --- /dev/null +++ b/Runtime/Internal/DrawSerieTemplate.cs @@ -0,0 +1,71 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using XUGL; + +namespace XCharts +{ + internal class DrawSerieTemplate : IDrawSerie + { + public BaseChart chart; + + public DrawSerieTemplate(BaseChart chart) + { + this.chart = chart; + } + + public void InitComponent() + { + } + public void CheckComponent() + { + } + + public void Update() + { + } + + public void DrawBase(VertexHelper vh) + { + } + + public void DrawSerie(VertexHelper vh, Serie serie) + { + } + + public void RefreshLabel() + { + } + + public bool CheckTootipArea(Vector2 local) + { + return false; + } + + public bool OnLegendButtonClick(int index, string legendName, bool show) + { + return false; + } + + public bool OnLegendButtonEnter(int index, string legendName) + { + return false; + } + + public bool OnLegendButtonExit(int index, string legendName) + { + return false; + } + + public void OnPointerDown(PointerEventData eventData) + { + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/DrawSerieTemplate.cs.meta b/Runtime/Internal/DrawSerieTemplate.cs.meta new file mode 100644 index 00000000..b56755ab --- /dev/null +++ b/Runtime/Internal/DrawSerieTemplate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35f409612108b4fdead9ddce4426c9b0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Helper/AxisHelper.cs b/Runtime/Internal/Helper/AxisHelper.cs index ee560d0e..5d72815b 100644 --- a/Runtime/Internal/Helper/AxisHelper.cs +++ b/Runtime/Internal/Helper/AxisHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Text; using UnityEngine; using UnityEngine.UI; @@ -12,10 +12,6 @@ namespace XCharts { public static class AxisHelper { - public static float GetTickWidth(Axis axis) - { - return axis.axisTick.width != 0 ? axis.axisTick.width : axis.axisLine.width; - } /// <summary> /// 包含箭头偏移的轴线长度 @@ -24,9 +20,9 @@ namespace XCharts /// <returns></returns> public static float GetAxisLineSymbolOffset(Axis axis) { - if (axis.axisLine.show && axis.axisLine.symbol && axis.axisLine.symbolOffset > 0) + if (axis.axisLine.show && axis.axisLine.showArrow && axis.axisLine.arrow.offset > 0) { - return axis.axisLine.symbolOffset; + return axis.axisLine.arrow.offset; } return 0; } @@ -115,7 +111,7 @@ namespace XCharts if (axis.type == Axis.AxisType.Value) { if (minValue == 0 && maxValue == 0) return string.Empty; - float value = 0; + var value = 0f; if (forcePercent) maxValue = 100; if (axis.interval > 0) { @@ -124,7 +120,7 @@ namespace XCharts } else { - value = (minValue + (maxValue - minValue) * index / split); + value = minValue + (maxValue - minValue) * index / split; if (!axis.clockwise && value != minValue) value = maxValue - value; } if (axis.inverse) @@ -133,6 +129,7 @@ namespace XCharts minValue = -minValue; maxValue = -maxValue; } + if (forcePercent) return string.Format("{0}%", (int)value); else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue); } @@ -324,11 +321,11 @@ namespace XCharts else return true; } - internal static void AdjustCircleLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) + internal static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) { - var txtWidth = txt.preferredWidth; - var sizeDelta = new Vector2(txtWidth, txt.preferredHeight); - txt.GetComponent<RectTransform>().sizeDelta = sizeDelta; + var txtWidth = txt.GetPreferredWidth(); + var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight()); + txt.SetSizeDelta(sizeDelta); var diff = pos.x - cenPos.x; if (diff < -1f) //left { @@ -343,14 +340,14 @@ namespace XCharts float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2; pos = new Vector3(pos.x, y); } - txt.transform.localPosition = pos + offset; + txt.SetLocalPosition(pos + offset); } - internal static void AdjustRadiusAxisLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) + internal static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) { - var txtWidth = txt.preferredWidth; - var sizeDelta = new Vector2(txtWidth, txt.preferredHeight); - txt.GetComponent<RectTransform>().sizeDelta = sizeDelta; + var txtWidth = txt.GetPreferredWidth(); + var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight()); + txt.SetSizeDelta(sizeDelta); var diff = pos.y - cenPos.y; if (diff > 20f) //left { @@ -365,7 +362,7 @@ namespace XCharts float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2; pos = new Vector3(pos.x, y); } - txt.transform.localPosition = pos; + txt.SetLocalPosition(pos); } } } \ No newline at end of file diff --git a/Runtime/Internal/Helper/ItemStyleHelper.cs b/Runtime/Internal/Helper/ItemStyleHelper.cs index e18b6996..c8576ff3 100644 --- a/Runtime/Internal/Helper/ItemStyleHelper.cs +++ b/Runtime/Internal/Helper/ItemStyleHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; diff --git a/Runtime/Internal/Helper/LegendHelper.cs b/Runtime/Internal/Helper/LegendHelper.cs index 446fe12d..7cb29792 100644 --- a/Runtime/Internal/Helper/LegendHelper.cs +++ b/Runtime/Internal/Helper/LegendHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; @@ -11,29 +11,29 @@ namespace XCharts { internal static class LegendHelper { - public static Color GetContentColor(Legend legend, ThemeInfo themeInfo, bool active) + public static Color GetContentColor(Legend legend, ChartTheme theme, bool active) { var textStyle = legend.textStyle; - if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : (Color)themeInfo.legendTextColor; - else return (Color)themeInfo.legendUnableColor; + if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor; + else return theme.legend.unableColor; } - public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, Series series, string legendName, bool active) + public static Color GetIconColor(Legend legend, int readIndex, ChartTheme theme, Series series, string legendName, bool active) { if (active) { if (legend.itemAutoColor || legend.GetIcon(readIndex) == null) { - return SeriesHelper.GetNameColor(series, readIndex, legendName, themeInfo); + return SeriesHelper.GetNameColor(series, readIndex, legendName, theme); } else return Color.white; } - else return (Color)themeInfo.legendUnableColor; + else return theme.legend.unableColor; } - public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo, - string content, Color itemColor, bool active) + public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, + ChartTheme theme, string content, Color itemColor, bool active) { var objName = i + "_" + legendName; var anchorMin = new Vector2(0, 0.5f); @@ -42,8 +42,7 @@ namespace XCharts var sizeDelta = new Vector2(100, 30); var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight); var textStyle = legend.textStyle; - var font = textStyle.font ? textStyle.font : themeInfo.font; - var contentColor = GetContentColor(legend, themeInfo, active); + var contentColor = GetContentColor(legend, theme, active); var objAnchorMin = new Vector2(0, 1); var objAnchorMax = new Vector2(0, 1); @@ -56,9 +55,10 @@ namespace XCharts ChartHelper.GetOrAddComponent<Button>(btnObj); ChartHelper.GetOrAddComponent<Image>(iconObj); ChartHelper.GetOrAddComponent<Image>(contentObj); - ChartHelper.AddTextObject("Text", contentObj.transform, font, contentColor, - TextAnchor.MiddleLeft, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, - textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing); + var txt = ChartHelper.AddTextObject("Text", contentObj.transform, anchorMin, anchorMax, pivot, sizeDelta, + textStyle, theme.legend); + txt.SetAlignment(TextAnchor.MiddleLeft); + txt.SetColor(contentColor); var item = new LegendItem(); item.index = i; item.name = objName; @@ -278,5 +278,30 @@ namespace XCharts } return show; } + + public static bool IsSerieLegend(Series series, string legendName, SerieType type) + { + foreach (var serie in series.list) + { + if (serie.type == type) + { + switch (serie.type) + { + case SerieType.Pie: + case SerieType.Radar: + case SerieType.Ring: + foreach (var serieData in serie.data) + { + if (legendName.Equals(serieData.name)) return true; + } + break; + default: + if (legendName.Equals(serie.name)) return true; + break; + } + } + } + return false; + } } } \ No newline at end of file diff --git a/Runtime/Internal/Helper/PolarHelper.cs b/Runtime/Internal/Helper/PolarHelper.cs index 589e6b72..07482db5 100644 --- a/Runtime/Internal/Helper/PolarHelper.cs +++ b/Runtime/Internal/Helper/PolarHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Runtime/Internal/Helper/SerieHelper.cs b/Runtime/Internal/Helper/SerieHelper.cs index 60d82c8c..048ee2b9 100644 --- a/Runtime/Internal/Helper/SerieHelper.cs +++ b/Runtime/Internal/Helper/SerieHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -11,7 +11,7 @@ namespace XCharts { public static partial class SerieHelper { - internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, + internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight, bool useDefault = true) { var color = ChartConst.clearColor32; @@ -43,7 +43,7 @@ namespace XCharts return color; } - internal static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight) + internal static Color32 GetItemColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight) { if (serie == null) return ChartConst.clearColor32; if (highlight) @@ -70,7 +70,7 @@ namespace XCharts } } - internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight) + internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight) { if (highlight) { @@ -174,7 +174,7 @@ namespace XCharts else return serie.symbol; } - internal static Color32 GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight) + internal static Color32 GetAreaColor(Serie serie, ChartTheme theme, int index, bool highlight) { var areaStyle = serie.areaStyle; var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : theme.GetColor(index); @@ -187,7 +187,7 @@ namespace XCharts return color; } - internal static Color32 GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight) + internal static Color32 GetAreaToColor(Serie serie, ChartTheme theme, int index, bool highlight) { var areaStyle = serie.areaStyle; if (!ChartHelper.IsClearColor(areaStyle.toColor)) @@ -207,7 +207,7 @@ namespace XCharts } } - internal static Color32 GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight) + internal static Color32 GetLineColor(Serie serie, ChartTheme theme, int index, bool highlight) { Color32 color = ChartConst.clearColor32; if (highlight) @@ -231,12 +231,11 @@ namespace XCharts return color; } - internal static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight, bool useLineWidth = true) + internal static float GetSymbolBorder(Serie serie, SerieData serieData, ChartTheme theme, bool highlight, bool useLineWidth = true) { var itemStyle = GetItemStyle(serie, serieData, highlight); if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth; - else if (serie.lineStyle.width != 0 && useLineWidth) return serie.lineStyle.width; - else return 0; + else return serie.lineStyle.GetWidth(theme.serie.lineWidth); } internal static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight) diff --git a/Runtime/Internal/Helper/SerieLabelHelper.cs b/Runtime/Internal/Helper/SerieLabelHelper.cs index 5585fad3..61cdf0c7 100644 --- a/Runtime/Internal/Helper/SerieLabelHelper.cs +++ b/Runtime/Internal/Helper/SerieLabelHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -42,7 +42,7 @@ namespace XCharts } } - public static void UpdateLabelText(Series series, ThemeInfo themeInfo, List<string> legendRealShowName) + public static void UpdateLabelText(Series series, ChartTheme theme, List<string> legendRealShowName) { foreach (var serie in series.list) { @@ -54,35 +54,35 @@ namespace XCharts SetGaugeLabelText(serie); break; case SerieType.Ring: - SetRingLabelText(serie, themeInfo); + SetRingLabelText(serie, theme); break; case SerieType.Liquid: - SetLiquidLabelText(serie, themeInfo, colorIndex); + SetLiquidLabelText(serie, theme, colorIndex); break; } } } - public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index) + public static Color GetLabelColor(Serie serie, ChartTheme theme, int index) { - if (!ChartHelper.IsClearColor(serie.label.color)) + if (!ChartHelper.IsClearColor(serie.label.textStyle.color)) { - return serie.label.color; + return serie.label.textStyle.color; } else { - return themeInfo.GetColor(index); + return theme.GetColor(index); } } - public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex) + public static void ResetLabel(SerieData serieData, SerieLabel label, ChartTheme theme, int colorIndex) { if (serieData.labelObject == null) return; if (serieData.labelObject.label == null) return; - serieData.labelObject.label.color = !ChartHelper.IsClearColor(label.color) ? label.color : - (Color)themeInfo.GetColor(colorIndex); - serieData.labelObject.label.fontSize = label.fontSize; - serieData.labelObject.label.fontStyle = label.fontStyle; + serieData.labelObject.label.SetColor(!ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color : + (Color)theme.GetColor(colorIndex)); + serieData.labelObject.label.SetFontSize(label.textStyle.GetFontSize(theme.common)); + serieData.labelObject.label.SetFontStyle(label.textStyle.fontStyle); } public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion) @@ -111,7 +111,7 @@ namespace XCharts } } - private static void SetGaugeLabelText(Serie serie) + public static void SetGaugeLabelText(Serie serie) { var serieData = serie.GetSerieData(0); if (serieData == null) return; @@ -121,13 +121,13 @@ namespace XCharts var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total); serieData.labelObject.SetText(content); serieData.labelObject.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset); - if (!ChartHelper.IsClearColor(serie.label.color)) + if (!ChartHelper.IsClearColor(serie.label.textStyle.color)) { - serieData.labelObject.label.color = serie.label.color; + serieData.labelObject.label.SetColor(serie.label.textStyle.color); } } - private static void SetRingLabelText(Serie serie, ThemeInfo themeInfo) + public static void SetRingLabelText(Serie serie, ChartTheme theme) { for (int i = 0; i < serie.dataCount; i++) { @@ -145,7 +145,7 @@ namespace XCharts var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total); serieData.SetLabelActive(true); serieData.labelObject.SetText(content); - serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, i)); + serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, i)); if (serie.label.position == SerieLabel.Position.Bottom) { @@ -163,7 +163,7 @@ namespace XCharts } } - private static void SetLiquidLabelText(Serie serie, ThemeInfo themeInfo, int colorIndex) + public static void SetLiquidLabelText(Serie serie, ChartTheme theme, int colorIndex) { var serieData = serie.GetSerieData(0); if (serieData == null) return; @@ -180,7 +180,7 @@ namespace XCharts var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total); serieData.SetLabelActive(true); serieData.labelObject.SetText(content); - serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, colorIndex)); + serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, colorIndex)); serieData.labelObject.SetLabelPosition(serieData.labelPosition + serieLabel.offset); } } @@ -220,7 +220,7 @@ namespace XCharts } var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4; - r4 += serieData.labelObject.label.preferredWidth / 2; + r4 += serieData.labelObject.label.GetPreferredWidth() / 2; serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4; } else @@ -228,7 +228,7 @@ namespace XCharts labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1; labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad), serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad)); - float labelWidth = serieData.labelObject.label.preferredWidth; + float labelWidth = serieData.labelObject.label.GetPreferredWidth(); serieData.labelPosition = labelCenter; } break; @@ -280,7 +280,7 @@ namespace XCharts } else if (serieData.labelPosition.x != 0) { - float hig = serieLabel.fontSize; + float hig = serieLabel.textStyle.fontSize; if (lastCheckPos.y - serieData.labelPosition.y < hig) { var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1; diff --git a/Runtime/Internal/Helper/SeriesHelper.cs b/Runtime/Internal/Helper/SeriesHelper.cs index a5dff96a..aeca863f 100644 --- a/Runtime/Internal/Helper/SeriesHelper.cs +++ b/Runtime/Internal/Helper/SeriesHelper.cs @@ -1,16 +1,16 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; namespace XCharts { - internal static class SeriesHelper + public static class SeriesHelper { public static bool IsNeedLabelUpdate(Series series) { @@ -119,7 +119,7 @@ namespace XCharts } } - internal static Color GetNameColor(Series series, int index, string name, ThemeInfo theme) + internal static Color GetNameColor(Series series, int index, string name, ChartTheme theme) { Serie destSerie = null; SerieData destSerieData = null; @@ -188,6 +188,15 @@ namespace XCharts return false; } + internal static bool ContainsSerie(Series series, SerieType type) + { + foreach (var serie in series.list) + { + if (serie.type == type) return true; + } + return false; + } + internal static bool IsAnyUpdateAnimationSerie(Series series) { foreach (var serie in series.list) @@ -236,20 +245,6 @@ namespace XCharts return null; } - /// <summary> - /// 是否由系列在用指定索引的axis - /// </summary> - /// <param name="axisIndex"></param> - /// <returns></returns> - internal static bool IsUsedAxisIndex(Series series, int axisIndex) - { - foreach (var serie in series.list) - { - if (serie.axisIndex == axisIndex) return true; - } - return false; - } - private static HashSet<string> _setForStack = new HashSet<string>(); /// <summary> /// 是否由数据堆叠 @@ -393,6 +388,19 @@ namespace XCharts } } + internal static void UpdateStackDataList(Series series, Serie currSerie, DataZoom dataZoom, List<List<SerieData>> dataList) + { + dataList.Clear(); + for (int i = 0; i <= currSerie.index; i++) + { + var serie = series.list[i]; + if (serie.type == currSerie.type && ChartHelper.IsValueEqualsString(serie.stack, currSerie.stack)) + { + dataList.Add(serie.GetDataList(dataZoom)); + } + } + } + /// <summary> /// 获得维度X的最大最小值 /// </summary> @@ -401,9 +409,9 @@ namespace XCharts /// <param name="minVaule"></param> /// <param name="maxValue"></param> internal static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, out float minVaule, out float maxValue) + bool inverse, out float minVaule, out float maxValue, bool isPolar = false) { - GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue); + GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar); } /// <summary> @@ -414,15 +422,15 @@ namespace XCharts /// <param name="minVaule"></param> /// <param name="maxValue"></param> internal static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, out float minVaule, out float maxValue) + bool inverse, out float minVaule, out float maxValue, bool isPolar = false) { - GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue); + GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar); } private static Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>(); private static Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>(); internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, - bool inverse, bool yValue, out float minVaule, out float maxValue) + bool inverse, bool yValue, out float minVaule, out float maxValue, bool isPolar = false) { float min = int.MaxValue; float max = int.MinValue; @@ -432,8 +440,8 @@ namespace XCharts for (int i = 0; i < series.list.Count; i++) { var serie = series.GetSerie(i); - if (serie.axisIndex != axisIndex) continue; - + if ((isPolar && serie.polarIndex != axisIndex) + || (!isPolar && serie.yAxisIndex != axisIndex)) continue; if (series.IsActive(i)) { if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar)) @@ -463,7 +471,9 @@ namespace XCharts for (int i = 0; i < ss.Value.Count; i++) { var serie = ss.Value[i]; - if (serie.axisIndex != axisIndex || !series.IsActive(i)) continue; + if ((isPolar && serie.polarIndex != axisIndex) + || (!isPolar && serie.yAxisIndex != axisIndex) + || !series.IsActive(i)) continue; var showData = serie.GetDataList(dataZoom); if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar)) { diff --git a/Runtime/Internal/Helper/ThemeHelper.cs b/Runtime/Internal/Helper/ThemeHelper.cs index 8c17a5bc..293ec750 100644 --- a/Runtime/Internal/Helper/ThemeHelper.cs +++ b/Runtime/Internal/Helper/ThemeHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -11,10 +11,10 @@ namespace XCharts { internal static class ThemeHelper { - public static Color32 GetBackgroundColor(ThemeInfo themeInfo, Background background) + public static Color32 GetBackgroundColor(ChartTheme theme, Background background) { - if (background.show && background.runtimeActive && background.hideThemeBackgroundColor) return ChartConst.clearColor32; - else return themeInfo.backgroundColor; + if (background.show && background.hideThemeBackgroundColor) return ChartConst.clearColor32; + else return theme.backgroundColor; } } } \ No newline at end of file diff --git a/Runtime/Internal/Helper/TitleHelper.cs b/Runtime/Internal/Helper/TitleHelper.cs deleted file mode 100644 index 27ab0c41..00000000 --- a/Runtime/Internal/Helper/TitleHelper.cs +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ -using UnityEngine; -using UnityEngine.UI; - -namespace XCharts -{ - internal static class TitleHelper - { - public static Font GetTextFont(Title title, ThemeInfo themeInfo) - { - return (title.textStyle.font != null) ? title.textStyle.font : themeInfo.font; - } - - public static Color GetTextColor(Title title, ThemeInfo themeInfo) - { - return !ChartHelper.IsClearColor(title.textStyle.color) ? title.textStyle.color : (Color)themeInfo.titleTextColor; - } - - public static Font GetSubTextFont(Title title, ThemeInfo themeInfo) - { - return (title.subTextStyle.font != null) ? title.subTextStyle.font : themeInfo.font; - } - - public static Color GetSubTextColor(Title title, ThemeInfo themeInfo) - { - return !ChartHelper.IsClearColor(title.subTextStyle.color) ? title.subTextStyle.color : (Color)themeInfo.titleSubTextColor; - } - } -} \ No newline at end of file diff --git a/Runtime/Internal/Helper/TitleHelper.cs.meta b/Runtime/Internal/Helper/TitleHelper.cs.meta deleted file mode 100644 index 67f3117c..00000000 --- a/Runtime/Internal/Helper/TitleHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e22859d8021f6491f8ee08339b71e577 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Internal/Helper/TitleStyleHelper.cs b/Runtime/Internal/Helper/TitleStyleHelper.cs index fb3b43d2..e8fb1f26 100644 --- a/Runtime/Internal/Helper/TitleStyleHelper.cs +++ b/Runtime/Internal/Helper/TitleStyleHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; diff --git a/Runtime/Internal/Helper/TooltipHelper.cs b/Runtime/Internal/Helper/TooltipHelper.cs index 17c10922..a80853a0 100644 --- a/Runtime/Internal/Helper/TooltipHelper.cs +++ b/Runtime/Internal/Helper/TooltipHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Text; using UnityEngine; @@ -13,7 +13,7 @@ namespace XCharts internal static class TooltipHelper { private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, - ThemeInfo themeInfo) + ChartTheme theme) { if (!tooltip.runtimeSerieIndex.ContainsKey(serie.index)) return; var dataIndexList = tooltip.runtimeSerieIndex[serie.index]; @@ -29,7 +29,7 @@ namespace XCharts float xValue, yValue; serie.GetXYData(dataIndex, null, out xValue, out yValue); - sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>"); + sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>"); if (!string.IsNullOrEmpty(serieData.name)) sb.Append(serieData.name).Append(": "); sb.AppendFormat("({0},{1})", ChartCached.FloatToStr(xValue, numericFormatter), @@ -43,7 +43,7 @@ namespace XCharts private static void InitPieTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, - ThemeInfo themeInfo) + ChartTheme theme) { if (tooltip.runtimeDataIndex[serie.index] < 0) return; string key = serie.data[index].name; @@ -56,14 +56,14 @@ namespace XCharts { sb.Append(serie.name).Append(FormatterHelper.PH_NN); } - sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>"); + sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>"); if (!string.IsNullOrEmpty(key)) sb.Append(key).Append(": "); sb.Append(ChartCached.FloatToStr(value, numericFormatter)); } private static void InitRingTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, - ThemeInfo themeInfo) + ChartTheme theme) { var serieData = serie.GetSerieData(index); var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData); @@ -71,7 +71,7 @@ namespace XCharts sb.Length = 0; if (!string.IsNullOrEmpty(serieData.name)) { - sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>") + sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>") .Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter)); } else @@ -79,11 +79,36 @@ namespace XCharts sb.Append(ChartCached.FloatToStr(value, numericFormatter)); } } + private static void InitGaugeTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, + ChartTheme theme) + { + if (tooltip.runtimeGridIndex >= 0) return; + if (serie.index != index || serie.type != SerieType.Gauge) return; + var serieData = serie.GetSerieData(0); + var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData); + float value = serieData.data[1]; + sb.Length = 0; + if (!string.IsNullOrEmpty(serie.name)) + { + sb.Append(serie.name).Append("\n"); + } + if (!string.IsNullOrEmpty(serieData.name)) + { + //sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>") + sb.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter)); + } + else + { + sb.Append(ChartCached.FloatToStr(value, numericFormatter)); + } + } public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar, - ThemeInfo themeInfo) + ChartTheme theme) { + if(radar == null) return; if (!serie.show) return; + if (tooltip.runtimeGridIndex >= 0) return; if (serie.radarIndex != radar.index) return; var dataIndex = tooltip.runtimeDataIndex[1]; var serieData = serie.GetSerieData(dataIndex); @@ -109,7 +134,7 @@ namespace XCharts numericFormatter = GetItemNumericFormatter(tooltip, serie, sd); if (!first) sb.Append("\n"); first = false; - sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>"); + sb.Append("<color=#").Append(theme.GetColorStr(i)).Append(">● </color>"); if (string.IsNullOrEmpty(itemFormatter)) { if (string.IsNullOrEmpty(key)) key = radar.indicatorList[dataIndex].name; @@ -164,7 +189,7 @@ namespace XCharts } private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, - ThemeInfo themeInfo, bool isCartesian, DataZoom dataZoom = null) + ChartTheme theme, bool isCartesian, DataZoom dataZoom = null) { string key = serie.name; float xValue, yValue; @@ -185,38 +210,39 @@ namespace XCharts { var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent : ChartCached.FloatToStr(yValue, numericFormatter); - sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>") + sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>") .Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "") .Append(valueTxt); } } private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index, - string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null, bool isCartesian = false, + string category, ChartTheme theme = null, DataZoom dataZoom = null, bool isCartesian = false, Radar radar = null) { switch (serie.type) { case SerieType.Line: case SerieType.Bar: - InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom); + InitCoordinateTooltip(ref sb, tooltip, serie, index, theme, isCartesian, dataZoom); break; case SerieType.Scatter: case SerieType.EffectScatter: - InitScatterTooltip(ref sb, tooltip, serie, index, themeInfo); + InitScatterTooltip(ref sb, tooltip, serie, index, theme); break; case SerieType.Radar: - InitRadarTooltip(ref sb, tooltip, serie, radar, themeInfo); + InitRadarTooltip(ref sb, tooltip, serie, radar, theme); break; case SerieType.Pie: - InitPieTooltip(ref sb, tooltip, serie, index, themeInfo); + InitPieTooltip(ref sb, tooltip, serie, index, theme); break; case SerieType.Ring: - InitRingTooltip(ref sb, tooltip, serie, index, themeInfo); + InitRingTooltip(ref sb, tooltip, serie, index, theme); break; case SerieType.Heatmap: break; case SerieType.Gauge: + InitGaugeTooltip(ref sb, tooltip, serie, index, theme); break; } } @@ -236,7 +262,7 @@ namespace XCharts tooltip.UpdateContentPos(pos); } - public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo, AngleAxis angleAxis) + public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ChartTheme theme, AngleAxis angleAxis) { if (string.IsNullOrEmpty(tooltip.formatter)) { @@ -260,7 +286,7 @@ namespace XCharts { if (formatTitle) { - FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, themeInfo, null, null); + FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, theme, null, null); } var dataIndexList = tooltip.runtimeSerieIndex[serie.index]; @@ -274,7 +300,7 @@ namespace XCharts serie.GetXYData(dataIndex, null, out xValue, out yValue); if (string.IsNullOrEmpty(itemFormatter)) { - sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>"); + sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>"); if (!string.IsNullOrEmpty(serie.name)) sb.Append(serie.name).Append(": "); sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter)); @@ -286,9 +312,9 @@ namespace XCharts else { string content = itemFormatter; - FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, null, null); + FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, theme, null, null); var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : serie.index; - sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex))); + sb.Append(ChartCached.ColorToDotStr(theme.GetColor(dotColorIndex))); sb.Append(content); } } @@ -308,12 +334,12 @@ namespace XCharts else { string content = tooltip.formatter; - FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, themeInfo, null, null); + FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, theme, null, null); return content; } } - public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo, + public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ChartTheme theme, string category = null, DataZoom dataZoom = null, bool isCartesian = false, Radar radar = null) { if (string.IsNullOrEmpty(tooltip.formatter)) @@ -335,6 +361,7 @@ namespace XCharts for (int i = 0; i < series.Count; i++) { var serie = series.GetSerie(i); + if (tooltip.runtimeGridIndex >= 0 && serie.runtimeGridIndex != tooltip.runtimeGridIndex) continue; if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter) { if (serie.show && IsSelectedSerie(tooltip, serie.index)) @@ -344,24 +371,24 @@ namespace XCharts if (string.IsNullOrEmpty(itemFormatter)) { if (!first) sb.Append(FormatterHelper.PH_NN); - InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar); + InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, theme, dataZoom, isCartesian, radar); first = false; continue; } var itemTitle = title; if (!string.IsNullOrEmpty(itemTitle)) { - FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom); + FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom); sb.Append(itemTitle).Append(FormatterHelper.PH_NN); } var dataIndexList = tooltip.runtimeSerieIndex[serie.index]; foreach (var tempIndex in dataIndexList) { string content = itemFormatter; - var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom); + var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom); if (!foundDot) { - sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index))); + sb.Append(ChartCached.ColorToDotStr(theme.GetColor(serie.index))); } sb.Append(content).Append(FormatterHelper.PH_NN); } @@ -369,28 +396,38 @@ namespace XCharts } else if (IsNeedTooltipSerie(serie, tooltip)) { - var serieData = serie.GetSerieData(dataIndex, dataZoom); - if (serieData == null) continue; - var itemFormatter = GetItemFormatter(tooltip, serie, serieData); + var itemFormatter = string.Empty; + if (serie.type == SerieType.Gauge) + { + var serieData = serie.GetSerieData(0, dataZoom); + if (serieData == null) continue; + itemFormatter = GetItemFormatter(tooltip, serie, serieData); + } + else + { + var serieData = serie.GetSerieData(dataIndex, dataZoom); + if (serieData == null) continue; + itemFormatter = GetItemFormatter(tooltip, serie, serieData); + } needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar); if (formatTitle) { - FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom); + FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom); } if (serie.show) { if (string.IsNullOrEmpty(itemFormatter) || serie.type == SerieType.Radar) { if (!first) sb.Append(FormatterHelper.PH_NN); - InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar); + InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, theme, dataZoom, isCartesian, radar); first = false; continue; } string content = itemFormatter; - FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom); + FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom); if (!first) sb.Append(FormatterHelper.PH_NN); var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : i; - sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex))); + sb.Append(ChartCached.ColorToDotStr(theme.GetColor(dotColorIndex))); sb.Append(content); first = false; } @@ -416,7 +453,7 @@ namespace XCharts else { string content = tooltip.formatter; - FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, themeInfo, category, dataZoom); + FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, theme, category, dataZoom); return content; } } @@ -426,7 +463,14 @@ namespace XCharts //if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring) if (serie.type == SerieType.Pie || serie.type == SerieType.Ring) { - return tooltip.runtimeDataIndex[serie.index] >= 0; + if (serie.index < tooltip.runtimeDataIndex.Count) + return tooltip.runtimeDataIndex[serie.index] >= 0; + else + return false; + } + else if (serie.type == SerieType.Gauge) + { + return serie.index == tooltip.runtimeDataIndex[0]; } else { @@ -457,7 +501,7 @@ namespace XCharts else return tooltip.numericFormatter; } - public static Color32 GetLineColor(Tooltip tooltip, ThemeInfo theme) + public static Color32 GetLineColor(Tooltip tooltip, ChartTheme theme) { var lineStyle = tooltip.lineStyle; if (!ChartHelper.IsClearColor(lineStyle.color)) @@ -466,10 +510,34 @@ namespace XCharts } else { - var color = theme.tooltipLineColor; + var color = theme.tooltip.lineColor; ChartHelper.SetColorOpacity(ref color, lineStyle.opacity); return color; } } + + public static Color GetTexColor(Tooltip tooltip, ComponentTheme theme) + { + if (!ChartHelper.IsClearColor(tooltip.textStyle.color)) + { + return tooltip.textStyle.color; + } + else + { + return theme.textColor; + } + } + + public static Color GetTexBackgroundColor(Tooltip tooltip, ComponentTheme theme) + { + if (!ChartHelper.IsClearColor(tooltip.textStyle.backgroundColor)) + { + return tooltip.textStyle.backgroundColor; + } + else + { + return theme.textBackgroundColor; + } + } } } \ No newline at end of file diff --git a/Runtime/Internal/Helper/VesselHelper.cs b/Runtime/Internal/Helper/VesselHelper.cs index 97be43bd..016de48e 100644 --- a/Runtime/Internal/Helper/VesselHelper.cs +++ b/Runtime/Internal/Helper/VesselHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -12,12 +12,12 @@ namespace XCharts { public static class VesselHelper { - internal static Color32 GetColor(Vessel vessel, Serie serie, ThemeInfo themeInfo, List<string> legendRealShowName) + internal static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName) { if (serie != null && vessel.autoColor) { var colorIndex = legendRealShowName.IndexOf(serie.name); - return SerieHelper.GetItemColor(serie, null, themeInfo, colorIndex, false); + return SerieHelper.GetItemColor(serie, null, theme, colorIndex, false); } else { diff --git a/Runtime/Internal/Helper/VisualMapHelper.cs b/Runtime/Internal/Helper/VisualMapHelper.cs index 50c29233..c94b8803 100644 --- a/Runtime/Internal/Helper/VisualMapHelper.cs +++ b/Runtime/Internal/Helper/VisualMapHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using System.Collections.Generic; @@ -80,22 +80,24 @@ namespace XCharts case VisualMap.Direction.X: var min = axis.runtimeMinValue; var max = axis.runtimeMaxValue; - value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min); + var grid = chart.GetAxisGridOrDefault(axis); + value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min); break; case VisualMap.Direction.Y: if (axis is YAxis) { - var yAxis = chart.xAxises[axis.index]; + var yAxis = chart.xAxes[axis.index]; min = yAxis.runtimeMinValue; max = yAxis.runtimeMaxValue; } else { - var yAxis = chart.yAxises[axis.index]; + var yAxis = chart.yAxes[axis.index]; min = yAxis.runtimeMinValue; max = yAxis.runtimeMaxValue; } - value = min + (pos.y - chart.coordinateY) / chart.coordinateHeight * (max - min); + grid = chart.GetAxisGridOrDefault(axis); + value = min + (pos.y - grid.runtimeY) / grid.runtimeHeight * (max - min); break; } var color = visualMap.GetColor(value); @@ -107,7 +109,8 @@ namespace XCharts { var min = axis.runtimeMinValue; var max = axis.runtimeMaxValue; - var value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min); + var grid = chart.GetAxisGridOrDefault(axis); + var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min); var rate = (value - min) / (max - min); var color = itemStyle.GetGradientColor(rate, defaultColor); if (ChartHelper.IsClearColor(color)) return defaultColor; @@ -118,7 +121,8 @@ namespace XCharts { var min = axis.runtimeMinValue; var max = axis.runtimeMaxValue; - var value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min); + var grid = chart.GetAxisGridOrDefault(axis); + var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min); var rate = (value - min) / (max - min); var color = lineStyle.GetGradientColor(rate, defaultColor); if (ChartHelper.IsClearColor(color)) return defaultColor; diff --git a/Runtime/Internal/Interface/IDrawSerie.cs b/Runtime/Internal/Interface/IDrawSerie.cs new file mode 100644 index 00000000..a39ea13e --- /dev/null +++ b/Runtime/Internal/Interface/IDrawSerie.cs @@ -0,0 +1,28 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace XCharts +{ + public interface IDrawSerie + { + void InitComponent(); + void CheckComponent(); + void Update(); + void DrawBase(VertexHelper vh); + void DrawSerie(VertexHelper vh, Serie serie); + void RefreshLabel(); + bool CheckTootipArea(Vector2 local); + bool OnLegendButtonClick(int index, string legendName, bool show); + bool OnLegendButtonEnter(int index, string legendName); + bool OnLegendButtonExit(int index, string legendName); + void OnPointerDown(PointerEventData eventData); + } +} \ No newline at end of file diff --git a/Runtime/Internal/Interface/IDrawSerie.cs.meta b/Runtime/Internal/Interface/IDrawSerie.cs.meta new file mode 100644 index 00000000..c14fa401 --- /dev/null +++ b/Runtime/Internal/Interface/IDrawSerie.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0c4b04c07f5704c06a54b54193558c1b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Interface/IJsonData.cs b/Runtime/Internal/Interface/IJsonData.cs deleted file mode 100644 index 778f3c86..00000000 --- a/Runtime/Internal/Interface/IJsonData.cs +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -namespace XCharts -{ - /// <summary> - /// 从json导入数据接口 - /// </summary> - public interface IJsonData - { - void ParseJsonData(string json); - } -} \ No newline at end of file diff --git a/Runtime/Internal/Interface/IJsonData.cs.meta b/Runtime/Internal/Interface/IJsonData.cs.meta deleted file mode 100644 index 3127164b..00000000 --- a/Runtime/Internal/Interface/IJsonData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e9132f4c137015247b44450c2cb23606 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Internal/Interface/IPropertyChanged.cs b/Runtime/Internal/Interface/IPropertyChanged.cs index 8d4005ec..ce775ce2 100644 --- a/Runtime/Internal/Interface/IPropertyChanged.cs +++ b/Runtime/Internal/Interface/IPropertyChanged.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ namespace XCharts { diff --git a/Runtime/Internal/Object/LabelObject.cs b/Runtime/Internal/Object/ChartLabel.cs similarity index 76% rename from Runtime/Internal/Object/LabelObject.cs rename to Runtime/Internal/Object/ChartLabel.cs index c9623a11..52e02464 100644 --- a/Runtime/Internal/Object/LabelObject.cs +++ b/Runtime/Internal/Object/ChartLabel.cs @@ -1,21 +1,21 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; using UnityEngine.UI; namespace XCharts { - public class LabelObject : ChartObject + public class ChartLabel : ChartObject { private bool m_LabelAutoSize = true; private float m_LabelPaddingLeftRight = 3f; private float m_LabelPaddingTopBottom = 3f; - private Text m_LabelText; + private ChartText m_LabelText; private RectTransform m_LabelRect; private RectTransform m_IconRect; private RectTransform m_ObjectRect; @@ -24,9 +24,9 @@ namespace XCharts public GameObject gameObject { get { return m_GameObject; } } public Image icon { get { return m_IconImage; } } - public Text label { get { return m_LabelText; } } + public ChartText label { get { return m_LabelText; } } - public LabelObject() + public ChartLabel() { } @@ -36,8 +36,8 @@ namespace XCharts m_LabelAutoSize = autoSize; m_LabelPaddingLeftRight = paddingLeftRight; m_LabelPaddingTopBottom = paddingTopBottom; - m_LabelText = labelObj.GetComponentInChildren<Text>(); - m_LabelRect = m_LabelText.GetComponent<RectTransform>(); + m_LabelText = new ChartText(labelObj); + m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>(); m_ObjectRect = labelObj.GetComponent<RectTransform>(); } @@ -95,12 +95,12 @@ namespace XCharts public void SetLabelColor(Color color) { - if (m_LabelText) m_LabelText.color = color; + if (m_LabelText != null) m_LabelText.SetColor(color); } public void SetLabelRotate(float rotate) { - if (m_LabelText) m_LabelText.transform.localEulerAngles = new Vector3(0, 0, rotate); + if (m_LabelText != null) m_LabelText.SetLocalEulerAngles(new Vector3(0, 0, rotate)); } public void SetPosition(Vector3 position) @@ -122,7 +122,7 @@ namespace XCharts } public void SetLabelActive(bool flag) { - if (m_LabelText) ChartHelper.SetActive(m_LabelText, flag); + if (m_LabelText != null) m_LabelText.SetActive(flag); } public void SetIconActive(bool flag) { @@ -131,14 +131,15 @@ namespace XCharts public bool SetText(string text) { - if (m_LabelText && !m_LabelText.text.Equals(text)) + if (m_LabelRect == null) return false; + if (m_LabelText != null && !m_LabelText.GetText().Equals(text)) { - m_LabelText.text = text; + m_LabelText.SetText(text); if (m_LabelAutoSize) { var newSize = string.IsNullOrEmpty(text) ? Vector2.zero : - new Vector2(m_LabelText.preferredWidth + m_LabelPaddingLeftRight * 2, - m_LabelText.preferredHeight + m_LabelPaddingTopBottom * 2); + 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; if (sizeChange) { diff --git a/Runtime/Internal/Object/ChartLabel.cs.meta b/Runtime/Internal/Object/ChartLabel.cs.meta new file mode 100644 index 00000000..d673cbbf --- /dev/null +++ b/Runtime/Internal/Object/ChartLabel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 61287841bdc4142caba8e77985cd8715 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Object/ChartObject.cs b/Runtime/Internal/Object/ChartObject.cs index b23c4dba..6ce5d80e 100644 --- a/Runtime/Internal/Object/ChartObject.cs +++ b/Runtime/Internal/Object/ChartObject.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; diff --git a/Runtime/Internal/Object/ChartText.cs b/Runtime/Internal/Object/ChartText.cs new file mode 100644 index 00000000..0b2cecc2 --- /dev/null +++ b/Runtime/Internal/Object/ChartText.cs @@ -0,0 +1,255 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + public class ChartText + { + private Text m_Text; + private TextGenerationSettings m_RelatedTextSettings; + public Text text + { + get { return m_Text; } + set + { + m_Text = value; + if (value != null) + { + m_RelatedTextSettings = m_Text.GetGenerationSettings(Vector2.zero); + } + } + } +#if dUI_TextMeshPro + private TextMeshProUGUI m_TMPText; + public TextMeshProUGUI tmpText { get { return m_TMPText; } set { m_TMPText = value; } } +#endif + public GameObject gameObject + { + get + { +#if dUI_TextMeshPro + if (m_TMPText != null) return m_TMPText.gameObject; +#else + if (m_Text != null) return m_Text.gameObject; +#endif + return null; + } + } + + public ChartText() + { + } + + public ChartText(GameObject textParent) + { +#if dUI_TextMeshPro + m_TMPText = textParent.GetComponentInChildren<TextMeshProUGUI>(); + if (m_TMPText == null) + { + Debug.LogError("can't find TextMeshProUGUI component:" + textParent); + } +#else + m_Text = textParent.GetComponentInChildren<Text>(); + if (m_Text == null) + { + Debug.LogError("can't find Text component:" + textParent); + } +#endif + } + + public void SetFontSize(float fontSize) + { +#if dUI_TextMeshPro + if (m_TMPText != null) m_TMPText.fontSize = fontSize; +#else + if (m_Text != null) m_Text.fontSize = (int)fontSize; +#endif + } + + public void SetText(string text) + { + if (text == null) text = string.Empty; + else text = text.Replace("\\n", "\n"); +#if dUI_TextMeshPro + if(m_TMPText != null) m_TMPText.text = text; +#else + if (m_Text != null) m_Text.text = text; +#endif + } + + public string GetText() + { +#if dUI_TextMeshPro + if (m_TMPText != null) return m_TMPText.text; +#else + if (m_Text != null) return m_Text.text; +#endif + return string.Empty; + } + + public void SetColor(Color color) + { +#if dUI_TextMeshPro + if (m_TMPText != null) m_TMPText.color = color; +#else + if (m_Text != null) m_Text.color = color; +#endif + } + + public void SetLineSpacing(float lineSpacing) + { +#if dUI_TextMeshPro + if (m_TMPText != null) m_TMPText.lineSpacing = lineSpacing; +#else + if (m_Text != null) m_Text.lineSpacing = lineSpacing; +#endif + } + + public void SetActive(bool flag) + { +#if dUI_TextMeshPro + //m_TMPText.gameObject.SetActive(flag); + if (m_TMPText != null) ChartHelper.SetActive(m_TMPText.gameObject, flag); +#else + //m_Text.gameObject.SetActive(flag); + if (m_Text != null) ChartHelper.SetActive(m_Text.gameObject, flag); +#endif + } + + public void SetLocalPosition(Vector3 position) + { +#if dUI_TextMeshPro + if (m_TMPText != null) m_TMPText.transform.localPosition = position; +#else + if (m_Text != null) m_Text.transform.localPosition = position; +#endif + } + public void SetSizeDelta(Vector2 sizeDelta) + { +#if dUI_TextMeshPro + if (m_TMPText != null) m_TMPText.GetComponent<RectTransform>().sizeDelta = sizeDelta; +#else + if (m_Text != null) m_Text.GetComponent<RectTransform>().sizeDelta = sizeDelta; +#endif + } + + public void SetLocalEulerAngles(Vector3 position) + { +#if dUI_TextMeshPro + if (m_TMPText != null) m_TMPText.transform.localEulerAngles = position; +#else + if (m_Text != null) m_Text.transform.localEulerAngles = position; +#endif + } + + public void SetAlignment(TextAnchor alignment) + { +#if dUI_TextMeshPro + if (m_TMPText == null) return; + switch (alignment) + { + case TextAnchor.LowerCenter: m_TMPText.alignment = TextAlignmentOptions.Bottom; break; + case TextAnchor.LowerLeft: m_TMPText.alignment = TextAlignmentOptions.BottomLeft; break; + case TextAnchor.LowerRight: m_TMPText.alignment = TextAlignmentOptions.BottomRight; break; + case TextAnchor.MiddleCenter: m_TMPText.alignment = TextAlignmentOptions.Center; break; + case TextAnchor.MiddleLeft: m_TMPText.alignment = TextAlignmentOptions.Left; break; + case TextAnchor.MiddleRight: m_TMPText.alignment = TextAlignmentOptions.Right; break; + 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; + } +#else + if (m_Text != null) m_Text.alignment = alignment; +#endif + } + + public void SetFont(Font font) + { + if (m_Text) m_Text.font = font; + } + + public void SetFontStyle(FontStyle fontStyle) + { +#if dUI_TextMeshPro + if (m_TMPText == null) return; + switch (fontStyle) + { + case FontStyle.Normal: m_TMPText.fontStyle = FontStyles.Normal; break; + case FontStyle.Bold: m_TMPText.fontStyle = FontStyles.Bold; break; + case FontStyle.BoldAndItalic: m_TMPText.fontStyle = FontStyles.Bold | FontStyles.Italic; break; + case FontStyle.Italic: m_TMPText.fontStyle = FontStyles.Italic; break; + } +#else + if (m_Text != null) m_Text.fontStyle = fontStyle; +#endif + } + + public void SetFontAndSizeAndStyle(TextStyle textStyle, ComponentTheme theme) + { +#if dUI_TextMeshPro + if (m_TMPText == null) return; + m_TMPText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont; + m_TMPText.fontSize = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize; + m_TMPText.fontStyle = textStyle.tmpFontStyle; +#else + if (m_Text != null) + { + m_Text.font = textStyle.font == null ? theme.font : textStyle.font; + m_Text.fontSize = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize; + m_Text.fontStyle = textStyle.fontStyle; + } +#endif + } + + public float GetPreferredWidth(string content) + { +#if dUI_TextMeshPro + if (m_TMPText != null) return 0; // TODO: +#else + if (m_Text != null) return m_Text.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings); +#endif + return 0; + } + + public float GetPreferredWidth() + { +#if dUI_TextMeshPro + if (m_TMPText != null) return m_TMPText.preferredWidth; +#else + if (m_Text != null) return m_Text.preferredWidth; +#endif + return 0; + } + public float GetPreferredHeight() + { +#if dUI_TextMeshPro + if (m_TMPText != null) return m_TMPText.preferredHeight; +#else + if (m_Text != null) return m_Text.preferredHeight; +#endif + return 0; + } + +#if dUI_TextMeshPro + public void SetAlignment(TextAlignmentOptions alignment) + { + if (m_TMPText != null) m_TMPText.alignment = alignment; + } + + public void SetFont(TMP_FontAsset font) + { + if (m_TMPText != null) m_TMPText.font = font; + } +#endif + } +} \ No newline at end of file diff --git a/Runtime/Internal/Object/ChartText.cs.meta b/Runtime/Internal/Object/ChartText.cs.meta new file mode 100644 index 00000000..6b1b33de --- /dev/null +++ b/Runtime/Internal/Object/ChartText.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4e2466c1fe5874bea8373b071405a930 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Object/LabelObject.cs.meta b/Runtime/Internal/Object/LabelObject.cs.meta deleted file mode 100644 index ee6c0b32..00000000 --- a/Runtime/Internal/Object/LabelObject.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1277b7528331b42cfb61da7a2c762bee -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Internal/Object/LegendItem.cs b/Runtime/Internal/Object/LegendItem.cs index 2d9a2da7..40b81be9 100644 --- a/Runtime/Internal/Object/LegendItem.cs +++ b/Runtime/Internal/Object/LegendItem.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System; using UnityEngine; using UnityEngine.UI; @@ -18,7 +18,7 @@ namespace XCharts private GameObject m_GameObject; private Button m_Button; private Image m_Icon; - private Text m_Text; + private ChartText m_Text; private Image m_TextBackground; private RectTransform m_Rect; private RectTransform m_IconRect; @@ -71,7 +71,7 @@ namespace XCharts m_Rect = obj.GetComponent<RectTransform>(); m_Icon = obj.transform.Find("icon").gameObject.GetComponent<Image>(); m_TextBackground = obj.transform.Find("content").gameObject.GetComponent<Image>(); - m_Text = obj.transform.Find("content/Text").gameObject.GetComponent<Text>(); + m_Text = new ChartText(obj); m_IconRect = m_Icon.gameObject.GetComponent<RectTransform>(); m_TextRect = m_Text.gameObject.GetComponent<RectTransform>(); m_TextBackgroundRect = m_TextBackground.gameObject.GetComponent<RectTransform>(); @@ -87,7 +87,7 @@ namespace XCharts m_Icon = icon; } - public void SetText(Text text) + public void SetText(ChartText text) { m_Text = text; } @@ -123,9 +123,9 @@ namespace XCharts public void SetContentColor(Color color) { - if (m_Text) + if (m_Text != null) { - m_Text.color = color; + m_Text.SetColor(color); } } @@ -149,20 +149,20 @@ namespace XCharts public bool SetContent(string content) { - if (m_Text && !m_Text.text.Equals(content)) + if (m_Text != null && !m_Text.GetText().Equals(content)) { - m_Text.text = content; + m_Text.SetText(content); if (m_LabelAutoSize) { var newSize = string.IsNullOrEmpty(content) ? Vector2.zero : - new Vector2(m_Text.preferredWidth, m_Text.preferredHeight); + new Vector2(m_Text.GetPreferredWidth(), m_Text.GetPreferredHeight()); var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y; if (sizeChange) { m_TextRect.sizeDelta = newSize; m_TextRect.anchoredPosition3D = new Vector3(m_LabelPaddingLeftRight, 0); - m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.preferredWidth + m_LabelPaddingLeftRight * 2, - m_Text.preferredHeight + m_LabelPaddingTopBottom * 2 - 4); + m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.GetPreferredWidth() + m_LabelPaddingLeftRight * 2, + m_Text.GetPreferredHeight() + m_LabelPaddingTopBottom * 2 - 4); m_Rect.sizeDelta = new Vector3(width, height); } return sizeChange; diff --git a/Runtime/Internal/Painter.cs b/Runtime/Internal/Painter.cs new file mode 100644 index 00000000..432e424d --- /dev/null +++ b/Runtime/Internal/Painter.cs @@ -0,0 +1,79 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using UnityEngine.UI; +using System; + +namespace XCharts +{ + public partial class Painter : MaskableGraphic + { + public enum Type + { + Base, + Serie, + Top + } + protected int m_Index = -1; + protected Type m_Type = Type.Base; + protected bool m_Refresh; + protected Action<VertexHelper, Painter> m_OnPopulateMesh; + + public Action<VertexHelper, Painter> onPopulateMesh { set { m_OnPopulateMesh = value; } } + public int index { get { return m_Index; } set { m_Index = value; } } + public Type type { get { return m_Type; } set { m_Type = value; } } + public void Refresh() + { + if (gameObject == null) return; + if (!gameObject.activeSelf) return; + m_Refresh = true; + //Debug.LogError("refresh painter:"+name); + } + + public void Init() + { + raycastTarget = false; + } + + public void SetActive(bool flag, bool isDebugMode = false) + { + if (gameObject.activeInHierarchy != flag) + { + gameObject.SetActive(flag); + } + // var higFlags = !flag || !isDebugMode ? HideFlags.HideInHierarchy : HideFlags.None; + // if (gameObject.hideFlags != higFlags) + // { + // gameObject.hideFlags = hideFlags; + // } + } + + protected override void Awake() + { + Init(); + } + + internal void CheckRefresh() + { + if (m_Refresh && gameObject.activeSelf) + { + m_Refresh = false; + SetVerticesDirty(); + } + } + + protected override void OnPopulateMesh(VertexHelper vh) + { + vh.Clear(); + if (m_OnPopulateMesh != null) + { + m_OnPopulateMesh(vh, this); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/Painter.cs.meta b/Runtime/Internal/Painter.cs.meta new file mode 100644 index 00000000..60597faf --- /dev/null +++ b/Runtime/Internal/Painter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 01c85cd323a9f4dfb803470695bd0944 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Pools/AxisPool.cs b/Runtime/Internal/Pools/AxisPool.cs index e02b4d9e..f08ab3df 100644 --- a/Runtime/Internal/Pools/AxisPool.cs +++ b/Runtime/Internal/Pools/AxisPool.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ namespace XCharts { diff --git a/Runtime/Internal/Pools/ListPool.cs b/Runtime/Internal/Pools/ListPool.cs index 49b72c19..f38b668f 100644 --- a/Runtime/Internal/Pools/ListPool.cs +++ b/Runtime/Internal/Pools/ListPool.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/Internal/Pools/ObjectPool.cs b/Runtime/Internal/Pools/ObjectPool.cs index 344331ef..c308a8df 100644 --- a/Runtime/Internal/Pools/ObjectPool.cs +++ b/Runtime/Internal/Pools/ObjectPool.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/Internal/Pools/SerieDataPool.cs b/Runtime/Internal/Pools/SerieDataPool.cs index 1328429f..6c191eef 100644 --- a/Runtime/Internal/Pools/SerieDataPool.cs +++ b/Runtime/Internal/Pools/SerieDataPool.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Runtime/Internal/Pools/SerieLabelPool.cs b/Runtime/Internal/Pools/SerieLabelPool.cs index 18f4c645..0f38af5d 100644 --- a/Runtime/Internal/Pools/SerieLabelPool.cs +++ b/Runtime/Internal/Pools/SerieLabelPool.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; @@ -16,41 +16,38 @@ namespace XCharts private static readonly Stack<GameObject> m_Stack = new Stack<GameObject>(200); private static Dictionary<int, bool> m_ReleaseDic = new Dictionary<int, bool>(1000); - public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, - float iconWidth, float iconHeight) + public static GameObject Get(string name, Transform parent, SerieLabel label, Color color, + float iconWidth, float iconHeight, ChartTheme theme) { GameObject element; if (m_Stack.Count == 0 || !Application.isPlaying) { - element = CreateSerieLabel(name, parent, label, font, color, iconWidth, iconHeight); + element = CreateSerieLabel(name, parent, label, color, iconWidth, iconHeight, theme); } else { element = m_Stack.Pop(); if (element == null) { - element = CreateSerieLabel(name, parent, label, font, color, iconWidth, iconHeight); + element = CreateSerieLabel(name, parent, label, color, iconWidth, iconHeight, theme); } m_ReleaseDic.Remove(element.GetInstanceID()); element.name = name; element.transform.SetParent(parent); - element.transform.localEulerAngles = new Vector3(0, 0, label.rotate); - var text = element.GetComponentInChildren<Text>(); - text.color = color; - text.font = font; - text.fontSize = label.fontSize; - text.fontStyle = label.fontStyle; + element.transform.localEulerAngles = new Vector3(0, 0, label.textStyle.rotate); + var text = new ChartText(element); + text.SetColor(color); + text.SetFontAndSizeAndStyle(label.textStyle, theme.common); ChartHelper.SetActive(element, true); } return element; } - private static GameObject CreateSerieLabel(string name, Transform parent, SerieLabel label, Font font, Color color, - float iconWidth, float iconHeight) + private static GameObject CreateSerieLabel(string name, Transform parent, SerieLabel label, Color color, + float iconWidth, float iconHeight, ChartTheme theme) { - var element = ChartHelper.AddSerieLabel(name, parent, font, - color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate, - label.backgroundWidth, label.backgroundHeight, 1); + var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight, + color, label.textStyle, theme); ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight); return element; } diff --git a/Runtime/Internal/Utility/ChartCached.cs b/Runtime/Internal/Utility/ChartCached.cs index 588ac03a..0990f9db 100644 --- a/Runtime/Internal/Utility/ChartCached.cs +++ b/Runtime/Internal/Utility/ChartCached.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using System.Globalization; @@ -126,7 +126,6 @@ namespace XCharts internal static string GetXAxisName(int axisIndex, int index = -1) { - if (axisIndex > 0) axisIndex = 2; if (index >= 0) { int key = (axisIndex + 1) * 10000 + index; @@ -145,7 +144,6 @@ namespace XCharts internal static string GetYAxisName(int axisIndex, int index = -1) { - if (axisIndex > 0) axisIndex = 2; if (index >= 0) { int key = (axisIndex + 1) * 10000 + index; diff --git a/Runtime/Internal/Utility/ChartConst.cs b/Runtime/Internal/Utility/ChartConst.cs index 9e014897..f5eb9ceb 100644 --- a/Runtime/Internal/Utility/ChartConst.cs +++ b/Runtime/Internal/Utility/ChartConst.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; diff --git a/Runtime/Internal/Utility/ChartDrawer.cs b/Runtime/Internal/Utility/ChartDrawer.cs index 936f0cb7..3ca96c31 100644 --- a/Runtime/Internal/Utility/ChartDrawer.cs +++ b/Runtime/Internal/Utility/ChartDrawer.cs @@ -1,1308 +1,20 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using XUGL; namespace XCharts { public static class ChartDrawer { - private static Color32 s_Color32Clear = new Color32(0, 0, 0, 0); - private static readonly Vector2 zeroVector2 = Vector2.zero; - private static UIVertex[] vertex = new UIVertex[4]; - private static List<Vector3> s_CurvesPosList = new List<Vector3>(); - - public static void DrawArrow(VertexHelper vh, Vector3 startPos, Vector3 arrowPos, float width, - float height, float offset, float dent, Color32 color) - { - var dir = (arrowPos - startPos).normalized; - - var sharpPos = arrowPos + (offset + height / 2) * dir; - var middle = sharpPos + (dent - height) * dir; - var diff = Vector3.Cross(dir, Vector3.forward).normalized * width / 2; - var left = sharpPos - height * dir + diff; - var right = sharpPos - height * dir - diff; - DrawTriangle(vh, middle, sharpPos, left, color); - DrawTriangle(vh, middle, sharpPos, right, color); - } - - public static void DrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color) - { - if (p1 == p2) return; - Vector3 v = Vector3.Cross(p2 - p1, Vector3.forward).normalized * size; - vertex[0].position = p1 - v; - vertex[1].position = p2 - v; - vertex[2].position = p2 + v; - vertex[3].position = p1 + v; - - for (int j = 0; j < 4; j++) - { - vertex[j].color = color; - vertex[j].uv0 = zeroVector2; - } - vh.AddUIVertexQuad(vertex); - } - - public static void DrawLine(VertexHelper vh, Vector3 start, Vector3 middle, Vector3 end, float size, Color32 color) - { - var dir1 = (middle - start).normalized; - var dir2 = (end - middle).normalized; - var dir1v = Vector3.Cross(dir1, Vector3.forward).normalized; - var dir2v = Vector3.Cross(dir2, Vector3.forward).normalized; - var dir3 = (dir1 + dir2).normalized; - var isDown = Vector3.Cross(dir1, dir2).z <= 0; - var angle = (180 - Vector3.Angle(dir1, dir2)) * Mathf.Deg2Rad / 2; - var diff = size / Mathf.Sin(angle); - var dirDp = Vector3.Cross(dir3, Vector3.forward).normalized; - var dnPos = middle + (isDown ? dirDp : -dirDp) * diff; - var upPos1 = middle + (isDown ? -dir1v : dir1v) * size; - var upPos2 = middle + (isDown ? -dir2v : dir2v) * size; - var startUp = start - dir1v * size; - var startDn = start + dir1v * size; - var endUp = end - dir2v * size; - var endDn = end + dir2v * size; - if (isDown) - { - DrawPolygon(vh, startDn, startUp, upPos1, dnPos, color); - DrawPolygon(vh, dnPos, upPos2, endUp, endDn, color); - DrawTriangle(vh, dnPos, upPos1, upPos2, color); - } - else - { - DrawPolygon(vh, startDn, startUp, dnPos, upPos1, color); - DrawPolygon(vh, upPos2, dnPos, endUp, endDn, color); - DrawTriangle(vh, dnPos, upPos1, upPos2, color); - } - } - - public static void DrawDashLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color, - float dashLen = 15f, float blankLen = 7f, List<Vector3> posList = null) - { - float dist = Vector3.Distance(p1, p2); - if (dist < 0.1f) return; - int segment = Mathf.CeilToInt(dist / (dashLen + blankLen)); - Vector3 dir = (p2 - p1).normalized; - Vector3 sp = p1, np; - if (posList != null) posList.Clear(); - for (int i = 1; i <= segment; i++) - { - if (posList != null) posList.Add(sp); - np = p1 + dir * dist * i / segment; - var dashep = np - dir * blankLen; - DrawLine(vh, sp, dashep, size, color); - sp = np; - } - if (posList != null) posList.Add(p2); - DrawLine(vh, sp, p2, size, color); - } - public static void DrawDotLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color, - float dotLen = 5f, float blankLen = 5f, List<Vector3> posList = null) - { - float dist = Vector3.Distance(p1, p2); - if (dist < 0.1f) return; - int segment = Mathf.CeilToInt(dist / (dotLen + blankLen)); - Vector3 dir = (p2 - p1).normalized; - Vector3 sp = p1, np; - if (posList != null) posList.Clear(); - for (int i = 1; i <= segment; i++) - { - if (posList != null) posList.Add(sp); - np = p1 + dir * dist * i / segment; - var dashep = np - dir * blankLen; - DrawLine(vh, sp, dashep, size, color); - sp = np; - } - if (posList != null) posList.Add(p2); - DrawLine(vh, sp, p2, size, color); - } - - public static void DrawDashDotLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color, - float dashLen = 15f, float blankDotLen = 15f, List<Vector3> posList = null) - { - float dist = Vector3.Distance(p1, p2); - if (dist < 0.1f) return; - int segment = Mathf.CeilToInt(dist / (dashLen + blankDotLen)); - Vector3 dir = (p2 - p1).normalized; - Vector3 sp = p1, np; - if (posList != null) posList.Clear(); - for (int i = 1; i <= segment; i++) - { - if (posList != null) posList.Add(sp); - np = p1 + dir * dist * i / segment; - var dashep = np - dir * blankDotLen; - DrawLine(vh, sp, dashep, size, color); - if (posList != null) posList.Add(dashep); - var dotsp = dashep + (blankDotLen - 2 * size) / 2 * dir; - var dotep = dotsp + 2 * size * dir; - DrawLine(vh, dotsp, dotep, size, color); - if (posList != null) posList.Add(dotsp); - sp = np; - } - if (posList != null) posList.Add(p2); - DrawLine(vh, sp, p2, size, color); - } - - public static void DrawDashDotDotLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, - Color32 color, float dashLen = 15f, float blankDotLen = 20f, List<Vector3> posList = null) - { - float dist = Vector3.Distance(p1, p2); - if (dist < 0.1f) return; - int segment = Mathf.CeilToInt(dist / (dashLen + blankDotLen)); - Vector3 dir = (p2 - p1).normalized; - Vector3 sp = p1, np; - if (posList != null) posList.Clear(); - for (int i = 1; i <= segment; i++) - { - if (posList != null) posList.Add(sp); - np = p1 + dir * dist * i / segment; - var dashep = np - dir * blankDotLen; - DrawLine(vh, sp, dashep, size, color); - if (posList != null) posList.Add(dashep); - var dotsp = dashep + (blankDotLen / 2 - 2 * size) / 2 * dir; - var dotep = dotsp + 2 * size * dir; - DrawLine(vh, dotsp, dotep, size, color); - if (posList != null) posList.Add(dotep); - var dotsp2 = dashep + blankDotLen / 2 * dir; - dotsp2 = dotsp2 + (blankDotLen / 4 - 2 * size) / 2 * dir; - var dotep2 = dotsp2 + 2 * size * dir; - DrawLine(vh, dotsp2, dotep2, size, color); - if (posList != null) posList.Add(dotep2); - sp = np; - } - if (posList != null) posList.Add(p2); - DrawLine(vh, sp, p2, size, color); - } - - public static void DrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, - float zebraWidth, float zebraGap, Color32 color) - { - DrawDotLine(vh, p1, p2, size, color, zebraWidth, zebraGap); - } - - public static void DrawDiamond(VertexHelper vh, Vector3 pos, float size, Color32 color) - { - DrawDiamond(vh, pos, size, color, color); - } - - public static void DrawDiamond(VertexHelper vh, Vector3 pos, float size, Color32 color, Color32 toColor) - { - var p1 = new Vector2(pos.x - size, pos.y); - var p2 = new Vector2(pos.x, pos.y + size); - var p3 = new Vector2(pos.x + size, pos.y); - var p4 = new Vector2(pos.x, pos.y - size); - DrawTriangle(vh, p4, p1, p2, color, color, toColor); - DrawTriangle(vh, p3, p4, p2, color, color, toColor); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color, - bool vertical = true) - { - DrawPolygon(vh, p, radius, color, color, vertical); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color, Color32 toColor, - bool vertical = true) - { - Vector3 p1, p2, p3, p4; - if (vertical) - { - p1 = new Vector3(p.x + radius, p.y - radius); - p2 = new Vector3(p.x - radius, p.y - radius); - p3 = new Vector3(p.x - radius, p.y + radius); - p4 = new Vector3(p.x + radius, p.y + radius); - } - else - { - p1 = new Vector3(p.x - radius, p.y - radius); - p2 = new Vector3(p.x - radius, p.y + radius); - p3 = new Vector3(p.x + radius, p.y + radius); - p4 = new Vector3(p.x + radius, p.y - radius); - } - DrawPolygon(vh, p1, p2, p3, p4, color, toColor); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, float radius, Color32 color) - { - DrawPolygon(vh, p1, p2, radius, color, color); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, float radius, Color32 color, Color32 toColor) - { - var dir = (p2 - p1).normalized; - var dirv = Vector3.Cross(dir, Vector3.forward).normalized; - - var p3 = p1 + dirv * radius; - var p4 = p1 - dirv * radius; - var p5 = p2 - dirv * radius; - var p6 = p2 + dirv * radius; - DrawPolygon(vh, p3, p4, p5, p6, color, toColor); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p, float xRadius, float yRadius, - Color32 color, bool vertical = true) - { - DrawPolygon(vh, p, xRadius, yRadius, color, color, vertical); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p, float xRadius, float yRadius, - Color32 color, Color32 toColor, bool vertical = true) - { - Vector3 p1, p2, p3, p4; - if (vertical) - { - p1 = new Vector3(p.x + xRadius, p.y - yRadius); - p2 = new Vector3(p.x - xRadius, p.y - yRadius); - p3 = new Vector3(p.x - xRadius, p.y + yRadius); - p4 = new Vector3(p.x + xRadius, p.y + yRadius); - } - else - { - p1 = new Vector3(p.x - xRadius, p.y - yRadius); - p2 = new Vector3(p.x - xRadius, p.y + yRadius); - p3 = new Vector3(p.x + xRadius, p.y + yRadius); - p4 = new Vector3(p.x + xRadius, p.y - yRadius); - } - - DrawPolygon(vh, p1, p2, p3, p4, color, toColor); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, - Color32 color) - { - DrawPolygon(vh, p1, p2, p3, p4, color, color); - } - - public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, - Color32 startColor, Color32 toColor) - { - vertex[0].position = p1; - vertex[1].position = p2; - vertex[2].position = p3; - vertex[3].position = p4; - for (int j = 0; j < 4; j++) - { - vertex[j].color = j >= 2 ? toColor : startColor; - vertex[j].uv0 = zeroVector2; - } - vh.AddUIVertexQuad(vertex); - } - - private static void InitCornerRadius(float[] cornerRadius, float width, float height, bool isYAxis, ref float brLt, - ref float brRt, ref float brRb, ref float brLb, ref bool needRound) - { - if (cornerRadius == null) return; - brLt = cornerRadius.Length > 0 ? cornerRadius[0] : 0; - brRt = cornerRadius.Length > 1 ? cornerRadius[1] : 0; - brRb = cornerRadius.Length > 2 ? cornerRadius[2] : 0; - brLb = cornerRadius.Length > 3 ? cornerRadius[3] : 0; - needRound = brLb != 0 || brRt != 0 || brRb != 0 || brLb != 0; - if (needRound) - { - var min = Mathf.Min(width, height); - if (brLt == 1 && brRt == 1 && brRb == 1 && brLb == 1) - { - brLt = brRt = brRb = brLb = min / 2; - return; - } - if (brLt > 0 && brLt <= 1) brLt = brLt * min; - if (brRt > 0 && brRt <= 1) brRt = brRt * min; - if (brRb > 0 && brRb <= 1) brRb = brRb * min; - if (brLb > 0 && brLb <= 1) brLb = brLb * min; - if (isYAxis) - { - if (brLb + brLt >= height) - { - var total = brLb + brLt; - brLb = height * (brLb / total); - brLt = height * (brLt / total); - } - if (brRt + brRb >= height) - { - var total = brRt + brRb; - brRt = height * (brRt / total); - brRb = height * (brRb / total); - } - if (brLt + brRt >= width) - { - var total = brLt + brRt; - brLt = width * (brLt / total); - brRt = width * (brRt / total); - } - if (brRb + brLb >= width) - { - var total = brRb + brLb; - brRb = width * (brRb / total); - brLb = width * (brLb / total); - } - } - else - { - if (brLt + brRt >= width) - { - var total = brLt + brRt; - brLt = width * (brLt / total); - brRt = width * (brRt / total); - } - if (brRb + brLb >= width) - { - var total = brRb + brLb; - brRb = width * (brRb / total); - brLb = width * (brLb / total); - } - if (brLb + brLt >= height) - { - var total = brLb + brLt; - brLb = height * (brLb / total); - brLt = height * (brLt / total); - } - if (brRt + brRb >= height) - { - var total = brRt + brRb; - brRt = height * (brRt / total); - brRb = height * (brRb / total); - } - } - } - } - - /// <summary> - /// 绘制圆角矩形 - /// </summary> - /// <param name="vh"></param> - /// <param name="center"></param> - /// <param name="rectWidth"></param> - /// <param name="rectHeight"></param> - /// <param name="color"></param> - /// <param name="rotate"></param> - /// <param name="cornerRadius"></param> - public static void DrawRoundRectangle(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, - Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false) - { - var isGradient = !ChartHelper.IsValueEqualsColor(color, toColor); - var halfWid = rectWidth / 2; - var halfHig = rectHeight / 2; - float brLt = 0, brRt = 0, brRb = 0, brLb = 0; - bool needRound = false; - InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound); - var tempCenter = Vector3.zero; - var lbIn = new Vector3(center.x - halfWid, center.y - halfHig); - var ltIn = new Vector3(center.x - halfWid, center.y + halfHig); - var rtIn = new Vector3(center.x + halfWid, center.y + halfHig); - var rbIn = new Vector3(center.x + halfWid, center.y - halfHig); - if (needRound) - { - var lbIn2 = lbIn; - var ltIn2 = ltIn; - var rtIn2 = rtIn; - var rbIn2 = rbIn; - var roundLb = lbIn; - var roundLt = ltIn; - var roundRt = rtIn; - var roundRb = rbIn; - if (brLt > 0) - { - roundLt = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt); - ltIn = roundLt + brLt * Vector3.left; - ltIn2 = roundLt + brLt * Vector3.up; - } - if (brRt > 0) - { - roundRt = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt); - rtIn = roundRt + brRt * Vector3.up; - rtIn2 = roundRt + brRt * Vector3.right; - } - if (brRb > 0) - { - roundRb = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb); - rbIn = roundRb + brRb * Vector3.right; - rbIn2 = roundRb + brRb * Vector3.down; - } - if (brLb > 0) - { - roundLb = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb); - lbIn = roundLb + brLb * Vector3.left; - lbIn2 = roundLb + brLb * Vector3.down; - } - - if (isYAxis) - { - var maxLeft = Mathf.Max(brLt, brLb); - var maxRight = Mathf.Max(brRt, brRb); - var ltInRight = ltIn + maxLeft * Vector3.right; - var lbInRight = lbIn + maxLeft * Vector3.right; - var rtIn2Left = rtIn2 + maxRight * Vector3.left; - var rbInLeft = rbIn + maxRight * Vector3.left; - - var roundLbRight = roundLb + (maxLeft - brLb) * Vector3.right; - var lbIn2Right = lbIn2 + (maxLeft - brLb) * Vector3.right; - if (roundLbRight.x > roundRb.x) roundLbRight.x = roundRb.x; - if (lbIn2Right.x > roundRb.x) lbIn2Right.x = roundRb.x; - - var ltIn2Right = ltIn2 + (maxLeft - brLt) * Vector3.right; - var roundLtRight = roundLt + (maxLeft - brLt) * Vector3.right; - if (ltIn2Right.x > roundRt.x) ltIn2Right.x = roundRt.x; - if (roundLtRight.x > roundRt.x) roundLtRight.x = roundRt.x; - - var roundRtLeft = roundRt + (maxRight - brRt) * Vector3.left; - var rtInLeft = rtIn + (maxRight - brRt) * Vector3.left; - if (roundRtLeft.x < roundLt.x) roundRtLeft.x = roundLt.x; - if (rtInLeft.x < roundLt.x) rtInLeft.x = roundLt.x; - - var rbIn2Left = rbIn2 + (maxRight - brRb) * Vector3.left; - var roundRbLeft = roundRb + (maxRight - brRb) * Vector3.left; - if (rbIn2Left.x < roundLb.x) rbIn2Left.x = roundLb.x; - if (roundRbLeft.x < roundLb.x) roundRbLeft.x = roundLb.x; - if (!isGradient) - { - DrawSector(vh, roundLt, brLt, color, color, 270, 360, 1, isYAxis); - DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, isYAxis); - DrawSector(vh, roundRb, brRb, toColor, toColor, 90, 180, 1, isYAxis); - DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, isYAxis); - - DrawPolygon(vh, ltIn, ltInRight, lbInRight, lbIn, color, color); - DrawPolygon(vh, lbIn2, roundLb, roundLbRight, lbIn2Right, color, color); - DrawPolygon(vh, roundLt, ltIn2, ltIn2Right, roundLtRight, color, color); - - DrawPolygon(vh, rbInLeft, rtIn2Left, rtIn2, rbIn, toColor, toColor); - DrawPolygon(vh, roundRtLeft, rtInLeft, rtIn, roundRt, toColor, toColor); - DrawPolygon(vh, rbIn2Left, roundRbLeft, roundRb, rbIn2, toColor, toColor); - - var clt = new Vector3(center.x - halfWid + maxLeft, center.y + halfHig); - var crt = new Vector3(center.x + halfWid - maxRight, center.y + halfHig); - var crb = new Vector3(center.x + halfWid - maxRight, center.y - halfHig); - var clb = new Vector3(center.x - halfWid + maxLeft, center.y - halfHig); - if (crt.x > clt.x) - { - DrawPolygon(vh, clb, clt, crt, crb, color, toColor); - } - } - else - { - var tempLeftColor = Color32.Lerp(color, toColor, maxLeft / rectWidth); - var upLeftColor = Color32.Lerp(color, tempLeftColor, brLt / maxLeft); - var downLeftColor = Color32.Lerp(color, tempLeftColor, brLb / maxLeft); - - var tempRightColor = Color32.Lerp(color, toColor, (rectWidth - maxRight) / rectWidth); - var upRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRt) / maxRight); - var downRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRb) / maxRight); - - DrawSector(vh, roundLt, brLt, color, upLeftColor, 270, 360, 1, isYAxis); - DrawSector(vh, roundRt, brRt, upRightColor, toColor, 0, 90, 1, isYAxis); - DrawSector(vh, roundRb, brRb, downRightColor, toColor, 90, 180, 1, isYAxis); - DrawSector(vh, roundLb, brLb, color, downLeftColor, 180, 270, 1, isYAxis); - - - DrawPolygon(vh, lbIn, ltIn, ltInRight, lbInRight, color, tempLeftColor); - DrawPolygon(vh, lbIn2, roundLb, roundLbRight, lbIn2Right, downLeftColor, roundLbRight.x == roundRb.x ? downRightColor : tempLeftColor); - DrawPolygon(vh, roundLt, ltIn2, ltIn2Right, roundLtRight, upLeftColor, ltIn2Right.x == roundRt.x ? upRightColor : tempLeftColor); - - DrawPolygon(vh, rbInLeft, rtIn2Left, rtIn2, rbIn, tempRightColor, toColor); - DrawPolygon(vh, roundRtLeft, rtInLeft, rtIn, roundRt, roundRtLeft.x == roundLt.x ? upLeftColor : tempRightColor, upRightColor); - DrawPolygon(vh, rbIn2Left, roundRbLeft, roundRb, rbIn2, rbIn2Left.x == roundLb.x ? downLeftColor : tempRightColor, downRightColor); - - var clt = new Vector3(center.x - halfWid + maxLeft, center.y + halfHig); - var crt = new Vector3(center.x + halfWid - maxRight, center.y + halfHig); - var crb = new Vector3(center.x + halfWid - maxRight, center.y - halfHig); - var clb = new Vector3(center.x - halfWid + maxLeft, center.y - halfHig); - if (crt.x > clt.x) - { - DrawPolygon(vh, clb, clt, crt, crb, tempLeftColor, tempRightColor); - } - } - } - else - { - var maxup = Mathf.Max(brLt, brRt); - var maxdown = Mathf.Max(brLb, brRb); - var clt = new Vector3(center.x - halfWid, center.y + halfHig - maxup); - var crt = new Vector3(center.x + halfWid, center.y + halfHig - maxup); - var crb = new Vector3(center.x + halfWid, center.y - halfHig + maxdown); - var clb = new Vector3(center.x - halfWid, center.y - halfHig + maxdown); - var lbIn2Up = lbIn2 + maxdown * Vector3.up; - var rbIn2Up = rbIn2 + maxdown * Vector3.up; - var rtInDown = rtIn + maxup * Vector3.down; - var ltIn2Down = ltIn2 + maxup * Vector3.down; - - var roundLtDown = roundLt + (maxup - brLt) * Vector3.down; - var ltInDown = ltIn + (maxup - brLt) * Vector3.down; - if (roundLtDown.y < roundLb.y) roundLtDown.y = roundLb.y; - if (ltInDown.y < roundLb.y) ltInDown.y = roundLb.y; - - var rtIn2Down = rtIn2 + (maxup - brRt) * Vector3.down; - var roundRtDown = roundRt + (maxup - brRt) * Vector3.down; - if (rtIn2Down.y < roundRb.y) rtIn2Down.y = roundRb.y; - if (roundRtDown.y < roundRb.y) roundRtDown.y = roundRb.y; - - var lbInUp = lbIn + (maxdown - brLb) * Vector3.up; - var roundLbUp = roundLb + (maxdown - brLb) * Vector3.up; - if (lbInUp.y > roundLt.y) lbInUp.y = roundLt.y; - if (roundLbUp.y > roundLt.y) roundLbUp.y = roundLt.y; - - var roundRbUp = roundRb + (maxdown - brRb) * Vector3.up; - var rbInUp = rbIn + (maxdown - brRb) * Vector3.up; - if (roundRbUp.y > roundRt.y) roundRbUp.y = roundRt.y; - if (rbInUp.y > roundRt.y) rbInUp.y = roundRt.y; - - if (!isGradient) - { - DrawSector(vh, roundLt, brLt, toColor, toColor, 270, 360, 1, isYAxis); - DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, isYAxis); - DrawSector(vh, roundRb, brRb, color, color, 90, 180, 1, isYAxis); - DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, isYAxis); - - DrawPolygon(vh, ltIn2, rtIn, rtInDown, ltIn2Down, toColor, toColor); - DrawPolygon(vh, ltIn, roundLt, roundLtDown, ltInDown, toColor, toColor); - DrawPolygon(vh, roundRt, rtIn2, rtIn2Down, roundRtDown, toColor, toColor); - - DrawPolygon(vh, lbIn2, lbIn2Up, rbIn2Up, rbIn2, color, color); - DrawPolygon(vh, lbIn, lbInUp, roundLbUp, roundLb, color, color); - DrawPolygon(vh, roundRb, roundRbUp, rbInUp, rbIn, color, color); - if (clt.y > clb.y) - { - DrawPolygon(vh, clt, crt, crb, clb, toColor, color); - } - } - else - { - var tempUpColor = Color32.Lerp(color, toColor, (rectHeight - maxup) / rectHeight); - var leftUpColor = Color32.Lerp(tempUpColor, toColor, (maxup - brLt) / maxup); - var rightUpColor = Color32.Lerp(tempUpColor, toColor, (maxup - brRt) / maxup); - var tempDownColor = Color32.Lerp(color, toColor, maxdown / rectHeight); - var leftDownColor = Color32.Lerp(color, tempDownColor, brLb / maxdown); - var rightDownColor = Color32.Lerp(color, tempDownColor, brRb / maxdown); - - DrawSector(vh, roundLt, brLt, leftUpColor, toColor, 270, 360, 1, isYAxis); - DrawSector(vh, roundRt, brRt, rightUpColor, toColor, 0, 90, 1, isYAxis); - DrawSector(vh, roundRb, brRb, rightDownColor, color, 90, 180, 1, isYAxis); - DrawSector(vh, roundLb, brLb, leftDownColor, color, 180, 270, 1, isYAxis); - - DrawPolygon(vh, ltIn2, rtIn, rtInDown, ltIn2Down, toColor, tempUpColor); - DrawPolygon(vh, ltIn, roundLt, roundLtDown, ltInDown, leftUpColor, roundLtDown.y == roundLb.y ? leftDownColor : tempUpColor); - DrawPolygon(vh, roundRt, rtIn2, rtIn2Down, roundRtDown, rightUpColor, rtIn2Down.y == roundRb.y ? rightDownColor : tempUpColor); - - DrawPolygon(vh, rbIn2, lbIn2, lbIn2Up, rbIn2Up, color, tempDownColor); - DrawPolygon(vh, roundLb, lbIn, lbInUp, roundLbUp, leftDownColor, lbInUp.y == roundLt.y ? leftUpColor : tempDownColor); - DrawPolygon(vh, rbIn, roundRb, roundRbUp, rbInUp, rightDownColor, roundRbUp.y == roundRt.y ? rightUpColor : tempDownColor); - if (clt.y > clb.y) - { - DrawPolygon(vh, clt, crt, crb, clb, tempUpColor, tempDownColor); - } - } - } - } - else - { - DrawPolygon(vh, lbIn, ltIn, rtIn, rbIn, toColor, color); - } - } - - /// <summary> - /// 绘制(圆角)边框 - /// </summary> - /// <param name="vh"></param> - /// <param name="center"></param> - /// <param name="rectWidth"></param> - /// <param name="rectHeight"></param> - /// <param name="borderWidth"></param> - /// <param name="color"></param> - /// <param name="rotate"></param> - /// <param name="cornerRadius"></param> - public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, - float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false) - { - if (borderWidth == 0 || ChartHelper.IsClearColor(color)) return; - var halfWid = rectWidth / 2; - var halfHig = rectHeight / 2; - var lbIn = new Vector3(center.x - halfWid, center.y - halfHig); - var lbOt = new Vector3(center.x - halfWid - borderWidth, center.y - halfHig - borderWidth); - var ltIn = new Vector3(center.x - halfWid, center.y + halfHig); - var ltOt = new Vector3(center.x - halfWid - borderWidth, center.y + halfHig + borderWidth); - var rtIn = new Vector3(center.x + halfWid, center.y + halfHig); - var rtOt = new Vector3(center.x + halfWid + borderWidth, center.y + halfHig + borderWidth); - var rbIn = new Vector3(center.x + halfWid, center.y - halfHig); - var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth); - float brLt = 0, brRt = 0, brRb = 0, brLb = 0; - bool needRound = false; - InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound); - var tempCenter = Vector3.zero; - if (needRound) - { - var lbIn2 = lbIn; - var lbOt2 = lbOt; - var ltIn2 = ltIn; - var ltOt2 = ltOt; - var rtIn2 = rtIn; - var rtOt2 = rtOt; - var rbIn2 = rbIn; - var rbOt2 = rbOt; - if (brLt > 0) - { - tempCenter = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt); - DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, color, s_Color32Clear, 270, 360); - ltIn = tempCenter + brLt * Vector3.left; - ltOt = tempCenter + (brLt + borderWidth) * Vector3.left; - ltIn2 = tempCenter + brLt * Vector3.up; - ltOt2 = tempCenter + (brLt + borderWidth) * Vector3.up; - } - if (brRt > 0) - { - tempCenter = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt); - DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, color, s_Color32Clear, 0, 90); - rtIn = tempCenter + brRt * Vector3.up; - rtOt = tempCenter + (brRt + borderWidth) * Vector3.up; - rtIn2 = tempCenter + brRt * Vector3.right; - rtOt2 = tempCenter + (brRt + borderWidth) * Vector3.right; - } - if (brRb > 0) - { - tempCenter = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb); - DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, color, s_Color32Clear, 90, 180); - rbIn = tempCenter + brRb * Vector3.right; - rbOt = tempCenter + (brRb + borderWidth) * Vector3.right; - rbIn2 = tempCenter + brRb * Vector3.down; - rbOt2 = tempCenter + (brRb + borderWidth) * Vector3.down; - } - if (brLb > 0) - { - tempCenter = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb); - DrawDoughnut(vh, tempCenter, brLb, brLb + borderWidth, color, s_Color32Clear, 180, 270); - lbIn = tempCenter + brLb * Vector3.left; - lbOt = tempCenter + (brLb + borderWidth) * Vector3.left; - lbIn2 = tempCenter + brLb * Vector3.down; - lbOt2 = tempCenter + (brLb + borderWidth) * Vector3.down; - } - DrawPolygon(vh, lbIn, lbOt, ltOt, ltIn, color); - DrawPolygon(vh, ltIn2, ltOt2, rtOt, rtIn, color); - DrawPolygon(vh, rtIn2, rtOt2, rbOt, rbIn, color); - DrawPolygon(vh, rbIn2, rbOt2, lbOt2, lbIn2, color); - } - else - { - if (rotate > 0) - { - lbIn = ChartHelper.RotateRound(lbIn, center, Vector3.forward, rotate); - lbOt = ChartHelper.RotateRound(lbOt, center, Vector3.forward, rotate); - ltIn = ChartHelper.RotateRound(ltIn, center, Vector3.forward, rotate); - ltOt = ChartHelper.RotateRound(ltOt, center, Vector3.forward, rotate); - rtIn = ChartHelper.RotateRound(rtIn, center, Vector3.forward, rotate); - rtOt = ChartHelper.RotateRound(rtOt, center, Vector3.forward, rotate); - rbIn = ChartHelper.RotateRound(rbIn, center, Vector3.forward, rotate); - rbOt = ChartHelper.RotateRound(rbOt, center, Vector3.forward, rotate); - } - DrawPolygon(vh, lbIn, lbOt, ltOt, ltIn, color); - DrawPolygon(vh, ltIn, ltOt, rtOt, rtIn, color); - DrawPolygon(vh, rtIn, rtOt, rbOt, rbIn, color); - DrawPolygon(vh, rbIn, rbOt, lbOt, lbIn, color); - } - } - - public static void DrawTriangle(VertexHelper vh, Vector3 p1, - Vector3 p2, Vector3 p3, Color32 color) - { - DrawTriangle(vh, p1, p2, p3, color, color, color); - } - - public static void DrawTriangle(VertexHelper vh, Vector3 pos, float size, Color32 color) - { - DrawTriangle(vh, pos, size, color, color); - } - - public static void DrawTriangle(VertexHelper vh, Vector3 pos, float size, Color32 color, Color32 toColor) - { - var x = size * Mathf.Cos(30 * Mathf.PI / 180); - var y = size * Mathf.Sin(30 * Mathf.PI / 180); - var p1 = new Vector2(pos.x - x, pos.y - y); - var p2 = new Vector2(pos.x, pos.y + size); - var p3 = new Vector2(pos.x + x, pos.y - y); - ChartDrawer.DrawTriangle(vh, p1, p2, p3, color, toColor, color); - } - - public static void DrawTriangle(VertexHelper vh, Vector3 p1, - Vector3 p2, Vector3 p3, Color32 color, Color32 color2, Color32 color3) - { - UIVertex v1 = new UIVertex(); - v1.position = p1; - v1.color = color; - v1.uv0 = zeroVector2; - UIVertex v2 = new UIVertex(); - v2.position = p2; - v2.color = color2; - v2.uv0 = zeroVector2; - UIVertex v3 = new UIVertex(); - v3.position = p3; - v3.color = color3; - v3.uv0 = zeroVector2; - int startIndex = vh.currentVertCount; - vh.AddVert(v1); - vh.AddVert(v2); - vh.AddVert(v3); - vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2); - } - - public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color, - float smoothness = 2f) - { - DrawCricle(vh, p, radius, color, color, 0, s_Color32Clear, smoothness); - } - - public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color, - Color32 toColor, float smoothness = 2f) - { - DrawSector(vh, p, radius, color, toColor, 0, 360, 0, s_Color32Clear, smoothness); - } - - public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color, - Color32 toColor, float borderWidth, Color32 borderColor, float smoothness = 2f) - { - DrawSector(vh, p, radius, color, toColor, 0, 360, borderWidth, borderColor, smoothness); - } - - public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color, - float borderWidth, Color32 borderColor, float smoothness = 2f) - { - DrawCricle(vh, p, radius, color, color, borderWidth, borderColor, smoothness); - } - - public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness, - Color32 color, Color32 emptyColor, float smoothness = 2f) - { - DrawDoughnut(vh, p, radius - tickness, radius, color, color, emptyColor, 0, 360, 0, s_Color32Clear, 0, smoothness); - } - - public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness, - Color32 color, Color32 emptyColor, float borderWidth, Color32 borderColor, float smoothness = 2f) - { - DrawDoughnut(vh, p, radius - tickness, radius, color, color, emptyColor, 0, 360, borderWidth, - borderColor, 0, smoothness); - } - - public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness, - Color32 color, Color32 toColor, Color32 emptyColor, float smoothness = 2f) - { - DrawDoughnut(vh, p, radius - tickness, radius, color, toColor, emptyColor, 0, 360, 0, - s_Color32Clear, 0, smoothness); - } - - public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness, - Color32 color, Color32 toColor, Color32 emptyColor, float borderWidth, Color32 borderColor, - float smoothness = 2f) - { - DrawDoughnut(vh, p, radius - tickness, radius, color, toColor, emptyColor, 0, 360, borderWidth, - borderColor, 0, smoothness); - } - - public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color, - float startDegree, float toDegree, float smoothness = 2f) - { - DrawSector(vh, p, radius, color, color, startDegree, toDegree, 0, s_Color32Clear, smoothness); - } - - public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color, Color32 toColor, - float startDegree, float toDegree, int gradientType = 0, bool isYAxis = false, float smoothness = 2f) - { - DrawSector(vh, p, radius, color, toColor, startDegree, toDegree, 0, s_Color32Clear, 0, smoothness, gradientType, isYAxis); - } - - public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color, - float startDegree, float toDegree, float borderWidth, Color32 borderColor, float smoothness = 2f) - { - DrawSector(vh, p, radius, color, color, startDegree, toDegree, borderWidth, borderColor, smoothness); - } - - public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color, Color32 toColor, - float startDegree, float toDegree, float borderWidth, Color32 borderColor, float smoothness = 2f) - { - DrawSector(vh, p, radius, color, toColor, startDegree, toDegree, borderWidth, borderColor, 0, smoothness); - } - - /// <summary> - /// 绘制扇形(可带边框、有空白边距、3种类型渐变) - /// </summary> - /// <param name="vh"></param> - /// <param name="p">中心点</param> - /// <param name="radius">半径</param> - /// <param name="color">颜色</param> - /// <param name="toColor">渐变颜色</param> - /// <param name="startDegree">开始角度</param> - /// <param name="toDegree">结束角度</param> - /// <param name="borderWidth">边框宽度</param> - /// <param name="borderColor">边框颜色</param> - /// <param name="space">边距</param> - /// <param name="smoothness">光滑度</param> - /// <param name="gradientType">渐变类型,0:向圆形渐变,1:水平或垂直渐变,2:开始角度向结束角度渐变</param> - /// <param name="isYAxis">水平渐变还是垂直渐变,gradientType为1时生效</param> - public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color, Color32 toColor, - float startDegree, float toDegree, float borderWidth, Color32 borderColor, float space, - float smoothness, int gradientType = 0, bool isYAxis = false) - { - if (radius == 0) return; - if (space > 0 && Mathf.Abs(toDegree - startDegree) >= 360) space = 0; - radius -= borderWidth; - smoothness = (smoothness < 0 ? 2f : smoothness); - int segments = (int)((2 * Mathf.PI * radius) * (Mathf.Abs(toDegree - startDegree) / 360) / smoothness); - if (segments < 1) segments = 1; - float startAngle = startDegree * Mathf.Deg2Rad; - float toAngle = toDegree * Mathf.Deg2Rad; - float realStartAngle = startAngle; - float realToAngle = toAngle; - float halfAngle = (toAngle - startAngle) / 2; - float borderAngle = 0; - float spaceAngle = 0; - - var p2 = p + radius * ChartHelper.GetDire(startAngle); - var p3 = Vector3.zero; - var p4 = Vector3.zero; - var spaceCenter = p; - var realCenter = p; - var lastP4 = p; - var lastColor = color; - var needBorder = borderWidth != 0; - var needSpace = space != 0; - var borderLineWidth = needSpace ? borderWidth : borderWidth / 2; - var lastPos = Vector3.zero; - var middleDire = ChartHelper.GetDire(startAngle + halfAngle); - if (needBorder || needSpace) - { - float spaceDiff = 0f; - float borderDiff = 0f; - if (needSpace) - { - spaceDiff = space / Mathf.Sin(halfAngle); - spaceCenter = p + spaceDiff * middleDire; - realCenter = spaceCenter; - spaceAngle = 2 * Mathf.Asin(space / (2 * radius)); - realStartAngle = startAngle + spaceAngle; - realToAngle = toAngle - spaceAngle; - if (realToAngle < realStartAngle) realToAngle = realStartAngle; - p2 = ChartHelper.GetPos(p, radius, realStartAngle); - } - if (needBorder) - { - borderDiff = borderLineWidth / Mathf.Sin(halfAngle); - realCenter += borderDiff * middleDire; - borderAngle = 2 * Mathf.Asin(borderLineWidth / (2 * radius)); - realStartAngle = realStartAngle + borderAngle; - realToAngle = realToAngle - borderAngle; - if (realToAngle < realStartAngle) - { - realToAngle = realStartAngle; - p2 = ChartHelper.GetPos(p, radius, realStartAngle); - } - else - { - var borderX1 = ChartHelper.GetPos(p, radius, realStartAngle); - DrawPolygon(vh, realCenter, spaceCenter, p2, borderX1, borderColor); - p2 = borderX1; - - var borderX2 = ChartHelper.GetPos(p, radius, realToAngle); - var pEnd = ChartHelper.GetPos(p, radius, toAngle - spaceAngle); - DrawPolygon(vh, realCenter, borderX2, pEnd, spaceCenter, borderColor); - } - } - } - float segmentAngle = (realToAngle - realStartAngle) / segments; - bool isLeft = startDegree >= 180; - for (int i = 0; i <= segments; i++) - { - float currAngle = realStartAngle + i * segmentAngle; - p3 = p + radius * ChartHelper.GetDire(currAngle); - if (gradientType == 1) - { - if (isYAxis) - { - p4 = new Vector3(p3.x, realCenter.y); - var dist = p4.x - realCenter.x; - var tcolor = Color32.Lerp(color, toColor, dist >= 0 ? dist / radius : Mathf.Min(radius + dist, radius) / radius); - if (isLeft && (i == segments || i == 0)) tcolor = toColor; - DrawPolygon(vh, lastP4, p2, p3, p4, lastColor, tcolor); - lastP4 = p4; - lastColor = tcolor; - } - else - { - p4 = new Vector3(realCenter.x, p3.y); - var tcolor = Color32.Lerp(color, toColor, Mathf.Abs(p4.y - realCenter.y) / radius); - DrawPolygon(vh, lastP4, p2, p3, p4, lastColor, tcolor); - lastP4 = p4; - lastColor = tcolor; - } - } - else if (gradientType == 2) - { - var tcolor = Color32.Lerp(color, toColor, i / segments); - DrawPolygon(vh, realCenter, p2, p3, realCenter, lastColor, tcolor); - lastColor = tcolor; - } - else - { - DrawTriangle(vh, realCenter, p2, p3, toColor, color, color); - } - p2 = p3; - - } - if (needBorder || needSpace) - { - if (realToAngle > realStartAngle) - { - var borderX2 = p + radius * ChartHelper.GetDire(realToAngle); - DrawTriangle(vh, realCenter, p2, borderX2, toColor, color, color); - if (needBorder) - { - var realStartDegree = (realStartAngle - borderAngle) * Mathf.Rad2Deg; - var realToDegree = (realToAngle + borderAngle) * Mathf.Rad2Deg; - DrawDoughnut(vh, p, radius, radius + borderWidth, borderColor, s_Color32Clear, realStartDegree, - realToDegree, smoothness); - } - } - } - } - - public static void DrawRoundCap(VertexHelper vh, Vector3 center, float width, float radius, float angle, - bool clockwise, Color32 color, bool end) - { - var px = Mathf.Sin(angle * Mathf.Deg2Rad) * radius; - var py = Mathf.Cos(angle * Mathf.Deg2Rad) * radius; - var pos = new Vector3(px, py) + center; - if (end) - { - if (clockwise) - ChartDrawer.DrawSector(vh, pos, width, color, angle, angle + 180, 0, s_Color32Clear); - else - ChartDrawer.DrawSector(vh, pos, width, color, angle, angle - 180, 0, s_Color32Clear); - } - else - { - if (clockwise) - ChartDrawer.DrawSector(vh, pos, width, color, angle + 180, angle + 360, 0, s_Color32Clear); - else - ChartDrawer.DrawSector(vh, pos, width, color, angle - 180, angle - 360, 0, s_Color32Clear); - } - } - - public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius, - Color32 color, Color32 emptyColor, float smoothness = 2f) - { - DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, 0, 360, 0, s_Color32Clear, - 0, smoothness); - } - - public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius, - Color32 color, Color32 emptyColor, float startDegree, - float toDegree, float smoothness = 2f) - { - DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, startDegree, toDegree, - 0, s_Color32Clear, 0, smoothness); - } - - public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius, - Color32 color, Color32 emptyColor, float startDegree, - float toDegree, float borderWidth, Color32 borderColor, float smoothness = 2f) - { - DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, startDegree, toDegree, - borderWidth, borderColor, 0, smoothness); - } - - public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius, - Color32 color, Color32 toColor, Color32 emptyColor, float smoothness = 2f) - { - DrawDoughnut(vh, p, insideRadius, outsideRadius, color, toColor, emptyColor, 0, 360, 0, s_Color32Clear, - 0, smoothness); - } - - public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius, - Color32 color, Color32 toColor, Color32 emptyColor, float startDegree, float toDegree, float borderWidth, - Color32 borderColor, float space, float smoothness, bool roundCap = false, bool clockwise = true) - { - if (toDegree - startDegree == 0) return; - if (space > 0 && Mathf.Abs(toDegree - startDegree) >= 360) space = 0; - if (insideRadius <= 0) - { - DrawSector(vh, p, outsideRadius, color, toColor, startDegree, toDegree, borderWidth, borderColor, - space, smoothness); - return; - } - outsideRadius -= borderWidth; - insideRadius += borderWidth; - smoothness = smoothness < 0 ? 2f : smoothness; - Vector3 p1, p2, p3, p4, e1, e2; - var needBorder = borderWidth != 0; - var needSpace = space != 0; - var diffAngle = Mathf.Abs(toDegree - startDegree) * Mathf.Deg2Rad; - - int segments = (int)((2 * Mathf.PI * outsideRadius) * (diffAngle * Mathf.Rad2Deg / 360) / smoothness); - if (segments < 1) segments = 1; - float startAngle = startDegree * Mathf.Deg2Rad; - float toAngle = toDegree * Mathf.Deg2Rad; - - float realStartOutAngle = startAngle; - float realToOutAngle = toAngle; - float realStartInAngle = startAngle; - float realToInAngle = toAngle; - float halfAngle = (toAngle - startAngle) / 2; - float borderAngle = 0, borderInAngle = 0, borderHalfAngle = 0; - float spaceAngle = 0, spaceInAngle = 0, spaceHalfAngle = 0; - - var spaceCenter = p; - var realCenter = p; - var startDire = new Vector3(Mathf.Sin(startAngle), Mathf.Cos(startAngle)).normalized; - var toDire = new Vector3(Mathf.Sin(toAngle), Mathf.Cos(toAngle)).normalized; - var middleDire = new Vector3(Mathf.Sin(startAngle + halfAngle), Mathf.Cos(startAngle + halfAngle)).normalized; - p1 = p + insideRadius * startDire; - p2 = p + outsideRadius * startDire; - e1 = p + insideRadius * toDire; - e2 = p + outsideRadius * toDire; - if (roundCap) - { - var roundRadius = (outsideRadius - insideRadius) / 2; - var roundAngleRadius = insideRadius + roundRadius; - var roundAngle = Mathf.Atan(roundRadius / roundAngleRadius); - if (diffAngle < 2 * roundAngle) - { - roundCap = false; - } - } - if (needBorder || needSpace) - { - if (needSpace) - { - var spaceDiff = space / Mathf.Sin(halfAngle); - spaceCenter = p + Mathf.Abs(spaceDiff) * middleDire; - realCenter = spaceCenter; - spaceAngle = 2 * Mathf.Asin(space / (2 * outsideRadius)); - spaceInAngle = 2 * Mathf.Asin(space / (2 * insideRadius)); - spaceHalfAngle = 2 * Mathf.Asin(space / (2 * (insideRadius + (outsideRadius - insideRadius) / 2))); - if (clockwise) - { - p1 = ChartHelper.GetPos(p, insideRadius, startAngle + spaceInAngle, false); - e1 = ChartHelper.GetPos(p, insideRadius, toAngle - spaceInAngle, false); - realStartOutAngle = startAngle + spaceAngle; - realToOutAngle = toAngle - spaceAngle; - realStartInAngle = startAngle + spaceInAngle; - realToInAngle = toAngle - spaceInAngle; - } - else - { - p1 = ChartHelper.GetPos(p, insideRadius, startAngle - spaceInAngle, false); - e1 = ChartHelper.GetPos(p, insideRadius, toAngle + spaceInAngle, false); - realStartOutAngle = startAngle - spaceAngle; - realToOutAngle = toAngle + spaceAngle; - realStartInAngle = startAngle - spaceInAngle; - realToOutAngle = toAngle + spaceInAngle; - } - p2 = ChartHelper.GetPos(p, outsideRadius, realStartOutAngle, false); - e2 = ChartHelper.GetPos(p, outsideRadius, realToOutAngle, false); - } - if (needBorder) - { - var borderDiff = borderWidth / Mathf.Sin(halfAngle); - realCenter += Mathf.Abs(borderDiff) * middleDire; - borderAngle = 2 * Mathf.Asin(borderWidth / (2 * outsideRadius)); - borderInAngle = 2 * Mathf.Asin(borderWidth / (2 * insideRadius)); - borderHalfAngle = 2 * Mathf.Asin(borderWidth / (2 * (insideRadius + (outsideRadius - insideRadius) / 2))); - if (clockwise) - { - realStartOutAngle = realStartOutAngle + borderAngle; - realToOutAngle = realToOutAngle - borderAngle; - realStartInAngle = startAngle + spaceInAngle + borderInAngle; - realToInAngle = toAngle - spaceInAngle - borderInAngle; - var newp1 = ChartHelper.GetPos(p, insideRadius, startAngle + spaceInAngle + borderInAngle, false); - var newp2 = ChartHelper.GetPos(p, outsideRadius, realStartOutAngle, false); - if (!roundCap) DrawPolygon(vh, newp2, newp1, p1, p2, borderColor); - p1 = newp1; - p2 = newp2; - if (toAngle - spaceInAngle - 2 * borderInAngle > realStartOutAngle) - { - var newe1 = ChartHelper.GetPos(p, insideRadius, toAngle - spaceInAngle - borderInAngle, false); - var newe2 = ChartHelper.GetPos(p, outsideRadius, realToOutAngle, false); - if (!roundCap) DrawPolygon(vh, newe2, e2, e1, newe1, borderColor); - e1 = newe1; - e2 = newe2; - } - } - else - { - realStartOutAngle = realStartOutAngle - borderAngle; - realToOutAngle = realToOutAngle + borderAngle; - realStartInAngle = startAngle - spaceInAngle - borderInAngle; - realToInAngle = toAngle + spaceInAngle + borderInAngle; - var newp1 = ChartHelper.GetPos(p, insideRadius, startAngle - spaceInAngle - borderInAngle, false); - var newp2 = ChartHelper.GetPos(p, outsideRadius, realStartOutAngle, false); - if (!roundCap) DrawPolygon(vh, newp2, newp1, p1, p2, borderColor); - p1 = newp1; - p2 = newp2; - if (toAngle + spaceInAngle + 2 * borderInAngle < realStartOutAngle) - { - var newe1 = ChartHelper.GetPos(p, insideRadius, toAngle + spaceInAngle + borderInAngle, false); - var newe2 = ChartHelper.GetPos(p, outsideRadius, realToOutAngle, false); - if (!roundCap) DrawPolygon(vh, newe2, e2, e1, newe1, borderColor); - e1 = newe1; - e2 = newe2; - } - } - } - } - if (roundCap) - { - var roundRadius = (outsideRadius - insideRadius) / 2; - var roundAngleRadius = insideRadius + roundRadius; - var roundAngle = Mathf.Atan(roundRadius / roundAngleRadius); - if (clockwise) - { - realStartOutAngle = startAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; - realStartInAngle = startAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; - } - else - { - realStartOutAngle = startAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; - realStartInAngle = startAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; - } - var roundTotalDegree = realStartOutAngle * Mathf.Rad2Deg; - var roundCenter = p + roundAngleRadius * ChartHelper.GetDire(realStartOutAngle); - var sectorStartDegree = clockwise ? roundTotalDegree + 180 : roundTotalDegree; - var sectorToDegree = clockwise ? roundTotalDegree + 360 : roundTotalDegree + 180; - DrawSector(vh, roundCenter, roundRadius, color, sectorStartDegree, sectorToDegree, smoothness / 2); - if (needBorder) - { - DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, s_Color32Clear, - sectorStartDegree, sectorToDegree, smoothness / 2); - } - p1 = ChartHelper.GetPos(p, insideRadius, realStartOutAngle); - p2 = ChartHelper.GetPos(p, outsideRadius, realStartOutAngle); - - if (clockwise) - { - realToOutAngle = toAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; - realToInAngle = toAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; - if (realToOutAngle < realStartOutAngle) realToOutAngle = realStartOutAngle; - } - else - { - realToOutAngle = toAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; - realToInAngle = toAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; - if (realToOutAngle > realStartOutAngle) realToOutAngle = realStartOutAngle; - } - roundTotalDegree = realToOutAngle * Mathf.Rad2Deg; - roundCenter = p + roundAngleRadius * ChartHelper.GetDire(realToOutAngle); - sectorStartDegree = clockwise ? roundTotalDegree : roundTotalDegree + 180; - sectorToDegree = clockwise ? roundTotalDegree + 180 : roundTotalDegree + 360; - DrawSector(vh, roundCenter, roundRadius, toColor, sectorStartDegree, sectorToDegree, smoothness / 2); - if (needBorder) - { - DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, s_Color32Clear, - sectorStartDegree, sectorToDegree, smoothness / 2); - } - e1 = ChartHelper.GetPos(p, insideRadius, realToOutAngle); - e2 = ChartHelper.GetPos(p, outsideRadius, realToOutAngle); - } - var segmentAngle = (realToInAngle - realStartInAngle) / segments; - var isGradient = !ChartHelper.IsValueEqualsColor(color, toColor); - for (int i = 0; i <= segments; i++) - { - float currAngle = realStartInAngle + i * segmentAngle; - p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), - p.y + outsideRadius * Mathf.Cos(currAngle)); - p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle), - p.y + insideRadius * Mathf.Cos(currAngle)); - if (!ChartHelper.IsClearColor(emptyColor)) DrawTriangle(vh, p, p1, p4, emptyColor); - if (isGradient) - { - var tcolor = Color32.Lerp(color, toColor, i * 1.0f / segments); - DrawPolygon(vh, p2, p3, p4, p1, tcolor, tcolor); - } - else - { - DrawPolygon(vh, p2, p3, p4, p1, color, color); - } - p1 = p4; - p2 = p3; - } - if (needBorder || needSpace || roundCap) - { - if (clockwise) - { - var isInAngleFixed = toAngle - spaceInAngle - 2 * borderInAngle > realStartOutAngle; - if (isInAngleFixed) DrawPolygon(vh, p2, e2, e1, p1, color, toColor); - else DrawTriangle(vh, p2, e2, p1, color, color, toColor); - if (needBorder) - { - var realStartDegree = (realStartOutAngle - (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; - var realToDegree = (realToOutAngle + (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; - if (realToDegree < realStartOutAngle) realToDegree = realStartOutAngle; - var inStartDegree = roundCap ? realStartDegree : (startAngle + spaceInAngle) * Mathf.Rad2Deg; - var inToDegree = roundCap ? realToDegree : (toAngle - spaceInAngle) * Mathf.Rad2Deg; - if (inToDegree < inStartDegree) inToDegree = inStartDegree; - if (isInAngleFixed) DrawDoughnut(vh, p, insideRadius - borderWidth, insideRadius, borderColor, s_Color32Clear, - inStartDegree, inToDegree, smoothness); - DrawDoughnut(vh, p, outsideRadius, outsideRadius + borderWidth, borderColor, s_Color32Clear, - realStartDegree, realToDegree, smoothness); - } - } - else - { - var isInAngleFixed = toAngle + spaceInAngle + 2 * borderInAngle < realStartOutAngle; - if (isInAngleFixed) DrawPolygon(vh, p2, e2, e1, p1, color, toColor); - else DrawTriangle(vh, p2, e2, p1, color, color, toColor); - if (needBorder) - { - var realStartDegree = (realStartOutAngle + (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; - var realToDegree = (realToOutAngle - (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; - var inStartDegree = roundCap ? realStartDegree : (startAngle - spaceInAngle) * Mathf.Rad2Deg; - var inToDegree = roundCap ? realToDegree : (toAngle + spaceInAngle) * Mathf.Rad2Deg; - if (inToDegree > inStartDegree) inToDegree = inStartDegree; - if (isInAngleFixed) DrawDoughnut(vh, p, insideRadius - borderWidth, insideRadius, borderColor, s_Color32Clear, - inStartDegree, inToDegree, smoothness); - DrawDoughnut(vh, p, outsideRadius, outsideRadius + borderWidth, borderColor, s_Color32Clear, - realStartDegree, realToDegree, smoothness); - } - } - } - } - - /// <summary> - /// 画贝塞尔曲线 - /// </summary> - /// <param name="vh"></param> - /// <param name="sp">起始点</param> - /// <param name="ep">结束点</param> - /// <param name="cp1">控制点1</param> - /// <param name="cp2">控制点2</param> - /// <param name="lineWidth">曲线宽</param> - /// <param name="lineColor">曲线颜色</param> - public static void DrawCurves(VertexHelper vh, Vector3 sp, Vector3 ep, Vector3 cp1, Vector3 cp2, - float lineWidth, Color32 lineColor, float smoothness) - { - var dist = Vector3.Distance(sp, ep); - var segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness)); - ChartHelper.GetBezierList2(ref s_CurvesPosList, sp, ep, segment, cp1, cp2); - if (s_CurvesPosList.Count > 1) - { - var start = s_CurvesPosList[0]; - var to = Vector3.zero; - var dir = s_CurvesPosList[1] - start; - var diff = Vector3.Cross(dir, Vector3.forward).normalized * lineWidth; - var startUp = start - diff; - var startDn = start + diff; - for (int i = 1; i < s_CurvesPosList.Count; i++) - { - to = s_CurvesPosList[i]; - diff = Vector3.Cross(to - start, Vector3.forward).normalized * lineWidth; - var toUp = to - diff; - var toDn = to + diff; - DrawPolygon(vh, startUp, toUp, toDn, startDn, lineColor); - startUp = toUp; - startDn = toDn; - start = to; - } - } - } - public static void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius, Color32 backgroundColor, float smoothness) @@ -1314,82 +26,97 @@ namespace XCharts case SerieSymbolType.Circle: if (gap > 0) { - ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness); + UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness); } else { - ChartDrawer.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness); + UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness); } break; case SerieSymbolType.EmptyCircle: if (gap > 0) { - ChartDrawer.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness); - ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness); + UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness); + UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness); } else { - ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness); + UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness); } break; case SerieSymbolType.Rect: if (gap > 0) { - ChartDrawer.DrawPolygon(vh, pos, symbolSize + gap, backgroundColor); - ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor); + UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor); + UGL.DrawSquare(vh, pos, symbolSize, color, toColor); } else { - //ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor); - ChartDrawer.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true); + //UGL.DrawPolygon(vh, pos, symbolSize, color, toColor); + UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true); } break; case SerieSymbolType.Triangle: if (gap > 0) { - ChartDrawer.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor); - ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor); + UGL.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor); + UGL.DrawTriangle(vh, pos, symbolSize, color, toColor); } else { - ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor); + UGL.DrawTriangle(vh, pos, symbolSize, color, toColor); } break; case SerieSymbolType.Diamond: if (gap > 0) { - ChartDrawer.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor); - ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor); + UGL.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor); + UGL.DrawDiamond(vh, pos, symbolSize, color, toColor); } else { - ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor); + UGL.DrawDiamond(vh, pos, symbolSize, color, toColor); } break; } } + // public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, + // Vector3 startPos, Vector3 endPos, Color32 color, float themeWidth) + // { + // var type = lineStyle.type; + // var width = lineStyle.GetWidth(themeWidth); + // DrawLineStyle(vh, type, width, startPos, endPos, color); + // } + public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, + Vector3 startPos, Vector3 endPos, Color32 color, float themeWidth, LineStyle.Type themeType) + { + var type = lineStyle.GetType(themeType); + var width = lineStyle.GetWidth(themeWidth); + DrawLineStyle(vh, type, width, startPos, endPos, color); + } + + public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth, Vector3 startPos, Vector3 endPos, Color32 color) { - var type = lineStyle.type; - var width = lineStyle.width; - switch (type) + var type = lineType; + switch (lineType) { case LineStyle.Type.Dashed: - ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color); + UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color); break; case LineStyle.Type.Dotted: - ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color); + UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color); break; case LineStyle.Type.Solid: - ChartDrawer.DrawLine(vh, startPos, endPos, width, color); + UGL.DrawLine(vh, startPos, endPos, lineWidth, color); break; case LineStyle.Type.DashDot: - ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color); + UGL.DrawDashDotLine(vh, startPos, endPos, lineWidth, color); break; case LineStyle.Type.DashDotDot: - ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color); + UGL.DrawDashDotDotLine(vh, startPos, endPos, lineWidth, color); break; } } diff --git a/Runtime/Internal/Utility/ChartHelper.cs b/Runtime/Internal/Utility/ChartHelper.cs index 8b60116f..7eea3605 100644 --- a/Runtime/Internal/Utility/ChartHelper.cs +++ b/Runtime/Internal/Utility/ChartHelper.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Text; using System; @@ -12,6 +12,9 @@ using System.Text.RegularExpressions; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; +#if dUI_TextMeshPro +using TMPro; +#endif #if UNITY_EDITOR using UnityEditor; #endif @@ -139,6 +142,21 @@ namespace XCharts return name; } + public static void RemoveComponent<T>(GameObject gameObject) + { + var component = gameObject.GetComponent<T>(); + if (component != null) + { +#if UNITY_EDITOR + if (!Application.isPlaying) + GameObject.DestroyImmediate(component as GameObject); + else + GameObject.Destroy(component as GameObject); +#else + GameObject.Destroy(component as GameObject); +#endif + } + } public static T GetOrAddComponent<T>(Transform transform) where T : Component { return GetOrAddComponent<T>(transform.gameObject); @@ -148,9 +166,12 @@ namespace XCharts { if (gameObject.GetComponent<T>() == null) { - gameObject.AddComponent<T>(); + return gameObject.AddComponent<T>(); + } + else + { + return gameObject.GetComponent<T>(); } - return gameObject.GetComponent<T>(); } public static GameObject AddObject(string name, Transform parent, Vector2 anchorMin, @@ -188,12 +209,62 @@ namespace XCharts return obj; } + public static void UpdateRectTransform(GameObject obj, Vector2 anchorMin, + Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta) + { + if (obj == null) return; + RectTransform rect = GetOrAddComponent<RectTransform>(obj); + rect.sizeDelta = sizeDelta; + rect.anchorMin = anchorMin; + rect.anchorMax = anchorMax; + rect.pivot = pivot; + } + + public static ChartText AddTextObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, + Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme) + { + GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); + txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate); + var chartText = new ChartText(); +#if dUI_TextMeshPro + RemoveComponent<Text>(txtObj); + chartText.tmpText = GetOrAddComponent<TextMeshProUGUI>(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 = false; +#else + chartText.text = GetOrAddComponent<Text>(txtObj); + chartText.text.font = textStyle.font == null ? theme.font : textStyle.font; + chartText.text.fontStyle = textStyle.fontStyle; + chartText.text.alignment = textStyle.alignment; + chartText.text.horizontalOverflow = HorizontalWrapMode.Overflow; + chartText.text.verticalOverflow = VerticalWrapMode.Overflow; + chartText.text.supportRichText = true; + chartText.text.raycastTarget = false; +#endif + chartText.SetColor(textStyle.GetColor(theme.textColor)); + chartText.SetFontSize(textStyle.fontSize > 0 ? textStyle.fontSize : theme.fontSize); + chartText.SetText("Text"); + chartText.SetLineSpacing(textStyle.lineSpacing); + + RectTransform rect = GetOrAddComponent<RectTransform>(txtObj); + rect.localPosition = Vector3.zero; + rect.sizeDelta = sizeDelta; + rect.anchorMin = anchorMin; + rect.anchorMax = anchorMax; + rect.pivot = pivot; + 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); - Text txt = GetOrAddComponent<Text>(txtObj); + var txt = GetOrAddComponent<Text>(txtObj); txt.font = font; txt.fontSize = fontSize; txt.fontStyle = fontStyle; @@ -212,9 +283,37 @@ namespace XCharts rect.anchorMin = anchorMin; rect.anchorMax = anchorMax; rect.pivot = pivot; - return txtObj.GetComponent<Text>(); + 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<TextMeshProUGUI>(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<RectTransform>(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) @@ -230,8 +329,25 @@ namespace XCharts return btnObj.GetComponent<Button>(); } - internal static GameObject AddTooltipContent(string name, Transform parent, Font font, int fontSize, - FontStyle fontStyle, float lineSpacing) +#if dUI_TextMeshPro + public static Button AddTMPButtonObject(string name, Transform parent, TMP_FontAsset font, int fontSize, + Color color, TextAlignmentOptions anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, + Vector2 sizeDelta, float lineSpacing) + { + GameObject btnObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); + GetOrAddComponent<Image>(btnObj); + GetOrAddComponent<Button>(btnObj); + var txt = AddTMPTextObject("Text", btnObj.transform, font, color, anchor, + new Vector2(0, 0), new Vector2(1, 1), new Vector2(0.5f, 0.5f), + sizeDelta, fontSize, lineSpacing); + txt.rectTransform.offsetMin = Vector2.zero; + txt.rectTransform.offsetMax = Vector2.zero; + return btnObj.GetComponent<Button>(); + } +#endif + + internal static GameObject AddTooltipContent(string name, Transform parent, TextStyle textStyle, + ChartTheme theme) { var anchorMax = new Vector2(0, 1); var anchorMin = new Vector2(0, 1); @@ -240,10 +356,11 @@ namespace XCharts GameObject tooltipObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); var img = GetOrAddComponent<Image>(tooltipObj); img.color = Color.black; - Text txt = AddTextObject("Text", tooltipObj.transform, font, Color.white, TextAnchor.UpperLeft, - anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle, lineSpacing); - txt.text = "Text"; - txt.transform.localPosition = new Vector2(3, -3); + var txt = AddTextObject("Text", tooltipObj.transform, anchorMin, anchorMax, pivot, sizeDelta, + textStyle, theme.tooltip); + txt.SetAlignment(TextAnchor.UpperLeft); + txt.SetText("Text"); + txt.SetLocalPosition(new Vector2(3, -3)); tooltipObj.transform.localPosition = Vector3.zero; return tooltipObj; } @@ -260,46 +377,53 @@ namespace XCharts return iconObj; } - internal static GameObject AddSerieLabel(string name, Transform parent, Font font, Color textColor, - Color backgroundColor, int fontSize, FontStyle fontStyle, float rotate, float width, float height, - float lineSpacing) + internal static GameObject AddSerieLabel(string name, Transform parent, float width, float height, + Color color, TextStyle textStyle, ChartTheme theme) { 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 sizeDelta = (width != 0 && height != 0) ? new Vector2(width, height) : new Vector2(50, fontSize + 2); - GameObject labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); - //var img = GetOrAddComponent<Image>(labelObj); - //img.color = backgroundColor; - labelObj.transform.localEulerAngles = new Vector3(0, 0, rotate); - Text txt = AddTextObject("Text", labelObj.transform, font, textColor, TextAnchor.MiddleCenter, - anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle, lineSpacing); - txt.text = "Text"; - txt.transform.localPosition = new Vector2(0, 0); - txt.transform.localEulerAngles = Vector3.zero; + var sizeDelta = (width != 0 && height != 0) + ? new Vector2(width, height) + : new Vector2(50, textStyle.GetFontSize(theme.common) + 2); + var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); + var txt = AddTextObject("Text", labelObj.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, + theme.common); + txt.SetColor(color); + txt.SetAlignment(TextAnchor.MiddleCenter); + txt.SetText("Text"); + txt.SetLocalPosition(new Vector2(0, 0)); + txt.SetLocalEulerAngles(Vector3.zero); labelObj.transform.localPosition = Vector3.zero; + labelObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate); return labelObj; } - internal static GameObject AddTooltipLabel(string name, Transform parent, Font font, Vector2 pivot) + internal static GameObject AddTooltipLabel(string name, Transform parent, ChartTheme theme, Vector2 pivot) { var anchorMax = new Vector2(0, 0); var anchorMin = new Vector2(0, 0); var sizeDelta = new Vector2(100, 50); - return AddTooltipLabel(name, parent, font, pivot, anchorMin, anchorMax, sizeDelta); + return AddTooltipLabel(name, parent, theme, pivot, anchorMin, anchorMax, sizeDelta); } - internal static GameObject AddTooltipLabel(string name, Transform parent, Font font, Vector2 pivot, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta) + internal static GameObject AddTooltipLabel(string name, Transform parent, ChartTheme theme, Vector2 pivot, + Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta) { GameObject labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); labelObj.transform.localPosition = Vector3.zero; var img = GetOrAddComponent<Image>(labelObj); img.color = Color.black; - Text txt = AddTextObject("Text", labelObj.transform, font, Color.white, TextAnchor.MiddleCenter, +#if dUI_TextMeshPro + var alignment = TextAlignmentOptions.Center; + var txt = AddTMPTextObject("Text", labelObj.transform, theme.tmpFont, Color.white, alignment, new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 1), sizeDelta, 16); +#else + var txt = AddTextObject("Text", labelObj.transform, theme.font, Color.white, TextAnchor.MiddleCenter, + new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 1), sizeDelta, 16); +#endif txt.GetComponent<RectTransform>().offsetMin = Vector2.zero; txt.GetComponent<RectTransform>().offsetMax = Vector2.zero; - txt.text = "Text"; return labelObj; } @@ -624,7 +748,7 @@ namespace XCharts splitNumber = 0; if (value <= 0) return 0; float max = 0; - while (max < value) + while (splitNumber < 12 && max < value) { if (isLogBaseE) { @@ -858,5 +982,21 @@ namespace XCharts newColor.b = (byte)(color.b * rate); return newColor; } + + public static bool IsPointInQuadrilateral(Vector3 P, Vector3 A, Vector3 B, Vector3 C, Vector3 D) + { + Vector3 v0 = Vector3.Cross(A - D, P - D); + Vector3 v1 = Vector3.Cross(B - A, P - A); + Vector3 v2 = Vector3.Cross(C - B, P - B); + Vector3 v3 = Vector3.Cross(D - C, P - C); + if (Vector3.Dot(v0, v1) < 0 || Vector3.Dot(v0, v2) < 0 || Vector3.Dot(v0, v3) < 0) + { + return false; + } + else + { + return true; + } + } } } \ No newline at end of file diff --git a/Runtime/Internal/Utility/PropertyUtility.cs.meta b/Runtime/Internal/Utility/PropertyUtility.cs.meta deleted file mode 100644 index 45360e76..00000000 --- a/Runtime/Internal/Utility/PropertyUtility.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c99b09a733f8d45a69c90f27b00cd908 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/LineChart.cs b/Runtime/LineChart.cs index ea090282..ad4c711b 100644 --- a/Runtime/LineChart.cs +++ b/Runtime/LineChart.cs @@ -1,10 +1,10 @@  -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -21,24 +21,22 @@ namespace XCharts protected override void Reset() { base.Reset(); - m_Title.text = "LineChart"; - m_Tooltip.type = Tooltip.Type.Line; + title.text = "LineChart"; + tooltip.type = Tooltip.Type.Line; - m_VisualMap.enable = false; - m_VisualMap.show = false; - m_VisualMap.autoMinMax = true; - m_VisualMap.direction = VisualMap.Direction.Y; - m_VisualMap.inRange.Clear(); - m_VisualMap.inRange.Add(Color.blue); - m_VisualMap.inRange.Add(Color.red); + visualMap.enable = false; + visualMap.show = false; + visualMap.autoMinMax = true; + visualMap.direction = VisualMap.Direction.Y; + visualMap.inRange.Clear(); + visualMap.inRange.Add(Color.blue); + visualMap.inRange.Add(Color.red); RemoveData(); - var serie = AddSerie(SerieType.Line, "serie1"); - serie.symbol.show = true; + SerieTemplate.AddDefaultLineSerie(this, "serie1"); for (int i = 0; i < 5; i++) { AddXAxisData("x" + (i + 1)); - AddData(0, UnityEngine.Random.Range(10, 90)); } } #endif diff --git a/Runtime/LiquidChart.cs b/Runtime/LiquidChart.cs index c1f613cd..0bcb54a7 100644 --- a/Runtime/LiquidChart.cs +++ b/Runtime/LiquidChart.cs @@ -1,15 +1,13 @@ -using System.Linq; +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ - -using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using XUGL; namespace XCharts { @@ -20,240 +18,19 @@ namespace XCharts [ExecuteInEditMode] [RequireComponent(typeof(RectTransform))] [DisallowMultipleComponent] - public partial class LiquidChart : BaseChart + public class LiquidChart : BaseChart { - [SerializeField] private List<Vessel> m_Vessels = new List<Vessel>(); - private bool m_UpdateLabelText = false; - - protected override void Awake() - { - base.Awake(); - UpdateRuntimeValue(); - SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName); - } #if UNITY_EDITOR protected override void Reset() { base.Reset(); - m_Title.text = "LiquidChart"; + title.text = "LiquidChart"; RemoveData(); RemoveVessel(); AddVessel(Vessel.defaultVessel); - var serie = AddSerie(SerieType.Liquid, "serie1"); - serie.min = 0; - serie.max = 100; - serie.label.show = true; - serie.label.fontSize = 40; - serie.label.formatter = "{d}%"; - serie.label.color = new Color32(70, 70, 240, 255); - AddData(0, UnityEngine.Random.Range(0, 100)); - } - - protected override void OnValidate() - { - base.OnValidate(); - RefreshChart(); + SerieTemplate.AddDefaultLiquidSerie(this, "serie1"); } #endif - - protected override void OnSizeChanged() - { - base.OnSizeChanged(); - UpdateRuntimeValue(); - m_UpdateLabelText = true; - } - - protected override void Update() - { - base.Update(); - if (m_UpdateLabelText) - { - m_UpdateLabelText = false; - SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName); - } - } - - protected override void DrawChart(VertexHelper vh) - { - base.DrawChart(vh); - UpdateRuntimeValue(); - DrawVesselBackground(vh); - DrawSeries(vh); - DrawVessel(vh); - } - - private void UpdateRuntimeValue() - { - for (int i = 0; i < m_Vessels.Count; i++) - { - var vessel = m_Vessels[i]; - vessel.index = i; - VesselHelper.UpdateVesselCenter(vessel, m_ChartPosition, m_ChartWidth, m_ChartHeight); - } - } - - private void DrawVesselBackground(VertexHelper vh) - { - for (int i = 0; i < m_Vessels.Count; i++) - { - var vessel = m_Vessels[i]; - if (vessel.backgroundColor.a != 0) - { - var cenPos = vessel.runtimeCenterPos; - var radius = vessel.runtimeRadius; - ChartDrawer.DrawCricle(vh, cenPos, vessel.runtimeInnerRadius, vessel.backgroundColor, m_Settings.cicleSmoothness); - } - } - } - - private void DrawVessel(VertexHelper vh) - { - for (int i = 0; i < m_Vessels.Count; i++) - { - var vessel = m_Vessels[i]; - vessel.index = i; - DrawCirleVessel(vh, vessel); - } - } - - private void DrawCirleVessel(VertexHelper vh, Vessel vessel) - { - var cenPos = vessel.runtimeCenterPos; - var radius = vessel.runtimeRadius; - var serie = SeriesHelper.GetSerieByVesselIndex(m_Series, vessel.index); - var vesselColor = VesselHelper.GetColor(vessel, serie, m_ThemeInfo, m_LegendRealShowName); - ChartDrawer.DrawDoughnut(vh, cenPos, radius - vessel.shapeWidth, radius, vesselColor, Color.clear, m_Settings.cicleSmoothness); - } - - private void DrawSeries(VertexHelper vh) - { - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.GetSerie(i); - if (!serie.show) continue; - DrawSerie(vh, serie); - } - } - - private void DrawSerie(VertexHelper vh, Serie serie) - { - if (serie.animation.HasFadeOut()) - { - return; - } - var vessel = GetVessel(serie.vesselIndex); - if (vessel == null) return; - var cenPos = vessel.runtimeCenterPos; - var radius = vessel.runtimeInnerRadius; - var serieData = serie.GetSerieData(0); - if (serieData == null) return; - var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - var value = serieData.GetCurrData(1, dataChangeDuration); - if (serie.runtimeCheckValue != value) - { - serie.runtimeCheckValue = value; - m_UpdateLabelText = true; - } - if (serieData.labelPosition != cenPos) - { - serieData.labelPosition = cenPos; - m_UpdateLabelText = true; - } - if (value == 0) return; - var colorIndex = m_LegendRealShowName.IndexOf(serie.name); - - var realHig = (value - serie.min) / (serie.max - serie.min) * radius * 2; - serie.animation.InitProgress(1, 0, realHig); - - var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); - var a = Mathf.Abs(radius - hig + (hig > radius ? serie.waveHeight : -serie.waveHeight)); - var diff = Mathf.Sqrt(radius * radius - Mathf.Pow(a, 2)); - - var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, false); - var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, false); - var isNeedGradient = !ChartHelper.IsValueEqualsColor(color, toColor); - var isFull = hig >= 2 * radius; - if (hig >= 2 * radius) hig = 2 * radius; - if (isFull && !isNeedGradient) - { - ChartDrawer.DrawCricle(vh, cenPos, radius, toColor, m_Settings.cicleSmoothness); - } - else - { - var startY = cenPos.y - radius + hig; - var waveStartPos = new Vector3(cenPos.x - diff, startY); - var waveEndPos = new Vector3(cenPos.x + diff, startY); - var startX = hig > radius ? cenPos.x - radius : waveStartPos.x; - var endX = hig > radius ? cenPos.x + radius : waveEndPos.x; - - var step = vessel.smoothness; - if (step < 0.5f) step = 0.5f; - var lup = hig > radius ? new Vector3(cenPos.x - radius, cenPos.y) : waveStartPos; - var ldp = lup; - var nup = Vector3.zero; - var ndp = Vector3.zero; - var angle = 0f; - serie.runtimeWaveSpeed += serie.waveSpeed * Time.deltaTime; - var isStarted = false; - var isEnded = false; - var waveHeight = isFull ? 0 : serie.waveHeight; - while (startX < endX) - { - startX += step; - if (startX > endX) startX = endX; - if (startX > waveStartPos.x && !isStarted) - { - startX = waveStartPos.x; - isStarted = true; - } - if (startX > waveEndPos.x && !isEnded) - { - startX = waveEndPos.x; - isEnded = true; - } - var py = Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2)); - if (startX < waveStartPos.x || startX > waveEndPos.x) - { - nup = new Vector3(startX, cenPos.y + py); - } - else - { - var py2 = waveHeight * Mathf.Sin(1 / serie.waveLength * angle + serie.runtimeWaveSpeed + serie.waveOffset); - var nupY = waveStartPos.y + py2; - if (nupY > cenPos.y + py) nupY = cenPos.y + py; - else if (nupY < cenPos.y - py) nupY = cenPos.y - py; - nup = new Vector3(startX, nupY); - angle += step; - } - ndp = new Vector3(startX, cenPos.y - py); - if (!ChartHelper.IsValueEqualsColor(color, toColor)) - { - var colorMin = cenPos.y - radius; - var colorMax = startY + serie.waveHeight; - var tcolor1 = Color32.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin)); - var tcolor2 = Color32.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin)); - ChartDrawer.DrawPolygon(vh, lup, nup, ndp, ldp, tcolor1, tcolor2); - } - else - { - ChartDrawer.DrawPolygon(vh, lup, nup, ndp, ldp, color); - } - lup = nup; - ldp = ndp; - } - } - - if (serie.waveSpeed != 0 && Application.isPlaying && !isFull) - { - RefreshChart(); - } - if (!serie.animation.IsFinish()) - { - serie.animation.CheckProgress(realHig); - m_IsPlayingAnimation = true; - RefreshChart(); - } - } } } diff --git a/Runtime/PieChart.cs b/Runtime/PieChart.cs index 7c91e909..1db8b35c 100644 --- a/Runtime/PieChart.cs +++ b/Runtime/PieChart.cs @@ -1,14 +1,11 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System; using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; namespace XCharts { @@ -18,11 +15,6 @@ namespace XCharts [DisallowMultipleComponent] public partial class PieChart : BaseChart { - private bool isDrawPie; - private bool m_IsEnterLegendButtom; - - protected Action<PointerEventData, int, int> m_OnPointerClickPie; - protected override void Awake() { base.Awake(); @@ -33,515 +25,11 @@ namespace XCharts protected override void Reset() { base.Reset(); - m_Title.text = "PieChart"; - m_Legend.show = true; + title.text = "PieChart"; + m_Legends[0].show = true; RemoveData(); - AddSerie(SerieType.Pie, "serie1"); - AddData(0, 70, "pie1"); - AddData(0, 20, "pie2"); - AddData(0, 10, "pie3"); + SerieTemplate.AddDefaultPieSerie(this, "serie1"); } #endif - - protected override void Update() - { - base.Update(); - if (!isDrawPie) RefreshChart(); - } - - protected override void DrawChart(VertexHelper vh) - { - base.DrawChart(vh); - UpdateRuntimeData(); - DrawLabelLine(vh); - DrawPie(vh); - DrawLabelBackground(vh); - } - - private void UpdateRuntimeData() - { - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.list[i]; - if (serie.type != SerieType.Pie) continue; - serie.index = i; - var data = serie.data; - serie.runtimeDataMax = serie.yMax; - serie.runtimePieDataTotal = serie.yTotal; - serie.animation.InitProgress(data.Count, 0, 360); - SerieHelper.UpdateCenter(serie, chartPosition, chartWidth, chartHeight); - float totalDegree = 360f; - float startDegree = 0; - int showdataCount = 0; - foreach (var sd in serie.data) - { - if (sd.show && serie.pieRoseType == RoseType.Area) showdataCount++; - sd.canShowLabel = false; - } - float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - bool isAllZeroValue = SerieHelper.IsAllZeroValue(serie, 1); - float zeroReplaceValue = totalDegree / data.Count; - if (isAllZeroValue) - { - serie.runtimeDataMax = zeroReplaceValue; - serie.runtimePieDataTotal = totalDegree; - } - for (int n = 0; n < data.Count; n++) - { - var serieData = data[n]; - serieData.index = n; - float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration); - serieData.runtimePieStartAngle = startDegree; - serieData.runtimePieToAngle = startDegree; - serieData.runtimePieHalfAngle = startDegree; - serieData.runtimePieCurrAngle = startDegree; - if (!serieData.show) - { - continue; - } - float degree = serie.pieRoseType == RoseType.Area ? - (totalDegree / showdataCount) : (totalDegree * value / serie.runtimePieDataTotal); - serieData.runtimePieToAngle = startDegree + degree; - - serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ? - serie.runtimeInsideRadius + (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax : - serie.runtimeOutsideRadius; - if (serieData.highlighted) - { - serieData.runtimePieOutsideRadius += m_Settings.pieTooltipExtraRadius; - } - var offset = 0f; - if (serie.pieClickOffset && serieData.selected) - { - offset += m_Settings.pieSelectedOffset; - } - if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle)) - { - serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail(); - } - else - { - serieData.runtimePieCurrAngle = serieData.runtimePieToAngle; - } - var halfDegree = (serieData.runtimePieToAngle - startDegree) / 2; - serieData.runtimePieHalfAngle = startDegree + halfDegree; - serieData.runtiemPieOffsetCenter = serie.runtimeCenterPos; - serieData.runtimePieInsideRadius = serie.runtimeInsideRadius; - if (offset > 0) - { - var currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad; - var currSin = Mathf.Sin(currRad); - var currCos = Mathf.Cos(currRad); - serieData.runtimePieOffsetRadius = 0; - serieData.runtimePieInsideRadius -= serieData.runtimePieOffsetRadius; - serieData.runtimePieOutsideRadius -= serieData.runtimePieOffsetRadius; - if (serie.pieClickOffset && serieData.selected) - { - serieData.runtimePieOffsetRadius += m_Settings.pieSelectedOffset; - if (serieData.runtimePieInsideRadius > 0) serieData.runtimePieInsideRadius += m_Settings.pieSelectedOffset; - serieData.runtimePieOutsideRadius += m_Settings.pieSelectedOffset; - } - serieData.runtiemPieOffsetCenter = new Vector3(serie.runtimeCenterPos.x + serieData.runtimePieOffsetRadius * currSin, - serie.runtimeCenterPos.y + serieData.runtimePieOffsetRadius * currCos); - } - serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle; - startDegree = serieData.runtimePieToAngle; - SerieLabelHelper.UpdatePieLabelPosition(serie, serieData); - } - SerieLabelHelper.AvoidLabelOverlap(serie); - } - } - - private void DrawCenter(VertexHelper vh, Serie serie, ItemStyle itemStyle, float insideRadius) - { - if (!ChartHelper.IsClearColor(itemStyle.centerColor)) - { - var radius = insideRadius - itemStyle.centerGap; - ChartDrawer.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, m_Settings.cicleSmoothness); - } - } - - private void DrawPie(VertexHelper vh) - { - bool isClickOffset = false; - bool isDataHighlight = false; - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.list[i]; - serie.index = i; - var data = serie.data; - serie.animation.InitProgress(data.Count, 0, 360); - if (!serie.show || serie.animation.HasFadeOut()) - { - continue; - } - if (serie.pieClickOffset) isClickOffset = true; - bool dataChanging = false; - for (int n = 0; n < data.Count; n++) - { - var serieData = data[n]; - if (!serieData.show) - { - continue; - } - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted); - if (serieData.IsDataChanged()) dataChanging = true; - var serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName); - var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted); - var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted); - var borderWidth = itemStyle.borderWidth; - var borderColor = itemStyle.borderColor; - - if (serieData.highlighted) - { - isDataHighlight = true; - } - if (serie.pieClickOffset && serieData.selected) - { - var drawEndDegree = serieData.runtimePieCurrAngle; - var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0; - ChartDrawer.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius, - serieData.runtimePieOutsideRadius, color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree, - borderWidth, borderColor, serie.pieSpace / 2, m_Settings.cicleSmoothness, needRoundCap, true); - } - else - { - var drawEndDegree = serieData.runtimePieCurrAngle; - var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0; - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius, - color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, - m_Settings.cicleSmoothness, needRoundCap, true); - DrawCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius); - } - isDrawPie = true; - if (!serie.animation.CheckDetailBreak(serieData.runtimePieToAngle)) serie.animation.SetDataFinish(n); - else break; - } - if (!serie.animation.IsFinish()) - { - serie.animation.CheckProgress(360); - serie.animation.CheckSymbol(serie.symbol.size); - RefreshChart(); - } - if (dataChanging) - { - RefreshChart(); - } - } - raycastTarget = isClickOffset && isDataHighlight; - } - - private void DrawLabelLine(VertexHelper vh) - { - foreach (var serie in m_Series.list) - { - if (serie.type != SerieType.Pie) continue; - foreach (var serieData in serie.data) - { - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); - if (SerieLabelHelper.CanShowLabel(serie, serieData, serieLabel, 1)) - { - int colorIndex = m_LegendRealShowName.IndexOf(serieData.name); - Color color = m_ThemeInfo.GetColor(colorIndex); - DrawLabelLine(vh, serie, serieData, color); - } - } - } - } - - private void DrawLabelBackground(VertexHelper vh) - { - foreach (var serie in m_Series.list) - { - if (serie.type != SerieType.Pie) continue; - if (serie.avoidLabelOverlap) continue; - foreach (var serieData in serie.data) - { - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); - if (SerieLabelHelper.CanShowLabel(serie, serieData, serieLabel, 1)) - { - SerieLabelHelper.UpdatePieLabelPosition(serie, serieData); - DrawLabelBackground(vh, serie, serieData); - } - } - } - } - - private void DrawLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color) - { - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); - if (serieLabel.show - && serieLabel.position == SerieLabel.Position.Outside - && serieLabel.line) - { - var insideRadius = serieData.runtimePieInsideRadius; - var outSideRadius = serieData.runtimePieOutsideRadius; - var center = serie.runtimeCenterPos; - var currAngle = serieData.runtimePieHalfAngle; - if (!ChartHelper.IsClearColor(serieLabel.lineColor)) color = serieLabel.lineColor; - else if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine) color *= color; - float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad); - float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad); - var radius1 = serieLabel.lineType == SerieLabel.LineType.HorizontalLine ? - serie.runtimeOutsideRadius : outSideRadius; - var radius2 = serie.runtimeOutsideRadius + serieLabel.lineLength1; - var radius3 = insideRadius + (outSideRadius - insideRadius) / 2; - if (radius1 < serie.runtimeInsideRadius) radius1 = serie.runtimeInsideRadius; - radius1 -= 0.1f; - var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos); - var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos); - var pos2 = serieData.labelPosition; - if (pos2.x == 0) - { - pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos); - } - Vector3 pos4, pos6; - var horizontalLineCircleRadius = serieLabel.lineWidth * 4f; - var lineCircleDiff = horizontalLineCircleRadius - 0.3f; - if (currAngle < 90) - { - var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; - r4 += serieLabel.lineLength1 - lineCircleDiff; - pos6 = pos0 + Vector3.right * lineCircleDiff; - pos4 = pos6 + Vector3.right * r4; - } - else if (currAngle < 180) - { - var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; - r4 += serieLabel.lineLength1 - lineCircleDiff; - pos6 = pos0 + Vector3.right * lineCircleDiff; - pos4 = pos6 + Vector3.right * r4; - } - else if (currAngle < 270) - { - var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad); - var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad); - var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3; - r4 += serieLabel.lineLength1 - lineCircleDiff; - pos6 = pos0 + Vector3.left * lineCircleDiff; - pos4 = pos6 + Vector3.left * r4; - } - else - { - var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad); - var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad); - var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3; - r4 += serieLabel.lineLength1 - lineCircleDiff; - pos6 = pos0 + Vector3.left * lineCircleDiff; - pos4 = pos6 + Vector3.left * r4; - } - var pos5 = new Vector3(currAngle > 180 ? pos2.x - serieLabel.lineLength2 : pos2.x + serieLabel.lineLength2, pos2.y); - switch (serieLabel.lineType) - { - case SerieLabel.LineType.BrokenLine: - ChartDrawer.DrawLine(vh, pos1, pos2, pos5, serieLabel.lineWidth, color); - break; - case SerieLabel.LineType.Curves: - ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, m_Settings.lineSmoothness); - break; - case SerieLabel.LineType.HorizontalLine: - ChartDrawer.DrawCricle(vh, pos0, horizontalLineCircleRadius, color); - ChartDrawer.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color); - break; - } - } - } - - protected override void OnRefreshLabel() - { - int serieNameCount = -1; - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.list[i]; - serie.index = i; - if (!serie.show) continue; - var data = serie.data; - for (int n = 0; n < data.Count; n++) - { - var serieData = data[n]; - if (!serieData.canShowLabel || serie.IsIgnoreValue(serieData.GetData(1))) - { - serieData.SetLabelActive(false); - continue; - } - if (!serieData.show) continue; - serieNameCount = m_LegendRealShowName.IndexOf(serieData.name); - Color color = m_ThemeInfo.GetColor(serieNameCount); - DrawLabel(serie, n, serieData, color); - } - } - } - - private void DrawLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor) - { - if (serieData.labelObject == null) return; - var currAngle = serieData.runtimePieHalfAngle; - var isHighlight = (serieData.highlighted && serie.emphasis.label.show); - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); - var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel); - if (showLabel || serieData.iconStyle.show) - { - serieData.SetLabelActive(showLabel); - float rotate = 0; - bool isInsidePosition = serieLabel.position == SerieLabel.Position.Inside; - if (serieLabel.rotate > 0 && isInsidePosition) - { - if (currAngle > 180) rotate += 270 - currAngle; - else rotate += -(currAngle - 90); - } - Color color = serieColor; - if (isHighlight) - { - if (!ChartHelper.IsClearColor(serie.emphasis.label.color)) color = serie.emphasis.label.color; - } - else if (!ChartHelper.IsClearColor(serieLabel.color)) - { - color = serieLabel.color; - } - else - { - color = isInsidePosition ? Color.white : serieColor; - } - var fontSize = isHighlight ? serie.emphasis.label.fontSize : serieLabel.fontSize; - var fontStyle = isHighlight ? serie.emphasis.label.fontStyle : serieLabel.fontStyle; - - serieData.labelObject.label.color = color; - serieData.labelObject.label.fontSize = fontSize; - serieData.labelObject.label.fontStyle = fontStyle; - serieData.labelObject.SetLabelRotate(rotate); - if (!string.IsNullOrEmpty(serieLabel.formatter)) - { - var value = serieData.data[1]; - var total = serie.yTotal; - var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, serieLabel); - if (serieData.labelObject.SetText(content)) RefreshChart(); - } - else - { - if (serieData.labelObject.SetText(serieData.name)) RefreshChart(); - } - serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel)); - if (showLabel) serieData.labelObject.SetLabelPosition(serieLabel.offset); - else serieData.SetLabelActive(false); - } - else - { - serieData.SetLabelActive(false); - } - serieData.labelObject.UpdateIcon(serieData.iconStyle); - } - - protected override void OnLegendButtonClick(int index, string legendName, bool show) - { - LegendHelper.CheckDataShow(m_Series, legendName, show); - UpdateLegendColor(legendName, show); - RefreshChart(); - } - - protected override void OnLegendButtonEnter(int index, string legendName) - { - m_IsEnterLegendButtom = true; - LegendHelper.CheckDataHighlighted(m_Series, legendName, true); - RefreshChart(); - } - - protected override void OnLegendButtonExit(int index, string legendName) - { - m_IsEnterLegendButtom = false; - LegendHelper.CheckDataHighlighted(m_Series, legendName, false); - RefreshChart(); - } - - protected override void CheckTootipArea(Vector2 local) - { - if (m_IsEnterLegendButtom) return; - m_Tooltip.runtimeDataIndex.Clear(); - bool selected = false; - foreach (var serie in m_Series.list) - { - int index = GetPosPieIndex(serie, local); - m_Tooltip.runtimeDataIndex.Add(index); - if (serie.type != SerieType.Pie) continue; - bool refresh = false; - for (int j = 0; j < serie.data.Count; j++) - { - var serieData = serie.data[j]; - if (serieData.highlighted != (j == index)) refresh = true; - serieData.highlighted = j == index; - } - if (index >= 0) selected = true; - if (refresh) RefreshChart(); - } - if (selected) - { - m_Tooltip.UpdateContentPos(local + m_Tooltip.offset); - UpdateTooltip(); - } - else if (m_Tooltip.IsActive()) - { - m_Tooltip.SetActive(false); - RefreshChart(); - } - } - - private int GetPosPieIndex(Serie serie, Vector2 local) - { - if (serie.type != SerieType.Pie) return -1; - var dist = Vector2.Distance(local, serie.runtimeCenterPos); - if (dist < serie.runtimeInsideRadius || dist > serie.runtimeOutsideRadius) return -1; - Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y); - float angle = ChartHelper.GetAngle360(Vector2.up, dir); - for (int i = 0; i < serie.data.Count; i++) - { - var serieData = serie.data[i]; - if (angle >= serieData.runtimePieStartAngle && angle <= serieData.runtimePieToAngle) - { - return i; - } - } - return -1; - } - - protected override void UpdateTooltip() - { - base.UpdateTooltip(); - bool showTooltip = false; - foreach (var serie in m_Series.list) - { - int index = m_Tooltip.runtimeDataIndex[serie.index]; - if (index < 0) continue; - showTooltip = true; - var content = TooltipHelper.GetFormatterContent(m_Tooltip, index, m_Series, m_ThemeInfo); - TooltipHelper.SetContentAndPosition(tooltip, content, chartRect); - } - m_Tooltip.SetActive(showTooltip); - } - - public override void OnPointerDown(PointerEventData eventData) - { - base.OnPointerDown(eventData); - if (pointerPos == Vector2.zero) return; - var refresh = false; - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.GetSerie(i); - if (serie.type != SerieType.Pie) continue; - var index = GetPosPieIndex(serie, pointerPos); - if (index >= 0) - { - refresh = true; - for (int j = 0; j < serie.data.Count; j++) - { - if (j == index) serie.data[j].selected = !serie.data[j].selected; - else serie.data[j].selected = false; - } - if (m_OnPointerClickPie != null) - { - m_OnPointerClickPie(eventData, i, index); - } - } - } - if (refresh) RefreshChart(); - } } } diff --git a/Runtime/PolarChart.cs b/Runtime/PolarChart.cs index d9882b54..4836b06d 100644 --- a/Runtime/PolarChart.cs +++ b/Runtime/PolarChart.cs @@ -1,12 +1,14 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ +using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using XUGL; namespace XCharts { @@ -16,28 +18,33 @@ namespace XCharts [DisallowMultipleComponent] public partial class PolarChart : BaseChart { - [SerializeField] Polar m_Polar = Polar.defaultPolar; - [SerializeField] private RadiusAxis m_RadiusAxis = RadiusAxis.defaultRadiusAxis; - [SerializeField] private AngleAxis m_AngleAxis = AngleAxis.defaultAngleAxis; - - protected override void Awake() + public Polar GetPolar(int index) { - base.Awake(); - CheckMinMaxValue(); - UpdateRuntimeValue(); - InitRadiusAxis(m_RadiusAxis); - InitAngleAxis(m_AngleAxis); - m_Tooltip.UpdateToTop(); - m_Tooltip.runtimeAngle = -1; + if (index >= 0 && index < m_Polars.Count) return m_Polars[index]; + else return null; } + protected override void InitComponent() + { + base.InitComponent(); + CheckMinMaxValue(); + UpdateRuntimeValue(); + InitPolars(); + InitRadiusAxes(); + InitAngleAxes(); + tooltip.UpdateToTop(); + tooltip.runtimeAngle = -1; + } #if UNITY_EDITOR protected override void Reset() { base.Reset(); - m_Title.text = "PolarChart"; - m_Tooltip.type = Tooltip.Type.Corss; + m_Polars = new List<Polar>() { Polar.defaultPolar }; + m_RadiusAxes = new List<RadiusAxis>() { RadiusAxis.defaultRadiusAxis }; + m_AngleAxes = new List<AngleAxis>() { AngleAxis.defaultAngleAxis }; + title.text = "PolarChart"; + tooltip.type = Tooltip.Type.Corss; RemoveData(); ResetValuePolar(); Awake(); @@ -45,10 +52,10 @@ namespace XCharts private void ResetValuePolar() { - m_AngleAxis.type = Axis.AxisType.Value; - m_AngleAxis.minMaxType = Axis.AxisMinMaxType.Custom; - m_AngleAxis.min = 0; - m_AngleAxis.max = 360; + m_AngleAxes[0].type = Axis.AxisType.Value; + m_AngleAxes[0].minMaxType = Axis.AxisMinMaxType.Custom; + m_AngleAxes[0].min = 0; + m_AngleAxes[0].max = 360; AddSerie(SerieType.Line, "line1"); for (int i = 0; i <= 360; i++) { @@ -60,165 +67,188 @@ namespace XCharts private void ResetCategoryPolar() { - m_AngleAxis.type = Axis.AxisType.Category; + m_AngleAxes[0].type = Axis.AxisType.Category; AddSerie(SerieType.Bar, "line1"); for (int i = 0; i <= 13; i++) { - m_AngleAxis.AddData("bar" + i); + m_AngleAxes[0].AddData("bar" + i); AddData(0, Random.Range(0, 10)); } } - - protected override void OnValidate() - { - base.OnValidate(); - m_RadiusAxis.SetAllDirty(); - m_AngleAxis.SetAllDirty(); - CheckMinMaxValue(); - } #endif - protected override void CheckComponent() + protected override void SetAllComponentDirty() { - if (m_Polar.anyDirty) - { - if (m_Polar.componentDirty) - { - m_AngleAxis.SetComponentDirty(); - m_RadiusAxis.SetComponentDirty(); - } - if (m_Polar.vertsDirty) RefreshChart(); - m_Polar.ClearDirty(); - } - if (m_AngleAxis.anyDirty || m_RadiusAxis.anyDirty) - { - if (m_AngleAxis.componentDirty || m_RadiusAxis.componentDirty) - { - UpdateRuntimeValue(); - InitAngleAxis(m_AngleAxis); - InitRadiusAxis(m_RadiusAxis); - } - if (m_AngleAxis.vertsDirty || m_RadiusAxis.vertsDirty) RefreshChart(); - m_AngleAxis.ClearDirty(); - m_RadiusAxis.ClearDirty(); - } - base.CheckComponent(); + base.SetAllComponentDirty(); + foreach (var axis in m_RadiusAxes) axis.SetAllDirty(); + foreach (var axis in m_AngleAxes) axis.SetAllDirty(); + CheckMinMaxValue(); } protected override void OnSizeChanged() { base.OnSizeChanged(); - m_RadiusAxis.SetAllDirty(); - m_AngleAxis.SetAllDirty(); + foreach (var axis in m_RadiusAxes) axis.SetAllDirty(); + foreach (var axis in m_AngleAxes) axis.SetAllDirty(); UpdateRuntimeValue(); } + private void InitPolars() + { + for (int i = 0; i < m_Polars.Count; i++) + { + m_Polars[i].index = i; + } + } + + private void InitRadiusAxes() + { + for (int i = 0; i < m_RadiusAxes.Count; i++) + { + var radiusAxis = m_RadiusAxes[i]; + radiusAxis.index = i; + InitRadiusAxis(radiusAxis); + } + } + private void InitRadiusAxis(RadiusAxis axis) { + var m_Polar = GetPolar(axis.index); + if (m_Polars == null) return; + var m_AngleAxis = GetAngleAxis(m_Polar.index); + if (m_AngleAxis == null) return; PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); - var radius = m_Polar.runtimeRadius; axis.axisLabelTextList.Clear(); - string objName = "axis_radius"; - var axisObj = ChartHelper.AddObject(objName, transform, chartAnchorMin, - chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); + var radius = m_Polar.runtimeRadius; + var objName = "axis_radius" + axis.index; + var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, + graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.hideFlags = chartHideFlags; ChartHelper.HideAllObject(axisObj); - var labelColor = ChartHelper.IsClearColor(axis.axisLabel.color) ? - (Color)m_ThemeInfo.axisTextColor : - axis.axisLabel.color; - int splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); - float totalWidth = 0; + var textStyle = axis.axisLabel.textStyle; + var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); + var totalWidth = 0f; var startAngle = m_AngleAxis.runtimeStartAngle; var cenPos = m_Polar.runtimeCenterPos; - var txtHig = axis.axisLabel.fontSize + 2; + var txtHig = textStyle.GetFontSize(m_Theme.axis) + 2; var dire = ChartHelper.GetDire(startAngle, true).normalized; - var tickVetor = ChartHelper.GetVertialDire(dire) * (m_RadiusAxis.axisTick.length + m_RadiusAxis.axisLabel.margin); + var tickWidth = axis.axisTick.GetLength(m_Theme.radiusAxis.tickWidth); + var tickVetor = ChartHelper.GetVertialDire(dire) + * (tickWidth + axis.axisLabel.margin); for (int i = 0; i < splitNumber; i++) { float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null); bool inside = axis.axisLabel.inside; - Text txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, - m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), - new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), - axis.axisLabel.fontSize, axis.axisLabel.rotate, axis.axisLabel.fontStyle); + var txt = ChartHelper.AddTextObject(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), textStyle, + m_Theme.axis); if (i == 0) axis.axisLabel.SetRelatedText(txt, labelWidth); var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); - txt.text = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue, null, - isPercentStack); - txt.gameObject.SetActive(axis.show && + var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue, + null, isPercentStack); + txt.SetAlignment(TextAnchor.MiddleCenter); + txt.SetText(labelName); + txt.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor; - txt.transform.localPosition = pos; + txt.SetLocalPosition(pos); AxisHelper.AdjustRadiusAxisLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); axis.axisLabelTextList.Add(txt); totalWidth += labelWidth; } - if (m_Tooltip.runtimeGameObject) + if (tooltip.runtimeGameObject) { Vector2 privot = new Vector2(0.5f, 1); - var labelParent = m_Tooltip.runtimeGameObject.transform; - GameObject labelObj = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, m_ThemeInfo.font, privot); + var labelParent = tooltip.runtimeGameObject.transform; + var labelName = ChartCached.GetAxisTooltipLabel(objName); + GameObject labelObj = ChartHelper.AddTooltipLabel(labelName, labelParent, m_Theme, privot); axis.SetTooltipLabel(labelObj); - axis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor); - axis.SetTooltipLabelActive(axis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss); + axis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor); + axis.SetTooltipLabelActive(axis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); + } + } + + private AngleAxis GetAngleAxis(int polarIndex) + { + foreach (var axis in m_AngleAxes) + { + if (axis.polarIndex == polarIndex) return axis; + } + return null; + } + private RadiusAxis GetRadiusAxis(int polarIndex) + { + foreach (var axis in m_RadiusAxes) + { + if (axis.polarIndex == polarIndex) return axis; + } + return null; + } + + private void InitAngleAxes() + { + for (int i = 0; i < m_AngleAxes.Count; i++) + { + var angleAxis = m_AngleAxes[i]; + angleAxis.index = i; + InitAngleAxis(angleAxis); } } private void InitAngleAxis(AngleAxis axis) { + var m_Polar = GetPolar(axis.polarIndex); + if (m_Polars == null) return; PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); var radius = m_Polar.runtimeRadius; axis.axisLabelTextList.Clear(); - string objName = "axis_angle"; - var axisObj = ChartHelper.AddObject(objName, transform, chartAnchorMin, - chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); + string objName = "axis_angle" + axis.index; + var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, + graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.hideFlags = chartHideFlags; ChartHelper.HideAllObject(axisObj); - var labelColor = ChartHelper.IsClearColor(axis.axisLabel.color) ? - (Color)m_ThemeInfo.axisTextColor : - axis.axisLabel.color; - int splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); - float totalAngle = m_AngleAxis.runtimeStartAngle; + var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); + var totalAngle = axis.runtimeStartAngle; var total = 360; var cenPos = m_Polar.runtimeCenterPos; - var txtHig = m_AngleAxis.axisLabel.fontSize + 2; - var margin = m_AngleAxis.axisLabel.margin; - var isCategory = m_AngleAxis.IsCategory(); - for (int i = 0; i < splitNumber - 1; i++) + var txtHig = axis.axisLabel.textStyle.GetFontSize(m_Theme.axis) + 2; + var margin = axis.axisLabel.margin; + var isCategory = axis.IsCategory(); + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); + for (int i = 0; i < splitNumber; i++) { float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i, null); bool inside = axis.axisLabel.inside; - Text txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, - m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), + var txt = ChartHelper.AddTextObject(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.axisLabel.fontSize, axis.axisLabel.rotate, axis.axisLabel.fontStyle); - if (i == 0) axis.axisLabel.SetRelatedText(txt, scaleAngle); - var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); - txt.text = AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue, null, - isPercentStack); - txt.gameObject.SetActive(axis.show && - (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); - var pos = ChartHelper.GetPos(cenPos, radius + margin, isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true); + axis.axisLabel.textStyle, m_Theme.axis); + txt.SetAlignment(TextAnchor.MiddleCenter); + txt.SetText(AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue, + null, isPercentStack)); + txt.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); + var pos = ChartHelper.GetPos(cenPos, radius + margin, + isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true); AxisHelper.AdjustCircleLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); + if (i == 0) axis.axisLabel.SetRelatedText(txt, scaleAngle); axis.axisLabelTextList.Add(txt); totalAngle += scaleAngle; } - if (m_Tooltip.runtimeGameObject) + if (tooltip.runtimeGameObject) { Vector2 privot = new Vector2(0.5f, 0.5f); - var labelParent = m_Tooltip.runtimeGameObject.transform; + var labelParent = tooltip.runtimeGameObject.transform; GameObject labelObj = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, - m_ThemeInfo.font, privot, privot, privot, new Vector2(10, txtHig)); + m_Theme, privot, privot, privot, new Vector2(10, txtHig)); axis.SetTooltipLabel(labelObj); - axis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor); - axis.SetTooltipLabelActive(axis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss); + axis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor); + axis.SetTooltipLabelActive(axis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); } } @@ -230,26 +260,22 @@ namespace XCharts private void CheckMinMaxValue() { - if (m_RadiusAxis.IsCategory() && m_AngleAxis.IsCategory()) - { - return; - } - UpdateAxisMinMaxValue(0, m_RadiusAxis); - UpdateAxisMinMaxValue(0, m_AngleAxis); + foreach (var axis in m_RadiusAxes) UpdateAxisMinMaxValue(axis); + foreach (var axis in m_AngleAxes) UpdateAxisMinMaxValue(axis); } - private void UpdateAxisMinMaxValue(int axisIndex, Axis axis, bool updateChart = true) + private void UpdateAxisMinMaxValue(Axis axis, bool updateChart = true) { if (axis.IsCategory() || !axis.show) return; float tempMinValue = 0; float tempMaxValue = 0; if (axis is RadiusAxis) { - SeriesHelper.GetXMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetXMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true); } else { - SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetYMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true); } AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue) @@ -276,14 +302,15 @@ namespace XCharts protected void UpdateAxisLabelText(Axis axis) { - float m_CoordinateWidth = axis is RadiusAxis ? m_Polar.runtimeRadius : 360; + var polar = GetPolar(axis.polarIndex); + var runtimeWidth = axis is RadiusAxis ? polar.runtimeRadius : 360; var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); - axis.UpdateLabelText(m_CoordinateWidth, null, isPercentStack, 500); + axis.UpdateLabelText(runtimeWidth, null, isPercentStack, 500); } - protected override void DrawChart(VertexHelper vh) + protected override void DrawPainterBase(VertexHelper vh) { - base.DrawChart(vh); + base.DrawPainterBase(vh); DrawPolar(vh); DrawAngleAxis(vh); DrawRadiusAxis(vh); @@ -292,81 +319,103 @@ namespace XCharts private void UpdateRuntimeValue() { - PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); - m_AngleAxis.runtimeStartAngle = 90 - m_AngleAxis.startAngle; + foreach (var polar in m_Polars) + PolarHelper.UpdatePolarCenter(polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); + foreach (var axis in m_AngleAxes) + axis.runtimeStartAngle = 90 - axis.startAngle; } private void DrawPolar(VertexHelper vh) { UpdateRuntimeValue(); - if (!ChartHelper.IsClearColor(m_Polar.backgroundColor)) + foreach (var polar in m_Polars) { - ChartDrawer.DrawCricle(vh, m_Polar.runtimeCenterPos, m_Polar.runtimeRadius, m_Polar.backgroundColor); + if (!ChartHelper.IsClearColor(polar.backgroundColor)) + { + UGL.DrawCricle(vh, polar.runtimeCenterPos, polar.runtimeRadius, polar.backgroundColor); + } } } private void DrawRadiusAxis(VertexHelper vh) { - var startAngle = m_AngleAxis.runtimeStartAngle; - var radius = m_Polar.runtimeRadius; - var cenPos = m_Polar.runtimeCenterPos; - var size = AxisHelper.GetScaleNumber(m_RadiusAxis, radius, null); - var totalWidth = 0f; - var dire = ChartHelper.GetDire(startAngle, true).normalized; - var tickVetor = ChartHelper.GetVertialDire(dire) * m_RadiusAxis.axisTick.length; - var tickWidth = AxisHelper.GetTickWidth(m_RadiusAxis); - for (int i = 0; i < size; i++) + foreach (var radiusAxis in m_RadiusAxes) { - var scaleWidth = AxisHelper.GetScaleWidth(m_RadiusAxis, radius, i); - var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true); - if (m_RadiusAxis.show && m_RadiusAxis.splitLine.show) + var polar = GetPolar(radiusAxis.polarIndex); + if (polar == null) continue; + var angleAxis = GetAngleAxis(polar.index); + if (angleAxis == null) continue; + var startAngle = angleAxis.runtimeStartAngle; + var radius = polar.runtimeRadius; + var cenPos = polar.runtimeCenterPos; + var size = AxisHelper.GetScaleNumber(radiusAxis, radius, null); + var totalWidth = 0f; + var dire = ChartHelper.GetDire(startAngle, true).normalized; + var tickWidth = radiusAxis.axisTick.GetLength(m_Theme.radiusAxis.tickWidth); + var tickLength = radiusAxis.axisTick.GetLength(m_Theme.radiusAxis.tickLength); + var tickVetor = ChartHelper.GetVertialDire(dire) * tickLength; + for (int i = 0; i < size - 1; i++) { - var outsideRaidus = totalWidth + m_RadiusAxis.splitLine.lineStyle.width * 2; - var splitLineColor = m_RadiusAxis.splitLine.GetColor(m_ThemeInfo); - ChartDrawer.DrawDoughnut(vh, cenPos, totalWidth, outsideRaidus, splitLineColor, Color.clear); + var scaleWidth = AxisHelper.GetScaleWidth(radiusAxis, radius, i); + var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true); + if (radiusAxis.show && radiusAxis.splitLine.show) + { + var outsideRaidus = totalWidth + radiusAxis.splitLine.GetWidth(m_Theme.radiusAxis.splitLineWidth) * 2; + var splitLineColor = radiusAxis.splitLine.GetColor(m_Theme.radiusAxis.splitLineColor); + UGL.DrawDoughnut(vh, cenPos, totalWidth, outsideRaidus, splitLineColor, Color.clear); + } + if (radiusAxis.show && radiusAxis.axisTick.show) + { + UGL.DrawLine(vh, pos, pos + tickVetor, tickWidth, m_Theme.axis.lineColor); + } + totalWidth += scaleWidth; } - if (m_RadiusAxis.show && m_RadiusAxis.axisTick.show) + if (radiusAxis.show && radiusAxis.axisLine.show) { - ChartDrawer.DrawLine(vh, pos, pos + tickVetor, tickWidth, m_ThemeInfo.axisLineColor); + var lineStartPos = polar.runtimeCenterPos - dire * tickWidth; + var lineEndPos = polar.runtimeCenterPos + dire * (radius + tickWidth); + var lineWidth = radiusAxis.axisLine.GetWidth(m_Theme.polar.lineWidth); + UGL.DrawLine(vh, lineStartPos, lineEndPos, lineWidth, m_Theme.axis.lineColor); } - totalWidth += scaleWidth; - } - if (m_RadiusAxis.show && m_RadiusAxis.axisLine.show) - { - var lineStartPos = m_Polar.runtimeCenterPos - dire * m_RadiusAxis.axisTick.width; - var lineEndPos = m_Polar.runtimeCenterPos + dire * (radius + m_RadiusAxis.axisTick.width); - ChartDrawer.DrawLine(vh, lineStartPos, lineEndPos, m_RadiusAxis.axisLine.width, m_ThemeInfo.axisLineColor); } } private void DrawAngleAxis(VertexHelper vh) { - var radius = m_Polar.runtimeRadius; - var cenPos = m_Polar.runtimeCenterPos; - var total = 360; - var size = AxisHelper.GetScaleNumber(m_AngleAxis, total, null); - var currAngle = m_AngleAxis.runtimeStartAngle; - var tickWidth = AxisHelper.GetTickWidth(m_AngleAxis); - for (int i = 0; i < size; i++) + foreach (var m_AngleAxis in m_AngleAxes) { - var scaleWidth = AxisHelper.GetScaleWidth(m_AngleAxis, total, i); - var pos = ChartHelper.GetPos(cenPos, radius, currAngle, true); - if (m_AngleAxis.show && m_AngleAxis.splitLine.show) + var m_Polar = GetPolar(m_AngleAxis.polarIndex); + var radius = m_Polar.runtimeRadius; + var cenPos = m_Polar.runtimeCenterPos; + var total = 360; + var size = AxisHelper.GetScaleNumber(m_AngleAxis, total, null); + var currAngle = m_AngleAxis.runtimeStartAngle; + var tickWidth = m_AngleAxis.axisTick.GetWidth(m_Theme.angleAxis.tickWidth); + var tickLength = m_AngleAxis.axisTick.GetLength(m_Theme.angleAxis.tickLength); + for (int i = 0; i < size; i++) { - var splitLineColor = m_AngleAxis.splitLine.GetColor(m_ThemeInfo); - ChartDrawer.DrawLine(vh, cenPos, pos, m_AngleAxis.splitLine.lineStyle.width, splitLineColor); + var scaleWidth = AxisHelper.GetScaleWidth(m_AngleAxis, total, i); + var pos = ChartHelper.GetPos(cenPos, radius, currAngle, true); + if (m_AngleAxis.show && m_AngleAxis.splitLine.show) + { + var splitLineColor = m_AngleAxis.splitLine.GetColor(m_Theme.angleAxis.splitLineColor); + var lineWidth = m_AngleAxis.splitLine.GetWidth(m_Theme.angleAxis.splitLineWidth); + UGL.DrawLine(vh, cenPos, pos, lineWidth, splitLineColor); + } + if (m_AngleAxis.show && m_AngleAxis.axisTick.show) + { + var tickY = radius + tickLength; + var tickPos = ChartHelper.GetPos(cenPos, tickY, currAngle, true); + UGL.DrawLine(vh, pos, tickPos, tickWidth, m_Theme.axis.lineColor); + } + currAngle += scaleWidth; } - if (m_AngleAxis.show && m_AngleAxis.axisTick.show) + if (m_AngleAxis.show && m_AngleAxis.axisLine.show) { - var tickPos = ChartHelper.GetPos(cenPos, radius + m_AngleAxis.axisTick.length, currAngle, true); - ChartDrawer.DrawLine(vh, pos, tickPos, tickWidth, m_ThemeInfo.axisLineColor); + var lineWidth = m_AngleAxis.axisLine.GetWidth(m_Theme.angleAxis.lineWidth); + var outsideRaidus = radius + lineWidth * 2; + UGL.DrawDoughnut(vh, cenPos, radius, outsideRaidus, m_Theme.axis.lineColor, Color.clear); } - currAngle += scaleWidth; - } - if (m_AngleAxis.show && m_AngleAxis.axisLine.show) - { - var outsideRaidus = radius + m_AngleAxis.axisLine.width * 2; - ChartDrawer.DrawDoughnut(vh, cenPos, radius, outsideRaidus, m_ThemeInfo.axisLineColor, Color.clear); } } @@ -391,11 +440,15 @@ namespace XCharts } DrawPolarLineSymbol(vh); - } private void DrawPolarLine(VertexHelper vh, Serie serie) { + var m_Polar = GetPolar(serie.polarIndex); + if (m_Polar == null) return; + var m_AngleAxis = GetAngleAxis(m_Polar.index); + var m_RadiusAxis = GetRadiusAxis(m_Polar.index); + if (m_AngleAxis == null || m_RadiusAxis == null) return; var startAngle = m_AngleAxis.runtimeStartAngle; var radius = m_Polar.runtimeRadius; var datas = serie.data; @@ -403,12 +456,11 @@ namespace XCharts float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); float min = m_RadiusAxis.GetCurrMinValue(dataChangeDuration); float max = m_RadiusAxis.GetCurrMaxValue(dataChangeDuration); - var firstSerieData = datas[0]; - var startPos = GetPolarPos(firstSerieData, min, max, radius); + var startPos = GetPolarPos(m_Polar, m_AngleAxis, firstSerieData, min, max, radius); var nextPos = Vector3.zero; - var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, serie.index, serie.highlighted); - var lineWidth = serie.lineStyle.width; + var lineColor = SerieHelper.GetLineColor(serie, m_Theme, serie.index, serie.highlighted); + var lineWidth = serie.lineStyle.GetWidth(m_Theme.serie.lineWidth); float currDetailProgress = 0; float totalDetailProgress = datas.Count; serie.animation.InitProgress(serie.dataPoints.Count, currDetailProgress, totalDetailProgress); @@ -417,14 +469,14 @@ namespace XCharts { if (serie.animation.CheckDetailBreak(i)) break; var serieData = datas[i]; - nextPos = GetPolarPos(datas[i], min, max, radius); - ChartDrawer.DrawLine(vh, startPos, nextPos, lineWidth, lineColor); + nextPos = GetPolarPos(m_Polar, m_AngleAxis, datas[i], min, max, radius); + UGL.DrawLine(vh, startPos, nextPos, lineWidth, lineColor); startPos = nextPos; } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(totalDetailProgress); - serie.animation.CheckSymbol(serie.symbol.size); + serie.animation.CheckSymbol(serie.symbol.GetSize(null, m_Theme.serie.lineSymbolSize)); m_IsPlayingAnimation = true; RefreshChart(); } @@ -432,7 +484,6 @@ namespace XCharts private void DrawPolarBar(VertexHelper vh, Serie serie) { - } private void DrawPolarLineSymbol(VertexHelper vh) @@ -450,10 +501,12 @@ namespace XCharts if (ChartHelper.IsIngore(serieData.runtimePosition)) continue; bool highlight = serieData.highlighted || serie.highlighted; if ((!symbol.show || !symbol.ShowSymbol(i, count) || serie.IsPerformanceMode()) && !serieData.highlighted) continue; - float symbolSize = highlight ? symbol.selectedSize : symbol.size; - var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, n, highlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, n, highlight); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight); + float symbolSize = highlight + ? symbol.GetSelectedSize(serieData.data, m_Theme.serie.lineSymbolSize) + : symbol.GetSize(serieData.data, m_Theme.serie.lineSymbolSize); + var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, n, highlight); + var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, n, highlight); + var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight); var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight); symbolSize = serie.animation.GetSysmbolSize(symbolSize); DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serieData.runtimePosition, symbolColor, @@ -464,33 +517,37 @@ namespace XCharts protected override void DrawTooltip(VertexHelper vh) { - if (m_Tooltip.runtimeAngle < 0) return; - var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo); + if (tooltip.runtimeAngle < 0) return; + var m_Polar = GetPolar(tooltip.runtimePolarIndex); + var m_AngleAxis = GetAngleAxis(m_Polar.index); + var lineColor = TooltipHelper.GetLineColor(tooltip, m_Theme); + var lineType = tooltip.lineStyle.GetType(m_Theme.tooltip.lineType); + var lineWidth = tooltip.lineStyle.GetWidth(m_Theme.tooltip.lineWidth); var cenPos = m_Polar.runtimeCenterPos; var radius = m_Polar.runtimeRadius; var sp = m_Polar.runtimeCenterPos; - var tooltipAngle = m_Tooltip.runtimeAngle + m_AngleAxis.runtimeStartAngle; + var tooltipAngle = tooltip.runtimeAngle + m_AngleAxis.runtimeStartAngle; var ep = ChartHelper.GetPos(sp, radius, tooltipAngle, true); - switch (m_Tooltip.type) + switch (tooltip.type) { case Tooltip.Type.Corss: - ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor); var dist = Vector2.Distance(pointerPos, cenPos); if (dist > radius) dist = radius; - var outsideRaidus = dist + m_Tooltip.lineStyle.width * 2; - ChartDrawer.DrawDoughnut(vh, cenPos, dist, outsideRaidus, lineColor, Color.clear); + var outsideRaidus = dist + tooltip.lineStyle.GetWidth(m_Theme.tooltip.lineWidth) * 2; + UGL.DrawDoughnut(vh, cenPos, dist, outsideRaidus, lineColor, Color.clear); break; case Tooltip.Type.Line: - ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor); break; case Tooltip.Type.Shadow: - ChartDrawer.DrawSector(vh, cenPos, radius, lineColor, tooltipAngle - 2, tooltipAngle + 2, m_Settings.cicleSmoothness); + UGL.DrawSector(vh, cenPos, radius, lineColor, tooltipAngle - 2, tooltipAngle + 2, settings.cicleSmoothness); break; } } - private Vector3 GetPolarPos(SerieData serieData, float min, float max, float polarRadius) + private Vector3 GetPolarPos(Polar m_Polar, AngleAxis m_AngleAxis, SerieData serieData, float min, float max, float polarRadius) { var angle = 0f; if (!m_AngleAxis.clockwise) @@ -509,15 +566,16 @@ namespace XCharts return serieData.runtimePosition; } - protected override void CheckTootipArea(Vector2 local) + protected override void CheckTootipArea(Vector2 local, bool isActivedOther) { - var dist = Vector2.Distance(local, m_Polar.runtimeCenterPos); - if (dist > m_Polar.runtimeRadius) + if (isActivedOther) return; + tooltip.runtimePolarIndex = GetPointerInPoloar(local); + if (tooltip.runtimePolarIndex < 0) { - m_Tooltip.runtimeAngle = -1; - if (m_Tooltip.IsActive()) + tooltip.runtimeAngle = -1; + if (tooltip.IsActive()) { - foreach (var kv in m_Tooltip.runtimeSerieIndex) + foreach (var kv in tooltip.runtimeSerieIndex) { var serie = m_Series.GetSerie(kv.Key); foreach (var dataIndex in kv.Value) @@ -525,15 +583,17 @@ namespace XCharts serie.GetSerieData(dataIndex).highlighted = false; } } - m_Tooltip.ClearSerieDataIndex(); - m_Tooltip.SetActive(false); - m_AngleAxis.SetTooltipLabelActive(false); - m_RadiusAxis.SetTooltipLabelActive(false); + tooltip.ClearSerieDataIndex(); + tooltip.SetActive(false); + foreach (var axis in m_AngleAxes) axis.SetTooltipLabelActive(false); + foreach (var axis in m_RadiusAxes) axis.SetTooltipLabelActive(false); RefreshChart(); } return; } - m_Tooltip.ClearSerieDataIndex(); + var m_Polar = GetPolar(tooltip.runtimePolarIndex); + var m_AngleAxis = GetAngleAxis(m_Polar.index); + tooltip.ClearSerieDataIndex(); Vector2 dir = local - new Vector2(m_Polar.runtimeCenterPos.x, m_Polar.runtimeCenterPos.y); float angle = ChartHelper.GetAngle360(Vector2.up, dir); @@ -557,8 +617,8 @@ namespace XCharts serieData.highlighted = flag; if (flag) { - m_Tooltip.runtimeAngle = (serieData.runtimeAngle - m_AngleAxis.runtimeStartAngle + 360) % 360; - m_Tooltip.AddSerieDataIndex(serie.index, j); + tooltip.runtimeAngle = (serieData.runtimeAngle - m_AngleAxis.runtimeStartAngle + 360) % 360; + tooltip.AddSerieDataIndex(serie.index, j); } } if (refresh) RefreshChart(); @@ -570,14 +630,29 @@ namespace XCharts break; } } - m_Tooltip.UpdateContentPos(local + m_Tooltip.offset); + tooltip.UpdateContentPos(local + tooltip.offset); UpdateTooltip(); - if (m_Tooltip.type == Tooltip.Type.Corss) + if (tooltip.type == Tooltip.Type.Corss) { RefreshChart(); } } + private int GetPointerInPoloar(Vector2 local) + { + for (int i = 0; i < m_Polars.Count; i++) + { + var polar = m_Polars[i]; + polar.index = i; + var dist = Vector2.Distance(local, polar.runtimeCenterPos); + if (dist <= polar.runtimeRadius) + { + return polar.index; + } + } + return -1; + } + private float GetAngleDiff(SerieData nextData, SerieData serieData, float angle) { var nextAngle = nextData.runtimeAngle; @@ -597,25 +672,30 @@ namespace XCharts protected override void UpdateTooltip() { base.UpdateTooltip(); - var showTooltip = m_Tooltip.isAnySerieDataIndex(); + var showTooltip = tooltip.isAnySerieDataIndex(); if (showTooltip) { - var content = TooltipHelper.GetPolarFormatterContent(m_Tooltip, m_Series, m_ThemeInfo, m_AngleAxis); + var m_AngleAxis = GetAngleAxis(tooltip.runtimePolarIndex); + var content = TooltipHelper.GetPolarFormatterContent(tooltip, m_Series, m_Theme, m_AngleAxis); TooltipHelper.SetContentAndPosition(tooltip, content, chartRect); UdpateTooltipLabel(); } - m_Tooltip.SetActive(showTooltip); + tooltip.SetActive(showTooltip); } private void UdpateTooltipLabel() { - if (m_Tooltip.type != Tooltip.Type.Corss) return; + if (tooltip.type != Tooltip.Type.Corss) return; + var m_Polar = GetPolar(tooltip.runtimePolarIndex); + if (m_Polar == null) return; + var m_AngleAxis = GetAngleAxis(m_Polar.index); + var m_RadiusAxis = GetRadiusAxis(m_Polar.index); var cenPos = m_Polar.runtimeCenterPos; var radius = m_Polar.runtimeRadius; m_AngleAxis.SetTooltipLabelActive(true); m_RadiusAxis.SetTooltipLabelActive(true); - m_AngleAxis.UpdateTooptipLabelText(ChartCached.FloatToStr(m_Tooltip.runtimeAngle)); - var tooltipAngle = m_Tooltip.runtimeAngle + m_AngleAxis.runtimeStartAngle; + m_AngleAxis.UpdateTooptipLabelText(ChartCached.FloatToStr(tooltip.runtimeAngle)); + var tooltipAngle = tooltip.runtimeAngle + m_AngleAxis.runtimeStartAngle; var ep = ChartHelper.GetPos(cenPos, radius + 5, tooltipAngle, true); m_AngleAxis.UpdateTooltipLabelPos(ep); diff --git a/Runtime/RadarChart.cs b/Runtime/RadarChart.cs index 5c802436..ff063a9d 100644 --- a/Runtime/RadarChart.cs +++ b/Runtime/RadarChart.cs @@ -1,15 +1,11 @@ -using System.Linq; -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System.Collections.Generic; -using System.Text; using UnityEngine; -using UnityEngine.UI; namespace XCharts { @@ -17,763 +13,17 @@ namespace XCharts [ExecuteInEditMode] [RequireComponent(typeof(RectTransform))] [DisallowMultipleComponent] - public partial class RadarChart : BaseChart + public class RadarChart : BaseChart { - private const string INDICATOR_TEXT = "indicator"; - [SerializeField] private List<Radar> m_Radars = new List<Radar>(); - private bool m_IsEnterLegendButtom; - private bool m_RadarsDirty; - - protected override void OnLegendButtonClick(int index, string legendName, bool show) - { - LegendHelper.CheckDataShow(m_Series, legendName, show); - UpdateLegendColor(legendName, show); - RefreshChart(); - } - - protected override void OnLegendButtonEnter(int index, string legendName) - { - m_IsEnterLegendButtom = true; - LegendHelper.CheckDataHighlighted(m_Series, legendName, true); - RefreshChart(); - } - - protected override void OnLegendButtonExit(int index, string legendName) - { - m_IsEnterLegendButtom = false; - LegendHelper.CheckDataHighlighted(m_Series, legendName, false); - RefreshChart(); - } - - protected override void Awake() - { - base.Awake(); - InitIndicator(); - } - - protected override void Update() - { - base.Update(); - } - - protected override void CheckComponent() - { - var anyDirty = IsAnyRadarDirty(); - if (m_RadarsDirty || anyDirty) - { - InitIndicator(); - OnRadarChanged(); - RefreshChart(); - m_Tooltip.UpdateToTop(); - if (anyDirty) - { - foreach (var radar in m_Radars) - { - radar.ClearDirty(); - } - } - m_RadarsDirty = false; - } - base.CheckComponent(); - } - #if UNITY_EDITOR protected override void Reset() { base.Reset(); RemoveData(); m_Radars.Add(Radar.defaultRadar); - m_Title.text = "RadarChart"; - var serie = AddSerie(SerieType.Radar, "serie1"); - serie.symbol.show = true; - serie.symbol.type = SerieSymbolType.EmptyCircle; - serie.symbol.size = 4; - serie.symbol.selectedSize = 6; - serie.showDataName = true; - List<float> data = new List<float>(); - for (int i = 0; i < 5; i++) - { - data.Add(Random.Range(20, 90)); - } - AddData(0, data, "legendName"); - } - - protected override void OnValidate() - { - base.OnValidate(); - m_RadarsDirty = true; + title.text = "RadarChart"; + SerieTemplate.AddDefaultRadarSerie(this, "serie1"); } #endif - - protected override void OnSizeChanged() - { - base.OnSizeChanged(); - m_RadarsDirty = true; - } - - private void InitIndicator() - { - ChartHelper.HideAllObject(transform, INDICATOR_TEXT); - for (int n = 0; n < m_Radars.Count; n++) - { - Radar radar = m_Radars[n]; - radar.UpdateRadarCenter(chartPosition, chartWidth, chartHeight); - int indicatorNum = radar.indicatorList.Count; - float txtWid = 100; - float txtHig = 20; - for (int i = 0; i < indicatorNum; i++) - { - var indicator = radar.indicatorList[i]; - var pos = radar.GetIndicatorPosition(i); - TextAnchor anchor = TextAnchor.MiddleCenter; - var textStyle = indicator.textStyle; - var textColor = ChartHelper.IsClearColor(textStyle.color) ? (Color)m_ThemeInfo.axisTextColor : textStyle.color; - var txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font, - textColor, anchor, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), - new Vector2(txtWid, txtHig), textStyle.fontSize, textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing); - txt.gameObject.hideFlags = chartHideFlags; - txt.text = radar.indicatorList[i].name; - txt.gameObject.SetActive(radar.indicator); - var offset = new Vector3(textStyle.offset.x, textStyle.offset.y); - AxisHelper.AdjustCircleLabelPos(txt, pos, radar.runtimeCenterPos, txtHig, offset); - } - } - } - - private bool IsAnyRadarDirty() - { - foreach (var radar in m_Radars) - { - if (radar.anyDirty) return true; - } - return false; - } - - protected virtual void OnRadarChanged() - { - } - - protected override void DrawChart(VertexHelper vh) - { - base.DrawChart(vh); - for (int i = 0; i < m_Radars.Count; i++) - { - var radar = m_Radars[i]; - radar.index = i; - radar.UpdateRadarCenter(chartPosition, chartWidth, chartHeight); - if (radar.shape == Radar.Shape.Circle) - { - DrawCricleRadar(vh, radar); - } - else - { - DrawRadar(vh, radar); - } - } - DrawData(vh); - } - - protected override void OnThemeChanged() - { - base.OnThemeChanged(); - foreach (var radar in m_Radars) - { - radar.splitArea.color.Clear(); - switch (m_ThemeInfo.theme) - { - case Theme.Dark: - radar.splitArea.color.Add(ThemeInfo.GetColor("#6f6f6f")); - radar.splitArea.color.Add(ThemeInfo.GetColor("#606060")); - break; - case Theme.Default: - radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6")); - radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7")); - break; - case Theme.Light: - radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6")); - radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7")); - break; - } - } - m_RadarsDirty = true; - } - - Dictionary<string, int> serieNameSet = new Dictionary<string, int>(); - private void DrawData(VertexHelper vh) - { - serieNameSet.Clear(); - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.list[i]; - serie.index = i; - switch (serie.radarType) - { - case RadarType.Multiple: - DrawMutipleRadar(vh, serie, i); - break; - case RadarType.Single: - DrawSingleRadar(vh, serie, i); - break; - } - } - } - - private void DrawMutipleRadar(VertexHelper vh, Serie serie, int i) - { - var startPoint = Vector3.zero; - var toPoint = Vector3.zero; - var firstPoint = Vector3.zero; - - var radar = m_Radars[serie.radarIndex]; - var indicatorNum = radar.indicatorList.Count; - var angle = 2 * Mathf.PI / indicatorNum; - var centerPos = radar.runtimeCenterPos; - var serieNameCount = -1; - serie.animation.InitProgress(1, 0, 1); - if (!IsActive(i) || serie.animation.HasFadeOut()) - { - return; - } - var rate = serie.animation.GetCurrRate(); - var dataChanging = false; - var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - SerieHelper.GetAllMinMaxData(serie, radar.ceilRate); - for (int j = 0; j < serie.data.Count; j++) - { - var serieData = serie.data[j]; - int key = i * 1000 + j; - if (!radar.runtimeDataPosList.ContainsKey(key)) - { - radar.runtimeDataPosList.Add(i * 1000 + j, new List<Vector3>(serieData.data.Count)); - } - else - { - radar.runtimeDataPosList[key].Clear(); - } - string dataName = serieData.name; - int serieIndex = 0; - if (string.IsNullOrEmpty(dataName)) - { - serieNameCount++; - serieIndex = serieNameCount; - } - else if (!serieNameSet.ContainsKey(dataName)) - { - serieNameSet.Add(dataName, serieNameCount); - serieNameCount++; - serieIndex = serieNameCount; - } - else - { - serieIndex = serieNameSet[dataName]; - } - if (!serieData.show) - { - continue; - } - var isHighlight = IsHighlight(radar, serie, serieData, j, 0); - var areaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, serieIndex, isHighlight); - var areaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, serieIndex, isHighlight); - var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, serieIndex, isHighlight); - int dataCount = radar.indicatorList.Count; - List<Vector3> pointList = radar.runtimeDataPosList[key]; - for (int n = 0; n < dataCount; n++) - { - if (n >= serieData.data.Count) break; - float max = radar.GetIndicatorMax(n); - float value = serieData.GetCurrData(n, dataChangeDuration); - if (serieData.IsDataChanged()) dataChanging = true; - if (max == 0) - { - max = serie.runtimeDataMax; - } - var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max - : radar.runtimeDataRadius * value / max; - var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle; - radius *= rate; - if (n == 0) - { - startPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle), - centerPos.y + radius * Mathf.Cos(currAngle)); - firstPoint = startPoint; - } - else - { - toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle), - centerPos.y + radius * Mathf.Cos(currAngle)); - if (serie.areaStyle.show) - { - ChartDrawer.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor); - } - if (serie.lineStyle.show) - { - ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor); - } - startPoint = toPoint; - } - pointList.Add(startPoint); - } - if (serie.areaStyle.show) - { - ChartDrawer.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); - } - if (serie.lineStyle.show) - { - ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor); - } - if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None) - { - for (int m = 0; m < pointList.Count; m++) - { - var point = pointList[m]; - isHighlight = IsHighlight(radar, serie, serieData, j, m); - var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size); - var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); - DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor, - symbolToColor, serie.symbol.gap, cornerRadius); - } - } - } - if (!serie.animation.IsFinish()) - { - serie.animation.CheckProgress(1); - RefreshChart(); - } - if (dataChanging) - { - RefreshChart(); - } - } - - private bool IsHighlight(Radar radar, Serie serie, SerieData serieData, int dataIndex, int dimension) - { - if (serie.highlighted || serieData.highlighted) return true; - if (!m_Tooltip.show) return false; - var selectedSerieIndex = m_Tooltip.runtimeDataIndex[0]; - if (selectedSerieIndex < 0) return false; - if (m_Series.GetSerie(selectedSerieIndex).radarIndex != serie.radarIndex) return false; - switch (serie.radarType) - { - case RadarType.Multiple: - if (radar.isAxisTooltip) - { - var selectedDimension = tooltip.runtimeDataIndex[2]; - return selectedDimension == dimension; - } - else - { - return m_Tooltip.runtimeDataIndex[0] == serie.index && m_Tooltip.runtimeDataIndex[1] == dataIndex; - } - case RadarType.Single: - return m_Tooltip.runtimeDataIndex[1] == dataIndex; - } - return false; - } - - private void DrawSingleRadar(VertexHelper vh, Serie serie, int i) - { - var startPoint = Vector3.zero; - var toPoint = Vector3.zero; - var firstPoint = Vector3.zero; - - var radar = m_Radars[serie.radarIndex]; - var indicatorNum = radar.indicatorList.Count; - var angle = 2 * Mathf.PI / indicatorNum; - var centerPos = radar.runtimeCenterPos; - var serieNameCount = -1; - serie.animation.InitProgress(1, 0, 1); - if (!IsActive(i) || serie.animation.HasFadeOut()) - { - return; - } - var rate = serie.animation.GetCurrRate(); - var dataChanging = false; - var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - int key = i * 1000; - if (!radar.runtimeDataPosList.ContainsKey(key)) - { - radar.runtimeDataPosList.Add(i * 1000, new List<Vector3>(serie.dataCount)); - } - else - { - radar.runtimeDataPosList[key].Clear(); - } - var pointList = radar.runtimeDataPosList[key]; - var startIndex = GetStartShowIndex(serie); - var endIndex = GetEndShowIndex(serie); - SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate); - for (int j = 0; j < serie.data.Count; j++) - { - var serieData = serie.data[j]; - serieData.index = j; - string dataName = serieData.name; - int serieIndex = 0; - if (string.IsNullOrEmpty(dataName)) - { - serieNameCount++; - serieIndex = serieNameCount; - } - else if (!serieNameSet.ContainsKey(dataName)) - { - serieNameSet.Add(dataName, serieNameCount); - serieNameCount++; - serieIndex = serieNameCount; - } - else - { - serieIndex = serieNameSet[dataName]; - } - if (!serieData.show) - { - serieData.labelPosition = Vector3.zero; - continue; - } - var isHighlight = IsHighlight(radar, serie, serieData, j, 0); - var areaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, serieIndex, isHighlight); - var areaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, serieIndex, isHighlight); - var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, serieIndex, isHighlight); - int dataCount = radar.indicatorList.Count; - var index = serieData.index; - var p = radar.runtimeCenterPos; - var max = radar.GetIndicatorMax(index); - var value = serieData.GetCurrData(1, dataChangeDuration); - if (serieData.IsDataChanged()) dataChanging = true; - if (max == 0) - { - max = serie.runtimeDataMax; - } - var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max - : radar.runtimeDataRadius * value / max; - var currAngle = (index + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle; - radius *= rate; - if (index == startIndex) - { - startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), - p.y + radius * Mathf.Cos(currAngle)); - firstPoint = startPoint; - } - else - { - toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), - p.y + radius * Mathf.Cos(currAngle)); - if (serie.areaStyle.show) - { - ChartDrawer.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor); - } - if (serie.lineStyle.show) - { - ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor); - } - startPoint = toPoint; - } - serieData.labelPosition = startPoint; - pointList.Add(startPoint); - - if (serie.areaStyle.show && j == endIndex) - { - ChartDrawer.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor); - } - if (serie.lineStyle.show && j == endIndex) - { - ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor); - } - } - if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None) - { - for (int j = 0; j < serie.data.Count; j++) - { - var serieData = serie.data[j]; - if (!serieData.show) continue; - var isHighlight = serie.highlighted || serieData.highlighted || - (m_Tooltip.show && m_Tooltip.runtimeDataIndex[0] == i && m_Tooltip.runtimeDataIndex[1] == j); - var serieIndex = serieData.index; - var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size); - var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); - DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.labelPosition, symbolColor, - symbolToColor, serie.symbol.gap, cornerRadius); - } - } - if (!serie.animation.IsFinish()) - { - serie.animation.CheckProgress(1); - RefreshChart(); - } - if (dataChanging) - { - RefreshChart(); - } - } - - private int GetStartShowIndex(Serie serie) - { - for (int i = 0; i < serie.dataCount; i++) - { - if (serie.data[i].show) return i; - } - return 0; - } - private int GetEndShowIndex(Serie serie) - { - for (int i = serie.dataCount - 1; i >= 0; i--) - { - if (serie.data[i].show) return i; - } - return 0; - } - - private void DrawRadarSymbol(VertexHelper vh, Serie serie, SerieData serieData, int serieIndex, bool isHighlight, - List<Vector3> pointList) - { - if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None) - { - var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size); - var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight); - var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight); - var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight); - var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight); - foreach (var point in pointList) - { - DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor, - symbolToColor, serie.symbol.gap, cornerRadius); - } - } - } - - private void DrawRadar(VertexHelper vh, Radar radar) - { - if (!radar.splitLine.show && !radar.splitArea.show) - { - return; - } - float insideRadius = 0, outsideRadius = 0; - float block = radar.runtimeRadius / radar.splitNumber; - int indicatorNum = radar.indicatorList.Count; - Vector3 p1, p2, p3, p4; - Vector3 p = radar.runtimeCenterPos; - float angle = 2 * Mathf.PI / indicatorNum; - var lineColor = GetLineColor(radar); - for (int i = 0; i < radar.splitNumber; i++) - { - Color color = radar.splitArea.color[i % radar.splitArea.color.Count]; - outsideRadius = insideRadius + block; - p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0)); - p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0)); - for (int j = 0; j <= indicatorNum; j++) - { - float currAngle = j * angle; - p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), - p.y + outsideRadius * Mathf.Cos(currAngle)); - p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle), - p.y + insideRadius * Mathf.Cos(currAngle)); - if (radar.splitArea.show) - { - ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color); - } - if (radar.splitLine.NeedShow(i)) - { - ChartDrawer.DrawLineStyle(vh, radar.splitLine.lineStyle, p2, p3, lineColor); - } - p1 = p4; - p2 = p3; - } - insideRadius = outsideRadius; - } - for (int j = 0; j <= indicatorNum; j++) - { - float currAngle = j * angle; - p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), - p.y + outsideRadius * Mathf.Cos(currAngle)); - if (radar.splitLine.show) - { - ChartDrawer.DrawLineStyle(vh, radar.splitLine.lineStyle, p, p3, lineColor); - } - } - } - - private void DrawCricleRadar(VertexHelper vh, Radar radar) - { - if (!radar.splitLine.show && !radar.splitArea.show) - { - return; - } - float insideRadius = 0, outsideRadius = 0; - float block = radar.runtimeRadius / radar.splitNumber; - int indicatorNum = radar.indicatorList.Count; - Vector3 p = radar.runtimeCenterPos; - Vector3 p1; - float angle = 2 * Mathf.PI / indicatorNum; - var lineColor = GetLineColor(radar); - for (int i = 0; i < radar.splitNumber; i++) - { - Color color = radar.splitArea.color[i % radar.splitArea.color.Count]; - outsideRadius = insideRadius + block; - if (radar.splitArea.show) - { - ChartDrawer.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear, - 0, 360, m_Settings.cicleSmoothness); - } - if (radar.splitLine.show) - { - ChartDrawer.DrawEmptyCricle(vh, p, outsideRadius, radar.splitLine.lineStyle.width, lineColor, - Color.clear, m_Settings.cicleSmoothness); - } - insideRadius = outsideRadius; - } - for (int j = 0; j <= indicatorNum; j++) - { - float currAngle = j * angle; - p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), - p.y + outsideRadius * Mathf.Cos(currAngle)); - if (radar.splitLine.show) - { - ChartDrawer.DrawLine(vh, p, p1, radar.splitLine.lineStyle.width / 2, lineColor); - } - } - } - - private Color GetLineColor(Radar radar) - { - return radar.splitLine.GetColor(m_ThemeInfo); - } - - protected override void CheckTootipArea(Vector2 local) - { - if (m_IsEnterLegendButtom) return; - - bool highlight = false; - m_Tooltip.ClearValue(); - for (int i = 0; i < m_Series.Count; i++) - { - if (!IsActive(i)) continue; - var serie = m_Series.GetSerie(i); - var radar = m_Radars[serie.radarIndex]; - var dist = Vector2.Distance(radar.runtimeCenterPos, local); - if (dist > radar.runtimeRadius + serie.symbol.size) - { - continue; - } - switch (serie.radarType) - { - case RadarType.Multiple: - for (int n = 0; n < serie.data.Count; n++) - { - var posKey = i * 1000 + n; - if (radar.runtimeDataPosList.ContainsKey(posKey)) - { - var posList = radar.runtimeDataPosList[posKey]; - for (int k = 0; k < posList.Count; k++) - { - if (Vector2.Distance(posList[k], local) <= serie.symbol.size * 1.3f) - { - m_Tooltip.runtimeDataIndex[0] = i; - m_Tooltip.runtimeDataIndex[1] = n; - if (m_Tooltip.runtimeDataIndex.Count >= 3) - m_Tooltip.runtimeDataIndex[2] = k; - else - m_Tooltip.runtimeDataIndex.Add(k); - highlight = true; - break; - } - } - } - } - break; - case RadarType.Single: - for (int n = 0; n < serie.data.Count; n++) - { - var serieData = serie.data[n]; - if (Vector2.Distance(serieData.labelPosition, local) <= serie.symbol.size * 1.3f) - { - m_Tooltip.runtimeDataIndex[0] = i; - m_Tooltip.runtimeDataIndex[1] = n; - highlight = true; - break; - } - } - break; - } - - } - - if (!highlight) - { - if (m_Tooltip.IsActive()) - { - m_Tooltip.SetActive(false); - RefreshChart(); - } - } - else - { - m_Tooltip.UpdateContentPos(local + m_Tooltip.offset); - UpdateTooltip(); - RefreshChart(); - } - } - - protected override void UpdateTooltip() - { - base.UpdateTooltip(); - int serieIndex = m_Tooltip.runtimeDataIndex[0]; - if (serieIndex < 0) - { - if (m_Tooltip.IsActive()) - { - m_Tooltip.SetActive(false); - RefreshChart(); - } - return; - } - m_Tooltip.SetActive(true); - var serie = m_Series.GetSerie(serieIndex); - var radar = m_Radars[serie.radarIndex]; - var dataIndex = tooltip.runtimeDataIndex[1]; - var content = TooltipHelper.GetFormatterContent(m_Tooltip, dataIndex, m_Series, m_ThemeInfo, null, null, false, radar); - TooltipHelper.SetContentAndPosition(tooltip, content, chartRect); - } - - protected override void OnRefreshLabel() - { - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series.GetSerie(i); - if (!serie.show && serie.radarType != RadarType.Single) continue; - var radar = m_Radars[serie.radarIndex]; - var center = radar.runtimeCenterPos; - for (int n = 0; n < serie.dataCount; n++) - { - var serieData = serie.data[n]; - if (serieData.labelObject == null) continue; - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); - var labelPos = serieData.labelPosition; - if (serieLabel.margin != 0) - { - labelPos += serieLabel.margin * (labelPos - center).normalized; - } - serieData.labelObject.SetPosition(labelPos); - serieData.labelObject.UpdateIcon(serieData.iconStyle); - if (serie.show && serieLabel.show && serieData.canShowLabel) - { - var value = serieData.GetCurrData(1); - var max = radar.GetIndicatorMax(n); - SerieLabelHelper.ResetLabel(serieData, serieLabel, themeInfo, i); - serieData.SetLabelActive(serieData.labelPosition != Vector3.zero); - serieData.labelObject.SetLabelPosition(serieLabel.offset); - var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, max, serieLabel); - if (serieData.labelObject.SetText(content)) RefreshChart(); - } - else - { - serieData.SetLabelActive(false); - } - } - } - } } } diff --git a/Runtime/RingChart.cs b/Runtime/RingChart.cs index 17421451..44d8e09a 100644 --- a/Runtime/RingChart.cs +++ b/Runtime/RingChart.cs @@ -1,15 +1,12 @@  -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ -using System.Collections.Generic; -using System.Text; using UnityEngine; -using UnityEngine.UI; namespace XCharts { @@ -19,322 +16,16 @@ namespace XCharts [DisallowMultipleComponent] public partial class RingChart : BaseChart { - private bool m_UpdateTitleText = false; - private bool m_UpdateLabelText = false; - private bool m_IsEnterLegendButtom; - - protected override void Update() - { - base.Update(); - if (m_UpdateTitleText) - { - m_UpdateTitleText = false; - TitleStyleHelper.UpdateTitleText(m_Series); - } - if (m_UpdateLabelText) - { - m_UpdateLabelText = false; - SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName); - } - } #if UNITY_EDITOR protected override void Reset() { base.Reset(); - m_Title.text = "RingChart"; - m_Tooltip.type = Tooltip.Type.Line; + title.text = "RingChart"; + tooltip.type = Tooltip.Type.Line; RemoveData(); - var serie = AddSerie(SerieType.Ring, "serie1"); - serie.roundCap = true; - serie.radius = new float[] { 0.3f, 0.35f }; - serie.titleStyle.show = false; - serie.titleStyle.textStyle.offset = new Vector2(0, 30); - serie.label.show = true; - serie.label.position = SerieLabel.Position.Center; - serie.label.formatter = "{d:f0}%"; - serie.label.fontSize = 28; - var value = Random.Range(30, 90); - var max = 100; - AddData(0, value, max, "data1"); + SerieTemplate.AddDefaultRingSerie(this, "serie1"); } #endif - - protected override void DrawChart(VertexHelper vh) - { - base.DrawChart(vh); - for (int i = 0; i < m_Series.list.Count; i++) - { - var serie = m_Series.list[i]; - var data = serie.data; - serie.index = i; - if (!serie.show || serie.type != SerieType.Ring || serie.animation.HasFadeOut()) - { - continue; - } - serie.animation.InitProgress(data.Count, serie.startAngle, serie.startAngle + 360); - SerieHelper.UpdateCenter(serie, chartPosition, chartWidth, chartHeight); - TitleStyleHelper.CheckTitle(serie, ref m_ReinitTitle, ref m_UpdateTitleText); - SerieLabelHelper.CheckLabel(serie, ref m_ReinitLabel, ref m_UpdateLabelText); - var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - var ringWidth = serie.runtimeOutsideRadius - serie.runtimeInsideRadius; - var dataChanging = false; - for (int j = 0; j < data.Count; j++) - { - var serieData = data[j]; - if (!serieData.show) continue; - if (serieData.IsDataChanged()) dataChanging = true; - var value = serieData.GetFirstData(dataChangeDuration); - var max = serieData.GetLastData(); - var degree = 360 * value / max; - var startDegree = GetStartAngle(serie); - var toDegree = GetToAngle(serie, degree); - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted); - var itemColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, j, serieData.highlighted); - var itemToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, j, serieData.highlighted); - var outsideRadius = serie.runtimeOutsideRadius - j * (ringWidth + serie.ringGap); - var insideRadius = outsideRadius - ringWidth; - var centerRadius = (outsideRadius + insideRadius) / 2; - var borderWidth = itemStyle.borderWidth; - var borderColor = itemStyle.borderColor; - var roundCap = serie.roundCap && insideRadius > 0; - - serieData.runtimePieStartAngle = serie.clockwise ? startDegree : toDegree; - serieData.runtimePieToAngle = serie.clockwise ? toDegree : startDegree; - serieData.runtimePieInsideRadius = insideRadius; - serieData.runtimePieOutsideRadius = outsideRadius; - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, outsideRadius, itemColor, itemToColor, - Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, m_Settings.cicleSmoothness, - roundCap, serie.clockwise); - DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1); - UpateLabelPosition(serie, serieData, j, startDegree, toDegree, centerRadius); - } - if (!serie.animation.IsFinish()) - { - serie.animation.CheckProgress(360); - serie.animation.CheckSymbol(serie.symbol.size); - RefreshChart(); - } - if (dataChanging) - { - RefreshChart(); - } - } - } - - private float GetStartAngle(Serie serie) - { - return serie.clockwise ? serie.startAngle : 360 - serie.startAngle; - } - - private float GetToAngle(Serie serie, float angle) - { - var toAngle = angle + serie.startAngle; - if (!serie.clockwise) - { - toAngle = 360 - angle - serie.startAngle; - } - if (!serie.animation.IsFinish()) - { - var currAngle = serie.animation.GetCurrDetail(); - if (serie.clockwise) - { - toAngle = toAngle > currAngle ? currAngle : toAngle; - } - else - { - toAngle = toAngle < 360 - currAngle ? 360 - currAngle : toAngle; - } - } - return toAngle; - } - - private void DrawCenter(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, bool last) - { - var itemStyle = SerieHelper.GetItemStyle(serie, serieData); - if (!ChartHelper.IsClearColor(itemStyle.centerColor) && last) - { - var radius = insideRadius - itemStyle.centerGap; - var smoothness = m_Settings.cicleSmoothness; - ChartDrawer.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, smoothness); - } - } - - private void UpateLabelPosition(Serie serie, SerieData serieData, int index, float startAngle, - float toAngle, float centerRadius) - { - if (!serie.label.show) return; - if (serieData.labelObject == null) return; - switch (serie.label.position) - { - case SerieLabel.Position.Center: - serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset; - break; - case SerieLabel.Position.Bottom: - var px1 = Mathf.Sin(startAngle * Mathf.Deg2Rad) * centerRadius; - var py1 = Mathf.Cos(startAngle * Mathf.Deg2Rad) * centerRadius; - var xDiff = serie.clockwise ? -serie.label.margin : serie.label.margin; - serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px1 + xDiff, py1); - break; - case SerieLabel.Position.Top: - startAngle += serie.clockwise ? -serie.label.margin : serie.label.margin; - toAngle += serie.clockwise ? serie.label.margin : -serie.label.margin; - var px2 = Mathf.Sin(toAngle * Mathf.Deg2Rad) * centerRadius; - var py2 = Mathf.Cos(toAngle * Mathf.Deg2Rad) * centerRadius; - serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px2, py2); - break; - } - serieData.labelObject.SetLabelPosition(serieData.labelPosition); - } - - private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius) - { - var itemStyle = SerieHelper.GetItemStyle(serie, serieData); - var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, index, false); - if (itemStyle.backgroundWidth != 0) - { - var centerRadius = (outsideRadius + insideRadius) / 2; - var inradius = centerRadius - itemStyle.backgroundWidth / 2; - var outradius = centerRadius + itemStyle.backgroundWidth / 2; - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, inradius, - outradius, backgroundColor, Color.clear, m_Settings.cicleSmoothness); - } - else - { - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, - outsideRadius, backgroundColor, Color.clear, m_Settings.cicleSmoothness); - } - } - - private void DrawBorder(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, float outsideRadius) - { - var itemStyle = SerieHelper.GetItemStyle(serie, serieData); - if (itemStyle.show && itemStyle.borderWidth > 0 && !ChartHelper.IsClearColor(itemStyle.borderColor)) - { - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, outsideRadius, - outsideRadius + itemStyle.borderWidth, itemStyle.borderColor, - Color.clear, m_Settings.cicleSmoothness); - ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, - insideRadius + itemStyle.borderWidth, itemStyle.borderColor, - Color.clear, m_Settings.cicleSmoothness); - } - } - - - private void DrawRoundCap(VertexHelper vh, Serie serie, Vector3 centerPos, Color color, - float insideRadius, float outsideRadius, ref float drawStartDegree, ref float drawEndDegree) - { - if (serie.roundCap && insideRadius > 0 && drawStartDegree != drawEndDegree) - { - var width = (outsideRadius - insideRadius) / 2; - var radius = insideRadius + width; - - var diffDegree = Mathf.Asin(width / radius) * Mathf.Rad2Deg; - drawStartDegree += serie.clockwise ? diffDegree : -diffDegree; - drawEndDegree -= serie.clockwise ? diffDegree : -diffDegree; - ChartDrawer.DrawRoundCap(vh, centerPos, width, radius, drawStartDegree, serie.clockwise, color, false); - ChartDrawer.DrawRoundCap(vh, centerPos, width, radius, drawEndDegree, serie.clockwise, color, true); - } - } - - protected override void OnLegendButtonClick(int index, string legendName, bool show) - { - LegendHelper.CheckDataShow(m_Series, legendName, show); - UpdateLegendColor(legendName, show); - RefreshChart(); - } - - protected override void OnLegendButtonEnter(int index, string legendName) - { - m_IsEnterLegendButtom = true; - LegendHelper.CheckDataHighlighted(m_Series, legendName, true); - RefreshChart(); - } - - protected override void OnLegendButtonExit(int index, string legendName) - { - m_IsEnterLegendButtom = false; - LegendHelper.CheckDataHighlighted(m_Series, legendName, false); - RefreshChart(); - } - - protected override void CheckTootipArea(Vector2 local) - { - if (m_IsEnterLegendButtom) return; - m_Tooltip.runtimeDataIndex.Clear(); - bool selected = false; - foreach (var serie in m_Series.list) - { - int index = GetRingIndex(serie, local); - m_Tooltip.runtimeDataIndex.Add(index); - if (serie.type != SerieType.Ring) continue; - bool refresh = false; - for (int j = 0; j < serie.data.Count; j++) - { - var serieData = serie.data[j]; - if (serieData.highlighted != (j == index)) refresh = true; - serieData.highlighted = j == index; - } - if (index >= 0) selected = true; - if (refresh) RefreshChart(); - } - if (selected) - { - m_Tooltip.UpdateContentPos(local + m_Tooltip.offset); - UpdateTooltip(); - } - else if (m_Tooltip.IsActive()) - { - m_Tooltip.SetActive(false); - RefreshChart(); - } - } - - private int GetRingIndex(Serie serie, Vector2 local) - { - if (serie.type != SerieType.Ring) return -1; - var dist = Vector2.Distance(local, serie.runtimeCenterPos); - if (dist > serie.runtimeOutsideRadius) return -1; - Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y); - float angle = VectorAngle(Vector2.up, dir); - for (int i = 0; i < serie.data.Count; i++) - { - var serieData = serie.data[i]; - if (dist >= serieData.runtimePieInsideRadius && - dist <= serieData.runtimePieOutsideRadius && - angle >= serieData.runtimePieStartAngle && - angle <= serieData.runtimePieToAngle) - { - return i; - } - } - return -1; - } - - float VectorAngle(Vector2 from, Vector2 to) - { - float angle; - - Vector3 cross = Vector3.Cross(from, to); - angle = Vector2.Angle(from, to); - angle = cross.z > 0 ? -angle : angle; - angle = (angle + 360) % 360; - return angle; - } - - protected override void UpdateTooltip() - { - base.UpdateTooltip(); - bool showTooltip = false; - foreach (var serie in m_Series.list) - { - int index = m_Tooltip.runtimeDataIndex[serie.index]; - if (index < 0) continue; - showTooltip = true; - var content = TooltipHelper.GetFormatterContent(m_Tooltip, index, m_Series, m_ThemeInfo); - TooltipHelper.SetContentAndPosition(tooltip, content, chartRect); - } - m_Tooltip.SetActive(showTooltip); - } } } diff --git a/Runtime/ScatterChart.cs b/Runtime/ScatterChart.cs index d014a386..343bfc93 100644 --- a/Runtime/ScatterChart.cs +++ b/Runtime/ScatterChart.cs @@ -1,9 +1,9 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using UnityEngine; @@ -23,22 +23,14 @@ namespace XCharts protected override void Reset() { base.Reset(); - m_Title.text = "ScatterChart"; - m_Tooltip.type = Tooltip.Type.None; - m_XAxises[0].type = Axis.AxisType.Value; - m_XAxises[0].boundaryGap = false; - m_YAxises[1].type = Axis.AxisType.Value; - m_XAxises[1].boundaryGap = false; + title.text = "ScatterChart"; + tooltip.type = Tooltip.Type.None; + m_XAxes[0].type = Axis.AxisType.Value; + m_XAxes[0].boundaryGap = false; + m_YAxes[1].type = Axis.AxisType.Value; + m_XAxes[1].boundaryGap = false; RemoveData(); - var serie = AddSerie(SerieType.Scatter, "serie1"); - serie.symbol.show = true; - serie.symbol.type = SerieSymbolType.Circle; - serie.itemStyle.opacity = 0.8f; - serie.clip = false; - for (int i = 0; i < 10; i++) - { - AddData(0, Random.Range(10, 100), Random.Range(10, 100)); - } + SerieTemplate.AddDefaultScatterSerie(this, "serie1"); } #endif @@ -51,10 +43,11 @@ namespace XCharts if (serie.type == SerieType.EffectScatter) { hasEffectScatter = true; + var symbolSize = serie.symbol.GetSize(null, m_Theme.serie.scatterSymbolSize); for (int i = 0; i < serie.symbol.animationSize.Count; ++i) { serie.symbol.animationSize[i] += m_EffectScatterSpeed * Time.deltaTime; - if (serie.symbol.animationSize[i] > serie.symbol.size) + if (serie.symbol.animationSize[i] > symbolSize) { serie.symbol.animationSize[i] = i * 5; } @@ -67,10 +60,11 @@ namespace XCharts } } - protected override void CheckTootipArea(Vector2 local) + protected override void CheckTootipArea(Vector2 local, bool isActivedOther) { - base.CheckTootipArea(local); - m_Tooltip.ClearSerieDataIndex(); + base.CheckTootipArea(local, isActivedOther); + if (isActivedOther) return; + tooltip.ClearSerieDataIndex(); bool selected = false; foreach (var serie in m_Series.list) { @@ -84,10 +78,10 @@ namespace XCharts var symbol = SerieHelper.GetSerieSymbol(serie, serieData); if (!symbol.ShowSymbol(j, dataCount)) continue; var dist = Vector3.Distance(local, serieData.runtimePosition); - if (dist <= symbol.size) + if (dist <= symbol.GetSize(serieData.data, m_Theme.serie.scatterSymbolSize)) { serieData.selected = true; - m_Tooltip.AddSerieDataIndex(serie.index, j); + tooltip.AddSerieDataIndex(serie.index, j); selected = true; } else @@ -99,12 +93,12 @@ namespace XCharts } if (selected) { - m_Tooltip.UpdateContentPos(local + m_Tooltip.offset); + tooltip.UpdateContentPos(local + tooltip.offset); UpdateTooltip(); } - else if (m_Tooltip.IsActive()) + else if (tooltip.IsActive()) { - m_Tooltip.SetActive(false); + tooltip.SetActive(false); RefreshChart(); } } @@ -112,15 +106,15 @@ namespace XCharts protected override void UpdateTooltip() { base.UpdateTooltip(); - if (m_Tooltip.isAnySerieDataIndex()) + if (tooltip.isAnySerieDataIndex()) { - var content = TooltipHelper.GetFormatterContent(m_Tooltip, 0, m_Series, m_ThemeInfo); + var content = TooltipHelper.GetFormatterContent(tooltip, 0, m_Series, m_Theme); TooltipHelper.SetContentAndPosition(tooltip, content, chartRect); - m_Tooltip.SetActive(true); + tooltip.SetActive(true); } else { - m_Tooltip.SetActive(false); + tooltip.SetActive(false); } } } diff --git a/Runtime/Template.meta b/Runtime/Template.meta new file mode 100644 index 00000000..e420098f --- /dev/null +++ b/Runtime/Template.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 17dec85beb28a4c53a8d4dd618a781c8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Template/SerieTemplate.cs b/Runtime/Template/SerieTemplate.cs new file mode 100644 index 00000000..8b3f4ebc --- /dev/null +++ b/Runtime/Template/SerieTemplate.cs @@ -0,0 +1,172 @@ + +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEngine; + +namespace XCharts +{ + public static class SerieTemplate + { + public static void AddDefaultSerie(BaseChart chart, SerieType serieType, string serieName) + { + switch (serieType) + { + case SerieType.Line: AddDefaultLineSerie(chart, serieName); break; + case SerieType.Bar: AddDefaultBarSerie(chart, serieName); break; + case SerieType.Pie: AddDefaultPieSerie(chart, serieName); break; + case SerieType.Radar: AddDefaultRadarSerie(chart, serieName); break; + case SerieType.Scatter: AddDefaultScatterSerie(chart, serieName); break; + case SerieType.EffectScatter: AddDefaultEffectScatterSerie(chart, serieName); break; + case SerieType.Heatmap: AddDefaultHeatmapSerie(chart, serieName); break; + case SerieType.Liquid: AddDefaultLiquidSerie(chart, serieName); break; + case SerieType.Gauge: AddDefaultGaugeSerie(chart, serieName); break; + case SerieType.Ring: AddDefaultRingSerie(chart, serieName); break; + default: Debug.LogError("AddDefaultSerie: not support serieType yet:" + serieType); break; + } + } + + public static void AddDefaultLineSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.Line, serieName); + serie.symbol.show = true; + for (int i = 0; i < 5; i++) + { + chart.AddData(serie.index, UnityEngine.Random.Range(10, 90)); + } + } + + public static void AddDefaultBarSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.Bar, serieName); + for (int i = 0; i < 5; i++) + { + chart.AddData(serie.index, UnityEngine.Random.Range(10, 90)); + } + } + public static void AddDefaultPieSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.Pie, serieName); + chart.AddData(serie.index, 70, "pie1"); + chart.AddData(serie.index, 20, "pie2"); + chart.AddData(serie.index, 10, "pie3"); + } + + public static void AddDefaultScatterSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.Scatter, serieName); + serie.symbol.show = true; + serie.symbol.type = SerieSymbolType.Circle; + serie.itemStyle.opacity = 0.8f; + serie.clip = false; + for (int i = 0; i < 10; i++) + { + chart.AddData(serie.index, Random.Range(10, 100), Random.Range(10, 100)); + } + } + + public static void AddDefaultEffectScatterSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.EffectScatter, serieName); + serie.symbol.show = true; + serie.symbol.type = SerieSymbolType.Circle; + serie.itemStyle.opacity = 0.8f; + serie.clip = false; + for (int i = 0; i < 10; i++) + { + chart.AddData(serie.index, Random.Range(10, 100), Random.Range(10, 100)); + } + } + + public static void AddDefaultHeatmapSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.Heatmap, serieName); + serie.itemStyle.show = true; + serie.itemStyle.borderWidth = 1; + serie.itemStyle.borderColor = Color.clear; + serie.emphasis.show = true; + serie.emphasis.itemStyle.show = true; + serie.emphasis.itemStyle.borderWidth = 1; + serie.emphasis.itemStyle.borderColor = Color.black; + } + + public static void AddDefaultLiquidSerie(BaseChart chart, string serieName) + { + if (chart.vessels.Count == 0) + { + chart.AddVessel(Vessel.defaultVessel); + } + var serie = chart.AddSerie(SerieType.Liquid, serieName); + serie.min = 0; + serie.max = 100; + serie.label.show = true; + serie.label.textStyle.fontSize = 40; + serie.label.formatter = "{d}%"; + serie.label.textStyle.color = new Color32(70, 70, 240, 255); + chart.AddData(serie.index, UnityEngine.Random.Range(0, 100)); + } + + public static void AddDefaultRadarSerie(BaseChart chart, string serieName) + { + if (chart.radars.Count == 0) + { + chart.AddRadar(Radar.defaultRadar); + } + var serie = chart.AddSerie(SerieType.Radar, serieName); + serie.symbol.show = true; + serie.symbol.type = SerieSymbolType.EmptyCircle; + serie.symbol.size = 4; + serie.symbol.selectedSize = 6; + serie.showDataName = true; + List<float> data = new List<float>(); + for (int i = 0; i < 5; i++) + { + data.Add(Random.Range(20, 90)); + } + chart.AddData(serie.index, data, "legendName"); + } + + public static void AddDefaultGaugeSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.Gauge, serieName); + serie.min = 0; + serie.max = 100; + serie.startAngle = -125; + serie.endAngle = 125; + serie.center[0] = 0.5f; + serie.center[1] = 0.5f; + serie.radius[0] = 80; + serie.splitNumber = 5; + serie.animation.dataChangeEnable = true; + serie.titleStyle.show = true; + serie.titleStyle.textStyle.offset = new Vector2(0, 20); + serie.label.show = true; + serie.label.offset = new Vector3(0, -30); + serie.itemStyle.show = true; + serie.gaugeAxis.axisLabel.show = true; + serie.gaugeAxis.axisLabel.margin = 18; + chart.AddData(serie.index, UnityEngine.Random.Range(10, 90), "title"); + } + + public static void AddDefaultRingSerie(BaseChart chart, string serieName) + { + var serie = chart.AddSerie(SerieType.Ring, serieName); + serie.roundCap = true; + serie.radius = new float[] { 0.3f, 0.35f }; + serie.titleStyle.show = false; + serie.titleStyle.textStyle.offset = new Vector2(0, 30); + serie.label.show = true; + serie.label.position = SerieLabel.Position.Center; + serie.label.formatter = "{d:f0}%"; + serie.label.textStyle.fontSize = 28; + var value = Random.Range(30, 90); + var max = 100; + chart.AddData(serie.index, value, max, "data1"); + } + } +} \ No newline at end of file diff --git a/Runtime/Template/SerieTemplate.cs.meta b/Runtime/Template/SerieTemplate.cs.meta new file mode 100644 index 00000000..4cc40220 --- /dev/null +++ b/Runtime/Template/SerieTemplate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a9df567ff69c4d4db6d481627bed703 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utils.meta b/Runtime/Utils.meta new file mode 100644 index 00000000..e226224c --- /dev/null +++ b/Runtime/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4a108c82e8e324eea98f734dea6796f1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utils/ColorUtil.cs b/Runtime/Utils/ColorUtil.cs new file mode 100644 index 00000000..b4ed025a --- /dev/null +++ b/Runtime/Utils/ColorUtil.cs @@ -0,0 +1,29 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; + +namespace XCharts +{ + public static class ColorUtil + { + public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0); + public static readonly Vector2 zeroVector2 = Vector2.zero; + /// <summary> + /// Convert the html string to color. + /// 将字符串颜色值转成Color。 + /// </summary> + /// <param name="hexColorStr"></param> + /// <returns></returns> + public static Color32 GetColor(string hexColorStr) + { + Color color; + ColorUtility.TryParseHtmlString(hexColorStr, out color); + return (Color32)color; + } + } +} \ No newline at end of file diff --git a/Runtime/Utils/ColorUtil.cs.meta b/Runtime/Utils/ColorUtil.cs.meta new file mode 100644 index 00000000..a53ccbb9 --- /dev/null +++ b/Runtime/Utils/ColorUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4260c3b8fdaff435a8bc10375b812bd8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utils/DefineSymbolsUtil.cs b/Runtime/Utils/DefineSymbolsUtil.cs new file mode 100644 index 00000000..fe26908a --- /dev/null +++ b/Runtime/Utils/DefineSymbolsUtil.cs @@ -0,0 +1,93 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System; +using System.Reflection; +using System.Text; +using UnityEditor; +using UnityEngine; + +namespace XCharts +{ + public static class DefineSymbolsUtil + { + private static readonly StringBuilder s_StringBuilder = new StringBuilder(); + + public static void AddGlobalDefine(string symbol) + { + var flag = false; + var num = 0; + foreach (var buildTargetGroup in (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup))) + { + if (IsValidBuildTargetGroup(buildTargetGroup)) + { + var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); + symbols = symbols.Replace(" ", ""); + if (Array.IndexOf(symbols.Split(';'), symbol) != -1) continue; + flag = true; + num++; + var defines = symbols + (symbols.Length > 0 ? ";" + symbol : symbol); + PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); + } + } + if (flag) + { + Debug.LogFormat("Added global define symbol \"{0}\" to {1} BuildTargetGroups.", symbol, num); + } + } + + public static void RemoveGlobalDefine(string symbol) + { + var flag = false; + var num = 0; + foreach (var buildTargetGroup in (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup))) + { + if (IsValidBuildTargetGroup(buildTargetGroup)) + { + var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup).Split(';'); + if (Array.IndexOf(symbols, symbol) == -1) continue; + flag = true; + num++; + s_StringBuilder.Length = 0; + foreach (var str in symbols) + { + if (!str.Equals(symbol)) + { + if (s_StringBuilder.Length > 0) s_StringBuilder.Append(";"); + s_StringBuilder.Append(str); + } + } + PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, s_StringBuilder.ToString()); + } + } + if (flag) + { + Debug.LogFormat("Removed global define symbol \"{0}\" to {1} BuildTargetGroups.", symbol, num); + } + } + + private static bool IsValidBuildTargetGroup(BuildTargetGroup group) + { + if (group == BuildTargetGroup.Unknown) return false; + var type = Type.GetType("UnityEditor.Modules.ModuleManager, UnityEditor.dll"); + if (type == null) return true; + var method1 = type.GetMethod("GetTargetStringFromBuildTargetGroup", BindingFlags.Static | BindingFlags.NonPublic); + var method2 = typeof(PlayerSettings).GetMethod("GetPlatformName", BindingFlags.Static | BindingFlags.NonPublic); + if (method1 == null || method2 == null) return true; + var str1 = (string)method1.Invoke(null, new object[] { group }); + var str2 = (string)method2.Invoke(null, new object[] { group }); + if (string.IsNullOrEmpty(str1)) + { + return !string.IsNullOrEmpty(str2); + } + else + { + return true; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utils/DefineSymbolsUtil.cs.meta b/Runtime/Utils/DefineSymbolsUtil.cs.meta new file mode 100644 index 00000000..eae3d81e --- /dev/null +++ b/Runtime/Utils/DefineSymbolsUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 91545951242fa441eb1a9bba3a6ad5a7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Utility/PropertyUtility.cs b/Runtime/Utils/PropertyUtil.cs similarity index 82% rename from Runtime/Internal/Utility/PropertyUtility.cs rename to Runtime/Utils/PropertyUtil.cs index e9628ff5..3ab7b222 100644 --- a/Runtime/Internal/Utility/PropertyUtility.cs +++ b/Runtime/Utils/PropertyUtil.cs @@ -1,16 +1,16 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Collections.Generic; using UnityEngine; namespace XCharts { - internal static class PropertyUtility + public static class PropertyUtil { public static bool SetColor(ref Color currentValue, Color newValue) { diff --git a/Runtime/Utils/PropertyUtil.cs.meta b/Runtime/Utils/PropertyUtil.cs.meta new file mode 100644 index 00000000..9292ef02 --- /dev/null +++ b/Runtime/Utils/PropertyUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b1f52eadd805d43aea47947fb81e761f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XCharts.Runtime.asmdef b/Runtime/XCharts.Runtime.asmdef index f16518a1..9ec9d4b0 100644 --- a/Runtime/XCharts.Runtime.asmdef +++ b/Runtime/XCharts.Runtime.asmdef @@ -1,6 +1,8 @@ { "name": "XCharts.Runtime", - "references": [], + "references": [ + "Unity.TextMeshPro" + ], "optionalUnityReferences": [], "includePlatforms": [], "excludePlatforms": [], diff --git a/Runtime/Internal/Utility/XChartsMgr.cs b/Runtime/XChartsMgr.cs similarity index 62% rename from Runtime/Internal/Utility/XChartsMgr.cs rename to Runtime/XChartsMgr.cs index 01908be8..1ce199ec 100644 --- a/Runtime/Internal/Utility/XChartsMgr.cs +++ b/Runtime/XChartsMgr.cs @@ -1,11 +1,11 @@ -/******************************************/ -/* */ -/* Copyright (c) 2018 monitor1394 */ -/* https://github.com/monitor1394 */ -/* */ -/******************************************/ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ using System.Text; using System.Collections; @@ -14,6 +14,9 @@ using System.Text.RegularExpressions; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; +#if UNITY_EDITOR +using UnityEditor; +#endif namespace XCharts { @@ -26,15 +29,24 @@ namespace XCharts public string homepage = ""; } +#if UNITY_EDITOR + [InitializeOnLoad] +#endif [ExecuteInEditMode] public class XChartsMgr : MonoBehaviour { - public const string version = "1.6.3"; - public const int date = 20210102; + internal static string _version = "2.0.0_preview1"; + internal static int _versionDate = 20210110; + public static string version { get { return _version; } } + public static int versionDate { get { return _versionDate; } } + public static string fullVersion { get { return version + "_" + versionDate; } } [SerializeField] private string m_NowVersion; [SerializeField] private string m_NewVersion; [SerializeField] private List<BaseChart> m_ChartList = new List<BaseChart>(); + [SerializeField] private Dictionary<string, ChartTheme> m_ThemeDict = new Dictionary<string, ChartTheme>(); + + private List<string> m_ThemeNames = new List<string>(); private static XChartsMgr m_XCharts; public static XChartsMgr Instance @@ -43,37 +55,38 @@ namespace XCharts { if (m_XCharts == null) { - var go = GameObject.Find("_xcharts_"); - if (go == null) + m_XCharts = FindObjectOfType<XChartsMgr>(); + if (m_XCharts == null) { - go = new GameObject(); - go.name = "_xcharts_"; - if (Application.isPlaying) - { - DontDestroyOnLoad(go); - } - m_XCharts = go.AddComponent<XChartsMgr>(); + GameObject obj = new GameObject("_xcharts_"); + m_XCharts = obj.AddComponent<XChartsMgr>(); } - else - { - m_XCharts = go.GetComponent<XChartsMgr>(); - if (m_XCharts == null) - { - m_XCharts = go.AddComponent<XChartsMgr>(); - } - } - m_XCharts.m_NowVersion = version + "_" + date; + m_XCharts.m_NowVersion = fullVersion; } return m_XCharts; } } - private XChartsMgr() { } + private XChartsMgr() + { + } + + static XChartsMgr() + { +#if UNITY_EDITOR + EditorApplication.delayCall += () => + { + var mgr = XChartsMgr.Instance; + }; +#endif + } private void Awake() { SerieLabelPool.ClearAll(); m_ChartList.Clear(); + m_ThemeDict.Clear(); + LoadThemesFromResources(); } public string changeLog { get; private set; } @@ -199,7 +212,7 @@ namespace XCharts StringBuilder sb = new StringBuilder(); var temp = text.Split('\n'); var regex = new Regex(".*(\\d{4}\\.\\d{2}\\.\\d{2}).*"); - var checkDate = XChartsMgr.date; + var checkDate = versionDate; foreach (var t in temp) { if (regex.IsMatch(t)) @@ -266,6 +279,34 @@ namespace XCharts SerieLabelPool.ClearAll(); } + public void LoadThemesFromResources() + { + //Debug.Log("LoadThemesFromResources"); + m_ThemeDict.Clear(); + AddTheme(ChartTheme.Default); + AddTheme(ChartTheme.Light); + AddTheme(ChartTheme.Dark); + var list = Resources.LoadAll<ChartTheme>(""); + foreach (var theme in list) + { + AddTheme(theme); + } + //Debug.Log("LoadThemesFromResources DONE: theme count=" + m_ThemeDict.Keys.Count); + } + + private void AddTheme(ChartTheme theme) + { + if (!m_ThemeDict.ContainsKey(theme.themeName)) + { + m_ThemeDict.Add(theme.themeName, theme); + m_ThemeNames.Add(theme.themeName); + } + else + { + Debug.LogError("Theme name is exist:" + theme.themeName); + } + } + public void AddChart(BaseChart chart) { var sameNameChart = GetChart(chart.chartName); @@ -308,5 +349,90 @@ namespace XCharts { return m_ChartList.Contains(chart); } + + public static List<string> GetAllThemeNames() + { + return Instance.m_ThemeNames; + } + + public static bool ContainsTheme(string themeName) + { + return Instance.m_ThemeNames.Contains(themeName); + } + + public static void SwitchTheme(BaseChart chart, string themeName) + { + Debug.Log("SwitchTheme:" + themeName); + if (chart.theme.themeName.Equals(themeName)) + { + return; + } +#if UNITY_EDITOR + if (Instance.m_ThemeDict.Count == 0) + { + Instance.LoadThemesFromResources(); + } +#endif + if (!Instance.m_ThemeDict.ContainsKey(themeName)) + { + Debug.LogError("SwitchTheme ERROR: not exist theme:" + themeName); + return; + } + var target = Instance.m_ThemeDict[themeName]; + chart.theme.CopyTheme(target); + chart.RefreshAllComponent(); + } + + public static string GetThemeAssetPath(string themeName) + { + return string.Format("Assets/XCharts/Resources/XChartsTheme-{0}.asset", themeName); + } + + public static bool ExportTheme(ChartTheme theme, string themeNewName) + { +#if UNITY_EDITOR + var newtheme = ChartTheme.EmptyTheme; + newtheme.CopyTheme(theme); + newtheme.name = themeNewName; + newtheme.themeName = themeNewName; + + var themeFileName = "XChartsTheme-" + newtheme.themeName; + var assetPath = string.Format("Assets/XCharts/Resources/{0}.asset", themeFileName); + if (Resources.Load<XChartsSettings>(themeFileName)) + { + AssetDatabase.DeleteAsset(assetPath); + } + AssetDatabase.CreateAsset(newtheme, assetPath); + Instance.AddTheme(newtheme); + return true; +#else + return false; +#endif + } + + public static void RemoveAllChartObject() + { + if (Instance.m_ChartList.Count == 0) + { + return; + } + foreach (var chart in Instance.m_ChartList) + { + if (chart != null) + chart.RemoveChartObject(); + } + } + + public static void EnableTextMeshPro() + { + DefineSymbolsUtil.AddGlobalDefine("dUI_TextMeshPro"); + RemoveAllChartObject(); + } + + public static void DisableTextMeshPro() + { + DefineSymbolsUtil.RemoveGlobalDefine("dUI_TextMeshPro"); + RemoveAllChartObject(); + } } } \ No newline at end of file diff --git a/Runtime/Internal/Utility/XChartsMgr.cs.meta b/Runtime/XChartsMgr.cs.meta similarity index 83% rename from Runtime/Internal/Utility/XChartsMgr.cs.meta rename to Runtime/XChartsMgr.cs.meta index de652c5f..f86bdc67 100644 --- a/Runtime/Internal/Utility/XChartsMgr.cs.meta +++ b/Runtime/XChartsMgr.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5a1a53cb62d6d4485a30464e892d8005 +guid: 953f0e846565c4086a4bcdc6bc14cf85 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/XChartsPackageResourceImporter.cs b/Runtime/XChartsPackageResourceImporter.cs new file mode 100644 index 00000000..be94a6ae --- /dev/null +++ b/Runtime/XChartsPackageResourceImporter.cs @@ -0,0 +1,209 @@ +#if UNITY_EDITOR + +using System; +using System.IO; +using UnityEngine; +using UnityEditor; + + +namespace XCharts +{ + [System.Serializable] + public class XChartsPackageResourceImporter + { + bool m_EssentialResourcesImported; + bool m_ExamplesAndExtrasResourcesImported; + + public XChartsPackageResourceImporter() { } + + public void OnDestroy() + { + } + + public void OnGUI() + { + m_EssentialResourcesImported = File.Exists("Assets/XCharts/Resources/XChartsSettings.asset"); + m_ExamplesAndExtrasResourcesImported = Directory.Exists("Assets/XCharts/Examples & Extras"); + + GUILayout.BeginVertical(); + { + GUILayout.BeginVertical(EditorStyles.helpBox); + { + GUILayout.Label("XCharts Essentials", EditorStyles.boldLabel); + GUILayout.Label("This appears to be the first time you access XCharts, as such we need to add resources to your project that are essential for using XCharts. These new resources will be placed at the root of your project in the \"XCharts\" folder.", new GUIStyle(EditorStyles.label) { wordWrap = true }); + GUILayout.Space(5f); + + GUI.enabled = !m_EssentialResourcesImported; + if (GUILayout.Button("Import XCharts Essentials")) + { + AssetDatabase.importPackageCompleted += ImportCallback; + + string packageFullPath = GetPackageFullPath(); + Debug.LogError("packageFullPath:" + packageFullPath); + AssetDatabase.ImportPackage(packageFullPath + "/Package Resources/XCharts Essential Resources.unitypackage", false); + } + GUILayout.Space(5f); + GUI.enabled = true; + } + GUILayout.EndVertical(); + } + GUILayout.EndVertical(); + + GUILayout.BeginVertical(); + { + GUILayout.BeginVertical(EditorStyles.helpBox); + { + GUILayout.Label("TextMeshPro", EditorStyles.boldLabel); +#if dUI_TextMeshPro + GUILayout.Label("TextMeshPro is now enabled. You can turn it off by clicking the button below.", new GUIStyle(EditorStyles.label) { wordWrap = true }); + GUILayout.Space(5f); + if (GUILayout.Button("Disable TextMeshPro")) + { + XChartsMgr.DisableTextMeshPro(); + } +#else + GUILayout.Label("TextMeshPro is not active. You can activate it by clicking the button below. Make sure TextMeshPro is already in your project before activating it.", new GUIStyle(EditorStyles.label) { wordWrap = true }); + GUILayout.Space(5f); + if (GUILayout.Button("Enable TextMeshPro")) + { + XChartsMgr.EnableTextMeshPro(); + } +#endif + GUILayout.Space(5f); + } + GUILayout.EndVertical(); + } + GUILayout.EndVertical(); + GUILayout.Space(5f); + } + + internal void RegisterResourceImportCallback() + { + AssetDatabase.importPackageCompleted += ImportCallback; + } + + /// <summary> + /// + /// </summary> + /// <param name="packageName"></param> + void ImportCallback(string packageName) + { + if (packageName == "XCharts Essential Resources") + { + m_EssentialResourcesImported = true; +#if UNITY_2018_3_OR_NEWER + SettingsService.NotifySettingsProviderChanged(); +#endif + } + Debug.Log("[" + packageName + "] have been imported."); + + AssetDatabase.importPackageCompleted -= ImportCallback; + } + + static string GetPackageFullPath() + { + // Check for potential UPM package + string packagePath = Path.GetFullPath("Packages/com.monitor1394.xcharts"); + if (Directory.Exists(packagePath)) + { + return packagePath; + } + + packagePath = Path.GetFullPath("Assets/.."); + Debug.LogError("packagePath:" + packagePath + ":" + Directory.Exists(packagePath)); + if (Directory.Exists(packagePath)) + { + // Search default location for development package + if (Directory.Exists(packagePath + "/Assets/Packages/com.monitor1394.xcharts/Package Resources")) + { + return packagePath + "/Assets/Packages/com.monitor1394.xcharts"; + } + + // Search for default location of normal XCharts AssetStore package + if (Directory.Exists(packagePath + "/Assets/XCharts/Package Resources")) + { + return packagePath + "/Assets/XCharts"; + } + + // Search for potential alternative locations in the user project + string[] matchingPaths = Directory.GetDirectories(packagePath, "XCharts", SearchOption.AllDirectories); + string path = ValidateLocation(matchingPaths, packagePath); + if (path != null) return packagePath + path; + } + + return null; + } + + static string ValidateLocation(string[] paths, string projectPath) + { + for (int i = 0; i < paths.Length; i++) + { + // Check if the Editor Resources folder exists. + if (Directory.Exists(paths[i] + "/Package Resources")) + { + string folderPath = paths[i].Replace(projectPath, ""); + folderPath = folderPath.TrimStart('\\', '/'); + return folderPath; + } + } + + return null; + } + } + + public class XChartsPackageResourceImporterWindow : EditorWindow + { + [SerializeField] + XChartsPackageResourceImporter m_ResourceImporter; + + static XChartsPackageResourceImporterWindow m_ImporterWindow; + + public static void ShowPackageImporterWindow() + { + if (m_ImporterWindow == null) + { + m_ImporterWindow = GetWindow<XChartsPackageResourceImporterWindow>(); + m_ImporterWindow.titleContent = new GUIContent("XCharts Importer"); + } + + m_ImporterWindow.Focus(); + } + + void OnEnable() + { + SetEditorWindowSize(); + + if (m_ResourceImporter == null) + m_ResourceImporter = new XChartsPackageResourceImporter(); + } + + void OnDestroy() + { + m_ResourceImporter.OnDestroy(); + } + + void OnGUI() + { + m_ResourceImporter.OnGUI(); + } + + void OnInspectorUpdate() + { + Repaint(); + } + + /// <summary> + /// Limits the minimum size of the editor window. + /// </summary> + void SetEditorWindowSize() + { + EditorWindow editorWindow = this; + + Vector2 windowSize = new Vector2(640, 210); + editorWindow.minSize = windowSize; + editorWindow.maxSize = windowSize; + } + } +} + +#endif diff --git a/Runtime/XChartsPackageResourceImporter.cs.meta b/Runtime/XChartsPackageResourceImporter.cs.meta new file mode 100644 index 00000000..5c571723 --- /dev/null +++ b/Runtime/XChartsPackageResourceImporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 57156ca98208e4f648d71cb12beb0a28 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XChartsSettings.cs b/Runtime/XChartsSettings.cs new file mode 100644 index 00000000..87b7d3cd --- /dev/null +++ b/Runtime/XChartsSettings.cs @@ -0,0 +1,143 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using UnityEngine; +using System; +#if dUI_TextMeshPro +using TMPro; +#endif + +namespace XCharts +{ + [Serializable] + [ExcludeFromPresetAttribute] + public class XChartsSettings : ScriptableObject + { + + [SerializeField] private Font m_Font; +#if dUI_TextMeshPro + [SerializeField] private TMP_FontAsset m_TMPFont; +#endif + [SerializeField] [Range(1, 200)] private int m_FontSizeLv1 = 28; + [SerializeField] [Range(1, 200)] private int m_FontSizeLv2 = 24; + [SerializeField] [Range(1, 200)] private int m_FontSizeLv3 = 20; + [SerializeField] [Range(1, 200)] private int m_FontSizeLv4 = 18; + [SerializeField] private LineStyle.Type m_AxisLineType = LineStyle.Type.Solid; + [SerializeField] [Range(0, 20)] private float m_AxisLineWidth = 0.8f; + [SerializeField] private LineStyle.Type m_AxisSplitLineType = LineStyle.Type.Solid; + [SerializeField] [Range(0, 20)] private float m_AxisSplitLineWidth = 0.8f; + [SerializeField] [Range(0, 20)] private float m_AxisTickWidth = 0.8f; + [SerializeField] [Range(0, 20)] private float m_AxisTickLength = 5f; + [SerializeField] [Range(0, 200)] private float m_GaugeAxisLineWidth = 15f; + [SerializeField] [Range(0, 20)] private float m_GaugeAxisSplitLineWidth = 0.8f; + [SerializeField] [Range(0, 20)] private float m_GaugeAxisSplitLineLength = 15f; + [SerializeField] [Range(0, 20)] private float m_GaugeAxisTickWidth = 0.8f; + [SerializeField] [Range(0, 20)] private float m_GaugeAxisTickLength = 5f; + [SerializeField] [Range(0, 20)] private float m_TootipLineWidth = 0.8f; + [SerializeField] [Range(0, 20)] private float m_DataZoomBorderWidth = 0.5f; + [SerializeField] [Range(0, 20)] private float m_DataZoomDataLineWidth = 0.5f; + [SerializeField] [Range(0, 20)] private float m_VisualMapBorderWidth = 0f; + + [SerializeField] [Range(0, 20)] private float m_SerieLineWidth = 1.4f; + [SerializeField] [Range(0, 200)] private float m_SerieLineSymbolSize = 4f; + [SerializeField] [Range(0, 200)] private float m_SerieLineSymbolSelectedSize = 8f; + [SerializeField] [Range(0, 200)] private float m_SerieScatterSymbolSize = 20f; + [SerializeField] [Range(0, 200)] private float m_SerieScatterSymbolSelectedSize = 30f; + + [SerializeField] private bool m_EditorBlockEnable = true; + + [SerializeField] [Range(1, 20)] protected int m_MaxPainter = 10; + [SerializeField] [Range(1, 10)] protected float m_LineSmoothStyle = 3f; + [SerializeField] [Range(1f, 20)] protected float m_LineSmoothness = 2f; + [SerializeField] [Range(1f, 20)] protected float m_LineSegmentDistance = 3f; + [SerializeField] [Range(1, 10)] protected float m_CicleSmoothness = 2f; + [SerializeField] [Range(10, 50)] protected float m_VisualMapTriangeLen = 20f; + [SerializeField] [Range(1, 20)] protected float m_PieTooltipExtraRadius = 8f; + [SerializeField] [Range(1, 20)] protected float m_PieSelectedOffset = 8f; + + public static Font font { get { return Instance.m_Font; } } +#if dUI_TextMeshPro + public static TMP_FontAsset tmpFont { get { return Instance.m_TMPFont; } } +#endif + /// <summary> + /// 一级字体大小。 + /// </summary> + public static int fontSizeLv1 { get { return Instance.m_FontSizeLv1; } } + public static int fontSizeLv2 { get { return Instance.m_FontSizeLv2; } } + public static int fontSizeLv3 { get { return Instance.m_FontSizeLv3; } } + public static int fontSizeLv4 { get { return Instance.m_FontSizeLv4; } } + public static LineStyle.Type axisLineType { get { return Instance.m_AxisLineType; } } + public static float axisLineWidth { get { return Instance.m_AxisLineWidth; } } + public static LineStyle.Type axisSplitLineType { get { return Instance.m_AxisSplitLineType; } } + public static float axisSplitLineWidth { get { return Instance.m_AxisSplitLineWidth; } } + public static float axisTickWidth { get { return Instance.m_AxisTickWidth; } } + public static float axisTickLength { get { return Instance.m_AxisTickLength; } } + public static float gaugeAxisLineWidth { get { return Instance.m_GaugeAxisLineWidth; } } + public static float gaugeAxisSplitLineWidth { get { return Instance.m_GaugeAxisSplitLineWidth; } } + public static float gaugeAxisSplitLineLength { get { return Instance.m_GaugeAxisSplitLineLength; } } + public static float gaugeAxisTickWidth { get { return Instance.m_GaugeAxisTickWidth; } } + public static float gaugeAxisTickLength { get { return Instance.m_GaugeAxisTickLength; } } + + public static float tootipLineWidth { get { return Instance.m_TootipLineWidth; } } + public static float dataZoomBorderWidth { get { return Instance.m_DataZoomBorderWidth; } } + public static float dataZoomDataLineWidth { get { return Instance.m_DataZoomDataLineWidth; } } + public static float visualMapBorderWidth { get { return Instance.m_VisualMapBorderWidth; } } + + #region serie + public static float serieLineWidth { get { return Instance.m_SerieLineWidth; } } + public static float serieLineSymbolSize { get { return Instance.m_SerieLineSymbolSize; } } + public static float serieLineSymbolSelectedSize { get { return Instance.m_SerieLineSymbolSelectedSize; } } + public static float serieScatterSymbolSize { get { return Instance.m_SerieScatterSymbolSize; } } + public static float serieScatterSymbolSelectedSize { get { return Instance.m_SerieScatterSymbolSelectedSize; } } + #endregion + + #region editor + public static bool editorBlockEnable { get { return Instance.m_EditorBlockEnable; } } + #endregion + + #region graphic + public static int maxPainter { get { return Instance.m_MaxPainter; } } + public static float lineSmoothStyle { get { return Instance.m_LineSmoothStyle; } } + public static float lineSmoothness { get { return Instance.m_LineSmoothness; } } + public static float lineSegmentDistance { get { return Instance.m_LineSegmentDistance; } } + public static float cicleSmoothness { get { return Instance.m_CicleSmoothness; } } + public static float visualMapTriangeLen { get { return Instance.m_VisualMapTriangeLen; } } + public static float pieTooltipExtraRadius { get { return Instance.m_PieTooltipExtraRadius; } } + public static float pieSelectedOffset { get { return Instance.m_PieSelectedOffset; } } + #endregion + + + private static XChartsSettings s_Instance; + public static XChartsSettings Instance + { + get + { + if (s_Instance == null) + { + s_Instance = Resources.Load<XChartsSettings>("XChartsSettings"); +#if UNITY_EDITOR + if (s_Instance == null) + { + XChartsPackageResourceImporterWindow.ShowPackageImporterWindow(); + } + else + { + if (s_Instance.m_Font == null) + s_Instance.m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"); +#if dUI_TextMeshPro + if (s_Instance.m_TMPFont == null) + s_Instance.m_TMPFont = Resources.Load<TMP_FontAsset>("LiberationSans SDF"); +#endif + } +#endif + } + + return s_Instance; + } + } + } +} \ No newline at end of file diff --git a/Runtime/XChartsSettings.cs.meta b/Runtime/XChartsSettings.cs.meta new file mode 100644 index 00000000..4fc72f20 --- /dev/null +++ b/Runtime/XChartsSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3694d869548264b718bdfc6c8009dcf1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL.meta b/Runtime/XUGL.meta new file mode 100644 index 00000000..53b2bee4 --- /dev/null +++ b/Runtime/XUGL.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c4fe06f67e9674b808b44154ab0e5fc3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs new file mode 100644 index 00000000..84935c94 --- /dev/null +++ b/Runtime/XUGL/UGL.cs @@ -0,0 +1,1505 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace XUGL +{ + /// <summary> + /// UGUI Graphics Library. + /// UGUI 图形库 + /// </summary> + public static class UGL + { + private static readonly Color32 s_ClearColor32 = new Color32(0, 0, 0, 0); + private static readonly Vector2 s_ZeroVector2 = Vector2.zero; + private static UIVertex[] s_Vertex = new UIVertex[4]; + private static List<Vector3> s_CurvesPosList = new List<Vector3>(); + + /// <summary> + /// Draw a arrow. 画箭头 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起始位置</param> + /// <param name="arrowPoint">箭头位置</param> + /// <param name="width">箭头宽</param> + /// <param name="height">箭头长</param> + /// <param name="offset">相对箭头位置的偏移</param> + /// <param name="dent">箭头凹度</param> + /// <param name="color">颜色</param> + public static void DrawArrow(VertexHelper vh, Vector3 startPoint, Vector3 arrowPoint, float width, + float height, float offset, float dent, Color32 color) + { + var dir = (arrowPoint - startPoint).normalized; + + var sharpPos = arrowPoint + (offset + height / 2) * dir; + var middle = sharpPos + (dent - height) * dir; + var diff = Vector3.Cross(dir, Vector3.forward).normalized * width / 2; + var left = sharpPos - height * dir + diff; + var right = sharpPos - height * dir - diff; + DrawTriangle(vh, middle, sharpPos, left, color); + DrawTriangle(vh, middle, sharpPos, right, color); + } + + /// <summary> + /// Draw a line. 画直线 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起点</param> + /// <param name="endPoint">终点</param> + /// <param name="width">线宽</param> + /// <param name="color">颜色</param> + public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, Color32 color) + { + if (startPoint == endPoint) return; + Vector3 v = Vector3.Cross(endPoint - startPoint, Vector3.forward).normalized * width; + s_Vertex[0].position = startPoint - v; + s_Vertex[1].position = endPoint - v; + s_Vertex[2].position = endPoint + v; + s_Vertex[3].position = startPoint + v; + + for (int j = 0; j < 4; j++) + { + s_Vertex[j].color = color; + s_Vertex[j].uv0 = s_ZeroVector2; + } + vh.AddUIVertexQuad(s_Vertex); + } + + /// <summary> + /// Draw a line defined by three points. 画一条由3个点确定的折线 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起始点</param> + /// <param name="middlePoint">中间转折点</param> + /// <param name="endPoint">终点</param> + /// <param name="width">线宽</param> + /// <param name="color">颜色</param> + public static void DrawLine(VertexHelper vh, Vector3 startPoint, Vector3 middlePoint, Vector3 endPoint, + float width, Color32 color) + { + var dir1 = (middlePoint - startPoint).normalized; + var dir2 = (endPoint - middlePoint).normalized; + var dir1v = Vector3.Cross(dir1, Vector3.forward).normalized; + var dir2v = Vector3.Cross(dir2, Vector3.forward).normalized; + var dir3 = (dir1 + dir2).normalized; + var isDown = Vector3.Cross(dir1, dir2).z <= 0; + var angle = (180 - Vector3.Angle(dir1, dir2)) * Mathf.Deg2Rad / 2; + var diff = width / Mathf.Sin(angle); + var dirDp = Vector3.Cross(dir3, Vector3.forward).normalized; + var dnPos = middlePoint + (isDown ? dirDp : -dirDp) * diff; + var upPos1 = middlePoint + (isDown ? -dir1v : dir1v) * width; + var upPos2 = middlePoint + (isDown ? -dir2v : dir2v) * width; + var startUp = startPoint - dir1v * width; + var startDn = startPoint + dir1v * width; + var endUp = endPoint - dir2v * width; + var endDn = endPoint + dir2v * width; + if (isDown) + { + DrawQuadrilateral(vh, startDn, startUp, upPos1, dnPos, color); + DrawQuadrilateral(vh, dnPos, upPos2, endUp, endDn, color); + DrawTriangle(vh, dnPos, upPos1, upPos2, color); + } + else + { + DrawQuadrilateral(vh, startDn, startUp, dnPos, upPos1, color); + DrawQuadrilateral(vh, upPos2, dnPos, endUp, endDn, color); + DrawTriangle(vh, dnPos, upPos1, upPos2, color); + } + } + /// <summary> + /// Draw a dash line. 画虚线 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起始点</param> + /// <param name="endPoint">结束点</param> + /// <param name="width">线宽</param> + /// <param name="color">颜色</param> + /// <param name="lineLength">实线部分长度,默认为线宽的12倍</param> + /// <param name="gapLength">间隙部分长度,默认为线宽的3倍</param> + /// <param name="posList">可选,输出的关键点</param> + public static void DrawDashLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, + Color32 color, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null) + { + float dist = Vector3.Distance(startPoint, endPoint); + if (dist < 0.1f) return; + if (lineLength == 0) lineLength = 12 * width; + if (gapLength == 0) gapLength = 3 * width; + int segment = Mathf.CeilToInt(dist / (lineLength + gapLength)); + Vector3 dir = (endPoint - startPoint).normalized; + Vector3 sp = startPoint, np; + if (posList != null) posList.Clear(); + for (int i = 1; i <= segment; i++) + { + if (posList != null) posList.Add(sp); + np = startPoint + dir * dist * i / segment; + var dashep = np - dir * gapLength; + DrawLine(vh, sp, dashep, width, color); + sp = np; + } + if (posList != null) posList.Add(endPoint); + DrawLine(vh, sp, endPoint, width, color); + } + + /// <summary> + /// Draw a dot line. 画点线 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起始点</param> + /// <param name="endPoint">结束点</param> + /// <param name="width">线宽</param> + /// <param name="color">颜色</param> + /// <param name="lineLength">实线部分长度,默认为线宽的3倍</param> + /// <param name="gapLength">间隙部分长度,默认为线宽的3倍</param> + /// <param name="posList">可选,输出的关键点</param> + public static void DrawDotLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, + Color32 color, float lineLength = 0f, float gapLength = 0f, List<Vector3> posList = null) + { + float dist = Vector3.Distance(startPoint, endPoint); + if (dist < 0.1f) return; + if (lineLength == 0) lineLength = 3 * width; + if (gapLength == 0) gapLength = 3 * width; + int segment = Mathf.CeilToInt(dist / (lineLength + gapLength)); + Vector3 dir = (endPoint - startPoint).normalized; + Vector3 sp = startPoint, np; + if (posList != null) posList.Clear(); + for (int i = 1; i <= segment; i++) + { + if (posList != null) posList.Add(sp); + np = startPoint + dir * dist * i / segment; + var dashep = np - dir * gapLength; + DrawLine(vh, sp, dashep, width, color); + sp = np; + } + if (posList != null) posList.Add(endPoint); + DrawLine(vh, sp, endPoint, width, color); + } + + /// <summary> + /// Draw a dash-dot line. 画点划线 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起始点</param> + /// <param name="endPoint">结束点</param> + /// <param name="width">线宽</param> + /// <param name="color">颜色</param> + /// <param name="dashLength">划线长,默认15倍线宽</param> + /// <param name="dotLength">点线长,默认3倍线宽</param> + /// <param name="gapLength">间隙长,默认5倍线宽</param> + /// <param name="posList">可选,输出的关键点</param> + public static void DrawDashDotLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, + Color32 color, float dashLength = 0f, float dotLength = 0, float gapLength = 0f, + List<Vector3> posList = null) + { + float dist = Vector3.Distance(startPoint, endPoint); + if (dist < 0.1f) return; + if (dashLength == 0) dashLength = 15 * width; + if (dotLength == 0) dotLength = 3 * width; + if (gapLength == 0) gapLength = 5 * width; + int segment = Mathf.CeilToInt(dist / (dashLength + 2 * gapLength + dotLength)); + Vector3 dir = (endPoint - startPoint).normalized; + Vector3 sp = startPoint, np; + if (posList != null) posList.Clear(); + for (int i = 1; i <= segment; i++) + { + if (posList != null) posList.Add(sp); + np = startPoint + dir * dist * i / segment; + var dashep = np - dir * (2 * gapLength + dotLength); + DrawLine(vh, sp, dashep, width, color); + if (posList != null) posList.Add(dashep); + var dotsp = dashep + gapLength * dir; + var dotep = dotsp + dotLength * dir; + DrawLine(vh, dotsp, dotep, width, color); + if (posList != null) posList.Add(dotsp); + sp = np; + } + if (posList != null) posList.Add(endPoint); + DrawLine(vh, sp, endPoint, width, color); + } + + /// <summary> + /// Draw a dash-dot-dot line. 画双点划线 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起始点</param> + /// <param name="endPoint">结束点</param> + /// <param name="width">线宽</param> + /// <param name="color">颜色</param> + /// <param name="dashLength">折线长,默认15倍线宽</param> + /// <param name="dotLength">点线长,默认3倍线宽</param> + /// <param name="gapLength">间隙长,默认5倍线宽</param> + /// <param name="posList">可选,输出的关键点</param> + public static void DrawDashDotDotLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, + Color32 color, float dashLength = 0f, float dotLength = 0f, float gapLength = 0f, + List<Vector3> posList = null) + { + float dist = Vector3.Distance(startPoint, endPoint); + if (dist < 0.1f) return; + if (dashLength == 0) dashLength = 15 * width; + if (dotLength == 0) dotLength = 3 * width; + if (gapLength == 0) gapLength = 5 * width; + int segment = Mathf.CeilToInt(dist / (dashLength + 3 * gapLength + 2 * dotLength)); + Vector3 dir = (endPoint - startPoint).normalized; + Vector3 sp = startPoint, np; + if (posList != null) posList.Clear(); + for (int i = 1; i <= segment; i++) + { + if (posList != null) posList.Add(sp); + np = startPoint + dir * dist * i / segment; + var dashep = np - dir * (3 * gapLength + 2 * dotLength); + DrawLine(vh, sp, dashep, width, color); + if (posList != null) posList.Add(dashep); + var dotsp = dashep + gapLength * dir; + var dotep = dotsp + dotLength * dir; + DrawLine(vh, dotsp, dotep, width, color); + if (posList != null) posList.Add(dotep); + var dotsp2 = dotep + gapLength * dir; + var dotep2 = dotsp2 + dotLength * dir; + DrawLine(vh, dotsp2, dotep2, width, color); + if (posList != null) posList.Add(dotep2); + sp = np; + } + if (posList != null) posList.Add(endPoint); + DrawLine(vh, sp, endPoint, width, color); + } + + /// <summary> + /// Draw a zebar-line. 画斑马线 + /// </summary> + /// <param name="vh"></param> + /// <param name="startPoint">起始点</param> + /// <param name="endPoint">结束点</param> + /// <param name="width">线宽</param> + /// <param name="zebraWidth">斑马条纹宽</param> + /// <param name="zebraGap">间隙宽</param> + /// <param name="color">颜色</param> + public static void DrawZebraLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, + float zebraWidth, float zebraGap, Color32 color) + { + DrawDotLine(vh, startPoint, endPoint, width, color, zebraWidth, zebraGap); + } + + /// <summary> + /// Draw a diamond. 画菱形(钻石形状) + /// </summary> + /// <param name="vh"></param> + /// <param name="center">中心点</param> + /// <param name="size">尺寸</param> + /// <param name="color">颜色</param> + public static void DrawDiamond(VertexHelper vh, Vector3 center, float size, Color32 color) + { + DrawDiamond(vh, center, size, color, color); + } + + /// <summary> + /// Draw a diamond. 画菱形(钻石形状) + /// </summary> + /// <param name="vh"></param> + /// <param name="center">中心点</param> + /// <param name="size">尺寸</param> + /// <param name="color">渐变色1</param> + /// <param name="toColor">渐变色2</param> + public static void DrawDiamond(VertexHelper vh, Vector3 center, float size, Color32 color, Color32 toColor) + { + var p1 = new Vector2(center.x - size, center.y); + var p2 = new Vector2(center.x, center.y + size); + var p3 = new Vector2(center.x + size, center.y); + var p4 = new Vector2(center.x, center.y - size); + DrawTriangle(vh, p4, p1, p2, color, color, toColor); + DrawTriangle(vh, p3, p4, p2, color, color, toColor); + } + + /// <summary> + /// Draw a square. 画正方形 + /// </summary> + /// <param name="center">中心点</param> + /// <param name="radius">半径</param> + /// <param name="color">颜色</param> + public static void DrawSquare(VertexHelper vh, Vector3 center, float radius, Color32 color) + { + DrawSquare(vh, center, radius, color, color, true); + } + + /// <summary> + /// Draw a square. 画带渐变的正方形 + /// </summary> + /// <param name="vh"></param> + /// <param name="center">中心点</param> + /// <param name="radius">半径</param> + /// <param name="color">渐变色1</param> + /// <param name="toColor">渐变色2</param> + /// <param name="vertical">渐变是否为垂直方向</param> + public static void DrawSquare(VertexHelper vh, Vector3 center, float radius, Color32 color, + Color32 toColor, bool vertical = true) + { + Vector3 p1, p2, p3, p4; + if (vertical) + { + p1 = new Vector3(center.x + radius, center.y - radius); + p2 = new Vector3(center.x - radius, center.y - radius); + p3 = new Vector3(center.x - radius, center.y + radius); + p4 = new Vector3(center.x + radius, center.y + radius); + } + else + { + p1 = new Vector3(center.x - radius, center.y - radius); + p2 = new Vector3(center.x - radius, center.y + radius); + p3 = new Vector3(center.x + radius, center.y + radius); + p4 = new Vector3(center.x + radius, center.y - radius); + } + DrawQuadrilateral(vh, p1, p2, p3, p4, color, toColor); + } + + /// <summary> + /// Draw a rectangle. 画带长方形 + /// </summary> + /// <param name="p1">起始点</param> + /// <param name="p2">结束点</param> + /// <param name="radius">半径</param> + /// <param name="color">颜色</param> + public static void DrawRectangle(VertexHelper vh, Vector3 p1, Vector3 p2, float radius, Color32 color) + { + DrawRectangle(vh, p1, p2, radius, color, color); + } + + /// <summary> + /// Draw a rectangle. 画带渐变的长方形 + /// </summary> + /// <param name="vh"></param> + /// <param name="p1">起始点</param> + /// <param name="p2">结束点</param> + /// <param name="radius">半径</param> + /// <param name="color">渐变色1</param> + /// <param name="toColor">渐变色2</param> + public static void DrawRectangle(VertexHelper vh, Vector3 p1, Vector3 p2, float radius, Color32 color, + Color32 toColor) + { + var dir = (p2 - p1).normalized; + var dirv = Vector3.Cross(dir, Vector3.forward).normalized; + + var p3 = p1 + dirv * radius; + var p4 = p1 - dirv * radius; + var p5 = p2 - dirv * radius; + var p6 = p2 + dirv * radius; + DrawQuadrilateral(vh, p3, p4, p5, p6, color, toColor); + } + + /// <summary> + /// Draw a rectangle. 画长方形 + /// </summary> + /// <param name="vh"></param> + /// <param name="p">中心点</param> + /// <param name="xRadius">x宽</param> + /// <param name="yRadius">y宽</param> + /// <param name="color">颜色</param> + /// <param name="vertical">是否垂直方向</param> + public static void DrawRectangle(VertexHelper vh, Vector3 p, float xRadius, float yRadius, + Color32 color, bool vertical = true) + { + DrawRectangle(vh, p, xRadius, yRadius, color, color, vertical); + } + + /// <summary> + /// Draw a rectangle. 画带渐变的长方形 + /// </summary> + /// <param name="vh"></param> + /// <param name="p">中心点</param> + /// <param name="xRadius">x宽</param> + /// <param name="yRadius">y宽</param> + /// <param name="color">渐变色1</param> + /// <param name="toColor">渐变色2</param> + /// <param name="vertical">是否垂直方向</param> + public static void DrawRectangle(VertexHelper vh, Vector3 p, float xRadius, float yRadius, + Color32 color, Color32 toColor, bool vertical = true) + { + Vector3 p1, p2, p3, p4; + if (vertical) + { + p1 = new Vector3(p.x + xRadius, p.y - yRadius); + p2 = new Vector3(p.x - xRadius, p.y - yRadius); + p3 = new Vector3(p.x - xRadius, p.y + yRadius); + p4 = new Vector3(p.x + xRadius, p.y + yRadius); + } + else + { + p1 = new Vector3(p.x - xRadius, p.y - yRadius); + p2 = new Vector3(p.x - xRadius, p.y + yRadius); + p3 = new Vector3(p.x + xRadius, p.y + yRadius); + p4 = new Vector3(p.x + xRadius, p.y - yRadius); + } + + DrawQuadrilateral(vh, p1, p2, p3, p4, color, toColor); + } + + /// <summary> + /// Draw a quadrilateral. 画任意的四边形 + /// </summary> + /// <param name="vh"></param> + /// <param name="p1"></param> + /// <param name="p2"></param> + /// <param name="p3"></param> + /// <param name="p4"></param> + /// <param name="color"></param> + public static void DrawQuadrilateral(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, + Color32 color) + { + DrawQuadrilateral(vh, p1, p2, p3, p4, color, color); + } + + /// <summary> + /// Draw a quadrilateral. 画任意带渐变的四边形 + /// </summary> + /// <param name="vh"></param> + /// <param name="p1"></param> + /// <param name="p2"></param> + /// <param name="p3"></param> + /// <param name="p4"></param> + /// <param name="startColor"></param> + /// <param name="toColor"></param> + public static void DrawQuadrilateral(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, + Color32 startColor, Color32 toColor) + { + s_Vertex[0].position = p1; + s_Vertex[1].position = p2; + s_Vertex[2].position = p3; + s_Vertex[3].position = p4; + for (int j = 0; j < 4; j++) + { + s_Vertex[j].color = j >= 2 ? toColor : startColor; + s_Vertex[j].uv0 = s_ZeroVector2; + } + vh.AddUIVertexQuad(s_Vertex); + } + + private static void InitCornerRadius(float[] cornerRadius, float width, float height, bool isYAxis, + ref float brLt, ref float brRt, ref float brRb, ref float brLb, ref bool needRound) + { + if (cornerRadius == null) return; + brLt = cornerRadius.Length > 0 ? cornerRadius[0] : 0; + brRt = cornerRadius.Length > 1 ? cornerRadius[1] : 0; + brRb = cornerRadius.Length > 2 ? cornerRadius[2] : 0; + brLb = cornerRadius.Length > 3 ? cornerRadius[3] : 0; + needRound = brLb != 0 || brRt != 0 || brRb != 0 || brLb != 0; + if (needRound) + { + var min = Mathf.Min(width, height); + if (brLt == 1 && brRt == 1 && brRb == 1 && brLb == 1) + { + brLt = brRt = brRb = brLb = min / 2; + return; + } + if (brLt > 0 && brLt <= 1) brLt = brLt * min; + if (brRt > 0 && brRt <= 1) brRt = brRt * min; + if (brRb > 0 && brRb <= 1) brRb = brRb * min; + if (brLb > 0 && brLb <= 1) brLb = brLb * min; + if (isYAxis) + { + if (brLb + brLt >= height) + { + var total = brLb + brLt; + brLb = height * (brLb / total); + brLt = height * (brLt / total); + } + if (brRt + brRb >= height) + { + var total = brRt + brRb; + brRt = height * (brRt / total); + brRb = height * (brRb / total); + } + if (brLt + brRt >= width) + { + var total = brLt + brRt; + brLt = width * (brLt / total); + brRt = width * (brRt / total); + } + if (brRb + brLb >= width) + { + var total = brRb + brLb; + brRb = width * (brRb / total); + brLb = width * (brLb / total); + } + } + else + { + if (brLt + brRt >= width) + { + var total = brLt + brRt; + brLt = width * (brLt / total); + brRt = width * (brRt / total); + } + if (brRb + brLb >= width) + { + var total = brRb + brLb; + brRb = width * (brRb / total); + brLb = width * (brLb / total); + } + if (brLb + brLt >= height) + { + var total = brLb + brLt; + brLb = height * (brLb / total); + brLt = height * (brLt / total); + } + if (brRt + brRb >= height) + { + var total = brRt + brRb; + brRt = height * (brRt / total); + brRb = height * (brRb / total); + } + } + } + } + + /// <summary> + /// 绘制圆角矩形 + /// </summary> + /// <param name="vh"></param> + /// <param name="center"></param> + /// <param name="rectWidth"></param> + /// <param name="rectHeight"></param> + /// <param name="color"></param> + /// <param name="rotate"></param> + /// <param name="cornerRadius"></param> + public static void DrawRoundRectangle(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, + Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false) + { + var isGradient = !UGLHelper.IsValueEqualsColor(color, toColor); + var halfWid = rectWidth / 2; + var halfHig = rectHeight / 2; + float brLt = 0, brRt = 0, brRb = 0, brLb = 0; + bool needRound = false; + InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb, + ref brLb, ref needRound); + var tempCenter = Vector3.zero; + var lbIn = new Vector3(center.x - halfWid, center.y - halfHig); + var ltIn = new Vector3(center.x - halfWid, center.y + halfHig); + var rtIn = new Vector3(center.x + halfWid, center.y + halfHig); + var rbIn = new Vector3(center.x + halfWid, center.y - halfHig); + if (needRound) + { + var lbIn2 = lbIn; + var ltIn2 = ltIn; + var rtIn2 = rtIn; + var rbIn2 = rbIn; + var roundLb = lbIn; + var roundLt = ltIn; + var roundRt = rtIn; + var roundRb = rbIn; + if (brLt > 0) + { + roundLt = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt); + ltIn = roundLt + brLt * Vector3.left; + ltIn2 = roundLt + brLt * Vector3.up; + } + if (brRt > 0) + { + roundRt = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt); + rtIn = roundRt + brRt * Vector3.up; + rtIn2 = roundRt + brRt * Vector3.right; + } + if (brRb > 0) + { + roundRb = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb); + rbIn = roundRb + brRb * Vector3.right; + rbIn2 = roundRb + brRb * Vector3.down; + } + if (brLb > 0) + { + roundLb = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb); + lbIn = roundLb + brLb * Vector3.left; + lbIn2 = roundLb + brLb * Vector3.down; + } + + if (isYAxis) + { + var maxLeft = Mathf.Max(brLt, brLb); + var maxRight = Mathf.Max(brRt, brRb); + var ltInRight = ltIn + maxLeft * Vector3.right; + var lbInRight = lbIn + maxLeft * Vector3.right; + var rtIn2Left = rtIn2 + maxRight * Vector3.left; + var rbInLeft = rbIn + maxRight * Vector3.left; + + var roundLbRight = roundLb + (maxLeft - brLb) * Vector3.right; + var lbIn2Right = lbIn2 + (maxLeft - brLb) * Vector3.right; + if (roundLbRight.x > roundRb.x) roundLbRight.x = roundRb.x; + if (lbIn2Right.x > roundRb.x) lbIn2Right.x = roundRb.x; + + var ltIn2Right = ltIn2 + (maxLeft - brLt) * Vector3.right; + var roundLtRight = roundLt + (maxLeft - brLt) * Vector3.right; + if (ltIn2Right.x > roundRt.x) ltIn2Right.x = roundRt.x; + if (roundLtRight.x > roundRt.x) roundLtRight.x = roundRt.x; + + var roundRtLeft = roundRt + (maxRight - brRt) * Vector3.left; + var rtInLeft = rtIn + (maxRight - brRt) * Vector3.left; + if (roundRtLeft.x < roundLt.x) roundRtLeft.x = roundLt.x; + if (rtInLeft.x < roundLt.x) rtInLeft.x = roundLt.x; + + var rbIn2Left = rbIn2 + (maxRight - brRb) * Vector3.left; + var roundRbLeft = roundRb + (maxRight - brRb) * Vector3.left; + if (rbIn2Left.x < roundLb.x) rbIn2Left.x = roundLb.x; + if (roundRbLeft.x < roundLb.x) roundRbLeft.x = roundLb.x; + if (!isGradient) + { + DrawSector(vh, roundLt, brLt, color, color, 270, 360, 1, isYAxis); + DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, isYAxis); + DrawSector(vh, roundRb, brRb, toColor, toColor, 90, 180, 1, isYAxis); + DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, isYAxis); + + DrawQuadrilateral(vh, ltIn, ltInRight, lbInRight, lbIn, color, color); + DrawQuadrilateral(vh, lbIn2, roundLb, roundLbRight, lbIn2Right, color, color); + DrawQuadrilateral(vh, roundLt, ltIn2, ltIn2Right, roundLtRight, color, color); + + DrawQuadrilateral(vh, rbInLeft, rtIn2Left, rtIn2, rbIn, toColor, toColor); + DrawQuadrilateral(vh, roundRtLeft, rtInLeft, rtIn, roundRt, toColor, toColor); + DrawQuadrilateral(vh, rbIn2Left, roundRbLeft, roundRb, rbIn2, toColor, toColor); + + var clt = new Vector3(center.x - halfWid + maxLeft, center.y + halfHig); + var crt = new Vector3(center.x + halfWid - maxRight, center.y + halfHig); + var crb = new Vector3(center.x + halfWid - maxRight, center.y - halfHig); + var clb = new Vector3(center.x - halfWid + maxLeft, center.y - halfHig); + if (crt.x > clt.x) + { + DrawQuadrilateral(vh, clb, clt, crt, crb, color, toColor); + } + } + else + { + var tempLeftColor = Color32.Lerp(color, toColor, maxLeft / rectWidth); + var upLeftColor = Color32.Lerp(color, tempLeftColor, brLt / maxLeft); + var downLeftColor = Color32.Lerp(color, tempLeftColor, brLb / maxLeft); + + var tempRightColor = Color32.Lerp(color, toColor, (rectWidth - maxRight) / rectWidth); + var upRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRt) / maxRight); + var downRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRb) / maxRight); + + DrawSector(vh, roundLt, brLt, color, upLeftColor, 270, 360, 1, isYAxis); + DrawSector(vh, roundRt, brRt, upRightColor, toColor, 0, 90, 1, isYAxis); + DrawSector(vh, roundRb, brRb, downRightColor, toColor, 90, 180, 1, isYAxis); + DrawSector(vh, roundLb, brLb, color, downLeftColor, 180, 270, 1, isYAxis); + + DrawQuadrilateral(vh, lbIn, ltIn, ltInRight, lbInRight, color, tempLeftColor); + DrawQuadrilateral(vh, lbIn2, roundLb, roundLbRight, lbIn2Right, downLeftColor, + roundLbRight.x == roundRb.x ? downRightColor : tempLeftColor); + DrawQuadrilateral(vh, roundLt, ltIn2, ltIn2Right, roundLtRight, upLeftColor, + ltIn2Right.x == roundRt.x ? upRightColor : tempLeftColor); + + DrawQuadrilateral(vh, rbInLeft, rtIn2Left, rtIn2, rbIn, tempRightColor, toColor); + DrawQuadrilateral(vh, roundRtLeft, rtInLeft, rtIn, roundRt, + roundRtLeft.x == roundLt.x ? upLeftColor : tempRightColor, upRightColor); + DrawQuadrilateral(vh, rbIn2Left, roundRbLeft, roundRb, rbIn2, + rbIn2Left.x == roundLb.x ? downLeftColor : tempRightColor, downRightColor); + + var clt = new Vector3(center.x - halfWid + maxLeft, center.y + halfHig); + var crt = new Vector3(center.x + halfWid - maxRight, center.y + halfHig); + var crb = new Vector3(center.x + halfWid - maxRight, center.y - halfHig); + var clb = new Vector3(center.x - halfWid + maxLeft, center.y - halfHig); + if (crt.x > clt.x) + { + DrawQuadrilateral(vh, clb, clt, crt, crb, tempLeftColor, tempRightColor); + } + } + } + else + { + var maxup = Mathf.Max(brLt, brRt); + var maxdown = Mathf.Max(brLb, brRb); + var clt = new Vector3(center.x - halfWid, center.y + halfHig - maxup); + var crt = new Vector3(center.x + halfWid, center.y + halfHig - maxup); + var crb = new Vector3(center.x + halfWid, center.y - halfHig + maxdown); + var clb = new Vector3(center.x - halfWid, center.y - halfHig + maxdown); + var lbIn2Up = lbIn2 + maxdown * Vector3.up; + var rbIn2Up = rbIn2 + maxdown * Vector3.up; + var rtInDown = rtIn + maxup * Vector3.down; + var ltIn2Down = ltIn2 + maxup * Vector3.down; + + var roundLtDown = roundLt + (maxup - brLt) * Vector3.down; + var ltInDown = ltIn + (maxup - brLt) * Vector3.down; + if (roundLtDown.y < roundLb.y) roundLtDown.y = roundLb.y; + if (ltInDown.y < roundLb.y) ltInDown.y = roundLb.y; + + var rtIn2Down = rtIn2 + (maxup - brRt) * Vector3.down; + var roundRtDown = roundRt + (maxup - brRt) * Vector3.down; + if (rtIn2Down.y < roundRb.y) rtIn2Down.y = roundRb.y; + if (roundRtDown.y < roundRb.y) roundRtDown.y = roundRb.y; + + var lbInUp = lbIn + (maxdown - brLb) * Vector3.up; + var roundLbUp = roundLb + (maxdown - brLb) * Vector3.up; + if (lbInUp.y > roundLt.y) lbInUp.y = roundLt.y; + if (roundLbUp.y > roundLt.y) roundLbUp.y = roundLt.y; + + var roundRbUp = roundRb + (maxdown - brRb) * Vector3.up; + var rbInUp = rbIn + (maxdown - brRb) * Vector3.up; + if (roundRbUp.y > roundRt.y) roundRbUp.y = roundRt.y; + if (rbInUp.y > roundRt.y) rbInUp.y = roundRt.y; + + if (!isGradient) + { + DrawSector(vh, roundLt, brLt, toColor, toColor, 270, 360, 1, isYAxis); + DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, isYAxis); + DrawSector(vh, roundRb, brRb, color, color, 90, 180, 1, isYAxis); + DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, isYAxis); + + DrawQuadrilateral(vh, ltIn2, rtIn, rtInDown, ltIn2Down, toColor, toColor); + DrawQuadrilateral(vh, ltIn, roundLt, roundLtDown, ltInDown, toColor, toColor); + DrawQuadrilateral(vh, roundRt, rtIn2, rtIn2Down, roundRtDown, toColor, toColor); + + DrawQuadrilateral(vh, lbIn2, lbIn2Up, rbIn2Up, rbIn2, color, color); + DrawQuadrilateral(vh, lbIn, lbInUp, roundLbUp, roundLb, color, color); + DrawQuadrilateral(vh, roundRb, roundRbUp, rbInUp, rbIn, color, color); + if (clt.y > clb.y) + { + DrawQuadrilateral(vh, clt, crt, crb, clb, toColor, color); + } + } + else + { + var tempUpColor = Color32.Lerp(color, toColor, (rectHeight - maxup) / rectHeight); + var leftUpColor = Color32.Lerp(tempUpColor, toColor, (maxup - brLt) / maxup); + var rightUpColor = Color32.Lerp(tempUpColor, toColor, (maxup - brRt) / maxup); + var tempDownColor = Color32.Lerp(color, toColor, maxdown / rectHeight); + var leftDownColor = Color32.Lerp(color, tempDownColor, brLb / maxdown); + var rightDownColor = Color32.Lerp(color, tempDownColor, brRb / maxdown); + + DrawSector(vh, roundLt, brLt, leftUpColor, toColor, 270, 360, 1, isYAxis); + DrawSector(vh, roundRt, brRt, rightUpColor, toColor, 0, 90, 1, isYAxis); + DrawSector(vh, roundRb, brRb, rightDownColor, color, 90, 180, 1, isYAxis); + DrawSector(vh, roundLb, brLb, leftDownColor, color, 180, 270, 1, isYAxis); + + DrawQuadrilateral(vh, ltIn2, rtIn, rtInDown, ltIn2Down, toColor, tempUpColor); + DrawQuadrilateral(vh, ltIn, roundLt, roundLtDown, ltInDown, leftUpColor, + roundLtDown.y == roundLb.y ? leftDownColor : tempUpColor); + DrawQuadrilateral(vh, roundRt, rtIn2, rtIn2Down, roundRtDown, rightUpColor, + rtIn2Down.y == roundRb.y ? rightDownColor : tempUpColor); + + DrawQuadrilateral(vh, rbIn2, lbIn2, lbIn2Up, rbIn2Up, color, tempDownColor); + DrawQuadrilateral(vh, roundLb, lbIn, lbInUp, roundLbUp, leftDownColor, + lbInUp.y == roundLt.y ? leftUpColor : tempDownColor); + DrawQuadrilateral(vh, rbIn, roundRb, roundRbUp, rbInUp, rightDownColor, + roundRbUp.y == roundRt.y ? rightUpColor : tempDownColor); + if (clt.y > clb.y) + { + DrawQuadrilateral(vh, clt, crt, crb, clb, tempUpColor, tempDownColor); + } + } + } + } + else + { + DrawQuadrilateral(vh, lbIn, ltIn, rtIn, rbIn, toColor, color); + } + } + + /// <summary> + /// 绘制(圆角)边框 + /// </summary> + /// <param name="vh"></param> + /// <param name="center"></param> + /// <param name="rectWidth"></param> + /// <param name="rectHeight"></param> + /// <param name="borderWidth"></param> + /// <param name="color"></param> + /// <param name="rotate"></param> + /// <param name="cornerRadius"></param> + public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, + float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false) + { + if (borderWidth == 0 || UGLHelper.IsClearColor(color)) return; + var halfWid = rectWidth / 2; + var halfHig = rectHeight / 2; + var lbIn = new Vector3(center.x - halfWid, center.y - halfHig); + var lbOt = new Vector3(center.x - halfWid - borderWidth, center.y - halfHig - borderWidth); + var ltIn = new Vector3(center.x - halfWid, center.y + halfHig); + var ltOt = new Vector3(center.x - halfWid - borderWidth, center.y + halfHig + borderWidth); + var rtIn = new Vector3(center.x + halfWid, center.y + halfHig); + var rtOt = new Vector3(center.x + halfWid + borderWidth, center.y + halfHig + borderWidth); + var rbIn = new Vector3(center.x + halfWid, center.y - halfHig); + var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth); + float brLt = 0, brRt = 0, brRb = 0, brLb = 0; + bool needRound = false; + InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb, + ref brLb, ref needRound); + var tempCenter = Vector3.zero; + if (needRound) + { + var lbIn2 = lbIn; + var lbOt2 = lbOt; + var ltIn2 = ltIn; + var ltOt2 = ltOt; + var rtIn2 = rtIn; + var rtOt2 = rtOt; + var rbIn2 = rbIn; + var rbOt2 = rbOt; + if (brLt > 0) + { + tempCenter = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt); + DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, color, s_ClearColor32, 270, 360); + ltIn = tempCenter + brLt * Vector3.left; + ltOt = tempCenter + (brLt + borderWidth) * Vector3.left; + ltIn2 = tempCenter + brLt * Vector3.up; + ltOt2 = tempCenter + (brLt + borderWidth) * Vector3.up; + } + if (brRt > 0) + { + tempCenter = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt); + DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, color, s_ClearColor32, 0, 90); + rtIn = tempCenter + brRt * Vector3.up; + rtOt = tempCenter + (brRt + borderWidth) * Vector3.up; + rtIn2 = tempCenter + brRt * Vector3.right; + rtOt2 = tempCenter + (brRt + borderWidth) * Vector3.right; + } + if (brRb > 0) + { + tempCenter = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb); + DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, color, s_ClearColor32, 90, 180); + rbIn = tempCenter + brRb * Vector3.right; + rbOt = tempCenter + (brRb + borderWidth) * Vector3.right; + rbIn2 = tempCenter + brRb * Vector3.down; + rbOt2 = tempCenter + (brRb + borderWidth) * Vector3.down; + } + if (brLb > 0) + { + tempCenter = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb); + DrawDoughnut(vh, tempCenter, brLb, brLb + borderWidth, color, s_ClearColor32, 180, 270); + lbIn = tempCenter + brLb * Vector3.left; + lbOt = tempCenter + (brLb + borderWidth) * Vector3.left; + lbIn2 = tempCenter + brLb * Vector3.down; + lbOt2 = tempCenter + (brLb + borderWidth) * Vector3.down; + } + DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color); + DrawQuadrilateral(vh, ltIn2, ltOt2, rtOt, rtIn, color); + DrawQuadrilateral(vh, rtIn2, rtOt2, rbOt, rbIn, color); + DrawQuadrilateral(vh, rbIn2, rbOt2, lbOt2, lbIn2, color); + } + else + { + if (rotate > 0) + { + lbIn = UGLHelper.RotateRound(lbIn, center, Vector3.forward, rotate); + lbOt = UGLHelper.RotateRound(lbOt, center, Vector3.forward, rotate); + ltIn = UGLHelper.RotateRound(ltIn, center, Vector3.forward, rotate); + ltOt = UGLHelper.RotateRound(ltOt, center, Vector3.forward, rotate); + rtIn = UGLHelper.RotateRound(rtIn, center, Vector3.forward, rotate); + rtOt = UGLHelper.RotateRound(rtOt, center, Vector3.forward, rotate); + rbIn = UGLHelper.RotateRound(rbIn, center, Vector3.forward, rotate); + rbOt = UGLHelper.RotateRound(rbOt, center, Vector3.forward, rotate); + } + DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color); + DrawQuadrilateral(vh, ltIn, ltOt, rtOt, rtIn, color); + DrawQuadrilateral(vh, rtIn, rtOt, rbOt, rbIn, color); + DrawQuadrilateral(vh, rbIn, rbOt, lbOt, lbIn, color); + } + } + + public static void DrawTriangle(VertexHelper vh, Vector3 p1, + Vector3 p2, Vector3 p3, Color32 color) + { + DrawTriangle(vh, p1, p2, p3, color, color, color); + } + + public static void DrawTriangle(VertexHelper vh, Vector3 pos, float size, Color32 color) + { + DrawTriangle(vh, pos, size, color, color); + } + + public static void DrawTriangle(VertexHelper vh, Vector3 pos, float size, Color32 color, Color32 toColor) + { + var x = size * Mathf.Cos(30 * Mathf.PI / 180); + var y = size * Mathf.Sin(30 * Mathf.PI / 180); + var p1 = new Vector2(pos.x - x, pos.y - y); + var p2 = new Vector2(pos.x, pos.y + size); + var p3 = new Vector2(pos.x + x, pos.y - y); + DrawTriangle(vh, p1, p2, p3, color, toColor, color); + } + + public static void DrawTriangle(VertexHelper vh, Vector3 p1, + Vector3 p2, Vector3 p3, Color32 color, Color32 color2, Color32 color3) + { + UIVertex v1 = new UIVertex(); + v1.position = p1; + v1.color = color; + v1.uv0 = s_ZeroVector2; + UIVertex v2 = new UIVertex(); + v2.position = p2; + v2.color = color2; + v2.uv0 = s_ZeroVector2; + UIVertex v3 = new UIVertex(); + v3.position = p3; + v3.color = color3; + v3.uv0 = s_ZeroVector2; + int startIndex = vh.currentVertCount; + vh.AddVert(v1); + vh.AddVert(v2); + vh.AddVert(v3); + vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2); + } + + public static void DrawCricle(VertexHelper vh, Vector3 center, float radius, Color32 color, + float smoothness = 2f) + { + DrawCricle(vh, center, radius, color, color, 0, s_ClearColor32, smoothness); + } + + public static void DrawCricle(VertexHelper vh, Vector3 center, float radius, Color32 color, + Color32 toColor, float smoothness = 2f) + { + DrawSector(vh, center, radius, color, toColor, 0, 360, 0, s_ClearColor32, smoothness); + } + + public static void DrawCricle(VertexHelper vh, Vector3 center, float radius, Color32 color, + Color32 toColor, float borderWidth, Color32 borderColor, float smoothness = 2f) + { + DrawSector(vh, center, radius, color, toColor, 0, 360, borderWidth, borderColor, smoothness); + } + + public static void DrawCricle(VertexHelper vh, Vector3 center, float radius, Color32 color, + float borderWidth, Color32 borderColor, float smoothness = 2f) + { + DrawCricle(vh, center, radius, color, color, borderWidth, borderColor, smoothness); + } + + public static void DrawEmptyCricle(VertexHelper vh, Vector3 center, float radius, float tickness, + Color32 color, Color32 emptyColor, float smoothness = 2f) + { + DrawDoughnut(vh, center, radius - tickness, radius, color, color, emptyColor, 0, 360, 0, s_ClearColor32, + 0, smoothness); + } + + public static void DrawEmptyCricle(VertexHelper vh, Vector3 center, float radius, float tickness, + Color32 color, Color32 emptyColor, float borderWidth, Color32 borderColor, float smoothness = 2f) + { + DrawDoughnut(vh, center, radius - tickness, radius, color, color, emptyColor, 0, 360, borderWidth, + borderColor, 0, smoothness); + } + + public static void DrawEmptyCricle(VertexHelper vh, Vector3 center, float radius, float tickness, + Color32 color, Color32 toColor, Color32 emptyColor, float smoothness = 2f) + { + DrawDoughnut(vh, center, radius - tickness, radius, color, toColor, emptyColor, 0, 360, 0, + s_ClearColor32, 0, smoothness); + } + + public static void DrawEmptyCricle(VertexHelper vh, Vector3 center, float radius, float tickness, + Color32 color, Color32 toColor, Color32 emptyColor, float borderWidth, Color32 borderColor, + float smoothness = 2f) + { + DrawDoughnut(vh, center, radius - tickness, radius, color, toColor, emptyColor, 0, 360, borderWidth, + borderColor, 0, smoothness); + } + + public static void DrawSector(VertexHelper vh, Vector3 center, float radius, Color32 color, + float startDegree, float toDegree, float smoothness = 2f) + { + DrawSector(vh, center, radius, color, color, startDegree, toDegree, 0, s_ClearColor32, smoothness); + } + + public static void DrawSector(VertexHelper vh, Vector3 center, float radius, Color32 color, Color32 toColor, + float startDegree, float toDegree, int gradientType = 0, bool isYAxis = false, float smoothness = 2f) + { + DrawSector(vh, center, radius, color, toColor, startDegree, toDegree, 0, s_ClearColor32, 0, smoothness, + gradientType, isYAxis); + } + + public static void DrawSector(VertexHelper vh, Vector3 center, float radius, Color32 color, + float startDegree, float toDegree, float borderWidth, Color32 borderColor, float smoothness = 2f) + { + DrawSector(vh, center, radius, color, color, startDegree, toDegree, borderWidth, borderColor, smoothness); + } + + public static void DrawSector(VertexHelper vh, Vector3 center, float radius, Color32 color, Color32 toColor, + float startDegree, float toDegree, float borderWidth, Color32 borderColor, float smoothness = 2f) + { + DrawSector(vh, center, radius, color, toColor, startDegree, toDegree, borderWidth, borderColor, 0, smoothness); + } + + /// <summary> + /// 绘制扇形(可带边框、有空白边距、3种类型渐变) + /// </summary> + /// <param name="vh"></param> + /// <param name="center">中心点</param> + /// <param name="radius">半径</param> + /// <param name="color">颜色</param> + /// <param name="toColor">渐变颜色</param> + /// <param name="startDegree">开始角度</param> + /// <param name="toDegree">结束角度</param> + /// <param name="borderWidth">边框宽度</param> + /// <param name="borderColor">边框颜色</param> + /// <param name="space">边距</param> + /// <param name="smoothness">光滑度</param> + /// <param name="gradientType">渐变类型,0:向圆形渐变,1:水平或垂直渐变,2:开始角度向结束角度渐变</param> + /// <param name="isYAxis">水平渐变还是垂直渐变,gradientType为1时生效</param> + public static void DrawSector(VertexHelper vh, Vector3 center, float radius, Color32 color, Color32 toColor, + float startDegree, float toDegree, float borderWidth, Color32 borderColor, float space, + float smoothness, int gradientType = 0, bool isYAxis = false) + { + if (radius == 0) return; + if (space > 0 && Mathf.Abs(toDegree - startDegree) >= 360) space = 0; + radius -= borderWidth; + smoothness = (smoothness < 0 ? 2f : smoothness); + int segments = (int)((2 * Mathf.PI * radius) * (Mathf.Abs(toDegree - startDegree) / 360) / smoothness); + if (segments < 1) segments = 1; + float startAngle = startDegree * Mathf.Deg2Rad; + float toAngle = toDegree * Mathf.Deg2Rad; + float realStartAngle = startAngle; + float realToAngle = toAngle; + float halfAngle = (toAngle - startAngle) / 2; + float borderAngle = 0; + float spaceAngle = 0; + + var p2 = center + radius * UGLHelper.GetDire(startAngle); + var p3 = Vector3.zero; + var p4 = Vector3.zero; + var spaceCenter = center; + var realCenter = center; + var lastP4 = center; + var lastColor = color; + var needBorder = borderWidth != 0; + var needSpace = space != 0; + var borderLineWidth = needSpace ? borderWidth : borderWidth / 2; + var lastPos = Vector3.zero; + var middleDire = UGLHelper.GetDire(startAngle + halfAngle); + if (needBorder || needSpace) + { + float spaceDiff = 0f; + float borderDiff = 0f; + if (needSpace) + { + spaceDiff = space / Mathf.Sin(halfAngle); + spaceCenter = center + spaceDiff * middleDire; + realCenter = spaceCenter; + spaceAngle = 2 * Mathf.Asin(space / (2 * radius)); + realStartAngle = startAngle + spaceAngle; + realToAngle = toAngle - spaceAngle; + if (realToAngle < realStartAngle) realToAngle = realStartAngle; + p2 = UGLHelper.GetPos(center, radius, realStartAngle); + } + if (needBorder) + { + borderDiff = borderLineWidth / Mathf.Sin(halfAngle); + realCenter += borderDiff * middleDire; + borderAngle = 2 * Mathf.Asin(borderLineWidth / (2 * radius)); + realStartAngle = realStartAngle + borderAngle; + realToAngle = realToAngle - borderAngle; + if (realToAngle < realStartAngle) + { + realToAngle = realStartAngle; + p2 = UGLHelper.GetPos(center, radius, realStartAngle); + } + else + { + var borderX1 = UGLHelper.GetPos(center, radius, realStartAngle); + DrawQuadrilateral(vh, realCenter, spaceCenter, p2, borderX1, borderColor); + p2 = borderX1; + + var borderX2 = UGLHelper.GetPos(center, radius, realToAngle); + var pEnd = UGLHelper.GetPos(center, radius, toAngle - spaceAngle); + DrawQuadrilateral(vh, realCenter, borderX2, pEnd, spaceCenter, borderColor); + } + } + } + float segmentAngle = (realToAngle - realStartAngle) / segments; + bool isLeft = startDegree >= 180; + for (int i = 0; i <= segments; i++) + { + float currAngle = realStartAngle + i * segmentAngle; + p3 = center + radius * UGLHelper.GetDire(currAngle); + if (gradientType == 1) + { + if (isYAxis) + { + p4 = new Vector3(p3.x, realCenter.y); + var dist = p4.x - realCenter.x; + var tcolor = Color32.Lerp(color, toColor, dist >= 0 + ? dist / radius + : Mathf.Min(radius + dist, radius) / radius); + if (isLeft && (i == segments || i == 0)) tcolor = toColor; + DrawQuadrilateral(vh, lastP4, p2, p3, p4, lastColor, tcolor); + lastP4 = p4; + lastColor = tcolor; + } + else + { + p4 = new Vector3(realCenter.x, p3.y); + var tcolor = Color32.Lerp(color, toColor, Mathf.Abs(p4.y - realCenter.y) / radius); + DrawQuadrilateral(vh, lastP4, p2, p3, p4, lastColor, tcolor); + lastP4 = p4; + lastColor = tcolor; + } + } + else if (gradientType == 2) + { + var tcolor = Color32.Lerp(color, toColor, i / segments); + DrawQuadrilateral(vh, realCenter, p2, p3, realCenter, lastColor, tcolor); + lastColor = tcolor; + } + else + { + DrawTriangle(vh, realCenter, p2, p3, toColor, color, color); + } + p2 = p3; + + } + if (needBorder || needSpace) + { + if (realToAngle > realStartAngle) + { + var borderX2 = center + radius * UGLHelper.GetDire(realToAngle); + DrawTriangle(vh, realCenter, p2, borderX2, toColor, color, color); + if (needBorder) + { + var realStartDegree = (realStartAngle - borderAngle) * Mathf.Rad2Deg; + var realToDegree = (realToAngle + borderAngle) * Mathf.Rad2Deg; + DrawDoughnut(vh, center, radius, radius + borderWidth, borderColor, s_ClearColor32, + realStartDegree, realToDegree, smoothness); + } + } + } + } + + public static void DrawRoundCap(VertexHelper vh, Vector3 center, float width, float radius, float angle, + bool clockwise, Color32 color, bool end) + { + var px = Mathf.Sin(angle * Mathf.Deg2Rad) * radius; + var py = Mathf.Cos(angle * Mathf.Deg2Rad) * radius; + var pos = new Vector3(px, py) + center; + if (end) + { + if (clockwise) + DrawSector(vh, pos, width, color, angle, angle + 180, 0, s_ClearColor32); + else + DrawSector(vh, pos, width, color, angle, angle - 180, 0, s_ClearColor32); + } + else + { + if (clockwise) + DrawSector(vh, pos, width, color, angle + 180, angle + 360, 0, s_ClearColor32); + else + DrawSector(vh, pos, width, color, angle - 180, angle - 360, 0, s_ClearColor32); + } + } + + public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, + Color32 color, Color32 emptyColor, float smoothness = 2f) + { + DrawDoughnut(vh, center, insideRadius, outsideRadius, color, color, emptyColor, 0, 360, 0, + s_ClearColor32, 0, smoothness); + } + + public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, + Color32 color, Color32 emptyColor, float startDegree, + float toDegree, float smoothness = 2f) + { + DrawDoughnut(vh, center, insideRadius, outsideRadius, color, color, emptyColor, startDegree, toDegree, + 0, s_ClearColor32, 0, smoothness); + } + + public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, + Color32 color, Color32 emptyColor, float startDegree, + float toDegree, float borderWidth, Color32 borderColor, float smoothness = 2f) + { + DrawDoughnut(vh, center, insideRadius, outsideRadius, color, color, emptyColor, startDegree, toDegree, + borderWidth, borderColor, 0, smoothness); + } + + public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, + Color32 color, Color32 toColor, Color32 emptyColor, float smoothness = 2f) + { + DrawDoughnut(vh, center, insideRadius, outsideRadius, color, toColor, emptyColor, 0, 360, 0, + s_ClearColor32, 0, smoothness); + } + + public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, + Color32 color, Color32 toColor, Color32 emptyColor, float startDegree, float toDegree, float borderWidth, + Color32 borderColor, float space, float smoothness, bool roundCap = false, bool clockwise = true) + { + if (toDegree - startDegree == 0) return; + if (space > 0 && Mathf.Abs(toDegree - startDegree) >= 360) space = 0; + if (insideRadius <= 0) + { + DrawSector(vh, center, outsideRadius, color, toColor, startDegree, toDegree, borderWidth, borderColor, + space, smoothness); + return; + } + outsideRadius -= borderWidth; + insideRadius += borderWidth; + smoothness = smoothness < 0 ? 2f : smoothness; + Vector3 p1, p2, p3, p4, e1, e2; + var needBorder = borderWidth != 0; + var needSpace = space != 0; + var diffAngle = Mathf.Abs(toDegree - startDegree) * Mathf.Deg2Rad; + + int segments = (int)((2 * Mathf.PI * outsideRadius) * (diffAngle * Mathf.Rad2Deg / 360) / smoothness); + if (segments < 1) segments = 1; + float startAngle = startDegree * Mathf.Deg2Rad; + float toAngle = toDegree * Mathf.Deg2Rad; + + float realStartOutAngle = startAngle; + float realToOutAngle = toAngle; + float realStartInAngle = startAngle; + float realToInAngle = toAngle; + float halfAngle = (toAngle - startAngle) / 2; + float borderAngle = 0, borderInAngle = 0, borderHalfAngle = 0; + float spaceAngle = 0, spaceInAngle = 0, spaceHalfAngle = 0; + + var spaceCenter = center; + var realCenter = center; + var startDire = new Vector3(Mathf.Sin(startAngle), Mathf.Cos(startAngle)).normalized; + var toDire = new Vector3(Mathf.Sin(toAngle), Mathf.Cos(toAngle)).normalized; + var middleDire = new Vector3(Mathf.Sin(startAngle + halfAngle), Mathf.Cos(startAngle + halfAngle)).normalized; + p1 = center + insideRadius * startDire; + p2 = center + outsideRadius * startDire; + e1 = center + insideRadius * toDire; + e2 = center + outsideRadius * toDire; + if (roundCap) + { + var roundRadius = (outsideRadius - insideRadius) / 2; + var roundAngleRadius = insideRadius + roundRadius; + var roundAngle = Mathf.Atan(roundRadius / roundAngleRadius); + if (diffAngle < 2 * roundAngle) + { + roundCap = false; + } + } + if (needBorder || needSpace) + { + if (needSpace) + { + var spaceDiff = space / Mathf.Sin(halfAngle); + spaceCenter = center + Mathf.Abs(spaceDiff) * middleDire; + realCenter = spaceCenter; + spaceAngle = 2 * Mathf.Asin(space / (2 * outsideRadius)); + spaceInAngle = 2 * Mathf.Asin(space / (2 * insideRadius)); + spaceHalfAngle = 2 * Mathf.Asin(space / (2 * (insideRadius + (outsideRadius - insideRadius) / 2))); + if (clockwise) + { + p1 = UGLHelper.GetPos(center, insideRadius, startAngle + spaceInAngle, false); + e1 = UGLHelper.GetPos(center, insideRadius, toAngle - spaceInAngle, false); + realStartOutAngle = startAngle + spaceAngle; + realToOutAngle = toAngle - spaceAngle; + realStartInAngle = startAngle + spaceInAngle; + realToInAngle = toAngle - spaceInAngle; + } + else + { + p1 = UGLHelper.GetPos(center, insideRadius, startAngle - spaceInAngle, false); + e1 = UGLHelper.GetPos(center, insideRadius, toAngle + spaceInAngle, false); + realStartOutAngle = startAngle - spaceAngle; + realToOutAngle = toAngle + spaceAngle; + realStartInAngle = startAngle - spaceInAngle; + realToOutAngle = toAngle + spaceInAngle; + } + p2 = UGLHelper.GetPos(center, outsideRadius, realStartOutAngle, false); + e2 = UGLHelper.GetPos(center, outsideRadius, realToOutAngle, false); + } + if (needBorder) + { + var borderDiff = borderWidth / Mathf.Sin(halfAngle); + realCenter += Mathf.Abs(borderDiff) * middleDire; + borderAngle = 2 * Mathf.Asin(borderWidth / (2 * outsideRadius)); + borderInAngle = 2 * Mathf.Asin(borderWidth / (2 * insideRadius)); + borderHalfAngle = 2 * Mathf.Asin(borderWidth / (2 * (insideRadius + (outsideRadius - insideRadius) / 2))); + if (clockwise) + { + realStartOutAngle = realStartOutAngle + borderAngle; + realToOutAngle = realToOutAngle - borderAngle; + realStartInAngle = startAngle + spaceInAngle + borderInAngle; + realToInAngle = toAngle - spaceInAngle - borderInAngle; + var newp1 = UGLHelper.GetPos(center, insideRadius, startAngle + spaceInAngle + borderInAngle, false); + var newp2 = UGLHelper.GetPos(center, outsideRadius, realStartOutAngle, false); + if (!roundCap) DrawQuadrilateral(vh, newp2, newp1, p1, p2, borderColor); + p1 = newp1; + p2 = newp2; + if (toAngle - spaceInAngle - 2 * borderInAngle > realStartOutAngle) + { + var newe1 = UGLHelper.GetPos(center, insideRadius, toAngle - spaceInAngle - borderInAngle, false); + var newe2 = UGLHelper.GetPos(center, outsideRadius, realToOutAngle, false); + if (!roundCap) DrawQuadrilateral(vh, newe2, e2, e1, newe1, borderColor); + e1 = newe1; + e2 = newe2; + } + } + else + { + realStartOutAngle = realStartOutAngle - borderAngle; + realToOutAngle = realToOutAngle + borderAngle; + realStartInAngle = startAngle - spaceInAngle - borderInAngle; + realToInAngle = toAngle + spaceInAngle + borderInAngle; + var newp1 = UGLHelper.GetPos(center, insideRadius, startAngle - spaceInAngle - borderInAngle, false); + var newp2 = UGLHelper.GetPos(center, outsideRadius, realStartOutAngle, false); + if (!roundCap) DrawQuadrilateral(vh, newp2, newp1, p1, p2, borderColor); + p1 = newp1; + p2 = newp2; + if (toAngle + spaceInAngle + 2 * borderInAngle < realStartOutAngle) + { + var newe1 = UGLHelper.GetPos(center, insideRadius, toAngle + spaceInAngle + borderInAngle, false); + var newe2 = UGLHelper.GetPos(center, outsideRadius, realToOutAngle, false); + if (!roundCap) DrawQuadrilateral(vh, newe2, e2, e1, newe1, borderColor); + e1 = newe1; + e2 = newe2; + } + } + } + } + if (roundCap) + { + var roundRadius = (outsideRadius - insideRadius) / 2; + var roundAngleRadius = insideRadius + roundRadius; + var roundAngle = Mathf.Atan(roundRadius / roundAngleRadius); + if (clockwise) + { + realStartOutAngle = startAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; + realStartInAngle = startAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; + } + else + { + realStartOutAngle = startAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; + realStartInAngle = startAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; + } + var roundTotalDegree = realStartOutAngle * Mathf.Rad2Deg; + var roundCenter = center + roundAngleRadius * UGLHelper.GetDire(realStartOutAngle); + var sectorStartDegree = clockwise ? roundTotalDegree + 180 : roundTotalDegree; + var sectorToDegree = clockwise ? roundTotalDegree + 360 : roundTotalDegree + 180; + DrawSector(vh, roundCenter, roundRadius, color, sectorStartDegree, sectorToDegree, smoothness / 2); + if (needBorder) + { + DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, + s_ClearColor32, sectorStartDegree, sectorToDegree, smoothness / 2); + } + p1 = UGLHelper.GetPos(center, insideRadius, realStartOutAngle); + p2 = UGLHelper.GetPos(center, outsideRadius, realStartOutAngle); + + if (clockwise) + { + realToOutAngle = toAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; + realToInAngle = toAngle - 2 * spaceHalfAngle - borderHalfAngle - roundAngle; + if (realToOutAngle < realStartOutAngle) realToOutAngle = realStartOutAngle; + } + else + { + realToOutAngle = toAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; + realToInAngle = toAngle + 2 * spaceHalfAngle + borderHalfAngle + roundAngle; + if (realToOutAngle > realStartOutAngle) realToOutAngle = realStartOutAngle; + } + roundTotalDegree = realToOutAngle * Mathf.Rad2Deg; + roundCenter = center + roundAngleRadius * UGLHelper.GetDire(realToOutAngle); + sectorStartDegree = clockwise ? roundTotalDegree : roundTotalDegree + 180; + sectorToDegree = clockwise ? roundTotalDegree + 180 : roundTotalDegree + 360; + DrawSector(vh, roundCenter, roundRadius, toColor, sectorStartDegree, sectorToDegree, smoothness / 2); + if (needBorder) + { + DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, + s_ClearColor32, sectorStartDegree, sectorToDegree, smoothness / 2); + } + e1 = UGLHelper.GetPos(center, insideRadius, realToOutAngle); + e2 = UGLHelper.GetPos(center, outsideRadius, realToOutAngle); + } + var segmentAngle = (realToInAngle - realStartInAngle) / segments; + var isGradient = !UGLHelper.IsValueEqualsColor(color, toColor); + for (int i = 0; i <= segments; i++) + { + float currAngle = realStartInAngle + i * segmentAngle; + p3 = new Vector3(center.x + outsideRadius * Mathf.Sin(currAngle), + center.y + outsideRadius * Mathf.Cos(currAngle)); + p4 = new Vector3(center.x + insideRadius * Mathf.Sin(currAngle), + center.y + insideRadius * Mathf.Cos(currAngle)); + if (!UGLHelper.IsClearColor(emptyColor)) DrawTriangle(vh, center, p1, p4, emptyColor); + if (isGradient) + { + var tcolor = Color32.Lerp(color, toColor, i * 1.0f / segments); + DrawQuadrilateral(vh, p2, p3, p4, p1, tcolor, tcolor); + } + else + { + DrawQuadrilateral(vh, p2, p3, p4, p1, color, color); + } + p1 = p4; + p2 = p3; + } + if (needBorder || needSpace || roundCap) + { + if (clockwise) + { + var isInAngleFixed = toAngle - spaceInAngle - 2 * borderInAngle > realStartOutAngle; + if (isInAngleFixed) DrawQuadrilateral(vh, p2, e2, e1, p1, color, toColor); + else DrawTriangle(vh, p2, e2, p1, color, color, toColor); + if (needBorder) + { + var realStartDegree = (realStartOutAngle - (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; + var realToDegree = (realToOutAngle + (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; + if (realToDegree < realStartOutAngle) realToDegree = realStartOutAngle; + var inStartDegree = roundCap ? realStartDegree : (startAngle + spaceInAngle) * Mathf.Rad2Deg; + var inToDegree = roundCap ? realToDegree : (toAngle - spaceInAngle) * Mathf.Rad2Deg; + if (inToDegree < inStartDegree) inToDegree = inStartDegree; + if (isInAngleFixed) DrawDoughnut(vh, center, insideRadius - borderWidth, insideRadius, borderColor, + s_ClearColor32, inStartDegree, inToDegree, smoothness); + DrawDoughnut(vh, center, outsideRadius, outsideRadius + borderWidth, borderColor, s_ClearColor32, + realStartDegree, realToDegree, smoothness); + } + } + else + { + var isInAngleFixed = toAngle + spaceInAngle + 2 * borderInAngle < realStartOutAngle; + if (isInAngleFixed) DrawQuadrilateral(vh, p2, e2, e1, p1, color, toColor); + else DrawTriangle(vh, p2, e2, p1, color, color, toColor); + if (needBorder) + { + var realStartDegree = (realStartOutAngle + (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; + var realToDegree = (realToOutAngle - (roundCap ? 0 : borderAngle)) * Mathf.Rad2Deg; + var inStartDegree = roundCap ? realStartDegree : (startAngle - spaceInAngle) * Mathf.Rad2Deg; + var inToDegree = roundCap ? realToDegree : (toAngle + spaceInAngle) * Mathf.Rad2Deg; + if (inToDegree > inStartDegree) inToDegree = inStartDegree; + if (isInAngleFixed) + { + DrawDoughnut(vh, center, insideRadius - borderWidth, insideRadius, borderColor, + s_ClearColor32, inStartDegree, inToDegree, smoothness); + } + DrawDoughnut(vh, center, outsideRadius, outsideRadius + borderWidth, borderColor, + s_ClearColor32, realStartDegree, realToDegree, smoothness); + } + } + } + } + + /// <summary> + /// 画贝塞尔曲线 + /// </summary> + /// <param name="vh"></param> + /// <param name="sp">起始点</param> + /// <param name="ep">结束点</param> + /// <param name="cp1">控制点1</param> + /// <param name="cp2">控制点2</param> + /// <param name="lineWidth">曲线宽</param> + /// <param name="lineColor">曲线颜色</param> + public static void DrawCurves(VertexHelper vh, Vector3 sp, Vector3 ep, Vector3 cp1, Vector3 cp2, + float lineWidth, Color32 lineColor, float smoothness) + { + var dist = Vector3.Distance(sp, ep); + var segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness)); + UGLHelper.GetBezierList2(ref s_CurvesPosList, sp, ep, segment, cp1, cp2); + if (s_CurvesPosList.Count > 1) + { + var start = s_CurvesPosList[0]; + var to = Vector3.zero; + var dir = s_CurvesPosList[1] - start; + var diff = Vector3.Cross(dir, Vector3.forward).normalized * lineWidth; + var startUp = start - diff; + var startDn = start + diff; + for (int i = 1; i < s_CurvesPosList.Count; i++) + { + to = s_CurvesPosList[i]; + diff = Vector3.Cross(to - start, Vector3.forward).normalized * lineWidth; + var toUp = to - diff; + var toDn = to + diff; + DrawQuadrilateral(vh, startUp, toUp, toDn, startDn, lineColor); + startUp = toUp; + startDn = toDn; + start = to; + } + } + } + } +} diff --git a/Runtime/XUGL/UGL.cs.meta b/Runtime/XUGL/UGL.cs.meta new file mode 100644 index 00000000..0ca349f8 --- /dev/null +++ b/Runtime/XUGL/UGL.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 463dc57c2fc1849379941a7facf8dc84 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/UGLExample.cs b/Runtime/XUGL/UGLExample.cs new file mode 100644 index 00000000..b873c04b --- /dev/null +++ b/Runtime/XUGL/UGLExample.cs @@ -0,0 +1,62 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace XUGL +{ + [ExecuteInEditMode] + public class UGLExample : MaskableGraphic + { + private float m_Width = 800; + private float m_Height = 800; + private Vector3 m_Center = Vector3.zero; + private Vector3 m_LeftTopPos = Vector3.zero; + private Color32 m_BackgroundColor = new Color32(224, 224, 224, 255); + private Color32 m_DrawColor = new Color32(255, 132, 142, 255); + private float[] m_BorderRadius = new float[] { 2, 2, 2, 2 }; + + protected override void Awake() + { + base.Awake(); + var rectTransform = GetComponent<RectTransform>(); + rectTransform.sizeDelta = new Vector2(500, 500); + rectTransform.anchorMin = new Vector2(0.5f, 0.5f); + rectTransform.anchorMax = new Vector2(0.5f, 0.5f); + rectTransform.pivot = new Vector2(0.5f, 0.5f); + m_Center = Vector3.zero; + m_LeftTopPos = new Vector3(-m_Width / 2, m_Height / 2); + } + + protected override void OnPopulateMesh(VertexHelper vh) + { + Vector3 sp, cp, ep; + vh.Clear(); + + //背景边框 + UGL.DrawSquare(vh, m_Center, m_Width / 2, m_BackgroundColor); + UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 10, Color.green, 0, m_BorderRadius); + + //点 + UGL.DrawCricle(vh, m_LeftTopPos + new Vector3(20, -20), 10, m_DrawColor); + + //直线 + sp = new Vector3(m_LeftTopPos.x + 50, m_LeftTopPos.y - 20); + ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 20); + UGL.DrawLine(vh, sp, ep, 3, m_DrawColor); + + //3点确定的折线 + sp = new Vector3(m_LeftTopPos.x + 20, m_LeftTopPos.y - 100); + cp = new Vector3(m_LeftTopPos.x + 200, m_LeftTopPos.y - 40); + ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 80); + UGL.DrawLine(vh, sp, cp, ep, 5, m_DrawColor); + + } + } +} \ No newline at end of file diff --git a/Runtime/XUGL/UGLExample.cs.meta b/Runtime/XUGL/UGLExample.cs.meta new file mode 100644 index 00000000..e216aea3 --- /dev/null +++ b/Runtime/XUGL/UGLExample.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e8a87ea5df031473da3eb5fb8f57e20a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/UGLHelper.cs b/Runtime/XUGL/UGLHelper.cs new file mode 100644 index 00000000..b3119c0b --- /dev/null +++ b/Runtime/XUGL/UGLHelper.cs @@ -0,0 +1,219 @@ +/************************************************/ +/* */ +/* Copyright (c) 2018 - 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/************************************************/ + +using System.Collections.Generic; +using UnityEngine; + +namespace XUGL +{ + public static class UGLHelper + { + public static bool IsValueEqualsColor(Color32 color1, Color32 color2) + { + return color1.a == color2.a && + color1.b == color2.b && + color1.g == color2.g && + color1.r == color2.r; + } + + public static bool IsValueEqualsColor(Color color1, Color color2) + { + return color1.a == color2.a && + color1.b == color2.b && + color1.g == color2.g && + color1.r == color2.r; + } + + public static bool IsValueEqualsString(string str1, string str2) + { + if (str1 == null && str2 == null) return true; + else if (str1 != null && str2 != null) return str1.Equals(str2); + else return false; + } + + public static bool IsValueEqualsVector2(Vector2 v1, Vector2 v2) + { + return v1.x == v2.x && v1.y == v2.y; + } + + public static bool IsValueEqualsVector3(Vector3 v1, Vector3 v2) + { + return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z; + } + + public static bool IsValueEqualsList<T>(List<T> list1, List<T> list2) + { + if (list1 == null || list2 == null) return false; + if (list1.Count != list2.Count) return false; + for (int i = 0; i < list1.Count; i++) + { + if (list1[i] == null && list2[i] == null) { } + else + { + if (list1[i] != null) + { + if (!list1[i].Equals(list2[i])) return false; + } + else + { + if (!list2[i].Equals(list1[i])) return false; + } + } + } + return true; + } + + public static bool IsClearColor(Color32 color) + { + return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0; + } + + public static bool IsClearColor(Color color) + { + return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0; + } + + public static bool IsZeroVector(Vector3 pos) + { + return pos.x == 0 && pos.y == 0 && pos.z == 0; + } + + public static Vector3 RotateRound(Vector3 position, Vector3 center, Vector3 axis, float angle) + { + Vector3 point = Quaternion.AngleAxis(angle, axis) * (position - center); + Vector3 resultVec3 = center + point; + return resultVec3; + } + + public static void GetBezierList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, + Vector3 lsp, Vector3 nep, float smoothness = 2f, float k = 2.0f) + { + float dist = Mathf.Abs(sp.x - ep.x); + Vector3 cp1, cp2; + var dir = (ep - sp).normalized; + var diff = dist / k; + if (lsp == sp) + { + cp1 = sp + dist / k * dir * 1; + cp1.y = sp.y; + cp1 = sp; + } + else + { + cp1 = sp + (ep - lsp).normalized * diff; + } + if (nep == ep) cp2 = ep; + else cp2 = ep - (nep - sp).normalized * diff; + dist = Vector3.Distance(sp, ep); + int segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness)); + if (segment < 1) segment = (int)(dist / 0.5f); + if (segment < 4) segment = 4; + GetBezierList2(ref posList, sp, ep, segment, cp1, cp2); + } + + public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep, + float smoothness = 2f, float k = 2.0f) + { + Vector3 dir = (ep - sp).normalized; + float dist = Vector3.Distance(sp, ep); + Vector3 cp1 = sp + dist / k * dir * 1; + Vector3 cp2 = sp + dist / k * dir * (k - 1); + cp1.x = sp.x; + cp2.x = ep.x; + int segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness)); + GetBezierList2(ref posList, sp, ep, segment, cp1, cp2); + } + + public static List<Vector3> GetBezierList(Vector3 sp, Vector3 ep, int segment, Vector3 cp) + { + List<Vector3> list = new List<Vector3>(); + for (int i = 0; i < segment; i++) + { + list.Add(GetBezier(i / (float)segment, sp, cp, ep)); + } + list.Add(ep); + return list; + } + + public static void GetBezierList2(ref List<Vector3> posList, Vector3 sp, Vector3 ep, int segment, Vector3 cp, + Vector3 cp2) + { + posList.Clear(); + if (posList.Capacity < segment + 1) + { + posList.Capacity = segment + 1; + } + for (int i = 0; i < segment; i++) + { + posList.Add((GetBezier2(i / (float)segment, sp, cp, cp2, ep))); + } + posList.Add(ep); + } + + public static Vector3 GetBezier(float t, Vector3 sp, Vector3 cp, Vector3 ep) + { + Vector3 aa = sp + (cp - sp) * t; + Vector3 bb = cp + (ep - cp) * t; + return aa + (bb - aa) * t; + } + + public static Vector3 GetBezier2(float t, Vector3 sp, Vector3 p1, Vector3 p2, Vector3 ep) + { + t = Mathf.Clamp01(t); + var oneMinusT = 1f - t; + return oneMinusT * oneMinusT * oneMinusT * sp + + 3f * oneMinusT * oneMinusT * t * p1 + + 3f * oneMinusT * t * t * p2 + + t * t * t * ep; + } + + public static Vector3 GetDire(float angle, bool isDegree = false) + { + angle = isDegree ? angle * Mathf.Deg2Rad : angle; + return new Vector3(Mathf.Sin(angle), Mathf.Cos(angle)); + } + + public static Vector3 GetVertialDire(Vector3 dire) + { + if (dire.x == 0) + { + return new Vector3(-1, 0, 0); + } + if (dire.y == 0) + { + return new Vector3(0, -1, 0); + } + else + { + return new Vector3(-dire.y / dire.x, 1, 0).normalized; + } + } + + /// <summary> + /// 获得0-360的角度(12点钟方向为0度) + /// </summary> + /// <param name="from"></param> + /// <param name="to"></param> + /// <returns></returns> + public static float GetAngle360(Vector2 from, Vector2 to) + { + float angle; + + Vector3 cross = Vector3.Cross(from, to); + angle = Vector2.Angle(from, to); + angle = cross.z > 0 ? -angle : angle; + angle = (angle + 360) % 360; + return angle; + } + + public static Vector3 GetPos(Vector3 center, float radius, float angle, bool isDegree = false) + { + angle = isDegree ? angle * Mathf.Deg2Rad : angle; + return new Vector3(center.x + radius * Mathf.Sin(angle), center.y + radius * Mathf.Cos(angle)); + } + } +} \ No newline at end of file diff --git a/Runtime/XUGL/UGLHelper.cs.meta b/Runtime/XUGL/UGLHelper.cs.meta new file mode 100644 index 00000000..2165db18 --- /dev/null +++ b/Runtime/XUGL/UGLHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cc77f59a050d547caa3de82f4a9abd99 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: