public static PlotModel AddAnnotations() { var model = new PlotModel { Title = "Add arrow annotations", Subtitle = "Press and drag the left mouse button" }; var xaxis = new LinearAxis { Position = AxisPosition.Bottom }; var yaxis = new LinearAxis { Position = AxisPosition.Left }; model.Axes.Add(xaxis); model.Axes.Add(yaxis); model.Series.Add(new FunctionSeries(x => Math.Sin(x / 4) * Math.Acos(Math.Sin(x)), 0, Math.PI * 8, 2000, "sin(x/4)*acos(sin(x))")); ArrowAnnotation tmp = null; // Add handlers to the PlotModel's mouse events model.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { // Create a new arrow annotation tmp = new ArrowAnnotation(); tmp.StartPoint = tmp.EndPoint = xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis); model.Annotations.Add(tmp); e.Handled = true; } }; // Handle mouse movements (note: this is only called when the mousedown event was handled) model.MouseMove += (s, e) => { if (tmp != null) { // Modify the end point tmp.EndPoint = xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis); tmp.Text = string.Format("Y = {0:0.###}", tmp.EndPoint.Y); // Redraw the plot model.InvalidatePlot(false); e.Handled = true; } }; model.MouseUp += (s, e) => { if (tmp != null) { tmp = null; e.Handled = true; } }; return(model); }
public static PlotModel MouseEvents() { var model = new PlotModel { Title = "Mouse events", Subtitle = "Left click and drag" }; var yaxis = new LinearAxis { Position = AxisPosition.Left, Minimum = -1, Maximum = 1 }; var xaxis = new LinearAxis { Position = AxisPosition.Bottom, Minimum = -1, Maximum = 1 }; model.Axes.Add(yaxis); model.Axes.Add(xaxis); LineSeries s1 = null; // Subscribe to the mouse down event on the line series model.MouseDown += (s, e) => { // only handle the left mouse button (right button can still be used to pan) if (e.ChangedButton == OxyMouseButton.Left) { // Add a line series s1 = new LineSeries { Title = "LineSeries" + (model.Series.Count + 1), MarkerType = MarkerType.None, StrokeThickness = 2 }; s1.Points.Add(xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis)); model.Series.Add(s1); model.InvalidatePlot(false); e.Handled = true; } }; model.MouseMove += (s, e) => { if (s1 != null) { s1.Points.Add(xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis)); model.InvalidatePlot(false); e.Handled = true; } }; model.MouseUp += (s, e) => { if (s1 != null) { s1 = null; e.Handled = true; } }; return(model); }
private void myModel_MouseDown(object sender, OxyMouseDownEventArgs ex) { if (StartROISet && ex.ChangedButton == OxyMouseButton.Left) { PlotMouseDown = true; double dataTmp = xValueAxis.InverseTransform(ex.Position.X); if (ROIState == 0) { ROI1.Points.Add(new DataPoint(dataTmp, -100000)); ROI1.Points.Add(new DataPoint(dataTmp, 100000)); ROIX[0] = dataTmp; ROI1.Color = OxyColors.Gray; ROI1.StrokeThickness = 0.5; myModel.InvalidatePlot(true); } else if (ROIState == 1) { ROIX[1] = dataTmp; ROI2.Points.Add(new DataPoint(ROIX[1], -100000)); ROI2.Points.Add(new DataPoint(ROIX[1], 100000)); ROI2.Color = OxyColors.Gray; ROI2.StrokeThickness = 0.5; myModel.InvalidatePlot(true); } else { if (System.Math.Abs(dataTmp - ROIX[0]) < 2) { ROI1.Points.Clear(); ROIX[0] = dataTmp; ROI1.Points.Add(new DataPoint(ROIX[0], -100000)); ROI1.Points.Add(new DataPoint(ROIX[0], 100000)); ROI1.Color = OxyColors.Gray; ROI1.StrokeThickness = 0.5; myModel.InvalidatePlot(true); ROIState = 2; } else if (System.Math.Abs(dataTmp - ROIX[1]) < 2) { ROI2.Points.Clear(); ROIX[1] = dataTmp; ROI2.Points.Add(new DataPoint(ROIX[1], -100000)); ROI2.Points.Add(new DataPoint(ROIX[1], 100000)); ROI2.Color = OxyColors.Gray; ROI2.StrokeThickness = 0.5; myModel.InvalidatePlot(true); ROIState = 3; } } } }
public static PlotModel MouseEvents() { var model = new PlotModel { Title = "Mouse events", Subtitle = "Left click and drag" }; var yaxis = new LinearAxis { Position = AxisPosition.Left, Minimum = -1, Maximum = 1 }; var xaxis = new LinearAxis { Position = AxisPosition.Bottom, Minimum = -1, Maximum = 1 }; model.Axes.Add(yaxis); model.Axes.Add(xaxis); LineSeries s1 = null; // Subscribe to the mouse down event on the line series model.MouseDown += (s, e) => { // only handle the left mouse button (right button can still be used to pan) if (e.ChangedButton == OxyMouseButton.Left) { // Add a line series s1 = new LineSeries { Title = "LineSeries" + (model.Series.Count + 1), MarkerType = MarkerType.None, StrokeThickness = 2 }; s1.Points.Add(xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis)); model.Series.Add(s1); model.InvalidatePlot(false); e.Handled = true; } }; model.MouseMove += (s, e) => { if (s1 != null) { s1.Points.Add(xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis)); model.InvalidatePlot(false); e.Handled = true; } }; model.MouseUp += (s, e) => { if (s1 != null) { s1 = null; e.Handled = true; } }; return model; }
public static PlotModel AddAnnotations() { var model = new PlotModel { Title = "Add arrow annotations", Subtitle = "Press and drag the left mouse button" }; var xaxis = new LinearAxis { Position = AxisPosition.Bottom }; var yaxis = new LinearAxis { Position = AxisPosition.Left }; model.Axes.Add(xaxis); model.Axes.Add(yaxis); model.Series.Add(new FunctionSeries(x => Math.Sin(x / 4) * Math.Acos(Math.Sin(x)), 0, Math.PI * 8, 2000, "sin(x/4)*acos(sin(x))")); ArrowAnnotation tmp = null; // Add handlers to the PlotModel's mouse events model.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { // Create a new arrow annotation tmp = new ArrowAnnotation(); tmp.StartPoint = tmp.EndPoint = xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis); model.Annotations.Add(tmp); e.Handled = true; } }; // Handle mouse movements (note: this is only called when the mousedown event was handled) model.MouseMove += (s, e) => { if (tmp != null) { // Modify the end point tmp.EndPoint = xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis); tmp.Text = string.Format("Y = {0:0.###}", tmp.EndPoint.Y); // Redraw the plot model.InvalidatePlot(false); e.Handled = true; } }; model.MouseUp += (s, e) => { if (tmp != null) { tmp = null; e.Handled = true; } }; return model; }
private void Subscribe(LineSeries series) { EventHandler <OxyMouseEventArgs> MouseDown = (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { series.LineStyle = LineStyle.Dot; PlotModel.RefreshPlot(false); e.Handled = true; } }; EventHandler <OxyMouseEventArgs> MouseUp = (s, e) => { PlotModel.Series.Remove(series); if (InEditMode) { var y = axisY.InverseTransform(e.Position.Y); var x = axisX.InverseTransform(e.Position.X); DrawLines(x, x, y, y); } PlotModel.RefreshPlot(false); e.Handled = true; }; series.MouseDown += MouseDown; series.MouseUp += MouseUp; }
public ViewModelPlot(Func <double, double, double> xt, Func <double, double, double> yt, double gridSpan, int steps, int chunks, int arrows, double arrowSize, bool fromcenter) { PlotModel = new PlotModel { PlotAreaBorderColor = OxyColor.FromRgb(230, 230, 230), }; _xt = xt; _yt = yt; _arrowSize = arrowSize; _chunks = chunks; _arrows = arrows; _gridSpan = gridSpan; axisY = new LinearAxis { MajorGridlineStyle = LineStyle.Solid, MajorGridlineThickness = 0.5, MinorGridlineStyle = LineStyle.Dot, MinorGridlineColor = OxyColor.FromRgb(240, 240, 240), MinimumPadding = 0.05, MaximumPadding = 0.05, Position = AxisPosition.Left, Title = "y", }; axisX = new LinearAxis { MajorGridlineStyle = LineStyle.Solid, MajorGridlineThickness = 0.5, MinorGridlineStyle = LineStyle.Dot, MinorGridlineColor = OxyColor.FromRgb(240, 240, 240), MinimumPadding = 0.05, MaximumPadding = 0.05, Position = AxisPosition.Bottom, Title = "x" }; PlotModel.Axes.Add(axisX); PlotModel.Axes.Add(axisY); PlotModel.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { var y = axisY.InverseTransform(e.Position.Y); var x = axisX.InverseTransform(e.Position.X); DrawLines(x, x, y, y); PlotModel.RefreshPlot(false); e.Handled = true; } }; MakePlot(steps, fromcenter); }