KiCad PCB EDA Suite
mpScaleY Class Reference

Plot layer implementing a y-scale ruler. More...

#include <mathplot.h>

Inheritance diagram for mpScaleY:
mpScaleBase mpLayer

Public Member Functions

 mpScaleY (const wxString &name=wxT("Y"), int flags=mpALIGN_CENTER, bool ticks=true)
 
virtual bool IsHorizontal () const override
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Layer plot handler. More...
 
virtual bool HasBBox () const override
 Check whether this layer has a bounding box. More...
 
void SetAlign (int align)
 Set Y axis alignment. More...
 
void SetTicks (bool ticks)
 Set Y axis ticks or grid. More...
 
bool GetTicks () const
 Get Y axis ticks or grid. More...
 
virtual double TransformToPlot (double x) const override
 
virtual double TransformFromPlot (double xplot) const override
 
void SetMasterScale (mpScaleY *masterScale)
 
void SetNameAlign (int align)
 
void SetDataRange (double minV, double maxV)
 
void GetDataRange (double &minV, double &maxV) const
 
void ExtendDataRange (double minV, double maxV)
 
void ResetDataRange ()
 
double AbsMaxValue () const
 
double AbsVisibleMaxValue () const
 
std::vector< TickLabel > & TickLabels ()
 
virtual bool IsInfo () const
 Check whether the layer is an info box. More...
 
virtual double GetMinX () const
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX () const
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY () const
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY () const
 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...
 
virtual 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) const
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType () const
 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 () const
 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 getVisibleDataRange (mpWindow &w, double &minV, double &maxV) override
 
virtual void recalculateTicks (wxDC &dc, mpWindow &w) override
 
void computeLabelExtents (wxDC &dc, mpWindow &w)
 
void computeSlaveTicks (mpWindow &w)
 
void updateTickLabels (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) const
 
virtual double getLabelPos (int n) const
 
virtual wxString getLabel (int n) const
 

Protected Attributes

mpScaleYm_masterScale
 
int m_flags
 
bool m_ticks
 
std::vector< double > m_tickValues
 
std::vector< TickLabelm_tickLabels
 
double m_offset
 
double m_scale
 
double m_absVisibleMaxV
 
int m_nameFlags
 
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

Plot layer implementing a y-scale ruler.

If align is set to mpALIGN_CENTER, the ruler is fixed at X=0 in the coordinate system. If the align is set to mpALIGN_TOP or mpALIGN_BOTTOM, the axis is always drawn respectively at top or bottom of the window. A label is plotted at the top-right hand of the ruler. The scale numbering automatically adjusts to view and zoom factor.

Definition at line 943 of file mathplot.h.

Constructor & Destructor Documentation

◆ mpScaleY()

mpScaleY::mpScaleY ( const wxString &  name = wxT( "Y" ),
int  flags = mpALIGN_CENTER,
bool  ticks = true 
)
Parameters
nameLabel to plot by the ruler
flagsSet position of the scale respect to the window.
ticksSelect ticks or grid. Give true (default) for drawing axis ticks, false for drawing the grid

Definition at line 1407 of file mathplot.cpp.

1408{
1409 SetName( name );
1410 SetFont( (wxFont&) *wxSMALL_FONT );
1411 SetPen( (wxPen&) *wxGREY_PEN );
1412 m_flags = flags;
1413 m_ticks = ticks;
1415 m_masterScale = nullptr;
1417}
const char * name
Definition: DXF_plotter.cpp:56
void SetPen(wxPen pen)
Set layer pen.
Definition: mathplot.h:277
void SetFont(wxFont &font)
Set layer font.
Definition: mathplot.h:272
mpLayerType m_type
Definition: mathplot.h:321
virtual void SetName(wxString name)
Set layer name.
Definition: mathplot.h:267
int m_nameFlags
Definition: mathplot.h:836
int m_flags
Definition: mathplot.h:1002
mpScaleY * m_masterScale
Definition: mathplot.h:998
bool m_ticks
Definition: mathplot.h:1003
@ mpLAYER_AXIS
Definition: mathplot.h:129
#define mpALIGN_BORDER_LEFT
Aligns Y axis to left border.
Definition: mathplot.h:503

