抽离甘特图

This commit is contained in:
monitor1394
2021-05-16 23:38:06 +08:00
parent a88b1979d8
commit 79a02e5594
32 changed files with 102 additions and 735 deletions

View File

@@ -1,7 +1,7 @@
# 更新日志
[Latest](#Latest)
[Latest](#master)
[v2.1.1](#v2.1.1)
[v2.1.0](#v2.1.0)
[v2.0.1](#v2.0.1)
@@ -32,8 +32,10 @@
[v0.5.0](#v0.5.0)
[v0.1.0](#v0.1.0)
## Latest
## master
* (2021.05.16) Pull out the `Ganttchart` chart and provide it as an extension module
* (2021.05.11) Added support for `VisualMap` to set color by `Piecewise`
* (2021.05.09) Fixed an issue where `RingChart` could not set the background color of the ring #141
* (2021.05.08) Added `Liquidchart` support for `Rect` shape
* (2021.05.07) Improved the `Axis` scale performance #135

View File

@@ -1,7 +1,7 @@
# 更新日志
[Latest](#Latest)
[Latest](#master)
[v2.1.1](#v2.1.1)
[v2.1.0](#v2.1.0)
[v2.0.1](#v2.0.1)
@@ -32,8 +32,10 @@
[v0.5.0](#v0.5.0)
[v0.1.0](#v0.1.0)
## Latest
## master
* (2021.05.16) 抽离`GanttChart`甘特图,通过扩展模块的方式来提供
* (2021.05.11) 增加`VisualMap``Piecewise`分段设置颜色的支持
* (2021.05.09) 修复`RingChart`无法设置环形的背景色的问题 #141
* (2021.05.08) 增加`LiquidChart`的方形水位图支持
* (2021.05.07) 优化`Axis`的刻度表现 #135

View File

@@ -1,25 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEditor;
namespace XCharts
{
/// <summary>
/// Editor class used to edit UI GanttChart.
/// </summary>
[CustomEditor(typeof(GanttChart), false)]
public class GanttChartEditor : CoordinateChartEditor
{
protected override void OnEnable()
{
base.OnEnable();
if(target == null) return;
m_Chart = (GanttChart)target;
}
}
}

View File

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

View File

@@ -21,7 +21,9 @@ namespace XCharts
{
pos.width -= 9;
base.OnGUI(pos, prop, label);
var chart = prop.serializedObject.targetObject as BaseChart;
var type = prop.FindPropertyRelative("m_Type");
var serieType = (SerieType)type.enumValueIndex;
if (!MakeFoldout(prop, "m_Show"))
{
var orderButton = 48;
@@ -29,15 +31,18 @@ namespace XCharts
var drawRect = pos;
drawRect.x += EditorGUIUtility.labelWidth + gap;
drawRect.width = pos.width - drawRect.x + ChartEditorHelper.BOOL_WIDTH - orderButton;
EditorGUI.PropertyField(drawRect, type, GUIContent.none);
type.enumValueIndex = EditorGUI.Popup(drawRect, (int)serieType, GetChartSerieTypeNames(chart));
}
else
{
var chart = prop.serializedObject.targetObject as BaseChart;
m_IsPolar = chart is PolarChart;
var serieType = (SerieType)type.enumValueIndex;
++EditorGUI.indentLevel;
PropertyField(prop, "m_Type");
type.enumValueIndex = EditorGUI.Popup(m_DrawRect, "Type", (int)serieType, GetChartSerieTypeNames(chart));
var hig = EditorGUI.GetPropertyHeight(prop);
m_DrawRect.y += hig;
m_Heights[m_KeyName] += hig;
PropertyField(prop, "m_Name");
switch (serieType)
{
@@ -68,10 +73,7 @@ namespace XCharts
PropertyField(prop, "m_Symbol");
PropertyField(prop, "m_LineStyle");
PropertyField(prop, "m_LineArrow");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_AreaStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Bar:
PropertyField(prop, "m_Stack");
@@ -99,9 +101,6 @@ namespace XCharts
PropertyField(prop, "m_ShowAsPositiveNumber");
PropertyField(prop, "m_Large");
PropertyField(prop, "m_LargeThreshold");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Pie:
PropertyField(prop, "m_RoseType");
@@ -113,9 +112,6 @@ namespace XCharts
PropertyField(prop, "m_Ignore");
PropertyField(prop, "m_IgnoreValue");
PropertyField(prop, "m_AvoidLabelOverlap");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Ring:
PropertyTwoFiled(prop, "m_Center");
@@ -125,34 +121,22 @@ namespace XCharts
PropertyField(prop, "m_RoundCap");
PropertyField(prop, "m_Clockwise");
PropertyField(prop, "m_TitleStyle");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Radar:
PropertyField(prop, "m_RadarType");
PropertyField(prop, "m_RadarIndex");
PropertyField(prop, "m_Symbol");
PropertyField(prop, "m_LineStyle");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_AreaStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
PropertyField(prop, "m_Clip");
PropertyField(prop, "m_Symbol");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Heatmap:
PropertyField(prop, "m_Ignore");
PropertyField(prop, "m_IgnoreValue");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Gauge:
PropertyField(prop, "m_GaugeType");
@@ -167,9 +151,6 @@ namespace XCharts
PropertyField(prop, "m_TitleStyle");
PropertyField(prop, "m_GaugeAxis");
PropertyField(prop, "m_GaugePointer");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Liquid:
PropertyField(prop, "m_VesselIndex");
@@ -179,8 +160,6 @@ namespace XCharts
PropertyField(prop, "m_WaveHeight");
PropertyField(prop, "m_WaveSpeed");
PropertyField(prop, "m_WaveOffset");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
break;
case SerieType.Candlestick:
PropertyField(prop, "m_XAxisIndex");
@@ -193,20 +172,6 @@ namespace XCharts
PropertyField(prop, "m_ShowAsPositiveNumber");
PropertyField(prop, "m_Large");
PropertyField(prop, "m_LargeThreshold");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Gantt:
PropertyField(prop, "m_XAxisIndex");
PropertyField(prop, "m_YAxisIndex");
PropertyField(prop, "m_BarWidth");
PropertyField(prop, "m_Clip");
PropertyField(prop, "m_Large");
PropertyField(prop, "m_LargeThreshold");
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
break;
case SerieType.Custom:
var fileds = chart.GetCustomSerieInspectorShowFileds();
@@ -217,16 +182,34 @@ namespace XCharts
PropertyField(prop, filed);
}
}
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
break;
}
PropertyField(prop, "m_ItemStyle");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_Emphasis");
PropertyField(prop, "m_Animation");
DrawData(pos, prop, serieType, ref m_DrawRect);
--EditorGUI.indentLevel;
}
}
private string[] GetChartSerieTypeNames(BaseChart chart)
{
var list = System.Enum.GetNames(typeof(SerieType));
for (int i = 0; i < list.Length; i++)
{
if (list[i].Equals("Custom"))
{
var customName = chart.GetCustomSerieTypeName();
if (!string.IsNullOrEmpty(customName))
{
list[i] = customName;
}
}
}
return list;
}
private void DrawData(Rect pos, SerializedProperty prop, SerieType serieType, ref Rect drawRect)
{
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");

View File

@@ -142,12 +142,7 @@ namespace XCharts
AddChart<LiquidChart>("LiquidChart");
}
[MenuItem("XCharts/GanttChart", priority = 54)]
[MenuItem("GameObject/XCharts/GanttChart", priority = 54)]
public static void AddGanttChart()
{
AddChart<GanttChart>("GanttChart");
}
[MenuItem("XCharts/Themes Reload")]
public static void ReloadTheme()

View File

@@ -1,79 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts.Examples
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Example100_Gantt_Category : MonoBehaviour
{
private GanttChart chart;
private float updateTime;
public int dayCount = 10;
public int taskCount = 5;
void Awake()
{
chart = gameObject.GetComponent<GanttChart>();
if (chart == null)
{
chart = gameObject.AddComponent<GanttChart>();
}
GenerateCategoryData();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
AddData();
}
}
void AddData()
{
for (int i = 0; i < taskCount; i++)
{
var startIndex = Random.Range(0, (int)(dayCount * 2.0f / 3));
var endIndex = Random.Range(startIndex, dayCount);
chart.UpdateData(0, i, 0, startIndex);
chart.UpdateData(0, i, 1, endIndex);
}
}
void GenerateCategoryData()
{
chart.RemoveData();
chart.grid.left = 100;
chart.xAxis0.type = Axis.AxisType.Category;
chart.xAxis0.boundaryGap = false;
chart.xAxis0.splitNumber = dayCount;
chart.yAxis0.type = Axis.AxisType.Category;
chart.yAxis0.boundaryGap = true;
chart.yAxis0.splitNumber = 0;
for (int i = 0; i < dayCount; i++)
{
chart.AddXAxisData("day" + (i + 1));
}
chart.AddSerie(SerieType.Gantt, "任务进度表");
for (int i = 0; i < taskCount; i++)
{
var taskName = "task-" + (i + 1);
var startIndex = Random.Range(0, (int)(dayCount * 2.0f / 3));
var endIndex = Random.Range(startIndex, dayCount);
chart.AddData(0, startIndex, endIndex, taskName);
}
}
}
}

View File

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

View File

@@ -1,99 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts.Examples
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Example101_Gantt_Time : MonoBehaviour
{
private GanttChart chart;
private float updateTime;
public int taskCount = 5;
void Awake()
{
chart = gameObject.GetComponent<GanttChart>();
if (chart == null)
{
chart = gameObject.AddComponent<GanttChart>();
}
GenerateTimeData();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
AddData();
}
}
void AddData()
{
chart.ClearData();
for (int i = 0; i < taskCount; i++)
{
var taskName = "张三-任务-" + (i + 1);
var nowTimestamp = DateTimeUtil.GetTimestamp();
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
chart.AddData(0, startTimestamp, endTimestamp, taskName);
}
chart.AddSerie(SerieType.Gantt, "李四");
for (int i = 0; i < taskCount; i++)
{
var taskName = "李四-任务-" + (i + 1);
var nowTimestamp = DateTimeUtil.GetTimestamp();
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
chart.AddData(1, startTimestamp, endTimestamp, taskName);
}
}
void GenerateTimeData()
{
chart.RemoveData();
chart.grid.left = 100;
chart.xAxis0.type = Axis.AxisType.Time;
chart.xAxis0.boundaryGap = false;
chart.xAxis0.splitNumber = 5;
chart.xAxis0.axisLabel.numericFormatter = "HH:mm:ss";
chart.xAxis0.axisLabel.formatter = "time:{value}";
chart.yAxis0.type = Axis.AxisType.Category;
chart.yAxis0.boundaryGap = true;
chart.yAxis0.splitNumber = 0;
var serie1 = chart.AddSerie(SerieType.Gantt, "张三");
serie1.label.show = true;
for (int i = 0; i < taskCount; i++)
{
var taskName = "张三-任务-" + (i + 1);
var nowTimestamp = DateTimeUtil.GetTimestamp();
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
chart.AddData(0, startTimestamp, endTimestamp, taskName);
}
chart.AddSerie(SerieType.Gantt, "李四");
for (int i = 0; i < taskCount; i++)
{
var taskName = "李四-任务-" + (i + 1);
var nowTimestamp = DateTimeUtil.GetTimestamp();
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
chart.AddData(1, startTimestamp, endTimestamp, taskName);
}
}
}
}

View File

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

View File

@@ -201,6 +201,25 @@ namespace XCharts
return m_Series.AddSerie(type, serieName);
}
/// <summary>
/// Add a serie to serie list.
/// 通过字符串类型的serieType添加一个系列到系列列表中。如果serieType不是已定义的SerieType类型则设置为Custom类型。
/// </summary>
/// <param name="serieType"></param>
/// <param name="serieName"></param>
/// <param name="show"></param>
/// <returns></returns>
public virtual Serie AddSerie(string serieType, string serieName = null, bool show = true)
{
var type = SerieType.Custom;
var list = Enum.GetNames(typeof(SerieType));
foreach (var t in list)
{
if (t.Equals(serieType)) type = (SerieType)Enum.Parse(typeof(SerieType), t);
}
return AddSerie(type, serieName, show);
}
/// <summary>
/// Add a data to serie.
/// If serieName doesn't exist in legend,will be add to legend.
@@ -733,7 +752,7 @@ namespace XCharts
return SeriesHelper.ContainsSerie(m_Series, serieType);
}
public virtual bool AddDefaultCustomSerie(string serieName)
public virtual bool AddDefaultCustomSerie(string serieName, int dataCount = 5)
{
return false;
}
@@ -747,6 +766,11 @@ namespace XCharts
return null;
}
public virtual string GetCustomSerieTypeName()
{
return null;
}
public int GetLegendRealShowNameIndex(string name)
{
return m_LegendRealShowName.IndexOf(name);

View File

@@ -31,22 +31,22 @@ namespace XCharts
public Action refreshComponent { get; set; }
public GameObject gameObject { get; set; }
internal virtual void SetVerticesDirty()
public virtual void SetVerticesDirty()
{
m_VertsDirty = true;
}
internal virtual void ClearVerticesDirty()
public virtual void ClearVerticesDirty()
{
m_VertsDirty = false;
}
internal virtual void SetComponentDirty()
public virtual void SetComponentDirty()
{
m_ComponentDirty = true;
}
internal virtual void ClearComponentDirty()
public virtual void ClearComponentDirty()
{
m_ComponentDirty = false;
}

View File

@@ -348,14 +348,14 @@ namespace XCharts
{
get { return m_ComponentDirty || axisName.anyDirty || axisLabel.anyDirty; }
}
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
axisName.ClearComponentDirty();
axisLabel.ClearComponentDirty();
}
internal override void ClearVerticesDirty()
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
axisLine.ClearVerticesDirty();
@@ -411,9 +411,9 @@ namespace XCharts
public float runtimeZeroYOffset { get; internal set; }
public int runtimeMinLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMinValue) : (int)Mathf.Log(runtimeMinValue, logBase); } }
public int runtimeMaxLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMaxValue) : (int)Mathf.Log(runtimeMaxValue, logBase); } }
internal bool runtimeLastCheckInverse { get; set; }
internal double runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } }
internal List<string> runtimeData { get { return m_RuntimeData; } }
public bool runtimeLastCheckInverse { get; set; }
public double runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } }
public List<string> runtimeData { get { return m_RuntimeData; } }
public float runtimeScaleWidth { get; internal set; }
private int filterStart;
private int filterEnd;

