MathPlot
Classes | Macros | Typedefs | Enumerations | Functions
mathplot.h File Reference
#include <cassert>
#include <vector>
#include <map>
#include <unordered_map>
#include <wx/defs.h>
#include <wx/menu.h>
#include <wx/scrolwin.h>
#include <wx/event.h>
#include <wx/dynarray.h>
#include <wx/pen.h>
#include <wx/dcmemory.h>
#include <wx/string.h>
#include <wx/print.h>
#include <wx/image.h>
#include <wx/intl.h>
#include <cmath>
#include <deque>
#include <algorithm>
Include dependency graph for mathplot.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  mpRect
 A rectangle structure in several (integer) flavors. More...
 
struct  mpRange< T >
 Represents a numeric range with minimum and maximum values. More...
 
struct  mpFloatRectSimple
 Define a simple rectangular box X refer to X axis Y refer to Y axis. More...
 
class  mpLayer
 Plot layer, abstract base class. More...
 
class  mpInfoLayer
 Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rectangular info box in transparent overlay over plot layers. More...
 
class  mpInfoCoords
 Implements an overlay box which shows the mouse coordinates in plot units. More...
 
class  mpInfoLegend
 Implements the legend to be added to the plot This layer allows you to add a legend to describe the plots in the window. More...
 
class  mpFunction
 Plot layer implementing an abstract function plot class. More...
 
class  mpLine
 Abstract class providing a line. More...
 
class  mpHorizontalLine
 Abstract class providing an horizontal line. More...
 
class  mpVerticalLine
 Abstract class providing an vertical line. More...
 
class  mpFX
 Abstract base class providing plot and labeling functionality for functions F:X->Y. More...
 
class  mpFY
 Abstract base class providing plot and labeling functionality for functions F:Y->X. More...
 
class  mpFXY
 Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y. More...
 
class  mpFXYVector
 A class providing graphs functionality for a 2D plot (either continuous or a set of points), from vectors of data. More...
 
class  mpProfile
 Abstract base class providing plot and labeling functionality for functions F:Y->X. More...
 
class  mpChart
 abstract Layer for chart (bar and pie). More...
 
class  mpBarChart
 Layer for bar chart. More...
 
class  mpPieChart
 Layer for pie chart. More...
 
class  mpScale
 Plot layer implementing an abstract scale ruler. More...
 
class  mpScaleX
 Plot layer implementing a x-scale ruler. More...
 
class  mpScaleY
 Plot layer implementing a y-scale ruler. More...
 
struct  mpAxisData
 Represents all the informations needed for plotting a layer in one direction (X or Y) This struct holds: More...
 
class  mpMagnet
 Class for drawing mouse magnetization Draw an horizontal and a vertical line at the mouse position. More...
 
class  mpWindow
 Canvas for plotting mpLayer implementations. More...
 
class  mpText
 Plot layer implementing a text string. More...
 
class  mpTitle
 Plot layer implementing a simple title. More...
 
class  mpPrintout
 Printout class used by mpWindow to draw in the objects to be printed. More...
 
class  mpMovableObject
 This virtual class represents objects that can be moved to an arbitrary 2D location+rotation. More...
 
class  mpCovarianceEllipse
 A 2D ellipse, described by a 2x2 covariance matrix. More...
 
class  mpPolygon
 An arbitrary polygon, descendant of mpMovableObject. More...
 
class  mpBitmapLayer
 A layer that allows you to have a bitmap image printed in the mpWindow. More...
 
class  wxIndexColour
 Create a wxColour id is the number of the colour : blue, red, green, ... More...
 

Macros

#define WXDLLIMPEXP_MATHPLOT
 Definition uses windows dll to export function.
 
#define WXDLLIMPEXP_DATA_MATHPLOT(type)   type
 Definition uses windows dll to export data type.
 
#define MP_OPTNULL_INT   -1
 
#define MP_OPTTEST(opt)   ((opt) != -1)
 
#define MP_OPTGET(opt)   (opt)
 
#define MP_LOOP_ITER   auto& elem
 
#define m_yID   elem.first
 
