-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
add 'width' to box and violin trace #3109
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
Changes from 1 commit
8f04d13
f76ca97
81cdbe9
5ef2eeb
1c6b26b
2d93a0e
1f9ced8
26f44c4
77b9c9d
243a369
eb5e9da
eea273b
408aacb
0555283
4eb8b44
44e0a88
f8b963b
54aa355
0d4239b
fa3a314
c63780f
c24330d
6e7883d
37786d6
45ae47d
8366c88
ce81377
8885b5e
57cc05a
fe3d7ed
44fa269
f5ba38c
34722d3
d1aed48
c70f7d5
0dea0e9
5e5f9ee
d04c60c
91497e5
657848f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,23 +90,35 @@ function setPositionOffset(traceType, gd, boxList, posAxis, pad) { | |
var groupgap = fullLayout[traceType + 'groupgap']; | ||
var padfactor = (1 - gap) * (1 - groupgap) * dPos / fullLayout[numKey]; | ||
|
||
// Find maximum trace width | ||
// we baseline this at dPos | ||
var max_half_width = dPos; | ||
for(i = 0; i < boxList.length; i++) { | ||
calcTrace = calcdata[boxList[i]]; | ||
|
||
if(calcTrace[0].trace.vwidth) { | ||
if(calcTrace[0].trace.vwidth / 2 > max_half_width) { | ||
max_half_width = calcTrace[0].trace.vwidth / 2; | ||
} | ||
} | ||
} | ||
alexcjohnson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// autoscale the x axis - including space for points if they're off the side | ||
// TODO: this will overdo it if the outermost boxes don't have | ||
// their points as far out as the other boxes | ||
var extremes = Axes.findExtremes(posAxis, boxdv.vals, { | ||
vpadminus: dPos + pad[0] * padfactor, | ||
vpadplus: dPos + pad[1] * padfactor | ||
vpadminus: max_half_width + pad[0] * padfactor, | ||
vpadplus: max_half_width + pad[1] * padfactor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah good catch - unfortunately the It looks to me as though we could pretty easily fix this by calculating var thisDPos = calcTrace[0].t.dPos = (calcTrace[0].trace.width / 2) || dPos;
var positions = calcTrace.map(function(di) { return di.pos });
var extremes = Axes.findExtremes(posAxis, positions, {
vpadminus: thisDPos + pad[0] * padfactor,
vpadminus: thisDPos + pad[1] * padfactor
});
calcTrace[0].trace._extremes[posAxis._id] = extremes; That wouldn't address the original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not that much improvement, but there is some. Notice the vertical distance between the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right - because we don't take There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}); | ||
|
||
for(i = 0; i < boxList.length; i++) { | ||
calcTrace = calcdata[boxList[i]]; | ||
// set the width of all boxes and | ||
// override this width with | ||
// trace.width if it exists | ||
// set the width of all boxes | ||
// override dPos with trace.width if present | ||
if(calcTrace[0].trace && calcTrace[0].trace.vwidth) { | ||
calcTrace[0].t.dPos = calcTrace[0].trace.vwidth; | ||
calcTrace[0].t.dPos = calcTrace[0].trace.vwidth / 2; | ||
} else { | ||
calcTrace[0].t.dPos = dPos; | ||
calcTrace[0].t.dPos = dPos; | ||
} | ||
alexcjohnson marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🌴 var side = calcTrace[0].trace.side;
var vpadminus = (side === 'positive') ? 0 : (thisDPos + pad[0] * padfactor);
var vpadplus = (side === 'negative') ? 0 : (thisDPos + pad[1] * padfactor); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit worried actually that this will exacerbate the issue in the TODO above. For example what if you have a single-sided violin but the points get drawn on the other side? It looks to me like this algorithm will cut them off entirely. @etpinard thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does 🌴 mean? Don't repeat yourself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I noticed another bug - if we choose to show the box, it gets cut in half if we choose DATA: var data = [{
type: 'violin',
x: [0, 5, 7, 8],
points: 'all',
side: 'positive',
box: {
visible: true
},
boxpoints: true,
line: {
color: 'black'
},
fillcolor: '#8dd3c7',
opacity: 0.6,
meanline: {
visible: true
},
y0: 0.0
}]; I think we are going to have to correlate the currently The fact that the image tests passed tells me an example like ^ is not in mocks. I think we should add a single sided violin baseline. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah sorry, DRY - I guess that's just a plotly.js convention.
That's intentional, eg for two back-to-back violins. https://github.com/plotly/plotly.js/blob/master/test/image/baselines/violin_side-by-side.png |
||
|
||
// link extremes to all boxes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,12 +27,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout | |
|
||
coerce('bandwidth'); | ||
coerce('side'); | ||
|
||
var vwidth = coerce('vwidth'); | ||
if(!vwidth) { | ||
coerce('scalegroup', traceOut.name); | ||
coerce('scalemode'); | ||
} | ||
coerce('scalegroup', traceOut.name); | ||
coerce('scalemode'); | ||
coerce('vwidth'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect we should disable var width = coerce('width');
if(!width) {
coerce('scalegroup', traceOut.name);
coerce('scalemode');
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly, that's why we don't want to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, I marked this resolved when I saw that you added the conditional |
||
|
||
var span = coerce('span'); | ||
var spanmodeDflt; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Camel case please 🐫