Skip to content

Commit

Permalink
增加SerieData可单独设置SerieSymbol#66
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Jun 17, 2020
1 parent c187226 commit 17c8b76
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 41 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

# 更新日志

* (2020.06.17) 增加`SerieData`可单独设置`SerieSymbol`#66
* (2020.06.17) 修复`Check For Update``Unity 2018`部分版本报错的问题#63
* (2020.06.16) 增加`Serie``avoidLabelOverlap`参数避免饼图标签堆叠的情况#56
* (2020.06.15) 修复`SerieLabel`单独控制显示时可能错乱的问题
* (2020.06.11) 修复`Check warning`不生效的问题
* (2020.06.11) 修复`PieChart``RingChart`在数据占比很小时不显示的问题
* (2020.06.11) 增加`Tooltip``titleFormatter`支持配置占位符`{i}`表示忽略不显示标题
* (2020.06.07) 增加`Animation``customFadeInDelay`等自定义数据项延时和时长回调函数
* (2020.06.07) 优化`PieChart`在数据全为`0`时的显示为等份的效果
* (2020.06.07) 增加`Animation``customFadeInDelay`等自定义数据项延时和时长回调函数#58
* (2020.06.07) 优化`PieChart`在数据全为`0`时的显示为等份的效果#59
* (2020.06.04) 增加`SerieLabel``autoOffset`参数设置是否自动判断上下偏移
* (2020.06.04) 增加`Tooltip``alwayShow`参数设置触发后一直显示
* (2020.06.04) 优化`Tooltip``formatter`支持`{.1}`通配符
* (2020.06.04) 优化`Legend`数量过多时自动换行显示
* (2020.06.04) 优化`Legend`数量过多时自动换行显示#53
* (2020.06.03) 发布`v1.5.1`版本
* (2020.06.02) 增加`Radar``ceilRate`,设置最大最小值的取整倍率
* (2020.06.02) 优化`Tooltip``formatter`,支持`{c1:1-1:f1}`格式配置
Expand Down
17 changes: 11 additions & 6 deletions Documentation/XCharts配置项手册.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,16 @@
* `name`:数据项名称。
* `selected`:该数据项是否被选中。
* `radius`:自定义半径。可用在饼图中自定义某个数据项的半径。
* `showIcon`:是否显示图标。
* `iconImage`:图标的图片。
* `iconColor`:图标颜色。
* `iconWidth`:图标宽。
* `iconHeight`:图标高。
* `iconOffset`:图标偏移。
* `iconStyle`:数据项图标样式。
* `enableLabel`:是否启用单个数据项的标签设置。
* `label`:单个数据项的标签设置。
* `enableItemStyle`:是否启用单个数据项的样式。
* `itemStyle`:单个数据项的样式设置。
* `enableEmphasis`:是否启用单个数据项的高亮样式。
* `emphasis`:单个数据项的高亮样式设置。
* `enableSymbol`:是否启用单个数据项的标记设置。
* `symbol`:单个数据项的标记设置。
* `data`:可指定任意维数的数值列表。对于折线图和柱状图,`data`其实是`size``2`的数组,`data[0]`是x的编号,`data[1]``y`的数值,默认显示`data[1]`。其他图表看需求而定是长度大于`2`的数组。可通过`Serie``showDataDimension`指定数据长度。

## `SerieLabel`

Expand Down Expand Up @@ -881,6 +885,7 @@

## `SerieSymbol`

* `show`:是否显示标记。
* `type`:标记类型。支持以下六种类型:
* `EmptyCircle`:空心圆。
* `Circle`:实心圆。
Expand Down
7 changes: 6 additions & 1 deletion Editor/PropertyDrawers/SerieDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,13 @@ private void DrawDataElement(ref Rect drawRect, int dimension, SerializedPropert
var m_ItemStyle = serieData.FindPropertyRelative("m_ItemStyle");
var m_EnableEmphasis = serieData.FindPropertyRelative("m_EnableEmphasis");
var m_Emphasis = serieData.FindPropertyRelative("m_Emphasis");
var m_EnableSymbol = serieData.FindPropertyRelative("m_EnableSymbol");
var m_Symbol = serieData.FindPropertyRelative("m_Symbol");
EditorGUI.PropertyField(drawRect, m_Icon);
drawRect.y += EditorGUI.GetPropertyHeight(m_Icon);
EditorGUI.PropertyField(drawRect, m_Symbol);
ChartEditorHelper.MakeBool(drawRect, m_EnableSymbol, 1, "(enable)");
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_Label);
ChartEditorHelper.MakeBool(drawRect, m_EnableLabel, 1, "(enable)");
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
Expand All @@ -497,7 +502,6 @@ private void DrawDataElement(ref Rect drawRect, int dimension, SerializedPropert
EditorGUI.PropertyField(drawRect, m_Emphasis);
ChartEditorHelper.MakeBool(drawRect, m_EnableEmphasis, 1, "(enable)");
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);