#define m_yData   elem.second
 
#define X_BORDER_SEPARATION   40
 This directive allow the user to add a custom include. More...
 
#define Y_BORDER_SEPARATION   60
 
#define mpX_LOCALTIME   0x10
 When setting x labels in date/time format, convert input time to local time. More...
 
#define mpX_UTCTIME   0x20
 When setting x labels in date/time format, convert input time to UTC time (or just leave it raw). More...
 
#define mpX_RAWTIME   mpX_UTCTIME
 Shortcut for mpX_UTCTIME.
 
#define EPSILON   1e-8
 An epsilon for float comparison to 0.
 
#define ISNOTNULL(x)   (fabs(x) > EPSILON)
 Nullity test according small epsilon.
 
#define EXTRA_MARGIN   8
 A small extra margin for the plot boundary.
 
#define ZOOM_AROUND_CENTER   -1
 Default value for zoom around a point (default -1 is no zoom)
 
mpLayer implementations - functions
#define mpBAR_NONE   0
 No bar labels.
 
#define mpBAR_AXIS_H   1
 Labels under X axis - horizontal layout.
 
#define mpBAR_AXIS_V   2
 Labels under X axis - vertical layout.
 
#define mpBAR_INSIDE   3
 Labels inside bar rectangle.
 
#define mpBAR_TOP   4
 Labels over the bar.
 
Constants defining mouse modes for mpWindow
#define mpMOUSEMODE_DRAG   0
 Mouse panning drags the view. More...
 
#define mpMOUSEMODE_ZOOMBOX   1
 Mouse panning creates a zoom box. More...
 

Typedefs

typedef unsigned int mpOptional_uint
 
typedef int mpOptional_int
 
typedef enum __mp_Location_Type mpLocation
 Location for the Info layer.
 
typedef enum __XAxis_Align_Type mpXAxis_Align
 Alignment for X axis.
 
typedef enum __YAxis_Align_Type mpYAxis_Align
 Alignment for Y axis.
 
typedef enum __Plot_Align_Name_Type mpPlot_Align
 Plot alignment (which corner should plot be placed)
 
typedef enum __mp_Style_Type mpLegendStyle
 Style for the Legend layer.
 
typedef enum __mp_Direction_Type mpLegendDirection
 Direction for the Legend layer.
 
typedef enum __Symbol_Type mpSymbol
 Displaying a symbol instead of a point in the plot function.
 
typedef enum __Info_Type mpInfoType
 sub_type values for mpLAYER_INFO
 
typedef enum __Text_Type mpTextType
 sub_type values for mpLAYER_TEXT
 
typedef enum __Function_Type mpFunctionType
 sub_type values for mpLAYER_PLOT and mpLAYER_LINE
 
typedef enum __Scale_Type mpScaleType
 sub_type values for mpLAYER_AXIS
 
typedef enum __Chart_Type mpChartType
 sub_type values for mpLAYER_CHART
 
typedef enum __mp_Layer_Type mpLayerType
 < Major type of an mpLayer (detail is in subtype)
 
typedef enum __mp_Layer_ZOrder mpLayerZOrder
 Z order for drawing layer Background is the deeper (bitmap layer) Then draw axis, custom layer, function, info (info, coord, legend, ...) and finally text (text, title)
 
typedef enum __mp_Delete_Action mpDeleteAction
 Action to do with the object associated to the layer when we delete it. More...
 
typedef std::deque< mpLayer * > mpLayerList
 Define the type for the list of layers inside mpWindow.
 
typedef std::unordered_map< int, mpAxisDatampAxisList
 Define the type for the list of axis.
 
typedef std::function< void(void *Sender, const wxString &classname, bool &cancel)> mpOnDeleteLayer
 Define an event for when we delete a layer. More...
 
typedef std::function< void(void *Sender, wxMouseEvent &event, bool &cancel)> mpOnUserMouseAction
 Define an event for when we have a mouse click Use like this : your_plot->SetOnUserMouseAction([this](void *Sender, wxMouseEvent &event, bool &cancel) { your_event_function(Sender, event, cancel);});.
 
