public override void Draw(Graphics g, AxisCollection yAxisCollection, XAxis xAxis, AdvancedRect area) { if (data.Count == 0) { return; } GraphicsState _s = g.Save(); g.SmoothingMode = SmoothingMode.AntiAlias; NumericAxis yAxis = yAxisCollection[YAxisName]; double[] baseY = new double[data.Count]; if (yAxis.LogAxis) { for (int i = 0; i < data.Count; i++) { baseY[i] = yAxis.ScaleMinimum; } } else { for (int i = 0; i < data.Count; i++) { baseY[i] = 0; } } for (int ySet = 0; ySet < data.GetY(0).Length; ySet++) { PointF[] polygon = new PointF[data.Count * 2]; PointF[] line = new PointF[data.Count]; int j = 0; for (int i = (data.Count - 1); i >= 0; i--, j++) { polygon[j] = new PointF( xAxis.DataToCoordinate(data.GetX(i), area), yAxis.DataToCoordinate(baseY[i], area) ); } for (int i = 0; i < data.Count; i++, j++) { double?y = data.GetY(i)[ySet]; if (y == null) { y = baseY[i]; } else { y = baseY[i] + y.Value; } polygon[j] = new PointF( xAxis.DataToCoordinate(data.GetX(i), area), yAxis.DataToCoordinate(y.Value, area) ); line[i] = polygon[j]; baseY[i] = y.Value; } if (brushes.Count != 0) { int idx = ySet % brushes.Count; using (Brush br = brushes[idx].CreateBrush()) g.FillPolygon(br, polygon); } if (pens.Count != 0 && line.Length >= 2) { int idx = ySet % pens.Count; using (Pen p = pens[idx].CreatePen()) g.DrawLines(p, line); } } g.Restore(_s); }
private void drawLines(Graphics g, Pen p, Symbol s, XAxis xAxis, NumericAxis yAxis, AdvancedRect area, int start, int end) { PointF[] pt; int count = end - start; if (stepLine) { if (end == data.Count && count == 1) { // drawing a single point at the end going nowhere, // not possible. fixme: make a symbol or something to // indicate a single point? return; } pt = new PointF[count * 2 - (end == data.Count ? 1 : 0)]; for (int i = 0; i < count; i++) { pt[i * 2].X = xAxis.DataToCoordinate(data.GetX(start + i), area); pt[i * 2].Y = yAxis.DataToCoordinate(data.GetY(start + i).Value, area); if ((start + i + 1) < data.Count) { pt[(i * 2) + 1].X = xAxis.DataToCoordinate(data.GetX(start + i + 1), area); pt[(i * 2) + 1].Y = pt[i * 2].Y; } } } else { if (count == 1) { // can't really draw a line here. // fixme: make a symbol or something to indicate a single // point? return; } pt = new PointF[count]; for (int i = 0; i < count; i++) { pt[i].X = xAxis.DataToCoordinate(data.GetX(start + i), area); pt[i].Y = yAxis.DataToCoordinate(data.GetY(start + i).Value, area); } } g.DrawLines(p, pt); switch (SymbolStyle) { case SymbolStyle.IdentifyPoints: foreach (PointF x in pt) { s.DrawCenteredAt(g, x); } break; case SymbolStyle.IdentifyLine: PointF lastPt = pt[0]; for (int i = 1; i < pt.Length; i++) { PointF curPt = pt[i]; double dist = Math.Sqrt(Math.Pow(curPt.X - lastPt.X, 2) + Math.Pow(curPt.Y - lastPt.Y, 2)); if (dist > 0.5) { s.DrawCenteredAt(g, curPt); lastPt = curPt; } } break; } }