增加GaugeChart仪表盘

This commit is contained in:
monitor1394
2019-11-30 21:24:04 +08:00
parent 05d2a01103
commit e57a1a7a1c
52 changed files with 2673 additions and 338 deletions

View File

@@ -208,12 +208,52 @@ namespace XCharts
/// the current minimun value.
/// 当前最小值。
/// </summary>
public float runtimeMinValue { get; internal set; }
public float runtimeMinValue
{
get { return m_RuntimeMinValue; }
internal set
{
if (value != m_RuntimeMinValue)
{
if (m_RuntimeMinValueFirstChanged)
{
m_RuntimeMinValueFirstChanged = false;
}
else
{
m_RuntimeLastMinValue = m_RuntimeMinValue;
m_RuntimeMinValueChanged = true;
m_RuntimeMinValueUpdateTime = Time.time;
}
m_RuntimeMinValue = value;
}
}
}
/// <summary>
/// the current maximum value.
/// 当前最大值。
/// </summary>
public float runtimeMaxValue { get; internal set; }
public float runtimeMaxValue
{
get { return m_RuntimeMaxValue; }
internal set
{
if (value != m_RuntimeMaxValue)
{
if (m_RuntimeMaxValueFirstChanged)
{
m_RuntimeMaxValueFirstChanged = false;
}
else
{
m_RuntimeLastMaxValue = m_RuntimeMaxValue;
m_RuntimeMaxValueChanged = true;
m_RuntimeMaxValueUpdateTime = Time.time;
}
m_RuntimeMaxValue = value;
}
}
}
/// <summary>
/// the x offset of zero position.
/// 坐标轴原点在X轴的偏移。
@@ -232,6 +272,16 @@ namespace XCharts
private GameObject m_TooltipLabel;
private Text m_TooltipLabelText;
private RectTransform m_TooltipLabelRect;
private float m_RuntimeMinValue;
private float m_RuntimeLastMinValue;
private bool m_RuntimeMinValueChanged;
private float m_RuntimeMinValueUpdateTime;
private float m_RuntimeMaxValue;
private float m_RuntimeLastMaxValue;
private bool m_RuntimeMaxValueChanged;
private float m_RuntimeMaxValueUpdateTime;
private bool m_RuntimeMinValueFirstChanged = true;
private bool m_RuntimeMaxValueFirstChanged = true;
public void Copy(Axis other)
{
@@ -528,13 +578,15 @@ namespace XCharts
/// 更新刻度标签文字
/// </summary>
/// <param name="dataZoom"></param>
internal void UpdateLabelText(float coordinateWidth, DataZoom dataZoom, bool forcePercent)
internal void UpdateLabelText(float coordinateWidth, DataZoom dataZoom, bool forcePercent, float duration)
{
var minValue = GetCurrMinValue(duration);
var maxValue = GetCurrMaxValue(duration);
for (int i = 0; i < axisLabelTextList.Count; i++)
{
if (axisLabelTextList[i] != null)
{
axisLabelTextList[i].text = GetLabelName(coordinateWidth, i, runtimeMinValue, runtimeMaxValue, dataZoom, forcePercent);
axisLabelTextList[i].text = GetLabelName(coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent);
}
}
}
@@ -591,7 +643,7 @@ namespace XCharts
/// </summary>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
internal void AdjustMinMaxValue(ref float minValue, ref float maxValue)
internal void AdjustMinMaxValue(ref float minValue, ref float maxValue, bool needFormat)
{
if (minMaxType == Axis.AxisMinMaxType.Custom)
{
@@ -609,28 +661,74 @@ namespace XCharts
if (minValue > 0 && maxValue > 0)
{
minValue = 0;
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
}
else if (minValue < 0 && maxValue < 0)
{
minValue = ChartHelper.GetMinDivisibleValue(minValue);
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = 0;
}
else
{
minValue = ChartHelper.GetMinDivisibleValue(minValue);
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
}
break;
case Axis.AxisMinMaxType.MinMax:
minValue = ChartHelper.GetMinDivisibleValue(minValue);
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
break;
}
}
m_ValueRange = maxValue - minValue;
}
internal float GetCurrMinValue(float duration)
{
if (!m_RuntimeMinValueChanged) return m_RuntimeMinValue;
var time = Time.time - m_RuntimeMinValueUpdateTime;
var total = duration / 1000;
if (duration > 0 && time <= total)
{
var curr = Mathf.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total);
return curr;
}
else
{
m_RuntimeMinValueChanged = false;
return m_RuntimeMinValue;
}
}
internal float GetCurrMaxValue(float duration)
{
if (!m_RuntimeMaxValueChanged) return m_RuntimeMaxValue;
var time = Time.time - m_RuntimeMaxValueUpdateTime;
var total = duration / 1000;
if (duration > 0 && time <= total)
{
var curr = Mathf.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
return curr;
}
else
{
m_RuntimeMaxValueChanged = false;
return m_RuntimeMaxValue;
}
}
public bool IsValueChanging(float duration)
{
if (GetCurrMinValue(duration) != m_RuntimeMinValue || GetCurrMaxValue(duration) != m_RuntimeMaxValue)
{
return true;
}
else
{
return false;
}
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))

