Skip to content

Commit

Permalink
add outlier rendering to box-whisker demo. close #852.
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed Jul 3, 2023
1 parent 78b006d commit f2804d0
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion demos/box-whisker.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
let q3 = u.data[3][i];
let min = u.data[4][i];
let max = u.data[5][i];
let outs = u.data[6][i];

let timeAsX = u.valToPos(i, "x", true);
let lowAsY = u.valToPos(min, "y", true);
Expand Down Expand Up @@ -228,6 +229,11 @@
);
u.ctx.stroke();


for (let j = 0; j < outs.length; j++) {
let cy = u.valToPos(outs[j], "y", true);
u.ctx.fillRect(timeAsX - 4, cy - 4, 8, 8);
}
}

u.ctx.translate(-offset, -offset);
Expand All @@ -242,6 +248,17 @@
points: {
show: false,
}
},
scales: {
y: {
range: (u, dataMin, dataMax) => {
// TODO: only scan values in x idx0...idx1 range
let outsMin = Math.min(...u.data[6].map(outs => outs.at(0) ?? Infinity));
let outsMax = Math.max(...u.data[6].map(outs => outs.at(-1) ?? -Infinity));

return uPlot.rangeNum(Math.min(dataMin, outsMin), Math.max(dataMax, outsMax), 0.1, true);
}
}
}
});

Expand All @@ -267,14 +284,26 @@
// filter outliers
run.values.sort((a, b) => a - b);
let pad = iq * 1.5;
let vals = run.values.filter(v => v >= s.q1 - pad && v <= s.q3 + pad);

let vals = [];
let outs = [];

run.values.forEach(v => {
if (v >= s.q1 - pad && v <= s.q3 + pad)
vals.push(v);
else
outs.push(v);
});

outs.sort((a, b) => a - b);

bench[run.framework] = [
s.median,
s.q1,
s.q3,
vals[0],
vals[vals.length - 1],
outs,
];
});

Expand Down Expand Up @@ -303,6 +332,8 @@
libNames.map(libName => bench[libName][3]).slice(0,30),
// max
libNames.map(libName => bench[libName][4]).slice(0,30),
// outliers
libNames.map(libName => bench[libName][5]).slice(0,30),
]
};
}
Expand Down

0 comments on commit f2804d0

Please sign in to comment.