mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20:10 +00:00
增加Serie采样类型sampleType的相关配置
This commit is contained in:
@@ -31,6 +31,8 @@ namespace XCharts
|
|||||||
SerializedProperty m_LineArrow = prop.FindPropertyRelative("m_LineArrow");
|
SerializedProperty m_LineArrow = prop.FindPropertyRelative("m_LineArrow");
|
||||||
SerializedProperty m_LineType = prop.FindPropertyRelative("m_LineType");
|
SerializedProperty m_LineType = prop.FindPropertyRelative("m_LineType");
|
||||||
SerializedProperty m_SampleDist = prop.FindPropertyRelative("m_SampleDist");
|
SerializedProperty m_SampleDist = prop.FindPropertyRelative("m_SampleDist");
|
||||||
|
SerializedProperty m_SampleType = prop.FindPropertyRelative("m_SampleType");
|
||||||
|
SerializedProperty m_SampleAverage = prop.FindPropertyRelative("m_SampleAverage");
|
||||||
SerializedProperty m_BarWidth = prop.FindPropertyRelative("m_BarWidth");
|
SerializedProperty m_BarWidth = prop.FindPropertyRelative("m_BarWidth");
|
||||||
SerializedProperty m_BarGap = prop.FindPropertyRelative("m_BarGap");
|
SerializedProperty m_BarGap = prop.FindPropertyRelative("m_BarGap");
|
||||||
SerializedProperty m_BarCategoryGap = prop.FindPropertyRelative("m_BarCategoryGap");
|
SerializedProperty m_BarCategoryGap = prop.FindPropertyRelative("m_BarCategoryGap");
|
||||||
@@ -98,6 +100,10 @@ namespace XCharts
|
|||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_SampleDist);
|
EditorGUI.PropertyField(drawRect, m_SampleDist);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_SampleType);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_SampleAverage);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
if (serieType == SerieType.Line
|
if (serieType == SerieType.Line
|
||||||
|| serieType == SerieType.Scatter
|
|| serieType == SerieType.Scatter
|
||||||
@@ -361,7 +367,7 @@ namespace XCharts
|
|||||||
if (serieType == SerieType.Line)
|
if (serieType == SerieType.Line)
|
||||||
{
|
{
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow"));
|
||||||
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
if (serieType == SerieType.Bar)
|
if (serieType == SerieType.Bar)
|
||||||
{
|
{
|
||||||
@@ -371,7 +377,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||||
int num = m_Data.arraySize + 2;
|
int num = m_Data.arraySize + 2;
|
||||||
if (num > 30) num = 14;
|
if (num > 30) num = 15;
|
||||||
if (prop.FindPropertyRelative("m_ShowDataIcon").boolValue)
|
if (prop.FindPropertyRelative("m_ShowDataIcon").boolValue)
|
||||||
{
|
{
|
||||||
num *= 5;
|
num *= 5;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
|
||||||
|
|
||||||
namespace XCharts
|
namespace XCharts
|
||||||
{
|
{
|
||||||
@@ -111,6 +110,33 @@ namespace XCharts
|
|||||||
DashDotDot
|
DashDotDot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 采样类型
|
||||||
|
/// </summary>
|
||||||
|
public enum SampleType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 取峰值。
|
||||||
|
/// </summary>
|
||||||
|
Peak,
|
||||||
|
/// <summary>
|
||||||
|
/// 取过滤点的平均值。
|
||||||
|
/// </summary>
|
||||||
|
Average,
|
||||||
|
/// <summary>
|
||||||
|
/// 取过滤点的最大值。
|
||||||
|
/// </summary>
|
||||||
|
Max,
|
||||||
|
/// <summary>
|
||||||
|
/// 取过滤点的最小值。
|
||||||
|
/// </summary>
|
||||||
|
Min,
|
||||||
|
/// <summary>
|
||||||
|
/// 取过滤点的和。
|
||||||
|
/// </summary>
|
||||||
|
Sum
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 系列。每个系列通过 type 决定自己的图表类型。
|
/// 系列。每个系列通过 type 决定自己的图表类型。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -130,6 +156,9 @@ namespace XCharts
|
|||||||
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
||||||
[SerializeField] private LineType m_LineType = LineType.Normal;
|
[SerializeField] private LineType m_LineType = LineType.Normal;
|
||||||
[SerializeField] private float m_SampleDist = 0;
|
[SerializeField] private float m_SampleDist = 0;
|
||||||
|
[SerializeField] private SampleType m_SampleType = SampleType.Average;
|
||||||
|
[SerializeField] private float m_SampleAverage = 0;
|
||||||
|
|
||||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
||||||
[SerializeField] private float m_BarWidth = 0.6f;
|
[SerializeField] private float m_BarWidth = 0.6f;
|
||||||
[SerializeField] private float m_BarGap = 0.3f; // 30%
|
[SerializeField] private float m_BarGap = 0.3f; // 30%
|
||||||
@@ -242,6 +271,16 @@ namespace XCharts
|
|||||||
/// <value></value>
|
/// <value></value>
|
||||||
public float sampleDist { get { return m_SampleDist; } set { m_SampleDist = value < 0 ? 0 : value; } }
|
public float sampleDist { get { return m_SampleDist; } set { m_SampleDist = value < 0 ? 0 : value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// the type of sample.
|
||||||
|
/// 采样类型。当sampleDist大于0时有效。
|
||||||
|
/// </summary>
|
||||||
|
public SampleType sampleType { get { return m_SampleType; } set { m_SampleType = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// 设定的采样平均值。当sampleType 为 Peak 时,用于和过滤数据的平均值做对比是取最大值还是最小值。默认为0时会实时计算所有数据的平均值。
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public float sampleAverage { get { return m_SampleAverage; } set { m_SampleAverage = value; } }
|
||||||
|
/// <summary>
|
||||||
/// The style of line.
|
/// The style of line.
|
||||||
/// 线条样式。
|
/// 线条样式。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ namespace XCharts
|
|||||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWid / sampleDist));
|
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWid / sampleDist));
|
||||||
if (rate < 1) rate = 1;
|
if (rate < 1) rate = 1;
|
||||||
var includeLastData = false;
|
var includeLastData = false;
|
||||||
|
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||||
|
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||||
for (i = serie.minShow; i < maxCount; i += rate)
|
for (i = serie.minShow; i < maxCount; i += rate)
|
||||||
{
|
{
|
||||||
if (i == maxCount - 1) includeLastData = true;
|
if (i == maxCount - 1) includeLastData = true;
|
||||||
@@ -108,7 +110,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < rate; j++) seriesHig.Add(0);
|
for (int j = 0; j < rate; j++) seriesHig.Add(0);
|
||||||
}
|
}
|
||||||
float yValue = showData[i].data[1];
|
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i);
|
||||||
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np);
|
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np);
|
||||||
serie.dataPoints.Add(np);
|
serie.dataPoints.Add(np);
|
||||||
}
|
}
|
||||||
@@ -186,6 +188,71 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float DataAverage(ref List<SerieData> showData, SampleType sampleType, int minCount, int maxCount, int rate)
|
||||||
|
{
|
||||||
|
var totalAverage = 0f;
|
||||||
|
if (rate > 1 && sampleType == SampleType.Peak)
|
||||||
|
{
|
||||||
|
var total = 0f;
|
||||||
|
for (int i = minCount; i < maxCount; i++)
|
||||||
|
{
|
||||||
|
total += showData[i].data[1];
|
||||||
|
}
|
||||||
|
totalAverage = total / (maxCount - minCount);
|
||||||
|
}
|
||||||
|
return totalAverage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
|
||||||
|
int minCount, int maxCount, float totalAverage, int index)
|
||||||
|
{
|
||||||
|
if (rate <= 1 || index == minCount) return showData[index].data[1];
|
||||||
|
switch (sampleType)
|
||||||
|
{
|
||||||
|
case SampleType.Sum:
|
||||||
|
case SampleType.Average:
|
||||||
|
float total = 0;
|
||||||
|
for (int i = index; i > index - rate; i--)
|
||||||
|
{
|
||||||
|
total += showData[i].data[1];
|
||||||
|
}
|
||||||
|
if (sampleType == SampleType.Average) return total / rate;
|
||||||
|
else return total;
|
||||||
|
case SampleType.Max:
|
||||||
|
float max = float.MinValue;
|
||||||
|
for (int i = index; i > index - rate; i--)
|
||||||
|
{
|
||||||
|
var value = showData[i].data[1];
|
||||||
|
if (value > max) max = value;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
case SampleType.Min:
|
||||||
|
float min = float.MaxValue;
|
||||||
|
for (int i = index; i > index - rate; i--)
|
||||||
|
{
|
||||||
|
var value = showData[i].data[1];
|
||||||
|
if (value < min) min = value;
|
||||||
|
}
|
||||||
|
return min;
|
||||||
|
case SampleType.Peak:
|
||||||
|
max = float.MinValue;
|
||||||
|
min = float.MaxValue;
|
||||||
|
total = 0;
|
||||||
|
for (int i = index; i > index - rate; i--)
|
||||||
|
{
|
||||||
|
var value = showData[i].data[1];
|
||||||
|
total += value;
|
||||||
|
if (value < min) min = value;
|
||||||
|
if (value > max) max = value;
|
||||||
|
}
|
||||||
|
var average = total / rate;
|
||||||
|
if (average >= totalAverage) return max;
|
||||||
|
else return min;
|
||||||
|
|
||||||
|
}
|
||||||
|
return showData[index].data[1];
|
||||||
|
}
|
||||||
|
|
||||||
private float GetDetailProgress(Serie serie, Axis axis, Vector3 lp, Vector3 np, Vector3 llp,
|
private float GetDetailProgress(Serie serie, Axis axis, Vector3 lp, Vector3 np, Vector3 llp,
|
||||||
Vector3 nnp, bool fine)
|
Vector3 nnp, bool fine)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user