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

Should Plotly.restyle throw error(s) when the update object isn't valid? #167

Closed
harshjv opened this issue Jan 7, 2016 · 7 comments
Closed
Milestone

Comments

@harshjv
Copy link

harshjv commented Jan 7, 2016

Consider this setup,

var data = [
  {
    y: ['22.3', '23'],
    x: ['2001-06-11 11:00', '2001-06-11 11:10'],
    line: {
      'width': 2
    },
    uid: '40abaa'
  }
]

var layout = {
  yaxis: {
    title: 'Rate'
  },
  margin: {
    l: 40, b: 40, r: 40, t: 40
  }
}

Plotly.plot('mydiv', data, layout)

This dosen't work, and clears the plot

var update = {
  x: ['2001-06-15 11:10', '2001-06-15 11:20'],
  y: ['23', '100.3']
}

Plotly.restyle('mydiv', update)

But this is working

var update = {
  y: ['23', '100.3']
}

Plotly.restyle('mydiv', update)

Plotly.restyle is handling two axis data update incorrectly and clears the existing data on the plot.

@mdtusz
Copy link
Contributor

mdtusz commented Jan 7, 2016

Thanks for opening the issue. I'll take a look into this and we'll hopefully have a fix in a future release. We're always open to community pull requests as well if they follow our contributing guidelines and style!

For now, your best bet is to use Plotly.newPlot or change the plot data manually and call Plotly.redraw as seen here.

@mdtusz mdtusz added the bug something broken label Jan 7, 2016
@etpinard
Copy link
Contributor

etpinard commented Jan 7, 2016

@harshjv Your update object should be:

var update = {
  x: [['2001-06-15 11:10', '2001-06-15 11:20']],
  y: [['23', '100.3']]
};

to update the x and y of your single-trace graph.

The restyle syntax works as fellow, the outer array maps to different traces i.e. your above update object mapped '2001-06-15 11:10' to the x in the first (and only) trace of your graph. As x and y need to be linked to an array, the graph is left blank after the update.

So, to update the the x data, you need to nest the update data array.

More info about the restyle syntax here. Unfortunately our docs on restyle are limited at the moment. Our apologies.

That said, one could argue that trying to update x (or y) with a scalar should throw an error. @mdtusz @cldougl thoughts?

@etpinard etpinard removed the bug something broken label Jan 7, 2016
@harshjv
Copy link
Author

harshjv commented Jan 7, 2016

@etpinard Thanks. 👍

@etpinard
Copy link
Contributor

etpinard commented Jan 7, 2016

@harshjv no problem. I'd rename your issue to reflect the discussion about possibly making restyle throw errors.

@etpinard etpinard changed the title Problem with 2 axis on restyle Should Plotly.restyle throw array when update object isn't valid? Jan 7, 2016
@etpinard etpinard changed the title Should Plotly.restyle throw array when update object isn't valid? Should Plotly.restyle throw error(s) when the update object isn't valid? Jan 7, 2016
@cldougl
Copy link
Member

cldougl commented Jan 7, 2016

No initial opposition to throwing an error from me.
Regarding docs: we mention wrapping with the outer array in the function reference doc,
but I think it could be a bit more clear if we add a codepen example updating data and possibly use x/y data instead of z (it might be a little easier to see/understand the outer array looking at an x array opposed to a z matrix).

@ocramz-mhc
Copy link

Hi! I've been pulling my h playing with restyle() and agree that validation needs more informative error messages.

@gvwilson
Copy link
Contributor

gvwilson commented Jun 5, 2024

Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson

@gvwilson gvwilson closed this as completed Jun 5, 2024
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

No branches or pull requests

6 participants