Skip to content

Commit 19a960b

Browse files
committed
Normalize cheater range for better consistency
1 parent cd246e9 commit 19a960b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/traces/carpet/cheater_basis.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,30 @@ module.exports = function(a, b, cheaterslope) {
3535
bscal = (bdata.length - 1) / (bdata[bdata.length - 1] - bdata[0]) / (nb - 1);
3636
}
3737

38+
var xval;
39+
var xmin = Infinity;
40+
var xmax = -Infinity;
3841
for(j = 0; j < nb; j++) {
3942
data[j] = [];
4043
bval = bdata ? (bdata[j] - bdata[0]) * bscal : j / (nb - 1);
4144
for(i = 0; i < na; i++) {
4245
aval = adata ? (adata[i] - adata[0]) * ascal : i / (na - 1);
43-
data[j][i] = aval - bval * cheaterslope;
46+
xval = aval - bval * cheaterslope;
47+
xmin = Math.min(xval, xmin);
48+
xmax = Math.max(xval, xmax);
49+
data[j][i] = xval;
50+
}
51+
}
52+
53+
// Normalize cheater values to the 0-1 range. This comes into play when you have
54+
// multiple cheater plots. After careful consideration, it seems better if cheater
55+
// values are normalized to a consistent range. Otherwise one cheater affects the
56+
// layout of other cheaters on the same axis.
57+
var slope = 1.0 / (xmax - xmin);
58+
var offset = -xmin * slope;
59+
for(j = 0; j < nb; j++) {
60+
for(i = 0; i < na; i++) {
61+
data[j][i] = slope * data[j][i] + offset;
4462
}
4563
}
4664

0 commit comments

Comments
 (0)