private void DrawPolygons(IGraphics g, int width, int height) { if (GetPolygonCount == null || GetPolygon == null) { return; } for (int i = 0; i < GetPolygonCount(); i++) { PolygonData pol = GetPolygon(i); PolygonProperties lp = GetPolygonProperties(i); double[] xc = pol.x; double[] yc = pol.y; Pen linePen = new Pen(lp.LineColor, lp.LineWidth) { DashStyle = lp.LineDashStyle }; List <Point> ps = new List <Point>(); for (int j = 0; j < xc.Length; j++) { if (double.IsNaN(xc[j]) || double.IsNaN(yc[j]) || double.IsInfinity(xc[j]) || double.IsInfinity(yc[j])) { continue; } int xi1 = ModelToViewX(xc[j], width); int yi1 = ModelToViewY(yc[j], height); ps.Add(new Point(xi1, yi1)); } if (lp.LineWidth > 0) { g.DrawLines(linePen, ps.ToArray()); } SymbolType symbolType = SymbolType.allSymbols[lp.SymbolType]; int symbolSize = lp.SymbolSize; Pen p = new Pen(lp.SymbolColor); Brush b = new SolidBrush(lp.SymbolColor); if (symbolSize > 0) { foreach (Point t in ps) { symbolType.Draw(symbolSize, t.X, t.Y, g, p, b); } } int w2 = lp.ErrorSize / 2; if (lp.HorizErrors) { Pen errorPen = new Pen(lp.SymbolColor, lp.ErrorLineWidth) { DashStyle = DashStyle.Solid }; for (int j = 0; j < xc.Length; j++) { double x = xc[j]; double y = yc[j]; if (double.IsNaN(x) || double.IsNaN(y) || double.IsInfinity(x) || double.IsInfinity(y)) { continue; } int xi = ModelToViewX(x, width); int yi = ModelToViewY(y, height); double ed = pol.xErrDown[j]; if (!double.IsNaN(ed) && !double.IsInfinity(ed) && ed >= 0) { int xi2 = ModelToViewX(x - ed, width); g.DrawLine(errorPen, xi, yi, xi2, yi); if (w2 > 0) { g.DrawLine(errorPen, xi2, yi - w2, xi2, yi + w2); } } double eu = pol.xErrUp[j]; if (!double.IsNaN(eu) && !double.IsInfinity(eu) && eu >= 0) { int xi3 = ModelToViewX(x + eu, width); g.DrawLine(errorPen, xi, yi, xi3, yi); if (w2 > 0) { g.DrawLine(errorPen, xi3, yi - w2, xi3, yi + w2); } } } } if (lp.VertErrors) { Pen errorPen = new Pen(lp.SymbolColor, lp.ErrorLineWidth) { DashStyle = DashStyle.Solid }; for (int j = 0; j < xc.Length; j++) { double x = xc[j]; double y = yc[j]; if (double.IsNaN(x) || double.IsNaN(y) || double.IsInfinity(x) || double.IsInfinity(y)) { continue; } int xi = ModelToViewX(x, width); int yi = ModelToViewY(y, height); double ed = pol.yErrDown[j]; if (!double.IsNaN(ed) && !double.IsInfinity(ed) && ed >= 0) { int yi2 = ModelToViewY(y - ed, height); g.DrawLine(errorPen, xi, yi, xi, yi2); if (w2 > 0) { g.DrawLine(errorPen, xi - w2, yi2, xi + w2, yi2); } } double eu = pol.yErrUp[j]; if (!double.IsNaN(eu) && !double.IsInfinity(eu) && eu >= 0) { int yi3 = ModelToViewY(y + eu, height); g.DrawLine(errorPen, xi, yi, xi, yi3); if (w2 > 0) { g.DrawLine(errorPen, xi - w2, yi3, xi + w2, yi3); } } } } } }
protected void PaintOnGraphicsVector(IGraphics g, int width, int height) { if (scatterPlot == null) { return; } if (!area.IsEmpty) { g.FillRectangle(Brushes.LightGray, 0, 0, width, height); g.FillRectangle(Brushes.White, area.X, area.Y, area.Width, area.Height); } else { g.FillRectangle(new SolidBrush(BackColor), 0, 0, width, height); } PaintGridVector(g, width, height); SymbolProperties[] gg = ArrayUtils.GetKeys(values); int[] counts = new int[gg.Length]; for (int i = 0; i < counts.Length; i++) { counts[i] = values[gg[i]].Count; } int[] o = ArrayUtils.Order(counts); Array.Reverse(o); gg = ArrayUtils.SubArray(gg, o); foreach (SymbolProperties g1 in gg) { bool[,] vals = values[g1].Data; double[,] zvals = null; if (zValues != null) { zvals = zValues[g1]; } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (vals[i, j]) { Color color; if (zvals != null && !double.IsNaN(zvals[i, j]) && colorScale != null) { color = colorScale.GetColor(zvals[i, j]); } else { color = g1.Color; } Pen p = new Pen(color); Brush b = new SolidBrush(color); SymbolType symbolType = SymbolType.allSymbols[g1.Type]; int symbolSize = g1.Size; if (symbolSize == 0) { continue; } int[] pathX; int[] pathY; symbolType.GetPath(symbolSize, out pathX, out pathY); symbolType.Draw(symbolSize, i, j, g, p, b); } } } } // selected data points Brush selectionBrush = new SolidBrush(SelectionColor); Pen selectionPen = new Pen(SelectionColor); foreach (int s in scatterPlot.Selection) { double[] w = scatterPlot.GetDataAt(s); if (w.Length > 0) { double x = w[0]; double y = w[1]; SymbolProperties gx = GetPointProperties != null?GetPointProperties(s) : defaultSymbol; SymbolType symbolType = SymbolType.allSymbols[gx.Type]; int symbolSize = gx.Size; if (symbolSize > 0) { symbolType.Draw(symbolSize, ModelToViewX(x, width), ModelToViewY(y, height), g, selectionPen, selectionBrush); } } } // labels ScatterPlotLabelMode labelMode = scatterPlot.GetLabelMode(); bool cutLabels = scatterPlot.CutLabels; if (labelMode == ScatterPlotLabelMode.All && scatterPlot.HasLabels) { Font font = new Font("Arial", scatterPlot.FontSize, scatterPlot.FontStyle); for (;;) { double[] x; double[] y; double[] z; string[] labels; int index; scatterPlot.GetData(out x, out y, out z, out labels, out index); if (x == null) { break; } SymbolProperties gx = GetPointProperties != null?GetPointProperties(index) : defaultSymbol; for (int i = 0; i < x.Length; i++) { if (labelMode == ScatterPlotLabelMode.All || scatterPlot.IsSelected(i)) { int ix = ModelToViewX(x[i], width); int iy = ModelToViewY(y[i], height); Color c; if (z != null && colorScale != null) { c = colorScale.GetColor(z[i]); } else { c = gx.Color; } Brush b = new SolidBrush(c); if (ix >= 0 && iy >= 0 && ix < width && iy < height) { if (labels[i] != null) { string s = labels[i]; if (cutLabels) { if (s.Contains(";")) { s = s.Substring(0, s.IndexOf(';')); } } g.DrawString(s, font, b, ix, iy); } } } } } scatterPlot.Reset(); } if (labelMode == ScatterPlotLabelMode.Selected && scatterPlot.HasLabels) { Font font = new Font("Arial", scatterPlot.FontSize, scatterPlot.FontStyle); foreach (int s in scatterPlot.Selection) { double[] w = scatterPlot.GetDataAt(s); string label = scatterPlot.GetLabelAt(s); double x = w[0]; double y = w[1]; int ix = ModelToViewX(x, width); int iy = ModelToViewY(y, height); if (ix >= 0 && iy >= 0 && ix < width && iy < height) { if (label != null) { if (cutLabels) { if (label.Contains(";")) { label = label.Substring(0, label.IndexOf(';')); } } g.DrawString(label, font, selectionBrush, ix, iy); } } } } DrawPolygons(g, width, height); if (drawFunctions != null) { drawFunctions(g, width, height, ModelToViewX, ModelToViewY, ViewToModelX, ViewToModelY); } }