This commit is contained in:
monitor1394
2022-03-29 22:06:10 +08:00
parent b784900fda
commit 1ad87920d0
17 changed files with 130 additions and 117 deletions

View File

@@ -11,6 +11,15 @@ namespace XCharts.Editor
[CustomEditor(typeof(BaseChart), true)] [CustomEditor(typeof(BaseChart), true)]
public class BaseChartEditor : UnityEditor.Editor public class BaseChartEditor : UnityEditor.Editor
{ {
class Styles
{
public static readonly GUIContent btnAddSerie = new GUIContent("Add Serie", "");
public static readonly GUIContent btnAddComponent = new GUIContent("Add Main Component", "");
public static readonly GUIContent btnCovertXYAxis = new GUIContent("Covert XY Axis", "");
public static readonly GUIContent btnRebuildChartObject = new GUIContent("Rebuild Chart Object", "");
public static readonly GUIContent btnCheckWarning = new GUIContent("Check Warning", "");
public static readonly GUIContent btnHideWarning = new GUIContent("Hide Warning", "");
}
protected BaseChart m_Chart; protected BaseChart m_Chart;
protected SerializedProperty m_Script; protected SerializedProperty m_Script;
protected SerializedProperty m_EnableTextMeshPro; protected SerializedProperty m_EnableTextMeshPro;
@@ -102,8 +111,6 @@ namespace XCharts.Editor
m_SerieList.UpdateSeriesProperty(m_Series); m_SerieList.UpdateSeriesProperty(m_Series);
} }
OnStartInspectorGUI(); OnStartInspectorGUI();
EditorGUILayout.Space();
OnDebugInspectorGUI(); OnDebugInspectorGUI();
EditorGUILayout.Space(); EditorGUILayout.Space();
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
@@ -118,18 +125,23 @@ namespace XCharts.Editor
EditorGUILayout.PropertyField(m_Script); EditorGUILayout.PropertyField(m_Script);
EditorGUILayout.PropertyField(m_ChartName); EditorGUILayout.PropertyField(m_ChartName);
EditorGUILayout.PropertyField(m_RaycastTarget); EditorGUILayout.PropertyField(m_RaycastTarget);
if (XChartsMgr.IsRepeatChartName(m_Chart, m_ChartName.stringValue))
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("chart name is repeated: " + m_ChartName.stringValue, MessageType.Error);
EditorGUILayout.EndHorizontal();
}
} }
EditorGUILayout.PropertyField(m_Theme); EditorGUILayout.PropertyField(m_Theme);
EditorGUILayout.PropertyField(m_Settings); EditorGUILayout.PropertyField(m_Settings);
m_ComponentList.OnGUI(); m_ComponentList.OnGUI();
m_SerieList.OnGUI(); m_SerieList.OnGUI();
} }
protected virtual void OnDebugInspectorGUI() protected virtual void OnDebugInspectorGUI()
{ {
EditorGUILayout.PropertyField(m_DebugInfo, true); EditorGUILayout.PropertyField(m_DebugInfo, true);
EditorGUILayout.Space();
AddSerie(); AddSerie();
AddComponent(); AddComponent();
CheckWarning(); CheckWarning();
@@ -175,7 +187,7 @@ namespace XCharts.Editor
private void AddComponent() private void AddComponent()
{ {
if (GUILayout.Button("Add Component")) if (GUILayout.Button(Styles.btnAddComponent))
{ {
var menu = new GenericMenu(); var menu = new GenericMenu();
foreach (var type in GetMainComponentTypeNames()) foreach (var type in GetMainComponentTypeNames())
@@ -198,7 +210,7 @@ namespace XCharts.Editor
} }
private void AddSerie() private void AddSerie()
{ {
if (GUILayout.Button("Add Serie")) if (GUILayout.Button(Styles.btnAddSerie))
{ {
var menu = new GenericMenu(); var menu = new GenericMenu();
foreach (var type in GetSerieTypeNames()) foreach (var type in GetSerieTypeNames())
@@ -261,22 +273,22 @@ namespace XCharts.Editor
{ {
if (m_Chart.HasChartComponent<XAxis>() && m_Chart.HasChartComponent<YAxis>()) if (m_Chart.HasChartComponent<XAxis>() && m_Chart.HasChartComponent<YAxis>())
{ {
if (GUILayout.Button("Covert XY Axis")) if (GUILayout.Button(Styles.btnCovertXYAxis))
m_Chart.CovertXYAxis(0); m_Chart.CovertXYAxis(0);
} }
if (GUILayout.Button("Rebuild Chart Object")) if (GUILayout.Button(Styles.btnRebuildChartObject))
{ {
m_Chart.RebuildChartObject(); m_Chart.RebuildChartObject();
} }
if (m_CheckWarning) if (m_CheckWarning)
{ {
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Check Warning")) if (GUILayout.Button(Styles.btnCheckWarning))
{ {
m_CheckWarning = true; m_CheckWarning = true;
m_Chart.CheckWarning(); m_Chart.CheckWarning();
} }
if (GUILayout.Button("Hide Warning")) if (GUILayout.Button(Styles.btnHideWarning))
{ {
m_CheckWarning = false; m_CheckWarning = false;
} }
@@ -297,7 +309,7 @@ namespace XCharts.Editor
} }
else else
{ {
if (GUILayout.Button("Check warning")) if (GUILayout.Button(Styles.btnCheckWarning))
{ {
m_CheckWarning = true; m_CheckWarning = true;
m_Chart.CheckWarning(); m_Chart.CheckWarning();

View File

@@ -18,7 +18,6 @@ namespace XCharts.Editor
PropertyField(prop, "m_Position"); PropertyField(prop, "m_Position");
PropertyField(prop, "m_Offset"); PropertyField(prop, "m_Offset");
PropertyField(prop, "m_AutoOffset"); PropertyField(prop, "m_AutoOffset");
PropertyField(prop, "m_AutoColor");
PropertyField(prop, "m_Distance"); PropertyField(prop, "m_Distance");
PropertyField(prop, "m_Formatter"); PropertyField(prop, "m_Formatter");
PropertyField(prop, "m_NumericFormatter"); PropertyField(prop, "m_NumericFormatter");

View File

@@ -26,6 +26,7 @@ namespace XCharts.Editor
PropertyField(prop, "m_Rotate"); PropertyField(prop, "m_Rotate");
PropertyField(prop, "m_Offset"); PropertyField(prop, "m_Offset");
PropertyField(prop, "m_ExtraWidth"); PropertyField(prop, "m_ExtraWidth");
PropertyField(prop, "m_AutoColor");
PropertyField(prop, "m_Color"); PropertyField(prop, "m_Color");
PropertyField(prop, "m_AutoBackgroundColor"); PropertyField(prop, "m_AutoBackgroundColor");
PropertyField(prop, "m_BackgroundColor"); PropertyField(prop, "m_BackgroundColor");

View File

@@ -71,7 +71,7 @@ namespace XCharts.Runtime
public override void SetDefaultValue() public override void SetDefaultValue()
{ {
m_Show = false; m_Show = true;
m_Image = null; m_Image = null;
m_ImageType = Image.Type.Sliced; m_ImageType = Image.Type.Sliced;
m_ImageColor = Color.white; m_ImageColor = Color.white;

View File

@@ -33,32 +33,6 @@ namespace XCharts.Runtime
component.refreshComponent(); component.refreshComponent();
} }
//protected void DrawBackground(VertexHelper vh)
//{
//TODO: CooridateChart
// if (SeriesHelper.IsAnyClipSerie(m_Series))
// {
// var xLineDiff = xAxis0.axisLine.GetWidth(m_Theme.axis.lineWidth);
// var yLineDiff = yAxis0.axisLine.GetWidth(m_Theme.axis.lineWidth);
// var xSplitDiff = xAxis0.splitLine.GetWidth(m_Theme.axis.splitLineWidth);
// var ySplitDiff = yAxis0.splitLine.GetWidth(m_Theme.axis.splitLineWidth);
// foreach (var grid in m_Grids)
// {
// var cpty = grid.context.runtimeY + grid.context.runtimeHeight + ySplitDiff;
// var cp1 = new Vector3(grid.context.runtimeX - yLineDiff, grid.context.runtimeY - xLineDiff);
// var cp2 = new Vector3(grid.context.runtimeX - yLineDiff, cpty);
// var cp3 = new Vector3(grid.context.runtimeX + grid.context.runtimeWidth + xSplitDiff, cpty);
// var cp4 = new Vector3(grid.context.runtimeX + grid.context.runtimeWidth + xSplitDiff, grid.context.runtimeY - xLineDiff);
// var backgroundColor = ThemeHelper.GetBackgroundColor(m_Theme, m_Background);
// UGL.DrawQuadrilateral(vh, cp1, cp2, cp3, cp4, backgroundColor);
// }
// }
// else
// {
// base.DrawBackground(vh);
// }
// }
public override void DrawBase(VertexHelper vh) public override void DrawBase(VertexHelper vh)
{ {
if (!component.show) if (!component.show)

View File

@@ -1,6 +1,4 @@
 using UnityEngine;
using System;
using UnityEngine;
namespace XCharts.Runtime namespace XCharts.Runtime
{ {
@@ -69,7 +67,6 @@ namespace XCharts.Runtime
End End
} }
[SerializeField] private bool m_Show = true; [SerializeField] private bool m_Show = true;
[SerializeField] Position m_Position = Position.Outside; [SerializeField] Position m_Position = Position.Outside;
[SerializeField] private Vector3 m_Offset; [SerializeField] private Vector3 m_Offset;
@@ -81,7 +78,7 @@ namespace XCharts.Runtime
[SerializeField] private float m_BackgroundHeight = 0; [SerializeField] private float m_BackgroundHeight = 0;
[SerializeField] private string m_NumericFormatter = ""; [SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_AutoOffset = false; [SerializeField] private bool m_AutoOffset = false;
[SerializeField] private bool m_AutoColor = false;
[SerializeField] private TextStyle m_TextStyle = new TextStyle(); [SerializeField] private TextStyle m_TextStyle = new TextStyle();
private SerieLabelFormatterFunction m_FormatterFunction; private SerieLabelFormatterFunction m_FormatterFunction;
@@ -97,7 +94,6 @@ namespace XCharts.Runtime
m_BackgroundHeight = 0; m_BackgroundHeight = 0;
m_NumericFormatter = ""; m_NumericFormatter = "";
m_AutoOffset = false; m_AutoOffset = false;
m_AutoColor = false;
} }
/// <summary> /// <summary>
@@ -211,14 +207,7 @@ namespace XCharts.Runtime
get { return m_AutoOffset; } get { return m_AutoOffset; }
set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); } set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
} }
/// <summary>
/// 是否开启自动颜色。当开启时会根据已支持的serie自动设置颜色。
/// </summary>
public bool autoColor
{
get { return m_AutoColor; }
set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetAllDirty(); }
}
/// <summary> /// <summary>
/// the sytle of text. /// the sytle of text.

View File

@@ -20,6 +20,7 @@ namespace XCharts.Runtime
[SerializeField] private float m_Rotate = 0; [SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_ExtraWidth = 0; [SerializeField] private float m_ExtraWidth = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero; [SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private bool m_AutoColor = false;
[SerializeField] private Color m_Color = Color.clear; [SerializeField] private Color m_Color = Color.clear;
[SerializeField] private bool m_AutoBackgroundColor = false; [SerializeField] private bool m_AutoBackgroundColor = false;
[SerializeField] private Color m_BackgroundColor = Color.clear; [SerializeField] private Color m_BackgroundColor = Color.clear;
@@ -61,9 +62,15 @@ namespace XCharts.Runtime
get { return m_Offset; } get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); } set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
} }
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } } public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
/// <summary>
/// 是否开启自动颜色。当开启时,会自动设置颜色。
/// </summary>
public bool autoColor
{
get { return m_AutoColor; }
set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetAllDirty(); }
}
/// <summary> /// <summary>
/// the color of text. /// the color of text.
/// |文本的颜色。 /// |文本的颜色。
@@ -207,7 +214,9 @@ namespace XCharts.Runtime
font = textStyle.font; font = textStyle.font;
rotate = textStyle.rotate; rotate = textStyle.rotate;
offset = textStyle.offset; offset = textStyle.offset;
autoColor = textStyle.autoColor;
color = textStyle.color; color = textStyle.color;
autoBackgroundColor = textStyle.autoBackgroundColor;
backgroundColor = textStyle.backgroundColor; backgroundColor = textStyle.backgroundColor;
fontSize = textStyle.fontSize; fontSize = textStyle.fontSize;
fontStyle = textStyle.fontStyle; fontStyle = textStyle.fontStyle;
@@ -251,5 +260,13 @@ namespace XCharts.Runtime
{ {
return m_AutoAlign ? systemAlignment : alignment; return m_AutoAlign ? systemAlignment : alignment;
} }
public Color32 GetBackgroundColor(Color32 chartBackgroundColor)
{
if (m_AutoColor || ChartHelper.IsClearColor(m_BackgroundColor))
return chartBackgroundColor;
else
return m_BackgroundColor;
}
} }
} }

View File

@@ -198,7 +198,7 @@ namespace XCharts.Runtime
UGL.DrawDiamond(vh, rect.center, radius, color); UGL.DrawDiamond(vh, rect.center, radius, color);
break; break;
case Legend.Type.EmptyCircle: case Legend.Type.EmptyCircle:
var backgroundColor = chart.theme.GetBackgroundColor(chart.GetChartComponent<Background>()); var backgroundColor = chart.GetChartBackgroundColor();
UGL.DrawEmptyCricle(vh, rect.center, radius, 2 * chart.settings.legendIconLineWidth, UGL.DrawEmptyCricle(vh, rect.center, radius, 2 * chart.settings.legendIconLineWidth,
color, color, backgroundColor, 1f); color, color, backgroundColor, 1f);
break; break;

View File

@@ -78,12 +78,14 @@ namespace XCharts.Runtime
var element = ChartHelper.AddSerieLabel(textName, m_MarkLineLabelRoot.transform, label.backgroundWidth, var element = ChartHelper.AddSerieLabel(textName, m_MarkLineLabelRoot.transform, label.backgroundWidth,
label.backgroundHeight, color, label.textStyle, chart.theme); label.backgroundHeight, color, label.textStyle, chart.theme);
var isAutoSize = label.backgroundWidth == 0 || label.backgroundHeight == 0; var isAutoSize = label.backgroundWidth == 0 || label.backgroundHeight == 0;
var backgroundColor = label.textStyle.GetBackgroundColor(chart.GetChartBackgroundColor());
var item = ChartHelper.GetOrAddComponent<ChartLabel>(element); var item = ChartHelper.GetOrAddComponent<ChartLabel>(element);
item.SetLabel(element, isAutoSize, label.paddingLeftRight, label.paddingTopBottom); item.SetLabel(element, isAutoSize, label.paddingLeftRight, label.paddingTopBottom);
item.SetIconActive(false); item.SetIconActive(false);
item.SetActive(data.label.show); item.SetActive(data.label.show);
item.SetPosition(MarkLineHelper.GetLabelPosition(data)); item.SetPosition(MarkLineHelper.GetLabelPosition(data));
item.SetText(MarkLineHelper.GetFormatterContent(serie, data)); item.SetText(MarkLineHelper.GetFormatterContent(serie, data));
item.color = backgroundColor;
data.runtimeLabel = item; data.runtimeLabel = item;
}; };
data.refreshComponent(); data.refreshComponent();