References mpALIGN_BORDER_LEFT, mpLAYER_AXIS, and name.

Member Function Documentation

◆ AbsMaxValue()

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 766 of file mathplot.h.

767 {
768 return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
769 }
double m_maxV
Definition: mathplot.h:838
double m_minV
Definition: mathplot.h:838
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:418

References std::abs().

◆ AbsVisibleMaxValue()

double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 771 of file mathplot.h.

772 {
773 return m_absVisibleMaxV;
774 }
double m_absVisibleMaxV
Definition: mathplot.h:834

◆ computeLabelExtents()

void mpScaleY::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protected

◆ computeSlaveTicks()

void mpScaleY::computeSlaveTicks ( mpWindow w)
protected

Definition at line 1009 of file mathplot.cpp.

1010{
1011 if( m_masterScale->m_tickValues.size() == 0 )
1012 return;
1013
1014 m_tickValues.clear();
1015 m_tickLabels.clear();
1016
1019
1020 m_scale = 1.0 / ( m_maxV - m_minV );
1021 m_offset = -m_minV;
1022
1023 double y_slave0 = p0 / m_scale;
1024 double y_slave1 = p1 / m_scale;
1025
1026 double dy_slave = (y_slave1 - y_slave0);
1027 double exponent = floor( log10( dy_slave ) );
1028 double base = dy_slave / pow( 10.0, exponent );
1029
1030 double dy_scaled = ceil( 2.0 * base ) / 2.0 * pow( 10.0, exponent );
1031
1032 double minvv, maxvv;
1033
1034 getVisibleDataRange( w, minvv, maxvv );
1035
1036 minvv = floor( minvv / dy_scaled ) * dy_scaled;
1037
1038 m_scale = 1.0 / ( m_maxV - m_minV );
1039 m_scale *= dy_slave / dy_scaled;
1040
1041 m_offset = p0 / m_scale - minvv;
1042
1043 m_tickValues.clear();
1044
1045 double m;
1046
1047 m_absVisibleMaxV = 0;
1048
1049 for( unsigned int i = 0; i < m_masterScale->m_tickValues.size(); i++ )
1050 {
1052 m_tickValues.push_back( m );
1053 m_tickLabels.emplace_back( m );
1054 m_absVisibleMaxV = std::max( m_absVisibleMaxV, fabs( m ) );
1055 }
1056}
double m_scale
Definition: mathplot.h:833
double m_offset
Definition: mathplot.h:833
std::vector< double > m_tickValues
Definition: mathplot.h:830
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:831
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:996
virtual double TransformFromPlot(double xplot) const override
Definition: mathplot.cpp:2863
virtual double TransformToPlot(double x) const override
Definition: mathplot.cpp:2857

References getVisibleDataRange(), mpScaleBase::m_absVisibleMaxV, m_masterScale, mpScaleBase::m_maxV, mpScaleBase::m_minV, mpScaleBase::m_offset, mpScaleBase::m_scale, mpScaleBase::m_tickLabels, mpScaleBase::m_tickValues, TransformFromPlot(), and TransformToPlot().

Referenced by recalculateTicks().

◆ ExtendDataRange()

void mpScaleBase::ExtendDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 740 of file mathplot.h.

741 {
742 if( !m_rangeSet )
743 {
744 m_minV = minV;
745 m_maxV = maxV;
746 m_rangeSet = true;
747 }
748 else
749 {
750 m_minV = std::min( minV, m_minV );
751 m_maxV = std::max( maxV, m_maxV );
752 }
753
754 if( m_minV == m_maxV )
755 {
756 m_minV = m_minV - 1.0;
757 m_maxV = m_maxV + 1.0;
758 }
759 }
bool m_rangeSet
Definition: mathplot.h:839

Referenced by mpFXY::UpdateScales().

◆ formatLabel()

virtual const wxString mpScaleBase::formatLabel ( double  value,
int  nDigits 
)
inlineprotectedvirtualinherited

Definition at line 812 of file mathplot.h.

812{ return wxT( "" ); }

