jkriege2 / JKQtPlotter

an extensive Qt5 & Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
http://jkriege2.github.io/JKQtPlotter/index.html
GNU Lesser General Public License v2.1
889 stars 190 forks source link

Support QScrollBar #133

Closed taibai123abc closed 1 month ago

taibai123abc commented 2 months ago

JKQTPlotter cannot support QScrollBar originally. I have released a plot with QScrollBar. But while I drag the plot, i cannot update the graph. Can you add a signal which can be emited after the plot has been drag?

jkriege2 commented 2 months ago

I'm not sure what you try to achieve?

Bind a scrollbar to a plot, that displays a section from a graph with pre-known maximalextent?

I think you could achieve such a thing, using the signal JKQTPlotter::zoomChangedLocally() ... that signal is emitted, whenever the zoom changes and provides the currently displayed data-range in x- and y-direction. The you could calculate the data required for the QScrollBar ...

Does that help?

taibai123abc commented 2 months ago

Yes, and I have achieved it like this slot:

void FormWithJKQTPlotter::onActionViewChanged(int value)
{
    JKQTPDatastore* ds = ui->plot->getDatastore();
    //dateAndTime and squeezeData are the whole data, partXData and partYData 
    //are the data which are shown on the plot.
    QVector<double> partXData = dateAndTime.mid(value, ui->numSpinBox->value());
    QVector<double> partYData = squeezeData.mid(value, ui->numSpinBox->value());

    ds->clear();
    size_t colDate = ds->addCopiedColumn(partXData, "date");
    size_t colSq = ds->addCopiedColumn(partYData, "squeeze");

    graph->setXColumn(colDate);
    graph->setYColumn(colSq);

    ui->plot->getXAxis()->setTickLabelType(JKQTPCALTdatetime);
    ui->plot->getXAxis()->setAxisLabel("Time and Date");
    ui->plot->getXAxis()->setTickDateTimeFormat("yyyy/MM/dd HH:mm");
    ui->plot->getXAxis()->setTickLabelFontSize(5);
    ui->plot->getXAxis()->setTickSpacing(3);
    ui->plot->zoomToFit();
    ui->plot->show();
    ui->plot->resize(600, 300);
}

But I faced a problem that when I drag the graph horizontally, the left and right sides of the graph cannot be refreshed. The effect is shown below: image The right side graph cannot be complemented while i drag the plot. Though the jkqtplotter has many useful signals such as plotMouseMove, plotMouseWheelOperated and so on, but i cannot find a suitable signals for the drag "event".

Bind a scrollbar to a plot, that displays a section from a graph with pre-known maximalextent?

jkriege2 commented 1 month ago

Please have a look at the recently added example https://github.com/jkriege2/JKQtPlotter/tree/master/examples/ui_bind_scrollbar , which shows how to do what you requested ... unless I missunderstood your request ;-)

taibai123abc commented 1 month ago

Thanks, I have changed the problem via the signal "zoomChanged locally".