Skip to content

Clear axis types during Plotly.newPlot #1285

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

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Jan 6, 2017

fixes #1231

So that calling plot then newPlot using the same layout object does not lead to any side-effects.

For example,

var gd = document.getElementById('graph')
var layout = {};

var numberTrace = {
  x: [22000, 22100, 2300],
  type: "histogram"
};

var stringTrace = {
  x: ['apple', 'orange'],
  type: "histogram"
};

Plotly.plot(gd, [numberTrace], layout);

console.log(layout.xaxis.type)  // => 'linear'

// so subsequent `newPlot` will try to plot a categorical histogram
// on  a linear axis.

Plotly.newPlot(gd, [stringTrace], layout);

There are probably other auto attributes (referencing #1282) that could/should get the same treatment in newPlot. Obviously, the real way to fix this issue would to not mutate the user layout object, but that's a much harder project.

- so that calling plot then newPlot using the same layout object
  does not lead to any side-effects.
@etpinard etpinard added status: in progress bug something broken labels Jan 6, 2017
@etpinard
Copy link
Contributor Author

etpinard commented Jan 6, 2017

@alexcjohnson thoughts on this?

@alexcjohnson
Copy link
Collaborator

If we do that, then you can't use newPlot in cases where the axis autotype is wrong.

One way I can imagine doing this that wouldn't be too invasive:

  • when we set an autotype, save a private var (like _autotype: true) in the fullLayout axis.
  • in your new loop in newPlot, instead do something like:
var axList = Plotly.Axes.list(gd);
for(var i = 0; i < axList.length; i++) {
    var ax = axList[i];
    var axIn = layout[ax._name];
    if(axIn && axIn.type && ax._autotype) axIn.type = '-';
}

@etpinard
Copy link
Contributor Author

etpinard commented Jan 6, 2017

Ooops. I forgot to push one commit. Thanks for checking!

But I guess most importantly, would you be ok with this kind of (hacky) solution in newPlot?

@alexcjohnson
Copy link
Collaborator

would you be ok with this kind of (hacky) solution

yes - hack away :)

@etpinard
Copy link
Contributor Author

Closing. We'll come up with a better solution as part of #1850

@etpinard etpinard closed this Jul 19, 2017
@etpinard etpinard deleted the newplot-axis-type branch July 19, 2017 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

newPlot does not clear histogram axis type!!!
2 participants