整理代码更新文档

This commit is contained in:
monitor1394
2020-06-12 09:22:51 +08:00
parent 42980e87e3
commit eccd5a8995
11 changed files with 47 additions and 54 deletions

View File

@@ -195,13 +195,13 @@
* `Corss`:十字准星指示器。坐标轴显示`Label`和交叉线。
* `formatter`:提示框内容字符串模版格式器。支持用 `\n` 换行。当`formatter`不为空时,优先使用`formatter`,否则使用`itemFormatter`
* 模板变量有`{.}``{a}``{b}``{c}``{d}`
* `{.}`表示带动态颜色的圆点。
* `{a}`系列名`serie``name`
* `{b}`为数据项`serieData``name`,或者类目值(如折线图的`X`轴)。
* `{c}`为数值。
* `{d}`为百分比值,注意不带`%`号。
* `{.}`为当前所指示或`index``0``serie`的对应颜色的圆点。
* `{a}`当前所指示或`index``0``serie`系列名`name`
* `{b}`当前所指示或`index``0``serie`数据项`serieData``name`,或者类目值(如折线图的`X`轴)。
* `{c}`当前所指示或`index``0``serie``y`维(`dimesion``1`)的数值。
* `{d}`当前所指示或`index``0``serie``y`维(`dimesion``1`百分比值,注意不带`%`号。
* `{.1}`表示指定`index``1``serie`对应颜色的圆点。
* `{a1}``{b1}``{c1}`中的`1`表示指定`index``1``serie``{a}`默认`index``0``serie`
* `{a1}``{b1}``{c1}`中的`1`表示指定`index``1``serie`
* `{c1:2}`表示索引为`1``serie`的当前指示数据项的第`3`个数据一个数据项有多个数据index为`2`表示第`3`个数据)。
* `{c1:2-2}`表示索引为`1``serie`的第`3`个数据项的第`3`个数据(也就是要指定第几个数据项时必须要指定第几个数据)。
* `{d1:2:f2}`表示单独指定了数值的格式化字符串为`f2`(不指定时用`numericFormatter`)。

View File

@@ -74,10 +74,7 @@ namespace XCharts
var tempWidth = (pos.width - startX + 35) / 2;
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
var centerYRect = new Rect(centerXRect.x + tempWidth - 20, drawRect.y, tempWidth, drawRect.height);
while (m_Center.arraySize < 2)
{
m_Center.InsertArrayElementAtIndex(m_Center.arraySize);
}
while (m_Center.arraySize < 2) m_Center.arraySize++;
EditorGUI.PropertyField(centerXRect, m_Center.GetArrayElementAtIndex(0), GUIContent.none);
EditorGUI.PropertyField(centerYRect, m_Center.GetArrayElementAtIndex(1), GUIContent.none);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

View File

