260202_01_ENH: route 구조 초창기 기획으로 다시 변경 및 Category 별 하위 페이지에 샘플 데이터 모두 적용

This commit is contained in:
2026-02-02 11:32:50 +09:00
parent 4b40c43962
commit 6f8e09bcf3
60 changed files with 1750 additions and 464 deletions

View File

@@ -14,6 +14,7 @@ import { buildLgPalette } from "../color";
import { GroupedOverlayBarData, ShowLabel} from "../types";
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
import { CHART_HEIGHTS, LEGEND_ITEM_SIZE } from "@/const/chartConst";
type Props = {
data: GroupedOverlayBarData;
@@ -34,7 +35,7 @@ type Props = {
const GroupedOverlayBar = ({
data,
height = 260,
height = CHART_HEIGHTS.DEFAULT,
tooltip,
grid,
xAxis,
@@ -170,9 +171,9 @@ const GroupedOverlayBar = ({
});
}
const YEAR_ITEM_W = 25;
const YEAR_ITEM_H = 14;
const YEAR_RADIUS = 4;
const YEAR_ITEM_W = LEGEND_ITEM_SIZE.WIDTH;
const YEAR_ITEM_H = LEGEND_ITEM_SIZE.HEIGHT;
const YEAR_RADIUS = LEGEND_ITEM_SIZE.RADIUS;
let yearLegendOpt: LegendComponentOption | undefined = showYearLegend
? ({

View File

@@ -14,6 +14,7 @@ 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";
import { CHART_HEIGHTS, LEGEND_ITEM_SIZE } from "@/const/chartConst";
type Props = {
data: GroupedStackBarData;
@@ -33,7 +34,7 @@ type Props = {
const GroupedStackBar = ({
data,
height = 260,
height = CHART_HEIGHTS.DEFAULT,
tooltip,
grid,
xAxis,
@@ -133,10 +134,6 @@ const GroupedStackBar = ({
}
}
const YEAR_ITEM_W = 25;
const YEAR_ITEM_H = 14;
const YEAR_RADIUS = 4;
// 3) legend 2개: (좌)연도, (우)브랜드
let yearLegendOpt: LegendComponentOption | undefined = showYearLegend
? ({
@@ -145,9 +142,9 @@ const GroupedStackBar = ({
orient: "horizontal",
data: yearLabels, // yearLegendSeries name과 일치
selected: yearSelected,
icon: roundedRectIcon(YEAR_ITEM_W, YEAR_ITEM_H, YEAR_RADIUS),
itemWidth: YEAR_ITEM_W,
itemHeight: YEAR_ITEM_H,
icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS),
itemWidth: LEGEND_ITEM_SIZE.WIDTH,
itemHeight: LEGEND_ITEM_SIZE.HEIGHT,
itemGap: 8,
...legend,
} as LegendComponentOption)
@@ -161,12 +158,12 @@ const GroupedStackBar = ({
top: 25,
right: "center",
orient: "horizontal",
data: brands,
icon: roundedRectIcon(YEAR_ITEM_W, YEAR_ITEM_H, YEAR_RADIUS),
itemWidth: YEAR_ITEM_W,
itemHeight: YEAR_ITEM_H,
icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS),
itemWidth: LEGEND_ITEM_SIZE.WIDTH,
itemHeight: LEGEND_ITEM_SIZE.HEIGHT,
itemGap: 8,
...legend,
data: [...brands].reverse(),
} as LegendComponentOption);
const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt;

View File

@@ -6,6 +6,14 @@ import BaseEChart from "../BaseEChart";
import {ChartData, ShowLabel, ValueFormatter} from "../types";
import { buildLgPalette } from "../color";
import {getIsShowLabel} from "@/components/lge-dashboard/chart/utill";
import {
createDefaultTooltip,
createDefaultLegend,
createDefaultGrid,
createCategoryAxis,
createValueAxis,
} from "@/lib/chart-options";
import { BAR_WIDTHS } from "@/const/chartConst";
type Props = {
data: ChartData;
@@ -41,24 +49,13 @@ const HorizontalBar = ({
const option: EChartsOption = useMemo(() => {
const fmt = valueFormatter ?? ((v: number) => String(v));
const defaultTooltip: EChartsOption["tooltip"] = {
trigger: "axis",
axisPointer: { type: "shadow" },
valueFormatter: (v: unknown) => (typeof v === "number" ? fmt(v) : String(v)),
};
const defaultLegend: EChartsOption["legend"] = { top: 0 };
const defaultGrid: EChartsOption["grid"] = { left: 16, right: 16, top: 36, bottom: 12, containLabel: true };
const defaultXAxis: EChartsOption["xAxis"] = { type: "value" };
const defaultYAxis: EChartsOption["yAxis"] = { type: "category", data: data.categories };
return {
color: palette,
tooltip: tooltip ?? defaultTooltip,
legend: legend ?? defaultLegend,
grid: grid ?? defaultGrid,
xAxis: xAxis ?? defaultXAxis,
yAxis: yAxis ?? defaultYAxis,
tooltip: tooltip ?? createDefaultTooltip(fmt),
legend: legend ?? createDefaultLegend(),
grid: grid ?? createDefaultGrid(),
xAxis: xAxis ?? createValueAxis(),
yAxis: yAxis ?? createCategoryAxis(data.categories),
series: data.series.map((s, index) => {
const showLabel = getIsShowLabel(showFocusLabel, index, data.series.length);
@@ -67,7 +64,7 @@ const HorizontalBar = ({
type: "bar",
data: s.data,
emphasis: { disabled: true },
barMaxWidth: barMaxWidth ?? 42,
barMaxWidth: barMaxWidth ?? BAR_WIDTHS.DEFAULT,
label: showLabel
? {
show: true,

View File

@@ -5,6 +5,16 @@ import type { EChartsOption } from "echarts";
import BaseEChart from "../BaseEChart";
import type { ChartData, ValueFormatter } from "../types";
import { buildLgPalette } from "../color";
import {
createDefaultTooltip,
createDefaultLegend,
createDefaultGrid,
createCategoryAxis,
createValueAxis,
createBarSeries,
createReverseTooltip,
createReverseLegend, reverseSeries,
} from "@/lib/chart-options";
type Props = {
data: ChartData;
@@ -13,7 +23,6 @@ type Props = {
paletteVarNames?: string[];
valueFormatter?: ValueFormatter;
orientation?: "vertical" | "horizontal";
/** series.stack이 없을 때 기본 stack key */
defaultStackKey?: string;
tooltip?: EChartsOption["tooltip"];
legend?: EChartsOption["legend"];
@@ -21,58 +30,76 @@ type Props = {
xAxis?: EChartsOption["xAxis"];
yAxis?: EChartsOption["yAxis"];
barMaxWidth?: number;
isReverse?: boolean;
};
const StackBar = ({
data,
height,
className,
paletteVarNames,
valueFormatter,
orientation = "vertical",
defaultStackKey = "total",
tooltip,
legend,
grid,
xAxis,
yAxis,
barMaxWidth,
}: Props) => {
const palette = useMemo(() => buildLgPalette(paletteVarNames), [paletteVarNames]);
data,
height,
className,
paletteVarNames,
valueFormatter,
orientation = "vertical",
defaultStackKey = "total",
tooltip,
legend,
grid,
xAxis,
yAxis,
barMaxWidth,
isReverse = false,
}: Props) => {
// ✅ 렌더링용 데이터만 뒤집기
const renderData = useMemo(
() => (isReverse ? reverseSeries(data) : data),
[data, isReverse]
);
// ✅ 팔레트도 뒤집어줘야 "시리즈 이름별" 색이 유지됨
const palette = useMemo(() => {
const temp = buildLgPalette(paletteVarNames);
const n = data.series.length; // 원본 기준
const base = temp.slice(0, n);
return isReverse ? [...base].reverse() : base;
}, [paletteVarNames, data.series.length, isReverse]);
const option: EChartsOption = useMemo(() => {
const fmt = valueFormatter ?? ((v: number) => String(v));
const isV = orientation === "vertical";
const defaultTooltip: EChartsOption["tooltip"] = {
trigger: "axis",
axisPointer: { type: "shadow" },
valueFormatter: (v: unknown) => (typeof v === "number" ? fmt(v) : String(v)),
};
const defaultLegend: EChartsOption["legend"] = { top: 0 };
const defaultGrid: EChartsOption["grid"] = { left: 16, right: 16, top: 36, bottom: 12, containLabel: true };
const defaultXAxis: EChartsOption["xAxis"] = isV ? { type: "category", data: data.categories } : { type: "value" };
const defaultYAxis: EChartsOption["yAxis"] = isV ? { type: "value" } : { type: "category", data: data.categories };
return {
color: palette,
tooltip: tooltip ?? defaultTooltip,
legend: legend ?? defaultLegend,
grid: grid ?? defaultGrid,
xAxis: xAxis ?? defaultXAxis,
yAxis: yAxis ?? defaultYAxis,
series: data.series.map((s) => ({
name: s.name,
type: "bar",
stack: s.stack ?? defaultStackKey,
data: s.data,
emphasis: { disabled: true },
barMaxWidth: barMaxWidth ?? 42,
})),
tooltip: tooltip ?? (isReverse ? createReverseTooltip(data, fmt) : createDefaultTooltip(fmt)),
legend: legend ?? (isReverse ? createReverseLegend(data) : createDefaultLegend()),
grid: grid ?? createDefaultGrid(),
xAxis: xAxis ?? (isV ? createCategoryAxis(renderData.categories) : createValueAxis()),
yAxis: yAxis ?? (isV ? createValueAxis() : createCategoryAxis(renderData.categories)),
series: renderData.series.map((s) =>
createBarSeries(s.name, s.data, {
stack: s.stack ?? defaultStackKey,
barMaxWidth,
})
),
};
}, [data, palette, valueFormatter, orientation, defaultStackKey, tooltip, legend, grid, xAxis, yAxis, barMaxWidth]);
}, [
data,
renderData,
palette,
valueFormatter,
orientation,
defaultStackKey,
tooltip,
legend,
grid,
xAxis,
yAxis,
barMaxWidth,
isReverse,
]);
return <BaseEChart option={option} height={height} className={className} />;
}
};
export default StackBar;

View File

@@ -6,6 +6,14 @@ import BaseEChart from "../BaseEChart";
import {ChartData, ShowLabel, ValueFormatter} from "../types";
import { buildLgPalette } from "../color";
import {getIsShowLabel} from "@/components/lge-dashboard/chart/utill";
import {
createDefaultTooltip,
createDefaultLegend,
createDefaultGrid,
createCategoryAxis,
createValueAxis,
} from "@/lib/chart-options";
import { BAR_WIDTHS } from "@/const/chartConst";
type Props = {
data: ChartData;
@@ -42,24 +50,13 @@ const VerticalBar = ({
const option: EChartsOption = useMemo(() => {
const fmt = valueFormatter ?? ((v: number) => String(v));
const defaultTooltip: EChartsOption["tooltip"] = {
trigger: "axis",
axisPointer: { type: "shadow" },
valueFormatter: (v: unknown) => (typeof v === "number" ? fmt(v) : String(v)),
};
const defaultLegend: EChartsOption["legend"] = { top: 0 };
const defaultGrid: EChartsOption["grid"] = { left: 16, right: 16, top: 36, bottom: 12, containLabel: true };
const defaultXAxis: EChartsOption["xAxis"] = { type: "category", data: data.categories, axisTick: { alignWithLabel: true } };
const defaultYAxis: EChartsOption["yAxis"] = { type: "value" };
return {
color: palette,
tooltip: tooltip ?? defaultTooltip,
legend: legend ?? defaultLegend,
grid: grid ?? defaultGrid,
xAxis: xAxis ?? defaultXAxis,
yAxis: yAxis ?? defaultYAxis,
tooltip: tooltip ?? createDefaultTooltip(fmt),
legend: legend ?? createDefaultLegend(),
grid: grid ?? createDefaultGrid(),
xAxis: xAxis ?? createCategoryAxis(data.categories, false, { axisTick: { alignWithLabel: true } }),
yAxis: yAxis ?? createValueAxis(),
series: data.series.map((s, index) => {
const showLabel = getIsShowLabel(showFocusLabel, index, data.series.length);
@@ -68,7 +65,7 @@ const VerticalBar = ({
type: "bar",
data: s.data,
emphasis: { disabled: true },
barMaxWidth: barMaxWidth ?? 42,
barMaxWidth: barMaxWidth ?? BAR_WIDTHS.DEFAULT,
label: showLabel
? {
show: true,