* Create a criterion group chart that is filtered by a secondary "query file" dimension. * Keys must follow the pattern " / _ ". * A is injected above the chart to switch between query files.
(entries, {
groupPrefix,
chartId,
selectId,
title,
yAxisTitle,
conversionFactor,
decimalPlaces,
thresholds = null,
})
| 903 | * A <select> is injected above the chart to switch between query files. |
| 904 | */ |
| 905 | function createCriterionQueryFilteredChart(entries, { |
| 906 | groupPrefix, |
| 907 | chartId, |
| 908 | selectId, |
| 909 | title, |
| 910 | yAxisTitle, |
| 911 | conversionFactor, |
| 912 | decimalPlaces, |
| 913 | thresholds = null, |
| 914 | }) { |
| 915 | const chartElement = document.getElementById(chartId); |
| 916 | if (!chartElement) return; |
| 917 | |
| 918 | const allBenchmarks = Object.keys(entries[0].criterion_results).filter((b) => |
| 919 | b.startsWith(groupPrefix + "/"), |
| 920 | ); |
| 921 | if (allBenchmarks.length === 0) return; |
| 922 | |
| 923 | const names = allBenchmarks.map((b) => b.replace(groupPrefix + "/", "")); |
| 924 | const queryFiles = [...new Set(names.map((n) => n.replace(/^[^_]+_/, "")))].sort(); |
| 925 | |
| 926 | let select = document.getElementById(selectId); |
| 927 | if (!select) { |
| 928 | const wrapper = document.createElement("div"); |
| 929 | wrapper.style.cssText = "margin-bottom: 0.5rem;"; |
| 930 | select = document.createElement("select"); |
| 931 | select.id = selectId; |
| 932 | queryFiles.forEach((q) => { |
| 933 | const opt = document.createElement("option"); |
| 934 | opt.value = q; |
| 935 | opt.textContent = q.replace(/-/g, " ").replace(/_/g, " "); |
| 936 | select.appendChild(opt); |
| 937 | }); |
| 938 | wrapper.appendChild(select); |
| 939 | chartElement.parentNode.insertBefore(wrapper, chartElement); |
| 940 | } |
| 941 | |
| 942 | const outlierId = chartId.replace("-chart", "-outliers-chart"); |
| 943 | |
| 944 | function renderForQuery(queryFile) { |
| 945 | [chartId, outlierId].forEach((id) => { |
| 946 | const idx = charts.findIndex((c) => c && c.el && c.el.id === id); |
| 947 | if (idx !== -1) { |
| 948 | charts[idx].destroy(); |
| 949 | charts.splice(idx, 1); |
| 950 | } |
| 951 | if (id === outlierId) { |
| 952 | const el = document.getElementById(id); |
| 953 | if (el) el.remove(); |
| 954 | } |
| 955 | }); |
| 956 | |
| 957 | const filtered = allBenchmarks.filter((b) => b.endsWith("_" + queryFile)); |
| 958 | const filteredEntries = entries.map((e) => ({ |
| 959 | ...e, |
| 960 | criterion_results: Object.fromEntries( |
| 961 | Object.entries(e.criterion_results).filter(([k]) => filtered.includes(k)), |
| 962 | ), |
no test coverage detected