◆ formatLabels()

virtual void mpScaleBase::formatLabels ( )
inlineprotectedvirtualinherited

Definition at line 813 of file mathplot.h.

813{};

Referenced by mpScaleBase::updateTickLabels().

◆ GetBrush()

const wxBrush & mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 306 of file mathplot.h.

306{ return m_brush; };
wxBrush m_brush
Definition: mathplot.h:316

◆ GetColourSquare()

wxBitmap mpLayer::GetColourSquare ( int  side = 16) const
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 75 of file mathplot.cpp.

76{
77 wxBitmap square( side, side, -1 );
78 wxColour filler = m_pen.GetColour();
79 wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
80 wxMemoryDC dc;
81
82 dc.SelectObject( square );
83 dc.SetBackground( brush );
84 dc.Clear();
85 dc.SelectObject( wxNullBitmap );
86 return square;
87}
double square(double x)
wxPen m_pen
Definition: mathplot.h:315

References mpLayer::m_pen, and square().

◆ GetContinuity()

bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 258 of file mathplot.h.

258{ return m_continuous; }
bool m_continuous
Definition: mathplot.h:318

◆ GetDataRange()

void mpScaleBase::GetDataRange ( double &  minV,
double &  maxV 
) const
inlineinherited

Definition at line 734 of file mathplot.h.

735 {
736 minV = m_minV;
737 maxV = m_maxV;
738 }

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

◆ GetDrawOutsideMargins()

bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 285 of file mathplot.h.

