mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 18:30:14 +00:00
增加GaugeChart仪表盘
This commit is contained in:
@@ -34,9 +34,10 @@ namespace XCharts
|
||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler,
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
{
|
||||
private static readonly string s_TitleObjectName = "title";
|
||||
private static readonly string s_LegendObjectName = "legend";
|
||||
private static readonly string s_SerieLabelObjectName = "label";
|
||||
protected static readonly string s_TitleObjectName = "title";
|
||||
protected static readonly string s_LegendObjectName = "legend";
|
||||
protected static readonly string s_SerieLabelObjectName = "label";
|
||||
protected static readonly string s_SerieTitleObjectName = "serie";
|
||||
|
||||
[SerializeField] protected float m_ChartWidth;
|
||||
[SerializeField] protected float m_ChartHeight;
|
||||
@@ -62,7 +63,9 @@ namespace XCharts
|
||||
[NonSerialized] protected bool m_RefreshChart = false;
|
||||
[NonSerialized] protected bool m_RefreshLabel = false;
|
||||
[NonSerialized] protected bool m_ReinitLabel = false;
|
||||
[NonSerialized] protected bool m_ReinitTitle = false;
|
||||
[NonSerialized] protected bool m_CheckAnimation = false;
|
||||
[NonSerialized] protected bool m_IsPlayingStartAnimation = false;
|
||||
[NonSerialized] protected List<string> m_LegendRealShowName = new List<string>();
|
||||
|
||||
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
||||
@@ -87,6 +90,7 @@ namespace XCharts
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitSerieLabel();
|
||||
InitSerieTitle();
|
||||
InitTooltip();
|
||||
m_Series.AnimationStop();
|
||||
m_Series.AnimationStart();
|
||||
@@ -300,33 +304,64 @@ namespace XCharts
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
if (!serie.label.show && j > 100) continue;
|
||||
var serieLabel = serieData.GetSerieLabel(serie.label);
|
||||
if (!serieLabel.show && j > 100) continue;
|
||||
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
|
||||
var color = Color.grey;
|
||||
if (serie.type == SerieType.Pie)
|
||||
{
|
||||
color = (serie.label.position == SerieLabel.Position.Inside) ? Color.white :
|
||||
color = (serieLabel.position == SerieLabel.Position.Inside) ? Color.white :
|
||||
(Color)m_ThemeInfo.GetColor(count);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = serie.label.color != Color.clear ? serie.label.color :
|
||||
color = serieLabel.color != Color.clear ? serieLabel.color :
|
||||
(Color)m_ThemeInfo.GetColor(i);
|
||||
}
|
||||
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serie.label, m_ThemeInfo.font, color, serieData);
|
||||
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, m_ThemeInfo.font, color,
|
||||
serieData.iconStyle.width, serieData.iconStyle.height);
|
||||
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||
serieData.SetIconImage(iconImage);
|
||||
|
||||
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
|
||||
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
serieData.InitLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
serieData.SetLabelActive(false);
|
||||
serieData.SetLabelText(serieData.name);
|
||||
|
||||
//serieData.SetLabelText(serieData.name);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitSerieTitle()
|
||||
{
|
||||
var titleObject = ChartHelper.AddObject(s_SerieTitleObjectName, transform, Vector2.zero,
|
||||
Vector2.zero, Vector2.zero, new Vector2(chartWidth, chartHeight));
|
||||
ChartHelper.HideAllObject(titleObject);
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
var textStyle = serie.titleStyle.textStyle;
|
||||
var color = textStyle.color == Color.clear ? m_ThemeInfo.GetColor(i) : (Color32)textStyle.color;
|
||||
var anchorMin = new Vector2(0.5f, 0.5f);
|
||||
var anchorMax = new Vector2(0.5f, 0.5f);
|
||||
var pivot = new Vector2(0.5f, 0.5f);
|
||||
var fontSize = 10;
|
||||
var sizeDelta = new Vector2(50, fontSize + 2);
|
||||
var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color, TextAnchor.MiddleCenter,
|
||||
anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate, textStyle.fontStyle);
|
||||
txt.text = "";
|
||||
txt.transform.localPosition = new Vector2(0, 0);
|
||||
txt.transform.localEulerAngles = Vector2.zero;
|
||||
ChartHelper.SetActive(txt, false);
|
||||
serie.titleStyle.runtimeText = txt;
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData != null)
|
||||
{
|
||||
txt.text = serieData.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void InitTooltip()
|
||||
{
|
||||
@@ -507,6 +542,11 @@ namespace XCharts
|
||||
m_LegendRealShowName = m_Series.GetSerieNameList();
|
||||
InitSerieLabel();
|
||||
}
|
||||
if (m_ReinitTitle)
|
||||
{
|
||||
m_ReinitTitle = false;
|
||||
InitSerieTitle();
|
||||
}
|
||||
if (m_RefreshLabel)
|
||||
{
|
||||
m_RefreshLabel = false;
|
||||
@@ -717,25 +757,26 @@ namespace XCharts
|
||||
{
|
||||
var labelHalfWid = serieData.GetLabelWidth() / 2;
|
||||
var labelHalfHig = serieData.GetLabelHeight() / 2;
|
||||
var centerPos = serieData.labelPosition + serie.label.offset;
|
||||
var serieLabel = serieData.GetSerieLabel(serie.label);
|
||||
var centerPos = serieData.labelPosition + serieLabel.offset;
|
||||
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
|
||||
var p2 = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
|
||||
var p3 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
|
||||
var p4 = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);
|
||||
|
||||
if (serie.label.rotate > 0)
|
||||
if (serieLabel.rotate > 0)
|
||||
{
|
||||
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
}
|
||||
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serie.label.backgroundColor);
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor);
|
||||
|
||||
if (serie.label.border)
|
||||
if (serieLabel.border)
|
||||
{
|
||||
var borderWid = serie.label.borderWidth;
|
||||
var borderWid = serieLabel.borderWidth;
|
||||
p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig + borderWid);
|
||||
p2 = new Vector3(centerPos.x + labelHalfWid + 2 * borderWid, centerPos.y + labelHalfHig + borderWid);
|
||||
p3 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y + labelHalfHig);
|
||||
@@ -744,21 +785,21 @@ namespace XCharts
|
||||
var p6 = new Vector3(centerPos.x - labelHalfWid - 2 * borderWid, centerPos.y - labelHalfHig - borderWid);
|
||||
var p7 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y - labelHalfHig);
|
||||
var p8 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y + labelHalfHig + 2 * borderWid);
|
||||
if (serie.label.rotate > 0)
|
||||
if (serieLabel.rotate > 0)
|
||||
{
|
||||
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p5 = ChartHelper.RotateRound(p5, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p6 = ChartHelper.RotateRound(p6, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p7 = ChartHelper.RotateRound(p7, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p8 = ChartHelper.RotateRound(p8, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p5 = ChartHelper.RotateRound(p5, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p6 = ChartHelper.RotateRound(p6, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p7 = ChartHelper.RotateRound(p7, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
p8 = ChartHelper.RotateRound(p8, centerPos, Vector3.forward, serieLabel.rotate);
|
||||
}
|
||||
ChartDrawer.DrawLine(vh, p1, p2, borderWid, serie.label.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p3, p4, borderWid, serie.label.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p5, p6, borderWid, serie.label.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p7, p8, borderWid, serie.label.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p1, p2, borderWid, serieLabel.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p3, p4, borderWid, serieLabel.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p5, p6, borderWid, serieLabel.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p7, p8, borderWid, serieLabel.borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ namespace XCharts
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
if (!m_CheckMinMaxValue) return;
|
||||
m_IsPlayingStartAnimation = false;
|
||||
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
|
||||
m_Series.GetStackSeries(ref m_StackSeries);
|
||||
int seriesCount = m_StackSeries.Count;
|
||||
@@ -787,7 +788,7 @@ namespace XCharts
|
||||
{
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, false, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue);
|
||||
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue, true);
|
||||
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
|
||||
{
|
||||
m_CheckMinMaxValue = true;
|
||||
@@ -814,10 +815,17 @@ namespace XCharts
|
||||
{
|
||||
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
axis.UpdateLabelText(coordinateWidth, m_DataZoom, isPercentStack);
|
||||
axis.UpdateLabelText(coordinateWidth, m_DataZoom, isPercentStack, 500);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
if (axis.IsValueChanging(500) && !m_IsPlayingStartAnimation)
|
||||
{
|
||||
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
axis.UpdateLabelText(coordinateWidth, m_DataZoom, isPercentStack, 500);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnCoordinateChanged()
|
||||
@@ -1044,7 +1052,7 @@ namespace XCharts
|
||||
float minValue = 0;
|
||||
float maxValue = 0;
|
||||
m_Series.GetYMinMaxValue(null, 0, IsValue(), out minValue, out maxValue);
|
||||
axis.AdjustMinMaxValue(ref minValue, ref maxValue);
|
||||
axis.AdjustMinMaxValue(ref minValue, ref maxValue, true);
|
||||
|
||||
int rate = 1;
|
||||
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
|
||||
@@ -1053,10 +1061,11 @@ namespace XCharts
|
||||
if (rate < 1) rate = 1;
|
||||
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||
|
||||
var dataChanging = false;
|
||||
for (int i = 0; i < maxCount; i += rate)
|
||||
{
|
||||
float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i);
|
||||
float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
|
||||
serie.animation.GetUpdateAnimationDuration(), ref dataChanging);
|
||||
float pX = coordinateX + i * scaleWid;
|
||||
float dataHig = (axis.runtimeMaxValue - axis.runtimeMinValue) == 0 ? 0 :
|
||||
(value - axis.runtimeMinValue) / (axis.runtimeMaxValue - axis.runtimeMinValue) * hig;
|
||||
@@ -1074,6 +1083,10 @@ namespace XCharts
|
||||
}
|
||||
lp = np;
|
||||
}
|
||||
if (dataChanging)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
switch (m_DataZoom.rangeMode)
|
||||
{
|
||||
@@ -1373,7 +1386,7 @@ namespace XCharts
|
||||
if (j >= serie.dataPoints.Count) break;
|
||||
var serieData = serie.data[j];
|
||||
var pos = serie.dataPoints[j];
|
||||
|
||||
|
||||
serieData.SetGameObjectPosition(serieData.labelPosition);
|
||||
serieData.UpdateIcon();
|
||||
if (serie.show && serie.label.show && serieData.canShowLabel)
|
||||
|
||||
@@ -123,6 +123,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
m_IsPlayingStartAnimation = true;
|
||||
}
|
||||
return currHig;
|
||||
}
|
||||
@@ -155,15 +156,16 @@ namespace XCharts
|
||||
}
|
||||
|
||||
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
|
||||
float updateDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
bool dataChanging = false;
|
||||
for (int i = serie.minShow; i < maxCount; i++)
|
||||
{
|
||||
if (i >= seriesHig.Count)
|
||||
{
|
||||
seriesHig.Add(0);
|
||||
}
|
||||
var serieData = showData[i];
|
||||
serieData.canShowLabel = true;
|
||||
float value = showData[i].data[1];
|
||||
float value = showData[i].GetCurrData(1, updateDuration);
|
||||
if (showData[i].IsDataChanged()) dataChanging = true;
|
||||
float pX = coordinateX + i * categoryWidth;
|
||||
float zeroY = coordinateY + yAxis.runtimeZeroYOffset;
|
||||
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
|
||||
@@ -213,6 +215,10 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dataChanging)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
|
||||
{
|
||||
m_BarLastOffset += barGapWidth;
|
||||
|
||||
@@ -183,6 +183,7 @@ namespace XCharts
|
||||
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
|
||||
float speed = xCount / duration;
|
||||
serie.animation.CheckProgress(Time.deltaTime * speed);
|
||||
m_IsPlayingStartAnimation = true;
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,8 @@ namespace XCharts
|
||||
var includeLastData = false;
|
||||
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||
var dataChanging = false;
|
||||
var updateDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
for (i = serie.minShow; i < maxCount; i += rate)
|
||||
{
|
||||
if (i == maxCount - 1) includeLastData = true;
|
||||
@@ -118,16 +120,23 @@ namespace XCharts
|
||||
{
|
||||
for (int j = 0; j < rate; j++) seriesHig.Add(0);
|
||||
}
|
||||
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i);
|
||||
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np);
|
||||
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage,
|
||||
i, updateDuration, ref dataChanging);
|
||||
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
|
||||
updateDuration);
|
||||
serie.dataPoints.Add(np);
|
||||
}
|
||||
if (dataChanging)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
if (!includeLastData)
|
||||
{
|
||||
i = maxCount - 1;
|
||||
seriesHig.Add(0);
|
||||
float yValue = showData[i].data[1];
|
||||
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np);
|
||||
float yValue = showData[i].GetCurrData(1, updateDuration);
|
||||
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
|
||||
updateDuration);
|
||||
serie.dataPoints.Add(np);
|
||||
}
|
||||
if (serie.dataPoints.Count <= 0)
|
||||
@@ -144,8 +153,8 @@ namespace XCharts
|
||||
if (serie.minShow > 0 && serie.minShow < showData.Count)
|
||||
{
|
||||
i = serie.minShow - 1;
|
||||
float yValue = showData[i].data[1];
|
||||
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos);
|
||||
float yValue = showData[i].GetCurrData(1, updateDuration);
|
||||
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos, updateDuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -154,14 +163,13 @@ namespace XCharts
|
||||
if (serie.maxShow > 0 && serie.maxShow < showData.Count)
|
||||
{
|
||||
i = serie.maxShow;
|
||||
float yValue = showData[i].data[1];
|
||||
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos);
|
||||
float yValue = showData[i].GetCurrData(1, updateDuration);
|
||||
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos, updateDuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
lastNextPos = serie.dataPoints[serie.dataPoints.Count - 1];
|
||||
}
|
||||
|
||||
for (i = 1; i < serie.dataPoints.Count; i++)
|
||||
{
|
||||
np = serie.dataPoints[i];
|
||||
@@ -216,6 +224,7 @@ namespace XCharts
|
||||
float symbolSpeed = serie.symbol.size / duration;
|
||||
serie.animation.CheckProgress(Time.deltaTime * speed);
|
||||
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
|
||||
m_IsPlayingStartAnimation = true;
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
@@ -236,9 +245,13 @@ namespace XCharts
|
||||
}
|
||||
|
||||
private float SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
|
||||
int minCount, int maxCount, float totalAverage, int index)
|
||||
int minCount, int maxCount, float totalAverage, int index, float updateDuration, ref bool dataChanging)
|
||||
{
|
||||
if (rate <= 1 || index == minCount) return showData[index].data[1];
|
||||
if (rate <= 1 || index == minCount)
|
||||
{
|
||||
if (showData[index].IsDataChanged()) dataChanging = true;
|
||||
return showData[index].GetCurrData(1, updateDuration);
|
||||
}
|
||||
switch (sampleType)
|
||||
{
|
||||
case SampleType.Sum:
|
||||
@@ -246,7 +259,8 @@ namespace XCharts
|
||||
float total = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
total += showData[i].data[1];
|
||||
total += showData[i].GetCurrData(1, updateDuration);
|
||||
if (showData[i].IsDataChanged()) dataChanging = true;
|
||||
}
|
||||
if (sampleType == SampleType.Average) return total / rate;
|
||||
else return total;
|
||||
@@ -254,16 +268,18 @@ namespace XCharts
|
||||
float max = float.MinValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].data[1];
|
||||
var value = showData[i].GetCurrData(1, updateDuration);
|
||||
if (value > max) max = value;
|
||||
if (showData[i].IsDataChanged()) dataChanging = true;
|
||||
}
|
||||
return max;
|
||||
case SampleType.Min:
|
||||
float min = float.MaxValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].data[1];
|
||||
var value = showData[i].GetCurrData(1, updateDuration);
|
||||
if (value < min) min = value;
|
||||
if (showData[i].IsDataChanged()) dataChanging = true;
|
||||
}
|
||||
return min;
|
||||
case SampleType.Peak:
|
||||
@@ -272,40 +288,45 @@ namespace XCharts
|
||||
total = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].data[1];
|
||||
var value = showData[i].GetCurrData(1, updateDuration);
|
||||
total += value;
|
||||
if (value < min) min = value;
|
||||
if (value > max) max = value;
|
||||
if (showData[i].IsDataChanged()) dataChanging = true;
|
||||
}
|
||||
var average = total / rate;
|
||||
if (average >= totalAverage) return max;
|
||||
else return min;
|
||||
|
||||
}
|
||||
return showData[index].data[1];
|
||||
if (showData[index].IsDataChanged()) dataChanging = true;
|
||||
return showData[index].GetCurrData(1, updateDuration);
|
||||
}
|
||||
|
||||
private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i,
|
||||
float scaleWid, float serieHig, ref Vector3 np)
|
||||
float scaleWid, float serieHig, ref Vector3 np, float duration)
|
||||
{
|
||||
float xDataHig, yDataHig;
|
||||
float xMinValue = xAxis.GetCurrMinValue(duration);
|
||||
float xMaxValue = xAxis.GetCurrMaxValue(duration);
|
||||
float yMinValue = yAxis.GetCurrMinValue(duration);
|
||||
float yMaxValue = yAxis.GetCurrMaxValue(duration);
|
||||
if (xAxis.IsValue())
|
||||
{
|
||||
float xValue = i > showData.Count - 1 ? 0 : showData[i].data[0];
|
||||
float pX = coordinateX + xAxis.axisLine.width;
|
||||
float pY = serieHig + coordinateY + xAxis.axisLine.width;
|
||||
if ((xAxis.runtimeMaxValue - xAxis.runtimeMinValue) <= 0) xDataHig = 0;
|
||||
else xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
|
||||
if ((yAxis.runtimeMaxValue - yAxis.runtimeMinValue) <= 0) yDataHig = 0;
|
||||
else yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
|
||||
if ((xMaxValue - xMinValue) <= 0) xDataHig = 0;
|
||||
else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
|
||||
if ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
|
||||
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
|
||||
np = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
}
|
||||
else
|
||||
{
|
||||
float pX = startX + i * scaleWid;
|
||||
float pY = serieHig + coordinateY + yAxis.axisLine.width;
|
||||
if ((yAxis.runtimeMaxValue - yAxis.runtimeMinValue) <= 0) yDataHig = 0;
|
||||
else yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
|
||||
if ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
|
||||
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
|
||||
np = new Vector3(pX, pY + yDataHig);
|
||||
}
|
||||
return yDataHig;
|
||||
@@ -442,6 +463,7 @@ namespace XCharts
|
||||
float symbolSpeed = serie.symbol.size / duration;
|
||||
serie.animation.CheckProgress(Time.deltaTime * speed);
|
||||
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
|
||||
m_IsPlayingStartAnimation = true;
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace XCharts
|
||||
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
|
||||
float speed = 1 / duration;
|
||||
serie.animation.CheckProgress(Time.deltaTime * speed);
|
||||
m_IsPlayingStartAnimation = true;
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
96
Runtime/Internal/LabelObject.cs
Normal file
96
Runtime/Internal/LabelObject.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class LabelObject
|
||||
{
|
||||
private GameObject m_GameObject;
|
||||
private bool m_LabelAutoSize = true;
|
||||
private float m_LabelPaddingLeftRight = 3f;
|
||||
private float m_LabelPaddingTopBottom = 3f;
|
||||
private Text m_LabelText;
|
||||
private RectTransform m_LabelRect;
|
||||
private Image m_IconImage;
|
||||
private RectTransform m_IconRect;
|
||||
|
||||
public Image icon { get { return m_IconImage; } }
|
||||
public Text label { get { return m_LabelText; } }
|
||||
|
||||
public LabelObject()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
||||
{
|
||||
m_GameObject = labelObj;
|
||||
m_LabelAutoSize = autoSize;
|
||||
m_LabelPaddingLeftRight = paddingLeftRight;
|
||||
m_LabelPaddingTopBottom = paddingTopBottom;
|
||||
m_LabelText = labelObj.GetComponentInChildren<Text>();
|
||||
m_LabelRect = m_LabelText.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void SetIcon(Image image)
|
||||
{
|
||||
m_IconImage = image;
|
||||
if (image != null)
|
||||
{
|
||||
m_IconRect = m_IconImage.GetComponent<RectTransform>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIconSprite(Sprite sprite)
|
||||
{
|
||||
if (m_IconImage != null) m_IconImage.sprite = sprite;
|
||||
}
|
||||
|
||||
public void SetIconSize(float width, float height)
|
||||
{
|
||||
if (m_LabelRect != null) m_LabelRect.sizeDelta = new Vector3(width, height);
|
||||
}
|
||||
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage, flag);
|
||||
}
|
||||
|
||||
public void SetPosition(Vector3 position)
|
||||
{
|
||||
if (m_GameObject != null)
|
||||
{
|
||||
m_GameObject.transform.localPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
ChartHelper.SetActive(m_GameObject, flag);
|
||||
}
|
||||
|
||||
public bool SetText(string text)
|
||||
{
|
||||
if (m_LabelText && !m_LabelText.text.Equals(text))
|
||||
{
|
||||
m_LabelText.text = text;
|
||||
if (m_LabelAutoSize)
|
||||
{
|
||||
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
|
||||
new Vector2(m_LabelText.preferredWidth + m_LabelPaddingLeftRight * 2,
|
||||
m_LabelText.preferredHeight + m_LabelPaddingTopBottom * 2);
|
||||
var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y;
|
||||
if (sizeChange) m_LabelRect.sizeDelta = newSize;
|
||||
return sizeChange;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/LabelObject.cs.meta
Normal file
11
Runtime/Internal/LabelObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4e7ef04b9a0e4526b49bf63967cfef4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,7 +15,7 @@ namespace XCharts
|
||||
{
|
||||
private static readonly Stack<GameObject> m_Stack = new Stack<GameObject>(200);
|
||||
|
||||
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, SerieData serieData)
|
||||
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, float iconWidth, float iconHeight)
|
||||
{
|
||||
GameObject element;
|
||||
if (m_Stack.Count == 0 || !Application.isPlaying)
|
||||
@@ -23,7 +23,7 @@ namespace XCharts
|
||||
element = ChartHelper.AddSerieLabel(name, parent, font,
|
||||
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
|
||||
label.backgroundWidth, label.backgroundHeight);
|
||||
ChartHelper.AddIcon("Icon", element.transform, serieData.iconStyle.width, serieData.iconStyle.height);
|
||||
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -34,7 +34,7 @@ namespace XCharts
|
||||
var text = element.GetComponentInChildren<Text>();
|
||||
text.color = color;
|
||||
text.font = font;
|
||||
text.fontSize =label.fontSize;
|
||||
text.fontSize = label.fontSize;
|
||||
text.fontStyle = label.fontStyle;
|
||||
ChartHelper.SetActive(element, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user