mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 17:00:08 +00:00
3.0 - radar chart
This commit is contained in:
@@ -23,6 +23,7 @@ namespace XCharts
|
||||
}
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Formatter;
|
||||
[SerializeField] private Location m_Location;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
@@ -45,6 +46,15 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The formatter of indicator's name.
|
||||
/// 指示器名称显示的格式器。可用在雷达图。
|
||||
/// </summary>
|
||||
public string formatter
|
||||
{
|
||||
get { return m_Formatter; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Location of axis name.
|
||||
/// 坐标轴名称显示位置。
|
||||
/// </summary>
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace XCharts
|
||||
/// 区域填充样式。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class AreaStyle : ChildComponent, ISerieExtraComponent
|
||||
public class AreaStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Origin position of area.
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace XCharts
|
||||
/// toColor,toColor2可设置水平方向的渐变,如需要设置垂直方向的渐变,可使用VisualMap。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class LineStyle : ChildComponent
|
||||
public class LineStyle : ChildComponent, ISerieDataComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// 线的类型。
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace XCharts
|
||||
|
||||
private void InitLegend(Legend legend)
|
||||
{
|
||||
legend.painter = null; // legend component does not need to paint
|
||||
legend.painter = null;
|
||||
legend.refreshComponent = delegate ()
|
||||
{
|
||||
legend.OnChanged();
|
||||
@@ -55,9 +55,10 @@ namespace XCharts
|
||||
if (legend.show && legend.data.Count > 0)
|
||||
{
|
||||
datas = new List<string>();
|
||||
for (int i = 0; i < chart.m_LegendRealShowName.Count; i++)
|
||||
foreach (var data in legend.data)
|
||||
{
|
||||
if (legend.data.Contains(chart.m_LegendRealShowName[i])) datas.Add(chart.m_LegendRealShowName[i]);
|
||||
if (chart.m_LegendRealShowName.Contains(data) || chart.IsSerieName(data))
|
||||
datas.Add(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -130,13 +131,6 @@ namespace XCharts
|
||||
chart.OnLegendButtonExit(index, selectedName);
|
||||
});
|
||||
}
|
||||
if (legend.selectedMode == Legend.SelectedMode.Single)
|
||||
{
|
||||
for (int n = 0; n < chart.m_LegendRealShowName.Count; n++)
|
||||
{
|
||||
chart.OnLegendButtonClick(n, chart.m_LegendRealShowName[n], n == 0 ? true : false);
|
||||
}
|
||||
}
|
||||
LegendHelper.ResetItemPosition(legend, chart.chartPosition, chart.chartWidth, chart.chartHeight);
|
||||
};
|
||||
legend.refreshComponent();
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace XCharts
|
||||
UpdateRuntimeData(markArea);
|
||||
|
||||
var colorIndex = chart.GetLegendRealShowNameIndex(serie.serieName);
|
||||
var serieColor = SerieHelper.GetLineColor(serie, chart.theme, colorIndex, false);
|
||||
var serieColor = SerieHelper.GetLineColor(serie, null, chart.theme, colorIndex, false);
|
||||
var areaColor = markArea.itemStyle.GetColor(serieColor);
|
||||
UGL.DrawRectangle(vh, markArea.runtimeRect, areaColor, areaColor);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace XCharts
|
||||
var sp = Vector3.zero;
|
||||
var ep = Vector3.zero;
|
||||
var colorIndex = chart.GetLegendRealShowNameIndex(serie.serieName);
|
||||
var serieColor = SerieHelper.GetLineColor(serie, chart.theme, colorIndex, false);
|
||||
var serieColor = SerieHelper.GetLineColor(serie, null, chart.theme, colorIndex, false);
|
||||
animation.InitProgress(0, 1f);
|
||||
ResetTempMarkLineGroupData(markLine);
|
||||
if (m_TempGroupData.Count > 0)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace XCharts
|
||||
public class TitleStyle : ChildComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[FormerlySerializedAs("m_textStyle")]
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -357,7 +357,7 @@ namespace XCharts
|
||||
{
|
||||
var serie = series[i];
|
||||
serie.context.isTriggerByAxis = isTriggerByAxis;
|
||||
if (isTriggerByAxis)
|
||||
if (isTriggerByAxis && dataIndex >= 0)
|
||||
serie.context.pointerItemDataIndex = dataIndex;
|
||||
serie.handler.UpdateTooltipSerieParams(dataIndex, showCategory, category,
|
||||
tooltip.marker, tooltip.itemFormatter, tooltip.numericFormatter,
|
||||
|
||||
Reference in New Issue
Block a user