260128_03_ENH: 샘플데이터 랜덤 적용, lg 보급률 하단 카드 + 게이지 테이블 적용

This commit is contained in:
2026-01-28 17:01:40 +09:00
parent 4c00cfa946
commit d7cb9259cd
12 changed files with 395 additions and 134 deletions

View File

@@ -21,7 +21,6 @@ type Props<T extends Record<string, unknown>> = {
cellHeight?: number; // 기본 26
/** 숫자 표시 여부/포맷 */
showValue?: boolean; // 기본 true
valueFormatter?: (v: number) => string;
};
@@ -40,10 +39,9 @@ const GaugeTable = <T extends Record<string, unknown>>({
className,
wrapperClassName,
scale = 1,
fillColor = "hsl(var(--primary) / 0.85)",
trackColor = "hsl(var(--lg-gray-200) / 0.85)",
fillColor = "hsl(var(--lg-gray-200) / 0.85)",
trackColor = "hsl(var(--lg-pink-300) / 0.2)",
cellHeight = 26,
showValue = true,
valueFormatter,
}: Props<T>) => {
const hasGroup = columns.some((c) => !!c.group);
@@ -68,9 +66,23 @@ const GaugeTable = <T extends Record<string, unknown>>({
const fmt = valueFormatter ?? ((v: number) => String(Math.round(v)));
const clamp01 = (n: number) => Math.max(0, Math.min(1, n));
return (
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
<table className={cn("lg-table", className)}>
<table className={cn("lg-table", className)} style={{minWidth:"100%"}}>
<colgroup>
{columns.map((c, i) => (
<col
key={`${String(c.key)}-${i}`}
style={{
width:
c.width ??
(c.rowHead ? 50 : 40), // 기본 폭(필요시 숫자 조절)
}}
/>
))}
</colgroup>
<thead>
{hasGroup && (
<tr className="lg-table__group">
@@ -83,7 +95,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
)}
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
{columns.map((c) => (
<th key={String(c.key)} style={{ width: c.width }}>
<th key={String(c.key)}>
{c.header}
</th>
))}
@@ -95,6 +107,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
<tr key={rIdx}>
{columns.map((c) => {
const align = c.align ?? (c.rowHead ? "left" : "center");
const cellType = c.cellType ?? "gauge";
if (c.rowHead) {
const raw = row[c.key];
@@ -119,35 +132,42 @@ const GaugeTable = <T extends Record<string, unknown>>({
const raw = row[c.key];
const v = num(raw);
const max = c.max ?? 100;
const ratio = v === null ? 0 : Math.max(0, Math.min(1, (v * scale) / max));
const ratio = v === null ? 0 : clamp01((v * scale) / max);
const pct = ratio * 100;
return (
<td key={String(c.key)} style={{ textAlign: align }}>
<div
className="relative overflow-hidden rounded-md"
style={{
height: cellHeight,
background: trackColor,
border: "1px solid hsl(var(--border))",
}}
const fill = fillColor;
const track = trackColor;
const cellBg =
v === null
? undefined
: `linear-gradient(to right, ${fill} ${pct}%, ${track} 0%)`;
console.log(cellBg);
if (cellType === "number") {
return (
<td
key={String(c.key)}
className="px-2 content-text-sm"
style={{ textAlign: align }}
>
<div
className="absolute inset-y-0 left-0"
style={{
width: `${pct}%`,
background: fillColor,
}}
/>
{showValue && (
<div
className="relative z-10 flex h-full items-center justify-center content-text-sm"
style={{ color: "hsl(var(--lg-gray-900))" }}
>
{v === null ? "-" : fmt(v)}
</div>
)}
</div>
{v === null ? "-" : fmt(v)}
</td>
);
}
return (
<td
key={String(c.key)}
className="px-2 content-text-sm"
style={{
textAlign: "left",
height: cellHeight,
whiteSpace: "nowrap",
background: cellBg,
backgroundClip: "padding-box",
}}
>
{v === null ? "-" : fmt(v)}
</td>
);
})}