Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Modified Graph.react.js to include restyle event #483

Merged
merged 9 commits into from
Mar 18, 2019

Conversation

mako-npm
Copy link
Contributor

@mako-npm mako-npm commented Mar 9, 2019

#197
https://community.plot.ly/t/interactive-callback-on-legend-click/9236/6

Made changes to Graph.react.js to add support for restyle events, restyleData is now an available component_property for graph components in Dash. Toggling on/off legend items now triggers callbacks with the associated restyleData component property.

@alexcjohnson
Copy link
Collaborator

alexcjohnson commented Mar 9, 2019

Nice, thanks for the PR @mako-npm! A few things we'll need to finish this:

  • Looks like the linter had a complaint, you can fix it with npm run format.
  • I'd also like to add a test for restyleData - but as we don't have any graph event data tests yet, unless you're feeling adventurous I'll be happy to do that part next week.
  • There are some percy test failures. They look like flaky tests rather than anything you did in this PR, but no time like the present to fix that! Again, I can take a look at this next week.

@lo-ise
Copy link

lo-ise commented Mar 13, 2019

Hey folks, huge thanks @mako-npm for this PR, I could really use this feature. And huge thanks @alexcjohnson for looking into the issues. Looking forward to this getting merged.

'layout': {
'width': 700,
'height': 450
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what to say about this one... I'm tempted to consider it a bug, but I don't know what we'd do to fix it. The issue - and I still don't understand why it's triggered intermittently here, but it's a real issue users will face - is that if you have an autosized graph that's initially drawn in a display: none container, it gets the default size. It keeps that default size when the container is displayed, because no redraw is triggered. But if the window is resized at all, THEN the graph gets sized correctly.

This seems to sometimes happen on CI - see eg https://percy.io/plotly/dash-core-components/builds/1576352?utm_campaign=plotly&utm_content=dash-core-components&utm_source=github_status - so I'm just locking down the size here.

button = self.wait_for_element_by_css_selector('#button')
self.snapshot(test_name + ' -> initial')
Copy link
Collaborator

Choose a reason for hiding this comment

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

take the snapshot after we know the button exists

@alexcjohnson alexcjohnson requested a review from T4rk1n March 15, 2019 03:01
gd.on('plotly_restyle', eventData => {
const restyleData = filterEventData(gd, eventData, 'restyle');
if (!isNil(restyleData)) {
if (setProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🔪 Think we can remove these checks now ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

good call. In case @Marc-Andre-Rivet is already working on removing the others I'll just do this one for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

🔪 in 8e7806b - but as commented I only changed the new prop for now.

* Data from latest restyle event which occurs
* when the user toggles a legend item
*/
restyleData: PropTypes.object,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a shape instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh right, it’s actually a length-2 array of the args to Plotly.restyle - the first one an object of <attribute.string>: <value>, the second an integer or array of integers for the trace indices. So I’ll change it to array and describe this (yes, it’s also read-only) but it doesn’t look to me as though PropTypes allows us to do better other than via custom function, which wouldn’t do the user any good. Is that right or am I missing how to do that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Changed to array and improved docs (including read-only on all the event data props) in 688a66f

@@ -271,6 +279,12 @@ const graphPropTypes = {
*/
relayoutData: PropTypes.object,

/**
* Data from latest restyle event which occurs
* when the user toggles a legend item
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not obvious to me if this prop is read-only or not. From reading the code I'd say changing it has no effect, so it's a read only and should be stated.

Copy link
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

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

💃 Docstrings looks great!

@alexcjohnson alexcjohnson merged commit 33118ed into plotly:master Mar 18, 2019
@alexcjohnson
Copy link
Collaborator

Thanks @mako-npm for kicking this off! This will be part of our next release, which should come out in the next couple of days.

@mako-npm
Copy link
Contributor Author

@alexcjohnson Thanks for all the work on this, looking forward to seeing it!

@mako-npm mako-npm deleted the Add_restyle_prop branch March 20, 2019 20:33
@mako-npm mako-npm restored the Add_restyle_prop branch March 20, 2019 20:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants