mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 01:40:06 +00:00
优化DataZoom组件,增加双指缩放
This commit is contained in:
@@ -151,7 +151,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 > 50) num = 13;
|
if (num > 30) num = 14;
|
||||||
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||||
height += EditorGUIUtility.standardVerticalSpacing;
|
height += EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,55 +12,68 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
Rect drawRect = pos;
|
Rect drawRect = pos;
|
||||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
SerializedProperty show = prop.FindPropertyRelative("m_Enable");
|
||||||
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
|
//SerializedProperty m_FilterMode = prop.FindPropertyRelative("m_FilterMode");
|
||||||
SerializedProperty m_FilterMode = prop.FindPropertyRelative("m_FilterMode");
|
|
||||||
//SerializedProperty m_Orient = prop.FindPropertyRelative("m_Orient");
|
//SerializedProperty m_Orient = prop.FindPropertyRelative("m_Orient");
|
||||||
|
SerializedProperty m_SupportInside = prop.FindPropertyRelative("m_SupportInside");
|
||||||
|
SerializedProperty m_SupportSlider = prop.FindPropertyRelative("m_SupportSlider");
|
||||||
|
//SerializedProperty m_SupportSelect = prop.FindPropertyRelative("m_SupportSelect");
|
||||||
SerializedProperty m_ShowDataShadow = prop.FindPropertyRelative("m_ShowDataShadow");
|
SerializedProperty m_ShowDataShadow = prop.FindPropertyRelative("m_ShowDataShadow");
|
||||||
SerializedProperty m_ShowDetail = prop.FindPropertyRelative("m_ShowDetail");
|
SerializedProperty m_ShowDetail = prop.FindPropertyRelative("m_ShowDetail");
|
||||||
SerializedProperty m_ZoomLock = prop.FindPropertyRelative("m_ZoomLock");
|
SerializedProperty m_ZoomLock = prop.FindPropertyRelative("m_ZoomLock");
|
||||||
SerializedProperty m_Realtime = prop.FindPropertyRelative("m_Realtime");
|
// SerializedProperty m_Realtime = prop.FindPropertyRelative("m_Realtime");
|
||||||
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
|
// SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
|
||||||
SerializedProperty m_Height = prop.FindPropertyRelative("m_Height");
|
SerializedProperty m_Height = prop.FindPropertyRelative("m_Height");
|
||||||
SerializedProperty m_Bottom = prop.FindPropertyRelative("m_Bottom");
|
SerializedProperty m_Bottom = prop.FindPropertyRelative("m_Bottom");
|
||||||
SerializedProperty m_RangeMode = prop.FindPropertyRelative("m_RangeMode");
|
SerializedProperty m_RangeMode = prop.FindPropertyRelative("m_RangeMode");
|
||||||
SerializedProperty m_Start = prop.FindPropertyRelative("m_Start");
|
SerializedProperty m_Start = prop.FindPropertyRelative("m_Start");
|
||||||
SerializedProperty m_End = prop.FindPropertyRelative("m_End");
|
SerializedProperty m_End = prop.FindPropertyRelative("m_End");
|
||||||
SerializedProperty m_ScrollSensitivity = prop.FindPropertyRelative("m_ScrollSensitivity");
|
SerializedProperty m_ScrollSensitivity = prop.FindPropertyRelative("m_ScrollSensitivity");
|
||||||
|
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
|
||||||
|
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
|
||||||
|
|
||||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_DataZoomModuleToggle, "DataZoom", show);
|
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_DataZoomModuleToggle, "DataZoom", show);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
if (m_DataZoomModuleToggle)
|
if (m_DataZoomModuleToggle)
|
||||||
{
|
{
|
||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
EditorGUI.PropertyField(drawRect, m_Type);
|
EditorGUI.PropertyField(drawRect, m_SupportInside);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_FilterMode);
|
EditorGUI.PropertyField(drawRect, m_SupportSlider);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
//EditorGUI.PropertyField(drawRect, m_Orient);
|
if (m_SupportSlider.boolValue)
|
||||||
|
{
|
||||||
|
++EditorGUI.indentLevel;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_ShowDataShadow);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_ShowDetail);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_FontSize);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_FontStyle);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
// EditorGUI.PropertyField(drawRect, m_Realtime);
|
||||||
|
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Height);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Bottom);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
--EditorGUI.indentLevel;
|
||||||
|
}
|
||||||
|
//EditorGUI.PropertyField(drawRect, m_SupportSelect);
|
||||||
//drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
//drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_ShowDataShadow);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_ShowDetail);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_ZoomLock);
|
EditorGUI.PropertyField(drawRect, m_ZoomLock);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_Realtime);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_ScrollSensitivity);
|
EditorGUI.PropertyField(drawRect, m_ScrollSensitivity);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_Height);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_Bottom);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_RangeMode);
|
EditorGUI.PropertyField(drawRect, m_RangeMode);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_Start);
|
EditorGUI.PropertyField(drawRect, m_Start);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_End);
|
EditorGUI.PropertyField(drawRect, m_End);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
if (m_Start.floatValue < 0) m_Start.floatValue = 0;
|
||||||
|
if (m_End.floatValue > 100) m_End.floatValue = 100;
|
||||||
--EditorGUI.indentLevel;
|
--EditorGUI.indentLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,12 +81,14 @@ namespace XCharts
|
|||||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||||
{
|
{
|
||||||
float height = 0;
|
float height = 0;
|
||||||
|
int num = 1;
|
||||||
if (m_DataZoomModuleToggle)
|
if (m_DataZoomModuleToggle)
|
||||||
{
|
{
|
||||||
height += 13 * EditorGUIUtility.singleLineHeight + 12 * EditorGUIUtility.standardVerticalSpacing;
|
num += 7;
|
||||||
|
if (prop.FindPropertyRelative("m_SupportSlider").boolValue) num += 6;
|
||||||
|
|
||||||
}
|
}
|
||||||
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ namespace XCharts
|
|||||||
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
||||||
|
|
||||||
[NonSerialized] private float m_ValueRange;
|
[NonSerialized] private float m_ValueRange;
|
||||||
|
[NonSerialized] private bool m_NeedUpdateFilterData;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set this to false to prevent the axis from showing.
|
/// Set this to false to prevent the axis from showing.
|
||||||
@@ -279,7 +280,11 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
if (maxCache > 0)
|
if (maxCache > 0)
|
||||||
{
|
{
|
||||||
while (m_Data.Count > maxCache) m_Data.RemoveAt(0);
|
while (m_Data.Count > maxCache)
|
||||||
|
{
|
||||||
|
m_NeedUpdateFilterData = true;
|
||||||
|
m_Data.RemoveAt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_Data.Add(category);
|
m_Data.Add(category);
|
||||||
}
|
}
|
||||||
@@ -306,15 +311,12 @@ namespace XCharts
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<string> GetDataList(DataZoom dataZoom)
|
public List<string> GetDataList(DataZoom dataZoom)
|
||||||
{
|
{
|
||||||
if (dataZoom != null && dataZoom.show)
|
if (dataZoom != null && dataZoom.enable)
|
||||||
{
|
{
|
||||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||||
if (filterData == null || filterData.Count != count)
|
UpdateFilterData(dataZoom);
|
||||||
{
|
|
||||||
UpdateFilterData(dataZoom);
|
|
||||||
}
|
|
||||||
return filterData;
|
return filterData;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -323,20 +325,22 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<string> emptyFliter = new List<string>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新dataZoom对应的类目数据列表
|
/// 更新dataZoom对应的类目数据列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataZoom"></param>
|
/// <param name="dataZoom"></param>
|
||||||
public void UpdateFilterData(DataZoom dataZoom)
|
public void UpdateFilterData(DataZoom dataZoom)
|
||||||
{
|
{
|
||||||
if (dataZoom != null && dataZoom.show)
|
if (dataZoom != null && dataZoom.enable)
|
||||||
{
|
{
|
||||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||||
if (startIndex != filterStart || endIndex != filterEnd)
|
if (startIndex != filterStart || endIndex != filterEnd || m_NeedUpdateFilterData)
|
||||||
{
|
{
|
||||||
filterStart = startIndex;
|
filterStart = startIndex;
|
||||||
filterEnd = endIndex;
|
filterEnd = endIndex;
|
||||||
|
m_NeedUpdateFilterData = false;
|
||||||
if (m_Data.Count > 0)
|
if (m_Data.Count > 0)
|
||||||
{
|
{
|
||||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||||
@@ -349,7 +353,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else if (endIndex == 0)
|
else if (endIndex == 0)
|
||||||
{
|
{
|
||||||
filterData = new List<string>();
|
filterData = emptyFliter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,22 +12,6 @@ namespace XCharts
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class DataZoom
|
public class DataZoom
|
||||||
{
|
{
|
||||||
public enum DataZoomType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// DataZoom functionalities is embeded inside coordinate systems, enable user to
|
|
||||||
/// zoom or roam coordinate system by mouse dragging, mouse move or finger touch (in touch screen).
|
|
||||||
/// 内置于坐标系中,使用户可以在坐标系上通过鼠标拖拽、鼠标滚轮、手指滑动(触屏上)来缩放或漫游坐标系。
|
|
||||||
/// </summary>
|
|
||||||
Inside,
|
|
||||||
/// <summary>
|
|
||||||
/// A special slider bar is provided, on which coordinate systems can be zoomed or
|
|
||||||
/// roamed by mouse dragging or finger touch (in touch screen).
|
|
||||||
/// 有单独的滑动条,用户在滑动条上进行缩放或漫游。
|
|
||||||
/// </summary>
|
|
||||||
Slider
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generally dataZoom component zoom or roam coordinate system through data filtering
|
/// Generally dataZoom component zoom or roam coordinate system through data filtering
|
||||||
/// and set the windows of axes internally.
|
/// and set the windows of axes internally.
|
||||||
@@ -70,12 +54,13 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
Percent
|
Percent
|
||||||
}
|
}
|
||||||
[SerializeField] private bool m_Show;
|
[SerializeField] private bool m_Enable;
|
||||||
[SerializeField] private DataZoomType m_Type;
|
|
||||||
[SerializeField] private FilterMode m_FilterMode;
|
[SerializeField] private FilterMode m_FilterMode;
|
||||||
[SerializeField] private Orient m_Orient;
|
|
||||||
[SerializeField] private int m_XAxisIndex;
|
[SerializeField] private int m_XAxisIndex;
|
||||||
[SerializeField] private int m_YAxisIndex;
|
[SerializeField] private int m_YAxisIndex;
|
||||||
|
[SerializeField] private bool m_SupportInside;
|
||||||
|
[SerializeField] private bool m_SupportSlider;
|
||||||
|
[SerializeField] private bool m_SupportSelect;
|
||||||
[SerializeField] private bool m_ShowDataShadow;
|
[SerializeField] private bool m_ShowDataShadow;
|
||||||
[SerializeField] private bool m_ShowDetail;
|
[SerializeField] private bool m_ShowDetail;
|
||||||
[SerializeField] private bool m_ZoomLock;
|
[SerializeField] private bool m_ZoomLock;
|
||||||
@@ -89,29 +74,21 @@ namespace XCharts
|
|||||||
[SerializeField] private float m_StartValue;
|
[SerializeField] private float m_StartValue;
|
||||||
[SerializeField] private float m_EndValue;
|
[SerializeField] private float m_EndValue;
|
||||||
[Range(1f, 20f)]
|
[Range(1f, 20f)]
|
||||||
[SerializeField] private float m_ScrollSensitivity;
|
[SerializeField] private float m_ScrollSensitivity = 1.1f;
|
||||||
|
[SerializeField] private int m_FontSize = 18;
|
||||||
|
[SerializeField] private FontStyle m_FontStyle;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to show dataZoom.
|
/// Whether to show dataZoom.
|
||||||
/// 是否显示缩放区域。
|
/// 是否显示缩放区域。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
|
||||||
/// <summary>
|
|
||||||
/// The type of dataZoom.
|
|
||||||
/// 区域缩放类型。
|
|
||||||
/// </summary>
|
|
||||||
public DataZoomType type { get { return m_Type; } set { m_Type = value; } }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mode of data filter.
|
/// The mode of data filter.
|
||||||
/// 数据过滤类型。
|
/// 数据过滤类型。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
|
public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specify whether the layout of dataZoom component is horizontal or vertical.
|
|
||||||
/// 水平还是垂直显示。
|
|
||||||
/// </summary>
|
|
||||||
public Orient orient { get { return m_Orient; } set { m_Orient = value; } }
|
|
||||||
/// <summary>
|
|
||||||
/// Specify which xAxis is controlled by the dataZoom.
|
/// Specify which xAxis is controlled by the dataZoom.
|
||||||
/// 控制哪一个 x 轴。
|
/// 控制哪一个 x 轴。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -122,6 +99,18 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int yAxisIndex { get { return m_YAxisIndex; } set { m_YAxisIndex = value; } }
|
public int yAxisIndex { get { return m_YAxisIndex; } set { m_YAxisIndex = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 是否支持内置。内置于坐标系中,使用户可以在坐标系上通过鼠标拖拽、鼠标滚轮、手指滑动(触屏上)来缩放或漫游坐标系。
|
||||||
|
/// </summary>
|
||||||
|
public bool supportInside { get { return m_SupportInside; } set { m_SupportInside = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// 是否支持滑动条。有单独的滑动条,用户在滑动条上进行缩放或漫游。
|
||||||
|
/// </summary>
|
||||||
|
public bool supportSlider { get { return m_SupportSlider; } set { m_SupportSlider = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// 是否支持框选。提供一个选框进行数据区域缩放。
|
||||||
|
/// </summary>
|
||||||
|
private bool supportSelect { get { return m_SupportSelect; } set { m_SupportSelect = value; } }
|
||||||
|
/// <summary>
|
||||||
/// Whether to show data shadow, to indicate the data tendency in brief.
|
/// Whether to show data shadow, to indicate the data tendency in brief.
|
||||||
/// default:true
|
/// default:true
|
||||||
/// 是否显示数据阴影。数据阴影可以简单地反应数据走势。
|
/// 是否显示数据阴影。数据阴影可以简单地反应数据走势。
|
||||||
@@ -142,14 +131,14 @@ namespace XCharts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief.
|
/// Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief.
|
||||||
/// default:true
|
/// default:true
|
||||||
/// 拖动时,是否实时更新系列的视图。如果设置为 false,则只在拖拽结束的时候更新。
|
/// 拖动时,是否实时更新系列的视图。如果设置为 false,则只在拖拽结束的时候更新。默认为true,暂不支持修改。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool realtime { get { return m_Realtime; } set { m_Realtime = value; } }
|
public bool realtime { get { return true; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The background color of the component.
|
/// The background color of the component.
|
||||||
/// 组件的背景颜色。
|
/// 组件的背景颜色。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
|
private Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Distance between dataZoom component and the bottom side of the container.
|
/// Distance between dataZoom component and the bottom side of the container.
|
||||||
/// bottom value is a instant pixel value like 10.
|
/// bottom value is a instant pixel value like 10.
|
||||||
@@ -175,13 +164,21 @@ namespace XCharts
|
|||||||
/// default:30
|
/// default:30
|
||||||
/// 数据窗口范围的起始百分比。范围是:0 ~ 100。
|
/// 数据窗口范围的起始百分比。范围是:0 ~ 100。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float start { get { return m_Start; } set { m_Start = value; } }
|
public float start
|
||||||
|
{
|
||||||
|
get { return m_Start; }
|
||||||
|
set { m_Start = value; if (m_Start < 0) m_Start = 0; if (m_Start > 100) m_Start = 100; }
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The end percentage of the window out of the data extent, in the range of 0 ~ 100.
|
/// The end percentage of the window out of the data extent, in the range of 0 ~ 100.
|
||||||
/// default:70
|
/// default:70
|
||||||
/// 数据窗口范围的结束百分比。范围是:0 ~ 100。
|
/// 数据窗口范围的结束百分比。范围是:0 ~ 100。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float end { get { return m_End; } set { m_End = value; } }
|
public float end
|
||||||
|
{
|
||||||
|
get { return m_End; }
|
||||||
|
set { m_End = value; if (m_End < 0) m_End = 0; if (m_End > 100) m_End = 100; }
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The sensitivity of dataZoom scroll.
|
/// The sensitivity of dataZoom scroll.
|
||||||
/// The larger the number, the more sensitive it is.
|
/// The larger the number, the more sensitive it is.
|
||||||
@@ -189,6 +186,16 @@ namespace XCharts
|
|||||||
/// 缩放区域组件的敏感度。值越高每次缩放所代表的数据越多。
|
/// 缩放区域组件的敏感度。值越高每次缩放所代表的数据越多。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float scrollSensitivity { get { return m_ScrollSensitivity; } set { m_ScrollSensitivity = value; } }
|
public float scrollSensitivity { get { return m_ScrollSensitivity; } set { m_ScrollSensitivity = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// font size.
|
||||||
|
/// 文字的字体大小。
|
||||||
|
/// </summary>
|
||||||
|
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// font style.
|
||||||
|
/// 文字字体的风格。
|
||||||
|
/// </summary>
|
||||||
|
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DataZoom is in draging.
|
/// DataZoom is in draging.
|
||||||
@@ -212,16 +219,13 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
return new DataZoom()
|
return new DataZoom()
|
||||||
{
|
{
|
||||||
m_Type = DataZoomType.Slider,
|
|
||||||
filterMode = FilterMode.None,
|
filterMode = FilterMode.None,
|
||||||
orient = Orient.Horizonal,
|
|
||||||
xAxisIndex = 0,
|
xAxisIndex = 0,
|
||||||
yAxisIndex = 0,
|
yAxisIndex = 0,
|
||||||
showDataShadow = true,
|
showDataShadow = true,
|
||||||
showDetail = false,
|
showDetail = false,
|
||||||
zoomLock = false,
|
zoomLock = false,
|
||||||
realtime = true,
|
m_Height = 0,
|
||||||
m_Height = 50,
|
|
||||||
m_Bottom = 10,
|
m_Bottom = 10,
|
||||||
rangeMode = RangeMode.Percent,
|
rangeMode = RangeMode.Percent,
|
||||||
start = 30,
|
start = 30,
|
||||||
@@ -320,5 +324,21 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
if (endLabel) endLabel.text = text;
|
if (endLabel) endLabel.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取DataZoom的高,当height设置为0时,自动计算合适的偏移。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gridBottom"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public float GetHeight(float gridBottom)
|
||||||
|
{
|
||||||
|
if (height <= 0)
|
||||||
|
{
|
||||||
|
var hig = gridBottom - bottom - 30;
|
||||||
|
if (hig < 10) hig = 10;
|
||||||
|
return hig;
|
||||||
|
}
|
||||||
|
else return height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,6 +192,7 @@ namespace XCharts
|
|||||||
[NonSerialized] private Dictionary<int, List<Vector3>> m_UpSmoothPoints = new Dictionary<int, List<Vector3>>();
|
[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 Dictionary<int, List<Vector3>> m_DownSmoothPoints = new Dictionary<int, List<Vector3>>();
|
||||||
[NonSerialized] private List<Vector3> m_DataPoints = new List<Vector3>();
|
[NonSerialized] private List<Vector3> m_DataPoints = new List<Vector3>();
|
||||||
|
[NonSerialized] private bool m_NeedUpdateFilterData;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to show serie in chart.
|
/// Whether to show serie in chart.
|
||||||
@@ -590,7 +591,11 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
if (m_MaxCache > 0)
|
if (m_MaxCache > 0)
|
||||||
{
|
{
|
||||||
while (m_Data.Count > m_MaxCache) m_Data.RemoveAt(0);
|
while (m_Data.Count > m_MaxCache)
|
||||||
|
{
|
||||||
|
m_NeedUpdateFilterData = true;
|
||||||
|
m_Data.RemoveAt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int xValue = m_Data.Count;
|
int xValue = m_Data.Count;
|
||||||
m_Data.Add(new SerieData() { data = new List<float>() { xValue, value }, name = dataName });
|
m_Data.Add(new SerieData() { data = new List<float>() { xValue, value }, name = dataName });
|
||||||
@@ -607,7 +612,11 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
if (m_MaxCache > 0)
|
if (m_MaxCache > 0)
|
||||||
{
|
{
|
||||||
while (m_Data.Count > m_MaxCache) m_Data.RemoveAt(0);
|
while (m_Data.Count > m_MaxCache)
|
||||||
|
{
|
||||||
|
m_NeedUpdateFilterData = true;
|
||||||
|
m_Data.RemoveAt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
|
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
|
||||||
}
|
}
|
||||||
@@ -634,7 +643,11 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
if (m_MaxCache > 0)
|
if (m_MaxCache > 0)
|
||||||
{
|
{
|
||||||
while (m_Data.Count > m_MaxCache) m_Data.RemoveAt(0);
|
while (m_Data.Count > m_MaxCache)
|
||||||
|
{
|
||||||
|
m_NeedUpdateFilterData = true;
|
||||||
|
m_Data.RemoveAt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var serieData = new SerieData();
|
var serieData = new SerieData();
|
||||||
serieData.name = dataName;
|
serieData.name = dataName;
|
||||||
@@ -727,15 +740,9 @@ namespace XCharts
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<SerieData> GetDataList(DataZoom dataZoom)
|
public List<SerieData> GetDataList(DataZoom dataZoom)
|
||||||
{
|
{
|
||||||
if (dataZoom != null && dataZoom.show)
|
if (dataZoom != null && dataZoom.enable)
|
||||||
{
|
{
|
||||||
var startIndex = (int)((m_Data.Count - 1) * dataZoom.start / 100);
|
UpdateFilterData(dataZoom);
|
||||||
var endIndex = (int)((m_Data.Count - 1) * dataZoom.end / 100);
|
|
||||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
|
||||||
if (m_FilterData == null || m_FilterData.Count != count)
|
|
||||||
{
|
|
||||||
UpdateFilterData(dataZoom);
|
|
||||||
}
|
|
||||||
return m_FilterData;
|
return m_FilterData;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -769,20 +776,22 @@ namespace XCharts
|
|||||||
minValue = min;
|
minValue = min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<SerieData> emptyFilter = new List<SerieData>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据dataZoom更新数据列表缓存
|
/// 根据dataZoom更新数据列表缓存
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataZoom"></param>
|
/// <param name="dataZoom"></param>
|
||||||
public void UpdateFilterData(DataZoom dataZoom)
|
public void UpdateFilterData(DataZoom dataZoom)
|
||||||
{
|
{
|
||||||
if (dataZoom != null && dataZoom.show)
|
if (dataZoom != null && dataZoom.enable)
|
||||||
{
|
{
|
||||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||||
if (startIndex != m_FilterStart || endIndex != m_FilterEnd)
|
if (startIndex != m_FilterStart || endIndex != m_FilterEnd || m_NeedUpdateFilterData)
|
||||||
{
|
{
|
||||||
m_FilterStart = startIndex;
|
m_FilterStart = startIndex;
|
||||||
m_FilterEnd = endIndex;
|
m_FilterEnd = endIndex;
|
||||||
|
m_NeedUpdateFilterData = false;
|
||||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||||
if (m_Data.Count > 0)
|
if (m_Data.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -795,7 +804,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else if (endIndex == 0)
|
else if (endIndex == 0)
|
||||||
{
|
{
|
||||||
m_FilterData = new List<SerieData>();
|
m_FilterData = emptyFilter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ namespace XCharts
|
|||||||
/// <param name="dataZoom"></param>
|
/// <param name="dataZoom"></param>
|
||||||
public void UpdateFilterData(DataZoom dataZoom)
|
public void UpdateFilterData(DataZoom dataZoom)
|
||||||
{
|
{
|
||||||
if (dataZoom != null && dataZoom.show)
|
if (dataZoom != null && dataZoom.enable)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_Series.Count; i++)
|
for (int i = 0; i < m_Series.Count; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace XCharts
|
|||||||
[SerializeField] protected DataZoom m_DataZoom = DataZoom.defaultDataZoom;
|
[SerializeField] protected DataZoom m_DataZoom = DataZoom.defaultDataZoom;
|
||||||
|
|
||||||
private bool m_DataZoomDrag;
|
private bool m_DataZoomDrag;
|
||||||
|
private bool m_DataZoomCoordinateDrag;
|
||||||
private bool m_DataZoomStartDrag;
|
private bool m_DataZoomStartDrag;
|
||||||
private bool m_DataZoomEndDrag;
|
private bool m_DataZoomEndDrag;
|
||||||
private float m_DataZoomLastStartIndex;
|
private float m_DataZoomLastStartIndex;
|
||||||
@@ -25,6 +26,7 @@ namespace XCharts
|
|||||||
private bool m_XAxisChanged;
|
private bool m_XAxisChanged;
|
||||||
private bool m_YAxisChanged;
|
private bool m_YAxisChanged;
|
||||||
private bool m_CheckMinMaxValue;
|
private bool m_CheckMinMaxValue;
|
||||||
|
private bool m_CheckDataZoomLabel;
|
||||||
private List<XAxis> m_CheckXAxises = new List<XAxis>();
|
private List<XAxis> m_CheckXAxises = new List<XAxis>();
|
||||||
private List<YAxis> m_CheckYAxises = new List<YAxis>();
|
private List<YAxis> m_CheckYAxises = new List<YAxis>();
|
||||||
private Grid m_CheckCoordinate = Grid.defaultGrid;
|
private Grid m_CheckCoordinate = Grid.defaultGrid;
|
||||||
@@ -69,7 +71,7 @@ namespace XCharts
|
|||||||
base.DrawChart(vh);
|
base.DrawChart(vh);
|
||||||
DrawCoordinate(vh);
|
DrawCoordinate(vh);
|
||||||
DrawSerie(vh);
|
DrawSerie(vh);
|
||||||
DrawDataZoom(vh);
|
DrawDataZoomSlider(vh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,8 +95,8 @@ namespace XCharts
|
|||||||
switch (serie.type)
|
switch (serie.type)
|
||||||
{
|
{
|
||||||
case SerieType.Line:
|
case SerieType.Line:
|
||||||
if (yCategory) DrawYLineSerie(vh,serie, colorIndex, ref m_SeriesCurrHig);
|
if (yCategory) DrawYLineSerie(vh, serie, colorIndex, ref m_SeriesCurrHig);
|
||||||
else DrawXLineSerie(vh,serie, colorIndex, ref m_SeriesCurrHig);
|
else DrawXLineSerie(vh, serie, colorIndex, ref m_SeriesCurrHig);
|
||||||
break;
|
break;
|
||||||
case SerieType.Bar:
|
case SerieType.Bar:
|
||||||
if (yCategory) DrawYBarSerie(vh, serie, colorIndex, ref m_SeriesCurrHig);
|
if (yCategory) DrawYBarSerie(vh, serie, colorIndex, ref m_SeriesCurrHig);
|
||||||
@@ -122,8 +124,7 @@ namespace XCharts
|
|||||||
|
|
||||||
protected override void CheckTootipArea(Vector2 local)
|
protected override void CheckTootipArea(Vector2 local)
|
||||||
{
|
{
|
||||||
if (local.x < coordinateX - 1 || local.x > coordinateX + coordinateWid + 1 ||
|
if (!IsInCooridate(local))
|
||||||
local.y < coordinateY - 1 || local.y > coordinateY + coordinateHig + 1)
|
|
||||||
{
|
{
|
||||||
m_Tooltip.ClearValue();
|
m_Tooltip.ClearValue();
|
||||||
RefreshTooltip();
|
RefreshTooltip();
|
||||||
@@ -605,12 +606,12 @@ namespace XCharts
|
|||||||
ChartHelper.HideAllObject(dataZoomObject);
|
ChartHelper.HideAllObject(dataZoomObject);
|
||||||
m_DataZoom.startLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "start",
|
m_DataZoom.startLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "start",
|
||||||
dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleRight,
|
dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleRight,
|
||||||
Vector2.zero, Vector2.zero, new Vector2(1, 0.5f), new Vector2(200, 20));
|
Vector2.zero, Vector2.zero, new Vector2(1, 0.5f), new Vector2(200, 20), m_DataZoom.fontSize, 0, m_DataZoom.fontStyle);
|
||||||
m_DataZoom.endLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "end",
|
m_DataZoom.endLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "end",
|
||||||
dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleLeft,
|
dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleLeft,
|
||||||
Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20));
|
Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20), m_DataZoom.fontSize, 0, m_DataZoom.fontStyle);
|
||||||
m_DataZoom.SetLabelActive(false);
|
m_DataZoom.SetLabelActive(false);
|
||||||
raycastTarget = m_DataZoom.show;
|
raycastTarget = m_DataZoom.enable;
|
||||||
var xAxis = m_XAxises[m_DataZoom.xAxisIndex];
|
var xAxis = m_XAxises[m_DataZoom.xAxisIndex];
|
||||||
if (xAxis != null)
|
if (xAxis != null)
|
||||||
{
|
{
|
||||||
@@ -964,12 +965,13 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawDataZoom(VertexHelper vh)
|
private void DrawDataZoomSlider(VertexHelper vh)
|
||||||
{
|
{
|
||||||
if (!m_DataZoom.show) return;
|
if (!m_DataZoom.enable || !m_DataZoom.supportSlider) return;
|
||||||
|
var hig = m_DataZoom.GetHeight(grid.bottom);
|
||||||
var p1 = new Vector2(coordinateX, m_DataZoom.bottom);
|
var p1 = new Vector2(coordinateX, m_DataZoom.bottom);
|
||||||
var p2 = new Vector2(coordinateX, m_DataZoom.bottom + m_DataZoom.height);
|
var p2 = new Vector2(coordinateX, m_DataZoom.bottom + hig);
|
||||||
var p3 = new Vector2(coordinateX + coordinateWid, m_DataZoom.bottom + m_DataZoom.height);
|
var p3 = new Vector2(coordinateX + coordinateWid, m_DataZoom.bottom + hig);
|
||||||
var p4 = new Vector2(coordinateX + coordinateWid, m_DataZoom.bottom);
|
var p4 = new Vector2(coordinateX + coordinateWid, m_DataZoom.bottom);
|
||||||
var xAxis = xAxises[0];
|
var xAxis = xAxises[0];
|
||||||
ChartDrawer.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
ChartDrawer.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
||||||
@@ -980,7 +982,8 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
Serie serie = m_Series.list[0];
|
Serie serie = m_Series.list[0];
|
||||||
Axis axis = yAxises[0];
|
Axis axis = yAxises[0];
|
||||||
float scaleWid = coordinateWid / (serie.data.Count - 1);
|
var showData = serie.GetDataList(null);
|
||||||
|
float scaleWid = coordinateWid / (showData.Count - 1);
|
||||||
Vector3 lp = Vector3.zero;
|
Vector3 lp = Vector3.zero;
|
||||||
Vector3 np = Vector3.zero;
|
Vector3 np = Vector3.zero;
|
||||||
int minValue = 0;
|
int minValue = 0;
|
||||||
@@ -988,11 +991,21 @@ namespace XCharts
|
|||||||
m_Series.GetYMinMaxValue(null, 0, IsValue(), out minValue, out maxValue);
|
m_Series.GetYMinMaxValue(null, 0, IsValue(), out minValue, out maxValue);
|
||||||
axis.AdjustMinMaxValue(ref minValue, ref maxValue);
|
axis.AdjustMinMaxValue(ref minValue, ref maxValue);
|
||||||
if (minValue > 0 && maxValue > 0) minValue = 0;
|
if (minValue > 0 && maxValue > 0) minValue = 0;
|
||||||
for (int i = 0; i < serie.data.Count; i++)
|
|
||||||
|
|
||||||
|
int rate = 1;
|
||||||
|
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
|
||||||
|
var maxCount = showData.Count;
|
||||||
|
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWid / sampleDist));
|
||||||
|
if (rate < 1) rate = 1;
|
||||||
|
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||||
|
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||||
|
|
||||||
|
for (int i = 0; i < maxCount; i += rate)
|
||||||
{
|
{
|
||||||
float value = serie.data[i].data[1];
|
float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i);
|
||||||
float pX = coordinateX + i * scaleWid;
|
float pX = coordinateX + i * scaleWid;
|
||||||
float dataHig = value / (maxValue - minValue) * m_DataZoom.height;
|
float dataHig = value / (maxValue - minValue) * hig;
|
||||||
np = new Vector3(pX, m_DataZoom.bottom + dataHig);
|
np = new Vector3(pX, m_DataZoom.bottom + dataHig);
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
@@ -1014,8 +1027,8 @@ namespace XCharts
|
|||||||
var start = coordinateX + coordinateWid * m_DataZoom.start / 100;
|
var start = coordinateX + coordinateWid * m_DataZoom.start / 100;
|
||||||
var end = coordinateX + coordinateWid * m_DataZoom.end / 100;
|
var end = coordinateX + coordinateWid * m_DataZoom.end / 100;
|
||||||
p1 = new Vector2(start, m_DataZoom.bottom);
|
p1 = new Vector2(start, m_DataZoom.bottom);
|
||||||
p2 = new Vector2(start, m_DataZoom.bottom + m_DataZoom.height);
|
p2 = new Vector2(start, m_DataZoom.bottom + hig);
|
||||||
p3 = new Vector2(end, m_DataZoom.bottom + m_DataZoom.height);
|
p3 = new Vector2(end, m_DataZoom.bottom + hig);
|
||||||
p4 = new Vector2(end, m_DataZoom.bottom);
|
p4 = new Vector2(end, m_DataZoom.bottom);
|
||||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.dataZoomSelectedColor);
|
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.dataZoomSelectedColor);
|
||||||
ChartDrawer.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomSelectedColor);
|
ChartDrawer.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomSelectedColor);
|
||||||
@@ -1135,16 +1148,53 @@ namespace XCharts
|
|||||||
|
|
||||||
private void CheckDataZoom()
|
private void CheckDataZoom()
|
||||||
{
|
{
|
||||||
if (raycastTarget != m_DataZoom.show)
|
if (raycastTarget != m_DataZoom.enable)
|
||||||
{
|
{
|
||||||
raycastTarget = m_DataZoom.show;
|
raycastTarget = m_DataZoom.enable;
|
||||||
}
|
}
|
||||||
if (!m_DataZoom.show) return;
|
if (!m_DataZoom.enable) return;
|
||||||
if (m_DataZoom.showDetail)
|
CheckDataZoomScale();
|
||||||
|
CheckDataZoomLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool m_IsSingleTouch;
|
||||||
|
private Vector2 m_LastSingleTouchPos;
|
||||||
|
private Vector2 m_LastTouchPos0;
|
||||||
|
private Vector2 m_LastTouchPos1;
|
||||||
|
private void CheckDataZoomScale()
|
||||||
|
{
|
||||||
|
if (!m_DataZoom.enable || m_DataZoom.zoomLock || !m_DataZoom.supportInside) return;
|
||||||
|
|
||||||
|
if (Input.touchCount == 2)
|
||||||
|
{
|
||||||
|
var touch0 = Input.GetTouch(0);
|
||||||
|
var touch1 = Input.GetTouch(1);
|
||||||
|
if (touch1.phase == TouchPhase.Began)
|
||||||
|
{
|
||||||
|
m_LastTouchPos0 = touch0.position;
|
||||||
|
m_LastTouchPos1 = touch1.position;
|
||||||
|
}
|
||||||
|
else if (touch0.phase == TouchPhase.Moved || touch1.phase == TouchPhase.Moved)
|
||||||
|
{
|
||||||
|
var tempPos0 = touch0.position;
|
||||||
|
var tempPos1 = touch1.position;
|
||||||
|
var currDist = Vector2.Distance(tempPos0, tempPos1);
|
||||||
|
var lastDist = Vector2.Distance(m_LastTouchPos0, m_LastTouchPos1);
|
||||||
|
var delta = (currDist - lastDist);
|
||||||
|
ScaleDataZoom(delta / m_DataZoom.scrollSensitivity);
|
||||||
|
m_LastTouchPos0 = tempPos0;
|
||||||
|
m_LastTouchPos1 = tempPos1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckDataZoomLabel()
|
||||||
|
{
|
||||||
|
if (m_DataZoom.supportSlider && m_DataZoom.showDetail)
|
||||||
{
|
{
|
||||||
Vector2 local;
|
Vector2 local;
|
||||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||||
Input.mousePosition, null, out local))
|
Input.mousePosition, canvas.worldCamera, out local))
|
||||||
{
|
{
|
||||||
m_DataZoom.SetLabelActive(false);
|
m_DataZoom.SetLabelActive(false);
|
||||||
return;
|
return;
|
||||||
@@ -1158,9 +1208,35 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
m_DataZoom.SetLabelActive(false);
|
m_DataZoom.SetLabelActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (m_CheckDataZoomLabel)
|
||||||
|
{
|
||||||
|
m_CheckDataZoomLabel = false;
|
||||||
|
var xAxis = m_XAxises[m_DataZoom.xAxisIndex];
|
||||||
|
var startIndex = (int)((xAxis.data.Count - 1) * m_DataZoom.start / 100);
|
||||||
|
var endIndex = (int)((xAxis.data.Count - 1) * m_DataZoom.end / 100);
|
||||||
|
if (m_DataZoomLastStartIndex != startIndex || m_DataZoomLastEndIndex != endIndex)
|
||||||
|
{
|
||||||
|
m_DataZoomLastStartIndex = startIndex;
|
||||||
|
m_DataZoomLastEndIndex = endIndex;
|
||||||
|
if (xAxis.data.Count > 0)
|
||||||
|
{
|
||||||
|
m_DataZoom.SetStartLabelText(xAxis.data[startIndex]);
|
||||||
|
m_DataZoom.SetEndLabelText(xAxis.data[endIndex]);
|
||||||
|
}
|
||||||
|
InitAxisX();
|
||||||
|
}
|
||||||
|
var start = coordinateX + coordinateWid * m_DataZoom.start / 100;
|
||||||
|
var end = coordinateX + coordinateWid * m_DataZoom.end / 100;
|
||||||
|
var hig = m_DataZoom.GetHeight(grid.bottom);
|
||||||
|
m_DataZoom.startLabel.transform.localPosition =
|
||||||
|
new Vector3(start - 10, m_DataZoom.bottom + hig / 2);
|
||||||
|
m_DataZoom.endLabel.transform.localPosition =
|
||||||
|
new Vector3(end + 10, m_DataZoom.bottom + hig / 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DrawLabelBackground(VertexHelper vh)
|
protected void DrawLabelBackground(VertexHelper vh)
|
||||||
@@ -1257,64 +1333,103 @@ namespace XCharts
|
|||||||
|
|
||||||
public override void OnBeginDrag(PointerEventData eventData)
|
public override void OnBeginDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
|
if (Input.touchCount > 1) return;
|
||||||
Vector2 pos;
|
Vector2 pos;
|
||||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||||
eventData.position, canvas.worldCamera, out pos))
|
eventData.position, canvas.worldCamera, out pos))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_DataZoom.IsInStartZoom(pos, coordinateX, coordinateWid))
|
if (m_DataZoom.supportInside)
|
||||||
{
|
{
|
||||||
m_DataZoom.isDraging = true;
|
if (IsInCooridate(pos))
|
||||||
m_DataZoomStartDrag = true;
|
{
|
||||||
|
m_DataZoom.isDraging = true;
|
||||||
|
m_DataZoomCoordinateDrag = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (m_DataZoom.IsInEndZoom(pos, coordinateX, coordinateWid))
|
if (m_DataZoom.supportSlider)
|
||||||
{
|
{
|
||||||
m_DataZoom.isDraging = true;
|
if (m_DataZoom.IsInStartZoom(pos, coordinateX, coordinateWid))
|
||||||
m_DataZoomEndDrag = true;
|
{
|
||||||
}
|
m_DataZoom.isDraging = true;
|
||||||
else if (m_DataZoom.IsInSelectedZoom(pos, coordinateX, coordinateWid))
|
m_DataZoomStartDrag = true;
|
||||||
{
|
}
|
||||||
m_DataZoom.isDraging = true;
|
else if (m_DataZoom.IsInEndZoom(pos, coordinateX, coordinateWid))
|
||||||
m_DataZoomDrag = true;
|
{
|
||||||
|
m_DataZoom.isDraging = true;
|
||||||
|
m_DataZoomEndDrag = true;
|
||||||
|
}
|
||||||
|
else if (m_DataZoom.IsInSelectedZoom(pos, coordinateX, coordinateWid))
|
||||||
|
{
|
||||||
|
m_DataZoom.isDraging = true;
|
||||||
|
m_DataZoomDrag = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDrag(PointerEventData eventData)
|
public override void OnDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
|
if (Input.touchCount > 1) return;
|
||||||
float deltaX = eventData.delta.x;
|
float deltaX = eventData.delta.x;
|
||||||
float deltaPercent = deltaX / coordinateWid * 100;
|
float deltaPercent = deltaX / coordinateWid * 100;
|
||||||
|
OnDragInside(deltaPercent);
|
||||||
|
OnDragSlider(deltaPercent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDragInside(float deltaPercent)
|
||||||
|
{
|
||||||
|
if (Input.touchCount > 1) return;
|
||||||
|
if (!m_DataZoom.supportInside) return;
|
||||||
|
if (!m_DataZoomCoordinateDrag) return;
|
||||||
|
var diff = m_DataZoom.end - m_DataZoom.start;
|
||||||
|
if (deltaPercent > 0)
|
||||||
|
{
|
||||||
|
m_DataZoom.start -= deltaPercent;
|
||||||
|
m_DataZoom.end = m_DataZoom.start + diff;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_DataZoom.end += -deltaPercent;
|
||||||
|
m_DataZoom.start = m_DataZoom.end - diff;
|
||||||
|
}
|
||||||
|
RefreshDataZoomLabel();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDragSlider(float deltaPercent)
|
||||||
|
{
|
||||||
|
if (Input.touchCount > 1) return;
|
||||||
|
if (!m_DataZoom.supportSlider) return;
|
||||||
if (m_DataZoomStartDrag)
|
if (m_DataZoomStartDrag)
|
||||||
{
|
{
|
||||||
m_DataZoom.start += deltaPercent;
|
m_DataZoom.start += deltaPercent;
|
||||||
if (m_DataZoom.start < 0)
|
if (m_DataZoom.start > m_DataZoom.end)
|
||||||
{
|
|
||||||
m_DataZoom.start = 0;
|
|
||||||
}
|
|
||||||
else if (m_DataZoom.start > m_DataZoom.end)
|
|
||||||
{
|
{
|
||||||
m_DataZoom.start = m_DataZoom.end;
|
m_DataZoom.start = m_DataZoom.end;
|
||||||
m_DataZoomEndDrag = true;
|
m_DataZoomEndDrag = true;
|
||||||
m_DataZoomStartDrag = false;
|
m_DataZoomStartDrag = false;
|
||||||
}
|
}
|
||||||
RefreshDataZoomLabel();
|
if (m_DataZoom.realtime)
|
||||||
RefreshChart();
|
{
|
||||||
|
RefreshDataZoomLabel();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (m_DataZoomEndDrag)
|
else if (m_DataZoomEndDrag)
|
||||||
{
|
{
|
||||||
m_DataZoom.end += deltaPercent;
|
m_DataZoom.end += deltaPercent;
|
||||||
if (m_DataZoom.end > 100)
|
if (m_DataZoom.end < m_DataZoom.start)
|
||||||
{
|
|
||||||
m_DataZoom.end = 100;
|
|
||||||
}
|
|
||||||
else if (m_DataZoom.end < m_DataZoom.start)
|
|
||||||
{
|
{
|
||||||
m_DataZoom.end = m_DataZoom.start;
|
m_DataZoom.end = m_DataZoom.start;
|
||||||
m_DataZoomStartDrag = true;
|
m_DataZoomStartDrag = true;
|
||||||
m_DataZoomEndDrag = false;
|
m_DataZoomEndDrag = false;
|
||||||
}
|
}
|
||||||
RefreshDataZoomLabel();
|
if (m_DataZoom.realtime)
|
||||||
RefreshChart();
|
{
|
||||||
|
RefreshDataZoomLabel();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (m_DataZoomDrag)
|
else if (m_DataZoomDrag)
|
||||||
{
|
{
|
||||||
@@ -1334,43 +1449,27 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
m_DataZoom.start += deltaPercent;
|
m_DataZoom.start += deltaPercent;
|
||||||
m_DataZoom.end += deltaPercent;
|
m_DataZoom.end += deltaPercent;
|
||||||
RefreshDataZoomLabel();
|
if (m_DataZoom.realtime)
|
||||||
RefreshChart();
|
{
|
||||||
|
RefreshDataZoomLabel();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshDataZoomLabel()
|
private void RefreshDataZoomLabel()
|
||||||
{
|
{
|
||||||
var xAxis = m_XAxises[m_DataZoom.xAxisIndex];
|
m_CheckDataZoomLabel = true;
|
||||||
var startIndex = (int)((xAxis.data.Count - 1) * m_DataZoom.start / 100);
|
|
||||||
var endIndex = (int)((xAxis.data.Count - 1) * m_DataZoom.end / 100);
|
|
||||||
if (m_DataZoomLastStartIndex != startIndex || m_DataZoomLastEndIndex != endIndex)
|
|
||||||
{
|
|
||||||
m_DataZoomLastStartIndex = startIndex;
|
|
||||||
m_DataZoomLastEndIndex = endIndex;
|
|
||||||
if (xAxis.data.Count > 0)
|
|
||||||
{
|
|
||||||
m_DataZoom.SetStartLabelText(xAxis.data[startIndex]);
|
|
||||||
m_DataZoom.SetEndLabelText(xAxis.data[endIndex]);
|
|
||||||
}
|
|
||||||
InitAxisX();
|
|
||||||
}
|
|
||||||
|
|
||||||
var start = coordinateX + coordinateWid * m_DataZoom.start / 100;
|
|
||||||
var end = coordinateX + coordinateWid * m_DataZoom.end / 100;
|
|
||||||
m_DataZoom.startLabel.transform.localPosition =
|
|
||||||
new Vector3(start - 10, m_DataZoom.bottom + m_DataZoom.height / 2);
|
|
||||||
m_DataZoom.endLabel.transform.localPosition =
|
|
||||||
new Vector3(end + 10, m_DataZoom.bottom + m_DataZoom.height / 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnEndDrag(PointerEventData eventData)
|
public override void OnEndDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
if (m_DataZoomDrag || m_DataZoomStartDrag || m_DataZoomEndDrag)
|
if (m_DataZoomDrag || m_DataZoomStartDrag || m_DataZoomEndDrag || m_DataZoomCoordinateDrag)
|
||||||
{
|
{
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
}
|
}
|
||||||
m_DataZoomDrag = false;
|
m_DataZoomDrag = false;
|
||||||
|
m_DataZoomCoordinateDrag = false;
|
||||||
m_DataZoomStartDrag = false;
|
m_DataZoomStartDrag = false;
|
||||||
m_DataZoomEndDrag = false;
|
m_DataZoomEndDrag = false;
|
||||||
m_DataZoom.isDraging = false;
|
m_DataZoom.isDraging = false;
|
||||||
@@ -1378,6 +1477,7 @@ namespace XCharts
|
|||||||
|
|
||||||
public override void OnPointerDown(PointerEventData eventData)
|
public override void OnPointerDown(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
|
if (Input.touchCount > 1) return;
|
||||||
Vector2 localPos;
|
Vector2 localPos;
|
||||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||||
eventData.position, canvas.worldCamera, out localPos))
|
eventData.position, canvas.worldCamera, out localPos))
|
||||||
@@ -1415,10 +1515,25 @@ namespace XCharts
|
|||||||
|
|
||||||
public override void OnScroll(PointerEventData eventData)
|
public override void OnScroll(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
if (!m_DataZoom.show || m_DataZoom.zoomLock) return;
|
if (Input.touchCount > 1) return;
|
||||||
float deltaPercent = Mathf.Abs(eventData.scrollDelta.y *
|
if (!m_DataZoom.enable || m_DataZoom.zoomLock || !m_DataZoom.supportInside) return;
|
||||||
m_DataZoom.scrollSensitivity / coordinateWid * 100);
|
Vector2 pos;
|
||||||
if (eventData.scrollDelta.y > 0)
|
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||||
|
eventData.position, canvas.worldCamera, out pos))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!IsInCooridate(pos))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ScaleDataZoom(eventData.scrollDelta.y * m_DataZoom.scrollSensitivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ScaleDataZoom(float delta)
|
||||||
|
{
|
||||||
|
float deltaPercent = Mathf.Abs(delta / coordinateWid * 100);
|
||||||
|
if (delta > 0)
|
||||||
{
|
{
|
||||||
if (m_DataZoom.end <= m_DataZoom.start) return;
|
if (m_DataZoom.end <= m_DataZoom.start) return;
|
||||||
m_DataZoom.end -= deltaPercent;
|
m_DataZoom.end -= deltaPercent;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace XCharts
|
namespace XCharts
|
||||||
{
|
{
|
||||||
@@ -131,6 +132,15 @@ namespace XCharts
|
|||||||
return !IsValue();
|
return !IsValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsInCooridate(Vector2 local)
|
||||||
|
{
|
||||||
|
if (local.x < coordinateX - 1 || local.x > coordinateX + coordinateWid + 1 ||
|
||||||
|
local.y < coordinateY - 1 || local.y > coordinateY + coordinateHig + 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user