import React from "react"; /** * Bar chart — brand ramp by default (--chart-brand-1…5), one hue only. * palette="categorical" uses --chart-1 and --chart-3…10, excluding lime --chart-2 — 서로 다른 계열의 * 항목을 비교할 때만. * Accessible by default: the chart is role="img" with a generated summary, * and the same numbers are exposed as a visually-hidden table. * data: [{label, value, color?}] */ export function BarChart(props) { const data = props.data || []; const orientation = props.orientation || "vertical"; const height = props.height || 220; const unit = props.unit || ""; const title = props.title; const showValues = props.showValues !== false; const style = props.style; const palette = props.palette || "brand"; const categorical = [1, 3, 4, 5, 6, 7, 8, 9, 10]; const values = data.map(function (d) { return d.value; }); const top = props.max || Math.max.apply(null, values.concat([0])) || 1; const fmt = props.valueFormat || function (v) { return v + unit; }; const parts = data.map(function (d) { return d.label + " " + fmt(d.value); }).join(", "); const summary = title ? title + ". " + parts : parts; const color = function (d, i) { if (d.color) return d.color; if (palette === "categorical") return "hsl(var(--chart-" + categorical[i % categorical.length] + "))"; return "hsl(var(--chart-brand-" + ((i % 5) + 1) + "))"; }; const srTable = (
| {d.label} | {fmt(d.value)} |
|---|