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

View File

@@ -1,7 +1,6 @@

using System;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace XCharts.Runtime
{
@@ -233,7 +232,7 @@ namespace XCharts.Runtime
if (m_IsEnd)
return;
m_ActualDuration = (int)((Time.time - startTime) * 1000) - (m_FadeOut ? fadeOutDelay : fadeInDelay);
m_ActualDuration = (int) ((Time.time - startTime) * 1000) - (m_FadeOut ? fadeOutDelay : fadeInDelay);
m_IsEnd = true;
m_IsInit = false;
@@ -380,9 +379,9 @@ namespace XCharts.Runtime
public bool IsIndexAnimation()
{
return context.type == AnimationType.LeftToRight
|| context.type == AnimationType.Clockwise
|| context.type == AnimationType.AlongPath;
return context.type == AnimationType.LeftToRight ||
context.type == AnimationType.Clockwise ||
context.type == AnimationType.AlongPath;
}
public float GetIndexDelay(int dataIndex)
@@ -462,9 +461,9 @@ namespace XCharts.Runtime
if (IsInDelay())
return;
m_ActualDuration = (int)((Time.time - startTime) * 1000) - fadeInDelay;
m_ActualDuration = (int) ((Time.time - startTime) * 1000) - fadeInDelay;
var duration = GetCurrAnimationDuration();
var delta = (float)(total / duration * Time.deltaTime);
var delta = (float) (total / duration * Time.deltaTime);
if (m_FadeOut)
{
m_CurrDetailProgress -= delta;
@@ -534,8 +533,8 @@ namespace XCharts.Runtime
}
else
{
if ((destProgress - startProgress > 0 && currHig > destProgress)
|| (destProgress - startProgress < 0 && currHig < destProgress))
if ((destProgress - startProgress > 0 && currHig > destProgress) ||
(destProgress - startProgress < 0 && currHig < destProgress))
{
currHig = destProgress;
isEnd = true;
@@ -613,7 +612,7 @@ namespace XCharts.Runtime
#endif
if (!enable || m_IsEnd)
return -1;
return (int)m_CurrDetailProgress;
return (int) m_CurrDetailProgress;
}
public float GetUpdateAnimationDuration()

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using UnityEngine;

View File

@@ -39,9 +39,9 @@ namespace XCharts.Runtime
public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType)
{
animation.context.type = animation.type == AnimationType.Default
? defaultType
: animation.type;
animation.context.type = animation.type == AnimationType.Default ?
defaultType :
animation.type;
}
public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip)

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;

View File