View File

@@ -48,6 +48,10 @@ namespace XCharts
/// 热力图。主要通过颜色去表现数值的大小,必须要配合 visualMap 组件使用。
/// </summary>
Heatmap,
/// <summary>
/// 仪表盘。
/// </summary>
Gauge,
}
/// <summary>
@@ -142,6 +146,21 @@ namespace XCharts
Capsule
}
/// <summary>
/// 仪表盘类型
/// </summary>
public enum GaugeType
{
/// <summary>
/// 指针型
/// </summary>
Pointer,
/// <summary>
/// 进度条型
/// </summary>
ProgressBar
}
/// <summary>
/// 采样类型
/// </summary>
@@ -202,6 +221,16 @@ namespace XCharts
[SerializeField] private float m_BarZebraWidth = 4f;
[SerializeField] private float m_BarZebraGap = 2f;
[SerializeField] private float m_Min;
[SerializeField] private float m_Max;
[SerializeField] private float m_StartAngle;
[SerializeField] private float m_EndAngle;
[SerializeField] private bool m_Clockwise;
[SerializeField] private bool m_ArcShaped;
[SerializeField] private int m_SplitNumber;
[SerializeField] private GaugeType m_GaugeType = GaugeType.Pointer;
[SerializeField] private GaugeAxis m_GaugeAxis = new GaugeAxis();
[SerializeField] private GaugePointer m_GaugePointer = new GaugePointer();
[SerializeField] private bool m_ClickOffset = true;
[SerializeField] private RoseType m_RoseType = RoseType.None;
@@ -213,6 +242,7 @@ namespace XCharts
[SerializeField] private LineArrow m_LineArrow = new LineArrow();
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
[SerializeField] private TitleStyle m_TitleStyle = new TitleStyle();
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
[SerializeField] private bool m_ShowDataName;
[SerializeField] private bool m_ShowDataIcon;
@@ -383,15 +413,59 @@ namespace XCharts
/// </summary>
public float pieSpace { get { return m_Space; } set { m_Space = value; } }
/// <summary>
/// the center of pie chart.
/// 饼图的中心点。
/// the center of chart.
/// 中心点。
/// </summary>
public float[] pieCenter { get { return m_Center; } set { m_Center = value; } }
public float[] center { get { return m_Center; } set { m_Center = value; } }
/// <summary>
/// the radius of pie chart.
/// 饼图的半径。radius[0]表示内径radius[1]表示外径。
/// the radius of chart.
/// 半径。radius[0]表示内径radius[1]表示外径。
/// </summary>
public float[] pieRadius { get { return m_Radius; } set { m_Radius = value; } }
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
[Obsolete("Use Serie.center instead.", true)]
public float[] pieCenter { get { return center; } set { center = value; } }
[Obsolete("Use Serie.radius instead.", true)]
public float[] pieRadius { get { return radius; } set { radius = value; } }
/// <summary>
/// 最小值,映射到 startAngle。
/// </summary>
public float min { get { return m_Min; } set { m_Min = value; } }
/// <summary>
/// 最大值,映射到 endAngle。
/// </summary>
public float max { get { return m_Max; } set { m_Max = value; } }
/// <summary>
/// 起始角度。和时钟一样12点钟位置是0度顺时针到360度。
/// </summary>
public float startAngle { get { return m_StartAngle; } set { m_StartAngle = value; } }
/// <summary>
/// 结束角度。和时钟一样12点钟位置是0度顺时针到360度。
/// </summary>
public float endAngle { get { return m_EndAngle; } set { m_EndAngle = value; } }
/// <summary>
/// 是否顺时针。
/// </summary>
public bool clockwise { get { return m_Clockwise; } set { m_Clockwise = value; } }
/// <summary>
/// 刻度分割段数。
/// </summary>
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value > 36 ? 36 : value; } }
/// <summary>
/// 是否开启圆弧形边角。
/// </summary>
public bool arcShaped { get { return m_ArcShaped; } set { m_ArcShaped = value; } }
/// <summary>
/// 仪表盘轴线。
/// </summary>
public GaugeAxis gaugeAxis { get { return m_GaugeAxis; } set { m_GaugeAxis = value; } }
/// <summary>
/// 仪表盘指针。
/// </summary>
public GaugePointer gaugePointer { get { return m_GaugePointer; } set { m_GaugePointer = value; } }
/// <summary>
/// 仪表盘类型。
/// </summary>
public GaugeType gaugeType { get { return m_GaugeType; } set { m_GaugeType = value; } }
/// <summary>
/// Text label of graphic element,to explain some data information about graphic item like value, name and so on.
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
@@ -416,6 +490,10 @@ namespace XCharts
/// 高亮的图形样式和文本标签样式。
/// </summary>
public Emphasis emphasis { get { return m_Emphasis; } set { m_Emphasis = value; } }
/// <summary>
/// 标题样式。
/// </summary>
public TitleStyle titleStyle { get { return m_TitleStyle; } set { m_TitleStyle = value; } }
/// <summary>
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。
@@ -444,15 +522,15 @@ namespace XCharts
/// <summary>
/// 饼图的中心点位置。
/// </summary>
public Vector3 runtimePieCenterPos { get; internal set; }
public Vector3 runtimeCenterPos { get; internal set; }
/// <summary>
/// 饼图的内径
/// </summary>
public float runtimePieInsideRadius { get; internal set; }
public float runtimeInsideRadius { get; internal set; }
/// <summary>
/// 饼图的外径
/// </summary>
public float runtimePieOutsideRadius { get; internal set; }
public float runtimeOutsideRadius { get; internal set; }
/// <summary>
/// 饼图的数据项最大值
/// </summary>
@@ -732,6 +810,17 @@ namespace XCharts
return 0;
}
public float GetYCurrData(int index, DataZoom dataZoom = null)
{
if (index < 0) return 0;
var serieData = GetDataList(dataZoom);
if (index < serieData.Count)
{
return serieData[index].GetCurrData(1, animation.GetUpdateAnimationDuration());
}
return 0;
}
/// <summary>
/// 获得维度Y索引对应的数据和数据名
/// </summary>
@@ -768,6 +857,24 @@ namespace XCharts
return null;
}
/// <summary>
/// 获得指定索引的数据项的Label
/// </summary>
/// <param name="index"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public SerieLabel GetSerieLabel(int index, DataZoom dataZoom = null)
{
var data = GetDataList(dataZoom);
if (index >= 0 && index <= data.Count - 1)
{
var serieData = data[index];
if (serieData.enableLabel) return serieData.label;
else return label;
}
return null;
}
/// <summary>
/// 获得指定索引的维度X和维度Y的数据
/// </summary>
@@ -896,9 +1003,9 @@ namespace XCharts
public void UpdateData(int index, int dimension, float value)
{
if (index < 0) return;
if (index < m_Data.Count && dimension < m_Data[index].data.Count)
if (index < m_Data.Count)
{
m_Data[index].data[dimension] = value;
m_Data[index].UpdateData(dimension, value);
}
}
@@ -1083,6 +1190,22 @@ namespace XCharts
return false;
}
/// <summary>
/// 更新运行时中心点和半径
/// </summary>
/// <param name="chartWidth"></param>
/// <param name="chartHeight"></param>
internal void UpdateCenter(float chartWidth, float chartHeight)
{
if (center.Length < 2) return;
var centerX = center[0] <= 1 ? chartWidth * center[0] : center[0];
var centerY = center[1] <= 1 ? chartHeight * center[1] : center[1];
runtimeCenterPos = new Vector2(centerX, centerY);
var minWidth = Mathf.Min(chartWidth, chartHeight);
runtimeInsideRadius = radius[0] <= 1 ? minWidth * radius[0] : radius[0];
runtimeOutsideRadius = radius[1] <= 1 ? minWidth * radius[1] : radius[1];
}
/// <summary>
/// 设置指定index的数据图标的尺寸
/// </summary>

