Skip to content

Plotly.deleteTraces bug #73

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

Closed
wants to merge 1 commit into from
Closed

Plotly.deleteTraces bug #73

wants to merge 1 commit into from

Conversation

mdtusz
Copy link
Contributor

@mdtusz mdtusz commented Dec 3, 2015

When Plotly.deleteTraces is called on a plot with only one trace, it calls Plotly.plot with an empty data array, rendering a blank canvas and for some reason leaving the trace that you wanted to delete.

Recreation:

    Plotly.plot('graphDiv', [{ x: [1,2,3,4], y: [5,6,7,8] }], {});

    var graphDiv = document.getElementById('graphDiv');

    Plotly.deleteTrace(graphDiv, 0);

The fix is to check whether we are deleting the last trace of a data array, and if so, set gd.data = [{ type: 'someType' }] - the type is required to ensure that the correct axes/layout are redrawn for the type of data that previously existed.

By pushing the last object onto traces, it means that multiple "empty actions" will build up if someone continuously deletes the last trace - if anyone has suggestions for a good way to avoid this, I'm all ears.

@etpinard
Copy link
Contributor

etpinard commented Dec 3, 2015

To add some info:

Plotly.plot('id', []);

shows a graph a blank graph with no axes.

Plotly.plot('id', [{}]);

show blank cartesian axes (as the default trace type is 'scatter')

When Plotly.deleteTraces is called on a 1-trace graph, should we show a blank graph with no axes or a blank plot (axes or scene)?

I'd vote for the latter.

@alexcjohnson
Copy link
Collaborator

If you want an exciting error condition, follow @mdtusz 's initial recreation code, then call Plotly.Plots.purge(graphDiv) - endless loop of js errors!

Long ago the plotly workspace opened with a blank (cartesian) graph, ie we had designed it to do that when there was no data. If we do want to show something, this seems like the thing to show. But doing it by adding a fictitious trace is going to cause problems for users. And I wonder, are there also problems when deleting the last trace off a subplot? Or maybe in the future whenever we get to support for different subplot types, ie you have a map, or 3D scene, next to a cartesian subplot, and you delete the last trace off that. I'd much prefer to get to the bottom of why the data sticks around (I notice axis titles stick around too, if you have them) and THEN as a separate issue decide what to do with a blank plot.

We also muck it up if a user decides to make a plot entirely out of annotations, or shapes, with no data. For instance:

Plotly.newPlot(gd, [], {
    xaxis:{title:'red'},
    yaxis:{title:'blue'},
    annotations:[{text:'hi!', xref:'x', yref:'y', x:12, y:22}]
})

This should create x and y axes (with titles) and autorange them so the annotation is in the middle. Instead the annotation falls back to paper reference, and gets drawn way up in the corner (you can just see the corner of the h - this is so it's not gone entirely, though that requirement is itself a holdover from when the only way to position an annotation in the workspace was with the mouse... we could allow it to go offscreen completely now. So many layers to this seemingly simple bug!)

@mdtusz
Copy link
Contributor Author

mdtusz commented Dec 9, 2015

Nothing is ever simple :)

@alexcjohnson @etpinard @bpostlethwaite what should the expected behaviour be for when a user deletes the last trace (of any type)? I'd expect my axes to remain, but you bring up a good point about when there are subplots (although, I don't know too too much about how subplots are done yet).

@etpinard
Copy link
Contributor

closed in favour of #268

@etpinard etpinard closed this Feb 19, 2016
@etpinard etpinard deleted the patch-zero-data branch February 19, 2016 23:47
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.

3 participants