mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user