All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Types | Public Member Functions
SciFigs::Scale Class Reference

Manage a scale for transforming real coordinates into screen coordinates. More...

#include <Scale.h>

List of all members.

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

Detailed Description

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.


Member Enumeration Documentation

Enumerator:
Linear 
Inversed 
Log 

Constructor & Destructor Documentation

Description of constructor still missing

References Linear, and TRACE.

{
  TRACE;
  _globalMinimum=0;
  _globalMaximum=100;
  _minimum=0.0;
  _maximum=100.0;
  _type=Linear;
  _reversed=false;
  _majorTicks=5.;
  _minorTicks=1.;
}

Member Function Documentation

double SciFigs::Scale::a ( ) const [inline]
{return _a;}

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

  • if difference < 1.2:
    • labels - 0.2, 0.4, 0.6, 0.8, 1.0
    • ticks - 0.04, 0.08, 0.12, 0.16, 0.2, ...
  • if difference < 2.4:
    • labels - 0.4, 0.8, 1.2, 1.6, 2.0
    • ticks - 0.1, 0.2, 0.3, 0.4, ...
  • if difference < 6:
    • labels - 1, 2, 3, 4, 5
    • ticks - 0.2, 0.4, 0.6, 0.8, 1.0, ...
  • else:
    • labels - 2, 4, 6, 8, 10
    • ticks - 0.4, 0.8, 1.2, 1.6, 2.0, ...
See also:
setAutoTicks(), autoTicks()

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;}

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]
double SciFigs::Scale::globalMinimum ( ) const [inline]

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]
bool SciFigs::Scale::isReversed ( ) const [inline]
{return _reversed;}
int SciFigs::Scale::lineCount ( ) const [inline]

References TRACE.

{
  TRACE;
  // Line is one tenth of physical size of axis in pixel (aSize()*0.1). Hence 9 steps are removed
  // because the screen is always full of content.
  return (int) ceil((r2a(_globalMaximum) - r2a(_globalMinimum))/((r2a(_maximum) - r2a(_minimum))*0.1))-9;
}
double SciFigs::Scale::majorTicks ( ) const [inline]

Referenced by SciFigs::GraphContentOptions::paintGridLines().

{return _majorTicks;}
double SciFigs::Scale::maximum ( ) const [inline]
double SciFigs::Scale::minimum ( ) const [inline]
double SciFigs::Scale::minorTicks ( ) const [inline]

Referenced by SciFigs::GraphContentOptions::paintGridLines().

{return _minorTicks;}
void SciFigs::Scale::operator= ( const Scale o)

References TRACE.

{
  TRACE;
  _globalMinimum=o._globalMinimum;
  _globalMaximum=o._globalMaximum;
  _minimum=o._minimum;
  _maximum=o._maximum;
  _type=o._type;
  _reversed=o._reversed;
  _a=o._a;
  _b=o._b;
  _majorTicks=o._majorTicks;
  _minorTicks=o._minorTicks;
}
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]

References Inversed, Log, and TRACE.

{
  TRACE;
  switch (_type) {
  case Inversed:
    return _a/val+_b;
  case Log:
    return _a*log10(val)+_b;
  default:
    return _a*val+_b;
  }
}
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]

References Inversed, Log, and TRACE.

{
  TRACE;
  switch (_type) {
  case Inversed:
    return _a/(val-_b);
  case Log:
    return pow(10.0, (val-_b)/_a);
  default:
    return (val-_b)/_a;
  }
}

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]
void SciFigs::Scale::setGlobalMinimum ( double  m) [inline]

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);
  }
}

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]
void SciFigs::Scale::setMinimum ( double  min) [inline]
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;}

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);
  }
}

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]

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));
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines