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

Introducing Plotly.update #875

Merged
merged 14 commits into from
Sep 7, 2016
Merged

Introducing Plotly.update #875

merged 14 commits into from
Sep 7, 2016

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Aug 22, 2016

resolves #671

This PR adds a top-level API method: Plotly.update. In brief, Plotly.update combines trace and layout update logic from Plotly.restyle and Plotly.relayout respectively so that user can update both a graphs's trace and layout objects at the same time.

The API is the following:

/**
 * update: update trace and layout attributes of an existing plot
 *
 * @param {string id or DOM element} gd
 *  the id or DOM element of the graph container div
 * @param {object} traceUpdate
 *  attribute object `{astr1: val1, astr2: val2 ...}`
 *  corresponding to updates in the plot's traces
 * @param {object} layoutUpdate
 *  attribute object `{astr1: val1, astr2: val2 ...}`
 *  corresponding to updates in the plot's layout
 * @param {number or array} traces (optional)
 *  integer or array of integers for the traces to alter (all if omitted)
 *
 */

where:

  • Plotly.update(gd, traceUpdate, {}) is the same as Plotly.restyle(gd, traceUptate) and
  • Plotly.update(gd, {}, layoutUpdate) is the same as Plotly.relayout(gd, layoutUpdate)

- this move will allow us to test (with jasmine spies)
  that the proper subroutines are called.
- split flag-finding logic with plot-routine sequence building
- in a similar way to Plotly.restyle
- reuse flag-finding methods called in restyle & relayout
- combine flags into subroutine sequences
- testing that the correct subroutines are called.
@etpinard etpinard added this to the v1.17.0 milestone Aug 22, 2016
@etpinard
Copy link
Contributor Author

I had to move around a lot of restyle / relayout code in order to keep things DRY while adding Plotly.update.

@chriddyp / @VeraZab or anyone in @plotly/frontend

Would someone mind pulling down this branch and test that it doesn't break anything in the plot.ly workspace?

Thanks in advance.

var ModeBar = require('../components/modebar');


exports.layoutStyles = function(gd) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Attaching plot/update subroutines to a separate modules allows us to easily test whether the correct subroutine is called on update using jasmine spies. See 26c4075 for example.

@VeraZab
Copy link

VeraZab commented Aug 23, 2016

Nice!
Well, looks like everything's working, at least from what I've played around with..
test

cc @chriddyp
I've followed this: https://github.com/plotly/dev-docs/blob/master/advanced/plotly.js.md#developing-plotlyjs-in-streambed

so, just fyi, or correct me if I'm wrong somewhere in here as I'm doing more and more of this and want to make sure I'm doing it right:

  1. I've cloned and pulled the latests from the plotly.js repo, which for me is saved in this directory: ~/plotly/plotly.js

  2. Did:
    ~/plotly/streambed (master)* npm link plotly.js,
    saw that the output of this was:
    /Users/verazabeida/plotly/streambed/node_modules/plotly.js -> **/Users/verazabeida/n/lib/node_modules/plotly.js**,
    so that's how I knew which patch to use in the next step, hope the order didn't matter..

  3. Cd'd into Etienne's branch and did npm link:
    ~/plotly/plotly.js (update-method)* npm link /Users/verazabeida/n/lib/node_modules/plotly.js -> /Users/verazabeida/plotly/plotly.js

  4. Did: ~/plotly/streambed/shelly/plotlyjs/bin (master)* ./watch.sh

  5. then in streambed ran my build script as usual

  6. everything seems to have worked as when I ran this
    ~/plotly/streambed (master)* ls -l node_modules | grep ^l,
    I got: lrwxr-xr-x 1 verazabeida staff 37 23 Aug 08:20 plotly.js -> ../../../n/lib/node_modules/plotly.js

  7. Then, when I was done:
    ~/plotly/streambed (master)* npm unlink plotly.js
    and to recover my normal state: ~/plotly/streambed/shelly/filewell (master)* npm install

* Can be called two ways.
*
* Signature 1:
* @param {string id or DOM element} gd
Copy link
Contributor

Choose a reason for hiding this comment

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

🐄 | instead of or for jsdoc (although we don't generate them so it's kinda moot...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in e8dbf55

@mdtusz
Copy link
Contributor

mdtusz commented Aug 23, 2016

Looks good! It would be awesome if we could have a more programatic/automated test suite to ensure that things are all "caught" and get their respective updates using this method, but it can be done down the road. This will make things so much easier 😸

💃

@VeraZab
Copy link

VeraZab commented Aug 29, 2016

mapbox plots are broken on this branch
test3

@etpinard
Copy link
Contributor Author

etpinard commented Sep 1, 2016

mapbox plots are broken on this branch

@VeraZab any console errors? Mapbox traces are working fine in the plotly.js test dashboard.

@theengineear
Copy link
Contributor

^^ @VeraZab I made some changes to how mapbox info is updated. Can you ssh into yr vagrant box and ensure that:

echo $PLOTLY_MAPBOX_DEFAULT_ACCESS_TOKEN

isn't empty?

@VeraZab
Copy link

VeraZab commented Sep 4, 2016

ah @etpinard was still not linking properly. All good now. All works ! 💃 :)
and thanks @theengineear , everything was good with the accesstoken

@etpinard
Copy link
Contributor Author

etpinard commented Sep 6, 2016

@rreusser commits 3db6d21 and c15a617 DRYed the trace indices input argument logic used in Plotly.restyle, Plotly.update and Plotly.animate (as of #802), I hope you like it.

@rreusser
Copy link
Contributor

rreusser commented Sep 6, 2016

Awesome. Love it. Can make use of it, I think...

@etpinard etpinard merged commit 7916bb3 into master Sep 7, 2016
@etpinard etpinard deleted the update-method branch September 7, 2016 13:42
@theengineear
Copy link
Contributor

🎉!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should we add a Plotly.update method?
5 participants