View File

@@ -81,6 +81,18 @@ namespace XCharts
}
}
public float GetCurrData(int serieIndex, int dataIndex)
{
if (serieIndex >= 0 && serieIndex < Count)
{
return m_Series[serieIndex].GetYCurrData(dataIndex);
}
else
{
return 0;
}
}
/// <summary>
/// 获得指定系列名的第一个系列
/// </summary>
@@ -167,6 +179,18 @@ namespace XCharts
return false;
}
internal bool IsAnyUpdateAnimationSerie()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable && serie.animation.updateAnimation)
{
return true;
}
}
return false;
}
/// <summary>
/// 获得上一个同堆叠且显示的serie。
/// </summary>
@@ -603,8 +627,9 @@ namespace XCharts
{
if (yValue)
{
if (data.data[1] > max) max = data.data[1];
if (data.data[1] < min) min = data.data[1];
var currData = data.GetData(1);
if (currData > max) max = currData;
if (currData < min) min = currData;
}
else
{
@@ -641,7 +666,7 @@ namespace XCharts
if (!_serieTotalValueForMinMax.ContainsKey(j))
_serieTotalValueForMinMax[j] = 0;
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] +
(yValue ? showData[j].data[1] : showData[i].data[0]);
(yValue ? showData[j].GetData(1) : showData[i].data[0]);
}
}
@@ -668,7 +693,9 @@ namespace XCharts
{
minVaule = Mathf.FloorToInt(min);
maxValue = Mathf.CeilToInt(max);
}else{
}
else
{
minVaule = min;
maxValue = max;
}

