MathPlot
mathplot.h
1 // Name: mathplot.cpp
3 // Purpose: Framework for plotting in wxWindows
4 // Original Author: David Schalig
5 // Maintainer: Davide Rondini
6 // Contributors: Jose Luis Blanco, Val Greene, Lionel Reynaud, Dave Nadler, MortenMacFly,
7 // Oskar Waldemarsson (for multi Y axis and corrections)
8 // Created: 21/07/2003
9 // Last edit: 23/11/2025
10 // Copyright: (c) David Schalig, Davide Rondini
11 // Licence: wxWindows licence
13 
14 #ifndef MATHPLOT_H_INCLUDED
15 #define MATHPLOT_H_INCLUDED
16 
17 #define MATHPLOT_MANY_YAXIS
18 
19 
58 //this definition uses windows dll to export function.
59 //WXDLLIMPEXP_MATHPLOT definition definition changed to WXDLLIMPEXP_MATHPLOT
60 //mathplot_EXPORTS will be defined by cmake
61 #ifdef mathplot_EXPORTS
62 #define WXDLLIMPEXP_MATHPLOT WXEXPORT
63 #define WXDLLIMPEXP_DATA_MATHPLOT(type) WXEXPORT type
64 #else // not making DLL
65 #define WXDLLIMPEXP_MATHPLOT
66 #define WXDLLIMPEXP_DATA_MATHPLOT(type) type
67 #endif
68 
69 #if defined(__GNUG__) && !defined(__APPLE__) && !defined(__INTEL_CLANG_COMPILER)
70 #pragma interface "mathplot.h"
71 #endif
72 
73 #include <vector>
74 #include <optional>
75 
76 // #include <wx/wx.h>
77 #include <wx/defs.h>
78 #include <wx/menu.h>
79 #include <wx/scrolwin.h>
80 #include <wx/event.h>
81 #include <wx/dynarray.h>
82 #include <wx/pen.h>
83 #include <wx/dcmemory.h>
84 #include <wx/string.h>
85 #include <wx/print.h>
86 #include <wx/image.h>
87 #include <wx/intl.h>
88 
89 #include <cmath>
90 #include <deque>
91 #include <algorithm>
92 
93 // No, this is supposed to be a build parameter: #define ENABLE_MP_CONFIG
94 #ifdef ENABLE_MP_CONFIG
95  #include "MathPlotConfig.h"
96 #endif // ENABLE_MP_CONFIG
97 
102 // No, this is supposed to be a build parameter: #define ENABLE_MP_NAMESPACE
103 #ifdef ENABLE_MP_NAMESPACE
104  namespace MathPlot {
105 #endif // ENABLE_MP_NAMESPACE
106 
107 #ifdef ENABLE_MP_DEBUG
108 // For memory leak debug
109 #ifdef _WINDOWS
110 #ifdef _DEBUG
111 #include <crtdbg.h>
112 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
113 #else
114 #define DEBUG_NEW new
115 #endif // _DEBUG
116 #endif // _WINDOWS
117 #endif // ENABLE_MP_DEBUG
118 
119 // Separation for axes when set close to border
120 #define X_BORDER_SEPARATION 40
121 #define Y_BORDER_SEPARATION 60
122 
124 #define mpX_LOCALTIME 0x10
125 
126 #define mpX_UTCTIME 0x20
127 #define mpX_RAWTIME mpX_UTCTIME
128 
129 // An epsilon for float comparison to 0
130 #define EPSILON 1e-8
131 #define ISNOTNULL(x) (fabs(x) > EPSILON)
132 
133 // A small extra margin for the plot boundary
134 #define EXTRA_MARGIN 8
135 
136 #define ZOOM_AROUND_CENTER -1
137 
138 //-----------------------------------------------------------------------------
139 // classes
140 //-----------------------------------------------------------------------------
141 
142 class WXDLLIMPEXP_MATHPLOT mpLayer;
143 class WXDLLIMPEXP_MATHPLOT mpFunction;
144 class WXDLLIMPEXP_MATHPLOT mpLine;
145 class WXDLLIMPEXP_MATHPLOT mpHorizontalLine;
146 class WXDLLIMPEXP_MATHPLOT mpVerticalLine;
147 class WXDLLIMPEXP_MATHPLOT mpFX;
148 class WXDLLIMPEXP_MATHPLOT mpFY;
149 class WXDLLIMPEXP_MATHPLOT mpFXY;
150 class WXDLLIMPEXP_MATHPLOT mpFXYVector;
151 class WXDLLIMPEXP_MATHPLOT mpProfile;
152 class WXDLLIMPEXP_MATHPLOT mpChart;
153 class WXDLLIMPEXP_MATHPLOT mpBarChart;
154 class WXDLLIMPEXP_MATHPLOT mpScale;
155 class WXDLLIMPEXP_MATHPLOT mpScaleX;
156 class WXDLLIMPEXP_MATHPLOT mpScaleY;
157 class WXDLLIMPEXP_MATHPLOT mpInfoLayer;
158 class WXDLLIMPEXP_MATHPLOT mpInfoCoords;
159 class WXDLLIMPEXP_MATHPLOT mpInfoLegend;
160 class WXDLLIMPEXP_MATHPLOT mpWindow;
161 class WXDLLIMPEXP_MATHPLOT mpText;
162 class WXDLLIMPEXP_MATHPLOT mpTitle;
163 class WXDLLIMPEXP_MATHPLOT mpPrintout;
164 class WXDLLIMPEXP_MATHPLOT mpMovableObject;
165 class WXDLLIMPEXP_MATHPLOT mpCovarianceEllipse;
166 class WXDLLIMPEXP_MATHPLOT mpPolygon;
167 class WXDLLIMPEXP_MATHPLOT mpBitmapLayer;
168 
169 #ifdef ENABLE_MP_CONFIG
171 #endif // ENABLE_MP_CONFIG
172 
174 typedef union
175 {
176  struct
177  {
178  wxCoord startPx;
179  wxCoord endPx;
180  wxCoord startPy;
181  wxCoord endPy;
182  };
183  struct
184  {
185  wxCoord left;
186  wxCoord top;
187  wxCoord right;
188  wxCoord bottom;
189  };
190  struct
191  {
192  wxCoord x1;
193  wxCoord y1;
194  wxCoord x2;
195  wxCoord y2;
196  };
197  wxCoord tab[4];
198 } mpRect;
199 
205 struct mpRange
206 {
207  double min = 0.0f;
208  double max = 0.0f;
209 
210 #if (defined(__cplusplus) && (__cplusplus > 201703L)) // C++20 or newer
211  bool operator==(const mpRange&) const = default;
212 #else
213  bool operator==(const mpRange& other) const
214  {
215  return min == other.min && max == other.max;
216  }
217 #endif
218 };
219 
226 {
227  mpRange x;
228  std::vector<mpRange> y;
229 
236  mpFloatRect(mpWindow& w);
237 
239  mpFloatRect() = delete;
240 
242  bool PointIsInside(double px, double py, size_t yIndex = 0) const {
243  if(yIndex < y.size())
244  {
245  if( (px < x.min || px > x.max) ||
246  (py < y[yIndex].min || py > y[yIndex].max))
247  {
248  return false;
249  }
250  }
251  else
252  {
253  return false;
254  }
255 
256  return true;
257  }
259  void UpdateBoundingBoxToInclude(double px, double py, size_t yIndex = 0) {
260  assert(yIndex < y.size());
261  if(yIndex < y.size())
262  {
263  if (px < x.min ) x.min = px;
264  else if (px > x.max ) x.max = px;
265  if (py < y[yIndex].min ) y[yIndex].min = py;
266  else if (py > y[yIndex].max ) y[yIndex].max = py;
267  }
268  }
270  void InitializeBoundingBox(double px, double py, size_t yIndex = 0) {
271  assert(yIndex < y.size());
272  if(yIndex < y.size())
273  {
274  x.min = x.max = px;
275  y[yIndex].min = y[yIndex].max = py;
276  }
277  }
279  bool IsNotSet(mpWindow& w) const { const mpFloatRect def(w); return *this==def; }
281 #if (defined(__cplusplus) && (__cplusplus > 201703L)) // C++ > C++17 (MSVC requires <AdditionalOptions>/Zc:__cplusplus</AdditionalOptions>
282  bool operator==(const mpFloatRect&) const = default;
283 #else
284  // We compare with an epsilon precision
285  // NOTE: should be unnecessary as we are looking for any changes; normally this will be an exact match or a real change...
286  bool operator==(const mpFloatRect& rect) const
287  {
288  auto Same = [](double a, double b) {
289  return std::fabs(a - b) < EPSILON;
290  };
291 
292  // Compare scalar members
293  if (!Same(x.min, rect.x.min) || !Same(x.max, rect.x.max))
294  {
295  return false;
296  }
297 
298  // Compare vector sizes
299  if (y.size() != rect.y.size())
300  {
301  return false;
302  }
303 
304  // Compare each Y boundary
305  for (size_t i = 0; i < y.size(); ++i)
306  {
307  if (!Same(y[i].min, rect.y[i].min) ||
308  !Same(y[i].max, rect.y[i].max) )
309  {
310  return false;
311  }
312  }
313 
314  return true;
315  }
316 #endif
317 };
318 
322 enum
323 {
324  mpID_FIT = 2000,
325  mpID_ZOOM_IN,
326  mpID_ZOOM_OUT,
327  mpID_CENTER,
328  mpID_LOCKASPECT,
329  mpID_TOGGLE_GRID,
330  mpID_TOGGLE_COORD,
331  mpID_SCREENSHOT,
332 #ifdef ENABLE_MP_CONFIG
333  mpID_CONFIG,
334 #endif // ENABLE_MP_CONFIG
335  mpID_LOAD_FILE,
336  mpID_HELP_MOUSE,
337  mpID_FULLSCREEN
338 };
339 
341 typedef enum __mp_Location_Type
342 {
343  mpMarginLeftCenter,
344  mpMarginTopLeft,
345  mpMarginTopCenter,
346  mpMarginTopRight,
347  mpMarginRightCenter,
348  mpMarginBottomLeft,
349  mpMarginBottomCenter,
350  mpMarginBottomRight,
351  mpMarginNone,
352  mpCursor // only for mpInfoCoords
353 } mpLocation;
354 
356 typedef enum __XAxis_Align_Type
357 {
358  mpALIGN_BORDER_BOTTOM = 10,
359  mpALIGN_BOTTOM,
360  mpALIGN_CENTERX,
361  mpALIGN_TOP,
362  mpALIGN_BORDER_TOP
363 } mpXAxis_Align;
364 
366 typedef enum __YAxis_Align_Type
367 {
368  mpALIGN_BORDER_LEFT = 20,
369  mpALIGN_LEFT,
370  mpALIGN_CENTERY,
371  mpALIGN_RIGHT,
372  mpALIGN_BORDER_RIGHT
373 } mpYAxis_Align;
374 
376 typedef enum __Plot_Align_Name_Type
377 {
378  mpALIGN_NW = 5,
379  mpALIGN_NE,
380  mpALIGN_SE,
381  mpALIGN_SW
382 } mpPlot_Align;
383 
385 typedef enum __mp_Style_Type
386 {
387  mpLegendLine,
388  mpLegendSquare,
389  mpLegendSymbol
390 } mpLegendStyle;
391 
393 typedef enum __mp_Direction_Type
394 {
395  mpVertical,
396  mpHorizontal
397 } mpLegendDirection;
398 
399 typedef enum __Symbol_Type
400 {
401  mpsNone,
402  mpsCircle,
403  mpsSquare,
404  mpsUpTriangle,
405  mpsDownTriangle,
406  mpsCross,
407  mpsPlus
408 } mpSymbol;
409 
410 //-----------------------------------------------------------------------------
411 // mpLayer sub_type values
412 //-----------------------------------------------------------------------------
413 
415 typedef enum __Info_Type
416 {
417  mpiNone, // never used
418  mpiInfo,
419  mpiCoords,
420  mpiLegend
421 } mpInfoType;
422 
424 typedef enum __Text_Type
425 {
426  mptNone, // never used
427  mptText,
428  mptTitle
429 } mpTextType;
430 
431 typedef enum __Function_Type
432 {
433  mpfNone,
434  mpfFX,
435  mpfFY,
436  mpfFXY,
437  mpfFXYVector,
438  mpfMovable,
439  mpfLine,
440  mpfAllType
441 } mpFunctionType;
442 
443 typedef enum __Scale_Type
444 {
445  mpsScaleNone,
446  mpsScaleX,
447  mpsScaleY,
448  mpsAllType
449 } mpScaleType;
450 
451 typedef enum __Chart_Type
452 {
453  mpcChartNone,
454  mpcBarChart,
455  mpcPieChart,
456  mpcAllType
457 } mpChartType;
458 
459 enum mpMouseButtonAction
460 {
461  mpMouseBoxZoom,
462  mpMouseDragZoom,
463 };
464 
465 //-----------------------------------------------------------------------------
466 // mpLayer
467 //-----------------------------------------------------------------------------
468 
469 typedef enum __mp_Layer_Type
470 {
471  mpLAYER_UNDEF,
472  mpLAYER_AXIS,
473  mpLAYER_PLOT,
474  mpLAYER_INFO,
475  mpLAYER_TEXT,
476  mpLAYER_BITMAP,
477  mpLAYER_LINE,
478  mpLAYER_CHART,
479 } mpLayerType;
480 
486 typedef enum __mp_Layer_ZOrder
487 {
488  mpZIndex_BACKGROUND,
489  mpZIndex_AXIS,
490  mpZIndex_LINE,
491  mpZIndex_PLOT,
492  mpZIndex_CHART,
493  mpZIndex_INFO,
494  mpZIndex_TEXT,
495  mpZIndex_END
496 } mpLayerZOrder;
497 
508 class WXDLLIMPEXP_MATHPLOT mpLayer: public wxObject
509 {
510  public:
511  mpLayer(mpLayerType layerType);
512 
513  virtual ~mpLayer()
514  {
515  ;
516  }
517 
521  {
522  m_win = &w;
523  }
524 
532  virtual bool HasBBox()
533  {
534  return true;
535  }
536 
541  mpLayerType GetLayerType() const
542  {
543  return m_type;
544  }
545 
549  int GetLayerSubType() const
550  {
551  return m_subtype;
552  }
553 
559  virtual bool IsLayerType(mpLayerType typeOfInterest, int *subtype)
560  {
561  *subtype = m_subtype;
562  return (m_type == typeOfInterest);
563  }
564 
568  virtual double GetMinX()
569  {
570  return -1.0;
571  }
572 
576  virtual double GetMaxX()
577  {
578  return 1.0;
579  }
580 
584  virtual double GetMinY()
585  {
586  return -1.0;
587  }
588 
592  virtual double GetMaxY()
593  {
594  return 1.0;
595  }
596 
638  void Plot(wxDC &dc, mpWindow &w);
639 
643  void SetName(const wxString &name)
644  {
645  m_name = name;
646  }
647 
651  const wxString& GetName() const
652  {
653  return m_name;
654  }
655 
659  void SetFont(const wxFont &font)
660  {
661  m_font = font;
662  }
663 
667  const wxFont& GetFont() const
668  {
669  return m_font;
670  }
671 
675  void SetFontColour(const wxColour &colour)
676  {
677  m_fontcolour = colour;
678  }
679 
683  const wxColour& GetFontColour() const
684  {
685  return m_fontcolour;
686  }
687 
691  void SetPen(const wxPen &pen)
692  {
693  m_pen = pen;
694  }
695 
699  const wxPen& GetPen() const
700  {
701  return m_pen;
702  }
703 
706  void SetBrush(const wxBrush &brush)
707  {
708  if (brush == wxNullBrush)
709  m_brush = *wxTRANSPARENT_BRUSH;
710  else
711  m_brush = brush;
712  }
713 
716  const wxBrush& GetBrush() const
717  {
718  return m_brush;
719  }
720 
723  void SetShowName(bool show)
724  {
725  m_showName = show;
726  }
727 
730  inline bool GetShowName() const
731  {
732  return m_showName;
733  }
734 
737  void SetDrawOutsideMargins(bool drawModeOutside)
738  {
739  m_drawOutsideMargins = drawModeOutside;
740  }
741 
745  {
746  return m_drawOutsideMargins;
747  }
748 
753  wxBitmap GetColourSquare(int side = 16);
754 
757  inline bool IsVisible() const
758  {
759  return m_visible;
760  }
761 
764  virtual void SetVisible(bool show)
765  {
766  m_visible = show;
767  }
768 
771  inline bool IsTractable() const
772  {
773  return m_tractable;
774  }
775 
778  virtual void SetTractable(bool track)
779  {
780  m_tractable = track;
781  }
782 
785  void SetAlign(int align)
786  {
787  m_flags = align;
788  }
789 
792  int GetAlign() const
793  {
794  return m_flags;
795  }
796 
799  void SetCanDelete(bool canDelete)
800  {
801  m_CanDelete = canDelete;
802  }
803 
806  bool GetCanDelete(void) const
807  {
808  return m_CanDelete;
809  }
810 
813  mpLayerZOrder GetZIndex(void) const
814  {
815  return m_ZIndex;
816  }
817 
818  protected:
819  const mpLayerType m_type;
821  int m_subtype;
822  wxFont m_font;
823  wxColour m_fontcolour;
824  wxPen m_pen;
825  wxBrush m_brush;
826  wxString m_name;
827  bool m_showName;
829  bool m_visible;
830  bool m_tractable;
831  int m_flags;
833  bool m_CanDelete;
834  mpLayerZOrder m_ZIndex;
835 
838  void UpdateContext(wxDC &dc) const;
839 
844  virtual void DoPlot(wxDC &dc, mpWindow &w) = 0;
845 
849  virtual void DoBeforePlot()
850  {
851  ;
852  }
853 
857  void CheckLog(double *x, double *y, size_t id = 0);
858 
859  private:
860  bool m_busy;
861  mpLayer() = delete; // default ctor not implemented/permitted
862 
863  wxDECLARE_DYNAMIC_CLASS(mpLayer);
864 };
865 
866 //-----------------------------------------------------------------------------
867 // mpInfoLayer
868 //-----------------------------------------------------------------------------
869 
875 class WXDLLIMPEXP_MATHPLOT mpInfoLayer: public mpLayer
876 {
877  public:
879  mpInfoLayer();
880 
885  mpInfoLayer(wxRect rect, const wxBrush &brush = *wxTRANSPARENT_BRUSH, mpLocation location = mpMarginNone);
886 
888  virtual ~mpInfoLayer();
889 
892  virtual void SetVisible(bool show);
893 
898  virtual void UpdateInfo(mpWindow &w, wxEvent &event);
899 
902  virtual bool HasBBox()
903  {
904  return false;
905  }
906 
910  virtual void ErasePlot(wxDC &dc, mpWindow &w);
911 
915  virtual bool Inside(const wxPoint &point);
916 
919  virtual void Move(wxPoint delta);
920 
922  virtual void UpdateReference();
923 
926  wxPoint GetPosition() const
927  {
928  return m_dim.GetPosition();
929  }
930 
933  wxSize GetSize() const
934  {
935  return m_dim.GetSize();
936  }
937 
940  const wxRect& GetRectangle() const
941  {
942  return m_dim;
943  }
944 
947  void SetLocation(mpLocation location)
948  {
949  m_location = location;
950  }
951 
954  mpLocation GetLocation() const
955  {
956  return m_location;
957  }
958 
959  protected:
960  wxRect m_dim;
961  wxRect m_oldDim;
962  wxBitmap* m_info_bmp;
963  wxPoint m_reference;
964  int m_winX, m_winY;
965  mpLocation m_location;
966 
971  virtual void DoPlot(wxDC &dc, mpWindow &w);
972 
975  void SetInfoRectangle(mpWindow &w, int width = 0, int height = 0);
976 
977  wxDECLARE_DYNAMIC_CLASS(mpInfoLayer);
978 };
979 
984 class WXDLLIMPEXP_MATHPLOT mpInfoCoords: public mpInfoLayer
985 {
986  public:
988  mpInfoCoords();
989 
991  mpInfoCoords(mpLocation location);
992 
997  mpInfoCoords(wxRect rect, const wxBrush &brush = *wxTRANSPARENT_BRUSH, mpLocation location = mpMarginNone);
998 
1001  {
1002  ;
1003  }
1004 
1008  virtual void UpdateInfo(mpWindow &w, wxEvent &event);
1009 
1010  virtual void ErasePlot(wxDC &dc, mpWindow &w);
1011 
1014  void SetLabelMode(unsigned int mode, unsigned int time_conv = mpX_RAWTIME)
1015  {
1016  m_labelType = mode;
1017  m_timeConv = time_conv;
1018  }
1019 
1022  void SetSeriesCoord(bool show)
1023  {
1024  m_series_coord = show;
1025  }
1026 
1029  bool IsSeriesCoord() const
1030  {
1031  return m_series_coord;
1032  }
1033 
1039  virtual wxString GetInfoCoordsText(mpWindow &w, double xVal, std::vector<double> yValList);
1040 
1043  void SetPenSeries(const wxPen &pen)
1044  {
1045  m_penSeries = pen;
1046  }
1047 
1048  protected:
1049  wxString m_content;
1050  unsigned int m_labelType;
1051  unsigned int m_timeConv;
1052  wxCoord m_mouseX;
1053  wxCoord m_mouseY;
1054  bool m_series_coord;
1055  wxPen m_penSeries;
1056 
1061  virtual void DoPlot(wxDC &dc, mpWindow &w);
1062 
1063  wxDECLARE_DYNAMIC_CLASS(mpInfoCoords);
1064 };
1065 
1070 class WXDLLIMPEXP_MATHPLOT mpInfoLegend: public mpInfoLayer
1071 {
1072  public:
1074  mpInfoLegend();
1075 
1081  mpInfoLegend(wxRect rect, const wxBrush &brush = *wxWHITE_BRUSH, mpLocation location = mpMarginNone);
1082 
1085 
1088  void SetItemMode(mpLegendStyle mode)
1089  {
1090  m_item_mode = mode;
1091  m_needs_update = true;
1092  }
1093 
1094  mpLegendStyle GetItemMode() const
1095  {
1096  return m_item_mode;
1097  }
1098 
1101  void SetItemDirection(mpLegendDirection mode)
1102  {
1103  m_item_direction = mode;
1104  m_needs_update = true;
1105  }
1106 
1107  mpLegendDirection GetItemDirection() const
1108  {
1109  return m_item_direction;
1110  }
1111 
1112  void SetNeedUpdate()
1113  {
1114  m_needs_update = true;
1115  }
1116 
1118  int GetPointed(mpWindow &w, wxPoint eventPoint);
1119 
1120  protected:
1121  mpLegendStyle m_item_mode;
1122  mpLegendDirection m_item_direction;
1123 
1128  virtual void DoPlot(wxDC &dc, mpWindow &w);
1129 
1130  private:
1132  struct LegendDetail
1133  {
1134  unsigned int layerIdx;
1135  wxCoord legendEnd;
1136  };
1138  std::vector<LegendDetail> m_LegendDetailList;
1139  bool m_needs_update;
1140 
1150  void UpdateBitmap(wxDC &dc, mpWindow &w);
1151 
1152  wxDECLARE_DYNAMIC_CLASS(mpInfoLegend);
1153 };
1154 
1155 //-----------------------------------------------------------------------------
1156 // mpLayer implementations - functions
1157 //-----------------------------------------------------------------------------
1158 
1166 class WXDLLIMPEXP_MATHPLOT mpFunction: public mpLayer
1167 {
1168  public:
1171  mpFunction(mpLayerType layerType = mpLAYER_PLOT, const wxString &name = wxEmptyString, size_t yAxisIndex = 0);
1172 
1176  void SetContinuity(bool continuity)
1177  {
1178  m_continuous = continuity;
1179  }
1180 
1184  bool GetContinuity() const
1185  {
1186  return m_continuous;
1187  }
1188 
1191  void SetStep(unsigned int step)
1192  {
1193  m_step = step;
1194  }
1195 
1198  unsigned int GetStep() const
1199  {
1200  return m_step;
1201  }
1202 
1205  void SetSymbol(mpSymbol symbol)
1206  {
1207  m_symbol = symbol;
1208  }
1209 
1212  mpSymbol GetSymbol() const
1213  {
1214  return m_symbol;
1215  }
1216 
1219  void SetSymbolSize(int size)
1220  {
1221  m_symbolSize = size;
1222  m_symbolSize2 = size / 2;
1223  }
1224 
1227  int GetSymbolSize() const
1228  {
1229  return m_symbolSize;
1230  }
1231 
1235  virtual bool DrawSymbol(wxDC &dc, wxCoord x, wxCoord y);
1236 
1240  size_t GetYAxisIndex() const
1241  {
1242  return m_yAxisIndex;
1243  }
1244 
1248  void SetYAxisIndex(size_t index)
1249  {
1250  m_yAxisIndex = index;
1251  }
1252 
1253  protected:
1255  mpSymbol m_symbol;
1258  unsigned int m_step;
1259  size_t m_yAxisIndex;
1260 
1261  wxDECLARE_DYNAMIC_CLASS(mpFunction);
1262 };
1263 
1266 class WXDLLIMPEXP_MATHPLOT mpLine: public mpFunction
1267 {
1268  public:
1269  mpLine(double value, const wxPen &pen = *wxGREEN_PEN);
1270 
1271  // We don't want to include line (horizontal or vertical) in BBox computation
1272  virtual bool HasBBox() override
1273  {
1274  return false;
1275  }
1276 
1280  double GetValue() const
1281  {
1282  return m_value;
1283  }
1284 
1288  void SetValue(const double value)
1289  {
1290  m_value = value;
1291  }
1292 
1295  bool IsHorizontal(void) const
1296  {
1297  return m_IsHorizontal;
1298  }
1299 
1300  protected:
1301  double m_value;
1302  bool m_IsHorizontal;
1303 
1304  wxDECLARE_DYNAMIC_CLASS(mpLine);
1305 };
1306 
1309 class WXDLLIMPEXP_MATHPLOT mpHorizontalLine: public mpLine
1310 {
1311  public:
1312  mpHorizontalLine(double yvalue, const wxPen &pen = *wxGREEN_PEN, size_t yAxisIndex = 0);
1313 
1317  void SetYValue(const double yvalue)
1318  {
1319  SetValue(yvalue);
1320  }
1321 
1322  protected:
1323 
1324  virtual void DoPlot(wxDC &dc, mpWindow &w);
1325 
1326  wxDECLARE_DYNAMIC_CLASS(mpHorizontalLine);
1327 };
1328 
1331 class WXDLLIMPEXP_MATHPLOT mpVerticalLine: public mpLine
1332 {
1333  public:
1334  mpVerticalLine(double xvalue, const wxPen &pen = *wxGREEN_PEN);
1335 
1339  void SetXValue(const double xvalue)
1340  {
1341  SetValue(xvalue);
1342  }
1343 
1344  protected:
1345 
1346  virtual void DoPlot(wxDC &dc, mpWindow &w);
1347 
1348  wxDECLARE_DYNAMIC_CLASS(mpVerticalLine);
1349 };
1350 
1357 class WXDLLIMPEXP_MATHPLOT mpFX: public mpFunction
1358 {
1359  public:
1363  mpFX(const wxString &name = wxEmptyString, int flags = mpALIGN_RIGHT, size_t yAxisIndex = 0);
1364 
1370  virtual double GetY(double x) = 0;
1371 
1376  double DoGetY(double x);
1377 
1382  void DefineDoGetY(void);
1383 
1384  protected:
1385 
1386  // Pointer function to the appropriate DoGetY function
1387  double (mpFX::*pDoGetY)(double x);
1388 
1393  virtual void DoPlot(wxDC &dc, mpWindow &w);
1394 
1398  double NormalDoGetY(double x);
1399  double LogDoGetY(double x);
1400 
1401  wxDECLARE_DYNAMIC_CLASS(mpFX);
1402 };
1403 
1410 class WXDLLIMPEXP_MATHPLOT mpFY: public mpFunction
1411 {
1412  public:
1416  mpFY(const wxString &name = wxEmptyString, int flags = mpALIGN_TOP, size_t yAxisIndex = 0);
1417 
1423  virtual double GetX(double y) = 0;
1424 
1429  double DoGetX(double y);
1430 
1435  void DefineDoGetX(void);
1436 
1437  protected:
1438 
1439  // Pointer function to the appropriate DoGetX function
1440  double (mpFY::*pDoGetX)(double y);
1441 
1446  virtual void DoPlot(wxDC &dc, mpWindow &w);
1447 
1451  double NormalDoGetX(double y);
1452  double LogDoGetX(double y);
1453 
1454  wxDECLARE_DYNAMIC_CLASS(mpFY);
1455 };
1456 
1466 class WXDLLIMPEXP_MATHPLOT mpFXY: public mpFunction
1467 {
1468  public:
1472  mpFXY(const wxString &name = wxEmptyString, int flags = mpALIGN_NE, bool viewAsBar = false, size_t yAxisIndex = 0);
1473 
1477  virtual void Rewind() = 0;
1478 
1482  virtual void Clear()
1483  {
1484  ;
1485  }
1486 
1490  virtual int GetSize()
1491  {
1492  return 0;
1493  }
1494 
1501  virtual bool GetNextXY(double *x, double *y) = 0;
1502 
1506  bool DoGetNextXY(double *x, double *y);
1507 
1511  void SetViewMode(bool asBar);
1512 
1516  int GetBarWidth(void) const
1517  {
1518  return m_BarWidth;
1519  }
1520 
1524  bool ViewAsBar(void) const
1525  {
1526  return m_ViewAsBar;
1527  }
1528 
1529  protected:
1530 
1531  // Data to calculate label positioning
1532  wxCoord maxDrawX, minDrawX, maxDrawY, minDrawY;
1533 
1534  // Min delta between 2 x coordinate (used for view as bar)
1535  double m_deltaX, m_deltaY;
1536 
1537  // The width of a bar
1538  int m_BarWidth;
1539 
1540  // Plot data as bar graph
1541  bool m_ViewAsBar = false;
1542 
1543  // Can the series be deleted?
1544  bool m_CanDelete = true;
1545 
1550  virtual void DoPlot(wxDC &dc, mpWindow &w);
1551 
1556  void UpdateViewBoundary(wxCoord xnew, wxCoord ynew);
1557 
1558  wxDECLARE_DYNAMIC_CLASS(mpFXY);
1559 };
1560 
1561 //-----------------------------------------------------------------------------
1562 // mpFXYVector - provided by Jose Luis Blanco
1563 //-----------------------------------------------------------------------------
1564 
1584 class WXDLLIMPEXP_MATHPLOT mpFXYVector: public mpFXY
1585 {
1586  public:
1590  mpFXYVector(const wxString &name = wxEmptyString, int flags = mpALIGN_NE, bool viewAsBar = false, size_t yAxisIndex = 0);
1591 
1594  virtual ~mpFXYVector()
1595  {
1596  Clear();
1597  }
1598 
1603  void SetData(const std::vector<double> &xs, const std::vector<double> &ys);
1604 
1608  void Clear();
1609 
1614  virtual int GetSize()
1615  {
1616  return m_xs.size();
1617  }
1618 
1626  bool AddData(const double x, const double y, bool updatePlot);
1627 
1633  void SetReserve(int reserve)
1634  {
1635  m_reserveXY = reserve;
1636  m_xs.reserve(m_reserveXY);
1637  m_ys.reserve(m_reserveXY);
1638  }
1639 
1642  int GetReserve() const
1643  {
1644  return m_reserveXY;
1645  }
1646 
1647  protected:
1650  std::vector<double> m_xs, m_ys;
1651 
1655 
1658  size_t m_index;
1659 
1662  double m_minX, m_maxX, m_minY, m_maxY, m_lastX, m_lastY;
1663 
1667  inline void Rewind()
1668  {
1669  m_index = 0;
1670  }
1671 
1677  virtual bool GetNextXY(double *x, double *y);
1678 
1681  void DrawAddedPoint(double x, double y);
1682 
1685  virtual double GetMinX()
1686  {
1687  if(m_ViewAsBar)
1688  {
1689  // Make extra space for outer bars
1690  return m_minX - (m_deltaX / 2);
1691  }
1692  else
1693  {
1694  return m_minX;
1695  }
1696  }
1697 
1700  virtual double GetMinY()
1701  {
1702  return m_minY;
1703  }
1704 
1707  virtual double GetMaxX()
1708  {
1709  if(m_ViewAsBar)
1710  {
1711  // Make extra space for outer bars
1712  return m_maxX + (m_deltaX / 2);
1713  }
1714  else
1715  {
1716  return m_maxX;
1717  }
1718  }
1719 
1722  virtual double GetMaxY()
1723  {
1724  return m_maxY;
1725  }
1726 
1727  private:
1730  void First_Point(double x, double y);
1731 
1734  void Check_Limit(double val, double *min, double *max, double *last, double *delta);
1735 
1736  wxDECLARE_DYNAMIC_CLASS(mpFXYVector);
1737 };
1738 
1747 class WXDLLIMPEXP_MATHPLOT mpProfile: public mpFunction
1748 {
1749  public:
1753  mpProfile(const wxString &name = wxEmptyString, int flags = mpALIGN_TOP);
1754 
1760  virtual double GetY(double x) = 0;
1761 
1762  protected:
1763 
1768  virtual void DoPlot(wxDC &dc, mpWindow &w);
1769 
1770  wxDECLARE_DYNAMIC_CLASS(mpProfile);
1771 };
1772 
1773 //-----------------------------------------------------------------------------
1774 // mpChart
1775 //-----------------------------------------------------------------------------
1778 class WXDLLIMPEXP_MATHPLOT mpChart: public mpFunction
1779 {
1780  public:
1782  mpChart(const wxString &name = wxEmptyString);
1783 
1786  {
1787  Clear();
1788  }
1789 
1792  void SetChartValues(const std::vector<double> &data);
1793 
1796  void SetChartLabels(const std::vector<std::string> &labelArray);
1797 
1802  void AddData(const double &data, const std::string &label);
1803 
1807  virtual void Clear();
1808 
1809  virtual bool HasBBox()
1810  {
1811  return (values.size() > 0);
1812  }
1813 
1814  protected:
1815  std::vector<double> values;
1816  std::vector<std::string> labels;
1817 
1818  double m_max_value;
1819  double m_total_value;
1820 
1821  wxDECLARE_DYNAMIC_CLASS(mpChart);
1822 };
1823 
1824 //-----------------------------------------------------------------------------
1825 // mpBarChart - provided by Jose Davide Rondini
1826 //-----------------------------------------------------------------------------
1827 /* Defines for bar charts label positioning. */
1828 #define mpBAR_NONE 0
1829 #define mpBAR_AXIS_H 1
1830 #define mpBAR_AXIS_V 2
1831 #define mpBAR_INSIDE 3
1832 #define mpBAR_TOP 4
1833 
1834 
1836 class WXDLLIMPEXP_MATHPLOT mpBarChart: public mpChart
1837 {
1838  public:
1840  mpBarChart(const wxString &name = wxEmptyString, double width = 0.5);
1841 
1844  {
1845  Clear();
1846  }
1847 
1848  void SetBarColour(const wxColour &colour);
1849 
1850  void SetColumnWidth(const double colWidth)
1851  {
1852  m_width = colWidth;
1853  }
1854 
1856  void SetBarLabelPosition(int position);
1857 
1861  virtual double GetMinX();
1862 
1866  virtual double GetMaxX();
1867 
1871  virtual double GetMinY();
1872 
1876  virtual double GetMaxY();
1877 
1878  protected:
1879 
1880  double m_width;
1881  wxColour m_barColour;
1882  int m_labelPos;
1883  double m_labelAngle;
1884 
1889  virtual void DoPlot(wxDC &dc, mpWindow &w);
1890 
1891  wxDECLARE_DYNAMIC_CLASS(mpBarChart);
1892 };
1893 
1898 class WXDLLIMPEXP_MATHPLOT mpPieChart: public mpChart
1899 {
1900  public:
1902  mpPieChart(const wxString &name = wxEmptyString, double radius = 20);
1903 
1906  {
1907  Clear();
1908  colours.clear();
1909  }
1910 
1914  void SetPieColours(const std::vector<wxColour> &colourArray);
1915 
1919  virtual double GetMinX()
1920  {
1921  return -m_radius;
1922  }
1923 
1927  virtual double GetMaxX()
1928  {
1929  return m_radius;
1930  }
1931 
1935  virtual double GetMinY()
1936  {
1937  return -m_radius;
1938  }
1939 
1943  virtual double GetMaxY()
1944  {
1945  return m_radius;
1946  }
1947 
1948  protected:
1949 
1950  double m_radius;
1951  std::vector<wxColour> colours;
1952 
1957  virtual void DoPlot(wxDC &dc, mpWindow &w);
1958 
1959  const wxColour& GetColour(unsigned int id);
1960 
1961  wxDECLARE_DYNAMIC_CLASS(mpBarChart);
1962 };
1963 
1966 //-----------------------------------------------------------------------------
1967 // mpLayer implementations - furniture (scales, ...)
1968 //-----------------------------------------------------------------------------
1975 class WXDLLIMPEXP_MATHPLOT mpScale: public mpLayer
1976 {
1977  public:
1982  mpScale(const wxString &name, int flags, bool grids);
1983 
1987  virtual bool HasBBox()
1988  {
1989  return false;
1990  }
1991 
1994  void ShowTicks(bool ticks)
1995  {
1996  m_ticks = ticks;
1997  }
1998 
2001  bool GetShowTicks() const
2002  {
2003  return m_ticks;
2004  }
2005 
2008  void ShowGrids(bool grids)
2009  {
2010  m_grids = grids;
2011  }
2012 
2015  bool GetShowGrids() const
2016  {
2017  return m_grids;
2018  }
2019 
2022  virtual void SetLabelFormat(const wxString &format)
2023  {
2024  m_labelFormat = format;
2025  }
2026 
2029  const wxString& GetLabelFormat() const
2030  {
2031  return m_labelFormat;
2032  }
2033 
2037  void SetGridPen(const wxPen &pen)
2038  {
2039  m_gridpen = pen;
2040  }
2041 
2045  const wxPen& GetGridPen() const
2046  {
2047  return m_gridpen;
2048  }
2049 
2053  void SetAuto(bool automaticScalingIsEnabled)
2054  {
2055  m_auto = automaticScalingIsEnabled;
2056  }
2057 
2061  bool GetAuto() const
2062  {
2063  return m_auto;
2064  }
2065 
2066  void SetMinScale(double min)
2067  {
2068  m_min = min;
2069  }
2070 
2071  double GetMinScale() const
2072  {
2073  return m_min;
2074  }
2075 
2076  void SetMaxScale(double max)
2077  {
2078  m_max = max;
2079  }
2080 
2081  double GetMaxScale() const
2082  {
2083  return m_max;
2084  }
2085 
2089  virtual bool IsLogAxis()
2090  {
2091  return m_isLog;
2092  }
2093  virtual void SetLogAxis(bool log)
2094  {
2095  m_isLog = log;
2096  }
2097 
2098  protected:
2099  static const wxCoord kTickSize = 4;
2100  static const wxCoord kAxisExtraSpace = 6;
2101 
2102  wxPen m_gridpen;
2103  bool m_ticks;
2104  bool m_grids;
2105  bool m_auto;
2106  double m_min, m_max;
2107  wxString m_labelFormat;
2108  bool m_isLog;
2109 
2110  virtual int GetOrigin(mpWindow &w) = 0;
2111 
2118  double GetStep(double scale, int minLabelSpacing);
2119  virtual void DrawScaleName(wxDC &dc, mpWindow &w, int origin, int labelSize) = 0;
2120 
2121  wxString FormatLogValue(double n);
2122 
2123  wxDECLARE_DYNAMIC_CLASS(mpScale);
2124 };
2125 
2127 #define mpX_NORMAL 0x00
2128 
2130 #define mpX_TIME 0x01
2131 
2132 #define mpX_HOURS 0x02
2133 
2134 #define mpX_DATE 0x03
2135 
2136 #define mpX_DATETIME 0x04
2137 
2138 #define mpX_USER 0x05
2139 
2140 #define mpX_NONE 0x06
2141 
2147 class WXDLLIMPEXP_MATHPLOT mpScaleX: public mpScale
2148 {
2149  public:
2155  mpScaleX(const wxString &name = _T("X"), int flags = mpALIGN_CENTERX, bool grids = false, unsigned int type = mpX_NORMAL) :
2156  mpScale(name, flags, grids)
2157  {
2158  m_subtype = mpsScaleX;
2159  m_labelType = type;
2160  m_timeConv = mpX_RAWTIME;
2161  }
2162 
2163  virtual void SetLabelFormat(const wxString &format)
2164  {
2165  mpScale::SetLabelFormat(format);
2166  m_labelType = mpX_USER;
2167  }
2168 
2171  unsigned int GetLabelMode() const
2172  {
2173  return m_labelType;
2174  }
2175 
2178  void SetLabelMode(unsigned int mode, unsigned int time_conv = mpX_RAWTIME)
2179  {
2180  m_labelType = mode;
2181  m_timeConv = time_conv;
2182  }
2183 
2184  protected:
2185  unsigned int m_labelType;
2186  unsigned int m_timeConv;
2187 
2190  virtual void DoPlot(wxDC &dc, mpWindow &w);
2191 
2197  int GetLabelWidth(double value, wxDC &dc, wxString fmt);
2198 
2199  virtual int GetOrigin(mpWindow &w);
2200  virtual void DrawScaleName(wxDC &dc, mpWindow &w, int origin, int labelSize);
2201  wxString FormatValue(const wxString &fmt, double n);
2202 
2203  wxDECLARE_DYNAMIC_CLASS(mpScaleX);
2204 };
2205 
2212 class WXDLLIMPEXP_MATHPLOT mpScaleY: public mpScale
2213 {
2214  public:
2219  mpScaleY(const wxString &name = _T("Y"), int flags = mpALIGN_CENTERY, bool grids = false, size_t axisIndex = 0) :
2220  mpScale(name, flags, grids)
2221  {
2222  m_subtype = mpsScaleY;
2223  m_axisWidth = Y_BORDER_SEPARATION;
2224  m_axisIndex = axisIndex;
2225  m_xPos = 0;
2226  }
2227 
2230  void UpdateAxisWidth(mpWindow &w);
2231 
2232  size_t GetAxisIndex(void)
2233  {
2234  return m_axisIndex;
2235  }
2236 
2237  int GetAxisWidth()
2238  {
2239  return m_axisWidth;
2240  }
2241 
2242  bool IsLeftAxis()
2243  {
2244  return ((GetAlign() == mpALIGN_BORDER_LEFT) || (GetAlign() == mpALIGN_LEFT));
2245  }
2246 
2247  bool IsRightAxis()
2248  {
2249  return ((GetAlign() == mpALIGN_BORDER_RIGHT) || (GetAlign() == mpALIGN_RIGHT));
2250  }
2251 
2252  bool IsInside(wxCoord xPixel)
2253  {
2254  if( (IsLeftAxis() || IsRightAxis()) && (xPixel >= m_xPos) && (xPixel <= (m_xPos + m_axisWidth)) )
2255  {
2256  return true;
2257  }
2258  return false;
2259  }
2260 
2261  protected:
2262  int m_axisWidth;
2263  size_t m_axisIndex;
2264  int m_xPos;
2265 
2268  virtual void DoPlot(wxDC &dc, mpWindow &w);
2269 
2270  virtual int GetOrigin(mpWindow &w);
2271  wxString GetLabelFormat(mpWindow &w);
2272  int GetLabelWidth(double value, wxDC &dc, wxString fmt);
2273  virtual void DrawScaleName(wxDC &dc, mpWindow &w, int origin, int labelSize);
2274 
2275  wxDECLARE_DYNAMIC_CLASS(mpScaleY);
2276 };
2277 
2278 //-----------------------------------------------------------------------------
2279 // mpWindow
2280 //-----------------------------------------------------------------------------
2281 
2286 #define mpMOUSEMODE_DRAG 0
2287 
2288 #define mpMOUSEMODE_ZOOMBOX 1
2289 
2292 //WX_DECLARE_HASH_MAP( int, mpLayer*, wxIntegerHash, wxIntegerEqual, mpLayerList );
2293 typedef std::deque<mpLayer*> mpLayerList;
2294 
2301 typedef std::function<void(void *Sender, const wxString &classname, bool &cancel)> mpOnDeleteLayer;
2302 
2309 typedef std::function<void(void *Sender, wxMouseEvent &event, bool &cancel)> mpOnUserMouseAction;
2310 
2315 {
2316  public:
2317  mpMagnet()
2318  {
2319  m_IsDrawn = false;
2320  m_rightClick = false;
2321  m_IsWasDrawn = false;
2322  }
2323  ~mpMagnet()
2324  {
2325  ;
2326  }
2327  void UpdateBox(wxCoord left, wxCoord top, wxCoord width, wxCoord height)
2328  {
2329  m_domain = wxRect(left, top, width, height);
2330  m_plot_size = wxRect(left, top, width + left, height + top);
2331  }
2332  void UpdateBox(const wxRect &size)
2333  {
2334  m_domain = size;
2335  m_plot_size = wxRect(size.GetLeft(), size.GetTop(),
2336  size.GetWidth() + size.GetLeft(), size.GetHeight() + size.GetTop());
2337  }
2338  void Plot(wxClientDC &dc, const wxPoint &mousePos);
2339  void ClearPlot(wxClientDC &dc);
2340  void UpdatePlot(wxClientDC &dc, const wxPoint &mousePos);
2341  void SaveDrawState(void)
2342  {
2343  m_IsWasDrawn = m_IsDrawn;
2344  // In any cases, set to false because we erase and repaint all the plot
2345  m_IsDrawn = false;
2346  }
2347 
2348  void SetRightClick(void)
2349  {
2350  m_rightClick = true;
2351  }
2352 
2353  private:
2354  wxRect m_domain;
2355  wxRect m_plot_size;
2356  wxPoint m_mousePosition;
2357  bool m_IsDrawn;
2358  bool m_IsWasDrawn;
2359  bool m_rightClick;
2360  void DrawCross(wxClientDC &dc) const;
2361 };
2362 
2384 class WXDLLIMPEXP_MATHPLOT mpWindow: public wxWindow
2385 {
2386  public:
2387  mpWindow() : m_yAxisDataList(1), m_bound(*this), m_desired(*this), m_lastDesiredReportedBounds(*this)
2388  {
2389  InitParameters();
2390  }
2391 
2392  mpWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
2393  long flags = 0);
2394 
2395  ~mpWindow();
2396 
2400  wxMenu* GetPopupMenu()
2401  {
2402  return &m_popmenu;
2403  }
2404 
2412  bool AddLayer(mpLayer *layer, bool refreshDisplay = true);
2413 
2423  bool DelLayer(mpLayer *layer, bool alsoDeleteObject, bool refreshDisplay = true);
2424 
2429  void DelAllLayers(bool alsoDeleteObject, bool refreshDisplay = true);
2430 
2436  void DelAllPlot(bool alsoDeleteObject, mpFunctionType func = mpfAllType, bool refreshDisplay = true);
2437 
2443  mpLayer* GetLayer(int position);
2444 
2451  mpLayer* GetLayersType(int position, mpLayerType type);
2452 
2458  mpLayer* GetLayerPlot(int position, mpFunctionType func = mpfAllType);
2459 
2462  mpLayer* GetLayerAxis(int position, mpScaleType scale = mpsAllType);
2463 
2468  mpFXYVector* GetXYSeries(unsigned int n, const wxString &name = _T("Serie "), bool create = true);
2469 
2473  mpLayer* GetClosestPlot(wxCoord ix, wxCoord iy, double *xnear, double *ynear);
2474 
2479  mpLayer* GetLayerByName(const wxString &name);
2480 
2485  mpLayer* GetLayerByClassName(const wxString &name);
2486 
2490  void RefreshLegend(void);
2491 
2496  bool IsYAxisUsed(size_t yIndex);
2497 
2501  mpScaleX* GetLayerXAxis();
2502 
2506  mpScaleY* GetLayerYAxis(size_t yIndex);
2507 
2511  void SetScaleX(const double scaleX)
2512  {
2513  if (ISNOTNULL(scaleX))
2514  {
2515  m_scaleX = scaleX;
2516  UpdateDesiredBoundingBox();
2517  }
2518  UpdateAll();
2519  }
2520 
2525  double GetScaleX(void) const
2526  {
2527  return m_scaleX;
2528  }
2529 
2533  void SetScaleY(const double scaleY, size_t yIndex)
2534  {
2535  if (ISNOTNULL(scaleY))
2536  {
2537  m_yAxisDataList[yIndex].m_scaleY = scaleY;
2538  UpdateDesiredBoundingBox();
2539  }
2540  UpdateAll();
2541  }
2542 
2547  double GetScaleY(size_t yIndex = 0) const
2548  {
2549  return m_yAxisDataList[yIndex].m_scaleY;
2550  } // Schaling's method: maybe another method exists with the same name
2551 
2552  [[deprecated("Incomplete, use UpdateBBox instead")]]
2555  void SetBound();
2556 
2559  {
2560  return m_bound;
2561  }
2562 
2566  void SetPosX(const double posX)
2567  {
2568  m_posX = posX;
2569  UpdateDesiredBoundingBox();
2570  UpdateAll();
2571  }
2572 
2577  double GetPosX(void) const
2578  {
2579  return m_posX;
2580  }
2581 
2585  void SetPosY(const std::vector<double>& posYList)
2586  {
2587  for(size_t i = 0; i < m_yAxisDataList.size(); i++)
2588  {
2589  m_yAxisDataList[i].m_posY = posYList[i];
2590  }
2591  UpdateDesiredBoundingBox();
2592  UpdateAll();
2593  }
2594 
2599  double GetPosY(size_t yIndex = 0) const
2600  {
2601  return m_yAxisDataList[yIndex].m_posY;
2602  }
2603 
2604  size_t GetNOfYScales(void) const
2605  {
2606  // Should never be size 0
2607  assert(m_yAxisDataList.size() != 0);
2608  return m_yAxisDataList.size();
2609  }
2610 
2611  std::vector<mpScaleY*> GetYAxisList(void) const
2612  {
2613  return m_YAxisList;
2614  }
2615 
2621  void SetScreen(const int scrX, const int scrY)
2622  {
2623  m_scrX = scrX;
2624  m_scrY = scrY;
2625  m_plotWidth = m_scrX - (m_margin.left + m_margin.right);
2626  m_plotHeight = m_scrY - (m_margin.top + m_margin.bottom);
2627 
2628  m_plotBoundaries.endPx = m_scrX;
2629  m_plotBoundariesMargin.endPx = m_scrX - m_margin.right;
2630  m_plotBoundaries.endPy = m_scrY;
2631  m_plotBoundariesMargin.endPy = m_scrY - m_margin.bottom;
2632 
2633  m_PlotArea = wxRect(m_margin.left - EXTRA_MARGIN, m_margin.top - EXTRA_MARGIN,
2634  m_plotWidth + 2*EXTRA_MARGIN, m_plotHeight + 2*EXTRA_MARGIN);
2635 
2636  m_magnet.UpdateBox(m_PlotArea);
2637  }
2638 
2645  int GetScreenX(void) const
2646  {
2647  return m_scrX;
2648  }
2649 
2656  int GetScreenY(void) const
2657  {
2658  return m_scrY;
2659  }
2660 
2665  void SetPos(const double posX, const std::vector<double>& posYList)
2666  {
2667  m_posX = posX;
2668  for(size_t i = 0; i < m_yAxisDataList.size(); i++)
2669  {
2670  m_yAxisDataList[i].m_posY = posYList[i];
2671  }
2672 
2673  UpdateDesiredBoundingBox();
2674  UpdateAll();
2675  }
2676 
2680  inline double p2x(const wxCoord pixelCoordX) const
2681  {
2682  return m_posX + (pixelCoordX / m_scaleX);
2683  }
2684 
2688  inline double p2y(const wxCoord pixelCoordY, size_t yIndex = 0) const
2689  {
2690  return m_yAxisDataList[yIndex].m_posY - (pixelCoordY / m_yAxisDataList[yIndex].m_scaleY);
2691  }
2692 
2696  inline wxCoord x2p(const double x) const
2697  {
2698  return (wxCoord)((x - m_posX) * m_scaleX);
2699  }
2700 
2704  inline wxCoord y2p(const double y, size_t yIndex = 0) const
2705  {
2706  return (wxCoord)((m_yAxisDataList[yIndex].m_posY - y) * m_yAxisDataList[yIndex].m_scaleY);
2707  }
2708 
2711  void EnableDoubleBuffer(const bool enabled)
2712  {
2713  m_enableDoubleBuffer = enabled;
2714  }
2715 
2718  void EnableMousePanZoom(const bool enabled)
2719  {
2720  m_enableMouseNavigation = enabled;
2721  }
2722 
2728  void LockAspect(bool enable = true);
2729 
2734  inline bool IsAspectLocked() const
2735  {
2736  return m_lockaspect;
2737  }
2738 
2743  inline bool IsRepainting() const
2744  {
2745  return m_repainting;
2746  }
2747 
2752  void Fit();
2753 
2760  void Fit(const mpFloatRect &rect, wxCoord *printSizeX = NULL, wxCoord *printSizeY = NULL);
2761 
2765  void FitX(void);
2766 
2771  void FitY(size_t yIndex);
2772 
2777  void ZoomIn(const wxPoint &centerPoint = wxDefaultPosition);
2778 
2783  void ZoomOut(const wxPoint &centerPoint = wxDefaultPosition);
2784 
2786  void ZoomInX();
2787 
2789  void ZoomOutX();
2790 
2793  void ZoomInY(std::optional<size_t> yIndex = std::nullopt);
2794 
2797  void ZoomOutY(std::optional<size_t> yIndex = std::nullopt);
2798 
2800  void ZoomRect(wxPoint p0, wxPoint p1);
2801 
2803  void UpdateAll();
2804 
2805  // Added methods by Davide Rondini
2806 
2810  unsigned int CountLayers();
2811 
2814  unsigned int CountAllLayers()
2815  {
2816  return (unsigned int)m_layers.size();
2817  }
2818 
2822  unsigned int CountLayersType(mpLayerType type);
2823  unsigned int CountLayersFXYPlot();
2824 
2827  //void PrintGraph(mpPrintout *print);
2828 
2835  {
2836  m_desired.x.min = m_posX + (m_margin.left / m_scaleX);
2837  m_desired.x.max = m_posX + ((m_margin.left + m_plotWidth) / m_scaleX);
2838 
2839  for(size_t i = 0; i < m_desired.y.size(); i++)
2840  {
2841  m_desired.y[i].max = m_yAxisDataList[i].m_posY - (m_margin.top / m_yAxisDataList[i].m_scaleY);
2842  m_desired.y[i].min = m_yAxisDataList[i].m_posY - ((m_margin.top + m_plotHeight) / m_yAxisDataList[i].m_scaleY);
2843  }
2844 
2845  CheckAndReportDesiredBoundsChanges();
2846  }
2847 
2850  mpFloatRect GetDesiredBoundingBox() const { return m_desired; }
2851 
2855  double GetDesiredXmin() const
2856  {
2857  return m_desired.x.min;
2858  }
2859 
2864  double GetDesiredXmax() const
2865  {
2866  return m_desired.x.max;
2867  }
2868 
2873  double GetDesiredYmin(size_t yIndex) const
2874  {
2875  return m_desired.y[yIndex].min;
2876  }
2877 
2882  double GetDesiredYmax(size_t yIndex) const
2883  {
2884  return m_desired.y[yIndex].max;
2885  }
2886 
2889  void GetBoundingBox(double *bbox) const;
2890  mpFloatRect *GetBoundingBox(void)
2891  {
2892  return &m_bound;
2893  }
2894 
2897  void SetMPScrollbars(bool status);
2898 
2901  bool GetMPScrollbars() const
2902  {
2903  return m_enableScrollBars;
2904  }
2905 
2911  bool SaveScreenshot(const wxString &filename, int type = wxBITMAP_TYPE_BMP, wxSize imageSize = wxDefaultSize, bool fit = false);
2912 
2916  wxBitmap* BitmapScreenshot(wxSize imageSize = wxDefaultSize, bool fit = false);
2917 
2921  void ClipboardScreenshot(wxSize imageSize = wxDefaultSize, bool fit = false);
2922 
2927  bool LoadFile(const wxString &filename);
2928 
2932 
2939  void SetMargins(int top, int right, int bottom, int left);
2940 
2943  {
2944  SetMargins(m_marginOuter.top, m_marginOuter.right, m_marginOuter.bottom, m_marginOuter.left);
2945  }
2946 
2948  void SetMarginTop(int top)
2949  {
2950  SetMargins(top, m_marginOuter.right, m_marginOuter.bottom, m_marginOuter.left);
2951  }
2952 
2954  int GetMarginTop() const
2955  {
2956  return m_margin.top;
2957  }
2958 
2960  void SetMarginRight(int right)
2961  {
2962  SetMargins(m_marginOuter.top, right, m_marginOuter.bottom, m_marginOuter.left);
2963  }
2964 
2966  int GetMarginRight() const
2967  {
2968  return m_margin.right;
2969  }
2970 
2973  {
2974  return m_marginOuter.right;
2975  }
2976 
2978  void SetMarginBottom(int bottom)
2979  {
2980  SetMargins(m_marginOuter.top, m_marginOuter.right, bottom, m_marginOuter.left);
2981  }
2982 
2984  int GetMarginBottom() const
2985  {
2986  return m_margin.bottom;
2987  }
2988 
2990  void SetMarginLeft(int left)
2991  {
2992  SetMargins(m_marginOuter.top, m_marginOuter.right, m_marginOuter.bottom, left);
2993  }
2994 
2996  int GetMarginLeft() const
2997  {
2998  return m_margin.left;
2999  }
3000 
3003  {
3004  return m_marginOuter.left;
3005  }
3006 
3008  int GetPlotWidth() const
3009  {
3010  return m_plotWidth;
3011  }
3012 
3014  int GetPlotHeight() const
3015  {
3016  return m_plotHeight;
3017  }
3018 
3020  mpRect GetPlotBoundaries(bool with_margin) const
3021  {
3022  mpRect bond;
3023  if (with_margin)
3024  bond = m_plotBoundariesMargin;
3025  else
3026  bond = m_plotBoundaries;
3027  bond.startPx -= EXTRA_MARGIN;
3028  bond.endPx += EXTRA_MARGIN;
3029  bond.startPy -= EXTRA_MARGIN;
3030  bond.endPy += EXTRA_MARGIN;
3031  return bond;
3032  }
3033 
3037  int GetLeftYAxesWidth(std::optional<size_t> yIndex = std::nullopt);
3038 
3042  int GetRightYAxesWidth(std::optional<size_t> yIndex = std::nullopt);
3043 
3045  void SetDrawBox(bool drawbox)
3046  {
3047  m_drawBox = drawbox;
3048  }
3049 
3051  bool GetDrawBox() const
3052  {
3053  return m_drawBox;
3054  }
3055 
3059  std::optional<size_t> IsInsideYAxis(const wxPoint &point);
3060 
3064  mpInfoLayer* IsInsideInfoLayer(const wxPoint &point);
3065 
3069  void SetLayerVisible(const wxString &name, bool viewable);
3070 
3074  bool IsLayerVisible(const wxString &name);
3075 
3079  bool IsLayerVisible(const unsigned int position);
3080 
3084  void SetLayerVisible(const unsigned int position, bool viewable);
3085 
3090  void SetColourTheme(const wxColour &bgColour, const wxColour &drawColour, const wxColour &axesColour);
3091 
3094  const wxColour& GetAxesColour() const
3095  {
3096  return m_axColour;
3097  }
3098 
3099  const wxColour& GetbgColour() const
3100  {
3101  return m_bgColour;
3102  }
3103 
3104  void SetbgColour(const wxColour &colour)
3105  {
3106  m_bgColour = colour;
3107  }
3108 
3113  void SetOnDeleteLayer(const mpOnDeleteLayer &event)
3114  {
3115  m_OnDeleteLayer = event;
3116  }
3117 
3120  {
3121  m_OnDeleteLayer = NULL;
3122  }
3123 
3128  void SetOnUserMouseAction(const mpOnUserMouseAction &userMouseEventHandler)
3129  {
3130  m_OnUserMouseAction = userMouseEventHandler;
3131  }
3132 
3135  {
3136  m_OnUserMouseAction = NULL;
3137  }
3138 
3144  bool IsLogXaxis()
3145  {
3146  if (m_XAxis)
3147  return m_XAxis->IsLogAxis();
3148  else
3149  return false;
3150  }
3151 
3155  bool IsLogYaxis(size_t yAxisIndex)
3156  {
3157  mpScaleY* yAxis = GetLayerYAxis(yAxisIndex);
3158  if (yAxis)
3159  return yAxis->IsLogAxis();
3160  else
3161  return false;
3162  }
3163 
3164  void SetLogXaxis(bool log)
3165  {
3166  if (m_XAxis)
3167  m_XAxis->SetLogAxis(log);
3168  }
3169 
3173  void SetLogYaxis(size_t yIndex, bool log)
3174  {
3175  mpScaleY* yAxis = GetLayerYAxis(yIndex);
3176  if (yAxis)
3177  yAxis->SetLogAxis(log);
3178  }
3179 
3185  bool GetMagnetize() const
3186  {
3187  return m_magnetize;
3188  }
3189 
3190  void SetMagnetize(bool mag)
3191  {
3192  m_magnetize = mag;
3193  }
3194 
3199  void SetMouseLeftDownAction(mpMouseButtonAction action)
3200  {
3201  m_mouseLeftDownAction = action;
3202  }
3203 
3208  mpMouseButtonAction GetMouseLeftDownAction()
3209  {
3210  return m_mouseLeftDownAction;
3211  }
3212 
3213 #ifdef ENABLE_MP_CONFIG
3214  void RefreshConfigWindow();
3219  MathPlotConfigDialog* GetConfigWindow(bool Create = false);
3220 #endif // ENABLE_MP_CONFIG
3221 
3222  protected:
3223  virtual void OnPaint(wxPaintEvent &event);
3224  virtual void OnSize(wxSizeEvent &event);
3225  virtual void OnShowPopupMenu(wxMouseEvent &event);
3226  virtual void OnCenter(wxCommandEvent &event);
3227  virtual void OnFit(wxCommandEvent &event);
3228  virtual void OnToggleGrids(wxCommandEvent &event);
3229  virtual void OnToggleCoords(wxCommandEvent &event);
3230  virtual void OnScreenShot(wxCommandEvent &event);
3231  virtual void OnFullScreen(wxCommandEvent &event);
3232 #ifdef ENABLE_MP_CONFIG
3233  virtual void OnConfiguration(wxCommandEvent &event);
3234 #endif // ENABLE_MP_CONFIG
3235  virtual void OnLoadFile(wxCommandEvent &event);
3236  virtual void OnZoomIn(wxCommandEvent &event);
3237  virtual void OnZoomOut(wxCommandEvent &event);
3238  virtual void OnLockAspect(wxCommandEvent &event);
3239  virtual void OnMouseHelp(wxCommandEvent &event);
3240  virtual void OnMouseLeftDown(wxMouseEvent &event);
3241  virtual void OnMouseRightDown(wxMouseEvent &event);
3242  virtual void OnMouseMove(wxMouseEvent &event);
3243  virtual void OnMouseLeftRelease(wxMouseEvent &event);
3244  virtual void OnMouseWheel(wxMouseEvent &event);
3245  virtual void OnMouseLeave(wxMouseEvent &event);
3246  bool CheckUserMouseAction(wxMouseEvent &event);
3247  virtual void OnScrollThumbTrack(wxScrollWinEvent &event);
3248  virtual void OnScrollPageUp(wxScrollWinEvent &event);
3249  virtual void OnScrollPageDown(wxScrollWinEvent &event);
3250  virtual void OnScrollLineUp(wxScrollWinEvent &event);
3251  virtual void OnScrollLineDown(wxScrollWinEvent &event);
3252  virtual void OnScrollTop(wxScrollWinEvent &event);
3253  virtual void OnScrollBottom(wxScrollWinEvent &event);
3254 
3255  void DoScrollCalc(const int position, const int orientation);
3256 
3261  void DoZoomXCalc(bool zoomIn, wxCoord staticXpixel = ZOOM_AROUND_CENTER);
3262 
3269  void DoZoomYCalc(bool zoomIn, wxCoord staticYpixel = ZOOM_AROUND_CENTER, std::optional<size_t> = std::nullopt);
3270 
3275  void SetScaleXAndCenter(double scaleX);
3276 
3282  void SetScaleYAndCenter(double scaleYList, size_t yIndex);
3283 
3284  void Zoom(bool zoomIn, const wxPoint &centerPoint);
3285 
3288  virtual bool UpdateBBox();
3289 
3290  void InitParameters();
3291 
3296  void UpdateNOfYAxes(size_t nOfYAxes);
3297 
3298  wxTopLevelWindow* m_parent;
3299  bool m_fullscreen;
3300 
3301  mpLayerList m_layers;
3303  std::vector<mpScaleY*> m_YAxisList;
3304 
3305  wxMenu m_popmenu;
3307  wxColour m_bgColour;
3308  wxColour m_fgColour;
3309  wxColour m_axColour;
3310  bool m_drawBox;
3311 
3312  double m_scaleX;
3313  double m_posX;
3314  struct m_yAxisData
3315  {
3316  double m_scaleY = 1.0;
3317  double m_posY = 0;
3318  };
3319  std::vector<m_yAxisData> m_yAxisDataList;
3320 
3321  int m_scrX;
3322  int m_scrY;
3325 
3328 
3331  wxCoord m_plotWidth;
3332  wxCoord m_plotHeight;
3333 
3336  wxRect m_PlotArea;
3337 
3338  bool m_repainting;
3339  int m_last_lx, m_last_ly;
3340  wxBitmap* m_buff_bmp;
3343  mpMouseButtonAction m_mouseLeftDownAction;
3344  bool m_mouseMovedAfterRightClick;
3345  wxPoint m_mouseRClick;
3346  wxPoint m_mouseLClick;
3347  double m_mouseScaleX;
3348  std::vector<double> m_mouseScaleYList;
3349  std::optional<size_t> m_mouseYAxisIndex;
3350  bool m_enableScrollBars;
3351  int m_scrollX, m_scrollY;
3355  bool m_InInfoLegend;
3356 
3357  wxBitmap* m_zoom_bmp;
3358  wxRect m_zoom_dim;
3359  wxRect m_zoom_oldDim;
3360 
3363 
3364  wxBitmap* m_Screenshot_bmp;
3365 
3366 #ifdef ENABLE_MP_CONFIG
3367  MathPlotConfigDialog* m_configWindow = NULL;
3368 #endif // ENABLE_MP_CONFIG
3369 
3370  mpOnDeleteLayer m_OnDeleteLayer = NULL;
3371  mpOnUserMouseAction m_OnUserMouseAction = NULL;
3372 
3376  virtual void DesiredBoundsHaveChanged() {}; // called from CheckAndReportDesiredBoundsChanges()
3377 
3378  private:
3379  void FillI18NString();
3380 
3381  void CheckAndReportDesiredBoundsChanges();
3382  bool m_initialDesiredBoundsRecorded = false;
3383  mpFloatRect m_lastDesiredReportedBounds;
3384 
3385  wxDECLARE_DYNAMIC_CLASS(mpWindow);
3386  wxDECLARE_EVENT_TABLE();
3387 
3388  // To have direct access to m_Screenshot_dc
3389  friend mpPrintout;
3390 };
3391 
3392 //-----------------------------------------------------------------------------
3393 // mpText - provided by Val Greene
3394 //-----------------------------------------------------------------------------
3395 
3403 class WXDLLIMPEXP_MATHPLOT mpText: public mpLayer
3404 {
3405  public:
3408  mpText(const wxString &name = wxEmptyString) : mpLayer(mpLAYER_TEXT)
3409  {
3410  m_subtype = mptText;
3411  SetName(name);
3412  m_offsetx = 5;
3413  m_offsety = 50;
3414  m_location = mpMarginNone;
3415  m_ZIndex = mpZIndex_TEXT;
3416  }
3417 
3421  mpText(const wxString &name, int offsetx, int offsety);
3422 
3426  mpText(const wxString &name, mpLocation marginLocation);
3427 
3430  virtual bool HasBBox()
3431  {
3432  return false;
3433  }
3434 
3437  void SetLocation(mpLocation location)
3438  {
3439  m_location = location;
3440  }
3441 
3444  mpLocation GetLocation() const
3445  {
3446  return m_location;
3447  }
3448 
3451  void SetOffset(int offX, int offY)
3452  {
3453  m_offsetx = offX;
3454  m_offsety = offY;
3455  }
3456 
3458  void GetOffset(int *offX, int *offY) const
3459  {
3460  *offX = m_offsetx;
3461  *offY = m_offsety;
3462  }
3463 
3464  protected:
3467  mpLocation m_location;
3468 
3471  virtual void DoPlot(wxDC &dc, mpWindow &w);
3472 
3473  wxDECLARE_DYNAMIC_CLASS(mpText);
3474 };
3475 
3479 class WXDLLIMPEXP_MATHPLOT mpTitle: public mpText
3480 {
3481  public:
3484  mpTitle();
3485 
3488  mpTitle(const wxString &name) :
3489  mpText(name, mpMarginTopCenter)
3490  {
3491  m_subtype = mptTitle;
3492  SetPen(*wxWHITE_PEN);
3493  SetBrush(*wxWHITE_BRUSH);
3494  }
3495 
3496  protected:
3497 
3498  wxDECLARE_DYNAMIC_CLASS(mpTitle);
3499 };
3500 
3501 //-----------------------------------------------------------------------------
3502 // mpPrintout - provided by Davide Rondini
3503 //-----------------------------------------------------------------------------
3504 
3509 class WXDLLIMPEXP_MATHPLOT mpPrintout: public wxPrintout
3510 {
3511  public:
3512  mpPrintout()
3513  {
3514  plotWindow = NULL;
3515  drawn = false;
3516  stretch_factor = 2;
3517  }
3518 
3519  mpPrintout(mpWindow *drawWindow, const wxString &title = _T("wxMathPlot print output"), int factor = 2);
3520  virtual ~mpPrintout()
3521  {
3522  ;
3523  }
3524 
3525  void SetDrawState(bool drawState)
3526  {
3527  drawn = drawState;
3528  }
3529 
3530  bool OnPrintPage(int page);
3531  bool HasPage(int page);
3532 
3535  void SetFactor(int factor)
3536  {
3537  stretch_factor = factor;
3538  }
3539 
3540  private:
3541  bool drawn;
3542  mpWindow* plotWindow;
3543  int stretch_factor; // To reduce the size of plot
3544 
3545  protected:
3546 
3547  wxDECLARE_DYNAMIC_CLASS(mpPrintout);
3548 };
3549 
3550 //-----------------------------------------------------------------------------
3551 // mpMovableObject - provided by Jose Luis Blanco
3552 //-----------------------------------------------------------------------------
3560 class WXDLLIMPEXP_MATHPLOT mpMovableObject: public mpFunction
3561 {
3562  public:
3566  m_reference_x(0), m_reference_y(0), m_reference_phi(0), m_shape_xs(0), m_shape_ys(0)
3567  {
3568  assert(m_type == mpLAYER_PLOT); // m_type is already set to mpLAYER_PLOT in default-arg mpFunction ctor: m_type = mpLAYER_PLOT;
3569  m_subtype = mpfMovable;
3570  m_bbox_min_x = m_bbox_max_x = 0;
3571  m_bbox_min_y = m_bbox_max_y = 0;
3572  }
3573 
3574  virtual ~mpMovableObject() {}
3575 
3578  void GetCoordinateBase(double &x, double &y, double &phi) const
3579  {
3580  x = m_reference_x;
3581  y = m_reference_y;
3582  phi = m_reference_phi;
3583  }
3584 
3587  void SetCoordinateBase(double x, double y, double phi = 0)
3588  {
3589  m_reference_x = x;
3590  m_reference_y = y;
3591  m_reference_phi = phi;
3592  m_flags = mpALIGN_NE;
3593  ShapeUpdated();
3594  }
3595 
3596  virtual bool HasBBox()
3597  {
3598  return m_trans_shape_xs.size() != 0;
3599  }
3600 
3603  virtual double GetMinX()
3604  {
3605  return m_bbox_min_x;
3606  }
3607 
3610  virtual double GetMaxX()
3611  {
3612  return m_bbox_max_x;
3613  }
3614 
3617  virtual double GetMinY()
3618  {
3619  return m_bbox_min_y;
3620  }
3621 
3624  virtual double GetMaxY()
3625  {
3626  return m_bbox_max_y;
3627  }
3628 
3629  protected:
3630 
3633  double m_reference_x, m_reference_y, m_reference_phi;
3634 
3635  virtual void DoPlot(wxDC &dc, mpWindow &w);
3636 
3639  void TranslatePoint(double x, double y, double &out_x, double &out_y) const;
3640 
3643  std::vector<double> m_shape_xs, m_shape_ys;
3644 
3648  std::vector<double> m_trans_shape_xs, m_trans_shape_ys;
3649 
3653  double m_bbox_min_x, m_bbox_max_x, m_bbox_min_y, m_bbox_max_y;
3654 
3658  void ShapeUpdated();
3659 
3660  wxDECLARE_DYNAMIC_CLASS(mpMovableObject);
3661 };
3662 
3663 //-----------------------------------------------------------------------------
3664 // mpCovarianceEllipse - provided by Jose Luis Blanco
3665 //-----------------------------------------------------------------------------
3677 class WXDLLIMPEXP_MATHPLOT mpCovarianceEllipse: public mpMovableObject
3678 {
3679  public:
3683  mpCovarianceEllipse(double cov_00 = 1, double cov_11 = 1, double cov_01 = 0, double quantiles = 2, int segments = 32,
3684  const wxString &layerName = _T("")) : mpMovableObject(),
3685  m_cov_00(cov_00), m_cov_11(cov_11), m_cov_01(cov_01), m_quantiles(quantiles), m_segments(segments)
3686  {
3687  m_continuous = true;
3688  m_name = layerName;
3689  RecalculateShape();
3690  }
3691 
3692  virtual ~mpCovarianceEllipse()
3693  {
3694  ;
3695  }
3696 
3697  double GetQuantiles() const
3698  {
3699  return m_quantiles;
3700  }
3701 
3704  void SetQuantiles(double q)
3705  {
3706  m_quantiles = q;
3707  RecalculateShape();
3708  }
3709 
3710  void SetSegments(int segments)
3711  {
3712  m_segments = segments;
3713  }
3714 
3715  int GetSegments() const
3716  {
3717  return m_segments;
3718  }
3719 
3722  void GetCovarianceMatrix(double &cov_00, double &cov_01, double &cov_11) const
3723  {
3724  cov_00 = m_cov_00;
3725  cov_01 = m_cov_01;
3726  cov_11 = m_cov_11;
3727  }
3728 
3731  void SetCovarianceMatrix(double cov_00, double cov_01, double cov_11)
3732  {
3733  m_cov_00 = cov_00;
3734  m_cov_01 = cov_01;
3735  m_cov_11 = cov_11;
3736  RecalculateShape();
3737  }
3738 
3739  protected:
3742  double m_cov_00, m_cov_11, m_cov_01;
3743  double m_quantiles;
3744 
3748 
3751  void RecalculateShape();
3752 
3753  wxDECLARE_DYNAMIC_CLASS(mpCovarianceEllipse);
3754 };
3755 
3756 //-----------------------------------------------------------------------------
3757 // mpPolygon - provided by Jose Luis Blanco
3758 //-----------------------------------------------------------------------------
3763 class WXDLLIMPEXP_MATHPLOT mpPolygon: public mpMovableObject
3764 {
3765  public:
3768  mpPolygon(const wxString &layerName = _T("")) : mpMovableObject()
3769  {
3770  m_continuous = true;
3771  m_name = layerName;
3772  }
3773 
3774  virtual ~mpPolygon()
3775  {
3776  ;
3777  }
3778 
3784  void setPoints(const std::vector<double> &points_xs, const std::vector<double> &points_ys, bool closedShape = true);
3785 
3786  protected:
3787 
3788  wxDECLARE_DYNAMIC_CLASS(mpPolygon);
3789 };
3790 
3791 //-----------------------------------------------------------------------------
3792 // mpBitmapLayer - provided by Jose Luis Blanco
3793 //-----------------------------------------------------------------------------
3798 class WXDLLIMPEXP_MATHPLOT mpBitmapLayer: public mpLayer
3799 {
3800  public:
3803  mpBitmapLayer() : mpLayer(mpLAYER_BITMAP)
3804  {
3805  m_min_x = m_max_x = 0;
3806  m_min_y = m_max_y = 0;
3807  m_validImg = false;
3808  m_bitmapChanged = false;
3809  m_scaledBitmap_offset_x = m_scaledBitmap_offset_y = 0;
3810  }
3811 
3812  virtual ~mpBitmapLayer()
3813  {
3814  ;
3815  }
3816 
3819  void GetBitmapCopy(wxImage &outBmp) const;
3820 
3828  void SetBitmap(const wxImage &inBmp, double x, double y, double lx, double ly);
3829 
3832  virtual double GetMinX()
3833  {
3834  return m_min_x;
3835  }
3836 
3839  virtual double GetMaxX()
3840  {
3841  return m_max_x;
3842  }
3843 
3846  virtual double GetMinY()
3847  {
3848  return m_min_y;
3849  }
3850 
3853  virtual double GetMaxY()
3854  {
3855  return m_max_y;
3856  }
3857 
3858  protected:
3859 
3862  wxImage m_bitmap;
3863  wxBitmap m_scaledBitmap;
3864  wxCoord m_scaledBitmap_offset_x, m_scaledBitmap_offset_y;
3865  bool m_validImg;
3866  bool m_bitmapChanged;
3867 
3870  double m_min_x, m_max_x, m_min_y, m_max_y;
3871 
3872  virtual void DoPlot(wxDC &dc, mpWindow &w);
3873 
3874  wxDECLARE_DYNAMIC_CLASS(mpBitmapLayer);
3875 };
3876 
3877 // utility class
3878 
3879 // Enumeration of classic colour
3880 typedef enum __mp_Colour
3881 {
3882  mpBlue,
3883  mpRed,
3884  mpGreen,
3885  mpPurple,
3886  mpYellow,
3887  mpFuchsia,
3888  mpLime,
3889  mpAqua,
3890  mpOlive
3891 } mpColour;
3892 
3897 class WXDLLIMPEXP_MATHPLOT wxIndexColour: public wxColour
3898 {
3899  public:
3900  wxIndexColour(unsigned int id)
3901  {
3902  switch (id)
3903  {
3904  case 0:
3905  this->Set(0, 0, 255);
3906  break; // Blue
3907  case 1:
3908  this->Set(255, 0, 0);
3909  break; // Red
3910  case 2:
3911  this->Set(0, 128, 0);
3912  break; // Green
3913  case 3:
3914  this->Set(128, 0, 128);
3915  break; // Purple
3916  case 4:
3917  this->Set(255, 255, 0);
3918  break; // Yellow
3919  case 5:
3920  this->Set(255, 0, 255);
3921  break; // Fuchsia
3922  case 6:
3923  this->Set(0, 255, 0);
3924  break; // Lime
3925  case 7:
3926  this->Set(0, 255, 255);
3927  break; // Aqua/Cyan
3928  case 8:
3929  this->Set(128, 128, 0);
3930  break; // Olive
3931  default:
3932  this->Set((ChannelType)((rand() * 255) / RAND_MAX), (ChannelType)((rand() * 255) / RAND_MAX),
3933  (ChannelType)((rand() * 255) / RAND_MAX));
3934  }
3935  }
3936 };
3937 
3940 // ---------------------------------------------------------------------
3941 #ifdef ENABLE_MP_NAMESPACE
3942  }// namespace MathPlot
3943  // No, iff build enables namespace, its up to app to use it appropriately: using namespace MathPlot;
3944 #endif // ENABLE_MP_NAMESPACE
3945 
3946 #endif // MATHPLOT_H_INCLUDED
int m_offsety
Holds offset for Y in percentage.
Definition: mathplot.h:3466
const wxString & GetLabelFormat() const
Get axis Label format (used for mpX_NORMAL draw mode).
Definition: mathplot.h:2029
bool IsHorizontal(void) const
Get if is horizontal line.
Definition: mathplot.h:1295
void SetValue(const double value)
Set x or y.
Definition: mathplot.h:1288
double m_min_x
The shape of the bitmap:
Definition: mathplot.h:3870
mpRect m_marginOuter
Margin around the plot exluding Y-axis. Default 50.
Definition: mathplot.h:3330
bool m_isLog
Is the axis a log axis ?
Definition: mathplot.h:2108
void EnableDoubleBuffer(const bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=enabled).
Definition: mathplot.h:2711
mpFloatRect m_bound
Global layer bounding box in user coordinates. Does NOT include borders.
Definition: mathplot.h:3326
double GetDesiredYmin(size_t yIndex) const
Return the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not exa...
Definition: mathplot.h:2873
void SetBrush(const wxBrush &brush)
Set layer brush.
Definition: mathplot.h:706
bool m_showName
States whether the name of the layer must be shown. Default : false.
Definition: mathplot.h:827
std::vector< m_yAxisData > m_yAxisDataList
Current view&#39;s Y scales and Y positions.
Definition: mathplot.h:3319
int GetScreenX(void) const
Get current view&#39;s X dimension in device context units.
Definition: mathplot.h:2645
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: mathplot.h:3853
void UnSetOnDeleteLayer()
Remove the &#39;delete layer event&#39; callback.
Definition: mathplot.h:3119
bool operator==(const mpFloatRect &rect) const
Equal operator.
Definition: mathplot.h:286
void SetXValue(const double xvalue)
Set x.
Definition: mathplot.h:1339
An arbitrary polygon, descendant of mpMovableObject.
Definition: mathplot.h:3763
void SetScaleX(const double scaleX)
Set current view&#39;s X scale and refresh display.
Definition: mathplot.h:2511
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: mathplot.h:584
A rectangle structure in several (integer) flavors.
Definition: mathplot.h:174
A class providing graphs functionality for a 2D plot (either continuous or a set of points)...
Definition: mathplot.h:1584
int m_clickedX
Last mouse click X position, for centering and zooming the view.
Definition: mathplot.h:3323
A layer that allows you to have a bitmap image printed in the mpWindow.
Definition: mathplot.h:3798
void InitializeBoundingBox(double px, double py, size_t yIndex=0)
Initialize bounding box with an initial point.
Definition: mathplot.h:270
bool m_magnetize
For mouse magnetization.
Definition: mathplot.h:3361
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: mathplot.h:1935
wxPoint m_mouseRClick
For the right button "drag" feature.
Definition: mathplot.h:3345
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: mathplot.h:1919
mpPolygon(const wxString &layerName=_T(""))
Default constructor.
Definition: mathplot.h:3768
bool GetShowGrids() const
Get axis grids.
Definition: mathplot.h:2015
wxString m_name
Layer&#39;s name.
Definition: mathplot.h:826
void UpdateDesiredBoundingBox()
Draws the mpWindow on a page for printing.
Definition: mathplot.h:2834
std::vector< double > m_mouseScaleYList
Store current Y-scales, used as reference during drag zooming.
Definition: mathplot.h:3348
const mpLayerType m_type
Layer type mpLAYER_*.
Definition: mathplot.h:819
virtual bool HasBBox() override
Check whether this layer has a bounding box.
Definition: mathplot.h:1272
void SetItemMode(mpLegendStyle mode)
Set item mode (the element on the left of text representing the plot line may be line, square, or line with symbol).
Definition: mathplot.h:1088
int m_offsetx
Holds offset for X in percentage.
Definition: mathplot.h:3465
Abstract class providing a line.
Definition: mathplot.h:1266
Abstract class providing an vertical line.
Definition: mathplot.h:1331
bool GetShowTicks() const
Get axis ticks.
Definition: mathplot.h:2001
mpFloatRect m_desired
Stores current plot view min/max boundaries. Used primarily during frame resizing via OnSize...
Definition: mathplot.h:3327
Canvas for plotting mpLayer implementations.
Definition: mathplot.h:2384
mpWindow * m_win
The wxWindow handle.
Definition: mathplot.h:820
wxPen m_gridpen
Grid&#39;s pen. Default Colour = LIGHT_GREY, width = 1, style = wxPENSTYLE_DOT.
Definition: mathplot.h:2102
void SetCoordinateBase(double x, double y, double phi=0)
Set the coordinate transformation (phi in radians, 0 means no rotation).
Definition: mathplot.h:3587
std::optional< size_t > m_mouseYAxisIndex
Indicate which Y-axis the mouse was on during zoom/pan.
Definition: mathplot.h:3349
const wxColour & GetFontColour() const
Get font foreground colour set for this layer.
Definition: mathplot.h:683
bool IsAspectLocked() const
Checks whether the X/Y scale aspect is locked.
Definition: mathplot.h:2734
int m_winY
Holds the mpWindow size. Used to rescale position when window is resized.
Definition: mathplot.h:964
~mpBarChart()
Destructor.
Definition: mathplot.h:1843
double p2x(const wxCoord pixelCoordX) const
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:2680
mpLayerZOrder m_ZIndex
The index in Z-Order to draw the layer.
Definition: mathplot.h:834
void SetLabelMode(unsigned int mode, unsigned int time_conv=0x20)
Set X axis label view mode.
Definition: mathplot.h:2178
double p2y(const wxCoord pixelCoordY, size_t yIndex=0) const
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:2688
wxPoint m_mouseLClick
Starting coords for rectangular zoom selection.
Definition: mathplot.h:3346
virtual void DesiredBoundsHaveChanged()
To be notified of displayed bounds changes (after user zoom etc), override this callback in your deri...
Definition: mathplot.h:3376
void SetPen(const wxPen &pen)
Set layer pen.
Definition: mathplot.h:691
wxBitmap * m_Screenshot_bmp
For clipboard, save and print.
Definition: mathplot.h:3364
int m_flags
Holds label alignment. Default : mpALIGN_NE.
Definition: mathplot.h:831
virtual bool HasBBox()
Text Layer has not bounding box.
Definition: mathplot.h:3430
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: mathplot.h:568
wxPoint GetPosition() const
Returns the position of the upper left corner of the box (in pixels)
Definition: mathplot.h:926
void SetPenSeries(const wxPen &pen)
Pen series for tractable.
Definition: mathplot.h:1043
void SetDrawOutsideMargins(bool drawModeOutside)
Set Draw mode: inside or outside margins.
Definition: mathplot.h:737
unsigned int GetLabelMode() const
Get X axis label view mode.
Definition: mathplot.h:2171
~mpPieChart()
Destructor.
Definition: mathplot.h:1905
bool PointIsInside(double px, double py, size_t yIndex=0) const
Is point inside this bounding box?
Definition: mathplot.h:242
int m_symbolSize
Size of the symbol. Default 6.
Definition: mathplot.h:1256
int GetPlotWidth() const
Get the width of the plot.
Definition: mathplot.h:3008
int m_subtype
Layer sub type, set in constructors.
Definition: mathplot.h:821
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: mathplot.h:3617
mpInfoCoords * m_InfoCoords
pointer to the optional info coords layer
Definition: mathplot.h:3353
void SetMarginRight(int right)
Set the right margin.
Definition: mathplot.h:2960
void SetContinuity(bool continuity)
Set the &#39;continuity&#39; property of the layer.
Definition: mathplot.h:1176
int GetMarginLeftOuter() const
Get the left outer margin, exluding Y-axis.
Definition: mathplot.h:3002
void SetMouseLeftDownAction(mpMouseButtonAction action)
Set the type of action for the left mouse button.
Definition: mathplot.h:3199
wxMenu m_popmenu
Canvas&#39; context menu.
Definition: mathplot.h:3305
double m_mouseScaleX
Store current X-scale, used as reference during drag zooming.
Definition: mathplot.h:3347
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:1410
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
Definition: mathplot.h:1466
std::vector< double > m_shape_xs
This contains the object points, in local coordinates (to be transformed by the current transformatio...
Definition: mathplot.h:3643
wxColour m_axColour
Axes Colour.
Definition: mathplot.h:3309
bool m_visible
Toggles layer visibility. Default : true.
Definition: mathplot.h:829
mpRect m_plotBoundaries
The full size of the plot. Calculated.
Definition: mathplot.h:3334
void GetCoordinateBase(double &x, double &y, double &phi) const
Get the current coordinate transformation.
Definition: mathplot.h:3578
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
Definition: mathplot.h:1070
Plot layer implementing a x-scale ruler.
Definition: mathplot.h:2147
bool m_tractable
Is the layer tractable.
Definition: mathplot.h:830
void SetLocation(mpLocation location)
Set the location of the box.
Definition: mathplot.h:3437
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:1809
virtual void SetLabelFormat(const wxString &format)
Set axis Label format (used for mpX_NORMAL draw mode).
Definition: mathplot.h:2163
void EnableMousePanZoom(const bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
Definition: mathplot.h:2718
bool m_drawBox
Draw box of the plot bound. Default true.
Definition: mathplot.h:3310
const wxPen & GetGridPen() const
Get pen set for this axis.
Definition: mathplot.h:2045
int GetMarginRight() const
Get the right margin.
Definition: mathplot.h:2966
bool m_CanDelete
Is the layer can be deleted.
Definition: mathplot.h:833
mpSymbol GetSymbol() const
Get symbol.
Definition: mathplot.h:1212
void SetWindow(mpWindow &w)
Set the wxWindow handle.
Definition: mathplot.h:520
wxFont m_font
Layer&#39;s font.
Definition: mathplot.h:822
bool GetCanDelete(void) const
Get CanDelete for plot.
Definition: mathplot.h:806
Definition: MathPlotConfig.h:44
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: mathplot.h:1943
bool m_auto
Flag to autosize grids. Default true.
Definition: mathplot.h:2105
void SetCanDelete(bool canDelete)
Set CanDelete for plot.
Definition: mathplot.h:799
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: mathplot.h:3832
bool GetMagnetize() const
Magnetize the position of the mouse in the plot ie draw a vertical and horizontal line...
Definition: mathplot.h:3185
mpFloatRect Get_Bound(void) const
Get bounding box encompassing all visible plots on this mpWindow.
Definition: mathplot.h:2558
~mpInfoCoords()
Default destructor.
Definition: mathplot.h:1000
void ShowGrids(bool grids)
Set axis grids.
Definition: mathplot.h:2008
const wxColour & GetAxesColour() const
Get axes draw colour.
Definition: mathplot.h:3094
const wxBrush & GetBrush() const
Get brush set for this layer.
Definition: mathplot.h:716
virtual double GetMaxY()
Returns the actual maximum Y data (loaded in SetData).
Definition: mathplot.h:1722
mpText(const wxString &name=wxEmptyString)
Default constructor.
Definition: mathplot.h:3408
wxImage m_bitmap
The internal copy of the Bitmap:
Definition: mathplot.h:3862
void SetOnUserMouseAction(const mpOnUserMouseAction &userMouseEventHandler)
On user mouse action event Allows the user to perform certain actions before normal event processing...
Definition: mathplot.h:3128
wxBitmap * m_buff_bmp
For double buffering.
Definition: mathplot.h:3340
void SetPosX(const double posX)
Set current view&#39;s X position and refresh display.
Definition: mathplot.h:2566
mpLayerZOrder GetZIndex(void) const
Get the ZIndex of the plot.
Definition: mathplot.h:813
int GetPlotHeight() const
Get the height of the plot.
Definition: mathplot.h:3014
bool IsSeriesCoord() const
Return if we show the series coordinates.
Definition: mathplot.h:1029
size_t m_index
The internal counter for the "GetNextXY" interface.
Definition: mathplot.h:1658
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: mathplot.h:3839
mpInfoLegend * m_InfoLegend
pointer to the optional info legend layer
Definition: mathplot.h:3354
bool GetShowName() const
Get Name visibility.
Definition: mathplot.h:730
void SetCovarianceMatrix(double cov_00, double cov_01, double cov_11)
Changes the covariance matrix:
Definition: mathplot.h:3731
Printout class used by mpWindow to draw in the objects to be printed.
Definition: mathplot.h:3509
int m_last_ly
For double buffering.
Definition: mathplot.h:3339
void SetLogYaxis(size_t yIndex, bool log)
Set the log property (true or false) Y layer (Y axis) with a specific Y-index.
Definition: mathplot.h:3173
mpMagnet m_magnet
For mouse magnetization.
Definition: mathplot.h:3362
wxSize GetSize() const
Returns the size of the box (in pixels)
Definition: mathplot.h:933
bool m_grids
Flag to show grids. Default false.
Definition: mathplot.h:2104
mpScaleY(const wxString &name=_T("Y"), int flags=mpALIGN_CENTERY, bool grids=false, size_t axisIndex=0)
Full constructor.
Definition: mathplot.h:2219
wxRect m_dim
The bounding rectangle of the mpInfoLayer box (may be resized dynamically by the Plot method)...
Definition: mathplot.h:960
mpLocation GetLocation() const
Returns the location of the box.
Definition: mathplot.h:3444
unsigned int m_step
Step to get point to be draw. Default : 1.
Definition: mathplot.h:1258
wxCoord y2p(const double y, size_t yIndex=0) const
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:2704
virtual ~mpFXYVector()
destrutor
Definition: mathplot.h:1594
mpFloatRect GetDesiredBoundingBox() const
Get the &#39;desired&#39; user-coordinate bounding box for the currently displayed view (set by Fit...
Definition: mathplot.h:2850
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
Definition: mathplot.h:3560
double m_scaleX
Current view&#39;s X scale.
Definition: mathplot.h:3312
mpInfoLayer * m_movingInfoLayer
For moving info layers over the window area.
Definition: mathplot.h:3352
virtual int GetSize()
Return the number of points in the series.
Definition: mathplot.h:1490
virtual bool IsLogAxis()
Logarithmic axis.
Definition: mathplot.h:2089
void SetSymbolSize(int size)
Set symbol size.
Definition: mathplot.h:1219
Create a wxColour id is the number of the colour : blue, red, green, ...
Definition: mathplot.h:3897
unsigned int m_labelType
Select labels mode: mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.
Definition: mathplot.h:2185
bool GetContinuity() const
Gets the &#39;continuity&#39; property of the layer.
Definition: mathplot.h:1184
A structure for computation of bounds in real units (not in screen pixel) X refer to X axis Y refer t...
Definition: mathplot.h:225
Layer for bar chart.
Definition: mathplot.h:1836
double m_max
Min and max axis values when autosize is false.
Definition: mathplot.h:2106
wxPen m_pen
Layer&#39;s pen. Default Colour = Black, width = 1, style = wxPENSTYLE_SOLID.
Definition: mathplot.h:824
wxString m_content
string holding the coordinates to be drawn.
Definition: mathplot.h:1049
abstract Layer for chart (bar and pie).
Definition: mathplot.h:1778
void SetPosY(const std::vector< double > &posYList)
Set current view&#39;s Y position and refresh display.
Definition: mathplot.h:2585
const wxPen & GetPen() const
Get pen set for this layer.
Definition: mathplot.h:699
std::vector< mpScaleY * > m_YAxisList
Pointer to the optional Y axes layer of this mpWindow.
Definition: mathplot.h:3303
const wxRect & GetRectangle() const
Returns the current rectangle coordinates.
Definition: mathplot.h:940
double m_bbox_min_x
The precomputed bounding box:
Definition: mathplot.h:3653
double GetDesiredXmin() const
Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
Definition: mathplot.h:2855
virtual void DoBeforePlot()
If we need to do something before plot like reinitialize some parameters ...
Definition: mathplot.h:849
mpSymbol m_symbol
A symbol for the plot in place of point. Default mpNone.
Definition: mathplot.h:1255
void SetMarginBottom(int bottom)
Set the bottom margin.
Definition: mathplot.h:2978
virtual int GetSize()
Return the number of points in the series We assume that size of m_xs equals size of m_ys...
Definition: mathplot.h:1614
int m_symbolSize2
Size of the symbol div 2.
Definition: mathplot.h:1257
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: mathplot.h:3846
bool GetAuto() const
Is automatic scaling enabled for this axis?
Definition: mathplot.h:2061
wxBitmap * m_info_bmp
The bitmap that contain the info.
Definition: mathplot.h:962
virtual double GetMinX()
Returns the actual minimum X data (loaded in SetData).
Definition: mathplot.h:1685
void SetYAxisIndex(size_t index)
Set the index of the Y axis associated to the function.
Definition: mathplot.h:1248
void SetYValue(const double yvalue)
Set y.
Definition: mathplot.h:1317
void SetReserve(int reserve)
Set memory reserved for m_xs and m_ys Note : this does not modify the size of m_xs and m_ys...
Definition: mathplot.h:1633
int GetReserve() const
Get memory reserved for m_xs and m_ys.
Definition: mathplot.h:1642
mpMouseButtonAction GetMouseLeftDownAction()
Returns the type of action for the left mouse button.
Definition: mathplot.h:3208
void UpdateMargins()
Update margins if e.g.
Definition: mathplot.h:2942
< Y scale and position structure
Definition: mathplot.h:3314
int GetMarginTop() const
Get the top margin.
Definition: mathplot.h:2954
wxRect m_PlotArea
The full size of the plot with EXTRA_MARGIN.
Definition: mathplot.h:3336
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
Definition: mathplot.h:875
std::vector< double > m_trans_shape_xs
The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh)...
Definition: mathplot.h:3648
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:532
void GetOffset(int *offX, int *offY) const
Get the offset.
Definition: mathplot.h:3458
wxCoord m_plotWidth
Width of the plot = m_scrX - (m_margin.left + m_margin.right)
Definition: mathplot.h:3331
virtual bool HasBBox()
mpInfoLayer has not bounding box.
Definition: mathplot.h:902
mpLayerType GetLayerType() const
Get layer type: a Layer can be of different types: plot, lines, axis, info boxes, etc...
Definition: mathplot.h:541
Implements an overlay box which shows the mouse coordinates in plot units.
Definition: mathplot.h:984
bool GetMPScrollbars() const
Get scrollbars status.
Definition: mathplot.h:2901
wxBitmap * m_zoom_bmp
For zoom selection.
Definition: mathplot.h:3357
int m_scrY
Current view&#39;s Y dimension.
Definition: mathplot.h:3322
double GetDesiredYmax(size_t yIndex) const
Return the top layer-border coordinate that the user wants the mpWindow to show (it may be not exactl...
Definition: mathplot.h:2882
wxCoord x2p(const double x) const
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:2696
void SetStep(unsigned int step)
Set step for plot.
Definition: mathplot.h:1191
~mpInfoLegend()
Default destructor.
Definition: mathplot.h:1084
wxRect m_oldDim
Keep the old values of m_dim.
Definition: mathplot.h:961
wxColour m_bgColour
Background Colour.
Definition: mathplot.h:3307
bool IsLogXaxis()
Is this an X axis to be displayed with log scale? It is really an axis property but as we need to con...
Definition: mathplot.h:3144
void SetScreen(const int scrX, const int scrY)
Set current view&#39;s dimensions in device context units.
Definition: mathplot.h:2621
int GetBarWidth(void) const
return the width of the bar
Definition: mathplot.h:1516
void SetOnDeleteLayer(const mpOnDeleteLayer &event)
On delete layer event Allows the user to perform certain actions before deleting the layer...
Definition: mathplot.h:3113
void SetSeriesCoord(bool show)
Set the series coordinates of the mouse position (if tractable set)
Definition: mathplot.h:1022
virtual double GetMaxX()
Returns the actual maximum X data (loaded in SetData).
Definition: mathplot.h:1707
void SetDrawBox(bool drawbox)
Set the draw of the box around the plot.
Definition: mathplot.h:3045
bool m_enableDoubleBuffer
For double buffering. Default enabled.
Definition: mathplot.h:3341
Plot layer implementing an abstract function plot class.
Definition: mathplot.h:1166
Abstract base class providing plot and labeling functionality for functions F:X->Y.
Definition: mathplot.h:1357
mpTitle(const wxString &name)
Definition: mathplot.h:3488
void SetLabelMode(unsigned int mode, unsigned int time_conv=0x20)
Set X axis label view mode.
Definition: mathplot.h:1014
Plot layer implementing a simple title.
Definition: mathplot.h:3479
Plot layer implementing a y-scale ruler.
Definition: mathplot.h:2212
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:3596
bool ViewAsBar(void) const
return true if XY series is plotted with bar
Definition: mathplot.h:1524
double GetScaleY(size_t yIndex=0) const
Get current view&#39;s Y scale.
Definition: mathplot.h:2547
mpLocation m_location
Location of the box in the margin. Default mpMarginNone = use coordinates.
Definition: mathplot.h:965
virtual void SetVisible(bool show)
Sets layer visibility.
Definition: mathplot.h:764
mpRect GetPlotBoundaries(bool with_margin) const
Get the boundaries of the plot.
Definition: mathplot.h:3020
double GetPosX(void) const
Get current view&#39;s X position.
Definition: mathplot.h:2577
int GetAlign() const
Get X/Y alignment.
Definition: mathplot.h:792
bool m_drawOutsideMargins
Select if the layer should draw only inside margins or over all DC. Default : false.
Definition: mathplot.h:828
virtual void SetLabelFormat(const wxString &format)
Set axis Label format (used for mpX_NORMAL draw mode).
Definition: mathplot.h:2022
void SetAuto(bool automaticScalingIsEnabled)
Enable/Disable automatic scaling for this axis.
Definition: mathplot.h:2053
virtual void Clear()
Clears all the data, leaving the layer empty.
Definition: mathplot.h:1482
bool m_continuous
Specify if the layer will be plotted as a continuous line or a set of points. Default false...
Definition: mathplot.h:1254
void UnSetOnUserMouseAction()
Remove the &#39;user mouse action event&#39; callback.
Definition: mathplot.h:3134
mpScaleX(const wxString &name=_T("X"), int flags=mpALIGN_CENTERX, bool grids=false, unsigned int type=0x00)
Full constructor.
Definition: mathplot.h:2155
~mpChart()
Destructor.
Definition: mathplot.h:1785
Abstract class providing an horizontal line.
Definition: mathplot.h:1309
std::vector< double > m_xs
The internal copy of the set of data to draw.
Definition: mathplot.h:1650
bool m_lockaspect
Scale aspect is locked or not.
Definition: mathplot.h:3306
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:3747
void Rewind()
Rewind value enumeration with mpFXY::GetNextXY.
Definition: mathplot.h:1667
void SetPos(const double posX, const std::vector< double > &posYList)
Set current view&#39;s X and Y position and refresh display.
Definition: mathplot.h:2665
Plot layer implementing an abstract scale ruler.
Definition: mathplot.h:1975
void SetFont(const wxFont &font)
Set layer font.
Definition: mathplot.h:659
Class for drawing mouse magnetization.
Definition: mathplot.h:2314
int m_reserveXY
Memory reserved for m_xs and m_ys.
Definition: mathplot.h:1654
void UpdateBoundingBoxToInclude(double px, double py, size_t yIndex=0)
Update bounding box to include this point.
Definition: mathplot.h:259
double GetPosY(size_t yIndex=0) const
Get current view&#39;s Y position.
Definition: mathplot.h:2599
size_t GetYAxisIndex() const
Get the index of the Y axis associated to the function.
Definition: mathplot.h:1240
A 2D ellipse, described by a 2x2 covariance matrix.
Definition: mathplot.h:3677
double m_minX
Loaded at SetData.
Definition: mathplot.h:1662
double GetDesiredXmax() const
Return the right-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
Definition: mathplot.h:2864
Layer for pie chart.
Definition: mathplot.h:1898
void SetFontColour(const wxColour &colour)
Set layer font foreground colour.
Definition: mathplot.h:675
mpCovarianceEllipse(double cov_00=1, double cov_11=1, double cov_01=0, double quantiles=2, int segments=32, const wxString &layerName=_T(""))
Default constructor.
Definition: mathplot.h:3683
const wxFont & GetFont() const
Get font set for this layer.
Definition: mathplot.h:667
bool m_enableMouseNavigation
For pan/zoom with the mouse.
Definition: mathplot.h:3342
int GetMarginLeft() const
Get the left margin.
Definition: mathplot.h:2996
wxColour m_fontcolour
Layer&#39;s font foreground colour.
Definition: mathplot.h:823
void GetCovarianceMatrix(double &cov_00, double &cov_01, double &cov_11) const
Returns the elements of the current covariance matrix:
Definition: mathplot.h:3722
void SetLocation(mpLocation location)
Set the location of the mpInfoLayer box.
Definition: mathplot.h:947
bool IsVisible() const
Checks whether the layer is visible or not.
Definition: mathplot.h:757
void ShowTicks(bool ticks)
Set axis ticks.
Definition: mathplot.h:1994
int GetLayerSubType() const
Get layer subtype: each layer type can have several flavors.
Definition: mathplot.h:549
virtual void SetTractable(bool track)
Sets layer tractability.
Definition: mathplot.h:778
int GetMarginBottom() const
Get the bottom margin.
Definition: mathplot.h:2984
int GetSymbolSize() const
Get symbol size.
Definition: mathplot.h:1227
mpMovableObject()
Default constructor (sets mpMovableObject location and rotation to (0,0,0))
Definition: mathplot.h:3565
int GetScreenY(void) const
Get current view&#39;s Y dimension in device context units.
Definition: mathplot.h:2656
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: mathplot.h:592
Plot layer implementing a text string.
Definition: mathplot.h:3403
virtual bool IsLayerType(mpLayerType typeOfInterest, int *subtype)
Set the layer&#39;s subtype in caller variable, and return true if the layer is of type "typeOfInterest"...
Definition: mathplot.h:559
wxCoord m_plotHeight
Height of the plot = m_scrY - (m_margin.top + m_margin.bottom)
Definition: mathplot.h:3332
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: mathplot.h:3624
bool GetDrawBox() const
Get the draw of the box around the plot.
Definition: mathplot.h:3051
bool GetDrawOutsideMargins() const
Get Draw mode: inside or outside margins.
Definition: mathplot.h:744
wxBrush m_brush
Layer&#39;s brush. Default wxTRANSPARENT_BRUSH.
Definition: mathplot.h:825
int GetMarginRightOuter() const
Get the right outer margin, exluding Y-axis.
Definition: mathplot.h:2972
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: mathplot.h:576
wxPoint m_reference
Holds the reference point for movements.
Definition: mathplot.h:963
void SetMarginTop(int top)
Set the top margin.
Definition: mathplot.h:2948
double GetScaleX(void) const
Get current view&#39;s X scale.
Definition: mathplot.h:2525
wxColour m_fgColour
Foreground Colour.
Definition: mathplot.h:3308
void SetItemDirection(mpLegendDirection mode)
Set item direction (may be vertical or horizontal)
Definition: mathplot.h:1101
void SetQuantiles(double q)
Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above)...
Definition: mathplot.h:3704
int m_clickedY
Last mouse click Y position, for centering and zooming the view.
Definition: mathplot.h:3324
Represents a numeric range with minimum and maximum values.
Definition: mathplot.h:205
static double m_zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
Definition: mathplot.h:2931
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:3633
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: mathplot.h:1927
unsigned int GetStep() const
Get step for plot.
Definition: mathplot.h:1198
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: mathplot.h:3603
Plot layer, abstract base class.
Definition: mathplot.h:508
mpRect m_plotBoundaries
The boundaries for plotting curve calculated by mpWindow.
Definition: mathplot.h:832
bool IsNotSet(mpWindow &w) const
Is mpFloatRect set ?
Definition: mathplot.h:279
double GetValue() const
Set x or y.
Definition: mathplot.h:1280
void SetOffset(int offX, int offY)
Set offset.
Definition: mathplot.h:3451
void SetFactor(int factor)
Definition: mathplot.h:3535
void SetName(const wxString &name)
Set layer name.
Definition: mathplot.h:643
size_t m_yAxisIndex
The index of the Y axis, 0 is the first axis (default)
Definition: mathplot.h:1259
wxString m_labelFormat
Format string used to print labels.
Definition: mathplot.h:2107
double m_posX
Current view&#39;s X position.
Definition: mathplot.h:3313
int m_scrX
Current view&#39;s X dimension in DC units, including all scales, margins.
Definition: mathplot.h:3321
mpScaleX * m_XAxis
Pointer to the optional X axis layer of this mpWindow.
Definition: mathplot.h:3302
void SetShowName(bool show)
Set Name visibility.
Definition: mathplot.h:723
const wxString & GetName() const
Get layer name.
Definition: mathplot.h:651
double m_cov_00
The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix)...
Definition: mathplot.h:3742
void SetMarginLeft(int left)
Set the left margin.
Definition: mathplot.h:2990
mpLayerList m_layers
List of attached plot layers.
Definition: mathplot.h:3301
bool m_ticks
Flag to show ticks. Default true.
Definition: mathplot.h:2103
mpRect m_margin
Margin around the plot including Y-axis.
Definition: mathplot.h:3329
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:1747
mpLocation GetLocation() const
Return the location of the mpInfoLayer box.
Definition: mathplot.h:954
mpMouseButtonAction m_mouseLeftDownAction
Type of action for left mouse button.
Definition: mathplot.h:3343
mpRect m_plotBoundariesMargin
The size of the plot with the margins. Calculated.
Definition: mathplot.h:3335
bool IsTractable() const
Checks whether the layer is tractable or not.
Definition: mathplot.h:771
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:1987
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: mathplot.h:3610
bool IsRepainting() const
Checks if we are repainting.
Definition: mathplot.h:2743
unsigned int CountAllLayers()
Counts the number of plot layers, whether or not they have a bounding box.
Definition: mathplot.h:2814
void SetGridPen(const wxPen &pen)
Set grid pen.
Definition: mathplot.h:2037
unsigned int m_timeConv
Selects if time has to be converted to local time or not.
Definition: mathplot.h:2186
void SetSymbol(mpSymbol symbol)
Set symbol.
Definition: mathplot.h:1205
mpBitmapLayer()
Default constructor.
Definition: mathplot.h:3803
bool IsLogYaxis(size_t yAxisIndex)
Get the log property (true or false) Y layer (Y axis) with a specific Y-index or false if not found...
Definition: mathplot.h:3155
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
Definition: mathplot.h:2400
void SetAlign(int align)
Set X/Y alignment.
Definition: mathplot.h:785
virtual double GetMinY()
Returns the actual minimum Y data (loaded in SetData).
Definition: mathplot.h:1700
void SetScaleY(const double scaleY, size_t yIndex)
Set current view&#39;s Y scale and refresh display.
Definition: mathplot.h:2533