mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 22:10:11 +00:00
增加HeatmapChart热力图
This commit is contained in:
@@ -16,6 +16,7 @@ namespace XCharts
|
||||
[SerializeField] protected List<XAxis> m_XAxises = new List<XAxis>();
|
||||
[SerializeField] protected List<YAxis> m_YAxises = new List<YAxis>();
|
||||
[SerializeField] protected DataZoom m_DataZoom = DataZoom.defaultDataZoom;
|
||||
[SerializeField] protected VisualMap m_VisualMap = new VisualMap();
|
||||
|
||||
private bool m_DataZoomDrag;
|
||||
private bool m_DataZoomCoordinateDrag;
|
||||
@@ -52,7 +53,9 @@ namespace XCharts
|
||||
CheckXAxis();
|
||||
CheckMinMaxValue();
|
||||
CheckCoordinate();
|
||||
CheckRaycastTarget();
|
||||
CheckDataZoom();
|
||||
CheckVisualMap();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@@ -72,6 +75,7 @@ namespace XCharts
|
||||
DrawCoordinate(vh);
|
||||
DrawSerie(vh);
|
||||
DrawDataZoomSlider(vh);
|
||||
DrawVisualMap(vh);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +116,9 @@ namespace XCharts
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SerieType.Heatmap:
|
||||
DrawHeatmapSerie(vh, colorIndex, serie);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,6 +177,33 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (IsCategory())
|
||||
{
|
||||
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float pX = coordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.xValues[i] = j;
|
||||
m_Tooltip.dataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float pY = coordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.yValues[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (xAxis.IsCategory())
|
||||
{
|
||||
var value = (yAxis.maxValue - yAxis.minValue) * (local.y - coordinateY - yAxis.zeroYOffset) / coordinateHig;
|
||||
@@ -225,7 +259,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private StringBuilder sb = new StringBuilder(100);
|
||||
protected StringBuilder sb = new StringBuilder(100);
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
@@ -320,7 +354,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAxisTooltipLabel(int axisIndex, Axis axis)
|
||||
protected void UpdateAxisTooltipLabel(int axisIndex, Axis axis)
|
||||
{
|
||||
var showTooltipLabel = axis.show && m_Tooltip.type == Tooltip.Type.Corss;
|
||||
axis.SetTooltipLabelActive(showTooltipLabel);
|
||||
@@ -611,7 +645,7 @@ namespace XCharts
|
||||
dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleLeft,
|
||||
Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20), m_DataZoom.fontSize, 0, m_DataZoom.fontStyle);
|
||||
m_DataZoom.SetLabelActive(false);
|
||||
raycastTarget = m_DataZoom.enable;
|
||||
CheckRaycastTarget();
|
||||
var xAxis = m_XAxises[m_DataZoom.xAxisIndex];
|
||||
if (xAxis != null)
|
||||
{
|
||||
@@ -705,6 +739,11 @@ namespace XCharts
|
||||
private void CheckMinMaxValue()
|
||||
{
|
||||
if (m_XAxises == null || m_YAxises == null) return;
|
||||
if (IsCategory())
|
||||
{
|
||||
m_CheckMinMaxValue = true;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
UpdateAxisMinMaxValue(i, m_XAxises[i]);
|
||||
@@ -1145,12 +1184,17 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckRaycastTarget()
|
||||
{
|
||||
var ray = m_DataZoom.enable || (m_VisualMap.enable && m_VisualMap.show && m_VisualMap.calculable);
|
||||
if (raycastTarget != ray)
|
||||
{
|
||||
raycastTarget = ray;
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckDataZoom()
|
||||
{
|
||||
if (raycastTarget != m_DataZoom.enable)
|
||||
{
|
||||
raycastTarget = m_DataZoom.enable;
|
||||
}
|
||||
if (!m_DataZoom.enable) return;
|
||||
CheckDataZoomScale();
|
||||
CheckDataZoomLabel();
|
||||
@@ -1314,11 +1358,18 @@ namespace XCharts
|
||||
var pos = serie.dataPoints[j];
|
||||
serieData.SetGameObjectPosition(serieData.labelPosition);
|
||||
serieData.UpdateIcon();
|
||||
if (serie.show && serie.label.show)
|
||||
if (serie.show && serie.label.show && serieData.canShowLabel)
|
||||
{
|
||||
var value = serieData.data[1];
|
||||
float value = 0f;
|
||||
var dimension = 1;
|
||||
if (serie.type == SerieType.Heatmap)
|
||||
{
|
||||
dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
|
||||
serieData.data.Count - 1;
|
||||
}
|
||||
value = serieData.data[dimension];
|
||||
var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.SetLabelActive(value != 0);
|
||||
serieData.SetLabelPosition(serie.label.offset);
|
||||
if (serieData.SetLabelText(content)) RefreshChart();
|
||||
}
|
||||
@@ -1343,7 +1394,6 @@ namespace XCharts
|
||||
{
|
||||
if (IsInCooridate(pos))
|
||||
{
|
||||
m_DataZoom.isDraging = true;
|
||||
m_DataZoomCoordinateDrag = true;
|
||||
}
|
||||
}
|
||||
@@ -1351,20 +1401,18 @@ namespace XCharts
|
||||
{
|
||||
if (m_DataZoom.IsInStartZoom(pos, coordinateX, coordinateWid))
|
||||
{
|
||||
m_DataZoom.isDraging = true;
|
||||
m_DataZoomStartDrag = true;
|
||||
}
|
||||
else if (m_DataZoom.IsInEndZoom(pos, coordinateX, coordinateWid))
|
||||
{
|
||||
m_DataZoom.isDraging = true;
|
||||
m_DataZoomEndDrag = true;
|
||||
}
|
||||
else if (m_DataZoom.IsInSelectedZoom(pos, coordinateX, coordinateWid))
|
||||
{
|
||||
m_DataZoom.isDraging = true;
|
||||
m_DataZoomDrag = true;
|
||||
}
|
||||
}
|
||||
OnDragVisualMapStart();
|
||||
}
|
||||
|
||||
public override void OnDrag(PointerEventData eventData)
|
||||
@@ -1374,6 +1422,7 @@ namespace XCharts
|
||||
float deltaPercent = deltaX / coordinateWid * 100;
|
||||
OnDragInside(deltaPercent);
|
||||
OnDragSlider(deltaPercent);
|
||||
OnDragVisualMap();
|
||||
}
|
||||
|
||||
private void OnDragInside(float deltaPercent)
|
||||
@@ -1471,7 +1520,7 @@ namespace XCharts
|
||||
m_DataZoomCoordinateDrag = false;
|
||||
m_DataZoomStartDrag = false;
|
||||
m_DataZoomEndDrag = false;
|
||||
m_DataZoom.isDraging = false;
|
||||
OnDragVisualMapEnd();
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
|
||||
@@ -49,8 +49,12 @@ namespace XCharts
|
||||
/// dataZoom component.
|
||||
/// 区域缩放组件。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public DataZoom dataZoom { get { return m_DataZoom; } }
|
||||
/// <summary>
|
||||
/// visualMap component.
|
||||
/// 视觉映射组件。
|
||||
/// </summary>
|
||||
public VisualMap visualMap { get { return m_VisualMap; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +133,15 @@ namespace XCharts
|
||||
|
||||
public bool IsCategory()
|
||||
{
|
||||
return !IsValue();
|
||||
foreach (var axis in m_XAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsCategory()) return false;
|
||||
}
|
||||
foreach (var axis in m_YAxises)
|
||||
{
|
||||
if (axis.show && !axis.IsCategory()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsInCooridate(Vector2 local)
|
||||
|
||||
374
Scripts/UI/Internal/CoordinateChart_DrawHeatmap.cs
Normal file
374
Scripts/UI/Internal/CoordinateChart_DrawHeatmap.cs
Normal file
@@ -0,0 +1,374 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
private bool m_VisualMapMinDrag;
|
||||
private bool m_VisualMapMaxDrag;
|
||||
|
||||
protected void CheckVisualMap()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show) return;
|
||||
Vector2 local;
|
||||
if (canvas == null) return;
|
||||
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, canvas.worldCamera, out local))
|
||||
{
|
||||
if (m_VisualMap.rtSelectedIndex >= 0)
|
||||
{
|
||||
m_VisualMap.rtSelectedIndex = -1;
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (local.x < 0 || local.x > chartWidth ||
|
||||
local.y < 0 || local.y > chartHeight ||
|
||||
!m_VisualMap.IsInRangeRect(local, chartWidth, chartHeight))
|
||||
{
|
||||
if (m_VisualMap.rtSelectedIndex >= 0)
|
||||
{
|
||||
m_VisualMap.rtSelectedIndex = -1;
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
var pos1 = Vector3.zero;
|
||||
var pos2 = Vector3.zero;
|
||||
var halfWid = m_VisualMap.itemWidth / 2;
|
||||
var halfHig = m_VisualMap.itemHeight / 2;
|
||||
var centerPos = m_VisualMap.location.GetPosition(chartWidth, chartHeight);
|
||||
var selectedIndex = -1;
|
||||
var value = 0f;
|
||||
switch (m_VisualMap.orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
pos1 = centerPos + Vector3.left * halfHig;
|
||||
pos2 = centerPos + Vector3.right * halfHig;
|
||||
value = m_VisualMap.min + (local.x - pos1.x) / (pos2.x - pos1.x) * (m_VisualMap.max - m_VisualMap.min);
|
||||
selectedIndex = m_VisualMap.GetIndex(value);
|
||||
break;
|
||||
case Orient.Vertical:
|
||||
pos1 = centerPos + Vector3.down * halfHig;
|
||||
pos2 = centerPos + Vector3.up * halfHig;
|
||||
value = m_VisualMap.min + (local.y - pos1.y) / (pos2.y - pos1.y) * (m_VisualMap.max - m_VisualMap.min);
|
||||
selectedIndex = m_VisualMap.GetIndex(value);
|
||||
break;
|
||||
}
|
||||
m_VisualMap.rtSelectedValue = value;
|
||||
m_VisualMap.rtSelectedIndex = selectedIndex;
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected void OnDragVisualMapStart()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
|
||||
var inMinRect = m_VisualMap.IsInRangeMinRect(pointerPos, chartWidth, chartHeight, m_Settings.visualMapTriangeLen);
|
||||
var inMaxRect = m_VisualMap.IsInRangeMaxRect(pointerPos, chartWidth, chartHeight, m_Settings.visualMapTriangeLen);
|
||||
if (inMinRect || inMaxRect)
|
||||
{
|
||||
if (inMinRect)
|
||||
{
|
||||
m_VisualMapMinDrag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VisualMapMaxDrag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnDragVisualMap()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
|
||||
if (!m_VisualMapMinDrag && !m_VisualMapMaxDrag) return;
|
||||
|
||||
var centerPos = m_VisualMap.location.GetPosition(chartWidth, chartHeight);
|
||||
var isVertical = m_VisualMap.isVertical;
|
||||
var pos1 = centerPos + (isVertical ? Vector3.down : Vector3.left) * m_VisualMap.itemHeight / 2;
|
||||
var pos2 = centerPos + (isVertical ? Vector3.up : Vector3.right) * m_VisualMap.itemHeight / 2;
|
||||
var value = m_VisualMap.GetValue(pointerPos, chartWidth, chartHeight);
|
||||
if (m_VisualMapMinDrag)
|
||||
{
|
||||
m_VisualMap.rangeMin = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VisualMap.rangeMax = value;
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected void OnDragVisualMapEnd()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
|
||||
if (m_VisualMapMinDrag || m_VisualMapMaxDrag)
|
||||
{
|
||||
RefreshChart();
|
||||
m_VisualMapMinDrag = false;
|
||||
m_VisualMapMaxDrag = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
|
||||
{
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var xCount = xAxis.data.Count;
|
||||
var yCount = yAxis.data.Count;
|
||||
var xWidth = coordinateWid / xCount;
|
||||
var yWidth = coordinateHig / yCount;
|
||||
|
||||
var zeroX = coordinateX;
|
||||
var zeroY = coordinateY;
|
||||
var dataList = serie.GetDataList();
|
||||
var rangeMin = m_VisualMap.rangeMin;
|
||||
var rangeMax = m_VisualMap.rangeMax;
|
||||
var color = m_ThemeInfo.GetColor(serie.index);
|
||||
var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
|
||||
var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : Color.clear;
|
||||
borderColor.a *= serie.itemStyle.opacity;
|
||||
serie.dataPoints.Clear();
|
||||
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];
|
||||
var dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
|
||||
serieData.data.Count - 1;
|
||||
var value = serieData.data[dimension];
|
||||
var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
|
||||
serie.dataPoints.Add(pos);
|
||||
serieData.canShowLabel = false;
|
||||
if (value == 0) continue;
|
||||
if (m_VisualMap.enable)
|
||||
{
|
||||
if ((value < rangeMin && rangeMin != m_VisualMap.min)
|
||||
|| (value > rangeMax && rangeMax != m_VisualMap.max))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!m_VisualMap.IsInSelectedValue(value)) continue;
|
||||
color = m_VisualMap.GetColor(value);
|
||||
}
|
||||
serieData.canShowLabel = true;
|
||||
var emphasis = (m_Tooltip.show && i == (int)m_Tooltip.xValues[0] && j == (int)m_Tooltip.yValues[0])
|
||||
|| m_VisualMap.rtSelectedIndex > 0;
|
||||
var rectWid = xWidth - 2 * borderWidth;
|
||||
var rectHig = yWidth - 2 * borderWidth;
|
||||
ChartDrawer.DrawPolygon(vh, pos, rectWid / 2, rectHig / 2, color);
|
||||
if (borderWidth > 0 && borderColor != Color.clear)
|
||||
{
|
||||
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
|
||||
}
|
||||
if (m_VisualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
|
||||
{
|
||||
var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
|
||||
var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : Color.clear;
|
||||
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawVisualMap(VertexHelper vh)
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show) return;
|
||||
var centerPos = m_VisualMap.location.GetPosition(chartWidth, chartHeight);
|
||||
|
||||
var pos1 = Vector3.zero;
|
||||
var pos2 = Vector3.zero;
|
||||
var dir = Vector3.zero;
|
||||
var halfWid = m_VisualMap.itemWidth / 2;
|
||||
var halfHig = m_VisualMap.itemHeight / 2;
|
||||
var xRadius = 0f;
|
||||
var yRadius = 0f;
|
||||
var splitNum = m_VisualMap.rtInRange.Count;
|
||||
var splitWid = m_VisualMap.itemHeight / (splitNum - 1);
|
||||
var isVertical = false;
|
||||
var colors = m_VisualMap.rtInRange;
|
||||
var triangeLen = m_Settings.visualMapTriangeLen;
|
||||
switch (m_VisualMap.orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
pos1 = centerPos + Vector3.left * halfHig;
|
||||
pos2 = centerPos + Vector3.right * halfHig;
|
||||
dir = Vector3.right;
|
||||
xRadius = splitWid / 2;
|
||||
yRadius = halfWid;
|
||||
isVertical = false;
|
||||
if (m_VisualMap.calculable)
|
||||
{
|
||||
var p0 = pos1 + Vector3.right * m_VisualMap.rangeMinHeight;
|
||||
var p1 = p0 + Vector3.up * halfWid;
|
||||
var p2 = p0 + Vector3.up * (halfWid + triangeLen);
|
||||
var p3 = p2 + Vector3.left * triangeLen;
|
||||
var color = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
p0 = pos1 + Vector3.right * m_VisualMap.rangeMaxHeight;
|
||||
p1 = p0 + Vector3.up * halfWid;
|
||||
p2 = p0 + Vector3.up * (halfWid + triangeLen);
|
||||
p3 = p2 + Vector3.right * triangeLen;
|
||||
color = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
}
|
||||
break;
|
||||
case Orient.Vertical:
|
||||
pos1 = centerPos + Vector3.down * halfHig;
|
||||
pos2 = centerPos + Vector3.up * halfHig;
|
||||
dir = Vector3.up;
|
||||
xRadius = halfWid;
|
||||
yRadius = splitWid / 2;
|
||||
isVertical = true;
|
||||
if (m_VisualMap.calculable)
|
||||
{
|
||||
var p0 = pos1 + Vector3.up * m_VisualMap.rangeMinHeight;
|
||||
var p1 = p0 + Vector3.right * halfWid;
|
||||
var p2 = p0 + Vector3.right * (halfWid + triangeLen);
|
||||
var p3 = p2 + Vector3.down * triangeLen;
|
||||
var color = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
p0 = pos1 + Vector3.up * m_VisualMap.rangeMaxHeight;
|
||||
p1 = p0 + Vector3.right * halfWid;
|
||||
p2 = p0 + Vector3.right * (halfWid + triangeLen);
|
||||
p3 = p2 + Vector3.up * triangeLen;
|
||||
color = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (m_VisualMap.calculable && (m_VisualMap.rangeMin > m_VisualMap.min
|
||||
|| m_VisualMap.rangeMax < m_VisualMap.max))
|
||||
{
|
||||
var rangeMin = m_VisualMap.rangeMin;
|
||||
var rangeMax = m_VisualMap.rangeMax;
|
||||
var diff = (m_VisualMap.max - m_VisualMap.min) / (splitNum - 1);
|
||||
for (int i = 1; i < splitNum; i++)
|
||||
{
|
||||
var splitMin = m_VisualMap.min + (i - 1) * diff;
|
||||
var splitMax = splitMin + diff;
|
||||
if (rangeMin > splitMax || rangeMax < splitMin)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (rangeMin <= splitMin && rangeMax >= splitMax)
|
||||
{
|
||||
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
|
||||
var startColor = colors[i - 1];
|
||||
var toColor = colors[i];
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
else if (rangeMin > splitMin && rangeMax >= splitMax)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
var splitMaxPos = pos1 + dir * i * splitWid;
|
||||
var splitPos = p0 + (splitMaxPos - p0) / 2;
|
||||
var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
var toColor = colors[i];
|
||||
var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2;
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
|
||||
else
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
else if (rangeMax < splitMax && rangeMin <= splitMin)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
var splitMinPos = pos1 + dir * (i - 1) * splitWid;
|
||||
var splitPos = splitMinPos + (p0 - splitMinPos) / 2;
|
||||
var startColor = colors[i - 1];
|
||||
var toColor = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2;
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
|
||||
else
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
else
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
var splitPos = (p0 + p1) / 2;
|
||||
var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
var toColor = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
var yRadius1 = Vector3.Distance(p0, p1) / 2;
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
|
||||
else
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < splitNum; i++)
|
||||
{
|
||||
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
|
||||
var startColor = colors[i - 1];
|
||||
var toColor = colors[i];
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_VisualMap.rangeMin > m_VisualMap.min)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
ChartDrawer.DrawPolygon(vh, pos1, p0, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor);
|
||||
}
|
||||
if (m_VisualMap.rangeMax < m_VisualMap.max)
|
||||
{
|
||||
var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
ChartDrawer.DrawPolygon(vh, p1, pos2, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor);
|
||||
}
|
||||
|
||||
if (m_VisualMap.hoverLink)
|
||||
{
|
||||
if (m_VisualMap.rtSelectedIndex >= 0)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
{
|
||||
var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
|
||||
var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
|
||||
var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
|
||||
ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
|
||||
ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
}
|
||||
}
|
||||
else if (m_Tooltip.show && m_Tooltip.xValues[0] >= 0 && m_Tooltip.yValues[0] >= 0)
|
||||
{
|
||||
// var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
// var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
// if (m_VisualMap.orient == Orient.Vertical)
|
||||
// {
|
||||
// var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
|
||||
// var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
|
||||
// var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
|
||||
// ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
// var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
// var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
|
||||
// ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Internal/CoordinateChart_DrawHeatmap.cs.meta
Normal file
11
Scripts/UI/Internal/CoordinateChart_DrawHeatmap.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2713cb84109d8491aa61bf37d1fa850e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Scripts/UI/Internal/Emphasis.cs
Normal file
28
Scripts/UI/Internal/Emphasis.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 高亮的图形样式和文本标签样式。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class Emphasis
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
|
||||
/// <summary>
|
||||
/// 是否启用高亮样式。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// 图形文本标签。
|
||||
/// </summary>
|
||||
public SerieLabel label { get { return m_Label; } }
|
||||
/// <summary>
|
||||
/// 图形样式。
|
||||
/// </summary>
|
||||
public ItemStyle itemStyle { get { return m_ItemStyle; } }
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Internal/Emphasis.cs.meta
Normal file
11
Scripts/UI/Internal/Emphasis.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6306ce69fc614416b82469b327516a49
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
Scripts/UI/Internal/ItemStyle.cs
Normal file
62
Scripts/UI/Internal/ItemStyle.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 图形样式。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class ItemStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// 线的类型。
|
||||
/// </summary>
|
||||
public enum Type
|
||||
{
|
||||
/// <summary>
|
||||
/// 实线
|
||||
/// </summary>
|
||||
Solid,
|
||||
/// <summary>
|
||||
/// 虚线
|
||||
/// </summary>
|
||||
Dashed,
|
||||
/// <summary>
|
||||
/// 点线
|
||||
/// </summary>
|
||||
Dotted
|
||||
}
|
||||
[SerializeField] private bool m_Show = false;
|
||||
[SerializeField] private Color m_Color;
|
||||
[SerializeField] private Type m_BorderType = Type.Solid;
|
||||
[SerializeField] private float m_BorderWidth = 0;
|
||||
[SerializeField] private Color m_BorderColor;
|
||||
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// 数据项颜色。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
/// <summary>
|
||||
/// 边框的类型。
|
||||
/// </summary>
|
||||
public Type borderType { get { return m_BorderType; } set { m_BorderType = value; } }
|
||||
/// <summary>
|
||||
/// 边框的颜色。
|
||||
/// </summary>
|
||||
public Color borderColor { get { return m_BorderColor; } set { m_BorderColor = value; } }
|
||||
/// <summary>
|
||||
/// 边框宽。
|
||||
/// </summary>
|
||||
public float borderWidth { get { return m_BorderWidth; } set { m_BorderWidth = value; } }
|
||||
/// <summary>
|
||||
/// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
|
||||
/// </summary>
|
||||
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Internal/ItemStyle.cs.meta
Normal file
11
Scripts/UI/Internal/ItemStyle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a89f8d34b0da24de4b59b179b022e685
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -213,31 +213,31 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 返回在坐标系中的具体位置
|
||||
/// </summary>
|
||||
/// <param name="chartWidht"></param>
|
||||
/// <param name="chartWidth"></param>
|
||||
/// <param name="chartHeight"></param>
|
||||
/// <returns></returns>
|
||||
public Vector2 GetPosition(float chartWidht, float chartHeight)
|
||||
public Vector3 GetPosition(float chartWidth, float chartHeight)
|
||||
{
|
||||
switch (align)
|
||||
{
|
||||
case Align.BottomCenter:
|
||||
return new Vector2(chartWidht / 2, bottom);
|
||||
return new Vector3(chartWidth / 2, bottom);
|
||||
case Align.BottomLeft:
|
||||
return new Vector2(left, bottom);
|
||||
return new Vector3(left, bottom);
|
||||
case Align.BottomRight:
|
||||
return new Vector2(chartWidht - right, bottom);
|
||||
return new Vector3(chartWidth - right, bottom);
|
||||
case Align.Center:
|
||||
return new Vector2(chartWidht / 2, chartHeight / 2);
|
||||
return new Vector3(chartWidth / 2, chartHeight / 2);
|
||||
case Align.CenterLeft:
|
||||
return new Vector2(left, chartHeight / 2);
|
||||
return new Vector3(left, chartHeight / 2);
|
||||
case Align.CenterRight:
|
||||
return new Vector2(chartWidht - right, chartHeight / 2);
|
||||
return new Vector3(chartWidth - right, chartHeight / 2);
|
||||
case Align.TopCenter:
|
||||
return new Vector2(chartWidht / 2, chartHeight - top);
|
||||
return new Vector3(chartWidth / 2, chartHeight - top);
|
||||
case Align.TopLeft:
|
||||
return new Vector2(left, chartHeight - top);
|
||||
return new Vector3(left, chartHeight - top);
|
||||
case Align.TopRight:
|
||||
return new Vector2(chartWidht - right, chartHeight - top);
|
||||
return new Vector3(chartWidth - right, chartHeight - top);
|
||||
default:
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user