Skip to content

unable to set tickwidth and tickcolor via template #4852

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
archmoj opened this issue May 21, 2020 · 7 comments · Fixed by #4904
Closed

unable to set tickwidth and tickcolor via template #4852

archmoj opened this issue May 21, 2020 · 7 comments · Fixed by #4904
Labels
bug something broken
Milestone

Comments

@archmoj
Copy link
Contributor

archmoj commented May 21, 2020

Demo

@archmoj archmoj added the bug something broken label May 21, 2020
@archmoj
Copy link
Contributor Author

archmoj commented May 21, 2020

@alexcjohnson
Hmm... not sure if this is a bug?
It goes down to here:

if(!Lib.isPlainObject(layoutIn[axName])) {
layoutIn[axName] = {};
}

Should we support template for axes?

@alexcjohnson
Copy link
Collaborator

I think the problem is a little more subtle than that. We do support templating axes, but currently Lib.coerce2 does not consider a template value to be "non-default."

Consider: just adding empty containers for the axes also doesn't show the ticks:

Plotly.newPlot(gd, {
  data: data,
  layout: {
    template: {layout: layout},
    yaxis: {},
    xaxis: {}
  }
});

But if you explicitly turn the ticks on they have the style from the template:

Plotly.newPlot(gd, {
  data: data,
  layout: {
    template: {layout: layout},
    yaxis: {ticks: 'outside'},
    xaxis: {ticks: 'inside'}
  }
});

And if you turn ticks on explicitly from the template, that also makes them appear:

var layout = {
  "yaxis": {
    "type": "log",
    "tickwidth": 5,
    "tickcolor": "green",
    ticks: 'outside'
  },
  "xaxis": {
    "type": "date",
    "tickwidth": 50,
    "tickcolor": "red",
    ticks: 'outside'
  }
};
Plotly.newPlot(gd, {
  data: data,
  layout: {
    template: {layout: layout}
  }
});

What's happening is in this block:

var tickLen = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'ticklen');
var tickWidth = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickwidth');
var tickColor = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickcolor', containerOut.color);
var showTicks = coerce('ticks', (options.outerTicks || tickLen || tickWidth || tickColor) ? 'outside' : '');

Lib.coerce2 returns false because no user value was provided, even though the template provided a value. So ticks defaults to '' rather than 'outside'.

In this particular case I think it's clear that we want to consider the template value to be "non-default" and to therefore cause ticks to be shown. I think that's a generally true statement, following from the principle that layout: obj should produce equivalent output to layout: {template: {layout: obj}}, so we should fix that at the level of Lib.coerce2, but we should explore some of the other uses of Lib.coerce2 before deciding that for sure.

@archmoj
Copy link
Contributor Author

archmoj commented Jul 23, 2020

Reopening after the revert by #5016.

@archmoj archmoj reopened this Jul 23, 2020
@nicolaskruchten
Copy link
Contributor

is it true that we can't set the tickwidth etc in the template ? or just that we have to also show the ticks from the template?

@archmoj
Copy link
Contributor Author

archmoj commented Jul 23, 2020

We were unable to set that before v1.54.4. Now moving forward with v1.54.7, again we cannot set that.

@nicolaskruchten
Copy link
Contributor

I can't agree with "we cannot set that" ... if you also set ticks: "outside" in the template then you'll see that the provided tickwidth values in the template are indeed set in the figure. So the problem is not precisely "you can't set it", the problem is that "setting it doesn't also trigger all the other default behaviours it does when it's set in the layout".

@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

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
4 participants