@@ -86,7 +86,7 @@ namespace XCharts.Runtime
bool inside = axis.axisLabel.inside;
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.context.minValue, axis.context.maxValue,
null, isPercentStack);
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
new Vector2(scaleAngle, txtHig), axis,
chart.theme.axis, labelName, Color.clear);
label.text.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
@@ -124,9 +124,9 @@ namespace XCharts.Runtime
}
if (angleAxis.show && angleAxis.axisTick.show)
{
if ((i == 1 && angleAxis.axisTick.showStartTick)
|| (i == size - 1 && angleAxis.axisTick.showEndTick)
|| (i > 1 && i < size - 1))
if ((i == 1 && angleAxis.axisTick.showStartTick) ||
(i == size - 1 && angleAxis.axisTick.showEndTick) ||
(i > 1 && i < size - 1))
{
var tickY = radius + tickLength;
var tickPos = ChartHelper.GetPos(cenPos, tickY, currAngle, true);

View File

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

using System;
using System.Collections.Generic;
using UnityEngine;
@@ -366,11 +365,11 @@ namespace XCharts.Runtime
{
get
{
return m_VertsDirty
|| axisLine.anyDirty
|| axisTick.anyDirty
|| splitLine.anyDirty
|| splitArea.anyDirty;
return m_VertsDirty ||
axisLine.anyDirty ||
axisTick.anyDirty ||
splitLine.anyDirty ||
splitArea.anyDirty;
}
}
@@ -378,9 +377,9 @@ namespace XCharts.Runtime
{
get
{
return m_ComponentDirty
|| axisName.anyDirty
|| axisLabel.anyDirty;
return m_ComponentDirty ||
axisName.anyDirty ||
axisLabel.anyDirty;
}
}
@@ -656,11 +655,11 @@ namespace XCharts.Runtime
if (IsCategory() && boundaryGap)
{
var each = axisLength / data.Count;
return (float)(each * (value + 0.5f));
return (float) (each * (value + 0.5f));
}
else
{
return axisLength * (float)((value - context.minValue) / context.minMaxRange);
return axisLength * (float) ((value - context.minValue) / context.minMaxRange);
}
}
@@ -754,21 +753,21 @@ namespace XCharts.Runtime
if (value <= 0 || value == 1)
return 0;
else
return logBaseE ? (float)Math.Log(value) : (float)Math.Log(value, logBase);
return logBaseE ? (float) Math.Log(value) : (float) Math.Log(value, logBase);
}
public int GetLogMinIndex()
{
return logBaseE
? (int)Math.Log(context.minValue)
: (int)Math.Log(context.minValue, logBase);
return logBaseE ?
(int) Math.Log(context.minValue) :
(int) Math.Log(context.minValue, logBase);
}
public int GetLogMaxIndex()
{
return logBaseE
? (int)Math.Log(context.maxValue)
: (int)Math.Log(context.maxValue, logBase);
return logBaseE ?
(int) Math.Log(context.maxValue) :
(int) Math.Log(context.maxValue, logBase);
}
public double GetLabelValue(int index)

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -56,7 +55,6 @@ namespace XCharts.Runtime
private List<double> m_LabelValueList = new List<double>();
private List<string> m_RuntimeData = new List<string>();
internal void Clear()
{
m_RuntimeData.Clear();
@@ -87,10 +85,10 @@ namespace XCharts.Runtime
if (end > data.Count) end = data.Count;
}
if (start != filterStart
|| end != filterEnd
|| dataZoom.minShowNum != filterMinShow
|| isNeedUpdateFilterData)
if (start != filterStart ||
end != filterEnd ||
dataZoom.minShowNum != filterMinShow ||
isNeedUpdateFilterData)
{
filterStart = start;
filterEnd = end;

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
using UnityEngine.UI;
@@ -8,7 +7,7 @@ using XUGL;
namespace XCharts
{
public abstract class AxisHandler<T> : MainComponentHandler
where T : Axis
where T : Axis
{
private static readonly string s_DefaultAxisName = "name";
private double m_LastInterval = double.MinValue;
@@ -17,7 +16,7 @@ namespace XCharts
internal override void SetComponent(MainComponent component)
{
this.component = (T)component;
this.component = (T) component;
}
protected virtual Vector3 GetLabelPosition(float scaleWid, int i)
@@ -25,6 +24,11 @@ namespace XCharts
return Vector3.zero;
}
protected virtual float GetAxisLineXOrY()
{
return 0;
}
protected virtual Orient orient { get; set; }
protected virtual void UpdatePointerValue(Axis axis)
@@ -50,8 +54,8 @@ namespace XCharts
for (int j = 0; j < axis.GetDataCount(dataZoom); j++)
{
float pY = grid.context.y + j * splitWid;
if ((axis.boundaryGap && (local.y > pY && local.y <= pY + splitWid))
|| (!axis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
if ((axis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
(!axis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
{
axis.context.pointerValue = j;
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
@@ -70,8 +74,8 @@ namespace XCharts
for (int j = 0; j < axis.GetDataCount(dataZoom); j++)
{
float pX = grid.context.x + j * splitWid;
if ((axis.boundaryGap && (local.x > pX && local.x <= pX + splitWid))
|| (!axis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
if ((axis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
(!axis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
{
axis.context.pointerValue = j;
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
@@ -140,10 +144,10 @@ namespace XCharts
double tempMaxValue = 0;
chart.GetSeriesMinMaxValue(axis, axisIndex, out tempMinValue, out tempMaxValue);
if (tempMinValue != axis.context.minValue
|| tempMaxValue != axis.context.maxValue
|| m_LastInterval != axis.interval
|| m_LastSplitNumber != axis.splitNumber)
if (tempMinValue != axis.context.minValue ||
tempMaxValue != axis.context.maxValue ||
m_LastInterval != axis.interval ||
m_LastSplitNumber != axis.splitNumber)
{
m_LastSplitNumber = axis.splitNumber;
m_LastInterval = axis.interval;
@@ -151,7 +155,6 @@ namespace XCharts
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
axis.context.offset = 0;
axis.context.lastCheckInverse = axis.inverse;
UpdateAxisTickValueList(axis);
if (tempMinValue != 0 || tempMaxValue != 0)
@@ -159,31 +162,31 @@ namespace XCharts
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
if (grid != null && axis is XAxis && axis.IsValue())
{
axis.context.offset = axis.context.minValue > 0
? 0
: (axis.context.maxValue < 0
? grid.context.width
: (float)(Math.Abs(axis.context.minValue) * (grid.context.width
/ (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue))))
axis.context.offset = axis.context.minValue > 0 ?
0 :
(axis.context.maxValue < 0 ?
grid.context.width :
(float) (Math.Abs(axis.context.minValue) * (grid.context.width /
(Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue))))
);
axis.context.x = grid.context.x;
axis.context.y = grid.context.y;
axis.context.y = GetAxisLineXOrY();
axis.context.zeroY = grid.context.y;
axis.context.zeroX = grid.context.x - (float)(axis.context.minValue * grid.context.width / axis.context.minMaxRange);
axis.context.zeroX = grid.context.x - (float) (axis.context.minValue * grid.context.width / axis.context.minMaxRange);
}
if (grid != null && axis is YAxis && axis.IsValue())
{
axis.context.offset = axis.context.minValue > 0
? 0
: (axis.context.maxValue < 0
? grid.context.height
: (float)(Math.Abs(axis.context.minValue) * (grid.context.height
/ (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue))))
axis.context.offset = axis.context.minValue > 0 ?
0 :
(axis.context.maxValue < 0 ?
grid.context.height :
(float) (Math.Abs(axis.context.minValue) * (grid.context.height /
(Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue))))
);
axis.context.x = grid.context.x;
axis.context.x = GetAxisLineXOrY();
axis.context.y = grid.context.y;
axis.context.zeroX = grid.context.x;
axis.context.zeroY = grid.context.y - (float)(axis.context.minValue * grid.context.height / axis.context.minMaxRange);
axis.context.zeroY = grid.context.y - (float) (axis.context.minValue * grid.context.height / axis.context.minMaxRange);
}
}
var dataZoom = chart.GetDataZoomOfAxis(axis);
@@ -220,8 +223,8 @@ namespace XCharts
if (axis.IsTime())
{
var lastCount = axis.context.labelValueList.Count;
DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList, (int)axis.context.minValue,
(int)axis.context.maxValue, axis.splitNumber);
DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList, (int) axis.context.minValue,
(int) axis.context.maxValue, axis.splitNumber);
if (axis.context.labelValueList.Count != lastCount)
axis.SetAllDirty();
@@ -255,7 +258,7 @@ namespace XCharts
}
}
var value = 0d;
if (Mathf.Approximately((float)(axis.context.minValue % tick), 0))
if (Mathf.Approximately((float) (axis.context.minValue % tick), 0))
{
value = axis.context.minValue;
}
@@ -328,9 +331,10 @@ namespace XCharts
}
}
internal static void InitAxis(Axis axis, Axis relativedAxis, BaseChart chart, AxisHandler<T> handler,
Orient orient, float axisStartX, float axisStartY, float axisLength, float relativedLength)
protected void InitAxis(Axis relativedAxis, Orient orient,
float axisStartX, float axisStartY, float axisLength, float relativedLength)
{
Axis axis = component;
chart.InitAxisRuntimeData(axis);
var objName = ChartCached.GetComponentObjectName(axis);
@@ -358,23 +362,23 @@ namespace XCharts
var eachWidth = AxisHelper.GetEachWidth(axis, axisLength, dataZoom);
var gapWidth = axis.boundaryGap ? eachWidth / 2 : 0;
var textWidth = axis.axisLabel.width > 0
? axis.axisLabel.width
: (orient == Orient.Horizonal
? AxisHelper.GetScaleWidth(axis, axisLength, 0, dataZoom)
: (axisStartX - chart.chartX)
var textWidth = axis.axisLabel.width > 0 ?
axis.axisLabel.width :
(orient == Orient.Horizonal ?
AxisHelper.GetScaleWidth(axis, axisLength, 0, dataZoom) :
(axisStartX - chart.chartX)
);
var textHeight = axis.axisLabel.height > 0
? axis.axisLabel.height
: 20f;
var textHeight = axis.axisLabel.height > 0 ?
axis.axisLabel.height :
20f;
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
var inside = axis.axisLabel.inside;
var defaultAlignment = orient == Orient.Horizonal ? TextAnchor.MiddleCenter :
((inside && axis.IsLeft()) || (!inside && axis.IsRight())
? TextAnchor.MiddleLeft
: TextAnchor.MiddleRight);
((inside && axis.IsLeft()) || (!inside && axis.IsRight()) ?
TextAnchor.MiddleLeft :
TextAnchor.MiddleRight);
if (axis.IsCategory() && axis.boundaryGap)
splitNumber -= 1;
@@ -398,9 +402,9 @@ namespace XCharts
if (i == 0)
axis.axisLabel.SetRelatedText(label.text, labelWidth);
var pos = handler.GetLabelPosition(totalWidth + gapWidth, i);
var pos = GetLabelPosition(totalWidth + gapWidth, i);
label.SetPosition(pos);
handler.CheckValueLabelActive(axis, i, label, pos);
CheckValueLabelActive(axis, i, label, pos);
axis.context.labelObjectList.Add(label);
@@ -415,6 +419,7 @@ namespace XCharts
var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor);
if (orient == Orient.Horizonal)
{
var posY = GetAxisLineXOrY() + offset.y;
switch (axis.axisName.labelStyle.position)
{
case LabelStyle.Position.Start:
@@ -422,9 +427,9 @@ namespace XCharts
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleRight);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Top
? new Vector2(zeroPos.x - offset.x, axisStartY + relativedLength + offset.y + axis.offset)
: new Vector2(zeroPos.x - offset.x, zeroPos.y + offset.y + axis.offset));
label.SetPosition(axis.position == Axis.AxisPosition.Top ?
new Vector2(zeroPos.x - offset.x, axisStartY + relativedLength + offset.y + axis.offset) :
new Vector2(zeroPos.x - offset.x, posY));
break;
case LabelStyle.Position.Middle:
@@ -432,9 +437,9 @@ namespace XCharts
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Top
? new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY + relativedLength - offset.y + axis.offset)
: new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY - offset.y + axis.offset));
label.SetPosition(axis.position == Axis.AxisPosition.Top ?
new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY + relativedLength - offset.y + axis.offset) :
new Vector2(axisStartX + axisLength / 2 + offset.x, posY));
break;
default:
@@ -442,44 +447,45 @@ namespace XCharts
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleLeft);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Top
? new Vector2(axisStartX + axisLength + offset.x, axisStartY + relativedLength + offset.y + axis.offset)
: new Vector2(axisStartX + axisLength + offset.x, zeroPos.y + offset.y + axis.offset));
label.SetPosition(axis.position == Axis.AxisPosition.Top ?
new Vector2(axisStartX + axisLength + offset.x, axisStartY + relativedLength + offset.y + axis.offset) :
new Vector2(axisStartX + axisLength + offset.x, posY));
break;
}
}
else
{
var posX = GetAxisLineXOrY() + offset.x;
switch (axis.axisName.labelStyle.position)
{
case LabelStyle.Position.Start:
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Right ?
new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY - offset.y) :
new Vector2(zeroPos.x + offset.x + axis.offset, axisStartY - offset.y));
new Vector2(posX, axisStartY - offset.y));
break;
case LabelStyle.Position.Middle:
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Right ?
new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) :
new Vector2(axisStartX - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y));
new Vector2(posX, axisStartY + axisLength / 2 + offset.y));
break;
default:
//LabelStyle.Position
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Right ?
new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY + axisLength + offset.y) :
new Vector2(zeroPos.x + offset.x + axis.offset, axisStartY + axisLength + offset.y));
new Vector2(posX, axisStartY + axisLength + offset.y));
break;
}
}
@@ -495,9 +501,9 @@ namespace XCharts
if (axis.IsTime() || axis.IsValue())
{
scaleWid = axis.context.minMaxRange != 0
? axis.GetDistance(axis.GetLabelValue(i), axisLength)
: 0;
scaleWid = axis.context.minMaxRange != 0 ?
axis.GetDistance(axis.GetLabelValue(i), axisLength) :
0;
}
if (orient == Orient.Horizonal)
@@ -513,7 +519,7 @@ namespace XCharts
else
current += axisStartY - axis.axisLabel.distance - fontSize / 2;
return new Vector3(axisStartX + scaleWid, current);
return new Vector3(axisStartX + scaleWid, current) + axis.axisLabel.offset;
}
else
{
@@ -528,7 +534,7 @@ namespace XCharts
else
current += axisStartX - axis.axisLabel.distance;
return new Vector3(current, axisStartY + scaleWid);
return new Vector3(current, axisStartY + scaleWid) + axis.axisLabel.offset;
}
}
@@ -566,9 +572,9 @@ namespace XCharts
{
var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
var current = orient == Orient.Horizonal
? startX
: startY;
var current = orient == Orient.Horizonal ?
startX :
startY;
for (int i = 0; i < size; i++)
{
@@ -587,17 +593,17 @@ namespace XCharts
{
if (orient == Orient.Horizonal)
{
float pX = axis.IsTime()
? (startX + axis.GetDistance(axis.GetLabelValue(i), axisLength))
: current;
float pX = axis.IsTime() ?
(startX + axis.GetDistance(axis.GetLabelValue(i), axisLength)) :
current;
if (axis.boundaryGap && axis.axisTick.alignWithLabel)
pX -= scaleWidth / 2;
var sY = 0f;
var eY = 0f;
if ((axis.axisTick.inside && axis.IsBottom())
|| (!axis.axisTick.inside && axis.IsTop()))
if ((axis.axisTick.inside && axis.IsBottom()) ||
(!axis.axisTick.inside && axis.IsTop()))
{
sY = startY + axis.offset + lineWidth;
eY = sY + tickLength;
@@ -614,17 +620,17 @@ namespace XCharts
}
else
{
float pY = axis.IsTime()
? (startY + axis.GetDistance(axis.GetLabelValue(i), axisLength))
: current;
float pY = axis.IsTime() ?
(startY + axis.GetDistance(axis.GetLabelValue(i), axisLength)) :
current;
if (axis.boundaryGap && axis.axisTick.alignWithLabel)
pY -= scaleWidth / 2;
var sX = 0f;
var eX = 0f;
if ((axis.axisTick.inside && axis.IsLeft())
|| (!axis.axisTick.inside && axis.IsRight()))
if ((axis.axisTick.inside && axis.IsLeft()) ||
(!axis.axisTick.inside && axis.IsRight()))
{
sX = startX + axis.offset + lineWidth;
eX = sX + tickLength;
@@ -690,9 +696,10 @@ namespace XCharts
}
}
internal static void DrawAxisSplit(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom,
protected void DrawAxisSplit(VertexHelper vh, AxisTheme theme, DataZoom dataZoom,
Orient orient, float startX, float startY, float axisLength, float splitLength, Axis relativedAxis = null)
{
Axis axis = component;
var lineColor = axis.splitLine.GetColor(theme.splitLineColor);
var lineWidth = axis.splitLine.GetWidth(theme.lineWidth);
var lineType = axis.splitLine.GetType(theme.splitLineType);
@@ -705,9 +712,9 @@ namespace XCharts
size += 1;
}
var current = orient == Orient.Horizonal
? startX
: startY;
var current = orient == Orient.Horizonal ?
startX :
startY;
for (int i = 0; i < size; i++)
{
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom);
@@ -743,7 +750,7 @@ namespace XCharts
{
if (orient == Orient.Horizonal)
{
if (relativedAxis == null || !MathUtil.Approximately(current, relativedAxis.context.x))
if (relativedAxis == null || !MathUtil.Approximately(current, GetAxisLineXOrY()))
ChartDrawer.DrawLineStyle(vh,
lineType,
lineWidth,
@@ -753,7 +760,7 @@ namespace XCharts
}
else
{
if (relativedAxis == null || !MathUtil.Approximately(current, relativedAxis.context.y))
if (relativedAxis == null || !MathUtil.Approximately(current, GetAxisLineXOrY()))
ChartDrawer.DrawLineStyle(vh,
lineType,
lineWidth,
@@ -761,7 +768,6 @@ namespace XCharts
new Vector3(startX + splitLength, current),
lineColor);
}
}
}
current += scaleWidth;

View File

@@ -120,15 +120,15 @@ namespace XCharts.Runtime
maxValue = -maxValue;
}
if (forcePercent)
return string.Format("{0}%", (int)value);
return string.Format("{0}%", (int) value);
else
return axis.axisLabel.GetFormatterContent(index, value, minValue, maxValue);
}
else if (axis.type == Axis.AxisType.Log)
{
float value = axis.logBaseE
? Mathf.Exp(axis.GetLogMinIndex() + index)
: Mathf.Pow(axis.logBase, axis.GetLogMinIndex() + index);
double value = axis.logBaseE ?
System.Math.Exp(axis.GetLogMinIndex() + index) :
System.Math.Pow(axis.logBase, axis.GetLogMinIndex() + index);
if (axis.inverse)
{
value = -value;
@@ -206,16 +206,16 @@ namespace XCharts.Runtime
if (axis.boundaryGap)
{
scaleNum = dataCount > 2 && dataCount % splitNum == 0
? splitNum + 1
: splitNum + 2;
scaleNum = dataCount > 2 && dataCount % splitNum == 0 ?
splitNum + 1 :
splitNum + 2;
}
else
{
if (dataCount < splitNum) scaleNum = splitNum;
else scaleNum = dataCount > 2 && dataCount % splitNum == 0
? splitNum
: splitNum + 1;
else scaleNum = dataCount > 2 && dataCount % splitNum == 0 ?
splitNum :
splitNum + 1;
}
return scaleNum;
}
@@ -245,9 +245,9 @@ namespace XCharts.Runtime
{
var value = axis.GetLabelValue(index);
var lastValue = axis.GetLabelValue(index - 1);
return axis.context.minMaxRange == 0
? 0
: (float)(coordinateWidth * (value - lastValue) / axis.context.minMaxRange);
return axis.context.minMaxRange == 0 ?
0 :
(float) (coordinateWidth * (value - lastValue) / axis.context.minMaxRange);
}
else
{
@@ -339,8 +339,7 @@ namespace XCharts.Runtime
return;
}
if (axis.type == Axis.AxisType.Time)
{
}
{ }
else if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
{
if (axis.min != 0 || axis.max != 0)
@@ -365,8 +364,7 @@ namespace XCharts.Runtime
case Axis.AxisMinMaxType.Default:
if (minValue == 0 && maxValue == 0)
{
}
{ }
else if (minValue > 0 && maxValue > 0)
{
minValue = 0;
@@ -454,7 +452,7 @@ namespace XCharts.Runtime
if (axis.IsCategory())
{
if (dataCount == 0) dataCount = axis.data.Count;
var categoryIndex = (int)value;
var categoryIndex = (int) value;
var scaleWid = AxisHelper.GetDataWidth(axis, gridHeight, dataCount, dataZoom);
float startY = gridXY + (axis.boundaryGap ? scaleWid / 2 : 0);
return startY + scaleWid * categoryIndex;
@@ -462,7 +460,7 @@ namespace XCharts.Runtime
else
{
var yDataHig = (axis.context.minMaxRange == 0) ? 0f :
(float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
(float) ((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
return gridXY + yDataHig;
}
@@ -533,16 +531,16 @@ namespace XCharts.Runtime
{
int minIndex = axis.GetLogMinIndex();
float nowIndex = axis.GetLogValue(value);
return includeGridXY
? gridXY + (nowIndex - minIndex) / axis.splitNumber * gridHeight
: (nowIndex - minIndex) / axis.splitNumber * gridHeight;
return includeGridXY ?
gridXY + (nowIndex - minIndex) / axis.splitNumber * gridHeight :
(nowIndex - minIndex) / axis.splitNumber * gridHeight;
}
else if (axis.IsCategory())
{
var categoryIndex = (int)value;
return includeGridXY
? gridXY + (axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex
: (axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex;
var categoryIndex = (int) value;
return includeGridXY ?
gridXY + (axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex :
(axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex;
}
else
{
@@ -550,13 +548,13 @@ namespace XCharts.Runtime
if (axis.context.minMaxRange != 0)
{
if (realLength)
yDataHig = (float)(value * gridHeight / axis.context.minMaxRange);
yDataHig = (float) (value * gridHeight / axis.context.minMaxRange);
else
yDataHig = (float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
yDataHig = (float) ((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
}
return includeGridXY
? gridXY + yDataHig
: yDataHig;
return includeGridXY ?
gridXY + yDataHig :
yDataHig;
}
}
}

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
using UnityEngine.UI;
@@ -97,10 +96,10 @@ namespace XCharts.Runtime
return new AxisLabel()
{
m_Show = true,
m_Interval = 0,
m_Inside = false,
m_Distance = 8,
m_TextStyle = new TextStyle(),
m_Interval = 0,
m_Inside = false,
m_Distance = 8,
m_TextStyle = new TextStyle(),
};
}
}
@@ -150,9 +149,9 @@ namespace XCharts.Runtime
{
return m_FormatterFunction(labelIndex, 0, category);
}
if (string.IsNullOrEmpty(category))
if (string.IsNullOrEmpty(category))
return category;
if (string.IsNullOrEmpty(m_Formatter))
{
return m_TextLimit.GetLimitContent(category);
@@ -205,7 +204,7 @@ namespace XCharts.Runtime
{
return m_FormatterFunction(labelIndex, value, null);
}
var timestamp = (int)value;
var timestamp = (int) value;
var dateTime = DateTimeUtil.GetDateTime(timestamp);
var dateString = string.Empty;
if (string.IsNullOrEmpty(numericFormatter))

View File

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

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -43,7 +42,7 @@ namespace XCharts.Runtime
return new AxisSplitArea()
{
m_Show = false,
m_Color = new List<Color32>() { }
m_Color = new List<Color32>() { }
};
}
}

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;

View File

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

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
@@ -26,6 +25,5 @@ namespace XCharts.Runtime
axisLabel.textLimit.enable = true;
}
}
}

View File

@@ -1,4 +1,3 @@
using UnityEngine;
using UnityEngine.UI;
@@ -64,10 +63,10 @@ namespace XCharts.Runtime
var theme = chart.theme;
var xAxisIndex = axis.index;
axis.painter = chart.painter;
axis.refreshComponent = delegate ()
axis.refreshComponent = delegate()
{
UpdateContext(axis);
InitAxis(axis, null, chart, this,
InitAxis(null,
m_Orient,
axis.context.x,
axis.context.y,
@@ -118,7 +117,7 @@ namespace XCharts.Runtime
var dataZoom = chart.GetDataZoomOfAxis(axis);
DrawAxisSplit(vh, axis, chart.theme.axis, dataZoom,
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
m_Orient,
axis.context.x,
axis.context.y,
@@ -159,5 +158,10 @@ namespace XCharts.Runtime
axis.context.width);
}
}
protected override float GetAxisLineXOrY()
{
return component.context.y;
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
namespace XCharts.Runtime

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -52,7 +51,7 @@ namespace XCharts.Runtime
double tempMinValue = 0;
double tempMaxValue = 0;
SeriesHelper.GetXMinMaxValue(chart.series, null, axis.polarIndex, true, axis.inverse, out tempMinValue,
out tempMaxValue, true);
out tempMaxValue, true);
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue)
{
@@ -132,8 +131,8 @@ namespace XCharts.Runtime
var cenPos = polar.context.center;
var dire = ChartHelper.GetDire(startAngle, true).normalized;
var tickLength = axis.axisTick.GetLength(chart.theme.axis.tickLength);
var tickVector = ChartHelper.GetVertialDire(dire)
* (tickLength + axis.axisLabel.distance);
var tickVector = ChartHelper.GetVertialDire(dire) *
(tickLength + axis.axisLabel.distance);
return ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVector;
}
@@ -168,9 +167,9 @@ namespace XCharts.Runtime
}
if (radiusAxis.show && radiusAxis.axisTick.show)
{
if ((i == 0 && radiusAxis.axisTick.showStartTick)
|| (i == size && radiusAxis.axisTick.showEndTick)
|| (i > 0 && i < size))
if ((i == 0 && radiusAxis.axisTick.showStartTick) ||
(i == size && radiusAxis.axisTick.showEndTick) ||
(i > 0 && i < size))
{
UGL.DrawLine(vh, pos, pos + tickVetor, tickWidth, chart.theme.axis.lineColor);
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
@@ -87,15 +86,15 @@ namespace XCharts.Runtime
if (m_Orient == Orient.Horizonal)
{
context.width = width == 0
? chartWidth - context.left - context.right
: (width <= 1 ? chartWidth * width : width);
context.width = width == 0 ?
chartWidth - context.left - context.right :
(width <= 1 ? chartWidth * width : width);
}
else
{
context.width = width == 0
? chartHeight - context.top - context.bottom
: (width <= 1 ? chartHeight * width : width);
context.width = width == 0 ?
chartHeight - context.top - context.bottom :
(width <= 1 ? chartHeight * width : width);
}
if (context.left != 0 && context.right == 0)

View File

@@ -1,4 +1,3 @@
using UnityEngine;
using UnityEngine.UI;
@@ -32,14 +31,14 @@ namespace XCharts.Runtime
var theme = chart.theme;
var xAxisIndex = axis.index;
axis.painter = chart.painter;
axis.refreshComponent = delegate ()
axis.refreshComponent = delegate()
{
axis.UpdateRuntimeData(chart.chartX,
chart.chartY,
chart.chartWidth,
chart.chartHeight);
InitAxis(axis, null, chart, this,
InitAxis(null,
axis.orient,
axis.context.x,
axis.context.y,
@@ -83,7 +82,7 @@ namespace XCharts.Runtime
if (AxisHelper.NeedShowSplit(axis))
{
var dataZoom = chart.GetDataZoomOfAxis(axis);
DrawAxisSplit(vh, axis, chart.theme.axis, dataZoom,
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
axis.orient,
axis.context.x,
axis.context.y,
@@ -109,14 +108,18 @@ namespace XCharts.Runtime
{
if (axis.show && axis.axisLine.show)
{
var axisStartY = axis.context.y + axis.offset;
DrawAxisLine(vh, axis,
chart.theme.axis,
axis.orient,
axis.context.x,
axisStartY,
GetAxisLineXOrY(),
axis.context.width);
}
}
protected override float GetAxisLineXOrY()
{
return component.context.y + component.offset;
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;

View File

@@ -1,4 +1,3 @@
using UnityEngine;
using UnityEngine.UI;
@@ -32,13 +31,13 @@ namespace XCharts.Runtime
var theme = chart.theme;
var xAxisIndex = xAxis.index;
xAxis.painter = chart.painter;
xAxis.refreshComponent = delegate ()
xAxis.refreshComponent = delegate()
{
var grid = chart.GetChartComponent<GridCoord>(xAxis.gridIndex);
if (grid != null)
{
var yAxis = chart.GetChartComponent<YAxis>(xAxis.index);
InitAxis(xAxis, yAxis, chart, this,
InitAxis(yAxis,
orient,
grid.context.x,
grid.context.y,
@@ -94,7 +93,7 @@ namespace XCharts.Runtime
var relativedAxis = chart.GetChartComponent<YAxis>(xAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
Orient.Horizonal,
grid.context.x,
grid.context.y,
@@ -114,16 +113,10 @@ namespace XCharts.Runtime
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
var startY = grid.context.y + xAxis.offset;
if (xAxis.IsTop())
startY += grid.context.height;
else
startY += ComponentHelper.GetXAxisOnZeroOffset(chart.components, xAxis);
DrawAxisTick(vh, xAxis, chart.theme.axis, dataZoom,
Orient.Horizonal,
grid.context.x,
startY,
GetAxisLineXOrY(),
grid.context.width);
}
}
@@ -136,18 +129,24 @@ namespace XCharts.Runtime
if (grid == null)
return;
var startY = grid.context.y + xAxis.offset;
if (xAxis.IsTop())
startY += grid.context.height;
else
startY += ComponentHelper.GetXAxisOnZeroOffset(chart.components, xAxis);
DrawAxisLine(vh, xAxis, chart.theme.axis,
Orient.Horizonal,
grid.context.x,
startY,
GetAxisLineXOrY(),
grid.context.width);
}
}
protected override float GetAxisLineXOrY()
{
var xAxis = component;
var grid = chart.GetChartComponent<GridCoord>(xAxis.gridIndex);
var startY = grid.context.y + xAxis.offset;
if (xAxis.IsTop())
startY += grid.context.height;
else
startY += ComponentHelper.GetXAxisOnZeroOffset(chart.components, xAxis);
return startY;
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
namespace XCharts.Runtime

View File

@@ -1,4 +1,3 @@
using UnityEngine;
using UnityEngine.UI;
@@ -32,13 +31,13 @@ namespace XCharts.Runtime
var theme = chart.theme;
var yAxisIndex = yAxis.index;
yAxis.painter = chart.painter;
yAxis.refreshComponent = delegate ()
yAxis.refreshComponent = delegate()
{
var grid = chart.GetChartComponent<GridCoord>(yAxis.gridIndex);
if (grid != null)
{
var xAxis = chart.GetChartComponent<YAxis>(yAxis.index);
InitAxis(yAxis, xAxis, chart, this,
InitAxis(xAxis,
orient,
grid.context.x,
grid.context.y,
@@ -91,7 +90,7 @@ namespace XCharts.Runtime
return;
var relativedAxis = chart.GetChartComponent<XAxis>(yAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
Orient.Vertical,
grid.context.x,
grid.context.y,
@@ -111,15 +110,9 @@ namespace XCharts.Runtime
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
var startX = grid.context.x + yAxis.offset;
if (yAxis.IsRight())
startX += grid.context.width;
else
startX += ComponentHelper.GetYAxisOnZeroOffset(chart.components, yAxis);
DrawAxisTick(vh, yAxis, chart.theme.axis, dataZoom,
Orient.Vertical,
startX,
GetAxisLineXOrY(),
grid.context.y,
grid.context.height);
}
@@ -133,18 +126,24 @@ namespace XCharts.Runtime
if (grid == null)
return;
var startX = grid.context.x + yAxis.offset;
if (yAxis.IsRight())
startX += grid.context.width;
else
startX += ComponentHelper.GetYAxisOnZeroOffset(chart.components, yAxis);
DrawAxisLine(vh, yAxis, chart.theme.axis,
Orient.Vertical,
startX,
GetAxisLineXOrY(),
grid.context.y,
grid.context.height);
}
}
protected override float GetAxisLineXOrY()
{
var yAxis = component;
var grid = chart.GetChartComponent<GridCoord>(yAxis.gridIndex);
var startX = grid.context.x + yAxis.offset;
if (yAxis.IsRight())
startX += grid.context.width;
else
startX += ComponentHelper.GetYAxisOnZeroOffset(chart.components, yAxis);
return startX;
}
}
}

View File

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

using System;
using UnityEngine;
using UnityEngine.UI;

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
using UnityEngine.UI;
@@ -13,7 +12,7 @@ namespace XCharts.Runtime
public override void InitComponent()
{
component.painter = chart.painter;
component.refreshComponent = delegate ()
component.refreshComponent = delegate()
{
var backgroundObj = ChartHelper.AddObject(s_BackgroundObjectName, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
@@ -43,7 +42,7 @@ namespace XCharts.Runtime
var p3 = new Vector3(chart.chartX + chart.chartWidth, chart.chartY);
var p4 = new Vector3(chart.chartX, chart.chartY);
var backgroundColor = chart.theme.GetBackgroundColor(component);
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, backgroundColor);
}
}

View File

@@ -1,5 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -33,11 +31,12 @@ namespace XCharts.Runtime
/// </summary>
End
}
[SerializeField] private bool m_Show = true;
[SerializeField] private AreaOrigin m_Origin;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 0.6f;
[SerializeField][Range(0, 1)] private float m_Opacity = 0.6f;
[SerializeField] private Color32 m_HighlightColor;
[SerializeField] private Color32 m_HighlightToColor;
@@ -111,7 +110,7 @@ namespace XCharts.Runtime
return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -124,7 +123,7 @@ namespace XCharts.Runtime
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
color.a = (byte) (color.a * opacity);
return color;
}
}

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;

View File

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

View File

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

using UnityEngine;
using UnityEngine.UI;
@@ -20,6 +19,7 @@ namespace XCharts.Runtime
/// </summary>
AboveText
}
[SerializeField] private bool m_Show = false;
[SerializeField] private Layer m_Layer;
[SerializeField] private Align m_Align = Align.Left;
@@ -115,4 +115,4 @@ namespace XCharts.Runtime
autoHideWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty;
}
}
}
}

View File

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

using UnityEngine;
using UnityEngine.UI;
@@ -79,4 +78,4 @@ namespace XCharts.Runtime
height = imageStyle.height;
}
}
}
}

View File

@@ -22,7 +22,7 @@ namespace XCharts.Runtime
[SerializeField] private Color32 m_BorderColor;
[SerializeField] private Color32 m_BorderColor0;
[SerializeField] private Color32 m_BorderToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
[SerializeField][Range(0, 1)] private float m_Opacity = 1;
[SerializeField] private string m_ItemMarker;
[SerializeField] private string m_ItemFormatter;
[SerializeField] private string m_NumericFormatter = "";
@@ -237,7 +237,7 @@ namespace XCharts.Runtime
return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -247,7 +247,7 @@ namespace XCharts.Runtime
return m_ToColor;
var color = m_ToColor;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -257,7 +257,7 @@ namespace XCharts.Runtime
return m_Color0;
var color = m_Color0;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -268,7 +268,7 @@ namespace XCharts.Runtime
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -279,7 +279,7 @@ namespace XCharts.Runtime
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -290,7 +290,7 @@ namespace XCharts.Runtime
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -301,7 +301,7 @@ namespace XCharts.Runtime
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -332,7 +332,7 @@ namespace XCharts.Runtime
}
if (m_Opacity != 1)
{
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
}
return color;
}
@@ -347,4 +347,4 @@ namespace XCharts.Runtime
return false;
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
@@ -20,6 +19,7 @@ namespace XCharts.Runtime
/// </summary>
Start
}
[SerializeField] private bool m_Show;
[SerializeField] private Position m_Position;
[SerializeField]

View File

@@ -1,5 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -40,6 +38,7 @@ namespace XCharts.Runtime
DashDotDot,
None,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Solid;
[SerializeField] private Color32 m_Color;
@@ -47,7 +46,7 @@ namespace XCharts.Runtime
[SerializeField] private Color32 m_ToColor2;
[SerializeField] private float m_Width = 0;
[SerializeField] private float m_Length = 0;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
[SerializeField][Range(0, 1)] private float m_Opacity = 1;
/// <summary>
/// Whether show line.
@@ -123,8 +122,7 @@ namespace XCharts.Runtime
}
public LineStyle()
{
}
{ }
public LineStyle(float width)
{
@@ -172,7 +170,7 @@ namespace XCharts.Runtime
return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
return color;
}
@@ -203,7 +201,7 @@ namespace XCharts.Runtime
}
if (m_Opacity != 1)
{
color.a = (byte)(color.a * m_Opacity);
color.a = (byte) (color.a * m_Opacity);
}
return color;
}
@@ -232,7 +230,7 @@ namespace XCharts.Runtime
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
color.a = (byte) (color.a * opacity);
return color;
}
}