View File

@@ -0,0 +1,305 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to gauge axis line.
/// 仪表盘轴线相关设置。
/// </summary>
[System.Serializable]
public class GaugeAxis : SubComponent
{
[System.Serializable]
public class AxisLine
{
[System.Serializable]
public class StageColor
{
[SerializeField] private float m_Percent;
[SerializeField] private Color m_Color;
/// <summary>
/// 结束位置百分比。
/// </summary>
public float percent { get { return m_Percent; } set { m_Percent = value; } }
/// <summary>
/// 颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public StageColor(float percent, Color color)
{
m_Percent = percent;
m_Color = color;
}
}
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Width = 15f;
[SerializeField] private float m_Opacity = 1f;
[SerializeField] private Color m_BarColor;
[SerializeField] private Color m_BarBackgroundColor = new Color32(200, 200, 200, 255);
[SerializeField]
private List<StageColor> m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// line style line width.
/// 坐标轴线线宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// The opacity of axis line.
/// 透明度。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
/// <summary>
/// 进度条颜色。
/// </summary>
public Color barColor { get { return m_BarColor; } set { m_BarColor = value; } }
/// <summary>
/// 进度条背景颜色。
/// </summary>
public Color barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
/// <summary>
/// 阶段颜色。
/// </summary>
public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } }
}
/// <summary>
/// 分割线
/// </summary>
[System.Serializable]
public class SplitLine
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 15;
[SerializeField]
private LineStyle m_LineStyle = new LineStyle()
{
width = 1.5f,
type = LineStyle.Type.Solid,
color = new Color32(238, 238, 238, 255)
};
/// <summary>
/// 是否显示分割线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 分割线长度。
/// </summary>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 分割线样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
}
/// <summary>
/// 刻度
/// </summary>
[System.Serializable]
public class AxisTick
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 5;
[SerializeField] private float m_SplitNumber = 5;
[SerializeField]
private LineStyle m_LineStyle = new LineStyle()
{
width = 1f,
type = LineStyle.Type.Solid,
color = new Color32(238, 238, 238, 255)
};
/// <summary>
/// 是否显示刻度。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 刻度长度。当为0-1的浮点数时表示半径的百分比。
/// </summary>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 分割线之间的分割段数。
/// </summary>
public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
/// <summary>
/// 刻度线样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
}
[SerializeField] private bool m_Show = true;
[SerializeField] private AxisLine m_AxisLine = new AxisLine();
[SerializeField] private SplitLine m_SplitLine = new SplitLine();
[SerializeField] private AxisTick m_AxisTick = new AxisTick();
[SerializeField] private SerieLabel m_AxisLabel = new SerieLabel();
[SerializeField] private List<string> m_AxisLabelText = new List<string>();
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 仪表盘轴线。
/// </summary>
public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
/// <summary>
/// 分割线。
/// </summary>
public SplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
/// <summary>
/// 刻度。
/// </summary>
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
/// <summary>
/// 文本标签。
/// </summary>
public SerieLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
/// <summary>
/// 自定义Label的内容。
/// </summary>
public List<string> axisLabelText { get { return m_AxisLabelText; } set { m_AxisLabelText = value; } }
public List<float> runtimeStageAngle = new List<float>();
public List<Vector3> runtimeLabelPosition = new List<Vector3>();
private List<LabelObject> m_RuntimeLabelList = new List<LabelObject>();
internal Color GetAxisLineColor(ThemeInfo theme, int index)
{
var color = axisLine.barColor != Color.clear ? axisLine.barColor : (Color)theme.GetColor(index);
color.a *= axisLine.opacity;
return color;
}
internal Color GetAxisLineBackgroundColor(ThemeInfo theme, int index)
{
var color = axisLine.barBackgroundColor != Color.clear ? axisLine.barBackgroundColor : Color.grey;
color.a *= axisLine.opacity;
return color;
}
internal Color GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle)
{
Color color;
if (splitLine.lineStyle.color != Color.clear)
{
color = splitLine.lineStyle.color;
color.a *= splitLine.lineStyle.opacity;
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= splitLine.lineStyle.opacity;
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= splitLine.lineStyle.opacity;
return color;
}
internal Color GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
{
Color color;
if (axisTick.lineStyle.color != Color.clear)
{
color = axisTick.lineStyle.color;
color.a *= axisTick.lineStyle.opacity;
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= axisTick.lineStyle.opacity;
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= axisTick.lineStyle.opacity;
return color;
}
internal Color GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
{
Color color;
if (itemStyle.color != Color.clear)
{
color = itemStyle.color;
color.a *= itemStyle.opacity;
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= itemStyle.opacity;
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= itemStyle.opacity;
return color;
}
public void ClearLabelObject()
{
m_RuntimeLabelList.Clear();
}
public void AddLabelObject(LabelObject label)
{
m_RuntimeLabelList.Add(label);
}
public LabelObject GetLabelObject(int index)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
return m_RuntimeLabelList[index];
}
return null;
}
public void SetLabelObjectPosition(int index, Vector3 pos)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
m_RuntimeLabelList[index].SetPosition(pos);
}
}
public void SetLabelObjectText(int index, string text)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{
m_RuntimeLabelList[index].SetText(text);
}
}
public void SetLabelObjectActive(bool flag)
{
foreach (var label in m_RuntimeLabelList)
{
label.SetActive(flag);
}
}
}
}