View File

@@ -656,6 +656,7 @@ namespace XCharts
public void Update()
{
if (chart == null) return;
foreach (var dataZoom in chart.dataZooms)
{
CheckDataZoomScale(dataZoom);

View File

@@ -228,7 +228,7 @@ namespace XCharts
get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty; }
}
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();

View File

@@ -65,10 +65,6 @@ namespace XCharts
/// </summary>
Candlestick,
/// <summary>
/// 甘特图。甘特图的data至少包含两个数据[start, end]
/// </summary>
Gantt,
/// <summary>
/// 自定义。
/// </summary>
Custom,
@@ -195,6 +191,7 @@ namespace XCharts
/// </summary>
Single
}
/// <summary>
/// 采样类型
/// </summary>
@@ -799,7 +796,7 @@ namespace XCharts
/// <summary>
/// 数据项里的数据维数。
/// </summary>
public int showDataDimension { get { return m_ShowDataDimension; } internal set { m_ShowDataDimension = value; } }
public int showDataDimension { get { return m_ShowDataDimension; } set { m_ShowDataDimension = value; } }
/// <summary>
/// 在Editor的inpsector上是否显示name参数
/// </summary>
@@ -954,7 +951,7 @@ namespace XCharts
}
public override bool componentDirty { get { return m_ComponentDirty || titleStyle.componentDirty; } }
internal override void ClearVerticesDirty()
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
symbol.ClearVerticesDirty();
@@ -969,7 +966,7 @@ namespace XCharts
titleStyle.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
symbol.ClearComponentDirty();
@@ -1751,7 +1748,6 @@ namespace XCharts
|| type == SerieType.Bar
|| type == SerieType.Scatter
|| type == SerieType.Heatmap
|| type == SerieType.Gantt
|| type == SerieType.Candlestick;
}

