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

Feature: Update/remove/replace Trace from Graph #45

Open
3 tasks
bcliang opened this issue Jul 15, 2020 · 3 comments
Open
3 tasks

Feature: Update/remove/replace Trace from Graph #45

bcliang opened this issue Jul 15, 2020 · 3 comments

Comments

@bcliang
Copy link
Owner

bcliang commented Jul 15, 2020

Background

#35 requested support for a "sorted" extend
#39 asked about updating data within a trace

Unfortunately, the plotly.js graphing library doesn't support this type of "data update". In both cases, the feature could be implemented on the callback side provided there is/was a way to replace (or just delete) an existing trace.

Imagined use-case within a callback:

  1. Grab existing trace data in callback:
#either 
[..Input('graph', 'figure')]
#or
[..State('graph', 'figure')]
  1. Make updates/modifications to the trace in question:
..
# add new values to x,y and sort by x
data_unsorted = zip(data[0]['x'].extend(new_x_values), data[0]['y'].extend(new_y_values))
data_sorted = sorted(data_unsorted, key=lambda x: x[0])
# map results to independent lists to be used in the callback output
x_new, y_new = map(list, zip(*data_sorted))
  1. Do something like
  • delete the existing trace, add a new one to the figure (replace a trace)
  • delete the existing trace, add a new one with the same trace index (update existing trace)

In the above case, it may be better to go with update in order to support preserving the trace order for the figure (for future indexing)

Considerations

  • Could implement support for this within the extendData callback, and possibly rename it to a more general name e.g. updateData. Pros: It already supports specifying the trace index. In this implementation, I suppose there would be an additional input allowing the user to specify whether to extend, replace, or just delete a trace. Cons: complexity increases
  • Could implement separate props the explicitly implements delete, replace, and/or update functions. Pros: simpler to test, easier to implement each prop on its own. Cons: More difficult on the dash-side to perform required operations (e.g. if logic flows in such a way that some conditions require update, others require extend, and still others require delete)
  • While we're at it, what about implementing a prependData prop / adding it to the extendData prop? Plotly.prependTraces() exists, and this is a special case for updating a trace. I'm sure there's a use case, though no one has explicitly requested it.
  • To get a better sense of actual use case(s), prototype something similar within a PR made to dash-core-components

Requires

  • Decide on which use case(s) to support via new/existing props.
  • Ensure that figure.data contains the latest trace information. I'm not sure but it's possible that when using the extendData callback that figure.data isn't immediately updated.
  • Add functionality for Plotly.deleteTraces()
@hxse
Copy link

hxse commented Sep 1, 2020

Very expecting

@bcliang
Copy link
Owner Author

bcliang commented Sep 1, 2020

Looks like dash-core-components.Graph will be getting a prependData() method. plotly/dash-core-components#850

Add that to scope here.

  • Interface with Plotly.prependTraces API

@bcliang
Copy link
Owner Author

bcliang commented Sep 1, 2020

Very expecting

@hxse, which use case do you have in mind? I have not been working on this feature as I have been loaded with work. If you can describe what you need, that would help make a decision on how to implement the above. If it's a small use case it might be easier to do a partial implementation (e.g just creating an additional prop specifically for prependData, deleteTrace or insertTrace)

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

2 participants