增加EffectScatter类型的散点图

This commit is contained in:
monitor1394
2019-07-22 19:02:28 +08:00
parent 34e7a5a913
commit 74e045686a
4 changed files with 71 additions and 6 deletions

View File

@@ -176,7 +176,8 @@ namespace XCharts
{
var xdata = serie.xData[n];
var ydata = serie.yData[n];
var symbolSize = serie.symbol.GetSize(serie.data[n].data);
var serieData = serie.GetSerieData(n);
var symbolSize = serie.symbol.GetSize(serieData == null?null:serieData.data);
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
{

View File

@@ -82,8 +82,13 @@ namespace XCharts
public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } set { m_SizeCallback = value; } }
public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } set { m_SelectedSizeCallback = value; } }
private List<float> m_AnimationSize = new List<float>(){0,5,10};
public List<float> animationSize { get{return m_AnimationSize;}}
public Color animationColor { get; set; }
public float GetSize(List<float> data)
{
if(data == null) return size;
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
@@ -106,6 +111,7 @@ namespace XCharts
public float GetSelectedSize(List<float> data)
{
if(data == null) return selectedSize;
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
@@ -305,6 +311,15 @@ namespace XCharts
return 0;
}
public SerieData GetSerieData(int index,DataZoom dataZoom = null){
var data = GetDataList(dataZoom);
if (index >= 0 && index <= data.Count - 1)
{
return data[index];
}
return null;
}
public void GetXYData(int index, DataZoom dataZoom, out float xValue, out float yVlaue)
{
xValue = 0;
@@ -372,6 +387,8 @@ namespace XCharts
}
}
public void UpdateFilterData(DataZoom dataZoom)
{
if (dataZoom != null && dataZoom.show)

View File

@@ -14,6 +14,10 @@ namespace XCharts
public Scatter scatter { get { return m_Scatter; } }
private float m_EffectScatterSpeed = 15;
private float m_EffectScatterSize;
private float m_EffectScatterAplha;
#if UNITY_EDITOR
protected override void Reset()
{
@@ -34,6 +38,31 @@ namespace XCharts
}
#endif
protected override void Update()
{
base.Update();
bool hasEffectScatter = false;
foreach (var serie in m_Series.series)
{
if (serie.type == SerieType.EffectScatter)
{
hasEffectScatter = true;
for (int i = 0; i < serie.symbol.animationSize.Count; ++i)
{
serie.symbol.animationSize[i] += m_EffectScatterSpeed * Time.deltaTime;
if (serie.symbol.animationSize[i] > serie.symbol.size)
{
serie.symbol.animationSize[i] = i*5;
}
}
}
}
if (hasEffectScatter)
{
RefreshChart();
}
}
protected override void DrawChart(VertexHelper vh)
{
base.DrawChart(vh);
@@ -55,6 +84,8 @@ namespace XCharts
{
continue;
}
var color = m_ThemeInfo.GetColor(serieNameCount);
color.a = 200;
int maxCount = maxShowDataNumber > 0 ?
(maxShowDataNumber > serie.dataCount ? serie.dataCount : maxShowDataNumber)
: serie.dataCount;
@@ -68,8 +99,7 @@ namespace XCharts
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 color = m_ThemeInfo.GetColor(serieNameCount);
color.a = 200;
var datas = serie.data[n].data;
float symbolSize = 0;
if (serie.selected && n == m_Tooltip.dataIndex[serie.axisIndex])
@@ -81,7 +111,20 @@ namespace XCharts
symbolSize = serie.symbol.GetSize(datas);
}
if (symbolSize > 100) symbolSize = 100;
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
if (serie.type == SerieType.EffectScatter)
{
for (int count = 0; count < serie.symbol.animationSize.Count; count++)
{
var nowSize = serie.symbol.animationSize[count];
color.a = (byte)(255 * (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)
{