View File

@@ -67,7 +67,7 @@ namespace XCharts
m_LabelDirty = true;
}
internal override void ClearVerticesDirty()
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
foreach (var serie in m_Series)

View File

@@ -91,7 +91,7 @@ namespace XCharts
get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty || subTextStyle.componentDirty; }
}
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();

View File

@@ -237,7 +237,7 @@ namespace XCharts
get { return m_ComponentDirty || lineStyle.componentDirty || textStyle.componentDirty; }
}
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
lineStyle.ClearComponentDirty();

View File

@@ -339,13 +339,13 @@ namespace XCharts
}
public override bool vertsDirty { get { return m_VertsDirty || location.anyDirty; } }
internal override void ClearVerticesDirty()
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
location.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
@@ -676,16 +676,18 @@ namespace XCharts
public void Draw(VertexHelper vh)
{
var visualMap = chart.visualMap;
if (!visualMap.enable || !visualMap.show) return;
switch (visualMap.type)
foreach (var visualMap in chart.visualMaps)
{
case VisualMap.Type.Continuous:
DrawContinuousVisualMap(vh, visualMap);
break;
case VisualMap.Type.Piecewise:
//DrawPiecewiseVisualMap(vh, visualMap);
break;
if (!visualMap.enable || !visualMap.show) continue;
switch (visualMap.type)
{
case VisualMap.Type.Continuous:
DrawContinuousVisualMap(vh, visualMap);
break;
case VisualMap.Type.Piecewise:
//DrawPiecewiseVisualMap(vh, visualMap);
break;
}
}
}

