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

box/violin vs bar positioning inconsistency #3502

Closed
nicolaskruchten opened this issue Feb 1, 2019 · 8 comments
Closed

box/violin vs bar positioning inconsistency #3502

nicolaskruchten opened this issue Feb 1, 2019 · 8 comments
Milestone

Comments

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented Feb 1, 2019

Not sure we can fix it in the context of the fix for #3402, but logging for reference:

Violin/box auto-populates x-axis categories here:

Plotly.newPlot(
  document.getElementById("gd"),
  {
    data: [{
      type: "violin",
      y: [1]
    },{
      type: "violin",
      y: [1]
    }],
  }
)

image

But bar does not:

Plotly.newPlot(
  document.getElementById("gd"),
  {
    data: [{
      type: "bar",
      y: [1]
    },{
      type: "bar",
      y: [1]
    }],
  }
)

image

@etpinard
Copy link
Contributor

etpinard commented Feb 8, 2019

Here's the block in question:

// In vertical (horizontal) box plots:
// if no x (y) data, use x0 (y0), or name
// so if you want one box
// per trace, set x0 (y0) to the x (y) value or category for this trace
// (or set x (y) to a constant array matching y (x))
function getPos(trace, posLetter, posAxis, val, num) {
if(posLetter in trace) {
return posAxis.makeCalcdata(trace, posLetter);
}
var pos0;
if(posLetter + '0' in trace) {
pos0 = trace[posLetter + '0'];
} else if('name' in trace && (
posAxis.type === 'category' || (
isNumeric(trace.name) &&
['linear', 'log'].indexOf(posAxis.type) !== -1
) || (
Lib.isDateTime(trace.name) &&
posAxis.type === 'date'
)
)) {
pos0 = trace.name;
} else {
pos0 = num;
}
var pos0c = posAxis.type === 'multicategory' ?
posAxis.r2c_just_indices(pos0) :
posAxis.d2c(pos0, 0, trace[posLetter + 'calendar']);
return val.map(function() { return pos0c; });
}

I guess we could add another attribute to optionally make things consistent between bar and box/violin traces and perhaps change the default in v2 (or v3 😏 ).

@nicolaskruchten
Copy link
Contributor Author

I think we will need an attribute to disable this behaviour for 1.45.0 otherwise PX will likely have trouble using offsetgroup and alignmentgroup correctly.

@etpinard
Copy link
Contributor

etpinard commented Feb 8, 2019

It shouldn't have any problems if x and y are set.

@etpinard
Copy link
Contributor

etpinard commented Feb 8, 2019

or x0 / y0

@nicolaskruchten
Copy link
Contributor Author

Yes, but PX doesn't require both to be set and I don't want to change that...

@etpinard
Copy link
Contributor

etpinard commented Feb 8, 2019

Ok, but then setting x0 or y0 will solve the issue? How is that different from adding a new box/violin attribute?

@nicolaskruchten
Copy link
Contributor Author

OK, fair enough.

@etpinard etpinard changed the title box/violin vs bar inconsistency box/violin vs bar positioning inconsistency Feb 8, 2019
@etpinard etpinard added this to the v2.0.0 milestone Feb 8, 2019
@gvwilson
Copy link
Contributor

Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson

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

3 participants