public static void DataPlottables(Settings settings) { if (settings.gfxData == null) { return; } // Construct the dimensions object to be injected into plottables during rendering. var dims = new PlotDimensions(settings.figureSize, settings.dataSize, settings.dataOrigin, settings.axes.Limits); for (int i = 0; i < settings.plottables.Count; i++) { Plottable plottable = settings.plottables[i]; if (plottable.visible) { try { if (plottable is IPlottable modernPlottable) { // use the new render method (that injections dimensions and the bitmap to draw on) modernPlottable.Render(dims, settings.bmpData); } else { // use the old render method (that reads state from settings module and draws on the bitmap stored there) plottable.Render(settings); } } catch (OverflowException) { Debug.WriteLine($"OverflowException plotting: {plottable}"); } } } }
private static void DrawLegendItemString(Plottable plottable, Settings settings, Point itemLocation, int padding, int stubWidth, float legendFontLineHeight) { Brush brushText = new SolidBrush(settings.legend.colorText); var textLocation = itemLocation + new Size(padding + stubWidth + padding, 0); settings.gfxLegend.DrawString(plottable.label, settings.legend.font, brushText, textLocation); }
private static void DrawLegendItemLine(Plottable plottable, Settings settings, Point textLocation, int padding, int stubWidth, float legendFontLineHeight) { Pen pen = new Pen(plottable.color, 1); if (plottable is PlottableAxSpan) { pen.Width = 10; } if (settings.legend.fixedLineWidth == false) { if (plottable is PlottableScatter) { pen.Width = (float)((PlottableScatter)plottable).lineWidth; } if (plottable is PlottableSignal) { pen.Width = (float)((PlottableSignal)plottable).lineWidth; } } // dont draw line if it's not on the plottable if ((plottable is PlottableScatter) && (((PlottableScatter)plottable).lineWidth) == 0) { return; } if ((plottable is PlottableSignal) && (((PlottableSignal)plottable).lineWidth) == 0) { return; } switch (plottable.lineStyle) { case LineStyle.Solid: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; break; case LineStyle.Dash: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; break; case LineStyle.DashDot: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; break; case LineStyle.DashDotDot: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; break; case LineStyle.Dot: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; break; } settings.gfxLegend.DrawLine(pen, textLocation.X - padding, textLocation.Y + legendFontLineHeight / 2, textLocation.X - padding - stubWidth, textLocation.Y + legendFontLineHeight / 2); }
/// <summary> /// Clear all plottables of the same type as the one that is given /// </summary> public void Clear(Plottable examplePlottable) { settings.plottables.RemoveAll(x => x.GetType() == examplePlottable.GetType()); if (settings.plottables.Count == 0) { settings.axes.Reset(); } }
public void MouseUp(Point eLocation) { if (draggingObject == null) { settings.MouseMoveAxis(Cursor.Position.X, Cursor.Position.Y); settings.MouseUpAxis(); } else { PointF newPosition = settings.GetLocation(eLocation.X, eLocation.Y); draggingObject = null; } }
public void MouseDown(Point eLocation) { draggingObject = PlottableUnderCursor(eLocation); if (draggingObject == null) { mouseDownStopwatch.Restart(); if (Control.MouseButtons == MouseButtons.Left) { settings.MouseDown(Cursor.Position.X, Cursor.Position.Y, panning: true); } else if (Control.MouseButtons == MouseButtons.Right) { settings.MouseDown(Cursor.Position.X, Cursor.Position.Y, zooming: true); } } else { PointF newPosition = settings.GetLocation(eLocation.X, eLocation.Y); } }
public static void DataPlottables(Settings settings) { if (settings.gfxData == null) { return; } for (int i = 0; i < settings.plottables.Count; i++) { Plottable pltThing = settings.plottables[i]; try { pltThing.Render(settings); } catch (OverflowException) { Debug.WriteLine($"OverflowException plotting: {pltThing}"); } } }
private void PbPlot_MouseMove(object sender, MouseEventArgs e) { plt.mouseTracker.MouseMove(e.Location); OnMouseMoved(EventArgs.Empty); Plottable plottableUnderCursor = plt.mouseTracker.PlottableUnderCursor(e.Location); if (plottableUnderCursor != null) { if (e.Button != MouseButtons.None) { OnMouseDragPlottable(EventArgs.Empty); } if (plottableUnderCursor is PlottableAxLine axLine) { if (axLine.vertical == true) { pbPlot.Cursor = Cursors.SizeWE; } else { pbPlot.Cursor = Cursors.SizeNS; } } else { pbPlot.Cursor = Cursors.Arrow; } } if (e.Button != MouseButtons.None) { bool skipIfBusy = true; if (e.Button == MouseButtons.Middle) { skipIfBusy = false; } Render(skipIfCurrentlyRendering: skipIfBusy, lowQuality: plt.mouseTracker.lowQualityWhileInteracting); OnMouseDragged(EventArgs.Empty); } }
public void MouseDown(Point eLocation) { plottableBeingDragged = PlottableUnderCursor(eLocation); if (plottableBeingDragged == null) { mouseDownStopwatch.Restart(); if ((Control.MouseButtons == MouseButtons.Left) && (enablePanning)) { settings.MouseDown(Cursor.Position.X, Cursor.Position.Y, panning: true); } else if ((Control.MouseButtons == MouseButtons.Right) && (enableZooming)) { settings.MouseDown(Cursor.Position.X, Cursor.Position.Y, zooming: true); } } if (Control.MouseButtons == MouseButtons.Middle) { settings.mouse.downMiddle = eLocation; } }
public void MouseUp(Point eLocation) { if (plottableBeingDragged == null) { settings.MouseMoveAxis(Cursor.Position.X, Cursor.Position.Y, ctrlIsDown(), altIsDown()); settings.MouseUpAxis(); } else { PointF newPosition = settings.GetLocation(eLocation.X, eLocation.Y); plottableBeingDragged = null; } if (settings.mouse.rectangleIsHappening) { int[] xs = new int[] { settings.mouse.downMiddle.X, settings.mouse.currentLoc.X }; int[] ys = new int[] { settings.mouse.downMiddle.Y, settings.mouse.currentLoc.Y }; var lowerLeft = settings.GetLocation(xs.Min(), ys.Max()); var upperRight = settings.GetLocation(xs.Max(), ys.Min()); settings.axes.Set(lowerLeft.X, upperRight.X, lowerLeft.Y, upperRight.Y); settings.mouse.rectangleIsHappening = false; } }
private static void DrawLegendItemLine(Plottable plottable, Settings settings, Point textLocation, int padding, int stubWidth, float legendFontLineHeight) { Pen pen = new Pen(plottable.color, 1); if (plottable is PlottableAxSpan) { pen.Width = 10; } switch (plottable.lineStyle) { case LineStyle.Solid: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; break; case LineStyle.Dash: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; break; case LineStyle.DashDot: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; break; case LineStyle.DashDotDot: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; break; case LineStyle.Dot: pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; break; } settings.gfxLegend.DrawLine(pen, textLocation.X - padding, textLocation.Y + legendFontLineHeight / 2, textLocation.X - padding - stubWidth, textLocation.Y + legendFontLineHeight / 2); }
private static void DrawLegendItemMarker(Plottable plottable, Settings settings, Point textLocation, int padding, int stubWidth, float legendFontLineHeight) { Brush brushMarker = new SolidBrush(plottable.color); Pen penMarker = new Pen(plottable.color, 1); // dont draw marker if it's not on the plottable if (plottable.markerShape == MarkerShape.none) { return; } if ((plottable is PlottableScatter) && (((PlottableScatter)plottable).markerSize) == 0) { return; } if ((plottable is PlottableSignal) && (((PlottableSignal)plottable).markerSize) == 0) { return; } PointF corner1 = new PointF(textLocation.X - stubWidth + settings.legend.font.Size / 4, textLocation.Y + settings.legend.font.Size / 4 * padding); PointF center = new PointF { X = corner1.X + settings.legend.font.Size / 4, Y = corner1.Y + settings.legend.font.Size / 4 }; SizeF bounds = new SizeF(settings.legend.font.Size / 2, settings.legend.font.Size / 2); RectangleF rect = new RectangleF(corner1, bounds); switch (plottable.markerShape) { case MarkerShape.none: //Nothing to do because the Drawline needs to be there for all cases, and it's already there break; case MarkerShape.asterisk: Font drawFontAsterisk = new Font("CourierNew", settings.legend.font.Size); Point markerPositionAsterisk = new Point(textLocation.X - stubWidth, (int)(textLocation.Y + legendFontLineHeight / 4)); settings.gfxLegend.DrawString("*", drawFontAsterisk, brushMarker, markerPositionAsterisk); break; case MarkerShape.cross: Font drawFontCross = new Font("CourierNew", settings.legend.font.Size); Point markerPositionCross = new Point(textLocation.X - stubWidth, (int)(textLocation.Y + legendFontLineHeight / 8)); settings.gfxLegend.DrawString("+", drawFontCross, brushMarker, markerPositionCross); break; case MarkerShape.eks: Font drawFontEks = new Font("CourierNew", settings.legend.font.Size); Point markerPositionEks = new Point(textLocation.X - stubWidth, (int)(textLocation.Y)); settings.gfxLegend.DrawString("x", drawFontEks, brushMarker, markerPositionEks); break; case MarkerShape.filledCircle: settings.gfxLegend.FillEllipse(brushMarker, rect); break; case MarkerShape.filledDiamond: // Create points that define polygon. PointF point1 = new PointF(center.X, center.Y + settings.legend.font.Size / 4); PointF point2 = new PointF(center.X - settings.legend.font.Size / 4, center.Y); PointF point3 = new PointF(center.X, center.Y - settings.legend.font.Size / 4); PointF point4 = new PointF(center.X + settings.legend.font.Size / 4, center.Y); PointF[] curvePoints = { point1, point2, point3, point4 }; //Draw polygon to screen settings.gfxLegend.FillPolygon(brushMarker, curvePoints); break; case MarkerShape.filledSquare: settings.gfxLegend.FillRectangle(brushMarker, rect); break; case MarkerShape.hashTag: Font drawFontHashtag = new Font("CourierNew", settings.legend.font.Size); Point markerPositionHashTag = new Point(textLocation.X - stubWidth, (int)(textLocation.Y + legendFontLineHeight / 8)); settings.gfxLegend.DrawString("#", drawFontHashtag, brushMarker, markerPositionHashTag); break; case MarkerShape.openCircle: settings.gfxLegend.DrawEllipse(penMarker, rect); break; case MarkerShape.openDiamond: // Create points that define polygon. PointF point5 = new PointF(center.X, center.Y + settings.legend.font.Size / 4); PointF point6 = new PointF(center.X - settings.legend.font.Size / 4, center.Y); PointF point7 = new PointF(center.X, center.Y - settings.legend.font.Size / 4); PointF point8 = new PointF(center.X + settings.legend.font.Size / 4, center.Y); PointF[] curvePoints2 = { point5, point6, point7, point8 }; //Draw polygon to screen settings.gfxLegend.DrawPolygon(penMarker, curvePoints2); break; case MarkerShape.openSquare: settings.gfxLegend.DrawRectangle(penMarker, corner1.X, corner1.Y, settings.legend.font.Size / 2, settings.legend.font.Size / 2); break; case MarkerShape.triDown: // Create points that define polygon. PointF point14 = new PointF(center.X, center.Y + settings.legend.font.Size / 2); PointF point15 = new PointF(center.X, center.Y); PointF point16 = new PointF(center.X - settings.legend.font.Size / 2 * (float)0.866, center.Y - settings.legend.font.Size / 2 * (float)0.5); PointF point17 = new PointF(center.X, center.Y); PointF point18 = new PointF(center.X + settings.legend.font.Size / 2 * (float)0.866, center.Y - settings.legend.font.Size / 2 * (float)0.5); PointF[] curvePoints4 = { point17, point14, point15, point16, point17, point18 }; //Draw polygon to screen settings.gfxLegend.DrawPolygon(penMarker, curvePoints4); break; case MarkerShape.triUp: // Create points that define polygon. PointF point9 = new PointF(center.X, center.Y - settings.legend.font.Size / 2); PointF point10 = new PointF(center.X, center.Y); PointF point11 = new PointF(center.X - settings.legend.font.Size / 2 * (float)0.866, center.Y + settings.legend.font.Size / 2 * (float)0.5); PointF point12 = new PointF(center.X, center.Y); PointF point13 = new PointF(center.X + settings.legend.font.Size / 2 * (float)0.866, center.Y + settings.legend.font.Size / 2 * (float)0.5); PointF[] curvePoints3 = { point12, point9, point10, point11, point12, point13 }; //Draw polygon to screen settings.gfxLegend.DrawPolygon(penMarker, curvePoints3); break; case MarkerShape.verticalBar: Font drawFontVertical = new Font("CourierNew", settings.legend.font.Size); Point markerPositionVertical = new Point(textLocation.X - stubWidth, (int)(textLocation.Y)); settings.gfxLegend.DrawString("|", drawFontVertical, brushMarker, markerPositionVertical); break; } }
private static void DrawLegendItemString(Plottable plottable, Settings settings, Point textLocation, int padding, int stubWidth, float legendFontLineHeight) { Brush brushText = new SolidBrush(settings.legendFontColor); settings.gfxData.DrawString(plottable.label, settings.legendFont, brushText, textLocation); }
public void Add(Plottable plottable) { settings.plottables.Add(plottable); }
/// <summary> /// Remove the given plottable from the plot /// </summary> public void Remove(Plottable plottable) { settings.plottables.Remove(plottable); }