View File

@@ -127,7 +127,7 @@ namespace XCharts
}
public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } }
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
textLimit.ClearComponentDirty();

View File

@@ -26,7 +26,7 @@ namespace XCharts
}
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
internal override void ClearVerticesDirty()
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
m_LineStyle.ClearVerticesDirty();

View File

@@ -56,14 +56,14 @@ namespace XCharts
public override bool componentDirty { get { return m_ComponentDirty || label.componentDirty; } }
internal override void ClearVerticesDirty()
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
label.ClearVerticesDirty();
itemStyle.ClearVerticesDirty();
}
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
label.ClearComponentDirty();

View File

@@ -46,7 +46,7 @@ namespace XCharts
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
internal override void ClearComponentDirty()
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
textStyle.ClearComponentDirty();

View File

@@ -1,136 +0,0 @@

/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
[AddComponentMenu("XCharts/GanttChart", 22)]
[ExecuteInEditMode]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
public partial class GanttChart : CoordinateChart
{
#if UNITY_EDITOR
protected override void Reset()
{
base.Reset();
title.text = "GanttChart";
var xCount = 5;
var yCount = 5;
m_Grids[0].left = 60;
m_Grids[0].right = 50;
m_XAxes[0].type = Axis.AxisType.Time;
m_XAxes[0].boundaryGap = false;
m_XAxes[0].splitNumber = xCount;
m_YAxes[0].type = Axis.AxisType.Category;
m_YAxes[0].boundaryGap = true;
m_YAxes[0].splitNumber = 0;
RemoveData();
SerieTemplate.AddDefaultTimeGanttSerie(this, "task", yCount);
}
#endif
protected override void GetSeriesMinMaxValue(Axis axis, int axisIndex, out float tempMinValue, out float tempMaxValue)
{
tempMinValue = float.MaxValue;
tempMaxValue = float.MinValue;
foreach (var serie in m_Series.list)
{
if (serie.type != SerieType.Gantt) continue;
if (serie.xAxisIndex != axis.index) continue;
foreach (var serieData in serie.data)
{
if (serieData.data.Count >= 2)
{
var xData = serieData.data[0];
var yData = serieData.data[1];
if (xData < tempMinValue) tempMinValue = xData;
if (yData > tempMaxValue) tempMaxValue = yData;
}
}
}
if (tempMinValue == float.MaxValue) tempMinValue = 0;
if (tempMaxValue == float.MinValue) tempMaxValue = 0;
}
protected override void OnRefreshLabel()
{
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.GetSerie(i);
if (serie.IsPerformanceMode()) continue;
if (serie.type != SerieType.Gantt) continue;
foreach (var serieData in serie.data)
{
if (serieData.labelObject == null) continue;
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
var labelShow = serie.show && serieLabel.show;
serieData.SetLabelActive(labelShow);
if (labelShow)
{
var labelColor = serieLabel.textStyle.GetColor(m_Theme.axis.textColor);
var labelPos = serieData.runtimePosition;
SerieLabelHelper.ResetLabel(serieData.labelObject.label, serieLabel, m_Theme, i);
serieData.labelObject.SetPosition(labelPos);
serieData.labelObject.SetLabelColor(labelColor);
serieData.labelObject.SetText(serieData.name);
}
}
}
}
protected override void UpdateTooltipValue(Vector2 local)
{
var grid = GetGrid(tooltip.runtimeGridIndex);
if (grid == null) return;
tooltip.runtimeDataIndex.Clear();
foreach (var serie in m_Series.list)
{
var serieGrid = GetSerieGridOrDefault(serie);
if (grid.index != serieGrid.index) continue;
for (int i = 0; i < serie.data.Count; i++)
{
var serieData = serie.GetSerieData(i);
var highlight = serieData.runtimeRect.Contains(local);
serieData.highlighted = highlight;
if (highlight)
{
tooltip.runtimeDataIndex.Add(serie.index);
tooltip.runtimeDataIndex.Add(i);
return;
}
}
}
}
protected override void UpdateTooltip()
{
if (tooltip.runtimeDataIndex.Count == 0)
{
if (tooltip.IsActive())
{
tooltip.SetActive(false);
RefreshChart();
}
return;
}
var serieIndex = tooltip.runtimeDataIndex[0];
var dataIndex = tooltip.runtimeDataIndex[1];
var serie = m_Series.GetSerie(serieIndex);
if (serie == null) return;
var serieData = serie.GetSerieData(dataIndex);
var category = serieData == null ? serie.name : serieData.name;
TooltipHelper.SetContentAndPosition(tooltip, category, chartRect);
tooltip.SetActive(true);
}
}
}