View File

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

using System;
using UnityEngine;
#if dUI_TextMeshPro
@@ -126,10 +125,10 @@ namespace XCharts.Runtime
return new Location()
{
align = Align.CenterLeft,
left = 0.03f,
right = 0,
top = 0,
bottom = 0
left = 0.03f,
right = 0,
top = 0,
bottom = 0
};
}
}
@@ -141,10 +140,10 @@ namespace XCharts.Runtime
return new Location()
{
align = Align.CenterRight,
left = 0,
right = 0.03f,
top = 0,
bottom = 0
left = 0,
right = 0.03f,
top = 0,
bottom = 0
};
}
}
@@ -156,10 +155,10 @@ namespace XCharts.Runtime
return new Location()
{
align = Align.TopCenter,
left = 0,
right = 0,
top = 0.03f,
bottom = 0
left = 0,
right = 0,
top = 0.03f,
bottom = 0
};
}
}
@@ -171,10 +170,10 @@ namespace XCharts.Runtime
return new Location()
{
align = Align.BottomCenter,
left = 0,
right = 0,
top = 0,
bottom = 0.03f
left = 0,
right = 0,
top = 0,
bottom = 0.03f
};
}
}
@@ -319,4 +318,4 @@ namespace XCharts.Runtime
UpdateAlign();
}
}
}
}