typedef enum __mp_Colour mpColour
 Enumeration of classic colour.
 

Enumerations

enum  {
  mpID_FIT = 2000, mpID_ZOOM_IN, mpID_ZOOM_OUT, mpID_CENTER,
  mpID_LOCKASPECT, mpID_TOGGLE_GRID, mpID_TOGGLE_COORD, mpID_SCREENSHOT,
  mpID_LOAD_FILE, mpID_HELP_MOUSE, mpID_FULLSCREEN
}
 Command IDs used by mpWindow Same order for the popup menu. More...
 
enum  __mp_Location_Type {
  mpMarginLeftCenter, mpMarginTopLeft, mpMarginTopCenter, mpMarginTopRight,
  mpMarginRightCenter, mpMarginBottomLeft, mpMarginBottomCenter, mpMarginBottomRight,
  mpMarginNone, mpCursor
}
 Location for the Info layer. More...
 
enum  __XAxis_Align_Type {
  mpALIGN_BORDER_BOTTOM = 10, mpALIGN_BOTTOM, mpALIGN_CENTERX, mpALIGN_TOP,
  mpALIGN_BORDER_TOP
}
 Alignment for X axis. More...
 
enum  __YAxis_Align_Type {
  mpALIGN_BORDER_LEFT = 20, mpALIGN_LEFT, mpALIGN_CENTERY, mpALIGN_RIGHT,
  mpALIGN_BORDER_RIGHT
}
 Alignment for Y axis. More...
 
enum  __Plot_Align_Name_Type { mpALIGN_NW = 5, mpALIGN_NE, mpALIGN_SE, mpALIGN_SW }
 Plot alignment (which corner should plot be placed) More...
 
enum  __mp_Style_Type { mpLegendLine, mpLegendSquare, mpLegendSymbol }
 Style for the Legend layer. More...
 
enum  __mp_Direction_Type { mpVertical, mpHorizontal }
 Direction for the Legend layer. More...
 
enum  __Symbol_Type {
  mpsNone, mpsCircle, mpsSquare, mpsUpTriangle,
  mpsDownTriangle, mpsCross, mpsPlus
}
 Displaying a symbol instead of a point in the plot function. More...
 
enum  __Info_Type { mpiNone, mpiInfo, mpiCoords, mpiLegend }
 sub_type values for mpLAYER_INFO More...
 
enum  __Text_Type { mptNone, mptText, mptTitle }
 sub_type values for mpLAYER_TEXT More...
 
enum  __Function_Type {
  mpfNone, mpfFX, mpfFY, mpfFXY,
  mpfFXYVector, mpfMovable, mpfLine, mpfAllType
}
 sub_type values for mpLAYER_PLOT and mpLAYER_LINE More...
 
enum  __Scale_Type { mpsScaleNone, mpsScaleX, mpsScaleY, mpsAllType }
 sub_type values for mpLAYER_AXIS More...
 
enum  __Chart_Type { mpcChartNone, mpcBarChart, mpcPieChart, mpcAllType }
 sub_type values for mpLAYER_CHART More...
 
enum  mpMouseButtonAction { mpMouseBoxZoom, mpMouseDragZoom }
 enum for left button mouse action: box zoom or drag More...
 
enum  mpLabelType {
  mpLabel_AUTO, mpLabel_DECIMAL, mpLabel_SCIENTIFIC, mpLabel_TIME,
  mpLabel_HOURS, mpLabel_DATE, mpLabel_DATETIME, mpLabel_USER,
  mpLabel_NONE
}
 enum for label for grid More...
 
enum  __mp_Layer_Type {
  mpLAYER_UNDEF, mpLAYER_AXIS, mpLAYER_PLOT, mpLAYER_INFO,
  mpLAYER_TEXT, mpLAYER_BITMAP, mpLAYER_LINE, mpLAYER_CHART
}
 < Major type of an mpLayer (detail is in subtype) More...
 
