mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 08:50:10 +00:00
优化代码,更好的支持自定义图表
This commit is contained in:
@@ -1,412 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class AxisHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 包含箭头偏移的轴线长度
|
||||
/// </summary>
|
||||
/// <param name="axis"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetAxisLineSymbolOffset(Axis axis)
|
||||
{
|
||||
if (axis.axisLine.show && axis.axisLine.showArrow && axis.axisLine.arrow.offset > 0)
|
||||
{
|
||||
return axis.axisLine.arrow.offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割段数
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom)
|
||||
{
|
||||
if (axis.type == Axis.AxisType.Value)
|
||||
{
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
if (coordinateWid <= 0) return 0;
|
||||
int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
|
||||
int maxNum = Mathf.CeilToInt(coordinateWid / 15);
|
||||
if (num > maxNum)
|
||||
{
|
||||
axis.interval *= 2;
|
||||
num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
else
|
||||
{
|
||||
return axis.splitNumber > 0 ? axis.splitNumber : 4;
|
||||
}
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Time)
|
||||
{
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
if (coordinateWid <= 0) return 0;
|
||||
int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
|
||||
int maxNum = Mathf.CeilToInt(coordinateWid / 15);
|
||||
if (num > maxNum)
|
||||
{
|
||||
axis.interval *= 2;
|
||||
num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
else
|
||||
{
|
||||
return axis.splitNumber > 0 ? axis.splitNumber : 4;
|
||||
}
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
return axis.splitNumber > 0 ? axis.splitNumber : 4;
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Category)
|
||||
{
|
||||
int dataCount = axis.GetDataList(dataZoom).Count;
|
||||
if (axis.splitNumber <= 0 || axis.splitNumber > dataCount) return dataCount;
|
||||
if (dataCount >= axis.splitNumber * 2) return axis.splitNumber;
|
||||
else return dataCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割段的宽度
|
||||
/// </summary>
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetSplitWidth(Axis axis, float coordinateWidth, DataZoom dataZoom)
|
||||
{
|
||||
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
int segment = (axis.boundaryGap ? split : split - 1);
|
||||
segment = segment <= 0 ? 1 : segment;
|
||||
return coordinateWidth / segment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得一个类目数据在坐标系中代表的宽度
|
||||
/// </summary>
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)
|
||||
{
|
||||
if (dataCount < 1) dataCount = 1;
|
||||
var categoryCount = axis.GetDataNumber(dataZoom);
|
||||
int segment = (axis.boundaryGap ? categoryCount : categoryCount - 1);
|
||||
segment = segment <= 0 ? dataCount : segment;
|
||||
if (segment <= 0) segment = 1;
|
||||
return coordinateWidth / segment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得标签显示的名称
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="minValue"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue,
|
||||
DataZoom dataZoom, bool forcePercent)
|
||||
{
|
||||
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
if (axis.type == Axis.AxisType.Value)
|
||||
{
|
||||
if (minValue == 0 && maxValue == 0) return string.Empty;
|
||||
var value = 0f;
|
||||
if (forcePercent) maxValue = 100;
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
if (index == split) value = maxValue;
|
||||
else value = minValue + index * axis.interval;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = minValue + (maxValue - minValue) * index / split;
|
||||
if (!axis.clockwise && value != minValue) value = maxValue - value;
|
||||
}
|
||||
if (axis.inverse)
|
||||
{
|
||||
value = -value;
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
|
||||
if (forcePercent) return string.Format("{0}%", (int)value);
|
||||
else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue);
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) :
|
||||
Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index);
|
||||
if (axis.inverse)
|
||||
{
|
||||
value = -value;
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
return axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true);
|
||||
}
|
||||
else if (axis.type == Axis.AxisType.Time)
|
||||
{
|
||||
if (minValue == 0 && maxValue == 0) return string.Empty;
|
||||
var value = 0f;
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
if (index == split) value = maxValue;
|
||||
else value = minValue + index * axis.interval;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = minValue + (maxValue - minValue) * index / split;
|
||||
}
|
||||
var timestamp = (int)value;
|
||||
var dateTime = DateTimeUtil.GetDateTime(timestamp);
|
||||
return axis.axisLabel.GetFormatterDateTime(dateTime);
|
||||
}
|
||||
var showData = axis.GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
if (dataCount <= 0) return "";
|
||||
int rate = Mathf.RoundToInt(dataCount * 1f / split);
|
||||
int newIndex = index * rate;
|
||||
if (newIndex <= dataCount - 1)
|
||||
{
|
||||
return axis.axisLabel.GetFormatterContent(showData[newIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rate == 1) return string.Empty;
|
||||
else if (axis.boundaryGap && coordinateWidth / dataCount > 10) return string.Empty;
|
||||
else
|
||||
{
|
||||
if ((index - 1) * rate > dataCount - 1) return string.Empty;
|
||||
else return axis.axisLabel.GetFormatterContent(showData[dataCount - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割线条数
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
|
||||
{
|
||||
int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
var data = axis.GetDataList();
|
||||
int tick = Mathf.RoundToInt(data.Count * 1f / splitNum);
|
||||
if (axis.boundaryGap)
|
||||
return Mathf.CeilToInt(data.Count * 1.0f / tick) + 1;
|
||||
else
|
||||
return Mathf.CeilToInt(data.Count * 1.0f / tick);
|
||||
}
|
||||
else
|
||||
{
|
||||
return splitNum + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得分割段宽度
|
||||
/// </summary>
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null)
|
||||
{
|
||||
if (index < 0) return 0;
|
||||
int num = GetScaleNumber(axis, coordinateWidth, dataZoom);
|
||||
int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
if (num <= 0) num = 1;
|
||||
if (axis.type == Axis.AxisType.Value && axis.interval > 0)
|
||||
{
|
||||
if (axis.runtimeMinMaxRange <= 0) return 0;
|
||||
if (index >= splitNum) return coordinateWidth - (index - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange;
|
||||
else return axis.interval * coordinateWidth / axis.runtimeMinMaxRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
var data = axis.GetDataList();
|
||||
if (axis.IsCategory() && data.Count > 0)
|
||||
{
|
||||
int tick = Mathf.RoundToInt(data.Count * 1f / splitNum);
|
||||
var count = axis.boundaryGap ? data.Count : data.Count - 1;
|
||||
if (count <= 0) return 0;
|
||||
var each = coordinateWidth / count;
|
||||
if (index >= num - 1)
|
||||
{
|
||||
if (axis.axisTick.alignWithLabel) return each * tick;
|
||||
else return coordinateWidth - each * tick * (index - 1);
|
||||
}
|
||||
else return each * tick;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (splitNum <= 0) return 0;
|
||||
else return coordinateWidth / splitNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static float GetEachWidth(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
|
||||
{
|
||||
var data = axis.GetDataList();
|
||||
if (data.Count > 0)
|
||||
{
|
||||
var count = axis.boundaryGap ? data.Count : data.Count - 1;
|
||||
return count > 0 ? coordinateWidth / count : coordinateWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
int num = GetScaleNumber(axis, coordinateWidth, dataZoom) - 1;
|
||||
return num > 0 ? coordinateWidth / num : coordinateWidth;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调整最大最小值
|
||||
/// </summary>
|
||||
/// <param name="minValue"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void AdjustMinMaxValue(Axis axis, ref float minValue, ref float maxValue, bool needFormat, int ceilRate = 0)
|
||||
{
|
||||
if (axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
int minSplit = 0;
|
||||
int maxSplit = 0;
|
||||
maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit);
|
||||
minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit);
|
||||
axis.splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit);
|
||||
return;
|
||||
}
|
||||
if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
|
||||
{
|
||||
if (axis.min != 0 || axis.max != 0)
|
||||
{
|
||||
if (axis.inverse)
|
||||
{
|
||||
minValue = -axis.max;
|
||||
maxValue = -axis.min;
|
||||
}
|
||||
else
|
||||
{
|
||||
minValue = axis.min;
|
||||
maxValue = axis.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ceilRate == 0) ceilRate = axis.ceilRate;
|
||||
switch (axis.minMaxType)
|
||||
{
|
||||
case Axis.AxisMinMaxType.Default:
|
||||
if (minValue == 0 && maxValue == 0)
|
||||
{
|
||||
}
|
||||
else if (minValue > 0 && maxValue > 0)
|
||||
{
|
||||
minValue = 0;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
|
||||
}
|
||||
else if (minValue < 0 && maxValue < 0)
|
||||
{
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
|
||||
}
|
||||
break;
|
||||
case Axis.AxisMinMaxType.MinMax:
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var tempRange = maxValue - minValue;
|
||||
if (axis.runtimeMinMaxRange != tempRange)
|
||||
{
|
||||
axis.runtimeMinMaxRange = tempRange;
|
||||
if (axis.type == Axis.AxisType.Value && axis.interval > 0)
|
||||
{
|
||||
axis.SetComponentDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool NeedShowSplit(Axis axis)
|
||||
{
|
||||
if (!axis.show) return false;
|
||||
if (axis.IsCategory() && axis.GetDataList().Count <= 0) return false;
|
||||
else if (axis.IsValue() && axis.runtimeMinValue == 0 && axis.runtimeMaxValue == 0) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
internal static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
{
|
||||
var txtWidth = txt.GetPreferredWidth();
|
||||
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
|
||||
txt.SetSizeDelta(sizeDelta);
|
||||
var diff = pos.x - cenPos.x;
|
||||
if (diff < -1f) //left
|
||||
{
|
||||
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
|
||||
}
|
||||
else if (diff > 1f) //right
|
||||
{
|
||||
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x, y);
|
||||
}
|
||||
txt.SetLocalPosition(pos + offset);
|
||||
}
|
||||
|
||||
internal static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
{
|
||||
var txtWidth = txt.GetPreferredWidth();
|
||||
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
|
||||
txt.SetSizeDelta(sizeDelta);
|
||||
var diff = pos.y - cenPos.y;
|
||||
if (diff > 20f) //left
|
||||
{
|
||||
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
|
||||
}
|
||||
else if (diff < -20f) //right
|
||||
{
|
||||
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x, y);
|
||||
}
|
||||
txt.SetLocalPosition(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 502c2be6d197b40f59ae65d9c659700f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,24 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class ItemStyleHelper
|
||||
{
|
||||
public static bool IsNeedCorner(ItemStyle itemStyle)
|
||||
{
|
||||
if (itemStyle.cornerRadius == null) return false;
|
||||
foreach (var value in itemStyle.cornerRadius)
|
||||
{
|
||||
if (value != 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14c20b85c2c6d44b08f57c928307080d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,307 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class LegendHelper
|
||||
{
|
||||
public static Color GetContentColor(Legend legend, ChartTheme theme, bool active)
|
||||
{
|
||||
var textStyle = legend.textStyle;
|
||||
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
|
||||
else return theme.legend.unableColor;
|
||||
}
|
||||
|
||||
public static Color GetIconColor(Legend legend, int readIndex, ChartTheme theme, Series series, string legendName, bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
|
||||
{
|
||||
return SeriesHelper.GetNameColor(series, readIndex, legendName, theme);
|
||||
}
|
||||
else
|
||||
return Color.white;
|
||||
}
|
||||
else return theme.legend.unableColor;
|
||||
}
|
||||
|
||||
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent,
|
||||
ChartTheme theme, string content, Color itemColor, bool active)
|
||||
{
|
||||
var objName = i + "_" + legendName;
|
||||
var anchorMin = new Vector2(0, 0.5f);
|
||||
var anchorMax = new Vector2(0, 0.5f);
|
||||
var pivot = new Vector2(0, 0.5f);
|
||||
var sizeDelta = new Vector2(100, 30);
|
||||
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
|
||||
var textStyle = legend.textStyle;
|
||||
var contentColor = GetContentColor(legend, theme, active);
|
||||
|
||||
var objAnchorMin = new Vector2(0, 1);
|
||||
var objAnchorMax = new Vector2(0, 1);
|
||||
var objPivot = new Vector2(0, 1);
|
||||
var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta, i);
|
||||
var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
|
||||
var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var img = ChartHelper.GetOrAddComponent<Image>(btnObj);
|
||||
img.color = Color.clear;
|
||||
ChartHelper.GetOrAddComponent<Button>(btnObj);
|
||||
ChartHelper.GetOrAddComponent<Image>(iconObj);
|
||||
ChartHelper.GetOrAddComponent<Image>(contentObj);
|
||||
var txt = ChartHelper.AddTextObject("Text", contentObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
|
||||
textStyle, theme.legend);
|
||||
txt.SetAlignment(TextAnchor.MiddleLeft);
|
||||
txt.SetColor(contentColor);
|
||||
var item = new LegendItem();
|
||||
item.index = i;
|
||||
item.name = objName;
|
||||
item.legendName = legendName;
|
||||
item.SetObject(btnObj);
|
||||
item.SetIconSize(legend.itemWidth, legend.itemHeight);
|
||||
item.SetIconColor(itemColor);
|
||||
item.SetIconImage(legend.GetIcon(i));
|
||||
item.SetContentPosition(textStyle.offsetv3);
|
||||
item.SetContent(content);
|
||||
item.SetContentBackgroundColor(textStyle.backgroundColor);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void ResetItemPosition(Legend legend, Vector3 chartPos, float chartWidth, float chartHeight)
|
||||
{
|
||||
var startX = 0f;
|
||||
var startY = 0f;
|
||||
var legendMaxWidth = chartWidth - legend.location.left - legend.location.right;
|
||||
var legendMaxHeight = chartHeight - legend.location.top - legend.location.bottom;
|
||||
UpdateLegendWidthAndHeight(legend, legendMaxWidth, legendMaxHeight);
|
||||
var legendRuntimeWidth = legend.runtimeWidth;
|
||||
var legendRuntimeHeight = legend.runtimeHeight;
|
||||
var isVertical = legend.orient == Orient.Vertical;
|
||||
switch (legend.location.align)
|
||||
{
|
||||
case Location.Align.TopCenter:
|
||||
startX = chartPos.x + chartWidth / 2 - legendRuntimeWidth / 2;
|
||||
startY = chartPos.y + chartHeight - legend.location.top;
|
||||
break;
|
||||
case Location.Align.TopLeft:
|
||||
startX = chartPos.x + legend.location.left;
|
||||
startY = chartPos.y + chartHeight - legend.location.top;
|
||||
break;
|
||||
case Location.Align.TopRight:
|
||||
startX = chartPos.x + chartWidth - legendRuntimeWidth - legend.location.right;
|
||||
startY = chartPos.y + chartHeight - legend.location.top;
|
||||
break;
|
||||
case Location.Align.Center:
|
||||
startX = chartPos.x + chartWidth / 2 - legendRuntimeWidth / 2;
|
||||
startY = chartPos.y + chartHeight / 2 + legendRuntimeHeight / 2;
|
||||
break;
|
||||
case Location.Align.CenterLeft:
|
||||
startX = chartPos.x + legend.location.left;
|
||||
startY = chartPos.y + chartHeight / 2 + legendRuntimeHeight / 2;
|
||||
break;
|
||||
case Location.Align.CenterRight:
|
||||
startX = chartPos.x + chartWidth - legendRuntimeWidth - legend.location.right;
|
||||
startY = chartPos.y + chartHeight / 2 + legendRuntimeHeight / 2;
|
||||
break;
|
||||
case Location.Align.BottomCenter:
|
||||
startX = chartPos.x + chartWidth / 2 - legendRuntimeWidth / 2;
|
||||
startY = chartPos.y + legendRuntimeHeight + legend.location.bottom;
|
||||
break;
|
||||
case Location.Align.BottomLeft:
|
||||
startX = chartPos.x + legend.location.left;
|
||||
startY = chartPos.y + legendRuntimeHeight + legend.location.bottom;
|
||||
break;
|
||||
case Location.Align.BottomRight:
|
||||
startX = chartPos.x + chartWidth - legendRuntimeWidth - legend.location.right;
|
||||
startY = chartPos.y + legendRuntimeHeight + legend.location.bottom;
|
||||
break;
|
||||
}
|
||||
if (isVertical) SetVerticalItemPosition(legend, legendMaxHeight, startX, startY);
|
||||
else SetHorizonalItemPosition(legend, legendMaxWidth, startX, startY);
|
||||
}
|
||||
|
||||
private static void SetVerticalItemPosition(Legend legend, float legendMaxHeight, float startX, float startY)
|
||||
{
|
||||
var currHeight = 0f;
|
||||
var offsetX = 0f;
|
||||
var row = 0;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
if (currHeight + item.height > legendMaxHeight)
|
||||
{
|
||||
currHeight = 0;
|
||||
offsetX += legend.runtimeEachWidth[row];
|
||||
row++;
|
||||
}
|
||||
item.SetPosition(new Vector3(startX + offsetX, startY - currHeight));
|
||||
currHeight += item.height + legend.itemGap;
|
||||
}
|
||||
}
|
||||
private static void SetHorizonalItemPosition(Legend legend, float legendMaxWidth, float startX, float startY)
|
||||
{
|
||||
var currWidth = 0f;
|
||||
var offsetY = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
if (currWidth + item.width > legendMaxWidth)
|
||||
{
|
||||
currWidth = 0;
|
||||
offsetY += legend.runtimeEachHeight;
|
||||
}
|
||||
item.SetPosition(new Vector3(startX + currWidth, startY - offsetY));
|
||||
currWidth += item.width + legend.itemGap;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateLegendWidthAndHeight(Legend legend, float maxWidth, float maxHeight)
|
||||
{
|
||||
var width = 0f;
|
||||
var height = 0f;
|
||||
var realHeight = 0f;
|
||||
var realWidth = 0f;
|
||||
legend.runtimeEachWidth.Clear();
|
||||
legend.runtimeEachHeight = 0;
|
||||
if (legend.orient == Orient.Horizonal)
|
||||
{
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
if (width + kv.Value.width > maxWidth)
|
||||
{
|
||||
realWidth = width - legend.itemGap;
|
||||
realHeight += height + legend.itemGap;
|
||||
if (legend.runtimeEachHeight < height + legend.itemGap)
|
||||
{
|
||||
legend.runtimeEachHeight = height + legend.itemGap;
|
||||
}
|
||||
height = 0;
|
||||
width = 0;
|
||||
}
|
||||
width += kv.Value.width + legend.itemGap;
|
||||
if (kv.Value.height > height)
|
||||
height = kv.Value.height;
|
||||
}
|
||||
width -= legend.itemGap;
|
||||
legend.runtimeHeight = realHeight + height;
|
||||
legend.runtimeWidth = realWidth > 0 ? realWidth : width;
|
||||
}
|
||||
else
|
||||
{
|
||||
var row = 0;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
if (height + kv.Value.height > maxHeight)
|
||||
{
|
||||
realHeight = height - legend.itemGap;
|
||||
realWidth += width + legend.itemGap;
|
||||
legend.runtimeEachWidth[row] = width + legend.itemGap;
|
||||
row++;
|
||||
height = 0;
|
||||
width = 0;
|
||||
}
|
||||
height += kv.Value.height + legend.itemGap;
|
||||
if (kv.Value.width > width)
|
||||
width = kv.Value.width;
|
||||
}
|
||||
height -= legend.itemGap;
|
||||
legend.runtimeHeight = realHeight > 0 ? realHeight : height;
|
||||
legend.runtimeWidth = realWidth + width;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsBeyondWidth(Legend legend, float maxWidth)
|
||||
{
|
||||
var totalWidth = 0f;
|
||||
foreach (var kv in legend.buttonList)
|
||||
{
|
||||
var item = kv.Value;
|
||||
totalWidth += item.width + legend.itemGap;
|
||||
if (totalWidth > maxWidth) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool CheckDataShow(Series series, string legendName, bool show)
|
||||
{
|
||||
bool needShow = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.show = show;
|
||||
serie.highlighted = false;
|
||||
if (serie.show) needShow = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.show = show;
|
||||
data.highlighted = false;
|
||||
if (data.show) needShow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return needShow;
|
||||
}
|
||||
|
||||
public static bool CheckDataHighlighted(Series series, string legendName, bool heighlight)
|
||||
{
|
||||
bool show = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.highlighted = heighlight;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.highlighted = heighlight;
|
||||
if (data.highlighted) show = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return show;
|
||||
}
|
||||
|
||||
public static bool IsSerieLegend(Series series, string legendName, SerieType type)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.type == type)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Pie:
|
||||
case SerieType.Radar:
|
||||
case SerieType.Ring:
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
if (legendName.Equals(serieData.name)) return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (legendName.Equals(serie.name)) return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d03ce7a11ecde41b6930883612bf8f05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,9 +9,9 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class PolarHelper
|
||||
public static class PolarHelper
|
||||
{
|
||||
internal static void UpdatePolarCenter(Polar polar, Vector3 chartPosition, float chartWidth, float chartHeight)
|
||||
public static void UpdatePolarCenter(Polar polar, Vector3 chartPosition, float chartWidth, float chartHeight)
|
||||
{
|
||||
if (polar.center.Length < 2) return;
|
||||
var centerX = polar.center[0] <= 1 ? chartWidth * polar.center[0] : polar.center[0];
|
||||
|
||||
@@ -1,427 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static partial class SerieHelper
|
||||
{
|
||||
internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ChartTheme theme, int index,
|
||||
bool highlight, bool useDefault = true)
|
||||
{
|
||||
var color = ChartConst.clearColor32;
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.backgroundColor))
|
||||
{
|
||||
color = itemStyleEmphasis.backgroundColor;
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
var itemStyle = GetItemStyle(serie, serieData);
|
||||
if (!ChartHelper.IsClearColor(itemStyle.backgroundColor))
|
||||
{
|
||||
color = itemStyle.backgroundColor;
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
else if (useDefault)
|
||||
{
|
||||
color = theme.GetColor(index);
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
color.a = 50;
|
||||
return color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
internal static Color32 GetItemColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
if (serie == null) return ChartConst.clearColor32;
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
|
||||
{
|
||||
var color = itemStyleEmphasis.color;
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
var itemStyle = GetItemStyle(serie, serieData);
|
||||
if (!ChartHelper.IsClearColor(itemStyle.color))
|
||||
{
|
||||
return itemStyle.GetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = theme.GetColor(index);
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
internal static Color32 GetItemColor0(Serie serie, SerieData serieData, ChartTheme theme, bool highlight, Color32 defaultColor)
|
||||
{
|
||||
if (serie == null) return ChartConst.clearColor32;
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
|
||||
{
|
||||
var color = itemStyleEmphasis.color0;
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
var itemStyle = GetItemStyle(serie, serieData);
|
||||
if (!ChartHelper.IsClearColor(itemStyle.color0))
|
||||
{
|
||||
return itemStyle.GetColor0();
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = defaultColor;
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.toColor))
|
||||
{
|
||||
return itemStyleEmphasis.GetColor();
|
||||
}
|
||||
}
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle == null) itemStyle = serieData.itemStyle;
|
||||
if (!ChartHelper.IsClearColor(itemStyle.toColor))
|
||||
{
|
||||
var color = itemStyle.toColor;
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
if (!ChartHelper.IsClearColor(itemStyle.color))
|
||||
{
|
||||
var color = itemStyle.color;
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = theme.GetColor(index);
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool IsDownPoint(Serie serie, int index)
|
||||
{
|
||||
var dataPoints = serie.dataPoints;
|
||||
if (dataPoints.Count < 2) return false;
|
||||
else if (index > 0 && index < dataPoints.Count - 1)
|
||||
{
|
||||
var lp = dataPoints[index - 1];
|
||||
var np = dataPoints[index + 1];
|
||||
var cp = dataPoints[index];
|
||||
var dot = Vector3.Cross(np - lp, cp - np);
|
||||
return dot.z < 0;
|
||||
}
|
||||
else if (index == 0)
|
||||
{
|
||||
return dataPoints[0].y < dataPoints[1].y;
|
||||
}
|
||||
else if (index == dataPoints.Count - 1)
|
||||
{
|
||||
return dataPoints[index].y < dataPoints[index - 1].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
var style = GetItemStyleEmphasis(serie, serieData);
|
||||
if (style == null) return GetItemStyle(serie, serieData, false);
|
||||
else return style;
|
||||
}
|
||||
else if (serie.IsPerformanceMode()) return serie.itemStyle;
|
||||
else if (serieData != null && serieData.enableItemStyle) return serieData.itemStyle;
|
||||
else return serie.itemStyle;
|
||||
}
|
||||
|
||||
internal static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData != null && serieData.enableEmphasis && serieData.emphasis.show)
|
||||
return serieData.emphasis.itemStyle;
|
||||
else if (serie.emphasis.show) return serie.emphasis.itemStyle;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static SerieLabel GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableEmphasis && serieData.emphasis.show)
|
||||
return serieData.emphasis.label;
|
||||
else if (serie.emphasis.show) return serie.emphasis.label;
|
||||
else return serie.label;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableLabel) return serieData.label;
|
||||
else return serie.label;
|
||||
}
|
||||
}
|
||||
|
||||
internal static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableSymbol) return serieData.symbol;
|
||||
else return serie.symbol;
|
||||
}
|
||||
|
||||
internal static Color32 GetAreaColor(Serie serie, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : theme.GetColor(index);
|
||||
if (highlight)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(areaStyle.highlightColor)) color = areaStyle.highlightColor;
|
||||
else color = ChartHelper.GetHighlightColor(color);
|
||||
}
|
||||
ChartHelper.SetColorOpacity(ref color, areaStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
|
||||
internal static Color32 GetAreaToColor(Serie serie, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
if (!ChartHelper.IsClearColor(areaStyle.toColor))
|
||||
{
|
||||
var color = areaStyle.toColor;
|
||||
if (highlight)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(areaStyle.highlightToColor)) color = areaStyle.highlightToColor;
|
||||
else color = ChartHelper.GetHighlightColor(color);
|
||||
}
|
||||
ChartHelper.SetColorOpacity(ref color, areaStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetAreaColor(serie, theme, index, highlight);
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color32 GetLineColor(Serie serie, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
Color32 color = ChartConst.clearColor32;
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
|
||||
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
|
||||
{
|
||||
color = itemStyleEmphasis.color;
|
||||
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (!ChartHelper.IsClearColor(serie.lineStyle.color)) color = serie.lineStyle.GetColor();
|
||||
else if (!ChartHelper.IsClearColor(serie.itemStyle.color)) color = serie.itemStyle.GetColor();
|
||||
if (ChartHelper.IsClearColor(color))
|
||||
{
|
||||
color = theme.GetColor(index);
|
||||
ChartHelper.SetColorOpacity(ref color, serie.lineStyle.opacity);
|
||||
}
|
||||
if (highlight) color = ChartHelper.GetHighlightColor(color);
|
||||
return color;
|
||||
}
|
||||
|
||||
internal static float GetSymbolBorder(Serie serie, SerieData serieData, ChartTheme theme, bool highlight, bool useLineWidth = true)
|
||||
{
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
|
||||
else return serie.lineStyle.GetWidth(theme.serie.lineWidth);
|
||||
}
|
||||
|
||||
internal static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)
|
||||
{
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle != null) return itemStyle.cornerRadius;
|
||||
else return null;
|
||||
}
|
||||
|
||||
internal static string GetNumericFormatter(Serie serie, SerieData serieData)
|
||||
{
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
|
||||
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
|
||||
else return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定维数的最大最小值
|
||||
/// </summary>
|
||||
/// <param name="dimension"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static void UpdateMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null)
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
GetMinMaxData(serie, dimension, out min, out max, dataZoom);
|
||||
if (ceilRate < 0)
|
||||
{
|
||||
serie.runtimeDataMin = min;
|
||||
serie.runtimeDataMax = max;
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
|
||||
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void GetAllMinMaxData(Serie serie, int ceilRate = 0, DataZoom dataZoom = null)
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
GetMinMaxData(serie, out min, out max, dataZoom);
|
||||
if (ceilRate < 0)
|
||||
{
|
||||
serie.runtimeDataMin = min;
|
||||
serie.runtimeDataMax = max;
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
|
||||
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<SerieData> emptyFilter = new List<SerieData>();
|
||||
/// <summary>
|
||||
/// 根据dataZoom更新数据列表缓存
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
internal static void UpdateFilterData(Serie serie, DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom == null || !dataZoom.enable) return;
|
||||
if (dataZoom.xAxisIndexs.Contains(serie.xAxisIndex))
|
||||
{
|
||||
if (dataZoom.IsXAxisIndexValue(serie.xAxisIndex))
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
dataZoom.GetXAxisIndexValue(serie.xAxisIndex, out min, out max);
|
||||
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateFilterData_Category(serie, dataZoom);
|
||||
}
|
||||
}
|
||||
else if (dataZoom.yAxisIndexs.Contains(serie.yAxisIndex))
|
||||
{
|
||||
if (dataZoom.IsYAxisIndexValue(serie.yAxisIndex))
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
dataZoom.GetYAxisIndexValue(serie.yAxisIndex, out min, out max);
|
||||
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateFilterData_Category(serie, dataZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, float min, float max)
|
||||
{
|
||||
var data = serie.data;
|
||||
var startValue = min + (max - min) * dataZoom.start / 100;
|
||||
var endValue = min + (max - min) * dataZoom.end / 100;
|
||||
if (endValue < startValue) endValue = startValue;
|
||||
|
||||
if (startValue != serie.m_FilterStartValue || endValue != serie.m_FilterEndValue
|
||||
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
|
||||
{
|
||||
serie.m_FilterStartValue = startValue;
|
||||
serie.m_FilterEndValue = endValue;
|
||||
serie.m_FilterMinShow = dataZoom.minShowNum;
|
||||
serie.m_NeedUpdateFilterData = false;
|
||||
|
||||
serie.m_FilterData.Clear();
|
||||
foreach (var serieData in data)
|
||||
{
|
||||
var value = serieData.GetData(dimension);
|
||||
if (value >= startValue && value <= endValue)
|
||||
{
|
||||
serie.m_FilterData.Add(serieData);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (endValue == 0)
|
||||
{
|
||||
serie.m_FilterData = emptyFilter;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateFilterData_Category(Serie serie, DataZoom dataZoom)
|
||||
{
|
||||
var data = serie.data;
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
if (endIndex < startIndex) endIndex = startIndex;
|
||||
|
||||
if (startIndex != serie.m_FilterStart || endIndex != serie.m_FilterEnd
|
||||
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
|
||||
{
|
||||
serie.m_FilterStart = startIndex;
|
||||
serie.m_FilterEnd = endIndex;
|
||||
serie.m_FilterMinShow = dataZoom.minShowNum;
|
||||
serie.m_NeedUpdateFilterData = false;
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (count < dataZoom.minShowNum)
|
||||
{
|
||||
if (dataZoom.minShowNum > data.Count) count = data.Count;
|
||||
else count = dataZoom.minShowNum;
|
||||
}
|
||||
if (data.Count > 0)
|
||||
{
|
||||
if (startIndex + count > data.Count)
|
||||
{
|
||||
int start = endIndex - count;
|
||||
data = data.GetRange(start < 0 ? 0 : start, count);
|
||||
}
|
||||
else serie.m_FilterData = data.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.m_FilterData = data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
{
|
||||
serie.m_FilterData = emptyFilter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5c421b17fb6f45a283f4f57efce686f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,314 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class SerieLabelHelper
|
||||
{
|
||||
public static void CheckLabel(Serie serie, ref bool m_ReinitLabel, ref bool m_UpdateLabelText)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Gauge:
|
||||
case SerieType.Ring:
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData != null)
|
||||
{
|
||||
if (serie.label.show && serie.show)
|
||||
{
|
||||
if (serieData.labelObject != null)
|
||||
{
|
||||
serieData.SetLabelActive(true);
|
||||
m_UpdateLabelText = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ReinitLabel = true;
|
||||
}
|
||||
}
|
||||
else if (serieData.labelObject != null)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateLabelText(Series series, ChartTheme theme, List<string> legendRealShowName)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (!serie.label.show) continue;
|
||||
var colorIndex = legendRealShowName.IndexOf(serie.name);
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Gauge:
|
||||
SetGaugeLabelText(serie);
|
||||
break;
|
||||
case SerieType.Ring:
|
||||
SetRingLabelText(serie, theme);
|
||||
break;
|
||||
case SerieType.Liquid:
|
||||
SetLiquidLabelText(serie, theme, colorIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetLabelColor(Serie serie, ChartTheme theme, int index)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
|
||||
{
|
||||
return serie.label.textStyle.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return theme.GetColor(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetLabel(ChartText labelObject, SerieLabel label, ChartTheme theme, int colorIndex)
|
||||
{
|
||||
if (labelObject == null) return;
|
||||
labelObject.SetColor(!ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color :
|
||||
(Color)theme.GetColor(colorIndex));
|
||||
labelObject.SetFontSize(label.textStyle.GetFontSize(theme.common));
|
||||
labelObject.SetFontStyle(label.textStyle.fontStyle);
|
||||
}
|
||||
|
||||
public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion)
|
||||
{
|
||||
return serie.show && serieData.canShowLabel && !serie.IsIgnoreValue(serieData.GetData(dimesion));
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Serie serie, SerieData serieData,
|
||||
float dataValue, float dataTotal, SerieLabel serieLabel, Color color)
|
||||
{
|
||||
if (serieLabel == null)
|
||||
{
|
||||
serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
}
|
||||
var numericFormatter = serieLabel == null ? serie.label.numericFormatter : serieLabel.numericFormatter;
|
||||
var serieName = serie.name;
|
||||
var dataName = serieData != null ? serieData.name : null;
|
||||
if (string.IsNullOrEmpty(serieLabel.formatter))
|
||||
return ChartCached.NumberToStr(dataValue, numericFormatter);
|
||||
else
|
||||
{
|
||||
var content = serieLabel.formatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, dataValue,
|
||||
dataTotal, serieName, dataName, color);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetGaugeLabelText(Serie serie)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData == null) return;
|
||||
if (serieData.labelObject == null) return;
|
||||
var value = serieData.GetData(1);
|
||||
var total = serie.max;
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
|
||||
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
|
||||
{
|
||||
serieData.labelObject.label.SetColor(serie.label.textStyle.color);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetRingLabelText(Serie serie, ChartTheme theme)
|
||||
{
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
|
||||
if (serieLabel.show && serieData.labelObject != null)
|
||||
{
|
||||
if (!serie.show || !serieData.show)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
continue;
|
||||
}
|
||||
var value = serieData.GetData(0);
|
||||
var total = serieData.GetData(1);
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear);
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, i));
|
||||
|
||||
if (serie.label.position == SerieLabel.Position.Bottom)
|
||||
{
|
||||
var labelWidth = serieData.GetLabelWidth();
|
||||
if (serie.clockwise)
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition - new Vector3(labelWidth / 2, 0));
|
||||
else
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition + new Vector3(labelWidth / 2, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetLiquidLabelText(Serie serie, ChartTheme theme, int colorIndex)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData == null) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
|
||||
if (serieLabel.show && serieData.labelObject != null)
|
||||
{
|
||||
if (!serie.show || !serieData.show)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
return;
|
||||
}
|
||||
var value = serieData.GetData(1);
|
||||
var total = serie.max - serie.min;
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear);
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, colorIndex));
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition + serieLabel.offset);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdatePieLabelPosition(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (serieData.labelObject == null) return;
|
||||
var currAngle = serieData.runtimePieHalfAngle;
|
||||
var currRad = currAngle * Mathf.Deg2Rad;
|
||||
var offsetRadius = serieData.runtimePieOffsetRadius;
|
||||
var insideRadius = serieData.runtimePieInsideRadius;
|
||||
var outsideRadius = serieData.runtimePieOutsideRadius;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
switch (serieLabel.position)
|
||||
{
|
||||
case SerieLabel.Position.Center:
|
||||
serieData.labelPosition = serie.runtimeCenterPos;
|
||||
break;
|
||||
case SerieLabel.Position.Inside:
|
||||
var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
|
||||
var labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
|
||||
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
|
||||
serieData.labelPosition = labelCenter;
|
||||
break;
|
||||
case SerieLabel.Position.Outside:
|
||||
if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine)
|
||||
{
|
||||
var radius1 = serie.runtimeOutsideRadius;
|
||||
var radius3 = insideRadius + (outsideRadius - insideRadius) / 2;
|
||||
var currSin = Mathf.Sin(currRad);
|
||||
var currCos = Mathf.Cos(currRad);
|
||||
var pos0 = new Vector3(serie.runtimeCenterPos.x + radius3 * currSin, serie.runtimeCenterPos.y + radius3 * currCos);
|
||||
if (currAngle > 180)
|
||||
{
|
||||
currSin = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
|
||||
currCos = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
|
||||
}
|
||||
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
||||
r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4;
|
||||
r4 += serieData.labelObject.label.GetPreferredWidth() / 2;
|
||||
serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4;
|
||||
}
|
||||
else
|
||||
{
|
||||
labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
||||
labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
|
||||
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
|
||||
serieData.labelPosition = labelCenter;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void AvoidLabelOverlap(Serie serie)
|
||||
{
|
||||
if (!serie.avoidLabelOverlap) return;
|
||||
var lastCheckPos = Vector3.zero;
|
||||
var data = serie.data;
|
||||
var splitCount = 0;
|
||||
for (int n = 0; n < data.Count; n++)
|
||||
{
|
||||
var serieData = data[n];
|
||||
if (serieData.labelPosition.x != 0 && serieData.labelPosition.x < serie.runtimeCenterPos.x)
|
||||
{
|
||||
splitCount = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int n = 0; n < splitCount; n++)
|
||||
{
|
||||
var serieData = data[n];
|
||||
CheckSerieDataLabel(serie, serieData, false, ref lastCheckPos);
|
||||
}
|
||||
lastCheckPos = Vector3.zero;
|
||||
for (int n = data.Count - 1; n >= splitCount; n--)
|
||||
{
|
||||
var serieData = data[n];
|
||||
CheckSerieDataLabel(serie, serieData, true, ref lastCheckPos);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckSerieDataLabel(Serie serie, SerieData serieData, bool isLeft, ref Vector3 lastCheckPos)
|
||||
{
|
||||
if (!serieData.canShowLabel)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
return;
|
||||
}
|
||||
if (!serieData.show) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
if (!serieLabel.show) return;
|
||||
if (serieLabel.position != SerieLabel.Position.Outside) return;
|
||||
if (lastCheckPos == Vector3.zero)
|
||||
{
|
||||
lastCheckPos = serieData.labelPosition;
|
||||
}
|
||||
else if (serieData.labelPosition.x != 0)
|
||||
{
|
||||
float hig = serieLabel.textStyle.fontSize;
|
||||
if (lastCheckPos.y - serieData.labelPosition.y < hig)
|
||||
{
|
||||
var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
||||
var y1 = lastCheckPos.y - hig;
|
||||
var cy = serie.runtimeCenterPos.y;
|
||||
var diff = Mathf.Abs(y1 - cy);
|
||||
var diffX = labelRadius * labelRadius - diff * diff;
|
||||
diffX = diffX <= 0 ? 0 : diffX;
|
||||
var x1 = serie.runtimeCenterPos.x + Mathf.Sqrt(diffX) * (isLeft ? -1 : 1);
|
||||
serieData.labelPosition = new Vector3(x1, y1);
|
||||
}
|
||||
lastCheckPos = serieData.labelPosition;
|
||||
serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel));
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetRealLabelPosition(SerieData serieData, SerieLabel label)
|
||||
{
|
||||
if (label.position == SerieLabel.Position.Outside && label.lineType != SerieLabel.LineType.HorizontalLine)
|
||||
{
|
||||
var currAngle = serieData.runtimePieHalfAngle;
|
||||
var offset = label.lineLength2 + serieData.labelObject.GetLabelWidth() / 2;
|
||||
if (currAngle > 180)
|
||||
return serieData.labelPosition + new Vector3(-offset, 0, 0);
|
||||
else
|
||||
return serieData.labelPosition + new Vector3(offset, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return serieData.labelPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbd57df98f6f145f299cf942b04229a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,548 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class SeriesHelper
|
||||
{
|
||||
public static bool IsNeedLabelUpdate(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.label.vertsDirty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsLabelDirty(Series series)
|
||||
{
|
||||
if (series.labelDirty) return true;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.label.componentDirty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsNameDirty(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.nameDirty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void ClearNameDirty(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
serie.ClearNameDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsLegalLegendName(string name)
|
||||
{
|
||||
int numName = -1;
|
||||
if (int.TryParse(name, out numName))
|
||||
{
|
||||
if (numName >= 0 && numName < 100) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<string> GetLegalSerieNameList(Series series)
|
||||
{
|
||||
var list = new List<string>();
|
||||
for (int n = 0; n < series.list.Count; n++)
|
||||
{
|
||||
var serie = series.GetSerie(n);
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Pie:
|
||||
case SerieType.Radar:
|
||||
case SerieType.Ring:
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
var dataName = serie.data[i].name;
|
||||
if (!string.IsNullOrEmpty(dataName) && IsLegalLegendName(dataName) && !list.Contains(dataName))
|
||||
list.Add(dataName);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!string.IsNullOrEmpty(serie.name) && !list.Contains(serie.name) && IsLegalLegendName(serie.name))
|
||||
list.Add(serie.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得所有系列名,不包含空名字。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static void UpdateSerieNameList(Series series, ref List<string> serieNameList)
|
||||
{
|
||||
serieNameList.Clear();
|
||||
for (int n = 0; n < series.list.Count; n++)
|
||||
{
|
||||
var serie = series.GetSerie(n);
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Pie:
|
||||
case SerieType.Radar:
|
||||
case SerieType.Ring:
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
if (serie.type == SerieType.Pie && serie.IsIgnoreValue(serie.data[i].GetData(1))) continue;
|
||||
if (string.IsNullOrEmpty(serie.data[i].name))
|
||||
serieNameList.Add(ChartCached.IntToStr(i));
|
||||
else if (!serieNameList.Contains(serie.data[i].name))
|
||||
serieNameList.Add(serie.data[i].name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (string.IsNullOrEmpty(serie.name))
|
||||
serieNameList.Add(ChartCached.IntToStr(n));
|
||||
else if (!serieNameList.Contains(serie.name))
|
||||
serieNameList.Add(serie.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color GetNameColor(Series series, int index, string name, ChartTheme theme)
|
||||
{
|
||||
Serie destSerie = null;
|
||||
SerieData destSerieData = null;
|
||||
|
||||
for (int n = 0; n < series.list.Count; n++)
|
||||
{
|
||||
var serie = series.GetSerie(n);
|
||||
if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring)
|
||||
{
|
||||
bool found = false;
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
if (name.Equals(serie.data[i].name))
|
||||
{
|
||||
destSerie = serie;
|
||||
destSerieData = serie.data[i];
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (name.Equals(serie.name))
|
||||
{
|
||||
destSerie = serie;
|
||||
destSerieData = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SerieHelper.GetItemColor(destSerie, destSerieData, theme, index, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同堆叠的serie是否有渐变色的。
|
||||
/// </summary>
|
||||
/// <param name="stack"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsAnyGradientSerie(Series series, string stack)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stack)) return false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack))
|
||||
{
|
||||
if (!ChartHelper.IsValueEqualsColor(serie.areaStyle.color, serie.areaStyle.toColor)
|
||||
&& !ChartHelper.IsClearColor(serie.areaStyle.toColor))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否有需裁剪的serie。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static bool IsAnyClipSerie(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.clip) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool ContainsSerie(Series series, SerieType type)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.type == type) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool IsAnyUpdateAnimationSerie(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.animation.enable && serie.animation.dataChangeEnable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得上一个同堆叠且显示的serie。
|
||||
/// </summary>
|
||||
/// <param name="serie"></param>
|
||||
/// <returns></returns>
|
||||
internal static Serie GetLastStackSerie(Series series, Serie serie)
|
||||
{
|
||||
if (serie == null || string.IsNullOrEmpty(serie.stack)) return null;
|
||||
for (int i = serie.index - 1; i >= 0; i--)
|
||||
{
|
||||
var temp = series.list[i];
|
||||
if (temp.show && serie.stack.Equals(temp.stack)) return temp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得上一个同堆叠且显示的serie。
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
internal static Serie GetLastStackSerie(Series series, int index)
|
||||
{
|
||||
var serie = series.GetSerie(index);
|
||||
return GetLastStackSerie(series, serie);
|
||||
}
|
||||
|
||||
internal static Serie GetSerieByVesselIndex(Series series, int vesselIndex)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.vesselIndex == vesselIndex) return serie;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HashSet<string> _setForStack = new HashSet<string>();
|
||||
/// <summary>
|
||||
/// 是否由数据堆叠
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static bool IsStack(Series series)
|
||||
{
|
||||
_setForStack.Clear();
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.stack)) continue;
|
||||
if (_setForStack.Contains(serie.stack)) return true;
|
||||
else
|
||||
{
|
||||
_setForStack.Add(serie.stack);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否堆叠
|
||||
/// </summary>
|
||||
/// <param name="stackName"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsStack(Series series, string stackName, SerieType type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stackName)) return false;
|
||||
int count = 0;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.type == type)
|
||||
{
|
||||
if (stackName.Equals(serie.stack)) count++;
|
||||
if (count >= 2) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否时百分比堆叠
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsPercentStack(Series series, SerieType type)
|
||||
{
|
||||
int count = 0;
|
||||
bool isPercentStack = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.type == type)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
count++;
|
||||
if (serie.barPercentStack) isPercentStack = true;
|
||||
}
|
||||
if (count >= 2 && isPercentStack) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否时百分比堆叠
|
||||
/// </summary>
|
||||
/// <param name="stackName"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsPercentStack(Series series, string stackName, SerieType type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stackName)) return false;
|
||||
int count = 0;
|
||||
bool isPercentStack = false;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && serie.type == type)
|
||||
{
|
||||
if (stackName.Equals(serie.stack))
|
||||
{
|
||||
count++;
|
||||
if (serie.barPercentStack) isPercentStack = true;
|
||||
}
|
||||
if (count >= 2 && isPercentStack) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Dictionary<string, int> sets = new Dictionary<string, int>();
|
||||
/// <summary>
|
||||
/// 获得堆叠系列列表
|
||||
/// </summary>
|
||||
/// <param name="Dictionary<int"></param>
|
||||
/// <param name="stackSeries"></param>
|
||||
internal static void GetStackSeries(Series series, ref Dictionary<int, List<Serie>> stackSeries)
|
||||
{
|
||||
int count = 0;
|
||||
var serieCount = series.list.Count;
|
||||
sets.Clear();
|
||||
if (stackSeries == null)
|
||||
{
|
||||
stackSeries = new Dictionary<int, List<Serie>>(serieCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var kv in stackSeries)
|
||||
{
|
||||
kv.Value.Clear();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < serieCount; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
serie.index = i;
|
||||
if (string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (!stackSeries.ContainsKey(count))
|
||||
stackSeries[count] = new List<Serie>(serieCount);
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sets.ContainsKey(serie.stack))
|
||||
{
|
||||
sets.Add(serie.stack, count);
|
||||
if (!stackSeries.ContainsKey(count))
|
||||
stackSeries[count] = new List<Serie>(serieCount);
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int stackIndex = sets[serie.stack];
|
||||
stackSeries[stackIndex].Add(serie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdateStackDataList(Series series, Serie currSerie, DataZoom dataZoom, List<List<SerieData>> dataList)
|
||||
{
|
||||
dataList.Clear();
|
||||
for (int i = 0; i <= currSerie.index; i++)
|
||||
{
|
||||
var serie = series.list[i];
|
||||
if (serie.type == currSerie.type && ChartHelper.IsValueEqualsString(serie.stack, currSerie.stack))
|
||||
{
|
||||
dataList.Add(serie.GetDataList(dataZoom));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得维度X的最大最小值
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得维度Y的最大最小值
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar);
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private static Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
|
||||
internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, bool yValue, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
float max = int.MinValue;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar);
|
||||
if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue))
|
||||
{
|
||||
for (int i = 0; i < series.list.Count; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
if ((isPolar && serie.polarIndex != axisIndex)
|
||||
|| (!isPolar && serie.yAxisIndex != axisIndex)) continue;
|
||||
if (series.IsActive(i))
|
||||
{
|
||||
if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
|
||||
{
|
||||
if (100 > max) max = 100;
|
||||
if (0 < min) min = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
var dataMin = data.min;
|
||||
var dataMax = data.max;
|
||||
if (dataMax > max) max = dataMax;
|
||||
if (dataMin < min) min = dataMin;
|
||||
}
|
||||
else
|
||||
{
|
||||
var currData = data.GetData(yValue ? 1 : 0, inverse);
|
||||
if (currData > max) max = currData;
|
||||
if (currData < min) min = currData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax);
|
||||
foreach (var ss in _stackSeriesForMinMax)
|
||||
{
|
||||
_serieTotalValueForMinMax.Clear();
|
||||
for (int i = 0; i < ss.Value.Count; i++)
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if ((isPolar && serie.polarIndex != axisIndex)
|
||||
|| (!isPolar && serie.yAxisIndex != axisIndex)
|
||||
|| !series.IsActive(i)) continue;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar))
|
||||
{
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
_serieTotalValueForMinMax[j] = 100;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
var currData = 0f;
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
currData = showData[j].max;
|
||||
}
|
||||
else
|
||||
{
|
||||
currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0);
|
||||
}
|
||||
if (inverse) currData = -currData;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
|
||||
}
|
||||
}
|
||||
}
|
||||
float tmax = int.MinValue;
|
||||
float tmin = int.MaxValue;
|
||||
foreach (var tt in _serieTotalValueForMinMax)
|
||||
{
|
||||
if (tt.Value > tmax) tmax = tt.Value;
|
||||
if (tt.Value < tmin) tmin = tt.Value;
|
||||
}
|
||||
if (tmax > max) max = tmax;
|
||||
if (tmin < min) min = tmin;
|
||||
}
|
||||
}
|
||||
if (max == int.MinValue && min == int.MaxValue)
|
||||
{
|
||||
minVaule = 0;
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minVaule = min > 1 ? Mathf.FloorToInt(min) : min;
|
||||
maxValue = max > 1 ? Mathf.CeilToInt(max) : max;
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetMaxSerieDataCount(Series series)
|
||||
{
|
||||
int max = 0;
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.dataCount > max) max = serie.dataCount;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7411a13172764cf89b10e643089c832
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,20 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class ThemeHelper
|
||||
{
|
||||
public static Color32 GetBackgroundColor(ChartTheme theme, Background background)
|
||||
{
|
||||
if (background.show && background.hideThemeBackgroundColor) return ChartConst.clearColor32;
|
||||
else return theme.backgroundColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5093880c2dbba4c01bb0231653ed3252
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,43 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class TitleStyleHelper
|
||||
{
|
||||
public static void CheckTitle(Serie serie, ref bool m_ReinitTitle, ref bool m_UpdateTitleText)
|
||||
{
|
||||
if (serie.titleStyle.show)
|
||||
{
|
||||
if (serie.titleStyle.IsInited())
|
||||
{
|
||||
serie.titleStyle.UpdatePosition(serie.runtimeCenterPos);
|
||||
m_UpdateTitleText = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ReinitTitle = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateTitleText(Series series)
|
||||
{
|
||||
foreach (var serie in series.list) UpdateTitleText(serie);
|
||||
}
|
||||
|
||||
public static void UpdateTitleText(Serie serie)
|
||||
{
|
||||
if (serie.titleStyle.show)
|
||||
{
|
||||
serie.titleStyle.SetText(serie.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35fa58aecc0f4414e8a2f03195b66175
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,577 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class TooltipHelper
|
||||
{
|
||||
private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme)
|
||||
{
|
||||
if (!tooltip.runtimeSerieIndex.ContainsKey(serie.index)) return;
|
||||
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
sb.Append(serie.name).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
for (int i = 0; i < dataIndexList.Count; i++)
|
||||
{
|
||||
var dataIndex = dataIndexList[i];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
sb.Append(serieData.name).Append(": ");
|
||||
sb.AppendFormat("({0},{1})", ChartCached.FloatToStr(xValue, numericFormatter),
|
||||
ChartCached.FloatToStr(yValue, numericFormatter));
|
||||
if (i != dataIndexList.Count - 1)
|
||||
{
|
||||
sb.Append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void InitPieTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme)
|
||||
{
|
||||
if (tooltip.runtimeDataIndex[serie.index] < 0) return;
|
||||
string key = serie.data[index].name;
|
||||
var serieData = serie.GetSerieData(index);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
|
||||
float value = serieData.GetData(1);
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
sb.Append(serie.name).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
sb.Append(key).Append(": ");
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
|
||||
private static void InitRingTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme)
|
||||
{
|
||||
var serieData = serie.GetSerieData(index);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float value = serieData.GetFirstData();
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
{
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>")
|
||||
.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
private static void InitGaugeTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme)
|
||||
{
|
||||
if (tooltip.runtimeGridIndex >= 0) return;
|
||||
if (serie.index != index || serie.type != SerieType.Gauge) return;
|
||||
var serieData = serie.GetSerieData(0);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float value = serieData.data[1];
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
sb.Append(serie.name).Append("\n");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
{
|
||||
//sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>")
|
||||
sb.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar,
|
||||
ChartTheme theme)
|
||||
{
|
||||
if (radar == null) return;
|
||||
if (!serie.show) return;
|
||||
if (tooltip.runtimeGridIndex >= 0) return;
|
||||
if (serie.radarIndex != radar.index) return;
|
||||
var dataIndex = tooltip.runtimeDataIndex[1];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
if (!serieData.show) return;
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
switch (serie.radarType)
|
||||
{
|
||||
case RadarType.Multiple:
|
||||
if (radar.isAxisTooltip)
|
||||
{
|
||||
var dimension = tooltip.runtimeDataIndex[2];
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
sb.Append(serie.name).Append("\n");
|
||||
var total = serie.GetDataTotal(dimension);
|
||||
var first = true;
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var sd = serie.GetSerieData(i);
|
||||
if (!sd.show) continue;
|
||||
var key = sd.name;
|
||||
var value = sd.GetData(dimension);
|
||||
var itemFormatter = GetItemFormatter(tooltip, serie, sd);
|
||||
numericFormatter = GetItemNumericFormatter(tooltip, serie, sd);
|
||||
if (!first) sb.Append("\n");
|
||||
first = false;
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(i)).Append(">● </color>");
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
if (string.IsNullOrEmpty(key)) key = radar.indicatorList[dataIndex].name;
|
||||
if (string.IsNullOrEmpty(key))
|
||||
sb.AppendFormat("{0}\n", ChartCached.FloatToStr(value, numericFormatter));
|
||||
else
|
||||
sb.AppendFormat("{0}: {1}\n", key, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
string content = itemFormatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, value, total, serie.name,
|
||||
sd.name, theme.GetColor(i));
|
||||
sb.Append(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (serie.index != tooltip.runtimeDataIndex[0]) return;
|
||||
sb.Append(serieData.name);
|
||||
for (int i = 0; i < radar.indicatorList.Count; i++)
|
||||
{
|
||||
string key = radar.indicatorList[i].name;
|
||||
float value = serieData.GetData(i);
|
||||
if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append(FormatterHelper.PH_NN);
|
||||
sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RadarType.Single:
|
||||
var key2 = serieData.name;
|
||||
var value2 = serieData.GetData(1);
|
||||
var total2 = serie.GetDataTotal(1);
|
||||
var itemFormatter2 = GetItemFormatter(tooltip, serie, serieData);
|
||||
if (string.IsNullOrEmpty(itemFormatter2))
|
||||
{
|
||||
if (string.IsNullOrEmpty(key2))
|
||||
{
|
||||
key2 = radar.indicatorList[dataIndex].name;
|
||||
}
|
||||
sb.AppendFormat("{0}: {1}", key2, ChartCached.FloatToStr(value2, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
string content = itemFormatter2;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, value2, total2, serie.name,
|
||||
serieData.name, theme.GetColor(serie.index));
|
||||
sb.Append(content);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme, bool isCartesian, DataZoom dataZoom = null)
|
||||
{
|
||||
string key = serie.name;
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(index, dataZoom, out xValue, out yValue);
|
||||
var isIngore = serie.IsIgnorePoint(index);
|
||||
var serieData = serie.GetSerieData(index, dataZoom);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
if (isCartesian)
|
||||
{
|
||||
if (serieData != null && serieData.highlighted)
|
||||
{
|
||||
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
|
||||
sb.Append("[").Append(ChartCached.FloatToStr(xValue, numericFormatter)).Append(",")
|
||||
.Append(ChartCached.FloatToStr(yValue, numericFormatter)).Append("]");
|
||||
}
|
||||
}
|
||||
else if (!isIngore || (isIngore && tooltip.ignoreDataShow))
|
||||
{
|
||||
var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
|
||||
ChartCached.FloatToStr(yValue, numericFormatter);
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
sb.Append(key).Append(FormatterHelper.PH_NN);
|
||||
var data = serieData.data;
|
||||
var open = ChartCached.FloatToStr(data[0], numericFormatter);
|
||||
var close = ChartCached.FloatToStr(data[1], numericFormatter);
|
||||
var lowest = ChartCached.FloatToStr(data[2], numericFormatter);
|
||||
var heighest = ChartCached.FloatToStr(data[3], numericFormatter);
|
||||
sb.Append(" open: ").Append(open).Append(FormatterHelper.PH_NN);
|
||||
sb.Append(" close: ").Append(close).Append(FormatterHelper.PH_NN);
|
||||
sb.Append(" lowest: ").Append(lowest).Append(FormatterHelper.PH_NN);
|
||||
sb.Append(" heighest: ").Append(heighest);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
|
||||
sb.Append(valueTxt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitGanttTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme)
|
||||
{
|
||||
//if (tooltip.runtimeGridIndex >= 0) return;
|
||||
//if (serie.index != index || serie.type != SerieType.Gantt) return;
|
||||
sb.Append(serie.name);
|
||||
}
|
||||
|
||||
private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme = null, DataZoom dataZoom = null, bool isCartesian = false,
|
||||
Radar radar = null)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Line:
|
||||
case SerieType.Bar:
|
||||
case SerieType.Candlestick:
|
||||
InitCoordinateTooltip(ref sb, tooltip, serie, index, theme, isCartesian, dataZoom);
|
||||
break;
|
||||
case SerieType.Scatter:
|
||||
case SerieType.EffectScatter:
|
||||
InitScatterTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
case SerieType.Radar:
|
||||
InitRadarTooltip(ref sb, tooltip, serie, radar, theme);
|
||||
break;
|
||||
case SerieType.Pie:
|
||||
InitPieTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
case SerieType.Ring:
|
||||
InitRingTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
case SerieType.Heatmap:
|
||||
break;
|
||||
case SerieType.Gauge:
|
||||
InitGaugeTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
case SerieType.Gantt:
|
||||
InitGanttTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetContentAndPosition(Tooltip tooltip, string content, Rect chartRect)
|
||||
{
|
||||
tooltip.UpdateContentText(content);
|
||||
var pos = tooltip.GetContentPos();
|
||||
if (pos.x + tooltip.runtimeWidth > chartRect.x + chartRect.width)
|
||||
{
|
||||
pos.x = chartRect.x + chartRect.width - tooltip.runtimeWidth;
|
||||
}
|
||||
if (pos.y - tooltip.runtimeHeight < chartRect.y)
|
||||
{
|
||||
pos.y = chartRect.y + tooltip.runtimeHeight;
|
||||
}
|
||||
tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
|
||||
public static string GetPolarFormatterContent(Tooltip tooltip, BaseChart chart, AngleAxis angleAxis)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tooltip.formatter))
|
||||
{
|
||||
var sb = ChartHelper.sb;
|
||||
sb.Length = 0;
|
||||
var title = tooltip.titleFormatter;
|
||||
var formatTitle = !string.IsNullOrEmpty(title);
|
||||
if ("{i}".Equals(tooltip.titleFormatter))
|
||||
{
|
||||
title = string.Empty;
|
||||
formatTitle = false;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
var angle = angleAxis.clockwise ? tooltip.runtimeAngle : 360 - tooltip.runtimeAngle;
|
||||
title = ChartCached.FloatToStr(angle);
|
||||
}
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
if (serie.show && IsSelectedSerie(tooltip, serie.index))
|
||||
{
|
||||
if (formatTitle)
|
||||
{
|
||||
FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, chart, null);
|
||||
}
|
||||
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
|
||||
|
||||
for (int i = 0; i < dataIndexList.Count; i++)
|
||||
{
|
||||
var dataIndex = dataIndexList[i];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
sb.Append("<color=#").Append(chart.theme.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
sb.Append(serie.name).Append(": ");
|
||||
sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
|
||||
if (i != dataIndexList.Count - 1)
|
||||
{
|
||||
sb.Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string content = itemFormatter;
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, chart, null);
|
||||
var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar
|
||||
|| serie.type == SerieType.Ring ? dataIndex : serie.index;
|
||||
sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(dotColorIndex)));
|
||||
sb.Append(content);
|
||||
}
|
||||
}
|
||||
sb.Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
return FormatterHelper.TrimAndReplaceLine(sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
title = FormatterHelper.TrimAndReplaceLine(title);
|
||||
return title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string content = tooltip.formatter;
|
||||
FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, chart, null);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, BaseChart chart, DataZoom dataZoom = null,
|
||||
bool isCartesian = false, Radar radar = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tooltip.formatter))
|
||||
{
|
||||
var sb = ChartHelper.sb;
|
||||
var title = tooltip.titleFormatter;
|
||||
var formatTitle = !string.IsNullOrEmpty(title);
|
||||
var titleIsIgnroe = false;
|
||||
var needCategory = false;
|
||||
var first = true;
|
||||
var isScatter = false;
|
||||
sb.Length = 0;
|
||||
if ("{i}".Equals(tooltip.titleFormatter))
|
||||
{
|
||||
title = string.Empty;
|
||||
formatTitle = false;
|
||||
titleIsIgnroe = true;
|
||||
}
|
||||
for (int i = 0; i < chart.series.Count; i++)
|
||||
{
|
||||
var serie = chart.series.GetSerie(i);
|
||||
if (tooltip.runtimeGridIndex >= 0 && serie.runtimeGridIndex != tooltip.runtimeGridIndex) continue;
|
||||
if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
|
||||
{
|
||||
if (serie.show && IsSelectedSerie(tooltip, serie.index))
|
||||
{
|
||||
isScatter = true;
|
||||
var itemFormatter = GetItemFormatter(tooltip, serie, null);
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
if (!first) sb.Append(FormatterHelper.PH_NN);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, chart.theme, dataZoom, isCartesian, radar);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
var itemTitle = title;
|
||||
if (!string.IsNullOrEmpty(itemTitle))
|
||||
{
|
||||
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, chart, dataZoom);
|
||||
sb.Append(itemTitle).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
|
||||
foreach (var tempIndex in dataIndexList)
|
||||
{
|
||||
string content = itemFormatter;
|
||||
var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, chart, dataZoom);
|
||||
if (!foundDot)
|
||||
{
|
||||
sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(serie.index)));
|
||||
}
|
||||
sb.Append(content).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (IsNeedTooltipSerie(serie, tooltip))
|
||||
{
|
||||
var itemFormatter = string.Empty;
|
||||
if (serie.type == SerieType.Gauge)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0, dataZoom);
|
||||
if (serieData == null) continue;
|
||||
itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
}
|
||||
else
|
||||
{
|
||||
var serieData = serie.GetSerieData(dataIndex, dataZoom);
|
||||
if (serieData == null) continue;
|
||||
itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
}
|
||||
needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
|
||||
if (formatTitle)
|
||||
{
|
||||
FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, chart, dataZoom);
|
||||
}
|
||||
if (serie.show)
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemFormatter) || serie.type == SerieType.Radar)
|
||||
{
|
||||
if (!first) sb.Append(FormatterHelper.PH_NN);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, chart.theme, dataZoom, isCartesian, radar);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
string content = itemFormatter;
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, chart, dataZoom);
|
||||
if (!first) sb.Append(FormatterHelper.PH_NN);
|
||||
var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar
|
||||
|| serie.type == SerieType.Ring ? dataIndex : i;
|
||||
sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(dotColorIndex)));
|
||||
sb.Append(content);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isScatter)
|
||||
{
|
||||
return FormatterHelper.TrimAndReplaceLine(sb);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
if (needCategory && !titleIsIgnroe)
|
||||
{
|
||||
var category = (chart as CoordinateChart).GetTooltipCategory(dataIndex, dataZoom);
|
||||
return category + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb);
|
||||
}
|
||||
else
|
||||
return FormatterHelper.TrimAndReplaceLine(sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
title = FormatterHelper.TrimAndReplaceLine(title);
|
||||
return title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string content = tooltip.formatter;
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, chart, dataZoom);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsNeedTooltipSerie(Serie serie, Tooltip tooltip)
|
||||
{
|
||||
//if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring)
|
||||
if (serie.type == SerieType.Pie || serie.type == SerieType.Ring)
|
||||
{
|
||||
if (serie.index < tooltip.runtimeDataIndex.Count)
|
||||
return tooltip.runtimeDataIndex[serie.index] >= 0;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (serie.type == SerieType.Gauge)
|
||||
{
|
||||
return serie.index == tooltip.runtimeDataIndex[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsSelectedSerie(Tooltip tooltip, int serieIndex)
|
||||
{
|
||||
if (tooltip.runtimeSerieIndex.ContainsKey(serieIndex))
|
||||
{
|
||||
return tooltip.runtimeSerieIndex[serieIndex].Count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string GetItemFormatter(Tooltip tooltip, Serie serie, SerieData serieData)
|
||||
{
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
|
||||
if (!string.IsNullOrEmpty(itemStyle.tooltipFormatter)) return itemStyle.tooltipFormatter;
|
||||
else return tooltip.itemFormatter;
|
||||
}
|
||||
|
||||
private static string GetItemNumericFormatter(Tooltip tooltip, Serie serie, SerieData serieData)
|
||||
{
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
|
||||
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
|
||||
else return tooltip.numericFormatter;
|
||||
}
|
||||
|
||||
public static Color32 GetLineColor(Tooltip tooltip, ChartTheme theme)
|
||||
{
|
||||
var lineStyle = tooltip.lineStyle;
|
||||
if (!ChartHelper.IsClearColor(lineStyle.color))
|
||||
{
|
||||
return lineStyle.GetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = theme.tooltip.lineColor;
|
||||
ChartHelper.SetColorOpacity(ref color, lineStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetTexColor(Tooltip tooltip, ComponentTheme theme)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(tooltip.textStyle.color))
|
||||
{
|
||||
return tooltip.textStyle.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return theme.textColor;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetTexBackgroundColor(Tooltip tooltip, ComponentTheme theme)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(tooltip.textStyle.backgroundColor))
|
||||
{
|
||||
return tooltip.textStyle.backgroundColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return theme.textBackgroundColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0fa1b19683a8424bb335802de5c9726
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,7 +12,7 @@ namespace XCharts
|
||||
{
|
||||
public static class VesselHelper
|
||||
{
|
||||
internal static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName)
|
||||
public static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName)
|
||||
{
|
||||
if (serie != null && vessel.autoColor)
|
||||
{
|
||||
@@ -25,7 +25,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdateVesselCenter(Vessel vessel, Vector3 chartPosition, float chartWidth, float chartHeight)
|
||||
public static void UpdateVesselCenter(Vessel vessel, Vector3 chartPosition, float chartWidth, float chartHeight)
|
||||
{
|
||||
if (vessel.center.Length < 2) return;
|
||||
var centerX = vessel.center[0] <= 1 ? chartWidth * vessel.center[0] : vessel.center[0];
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class VisualMapHelper
|
||||
{
|
||||
public static void AutoSetLineMinMax(VisualMap visualMap, Serie serie, XAxis xAxis, YAxis yAxis)
|
||||
{
|
||||
if (!IsNeedGradient(visualMap) || !visualMap.autoMinMax) return;
|
||||
float min = 0;
|
||||
float max = 0;
|
||||
switch (visualMap.direction)
|
||||
{
|
||||
case VisualMap.Direction.Default:
|
||||
case VisualMap.Direction.X:
|
||||
min = xAxis.IsCategory() ? 0 : xAxis.runtimeMinValue;
|
||||
max = xAxis.IsCategory() ? serie.dataCount : xAxis.runtimeMaxValue;
|
||||
SetMinMax(visualMap, min, max);
|
||||
break;
|
||||
case VisualMap.Direction.Y:
|
||||
min = yAxis.IsCategory() ? 0 : yAxis.runtimeMinValue;
|
||||
max = yAxis.IsCategory() ? serie.dataCount : yAxis.runtimeMaxValue;
|
||||
SetMinMax(visualMap, min, max);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetMinMax(VisualMap visualMap, float min, float max)
|
||||
{
|
||||
if (visualMap.enable && (visualMap.min != min || visualMap.max != max))
|
||||
{
|
||||
if (max >= min)
|
||||
{
|
||||
visualMap.min = min;
|
||||
visualMap.max = max;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("SetMinMax:max < min:" + min + "," + max);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetLineGradientColor(VisualMap visualMap, float xValue, float yValue,
|
||||
out Color32 startColor, out Color32 toColor)
|
||||
{
|
||||
startColor = ChartConst.clearColor32;
|
||||
toColor = ChartConst.clearColor32;
|
||||
switch (visualMap.direction)
|
||||
{
|
||||
case VisualMap.Direction.Default:
|
||||
case VisualMap.Direction.X:
|
||||
startColor = visualMap.IsPiecewise() ? visualMap.GetColor(xValue) : visualMap.GetColor(xValue - 1);
|
||||
toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(xValue);
|
||||
break;
|
||||
case VisualMap.Direction.Y:
|
||||
startColor = visualMap.IsPiecewise() ? visualMap.GetColor(yValue) : visualMap.GetColor(yValue - 1);
|
||||
toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(yValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
|
||||
{
|
||||
float value = 0;
|
||||
switch (visualMap.direction)
|
||||
{
|
||||
case VisualMap.Direction.Default:
|
||||
case VisualMap.Direction.X:
|
||||
var min = axis.runtimeMinValue;
|
||||
var max = axis.runtimeMaxValue;
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
break;
|
||||
case VisualMap.Direction.Y:
|
||||
if (axis is YAxis)
|
||||
{
|
||||
var yAxis = chart.xAxes[axis.index];
|
||||
min = yAxis.runtimeMinValue;
|
||||
max = yAxis.runtimeMaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = chart.yAxes[axis.index];
|
||||
min = yAxis.runtimeMinValue;
|
||||
max = yAxis.runtimeMaxValue;
|
||||
}
|
||||
grid = chart.GetAxisGridOrDefault(axis);
|
||||
value = min + (pos.y - grid.runtimeY) / grid.runtimeHeight * (max - min);
|
||||
break;
|
||||
}
|
||||
var color = visualMap.GetColor(value);
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
else return color;
|
||||
}
|
||||
|
||||
internal static Color32 GetItemStyleGradientColor(ItemStyle itemStyle, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
|
||||
{
|
||||
var min = axis.runtimeMinValue;
|
||||
var max = axis.runtimeMaxValue;
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
var rate = (value - min) / (max - min);
|
||||
var color = itemStyle.GetGradientColor(rate, defaultColor);
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
else return color;
|
||||
}
|
||||
|
||||
internal static Color32 GetLineStyleGradientColor(LineStyle lineStyle, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
|
||||
{
|
||||
var min = axis.runtimeMinValue;
|
||||
var max = axis.runtimeMaxValue;
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
var rate = (value - min) / (max - min);
|
||||
var color = lineStyle.GetGradientColor(rate, defaultColor);
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
else return color;
|
||||
}
|
||||
|
||||
public static bool IsNeedGradient(VisualMap visualMap)
|
||||
{
|
||||
if (!visualMap.enable || visualMap.inRange.Count <= 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int GetDimension(VisualMap visualMap, int serieDataCount)
|
||||
{
|
||||
var dimension = visualMap.enable && visualMap.dimension >= 0 ? visualMap.dimension : serieDataCount - 1;
|
||||
if (dimension > serieDataCount - 1) dimension = serieDataCount - 1;
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15e5106bd46f5484596429d512f6af5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user