260225_01_ENH: 실제 Data 통계 API와 연결 및 일부 페이지 축소
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
||||
import {BannerKey, ServerBannerRow} from "@/types/lg";
|
||||
import {BannerKey, BannerRow} from "@/types/lg";
|
||||
import {formatRowLabel, isGapRow, wrapSampleRow} from "@/lib/lg-dashboard";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
@@ -15,8 +15,9 @@ import {
|
||||
Section
|
||||
} from "@/lib/lg-export-excel";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
|
||||
|
||||
type SectionSpec = {
|
||||
@@ -36,11 +37,11 @@ const SEP_R = "lg-table__sep-r";
|
||||
const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] =>
|
||||
spec.groupKeys.flatMap((gk) => BANNER_GROUP[gk].keys);
|
||||
|
||||
const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<ServerBannerRow>[] => {
|
||||
const columns: DataColumn<ServerBannerRow>[] = [
|
||||
const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<BannerRow>[] => {
|
||||
const columns: DataColumn<BannerRow>[] = [
|
||||
{
|
||||
key: "rowLabel",
|
||||
header: `20${selectedYear}년`,
|
||||
header: `${selectedYear}년`,
|
||||
headRowSpan: 2,
|
||||
rowHead: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
@@ -77,15 +78,16 @@ const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<Server
|
||||
};
|
||||
|
||||
type BannerSummaryProps = {
|
||||
data: ServerBannerRow[];
|
||||
data: BannerRow[];
|
||||
useChart: boolean;
|
||||
useYear: boolean;
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
const {filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
|
||||
const buildChartData = (rows: BannerRow[]): ChartData => {
|
||||
const categories = rows
|
||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => formatRowLabel(r.rowLabel))
|
||||
@@ -104,7 +106,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
return { categories, series };
|
||||
};
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
const signStyleGap: SignStyle<BannerRow> = {
|
||||
rowSelector: (row) => isGapRow(row.rowLabel),
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
@@ -127,7 +129,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
row.rowLabel = formatRowLabel(row.rowLabel);
|
||||
return row
|
||||
})
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
const chartData = buildChartData(rows);
|
||||
|
||||
return {
|
||||
spec,
|
||||
@@ -141,9 +143,12 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
}, [data, useYear, filterValue.year]);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
const targetString =filterValue.target === CategoryTargetData.PROFILE? "Profile" : "보급률 변화"
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_${targetString}`
|
||||
registerExcelExporter(async () => {
|
||||
const product = debouncedFilterValue.product;
|
||||
const type = debouncedFilterValue.type.label;
|
||||
const target = debouncedFilterValue.target.value === CategoryTargetData.PROFILE? "Profile" : "보급률 변화"
|
||||
|
||||
const sheetName = `${product}_${type}_${target}`
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] =
|
||||
@@ -162,7 +167,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
}, [registerExcelExporter, debouncedFilterValue, sectionRows]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
@@ -171,7 +176,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
<div key={`div_${sectionRow.specTitle}`}>
|
||||
{
|
||||
useChart ?
|
||||
<LeftChartTable<ServerBannerRow>
|
||||
<LeftChartTable<BannerRow>
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
@@ -193,7 +198,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
starUnder30Sample={true}
|
||||
/>
|
||||
:
|
||||
<DataTable<ServerBannerRow>
|
||||
<DataTable<BannerRow>
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
|
||||
@@ -8,32 +8,31 @@ import {
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import React, {useMemo, useState} from "react";
|
||||
import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg";
|
||||
import {BannerGroupKey, CategoryChartMode, BannerRow} from "@/types/lg";
|
||||
import {
|
||||
buildRowLabelSeriesChartData,
|
||||
buildYearSeriesChartData, formatRowLabel,
|
||||
isBannerGroupKey, isGapRow,
|
||||
wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, GAP_WORDING, SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
||||
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP} from "@/const/lgConst";
|
||||
import {createDefaultGrid, reverseCategories} from "@/lib/chart-options";
|
||||
|
||||
type CategoryByDataProps = {
|
||||
selectedYear: string;
|
||||
title?: string;
|
||||
chartMode: CategoryChartMode;
|
||||
allTableData: ServerBannerRow[];
|
||||
allTableData: BannerRow[];
|
||||
fillGreaterThan5?: boolean;
|
||||
chartHeight?: number;
|
||||
chartHeight?: number | string;
|
||||
chartWidth?: number;
|
||||
unitText?: string;
|
||||
}
|
||||
|
||||
const banners: bannerType[] = totalFilters.map((filter) => {
|
||||
return {variable: filter.variable, variableName: filter.variableName}
|
||||
})
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
const signStyleGap: SignStyle<BannerRow> = {
|
||||
rowSelector: (row) => isGapRow(row.rowLabel),
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
@@ -49,15 +48,14 @@ const CategoryByData = ({
|
||||
fillGreaterThan5,
|
||||
chartHeight,
|
||||
chartWidth,
|
||||
unitText = UNIT_TEXT,
|
||||
}: CategoryByDataProps) => {
|
||||
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
|
||||
|
||||
const buildColumns = (groupKey: BannerGroupKey, selectedYear:string): DataColumn<ServerBannerRow>[] => {
|
||||
const columns: DataColumn<ServerBannerRow>[] = [
|
||||
const buildColumns = (groupKey: BannerGroupKey, selectedYear:string): DataColumn<BannerRow>[] => {
|
||||
const columns: DataColumn<BannerRow>[] = [
|
||||
{
|
||||
key: "rowLabel",
|
||||
header: `20${selectedYear}년`,
|
||||
header: `${selectedYear}년`,
|
||||
headRowSpan: 2,
|
||||
rowHead: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
@@ -111,22 +109,34 @@ const CategoryByData = ({
|
||||
</div>
|
||||
<div className="flex gap-6 p-3">
|
||||
<div className="flex-shrink-0" style={{ width: `${chartWidth ?? 400}px`}}>
|
||||
{
|
||||
chartMode === "stack" || chartMode === "reverseStack" ?
|
||||
<StackBar
|
||||
data={chartData}
|
||||
height={`${chartHeight ?? 340}px`}
|
||||
grid={createDefaultGrid("default", { top: 52 })}
|
||||
isReverse={chartMode === "reverseStack"}
|
||||
/>
|
||||
:
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
height={`${chartHeight ?? 340}px`}
|
||||
showFocusLabel="none"
|
||||
paletteVarNames={chartData.series.length === 1? ["--chart-1"]: ["--chart-2","--chart-1"]}
|
||||
/>
|
||||
}
|
||||
{(() => {
|
||||
switch (chartMode) {
|
||||
case "horizontal":
|
||||
return (
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
height={chartHeight}
|
||||
showFocusLabel="none"
|
||||
paletteVarNames={
|
||||
chartData.series.length === 1 ? ["--chart-1"] : ["--chart-2", "--chart-1"]
|
||||
}
|
||||
/>
|
||||
);
|
||||
case "stack":
|
||||
case "reverseStack":
|
||||
return (
|
||||
<StackBar
|
||||
data={chartData}
|
||||
height={chartHeight}
|
||||
grid={createDefaultGrid("default", { top: 52 })}
|
||||
isReverse={chartMode === "reverseStack"}
|
||||
/>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
})()}
|
||||
|
||||
</div>
|
||||
|
||||
<div className="flex items-center">
|
||||
|
||||
Reference in New Issue
Block a user