enum  __mp_Layer_ZOrder {
  mpZIndex_BACKGROUND, mpZIndex_AXIS, mpZIndex_LINE, mpZIndex_PLOT,
  mpZIndex_CHART, mpZIndex_INFO, mpZIndex_TEXT, mpZIndex_END
}
 Z order for drawing layer Background is the deeper (bitmap layer) Then draw axis, custom layer, function, info (info, coord, legend, ...) and finally text (text, title) More...
 
enum  __mp_Delete_Action { mpNoDelete, mpYesDelete, mpForceDelete }
 Action to do with the object associated to the layer when we delete it. More...
 
enum  mpAxisUpdate { uXAxis = 1, uYAxis = 2, uXYAxis = 3 }
 Define the axis we want to update. More...
 
enum  __mp_Colour {
  mpBlue, mpRed, mpGreen, mpPurple,
  mpYellow, mpFuchsia, mpLime, mpAqua,
  mpOlive
}
 Enumeration of classic colour.
 

Functions

struct deprecated ("No more used, X and Y are now separated")]] mpFloatRect
 A structure for computation of bounds in real units (not in screen pixel) X refer to X axis Y refer to Y axis. More...
 

Macro Definition Documentation

◆ mpMOUSEMODE_DRAG

#define mpMOUSEMODE_DRAG   0

Mouse panning drags the view.

Mouse mode for mpWindow.

◆ mpMOUSEMODE_ZOOMBOX

#define mpMOUSEMODE_ZOOMBOX   1

Mouse panning creates a zoom box.

Mouse mode for mpWindow.

◆ mpX_LOCALTIME

#define mpX_LOCALTIME   0x10

When setting x labels in date/time format, convert input time to local time.

◆ mpX_UTCTIME

#define mpX_UTCTIME   0x20

When setting x labels in date/time format, convert input time to UTC time (or just leave it raw).

◆ X_BORDER_SEPARATION

#define X_BORDER_SEPARATION   40

This directive allow the user to add a custom include.

For example, this can be useful if you have your own I18N management system MP_USER_INCLUDE simply needs to contain the name of the include file without the .h extension. A simple plot component for wxWidgets

Typedef Documentation

◆ mpDeleteAction

Action to do with the object associated to the layer when we delete it.

We can:

  • mpNoDelete: keep the object
  • mpYesDelete: delete the object if CanDelete is true
  • mpForceDelete: delete the object in any cases

◆ mpOnDeleteLayer

typedef std::function<void(void *Sender, const wxString &classname, bool &cancel)> mpOnDeleteLayer

Define an event for when we delete a layer.

Parameters
Senderthe mpWindow
classnamethe class name of the object we want to delete
cancelif true, the deletion is canceled (default false) Use like this : your_plot->SetOnDeleteLayer([this](void *Sender, const wxString &classname, bool &cancel) { your_event_function(Sender, classname, cancel);});

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Command IDs used by mpWindow Same order for the popup menu.

Enumerator
mpID_FIT 

Fit view to match bounding box of all layers.

mpID_ZOOM_IN 

Zoom into view at clickposition / window center.

mpID_ZOOM_OUT 

Zoom out.

mpID_CENTER 

Center view on click position.

mpID_LOCKASPECT 

Lock x/y scaling aspect.

mpID_TOGGLE_GRID 

Show/Hide grids.

mpID_TOGGLE_COORD 

Show/Hide info coord.

mpID_SCREENSHOT 

Copy a screen shot to the clipboard.

mpID_LOAD_FILE 

Load a file.

mpID_HELP_MOUSE 

Shows information about the mouse commands.

mpID_FULLSCREEN 

Toggle fullscreen only if parent is a frame windows.

◆ __Chart_Type

sub_type values for mpLAYER_CHART

Enumerator
mpcChartNone 

sub type not defined (should be never used)

mpcBarChart 

sub type for mpBarChart

mpcPieChart 

sub type for mpPieChart

mpcAllType 

sub type for all layers who are chart.

See also
mpChart

◆ __Function_Type

sub_type values for mpLAYER_PLOT and mpLAYER_LINE

Enumerator
mpfNone 

sub type not defined (should be never used)

mpfFX 

sub type for mpFX function

mpfFY 