View File

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

View File

@@ -234,14 +234,6 @@ namespace XCharts
}
}
private static void InitGanttTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ChartTheme theme)
{
//if (tooltip.runtimeGridIndex >= 0) return;
//if (serie.index != index || serie.type != SerieType.Gantt) return;
sb.Append(serie.name);
}
private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
BaseChart chart, DataZoom dataZoom = null, bool isCartesian = false,
Radar radar = null)
@@ -271,9 +263,6 @@ namespace XCharts
case SerieType.Gauge:
InitGaugeTooltip(ref sb, tooltip, serie, index, chart.theme);
break;
case SerieType.Gantt:
InitGanttTooltip(ref sb, tooltip, serie, index, chart.theme);
break;
case SerieType.Custom:
chart.InitCustomSerieTooltip(ref sb, serie, index);
break;

View File

@@ -173,10 +173,6 @@ namespace XCharts
serie.dataPoints.Clear();
DrawCandlestickSerie(vh, colorIndex, serie);
break;
case SerieType.Gantt:
serie.dataPoints.Clear();
DrawGanttSerie(vh, colorIndex, serie);
break;
}
}
@@ -636,23 +632,8 @@ namespace XCharts
yAxis.refreshComponent();
}
private void InitAxisRuntimeData(Axis axis)
protected virtual void InitAxisRuntimeData(Axis axis)
{
if (axis.type != Axis.AxisType.Category) return;
if (axis.data.Count > 0) return;
if (this is GanttChart)
{
axis.runtimeData.Clear();
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.GetSerie(i);
if (serie.yAxisIndex != axis.index) continue;
for (int j = serie.data.Count - 1; j >= 0; j--)
{
axis.runtimeData.Add(serie.data[j].name);
}
}
}
}
internal void InitAxisX()

