mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 06:20:15 +00:00
增加ScatterChart同时对Scatter和Line的支持,实现折线图和散点图的组合图
This commit is contained in:
@@ -61,8 +61,8 @@ namespace XCharts
|
||||
else DrawXLineSerie(vh, j, serie, ref m_SeriesCurrHig);
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
if (yCategory) DrawYBarSerie(vh, j, seriesCount, serie, serieNameCount, ref m_SeriesCurrHig);
|
||||
else DrawXBarSerie(vh, j, seriesCount, serie, serieNameCount, ref m_SeriesCurrHig);
|
||||
if (yCategory) DrawYBarSerie(vh, j, serie, serieNameCount, ref m_SeriesCurrHig);
|
||||
else DrawXBarSerie(vh, j, serie, serieNameCount, ref m_SeriesCurrHig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,9 +568,10 @@ namespace XCharts
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
public void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
public void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom, axisIndex, false, out minVaule, out maxValue);
|
||||
GetMinMaxValue(dataZoom, axisIndex, isValueAxis, false, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -580,47 +581,20 @@ namespace XCharts
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
public void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
public void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom, axisIndex, true, out minVaule, out maxValue);
|
||||
GetMinMaxValue(dataZoom, axisIndex, isValueAxis, true, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
private Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
|
||||
public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool yValue, out int minVaule, out int maxValue)
|
||||
public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool yValue,
|
||||
out int minVaule, out int maxValue)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
float max = int.MinValue;
|
||||
if (IsStack())
|
||||
{
|
||||
GetStackSeries(ref _stackSeriesForMinMax);
|
||||
foreach (var ss in _stackSeriesForMinMax)
|
||||
{
|
||||
_serieTotalValueForMinMax.Clear();
|
||||
for (int i = 0; i < ss.Value.Count; i++)
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if (serie.axisIndex != axisIndex || !IsActive(i)) continue;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + (yValue ? showData[j].data[1] : showData[i].data[0]);
|
||||
}
|
||||
}
|
||||
float tmax = int.MinValue;
|
||||
float tmin = int.MaxValue;
|
||||
foreach (var tt in _serieTotalValueForMinMax)
|
||||
{
|
||||
if (tt.Value > tmax) tmax = tt.Value;
|
||||
if (tt.Value < tmin) tmin = tt.Value;
|
||||
}
|
||||
if (tmax > max) max = tmax;
|
||||
if (tmin < min) min = tmin;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!IsStack() || (isValueAxis && !yValue))
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
@@ -645,6 +619,36 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetStackSeries(ref _stackSeriesForMinMax);
|
||||
foreach (var ss in _stackSeriesForMinMax)
|
||||
{
|
||||
_serieTotalValueForMinMax.Clear();
|
||||
for (int i = 0; i < ss.Value.Count; i++)
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if (serie.axisIndex != axisIndex || !IsActive(i)) continue;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] +
|
||||
(yValue ? showData[j].data[1] : showData[i].data[0]);
|
||||
}
|
||||
}
|
||||
float tmax = int.MinValue;
|
||||
float tmin = int.MaxValue;
|
||||
foreach (var tt in _serieTotalValueForMinMax)
|
||||
{
|
||||
if (tt.Value > tmax) tmax = tt.Value;
|
||||
if (tt.Value < tmin) tmin = tt.Value;
|
||||
}
|
||||
if (tmax > max) max = tmax;
|
||||
if (tmin < min) min = tmin;
|
||||
}
|
||||
}
|
||||
if (max == int.MinValue && min == int.MaxValue)
|
||||
{
|
||||
minVaule = 0;
|
||||
|
||||
@@ -668,20 +668,20 @@ namespace XCharts
|
||||
if (axis.IsCategory() || !axis.show) return;
|
||||
int tempMinValue = 0;
|
||||
int tempMaxValue = 0;
|
||||
if (m_XAxises[axisIndex].IsValue() && m_YAxises[axisIndex].IsValue())
|
||||
if (IsValue())
|
||||
{
|
||||
if (axis is XAxis)
|
||||
{
|
||||
m_Series.GetXMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
m_Series.GetXMinMaxValue(m_DataZoom, axisIndex, true, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, true, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, false, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue);
|
||||
if (tempMinValue != axis.minValue || tempMaxValue != axis.maxValue)
|
||||
@@ -921,7 +921,7 @@ namespace XCharts
|
||||
Vector3 np = Vector3.zero;
|
||||
int minValue = 0;
|
||||
int maxValue = 100;
|
||||
m_Series.GetYMinMaxValue(null, 0, out minValue, out maxValue);
|
||||
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++)
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace XCharts
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
protected float m_BarLastOffset = 0;
|
||||
|
||||
protected void DrawYBarSerie(VertexHelper vh, int serieIndex, int stackCount,
|
||||
Serie serie, int colorIndex, ref List<float> seriesHig)
|
||||
|
||||
protected void DrawYBarSerie(VertexHelper vh, int serieIndex, Serie serie, int colorIndex,
|
||||
ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
@@ -95,8 +95,8 @@ namespace XCharts
|
||||
return currHig;
|
||||
}
|
||||
|
||||
protected void DrawXBarSerie(VertexHelper vh, int serieIndex, int stackCount,
|
||||
Serie serie, int colorIndex, ref List<float> seriesHig)
|
||||
protected void DrawXBarSerie(VertexHelper vh, int serieIndex, Serie serie, int colorIndex,
|
||||
ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
|
||||
58
Scripts/UI/Internal/CoordinateChart_DrawScatter.cs
Normal file
58
Scripts/UI/Internal/CoordinateChart_DrawScatter.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
protected void DrawScatterSerie(VertexHelper vh,int colorIndex, Serie serie)
|
||||
{
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex);
|
||||
color.a *= serie.symbol.opacity;
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
|
||||
: serie.dataCount;
|
||||
for (int n = serie.minShow; n < maxCount; n++)
|
||||
{
|
||||
var serieData = serie.GetDataList(m_DataZoom)[n];
|
||||
float xValue = serieData.data[0];
|
||||
float yValue = serieData.data[1];
|
||||
float pX = coordinateX + xAxis.axisLine.width;
|
||||
float pY = coordinateY + yAxis.axisLine.width;
|
||||
float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
float yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
|
||||
var datas = serie.data[n].data;
|
||||
float symbolSize = 0;
|
||||
if (serie.highlighted || serieData.highlighted)
|
||||
{
|
||||
symbolSize = serie.symbol.GetSelectedSize(datas);
|
||||
}
|
||||
else
|
||||
{
|
||||
symbolSize = serie.symbol.GetSize(datas);
|
||||
}
|
||||
if (symbolSize > 100) symbolSize = 100;
|
||||
if (serie.type == SerieType.EffectScatter)
|
||||
{
|
||||
for (int count = 0; count < serie.symbol.animationSize.Count; count++)
|
||||
{
|
||||
var nowSize = serie.symbol.animationSize[count];
|
||||
color.a = (symbolSize - nowSize) / symbolSize;
|
||||
DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color);
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Internal/CoordinateChart_DrawScatter.cs.meta
Normal file
11
Scripts/UI/Internal/CoordinateChart_DrawScatter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f06734940c9e4f92897bb83573394a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -72,8 +72,8 @@ namespace XCharts
|
||||
else DrawXLineSerie(vh, serieCount, serie, ref m_SeriesCurrHig);
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
if (yCategory) DrawYBarSerie(vh, serieCount, seriesCount, serie, serieCount, ref m_SeriesCurrHig);
|
||||
else DrawXBarSerie(vh, serieCount, seriesCount, serie, serieCount, ref m_SeriesCurrHig);
|
||||
if (yCategory) DrawYBarSerie(vh, serieCount, serie, serieCount, ref m_SeriesCurrHig);
|
||||
else DrawXBarSerie(vh, serieCount, serie, serieCount, ref m_SeriesCurrHig);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,77 +58,56 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
protected HashSet<string> m_SerieNameSet = new HashSet<string>();
|
||||
protected Dictionary<int, List<Serie>> m_StackSeries = new Dictionary<int, List<Serie>>();
|
||||
protected List<float> m_SeriesCurrHig = new List<float>();
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
if (!m_CheckMinMaxValue) return;
|
||||
HashSet<string> serieNameSet = new HashSet<string>();
|
||||
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
|
||||
m_Series.GetStackSeries(ref m_StackSeries);
|
||||
int seriesCount = m_StackSeries.Count;
|
||||
int serieNameCount = -1;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
m_SerieNameSet.Clear();
|
||||
m_BarLastOffset = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
serie.index = i;
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
||||
else if (!serieNameSet.Contains(serie.name))
|
||||
var serieList = m_StackSeries[j];
|
||||
m_SeriesCurrHig.Clear();
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
serieNameSet.Add(serie.name);
|
||||
serieNameCount++;
|
||||
}
|
||||
if (serie.dataCount <= 0 || !serie.show)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(serieNameCount);
|
||||
color.a *= serie.symbol.opacity;
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
|
||||
: serie.dataCount;
|
||||
for (int n = serie.minShow; n < maxCount; n++)
|
||||
{
|
||||
var serieData = serie.GetDataList(m_DataZoom)[n];
|
||||
float xValue = serieData.data[0];
|
||||
float yValue = serieData.data[1];
|
||||
float pX = coordinateX + xAxis.axisLine.width;
|
||||
float pY = coordinateY + yAxis.axisLine.width;
|
||||
float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
float yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
|
||||
var datas = serie.data[n].data;
|
||||
float symbolSize = 0;
|
||||
if (serie.highlighted || serieData.highlighted)
|
||||
Serie serie = serieList[n];
|
||||
serie.dataPoints.Clear();
|
||||
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
||||
else if (!m_SerieNameSet.Contains(serie.name))
|
||||
{
|
||||
symbolSize = serie.symbol.GetSelectedSize(datas);
|
||||
m_SerieNameSet.Add(serie.name);
|
||||
serieNameCount++;
|
||||
}
|
||||
else
|
||||
switch (serie.type)
|
||||
{
|
||||
symbolSize = serie.symbol.GetSize(datas);
|
||||
case SerieType.Line:
|
||||
if (yCategory) DrawYLineSerie(vh, j, serie, ref m_SeriesCurrHig);
|
||||
else DrawXLineSerie(vh, j, serie, ref m_SeriesCurrHig);
|
||||
break;
|
||||
case SerieType.Scatter:
|
||||
case SerieType.EffectScatter:
|
||||
DrawScatterSerie(vh, serieNameCount, serie);
|
||||
if (vh.currentVertCount > 60000)
|
||||
{
|
||||
m_Large++;
|
||||
RefreshChart();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (symbolSize > 100) symbolSize = 100;
|
||||
if (serie.type == SerieType.EffectScatter)
|
||||
{
|
||||
for (int count = 0; count < serie.symbol.animationSize.Count; count++)
|
||||
{
|
||||
var nowSize = serie.symbol.animationSize[count];
|
||||
color.a = (symbolSize - nowSize) / symbolSize;
|
||||
DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color);
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
|
||||
}
|
||||
}
|
||||
if (vh.currentVertCount > 60000)
|
||||
{
|
||||
m_Large++;
|
||||
RefreshChart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
DrawLinePoint(vh);
|
||||
DrawLineArrow(vh);
|
||||
if (yCategory) DrawYTooltipIndicator(vh);
|
||||
else DrawXTooltipIndicator(vh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user