public Plot2D(InteractivePlotSurface2D plotSurface) { this.plotSurface2D = plotSurface; pen = new Pen (Color.Red, PenWidth); marker = new Marker (Marker.MarkerType.FilledCircle, MarkerSize, Color.Blue); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("DemoLib.Resources.asx_jbh.xml"); ds.ReadXml(file, System.Data.XmlReadMode.ReadSchema); DataTable dt = ds.Tables[0]; // create CandlePlot. CandlePlot cp = new CandlePlot(); cp.DataSource = dt; cp.AbscissaData = "Date"; cp.OpenData = "Open"; cp.LowData = "Low"; cp.HighData = "High"; cp.CloseData = "Close"; cp.BearishColor = Color.Red; cp.BullishColor = Color.Green; cp.StickWidth = 3; cp.Color = Color.DarkBlue; plotSurface.Add(new Grid()); plotSurface.Add(cp); plotSurface.Title = "AU:JBH"; plotSurface.XAxis1.Label = "Date / Time"; plotSurface.YAxis1.Label = "Price [$]"; plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); double[] y = new double[1] { 1.0f }; foreach (object i in Enum.GetValues(typeof(Marker.MarkerType))) { Marker m = new Marker((Marker.MarkerType)Enum.Parse(typeof(Marker.MarkerType), i.ToString()), 8); double[] x = new double[1]; x[0] = (double)m.Type; PointPlot pp = new PointPlot(); pp.OrdinateData = y; pp.AbscissaData = x; pp.Marker = m; pp.Label = m.Type.ToString(); plotSurface.Add(pp); } plotSurface.Title = "Markers"; plotSurface.YAxis1.Label = "Index"; plotSurface.XAxis1.Label = "Marker"; plotSurface.YAxis1.WorldMin = 0.0f; plotSurface.YAxis1.WorldMax = 2.0f; plotSurface.XAxis1.WorldMin -= 1.0f; plotSurface.XAxis1.WorldMax += 1.0f; Legend legend = new Legend(); legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right); legend.VerticalEdgePlacement = Legend.Placement.Outside; legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.XOffset = 5; // note that these numbers can be negative. legend.YOffset = 0; plotSurface.Legend = legend; plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { double[] data = new double[] { 0, 4, 3, 2, 5, 4, 2, 3 }; double[] data2 = new double[] { 5, 2, 4, 1, 2, 1, 5, 3 }; HistogramPlot hp = new HistogramPlot(); hp.OrdinateData = data; hp.RectangleBrush = RectangleBrushes.Horizontal.FaintRedFade; hp.Filled = true; hp.BaseOffset = -0.15; hp.BaseWidth = 0.25f; HistogramPlot hp2 = new HistogramPlot(); hp2.OrdinateData = data2; hp2.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade; hp2.Filled = true; hp2.BaseOffset = 0.15; hp2.BaseWidth = 0.25f; plotSurface.Clear(); plotSurface.Add(hp); plotSurface.Add(hp2); plotSurface.PlotBackBrush = RectangleBrushes.Vertical.FaintBlueFade; plotSurface.Refresh(); }
/// <summary> /// MouseMove method for Guideline /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { Rectangle plotArea = ps.PlotAreaBoundingBoxCache; if (drawPending) { overRuns += 1; return(false); } // note previous guideline ready to erase it Rectangle prevExtent = lineExtent; // Only display guideline when mouse is within the plotArea if (plotArea.Contains(X, Y)) { int h = 1; int w = plotArea.Right - plotArea.Left + 1; lineExtent = new Rectangle(plotArea.X, Y, w, h); drawPending = true; } else { lineExtent = Rectangle.Empty; } ps.QueueDraw(prevExtent); ps.QueueDraw(lineExtent); return(false); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { string myfile = "-1.251382E-3 -1.279191E-3 -7.230207E-4 -8.064462E-4 -5.005528E-4 -5.839783E-4 -1.696318E-3 -1.668509E-3 -3.893189E-4 -4.449358E-4 -1.473850E-3 -1.473850E-3 -1.974403E-3 -1.946594E-3 -2.085637E-3 -2.085637E-3 -1.612892E-3 -1.640701E-3 -1.863169E-3 " + "-1.251382E-3 -1.306999E-3 -6.674037E-4 -8.620631E-4 -4.449358E-4 -6.674037E-4 -1.668509E-4 -1.668509E-3 -3.615103E-4 -5.005528E-4 -5.561698E-5 -1.473850E-3 -4.449358E-4 -1.946594E-3 -6.395953E-4 -2.057828E-3 -1.585084E-3 -1.696318E-3 -1.807552E-3 " + "-1.223573E-3 -1.306999E-3 -6.117867E-4 -9.176802E-4 -3.893189E-4 -7.508292E-4 -1.390424E-4 -1.640701E-3 -3.615103E-4 -5.561698E-4 -5.561698E-5 -1.446041E-3 -4.449358E-4 -1.918786E-3 -6.117867E-4 -2.057828E-3 -1.585084E-3 -1.724126E-3 -1.779743E-3 " + "-1.251382E-3 -1.334807E-3 -5.839783E-4 -9.732971E-4 -3.615103E-4 -8.342547E-4 -1.390424E-4 3.893189E-4 1.751935E-3 2.919891E-3 3.476061E-3 3.031125E-3 1.807552E-3 6.674037E-4 -6.117867E-4 -2.030020E-3 -1.585084E-3 -1.779743E-3 -1.779743E-3 " + "-1.279191E-3 -1.362616E-3 -5.561698E-4 -1.028914E-3 -3.615103E-4 8.620631E-4 2.335913E-3 3.114551E-3 4.087848E-3 5.227996E-3 6.395952E-3 5.700740E-3 4.560592E-3 2.502764E-3 1.362616E-3 -6.117867E-4 -1.585084E-3 -1.807552E-3 -1.751935E-3 " + "-1.306999E-3 -1.390424E-3 -5.561698E-4 -1.056723E-3 1.890977E-3 4.087848E-3 6.117868E-3 9.621738E-3 1.357054E-2 1.721345E-2 1.715784E-2 1.462726E-2 1.059503E-2 6.368144E-3 3.253593E-3 1.279191E-3 6.674037E-4 -1.807552E-3 -1.779743E-3 " + "-1.390424E-3 -1.390424E-3 -5.561698E-4 1.585084E-3 4.560592E-3 8.481589E-3 1.437699E-2 2.155158E-2 2.702985E-2 3.078400E-2 3.134017E-2 2.892083E-2 2.338694E-2 1.446041E-2 6.757463E-3 3.031125E-3 6.674037E-4 -1.807552E-3 -1.807552E-3 " + "-1.446041E-3 -1.362616E-3 1.140148E-3 3.448253E-3 7.647335E-3 1.512782E-2 2.360941E-2 3.125674E-2 3.520555E-2 3.673501E-2 3.692967E-2 3.598418E-2 3.345361E-2 2.466613E-2 1.415452E-2 5.700740E-3 3.114551E-3 8.342547E-5 -1.835360E-3 " + "-1.529467E-3 -1.334807E-3 1.112340E-3 5.367038E-3 1.154052E-2 2.080075E-2 3.011659E-2 3.581733E-2 3.751365E-2 3.676282E-2 3.687406E-2 3.776393E-2 3.598418E-2 3.139579E-2 1.999430E-2 9.315844E-3 3.142359E-3 1.112340E-4 -1.863169E-3 " + "-1.640701E-3 -1.306999E-3 1.084531E-3 6.785271E-3 1.557275E-2 2.410996E-2 3.311991E-2 3.584514E-2 3.748584E-2 3.681844E-2 3.681844E-2 3.776393E-2 3.592857E-2 3.350923E-2 2.177405E-2 1.140148E-2 3.114551E-3 1.112340E-4 -1.890977E-3 " + "-1.696318E-3 -1.251382E-3 1.056723E-3 6.813080E-3 1.557275E-2 2.413777E-2 3.311991E-2 3.756927E-2 3.745804E-2 3.687406E-2 3.676282E-2 3.776393E-2 3.590076E-2 3.350923E-2 2.174624E-2 1.142929E-2 3.114551E-3 1.390424E-4 -1.918786E-3 " + "-1.779743E-3 -1.195765E-3 1.028914E-3 6.785271E-3 1.256944E-2 2.180186E-2 3.039468E-2 3.598418E-2 3.743023E-2 3.695748E-2 3.673501E-2 3.773612E-2 3.587295E-2 2.967166E-2 1.874292E-2 9.593928E-3 3.086742E-3 1.668509E-4 -1.918786E-3 " + "-1.863169E-3 -1.140148E-3 -1.362616E-3 3.058934E-3 7.285824E-3 1.532248E-2 2.472175E-2 3.195195E-2 3.478842E-2 3.701310E-2 3.670720E-2 3.545582E-2 3.220223E-2 2.333132E-2 1.354273E-2 5.978825E-3 1.279191E-3 1.668509E-4 -1.918786E-3 " + "-1.918786E-3 -1.084531E-3 -1.390424E-3 6.674037E-4 3.448253E-3 7.563909E-3 1.596207E-2 2.394311E-2 2.875398E-2 3.103427E-2 3.181291E-2 2.972727E-2 2.363721E-2 1.543371E-2 9.176801E-3 5.978825E-3 1.251382E-3 1.668509E-4 -1.890977E-3 " + "-1.974403E-3 -1.056723E-3 -1.390424E-3 6.674037E-4 1.362616E-3 3.781955E-3 8.036654E-3 1.304218E-2 1.824237E-2 2.127349E-2 2.174624E-2 1.963279E-2 1.573960E-2 1.148491E-2 7.341441E-3 3.197976E-3 -1.446041E-3 -1.557275E-3 -1.835360E-3 " + "-2.030020E-3 -1.056723E-3 -1.334807E-3 -1.084531E-3 -1.279191E-3 1.001106E-3 3.948805E-3 6.674037E-3 9.983247E-3 1.243039E-2 1.426576E-2 1.454384E-2 1.184642E-2 8.787482E-3 4.504975E-3 6.952122E-4 -1.418233E-3 -1.557275E-3 -1.779743E-3 " + "-2.057828E-3 -1.056723E-3 -1.306999E-3 -1.084531E-3 -1.251382E-3 -7.786377E-4 6.395953E-4 2.586189E-3 4.254699E-3 6.117868E-3 7.619526E-3 7.508292E-3 5.951017E-3 3.003317E-3 -9.176802E-4 -1.195765E-3 -1.362616E-3 -1.557275E-3 -1.751935E-3 " + "-2.085637E-3 -1.084531E-3 -1.251382E-3 -1.112340E-3 -1.223573E-3 -7.786377E-4 -8.620631E-4 -3.893189E-4 -4.449358E-4 3.337019E-4 1.167957E-3 9.454886E-4 3.893189E-4 -8.342547E-4 -9.176802E-4 -1.195765E-3 -1.306999E-3 -1.585084E-3 -1.696318E-3 " + "-2.113445E-3 -1.140148E-3 -1.195765E-3 -1.140148E-3 -1.167957E-3 -7.786377E-4 -8.342547E-4 -3.893189E-4 -4.171273E-4 -1.279191E-3 -1.251382E-3 -1.195765E-3 -1.195765E-3 -8.342547E-4 -8.620631E-4 -1.223573E-3 -1.251382E-3 -1.612892E-3 -1.668509E-3"; string[] tokens = myfile.Split(new char[1] { ' ' }); double[,] map = new double[19, 19]; for (int i = 0; i < 19; ++i) { for (int j = 0; j < 19; ++j) { map[i, j] = Convert.ToDouble(tokens[i * 19 + j], new System.Globalization.CultureInfo("en-US")); } } plotSurface.Clear(); plotSurface.Title = "Cathode 11.2 QE Map"; ImagePlot ip = new ImagePlot(map, -9.0f, 1.0f, -9.0f, 1.0f); //ip.Gradient = new StepGradient( StepGradient.Type.Rainbow ); ip.Gradient = new LinearGradient(Color.Gold, Color.Black); plotSurface.Add(ip); plotSurface.XAxis1.Label = "x [mm]"; plotSurface.YAxis1.Label = "y [mm]"; plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; //plotSurface.AddAxesConstraint( new AxesConstraint.AxisPosition( PlotSurface2D.YAxisPosition.Left, 0) ); //plotSurface.AddAxesConstraint( new AxesConstraint.AxisPosition( PlotSurface2D.XAxisPosition.Top, 0.0f) ); //plotSurface.AddAxesConstraint( // new AxesConstraint.YPixelWorldLength(0.1f,PlotSurface2D.XAxisPosition.Bottom) ); //plotSurface.AddAxesConstraint( new AxesConstraint.AspectRatio(1.0,PlotSurface2D.XAxisPosition.Top,PlotSurface2D.YAxisPosition.Left) ); plotSurface.AddInteraction(new PlotSelection()); plotSurface.Refresh(); }
/// <summary> /// MouseLeave method for RubberBand selection /// </summary> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseLeave(InteractivePlotSurface2D ps) { if (selectionActive) { ps.QueueDraw(selection); selectionActive = false; } return(false); }
/// <summary> /// MouseLeave method for Guideline /// </summary> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseLeave(InteractivePlotSurface2D ps) { if (lineExtent != Rectangle.Empty) { // erase previous vertical guideline ps.QueueDraw(lineExtent); } lineExtent = Rectangle.Empty; return(false); }
/// <summary> /// MouseUp method for PlotDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseUp(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { if (dragInitiated_) { lastPoint_ = unset_; dragInitiated_ = false; ps.plotCursor = CursorType.LeftPointer; } return(false); }
/// <summary> /// MouseDown method for AxisDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y">mouse Y position</param> /// <param name="keys">mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseDown(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { // if the mouse is inside the plot area [the tick marks may be here, // and are counted as part of the axis], then don't invoke drag. if (ps.PlotAreaBoundingBoxCache.Contains(X, Y)) { return(false); } if ((keys & Modifier.Button1) != 0) { // see if hit with axis. NB Only one axis object will be returned ArrayList objects = ps.HitTest(new Point(X, Y)); foreach (object o in objects) { if (o is Florence.Axis) { dragging_ = true; axis_ = (Axis)o; if (ps.PhysicalXAxis1Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalXAxis1Cache; ps.plotCursor = CursorType.LeftRight; } else if (ps.PhysicalXAxis2Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalXAxis2Cache; ps.plotCursor = CursorType.LeftRight; } else if (ps.PhysicalYAxis1Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalYAxis1Cache; ps.plotCursor = CursorType.UpDown; } else if (ps.PhysicalYAxis2Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalYAxis2Cache; ps.plotCursor = CursorType.UpDown; } startPoint_ = new Point(X, Y); // don't combine these - Mono lastPoint_ = startPoint_; // bug #475205 prior to 2.4 // evaluate focusRatio about which axis is expanded float x = startPoint_.X - physicalAxis_.PhysicalMin.X; float y = startPoint_.Y - physicalAxis_.PhysicalMin.Y; double r = Math.Sqrt(x * x + y * y); focusRatio_ = r / physicalAxis_.PhysicalLength; return(false); } } } return(false); }
/// <summary> /// MouseDown method for AxisDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y">mouse Y position</param> /// <param name="keys">mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseDown(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { // if the mouse is inside the plot area [the tick marks may be here, // and are counted as part of the axis], then don't invoke drag. if (ps.PlotAreaBoundingBoxCache.Contains(X, Y)) { return false; } if ((keys & Modifier.Button1) != 0) { // see if hit with axis. NB Only one axis object will be returned ArrayList objects = ps.HitTest(new Point(X, Y)); foreach (object o in objects) { if (o is Florence.Axis) { dragging_ = true; axis_ = (Axis)o; if (ps.PhysicalXAxis1Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalXAxis1Cache; ps.plotCursor = CursorType.LeftRight; } else if (ps.PhysicalXAxis2Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalXAxis2Cache; ps.plotCursor = CursorType.LeftRight; } else if (ps.PhysicalYAxis1Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalYAxis1Cache; ps.plotCursor = CursorType.UpDown; } else if (ps.PhysicalYAxis2Cache.Axis == axis_) { physicalAxis_ = ps.PhysicalYAxis2Cache; ps.plotCursor = CursorType.UpDown; } startPoint_ = new Point(X, Y); // don't combine these - Mono lastPoint_ = startPoint_; // bug #475205 prior to 2.4 // evaluate focusRatio about which axis is expanded float x = startPoint_.X - physicalAxis_.PhysicalMin.X; float y = startPoint_.Y - physicalAxis_.PhysicalMin.Y; double r = Math.Sqrt(x * x + y * y); focusRatio_ = r / physicalAxis_.PhysicalLength; return false; } } } return false; }
/// <summary> /// Handler for KeyPress events /// </summary> /// <param name="key">the NPlot key enumeration</param> /// <param name="ps">the InteractivePlotSurface2D</param> /// <returns></returns> public override bool DoKeyPress(Modifier keys, InteractivePlotSurface2D ps) { double factor = Sensitivity; if (((keys & Modifier.Alt) != 0)) { factor *= altFactor; } if ((keys & Modifier.Home) != 0) { ps.SetOriginalDimensions(); return(true); } if ((keys & Modifier.Left) != 0) { ps.CacheAxes(); ps.TranslateXAxes(left * factor); return(true); } if ((keys & Modifier.Right) != 0) { ps.CacheAxes(); ps.TranslateXAxes(right * factor); return(true); } if ((keys & Modifier.Up) != 0) { ps.CacheAxes(); ps.TranslateYAxes(up * factor); return(true); } if ((keys & Modifier.Down) != 0) { ps.CacheAxes(); ps.TranslateYAxes(down * factor); return(true); } if ((keys & Modifier.Plus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomIn * factor, symmetrical); ps.ZoomYAxes(zoomIn * factor, symmetrical); return(true); } if ((keys & Modifier.Minus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomOut * factor, symmetrical); ps.ZoomYAxes(zoomOut * factor, symmetrical); return(true); } return(false); }
/// <summary> /// Mouse Down method for Rubberband selection of plot region /// </summary> public override bool DoMouseDown(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { // Only start selection if mouse is inside plot area (excluding axes) if (ps.PlotAreaBoundingBoxCache.Contains(X, Y)) { selectionActive = true; startPoint.X = X; startPoint.Y = Y; endPoint = startPoint; } return(false); }
/// <summary> /// MouseUp method for AxisDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseUp(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { if (dragging_) { dragging_ = false; axis_ = null; physicalAxis_ = null; lastPoint_ = new Point(); ps.plotCursor = CursorType.LeftPointer; } return(false); }
public PlotSurface2DDemo() { // // Required for Windows Form Designer support // InitializeComponent(); this.plotControl.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom; this.plotSurface = new InteractivePlotSurface2D(); this.plotControl.InteractivePlotSurface2D = this.plotSurface; // List here the plot routines that you want to be accessed PlotRoutines = new IDemo [] { new PlotWave(), new PlotDataSet(), new PlotMockup(), new PlotImage(), new PlotQE(), new PlotMarkers(), new PlotLogAxis(), new PlotLogLog(), new PlotParticles(), new PlotWavelet(), new PlotSincFunction(), new PlotGaussian(), new PlotLabelAxis(), new PlotCircular(), new PlotCandleSimple(), new PlotABC(), }; // setup resize handler that takes care of placement of buttons, and sizing of // plotsurface2D when window is resized. this.Resize += new System.EventHandler(this.ResizeHandler); // set up printer printDocument = new PrintDocument(); printDocument.PrintPage += new PrintPageEventHandler(pd_PrintPage); int id = currentPlot + 1; exampleNumberLabel.Text = "Plot " + id.ToString("0") + "/" + PlotRoutines.Length.ToString("0"); //this.plotSurface.RightMenu = Florence.WinForms.WinFormsPlotSurface2D.DefaultContextMenu; // draw the first plot. currentPlot = -1; SetPlot(0); }
/// <summary> /// MouseMove method for PlotDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { Rectangle area = ps.PlotAreaBoundingBoxCache; // Mouse Left-Button gives Plot Drag, Ctrl.Left-Button Zooms if (((keys & Modifier.Button1) != 0) && dragInitiated_) { ps.CacheAxes(); double dX = X - lastPoint_.X; // distance mouse has moved double dY = Y - lastPoint_.Y; lastPoint_ = new Point(X, Y); if ((keys & Modifier.Control) != 0) { // Axis re-ranging required double factor = Sensitivity; if ((keys & Modifier.Alt) != 0) { factor *= 0.25; // arbitrary change } double xProportion = +dX * factor / area.Width; double yProportion = -dY * factor / area.Height; if (horizontal_) { ps.ZoomXAxes(xProportion, focusX); } if (vertical_) { ps.ZoomYAxes(yProportion, focusY); } } else { // Axis translation required double xShift = -dX / area.Width; double yShift = +dY / area.Height; if (horizontal_) { ps.TranslateXAxes(xShift); } if (vertical_) { ps.TranslateYAxes(yShift); } } return(true); } return(false); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { // this example will in the future demonstrate histogram plots with +- values. // currently not used - histograms don't support this. plotSurface.Clear(); int[] values = { -10, 2, -3, 4, 6, -1, 10, 4, -4, -3 }; HistogramPlot hp = new HistogramPlot(); hp.OrdinateData = values; plotSurface.Add(hp); plotSurface.Refresh(); }
/// <summary> /// Handle KeyReleased for all PlotSurface interactions /// </summary> public bool DoKeyRelease(Modifier keys, InteractivePlotSurface2D ps) { bool modified = false; foreach (Interaction i in interactions) { modified |= i.DoKeyRelease(keys, this); } if (modified) { InteractionOccurred(this); Refresh(); } return(modified); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); // clear everything. reset fonts. remove plot components etc. System.Random r = new Random(); double[] a = new double[100]; double[] b = new double[100]; double mult = 0.00001f; for (int i = 0; i < 100; ++i) { a[i] = ((double)r.Next(1000) / 5000.0f - 0.1f) * mult; if (i == 50) { b[i] = 1.0f * mult; } else { b[i] = (double)Math.Sin((((double)i - 50.0f) / 4.0f)) / (((double)i - 50.0f) / 4.0f); b[i] *= mult; } a[i] += b[i]; } Marker m = new Marker(Marker.MarkerType.Cross1, 6, new Pen(Color.Blue, 2.0F)); PointPlot pp = new PointPlot(m); pp.OrdinateData = a; pp.AbscissaData = new StartStep(-500.0, 10.0); pp.Label = "Random"; plotSurface.Add(pp); LinePlot lp = new LinePlot(); lp.OrdinateData = b; lp.AbscissaData = new StartStep(-500.0, 10.0); lp.Pen = new Pen(Color.Red, 2.0f); plotSurface.Add(lp); plotSurface.Title = "Sinc Function"; plotSurface.YAxis1.Label = "Magnitude"; plotSurface.XAxis1.Label = "Position"; Legend legend = new Legend(); legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left); legend.VerticalEdgePlacement = Legend.Placement.Inside; legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.YOffset = 8; plotSurface.Legend = legend; plotSurface.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top. plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); // Create a new line plot from array data via the ArrayAdapter class. LinePlot lp = new LinePlot(); lp.DataSource = makeDaub(256); lp.Color = Color.Green; lp.Label = "Daubechies Wavelet"; // no legend, but still useful for copy data to clipboard. Grid myGrid = new Grid(); myGrid.VerticalGridType = Grid.GridType.Fine; myGrid.HorizontalGridType = Grid.GridType.Coarse; plotSurface.Add(myGrid); // And add it to the plot surface plotSurface.Add(lp); plotSurface.Title = "Reversed / Upside down Daubechies Wavelet"; // Ok, the above will produce a decent default plot, but we would like to change // some of the Y Axis details. First, we'd like lots of small ticks (10) between // large tick values. Secondly, we'd like to draw a grid for the Y values. To do // this, we create a new LinearAxis (we could also use Label, Log etc). Rather than // starting from scratch, we use the constructor that takes an existing axis and // clones it (values in the superclass Axis only are cloned). PlotSurface2D // automatically determines a suitable axis when we add plots to it (merging // current requirements with old requirements), and we use this as our starting // point. Because we didn't specify which Y Axis we are using when we added the // above line plot (there is one on the left - YAxis1 and one on the right - YAxis2) // PlotSurface2D.Add assumed we were using YAxis1. So, we create a new axis based on // YAxis1, update the details we want, then set the YAxis1 to be our updated one. LinearAxis myAxis = new LinearAxis(plotSurface.YAxis1); myAxis.NumberOfSmallTicks = 2; plotSurface.YAxis1 = myAxis; // We would also like to modify the way in which the X Axis is printed. This time, // we'll just modify the relevant PlotSurface2D Axis directly. plotSurface.XAxis1.WorldMax = 100.0f; plotSurface.PlotBackColor = Color.OldLace; plotSurface.XAxis1.Reversed = true; plotSurface.YAxis1.Reversed = true; // Force a re-draw of the control. plotSurface.Refresh(); }
/// <summary> /// Mouse Scroll (wheel) method for AxisZoom interaction /// </summary> public override bool DoMouseScroll(int X, int Y, int direction, Modifier keys, InteractivePlotSurface2D ps) { // Add timeout into Gtk loop when scroll starts - Omit for now // GLib.Timeout.Add (500, new GLib.TimeoutHandler (zoomTimeout) ); zoomActive = true; surface = ps; double proportion = 0.1 * sensitivity_; // use initial zoom of 10% double focusX = 0.5, focusY = 0.5; // default focus point // Zoom direction is +1 for Up/ZoomIn, or -1 for Down/ZoomOut proportion *= -direction; // delete previous focusPoint drawing - this is all a bit 'tentative' ps.QueueDraw(focusRect); Rectangle area = ps.PlotAreaBoundingBoxCache; if (area.Contains(X, Y)) { p.X = X; p.Y = Y; focusX = (double)(X - area.Left) / (double)area.Width; focusY = (double)(area.Bottom - Y) / (double)area.Height; } // Zoom in/out for all defined axes ps.CacheAxes(); ps.ZoomXAxes(proportion, focusX); ps.ZoomYAxes(proportion, focusY); // Note: r = 16, and Focus extents range from x-2*r-1 to x+2*r+1, y-2*r-1 to y+2*r+1 int x = p.X - 31; int y = p.Y - 31; focusRect = new Rectangle(x, y, 64, 64); // draw new focusRect ps.QueueDraw(focusRect); return(true); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); const int size = 200; float [] xs = new float [size]; float [] ys = new float [size]; for (int i=0; i<size; i++) { xs[i] = (float)Math.Sin((double)i/(double)(size-1)*2.0*Math.PI); ys[i] = (float)Math.Cos((double)i/(double)(size-1)*6.0*Math.PI); } LinePlot lp = new LinePlot(); lp.OrdinateData = ys; lp.AbscissaData = xs; Pen linePen = new Pen( Color.Yellow, 5.0f ); lp.Pen = linePen; plotSurface.Add(lp); plotSurface.Title = "AxisConstraint.EqualScaling in action..."; // Image downloaded from http://squidfingers.com. Thanks! Assembly a = Assembly.GetExecutingAssembly(); System.IO.Stream file = a.GetManifestResourceStream( "DemoLib.Resources.pattern01.jpg" ); System.Drawing.Image im = Image.FromStream( file ); plotSurface.PlotBackImage = new Bitmap( im ); plotSurface.AddAxesConstraint( new AxesConstraint.AspectRatio( 1.0, PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left ) ); plotSurface.XAxis1.WorldMin = plotSurface.YAxis1.WorldMin; plotSurface.XAxis1.WorldMax = plotSurface.YAxis1.WorldMax; plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; plotSurface.AddInteraction(new PlotZoom()); // make sure plot surface colors are as we expect - the wave example changes them. //plotSurface.PlotBackColor = Color.White; plotSurface.XAxis1.Color = Color.Black; plotSurface.YAxis1.Color = Color.Black; plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { //FileStream fs = new FileStream( @"c:\light.wav", System.IO.FileMode.Open ); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("DemoLib.Resources.light.wav"); System.Int16[] w = new short[5000]; byte[] a = new byte[10000]; file.Read(a, 0, 10000); for (int i = 100; i < 5000; ++i) { w[i] = BitConverter.ToInt16(a, i * 2); } file.Close(); plotSurface.Clear(); plotSurface.AddInteraction(new VerticalGuideline(Color.Gray)); plotSurface.AddInteraction(new HorizontalGuideline(Color.Gray)); plotSurface.AddInteraction(new PlotDrag(true, true)); plotSurface.AddInteraction(new AxisDrag()); plotSurface.Add(new HorizontalLine(0.0, Color.LightBlue)); StepPlot sp = new StepPlot(); sp.DataSource = w; sp.Color = Color.Yellow; sp.Center = true; plotSurface.Add(sp); plotSurface.YAxis1.FlipTicksLabel = true; plotSurface.OuterBackColor = Color.Black; plotSurface.PlotBackColor = Color.DarkBlue; plotSurface.XAxis1.Color = Color.White; plotSurface.YAxis1.Color = Color.White; plotSurface.Refresh(); }
/// <summary> /// MouseMove method for AxisDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { if (((keys & Modifier.Button1) != 0) && dragging_ && physicalAxis_ != null) { ps.CacheAxes(); float dX = (X - lastPoint_.X); float dY = (Y - lastPoint_.Y); lastPoint_ = new Point(X, Y); // In case the physical axis is not horizontal/vertical, combine dX and dY // in a way which preserves their sign and intuitive axis zoom sense, ie // because the physical origin is top-left, expand with +ve dX, but -ve dY double distance = dX - dY; double proportion = distance * sensitivity_ / physicalAxis_.PhysicalLength; axis_.IncreaseRange(proportion, focusRatio_); return(true); } return(false); }
/// <summary> /// MouseUp method for RubberBand selection /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseUp(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { bool modified = false; // delete previous overlay rectangle ps.QueueDraw(selection); if (selectionActive) { selectionActive = false; Rectangle bounds = ps.PlotAreaBoundingBoxCache; if (!bounds.Contains(endPoint)) { // MouseUp outside plotArea - cancel selection modified = false; } else { ps.CacheAxes(); // Redefine range based on selection. The proportions for // Min and Max do not require Min < Max, since they will // be re-ordered by Axis.DefineRange if necessary double xMin = startPoint.X - bounds.Left; double yMin = bounds.Bottom - startPoint.Y; double xMax = endPoint.X - bounds.Left; double yMax = bounds.Bottom - endPoint.Y; double xMinProp = xMin / bounds.Width; double xMaxProp = xMax / bounds.Width; double yMinProp = yMin / bounds.Height; double yMaxProp = yMax / bounds.Height; ps.DefineXAxes(xMinProp, xMaxProp); ps.DefineYAxes(yMinProp, yMaxProp); modified = true; } } return(modified); }
/// <summary> /// Default constructor. /// </summary> public PlotControl() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // double buffer, and update when resize. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); this.ResizeRedraw = true; this.Surface = null; // Map control events to generic events this.MouseEnter += new EventHandler(WinFormsPlotSurface2D_MouseEnter); this.MouseLeave += new EventHandler(WinFormsPlotSurface2D_MouseLeave); this.MouseDown += new MouseEventHandler(WinFormsPlotSurface2D_MouseDown); this.MouseMove += new MouseEventHandler(WinFormsPlotSurface2D_MouseMove); this.MouseUp += new MouseEventHandler(WinFormsPlotSurface2D_MouseUp); this.MouseWheel += new MouseEventHandler(WinFormsPlotSurface2D_MouseWheel); this.KeyDown += new KeyEventHandler(WinFormsPlotSurface2D_KeyDown); this.KeyUp += new KeyEventHandler(WinFormsPlotSurface2D_KeyUp); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); System.Random r = new Random(); int len = 35; double[] a = new double[len]; double[] b = new double[len]; for (int i = 0; i < len; ++i) { int j = len - 1 - i; a[i] = (double)Math.Exp(-(double)(i - len / 2) * (double)(i - len / 2) / 50.0f); b[i] = a[i] + (r.Next(10) / 50.0f) - 0.05f; if (b[i] < 0.0f) { b[i] = 0; } } HistogramPlot sp = new HistogramPlot(); sp.DataSource = b; sp.Pen = Pens.DarkBlue; sp.Filled = true; sp.RectangleBrush = new RectangleBrushes.HorizontalCenterFade(Color.Lavender, Color.Gold); sp.BaseWidth = 0.5f; sp.Label = "Random Data"; LinePlot lp = new LinePlot(); lp.DataSource = a; lp.Pen = new Pen(Color.Blue, 3.0f); lp.Label = "Gaussian Function"; plotSurface.Add(sp); plotSurface.Add(lp); plotSurface.Legend = new Legend(); plotSurface.YAxis1.WorldMin = 0.0f; plotSurface.Title = "Histogram Plot"; plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); plotSurface.Add(new HorizontalLine(0.0, Color.LightGray)); plotSurface.Add(new VerticalLine(0.0, Color.LightGray)); const int N = 400; const double start = -Math.PI * 7.0; const double end = Math.PI * 7.0; double[] xs = new double[N]; double[] ys = new double[N]; for (int i = 0; i < N; ++i) { double t = ((double)i * (end - start) / (double)N + start); xs[i] = 0.5 * (t - 2.0 * Math.Sin(t)); ys[i] = 2.0 * (1.0 - 2.0 * Math.Cos(t)); } LinePlot lp = new LinePlot(ys, xs); lp.Pen = new Pen(Color.DarkBlue, 2.0f); lp.Label = "Circular Line"; // no legend, but still useful for copy data to clipboard. plotSurface.Add(lp); plotSurface.XAxis1 = new PiAxis(plotSurface.XAxis1); plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; plotSurface.Legend = new Legend(); plotSurface.Legend.AttachTo(PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Right); plotSurface.Legend.HorizontalEdgePlacement = Legend.Placement.Inside; plotSurface.Legend.VerticalEdgePlacement = Legend.Placement.Inside; plotSurface.Legend.XOffset = -10; plotSurface.Legend.YOffset = -10; plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); FilledRegion fr = new FilledRegion( new VerticalLine(1.2), new VerticalLine(2.4)); fr.Brush = Brushes.BlanchedAlmond; plotSurface.Add(fr); // note that arrays can be of any type you like. int[] opens = { 1, 2, 1, 2, 1, 3 }; double[] closes = { 2, 2, 2, 1, 2, 1 }; float[] lows = { 0, 1, 1, 1, 0, 0 }; System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; int[] times = { 0, 1, 2, 3, 4, 5 }; CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; plotSurface.Add(cp); HorizontalLine line = new HorizontalLine(1.2); line.LengthScale = 0.89f; plotSurface.Add(line, -10); VerticalLine line2 = new VerticalLine(1.2); line2.LengthScale = 0.89f; plotSurface.Add(line2); plotSurface.AddInteraction(new PlotZoom()); plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another"; plotSurface.Refresh(); }
/// <summary> /// MouseMove method for Rubberband selection of plot area /// </summary> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { if (((keys & Modifier.Button1) != 0) && selectionActive) { // note last selection rectangle Rectangle lastSelection = selection; Rectangle bounds = ps.PlotAreaBoundingBoxCache; // clip selection rectangle to PlotArea X = Math.Max(X, bounds.Left); X = Math.Min(X, bounds.Right); Y = Math.Max(Y, bounds.Top); Y = Math.Min(Y, bounds.Bottom); endPoint.X = X; endPoint.Y = Y; selection = FromPoints(startPoint, endPoint); ps.QueueDraw(lastSelection); //Console.WriteLine ("Erase: {0} {1} {2} {3} ", lastSelection.X, lastSelection.Y, lastSelection.Width, lastSelection.Height); ps.QueueDraw(selection); } return(false); }
/// <summary> /// MouseDown method for PlotDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseDown(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { // Only start drag if mouse is inside plot area (excluding axes) Rectangle area = ps.PlotAreaBoundingBoxCache; if (area.Contains(X, Y)) { dragInitiated_ = true; lastPoint_ = new Point(X, Y); if (((keys & Modifier.Button1) != 0)) { // Drag if (horizontal_ || vertical_) { ps.plotCursor = CursorType.Hand; } if (((keys & Modifier.Control) != 0)) { // Zoom if (horizontal_) { ps.plotCursor = CursorType.LeftRight; } if (vertical_) { ps.plotCursor = CursorType.UpDown; } if (horizontal_ && vertical_) { ps.plotCursor = CursorType.Zoom; } } } // evaluate focusPoint about which axis is expanded focusX = (double)(X - area.Left) / (double)area.Width; focusY = (double)(area.Bottom - Y) / (double)area.Height; } return(false); }
/// <summary> /// Handler for KeyRelease events /// </summary> /// <param name="key">the NPlot key enumeration</param> /// <param name="ps">the InteractivePlotSurface2D</param> /// <returns></returns> public override bool DoKeyRelease(Modifier keys, InteractivePlotSurface2D ps) { return(false); }
public virtual bool DoKeyRelease(Modifier keys, InteractivePlotSurface2D ps) { return false; }
/// <summary> /// MouseUp method for AxisDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseUp(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { if (dragging_) { dragging_ = false; axis_ = null; physicalAxis_ = null; lastPoint_ = new Point(); ps.plotCursor = CursorType.LeftPointer; } return false; }
/// <summary> /// React to the mouse leaving the plot. /// </summary> /// <param name="ps">The plot surface to act on.</param> /// <returns>True if the plot needs to redraw, false otherwise.</returns> public virtual bool DoMouseLeave(InteractivePlotSurface2D ps) { return(false); }
public virtual bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { return false; }
/// <summary> /// Handle KeyReleased for all PlotSurface interactions /// </summary> public bool DoKeyRelease(Modifier keys, InteractivePlotSurface2D ps) { bool modified = false; foreach (Interaction i in interactions) { modified |= i.DoKeyRelease(keys, this); } if (modified) { InteractionOccurred(this); Refresh(); } return (modified); }
/// <summary> /// MouseMove method for PlotScroll /// </summary> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { zoomActive = false; ps.QueueDraw(focusRect); return(false); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { // first of all, generate some mockup data. DataTable info = new DataTable("Store Information"); info.Columns.Add("Index", typeof(int)); info.Columns.Add("IndexOffsetLeft", typeof(float)); info.Columns.Add("IndexOffsetRight", typeof(float)); info.Columns.Add("StoreName", typeof(string)); info.Columns.Add("BarBase", typeof(float)); info.Columns.Add("StoreGrowth", typeof(float)); info.Columns.Add("AverageGrowth", typeof(float)); info.Columns.Add("ProjectedSales", typeof(float)); float barBase = 185.0f; Random r = new Random(); for (int i = 0; i < 18; ++i) { DataRow row = info.NewRow(); row["Index"] = i; row["IndexOffsetLeft"] = (float)i - 0.1f; row["IndexOffsetRight"] = (float)i + 0.1f; row["StoreName"] = "Store " + (i + 1).ToString(); row["BarBase"] = barBase; row["StoreGrowth"] = barBase + ((r.NextDouble() - 0.1) * 20.0f); row["AverageGrowth"] = barBase + ((r.NextDouble() - 0.1) * 15.0f); row["ProjectedSales"] = barBase + (r.NextDouble() * 15.0f); info.Rows.Add(row); barBase += (float)r.NextDouble() * 4.0f; } plotSurface.Clear(); plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // generate the grid Grid grid = new Grid(); grid.VerticalGridType = Grid.GridType.Coarse; grid.HorizontalGridType = Grid.GridType.None; grid.MajorGridPen = new Pen(Color.Black, 1.0f); plotSurface.Add(grid); // generate the trendline LinePlot trendline = new LinePlot(); trendline.DataSource = info; trendline.AbscissaData = "Index"; trendline.OrdinateData = "BarBase"; trendline.Pen = new Pen(Color.Black, 3.0f); trendline.Label = "Trendline"; plotSurface.Add(trendline); // draw store growth bars BarPlot storeGrowth = new BarPlot(); storeGrowth.DataSource = info; storeGrowth.AbscissaData = "IndexOffsetLeft"; storeGrowth.OrdinateDataTop = "StoreGrowth"; storeGrowth.OrdinateDataBottom = "BarBase"; storeGrowth.Label = "Store Growth"; storeGrowth.FillBrush = Florence.RectangleBrushes.Solid.Black; //storeGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(storeGrowth); // draw average growth bars BarPlot averageGrowth = new BarPlot(); averageGrowth.DataSource = info; averageGrowth.AbscissaData = "IndexOffsetRight"; averageGrowth.OrdinateDataBottom = "BarBase"; averageGrowth.OrdinateDataTop = "AverageGrowth"; averageGrowth.Label = "Average Growth"; averageGrowth.FillBrush = Florence.RectangleBrushes.Solid.Gray; //averageGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(averageGrowth); // generate the projected sales step line. StepPlot projected = new StepPlot(); projected.DataSource = info; projected.AbscissaData = "Index"; projected.OrdinateData = "ProjectedSales"; projected.Pen = new Pen(Color.Orange, 3.0f); projected.HideVerticalSegments = true; projected.Center = true; projected.Label = "Projected Sales"; projected.WidthScale = 0.7f; plotSurface.Add(projected); // generate the minimum target line. HorizontalLine minimumTargetLine = new HorizontalLine(218, new Pen(Color.Green, 3.5f)); minimumTargetLine.Label = "Minimum Target"; minimumTargetLine.LengthScale = 0.98f; minimumTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(minimumTargetLine); // generate the preferred target line. HorizontalLine preferredTargetLine = new HorizontalLine(228, new Pen(Color.Blue, 3.5f)); preferredTargetLine.Label = "Preferred Target"; preferredTargetLine.LengthScale = 0.98f; preferredTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(preferredTargetLine); // make some modifications so that chart matches requirements. // y axis. plotSurface.YAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.YAxis1.TickTextNextToAxis = false; plotSurface.YAxis1.TicksAngle = 3.0f * (float)Math.PI / 2.0f; ((LinearAxis)plotSurface.YAxis1).LargeTickStep = 10.0; ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 0; // x axis plotSurface.XAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.XAxis1.TickTextNextToAxis = false; plotSurface.XAxis1.TicksAngle = (float)Math.PI / 2.0f; LabelAxis la = new LabelAxis(plotSurface.XAxis1); for (int i = 0; i < info.Rows.Count; ++i) { la.AddLabel((string)info.Rows[i]["StoreName"], Convert.ToInt32(info.Rows[i]["Index"])); } la.TicksLabelAngle = (float)90.0f; la.TicksBetweenText = true; plotSurface.XAxis1 = la; plotSurface.XAxis2 = (Axis)plotSurface.XAxis1.Clone(); plotSurface.XAxis2.HideTickText = true; plotSurface.XAxis2.LargeTickSize = 0; Legend l = new Legend(); l.NumberItemsVertically = 2; l.AttachTo(Florence.PlotSurface2D.XAxisPosition.Bottom, Florence.PlotSurface2D.YAxisPosition.Left); l.HorizontalEdgePlacement = Florence.Legend.Placement.Outside; l.VerticalEdgePlacement = Florence.Legend.Placement.Inside; l.XOffset = 5; l.YOffset = 50; l.BorderStyle = Florence.LegendBase.BorderType.Line; plotSurface.Legend = l; plotSurface.Title = "Sales Growth Compared to\n" + "Average Sales Growth by Store Size - Rank Order Low to High"; plotSurface.Refresh(); }
/// <summary> /// MouseMove method for Guideline /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { Rectangle plotArea = ps.PlotAreaBoundingBoxCache; if (drawPending) { overRuns += 1; return false; } // note previous guideline ready to erase it Rectangle prevExtent = lineExtent; // Only display guideline when mouse is within the plotArea if (plotArea.Contains(X, Y)) { int w = 1; int h = plotArea.Bottom - plotArea.Top + 1; lineExtent = new Rectangle(X, plotArea.Top, w, h); drawPending = true; } else { lineExtent = Rectangle.Empty; } ps.QueueDraw(prevExtent); ps.QueueDraw(lineExtent); return false; }
/// <summary> /// MouseLeave method for Guideline /// </summary> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseLeave(InteractivePlotSurface2D ps) { if (lineExtent != Rectangle.Empty) { // erase previous vertical guideline ps.QueueDraw(lineExtent); } lineExtent = Rectangle.Empty; return false; }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); // draw a fine grid. Grid fineGrid = new Grid(); fineGrid.VerticalGridType = Grid.GridType.Fine; fineGrid.HorizontalGridType = Grid.GridType.Fine; plotSurface.Add(fineGrid); const int npt = 101; float[] x = new float[npt]; float[] y = new float[npt]; float step = 0.1f; for (int i = 0; i < npt; ++i) { x[i] = i * step - 5.0f; y[i] = (float)Math.Pow(10.0, x[i]); } float xmin = x[0]; float xmax = x[npt - 1]; float ymin = (float)Math.Pow(10.0, xmin); float ymax = (float)Math.Pow(10.0, xmax); LinePlot lp = new LinePlot(); lp.OrdinateData = y; lp.AbscissaData = x; lp.Pen = new Pen(Color.Red); plotSurface.Add(lp); LogAxis loga = new LogAxis(plotSurface.YAxis1); loga.WorldMin = ymin; loga.WorldMax = ymax; loga.AxisColor = Color.Red; loga.LabelColor = Color.Red; loga.TickTextColor = Color.Red; loga.LargeTickStep = 1.0f; loga.Label = "10^x"; plotSurface.YAxis1 = loga; LinePlot lp1 = new LinePlot(); lp1.OrdinateData = y; lp1.AbscissaData = x; lp1.Pen = new Pen(Color.Blue); plotSurface.Add(lp1, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Right); LinearAxis lin = new LinearAxis(plotSurface.YAxis2); lin.WorldMin = ymin; lin.WorldMax = ymax; lin.AxisColor = Color.Blue; lin.LabelColor = Color.Blue; lin.TickTextColor = Color.Blue; lin.Label = "10^x"; plotSurface.YAxis2 = lin; LinearAxis lx = (LinearAxis)plotSurface.XAxis1; lx.WorldMin = xmin; lx.WorldMax = xmax; lx.Label = "x"; //((LogAxis)plotSurface.YAxis1).LargeTickStep = 2; plotSurface.Title = "Mixed Linear/Log Axes"; //plotSurface.XAxis1.LabelOffset = 20.0f; plotSurface.Refresh(); }
public virtual bool DoMouseLeave(InteractivePlotSurface2D ps) { return false; }
/// <summary> /// React to a mouse button being released. /// </summary> /// <param name="X">X coordinates of the cursor upon mouse up.</param> /// <param name="Y">Y coordinates of the curson upon mouse up.</param> /// <param name="keys">Indication of which mouse button has been pressed, along with which keyboard keys are also depressed.</param> /// <param name="ps">The plot surface to act on.</param> /// <returns>True if the plot needs to redraw, false otherwise.</returns> public virtual bool DoMouseUp(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { return(false); }
/// <summary> /// MouseMove method for AxisDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { if (((keys & Modifier.Button1) != 0) && dragging_ && physicalAxis_ != null) { ps.CacheAxes(); float dX = (X - lastPoint_.X); float dY = (Y - lastPoint_.Y); lastPoint_ = new Point(X, Y); // In case the physical axis is not horizontal/vertical, combine dX and dY // in a way which preserves their sign and intuitive axis zoom sense, ie // because the physical origin is top-left, expand with +ve dX, but -ve dY double distance = dX - dY; double proportion = distance * sensitivity_ / physicalAxis_.PhysicalLength; axis_.IncreaseRange(proportion, focusRatio_); return true; } return false; }
/// <summary> /// Initializes a new instance of the NPlotDemo.PlotSurface2DDemo class. /// </summary> public PlotSurface2DDemo() : base("NPlot Gtk.InteractivePlotSurface2D Demo") { // Initialise Gtk# form InitializeComponent(); // Define array of PlotSamples classes sampleTypes = new Type[] { typeof (PlotWave), typeof (PlotDataSet), typeof (PlotMockup), typeof (PlotImage), typeof (PlotQE), typeof (PlotMarkers), typeof (PlotLogAxis), typeof (PlotLogLog), typeof (PlotParticles), typeof (PlotWavelet), typeof (PlotSincFunction), typeof (PlotGaussian), typeof (PlotLabelAxis), typeof (PlotCircular), typeof (PlotCandle), typeof (PlotABC) }; plotSurface = new InteractivePlotSurface2D(); plotWidget.InteractivePlotSurface2D = plotSurface; // set up printer printDocument = new PrintDocument(); printDocument.PrintPage += new PrintPageEventHandler(pd_PrintPage); // draw the first plot sample currentPlot = 0; ShowSample(currentPlot); }
/// <summary> /// React to a key being released. /// </summary> /// <param name="keys">Indication of which keys have been released.</param> /// <param name="ps">The plot surface to act on.</param> /// <returns>True if the plot needs to redraw, false otherwise.</returns> public virtual bool DoKeyRelease(Modifier keys, InteractivePlotSurface2D ps) { return(false); }
public FinancialDemo() { this.volumePS = new InteractivePlotSurface2D(); this.costPS = new InteractivePlotSurface2D(); }
/// <summary> /// Handler for KeyRelease events /// </summary> /// <param name="key">the NPlot key enumeration</param> /// <param name="ps">the InteractivePlotSurface2D</param> /// <returns></returns> public override bool DoKeyRelease(Modifier keys, InteractivePlotSurface2D ps) { return false; }
/// <summary> /// Handler for KeyPress events /// </summary> /// <param name="key">the NPlot key enumeration</param> /// <param name="ps">the InteractivePlotSurface2D</param> /// <returns></returns> public override bool DoKeyPress(Modifier keys, InteractivePlotSurface2D ps) { double factor = Sensitivity; if (((keys & Modifier.Alt) != 0)) { factor *= altFactor; } if ((keys & Modifier.Home) != 0) { ps.SetOriginalDimensions(); return true; } if ((keys & Modifier.Left) != 0) { ps.CacheAxes(); ps.TranslateXAxes(left * factor); return true; } if ((keys & Modifier.Right) != 0) { ps.CacheAxes(); ps.TranslateXAxes(right * factor); return true; } if ((keys & Modifier.Up) != 0) { ps.CacheAxes(); ps.TranslateYAxes(up * factor); return true; } if ((keys & Modifier.Down) != 0) { ps.CacheAxes(); ps.TranslateYAxes(down * factor); return true; } if ((keys & Modifier.Plus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomIn * factor, symmetrical); ps.ZoomYAxes(zoomIn * factor, symmetrical); return true; } if ((keys & Modifier.Minus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomOut * factor, symmetrical); ps.ZoomYAxes(zoomOut * factor, symmetrical); return true; } return false; }
/// <summary> /// React to mouse scrolling. /// </summary> /// <param name="X">X coordinates of the cursor.</param> /// <param name="Y">Y coordinates of the cursor.</param> /// <param name="direction">Direction of scroll (1 for up, -1 for down).</param> /// <param name="keys">Indication of which mouse buttons and keyboard keys have been pressed.</param> /// <param name="ps">The plot surface to act on.</param> /// <returns>True if the plot needs to redraw, false otherwise.</returns> public virtual bool DoMouseScroll(int X, int Y, int direction, Modifier keys, InteractivePlotSurface2D ps) { return(false); }