(function () {
"use strict";
function isDark() {
var c = document.documentElement.classList;
return c.contains("coal") || c.contains("navy") || c.contains("ayu");
}
function orderedUnique(rows, key) {
var seen = Object.create(null);
var out = [];
rows.forEach(function (r) {
if (!(r[key] in seen)) {
seen[r[key]] = true;
out.push(r[key]);
}
});
return out;
}
function powersOfTenTicks(points) {
var ratios = points
.map(function (p) {
return p.ratio;
})
.filter(function (r) {
return r > 0;
});
if (!ratios.length) {
return [1];
}
var lo = Math.floor(Math.log10(Math.min.apply(null, ratios)));
var hi = Math.ceil(Math.log10(Math.max.apply(null, ratios)));
var ticks = [];
for (var e = lo; e <= hi; e++) {
ticks.push(Math.pow(10, e));
}
return ticks;
}
function spec(points) {
var dark = isDark();
var fg = dark ? "#c8c9db" : "#333333";
var grid = dark ? "#3b3f5c" : "#dddddd";
var formatters = orderedUnique(points, "formatter");
var documents = orderedUnique(points, "document");
return {
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
description:
"Dot plot of formatting speed relative to badness. Each dot is one " +
"document formatted by one tool; the vertical axis is mean time as a " +
"ratio to badness on a log scale, with badness on a dashed baseline " +
"at 1, faster tools below and slower tools above. See the data table " +
"for the underlying numbers.",
width: "container",
height: 340,
data: { values: points },
layer: [
{
mark: { type: "rule", strokeDash: [4, 4], color: grid },
encoding: { y: { datum: 1, type: "quantitative" } },
},
{
mark: { type: "point", filled: true, size: 130, opacity: 0.9 },
encoding: {
x: {
field: "formatter",
type: "nominal",
title: "Tool",
sort: formatters,
axis: { labelAngle: 0 },
},
y: {
field: "ratio",
type: "quantitative",
title: "Time relative to badness",
scale: { type: "log" },
axis: {
values: powersOfTenTicks(points),
format: "~f",
},
},
color: {
field: "document",
type: "nominal",
title: "Document",
sort: documents,
},
tooltip: [
{ field: "document", title: "Document" },
{ field: "formatter", title: "Tool" },
{ field: "mean_ms", title: "Mean (ms)", format: ".3f" },
{ field: "ratio_label", title: "Relative" },
{ field: "min_ms", title: "Min (ms)", format: ".3f" },
{ field: "max_ms", title: "Max (ms)", format: ".3f" },
{ field: "stddev_ms", title: "Std dev (ms)", format: ".3f" },
],
},
},
],
config: {
background: null,
view: { stroke: null },
axis: {
labelColor: fg,
titleColor: fg,
gridColor: grid,
domainColor: grid,
tickColor: grid,
},
legend: { labelColor: fg, titleColor: fg },
},
};
}
function renderInto(container, points) {
if (!window.vegaEmbed) {
return;
}
var vlSpec = spec(points);
container.setAttribute("role", "img");
container.setAttribute("aria-label", vlSpec.description);
window
.vegaEmbed(container, vlSpec, { actions: false, renderer: "svg" })
.catch(function (err) {
console.error("bench-charts: failed to render", err);
});
}
function init() {
var blocks = document.querySelectorAll(".bench-chart-block");
if (!blocks.length) {
return;
}
blocks.forEach(function (block) {
var container = block.querySelector(".bench-chart");
var data = block.querySelector("script.bench-data");
if (!container || !data) {
return;
}
var points;
try {
points = JSON.parse(data.textContent);
} catch (err) {
console.error("bench-charts: bad data payload", err);
return;
}
if (!Array.isArray(points) || !points.length) {
return;
}
container.__benchPoints = points;
renderInto(container, points);
});
var observer = new MutationObserver(function () {
document.querySelectorAll(".bench-chart").forEach(function (container) {
if (container.__benchPoints) {
renderInto(container, container.__benchPoints);
}
});
});
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ["class"],
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();