Manage a scale for transforming real coordinates into screen coordinates. More...
#include <Scale.h>
Public Types | |
enum | Type { Linear, Inversed, Log } |
Public Member Functions | |
double | a () const |
void | autoTicks (Number::Type numberType) |
double | b () const |
void | checkLimits () |
double | globalMaximum () const |
double | globalMinimum () const |
int | horizontalCurrentLine () const |
bool | isEffectivelyReversed () const |
bool | isReversed () const |
int | lineCount () const |
double | majorTicks () const |
double | maximum () const |
double | minimum () const |
double | minorTicks () const |
void | operator= (const Scale &o) |
int | r2s (double val) const |
double | r2sF (double val) const |
double | s2r (int val) const |
double | s2rF (double val) const |
SamplingOption | sampling () const |
Scale () | |
void | setGlobalMaximum (double m) |
void | setGlobalMinimum (double m) |
void | setHorizontalCurrentLine (int line) |
void | setHorizontalTransformation (int length) |
void | setMajorTicks (double m) |
void | setMaximum (double max) |
void | setMinimum (double min) |
void | setMinorTicks (double m) |
void | setReversed (bool r) |
void | setType (Type t) |
void | setVerticalCurrentLine (int line) |
void | setVerticalTransformation (int length) |
Type | type () const |
int | verticalCurrentLine () const |
Manage a scale for transforming real coordinates into screen coordinates.
The scale is defined by a minimum() and a maximum() which correspond to the visible minimum and maximum of a Axis. The scale tranformation is defined by the type of scale (Normal, Inversed or Log) by its reversed flag (isReversed()) and by a() and b(). a() and b() are set indirectly by setVerticalTransformation() or setHorizontalTransformation().
Three types of coordinates are in use here: screen, real, axis.
enum SciFigs::Scale::Type |
double SciFigs::Scale::a | ( | ) | const [inline] |
{return _a;}
void SciFigs::Scale::autoTicks | ( | Number::Type | numberType | ) |
According to the min and max values, the numberType and the scaleType, typical rounded values are set for label and tick.
For log scales label is set to 1 and tick is set to 0.2.
If numberType is 't', a maximum of 12 labels is chosen, 6 ticks between two labels.
For other scales, the difference between max and min is divided by the appropriate power of ten (expo) to get a number between 1 and 10. For example if the difference is between 1 and 10. The labels and ticks will be
References Inversed, Linear, Log, maximum(), minimum(), TRACE, and type().
Referenced by SciFigs::Axis::addStringLabel(), SciFigs::Axis::setAutoTicks(), SciFigs::Axis::setNumberType(), SciFigs::Axis::setPrintScale(), and SciFigs::Axis::setVisibleRange().
{ TRACE; double delta=0; switch (type()) { case Linear: delta=maximum() - minimum(); break; case Inversed: delta=1.0/minimum() - 1.0/maximum(); break; case Log: _majorTicks=5.0; _minorTicks=1.0; return; } switch(numberType) { case Number::Weeks: case Number::Days: case Number::Hours: case Number::Minutes: case Number::Seconds: if(delta<=2419200) { if(delta<=14400) { if(delta<=1200) { if(delta<=300) { if(delta<=180) { // Less than 180 0 double expo=pow(10., floor(log10(delta))); delta/=expo; setTicks(delta, expo); } else { // Between 180 and 300 _majorTicks=30; _minorTicks=5; } } else { if(delta<=600) { // Between 300 and 600 _majorTicks=60; _minorTicks=10; } else { // Between 600 and 1200 _majorTicks=120; _minorTicks=20; } } } else { if(delta<=3600) { if(delta<=2400) { // Between 1200 and 2400 _majorTicks=240; _minorTicks=60; } else { // Between 2400 and 3600 _majorTicks=300; _minorTicks=60; } } else { if(delta<=7200) { // Between 3600 and 7200 _majorTicks=600; _minorTicks=120; } else { // Between 7200 and 14400 _majorTicks=1200; _minorTicks=240; } } } } else { if(delta<=172800) { if(delta<=43200) { if(delta<=21600) { // Between 14400 and 21600 _majorTicks=1800; _minorTicks=300; } else { // Between 21600 and 43200 _majorTicks=3600; _minorTicks=600; } } else { if(delta<=86400) { // Between 43200 and 86400 _majorTicks=7200; _minorTicks=1200; } else { // Between 86400 and 172800 _majorTicks=14400; _minorTicks=3600; } } } else { if(delta<=604800) { if(delta<=345600) { // Between 172800 and 345600 _majorTicks=43200; _minorTicks=7200; } else { // Between 345600 and 604800 _majorTicks=86400; _minorTicks=14400; } } else { if(delta<=1209600) { // Between 604800 and 1209600 _majorTicks=172800; _minorTicks=28800; } else { // Between 1209600 and 2419200 _majorTicks=345600; _minorTicks=86400; } } } } } else { if(delta<=9676800) { if(delta<=4838400) { // Between 2419200 and 4838400 _majorTicks=604800; _minorTicks=86400; } else { // Between 4838400 and 9676800 _majorTicks=1209600; _minorTicks=172800; } } else { if(delta<=19353600) { _majorTicks=2419200; _minorTicks=604800; } else { delta /= 604800; double expo=pow(10., floor(log10(delta))); delta /= expo; expo *= 604800; setTicks(delta, expo); } } } break; case Number::Fixed: case Number::Scientific: { double expo=pow(10., floor(log10(delta))); delta/=expo; setTicks(delta, expo); } break; } }
double SciFigs::Scale::b | ( | ) | const [inline] |
{return _b;}
void SciFigs::Scale::checkLimits | ( | ) |
Make sure minimum() and maximum() are within min and max. If not, they are corrected keeping the difference between minimum() and maximum() constant
References TRACE.
{ TRACE; double delta=r2a(_maximum) - r2a(_minimum); if(_minimum < _globalMinimum) { _maximum=a2r(r2a(_globalMinimum) + delta); _minimum=_globalMinimum; if(_maximum > _globalMaximum) _maximum=_globalMaximum; } else if(_maximum > _globalMaximum) { _minimum=a2r(r2a(_globalMaximum) - delta); _maximum=_globalMaximum; if(_minimum < _globalMinimum) _minimum=_globalMinimum; } }
double SciFigs::Scale::globalMaximum | ( | ) | const [inline] |
Referenced by SciFigs::Axis::isZoomed(), SciFigs::Axis::printThickness(), and SciFigs::Axis::setPrintScale().
{return _globalMaximum;}
double SciFigs::Scale::globalMinimum | ( | ) | const [inline] |
Referenced by SciFigs::Axis::isZoomed(), SciFigs::Axis::printThickness(), SciFigs::Axis::setPrintScale(), and SciFigs::Axis::setVisibleRange().
{return _globalMinimum;}
int SciFigs::Scale::horizontalCurrentLine | ( | ) | const |
The scroll is counted in "lines", one line is one tenth of the current scale length.
References isEffectivelyReversed().
Referenced by SciFigs::Axis::currentLine().
{ if(isEffectivelyReversed()) return (int) round((r2a(_maximum) - r2a(_globalMaximum))/((r2a(_minimum) - r2a(_maximum)) * 0.1)); else return (int) round((r2a(_minimum) - r2a(_globalMinimum))/((r2a(_maximum) - r2a(_minimum)) * 0.1)); }
bool SciFigs::Scale::isEffectivelyReversed | ( | ) | const [inline] |
References Inversed, and TRACE.
Referenced by SciFigs::GridPlot::drawGrid2DBlock(), SciFigs::GridPlot::drawGrid2DSmooth(), horizontalCurrentLine(), SciFigs::ImageLayer::paintData(), setHorizontalCurrentLine(), setHorizontalTransformation(), setVerticalCurrentLine(), setVerticalTransformation(), and verticalCurrentLine().
bool SciFigs::Scale::isReversed | ( | ) | const [inline] |
{return _reversed;}
int SciFigs::Scale::lineCount | ( | ) | const [inline] |
double SciFigs::Scale::majorTicks | ( | ) | const [inline] |
Referenced by SciFigs::GraphContentOptions::paintGridLines().
{return _majorTicks;}
double SciFigs::Scale::maximum | ( | ) | const [inline] |
Referenced by autoTicks(), SciFigs::Axis::isZoomed(), SciFigs::GraphContentOptions::paintGridLines(), SciFigs::GraphContentOptions::r2s(), and SciFigs::GraphContentOptions::yr2s().
{return _maximum;}
double SciFigs::Scale::minimum | ( | ) | const [inline] |
Referenced by autoTicks(), SciFigs::Axis::isZoomed(), SciFigs::GraphContentOptions::paintGridLines(), SciFigs::GraphContentOptions::r2s(), and SciFigs::GraphContentOptions::yr2s().
{return _minimum;}
double SciFigs::Scale::minorTicks | ( | ) | const [inline] |
Referenced by SciFigs::GraphContentOptions::paintGridLines().
{return _minorTicks;}
void SciFigs::Scale::operator= | ( | const Scale & | o | ) |
int SciFigs::Scale::r2s | ( | double | val | ) | const [inline] |
Conversion from real coordinate to screen coordinate
{return round(r2sF(val));}
double SciFigs::Scale::r2sF | ( | double | val | ) | const [inline] |
double SciFigs::Scale::s2r | ( | int | val | ) | const [inline] |
Conversion from screen coordinate to real coordinate
{return s2rF(val);}
double SciFigs::Scale::s2rF | ( | double | val | ) | const [inline] |
SamplingOption SciFigs::Scale::sampling | ( | ) | const |
Returns the type() as a Qtb::SamplingOption
References Inversed, QGpCoreTools::InversedScale, Linear, QGpCoreTools::LinearScale, Log, QGpCoreTools::LogScale, and TRACE.
Referenced by addPlot(), and HistogramWidget::setHistogram().
{ TRACE; switch(_type) { case Log: return LogScale; case Inversed: return InversedScale; case Linear: return LinearScale; } return LinearScale; }
void SciFigs::Scale::setGlobalMaximum | ( | double | m | ) | [inline] |
Referenced by SciFigs::Axis::setRange(), SciFigs::Axis::setScaleType(), and SciFigs::Axis::setVisibleRange().
{_globalMaximum=m;}
void SciFigs::Scale::setGlobalMinimum | ( | double | m | ) | [inline] |
Referenced by SciFigs::Axis::setRange(), SciFigs::Axis::setScaleType(), and SciFigs::Axis::setVisibleRange().
{_globalMinimum=m;}
void SciFigs::Scale::setHorizontalCurrentLine | ( | int | line | ) |
The scroll is counted in "lines", one line is one tenth of the current scale length. This line count refers to min and max.
The main trick here is that delta cannot change when scrolling, never, never, ever ...
References isEffectivelyReversed(), and TRACE.
Referenced by SciFigs::Axis::setCurrentLine().
{ TRACE; double delta=r2a(_maximum) - r2a(_minimum); if(isEffectivelyReversed()) { _maximum=a2r(r2a(_globalMaximum) - (double) line * 0.1 * delta); _minimum=a2r(r2a(_maximum) - delta); } else { _minimum=a2r((double) line * 0.1 * delta + r2a(_globalMinimum)); _maximum=a2r(r2a(_minimum) + delta); } }
void SciFigs::Scale::setHorizontalTransformation | ( | int | length | ) |
Set scale transformation factors (_a and _b). length is the size of axis along its direction. For an X axis (horizontal), length is the width of the axis object.
References isEffectivelyReversed(), and TRACE.
{ TRACE; _a=(double) (length - 1)/(r2a(_maximum) - r2a(_minimum)); if(isEffectivelyReversed()) { _a=-_a; _b=-_a * r2a(_maximum); } else { _b=-_a * r2a(_minimum); } }
void SciFigs::Scale::setMajorTicks | ( | double | m | ) | [inline] |
{_majorTicks=m;}
void SciFigs::Scale::setMaximum | ( | double | max | ) | [inline] |
Referenced by SciFigs::Axis::setPrintScale(), SciFigs::Axis::setScaleType(), and SciFigs::Axis::setVisibleRange().
{_maximum=max;}
void SciFigs::Scale::setMinimum | ( | double | min | ) | [inline] |
Referenced by SciFigs::Axis::setPrintScale(), SciFigs::Axis::setScaleType(), and SciFigs::Axis::setVisibleRange().
{_minimum=min;}
void SciFigs::Scale::setMinorTicks | ( | double | m | ) | [inline] |
{_minorTicks=m;}
void SciFigs::Scale::setReversed | ( | bool | r | ) | [inline] |
{_reversed=r;}
void SciFigs::Scale::setType | ( | Type | t | ) | [inline] |
Referenced by SciFigs::Axis::setScaleType().
{_type=t;}
void SciFigs::Scale::setVerticalCurrentLine | ( | int | line | ) |
The scroll is counted in "lines", one line is one tenth of the current scale length. This line count refers to min and max.
The main trick here is that delta cannot change when scrolling, never, never, ever ...
References isEffectivelyReversed(), and TRACE.
Referenced by SciFigs::Axis::setCurrentLine().
{ TRACE; double delta=r2a(_maximum) - r2a(_minimum); if(isEffectivelyReversed()) { _minimum=a2r((double) line * 0.1 * delta + r2a(_globalMinimum)); _maximum=a2r(r2a(_minimum) + delta); } else { _maximum=a2r(r2a(_globalMaximum) - (double) line * 0.1 * delta); _minimum=a2r(r2a(_maximum) - delta); } }
void SciFigs::Scale::setVerticalTransformation | ( | int | length | ) |
Set scale transformation factors (_a and _b). length is the size of axis along its direction. For a Y axis (vertical), length is the height of the axis object.
References isEffectivelyReversed(), and TRACE.
{ TRACE; _a=(double) (length - 1)/(r2a(_maximum) - r2a(_minimum)); if(isEffectivelyReversed()) { _b=-_a * r2a(_minimum); } else { _a=-_a; _b=-_a * r2a(_maximum); } }
Type SciFigs::Scale::type | ( | ) | const [inline] |
Referenced by autoTicks(), SciFigs::GraphContentOptions::paintGridLines(), and SciFigs::Axis::printThickness().
{return _type;}
int SciFigs::Scale::verticalCurrentLine | ( | ) | const |
The scroll is counted in "lines", one line is one tenth of the current scale length.
References isEffectivelyReversed(), and TRACE.
Referenced by SciFigs::Axis::currentLine().
{ TRACE; if(isEffectivelyReversed()) return (int) round((r2a(_minimum) - r2a(_globalMinimum))/((r2a(_maximum) - r2a(_minimum)) * 0.1)); else return (int) round((r2a(_maximum) - r2a(_globalMaximum))/((r2a(_minimum) - r2a(_maximum)) * 0.1)); }