plot_histo = (samples, chart_options = histo_options, quantile = null) =>
Plot.plot({
className: "chart",
marks: [
Plot.frame(),
Plot.rect(samples, {
y1: "latency_min",
y2: "latency_max",
x1: "quantile_min",
x2: "quantile_max",
stroke: "latency_max",
fill: "latency_max",
fillOpacity: fillOpacity
}),
chart_options.tip
? Plot.text(
samples,
Plot.pointerX({
py: (d) => (d.latency_min + d.latency_max) / 2,
px: (d) => (d.quantile_min + d.quantile_max) / 2,
dy: -3 * text_fontsize - 2,
frameAnchor: "top-right",
fontVariant: "tabular-nums",
fontSize: text_fontsize,
text: (d) =>
[
`Latency Range (seconds): (${d.latency_min.toFixed(
3
)} - ${d.latency_max.toFixed(3)}]`,
`Quantile Range: (${d.quantile_min.toFixed(
4
)} - ${d.quantile_max.toFixed(4)}]`,
`Sample Counts: ${d.count}`
].join("\n")
})
)
: null,
chart_options.tip
? Plot.crosshairX(samples, {
y: (d) => (d.latency_min + d.latency_max) / 2,
x: (d) => (d.quantile_min + d.quantile_max) / 2,
ruleStrokeWidth: 1,
ruleStrokeOpacity: 0.8,
color: "teal"
})
: null,
chart_options.tip
? Plot.rect(
samples,
Plot.pointerX({
y1: "latency_min",
y2: "latency_max",
x1: "quantile_min",
x2: "quantile_max",
stroke: "blue",
strokeWidth: 0.5
})
)
: null,
use_warningline && chart_options.warningline != null
? Plot.ruleY([chart_options.warningline], {
stroke: "rgb(221, 64, 48)",
text: String(chart_options.warningline),
title: () => "Warning line"
})
: null,
use_warningline && chart_options.warningline != null
? Plot.tip([chart_options.warningline], {
x: 0,
y: (d) => d,
anchor: "right",
stroke: "rgb(221, 64, 48)",
title: (d) => String(d),
textPadding: 3
})
: null,
quantile == null
? null
: Plot.ruleX([quantile.value], {
stroke: "#0172ad",
text: quantile.title
//title: () => quantile.title
}),
quantile == null
? null
: Plot.tip([quantile], {
title: (d) => d.title,
x: (d) => d.value,
y: 0,
stroke: "#0172ad",
anchor: "top",
textPadding: 3
}),
Plot.gridX({ interval: 0.1, label: null, strokeOpacity: gridOpacity }),
Plot.gridY({ label: null, strokeOpacity: gridOpacity })
],
...chart_options,
marginTop: chart_options.tip ? 3 * text_fontsize + 4 : text_fontsize + 4,
color: {
range: chart_options.color_palette,
//range: pattern_range,
type: "threshold",
domain: chart_options.color_domain
}
})