285{ return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:320

◆ GetFont()

const wxFont & mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 243 of file mathplot.h.

243{ return m_font; }
wxFont m_font
Definition: mathplot.h:314

◆ getLabel()

virtual wxString mpScaleBase::getLabel ( int  n) const
inlineprotectedvirtualinherited

Definition at line 825 of file mathplot.h.

826 {
827 return m_tickLabels[n].label;
828 }

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

◆ getLabelPos()

virtual double mpScaleBase::getLabelPos ( int  n) const
inlineprotectedvirtualinherited

Definition at line 820 of file mathplot.h.

821 {
822 return m_tickLabels[n].pos;
823 }

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

◆ GetLayerType()

mpLayerType mpLayer::GetLayerType ( ) const
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 294 of file mathplot.h.

294{ return m_type; };

Referenced by mpInfoLegend::Plot().

◆ GetMaxX()

virtual double mpLayer::GetMaxX ( ) const
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpFXYVector, mpMovableObject, and mpBitmapLayer.

Definition at line 180 of file mathplot.h.

180{ return 1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetMaxY()

virtual double mpLayer::GetMaxY ( ) const
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpFXYVector, mpMovableObject, and mpBitmapLayer.

Definition at line 190 of file mathplot.h.

190{ return 1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetMinX()

virtual double mpLayer::GetMinX ( ) const
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpFXYVector, mpMovableObject, and mpBitmapLayer.

Definition at line 175 of file mathplot.h.

175{ return -1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetMinY()

virtual double mpLayer::GetMinY ( ) const
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpFXYVector, mpMovableObject, and mpBitmapLayer.

Definition at line 185 of file mathplot.h.

185{ return -1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetName()

const wxString & mpLayer::GetName ( void  ) const
inlineinherited

◆ GetPen()

const wxPen & mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 248 of file mathplot.h.

248{ return m_pen; }

Referenced by CURSOR::Plot(), mpInfoLegend::Plot(), and SIMULATOR_FRAME::rebuildSignalsGrid().

◆ getTickPos()

virtual double mpScaleBase::getTickPos ( int  n) const
inlineprotectedvirtualinherited

Definition at line 815 of file mathplot.h.

816 {
817 return m_tickValues[n];
818 }

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

◆ GetTicks()

bool mpScaleY::GetTicks ( ) const
inline

Get Y axis ticks or grid.

Returns
true if plot is drawing axis ticks, false if the grid is active.

Definition at line 975 of file mathplot.h.

975{ return m_ticks; };

Referenced by SIM_PLOT_PANEL::IsGridShown().

◆ getVisibleDataRange()

void mpScaleY::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overrideprotectedvirtual

Reimplemented from mpScaleBase.

Definition at line 996 of file mathplot.cpp.

997{
998 wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
999 wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1000
1001 double pymin = w.p2y( minYpx );
1002 double pymax = w.p2y( maxYpx );
1003
1004 minV = TransformFromPlot( pymax );
1005 maxV = TransformFromPlot( pymin );
1006}
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1199
int GetMarginTop() const
Definition: mathplot.h:1373
int GetMarginBottom() const
Definition: mathplot.h:1377
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1149

References mpWindow::GetMarginBottom(), mpWindow::GetMarginTop(), mpWindow::GetScrY(), mpLayer::m_drawOutsideMargins, mpWindow::p2y(), and TransformFromPlot().

Referenced by computeSlaveTicks(), and recalculateTicks().

◆ HasBBox()

virtual bool mpScaleY::HasBBox ( ) const
inlineoverridevirtual

Check whether this layer has a bounding box.

This implementation returns false thus making the ruler invisible to the plot layer bounding box calculation by mpWindow.

Reimplemented from mpScaleBase.

Definition at line 963 of file mathplot.h.

963{ return false; }

◆ IsHorizontal()

virtual bool mpScaleY::IsHorizontal ( ) const
inlineoverridevirtual

Implements mpScaleBase.

Definition at line 952 of file mathplot.h.

952{ return false; }

◆ IsInfo()

virtual bool mpLayer::IsInfo ( ) const
inlinevirtualinherited

Check whether the layer is an info box.

The default implementation returns false. It is overridden 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 170 of file mathplot.h.

170{ return false; };

◆ IsVisible()

bool mpLayer::IsVisible ( ) const
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 298 of file mathplot.h.

298{ return m_visible; };
bool m_visible
Definition: mathplot.h:322

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

◆ labelCount()

virtual int mpScaleBase::labelCount ( ) const
inlineprotectedvirtualinherited

Definition at line 807 of file mathplot.h.

808 {
809 return m_tickLabels.size();
810 }

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

◆ Plot()

void mpScaleY::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtual

Layer plot handler.

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

Implements mpLayer.

Definition at line 1420 of file mathplot.cpp.

1421{
1422 m_offset = -m_minV;
1423 m_scale = 1.0 / ( m_maxV - m_minV );
1424
1425 recalculateTicks( dc, w );
1426
1427 if( m_visible )
1428 {
1429 dc.SetPen( m_pen );
1430 dc.SetFont( m_font );
1431
1432 int orgx = 0;
1433
1434 // const int extend = w.GetScrY(); // /2;
1435 if( m_flags == mpALIGN_CENTER )
1436 orgx = w.x2p( 0 ); // (int)(w.GetPosX() * w.GetScaleX());
1437
1438 if( m_flags == mpALIGN_LEFT )
1439 {
1441 orgx = Y_BORDER_SEPARATION;
1442 else
1443 orgx = w.GetMarginLeft();
1444 }
1445
1446 if( m_flags == mpALIGN_RIGHT )
1447 {
1449 orgx = w.GetScrX() - Y_BORDER_SEPARATION;
1450 else
1451 orgx = w.GetScrX() - w.GetMarginRight();
1452 }
1453
1454 if( m_flags == mpALIGN_FAR_RIGHT )
1455 orgx = w.GetScrX() - ( w.GetMarginRight() / 2 );
1456
1458 orgx = w.GetScrX() - 1; // dc.LogicalToDeviceX(0) - 1;
1459
1461 orgx = 1; // -dc.LogicalToDeviceX(0);
1462
1463 wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1464 wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1465 wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1466 // Draw line
1467 dc.DrawLine( orgx, minYpx, orgx, maxYpx );
1468
1469
1470 wxCoord tx, ty;
1471 wxString s;
1472 wxString fmt;
1473 int n = 0;
1474
1475
1476 int labelW = 0;
1477 // Before staring cycle, calculate label height
1478 int labelHeight = 0;
1479 s.Printf( fmt, n );
1480 dc.GetTextExtent( s, &tx, &labelHeight );
1481
1482 for( n = 0; n < tickCount(); n++ )
1483 {
1484 double tp = getTickPos( n );
1485
1486 double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1487 const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1488
1489
1490 if( (p >= minYpx) && (p <= maxYpx) )
1491 {
1492 if( m_ticks ) // Draw axis ticks
1493 {
1495 {
1496 dc.DrawLine( orgx, p, orgx + 4, p );
1497 }
1498 else
1499 {
1500 dc.DrawLine( orgx - 4, p, orgx, p ); // ( orgx, p, orgx+4, p);
1501 }
1502 }
1503 else
1504 {
1505 dc.DrawLine( orgx - 4, p, orgx + 4, p );
1506
1507 m_pen.SetStyle( wxPENSTYLE_DOT );
1508 dc.SetPen( m_pen );
1509
1510 dc.DrawLine( orgx - 4, p, endPx, p );
1511
1512 m_pen.SetStyle( wxPENSTYLE_SOLID );
1513 dc.SetPen( m_pen );
1514 }
1515
1516 // Print ticks labels
1517 }
1518 }
1519
1520 for( n = 0; n < labelCount(); n++ )
1521 {
1522 double tp = getLabelPos( n );
1523
1524 double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1525 const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1526
1527 if( !m_tickLabels[n].visible )
1528 continue;
1529
1530 if( (p >= minYpx) && (p <= maxYpx) )
1531 {
1532 s = getLabel( n );
1533 dc.GetTextExtent( s, &tx, &ty );
1534
1536 dc.DrawText( s, orgx + 4, p - ty / 2 );
1537 else
1538 dc.DrawText( s, orgx - 4 - tx, p - ty / 2 ); // ( s, orgx+4, p-ty/2);
1539 }
1540 }
1541
1542 // Draw axis name
1543 // Draw axis name
1544
1545 dc.GetTextExtent( m_name, &tx, &ty );
1546
1547 switch( m_nameFlags )
1548 {
1550 dc.DrawText( m_name, labelW + 8, 4 );
1551 break;
1552
1553 case mpALIGN_LEFT:
1554 {
1555 // if ((!m_drawOutsideMargins) && (w.GetMarginLeft() > (ty + labelW + 8))) {
1556 // dc.DrawRotatedText( m_name, orgx - 6 - labelW - ty, (maxYpx + minYpx) / 2 + tx / 2, 90);
1557 // } else {
1558 dc.DrawText( m_name, orgx - ( tx / 2 ), minYpx - ty - 4 );
1559 // }
1560 }
1561 break;
1562
1563 case mpALIGN_CENTER:
1564 dc.DrawText( m_name, orgx + 4, 4 );
1565 break;
1566
1567 case mpALIGN_RIGHT:
1568 case mpALIGN_FAR_RIGHT:
1569 {
1570 // dc.DrawRotatedText( m_name, orgx + 6, (maxYpx + minYpx) / 2 + tx / 2, 90);
1571
1572 /*if ((!m_drawOutsideMargins) && (w.GetMarginRight() > (ty + labelW + 8))) {
1573 * dc.DrawRotatedText( m_name, orgx + 6 + labelW, (maxYpx - minYpx + tx)>>1, 90);
1574 * } else {*/
1575 dc.DrawText( m_name, orgx - ( tx / 2 ), minYpx - ty - 4 );
1576 // }
1577 }
1578 break;
1579
1581 dc.DrawText( m_name, orgx - 6 - tx - labelW, 4 );
1582 break;
1583
1584 default:
1585 break;
1586 }
1587 }
1588}
virtual wxString getLabel(int n) const
Definition: mathplot.h:825
virtual double getTickPos(int n) const
Definition: mathplot.h:815
int tickCount() const
Definition: mathplot.h:802
virtual double getLabelPos(int n) const
Definition: mathplot.h:820
virtual int labelCount() const
Definition: mathplot.h:807
virtual void recalculateTicks(wxDC &dc, mpWindow &w) override
Definition: mathplot.cpp:1059
int GetMarginLeft() const
Definition: mathplot.h:1379
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1140
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1204
double GetPosY(void) const
Definition: mathplot.h:1132
double GetScaleY(void) const
Definition: mathplot.h:1118
int GetMarginRight() const
Definition: mathplot.h:1375
#define mpALIGN_BORDER_RIGHT
Aligns Y axis to right border.
Definition: mathplot.h:505
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:477
#define mpALIGN_FAR_RIGHT
Aligns label to the right of mpALIGN_RIGHT.
Definition: mathplot.h:491
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:479
#define mpALIGN_LEFT
Aligns label to the left.
Definition: mathplot.h:481
#define Y_BORDER_SEPARATION
Definition: mathplot.h:95
static thread_pool * tp
Definition: thread_pool.cpp:30

References mpScaleBase::getLabel(), mpScaleBase::getLabelPos(), mpWindow::GetMarginBottom(), mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetMarginTop(), mpWindow::GetPosY(), mpWindow::GetScaleY(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpScaleBase::getTickPos(), mpScaleBase::labelCount(), mpLayer::m_drawOutsideMargins, m_flags, mpLayer::m_font, mpScaleBase::m_maxV, mpScaleBase::m_minV, mpLayer::m_name, mpScaleBase::m_nameFlags, mpScaleBase::m_offset, mpLayer::m_pen, mpScaleBase::m_scale, mpScaleBase::m_tickLabels, m_ticks, mpLayer::m_visible, mpALIGN_BORDER_LEFT, mpALIGN_BORDER_RIGHT, mpALIGN_CENTER, mpALIGN_FAR_RIGHT, mpALIGN_LEFT, mpALIGN_RIGHT, recalculateTicks(), mpScaleBase::tickCount(), tp, TransformToPlot(), mpWindow::x2p(), and Y_BORDER_SEPARATION.

◆ recalculateTicks()

void mpScaleY::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
overrideprotectedvirtual

Reimplemented from mpScaleBase.

Definition at line 1059 of file mathplot.cpp.

1060{
1061 if( m_masterScale )
1062 {
1063 computeSlaveTicks( w );
1064 updateTickLabels( dc, w );
1065
1066 return;
1067 }
1068
1069 double minV, maxV, minVvis, maxVvis;
1070 GetDataRange( minV, maxV );
1071 getVisibleDataRange( w, minVvis, maxVvis );
1072
1073 m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
1074 m_tickValues.clear();
1075 m_tickLabels.clear();
1076
1077 double minErr = 1000000000000.0;
1078 double bestStep = 1.0;
1079
1080 for( int i = 10; i <= 20; i += 2 )
1081 {
1082 double curr_step = fabs( maxVvis - minVvis ) / (double) i;
1083 double base = pow( 10, floor( log10( curr_step ) ) );
1084 double stepInt = floor( curr_step / base ) * base;
1085 double err = fabs( curr_step - stepInt );
1086
1087 if( err< minErr )
1088 {
1089 minErr = err;
1090 bestStep = stepInt;
1091 }
1092 }
1093
1094
1095 double v = floor( minVvis / bestStep ) * bestStep;
1096
1097 double zeroOffset = 100000000.0;
1098
1099 const int iterLimit = 1000;
1100 int i = 0;
1101
1102 while( v < maxVvis && i < iterLimit )
1103 {
1104 m_tickValues.push_back( v );
1105
1106 if( fabs( v ) < zeroOffset )
1107 zeroOffset = fabs( v );
1108
1109 v += bestStep;
1110 i++;
1111 }
1112
1113
1114 // something weird happened...
1115 if( i == iterLimit )
1116 {
1117 m_tickValues.clear();
1118 }
1119
1120 if( zeroOffset <= bestStep )
1121 {
1122 for( double& t : m_tickValues )
1123 t -= zeroOffset;
1124 }
1125
1126 for( double t : m_tickValues )
1127 m_tickLabels.emplace_back( t );
1128
1129
1130 // n0 = floor(minVvis / bestStep) * bestStep;
1131 // end = n0 +
1132
1133 // n0 = floor( (w.GetPosX() ) / step ) * step ;
1134 updateTickLabels( dc, w );
1135
1136 // labelStep = ceil(((double) m_maxLabelWidth + mpMIN_X_AXIS_LABEL_SEPARATION)/(w.GetScaleX()*step))*step;
1137}
void GetDataRange(double &minV, double &maxV) const
Definition: mathplot.h:734
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:952
void computeSlaveTicks(mpWindow &w)
Definition: mathplot.cpp:1009

References std::abs(), computeSlaveTicks(), mpScaleBase::GetDataRange(), getVisibleDataRange(), mpScaleBase::m_absVisibleMaxV, m_masterScale, mpScaleBase::m_tickLabels, mpScaleBase::m_tickValues, and mpScaleBase::updateTickLabels().

Referenced by Plot().

◆ ResetDataRange()

void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 761 of file mathplot.h.

762 {
763 m_rangeSet = 0;
764 }

Referenced by SIM_PLOT_PANEL::ResetScales().

◆ SetAlign()

void mpScaleY::SetAlign ( int  align)
inline

Set Y axis alignment.

Parameters
alignalignment (choose between mpALIGN_BORDER_LEFT, mpALIGN_LEFT, mpALIGN_CENTER, mpALIGN_RIGHT, mpALIGN_BORDER_RIGHT)

Definition at line 967 of file mathplot.h.

967{ m_flags = align; };

◆ SetBrush()

void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 310 of file mathplot.h.

310{ m_brush = brush; };

◆ SetContinuity()

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 253 of file mathplot.h.

253{ m_continuous = continuity; }

Referenced by TRACE::TRACE().

◆ SetDataRange()

void mpScaleBase::SetDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 727 of file mathplot.h.

728 {
729 m_rangeSet = true;
730 m_minV = minV;
731 m_maxV = maxV;
732 }

◆ SetDrawOutsideMargins()

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 281 of file mathplot.h.

281{ m_drawOutsideMargins = drawModeOutside; };

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

◆ SetFont()

void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 272 of file mathplot.h.

272{ m_font = font; }

◆ SetMasterScale()

void mpScaleY::SetMasterScale ( mpScaleY masterScale)
inline

Definition at line 981 of file mathplot.h.

982 {
983 m_masterScale = masterScale;
984 }

Referenced by SIM_PLOT_PANEL::AddTrace(), SIM_PLOT_PANEL::prepareDCAxes(), and SIM_PLOT_PANEL::updateAxes().

◆ SetName()

virtual void mpLayer::SetName ( wxString  name)
inlinevirtualinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Reimplemented in TRACE.

Definition at line 267 of file mathplot.h.

267{ m_name = name; }

References name.

Referenced by SIM_PLOT_PANEL::prepareDCAxes(), TRACE::SetName(), and SIM_PLOT_PANEL::updateAxes().

◆ SetNameAlign()

void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 711 of file mathplot.h.

711{ m_nameFlags = align; }

Referenced by SIM_PLOT_PANEL::prepareDCAxes(), and SIM_PLOT_PANEL::updateAxes().

◆ SetPen()

void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 277 of file mathplot.h.

277{ m_pen = pen; }

Referenced by SIM_PLOT_PANEL::UpdateTraceStyle().

◆ SetTicks()

void mpScaleY::SetTicks ( bool  ticks)
inline

Set Y axis ticks or grid.

Parameters
tickstrue to plot axis ticks, false to plot grid.

Definition at line 971 of file mathplot.h.

971{ m_ticks = ticks; };

Referenced by SIM_PLOT_PANEL::ShowGrid().

◆ SetVisible()

void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 302 of file mathplot.h.

302{ m_visible = show; };

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

◆ ShowName()

void mpLayer::ShowName ( bool  show)
inlineinherited

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

Definition at line 262 of file mathplot.h.

262{ m_showName = show; };
bool m_showName
Definition: mathplot.h:319

Referenced by TRACE::TRACE().

◆ tickCount()

int mpScaleBase::tickCount ( ) const
inlineprotectedinherited

Definition at line 802 of file mathplot.h.

803 {
804 return m_tickValues.size();
805 }

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

◆ TickLabels()

std::vector< TickLabel > & mpScaleBase::TickLabels ( )
inlineinherited

Definition at line 791 of file mathplot.h.

791{ return m_tickLabels; };

◆ TransformFromPlot()

double mpScaleY::TransformFromPlot ( double  xplot) const
overridevirtual

Reimplemented from mpScaleBase.

Definition at line 2863 of file mathplot.cpp.

2864{
2865 return xplot / m_scale - m_offset;
2866}

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

Referenced by computeSlaveTicks(), and getVisibleDataRange().

◆ TransformToPlot()

double mpScaleY::TransformToPlot ( double  x) const
overridevirtual

Reimplemented from mpScaleBase.

Definition at line 2857 of file mathplot.cpp.

2858{
2859 return (x + m_offset) * m_scale;
2860}

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

Referenced by computeSlaveTicks(), and Plot().

◆ updateTickLabels()

void mpScaleBase::updateTickLabels ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 952 of file mathplot.cpp.

953{
954 formatLabels();
955 computeLabelExtents( dc, w );
956
957 // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
958
959 // if ( m_tickLabels.size() <= 2)
960 // return;
961
962 /*
963 * fixme!
964 *
965 * for ( auto &l : m_tickLabels )
966 * {
967 * double p = TransformToPlot ( l.pos );
968 *
969 * if ( !IsHorizontal() )
970 * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
971 * else
972 * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
973 * }
974 *
975 *
976 * for (int i = 1; i < m_tickLabels.size() - 1; i++)
977 * {
978 * int dist_prev;
979 *
980 * for(int j = i-1; j >= 1; j--)
981 * {
982 * if( m_tickLabels[j].visible)
983 * {
984 * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
985 * break;
986 * }
987 * }
988 *
989 * if (dist_prev < gap)
990 * m_tickLabels[i].visible = false;
991 * }
992 */
993}
virtual void formatLabels()
Definition: mathplot.h:813
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:935

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

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

Member Data Documentation

◆ m_absVisibleMaxV

double mpScaleBase::m_absVisibleMaxV
protectedinherited

◆ m_brush

wxBrush mpLayer::m_brush
protectedinherited

Definition at line 316 of file mathplot.h.

◆ m_continuous

bool mpLayer::m_continuous
protectedinherited

Definition at line 318 of file mathplot.h.

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

◆ m_drawOutsideMargins

bool mpLayer::m_drawOutsideMargins
protectedinherited

◆ m_flags

int mpScaleY::m_flags
protected

Definition at line 1002 of file mathplot.h.

Referenced by Plot().

◆ m_font

◆ m_masterScale

mpScaleY* mpScaleY::m_masterScale
protected

Definition at line 998 of file mathplot.h.

Referenced by computeSlaveTicks(), and recalculateTicks().

◆ m_maxLabelHeight

int mpScaleBase::m_maxLabelHeight
protectedinherited

◆ m_maxLabelWidth

int mpScaleBase::m_maxLabelWidth
protectedinherited

Definition at line 841 of file mathplot.h.

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

◆ m_maxV

double mpScaleBase::m_maxV
protectedinherited

◆ m_minV

double mpScaleBase::m_minV
protectedinherited

◆ m_name

wxString mpLayer::m_name
protectedinherited

◆ m_nameFlags

int mpScaleBase::m_nameFlags
protectedinherited

Definition at line 836 of file mathplot.h.

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

◆ m_offset

◆ m_pen

◆ m_rangeSet

bool mpScaleBase::m_rangeSet
protectedinherited

Definition at line 839 of file mathplot.h.

Referenced by mpScaleBase::mpScaleBase().

◆ m_scale

◆ m_showName

bool mpLayer::m_showName
protectedinherited

◆ m_tickLabels

std::vector<TickLabel> mpScaleBase::m_tickLabels
protectedinherited

◆ m_ticks

bool mpScaleY::m_ticks
protected

Definition at line 1003 of file mathplot.h.

Referenced by Plot().

◆ m_tickValues

std::vector<double> mpScaleBase::m_tickValues
protectedinherited

◆ m_type

mpLayerType mpLayer::m_type
protectedinherited

Definition at line 321 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

◆ m_visible


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