This commit is contained in:
monitor1394
2022-05-22 22:17:38 +08:00
parent 003f4da9de
commit bafe032bb9
391 changed files with 3718 additions and 2774 deletions

View File

@@ -1,8 +1,3 @@
using System;
using System.Reflection;
using UnityEngine;
namespace XCharts.Runtime
{
[System.Serializable]
@@ -10,7 +5,9 @@ namespace XCharts.Runtime
[SerieConvert(typeof(Line), typeof(Pie))]
[RequireChartComponent(typeof(GridCoord))]
[DefaultAnimation(AnimationType.BottomToTop)]
[SerieExtraComponent(typeof(LabelStyle), typeof(Emphasis))]
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraField("m_Ignore")]
public class Bar : Serie, INeedSerieContainer
{
public int containerIndex { get; internal set; }

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using XUGL;
@@ -47,6 +47,16 @@ namespace XCharts.Runtime
}
}
public override void OnPointerDown(PointerEventData eventData)
{
if (!serie.context.pointerEnter) return;
if (serie.context.pointerItemDataIndex < 0) return;
if (chart.onPointerClickBar != null)
{
chart.onPointerClickBar(eventData, serie.context.pointerItemDataIndex);
}
}
private void UpdateSerieContext()
{
if (m_SerieGrid == null)
@@ -87,8 +97,8 @@ namespace XCharts.Runtime
serie.context.pointerEnter = false;
foreach (var serieData in serie.data)
{
if (serie.context.pointerAxisDataIndexs.Contains(serieData.index)
|| serieData.context.rect.Contains(chart.pointerPos))
if (serie.context.pointerAxisDataIndexs.Contains(serieData.index) ||
serieData.context.rect.Contains(chart.pointerPos))
{
serie.context.pointerItemDataIndex = serieData.index;
serie.context.pointerEnter = true;
@@ -155,17 +165,17 @@ namespace XCharts.Runtime
if (isStack)
SeriesHelper.UpdateStackDataList(chart.series, serie, dataZoom, m_StackSerieData);
var barCount = chart.GetSerieBarRealCount<Bar>();
float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
float barGap = chart.GetSerieBarGap<Bar>();
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap);
float barWidth = serie.GetBarWidth(categoryWidth);
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap, barCount);
float barWidth = serie.GetBarWidth(categoryWidth, barCount);
float offset = (categoryWidth - totalBarWidth) * 0.5f;
float barGapWidth = barWidth + barWidth * barGap;
float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieIndexIfStack<Bar>(serie) * barGapWidth;
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
var serieReadIndex = chart.GetSerieIndexIfStack<Bar>(serie);
float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieTotalGap<Bar>(categoryWidth, barGap, serieReadIndex);
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series, serie.stack);
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
@@ -214,7 +224,7 @@ namespace XCharts.Runtime
if (isPercentStack)
{
var valueTotal = chart.GetSerieSameStackTotalValue<Bar>(serie.stack, i);
barHig = valueTotal != 0 ? (float)(relativedValue / valueTotal * relativedAxisLength) : 0;
barHig = valueTotal != 0 ? (float) (relativedValue / valueTotal * relativedAxisLength) : 0;
}
else
{
@@ -229,9 +239,9 @@ namespace XCharts.Runtime
serieData.context.position = top;
serieData.context.rect = Rect.MinMaxRect(plb.x + borderGapAndWidth, plb.y + borderGapAndWidth,
prt.x - borderGapAndWidth, prt.y - borderGapAndWidth);
serieData.context.backgroundRect = isY
? Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y)
: Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength);
serieData.context.backgroundRect = isY ?
Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y) :
Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength);
if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top)))
serie.context.dataPoints.Add(top);
@@ -283,7 +293,7 @@ namespace XCharts.Runtime
if (axis.context.minMaxRange <= 0) pY = grid.context.y;
else
{
var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.height;
var valueLen = (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.height;
pY = grid.context.y + valueLen - categoryWidth * 0.5f;
}
}
@@ -305,7 +315,7 @@ namespace XCharts.Runtime
if (axis.context.minMaxRange <= 0) pX = grid.context.x;
else
{
var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.width;
var valueLen = (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.width;
pX = grid.context.x + valueLen - categoryWidth * 0.5f;
}
}
@@ -374,9 +384,9 @@ namespace XCharts.Runtime
{
var borderWidth = itemStyle.runtimeBorderWidth;
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false);
var cornerRadius = serie.barType == BarType.Capsule && !itemStyle.IsNeedCorner()
? m_CapusleDefaultCornerRadius
: itemStyle.cornerRadius;
var cornerRadius = serie.barType == BarType.Capsule && !itemStyle.IsNeedCorner() ?
m_CapusleDefaultCornerRadius :
itemStyle.cornerRadius;
var invert = value < 0;
if (!ChartHelper.IsClearColor(backgroundColor))
{
@@ -384,7 +394,7 @@ namespace XCharts.Runtime
cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
}
UGL.DrawRoundRectangle(vh, serieData.context.rect, areaColor, areaToColor, 0,
cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
if (serie.barType == BarType.Capsule)
{
UGL.DrawBorder(vh, serieData.context.backgroundRect, borderWidth, itemStyle.borderColor,
@@ -393,7 +403,7 @@ namespace XCharts.Runtime
else
{
UGL.DrawBorder(vh, serieData.context.rect, borderWidth, itemStyle.borderColor,
0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, itemStyle.borderGap);
0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, itemStyle.borderGap);
}
}

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
@@ -10,6 +9,8 @@ namespace XCharts.Runtime
[CoordOptions(typeof(GridCoord))]
[DefaultAnimation(AnimationType.LeftToRight)]
[SerieExtraComponent()]
[SerieDataExtraComponent()]
[SerieDataExtraField()]
public class SimplifiedBar : Serie, INeedSerieContainer, ISimplifiedSerie
{
public int containerIndex { get; internal set; }

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -138,16 +137,17 @@ namespace XCharts.Runtime
var axisLength = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width;
var axisXY = isY ? m_SerieGrid.context.y : m_SerieGrid.context.x;
var barCount = chart.GetSerieBarRealCount<SimplifiedBar>();
float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
float barGap = chart.GetSerieBarGap<Bar>();
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap);
float barWidth = serie.GetBarWidth(categoryWidth);
float barGap = chart.GetSerieBarGap<SimplifiedBar>();
float totalBarWidth = chart.GetSerieTotalWidth<SimplifiedBar>(categoryWidth, barGap, barCount);
float barWidth = serie.GetBarWidth(categoryWidth, barCount);
float offset = (categoryWidth - totalBarWidth) * 0.5f;
float barGapWidth = barWidth + barWidth * barGap;
float gap = serie.barGap == -1 ? offset : offset + serie.index * barGapWidth;
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
@@ -231,7 +231,7 @@ namespace XCharts.Runtime
else
{
if (axis.context.minMaxRange <= 0) pY = grid.context.y;
else pY = grid.context.y + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth);
else pY = grid.context.y + (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth);
}
pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
}
@@ -244,7 +244,7 @@ namespace XCharts.Runtime
else
{
if (axis.context.minMaxRange <= 0) pX = grid.context.x;
else pX = grid.context.x + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth);
else pX = grid.context.x + (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth);
}
pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
}

View File

@@ -1,4 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -7,6 +6,8 @@ namespace XCharts.Runtime
[SerieHandler(typeof(CandlestickHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight)]
[SerieExtraComponent()]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(EmphasisItemStyle))]
[SerieDataExtraField()]
public class Candlestick : Serie, INeedSerieContainer
{
public int containerIndex { get; internal set; }

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -41,6 +40,7 @@ namespace XCharts.Runtime
param.category = category;
param.dimension = 1;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = 0;
param.total = 0;
param.color = color;
@@ -61,6 +61,7 @@ namespace XCharts.Runtime
param.serieIndex = serie.index;
param.dimension = i;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = serieData.GetData(i);
param.total = SerieHelper.GetMaxData(serie, i);
param.color = color;
@@ -93,9 +94,9 @@ namespace XCharts.Runtime
float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, showData.Count, dataZoom);
float barWidth = serie.GetBarWidth(categoryWidth);
float gap = (categoryWidth - barWidth) / 2;
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
@@ -118,10 +119,10 @@ namespace XCharts.Runtime
var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var isRise = yAxis.inverse ? close < open : close > open;
var borderWidth = open == 0 ? 0f
: (itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth
: itemStyle.runtimeBorderWidth);
var isRise = yAxis.inverse ? close<open : close> open;
var borderWidth = open == 0 ? 0f :
(itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth :
itemStyle.runtimeBorderWidth);
if (serieData.IsDataChanged()) dataChanging = true;
float pX = grid.context.x + i * categoryWidth;
float zeroY = grid.context.y + yAxis.context.offset;
@@ -132,8 +133,8 @@ namespace XCharts.Runtime
var minCut = (yMinValue > 0 ? yMinValue : 0);
if (valueTotal != 0)
{
barHig = (float)((close - open) / valueTotal * grid.context.height);
pY += (float)((open - minCut) / valueTotal * grid.context.height);
barHig = (float) ((close - open) / valueTotal * grid.context.height);
pY += (float) ((open - minCut) / valueTotal * grid.context.height);
}
serieData.context.stackHeight = barHig;
float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig);
@@ -153,17 +154,17 @@ namespace XCharts.Runtime
top = chart.ClampInGrid(grid, top);
}
serie.context.dataPoints.Add(top);
var areaColor = isRise
? itemStyle.GetColor(theme.serie.candlestickColor)
: itemStyle.GetColor0(theme.serie.candlestickColor0);
var borderColor = isRise
? itemStyle.GetBorderColor(theme.serie.candlestickBorderColor)
: itemStyle.GetBorderColor0(theme.serie.candlestickBorderColor0);
var areaColor = isRise ?
itemStyle.GetColor(theme.serie.candlestickColor) :
itemStyle.GetColor0(theme.serie.candlestickColor0);
var borderColor = isRise ?
itemStyle.GetBorderColor(theme.serie.candlestickBorderColor) :
itemStyle.GetBorderColor0(theme.serie.candlestickBorderColor0);
var itemWidth = Mathf.Abs(prt.x - plb.x);
var itemHeight = Mathf.Abs(plt.y - prb.y);
var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
var lowPos = new Vector3(center.x, zeroY + (float)((lowest - minCut) / valueTotal * grid.context.height));
var heighPos = new Vector3(center.x, zeroY + (float)((heighest - minCut) / valueTotal * grid.context.height));
var lowPos = new Vector3(center.x, zeroY + (float) ((lowest - minCut) / valueTotal * grid.context.height));
var heighPos = new Vector3(center.x, zeroY + (float) ((heighest - minCut) / valueTotal * grid.context.height));
var openCenterPos = new Vector3(center.x, prb.y);
var closeCenterPos = new Vector3(center.x, prt.y);
if (barWidth > 2f * borderWidth)
@@ -181,7 +182,7 @@ namespace XCharts.Runtime
serie.clip, grid);
}
UGL.DrawBorder(vh, center, itemWidth, itemHeight, 2 * borderWidth, borderColor, 0,
itemStyle.cornerRadius, isYAxis, 0.5f);
itemStyle.cornerRadius, isYAxis, 0.5f);
}
}
else

View File

