Files
XCharts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs

114 lines
5.5 KiB
C#
Raw Normal View History

2021-01-11 08:54:28 +08:00
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
2019-10-14 07:45:56 +08:00
using UnityEngine;
using UnityEngine.UI;
2021-01-11 08:54:28 +08:00
using XUGL;
2019-10-14 07:45:56 +08:00
namespace XCharts
{
public partial class CoordinateChart
{
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
{
if (serie.animation.HasFadeOut()) return;
2021-01-11 08:54:28 +08:00
var yAxis = m_YAxes[serie.yAxisIndex];
var xAxis = m_XAxes[serie.xAxisIndex];
xAxis.boundaryGap = true;
yAxis.boundaryGap = true;
2021-01-11 08:54:28 +08:00
var grid = GetSerieGridOrDefault(serie);
2019-10-14 07:45:56 +08:00
var xCount = xAxis.data.Count;
var yCount = yAxis.data.Count;
2021-01-11 08:54:28 +08:00
var xWidth = grid.runtimeWidth / xCount;
var yWidth = grid.runtimeHeight / yCount;
2019-10-14 07:45:56 +08:00
2021-01-11 08:54:28 +08:00
var zeroX = grid.runtimeX;
var zeroY = grid.runtimeY;
2019-10-14 07:45:56 +08:00
var dataList = serie.GetDataList();
2021-01-11 08:54:28 +08:00
var rangeMin = visualMap.rangeMin;
var rangeMax = visualMap.rangeMax;
var color = m_Theme.GetColor(serie.index);
2019-10-14 07:45:56 +08:00
var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32;
borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
var borderToColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderToColor : ChartConst.clearColor32;
borderToColor.a = (byte)(borderToColor.a * serie.itemStyle.opacity);
2019-10-14 07:45:56 +08:00
serie.dataPoints.Clear();
serie.animation.InitProgress(1, 0, xCount);
var animationIndex = serie.animation.GetCurrIndex();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
2019-12-03 07:49:37 +08:00
var dataChanging = false;
2019-10-14 07:45:56 +08:00
for (int i = 0; i < xCount; i++)
{
for (int j = 0; j < yCount; j++)
{
var dataIndex = i * yCount + j;
if (dataIndex >= dataList.Count) continue;
var serieData = dataList[dataIndex];
2021-01-11 08:54:28 +08:00
var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
if (serie.IsIgnoreIndex(dataIndex, dimension))
{
serie.dataPoints.Add(Vector3.zero);
continue;
}
var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse,
yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
2019-12-03 07:49:37 +08:00
if (serieData.IsDataChanged()) dataChanging = true;
var pos = new Vector3(zeroX + (i + (xAxis.boundaryGap ? 0.5f : 0)) * xWidth,
zeroY + (j + (yAxis.boundaryGap ? 0.5f : 0)) * yWidth);
2019-10-14 07:45:56 +08:00
serie.dataPoints.Add(pos);
serieData.canShowLabel = false;
if (value == 0) continue;
2021-01-11 08:54:28 +08:00
if (visualMap.enable)
2019-10-14 07:45:56 +08:00
{
2021-01-11 08:54:28 +08:00
if ((value < rangeMin && rangeMin != visualMap.min)
|| (value > rangeMax && rangeMax != visualMap.max))
2019-10-14 07:45:56 +08:00
{
continue;
}
2021-01-11 08:54:28 +08:00
if (!visualMap.IsInSelectedValue(value)) continue;
color = visualMap.GetColor(value);
2019-10-14 07:45:56 +08:00
}
2019-12-03 07:49:37 +08:00
if (animationIndex >= 0 && i > animationIndex) continue;
2019-10-14 07:45:56 +08:00
serieData.canShowLabel = true;
var emphasis = (tooltip.show
&& i == (int)tooltip.runtimeXValues[0]
&& j == (int)tooltip.runtimeYValues[0])
2021-01-11 08:54:28 +08:00
|| visualMap.runtimeSelectedIndex > 0;
2019-10-14 07:45:56 +08:00
var rectWid = xWidth - 2 * borderWidth;
var rectHig = yWidth - 2 * borderWidth;
2021-01-11 08:54:28 +08:00
UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
2019-10-14 07:45:56 +08:00
{
UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor);
2019-10-14 07:45:56 +08:00
}
if (visualMap.hoverLink && emphasis && serie.emphasis.show
&& serie.emphasis.itemStyle.borderWidth > 0)
2019-10-14 07:45:56 +08:00
{
var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0
? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
var emphasisBorderToColor = serie.emphasis.itemStyle.opacity > 0
? serie.emphasis.itemStyle.borderToColor : ChartConst.clearColor32;
UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor,
emphasisBorderToColor);
2019-10-14 07:45:56 +08:00
}
}
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(xCount);
m_IsPlayingAnimation = true;
2021-01-11 08:54:28 +08:00
RefreshPainter(serie);
}
2019-12-03 07:49:37 +08:00
if (dataChanging)
{
2021-01-11 08:54:28 +08:00
RefreshPainter(serie);
2019-12-03 07:49:37 +08:00
}
2019-10-14 07:45:56 +08:00
}
}
}