View File

@@ -1,177 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts
{
public partial class CoordinateChart
{
protected void DrawGanttSerie(VertexHelper vh, int colorIndex, Serie serie)
{
if (!IsActive(serie.index)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(null);
var yAxis = m_YAxes[serie.yAxisIndex];
var xAxis = m_XAxes[serie.xAxisIndex];
var grid = GetSerieGridOrDefault(serie);
var xCategoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom);
var yCategoryWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom);
var barWidth = serie.GetBarWidth(yCategoryWidth);
var space = (yCategoryWidth - barWidth) / 2;
var dataChanging = false;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var minValue = xAxis.GetCurrMinValue(dataChangeDuration);
var maxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
var pX = grid.runtimeX + (xAxis.boundaryGap ? xCategoryWidth / 2 : 0);
var pY = 0f;
var startY = grid.runtimeY - (yAxis.boundaryGap ? 0 : yCategoryWidth / 2);
var isTime = xAxis.type == Axis.AxisType.Time;
var categoryIndex = GetGanttSerieCategoryIndex(serie, grid.index);
var dataCount = serie.data.Count;
for (int i = 0; i < dataCount; i++)
{
var serieData = serie.data[i];
pY = startY + (categoryIndex - 1 - i) * yCategoryWidth;
DrawSerieData(vh, grid, serie, serieData, colorIndex, pX, pY, space, barWidth, isTime, minValue,
maxValue, xCategoryWidth);
}
if (dataChanging)
{
RefreshPainter(serie);
}
}
private void DrawSerieData(VertexHelper vh, Grid grid, Serie serie, SerieData serieData, int colorIndex,
float pX, float pY, float space, float barWidth, bool isTime, float minValue, float maxValue,
float xCategoryWidth)
{
var xStart = 0f;
var xEnd = 0f;
var xActualStart = 0f;
var xActualEnd = 0f;
var start = (int)serieData.GetData(0);
var end = (int)serieData.GetData(1);
var actualStart = (int)serieData.GetData(2);
var actualEnd = (int)serieData.GetData(3);
var enableActual = actualStart > 0 && actualEnd > 0;
if (isTime)
{
var valueTotal = maxValue - minValue;
xStart = pX + (start - minValue) / valueTotal * grid.runtimeWidth;
xEnd = pX + (end - minValue) / valueTotal * grid.runtimeWidth;
if (enableActual)
{
xActualStart = pX + (actualStart - minValue) / valueTotal * grid.runtimeWidth;
xActualEnd = pX + (actualEnd - minValue) / valueTotal * grid.runtimeWidth;
}
}
else
{
xStart = pX + start * xCategoryWidth;
xEnd = pX + end * xCategoryWidth;
if (enableActual)
{
xActualStart = pX + actualStart * xCategoryWidth;
xActualEnd = pX + actualEnd * xCategoryWidth;
}
}
var highlight = (serieData != null && serieData.highlighted)
|| serie.highlighted;
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
var color = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
var borderWidth = itemStyle.borderWidth;
var rect = DrawGanttBar(vh, grid, serie, serieData, itemStyle, color, pY, pY, space, barWidth, xStart,
xEnd);
if (enableActual)
{
var defaultActualColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, true);
var actualColor = SerieHelper.GetItemColor0(serie, serieData, m_Theme, highlight, defaultActualColor);
var rect2 = DrawGanttBar(vh, grid, serie, serieData, itemStyle, actualColor, pY, pY, space, barWidth,
xActualStart, xActualEnd);
var rect3X = Mathf.Min(rect.x, rect2.x);
var rect3Width = Mathf.Max(rect.x + rect.width, rect2.x + rect2.width) - rect3X;
var rect3 = new Rect(rect3X, rect.y, rect3Width, rect.height);
serie.dataPoints.Add(rect3.center);
serieData.runtimePosition = rect3.center;
serieData.labelPosition = rect3.center;
serieData.runtimeRect = rect3;
}
else
{
serie.dataPoints.Add(rect.center);
serieData.runtimePosition = rect.center;
serieData.labelPosition = rect.center;
serieData.runtimeRect = rect;
}
}
private Rect DrawGanttBar(VertexHelper vh, Grid grid, Serie serie, SerieData serieData, ItemStyle itemStyle,
Color32 color, float pX, float pY, float space, float barWidth, float xStart, float xEnd)
{
var borderWidth = itemStyle.borderWidth;
var plb = new Vector3(xStart + borderWidth, pY + space + borderWidth);
var plt = new Vector3(xStart + borderWidth, pY + space + barWidth - borderWidth);
var prt = new Vector3(xEnd - borderWidth, pY + space + barWidth - borderWidth);
var prb = new Vector3(xEnd - borderWidth, pY + space + borderWidth);
var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
var itemWidth = Mathf.Abs(prt.x - plb.x);
var itemHeight = Mathf.Abs(plt.y - prb.y);
if (serie.clip)
{
plb = ClampInGrid(grid, plb);
plt = ClampInGrid(grid, plt);
prt = ClampInGrid(grid, prt);
prb = ClampInGrid(grid, prb);
center = ClampInGrid(grid, center);
}
if (ItemStyleHelper.IsNeedCorner(itemStyle))
{
UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, color, color, 0,
itemStyle.cornerRadius, true, 0.5f);
}
else
{
Internal_CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color,
serie.clip, grid);
}
if (borderWidth != 0)
{
UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
itemStyle.borderToColor, 0, itemStyle.cornerRadius, true, 0.5f);
}
return new Rect(plb.x, plb.y, xEnd - xStart, barWidth);
}
private int GetGanttSerieCategoryIndex(Serie currSerie, int gridIndex)
{
var count = m_Series.Count;
var index = 0;
for (int i = 0; i < count; i++)
{
var serie = m_Series.GetSerie(i);
if (serie.type != SerieType.Gantt) continue;
var grid = GetSerieGridOrDefault(serie);
if (grid.index != gridIndex) continue;
foreach (var serieData in serie.data)
{
index++;
}
if (serie.index == currSerie.index)
{
return index;
}
}
return index;
}
}
}

