mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 06:50:18 +00:00
增加RingChart环形图
This commit is contained in:
50
Runtime/Helper/SerieHelper.cs
Normal file
50
Runtime/Helper/SerieHelper.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieHelper
|
||||
{
|
||||
internal static Color GetItemBackgroundColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (serie.itemStyle.backgroundColor != Color.clear)
|
||||
{
|
||||
var color = serie.itemStyle.backgroundColor;
|
||||
if (highlight) color *= color;
|
||||
color.a *= serie.itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a = 0.2f;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color GetItemColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (serie.itemStyle.color != Color.clear)
|
||||
{
|
||||
var color = serie.itemStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= serie.itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= serie.itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Helper/SerieHelper.cs.meta
Normal file
11
Runtime/Helper/SerieHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f69933c37061c417d9cadd9e486e6785
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Runtime/Helper/SerieLabelHelper.cs
Normal file
128
Runtime/Helper/SerieLabelHelper.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieLabelHelper
|
||||
{
|
||||
public static void CheckLabel(Serie serie, ref bool m_ReinitLabel, ref bool m_UpdateLabelText)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Gauge:
|
||||
case SerieType.Ring:
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData != null)
|
||||
{
|
||||
if (serie.label.show && serie.show)
|
||||
{
|
||||
if (serieData.IsInitLabel())
|
||||
{
|
||||
serieData.SetLabelActive(true);
|
||||
m_UpdateLabelText = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ReinitLabel = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateLabelText(Series series, ThemeInfo themeInfo)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (!serie.label.show) continue;
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Gauge:
|
||||
SetGaugeLabelText(serie);
|
||||
break;
|
||||
case SerieType.Ring:
|
||||
SetRingLabelText(serie, themeInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index)
|
||||
{
|
||||
if (serie.label.color != Color.clear)
|
||||
{
|
||||
return serie.label.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return themeInfo.GetColor(index);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetGaugeLabelText(Serie serie)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData != null)
|
||||
{
|
||||
if (serieData.IsInitLabel())
|
||||
{
|
||||
var value = serieData.GetData(1);
|
||||
var total = serie.max;
|
||||
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
||||
serieData.SetLabelText(content);
|
||||
serieData.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
|
||||
if (serie.label.color != Color.clear)
|
||||
{
|
||||
serieData.SetLabelColor(serie.label.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetRingLabelText(Serie serie, ThemeInfo themeInfo)
|
||||
{
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
if (serieData.IsInitLabel())
|
||||
{
|
||||
if (!serie.show || !serieData.show)
|
||||
{
|
||||
serieData.SetLabelActive(false);
|
||||
continue;
|
||||
}
|
||||
var value = serieData.GetData(0);
|
||||
var total = serieData.GetData(1);
|
||||
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.SetLabelText(content);
|
||||
serieData.SetLabelColor(GetLabelColor(serie, themeInfo, i));
|
||||
|
||||
if (serie.label.position == SerieLabel.Position.Bottom)
|
||||
{
|
||||
var labelWidth = serieData.GetLabelWidth();
|
||||
if (serie.clockwise)
|
||||
serieData.SetLabelPosition(serieData.labelPosition - new Vector3(labelWidth / 2, 0));
|
||||
else
|
||||
serieData.SetLabelPosition(serieData.labelPosition + new Vector3(labelWidth / 2, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
serieData.SetLabelPosition(serieData.labelPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Helper/SerieLabelHelper.cs.meta
Normal file
11
Runtime/Helper/SerieLabelHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d74ec0ba2845e409ca2e1c85a3814939
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Runtime/Helper/TitleStyleHelper.cs
Normal file
43
Runtime/Helper/TitleStyleHelper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class TitleStyleHelper
|
||||
{
|
||||
public static void CheckTitle(Serie serie, ref bool m_ReinitTitle, ref bool m_UpdateTitleText)
|
||||
{
|
||||
if (serie.titleStyle.show)
|
||||
{
|
||||
if (serie.titleStyle.IsInited())
|
||||
{
|
||||
serie.titleStyle.UpdatePosition(serie.runtimeCenterPos);
|
||||
m_UpdateTitleText = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ReinitTitle = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateTitleText(Series series)
|
||||
{
|
||||
foreach (var serie in series.list) UpdateTitleText(serie);
|
||||
}
|
||||
|
||||
public static void UpdateTitleText(Serie serie)
|
||||
{
|
||||
if (serie.titleStyle.show)
|
||||
{
|
||||
serie.titleStyle.SetText(serie.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Helper/TitleStyleHelper.cs.meta
Normal file
11
Runtime/Helper/TitleStyleHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76af3a33fe0b643e4ac6e875864233c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user