mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 22:40:10 +00:00
增加Serie的iconStyle统一配置图标
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.07.18) Added `iconStyle` for serie
|
||||
* (2021.07.15) Added `MarkLine` (#142)
|
||||
* (2021.07.09) Optimize `BarChart` to set whether to show bars via `seriedata.show`
|
||||
* (2021.07.08) Optimize data storage type from `float` to `double`
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.07.18) 增加`Serie`的`iconStyle`统一配置图标
|
||||
* (2021.07.15) 增加`MarkLine`标线 (#142)
|
||||
* (2021.07.09) 优化`BarChart`可通过`serieData.show`设置是否显示柱条
|
||||
* (2021.07.08) 优化数据存储类型由`float`全部转为`double`
|
||||
|
||||
@@ -978,6 +978,7 @@ K线图系列。
|
||||
* `name`:数据项名称。
|
||||
* `selected`:该数据项是否被选中。
|
||||
* `radius`:自定义半径。可用在饼图中自定义某个数据项的半径。
|
||||
* `enableIconStyle`: 是否启用单个数据项的图标设置。
|
||||
* `iconStyle`:数据项图标样式。
|
||||
* `enableLabel`:是否启用单个数据项的标签设置。
|
||||
* `label`:单个数据项的标签设置。
|
||||
|
||||
@@ -872,6 +872,7 @@ K线图系列。
|
||||
* `name`: 数据项名称。
|
||||
* `selected`: 该数据项是否被选中。
|
||||
* `radius`: 自定义半径。可用在饼图中自定义某个数据项的半径。
|
||||
* `enableIconStyle`: 是否启用单个数据项的图标设置。
|
||||
* `iconStyle`: 数据项图标样式。
|
||||
* `enableLabel`: 是否启用单个数据项的标签设置。
|
||||
* `label`: 单个数据项的标签设置。
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_ShowAsPositiveNumber");
|
||||
PropertyField(prop, "m_Large");
|
||||
PropertyField(prop, "m_LargeThreshold");
|
||||
PropertyField(prop, "m_MarkLine");
|
||||
PropertyField(prop, "m_MarkLine");
|
||||
break;
|
||||
case SerieType.Pie:
|
||||
PropertyField(prop, "m_RoseType");
|
||||
@@ -200,6 +200,7 @@ namespace XCharts
|
||||
break;
|
||||
}
|
||||
PropertyField(prop, "m_ItemStyle");
|
||||
PropertyField(prop, "m_IconStyle");
|
||||
PropertyField(prop, "m_Label");
|
||||
PropertyField(prop, "m_Emphasis");
|
||||
PropertyField(prop, "m_Animation");
|
||||
@@ -400,6 +401,7 @@ namespace XCharts
|
||||
{
|
||||
EditorGUI.indentLevel += 2;
|
||||
var m_Ignore = serieData.FindPropertyRelative("m_Ignore");
|
||||
var m_EnableIcon = serieData.FindPropertyRelative("m_EnableIconStyle");
|
||||
var m_Icon = serieData.FindPropertyRelative("m_IconStyle");
|
||||
var m_EnableLabel = serieData.FindPropertyRelative("m_EnableLabel");
|
||||
var m_Label = serieData.FindPropertyRelative("m_Label");
|
||||
@@ -412,6 +414,7 @@ namespace XCharts
|
||||
EditorGUI.PropertyField(drawRect, m_Ignore);
|
||||
AddHeight(EditorGUI.GetPropertyHeight(m_Ignore));
|
||||
EditorGUI.PropertyField(drawRect, m_Icon);
|
||||
ChartEditorHelper.MakeBool(drawRect, m_EnableIcon, 1, "(enable)");
|
||||
AddHeight(EditorGUI.GetPropertyHeight(m_Icon));
|
||||
EditorGUI.PropertyField(drawRect, m_Symbol);
|
||||
ChartEditorHelper.MakeBool(drawRect, m_EnableSymbol, 1, "(enable)");
|
||||
|
||||
@@ -319,6 +319,7 @@ namespace XCharts
|
||||
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
|
||||
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
|
||||
[SerializeField] private TitleStyle m_TitleStyle = new TitleStyle();
|
||||
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
|
||||
[SerializeField] private MarkLine m_MarkLine = MarkLine.defaultMarkLine;
|
||||
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
|
||||
[SerializeField] private bool m_ShowDataName;
|
||||
@@ -862,6 +863,15 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetClass(ref m_MarkLine, value, true)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the icon of data.
|
||||
/// 数据项图标样式。
|
||||
/// </summary>
|
||||
public IconStyle iconStyle
|
||||
{
|
||||
get { return m_IconStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_IconStyle, value, true)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据项里的数据维数。
|
||||
/// </summary>
|
||||
public int showDataDimension { get { return m_ShowDataDimension; } set { m_ShowDataDimension = value; } }
|
||||
@@ -1097,6 +1107,7 @@ namespace XCharts
|
||||
gaugePointer.ClearVerticesDirty();
|
||||
titleStyle.ClearVerticesDirty();
|
||||
markLine.ClearVerticesDirty();
|
||||
iconStyle.ClearVerticesDirty();
|
||||
}
|
||||
|
||||
public override void ClearComponentDirty()
|
||||
@@ -1113,6 +1124,7 @@ namespace XCharts
|
||||
gaugePointer.ClearComponentDirty();
|
||||
titleStyle.ClearComponentDirty();
|
||||
markLine.ClearComponentDirty();
|
||||
iconStyle.ClearComponentDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1789,60 +1801,6 @@ namespace XCharts
|
||||
else return m_BarWidth * categoryWidth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置所有数据的图标是否显示
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
public void SetDataIconActive(bool flag)
|
||||
{
|
||||
foreach (var data in m_Data)
|
||||
{
|
||||
data.iconStyle.show = flag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标是否显示
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="flag"></param>
|
||||
public void SetDataIconActive(int dataIndex, bool flag)
|
||||
{
|
||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||
{
|
||||
var data = m_Data[dataIndex];
|
||||
data.iconStyle.show = flag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统一设置图标的尺寸
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void SetDataIconSize(float width, float height)
|
||||
{
|
||||
foreach (var data in m_Data)
|
||||
{
|
||||
data.iconStyle.width = width;
|
||||
data.iconStyle.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定index的数据图标的图片
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <param name="image"></param>
|
||||
public void SetDataIcon(int dataIndex, Sprite image)
|
||||
{
|
||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||
{
|
||||
var data = m_Data[dataIndex];
|
||||
data.iconStyle.sprite = image;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsIgnoreIndex(int index, int dimension = 1)
|
||||
{
|
||||
var serieData = GetSerieData(index);
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private bool m_Ignore = false;
|
||||
[SerializeField] private float m_Radius;
|
||||
[SerializeField] private bool m_EnableIconStyle = false;
|
||||
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
|
||||
[SerializeField] private bool m_EnableLabel = false;
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
@@ -58,6 +59,10 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||
/// <summary>
|
||||
/// 是否启用单个数据项的图标设置。
|
||||
/// </summary>
|
||||
public bool enableIconStyle { get { return m_EnableIconStyle; } set { m_EnableIconStyle = value; } }
|
||||
/// <summary>
|
||||
/// the icon of data.
|
||||
/// 数据项图标样式。
|
||||
/// </summary>
|
||||
@@ -185,6 +190,7 @@ namespace XCharts
|
||||
m_Show = true;
|
||||
m_Selected = false;
|
||||
m_CanShowLabel = true;
|
||||
m_EnableIconStyle = false;
|
||||
m_EnableSymbol = false;
|
||||
m_EnableLabel = false;
|
||||
m_EnableEmphasis = false;
|
||||
@@ -381,6 +387,10 @@ namespace XCharts
|
||||
{
|
||||
if (labelObject != null) labelObject.SetLabelActive(flag);
|
||||
}
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
if (labelObject != null) labelObject.SetIconActive(flag);
|
||||
}
|
||||
|
||||
public void SetPolygon(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
|
||||
{
|
||||
|
||||
@@ -419,6 +419,12 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static IconStyle GetIconStyle(Serie serie, SerieData serieData)
|
||||
{
|
||||
if(serieData.enableIconStyle) return serieData.iconStyle;
|
||||
else return serie.iconStyle;
|
||||
}
|
||||
|
||||
public static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (!serie.IsPerformanceMode() && serieData.enableSymbol) return serieData.symbol;
|
||||
|
||||
@@ -540,8 +540,9 @@ namespace XCharts
|
||||
if (m_SerieLabelRoot == null) return;
|
||||
if (count == -1) count = serie.dataCount;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
if (serie.IsPerformanceMode()) return;
|
||||
if (!serieLabel.show) return;
|
||||
if (!serieLabel.show && !iconStyle.show) return;
|
||||
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
|
||||
var color = Color.grey;
|
||||
if (serie.type == SerieType.Pie)
|
||||
@@ -555,13 +556,13 @@ namespace XCharts
|
||||
(Color)m_Theme.GetColor(serie.index);
|
||||
}
|
||||
var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, color,
|
||||
serieData.iconStyle.width, serieData.iconStyle.height, theme);
|
||||
iconStyle.width, iconStyle.height, theme);
|
||||
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
var item = new ChartLabel();
|
||||
item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
item.SetIcon(iconImage);
|
||||
item.SetIconActive(false);
|
||||
item.SetIconActive(iconStyle.show);
|
||||
serieData.labelObject = item;
|
||||
}
|
||||
|
||||
|
||||
@@ -1471,7 +1471,7 @@ namespace XCharts
|
||||
if (serieData.labelObject == null) continue;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
|
||||
serieData.index = j;
|
||||
if ((serieLabel.show || serieData.iconStyle.show) && j < serie.dataPoints.Count)
|
||||
if (serieLabel.show && j < serie.dataPoints.Count)
|
||||
{
|
||||
var pos = serie.dataPoints[j];
|
||||
|
||||
@@ -1482,48 +1482,8 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = serieData.data[1];
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Line:
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
var zeroPos = Vector3.zero;
|
||||
var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, n);
|
||||
if (serie.type == SerieType.Bar)
|
||||
{
|
||||
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[j];
|
||||
switch (serieLabel.position)
|
||||
{
|
||||
case SerieLabel.Position.Center:
|
||||
|
||||
pos = isYAxis ? new Vector3(bottomPos.x + (pos.x - bottomPos.x) / 2, pos.y) :
|
||||
new Vector3(pos.x, bottomPos.y + (pos.y - bottomPos.y) / 2);
|
||||
break;
|
||||
case SerieLabel.Position.Bottom:
|
||||
pos = isYAxis ? new Vector3(bottomPos.x, pos.y) : new Vector3(pos.x, bottomPos.y);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Internal_RefreshLabelPosition(serie, serieData, serieLabel, pos, serie.type == SerieType.Bar, isYAxis);
|
||||
m_RefreshLabel = true;
|
||||
serieData.labelPosition = pos;
|
||||
if (serieLabel.show) DrawLabelBackground(vh, serie, serieData);
|
||||
}
|
||||
}
|
||||
@@ -1535,10 +1495,50 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void Internal_RefreshLabelPosition(Serie serie, SerieData serieData, SerieLabel serieLabel, Vector3 pos, bool IsNeedCheckPosition, bool isYAxis)
|
||||
{
|
||||
if (IsNeedCheckPosition)
|
||||
{
|
||||
var value = serieData.data[1];
|
||||
var zeroPos = Vector3.zero;
|
||||
var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, serie.index);
|
||||
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(xAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX + xAxis.runtimeZeroXOffset, grid.runtimeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var grid = GetAxisGridOrDefault(yAxis);
|
||||
zeroPos = new Vector3(grid.runtimeX, grid.runtimeY + yAxis.runtimeZeroYOffset);
|
||||
}
|
||||
}
|
||||
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[serieData.index];
|
||||
switch (serieLabel.position)
|
||||
{
|
||||
case SerieLabel.Position.Center:
|
||||
|
||||
pos = isYAxis ? new Vector3(bottomPos.x + (pos.x - bottomPos.x) / 2, pos.y) :
|
||||
new Vector3(pos.x, bottomPos.y + (pos.y - bottomPos.y) / 2);
|
||||
break;
|
||||
case SerieLabel.Position.Bottom:
|
||||
pos = isYAxis ? new Vector3(bottomPos.x, pos.y) : new Vector3(pos.x, bottomPos.y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
serieData.labelPosition = pos;
|
||||
}
|
||||
|
||||
protected override void OnRefreshLabel()
|
||||
{
|
||||
base.OnRefreshLabel();
|
||||
var isYAxis = IsAnyYAxisIsCategory();
|
||||
var anyPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
|
||||
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(i);
|
||||
@@ -1546,7 +1546,6 @@ namespace XCharts
|
||||
if (!serie.IsCoordinateSerie()) continue;
|
||||
var total = serie.yTotal;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
|
||||
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
@@ -1554,14 +1553,17 @@ namespace XCharts
|
||||
if (j >= serie.dataPoints.Count)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
serieData.SetIconActive(false);
|
||||
continue;
|
||||
}
|
||||
var pos = serie.dataPoints[j];
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var dimension = 1;
|
||||
var isIgnore = serie.IsIgnoreIndex(j);
|
||||
Internal_RefreshLabelPosition(serie, serieData, serieLabel, pos, serie.type == SerieType.Bar, isYAxis);
|
||||
serieData.labelObject.SetPosition(serieData.labelPosition);
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
if (serie.show && serieLabel.show && serieData.canShowLabel && !isIgnore)
|
||||
{
|
||||
double value = 0;
|
||||
|
||||
@@ -499,9 +499,9 @@ namespace XCharts
|
||||
var currAngle = serieData.runtimePieHalfAngle;
|
||||
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel);
|
||||
|
||||
if (showLabel || serieData.iconStyle.show)
|
||||
if (showLabel)
|
||||
{
|
||||
serieData.SetLabelActive(showLabel);
|
||||
float rotate = 0;
|
||||
@@ -558,7 +558,7 @@ namespace XCharts
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
}
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
}
|
||||
|
||||
protected int GetPiePosIndex(Serie serie, Vector2 local)
|
||||
|
||||
@@ -88,13 +88,14 @@ namespace XCharts
|
||||
var serieData = serie.data[n];
|
||||
if (serieData.labelObject == null) continue;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
|
||||
var labelPos = serieData.labelPosition;
|
||||
if (serieLabel.margin != 0)
|
||||
{
|
||||
labelPos += serieLabel.margin * (labelPos - center).normalized;
|
||||
}
|
||||
serieData.labelObject.SetPosition(labelPos);
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
serieData.labelObject.UpdateIcon(iconStyle);
|
||||
if (serie.show && serieLabel.show && serieData.canShowLabel)
|
||||
{
|
||||
var value = serieData.GetCurrData(1);
|
||||
|
||||
Reference in New Issue
Block a user