增加LiquidChart水位图

This commit is contained in:
monitor1394
2020-07-06 08:41:28 +08:00
parent cc23df6821
commit fe8fa90625
24 changed files with 14313 additions and 41 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.07.06) 增加`LiquidChart`水位图
* (2020.07.01) 增加`PolarChart`极坐标图表
* (2020.06.25) 发布`v1.5.2`版本
* (2020.06.25) 修复`BarChart`在数值为`0`时还会绘制一小部分柱条的问题

View File

@@ -0,0 +1,34 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEditor;
namespace XCharts
{
/// <summary>
/// Editor class used to edit UI LiquidChart.
/// </summary>
[CustomEditor(typeof(LiquidChart), false)]
public class LiquidChartEditor : BaseChartEditor
{
protected SerializedProperty m_Vessels;
protected override void OnEnable()
{
base.OnEnable();
m_Target = (LiquidChart)target;
m_Vessels = serializedObject.FindProperty("m_Vessels");
}
protected override void OnStartInspectorGUI()
{
base.OnStartInspectorGUI();
EditorGUILayout.PropertyField(m_Vessels, true);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 307a1578a6be1403c98fdc27d99d1808
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -30,6 +30,7 @@ namespace XCharts
SerializedProperty m_AxisIndex = prop.FindPropertyRelative("m_AxisIndex");
SerializedProperty m_RadarType = prop.FindPropertyRelative("m_RadarType");
SerializedProperty m_RadarIndex = prop.FindPropertyRelative("m_RadarIndex");
SerializedProperty m_VesselIndex = prop.FindPropertyRelative("m_VesselIndex");
SerializedProperty m_MinShow = prop.FindPropertyRelative("m_MinShow");
SerializedProperty m_MaxShow = prop.FindPropertyRelative("m_MaxShow");
SerializedProperty m_MaxCache = prop.FindPropertyRelative("m_MaxCache");
@@ -78,6 +79,10 @@ namespace XCharts
SerializedProperty m_Large = prop.FindPropertyRelative("m_Large");
SerializedProperty m_LargeThreshold = prop.FindPropertyRelative("m_LargeThreshold");
SerializedProperty m_AvoidLabelOverlap = prop.FindPropertyRelative("m_AvoidLabelOverlap");
SerializedProperty m_WaveHeight = prop.FindPropertyRelative("m_WaveHeight");
SerializedProperty m_WaveLength = prop.FindPropertyRelative("m_WaveLength");
SerializedProperty m_WaveSpeed = prop.FindPropertyRelative("m_WaveSpeed");
SerializedProperty m_WaveOffset = prop.FindPropertyRelative("m_WaveOffset");
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");
int index = InitToggle(prop);
@@ -322,6 +327,26 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Liquid:
EditorGUI.PropertyField(drawRect, m_VesselIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Min);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Max);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_WaveLength);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_WaveHeight);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_WaveSpeed);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_WaveOffset);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
break;
}
EditorGUI.PropertyField(drawRect, m_Animation);
drawRect.y += EditorGUI.GetPropertyHeight(m_Animation);
@@ -589,6 +614,12 @@ namespace XCharts
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Liquid:
height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
}
if (m_DataFoldout[index])
{

View File

@@ -0,0 +1,68 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(Vessel), true)]
public class VesselDrawer : PropertyDrawer
{
private bool m_VesselModuleToggle = false;
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Shape = prop.FindPropertyRelative("m_Shape");
SerializedProperty m_Center = prop.FindPropertyRelative("m_Center");
SerializedProperty m_Radius = prop.FindPropertyRelative("m_Radius");
SerializedProperty m_ShapeWidth = prop.FindPropertyRelative("m_ShapeWidth");
SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap");
SerializedProperty m_Smoothness = prop.FindPropertyRelative("m_Smoothness");
SerializedProperty m_AutoColor = prop.FindPropertyRelative("m_AutoColor");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
int index = ChartEditorHelper.GetIndexFromPath(prop);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_VesselModuleToggle, "Vessel " + index, show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_VesselModuleToggle)
{
EditorGUI.indentLevel++;
EditorGUI.PropertyField(drawRect, m_Shape);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ShapeWidth);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Gap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
ChartEditorHelper.MakeTwoField(ref drawRect, pos.width, m_Center, "Center");
EditorGUI.PropertyField(drawRect, m_Radius);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AutoColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Smoothness);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.indentLevel--;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (m_VesselModuleToggle)
return 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
else
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 744a68155f2f349dc8fe26536ec83f80
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -134,5 +134,12 @@ namespace XCharts
{
AddChart<PolarChart>("PolarChart");
}
[MenuItem("XCharts/LiquidChart", priority = 53)]
[MenuItem("GameObject/XCharts/LiquidChart", priority = 53)]
public static void AddLiquidChart()
{
AddChart<LiquidChart>("LiquidChart");
}
}
}