View File

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

View File

@@ -0,0 +1,40 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to gauge pointer.
/// 仪表盘指针相关设置。
/// </summary>
[System.Serializable]
public class GaugePointer : SubComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 0.8f;
[SerializeField] private float m_Width = 15;
/// <summary>
/// 是否显示指针。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 指针长度。可以是绝对值也可以是相对于半径的百分比0-1的浮点数
/// </summary>
/// <value></value>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 指针宽度。
/// </summary>
/// <value></value>
public float width { get { return m_Width; } set { m_Width = value; } }
}
}

View File

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

View File

@@ -23,10 +23,12 @@ namespace XCharts
}
[SerializeField] private bool m_Enable = true;
[SerializeField] private Easing m_Easting;
[SerializeField] private int m_Duration = 1000;
[SerializeField] private float m_Duration = 1000;
[SerializeField] private int m_Threshold = 2000;
[SerializeField] private int m_Delay = 0;
[SerializeField] private int m_ActualDuration;
[SerializeField] private float m_Delay = 0;
[SerializeField] private bool m_UpdateAnimation = false;
[SerializeField] private float m_UpdateDuration = 500;
[SerializeField] private float m_ActualDuration;
/// <summary>
/// Whether to enable animation.
@@ -42,12 +44,12 @@ namespace XCharts
/// The milliseconds duration of the first animation.
/// 设定的动画时长(毫秒)。
/// </summary>
public int duration { get { return m_Duration; } set { m_Duration = value; } }
public float duration { get { return m_Duration; } set { m_Duration = value < 0 ? 0 : value; } }
/// <summary>
/// The milliseconds actual duration of the first animation.
/// 实际的动画时长(毫秒)。
/// </summary>
public int actualDuration { get { return m_ActualDuration; } }
public float actualDuration { get { return m_ActualDuration; } }
/// <summary>
/// Whether to set graphic number threshold to animation. Animation will be disabled when graphic number is larger than threshold.
/// 是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。
@@ -57,7 +59,16 @@ namespace XCharts
/// The milliseconds delay before updating the first animation.
/// 动画延时(毫秒)。
/// </summary>
public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } }
public float delay { get { return m_Delay; } set { m_Delay = value < 0 ? 0 : value; } }
/// <summary>
/// 是否开启数据变更动画。
/// </summary>
public bool updateAnimation { get { return m_UpdateAnimation; } set { m_UpdateAnimation = value; } }
/// <summary>
/// The milliseconds duration of the first animation.
/// 数据变更的动画时长(毫秒)。
/// </summary>
public float updateDuration { get { return m_UpdateDuration; } set { m_UpdateDuration = value < 0 ? 0 : value; } }
private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>();
private bool m_IsStart = false;
@@ -232,5 +243,11 @@ namespace XCharts
{
return m_CurrDataProgress;
}
public float GetUpdateAnimationDuration()
{
if (m_Enable && m_UpdateAnimation && IsFinish()) return m_UpdateDuration;
else return 0;
}
}
}

