260331_02_ENH: 그룹 헤더 다단도 가능하게 수정
This commit is contained in:
@@ -4,7 +4,7 @@ import { cn, parseNumber } from "@/lib/utils";
|
||||
import { roundNumber } from "@/lib/lg-dashboard";
|
||||
import type { GaugeColumn } from "../types";
|
||||
import BaseTableRenderer from "./core/BaseTableRenderer";
|
||||
import { getColumnAlign, toTableCellContent } from "./core/table-core.helpers";
|
||||
import { getColumnAlign, getLeafColumns, toTableCellContent } from "./core/table-core.helpers";
|
||||
|
||||
type Props<T extends Record<string, unknown>> = {
|
||||
columns: GaugeColumn<T>[];
|
||||
@@ -33,6 +33,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
}: Props<T>) => {
|
||||
const formatValue = valueFormatter ?? ((value: number) => String(roundNumber(value)));
|
||||
const clampRatio = (value: number) => Math.max(0, Math.min(1, value));
|
||||
const leafColumns = getLeafColumns(columns);
|
||||
|
||||
return (
|
||||
<BaseTableRenderer
|
||||
@@ -42,7 +43,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
minWidth="100%"
|
||||
colgroup={
|
||||
<colgroup>
|
||||
{columns.map((column, index) => (
|
||||
{leafColumns.map((column, index) => (
|
||||
<col
|
||||
key={`${String(column.key)}-${index}`}
|
||||
style={{
|
||||
@@ -55,7 +56,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
>
|
||||
{rows.map((row, rowIndex) => (
|
||||
<tr key={rowIndex}>
|
||||
{columns.map((column) => {
|
||||
{leafColumns.map((column) => {
|
||||
const align = getColumnAlign(column);
|
||||
|
||||
if (column.rowHead) {
|
||||
@@ -74,13 +75,13 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
|
||||
const rawValue = row[column.key];
|
||||
const numericValue = parseNumber(rawValue);
|
||||
const max = column.max ?? 100;
|
||||
const max = "max" in column ? column.max ?? 100 : 100;
|
||||
const ratio = numericValue === null ? 0 : clampRatio((numericValue * scale) / max);
|
||||
const percentage = ratio * 100;
|
||||
const background =
|
||||
numericValue === null ? undefined : `linear-gradient(to right, ${fillColor} ${percentage}%, ${trackColor} 0%)`;
|
||||
|
||||
if ((column.cellType ?? "gauge") === "number") {
|
||||
if (("cellType" in column ? column.cellType : "gauge") === "number") {
|
||||
return (
|
||||
<td key={String(column.key)} className={cn("px-2 content-text-sm", column.cellClassName)} style={{ textAlign: align }}>
|
||||
{numericValue === null ? "-" : formatValue(numericValue)}
|
||||
|
||||
Reference in New Issue
Block a user