View File

@@ -1,33 +0,0 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// 数据项的其他基础数据。
/// </summary>
[System.Serializable]
public class SerieDataBaseInfo : ChildComponent, ISerieDataComponent
{
[SerializeField] private bool m_Ignore = false;
[SerializeField] private bool m_Selected;
[SerializeField] private float m_Radius;
/// <summary>
/// 是否忽略数据。当为 true 时,数据不进行绘制。
/// </summary>
public bool ignore
{
get { return m_Ignore; }
set { if (PropertyUtil.SetStruct(ref m_Ignore, value)) SetVerticesDirty(); }
}
/// <summary>
/// 自定义半径。可用在饼图中自定义某个数据项的半径。
/// </summary>
public float radius { get { return m_Radius; } set { m_Radius = value; } }
/// <summary>
/// Whether the data item is selected.
/// |该数据项是否被选中。
/// </summary>
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -174,7 +173,7 @@ namespace XCharts.Runtime
case SymbolSizeType.FromData:
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return (float)data[dataIndex] * m_DataScale;
return (float) data[dataIndex] * m_DataScale;
}
else
{
@@ -183,7 +182,8 @@ namespace XCharts.Runtime
case SymbolSizeType.Function:
if (data != null && sizeFunction != null) return sizeFunction(data);
else return size == 0 ? themeSize : size;
default: return size == 0 ? themeSize : size;
default:
return size == 0 ? themeSize : size;
}
}
@@ -204,7 +204,7 @@ namespace XCharts.Runtime
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return (float)data[dataIndex] * m_SelectedDataScale;
return (float) data[dataIndex] * m_SelectedDataScale;
}
else
{
@@ -218,7 +218,8 @@ namespace XCharts.Runtime
else
return selectedSize == 0 ? themeSelectedSize : selectedSize;
default: return selectedSize == 0 ? themeSelectedSize : selectedSize;
default:
return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
}
@@ -239,4 +240,4 @@ namespace XCharts.Runtime
return (dataIndex - startIndex) % (m_Interval + 1) == 0;
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;

View File

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

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -179,11 +178,10 @@ namespace XCharts.Runtime
/// |带有涟漪特效动画的散点图的动画参数。
/// </summary>
public List<float> animationSize { get { return m_AnimationSize; } }
public Color32 GetColor(Color32 defaultColor)
{
return ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
using UnityEngine.UI;
@@ -87,7 +86,6 @@ namespace XCharts.Runtime
m_RelatedTextWidth = labelWidth;
}
public string GetLimitContent(string content)
{
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
@@ -123,9 +121,9 @@ namespace XCharts.Runtime
int middle = content.Length / 2;
int end = content.Length;
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
float limit = checkWidth - m_Gap * 2 - suffixLen;
if (limit < 0)
if (limit < 0)
return 0;
float len = 0;

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
@@ -26,7 +25,7 @@ namespace XCharts.Runtime
public void SetPadding(float top, float right, float bottom, float left)
{
m_Top = top; ;
m_Top = top;;
m_Right = right;
m_Bottom = bottom;
m_Left = left;

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
#if dUI_TextMeshPro
@@ -141,9 +140,7 @@ namespace XCharts.Runtime
}
#endif
public TextStyle()
{
}
public TextStyle() { }
public TextStyle(int fontSize)
{

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 81fe767917cd3492a9f587f5d5e3a037
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// comment of chart.
/// |图表注解组件。
/// </summary>
[Serializable]
[ComponentHandler(typeof(CommentHander), true)]
public class Comment : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private CommentMarkStyle m_MarkStyle;
[SerializeField] private List<CommentItem> m_Items = new List<CommentItem>() { new CommentItem() };
/// <summary>
/// Set this to false to prevent the comment from showing.
/// |是否显示注解组件。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
public List<CommentItem> items { get { return m_Items; } set { m_Items = value; SetComponentDirty(); } }
/// <summary>
/// The text style of all comments.
/// |所有组件的文本样式。
/// </summary>
public LabelStyle labelStyle
{
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// The text style of all comments.
/// |所有组件的文本样式。
/// </summary>
public CommentMarkStyle markStyle
{
get { return m_MarkStyle; }
set { if (PropertyUtil.SetClass(ref m_MarkStyle, value)) SetVerticesDirty(); }
}
public LabelStyle GetLabelStyle(int index)
{
if (index >= 0 && index < items.Count)
{
var labelStyle = items[index].labelStyle;
if (labelStyle.show) return labelStyle;
}
return m_LabelStyle;
}
public CommentMarkStyle GetMarkStyle(int index)
{
if (index >= 0 && index < items.Count)
{
var markStyle = items[index].markStyle;
if (markStyle.show) return markStyle;
}
return m_MarkStyle;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a6d8757fbd847419aaed450e020e827c
guid: ec99dd6b13a3b4e9789d007f23ffa499
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,71 @@
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class CommentHander : MainComponentHandler<Comment>
{
private static readonly string s_CommentObjectName = "comment";
public override void InitComponent()
{
var comment = component;
comment.painter = null;
comment.refreshComponent = delegate()
{
var objName = ChartCached.GetComponentObjectName(comment);
var commentObj = ChartHelper.AddObject(objName,
chart.transform,
chart.chartMinAnchor,
chart.chartMaxAnchor,
chart.chartPivot,
chart.chartSizeDelta);
commentObj.SetActive(comment.show);
commentObj.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(commentObj);
for (int i = 0; i < comment.items.Count; i++)
{
var item = comment.items[i];
var labelStyle = comment.GetLabelStyle(i);
var label = ChartHelper.AddChartLabel(s_CommentObjectName + i, commentObj.transform, labelStyle, chart.theme.common,
GetContent(item), Color.clear, TextAnchor.MiddleCenter);
label.SetActive(comment.show && item.show);
label.SetPosition(item.position + labelStyle.offset);
}
};
comment.refreshComponent();
}
private string GetContent(CommentItem item)
{
if (item.content.IndexOf("{") >= 0)
{
var content = item.content;
FormatterHelper.ReplaceContent(ref content, 0, item.labelStyle.numericFormatter, null, chart);
return content;
}
else
{
return item.content;
}
}
public override void DrawTop(VertexHelper vh)
{
for (int i = 0; i < component.items.Count; i++)
{
var item = component.items[i];
var markStyle = component.GetMarkStyle(i);
if (!markStyle.show) continue;
var color = ChartHelper.IsClearColor(markStyle.lineStyle.color) ?
chart.theme.axis.splitLineColor :
markStyle.lineStyle.color;
var width = markStyle.lineStyle.width == 0 ? 1 : markStyle.lineStyle.width;
UGL.DrawBorder(vh, item.markRect, width, color);
}
}
}
}

View File

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

View File

@@ -0,0 +1,47 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// comment of chart.
/// |注解项。
/// </summary>
[Serializable]
public class CommentItem : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Content = "comment";
[SerializeField] private Vector3 m_Position;
[SerializeField] private Rect m_MarkRect;
[SerializeField] private CommentMarkStyle m_MarkStyle = new CommentMarkStyle() { show = false };
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle() { show = false };
/// <summary>
/// Set this to false to prevent this comment item from showing.
/// |是否显示当前注解项。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
/// position of comment.
/// |注解项的位置坐标。
/// </summary>
public Vector3 position { get { return m_Position; } set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetComponentDirty(); } }
/// <summary>
/// content of comment.
/// |注解的文本内容。
/// </summary>
public string content { get { return m_Content; } set { if (PropertyUtil.SetClass(ref m_Content, value)) SetComponentDirty(); } }
public Rect markRect { get { return m_MarkRect; } set { if (PropertyUtil.SetStruct(ref m_MarkRect, value)) SetVerticesDirty(); } }
public CommentMarkStyle markStyle { get { return m_MarkStyle; } set { if (PropertyUtil.SetClass(ref m_MarkStyle, value)) SetVerticesDirty(); } }
/// <summary>
/// The text style of all comments.
/// |注解项的文本样式。
/// </summary>
public LabelStyle labelStyle
{
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
}
}

View File

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

View File

@@ -0,0 +1,23 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// comment of chart.
/// |注解项。
/// </summary>
[Serializable]
public class CommentMarkStyle : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private LineStyle m_LineStyle;
/// <summary>
/// Set this to false to prevent this comment item from showing.
/// |是否显示当前注解项。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } }
public LineStyle lineStyle { get { return m_LineStyle; } set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetVerticesDirty(); } }
}
}

View File

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

View File

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

