mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-30 21:38:49 +00:00
重构Component相关代码,调整API接口
This commit is contained in:
@@ -204,15 +204,15 @@ namespace XCharts.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
serieDataMenus.Clear();
|
serieDataMenus.Clear();
|
||||||
if (serie.GetType().IsDefined(typeof(SerieDataExtraComponentAttribute), false))
|
if (serie.GetType().IsDefined(typeof(SerieDataComponentAttribute), false))
|
||||||
{
|
{
|
||||||
var attribute = serie.GetType().GetAttribute<SerieDataExtraComponentAttribute>();
|
var attribute = serie.GetType().GetAttribute<SerieDataComponentAttribute>();
|
||||||
foreach (var type in attribute.types)
|
foreach (var type in attribute.types)
|
||||||
{
|
{
|
||||||
var size = serieData.FindPropertyRelative(SerieData.extraComponentMap[type]).arraySize;
|
var size = serieData.FindPropertyRelative(SerieData.extraComponentMap[type]).arraySize;
|
||||||
serieDataMenus.Add(new HeaderMenuInfo("Add " + type.Name, () =>
|
serieDataMenus.Add(new HeaderMenuInfo("Add " + type.Name, () =>
|
||||||
{
|
{
|
||||||
serie.GetSerieData(index).GetOrAddComponent(type);
|
serie.GetSerieData(index).EnsureComponent(type);
|
||||||
EditorUtility.SetDirty(chart);
|
EditorUtility.SetDirty(chart);
|
||||||
}, size == 0));
|
}, size == 0));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,15 +176,15 @@ namespace XCharts.Editor
|
|||||||
ConvertSerie(editor.serie, type);
|
ConvertSerie(editor.serie, type);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
if (editor.serie.GetType().IsDefined(typeof(SerieExtraComponentAttribute), false))
|
if (editor.serie.GetType().IsDefined(typeof(SerieComponentAttribute), false))
|
||||||
{
|
{
|
||||||
var attribute = editor.serie.GetType().GetAttribute<SerieExtraComponentAttribute>();
|
var attribute = editor.serie.GetType().GetAttribute<SerieComponentAttribute>();
|
||||||
foreach (var type in attribute.types)
|
foreach (var type in attribute.types)
|
||||||
{
|
{
|
||||||
var size = editor.FindProperty(Serie.extraComponentMap[type]).arraySize;
|
var size = editor.FindProperty(Serie.extraComponentMap[type]).arraySize;
|
||||||
editor.menus.Add(new HeaderMenuInfo("Add " + type.Name, () =>
|
editor.menus.Add(new HeaderMenuInfo("Add " + type.Name, () =>
|
||||||
{
|
{
|
||||||
editor.serie.AddExtraComponent(type);
|
editor.serie.EnsureComponent(type);
|
||||||
RefreshEditors();
|
RefreshEditors();
|
||||||
chart.RefreshAllComponent();
|
chart.RefreshAllComponent();
|
||||||
EditorUtility.SetDirty(chart);
|
EditorUtility.SetDirty(chart);
|
||||||
@@ -195,7 +195,7 @@ namespace XCharts.Editor
|
|||||||
var size = editor.FindProperty(Serie.extraComponentMap[type]).arraySize;
|
var size = editor.FindProperty(Serie.extraComponentMap[type]).arraySize;
|
||||||
editor.menus.Add(new HeaderMenuInfo("Remove " + type.Name, () =>
|
editor.menus.Add(new HeaderMenuInfo("Remove " + type.Name, () =>
|
||||||
{
|
{
|
||||||
editor.serie.RemoveExtraComponent(type);
|
editor.serie.RemoveComponent(type);
|
||||||
RefreshEditors();
|
RefreshEditors();
|
||||||
chart.RefreshAllComponent();
|
chart.RefreshAllComponent();
|
||||||
EditorUtility.SetDirty(chart);
|
EditorUtility.SetDirty(chart);
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ namespace XCharts.Example
|
|||||||
chart = gameObject.GetComponent<LineChart>();
|
chart = gameObject.GetComponent<LineChart>();
|
||||||
if (chart == null) gameObject.AddComponent<LineChart>();
|
if (chart == null) gameObject.AddComponent<LineChart>();
|
||||||
|
|
||||||
chart.GetOrAddChartComponent<Title>().show = true;
|
chart.EnsureChartComponent<Title>().show = true;
|
||||||
chart.EnsureChartComponent<Title>().text = "术语解析-组件";
|
chart.EnsureChartComponent<Title>().text = "术语解析-组件";
|
||||||
|
|
||||||
var grid = chart.GetOrAddChartComponent<GridCoord>();
|
var grid = chart.EnsureChartComponent<GridCoord>();
|
||||||
grid.bottom = 30;
|
grid.bottom = 30;
|
||||||
grid.right = 30;
|
grid.right = 30;
|
||||||
grid.left = 50;
|
grid.left = 50;
|
||||||
@@ -197,7 +197,7 @@ namespace XCharts.Example
|
|||||||
var grid = chart.EnsureChartComponent<GridCoord>();
|
var grid = chart.EnsureChartComponent<GridCoord>();
|
||||||
grid.bottom = 70;
|
grid.bottom = 70;
|
||||||
|
|
||||||
var dataZoom = chart.GetOrAddChartComponent<DataZoom>();
|
var dataZoom = chart.EnsureChartComponent<DataZoom>();
|
||||||
dataZoom.enable = true;
|
dataZoom.enable = true;
|
||||||
dataZoom.supportInside = true;
|
dataZoom.supportInside = true;
|
||||||
dataZoom.supportSlider = true;
|
dataZoom.supportSlider = true;
|
||||||
@@ -258,7 +258,7 @@ namespace XCharts.Example
|
|||||||
{
|
{
|
||||||
chart.EnsureChartComponent<Title>().subText = "VisualMap 视觉映射:可从全局上配置图表的颜色、字体等效果,支持默认主题切换";
|
chart.EnsureChartComponent<Title>().subText = "VisualMap 视觉映射:可从全局上配置图表的颜色、字体等效果,支持默认主题切换";
|
||||||
|
|
||||||
var visualMap = chart.GetOrAddChartComponent<VisualMap>();
|
var visualMap = chart.EnsureChartComponent<VisualMap>();
|
||||||
visualMap.show = true;
|
visualMap.show = true;
|
||||||
visualMap.showUI = true;
|
visualMap.showUI = true;
|
||||||
visualMap.orient = Orient.Vertical;
|
visualMap.orient = Orient.Vertical;
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ namespace XCharts.Example
|
|||||||
{
|
{
|
||||||
if (dataZoom.IsInMarqueeArea(serieData))
|
if (dataZoom.IsInMarqueeArea(serieData))
|
||||||
{
|
{
|
||||||
serieData.GetOrAddComponent<ItemStyle>().color = Color.red;
|
serieData.EnsureComponent<ItemStyle>().color = Color.red;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
serieData.GetOrAddComponent<ItemStyle>().color = Color.clear;
|
serieData.EnsureComponent<ItemStyle>().color = Color.clear;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace XCharts.Example
|
|||||||
{
|
{
|
||||||
chart.GetChartComponent<Title>().subText = "AreaStyle 面积图";
|
chart.GetChartComponent<Title>().subText = "AreaStyle 面积图";
|
||||||
|
|
||||||
serie.AddExtraComponent<AreaStyle>();
|
serie.EnsureComponent<AreaStyle>();
|
||||||
serie.areaStyle.show = true;
|
serie.areaStyle.show = true;
|
||||||
chart.RefreshChart();
|
chart.RefreshChart();
|
||||||
yield return new WaitForSeconds(1f);
|
yield return new WaitForSeconds(1f);
|
||||||
@@ -136,7 +136,7 @@ namespace XCharts.Example
|
|||||||
IEnumerator LineArrowSettings()
|
IEnumerator LineArrowSettings()
|
||||||
{
|
{
|
||||||
chart.GetChartComponent<Title>().subText = "LineArrow 头部箭头";
|
chart.GetChartComponent<Title>().subText = "LineArrow 头部箭头";
|
||||||
chart.GetSerie(0).AddExtraComponent<LineArrow>();
|
chart.GetSerie(0).EnsureComponent<LineArrow>();
|
||||||
serie.lineArrow.show = true;
|
serie.lineArrow.show = true;
|
||||||
serie.lineArrow.position = LineArrow.Position.Start;
|
serie.lineArrow.position = LineArrow.Position.Start;
|
||||||
chart.RefreshChart();
|
chart.RefreshChart();
|
||||||
@@ -198,7 +198,7 @@ namespace XCharts.Example
|
|||||||
IEnumerator LineLabelSettings()
|
IEnumerator LineLabelSettings()
|
||||||
{
|
{
|
||||||
chart.GetChartComponent<Title>().subText = "SerieLabel 文本标签";
|
chart.GetChartComponent<Title>().subText = "SerieLabel 文本标签";
|
||||||
serie.AddExtraComponent<LabelStyle>();
|
serie.EnsureComponent<LabelStyle>();
|
||||||
chart.RefreshChart();
|
chart.RefreshChart();
|
||||||
while (serie.label.offset[1] < 20)
|
while (serie.label.offset[1] < 20)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ namespace XCharts.Example
|
|||||||
chart.Init();
|
chart.Init();
|
||||||
chart.SetSize(580, 300);
|
chart.SetSize(580, 300);
|
||||||
}
|
}
|
||||||
chart.GetOrAddChartComponent<Title>().show = true;
|
chart.EnsureChartComponent<Title>().show = true;
|
||||||
chart.GetOrAddChartComponent<Title>().text = "Line Simple";
|
chart.EnsureChartComponent<Title>().text = "Line Simple";
|
||||||
|
|
||||||
chart.GetOrAddChartComponent<Tooltip>().show = true;
|
chart.EnsureChartComponent<Tooltip>().show = true;
|
||||||
chart.GetOrAddChartComponent<Legend>().show = false;
|
chart.EnsureChartComponent<Legend>().show = false;
|
||||||
|
|
||||||
var xAxis = chart.GetOrAddChartComponent<XAxis>();
|
var xAxis = chart.EnsureChartComponent<XAxis>();
|
||||||
var yAxis = chart.GetOrAddChartComponent<YAxis>();
|
var yAxis = chart.EnsureChartComponent<YAxis>();
|
||||||
xAxis.show = true;
|
xAxis.show = true;
|
||||||
yAxis.show = true;
|
yAxis.show = true;
|
||||||
xAxis.type = Axis.AxisType.Category;
|
xAxis.type = Axis.AxisType.Category;
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ namespace XCharts.Example
|
|||||||
serie.barPercentStack = true;
|
serie.barPercentStack = true;
|
||||||
if (null == serie.label)
|
if (null == serie.label)
|
||||||
{
|
{
|
||||||
serie.AddExtraComponent<LabelStyle>();
|
serie.EnsureComponent<LabelStyle>();
|
||||||
}
|
}
|
||||||
serie.label.show = true;
|
serie.label.show = true;
|
||||||
serie.label.position = LabelStyle.Position.Center;
|
serie.label.position = LabelStyle.Position.Center;
|
||||||
@@ -139,7 +139,7 @@ namespace XCharts.Example
|
|||||||
|
|
||||||
if (null == serie2.label)
|
if (null == serie2.label)
|
||||||
{
|
{
|
||||||
serie2.AddExtraComponent<LabelStyle>();
|
serie2.EnsureComponent<LabelStyle>();
|
||||||
}
|
}
|
||||||
serie2.label.show = true;
|
serie2.label.show = true;
|
||||||
serie2.label.position = LabelStyle.Position.Center;
|
serie2.label.position = LabelStyle.Position.Center;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace XCharts.Example
|
|||||||
{
|
{
|
||||||
chart.EnsureChartComponent<Title>().subText = "显示文本标签";
|
chart.EnsureChartComponent<Title>().subText = "显示文本标签";
|
||||||
|
|
||||||
serie.AddExtraComponent<LabelStyle>();
|
serie.EnsureComponent<LabelStyle>();
|
||||||
serie.label.show = true;
|
serie.label.show = true;
|
||||||
chart.RefreshChart();
|
chart.RefreshChart();
|
||||||
yield return new WaitForSeconds(1);
|
yield return new WaitForSeconds(1);
|
||||||
@@ -139,11 +139,11 @@ namespace XCharts.Example
|
|||||||
}
|
}
|
||||||
if (null == serie.label)
|
if (null == serie.label)
|
||||||
{
|
{
|
||||||
serie.AddExtraComponent<LabelStyle>();
|
serie.EnsureComponent<LabelStyle>();
|
||||||
}
|
}
|
||||||
if (null == serie1.label)
|
if (null == serie1.label)
|
||||||
{
|
{
|
||||||
serie1.AddExtraComponent<LabelStyle>();
|
serie1.EnsureComponent<LabelStyle>();
|
||||||
}
|
}
|
||||||
serie1.label.show = true;
|
serie1.label.show = true;
|
||||||
serie1.label.position = LabelStyle.Position.Inside;
|
serie1.label.position = LabelStyle.Position.Inside;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace XCharts.Example
|
|||||||
var serieIndex = 0;
|
var serieIndex = 0;
|
||||||
var serie = chart.GetSerie(serieIndex);
|
var serie = chart.GetSerie(serieIndex);
|
||||||
if (serie == null) return;
|
if (serie == null) return;
|
||||||
serie.AddExtraComponent<LabelStyle>();
|
serie.EnsureComponent<LabelStyle>();
|
||||||
serie.label.show = true;
|
serie.label.show = true;
|
||||||
serie.label.position = LabelStyle.Position.Outside;
|
serie.label.position = LabelStyle.Position.Outside;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace XCharts.Example
|
|||||||
serie.itemStyle.borderColor = Color.clear;
|
serie.itemStyle.borderColor = Color.clear;
|
||||||
|
|
||||||
//设置高亮样式
|
//设置高亮样式
|
||||||
var emphasisStyle = serie.AddExtraComponent<EmphasisStyle>();
|
var emphasisStyle = serie.EnsureComponent<EmphasisStyle>();
|
||||||
emphasisStyle.itemStyle.show = true;
|
emphasisStyle.itemStyle.show = true;
|
||||||
emphasisStyle.itemStyle.borderWidth = 1;
|
emphasisStyle.itemStyle.borderWidth = 1;
|
||||||
emphasisStyle.itemStyle.borderColor = Color.black;
|
emphasisStyle.itemStyle.borderColor = Color.black;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace XCharts.Example
|
|||||||
{
|
{
|
||||||
chart = gameObject.AddComponent<BaseChart>();
|
chart = gameObject.AddComponent<BaseChart>();
|
||||||
}
|
}
|
||||||
chart.GetOrAddChartComponent<PolarCoord>();
|
chart.EnsureChartComponent<PolarCoord>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
|
|||||||
@@ -33,22 +33,22 @@ namespace XCharts.Example
|
|||||||
chart.Init();
|
chart.Init();
|
||||||
chart.SetSize(1200, 600);
|
chart.SetSize(1200, 600);
|
||||||
}
|
}
|
||||||
var title = chart.GetOrAddChartComponent<Title>();
|
var title = chart.EnsureChartComponent<Title>();
|
||||||
title.text = "Simple LineChart";
|
title.text = "Simple LineChart";
|
||||||
title.subText = "normal line";
|
title.subText = "normal line";
|
||||||
|
|
||||||
var tooltip = chart.GetOrAddChartComponent<Tooltip>();
|
var tooltip = chart.EnsureChartComponent<Tooltip>();
|
||||||
tooltip.show = true;
|
tooltip.show = true;
|
||||||
|
|
||||||
var legend = chart.GetOrAddChartComponent<Legend>();
|
var legend = chart.EnsureChartComponent<Legend>();
|
||||||
legend.show = false;
|
legend.show = false;
|
||||||
|
|
||||||
var xAxis = chart.GetOrAddChartComponent<XAxis>();
|
var xAxis = chart.EnsureChartComponent<XAxis>();
|
||||||
xAxis.splitNumber = 10;
|
xAxis.splitNumber = 10;
|
||||||
xAxis.boundaryGap = true;
|
xAxis.boundaryGap = true;
|
||||||
xAxis.type = Axis.AxisType.Category;
|
xAxis.type = Axis.AxisType.Category;
|
||||||
|
|
||||||
var yAxis = chart.GetOrAddChartComponent<YAxis>();
|
var yAxis = chart.EnsureChartComponent<YAxis>();
|
||||||
yAxis.type = Axis.AxisType.Value;
|
yAxis.type = Axis.AxisType.Value;
|
||||||
|
|
||||||
chart.RemoveData();
|
chart.RemoveData();
|
||||||
|
|||||||
@@ -15,20 +15,20 @@ namespace XCharts.Example
|
|||||||
|
|
||||||
void ModifyComponent()
|
void ModifyComponent()
|
||||||
{
|
{
|
||||||
var title = chart.GetOrAddChartComponent<Title>();
|
var title = chart.EnsureChartComponent<Title>();
|
||||||
title.text = "Simple LineChart";
|
title.text = "Simple LineChart";
|
||||||
title.subText = "normal line";
|
title.subText = "normal line";
|
||||||
|
|
||||||
var serie1 = chart.AddSerie<Line>();
|
var serie1 = chart.AddSerie<Line>();
|
||||||
//var serie2 = chart.GetSerie<Line>();
|
//var serie2 = chart.GetSerie<Line>();
|
||||||
|
|
||||||
serie1.AddExtraComponent<AreaStyle>();
|
serie1.EnsureComponent<AreaStyle>();
|
||||||
var label = serie1.AddExtraComponent<LabelStyle>();
|
var label = serie1.EnsureComponent<LabelStyle>();
|
||||||
label.offset = new Vector3(0, 20, 0);
|
label.offset = new Vector3(0, 20, 0);
|
||||||
|
|
||||||
var serieData = chart.AddData(0, 20);
|
var serieData = chart.AddData(0, 20);
|
||||||
serieData.radius = 10;
|
serieData.radius = 10;
|
||||||
var itemStyle = serieData.GetOrAddComponent<ItemStyle>();
|
var itemStyle = serieData.EnsureComponent<ItemStyle>();
|
||||||
itemStyle.color = Color.blue;
|
itemStyle.color = Color.blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace XCharts.Example
|
|||||||
serie.symbol.show = false;
|
serie.symbol.show = false;
|
||||||
serie.maxCache = maxCacheDataNumber;
|
serie.maxCache = maxCacheDataNumber;
|
||||||
|
|
||||||
var xAxis = chart.GetOrAddChartComponent<XAxis>();
|
var xAxis = chart.EnsureChartComponent<XAxis>();
|
||||||
xAxis.maxCache = maxCacheDataNumber;
|
xAxis.maxCache = maxCacheDataNumber;
|
||||||
timeNow = DateTime.Now;
|
timeNow = DateTime.Now;
|
||||||
timeNow = timeNow.AddSeconds(-maxCacheDataNumber);
|
timeNow = timeNow.AddSeconds(-maxCacheDataNumber);
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ namespace XCharts.Example
|
|||||||
chart.Init();
|
chart.Init();
|
||||||
chart.SetSize(580, 300);
|
chart.SetSize(580, 300);
|
||||||
|
|
||||||
chart.GetOrAddChartComponent<Title>().show = true;
|
chart.EnsureChartComponent<Title>().show = true;
|
||||||
chart.GetOrAddChartComponent<Title>().text = chartName;
|
chart.EnsureChartComponent<Title>().text = chartName;
|
||||||
|
|
||||||
chart.GetOrAddChartComponent<Tooltip>().show = true;
|
chart.EnsureChartComponent<Tooltip>().show = true;
|
||||||
chart.GetOrAddChartComponent<Legend>().show = true;
|
chart.EnsureChartComponent<Legend>().show = true;
|
||||||
|
|
||||||
chart.RemoveData();
|
chart.RemoveData();
|
||||||
chart.AddSerie<Pie>();
|
chart.AddSerie<Pie>();
|
||||||
@@ -67,16 +67,16 @@ namespace XCharts.Example
|
|||||||
chart.Init();
|
chart.Init();
|
||||||
chart.SetSize(580, 300);
|
chart.SetSize(580, 300);
|
||||||
|
|
||||||
chart.GetOrAddChartComponent<Title>().show = true;
|
chart.EnsureChartComponent<Title>().show = true;
|
||||||
chart.GetOrAddChartComponent<Title>().text = chartName;
|
chart.EnsureChartComponent<Title>().text = chartName;
|
||||||
|
|
||||||
chart.GetOrAddChartComponent<Legend>().show = false;
|
chart.EnsureChartComponent<Legend>().show = false;
|
||||||
|
|
||||||
var tooltip = chart.GetOrAddChartComponent<Tooltip>();
|
var tooltip = chart.EnsureChartComponent<Tooltip>();
|
||||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||||
|
|
||||||
var xAxis = chart.GetOrAddChartComponent<XAxis>();
|
var xAxis = chart.EnsureChartComponent<XAxis>();
|
||||||
var yAxis = chart.GetOrAddChartComponent<YAxis>();
|
var yAxis = chart.EnsureChartComponent<YAxis>();
|
||||||
xAxis.splitNumber = 10;
|
xAxis.splitNumber = 10;
|
||||||
xAxis.boundaryGap = true;
|
xAxis.boundaryGap = true;
|
||||||
xAxis.show = true;
|
xAxis.show = true;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace XCharts.Runtime
|
|||||||
AddChartComponentWhenNoExist<XAxis>();
|
AddChartComponentWhenNoExist<XAxis>();
|
||||||
AddChartComponentWhenNoExist<YAxis>();
|
AddChartComponentWhenNoExist<YAxis>();
|
||||||
|
|
||||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
var tooltip = EnsureChartComponent<Tooltip>();
|
||||||
tooltip.type = Tooltip.Type.Shadow;
|
tooltip.type = Tooltip.Type.Shadow;
|
||||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace XCharts.Runtime
|
|||||||
AddChartComponentWhenNoExist<XAxis>();
|
AddChartComponentWhenNoExist<XAxis>();
|
||||||
AddChartComponentWhenNoExist<YAxis>();
|
AddChartComponentWhenNoExist<YAxis>();
|
||||||
|
|
||||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
var tooltip = EnsureChartComponent<Tooltip>();
|
||||||
tooltip.type = Tooltip.Type.Shadow;
|
tooltip.type = Tooltip.Type.Shadow;
|
||||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ namespace XCharts.Runtime
|
|||||||
tooltip.type = Tooltip.Type.None;
|
tooltip.type = Tooltip.Type.None;
|
||||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||||
|
|
||||||
var grid = GetOrAddChartComponent<GridCoord>();
|
var grid = EnsureChartComponent<GridCoord>();
|
||||||
grid.left = 0.12f;
|
grid.left = 0.12f;
|
||||||
|
|
||||||
var xAxis = GetOrAddChartComponent<XAxis>();
|
var xAxis = EnsureChartComponent<XAxis>();
|
||||||
xAxis.type = Axis.AxisType.Category;
|
xAxis.type = Axis.AxisType.Category;
|
||||||
xAxis.boundaryGap = true;
|
xAxis.boundaryGap = true;
|
||||||
xAxis.splitNumber = 10;
|
xAxis.splitNumber = 10;
|
||||||
|
|
||||||
var yAxis = GetOrAddChartComponent<YAxis>();
|
var yAxis = EnsureChartComponent<YAxis>();
|
||||||
yAxis.type = Axis.AxisType.Category;
|
yAxis.type = Axis.AxisType.Category;
|
||||||
yAxis.boundaryGap = true;
|
yAxis.boundaryGap = true;
|
||||||
yAxis.splitNumber = 10;
|
yAxis.splitNumber = 10;
|
||||||
@@ -35,7 +35,7 @@ namespace XCharts.Runtime
|
|||||||
|
|
||||||
Heatmap.AddDefaultSerie(this, GenerateDefaultSerieName());
|
Heatmap.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||||
|
|
||||||
var visualMap = GetOrAddChartComponent<VisualMap>();
|
var visualMap = EnsureChartComponent<VisualMap>();
|
||||||
visualMap.autoMinMax = true;
|
visualMap.autoMinMax = true;
|
||||||
visualMap.orient = Orient.Vertical;
|
visualMap.orient = Orient.Vertical;
|
||||||
visualMap.calculable = true;
|
visualMap.calculable = true;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace XCharts.Runtime
|
|||||||
AddChartComponentWhenNoExist<XAxis>();
|
AddChartComponentWhenNoExist<XAxis>();
|
||||||
AddChartComponentWhenNoExist<YAxis>();
|
AddChartComponentWhenNoExist<YAxis>();
|
||||||
|
|
||||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
var tooltip = EnsureChartComponent<Tooltip>();
|
||||||
tooltip.type = Tooltip.Type.Line;
|
tooltip.type = Tooltip.Type.Line;
|
||||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
protected override void DefaultChart()
|
protected override void DefaultChart()
|
||||||
{
|
{
|
||||||
var legend = GetOrAddChartComponent<Legend>();
|
var legend = EnsureChartComponent<Legend>();
|
||||||
legend.show = true;
|
legend.show = true;
|
||||||
|
|
||||||
RemoveData();
|
RemoveData();
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
AddChartComponentWhenNoExist<GridCoord>();
|
AddChartComponentWhenNoExist<GridCoord>();
|
||||||
|
|
||||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
var tooltip = EnsureChartComponent<Tooltip>();
|
||||||
tooltip.type = Tooltip.Type.None;
|
tooltip.type = Tooltip.Type.None;
|
||||||
tooltip.trigger = Tooltip.Trigger.Item;
|
tooltip.trigger = Tooltip.Trigger.Item;
|
||||||
|
|
||||||
var xAxis = GetOrAddChartComponent<XAxis>();
|
var xAxis = EnsureChartComponent<XAxis>();
|
||||||
xAxis.type = Axis.AxisType.Value;
|
xAxis.type = Axis.AxisType.Value;
|
||||||
xAxis.boundaryGap = false;
|
xAxis.boundaryGap = false;
|
||||||
|
|
||||||
var yAxis = GetOrAddChartComponent<YAxis>();
|
var yAxis = EnsureChartComponent<YAxis>();
|
||||||
yAxis.type = Axis.AxisType.Value;
|
yAxis.type = Axis.AxisType.Value;
|
||||||
yAxis.boundaryGap = false;
|
yAxis.boundaryGap = false;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace XCharts.Runtime
|
|||||||
/// |区域填充样式。
|
/// |区域填充样式。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class AreaStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
|
public class AreaStyle : ChildComponent, ISerieComponent, ISerieDataComponent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Origin position of area.
|
/// Origin position of area.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using UnityEngine.UI;
|
|||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class ImageStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
|
public class ImageStyle : ChildComponent, ISerieComponent, ISerieDataComponent
|
||||||
{
|
{
|
||||||
[SerializeField] private bool m_Show = true;
|
[SerializeField] private bool m_Show = true;
|
||||||
[SerializeField] private Sprite m_Sprite;
|
[SerializeField] private Sprite m_Sprite;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace XCharts.Runtime
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class LineArrow : ChildComponent, ISerieExtraComponent
|
public class LineArrow : ChildComponent, ISerieComponent
|
||||||
{
|
{
|
||||||
public enum Position
|
public enum Position
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace XCharts.Runtime
|
|||||||
/// 标签的引导线
|
/// 标签的引导线
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class LabelLine : ChildComponent, ISerieExtraComponent, ISerieDataComponent
|
public class LabelLine : ChildComponent, ISerieComponent, ISerieDataComponent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 标签视觉引导线类型
|
/// 标签视觉引导线类型
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace XCharts.Runtime
|
|||||||
/// |图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
/// |图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class LabelStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
|
public class LabelStyle : ChildComponent, ISerieComponent, ISerieDataComponent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The position of label.
|
/// The position of label.
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ namespace XCharts.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[Since("v3.2.0")]
|
[Since("v3.2.0")]
|
||||||
public class BlurStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent
|
public class BlurStyle : StateStyle, ISerieComponent, ISerieDataComponent
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace XCharts.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[Since("v3.2.0")]
|
[Since("v3.2.0")]
|
||||||
public class EmphasisStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent
|
public class EmphasisStyle : StateStyle, ISerieComponent, ISerieDataComponent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// focus type.
|
/// focus type.
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ namespace XCharts.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[Since("v3.2.0")]
|
[Since("v3.2.0")]
|
||||||
public class SelectStyle : StateStyle, ISerieExtraComponent, ISerieDataComponent
|
public class SelectStyle : StateStyle, ISerieComponent, ISerieDataComponent
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace XCharts.Runtime
|
|||||||
/// |标题相关设置。
|
/// |标题相关设置。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieExtraComponent
|
public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieComponent
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,36 +3,40 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The attribute for serie component.
|
||||||
|
/// |可添加到Serie的组件。
|
||||||
|
/// </summary>
|
||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||||
public sealed class SerieExtraComponentAttribute : Attribute
|
public sealed class SerieComponentAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly List<Type> types = new List<Type>();
|
public readonly List<Type> types = new List<Type>();
|
||||||
|
|
||||||
public SerieExtraComponentAttribute()
|
public SerieComponentAttribute()
|
||||||
{ }
|
{ }
|
||||||
public SerieExtraComponentAttribute(Type type1)
|
public SerieComponentAttribute(Type type1)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
}
|
}
|
||||||
public SerieExtraComponentAttribute(Type type1, Type type2)
|
public SerieComponentAttribute(Type type1, Type type2)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
}
|
}
|
||||||
public SerieExtraComponentAttribute(Type type1, Type type2, Type type3)
|
public SerieComponentAttribute(Type type1, Type type2, Type type3)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
AddType(type3);
|
AddType(type3);
|
||||||
}
|
}
|
||||||
public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4)
|
public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
AddType(type3);
|
AddType(type3);
|
||||||
AddType(type4);
|
AddType(type4);
|
||||||
}
|
}
|
||||||
public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5)
|
public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
@@ -40,7 +44,7 @@ namespace XCharts.Runtime
|
|||||||
AddType(type4);
|
AddType(type4);
|
||||||
AddType(type5);
|
AddType(type5);
|
||||||
}
|
}
|
||||||
public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6)
|
public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
@@ -49,7 +53,7 @@ namespace XCharts.Runtime
|
|||||||
AddType(type5);
|
AddType(type5);
|
||||||
AddType(type6);
|
AddType(type6);
|
||||||
}
|
}
|
||||||
public SerieExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7)
|
public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
@@ -67,7 +71,7 @@ namespace XCharts.Runtime
|
|||||||
types.Add(type);
|
types.Add(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains<T>() where T : ISerieExtraComponent
|
public bool Contains<T>() where T : ISerieComponent
|
||||||
{
|
{
|
||||||
return Contains(typeof(T));
|
return Contains(typeof(T));
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,11 @@ using System;
|
|||||||
|
|
||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// What serie can convert to me
|
/// The attribute for which serie types can be converted to.
|
||||||
|
/// |可转化为哪些Serie类型。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||||
public sealed class SerieConvertAttribute : Attribute
|
public sealed class SerieConvertAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly Type type0;
|
public readonly Type type0;
|
||||||
|
|||||||
@@ -3,36 +3,41 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The attribute for serie data component.
|
||||||
|
/// |可添加到SerieData的组件。
|
||||||
|
/// </summary>
|
||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||||
public sealed class SerieDataExtraComponentAttribute : Attribute
|
public sealed class SerieDataComponentAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly List<Type> types = new List<Type>();
|
public readonly List<Type> types = new List<Type>();
|
||||||
|
|
||||||
public SerieDataExtraComponentAttribute()
|
public SerieDataComponentAttribute()
|
||||||
{ }
|
{
|
||||||
public SerieDataExtraComponentAttribute(Type type1)
|
}
|
||||||
|
public SerieDataComponentAttribute(Type type1)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
}
|
}
|
||||||
public SerieDataExtraComponentAttribute(Type type1, Type type2)
|
public SerieDataComponentAttribute(Type type1, Type type2)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
}
|
}
|
||||||
public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3)
|
public SerieDataComponentAttribute(Type type1, Type type2, Type type3)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
AddType(type3);
|
AddType(type3);
|
||||||
}
|
}
|
||||||
public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4)
|
public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
AddType(type3);
|
AddType(type3);
|
||||||
AddType(type4);
|
AddType(type4);
|
||||||
}
|
}
|
||||||
public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5)
|
public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
@@ -40,7 +45,7 @@ namespace XCharts.Runtime
|
|||||||
AddType(type4);
|
AddType(type4);
|
||||||
AddType(type5);
|
AddType(type5);
|
||||||
}
|
}
|
||||||
public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6)
|
public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
@@ -49,7 +54,7 @@ namespace XCharts.Runtime
|
|||||||
AddType(type5);
|
AddType(type5);
|
||||||
AddType(type6);
|
AddType(type6);
|
||||||
}
|
}
|
||||||
public SerieDataExtraComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7)
|
public SerieDataComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7)
|
||||||
{
|
{
|
||||||
AddType(type1);
|
AddType(type1);
|
||||||
AddType(type2);
|
AddType(type2);
|
||||||
@@ -67,7 +72,7 @@ namespace XCharts.Runtime
|
|||||||
types.Add(type);
|
types.Add(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains<T>() where T : ISerieExtraComponent
|
public bool Contains<T>() where T : ISerieComponent
|
||||||
{
|
{
|
||||||
return Contains(typeof(T));
|
return Contains(typeof(T));
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,15 @@ namespace XCharts.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector3 chartPosition { get { return m_ChartPosition; } }
|
public Vector3 chartPosition { get { return m_ChartPosition; } }
|
||||||
public Rect chartRect { get { return m_ChartRect; } }
|
public Rect chartRect { get { return m_ChartRect; } }
|
||||||
|
/// <summary>
|
||||||
|
/// The callback function of chart init.
|
||||||
|
/// |图表的初始化完成回调。
|
||||||
|
/// </summary>
|
||||||
public Action onInit { set { m_OnInit = value; } }
|
public Action onInit { set { m_OnInit = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// The callback function of chart update.
|
||||||
|
/// |图表的Update回调。
|
||||||
|
/// </summary>
|
||||||
public Action onUpdate { set { m_OnUpdate = value; } }
|
public Action onUpdate { set { m_OnUpdate = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义绘制回调。在绘制Serie前调用。
|
/// 自定义绘制回调。在绘制Serie前调用。
|
||||||
|
|||||||
@@ -221,9 +221,9 @@ namespace XCharts.Runtime
|
|||||||
return GetChartComponentNum(typeof(T));
|
return GetChartComponentNum(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<MainComponent> list;
|
||||||
public int GetChartComponentNum(Type type)
|
public int GetChartComponentNum(Type type)
|
||||||
{
|
{
|
||||||
List<MainComponent> list;
|
|
||||||
if (m_ComponentMaps.TryGetValue(type, out list))
|
if (m_ComponentMaps.TryGetValue(type, out list))
|
||||||
return list.Count;
|
return list.Count;
|
||||||
else
|
else
|
||||||
@@ -245,6 +245,7 @@ namespace XCharts.Runtime
|
|||||||
return m_ComponentMaps[typeof(T)];
|
return m_ComponentMaps[typeof(T)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("'GetOrAddChartComponent' is obsolete, Use 'EnsureChartComponent' instead.")]
|
||||||
public T GetOrAddChartComponent<T>() where T : MainComponent
|
public T GetOrAddChartComponent<T>() where T : MainComponent
|
||||||
{
|
{
|
||||||
var component = GetChartComponent<T>();
|
var component = GetChartComponent<T>();
|
||||||
@@ -253,6 +254,15 @@ namespace XCharts.Runtime
|
|||||||
else
|
else
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure the chart has the component, if not, add it.
|
||||||
|
/// Note: it may fail to add.
|
||||||
|
/// |确保图表有该组件,如果没有则添加。注意:有可能添加不成功。
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns>component, or null if add failed.</returns>
|
||||||
|
[Since("v3.6.0")]
|
||||||
public T EnsureChartComponent<T>() where T : MainComponent
|
public T EnsureChartComponent<T>() where T : MainComponent
|
||||||
{
|
{
|
||||||
var component = GetChartComponent<T>();
|
var component = GetChartComponent<T>();
|
||||||
|
|||||||
11
Runtime/Internal/Misc/ISerieComponent.cs
Normal file
11
Runtime/Internal/Misc/ISerieComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace XCharts.Runtime
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The interface for serie component.
|
||||||
|
/// |可用于Serie的组件。
|
||||||
|
/// </summary>
|
||||||
|
public interface ISerieComponent
|
||||||
|
{
|
||||||
|
bool show { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
public interface ISerieContainer
|
public interface ISerieContainer
|
||||||
{
|
{
|
||||||
//bool runtimeIsPointerEnter { get; }
|
|
||||||
int index { get; }
|
int index { get; }
|
||||||
bool IsPointerEnter();
|
bool IsPointerEnter();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using UnityEngine;
|
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The interface for serie data component.
|
||||||
|
/// |可用于SerieData的组件。
|
||||||
|
/// </summary>
|
||||||
public interface ISerieDataComponent
|
public interface ISerieDataComponent
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace XCharts.Runtime
|
|
||||||
{
|
|
||||||
public interface ISerieExtraComponent
|
|
||||||
{
|
|
||||||
bool show { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,8 +5,8 @@ namespace XCharts.Runtime
|
|||||||
[SerieConvert(typeof(Line), typeof(Pie))]
|
[SerieConvert(typeof(Line), typeof(Pie))]
|
||||||
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
|
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
|
||||||
[DefaultAnimation(AnimationType.BottomToTop)]
|
[DefaultAnimation(AnimationType.BottomToTop)]
|
||||||
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField("m_Ignore")]
|
[SerieDataExtraField("m_Ignore")]
|
||||||
public class Bar : Serie, INeedSerieContainer
|
public class Bar : Serie, INeedSerieContainer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ namespace XCharts.Runtime
|
|||||||
[SerieConvert(typeof(SimplifiedLine), typeof(Bar))]
|
[SerieConvert(typeof(SimplifiedLine), typeof(Bar))]
|
||||||
[CoordOptions(typeof(GridCoord))]
|
[CoordOptions(typeof(GridCoord))]
|
||||||
[DefaultAnimation(AnimationType.LeftToRight)]
|
[DefaultAnimation(AnimationType.LeftToRight)]
|
||||||
[SerieExtraComponent()]
|
[SerieComponent()]
|
||||||
[SerieDataExtraComponent()]
|
[SerieDataComponent()]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class SimplifiedBar : Serie, INeedSerieContainer, ISimplifiedSerie
|
public class SimplifiedBar : Serie, INeedSerieContainer, ISimplifiedSerie
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace XCharts.Runtime
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[SerieHandler(typeof(CandlestickHandler), true)]
|
[SerieHandler(typeof(CandlestickHandler), true)]
|
||||||
[DefaultAnimation(AnimationType.LeftToRight)]
|
[DefaultAnimation(AnimationType.LeftToRight)]
|
||||||
[SerieExtraComponent()]
|
[SerieComponent()]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class Candlestick : Serie, INeedSerieContainer
|
public class Candlestick : Serie, INeedSerieContainer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace XCharts.Runtime
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[SerieHandler(typeof(SimplifiedCandlestickHandler), true)]
|
[SerieHandler(typeof(SimplifiedCandlestickHandler), true)]
|
||||||
[DefaultAnimation(AnimationType.LeftToRight)]
|
[DefaultAnimation(AnimationType.LeftToRight)]
|
||||||
[SerieExtraComponent()]
|
[SerieComponent()]
|
||||||
[SerieDataExtraComponent()]
|
[SerieDataComponent()]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class SimplifiedCandlestick : Serie, INeedSerieContainer, ISimplifiedSerie
|
public class SimplifiedCandlestick : Serie, INeedSerieContainer, ISimplifiedSerie
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ namespace XCharts.Runtime
|
|||||||
[DefaultAnimation(AnimationType.LeftToRight)]
|
[DefaultAnimation(AnimationType.LeftToRight)]
|
||||||
[RequireChartComponent(typeof(VisualMap))]
|
[RequireChartComponent(typeof(VisualMap))]
|
||||||
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
|
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
|
||||||
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class Heatmap : Serie, INeedSerieContainer
|
public class Heatmap : Serie, INeedSerieContainer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace XCharts.Runtime
|
|||||||
[SerieConvert(typeof(Bar), typeof(Pie))]
|
[SerieConvert(typeof(Bar), typeof(Pie))]
|
||||||
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
|
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
|
||||||
[DefaultAnimation(AnimationType.LeftToRight)]
|
[DefaultAnimation(AnimationType.LeftToRight)]
|
||||||
[SerieExtraComponent(
|
[SerieComponent(
|
||||||
typeof(LabelStyle),
|
typeof(LabelStyle),
|
||||||
typeof(EndLabelStyle),
|
typeof(EndLabelStyle),
|
||||||
typeof(LineArrow),
|
typeof(LineArrow),
|
||||||
@@ -15,7 +15,7 @@ namespace XCharts.Runtime
|
|||||||
typeof(EmphasisStyle),
|
typeof(EmphasisStyle),
|
||||||
typeof(BlurStyle),
|
typeof(BlurStyle),
|
||||||
typeof(SelectStyle))]
|
typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(
|
[SerieDataComponent(
|
||||||
typeof(ItemStyle),
|
typeof(ItemStyle),
|
||||||
typeof(LabelStyle),
|
typeof(LabelStyle),
|
||||||
typeof(SerieSymbol),
|
typeof(SerieSymbol),
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ namespace XCharts.Runtime
|
|||||||
[SerieConvert(typeof(SimplifiedBar), typeof(Line))]
|
[SerieConvert(typeof(SimplifiedBar), typeof(Line))]
|
||||||
[CoordOptions(typeof(GridCoord))]
|
[CoordOptions(typeof(GridCoord))]
|
||||||
[DefaultAnimation(AnimationType.LeftToRight)]
|
[DefaultAnimation(AnimationType.LeftToRight)]
|
||||||
[SerieExtraComponent(typeof(AreaStyle))]
|
[SerieComponent(typeof(AreaStyle))]
|
||||||
[SerieDataExtraComponent()]
|
[SerieDataComponent()]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class SimplifiedLine : Serie, INeedSerieContainer, ISimplifiedSerie
|
public class SimplifiedLine : Serie, INeedSerieContainer, ISimplifiedSerie
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ namespace XCharts.Runtime
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[SerieHandler(typeof(ParallelHandler), true)]
|
[SerieHandler(typeof(ParallelHandler), true)]
|
||||||
[RequireChartComponent(typeof(ParallelCoord))]
|
[RequireChartComponent(typeof(ParallelCoord))]
|
||||||
[SerieExtraComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class Parallel : Serie, INeedSerieContainer
|
public class Parallel : Serie, INeedSerieContainer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ namespace XCharts.Runtime
|
|||||||
[SerieConvert(typeof(Line), typeof(Bar))]
|
[SerieConvert(typeof(Line), typeof(Bar))]
|
||||||
[SerieHandler(typeof(PieHandler), true)]
|
[SerieHandler(typeof(PieHandler), true)]
|
||||||
[DefaultAnimation(AnimationType.Clockwise)]
|
[DefaultAnimation(AnimationType.Clockwise)]
|
||||||
[SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")]
|
[SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")]
|
||||||
public class Pie : Serie
|
public class Pie : Serie
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ namespace XCharts.Runtime
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[SerieHandler(typeof(RadarHandler), true)]
|
[SerieHandler(typeof(RadarHandler), true)]
|
||||||
[RequireChartComponent(typeof(RadarCoord))]
|
[RequireChartComponent(typeof(RadarCoord))]
|
||||||
[SerieExtraComponent(typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class Radar : Serie, INeedSerieContainer
|
public class Radar : Serie, INeedSerieContainer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[SerieHandler(typeof(RingHandler), true)]
|
[SerieHandler(typeof(RingHandler), true)]
|
||||||
[SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField()]
|
[SerieDataExtraField()]
|
||||||
public class Ring : Serie
|
public class Ring : Serie
|
||||||
{
|
{
|
||||||
@@ -17,14 +17,14 @@ namespace XCharts.Runtime
|
|||||||
serie.gap = 10;
|
serie.gap = 10;
|
||||||
serie.radius = new float[] { 0.3f, 0.35f };
|
serie.radius = new float[] { 0.3f, 0.35f };
|
||||||
|
|
||||||
var label = serie.AddExtraComponent<LabelStyle>();
|
var label = serie.EnsureComponent<LabelStyle>();
|
||||||
label.show = true;
|
label.show = true;
|
||||||
label.position = LabelStyle.Position.Center;
|
label.position = LabelStyle.Position.Center;
|
||||||
label.formatter = "{d:f0}%";
|
label.formatter = "{d:f0}%";
|
||||||
label.textStyle.autoColor = true;
|
label.textStyle.autoColor = true;
|
||||||
label.textStyle.fontSize = 28;
|
label.textStyle.fontSize = 28;
|
||||||
|
|
||||||
var titleStyle = serie.AddExtraComponent<TitleStyle>();
|
var titleStyle = serie.EnsureComponent<TitleStyle>();
|
||||||
titleStyle.show = false;
|
titleStyle.show = false;
|
||||||
titleStyle.offset = new Vector2(0, 30);
|
titleStyle.offset = new Vector2(0, 30);
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace XCharts.Runtime
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[SerieHandler(typeof(EffectScatterHandler), true)]
|
[SerieHandler(typeof(EffectScatterHandler), true)]
|
||||||
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
|
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
|
||||||
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField("m_Radius")]
|
[SerieDataExtraField("m_Radius")]
|
||||||
public class EffectScatter : BaseScatter
|
public class EffectScatter : BaseScatter
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace XCharts.Runtime
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
[SerieHandler(typeof(ScatterHandler), true)]
|
[SerieHandler(typeof(ScatterHandler), true)]
|
||||||
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
|
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
|
||||||
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
[SerieDataComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
|
||||||
[SerieDataExtraField("m_Radius")]
|
[SerieDataExtraField("m_Radius")]
|
||||||
public class Scatter : BaseScatter
|
public class Scatter : BaseScatter
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ namespace XCharts.Runtime
|
|||||||
public partial class Serie
|
public partial class Serie
|
||||||
{
|
{
|
||||||
public static Dictionary<Type, string> extraComponentMap = new Dictionary<Type, string>
|
public static Dictionary<Type, string> extraComponentMap = new Dictionary<Type, string>
|
||||||
{ { typeof(LabelStyle), "m_Labels" },
|
{
|
||||||
|
{ typeof(LabelStyle), "m_Labels" },
|
||||||
{ typeof(LabelLine), "m_LabelLines" },
|
{ typeof(LabelLine), "m_LabelLines" },
|
||||||
{ typeof(EndLabelStyle), "m_EndLabels" },
|
{ typeof(EndLabelStyle), "m_EndLabels" },
|
||||||
{ typeof(LineArrow), "m_LineArrows" },
|
{ typeof(LineArrow), "m_LineArrows" },
|
||||||
@@ -71,7 +72,11 @@ namespace XCharts.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public SelectStyle selectStyle { get { return m_SelectStyles.Count > 0 ? m_SelectStyles[0] : null; } }
|
public SelectStyle selectStyle { get { return m_SelectStyles.Count > 0 ? m_SelectStyles[0] : null; } }
|
||||||
|
|
||||||
public void RemoveAllExtraComponent()
|
/// <summary>
|
||||||
|
/// Remove all extra components.
|
||||||
|
/// |移除所有额外组件。
|
||||||
|
/// </summary>
|
||||||
|
public void RemoveAllComponents()
|
||||||
{
|
{
|
||||||
var serieType = GetType();
|
var serieType = GetType();
|
||||||
foreach (var kv in extraComponentMap)
|
foreach (var kv in extraComponentMap)
|
||||||
@@ -81,16 +86,72 @@ namespace XCharts.Runtime
|
|||||||
SetAllDirty();
|
SetAllDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T AddExtraComponent<T>() where T : ChildComponent, ISerieExtraComponent
|
[Obsolete("Use EnsureComponent<T>() instead.")]
|
||||||
|
public T AddExtraComponent<T>() where T : ChildComponent, ISerieComponent
|
||||||
{
|
{
|
||||||
return AddExtraComponent(typeof(T)) as T;
|
return EnsureComponent<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISerieExtraComponent AddExtraComponent(Type type)
|
public T GetComponent<T>() where T : ChildComponent, ISerieComponent
|
||||||
{
|
{
|
||||||
if (GetType().IsDefined(typeof(SerieExtraComponentAttribute), false))
|
return GetComponent(typeof(T)) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure the serie has the component. If not, add it.
|
||||||
|
/// |确保系列有该组件。如果没有,则添加。
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns>component or null</returns>
|
||||||
|
public T EnsureComponent<T>() where T : ChildComponent, ISerieComponent
|
||||||
{
|
{
|
||||||
var attr = GetType().GetAttribute<SerieExtraComponentAttribute>();
|
return EnsureComponent(typeof(T)) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanAddComponent<T>() where T : ChildComponent, ISerieComponent
|
||||||
|
{
|
||||||
|
return CanAddComponent(typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanAddComponent(Type type)
|
||||||
|
{
|
||||||
|
if (GetType().IsDefined(typeof(SerieComponentAttribute), false))
|
||||||
|
{
|
||||||
|
var attr = GetType().GetAttribute<SerieComponentAttribute>();
|
||||||
|
if (attr.Contains(type))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISerieComponent GetComponent(Type type)
|
||||||
|
{
|
||||||
|
if (GetType().IsDefined(typeof(SerieComponentAttribute), false))
|
||||||
|
{
|
||||||
|
var attr = GetType().GetAttribute<SerieComponentAttribute>();
|
||||||
|
if (attr.Contains(type))
|
||||||
|
{
|
||||||
|
var fieldName = string.Empty;
|
||||||
|
if (extraComponentMap.TryGetValue(type, out fieldName))
|
||||||
|
{
|
||||||
|
var field = typeof(Serie).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
if (ReflectionUtil.InvokeListCount(this, field) > 0)
|
||||||
|
{
|
||||||
|
return ReflectionUtil.InvokeListGet<ISerieComponent>(this, field, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISerieComponent EnsureComponent(Type type)
|
||||||
|
{
|
||||||
|
if (GetType().IsDefined(typeof(SerieComponentAttribute), false))
|
||||||
|
{
|
||||||
|
var attr = GetType().GetAttribute<SerieComponentAttribute>();
|
||||||
if (attr.Contains(type))
|
if (attr.Contains(type))
|
||||||
{
|
{
|
||||||
var fieldName = string.Empty;
|
var fieldName = string.Empty;
|
||||||
@@ -99,32 +160,32 @@ namespace XCharts.Runtime
|
|||||||
var field = typeof(Serie).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
|
var field = typeof(Serie).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
if (ReflectionUtil.InvokeListCount(this, field) <= 0)
|
if (ReflectionUtil.InvokeListCount(this, field) <= 0)
|
||||||
{
|
{
|
||||||
var extraComponent = Activator.CreateInstance(type) as ISerieExtraComponent;
|
var extraComponent = Activator.CreateInstance(type) as ISerieComponent;
|
||||||
ReflectionUtil.InvokeListAdd(this, field, extraComponent);
|
ReflectionUtil.InvokeListAdd(this, field, extraComponent);
|
||||||
SetAllDirty();
|
SetAllDirty();
|
||||||
return extraComponent;
|
return extraComponent;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ReflectionUtil.InvokeListGet<ISerieExtraComponent>(this, field, 0);
|
return ReflectionUtil.InvokeListGet<ISerieComponent>(this, field, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new System.Exception(string.Format("Serie {0} not support extra component: {1}",
|
throw new System.Exception(string.Format("Serie {0} not support component: {1}",
|
||||||
GetType().Name, type.Name));
|
GetType().Name, type.Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveExtraComponent<T>() where T : ISerieExtraComponent
|
public void RemoveComponent<T>() where T : ISerieComponent
|
||||||
{
|
{
|
||||||
RemoveExtraComponent(typeof(T));
|
RemoveComponent(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveExtraComponent(Type type)
|
public void RemoveComponent(Type type)
|
||||||
{
|
{
|
||||||
if (GetType().IsDefined(typeof(SerieExtraComponentAttribute), false))
|
if (GetType().IsDefined(typeof(SerieComponentAttribute), false))
|
||||||
{
|
{
|
||||||
var attr = GetType().GetAttribute<SerieExtraComponentAttribute>();
|
var attr = GetType().GetAttribute<SerieComponentAttribute>();
|
||||||
if (attr.Contains(type))
|
if (attr.Contains(type))
|
||||||
{
|
{
|
||||||
var fieldName = string.Empty;
|
var fieldName = string.Empty;
|
||||||
@@ -137,17 +198,6 @@ namespace XCharts.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new System.Exception(string.Format("Serie {0} not support extra component: {1}",
|
|
||||||
GetType().Name, type.Name));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RemoveExtraComponentList<T>(List<T> list) where T : ISerieExtraComponent
|
|
||||||
{
|
|
||||||
if (list.Count > 0)
|
|
||||||
{
|
|
||||||
list.Clear();
|
|
||||||
SetAllDirty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,71 +234,157 @@ namespace XCharts.Runtime
|
|||||||
m_SelectStyles.Clear();
|
m_SelectStyles.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("GetOrAddComponent is obsolete. Use EnsureComponent instead.")]
|
||||||
public T GetOrAddComponent<T>() where T : ChildComponent, ISerieDataComponent
|
public T GetOrAddComponent<T>() where T : ChildComponent, ISerieDataComponent
|
||||||
{
|
{
|
||||||
return GetOrAddComponent(typeof(T)) as T;
|
return EnsureComponent<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISerieDataComponent GetOrAddComponent(Type type)
|
/// <summary>
|
||||||
|
/// Get the component of the serie data. return null if not exist.
|
||||||
|
/// |获取数据项的指定类型的组件,如果不存在则返回null。
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T GetComponent<T>() where T : ChildComponent, ISerieDataComponent
|
||||||
|
{
|
||||||
|
return GetComponentInternal(typeof(T), false) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure the serie data has the component, if not, add it.
|
||||||
|
/// |确保数据项有指定类型的组件,如果没有则添加。
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Since("v3.6.0")]
|
||||||
|
public T EnsureComponent<T>() where T : ChildComponent, ISerieDataComponent
|
||||||
|
{
|
||||||
|
return GetComponentInternal(typeof(T), true) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure the serie data has the component, if not, add it.
|
||||||
|
/// |确保数据项有指定类型的组件,如果没有则添加。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Since("v3.6.0")]
|
||||||
|
public ISerieDataComponent EnsureComponent(Type type)
|
||||||
|
{
|
||||||
|
return GetComponentInternal(type, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISerieDataComponent GetComponentInternal(Type type, bool addIfNotExist)
|
||||||
{
|
{
|
||||||
if (type == typeof(ItemStyle))
|
if (type == typeof(ItemStyle))
|
||||||
{
|
{
|
||||||
if (m_ItemStyles.Count == 0)
|
if (m_ItemStyles.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_ItemStyles.Add(new ItemStyle() { show = true });
|
m_ItemStyles.Add(new ItemStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_ItemStyles[0];
|
return m_ItemStyles[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(LabelStyle))
|
else if (type == typeof(LabelStyle))
|
||||||
{
|
{
|
||||||
if (m_Labels.Count == 0)
|
if (m_Labels.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_Labels.Add(new LabelStyle() { show = true });
|
m_Labels.Add(new LabelStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_Labels[0];
|
return m_Labels[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(LabelLine))
|
else if (type == typeof(LabelLine))
|
||||||
{
|
{
|
||||||
if (m_LabelLines.Count == 0)
|
if (m_LabelLines.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_LabelLines.Add(new LabelLine() { show = true });
|
m_LabelLines.Add(new LabelLine() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_LabelLines[0];
|
return m_LabelLines[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(EmphasisStyle))
|
else if (type == typeof(EmphasisStyle))
|
||||||
{
|
{
|
||||||
if (m_EmphasisStyles.Count == 0)
|
if (m_EmphasisStyles.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_EmphasisStyles.Add(new EmphasisStyle() { show = true });
|
m_EmphasisStyles.Add(new EmphasisStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_EmphasisStyles[0];
|
return m_EmphasisStyles[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(BlurStyle))
|
else if (type == typeof(BlurStyle))
|
||||||
{
|
{
|
||||||
if (m_BlurStyles.Count == 0)
|
if (m_BlurStyles.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_BlurStyles.Add(new BlurStyle() { show = true });
|
m_BlurStyles.Add(new BlurStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_BlurStyles[0];
|
return m_BlurStyles[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(SelectStyle))
|
else if (type == typeof(SelectStyle))
|
||||||
{
|
{
|
||||||
if (m_SelectStyles.Count == 0)
|
if (m_SelectStyles.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_SelectStyles.Add(new SelectStyle() { show = true });
|
m_SelectStyles.Add(new SelectStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_SelectStyles[0];
|
return m_SelectStyles[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(SerieSymbol))
|
else if (type == typeof(SerieSymbol))
|
||||||
{
|
{
|
||||||
if (m_Symbols.Count == 0)
|
if (m_Symbols.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_Symbols.Add(new SerieSymbol() { show = true });
|
m_Symbols.Add(new SerieSymbol() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_Symbols[0];
|
return m_Symbols[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(LineStyle))
|
else if (type == typeof(LineStyle))
|
||||||
{
|
{
|
||||||
if (m_LineStyles.Count == 0)
|
if (m_LineStyles.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_LineStyles.Add(new LineStyle() { show = true });
|
m_LineStyles.Add(new LineStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_LineStyles[0];
|
return m_LineStyles[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(AreaStyle))
|
else if (type == typeof(AreaStyle))
|
||||||
{
|
{
|
||||||
if (m_AreaStyles.Count == 0)
|
if (m_AreaStyles.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_AreaStyles.Add(new AreaStyle() { show = true });
|
m_AreaStyles.Add(new AreaStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_AreaStyles[0];
|
return m_AreaStyles[0];
|
||||||
}
|
}
|
||||||
else if (type == typeof(TitleStyle))
|
else if (type == typeof(TitleStyle))
|
||||||
{
|
{
|
||||||
if (m_TitleStyles.Count == 0)
|
if (m_TitleStyles.Count == 0)
|
||||||
|
{
|
||||||
|
if (addIfNotExist)
|
||||||
m_TitleStyles.Add(new TitleStyle() { show = true });
|
m_TitleStyles.Add(new TitleStyle() { show = true });
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return m_TitleStyles[0];
|
return m_TitleStyles[0];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user