* Horizontal bars. `scale: 'ordinal'` is for categories whose order is their * meaning (run length, codebase size) and takes the one-hue ramp; nominal * categories all take slot 1, because colouring them by value would spend the * identity channel re-encoding what bar length already says.
(data, { scale = 'nominal' } = {})
| 167 | * identity channel re-encoding what bar length already says. |
| 168 | */ |
| 169 | function barChart(data, { scale = 'nominal' } = {}) { |
| 170 | const colours = |
| 171 | scale === 'ordinal' |
| 172 | ? paletteFor(data.labels, 'ordinal') |
| 173 | : data.labels.map((label) => (label === 'Other' ? NEUTRAL : CATEGORICAL[0])); |
| 174 | |
| 175 | return { |
| 176 | type: 'bar', |
| 177 | data: { |
| 178 | labels: data.labels, |
| 179 | datasets: [ |
| 180 | { |
| 181 | label: data.datasets[0].label, |
| 182 | data: data.datasets[0].data, |
| 183 | backgroundColor: colours, |
| 184 | maxBarThickness: 24, |
| 185 | // Rounded at the data end, square at the baseline (Chart.js skips the |
| 186 | // 'start' edge by default, which is the baseline on a horizontal bar). |
| 187 | borderRadius: 4, |
| 188 | }, |
| 189 | ], |
| 190 | }, |
| 191 | options: { |
| 192 | indexAxis: 'y', |
| 193 | plugins: { legend: { display: false } }, |
| 194 | scales: { |
| 195 | x: valueScale(), |
| 196 | y: categoryScale({ ticks: { color: undefined, padding: 6, autoSkip: false } }), |
| 197 | }, |
| 198 | }, |
| 199 | }; |
| 200 | } |
| 201 | |
| 202 | /** Part-to-whole at a glance. Capped at a handful of slices by the API's `limit`. */ |
| 203 | function pieChart(data, { scale = 'categorical' } = {}) { |
no test coverage detected