using System.Collections.Generic;
using UnityEngine;
@@ -57,6 +56,7 @@ namespace XCharts.Runtime
/// </summary>
Percent
}
[SerializeField] private bool m_Enable = true;
[SerializeField] private FilterMode m_FilterMode;
[SerializeField] private List<int> m_XAxisIndexs = new List<int>() { 0 };
@@ -448,11 +448,11 @@ namespace XCharts.Runtime
start = context.y + context.height * m_Start / 100;
end = context.y + context.height * m_End / 100;
return ChartHelper.IsInRect(pos, context.x, context.x + context.width, start, end);
default: return false;
default:
return false;
}
}
public bool IsInSelectedZoom(int totalIndex, int index, bool invert)
{
if (totalIndex <= 0)
@@ -486,7 +486,8 @@ namespace XCharts.Runtime
case Orient.Vertical:
start = context.y + context.height * m_Start / 100;
return ChartHelper.IsInRect(pos, context.x, context.x + context.width, start - 10, start + 10);
default: return false;
default:
return false;
}
}
@@ -507,11 +508,11 @@ namespace XCharts.Runtime
case Orient.Vertical:
end = context.y + context.height * m_End / 100;
return ChartHelper.IsInRect(pos, context.x, context.x + context.width, end - 10, end + 10);
default: return false;
default:
return false;
}
}
public bool IsContainsAxis(Axis axis)
{
if (axis == null)

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
@@ -21,7 +20,7 @@ namespace XCharts.Runtime
{
var dataZoom = component;
dataZoom.painter = chart.m_PainterTop;
dataZoom.refreshComponent = delegate ()
dataZoom.refreshComponent = delegate()
{
var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom + dataZoom.index, chart.transform,
chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
@@ -34,7 +33,7 @@ namespace XCharts.Runtime
startLabel.gameObject.SetActive(true);
var endLabel = ChartHelper.AddChartLabel(s_DefaultDataZoom + "end", dataZoomObject.transform,
dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleLeft);
dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleLeft);
endLabel.gameObject.SetActive(true);
dataZoom.SetStartLabel(startLabel);
@@ -158,8 +157,8 @@ namespace XCharts.Runtime
return;
var dataZoom = component;
if (dataZoom.context.isDrag || dataZoom.context.isStartDrag || dataZoom.context.isEndDrag
|| dataZoom.context.isCoordinateDrag)
if (dataZoom.context.isDrag || dataZoom.context.isStartDrag || dataZoom.context.isEndDrag ||
dataZoom.context.isCoordinateDrag)
{
chart.RefreshChart();
}
@@ -187,8 +186,8 @@ namespace XCharts.Runtime
return;
}
if (dataZoom.IsInZoom(localPos)
&& !dataZoom.IsInSelectedZoom(localPos))
if (dataZoom.IsInZoom(localPos) &&
!dataZoom.IsInSelectedZoom(localPos))
{
var pointerX = localPos.x;
var selectWidth = grid.context.width * (dataZoom.end - dataZoom.start) / 100;
@@ -313,8 +312,8 @@ namespace XCharts.Runtime
{
var grid = chart.GetGridOfDataZoom(dataZoom);
var deltaPercent = dataZoom.orient == Orient.Horizonal ?
Mathf.Abs(delta / grid.context.width * 100) :
Mathf.Abs(delta / grid.context.height * 100);
Mathf.Abs(delta / grid.context.width * 100) :
Mathf.Abs(delta / grid.context.height * 100);
if (delta > 0)
{
if (dataZoom.end <= dataZoom.start)
@@ -390,9 +389,9 @@ namespace XCharts.Runtime
dataZoom.SetLabelActive(false);
return;
}
if (dataZoom.IsInSelectedZoom(local)
|| dataZoom.IsInStartZoom(local)
|| dataZoom.IsInEndZoom(local))
if (dataZoom.IsInSelectedZoom(local) ||
dataZoom.IsInStartZoom(local) ||
dataZoom.IsInEndZoom(local))
{
dataZoom.SetLabelActive(true);
RefreshDataZoomLabel();
@@ -406,8 +405,8 @@ namespace XCharts.Runtime
{
m_CheckDataZoomLabel = false;
var xAxis = chart.GetChartComponent<XAxis>(dataZoom.xAxisIndexs[0]);
var startIndex = (int)((xAxis.data.Count - 1) * dataZoom.start / 100);
var endIndex = (int)((xAxis.data.Count - 1) * dataZoom.end / 100);
var startIndex = (int) ((xAxis.data.Count - 1) * dataZoom.start / 100);
var endIndex = (int) ((xAxis.data.Count - 1) * dataZoom.end / 100);
if (m_DataZoomLastStartIndex != startIndex || m_DataZoomLastEndIndex != endIndex)
{
@@ -472,7 +471,7 @@ namespace XCharts.Runtime
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
var maxCount = showData.Count;
if (sampleDist > 0)
rate = (int)((maxCount - serie.minShow) / (dataZoom.context.width / sampleDist));
rate = (int) ((maxCount - serie.minShow) / (dataZoom.context.width / sampleDist));
if (rate < 1)
rate = 1;
@@ -485,7 +484,7 @@ namespace XCharts.Runtime
double value = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
float pX = dataZoom.context.x + i * scaleWid;
float dataHig = (float)((maxValue - minValue) == 0 ? 0 :
float dataHig = (float) ((maxValue - minValue) == 0 ? 0 :
(value - minValue) / (maxValue - minValue) * dataZoom.context.height);
np = new Vector3(pX, chart.chartY + dataZoom.bottom + dataHig);
if (i > 0)
@@ -561,7 +560,7 @@ namespace XCharts.Runtime
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
var maxCount = showData.Count;
if (sampleDist > 0)
rate = (int)((maxCount - serie.minShow) / (dataZoom.context.height / sampleDist));
rate = (int) ((maxCount - serie.minShow) / (dataZoom.context.height / sampleDist));
if (rate < 1)
rate = 1;
@@ -575,7 +574,7 @@ namespace XCharts.Runtime
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
float pY = dataZoom.context.y + i * scaleWid;
float dataHig = (maxValue - minValue) == 0 ? 0 :
(float)((value - minValue) / (maxValue - minValue) * dataZoom.context.width);
(float) ((value - minValue) / (maxValue - minValue) * dataZoom.context.width);
np = new Vector3(chart.chartX + chart.chartWidth - dataZoom.right - dataHig, pY);
if (i > 0)
{

View File

@@ -1,4 +1,3 @@
namespace XCharts.Runtime
{
public static class DataZoomHelper

View File

@@ -1,8 +1,7 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace XCharts.Runtime
{
@@ -20,12 +19,12 @@ namespace XCharts.Runtime
{
background = new ImageStyle()
{
color = new Color32(32, 32, 32, 170)
color = new Color32(32, 32, 32, 170)
},
textStyle = new TextStyle()
{
fontSize = 18,
color = Color.white
fontSize = 18,
color = Color.white
}
};
@@ -56,7 +55,7 @@ namespace XCharts.Runtime
public void Update()
{
if (clickChartCount >= 2)
if (clickChartCount > 2)
{
m_ShowDebugInfo = !m_ShowDebugInfo;
ChartHelper.SetActive(m_Label.transform, m_ShowDebugInfo);
@@ -108,6 +107,13 @@ namespace XCharts.Runtime
SetValueWithKInfo(s_Sb, "s-vert", vertCount);
SetValueWithKInfo(s_Sb, "t-vert", m_Chart.m_TopPainterVertCount, false);
var serie0 = m_Chart.GetSerie(0);
for (int i = 0; i < serie0.dataCount; i++)
{
var serieData = serie0.data[i];
s_Sb.AppendFormat("{0}:{1}\n", i, serieData.interact.targetVaue);
}
m_Label.SetText(s_Sb.ToString());
}
}
@@ -144,7 +150,7 @@ namespace XCharts.Runtime
ChartHelper.SetActive(labelGameObject, m_ShowDebugInfo);
var label = ChartHelper.AddChartLabel("info", labelGameObject.transform, labelStyle, theme.common,
"", Color.clear, TextAnchor.UpperLeft);
"", Color.clear, TextAnchor.UpperLeft);
label.SetActive(labelStyle.show);
return label;
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4cd4074bb11fc40059363dd78b9ee98d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// 高亮的图形样式
/// </summary>
[System.Serializable]
public class EmphasisItemStyle : ItemStyle, ISerieExtraComponent, ISerieDataComponent
{ }
}

View File

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

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// 高亮的标签引导线样式
/// </summary>
[System.Serializable]
public class EmphasisLabelLine : LabelLine, ISerieExtraComponent, ISerieDataComponent
{ }
}

View File

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

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// 高亮的标签样式
/// </summary>
[System.Serializable]
public class EmphasisLabelStyle : LabelStyle, ISerieExtraComponent, ISerieDataComponent
{ }
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8445ec442e5314aa891cbbd6d4d966c4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ad378dd158b5d438a87405d35a3a6546
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;

View File

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

using System;
using UnityEngine;
@@ -143,4 +142,4 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_EndSymbol, value)) SetVerticesDirty(); }
}
}
}
}

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
namespace XCharts.Runtime
{
@@ -117,18 +117,19 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// 标签内容字符串模版格式器。支持用 \n 换行。
/// formatter of label.
/// |标签内容字符串模版格式器。支持用 \n 换行。
/// 模板变量有:
/// <list type="bullet">
/// <item><description>{a}:系列名。</description></item>
/// <item><description>{b}:数据名。</description></item>
/// <item><description>{c}:数据值。</description></item>
/// <item><description>{d}:百分比。</description></item>
/// </list>
/// </summary>
/// <example>
/// {.}:圆点标记。
/// {a}:系列名。
/// {a}:系列名。
/// {b}:类目值或数据名。
/// {c}:数据值。
/// {d}:百分比。
/// {e}:数据名。
/// {f}:数据和。
/// 示例:“{b}:{c}”
/// </example>
/// </summary>
public string formatter
{
get { return m_Formatter; }
@@ -315,4 +316,4 @@ namespace XCharts.Runtime
m_TextStyle.Copy(label.m_TextStyle);
}
}
}
}

View File

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

