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

@@ -11,8 +11,9 @@ import type {
} from "echarts";
import BaseEChart from "../BaseEChart";
import { buildLgPalette } from "../color";
import {AXIS_HIDE_STYLE, GroupedOverlayBarData, ShowLabel} from "../types";
import { GroupedOverlayBarData, ShowLabel} from "../types";
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
type Props = {
data: GroupedOverlayBarData;

View File

@@ -10,9 +10,10 @@ import type {
SeriesOption, EChartsOption,
} from "echarts";
import BaseEChart from "../BaseEChart";
import {AXIS_HIDE_STYLE, GroupedStackBarData, ShowLabel} from "../types";
import { GroupedStackBarData, ShowLabel} from "../types";
import { buildLgPalette } from "@/components/lge-dashboard/color";
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
type Props = {
data: GroupedStackBarData;

View File

@@ -0,0 +1,58 @@
"use client";
import React from "react";
import { cn } from "@/lib/utils";
import {GaugeColumn, GaugeTable} from "@/components/lge-dashboard";
import Card from "@/components/lge-dashboard/card/Card";
export type GaugeCardTableProps<T> = {
/** 카드 제목 */
title: string;
/** GaugeTable columns */
columns: GaugeColumn<T>[];
/** GaugeTable rows */
rows: T[];
/** GaugeTable 옵션들 (필요한 것만 노출) */
cellHeight?: number;
fillColor?: string;
trackColor?: string;
className?: string;
cardClassName?: string;
tableClassName?: string;
};
const GaugeCardTable = <T extends Record<string, unknown>>(
props: GaugeCardTableProps<T>
) => {
const {
title,
columns,
rows,
cellHeight = 26,
fillColor,
trackColor,
className,
cardClassName,
tableClassName,
} = props;
return (
<div className={cn("w-full", className)}>
<Card label={title} className={cardClassName}>
<div className={cn("w-full", tableClassName)}>
<GaugeTable
columns={columns}
rows={rows}
cellHeight={cellHeight}
fillColor={fillColor}
trackColor={trackColor}
/>
</div>
</Card>
</div>
);
};
export default GaugeCardTable;

View File

@@ -13,5 +13,7 @@ export { default as GaugeTable } from "./table/GaugeTable";
export { default as TopChartTable } from "./combo/TopChartTable";
export { default as LeftChartTable } from "./combo/LeftChartTable";
export { default as GaugeCardTable } from "./combo/GaugeCardTable";
export { default as CategoryByData } from "./combo/CategoryByData"
export { default as CardDefault } from "./card/Card";

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>
);
})}

View File

@@ -112,6 +112,17 @@ export type ServerBannerRow = ServerBaseRow &
[k: string]: number | string;
};
export type LifeStageRow = Record<string, unknown> & {
item: string;
total: number | null;
single: number | null;
noKids: number | null;
preschoolKids: number | null;
schoolKids: number | null;
adultKids: number | null;
independentSenior: number | null;
};
export type ChartSeries = {
/** legend에 노출될 이름 */
name: string;
@@ -190,6 +201,7 @@ export type GaugeColumn<T> = {
/** 게이지 최대값 기준(기본 100) */
max?: number;
renderLabel?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
cellType?: "gauge" | "number"; // default: "gauge"
};
export type SignDisplayMode = "number" | "arrow";
@@ -233,13 +245,6 @@ export const signStyleGapRow: SignStyle<TopChartTableRow> = {
arrowWithNumber: true,
paint: "text",
};
/** X 축 패딩 없앤 GridOption*/
export const GRID_X_NOT_PADDING = { left: 0, right: 0, top: 50, bottom: 10, containLabel: false } as const;
/** T 축 패딩 없앤 GridOption*/
export const GRID_Y_NOT_PADDING = { left: 10, right: 10, top: 0, bottom: 0, containLabel: false } as const;
/** 축 스타일 감춤 */
export const AXIS_HIDE_STYLE = { axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false }} as const;
/** ChartLabel 보여지는 옵션 */
export type ShowLabel = "none" | "all" | "last" | "first";