View File

@@ -24,6 +24,8 @@ namespace XCharts
[SerializeField] private bool m_Selected;
[SerializeField] private float m_Radius;
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
[SerializeField] private bool m_EnableLabel = false;
[SerializeField] private SerieLabel m_Label = new SerieLabel();
[SerializeField] private List<float> m_Data = new List<float>();
private bool m_Show = true;
@@ -58,6 +60,14 @@ namespace XCharts
/// </summary>
public IconStyle iconStyle { get { return m_IconStyle; } set { m_IconStyle = value; } }
/// <summary>
/// 是否启用单个数据项的标签设置。
/// </summary>
public bool enableLabel { get { return m_EnableLabel; } set { m_EnableLabel = value; } }
/// <summary>
/// 单个数据项的标签设置。
/// </summary>
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
/// <summary>
/// An arbitrary dimension data list of data item.
/// 可指定任意维数的数值列表。
/// </summary>
@@ -143,12 +153,67 @@ namespace XCharts
public float runtimePieOffsetRadius { get; internal set; }
public Vector3 runtiemPieOffsetCenter { get; internal set; }
private bool m_DataChanged;
private float m_LastData;
private float m_DataUpdateTime;
public float GetData(int index)
{
if (index >= 0 && index < m_Data.Count) return m_Data[index];
if (index >= 0 && index < m_Data.Count)
{
return m_Data[index];
}
else return 0;
}
public float GetCurrData(int index, float animationDuration = 500f)
{
if (index == 1 && m_DataChanged)
{
var time = Time.time - m_DataUpdateTime;
var total = animationDuration / 1000;
if (animationDuration > 0 && time <= total)
{
var curr = Mathf.Lerp(m_LastData, GetData(index), time / total);
return curr;
}
else
{
m_DataChanged = false;
return GetData(index);
}
}
else
{
return GetData(index);
}
}
public float GetLastData(int index)
{
if (index == 1 && m_DataChanged) return m_LastData;
else return GetData(index);
}
public void UpdateData(int dimension, float value)
{
if (dimension >= 0 && dimension < data.Count)
{
if (dimension == 1)
{
m_LastData = data[dimension];
m_DataUpdateTime = Time.time;
m_DataChanged = true;
}
data[dimension] = value;
}
}
public bool IsDataChanged()
{
return m_DataChanged;
}
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
{
gameObject = labelObj;
@@ -169,7 +234,7 @@ namespace XCharts
public bool SetLabelText(string text)
{
if (labelText)
if (labelText && !labelText.text.Equals(text))
{
labelText.text = text;
if (m_LabelAutoSize)
@@ -185,6 +250,14 @@ namespace XCharts
return false;
}
public void SetLabelColor(Color color)
{
if (labelText)
{
labelText.color = color;
}
}
public float GetLabelWidth()
{
if (labelRect) return labelRect.sizeDelta.x;
@@ -224,5 +297,16 @@ namespace XCharts
if (iconStyle == null) return;
iconStyle.UpdateIcon();
}
public bool IsInitLabel()
{
return labelText != null;
}
public SerieLabel GetSerieLabel(SerieLabel parentLabel)
{
if (enableLabel) return label;
else return parentLabel;
}
}
}

