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

Consistently either mutate or replace data and layout? #1492

Closed
druvisc opened this issue Mar 17, 2017 · 2 comments
Closed

Consistently either mutate or replace data and layout? #1492

druvisc opened this issue Mar 17, 2017 · 2 comments
Labels
feature something new

Comments

@druvisc
Copy link

druvisc commented Mar 17, 2017

http://codepen.io/anon/pen/vxWRry

The graphDiv.data looks like it 'should be', the trouble is with the passed in data array. At the first addTraces call the data array gets mutated and the trace gets added at the end of the array, not at the specified index, and further addTraces calls don't even further mutate the array.

This is very confusing and I'd say it's a bug one way or another (mutating the passed in data array or not continuing to do so after the first addTraces call, even if the addTraces index gets ignored). Should be clear that there's only one 'source of truth' so either the graphDiv.data should be accessed or the developer should keep tabs on the traces himself.

Currently the functionality for my use (Angular2 and input binding) is broken and I'll have to resort to to Plotly.redraw.

@alexcjohnson
Copy link
Collaborator

Thanks for the report @druvisc

graphDiv.data - and graphDiv.layout - are intended to be the 'source of truth', and all changes to a plot first modify these objects and then propagate the changes to the plot. We've never made a commitment either way about what would happen to the specific data and layout objects you pass in, whether they would mutate or be replaced. But I can see that the behavior of addTraces, doing half the mutation and then replacing the array, is particularly non-intuitive, and potentially harmful if you aren't expecting it.

When things change, we've generally mutated rather than replaced, owing largely to performance for cases like streaming new data into existing x/y arrays. We would consider making this a guarantee, that we will only ever mutate these objects, so your original reference remains a valid view into the plot state, but I would consider that a new feature rather than a bug.

@alexcjohnson alexcjohnson changed the title [bug] Plotly.addTraces Consistently either mutate or replace data and layout? Mar 18, 2017
@gvwilson
Copy link
Contributor

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

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

No branches or pull requests

3 participants