using System.Collections.Generic;
using UnityEngine;
@@ -63,7 +62,8 @@ namespace XCharts.Runtime
/// 无法选择。
/// </summary>
None
};
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_IconType = Type.Auto;
[SerializeField] private SelectedMode m_SelectedMode = SelectedMode.Multiple;
@@ -73,11 +73,13 @@ namespace XCharts.Runtime
[SerializeField] private float m_ItemHeight = 12.0f;
[SerializeField] private float m_ItemGap = 10f;
[SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private bool m_TextAutoColor = false;
[SerializeField] private float m_ItemOpacity = 1;
[SerializeField] private string m_Formatter;
[SerializeField] protected string m_NumericFormatter = "";
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private List<string> m_Data = new List<string>();
[SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
[SerializeField] private List<Color> m_Colors = new List<Color>();
public LegendContext context = new LegendContext();
@@ -171,19 +173,30 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether the legend text matches the color automatically.
/// |图例标记的文本是否自动匹配颜色
/// [default:false]
/// the opacity of item color.
/// |图例标记的图形的颜色透明度
/// </summary>
public bool textAutoColor
public float itemOpacity
{
get { return m_TextAutoColor; }
set { if (PropertyUtil.SetStruct(ref m_TextAutoColor, value)) SetComponentDirty(); }
get { return m_ItemOpacity; }
set { if (PropertyUtil.SetStruct(ref m_ItemOpacity, value)) SetComponentDirty(); }
}
/// <summary>
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{name}.
/// Standard numeric format strings.
/// |标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式A是格式说明符的单字符支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明从0-99。
/// 参考https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{value}.
/// |图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {name}。
/// 模板变量为图例名称 {value}。
/// [default:null]
/// </summary>
public string formatter
@@ -220,6 +233,11 @@ namespace XCharts.Runtime
get { return m_Icons; }
set { if (value != null) { m_Icons = value; SetComponentDirty(); } }
}
public List<Color> colors
{
get { return m_Colors; }
set { if (value != null) { m_Colors = value; SetAllDirty(); } }
}
/// <summary>
/// 图表是否需要刷新(图例组件不需要刷新图表)
/// </summary>
@@ -384,6 +402,14 @@ namespace XCharts.Runtime
}
}
public Color GetColor(int index)
{
if (index >= 0 && index < m_Colors.Count)
return m_Colors[index];
else
return Color.white;
}
/// <summary>
/// Callback handling when parameters change.
/// |参数变更时的回调处理。
@@ -392,23 +418,5 @@ namespace XCharts.Runtime
{
m_Location.OnChanged();
}
/// <summary>
/// 获得图例格式化后的显示内容。
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
public string GetFormatterContent(string category)
{
if (string.IsNullOrEmpty(m_Formatter))
return category;
else
{
var content = m_Formatter.Replace("{name}", category);
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
}
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
@@ -40,14 +39,20 @@ namespace XCharts.Runtime
DrawLegend(vh);
}
public override void OnSerieDataUpdate(int serieIndex)
{
if (FormatterHelper.NeedFormat(component.formatter))
component.refreshComponent();
}
private void InitLegend(Legend legend)
{
legend.painter = null;
legend.refreshComponent = delegate ()
legend.refreshComponent = delegate()
{
legend.OnChanged();
var legendObject = ChartHelper.AddObject(s_LegendObjectName + legend.index, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
legend.gameObject = legendObject;
legendObject.hideFlags = chart.chartHideFlags;
SeriesHelper.UpdateSerieNameList(chart, ref chart.m_LegendRealShowName);
@@ -77,10 +82,11 @@ namespace XCharts.Runtime
for (int i = 0; i < datas.Count; i++)
{
if (!SeriesHelper.IsLegalLegendName(datas[i])) continue;
string legendName = legend.GetFormatterContent(datas[i]);
string legendName = GetFormatterContent(legend, i, datas[i]);
var readIndex = chart.m_LegendRealShowName.IndexOf(datas[i]);
var active = chart.IsActiveByLegend(datas[i]);
var bgColor = LegendHelper.GetIconColor(chart, legend, readIndex, datas[i], active);
bgColor.a = legend.itemOpacity;
var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, chart.theme,
legendName, bgColor, active, readIndex);
legend.SetButton(legendName, item, totalLegend);
@@ -136,6 +142,20 @@ namespace XCharts.Runtime
legend.refreshComponent();
}
private string GetFormatterContent(Legend legend, int dataIndex, string category)
{
if (string.IsNullOrEmpty(legend.formatter))
return category;
else
{
var content = legend.formatter.Replace("{name}", category);
content = content.Replace("{value}", category);
var serie = chart.GetSerie(0);
FormatterHelper.ReplaceContent(ref content, dataIndex, legend.numericFormatter, serie, chart);
return content;
}
}
private void OnLegendButtonClick(Legend legend, int index, string legendName, bool show)
{
chart.OnLegendButtonClick(index, legendName, show);

View File

@@ -11,7 +11,7 @@ namespace XCharts.Runtime
var textStyle = legend.labelStyle.textStyle;
if (active)
{
if (legend.textAutoColor) return theme.GetColor(legendIndex);
if (legend.labelStyle.textStyle.autoColor) return theme.GetColor(legendIndex);
else return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
}
else return theme.legend.unableColor;
@@ -21,12 +21,12 @@ namespace XCharts.Runtime
{
if (active)
{
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
if (legend.itemAutoColor)
{
return SeriesHelper.GetNameColor(chart, readIndex, legendName);
}
else
return Color.white;
return legend.GetColor(readIndex);
}
else return chart.theme.legend.unableColor;
}
@@ -54,7 +54,7 @@ namespace XCharts.Runtime
ChartHelper.GetOrAddComponent<Image>(iconObj);
var label = ChartHelper.AddChartLabel("content", btnObj.transform, legend.labelStyle, theme.legend,
content, contentColor, TextAnchor.MiddleLeft);
content, contentColor, TextAnchor.MiddleLeft);
label.SetActive(true);
var item = new LegendItem();

View File

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

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -41,7 +40,7 @@ namespace XCharts.Runtime
private void InitMarkArea(MarkArea markArea)
{
markArea.painter = chart.m_PainterTop;
markArea.refreshComponent = delegate ()
markArea.refreshComponent = delegate()
{
var label = ChartHelper.AddChartLabel("label", m_MarkLineLabelRoot.transform, markArea.label, chart.theme.axis,
component.text, Color.clear, TextAnchor.MiddleCenter);

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
@@ -28,7 +27,6 @@ namespace XCharts.Runtime
Median
}
/// <summary>
/// Use a line in the chart to illustrate.
/// |图表标线。
@@ -86,11 +84,13 @@ namespace XCharts.Runtime
item.name = "average";
item.type = MarkLineType.Average;
item.lineStyle.type = LineStyle.Type.Dashed;
item.lineStyle.color = Color.blue;
item.lineStyle.color = Color.clear;
item.startSymbol.show = true;
item.startSymbol.type = SymbolType.Circle;
item.startSymbol.size = 4;
item.endSymbol.show = true;
item.endSymbol.type = SymbolType.Arrow;
item.endSymbol.size = 5;
item.label.show = true;
item.label.numericFormatter = "f1";
item.label.formatter = "{c}";

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -36,6 +35,7 @@ namespace XCharts.Runtime
{
if (data.runtimeLabel != null)
{
data.runtimeLabel.SetActive(data.label.show);
data.runtimeLabel.SetPosition(MarkLineHelper.GetLabelPosition(data));
data.runtimeLabel.SetText(MarkLineHelper.GetFormatterContent(serie, data));
}
@@ -70,13 +70,12 @@ namespace XCharts.Runtime
private void InitMarkLineLabel(Serie serie, MarkLineData data, Color serieColor)
{
data.painter = chart.m_PainterTop;
data.refreshComponent = delegate ()
data.refreshComponent = delegate()
{
var textName = string.Format("markLine_{0}_{1}", serie.index, data.index);
var content = MarkLineHelper.GetFormatterContent(serie, data);
var label = ChartHelper.AddChartLabel(textName, m_MarkLineLabelRoot.transform, data.label, chart.theme.axis,
content, Color.clear, TextAnchor.MiddleCenter);
label.SetActive(data.label.show);
label.SetIconActive(false);
label.SetActive(data.label.show);
@@ -203,7 +202,8 @@ namespace XCharts.Runtime
for (int i = 0; i < markLine.data.Count; i++)
{
var data = markLine.data[i];
data.index = i;
// data.index = i;
data.index = markLine.index;
if (data.group == 0) continue;
if (!m_TempGroupData.ContainsKey(data.group))
{

View File

@@ -1,4 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -18,7 +17,7 @@ namespace XCharts.Runtime
else
{
var content = serieLabel.formatter;
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, data.runtimeValue,
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, data.runtimeValue,
0, serie.serieName, data.name, data.name, Color.clear);
return content;
}

View File

@@ -1,6 +1,5 @@

using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
@@ -91,6 +90,7 @@ namespace XCharts.Runtime
return true;
}
}
[SerializeField] private bool m_Show;
[SerializeField] private Shape m_Shape;
[SerializeField] private float m_Radius = 100;
@@ -281,12 +281,13 @@ namespace XCharts.Runtime
m_Radius = 0.35f;
m_SplitNumber = 5;
m_Indicator = true;
m_IndicatorList = new List<Indicator>(5){
new Indicator(){name="indicator1",max = 0},
new Indicator(){name="indicator2",max = 0},
new Indicator(){name="indicator3",max = 0},
new Indicator(){name="indicator4",max = 0},
new Indicator(){name="indicator5",max = 0},
m_IndicatorList = new List<Indicator>(5)
{
new Indicator() { name = "indicator1", max = 0 },
new Indicator() { name = "indicator2", max = 0 },
new Indicator() { name = "indicator3", max = 0 },
new Indicator() { name = "indicator4", max = 0 },
new Indicator() { name = "indicator5", max = 0 },
};
center[0] = 0.5f;
center[1] = 0.4f;

View File

@@ -1,6 +1,5 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime

View File

@@ -1,6 +1,5 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XUGL;
@@ -24,8 +23,8 @@ namespace XCharts.Runtime
return;
}
var radar = component;
radar.context.isPointerEnter = radar.show
&& Vector3.Distance(radar.context.center, chart.pointerPos) <= radar.context.radius;
radar.context.isPointerEnter = radar.show &&
Vector3.Distance(radar.context.center, chart.pointerPos) <= radar.context.radius;
}
public override void DrawBase(VertexHelper vh)
@@ -37,11 +36,11 @@ namespace XCharts.Runtime
{
float txtHig = 20;
radar.painter = chart.GetPainter(radar.index);
radar.refreshComponent = delegate ()
radar.refreshComponent = delegate()
{
radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight);
var radarObject = ChartHelper.AddObject("Radar" + radar.index, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
radar.gameObject = radarObject;
radar.gameObject.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(radarObject.transform, INDICATOR_TEXT);
@@ -52,7 +51,7 @@ namespace XCharts.Runtime
var objName = INDICATOR_TEXT + "_" + i;
var label = ChartHelper.AddChartLabel(objName, radarObject.transform, radar.axisName.labelStyle,
chart.theme.common, radar.GetFormatterIndicatorContent(i), Color.clear, TextAnchor.MiddleCenter);
chart.theme.common, radar.GetFormatterIndicatorContent(i), Color.clear, TextAnchor.MiddleCenter);
label.SetActive(radar.indicator && radar.axisName.labelStyle.show);
AxisHelper.AdjustCircleLabelPos(label, pos, radar.context.center, txtHig, radar.axisName.labelStyle.offset);
}
@@ -95,7 +94,7 @@ namespace XCharts.Runtime
if (radar.splitArea.show)
{
UGL.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear,
0, 360, chart.settings.cicleSmoothness);
0, 360, chart.settings.cicleSmoothness);
}
if (radar.splitLine.show)
{

View File

@@ -1,6 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;
namespace XCharts.Runtime
{
@@ -12,15 +11,15 @@ namespace XCharts.Runtime
public class Settings : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] [Range(1, 20)] protected int m_MaxPainter = 10;
[SerializeField][Range(1, 20)] protected int m_MaxPainter = 10;
[SerializeField] protected bool m_ReversePainter = false;
[SerializeField] protected Material m_BasePainterMaterial;
[SerializeField] protected Material m_SeriePainterMaterial;
[SerializeField] protected Material m_TopPainterMaterial;
[SerializeField] [Range(1, 10)] protected float m_LineSmoothStyle = 3f;
[SerializeField] [Range(1f, 20)] protected float m_LineSmoothness = 2f;
[SerializeField] [Range(0.5f, 20)] protected float m_LineSegmentDistance = 3f;
[SerializeField] [Range(1, 10)] protected float m_CicleSmoothness = 2f;
[SerializeField][Range(1, 10)] protected float m_LineSmoothStyle = 3f;
[SerializeField][Range(1f, 20)] protected float m_LineSmoothness = 2f;
[SerializeField][Range(0.5f, 20)] protected float m_LineSegmentDistance = 3f;
[SerializeField][Range(1, 10)] protected float m_CicleSmoothness = 2f;
[SerializeField] protected float m_LegendIconLineWidth = 2;
[SerializeField] private float[] m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f };
@@ -156,13 +155,13 @@ namespace XCharts.Runtime
return new Settings()
{
m_ReversePainter = false,
m_MaxPainter = XCSettings.maxPainter,
m_LineSmoothStyle = XCSettings.lineSmoothStyle,
m_LineSmoothness = XCSettings.lineSmoothness,
m_LineSegmentDistance = XCSettings.lineSegmentDistance,
m_CicleSmoothness = XCSettings.cicleSmoothness,
m_LegendIconLineWidth = 2,
m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f }
m_MaxPainter = XCSettings.maxPainter,
m_LineSmoothStyle = XCSettings.lineSmoothStyle,
m_LineSmoothness = XCSettings.lineSmoothness,
m_LineSegmentDistance = XCSettings.lineSegmentDistance,
m_CicleSmoothness = XCSettings.cicleSmoothness,
m_LegendIconLineWidth = 2,
m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f }
};
}
}

View File

@@ -1,6 +1,5 @@