View File

@@ -80,6 +80,7 @@ namespace XCharts
[SerializeField] private bool m_Show = false;
[SerializeField] Position m_Position;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private float m_Margin;
[SerializeField] private string m_Formatter;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_PaddingLeftRight = 2f;
@@ -130,6 +131,10 @@ namespace XCharts
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// 距离轴线的距离。
/// </summary>
public float margin { get { return m_Margin; } set { m_Margin = value; } }
/// <summary>
/// Text color,If set as default ,the color will assigned as series color.
/// 自定义文字颜色,默认和系列的颜色一致。
/// </summary>

View File

@@ -0,0 +1,109 @@
/*
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// the title of serie.
/// 标题相关设置。
/// </summary>
[Serializable]
public class TitleStyle : SubComponent, IEquatable<TitleStyle>
{
[SerializeField] private bool m_Show;
[SerializeField] private TextStyle m_textStyle = new TextStyle(18);
/// <summary>
/// Whether to show title.
/// 是否显示标题。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// the color of text.
/// 文本的颜色。
/// </summary>
public TextStyle textStyle { get { return m_textStyle; } set { m_textStyle = value; } }
/// <summary>
///
/// </summary>
public Text runtimeText { get; set; }
public TitleStyle Clone()
{
var title = new TitleStyle();
title.show = show;
title.textStyle = textStyle.Clone();
return title;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is TitleStyle)
{
return Equals((TitleStyle)obj);
}
else
{
return false;
}
}
public bool Equals(TitleStyle other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return textStyle.Equals(other.textStyle);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public bool IsInited()
{
return runtimeText != null;
}
public void SetActive(bool active)
{
if (runtimeText)
{
ChartHelper.SetActive(runtimeText, active);
}
}
public void UpdatePosition(Vector3 pos)
{
if (runtimeText)
{
runtimeText.transform.localPosition = pos + new Vector3(m_textStyle.offset.x, m_textStyle.offset.y);
}
}
public void SetText(string text)
{
if (runtimeText)
{
if (textStyle.color != Color.clear) runtimeText.color = textStyle.color;
runtimeText.text = text;
}
}
}
}

View File

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