mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
优化DataZoom
This commit is contained in:
@@ -587,7 +587,7 @@ namespace XCharts
|
||||
/// <returns></returns>
|
||||
internal List<string> GetDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxisIndex(index))
|
||||
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxis(this))
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
return filterData;
|
||||
@@ -610,7 +610,7 @@ namespace XCharts
|
||||
/// <param name="dataZoom"></param>
|
||||
internal void UpdateFilterData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxisIndex(index))
|
||||
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxis(this))
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
|
||||
@@ -365,6 +365,14 @@ namespace XCharts
|
||||
public bool runtimeCoordinateDrag { get; internal set; }
|
||||
public bool runtimeStartDrag { get; internal set; }
|
||||
public bool runtimeEndDrag { get; internal set; }
|
||||
/// <summary>
|
||||
/// 运行时实际范围的开始值
|
||||
/// </summary>
|
||||
public float runtimeStartValue { get; internal set; }
|
||||
/// <summary>
|
||||
/// 运行时实际范围的结束值
|
||||
/// </summary>
|
||||
public float runtimeEndValue { get; internal set; }
|
||||
|
||||
class AxisIndexValueInfo
|
||||
{
|
||||
@@ -481,9 +489,20 @@ namespace XCharts
|
||||
return rect.Contains(pos);
|
||||
}
|
||||
|
||||
public bool IsContainsAxisIndex(int index)
|
||||
public bool IsContainsAxis(Axis axis)
|
||||
{
|
||||
return xAxisIndexs.Contains(index);// || yAxisIndexs.Contains(index);
|
||||
if (axis is XAxis) return xAxisIndexs.Contains(axis.index);
|
||||
else if (axis is YAxis) return yAxisIndexs.Contains(axis.index);
|
||||
else return false;
|
||||
}
|
||||
public bool IsContainsXAxis(int index)
|
||||
{
|
||||
return xAxisIndexs != null && xAxisIndexs.Contains(index);
|
||||
}
|
||||
|
||||
public bool IsContainsYAxis(int index)
|
||||
{
|
||||
return yAxisIndexs != null && yAxisIndexs.Contains(index);
|
||||
}
|
||||
|
||||
public Color32 GetFillerColor(Color32 themeColor)
|
||||
@@ -957,7 +976,7 @@ namespace XCharts
|
||||
dataZoom.SetLabelActive(false);
|
||||
}
|
||||
}
|
||||
if (m_CheckDataZoomLabel)
|
||||
if (m_CheckDataZoomLabel && dataZoom.xAxisIndexs.Count > 0)
|
||||
{
|
||||
m_CheckDataZoomLabel = false;
|
||||
var xAxis = chart.GetXAxis(dataZoom.xAxisIndexs[0]);
|
||||
|
||||
@@ -1577,7 +1577,7 @@ namespace XCharts
|
||||
public List<SerieData> GetDataList(DataZoom dataZoom = null)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.enable
|
||||
&& (dataZoom.xAxisIndexs.Contains(xAxisIndex) || dataZoom.yAxisIndexs.Contains(yAxisIndex)))
|
||||
&& (dataZoom.IsContainsXAxis(xAxisIndex) || dataZoom.IsContainsYAxis(yAxisIndex)))
|
||||
{
|
||||
SerieHelper.UpdateFilterData(this, dataZoom);
|
||||
return m_FilterData;
|
||||
|
||||
@@ -241,6 +241,18 @@ namespace XCharts
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetData(int index, float min, float max)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count)
|
||||
{
|
||||
var value = m_Data[index];
|
||||
if (value < min) return min;
|
||||
else if (value > max) return max;
|
||||
else return value;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetPreviousData(int index, bool inverse = false)
|
||||
{
|
||||
if (index >= 0 && index < m_PreviousData.Count)
|
||||
|
||||
37
Runtime/Helper/DataZoomHelper.cs
Normal file
37
Runtime/Helper/DataZoomHelper.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class DataZoomHelper
|
||||
{
|
||||
public static DataZoom GetDataZoom(Serie serie, List<DataZoom> dataZooms)
|
||||
{
|
||||
if(serie == null) return null;
|
||||
foreach (var dataZoom in dataZooms)
|
||||
{
|
||||
if (!dataZoom.enable) continue;
|
||||
if (dataZoom.IsContainsXAxis(serie.xAxisIndex)
|
||||
|| dataZoom.IsContainsYAxis(serie.yAxisIndex))
|
||||
{
|
||||
return dataZoom;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void UpdateDataZoomRuntimeStartEndValue(DataZoom dataZoom, Serie serie){
|
||||
if(dataZoom == null || serie == null) return;
|
||||
float min = 0;
|
||||
float max = 0;
|
||||
SerieHelper.GetMinMaxData(serie, out min, out max, null);
|
||||
dataZoom.runtimeStartValue = min + (max-min) * dataZoom.start / 100;
|
||||
dataZoom.runtimeEndValue = min +(max-min) * dataZoom.end / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Helper/DataZoomHelper.cs.meta
Normal file
11
Runtime/Helper/DataZoomHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 629319d47e0ca4e4dad76864d4e7226b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -442,7 +442,7 @@ namespace XCharts
|
||||
public static void UpdateFilterData(Serie serie, DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom == null || !dataZoom.enable) return;
|
||||
if (dataZoom.xAxisIndexs.Contains(serie.xAxisIndex))
|
||||
if (dataZoom.IsContainsXAxis(serie.xAxisIndex))
|
||||
{
|
||||
if (dataZoom.IsXAxisIndexValue(serie.xAxisIndex))
|
||||
{
|
||||
@@ -455,7 +455,7 @@ namespace XCharts
|
||||
UpdateFilterData_Category(serie, dataZoom);
|
||||
}
|
||||
}
|
||||
else if (dataZoom.yAxisIndexs.Contains(serie.yAxisIndex))
|
||||
else if (dataZoom.IsContainsYAxis(serie.yAxisIndex))
|
||||
{
|
||||
if (dataZoom.IsYAxisIndexValue(serie.yAxisIndex))
|
||||
{
|
||||
|
||||
@@ -1737,8 +1737,17 @@ namespace XCharts
|
||||
|
||||
public Grid GetDataZoomGridOrDefault(DataZoom dataZoom)
|
||||
{
|
||||
var xAxis = GetXAxis(dataZoom.xAxisIndexs[0]);
|
||||
Grid grid = GetGrid(xAxis.gridIndex);
|
||||
Grid grid = null;
|
||||
if (dataZoom.xAxisIndexs != null && dataZoom.xAxisIndexs.Count > 0)
|
||||
{
|
||||
var xAxis = GetXAxis(dataZoom.xAxisIndexs[0]);
|
||||
grid = GetGrid(xAxis.gridIndex);
|
||||
}
|
||||
else if (dataZoom.yAxisIndexs != null && dataZoom.yAxisIndexs.Count > 0)
|
||||
{
|
||||
var yAxis = GetYAxis(dataZoom.yAxisIndexs[0]);
|
||||
grid = GetGrid(yAxis.gridIndex);
|
||||
}
|
||||
if (grid == null) return m_Grids[0];
|
||||
else return grid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user