using UnityEngine;
using System;
using UnityEngine;
namespace XCharts.Runtime
{
@@ -83,10 +82,10 @@ namespace XCharts.Runtime
{
get
{
return m_ComponentDirty
|| location.componentDirty
|| m_LabelStyle.componentDirty
|| m_SubLabelStyle.componentDirty;
return m_ComponentDirty ||
location.componentDirty ||
m_LabelStyle.componentDirty ||
m_SubLabelStyle.componentDirty;
}
}

View File

@@ -1,4 +1,3 @@
using UnityEngine;
namespace XCharts.Runtime
@@ -8,12 +7,14 @@ namespace XCharts.Runtime
{
private static readonly string s_TitleObjectName = "title";
private static readonly string s_SubTitleObjectName = "title_sub";
private ChartLabel m_LabelObject;
private ChartLabel m_SubLabelObject;
public override void InitComponent()
{
var title = component;
title.painter = null;
title.refreshComponent = delegate ()
title.refreshComponent = delegate()
{
title.OnChanged();
var anchorMin = title.location.runtimeAnchorMin;
@@ -36,16 +37,52 @@ namespace XCharts.Runtime
titleObject.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(titleObject);
var label = ChartHelper.AddChartLabel(s_TitleObjectName, titleObject.transform, title.labelStyle, chart.theme.title,
title.text, Color.clear, title.location.runtimeTextAlignment);
label.SetActive(title.show && title.labelStyle.show);
m_LabelObject = ChartHelper.AddChartLabel(s_TitleObjectName, titleObject.transform, title.labelStyle, chart.theme.title,
GetTitleText(title), Color.clear, title.location.runtimeTextAlignment);
m_LabelObject.SetActive(title.show && title.labelStyle.show);
var subLabel = ChartHelper.AddChartLabel(s_SubTitleObjectName, titleObject.transform, title.subLabelStyle, chart.theme.subTitle,
title.subText, Color.clear, title.location.runtimeTextAlignment);
subLabel.SetActive(title.show && title.subLabelStyle.show);
subLabel.transform.localPosition = subTitlePosition + title.subLabelStyle.offset;
m_SubLabelObject = ChartHelper.AddChartLabel(s_SubTitleObjectName, titleObject.transform, title.subLabelStyle, chart.theme.subTitle,
GetSubTitleText(title), Color.clear, title.location.runtimeTextAlignment);
m_SubLabelObject.SetActive(title.show && title.subLabelStyle.show);
m_SubLabelObject.transform.localPosition = subTitlePosition + title.subLabelStyle.offset;
};
title.refreshComponent();
}
public override void OnSerieDataUpdate(int serieIndex)
{
if (m_LabelObject != null && FormatterHelper.NeedFormat(component.text))
m_LabelObject.SetText(GetTitleText(component));
if (m_SubLabelObject != null && FormatterHelper.NeedFormat(component.subText))
m_SubLabelObject.SetText(GetSubTitleText(component));
}
private string GetTitleText(Title title)
{
if (FormatterHelper.NeedFormat(title.text))
{
var content = title.text;
FormatterHelper.ReplaceContent(ref content, 0, title.labelStyle.numericFormatter, null, chart);
return content;
}
else
{
return title.text;
}
}
private string GetSubTitleText(Title title)
{
if (FormatterHelper.NeedFormat(title.subText))
{
var content = title.subText;
FormatterHelper.ReplaceContent(ref content, 0, title.subLabelStyle.numericFormatter, null, chart);
return content;
}
else
{
return title.subText;
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
@@ -11,6 +10,6 @@ namespace XCharts.Runtime
[Serializable]
public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieExtraComponent
{
}
}

View File

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

using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -101,9 +100,9 @@ namespace XCharts.Runtime
[SerializeField]
private List<LabelStyle> m_ContentLabelStyles = new List<LabelStyle>()
{
new LabelStyle(){ textPadding = new TextPadding(0,5,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }},
new LabelStyle(){ textPadding = new TextPadding(0,20,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }},
new LabelStyle(){ textPadding = new TextPadding(0,0,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleRight }}
new LabelStyle() { textPadding = new TextPadding(0, 5, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft } },
new LabelStyle() { textPadding = new TextPadding(0, 20, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft } },
new LabelStyle() { textPadding = new TextPadding(0, 0, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleRight } }
};
public TooltipContext context = new TooltipContext();
@@ -146,6 +145,7 @@ namespace XCharts.Runtime
/// {c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.</br>
/// {d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.</br>
/// {e} is the name of the data item serieData that is currently indicated or whose index is 0.</br>
/// {f} is sum of data.</br>
/// {.1} represents a dot from serie corresponding color that specifies index as 1.</br>
/// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.</br>
/// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).</br>
@@ -161,6 +161,7 @@ namespace XCharts.Runtime
/// {c}为当前所指示或index为0的serie的y维dimesion为1的数值。</br>
/// {d}为当前所指示或index为0的serie的y维dimesion为1百分比值注意不带%号。</br>
/// {e}为当前所指示或index为0的serie的数据项serieData的name。</br>
/// {f}为数据总和。</br>
/// {.1}表示指定index为1的serie对应颜色的圆点。</br>
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。</br>
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据一个数据项有多个数据index为2表示第3个数据。</br>
@@ -372,7 +373,7 @@ namespace XCharts.Runtime
/// |当前提示框所指示的数据项索引。
/// </summary>
public List<int> runtimeDataIndex { get { return m_RuntimeDateIndex; } internal set { m_RuntimeDateIndex = value; } }
private List<int> m_RuntimeDateIndex = new List<int>() { -1, -1 };
private List<int> m_RuntimeDateIndex = new List<int>() {-1, -1 };
/// <summary>
/// Keep Tooltiop displayed at the top.

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -35,7 +34,7 @@ namespace XCharts.Runtime
private void InitTooltip(Tooltip tooltip)
{
tooltip.painter = chart.m_PainterTop;
tooltip.refreshComponent = delegate ()
tooltip.refreshComponent = delegate()
{
var objName = ChartCached.GetComponentObjectName(tooltip);
tooltip.gameObject = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
@@ -186,7 +185,7 @@ namespace XCharts.Runtime
label.SetTextActive(true);
label.SetPosition(axis.context.pointerLabelPosition);
if (axis.IsCategory())
label.SetText(axis.GetData((int)axis.context.pointerValue));
label.SetText(axis.GetData((int) axis.context.pointerValue));
else
label.SetText(axis.context.pointerValue.ToString("f2"));
var textColor = axis.axisLabel.textStyle.GetColor(chart.theme.axis.textColor);
@@ -210,8 +209,8 @@ namespace XCharts.Runtime
{
foreach (var serie in chart.series)
{
if (serie is INeedSerieContainer
&& (serie as INeedSerieContainer).containterInstanceId == component.instanceId)
if (serie is INeedSerieContainer &&
(serie as INeedSerieContainer).containterInstanceId == component.instanceId)
{
var isTriggerAxis = tooltip.IsTriggerAxis();
if (container is GridCoord)
@@ -224,7 +223,7 @@ namespace XCharts.Runtime
else if (container is PolarCoord)
{
var m_AngleAxis = ComponentHelper.GetAngleAxis(chart.components, container.index);
tooltip.context.angle = (float)m_AngleAxis.context.pointerValue;
tooltip.context.angle = (float) m_AngleAxis.context.pointerValue;
}
list.Add(serie);
if (!isTriggerAxis)
@@ -243,7 +242,7 @@ namespace XCharts.Runtime
serie.context.pointerAxisDataIndexs.Clear();
if (yAxis.IsCategory())
{
serie.context.pointerAxisDataIndexs.Add((int)yAxis.context.pointerValue);
serie.context.pointerAxisDataIndexs.Add((int) yAxis.context.pointerValue);
yAxis.context.axisTooltipValue = yAxis.context.pointerValue;
}
else if (yAxis.IsTime())
@@ -255,7 +254,7 @@ namespace XCharts.Runtime
}
else if (xAxis.IsCategory())
{
serie.context.pointerAxisDataIndexs.Add((int)xAxis.context.pointerValue);
serie.context.pointerAxisDataIndexs.Add((int) xAxis.context.pointerValue);
xAxis.context.axisTooltipValue = xAxis.context.pointerValue;
}
else
@@ -286,7 +285,7 @@ namespace XCharts.Runtime
serieData.index = i;
serie.context.sortedData.Add(serieData);
}
serie.context.sortedData.Sort(delegate (SerieData a, SerieData b)
serie.context.sortedData.Sort(delegate(SerieData a, SerieData b)
{
return a.GetData(dimension).CompareTo(b.GetData(dimension));
});
@@ -437,7 +436,7 @@ namespace XCharts.Runtime
var axis = component as Axis;
if (axis.gridIndex == gridIndex && axis.IsCategory())
{
dataIndex = (int)axis.context.pointerValue;
dataIndex = (int) axis.context.pointerValue;
category = axis.GetData(dataIndex);
return true;
}
@@ -494,25 +493,25 @@ namespace XCharts.Runtime
case Tooltip.Type.Corss:
case Tooltip.Type.Line:
float pX = grid.context.x;
pX += xAxis.IsCategory()
? (float)(xAxis.context.pointerValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0))
: xAxis.GetDistance(xAxis.context.axisTooltipValue, grid.context.width);
pX += xAxis.IsCategory() ?
(float) (xAxis.context.pointerValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0)) :
xAxis.GetDistance(xAxis.context.axisTooltipValue, grid.context.width);
Vector2 sp = new Vector2(pX, grid.context.y);
Vector2 ep = new Vector2(pX, grid.context.y + grid.context.height);
var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme);
if (xAxis.IsCategory() && tooltip.type == Tooltip.Type.Corss)
{
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
pX = (float)(grid.context.x + splitWidth * xAxis.context.pointerValue -
(xAxis.boundaryGap ? 0 : splitWidth / 2));
float pY = grid.context.y + grid.context.height;
Vector3 p1 = new Vector3(pX, grid.context.y);
Vector3 p2 = new Vector3(pX, pY);
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
Vector3 p4 = new Vector3(pX + tooltipSplitWid, grid.context.y);
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, chart.theme.tooltip.areaColor);
}
else
// if (xAxis.IsCategory() && tooltip.type == Tooltip.Type.Corss)
// {
// float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
// pX = (float)(grid.context.x + splitWidth * xAxis.context.pointerValue -
// (xAxis.boundaryGap ? 0 : splitWidth / 2));
// float pY = grid.context.y + grid.context.height;
// Vector3 p1 = new Vector3(pX, grid.context.y);
// Vector3 p2 = new Vector3(pX, pY);
// Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
// Vector3 p4 = new Vector3(pX + tooltipSplitWid, grid.context.y);
// UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, chart.theme.tooltip.areaColor);
// }
// else
{
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
}
@@ -527,7 +526,7 @@ namespace XCharts.Runtime
if (xAxis.IsCategory())
{
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
pX = (float)(grid.context.x + splitWidth * xAxis.context.pointerValue -
pX = (float) (grid.context.x + splitWidth * xAxis.context.pointerValue -
(xAxis.boundaryGap ? 0 : splitWidth / 2));
float pY = grid.context.y + grid.context.height;
Vector3 p1 = new Vector3(pX, grid.context.y);
@@ -559,24 +558,24 @@ namespace XCharts.Runtime
{
case Tooltip.Type.Corss:
case Tooltip.Type.Line:
float pY = (float)(grid.context.y + yAxis.context.pointerValue * splitWidth
+ (yAxis.boundaryGap ? splitWidth / 2 : 0));
float pY = (float) (grid.context.y + yAxis.context.pointerValue * splitWidth +
(yAxis.boundaryGap ? splitWidth / 2 : 0));
Vector2 sp = new Vector2(grid.context.x, pY);
Vector2 ep = new Vector2(grid.context.x + grid.context.width, pY);
var lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme);
if (yAxis.IsCategory() && tooltip.type == Tooltip.Type.Corss)
{
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
float pX = grid.context.x + grid.context.width;
pY = (float)(grid.context.y + splitWidth * yAxis.context.pointerValue -
(yAxis.boundaryGap ? 0 : splitWidth / 2));
Vector3 p1 = new Vector3(grid.context.x, pY);
Vector3 p2 = new Vector3(grid.context.x, pY + tooltipSplitWid);
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
Vector3 p4 = new Vector3(pX, pY);
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, chart.theme.tooltip.areaColor);
}
else
// if (yAxis.IsCategory() && tooltip.type == Tooltip.Type.Corss)
// {
// float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
// float pX = grid.context.x + grid.context.width;
// pY = (float)(grid.context.y + splitWidth * yAxis.context.pointerValue -
// (yAxis.boundaryGap ? 0 : splitWidth / 2));
// Vector3 p1 = new Vector3(grid.context.x, pY);
// Vector3 p2 = new Vector3(grid.context.x, pY + tooltipSplitWid);
// Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
// Vector3 p4 = new Vector3(pX, pY);
// UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, chart.theme.tooltip.areaColor);
// }
// else
{
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
}
@@ -592,7 +591,7 @@ namespace XCharts.Runtime
{
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
float pX = grid.context.x + grid.context.width;
pY = (float)(grid.context.y + splitWidth * yAxis.context.pointerValue -
pY = (float) (grid.context.y + splitWidth * yAxis.context.pointerValue -
(yAxis.boundaryGap ? 0 : splitWidth / 2));
Vector3 p1 = new Vector3(grid.context.x, pY);
Vector3 p2 = new Vector3(grid.context.x, pY + tooltipSplitWid);

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
@@ -37,6 +36,7 @@ namespace XCharts.Runtime
var content = param.itemFormatter;
FormatterHelper.ReplaceSerieLabelContent(ref content,
param.numericFormatter,
param.dataCount,
param.value,
param.total,
param.serieName,

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
@@ -115,8 +114,6 @@ namespace XCharts.Runtime
tooltip.gameObject.transform.SetAsLastSibling();
}
private void ResetSize()
{
var maxHig = 0f;
@@ -220,8 +217,8 @@ namespace XCharts.Runtime
view.background = ChartHelper.GetOrAddComponent<Image>(view.gameObject);
view.background.sprite = tooltip.backgroundImage;
view.background.type = tooltip.backgroundType;
view.background.color = ChartHelper.IsClearColor(tooltip.backgroundColor)
? Color.white : tooltip.backgroundColor;
view.background.color = ChartHelper.IsClearColor(tooltip.backgroundColor) ?
Color.white : tooltip.backgroundColor;
view.border = ChartHelper.GetOrAddComponent<Outline>(view.gameObject);
view.border.enabled = tooltip.borderWidth > 0;
@@ -240,7 +237,7 @@ namespace XCharts.Runtime
tooltip.paddingTopBottom);
view.title = ChartHelper.AddChartLabel("title", view.gameObject.transform, tooltip.titleLabelStyle, theme.tooltip,
"", Color.clear, TextAnchor.MiddleLeft);
"", Color.clear, TextAnchor.MiddleLeft);
var item = CreateViewItem(0, view.gameObject.transform, tooltip, theme.tooltip);
view.m_Items.Add(item);
@@ -266,7 +263,7 @@ namespace XCharts.Runtime
{
var labelStyle = tooltip.GetContentLabelStyle(i);
var label = ChartHelper.AddChartLabel("column" + i, parent, labelStyle, theme,
"", Color.clear, TextAnchor.MiddleLeft);
"", Color.clear, TextAnchor.MiddleLeft);
return label;
}
}

View File

@@ -1,11 +1,10 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
[System.Serializable]
public class VisualMapPieces : ChildComponent
public class VisualMapRange : ChildComponent
{
[SerializeField] private double m_Min;
[SerializeField] private double m_Max;
@@ -31,6 +30,7 @@ namespace XCharts.Runtime
public bool Contains(double value, double minMaxRange)
{
if (m_Min == 0 && m_Max == 0) return false;
var cmin = System.Math.Abs(m_Min) < 1 ? minMaxRange * m_Min : m_Min;
var cmax = System.Math.Abs(m_Max) < 1 ? minMaxRange * m_Max : m_Max;
return value >= cmin && value < cmax;
@@ -101,9 +101,8 @@ namespace XCharts.Runtime
[SerializeField] private bool m_WorkOnLine = true;
[SerializeField] private bool m_WorkOnArea = false;
[SerializeField] private List<Color32> m_InRange = new List<Color32>();
[SerializeField] private List<Color32> m_OutOfRange = new List<Color32>() { Color.gray };
[SerializeField] private List<VisualMapPieces> m_Pieces = new List<VisualMapPieces>();
[SerializeField] private List<VisualMapRange> m_OutOfRange = new List<VisualMapRange>() { new VisualMapRange() { color = Color.gray } };
[SerializeField] private List<VisualMapRange> m_InRange = new List<VisualMapRange>();
public VisualMapContext context = new VisualMapContext();
@@ -331,19 +330,10 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_WorkOnArea, value)) SetVerticesDirty(); }
}
/// <summary>
/// Defines the visual color in the selected range.
/// |定义 在选中范围中 的视觉颜色。
/// </summary>
public List<Color32> inRange
{
get { return m_InRange; }
set { if (value != null) { m_InRange = value; SetVerticesDirty(); } }
}
/// <summary>
/// Defines a visual color outside of the selected range.
/// |定义 在选中范围外 的视觉颜色。
/// </summary>
public List<Color32> outOfRange
public List<VisualMapRange> outOfRange
{
get { return m_OutOfRange; }
set { if (value != null) { m_OutOfRange = value; SetVerticesDirty(); } }
@@ -351,10 +341,10 @@ namespace XCharts.Runtime
/// <summary>
/// 分段式每一段的相关配置。
/// </summary>
public List<VisualMapPieces> pieces
public List<VisualMapRange> inRange
{
get { return m_Pieces; }
set { if (value != null) { m_Pieces = value; SetVerticesDirty(); } }
get { return m_InRange; }
set { if (value != null) { m_InRange = value; SetVerticesDirty(); } }
}
public override bool vertsDirty { get { return m_VertsDirty || location.anyDirty; } }
@@ -396,73 +386,84 @@ namespace XCharts.Runtime
}
}
public float runtimeRangeMinHeight { get { return (float)((rangeMin - min) / (max - min) * itemHeight); } }
public float runtimeRangeMaxHeight { get { return (float)((rangeMax - min) / (max - min) * itemHeight); } }
public float runtimeRangeMinHeight { get { return (float) ((rangeMin - min) / (max - min) * itemHeight); } }
public float runtimeRangeMaxHeight { get { return (float) ((rangeMax - min) / (max - min) * itemHeight); } }
public List<Color32> runtimeInRange
public void AddColors(List<Color32> colors)
{
get
m_InRange.Clear();
foreach (var color in colors)
{
if (splitNumber == 0 || m_InRange.Count >= splitNumber || m_InRange.Count < 1 || IsPiecewise())
m_InRange.Add(new VisualMapRange()
{
return m_InRange;
}
else
color = color
});
}
}
public void AddColors(List<string> colors)
{
m_InRange.Clear();
foreach (var str in colors)
{
m_InRange.Add(new VisualMapRange()
{
var count = splitNumber > 0 && splitNumber <= m_InRange.Count
? splitNumber
: m_InRange.Count;
if (context.inRangeColors.Count != count)
{
context.inRangeColors.Clear();
var total = max - min;
var diff1 = total / (m_InRange.Count - 1);
var diff2 = total / splitNumber;
var inCount = 0;
var inValue = min;
var rtValue = min;
for (int i = 0; i < splitNumber; i++)
{
rtValue += diff2;
if (rtValue > inValue + diff1)
{
inValue += diff1;
inCount++;
}
if (i == splitNumber - 1)
{
context.inRangeColors.Add(m_InRange[m_InRange.Count - 1]);
}
else
{
var rate = (float)((rtValue - inValue) / diff1);
context.inRangeColors.Add(Color32.Lerp(m_InRange[inCount], m_InRange[inCount + 1], rate));
}
}
}
return context.inRangeColors;
}
color = ThemeStyle.GetColor(str)
});
}
}
public Color32 GetColor(double value)
{
switch (type)
int index = GetIndex(value);
if (index == -1)
{
case Type.Continuous:
return GetContinuousColor(value);
case Type.Piecewise:
return GetPiecesColor(value);
default:
return ColorUtil.clearColor32;
if (m_OutOfRange.Count > 0)
return m_OutOfRange[0].color;
else
return ChartConst.clearColor32;
}
if (m_Type == VisualMap.Type.Piecewise)
{
return m_InRange[index].color;
}
else
{
int splitNumber = m_InRange.Count;
var diff = (m_Max - m_Min) / (splitNumber - 1);
var nowMin = m_Min + index * diff;
var rate = (value - nowMin) / diff;
if (index == splitNumber - 1)
return m_InRange[index].color;
else
return Color32.Lerp(m_InRange[index].color, m_InRange[index + 1].color, (float) rate);
}
}
private bool IsNeedPieceColor(double value, out int index)
{
bool flag = false;
index = -1;
for (int i = 0; i < m_InRange.Count; i++)
{
var range = m_InRange[i];
if (range.min != 0 || range.max != 0)
{
flag = true;
if (range.Contains(value, max - min))
{
index = i;
return true;
}
}
}
return flag;
}
private Color32 GetPiecesColor(double value)
{
foreach (var piece in m_Pieces)
foreach (var piece in m_InRange)
{
if (piece.Contains(value, max - min))
{
@@ -470,54 +471,25 @@ namespace XCharts.Runtime
}
}
if (m_OutOfRange.Count > 0)
return m_OutOfRange[0];
return m_OutOfRange[0].color;
else
return ChartConst.clearColor32;
}
private Color32 GetContinuousColor(double value)
{
if (value < m_Min || value > m_Max)
{
if (m_OutOfRange.Count > 0)
return m_OutOfRange[0];
else
return ChartConst.clearColor32;
}
int splitNumber = runtimeInRange.Count;
if (splitNumber <= 0)
return ChartConst.clearColor32;
var index = GetIndex(value);
if (m_Type == VisualMap.Type.Piecewise)
{
if (index >= 0 && index < runtimeInRange.Count)
return runtimeInRange[index];
else
return ChartConst.clearColor32;
}
else
{
var diff = (m_Max - m_Min) / (splitNumber - 1);
var nowMin = m_Min + index * diff;
var rate = (value - nowMin) / diff;
if (index == splitNumber - 1)
return runtimeInRange[index];
else
return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], (float)rate);
}
}
public int GetIndex(double value)
{
int splitNumber = runtimeInRange.Count;
int splitNumber = m_InRange.Count;
if (splitNumber <= 0)
return -1;
var index = -1;
if (IsNeedPieceColor(value, out index))
{
return index;
}
value = MathUtil.Clamp(value, m_Min, m_Max);
var diff = (m_Max - m_Min) / (splitNumber - 1);
var index = -1;
for (int i = 0; i < splitNumber; i++)
{
if (value <= m_Min + (i + 1) * diff)
@@ -574,10 +546,10 @@ namespace XCharts.Runtime
var centerPos = new Vector3(chartRect.x, chartRect.y) + location.GetPosition(chartRect.width, chartRect.height);
var diff = calculable ? triangleLen : 0;
if (local.x >= centerPos.x - itemWidth / 2 - diff
&& local.x <= centerPos.x + itemWidth / 2 + diff
&& local.y >= centerPos.y - itemHeight / 2 - diff
&& local.y <= centerPos.y + itemHeight / 2 + diff)
if (local.x >= centerPos.x - itemWidth / 2 - diff &&
local.x <= centerPos.x + itemWidth / 2 + diff &&
local.y >= centerPos.y - itemHeight / 2 - diff &&
local.y <= centerPos.y + itemHeight / 2 + diff)
{
return true;
}
@@ -595,18 +567,18 @@ namespace XCharts.Runtime
{
var pos1 = centerPos + Vector3.down * itemHeight / 2;
return local.x >= centerPos.x - itemWidth / 2
&& local.x <= centerPos.x + itemWidth / 2
&& local.y >= pos1.y + runtimeRangeMinHeight
&& local.y <= pos1.y + runtimeRangeMaxHeight;
return local.x >= centerPos.x - itemWidth / 2 &&
local.x <= centerPos.x + itemWidth / 2 &&
local.y >= pos1.y + runtimeRangeMinHeight &&
local.y <= pos1.y + runtimeRangeMaxHeight;
}
else
{
var pos1 = centerPos + Vector3.left * itemHeight / 2;
return local.x >= pos1.x + runtimeRangeMinHeight
&& local.x <= pos1.x + runtimeRangeMaxHeight
&& local.y >= centerPos.y - itemWidth / 2
&& local.y <= centerPos.y + itemWidth / 2;
return local.x >= pos1.x + runtimeRangeMinHeight &&
local.x <= pos1.x + runtimeRangeMaxHeight &&
local.y >= centerPos.y - itemWidth / 2 &&
local.y <= centerPos.y + itemWidth / 2;
}
}
@@ -620,10 +592,10 @@ namespace XCharts.Runtime
var pos1 = centerPos + Vector3.down * itemHeight / 2;
var cpos = new Vector3(pos1.x + itemWidth / 2 + radius, pos1.y + runtimeRangeMinHeight - radius);
return local.x >= cpos.x - radius
&& local.x <= cpos.x + radius
&& local.y >= cpos.y - radius
&& local.y <= cpos.y + radius;
return local.x >= cpos.x - radius &&
local.x <= cpos.x + radius &&
local.y >= cpos.y - radius &&
local.y <= cpos.y + radius;
}
else
{
@@ -631,10 +603,10 @@ namespace XCharts.Runtime
var pos1 = centerPos + Vector3.left * itemHeight / 2;
var cpos = new Vector3(pos1.x + runtimeRangeMinHeight, pos1.y + itemWidth / 2 + radius);
return local.x >= cpos.x - radius
&& local.x <= cpos.x + radius
&& local.y >= cpos.y - radius
&& local.y <= cpos.y + radius;
return local.x >= cpos.x - radius &&
local.x <= cpos.x + radius &&
local.y >= cpos.y - radius &&
local.y <= cpos.y + radius;
}
}
@@ -648,10 +620,10 @@ namespace XCharts.Runtime
var pos1 = centerPos + Vector3.down * itemHeight / 2;
var cpos = new Vector3(pos1.x + itemWidth / 2 + radius, pos1.y + runtimeRangeMaxHeight + radius);
return local.x >= cpos.x - radius
&& local.x <= cpos.x + radius
&& local.y >= cpos.y - radius
&& local.y <= cpos.y + radius;
return local.x >= cpos.x - radius &&
local.x <= cpos.x + radius &&
local.y >= cpos.y - radius &&
local.y <= cpos.y + radius;
}
else
{
@@ -659,10 +631,10 @@ namespace XCharts.Runtime
var pos1 = centerPos + Vector3.left * itemHeight / 2;
var cpos = new Vector3(pos1.x + runtimeRangeMaxHeight + radius, pos1.y + itemWidth / 2 + radius);
return local.x >= cpos.x - radius
&& local.x <= cpos.x + radius
&& local.y >= cpos.y - radius
&& local.y <= cpos.y + radius;
return local.x >= cpos.x - radius &&
local.x <= cpos.x + radius &&
local.y >= cpos.y - radius &&
local.y <= cpos.y + radius;
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
@@ -15,6 +14,6 @@ namespace XCharts.Runtime
public bool maxDrag { get; internal set; }
internal List<Color32> inRangeColors = new List<Color32>();
}
}

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
@@ -63,11 +62,11 @@ namespace XCharts.Runtime
return;
}
if (local.x < chart.chartX
|| local.x > chart.chartX + chart.chartWidth
|| local.y < chart.chartY
|| local.y > chart.chartY + chart.chartHeight
|| !visualMap.IsInRangeRect(local, chart.chartRect))
if (local.x < chart.chartX ||
local.x > chart.chartX + chart.chartWidth ||
local.y < chart.chartY ||
local.y > chart.chartY + chart.chartHeight ||
!visualMap.IsInRangeRect(local, chart.chartRect))
{
if (visualMap.context.pointerIndex >= 0)
{
@@ -116,10 +115,10 @@ namespace XCharts.Runtime
var halfHig = visualMap.itemHeight / 2;
var xRadius = 0f;
var yRadius = 0f;
var splitNum = visualMap.runtimeInRange.Count;
var splitNum = visualMap.inRange.Count;
var splitWid = visualMap.itemHeight / (splitNum - 1);
var isVertical = false;
var colors = visualMap.runtimeInRange;
var colors = visualMap.inRange;
var triangeLen = chart.theme.visualMap.triangeLen;
switch (visualMap.orient)
@@ -172,8 +171,8 @@ namespace XCharts.Runtime
}
break;
}
if (visualMap.calculable
&& (visualMap.rangeMin > visualMap.min || visualMap.rangeMax < visualMap.max))
if (visualMap.calculable &&
(visualMap.rangeMin > visualMap.min || visualMap.rangeMax < visualMap.max))
{
var rangeMin = visualMap.rangeMin;
var rangeMax = visualMap.rangeMax;
@@ -189,8 +188,8 @@ namespace XCharts.Runtime
else if (rangeMin <= splitMin && rangeMax >= splitMax)
{
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
var startColor = colors[i - 1];
var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
var startColor = colors[i - 1].color;
var toColor = visualMap.IsPiecewise() ? startColor : colors[i].color;
UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
}
else if (rangeMin > splitMin && rangeMax >= splitMax)
@@ -199,7 +198,7 @@ namespace XCharts.Runtime
var splitMaxPos = pos1 + dir * i * splitWid;
var splitPos = p0 + (splitMaxPos - p0) / 2;
var startColor = visualMap.GetColor(visualMap.rangeMin);
var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
var toColor = visualMap.IsPiecewise() ? startColor : colors[i].color;
var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2;
if (visualMap.orient == Orient.Vertical)
@@ -212,7 +211,7 @@ namespace XCharts.Runtime
var p0 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
var splitMinPos = pos1 + dir * (i - 1) * splitWid;
var splitPos = splitMinPos + (p0 - splitMinPos) / 2;
var startColor = colors[i - 1];
var startColor = colors[i - 1].color;
var toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(visualMap.rangeMax);
var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2;
@@ -242,8 +241,8 @@ namespace XCharts.Runtime
for (int i = 1; i < splitNum; i++)
{
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
var startColor = colors[i - 1];
var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
var startColor = colors[i - 1].color;
var toColor = visualMap.IsPiecewise() ? startColor : colors[i].color;
UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
}
}
@@ -272,14 +271,14 @@ namespace XCharts.Runtime
var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex]);
UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex].color);
}
else
{
var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex]);
UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex].color);
}
}
}
@@ -293,23 +292,21 @@ namespace XCharts.Runtime
var dir = Vector3.zero;
var halfWid = visualMap.itemWidth / 2;
var halfHig = visualMap.itemHeight / 2;
var splitNum = visualMap.runtimeInRange.Count;
var colors = visualMap.runtimeInRange;
switch (visualMap.orient)
{
case Orient.Horizonal:
for (int i = 0; i < visualMap.pieces.Count; i++)
for (int i = 0; i < visualMap.inRange.Count; i++)
{
var piece = visualMap.pieces[i];
var piece = visualMap.inRange[i];
}
break;
case Orient.Vertical:
var each = visualMap.itemHeight + visualMap.itemGap;
for (int i = 0; i < visualMap.pieces.Count; i++)
for (int i = 0; i < visualMap.inRange.Count; i++)
{
var piece = visualMap.pieces[i];
var piece = visualMap.inRange[i];
var pos = new Vector3(centerPos.x, centerPos.y - each * i);
UGL.DrawRectangle(vh, pos, halfWid, halfHig, piece.color);
}

Some files were not shown because too many files have changed in this diff Show More