void QwtPlotScaleItem::updateBorders()
{
    const QwtPlot *plt = plot();
    if ( plt == NULL || !d_data->scaleDivFromAxis )
        return;
    
    const QRect r = plt->canvas()->contentsRect();
    d_data->canvasRectCache = r;

    QwtDoubleInterval interval;
    if ( d_data->scaleDraw->orientation() == Qt::Horizontal )
    {
        const QwtScaleMap map = plt->canvasMap(xAxis());
        interval.setMinValue(map.invTransform(r.left()));
        interval.setMaxValue(map.invTransform(r.right()));
    }
    else
    {
        const QwtScaleMap map = plt->canvasMap(yAxis());
        interval.setMinValue(map.invTransform(r.bottom()));
        interval.setMaxValue(map.invTransform(r.top()));
    }

    QwtScaleDiv scaleDiv = d_data->scaleDraw->scaleDiv();
    scaleDiv.setInterval(interval);
    d_data->scaleDraw->setScaleDiv(scaleDiv);
}
/*! 
  Expand the interval

  \param interval Interval to be expanded
  \param width Distance to be added to the interval
  \param direction Direction of the expand operation

  \return Expanded interval
*/
QwtDoubleInterval QwtPlotRescaler::expandInterval(
    const QwtDoubleInterval &interval, double width,    
    ExpandingDirection direction) const
{
    QwtDoubleInterval expanded = interval;

    switch(direction)
    {
        case ExpandUp:
            expanded.setMinValue(interval.minValue());
            expanded.setMaxValue(interval.minValue() + width);
            break;
        case ExpandDown:
            expanded.setMaxValue(interval.maxValue());
            expanded.setMinValue(interval.maxValue() - width);
            break;
        case ExpandBoth:
        default:
            expanded.setMinValue(interval.minValue() +
                interval.width() / 2.0 - width / 2.0);
            expanded.setMaxValue(expanded.minValue() + width);
    }
    return expanded;
}
Ejemplo n.º 3
0
/*!
   Calculate the bounding interval of the radial scale that is
   visible on the canvas.
*/
QwtDoubleInterval QwtPolarPlot::visibleInterval() const
{
  const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius );

  const QwtDoubleRect cRect = canvas()->contentsRect();
  const QwtDoubleRect pRect = plotRect( cRect.toRect() );
  if ( cRect.contains( pRect.toRect() ) || !cRect.intersects( pRect ) )
  {
#if QWT_VERSION < 0x050200
    return QwtDoubleInterval( sd->lBound(), sd->hBound() );
#else
    return QwtDoubleInterval( sd->lowerBound(), sd->upperBound() );
#endif
  }

  const QwtDoublePoint pole = pRect.center();
  const QwtDoubleRect scaleRect = pRect & cRect;

  const QwtScaleMap map = scaleMap( QwtPolar::Radius );

  double dmin = 0.0;
  double dmax = 0.0;
  if ( scaleRect.contains( pole ) )
  {
    dmin = 0.0;

    QwtDoublePoint corners[4];
    corners[0] = scaleRect.bottomRight();
    corners[1] = scaleRect.topRight();
    corners[2] = scaleRect.topLeft();
    corners[3] = scaleRect.bottomLeft();

    dmax = 0.0;
    for ( int i = 0; i < 4; i++ )
    {
      const double dist = qwtDistance( pole, corners[i] );
      if ( dist > dmax )
        dmax = dist;
    }
  }
  else
  {
    if ( pole.x() < scaleRect.left() )
    {
      if ( pole.y() < scaleRect.top() )
      {
        dmin = qwtDistance( pole, scaleRect.topLeft() );
        dmax = qwtDistance( pole, scaleRect.bottomRight() );
      }
      else if ( pole.y() > scaleRect.bottom() )
      {
        dmin = qwtDistance( pole, scaleRect.bottomLeft() );
        dmax = qwtDistance( pole, scaleRect.topRight() );
      }
      else
      {
        dmin = scaleRect.left() - pole.x();
        dmax = qwtMax( qwtDistance( pole, scaleRect.bottomRight() ),
                       qwtDistance( pole, scaleRect.topRight() ) );
      }
    }
    else if ( pole.x() > scaleRect.right() )
    {
      if ( pole.y() < scaleRect.top() )
      {
        dmin = qwtDistance( pole, scaleRect.topRight() );
        dmax = qwtDistance( pole, scaleRect.bottomLeft() );
      }
      else if ( pole.y() > scaleRect.bottom() )
      {
        dmin = qwtDistance( pole, scaleRect.bottomRight() );
        dmax = qwtDistance( pole, scaleRect.topLeft() );
      }
      else
      {
        dmin = pole.x() - scaleRect.right();
        dmax = qwtMax( qwtDistance( pole, scaleRect.bottomLeft() ),
                       qwtDistance( pole, scaleRect.topLeft() ) );
      }
    }
    else if ( pole.y() < scaleRect.top() )
    {
      dmin = scaleRect.top() - pole.y();
      dmax = qwtMax( qwtDistance( pole, scaleRect.bottomLeft() ),
                     qwtDistance( pole, scaleRect.bottomRight() ) );
    }
    else if ( pole.y() > scaleRect.bottom() )
    {
      dmin = pole.y() - scaleRect.bottom();
      dmax = qwtMax( qwtDistance( pole, scaleRect.topLeft() ),
                     qwtDistance( pole, scaleRect.topRight() ) );
    }
  }

  const double radius = pRect.width() / 2.0;
  if ( dmax > radius )
    dmax = radius;

  QwtDoubleInterval interval;
  interval.setMinValue( map.invTransform( dmin ) );
  interval.setMaxValue( map.invTransform( dmax ) );

  return interval;
}