QCustomPlot Discussion and Comments

Graph points not visible when value==range.lowerReturn to overview

Hi
When the values of a graph are equal to the lower bound of the y axis range, the points are not visible.
They are visible for the upper bound.

The ticks and the grid line are OK, but the issue appears also for the zeroLine (if lower bound is 0).

Seems there is a pixel offset...

Quick example base on the QCP plot-examples project :

QVector<double> x(101), y(101), y2(101); // initialize with entries 0..100
  for (int i=0; i<101; ++i)
  {
    x[i] = i/50.0 - 1; // x goes from -1 to 1
    y[i] = 0.5;
    y2[i] = 1;
  }
  // create graph and assign data to it:
  customPlot->addGraph();
  customPlot->graph(0)->setData(x, y);
  customPlot->addGraph();
  customPlot->graph(1)->setData(x, y2);
  // set axes ranges, so we see all data:
  customPlot->xAxis->setRange(-1, 1);
  customPlot->yAxis->setRange(0, 1);
  customPlot->yAxis->grid()->setVisible(true);
  customPlot->yAxis->grid()->setZeroLinePen(QPen(Qt::red));
  customPlot->xAxis->setVisible(false);
  customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

The code is obviously not correct to show the issue....

Replace

y[i] = 0.5;

By

y[i] = 0;

Same issue for me. It seems that the range lower value is not visible in the plot area. Only the points between ]range.lower, range.upper] are displayed.

Will try to investigate.

I tried to figure out why the points where not displayed but it's not obvious, at least for me.

FIrst, as the grid line is visible, i checked the differences between the grid line (value 0) and the graph (constant value 0). The QLineF were 1px different.

To get the same QLineF coordinates, i had to change the QCPAxisRect::bottom() and QCPAxisRect::right() methods to get the x and y coordinate (https://doc.qt.io/qt-5/qrect.html#bottom).

But the line is still not visible...

I found a way to make it work but can't say if there are side effects...

In QCPLayer::draw() method, i commented the following line :

painter->setClipRect(child->clipRect().translated(0, -1));

The 1-pixel offset came from here.
Thus the data points with values equal to valueAxis.range().lower are now visible. (valid also for the item lines...)

Regarding the zeroLine, it's a QCP implementation choice as the axis range lower value must be < 0 to draw the zeroLine.

@DerManu, any comment/thought please ?

Don' forget to replace

painter->setClipRect(child->clipRect().translated(0, -1));

by
painter->setClipRect(child->clipRect());