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