protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness, Vector3 pos, Color color) { switch (type) { case SerieSymbolType.None: break; case SerieSymbolType.Circle: ChartHelper.DrawCricle(vh, pos, symbolSize, color, GetSymbolCricleSegment(symbolSize)); break; case SerieSymbolType.EmptyCircle: int segment = GetSymbolCricleSegment(symbolSize); ChartHelper.DrawCricle(vh, pos, symbolSize, m_ThemeInfo.backgroundColor, segment); ChartHelper.DrawDoughnut(vh, pos, symbolSize - tickness, symbolSize, 0, 360, color, segment); break; case SerieSymbolType.Rect: ChartHelper.DrawPolygon(vh, pos, symbolSize, color); break; case SerieSymbolType.Triangle: var x = symbolSize * Mathf.Cos(30 * Mathf.PI / 180); var y = symbolSize * Mathf.Sin(30 * Mathf.PI / 180); var p1 = new Vector2(pos.x - x, pos.y - y); var p2 = new Vector2(pos.x, pos.y + symbolSize); var p3 = new Vector2(pos.x + x, pos.y - y); ChartHelper.DrawTriangle(vh, p1, p2, p3, color); break; case SerieSymbolType.Diamond: p1 = new Vector2(pos.x - symbolSize, pos.y); p2 = new Vector2(pos.x, pos.y + symbolSize); p3 = new Vector2(pos.x + symbolSize, pos.y); var p4 = new Vector2(pos.x, pos.y - symbolSize); ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color); break; } }
private void DrawXCategory(VertexHelper vh) { var stackSeries = m_Series.GetStackSeries(); int seriesCount = stackSeries.Count; int serieCount = 0; List <Vector3> points = new List <Vector3>(); List <Color> colorList = new List <Color>(); int dataCount = 0; for (int j = 0; j < seriesCount; j++) { var seriesCurrHig = new Dictionary <int, float>(); var serieList = stackSeries[j]; for (int n = 0; n < serieList.Count; n++) { Serie serie = serieList[n]; DrawXLineSerie(vh, serieCount, serie, ref dataCount, ref points, ref colorList, ref seriesCurrHig); if (serie.show) { serieCount++; } } // draw point if (m_Line.point) { for (int i = 0; i < points.Count; i++) { Vector3 p = points[i]; float pointWid = m_Line.pointWidth; if (m_Tooltip.show && i % dataCount == m_Tooltip.dataIndex - 1) { pointWid = pointWid * 1.8f; } if (m_Theme == Theme.Dark) { ChartHelper.DrawCricle(vh, p, pointWid, colorList[i], (int)m_Line.pointWidth * 5); } else { ChartHelper.DrawCricle(vh, p, pointWid, Color.white); ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness, pointWid, 0, 360, colorList[i]); } } } } //draw tooltip line if (m_Tooltip.show && m_Tooltip.dataIndex > 0) { for (int i = 0; i < m_XAxises.Count; i++) { var axis = m_XAxises[i]; if (!axis.show) { continue; } float splitWidth = axis.GetSplitWidth(coordinateWid, m_DataZoom); float px = coordinateX + (m_Tooltip.xValues[i] - 1) * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0); Vector2 sp = new Vector2(px, coordinateY); Vector2 ep = new Vector2(px, coordinateY + coordinateHig); ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipLineColor); if (m_Tooltip.crossLabel) { sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y); ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y); DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor); } } } }
private void DrawXCategory(VertexHelper vh) { var stackSeries = m_Series.GetStackSeries(); int seriesCount = stackSeries.Count; float scaleWid = m_XAxis.GetDataWidth(coordinateWid, m_DataZoom); int serieCount = 0; List <Vector3> points = new List <Vector3>(); List <Vector3> smoothPoints = new List <Vector3>(); List <Color> colorList = new List <Color>(); int dataCount = 0; for (int j = 0; j < seriesCount; j++) { var seriesCurrHig = new Dictionary <int, float>(); var serieList = stackSeries[j]; for (int n = 0; n < serieList.Count; n++) { Serie serie = serieList[n]; if (!IsActive(serie.name)) { continue; } List <Vector3> lastPoints = new List <Vector3>(); List <Vector3> lastSmoothPoints = new List <Vector3>(); List <float> serieData = serie.GetData(m_DataZoom); Color color = m_ThemeInfo.GetColor(serieCount); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; float startX = zeroX + (m_XAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = maxShowDataNumber > 0 ? (maxShowDataNumber > serieData.Count ? serieData.Count : maxShowDataNumber) : serieData.Count; dataCount = (maxCount - minShowDataNumber); if (m_Line.area && points.Count > 0) { if (!m_Line.smooth && points.Count > 0) { for (int m = points.Count - dataCount; m < points.Count; m++) { lastPoints.Add(points[m]); } } else if (m_Line.smooth && smoothPoints.Count > 0) { for (int m = 0; m < smoothPoints.Count; m++) { lastSmoothPoints.Add(smoothPoints[m]); } smoothPoints.Clear(); } } int smoothPointCount = 1; for (int i = minShowDataNumber; i < maxCount; i++) { if (!seriesCurrHig.ContainsKey(i)) { seriesCurrHig[i] = 0; } float value = serieData[i]; float pX = startX + i * scaleWid; float pY = seriesCurrHig[i] + zeroY + m_Coordinate.tickness; float dataHig = value / (maxValue - minValue) * coordinateHig; np = new Vector3(pX, pY + dataHig); if (i > 0) { if (m_Line.step) { Vector2 middle1, middle2; switch (m_Line.stepTpe) { case Line.StepType.Start: middle1 = new Vector2(lp.x, np.y + m_Line.tickness); middle2 = new Vector2(lp.x - m_Line.tickness, np.y); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(middle1.x, zeroY), middle1, np, new Vector2(np.x, zeroY), areaColor); } break; case Line.StepType.Middle: middle1 = new Vector2((lp.x + np.x) / 2 + m_Line.tickness, lp.y); middle2 = new Vector2((lp.x + np.x) / 2 - m_Line.tickness, np.y); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, new Vector2(middle1.x - m_Line.tickness, middle1.y), new Vector2(middle2.x + m_Line.tickness, middle2.y), m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, middle1, new Vector2(middle1.x, zeroY), areaColor); ChartHelper.DrawPolygon(vh, new Vector2(middle2.x + 2 * m_Line.tickness, zeroY), new Vector2(middle2.x + 2 * m_Line.tickness, middle2.y), np, new Vector2(np.x, zeroY), areaColor); } break; case Line.StepType.End: middle1 = new Vector2(np.x + m_Line.tickness, lp.y); middle2 = new Vector2(np.x, lp.y); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, new Vector2(middle1.x - m_Line.tickness, middle1.y), new Vector2(middle1.x - m_Line.tickness, zeroY), areaColor); } break; } } else if (m_Line.smooth) { var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle); Vector3 start, to; start = list[0]; for (int k = 1; k < list.Length; k++) { smoothPoints.Add(list[k]); to = list[k]; ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color); if (m_Line.area) { Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness); Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness); Vector3 tnp = serieCount > 0 ? (smoothPointCount > lastSmoothPoints.Count - 1 ? new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x, lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) : new Vector3(lastSmoothPoints[smoothPointCount].x, lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) : new Vector3(to.x, zeroY + m_Coordinate.tickness); Vector3 tlp = serieCount > 0 ? (smoothPointCount > lastSmoothPoints.Count - 1 ? new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x, lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) : new Vector3(lastSmoothPoints[smoothPointCount - 1].x, lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) : new Vector3(start.x, zeroY + m_Coordinate.tickness); Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor); } smoothPointCount++; start = to; } } else { ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color); if (m_Line.area) { Vector3 alp = new Vector3(lp.x, lp.y - m_Line.tickness); Vector3 anp = new Vector3(np.x, np.y - m_Line.tickness); Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); var cross = ChartHelper.GetIntersection(lp, np, new Vector3(zeroX, zeroY), new Vector3(zeroX + coordinateWid, zeroY)); if (cross == Vector3.zero) { Vector3 tnp = serieCount > 0 ? new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) : new Vector3(np.x, zeroY + m_Coordinate.tickness); Vector3 tlp = serieCount > 0 ? new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) : new Vector3(lp.x, zeroY + m_Coordinate.tickness); ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor); } else { Vector3 cross1 = new Vector3(cross.x, cross.y + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); Vector3 cross2 = new Vector3(cross.x, cross.y + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); Vector3 xp1 = new Vector3(alp.x, zeroY + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); Vector3 xp2 = new Vector3(anp.x, zeroY + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor); ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor); } } } } if (m_Line.point) { points.Add(np); colorList.Add(color); } seriesCurrHig[i] += dataHig; lp = np; } if (serie.show) { serieCount++; } } // draw point if (m_Line.point) { for (int i = 0; i < points.Count; i++) { Vector3 p = points[i]; float pointWid = m_Line.pointWidth; if (m_Tooltip.show && i % dataCount == m_Tooltip.dataIndex - 1) { pointWid = pointWid * 1.8f; } if (m_Theme == Theme.Dark) { ChartHelper.DrawCricle(vh, p, pointWid, colorList[i], (int)m_Line.pointWidth * 5); } else { ChartHelper.DrawCricle(vh, p, pointWid, Color.white); ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness, pointWid, 0, 360, colorList[i]); } } } } //draw tooltip line if (m_Tooltip.show && m_Tooltip.dataIndex > 0) { float splitWidth = m_XAxis.GetSplitWidth(coordinateWid, m_DataZoom); float px = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth + (m_XAxis.boundaryGap ? splitWidth / 2 : 0); Vector2 sp = new Vector2(px, coordinateY); Vector2 ep = new Vector2(px, coordinateY + coordinateHig); ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipLineColor); if (m_Tooltip.crossLabel) { sp = new Vector2(zeroX, m_Tooltip.pointerPos.y); ep = new Vector2(zeroX + coordinateWid, m_Tooltip.pointerPos.y); DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor); } } }
private void DrawData(VertexHelper vh) { int indicatorNum = m_Radar.indicatorList.Count; var angle = 2 * Mathf.PI / indicatorNum; var p = new Vector3(m_RadarCenterX, m_RadarCenterY); Vector3 startPoint = Vector3.zero; Vector3 toPoint = Vector3.zero; Vector3 firstPoint = Vector3.zero; dataPosList.Clear(); dataPosList.Capacity = m_Series.Count; for (int i = 0; i < m_Series.Count; i++) { if (!IsActive(i)) { dataPosList.Add(new List <Vector3>()); continue; } var dataList = m_Series.series[i].yData; var color = m_ThemeInfo.GetColor(i); var areaColor = color; areaColor.a = (byte)m_Radar.areaAipha; List <Vector3> pointList = new List <Vector3>(dataList.Count); dataPosList.Add(pointList); for (int j = 0; j < dataList.Count; j++) { var max = m_Radar.GetIndicatorMax(j) > 0 ? m_Radar.GetIndicatorMax(j) : GetMaxValue(j); var radius = max < 0 ? m_Radar.radius - m_Radar.radius * dataList[j] / max : m_Radar.radius * dataList[j] / max; var currAngle = j * angle; if (j == 0) { startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); firstPoint = startPoint; } else { toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); if (m_Radar.area) { ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor); } ChartHelper.DrawLine(vh, startPoint, toPoint, m_Radar.lineTickness, color); startPoint = toPoint; } pointList.Add(startPoint); } if (m_Radar.area) { ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor); } ChartHelper.DrawLine(vh, startPoint, firstPoint, m_Radar.lineTickness, color); foreach (var point in pointList) { float radius = m_Radar.linePointSize - m_Radar.lineTickness * 2; ChartHelper.DrawCricle(vh, point, radius, Color.white); ChartHelper.DrawDoughnut(vh, point, radius, m_Radar.linePointSize, 0, 360, color); } } }
private void DrawXCategory(VertexHelper vh) { int seriesCount = m_Series.Count; float scaleWid = m_XAxis.GetDataWidth(coordinateWid); for (int j = 0; j < seriesCount; j++) { if (!IsActive(j)) continue; Serie serie = m_Series.series[j]; Color32 color = m_ThemeInfo.GetColor(j); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; float startX = zeroX + (m_XAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = maxShowDataNumber > 0 ? (maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber) : serie.data.Count; for (int i = minShowDataNumber; i < maxCount; i++) { float value = serie.data[i]; float dataHig = coordinateY + (value - minValue) / (maxValue - minValue) * coordinateHig; np = new Vector3(startX + i * scaleWid, dataHig); if (i > 0) { if (m_Line.smooth) { var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle); Vector3 start, to; start = list[0]; for (int k = 1; k < list.Length; k++) { to = list[k]; ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color); start = to; } } else { ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color); if (m_Line.area) { ChartHelper.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY), new Vector3(lp.x, zeroY), color); } } } lp = np; } // draw point if (m_Line.point) { for (int i = 0; i < serie.data.Count; i++) { float value = serie.data[i]; float dataHig = coordinateY + (value - minValue) / (maxValue - minValue) * coordinateHig; Vector3 p = new Vector3(startX + i * scaleWid, dataHig); float pointWid = m_Line.pointWidth; if (m_Tooltip.show && i == m_Tooltip.dataIndex - 1) { pointWid = pointWid * 1.8f; } if (m_Theme == Theme.Dark) { ChartHelper.DrawCricle(vh, p, pointWid, color, (int)m_Line.pointWidth * 5); } else { ChartHelper.DrawCricle(vh, p, pointWid, Color.white); ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness, pointWid, 0, 360, color); } } } } //draw tooltip line if (m_Tooltip.show && m_Tooltip.dataIndex > 0) { float splitWidth = m_XAxis.GetSplitWidth(coordinateWid); float px = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth + (m_XAxis.boundaryGap ? splitWidth / 2 : 0); Vector2 sp = new Vector2(px, coordinateY); Vector2 ep = new Vector2(px, coordinateY + coordinateHig); ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipFlagAreaColor); } }