Skip to content

allow unsetting options in PlotDataItem and PlotCurveItem#2041

Merged
j9ac9k merged 7 commits intopyqtgraph:masterfrom
NilsNemitz:PDI_parameter_pass
Nov 18, 2021
Merged

allow unsetting options in PlotDataItem and PlotCurveItem#2041
j9ac9k merged 7 commits intopyqtgraph:masterfrom
NilsNemitz:PDI_parameter_pass

Conversation

@NilsNemitz
Copy link
Copy Markdown
Contributor

This is a quick attempt to address #2039: Various plotting parameters can be set, but cannot be unset, especially when going through the PlotDataItem interfaces.

The origin of the problem is that much of the code implicitly assumes that a new element is initialized from zero, and there are explicit checks that cancel out of the update early when parameters are None.

This problem is present in both PlotDataItem and PlotCurveItem, but the faulty shortcut checks are particularly used in the setData() methods. I think the problem is worse when going through a PlotDataItem, because this tends to call PlotCurveItem.setData() with any changes,

I made a quick pass over the code and removed problematic shortcut checks for None, as well as unconditional mkBrush / mkPen calls that prevented setting these to explicit None values.

The tests seem to pass, and this seems to address the test cases described in #2039.
But I have probably missed a few things, so some additional testing and feedback would be appreciated!

@pijyoi , do you immediately see anything that this misses?

Closes #2039 ... once it works.

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Oct 24, 2021

(deleted, discussion in #2039)

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Oct 29, 2021

So almost all the options are "sticky" options. If you set an option in one call of setData, it will persist.
This supports usage such as:

item = pg.PlotCurveItem(pen='w', brush='b', connect='finite')
item.setData(x, y)

The exception is skipFiniteCheck which gets disabled if you don't specify it in setData. I don't know if it should be made consistent with the rest.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 29, 2021

I can be talked into skipFiniteCheck going either way. The first use case was intended to implement the "safest" way, to minimize the likelihood of that check accidentally being skipped,

I'm still partial to that mechanism; but I'm not sure we should have one option behave differently from the others.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 30, 2021

@NilsNemitz do you think skipFiniteCheck should be a sticky option along w/ the others?

@NilsNemitz
Copy link
Copy Markdown
Contributor Author

NilsNemitz commented Oct 30, 2021

Hmm. So far, I always read "skipFiniteCheck" as a hint for just the current dataset.

But there is an argument to be made for turning it sticky:
In many cases, your data source will never produce non-finite values. Being forced to set the hint for each setData() call is needless boilerplate then.
Doing that is only useful if

  • non-finite values occur only occasionally
  • the user code already knows when they are present.

And where that rare case applies, a sticky flag can still be updated with every call. So I think a sticky flag might be better.


self.opts['skipFiniteCheck'] = kargs.get('skipFiniteCheck', False)
if 'skipFiniteCheck' in kargs:
self.opts['skipFiniteCheck'] = kargs['skipFiniteCheck']
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updates skipFiniteCheck only on request. A default False value will be used if it is never explicitly set.

@NilsNemitz
Copy link
Copy Markdown
Contributor Author

The latest commit should make skipFiniteCheck a sticky flag that can be set once, and will still be effective during later setData() calls. It also adds a setSkipFiniteTest() method (for both PlotDataItem and PlotCurveItem) to allow setting/unsetting this outside of setData().

I have updated the documentation for the logic and effect, and also added some text that explains the recently added handling of wide lines.

I would also suggest adding a final one-year expiration period for the long-deprecated options stepMode=True, decimate and identical. I have added that for now. The main motivation would be to keep the code simple. If there is a reason to keep these mostly non-functional parameters, please let me know!

require merging the entire plot into a single entity before the alpha value can be applied. For plots with more
than a few hundred points, this can result in excessive slowdown.

Since version 0.12.3, this slowdown is automatically avoided by an algorithm that draws line segments
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 0.12.4 (or whichever version comes after 0.12.3)

@@ -496,7 +515,10 @@ def updateData(self, *args, **kargs):
if self.opts['stepMode'] in ("center", True): ## check against True for backwards compatibility
if self.opts['stepMode'] is True:
import warnings
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't just add this, but would you mind removing this import here given the static code checker is complaining about it?

by line segments.

| 'all' (default) indicates full connection.
| 'pairs' omits even-numbered segments.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous docs say that even-numbered segments are drawn, presumably counting from zero.

Copy link
Copy Markdown
Contributor Author

@NilsNemitz NilsNemitz Nov 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. If you naturally start counting from zero, then neither of these descriptions seems particularly helpful.
I would start counting segments from one, and found the previous text confusing.

How about:
" 'pairs' draws one separate line segment for each two points given, starting with the first point. " ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose 'pairs' draws one separate line segment for each two points given. would be good enough. Don't think there is any doubt about it starting from the first point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and changed.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 18, 2021

Thanks @NilsNemitz you clearly have been busy ...love the documentation updates too 👍🏻 merging.

@j9ac9k j9ac9k merged commit 21d77db into pyqtgraph:master Nov 18, 2021
ntjess pushed a commit to ntjess/pyqtgraph that referenced this pull request Dec 10, 2021
…2041)

* allow unsetting parameters in PlotDataItem and PlotCurveItem

* sticky skipFiniteCheck and documentation updates

* can't count

* removed duplicate import of wanrings

* minor documentation clean-up for PlotCurveItem

* clarify pairs parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

some PlotCurveItem options not resettable by PlotDataItem

3 participants