mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 17:00:08 +00:00
优化代码
This commit is contained in:
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -683,10 +684,18 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(VertexHelper vh)
|
||||
public void DrawBase(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
public void DrawTop(VertexHelper vh)
|
||||
{
|
||||
foreach (var dataZoom in chart.dataZooms)
|
||||
{
|
||||
DrawDataZoomSlider(vh, dataZoom);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (chart == null) return;
|
||||
@@ -991,6 +1000,12 @@ namespace XCharts
|
||||
dataZoom.SetStartLabelText(xAxis.data[startIndex]);
|
||||
dataZoom.SetEndLabelText(xAxis.data[endIndex]);
|
||||
}
|
||||
else if (xAxis.IsTime())
|
||||
{
|
||||
//TODO:
|
||||
dataZoom.SetStartLabelText("");
|
||||
dataZoom.SetEndLabelText("");
|
||||
}
|
||||
chart.InitAxisX();
|
||||
}
|
||||
var start = dataZoom.runtimeX + dataZoom.runtimeWidth * dataZoom.start / 100;
|
||||
@@ -1000,5 +1015,87 @@ namespace XCharts
|
||||
dataZoom.UpdateEndLabelPosition(new Vector3(end + 10, chart.chartY + dataZoom.bottom + hig / 2));
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
|
||||
{
|
||||
if (!dataZoom.enable || !dataZoom.supportSlider) return;
|
||||
var p1 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY);
|
||||
var p2 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
var p3 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
var p4 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY);
|
||||
var xAxis = chart.GetXAxis(0);
|
||||
var lineColor = dataZoom.lineStyle.GetColor(chart.theme.dataZoom.dataLineColor);
|
||||
var lineWidth = dataZoom.lineStyle.GetWidth(chart.theme.dataZoom.dataLineWidth);
|
||||
var borderWidth = dataZoom.borderWidth == 0 ? chart.theme.dataZoom.borderWidth : dataZoom.borderWidth;
|
||||
var borderColor = dataZoom.GetBorderColor(chart.theme.dataZoom.borderColor);
|
||||
var backgroundColor = dataZoom.GetBackgroundColor(chart.theme.dataZoom.backgroundColor);
|
||||
var areaColor = dataZoom.areaStyle.GetColor(chart.theme.dataZoom.dataAreaColor);
|
||||
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, backgroundColor);
|
||||
var centerPos = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth / 2,
|
||||
dataZoom.runtimeY + dataZoom.runtimeHeight / 2);
|
||||
UGL.DrawBorder(vh, centerPos, dataZoom.runtimeWidth, dataZoom.runtimeHeight, borderWidth, borderColor);
|
||||
if (dataZoom.showDataShadow && chart.series.Count > 0)
|
||||
{
|
||||
Serie serie = chart.series.list[0];
|
||||
Axis axis = chart.GetYAxis(0);
|
||||
var showData = serie.GetDataList(null);
|
||||
float scaleWid = dataZoom.runtimeWidth / (showData.Count - 1);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float minValue = 0;
|
||||
float maxValue = 0;
|
||||
SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsValue(), axis.inverse, out minValue, out maxValue);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);
|
||||
|
||||
int rate = 1;
|
||||
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
|
||||
var maxCount = showData.Count;
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (dataZoom.runtimeWidth / sampleDist));
|
||||
if (rate < 1) rate = 1;
|
||||
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||
chart.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||
var dataChanging = false;
|
||||
for (int i = 0; i < maxCount; i += rate)
|
||||
{
|
||||
float value = chart.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
|
||||
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
|
||||
float pX = dataZoom.runtimeX + i * scaleWid;
|
||||
float dataHig = (maxValue - minValue) == 0 ? 0 :
|
||||
(value - minValue) / (maxValue - minValue) * dataZoom.runtimeHeight;
|
||||
np = new Vector3(pX, chart.chartY + dataZoom.bottom + dataHig);
|
||||
if (i > 0)
|
||||
{
|
||||
UGL.DrawLine(vh, lp, np, lineWidth, lineColor);
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - lineWidth);
|
||||
Vector3 anp = new Vector3(np.x, np.y - lineWidth);
|
||||
|
||||
Vector3 tnp = new Vector3(np.x, chart.chartY + dataZoom.bottom + lineWidth);
|
||||
Vector3 tlp = new Vector3(lp.x, chart.chartY + dataZoom.bottom + lineWidth);
|
||||
UGL.DrawQuadrilateral(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
lp = np;
|
||||
}
|
||||
if (dataChanging)
|
||||
{
|
||||
chart.RefreshTopPainter();
|
||||
}
|
||||
}
|
||||
switch (dataZoom.rangeMode)
|
||||
{
|
||||
case DataZoom.RangeMode.Percent:
|
||||
var start = dataZoom.runtimeX + dataZoom.runtimeWidth * dataZoom.start / 100;
|
||||
var end = dataZoom.runtimeX + dataZoom.runtimeWidth * dataZoom.end / 100;
|
||||
var fillerColor = dataZoom.GetFillerColor(chart.theme.dataZoom.fillerColor);
|
||||
|
||||
p1 = new Vector2(start, dataZoom.runtimeY);
|
||||
p2 = new Vector2(start, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
p3 = new Vector2(end, dataZoom.runtimeY + dataZoom.runtimeHeight);
|
||||
p4 = new Vector2(end, dataZoom.runtimeY);
|
||||
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, fillerColor);
|
||||
UGL.DrawLine(vh, p1, p2, lineWidth, fillerColor);
|
||||
UGL.DrawLine(vh, p3, p4, lineWidth, fillerColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user