MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / pieChart

Function pieChart

telemetry-dashboard/public/panels.js:203–229  ·  view source on GitHub ↗

Part-to-whole at a glance. Capped at a handful of slices by the API's `limit`.

(data, { scale = 'categorical' } = {})

Source from the content-addressed store, hash-verified

201
202/** Part-to-whole at a glance. Capped at a handful of slices by the API's `limit`. */
203function pieChart(data, { scale = 'categorical' } = {}) {
204 const total = data.datasets[0].data.reduce((n, v) => n + v, 0);
205 return {
206 type: 'pie',
207 data: {
208 labels: data.labels,
209 datasets: [
210 {
211 label: data.datasets[0].label,
212 data: data.datasets[0].data,
213 backgroundColor: paletteFor(data.labels, scale === 'ordinal' ? 'ordinal' : 'categorical'),
214 },
215 ],
216 },
217 options: {
218 plugins: {
219 legend: { display: true },
220 tooltip: {
221 callbacks: {
222 label: (ctx) =>
223 `${ctx.label}: ${number(ctx.parsed)} (${total > 0 ? percent(ctx.parsed / total, 1) : '—'})`,
224 },
225 },
226 },
227 },
228 };
229}
230
231// ---------------------------------------------------------------------------
232// Table twins

Callers 1

panels.jsFile · 0.85

Calls 3

paletteForFunction · 0.90
numberFunction · 0.90
percentFunction · 0.90

Tested by

no test coverage detected