mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 18:30:14 +00:00
3.0
This commit is contained in:
@@ -7,17 +7,15 @@ namespace XCharts.Runtime
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[DisallowMultipleComponent]
|
||||
public partial class BarChart : BaseChart
|
||||
public class BarChart : BaseChart
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<GridCoord>();
|
||||
AddChartComponentWhenNoExist<XAxis>();
|
||||
AddChartComponentWhenNoExist<YAxis>();
|
||||
|
||||
var tooltip = GetChartComponent<Tooltip>();
|
||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
||||
tooltip.type = Tooltip.Type.Shadow;
|
||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||
|
||||
@@ -28,6 +26,5 @@ namespace XCharts.Runtime
|
||||
AddXAxisData("x" + (i + 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,26 +10,22 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class CandlestickChart : BaseChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<GridCoord>();
|
||||
AddChartComponentWhenNoExist<XAxis>();
|
||||
AddChartComponentWhenNoExist<YAxis>();
|
||||
|
||||
var tooltip = GetChartComponent<Tooltip>();
|
||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
||||
tooltip.type = Tooltip.Type.Shadow;
|
||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||
|
||||
RemoveData();
|
||||
Candlestick.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||
for (int i = 0; i < GetSerie(0).dataCount; i++)
|
||||
var serie = Candlestick.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
AddXAxisData("x" + (i + 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,8 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class HeatmapChart : BaseChart
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
|
||||
var tooltip = GetChartComponent<Tooltip>();
|
||||
tooltip.type = Tooltip.Type.None;
|
||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||
@@ -76,6 +73,5 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,16 +10,13 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class LineChart : BaseChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<GridCoord>();
|
||||
AddChartComponentWhenNoExist<XAxis>();
|
||||
AddChartComponentWhenNoExist<YAxis>();
|
||||
|
||||
var tooltip = GetChartComponent<Tooltip>();
|
||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
||||
tooltip.type = Tooltip.Type.Line;
|
||||
tooltip.trigger = Tooltip.Trigger.Axis;
|
||||
|
||||
@@ -30,6 +27,5 @@ namespace XCharts.Runtime
|
||||
AddXAxisData("x" + (i + 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class ParallelChart : BaseChart
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
RemoveData();
|
||||
AddChartComponent<ParallelCoord>();
|
||||
|
||||
@@ -29,6 +27,5 @@ namespace XCharts.Runtime
|
||||
|
||||
Parallel.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,13 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class PieChart : BaseChart
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
var legend = GetOrAddChartComponent<Legend>();
|
||||
legend.show = true;
|
||||
|
||||
RemoveData();
|
||||
Pie.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,8 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class PolarChart : BaseChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<PolarCoord>();
|
||||
|
||||
var tooltip = GetChartComponent<Tooltip>();
|
||||
@@ -32,6 +29,5 @@ namespace XCharts.Runtime
|
||||
AddData(0, Mathf.Abs(r), i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,20 +9,12 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class RadarChart : BaseChart
|
||||
{
|
||||
protected override void InitComponent()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.InitComponent();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
RemoveData();
|
||||
RemoveChartComponents<RadarCoord>();
|
||||
AddChartComponent<RadarCoord>();
|
||||
Radar.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,11 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class RingChart : BaseChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
GetChartComponent<Tooltip>().type = Tooltip.Type.Line;
|
||||
RemoveData();
|
||||
Ring.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,27 +9,24 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class ScatterChart : BaseChart
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<GridCoord>();
|
||||
|
||||
|
||||
var tooltip = GetOrAddChartComponent<Tooltip>();
|
||||
tooltip.type = Tooltip.Type.None;
|
||||
tooltip.trigger = Tooltip.Trigger.Item;
|
||||
|
||||
var xAxis = GetOrAddChartComponent<XAxis>();
|
||||
xAxis.type = Axis.AxisType.Value;
|
||||
xAxis.type = Axis.AxisType.Value;
|
||||
xAxis.boundaryGap = false;
|
||||
|
||||
var yAxis = GetOrAddChartComponent<YAxis>();
|
||||
yAxis.type = Axis.AxisType.Value;
|
||||
yAxis.type = Axis.AxisType.Value;
|
||||
yAxis.boundaryGap = false;
|
||||
|
||||
RemoveData();
|
||||
Scatter.AddDefaultSerie(this, GenerateDefaultSerieName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,8 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class SimplifiedBarChart : BaseChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<GridCoord>();
|
||||
AddChartComponentWhenNoExist<XAxis>();
|
||||
AddChartComponentWhenNoExist<YAxis>();
|
||||
@@ -30,6 +27,5 @@ namespace XCharts.Runtime
|
||||
AddXAxisData("x" + (i + 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,8 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class SimplifiedCandlestickChart : BaseChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<GridCoord>();
|
||||
AddChartComponentWhenNoExist<XAxis>();
|
||||
AddChartComponentWhenNoExist<YAxis>();
|
||||
@@ -30,6 +27,5 @@ namespace XCharts.Runtime
|
||||
AddXAxisData("x" + (i + 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,8 @@ namespace XCharts.Runtime
|
||||
[DisallowMultipleComponent]
|
||||
public class SimplifiedLineChart : BaseChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected override void DefaultChart()
|
||||
{
|
||||
base.Reset();
|
||||
AddChartComponentWhenNoExist<GridCoord>();
|
||||
AddChartComponentWhenNoExist<XAxis>();
|
||||
AddChartComponentWhenNoExist<YAxis>();
|
||||
@@ -30,6 +27,5 @@ namespace XCharts.Runtime
|
||||
AddXAxisData("x" + (i + 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ namespace XCharts.Runtime
|
||||
/// <returns></returns>
|
||||
public bool IsCategory()
|
||||
{
|
||||
return type == AxisType.Category;
|
||||
return m_Type == AxisType.Category;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -498,7 +498,7 @@ namespace XCharts.Runtime
|
||||
/// <returns></returns>
|
||||
public bool IsValue()
|
||||
{
|
||||
return type == AxisType.Value;
|
||||
return m_Type == AxisType.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -507,7 +507,7 @@ namespace XCharts.Runtime
|
||||
/// <returns></returns>
|
||||
public bool IsLog()
|
||||
{
|
||||
return type == AxisType.Log;
|
||||
return m_Type == AxisType.Log;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -515,27 +515,27 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public bool IsTime()
|
||||
{
|
||||
return type == AxisType.Time;
|
||||
return m_Type == AxisType.Time;
|
||||
}
|
||||
|
||||
public bool IsLeft()
|
||||
{
|
||||
return position == AxisPosition.Left;
|
||||
return m_Position == AxisPosition.Left;
|
||||
}
|
||||
|
||||
public bool IsRight()
|
||||
{
|
||||
return position == AxisPosition.Right;
|
||||
return m_Position == AxisPosition.Right;
|
||||
}
|
||||
|
||||
public bool IsTop()
|
||||
{
|
||||
return position == AxisPosition.Top;
|
||||
return m_Position == AxisPosition.Top;
|
||||
}
|
||||
|
||||
public bool IsBottom()
|
||||
{
|
||||
return position == AxisPosition.Bottom;
|
||||
return m_Position == AxisPosition.Bottom;
|
||||
}
|
||||
|
||||
public void SetNeedUpdateFilterData()
|
||||
|
||||
@@ -69,6 +69,8 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public Vector3 chartPosition { get { return m_ChartPosition; } }
|
||||
public Rect chartRect { get { return m_ChartRect; } }
|
||||
public Action onInit { set { m_OnInit = value; } }
|
||||
public Action onUpdate { set { m_OnUpdate = value; } }
|
||||
/// <summary>
|
||||
/// 自定义绘制回调。在绘制Serie前调用。
|
||||
/// </summary>
|
||||
@@ -103,6 +105,19 @@ namespace XCharts.Runtime
|
||||
/// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue
|
||||
/// </summary>
|
||||
public Action<Axis, double> onAxisPointerValueChanged { set { m_OnAxisPointerValueChanged = value; } get { return m_OnAxisPointerValueChanged; } }
|
||||
|
||||
public void Init(bool defaultChart = true)
|
||||
{
|
||||
if (defaultChart)
|
||||
{
|
||||
OnInit();
|
||||
DefaultChart();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnBeforeSerialize();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Redraw chart in next frame.
|
||||
/// 在下一帧刷新图表。
|
||||
@@ -138,6 +153,7 @@ namespace XCharts.Runtime
|
||||
foreach (var component in m_Components)
|
||||
component.ClearData();
|
||||
m_Series.Clear();
|
||||
m_SerieHandlers.Clear();
|
||||
m_CheckAnimation = false;
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
@@ -55,12 +55,16 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (!CanAddChartComponent(type))
|
||||
{
|
||||
throw new InvalidOperationException("CanAddChartComponent:" + type.Name);
|
||||
Debug.LogError("XCharts ERROR: CanAddChartComponent:" + type.Name);
|
||||
return null;
|
||||
}
|
||||
CheckAddRequireChartComponent(type);
|
||||
var component = Activator.CreateInstance(type) as MainComponent;
|
||||
if (component == null)
|
||||
throw new InvalidOperationException("CanAddChartComponent:" + type.Name);
|
||||
{
|
||||
Debug.LogError("XCharts ERROR: CanAddChartComponent:" + type.Name);
|
||||
return null;
|
||||
}
|
||||
component.SetDefaultValue();
|
||||
if (component is IUpdateRuntimeData)
|
||||
(component as IUpdateRuntimeData).UpdateRuntimeData(chartX, chartY, chartWidth, chartHeight);
|
||||
|
||||
@@ -79,6 +79,8 @@ namespace XCharts.Runtime
|
||||
protected Vector2 m_ChartSizeDelta;
|
||||
|
||||
protected Rect m_ChartRect = new Rect(0, 0, 0, 0);
|
||||
protected Action m_OnInit;
|
||||
protected Action m_OnUpdate;
|
||||
protected Action<VertexHelper> m_OnDrawBase;
|
||||
protected Action<VertexHelper> m_OnDrawTop;
|
||||
protected Action<VertexHelper, Serie> m_OnDrawSerieBefore;
|
||||
@@ -101,6 +103,10 @@ namespace XCharts.Runtime
|
||||
protected List<MainComponentHandler> m_ComponentHandlers = new List<MainComponentHandler>();
|
||||
protected List<SerieHandler> m_SerieHandlers = new List<SerieHandler>();
|
||||
|
||||
protected virtual void DefaultChart()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitComponent()
|
||||
{
|
||||
base.InitComponent();
|
||||
@@ -125,10 +131,8 @@ namespace XCharts.Runtime
|
||||
XChartsMgr.AddChart(this);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected void OnInit()
|
||||
{
|
||||
base.Reset();
|
||||
RemoveAllChartComponent();
|
||||
OnBeforeSerialize();
|
||||
AddChartComponentWhenNoExist<Title>();
|
||||
@@ -148,6 +152,16 @@ namespace XCharts.Runtime
|
||||
rectTransform.sizeDelta = new Vector2(580, 300);
|
||||
}
|
||||
ChartHelper.HideAllObject(transform);
|
||||
if (m_OnInit != null)
|
||||
m_OnInit();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
OnInit();
|
||||
DefaultChart();
|
||||
Awake();
|
||||
}
|
||||
#endif
|
||||
@@ -167,6 +181,8 @@ namespace XCharts.Runtime
|
||||
foreach (var handler in m_SerieHandlers) handler.Update();
|
||||
foreach (var handler in m_ComponentHandlers) handler.Update();
|
||||
m_DebugInfo.Update();
|
||||
if (m_OnUpdate != null)
|
||||
m_OnUpdate();
|
||||
}
|
||||
|
||||
public Painter GetPainter(int index)
|
||||
@@ -537,7 +553,7 @@ namespace XCharts.Runtime
|
||||
serie.context.dataPoints.Clear();
|
||||
serie.context.dataIgnores.Clear();
|
||||
serie.animation.context.isAllItemAnimationEnd = true;
|
||||
|
||||
|
||||
if (m_OnDrawSerieBefore != null)
|
||||
{
|
||||
m_OnDrawSerieBefore.Invoke(vh, serie);
|
||||
|
||||
@@ -411,8 +411,8 @@ namespace XCharts.Runtime
|
||||
|
||||
public bool IsDataChanged()
|
||||
{
|
||||
foreach (var b in m_DataUpdateFlag)
|
||||
if (b) return true;
|
||||
for (int i = 0; i < m_DataUpdateFlag.Count; i++)
|
||||
if (m_DataUpdateFlag[i]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +192,8 @@ namespace XCharts.Runtime
|
||||
m_SerieLabelRoot = ChartHelper.AddObject(s_SerieLabelObjectName, m_SerieRoot.transform,
|
||||
chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
|
||||
m_SerieLabelRoot.hideFlags = chart.chartHideFlags;
|
||||
//SerieLabelPool.ReleaseAll(m_SerieLabelRoot.transform);
|
||||
ChartHelper.DestroyAllChildren(m_SerieLabelRoot.transform);
|
||||
SerieLabelPool.ReleaseAll(m_SerieLabelRoot.transform);
|
||||
//ChartHelper.DestroyAllChildren(m_SerieLabelRoot.transform);
|
||||
int count = 0;
|
||||
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
|
||||
@@ -294,17 +294,17 @@ namespace XUGL
|
||||
{
|
||||
var dir1 = (cp - lp).normalized;
|
||||
var dir2 = (cp - np).normalized;
|
||||
var dir1v = Vector3.Cross(dir1, Vector3.forward).normalized;
|
||||
var dir2v = Vector3.Cross(dir2, Vector3.back).normalized;
|
||||
var dir1v = Vector3.Cross(dir1, Vector3.forward).normalized * width;
|
||||
var dir2v = Vector3.Cross(dir2, Vector3.back).normalized * width;
|
||||
|
||||
ltp = lp - dir1v * width;
|
||||
lbp = lp + dir1v * width;
|
||||
ltp = lp - dir1v;
|
||||
lbp = lp + dir1v;
|
||||
|
||||
ntp = np - dir2v * width;
|
||||
nbp = np + dir2v * width;
|
||||
ntp = np - dir2v;
|
||||
nbp = np + dir2v;
|
||||
|
||||
clp = cp - dir2v * width;
|
||||
crp = cp + dir2v * width;
|
||||
clp = cp - dir2v;
|
||||
crp = cp + dir2v;
|
||||
|
||||
var ldist = (Vector3.Distance(cp, lp) + 1) * dir1;
|
||||
var rdist = (Vector3.Distance(cp, np) + 1) * dir2;
|
||||
@@ -312,24 +312,24 @@ namespace XUGL
|
||||
bitp = true;
|
||||
if (!UGLHelper.GetIntersection(ltp, ltp + ldist, ntp, ntp + rdist, ref itp))
|
||||
{
|
||||
itp = cp - dir1v * width;
|
||||
clp = cp - dir1v * width;
|
||||
crp = cp - dir2v * width;
|
||||
itp = cp - dir1v;
|
||||
clp = cp - dir1v;
|
||||
crp = cp - dir2v;
|
||||
bitp = false;
|
||||
}
|
||||
bibp = true;
|
||||
if (!UGLHelper.GetIntersection(lbp, lbp + ldist, nbp, nbp + rdist, ref ibp))
|
||||
{
|
||||
ibp = cp + dir1v * width;
|
||||
clp = cp + dir1v * width;
|
||||
crp = cp + dir2v * width;
|
||||
ibp = cp + dir1v;
|
||||
clp = cp + dir1v;
|
||||
crp = cp + dir2v;
|
||||
bibp = false;
|
||||
}
|
||||
if (bitp == false && bibp == false && cp == np)
|
||||
{
|
||||
ltp = cp - dir1v * width;
|
||||
clp = cp + dir1v * width;
|
||||
crp = cp + dir1v * width;
|
||||
ltp = cp - dir1v;
|
||||
clp = cp + dir1v;
|
||||
crp = cp + dir1v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user