Beispiel #1
0
/*!
  Rescales the value axis of the plottable so the whole plottable is visible.
  
  Returns true if the axis was actually scaled. This might not be the case if this plottable has an
  invalid range, e.g. because it has no data points.
  
  See \ref rescaleAxes for detailed behaviour.
*/
void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge) const
{
  QCPAxis *valueAxis = mValueAxis.data();
  if (!valueAxis) { qDebug() << Q_FUNC_INFO << "invalid value axis"; return; }
  
  SignDomain signDomain = sdBoth;
  if (valueAxis->scaleType() == QCPAxis::stLogarithmic)
    signDomain = (valueAxis->range().upper < 0 ? sdNegative : sdPositive);
  
  bool foundRange;
  QCPRange newRange = getValueRange(foundRange, signDomain);
  if (foundRange)
  {
    if (onlyEnlarge)
      newRange.expand(valueAxis->range());
    if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable
    {
      double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason
      if (valueAxis->scaleType() == QCPAxis::stLinear)
      {
        newRange.lower = center-valueAxis->range().size()/2.0;
        newRange.upper = center+valueAxis->range().size()/2.0;
      } else // scaleType() == stLogarithmic
      {
        newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower);
        newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower);
      }
    }
    valueAxis->setRange(newRange);
  }
}
Beispiel #2
0
void RgbImageWindow::scaleRulesForAxis(QCPAxis *axis, double rangeUpper, QCPRange newRange, QCPRange oldRange)
{

    QCPRange boundedRange = newRange;
    double lowerRangeBound = 0;
    double upperRangeBound = rangeUpper;
    const int MAX_ZOOM = 4;
    if((upperRangeBound - lowerRangeBound)/boundedRange.size() > MAX_ZOOM)
    {
        axis->setRange(oldRange);
        return;
    }

    if (boundedRange.size() > upperRangeBound-lowerRangeBound)
    {
        boundedRange = QCPRange(lowerRangeBound, upperRangeBound);
    } else
    {
        double oldSize = boundedRange.size();
        if (boundedRange.lower < lowerRangeBound)
        {
            boundedRange.lower = lowerRangeBound;
            boundedRange.upper = lowerRangeBound+oldSize;
        }
        if (boundedRange.upper > upperRangeBound)
        {
            boundedRange.lower = upperRangeBound-oldSize;
            boundedRange.upper = upperRangeBound;
        }
    }
    axis->setRange(boundedRange);
}
Beispiel #3
0
void plot_analytics::plotAnalyze( QCPGraph *target, plotStats *stats, QCPRange keyRange)
{
    QCPGraphDataContainer::const_iterator plotIterator = target->data().data()->findBegin(keyRange.lower,true);
    QCPGraphDataContainer::const_iterator targetDataEnd = target->data().data()->findEnd(keyRange.upper,true);
    QCPGraphData currentPoint, prevPoint;

    //Find the data ranges
    currentPoint.key = keyRange.lower;
    prevPoint = QCPGraphData(plotIterator->key, plotIterator->value);

    while(plotIterator != targetDataEnd && (keyRange.contains(plotIterator->key) || stats->totalData_entrys < 2))
    {
        currentPoint = QCPGraphData(plotIterator->key, plotIterator->value);
        handlePoints(currentPoint, prevPoint, stats);

        //Value is weighted to account for datapoints that may not be equally spaced
        if(!isInvalidData(currentPoint.value) && !isInvalidData(prevPoint.value))
            stats->avgValue += currentPoint.value*(currentPoint.key-prevPoint.key);

        prevPoint = QCPGraphData(plotIterator->key, plotIterator->value);
        ++plotIterator;
    }
    //Divide by total seconds
    stats->avgValue /= stats->totalData_seconds;
}
Beispiel #4
0
double ProfilePlotView::tickStep(const QCPRange & range, int nSteps)
{
	double step = range.size() / (double)(nSteps+1e-10);
	double factor = qPow(10.0, qFloor(qLn(step) / qLn(10.0)));
	double mantissa = step / factor;

	if (mantissa >= 7)
	{
		factor *= 10.0;
		step = 1;
	}
	else if (mantissa >= 5)
		step = 5;
	else if (mantissa >= 2)
		step = 2;
	else if (mantissa >= 1)
		step = 1;
	else
	{
		factor /= 10.0;
		step = 5;
	}

	return step * factor;
}
Beispiel #5
0
void MainWindow::onXRangeChanged(const QCPRange newRange, const QCPRange oldRange)
{
    double newSize = newRange.size();
    bool sizeToSmall = false;

    /* Plot range can't be larger than the time elapsed */
    if (newSize > (plotXAxis_maxRange - plotXAxis_minRange))
        newSize = plotXAxis_maxRange - plotXAxis_minRange;

    /* Don't want the plot to zoom to much */
    else if (newSize < 0.5)
        sizeToSmall = true;

    for (int i = 0; i < controller->getNumSensors(); i++) {
        /* Plot range can't go below the minimal value */
        if (newRange.lower < plotXAxis_minRange) {
            ui->plot_sensors->axisRect(i)->axis(QCPAxis::atBottom)->setRange(plotXAxis_minRange, plotXAxis_minRange + newSize);
            ui->plot_CoM->axisRect()->axis(QCPAxis::atBottom)->setRange(plotXAxis_minRange, plotXAxis_minRange + newSize);
        }

        /* Plot range can't go above the maximal value */
        else if (newRange.upper > plotXAxis_maxRange) {
            ui->plot_sensors->axisRect(i)->axis(QCPAxis::atBottom)->setRange(plotXAxis_maxRange - newSize, plotXAxis_maxRange);
            ui->plot_CoM->axisRect()->axis(QCPAxis::atBottom)->setRange(plotXAxis_maxRange - newSize, plotXAxis_maxRange);
        }

        /* Plot can't zoom infinitely */
        else if (sizeToSmall) {
            ui->plot_sensors->axisRect(i)->axis(QCPAxis::atBottom)->setRange(oldRange.lower, oldRange.upper);
            ui->plot_CoM->axisRect()->axis(QCPAxis::atBottom)->setRange(oldRange.lower, oldRange.upper);
            newSize = oldRange.size();
        }
    }

    ui->plot_sensors->replot();
    ui->plot_CoM->replot();

    /* Adjust the horizontal drag sliders */
    ui->plot_horizontalDrag->setRange(plotXAxis_minRange + newSize / 2, plotXAxis_maxRange - newSize / 2);
    ui->plot_horizontalDrag->setValue(ui->plot_sensors->axisRect()->axis(QCPAxis::atBottom)->range().lower + newSize / 2);

    ui->plotCoM_horizontalDrag->setRange(plotXAxis_minRange + newSize / 2, plotXAxis_maxRange - newSize / 2);
    ui->plotCoM_horizontalDrag->setValue(ui->plot_sensors->axisRect()->axis(QCPAxis::atBottom)->range().lower + newSize / 2);
}
Beispiel #6
0
void plot_analytics::plotAnalyze( QCPGraph *target, QVector<plotStats> *stats, QCPRange keyRange, double iterator)
{
    plotStats currentRangeStats;
    QCPRange currentRange = keyRange;

    currentRange.upper = currentRange.lower + iterator;

    while(keyRange.contains(currentRange.upper))
    {
        //Gernate and append the stats
        plotAnalyze( target, &currentRangeStats, currentRange);
        stats->append(currentRangeStats);
        //Update working range
        currentRange.lower = currentRange.upper;
        currentRange.upper += iterator;
    }
}
Beispiel #7
0
void plot_analytics::clearUnwantedPoints(QCPGraph *target, QCPGraph *enableReference, QCPRange valueEnableRange)
{
    QCPGraphDataContainer::iterator plotIterator = target->data()->begin();
    QCPGraphDataContainer::const_iterator refIterator;

    //First we scan and any time the reference plot is not in range wipe the plot data.
    //TODO: This will break the plot, do we clone the plot? That could be a huge amount of data...
    while(plotIterator != target->data()->end())
    {
        //Find closest reference point
        refIterator = enableReference->data().data()->findBegin(plotIterator->key, true);
        if (!valueEnableRange.contains(refIterator->value))
            plotIterator->value = std::numeric_limits<double>::quiet_NaN();

        ++plotIterator;
    }
}
void MainWindow::integerTickStepCase_yRangeChanged(QCPRange newRange)
{
	// Generate tick positions according to linear scaling:
	double mTickStep = newRange.size()/(double)(5+1e-10); // mAutoTickCount ticks on average, the small addition is to prevent jitter on exact integers
	double magnitudeFactor = qPow(10.0, qFloor(qLn(mTickStep)/qLn(10.0))); // get magnitude factor e.g. 0.01, 1, 10, 1000 etc.
	double tickStepMantissa = mTickStep/magnitudeFactor;
	if (tickStepMantissa < 5)
	{
		// round digit after decimal point to 0.5
		mTickStep = (int)(tickStepMantissa*2)/2.0*magnitudeFactor;
	} else
	{
		// round to first digit in multiples of 2
		mTickStep = (int)((tickStepMantissa/10.0)*5)/5.0*10*magnitudeFactor;
	}
	mCustomPlot->yAxis->setTickStep(qCeil(mTickStep));
}
Beispiel #9
0
void Window::on_horizontalSlider_valueChanged(int value)
{
    QCPRange range = ui->plot->xAxis->range();

    double real_size = range.size() / old_x_slider_scale;
    double new_size = real_size * value;

    old_x_slider_scale = value;

    ui->plot->xAxis->setRange(QCPRange(range.center() - new_size / 2, range.center() + new_size / 2));
    ui->plot->xAxis2->setRange(QCPRange(range.center() - new_size / 2, range.center() + new_size / 2));
    ui->plot->replot();
}
Beispiel #10
0
void MainWindow::yAxisChanged(QCPRange range)
{
    ui->verticalScrollBar->setValue(qRound(-range.center()*100.0)); // adjust position of scroll bar slider
    ui->verticalScrollBar->setPageStep(qRound(range.size()*100.0)); // adjust size of scroll bar slider
}
void AP2DataPlot2D::xAxisChanged(QCPRange range)
{
    ui.horizontalScrollBar->setValue(qRound(range.center())); // adjust position of scroll bar slider
    ui.horizontalScrollBar->setPageStep(qRound(range.size())); // adjust size of scroll bar slider
}
Beispiel #12
0
/*!
  Returns an expanded range that contains this and \a otherRange. It is assumed that both this
  range and \a otherRange are normalized (see \ref normalize).
  
  \see expand
*/
QCPRange QCPRange::expanded(const QCPRange &otherRange) const
{
  QCPRange result = *this;
  result.expand(otherRange);
  return result;
}
void SequenceDialog::yAxisChanged(QCPRange range)
{
    ui->verticalScrollBar->setValue(qRound(range.center()*100.0));
    ui->verticalScrollBar->setPageStep(qRound(range.size()*100.0));
}
Beispiel #14
0
void ChartPage::xAxisChanged(QCPRange range)
{
  ui->horizontalScrollBar->setValue(qRound(range.center()/1000000.0)); // adjust position of scroll bar slider
  ui->horizontalScrollBar->setPageStep(qRound(range.size()*1000000.0)); // adjust size of scroll bar slider
}
void LBMUIMFlowDialog::yAxisChanged(QCPRange range)
{
    m_ui->verticalScrollBar->setValue(qRound(range.center() * 100.0));
    m_ui->verticalScrollBar->setPageStep(qRound(range.size() * 100.0));
}