KiCad PCB EDA Suite
mpScaleX Class Reference

#include <mathplot.h>

Inheritance diagram for mpScaleX:
mpScaleXBase mpScaleBase mpLayer FREQUENCY_LIN_SCALE TIME_SCALE VOLTAGE_SCALE_X

Public Member Functions

 mpScaleX (wxString name=wxT("X"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
 Full constructor. More...
 
virtual double TransformToPlot (double x) override
 Layer plot handler. More...
 
virtual double TransformFromPlot (double xplot) override
 
virtual bool IsHorizontal () override
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Layer plot handler. More...
 
virtual void getVisibleDataRange (mpWindow &w, double &minV, double &maxV) override
 
bool HasBBox () override
 Check whether this layer has a bounding box. More...
 
void SetAlign (int align)
 Set X axis alignment. More...
 
void SetNameAlign (int align)
 
void SetTicks (bool enable)
 Set X axis ticks or grid. More...
 
bool GetTicks ()
 Get X axis ticks or grid. More...
 
void SetDataRange (double minV, double maxV)
 
void GetDataRange (double &minV, double &maxV)
 
void ExtendDataRange (double minV, double maxV)
 
void ResetDataRange ()
 
double AbsMaxValue () const
 
double AbsVisibleMaxValue () const
 
std::vector< TickLabel > & TickLabels ()
 
virtual bool IsInfo ()
 Check whether the layer is an info box. More...
 
virtual double GetMinX ()
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX ()
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY ()
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY ()
 Get inclusive top border of bounding box. More...
 
const wxString & GetName () const
 Get layer name. More...
 
const wxFont & GetFont () const
 Get font set for this layer. More...
 
const wxPen & GetPen () const
 Get pen set for this layer. More...
 
void SetContinuity (bool continuity)
 Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points). More...
 
bool GetContinuity () const
 Gets the 'continuity' property of the layer. More...
 
void ShowName (bool show)
 Shows or hides the text label with the name of the layer (default is visible). More...
 
void SetName (wxString name)
 Set layer name. More...
 
void SetFont (wxFont &font)
 Set layer font. More...
 
void SetPen (wxPen pen)
 Set layer pen. More...
 
void SetDrawOutsideMargins (bool drawModeOutside)
 Set Draw mode: inside or outside margins. More...
 
bool GetDrawOutsideMargins ()
 Get Draw mode: inside or outside margins. More...
 
wxBitmap GetColourSquare (int side=16)
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType ()
 Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value. More...
 
bool IsVisible ()
 Checks whether the layer is visible or not. More...
 
void SetVisible (bool show)
 Sets layer visibility. More...
 
const wxBrush & GetBrush () const
 Get brush set for this layer. More...
 
void SetBrush (wxBrush brush)
 Set layer brush. More...
 

Protected Member Functions

virtual void recalculateTicks (wxDC &dc, mpWindow &w) override
 
void updateTickLabels (wxDC &dc, mpWindow &w)
 
void computeLabelExtents (wxDC &dc, mpWindow &w)
 
int tickCount () const
 
virtual int labelCount () const
 
virtual const wxString formatLabel (double value, int nDigits)
 
virtual void formatLabels ()
 
virtual double getTickPos (int n)
 
virtual double getLabelPos (int n)
 
virtual const wxString getLabel (int n)
 

Protected Attributes

std::vector< double > m_tickValues
 
std::vector< TickLabelm_tickLabels
 
double m_offset
 
double m_scale
 
double m_absVisibleMaxV
 
int m_flags
 
int m_nameFlags
 
bool m_ticks
 
double m_minV
 
double m_maxV
 
bool m_rangeSet
 
int m_maxLabelHeight
 
int m_maxLabelWidth
 
wxFont m_font
 
wxPen m_pen
 
wxBrush m_brush
 
wxString m_name
 
bool m_continuous
 
bool m_showName
 
bool m_drawOutsideMargins
 
mpLayerType m_type
 
bool m_visible
 

Detailed Description

Definition at line 866 of file mathplot.h.

Constructor & Destructor Documentation

mpScaleX::mpScaleX ( wxString  name = wxT("X"),
int  flags = mpALIGN_CENTER,
bool  ticks = true,
unsigned int  type = mpX_NORMAL 
)

Full constructor.

Parameters
nameLabel to plot by the ruler
flagsSet the position of the scale with respect to the window.
ticksSelect ticks or grid. Give TRUE (default) for drawing axis ticks, FALSE for drawing the grid.
typempX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.

Definition at line 1288 of file mathplot.cpp.

1288  :
1289  mpScaleXBase( name, flags, ticks, type )
1290 {
1291 };
const char * name
mpScaleXBase(wxString name=wxT("X"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
Definition: mathplot.cpp:1276

Member Function Documentation

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 761 of file mathplot.h.

References abs, and max.

762  {
763  return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
764  }
double m_maxV
Definition: mathplot.h:833
#define abs(a)
Definition: auxiliary.h:84
double m_minV
Definition: mathplot.h:833
#define max(a, b)
Definition: auxiliary.h:86
double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 766 of file mathplot.h.

Referenced by formatSILabels().

767  {
768  return m_absVisibleMaxV;
769  }
double m_absVisibleMaxV
Definition: mathplot.h:829
void mpScaleBase::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 960 of file mathplot.cpp.

References mpScaleBase::getLabel(), mpScaleBase::labelCount(), mpScaleBase::m_maxLabelHeight, mpScaleBase::m_maxLabelWidth, and max.

Referenced by mpScaleBase::updateTickLabels().

961 {
962  // printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
963  m_maxLabelHeight = 0;
964  m_maxLabelWidth = 0;
965 
966  for( int n = 0; n < labelCount(); n++ )
967  {
968  int tx, ty;
969  const wxString s = getLabel( n );
970 
971  dc.GetTextExtent( s, &tx, &ty );
974  }
975 }
int m_maxLabelHeight
Definition: mathplot.h:835
int m_maxLabelWidth
Definition: mathplot.h:836
virtual int labelCount() const
Definition: mathplot.h:802
virtual const wxString getLabel(int n)
Definition: mathplot.h:820
#define max(a, b)
Definition: auxiliary.h:86
void mpScaleBase::ExtendDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 735 of file mathplot.h.

References max, and min.

Referenced by mpFXY::UpdateScales().

736  {
737  if( !m_rangeSet )
738  {
739  m_minV = minV;
740  m_maxV = maxV;
741  m_rangeSet = true;
742  }
743  else
744  {
745  m_minV = std::min( minV, m_minV );
746  m_maxV = std::max( maxV, m_maxV );
747  }
748 
749  if( m_minV == m_maxV )
750  {
751  m_minV = -1.0;
752  m_maxV = 1.0;
753  }
754  }
double m_maxV
Definition: mathplot.h:833
bool m_rangeSet
Definition: mathplot.h:834
double m_minV
Definition: mathplot.h:833
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85
virtual const wxString mpScaleBase::formatLabel ( double  value,
int  nDigits 
)
inlineprotectedvirtualinherited

Definition at line 807 of file mathplot.h.

807 { return wxT( "" ); }
virtual void mpScaleBase::formatLabels ( )
inlineprotectedvirtualinherited
const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 305 of file mathplot.h.

305 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:315
wxBitmap mpLayer::GetColourSquare ( int  side = 16)
inherited

Get a small square bitmap filled with the colour of the pen used in the layer.

Useful to create legends or similar reference to the layers.

Parameters
sideside length in pixels
Returns
a wxBitmap filled with layer's colour

Definition at line 82 of file mathplot.cpp.

References mpLayer::m_pen, and square().

83 {
84  wxBitmap square( side, side, -1 );
85  wxColour filler = m_pen.GetColour();
86  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
87  wxMemoryDC dc;
88 
89  dc.SelectObject( square );
90  dc.SetBackground( brush );
91  dc.Clear();
92  dc.SelectObject( wxNullBitmap );
93  return square;
94 }
static double square(int x)
Definition: trigo.cpp:138
wxPen m_pen
Definition: mathplot.h:314
bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 257 of file mathplot.h.

257 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:317
void mpScaleBase::GetDataRange ( double &  minV,
double &  maxV 
)
inlineinherited

Definition at line 729 of file mathplot.h.

Referenced by recalculateTicks(), mpScaleXLog::recalculateTicks(), and mpScaleY::recalculateTicks().

730  {
731  minV = m_minV;
732  maxV = m_maxV;
733  }
double m_maxV
Definition: mathplot.h:833
double m_minV
Definition: mathplot.h:833
bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 284 of file mathplot.h.

284 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 242 of file mathplot.h.

242 { return m_font; }
wxFont m_font
Definition: mathplot.h:309
virtual const wxString mpScaleBase::getLabel ( int  n)
inlineprotectedvirtualinherited

Definition at line 820 of file mathplot.h.

Referenced by mpScaleBase::computeLabelExtents(), and mpScaleY::Plot().

821  {
822  return m_tickLabels[n].label;
823  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
virtual double mpScaleBase::getLabelPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 815 of file mathplot.h.

Referenced by mpScaleXBase::Plot(), and mpScaleY::Plot().

816  {
817  return m_tickLabels[n].pos;
818  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
mpLayerType mpLayer::GetLayerType ( )
inlineinherited

Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.

Returns
An integer indicating layer type

Definition at line 293 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

293 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:320
virtual double mpLayer::GetMaxX ( )
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 179 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

179 { return 1.0; }
virtual double mpLayer::GetMaxY ( )
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 189 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

189 { return 1.0; }
virtual double mpLayer::GetMinX ( )
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 174 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

174 { return -1.0; }
virtual double mpLayer::GetMinY ( )
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 184 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

184 { return -1.0; }
const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 237 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::GetLabelX(), SIM_PLOT_PANEL::GetLabelY1(), SIM_PLOT_PANEL::GetLabelY2(), mpInfoLegend::Plot(), and mpText::Plot().

237 { return m_name; }
wxString m_name
Definition: mathplot.h:316
const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 247 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

247 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:314
virtual double mpScaleBase::getTickPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 810 of file mathplot.h.

Referenced by mpScaleXBase::Plot(), and mpScaleY::Plot().

811  {
812  return m_tickValues[n];
813  }
std::vector< double > m_tickValues
Definition: mathplot.h:825
bool mpScaleBase::GetTicks ( )
inlineinherited

Get X axis ticks or grid.

Returns
TRUE if plot is drawing axis ticks, FALSE if the grid is active.

Definition at line 716 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::IsGridShown().

716 { return m_ticks; };
bool m_ticks
Definition: mathplot.h:832
void mpScaleXBase::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 1215 of file mathplot.cpp.

References mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetScrX(), mpLayer::m_drawOutsideMargins, mpWindow::p2x(), and mpScaleBase::TransformFromPlot().

Referenced by recalculateTicks(), and mpScaleXLog::recalculateTicks().

1216 {
1217  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1218  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1219 
1220  // printf("getVisibleDataRange\n");
1221 
1222  double pxmin = w.p2x( startPx );
1223  double pxmax = w.p2x( endPx );
1224 
1225  minV = TransformFromPlot( pxmin );
1226  maxV = TransformFromPlot( pxmax );
1227 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1185
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1131
bool m_drawOutsideMargins
Definition: mathplot.h:319
int GetMarginRight()
Definition: mathplot.h:1348
int GetMarginLeft()
Definition: mathplot.h:1352
virtual double TransformFromPlot(double xplot)
Definition: mathplot.h:772
bool mpScaleBase::HasBBox ( )
inlineoverridevirtualinherited

Check whether this layer has a bounding box.

The default implementation returns TRUE. Override and return FALSE if your mpLayer implementation should be ignored by the calculation of the global bounding box for all layers in a mpWindow.

Return values
TRUEHas bounding box
FALSEHas not bounding box

Reimplemented from mpLayer.

Reimplemented in mpScaleY.

Definition at line 698 of file mathplot.h.

698 { return FALSE; }
virtual bool mpScaleXBase::IsHorizontal ( )
inlineoverridevirtualinherited

Implements mpScaleBase.

Definition at line 852 of file mathplot.h.

852 { return true; }
virtual bool mpLayer::IsInfo ( )
inlinevirtualinherited

Check whether the layer is an info box.

The default implementation returns FALSE. It is overrided to TRUE for mpInfoLayer class and its derivative. It is necessary to define mouse actions behaviour over info boxes.

Returns
whether the layer is an info boxes
See also
mpInfoLayer::IsInfo

Reimplemented in mpInfoLayer.

Definition at line 169 of file mathplot.h.

169 { return false; };
bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 297 of file mathplot.h.

Referenced by mpWindow::IsLayerVisible(), SIM_PLOT_PANEL::IsLegendShown(), and mpInfoLegend::Plot().

297 { return m_visible; };
bool m_visible
Definition: mathplot.h:321
virtual int mpScaleBase::labelCount ( ) const
inlineprotectedvirtualinherited

Definition at line 802 of file mathplot.h.

Referenced by mpScaleBase::computeLabelExtents(), mpScaleXBase::Plot(), and mpScaleY::Plot().

803  {
804  return m_tickLabels.size();
805  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
void mpScaleXBase::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtualinherited

Layer plot handler.

This implementation will plot the ruler adjusted to the visible area.

2;

Implements mpLayer.

Definition at line 1300 of file mathplot.cpp.

References mpScaleBase::getLabelPos(), mpWindow::GetMarginBottom(), mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetMarginTop(), mpWindow::GetPosX(), mpWindow::GetScaleX(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpScaleBase::getTickPos(), mpScaleBase::labelCount(), mpLayer::m_drawOutsideMargins, mpScaleBase::m_flags, mpLayer::m_font, mpScaleBase::m_maxLabelHeight, mpScaleBase::m_maxV, mpScaleBase::m_minV, mpLayer::m_name, mpScaleBase::m_nameFlags, mpScaleBase::m_offset, mpLayer::m_pen, mpScaleBase::m_scale, mpScaleBase::m_tickLabels, mpScaleBase::m_ticks, mpLayer::m_visible, mpALIGN_BORDER_BOTTOM, mpALIGN_BORDER_TOP, mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP, mpScaleBase::recalculateTicks(), mpScaleBase::tickCount(), mpScaleBase::TransformToPlot(), X_BORDER_SEPARATION, and mpWindow::y2p().

1301 {
1302  int tx, ty;
1303 
1304  m_offset = -m_minV;
1305  m_scale = 1.0 / ( m_maxV - m_minV );
1306 
1307  recalculateTicks( dc, w );
1308 
1309  if( m_visible )
1310  {
1311  dc.SetPen( m_pen );
1312  dc.SetFont( m_font );
1313  int orgy = 0;
1314 
1315  const int extend = w.GetScrX();
1316 
1317  if( m_flags == mpALIGN_CENTER )
1318  orgy = w.y2p( 0 ); // (int)(w.GetPosY() * w.GetScaleY());
1319 
1320  if( m_flags == mpALIGN_TOP )
1321  {
1322  if( m_drawOutsideMargins )
1323  orgy = X_BORDER_SEPARATION;
1324  else
1325  orgy = w.GetMarginTop();
1326  }
1327 
1328  if( m_flags == mpALIGN_BOTTOM )
1329  {
1330  if( m_drawOutsideMargins )
1331  orgy = X_BORDER_SEPARATION;
1332  else
1333  orgy = w.GetScrY() - w.GetMarginBottom();
1334  }
1335 
1337  orgy = w.GetScrY() - 1; // dc.LogicalToDeviceY(0) - 1;
1338 
1339  if( m_flags == mpALIGN_BORDER_TOP )
1340  orgy = 1; // -dc.LogicalToDeviceY(0);
1341 
1342  // dc.DrawLine( 0, orgy, w.GetScrX(), orgy);
1343 
1344  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1345  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1346  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1347  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1348 
1349  // printf("StartPx %d endPx %d ordy %d maxy %d\n", startPx, endPx, orgy, maxYpx);
1350 
1351  // int tmp=-65535;
1352  int labelH = m_maxLabelHeight; // Control labels heigth to decide where to put axis name (below labels or on top of axis)
1353 
1354  // int maxExtent = tc.MaxLabelWidth();
1355  // printf("Ticks : %d\n",labelCount());
1356  for( int n = 0; n < tickCount(); n++ )
1357  {
1358  double tp = getTickPos( n );
1359 
1360  // double xlogmin = log10 ( m_minV );
1361  // double xlogmax = log10 ( m_maxV );
1362 
1363  double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1364 
1365  const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
1366 
1367 #ifdef MATHPLOT_DO_LOGGING
1368  wxLogMessage( wxT( "mpScaleX::Plot: n: %f -> p = %d" ), n, p );
1369 #endif
1370 
1371  if( (p >= startPx) && (p <= endPx) )
1372  {
1373  if( m_ticks ) // draw axis ticks
1374  {
1376  dc.DrawLine( p, orgy, p, orgy - 4 );
1377  else
1378  dc.DrawLine( p, orgy, p, orgy + 4 );
1379  }
1380  else // draw grid dotted lines
1381  {
1382  m_pen.SetStyle( wxPENSTYLE_DOT );
1383  dc.SetPen( m_pen );
1384 
1386  {
1387  // printf("d1");
1388  m_pen.SetStyle( wxPENSTYLE_DOT );
1389  dc.SetPen( m_pen );
1390  dc.DrawLine( p, orgy + 4, p, minYpx );
1391  m_pen.SetStyle( wxPENSTYLE_SOLID );
1392  dc.SetPen( m_pen );
1393  dc.DrawLine( p, orgy + 4, p, orgy - 4 );
1394  }
1395  else
1396  {
1398  {
1399  // printf("d2");
1400  dc.DrawLine( p, orgy - 4, p, maxYpx );
1401  }
1402  else
1403  {
1404  // printf("d3");
1405  dc.DrawLine( p, minYpx, p, maxYpx ); // 0/*-w.GetScrY()*/, p, w.GetScrY() );
1406  }
1407  }
1408 
1409  m_pen.SetStyle( wxPENSTYLE_SOLID );
1410  dc.SetPen( m_pen );
1411  }
1412  }
1413  }
1414 
1415  m_pen.SetStyle( wxPENSTYLE_SOLID );
1416  dc.SetPen( m_pen );
1417  dc.DrawLine( startPx, minYpx, endPx, minYpx );
1418  dc.DrawLine( startPx, maxYpx, endPx, maxYpx );
1419 
1420  // printf("Labels : %d\n",labelCount());
1421  // Actually draw labels, taking care of not overlapping them, and distributing them regularly
1422  for( int n = 0; n < labelCount(); n++ )
1423  {
1424  double tp = getLabelPos( n );
1425 
1426  if( !m_tickLabels[n].visible )
1427  continue;
1428 
1429  // double xlogmin = log10 ( m_minV );
1430  // double xlogmax = log10 ( m_maxV );
1431 
1432  double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1433 
1434  const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
1435 
1436  // printf("p %d %.1f\n", p, px);
1437 #ifdef MATHPLOT_DO_LOGGING
1438  wxLogMessage( wxT( "mpScaleX::Plot: n_label = %f -> p_label = %d" ), n, p );
1439 #endif
1440 
1441  if( (p >= startPx) && (p <= endPx) )
1442  {
1443  // Write ticks labels in s string
1444  wxString s = m_tickLabels[n].label;
1445 
1446  dc.GetTextExtent( s, &tx, &ty );
1447 
1449  {
1450  dc.DrawText( s, p - tx / 2, orgy - 4 - ty );
1451  }
1452  else
1453  {
1454  dc.DrawText( s, p - tx / 2, orgy + 4 );
1455  }
1456  }
1457  }
1458 
1459  // Draw axis name
1460  dc.GetTextExtent( m_name, &tx, &ty );
1461 
1462  switch( m_nameFlags )
1463  {
1464  case mpALIGN_BORDER_BOTTOM:
1465  dc.DrawText( m_name, extend - tx - 4, orgy - 8 - ty - labelH );
1466  break;
1467 
1468  case mpALIGN_BOTTOM:
1469  {
1470  dc.DrawText( m_name, (endPx + startPx) / 2 - tx / 2, orgy + 6 + labelH );
1471  }
1472  break;
1473 
1474  case mpALIGN_CENTER:
1475  dc.DrawText( m_name, extend - tx - 4, orgy - 4 - ty );
1476  break;
1477 
1478  case mpALIGN_TOP:
1479  {
1480  if( (!m_drawOutsideMargins) && ( w.GetMarginTop() > (ty + labelH + 8) ) )
1481  {
1482  dc.DrawText( m_name, (endPx - startPx - tx) >> 1, orgy - 6 - ty - labelH );
1483  }
1484  else
1485  {
1486  dc.DrawText( m_name, extend - tx - 4, orgy + 4 );
1487  }
1488  }
1489  break;
1490 
1491  case mpALIGN_BORDER_TOP:
1492  dc.DrawText( m_name, extend - tx - 4, orgy + 6 + labelH );
1493  break;
1494 
1495  default:
1496  break;
1497  }
1498  }
1499 }
double m_maxV
Definition: mathplot.h:833
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
Definition: mathplot.h:795
bool m_ticks
Definition: mathplot.h:832
int tickCount() const
Definition: mathplot.h:797
double m_offset
Definition: mathplot.h:828
int m_maxLabelHeight
Definition: mathplot.h:835
int GetMarginBottom()
Definition: mathplot.h:1350
int m_flags
Definition: mathplot.h:830
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1140
bool m_visible
Definition: mathplot.h:321
#define X_BORDER_SEPARATION
Definition: mathplot.h:93
#define mpALIGN_BORDER_TOP
Aligns X axis to top border.
Definition: mathplot.h:488
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1200
int GetMarginTop()
Definition: mathplot.h:1346
virtual int labelCount() const
Definition: mathplot.h:802
double GetPosX(void) const
Definition: mathplot.h:1116
virtual double getLabelPos(int n)
Definition: mathplot.h:815
#define mpALIGN_TOP
Aligns label to the top.
Definition: mathplot.h:482
wxFont m_font
Definition: mathplot.h:309
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1131
double m_minV
Definition: mathplot.h:833
double GetScaleX(void) const
Definition: mathplot.h:1102
bool m_drawOutsideMargins
Definition: mathplot.h:319
int GetMarginRight()
Definition: mathplot.h:1348
int GetMarginLeft()
Definition: mathplot.h:1352
#define mpALIGN_BORDER_BOTTOM
Aligns X axis to bottom border.
Definition: mathplot.h:486
double m_scale
Definition: mathplot.h:828
virtual double TransformToPlot(double x)
Definition: mathplot.h:771
wxPen m_pen
Definition: mathplot.h:314
#define mpALIGN_BOTTOM
Aligns label to the bottom.
Definition: mathplot.h:484
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:478
wxString m_name
Definition: mathplot.h:316
int m_nameFlags
Definition: mathplot.h:831
virtual double getTickPos(int n)
Definition: mathplot.h:810
void mpScaleX::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
overrideprotectedvirtual

Reimplemented from mpScaleBase.

Definition at line 858 of file mathplot.cpp.

References abs, mpScaleBase::GetDataRange(), mpScaleXBase::getVisibleDataRange(), mpScaleBase::m_absVisibleMaxV, mpScaleBase::m_tickLabels, mpScaleBase::m_tickValues, max, and mpScaleBase::updateTickLabels().

859 {
860  double minV, maxV, minVvis, maxVvis;
861 
862  GetDataRange( minV, maxV );
863  getVisibleDataRange( w, minVvis, maxVvis );
864 
865  m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
866 
867  // printf("minV %.10f maxV %.10f %.10f %.10f\n", minV, maxV, minVvis, maxVvis);
868 
869  m_tickValues.clear();
870  m_tickLabels.clear();
871 
872  double minErr = 1000000000000.0;
873  double bestStep = 1.0;
874 
875  for( int i = 10; i <= 20; i += 2 )
876  {
877  double curr_step = fabs( maxVvis - minVvis ) / (double) i;
878  double base = pow( 10, floor( log10( curr_step ) ) );
879 
880  // printf("base %.3f\n", base);
881 
882  double stepInt = floor( curr_step / base ) * base;
883  double err = fabs( curr_step - stepInt );
884 
885  if( err < minErr )
886  {
887  minErr = err;
888  bestStep = stepInt;
889  }
890 
891  // printf("curr_step %d %.3f %.3f best %.3f\n",i, curr_step, stepInt, bestStep);
892  }
893 
894 
895  double v = floor( minVvis / bestStep ) * bestStep;
896 
897  double zeroOffset = 100000000.0;
898  // printf("maxVVis %.3f\n", maxVvis);
899 
900  while( v < maxVvis )
901  {
902  m_tickValues.push_back( v );
903 
904  if( fabs( v ) < zeroOffset )
905  zeroOffset = fabs( v );
906 
907  // printf("tick %.3f\n", v);
908  v += bestStep;
909  }
910 
911  if( zeroOffset <= bestStep )
912  {
913  for( double& t : m_tickValues )
914  t -= zeroOffset;
915  }
916 
917  for( double t : m_tickValues )
918  {
919  m_tickLabels.push_back( TickLabel( t ) );
920  }
921 
922  updateTickLabels( dc, w );
923 }
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1215
void GetDataRange(double &minV, double &maxV)
Definition: mathplot.h:729
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:978
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
#define abs(a)
Definition: auxiliary.h:84
double m_absVisibleMaxV
Definition: mathplot.h:829
#define max(a, b)
Definition: auxiliary.h:86
std::vector< double > m_tickValues
Definition: mathplot.h:825
void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 756 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::ResetScales().

757  {
758  m_rangeSet = 0;
759  }
bool m_rangeSet
Definition: mathplot.h:834
void mpScaleBase::SetAlign ( int  align)
inlineinherited

Set X axis alignment.

Parameters
alignalignment (choose between mpALIGN_BORDER_BOTTOM, mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP, mpALIGN_BORDER_TOP

Definition at line 704 of file mathplot.h.

704 { m_flags = align; };
int m_flags
Definition: mathplot.h:830
void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 309 of file mathplot.h.

309 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:315
void mpLayer::SetContinuity ( bool  continuity)
inlineinherited

Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).

See also
GetContinuity

Definition at line 252 of file mathplot.h.

Referenced by TRACE::TRACE().

252 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:317
void mpScaleBase::SetDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 722 of file mathplot.h.

723  {
724  m_rangeSet = true;
725  m_minV = minV;
726  m_maxV = maxV;
727  }
double m_maxV
Definition: mathplot.h:833
bool m_rangeSet
Definition: mathplot.h:834
double m_minV
Definition: mathplot.h:833
void mpLayer::SetDrawOutsideMargins ( bool  drawModeOutside)
inlineinherited

Set Draw mode: inside or outside margins.

Default is outside, which allows the layer to draw up to the mpWindow border.

Parameters
drawModeOutsideThe draw mode to be set

Definition at line 280 of file mathplot.h.

Referenced by CURSOR::CURSOR(), and TRACE::TRACE().

280 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 271 of file mathplot.h.

271 { m_font = font; }
wxFont m_font
Definition: mathplot.h:309
void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 266 of file mathplot.h.

References name.

266 { m_name = name; }
const char * name
wxString m_name
Definition: mathplot.h:316
void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 706 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

706 { m_nameFlags = align; }
int m_nameFlags
Definition: mathplot.h:831
void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 276 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::AddTrace().

276 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:314
void mpScaleBase::SetTicks ( bool  enable)
inlineinherited

Set X axis ticks or grid.

Parameters
enable= true to plot axis ticks, false to plot grid.

Definition at line 711 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::ShowGrid(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

711 { m_ticks = enable; };
bool m_ticks
Definition: mathplot.h:832
void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

Referenced by mpWindow::SetLayerVisible(), SIM_PLOT_PANEL::ShowLegend(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

301 { m_visible = show; };
bool m_visible
Definition: mathplot.h:321
void mpLayer::ShowName ( bool  show)
inlineinherited

Shows or hides the text label with the name of the layer (default is visible).

Definition at line 261 of file mathplot.h.

Referenced by TRACE::TRACE().

261 { m_showName = show; };
bool m_showName
Definition: mathplot.h:318
int mpScaleBase::tickCount ( ) const
inlineprotectedinherited

Definition at line 797 of file mathplot.h.

Referenced by mpScaleXBase::Plot(), and mpScaleY::Plot().

798  {
799  return m_tickValues.size();
800  }
std::vector< double > m_tickValues
Definition: mathplot.h:825
std::vector<TickLabel>& mpScaleBase::TickLabels ( )
inlineinherited

Definition at line 786 of file mathplot.h.

Referenced by FREQUENCY_LOG_SCALE::formatLabels(), and formatSILabels().

786 { return m_tickLabels; };
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
double mpScaleX::TransformFromPlot ( double  xplot)
overridevirtual

Reimplemented from mpScaleBase.

Definition at line 3289 of file mathplot.cpp.

References mpScaleBase::m_offset, and mpScaleBase::m_scale.

3290 {
3291  return xplot / m_scale - m_offset;
3292 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828
double mpScaleX::TransformToPlot ( double  x)
overridevirtual

Layer plot handler.

This implementation will plot the ruler adjusted to the visible area.

Reimplemented from mpScaleBase.

Definition at line 3283 of file mathplot.cpp.

References mpScaleBase::m_offset, and mpScaleBase::m_scale.

3284 {
3285  return (x + m_offset) * m_scale;
3286 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828
void mpScaleBase::updateTickLabels ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 978 of file mathplot.cpp.

References mpScaleBase::computeLabelExtents(), and mpScaleBase::formatLabels().

Referenced by recalculateTicks(), mpScaleXLog::recalculateTicks(), and mpScaleY::recalculateTicks().

979 {
980  formatLabels();
981  computeLabelExtents( dc, w );
982 
983  // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
984 
985  // if ( m_tickLabels.size() <= 2)
986  // return;
987 
988  /*
989  * fixme!
990  *
991  * for ( auto &l : m_tickLabels )
992  * {
993  * double p = TransformToPlot ( l.pos );
994  *
995  * if ( !IsHorizontal() )
996  * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
997  * else
998  * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
999  * }
1000  *
1001  *
1002  * for (int i = 1; i < m_tickLabels.size() - 1; i++)
1003  * {
1004  * int dist_prev;
1005  *
1006  * for(int j = i-1; j >= 1; j--)
1007  * {
1008  * if( m_tickLabels[j].visible)
1009  * {
1010  * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
1011  * break;
1012  * }
1013  * }
1014  *
1015  * if (dist_prev < gap)
1016  * m_tickLabels[i].visible = false;
1017  * }
1018  */
1019 }
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:960
virtual void formatLabels()
Definition: mathplot.h:808

Member Data Documentation

double mpScaleBase::m_absVisibleMaxV
protectedinherited
wxBrush mpLayer::m_brush
protectedinherited

Definition at line 315 of file mathplot.h.

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

Referenced by CURSOR::Plot(), mpFXY::Plot(), and mpMovableObject::Plot().

int mpScaleBase::m_flags
protectedinherited

Definition at line 830 of file mathplot.h.

Referenced by mpScaleBase::mpScaleBase(), and mpScaleXBase::Plot().

int mpScaleBase::m_maxLabelHeight
protectedinherited
int mpScaleBase::m_maxLabelWidth
protectedinherited

Definition at line 836 of file mathplot.h.

Referenced by mpScaleBase::computeLabelExtents(), and mpScaleBase::mpScaleBase().

wxString mpLayer::m_name
protectedinherited
int mpScaleBase::m_nameFlags
protectedinherited

Definition at line 831 of file mathplot.h.

Referenced by mpScaleBase::mpScaleBase(), mpScaleXBase::Plot(), and mpScaleY::Plot().

bool mpScaleBase::m_rangeSet
protectedinherited

Definition at line 834 of file mathplot.h.

Referenced by mpScaleBase::mpScaleBase().

bool mpLayer::m_showName
protectedinherited
std::vector<TickLabel> mpScaleBase::m_tickLabels
protectedinherited
bool mpScaleBase::m_ticks
protectedinherited

Definition at line 832 of file mathplot.h.

Referenced by mpScaleY::GetTicks(), mpScaleBase::mpScaleBase(), and mpScaleXBase::Plot().

std::vector<double> mpScaleBase::m_tickValues
protectedinherited
mpLayerType mpLayer::m_type
protectedinherited

Definition at line 320 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().


The documentation for this class was generated from the following files: