From a0537ea015ddd885c4e34dad4d7a7a88a2fb3ac3 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 1 Apr 2019 23:05:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=BA=E5=AF=B8=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/BaseAxesChart.cs | 29 ++++++++++++----------------- Scripts/BaseChart.cs | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Scripts/BaseAxesChart.cs b/Scripts/BaseAxesChart.cs index 2940191b..1b8714e2 100644 --- a/Scripts/BaseAxesChart.cs +++ b/Scripts/BaseAxesChart.cs @@ -154,6 +154,8 @@ namespace xcharts lastCoordinateHig = chartHig; lastCoordinateWid = chartWid; lastCoordinateScaleLen = coordinate.splitWidth; + checkXAxis = xAxis; + checkYAxis = yAxis; InitXScale(); InitYScale(); } @@ -363,6 +365,7 @@ namespace xcharts new Vector2(1, 0.5f), new Vector2(scaleWid, 20)); txt.transform.localPosition = GetXScalePosition(scaleWid, i); + txt.text = xAxis.GetData(i, max); txt.gameObject.SetActive(coordinate.show); xScaleTextList.Add(txt); @@ -470,23 +473,8 @@ namespace xcharts protected virtual void OnCoordinateSize() { - //update yScale pos - float yscaleWid = coordinateHig / (yAxis.GetSplitNumber() - 1); - float xscaleWid = coordinateHig / (xAxis.GetSplitNumber() - 1); - for (int i = 0; i < yAxis.GetSplitNumber(); i++) - { - if (i < yScaleTextList.Count && yScaleTextList[i]) - { - yScaleTextList[i].transform.localPosition = GetYScalePosition(yscaleWid,i); - } - } - for (int i = 0; i < xAxis.GetSplitNumber(); i++) - { - if (i < xScaleTextList.Count && xScaleTextList[i]) - { - xScaleTextList[i].transform.localPosition = GetXScalePosition(xscaleWid, i); - } - } + InitXScale(); + InitYScale(); } protected virtual void OnYAxisChanged() @@ -510,6 +498,13 @@ namespace xcharts } } + protected override void OnSizeChanged() + { + base.OnSizeChanged(); + InitXScale(); + InitYScale(); + } + protected override void OnYMaxValueChanged() { float max = GetMaxValue(); diff --git a/Scripts/BaseChart.cs b/Scripts/BaseChart.cs index f60d9fee..0fc902ca 100644 --- a/Scripts/BaseChart.cs +++ b/Scripts/BaseChart.cs @@ -249,6 +249,8 @@ namespace xcharts private Theme checkTheme = 0; private Title checkTitle = new Title(); private Legend checkLegend = new Legend(); + private float checkWid = 0; + private float checkHig = 0; protected Text titleText; protected List legendTextList = new List(); @@ -261,6 +263,9 @@ namespace xcharts rectTransform.anchorMax = Vector2.zero; rectTransform.anchorMin = Vector2.zero; rectTransform.pivot = Vector2.zero; + checkWid = chartWid; + checkHig = chartHig; + checkTheme = theme; InitTitle(); InitLegend(); InitTooltip(); @@ -268,6 +273,7 @@ namespace xcharts protected virtual void Update() { + CheckSize(); CheckTheme(); CheckTile(); CheckLegend(); @@ -472,6 +478,16 @@ namespace xcharts return bigger < 10 ? bigger : bigger - bigger % 10; } + private void CheckSize() + { + if(checkWid != chartWid || checkHig != chartHig) + { + checkWid = chartWid; + checkHig = chartHig; + OnSizeChanged(); + } + } + private void CheckTheme() { if (checkTheme != theme) @@ -549,6 +565,12 @@ namespace xcharts { } + protected virtual void OnSizeChanged() + { + InitTitle(); + InitLegend(); + } + protected virtual void OnThemeChanged() { switch (theme)