3.0 - radar chart

This commit is contained in:
monitor1394
2022-01-22 21:08:26 +08:00
parent a8b2068029
commit d9840bef52
29 changed files with 471 additions and 249 deletions

View File

@@ -51,7 +51,6 @@ namespace XCharts
[SerializeField] private double m_Max;
[SerializeField] private double m_Min;
[SerializeField] private double[] m_Range = new double[2] { 0, 0 };
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// The name of indicator.
@@ -69,11 +68,6 @@ namespace XCharts
/// </summary>
public double min { get { return m_Min; } set { m_Min = value; } }
/// <summary>
/// the style of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
/// <summary>
/// the text conponent of indicator.
/// 指示器的文本组件。
/// </summary>
@@ -103,6 +97,7 @@ namespace XCharts
[SerializeField] private int m_SplitNumber = 5;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private AxisLine m_AxisLine = AxisLine.defaultAxisLine;
[SerializeField] private AxisName m_AxisName = AxisName.defaultAxisName;
[SerializeField] private AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField] private bool m_Indicator = true;
@@ -171,6 +166,15 @@ namespace XCharts
set { if (PropertyUtil.SetClass(ref m_AxisLine, value, true)) SetAllDirty(); }
}
/// <summary>
/// Name options for radar indicators.
/// 雷达图每个指示器名称的配置项。
/// </summary>
public AxisName axisName
{
get { return m_AxisName; }
set { if (PropertyUtil.SetClass(ref m_AxisName, value, true)) SetAllDirty(); }
}
/// <summary>
/// split line.
/// 分割线。
/// </summary>
@@ -288,6 +292,8 @@ namespace XCharts
center[1] = 0.4f;
splitLine.show = true;
splitArea.show = true;
axisName.show = true;
axisName.name = null;
}
private bool IsEqualsIndicatorList(List<Indicator> indicators1, List<Indicator> indicators2)
@@ -410,5 +416,31 @@ namespace XCharts
{
indicatorList.Clear();
}
public string GetFormatterIndicatorContent(int indicatorIndex)
{
var indicator = GetIndicator(indicatorIndex);
if (indicator == null)
return string.Empty;
else
return GetFormatterIndicatorContent(indicator.name);
}
public string GetFormatterIndicatorContent(string indicatorName)
{
if (string.IsNullOrEmpty(indicatorName))
return indicatorName;
if (string.IsNullOrEmpty(m_AxisName.formatter))
{
return indicatorName;
}
else
{
var content = m_AxisName.formatter;
FormatterHelper.ReplaceAxisLabelContent(ref content, indicatorName);
return content;
}
}
}
}

View File

@@ -40,23 +40,32 @@ namespace XCharts
radar.painter = chart.GetPainter(radar.index);
radar.refreshComponent = delegate ()
{
ChartHelper.HideAllObject(chart.transform, INDICATOR_TEXT + "_" + radar.index);
radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight);
var radarObject = ChartHelper.AddObject("Radar" + radar.index, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
radar.gameObject = radarObject;
radar.gameObject.hideFlags = chart.chartHideFlags;
var textStyle = radar.axisName.textStyle;
ChartHelper.HideAllObject(radarObject.transform, INDICATOR_TEXT);
for (int i = 0; i < radar.indicatorList.Count; i++)
{
var indicator = radar.indicatorList[i];
var pos = radar.GetIndicatorPosition(i);
var textStyle = indicator.textStyle;
var objName = INDICATOR_TEXT + "_" + radar.index + "_" + i;
var txt = ChartHelper.AddTextObject(objName, chart.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig),
textStyle, chart.theme.axis);
txt.gameObject.hideFlags = chart.chartHideFlags;
txt.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
txt.SetText(radar.indicatorList[i].name);
txt.SetActive(radar.indicator);
var objName = INDICATOR_TEXT + "_" + i;
var labelGameObject = ChartHelper.AddObject(objName, radarObject.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig));
var label = ChartHelper.GetOrAddComponent<ChartLabel>(labelGameObject);
label.label = ChartHelper.AddTextObject("Text", label.gameObject.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig), textStyle, chart.theme.common);
label.SetAutoSize(true);
label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
label.SetText(radar.GetFormatterIndicatorContent(i));
label.SetActive(radar.indicator);
label.color = textStyle.backgroundColor;
var offset = new Vector3(textStyle.offset.x, textStyle.offset.y);
AxisHelper.AdjustCircleLabelPos(txt, pos, radar.context.center, txtHig, offset);
AxisHelper.AdjustCircleLabelPos(label, pos, radar.context.center, txtHig, offset);
}
chart.RefreshBasePainter();
};