@@ -1,4 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -7,6 +6,8 @@ namespace XCharts.Runtime
[SerieHandler(typeof(SimplifiedCandlestickHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight)]
[SerieExtraComponent()]
[SerieDataExtraComponent()]
[SerieDataExtraField()]
public class SimplifiedCandlestick : Serie, INeedSerieContainer, ISimplifiedSerie
{
public int containerIndex { get; internal set; }

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -41,6 +40,7 @@ namespace XCharts.Runtime
param.category = category;
param.dimension = 1;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = 0;
param.total = 0;
param.color = color;
@@ -61,6 +61,7 @@ namespace XCharts.Runtime
param.serieIndex = serie.index;
param.dimension = i;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = serieData.GetData(i);
param.total = SerieHelper.GetMaxData(serie, i);
param.color = color;
@@ -93,9 +94,9 @@ namespace XCharts.Runtime
float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, showData.Count, dataZoom);
float barWidth = serie.GetBarWidth(categoryWidth);
float gap = (categoryWidth - barWidth) / 2;
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
@@ -118,10 +119,10 @@ namespace XCharts.Runtime
var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var isRise = yAxis.inverse ? close < open : close > open;
var borderWidth = open == 0 ? 0f
: (itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth
: itemStyle.runtimeBorderWidth);
var isRise = yAxis.inverse ? close<open : close> open;
var borderWidth = open == 0 ? 0f :
(itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth :
itemStyle.runtimeBorderWidth);
if (serieData.IsDataChanged()) dataChanging = true;
float pX = grid.context.x + i * categoryWidth;
float zeroY = grid.context.y + yAxis.context.offset;
@@ -132,8 +133,8 @@ namespace XCharts.Runtime
var minCut = (yMinValue > 0 ? yMinValue : 0);
if (valueTotal != 0)
{
barHig = (float)((close - open) / valueTotal * grid.context.height);
pY += (float)((open - minCut) / valueTotal * grid.context.height);
barHig = (float) ((close - open) / valueTotal * grid.context.height);
pY += (float) ((open - minCut) / valueTotal * grid.context.height);
}
serieData.context.stackHeight = barHig;
float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig);
@@ -153,17 +154,17 @@ namespace XCharts.Runtime
// top = chart.ClampInGrid(grid, top);
// }
serie.context.dataPoints.Add(top);
var areaColor = isRise
? itemStyle.GetColor(theme.serie.candlestickColor)
: itemStyle.GetColor0(theme.serie.candlestickColor0);
var borderColor = isRise
? itemStyle.GetBorderColor(theme.serie.candlestickBorderColor)
: itemStyle.GetBorderColor0(theme.serie.candlestickBorderColor0);
var areaColor = isRise ?
itemStyle.GetColor(theme.serie.candlestickColor) :
itemStyle.GetColor0(theme.serie.candlestickColor0);
var borderColor = isRise ?
itemStyle.GetBorderColor(theme.serie.candlestickBorderColor) :
itemStyle.GetBorderColor0(theme.serie.candlestickBorderColor0);
var itemWidth = Mathf.Abs(prt.x - plb.x);
var itemHeight = Mathf.Abs(plt.y - prb.y);
var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
var lowPos = new Vector3(center.x, zeroY + (float)((lowest - minCut) / valueTotal * grid.context.height));
var heighPos = new Vector3(center.x, zeroY + (float)((heighest - minCut) / valueTotal * grid.context.height));
var lowPos = new Vector3(center.x, zeroY + (float) ((lowest - minCut) / valueTotal * grid.context.height));
var heighPos = new Vector3(center.x, zeroY + (float) ((heighest - minCut) / valueTotal * grid.context.height));
var openCenterPos = new Vector3(center.x, prb.y);
var closeCenterPos = new Vector3(center.x, prt.y);
if (barWidth > 2f * borderWidth)
@@ -181,7 +182,7 @@ namespace XCharts.Runtime
serie.clip, grid);
}
UGL.DrawBorder(vh, center, itemWidth, itemHeight, 2 * borderWidth, borderColor, 0,
itemStyle.cornerRadius, isYAxis, 0.5f);
itemStyle.cornerRadius, isYAxis, 0.5f);
}
if (isRise)
{

View File

@@ -1,4 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -7,7 +6,9 @@ namespace XCharts.Runtime
[SerieHandler(typeof(HeatmapHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight)]
[RequireChartComponent(typeof(VisualMap))]
[SerieExtraComponent(typeof(LabelStyle), typeof(Emphasis))]
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraField()]
public class Heatmap : Serie, INeedSerieContainer
{
public int containerIndex { get; internal set; }
@@ -19,11 +20,10 @@ namespace XCharts.Runtime
serie.itemStyle.borderWidth = 1;
serie.itemStyle.borderColor = Color.clear;
var emphasis = serie.AddExtraComponent<Emphasis>();
var emphasis = serie.AddExtraComponent<EmphasisItemStyle>();
emphasis.show = true;
emphasis.itemStyle.show = true;
emphasis.itemStyle.borderWidth = 1;
emphasis.itemStyle.borderColor = Color.black;
emphasis.borderWidth = 1;
emphasis.borderColor = Color.black;
return serie;
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -40,7 +39,7 @@ namespace XCharts.Runtime
{
var xAxis = chart.GetChartComponent<XAxis>(serie.xAxisIndex);
if (xAxis != null)
category = xAxis.GetData((int)serieData.GetData(0));
category = xAxis.GetData((int) serieData.GetData(0));
}
title = serie.serieName;
@@ -49,6 +48,7 @@ namespace XCharts.Runtime
param.serieName = serie.serieName;
param.serieIndex = serie.index;
param.dimension = defaultDimension;
param.dataCount = serie.dataCount;
param.serieData = serieData;
param.color = serieData.context.color;
param.marker = SerieHelper.GetItemMarker(serie, serieData, marker);
@@ -130,7 +130,7 @@ namespace XCharts.Runtime
xAxis.boundaryGap = true;
yAxis.boundaryGap = true;
var visualMap = chart.GetVisualMapOfSerie(serie);
var emphasis = serie.emphasis;
var emphasisItemStyle = serie.emphasisItemStyle;
var xCount = xAxis.data.Count;
var yCount = yAxis.data.Count;
var xWidth = m_SerieGrid.context.width / xCount;
@@ -145,15 +145,15 @@ namespace XCharts.Runtime
var rectWid = xWidth - 2 * borderWidth;
var rectHig = yWidth - 2 * borderWidth;
var borderColor = serie.itemStyle.opacity > 0
? serie.itemStyle.borderColor
: ChartConst.clearColor32;
borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
var borderColor = serie.itemStyle.opacity > 0 ?
serie.itemStyle.borderColor :
ChartConst.clearColor32;
borderColor.a = (byte) (borderColor.a * serie.itemStyle.opacity);
var borderToColor = serie.itemStyle.opacity > 0
? serie.itemStyle.borderToColor
: ChartConst.clearColor32;
borderToColor.a = (byte)(borderToColor.a * serie.itemStyle.opacity);
var borderToColor = serie.itemStyle.opacity > 0 ?
serie.itemStyle.borderToColor :
ChartConst.clearColor32;
borderToColor.a = (byte) (borderToColor.a * serie.itemStyle.opacity);
serie.context.dataPoints.Clear();
serie.animation.InitProgress(0, xCount);
@@ -166,8 +166,8 @@ namespace XCharts.Runtime
{
var serieData = serie.data[n];
serieData.index = n;
var i = (int)serieData.GetData(0);
var j = (int)serieData.GetData(1);
var i = (int) serieData.GetData(0);
var j = (int) serieData.GetData(1);
var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
if (serie.IsIgnoreValue(serieData, dimension))
{
@@ -185,8 +185,8 @@ namespace XCharts.Runtime
serieData.context.canShowLabel = false;
serieData.context.rect = new Rect(pos.x - rectWid / 2, pos.y - rectHig / 2, rectWid, rectHig);
if (value == 0) continue;
if ((value < rangeMin && rangeMin != visualMap.min)
|| (value > rangeMax && rangeMax != visualMap.max))
if ((value < rangeMin && rangeMin != visualMap.min) ||
(value > rangeMax && rangeMax != visualMap.max))
{
continue;
}
@@ -199,8 +199,8 @@ namespace XCharts.Runtime
serieData.context.canShowLabel = true;
serieData.context.color = color;
var highlight = (serieData.context.highlight)
|| visualMap.context.pointerIndex > 0;
var highlight = (serieData.context.highlight) ||
visualMap.context.pointerIndex > 0;
//UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
UGL.DrawRectangle(vh, serieData.context.rect, color);
@@ -209,14 +209,14 @@ namespace XCharts.Runtime
{
UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor);
}
if (visualMap.hoverLink && highlight && emphasis != null && emphasis.show
&& emphasis.itemStyle.borderWidth > 0)
if (visualMap.hoverLink && highlight && emphasisItemStyle != null &&
emphasisItemStyle.borderWidth > 0)
{
var emphasisBorderWidth = emphasis.itemStyle.borderWidth;
var emphasisBorderColor = emphasis.itemStyle.opacity > 0
? emphasis.itemStyle.borderColor : ChartConst.clearColor32;
var emphasisBorderToColor = emphasis.itemStyle.opacity > 0
? emphasis.itemStyle.borderToColor : ChartConst.clearColor32;
var emphasisBorderWidth = emphasisItemStyle.borderWidth;
var emphasisBorderColor = emphasisItemStyle.opacity > 0 ?
emphasisItemStyle.borderColor : ChartConst.clearColor32;
var emphasisBorderToColor = emphasisItemStyle.opacity > 0 ?
emphasisItemStyle.borderToColor : ChartConst.clearColor32;
UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor,
emphasisBorderToColor);
}

View File

@@ -1,209 +0,0 @@
using UnityEngine;
namespace XCharts.Runtime
{
public class InteractData
{
private float m_PreviousValue = 0;
private float m_TargetValue = 0;
private Color32 m_PreviousColor;
private Color32 m_TargetColor;
private Color32 m_PreviousToColor;
private Color32 m_TargetToColor;
private float m_UpdateTime = 0;
private bool m_UpdateFlag = false;
private bool m_ValueEnable = false;
public void SetValue(ref bool needInteract, float size, bool highlight, float rate = 1.3f)
{
size = highlight ? size * rate : size;
SetValue(ref needInteract, size);
}
public void SetValue(ref bool needInteract, float size)
{
if (m_TargetValue != size)
{
if (float.IsNaN(m_TargetValue))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousValue = m_TargetValue;
}
m_TargetValue = size;
}
}
public void SetColor(ref bool needInteract, Color32 color)
{
if (!ChartHelper.IsValueEqualsColor(color, m_TargetColor))
{
if (!ChartHelper.IsClearColor(m_TargetColor))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousColor = m_TargetColor;
}
m_TargetColor = color;
}
}
public void SetColor(ref bool needInteract, Color32 color, Color32 toColor)
{
SetColor(ref needInteract, color);
if (!ChartHelper.IsValueEqualsColor(toColor, m_TargetToColor))
{
if (!ChartHelper.IsClearColor(m_TargetToColor))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousToColor = m_TargetToColor;
}
m_TargetToColor = toColor;
}
}
public void SetValueAndColor(ref bool needInteract, float value, Color32 color)
{
SetValue(ref needInteract, value);
SetColor(ref needInteract, color);
}
public void SetValueAndColor(ref bool needInteract, float value, Color32 color, Color32 toColor)
{
SetValue(ref needInteract, value);
SetColor(ref needInteract, color, toColor);
}
public bool TryGetValue(ref float value, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable() || m_PreviousValue == 0)
return false;
if (m_UpdateFlag)
{
var time = Time.time - m_UpdateTime;
var total = animationDuration / 1000;
var rate = time / total;
if (rate > 1) rate = 1;
if (rate < 1)
{
interacting = true;
value = Mathf.Lerp(m_PreviousValue, m_TargetValue, rate);
return true;
}
else
{
m_UpdateFlag = false;
}
}
value = m_TargetValue;
return true;
}
public bool TryGetColor(ref Color32 color, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable())
return false;
if (m_UpdateFlag)
{
var time = Time.time - m_UpdateTime;
var total = animationDuration / 1000;
var rate = time / total;
if (rate > 1) rate = 1;
if (rate < 1)
{
interacting = true;
color = Color32.Lerp(m_PreviousColor, m_TargetColor, rate);
return true;
}
else
{
m_UpdateFlag = false;
}
}
color = m_TargetColor;
return true;
}
public bool TryGetColor(ref Color32 color, ref Color32 toColor, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable())
return false;
if (m_UpdateFlag)
{
var time = Time.time - m_UpdateTime;
var total = animationDuration / 1000;
var rate = time / total;
if (rate > 1) rate = 1;
if (rate < 1)
{
interacting = true;
color = Color32.Lerp(m_PreviousColor, m_TargetColor, rate);
toColor = Color32.Lerp(m_PreviousToColor, m_TargetToColor, rate);
return true;
}
else
{
m_UpdateFlag = false;
}
}
color = m_TargetColor;
toColor = m_TargetToColor;
return true;
}
public bool TryGetValueAndColor(ref float value, ref Color32 color, ref Color32 toColor, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable())
return false;
if (m_UpdateFlag)
{
var time = Time.time - m_UpdateTime;
var total = animationDuration / 1000;
var rate = time / total;
if (rate > 1) rate = 1;
if (rate < 1)
{
interacting = true;
value = Mathf.Lerp(m_PreviousValue, m_TargetValue, rate);
color = Color32.Lerp(m_PreviousColor, m_TargetColor, rate);
toColor = Color32.Lerp(m_PreviousToColor, m_TargetToColor, rate);
return true;
}
else
{
m_UpdateFlag = false;
}
}
value = m_TargetValue;
color = m_TargetColor;
toColor = m_TargetToColor;
return true;
}
public void Reset()
{
m_UpdateFlag = false;
m_ValueEnable = false;
m_PreviousValue = float.NaN;
m_TargetColor = ColorUtil.clearColor32;
m_TargetToColor = ColorUtil.clearColor32;
m_PreviousColor = ColorUtil.clearColor32;
m_PreviousToColor = ColorUtil.clearColor32;
}
private bool IsValueEnable()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return false;
#endif
return m_ValueEnable;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8ab01b44ab2454ef7ac2d71313c3d707
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,3 @@
using System;
namespace XCharts.Runtime
@@ -13,7 +12,15 @@ namespace XCharts.Runtime
typeof(EndLabelStyle),
typeof(LineArrow),
typeof(AreaStyle),
typeof(Emphasis))]
typeof(EmphasisItemStyle),
typeof(EmphasisLabelStyle))]
[SerieDataExtraComponent(
typeof(ItemStyle),
typeof(LabelStyle),
typeof(SerieSymbol),
typeof(EmphasisItemStyle),
typeof(EmphasisLabelStyle))]
[SerieDataExtraField("m_Ignore")]
public class Line : Serie, INeedSerieContainer
{
public int containerIndex { get; internal set; }

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -14,13 +13,12 @@ namespace XCharts.Runtime
{
List<List<SerieData>> m_StackSerieData = new List<List<SerieData>>();
private GridCoord m_SerieGrid;
private float m_LastLineWidth = 0f;
public override Vector3 GetSerieDataLabelOffset(SerieData serieData, LabelStyle label)
{
var invert = label.autoOffset
&& SerieHelper.IsDownPoint(serie, serieData.index)
&& (serie.areaStyle == null || !serie.areaStyle.show);
var invert = label.autoOffset &&
SerieHelper.IsDownPoint(serie, serieData.index) &&
(serie.areaStyle == null || !serie.areaStyle.show);
if (invert)
{
var offset = label.GetOffset(serie.context.insideRadius);
@@ -37,7 +35,7 @@ namespace XCharts.Runtime
if (m_SerieGrid == null)
return;
var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
var needCheck = (chart.isPointerInChart && m_SerieGrid.IsPointerEnter()) || m_LegendEnter || m_LastLineWidth != lineWidth;
var needCheck = (chart.isPointerInChart && m_SerieGrid.IsPointerEnter()) || m_LegendEnter;
if (!needCheck)
{
if (m_LastCheckContextFlag != needCheck)
@@ -45,10 +43,10 @@ namespace XCharts.Runtime
m_LastCheckContextFlag = needCheck;
serie.context.pointerItemDataIndex = -1;
serie.context.pointerEnter = false;
serie.highlight = false;
serie.ResetInteract();
foreach (var serieData in serie.data)
{
serieData.interact.Reset();
}
serieData.context.highlight = false;
if (SeriesHelper.IsStack(chart.series))
chart.RefreshTopPainter();
else
@@ -56,7 +54,6 @@ namespace XCharts.Runtime
}
return;
}
m_LastLineWidth = lineWidth;
m_LastCheckContextFlag = needCheck;
var themeSymbolSize = chart.theme.serie.lineSymbolSize;
var themeSymbolSelectedSize = chart.theme.serie.lineSymbolSelectedSize;
@@ -146,6 +143,23 @@ namespace XCharts.Runtime
var theme = chart.theme;
var interacting = false;
var lineArrow = serie.lineArrow;
var visualMap = chart.GetVisualMapOfSerie(serie);
var isVisualMapGradient = VisualMapHelper.IsNeedLineGradient(visualMap);
var isY = ComponentHelper.IsAnyCategoryOfYAxis(chart.components);
Axis axis;
Axis relativedAxis;
if (isY)
{
axis = chart.GetChartComponent<YAxis>(serie.yAxisIndex);
relativedAxis = chart.GetChartComponent<XAxis>(serie.xAxisIndex);
}
else
{
axis = chart.GetChartComponent<XAxis>(serie.xAxisIndex);
relativedAxis = chart.GetChartComponent<YAxis>(serie.yAxisIndex);
}
for (int i = 0; i < count; i++)
{
var serieData = serie.GetSerieData(i);
@@ -172,20 +186,26 @@ namespace XCharts.Runtime
continue;
var highlight = serie.data[i].context.highlight || serie.highlight;
var symbolSize = highlight
? theme.serie.lineSymbolSelectedSize
: theme.serie.lineSymbolSize;
var symbolSize = highlight ?
theme.serie.lineSymbolSelectedSize :
theme.serie.lineSymbolSize;
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
{
symbolSize = highlight
? symbol.GetSelectedSize(serieData.data, symbolSize)
: symbol.GetSize(serieData.data, symbolSize);
symbolSize = highlight ?
symbol.GetSelectedSize(serieData.data, symbolSize) :
symbol.GetSize(serieData.data, symbolSize);
serieData.interact.SetValue(ref interacting, symbolSize);
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
}
var symbolColor = SerieHelper.GetItemColor(serie, serieData, theme, serie.index, highlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, theme, serie.index, highlight);
var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, theme, serie.index, highlight, false);
if (isVisualMapGradient)
{
symbolColor = VisualMapHelper.GetLineGradientColor(visualMap, pos, m_SerieGrid, axis, relativedAxis, symbolColor);
symbolToColor = symbolColor;
}
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, highlight);
var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, highlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
@@ -289,13 +309,13 @@ namespace XCharts.Runtime
var axisLength = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width;
var scaleWid = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
int rate = LineHelper.GetDataAverageRate(serie, m_SerieGrid, maxCount, false);
var totalAverage = serie.sampleAverage > 0
? serie.sampleAverage
: DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var totalAverage = serie.sampleAverage > 0 ?
serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();

View File

@@ -1,4 +1,3 @@
using UnityEngine;
using UnityEngine.UI;
using XUGL;
@@ -76,7 +75,7 @@ namespace XCharts.Runtime
var serieData = serie.data[i];
var angle0 = serieData.context.angle;
var angle1 = i >= serie.dataCount - 1 ? angle0 : serie.data[i + 1].context.angle;
if (pointerAngle >= angle0 && pointerAngle < angle1)
{
serie.context.pointerItemDataIndex = i;
@@ -146,7 +145,7 @@ namespace XCharts.Runtime
cp = GetPolarPos(m_SeriePolar, m_AngleAxis, datas[i], min, max, radius);
var np = i == datas.Count - 1 ? cp :
GetPolarPos(m_SeriePolar, m_AngleAxis, datas[i + 1], min, max, radius);
GetPolarPos(m_SeriePolar, m_AngleAxis, datas[i + 1], min, max, radius);
UGLHelper.GetLinePoints(lp, cp, np, lineWidth,
ref ltp, ref lbp,
@@ -214,13 +213,13 @@ namespace XCharts.Runtime
continue;
bool highlight = serieData.context.highlight || serie.highlight;
if ((!symbol.show || !symbol.ShowSymbol(i, count) || serie.IsPerformanceMode())
&& !serieData.context.highlight)
if ((!symbol.show || !symbol.ShowSymbol(i, count) || serie.IsPerformanceMode()) &&
!serieData.context.highlight)
continue;
var symbolSize = highlight
? symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSize)
: symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
var symbolSize = highlight ?
symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSize) :
symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, n, highlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, n, highlight);
@@ -243,15 +242,15 @@ namespace XCharts.Runtime
if (!m_AngleAxis.clockwise)
{
angle = m_AngleAxis.GetValueAngle((float)serieData.GetData(1));
angle = m_AngleAxis.GetValueAngle((float) serieData.GetData(1));
}
else
{
angle = m_AngleAxis.GetValueAngle((float)serieData.GetData(1));
angle = m_AngleAxis.GetValueAngle((float) serieData.GetData(1));
}
var value = serieData.GetData(0);
var radius = (float)((value - min) / (max - min) * polarRadius);
var radius = (float) ((value - min) / (max - min) * polarRadius);
angle = (angle + 360) % 360;
serieData.context.angle = angle;

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -69,7 +68,7 @@ namespace XCharts.Runtime
var endLabelList = m_SerieGrid.context.endLabelList;
if (endLabelList.Count <= 1) return;
endLabelList.Sort(delegate (ChartLabel a, ChartLabel b)
endLabelList.Sort(delegate(ChartLabel a, ChartLabel b)
{
if (a == null || b == null) return 1;
return b.transform.position.y.CompareTo(a.transform.position.y);

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -16,7 +15,7 @@ namespace XCharts.Runtime
var rate = 0;
var width = isYAxis ? grid.context.height : grid.context.width;
if (sampleDist > 0)
rate = (int)((maxCount - serie.minShow) / (width / sampleDist));
rate = (int) ((maxCount - serie.minShow) / (width / sampleDist));
if (rate < 1)
rate = 1;
return rate;
@@ -69,12 +68,12 @@ namespace XCharts.Runtime
var lp = Vector3.zero;
var isVisualMapGradient = VisualMapHelper.IsNeedAreaGradient(visualMap);
var areaLerp = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor);
var zsp = isY
? new Vector3(zero, points[0].position.y)
: new Vector3(points[0].position.x, zero);
var zep = isY
? new Vector3(zero, points[count - 1].position.y)
: new Vector3(points[count - 1].position.x, zero);
var zsp = isY ?
new Vector3(zero, points[0].position.y) :
new Vector3(points[0].position.x, zero);
var zep = isY ?
new Vector3(zero, points[count - 1].position.y) :
new Vector3(points[count - 1].position.x, zero);
var lastDataIsIgnore = false;
for (int i = 0; i < points.Count; i++)
@@ -189,8 +188,8 @@ namespace XCharts.Runtime
var ip = Vector3.zero;
if (UGLHelper.GetIntersection(ltp, tp,
new Vector3(progress, -10000),
new Vector3(progress, 10000), ref ip))
new Vector3(progress, -10000),
new Vector3(progress, 10000), ref ip))
tp = ip;
else
tp = new Vector3(progress, tp.y);
@@ -203,8 +202,8 @@ namespace XCharts.Runtime
var ip = Vector3.zero;
if (UGLHelper.GetIntersection(lbp, bp,
new Vector3(progress, -10000),
new Vector3(progress, 10000), ref ip))
new Vector3(progress, -10000),
new Vector3(progress, 10000), ref ip))
bp = ip;
else
bp = new Vector3(progress, bp.y);
@@ -335,7 +334,7 @@ namespace XCharts.Runtime
if (dataCount == 2 || isBreak)
{
AddLineVertToVertexHelper(vh, clp, crp, lineColor, isVisualMapGradient, isLineStyleGradient,
visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore);
visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore);
serie.context.lineEndPostion = cp;
serie.context.lineEndValue = AxisHelper.GetAxisPositionValue(grid, relativedAxis, cp);
break;
@@ -346,7 +345,7 @@ namespace XCharts.Runtime
{
if (bitp)
AddLineVertToVertexHelper(vh, itp, ibp, lineColor, isVisualMapGradient, isLineStyleGradient,
visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore);
visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore);
else
{
AddLineVertToVertexHelper(vh, ltp, clp, lineColor, isVisualMapGradient, isLineStyleGradient,
@@ -455,7 +454,7 @@ namespace XCharts.Runtime
var ignore = serie.context.dataIgnores[i];
var dir = (ep - sp).normalized;
var dist = Vector3.Distance(sp, ep);
var segment = (int)(dist / setting.lineSegmentDistance);
var segment = (int) (dist / setting.lineSegmentDistance);
serie.context.drawPoints.Add(new PointInfo(sp, ignore));
for (int j = 1; j < segment; j++)
{
@@ -516,8 +515,8 @@ namespace XCharts.Runtime
{
var cp = points[i];
var ignore = serie.context.dataIgnores[i];
if ((isY && Mathf.Abs(lp.x - cp.x) <= lineWidth)
|| (!isY && Mathf.Abs(lp.y - cp.y) <= lineWidth))
if ((isY && Mathf.Abs(lp.x - cp.x) <= lineWidth) ||
(!isY && Mathf.Abs(lp.y - cp.y) <= lineWidth))
{
serie.context.drawPoints.Add(new PointInfo(cp, ignore));
lp = cp;
@@ -526,22 +525,22 @@ namespace XCharts.Runtime
switch (serie.lineType)
{
case LineType.StepStart:
serie.context.drawPoints.Add(new PointInfo(isY
? new Vector3(cp.x, lp.y)
: new Vector3(lp.x, cp.y), ignore));
serie.context.drawPoints.Add(new PointInfo(isY ?
new Vector3(cp.x, lp.y) :
new Vector3(lp.x, cp.y), ignore));
break;
case LineType.StepMiddle:
serie.context.drawPoints.Add(new PointInfo(isY
? new Vector3(lp.x, (lp.y + cp.y) / 2)
: new Vector3((lp.x + cp.x) / 2, lp.y), ignore));
serie.context.drawPoints.Add(new PointInfo(isY
? new Vector3(cp.x, (lp.y + cp.y) / 2)
: new Vector3((lp.x + cp.x) / 2, cp.y), ignore));
serie.context.drawPoints.Add(new PointInfo(isY ?
new Vector3(lp.x, (lp.y + cp.y) / 2) :
new Vector3((lp.x + cp.x) / 2, lp.y), ignore));
serie.context.drawPoints.Add(new PointInfo(isY ?
new Vector3(cp.x, (lp.y + cp.y) / 2) :
new Vector3((lp.x + cp.x) / 2, cp.y), ignore));
break;
case LineType.StepEnd:
serie.context.drawPoints.Add(new PointInfo(isY
? new Vector3(lp.x, cp.y)
: new Vector3(cp.x, lp.y), ignore));
serie.context.drawPoints.Add(new PointInfo(isY ?
new Vector3(lp.x, cp.y) :
new Vector3(cp.x, lp.y), ignore));
break;
}
serie.context.drawPoints.Add(new PointInfo(cp, ignore));

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
@@ -10,6 +9,8 @@ namespace XCharts.Runtime
[CoordOptions(typeof(GridCoord))]
[DefaultAnimation(AnimationType.LeftToRight)]
[SerieExtraComponent(typeof(AreaStyle))]
[SerieDataExtraComponent()]
[SerieDataExtraField()]
public class SimplifiedLine : Serie, INeedSerieContainer, ISimplifiedSerie
{
public int containerIndex { get; internal set; }

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -183,13 +182,13 @@ namespace XCharts.Runtime
var axisLength = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width;
var scaleWid = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
int rate = LineHelper.GetDataAverageRate(serie, m_SerieGrid, maxCount, false);
var totalAverage = serie.sampleAverage > 0
? serie.sampleAverage
: DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var totalAverage = serie.sampleAverage > 0 ?
serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
@@ -7,6 +6,8 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(ParallelHandler), true)]
[RequireChartComponent(typeof(ParallelCoord))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraField()]
public class Parallel : Serie, INeedSerieContainer
{
public int containerIndex { get; internal set; }
@@ -19,12 +20,13 @@ namespace XCharts.Runtime
for (int i = 0; i < 100; i++)
{
var data = new List<double>(){
Random.Range(0f,50f),
Random.Range(0f,100f),
Random.Range(0f,1000f),
Random.Range(0,5),
};
var data = new List<double>()
{
Random.Range(0f, 50f),
Random.Range(0f, 100f),
Random.Range(0f, 1000f),
Random.Range(0, 5),
};
serie.AddData(data, "data" + i);
}
chart.RefreshChart();

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -23,8 +22,7 @@ namespace XCharts.Runtime
}
private void UpdateSerieContext()
{
}
{ }
private void DrawParallelSerie(VertexHelper vh, Parallel serie)
{
@@ -44,13 +42,13 @@ namespace XCharts.Runtime
var lineColor = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex, false);
var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
float currDetailProgress = !isHorizonal
? parallel.context.x
: parallel.context.y;
float currDetailProgress = !isHorizonal ?
parallel.context.x :
parallel.context.y;
float totalDetailProgress = !isHorizonal
? parallel.context.x + parallel.context.width
: parallel.context.y + parallel.context.height;
float totalDetailProgress = !isHorizonal ?
parallel.context.x + parallel.context.width :
parallel.context.y + parallel.context.height;
serie.animation.InitProgress(currDetailProgress, totalDetailProgress);

View File

@@ -1,14 +1,16 @@
namespace XCharts.Runtime
{
[System.Serializable]
[SerieConvert(typeof(Line), typeof(Bar))]
[SerieHandler(typeof(PieHandler), true)]
[DefaultAnimation(AnimationType.Clockwise)]
[SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(Emphasis))]
[SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(TitleStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle), typeof(EmphasisLabelLine))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(LabelLine), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle), typeof(EmphasisLabelLine))]
[SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")]
public class Pie : Serie
{
public override bool useDataNameForColor { get { return true; } }
public override bool titleJustForSerie { get { return true; } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName)
{

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
@@ -37,6 +36,11 @@ namespace XCharts.Runtime
return SerieLabelHelper.GetRealLabelPosition(serie, serieData, label, labelLine);
}
public override Vector3 GetSerieDataTitlePosition(SerieData serieData, TitleStyle titleStyle)
{
return serie.context.center;
}
public override void OnLegendButtonClick(int index, string legendName, bool show)
{
if (!serie.IsLegendName(legendName))
@@ -192,16 +196,16 @@ namespace XCharts.Runtime
{
continue;
}
float degree = serie.pieRoseType == RoseType.Area
? (totalDegree / showdataCount)
: (float)(totalDegree * value / dataTotalFilterMinAngle);
float degree = serie.pieRoseType == RoseType.Area ?
(totalDegree / showdataCount) :
(float) (totalDegree * value / dataTotalFilterMinAngle);
if (serie.minAngle > 0 && degree < serie.minAngle) degree = serie.minAngle;
serieData.context.toAngle = startDegree + degree;
if (serieData.radius > 0)
serieData.context.outsideRadius = serieData.radius;
serieData.context.outsideRadius = ChartHelper.GetActualValue(serieData.radius, Mathf.Min(chart.chartWidth, chart.chartHeight));
else
serieData.context.outsideRadius = serie.pieRoseType > 0 ?
serie.context.insideRadius + (float)((serie.context.outsideRadius - serie.context.insideRadius) * value / serie.context.dataMax) :
serie.context.insideRadius + (float) ((serie.context.outsideRadius - serie.context.insideRadius) * value / serie.context.dataMax) :
serie.context.outsideRadius;
if (serieData.context.highlight)
{
@@ -404,9 +408,9 @@ namespace XCharts.Runtime
{
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
var labelLine = SerieHelper.GetSerieLabelLine(serie, serieData);
if (serieLabel != null && serieLabel.show
&& labelLine != null && labelLine.show
&& (serieLabel.IsDefaultPosition(LabelStyle.Position.Outside)))
if (serieLabel != null && serieLabel.show &&
labelLine != null && labelLine.show &&
(serieLabel.IsDefaultPosition(LabelStyle.Position.Outside)))
{
var insideRadius = serieData.context.insideRadius;
var outSideRadius = serieData.context.outsideRadius;
@@ -469,8 +473,8 @@ namespace XCharts.Runtime
pos6 = pos0 + Vector3.left * lineCircleDiff;
pos4 = pos6 + Vector3.left * r4;
}
var pos5X = (currAngle - startAngle) % 360 > 180
? pos2.x - labelLine.lineLength2 : pos2.x + labelLine.lineLength2;
var pos5X = (currAngle - startAngle) % 360 > 180 ?
pos2.x - labelLine.lineLength2 : pos2.x + labelLine.lineLength2;
var pos5 = new Vector3(pos5X, pos2.y);
switch (labelLine.lineType)
{
@@ -506,9 +510,9 @@ namespace XCharts.Runtime
var serieData = serie.data[i];
if (angle >= serieData.context.startAngle && angle <= serieData.context.toAngle)
{
var ndist = serieData.selected
? Vector2.Distance(local, serieData.context.offsetCenter)
: dist;
var ndist = serieData.selected ?
Vector2.Distance(local, serieData.context.offsetCenter) :
dist;
if (ndist >= serieData.context.insideRadius && ndist <= serieData.context.outsideRadius)
{
return i;

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
@@ -7,13 +6,15 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(RadarHandler), true)]
[RequireChartComponent(typeof(RadarCoord))]
[SerieExtraComponent(typeof(LabelStyle), typeof(LabelLine), typeof(AreaStyle), typeof(Emphasis))]
[SerieExtraComponent(typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(AreaStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraField()]
public class Radar : Serie, INeedSerieContainer
{
public int containerIndex { get; internal set; }
public int containterInstanceId { get; internal set; }
public override bool useDataNameForColor { get { return true; } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName)
{
chart.AddChartComponentWhenNoExist<RadarCoord>();

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -67,6 +66,7 @@ namespace XCharts.Runtime
param.serieIndex = serie.index;
param.dimension = i;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = serieData.GetData(i);
param.total = indicator.max;
param.color = color;
@@ -85,8 +85,8 @@ namespace XCharts.Runtime
private void UpdateSerieContext()
{
var needCheck = m_LegendEnter
|| (chart.isPointerInChart && (m_RadarCoord != null && m_RadarCoord.IsPointerEnter()));
var needCheck = m_LegendEnter ||
(chart.isPointerInChart && (m_RadarCoord != null && m_RadarCoord.IsPointerEnter()));
var needInteract = false;
var needHideAll = false;
if (!needCheck)
@@ -249,7 +249,7 @@ namespace XCharts.Runtime
max = serie.context.dataMax;
}
}
var radius = (float)(m_RadarCoord.context.dataRadius * (value - min) / (max - min));
var radius = (float) (m_RadarCoord.context.dataRadius * (value - min) / (max - min));
var currAngle = (n + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate;
if (n == 0)
@@ -287,14 +287,14 @@ namespace XCharts.Runtime
for (int m = 0; m < serieData.context.dataPoints.Count; m++)
{
var point = serieData.context.dataPoints[m];
var symbolSize = isHighlight
? symbol.GetSelectedSize(null, chart.theme.serie.lineSymbolSelectedSize)
: symbol.GetSize(null, chart.theme.serie.lineSymbolSize);
var symbolSize = isHighlight ?
symbol.GetSelectedSize(null, chart.theme.serie.lineSymbolSelectedSize) :
symbol.GetSize(null, chart.theme.serie.lineSymbolSize);
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
{
symbolSize = isHighlight
? symbol.GetSelectedSize(serieData.data, symbolSize)
: symbol.GetSize(serieData.data, symbolSize);
symbolSize = isHighlight ?
symbol.GetSelectedSize(serieData.data, symbolSize) :
symbol.GetSize(serieData.data, symbolSize);
serieData.interact.SetValue(ref interacting, symbolSize);
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
}
@@ -305,7 +305,7 @@ namespace XCharts.Runtime
var borderColor = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, isHighlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor,
symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius);
symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius);
}
}
}
@@ -378,8 +378,8 @@ namespace XCharts.Runtime
{
lineColor = radar.outRangeColor;
}
var radius = (float)(max < 0 ? radar.context.dataRadius - radar.context.dataRadius * value / max
: radar.context.dataRadius * value / max);
var radius = (float) (max < 0 ? radar.context.dataRadius - radar.context.dataRadius * value / max :
radar.context.dataRadius * value / max);
var currAngle = (index + (radar.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate;
if (index == startIndex)
@@ -420,7 +420,7 @@ namespace XCharts.Runtime
{
if (radar.connectCenter)
ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos,
chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, firstPoint, chart.theme.serie.lineWidth,
LineStyle.Type.Solid, lineColor, radar.lineGradient ? firstColor : lineColor);
}
@@ -433,9 +433,9 @@ namespace XCharts.Runtime
if (!serieData.show) continue;
var isHighlight = serie.highlight || serieData.context.highlight || serie.context.pointerEnter;
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 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 symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false);
@@ -448,7 +448,7 @@ namespace XCharts.Runtime
symbolToColor = radar.outRangeColor;
}
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.context.labelPosition, symbolColor,
symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius);
symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius);
}
}
if (!serie.animation.IsFinish())
@@ -484,9 +484,9 @@ namespace XCharts.Runtime
{
if (serie.symbol.show && serie.symbol.type != SymbolType.None)
{
var symbolSize = isHighlight
? serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize)
: serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
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 symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false);
@@ -496,7 +496,7 @@ namespace XCharts.Runtime
foreach (var point in pointList)
{
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius);
symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius);
}
}
}