View File

@@ -0,0 +1,61 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public partial class LiquidChart
{
/// <summary>
/// 容器组件列表。
/// </summary>
public List<Vessel> vessels { get { return m_Vessels; } }
/// <summary>
/// 移除所有容器组件。
/// </summary>
public void RemoveVessel()
{
m_Vessels.Clear();
}
/// <summary>
/// 添加容器组件。
/// </summary>
public void AddVessel(Vessel vessel)
{
m_Vessels.Add(vessel);
}
/// <summary>
/// 添加容器组件。
/// </summary>
public Vessel AddVessel(Vessel.Shape shape, Vector2 center, float radius)
{
var vessel = new Vessel();
vessel.shape = shape;
vessel.radius = radius;
vessel.center[0] = center.x;
vessel.center[1] = center.y;
AddVessel(vessel);
return vessel;
}
/// <summary>
/// 获得指定索引的容器组件。
/// </summary>
/// <param name="radarIndex"></param>
/// <returns></returns>
public Vessel GetVessel(int vesselIndex)
{
if (vesselIndex < 0 || vesselIndex > m_Vessels.Count - 1) return null;
return m_Vessels[vesselIndex];
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fd14dec4102b848f699bbf42babbe4c4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -56,6 +56,10 @@ namespace XCharts
/// 环形图。只支持一个数据的环形图。
/// </summary>
Ring,
/// <summary>
/// 水位图。
/// </summary>
Liquid,
}
/// <summary>
@@ -218,6 +222,7 @@ namespace XCharts
[SerializeField] private string m_Stack;
[SerializeField] [Range(0, 1)] private int m_AxisIndex = 0;
[SerializeField] private int m_RadarIndex = 0;
[SerializeField] private int m_VesselIndex = 0;
[SerializeField] protected int m_MinShow;
[SerializeField] protected int m_MaxShow;
[SerializeField] protected int m_MaxCache;
@@ -274,6 +279,10 @@ namespace XCharts
[SerializeField] private bool m_Large = true;
[SerializeField] private int m_LargeThreshold = 200;
[SerializeField] private bool m_AvoidLabelOverlap = false;
[SerializeField] private float m_WaveHeight = 10f;
[SerializeField] private float m_WaveLength = 20f;
[SerializeField] private float m_WaveSpeed = 5f;
[SerializeField] private float m_WaveOffset = 0f;
[SerializeField] private RadarType m_RadarType = RadarType.Multiple;
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
@@ -347,6 +356,15 @@ namespace XCharts
set { if (PropertyUtility.SetStruct(ref m_RadarIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// Index of vesel component that liquid chart uses.
/// 水位图所使用的 vessel 组件的 index。
/// </summary>
public int vesselIndex
{
get { return m_VesselIndex; }
set { if (PropertyUtility.SetStruct(ref m_VesselIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// The min number of data to show in chart.
/// 系列所显示数据的最小索引
/// </summary>
@@ -796,6 +814,39 @@ namespace XCharts
set { if (PropertyUtility.SetStruct(ref m_AvoidLabelOverlap, value)) SetVerticesDirty(); }
}
/// <summary>
/// Wave length of the wave, which is relative to the diameter.
/// 波长。为0-1小数时指直线的百分比。
/// </summary>
public float waveLength
{
get { return m_WaveLength; }
set { if (PropertyUtility.SetStruct(ref m_WaveLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// 波高。
/// </summary>
public float waveHeight
{
get { return m_WaveHeight; }
set { if (PropertyUtility.SetStruct(ref m_WaveHeight, value)) SetVerticesDirty(); }
}
/// <summary>
/// 波偏移。
/// </summary>
public float waveOffset
{
get { return m_WaveOffset; }
set { if (PropertyUtility.SetStruct(ref m_WaveOffset, value)) SetVerticesDirty(); }
}
/// <summary>
/// 波速。正数时左移,负数时右移。
/// </summary>
public float waveSpeed
{
get { return m_WaveSpeed; }
set { if (PropertyUtility.SetStruct(ref m_WaveSpeed, value)) SetVerticesDirty(); }
}
/// <summary>
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。
/// </summary>
public List<SerieData> data { get { return m_Data; } }
@@ -891,7 +942,9 @@ namespace XCharts
/// 饼图的数据项之和
/// </summary>
public float runtimePieDataTotal { get; internal set; }
public float runtimeWaveSpeed { get; internal set; }
internal int runtimeLastCheckDataCount { get; set; }
internal float runtimeCheckValue { get; set; }
public bool nameDirty { get { return m_NameDirty; } }
private void SetNameDirty()

View File

@@ -0,0 +1,176 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Vessel component for liquid chart.
/// <para>
/// 容器组件。
/// 一般用于LiquidChart。
/// </para>
/// </summary>
[Serializable]
public class Vessel : MainComponent
{
public enum Shape
{
/// <summary>
/// 圆形
/// </summary>
Circle,
/// <summary>
/// 正方形。
/// </summary>
Rect,
/// <summary>
/// 三角形。
/// </summary>
Triangle,
/// <summary>
/// 菱形。
/// </summary>
Diamond,
/// <summary>
/// 不显示标记。
/// </summary>
None,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Shape m_Shape = Shape.Circle;
[SerializeField] private float m_ShapeWidth = 5f;
[SerializeField] private float m_Gap = 10f;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private bool m_AutoColor = true;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private float m_Radius = 0.5f;
[SerializeField] [Range(0.5f, 10f)] private float m_Smoothness = 1f;
/// <summary>
/// Whether to show the grid in rectangular coordinate.
/// 是否显示直角坐标系网格。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 形状。
/// </summary>
public Shape shape
{
get { return m_Shape; }
set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetVerticesDirty(); }
}
/// <summary>
/// 容器宽度。
/// </summary>
public float shapeWidth
{
get { return m_ShapeWidth; }
set { if (PropertyUtility.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 间隙
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心点。数组的第一项是横坐标,第二项是纵坐标。
/// 当值为0-1之间时表示百分比设置成百分比时第一项是相对于容器宽度第二项是相对于容器高度。
/// </summary>
public float[] center
{
get { return m_Center; }
set { if (value != null) { m_Center = value; SetAllDirty(); } }
}
/// <summary>
/// 半径。
/// </summary>
public float radius
{
get { return m_Radius; }
set { if (PropertyUtility.SetStruct(ref m_Radius, value)) SetAllDirty(); }
}
/// <summary>
/// 水波平滑度。
/// </summary>
public float smoothness
{
get { return m_Smoothness; }
set { if (PropertyUtility.SetStruct(ref m_Smoothness, value)) SetAllDirty(); }
}
/// <summary>
/// Background color of polar, which is transparent by default.
/// 背景色,默认透明。
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 容器颜色。默认和serie一致。
/// </summary>
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// 是否自动颜色。为true时颜色会和serie一致。
/// </summary>
public bool autoColor
{
get { return m_AutoColor; }
set { if (PropertyUtility.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); }
}
public int index { get; internal set; }
/// <summary>
/// the runtime center position of vessel.
/// 运行时中心点。
/// </summary>
public Vector3 runtimeCenterPos { get; internal set; }
/// <summary>
/// the runtime radius of vessel.
/// 运行时半径。
/// </summary>
public float runtimeRadius { get; internal set; }
/// <summary>
/// 运行时内半径。
/// </summary>
public float runtimeInnerRadius { get; internal set; }
public static Vessel defaultVessel
{
get
{
var vessel = new Vessel
{
m_Show = true,
m_Shape = Shape.Circle,
m_ShapeWidth = 5,
m_Gap = 10,
m_Radius = 0.35f,
m_AutoColor = true,
m_Color = new Color32(70, 70, 240, 255),
m_Smoothness = 1
};
vessel.center[0] = 0.5f;
vessel.center[1] = 0.45f;
return vessel;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04afad352c62a405691c66f18c3f9db7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -49,7 +49,7 @@ namespace XCharts
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName);
UpdateAxisLabel();
}
}

View File

@@ -446,7 +446,7 @@ namespace XCharts
count++;
}
}
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName);
}
protected void AddSerieLabel(Serie serie, SerieData serieData, int count = -1)

View File

@@ -44,6 +44,7 @@ namespace XCharts
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
{
if (serie == null) return Color.clear;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);

View File

@@ -4,6 +4,7 @@
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -41,11 +42,12 @@ namespace XCharts
}
}
public static void UpdateLabelText(Series series, ThemeInfo themeInfo)
public static void UpdateLabelText(Series series, ThemeInfo themeInfo, List<string> legendRealShowName)
{
foreach (var serie in series.list)
{
if (!serie.label.show) continue;
var colorIndex = legendRealShowName.IndexOf(serie.name);
switch (serie.type)
{
case SerieType.Gauge:
@@ -54,6 +56,9 @@ namespace XCharts
case SerieType.Ring:
SetRingLabelText(serie, themeInfo);
break;
case SerieType.Liquid:
SetLiquidLabelText(serie, themeInfo, colorIndex);
break;
}
}
}
@@ -176,6 +181,28 @@ namespace XCharts
}
}
private static void SetLiquidLabelText(Serie serie, ThemeInfo themeInfo, int colorIndex)
{
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
if (serieLabel.show && serieData.labelObject != null)
{
if (!serie.show || !serieData.show)
{
serieData.SetLabelActive(false);
return;
}
var value = serieData.GetData(1);
var total = serie.max - serie.min;
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
serieData.SetLabelActive(true);
serieData.labelObject.SetText(content);
serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, colorIndex));
serieData.labelObject.SetLabelPosition(serieData.labelPosition + serieLabel.offset);
}
}
public static void UpdatePieLabelPosition(Serie serie, SerieData serieData)
{
if (serieData.labelObject == null) return;

View File

@@ -191,6 +191,15 @@ namespace XCharts
return GetLastStackSerie(series, serie);
}
internal static Serie GetSerieByVesselIndex(Series series, int vesselIndex)
{
foreach (var serie in series.list)
{
if (serie.vesselIndex == vesselIndex) return serie;
}
return null;
}
/// <summary>
/// 是否由系列在用指定索引的axis
/// </summary>

View File

@@ -0,0 +1,39 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public static class VesselHelper
{
internal static Color GetColor(Vessel vessel, Serie serie, ThemeInfo themeInfo, List<string> legendRealShowName)
{
if (serie != null && vessel.autoColor)
{
var colorIndex = legendRealShowName.IndexOf(serie.name);
return SerieHelper.GetItemColor(serie, null, themeInfo, colorIndex, false);
}
else
{
return vessel.color;
}
}
internal static void UpdateVesselCenter(Vessel vessel, Vector3 chartPosition, float chartWidth, float chartHeight)
{
if (vessel.center.Length < 2) return;
var centerX = vessel.center[0] <= 1 ? chartWidth * vessel.center[0] : vessel.center[0];
var centerY = vessel.center[1] <= 1 ? chartHeight * vessel.center[1] : vessel.center[1];
var checkWidth = Mathf.Min(chartWidth, chartHeight);
vessel.runtimeCenterPos = chartPosition + new Vector3(centerX, centerY);
vessel.runtimeRadius = ChartHelper.GetRuntimeRelativeOrAbsoluteValue(vessel.radius, checkWidth);
vessel.runtimeInnerRadius = vessel.runtimeRadius - vessel.shapeWidth - vessel.gap;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0c82cb73437a4004bf946cf4dcaa567
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,253 @@
using System.Linq;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// 水位图
/// </summary>
[AddComponentMenu("XCharts/LiquidChart", 22)]
[ExecuteInEditMode]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
public partial class LiquidChart : BaseChart
{
[SerializeField] private List<Vessel> m_Vessels = new List<Vessel>();
private bool m_UpdateLabelText = false;
protected override void Awake()
{
base.Awake();
UpdateRuntimeValue();
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName);
}
#if UNITY_EDITOR
protected override void Reset()
{
base.Reset();
m_Title.text = "LiquidChart";
RemoveData();
RemoveVessel();
AddVessel(Vessel.defaultVessel);
var serie = AddSerie(SerieType.Liquid, "serie1");
serie.min = 0;
serie.max = 100;
serie.label.show = true;
serie.label.fontSize = 40;
serie.label.formatter = "{d}%";
serie.label.color = new Color32(70, 70, 240, 255);
AddData(0, UnityEngine.Random.Range(0, 100));
}
protected override void OnValidate()
{
base.OnValidate();
RefreshChart();
}
#endif
protected override void OnSizeChanged()
{
base.OnSizeChanged();
UpdateRuntimeValue();
m_UpdateLabelText = true;
}
protected override void Update()
{
base.Update();
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName);
}
}
protected override void DrawChart(VertexHelper vh)
{
base.DrawChart(vh);
UpdateRuntimeValue();
DrawVesselBackground(vh);
DrawSeries(vh);
DrawVessel(vh);
}
private void UpdateRuntimeValue()
{
for (int i = 0; i < m_Vessels.Count; i++)
{
var vessel = m_Vessels[i];
vessel.index = i;
VesselHelper.UpdateVesselCenter(vessel, m_ChartPosition, m_ChartWidth, m_ChartHeight);
}
}
private void DrawVesselBackground(VertexHelper vh)
{
for (int i = 0; i < m_Vessels.Count; i++)
{
var vessel = m_Vessels[i];
if (vessel.backgroundColor.a != 0)
{
var cenPos = vessel.runtimeCenterPos;
var radius = vessel.runtimeRadius;
var serie = SeriesHelper.GetSerieByVesselIndex(m_Series, vessel.index);
ChartDrawer.DrawCricle(vh, cenPos, vessel.runtimeInnerRadius, vessel.backgroundColor, m_Settings.cicleSmoothness);
}
}
}
private void DrawVessel(VertexHelper vh)
{
for (int i = 0; i < m_Vessels.Count; i++)
{
var vessel = m_Vessels[i];
vessel.index = i;
DrawCirleVessel(vh, vessel);
}
}
private void DrawCirleVessel(VertexHelper vh, Vessel vessel)
{
var cenPos = vessel.runtimeCenterPos;
var radius = vessel.runtimeRadius;
var serie = SeriesHelper.GetSerieByVesselIndex(m_Series, vessel.index);
var vesselColor = VesselHelper.GetColor(vessel, serie, m_ThemeInfo, m_LegendRealShowName);
ChartDrawer.DrawDoughnut(vh, cenPos, radius - vessel.shapeWidth, radius, vesselColor, Color.clear, m_Settings.cicleSmoothness);
}
private void DrawSeries(VertexHelper vh)
{
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.GetSerie(i);
if (!serie.show) continue;
DrawSerie(vh, serie);
}
}
private void DrawSerie(VertexHelper vh, Serie serie)
{
var vessel = GetVessel(serie.vesselIndex);
if (vessel == null) return;
var cenPos = vessel.runtimeCenterPos;
var radius = vessel.runtimeInnerRadius;
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
var value = serieData.GetData(1);
if (serie.runtimeCheckValue != value)
{
serie.runtimeCheckValue = value;
m_UpdateLabelText = true;
}
if (serieData.labelPosition != cenPos)
{
serieData.labelPosition = cenPos;
m_UpdateLabelText = true;
}
if (value == 0) return;
var colorIndex = m_LegendRealShowName.IndexOf(serie.name);
var realHig = (value - serie.min) / (serie.max - serie.min) * radius * 2;
serie.animation.InitProgress(1, 0, realHig);
var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail();
var a = Mathf.Abs(radius - hig + (hig > radius ? serie.waveHeight : -serie.waveHeight));
var diff = Mathf.Sqrt(radius * radius - Mathf.Pow(a, 2));
var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, false);
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, false);
if (hig >= 2 * radius)
{
ChartDrawer.DrawCricle(vh, cenPos, radius, toColor, m_Settings.cicleSmoothness);
}
else
{
var startY = cenPos.y - radius + hig;
var waveStartPos = new Vector3(cenPos.x - diff, startY);
var waveEndPos = new Vector3(cenPos.x + diff, startY);
var startX = hig > radius ? cenPos.x - radius : waveStartPos.x;
var endX = hig > radius ? cenPos.x + radius : waveEndPos.x;
var step = vessel.smoothness;
if (step < 0.5f) step = 0.5f;
var lup = hig > radius ? new Vector3(cenPos.x - radius, cenPos.y) : waveStartPos;
var ldp = lup;
var nup = Vector3.zero;
var ndp = Vector3.zero;
var angle = 0f;
serie.runtimeWaveSpeed += serie.waveSpeed * Time.deltaTime;
var isStarted = false;
var isEnded = false;
while (startX < endX)
{
startX += step;
if (startX > endX) startX = endX;
if (startX > waveStartPos.x && !isStarted)
{
startX = waveStartPos.x;
isStarted = true;
}
if (startX > waveEndPos.x && !isEnded)
{
startX = waveEndPos.x;
isEnded = true;
}
var py = Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2));
if (startX < waveStartPos.x || startX > waveEndPos.x)
{
nup = new Vector3(startX, cenPos.y + py);
}
else
{
var py2 = serie.waveHeight * Mathf.Sin(1 / serie.waveLength * angle + serie.runtimeWaveSpeed + serie.waveOffset);
var nupY = waveStartPos.y + py2;
if (nupY > cenPos.y + py) nupY = cenPos.y + py;
else if (nupY < cenPos.y - py) nupY = cenPos.y - py;
nup = new Vector3(startX, nupY);
angle += step;
}
ndp = new Vector3(startX, cenPos.y - py);
if (!ChartHelper.IsValueEqualsColor(color, toColor))
{
var colorMin = cenPos.y - radius;
var colorMax = startY + serie.waveHeight;
var tcolor1 = Color.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin));
var tcolor2 = Color.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin));
ChartDrawer.DrawPolygon(vh, lup, nup, ndp, ldp, tcolor1, tcolor2);
}
else
{
ChartDrawer.DrawPolygon(vh, lup, nup, ndp, ldp, color);
}
lup = nup;
ldp = ndp;
}
}
if (serie.waveSpeed != 0 && Application.isPlaying)
{
RefreshChart();
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(realHig);
m_IsPlayingAnimation = true;
RefreshChart();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 41f7e109291bd44de96fccf526e9c7f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -34,7 +34,7 @@ namespace XCharts
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo, m_LegendRealShowName);
}
}
@@ -331,7 +331,7 @@ namespace XCharts
if (index < 0) continue;
showTooltip = true;
var content = TooltipHelper.GetFormatterContent(m_Tooltip, index, m_Series, m_ThemeInfo);
TooltipHelper.SetContentAndPosition(tooltip,content,chartRect);
TooltipHelper.SetContentAndPosition(tooltip, content, chartRect);
}
m_Tooltip.SetActive(showTooltip);
}

View File

@@ -792,5 +792,21 @@ namespace XCharts
return new Vector3(-dire.y / dire.x, 1, 0).normalized;
}
}
public static float GetRuntimeRelativeOrAbsoluteValue(float check, float total)
{
if (check <= 0)
{
return 0;
}
else if (check <= 1)
{
return total * check;
}
else
{
return check;
}
}
}
}

File diff suppressed because it is too large Load Diff