mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 17:00:08 +00:00
[code] refactor the code
This commit is contained in:
@@ -20,13 +20,18 @@ namespace XCharts.Editor
|
||||
var canvasObject = new GameObject();
|
||||
canvasObject.name = "Canvas";
|
||||
canvas = canvasObject.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
var mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
|
||||
canvas.worldCamera = mainCamera == null? null : mainCamera.GetComponent<Camera>();
|
||||
canvasObject.AddComponent<CanvasScaler>();
|
||||
canvasObject.AddComponent<GraphicRaycaster>();
|
||||
var eventSystem = new GameObject();
|
||||
eventSystem.name = "EventSystem";
|
||||
eventSystem.AddComponent<EventSystem>();
|
||||
eventSystem.AddComponent<StandaloneInputModule>();
|
||||
if (GameObject.Find("EventSystem") == null)
|
||||
{
|
||||
var eventSystem = new GameObject();
|
||||
eventSystem.name = "EventSystem";
|
||||
eventSystem.AddComponent<EventSystem>();
|
||||
eventSystem.AddComponent<StandaloneInputModule>();
|
||||
}
|
||||
return canvas.transform;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,22 +145,18 @@ namespace XCharts.Runtime
|
||||
|
||||
public string GetFormatterContent(int labelIndex, string category)
|
||||
{
|
||||
if (m_FormatterFunction != null)
|
||||
{
|
||||
return m_FormatterFunction(labelIndex, 0, category);
|
||||
}
|
||||
if (string.IsNullOrEmpty(category))
|
||||
return category;
|
||||
return GetFormatterFunctionContent(labelIndex, category, category);
|
||||
|
||||
if (string.IsNullOrEmpty(m_Formatter))
|
||||
{
|
||||
return m_TextLimit.GetLimitContent(category);
|
||||
return GetFormatterFunctionContent(labelIndex, category, m_TextLimit.GetLimitContent(category));
|
||||
}
|
||||
else
|
||||
{
|
||||
var content = m_Formatter;
|
||||
FormatterHelper.ReplaceAxisLabelContent(ref content, category);
|
||||
return m_TextLimit.GetLimitContent(content);
|
||||
return GetFormatterFunctionContent(labelIndex, category, m_TextLimit.GetLimitContent(content));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,15 +166,11 @@ namespace XCharts.Runtime
|
||||
{
|
||||
value = Math.Abs(value);
|
||||
}
|
||||
if (m_FormatterFunction != null)
|
||||
{
|
||||
return m_FormatterFunction(labelIndex, value, null);
|
||||
}
|
||||
if (string.IsNullOrEmpty(m_Formatter))
|
||||
{
|
||||
if (isLog)
|
||||
{
|
||||
return ChartCached.NumberToStr(value, numericFormatter);
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
|
||||
}
|
||||
if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1)
|
||||
{
|
||||
@@ -186,24 +178,20 @@ namespace XCharts.Runtime
|
||||
int maxAcc = ChartHelper.GetFloatAccuracy(maxValue);
|
||||
int curAcc = ChartHelper.GetFloatAccuracy(value);
|
||||
int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc);
|
||||
return ChartCached.FloatToStr(value, numericFormatter, acc);
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.FloatToStr(value, numericFormatter, acc));
|
||||
}
|
||||
return ChartCached.NumberToStr(value, numericFormatter);
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
var content = m_Formatter;
|
||||
FormatterHelper.ReplaceAxisLabelContent(ref content, numericFormatter, value);
|
||||
return content;
|
||||
return GetFormatterFunctionContent(labelIndex, value, content);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFormatterDateTime(int labelIndex, double value, double minValue, double maxValue)
|
||||
{
|
||||
if (m_FormatterFunction != null)
|
||||
{
|
||||
return m_FormatterFunction(labelIndex, value, null);
|
||||
}
|
||||
var timestamp = (int) value;
|
||||
var dateTime = DateTimeUtil.GetDateTime(timestamp);
|
||||
var dateString = string.Empty;
|
||||
@@ -219,12 +207,24 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var content = m_Formatter;
|
||||
FormatterHelper.ReplaceAxisLabelContent(ref content, dateString);
|
||||
return m_TextLimit.GetLimitContent(content);
|
||||
return GetFormatterFunctionContent(labelIndex, value, m_TextLimit.GetLimitContent(content));
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_TextLimit.GetLimitContent(dateString);
|
||||
return GetFormatterFunctionContent(labelIndex, value, m_TextLimit.GetLimitContent(dateString));
|
||||
}
|
||||
}
|
||||
|
||||
private string GetFormatterFunctionContent(int labelIndex, string category, string currentContent)
|
||||
{
|
||||
return m_FormatterFunction == null ? currentContent :
|
||||
m_FormatterFunction(labelIndex, labelIndex, category, currentContent);
|
||||
}
|
||||
|
||||
private string GetFormatterFunctionContent(int labelIndex, double value, string currentContent)
|
||||
{
|
||||
return m_FormatterFunction == null ? currentContent :
|
||||
m_FormatterFunction(labelIndex, labelIndex, null, currentContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,6 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetLabel(ChartText labelObject, LabelStyle label, ThemeStyle theme,
|
||||
Color textColor, float rotate)
|
||||
{
|
||||
if (labelObject == null) return;
|
||||
labelObject.SetColor(textColor);
|
||||
labelObject.SetLocalEulerAngles(new Vector3(0, 0, rotate));
|
||||
labelObject.SetFontSize(label.textStyle.GetFontSize(theme.common));
|
||||
labelObject.SetFontStyle(label.textStyle.fontStyle);
|
||||
}
|
||||
|
||||
public static bool CanShowLabel(Serie serie, SerieData serieData, LabelStyle label, int dimesion)
|
||||
{
|
||||
return serie.show && serieData.context.canShowLabel && !serie.IsIgnoreValue(serieData, dimesion);
|
||||
@@ -43,18 +33,23 @@ namespace XCharts.Runtime
|
||||
var numericFormatter = serieLabel == null ? "" : serieLabel.numericFormatter;
|
||||
var serieName = serie.serieName;
|
||||
var dataName = serieData != null ? serieData.name : null;
|
||||
if (serieLabel.formatterFunction != null)
|
||||
{
|
||||
return serieLabel.formatterFunction(serieData.index, dataValue, null);
|
||||
}
|
||||
if (string.IsNullOrEmpty(serieLabel.formatter))
|
||||
return ChartCached.NumberToStr(dataValue, numericFormatter);
|
||||
{
|
||||
var currentContent = ChartCached.NumberToStr(dataValue, numericFormatter);
|
||||
if (serieLabel.formatterFunction == null)
|
||||
return currentContent;
|
||||
else
|
||||
return serieLabel.formatterFunction(serieData.index, dataValue, null, currentContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
var content = serieLabel.formatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, dataValue,
|
||||
dataTotal, serieName, dataName, dataName, color, serieData);
|
||||
return content;
|
||||
if (serieLabel.formatterFunction == null)
|
||||
return content;
|
||||
else
|
||||
return serieLabel.formatterFunction(serieData.index, dataValue, null, content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,11 +187,11 @@ namespace XCharts.Runtime
|
||||
var angle = ChartHelper.GetAngle360(Vector2.up, newPos - serie.context.center);
|
||||
if (angle >= 180 && angle <= 270)
|
||||
{
|
||||
serieData.context.labelPosition = new Vector3(isLeft?(++lastX):(--lastX), y1);
|
||||
serieData.context.labelPosition = new Vector3(isLeft?(++lastX): (--lastX), y1);
|
||||
}
|
||||
else if (angle < 180 && angle >= 90)
|
||||
{
|
||||
serieData.context.labelPosition = new Vector3(isLeft?(++lastX):(--lastX), y1);
|
||||
serieData.context.labelPosition = new Vector3(isLeft?(++lastX): (--lastX), y1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b81cddd3452545748563f9c6ea9be69
|
||||
guid: 654a13ef33a064e4fbf078742f397b20
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -8,18 +8,19 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var serieLabel = data.label;
|
||||
var numericFormatter = serieLabel.numericFormatter;
|
||||
if (serieLabel.formatterFunction != null)
|
||||
{
|
||||
return serieLabel.formatterFunction(data.index, data.runtimeValue, null);
|
||||
}
|
||||
if (string.IsNullOrEmpty(serieLabel.formatter))
|
||||
return ChartCached.NumberToStr(data.runtimeValue, numericFormatter);
|
||||
{
|
||||
var content = ChartCached.NumberToStr(data.runtimeValue, numericFormatter);
|
||||
return serieLabel.formatterFunction == null? content:
|
||||
serieLabel.formatterFunction(data.index, data.runtimeValue, null, content);
|
||||
}
|
||||
else
|
||||
{
|
||||
var content = serieLabel.formatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, data.runtimeValue,
|
||||
0, serie.serieName, data.name, data.name, Color.clear, null);
|
||||
return content;
|
||||
return serieLabel.formatterFunction == null? content:
|
||||
serieLabel.formatterFunction(data.index, data.runtimeValue, null, content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var foundDot = false;
|
||||
var mc = s_Regex.Matches(content);
|
||||
Debug.LogError("context:" + content);
|
||||
foreach (var m in mc)
|
||||
{
|
||||
var old = m.ToString();
|
||||
|
||||
@@ -9,8 +9,10 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
/// <param name="dataIndex">数据索引</param>
|
||||
/// <param name="value">数值</param>
|
||||
/// <param name="category">类目</param>
|
||||
/// <param name="content">当前内容</param>
|
||||
/// <returns>最终显示的文本内容</returns>
|
||||
public delegate string LabelFormatterFunction(int dataIndex, double value, string category);
|
||||
public delegate string LabelFormatterFunction(int dataIndex, double value, string category, string content);
|
||||
public delegate float AnimationDelayFunction(int dataIndex);
|
||||
public delegate float AnimationDurationFunction(int dataIndex);
|
||||
/// <summary>
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.48f };
|
||||
[SerializeField] private float[] m_Radius = new float[2] { 0, 0.28f };
|
||||
|
||||
[SerializeField][Range(1, 10)] private int m_ShowDataDimension;
|
||||
[SerializeField][Range(2, 10)] private int m_ShowDataDimension;
|
||||
[SerializeField] private bool m_ShowDataName;
|
||||
[SerializeField] private bool m_Clip = false;
|
||||
[SerializeField] private bool m_Ignore = false;
|
||||
@@ -686,7 +686,7 @@ namespace XCharts.Runtime
|
||||
/// <summary>
|
||||
/// 数据项里的数据维数。
|
||||
/// </summary>
|
||||
public int showDataDimension { get { return m_ShowDataDimension; } set { m_ShowDataDimension = value; } }
|
||||
public int showDataDimension { get { return m_ShowDataDimension; } set { m_ShowDataDimension = Mathf.Clamp(2, 10, value); } }
|
||||
/// <summary>
|
||||
/// 在Editor的inpsector上是否显示name参数
|
||||
/// </summary>
|
||||
@@ -1132,7 +1132,7 @@ namespace XCharts.Runtime
|
||||
serieData.index = xValue;
|
||||
serieData.id = dataId;
|
||||
AddSerieData(serieData);
|
||||
m_ShowDataDimension = 1;
|
||||
m_ShowDataDimension = 2;
|
||||
SetVerticesDirty();
|
||||
CheckDataName(dataName);
|
||||
labelDirty = true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c031417514104eebb5bbd60dd1f90fd
|
||||
guid: 73512c276f5c34fb4a28cf61b2a0c4f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -138,15 +138,6 @@ namespace XCharts.Runtime
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Serie GetSerieByVesselIndex(List<Serie> series, int vesselIndex)
|
||||
{
|
||||
foreach (var serie in series)
|
||||
{
|
||||
if (serie.vesselIndex == vesselIndex) return serie;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HashSet<string> _setForStack = new HashSet<string>();
|
||||
/// <summary>
|
||||
/// 是否由数据堆叠
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96a06a5949772464da15c44ae2ad400d
|
||||
guid: 0a1c1086d9f88497d9e0ac89d719ff48
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
Reference in New Issue
Block a user