View File

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

View File

@@ -80,19 +80,12 @@ namespace XCharts
}
}
// public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle,
// Vector3 startPos, Vector3 endPos, Color32 color, float themeWidth)
// {
// var type = lineStyle.type;
// var width = lineStyle.GetWidth(themeWidth);
// DrawLineStyle(vh, type, width, startPos, endPos, color);
// }
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle,
Vector3 startPos, Vector3 endPos, Color32 color, float themeWidth, LineStyle.Type themeType)
Vector3 startPos, Vector3 endPos, Color32 defaultColor, float themeWidth, LineStyle.Type themeType)
{
var type = lineStyle.GetType(themeType);
var width = lineStyle.GetWidth(themeWidth);
var color = lineStyle.GetColor(defaultColor);
DrawLineStyle(vh, type, width, startPos, endPos, color);
}

View File

@@ -28,7 +28,6 @@ namespace XCharts
case SerieType.Gauge: AddDefaultGaugeSerie(chart, serieName); break;
case SerieType.Ring: AddDefaultRingSerie(chart, serieName); break;
case SerieType.Candlestick: AddDefaultCandlestickSerie(chart, serieName); break;
case SerieType.Gantt: AddDefaultCategoryGanttSerie(chart, serieName); break;
case SerieType.Custom: chart.AddDefaultCustomSerie(serieName); break;
default: Debug.LogError("AddDefaultSerie: not support serieType yet:" + serieType); break;
}
@@ -185,34 +184,5 @@ namespace XCharts
}
return defaultDataCount;
}
public static Serie AddDefaultCategoryGanttSerie(BaseChart chart, string serieName, int dataCount = 0, int min = 0, int max = 0)
{
var serie = chart.AddSerie(SerieType.Gantt, serieName);
serie.showDataName = true;
serie.showDataDimension = 2;
for (int i = 0; i < dataCount; i++)
{
var start = Random.Range(min, max);
var end = Random.Range(start + 1, max);
serie.AddXYData(start, end, "task-" + (i + 1));
}
return serie;
}
public static Serie AddDefaultTimeGanttSerie(BaseChart chart, string serieName, int dataCount = 0)
{
var serie = chart.AddSerie(SerieType.Gantt, serieName);
serie.showDataName = true;
serie.showDataDimension = 2;
var timestamp = DateTimeUtil.GetTimestamp();
for (int i = 0; i < dataCount; i++)
{
var start = timestamp + Random.Range(1, 6) * 3600 * 24;
var end = start + Random.Range(1, 10) * 3600 * 24;
serie.AddXYData(start, end, "task-" + (i + 1));
}
return serie;
}
}
}