private void DrawVesselBackground(VertexHelper vh, Serie serie) { var vessel = chart.GetVessel(serie.vesselIndex); if (vessel != null) { if (vessel.backgroundColor.a != 0) { switch (vessel.shape) { case Vessel.Shape.Circle: var cenPos = vessel.runtimeCenterPos; var radius = vessel.runtimeRadius; UGL.DrawCricle(vh, cenPos, vessel.runtimeInnerRadius + vessel.gap, vessel.backgroundColor, chart.settings.cicleSmoothness); UGL.DrawDoughnut(vh, cenPos, vessel.runtimeInnerRadius, vessel.runtimeInnerRadius + vessel.gap, vessel.backgroundColor, Color.clear, chart.settings.cicleSmoothness); break; case Vessel.Shape.Rect: UGL.DrawRectangle(vh, vessel.runtimeCenterPos, vessel.runtimeWidth / 2, vessel.runtimeHeight / 2, vessel.backgroundColor); break; default: break; } } } }
private void DrawPiecewiseVisualMap(VertexHelper vh, VisualMap visualMap) { var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight); var pos1 = Vector3.zero; var pos2 = Vector3.zero; var dir = Vector3.zero; var halfWid = visualMap.itemWidth / 2; var halfHig = visualMap.itemHeight / 2; switch (visualMap.orient) { case Orient.Horizonal: for (int i = 0; i < visualMap.inRange.Count; i++) { var piece = visualMap.inRange[i]; } break; case Orient.Vertical: var each = visualMap.itemHeight + visualMap.itemGap; for (int i = 0; i < visualMap.inRange.Count; i++) { var piece = visualMap.inRange[i]; var pos = new Vector3(centerPos.x, centerPos.y - each * i); UGL.DrawRectangle(vh, pos, halfWid, halfHig, piece.color); } break; } }
private void DrawMarkArea(VertexHelper vh, MarkArea markArea) { if (!markArea.show) { return; } var serie = chart.GetSerie(markArea.serieIndex); if (serie == null || !serie.show || !markArea.show) { return; } UpdateRuntimeData(markArea); var colorIndex = chart.GetLegendRealShowNameIndex(serie.legendName); var serieColor = SerieHelper.GetLineColor(serie, null, chart.theme, colorIndex, false); var areaColor = markArea.itemStyle.GetColor(serieColor); UGL.DrawRectangle(vh, markArea.runtimeRect, areaColor, areaColor); }
private void DrawContinuousVisualMap(VertexHelper vh, VisualMap visualMap) { var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight); var pos1 = Vector3.zero; var pos2 = Vector3.zero; var dir = Vector3.zero; var halfWid = visualMap.itemWidth / 2; var halfHig = visualMap.itemHeight / 2; var xRadius = 0f; var yRadius = 0f; var splitNum = visualMap.inRange.Count; var splitWid = visualMap.itemHeight / (splitNum - 1); var isVertical = false; var colors = visualMap.inRange; var triangeLen = chart.theme.visualMap.triangeLen; switch (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 (visualMap.calculable) { var p0 = pos1 + Vector3.right * visualMap.runtimeRangeMinHeight; var p1 = p0 + Vector3.up * halfWid; var p2 = p0 + Vector3.up * (halfWid + triangeLen); var p3 = p2 + Vector3.left * triangeLen; var color = visualMap.GetColor(visualMap.rangeMin); UGL.DrawTriangle(vh, p1, p2, p3, color); p0 = pos1 + Vector3.right * visualMap.runtimeRangeMaxHeight; p1 = p0 + Vector3.up * halfWid; p2 = p0 + Vector3.up * (halfWid + triangeLen); p3 = p2 + Vector3.right * triangeLen; color = visualMap.GetColor(visualMap.rangeMax); UGL.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 (visualMap.calculable) { var p0 = pos1 + Vector3.up * visualMap.runtimeRangeMinHeight; var p1 = p0 + Vector3.right * halfWid; var p2 = p0 + Vector3.right * (halfWid + triangeLen); var p3 = p2 + Vector3.down * triangeLen; var color = visualMap.GetColor(visualMap.rangeMin); UGL.DrawTriangle(vh, p1, p2, p3, color); p0 = pos1 + Vector3.up * visualMap.runtimeRangeMaxHeight; p1 = p0 + Vector3.right * halfWid; p2 = p0 + Vector3.right * (halfWid + triangeLen); p3 = p2 + Vector3.up * triangeLen; color = visualMap.GetColor(visualMap.rangeMax); UGL.DrawTriangle(vh, p1, p2, p3, color); } break; } if (visualMap.calculable && (visualMap.rangeMin > visualMap.min || visualMap.rangeMax < visualMap.max)) { var rangeMin = visualMap.rangeMin; var rangeMax = visualMap.rangeMax; var diff = (visualMap.max - visualMap.min) / (splitNum - 1); for (int i = 1; i < splitNum; i++) { var splitMin = 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].color; var toColor = visualMap.IsPiecewise() ? startColor : colors[i].color; UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); } else if (rangeMin > splitMin && rangeMax >= splitMax) { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; var splitMaxPos = pos1 + dir * i * splitWid; var splitPos = p0 + (splitMaxPos - p0) / 2; var startColor = visualMap.GetColor(visualMap.rangeMin); var toColor = visualMap.IsPiecewise() ? startColor : colors[i].color; var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2; if (visualMap.orient == Orient.Vertical) { UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); } else { UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } } else if (rangeMax < splitMax && rangeMin <= splitMin) { var p0 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var splitMinPos = pos1 + dir * (i - 1) * splitWid; var splitPos = splitMinPos + (p0 - splitMinPos) / 2; var startColor = colors[i - 1].color; var toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(visualMap.rangeMax); var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2; if (visualMap.orient == Orient.Vertical) { UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); } else { UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } } else { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var splitPos = (p0 + p1) / 2; var startColor = visualMap.GetColor(visualMap.rangeMin); var toColor = visualMap.GetColor(visualMap.rangeMax); var yRadius1 = Vector3.Distance(p0, p1) / 2; if (visualMap.orient == Orient.Vertical) { UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); } else { UGL.DrawRectangle(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].color; var toColor = visualMap.IsPiecewise() ? startColor : colors[i].color; UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); } } if (visualMap.rangeMin > visualMap.min) { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; UGL.DrawRectangle(vh, pos1, p0, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor); } if (visualMap.rangeMax < visualMap.max) { var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; UGL.DrawRectangle(vh, p1, pos2, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor); } if (visualMap.hoverLink) { if (visualMap.context.pointerIndex >= 0) { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var pointerPos = chart.pointerPos; if (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); UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex].color); } 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); UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex].color); } } } }
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie) { if (serie.animation.HasFadeOut()) { return; } var yAxis = m_YAxes[serie.yAxisIndex]; var xAxis = m_XAxes[serie.xAxisIndex]; xAxis.boundaryGap = true; yAxis.boundaryGap = true; var grid = GetSerieGridOrDefault(serie); var xCount = xAxis.data.Count; var yCount = yAxis.data.Count; var xWidth = grid.runtimeWidth / xCount; var yWidth = grid.runtimeHeight / yCount; var zeroX = grid.runtimeX; var zeroY = grid.runtimeY; var dataList = serie.GetDataList(); var rangeMin = visualMap.rangeMin; var rangeMax = visualMap.rangeMax; var color = m_Theme.GetColor(serie.index); 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); serie.dataPoints.Clear(); serie.animation.InitProgress(1, 0, xCount); var animationIndex = serie.animation.GetCurrIndex(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var dataChanging = false; 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 = 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); 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); serie.dataPoints.Add(pos); serieData.canShowLabel = false; if (value == 0) { continue; } if (visualMap.enable) { if ((value < rangeMin && rangeMin != visualMap.min) || (value > rangeMax && rangeMax != visualMap.max)) { continue; } if (!visualMap.IsInSelectedValue(value)) { continue; } color = visualMap.GetColor(value); } if (animationIndex >= 0 && i > animationIndex) { continue; } serieData.canShowLabel = true; var emphasis = (tooltip.show && i == (int)tooltip.runtimeXValues[0] && j == (int)tooltip.runtimeYValues[0]) || visualMap.runtimeSelectedIndex > 0; var rectWid = xWidth - 2 * borderWidth; var rectHig = yWidth - 2 * borderWidth; UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color); if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor)) { UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor); } if (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 : ChartConst.clearColor32; var emphasisBorderToColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderToColor : ChartConst.clearColor32; UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor, emphasisBorderToColor); } } } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(xCount); m_IsPlayingAnimation = true; RefreshPainter(serie); } if (dataChanging) { RefreshPainter(serie); } }
private void DrawRectLiquid(VertexHelper vh, Serie serie, Vessel vessel) { var cenPos = vessel.runtimeCenterPos; var serieData = serie.GetSerieData(0); if (serieData == null) { return; } var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var value = serieData.GetCurrData(1, dataChangeDuration); if (serie.runtimeCheckValue != value) { serie.runtimeCheckValue = value; m_UpdateLabelText = true; } if (serieData.labelPosition != cenPos) { serieData.labelPosition = cenPos; m_UpdateLabelText = true; } if (value <= 0) { return; } var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name); var realHig = (value - serie.min) / (serie.max - serie.min) * vessel.runtimeHeight; serie.animation.InitProgress(1, 0, (float)realHig); var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false); var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false); var isNeedGradient = !ChartHelper.IsValueEqualsColor(color, toColor); var isFull = hig >= vessel.runtimeHeight; if (hig >= vessel.runtimeHeight) { hig = vessel.runtimeHeight; } if (isFull && !isNeedGradient) { UGL.DrawRectangle(vh, cenPos, vessel.runtimeWidth / 2, vessel.runtimeHeight / 2, toColor); } else { var startY = (float)(cenPos.y - vessel.runtimeHeight / 2 + hig); var waveStartPos = new Vector3(cenPos.x - vessel.runtimeWidth / 2, startY); var waveEndPos = new Vector3(cenPos.x + vessel.runtimeWidth / 2, startY); var startX = waveStartPos.x; var endX = waveEndPos.x; var step = vessel.smoothness; if (step < 0.5f) { step = 0.5f; } var lup = waveStartPos; var ldp = new Vector3(startX, vessel.runtimeCenterPos.y - vessel.runtimeHeight / 2); var nup = Vector3.zero; var ndp = Vector3.zero; var angle = 0f; var isStarted = false; var isEnded = false; var waveHeight = isFull ? 0 : serie.waveHeight; serie.runtimeWaveSpeed += serie.waveSpeed * Time.deltaTime; while (startX < endX) { startX += step; if (startX > endX) { startX = endX; } if (startX > waveStartPos.x && !isStarted) { startX = waveStartPos.x; isStarted = true; } if (startX > waveEndPos.x && !isEnded) { startX = waveEndPos.x; isEnded = true; } var py = Mathf.Sqrt(Mathf.Pow(vessel.runtimeHeight, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2)); if (startX < waveStartPos.x || startX > waveEndPos.x) { nup = new Vector3(startX, cenPos.y + py); } else { var py2 = waveHeight * Mathf.Sin(1 / serie.waveLength * angle + serie.runtimeWaveSpeed + serie.waveOffset); var nupY = waveStartPos.y + py2; nup = new Vector3(startX, nupY); angle += step; } ndp = new Vector3(startX, cenPos.y - vessel.runtimeHeight / 2); if (nup.y > cenPos.y + vessel.runtimeHeight / 2) { nup.y = cenPos.y + vessel.runtimeHeight / 2; } if (nup.y < cenPos.y - vessel.runtimeHeight / 2) { nup.y = cenPos.y - vessel.runtimeHeight / 2; } if (!ChartHelper.IsValueEqualsColor(color, toColor)) { var colorMin = cenPos.y - vessel.runtimeHeight; var colorMax = startY + serie.waveHeight; var tcolor1 = Color32.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin)); var tcolor2 = Color32.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin)); UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, tcolor1, tcolor2); } else { UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, color); } lup = nup; ldp = ndp; } } if (serie.waveSpeed != 0 && Application.isPlaying && !isFull) { chart.RefreshPainter(serie); } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(realHig); chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } }
private void DrawHeatmapSerie(VertexHelper vh, Heatmap serie) { if (serie.animation.HasFadeOut()) { return; } XAxis xAxis; YAxis yAxis; if (!chart.TryGetChartComponent <XAxis>(out xAxis, serie.xAxisIndex)) { return; } if (!chart.TryGetChartComponent <YAxis>(out yAxis, serie.yAxisIndex)) { return; } m_SerieGrid = chart.GetChartComponent <GridCoord>(xAxis.gridIndex); xAxis.boundaryGap = true; yAxis.boundaryGap = true; var visualMap = chart.GetVisualMapOfSerie(serie); var emphasisItemStyle = serie.emphasisItemStyle; var xCount = xAxis.data.Count; var yCount = yAxis.data.Count; var xWidth = m_SerieGrid.context.width / xCount; var yWidth = m_SerieGrid.context.height / yCount; var zeroX = m_SerieGrid.context.x; var zeroY = m_SerieGrid.context.y; var rangeMin = visualMap.rangeMin; var rangeMax = visualMap.rangeMax; var color = chart.theme.GetColor(serie.index); var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0; var rectWid = xWidth - 2 * borderWidth; var rectHig = yWidth - 2 * borderWidth; 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); serie.context.dataPoints.Clear(); serie.animation.InitProgress(0, xCount); var animationIndex = serie.animation.GetCurrIndex(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var dataChanging = false; serie.containerIndex = m_SerieGrid.index; serie.containterInstanceId = m_SerieGrid.instanceId; for (int n = 0; n < serie.dataCount; n++) { var serieData = serie.data[n]; serieData.index = n; var i = (int)serieData.GetData(0); var j = (int)serieData.GetData(1); var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count); if (serie.IsIgnoreValue(serieData, dimension)) { serie.context.dataPoints.Add(Vector3.zero); continue; } var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse, yAxis.context.minValue, yAxis.context.maxValue); 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); serie.context.dataPoints.Add(pos); serieData.context.position = pos; serieData.context.canShowLabel = false; serieData.context.rect = new Rect(pos.x - rectWid / 2, pos.y - rectHig / 2, rectWid, rectHig); if (value == 0) { continue; } if ((value < rangeMin && rangeMin != visualMap.min) || (value > rangeMax && rangeMax != visualMap.max)) { continue; } if (!visualMap.IsInSelectedValue(value)) { continue; } if (animationIndex >= 0 && i > animationIndex) { continue; } color = visualMap.GetColor(value); if (serieData.context.highlight) { color = ChartHelper.GetHighlightColor(color); } serieData.context.canShowLabel = true; serieData.context.color = color; var highlight = (serieData.context.highlight) || visualMap.context.pointerIndex > 0; //UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color); UGL.DrawRectangle(vh, serieData.context.rect, color); if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor)) { UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor); } if (visualMap.hoverLink && highlight && emphasisItemStyle != null && emphasisItemStyle.borderWidth > 0) { var emphasisBorderWidth = emphasisItemStyle.borderWidth; var emphasisBorderColor = emphasisItemStyle.opacity > 0 ? emphasisItemStyle.borderColor : ChartConst.clearColor32; var emphasisBorderToColor = emphasisItemStyle.opacity > 0 ? emphasisItemStyle.borderToColor : ChartConst.clearColor32; UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor, emphasisBorderToColor); } } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(xCount); chart.RefreshPainter(serie); } if (dataChanging) { chart.RefreshPainter(serie); } }