mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
增加Heatmap的maxCache参数支持
This commit is contained in:
@@ -431,6 +431,7 @@ The axis in rectangular coordinate.
|
||||
|ClearVerticesDirty()||public override void ClearVerticesDirty()|
|
||||
|Clone()||public Axis Clone()|
|
||||
|Copy()||public void Copy(Axis axis)|
|
||||
|GetAddedDataCount()||public int GetAddedDataCount()<br/>get the history data count. |
|
||||
|GetData()||public string GetData(int index)<br/>获得指定索引的类目数据 |
|
||||
|GetData()||public string GetData(int index, DataZoom dataZoom)<br/>获得在dataZoom范围内指定索引的类目数据 |
|
||||
|GetDistance()||public float GetDistance(double value, float axisLength)<br/>获得值在坐标轴上的距离 |
|
||||
@@ -497,7 +498,7 @@ animation style of axis.
|
||||
|GetAxisValueDistance()||public static float GetAxisValueDistance(GridCoord grid, Axis axis, float scaleWidth, double value)<br/>获得数值value在坐标轴上相对起点的距离 |
|
||||
|GetAxisValueLength()||public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value)<br/>获得数值value在坐标轴上对应的长度 |
|
||||
|GetAxisValuePosition()||public static float GetAxisValuePosition(GridCoord grid, Axis axis, float scaleWidth, double value)<br/>获得数值value在坐标轴上的坐标位置 |
|
||||
|GetAxisValueSplitIndex()||public static int GetAxisValueSplitIndex(Axis axis, double value, int totalSplitNumber = -1)<br/>获得数值value在坐标轴上对应的split索引 |
|
||||
|GetAxisValueSplitIndex()||public static int GetAxisValueSplitIndex(Axis axis, double value, bool checkMaxCache, int totalSplitNumber = -1)<br/>获得数值value在坐标轴上对应的split索引 |
|
||||
|GetAxisXOrY()||public static float GetAxisXOrY(GridCoord grid, Axis axis, Axis relativedAxis)|
|
||||
|GetDataWidth()||public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)<br/>获得一个类目数据在坐标系中代表的宽度 |
|
||||
|GetEachWidth()||public static float GetEachWidth(Axis axis, float coordinateWidth, DataZoom dataZoom = null)|
|
||||
|
||||
@@ -431,6 +431,7 @@ slug: /api
|
||||
|ClearVerticesDirty()||public override void ClearVerticesDirty()|
|
||||
|Clone()||public Axis Clone()|
|
||||
|Copy()||public void Copy(Axis axis)|
|
||||
|GetAddedDataCount()||public int GetAddedDataCount()<br/>获得添加过的历史数据总数 |
|
||||
|GetData()||public string GetData(int index)<br/>获得指定索引的类目数据 |
|
||||
|GetData()||public string GetData(int index, DataZoom dataZoom)<br/>获得在dataZoom范围内指定索引的类目数据 |
|
||||
|GetDistance()||public float GetDistance(double value, float axisLength)<br/>获得值在坐标轴上的距离 |
|
||||
@@ -497,7 +498,7 @@ slug: /api
|
||||
|GetAxisValueDistance()||public static float GetAxisValueDistance(GridCoord grid, Axis axis, float scaleWidth, double value)<br/>获得数值value在坐标轴上相对起点的距离 |
|
||||
|GetAxisValueLength()||public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value)<br/>获得数值value在坐标轴上对应的长度 |
|
||||
|GetAxisValuePosition()||public static float GetAxisValuePosition(GridCoord grid, Axis axis, float scaleWidth, double value)<br/>获得数值value在坐标轴上的坐标位置 |
|
||||
|GetAxisValueSplitIndex()||public static int GetAxisValueSplitIndex(Axis axis, double value, int totalSplitNumber = -1)<br/>获得数值value在坐标轴上对应的split索引 |
|
||||
|GetAxisValueSplitIndex()||public static int GetAxisValueSplitIndex(Axis axis, double value, bool checkMaxCache, int totalSplitNumber = -1)<br/>获得数值value在坐标轴上对应的split索引 |
|
||||
|GetAxisXOrY()||public static float GetAxisXOrY(GridCoord grid, Axis axis, Axis relativedAxis)|
|
||||
|GetDataWidth()||public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)<br/>获得一个类目数据在坐标系中代表的宽度 |
|
||||
|GetEachWidth()||public static float GetEachWidth(Axis axis, float coordinateWidth, DataZoom dataZoom = null)|
|
||||
|
||||
@@ -70,7 +70,8 @@ slug: /changelog
|
||||
|
||||
## master
|
||||
|
||||
* (2023.12.25) 修复`Line`开启`clip`时绘制的顶点数可能反而增加的问题
|
||||
* (2023.12.26) 增加`Heatmap`的`maxCache`参数支持
|
||||
* (2023.12.25) 优化`Line`开启`clip`时绘制的顶点数
|
||||
* (2023.12.22) 修复`Scatter`散点图部分边界数据不显示的问题
|
||||
* (2023.12.21) 修复`TriggerTooltip()`接口在指定0或最大index时可能无法触发的问题
|
||||
* (2023.12.19) 修复`Legend`的`LabelStyle`设置`formatter`后不生效的问题
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace XCharts.Editor
|
||||
PropertyField("m_HeatmapType");
|
||||
PropertyField("m_Ignore");
|
||||
PropertyField("m_IgnoreValue");
|
||||
PropertyField("m_MaxCache");
|
||||
|
||||
|
||||
PropertyField("m_Symbol");
|
||||
PropertyField("m_ItemStyle");
|
||||
|
||||
@@ -74,10 +74,10 @@ namespace XCharts.Example
|
||||
var yAxis = chart.GetChartComponent<YAxis>();
|
||||
if (xAxis != null && yAxis != null)
|
||||
{
|
||||
chart.AddXAxisData((xAxis.data.Count + 1).ToString());
|
||||
chart.AddXAxisData((xAxis.GetAddedDataCount() + 1).ToString());
|
||||
for (int i = 0; i < yAxis.data.Count; i++)
|
||||
{
|
||||
chart.AddData(0, xAxis.data.Count - 1, i, Random.Range(10, 90));
|
||||
chart.AddData(0, xAxis.GetAddedDataCount() - 1, i, Random.Range(10, 90));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -89,7 +89,7 @@ namespace XCharts.Example
|
||||
{
|
||||
if (xAxis.type == Axis.AxisType.Category)
|
||||
{
|
||||
chart.AddXAxisData("x" + (xAxis.data.Count + 1));
|
||||
chart.AddXAxisData("x" + (xAxis.GetAddedDataCount() + 1));
|
||||
}
|
||||
}
|
||||
foreach (var serie in chart.series)
|
||||
@@ -147,7 +147,7 @@ namespace XCharts.Example
|
||||
var yAxis = chart.GetChartComponent<YAxis>(serie.yAxisIndex);
|
||||
for (int i = 0; i < yAxis.data.Count; i++)
|
||||
{
|
||||
chart.AddData(serie.index, xAxis.data.Count - 1, i, Random.Range(0, 150));
|
||||
chart.AddData(serie.index, xAxis.GetAddedDataCount() - 1, i, Random.Range(0, 150));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -609,12 +609,14 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (maxCache > 0)
|
||||
{
|
||||
if (context.addedDataCount < m_Data.Count)
|
||||
context.addedDataCount = m_Data.Count;
|
||||
while (m_Data.Count >= maxCache)
|
||||
{
|
||||
RemoveData(m_InsertDataToHead ? m_Data.Count - 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
context.addedDataCount++;
|
||||
if (m_InsertDataToHead)
|
||||
m_Data.Insert(0, category);
|
||||
else
|
||||
@@ -623,6 +625,16 @@ namespace XCharts.Runtime
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get the history data count.
|
||||
/// ||获得添加过的历史数据总数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetAddedDataCount()
|
||||
{
|
||||
return context.addedDataCount < m_Data.Count ? m_Data.Count : context.addedDataCount;
|
||||
}
|
||||
|
||||
public void RemoveData(int dataIndex)
|
||||
{
|
||||
context.isNeedUpdateFilterData = true;
|
||||
|
||||
@@ -66,6 +66,10 @@ namespace XCharts.Runtime
|
||||
public List<double> labelValueList { get { return m_LabelValueList; } }
|
||||
public List<ChartLabel> labelObjectList { get { return m_AxisLabelList; } }
|
||||
public int dataZoomStartIndex;
|
||||
/// <summary>
|
||||
/// 添加过的历史数据总数
|
||||
/// </summary>
|
||||
public int addedDataCount;
|
||||
|
||||
internal List<string> filterData;
|
||||
internal bool lastCheckInverse;
|
||||
@@ -81,6 +85,7 @@ namespace XCharts.Runtime
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
addedDataCount = 0;
|
||||
m_RuntimeData.Clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -543,11 +543,14 @@ namespace XCharts.Runtime
|
||||
/// <param name="axis"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetAxisValueSplitIndex(Axis axis, double value, int totalSplitNumber = -1)
|
||||
public static int GetAxisValueSplitIndex(Axis axis, double value, bool checkMaxCache, int totalSplitNumber = -1)
|
||||
{
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
return (int)value;
|
||||
if (checkMaxCache)
|
||||
return axis.maxCache > 0 ? (int)value - (axis.GetAddedDataCount() - axis.data.Count) : (int)value;
|
||||
else
|
||||
return (int)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -347,8 +347,8 @@ namespace XCharts.Runtime
|
||||
|
||||
private void GetSerieDataByXYAxis(Serie serie, Axis xAxis, Axis yAxis)
|
||||
{
|
||||
var xAxisIndex = AxisHelper.GetAxisValueSplitIndex(xAxis, xAxis.context.pointerValue);
|
||||
var yAxisIndex = AxisHelper.GetAxisValueSplitIndex(yAxis, yAxis.context.pointerValue);
|
||||
var xAxisIndex = AxisHelper.GetAxisValueSplitIndex(xAxis, xAxis.context.pointerValue, false);
|
||||
var yAxisIndex = AxisHelper.GetAxisValueSplitIndex(yAxis, yAxis.context.pointerValue, false);
|
||||
serie.context.pointerItemDataIndex = -1;
|
||||
if (serie is Heatmap)
|
||||
{
|
||||
@@ -361,8 +361,8 @@ namespace XCharts.Runtime
|
||||
}
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
var x = AxisHelper.GetAxisValueSplitIndex(xAxis, serieData.GetData(0));
|
||||
var y = AxisHelper.GetAxisValueSplitIndex(yAxis, serieData.GetData(1));
|
||||
var x = AxisHelper.GetAxisValueSplitIndex(xAxis, serieData.GetData(0), true);
|
||||
var y = AxisHelper.GetAxisValueSplitIndex(yAxis, serieData.GetData(1), true);
|
||||
if (xAxisIndex == x && y == yAxisIndex)
|
||||
{
|
||||
serie.context.pointerItemDataIndex = serieData.index;
|
||||
|
||||
@@ -154,8 +154,8 @@ namespace XCharts.Runtime
|
||||
angleValue = serieData.GetData(1);
|
||||
value = serieData.GetData(2);
|
||||
|
||||
var xIndex = AxisHelper.GetAxisValueSplitIndex(m_RadiusAxis, radiusValue, xCount);
|
||||
var yIndex = AxisHelper.GetAxisValueSplitIndex(m_AngleAxis, angleValue, yCount);
|
||||
var xIndex = AxisHelper.GetAxisValueSplitIndex(m_RadiusAxis, radiusValue, true, xCount);
|
||||
var yIndex = AxisHelper.GetAxisValueSplitIndex(m_AngleAxis, angleValue, true, yCount);
|
||||
|
||||
start = startAngle + yIndex * yWidth;
|
||||
end = start + yWidth;
|
||||
|
||||
@@ -235,8 +235,8 @@ namespace XCharts.Runtime
|
||||
var serieData = serie.data[n];
|
||||
var xValue = serieData.GetData(0);
|
||||
var yValue = serieData.GetData(1);
|
||||
var i = AxisHelper.GetAxisValueSplitIndex(xAxis, xValue, xCount);
|
||||
var j = AxisHelper.GetAxisValueSplitIndex(yAxis, yValue, yCount);
|
||||
var i = AxisHelper.GetAxisValueSplitIndex(xAxis, xValue, true, xCount);
|
||||
var j = AxisHelper.GetAxisValueSplitIndex(yAxis, yValue,true, yCount);
|
||||
|
||||
if (serie.IsIgnoreValue(serieData, dimension))
|
||||
{
|
||||
@@ -367,8 +367,8 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var xValue = serieData.GetData(0);
|
||||
var yValue = serieData.GetData(1);
|
||||
var i = AxisHelper.GetAxisValueSplitIndex(xAxis, xValue, xCount);
|
||||
var j = AxisHelper.GetAxisValueSplitIndex(yAxis, yValue, yCount);
|
||||
var i = AxisHelper.GetAxisValueSplitIndex(xAxis, xValue, true, xCount);
|
||||
var j = AxisHelper.GetAxisValueSplitIndex(yAxis, yValue,true, yCount);
|
||||
var key = GetGridKey(i, j);
|
||||
var count = 0;
|
||||
|
||||
|
||||
@@ -1339,7 +1339,7 @@ namespace XCharts.Runtime
|
||||
/// <param name="dataId">the unique id of data</param>
|
||||
public SerieData AddYData(double value, string dataName = null, string dataId = null)
|
||||
{
|
||||
CheckMaxCache();
|
||||
var flag = CheckMaxCache();
|
||||
int xValue = m_Data.Count;
|
||||
var serieData = SerieDataPool.Get();
|
||||
serieData.data.Add(xValue);
|
||||
@@ -1348,6 +1348,7 @@ namespace XCharts.Runtime
|
||||
serieData.index = xValue;
|
||||
serieData.id = dataId;
|
||||
AddSerieData(serieData);
|
||||
if (flag) ResetDataIndex();
|
||||
m_ShowDataDimension = 2;
|
||||
SetVerticesDirty();
|
||||
CheckDataName(dataName);
|
||||
@@ -1386,7 +1387,7 @@ namespace XCharts.Runtime
|
||||
/// <param name="dataId">the unique id of data</param>
|
||||
public SerieData AddXYData(double xValue, double yValue, string dataName = null, string dataId = null)
|
||||
{
|
||||
CheckMaxCache();
|
||||
var flag = CheckMaxCache();
|
||||
var serieData = SerieDataPool.Get();
|
||||
serieData.data.Clear();
|
||||
serieData.data.Add(xValue);
|
||||
@@ -1395,6 +1396,7 @@ namespace XCharts.Runtime
|
||||
serieData.index = m_Data.Count;
|
||||
serieData.id = dataId;
|
||||
AddSerieData(serieData);
|
||||
if (flag) ResetDataIndex();
|
||||
m_ShowDataDimension = 2;
|
||||
SetVerticesDirty();
|
||||
CheckDataName(dataName);
|
||||
@@ -1414,7 +1416,7 @@ namespace XCharts.Runtime
|
||||
/// <returns></returns>
|
||||
public SerieData AddData(double indexOrTimestamp, double open, double close, double lowest, double heighest, string dataName = null, string dataId = null)
|
||||
{
|
||||
CheckMaxCache();
|
||||
var flag = CheckMaxCache();
|
||||
var serieData = SerieDataPool.Get();
|
||||
serieData.data.Clear();
|
||||
serieData.data.Add(indexOrTimestamp);
|
||||
@@ -1426,6 +1428,7 @@ namespace XCharts.Runtime
|
||||
serieData.index = m_Data.Count;
|
||||
serieData.id = dataId;
|
||||
AddSerieData(serieData);
|
||||
if (flag) ResetDataIndex();
|
||||
m_ShowDataDimension = 5;
|
||||
SetVerticesDirty();
|
||||
CheckDataName(dataName);
|
||||
@@ -1449,7 +1452,7 @@ namespace XCharts.Runtime
|
||||
return AddXYData(valueList[0], valueList[1], dataName, dataId);
|
||||
else
|
||||
{
|
||||
CheckMaxCache();
|
||||
var flag = CheckMaxCache();
|
||||
m_ShowDataDimension = valueList.Count;
|
||||
var serieData = SerieDataPool.Get();
|
||||
serieData.name = dataName;
|
||||
@@ -1460,6 +1463,7 @@ namespace XCharts.Runtime
|
||||
serieData.data.Add(valueList[i]);
|
||||
}
|
||||
AddSerieData(serieData);
|
||||
if (flag) ResetDataIndex();
|
||||
SetVerticesDirty();
|
||||
CheckDataName(dataName);
|
||||
labelDirty = true;
|
||||
@@ -1483,7 +1487,7 @@ namespace XCharts.Runtime
|
||||
return AddXYData(values[0], values[1], dataName, dataId);
|
||||
else
|
||||
{
|
||||
CheckMaxCache();
|
||||
var flag = CheckMaxCache();
|
||||
m_ShowDataDimension = values.Length;
|
||||
var serieData = SerieDataPool.Get();
|
||||
serieData.name = dataName;
|
||||
@@ -1494,6 +1498,7 @@ namespace XCharts.Runtime
|
||||
serieData.data.Add(values[i]);
|
||||
}
|
||||
AddSerieData(serieData);
|
||||
if (flag) ResetDataIndex();
|
||||
SetVerticesDirty();
|
||||
CheckDataName(dataName);
|
||||
labelDirty = true;
|
||||
@@ -1558,15 +1563,18 @@ namespace XCharts.Runtime
|
||||
return link;
|
||||
}
|
||||
|
||||
private void CheckMaxCache()
|
||||
private bool CheckMaxCache()
|
||||
{
|
||||
if (m_MaxCache <= 0) return;
|
||||
if (m_MaxCache <= 0) return false;
|
||||
var flag = false;
|
||||
while (m_Data.Count >= m_MaxCache)
|
||||
{
|
||||
m_NeedUpdateFilterData = true;
|
||||
if (m_InsertDataToHead) RemoveData(m_Data.Count - 1);
|
||||
else RemoveData(0);
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user