Skip to content

Re-set autobin when defaults override. #149

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 2 commits into from
Closed

Conversation

mdtusz
Copy link
Contributor

@mdtusz mdtusz commented Dec 28, 2015

Fairly straightforward fix. Take a look and let me know if there's a more suitable place to put this logic.

// If autobinned before, autobin again. supplyDataDefaults sees
// the generated bin object and assumes it has been set manually
// so we need to override that behaviour.
if (oldFullData[i]){
Copy link
Contributor

Choose a reason for hiding this comment

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

this belongs in Plotly.restyle

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, on second thought, moving this block to restyle would not fix the problem in Plotly.extendTraces

@etpinard
Copy link
Contributor

@mdtusz (cc @alexcjohnson @cldougl)

Times where the calc or plot step adds attributes to user data:

  • histogram and histogram2d calc step: xbins and ybins when autobin? is true
  • contour calc step: contours when autocontours is true
  • contour plot step: zmin and zmax when zauto is true and coloring set to 'heatmap'
  • heatmap calc step: zsmooth when data can't be smooth using the 'fast' algorithm.
  • colorscale calc: zmin / zmax or cmin / cmax + colorscale when zauto or cauto is true

@etpinard
Copy link
Contributor

Updating histogram data should clear the computed xbins and ybins, but the other cases aren't as obvious.

Should updating contour data clear the computed contours attributes? I'd vote for no.

Should the updating data linked to a colorscale update the bounds of the colorscale? I'd vote for no also.

So, looks like xbins ans ybins are in a league of their own.

@mdtusz
Copy link
Contributor Author

mdtusz commented Dec 29, 2015

Is it possible for a restyle/extendTraces to display incorrectly on plots using contours or colorscales? E.g. extending a trace to a point where the initially generated contous will be incorrect?

@etpinard
Copy link
Contributor

@mdtusz

display incorrectly on plots using contours or colorscales?

everything is displayed correctly. My comment referred to the computed auto contour and auto colorscale ranges.

For example, at the moment, starting from a heatmap trace with zauto true (which is the default btw), calling Plotly.restyle with new z data doesn't re-compute zmin and zmax.

I think this correct. Updating heatmap data should not magically re-compute the colorscale range.

@etpinard
Copy link
Contributor

@mdtusz this turns out to a pretty hard problem.

First, the problem of #24 only affects restyle/extendTraces calls with new data outside the computed [ xbins.start , xbins.end ] interval (or the corresponding ybins interval for horizontal histograms).

e.g.

Plotly.plot(Tabs.fresh(), [
    {
        type: 'histogram',
        x: [ 0, 1, 1, 2, 2, 2, 3, 3, 4]
    }]
).then(function(gd) {
    Plotly.extendTraces(gd, {x: [[2,2,2,2]]}, [0]);
}).then(function(gd) {
    Plotly.restyle(gd, {x: [[0,0,0,1,2,3,3,3,4,4]]}, [0])
});

behaves as expected.

Now, consider the case where a user sets the xbins manually and then calls restyle/extendTraces:

Plotly.plot(Tabs.fresh(), [
    {
        type: 'histogram',
        x: [ 0, 1, 1, 2, 2, 2, 3, 3, 4],
        xbins: {     // N.B. this defaults fullTrace.autobinx to true
           start: 0,
           end: 4,
           size: 1
        }
    }]
).then(function(gd) {
    Plotly.extendTraces(gd, {x: [[2,2,2,2]]}, [0]);
});

then, the extendTraces call should not clear the set xbins. The patches on this branch make restyle and extendTraces clear them, erroneously.

I'm not sure what the solution should be.

We could to find a way to extend the [ xbins.start, xbins.end ] interval on restyle/extendTrace only when oldFullTrace.autobinx is true, somewhere in supplyDefaults like you have it here. To note, the histogram calc step fills in xbins but does not touch autobinx. Even then, I'm not convinced it's the way to go.

@mdtusz
Copy link
Contributor Author

mdtusz commented Mar 21, 2016

At present, this PR will likely create more issues than it solves, so it is being temporarily closed.

@mdtusz mdtusz closed this Mar 21, 2016
@etpinard etpinard deleted the restyle-re-range branch January 30, 2018 14:53
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.

2 participants