View File

@@ -1,11 +1,12 @@
using UnityEngine;
namespace XCharts.Runtime
{
[System.Serializable]
[SerieHandler(typeof(RingHandler), true)]
[SerieExtraComponent(typeof(LabelStyle), typeof(TitleStyle), typeof(Emphasis))]
[SerieExtraComponent(typeof(LabelStyle), typeof(TitleStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(TitleStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraField()]
public class Ring : Serie
{
public override bool useDataNameForColor { get { return true; } }

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -94,12 +93,13 @@ namespace XCharts.Runtime
param.category = category;
param.dimension = defaultDimension;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = serieData.GetData(0);
param.total = serieData.GetData(1);
param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, dataIndex, false);
param.marker = SerieHelper.GetItemMarker(serie, serieData, marker);
param.itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter);
param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter); ;
param.numericFormatter = SerieHelper.GetNumericFormatter(serie, serieData, numericFormatter);;
param.columns.Clear();
param.columns.Add(param.marker);
@@ -155,7 +155,7 @@ namespace XCharts.Runtime
if (serieData.IsDataChanged()) dataChanging = true;
var value = serieData.GetFirstData(dataChangeDuration);
var max = serieData.GetLastData();
var degree = (float)(360 * value / max);
var degree = (float) (360 * value / max);
var startDegree = GetStartAngle(serie);
var toDegree = GetToAngle(serie, degree);
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight);
@@ -215,8 +215,7 @@ namespace XCharts.Runtime
}
public override void OnPointerDown(PointerEventData eventData)
{
}
{ }
private float GetStartAngle(Serie serie)
{
@@ -281,11 +280,11 @@ namespace XCharts.Runtime
if (itemStyle.show && itemStyle.borderWidth > 0 && !ChartHelper.IsClearColor(itemStyle.borderColor))
{
UGL.DrawDoughnut(vh, serie.context.center, outsideRadius,
outsideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, chart.settings.cicleSmoothness);
outsideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, chart.settings.cicleSmoothness);
UGL.DrawDoughnut(vh, serie.context.center, insideRadius,
insideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, chart.settings.cicleSmoothness);
insideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, chart.settings.cicleSmoothness);
}
}

View File

@@ -1,4 +1,3 @@
namespace XCharts.Runtime
{
[System.Serializable]

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -35,6 +34,7 @@ namespace XCharts.Runtime
param.serieIndex = serie.index;
param.category = category;
param.dimension = 1;
param.dataCount = serie.dataCount;
param.serieData = serieData;
param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false);
param.marker = SerieHelper.GetItemMarker(serie, serieData, marker);
@@ -130,8 +130,8 @@ namespace XCharts.Runtime
var theme = chart.theme;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
: serie.dataCount;
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow) :
serie.dataCount;
serie.animation.InitProgress(0, 1);
var rate = serie.animation.GetCurrRate();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
@@ -175,14 +175,14 @@ namespace XCharts.Runtime
serie.context.dataPoints.Add(pos);
serieData.context.position = pos;
var datas = serieData.data;
var symbolSize = serie.highlight || serieData.context.highlight
? theme.serie.scatterSymbolSelectedSize
: theme.serie.scatterSymbolSize;
var symbolSize = serie.highlight || serieData.context.highlight ?
theme.serie.scatterSymbolSelectedSize :
theme.serie.scatterSymbolSize;
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
{
symbolSize = highlight
? symbol.GetSelectedSize(serieData.data, symbolSize)
: symbol.GetSize(serieData.data, symbolSize);
symbolSize = highlight ?
symbol.GetSelectedSize(serieData.data, symbolSize) :
symbol.GetSize(serieData.data, symbolSize);
serieData.interact.SetValue(ref interacting, symbolSize);
}
@@ -193,7 +193,7 @@ namespace XCharts.Runtime
for (int count = 0; count < symbol.animationSize.Count; count++)
{
var nowSize = symbol.animationSize[count];
color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize);
color.a = (byte) (255 * (symbolSize - nowSize) / symbolSize);
chart.DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos,
color, toColor, emptyColor, borderColor, symbol.gap, cornerRadius);
}
@@ -235,8 +235,8 @@ namespace XCharts.Runtime
var theme = chart.theme;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
: serie.dataCount;
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow) :
serie.dataCount;
serie.animation.InitProgress(0, 1);
var rate = serie.animation.GetCurrRate();
@@ -297,7 +297,7 @@ namespace XCharts.Runtime
for (int count = 0; count < symbol.animationSize.Count; count++)
{
var nowSize = symbol.animationSize[count];
color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize);
color.a = (byte) (255 * (symbolSize - nowSize) / symbolSize);
chart.DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos,
color, toColor, emptyColor, borderColor, symbol.gap, cornerRadius);
}
@@ -333,17 +333,17 @@ namespace XCharts.Runtime
{
if (axis.boundaryGap)
{
float tick = (float)(totalWidth / (axis.context.minMaxRange + 1));
return tick / 2 + (float)(value - axis.context.minValue) * tick;
float tick = (float) (totalWidth / (axis.context.minMaxRange + 1));
return tick / 2 + (float) (value - axis.context.minValue) * tick;
}
else
{
return (float)((value - axis.context.minValue) / axis.context.minMaxRange * totalWidth);
return (float) ((value - axis.context.minValue) / axis.context.minMaxRange * totalWidth);
}
}
else
{
return (float)((value - axis.context.minValue) / axis.context.minMaxRange * totalWidth);
return (float) ((value - axis.context.minValue) / axis.context.minMaxRange * totalWidth);
}
}
}

