Skip to content

One-sided violins with set width fixes #3842

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

Merged
merged 2 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/traces/box/cross_trace_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ function setPositionOffset(traceType, gd, boxList, posAxis) {
var edge = bPos + bdPos;
var edgeplus;
var edgeminus;
// value-space padding
var vpadplus;
var vpadminus;
// pixel-space padding
var ppadplus;
var ppadminus;
// do we add 5% of both sides (more logic for points beyond box/violin below)
var padded = Boolean(width);
// does this trace show points?
var hasPts = (trace.boxpoints || trace.points) && (shownPts > 0);

if(side === 'positive') {
pushplus = dPos * (width ? 1 : 0.5);
Expand All @@ -147,17 +157,6 @@ function setPositionOffset(traceType, gd, boxList, posAxis) {
edgeplus = edgeminus = edge;
}

// value-space padding
var vpadplus;
var vpadminus;
// pixel-space padding
var ppadplus;
var ppadminus;
// do we add 5% of both sides (for points beyond box/violin)
var padded = false;
// does this trace show points?
var hasPts = (trace.boxpoints || trace.points) && (shownPts > 0);

if(hasPts) {
var pointpos = trace.pointpos;
var jitter = trace.jitter;
Expand Down
10 changes: 8 additions & 2 deletions src/traces/box/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function hoverOnBoxes(pointData, xval, yval, hovermode) {
hoverPseudoDistance, spikePseudoDistance;

var boxDelta = t.bdPos;
var boxDeltaPos, boxDeltaNeg;
var posAcceptance = t.wHover;
var shiftPos = function(di) { return di.pos + t.bPos - pVal; };

Expand All @@ -67,18 +68,23 @@ function hoverOnBoxes(pointData, xval, yval, hovermode) {
var pos = shiftPos(di);
return Fx.inbox(pos, pos + posAcceptance, hoverPseudoDistance);
};
boxDeltaPos = boxDelta;
boxDeltaNeg = 0;
}
if(trace.side === 'negative') {
dPos = function(di) {
var pos = shiftPos(di);
return Fx.inbox(pos - posAcceptance, pos, hoverPseudoDistance);
};
boxDeltaPos = 0;
boxDeltaNeg = boxDelta;
}
} else {
dPos = function(di) {
var pos = shiftPos(di);
return Fx.inbox(pos - posAcceptance, pos + posAcceptance, hoverPseudoDistance);
};
boxDeltaPos = boxDeltaNeg = boxDelta;
}

var dVal;
Expand Down Expand Up @@ -134,8 +140,8 @@ function hoverOnBoxes(pointData, xval, yval, hovermode) {
else if(Color.opacity(mc) && trace.boxpoints) pointData.color = mc;
else pointData.color = trace.fillcolor;

pointData[pLetter + '0'] = pAxis.c2p(di.pos + t.bPos - boxDelta, true);
pointData[pLetter + '1'] = pAxis.c2p(di.pos + t.bPos + boxDelta, true);
pointData[pLetter + '0'] = pAxis.c2p(di.pos + t.bPos - boxDeltaNeg, true);
pointData[pLetter + '1'] = pAxis.c2p(di.pos + t.bPos + boxDeltaPos, true);

pointData[pLetter + 'LabelVal'] = di.pos;

Expand Down
Binary file modified test/image/baselines/violin_box_multiple_widths.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/violin_ridgeplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading