Esempio n. 1
0
void Lineplot::linkScales()
{
  setAxisScaleDiv(QwtPlot::yRight, deref(axisScaleDiv(QwtPlot::yLeft)));
}
Esempio n. 2
0
/**
  * Set the scale of the horizontal axis
  * @param from :: Minimum value
  * @param to :: Maximum value
  */
void OneCurvePlot::setXScale(double from, double to)
{
  QFontMetrics fm(axisFont(QwtPlot::xBottom));
  int n = from != 0.0 ? abs(static_cast<int>(floor(log10(fabs(from))))) : 0;
  int n1 = to != 0.0 ? abs(static_cast<int>(floor(log10(fabs(to))))) : 0;
  if (n1 > n) n = n1;
  n += 4;
  // approxiamte width of a tick label in pixels
  int labelWidth = n * fm.width("0");
  // calculate number of major ticks
  int nMajorTicks = this->width() / labelWidth;
  if ( nMajorTicks > 6 ) nMajorTicks = 6;
  // try creating a scale
  const QwtScaleDiv div = axisScaleEngine(QwtPlot::xBottom)->divideScale(from,to,nMajorTicks,nMajorTicks);
  // Major ticks are placed at round numbers so the first or last tick could be missing making
  // scale look ugly. Trying to fix it if possible
  bool rescaled = false;
  // get actual tick positions
  const QwtValueList& ticks = div.ticks(QwtScaleDiv::MajorTick);
  if (!ticks.empty() && ticks.size() < nMajorTicks)
  {
    // how much first tick is shifted from the lower bound
    double firstShift = ticks.front() - div.lBound();
    // how much last tick is shifted from the upper bound
    double lastShift = div.hBound() - ticks.back();
    // range of the scale
    double range = fabs(div.hBound() - div.lBound());
    // we say that 1st tick is missing if first tick is father away from its end of the scale
    // than the last tick is from its end
    bool isFirstMissing =  fabs(firstShift) > fabs(lastShift) ;
    // if first tick is missing
    if (isFirstMissing)
    {
      // distance between nearest major ticks
      double tickSize = 0;
      if (ticks.size() == 1)
      {
        // guess the tick size in case of only one visible
        double tickLog = log10(firstShift);
        tickLog = tickLog > 0 ? ceil(tickLog) : floor(tickLog);
        tickSize = pow(10.,tickLog);
      }
      else if (ticks.size() > 1)
      {
        // take the difference between the two first ticks
        tickSize = ticks[1] - ticks[0];
      }
      // claculate how much lower bound must be moved to make the missing tick visible
      double shift = (ticks.front() - tickSize) - from;
      // if the shift is not very big rescale the axis
      if (fabs(shift/range) < 0.1)
      {
        from += shift;
        const QwtScaleDiv updatedDiv = axisScaleEngine(QwtPlot::xBottom)->divideScale(from,to,nMajorTicks,nMajorTicks);
        setAxisScaleDiv(xBottom,updatedDiv);
        rescaled = true;
      }
    }
    else // last tick is missing
    {
      // distance between nearest major ticks
      double tickSize = 0;
      if (ticks.size() == 1)
      {
        // guess the tick size in case of only one visible
        double tickLog = log10(lastShift);
        tickLog = tickLog > 0 ? ceil(tickLog) : floor(tickLog);
        tickSize = pow(10.,tickLog);
      }
      else if (ticks.size() > 1)
      {
        // take the difference between the two first ticks
        tickSize = ticks[1] - ticks[0];
      }
      // claculate how much upper bound must be moved to make the missing tick visible
      double shift = (ticks.back() + tickSize) - to;
      // if the shift is not very big rescale the axis
      if (fabs(shift/range) < 0.1)
      {
        to += shift;
        const QwtScaleDiv updatedDiv = axisScaleEngine(QwtPlot::xBottom)->divideScale(from,to,nMajorTicks,nMajorTicks);
        setAxisScaleDiv(xBottom,updatedDiv);
        rescaled = true;
      }
    }
  }

  if (!rescaled)
  {
    setAxisScaleDiv(xBottom,div);
  }
  m_zoomer->setZoomBase();
}
Esempio n. 3
0
MUPlot::MUPlot(MUWidget *muw, CriticalPowerWindow *parent, Context *context) 
       : QwtPlot(parent), QwtSyntheticPointData(MUN), 
         context(context), muw(muw), parent(parent), modelCurve(NULL), slowCurve(NULL), fastCurve(NULL), mmpCurve(NULL)
{

    // initalise all the model stufff
    // probably abstract this out later
    muSet = NULL;
    slowHandle = NULL;
    slowLine = NULL;
    slowDrag = false;
    fastHandle = NULL;
    fastLine = NULL;
    fastDrag = false;

    setAutoDelete(false);
    setAutoFillBackground(true);
    static_cast<QwtPlotCanvas*>(canvas())->setFrameStyle(QFrame::NoFrame);

    // left yAxis scale prettify
    QwtScaleDraw *sd = new QwtScaleDraw;
    sd->setTickLength(QwtScaleDiv::MajorTick, 3);
    sd->enableComponent(QwtScaleDraw::Ticks, false);
    sd->enableComponent(QwtScaleDraw::Backbone, false);
    setAxisScaleDraw(yLeft, sd);
    setAxisTitle(yLeft, tr("w(x)"));
    setAxisMaxMinor(yLeft, 0);
    plotLayout()->setAlignCanvasToScales(true);

    // 0.5 increments on bottom axis
    QwtValueList ytick[QwtScaleDiv::NTickTypes];
    for (double i=0.0f; i<=10.0f; i+= 1.0)
        ytick[QwtScaleDiv::MajorTick]<<i;
    setAxisScaleDiv(yLeft,QwtScaleDiv(0.0f,10.0f,ytick));

    // bottom xAxis scale prettify
    sd = new QwtScaleDraw;
    sd->setTickLength(QwtScaleDiv::MajorTick, 3);
    sd->enableComponent(QwtScaleDraw::Ticks, false);
    sd->enableComponent(QwtScaleDraw::Backbone, false);
    setAxisScaleDraw(xBottom, sd);
    setAxisTitle(xBottom, tr("Motor Unit, x"));
    setAxisMaxMinor(xBottom, 0);

    // 0.2 increments on bottom axis
    QwtValueList xtick[QwtScaleDiv::NTickTypes];
    for (double i=0.0f; i<=1.0f; i+= 0.2)
        xtick[QwtScaleDiv::MajorTick]<<i;
    setAxisScaleDiv(xBottom,QwtScaleDiv(0.0f,1.0f,xtick));

    // now color everything we created
    configChanged();

    // set to a 2 Normal Model
    setModel(2);

    // set mouse tracker
    parent->setMouseTracking(true);
    installEventFilter(parent);
    new muMouseTracker(this);
}