mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 18:00:26 +00:00
重构代码
This commit is contained in:
@@ -175,8 +175,8 @@ namespace XCharts
|
||||
if (m_Series.anyDirty)
|
||||
{
|
||||
if (m_Series.vertsDirty) RefreshChart();
|
||||
if (m_Series.labelDirty) m_ReinitLabel = true;
|
||||
if (m_Series.labelUpdate && !m_RefreshChart) m_RefreshLabel = true;
|
||||
if (SeriesHelper.IsLabelDirty(m_Series)) m_ReinitLabel = true;
|
||||
if (SeriesHelper.IsNeedLabelUpdate(m_Series) && !m_RefreshChart) m_RefreshLabel = true;
|
||||
foreach (var serie in m_Series.list)
|
||||
{
|
||||
if (serie.titleStyle.componentDirty) m_ReinitTitle = true;
|
||||
@@ -285,8 +285,7 @@ namespace XCharts
|
||||
var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(chartWidth, chartHeight));
|
||||
legendObject.transform.localPosition = GetLegendPosition();
|
||||
|
||||
m_LegendRealShowName = m_Series.GetSerieNameList();
|
||||
SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName);
|
||||
List<string> datas;
|
||||
if (m_Legend.show && m_Legend.data.Count > 0)
|
||||
{
|
||||
@@ -303,7 +302,7 @@ namespace XCharts
|
||||
int totalLegend = 0;
|
||||
for (int i = 0; i < datas.Count; i++)
|
||||
{
|
||||
if (!m_Series.IsLegalLegendName(datas[i])) continue;
|
||||
if (!SeriesHelper.IsLegalLegendName(datas[i])) continue;
|
||||
totalLegend++;
|
||||
}
|
||||
m_Legend.RemoveButton();
|
||||
@@ -311,7 +310,7 @@ namespace XCharts
|
||||
if (!m_Legend.show) return;
|
||||
for (int i = 0; i < datas.Count; i++)
|
||||
{
|
||||
if (!m_Series.IsLegalLegendName(datas[i])) continue;
|
||||
if (!SeriesHelper.IsLegalLegendName(datas[i])) continue;
|
||||
string legendName = m_Legend.GetFormatterContent(datas[i]);
|
||||
var readIndex = m_LegendRealShowName.IndexOf(datas[i]);
|
||||
var active = IsActiveByLegend(datas[i]);
|
||||
@@ -621,7 +620,7 @@ namespace XCharts
|
||||
if (m_ReinitLabel)
|
||||
{
|
||||
m_ReinitLabel = false;
|
||||
m_LegendRealShowName = m_Series.GetSerieNameList();
|
||||
SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName);
|
||||
InitSerieLabel();
|
||||
}
|
||||
if (m_ReinitTitle)
|
||||
@@ -690,57 +689,6 @@ namespace XCharts
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected bool CheckDataShow(string legendName, bool show)
|
||||
{
|
||||
bool needShow = false;
|
||||
foreach (var serie in m_Series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.show = show;
|
||||
serie.highlighted = false;
|
||||
if (serie.show) needShow = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.show = show;
|
||||
data.highlighted = false;
|
||||
if (data.show) needShow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return needShow;
|
||||
}
|
||||
|
||||
protected bool CheckDataHighlighted(string legendName, bool heighlight)
|
||||
{
|
||||
bool show = false;
|
||||
foreach (var serie in m_Series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.highlighted = heighlight;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.highlighted = heighlight;
|
||||
if (data.highlighted) show = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return show;
|
||||
}
|
||||
|
||||
protected virtual void UpdateTooltip()
|
||||
{
|
||||
}
|
||||
@@ -775,100 +723,18 @@ namespace XCharts
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.backgroundColor);
|
||||
}
|
||||
|
||||
protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
|
||||
float tickness, Vector3 pos, Color color, Color toColor, float gap, float[] cornerRadius)
|
||||
public void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
|
||||
float tickness, Vector3 pos, Color color, Color toColor, float gap, float[] cornerRadius)
|
||||
{
|
||||
var backgroundColor = m_ThemeInfo.backgroundColor;
|
||||
var smoothness = m_Settings.cicleSmoothness;
|
||||
switch (type)
|
||||
{
|
||||
case SerieSymbolType.None:
|
||||
break;
|
||||
case SerieSymbolType.Circle:
|
||||
if (gap > 0)
|
||||
{
|
||||
ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, color, toColor, smoothness);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.EmptyCircle:
|
||||
if (gap > 0)
|
||||
{
|
||||
ChartDrawer.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
|
||||
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.Rect:
|
||||
if (gap > 0)
|
||||
{
|
||||
ChartDrawer.DrawPolygon(vh, pos, symbolSize + gap, backgroundColor);
|
||||
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor);
|
||||
ChartDrawer.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, 0, cornerRadius);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.Triangle:
|
||||
if (gap > 0)
|
||||
{
|
||||
ChartDrawer.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
|
||||
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
break;
|
||||
case SerieSymbolType.Diamond:
|
||||
if (gap > 0)
|
||||
{
|
||||
ChartDrawer.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
|
||||
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawLineStyle(VertexHelper vh, LineStyle lineStyle,
|
||||
Vector3 startPos, Vector3 endPos, Color color)
|
||||
{
|
||||
var type = lineStyle.type;
|
||||
var width = lineStyle.width;
|
||||
switch (type)
|
||||
{
|
||||
case LineStyle.Type.Dashed:
|
||||
ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case LineStyle.Type.Dotted:
|
||||
ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case LineStyle.Type.Solid:
|
||||
ChartDrawer.DrawLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case LineStyle.Type.DashDot:
|
||||
ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case LineStyle.Type.DashDotDot:
|
||||
ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
}
|
||||
ChartDrawer.DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap,
|
||||
cornerRadius, backgroundColor, smoothness);
|
||||
}
|
||||
|
||||
protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
|
||||
{
|
||||
if (serieData == null || serieData.labelObject == null) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
if (!serieLabel.show) return;
|
||||
var invert = serie.type == SerieType.Line
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace XCharts
|
||||
|
||||
protected override void DrawBackground(VertexHelper vh)
|
||||
{
|
||||
if (m_Series.IsAnyClipSerie())
|
||||
if (SeriesHelper.IsAnyClipSerie(m_Series))
|
||||
{
|
||||
var xLineDiff = xAxis0.axisLine.width;
|
||||
var yLineDiff = yAxis0.axisLine.width;
|
||||
@@ -167,7 +167,7 @@ namespace XCharts
|
||||
|
||||
protected void DrawClip(VertexHelper vh)
|
||||
{
|
||||
if (!m_Series.IsAnyClipSerie()) return;
|
||||
if (!SeriesHelper.IsAnyClipSerie(m_Series)) return;
|
||||
var xLineDiff = xAxis0.axisLine.width;
|
||||
var yLineDiff = yAxis0.axisLine.width;
|
||||
var xSplitDiff = xAxis0.splitLine.lineStyle.width;
|
||||
@@ -200,7 +200,7 @@ namespace XCharts
|
||||
if (!m_CheckMinMaxValue) return;
|
||||
m_IsPlayingAnimation = false;
|
||||
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
|
||||
m_Series.GetStackSeries(ref m_StackSeries);
|
||||
SeriesHelper.GetStackSeries(m_Series, ref m_StackSeries);
|
||||
int seriesCount = m_StackSeries.Count;
|
||||
m_BarLastOffset = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
@@ -300,7 +300,7 @@ namespace XCharts
|
||||
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
@@ -312,7 +312,7 @@ namespace XCharts
|
||||
}
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
@@ -329,7 +329,7 @@ namespace XCharts
|
||||
m_Tooltip.runtimeYValues[i] = value;
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
@@ -347,7 +347,7 @@ namespace XCharts
|
||||
m_Tooltip.runtimeXValues[i] = value;
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
@@ -443,7 +443,7 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
labelText = axis.GetData((int)m_Tooltip.runtimeXValues[axisIndex], m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(m_CoordinateWidth, m_DataZoom);
|
||||
float splitWidth = AxisHelper.GetSplitWidth(axis, m_CoordinateWidth, m_DataZoom);
|
||||
int index = (int)m_Tooltip.runtimeXValues[axisIndex];
|
||||
float px = m_CoordinateX + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0) + 0.5f;
|
||||
labelPos = new Vector2(px, posY - diff);
|
||||
@@ -461,7 +461,7 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
labelText = axis.GetData((int)m_Tooltip.runtimeYValues[axisIndex], m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(m_CoordinateHeight, m_DataZoom);
|
||||
float splitWidth = AxisHelper.GetSplitWidth(axis, m_CoordinateHeight, m_DataZoom);
|
||||
int index = (int)m_Tooltip.runtimeYValues[axisIndex];
|
||||
float py = m_CoordinateY + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0);
|
||||
labelPos = new Vector2(posX - diff, py);
|
||||
@@ -525,7 +525,7 @@ namespace XCharts
|
||||
var labelColor = ChartHelper.IsClearColor(yAxis.axisLabel.color) ?
|
||||
(Color)m_ThemeInfo.axisTextColor :
|
||||
yAxis.axisLabel.color;
|
||||
int splitNumber = yAxis.GetSplitNumber(m_CoordinateHeight, m_DataZoom);
|
||||
int splitNumber = AxisHelper.GetSplitNumber(yAxis, m_CoordinateHeight, m_DataZoom);
|
||||
float totalWidth = 0;
|
||||
for (int i = 0; i < splitNumber; i++)
|
||||
{
|
||||
@@ -546,12 +546,12 @@ namespace XCharts
|
||||
yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle);
|
||||
}
|
||||
|
||||
float labelWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom);
|
||||
float labelWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i, m_DataZoom);
|
||||
if (i == 0) yAxis.axisLabel.SetRelatedText(txt, labelWidth);
|
||||
txt.transform.localPosition = GetLabelYPosition(totalWidth + (yAxis.boundaryGap ? labelWidth / 2 : 0), i, yAxisIndex, yAxis);
|
||||
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
txt.text = yAxis.GetLabelName(m_CoordinateHeight, i, yAxis.runtimeMinValue, yAxis.runtimeMaxValue, m_DataZoom, isPercentStack);
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
txt.text = AxisHelper.GetLabelName(yAxis, m_CoordinateHeight, i, yAxis.runtimeMinValue, yAxis.runtimeMaxValue, m_DataZoom, isPercentStack);
|
||||
txt.gameObject.SetActive(yAxis.show &&
|
||||
(yAxis.axisLabel.interval == 0 || i % (yAxis.axisLabel.interval + 1) == 0));
|
||||
yAxis.axisLabelTextList.Add(txt);
|
||||
@@ -630,11 +630,11 @@ namespace XCharts
|
||||
var labelColor = ChartHelper.IsClearColor(xAxis.axisLabel.color) ?
|
||||
(Color)m_ThemeInfo.axisTextColor :
|
||||
xAxis.axisLabel.color;
|
||||
int splitNumber = xAxis.GetSplitNumber(m_CoordinateWidth, m_DataZoom);
|
||||
int splitNumber = AxisHelper.GetSplitNumber(xAxis, m_CoordinateWidth, m_DataZoom);
|
||||
float totalWidth = 0;
|
||||
for (int i = 0; i < splitNumber; i++)
|
||||
{
|
||||
float labelWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom);
|
||||
float labelWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i, m_DataZoom);
|
||||
bool inside = xAxis.axisLabel.inside;
|
||||
Text txt = ChartHelper.AddTextObject(ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform,
|
||||
m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0, 1),
|
||||
@@ -644,8 +644,8 @@ namespace XCharts
|
||||
txt.transform.localPosition = GetLabelXPosition(totalWidth + (xAxis.boundaryGap ? labelWidth : labelWidth / 2),
|
||||
i, xAxisIndex, xAxis);
|
||||
totalWidth += labelWidth;
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
txt.text = xAxis.GetLabelName(m_CoordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom,
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
txt.text = AxisHelper.GetLabelName(xAxis, m_CoordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom,
|
||||
isPercentStack);
|
||||
txt.gameObject.SetActive(xAxis.show &&
|
||||
(xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0));
|
||||
@@ -790,18 +790,18 @@ namespace XCharts
|
||||
{
|
||||
if (axis is XAxis)
|
||||
{
|
||||
m_Series.GetXMinMaxValue(null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue);
|
||||
SeriesHelper.GetXMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Series.GetYMinMaxValue(null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue);
|
||||
SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Series.GetYMinMaxValue(null, axisIndex, false, axis.inverse, out tempMinValue, out tempMaxValue);
|
||||
SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, false, axis.inverse, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue, true);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
|
||||
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
|
||||
{
|
||||
m_CheckMinMaxValue = true;
|
||||
@@ -843,7 +843,7 @@ namespace XCharts
|
||||
protected void UpdateAxisLabelText(Axis axis)
|
||||
{
|
||||
float m_CoordinateWidth = axis is XAxis ? this.m_CoordinateWidth : m_CoordinateHeight;
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
axis.UpdateLabelText(m_CoordinateWidth, m_DataZoom, isPercentStack, 500);
|
||||
}
|
||||
|
||||
@@ -907,15 +907,15 @@ namespace XCharts
|
||||
|
||||
private void DrawYAxisSplit(VertexHelper vh, int yAxisIndex, YAxis yAxis)
|
||||
{
|
||||
if (yAxis.NeedShowSplit())
|
||||
if (AxisHelper.NeedShowSplit(yAxis))
|
||||
{
|
||||
var size = yAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var size = AxisHelper.GetScaleNumber(yAxis, m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateY;
|
||||
var xAxis = m_XAxises[yAxisIndex];
|
||||
var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY + yAxis.runtimeZeroYOffset);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom);
|
||||
var scaleWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i, m_DataZoom);
|
||||
float pY = totalWidth;
|
||||
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
@@ -935,7 +935,7 @@ namespace XCharts
|
||||
{
|
||||
if (yAxis.splitLine.NeedShow(i))
|
||||
{
|
||||
DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(m_CoordinateX, pY),
|
||||
ChartDrawer.DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(m_CoordinateX, pY),
|
||||
new Vector3(m_CoordinateX + m_CoordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
}
|
||||
}
|
||||
@@ -947,14 +947,14 @@ namespace XCharts
|
||||
|
||||
private void DrawYAxisTick(VertexHelper vh, int yAxisIndex, YAxis yAxis)
|
||||
{
|
||||
if (yAxis.NeedShowSplit())
|
||||
if (AxisHelper.NeedShowSplit(yAxis))
|
||||
{
|
||||
var size = yAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var size = AxisHelper.GetScaleNumber(yAxis, m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateY;
|
||||
var xAxis = m_XAxises[yAxisIndex];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom);
|
||||
var scaleWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i, m_DataZoom);
|
||||
float pX = 0;
|
||||
float pY = totalWidth;
|
||||
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel)
|
||||
@@ -997,15 +997,15 @@ namespace XCharts
|
||||
|
||||
private void DrawXAxisSplit(VertexHelper vh, int xAxisIndex, XAxis xAxis)
|
||||
{
|
||||
if (xAxis.NeedShowSplit())
|
||||
if (AxisHelper.NeedShowSplit(xAxis))
|
||||
{
|
||||
var size = xAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var size = AxisHelper.GetScaleNumber(xAxis, m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateX;
|
||||
var yAxis = m_YAxises[xAxisIndex];
|
||||
var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom);
|
||||
var scaleWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i, m_DataZoom);
|
||||
float pX = totalWidth;
|
||||
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
@@ -1025,7 +1025,7 @@ namespace XCharts
|
||||
{
|
||||
if (xAxis.splitLine.NeedShow(i))
|
||||
{
|
||||
DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, m_CoordinateY),
|
||||
ChartDrawer.DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, m_CoordinateY),
|
||||
new Vector3(pX, m_CoordinateY + m_CoordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
}
|
||||
}
|
||||
@@ -1037,14 +1037,14 @@ namespace XCharts
|
||||
|
||||
private void DrawXAxisTick(VertexHelper vh, int xAxisIndex, XAxis xAxis)
|
||||
{
|
||||
if (xAxis.NeedShowSplit())
|
||||
if (AxisHelper.NeedShowSplit(xAxis))
|
||||
{
|
||||
var size = xAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var size = AxisHelper.GetScaleNumber(xAxis, m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateX;
|
||||
var yAxis = m_YAxises[xAxisIndex];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom);
|
||||
var scaleWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i, m_DataZoom);
|
||||
float pX = totalWidth;
|
||||
float pY = 0;
|
||||
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
|
||||
@@ -1132,8 +1132,8 @@ namespace XCharts
|
||||
Vector3 np = Vector3.zero;
|
||||
float minValue = 0;
|
||||
float maxValue = 0;
|
||||
m_Series.GetYMinMaxValue(null, 0, IsValue(), axis.inverse, out minValue, out maxValue);
|
||||
axis.AdjustMinMaxValue(ref minValue, ref maxValue, true);
|
||||
SeriesHelper.GetYMinMaxValue(m_Series, null, 0, IsValue(), axis.inverse, out minValue, out maxValue);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);
|
||||
|
||||
int rate = 1;
|
||||
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
|
||||
@@ -1148,8 +1148,6 @@ namespace XCharts
|
||||
float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
|
||||
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis.inverse);
|
||||
float pX = m_CoordinateX + i * scaleWid;
|
||||
// float dataHig = (axis.runtimeMaxValue - axis.runtimeMinValue) == 0 ? 0 :
|
||||
// (value - axis.runtimeMinValue) / (axis.runtimeMaxValue - axis.runtimeMinValue) * hig;
|
||||
float dataHig = (maxValue - minValue) == 0 ? 0 :
|
||||
(value - minValue) / (maxValue - minValue) * hig;
|
||||
np = new Vector3(pX, m_ChartY + m_DataZoom.bottom + dataHig);
|
||||
@@ -1197,7 +1195,7 @@ namespace XCharts
|
||||
var xAxis = m_XAxises[i];
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!xAxis.show) continue;
|
||||
float splitWidth = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float splitWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
@@ -1208,12 +1206,12 @@ namespace XCharts
|
||||
Vector2 sp = new Vector2(pX, m_CoordinateY);
|
||||
Vector2 ep = new Vector2(pX, m_CoordinateY + m_CoordinateHeight);
|
||||
var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
@@ -1242,7 +1240,7 @@ namespace XCharts
|
||||
var yAxis = m_YAxises[i];
|
||||
var xAxis = m_XAxises[i];
|
||||
if (!yAxis.show) continue;
|
||||
float splitWidth = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float splitWidth = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
@@ -1251,12 +1249,12 @@ namespace XCharts
|
||||
Vector2 sp = new Vector2(m_CoordinateX, pY);
|
||||
Vector2 ep = new Vector2(m_CoordinateX + m_CoordinateWidth, pY);
|
||||
var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
@@ -1403,7 +1401,7 @@ namespace XCharts
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
var zeroPos = Vector3.zero;
|
||||
var lastStackSerie = m_Series.GetLastStackSerie(n);
|
||||
var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, n);
|
||||
if (serie.type == SerieType.Bar)
|
||||
{
|
||||
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
|
||||
@@ -1449,13 +1447,13 @@ namespace XCharts
|
||||
|
||||
protected override void OnRefreshLabel()
|
||||
{
|
||||
var anyPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
var anyPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(i);
|
||||
if (serie.IsPerformanceMode()) continue;
|
||||
var total = serie.yTotal;
|
||||
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
if (j >= serie.dataPoints.Count) break;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace XCharts
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
float categoryWidth = yAxis.GetDataWidth(m_CoordinateHeight, showData.Count, m_DataZoom);
|
||||
float categoryWidth = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, showData.Count, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
@@ -43,7 +43,7 @@ namespace XCharts
|
||||
seriesHig.Add(0);
|
||||
}
|
||||
}
|
||||
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
||||
@@ -135,7 +135,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
|
||||
if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
|
||||
{
|
||||
m_BarLastOffset += barGapWidth;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ namespace XCharts
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
|
||||
float categoryWidth = xAxis.GetDataWidth(m_CoordinateWidth, showData.Count, m_DataZoom);
|
||||
float categoryWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
@@ -184,7 +184,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||
@@ -279,7 +279,7 @@ namespace XCharts
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
|
||||
if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
|
||||
{
|
||||
m_BarLastOffset += barGapWidth;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace XCharts
|
||||
{
|
||||
protected void DrawLinePoint(VertexHelper vh)
|
||||
{
|
||||
var clip = m_Series.IsAnyClipSerie();
|
||||
var clip = SeriesHelper.IsAnyClipSerie(m_Series);
|
||||
for (int n = 0; n < m_Series.Count; n++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(n);
|
||||
@@ -98,9 +98,9 @@ namespace XCharts
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset);
|
||||
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
|
||||
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line);
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(m_CoordinateWidth, showData.Count, m_DataZoom);
|
||||
float scaleWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom);
|
||||
float startX = m_CoordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
@@ -486,9 +486,9 @@ namespace XCharts
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY);
|
||||
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
|
||||
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line);
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(m_CoordinateHeight, showData.Count, m_DataZoom);
|
||||
float scaleWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, showData.Count, m_DataZoom);
|
||||
float startY = m_CoordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
@@ -653,7 +653,7 @@ namespace XCharts
|
||||
return true;
|
||||
}
|
||||
|
||||
var lastSerie = m_Series.GetLastStackSerie(serie);
|
||||
var lastSerie = SeriesHelper.GetLastStackSerie(m_Series, serie);
|
||||
Vector3 dnPos, upPos1, upPos2, dir1v, dir2v;
|
||||
bool isDown;
|
||||
var dir1 = (np - lp).normalized;
|
||||
@@ -1192,7 +1192,7 @@ namespace XCharts
|
||||
|
||||
if (serie.areaStyle.show)
|
||||
{
|
||||
var lastSerie = m_Series.GetLastStackSerie(serie);
|
||||
var lastSerie = SeriesHelper.GetLastStackSerie(m_Series, serie);
|
||||
if (lastSerie != null)
|
||||
{
|
||||
var lastSmoothPoints = lastSerie.GetUpSmoothList(dataIndex);
|
||||
|
||||
8
Runtime/Internal/Helper.meta
Normal file
8
Runtime/Internal/Helper.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3dbff4f83d24491da3a8a88e3e3ace4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
275
Runtime/Internal/Helper/AxisHelper.cs
Normal file
275
Runtime/Internal/Helper/AxisHelper.cs
Normal file
@@ -0,0 +1,275 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class AxisHelper
|
||||
{
|
||||
public static float GetTickWidth(Axis axis)
|
||||
{
|
||||
return axis.axisTick.width != 0 ? axis.axisTick.width : axis.axisLine.width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割段数
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom)
|
||||
{
|
||||
if (axis.type == Axis.AxisType.Value)
|
||||
{
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
if (coordinateWid <= 0) return 0;
|
||||
int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval) + 1;
|
||||
int maxNum = Mathf.CeilToInt(coordinateWid / 15);
|
||||
if (num > maxNum)
|
||||
{
|
||||
axis.interval *= 2;
|
||||
num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval) + 1;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
else return axis.splitNumber;
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
return axis.splitNumber;
|
||||
}
|
||||
int dataCount = axis.GetDataList(dataZoom).Count;
|
||||
if (axis.splitNumber <= 0) return dataCount;
|
||||
if (dataCount > 2 * axis.splitNumber || dataCount <= 0)
|
||||
return axis.splitNumber;
|
||||
else
|
||||
return dataCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割段的宽度
|
||||
/// </summary>
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetSplitWidth(Axis axis, float coordinateWidth, DataZoom dataZoom)
|
||||
{
|
||||
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
int segment = (axis.boundaryGap ? split : split - 1);
|
||||
segment = segment <= 0 ? 1 : segment;
|
||||
return coordinateWidth / segment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得一个类目数据在坐标系中代表的宽度
|
||||
/// </summary>
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)
|
||||
{
|
||||
if (dataCount < 1) dataCount = 1;
|
||||
var categoryCount = axis.GetDataNumber(dataZoom);
|
||||
int segment = (axis.boundaryGap ? categoryCount : categoryCount - 1);
|
||||
segment = segment <= 0 ? dataCount : segment;
|
||||
return coordinateWidth / segment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得标签显示的名称
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="minValue"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue,
|
||||
DataZoom dataZoom, bool forcePercent)
|
||||
{
|
||||
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
if (axis.type == Axis.AxisType.Value)
|
||||
{
|
||||
if (minValue == 0 && maxValue == 0) return string.Empty;
|
||||
float value = 0;
|
||||
if (forcePercent) maxValue = 100;
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
if (index == split - 1) value = maxValue;
|
||||
else value = minValue + index * axis.interval;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (minValue + (maxValue - minValue) * index / (split - 1));
|
||||
}
|
||||
if (axis.inverse)
|
||||
{
|
||||
value = -value;
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
if (forcePercent) return string.Format("{0}%", (int)value);
|
||||
else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue);
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) :
|
||||
Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index);
|
||||
if (axis.inverse)
|
||||
{
|
||||
value = -value;
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
return axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true);
|
||||
}
|
||||
var showData = axis.GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
if (dataCount <= 0) return "";
|
||||
|
||||
if (index == split - 1 && !axis.boundaryGap)
|
||||
{
|
||||
return axis.axisLabel.GetFormatterContent(showData[dataCount - 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
float rate = dataCount / split;
|
||||
if (rate < 1) rate = 1;
|
||||
int offset = axis.boundaryGap ? (int)(rate / 2) : 0;
|
||||
int newIndex = (int)(index * rate >= dataCount - 1 ?
|
||||
dataCount - 1 : offset + index * rate);
|
||||
return axis.axisLabel.GetFormatterContent(showData[newIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割线条数
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom)
|
||||
{
|
||||
if (axis.type == Axis.AxisType.Value || axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
return axis.boundaryGap ? splitNum + 1 : splitNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
var showData = axis.GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
if (axis.splitNumber <= 0) return axis.boundaryGap ? dataCount + 1 : dataCount;
|
||||
if (dataCount > 2 * axis.splitNumber || dataCount <= 0)
|
||||
return axis.boundaryGap ? axis.splitNumber + 1 : axis.splitNumber;
|
||||
else
|
||||
return axis.boundaryGap ? dataCount + 1 : dataCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割段宽度
|
||||
/// </summary>
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom)
|
||||
{
|
||||
int num = GetScaleNumber(axis, coordinateWidth, dataZoom) - 1;
|
||||
if (num <= 0) num = 1;
|
||||
if (axis.type == Axis.AxisType.Value && axis.interval > 0)
|
||||
{
|
||||
if (index == num - 1) return coordinateWidth - (num - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange;
|
||||
else return axis.interval * coordinateWidth / axis.runtimeMinMaxRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
return coordinateWidth / num;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调整最大最小值
|
||||
/// </summary>
|
||||
/// <param name="minValue"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void AdjustMinMaxValue(Axis axis, ref float minValue, ref float maxValue, bool needFormat)
|
||||
{
|
||||
if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
int minSplit = 0;
|
||||
int maxSplit = 0;
|
||||
maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit);
|
||||
minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit);
|
||||
axis.splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit);
|
||||
return;
|
||||
}
|
||||
if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
|
||||
{
|
||||
if (axis.min != 0 || axis.max != 0)
|
||||
{
|
||||
if (axis.inverse)
|
||||
{
|
||||
minValue = -axis.max;
|
||||
maxValue = -axis.min;
|
||||
}
|
||||
else
|
||||
{
|
||||
minValue = axis.min;
|
||||
maxValue = axis.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (axis.minMaxType)
|
||||
{
|
||||
case Axis.AxisMinMaxType.Default:
|
||||
if (minValue == 0 && maxValue == 0)
|
||||
{
|
||||
}
|
||||
else if (minValue > 0 && maxValue > 0)
|
||||
{
|
||||
minValue = 0;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, axis.ceilRate) : maxValue;
|
||||
}
|
||||
else if (minValue < 0 && maxValue < 0)
|
||||
{
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, axis.ceilRate) : minValue;
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, axis.ceilRate) : minValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, axis.ceilRate) : maxValue;
|
||||
}
|
||||
break;
|
||||
case Axis.AxisMinMaxType.MinMax:
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, axis.ceilRate) : minValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, axis.ceilRate) : maxValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var tempRange = maxValue - minValue;
|
||||
if (axis.runtimeMinMaxRange != tempRange)
|
||||
{
|
||||
axis.runtimeMinMaxRange = tempRange;
|
||||
if (axis.type == Axis.AxisType.Value && axis.interval > 0)
|
||||
{
|
||||
axis.SetComponentDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool NeedShowSplit(Axis axis)
|
||||
{
|
||||
if (!axis.show) return false;
|
||||
if (axis.IsCategory() && axis.data.Count <= 0) return false;
|
||||
else if (axis.IsValue() && axis.runtimeMinValue == 0 && axis.runtimeMaxValue == 0) return false;
|
||||
else return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 820c154b7b7d848cdaf52e68c369dd86
|
||||
guid: 502c2be6d197b40f59ae65d9c659700f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
24
Runtime/Internal/Helper/ItemStyleHelper.cs
Normal file
24
Runtime/Internal/Helper/ItemStyleHelper.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class ItemStyleHelper
|
||||
{
|
||||
public static bool IsNeedCorner(ItemStyle itemStyle)
|
||||
{
|
||||
if (itemStyle.cornerRadius == null) return false;
|
||||
foreach (var value in itemStyle.cornerRadius)
|
||||
{
|
||||
if (value != 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/ItemStyleHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/ItemStyleHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14c20b85c2c6d44b08f57c928307080d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
268
Runtime/Internal/Helper/LegendHelper.cs
Normal file
268
Runtime/Internal/Helper/LegendHelper.cs
Normal file
@@ -0,0 +1,268 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class LegendHelper
|
||||
{
|
||||
public static Color GetContentColor(Legend legend, ThemeInfo themeInfo, bool active)
|
||||
{
|
||||
var textStyle = legend.textStyle;
|
||||
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : (Color)themeInfo.legendTextColor;
|
||||
else return (Color)themeInfo.legendUnableColor;
|
||||
}
|
||||
|
||||
public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
|
||||
return (Color)themeInfo.GetColor(readIndex);
|
||||
else
|
||||
return Color.white;
|
||||
}
|
||||
else return (Color)themeInfo.legendUnableColor;
|
||||
}
|
||||
|
||||
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo,
|
||||
string content, Color itemColor, bool active)
|
||||
{
|
||||
var objName = i + "_" + legendName;
|
||||
var anchorMin = new Vector2(0, 0.5f);
|
||||
var anchorMax = new Vector2(0, 0.5f);
|
||||
var pivot = new Vector2(0, 0.5f);
|
||||
var sizeDelta = new Vector2(100, 30);
|
||||
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
|
||||
var textStyle = legend.textStyle;
|
||||
var font = textStyle.font ? textStyle.font : themeInfo.font;
|
||||
var contentColor = GetContentColor(legend, themeInfo, active);
|
||||
|
||||
var objAnchorMin = legend.location.runtimeAnchorMin;
|
||||
var objAnchorMax = legend.location.runtimeAnchorMax;
|
||||
var objPivot = legend.location.runtimePivot;
|
||||
var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta, i);
|
||||
var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
|
||||
var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var img = ChartHelper.GetOrAddComponent<Image>(btnObj);
|
||||
img.color = Color.clear;
|
||||
ChartHelper.GetOrAddComponent<Button>(btnObj);
|
||||
ChartHelper.GetOrAddComponent<Image>(iconObj);
|
||||
ChartHelper.GetOrAddComponent<Image>(contentObj);
|
||||
ChartHelper.AddTextObject("Text", contentObj.transform, font, contentColor,
|
||||
TextAnchor.MiddleLeft, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize,
|
||||
textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
|
||||
var item = new LegendItem();
|
||||
item.index = i;
|
||||
item.name = objName;
|
||||
item.legendName = legendName;
|
||||
item.SetObject(btnObj);
|
||||
item.SetIconSize(legend.itemWidth, legend.itemHeight);
|
||||
item.SetIconColor(itemColor);
|
||||
item.SetIconImage(legend.GetIcon(i));
|
||||
item.SetContentPosition(textStyle.offsetv3);
|
||||
item.SetContent(content);
|
||||
item.SetContentBackgroundColor(textStyle.backgroundColor);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void ResetItemPosition(Legend legend)
|
||||
{
|
||||
var startX = 0f;
|
||||
var currWidth = 0f;
|
||||
var currHeight = 0f;
|
||||
|
||||
switch (legend.orient)
|
||||
{
|
||||
case Orient.Vertical:
|
||||
switch (legend.location.align)
|
||||
{
|
||||
case Location.Align.TopCenter:
|
||||
startX = legend.runtimeWidth / 2;
|
||||
currHeight = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(-startX + item.width / 2, -currHeight));
|
||||
currHeight += item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
case Location.Align.TopLeft:
|
||||
currHeight = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(0, -currHeight));
|
||||
currHeight += item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
|
||||
case Location.Align.TopRight:
|
||||
currHeight = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, -currHeight));
|
||||
currHeight += item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
|
||||
case Location.Align.Center:
|
||||
startX = legend.runtimeWidth / 2;
|
||||
currHeight = legend.runtimeHeight;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
|
||||
currHeight -= item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
case Location.Align.CenterLeft:
|
||||
currHeight = legend.runtimeHeight;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(0, currHeight - item.height));
|
||||
currHeight -= item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
case Location.Align.CenterRight:
|
||||
currHeight = legend.runtimeHeight;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
|
||||
currHeight -= item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
case Location.Align.BottomCenter:
|
||||
startX = legend.runtimeWidth / 2;
|
||||
currHeight = legend.runtimeHeight;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
|
||||
currHeight -= item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
|
||||
case Location.Align.BottomLeft:
|
||||
currHeight = legend.runtimeHeight;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(0, currHeight - item.height));
|
||||
currHeight -= item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
case Location.Align.BottomRight:
|
||||
currHeight = legend.runtimeHeight;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
|
||||
currHeight -= item.height + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Orient.Horizonal:
|
||||
switch (legend.location.align)
|
||||
{
|
||||
case Location.Align.TopLeft:
|
||||
case Location.Align.CenterLeft:
|
||||
case Location.Align.BottomLeft:
|
||||
currWidth = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(currWidth, 0));
|
||||
currWidth += item.width + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
case Location.Align.TopCenter:
|
||||
case Location.Align.Center:
|
||||
case Location.Align.BottomCenter:
|
||||
startX = legend.runtimeWidth / 2;
|
||||
currWidth = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(-startX + item.width / 2 + currWidth, 0));
|
||||
currWidth += item.width + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
case Location.Align.TopRight:
|
||||
case Location.Align.CenterRight:
|
||||
case Location.Align.BottomRight:
|
||||
startX = -legend.runtimeWidth;
|
||||
currWidth = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
item.SetPosition(new Vector3(startX + currWidth + item.width, 0));
|
||||
currWidth += item.width + legend.itemGap;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckDataShow(Series series, string legendName, bool show)
|
||||
{
|
||||
bool needShow = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.show = show;
|
||||
serie.highlighted = false;
|
||||
if (serie.show) needShow = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.show = show;
|
||||
data.highlighted = false;
|
||||
if (data.show) needShow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return needShow;
|
||||
}
|
||||
|
||||
public static bool CheckDataHighlighted(Series series, string legendName, bool heighlight)
|
||||
{
|
||||
bool show = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.highlighted = heighlight;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.highlighted = heighlight;
|
||||
if (data.highlighted) show = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return show;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/LegendHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/LegendHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d03ce7a11ecde41b6930883612bf8f05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Runtime/Internal/Helper/SerieDataHelper.cs
Normal file
15
Runtime/Internal/Helper/SerieDataHelper.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieDataHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/SerieDataHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/SerieDataHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e78d1b28fc61d4b1b995a1eca16cf3b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
262
Runtime/Internal/Helper/SerieHelper.cs
Normal file
262
Runtime/Internal/Helper/SerieHelper.cs
Normal file
@@ -0,0 +1,262 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieHelper
|
||||
{
|
||||
internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight, bool useDefault = true)
|
||||
{
|
||||
var color = Color.clear;
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.backgroundColor))
|
||||
{
|
||||
color = itemStyleEmphasis.backgroundColor;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
var itemStyle = GetItemStyle(serie, serieData);
|
||||
if (!ChartHelper.IsClearColor(itemStyle.backgroundColor))
|
||||
{
|
||||
color = itemStyle.backgroundColor;
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else if (useDefault)
|
||||
{
|
||||
color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a = 0.2f;
|
||||
return color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
|
||||
{
|
||||
var color = itemStyleEmphasis.color;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
var itemStyle = GetItemStyle(serie, serieData);
|
||||
if (!ChartHelper.IsClearColor(itemStyle.color))
|
||||
{
|
||||
var color = itemStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.toColor))
|
||||
{
|
||||
var color = itemStyleEmphasis.toColor;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle == null) itemStyle = serieData.itemStyle;
|
||||
if (!ChartHelper.IsClearColor(itemStyle.toColor))
|
||||
{
|
||||
var color = itemStyle.toColor;
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
if (!ChartHelper.IsClearColor(itemStyle.color))
|
||||
{
|
||||
var color = itemStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsDownPoint(Serie serie, int index)
|
||||
{
|
||||
var dataPoints = serie.dataPoints;
|
||||
if (dataPoints.Count < 2) return false;
|
||||
else if (index > 0 && index < dataPoints.Count - 1)
|
||||
{
|
||||
var lp = dataPoints[index - 1];
|
||||
var np = dataPoints[index + 1];
|
||||
var cp = dataPoints[index];
|
||||
var dot = Vector3.Cross(np - lp, cp - np);
|
||||
return dot.z < 0;
|
||||
}
|
||||
else if (index == 0)
|
||||
{
|
||||
return dataPoints[0].y < dataPoints[1].y;
|
||||
}
|
||||
else if (index == dataPoints.Count - 1)
|
||||
{
|
||||
return dataPoints[index].y < dataPoints[index - 1].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
var style = GetItemStyleEmphasis(serie, serieData);
|
||||
if (style == null) return GetItemStyle(serie, serieData, false);
|
||||
else return style;
|
||||
}
|
||||
else if (serie.IsPerformanceMode()) return serie.itemStyle;
|
||||
else if (serieData != null && serieData.enableItemStyle) return serieData.itemStyle;
|
||||
else return serie.itemStyle;
|
||||
}
|
||||
|
||||
public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData != null && serieData.enableEmphasis && serieData.emphasis.show)
|
||||
return serieData.emphasis.itemStyle;
|
||||
else if (serie.emphasis.show) return serie.emphasis.itemStyle;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static SerieLabel GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableEmphasis && serieData.emphasis.show)
|
||||
return serieData.emphasis.label;
|
||||
else if (serie.emphasis.show) return serie.emphasis.label;
|
||||
else return serie.label;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableLabel) return serieData.label;
|
||||
else return serie.label;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : (Color)theme.GetColor(index);
|
||||
if (highlight)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(areaStyle.highlightColor)) color = areaStyle.highlightColor;
|
||||
else color *= color;
|
||||
}
|
||||
color.a *= areaStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
public static Color GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
if (!ChartHelper.IsClearColor(areaStyle.toColor))
|
||||
{
|
||||
var color = areaStyle.toColor;
|
||||
if (highlight)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(areaStyle.highlightToColor)) color = areaStyle.highlightToColor;
|
||||
else color *= color;
|
||||
}
|
||||
color.a *= areaStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetAreaColor(serie, theme, index, highlight);
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
var color = Color.clear;
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
|
||||
{
|
||||
color = itemStyleEmphasis.color;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (!ChartHelper.IsClearColor(serie.lineStyle.color)) color = serie.lineStyle.GetColor();
|
||||
else if (!ChartHelper.IsClearColor(serie.itemStyle.color)) color = serie.itemStyle.GetColor();
|
||||
if (ChartHelper.IsClearColor(color))
|
||||
{
|
||||
color = (Color)theme.GetColor(index);
|
||||
color.a = serie.lineStyle.opacity;
|
||||
}
|
||||
if (highlight) color *= color;
|
||||
return color;
|
||||
}
|
||||
|
||||
public static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight, bool useLineWidth = true)
|
||||
{
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
|
||||
else if (serie.lineStyle.width != 0 && useLineWidth) return serie.lineStyle.width;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)
|
||||
{
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle != null) return itemStyle.cornerRadius;
|
||||
else return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新运行时中心点和半径
|
||||
/// </summary>
|
||||
/// <param name="chartWidth"></param>
|
||||
/// <param name="chartHeight"></param>
|
||||
internal static void UpdateCenter(Serie serie, Vector3 chartPosition, float chartWidth, float chartHeight)
|
||||
{
|
||||
if (serie.center.Length < 2) return;
|
||||
var centerX = serie.center[0] <= 1 ? chartWidth * serie.center[0] : serie.center[0];
|
||||
var centerY = serie.center[1] <= 1 ? chartHeight * serie.center[1] : serie.center[1];
|
||||
serie.runtimeCenterPos = chartPosition + new Vector3(centerX, centerY);
|
||||
var minWidth = Mathf.Min(chartWidth, chartHeight);
|
||||
serie.runtimeInsideRadius = serie.radius[0] <= 1 ? minWidth * serie.radius[0] : serie.radius[0];
|
||||
serie.runtimeOutsideRadius = serie.radius[1] <= 1 ? minWidth * serie.radius[1] : serie.radius[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/SerieHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/SerieHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5c421b17fb6f45a283f4f57efce686f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
177
Runtime/Internal/Helper/SerieLabelHelper.cs
Normal file
177
Runtime/Internal/Helper/SerieLabelHelper.cs
Normal file
@@ -0,0 +1,177 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieLabelHelper
|
||||
{
|
||||
public static void CheckLabel(Serie serie, ref bool m_ReinitLabel, ref bool m_UpdateLabelText)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Gauge:
|
||||
case SerieType.Ring:
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData != null)
|
||||
{
|
||||
if (serie.label.show && serie.show)
|
||||
{
|
||||
if (serieData.labelObject != null)
|
||||
{
|
||||
serieData.SetLabelActive(true);
|
||||
m_UpdateLabelText = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ReinitLabel = true;
|
||||
}
|
||||
}
|
||||
else if (serieData.labelObject != null)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateLabelText(Series series, ThemeInfo themeInfo)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (!serie.label.show) continue;
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Gauge:
|
||||
SetGaugeLabelText(serie);
|
||||
break;
|
||||
case SerieType.Ring:
|
||||
SetRingLabelText(serie, themeInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(serie.label.color))
|
||||
{
|
||||
return serie.label.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return themeInfo.GetColor(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex)
|
||||
{
|
||||
if (serieData.labelObject == null) return;
|
||||
if (serieData.labelObject.label == null) return;
|
||||
serieData.labelObject.label.color = !ChartHelper.IsClearColor(label.color) ? label.color :
|
||||
(Color)themeInfo.GetColor(colorIndex);
|
||||
serieData.labelObject.label.fontSize = label.fontSize;
|
||||
serieData.labelObject.label.fontStyle = label.fontStyle;
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Serie serie, SerieData serieData,
|
||||
float dataValue, float dataTotal, SerieLabel serieLabel = null)
|
||||
{
|
||||
if (serieLabel == null)
|
||||
{
|
||||
serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
}
|
||||
var numericFormatter = GetLabelNumericFormatter(serie, serieData);
|
||||
var serieName = serie.name;
|
||||
var dataName = serieData != null ? serieData.name : null;
|
||||
if (string.IsNullOrEmpty(serieLabel.formatter))
|
||||
return ChartCached.NumberToStr(dataValue, numericFormatter);
|
||||
else
|
||||
{
|
||||
var content = serieLabel.formatter.Replace("{a}", serieName);
|
||||
content = content.Replace("{b}", dataName);
|
||||
content = content.Replace("{c}", ChartCached.NumberToStr(dataValue, numericFormatter));
|
||||
content = content.Replace("{c:f0}", ChartCached.IntToStr((int)Mathf.Round(dataValue)));
|
||||
content = content.Replace("{c:f1}", ChartCached.FloatToStr(dataValue, string.Empty, 1));
|
||||
content = content.Replace("{c:f2}", ChartCached.FloatToStr(dataValue, string.Empty, 2));
|
||||
if (dataTotal > 0)
|
||||
{
|
||||
var percent = dataValue / dataTotal * 100;
|
||||
content = content.Replace("{d}", ChartCached.NumberToStr(percent, numericFormatter));
|
||||
content = content.Replace("{d:f0}", ChartCached.IntToStr((int)Mathf.Round(percent)));
|
||||
content = content.Replace("{d:f1}", ChartCached.FloatToStr(percent, string.Empty, 1));
|
||||
content = content.Replace("{d:f2}", ChartCached.FloatToStr(percent, string.Empty, 2));
|
||||
}
|
||||
content = content.Replace("\\n", "\n");
|
||||
content = content.Replace("<br/>", "\n");
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetLabelNumericFormatter(Serie serie, SerieData serieData)
|
||||
{
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
|
||||
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
|
||||
else return serie.label.numericFormatter;
|
||||
}
|
||||
|
||||
|
||||
private static void SetGaugeLabelText(Serie serie)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData == null) return;
|
||||
if (serieData.labelObject == null) return;
|
||||
var value = serieData.GetData(1);
|
||||
var total = serie.max;
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
|
||||
if (!ChartHelper.IsClearColor(serie.label.color))
|
||||
{
|
||||
serieData.labelObject.label.color = serie.label.color;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetRingLabelText(Serie serie, ThemeInfo themeInfo)
|
||||
{
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
|
||||
if (serieLabel.show && serieData.labelObject != null)
|
||||
{
|
||||
if (!serie.show || !serieData.show)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
continue;
|
||||
}
|
||||
var value = serieData.GetData(0);
|
||||
var total = serieData.GetData(1);
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, i));
|
||||
|
||||
if (serie.label.position == SerieLabel.Position.Bottom)
|
||||
{
|
||||
var labelWidth = serieData.GetLabelWidth();
|
||||
if (serie.clockwise)
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition - new Vector3(labelWidth / 2, 0));
|
||||
else
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition + new Vector3(labelWidth / 2, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/SerieLabelHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/SerieLabelHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbd57df98f6f145f299cf942b04229a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
447
Runtime/Internal/Helper/SeriesHelper.cs
Normal file
447
Runtime/Internal/Helper/SeriesHelper.cs
Normal file
@@ -0,0 +1,447 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SeriesHelper
|
||||
{
|
||||
public static bool IsNeedLabelUpdate(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.label.vertsDirty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsLabelDirty(Series series)
|
||||
{
|
||||
if (series.labelDirty) return true;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.label.componentDirty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsLegalLegendName(string name)
|
||||
{
|
||||
int numName = -1;
|
||||
if (int.TryParse(name, out numName))
|
||||
{
|
||||
if (numName >= 0 && numName < 100) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<string> GetLegalSerieNameList(Series series)
|
||||
{
|
||||
var list = new List<string>();
|
||||
for (int n = 0; n < series.list.Count; n++)
|
||||
{
|
||||
var serie = series.GetSerie(n);
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Pie:
|
||||
case SerieType.Radar:
|
||||
case SerieType.Ring:
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
var dataName = serie.data[i].name;
|
||||
if (!string.IsNullOrEmpty(dataName) && IsLegalLegendName(dataName) && !list.Contains(dataName))
|
||||
list.Add(dataName);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!string.IsNullOrEmpty(serie.name) && !list.Contains(serie.name) && IsLegalLegendName(serie.name))
|
||||
list.Add(serie.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得所有系列名,不包含空名字。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static void UpdateSerieNameList(Series series, ref List<string> serieNameList)
|
||||
{
|
||||
serieNameList.Clear();
|
||||
for (int n = 0; n < series.list.Count; n++)
|
||||
{
|
||||
var serie = series.GetSerie(n);
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Pie:
|
||||
case SerieType.Radar:
|
||||
case SerieType.Ring:
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.data[i].name))
|
||||
serieNameList.Add(ChartCached.IntToStr(i));
|
||||
else if (!serieNameList.Contains(serie.data[i].name))
|
||||
serieNameList.Add(serie.data[i].name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (string.IsNullOrEmpty(serie.name))
|
||||
serieNameList.Add(ChartCached.IntToStr(n));
|
||||
else if (!serieNameList.Contains(serie.name))
|
||||
serieNameList.Add(serie.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同堆叠的serie是否有渐变色的。
|
||||
/// </summary>
|
||||
/// <param name="stack"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsAnyGradientSerie(Series series, string stack)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stack)) return false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack))
|
||||
{
|
||||
if (serie.areaStyle.color != serie.areaStyle.toColor
|
||||
&& !ChartHelper.IsClearColor(serie.areaStyle.toColor))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否有需裁剪的serie。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static bool IsAnyClipSerie(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.clip) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool IsAnyUpdateAnimationSerie(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.animation.enable && serie.animation.dataChangeEnable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得上一个同堆叠且显示的serie。
|
||||
/// </summary>
|
||||
/// <param name="serie"></param>
|
||||
/// <returns></returns>
|
||||
internal static Serie GetLastStackSerie(Series series, Serie serie)
|
||||
{
|
||||
if (serie == null || string.IsNullOrEmpty(serie.stack)) return null;
|
||||
for (int i = serie.index - 1; i >= 0; i--)
|
||||
{
|
||||
var temp = series.list[i];
|
||||
if (temp.show && serie.stack.Equals(temp.stack)) return temp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得上一个同堆叠且显示的serie。
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
internal static Serie GetLastStackSerie(Series series, int index)
|
||||
{
|
||||
var serie = series.GetSerie(index);
|
||||
return GetLastStackSerie(series, serie);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否由系列在用指定索引的axis
|
||||
/// </summary>
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsUsedAxisIndex(Series series, int axisIndex)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.axisIndex == axisIndex) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static HashSet<string> _setForStack = new HashSet<string>();
|
||||
/// <summary>
|
||||
/// 是否由数据堆叠
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static bool IsStack(Series series)
|
||||
{
|
||||
_setForStack.Clear();
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.stack)) continue;
|
||||
if (_setForStack.Contains(serie.stack)) return true;
|
||||
else
|
||||
{
|
||||
_setForStack.Add(serie.stack);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否堆叠
|
||||
/// </summary>
|
||||
/// <param name="stackName"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsStack(Series series, string stackName, SerieType type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stackName)) return false;
|
||||
int count = 0;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.type == type)
|
||||
{
|
||||
if (stackName.Equals(serie.stack)) count++;
|
||||
if (count >= 2) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否时百分比堆叠
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsPercentStack(Series series, SerieType type)
|
||||
{
|
||||
int count = 0;
|
||||
bool isPercentStack = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.type == type)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
count++;
|
||||
if (serie.barPercentStack) isPercentStack = true;
|
||||
}
|
||||
if (count >= 2 && isPercentStack) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否时百分比堆叠
|
||||
/// </summary>
|
||||
/// <param name="stackName"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsPercentStack(Series series, string stackName, SerieType type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stackName)) return false;
|
||||
int count = 0;
|
||||
bool isPercentStack = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.type == type)
|
||||
{
|
||||
if (stackName.Equals(serie.stack))
|
||||
{
|
||||
count++;
|
||||
if (serie.barPercentStack) isPercentStack = true;
|
||||
}
|
||||
if (count >= 2 && isPercentStack) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Dictionary<string, int> sets = new Dictionary<string, int>();
|
||||
/// <summary>
|
||||
/// 获得堆叠系列列表
|
||||
/// </summary>
|
||||
/// <param name="Dictionary<int"></param>
|
||||
/// <param name="stackSeries"></param>
|
||||
internal static void GetStackSeries(Series series, ref Dictionary<int, List<Serie>> stackSeries)
|
||||
{
|
||||
int count = 0;
|
||||
var serieCount = series.list.Count;
|
||||
sets.Clear();
|
||||
if (stackSeries == null)
|
||||
{
|
||||
stackSeries = new Dictionary<int, List<Serie>>(serieCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var kv in stackSeries)
|
||||
{
|
||||
kv.Value.Clear();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < serieCount; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
serie.index = i;
|
||||
if (string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (!stackSeries.ContainsKey(count))
|
||||
stackSeries[count] = new List<Serie>(serieCount);
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sets.ContainsKey(serie.stack))
|
||||
{
|
||||
sets.Add(serie.stack, count);
|
||||
if (!stackSeries.ContainsKey(count))
|
||||
stackSeries[count] = new List<Serie>(serieCount);
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int stackIndex = sets[serie.stack];
|
||||
stackSeries[stackIndex].Add(serie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得维度X的最大最小值
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得维度Y的最大最小值
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private static Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
|
||||
internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, bool yValue, out float minVaule, out float maxValue)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
float max = int.MinValue;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar);
|
||||
if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue))
|
||||
{
|
||||
for (int i = 0; i < series.list.Count; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
if (serie.axisIndex != axisIndex) continue;
|
||||
|
||||
if (series.IsActive(i))
|
||||
{
|
||||
if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
|
||||
{
|
||||
if (100 > max) max = 100;
|
||||
if (0 < min) min = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
var currData = data.GetData(yValue ? 1 : 0, inverse);
|
||||
if (currData > max) max = currData;
|
||||
if (currData < min) min = currData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax);
|
||||
foreach (var ss in _stackSeriesForMinMax)
|
||||
{
|
||||
_serieTotalValueForMinMax.Clear();
|
||||
for (int i = 0; i < ss.Value.Count; i++)
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if (serie.axisIndex != axisIndex || !series.IsActive(i)) continue;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar))
|
||||
{
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
_serieTotalValueForMinMax[j] = 100;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
var currData = (yValue ? showData[j].GetData(1) : showData[j].GetData(0));
|
||||
if (inverse) currData = -currData;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
|
||||
}
|
||||
}
|
||||
}
|
||||
float tmax = int.MinValue;
|
||||
float tmin = int.MaxValue;
|
||||
foreach (var tt in _serieTotalValueForMinMax)
|
||||
{
|
||||
if (tt.Value > tmax) tmax = tt.Value;
|
||||
if (tt.Value < tmin) tmin = tt.Value;
|
||||
}
|
||||
if (tmax > max) max = tmax;
|
||||
if (tmin < min) min = tmin;
|
||||
}
|
||||
}
|
||||
if (max == int.MinValue && min == int.MaxValue)
|
||||
{
|
||||
minVaule = 0;
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minVaule = min > 1 ? Mathf.FloorToInt(min) : min;
|
||||
maxValue = max > 1 ? Mathf.CeilToInt(max) : max;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/SeriesHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/SeriesHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7411a13172764cf89b10e643089c832
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Runtime/Internal/Helper/TitleHelper.cs
Normal file
34
Runtime/Internal/Helper/TitleHelper.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class TitleHelper
|
||||
{
|
||||
public static Font GetTextFont(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return (title.textStyle.font != null) ? title.textStyle.font : themeInfo.font;
|
||||
}
|
||||
|
||||
public static Color GetTextColor(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return !ChartHelper.IsClearColor(title.textStyle.color) ? title.textStyle.color : (Color)themeInfo.titleTextColor;
|
||||
}
|
||||
|
||||
public static Font GetSubTextFont(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return (title.subTextStyle.font != null) ? title.subTextStyle.font : themeInfo.font;
|
||||
}
|
||||
|
||||
public static Color GetSubTextColor(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return !ChartHelper.IsClearColor(title.subTextStyle.color) ? title.subTextStyle.color : (Color)themeInfo.titleSubTextColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/TitleHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/TitleHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e22859d8021f6491f8ee08339b71e577
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Runtime/Internal/Helper/TitleStyleHelper.cs
Normal file
43
Runtime/Internal/Helper/TitleStyleHelper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class TitleStyleHelper
|
||||
{
|
||||
public static void CheckTitle(Serie serie, ref bool m_ReinitTitle, ref bool m_UpdateTitleText)
|
||||
{
|
||||
if (serie.titleStyle.show)
|
||||
{
|
||||
if (serie.titleStyle.IsInited())
|
||||
{
|
||||
serie.titleStyle.UpdatePosition(serie.runtimeCenterPos);
|
||||
m_UpdateTitleText = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ReinitTitle = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateTitleText(Series series)
|
||||
{
|
||||
foreach (var serie in series.list) UpdateTitleText(serie);
|
||||
}
|
||||
|
||||
public static void UpdateTitleText(Serie serie)
|
||||
{
|
||||
if (serie.titleStyle.show)
|
||||
{
|
||||
serie.titleStyle.SetText(serie.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/TitleStyleHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/TitleStyleHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35fa58aecc0f4414e8a2f03195b66175
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
438
Runtime/Internal/Helper/TooltipHelper.cs
Normal file
438
Runtime/Internal/Helper/TooltipHelper.cs
Normal file
@@ -0,0 +1,438 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class TooltipHelper
|
||||
{
|
||||
private const string PH_A = "{a}";
|
||||
private const string PH_B = "{b}";
|
||||
private const string PH_C = "{c}";
|
||||
private const string PH_D = "{d}";
|
||||
private const string PH_I = "{.}";
|
||||
private const string PH_Y = "{j}";
|
||||
private const string PH_ON = "\\n";
|
||||
private const string PH_NN = "\n";
|
||||
private const string PH_NN_BBB = "\n";
|
||||
private const string PH_BR = "<br/>";
|
||||
private static Dictionary<string, Dictionary<int, string>> s_PHDic = new Dictionary<string, Dictionary<int, string>>();
|
||||
private static Dictionary<int, string> s_PHCCDic = new Dictionary<int, string>();
|
||||
private static Dictionary<int, Dictionary<int, string>> s_PHSerieCCDic = new Dictionary<int, Dictionary<int, string>>();
|
||||
|
||||
private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo)
|
||||
{
|
||||
if (!tooltip.runtimeSerieDataIndex.ContainsKey(serie.index)) return;
|
||||
var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
sb.Append(serie.name).Append(PH_NN);
|
||||
}
|
||||
for (int i = 0; i < dataIndexList.Count; i++)
|
||||
{
|
||||
var dataIndex = dataIndexList[i];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
sb.Append(serieData.name).Append(": ");
|
||||
sb.AppendFormat("({0},{1})", ChartCached.FloatToStr(xValue, numericFormatter),
|
||||
ChartCached.FloatToStr(yValue, numericFormatter));
|
||||
if (i != dataIndexList.Count - 1)
|
||||
{
|
||||
sb.Append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void InitPieTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo)
|
||||
{
|
||||
string key = serie.data[index].name;
|
||||
var serieData = serie.GetSerieData(index);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
|
||||
float value = serieData.GetData(1);
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
sb.Append(serie.name).Append(PH_NN);
|
||||
}
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
sb.Append(key).Append(": ");
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
|
||||
private static void InitRingTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo)
|
||||
{
|
||||
var serieData = serie.GetSerieData(index);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float value = serieData.GetFirstData();
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
{
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>")
|
||||
.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar,
|
||||
ThemeInfo themeInfo)
|
||||
{
|
||||
var dataIndex = tooltip.runtimeDataIndex[1];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
switch (serie.radarType)
|
||||
{
|
||||
case RadarType.Multiple:
|
||||
sb.Append(serieData.name);
|
||||
for (int i = 0; i < radar.indicatorList.Count; i++)
|
||||
{
|
||||
string key = radar.indicatorList[i].name;
|
||||
float value = serieData.GetData(i);
|
||||
if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append(PH_NN);
|
||||
sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
break;
|
||||
case RadarType.Single:
|
||||
string key2 = serieData.name;
|
||||
float value2 = serieData.GetData(1);
|
||||
if (string.IsNullOrEmpty(key2))
|
||||
{
|
||||
key2 = radar.indicatorList[dataIndex].name;
|
||||
}
|
||||
sb.AppendFormat("{0}: {1}", key2, ChartCached.FloatToStr(value2, numericFormatter));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo, bool isCartesian, DataZoom dataZoom = null)
|
||||
{
|
||||
string key = serie.name;
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(index, dataZoom, out xValue, out yValue);
|
||||
var isIngore = serie.IsIgnorePoint(index);
|
||||
var serieData = serie.GetSerieData(index, dataZoom);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
if (isCartesian)
|
||||
{
|
||||
if (serieData != null && serieData.highlighted)
|
||||
{
|
||||
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
|
||||
sb.Append("[").Append(ChartCached.FloatToStr(xValue, numericFormatter)).Append(",")
|
||||
.Append(ChartCached.FloatToStr(yValue, numericFormatter)).Append("]");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
|
||||
ChartCached.FloatToStr(yValue, numericFormatter);
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>")
|
||||
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
|
||||
.Append(valueTxt);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null, bool isCartesian = false)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Line:
|
||||
case SerieType.Bar:
|
||||
InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom);
|
||||
break;
|
||||
case SerieType.Scatter:
|
||||
case SerieType.EffectScatter:
|
||||
InitScatterTooltip(ref sb, tooltip, serie, index, themeInfo);
|
||||
break;
|
||||
case SerieType.Radar:
|
||||
break;
|
||||
case SerieType.Pie:
|
||||
InitPieTooltip(ref sb, tooltip, serie, index, themeInfo);
|
||||
break;
|
||||
case SerieType.Ring:
|
||||
InitRingTooltip(ref sb, tooltip, serie, index, themeInfo);
|
||||
break;
|
||||
case SerieType.Heatmap:
|
||||
break;
|
||||
case SerieType.Gauge:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetContentAndPosition(Tooltip tooltip, string content, Rect chartRect)
|
||||
{
|
||||
tooltip.UpdateContentText(content);
|
||||
var pos = tooltip.GetContentPos();
|
||||
if (pos.x + tooltip.runtimeWidth > chartRect.x + chartRect.width)
|
||||
{
|
||||
pos.x = chartRect.x + chartRect.width - tooltip.runtimeWidth;
|
||||
}
|
||||
if (pos.y - tooltip.runtimeHeight < chartRect.y)
|
||||
{
|
||||
pos.y = chartRect.y + tooltip.runtimeHeight;
|
||||
}
|
||||
tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
|
||||
string category = null, DataZoom dataZoom = null, bool isCartesian = false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tooltip.formatter))
|
||||
{
|
||||
var sb = ChartHelper.sb;
|
||||
var title = tooltip.titleFormatter;
|
||||
var formatTitle = !string.IsNullOrEmpty(title);
|
||||
var needCategory = false;
|
||||
var first = true;
|
||||
var isScatter = false;
|
||||
sb.Length = 0;
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
|
||||
{
|
||||
if (serie.show && IsSelectedSerie(tooltip, serie.index))
|
||||
{
|
||||
isScatter = true;
|
||||
var itemFormatter = GetItemFormatter(tooltip, serie, null);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, null);
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
if (!first) sb.Append(PH_NN);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
var itemTitle = title;
|
||||
if (!string.IsNullOrEmpty(itemTitle))
|
||||
{
|
||||
Replace(ref itemTitle, PH_A, i, serie.name, true);
|
||||
sb.Append(itemTitle).Append(PH_NN);
|
||||
}
|
||||
var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];
|
||||
foreach (var tempIndex in dataIndexList)
|
||||
{
|
||||
var foundDot = false;
|
||||
var serieData = serie.GetSerieData(tempIndex);
|
||||
string content = itemFormatter;
|
||||
Replace(ref content, PH_A, i, serie.name, true);
|
||||
Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true);
|
||||
if (itemFormatter.IndexOf(PH_I) >= 0)
|
||||
{
|
||||
foundDot = true;
|
||||
Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)), true);
|
||||
}
|
||||
for (int n = 0; n < serieData.data.Count; n++)
|
||||
{
|
||||
var valueStr = ChartCached.FloatToStr(serieData.GetData(n), numericFormatter);
|
||||
Replace(ref content, GetPHCC(n), i, valueStr, true);
|
||||
}
|
||||
if (!foundDot)
|
||||
{
|
||||
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
|
||||
}
|
||||
sb.Append(content).Append(PH_NN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var serieData = serie.GetSerieData(dataIndex, dataZoom);
|
||||
if (serieData == null) continue;
|
||||
var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
var percent = serieData.GetData(1) / serie.yTotal * 100;
|
||||
needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
|
||||
if (formatTitle)
|
||||
{
|
||||
var valueStr = ChartCached.FloatToStr(serieData.GetData(1), numericFormatter);
|
||||
Replace(ref title, PH_A, i, serie.name, true);
|
||||
Replace(ref title, PH_B, i, needCategory ? category : serieData.name, true);
|
||||
Replace(ref title, PH_C, i, valueStr, true);
|
||||
Replace(ref title, PH_D, i, ChartCached.FloatToStr(percent, string.Empty, 1), true);
|
||||
}
|
||||
if (serie.show)
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
if (!first) sb.Append(PH_NN);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
string content = itemFormatter;
|
||||
var valueStr = ChartCached.FloatToStr(serieData.GetData(1), numericFormatter);
|
||||
Replace(ref content, PH_A, i, serie.name, true);
|
||||
Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true);
|
||||
Replace(ref content, PH_C, i, valueStr, true);
|
||||
Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, string.Empty, 1), true);
|
||||
for (int n = 0; n < serieData.data.Count; n++)
|
||||
{
|
||||
valueStr = ChartCached.FloatToStr(serieData.GetData(n), numericFormatter);
|
||||
Replace(ref content, GetPHCC(n), i, valueStr, true);
|
||||
}
|
||||
if (!first) sb.Append(PH_NN);
|
||||
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
|
||||
sb.Append(content);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isScatter)
|
||||
{
|
||||
return TrimAndReplaceLine(sb);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
if (needCategory) return category + PH_NN + TrimAndReplaceLine(sb);
|
||||
else return TrimAndReplaceLine(sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
title = title.Replace(PH_ON, PH_NN);
|
||||
title = title.Replace(PH_BR, PH_NN);
|
||||
return title + PH_NN + TrimAndReplaceLine(sb);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string content = tooltip.formatter;
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
if (serie.show)
|
||||
{
|
||||
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
|
||||
var serieData = serie.GetSerieData(dataIndex, dataZoom);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
var percent = serieData.GetData(1) / serie.yTotal * 100;
|
||||
Replace(ref content, PH_A, i, serie.name);
|
||||
Replace(ref content, PH_B, i, needCategory ? category : serieData.name);
|
||||
Replace(ref content, PH_C, i, ChartCached.FloatToStr(serieData.GetData(1), numericFormatter));
|
||||
Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, string.Empty, 1));
|
||||
Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
|
||||
for (int n = 0; n < serieData.data.Count; n++)
|
||||
{
|
||||
var valueStr = ChartCached.FloatToStr(serieData.GetData(n), numericFormatter);
|
||||
if (i == 0) Replace(ref content, GetPHCC(n), i, valueStr, true);
|
||||
Replace(ref content, GetPHCC(i, n), i, valueStr, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
content = content.Replace(PH_ON, PH_NN);
|
||||
content = content.Replace(PH_BR, PH_NN);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private static string TrimAndReplaceLine(StringBuilder sb)
|
||||
{
|
||||
return sb.ToString().Trim().Replace(PH_ON, PH_NN_BBB).Replace(PH_BR, PH_NN_BBB);
|
||||
}
|
||||
|
||||
private static bool IsSelectedSerie(Tooltip tooltip, int serieIndex)
|
||||
{
|
||||
if (tooltip.runtimeSerieDataIndex.ContainsKey(serieIndex))
|
||||
{
|
||||
return tooltip.runtimeSerieDataIndex[serieIndex].Count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Replace(ref string content, string placeHolder, int index, string newStr, bool all = false)
|
||||
{
|
||||
if ((all || index == 0) && content.IndexOf(placeHolder) >= 0)
|
||||
{
|
||||
content = content.Replace(placeHolder, newStr);
|
||||
}
|
||||
if (!s_PHDic.ContainsKey(placeHolder))
|
||||
{
|
||||
s_PHDic[placeHolder] = new Dictionary<int, string>();
|
||||
}
|
||||
if (!s_PHDic[placeHolder].ContainsKey(index))
|
||||
{
|
||||
s_PHDic[placeHolder][index] = placeHolder.Insert(2, index.ToString());
|
||||
}
|
||||
var holder = s_PHDic[placeHolder][index];
|
||||
if (content.IndexOf(holder) >= 0)
|
||||
{
|
||||
content = content.Replace(holder, newStr);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetPHCC(int index)
|
||||
{
|
||||
if (!s_PHCCDic.ContainsKey(index))
|
||||
{
|
||||
s_PHCCDic[index] = "{c:" + index + "}";
|
||||
}
|
||||
return s_PHCCDic[index];
|
||||
}
|
||||
|
||||
private static string GetPHCC(int serieIndex, int dataIndex)
|
||||
{
|
||||
if (!s_PHSerieCCDic.ContainsKey(serieIndex))
|
||||
{
|
||||
s_PHSerieCCDic[serieIndex] = new Dictionary<int, string>();
|
||||
}
|
||||
if (!s_PHSerieCCDic[serieIndex].ContainsKey(dataIndex))
|
||||
{
|
||||
s_PHSerieCCDic[serieIndex][dataIndex] = "{c" + serieIndex + ":" + dataIndex + "}";
|
||||
}
|
||||
return s_PHSerieCCDic[serieIndex][dataIndex];
|
||||
}
|
||||
|
||||
private static string GetItemFormatter(Tooltip tooltip, Serie serie, SerieData serieData)
|
||||
{
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
|
||||
if (!string.IsNullOrEmpty(itemStyle.tooltipFormatter)) return itemStyle.tooltipFormatter;
|
||||
else return tooltip.itemFormatter;
|
||||
}
|
||||
|
||||
private static string GetItemNumericFormatter(Tooltip tooltip, Serie serie, SerieData serieData)
|
||||
{
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
|
||||
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
|
||||
else return tooltip.numericFormatter;
|
||||
}
|
||||
|
||||
public static Color GetLineColor(Tooltip tooltip, ThemeInfo theme)
|
||||
{
|
||||
var lineStyle = tooltip.lineStyle;
|
||||
if (!ChartHelper.IsClearColor(lineStyle.color))
|
||||
{
|
||||
var color = lineStyle.color;
|
||||
color.a *= lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.tooltipLineColor;
|
||||
color.a *= lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/TooltipHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/TooltipHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0fa1b19683a8424bb335802de5c9726
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Runtime/Internal/Helper/VisualMapHelper.cs
Normal file
14
Runtime/Internal/Helper/VisualMapHelper.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class VisualMapHelper
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/VisualMapHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/VisualMapHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15e5106bd46f5484596429d512f6af5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Runtime/Internal/Interface.meta
Normal file
8
Runtime/Internal/Interface.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e4276d289bef4136b22e6cc8b207d99
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Runtime/Internal/Interface/IJsonData.cs
Normal file
17
Runtime/Internal/Interface/IJsonData.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 从json导入数据接口
|
||||
/// </summary>
|
||||
public interface IJsonData
|
||||
{
|
||||
void ParseJsonData(string json);
|
||||
}
|
||||
}
|
||||
13
Runtime/Internal/Interface/IJsonData.cs.meta
Normal file
13
Runtime/Internal/Interface/IJsonData.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9132f4c137015247b44450c2cb23606
|
||||
timeCreated: 1555379601
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Runtime/Internal/Interface/IPropertyChanged.cs
Normal file
18
Runtime/Internal/Interface/IPropertyChanged.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 属性变更接口
|
||||
/// </summary>
|
||||
public interface IPropertyChanged
|
||||
{
|
||||
void OnChanged();
|
||||
}
|
||||
}
|
||||
|
||||
13
Runtime/Internal/Interface/IPropertyChanged.cs.meta
Normal file
13
Runtime/Internal/Interface/IPropertyChanged.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24f32e2d632f08245ae885545f14a2a3
|
||||
timeCreated: 1554979427
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Runtime/Internal/Object.meta
Normal file
8
Runtime/Internal/Object.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d225ec4fe992405d91714722649cc93
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Runtime/Internal/Object/ChartObject.cs
Normal file
22
Runtime/Internal/Object/ChartObject.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class ChartObject
|
||||
{
|
||||
protected GameObject m_GameObject;
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
GameObject.Destroy(m_GameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Object/ChartObject.cs.meta
Normal file
11
Runtime/Internal/Object/ChartObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fe3102b0eea042938d30af910ca86d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
147
Runtime/Internal/Object/LabelObject.cs
Normal file
147
Runtime/Internal/Object/LabelObject.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class LabelObject : ChartObject
|
||||
{
|
||||
private bool m_LabelAutoSize = true;
|
||||
private float m_LabelPaddingLeftRight = 3f;
|
||||
private float m_LabelPaddingTopBottom = 3f;
|
||||
private Text m_LabelText;
|
||||
private RectTransform m_LabelRect;
|
||||
private RectTransform m_IconRect;
|
||||
private Image m_IconImage;
|
||||
|
||||
public GameObject gameObject { get { return m_GameObject; } }
|
||||
public Image icon { get { return m_IconImage; } }
|
||||
public Text label { get { return m_LabelText; } }
|
||||
|
||||
public LabelObject()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
||||
{
|
||||
m_GameObject = labelObj;
|
||||
m_LabelAutoSize = autoSize;
|
||||
m_LabelPaddingLeftRight = paddingLeftRight;
|
||||
m_LabelPaddingTopBottom = paddingTopBottom;
|
||||
m_LabelText = labelObj.GetComponentInChildren<Text>();
|
||||
m_LabelRect = m_LabelText.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void SetIcon(Image image)
|
||||
{
|
||||
m_IconImage = image;
|
||||
if (image != null)
|
||||
{
|
||||
m_IconRect = m_IconImage.GetComponent<RectTransform>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIconSprite(Sprite sprite)
|
||||
{
|
||||
if (m_IconImage != null) m_IconImage.sprite = sprite;
|
||||
}
|
||||
|
||||
public void SetIconSize(float width, float height)
|
||||
{
|
||||
if (m_IconRect != null) m_IconRect.sizeDelta = new Vector3(width, height);
|
||||
}
|
||||
|
||||
public void UpdateIcon(IconStyle iconStyle)
|
||||
{
|
||||
if (m_IconImage == null) return;
|
||||
if (iconStyle.show)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, true);
|
||||
m_IconImage.sprite = iconStyle.sprite;
|
||||
m_IconImage.color = iconStyle.color;
|
||||
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
|
||||
m_IconImage.transform.localPosition = iconStyle.offset;
|
||||
if (iconStyle.layer == IconStyle.Layer.UnderLabel)
|
||||
m_IconRect.SetSiblingIndex(0);
|
||||
else
|
||||
m_IconRect.SetSiblingIndex(m_GameObject.transform.childCount - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, false);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetLabelWidth()
|
||||
{
|
||||
if (m_LabelRect) return m_LabelRect.sizeDelta.x;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetLabelHeight()
|
||||
{
|
||||
if (m_LabelRect) return m_LabelRect.sizeDelta.y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void SetLabelColor(Color color)
|
||||
{
|
||||
if (m_LabelText) m_LabelText.color = color;
|
||||
}
|
||||
|
||||
public void SetLabelRotate(float rotate)
|
||||
{
|
||||
if (m_LabelText) m_LabelText.transform.localEulerAngles = new Vector3(0, 0, rotate);
|
||||
}
|
||||
|
||||
public void SetPosition(Vector3 position)
|
||||
{
|
||||
if (m_GameObject != null)
|
||||
{
|
||||
m_GameObject.transform.localPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLabelPosition(Vector3 position)
|
||||
{
|
||||
if (m_LabelRect) m_LabelRect.localPosition = position;
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
if (m_GameObject) ChartHelper.SetActive(m_GameObject, flag);
|
||||
}
|
||||
public void SetLabelActive(bool flag)
|
||||
{
|
||||
if (m_LabelText) ChartHelper.SetActive(m_LabelText, flag);
|
||||
}
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
if (m_IconImage) ChartHelper.SetActive(m_IconImage, flag);
|
||||
}
|
||||
|
||||
public bool SetText(string text)
|
||||
{
|
||||
if (m_LabelText && !m_LabelText.text.Equals(text))
|
||||
{
|
||||
m_LabelText.text = text;
|
||||
if (m_LabelAutoSize)
|
||||
{
|
||||
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
|
||||
new Vector2(m_LabelText.preferredWidth + m_LabelPaddingLeftRight * 2,
|
||||
m_LabelText.preferredHeight + m_LabelPaddingTopBottom * 2);
|
||||
var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y;
|
||||
if (sizeChange) m_LabelRect.sizeDelta = newSize;
|
||||
return sizeChange;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Object/LabelObject.cs.meta
Normal file
11
Runtime/Internal/Object/LabelObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1277b7528331b42cfb61da7a2c762bee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3452002928282423f988cd5c5ecf318a
|
||||
guid: 3e5abcb8f339f41f5b3680ecdab67509
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
8
Runtime/Internal/Pools.meta
Normal file
8
Runtime/Internal/Pools.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 576ce681815d348d0a2abbbadf3dd9f7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d6006e13d2c640b9909e4d4121c01ea
|
||||
guid: 3a709ca44e9a445bd86bde1bbfae80de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 359b8b077c5954701a132fe69eb8ba9c
|
||||
guid: 02c30457469c746dc96f00f24cb6e1c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a543f22be703f4d58b47fa6d343581c8
|
||||
guid: 09e67988253cb4f568b82d52b4113797
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bd0d723595ba485dbe696491cf978f3
|
||||
guid: faf4da15b01d74648bd13f73125e27bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 340f267fa46e74d0bbbb0b75a20bd708
|
||||
guid: e960aeb14c09844e3bdcdc4138af0761
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,52 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class PropertyUtility
|
||||
{
|
||||
public static bool SetColor(ref Color currentValue, Color newValue)
|
||||
{
|
||||
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SetColor(ref Color32 currentValue, Color32 newValue)
|
||||
{
|
||||
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(currentValue, newValue))
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SetClass<T>(ref T currentValue, T newValue, bool notNull = false) where T : class
|
||||
{
|
||||
if (notNull)
|
||||
{
|
||||
if (newValue == null)
|
||||
{
|
||||
Debug.LogError("can not be null.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user