sub type for mpFY function

mpfFXY 

sub type for mpFXY function

mpfFXYVector 

sub type for mpFXYVector function

mpfMovable 

sub type for mpMovableObject function

mpfLine 

sub type for mpLine function

mpfAllType 

sub type for all layers who are function.

See also
mpFunction

◆ __Info_Type

sub_type values for mpLAYER_INFO

Enumerator
mpiNone 

sub type not defined (should be never used)

mpiInfo 

sub type for mpInfoLayer layer

mpiCoords 

sub type for mpInfoCoords layer

mpiLegend 

sub type for mpInfoLegend layer

◆ __mp_Delete_Action

Action to do with the object associated to the layer when we delete it.

We can:

  • mpNoDelete: keep the object
  • mpYesDelete: delete the object if CanDelete is true
  • mpForceDelete: delete the object in any cases
Enumerator
mpNoDelete 

Keep the object, just remove the layer from the layer list.

mpYesDelete 

Delete the object if CanDelete is true and remove it from the layer list.

mpForceDelete 

Delete the object regardless of the CanDelete value and remove it from the layer list.

◆ __mp_Direction_Type

Direction for the Legend layer.

Enumerator
mpVertical 

each visible plot is described on its own line, one above the other

mpHorizontal 

legend components follow each other horizontally on a single line

◆ __mp_Layer_Type

< Major type of an mpLayer (detail is in subtype)

Enumerator
mpLAYER_UNDEF 

Layer type undefined; SHOULD NOT BE USED.

mpLAYER_AXIS 

Axis type layer.

mpLAYER_PLOT 

Plot type layer.

mpLAYER_INFO 

Info box type layer.

mpLAYER_TEXT 

Text box type layer.

mpLAYER_BITMAP 

Bitmap type layer.

mpLAYER_LINE 

Line (horizontal or vertical) type layer.

mpLAYER_CHART 

Chart type layer (bar chart)

◆ __mp_Layer_ZOrder

Z order for drawing layer Background is the deeper (bitmap layer) Then draw axis, custom layer, function, info (info, coord, legend, ...) and finally text (text, title)

Enumerator
mpZIndex_BACKGROUND 

Bitmap type layer.

mpZIndex_AXIS 

Axis type layer.

mpZIndex_LINE 

Line (horizontal or vertical) type layer.

mpZIndex_PLOT 

Plot (function) type layer.

mpZIndex_CHART 

Chart type layer.

mpZIndex_INFO 

Info box type layer.

mpZIndex_TEXT 

Text box type layer.

mpZIndex_END 

Just the end of ZOrder.

◆ __mp_Location_Type

Location for the Info layer.

Enumerator
mpMarginLeftCenter 

Align the info in margin center-left.

mpMarginTopLeft 

Align the info in margin top-left.

mpMarginTopCenter 

Align the info in margin center-top.

mpMarginTopRight 

Align the info in margin top-right.

mpMarginRightCenter 

Align the info in margin center-right.

mpMarginBottomLeft 

Align the info in margin bottom-left.

mpMarginBottomCenter 

Align the info in margin center-bottom.

mpMarginBottomRight 

Align the info in margin bottom-right.

mpMarginNone 

No alignment.

mpCursor 

only for mpInfoCoords

◆ __mp_Style_Type

Style for the Legend layer.

Enumerator
mpLegendLine 

Show legend items with line with the same pen of referred mpLayer.

mpLegendSquare 

Show legend items with small square with the same color of referred mpLayer.

mpLegendSymbol 

Show legend items with symbol used with the referred mpLayer.

◆ __Plot_Align_Name_Type

Plot alignment (which corner should plot be placed)

Enumerator
mpALIGN_NW 

Align the plot label towards the northwest.

mpALIGN_NE 

Align the plot label towards the northeast.

mpALIGN_SE 

Align the plot label towards the southeast.

mpALIGN_SW 

Align the plot label towards the southwest.

◆ __Scale_Type

sub_type values for mpLAYER_AXIS

Enumerator
mpsScaleNone 

sub type not defined (should be never used)