View File

@@ -1,4 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -6,7 +5,9 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(EffectScatterHandler), true)]
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
[SerieExtraComponent(typeof(LabelStyle), typeof(Emphasis))]
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraField("m_Radius")]
public class EffectScatter : BaseScatter
{
public static Serie AddDefaultSerie(BaseChart chart, string serieName)

View File

@@ -1,4 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime

View File

@@ -1,6 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -8,7 +5,9 @@ namespace XCharts.Runtime
[System.Serializable]
[SerieHandler(typeof(ScatterHandler), true)]
[CoordOptions(typeof(GridCoord), typeof(SingleAxisCoord))]
[SerieExtraComponent(typeof(LabelStyle), typeof(Emphasis))]
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
[SerieDataExtraField("m_Radius")]
public class Scatter : BaseScatter
{
public static Serie AddDefaultSerie(BaseChart chart, string serieName)

View File

@@ -1,8 +1,6 @@
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class ScatterHandler : BaseScatterHandler<Scatter>
{
}
{ }
}

View File

@@ -1,21 +1,22 @@
using UnityEngine;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace XCharts.Runtime
{
public partial class Serie
{
public static Dictionary<Type, string> extraComponentFieldNameDict = new Dictionary<Type, string>
{
{typeof(LabelStyle), "m_Labels"},
{typeof(LabelLine), "m_LabelLines"},
{typeof(EndLabelStyle), "m_EndLabels"},
{typeof(LineArrow), "m_LineArrows"},
{typeof(AreaStyle), "m_AreaStyles"},
{typeof(Emphasis), "m_Emphases"},
{typeof(TitleStyle), "m_TitleStyles"},
public static Dictionary<Type, string> extraComponentMap = new Dictionary<Type, string>
{ { typeof(LabelStyle), "m_Labels" },
{ typeof(LabelLine), "m_LabelLines" },
{ typeof(EndLabelStyle), "m_EndLabels" },
{ typeof(LineArrow), "m_LineArrows" },
{ typeof(AreaStyle), "m_AreaStyles" },
{ typeof(TitleStyle), "m_TitleStyles" },
{ typeof(EmphasisItemStyle), "m_EmphasisItemStyles" },
{ typeof(EmphasisLabelStyle), "m_EmphasisLabels" },
{ typeof(EmphasisLabelLine), "m_EmphasisLabelLines" },
};
[SerializeField] private List<LabelStyle> m_Labels = new List<LabelStyle>();
@@ -24,7 +25,9 @@ namespace XCharts.Runtime
[SerializeField] private List<LineArrow> m_LineArrows = new List<LineArrow>();
[SerializeField] private List<AreaStyle> m_AreaStyles = new List<AreaStyle>();
[SerializeField] private List<TitleStyle> m_TitleStyles = new List<TitleStyle>();
[SerializeField] private List<Emphasis> m_Emphases = new List<Emphasis>();
[SerializeField] private List<EmphasisItemStyle> m_EmphasisItemStyles = new List<EmphasisItemStyle>();
[SerializeField] private List<EmphasisLabelStyle> m_EmphasisLabels = new List<EmphasisLabelStyle>();
[SerializeField] private List<EmphasisLabelLine> m_EmphasisLabelLines = new List<EmphasisLabelLine>();
/// <summary>
/// The style of area.
@@ -48,9 +51,17 @@ namespace XCharts.Runtime
/// </summary>
public LineArrow lineArrow { get { return m_LineArrows.Count > 0 ? m_LineArrows[0] : null; } }
/// <summary>
/// 高亮的图形样式和文本标签样式。
/// 高亮的图形样式
/// </summary>
public Emphasis emphasis { get { return m_Emphases.Count > 0 ? m_Emphases[0] : null; } }
public EmphasisItemStyle emphasisItemStyle { get { return m_EmphasisItemStyles.Count > 0 ? m_EmphasisItemStyles[0] : null; } }
/// <summary>
/// 高亮时的标签样式
/// </summary>
public EmphasisLabelStyle emphasisLabel { get { return m_EmphasisLabels.Count > 0 ? m_EmphasisLabels[0] : null; } }
/// <summary>
/// 高亮时的标签引导线样式
/// </summary>
public EmphasisLabelLine emphasisLabelLine { get { return m_EmphasisLabelLines.Count > 0 ? m_EmphasisLabelLines[0] : null; } }
/// <summary>
/// the icon of data.
/// |数据项标题样式。
@@ -60,14 +71,14 @@ namespace XCharts.Runtime
public void RemoveAllExtraComponent()
{
var serieType = GetType();
foreach (var kv in extraComponentFieldNameDict)
foreach (var kv in extraComponentMap)
{
ReflectionUtil.InvokeListClear(this, serieType.GetField(kv.Value));
}
SetAllDirty();
}
public T AddExtraComponent<T>() where T : ChildComponent
public T AddExtraComponent<T>() where T : ChildComponent, ISerieExtraComponent
{
return AddExtraComponent(typeof(T)) as T;
}
@@ -80,7 +91,7 @@ namespace XCharts.Runtime
if (attr.Contains(type))
{
var fieldName = string.Empty;
if (extraComponentFieldNameDict.TryGetValue(type, out fieldName))
if (extraComponentMap.TryGetValue(type, out fieldName))
{
var field = typeof(Serie).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
if (ReflectionUtil.InvokeListCount(this, field) <= 0)
@@ -114,7 +125,7 @@ namespace XCharts.Runtime
if (attr.Contains(type))
{
var fieldName = string.Empty;
if (extraComponentFieldNameDict.TryGetValue(type, out fieldName))
if (extraComponentMap.TryGetValue(type, out fieldName))
{
var field = typeof(Serie).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
ReflectionUtil.InvokeListClear(this, field);

View File

@@ -1,4 +1,3 @@

using System;
using System.Collections.Generic;
using UnityEngine;
@@ -76,8 +75,6 @@ namespace XCharts.Runtime
Capsule
}
/// <summary>
/// 雷达图类型
/// </summary>
@@ -185,8 +182,8 @@ namespace XCharts.Runtime
[SerializeField] private LineType m_LineType = LineType.Normal;
[SerializeField] private BarType m_BarType = BarType.Normal;
[SerializeField] private bool m_BarPercentStack = false;
[SerializeField] private float m_BarWidth = 0.6f;
[SerializeField] private float m_BarGap = 0.3f; // 30%
[SerializeField] private float m_BarWidth = 0;
[SerializeField] private float m_BarGap = 0.1f;
[SerializeField] private float m_BarZebraWidth = 4f;
[SerializeField] private float m_BarZebraGap = 2f;
@@ -204,9 +201,9 @@ namespace XCharts.Runtime
[SerializeField] private RoseType m_RoseType = RoseType.None;
[SerializeField] private float m_Gap;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.48f };
[SerializeField] private float[] m_Radius = new float[2] { 0, 80 };
[SerializeField] private float[] m_Radius = new float[2] { 0, 0.28f };
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
[SerializeField][Range(1, 10)] private int m_ShowDataDimension;
[SerializeField] private bool m_ShowDataName;
[SerializeField] private bool m_ShowDataIcon;
[SerializeField] private bool m_Clip = false;
@@ -826,7 +823,7 @@ namespace XCharts.Runtime
(areaStyle != null && areaStyle.vertsDirty) ||
(label != null && label.vertsDirty) ||
(labelLine != null && labelLine.vertsDirty) ||
(emphasis != null && emphasis.vertsDirty) ||
(emphasisItemStyle != null && emphasisItemStyle.vertsDirty) ||
(titleStyle != null && titleStyle.vertsDirty) ||
AnySerieDataVerticesDirty();
}
@@ -836,11 +833,13 @@ namespace XCharts.Runtime
{
get
{
return m_ComponentDirty
|| symbol.componentDirty
|| (titleStyle != null && titleStyle.componentDirty)
|| (label != null && label.componentDirty)
|| (labelLine != null && labelLine.componentDirty);
return m_ComponentDirty ||
symbol.componentDirty ||
(titleStyle != null && titleStyle.componentDirty) ||
(label != null && label.componentDirty) ||
(labelLine != null && labelLine.componentDirty) ||
(emphasisLabel != null && emphasisLabel.componentDirty) ||
(emphasisLabelLine != null && emphasisLabelLine.componentDirty);
}
}
public override void ClearVerticesDirty()
@@ -855,8 +854,8 @@ namespace XCharts.Runtime
areaStyle.ClearVerticesDirty();
if (label != null)
label.ClearVerticesDirty();
if (emphasis != null)
emphasis.ClearVerticesDirty();
if (emphasisItemStyle != null)
emphasisItemStyle.ClearVerticesDirty();
if (lineArrow != null)
lineArrow.ClearVerticesDirty();
if (titleStyle != null)
@@ -875,8 +874,10 @@ namespace XCharts.Runtime
areaStyle.ClearComponentDirty();
if (label != null)
label.ClearComponentDirty();
if (emphasis != null)
emphasis.ClearComponentDirty();
if (emphasisLabel != null)
emphasisLabel.ClearComponentDirty();
if (emphasisLabelLine != null)
emphasisLabelLine.ClearComponentDirty();
if (lineArrow != null)
lineArrow.ClearComponentDirty();
if (titleStyle != null)
@@ -1061,6 +1062,7 @@ namespace XCharts.Runtime
public void ResetInteract()
{
interact.Reset();
foreach (var serieData in m_Data)
serieData.interact.Reset();
}
@@ -1451,8 +1453,8 @@ namespace XCharts.Runtime
/// <returns></returns>
public List<SerieData> GetDataList(DataZoom dataZoom = null)
{
if (dataZoom != null && dataZoom.enable
&& (dataZoom.IsContainsXAxis(xAxisIndex) || dataZoom.IsContainsYAxis(yAxisIndex)))
if (dataZoom != null && dataZoom.enable &&
(dataZoom.IsContainsXAxis(xAxisIndex) || dataZoom.IsContainsYAxis(yAxisIndex)))
{
SerieHelper.UpdateFilterData(this, dataZoom);
return m_FilterData;
@@ -1570,10 +1572,18 @@ namespace XCharts.Runtime
serieData.context.highlight = flag;
}
public float GetBarWidth(float categoryWidth)
public float GetBarWidth(float categoryWidth, int barCount = 0)
{
if (m_BarWidth > 1) return m_BarWidth;
else return m_BarWidth * categoryWidth;
if (m_BarWidth == 0)
{
var width = ChartHelper.GetActualValue(0.6f, categoryWidth);
if (barCount == 0)
return width < 1 ? categoryWidth : width;
else
return width / barCount;
}
else
return ChartHelper.GetActualValue(m_BarWidth, categoryWidth);
}
public bool IsIgnoreIndex(int index, int dimension = 1)
@@ -1586,9 +1596,7 @@ namespace XCharts.Runtime
public bool IsIgnoreValue(SerieData serieData, int dimension = 1)
{
if (serieData.baseInfo != null && serieData.baseInfo.ignore)
return true;
return IsIgnoreValue(serieData.GetData(dimension));
return serieData.ignore || IsIgnoreValue(serieData.GetData(dimension));
}
public bool IsIgnoreValue(double value)
@@ -1747,4 +1755,4 @@ namespace XCharts.Runtime
return newSerie;
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
@@ -105,5 +104,6 @@ namespace XCharts.Runtime
/// </summary>
public List<PointInfo> drawPoints = new List<PointInfo>();
public SerieParams param = new SerieParams();
public ChartLabel titleObject { get; set; }
}
}

View File

@@ -1,4 +1,3 @@

using System;
using System.Collections.Generic;
using UnityEngine;
@@ -13,19 +12,44 @@ namespace XCharts.Runtime
[System.Serializable]
public class SerieData : ChildComponent
{
public static List<string> extraFieldList = new List<string>()
{
"m_Id",
"m_ParentId",
"m_Ignore",
"m_Selected",
"m_Radius"
};
public static Dictionary<Type, string> extraComponentMap = new Dictionary<Type, string>
{ { typeof(ItemStyle), "m_ItemStyles" },
{ typeof(LabelStyle), "m_Labels" },
{ typeof(LabelLine), "m_LabelLines" },
{ typeof(SerieSymbol), "m_Symbols" },
{ typeof(LineStyle), "m_LineStyles" },
{ typeof(AreaStyle), "m_AreaStyles" },
{ typeof(TitleStyle), "m_TitleStyles" },
{ typeof(EmphasisItemStyle), "m_EmphasisItemStyles" },
{ typeof(EmphasisLabelStyle), "m_EmphasisLabels" },
{ typeof(EmphasisLabelLine), "m_EmphasisLabelLines" },
};
[SerializeField] private int m_Index;
[SerializeField] private string m_Name;
[SerializeField] private string m_Id;
[SerializeField] private string m_ParentId;
[SerializeField] private List<SerieDataBaseInfo> m_BaseInfos = new List<SerieDataBaseInfo>();
[SerializeField] private bool m_Ignore;
[SerializeField] private bool m_Selected;
[SerializeField] private float m_Radius;
[SerializeField] private List<ItemStyle> m_ItemStyles = new List<ItemStyle>();
[SerializeField] private List<LabelStyle> m_Labels = new List<LabelStyle>();
[SerializeField] private List<LabelLine> m_LabelLines = new List<LabelLine>();
[SerializeField] private List<Emphasis> m_Emphases = new List<Emphasis>();
[SerializeField] private List<SerieSymbol> m_Symbols = new List<SerieSymbol>();
[SerializeField] private List<LineStyle> m_LineStyles = new List<LineStyle>();
[SerializeField] private List<AreaStyle> m_AreaStyles = new List<AreaStyle>();
[SerializeField] private List<TitleStyle> m_TitleStyles = new List<TitleStyle>();
[SerializeField] private List<EmphasisItemStyle> m_EmphasisItemStyles = new List<EmphasisItemStyle>();
[SerializeField] private List<EmphasisLabelStyle> m_EmphasisLabels = new List<EmphasisLabelStyle>();
[SerializeField] private List<EmphasisLabelLine> m_EmphasisLabelLines = new List<EmphasisLabelLine>();
[SerializeField] private List<double> m_Data = new List<double>();
[NonSerialized] public SerieDataContext context = new SerieDataContext();
@@ -48,12 +72,28 @@ namespace XCharts.Runtime
public string id { get { return m_Id; } set { m_Id = value; } }
public string parentId { get { return m_ParentId; } set { m_ParentId = value; } }
/// <summary>
/// 是否忽略数据。当为 true 时,数据不进行绘制。
/// </summary>
public bool ignore
{
get { return m_Ignore; }
set { if (PropertyUtil.SetStruct(ref m_Ignore, value)) SetVerticesDirty(); }
}
/// <summary>
/// 自定义半径。可用在饼图中自定义某个数据项的半径。
/// </summary>
public float radius { get { return m_Radius; } set { m_Radius = value; } }
/// <summary>
/// Whether the data item is selected.
/// |该数据项是否被选中。
/// </summary>
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
/// <summary>
/// 数据项图例名称。当数据项名称不为空时图例名称即为系列名称反之则为索引index。
/// </summary>
/// <value></value>
public string legendName { get { return string.IsNullOrEmpty(name) ? ChartCached.IntToStr(index) : name; } }
public SerieDataBaseInfo baseInfo { get { return m_BaseInfos.Count > 0 ? m_BaseInfos[0] : null; } }
/// <summary>
/// 单个数据项的标签设置。
/// </summary>
@@ -64,16 +104,24 @@ namespace XCharts.Runtime
/// </summary>
public ItemStyle itemStyle { get { return m_ItemStyles.Count > 0 ? m_ItemStyles[0] : null; } }
/// <summary>
/// 单个数据项的高亮样式设置。
/// </summary>
public Emphasis emphasis { get { return m_Emphases.Count > 0 ? m_Emphases[0] : null; } }
/// <summary>
/// 单个数据项的标记设置。
/// </summary>
public SerieSymbol symbol { get { return m_Symbols.Count > 0 ? m_Symbols[0] : null; } }
public LineStyle lineStyle { get { return m_LineStyles.Count > 0 ? m_LineStyles[0] : null; } }
public AreaStyle areaStyle { get { return m_AreaStyles.Count > 0 ? m_AreaStyles[0] : null; } }
public TitleStyle titleStyle { get { return m_TitleStyles.Count > 0 ? m_TitleStyles[0] : null; } }
/// <summary>
/// 高亮的图形样式
/// </summary>
public EmphasisItemStyle emphasisItemStyle { get { return m_EmphasisItemStyles.Count > 0 ? m_EmphasisItemStyles[0] : null; } }
/// <summary>
/// 高亮时的标签样式
/// </summary>
public EmphasisLabelStyle emphasisLabel { get { return m_EmphasisLabels.Count > 0 ? m_EmphasisLabels[0] : null; } }
/// <summary>
/// 高亮时的标签引导线样式
/// </summary>
public EmphasisLabelLine emphasisLabelLine { get { return m_EmphasisLabelLines.Count > 0 ? m_EmphasisLabelLines[0] : null; } }
/// <summary>
/// An arbitrary dimension data list of data item.
@@ -85,8 +133,6 @@ namespace XCharts.Runtime
/// |该数据项是否要显示。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public float radius { get { return baseInfo != null ? baseInfo.radius : 0; } }
public bool selected { get { return (baseInfo != null && baseInfo.selected) || context.selected; } }
private List<double> m_PreviousData = new List<double>();
private List<float> m_DataUpdateTime = new List<float>();
@@ -97,50 +143,49 @@ namespace XCharts.Runtime
{
get
{
return m_VertsDirty
|| (baseInfo != null && baseInfo.vertsDirty)
|| (labelLine != null && labelLine.vertsDirty)
|| (itemStyle != null && itemStyle.vertsDirty)
|| (symbol != null && symbol.vertsDirty)
|| (lineStyle != null && lineStyle.vertsDirty)
|| (areaStyle != null && areaStyle.vertsDirty);
return m_VertsDirty ||
(labelLine != null && labelLine.vertsDirty) ||
(itemStyle != null && itemStyle.vertsDirty) ||
(symbol != null && symbol.vertsDirty) ||
(lineStyle != null && lineStyle.vertsDirty) ||
(areaStyle != null && areaStyle.vertsDirty) ||
(emphasisItemStyle != null && emphasisItemStyle.vertsDirty);
}
}
public override bool componentDirty
{
get
{
return m_ComponentDirty
|| (baseInfo != null && baseInfo.componentDirty)
|| (labelStyle != null && labelStyle.componentDirty)
|| (labelLine != null && labelLine.componentDirty)
|| (titleStyle != null && titleStyle.componentDirty)
|| (emphasis != null && emphasis.componentDirty);
return m_ComponentDirty ||
(labelStyle != null && labelStyle.componentDirty) ||
(labelLine != null && labelLine.componentDirty) ||
(titleStyle != null && titleStyle.componentDirty) ||
(emphasisLabel != null && emphasisLabel.componentDirty) ||
(emphasisLabelLine != null && emphasisLabelLine.componentDirty);
}
}
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
if (baseInfo != null) baseInfo.ClearVerticesDirty();
if (labelLine != null) labelLine.ClearVerticesDirty();
if (itemStyle != null) itemStyle.ClearVerticesDirty();
if (lineStyle != null) lineStyle.ClearVerticesDirty();
if (areaStyle != null) areaStyle.ClearVerticesDirty();
if (symbol != null) symbol.ClearVerticesDirty();
if (emphasis != null) emphasis.ClearVerticesDirty();
if (emphasisItemStyle != null) emphasisItemStyle.ClearVerticesDirty();
}
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
if (baseInfo != null) baseInfo.ClearComponentDirty();
if (labelLine != null) labelLine.ClearComponentDirty();
if (itemStyle != null) itemStyle.ClearComponentDirty();
if (lineStyle != null) lineStyle.ClearComponentDirty();
if (areaStyle != null) areaStyle.ClearComponentDirty();
if (symbol != null) symbol.ClearComponentDirty();
if (emphasis != null) emphasis.ClearComponentDirty();
if (emphasisLabel != null) emphasisLabel.ClearComponentDirty();
if (emphasisLabelLine != null) emphasisLabelLine.ClearComponentDirty();
}
public void Reset()
@@ -157,73 +202,84 @@ namespace XCharts.Runtime
m_PreviousData.Clear();
m_DataUpdateTime.Clear();
m_DataUpdateFlag.Clear();
m_BaseInfos.Clear();
m_Labels.Clear();
m_LabelLines.Clear();
m_ItemStyles.Clear();
m_Emphases.Clear();
m_Symbols.Clear();
m_LineStyles.Clear();
m_AreaStyles.Clear();
m_TitleStyles.Clear();
m_EmphasisItemStyles.Clear();
m_EmphasisLabels.Clear();
m_EmphasisLabelLines.Clear();
}
public T GetOrAddComponent<T>() where T : ChildComponent
public T GetOrAddComponent<T>() where T : ChildComponent, ISerieDataComponent
{
return GetOrAddComponent(typeof(T)) as T;
}
public ISerieDataComponent GetOrAddComponent(Type type)
{
var type = typeof(T);
if (type == typeof(ItemStyle))
{
if (m_ItemStyles.Count == 0)
m_ItemStyles.Add(new ItemStyle() { show = true });
return m_ItemStyles[0] as T;
}
else if (type == typeof(SerieDataBaseInfo))
{
if (m_BaseInfos.Count == 0)
m_BaseInfos.Add(new SerieDataBaseInfo() { });
return m_BaseInfos[0] as T;
return m_ItemStyles[0];
}
else if (type == typeof(LabelStyle))
{
if (m_Labels.Count == 0)
m_Labels.Add(new LabelStyle() { show = true });
return m_Labels[0] as T;
return m_Labels[0];
}
else if (type == typeof(LabelLine))
{
if (m_LabelLines.Count == 0)
m_LabelLines.Add(new LabelLine() { show = true });
return m_LabelLines[0] as T;
return m_LabelLines[0];
}
else if (type == typeof(Emphasis))
else if (type == typeof(EmphasisItemStyle))
{
if (m_Emphases.Count == 0)
m_Emphases.Add(new Emphasis() { show = true });
return m_Emphases[0] as T;
if (m_EmphasisItemStyles.Count == 0)
m_EmphasisItemStyles.Add(new EmphasisItemStyle() { show = true });
return m_EmphasisItemStyles[0];
}
else if (type == typeof(EmphasisLabelStyle))
{
if (m_EmphasisLabels.Count == 0)
m_EmphasisLabels.Add(new EmphasisLabelStyle() { show = true });
return m_EmphasisLabels[0];
}
else if (type == typeof(EmphasisLabelLine))
{
if (m_EmphasisLabelLines.Count == 0)
m_EmphasisLabelLines.Add(new EmphasisLabelLine() { show = true });
return m_EmphasisLabelLines[0];
}
else if (type == typeof(SerieSymbol))
{
if (m_Symbols.Count == 0)
m_Symbols.Add(new SerieSymbol() { show = true });
return m_Symbols[0] as T;
return m_Symbols[0];
}
else if (type == typeof(LineStyle))
{
if (m_LineStyles.Count == 0)
m_LineStyles.Add(new LineStyle() { show = true });
return m_LineStyles[0] as T;
return m_LineStyles[0];
}
else if (type == typeof(AreaStyle))
{
if (m_AreaStyles.Count == 0)
m_AreaStyles.Add(new AreaStyle() { show = true });
return m_AreaStyles[0] as T;
return m_AreaStyles[0];
}
else if (type == typeof(TitleStyle))
{
if (m_TitleStyles.Count == 0)
m_TitleStyles.Add(new TitleStyle() { show = true });
return m_TitleStyles[0] as T;
return m_TitleStyles[0];
}
else
{
@@ -233,12 +289,13 @@ namespace XCharts.Runtime
public void RemoveAllComponent()
{
m_BaseInfos.Clear();
m_ItemStyles.Clear();
m_Labels.Clear();
m_LabelLines.Clear();
m_Symbols.Clear();
m_Emphases.Clear();
m_EmphasisItemStyles.Clear();
m_EmphasisLabels.Clear();
m_EmphasisLabelLines.Clear();
m_LineStyles.Clear();
m_AreaStyles.Clear();
m_TitleStyles.Clear();
@@ -246,17 +303,23 @@ namespace XCharts.Runtime
public void RemoveComponent<T>() where T : ISerieDataComponent
{
var type = typeof(T);
RemoveComponent(typeof(T));
}
public void RemoveComponent(Type type)
{
if (type == typeof(ItemStyle))
m_ItemStyles.Clear();
else if (type == typeof(SerieDataBaseInfo))
m_BaseInfos.Clear();
else if (type == typeof(LabelStyle))
m_Labels.Clear();
else if (type == typeof(LabelLine))
m_LabelLines.Clear();
else if (type == typeof(Emphasis))
m_Emphases.Clear();
else if (type == typeof(EmphasisItemStyle))
m_EmphasisItemStyles.Clear();
else if (type == typeof(EmphasisLabelStyle))
m_EmphasisLabels.Clear();
else if (type == typeof(EmphasisLabelLine))
m_EmphasisLabelLines.Clear();
else if (type == typeof(SerieSymbol))
m_Symbols.Clear();
else if (type == typeof(LineStyle))
@@ -483,4 +546,4 @@ namespace XCharts.Runtime
return UGLHelper.IsPointInPolygon(p, m_PolygonPoints);
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -57,7 +56,15 @@ namespace XCharts.Runtime
/// Whether the data item is highlighted.
/// |该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
/// </summary>
public bool highlight;
public bool highlight
{
get { return m_Highligth; }
set
{
m_Highligth = value;
}
}
private bool m_Highligth;
public bool selected;
public void Reset()

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -34,8 +33,7 @@ namespace XCharts.Runtime
public virtual void UpdateTooltipSerieParams(int dataIndex, bool showCategory,
string category, string marker,
string itemFormatter, string numericFormatter,
ref List<SerieParams> paramList, ref string title)
{ }
ref List<SerieParams> paramList, ref string title) { }
public virtual void OnLegendButtonClick(int index, string legendName, bool show) { }
public virtual void OnLegendButtonEnter(int index, string legendName) { }
public virtual void OnLegendButtonExit(int index, string legendName) { }
@@ -63,7 +61,7 @@ namespace XCharts.Runtime
internal override void SetSerie(Serie serie)
{
this.serie = (T)serie;
this.serie = (T) serie;
this.serie.context.param.serieType = typeof(T);
m_NeedInitComponent = true;
AnimationStyleHelper.UpdateSerieAnimation(serie);
@@ -119,6 +117,7 @@ namespace XCharts.Runtime
if (serie.vertsDirty)
{
chart.RefreshPainter(serie);
serie.ResetInteract();
serie.ClearVerticesDirty();
}
}
@@ -220,7 +219,7 @@ namespace XCharts.Runtime
var serieData = serie.data[j];
serieData.index = count;
serieData.labelObject = null;
if (AddSerieLabel(m_SerieLabelRoot, serie, serieData, ref count))
if (AddSerieLabel(m_SerieLabelRoot, serieData, ref count))
{
m_InitedLabel = true;
count++;
@@ -229,7 +228,7 @@ namespace XCharts.Runtime
RefreshLabelInternal();
}
protected bool AddSerieLabel(GameObject serieLabelRoot, Serie serie, SerieData serieData, ref int count)
protected bool AddSerieLabel(GameObject serieLabelRoot, SerieData serieData, ref int count)
{
if (serieData == null)
return false;
@@ -245,15 +244,14 @@ namespace XCharts.Runtime
var serieEmphasisLabel = SerieHelper.GetSerieEmphasisLabel(serie, serieData);
if (!serieLabel.show
&& (serieEmphasisLabel == null || !serieEmphasisLabel.show))
if (!serieLabel.show &&
(serieEmphasisLabel == null || !serieEmphasisLabel.show))
return false;
var colorIndex = serie.useDataNameForColor ? serieData.index : serie.index;
var dataAutoColor = (Color)SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false);
var dataAutoColor = GetSerieDataAutoColor(serieData);
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common,
"", dataAutoColor, TextAnchor.MiddleCenter);
"", dataAutoColor, TextAnchor.MiddleCenter);
label.SetActive(serieLabel.show);
serieData.labelObject = label;
@@ -261,7 +259,7 @@ namespace XCharts.Runtime
{
foreach (var childSerieData in serieData.context.children)
{
AddSerieLabel(serieLabelRoot, serie, childSerieData, ref count);
AddSerieLabel(serieLabelRoot, childSerieData, ref count);
count++;
}
}
@@ -280,7 +278,7 @@ namespace XCharts.Runtime
return;
}
InitRoot();
var dataAutoColor = (Color)chart.GetLegendRealShowNameColor(serie.legendName);
var dataAutoColor = (Color) chart.GetLegendRealShowNameColor(serie.legendName);
m_EndLabel = ChartHelper.AddChartLabel(s_SerieEndLabelObjectName, m_SerieRoot.transform, serie.endLabel,
chart.theme.common, "", dataAutoColor, TextAnchor.MiddleLeft);
m_EndLabel.SetActive(serie.endLabel.show);
@@ -297,19 +295,59 @@ namespace XCharts.Runtime
ChartHelper.RemoveComponent<Text>(serieTitleRoot);
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
for (int i = 0; i < serie.dataCount; i++)
if (serie.titleJustForSerie)
{
var serieData = serie.data[i];
var titleStyle = SerieHelper.GetTitleStyle(serie, serieData);
if (titleStyle == null) continue;
var color = chart.GetItemColor(serie, serieData);
var label = ChartHelper.AddChartLabel("title_" + i, serieTitleRoot.transform, titleStyle, chart.theme.common,
serieData.name, color, TextAnchor.MiddleCenter);
serieData.titleObject = label;
label.SetActive(titleStyle.show);
var labelPosition = GetSerieDataTitlePosition(serieData, titleStyle);
var offset = titleStyle.GetOffset(serie.context.insideRadius);
label.SetPosition(labelPosition + offset);
var titleStyle = SerieHelper.GetTitleStyle(serie, null);
if (titleStyle != null)
{
var color = chart.GetItemColor(serie, null);
var content = string.Empty;
if (string.IsNullOrEmpty(titleStyle.formatter))
{
content = serie.serieName;
}
else
{
content = titleStyle.formatter;
FormatterHelper.ReplaceContent(ref content, 0, titleStyle.numericFormatter, serie, chart);
}
var label = ChartHelper.AddChartLabel("title_" + 0, serieTitleRoot.transform, titleStyle, chart.theme.common,
content, color, TextAnchor.MiddleCenter);
serie.context.titleObject = label;
label.SetActive(titleStyle.show);
var labelPosition = GetSerieDataTitlePosition(null, titleStyle);
var offset = titleStyle.GetOffset(serie.context.insideRadius);
label.SetPosition(labelPosition + offset);
}
}
else
{
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
var titleStyle = SerieHelper.GetTitleStyle(serie, serieData);
if (titleStyle == null) continue;
var color = chart.GetItemColor(serie, serieData);
var content = string.Empty;
if (string.IsNullOrEmpty(titleStyle.formatter))
{
content = serieData.name;
}
else
{
content = titleStyle.formatter;
FormatterHelper.ReplaceContent(ref content, 0, titleStyle.numericFormatter, serie, chart);
}
FormatterHelper.ReplaceContent(ref content, i, titleStyle.numericFormatter, serie, chart);
var label = ChartHelper.AddChartLabel("title_" + i, serieTitleRoot.transform, titleStyle, chart.theme.common,
content, color, TextAnchor.MiddleCenter);
serieData.titleObject = label;
label.SetActive(titleStyle.show);
var labelPosition = GetSerieDataTitlePosition(serieData, titleStyle);
var offset = titleStyle.GetOffset(serie.context.insideRadius);
label.SetPosition(labelPosition + offset);
}
}
}
@@ -319,7 +357,6 @@ namespace XCharts.Runtime
return;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
foreach (var serieData in serie.data)
{
if (serieData.labelObject == null)
@@ -329,23 +366,29 @@ namespace XCharts.Runtime
var isHighlight = (serieData.context.highlight && emphasisLabel != null && emphasisLabel.show);
var isIgnore = serie.IsIgnoreIndex(serieData.index, defaultDimension);
var currLabel = isHighlight && emphasisLabel != null ? emphasisLabel : serieLabel;
if (serie.show
&& currLabel != null
&& (currLabel.show || isHighlight)
&& serieData.context.canShowLabel
&& !isIgnore)
if (serie.show &&
currLabel != null &&
(currLabel.show || isHighlight) &&
serieData.context.canShowLabel &&
!isIgnore)
{
var value = serieData.GetCurrData(defaultDimension, dataChangeDuration);
var total = serie.GetDataTotal(defaultDimension, serieData);
var color = chart.GetItemColor(serie, serieData);
var content = string.IsNullOrEmpty(currLabel.formatter)
? ChartCached.NumberToStr(value, serieLabel.numericFormatter)
: SerieLabelHelper.GetFormatterContent(serie, serieData, value, total,
var content = string.IsNullOrEmpty(currLabel.formatter) ?
ChartCached.NumberToStr(value, serieLabel.numericFormatter) :
SerieLabelHelper.GetFormatterContent(serie, serieData, value, total,
currLabel, color);
serieData.SetLabelActive(!isIgnore);
serieData.labelObject.SetText(content);
UpdateLabelPosition(serieData, currLabel);
if (currLabel.textStyle.autoColor)
{
var dataAutoColor = GetSerieDataAutoColor(serieData);
if (!ChartHelper.IsClearColor(dataAutoColor))
serieData.labelObject.SetTextColor(dataAutoColor);
}
}
else
{
@@ -368,7 +411,7 @@ namespace XCharts.Runtime
{
var value = serie.context.lineEndValue;
var content = SerieLabelHelper.GetFormatterContent(serie, null, value, 0,
endLabelStyle, Color.clear);
endLabelStyle, Color.clear);
m_EndLabel.SetText(content);
m_EndLabel.SetPosition(serie.context.lineEndPostion + endLabelStyle.offset);
}
@@ -384,9 +427,9 @@ namespace XCharts.Runtime
public virtual Vector3 GetSerieDataLabelPosition(SerieData serieData, LabelStyle label)
{
return ChartHelper.IsZeroVector(serieData.context.labelPosition)
? serieData.context.position
: serieData.context.labelPosition;
return ChartHelper.IsZeroVector(serieData.context.labelPosition) ?
serieData.context.position :
serieData.context.labelPosition;
}
public virtual Vector3 GetSerieDataLabelOffset(SerieData serieData, LabelStyle label)
@@ -399,6 +442,12 @@ namespace XCharts.Runtime
return serieData.context.position;
}
public virtual Color GetSerieDataAutoColor(SerieData serieData)
{
var colorIndex = serie.useDataNameForColor ? serieData.index : serie.index;
return (Color) SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false, false);
}
protected void UpdateCoordSerieParams(ref List<SerieParams> paramList, ref string title,
int dataIndex, bool showCategory, string category, string marker,
string itemFormatter, string numericFormatter)
@@ -423,6 +472,7 @@ namespace XCharts.Runtime
param.category = category;
param.dimension = 1;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = serieData.GetData(1);
param.total = serie.yTotal;
param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false);
@@ -464,6 +514,7 @@ namespace XCharts.Runtime
param.category = category;
param.dimension = dimension;
param.serieData = serieData;
param.dataCount = serie.dataCount;
param.value = serieData.GetData(param.dimension);
param.total = SerieHelper.GetMaxData(serie, dimension);
param.color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false);

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -14,6 +13,7 @@ namespace XCharts.Runtime
public string category;
public int dimension;
public SerieData serieData;
public int dataCount;
public double value;
public double total;
public Color32 color;