1- /*   
1+ /* 
22 * ScottPlot - a portable C# library to create interactive graphs from X/Y data. 
3-  *   
3+  * 
44 * https://github.com/swharden/ScottPlot 
55 * https://github.com/swharden/Csharp-Data-Visualization 
6-  *   
6+  * 
77 */ 
88
99using  System ; 
1010using  System . Collections . Generic ; 
11- using  System . Linq ; 
12- using  System . Text ; 
13- using  System . Threading . Tasks ; 
1411
1512using  System . Drawing ; 
1613
@@ -19,15 +16,16 @@ namespace drawing
1916    /// <summary> 
2017    /// ScottPlot graphs X/Y data and generates figures as bitmaps. 
2118    /// </summary> 
22-     class  ScottPlot 
19+     internal   class  ScottPlot 
2320    { 
24- 
2521        // figure dimensions 
2622        private  int  figure_width ; 
23+ 
2724        private  int  figure_height ; 
2825
2926        // padding, position, and size of data area 
3027        private  int  data_pad_left ; 
28+ 
3129        private  int  data_pad_top ; 
3230        private  int  data_pad_right ; 
3331        private  int  data_pad_bottom ; 
@@ -44,6 +42,7 @@ class ScottPlot
4442
4543        // figure and data colors 
4644        public  Color  color_figure_background  =  SystemColors . Control ; 
45+ 
4746        public  Color  color_axis_text  =  Color . Black ; 
4847        public  Color  color_data_background  =  Color . White ; 
4948        public  Color  color_data_highlight  =  Color . DarkGray ; 
@@ -52,12 +51,14 @@ class ScottPlot
5251
5352        // axis edges (the initial view of data) 
5453        private  double  axis_X1  =  - 100 ; 
54+ 
5555        private  double  axis_X2  =  100 ; 
5656        private  double  axis_Y1  =  - 100 ; 
5757        private  double  axis_Y2  =  100 ; 
5858
5959        // data limits (how far you can scroll around) 
6060        public  bool  axis_constrain  =  true ; 
61+ 
6162        public  double  axis_limit_X1  =  - 1000 ; 
6263        public  double  axis_limit_X2  =  1000 ; 
6364        public  double  axis_limit_Y1  =  - 1000 ; 
@@ -71,12 +72,14 @@ class ScottPlot
7172
7273        // axis scale 
7374        private  double  pixels_per_unit_X ; 
75+ 
7476        private  double  pixels_per_unit_Y ; 
7577        private  double  units_per_pixel_X ; 
7678        private  double  units_per_pixel_Y ; 
7779
7880        // graphics objects 
7981        private  Bitmap  bitmap ; 
82+ 
8083        private  System . Drawing . Graphics  gfx ; 
8184
8285        /// <summary> 
@@ -105,9 +108,9 @@ public void Pad(int data_pad_left, int data_pad_top, int data_pad_right, int dat
105108            this . data_pad_right  =  data_pad_right ; 
106109            this . data_pad_bottom  =  data_pad_bottom ; 
107110        } 
108-          
111+ 
109112        /// <summary> 
110-         /// Center the data view on a specific (X, Y) point in space.   
113+         /// Center the data view on a specific (X, Y) point in space. 
111114        /// This does not change scale/zoom. 
112115        /// </summary> 
113116        /// <param name="position_units_x">location in graph units</param> 
@@ -133,12 +136,11 @@ public void PanToFrac(double frac_x, double frac_y)
133136
134137            System . Console . WriteLine ( view_width ) ; 
135138
136-             axis_X1  =  frac_x  *  limit_width  +  axis_limit_X1  -  view_width / 2 ; 
137-             axis_X2  =  frac_x  *  limit_width  +  axis_limit_X1  +  view_width / 2 ; 
138-             axis_Y1  =  frac_y  *  limit_height  +  axis_limit_Y1  -  view_height / 2 ; 
139-             axis_Y2  =  frac_y  *  limit_height  +  axis_limit_Y1  +  view_height  / 2 ; 
139+             axis_X1  =  frac_x  *  limit_width  +  axis_limit_X1  -  view_width   /   2 ; 
140+             axis_X2  =  frac_x  *  limit_width  +  axis_limit_X1  +  view_width   /   2 ; 
141+             axis_Y1  =  frac_y  *  limit_height  +  axis_limit_Y1  -  view_height   /   2 ; 
142+             axis_Y2  =  frac_y  *  limit_height  +  axis_limit_Y1  +  view_height  /   2 ; 
140143            Zoom ( ) ; 
141- 
142144        } 
143145
144146        public  void  AxisSet ( double  X1 ,  double  X2 ,  double  Y1 ,  double  Y2 ) 
@@ -169,12 +171,12 @@ public void Pan(double panX = 0, double panY = 0)
169171        /// Call this after panning, even though scale is (1,1). 
170172        /// </summary> 
171173        /// <param name="scale"></param> 
172-         public  void  Zoom ( double  scaleX = 1.0 ,  double  scaleY = 1.0 ) 
174+         public  void  Zoom ( double  scaleX   =   1.0 ,  double  scaleY   =   1.0 ) 
173175        { 
174176            // recalculate the center point (which will not change by zoom) 
175177            axis_center_X  =  ( axis_X2  +  axis_X1 )  /  2 ; 
176178            axis_center_Y  =  ( axis_Y2  +  axis_Y1 )  /  2 ; 
177-              
179+ 
178180            // zoom only if necessary to reduce floating point errors 
179181            if  ( ! ( scaleX  ==  1.0 ) ) 
180182            { 
@@ -189,7 +191,7 @@ public void Zoom(double scaleX=1.0, double scaleY=1.0)
189191                axis_Y1  =  axis_center_Y  -  axis_Y_pad  *  scaleY ; 
190192                axis_Y2  =  axis_center_Y  +  axis_Y_pad  *  scaleY ; 
191193            } 
192-              
194+ 
193195            // limit the axis values constraining them to the field area 
194196            if  ( axis_constrain ) 
195197            { 
@@ -211,7 +213,7 @@ public void Zoom(double scaleX=1.0, double scaleY=1.0)
211213                axis_Y1  =  Math . Max ( axis_Y1 ,  axis_limit_Y1 ) ; 
212214                axis_Y2  =  Math . Min ( axis_Y2 ,  axis_limit_Y2 ) ; 
213215            } 
214-              
216+ 
215217            // recalculate visible fractions (useful for scrollbar widths) 
216218            axis_visible_frac_X  =  ( axis_X2  -  axis_X1 )  /  ( axis_limit_X2  -  axis_limit_X1 ) ; 
217219            axis_visible_frac_Y  =  ( axis_Y2  -  axis_Y1 )  /  ( axis_limit_Y2  -  axis_limit_Y1 ) ; 
@@ -225,7 +227,6 @@ public void Zoom(double scaleX=1.0, double scaleY=1.0)
225227            units_per_pixel_X  =  ( axis_X2  -  axis_X1 )  /  data_width ; 
226228            pixels_per_unit_Y  =  data_height  /  ( axis_Y2  -  axis_Y1 ) ; 
227229            units_per_pixel_Y  =  ( axis_Y2  -  axis_Y1 )  /  data_height ; 
228- 
229230        } 
230231
231232        /// <summary> 
@@ -235,7 +236,6 @@ public void Zoom(double scaleX=1.0, double scaleY=1.0)
235236        /// <param name="figure_height">width (px) of the entire plot image</param> 
236237        public  void  Resize ( int  figure_width ,  int  figure_height ) 
237238        { 
238- 
239239            this . figure_width  =  figure_width ; 
240240            this . figure_height  =  figure_height ; 
241241
@@ -271,7 +271,6 @@ public void ShowInfo()
271271            msg  +=  string . Format ( "\n Vertical Position: {0}" ,  axis_position_frac_Y ) ; 
272272
273273            System . Console . WriteLine ( msg ) ; 
274-             
275274        } 
276275
277276        /// <summary> 
@@ -291,7 +290,7 @@ public Bitmap Render()
291290            // prepare pens 
292291            Pen  penAxis  =  new  Pen ( color_axis_text ) ; 
293292            Pen  penGrid  =  new  Pen ( color_grid ) ; 
294-             penGrid . DashPattern  =  new  float [ ]  { 4 ,  4 } ; 
293+             penGrid . DashPattern  =  new  float [ ]  {   4 ,  4   } ; 
295294
296295            // fill the whole canvas with the default background color 
297296            gfx . Clear ( color_figure_background ) ; 
@@ -300,7 +299,7 @@ public Bitmap Render()
300299            gfx . FillRectangle ( new  SolidBrush ( color_data_background ) ,  data_rectangle ) ; 
301300
302301            // draw a highlight color on the far left 
303-             gfx . FillRectangle ( new  SolidBrush ( color_data_highlight ) ,  new  Rectangle ( 0 ,  0 ,  30 ,  figure_height - data_pad_bottom ) ) ; 
302+             gfx . FillRectangle ( new  SolidBrush ( color_data_highlight ) ,  new  Rectangle ( 0 ,  0 ,  30 ,  figure_height   -   data_pad_bottom ) ) ; 
304303
305304            // vertical axis label (complicated becasue it's rotated) 
306305            string  axis_label_y  =  "Analog Input 0\n (pA)" ; 
@@ -310,18 +309,18 @@ public Bitmap Render()
310309            gfx . ResetTransform ( ) ; 
311310
312311            // title 
313-             gfx . DrawString ( "ScottPlot Does Amazing Things" ,  font_title ,  new  SolidBrush ( color_axis_text ) ,  new  Point ( figure_width  /  2 ,  data_pad_top / 2 - 8 ) ,  string_format_center ) ; 
312+             gfx . DrawString ( "ScottPlot Does Amazing Things" ,  font_title ,  new  SolidBrush ( color_axis_text ) ,  new  Point ( figure_width  /  2 ,  data_pad_top   /   2   -   8 ) ,  string_format_center ) ; 
314313
315314            // horizontal axis label 
316-             gfx . DrawString ( "Time (ms)" ,  font_axis_labels ,  new  SolidBrush ( color_axis_text ) ,  new  Point ( figure_width  /  2 ,  figure_height - data_pad_bottom / 2 ) ,  string_format_center ) ; 
315+             gfx . DrawString ( "Time (ms)" ,  font_axis_labels ,  new  SolidBrush ( color_axis_text ) ,  new  Point ( figure_width  /  2 ,  figure_height   -   data_pad_bottom   /   2 ) ,  string_format_center ) ; 
317316
318317            // horizontal axis 
319318            foreach  ( double  tickValX  in  TickGen ( axis_X1 ,  axis_X2 ,  data_width ) ) 
320319            { 
321-                 int  tickPx  =  ( int ) ( ( tickValX  -  axis_X1 ) * ( double ) this . pixels_per_unit_X ) + data_pos_left ; 
320+                 int  tickPx  =  ( int ) ( ( tickValX  -  axis_X1 )   *   ( double ) this . pixels_per_unit_X )   +   data_pos_left ; 
322321                gfx . DrawLine ( penGrid ,  new  Point ( tickPx ,  data_pos_top ) ,  new  Point ( tickPx ,  data_pos_bottom ) ) ; 
323322                gfx . DrawLine ( penAxis ,  new  Point ( tickPx ,  data_pos_bottom ) ,  new  Point ( tickPx ,  data_pos_bottom  +  3 ) ) ; 
324-                 string  tickLabel  =  TickString ( tickValX ,  this . axis_X2 - this . axis_X1 ) ; 
323+                 string  tickLabel  =  TickString ( tickValX ,  this . axis_X2   -   this . axis_X1 ) ; 
325324                gfx . DrawString ( tickLabel ,  font_axis_labels ,  new  SolidBrush ( color_axis_text ) ,  new  Point ( tickPx ,  data_pos_bottom  +  8 ) ,  string_format_center ) ; 
326325            } 
327326
@@ -330,16 +329,15 @@ public Bitmap Render()
330329            { 
331330                int  tickPx  =  data_pos_bottom  -  ( int ) ( ( tickValY  -  axis_Y1 )  *  ( double ) this . pixels_per_unit_Y ) ; 
332331                gfx . DrawLine ( penGrid ,  new  Point ( data_pos_left ,  tickPx ) ,  new  Point ( data_pos_right ,  tickPx ) ) ; 
333-                 gfx . DrawLine ( penAxis ,  new  Point ( data_pos_left - 3 ,  tickPx ) ,  new  Point ( data_pos_left ,  tickPx ) ) ; 
332+                 gfx . DrawLine ( penAxis ,  new  Point ( data_pos_left   -   3 ,  tickPx ) ,  new  Point ( data_pos_left ,  tickPx ) ) ; 
334333                string  tickLabel  =  TickString ( tickValY ,  this . axis_Y2  -  this . axis_Y1 ) ; 
335-                 gfx . DrawString ( tickLabel ,  font_axis_labels ,  new  SolidBrush ( color_axis_text ) ,  new  Point ( data_pos_left  -  3 ,  tickPx - 8 ) ,  string_format_right ) ; 
334+                 gfx . DrawString ( tickLabel ,  font_axis_labels ,  new  SolidBrush ( color_axis_text ) ,  new  Point ( data_pos_left  -  3 ,  tickPx   -   8 ) ,  string_format_right ) ; 
336335            } 
337336
338337            // draw a black line around the data area 
339338            gfx . DrawRectangle ( penAxis ,  data_pos_left ,  data_pos_top ,  data_width ,  data_height ) ; 
340339
341340            return  this . bitmap ; 
342- 
343341        } 
344342
345343        /// <summary> 
@@ -414,6 +412,5 @@ public double[] TickGen(double axisValueLower, double axisValueUpper, int graphW
414412            } 
415413            return  values . ToArray ( ) ; 
416414        } 
417- 
418415    } 
419- } 
416+ } 
0 commit comments