private void DrawRadar(VertexHelper vh) { float insideRadius = 0, outsideRadius = 0; float block = radarInfo.radius / radarInfo.splitNumber; int indicatorNum = radarInfo.indicatorList.Count; Vector3 p1, p2, p3, p4; Vector3 p = new Vector3(radarCenterX, radarCenterY); float angle = 2 * Mathf.PI / indicatorNum; for (int i = 0; i < radarInfo.splitNumber; i++) { Color color = radarInfo.backgroundColorList[i % radarInfo.backgroundColorList.Count]; outsideRadius = insideRadius + block; p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0)); p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0)); for (int j = 0; j <= indicatorNum; j++) { float currAngle = j * angle; p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p.y + outsideRadius * Mathf.Cos(currAngle)); p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle), p.y + insideRadius * Mathf.Cos(currAngle)); ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color); ChartUtils.DrawLine(vh, p2, p3, radarInfo.lineTickness, radarInfo.lineColor); p1 = p4; p2 = p3; } insideRadius = outsideRadius; } for (int j = 0; j <= indicatorNum; j++) { float currAngle = j * angle; p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p.y + outsideRadius * Mathf.Cos(currAngle)); ChartUtils.DrawLine(vh, p, p3, radarInfo.lineTickness / 2, radarInfo.lineColor); } }
private void DrawCricleRadar(VertexHelper vh) { float insideRadius = 0, outsideRadius = 0; float block = radarInfo.radius / radarInfo.splitNumber; int indicatorNum = radarInfo.indicatorList.Count; Vector3 p = new Vector3(radarCenterX, radarCenterY); Vector3 p1; float angle = 2 * Mathf.PI / indicatorNum; for (int i = 0; i < radarInfo.splitNumber; i++) { Color color = radarInfo.backgroundColorList[i % radarInfo.backgroundColorList.Count]; outsideRadius = insideRadius + block; ChartUtils.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color); ChartUtils.DrawCicleNotFill(vh, p, outsideRadius, radarInfo.lineTickness, radarInfo.lineColor); insideRadius = outsideRadius; } for (int j = 0; j <= indicatorNum; j++) { float currAngle = j * angle; p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p.y + outsideRadius * Mathf.Cos(currAngle)); ChartUtils.DrawLine(vh, p, p1, radarInfo.lineTickness / 2, radarInfo.lineColor); } }
private void DrawData(VertexHelper vh) { int indicatorNum = radarInfo.indicatorList.Count; var angle = 2 * Mathf.PI / indicatorNum; var p = new Vector3(radarCenterX, radarCenterY); Vector3 startPoint = Vector3.zero; Vector3 toPoint = Vector3.zero; Vector3 firstPoint = Vector3.zero; for (int i = 0; i < seriesList.Count; i++) { if (!legend.IsShowSeries(i)) { continue; } var dataList = seriesList[i].dataList; var color = themeInfo.GetColor(i); var areaColor = new Color(color.r, color.g, color.b, color.a * 0.7f); var max = radarInfo.indicatorList[i].max > 0 ? radarInfo.indicatorList[i].max : GetMaxValue(); List <Vector3> pointList = new List <Vector3>(); for (int j = 0; j < dataList.Count; j++) { var radius = radarInfo.radius * dataList[j].value / 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 (radarInfo.area) { ChartUtils.DrawTriangle(vh, p, startPoint, toPoint, areaColor); } ChartUtils.DrawLine(vh, startPoint, toPoint, radarInfo.lineTickness, color); startPoint = toPoint; } pointList.Add(startPoint); } if (radarInfo.area) { ChartUtils.DrawTriangle(vh, p, startPoint, firstPoint, areaColor); } ChartUtils.DrawLine(vh, startPoint, firstPoint, radarInfo.lineTickness, color); foreach (var point in pointList) { float radius = radarInfo.linePointSize - radarInfo.lineTickness * 2; ChartUtils.DrawCricle(vh, point, radius, Color.white); ChartUtils.DrawDoughnut(vh, point, radius, radarInfo.linePointSize, 0, 360, color); } } }
public void DrawLine(VertexHelper vh, float value, Color color) { float y = GetPostionY(value); float scaleWid = xAxis.GetDataWidth(coordinateWid); float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0); Vector3 start = new Vector3(startX + 0 * scaleWid, y); Vector3 to = new Vector3(startX + (seriesList[0].DataList.Count - 1) * scaleWid, y); ChartUtils.DrawLine(vh, start, to, lineInfo.tickness * 0.5f, color); }
protected override void DrawCoordinate(VertexHelper vh) { if (!coordinate.show) { return; } // draw splitline for (int i = 1; i < yAxis.GetScaleNumber(); i++) { float pX = zeroX - coordinate.splitWidth; float pY = zeroY + i * coordinateHig / (yAxis.GetScaleNumber() - 1); ChartUtils.DrawLine(vh, new Vector3(pX, pY), new Vector3(zeroX, pY), coordinate.tickness, themeInfo.axisLineColor); if (yAxis.showSplitLine) { DrawSplitLine(vh, true, yAxis.splitLineType, new Vector3(zeroX, pY), new Vector3(zeroX + coordinateWid, pY)); } } for (int i = 1; i < xAxis.GetScaleNumber(); i++) { float pX = zeroX + i * coordinateWid / (xAxis.GetScaleNumber() - 1); float pY = zeroY - coordinate.splitWidth - 2; ChartUtils.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY), coordinate.tickness, themeInfo.axisLineColor); if (xAxis.showSplitLine) { DrawSplitLine(vh, false, xAxis.splitLineType, new Vector3(pX, zeroY), new Vector3(pX, zeroY + coordinateHig)); } } for (int i = 1; i < yAxis.GetScaleNumber(); i++) { float pX = zeroX + coordinateWid; float pY = zeroY + i * coordinateHig / (yAxis.GetScaleNumber() - 1); ChartUtils.DrawLine(vh, new Vector3(pX, pY), new Vector3(pX + coordinate.splitWidth, pY), coordinate.tickness, themeInfo.axisLineColor); } ChartUtils.DrawLine(vh, new Vector3(zeroX, zeroY - coordinate.splitWidth), new Vector3(zeroX, zeroY + coordinateHig + 2), coordinate.tickness, themeInfo.axisLineColor); ChartUtils.DrawLine(vh, new Vector3(zeroX - coordinate.splitWidth, zeroY), new Vector3(zeroX + coordinateWid + 5, zeroY), coordinate.tickness, themeInfo.axisLineColor); ChartUtils.DrawLine(vh, new Vector3(zeroX + coordinateWid, zeroY - coordinate.splitWidth), new Vector3(zeroX + coordinateWid, zeroY + coordinateHig + 2), coordinate.tickness, themeInfo.axisLineColor); }
private void DrawSplitLine(VertexHelper vh, bool isYAxis, SplitLineType type, Vector3 startPos, Vector3 endPos) { switch (type) { case SplitLineType.dashed: case SplitLineType.dotted: var startX = startPos.x; var startY = startPos.y; var dashLen = type == SplitLineType.dashed ? 6 : 2.5f; var count = isYAxis ? (endPos.x - startPos.x) / (dashLen * 2) : (endPos.y - startPos.y) / (dashLen * 2); for (int i = 0; i < count; i++) { if (isYAxis) { var toX = startX + dashLen; ChartUtils.DrawLine(vh, new Vector3(startX, startY), new Vector3(toX, startY), coordinate.tickness, themeInfo.axisSplitLineColor); startX += dashLen * 2; } else { var toY = startY + dashLen; ChartUtils.DrawLine(vh, new Vector3(startX, startY), new Vector3(startX, toY), coordinate.tickness, themeInfo.axisSplitLineColor); startY += dashLen * 2; } } break; case SplitLineType.solid: ChartUtils.DrawLine(vh, startPos, endPos, coordinate.tickness, themeInfo.axisSplitLineColor); break; } }
private void DrawCoordinate(VertexHelper vh) { if (!coordinate.show) { return; } // draw scale for (int i = 1; i < yAxis.splitNumber; i++) { float pX = zeroX - coordinate.scaleLen; float pY = zeroY + i * coordinateHig / (yAxis.splitNumber - 1); ChartUtils.DrawLine(vh, new Vector3(pX, pY), new Vector3(zeroX, pY), coordinate.tickness, Color.white); if (yAxis.showSplitLine) { ChartUtils.DrawLine(vh, new Vector3(zeroX, pY), new Vector3(zeroX + coordinateWid, pY), coordinate.tickness, Color.grey); } } for (int i = 1; i < xAxis.splitNumber; i++) { float pX = zeroX + i * coordinateWid / (xAxis.splitNumber - 1); float pY = zeroY - coordinate.scaleLen - 2; ChartUtils.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY), coordinate.tickness, Color.white); if (xAxis.showSplitLine) { ChartUtils.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, zeroY + coordinateHig), coordinate.tickness, Color.grey); } } //draw x,y axis ChartUtils.DrawLine(vh, new Vector3(zeroX, zeroY - coordinate.scaleLen), new Vector3(zeroX, zeroY + coordinateHig + 2), coordinate.tickness, Color.white); ChartUtils.DrawLine(vh, new Vector3(zeroX - coordinate.scaleLen, zeroY), new Vector3(zeroX + coordinateWid + 2, zeroY), coordinate.tickness, Color.white); }
protected override void DrawChart(VertexHelper vh) { base.DrawChart(vh); int seriesCount = seriesList.Count; Vector2 v2 = GetMaxAndMinValue(); float max = v2.x - v2.y; //float max = GetMaxValue(); float minValue = v2.y; //draw tooltip line if (tooltip.show && tooltip.DataIndex > 0) { float splitWid = coordinateWid / (xAxis.GetDataNumber() - 1); float px = zeroX + (tooltip.DataIndex - 1) * splitWid + (xAxis.boundaryGap ? splitWid / 2 : 0); Vector2 sp = new Vector2(px, zeroY); Vector2 ep = new Vector2(px, zeroY + coordinateHig); ChartUtils.DrawLine(vh, sp, ep, coordinate.tickness, themeInfo.tooltipFlagAreaColor); } DrawLine(vh, upper, new Color32(13, 217, 157, 255)); DrawLine(vh, lower, new Color32(246, 72, 82, 255)); float scaleWid = xAxis.GetDataWidth(coordinateWid); for (int j = 0; j < seriesCount; j++) { if (!legend.IsShowSeries(j)) { continue; } Series series = seriesList[j]; Color32 color = themeInfo.GetColor(j); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0); int showDataNumber = series.showDataNumber; int startIndex = 0; if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber) { startIndex = series.DataList.Count - series.showDataNumber; } for (int i = startIndex; i < series.DataList.Count; i++) { float value = series.DataList[i]; np = new Vector3(startX + i * scaleWid, zeroY + (value - minValue) * coordinateHig / max); if (i > 0) { if (lineInfo.smooth) { var list = ChartUtils.GetBezierList(lp, np, lineInfo.smoothStyle); Vector3 start, to; start = list[0]; for (int k = 1; k < list.Length; k++) { to = list[k]; ChartUtils.DrawLine(vh, start, to, lineInfo.tickness, color); start = to; } } else { ChartUtils.DrawLine(vh, lp, np, lineInfo.tickness, color); if (lineInfo.area) { ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY), new Vector3(lp.x, zeroY), color); } } } lp = np; } // draw point if (lineInfo.showPoint) { for (int i = 0; i < series.DataList.Count; i++) { float value = series.DataList[i]; Vector3 p = new Vector3(startX + i * scaleWid, zeroY + (value - minValue) * coordinateHig / max); float pointWid = lineInfo.pointWid; if (tooltip.show && i == tooltip.DataIndex - 1) { pointWid = pointWid * 5f; } if (theme == Theme.Dark) { ChartUtils.DrawCricle(vh, p, pointWid, color, (int)lineInfo.pointWid * 5); } else { ChartUtils.DrawCricle(vh, p, pointWid, color); //ChartUtils.DrawDoughnut(vh, p, pointWid - lineInfo.tickness, //pointWid, 0, 360, color); } } } } }
protected override void OnPopulateMesh(VertexHelper vh) { vh.Clear(); int dataRectWid = (int)(chartWid / pointWidth) * pointWidth; float dataMax = GetAllLineMax(); // draw bg Vector3 p1 = new Vector3(-graduationWidth, chartHig + 30); Vector3 p2 = new Vector3(dataRectWid + 50, chartHig + 30); Vector3 p3 = new Vector3(dataRectWid + 50, -20); Vector3 p4 = new Vector3(-graduationWidth, -20); ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, backgroundColor); // draw coordinate Vector3 coordZero = Vector3.zero; ChartUtils.DrawLine(vh, new Vector3(dataRectWid + 5, -5), new Vector3(dataRectWid + 5, chartHig + 0.5f), 1, Color.grey); // draw graduation for (int i = 0; i < graduationList.Count; i++) { Vector3 sp = new Vector3(-5, chartHig * i / (graduationList.Count - 1)); Vector3 ep = new Vector3(dataRectWid + 5, chartHig * i / (graduationList.Count - 1)); ChartUtils.DrawLine(vh, sp, ep, 0.5f, Color.grey); } // draw line for (int index = 0; index < lineList.Count; index++) { LineData_old line = lineList[index]; if (!line.visible) { continue; } Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; for (int i = 0; i < line.dataList.Count; i++) { float data = line.dataList[i] * chartHig / dataMax; np = new Vector3(i * pointWidth, data); if (i > 0) { ChartUtils.DrawLine(vh, lp, np, lineSize, line.lineColor); } lp = np; } // draw point for (int i = 0; i < line.dataList.Count; i++) { UIVertex[] quadverts = new UIVertex[4]; float data = line.dataList[i] * chartHig / dataMax; Vector3 p = new Vector3(i * pointWidth, data); ChartUtils.DrawPolygon(vh, p, pointSize, line.pointColor); } } //draw x,y axis float xLen = dataRectWid + 25; float yLen = chartHig + 15; float xPos = 0; float yPos = -5; ChartUtils.DrawLine(vh, new Vector3(xPos, yPos - 1.5f), new Vector3(xPos, yLen), 1.5f, Color.white); ChartUtils.DrawLine(vh, new Vector3(xPos, yPos), new Vector3(xLen, yPos), 1.5f, Color.white); //draw arrows ChartUtils.DrawTriangle(vh, new Vector3(xPos - arrowSize, yLen - arrowLen), new Vector3(xPos, yLen + 4), new Vector3(xPos + arrowSize, yLen - arrowLen), Color.white); ChartUtils.DrawTriangle(vh, new Vector3(xLen - arrowLen, yPos + arrowSize), new Vector3(xLen + 4, yPos), new Vector3(xLen - arrowLen, yPos - arrowSize), Color.white); }
void DrawLineChart(VertexHelper vh) { if (Mode == ChartMode.Bar) { return; } int seriesCount = seriesList.Count; Vector2 v2 = GetMaxAndMinValue(); float max = v2.x - v2.y; //float max = GetMaxValue(); float minValue = v2.y; float scaleWid = xAxis.GetDataWidth(coordinateWid); int num = Mode == ChartMode.Mixed?1:0; for (int j = num; j < seriesCount; j++) { if (!legend.IsShowSeries(j)) { continue; } Series series = seriesList[j]; Color32 color = themeInfo.GetColor(j); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0); int showDataNumber = series.showDataNumber; int startIndex = 0; if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber) { startIndex = series.DataList.Count - series.showDataNumber; } for (int i = startIndex; i < series.DataList.Count; i++) { float value = series.DataList[i]; np = new Vector3(startX + i * scaleWid, zeroY + (value - minValue) * coordinateHig / max); if (i > 0) { if (lineInfo.smooth) { var list = ChartUtils.GetBezierList(lp, np, lineInfo.smoothStyle); Vector3 start, to; start = list[0]; for (int k = 1; k < list.Length; k++) { to = list[k]; ChartUtils.DrawLine(vh, start, to, lineInfo.tickness, color); start = to; } } else { ChartUtils.DrawLine(vh, lp, np, lineInfo.tickness, color); if (lineInfo.area) { ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY), new Vector3(lp.x, zeroY), color); } } } lp = np; } // draw point if (lineInfo.showPoint) { for (int i = num; i < series.DataList.Count; i++) { float value = series.DataList[i]; Vector3 p = new Vector3(startX + i * scaleWid, zeroY + (value - minValue) * coordinateHig / max); float pointWid = lineInfo.pointWid; if (tooltip.show && i == tooltip.DataIndex - 1) { pointWid = pointWid * 1.8f; } if (theme == Theme.Dark) { ChartUtils.DrawCricle(vh, p, pointWid, color, (int)lineInfo.pointWid * 5); } else { ChartUtils.DrawCricle(vh, p, pointWid, Color.white); ChartUtils.DrawDoughnut(vh, p, pointWid - lineInfo.tickness, pointWid, 0, 360, color); } } } } }
protected override void OnPopulateMesh(VertexHelper vh) { base.OnPopulateMesh(vh); int seriesCount = seriesList.Count; float max = GetMaxValue(); float scaleWid = coordinateWid / (xAxis.splitNumber - 1); for (int j = 0; j < seriesCount; j++) { if (!legend.IsShowSeries(j)) { continue; } Series series = seriesList[j]; Color color = themeInfo.GetColor(j); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0); int showDataNumber = series.showDataNumber; int startIndex = 0; if (series.showDataNumber > 0 && series.dataList.Count > series.showDataNumber) { startIndex = series.dataList.Count - series.showDataNumber; } for (int i = startIndex; i < series.dataList.Count; i++) { SeriesData data = series.dataList[i]; np = new Vector3(startX + i * scaleWid, zeroY + data.value * coordinateHig / max); if (i > 0) { if (lineInfo.smooth) { var list = ChartUtils.GetBezierList(lp, np, lineInfo.smoothStyle); Vector3 start, to; start = list[0]; for (int k = 1; k < list.Count; k++) { to = list[k]; ChartUtils.DrawLine(vh, start, to, lineInfo.tickness, color); start = to; } } else { ChartUtils.DrawLine(vh, lp, np, lineInfo.tickness, color); if (lineInfo.area) { ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY), new Vector3(lp.x, zeroY), color); } } } lp = np; } // draw point if (lineInfo.showPoint) { for (int i = 0; i < series.dataList.Count; i++) { SeriesData data = series.dataList[i]; Vector3 p = new Vector3(startX + i * scaleWid, zeroY + data.value * coordinateHig / max); if (theme == Theme.Dark) { ChartUtils.DrawCricle(vh, p, lineInfo.pointWid, color, (int)lineInfo.pointWid * 5); } else { ChartUtils.DrawCricle(vh, p, lineInfo.pointWid, Color.white); ChartUtils.DrawDoughnut(vh, p, lineInfo.pointWid - lineInfo.tickness, lineInfo.pointWid, 0, 360, color); } } } } }