View File

@@ -481,5 +481,11 @@ namespace XCharts.Runtime
m_PainterTop.material = material; m_PainterTop.material = material;
} }
} }
public Color32 GetChartBackgroundColor()
{
var background = GetChartComponent<Background>();
return theme.GetBackgroundColor(background);
}
} }
} }

View File

@@ -112,7 +112,7 @@ namespace XCharts.Runtime
Vector3 pos, Color32 color, Color32 toColor, Color32 emptyColor, Color32 borderColor, Vector3 pos, Color32 color, Color32 toColor, Color32 emptyColor, Color32 borderColor,
float gap, float[] cornerRadius, Vector3 startPos) float gap, float[] cornerRadius, Vector3 startPos)
{ {
var backgroundColor = theme.GetBackgroundColor(GetChartComponent<Background>()); var backgroundColor = GetChartBackgroundColor();
if (ChartHelper.IsClearColor(emptyColor)) if (ChartHelper.IsClearColor(emptyColor))
emptyColor = backgroundColor; emptyColor = backgroundColor;
var smoothness = settings.cicleSmoothness; var smoothness = settings.cicleSmoothness;

View File

@@ -597,7 +597,9 @@ namespace XCharts.Runtime
protected virtual void DrawBackground(VertexHelper vh) protected virtual void DrawBackground(VertexHelper vh)
{ {
if (HasChartComponent<Background>()) return; var background = GetChartComponent<Background>();
if (background != null && background.show)
return;
Vector3 p1 = new Vector3(chartX, chartY + chartHeight); Vector3 p1 = new Vector3(chartX, chartY + chartHeight);
Vector3 p2 = new Vector3(chartX + chartWidth, chartY + chartHeight); Vector3 p2 = new Vector3(chartX + chartWidth, chartY + chartHeight);
Vector3 p3 = new Vector3(chartX + chartWidth, chartY); Vector3 p3 = new Vector3(chartX + chartWidth, chartY);

View File

@@ -86,6 +86,33 @@ namespace XCharts.Runtime
return chartList.Contains(chart); return chartList.Contains(chart);
} }
public static bool IsRepeatChartName(BaseChart chart, string chartName = null)
{
if (chartName == null)
chartName = chart.chartName;
if (string.IsNullOrEmpty(chartName))
return false;
foreach (var temp in chartList)
{
if (temp != chart && chartName.Equals(temp.chartName))
return true;
}
return false;
}
public static string GetRepeatChartNameInfo(BaseChart chart, string chartName)
{
if (string.IsNullOrEmpty(chartName))
return string.Empty;
string result = "";
foreach (var temp in chartList)
{
if (temp != chart && chartName.Equals(temp.chartName))
result += ChartHelper.GetFullName(temp.transform) + "\n";
}
return result;
}
public static void RemoveAllChartObject() public static void RemoveAllChartObject()
{ {
if (chartList.Count == 0) if (chartList.Count == 0)

View File

@@ -16,15 +16,16 @@ namespace XCharts.Runtime
serie.gap = 10; serie.gap = 10;
serie.radius = new float[] { 0.3f, 0.35f }; serie.radius = new float[] { 0.3f, 0.35f };
serie.AddExtraComponent<LabelStyle>(); var label = serie.AddExtraComponent<LabelStyle>();
serie.label.show = true; label.show = true;
serie.label.position = LabelStyle.Position.Center; label.position = LabelStyle.Position.Center;
serie.label.formatter = "{d:f0}%"; label.formatter = "{d:f0}%";
serie.label.textStyle.fontSize = 28; label.textStyle.autoColor = true;
label.textStyle.fontSize = 28;
serie.AddExtraComponent<TitleStyle>(); var titleStyle = serie.AddExtraComponent<TitleStyle>();
serie.titleStyle.show = false; titleStyle.show = false;
serie.titleStyle.textStyle.offset = new Vector2(0, 30); titleStyle.textStyle.offset = new Vector2(0, 30);
var value = Random.Range(30, 90); var value = Random.Range(30, 90);
var max = 100; var max = 100;

View File

@@ -109,6 +109,33 @@ namespace XCharts.Runtime
paramList.Add(param); paramList.Add(param);
} }
public override Vector3 GetSerieDataLabelPosition(SerieData serieData, LabelStyle label)
{
var centerRadius = (serieData.context.outsideRadius + serieData.context.insideRadius) / 2;
var startAngle = serieData.context.startAngle;
var toAngle = serieData.context.toAngle;
switch (label.position)
{
case LabelStyle.Position.Center:
serieData.context.labelPosition = serie.context.center + label.offset;
break;
case LabelStyle.Position.Bottom:
var px1 = Mathf.Sin(startAngle * Mathf.Deg2Rad) * centerRadius;
var py1 = Mathf.Cos(startAngle * Mathf.Deg2Rad) * centerRadius;
var xDiff = serie.clockwise ? -label.distance : label.distance;
serieData.context.labelPosition = serie.context.center + new Vector3(px1 + xDiff, py1);
break;
case LabelStyle.Position.Top:
startAngle += serie.clockwise ? -label.distance : label.distance;
toAngle += serie.clockwise ? label.distance : -label.distance;
var px2 = Mathf.Sin(toAngle * Mathf.Deg2Rad) * centerRadius;
var py2 = Mathf.Cos(toAngle * Mathf.Deg2Rad) * centerRadius;
serieData.context.labelPosition = serie.context.center + new Vector3(px2, py2);
break;
}
return serieData.context.labelPosition;
}
public override void DrawSerie(VertexHelper vh) public override void DrawSerie(VertexHelper vh)
{ {
if (!serie.show || serie.animation.HasFadeOut()) return; if (!serie.show || serie.animation.HasFadeOut()) return;
@@ -134,7 +161,6 @@ namespace XCharts.Runtime
var itemToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, j, serieData.context.highlight); var itemToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, j, serieData.context.highlight);
var outsideRadius = serie.context.outsideRadius - j * (ringWidth + serie.gap); var outsideRadius = serie.context.outsideRadius - j * (ringWidth + serie.gap);
var insideRadius = outsideRadius - ringWidth; var insideRadius = outsideRadius - ringWidth;
var centerRadius = (outsideRadius + insideRadius) / 2;
var borderWidth = itemStyle.borderWidth; var borderWidth = itemStyle.borderWidth;
var borderColor = itemStyle.borderColor; var borderColor = itemStyle.borderColor;
var roundCap = serie.roundCap && insideRadius > 0; var roundCap = serie.roundCap && insideRadius > 0;
@@ -153,7 +179,6 @@ namespace XCharts.Runtime
Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, chart.settings.cicleSmoothness, Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, chart.settings.cicleSmoothness,
roundCap, serie.clockwise); roundCap, serie.clockwise);
DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1); DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1);
UpateLabelPosition(serie, serieData, j, startDegree, toDegree, centerRadius);
} }
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
@@ -233,34 +258,6 @@ namespace XCharts.Runtime
} }
} }
private void UpateLabelPosition(Serie serie, SerieData serieData, int index, float startAngle,
float toAngle, float centerRadius)
{
var label = serie.label;
if (label == null || !label.show) return;
if (serieData.labelObject == null) return;
switch (label.position)
{
case LabelStyle.Position.Center:
serieData.context.labelPosition = serie.context.center + label.offset;
break;
case LabelStyle.Position.Bottom:
var px1 = Mathf.Sin(startAngle * Mathf.Deg2Rad) * centerRadius;
var py1 = Mathf.Cos(startAngle * Mathf.Deg2Rad) * centerRadius;
var xDiff = serie.clockwise ? -label.distance : label.distance;
serieData.context.labelPosition = serie.context.center + new Vector3(px1 + xDiff, py1);
break;
case LabelStyle.Position.Top:
startAngle += serie.clockwise ? -label.distance : label.distance;
toAngle += serie.clockwise ? label.distance : -label.distance;
var px2 = Mathf.Sin(toAngle * Mathf.Deg2Rad) * centerRadius;
var py2 = Mathf.Cos(toAngle * Mathf.Deg2Rad) * centerRadius;
serieData.context.labelPosition = serie.context.center + new Vector3(px2, py2);
break;
}
serieData.labelObject.SetLabelPosition(serieData.context.labelPosition);
}
private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius) private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius)
{ {
var itemStyle = SerieHelper.GetItemStyle(serie, serieData); var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
@@ -294,23 +291,6 @@ namespace XCharts.Runtime
} }
} }
private void DrawRoundCap(VertexHelper vh, Serie serie, Vector3 centerPos, Color color,
float insideRadius, float outsideRadius, ref float drawStartDegree, ref float drawEndDegree)
{
if (serie.roundCap && insideRadius > 0 && drawStartDegree != drawEndDegree)
{
var width = (outsideRadius - insideRadius) / 2;
var radius = insideRadius + width;
var diffDegree = Mathf.Asin(width / radius) * Mathf.Rad2Deg;
drawStartDegree += serie.clockwise ? diffDegree : -diffDegree;
drawEndDegree -= serie.clockwise ? diffDegree : -diffDegree;
UGL.DrawRoundCap(vh, centerPos, width, radius, drawStartDegree, serie.clockwise, color, false);
UGL.DrawRoundCap(vh, centerPos, width, radius, drawEndDegree, serie.clockwise, color, true);
}
}
private int GetRingIndex(Vector2 local) private int GetRingIndex(Vector2 local)
{ {
var dist = Vector2.Distance(local, serie.context.center); var dist = Vector2.Distance(local, serie.context.center);

View File

@@ -233,8 +233,10 @@ namespace XCharts.Runtime
&& (iconStyle == null || !iconStyle.show)) && (iconStyle == null || !iconStyle.show))
return false; return false;
var dataAutoColor = (Color)chart.theme.GetColor(serieData.index);
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index); var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
var color = chart.theme.common.textColor; var color = serieLabel.textStyle.autoColor ? dataAutoColor : chart.theme.common.textColor;
var iconWidth = iconStyle != null ? iconStyle.width : 20; var iconWidth = iconStyle != null ? iconStyle.width : 20;
var iconHeight = iconStyle != null ? iconStyle.height : 20; var iconHeight = iconStyle != null ? iconStyle.height : 20;
var labelObj = SerieLabelPool.Get(textName, serieLabelRoot.transform, serieLabel, color, var labelObj = SerieLabelPool.Get(textName, serieLabelRoot.transform, serieLabel, color,
@@ -246,7 +248,7 @@ namespace XCharts.Runtime
item.SetIcon(iconImage); item.SetIcon(iconImage);
item.SetIconActive(iconStyle != null && iconStyle.show); item.SetIconActive(iconStyle != null && iconStyle.show);
if (serieLabel.textStyle.autoBackgroundColor) if (serieLabel.textStyle.autoBackgroundColor)
item.color = chart.theme.GetColor(serieData.index); item.color = dataAutoColor;
else else
item.color = serieLabel.textStyle.backgroundColor; item.color = serieLabel.textStyle.backgroundColor;
serieData.labelObject = item; serieData.labelObject = item;
@@ -317,7 +319,6 @@ namespace XCharts.Runtime
var iconStyle = SerieHelper.GetIconStyle(serie, serieData); var iconStyle = SerieHelper.GetIconStyle(serie, serieData);
var isIgnore = serie.IsIgnoreIndex(serieData.index, defaultDimension); var isIgnore = serie.IsIgnoreIndex(serieData.index, defaultDimension);
var currLabel = isHighlight && emphasisLabel != null ? emphasisLabel : serieLabel; var currLabel = isHighlight && emphasisLabel != null ? emphasisLabel : serieLabel;
serieData.labelObject.UpdateIcon(iconStyle); serieData.labelObject.UpdateIcon(iconStyle);
if (serie.show if (serie.show
&& currLabel != null && currLabel != null
@@ -339,6 +340,8 @@ namespace XCharts.Runtime
textColor = currLabel.textStyle.color; textColor = currLabel.textStyle.color;
else if (isInsidePosition) else if (isInsidePosition)
textColor = Color.white; textColor = Color.white;
if (currLabel.textStyle.autoColor && serie.useDataNameForColor)
textColor = chart.theme.GetColor(serieData.index);
//text rotate //text rotate
var rotate = currLabel.textStyle.rotate; var rotate = currLabel.textStyle.rotate;
if (currLabel.textStyle.rotate > 0 && isInsidePosition) if (currLabel.textStyle.rotate > 0 && isInsidePosition)

View File

@@ -138,7 +138,7 @@ namespace XCharts.Runtime
public Color32 GetBackgroundColor(Background background) public Color32 GetBackgroundColor(Background background)
{ {
if (background != null && background.show && background.hideThemeBackgroundColor) if (background != null && background.show && background.hideThemeBackgroundColor)
return ChartConst.clearColor32; return background.imageColor;
else else
return backgroundColor; return backgroundColor;
} }