@@ -363,10 +363,8 @@ namespace XCharts
bool showSelected = (serieType == SerieType.Pie);
if (listSize != m_Datas.arraySize)
{
while (listSize > m_Datas.arraySize)
m_Datas.InsertArrayElementAtIndex(m_Datas.arraySize);
while (listSize < m_Datas.arraySize)
m_Datas.DeleteArrayElementAtIndex(m_Datas.arraySize - 1);
while (listSize > m_Datas.arraySize) m_Datas.arraySize++;
while (listSize < m_Datas.arraySize) m_Datas.arraySize--;
}
if (listSize > 30)
{
@@ -414,8 +412,9 @@ namespace XCharts
{
while (2 > data.arraySize)
{
data.InsertArrayElementAtIndex(data.arraySize);
data.GetArrayElementAtIndex(data.arraySize - 1).floatValue = 0;
var value = data.arraySize == 0 ? index : 0;
data.arraySize++;
data.GetArrayElementAtIndex(data.arraySize - 1).floatValue = value;
}
SerializedProperty element = data.GetArrayElementAtIndex(1);
if (showSelected)
@@ -452,8 +451,9 @@ namespace XCharts
var dataCount = i < 1 ? 2 : i + 1;
while (dataCount > data.arraySize)
{
data.InsertArrayElementAtIndex(data.arraySize);
data.GetArrayElementAtIndex(data.arraySize - 1).floatValue = 0;
var value = data.arraySize == 0 ? index : 0;
data.arraySize++;
data.GetArrayElementAtIndex(data.arraySize - 1).floatValue = value;
}
drawRect.x = startX + i * xWid;
drawRect.width = dataWid + 40;

View File

@@ -320,7 +320,7 @@ namespace XCharts
{
while (i > m_CustomColorPalette.arraySize - 1)
{
m_CustomColorPalette.InsertArrayElementAtIndex(m_CustomColorPalette.arraySize);
m_CustomColorPalette.arraySize++;
}
var customElement = m_CustomColorPalette.GetArrayElementAtIndex(i);
color = !ChartHelper.IsClearColor(customElement.colorValue) ?

View File

@@ -32,19 +32,13 @@ public class ChartEditorHelper
public static void MakeTwoField(ref Rect drawRect, float rectWidth, SerializedProperty arrayProp, string name)
{
while (arrayProp.arraySize < 2)
{
arrayProp.InsertArrayElementAtIndex(arrayProp.arraySize);
}
while (arrayProp.arraySize < 2) arrayProp.arraySize++;
MakeTwoField(ref drawRect, rectWidth, arrayProp.GetArrayElementAtIndex(0), arrayProp.GetArrayElementAtIndex(1), name);
}
public static void MakeDivideList(ref Rect drawRect, float rectWidth, SerializedProperty arrayProp, string name, int showNum)
{
while (arrayProp.arraySize < showNum)
{
arrayProp.InsertArrayElementAtIndex(arrayProp.arraySize);
}
while (arrayProp.arraySize < showNum) arrayProp.arraySize++;
EditorGUI.LabelField(drawRect, name);
#if UNITY_2019_3_OR_NEWER
var gap = 2;
@@ -214,7 +208,7 @@ public class ChartEditorHelper
var iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height);
if (GUI.Button(iconRect, new GUIContent("+", "add")))
{
listProp.InsertArrayElementAtIndex(listProp.arraySize);
listProp.arraySize++;
}
listSize = listProp.arraySize;
listSize = EditorGUI.IntField(elementRect, "Size", listSize);
@@ -228,10 +222,8 @@ public class ChartEditorHelper
if (listSize != listProp.arraySize)
{
while (listSize > listProp.arraySize)
listProp.InsertArrayElementAtIndex(listProp.arraySize);
while (listSize < listProp.arraySize)
listProp.DeleteArrayElementAtIndex(listProp.arraySize - 1);
while (listSize > listProp.arraySize) listProp.arraySize++;
while (listSize < listProp.arraySize) listProp.arraySize--;
}
}
if (listSize > 30)

View File

@@ -298,11 +298,11 @@ namespace XCharts
{
if (m_Font == null && m_CustomFont == null)
{
sb.AppendFormat("warning:theme->font is null");
sb.AppendFormat("warning:theme->font is null\n");
}
if (m_ColorPalette.Length == 0 && m_CustomColorPalette.Count == 0)
{
sb.AppendFormat("warning:theme->colorPalette is empty");
sb.AppendFormat("warning:theme->colorPalette is empty\n");
}
for (int i = 0; i < m_ColorPalette.Length; i++)
{

View File

@@ -97,17 +97,17 @@ namespace XCharts
/// <summary>
/// 提示框总内容的字符串模版格式器。支持用 \n 换行。当formatter不为空时优先使用formatter否则使用itemFormatter。
/// 模板变量有{.}、{a}、{b}、{c}、{d}。
/// {.}表示带动态颜色的圆点。
/// {a}为系列名serie的name。
/// {b}为数据项serieData的name或者类目值如折线图的X轴
/// {c}为数值。
/// {d}为百分比值,注意不带%号。
/// {.}为当前所指示或index为0的serie的对应颜色的圆点。
/// {a}为当前所指示或index为0的serie的系列名name。
/// {b}为当前所指示或index为0的serie的数据项serieData的name或者类目值如折线图的X轴
/// {c}为当前所指示或index为0的serie的y维dimesion为1数值。
/// {d}为当前所指示或index为0的serie的y维dimesion为1百分比值,注意不带%号。
/// {.1}表示指定index为1的serie对应颜色的圆点。
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie{a}默认index为0的serie
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据一个数据项有多个数据index为2表示第3个数据
/// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据也就是要指定第几个数据项时必须要指定第几个数据
/// {d1:2:f2}表示单独指定了数值的格式化字符串为f2不指定时用numericFormatter
/// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:1f1}"
/// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}"
/// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
/// <summary>

View File

@@ -65,10 +65,15 @@ namespace XCharts
m_Opacity = 1;
m_TooltipFormatter = null;
m_NumericFormatter = "";
m_CornerRadius[0] = 0;
m_CornerRadius[1] = 0;
m_CornerRadius[2] = 0;
m_CornerRadius[3] = 0;
if (m_CornerRadius == null)
{
m_CornerRadius = new float[] { 0, 0, 0, 0 };
}
else
{
for (int i = 0; i < m_CornerRadius.Length; i++)
m_CornerRadius[i] = 0;
}
}
/// <summary>

View File

@@ -117,7 +117,7 @@ namespace XCharts
if (serie.dataCount > 0)
{
allDataIsEmpty = false;
for (int i = 1; i < serie.dataCount; i++)
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.GetSerieData(i);
for (int j = 1; j < serieData.data.Count; j++)

View File

@@ -47,13 +47,12 @@ namespace XCharts
if (argsCount <= 0) continue;
int targetIndex = 0;
char p = GetSerieIndex(args[0].ToString(), ref targetIndex);
if (serie == null)
if (targetIndex >= 0)
{
if (targetIndex == -1) continue;
serie = series.GetSerie(targetIndex);
if (serie == null) continue;
}
else
else if (serie != null)
{
targetIndex = serie.index;
}
@@ -150,7 +149,7 @@ namespace XCharts
private static char GetSerieIndex(string strType, ref int index)
{
index = 0;
index = -1;
if (strType.Length > 1)
{
if (!int.TryParse(strType.Substring(1), out index))

View File

@@ -218,14 +218,14 @@ namespace XCharts
var itemTitle = title;
if (!string.IsNullOrEmpty(itemTitle))
{
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, null, themeInfo, category, dataZoom);
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
sb.Append(itemTitle).Append(FormatterHelper.PH_NN);
}
var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];
foreach (var tempIndex in dataIndexList)
{
string content = itemFormatter;
var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, null, themeInfo, category, dataZoom);
var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
if (!foundDot)
{
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
@@ -242,7 +242,7 @@ namespace XCharts
needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
if (formatTitle)
{
FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, null, series, themeInfo, category, dataZoom);
FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
}
if (serie.show)
{
@@ -254,7 +254,7 @@ namespace XCharts
continue;
}
string content = itemFormatter;
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, null, themeInfo, category, dataZoom);
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
if (!first) sb.Append(FormatterHelper.PH_NN);
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
sb.Append(content);