EditorGUI.indentLevel -= 2;
}
}
Expand Down Expand Up @@ -607,6 +611,7 @@ public override float GetPropertyHeight(SerializedProperty prop, GUIContent labe
{
var item = m_Data.GetArrayElementAtIndex(i);
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_IconStyle"));
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_Emphasis"));
Expand Down
15 changes: 10 additions & 5 deletions Editor/PropertyDrawers/SerieSymbolDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
SerializedProperty m_SizeType = prop.FindPropertyRelative("m_SizeType");
SerializedProperty m_Size = prop.FindPropertyRelative("m_Size");
Expand All @@ -32,12 +33,14 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
SerializedProperty m_ForceShowLast = prop.FindPropertyRelative("m_ForceShowLast");
SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap");

ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieSymbolToggle, prop, null, m_Type, false);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieSymbolToggle, prop, null, m_Show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_SerieSymbolToggle, prop))
{
++EditorGUI.indentLevel;

EditorGUI.PropertyField(drawRect, m_Type);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Gap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SizeType);
Expand Down Expand Up @@ -78,16 +81,18 @@ public override float GetPropertyHeight(SerializedProperty prop, GUIContent labe
{
SerializedProperty m_SizeType = prop.FindPropertyRelative("m_SizeType");
SerieSymbolSizeType sizeType = (SerieSymbolSizeType)m_SizeType.enumValueIndex;
var hig = 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
switch (sizeType)
{
case SerieSymbolSizeType.Custom:
return 8 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
break;
case SerieSymbolSizeType.FromData:
return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
hig += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
break;
case SerieSymbolSizeType.Callback:
return 8 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
break;
}
return 8 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
return hig;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/Runtime/Example11_AddSinCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Awake()
chart.RemoveData();

var serie = chart.AddSerie(SerieType.Line);
serie.symbol.type = SerieSymbolType.None;
serie.symbol.show = false;
serie.lineType = LineType.Normal;
for (angle = 0; angle < 1080; angle++)
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/Runtime/Example_Dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void Awake()
chart = gameObject.GetComponentInChildren<CoordinateChart>();
chart.RemoveData();
var serie = chart.AddSerie(SerieType.Line);
serie.symbol.type = SerieSymbolType.None;
serie.symbol.show = false;
serie.maxCache = maxCacheDataNumber;
chart.xAxises[0].maxCache = maxCacheDataNumber;
timeNow = DateTime.Now;
Expand Down
4 changes: 3 additions & 1 deletion Runtime/Component/Main/Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,21 @@ public Serie AddSerie(SerieType type, string serieName, bool show = true)

if (type == SerieType.Scatter)
{
serie.symbol.show = true;
serie.symbol.type = SerieSymbolType.Circle;
serie.symbol.size = 20f;
serie.symbol.selectedSize = 30f;
}
else if (type == SerieType.Line)
{
serie.symbol.show = true;
serie.symbol.type = SerieSymbolType.EmptyCircle;
serie.symbol.size = 2.5f;
serie.symbol.selectedSize = 5f;
}
else
{
serie.symbol.type = SerieSymbolType.None;
serie.symbol.show = false;
}
serie.animation.Restart();
m_Series.Add(serie);
Expand Down
14 changes: 14 additions & 0 deletions Runtime/Component/Sub/SerieData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class SerieData : SubComponent
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
[SerializeField] private bool m_EnableEmphasis = false;
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
[SerializeField] private bool m_EnableSymbol = false;
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
[SerializeField] private List<float> m_Data = new List<float>();

public LabelObject labelObject { get; set; }
Expand Down Expand Up @@ -87,6 +89,14 @@ public class SerieData : SubComponent
/// </summary>
public Emphasis emphasis { get { return m_Emphasis; } set { m_Emphasis = value; } }
/// <summary>
/// 是否启用单个数据项的标记设置。
/// </summary>
public bool enableSymbol { get { return m_EnableSymbol; } set { m_EnableSymbol = value; } }
/// <summary>
/// 单个数据项的标记设置。
/// </summary>
public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = value; } }
/// <summary>
/// An arbitrary dimension data list of data item.
/// 可指定任意维数的数值列表。
/// </summary>
Expand Down Expand Up @@ -169,6 +179,10 @@ public void Reset()
m_Name = string.Empty;
m_Selected = false;
m_CanShowLabel = false;
m_EnableSymbol = false;
m_EnableLabel = false;
m_EnableEmphasis = false;
m_EnableItemStyle = false;
m_Radius = 0;
m_Data.Clear();
m_PreviousData.Clear();
Expand Down
30 changes: 29 additions & 1 deletion Runtime/Component/Sub/SerieSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public enum SerieSymbolSizeType
[System.Serializable]
public class SerieSymbol : SubComponent
{
[SerializeField] private bool m_Show = false;
[SerializeField] private SerieSymbolType m_Type = SerieSymbolType.EmptyCircle;
[SerializeField] private SerieSymbolSizeType m_SizeType = SerieSymbolSizeType.Custom;
[SerializeField] private float m_Size = 6f;
Expand All @@ -92,6 +93,33 @@ public class SerieSymbol : SubComponent
[SerializeField] private bool m_ForceShowLast = false;
[SerializeField] private float m_Gap = 0;

public void Reset()
{
m_Show = false;
m_Type = SerieSymbolType.EmptyCircle;
m_SizeType = SerieSymbolSizeType.Custom;
m_Size = 6f;
m_SelectedDataScale = 10f;
m_DataIndex = 1;
m_DataScale = 1;
m_SelectedDataScale = 1.5f;
m_SizeCallback = null;
m_SelectedSizeCallback = null;
m_StartIndex = 0;
m_Interval = 0;
m_ForceShowLast = false;
m_Gap = 0;
}

/// <summary>
/// Whether the symbol is showed.
/// 是否显示标记。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of symbol.
/// 标记类型。
Expand Down Expand Up @@ -274,7 +302,7 @@ public float GetSelectedSize(List<float> data)

public bool ShowSymbol(int dataIndex, int dataCount)
{
if (type == SerieSymbolType.None) return false;
if (!show) return false;
if (dataIndex < startIndex) return false;
if (m_Interval <= 0) return true;
if (m_ForceShowLast && dataIndex == dataCount - 1) return true;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Helper/CheckHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private static void CheckSerie(BaseChart chart, StringBuilder sb)
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
if (serie.symbol.type == SerieSymbolType.None)
if (!serie.symbol.show)
sb.AppendFormat("warning:serie {0} symbol type is None\n", serie.index);
break;
}
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Internal/CoordinateChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ protected override void CheckTootipArea(Vector2 local)
var serieData = serie.data[n];
var xdata = serieData.GetData(0, xAxis.inverse);
var ydata = serieData.GetData(1, yAxis.inverse);
var symbolSize = serie.symbol.GetSize(serieData == null ? null : serieData.data);
var symbol = SerieHelper.GetSerieSymbol(serie,serieData);
var symbolSize = symbol.GetSize(serieData == null ? null : serieData.data);
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
{
Expand Down
17 changes: 8 additions & 9 deletions Runtime/Internal/CoordinateChart_DrawLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,30 @@ protected void DrawLinePoint(VertexHelper vh)
for (int n = 0; n < m_Series.Count; n++)
{
var serie = m_Series.GetSerie(n);
if (serie.IsPerformanceMode()) continue;
if (!serie.show || serie.IsPerformanceMode()) continue;
if (serie.type != SerieType.Line) continue;
if (!serie.show || serie.symbol.type == SerieSymbolType.None) continue;
var count = serie.dataPoints.Count;
for (int i = 0; i < count; i++)
{
if (!serie.symbol.ShowSymbol(i, count)) continue;
var serieData = serie.GetSerieData(i);
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
if (!symbol.show || !symbol.ShowSymbol(i, count)) continue;
if (serie.lineArrow.show)
{
if (serie.lineArrow.position == LineArrow.Position.Start && i == 0) continue;
if (serie.lineArrow.position == LineArrow.Position.End && i == count - 1) continue;
}
Vector3 p = serie.dataPoints[i];
var serieData = serie.GetSerieData(i);
if (ChartHelper.IsIngore(p)) continue;
if (ChartHelper.IsIngore(serie.dataPoints[i])) continue;
bool highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted || serie.highlighted;
float symbolSize = highlight ? serie.symbol.selectedSize : serie.symbol.size;
float symbolSize = highlight ? symbol.selectedSize : symbol.size;
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, n, highlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, n, highlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
CheckClipAndDrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, p, symbolColor,
symbolToColor, serie.symbol.gap, clip, cornerRadius);
CheckClipAndDrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serie.dataPoints[i], symbolColor,
symbolToColor, symbol.gap, clip, cornerRadius);
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions Runtime/Internal/CoordinateChart_DrawScatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
for (int n = serie.minShow; n < maxCount; n++)
{
var serieData = serie.GetDataList(m_DataZoom)[n];
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
if (!symbol.ShowSymbol(n, maxCount)) continue;
var highlight = serie.highlighted || serieData.highlighted;
var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
Expand All @@ -47,27 +49,27 @@ protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
float symbolSize = 0;
if (serie.highlighted || serieData.highlighted)
{
symbolSize = serie.symbol.GetSelectedSize(datas);
symbolSize = symbol.GetSelectedSize(datas);
}
else
{
symbolSize = serie.symbol.GetSize(datas);
symbolSize = symbol.GetSize(datas);
}
symbolSize *= rate;
if (symbolSize > 100) symbolSize = 100;
if (serie.type == SerieType.EffectScatter)
{
for (int count = 0; count < serie.symbol.animationSize.Count; count++)
for (int count = 0; count < symbol.animationSize.Count; count++)
{
var nowSize = serie.symbol.animationSize[count];
var nowSize = symbol.animationSize[count];
color.a = (symbolSize - nowSize) / symbolSize;
DrawSymbol(vh, serie.symbol.type, nowSize, symbolBorder, pos, color, toColor, serie.symbol.gap, cornerRadius);
DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
}
RefreshChart();
}
else
{
DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, pos, color, toColor, serie.symbol.gap, cornerRadius);
DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
}
}
if (!serie.animation.IsFinish())
Expand Down
Loading

0 comments on commit 17c8b76

Please sign in to comment.