Skip to content

Commit

Permalink
Also fix violin traces
Browse files Browse the repository at this point in the history
  • Loading branch information
s417-lama committed Oct 25, 2019
1 parent 1e4aa7e commit 349ef64
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/traces/scatter/line_points.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ module.exports = function linePoints(d, opts) {
function getPt(index) {
var di = d[index];
if(!di) return false;
var x = xa.c2p(di.x);
var y = ya.c2p(di.y);
var x = opts.linearized ? xa.l2p(di.x) : xa.c2p(di.x);
var y = opts.linearized ? ya.l2p(di.y) : ya.c2p(di.y);

// if non-positive log values, set them VERY far off-screen
// so the line looks essentially straight from the previous point.
Expand Down
11 changes: 6 additions & 5 deletions src/traces/violin/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
connectGaps: true,
baseTolerance: 0.75,
shape: 'spline',
simplify: true
simplify: true,
linearized: true
});
return Drawing.smoothopen(segments[0], 1);
}
Expand Down Expand Up @@ -64,8 +65,8 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
var pathSel = d3.select(this);
var density = d.density;
var len = density.length;
var posCenter = d.pos + bPos;
var posCenterPx = posAxis.c2p(posCenter);
var posCenter = posAxis.c2l(d.pos + bPos, true);
var posCenterPx = posAxis.l2p(posCenter);

var scale;
if(trace.width) {
Expand All @@ -85,7 +86,7 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
for(i = 0; i < len; i++) {
pt = pts[i] = {};
pt[t.posLetter] = posCenter + (density[i].v / scale);
pt[t.valLetter] = density[i].t;
pt[t.valLetter] = valAxis.c2l(density[i].t, true);
}
pathPos = makePath(pts);
}
Expand All @@ -95,7 +96,7 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
for(k = 0, i = len - 1; k < len; k++, i--) {
pt = pts[k] = {};
pt[t.posLetter] = posCenter - (density[i].v / scale);
pt[t.valLetter] = density[i].t;
pt[t.valLetter] = valAxis.c2l(density[i].t, true);
}
pathNeg = makePath(pts);
}
Expand Down
Binary file added test/image/baselines/violin_log_scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions test/image/mocks/violin_log_scale.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"data": [
{
"y": [
1.0,
1.1,
1.0,
0.9,
1.2,
2.0,
1.5,
2.3,
1.7,
2.2,
1.0,
1.1,
1.2,
0.9,
1.1
],
"x": [
1,
1,
1,
1,
1,
10,
10,
10,
10,
10,
100,
100,
100,
100,
100
],
"type": "violin",
"box": {
"visible": true
},
"meanline": {
"visible": true
},
"side": "negative"
},
{
"y": [
2.2,
2.3,
2.0,
2.5,
2.1,
0.1,
0.5,
0.8,
0.3,
0.3,
2.4,
2.0,
1.5,
1.6,
1.9
],
"x": [
1,
1,
1,
1,
1,
10,
10,
10,
10,
10,
100,
100,
100,
100,
100
],
"type": "violin",
"meanline": {
"visible": true
},
"side": "positive"
}
],
"layout": {
"xaxis": {
"type": "log"
}
}
}

0 comments on commit 349ef64

Please sign in to comment.