UI update 02
This commit is contained in:
@@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ChartCached
|
||||
{
|
||||
private const string NUMERIC_FORMATTER_D = "D";
|
||||
private const string NUMERIC_FORMATTER_d = "d";
|
||||
private const string NUMERIC_FORMATTER_X = "X";
|
||||
private const string NUMERIC_FORMATTER_x = "x";
|
||||
private static readonly string s_DefaultAxis = "axis_";
|
||||
private static CultureInfo ci = GetDefaultCultureInfo(); // "en-us", "zh-cn", "ar-iq", "de-de"
|
||||
private static Dictionary<Color, string> s_ColorToStr = new Dictionary<Color, string>(100);
|
||||
private static Dictionary<int, string> s_SerieLabelName = new Dictionary<int, string>(1000);
|
||||
private static Dictionary<Color, string> s_ColorDotStr = new Dictionary<Color, string>(100);
|
||||
private static Dictionary<Type, Dictionary<int, string>> s_ComponentObjectName = new Dictionary<Type, Dictionary<int, string>>();
|
||||
private static Dictionary<int, string> s_AxisLabelName = new Dictionary<int, string>();
|
||||
private static Dictionary<Type, string> s_TypeName = new Dictionary<Type, string>();
|
||||
|
||||
private static Dictionary<double, Dictionary<string, string>> s_NumberToStr = new Dictionary<double, Dictionary<string, string>>();
|
||||
private static Dictionary<int, Dictionary<string, string>> s_PrecisionToStr = new Dictionary<int, Dictionary<string, string>>();
|
||||
private static Dictionary<string, Dictionary<int, string>> s_StringIntDict = new Dictionary<string, Dictionary<int, string>>();
|
||||
private static Dictionary<double, DateTime> s_TimestampToDateTimeDict = new Dictionary<double, DateTime>();
|
||||
private static Dictionary<double, TimeSpan> s_NumberToTimeSpanDict = new Dictionary<double, TimeSpan>();
|
||||
|
||||
private static CultureInfo GetDefaultCultureInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new CultureInfo("en-us");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return CultureInfo.InvariantCulture;
|
||||
}
|
||||
}
|
||||
|
||||
public static string FloatToStr(double value, string numericFormatter = "F", int precision = 0)
|
||||
{
|
||||
if (precision > 0 && numericFormatter.Length == 1)
|
||||
{
|
||||
if (!s_PrecisionToStr.ContainsKey(precision))
|
||||
{
|
||||
s_PrecisionToStr[precision] = new Dictionary<string, string>();
|
||||
}
|
||||
if (!s_PrecisionToStr[precision].ContainsKey(numericFormatter))
|
||||
{
|
||||
s_PrecisionToStr[precision][numericFormatter] = numericFormatter + precision;
|
||||
}
|
||||
return NumberToStr(value, s_PrecisionToStr[precision][numericFormatter]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NumberToStr(value, numericFormatter);
|
||||
}
|
||||
}
|
||||
|
||||
public static string NumberToStr(double value, string formatter)
|
||||
{
|
||||
if (!s_NumberToStr.ContainsKey(value))
|
||||
{
|
||||
s_NumberToStr[value] = new Dictionary<string, string>();
|
||||
}
|
||||
if (!s_NumberToStr[value].ContainsKey(formatter))
|
||||
{
|
||||
bool isDateFormatter = false;
|
||||
string newFormatter = null;
|
||||
if (string.IsNullOrEmpty(formatter))
|
||||
{
|
||||
s_NumberToStr[value][formatter] = value.ToString();
|
||||
}
|
||||
else if (DateTimeUtil.IsDateOrTimeRegex(formatter,ref isDateFormatter, ref newFormatter))
|
||||
{
|
||||
if(isDateFormatter)
|
||||
s_NumberToStr[value][formatter] = NumberToDateStr(value, newFormatter);
|
||||
else
|
||||
s_NumberToStr[value][formatter] = NumberToTimeStr(value, newFormatter);
|
||||
}
|
||||
else if (formatter.StartsWith(NUMERIC_FORMATTER_D) ||
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_d) ||
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_X) ||
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_x)
|
||||
)
|
||||
{
|
||||
s_NumberToStr[value][formatter] = ((int)value).ToString(formatter, ci);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_NumberToStr[value][formatter] = value.ToString(formatter, ci);
|
||||
}
|
||||
}
|
||||
return s_NumberToStr[value][formatter];
|
||||
}
|
||||
|
||||
public static string IntToStr(int value, string numericFormatter = "")
|
||||
{
|
||||
return NumberToStr(value, numericFormatter);
|
||||
}
|
||||
|
||||
public static string NumberToDateStr(double timestamp, string formatter, bool local = false)
|
||||
{
|
||||
var dt = NumberToDateTime(timestamp, local);
|
||||
try
|
||||
{
|
||||
return dt.ToString(formatter, ci);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
XLog.LogError("Not support DateTime format: " + formatter);
|
||||
return timestamp.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static string NumberToTimeStr(double timestamp, string formatter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ts = NumberToTimeSpan(timestamp);
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
return ts.ToString(formatter, ci);
|
||||
#else
|
||||
return ts.ToString();
|
||||
#endif
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
XLog.LogError("Not support TimeSpan format: " + formatter);
|
||||
return timestamp.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime NumberToDateTime(double timestamp, bool local = false)
|
||||
{
|
||||
if (!s_TimestampToDateTimeDict.ContainsKey(timestamp))
|
||||
{
|
||||
s_TimestampToDateTimeDict[timestamp] = DateTimeUtil.GetDateTime(timestamp, local);
|
||||
}
|
||||
return s_TimestampToDateTimeDict[timestamp];
|
||||
}
|
||||
|
||||
public static TimeSpan NumberToTimeSpan(double timestamp)
|
||||
{
|
||||
if(!s_NumberToTimeSpanDict.ContainsKey(timestamp))
|
||||
{
|
||||
s_NumberToTimeSpanDict[timestamp] = TimeSpan.FromSeconds(timestamp);
|
||||
}
|
||||
return s_NumberToTimeSpanDict[timestamp];
|
||||
}
|
||||
|
||||
public static string ColorToStr(Color color)
|
||||
{
|
||||
if (s_ColorToStr.ContainsKey(color))
|
||||
{
|
||||
return s_ColorToStr[color];
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ColorToStr[color] = ColorUtility.ToHtmlStringRGBA(color);
|
||||
return s_ColorToStr[color];
|
||||
}
|
||||
}
|
||||
|
||||
public static string ColorToDotStr(Color color)
|
||||
{
|
||||
if (!s_ColorDotStr.ContainsKey(color))
|
||||
{
|
||||
s_ColorDotStr[color] = "<color=#" + ColorToStr(color) + ">●</color>";
|
||||
}
|
||||
return s_ColorDotStr[color];
|
||||
}
|
||||
|
||||
public static string GetSerieLabelName(string prefix, int i, int j)
|
||||
{
|
||||
int key = i * 10000000 + j;
|
||||
if (s_SerieLabelName.ContainsKey(key))
|
||||
{
|
||||
return s_SerieLabelName[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
string name = prefix + "_" + i + "_" + j;
|
||||
s_SerieLabelName[key] = name;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetString(string prefix, int suffix)
|
||||
{
|
||||
if (!s_StringIntDict.ContainsKey(prefix))
|
||||
{
|
||||
s_StringIntDict[prefix] = new Dictionary<int, string>();
|
||||
}
|
||||
if (!s_StringIntDict[prefix].ContainsKey(suffix))
|
||||
{
|
||||
s_StringIntDict[prefix][suffix] = prefix + suffix;
|
||||
}
|
||||
return s_StringIntDict[prefix][suffix];
|
||||
}
|
||||
|
||||
public static string GetComponentObjectName(MainComponent component)
|
||||
{
|
||||
Dictionary<int, string> dict;
|
||||
var type = component.GetType();
|
||||
if (s_ComponentObjectName.TryGetValue(type, out dict))
|
||||
{
|
||||
string name;
|
||||
if (!dict.TryGetValue(component.index, out name))
|
||||
{
|
||||
name = GetTypeName(type) + component.index;
|
||||
dict[component.index] = name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = GetTypeName(type) + component.index;
|
||||
dict = new Dictionary<int, string>();
|
||||
dict.Add(component.index, name);
|
||||
s_ComponentObjectName[type] = dict;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetAxisLabelName(int index)
|
||||
{
|
||||
string name;
|
||||
if (!s_AxisLabelName.TryGetValue(index, out name))
|
||||
{
|
||||
name = s_DefaultAxis + index;
|
||||
s_AxisLabelName[index] = name;
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetTypeName<T>()
|
||||
{
|
||||
return GetTypeName(typeof(T));
|
||||
}
|
||||
|
||||
public static string GetTypeName(Type type)
|
||||
{
|
||||
if (s_TypeName.ContainsKey(type)) return s_TypeName[type];
|
||||
else
|
||||
{
|
||||
var name = type.Name;
|
||||
s_TypeName[type] = name;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 403191b8caeb44430b89d9f3260c4a76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ChartConst
|
||||
{
|
||||
public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0);
|
||||
public static readonly Color32 greyColor32 = new Color32(128, 128, 128, 255);
|
||||
public static readonly Color clearColor = Color.clear;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e19d8fc0680be46b5ac9babf7dd9fe27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,215 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ChartDrawer
|
||||
{
|
||||
public static void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness,
|
||||
Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
|
||||
Color32 emptyColor, Color32 backgroundColor, Color32 borderColor, float smoothness,
|
||||
Vector3 startPos, float symbolSize2 = 0f)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SymbolType.None:
|
||||
break;
|
||||
case SymbolType.Circle:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tickness > 0 && !ChartHelper.IsClearColor(borderColor))
|
||||
UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + tickness, borderColor, borderColor, color, smoothness);
|
||||
else
|
||||
UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
|
||||
}
|
||||
break;
|
||||
case SymbolType.EmptyCircle:
|
||||
if (tickness == 0) tickness = 4f;
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Rect:
|
||||
if (symbolSize2 > 0 && symbolSize2 != symbolSize)
|
||||
{
|
||||
UGL.DrawRectangle(vh, pos, symbolSize, symbolSize2, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawSquare(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tickness > 0)
|
||||
{
|
||||
UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true);
|
||||
UGL.DrawBorder(vh, pos, symbolSize, symbolSize, tickness, borderColor, 0, cornerRadius);
|
||||
}
|
||||
else
|
||||
UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SymbolType.EmptyRect:
|
||||
if (tickness == 0) tickness = 4f;
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawBorder(vh, pos, symbolSize * 2, symbolSize * 2, tickness, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawBorder(vh, pos, symbolSize * 2 - tickness * 2, symbolSize * 2 - tickness * 2, tickness, color);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Triangle:
|
||||
case SymbolType.EmptyTriangle:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawEmptyTriangle(vh, pos, symbolSize * 1.4f + gap * 2, gap * 2, backgroundColor);
|
||||
}
|
||||
if (type == SymbolType.EmptyTriangle)
|
||||
{
|
||||
if (tickness == 0) tickness = 4f;
|
||||
UGL.DrawEmptyTriangle(vh, pos, symbolSize * 1.4f, tickness * 2f, color, emptyColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawTriangle(vh, pos, symbolSize * 1.4f, color, toColor);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Diamond:
|
||||
case SymbolType.EmptyDiamond:
|
||||
var xRadius = symbolSize;
|
||||
var yRadius = symbolSize * 1.5f;
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawEmptyDiamond(vh, pos, xRadius + gap, yRadius + gap, gap, backgroundColor);
|
||||
}
|
||||
if (type == SymbolType.EmptyDiamond)
|
||||
{
|
||||
if (tickness == 0) tickness = 4f;
|
||||
UGL.DrawEmptyDiamond(vh, pos, xRadius, yRadius, tickness, color, emptyColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawDiamond(vh, pos, xRadius, yRadius, color, toColor);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Arrow:
|
||||
case SymbolType.EmptyArrow:
|
||||
var arrowWidth = symbolSize * 2;
|
||||
var arrowHeight = arrowWidth * 1.5f;
|
||||
var arrowOffset = 0;
|
||||
var arrowDent = arrowWidth / 3.3f;
|
||||
if (gap > 0)
|
||||
{
|
||||
arrowWidth = (symbolSize + gap) * 2;
|
||||
arrowHeight = arrowWidth * 1.5f;
|
||||
arrowOffset = 0;
|
||||
arrowDent = arrowWidth / 3.3f;
|
||||
var dir = (pos - startPos).normalized;
|
||||
var sharpPos = pos + gap * dir;
|
||||
UGL.DrawArrow(vh, startPos, sharpPos, arrowWidth, arrowHeight,
|
||||
arrowOffset, arrowDent, backgroundColor);
|
||||
}
|
||||
arrowWidth = symbolSize * 2;
|
||||
arrowHeight = arrowWidth * 1.5f;
|
||||
arrowOffset = 0;
|
||||
arrowDent = arrowWidth / 3.3f;
|
||||
UGL.DrawArrow(vh, startPos, pos, arrowWidth, arrowHeight,
|
||||
arrowOffset, arrowDent, color);
|
||||
if (type == SymbolType.EmptyArrow)
|
||||
{
|
||||
if (tickness == 0) tickness = 4f;
|
||||
arrowWidth = (symbolSize - tickness) * 2;
|
||||
arrowHeight = arrowWidth * 1.5f;
|
||||
arrowOffset = 0;
|
||||
arrowDent = arrowWidth / 3.3f;
|
||||
var dir = (pos - startPos).normalized;
|
||||
var sharpPos = pos - tickness * dir;
|
||||
UGL.DrawArrow(vh, startPos, sharpPos, arrowWidth, arrowHeight,
|
||||
arrowOffset, arrowDent, backgroundColor);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Plus:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawPlus(vh, pos, symbolSize + gap, tickness + gap, backgroundColor);
|
||||
}
|
||||
UGL.DrawPlus(vh, pos, symbolSize, tickness, color);
|
||||
break;
|
||||
case SymbolType.Minus:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawMinus(vh, pos, symbolSize + gap, tickness + gap, backgroundColor);
|
||||
}
|
||||
UGL.DrawMinus(vh, pos, symbolSize, tickness, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
|
||||
Color32 defaultColor, float themeWidth, LineStyle.Type themeType)
|
||||
{
|
||||
var type = lineStyle.GetType(themeType);
|
||||
var width = lineStyle.GetWidth(themeWidth);
|
||||
var color = lineStyle.GetColor(defaultColor);
|
||||
DrawLineStyle(vh, type, width, startPos, endPos, color, color);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
|
||||
float themeWidth, LineStyle.Type themeType, Color32 defaultColor, Color32 defaultToColor)
|
||||
{
|
||||
var type = lineStyle.GetType(themeType);
|
||||
var width = lineStyle.GetWidth(themeWidth);
|
||||
var color = lineStyle.GetColor(defaultColor);
|
||||
var toColor = ChartHelper.IsClearColor(defaultToColor) ? color : defaultToColor;
|
||||
DrawLineStyle(vh, type, width, startPos, endPos, color, toColor);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
|
||||
Vector3 startPos, Vector3 endPos, Color32 color)
|
||||
{
|
||||
DrawLineStyle(vh, lineType, lineWidth, startPos, endPos, color, color);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
|
||||
Vector3 startPos, Vector3 endPos, Color32 color, Color32 toColor)
|
||||
{
|
||||
switch (lineType)
|
||||
{
|
||||
case LineStyle.Type.Dashed:
|
||||
UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.Dotted:
|
||||
UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.Solid:
|
||||
UGL.DrawLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.DashDot:
|
||||
UGL.DrawDashDotLine(vh, startPos, endPos, lineWidth, color);
|
||||
break;
|
||||
case LineStyle.Type.DashDotDot:
|
||||
UGL.DrawDashDotDotLine(vh, startPos, endPos, lineWidth, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 712f08d71f1bf4ab6a1785526bcd5c30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47cfa7bd879be4069bd187e46346d73d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ComponentHelper
|
||||
{
|
||||
public static AngleAxis GetAngleAxis(List<MainComponent> components, int polarIndex)
|
||||
{
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is AngleAxis)
|
||||
{
|
||||
var axis = component as AngleAxis;
|
||||
if (axis.polarIndex == polarIndex) return axis;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RadiusAxis GetRadiusAxis(List<MainComponent> components, int polarIndex)
|
||||
{
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is RadiusAxis)
|
||||
{
|
||||
var axis = component as RadiusAxis;
|
||||
if (axis.polarIndex == polarIndex) return axis;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static float GetXAxisOnZeroOffset(List<MainComponent> components, XAxis axis)
|
||||
{
|
||||
if (!axis.axisLine.onZero) return 0;
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is YAxis)
|
||||
{
|
||||
var yAxis = component as YAxis;
|
||||
if (yAxis.IsValue() && yAxis.gridIndex == axis.gridIndex) return yAxis.context.offset;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static float GetYAxisOnZeroOffset(List<MainComponent> components, YAxis axis)
|
||||
{
|
||||
if (!axis.axisLine.onZero) return 0;
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is XAxis)
|
||||
{
|
||||
var xAxis = component as XAxis;
|
||||
if (xAxis.IsValue() && xAxis.gridIndex == axis.gridIndex) return xAxis.context.offset;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static bool IsAnyCategoryOfYAxis(List<MainComponent> components)
|
||||
{
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is YAxis)
|
||||
{
|
||||
var yAxis = component as YAxis;
|
||||
if (yAxis.type == Axis.AxisType.Category)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b7af706293fe4e63b4d079dbe5c0ea2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class DataHelper
|
||||
{
|
||||
public static double DataAverage(ref List<SerieData> showData, SampleType sampleType,
|
||||
int minCount, int maxCount, int rate)
|
||||
{
|
||||
double totalAverage = 0;
|
||||
if (rate > 1 && sampleType == SampleType.Peak)
|
||||
{
|
||||
double total = 0;
|
||||
for (int i = minCount; i < maxCount; i++)
|
||||
{
|
||||
total += showData[i].data[1];
|
||||
}
|
||||
totalAverage = total / (maxCount - minCount);
|
||||
}
|
||||
return totalAverage;
|
||||
}
|
||||
|
||||
public static double SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
|
||||
int minCount, int maxCount, double totalAverage, int index, float dataAddDuration, float dataChangeDuration,
|
||||
ref bool dataChanging, Axis axis, bool unscaledTime)
|
||||
{
|
||||
var inverse = axis.inverse;
|
||||
var minValue = 0;
|
||||
var maxValue = 0;
|
||||
if (rate <= 1 || index == minCount)
|
||||
{
|
||||
if (showData[index].IsDataChanged())
|
||||
dataChanging = true;
|
||||
|
||||
return showData[index].GetCurrData(1, dataAddDuration, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
|
||||
}
|
||||
switch (sampleType)
|
||||
{
|
||||
case SampleType.Sum:
|
||||
case SampleType.Average:
|
||||
double total = 0;
|
||||
var count = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
count++;
|
||||
total += showData[i].GetCurrData(1, dataAddDuration, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
if (sampleType == SampleType.Average)
|
||||
return total / rate;
|
||||
else
|
||||
return total;
|
||||
|
||||
case SampleType.Max:
|
||||
double max = double.MinValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataAddDuration, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
|
||||
if (value > max)
|
||||
max = value;
|
||||
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
return max;
|
||||
|
||||
case SampleType.Min:
|
||||
double min = double.MaxValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataAddDuration, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
|
||||
if (value < min)
|
||||
min = value;
|
||||
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
return min;
|
||||
|
||||
case SampleType.Peak:
|
||||
max = double.MinValue;
|
||||
min = double.MaxValue;
|
||||
total = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataAddDuration, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
|
||||
total += value;
|
||||
if (value < min)
|
||||
min = value;
|
||||
if (value > max)
|
||||
max = value;
|
||||
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
var average = total / rate;
|
||||
if (average >= totalAverage)
|
||||
return max;
|
||||
else
|
||||
return min;
|
||||
}
|
||||
if (showData[index].IsDataChanged())
|
||||
dataChanging = true;
|
||||
|
||||
return showData[index].GetCurrData(1, dataAddDuration, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c982f1be15b204c9190197803101f2db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,111 @@
|
||||
#if INPUT_SYSTEM_ENABLED
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.LowLevel;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class InputHelper
|
||||
{
|
||||
public static Vector2 mousePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
var value = Vector2.zero;
|
||||
if (null != Mouse.current)
|
||||
{
|
||||
value = Mouse.current.position.ReadValue();
|
||||
}
|
||||
else if (null != Touchscreen.current && Touchscreen.current.touches.Count > 0)
|
||||
{
|
||||
value = Touchscreen.current.touches[0].position.ReadValue();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
public static int touchCount
|
||||
{
|
||||
get
|
||||
{
|
||||
var value = 0;
|
||||
if (null != Touchscreen.current)
|
||||
{
|
||||
value = Touchscreen.current.touches.Count;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Touch GetTouch(int v)
|
||||
{
|
||||
UnityEngine.TouchPhase PhaseConvert(TouchState state)
|
||||
{
|
||||
UnityEngine.TouchPhase temp = UnityEngine.TouchPhase.Began;
|
||||
switch (state.phase)
|
||||
{
|
||||
case UnityEngine.InputSystem.TouchPhase.Began:
|
||||
temp = UnityEngine.TouchPhase.Began;
|
||||
break;
|
||||
case UnityEngine.InputSystem.TouchPhase.Moved:
|
||||
temp = UnityEngine.TouchPhase.Moved;
|
||||
break;
|
||||
case UnityEngine.InputSystem.TouchPhase.Canceled:
|
||||
temp = UnityEngine.TouchPhase.Canceled;
|
||||
break;
|
||||
case UnityEngine.InputSystem.TouchPhase.Stationary:
|
||||
temp = UnityEngine.TouchPhase.Stationary;
|
||||
break;
|
||||
default:
|
||||
case UnityEngine.InputSystem.TouchPhase.Ended:
|
||||
case UnityEngine.InputSystem.TouchPhase.None:
|
||||
temp = UnityEngine.TouchPhase.Ended;
|
||||
break;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
var touch = Touchscreen.current.touches[v];
|
||||
var value = touch.ReadValue();
|
||||
//copy touchcontrol's touchstate data into touch
|
||||
return new Touch
|
||||
{
|
||||
deltaPosition = value.delta,
|
||||
fingerId = value.touchId,
|
||||
position = value.position,
|
||||
phase = PhaseConvert(value),
|
||||
pressure = value.pressure,
|
||||
radius = value.radius.magnitude,
|
||||
radiusVariance = value.radius.sqrMagnitude,
|
||||
type = value.isPrimaryTouch ? TouchType.Direct : TouchType.Indirect,
|
||||
tapCount = value.tapCount,
|
||||
deltaTime = Time.realtimeSinceStartup - (float)value.startTime,
|
||||
rawPosition = value.startPosition,
|
||||
};
|
||||
}
|
||||
|
||||
public static bool GetKeyDown(KeyCode keyCode)
|
||||
{
|
||||
var value = false;
|
||||
if (null != Keyboard.current)
|
||||
{
|
||||
var key = Keyboard.current.spaceKey;
|
||||
switch (keyCode)
|
||||
{
|
||||
case KeyCode.Space:
|
||||
key = Keyboard.current.spaceKey;
|
||||
break;
|
||||
case KeyCode.L:
|
||||
key = Keyboard.current.lKey;
|
||||
break;
|
||||
default:
|
||||
Debug.LogError($"{nameof(InputHelper)}: not support {keyCode} yet , please add it yourself if needed");
|
||||
break;
|
||||
}
|
||||
|
||||
value = key.wasPressedThisFrame;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5069defa9fe8c7a43843e1189e2d606c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,226 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class LayerHelper
|
||||
{
|
||||
private static Vector2 s_Vector0And0 = new Vector2(0, 0);
|
||||
private static Vector2 s_Vector0And0Dot5 = new Vector2(0, 0.5f);
|
||||
private static Vector2 s_Vector0And1 = new Vector2(0, 1f);
|
||||
private static Vector2 s_Vector0Dot5And1 = new Vector2(0.5f, 1f);
|
||||
private static Vector2 s_Vector0Dot5And0Dot5 = new Vector2(0.5f, 0.5f);
|
||||
private static Vector2 s_Vector0Dot5And0 = new Vector2(0.5f, 0f);
|
||||
private static Vector2 s_Vector1And1 = new Vector2(1f, 1f);
|
||||
private static Vector2 s_Vector1And0Dot5 = new Vector2(1f, 0.5f);
|
||||
private static Vector2 s_Vector1And0 = new Vector2(1f, 0);
|
||||
|
||||
internal static Vector2 ResetChartPositionAndPivot(Vector2 minAnchor, Vector2 maxAnchor, float width,
|
||||
float height, ref float chartX, ref float chartY)
|
||||
{
|
||||
if (IsLeftTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height;
|
||||
return s_Vector0And1;
|
||||
}
|
||||
else if (IsLeftCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0And0Dot5;
|
||||
}
|
||||
else if (IsLeftBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = 0;
|
||||
return s_Vector0And0;
|
||||
}
|
||||
else if (IsCenterTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height;
|
||||
return s_Vector0Dot5And1;
|
||||
}
|
||||
else if (IsCenterCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsCenterBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = 0;
|
||||
return s_Vector0Dot5And0;
|
||||
}
|
||||
else if (IsRightTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height;
|
||||
return s_Vector1And1;
|
||||
}
|
||||
else if (IsRightCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height / 2;
|
||||
return s_Vector1And0Dot5;
|
||||
}
|
||||
else if (IsRightBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = 0;
|
||||
return s_Vector1And0;
|
||||
}
|
||||
else if (IsStretchTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height;
|
||||
return s_Vector0Dot5And1;
|
||||
}
|
||||
else if (IsStretchMiddle(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsStretchBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = 0;
|
||||
return s_Vector0Dot5And0;
|
||||
}
|
||||
else if (IsStretchLeft(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0And0Dot5;
|
||||
}
|
||||
else if (IsStretchCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsStretchRight(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height / 2;
|
||||
return s_Vector1And0Dot5;
|
||||
}
|
||||
else if (IsStretchStrech(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
chartX = 0;
|
||||
chartY = 0;
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
private static bool IsLeftTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And1 && maxAnchor == s_Vector0And1;
|
||||
}
|
||||
|
||||
private static bool IsLeftCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0Dot5 && maxAnchor == s_Vector0And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsLeftBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == Vector2.zero && maxAnchor == Vector2.zero;
|
||||
}
|
||||
|
||||
private static bool IsCenterTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And1 && maxAnchor == s_Vector0Dot5And1;
|
||||
}
|
||||
|
||||
private static bool IsCenterCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0Dot5 && maxAnchor == s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsCenterBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0 && maxAnchor == s_Vector0Dot5And0;
|
||||
}
|
||||
|
||||
private static bool IsRightTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And1 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsRightCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0Dot5 && maxAnchor == s_Vector1And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsRightBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0 && maxAnchor == s_Vector1And0;
|
||||
}
|
||||
|
||||
private static bool IsStretchTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And1 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchMiddle(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0Dot5 && maxAnchor == s_Vector1And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsStretchBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector1And0;
|
||||
}
|
||||
|
||||
private static bool IsStretchLeft(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector0And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0 && maxAnchor == s_Vector0Dot5And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchRight(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchStrech(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
public static bool IsStretchPivot(RectTransform rt)
|
||||
{
|
||||
return IsStretchTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchMiddle(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchLeft(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchRight(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchStrech(rt.anchorMin, rt.anchorMax);
|
||||
}
|
||||
|
||||
public static bool IsFixedWidthHeight(RectTransform rt)
|
||||
{
|
||||
return IsLeftTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsLeftCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsLeftBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightBottom(rt.anchorMin, rt.anchorMax);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d6eeea6fc2824cc891fec0674bf2d71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class MathUtil
|
||||
{
|
||||
public static double Abs(double d)
|
||||
{
|
||||
return d > 0 ? d : -d;
|
||||
}
|
||||
|
||||
public static double Clamp(double d, double min, double max)
|
||||
{
|
||||
if (d >= min && d <= max) return d;
|
||||
else if (d < min) return min;
|
||||
else return max;
|
||||
}
|
||||
|
||||
public static bool Approximately(double a, double b)
|
||||
{
|
||||
return Math.Abs(b - a) < Math.Max(0.000001f * Math.Max(Math.Abs(a), Math.Abs(b)), Mathf.Epsilon * 8);
|
||||
}
|
||||
|
||||
public static double Clamp01(double value)
|
||||
{
|
||||
if (value < 0F)
|
||||
return 0F;
|
||||
else if (value > 1F)
|
||||
return 1F;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double Lerp(double a, double b, double t)
|
||||
{
|
||||
return a + (b - a) * Clamp01(t);
|
||||
}
|
||||
|
||||
public static bool IsInteger(double value)
|
||||
{
|
||||
if (value == 0) return true;
|
||||
if (value >= -1 && value <= 1) return false;
|
||||
return Math.Abs(value % 1) <= (Double.Epsilon * 100);
|
||||
}
|
||||
|
||||
public static int GetPrecision(double value)
|
||||
{
|
||||
if (IsInteger(value)) return 0;
|
||||
int count = 1;
|
||||
double intvalue = value * Mathf.Pow(10, count);
|
||||
while (!IsInteger(intvalue) && count < 38)
|
||||
{
|
||||
count++;
|
||||
intvalue = value * Mathf.Pow(10, count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 094dc7b90e3a049b48f15f990c050db1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// UI帮助类。
|
||||
/// </summary>
|
||||
public static class UIHelper
|
||||
{
|
||||
public static void DrawBackground(VertexHelper vh, UIComponent component)
|
||||
{
|
||||
var background = component.background;
|
||||
var rect = component.graphRect;
|
||||
if (background.imageWidth > 0 || background.imageHeight > 0)
|
||||
{
|
||||
if (background.imageWidth > 0)
|
||||
{
|
||||
rect.width = background.imageWidth;
|
||||
rect.x = component.graphX + (component.graphWidth - background.imageWidth) / 2;
|
||||
}
|
||||
if (background.imageHeight > 0)
|
||||
{
|
||||
rect.height = background.imageHeight;
|
||||
rect.y = component.graphY + (component.graphHeight - background.imageHeight) / 2;
|
||||
}
|
||||
}
|
||||
background.rect = rect;
|
||||
if (!background.show)
|
||||
return;
|
||||
if (background.image != null)
|
||||
return;
|
||||
var backgroundColor = component.theme.GetBackgroundColor(background);
|
||||
DrawBackground(vh, background, backgroundColor);
|
||||
}
|
||||
|
||||
public static void DrawBackground(VertexHelper vh, Background background, Color32 color, float smoothness = 2)
|
||||
{
|
||||
if (!background.show)
|
||||
return;
|
||||
if (background.image != null)
|
||||
return;
|
||||
var borderWidth = background.borderStyle.GetRuntimeBorderWidth();
|
||||
var borderColor = background.borderStyle.GetRuntimeBorderColor();
|
||||
var cornerRadius = background.borderStyle.GetRuntimeCornerRadius();
|
||||
UGL.DrawRoundRectangleWithBorder(vh, background.rect, color, color, cornerRadius,
|
||||
borderWidth, borderColor, 0, smoothness);
|
||||
}
|
||||
|
||||
internal static void InitBackground(UIComponent component)
|
||||
{
|
||||
if (component.background.show == false ||
|
||||
(component.background.image == null && ChartHelper.IsClearColor(component.background.imageColor)))
|
||||
{
|
||||
ChartHelper.DestoryGameObject(component.transform, "Background");
|
||||
return;
|
||||
}
|
||||
var sizeDelta = component.background.imageWidth > 0 && component.background.imageHeight > 0 ?
|
||||
new Vector2(component.background.imageWidth, component.background.imageHeight) :
|
||||
component.graphSizeDelta;
|
||||
var backgroundObj = ChartHelper.AddObject("Background", component.transform, component.graphMinAnchor,
|
||||
component.graphMaxAnchor, component.graphPivot, sizeDelta);
|
||||
backgroundObj.hideFlags = component.chartHideFlags;
|
||||
|
||||
var backgroundImage = ChartHelper.EnsureComponent<Image>(backgroundObj);
|
||||
ChartHelper.UpdateRectTransform(backgroundObj, component.graphMinAnchor,
|
||||
component.graphMaxAnchor, component.graphPivot, sizeDelta);
|
||||
ChartHelper.SetBackground(backgroundImage, component.background);
|
||||
backgroundObj.transform.SetSiblingIndex(0);
|
||||
backgroundObj.SetActive(component.background.show && component.background.image != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3be0399ecf6194793aa056e45ebfe20a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user