mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 06:50:18 +00:00
增加DataZoom对数值轴的支持 #71
This commit is contained in:
@@ -361,6 +361,14 @@ namespace XCharts
|
||||
public float runtimeWidth { get; private set; }
|
||||
public float runtimeHeight { get; private set; }
|
||||
|
||||
class AxisIndexValueInfo
|
||||
{
|
||||
public float min;
|
||||
public float max;
|
||||
}
|
||||
private Dictionary<int, AxisIndexValueInfo> m_XAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
|
||||
private Dictionary<int, AxisIndexValueInfo> m_YAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// The start label.
|
||||
/// 组件的开始信息文本。
|
||||
@@ -395,7 +403,8 @@ namespace XCharts
|
||||
end = 70,
|
||||
m_ScrollSensitivity = 10,
|
||||
m_TextStyle = new TextStyle(),
|
||||
m_LineStyle = new LineStyle(LineStyle.Type.Solid){
|
||||
m_LineStyle = new LineStyle(LineStyle.Type.Solid)
|
||||
{
|
||||
opacity = 0.3f
|
||||
},
|
||||
m_AreaStyle = new AreaStyle()
|
||||
@@ -472,6 +481,23 @@ namespace XCharts
|
||||
return xAxisIndexs.Contains(index);// || yAxisIndexs.Contains(index);
|
||||
}
|
||||
|
||||
public Color32 GetFillerColor(Color32 themeColor)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(fillerColor)) return themeColor;
|
||||
else return fillerColor;
|
||||
}
|
||||
|
||||
public Color32 GetBackgroundColor(Color32 themeColor)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(backgroundColor)) return themeColor;
|
||||
else return backgroundColor;
|
||||
}
|
||||
public Color32 GetBorderColor(Color32 themeColor)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(borderColor)) return themeColor;
|
||||
else return borderColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示文本
|
||||
/// </summary>
|
||||
@@ -538,21 +564,71 @@ namespace XCharts
|
||||
runtimeHeight = chartHeight - runtimeTop - runtimeBottom;
|
||||
}
|
||||
|
||||
public Color32 GetFillerColor(Color32 themeColor)
|
||||
internal void SetXAxisIndexValueInfo(int xAxisIndex, float min, float max)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(fillerColor)) return themeColor;
|
||||
else return fillerColor;
|
||||
if (!m_XAxisIndexInfos.ContainsKey(xAxisIndex))
|
||||
{
|
||||
m_XAxisIndexInfos[xAxisIndex] = new AxisIndexValueInfo()
|
||||
{
|
||||
min = min,
|
||||
max = max
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
m_XAxisIndexInfos[xAxisIndex].min = min;
|
||||
m_XAxisIndexInfos[xAxisIndex].max = max;
|
||||
}
|
||||
}
|
||||
|
||||
public Color32 GetBackgroundColor(Color32 themeColor)
|
||||
internal void SetYAxisIndexValueInfo(int yAxisIndex, float min, float max)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(backgroundColor)) return themeColor;
|
||||
else return backgroundColor;
|
||||
if (!m_YAxisIndexInfos.ContainsKey(yAxisIndex))
|
||||
{
|
||||
m_YAxisIndexInfos[yAxisIndex] = new AxisIndexValueInfo()
|
||||
{
|
||||
min = min,
|
||||
max = max
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
m_YAxisIndexInfos[yAxisIndex].min = min;
|
||||
m_YAxisIndexInfos[yAxisIndex].max = max;
|
||||
}
|
||||
}
|
||||
public Color32 GetBorderColor(Color32 themeColor)
|
||||
|
||||
internal bool IsXAxisIndexValue(int axisIndex)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(borderColor)) return themeColor;
|
||||
else return borderColor;
|
||||
return m_XAxisIndexInfos.ContainsKey(axisIndex);
|
||||
}
|
||||
|
||||
internal bool IsYAxisIndexValue(int axisIndex)
|
||||
{
|
||||
return m_YAxisIndexInfos.ContainsKey(axisIndex);
|
||||
}
|
||||
|
||||
internal void GetXAxisIndexValue(int axisIndex, out float min, out float max)
|
||||
{
|
||||
min = 0;
|
||||
max = 0;
|
||||
if (m_XAxisIndexInfos.ContainsKey(axisIndex))
|
||||
{
|
||||
var info = m_XAxisIndexInfos[axisIndex];
|
||||
min = info.min;
|
||||
max = info.max;
|
||||
}
|
||||
}
|
||||
internal void GetYAxisIndexValue(int axisIndex, out float min, out float max)
|
||||
{
|
||||
min = 0;
|
||||
max = 0;
|
||||
if (m_YAxisIndexInfos.ContainsKey(axisIndex))
|
||||
{
|
||||
var info = m_YAxisIndexInfos[axisIndex];
|
||||
min = info.min;
|
||||
max = info.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,14 +295,16 @@ namespace XCharts
|
||||
|
||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||
|
||||
[NonSerialized] private int m_FilterStart;
|
||||
[NonSerialized] private int m_FilterEnd;
|
||||
[NonSerialized] private int m_FilterMinShow;
|
||||
[NonSerialized] private List<SerieData> m_FilterData;
|
||||
[NonSerialized] internal int m_FilterStart;
|
||||
[NonSerialized] internal int m_FilterEnd;
|
||||
[NonSerialized] internal float m_FilterStartValue;
|
||||
[NonSerialized] internal float m_FilterEndValue;
|
||||
[NonSerialized] internal int m_FilterMinShow;
|
||||
[NonSerialized] internal bool m_NeedUpdateFilterData;
|
||||
[NonSerialized] internal List<SerieData> m_FilterData = new List<SerieData>();
|
||||
[NonSerialized] private Dictionary<int, List<Vector3>> m_UpSmoothPoints = new Dictionary<int, List<Vector3>>();
|
||||
[NonSerialized] private Dictionary<int, List<Vector3>> m_DownSmoothPoints = new Dictionary<int, List<Vector3>>();
|
||||
[NonSerialized] private List<Vector3> m_DataPoints = new List<Vector3>();
|
||||
[NonSerialized] private bool m_NeedUpdateFilterData;
|
||||
[NonSerialized] private bool m_NameDirty;
|
||||
|
||||
/// <summary>
|
||||
@@ -1426,7 +1428,7 @@ namespace XCharts
|
||||
if (dataZoom != null && dataZoom.enable
|
||||
&& (dataZoom.xAxisIndexs.Contains(xAxisIndex) || dataZoom.yAxisIndexs.Contains(yAxisIndex)))
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
SerieHelper.UpdateFilterData(this, dataZoom);
|
||||
return m_FilterData;
|
||||
}
|
||||
else
|
||||
@@ -1435,53 +1437,6 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private List<SerieData> emptyFilter = new List<SerieData>();
|
||||
/// <summary>
|
||||
/// 根据dataZoom更新数据列表缓存
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
internal void UpdateFilterData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.enable
|
||||
&& (dataZoom.xAxisIndexs.Contains(xAxisIndex) || dataZoom.yAxisIndexs.Contains(yAxisIndex)))
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
if (endIndex < startIndex) endIndex = startIndex;
|
||||
|
||||
if (startIndex != m_FilterStart || endIndex != m_FilterEnd || dataZoom.minShowNum != m_FilterMinShow || m_NeedUpdateFilterData)
|
||||
{
|
||||
m_FilterStart = startIndex;
|
||||
m_FilterEnd = endIndex;
|
||||
m_FilterMinShow = dataZoom.minShowNum;
|
||||
m_NeedUpdateFilterData = false;
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (count < dataZoom.minShowNum)
|
||||
{
|
||||
if (dataZoom.minShowNum > m_Data.Count) count = m_Data.Count;
|
||||
else count = dataZoom.minShowNum;
|
||||
}
|
||||
if (m_Data.Count > 0)
|
||||
{
|
||||
if (startIndex + count > m_Data.Count)
|
||||
{
|
||||
int start = endIndex - count;
|
||||
m_FilterData = m_Data.GetRange(start < 0 ? 0 : start, count);
|
||||
}
|
||||
else m_FilterData = m_Data.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_FilterData = m_Data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
{
|
||||
m_FilterData = emptyFilter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新指定索引的维度Y数据
|
||||
/// </summary>
|
||||
|
||||
@@ -539,7 +539,7 @@ namespace XCharts
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
m_Series[i].UpdateFilterData(dataZoom);
|
||||
SerieHelper.UpdateFilterData(m_Series[i], dataZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -843,6 +843,11 @@ namespace XCharts
|
||||
Mathf.Abs(axis.runtimeMinValue) * (grid.runtimeHeight / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue)));
|
||||
}
|
||||
}
|
||||
if (dataZoom != null && dataZoom.enable)
|
||||
{
|
||||
if (axis is XAxis) dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
|
||||
else dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
|
||||
}
|
||||
if (updateChart)
|
||||
{
|
||||
UpdateAxisLabelText(axis);
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace XCharts
|
||||
var rate = serie.animation.GetCurrRate();
|
||||
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
var dataChanging = false;
|
||||
for (int n = serie.minShow; n < maxCount; n++)
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
foreach (var serieData in dataList)
|
||||
{
|
||||
var serieData = serie.GetDataList(dataZoom)[n];
|
||||
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
|
||||
if (!symbol.ShowSymbol(n, maxCount)) continue;
|
||||
if (!symbol.ShowSymbol(serieData.index, maxCount)) continue;
|
||||
var highlight = serie.highlighted || serieData.highlighted;
|
||||
var color = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
|
||||
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
|
||||
@@ -46,7 +46,7 @@ namespace XCharts
|
||||
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
serie.dataPoints.Add(pos);
|
||||
serieData.runtimePosition = pos;
|
||||
var datas = serie.data[n].data;
|
||||
var datas = serieData.data;
|
||||
float symbolSize = 0;
|
||||
if (serie.highlighted || serieData.highlighted)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
@@ -305,5 +306,105 @@ namespace XCharts
|
||||
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<SerieData> emptyFilter = new List<SerieData>();
|
||||
/// <summary>
|
||||
/// 根据dataZoom更新数据列表缓存
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
internal static void UpdateFilterData(Serie serie, DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.enable
|
||||
&& (dataZoom.xAxisIndexs.Contains(serie.xAxisIndex) || dataZoom.yAxisIndexs.Contains(serie.yAxisIndex)))
|
||||
{
|
||||
if (dataZoom.IsXAxisIndexValue(serie.xAxisIndex))
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
dataZoom.GetXAxisIndexValue(serie.xAxisIndex, out min, out max);
|
||||
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
|
||||
}
|
||||
else if (dataZoom.IsYAxisIndexValue(serie.yAxisIndex))
|
||||
{
|
||||
float min = 0, max = 0;
|
||||
dataZoom.GetYAxisIndexValue(serie.yAxisIndex, out min, out max);
|
||||
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateFilterData_Category(serie, dataZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, float min, float max)
|
||||
{
|
||||
var data = serie.data;
|
||||
var startValue = min + (max - min) * dataZoom.start / 100;
|
||||
var endValue = min + (max - min) * dataZoom.end / 100;
|
||||
if (endValue < startValue) endValue = startValue;
|
||||
|
||||
if (startValue != serie.m_FilterStartValue || endValue != serie.m_FilterEndValue
|
||||
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
|
||||
{
|
||||
serie.m_FilterStartValue = startValue;
|
||||
serie.m_FilterEndValue = endValue;
|
||||
serie.m_FilterMinShow = dataZoom.minShowNum;
|
||||
serie.m_NeedUpdateFilterData = false;
|
||||
|
||||
serie.m_FilterData.Clear();
|
||||
foreach (var serieData in data)
|
||||
{
|
||||
var value = serieData.GetData(dimension);
|
||||
if (value >= startValue && value <= endValue)
|
||||
{
|
||||
serie.m_FilterData.Add(serieData);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (endValue == 0)
|
||||
{
|
||||
serie.m_FilterData = emptyFilter;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateFilterData_Category(Serie serie, DataZoom dataZoom)
|
||||
{
|
||||
var data = serie.data;
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
if (endIndex < startIndex) endIndex = startIndex;
|
||||
|
||||
if (startIndex != serie.m_FilterStart || endIndex != serie.m_FilterEnd
|
||||
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
|
||||
{
|
||||
serie.m_FilterStart = startIndex;
|
||||
serie.m_FilterEnd = endIndex;
|
||||
serie.m_FilterMinShow = dataZoom.minShowNum;
|
||||
serie.m_NeedUpdateFilterData = false;
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (count < dataZoom.minShowNum)
|
||||
{
|
||||
if (dataZoom.minShowNum > data.Count) count = data.Count;
|
||||
else count = dataZoom.minShowNum;
|
||||
}
|
||||
if (data.Count > 0)
|
||||
{
|
||||
if (startIndex + count > data.Count)
|
||||
{
|
||||
int start = endIndex - count;
|
||||
data = data.GetRange(start < 0 ? 0 : start, count);
|
||||
}
|
||||
else serie.m_FilterData = data.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.m_FilterData = data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
{
|
||||
serie.m_FilterData = emptyFilter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user