Ejemplo n.º 1
0
double QwtBarCurve::dataOffset() {
  if (bar_style == Vertical) {
    const QwtScaleMap &xMap = plot()->canvasMap(xAxis());
    int dx = abs(xMap.transform(x(1)) - xMap.transform(x(0)));
    double bar_width = dx * (1 - bar_gap * 0.01);
    if (plot()->isVisible()) {
      for (int i = 2; i < dataSize(); i++) {
        int min = abs(xMap.transform(x(i)) - xMap.transform(x(i - 1)));
        if (min <= dx) dx = min;
      }
      int x1 = xMap.transform(minXValue()) + int(bar_offset * 0.01 * bar_width);
      return xMap.invTransform(x1) - minXValue();
    } else
      return 0.5 * bar_offset * 0.01 * bar_width;
  } else {
    const QwtScaleMap &yMap = plot()->canvasMap(yAxis());
    int dy = abs(yMap.transform(y(1)) - yMap.transform(y(0)));
    double bar_width = dy * (1 - bar_gap * 0.01);
    if (plot()->isVisible()) {
      for (int i = 2; i < dataSize(); i++) {
        int min = abs(yMap.transform(y(i)) - yMap.transform(y(i - 1)));
        if (min <= dy) dy = min;
      }
      int y1 = yMap.transform(minYValue()) + int(bar_offset * 0.01 * bar_width);
      return yMap.invTransform(y1) - minYValue();
    } else
      return 0.5 * bar_offset * 0.01 * bar_width;
  }
  return 0;
}
Ejemplo n.º 2
0
void PlotCurve::computeWaterfallOffsets()
{
  Plot *plot = static_cast<Plot *>(this->plot());
  Graph *g = static_cast<Graph *>(plot->parent());

  // reset the offsets
  d_x_offset = 0.0;
  d_y_offset = 0.0;

  if (g->isWaterfallPlot()){
    int index = g->curveIndex(this);
    int curves = g->curves();
    auto firstCurve = g->curve(0);
    // Get the minimum value of the first curve in this plot
    double ymin = firstCurve ? firstCurve->minYValue() : 0.0;
    PlotCurve *c = dynamic_cast<PlotCurve*>(g->curve(0));
    if (index > 0 && c){
      d_x_offset = index*g->waterfallXOffset()*0.01*plot->canvas()->width()/(double)(curves - 1);
      d_y_offset = index*g->waterfallYOffset()*0.01*plot->canvas()->height()/(double)(curves - 1);

      setZ(-index);
      setBaseline(ymin-d_y_offset); // Fill down to minimum value of first curve

    } else {
      setZ(0);
      setBaseline(ymin); // This is for when 'fill under curve' is turn on
    }
    if (g->grid())
      g->grid()->setZ(-g->curves()/*Count()*/ - 1);
  }
}