Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default export to combined EditorControls + Plot component #384

Merged
merged 9 commits into from
Mar 12, 2018

Conversation

nicolaskruchten
Copy link
Contributor

@nicolaskruchten nicolaskruchten commented Mar 7, 2018

I'm happy to rename the new component but the idea here is to provide something that, though it keeps a gross DOM node in state, looks and behaves like a dumb component which bundles an editor and a plot area.

this.state = {
graphDiv: {},
plotRevision: 0,
data: [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note the new state in App: just data and layout!

dev/App.js Outdated
dataSources={dataSources}
dataSourceOptions={dataSourceOptions}
plotly={plotly}
onUpdate={(data, layout) => this.setState({data, layout})}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note the new update call: just data and layout!

@@ -69,7 +69,7 @@ class PlotlyEditor extends Component {
this.props.afterUpdateTraces(payload);
}
if (this.props.onUpdate) {
this.props.onUpdate();
this.props.onUpdate(graphDiv.data, graphDiv.layout);
Copy link
Contributor Author

@nicolaskruchten nicolaskruchten Mar 7, 2018

Choose a reason for hiding this comment

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

in this iteration, we mutate and pass along. In the next iteration, we'll finally use immutability-helper to NOT mutate and pass along copies as per #212 :)

class PlotlyEditorWithPlot extends Component {
constructor(props) {
super();
this.state = {graphDiv: {}};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new component only stores the graphDiv in state, which it gets from Plot.

So the lifecycle of a user edit is now:

  • data/layout from PlotlyEditor up to PlotlyEditorWithPlot up to App
  • setState causes render for App
  • data/layout from App down to PlotlyEditorWithPlot down to Plot
  • graphDiv from Plot up to PlotlyEditorWithPlot
  • setState causes render for PlotlyEditorWithPlot
  • graphDiv from PlotlyEditorWithPlot down to PlotlyEditor

Copy link
Member

@bpostlethwaite bpostlethwaite left a comment

Choose a reason for hiding this comment

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

Cool lets try it out! Since you just built a great end-to-end testing machine lets get a couple tests in with this PR so we have some patterns to build off of.

Then we can start adding more tests with less friction!

@bpostlethwaite
Copy link
Member

here is the batch reporter end-to-end test https://github.com/plotly/plotly.js-batch-reporter/blob/master/example/src/index.test.js

There are a few accompanying helper functions. One of which https://github.com/plotly/plotly.js-batch-reporter/blob/master/example/src/index.test.js#L11 may be instructive.

@bpostlethwaite
Copy link
Member

bpostlethwaite commented Mar 7, 2018

@VeraZab
Copy link
Contributor

VeraZab commented Mar 7, 2018

This is what we suspected could make the editor really slow right? And it isn't really slow?
For names: Editor, Plot, PlotWithEditor?
But this looks good to me!

@nicolaskruchten
Copy link
Contributor Author

@VeraZab Well, I didn't think it would make things "really slow" I said there might be a performance hit from extra renders. It doesn't feel bad to me at all though :)

@nicolaskruchten
Copy link
Contributor Author

Actually the bigger performance hit probably came from #381

@nicolaskruchten
Copy link
Contributor Author

@VeraZab @bpostlethwaite here's my more radical proposal: let's change the top-level export to be this new combined component that looks more React-idiomatic. I've renamed the top-level component to PlotlyEditor and the old one to EditorControls in this PR.

@nicolaskruchten
Copy link
Contributor Author

If we like it, I can fix all the other examples and write some tests against it. I'm pretty convinced that this is a better way forward but we can discuss in person when @VeraZab is back :)

@VeraZab
Copy link
Contributor

VeraZab commented Mar 7, 2018

I like it! I feel like API users should not have to think about those things (most of them). And for the ones who do want to handle this in a more individual way, that's still available to them.

@nicolaskruchten
Copy link
Contributor Author

nicolaskruchten commented Mar 7, 2018

OK so remaining to do on this PR:

  • add an end to end testing framework stub
  • fix the README
  • fix the existing examples

@nicolaskruchten
Copy link
Contributor Author

@VeraZab check out how nice the examples are now! simple and redux :)

useResizeHandler
debug
advancedTraceTypeSelector
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

yeahhh!! I like it!! 🎉

package.json Outdated
@@ -20,7 +20,7 @@
"raf": "^3.4.0",
"react-color": "^2.13.8",
"react-colorscales": "^0.4.2",
"react-plotly.js": "^1.6.0",
"react-plotly.js": "^1.7.0",
"react-rangeslider": "^2.2.0",
"react-select": "^1.0.0-rc.10",
"react-tabs": "^2.2.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

on ajoute le nouveau plotly.js aussi?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@nicolaskruchten nicolaskruchten force-pushed the combocomponent branch 2 times, most recently from b21456f to f29c2f6 Compare March 8, 2018 20:01
this.props.graphDiv._fullLayout &&
(this.props.children ? this.props.children : <DefaultEditor />)}
</ModalProvider>
<div className="app">
Copy link

Choose a reason for hiding this comment

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

Should app here be replaced with a BEM class instead? (Perhaps by adjusting/moving the one now in EditorControls?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I just copied stuff over but app is a terrible class to bake in ;)

@nicolaskruchten nicolaskruchten changed the title [WIP] first stab at combined component Change default export to combined EditorControls + Plot component Mar 12, 2018
@nicolaskruchten
Copy link
Contributor Author

@VeraZab @bpostlethwaite ready for review. The end-to-end test is a stub but it works and can be built upon in future PRs :)

partly addresses #321

<div
className="plotly_editor_plot"
style={{width: '100%', height: '100%'}}
>
Copy link
Contributor

Choose a reason for hiding this comment

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

could these encoded styles go in the plotly_editor_plot className?

onInitialized={graphDiv => this.setState({graphDiv})}
onUpdate={graphDiv => this.setState({graphDiv})}
style={{width: '100%', height: '100%'}}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

and this too, can we not hard code here?

@VeraZab
Copy link
Contributor

VeraZab commented Mar 12, 2018

💃

1 similar comment
@bpostlethwaite
Copy link
Member

💃

@nicolaskruchten nicolaskruchten merged commit f207cb2 into master Mar 12, 2018
@nicolaskruchten nicolaskruchten deleted the combocomponent branch March 12, 2018 20:42
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.

4 participants