diff --git a/Scripts/Editor/BaseChartEditor.cs b/Scripts/Editor/BaseChartEditor.cs index e2fcc767..7091efce 100644 --- a/Scripts/Editor/BaseChartEditor.cs +++ b/Scripts/Editor/BaseChartEditor.cs @@ -12,6 +12,8 @@ namespace XCharts { protected BaseChart m_Target; protected SerializedProperty m_Script; + protected SerializedProperty m_ChartWidth; + protected SerializedProperty m_ChartHeight; protected SerializedProperty m_Theme; protected SerializedProperty m_ThemeInfo; protected SerializedProperty m_Title; @@ -39,6 +41,8 @@ namespace XCharts { m_Target = (BaseChart)target; m_Script = serializedObject.FindProperty("m_Script"); + m_ChartWidth = serializedObject.FindProperty("m_ChartWidth"); + m_ChartHeight = serializedObject.FindProperty("m_ChartHeight"); m_Theme = serializedObject.FindProperty("m_Theme"); m_ThemeInfo = serializedObject.FindProperty("m_ThemeInfo"); m_Title = serializedObject.FindProperty("m_Title"); @@ -74,12 +78,23 @@ namespace XCharts { EditorGUILayout.PropertyField(m_Script); EditorGUILayout.BeginHorizontal(); + + EditorGUIUtility.labelWidth = 20; + EditorGUILayout.LabelField("Size"); + EditorGUIUtility.fieldWidth = 1; + m_ChartWidth.floatValue = EditorGUILayout.FloatField(m_ChartWidth.floatValue); + m_ChartHeight.floatValue = EditorGUILayout.FloatField(m_ChartHeight.floatValue); + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + EditorGUIUtility.labelWidth = m_DefaultLabelWidth; EditorGUIUtility.fieldWidth = EditorGUIUtility.labelWidth - 5; m_ThemeModuleToggle = EditorGUILayout.Foldout(m_ThemeModuleToggle, - new GUIContent("Theme","the theme of chart\n主题"), + new GUIContent("Theme", "the theme of chart\n主题"), ChartEditorHelper.foldoutStyle); EditorGUILayout.PropertyField(m_Theme, GUIContent.none); EditorGUILayout.EndHorizontal(); + EditorGUIUtility.labelWidth = m_DefaultLabelWidth; EditorGUIUtility.fieldWidth = m_DefaultFieldWidth; if (m_ThemeModuleToggle) @@ -95,13 +110,13 @@ namespace XCharts { EditorGUILayout.PropertyField(m_Series, true); m_BaseModuleToggle = EditorGUILayout.Foldout(m_BaseModuleToggle, - new GUIContent("Base","基础配置"), + new GUIContent("Base", "基础配置"), ChartEditorHelper.foldoutStyle); if (m_BaseModuleToggle) { EditorGUI.indentLevel++; var largeTip = "Whether to enable the optimization of large-scale graph. \n是否启用大规模线图的优化,在数据图形特别多的时候(>=5k)可以开启。"; - EditorGUILayout.PropertyField(m_Large, new GUIContent("Large",largeTip)); + EditorGUILayout.PropertyField(m_Large, new GUIContent("Large", largeTip)); EditorGUILayout.PropertyField(m_MinShowDataNumber, true); EditorGUILayout.PropertyField(m_MaxShowDataNumber, true); EditorGUILayout.PropertyField(m_MaxCacheDataNumber, true); diff --git a/Scripts/UI/BarChart.cs b/Scripts/UI/BarChart.cs index a061edb4..2a0875c3 100644 --- a/Scripts/UI/BarChart.cs +++ b/Scripts/UI/BarChart.cs @@ -25,7 +25,7 @@ namespace XCharts get{ return new Bar(){ m_InSameBar = false, - m_BarWidth = 0.7f, + m_BarWidth = 0.6f, m_Space = 10 }; } @@ -41,8 +41,9 @@ namespace XCharts { base.Reset(); m_Bar = Bar.defaultBar; + m_Title.text = "BarChart"; RemoveData(); - AddSerie("bar1", SerieType.Line); + AddSerie("serie1", SerieType.Line); for (int i = 0; i < 5; i++) { AddXAxisData("x" + (i + 1)); diff --git a/Scripts/UI/Internal/BaseChart.cs b/Scripts/UI/Internal/BaseChart.cs index f91b3ea9..7f1ef41c 100644 --- a/Scripts/UI/Internal/BaseChart.cs +++ b/Scripts/UI/Internal/BaseChart.cs @@ -19,6 +19,8 @@ namespace XCharts private static readonly string s_TitleObjectName = "title"; private static readonly string s_LegendObjectName = "legend"; + [SerializeField] protected float m_ChartWidth; + [SerializeField] protected float m_ChartHeight; [SerializeField] protected Theme m_Theme = Theme.Default; [SerializeField] protected ThemeInfo m_ThemeInfo; [SerializeField] protected Title m_Title = Title.defaultTitle; @@ -39,8 +41,6 @@ namespace XCharts [NonSerialized] private bool m_RefreshChart = false; [NonSerialized] protected List m_LegendTextList = new List(); - protected float chartWidth { get { return rectTransform.sizeDelta.x; } } - protected float chartHeight { get { return rectTransform.sizeDelta.y; } } protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } } protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } } protected Vector2 chartPivot { get { return rectTransform.pivot; } } @@ -50,6 +50,9 @@ namespace XCharts public Tooltip tooltip { get { return m_Tooltip; } } public Series series { get { return m_Series; } } + public float chartWidth { get { return m_ChartWidth; } } + public float chartHeight { get { return m_ChartHeight; } } + /// /// The min number of data to show in chart. /// @@ -79,6 +82,21 @@ namespace XCharts set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; } } + /// + /// Set the size of chart. + /// + /// width + /// height + public virtual void SetSize(float width, float height) + { + m_ChartWidth = width; + m_ChartHeight = height; + m_CheckWidth = width; + m_CheckHeight = height; + rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight); + OnSizeChanged(); + } + /// /// Remove all series and legend data. /// It just emptying all of serie's data without emptying the list of series. @@ -246,8 +264,10 @@ namespace XCharts rectTransform.anchorMax = Vector2.zero; rectTransform.anchorMin = Vector2.zero; rectTransform.pivot = Vector2.zero; - m_CheckWidth = chartWidth; - m_CheckHeight = chartHeight; + m_ChartWidth = rectTransform.sizeDelta.x; + m_ChartHeight = rectTransform.sizeDelta.y; + m_CheckWidth = m_ChartWidth; + m_CheckHeight = m_ChartHeight; m_CheckTheme = m_Theme; InitTitle(); InitLegend(); @@ -267,6 +287,11 @@ namespace XCharts #if UNITY_EDITOR protected override void Reset() { + var sizeDelta = rectTransform.sizeDelta; + if (sizeDelta.x < 580 && sizeDelta.y < 300) + { + rectTransform.sizeDelta = new Vector2(580, 300); + } ChartHelper.DestoryAllChilds(transform); m_ThemeInfo = ThemeInfo.Default; m_Title = Title.defaultTitle; @@ -388,9 +413,12 @@ namespace XCharts { if (m_CheckWidth != chartWidth || m_CheckHeight != chartHeight) { - m_CheckWidth = chartWidth; - m_CheckHeight = chartHeight; - OnSizeChanged(); + SetSize(chartWidth, chartHeight); + } + var sizeDelta = rectTransform.sizeDelta; + if (m_CheckWidth != sizeDelta.x || m_CheckHeight != sizeDelta.y) + { + SetSize(sizeDelta.x, sizeDelta.y); } } diff --git a/Scripts/UI/Internal/Coordinate.cs b/Scripts/UI/Internal/Coordinate.cs index 692cc007..8d11d366 100644 --- a/Scripts/UI/Internal/Coordinate.cs +++ b/Scripts/UI/Internal/Coordinate.cs @@ -28,7 +28,7 @@ namespace XCharts { m_Left = 50, m_Right = 30, - m_Top = 60, + m_Top = 50, m_Bottom = 30, m_Tickness = 0.6f, m_FontSize = 16, diff --git a/Scripts/UI/Internal/CoordinateChart.cs b/Scripts/UI/Internal/CoordinateChart.cs index 98cdb36b..c39f407f 100644 --- a/Scripts/UI/Internal/CoordinateChart.cs +++ b/Scripts/UI/Internal/CoordinateChart.cs @@ -330,7 +330,7 @@ namespace XCharts var axis1 = YAxis.defaultYAxis; var axis2 = YAxis.defaultYAxis; axis1.show = true; - axis1.splitNumber = 6; + axis1.splitNumber = 5; axis1.boundaryGap = false; axis2.show = false; m_YAxises.Add(axis1); diff --git a/Scripts/UI/Internal/Legend.cs b/Scripts/UI/Internal/Legend.cs index f309a2c9..ff87cc9e 100644 --- a/Scripts/UI/Internal/Legend.cs +++ b/Scripts/UI/Internal/Legend.cs @@ -42,7 +42,7 @@ namespace XCharts { var legend = new Legend { - m_Show = true, + m_Show = false, m_Orient = Orient.Horizonal, m_Location = Location.defaultTop, m_ItemWidth = 60.0f, diff --git a/Scripts/UI/LineChart.cs b/Scripts/UI/LineChart.cs index 92a04cec..3d580b8a 100644 --- a/Scripts/UI/LineChart.cs +++ b/Scripts/UI/LineChart.cs @@ -19,8 +19,9 @@ namespace XCharts { base.Reset(); m_Line = Line.defaultLine; + m_Title.text = "LineChart"; RemoveData(); - AddSerie("line1", SerieType.Line); + AddSerie("serie1", SerieType.Line); for (int i = 0; i < 5; i++) { AddXAxisData("x" + (i + 1)); diff --git a/Scripts/UI/PieChart.cs b/Scripts/UI/PieChart.cs index 91a05c00..4650f163 100644 --- a/Scripts/UI/PieChart.cs +++ b/Scripts/UI/PieChart.cs @@ -74,9 +74,10 @@ namespace XCharts { base.Reset(); m_Pie = Pie.defaultPie; + m_Title.text = "PieChart"; RemoveData(); - AddData("Pie1", 80); - AddData("Pie2", 20); + AddData("serie1", 80); + AddData("serie2", 20); } #endif diff --git a/Scripts/UI/RadarChart.cs b/Scripts/UI/RadarChart.cs index 7be38779..a09d5c90 100644 --- a/Scripts/UI/RadarChart.cs +++ b/Scripts/UI/RadarChart.cs @@ -48,7 +48,8 @@ namespace XCharts base.Reset(); RemoveData(); m_Radar = Radar.defaultRadar; - AddSerie("Radar", SerieType.Radar); + m_Title.text = "RadarChart"; + AddSerie("serie1", SerieType.Radar); for (int i = 0; i < 5; i++) { AddData(0, Random.Range(20, 90));