mpsScaleX 

sub type for mpScaleX

mpsScaleY 

sub type for mpScaleY

mpsAllType 

sub type for all layers who are scale.

See also
mpScale

◆ __Symbol_Type

Displaying a symbol instead of a point in the plot function.

Enumerator
mpsNone 

No symbol is drawing.

mpsCircle 

Draw a circle.

mpsSquare 

Draw a square.

mpsUpTriangle 

Draw a triangle up oriented.

mpsDownTriangle 

Draw a triangle down oriented.

mpsCross 

Draw a cross X.

mpsPlus 

Draw a plus +.

◆ __Text_Type

sub_type values for mpLAYER_TEXT

Enumerator
mptNone 

sub type not defined (should be never used)

mptText 

sub type for mpText layer

mptTitle 

sub type for mpTitle layer

◆ __XAxis_Align_Type

Alignment for X axis.

Enumerator
mpALIGN_BORDER_BOTTOM 

Align the x-axis towards bottom border.

mpALIGN_BOTTOM 

Align the x-axis towards bottom plot.

mpALIGN_CENTERX 

Align the x-axis center plot.

mpALIGN_TOP 

Align the x-axis towards top plot.

mpALIGN_BORDER_TOP 

Align the x-axis towards top border.

◆ __YAxis_Align_Type

Alignment for Y axis.

Enumerator
mpALIGN_BORDER_LEFT 

Align the y-axis towards left border.

mpALIGN_LEFT 

Align the y-axis towards left plot.

mpALIGN_CENTERY 

Align the y-axis center plot.

mpALIGN_RIGHT 

Align the y-axis towards right plot.

mpALIGN_BORDER_RIGHT 

Align the y-axis towards right border.

◆ mpAxisUpdate

Define the axis we want to update.

Could be:

  • x axis
  • y axis
  • x and y axis

◆ mpLabelType

enum for label for grid

Enumerator
mpLabel_AUTO 

Set label for axis in auto mode, automatically switch between decimal and scientific notation.

mpLabel_DECIMAL 

Set label for axis in decimal notation, with number of decimals automatically calculated based on zoom level.

mpLabel_SCIENTIFIC 

Set label for axis in scientific notation.

mpLabel_TIME 

Set label for axis in time mode: the value is represented as minutes:seconds.milliseconds if time is less than 2 minutes, hours:minutes:seconds otherwise.

mpLabel_HOURS 

Set label for axis in hours mode: the value is always represented as hours:minutes:seconds.

mpLabel_DATE 

Set label for axis in date mode: the value is always represented as yyyy-mm-dd.

mpLabel_DATETIME 

Set label for axis in datetime mode: the value is always represented as yyyy-mm-ddThh:mm:ss.

mpLabel_USER 

Set label user defined.

mpLabel_NONE 

Set no label for axis (useful for bar)

◆ mpMouseButtonAction

enum for left button mouse action: box zoom or drag

Enumerator
mpMouseBoxZoom 

Mouse action draw a box to zoom inside.

mpMouseDragZoom 

Mouse action drag the plot.

Function Documentation

◆ deprecated()

struct deprecated ( "No more  used,
X and Y are now separated"   
)

A structure for computation of bounds in real units (not in screen pixel) X refer to X axis Y refer to Y axis.

< range over x direction

< array of range over all y directions

Constructs a new mpFloatRect using it parent mpWindow to obtain the number of Y-scales to use. This makes sure that the y-size always matches the parant mpWindow y-size

Parameters
wparent mpWindow from which to obtain informations

Only allow constructor with mpWindow supplied

Is point inside this bounding box?

Parameters
pxx-coordinate
pyy-coordinate
yAxisIDthe y-axis ID (default 0, the first y axis)

Update bounding box to include this point

Parameters
pxx-coordinate
pyy-coordinate
yAxisIDthe y-axis ID (default 0, the first y axis)

Initialize bounding box with an initial point

Parameters
pxx-coordinate
pyy-coordinate
yAxisIDthe y-axis ID (default 0, the first y axis)

Is mpFloatRect set ?

Equal operator