Compare commits
52 Commits
11321c483b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 864dbffa6f | |||
| 0006e91779 | |||
| f6441c6a6c | |||
| 1da20a1fb6 | |||
| d1dc3fe6fa | |||
| 50e1ea19cc | |||
| fc43eab6fc | |||
| 7474d4d3d4 | |||
| 01208b5b24 | |||
| d6f4bca06f | |||
| 563f98c6f2 | |||
| 20b8547701 | |||
| b740cc27fa | |||
| 9b3a21ea39 | |||
| f4f487ca10 | |||
| 3c7865ef60 | |||
| 849245818c | |||
| 26848901cf | |||
| 3a42ac867c | |||
| ebc72e57c2 | |||
| f6b5b21cb2 | |||
| 59943b2e45 | |||
| c67971f803 | |||
| 882a5f046a | |||
| 8540df7274 | |||
| dc9b2baeb1 | |||
| d58c0b4dd4 | |||
| 5b2811fd86 | |||
| e51c6ba810 | |||
| 3dc735722d | |||
| a0ee062899 | |||
| 8fff3ec908 | |||
| 7f9465e96f | |||
| ee8bb13209 | |||
| 8133ab1ee4 | |||
| 2052c84371 | |||
| 8a6216ef02 | |||
| ffeee5bef2 | |||
| 836f756a42 | |||
| b2cf1b846f | |||
| c66b51ca53 | |||
| 72e18adb03 | |||
| b39c3e8ef9 | |||
| 1751a5071a | |||
| 41a8e2abb2 | |||
| 75153ff02e | |||
| 497301e102 | |||
| eee25ea68f | |||
| 1159993c62 | |||
| 1c2dcb6fd5 | |||
| 4bdb705720 | |||
| 9df181e6dc |
18
.agent/profile.yml
Normal file
18
.agent/profile.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
schema_version: 1
|
||||||
|
|
||||||
|
project:
|
||||||
|
id: lge-cx-dash-front
|
||||||
|
name: LGE CX Dashboard Frontend
|
||||||
|
type: requested-project
|
||||||
|
layer: frontend
|
||||||
|
legacy: false
|
||||||
|
|
||||||
|
stack:
|
||||||
|
- typescript
|
||||||
|
- react
|
||||||
|
- nextjs
|
||||||
|
|
||||||
|
shared_contracts:
|
||||||
|
consumes:
|
||||||
|
- kri-front-common
|
||||||
|
- kri-ui-registry
|
||||||
20
.agent/project.md
Normal file
20
.agent/project.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
## LGE CX Dashboard Frontend Repository Rules
|
||||||
|
|
||||||
|
### Deliverable and User Experience
|
||||||
|
|
||||||
|
- This Next.js frontend visualizes LGE appliance penetration, purchase, category, profile, and trend survey statistics.
|
||||||
|
- Treat approved planning and design material as the scope boundary. Preserve category navigation, filters, labels, chart/table values, comparison context, and Excel export behavior.
|
||||||
|
- A visual change must not silently alter the represented statistic, denominator, ordering, rounding, tooltip meaning, or empty-data behavior.
|
||||||
|
- Keep customer survey data, exported workbooks, and internal planning material out of logs, fixtures, screenshots, and external services.
|
||||||
|
|
||||||
|
### Frontend Implementation
|
||||||
|
|
||||||
|
- Use the consumed KRI frontend common and UI registry contracts. Prefer an existing shadcn/ui or registry component before creating a new foundational component.
|
||||||
|
- Do not create new TypeScript type or interface names ending in `Dto` or `DTO`.
|
||||||
|
- Preserve accessibility, responsive layout, loading, empty, error, unauthorized, and export states across every dashboard route.
|
||||||
|
- Coordinate API request, response, authentication, and error changes with the backend without requiring an unsafe simultaneous deployment.
|
||||||
|
|
||||||
|
### Harness and Verification
|
||||||
|
|
||||||
|
- `AGENTS.md` and `CLAUDE.md` are generated. Edit `.agent/profile.yml` or `.agent/project.md`, then recompose instead of editing generated files.
|
||||||
|
- Use the existing npm scripts and focused lint, type-check, test, or production build checks. Do not call production APIs or export real customer data during validation.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
NEXT_PUBLIC_ENV=prod
|
NEXT_PUBLIC_ENV=prod
|
||||||
NEXT_PUBLIC_API_BASE=https://test-lg-cxdash.kric.com/api
|
NEXT_PUBLIC_API_BASE=https://lg-cxdash.kric.com/api
|
||||||
|
|
||||||
ENV=prod
|
ENV=prod
|
||||||
API_BACK_SERVER=http://127.0.0.1:6101/api/v1
|
API_BACK_SERVER=http://127.0.0.1:6101/api/v1
|
||||||
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/.gitattributes text eol=lf
|
||||||
|
/.agent/** text eol=lf
|
||||||
|
/AGENTS.md text eol=lf
|
||||||
|
/CLAUDE.md text eol=lf
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,7 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
.idea
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
/node_modules
|
/node_modules
|
||||||
/.pnp
|
/.pnp
|
||||||
|
|||||||
306
AGENTS.md
Normal file
306
AGENTS.md
Normal file
@@ -0,0 +1,306 @@
|
|||||||
|
<!--
|
||||||
|
GENERATED BY KRI AGENT HARNESS. DO NOT EDIT DIRECTLY.
|
||||||
|
Project: lge-cx-dash-front
|
||||||
|
Schema version: 1
|
||||||
|
Edit the source fragments or repository .agent files, then recompose.
|
||||||
|
-->
|
||||||
|
|
||||||
|
# KRI Development Base Instructions
|
||||||
|
|
||||||
|
This document defines the shared working rules for KRI development repositories.
|
||||||
|
Keep project-specific facts and commands in the project profile and project rules.
|
||||||
|
|
||||||
|
## Instruction Resolution
|
||||||
|
|
||||||
|
Apply repository instructions in this order:
|
||||||
|
|
||||||
|
1. Base rules
|
||||||
|
2. Project-type rules
|
||||||
|
3. Technology-stack rules
|
||||||
|
4. Shared consumer contracts
|
||||||
|
5. Project-specific rules
|
||||||
|
6. The explicitly approved task scope
|
||||||
|
|
||||||
|
Later and more specific instructions may override earlier general instructions only within their stated scope.
|
||||||
|
|
||||||
|
- Apply a shared consumer contract only when `.agent/profile.yml` declares it.
|
||||||
|
- Do not silently resolve a material instruction conflict. Report the conflicting rules and request a decision before changing files.
|
||||||
|
- Rules involving destructive actions, credentials, external systems, production, deployment, databases, or Git publication require explicit authorization even when a later rule is less restrictive.
|
||||||
|
|
||||||
|
## Communication
|
||||||
|
|
||||||
|
- Respond to the user in Korean unless the user requests another language.
|
||||||
|
- Keep code identifiers, commands, paths, protocol names, and external API terms in their original form.
|
||||||
|
- Follow the repository's existing language conventions for code comments and user-facing messages.
|
||||||
|
- Lead with the result or decision, then provide only the detail needed to verify it.
|
||||||
|
- Do not create or retain a full session transcript.
|
||||||
|
|
||||||
|
## Work Authorization
|
||||||
|
|
||||||
|
- The default workflow is discussion first and explicit execution approval second.
|
||||||
|
- During discussion, perform only read-only investigation needed to understand the task and propose a concrete plan, unless the user prohibits inspection.
|
||||||
|
- Read-only investigation may include file inspection, code search, encoding checks, `git status`, `git diff`, `git log`, and sanitized official-documentation lookup.
|
||||||
|
- Before execution approval, do not edit files, install dependencies, run builds or tests, start services, connect to databases, or change local or external state.
|
||||||
|
- Before requesting approval, describe the intended scope, affected areas, validation plan, and material risks.
|
||||||
|
- Treat approval as limited to the presented scope. Pause and discuss again if the work materially expands.
|
||||||
|
- If the user explicitly requests immediate execution without prior discussion, the discussion gate may be skipped for the stated scope.
|
||||||
|
- Fast-track authorization does not implicitly authorize protected operations such as destructive commands, production changes, deployments, database mutations, Git publication, or external messages.
|
||||||
|
|
||||||
|
## Local Development Environment
|
||||||
|
|
||||||
|
- Primary OS: Windows 11.
|
||||||
|
- Primary shell: PowerShell.
|
||||||
|
- Use Git Bash only when the repository already depends on Bash or POSIX shell behavior.
|
||||||
|
- Prefer repository-provided wrappers and scripts over globally installed commands.
|
||||||
|
- Do not assume that GNU utilities, WSL, Docker, or a Unix-compatible shell are available unless the project profile confirms them.
|
||||||
|
- Detect Java, Node.js, .NET, Python, package-manager, and database-tool versions from repository configuration.
|
||||||
|
- Do not install or modify global toolchains as part of a project task.
|
||||||
|
|
||||||
|
Preferred human-facing tools:
|
||||||
|
|
||||||
|
- Classic ASP: Visual Studio Code
|
||||||
|
- Java and Spring Boot: IntelliJ IDEA
|
||||||
|
- C# and .NET: JetBrains Rider
|
||||||
|
- JavaScript, TypeScript, and Next.js: JetBrains WebStorm
|
||||||
|
- Python: JetBrains PyCharm
|
||||||
|
- Microsoft SQL Server: SQL Server Management Studio
|
||||||
|
- Other databases: JetBrains DataGrip
|
||||||
|
|
||||||
|
- These preferences do not authorize launching or controlling a GUI application.
|
||||||
|
- Prefer IDE-independent commands that can also run in CI.
|
||||||
|
- Do not modify global IDE settings.
|
||||||
|
- Do not create or modify `.idea`, `.vscode`, workspace, or run-configuration files unless the approved task requires it.
|
||||||
|
- Preserve existing shared IDE configuration when it is already tracked.
|
||||||
|
|
||||||
|
## PowerShell and Path Safety
|
||||||
|
|
||||||
|
- Quote paths containing spaces, brackets, parentheses, Korean characters, or PowerShell metacharacters.
|
||||||
|
- Prefer `-LiteralPath` when operating on an exact filesystem path.
|
||||||
|
- Use project-relative paths in committed configuration and documentation. Do not commit machine-specific paths such as `D:\_____Dev\...`.
|
||||||
|
- Do not pass filesystem targets between PowerShell, `cmd.exe`, and Bash for destructive or recursive operations.
|
||||||
|
- Keep a filesystem operation within one shell from target resolution through execution.
|
||||||
|
- Before a recursive delete or move, resolve and verify every absolute target.
|
||||||
|
- Never use a drive root, workspace root, user profile, unresolved variable, wildcard, or broad glob as a recursive delete target.
|
||||||
|
- Prefer recoverable operations when practical.
|
||||||
|
|
||||||
|
## Change Discipline
|
||||||
|
|
||||||
|
- Preserve all existing user changes, including uncommitted and untracked work.
|
||||||
|
- Keep changes minimal but complete for the approved objective.
|
||||||
|
- Avoid unrelated cleanup, formatting, renaming, dependency upgrades, and architectural refactoring.
|
||||||
|
- Do not overwrite or revert unrelated changes.
|
||||||
|
- Stop and report when the requested change overlaps existing work in a way that cannot be handled safely.
|
||||||
|
- Prefer changing an authoritative source over editing generated output.
|
||||||
|
- Treat files marked as generated as read-only unless regeneration is part of the approved plan.
|
||||||
|
- Do not edit vendored dependencies, build outputs, caches, or generated clients unless explicitly required.
|
||||||
|
- Do not regenerate a broad set of files for a narrow change without first explaining the expected output scope.
|
||||||
|
|
||||||
|
## Text Encoding and Korean Content Safety
|
||||||
|
|
||||||
|
- Treat the existing file encoding, BOM state, and line-ending style as part of the file's contract.
|
||||||
|
- Preserve Korean comments, user-facing messages, error messages, identifiers, and documentation exactly unless the task explicitly requires changing them.
|
||||||
|
- Do not assume that garbled terminal output means the file itself is corrupted. Verify bytes and encoding before modifying suspicious text.
|
||||||
|
- Before editing an existing text file, determine its current encoding and BOM state when repository configuration does not already guarantee them.
|
||||||
|
- Do not convert encoding, add or remove a BOM, or normalize line endings as a side effect of an unrelated change.
|
||||||
|
- Avoid whole-file rewrites for small changes.
|
||||||
|
- Do not rewrite source files through `Get-Content | Set-Content`, `Out-File`, shell redirection, or another method whose encoding behavior is implicit.
|
||||||
|
- Do not use a patching or formatting tool on a non-UTF-8 file unless it is known to preserve that file's encoding.
|
||||||
|
- Treat a console display problem and an on-disk encoding problem as separate issues.
|
||||||
|
- After editing Korean text, inspect the diff for replacement characters (`<60>`), mojibake, unexpected escapes, BOM changes, and unrelated line-ending changes.
|
||||||
|
- Run `.agent/tools/check-encoding.ps1` when it is available and the change touches Korean text or a non-default encoding.
|
||||||
|
- If encoding cannot be identified confidently, stop before writing and report the affected file and evidence.
|
||||||
|
- For a new text file, follow repository configuration. If no rule exists, use UTF-8 without BOM.
|
||||||
|
|
||||||
|
## Git Safety
|
||||||
|
|
||||||
|
- Use `git status`, `git diff`, and `git log` for read-only investigation.
|
||||||
|
- Do not run `commit`, `push`, `pull`, `fetch`, `merge`, `rebase`, `reset`, `checkout`, `switch`, `stash`, `clean`, `tag`, or force operations unless that specific operation is explicitly approved.
|
||||||
|
- Source-edit approval does not include commit or push approval.
|
||||||
|
- Never amend an existing commit unless explicitly requested.
|
||||||
|
- Before an approved commit, show the intended files, validation results, and proposed commit message.
|
||||||
|
- Never push directly to a protected branch unless the user names the target branch and explicitly authorizes the push.
|
||||||
|
|
||||||
|
## Dependencies and External Actions
|
||||||
|
|
||||||
|
- Use the package manager, lockfile, and toolchain already selected by the repository.
|
||||||
|
- Do not install global packages.
|
||||||
|
- Do not add, remove, or upgrade a dependency unless it was included in the approved plan.
|
||||||
|
- Pause for approval if an unplanned dependency becomes necessary.
|
||||||
|
- Keep lockfiles synchronized with approved dependency changes.
|
||||||
|
- Do not deploy, publish packages, create releases, send messages or email, call business APIs, or modify external services unless explicitly requested.
|
||||||
|
- Never upload proprietary source code, internal documents, credentials, customer data, or database contents to an external service.
|
||||||
|
- Remove secrets and unnecessary internal identifiers from external search queries.
|
||||||
|
|
||||||
|
## Database Safety
|
||||||
|
|
||||||
|
- Treat writing or reviewing SQL as source code separately from executing SQL against a database.
|
||||||
|
- SQL files, migrations, schema proposals, and query drafts may be created within an approved source-change scope.
|
||||||
|
- Do not connect to a shared, staging, or production database without explicit authorization for that environment.
|
||||||
|
- Read-only queries against a non-local database also require authorization because results may contain sensitive data.
|
||||||
|
- Do not execute DDL, DML, stored procedures, migrations, administrative commands, or data-correction scripts against a non-disposable database without separate authorization for the exact target and operation.
|
||||||
|
- Source-change approval does not authorize migration execution.
|
||||||
|
- Use a disposable local or test database for approved validation only after verifying its identity and disposable nature.
|
||||||
|
- Never place credentials, connection strings, or sensitive query results in source files, logs, generated documents, or chat output.
|
||||||
|
|
||||||
|
## Secrets and Sensitive Data
|
||||||
|
|
||||||
|
- Never add credentials, tokens, passwords, private keys, connection strings, session identifiers, or production data to source control.
|
||||||
|
- Read sensitive files only when the approved task requires it and no safer source exists.
|
||||||
|
- Prefer inspecting configuration keys and schemas without displaying secret values.
|
||||||
|
- Never echo secrets into terminal output, chat responses, logs, diffs, generated documents, test fixtures, or screenshots.
|
||||||
|
- Redact sensitive values when reporting errors or command output.
|
||||||
|
- If a possible secret is discovered, do not repeat it. Report only its location, type, and recommended containment action.
|
||||||
|
- Do not rotate, revoke, copy, or otherwise modify credentials unless that exact action is explicitly authorized.
|
||||||
|
|
||||||
|
## Validation
|
||||||
|
|
||||||
|
- Discover supported build, test, lint, type-check, and formatting commands from repository files and project instructions. Do not invent commands.
|
||||||
|
- Include intended validation in the discussion-phase plan.
|
||||||
|
- After approved changes, run the narrowest relevant validation first, then broader checks when appropriate.
|
||||||
|
- Limit formatting to files within the approved scope.
|
||||||
|
- Do not run tests that require a shared database, production service, paid external API, or sensitive data unless separately authorized.
|
||||||
|
- Do not claim that a check passed unless it was executed successfully.
|
||||||
|
- If a check cannot be run, state the exact reason.
|
||||||
|
- Distinguish a current-change failure from a pre-existing failure or an undetermined failure.
|
||||||
|
- Do not fix unrelated failures without expanding the approved scope.
|
||||||
|
- Inspect the worktree after validation for unexpected generated files, formatting churn, encoding changes, or lockfile changes.
|
||||||
|
|
||||||
|
## Artifacts and Session Records
|
||||||
|
|
||||||
|
- Do not create full-session transcripts, automatic HTML copies, analysis reports, or extra documentation unless explicitly requested.
|
||||||
|
- Store durable information in the repository's existing documentation structure.
|
||||||
|
- Do not place generated reports or temporary analysis files in the repository root.
|
||||||
|
- Remove task-specific temporary files created by the current task after validation when removal is safe.
|
||||||
|
|
||||||
|
## Completion Report
|
||||||
|
|
||||||
|
When implementation is complete, report in Korean:
|
||||||
|
|
||||||
|
- what changed and why;
|
||||||
|
- the main affected files or components;
|
||||||
|
- validation commands actually executed and their results;
|
||||||
|
- checks not executed and the reason;
|
||||||
|
- remaining risks, assumptions, or follow-up work;
|
||||||
|
- database, deployment, dependency, encoding, and compatibility impact when applicable.
|
||||||
|
|
||||||
|
- Do not report completion while required validation is failing or known encoding corruption is unresolved.
|
||||||
|
- Keep the report concise and do not include a full session transcript.
|
||||||
|
|
||||||
|
## Requested Project Rules
|
||||||
|
|
||||||
|
- Treat the approved requirements, acceptance criteria, and recorded decisions as the primary scope boundary.
|
||||||
|
- Do not infer a requirement solely from a file name, folder date, or apparently newer document.
|
||||||
|
- When requirements conflict, report the exact sources and request a decision.
|
||||||
|
- Preserve original customer, partner, and planning documents as read-only evidence unless document editing is explicitly approved.
|
||||||
|
- Summarize durable implementation requirements inside the repository rather than relying only on files outside the repository.
|
||||||
|
- Do not expand the deliverable with speculative features, infrastructure, or architectural changes.
|
||||||
|
- Record material assumptions and unresolved decisions in the project-specific rules or existing project documentation.
|
||||||
|
- Define observable acceptance criteria before implementation.
|
||||||
|
- Treat separately managed Frontend and Backend repositories as independent deliverables with a coordinated contract.
|
||||||
|
- Protect customer, partner, survey, and field data as sensitive information.
|
||||||
|
- Keep handoff, operation, configuration, and validation instructions usable by the requesting team.
|
||||||
|
- Report deviations from the requested scope and obtain approval before proceeding.
|
||||||
|
|
||||||
|
## TypeScript
|
||||||
|
|
||||||
|
- Treat the repository's current TypeScript version, `tsconfig` files, module system, path aliases, and package manager as authoritative.
|
||||||
|
- Preserve or strengthen existing strictness. Do not weaken compiler options or hide errors with broad `any`, `@ts-ignore`, or unsafe assertions.
|
||||||
|
- Prefer narrow domain types, discriminated unions, and explicit boundary types over duplicated or overly generic shapes.
|
||||||
|
- Validate untrusted runtime input even when a compile-time type exists.
|
||||||
|
- Keep imports, exports, aliases, and generated-code boundaries consistent with the repository.
|
||||||
|
- Do not introduce a JavaScript-to-TypeScript conversion outside the approved scope.
|
||||||
|
- Run the repository's focused type-check, lint, test, and build commands as applicable.
|
||||||
|
|
||||||
|
## React
|
||||||
|
|
||||||
|
- Treat the current React version, component style, state management, routing, styling, and test approach as authoritative.
|
||||||
|
- Do not perform unrelated class-to-hook, JavaScript-to-TypeScript, state-library, styling-system, or React-to-Next.js migrations.
|
||||||
|
- Keep components focused and follow the repository's established split between presentation, state, data access, and side effects.
|
||||||
|
- Keep effects dependency-correct and clean up subscriptions, timers, listeners, and in-flight work where applicable.
|
||||||
|
- Use stable semantic keys and preserve accessibility, loading, empty, error, disabled, and success states.
|
||||||
|
- Preserve public component props and shared UI contracts unless a coordinated breaking change is explicitly approved.
|
||||||
|
- Treat any planned Next.js migration as a separate policy and task; the current React application remains authoritative until that migration slice is approved.
|
||||||
|
|
||||||
|
## Next.js
|
||||||
|
|
||||||
|
- Treat the repository's current Next.js and React versions, routing model, rendering model, and package manager as authoritative.
|
||||||
|
- Preserve server and client component boundaries. Add `use client` only when browser APIs, state, effects, or client-only libraries require it.
|
||||||
|
- Keep secrets, privileged data access, and server-only modules out of client bundles.
|
||||||
|
- Preserve established route, layout, middleware, authentication, authorization, caching, revalidation, and error-handling conventions.
|
||||||
|
- Validate request parameters, payloads, headers, cookies, and external responses at runtime.
|
||||||
|
- Do not create new frontend TypeScript type or interface names ending in `Dto` or `DTO`. Use domain- or purpose-specific names such as `User`, `UserInput`, `UserRequest`, or `UserResponse`; do not rename existing types solely to enforce this rule outside the approved scope.
|
||||||
|
- Use the approved KRI frontend and UI contracts when the project profile includes them; do not copy shared implementations into an application.
|
||||||
|
- Avoid incidental routing-model or rendering-strategy migrations.
|
||||||
|
- Run the repository's focused lint, type-check, test, and production build commands as applicable.
|
||||||
|
|
||||||
|
## KriFrontCommon Consumer Contract
|
||||||
|
|
||||||
|
### Package Usage
|
||||||
|
|
||||||
|
- Consume this contract through the published `@kri/common` package and only through entry points declared in its `package.json` `exports` map.
|
||||||
|
- Use the package root for runtime-neutral object, URL, date, string, and shared type utilities.
|
||||||
|
- Use a focused subpath such as `@kri/common/http`, `@kri/common/browser`, `@kri/common/server`, `@kri/common/security`, `@kri/common/hooks`, `@kri/common/query`, `@kri/common/config`, `@kri/common/jotai`, or `@kri/common/noti-hub` for the corresponding capability.
|
||||||
|
- Do not import from `@kri/common/src/*`, `@kri/common/dist/*`, or another undeclared deep path.
|
||||||
|
- Do not copy or fork a shared utility locally merely to avoid using an available public entry point. Propose a backward-compatible library addition when the shared contract is genuinely missing.
|
||||||
|
|
||||||
|
### Runtime and Optional Integrations
|
||||||
|
|
||||||
|
- Keep browser, server, and runtime-neutral imports on their intended side of the application boundary.
|
||||||
|
- A consumer that uses React hooks, TanStack Query, or Jotai integrations must provide the compatible optional peer dependency required by its selected entry point.
|
||||||
|
- Preserve the project's established HTTP client, authentication, error-policy, query-client, storage, and environment conventions when adopting a shared helper.
|
||||||
|
- Validate external data at runtime; a shared TypeScript type alone does not validate an API response or persisted value.
|
||||||
|
- Prefer named public exports and retain the consumer project's current module system and bundler conventions.
|
||||||
|
|
||||||
|
### Change Safety
|
||||||
|
|
||||||
|
- Pin or constrain the package version according to the consumer repository's dependency policy and commit its lockfile changes.
|
||||||
|
- Review release notes and the actual affected API before upgrading. Run the consumer's focused type-check, test, and build commands after an upgrade.
|
||||||
|
- Do not modify KriFrontCommon or another consumer repository unless it is explicitly included in the approved task scope.
|
||||||
|
|
||||||
|
## KriUiRegistry Consumer Contract
|
||||||
|
|
||||||
|
### UI Component Selection
|
||||||
|
|
||||||
|
When implementing or changing frontend UI, use this order:
|
||||||
|
|
||||||
|
1. Reuse an existing shared component in the project when it already meets the requirement.
|
||||||
|
2. Prefer an approved component from KriUiRegistry.
|
||||||
|
3. Otherwise, prefer a suitable shadcn/ui component.
|
||||||
|
4. Create a new custom component only when the preceding options cannot meet the requirement without an unsafe or misleading adaptation.
|
||||||
|
|
||||||
|
### Installation and Ownership
|
||||||
|
|
||||||
|
- Inspect the registry item and its dependencies before installation. Use the shadcn CLI with the approved registry endpoint under `https://ui-registry.kric.com/r/` instead of copying files from `dist/r` manually.
|
||||||
|
- `kri-data-table` uses the TanStack Table v8 API. Keep `@tanstack/react-table` within the supported `^8.21.3` range and do not upgrade it to v9 until KriUiRegistry provides an explicitly migrated component contract.
|
||||||
|
- Respect the consumer project's component aliases, target paths, package manager, styling system, React version, and existing design tokens.
|
||||||
|
- The shadcn workflow copies component source into the consumer repository. After installation, treat that copy as project-owned code; do not assume registry updates propagate automatically.
|
||||||
|
- Do not overwrite an existing project component without reviewing the diff and confirming that local behavior and accessibility are preserved.
|
||||||
|
- Keep package and lockfile changes produced by an installation within the approved scope.
|
||||||
|
|
||||||
|
### Adaptation and Verification
|
||||||
|
|
||||||
|
- Adapt business data and application behavior outside the shared component when possible. Avoid embedding project-specific API, route, authentication, or environment logic into a reusable component.
|
||||||
|
- Preserve the installed component's public props, accessibility, keyboard behavior, responsive layout, and loading, empty, error, and disabled states unless the task explicitly changes them.
|
||||||
|
- If the registry lacks a generally reusable capability, propose it in KriUiRegistry; do not modify that repository unless it is explicitly in scope.
|
||||||
|
- Run the consumer repository's focused type-check, lint, tests, and build after installation or upgrade.
|
||||||
|
|
||||||
|
## LGE CX Dashboard Frontend Repository Rules
|
||||||
|
|
||||||
|
### Deliverable and User Experience
|
||||||
|
|
||||||
|
- This Next.js frontend visualizes LGE appliance penetration, purchase, category, profile, and trend survey statistics.
|
||||||
|
- Treat approved planning and design material as the scope boundary. Preserve category navigation, filters, labels, chart/table values, comparison context, and Excel export behavior.
|
||||||
|
- A visual change must not silently alter the represented statistic, denominator, ordering, rounding, tooltip meaning, or empty-data behavior.
|
||||||
|
- Keep customer survey data, exported workbooks, and internal planning material out of logs, fixtures, screenshots, and external services.
|
||||||
|
|
||||||
|
### Frontend Implementation
|
||||||
|
|
||||||
|
- Use the consumed KRI frontend common and UI registry contracts. Prefer an existing shadcn/ui or registry component before creating a new foundational component.
|
||||||
|
- Do not create new TypeScript type or interface names ending in `Dto` or `DTO`.
|
||||||
|
- Preserve accessibility, responsive layout, loading, empty, error, unauthorized, and export states across every dashboard route.
|
||||||
|
- Coordinate API request, response, authentication, and error changes with the backend without requiring an unsafe simultaneous deployment.
|
||||||
|
|
||||||
|
### Harness and Verification
|
||||||
|
|
||||||
|
- `AGENTS.md` and `CLAUDE.md` are generated. Edit `.agent/profile.yml` or `.agent/project.md`, then recompose instead of editing generated files.
|
||||||
|
- Use the existing npm scripts and focused lint, type-check, test, or production build checks. Do not call production APIs or export real customer data during validation.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
import CategoryPage from "../sub-page/CategoryPage";
|
||||||
|
|
||||||
const ESPage = () => {
|
const ESPage = () => {
|
||||||
return <CategoryPage/>
|
return <CategoryPage/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
import CategoryPage from "../sub-page/CategoryPage";
|
||||||
|
|
||||||
const KitchenPage = () => {
|
const KitchenPage = () => {
|
||||||
return <CategoryPage/>
|
return <CategoryPage/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
import CategoryPage from "../sub-page/CategoryPage";
|
||||||
|
|
||||||
const LivingPage = () => {
|
const LivingPage = () => {
|
||||||
return <CategoryPage/>
|
return <CategoryPage/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
import CategoryPage from "../sub-page/CategoryPage";
|
||||||
|
|
||||||
const MSPage = () => {
|
const MSPage = () => {
|
||||||
return <CategoryPage/>
|
return <CategoryPage/>
|
||||||
|
|||||||
120
src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx
Normal file
120
src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import {useMemo} from "react";
|
||||||
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
|
import {CategoryTargetData} from "@/types/filter.types";
|
||||||
|
import {BannerRow, CategoryResolvedField, StatisticsRequest} from "@/types/lg.types";
|
||||||
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||||
|
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||||
|
import {buildCategoryFilter, buildGapRow, buildPageModeConfig} from "@/lib/lg-dashboard";
|
||||||
|
import {BANNER_GROUP_KEY} from "@/const/lg-banner.const";
|
||||||
|
import {API_DECIMAL_POINT, USE_CACHE} from "@/const/lg-common.const";
|
||||||
|
import Profile from "./category-page/Profile";
|
||||||
|
import PenetrationChange from "./category-page/PenetrationChange";
|
||||||
|
import CategoryDetail from "./category-page/CategoryDetail";
|
||||||
|
import {useBannerStatisticsQuery} from "@/query/statistics";
|
||||||
|
|
||||||
|
export type CategoryPageProps = {
|
||||||
|
fields: CategoryResolvedField[];
|
||||||
|
variableIdMap: Record<string, string>;
|
||||||
|
dataMap:Record<string, BannerRow[]> | undefined;
|
||||||
|
fillGreaterThan5?: boolean;
|
||||||
|
isProfileAll?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PAGE_COMPONENTS: Partial<Record<CategoryTargetData, React.ComponentType<CategoryPageProps>>> = {
|
||||||
|
[CategoryTargetData.PROFILE]: Profile,
|
||||||
|
[CategoryTargetData.PROFILE_ALL]: Profile,
|
||||||
|
[CategoryTargetData.PENETRATION_CHANGE]: PenetrationChange,
|
||||||
|
[CategoryTargetData.BRAND]: CategoryDetail,
|
||||||
|
[CategoryTargetData.TYPE_SPEC]: CategoryDetail,
|
||||||
|
[CategoryTargetData.BEHAVIOR]: CategoryDetail,
|
||||||
|
[CategoryTargetData.PURCHASE_CHANNEL]: CategoryDetail,
|
||||||
|
[CategoryTargetData.PAYMENT_METHOD]: CategoryDetail,
|
||||||
|
};
|
||||||
|
|
||||||
|
const CategoryPage = () => {
|
||||||
|
const { isTotal, filterValue } = useLayoutFilter();
|
||||||
|
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||||
|
|
||||||
|
const { fields, variableIdMap } = useMemo(() => {
|
||||||
|
return buildPageModeConfig(debouncedFilterValue);
|
||||||
|
}, [debouncedFilterValue]);
|
||||||
|
|
||||||
|
const req = useMemo<StatisticsRequest>(() => {
|
||||||
|
return {
|
||||||
|
variableIdMap,
|
||||||
|
bannerIdList: BANNER_GROUP_KEY,
|
||||||
|
filterCondition: buildCategoryFilter(debouncedFilterValue),
|
||||||
|
option: { useCache: USE_CACHE, lastYear: false, decimalPoint: 2 },
|
||||||
|
};
|
||||||
|
}, [variableIdMap, debouncedFilterValue]);
|
||||||
|
const { data } = useBannerStatisticsQuery(req);
|
||||||
|
const dataMap = data?.statisticsDataMap;
|
||||||
|
const target = debouncedFilterValue.target;
|
||||||
|
const Comp = PAGE_COMPONENTS[target.value];
|
||||||
|
const isProfileAll = target.value === CategoryTargetData.PROFILE_ALL;
|
||||||
|
const fillGreaterThan5 = Comp === CategoryDetail && !!dataMap;
|
||||||
|
|
||||||
|
const processedDataMap = useMemo(() => {
|
||||||
|
if (!dataMap || target.value !== CategoryTargetData.BRAND) {
|
||||||
|
return dataMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextMap: Record<string, BannerRow[]> = { ...dataMap };
|
||||||
|
|
||||||
|
fields.forEach((f) => {
|
||||||
|
const rows = dataMap[f.requestKeyResolved];
|
||||||
|
if (!rows?.length) return;
|
||||||
|
|
||||||
|
const years = Array.from(new Set(rows.map((row) => Number(row.year))))
|
||||||
|
.filter((year) => Number.isFinite(year))
|
||||||
|
.sort((a, b) => b - a)
|
||||||
|
.slice(0, -1);
|
||||||
|
|
||||||
|
if(years.length === 0) {
|
||||||
|
nextMap[f.requestKeyResolved] = rows;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gapRowsByYear = new Map<number, BannerRow>();
|
||||||
|
|
||||||
|
years.forEach((year) => {
|
||||||
|
const currentYear = year;
|
||||||
|
const prevYear = year - 1;
|
||||||
|
const gapRow = buildGapRow(rows, prevYear, currentYear, "LG");
|
||||||
|
|
||||||
|
if(gapRow !== null){
|
||||||
|
gapRowsByYear.set(currentYear, gapRow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const nextRows: BannerRow[] = [];
|
||||||
|
rows.forEach((row) => {
|
||||||
|
nextRows.push(row);
|
||||||
|
|
||||||
|
const gapRow = gapRowsByYear.get(Number(row.year));
|
||||||
|
if (row.rowLabel === "LG" && gapRow) {
|
||||||
|
nextRows.push(gapRow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
nextMap[f.requestKeyResolved] = nextRows;
|
||||||
|
});
|
||||||
|
|
||||||
|
return nextMap;
|
||||||
|
}, [dataMap, fields, target.value]);
|
||||||
|
|
||||||
|
if(isTotal) return null;
|
||||||
|
return Comp ?
|
||||||
|
<Comp
|
||||||
|
fields={fields}
|
||||||
|
variableIdMap={variableIdMap}
|
||||||
|
dataMap={processedDataMap}
|
||||||
|
fillGreaterThan5={fillGreaterThan5}
|
||||||
|
isProfileAll={isProfileAll}
|
||||||
|
/>
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CategoryPage;
|
||||||
@@ -1,28 +1,41 @@
|
|||||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||||
import {useEffect, useMemo} from "react";
|
import {useEffect, useMemo} from "react";
|
||||||
import {BannerRow, PageData} from "@/types/lg";
|
import {BannerRow, PageData} from "@/types/lg.types";
|
||||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
import {BANNER_GROUP} from "@/const/lg-banner.const";
|
||||||
|
import {BANNER_KEY_MAP, PRODUCT_KEY_MAP} from "@/const/lg-schema.const";
|
||||||
|
import {QID_SURVEY_TITLE} from "@/const/lg-survey.const";
|
||||||
|
import {SITE_TITLE, YEARS} from "@/const/lg-common.const";
|
||||||
import {CategoryByData} from "@/components/lge-dashboard";
|
import {CategoryByData} from "@/components/lge-dashboard";
|
||||||
|
import {wrapSampleRow} from "@/lib/lg-dashboard";
|
||||||
|
|
||||||
const CategoryDetail = ({
|
const CategoryDetail = ({
|
||||||
fields,
|
fields,
|
||||||
dataMap
|
dataMap,
|
||||||
}:CategoryPageProps) => {
|
fillGreaterThan5
|
||||||
|
}:CategoryPageProps) => {
|
||||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||||
|
|
||||||
const tableDataArray = useMemo<PageData<BannerRow>[]>(() => {
|
const tableDataArray = useMemo<PageData<BannerRow>[]>(() => {
|
||||||
const tempTableDataArray = fields.map((f) => {
|
const tempTableDataArray = fields.map((f) :PageData<BannerRow> => {
|
||||||
const dataLength = dataMap?.[f.requestKeyResolved].filter((row) => row.rowLabel !=`사례수`).length;
|
const dataLength = dataMap?.[f.requestKeyResolved].filter((row) => row.rowLabel !=`사례수`).length;
|
||||||
|
const qid = f.qidByMode[debouncedFilterValue.type.value];
|
||||||
|
|
||||||
|
let surveyTitle = qid? QID_SURVEY_TITLE[qid] ?? "" : "";
|
||||||
|
surveyTitle = surveyTitle.replaceAll("[#YEAR#]", debouncedFilterValue.year);
|
||||||
|
surveyTitle = surveyTitle.replaceAll("[#NEXT_YEAR#]", String(Number(debouncedFilterValue.year) + 1));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: typeof f.title === "string"? f.title : f.title[debouncedFilterValue.type.value],
|
title: typeof f.title === "string"? f.title : f.title[debouncedFilterValue.type.value],
|
||||||
|
surveyTitle: surveyTitle,
|
||||||
chartMode:f.chartMode,
|
chartMode:f.chartMode,
|
||||||
data: dataLength && dataLength > 0 ? dataMap[f.requestKeyResolved] : []
|
chartLegend:f.chartLegend,
|
||||||
|
chartTopMargin:f.chartTopMargin,
|
||||||
|
data: dataLength && dataLength > 0 ? wrapSampleRow(dataMap[f.requestKeyResolved]) : []
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -33,17 +46,19 @@ const CategoryDetail = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const product = debouncedFilterValue.product;
|
const product = PRODUCT_KEY_MAP[debouncedFilterValue.product];
|
||||||
const type = debouncedFilterValue.type.label;
|
const type = debouncedFilterValue.type.label;
|
||||||
const target = debouncedFilterValue.target.label.replaceAll('/', '_');
|
const target = debouncedFilterValue.target.label.replaceAll('/', '_');
|
||||||
|
|
||||||
const sheetName = `${product}_${type}_${target}`
|
const sheetName = `${product}_${type}_${target}`
|
||||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||||
|
const years = [
|
||||||
|
debouncedFilterValue.year,
|
||||||
|
String(Number(debouncedFilterValue.year) - 1),
|
||||||
|
].filter((year) => YEARS.includes(year));
|
||||||
|
|
||||||
type AnyRow = Record<string, any>;
|
type AnyRow = Record<string, any>;
|
||||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
|
||||||
|
|
||||||
return years.map((year) => ({
|
return years.map((year) => ({
|
||||||
title: `${tableData.title}_${year}년`,
|
title: `${tableData.title}_${year}년`,
|
||||||
header: h3,
|
header: h3,
|
||||||
@@ -66,16 +81,20 @@ const CategoryDetail = ({
|
|||||||
{tableDataArray.map((tableData) => (
|
{tableDataArray.map((tableData) => (
|
||||||
<CategoryByData
|
<CategoryByData
|
||||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||||
selectedYear={filterValue.year}
|
selectedYear={debouncedFilterValue.year}
|
||||||
title={tableData.title}
|
title={tableData.title}
|
||||||
|
surveyTitle={tableData.surveyTitle}
|
||||||
chartMode={tableData.chartMode}
|
chartMode={tableData.chartMode}
|
||||||
|
chartLegend={tableData.chartLegend}
|
||||||
|
chartTopMargin={tableData.chartTopMargin}
|
||||||
allTableData={tableData.data}
|
allTableData={tableData.data}
|
||||||
chartHeight={tableData.chartHeight}
|
chartHeight={tableData.chartHeight}
|
||||||
chartWidth={tableData.chartWidth}
|
chartWidth={tableData.chartWidth}
|
||||||
|
fillGreaterThan5={fillGreaterThan5}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CategoryDetail;
|
export default CategoryDetail;
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import {DataColumn} from "@/components/lge-dashboard";
|
||||||
|
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||||
|
import {useMemo} from "react";
|
||||||
|
import {parseNumber} from "@/lib/utils";
|
||||||
|
import {BannerRow} from "@/types/lg.types";
|
||||||
|
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||||
|
import {LAST_YEAR} from "@/const/lg-common.const";
|
||||||
|
|
||||||
|
const PenetrationChange = ({
|
||||||
|
dataMap
|
||||||
|
}:CategoryPageProps) => {
|
||||||
|
|
||||||
|
const penetrationChangeData = useMemo<BannerRow[]>(() => {
|
||||||
|
if (dataMap === undefined) return [];
|
||||||
|
|
||||||
|
const tempProfileData: BannerRow[] = [];
|
||||||
|
Object.keys(dataMap).forEach(requestKey => {
|
||||||
|
const data = dataMap[requestKey];
|
||||||
|
tempProfileData.push(
|
||||||
|
...data.filter((r) => r.rowLabel === `사례수` && r.year === LAST_YEAR),
|
||||||
|
...data.filter((r) => r.rowLabel === `보유`)
|
||||||
|
.map((row) => {
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
rowLabel: row.year,
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
return tempProfileData;
|
||||||
|
}, [dataMap]);
|
||||||
|
|
||||||
|
const getCellClassName = (row: BannerRow, column: DataColumn<BannerRow>, rowIndex: number) => {
|
||||||
|
if (!("key" in column) || column.key === undefined) return undefined;
|
||||||
|
|
||||||
|
const currentYear = Number(row.year);
|
||||||
|
if (currentYear !== 2024 && currentYear !== 2025) return undefined;
|
||||||
|
if (column.key === "rowLabel" || column.key === "total") return undefined;
|
||||||
|
|
||||||
|
const prevRow = penetrationChangeData[rowIndex - 1];
|
||||||
|
if (!prevRow || Number(prevRow.year) !== currentYear - 1) return undefined;
|
||||||
|
|
||||||
|
const currentValue = parseNumber(row[column.key]);
|
||||||
|
const prevValue = parseNumber(prevRow[column.key]);
|
||||||
|
if (currentValue === null || prevValue === null) return undefined;
|
||||||
|
|
||||||
|
const gap = currentValue - prevValue;
|
||||||
|
|
||||||
|
if (gap >= 3) return "lg-num-pos";
|
||||||
|
if (gap <= -3) return "lg-num-neg";
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
return(
|
||||||
|
<>
|
||||||
|
<BannerSummary
|
||||||
|
data={penetrationChangeData}
|
||||||
|
useChart={true}
|
||||||
|
useYear={false}
|
||||||
|
getCellClassName={getCellClassName}
|
||||||
|
/>
|
||||||
|
<div className="content-text-base font-bold mt-2">
|
||||||
|
전년 대비 GAP ±3%p 이상 수치 강조 : <span className="lg-num-pos"> 상승</span> / <span className="lg-num-neg">하락</span>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PenetrationChange
|
||||||
@@ -3,26 +3,27 @@
|
|||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
import {BannerRow} from "@/types/lg";
|
import {BannerRow} from "@/types/lg.types";
|
||||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||||
import { calcGapBannerRow } from "@/lib/lg-dashboard";
|
import { calcGapBannerRow } from "@/lib/lg-dashboard";
|
||||||
import {YEARS} from "@/const/lgConst";
|
import {YEARS} from "@/const/lg-common.const";
|
||||||
import {CategoryTargetType} from "@/config/filter.types";
|
import {CategoryTargetType} from "@/types/filter.types";
|
||||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||||
|
|
||||||
const Profile = ({
|
const Profile = ({
|
||||||
dataMap
|
dataMap,
|
||||||
|
isProfileAll,
|
||||||
}:CategoryPageProps) => {
|
}:CategoryPageProps) => {
|
||||||
const { filterValue } = useLayoutFilter();
|
const { filterValue } = useLayoutFilter();
|
||||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||||
|
|
||||||
const profileData = useMemo<BannerRow[]>(() => {
|
const profileData = useMemo<BannerRow[]>(() => {
|
||||||
if (dataMap === undefined) return [];
|
if (dataMap === undefined) return [];
|
||||||
|
|
||||||
const targetMap = {
|
const targetMap = {
|
||||||
[CategoryTargetType.PENETRATION]: "보유",
|
[CategoryTargetType.PENETRATION]: "보유",
|
||||||
[CategoryTargetType.PURCHASE]: "해당년도",
|
[CategoryTargetType.PURCHASE]: "구매",
|
||||||
[CategoryTargetType.INTENDED]: "향후구매",
|
[CategoryTargetType.INTENDED]: "향후구매",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ const Profile = ({
|
|||||||
.map((row) => {
|
.map((row) => {
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: row.year,
|
rowLabel: isProfileAll ? `${row.rowLabel}율` : row.year,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -68,12 +69,20 @@ const Profile = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return tempProfileData.sort((a, b) => Number(a.rowLabel === "보유대수") - Number(b.rowLabel === "보유대수"));
|
tempProfileData.sort((a, b) => Number(a.rowLabel === "보유대수") - Number(b.rowLabel === "보유대수"));
|
||||||
}, [debouncedFilterValue, dataMap]);
|
tempProfileData.sort((a, b) => Number(a.year) - Number(b.year));
|
||||||
|
|
||||||
|
return tempProfileData;
|
||||||
|
}, [debouncedFilterValue, dataMap, isProfileAll]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BannerSummary data={profileData} useChart={false} useYear={true} />
|
<BannerSummary
|
||||||
|
data={profileData}
|
||||||
|
useChart={false}
|
||||||
|
useYear={!isProfileAll}
|
||||||
|
isProfileAll={isProfileAll}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Profile;
|
export default Profile;
|
||||||
@@ -9,15 +9,18 @@ import {
|
|||||||
type TopChartTableRow,
|
type TopChartTableRow,
|
||||||
} from "@/components/lge-dashboard";
|
} from "@/components/lge-dashboard";
|
||||||
import {
|
import {
|
||||||
CHART_COLOR_BY_YEAR,
|
|
||||||
CHART_FOCUS_COLOR_BY_YEAR,
|
|
||||||
LIFE_STAGE_COLUMNS,
|
LIFE_STAGE_COLUMNS,
|
||||||
LIFE_STAGE_GROUPS,
|
LIFE_STAGE_GROUPS,
|
||||||
PRODUCT_KEY_MAP,
|
|
||||||
PRODUCT_KEYS,
|
PRODUCT_KEYS,
|
||||||
|
} from "@/const/lg-product.const";
|
||||||
|
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
|
import {
|
||||||
|
API_DECIMAL_POINT,
|
||||||
SITE_TITLE,
|
SITE_TITLE,
|
||||||
YEARS
|
USE_CACHE,
|
||||||
} from "@/const/lgConst";
|
YEARS,
|
||||||
|
} from "@/const/lg-common.const";
|
||||||
|
import { CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import {useEffect, useMemo} from "react";
|
import {useEffect, useMemo} from "react";
|
||||||
import LifeStageDiv from "@/components/lge-dashboard/combo/LifeStageDiv";
|
import LifeStageDiv from "@/components/lge-dashboard/combo/LifeStageDiv";
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
@@ -25,7 +28,7 @@ import {
|
|||||||
calcGapProductRow, calcTotalBaseRow,
|
calcGapProductRow, calcTotalBaseRow,
|
||||||
formatRowLabel,
|
formatRowLabel,
|
||||||
normalizeFilterCondition,
|
normalizeFilterCondition,
|
||||||
withGapRow, withTotalBaseRow
|
withGapRow, withTotalBaseRow, wrapSampleRow
|
||||||
} from "@/lib/lg-dashboard";
|
} from "@/lib/lg-dashboard";
|
||||||
import {
|
import {
|
||||||
buildHeader_LifeStageColumns,
|
buildHeader_LifeStageColumns,
|
||||||
@@ -34,21 +37,21 @@ import {
|
|||||||
Section
|
Section
|
||||||
} from "@/lib/lg-export-excel";
|
} from "@/lib/lg-export-excel";
|
||||||
import {toNumOr0} from "@/lib/utils";
|
import {toNumOr0} from "@/lib/utils";
|
||||||
import {LifeStageGroup, LifeStageRow, ProductKey, StatisticsRequest} from "@/types/lg";
|
import {LifeStageGroup, LifeStageRow, ProductKey, StatisticsRequest} from "@/types/lg.types";
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||||
import {SelectedMap} from "@/types/common";
|
import {SelectedMap} from "@/types/common";
|
||||||
import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/query/statistics";
|
||||||
|
|
||||||
const LGPenetrationPage = () => {
|
const LGPenetrationPage = () => {
|
||||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||||
|
|
||||||
const req = useMemo<StatisticsRequest>(() => {
|
const req = useMemo<StatisticsRequest>(() => {
|
||||||
return {
|
return {
|
||||||
variableIdMap: {penetration: "KQA1", penetration_lg: "KQA3_3_LG"},
|
variableIdMap: {penetration: "KQA1", penetration_lg: "KQA3_3_LG"},
|
||||||
bannerIdList: ["product"],
|
bannerIdList: ["product"],
|
||||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||||
option: {useCache: true, lastYear: false, decimalPoint: 0},
|
option: {useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||||
};
|
};
|
||||||
}, [debouncedFilterValue]);
|
}, [debouncedFilterValue]);
|
||||||
|
|
||||||
@@ -59,7 +62,7 @@ const LGPenetrationPage = () => {
|
|||||||
variableIdMap: {lifestage_lg: "KQA3_3_LG"},
|
variableIdMap: {lifestage_lg: "KQA3_3_LG"},
|
||||||
bannerIdList: ["product|lifeStage"],
|
bannerIdList: ["product|lifeStage"],
|
||||||
filterCondition: normalizeFilterCondition(filter),
|
filterCondition: normalizeFilterCondition(filter),
|
||||||
option: {useCache: true, lastYear: true, decimalPoint: 0},
|
option: {useCache: USE_CACHE, lastYear: true, decimalPoint: API_DECIMAL_POINT },
|
||||||
};
|
};
|
||||||
}, [debouncedFilterValue]);
|
}, [debouncedFilterValue]);
|
||||||
|
|
||||||
@@ -82,19 +85,27 @@ const LGPenetrationPage = () => {
|
|||||||
data?.statisticsDataMap?.penetration
|
data?.statisticsDataMap?.penetration
|
||||||
.filter((r) => r.rowLabel == `보유`)
|
.filter((r) => r.rowLabel == `보유`)
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
|
const rowSample = data?.statisticsDataMap?.penetration
|
||||||
|
.find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: row.year,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const penetrationLGRows =
|
const penetrationLGRows =
|
||||||
data?.statisticsDataMap?.penetration_lg
|
data?.statisticsDataMap?.penetration_lg
|
||||||
.filter((row) => row.rowLabel === `보유`)
|
.filter((r) => r.rowLabel == `보유`)
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
|
const rowSample = data?.statisticsDataMap?.penetration_lg
|
||||||
|
.find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: row.year,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
@@ -119,13 +130,15 @@ const LGPenetrationPage = () => {
|
|||||||
}, [penetrationLGRows]);
|
}, [penetrationLGRows]);
|
||||||
|
|
||||||
const penetrationLGRowsWithGap = useMemo(() => {
|
const penetrationLGRowsWithGap = useMemo(() => {
|
||||||
const withGap = withGapRow(penetrationLGRows, calcGapProductRow);
|
const withGap = withGapRow(penetrationLGRows, calcGapProductRow, -1, -2);
|
||||||
return withTotalBaseRow("보급률",penetrationRows, withGap, calcTotalBaseRow);
|
|
||||||
|
return withTotalBaseRow("보급률",penetrationRows, wrapSampleRow(withGap, false), calcTotalBaseRow);
|
||||||
}, [penetrationRows, penetrationLGRows]);
|
}, [penetrationRows, penetrationLGRows]);
|
||||||
|
|
||||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return penetrationLGRowsWithGap.map((row) => ({
|
return penetrationLGRowsWithGap.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
||||||
}));
|
}));
|
||||||
@@ -181,6 +194,8 @@ const LGPenetrationPage = () => {
|
|||||||
"KLIFEstAGE#4": lifeStageData[`${key}|KLIFEstAGE#4`] ?? "",
|
"KLIFEstAGE#4": lifeStageData[`${key}|KLIFEstAGE#4`] ?? "",
|
||||||
"KLIFEstAGE#5": lifeStageData[`${key}|KLIFEstAGE#5`] ?? "",
|
"KLIFEstAGE#5": lifeStageData[`${key}|KLIFEstAGE#5`] ?? "",
|
||||||
"KLIFEstAGE#6": lifeStageData[`${key}|KLIFEstAGE#6`] ?? "",
|
"KLIFEstAGE#6": lifeStageData[`${key}|KLIFEstAGE#6`] ?? "",
|
||||||
|
"KLIFEstAGE#7": lifeStageData[`${key}|KLIFEstAGE#7`] ?? "",
|
||||||
|
"KLIFEstAGE#8": lifeStageData[`${key}|KLIFEstAGE#8`] ?? "",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -191,12 +206,13 @@ const LGPenetrationPage = () => {
|
|||||||
const description = useMemo(() => {
|
const description = useMemo(() => {
|
||||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||||
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?<br/>" +
|
||||||
|
"** 조사 년도 보급률 중 자사제품 비율 = (LG 보급률 ÷ 전체 보급률) × 100";
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const excelHeader = buildHeader_ProductKeyMap(productKeyMap);
|
const excelHeader = buildHeader_ProductKeyMap(productKeyMap, "sample");
|
||||||
const lifeStageHeader = buildHeader_LifeStageColumns(LIFE_STAGE_COLUMNS);
|
const lifeStageHeader = buildHeader_LifeStageColumns(LIFE_STAGE_COLUMNS);
|
||||||
|
|
||||||
type AnyRow = Record<string, any>;
|
type AnyRow = Record<string, any>;
|
||||||
@@ -235,6 +251,7 @@ const LGPenetrationPage = () => {
|
|||||||
chart={
|
chart={
|
||||||
<GroupedOverlayBar
|
<GroupedOverlayBar
|
||||||
data={productChartData}
|
data={productChartData}
|
||||||
|
questionText={"보급률"}
|
||||||
yearTotalColor={CHART_COLOR_BY_YEAR}
|
yearTotalColor={CHART_COLOR_BY_YEAR}
|
||||||
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
||||||
showFocusLabel={"last"}
|
showFocusLabel={"last"}
|
||||||
@@ -251,4 +268,4 @@ const LGPenetrationPage = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LGPenetrationPage;
|
export default LGPenetrationPage;
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
import {useEffect, useMemo} from "react";
|
import {useEffect, useMemo} from "react";
|
||||||
import {
|
import {
|
||||||
CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR,
|
|
||||||
PRODUCT_KEY_MAP,
|
|
||||||
PRODUCT_KEYS,
|
PRODUCT_KEYS,
|
||||||
|
} from "@/const/lg-product.const";
|
||||||
|
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
|
import {
|
||||||
|
API_DECIMAL_POINT,
|
||||||
SITE_TITLE,
|
SITE_TITLE,
|
||||||
YEARS
|
USE_CACHE,
|
||||||
} from "@/const/lgConst";
|
YEARS,
|
||||||
|
} from "@/const/lg-common.const";
|
||||||
|
import { CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import {
|
import {
|
||||||
BottomDescription,
|
BottomDescription,
|
||||||
GroupedOverlayBar,
|
GroupedOverlayBar,
|
||||||
@@ -21,25 +25,25 @@ import {
|
|||||||
calcGapProductRow, calcTotalBaseRow,
|
calcGapProductRow, calcTotalBaseRow,
|
||||||
formatRowLabel,
|
formatRowLabel,
|
||||||
normalizeFilterCondition,
|
normalizeFilterCondition,
|
||||||
withGapRow, withTotalBaseRow
|
withGapRow, withTotalBaseRow, wrapSampleRow
|
||||||
} from "@/lib/lg-dashboard";
|
} from "@/lib/lg-dashboard";
|
||||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||||
import {SelectedMap} from "@/types/common";
|
import {SelectedMap} from "@/types/common";
|
||||||
import {ProductKey, StatisticsRequest} from "@/types/lg";
|
import {ProductKey, StatisticsRequest} from "@/types/lg.types";
|
||||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||||
import {toNumOr0} from "@/lib/utils";
|
import {toNumOr0} from "@/lib/utils";
|
||||||
|
|
||||||
const LGPurchasePage = () => {
|
const LGPurchasePage = () => {
|
||||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||||
|
|
||||||
const req = useMemo<StatisticsRequest>(() => {
|
const req = useMemo<StatisticsRequest>(() => {
|
||||||
return {
|
return {
|
||||||
variableIdMap: {purchase: "KQA3_2", purchase_lg: "KQX3_3_LG"},
|
variableIdMap: {purchase: "KQB0", purchase_lg: "KQX3_3_LG"},
|
||||||
bannerIdList: ["product"],
|
bannerIdList: ["product"],
|
||||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||||
option: {useCache: true, lastYear: false, decimalPoint: 0},
|
option: {useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||||
};
|
};
|
||||||
}, [debouncedFilterValue]);
|
}, [debouncedFilterValue]);
|
||||||
|
|
||||||
@@ -51,11 +55,15 @@ const LGPurchasePage = () => {
|
|||||||
|
|
||||||
const purchaseRows =
|
const purchaseRows =
|
||||||
data?.statisticsDataMap?.purchase
|
data?.statisticsDataMap?.purchase
|
||||||
.filter((r) => r.rowLabel == `해당년도`)
|
.filter((r) => r.rowLabel == `구매`)
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
|
const rowSample = data?.statisticsDataMap?.purchase
|
||||||
|
.find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: row.year,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
@@ -63,14 +71,18 @@ const LGPurchasePage = () => {
|
|||||||
data?.statisticsDataMap?.purchase_lg
|
data?.statisticsDataMap?.purchase_lg
|
||||||
.filter((row) => row.rowLabel === `구입`)
|
.filter((row) => row.rowLabel === `구입`)
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
|
const rowSample = data?.statisticsDataMap?.purchase_lg
|
||||||
|
.find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: row.year,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const purchaseLGRowsWithGap = useMemo(() => {
|
const purchaseLGRowsWithGap = useMemo(() => {
|
||||||
const withGap = withGapRow(purchaseLGRows, calcGapProductRow);
|
const withGap = withGapRow(wrapSampleRow(purchaseLGRows, false), calcGapProductRow, -1, -2);
|
||||||
return withTotalBaseRow("구입율",purchaseRows, withGap, calcTotalBaseRow);
|
return withTotalBaseRow("구입율",purchaseRows, withGap, calcTotalBaseRow);
|
||||||
}, [purchaseRows, purchaseLGRows]);
|
}, [purchaseRows, purchaseLGRows]);
|
||||||
|
|
||||||
@@ -93,6 +105,7 @@ const LGPurchasePage = () => {
|
|||||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return purchaseLGRowsWithGap.map((row) => ({
|
return purchaseLGRowsWithGap.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
||||||
}));
|
}));
|
||||||
@@ -110,8 +123,8 @@ const LGPurchasePage = () => {
|
|||||||
|
|
||||||
for (let ci = 0; ci < includeProductKeys.length; ci++) {
|
for (let ci = 0; ci < includeProductKeys.length; ci++) {
|
||||||
const k = includeProductKeys[ci];
|
const k = includeProductKeys[ci];
|
||||||
const t = (purchaseRows[ri] as any)[k];
|
const t = (purchaseRows[ri] as any)[k] ?? "";
|
||||||
const v = (r as any)[k];
|
const v = (r as any)[k] ?? "";
|
||||||
|
|
||||||
total[yi][ci] = Number(t);
|
total[yi][ci] = Number(t);
|
||||||
focus[yi][ci] = Number(v);
|
focus[yi][ci] = Number(v);
|
||||||
@@ -132,15 +145,16 @@ const LGPurchasePage = () => {
|
|||||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||||
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>" +
|
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>" +
|
||||||
"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
//"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
||||||
"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
//"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
||||||
"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.<br/>" +
|
//"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.<br/>" +
|
||||||
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?<br/>" +
|
||||||
|
"** 조사 년도 구매율 중 자사제품 비율 = (LG 구매율 ÷ 전체 구매율) × 100";
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const excelHeader = buildHeader_ProductKeyMap(productKeyMap);
|
const excelHeader = buildHeader_ProductKeyMap(productKeyMap, "sample");
|
||||||
|
|
||||||
await exportDashboardExcel({
|
await exportDashboardExcel({
|
||||||
fileName: `${SITE_TITLE}(LG제품 구매율).xlsx`,
|
fileName: `${SITE_TITLE}(LG제품 구매율).xlsx`,
|
||||||
@@ -162,6 +176,7 @@ const LGPurchasePage = () => {
|
|||||||
chart={
|
chart={
|
||||||
<GroupedOverlayBar
|
<GroupedOverlayBar
|
||||||
data={purchaseChartData}
|
data={purchaseChartData}
|
||||||
|
questionText={"구매율"}
|
||||||
yearTotalColor={CHART_COLOR_BY_YEAR}
|
yearTotalColor={CHART_COLOR_BY_YEAR}
|
||||||
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
||||||
showFocusLabel={"last"}
|
showFocusLabel={"last"}
|
||||||
@@ -176,4 +191,4 @@ const LGPurchasePage = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LGPurchasePage;
|
export default LGPurchasePage;
|
||||||
|
|||||||
@@ -14,42 +14,37 @@ import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
BRAND_LIST,
|
BRAND_LIST,
|
||||||
PRODUCT_KEYS,
|
|
||||||
PRODUCTS,
|
|
||||||
YEARS,
|
YEARS,
|
||||||
AXIS_HIDE_STYLE,
|
SITE_TITLE,
|
||||||
GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, SITE_TITLE
|
USE_CACHE,
|
||||||
} from "@/const/lgConst";
|
API_DECIMAL_POINT,
|
||||||
|
} from "@/const/lg-common.const";
|
||||||
|
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
|
import { PRODUCT_KEYS, PRODUCTS } from "@/const/lg-product.const";
|
||||||
|
import { AXIS_HIDE_STYLE, GRID_X_NOT_PADDING } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import {
|
import {
|
||||||
calcCagrRow, calcGapProductRow,
|
calcCagrRow, calcGapProductRow,
|
||||||
formatRowLabel,
|
formatRowLabel,
|
||||||
normalizeFilterCondition, withCagrRow, withGapRow
|
normalizeFilterCondition, withCagrRow, withGapRow, wrapSampleRow
|
||||||
} from "@/lib/lg-dashboard";
|
} from "@/lib/lg-dashboard";
|
||||||
import {buildHeader_ProductKeyMap, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
import {buildHeader_ProductKeyMap, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||||
import {StatisticsRequest} from "@/types/lg";
|
import {StatisticsRequest} from "@/types/lg.types";
|
||||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||||
import {toNumOr0} from "@/lib/utils";
|
import {toNumOr0} from "@/lib/utils";
|
||||||
import {SelectedMap} from "@/types/common";
|
import {SelectedMap} from "@/types/common";
|
||||||
|
|
||||||
const PenetrationPage = () => {
|
const PenetrationPage = () => {
|
||||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||||
const [isBrandShare, setIsBrandShare] = useState(false);
|
const [isBrandShare, setIsBrandShare] = useState(false);
|
||||||
|
|
||||||
const chartColorByYear = Object.fromEntries(
|
|
||||||
YEARS.map((year, i) => [
|
|
||||||
year,
|
|
||||||
[`--chart-cbrand-${i + 1}`,`--chart-samsung-${i + 1}`,`--chart-lg-${i + 1}`],
|
|
||||||
])
|
|
||||||
) as Record<(typeof YEARS)[number], string[]>;
|
|
||||||
|
|
||||||
const req = useMemo<StatisticsRequest>(() => {
|
const req = useMemo<StatisticsRequest>(() => {
|
||||||
return {
|
return {
|
||||||
variableIdMap: { penetration: "KQA1", penetration_brand: "KQA3_3_NET" },
|
variableIdMap: { penetration: "KQA1", penetration_brand: "KQA3_3_NET" },
|
||||||
bannerIdList: ["product"],
|
bannerIdList: ["product"],
|
||||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||||
};
|
};
|
||||||
}, [debouncedFilterValue]);
|
}, [debouncedFilterValue]);
|
||||||
|
|
||||||
@@ -63,24 +58,46 @@ const PenetrationPage = () => {
|
|||||||
data?.statisticsDataMap?.penetration
|
data?.statisticsDataMap?.penetration
|
||||||
.filter((r) => r.rowLabel == `보유`)
|
.filter((r) => r.rowLabel == `보유`)
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
|
const rowSample = data?.statisticsDataMap?.penetration
|
||||||
|
.find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: row.year,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const penetrationBrandRows =
|
const penetrationBrandRows = (
|
||||||
data?.statisticsDataMap?.penetration_brand
|
data?.statisticsDataMap?.penetration_brand
|
||||||
.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? [];
|
?.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? []
|
||||||
|
).map((row) => {
|
||||||
|
PRODUCT_KEYS.forEach((k) => {
|
||||||
|
(row as any)[k] = Number((row as any)[k]).toFixed(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
return row;
|
||||||
|
});
|
||||||
|
|
||||||
const penetrationRowsWithGapCagr = useMemo(() => {
|
const penetrationRowsWithGapCagr = useMemo(() => {
|
||||||
const withGap = withGapRow(penetrationRows, calcGapProductRow);
|
const withGap = withGapRow(penetrationRows, calcGapProductRow, -1, -2);
|
||||||
return withCagrRow(withGap, calcCagrRow);
|
const withCagr = withCagrRow(withGap, calcCagrRow, -1, 1);
|
||||||
|
|
||||||
|
withCagr.forEach((row) => {
|
||||||
|
if (row.rowLabel !== "CAGR") {
|
||||||
|
PRODUCT_KEYS.forEach((k) => {
|
||||||
|
(row as any)[k] = Number((row as any)[k]).toFixed(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return wrapSampleRow(withCagr, false);
|
||||||
}, [penetrationRows]);
|
}, [penetrationRows]);
|
||||||
|
|
||||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return penetrationRowsWithGapCagr.map((row) => ({
|
return penetrationRowsWithGapCagr.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||||
}))
|
}))
|
||||||
@@ -131,7 +148,8 @@ const PenetrationPage = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP, "sample");
|
||||||
|
const brandHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||||
type AnyRow = Record<string, any>;
|
type AnyRow = Record<string, any>;
|
||||||
|
|
||||||
const sections: Section<AnyRow>[] = [
|
const sections: Section<AnyRow>[] = [
|
||||||
@@ -139,7 +157,7 @@ const PenetrationPage = () => {
|
|||||||
...YEARS.map((year) => (
|
...YEARS.map((year) => (
|
||||||
{
|
{
|
||||||
title: `브랜드 별 점유율_${year}년`,
|
title: `브랜드 별 점유율_${year}년`,
|
||||||
header: excelHeader,
|
header: brandHeader,
|
||||||
rows: penetrationBrandRows.filter((row) => row.year === year),
|
rows: penetrationBrandRows.filter((row) => row.year === year),
|
||||||
rowGap: 1,
|
rowGap: 1,
|
||||||
}
|
}
|
||||||
@@ -153,7 +171,7 @@ const PenetrationPage = () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
return () => registerExcelExporter(null);
|
return () => registerExcelExporter(null);
|
||||||
}, [registerExcelExporter, penetrationRows, penetrationBrandRows]);
|
}, [registerExcelExporter, penetrationRowsWithGapCagr, penetrationBrandRows]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -163,23 +181,23 @@ const PenetrationPage = () => {
|
|||||||
variant={isBrandShare ? "default" : "secondary"}
|
variant={isBrandShare ? "default" : "secondary"}
|
||||||
onClick={() => setIsBrandShare((v) => !v)}
|
onClick={() => setIsBrandShare((v) => !v)}
|
||||||
>
|
>
|
||||||
{"브랜드별 점유율"}
|
{"브랜드 점유율 변화"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TopChartTable
|
<TopChartTable
|
||||||
title={isBrandShare ? "브랜드별 점유율" : "전체 보급률"}
|
title={isBrandShare ? "브랜드 점유율 변화" : "전체 보급률"}
|
||||||
categories={[...PRODUCTS]}
|
categories={[...PRODUCTS]}
|
||||||
rows={productTableRows}
|
rows={productTableRows}
|
||||||
chart={
|
chart={
|
||||||
isBrandShare ? (
|
isBrandShare ? (
|
||||||
<GroupedStackBar
|
<GroupedStackBar
|
||||||
data={brandShareChartData}
|
data={brandShareChartData}
|
||||||
grid={{ ...GRID_X_NOT_PADDING, top: 60 }}
|
grid={{...GRID_X_NOT_PADDING, bottom: 20}}
|
||||||
xAxis={{ type: "category", data: PRODUCTS, ...AXIS_HIDE_STYLE }}
|
xAxis={{ type: "category", data: PRODUCTS, ...AXIS_HIDE_STYLE }}
|
||||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
||||||
showFocusLabel={"none"}
|
showFocusLabel={"none"}
|
||||||
yearBrandPalette={chartColorByYear}
|
yearBrandPalette={[ "--chart-etc", "--chart-cbrand","--chart-samsung","--chart-lg"]}
|
||||||
height={260}
|
height={260}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -197,9 +215,10 @@ const PenetrationPage = () => {
|
|||||||
signStyle={signStyleGapRow}
|
signStyle={signStyleGapRow}
|
||||||
fillCAGR={true}
|
fillCAGR={true}
|
||||||
/>
|
/>
|
||||||
|
<BottomDescription description={"CAGR(%) 5%p 이상 품목에 대해 음영 표시"} />
|
||||||
<BottomDescription description={description} />
|
<BottomDescription description={description} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PenetrationPage;
|
export default PenetrationPage;
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ import {useEffect, useMemo} from "react";
|
|||||||
import {
|
import {
|
||||||
PRODUCT_KEYS,
|
PRODUCT_KEYS,
|
||||||
PRODUCTS,
|
PRODUCTS,
|
||||||
AXIS_HIDE_STYLE,
|
} from "@/const/lg-product.const";
|
||||||
GRID_X_NOT_PADDING,
|
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
PRODUCT_KEY_MAP,
|
import {
|
||||||
SITE_TITLE
|
SITE_TITLE,
|
||||||
} from "@/const/lgConst";
|
USE_CACHE,
|
||||||
|
API_DECIMAL_POINT,
|
||||||
|
} from "@/const/lg-common.const";
|
||||||
|
import { AXIS_HIDE_STYLE, GRID_X_NOT_PADDING } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import {
|
import {
|
||||||
BottomDescription,
|
BottomDescription,
|
||||||
type ChartData,
|
type ChartData,
|
||||||
@@ -18,23 +21,29 @@ import {
|
|||||||
VerticalBar,
|
VerticalBar,
|
||||||
} from "@/components/lge-dashboard";
|
} from "@/components/lge-dashboard";
|
||||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||||
import {calcGapProductRow, formatRowLabel, normalizeFilterCondition, withGapRow} from "@/lib/lg-dashboard";
|
import {
|
||||||
|
calcGapProductRow,
|
||||||
|
formatRowLabel,
|
||||||
|
normalizeFilterCondition,
|
||||||
|
withGapRow,
|
||||||
|
wrapSampleRow
|
||||||
|
} from "@/lib/lg-dashboard";
|
||||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||||
import {SelectedMap} from "@/types/common";
|
import {SelectedMap} from "@/types/common";
|
||||||
import {StatisticsRequest} from "@/types/lg";
|
import {StatisticsRequest} from "@/types/lg.types";
|
||||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||||
|
|
||||||
const PurchasePage = () => {
|
const PurchasePage = () => {
|
||||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap);
|
||||||
|
|
||||||
const req = useMemo<StatisticsRequest>(() => {
|
const req = useMemo<StatisticsRequest>(() => {
|
||||||
return {
|
return {
|
||||||
variableIdMap: { purchase: "KQA3_2"},
|
variableIdMap: { purchase: "KQB0"},
|
||||||
bannerIdList: ["product"],
|
bannerIdList: ["product"],
|
||||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||||
};
|
};
|
||||||
}, [debouncedFilterValue]);
|
}, [debouncedFilterValue]);
|
||||||
|
|
||||||
@@ -46,21 +55,26 @@ const PurchasePage = () => {
|
|||||||
|
|
||||||
const purchaseRows =
|
const purchaseRows =
|
||||||
data?.statisticsDataMap?.purchase
|
data?.statisticsDataMap?.purchase
|
||||||
.filter((r) => r.rowLabel == `해당년도`)
|
.filter((r) => r.rowLabel == `구매`)
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
|
const rowSample = data?.statisticsDataMap?.purchase
|
||||||
|
.find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: row.year,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const purchaseRowsWithGap = useMemo(() => {
|
const purchaseRowsWithGap = useMemo(() => {
|
||||||
return withGapRow(purchaseRows, calcGapProductRow);
|
return withGapRow(wrapSampleRow(purchaseRows, false), calcGapProductRow, -1, -2);
|
||||||
}, [purchaseRows]);
|
}, [purchaseRows]);
|
||||||
|
|
||||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return purchaseRowsWithGap.map((row) => ({
|
return purchaseRowsWithGap.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||||
}));
|
}));
|
||||||
@@ -69,7 +83,7 @@ const PurchasePage = () => {
|
|||||||
const purchaseChartData = useMemo<ChartData>(() => {
|
const purchaseChartData = useMemo<ChartData>(() => {
|
||||||
return {
|
return {
|
||||||
categories: [...PRODUCTS],
|
categories: [...PRODUCTS],
|
||||||
series: purchaseRows
|
series: purchaseRows.filter((r) => !r.rowLabel.includes("사례수"))
|
||||||
.map((r) => ({
|
.map((r) => ({
|
||||||
name: r.rowLabel,
|
name: r.rowLabel,
|
||||||
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
||||||
@@ -80,15 +94,17 @@ const PurchasePage = () => {
|
|||||||
const description = useMemo(() => {
|
const description = useMemo(() => {
|
||||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||||
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>" +
|
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>";
|
||||||
|
/*
|
||||||
"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
||||||
"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
||||||
"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.";
|
"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.";
|
||||||
|
*/
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP, "sample");
|
||||||
|
|
||||||
await exportDashboardExcel({
|
await exportDashboardExcel({
|
||||||
fileName: `${SITE_TITLE}(구매율).xlsx`,
|
fileName: `${SITE_TITLE}(구매율).xlsx`,
|
||||||
@@ -113,7 +129,7 @@ const PurchasePage = () => {
|
|||||||
paletteVarNames={["--chart-3", "--chart-2", "--chart-1"]}
|
paletteVarNames={["--chart-3", "--chart-2", "--chart-1"]}
|
||||||
grid={GRID_X_NOT_PADDING}
|
grid={GRID_X_NOT_PADDING}
|
||||||
xAxis={{ type: "category", data: [...PRODUCTS], ...AXIS_HIDE_STYLE }}
|
xAxis={{ type: "category", data: [...PRODUCTS], ...AXIS_HIDE_STYLE }}
|
||||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
yAxis={{ type: "value", min:0, max:100, ...AXIS_HIDE_STYLE }}
|
||||||
showFocusLabel={"last"}
|
showFocusLabel={"last"}
|
||||||
height={260}
|
height={260}
|
||||||
/>
|
/>
|
||||||
@@ -126,4 +142,4 @@ const PurchasePage = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PurchasePage;
|
export default PurchasePage;
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
import {createBackApi} from "@/lib/server-api";
|
import {createBackApi} from "@/lib/server-api";
|
||||||
import {LoginRequest, LoginUser} from "@/types/auth";
|
import {LoginRequest, LoginResponse, LoginUser} from "@/types/auth";
|
||||||
import {NextRequest, NextResponse} from "next/server";
|
import {NextRequest, NextResponse} from "next/server";
|
||||||
import {serverEnv} from "@/lib/env.server";
|
import {serverEnv} from "@/lib/env.server";
|
||||||
import {errorToResponse} from "@/lib/http-util";
|
import {errorToResponse} from "@/lib/http-util";
|
||||||
|
|
||||||
type LoginResponse = {
|
|
||||||
accessToken: string;
|
|
||||||
user: LoginUser;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const POST = async (req: NextRequest) => {
|
export const POST = async (req: NextRequest) => {
|
||||||
try {
|
try {
|
||||||
const backApi = await createBackApi();
|
const backApi = await createBackApi();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {NextRequest, NextResponse} from "next/server";
|
|||||||
import {RouteContext} from "@/types/common";
|
import {RouteContext} from "@/types/common";
|
||||||
import {errorToResponse} from "@/lib/http-util";
|
import {errorToResponse} from "@/lib/http-util";
|
||||||
import {createBackApi} from "@/lib/server-api";
|
import {createBackApi} from "@/lib/server-api";
|
||||||
import {ProductResponse, BannerResponse} from "@/types/lg";
|
import {ProductResponse, BannerResponse} from "@/types/lg.types";
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
@@ -36,4 +36,4 @@ export async function POST(
|
|||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return errorToResponse(error);
|
return errorToResponse(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,17 +54,6 @@
|
|||||||
--color-warning: var(--warning);
|
--color-warning: var(--warning);
|
||||||
--color-info: var(--info);
|
--color-info: var(--info);
|
||||||
|
|
||||||
/* Chart */
|
|
||||||
--color-chart-1: var(--chart-1);
|
|
||||||
--color-chart-2: var(--chart-2);
|
|
||||||
--color-chart-3: var(--chart-3);
|
|
||||||
--color-chart-4: var(--chart-4);
|
|
||||||
--color-chart-5: var(--chart-5);
|
|
||||||
--color-chart-6: var(--chart-6);
|
|
||||||
--color-chart-7: var(--chart-7);
|
|
||||||
--color-chart-8: var(--chart-8);
|
|
||||||
--color-chart-9: var(--chart-9);
|
|
||||||
--color-chart-10: var(--chart-10);
|
|
||||||
--color-chart-border: var(--chart-border);
|
--color-chart-border: var(--chart-border);
|
||||||
|
|
||||||
/* Sidebar (shadcn sidebar 토큰) */
|
/* Sidebar (shadcn sidebar 토큰) */
|
||||||
@@ -108,6 +97,8 @@
|
|||||||
--lg-gray-400: 0 0% 50%; /* #7F7F7F */
|
--lg-gray-400: 0 0% 50%; /* #7F7F7F */
|
||||||
--lg-gray-300: 0 0% 75%; /* #BFBFBF */
|
--lg-gray-300: 0 0% 75%; /* #BFBFBF */
|
||||||
--lg-gray-200: 0 0% 85%; /* #D9D9D9 */
|
--lg-gray-200: 0 0% 85%; /* #D9D9D9 */
|
||||||
|
--lg-gray-100: 0 0% 92%; /* #EBEBEB */
|
||||||
|
--lg-gray-50: 0 0% 96%; /* #F5F5F5 */
|
||||||
|
|
||||||
--lg-red-600: 341.1 100% 32.4%; /* #A50034 */
|
--lg-red-600: 341.1 100% 32.4%; /* #A50034 */
|
||||||
--lg-red-500: 341.1 95% 44.0%; /* #DB0649 */
|
--lg-red-500: 341.1 95% 44.0%; /* #DB0649 */
|
||||||
@@ -134,11 +125,6 @@
|
|||||||
--lg-orange-500: 29.6 95% 56.0%;
|
--lg-orange-500: 29.6 95% 56.0%;
|
||||||
--lg-orange-400: 29.6 85% 68.0%;
|
--lg-orange-400: 29.6 85% 68.0%;
|
||||||
--lg-orange-300: 29.6 75% 78.0%;
|
--lg-orange-300: 29.6 75% 78.0%;
|
||||||
|
|
||||||
--samsung-blue-600: 218.93 53.91% 52.35%; /* #4472C7 */
|
|
||||||
--samsung-blue-500: 218.93 48.0% 56.0%; /* #597FC5 */
|
|
||||||
--samsung-blue-400: 218.93 40.0% 66.0%; /* #869ECB */
|
|
||||||
--samsung-blue-300: 218.93 33.0% 76.0%; /* #AEBCD6 */
|
|
||||||
/* =============================
|
/* =============================
|
||||||
Brand Core
|
Brand Core
|
||||||
(semantic은 "실제 색"으로 정의)
|
(semantic은 "실제 색"으로 정의)
|
||||||
@@ -183,26 +169,25 @@
|
|||||||
--chart-2-t: 0 0% 70%;
|
--chart-2-t: 0 0% 70%;
|
||||||
--chart-3-t: 0 0% 88%;
|
--chart-3-t: 0 0% 88%;
|
||||||
|
|
||||||
--chart-4: var(--lg-pink-400);
|
--chart-stack-1: 335 64% 34%;
|
||||||
--chart-5: var(--lg-pink-600);
|
--chart-stack-2: 332 65% 57%;
|
||||||
--chart-6: var(--lg-gray-500);
|
--chart-stack-3: 334 66% 73%;
|
||||||
--chart-7: var(--lg-gray-600);
|
--chart-stack-4: 334 28% 49%;
|
||||||
--chart-8: var(--lg-gray-700);
|
--chart-stack-5: 340 25% 58%;
|
||||||
--chart-9: var(--lg-gray-800);
|
--chart-stack-6: 0 28% 69%;
|
||||||
--chart-10: var(--lg-gray-900);
|
--chart-stack-7: 26 37% 70%;
|
||||||
|
--chart-stack-8: 27 38% 83%;
|
||||||
|
--chart-stack-9: 30 45% 91%;
|
||||||
|
--chart-stack-10: 0 0% 50%;
|
||||||
|
--chart-stack-11: 0 0% 60%;
|
||||||
|
--chart-stack-12: 0 0% 71%;
|
||||||
|
--chart-stack-13: 0 0% 82%;
|
||||||
|
--chart-stack-14: 0 0% 91%;
|
||||||
|
|
||||||
--chart-lg-1: var(--lg-pink-300);
|
--chart-lg: var(--chart-1);
|
||||||
--chart-lg-2: var(--lg-red-300);
|
--chart-samsung: 218 48% 58%;
|
||||||
--chart-lg-3: var(--lg-red-600);
|
--chart-cbrand: var(--chart-2);
|
||||||
--chart-total-1: var(--lg-gray-300);
|
--chart-etc: 0 0% 74%;
|
||||||
--chart-total-2: var(--lg-gray-400);
|
|
||||||
--chart-total-3: var(--lg-gray-700);
|
|
||||||
--chart-cbrand-1: var(--lg-gray-300);
|
|
||||||
--chart-cbrand-2: var(--lg-gray-400);
|
|
||||||
--chart-cbrand-3: var(--lg-gray-700);
|
|
||||||
--chart-samsung-1: var(--samsung-blue-400);
|
|
||||||
--chart-samsung-2: var(--samsung-blue-500);
|
|
||||||
--chart-samsung-3: var(--samsung-blue-600);
|
|
||||||
|
|
||||||
--chart-border: hsl(0 0% 95%);
|
--chart-border: hsl(0 0% 95%);
|
||||||
|
|
||||||
@@ -323,6 +308,8 @@
|
|||||||
.bg-gray-400 { background-color: hsl(var(--lg-gray-400)) !important; }
|
.bg-gray-400 { background-color: hsl(var(--lg-gray-400)) !important; }
|
||||||
.bg-gray-300 { background-color: hsl(var(--lg-gray-300)) !important; }
|
.bg-gray-300 { background-color: hsl(var(--lg-gray-300)) !important; }
|
||||||
.bg-gray-200 { background-color: hsl(var(--lg-gray-200)) !important; }
|
.bg-gray-200 { background-color: hsl(var(--lg-gray-200)) !important; }
|
||||||
|
.bg-gray-100 { background-color: hsl(var(--lg-gray-100)) !important; }
|
||||||
|
.bg-gray-50 { background-color: hsl(var(--lg-gray-50)) !important; }
|
||||||
|
|
||||||
.border-gray-900 { border-color: hsl(var(--lg-gray-900)) !important; }
|
.border-gray-900 { border-color: hsl(var(--lg-gray-900)) !important; }
|
||||||
.border-gray-800 { border-color: hsl(var(--lg-gray-800)) !important; }
|
.border-gray-800 { border-color: hsl(var(--lg-gray-800)) !important; }
|
||||||
@@ -332,6 +319,8 @@
|
|||||||
.border-gray-400 { border-color: hsl(var(--lg-gray-400)) !important; }
|
.border-gray-400 { border-color: hsl(var(--lg-gray-400)) !important; }
|
||||||
.border-gray-300 { border-color: hsl(var(--lg-gray-300)) !important; }
|
.border-gray-300 { border-color: hsl(var(--lg-gray-300)) !important; }
|
||||||
.border-gray-200 { border-color: hsl(var(--lg-gray-200)) !important; }
|
.border-gray-200 { border-color: hsl(var(--lg-gray-200)) !important; }
|
||||||
|
.border-gray-100 { border-color: hsl(var(--lg-gray-100)) !important; }
|
||||||
|
.border-gray-50 { border-color: hsl(var(--lg-gray-50)) !important; }
|
||||||
|
|
||||||
/* LG Red/Pink/Purple/Orange scale overrides */
|
/* LG Red/Pink/Purple/Orange scale overrides */
|
||||||
.bg-red-600 { background-color: hsl(var(--lg-red-600)) !important; }
|
.bg-red-600 { background-color: hsl(var(--lg-red-600)) !important; }
|
||||||
@@ -477,13 +466,25 @@
|
|||||||
word-break: auto-phrase;
|
word-break: auto-phrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lg-table th.lg-table__no-border-r,
|
||||||
|
.lg-table td.lg-table__no-border-r {
|
||||||
|
border-right: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lg-table th.lg-table__no-border-l,
|
||||||
|
.lg-table td.lg-table__no-border-l {
|
||||||
|
border-left: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
.lg-table thead tr.lg-table__group th {
|
.lg-table thead tr.lg-table__group th {
|
||||||
background: hsl(var(--lg-gray-400));
|
background: hsl(var(--lg-gray-400));
|
||||||
|
white-space: pre-wrap;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
.lg-table thead tr.lg-table__subhead th {
|
.lg-table thead tr.lg-table__subhead th {
|
||||||
background: hsl(var(--lg-gray-600));
|
background: hsl(var(--lg-gray-600));
|
||||||
|
white-space: pre-wrap;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
|
import { Loader2Icon } from "lucide-react";
|
||||||
import { loadingAtom } from "@/store/jotai/loading";
|
import { loadingAtom } from "@/store/jotai/loading";
|
||||||
|
|
||||||
export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
||||||
@@ -9,9 +10,11 @@ export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
|||||||
if (!force && !isLoading) return null;
|
if (!force && !isLoading) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-[9999] bg-black/70 flex items-center justify-center">
|
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/65">
|
||||||
{/* 심플 로딩 인디케이터 */}
|
<div className="flex flex-col items-center gap-3">
|
||||||
<div className="h-12 w-12 rounded-full border-4 border-gray-400 border-t-white animate-spin" />
|
<Loader2Icon className="size-20 animate-spin text-white" style={{ animationDuration: "0.7s" }} />
|
||||||
|
<div className="text-sm font-medium tracking-[0.18em] text-white/90">Loading</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,15 @@
|
|||||||
import {
|
import {
|
||||||
CategoryTargetType,
|
CategoryTargetType,
|
||||||
TargetChild,
|
TargetChild,
|
||||||
} from "@/config/filter.types";
|
} from "@/types/filter.types";
|
||||||
import {categoryTarget, categoryTargetType} from "@/config/filter.data";
|
import {categoryTarget, categoryTargetType} from "@/const/filter.const";
|
||||||
import { ChevronRight } from "lucide-react";
|
import { ChevronRight } from "lucide-react";
|
||||||
import {useCallback, useMemo} from "react";
|
import {useCallback, useMemo} from "react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {ProductKey, ProductsFilterItem} from "@/types/lg";
|
import {ProductKey, ProductsFilterItem} from "@/types/lg.types";
|
||||||
import {PRODUCT_KEY_MAP, YEARS} from "@/const/lgConst";
|
import {PRODUCT_KEY_MAP} from "@/const/lg-schema.const";
|
||||||
|
import {YEARS} from "@/const/lg-common.const";
|
||||||
|
|
||||||
export type CategoryTypeValue = {
|
export type CategoryTypeValue = {
|
||||||
label: string;
|
label: string;
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import {useAuth} from "@/hooks/useAuth";
|
|||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {LoginUser} from "@/types/auth";
|
import {LoginUser} from "@/types/auth";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import {topMenus} from "@/config/menu.data";
|
import {topMenus} from "@/const/menu.const";
|
||||||
import {Button} from "@/components/ui/button";
|
import {Button} from "@/components/ui/button";
|
||||||
import {LogOut} from "lucide-react";
|
import {LogOut} from "lucide-react";
|
||||||
import {cn} from "@/lib/utils";
|
import {cn} from "@/lib/utils";
|
||||||
import {SITE_TITLE} from "@/const/lgConst";
|
import {SITE_TITLE} from "@/const/lg-common.const";
|
||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
activeTopId: string;
|
activeTopId: string;
|
||||||
@@ -89,4 +89,4 @@ const Header = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Header;
|
export default Header;
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {ReactNode, useEffect, useRef, useState} from "react";
|
import {ReactNode, useEffect, useMemo, useRef, useState} from "react";
|
||||||
import {usePathname, useRouter} from "next/navigation";
|
import {usePathname, useRouter} from "next/navigation";
|
||||||
import {cn} from "@/lib/utils";
|
import {cn} from "@/lib/utils";
|
||||||
import {SelectedMap} from "@/types/common";
|
import {SelectedMap} from "@/types/common";
|
||||||
import {topMenus, totalSubMenus, categorySubMenus} from "@/config/menu.data";
|
import {topMenus, totalSubMenus, categorySubMenus} from "@/const/menu.const";
|
||||||
import {categoryTarget, totalFilters} from "@/config/filter.data";
|
import {categoryTarget, totalFilters} from "@/const/filter.const";
|
||||||
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
|
import {CategoryTargetData, CategoryTargetType} from "@/types/filter.types";
|
||||||
import Header from "./Header";
|
import Header from "./Header";
|
||||||
import SubMenu from "./SubMenu";
|
import SubMenu from "./SubMenu";
|
||||||
import TotalFilter from "./TotalFilter";
|
import TotalFilter from "./TotalFilter";
|
||||||
import CategoryFilter, {CategoryFilterValue} from "./CategoryFilter";
|
import CategoryFilter, {CategoryFilterValue} from "./CategoryFilter";
|
||||||
import ExcelDownloadButton from "./ExcelDownloadButton";
|
import ExcelDownloadButton from "./ExcelDownloadButton";
|
||||||
import {LayoutFilterProvider} from "./LayoutFilterContext";
|
import {LayoutFilterProvider} from "./LayoutFilterContext";
|
||||||
import {LAST_YEAR, PRODUCTS_FILTER_ITEM} from "@/const/lgConst";
|
import {LAST_YEAR} from "@/const/lg-common.const";
|
||||||
import {ProductsFilterItem} from "@/types/lg";
|
import {PRODUCTS_FILTER_ITEM} from "@/const/lg-product.const";
|
||||||
|
import {ProductsFilterItem} from "@/types/lg.types";
|
||||||
import {ArrowUp, Filter} from "lucide-react";
|
import {ArrowUp, Filter} from "lucide-react";
|
||||||
|
import {Button} from "@/components/ui/button";
|
||||||
|
|
||||||
type MainLayoutProps = {
|
type MainLayoutProps = {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -26,7 +28,9 @@ const buildDefaultTotalValue = (): SelectedMap => {
|
|||||||
totalFilters.forEach((f) => {
|
totalFilters.forEach((f) => {
|
||||||
// "전체"가 있으면 그 value, 없으면 첫 번째 값
|
// "전체"가 있으면 그 value, 없으면 첫 번째 값
|
||||||
const all = f.children.find((c) => c.label === "전체");
|
const all = f.children.find((c) => c.label === "전체");
|
||||||
init[f.variable] = all?.value ?? f.children[0]?.value ?? "";
|
const initValue = all?.value ?? f.children[0]?.value ?? "";
|
||||||
|
|
||||||
|
init[f.variable] = [initValue];
|
||||||
});
|
});
|
||||||
return init;
|
return init;
|
||||||
};
|
};
|
||||||
@@ -46,9 +50,18 @@ const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterItem): Cat
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buildTotalPartDescription = (pathname:string) => {
|
const buildTotalPartDescription = (pathname:string) => {
|
||||||
return pathname.match("penetration")
|
switch(pathname) {
|
||||||
? "■ 보급률: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>보유하고 있는 비율</strong>"
|
case "/total/penetration":
|
||||||
: "■ 구매율: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>구매한 비율</strong>";
|
return "■ 보급률: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>보유하고 있는 비율</strong>";
|
||||||
|
case "/total/lg-penetration":
|
||||||
|
return "■ 보급률: 전체 소비자 중, 조사 년도에 LG 제품을 <strong>보유하고 있는 비율</strong>";
|
||||||
|
case "/total/purchase":
|
||||||
|
return "■ 구매율: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>구매한 비율</strong>";
|
||||||
|
case "/total/lg-purchase":
|
||||||
|
return "■ 구매율: 전체 소비자 중, 조사 년도에 LG 제품을 <strong>구매한 비율</strong>";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MainLayout = ({ children }: MainLayoutProps) => {
|
const MainLayout = ({ children }: MainLayoutProps) => {
|
||||||
@@ -94,6 +107,21 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isDefaultTotalFilter = useMemo(() => {
|
||||||
|
if(!isTotal) return false;
|
||||||
|
|
||||||
|
return Object.values(totalValue).every(value => value.length === 1 && value[0] === "0");
|
||||||
|
},[isTotal, totalValue])
|
||||||
|
|
||||||
|
const setDefaultTotalFilter = () => {
|
||||||
|
if(isTotal && !isDefaultTotalFilter){
|
||||||
|
setTotalValue(prev =>
|
||||||
|
Object.fromEntries(
|
||||||
|
Object.keys(prev).map(key => [key, ["0"]])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const prevIsTotal = prevIsTotalRef.current;
|
const prevIsTotal = prevIsTotalRef.current;
|
||||||
@@ -152,8 +180,17 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
필터 <span className="text-sm leading-none mb-1">{isFilterOpen ? "▲" : "▼"}</span>
|
필터 <span className="text-sm leading-none mb-1">{isFilterOpen ? "▲" : "▼"}</span>
|
||||||
</button>
|
</button>
|
||||||
{isTotal && (
|
{isTotal && (
|
||||||
<div className={"ml-5 content-text-sm"} dangerouslySetInnerHTML={{__html: totalPartDescription}}>
|
<>
|
||||||
</div>
|
<Button
|
||||||
|
variant={isDefaultTotalFilter ? "secondary" : "default"}
|
||||||
|
onClick={setDefaultTotalFilter}
|
||||||
|
className="h-6 rounded-sm px-3 ml-3 text-sm font-semibold content-text-sm"
|
||||||
|
>
|
||||||
|
초기화
|
||||||
|
</Button>
|
||||||
|
<div className={"ml-5 content-text-sm"} dangerouslySetInnerHTML={{__html: totalPartDescription}}>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ExcelDownloadButton/>
|
<ExcelDownloadButton/>
|
||||||
@@ -204,4 +241,4 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MainLayout;
|
export default MainLayout;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {SubMenuItem} from "@/config/menu.types";
|
import {SubMenuItem} from "@/types/menu.types";
|
||||||
import {cn} from "@/lib/utils";
|
import {cn} from "@/lib/utils";
|
||||||
|
|
||||||
interface SubMenuProps {
|
interface SubMenuProps {
|
||||||
@@ -45,4 +45,4 @@ const SubMenu = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SubMenu;
|
export default SubMenu;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {TotalFilterItem} from "@/config/filter.types";
|
import {TotalFilterItem} from "@/types/filter.types";
|
||||||
import {SelectedMap} from "@/types/common";
|
import {SelectedMap} from "@/types/common";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
import {cn} from "@/lib/utils";
|
import {cn} from "@/lib/utils";
|
||||||
@@ -20,9 +20,32 @@ const TotalFilter = ({
|
|||||||
className
|
className
|
||||||
}: TotalFilterProps) => {
|
}: TotalFilterProps) => {
|
||||||
|
|
||||||
const handlePick = (variable: string, v: string) => {
|
const getSelectableCount = (variable: string) =>
|
||||||
if (value[variable] === v) return;
|
filters.find((filter) => filter.variable === variable)?.children
|
||||||
onChange({ ...value, [variable]: v });
|
.filter((child) => child.value !== "0").length ?? 0;
|
||||||
|
|
||||||
|
const handlePick = (variable: string, selectedValue: string) => {
|
||||||
|
if (selectedValue === "0") {
|
||||||
|
onChange({ ...value, [variable]: ["0"] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentValues = value[variable] ?? ["0"];
|
||||||
|
const normalizedValues = currentValues.filter((item) => item !== "0");
|
||||||
|
const selectableCount = getSelectableCount(variable);
|
||||||
|
|
||||||
|
const isAlreadySelected = normalizedValues.includes(selectedValue);
|
||||||
|
|
||||||
|
const nextValues = isAlreadySelected
|
||||||
|
? normalizedValues.filter((item) => item !== selectedValue)
|
||||||
|
: [...normalizedValues, selectedValue].sort((a, b) => Number(a) - Number(b));
|
||||||
|
|
||||||
|
if (nextValues.length === 0 || nextValues.length === selectableCount) {
|
||||||
|
onChange({ ...value, [variable]: ["0"] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange({ ...value, [variable]: nextValues });
|
||||||
};
|
};
|
||||||
|
|
||||||
const arranged = useMemo(() => {
|
const arranged = useMemo(() => {
|
||||||
@@ -74,7 +97,7 @@ const TotalFilter = ({
|
|||||||
{/* 우측 옵션 */}
|
{/* 우측 옵션 */}
|
||||||
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1 px-2 py-2">
|
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1 px-2 py-2">
|
||||||
{row.children.map((c) => {
|
{row.children.map((c) => {
|
||||||
const active = current === c.value;
|
const active = current.includes(c.value);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
@@ -97,4 +120,4 @@ const TotalFilter = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TotalFilter;
|
export default TotalFilter;
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import type { EChartsOption } from "echarts";
|
import type { EChartsOption } from "echarts";
|
||||||
import { CHART_HEIGHTS } from "@/const/chartConst";
|
import { CHART_HEIGHTS } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import {useResizeKey} from "@/hooks/useResize";
|
import {useResizeKey} from "@/hooks/useResize";
|
||||||
|
import { VIEW_DECIMAL_POINT } from "@/const/lg-common.const";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
import {roundNumber} from "@/lib/lg-dashboard";
|
||||||
|
|
||||||
const ReactECharts = dynamic(() => import("echarts-for-react"), { ssr: false });
|
const ReactECharts = dynamic(() => import("echarts-for-react"), { ssr: false });
|
||||||
|
|
||||||
@@ -20,6 +23,42 @@ type BaseEChartProps = {
|
|||||||
onEvents?: Record<string, (params: unknown) => void>;
|
onEvents?: Record<string, (params: unknown) => void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const normalizeDataValue = (value: unknown): unknown => {
|
||||||
|
if (typeof value === "number") {
|
||||||
|
return roundNumber(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.map(normalizeDataValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value && typeof value === "object" && "value" in value) {
|
||||||
|
const item = value as { value: unknown };
|
||||||
|
return {
|
||||||
|
...(value as Record<string, unknown>),
|
||||||
|
value: normalizeDataValue(item.value),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
const normalizeSeries = (series?: EChartsOption["series"]): EChartsOption["series"] => {
|
||||||
|
if (!series) return series;
|
||||||
|
|
||||||
|
const normalizeOne = (s: any) => {
|
||||||
|
if (!s || !("data" in s) || !Array.isArray(s.data)) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...s,
|
||||||
|
data: s.data.map(normalizeDataValue),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return Array.isArray(series) ? series.map(normalizeOne) : normalizeOne(series);
|
||||||
|
};
|
||||||
const BaseEChart = ({
|
const BaseEChart = ({
|
||||||
option,
|
option,
|
||||||
height = CHART_HEIGHTS.DEFAULT,
|
height = CHART_HEIGHTS.DEFAULT,
|
||||||
@@ -32,12 +71,19 @@ const BaseEChart = ({
|
|||||||
}: BaseEChartProps) => {
|
}: BaseEChartProps) => {
|
||||||
const resizeKey = useResizeKey(150);
|
const resizeKey = useResizeKey(150);
|
||||||
|
|
||||||
|
const normalizedOption = useMemo<EChartsOption>(() => {
|
||||||
|
return {
|
||||||
|
...option,
|
||||||
|
series: normalizeSeries(option.series),
|
||||||
|
};
|
||||||
|
}, [option]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className} style={{ display: "flex", flexDirection: "column", height: height }}>
|
<div className={className} style={{ display: "flex", flexDirection: "column", height: height }}>
|
||||||
<div className={contentClassName} style={{ flex: 1, minHeight: 0 }}>
|
<div className={contentClassName} style={{ flex: 1, minHeight: 0 }}>
|
||||||
<ReactECharts
|
<ReactECharts
|
||||||
key={resizeKey}
|
key={resizeKey}
|
||||||
option={option}
|
option={normalizedOption}
|
||||||
className={chartClassName}
|
className={chartClassName}
|
||||||
style={{ width: "100%", height: "100%" }}
|
style={{ width: "100%", height: "100%" }}
|
||||||
notMerge={notMerge}
|
notMerge={notMerge}
|
||||||
@@ -49,4 +95,4 @@ const BaseEChart = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BaseEChart;
|
export default BaseEChart;
|
||||||
|
|||||||
@@ -13,14 +13,13 @@ import BaseEChart from "../BaseEChart";
|
|||||||
import { buildLgPalette } from "../color";
|
import { buildLgPalette } from "../color";
|
||||||
import { GroupedOverlayBarData, ShowLabel} from "../types";
|
import { GroupedOverlayBarData, ShowLabel} from "../types";
|
||||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
import {AXIS_HIDE_STYLE, AXIS_HIDE_Y_STYLE, CHART_HEIGHTS, LEGEND_ITEM_SIZE} from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import { CHART_HEIGHTS, LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
|
||||||
import {makeTotalBasePct} from "@/lib/lg-dashboard";
|
import {makeTotalBasePct} from "@/lib/lg-dashboard";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: GroupedOverlayBarData;
|
data: GroupedOverlayBarData;
|
||||||
height?: number | string;
|
height?: number | string;
|
||||||
|
questionText: string;
|
||||||
tooltip?: TooltipComponentOption;
|
tooltip?: TooltipComponentOption;
|
||||||
grid?: GridComponentOption;
|
grid?: GridComponentOption;
|
||||||
xAxis?: XAXisComponentOption;
|
xAxis?: XAXisComponentOption;
|
||||||
@@ -36,6 +35,7 @@ type Props = {
|
|||||||
|
|
||||||
const GroupedOverlayBar = ({
|
const GroupedOverlayBar = ({
|
||||||
data,
|
data,
|
||||||
|
questionText,
|
||||||
height = CHART_HEIGHTS.DEFAULT,
|
height = CHART_HEIGHTS.DEFAULT,
|
||||||
tooltip,
|
tooltip,
|
||||||
grid,
|
grid,
|
||||||
@@ -60,7 +60,7 @@ const GroupedOverlayBar = ({
|
|||||||
|
|
||||||
const option = useMemo(() => {
|
const option = useMemo(() => {
|
||||||
const defaultGrid: EChartsOption["grid"] = {left: 10, right: 10, top: 40, bottom: 10, containLabel: true};
|
const defaultGrid: EChartsOption["grid"] = {left: 10, right: 10, top: 40, bottom: 10, containLabel: true};
|
||||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_STYLE };
|
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_Y_STYLE };
|
||||||
const expandedCategories: string[] = [];
|
const expandedCategories: string[] = [];
|
||||||
data.categories.forEach((cat, catIdx) => {
|
data.categories.forEach((cat, catIdx) => {
|
||||||
years.forEach(year => {
|
years.forEach(year => {
|
||||||
@@ -204,6 +204,7 @@ const GroupedOverlayBar = ({
|
|||||||
formatter: (params: any) => {
|
formatter: (params: any) => {
|
||||||
const arr = Array.isArray(params) ? params : [params];
|
const arr = Array.isArray(params) ? params : [params];
|
||||||
const header = arr?.[0]?.axisValueLabel ?? "";
|
const header = arr?.[0]?.axisValueLabel ?? "";
|
||||||
|
//header += ` ${questionText}`;
|
||||||
|
|
||||||
// bar만
|
// bar만
|
||||||
const barItems = arr
|
const barItems = arr
|
||||||
@@ -229,8 +230,10 @@ const GroupedOverlayBar = ({
|
|||||||
const t = v.total ?? 0;
|
const t = v.total ?? 0;
|
||||||
const f = v.focus ?? 0;
|
const f = v.focus ?? 0;
|
||||||
const pct = makeTotalBasePct(t, f);
|
const pct = makeTotalBasePct(t, f);
|
||||||
const pctStr = pct > 0 ? ` (${pct}%)` : "";
|
//const pctStr = pct > 0 ? ` (${pct}%)` : "";
|
||||||
return `${totalName} ${t} 중 ${focusName} ${f}${pctStr}`;
|
//return `${totalName} ${t} 중 ${focusName} ${f}${pctStr}`;
|
||||||
|
//return `${totalName} ${t} 중 ${focusName} ${f}`;
|
||||||
|
return `${questionText} ${totalName} ${t} 중 ${focusName} ${f}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return [header, ...lines].join("<br/>");
|
return [header, ...lines].join("<br/>");
|
||||||
@@ -283,4 +286,4 @@ const GroupedOverlayBar = ({
|
|||||||
return <BaseEChart option={option} height={height} onEvents={onEvents} />;
|
return <BaseEChart option={option} height={height} onEvents={onEvents} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GroupedOverlayBar;
|
export default GroupedOverlayBar;
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ import BaseEChart from "../BaseEChart";
|
|||||||
import { GroupedStackBarData, ShowLabel} from "../types";
|
import { GroupedStackBarData, ShowLabel} from "../types";
|
||||||
import { buildLgPalette } from "@/components/lge-dashboard/color";
|
import { buildLgPalette } from "@/components/lge-dashboard/color";
|
||||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
import {AXIS_HIDE_STYLE, AXIS_HIDE_Y_STYLE, LEGEND_ITEM_SIZE} from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import { LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: GroupedStackBarData;
|
data: GroupedStackBarData;
|
||||||
@@ -29,7 +28,7 @@ type Props = {
|
|||||||
showFocusLabel?: ShowLabel;
|
showFocusLabel?: ShowLabel;
|
||||||
|
|
||||||
showYearLegend?: boolean;
|
showYearLegend?: boolean;
|
||||||
yearBrandPalette?: Record<string, string[]>;
|
yearBrandPalette?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const GroupedStackBar = ({
|
const GroupedStackBar = ({
|
||||||
@@ -58,14 +57,12 @@ const GroupedStackBar = ({
|
|||||||
const option = useMemo(() => {
|
const option = useMemo(() => {
|
||||||
const defaultGrid: EChartsOption["grid"] = {left: 10, right: 10, top: 60, bottom: 10, containLabel: true};
|
const defaultGrid: EChartsOption["grid"] = {left: 10, right: 10, top: 60, bottom: 10, containLabel: true};
|
||||||
const defaultXAxis: EChartsOption["xAxis"] = { type: "category", data: data.categories, ...AXIS_HIDE_STYLE };
|
const defaultXAxis: EChartsOption["xAxis"] = { type: "category", data: data.categories, ...AXIS_HIDE_STYLE };
|
||||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_STYLE };
|
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_Y_STYLE };
|
||||||
|
|
||||||
const latestYear = years.at(-1);
|
const latestPalette = buildLgPalette(yearBrandPalette);
|
||||||
console.log(yearBrandPalette, String(latestYear), yearBrandPalette?.[String(latestYear)])
|
|
||||||
const latestPalette = buildLgPalette(yearBrandPalette?.[String(latestYear)]);
|
|
||||||
|
|
||||||
const yearLegendTokens = years.map((y) => {
|
const yearLegendTokens = years.map((y) => {
|
||||||
const tokens = yearBrandPalette?.[String(y)];
|
const tokens = yearBrandPalette;
|
||||||
const last = tokens?.[tokens.length - 1];
|
const last = tokens?.[tokens.length - 1];
|
||||||
return last ?? "--lg-gray-500";
|
return last ?? "--lg-gray-500";
|
||||||
});
|
});
|
||||||
@@ -105,8 +102,9 @@ const GroupedStackBar = ({
|
|||||||
for (let yi = 0; yi < years.length; yi++) {
|
for (let yi = 0; yi < years.length; yi++) {
|
||||||
const year = years[yi];
|
const year = years[yi];
|
||||||
const yearLabel = `${year}년`;
|
const yearLabel = `${year}년`;
|
||||||
|
const viewYearLabel = `'${Number(year)-2000}`;
|
||||||
|
|
||||||
const palette = buildLgPalette(yearBrandPalette?.[String(year)]);
|
const palette = buildLgPalette(yearBrandPalette);
|
||||||
|
|
||||||
for (let bi = 0; bi < brands.length; bi++) {
|
for (let bi = 0; bi < brands.length; bi++) {
|
||||||
const brand = brands[bi];
|
const brand = brands[bi];
|
||||||
@@ -115,6 +113,8 @@ const GroupedStackBar = ({
|
|||||||
const isYearOn = yearSelected[yearLabel];
|
const isYearOn = yearSelected[yearLabel];
|
||||||
const showLabel = getIsShowLabel(showFocusLabel, yi, years.length);
|
const showLabel = getIsShowLabel(showFocusLabel, yi, years.length);
|
||||||
|
|
||||||
|
const isFirstBrand = bi === 0;
|
||||||
|
|
||||||
realSeries.push({
|
realSeries.push({
|
||||||
id: `${year}|${brand}`,
|
id: `${year}|${brand}`,
|
||||||
name: brand,
|
name: brand,
|
||||||
@@ -123,12 +123,20 @@ const GroupedStackBar = ({
|
|||||||
emphasis: { disabled: true },
|
emphasis: { disabled: true },
|
||||||
barMaxWidth: barMaxWidth ?? 42,
|
barMaxWidth: barMaxWidth ?? 42,
|
||||||
itemStyle: { color: palette?.[bi] },
|
itemStyle: { color: palette?.[bi] },
|
||||||
label: showLabel
|
label: isFirstBrand
|
||||||
? ({
|
? {
|
||||||
|
show: true,
|
||||||
|
position: "bottom",
|
||||||
|
formatter: () => viewYearLabel,
|
||||||
|
color: "#666",
|
||||||
|
fontSize: 12,
|
||||||
|
}
|
||||||
|
: showLabel
|
||||||
|
? {
|
||||||
show: true,
|
show: true,
|
||||||
position: "top",
|
position: "top",
|
||||||
formatter: (p: any) => (p?.value ?? "") as any,
|
formatter: (p: any) => (p?.value ?? "") as any,
|
||||||
} as any)
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
data: data.categories.map((_, ci) => (isYearOn ? (row[ci] ?? null) : null)),
|
data: data.categories.map((_, ci) => (isYearOn ? (row[ci] ?? null) : null)),
|
||||||
});
|
});
|
||||||
@@ -156,7 +164,7 @@ const GroupedStackBar = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const brandLegendOpt: LegendComponentOption = ({
|
const brandLegendOpt: LegendComponentOption = ({
|
||||||
top: 25,
|
top: 0, //25,
|
||||||
right: "center",
|
right: "center",
|
||||||
orient: "horizontal",
|
orient: "horizontal",
|
||||||
icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS),
|
icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS),
|
||||||
@@ -167,7 +175,8 @@ const GroupedStackBar = ({
|
|||||||
data: [...brands].reverse(),
|
data: [...brands].reverse(),
|
||||||
} as LegendComponentOption);
|
} as LegendComponentOption);
|
||||||
|
|
||||||
const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt;
|
//const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt;
|
||||||
|
const legends = brandLegendOpt;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tooltip:
|
tooltip:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
createCategoryAxis,
|
createCategoryAxis,
|
||||||
createValueAxis,
|
createValueAxis,
|
||||||
} from "@/lib/chart-options";
|
} from "@/lib/chart-options";
|
||||||
import { BAR_WIDTHS } from "@/const/chartConst";
|
import { BAR_WIDTHS } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: ChartData;
|
data: ChartData;
|
||||||
@@ -28,6 +28,11 @@ type Props = {
|
|||||||
yAxis?: EChartsOption["yAxis"];
|
yAxis?: EChartsOption["yAxis"];
|
||||||
barMaxWidth?: number;
|
barMaxWidth?: number;
|
||||||
showFocusLabel?:ShowLabel;
|
showFocusLabel?:ShowLabel;
|
||||||
|
labelOptions?: {
|
||||||
|
position?: "right" | "insideRight";
|
||||||
|
color?: string;
|
||||||
|
distance?: number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const HorizontalBar = ({
|
const HorizontalBar = ({
|
||||||
@@ -43,6 +48,7 @@ const HorizontalBar = ({
|
|||||||
yAxis,
|
yAxis,
|
||||||
barMaxWidth,
|
barMaxWidth,
|
||||||
showFocusLabel = "all",
|
showFocusLabel = "all",
|
||||||
|
labelOptions,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const palette = useMemo(() => buildLgPalette(paletteVarNames), [paletteVarNames]);
|
const palette = useMemo(() => buildLgPalette(paletteVarNames), [paletteVarNames]);
|
||||||
|
|
||||||
@@ -68,16 +74,18 @@ const HorizontalBar = ({
|
|||||||
label: showLabel
|
label: showLabel
|
||||||
? {
|
? {
|
||||||
show: true,
|
show: true,
|
||||||
position: "right",
|
position: labelOptions?.position ?? "right",
|
||||||
|
color: labelOptions?.color,
|
||||||
|
distance: labelOptions?.distance,
|
||||||
formatter: (p: any) => (p?.value ?? "") as any,
|
formatter: (p: any) => (p?.value ?? "") as any,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}, [data, palette, valueFormatter, tooltip, legend, grid, xAxis, yAxis, barMaxWidth, showFocusLabel]);
|
}, [data, palette, valueFormatter, tooltip, legend, grid, xAxis, yAxis, barMaxWidth, showFocusLabel, labelOptions]);
|
||||||
|
|
||||||
return <BaseEChart option={option} height={height} className={className} />;
|
return <BaseEChart option={option} height={height} className={className} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default HorizontalBar;
|
export default HorizontalBar;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useMemo } from "react";
|
|||||||
import type { EChartsOption } from "echarts";
|
import type { EChartsOption } from "echarts";
|
||||||
import BaseEChart from "../BaseEChart";
|
import BaseEChart from "../BaseEChart";
|
||||||
import type { ChartData, ValueFormatter } from "../types";
|
import type { ChartData, ValueFormatter } from "../types";
|
||||||
import { buildLgPalette } from "../color";
|
import {buildLgPalette, buildLgStackPalette} from "../color";
|
||||||
import {
|
import {
|
||||||
createDefaultTooltip,
|
createDefaultTooltip,
|
||||||
createDefaultLegend,
|
createDefaultLegend,
|
||||||
@@ -56,7 +56,7 @@ const StackBar = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const palette = useMemo(() => {
|
const palette = useMemo(() => {
|
||||||
const temp = buildLgPalette(paletteVarNames);
|
const temp = buildLgStackPalette(paletteVarNames);
|
||||||
const n = data.series.length; // 원본 기준
|
const n = data.series.length; // 원본 기준
|
||||||
const base = temp.slice(0, n);
|
const base = temp.slice(0, n);
|
||||||
return isReverse ? [...base].reverse() : base;
|
return isReverse ? [...base].reverse() : base;
|
||||||
@@ -66,13 +66,26 @@ const StackBar = ({
|
|||||||
const fmt = valueFormatter ?? ((v: number) => String(v));
|
const fmt = valueFormatter ?? ((v: number) => String(v));
|
||||||
const isV = orientation === "vertical";
|
const isV = orientation === "vertical";
|
||||||
|
|
||||||
|
const seriseSum: number[] = new Array(renderData.categories.length).fill(0);
|
||||||
|
renderData.categories.forEach((c, i) => {
|
||||||
|
renderData.series.forEach((s) => {
|
||||||
|
seriseSum[i] += Number(s.data[i]);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const seriesSumMax = Math.max(...seriseSum);
|
||||||
|
const valueAxis: { min: number; max?: number } = { min: 0 };
|
||||||
|
if (seriesSumMax > 100) {
|
||||||
|
valueAxis.max = Math.ceil(seriesSumMax / 5) * 5;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
color: palette,
|
color: palette,
|
||||||
tooltip: tooltip ?? (isReverse ? createReverseTooltip(data, fmt) : createDefaultTooltip(fmt)),
|
tooltip: tooltip ?? (isReverse ? createReverseTooltip(data, fmt) : createDefaultTooltip(fmt)),
|
||||||
legend: legend ?? (isReverse ? createReverseLegend(data) : createDefaultLegend()),
|
legend: legend ?? (isReverse ? createReverseLegend(data) : createDefaultLegend()),
|
||||||
grid: grid ?? createDefaultGrid(),
|
grid: grid ?? createDefaultGrid(),
|
||||||
xAxis: xAxis ?? (isV ? createCategoryAxis(renderData.categories) : createValueAxis()),
|
xAxis: xAxis ?? (isV ? createCategoryAxis(renderData.categories) : createValueAxis(false, valueAxis)),
|
||||||
yAxis: yAxis ?? (isV ? createValueAxis() : createCategoryAxis(renderData.categories)),
|
yAxis: yAxis ?? (isV ? createValueAxis(false, valueAxis) : createCategoryAxis(renderData.categories)),
|
||||||
|
|
||||||
series: renderData.series.map((s) =>
|
series: renderData.series.map((s) =>
|
||||||
createBarSeries(s.name, s.data, {
|
createBarSeries(s.name, s.data, {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
createCategoryAxis,
|
createCategoryAxis,
|
||||||
createValueAxis,
|
createValueAxis,
|
||||||
} from "@/lib/chart-options";
|
} from "@/lib/chart-options";
|
||||||
import { BAR_WIDTHS } from "@/const/chartConst";
|
import { BAR_WIDTHS } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: ChartData;
|
data: ChartData;
|
||||||
@@ -81,4 +81,4 @@ const VerticalBar = ({
|
|||||||
return <BaseEChart option={option} height={height} className={className} />;
|
return <BaseEChart option={option} height={height} className={className} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default VerticalBar;
|
export default VerticalBar;
|
||||||
|
|||||||
86
src/components/lge-dashboard/chart/chart.config.ts
Normal file
86
src/components/lge-dashboard/chart/chart.config.ts
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* 차트 기본 높이 설정
|
||||||
|
*/
|
||||||
|
export const CHART_HEIGHTS = {
|
||||||
|
DEFAULT: "100%",
|
||||||
|
COMPACT: 200,
|
||||||
|
EXPANDED: 320,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bar 차트의 Bar 너비 설정
|
||||||
|
*/
|
||||||
|
export const BAR_WIDTHS = {
|
||||||
|
DEFAULT: 42,
|
||||||
|
NARROW: 30,
|
||||||
|
WIDE: 60,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 차트 Grid 기본 패딩 설정
|
||||||
|
*/
|
||||||
|
export const CHART_GRID_DEFAULTS = {
|
||||||
|
DEFAULT: {
|
||||||
|
left: 16,
|
||||||
|
right: 16,
|
||||||
|
top: 36,
|
||||||
|
bottom: 12,
|
||||||
|
containLabel: true,
|
||||||
|
},
|
||||||
|
COMPACT: {
|
||||||
|
left: 10,
|
||||||
|
right: 10,
|
||||||
|
top: 20,
|
||||||
|
bottom: 8,
|
||||||
|
containLabel: true,
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legend 아이템 크기 설정 (GroupedOverlayBar, GroupedStackBar에서 사용)
|
||||||
|
*/
|
||||||
|
export const LEGEND_ITEM_SIZE = {
|
||||||
|
WIDTH: 25,
|
||||||
|
HEIGHT: 14,
|
||||||
|
RADIUS: 4,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 테이블 크기 설정
|
||||||
|
*/
|
||||||
|
export const TABLE_DIMENSIONS = {
|
||||||
|
CELL_HEIGHT: {
|
||||||
|
DEFAULT: 26,
|
||||||
|
COMPACT: 20,
|
||||||
|
EXPANDED: 32,
|
||||||
|
},
|
||||||
|
MIN_WIDTH: {
|
||||||
|
STANDARD: 1600,
|
||||||
|
COMPACT: 1200,
|
||||||
|
WIDE: 2000,
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
import {YEARS} from "@/const/lg-common.const";
|
||||||
|
|
||||||
|
/** 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;
|
||||||
|
export const AXIS_HIDE_Y_STYLE = { min:0, max:100, axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false }} as const;
|
||||||
|
|
||||||
|
export const CHART_COLOR_BY_YEAR = Object.fromEntries(
|
||||||
|
YEARS.map((year, i) => [
|
||||||
|
year,
|
||||||
|
`--chart-${YEARS.length-i}-t`,
|
||||||
|
])
|
||||||
|
) as Record<(typeof YEARS)[number], string>;
|
||||||
|
|
||||||
|
export const CHART_FOCUS_COLOR_BY_YEAR = Object.fromEntries(
|
||||||
|
YEARS.map((year, i) => [
|
||||||
|
year,
|
||||||
|
`--chart-${YEARS.length-i}`,
|
||||||
|
])
|
||||||
|
) as Record<(typeof YEARS)[number], string>;
|
||||||
@@ -69,13 +69,30 @@ export const buildLgPalette = (varNames?: string[]): string[] => {
|
|||||||
"--chart-1",
|
"--chart-1",
|
||||||
"--chart-2",
|
"--chart-2",
|
||||||
"--chart-3",
|
"--chart-3",
|
||||||
"--chart-4",
|
];
|
||||||
"--chart-5",
|
|
||||||
"--chart-6",
|
return defaults.map((v) => {
|
||||||
"--chart-7",
|
const hsl = resolveHslVar(v);
|
||||||
"--chart-8",
|
return hsl ? hslCss(hsl, 1) : v;
|
||||||
"--chart-9",
|
});
|
||||||
"--chart-10",
|
};
|
||||||
|
|
||||||
|
export const buildLgStackPalette = (varNames?: string[]): string[] => {
|
||||||
|
// globals.css에 정의된 스케일을 직접 참조(중첩 var(--chart-1) 회피)
|
||||||
|
const defaults = varNames ?? [
|
||||||
|
"--chart-stack-1",
|
||||||
|
"--chart-stack-2",
|
||||||
|
"--chart-stack-3",
|
||||||
|
"--chart-stack-4",
|
||||||
|
"--chart-stack-5",
|
||||||
|
"--chart-stack-6",
|
||||||
|
"--chart-stack-7",
|
||||||
|
"--chart-stack-8",
|
||||||
|
"--chart-stack-9",
|
||||||
|
"--chart-stack-10",
|
||||||
|
"--chart-stack-11",
|
||||||
|
"--chart-stack-12",
|
||||||
|
"--chart-stack-13",
|
||||||
];
|
];
|
||||||
|
|
||||||
return defaults.map((v) => {
|
return defaults.map((v) => {
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
import { ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, MergedTableCell, SignStyle } from "@/components/lge-dashboard";
|
||||||
import {BannerKey, BannerRow} from "@/types/lg";
|
import { BannerKey, BannerRow } from "@/types/lg.types";
|
||||||
import {formatRowLabel, isGapRow, wrapSampleRow} from "@/lib/lg-dashboard";
|
import { buildBannerGroupColumns, formatRowLabel, isGapRow, wrapSampleRow } from "@/lib/lg-dashboard";
|
||||||
import {useEffect, useMemo} from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import {
|
import { BANNER_GROUP, flattenBannerGroupKeys } from "@/const/lg-banner.const";
|
||||||
BANNER_GROUP,
|
import { BANNER_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
BANNER_KEY_MAP,
|
import { SITE_TITLE } from "@/const/lg-common.const";
|
||||||
GRID_Y_NOT_PADDING,
|
import { GRID_Y_NOT_PADDING } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
SITE_TITLE,
|
import { parseNumber } from "@/lib/utils";
|
||||||
} from "@/const/lgConst";
|
import { buildHeader_DataColumn, exportDashboardExcel, Section } from "@/lib/lg-export-excel";
|
||||||
import {parseNumber} from "@/lib/utils";
|
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||||
import {
|
import { CategoryFilterValue } from "@/components/layout/CategoryFilter";
|
||||||
buildHeader_DataColumn,
|
import { CategoryTargetData } from "@/types/filter.types";
|
||||||
exportDashboardExcel,
|
import { useDebouncedValue } from "@/hooks/useDebouncedValue";
|
||||||
Section
|
|
||||||
} from "@/lib/lg-export-excel";
|
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
|
||||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
|
||||||
import {CategoryTargetData} from "@/config/filter.types";
|
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
|
||||||
|
|
||||||
|
|
||||||
type SectionSpec = {
|
type SectionSpec = {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -35,23 +28,32 @@ const SECTIONS: SectionSpec[] = [
|
|||||||
const SEP_R = "lg-table__sep-r";
|
const SEP_R = "lg-table__sep-r";
|
||||||
|
|
||||||
const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] =>
|
const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] =>
|
||||||
spec.groupKeys.flatMap((gk) => BANNER_GROUP[gk].keys);
|
spec.groupKeys.flatMap((gk) => flattenBannerGroupKeys(BANNER_GROUP[gk].children));
|
||||||
|
|
||||||
const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<BannerRow>[] => {
|
const buildColumns = (spec: SectionSpec, selectedYear: string, isProfileAll:boolean): DataColumn<BannerRow>[] => {
|
||||||
const columns: DataColumn<BannerRow>[] = [
|
const columns: DataColumn<BannerRow>[] = [
|
||||||
|
...(isProfileAll
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
key: "year" as const,
|
||||||
|
header: "",
|
||||||
|
rowHead: true,
|
||||||
|
headerClassName: "lg-table__no-border-r",
|
||||||
|
width: 60,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
{
|
{
|
||||||
key: "rowLabel",
|
key: "rowLabel",
|
||||||
header: `${selectedYear}년`,
|
header: selectedYear ? `${selectedYear}년` : "",
|
||||||
headRowSpan: 2,
|
headerClassName: "lg-table__no-border-l",
|
||||||
rowHead: true,
|
rowHead: true,
|
||||||
cellClassName: "lg-table__rowhead",
|
|
||||||
width: 120,
|
width: 120,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "total",
|
key: "total",
|
||||||
header: "전체",
|
header: "전체",
|
||||||
numeric: true,
|
numeric: true,
|
||||||
headRowSpan: 2,
|
|
||||||
headerClassName: SEP_R,
|
headerClassName: SEP_R,
|
||||||
cellClassName: SEP_R,
|
cellClassName: SEP_R,
|
||||||
width: 80,
|
width: 80,
|
||||||
@@ -60,47 +62,84 @@ const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<Banner
|
|||||||
|
|
||||||
spec.groupKeys.forEach((groupKey) => {
|
spec.groupKeys.forEach((groupKey) => {
|
||||||
const g = BANNER_GROUP[groupKey];
|
const g = BANNER_GROUP[groupKey];
|
||||||
g.keys.forEach((k, idx) => {
|
columns.push({
|
||||||
const isLast = idx === g.keys.length - 1;
|
id: `banner-group-${groupKey}`,
|
||||||
columns.push({
|
header: g.label,
|
||||||
key: k as any,
|
children: buildBannerGroupColumns<BannerRow>(g, BANNER_KEY_MAP, {
|
||||||
header: BANNER_KEY_MAP[k] ?? String(k),
|
|
||||||
group: g.label,
|
|
||||||
numeric: true,
|
numeric: true,
|
||||||
headerClassName: isLast ? SEP_R : undefined,
|
|
||||||
cellClassName: isLast ? SEP_R : undefined,
|
|
||||||
width: 90,
|
width: 90,
|
||||||
});
|
resolveLeafMeta: (_key, idx, total) => {
|
||||||
|
const isLast = idx === total - 1;
|
||||||
|
return {
|
||||||
|
headerClassName: isLast ? SEP_R : undefined,
|
||||||
|
cellClassName: isLast ? SEP_R : undefined,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildYearMergedCells = (rows: BannerRow[]): MergedTableCell<BannerRow>[] => {
|
||||||
|
const mergedCells: MergedTableCell<BannerRow>[] = [];
|
||||||
|
let startRowIndex = 0;
|
||||||
|
|
||||||
|
while (startRowIndex < rows.length) {
|
||||||
|
const year = rows[startRowIndex].year;
|
||||||
|
let endRowIndex = startRowIndex + 1;
|
||||||
|
|
||||||
|
while (endRowIndex < rows.length && rows[endRowIndex].year === year) {
|
||||||
|
endRowIndex += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mergedCells.push({
|
||||||
|
key: "year",
|
||||||
|
content: formatRowLabel(year),
|
||||||
|
startRowIndex,
|
||||||
|
rowSpan: endRowIndex - startRowIndex,
|
||||||
|
className: "font-bold text-center",
|
||||||
|
});
|
||||||
|
|
||||||
|
startRowIndex = endRowIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergedCells;
|
||||||
|
};
|
||||||
|
|
||||||
type BannerSummaryProps = {
|
type BannerSummaryProps = {
|
||||||
data: BannerRow[];
|
data: BannerRow[];
|
||||||
useChart: boolean;
|
useChart: boolean;
|
||||||
useYear: boolean;
|
useYear: boolean;
|
||||||
|
isProfileAll?: boolean;
|
||||||
|
getCellClassName?: (row: BannerRow, column: DataColumn<BannerRow>, rowIndex: number) => string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
const BannerSummary = ({
|
||||||
const {filterValue, registerExcelExporter } = useLayoutFilter();
|
data,
|
||||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
useChart,
|
||||||
|
useYear,
|
||||||
|
isProfileAll = false,
|
||||||
|
getCellClassName
|
||||||
|
}: BannerSummaryProps) => {
|
||||||
|
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||||
|
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue);
|
||||||
|
|
||||||
const buildChartData = (rows: BannerRow[]): ChartData => {
|
const buildChartData = (rows: BannerRow[]): ChartData => {
|
||||||
const categories = rows
|
const categories = rows
|
||||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||||
.map((r) => formatRowLabel(r.rowLabel))
|
.map((r) => formatRowLabel(r.rowLabel))
|
||||||
.reverse();
|
.reverse();
|
||||||
|
|
||||||
const series = [
|
const series = [
|
||||||
{
|
{
|
||||||
name:"전체",
|
name: "전체",
|
||||||
data: rows
|
data: rows
|
||||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||||
.map((r) => parseNumber(r.total) ?? null)
|
.map((r) => parseNumber(r.total) ?? null)
|
||||||
.reverse(),
|
.reverse(),
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return { categories, series };
|
return { categories, series };
|
||||||
@@ -114,22 +153,19 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
|||||||
zeroText: "-",
|
zeroText: "-",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const sectionRows = useMemo(() => {
|
const sectionRows = useMemo(() => {
|
||||||
return SECTIONS.map((spec) => {
|
return SECTIONS.map((spec) => {
|
||||||
const specTitle = spec.title;
|
const specTitle = spec.title;
|
||||||
|
|
||||||
const bannerKeys = getSectionBannerKeys(spec);
|
const bannerKeys = getSectionBannerKeys(spec);
|
||||||
const columns = buildColumns(spec, useYear? filterValue.year : "");
|
const columns = buildColumns(spec, useYear ? debouncedFilterValue.year : "", isProfileAll);
|
||||||
|
|
||||||
// rows가 spec마다 다르면 여기서 가져오도록 구성
|
// rows가 spec마다 다르면 여기서 가져오도록 구성
|
||||||
const rows =
|
const rows = wrapSampleRow(useYear ? data.filter((d) => d.year === debouncedFilterValue.year) : data).map((row) => {
|
||||||
wrapSampleRow(useYear? data.filter((d) => d.year === filterValue.year) : data)
|
row.rowLabel = formatRowLabel(row.rowLabel);
|
||||||
.map((row) => {
|
return row;
|
||||||
row.rowLabel = formatRowLabel(row.rowLabel);
|
});
|
||||||
return row
|
|
||||||
})
|
|
||||||
const chartData = buildChartData(rows);
|
const chartData = buildChartData(rows);
|
||||||
|
const mergedCells = isProfileAll ? buildYearMergedCells(rows) : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
spec,
|
spec,
|
||||||
@@ -138,81 +174,93 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
|||||||
columns,
|
columns,
|
||||||
rows,
|
rows,
|
||||||
chartData,
|
chartData,
|
||||||
|
mergedCells,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}, [data, useYear, filterValue.year]);
|
}, [data, useYear, debouncedFilterValue.year, isProfileAll]);
|
||||||
|
|
||||||
|
const getTargetString = (target: CategoryTargetData): string => {
|
||||||
|
switch (target) {
|
||||||
|
case CategoryTargetData.PROFILE_ALL:
|
||||||
|
return "Profile (전체)";
|
||||||
|
case CategoryTargetData.PROFILE:
|
||||||
|
return "Profile";
|
||||||
|
default:
|
||||||
|
return "보급률 변화"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const product = debouncedFilterValue.product;
|
const product = debouncedFilterValue.product;
|
||||||
const type = debouncedFilterValue.type.label;
|
const type = debouncedFilterValue.type.label;
|
||||||
const target = debouncedFilterValue.target.value === CategoryTargetData.PROFILE? "Profile" : "보급률 변화"
|
|
||||||
|
|
||||||
const sheetName = `${product}_${type}_${target}`
|
const target = getTargetString(debouncedFilterValue.target.value);
|
||||||
|
const sheetName = `${product}_${type}_${target}`;
|
||||||
|
|
||||||
type AnyRow = Record<string, any>;
|
type AnyRow = Record<string, any>;
|
||||||
const sections: Section<AnyRow>[] =
|
const sections: Section<AnyRow>[] = sectionRows.map((sectionRow) => ({
|
||||||
sectionRows.map((sectionRow) => ({
|
title: sectionRow.specTitle,
|
||||||
title: sectionRow.specTitle,
|
header: buildHeader_DataColumn(sectionRow.columns),
|
||||||
header: buildHeader_DataColumn(sectionRow.columns),
|
rows: sectionRow.rows as AnyRow[],
|
||||||
rows: sectionRow.rows as AnyRow[],
|
rowGap: 1,
|
||||||
rowGap: 1,
|
}));
|
||||||
}))
|
|
||||||
;
|
|
||||||
|
|
||||||
await exportDashboardExcel({
|
await exportDashboardExcel({
|
||||||
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
|
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
|
||||||
sheetName: sheetName,
|
sheetName,
|
||||||
sections: sections,
|
sections,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return () => registerExcelExporter(null);
|
return () => registerExcelExporter(null);
|
||||||
}, [registerExcelExporter, debouncedFilterValue, sectionRows]);
|
}, [registerExcelExporter, debouncedFilterValue, sectionRows]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
{sectionRows.map((sectionRow) => {
|
{sectionRows.map((sectionRow) => {
|
||||||
return (
|
return (
|
||||||
<div key={`div_${sectionRow.specTitle}`}>
|
<div key={`div_${sectionRow.specTitle}`}>
|
||||||
{
|
{useChart ? (
|
||||||
useChart ?
|
<LeftChartTable<BannerRow>
|
||||||
<LeftChartTable<BannerRow>
|
key={sectionRow.specTitle}
|
||||||
key={sectionRow.specTitle}
|
title={sectionRow.specTitle}
|
||||||
title={sectionRow.specTitle}
|
columns={sectionRow.columns}
|
||||||
columns={sectionRow.columns}
|
rows={sectionRow.rows}
|
||||||
rows={sectionRow.rows}
|
getCellClassName={getCellClassName}
|
||||||
signStyle={signStyleGap}
|
signStyle={signStyleGap}
|
||||||
chart={
|
chart={
|
||||||
<HorizontalBar
|
<HorizontalBar
|
||||||
data={sectionRow.chartData}
|
data={sectionRow.chartData}
|
||||||
height="100%"
|
height="100%"
|
||||||
showFocusLabel="none"
|
showFocusLabel="all"
|
||||||
legend={{ show: false }}
|
labelOptions={{ position: "insideRight", color: "#fff", distance: 4 }}
|
||||||
grid={GRID_Y_NOT_PADDING}
|
legend={{ show: false }}
|
||||||
xAxis={{ type: "value", show: false }}
|
grid={GRID_Y_NOT_PADDING}
|
||||||
yAxis={{ type: "category", data: sectionRow.chartData.categories, show: false }}
|
xAxis={{ type: "value", show: false }}
|
||||||
/>
|
yAxis={{ type: "category", data: sectionRow.chartData.categories, show: false }}
|
||||||
}
|
/>
|
||||||
chartCell={{ key: "total", startRowIndex: 1 }}
|
|
||||||
minWidthPx={1200}
|
|
||||||
starUnder30Sample={true}
|
|
||||||
/>
|
|
||||||
:
|
|
||||||
<DataTable<BannerRow>
|
|
||||||
key={sectionRow.specTitle}
|
|
||||||
title={sectionRow.specTitle}
|
|
||||||
columns={sectionRow.columns}
|
|
||||||
rows={sectionRow.rows}
|
|
||||||
signStyle={signStyleGap}
|
|
||||||
unitText={""}
|
|
||||||
starUnder30Sample={true}
|
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
</div>
|
chartCell={{ key: "total", startRowIndex: 1 }}
|
||||||
);
|
minWidthPx={1200}
|
||||||
})}
|
starUnder30Sample={true}
|
||||||
</div>
|
/>
|
||||||
|
) : (
|
||||||
|
<DataTable<BannerRow>
|
||||||
|
key={sectionRow.specTitle}
|
||||||
|
title={sectionRow.specTitle}
|
||||||
|
columns={sectionRow.columns}
|
||||||
|
rows={sectionRow.rows}
|
||||||
|
signStyle={signStyleGap}
|
||||||
|
unitText={""}
|
||||||
|
starUnder30Sample={true}
|
||||||
|
mergedCells={sectionRow.mergedCells}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default BannerSummary;
|
export default BannerSummary;
|
||||||
|
|||||||
@@ -1,36 +1,32 @@
|
|||||||
import {
|
import {
|
||||||
bannerType,
|
bannerType,
|
||||||
type DataColumn,
|
BottomDescription, type DataColumn, DataTable, HorizontalBar, SectionTitle, SignStyle, StackBar
|
||||||
DataTable,
|
|
||||||
HorizontalBar, SectionTitle, SignStyle,
|
|
||||||
StackBar
|
|
||||||
} from "@/components/lge-dashboard";
|
} from "@/components/lge-dashboard";
|
||||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||||
import {totalFilters} from "@/config/filter.data";
|
import { categoryByDataBanner } from "@/const/filter.const";
|
||||||
import React, {useMemo, useState} from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import {BannerGroupKey, CategoryChartMode, BannerRow} from "@/types/lg";
|
import { BannerGroupKey, CategoryChartMode, BannerRow, LegendOption } from "@/types/lg.types";
|
||||||
import {
|
import { buildBannerGroupColumns, buildRowLabelSeriesChartData, buildYearSeriesChartData, formatRowLabel, isBannerGroupKey, isGapRow, wrapSampleRow } from "@/lib/lg-dashboard";
|
||||||
buildRowLabelSeriesChartData,
|
import { BANNER_GROUP } from "@/const/lg-banner.const";
|
||||||
buildYearSeriesChartData, formatRowLabel,
|
import { BANNER_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
isBannerGroupKey, isGapRow,
|
import { createDefaultGrid, reverseCategories } from "@/lib/chart-options";
|
||||||
wrapSampleRow
|
|
||||||
} from "@/lib/lg-dashboard";
|
|
||||||
import {BANNER_GROUP, BANNER_KEY_MAP} from "@/const/lgConst";
|
|
||||||
import {createDefaultGrid, reverseCategories} from "@/lib/chart-options";
|
|
||||||
|
|
||||||
type CategoryByDataProps = {
|
type CategoryByDataProps = {
|
||||||
selectedYear: string;
|
selectedYear: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
surveyTitle?: string;
|
||||||
chartMode: CategoryChartMode;
|
chartMode: CategoryChartMode;
|
||||||
|
chartLegend?: LegendOption;
|
||||||
|
chartTopMargin?: number;
|
||||||
allTableData: BannerRow[];
|
allTableData: BannerRow[];
|
||||||
fillGreaterThan5?: boolean;
|
fillGreaterThan5?: boolean;
|
||||||
chartHeight?: number | string;
|
chartHeight?: number | string;
|
||||||
chartWidth?: number;
|
chartWidth?: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
const banners: bannerType[] = totalFilters.map((filter) => {
|
const banners: bannerType[] = categoryByDataBanner.map((filter) => {
|
||||||
return {variable: filter.variable, variableName: filter.variableName}
|
return { variable: filter.variable, variableName: filter.variableName };
|
||||||
})
|
});
|
||||||
|
|
||||||
const signStyleGap: SignStyle<BannerRow> = {
|
const signStyleGap: SignStyle<BannerRow> = {
|
||||||
rowSelector: (row) => isGapRow(row.rowLabel),
|
rowSelector: (row) => isGapRow(row.rowLabel),
|
||||||
@@ -41,51 +37,56 @@ const signStyleGap: SignStyle<BannerRow> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const CategoryByData = ({
|
const CategoryByData = ({
|
||||||
selectedYear,
|
selectedYear,
|
||||||
title,
|
title,
|
||||||
chartMode,
|
surveyTitle,
|
||||||
allTableData,
|
chartMode,
|
||||||
fillGreaterThan5,
|
chartLegend,
|
||||||
chartHeight,
|
chartTopMargin,
|
||||||
chartWidth,
|
allTableData,
|
||||||
}: CategoryByDataProps) => {
|
fillGreaterThan5,
|
||||||
|
chartHeight,
|
||||||
|
chartWidth,
|
||||||
|
}: CategoryByDataProps) => {
|
||||||
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
|
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
|
||||||
|
|
||||||
const buildColumns = (groupKey: BannerGroupKey, selectedYear:string): DataColumn<BannerRow>[] => {
|
const buildColumns = (groupKey: BannerGroupKey, year: string): DataColumn<BannerRow>[] => {
|
||||||
const columns: DataColumn<BannerRow>[] = [
|
const g = BANNER_GROUP[groupKey];
|
||||||
|
|
||||||
|
return [
|
||||||
{
|
{
|
||||||
key: "rowLabel",
|
key: "rowLabel",
|
||||||
header: `${selectedYear}년`,
|
header: `${year}년`,
|
||||||
headRowSpan: 2,
|
|
||||||
rowHead: true,
|
rowHead: true,
|
||||||
cellClassName: "lg-table__rowhead",
|
cellClassName: "lg-table__rowhead",
|
||||||
width: 120,
|
width: 120,
|
||||||
},
|
},
|
||||||
];
|
{
|
||||||
|
key: "total",
|
||||||
const g = BANNER_GROUP[groupKey];
|
header: "전체",
|
||||||
g.keys.forEach((k) => {
|
|
||||||
columns.push({
|
|
||||||
key: k as any,
|
|
||||||
header: BANNER_KEY_MAP[k] ?? String(k),
|
|
||||||
group: g.label,
|
|
||||||
numeric: true,
|
numeric: true,
|
||||||
width: 90,
|
cellClassName: "lg-table__rowhead",
|
||||||
});
|
width: 120,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
return columns;
|
id: `category-banner-${groupKey}`,
|
||||||
|
header: g.label,
|
||||||
|
children: buildBannerGroupColumns<BannerRow>(g, BANNER_KEY_MAP, {
|
||||||
|
numeric: true,
|
||||||
|
width: 90,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
const excludeRowLabels =["사례수", "gap"];
|
const excludeRowLabels = ["사례수", "gap"];
|
||||||
const chartTargetData = allTableData.filter((row) => row.year === selectedYear || Number(row.year) === Number(selectedYear) - 1);
|
const chartTargetData = allTableData.filter((row) => row.year === selectedYear || Number(row.year) === Number(selectedYear) - 1);
|
||||||
if(chartMode == "horizontal"){
|
if (chartMode === "horizontal") {
|
||||||
return reverseCategories(buildYearSeriesChartData(chartTargetData, {excludeRowLabels}));
|
return reverseCategories(buildYearSeriesChartData(chartTargetData, { excludeRowLabels }));
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildRowLabelSeriesChartData(chartTargetData, {excludeRowLabels});
|
return buildRowLabelSeriesChartData(chartTargetData, { excludeRowLabels });
|
||||||
|
|
||||||
}, [allTableData, selectedYear, chartMode]);
|
}, [allTableData, selectedYear, chartMode]);
|
||||||
|
|
||||||
const tableColumns = useMemo(() => {
|
const tableColumns = useMemo(() => {
|
||||||
@@ -93,72 +94,73 @@ const CategoryByData = ({
|
|||||||
return isBannerGroupKey(v) ? buildColumns(v, selectedYear) : [];
|
return isBannerGroupKey(v) ? buildColumns(v, selectedYear) : [];
|
||||||
}, [selectedBanner.variable, selectedYear]);
|
}, [selectedBanner.variable, selectedYear]);
|
||||||
|
|
||||||
const tableData = useMemo(() =>
|
const tableData = useMemo(
|
||||||
|
() =>
|
||||||
wrapSampleRow(allTableData)
|
wrapSampleRow(allTableData)
|
||||||
.filter((row) => row.year === selectedYear)
|
.filter((row) => row.year === selectedYear)
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
row.rowLabel = formatRowLabel(row.rowLabel);
|
row.rowLabel = formatRowLabel(row.rowLabel);
|
||||||
return row
|
return row;
|
||||||
})
|
}),
|
||||||
, [allTableData, selectedYear]);
|
[allTableData, selectedYear]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-2 flex items-center pr-6">
|
<div className="mb-2 flex items-center pr-6">
|
||||||
{title ? <SectionTitle title={title} /> : <div />}
|
{title ? <SectionTitle title={title} /> : <div />}
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-6 p-3">
|
||||||
|
<div className="flex-shrink-0" style={{ width: `${chartWidth ?? 400}px` }}>
|
||||||
|
{(() => {
|
||||||
|
switch (chartMode) {
|
||||||
|
case "horizontal":
|
||||||
|
return (
|
||||||
|
<HorizontalBar
|
||||||
|
data={chartData}
|
||||||
|
legend={chartLegend}
|
||||||
|
grid={chartTopMargin ? createDefaultGrid("default", { top: chartTopMargin }) : undefined}
|
||||||
|
height={chartHeight}
|
||||||
|
showFocusLabel="none"
|
||||||
|
paletteVarNames={chartData.series.length === 1 ? ["--chart-1"] : ["--chart-2", "--chart-1"]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
case "stack":
|
||||||
|
case "reverseStack":
|
||||||
|
return (
|
||||||
|
<StackBar
|
||||||
|
data={chartData}
|
||||||
|
legend={chartLegend}
|
||||||
|
height={chartHeight}
|
||||||
|
grid={createDefaultGrid("default", { top: chartTopMargin ? chartTopMargin : 52 })}
|
||||||
|
isReverse={chartMode === "reverseStack"}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-6 p-3">
|
|
||||||
<div className="flex-shrink-0" style={{ width: `${chartWidth ?? 400}px`}}>
|
|
||||||
{(() => {
|
|
||||||
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">
|
||||||
|
<BannerButtons banners={banners} selectedBanner={selectedBanner} onSelectBanner={setSelectedBanner} />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center">
|
<div className="flex-1">
|
||||||
<BannerButtons
|
<DataTable
|
||||||
banners={banners}
|
columns={tableColumns}
|
||||||
selectedBanner={selectedBanner}
|
rows={tableData}
|
||||||
onSelectBanner={setSelectedBanner}
|
signStyle={signStyleGap}
|
||||||
/>
|
fillGreaterThan5={fillGreaterThan5}
|
||||||
</div>
|
fillGapRow={true}
|
||||||
|
starUnder30Sample={true}
|
||||||
<div className="flex-1">
|
/>
|
||||||
<DataTable
|
<BottomDescription description={"전체 대비 5%p 이상 품목에 대해 음영 표시"} />
|
||||||
columns={tableColumns}
|
|
||||||
rows={tableData}
|
|
||||||
signStyle={signStyleGap}
|
|
||||||
fillGreaterThan5={fillGreaterThan5}
|
|
||||||
starUnder30Sample={true}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="ml-5 mb-5 -mt-3 flex content-text-sm">{surveyTitle}</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CategoryByData;
|
export default CategoryByData;
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useMemo } from "react";
|
import type React from "react";
|
||||||
import { cn, parseNumber } from "@/lib/utils";
|
import { TABLE_DIMENSIONS } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
|
import { UNIT_TEXT } from "@/const/lg-common.const";
|
||||||
import type { DataColumn, SignStyle } from "../types";
|
import type { DataColumn, SignStyle } from "../types";
|
||||||
import SectionTitle from "../SectionTitle";
|
import BaseDataTable from "../table/BaseDataTable";
|
||||||
import { TABLE_DIMENSIONS } from "@/const/chartConst";
|
|
||||||
import {isSampleRow} from "@/lib/lg-dashboard";
|
|
||||||
import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
|
||||||
|
|
||||||
type MergedChartCell<T> = {
|
type MergedChartCell<T> = {
|
||||||
/** 차트를 삽입할 컬럼 key(해당 컬럼 td는 startRow에서만 렌더되고 rowSpan 적용) */
|
|
||||||
key: keyof T;
|
key: keyof T;
|
||||||
/** rowSpan 시작 row index (기본 0) */
|
|
||||||
startRowIndex?: number;
|
startRowIndex?: number;
|
||||||
/** rowSpan 수 (기본: rows.length - startRowIndex) */
|
|
||||||
rowSpan?: number;
|
rowSpan?: number;
|
||||||
/** chart td 클래스 (예: lg-table__sep-r) */
|
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -23,42 +17,18 @@ type Props<T extends Record<string, unknown>> = {
|
|||||||
title?: string;
|
title?: string;
|
||||||
columns: DataColumn<T>[];
|
columns: DataColumn<T>[];
|
||||||
rows: T[];
|
rows: T[];
|
||||||
/** 머지된 셀 안에 렌더할 차트 */
|
|
||||||
chart: React.ReactNode;
|
chart: React.ReactNode;
|
||||||
/** 어떤 컬럼을 머지-차트 셀로 교체할지 */
|
|
||||||
chartCell: MergedChartCell<T>;
|
chartCell: MergedChartCell<T>;
|
||||||
|
|
||||||
/** +/-/0 표기/색상 옵션(선택) */
|
|
||||||
signStyle?: SignStyle<T>;
|
signStyle?: SignStyle<T>;
|
||||||
|
|
||||||
wrapperClassName?: string;
|
wrapperClassName?: string;
|
||||||
tableClassName?: string;
|
tableClassName?: string;
|
||||||
minWidthPx?: number;
|
minWidthPx?: number;
|
||||||
|
minWidth?: number;
|
||||||
starUnder30Sample?: boolean;
|
starUnder30Sample?: boolean;
|
||||||
unitText?: string;
|
unitText?: string;
|
||||||
|
getCellClassName?: (row: T, column: DataColumn<T>, rowIndex: number) => string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
|
||||||
|
|
||||||
function renderSigned(
|
|
||||||
n: number,
|
|
||||||
opts: {
|
|
||||||
display: "number" | "arrow";
|
|
||||||
showPlus: boolean;
|
|
||||||
arrowWithNumber: boolean;
|
|
||||||
zeroText: string;
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
if (n === 0) return opts.zeroText;
|
|
||||||
if (opts.display === "arrow") {
|
|
||||||
const arrow = n > 0 ? "▲" : "▼";
|
|
||||||
const num = Math.abs(n);
|
|
||||||
return opts.arrowWithNumber ? `${arrow} ${num}` : arrow;
|
|
||||||
}
|
|
||||||
if (n > 0) return opts.showPlus ? `+${n}` : `${n}`;
|
|
||||||
return `${n}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function LeftChartTable<T extends Record<string, unknown>>({
|
export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||||
title,
|
title,
|
||||||
columns,
|
columns,
|
||||||
@@ -69,206 +39,38 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
|||||||
wrapperClassName,
|
wrapperClassName,
|
||||||
tableClassName,
|
tableClassName,
|
||||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.COMPACT,
|
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.COMPACT,
|
||||||
|
minWidth,
|
||||||
starUnder30Sample = true,
|
starUnder30Sample = true,
|
||||||
unitText = UNIT_TEXT,
|
unitText = UNIT_TEXT,
|
||||||
}: Props<T>) {
|
getCellClassName,
|
||||||
const hasGroupHeader = useMemo(
|
}: Readonly<Props<T>>) {
|
||||||
() => columns.some((c) => c.group) || columns.some((c) => c.headRowSpan === 2),
|
|
||||||
[columns]
|
|
||||||
);
|
|
||||||
|
|
||||||
const groupCells = useMemo(() => {
|
|
||||||
if (!hasGroupHeader) return [] as Array<
|
|
||||||
| { kind: "rowspan"; label: string; colSpan: 1; rowSpan: 2; className?: string }
|
|
||||||
| { kind: "group"; label: string; colSpan: number; rowSpan: 1; className?: string }
|
|
||||||
| { kind: "blank"; label: string; colSpan: 1; rowSpan: 1; className?: string }
|
|
||||||
>;
|
|
||||||
|
|
||||||
type Cell =
|
|
||||||
| { kind: "rowspan"; label: string; colSpan: 1; rowSpan: 2; className?: string }
|
|
||||||
| { kind: "group"; label: string; colSpan: number; rowSpan: 1; className?: string }
|
|
||||||
| { kind: "blank"; label: string; colSpan: 1; rowSpan: 1; className?: string };
|
|
||||||
|
|
||||||
const out: Cell[] = [];
|
|
||||||
let i = 0;
|
|
||||||
while (i < columns.length) {
|
|
||||||
const c = columns[i];
|
|
||||||
if (c.headRowSpan === 2) {
|
|
||||||
out.push({
|
|
||||||
kind: "rowspan",
|
|
||||||
label: c.header,
|
|
||||||
colSpan: 1,
|
|
||||||
rowSpan: 2,
|
|
||||||
className: c.headerClassName,
|
|
||||||
});
|
|
||||||
i += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const g = c.group ?? "";
|
|
||||||
if (!g) {
|
|
||||||
out.push({ kind: "blank", label: "", colSpan: 1, rowSpan: 1, className: c.headerClassName });
|
|
||||||
i += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let span = 1;
|
|
||||||
while (
|
|
||||||
i + span < columns.length &&
|
|
||||||
(columns[i + span].headRowSpan ?? 1) !== 2 &&
|
|
||||||
(columns[i + span].group ?? "") === g
|
|
||||||
) {
|
|
||||||
span += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.push({ kind: "group", label: g, colSpan: span, rowSpan: 1, className: columns[i + span -1].headerClassName });
|
|
||||||
i += span;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}, [columns, hasGroupHeader]);
|
|
||||||
|
|
||||||
const display = signStyle?.display ?? "number";
|
|
||||||
const arrowWithNumber = signStyle?.arrowWithNumber ?? true;
|
|
||||||
const showPlus = signStyle?.showPlus ?? true;
|
|
||||||
const zeroText = signStyle?.zeroText ?? "-";
|
|
||||||
const posCls = signStyle?.positiveTextClassName ?? "lg-num-pos";
|
|
||||||
const negCls = signStyle?.negativeTextClassName ?? "lg-num-neg";
|
|
||||||
const zeroCls = signStyle?.zeroTextClassName ?? "";
|
|
||||||
|
|
||||||
const start = chartCell.startRowIndex ?? 0;
|
|
||||||
const rowSpan = chartCell.rowSpan ?? Math.max(0, rows.length - start);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("w-full", wrapperClassName)}>
|
<BaseDataTable
|
||||||
<div className="mb-2 flex items-center justify-between">
|
columns={columns}
|
||||||
{ title && <SectionTitle title={title} />}
|
rows={rows}
|
||||||
|
title={title}
|
||||||
|
wrapperClassName={wrapperClassName}
|
||||||
|
tableClassName={tableClassName}
|
||||||
|
minWidth={minWidth ?? minWidthPx}
|
||||||
|
signStyle={signStyle}
|
||||||
|
signStyleFallback={{
|
||||||
|
positiveTextClassName: "lg-num-pos",
|
||||||
|
negativeTextClassName: "lg-num-neg",
|
||||||
|
zeroTextClassName: "",
|
||||||
|
arrowWithNumber: true,
|
||||||
|
}}
|
||||||
|
starUnder30Sample={starUnder30Sample}
|
||||||
|
unitText={unitText}
|
||||||
|
getCellClassName={getCellClassName}
|
||||||
|
mergedCells={[
|
||||||
{
|
{
|
||||||
(unitText || starUnder30Sample) &&
|
key: chartCell.key,
|
||||||
<div className="ml-auto text-gray-500 content-text-xs font-semibold text-right">
|
content: chart,
|
||||||
{unitText}
|
startRowIndex: chartCell.startRowIndex,
|
||||||
{starUnder30Sample && <><br/>{SAMPLE_SIZE_NOTICE}</>}
|
rowSpan: chartCell.rowSpan,
|
||||||
</div>
|
className: chartCell.className,
|
||||||
}
|
},
|
||||||
</div>
|
]}
|
||||||
|
/>
|
||||||
<div className="overflow-x-auto">
|
|
||||||
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidthPx}px` }}>
|
|
||||||
<thead>
|
|
||||||
{hasGroupHeader ? (
|
|
||||||
<tr className="lg-table__group">
|
|
||||||
{groupCells.map((g, idx) => (
|
|
||||||
<th
|
|
||||||
key={`${g.kind}-${idx}`}
|
|
||||||
className={cn(g.className)}
|
|
||||||
colSpan={g.colSpan}
|
|
||||||
rowSpan={g.rowSpan}
|
|
||||||
>
|
|
||||||
{g.label}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<tr className={hasGroupHeader ? "lg-table__subhead" : undefined}>
|
|
||||||
{columns
|
|
||||||
.filter((c) => (c.headRowSpan ?? 1) !== 2)
|
|
||||||
.map((c) => (
|
|
||||||
<th key={String(c.key)} className={cn(c.headerClassName)} style={c.width ? { width: c.width } : undefined}>
|
|
||||||
{c.header}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
{rows.map((row, ri) => {
|
|
||||||
const sampleRow = isSampleRow(row.rowLabel as string ?? "");
|
|
||||||
const isSignRow = signStyle?.rowSelector ? signStyle.rowSelector(row, ri) : false;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<tr key={ri}>
|
|
||||||
{columns.map((c) => {
|
|
||||||
// 머지-차트 셀
|
|
||||||
if (c.key === chartCell.key && ri >= start) {
|
|
||||||
if (ri > start) return null;
|
|
||||||
return (
|
|
||||||
<td
|
|
||||||
key={String(c.key)}
|
|
||||||
rowSpan={rowSpan}
|
|
||||||
className={cn(c.cellClassName, chartCell.className)}
|
|
||||||
style={{ padding: 0, verticalAlign: "middle" }}
|
|
||||||
>
|
|
||||||
{chart}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 일반 셀
|
|
||||||
const raw = c.key in row ? row[c.key] : undefined;
|
|
||||||
const content = c.render
|
|
||||||
? c.render(row)
|
|
||||||
: raw === null || raw === undefined
|
|
||||||
? ""
|
|
||||||
: typeof raw === "string" || typeof raw === "number"
|
|
||||||
? raw
|
|
||||||
: String(raw);
|
|
||||||
|
|
||||||
const n = c.numeric ? parseNumber(raw) : null;
|
|
||||||
const shouldSign = isSignRow && (signStyle?.keys ? signStyle.keys.includes(c.key) : !!c.numeric);
|
|
||||||
|
|
||||||
if (c.rowHead) {
|
|
||||||
return (
|
|
||||||
<th
|
|
||||||
key={String(c.key)}
|
|
||||||
scope="row"
|
|
||||||
className={cn("lg-table__rowhead", c.cellClassName)}
|
|
||||||
style={c.width ? { width: c.width } : undefined}
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</th>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shouldSign) {
|
|
||||||
const numContent = c.numeric ? parseNumber(content) ?? 0 : 0;
|
|
||||||
const isStar = starUnder30Sample && sampleRow && numContent < 30;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<td
|
|
||||||
key={String(c.key)}
|
|
||||||
className={cn(c.cellClassName)}
|
|
||||||
style={c.width ? { width: c.width } : undefined}
|
|
||||||
>
|
|
||||||
{isStar?`${content}*`:content}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// sign row: 값이 없으면 "-" 유지
|
|
||||||
if (n === null) {
|
|
||||||
return (
|
|
||||||
<td key={String(c.key)} className={cn(c.cellClassName)}>
|
|
||||||
-
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const cls = n > 0 ? posCls : n < 0 ? negCls : zeroCls;
|
|
||||||
const txt = renderSigned(n, { display, showPlus, arrowWithNumber, zeroText });
|
|
||||||
|
|
||||||
return (
|
|
||||||
<td key={String(c.key)} className={cn(c.cellClassName, cls)}>
|
|
||||||
{txt}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import GaugeCardTable from "./GaugeCardTable";
|
import GaugeCardTable from "./GaugeCardTable";
|
||||||
import {LIFE_STAGE_COLUMNS, UNIT_TEXT} from "@/const/lgConst";
|
import {LIFE_STAGE_COLUMNS} from "@/const/lg-product.const";
|
||||||
import {LifeStageGroup} from "@/types/lg";
|
import {UNIT_TEXT} from "@/const/lg-common.const";
|
||||||
|
import {LifeStageGroup} from "@/types/lg.types";
|
||||||
import SectionTitle from "../SectionTitle";
|
import SectionTitle from "../SectionTitle";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
@@ -48,4 +49,4 @@ const LifeStageDiv = ({lifeStageRowsByGroup}:lifeStageDivProps) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LifeStageDiv;
|
export default LifeStageDiv;
|
||||||
|
|||||||
@@ -3,171 +3,145 @@
|
|||||||
import React, { useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
import { cn, parseNumber } from "@/lib/utils";
|
import { cn, parseNumber } from "@/lib/utils";
|
||||||
import type { ChartData, SignStyle, TopChartTableRow } from "../types";
|
import type { ChartData, SignStyle, TopChartTableRow } from "../types";
|
||||||
import SectionTitle from "../SectionTitle";
|
import { CHART_HEIGHTS, TABLE_DIMENSIONS } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import { CHART_HEIGHTS, TABLE_DIMENSIONS } from "@/const/chartConst";
|
import { UNIT_TEXT } from "@/const/lg-common.const";
|
||||||
import {UNIT_TEXT} from "@/const/lgConst";
|
import {isCagrRow, isSampleRow} from "@/lib/lg-dashboard";
|
||||||
import {isCagrRow} from "@/lib/lg-dashboard";
|
import BaseTableHeader from "../table/core/BaseTableHeader";
|
||||||
|
import { formatSignedValue, getSignTextClass, resolveSignStyle, toRoundedNumber } from "../table/core/table-core.helpers";
|
||||||
|
|
||||||
export type TopChartTableProps = {
|
export type TopChartTableProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
categories: string[];
|
categories: string[];
|
||||||
rows: TopChartTableRow[];
|
rows: TopChartTableRow[];
|
||||||
/** 테이블 상단(헤더 1행) 콜스팬 셀 내부에 렌더될 차트 */
|
|
||||||
chart?:
|
chart?:
|
||||||
| React.ReactNode
|
| React.ReactNode
|
||||||
| ((ctx: {
|
| ((ctx: {
|
||||||
/** 테이블 컬럼(=x축) 기준으로 구성된 ChartData */
|
chartData: ChartData;
|
||||||
chartData: ChartData;
|
}) => React.ReactNode);
|
||||||
}) => React.ReactNode);
|
chartHeight?: number | string;
|
||||||
/** chart 셀 높이(px) */
|
|
||||||
chartHeight?: number;
|
|
||||||
/** 가로 스크롤 min-width */
|
|
||||||
minWidthPx?: number;
|
minWidthPx?: number;
|
||||||
|
minWidth?: number;
|
||||||
tableClassName?: string;
|
tableClassName?: string;
|
||||||
wrapperClassName?: string;
|
wrapperClassName?: string;
|
||||||
/** +/-/0 색상/표기 옵션(선택) */
|
|
||||||
signStyle?: SignStyle<TopChartTableRow>;
|
signStyle?: SignStyle<TopChartTableRow>;
|
||||||
fillCAGR?: boolean;
|
fillCAGR?: boolean;
|
||||||
unitText?: string;
|
unitText?: string;
|
||||||
};
|
};
|
||||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
|
||||||
|
|
||||||
function formatSignedNumber(n: number, zeroText: string, showPlus: boolean) {
|
export default function TopChartTable({
|
||||||
if (n === 0) return zeroText;
|
title,
|
||||||
if (n > 0) return showPlus ? `+${n}` : `${n}`;
|
rows,
|
||||||
return `${n}`;
|
categories,
|
||||||
}
|
chart,
|
||||||
|
chartHeight = CHART_HEIGHTS.DEFAULT,
|
||||||
|
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
||||||
|
minWidth,
|
||||||
|
tableClassName,
|
||||||
|
wrapperClassName,
|
||||||
|
signStyle,
|
||||||
|
fillCAGR = false,
|
||||||
|
unitText = UNIT_TEXT,
|
||||||
|
}: Readonly<TopChartTableProps>) {
|
||||||
|
const resolvedSignStyle = resolveSignStyle(signStyle, {
|
||||||
|
positiveTextClassName: "lg-num-pos",
|
||||||
|
negativeTextClassName: "lg-num-neg",
|
||||||
|
zeroTextClassName: "",
|
||||||
|
arrowWithNumber: true,
|
||||||
|
});
|
||||||
|
|
||||||
type CellValue = TopChartTableRow["values"][number];
|
|
||||||
function toCellValue(v: unknown): CellValue {
|
|
||||||
if (v === null || v === undefined) return v;
|
|
||||||
if (typeof v === "number" || typeof v === "string") return v;
|
|
||||||
return String(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function TopChartTable(props: TopChartTableProps) {
|
|
||||||
const {
|
|
||||||
title,
|
|
||||||
rows,
|
|
||||||
categories,
|
|
||||||
chart,
|
|
||||||
chartHeight = CHART_HEIGHTS.DEFAULT,
|
|
||||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
|
||||||
tableClassName,
|
|
||||||
wrapperClassName,
|
|
||||||
signStyle,
|
|
||||||
fillCAGR = false,
|
|
||||||
unitText = UNIT_TEXT
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
const display = signStyle?.display ?? "number";
|
|
||||||
const arrowWithNumber = signStyle?.arrowWithNumber ?? true;
|
|
||||||
const showPlus = signStyle?.showPlus ?? true;
|
|
||||||
const posCls = signStyle?.positiveTextClassName ?? "lg-num-pos";
|
|
||||||
const negCls = signStyle?.negativeTextClassName ?? "lg-num-neg";
|
|
||||||
const zeroText = signStyle?.zeroText ?? "-";
|
|
||||||
|
|
||||||
// 테이블 컬럼(=categories)을 x축으로 사용하는 chartData를 항상 제공
|
|
||||||
const chartData: ChartData = useMemo(
|
const chartData: ChartData = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
categories,
|
categories,
|
||||||
series: rows.map((r) => ({
|
series: rows.map((row) => ({
|
||||||
name: r.label,
|
name: row.label,
|
||||||
data: r.values.map((v) => parseNumber(v) ?? null),
|
data: row.values.map((value) => parseNumber(value) ?? null),
|
||||||
})),
|
})),
|
||||||
}),
|
}),
|
||||||
[categories, rows]
|
[categories, rows]
|
||||||
);
|
);
|
||||||
|
|
||||||
const chartNode = useMemo(() => {
|
const chartNode = useMemo(() => {
|
||||||
if (!chart) return null;
|
if (!chart) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return typeof chart === "function" ? chart({ chartData }) : chart;
|
return typeof chart === "function" ? chart({ chartData }) : chart;
|
||||||
}, [chart, chartData, categories, rows]);
|
}, [chart, chartData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("w-full", wrapperClassName)}>
|
<div className={cn("w-full", wrapperClassName)}>
|
||||||
<div className="mb-2 flex items-center justify-between">
|
<BaseTableHeader title={title} unitText={unitText} />
|
||||||
{title ? <SectionTitle title={title} /> : <div />}
|
|
||||||
{unitText ? <div className="text-gray-500 text-xs font-semibold">{unitText}</div> : null}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table
|
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidth ?? minWidthPx}px` }}>
|
||||||
className={cn("lg-table", tableClassName)}
|
<thead>
|
||||||
style={{ minWidth: `${minWidthPx}px` }}
|
|
||||||
>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
<tr>
|
||||||
{/* 좌상단: rowhead 헤더(필요 시 표시). HTML과 동일하게 2행 rowspan */}
|
<th colSpan={2} className="w-44" style={{ whiteSpace: "nowrap" }} />
|
||||||
<th rowSpan={2} className="lg-table__sep-r w-31" style={{ whiteSpace: "nowrap" }}>
|
|
||||||
|
|
||||||
</th>
|
|
||||||
<td colSpan={categories.length} style={{ padding: 0, height: chartNode ? chartHeight : 0 }}>
|
<td colSpan={categories.length} style={{ padding: 0, height: chartNode ? chartHeight : 0 }}>
|
||||||
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr className="lg-table__subhead">
|
<tr className="lg-table__subhead">
|
||||||
{categories.map((c) => (
|
<th className="lg-table__sep-r"></th>
|
||||||
<th key={c} className={"content-text-xs"}>{c}</th>
|
<th className="content-text-xs">사례수</th>
|
||||||
|
{categories.map((category) => (
|
||||||
|
<th key={category} className="content-text-xs">
|
||||||
|
{category}
|
||||||
|
</th>
|
||||||
))}
|
))}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{rows.map((r, ri) => {
|
{rows.map((row, rowIndex) => {
|
||||||
const isSignRow = !!(signStyle?.rowSelector && signStyle.rowSelector(r, ri));
|
const signRow = !!signStyle?.rowSelector?.(row, rowIndex);
|
||||||
const cagrRow = isCagrRow(r.label as string ?? "");
|
const sampleRow = isSampleRow(row.label ?? "");
|
||||||
const total = parseNumber(r.total);
|
const cagrRow = isCagrRow(row.label ?? "");
|
||||||
|
const rowTotal = parseNumber(row.total);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr key={`${r.label}-${ri}`}>
|
<tr key={`${row.label}-${rowIndex}`}>
|
||||||
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
||||||
{r.label}
|
{row.label}
|
||||||
</th>
|
</th>
|
||||||
|
<td>
|
||||||
|
{row.sample}
|
||||||
|
</td>
|
||||||
|
|
||||||
{categories.map((_, ci) => {
|
{categories.map((_, categoryIndex) => {
|
||||||
const raw = r.values?.[ci];
|
const rawValue = row.values?.[categoryIndex];
|
||||||
const n = parseNumber(raw);
|
|
||||||
|
|
||||||
// 일반 행
|
if(sampleRow){
|
||||||
if (!isSignRow) {
|
return <td key={categoryIndex}>{rawValue}</td>;
|
||||||
if (n === null) return <td key={ci}>-</td>;
|
}
|
||||||
|
|
||||||
const isFill = fillCAGR && cagrRow && total && n > total + 5;
|
const roundedValue = toRoundedNumber(rawValue, cagrRow? 1 : 0);
|
||||||
const txt = n.toLocaleString();
|
|
||||||
return <td key={ci} className={cn(isFill? "bg-red-200" :"")}>{txt}</td>;
|
if (!signRow) {
|
||||||
|
if (roundedValue === null) {
|
||||||
|
return <td key={categoryIndex}>-</td>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sign row
|
const shouldFillCell = fillCAGR && cagrRow && rowTotal !== null && roundedValue >= rowTotal + 5;
|
||||||
if (n === null) return <td key={ci}>-</td>;
|
return <td key={categoryIndex} className={cn(shouldFillCell ? "bg-red-200" : "")}>{roundedValue.toLocaleString()}</td>;
|
||||||
if (n === 0) return <td key={ci}>{zeroText}</td>;
|
}
|
||||||
|
|
||||||
const cls = n > 0 ? posCls : negCls;
|
if (roundedValue === null) {
|
||||||
|
return <td key={categoryIndex}>-</td>;
|
||||||
|
}
|
||||||
|
|
||||||
if (display === "arrow") {
|
return (
|
||||||
const arrow = n > 0 ? "▲" : "▼";
|
<td key={categoryIndex} className={getSignTextClass(roundedValue, resolvedSignStyle)}>
|
||||||
const num = Math.abs(n);
|
{formatSignedValue(roundedValue, resolvedSignStyle)}
|
||||||
return (
|
</td>
|
||||||
<td key={ci} className={cls}>
|
);
|
||||||
{arrow}
|
})}
|
||||||
{arrowWithNumber ? ` ${num}` : ""}
|
</tr>
|
||||||
</td>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<td key={ci} className={cls}>
|
|
||||||
{formatSignedNumber(n, zeroText, showPlus)}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export { default as GroupedStackBar} from "./chart/GroupedStackBar";
|
|||||||
export { default as GroupedOverlayBar} from "./chart/GroupedOverlayBar";
|
export { default as GroupedOverlayBar} from "./chart/GroupedOverlayBar";
|
||||||
|
|
||||||
export { default as DataTable } from "./table/DataTable";
|
export { default as DataTable } from "./table/DataTable";
|
||||||
|
export type { DataTableProps } from "./table/DataTable";
|
||||||
|
export type { MergedTableCell } from "./table/BaseDataTable";
|
||||||
export { default as GaugeTable } from "./table/GaugeTable";
|
export { default as GaugeTable } from "./table/GaugeTable";
|
||||||
|
|
||||||
export { default as TopChartTable } from "./combo/TopChartTable";
|
export { default as TopChartTable } from "./combo/TopChartTable";
|
||||||
@@ -19,4 +21,4 @@ export { default as CategoryByData } from "./combo/CategoryByData"
|
|||||||
export { default as CardDefault } from "./card/Card";
|
export { default as CardDefault } from "./card/Card";
|
||||||
|
|
||||||
export { default as SectionTitle } from "./SectionTitle";
|
export { default as SectionTitle } from "./SectionTitle";
|
||||||
export { default as BottomDescription } from "./BottomDescription";
|
export { default as BottomDescription } from "./BottomDescription";
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
|
||||||
import {CategoryTargetData} from "@/config/filter.types";
|
|
||||||
import Profile from "./category-page/Profile";
|
|
||||||
import PenetrationChange from "./category-page/PenetrationChange";
|
|
||||||
import {BannerRow, CategoryResolvedField, StatisticsRequest} from "@/types/lg";
|
|
||||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
|
||||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
|
||||||
import {useMemo} from "react";
|
|
||||||
import {buildCategoryFilter, buildPageModeConfig} from "@/lib/lg-dashboard";
|
|
||||||
import {BANNER_GROUP_KEY} from "@/const/lgConst";
|
|
||||||
import {useBannerStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
|
||||||
import CategoryDetail from "@/components/lge-dashboard/sub-page/category-page/CategoryDetail";
|
|
||||||
|
|
||||||
export type CategoryPageProps = {
|
|
||||||
fields: CategoryResolvedField[];
|
|
||||||
variableIdMap: Record<string, string>;
|
|
||||||
dataMap:Record<string, BannerRow[]> | undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const PAGE_COMPONENTS: Partial<Record<CategoryTargetData, React.ComponentType<CategoryPageProps>>> = {
|
|
||||||
[CategoryTargetData.PROFILE]: Profile,
|
|
||||||
[CategoryTargetData.PENETRATION_CHANGE]: PenetrationChange,
|
|
||||||
[CategoryTargetData.BRAND]: CategoryDetail,
|
|
||||||
[CategoryTargetData.TYPE_SPEC]: CategoryDetail,
|
|
||||||
[CategoryTargetData.BEHAVIOR]: CategoryDetail,
|
|
||||||
[CategoryTargetData.PURCHASE_CHANNEL]: CategoryDetail,
|
|
||||||
[CategoryTargetData.PAYMENT_METHOD]: CategoryDetail,
|
|
||||||
};
|
|
||||||
|
|
||||||
const CategoryPage = () => {
|
|
||||||
const { isTotal, filterValue } = useLayoutFilter();
|
|
||||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
|
||||||
|
|
||||||
const { fields, variableIdMap } = useMemo(() => {
|
|
||||||
return buildPageModeConfig(debouncedFilterValue);
|
|
||||||
}, [debouncedFilterValue]);
|
|
||||||
|
|
||||||
const req = useMemo<StatisticsRequest>(() => {
|
|
||||||
return {
|
|
||||||
variableIdMap,
|
|
||||||
bannerIdList: BANNER_GROUP_KEY,
|
|
||||||
filterCondition: buildCategoryFilter(debouncedFilterValue),
|
|
||||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
|
||||||
};
|
|
||||||
}, [variableIdMap, debouncedFilterValue]);
|
|
||||||
|
|
||||||
const { data } = useBannerStatisticsQuery(req);
|
|
||||||
const dataMap = data?.statisticsDataMap;
|
|
||||||
const target = debouncedFilterValue.target;
|
|
||||||
const Comp = PAGE_COMPONENTS[target.value]
|
|
||||||
|
|
||||||
if(isTotal) return null;
|
|
||||||
return Comp ? <Comp fields={fields} variableIdMap={variableIdMap} dataMap={dataMap} /> : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default CategoryPage;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
|
||||||
import {useMemo} from "react";
|
|
||||||
import {BannerRow} from "@/types/lg";
|
|
||||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
|
||||||
import {LAST_YEAR} from "@/const/lgConst";
|
|
||||||
|
|
||||||
const PenetrationChange = ({
|
|
||||||
dataMap
|
|
||||||
}:CategoryPageProps) => {
|
|
||||||
|
|
||||||
const penetrationChangeData = useMemo<BannerRow[]>(() => {
|
|
||||||
if (dataMap === undefined) return [];
|
|
||||||
|
|
||||||
const tempProfileData: BannerRow[] = [];
|
|
||||||
Object.keys(dataMap).forEach(requestKey => {
|
|
||||||
const data = dataMap[requestKey];
|
|
||||||
tempProfileData.push(
|
|
||||||
...data.filter((r) => r.rowLabel === `사례수` && r.year === LAST_YEAR),
|
|
||||||
...data.filter((r) => r.rowLabel === `보유`)
|
|
||||||
.map((row) => {
|
|
||||||
return {
|
|
||||||
...row,
|
|
||||||
rowLabel: row.year,
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(tempProfileData)
|
|
||||||
|
|
||||||
return tempProfileData;
|
|
||||||
}, [dataMap]);
|
|
||||||
|
|
||||||
return(
|
|
||||||
<BannerSummary data={penetrationChangeData} useChart={true} useYear={false} />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PenetrationChange
|
|
||||||
176
src/components/lge-dashboard/table/BaseDataTable.tsx
Normal file
176
src/components/lge-dashboard/table/BaseDataTable.tsx
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type React from "react";
|
||||||
|
import { cn, parseNumber } from "@/lib/utils";
|
||||||
|
import {isGapRow, isHasCountRow, isSampleRow} from "@/lib/lg-dashboard";
|
||||||
|
import type { DataColumn, SignStyle } from "../types";
|
||||||
|
import BaseTableRenderer from "./core/BaseTableRenderer";
|
||||||
|
import {
|
||||||
|
appendCellMarker,
|
||||||
|
formatSignedValue,
|
||||||
|
getColumnAlign,
|
||||||
|
getLeafColumns,
|
||||||
|
getSignCellBackground,
|
||||||
|
getSignTextClass,
|
||||||
|
resolveSignStyle,
|
||||||
|
shouldApplySignToColumn,
|
||||||
|
toRoundedNumber,
|
||||||
|
toTableCellContent,
|
||||||
|
type ResolvedSignStyle,
|
||||||
|
} from "./core/table-core.helpers";
|
||||||
|
import {VIEW_DECIMAL_POINT} from "@/const/lg-common.const";
|
||||||
|
|
||||||
|
export type MergedTableCell<T> = {
|
||||||
|
key: keyof T;
|
||||||
|
content: React.ReactNode;
|
||||||
|
startRowIndex?: number;
|
||||||
|
rowSpan?: number;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Props<T extends Record<string, unknown>> = {
|
||||||
|
columns: DataColumn<T>[];
|
||||||
|
rows: T[];
|
||||||
|
title?: string;
|
||||||
|
wrapperClassName?: string;
|
||||||
|
tableClassName?: string;
|
||||||
|
subheadRowClassName?: string;
|
||||||
|
minWidth?: number;
|
||||||
|
signStyle?: SignStyle<T>;
|
||||||
|
signStyleFallback?: Partial<ResolvedSignStyle>;
|
||||||
|
fillGreaterThan5?: boolean;
|
||||||
|
fillGapRow?: boolean;
|
||||||
|
starUnder30Sample?: boolean;
|
||||||
|
unitText?: string;
|
||||||
|
mergedCells?: MergedTableCell<T>[];
|
||||||
|
getCellClassName?: (row: T, column: DataColumn<T>, rowIndex: number) => string | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||||
|
columns,
|
||||||
|
rows,
|
||||||
|
title,
|
||||||
|
wrapperClassName,
|
||||||
|
tableClassName,
|
||||||
|
subheadRowClassName,
|
||||||
|
minWidth,
|
||||||
|
signStyle,
|
||||||
|
signStyleFallback,
|
||||||
|
fillGreaterThan5 = false,
|
||||||
|
fillGapRow = false,
|
||||||
|
starUnder30Sample = false,
|
||||||
|
unitText,
|
||||||
|
mergedCells,
|
||||||
|
getCellClassName,
|
||||||
|
}: Readonly<Props<T>>) {
|
||||||
|
const resolvedSignStyle = resolveSignStyle(signStyle, signStyleFallback);
|
||||||
|
const leafColumns = getLeafColumns(columns);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BaseTableRenderer
|
||||||
|
columns={columns}
|
||||||
|
title={title}
|
||||||
|
unitText={unitText}
|
||||||
|
showSampleNotice={starUnder30Sample}
|
||||||
|
wrapperClassName={wrapperClassName}
|
||||||
|
tableClassName={tableClassName}
|
||||||
|
subheadRowClassName={subheadRowClassName}
|
||||||
|
minWidth={minWidth}
|
||||||
|
>
|
||||||
|
{rows.map((row, rowIndex) => {
|
||||||
|
const rowLabel = (row.rowLabel as string) ?? "";
|
||||||
|
const sampleRow = isSampleRow(rowLabel);
|
||||||
|
const hasCountRow = isHasCountRow(rowLabel);
|
||||||
|
const signRow = !!signStyle?.rowSelector?.(row, rowIndex);
|
||||||
|
const rowTotal = parseNumber(row.total);
|
||||||
|
const isFillGapRow = fillGapRow && isGapRow(rowLabel)
|
||||||
|
const fillGapClass = isFillGapRow ? "bg-gray-100" : "";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr key={rowIndex}>
|
||||||
|
{leafColumns.map((column) => {
|
||||||
|
const dynamicCellClassName = getCellClassName?.(row, column, rowIndex);
|
||||||
|
const mergedCell = mergedCells?.find((cell) => {
|
||||||
|
const startRowIndex = cell.startRowIndex ?? 0;
|
||||||
|
const rowSpan = cell.rowSpan ?? Math.max(0, rows.length - startRowIndex);
|
||||||
|
|
||||||
|
return column.key === cell.key && rowIndex >= startRowIndex && rowIndex < startRowIndex + rowSpan;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mergedCell) {
|
||||||
|
const mergedCellStart = mergedCell.startRowIndex ?? 0;
|
||||||
|
const mergedCellSpan = mergedCell.rowSpan ?? Math.max(0, rows.length - mergedCellStart);
|
||||||
|
|
||||||
|
if (rowIndex > mergedCellStart) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
key={String(column.key)}
|
||||||
|
rowSpan={mergedCellSpan}
|
||||||
|
className={cn(column.cellClassName, mergedCell.className)}
|
||||||
|
style={{ padding: 0, verticalAlign: "middle" }}
|
||||||
|
>
|
||||||
|
{mergedCell.content}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawValue = row[column.key];
|
||||||
|
const align = getColumnAlign(column);
|
||||||
|
const viewDecimalPoint = hasCountRow ? 2 : VIEW_DECIMAL_POINT;
|
||||||
|
const defaultContent = column.render ? column.render(row) : toTableCellContent(rawValue, viewDecimalPoint);
|
||||||
|
const numericValue = "numeric" in column && column.numeric ? parseNumber(rawValue ?? defaultContent) ?? 0 : 0;
|
||||||
|
const applySign = signRow && shouldApplySignToColumn(column, signStyle);
|
||||||
|
|
||||||
|
if (column.rowHead) {
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
key={String(column.key)}
|
||||||
|
scope="row"
|
||||||
|
className={cn("lg-table__rowhead", column.cellClassName, dynamicCellClassName, fillGapClass)}
|
||||||
|
style={{ textAlign: align }}
|
||||||
|
>
|
||||||
|
{defaultContent}
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applySign) {
|
||||||
|
const roundedValue = toRoundedNumber(rawValue);
|
||||||
|
const displayText = roundedValue === null ? "-" : formatSignedValue(roundedValue, resolvedSignStyle);
|
||||||
|
const cellStyle: React.CSSProperties =
|
||||||
|
resolvedSignStyle.paint === "cell"
|
||||||
|
? { textAlign: align, background: getSignCellBackground(roundedValue ?? 0, resolvedSignStyle) }
|
||||||
|
: { textAlign: align };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<td key={String(column.key)} className={cn(column.cellClassName, dynamicCellClassName, fillGapClass)} style={cellStyle}>
|
||||||
|
<span className={cn(roundedValue === null ? "text-gray-500" : getSignTextClass(roundedValue, resolvedSignStyle))}>
|
||||||
|
{displayText}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldFillCell = fillGreaterThan5 && rowTotal !== null && numericValue >= rowTotal + 5;
|
||||||
|
const shouldMarkSample = starUnder30Sample && sampleRow && numericValue < 30;
|
||||||
|
const displayContent = shouldMarkSample ? appendCellMarker(defaultContent, "*") : defaultContent;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
key={String(column.key)}
|
||||||
|
className={cn(column.cellClassName, dynamicCellClassName, fillGapClass, shouldFillCell ? "bg-red-200" : "")}
|
||||||
|
style={{ textAlign: align }}
|
||||||
|
>
|
||||||
|
{displayContent}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</BaseTableRenderer>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,55 +1,23 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMemo } from "react";
|
import type { DataColumn, SignStyle } from "../types";
|
||||||
import type React from "react";
|
import { UNIT_TEXT } from "@/const/lg-common.const";
|
||||||
import { cn, parseNumber } from "@/lib/utils";
|
import BaseDataTable, { type MergedTableCell } from "./BaseDataTable";
|
||||||
import type { DataColumn, SignDisplayMode, SignStyle } from "../types";
|
|
||||||
import SectionTitle from "../SectionTitle";
|
|
||||||
import {isCagrRow, isSampleRow} from "@/lib/lg-dashboard";
|
|
||||||
import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
|
||||||
|
|
||||||
type Props<T extends Record<string, unknown>> = {
|
export type DataTableProps<T extends Record<string, unknown>> = {
|
||||||
columns: DataColumn<T>[];
|
columns: DataColumn<T>[];
|
||||||
rows: T[];
|
rows: T[];
|
||||||
title?: string;
|
title?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
tableClassName?: string;
|
||||||
wrapperClassName?: string;
|
wrapperClassName?: string;
|
||||||
|
subheadRowClassName?: string;
|
||||||
signStyle?: SignStyle<T>;
|
signStyle?: SignStyle<T>;
|
||||||
fillGreaterThan5?: boolean;
|
fillGreaterThan5?: boolean;
|
||||||
fillCAGR?: boolean;
|
fillGapRow?: boolean;
|
||||||
starUnder30Sample?: boolean;
|
starUnder30Sample?: boolean;
|
||||||
unitText?: string;
|
unitText?: string;
|
||||||
};
|
mergedCells?: MergedTableCell<T>[];
|
||||||
|
|
||||||
// parseSignedNumber는 utils.ts의 parseNumber로 통합됨
|
|
||||||
|
|
||||||
const defaultFmt = (v: number) =>
|
|
||||||
Number.isInteger(v) ? String(v) : v.toLocaleString();
|
|
||||||
|
|
||||||
const signText = (
|
|
||||||
v: number,
|
|
||||||
display: SignDisplayMode,
|
|
||||||
showPlus: boolean,
|
|
||||||
arrowWithNumber: boolean,
|
|
||||||
fmt: (n: number) => string,
|
|
||||||
zeroText: string
|
|
||||||
) => {
|
|
||||||
if (display === "arrow") {
|
|
||||||
if (v > 0) return arrowWithNumber ? `▲ ${fmt(Math.abs(v))}` : "▲";
|
|
||||||
if (v < 0) return arrowWithNumber ? `▼ ${fmt(Math.abs(v))}` : "▼";
|
|
||||||
return zeroText;
|
|
||||||
}
|
|
||||||
|
|
||||||
// number
|
|
||||||
if (v > 0) return showPlus ? `+${fmt(v)}` : fmt(v);
|
|
||||||
if (v < 0) return fmt(v); // 음수는 기본적으로 - 포함
|
|
||||||
return zeroText;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toCellContent = (raw: unknown): React.ReactNode => {
|
|
||||||
if (raw == null) return "";
|
|
||||||
if (typeof raw === "string" || typeof raw === "number") return raw;
|
|
||||||
return String(raw);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const DataTable = <T extends Record<string, unknown>>({
|
const DataTable = <T extends Record<string, unknown>>({
|
||||||
@@ -57,211 +25,32 @@ const DataTable = <T extends Record<string, unknown>>({
|
|||||||
rows,
|
rows,
|
||||||
title,
|
title,
|
||||||
className,
|
className,
|
||||||
|
tableClassName,
|
||||||
wrapperClassName,
|
wrapperClassName,
|
||||||
|
subheadRowClassName,
|
||||||
signStyle,
|
signStyle,
|
||||||
fillGreaterThan5 = false,
|
fillGreaterThan5 = false,
|
||||||
fillCAGR = false,
|
fillGapRow = false,
|
||||||
starUnder30Sample = false,
|
starUnder30Sample = false,
|
||||||
unitText = UNIT_TEXT,
|
unitText = UNIT_TEXT,
|
||||||
}: Props<T>) => {
|
mergedCells,
|
||||||
const hasGroup = columns.some((c) => !!c.group) || columns.some((c) => c.headRowSpan === 2);
|
}: DataTableProps<T>) => {
|
||||||
|
|
||||||
// group header(1행): rowspan=2 컬럼(th) + group label(colspan)
|
|
||||||
const groupCells = useMemo(() => {
|
|
||||||
type GroupCell =
|
|
||||||
| { kind: "rowspan"; label: string; colSpan: 1; rowSpan: 2; className?: string }
|
|
||||||
| { kind: "group"; label: string; colSpan: number; rowSpan: 1; className?: string }
|
|
||||||
| { kind: "blank"; label: string; colSpan: 1; rowSpan: 1; className?: string };
|
|
||||||
|
|
||||||
if (!hasGroup) return [] as GroupCell[];
|
|
||||||
|
|
||||||
const res: GroupCell[] = [];
|
|
||||||
let i = 0;
|
|
||||||
|
|
||||||
while (i < columns.length) {
|
|
||||||
const c = columns[i];
|
|
||||||
|
|
||||||
if (c.headRowSpan === 2) {
|
|
||||||
res.push({ kind: "rowspan", label: c.header, colSpan: 1, rowSpan: 2, className: c.headerClassName });
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const g = c.group;
|
|
||||||
if (!g) {
|
|
||||||
// group 미지정: 1칸짜리 blank group 셀
|
|
||||||
res.push({ kind: "blank", label: "", colSpan: 1, rowSpan: 1, className: c.headerClassName });
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 같은 group 연속 구간 colSpan
|
|
||||||
let span = 1;
|
|
||||||
let j = i + 1;
|
|
||||||
while (j < columns.length && columns[j].headRowSpan !== 2 && columns[j].group === g) {
|
|
||||||
span++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
res.push({ kind: "group", label: g, colSpan: span, rowSpan: 1, className: c.headerClassName });
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}, [columns, hasGroup]);
|
|
||||||
|
|
||||||
const {
|
|
||||||
rowSelector,
|
|
||||||
keys,
|
|
||||||
paint = "text",
|
|
||||||
display = "number",
|
|
||||||
showPlus = true,
|
|
||||||
arrowWithNumber = false,
|
|
||||||
zeroText = "-",
|
|
||||||
valueFormatter,
|
|
||||||
positiveTextClassName = "text-primary font-semibold",
|
|
||||||
negativeTextClassName = "text-info font-semibold",
|
|
||||||
zeroTextClassName = "text-gray-600",
|
|
||||||
positiveCellBg = "hsl(var(--primary) / 0.08)",
|
|
||||||
negativeCellBg = "hsl(var(--info) / 0.08)",
|
|
||||||
zeroCellBg = "hsl(var(--lg-gray-200) / 0.6)",
|
|
||||||
} = signStyle ?? ({} as SignStyle<T>);
|
|
||||||
|
|
||||||
const fmt = valueFormatter ?? defaultFmt;
|
|
||||||
|
|
||||||
const isSignRow = (row: T, rowIndex: number) =>
|
|
||||||
!!signStyle && !!rowSelector?.(row, rowIndex);
|
|
||||||
|
|
||||||
const isTargetKey = (k: keyof T) => {
|
|
||||||
if (!signStyle) return false;
|
|
||||||
if (keys && keys.length) return keys.includes(k);
|
|
||||||
// keys 미지정이면 numeric 컬럼 전체
|
|
||||||
const col = columns.find((c) => c.key === k);
|
|
||||||
return !!col?.numeric;
|
|
||||||
};
|
|
||||||
|
|
||||||
const signClass = (v: number) => {
|
|
||||||
if (v > 0) return positiveTextClassName;
|
|
||||||
if (v < 0) return negativeTextClassName;
|
|
||||||
return zeroTextClassName;
|
|
||||||
};
|
|
||||||
|
|
||||||
const signBg = (v: number) => {
|
|
||||||
if (v > 0) return positiveCellBg;
|
|
||||||
if (v < 0) return negativeCellBg;
|
|
||||||
return zeroCellBg;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
<BaseDataTable
|
||||||
<div className="mb-2 flex items-center justify-between">
|
columns={columns}
|
||||||
{ title && <SectionTitle title={title} />}
|
rows={rows}
|
||||||
{
|
title={title}
|
||||||
(unitText || starUnder30Sample) &&
|
tableClassName={tableClassName ?? className}
|
||||||
<div className="ml-auto text-gray-500 content-text-xs font-semibold text-right">
|
wrapperClassName={wrapperClassName}
|
||||||
{unitText}
|
subheadRowClassName={subheadRowClassName}
|
||||||
{starUnder30Sample && <><br/>{SAMPLE_SIZE_NOTICE}</>}
|
signStyle={signStyle}
|
||||||
</div>
|
fillGreaterThan5={fillGreaterThan5}
|
||||||
}
|
fillGapRow={fillGapRow}
|
||||||
</div>
|
starUnder30Sample={starUnder30Sample}
|
||||||
<table className={cn("lg-table", className)}>
|
unitText={unitText}
|
||||||
<thead>
|
mergedCells={mergedCells}
|
||||||
{hasGroup && (
|
/>
|
||||||
<tr className="lg-table__group">
|
|
||||||
{groupCells.map((g, idx) => (
|
|
||||||
<th
|
|
||||||
key={`${g.kind}-${g.label}-${idx}`}
|
|
||||||
colSpan={g.colSpan}
|
|
||||||
rowSpan={g.rowSpan}
|
|
||||||
className={g.className}
|
|
||||||
>
|
|
||||||
{g.label}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
|
||||||
{columns
|
|
||||||
.filter((c) => c.headRowSpan !== 2)
|
|
||||||
.map((c) => (
|
|
||||||
<th key={String(c.key)} style={{ width: c.width }} className={c.headerClassName}>
|
|
||||||
{c.header}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
{rows.map((row, rIdx) => {
|
|
||||||
const sampleRow = isSampleRow(row.rowLabel as string ?? "");
|
|
||||||
const signRow = isSignRow(row, rIdx);
|
|
||||||
const total = parseNumber(row.total);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<tr key={rIdx}>
|
|
||||||
{columns.map((c) => {
|
|
||||||
const raw: unknown = c.key ? (row[c.key] as unknown) : undefined;
|
|
||||||
const align = c.align ?? (c.numeric ? "right" : "center");
|
|
||||||
|
|
||||||
// headRowSpan=2 컬럼은 thead 2행에서 제외되므로, tbody는 항상 렌더
|
|
||||||
|
|
||||||
// sign row + target column이면 색상/표기 적용
|
|
||||||
const applySign = signRow && isTargetKey(c.key) && !c.rowHead;
|
|
||||||
|
|
||||||
if (applySign) {
|
|
||||||
const n = parseNumber(raw);
|
|
||||||
const displayText =
|
|
||||||
n === null ? "-" : signText(n, display, showPlus, arrowWithNumber, fmt, zeroText);
|
|
||||||
|
|
||||||
const style: React.CSSProperties =
|
|
||||||
paint === "cell"
|
|
||||||
? { textAlign: align, background: signBg(n ?? 0) }
|
|
||||||
: { textAlign: align };
|
|
||||||
|
|
||||||
return (
|
|
||||||
<td key={String(c.key)} style={style} className={c.cellClassName}>
|
|
||||||
<span className={cn(n === null ? "text-gray-500" : signClass(n))}>
|
|
||||||
{displayText}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 일반 셀
|
|
||||||
const content: React.ReactNode = c.render
|
|
||||||
? c.render(row)
|
|
||||||
: toCellContent(raw);
|
|
||||||
|
|
||||||
if (c.rowHead) {
|
|
||||||
return (
|
|
||||||
<th
|
|
||||||
key={String(c.key)}
|
|
||||||
className={cn("lg-table__rowhead", c.cellClassName)}
|
|
||||||
style={{ textAlign: align }}
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</th>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const numContent = c.numeric ? parseNumber(content) ?? 0 : 0;
|
|
||||||
const isFill = fillGreaterThan5 && total && numContent > total + 5;
|
|
||||||
const isStar = starUnder30Sample && sampleRow && numContent < 30;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<td key={String(c.key)} style={{ textAlign: align }} className={
|
|
||||||
cn(c.cellClassName, isFill? "bg-red-200" :"")
|
|
||||||
}>
|
|
||||||
{isStar?`${content}*`:content}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default DataTable;
|
export default DataTable;
|
||||||
|
|||||||
@@ -1,204 +1,114 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useMemo } from "react";
|
|
||||||
import { cn, parseNumber } from "@/lib/utils";
|
import { cn, parseNumber } from "@/lib/utils";
|
||||||
import {GaugeColumn} from "../types";
|
import { roundNumber } from "@/lib/lg-dashboard";
|
||||||
|
import type { GaugeColumn } from "../types";
|
||||||
|
import BaseTableRenderer from "./core/BaseTableRenderer";
|
||||||
|
import { getColumnAlign, getLeafColumns, toTableCellContent } from "./core/table-core.helpers";
|
||||||
|
|
||||||
type Props<T extends Record<string, unknown>> = {
|
type Props<T extends Record<string, unknown>> = {
|
||||||
columns: GaugeColumn<T>[];
|
columns: GaugeColumn<T>[];
|
||||||
rows: T[];
|
rows: T[];
|
||||||
className?: string;
|
className?: string;
|
||||||
|
tableClassName?: string;
|
||||||
wrapperClassName?: string;
|
wrapperClassName?: string;
|
||||||
|
scale?: number;
|
||||||
/** value가 0~100이 아니라 0~1이면 scale=100 */
|
fillColor?: string;
|
||||||
scale?: number; // 기본 1
|
trackColor?: string;
|
||||||
|
cellHeight?: number;
|
||||||
/** 색상(기본: primary 채움 + gray 트랙) */
|
valueFormatter?: (value: number) => string;
|
||||||
fillColor?: string; // ex) "hsl(var(--primary) / 0.9)"
|
|
||||||
trackColor?: string; // ex) "hsl(var(--lg-gray-200) / 0.9)"
|
|
||||||
|
|
||||||
/** 셀 높이 */
|
|
||||||
cellHeight?: number; // 기본 26
|
|
||||||
|
|
||||||
/** 숫자 표시 여부/포맷 */
|
|
||||||
valueFormatter?: (v: number) => string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// num은 utils.ts의 parseNumber로 통합됨
|
|
||||||
|
|
||||||
const GaugeTable = <T extends Record<string, unknown>>({
|
const GaugeTable = <T extends Record<string, unknown>>({
|
||||||
columns,
|
columns,
|
||||||
rows,
|
rows,
|
||||||
className,
|
className,
|
||||||
wrapperClassName,
|
tableClassName,
|
||||||
scale = 1,
|
wrapperClassName,
|
||||||
fillColor = "hsl(var(--lg-gray-200) / 0.85)",
|
scale = 1,
|
||||||
trackColor = "hsl(var(--lg-pink-300) / 0.2)",
|
fillColor = "hsl(var(--lg-gray-200) / 0.85)",
|
||||||
cellHeight = 26,
|
trackColor = "hsl(var(--lg-pink-300) / 0.2)",
|
||||||
valueFormatter,
|
cellHeight = 26,
|
||||||
}: Props<T>) => {
|
valueFormatter,
|
||||||
const hasGroup = columns.some((c) => !!c.group) || columns.some((c) => c.headRowSpan === 2);
|
}: Props<T>) => {
|
||||||
|
const formatValue = valueFormatter ?? ((value: number) => String(roundNumber(value)));
|
||||||
const groupCells = useMemo(() => {
|
const clampRatio = (value: number) => Math.max(0, Math.min(1, value));
|
||||||
type GroupCell =
|
const leafColumns = getLeafColumns(columns);
|
||||||
| { kind: "rowspan"; label: string; colSpan: 1; rowSpan: 2; className?: string }
|
|
||||||
| { kind: "group"; label: string; colSpan: number; rowSpan: 1; className?: string }
|
|
||||||
| { kind: "blank"; label: string; colSpan: 1; rowSpan: 1; className?: string };
|
|
||||||
|
|
||||||
if (!hasGroup) return [] as GroupCell[];
|
|
||||||
|
|
||||||
const res: GroupCell[] = [];
|
|
||||||
let i = 0;
|
|
||||||
|
|
||||||
while (i < columns.length) {
|
|
||||||
const c = columns[i];
|
|
||||||
|
|
||||||
if (c.headRowSpan === 2) {
|
|
||||||
res.push({ kind: "rowspan", label: c.header, colSpan: 1, rowSpan: 2 });
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const g = c.group;
|
|
||||||
if (!g) {
|
|
||||||
// group 미지정: 1칸짜리 blank group 셀
|
|
||||||
res.push({ kind: "blank", label: "", colSpan: 1, rowSpan: 1 });
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 같은 group 연속 구간 colSpan
|
|
||||||
let span = 1;
|
|
||||||
let j = i + 1;
|
|
||||||
while (j < columns.length && columns[j].headRowSpan !== 2 && columns[j].group === g) {
|
|
||||||
span++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
res.push({ kind: "group", label: g, colSpan: span, rowSpan: 1 });
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}, [columns, hasGroup]);
|
|
||||||
|
|
||||||
const fmt = valueFormatter ?? ((v: number) => String(Math.round(v)));
|
|
||||||
|
|
||||||
const clamp01 = (n: number) => Math.max(0, Math.min(1, n));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
<BaseTableRenderer
|
||||||
<table className={cn("lg-table", className)} style={{minWidth:"100%"}}>
|
columns={columns}
|
||||||
<colgroup>
|
wrapperClassName={wrapperClassName}
|
||||||
{columns.map((c, i) => (
|
tableClassName={tableClassName ?? className}
|
||||||
<col
|
minWidth="100%"
|
||||||
key={`${String(c.key)}-${i}`}
|
colgroup={
|
||||||
style={{
|
<colgroup>
|
||||||
width:
|
{leafColumns.map((column, index) => (
|
||||||
c.width ??
|
<col
|
||||||
(c.rowHead ? 50 : 40), // 기본 폭(필요시 숫자 조절)
|
key={`${String(column.key)}-${index}`}
|
||||||
}}
|
style={{
|
||||||
/>
|
width: column.width ?? (column.rowHead ? 50 : 40),
|
||||||
))}
|
}}
|
||||||
</colgroup>
|
/>
|
||||||
<thead>
|
|
||||||
{hasGroup && (
|
|
||||||
<tr className="lg-table__group">
|
|
||||||
{groupCells.map((g, idx) => (
|
|
||||||
<th
|
|
||||||
key={`${g.kind}-${g.label}-${idx}`}
|
|
||||||
colSpan={g.colSpan}
|
|
||||||
rowSpan={g.rowSpan}
|
|
||||||
className={g.className}
|
|
||||||
>
|
|
||||||
{g.label}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
|
||||||
{columns.filter((c) => c.headRowSpan !== 2).map((c) => (
|
|
||||||
<th key={String(c.key)}>
|
|
||||||
{c.header}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
{rows.map((row, rIdx) => (
|
|
||||||
<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];
|
|
||||||
const label = c.render
|
|
||||||
? c.render(row)
|
|
||||||
: raw === null || raw === undefined
|
|
||||||
? ""
|
|
||||||
: typeof raw === "string" || typeof raw === "number"
|
|
||||||
? raw
|
|
||||||
: String(raw);
|
|
||||||
return (
|
|
||||||
<th
|
|
||||||
key={String(c.key)}
|
|
||||||
className="lg-table__rowhead"
|
|
||||||
style={{ textAlign: align }}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</th>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const raw = row[c.key];
|
|
||||||
const v = parseNumber(raw);
|
|
||||||
const max = c.max ?? 100;
|
|
||||||
const ratio = v === null ? 0 : clamp01((v * scale) / max);
|
|
||||||
const pct = ratio * 100;
|
|
||||||
|
|
||||||
const fill = fillColor;
|
|
||||||
const track = trackColor;
|
|
||||||
|
|
||||||
const cellBg =
|
|
||||||
v === null
|
|
||||||
? undefined
|
|
||||||
: `linear-gradient(to right, ${fill} ${pct}%, ${track} 0%)`;
|
|
||||||
|
|
||||||
if (cellType === "number") {
|
|
||||||
return (
|
|
||||||
<td
|
|
||||||
key={String(c.key)}
|
|
||||||
className="px-2 content-text-sm"
|
|
||||||
style={{ textAlign: align }}
|
|
||||||
>
|
|
||||||
{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>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</colgroup>
|
||||||
</table>
|
}
|
||||||
</div>
|
>
|
||||||
);
|
{rows.map((row, rowIndex) => (
|
||||||
}
|
<tr key={rowIndex}>
|
||||||
|
{leafColumns.map((column) => {
|
||||||
|
const align = getColumnAlign(column);
|
||||||
|
|
||||||
export default GaugeTable;
|
if (column.rowHead) {
|
||||||
|
const content = column.render ? column.render(row) : toTableCellContent(row[column.key]);
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
key={String(column.key)}
|
||||||
|
scope="row"
|
||||||
|
className={cn("lg-table__rowhead", column.cellClassName)}
|
||||||
|
style={{ textAlign: align }}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawValue = row[column.key];
|
||||||
|
const numericValue = parseNumber(rawValue);
|
||||||
|
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 (("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)}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
key={String(column.key)}
|
||||||
|
className={cn("px-2 content-text-sm", column.cellClassName)}
|
||||||
|
style={{
|
||||||
|
textAlign: "left",
|
||||||
|
height: cellHeight,
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
background,
|
||||||
|
backgroundClip: "padding-box",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{numericValue === null ? "-" : formatValue(numericValue)}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</BaseTableRenderer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GaugeTable;
|
||||||
|
|||||||
31
src/components/lge-dashboard/table/core/BaseTableHeader.tsx
Normal file
31
src/components/lge-dashboard/table/core/BaseTableHeader.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import SectionTitle from "../../SectionTitle";
|
||||||
|
import { SAMPLE_SIZE_NOTICE } from "@/const/lg-common.const";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title?: string;
|
||||||
|
unitText?: string;
|
||||||
|
showSampleNotice?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function BaseTableHeader({ title, unitText, showSampleNotice = false }: Props) {
|
||||||
|
if (!title && !unitText && !showSampleNotice) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mb-2 flex items-center justify-between">
|
||||||
|
{title ? <SectionTitle title={title} /> : <div />}
|
||||||
|
{unitText || showSampleNotice ? (
|
||||||
|
<div className="ml-auto text-right text-gray-500 content-text-xs font-semibold">
|
||||||
|
{unitText}
|
||||||
|
{showSampleNotice ? (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
{SAMPLE_SIZE_NOTICE}
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type React from "react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { DataColumn, GaugeColumn } from "../../types";
|
||||||
|
import BaseTableHeader from "./BaseTableHeader";
|
||||||
|
import { buildHeaderRows } from "./table-core.helpers";
|
||||||
|
|
||||||
|
type BaseColumn<T> = DataColumn<T> | GaugeColumn<T>;
|
||||||
|
|
||||||
|
type Props<T> = {
|
||||||
|
columns: BaseColumn<T>[];
|
||||||
|
title?: string;
|
||||||
|
unitText?: string;
|
||||||
|
showSampleNotice?: boolean;
|
||||||
|
wrapperClassName?: string;
|
||||||
|
tableClassName?: string;
|
||||||
|
subheadRowClassName?: string;
|
||||||
|
minWidth?: number | string;
|
||||||
|
colgroup?: React.ReactNode;
|
||||||
|
renderHeaderPrefix?: React.ReactNode;
|
||||||
|
children: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function BaseTableRenderer<T>({
|
||||||
|
columns,
|
||||||
|
title,
|
||||||
|
unitText,
|
||||||
|
showSampleNotice = false,
|
||||||
|
wrapperClassName,
|
||||||
|
tableClassName,
|
||||||
|
subheadRowClassName,
|
||||||
|
minWidth,
|
||||||
|
colgroup,
|
||||||
|
renderHeaderPrefix,
|
||||||
|
children,
|
||||||
|
}: Readonly<Props<T>>) {
|
||||||
|
const headerRows = buildHeaderRows(columns);
|
||||||
|
const lastHeaderRowIndex = headerRows.length - 1;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("w-full", wrapperClassName)}>
|
||||||
|
<BaseTableHeader title={title} unitText={unitText} showSampleNotice={showSampleNotice} />
|
||||||
|
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table
|
||||||
|
className={cn("lg-table", tableClassName)}
|
||||||
|
style={minWidth === undefined ? undefined : { minWidth: typeof minWidth === "number" ? `${minWidth}px` : minWidth }}
|
||||||
|
>
|
||||||
|
{colgroup}
|
||||||
|
<thead>
|
||||||
|
{renderHeaderPrefix}
|
||||||
|
{headerRows.map((row, rowIndex) => (
|
||||||
|
<tr
|
||||||
|
key={`header-row-${rowIndex}`}
|
||||||
|
className={cn(rowIndex === lastHeaderRowIndex ? "lg-table__subhead" : "lg-table__group", rowIndex === lastHeaderRowIndex ? subheadRowClassName : undefined)}
|
||||||
|
>
|
||||||
|
{row.map((cell) => (
|
||||||
|
<th key={cell.id} colSpan={cell.colSpan} rowSpan={cell.rowSpan} className={cell.className}>
|
||||||
|
{cell.label}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</thead>
|
||||||
|
<tbody>{children}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
277
src/components/lge-dashboard/table/core/table-core.helpers.tsx
Normal file
277
src/components/lge-dashboard/table/core/table-core.helpers.tsx
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
import type React from "react";
|
||||||
|
import { parseNumber } from "@/lib/utils";
|
||||||
|
import { roundNumber } from "@/lib/lg-dashboard";
|
||||||
|
import type {
|
||||||
|
DataColumn,
|
||||||
|
DataColumnLeaf,
|
||||||
|
GaugeColumn,
|
||||||
|
GaugeColumnLeaf,
|
||||||
|
SignDisplayMode,
|
||||||
|
SignStyle,
|
||||||
|
ValueFormatter,
|
||||||
|
} from "../../types";
|
||||||
|
|
||||||
|
export type TableColumnNode<T> = DataColumn<T> | GaugeColumn<T>;
|
||||||
|
export type TableColumnLeaf<T> = DataColumnLeaf<T> | GaugeColumnLeaf<T>;
|
||||||
|
|
||||||
|
export type GroupHeaderCell = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
colSpan: number;
|
||||||
|
rowSpan: number;
|
||||||
|
className?: string;
|
||||||
|
isLeaf: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ResolvedSignStyle = {
|
||||||
|
paint: "text" | "cell";
|
||||||
|
display: SignDisplayMode;
|
||||||
|
showPlus: boolean;
|
||||||
|
arrowWithNumber: boolean;
|
||||||
|
zeroText: string;
|
||||||
|
valueFormatter: ValueFormatter;
|
||||||
|
positiveTextClassName: string;
|
||||||
|
negativeTextClassName: string;
|
||||||
|
zeroTextClassName: string;
|
||||||
|
positiveCellBg: string;
|
||||||
|
negativeCellBg: string;
|
||||||
|
zeroCellBg: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultValueFormatter: ValueFormatter = (value) =>
|
||||||
|
Number.isInteger(value) ? String(roundNumber(value)) : value.toLocaleString();
|
||||||
|
|
||||||
|
const defaultSignStyle: ResolvedSignStyle = {
|
||||||
|
paint: "text",
|
||||||
|
display: "number",
|
||||||
|
showPlus: true,
|
||||||
|
arrowWithNumber: false,
|
||||||
|
zeroText: "-",
|
||||||
|
valueFormatter: defaultValueFormatter,
|
||||||
|
positiveTextClassName: "text-primary font-semibold",
|
||||||
|
negativeTextClassName: "text-info font-semibold",
|
||||||
|
zeroTextClassName: "text-gray-600",
|
||||||
|
positiveCellBg: "hsl(var(--primary) / 0.08)",
|
||||||
|
negativeCellBg: "hsl(var(--info) / 0.08)",
|
||||||
|
zeroCellBg: "hsl(var(--lg-gray-200) / 0.6)",
|
||||||
|
};
|
||||||
|
|
||||||
|
function isColumnLeaf<T>(column: TableColumnNode<T>): column is TableColumnLeaf<T> {
|
||||||
|
return !("children" in column) || !column.children?.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLeafColumns<T>(columns: TableColumnNode<T>[]) {
|
||||||
|
const leaves: TableColumnLeaf<T>[] = [];
|
||||||
|
|
||||||
|
const visit = (nodes: TableColumnNode<T>[]) => {
|
||||||
|
nodes.forEach((node) => {
|
||||||
|
if (isColumnLeaf(node)) {
|
||||||
|
leaves.push(node);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
visit(node.children);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
visit(columns);
|
||||||
|
return leaves;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHeaderDepth<T>(columns: TableColumnNode<T>[]) {
|
||||||
|
const visit = (nodes: TableColumnNode<T>[], depth: number): number =>
|
||||||
|
nodes.reduce((maxDepth, node) => {
|
||||||
|
if (isColumnLeaf(node)) {
|
||||||
|
return Math.max(maxDepth, depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max(maxDepth, visit(node.children, depth + 1));
|
||||||
|
}, depth);
|
||||||
|
|
||||||
|
return columns.length ? visit(columns, 1) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLeafCount<T>(column: TableColumnNode<T>): number {
|
||||||
|
if (isColumnLeaf(column)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return column.children.reduce((sum, child) => sum + getLeafCount(child), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColSpan<T>(isLeaf: boolean, node: TableColumnNode<T>) {
|
||||||
|
if(node.colSpan){
|
||||||
|
return node.colSpan;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isLeaf ? 1 : getLeafCount(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildHeaderRows<T>(columns: TableColumnNode<T>[]) {
|
||||||
|
const depth = getHeaderDepth(columns);
|
||||||
|
|
||||||
|
if (!depth) {
|
||||||
|
return [] as GroupHeaderCell[][];
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = Array.from({ length: depth }, () => [] as GroupHeaderCell[]);
|
||||||
|
|
||||||
|
const visit = (nodes: TableColumnNode<T>[], level: number, path: string[]) => {
|
||||||
|
nodes.forEach((node, index) => {
|
||||||
|
const nodeId = node.id ?? (isColumnLeaf(node) ? String(node.key) : `${path.join(".") || "root"}:${index}:${node.header}`);
|
||||||
|
const nextPath = [...path, nodeId];
|
||||||
|
const isLeaf = isColumnLeaf(node);
|
||||||
|
const colSpan = getColSpan(isLeaf, node);
|
||||||
|
|
||||||
|
rows[level].push({
|
||||||
|
id: nextPath.join("/"),
|
||||||
|
label: node.header,
|
||||||
|
colSpan,
|
||||||
|
rowSpan: isLeaf ? depth - level : 1,
|
||||||
|
className: node.headerClassName,
|
||||||
|
isLeaf,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!isLeaf) {
|
||||||
|
visit(node.children, level + 1, nextPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
visit(columns, 0, []);
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasGroupedHeader<T>(columns: TableColumnNode<T>[]) {
|
||||||
|
return getHeaderDepth(columns) > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getColumnAlign<T>(column: TableColumnLeaf<T>, fallback: "left" | "center" | "right" = "center") {
|
||||||
|
if (column.align) {
|
||||||
|
return column.align;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("numeric" in column && column.numeric) {
|
||||||
|
return "right";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.rowHead) {
|
||||||
|
return "left";
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toTableCellContent(raw: unknown, decimalPoint?: number): React.ReactNode {
|
||||||
|
if (raw == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof raw === "string") {
|
||||||
|
const trimmed = raw.trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = Number(trimmed);
|
||||||
|
return Number.isNaN(parsed) ? raw : roundNumber(parsed, decimalPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof raw === "number") {
|
||||||
|
return String(roundNumber(raw));
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toRoundedNumber(raw: unknown, decimalPoint?: number) {
|
||||||
|
const parsed = parseNumber(raw);
|
||||||
|
return parsed === null ? null : roundNumber(parsed, decimalPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function appendCellMarker(content: React.ReactNode, marker: string) {
|
||||||
|
if (!marker) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof content === "string" || typeof content === "number") {
|
||||||
|
return `${content}${marker}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{content}
|
||||||
|
{marker}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveSignStyle<T>(signStyle?: SignStyle<T>, fallback?: Partial<ResolvedSignStyle>) {
|
||||||
|
return {
|
||||||
|
...defaultSignStyle,
|
||||||
|
...fallback,
|
||||||
|
...signStyle,
|
||||||
|
valueFormatter: signStyle?.valueFormatter ?? fallback?.valueFormatter ?? defaultSignStyle.valueFormatter,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shouldApplySignToColumn<T>(column: TableColumnLeaf<T>, signStyle?: SignStyle<T>) {
|
||||||
|
if (!signStyle || column.rowHead) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signStyle.keys?.length) {
|
||||||
|
return signStyle.keys.includes(column.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "numeric" in column ? !!column.numeric : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatSignedValue(
|
||||||
|
value: number,
|
||||||
|
options: Pick<ResolvedSignStyle, "arrowWithNumber" | "display" | "showPlus" | "valueFormatter" | "zeroText">
|
||||||
|
) {
|
||||||
|
if (options.display === "arrow") {
|
||||||
|
if (value > 0) {
|
||||||
|
return options.arrowWithNumber ? `▲${options.valueFormatter(Math.abs(value))}` : "▲";
|
||||||
|
}
|
||||||
|
if (value < 0) {
|
||||||
|
return options.arrowWithNumber ? `▼${options.valueFormatter(Math.abs(value))}` : "▼";
|
||||||
|
}
|
||||||
|
return options.zeroText;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value > 0) {
|
||||||
|
return options.showPlus ? `+${options.valueFormatter(value)}` : options.valueFormatter(value);
|
||||||
|
}
|
||||||
|
if (value < 0) {
|
||||||
|
return options.valueFormatter(value);
|
||||||
|
}
|
||||||
|
return options.zeroText;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSignTextClass(
|
||||||
|
value: number,
|
||||||
|
options: Pick<ResolvedSignStyle, "negativeTextClassName" | "positiveTextClassName" | "zeroTextClassName">
|
||||||
|
) {
|
||||||
|
if (value > 0) {
|
||||||
|
return options.positiveTextClassName;
|
||||||
|
}
|
||||||
|
if (value < 0) {
|
||||||
|
return options.negativeTextClassName;
|
||||||
|
}
|
||||||
|
return options.zeroTextClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSignCellBackground(
|
||||||
|
value: number,
|
||||||
|
options: Pick<ResolvedSignStyle, "negativeCellBg" | "positiveCellBg" | "zeroCellBg">
|
||||||
|
) {
|
||||||
|
if (value > 0) {
|
||||||
|
return options.positiveCellBg;
|
||||||
|
}
|
||||||
|
if (value < 0) {
|
||||||
|
return options.negativeCellBg;
|
||||||
|
}
|
||||||
|
return options.zeroCellBg;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type React from "react";
|
import type React from "react";
|
||||||
import {GAP_WORDING} from "@/const/lgConst";
|
import { GAP_WORDING } from "@/const/lg-common.const";
|
||||||
|
|
||||||
export type NewNumber = number | null | undefined;
|
export type NewNumber = number | null | undefined;
|
||||||
|
|
||||||
@@ -34,10 +34,10 @@ export type GroupedStackBarData = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type GroupedOverlayBarData = {
|
export type GroupedOverlayBarData = {
|
||||||
categories: string[]; // 제품
|
categories: string[]; // 제품
|
||||||
years: string[]; // 예: [24,25,26]
|
years: string[]; // 예: [24,25,26]
|
||||||
totalName?: string; // default: "전체"
|
totalName?: string; // default: "전체"
|
||||||
focusName?: string; // default: "LG"
|
focusName?: string; // default: "LG"
|
||||||
total: Array<Array<number | null>>; // [yearIndex][categoryIndex]
|
total: Array<Array<number | null>>; // [yearIndex][categoryIndex]
|
||||||
focus: Array<Array<number | null>>; // [yearIndex][categoryIndex]
|
focus: Array<Array<number | null>>; // [yearIndex][categoryIndex]
|
||||||
};
|
};
|
||||||
@@ -47,47 +47,62 @@ export type TopChartTableRow = {
|
|||||||
/** 좌측 rowhead 라벨 */
|
/** 좌측 rowhead 라벨 */
|
||||||
label: string;
|
label: string;
|
||||||
total: number | string | null | undefined;
|
total: number | string | null | undefined;
|
||||||
|
sample: number | string | null | undefined;
|
||||||
/** categories 순서대로 값 */
|
/** categories 순서대로 값 */
|
||||||
values: Array<number | string | null | undefined>;
|
values: Array<number | string | null | undefined>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ValueFormatter = (v: number) => string;
|
export type ValueFormatter = (v: number) => string;
|
||||||
|
|
||||||
export type DataColumn<T> = {
|
export type TableColumnAlign = "left" | "center" | "right";
|
||||||
key: keyof T;
|
|
||||||
|
type TableColumnShared<T> = {
|
||||||
|
id?: string;
|
||||||
header: string;
|
header: string;
|
||||||
width?: number | string;
|
width?: number | string;
|
||||||
align?: "left" | "center" | "right";
|
align?: TableColumnAlign;
|
||||||
group?: string; // 2단 헤더 그룹
|
|
||||||
groupKey?:string;// 2단 헤더 그룹
|
|
||||||
|
|
||||||
/** group header에서 해당 컬럼 헤더를 rowspan=2로 올릴 때 사용(HTML 테이블과 동일한 구조 지원) */
|
|
||||||
headRowSpan?: 1 | 2;
|
|
||||||
rowHead?: boolean; // 첫 컬럼 등 row header
|
|
||||||
numeric?: boolean; // 숫자열(정렬 기본값/색상 타겟 기본값에 사용)
|
|
||||||
/** th 클래스(필요 시 lg-table__sep-r 등 주입) */
|
|
||||||
headerClassName?: string;
|
headerClassName?: string;
|
||||||
/** td 클래스(필요 시 lg-table__sep-l, lg-table__sep-r 등 주입) */
|
|
||||||
cellClassName?: string;
|
cellClassName?: string;
|
||||||
render?: (row: T) => React.ReactNode;
|
render?: (row: T) => React.ReactNode;
|
||||||
|
colSpan?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GaugeColumn<T> = {
|
export type DataColumnLeaf<T> = TableColumnShared<T> & {
|
||||||
key: keyof T;
|
key: keyof T;
|
||||||
header: string;
|
rowHead?: boolean; // 첫 컬럼 등 row header
|
||||||
width?: number | string;
|
numeric?: boolean; // 숫자열(정렬 기본값/색상 타겟 기본값에 사용)
|
||||||
align?: "left" | "center" | "right";
|
children?: undefined;
|
||||||
group?: string;
|
};
|
||||||
groupKey?:string;// 2단 헤더 그룹
|
|
||||||
|
|
||||||
headRowSpan?: 1 | 2;
|
export type DataColumnGroup<T> = TableColumnShared<T> & {
|
||||||
|
children: DataColumn<T>[];
|
||||||
|
key?: undefined;
|
||||||
|
rowHead?: undefined;
|
||||||
|
numeric?: undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type DataColumn<T> = DataColumnLeaf<T> | DataColumnGroup<T>;
|
||||||
|
|
||||||
|
export type GaugeColumnLeaf<T> = TableColumnShared<T> & {
|
||||||
|
key: keyof T;
|
||||||
rowHead?: boolean;
|
rowHead?: boolean;
|
||||||
/** 게이지 최대값 기준(기본 100) */
|
/** 게이지 최대값 기준(기본 100) */
|
||||||
max?: number;
|
max?: number;
|
||||||
render?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
render?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
||||||
cellType?: "gauge" | "number"; // default: "gauge"
|
cellType?: "gauge" | "number"; // default: "gauge"
|
||||||
|
children?: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type GaugeColumnGroup<T> = TableColumnShared<T> & {
|
||||||
|
children: GaugeColumn<T>[];
|
||||||
|
key?: undefined;
|
||||||
|
rowHead?: undefined;
|
||||||
|
max?: undefined;
|
||||||
|
cellType?: undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type GaugeColumn<T> = GaugeColumnLeaf<T> | GaugeColumnGroup<T>;
|
||||||
|
|
||||||
export type SignDisplayMode = "number" | "arrow";
|
export type SignDisplayMode = "number" | "arrow";
|
||||||
|
|
||||||
export type SignStyle<T> = {
|
export type SignStyle<T> = {
|
||||||
@@ -102,7 +117,7 @@ export type SignStyle<T> = {
|
|||||||
|
|
||||||
/** 표기 방식 */
|
/** 표기 방식 */
|
||||||
display?: SignDisplayMode; // 기본 number
|
display?: SignDisplayMode; // 기본 number
|
||||||
showPlus?: boolean; // number 모드에서 + 표시(기본 true)
|
showPlus?: boolean; // number 모드에서 + 표시(기본 true)
|
||||||
|
|
||||||
/** 0 값 표기(기본 "-") */
|
/** 0 값 표기(기본 "-") */
|
||||||
zeroText?: string;
|
zeroText?: string;
|
||||||
@@ -116,11 +131,11 @@ export type SignStyle<T> = {
|
|||||||
/** 색상 커스터마이즈(기본: + primary, - info, 0 gray) */
|
/** 색상 커스터마이즈(기본: + primary, - info, 0 gray) */
|
||||||
positiveTextClassName?: string; // 기본 "text-primary font-semibold"
|
positiveTextClassName?: string; // 기본 "text-primary font-semibold"
|
||||||
negativeTextClassName?: string; // 기본 "text-info font-semibold"
|
negativeTextClassName?: string; // 기본 "text-info font-semibold"
|
||||||
zeroTextClassName?: string; // 기본 "text-gray-600"
|
zeroTextClassName?: string; // 기본 "text-gray-600"
|
||||||
|
|
||||||
positiveCellBg?: string; // ex) "hsl(var(--primary) / 0.08)"
|
positiveCellBg?: string; // ex) "hsl(var(--primary) / 0.08)"
|
||||||
negativeCellBg?: string; // ex) "hsl(var(--info) / 0.08)"
|
negativeCellBg?: string; // ex) "hsl(var(--info) / 0.08)"
|
||||||
zeroCellBg?: string; // ex) "hsl(var(--lg-gray-200) / 0.6)"
|
zeroCellBg?: string; // ex) "hsl(var(--lg-gray-200) / 0.6)"
|
||||||
};
|
};
|
||||||
|
|
||||||
export const signStyleGapRow: SignStyle<TopChartTableRow> = {
|
export const signStyleGapRow: SignStyle<TopChartTableRow> = {
|
||||||
@@ -134,6 +149,6 @@ export const signStyleGapRow: SignStyle<TopChartTableRow> = {
|
|||||||
export type ShowLabel = "none" | "all" | "last" | "first";
|
export type ShowLabel = "none" | "all" | "last" | "first";
|
||||||
|
|
||||||
export type bannerType = {
|
export type bannerType = {
|
||||||
variable:string;
|
variable: string;
|
||||||
variableName:string;
|
variableName: string;
|
||||||
}
|
};
|
||||||
|
|||||||
266
src/config/lg-page.config.ts
Normal file
266
src/config/lg-page.config.ts
Normal file
@@ -0,0 +1,266 @@
|
|||||||
|
import {CategoryFieldSpec} from "@/types/lg.types";
|
||||||
|
import {CategoryTargetData, CategoryTargetType} from "@/types/filter.types";
|
||||||
|
|
||||||
|
const profileFieldSpec: CategoryFieldSpec[] = [
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "보유율"
|
||||||
|
, [CategoryTargetType.PURCHASE]: "구매율"
|
||||||
|
, [CategoryTargetType.INTENDED]: "향후 구매율"
|
||||||
|
},
|
||||||
|
requestKey: "category_${keyBase}",
|
||||||
|
chartMode:"none",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA1"
|
||||||
|
, [CategoryTargetType.PURCHASE]: "KQB0"
|
||||||
|
, [CategoryTargetType.INTENDED]: "KQC1"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "보유대수",
|
||||||
|
requestKey: "category_penetration_count",
|
||||||
|
chartMode:"none",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA2"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const CATEGORY_PAGE_FIELDS: Record<CategoryTargetData, CategoryFieldSpec[]> = {
|
||||||
|
[CategoryTargetData.PROFILE_ALL]: profileFieldSpec,
|
||||||
|
[CategoryTargetData.PROFILE]: profileFieldSpec,
|
||||||
|
|
||||||
|
[CategoryTargetData.PENETRATION_CHANGE]: [
|
||||||
|
{
|
||||||
|
title: "보급률 변화",
|
||||||
|
requestKey: "category_${keyBase}",
|
||||||
|
chartMode:"none",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA1"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
[CategoryTargetData.BRAND]: [
|
||||||
|
{
|
||||||
|
title: "브랜드",
|
||||||
|
requestKey: "category_${keyBase}_brand",
|
||||||
|
chartMode:"reverseStack",
|
||||||
|
chartTopMargin: 80,
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_3",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_3",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "",
|
||||||
|
[CategoryTargetType.PURCHASE]: "구매 고려 브랜드",
|
||||||
|
[CategoryTargetType.INTENDED]: "브랜드",
|
||||||
|
},
|
||||||
|
requestKey: "category_${keyBase}_consider_brand",
|
||||||
|
chartMode:"horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQB1",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
[CategoryTargetData.TYPE_SPEC]: [
|
||||||
|
{
|
||||||
|
title: "타입",
|
||||||
|
requestKey: "category_${keyBase}_type",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_4",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_4",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "깊이 타입",
|
||||||
|
requestKey: "category_${keyBase}_depthType",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_5",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_5",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "용량",
|
||||||
|
requestKey: "category_${keyBase}_capacity",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_6",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "설치 형태",
|
||||||
|
requestKey: "category_${keyBase}_installType",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_7",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_7",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "시공 방식",
|
||||||
|
requestKey: "category_${keyBase}_installMethod",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "냉장고 & 김치냉장고 설치 형태",
|
||||||
|
requestKey: "category_${keyBase}_fridgeInstallType",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "설치 위치",
|
||||||
|
requestKey: "category_${keyBase}_installLocation",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "배치/설치환경",
|
||||||
|
requestKey: "category_${keyBase}_installEnv",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_8",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_8",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "구입 고려 특징",
|
||||||
|
requestKey: "category_${keyBase}_buyConsiderations",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC3_8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "기능",
|
||||||
|
requestKey: "category_${keyBase}_features",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_9",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "스크린 사이즈",
|
||||||
|
requestKey: "category_${keyBase}_screenSize",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_10",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "용도",
|
||||||
|
requestKey: "category_${keyBase}_usage",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_11",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_11"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "스마트 모니터 여부",
|
||||||
|
requestKey: "category_${keyBase}_isSmartMonitor",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_12",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "음식물처리기 구동 방식",
|
||||||
|
requestKey: "category_${keyBase}_driveMethod",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_13",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_13"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "전기레인지 화구 수",
|
||||||
|
requestKey: "category_${keyBase}_burnerCount",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_14",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_14"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
[CategoryTargetData.BEHAVIOR]: [
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "보유 경로"
|
||||||
|
, [CategoryTargetType.PURCHASE]: "구입 행태"
|
||||||
|
, [CategoryTargetType.INTENDED]: "구입 행태"
|
||||||
|
},
|
||||||
|
requestKey: "category_${keyBase}_behavior",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_1",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQB2",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC5"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "구입 계기",
|
||||||
|
requestKey: "category_${keyBase}_chance",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQB3"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
[CategoryTargetData.PURCHASE_CHANNEL]: [
|
||||||
|
{
|
||||||
|
title: "구매 채널(온/오프라인)",
|
||||||
|
requestKey: "category_${keyBase}_channel",
|
||||||
|
chartMode: "reverseStack",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQB4_NET",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC6_NET"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "구매 채널(상세)",
|
||||||
|
requestKey: "category_${keyBase}_channel_detail",
|
||||||
|
chartMode: "horizontal",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQB4",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC6"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
[CategoryTargetData.PAYMENT_METHOD]: [
|
||||||
|
{
|
||||||
|
title: "구매형식",
|
||||||
|
requestKey: "category_${keyBase}_method",
|
||||||
|
chartMode:"reverseStack",
|
||||||
|
qidByMode: {
|
||||||
|
[CategoryTargetType.PENETRATION]: "KQA3_2_1",
|
||||||
|
[CategoryTargetType.PURCHASE]: "KQX3_2_1",
|
||||||
|
[CategoryTargetType.INTENDED]: "KQC7"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
/**
|
|
||||||
* 차트 관련 상수 정의
|
|
||||||
* - 차트 높이, Bar 너비, Grid 설정 등
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {GAP_WORDING} from "@/const/lgConst";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 차트 기본 높이 설정
|
|
||||||
*/
|
|
||||||
export const CHART_HEIGHTS = {
|
|
||||||
DEFAULT: "100%",
|
|
||||||
COMPACT: 200,
|
|
||||||
EXPANDED: 320,
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bar 차트의 Bar 너비 설정
|
|
||||||
*/
|
|
||||||
export const BAR_WIDTHS = {
|
|
||||||
DEFAULT: 42,
|
|
||||||
NARROW: 30,
|
|
||||||
WIDE: 60,
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 차트 Grid 기본 패딩 설정
|
|
||||||
*/
|
|
||||||
export const CHART_GRID_DEFAULTS = {
|
|
||||||
DEFAULT: {
|
|
||||||
left: 16,
|
|
||||||
right: 16,
|
|
||||||
top: 36,
|
|
||||||
bottom: 12,
|
|
||||||
containLabel: true,
|
|
||||||
},
|
|
||||||
COMPACT: {
|
|
||||||
left: 10,
|
|
||||||
right: 10,
|
|
||||||
top: 20,
|
|
||||||
bottom: 8,
|
|
||||||
containLabel: true,
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Legend 아이템 크기 설정 (GroupedOverlayBar, GroupedStackBar에서 사용)
|
|
||||||
*/
|
|
||||||
export const LEGEND_ITEM_SIZE = {
|
|
||||||
WIDTH: 25,
|
|
||||||
HEIGHT: 14,
|
|
||||||
RADIUS: 4,
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 색상 팔레트 설정
|
|
||||||
*/
|
|
||||||
export const CHART_COLOR_PALETTES = {
|
|
||||||
/** 연도별 트렌드 역순 (최신->과거) */
|
|
||||||
YEAR_TREND_REVERSE: ["--chart-3", "--chart-2", "--chart-1"],
|
|
||||||
|
|
||||||
/** LG Red 계열 */
|
|
||||||
LG_RED_SCALE: ["--lg-red-300", "--lg-red-400", "--lg-red-500"],
|
|
||||||
|
|
||||||
/** 연도별 전체 색상 */
|
|
||||||
YEAR_TOTAL: {
|
|
||||||
"24": "--chart-total-1",
|
|
||||||
"25": "--chart-total-2",
|
|
||||||
"26": "--chart-total-3",
|
|
||||||
} as const,
|
|
||||||
|
|
||||||
/** 연도별 LG 색상 */
|
|
||||||
YEAR_LG: {
|
|
||||||
"24": "--chart-lg-1",
|
|
||||||
"25": "--chart-lg-2",
|
|
||||||
"26": "--chart-lg-3",
|
|
||||||
} as const,
|
|
||||||
|
|
||||||
/** 연도별 브랜드 색상 (CBrand, Samsung, LG) */
|
|
||||||
YEAR_BRAND: {
|
|
||||||
"24": ["--chart-cbrand-1", "--chart-samsung-1", "--chart-lg-1"],
|
|
||||||
"25": ["--chart-cbrand-2", "--chart-samsung-2", "--chart-lg-2"],
|
|
||||||
"26": ["--chart-cbrand-3", "--chart-samsung-3", "--chart-lg-3"],
|
|
||||||
} as const,
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 테이블 색상 설정
|
|
||||||
*/
|
|
||||||
export const TABLE_COLORS = {
|
|
||||||
/** 게이지 테이블 색상 */
|
|
||||||
GAUGE: {
|
|
||||||
FILL: "hsl(var(--lg-gray-200) / 0.85)",
|
|
||||||
TRACK: "hsl(var(--lg-pink-300) / 0.2)",
|
|
||||||
},
|
|
||||||
|
|
||||||
/** Sign 표기 셀 배경색 */
|
|
||||||
SIGN_CELL: {
|
|
||||||
POSITIVE: "hsl(var(--primary) / 0.08)",
|
|
||||||
NEGATIVE: "hsl(var(--info) / 0.08)",
|
|
||||||
ZERO: "hsl(var(--lg-gray-200) / 0.6)",
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 테이블 크기 설정
|
|
||||||
*/
|
|
||||||
export const TABLE_DIMENSIONS = {
|
|
||||||
CELL_HEIGHT: {
|
|
||||||
DEFAULT: 26,
|
|
||||||
COMPACT: 20,
|
|
||||||
EXPANDED: 32,
|
|
||||||
},
|
|
||||||
MIN_WIDTH: {
|
|
||||||
STANDARD: 1600,
|
|
||||||
COMPACT: 1200,
|
|
||||||
WIDE: 2000,
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 차트/테이블 라벨 텍스트
|
|
||||||
*/
|
|
||||||
export const CHART_LABELS = {
|
|
||||||
TOTAL: "전체",
|
|
||||||
LG: "LG",
|
|
||||||
GAP: GAP_WORDING,
|
|
||||||
CAGR: "CAGR(%p)",
|
|
||||||
SAMPLE_COUNT: "(사례수)",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 차트 제목 텍스트
|
|
||||||
*/
|
|
||||||
export const CHART_TITLES = {
|
|
||||||
LG_PENETRATION: "LG제품 보급률",
|
|
||||||
TOTAL_PENETRATION: "전체 보급률",
|
|
||||||
LG_PURCHASE: "LG제품 구매율",
|
|
||||||
TOTAL_PURCHASE: "전체 구매율",
|
|
||||||
BRAND_SHARE: "브랜드별 점유율",
|
|
||||||
} as const;
|
|
||||||
@@ -2,9 +2,9 @@ import {
|
|||||||
CategoryTargetData,
|
CategoryTargetData,
|
||||||
CategoryTargetItem,
|
CategoryTargetItem,
|
||||||
CategoryTargetType,
|
CategoryTargetType,
|
||||||
CategoryTargetTypeItem,
|
CategoryTargetTypeItem, FilterItem,
|
||||||
TotalFilterItem
|
TotalFilterItem
|
||||||
} from "./filter.types";
|
} from "@/types/filter.types";
|
||||||
|
|
||||||
export const totalFilters:TotalFilterItem[] = [
|
export const totalFilters:TotalFilterItem[] = [
|
||||||
{
|
{
|
||||||
@@ -18,6 +18,8 @@ export const totalFilters:TotalFilterItem[] = [
|
|||||||
{ value: "4", label: "기혼 학령기"},
|
{ value: "4", label: "기혼 학령기"},
|
||||||
{ value: "5", label: "기혼 성인자녀"},
|
{ value: "5", label: "기혼 성인자녀"},
|
||||||
{ value: "6", label: "독립 시니어"},
|
{ value: "6", label: "독립 시니어"},
|
||||||
|
{ value: "7", label: "비혼 중년"},
|
||||||
|
{ value: "8", label: "기타"},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -64,7 +66,8 @@ export const totalFilters:TotalFilterItem[] = [
|
|||||||
{ value: "2", label: "주택"},
|
{ value: "2", label: "주택"},
|
||||||
{ value: "3", label: "오피스텔"},
|
{ value: "3", label: "오피스텔"},
|
||||||
{ value: "4", label: "(연립)빌라"},
|
{ value: "4", label: "(연립)빌라"},
|
||||||
{ value: "5", label: "기타"},
|
{ value: "5", label: "원룸"},
|
||||||
|
{ value: "6", label: "기타"},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -85,11 +88,11 @@ export const totalFilters:TotalFilterItem[] = [
|
|||||||
variableName:"연령대",
|
variableName:"연령대",
|
||||||
children:[
|
children:[
|
||||||
{ value: "0", label: "전체"},
|
{ value: "0", label: "전체"},
|
||||||
{ value: "2", label: "20대"},
|
{ value: "1", label: "20대"},
|
||||||
{ value: "3", label: "30대"},
|
{ value: "2", label: "30대"},
|
||||||
{ value: "4", label: "40대"},
|
{ value: "3", label: "40대"},
|
||||||
{ value: "5", label: "50대"},
|
{ value: "4", label: "50대"},
|
||||||
{ value: "6", label: "60대"},
|
{ value: "5", label: "60대"},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -125,6 +128,7 @@ export const categoryTarget: CategoryTargetItem[] = [
|
|||||||
type: [CategoryTargetType.PENETRATION],
|
type: [CategoryTargetType.PENETRATION],
|
||||||
children:[
|
children:[
|
||||||
{ value: CategoryTargetData.PROFILE, label: "Profile"},
|
{ value: CategoryTargetData.PROFILE, label: "Profile"},
|
||||||
|
{ value: CategoryTargetData.PROFILE_ALL, label: "Profile (전체)"},
|
||||||
{ value: CategoryTargetData.PENETRATION_CHANGE, label: "보급률 변화"},
|
{ value: CategoryTargetData.PENETRATION_CHANGE, label: "보급률 변화"},
|
||||||
{ value: CategoryTargetData.BRAND, label: "브랜드"},
|
{ value: CategoryTargetData.BRAND, label: "브랜드"},
|
||||||
{ value: CategoryTargetData.TYPE_SPEC, label: "타입/스펙"},
|
{ value: CategoryTargetData.TYPE_SPEC, label: "타입/스펙"},
|
||||||
@@ -136,6 +140,7 @@ export const categoryTarget: CategoryTargetItem[] = [
|
|||||||
type: [CategoryTargetType.PURCHASE, CategoryTargetType.INTENDED],
|
type: [CategoryTargetType.PURCHASE, CategoryTargetType.INTENDED],
|
||||||
children:[
|
children:[
|
||||||
{ value: CategoryTargetData.PROFILE, label: "Profile"},
|
{ value: CategoryTargetData.PROFILE, label: "Profile"},
|
||||||
|
{ value: CategoryTargetData.PROFILE_ALL, label: "Profile (전체)"},
|
||||||
{ value: CategoryTargetData.BRAND, label: "브랜드"},
|
{ value: CategoryTargetData.BRAND, label: "브랜드"},
|
||||||
{ value: CategoryTargetData.TYPE_SPEC, label: "타입/스펙"},
|
{ value: CategoryTargetData.TYPE_SPEC, label: "타입/스펙"},
|
||||||
{ value: CategoryTargetData.BEHAVIOR, label: "구입 행태"},
|
{ value: CategoryTargetData.BEHAVIOR, label: "구입 행태"},
|
||||||
@@ -143,4 +148,39 @@ export const categoryTarget: CategoryTargetItem[] = [
|
|||||||
{ value: CategoryTargetData.PAYMENT_METHOD, label: "구매 형식"},
|
{ value: CategoryTargetData.PAYMENT_METHOD, label: "구매 형식"},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const categoryByDataBanner:FilterItem[] = [
|
||||||
|
{
|
||||||
|
variable:"lifeStage",
|
||||||
|
variableName:"라이프 스테이지",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
variable:"age",
|
||||||
|
variableName:"연령대",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
variable:"household",
|
||||||
|
variableName:"가구원 수",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
variable:"occupancy",
|
||||||
|
variableName:"입주 형태",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
variable:"housing",
|
||||||
|
variableName:"주거 형태",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
variable:"houseSize",
|
||||||
|
variableName:"거주 평형",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
variable:"income",
|
||||||
|
variableName:"월 소득 규모",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
variable:"region",
|
||||||
|
variableName:"지역",
|
||||||
|
},
|
||||||
|
]
|
||||||
137
src/const/lg-banner.const.ts
Normal file
137
src/const/lg-banner.const.ts
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
import type { BannerKey } from "@/types/lg.types";
|
||||||
|
import { BANNER_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
|
|
||||||
|
export type BannerGroupLeafNode = {
|
||||||
|
type: "leaf";
|
||||||
|
key: BannerKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type BannerGroupBranchNode = {
|
||||||
|
type: "group";
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
children: readonly BannerGroupNode[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type BannerGroupNode = BannerGroupLeafNode | BannerGroupBranchNode;
|
||||||
|
|
||||||
|
export type BannerGroupDefinition = {
|
||||||
|
label: string;
|
||||||
|
children: readonly BannerGroupNode[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BANNER_KEYS = Object.keys(BANNER_KEY_MAP) as Array<keyof typeof BANNER_KEY_MAP>;
|
||||||
|
export const BANNER_KEY = Object.keys(BANNER_KEY_MAP).reduce((acc, k) => {
|
||||||
|
(acc as any)[k] = k;
|
||||||
|
return acc;
|
||||||
|
}, {} as { [K in BannerKey]: K });
|
||||||
|
|
||||||
|
const leaf = (key: BannerKey): BannerGroupLeafNode => ({
|
||||||
|
type: "leaf",
|
||||||
|
key,
|
||||||
|
});
|
||||||
|
|
||||||
|
const group = (id: string, label: string, children: readonly BannerGroupNode[]): BannerGroupBranchNode => ({
|
||||||
|
type: "group",
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
children,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const BANNER_GROUP = {
|
||||||
|
lifeStage: {
|
||||||
|
label: "라이프스테이지 별",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#1"]),
|
||||||
|
group("life-stage-married", "기혼", [
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#2"]),
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#3"]),
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#4"]),
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#5"]),
|
||||||
|
]),
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#6"]),
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#7"]),
|
||||||
|
leaf(BANNER_KEY["KLIFEstAGE#8"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
household: {
|
||||||
|
label: "가구원수 별",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KSQ8_R_DB#1"]),
|
||||||
|
leaf(BANNER_KEY["KSQ8_R_DB#2"]),
|
||||||
|
leaf(BANNER_KEY["KSQ8_R_DB#3"]),
|
||||||
|
leaf(BANNER_KEY["KSQ8_R_DB#4"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
age: {
|
||||||
|
label: "연령",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KSQ2_R_R#1"]),
|
||||||
|
leaf(BANNER_KEY["KSQ2_R_R#2"]),
|
||||||
|
leaf(BANNER_KEY["KSQ2_R_R#3"]),
|
||||||
|
leaf(BANNER_KEY["KSQ2_R_R#4"]),
|
||||||
|
leaf(BANNER_KEY["KSQ2_R_R#5"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
occupancy: {
|
||||||
|
label: "입주 형태",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KDQ6#1"]),
|
||||||
|
leaf(BANNER_KEY["KDQ6#2"]),
|
||||||
|
leaf(BANNER_KEY["KDQ6#3"]),
|
||||||
|
leaf(BANNER_KEY["KDQ6#4"]),
|
||||||
|
leaf(BANNER_KEY["KDQ6#5"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
housing: {
|
||||||
|
label: "주거 형태",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KDQ4#1"]),
|
||||||
|
leaf(BANNER_KEY["KDQ4#2"]),
|
||||||
|
leaf(BANNER_KEY["KDQ4#3"]),
|
||||||
|
leaf(BANNER_KEY["KDQ4#4"]),
|
||||||
|
leaf(BANNER_KEY["KDQ4#5"]),
|
||||||
|
leaf(BANNER_KEY["KDQ4#6"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
houseSize: {
|
||||||
|
label: "거주 평형",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KDQ5#1"]),
|
||||||
|
leaf(BANNER_KEY["KDQ5#2"]),
|
||||||
|
leaf(BANNER_KEY["KDQ5#3"]),
|
||||||
|
leaf(BANNER_KEY["KDQ5#4"]),
|
||||||
|
leaf(BANNER_KEY["KDQ5#5"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
region: {
|
||||||
|
label: "거주 지역",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KSQ4_R_R#1"]),
|
||||||
|
leaf(BANNER_KEY["KSQ4_R_R#2"]),
|
||||||
|
leaf(BANNER_KEY["KSQ4_R_R#3"]),
|
||||||
|
leaf(BANNER_KEY["KSQ4_R_R#4"]),
|
||||||
|
leaf(BANNER_KEY["KSQ4_R_R#5"]),
|
||||||
|
leaf(BANNER_KEY["KSQ4_R_R#6"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
income: {
|
||||||
|
label: "소득수준",
|
||||||
|
children: [
|
||||||
|
leaf(BANNER_KEY["KDQ3_DB#1"]),
|
||||||
|
leaf(BANNER_KEY["KDQ3_DB#2"]),
|
||||||
|
leaf(BANNER_KEY["KDQ3_DB#3"]),
|
||||||
|
leaf(BANNER_KEY["KDQ3_DB#4"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
} as const satisfies Record<string, BannerGroupDefinition>;
|
||||||
|
|
||||||
|
export const isBannerGroupBranchNode = (node: BannerGroupNode): node is BannerGroupBranchNode => {
|
||||||
|
return node.type === "group";
|
||||||
|
}
|
||||||
|
|
||||||
|
export const flattenBannerGroupKeys = (nodes: readonly BannerGroupNode[]): BannerKey[] => {
|
||||||
|
return nodes.flatMap((node) => (node.type === "leaf" ? [node.key] : flattenBannerGroupKeys(node.children)));
|
||||||
|
}
|
||||||
|
|
||||||
|
export const BANNER_GROUP_KEY = Object.keys(BANNER_GROUP) as string[];
|
||||||
15
src/const/lg-common.const.ts
Normal file
15
src/const/lg-common.const.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export const DEBOUNCE_TIME = 500;
|
||||||
|
export const USE_CACHE = true;
|
||||||
|
export const API_DECIMAL_POINT = 0;
|
||||||
|
export const VIEW_DECIMAL_POINT = 0;
|
||||||
|
|
||||||
|
export const SITE_TITLE = 'LGE CX Dashboard';
|
||||||
|
|
||||||
|
export const YEARS = ["2023", "2024", "2025"];
|
||||||
|
export const LAST_YEAR = YEARS.at(-1)!;
|
||||||
|
|
||||||
|
export const GAP_WORDING = "전년 대비 GAP(%p)";
|
||||||
|
export const UNIT_TEXT = "(단위 %)"
|
||||||
|
export const SAMPLE_SIZE_NOTICE = "* 30표본 미만 해석에 주의";
|
||||||
|
|
||||||
|
export const BRAND_LIST = ['기타', 'C Brand', '삼성', 'LG'];
|
||||||
70
src/const/lg-product.const.ts
Normal file
70
src/const/lg-product.const.ts
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { GaugeColumn } from "@/components/lge-dashboard";
|
||||||
|
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||||
|
import type { LifeStageRow } from "@/types/lg.types";
|
||||||
|
|
||||||
|
export const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
||||||
|
{ key: "item", header: "", rowHead: true, render: (r) => r.item },
|
||||||
|
{ key: "total", header: "전체", max: 100, align: "left", cellType: "number" },
|
||||||
|
{ key: "KLIFEstAGE#1", header: "미혼", max: 100, align: "left" },
|
||||||
|
{
|
||||||
|
id: "life-stage-married",
|
||||||
|
header: "기혼",
|
||||||
|
children: [
|
||||||
|
{ key: "KLIFEstAGE#2", header: "무자녀", max: 100, align: "left" },
|
||||||
|
{ key: "KLIFEstAGE#3", header: "미취학", max: 100, align: "left" },
|
||||||
|
{ key: "KLIFEstAGE#4", header: "취학자녀", max: 100, align: "left" },
|
||||||
|
{ key: "KLIFEstAGE#5", header: "성인자녀", max: 100, align: "left" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ key: "KLIFEstAGE#6", header: "독립\n시니어", max: 100, align: "left" },
|
||||||
|
{ key: "KLIFEstAGE#7", header: "비혼 중년", max: 100, align: "left" },
|
||||||
|
{ key: "KLIFEstAGE#8", header: "기타", max: 100, align: "left" },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const LIFE_STAGE_GROUPS = [
|
||||||
|
{ title: "대형가전 군", items: ["KPRODUCT#1", "KPRODUCT#7", "KPRODUCT#8", "KPRODUCT#12", "KPRODUCT#14", "KPRODUCT#2", "KPRODUCT#3", "KPRODUCT#11"] },
|
||||||
|
{ title: "소형가전 군", items: ["KPRODUCT#9", "KPRODUCT#13", "KPRODUCT#4"] },
|
||||||
|
{ title: "신가전 군", items: ["KPRODUCT#10", "KPRODUCT#6"] },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as Array<keyof typeof PRODUCT_KEY_MAP>;
|
||||||
|
export const PRODUCTS = Object.values(PRODUCT_KEY_MAP) as Array<string>;
|
||||||
|
|
||||||
|
export const PRODUCTS_FILTER_ITEM = [
|
||||||
|
{
|
||||||
|
path: "kitchen",
|
||||||
|
items: [
|
||||||
|
"KPRODUCT#1", // 냉장고
|
||||||
|
"KPRODUCT#2", // 김치 냉장고
|
||||||
|
"KPRODUCT#3", // 정수기
|
||||||
|
"KPRODUCT#4", // 전기 레인지
|
||||||
|
"KPRODUCT#5", // 식기 세척기
|
||||||
|
"KPRODUCT#6", // 음식물처리기
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "living",
|
||||||
|
items: [
|
||||||
|
"KPRODUCT#7", // 세탁기
|
||||||
|
"KPRODUCT#9", // 건조기
|
||||||
|
"KPRODUCT#8", // 청소기
|
||||||
|
"KPRODUCT#10", // 로봇 청소기
|
||||||
|
"KPRODUCT#11", // 의류 관리기
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "es",
|
||||||
|
items: [
|
||||||
|
"KPRODUCT#12", // 에어컨
|
||||||
|
"KPRODUCT#13", // 공기 청정기
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "ms",
|
||||||
|
items: [
|
||||||
|
"KPRODUCT#14", // TV
|
||||||
|
"KPRODUCT#15", // 노트북
|
||||||
|
"KPRODUCT#16", // 모니터
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
82
src/const/lg-schema.const.ts
Normal file
82
src/const/lg-schema.const.ts
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
export const PRODUCT_KEY_MAP = {
|
||||||
|
"KPRODUCT#1": "냉장고",
|
||||||
|
"KPRODUCT#2": "김치 냉장고",
|
||||||
|
"KPRODUCT#3": "정수기",
|
||||||
|
"KPRODUCT#4": "전기 레인지",
|
||||||
|
"KPRODUCT#5": "식기 세척기",
|
||||||
|
"KPRODUCT#6": "음식물처리기",
|
||||||
|
|
||||||
|
"KPRODUCT#7": "세탁기",
|
||||||
|
"KPRODUCT#9": "건조기",
|
||||||
|
"KPRODUCT#8": "청소기",
|
||||||
|
"KPRODUCT#10": "로봇 청소기",
|
||||||
|
"KPRODUCT#11": "의류 관리기",
|
||||||
|
|
||||||
|
"KPRODUCT#12": "에어컨",
|
||||||
|
"KPRODUCT#13": "공기 청정기",
|
||||||
|
|
||||||
|
"KPRODUCT#14": "TV",
|
||||||
|
"KPRODUCT#15": "노트북",
|
||||||
|
"KPRODUCT#16": "모니터",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const BANNER_KEY_MAP = {
|
||||||
|
// 라이프 스테이지
|
||||||
|
"KLIFEstAGE#1": "미혼",
|
||||||
|
"KLIFEstAGE#2": "무자녀",
|
||||||
|
"KLIFEstAGE#3": "미취학",
|
||||||
|
"KLIFEstAGE#4": "취학자녀",
|
||||||
|
"KLIFEstAGE#5": "성인자녀",
|
||||||
|
"KLIFEstAGE#6": "독립\n시니어",
|
||||||
|
"KLIFEstAGE#7": "비혼 중년",
|
||||||
|
"KLIFEstAGE#8": "기타",
|
||||||
|
|
||||||
|
// 가구원수
|
||||||
|
"KSQ8_R_DB#1": "1인 가구",
|
||||||
|
"KSQ8_R_DB#2": "2인 가구",
|
||||||
|
"KSQ8_R_DB#3": "3인 가구",
|
||||||
|
"KSQ8_R_DB#4": "4인 이상 가구",
|
||||||
|
|
||||||
|
// 연령
|
||||||
|
"KSQ2_R_R#1": "20대",
|
||||||
|
"KSQ2_R_R#2": "30대",
|
||||||
|
"KSQ2_R_R#3": "40대",
|
||||||
|
"KSQ2_R_R#4": "50대",
|
||||||
|
"KSQ2_R_R#5": "60대",
|
||||||
|
|
||||||
|
// 점유형태
|
||||||
|
"KDQ6#1": "자가",
|
||||||
|
"KDQ6#2": "전세",
|
||||||
|
"KDQ6#3": "전+월세\n(보증금有)",
|
||||||
|
"KDQ6#4": "월세\n(보증금無)",
|
||||||
|
"KDQ6#5": "기타",
|
||||||
|
|
||||||
|
// 주거형태
|
||||||
|
"KDQ4#1": "아파트",
|
||||||
|
"KDQ4#2": "주택",
|
||||||
|
"KDQ4#3": "오피스텔",
|
||||||
|
"KDQ4#4": "(연립)빌라",
|
||||||
|
"KDQ4#5": "원룸",
|
||||||
|
"KDQ4#6": "기타",
|
||||||
|
|
||||||
|
// 평형
|
||||||
|
"KDQ5#1": "19평 이하",
|
||||||
|
"KDQ5#2": "20평형 대",
|
||||||
|
"KDQ5#3": "30평형 대",
|
||||||
|
"KDQ5#4": "40평형 대",
|
||||||
|
"KDQ5#5": "50평형 대 이상",
|
||||||
|
|
||||||
|
// 권역
|
||||||
|
"KSQ4_R_R#1": "서울, 인천, 경기도",
|
||||||
|
"KSQ4_R_R#2": "경남, 부산, 울산",
|
||||||
|
"KSQ4_R_R#3": "경북, 대구",
|
||||||
|
"KSQ4_R_R#4": "전라도, 광주",
|
||||||
|
"KSQ4_R_R#5": "충청, 대전, 세종",
|
||||||
|
"KSQ4_R_R#6": "강원, 제주",
|
||||||
|
|
||||||
|
// 소득
|
||||||
|
"KDQ3_DB#1": "299만원 이하",
|
||||||
|
"KDQ3_DB#2": "300~599만원 이하",
|
||||||
|
"KDQ3_DB#3": "600~899만원 이하",
|
||||||
|
"KDQ3_DB#4": "900만원 이상",
|
||||||
|
} as const;
|
||||||
49
src/const/lg-survey.const.ts
Normal file
49
src/const/lg-survey.const.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
export const QID_SURVEY_TITLE: Record<string, string> = {
|
||||||
|
"KQA3_3": "Q. 보유하고 계신 제품의 브랜드는 어떻게 되십니까?",
|
||||||
|
"KQA3_4": "Q. 보유하고 계신 제품의 타입은 어떻게 되십니까?",
|
||||||
|
"KQA3_5": "Q. 보유하고 계신 제품의 깊이 타입은 어떻게 되십니까?",
|
||||||
|
"KQA3_6": "Q. 보유하고 계신 제품의 용량은 어떻게 되십니까?",
|
||||||
|
"KQA3_7": "Q. 보유하고 계신 제품의 설치 형태는 어떻게 되십니까?",
|
||||||
|
"KQA3_8": "Q. 보유하고 계신 제품은 메인 가구와 어떻게 배치되어 있습니까?",
|
||||||
|
"KQA3_9": "Q. 보유하고 계신 제품에 포함되어 있는 기능이 있으십니까? 모두 선택해 주세요.",
|
||||||
|
"KQA3_10": "Q. 보유하고 계신 제품의 스크린 사이즈는 어떻게 되십니까?",
|
||||||
|
"KQA3_11": "Q. 보유하고 계신 제품의 가장 주된 용도는 무엇입니까?",
|
||||||
|
"KQA3_12": "Q. 보유하고 계신 제품은 스마트 모니터(자체적으로 OS를 가지고 있어, 기타 기기 연결 없이 작동이 가능한 모니터) 입니까?",
|
||||||
|
"KQA3_13": "Q. 보유하고 계신 제품의 구동 방식은 어떻게 되십니까?",
|
||||||
|
"KQA3_14": "Q. 보유하고 계신 제품의 화구 수는 어떻게 되십니까?",
|
||||||
|
"KQA3_1": "Q. 보유하고 계신 제품을 구매 또는 보유하게 된 경로가 어떻게 되십니까? ",
|
||||||
|
"KQA3_2_1": "Q. 귀하께서는 제품을 어떤 방식으로 구입하셨습니까? ",
|
||||||
|
|
||||||
|
"KQX3_3": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 브랜드는 어떻게 되십니까?",
|
||||||
|
"KQB1": "Q. 귀하께서 [#YEAR#]년에 제품을 구매하실 때 구매를 고려하셨던 브랜드는 무엇입니까? 모두 선택하여 주시기 바랍니다",
|
||||||
|
"KQX3_4": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 타입은 어떻게 되십니까?",
|
||||||
|
"KQX3_5": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 깊이 타입은 어떻게 되십니까?",
|
||||||
|
"KQX3_6": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 용량은 어떻게 되십니까?",
|
||||||
|
"KQX3_7": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 설치 형태는 어떻게 되십니까?",
|
||||||
|
"KQX3_8": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품은 메인 가구와 어떻게 배치되어 있습니까?",
|
||||||
|
"KQX3_9": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품에 포함되어 있는 기능이 있으십니까? 모두 선택해 주세요.",
|
||||||
|
"KQX3_10": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 스크린 사이즈는 어떻게 되십니까?",
|
||||||
|
"KQX3_11": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 가장 주된 용도는 무엇입니까?",
|
||||||
|
"KQX3_12": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품은 스마트 모니터(자체적으로 OS를 가지고 있어, 기타 기기 연결 없이 작동이 가능한 모니터) 입니까?",
|
||||||
|
"KQX3_13": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 구동 방식은 어떻게 되십니까?",
|
||||||
|
"KQX3_14": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 화구 수는 어떻게 되십니까?",
|
||||||
|
"KQB2": "Q. 귀하께서는 [#YEAR#]년에 제품을 신규로 구입하신 건가요? 교체/추가 구입하신 건가요? 한 가지만 선택해주세요",
|
||||||
|
"KQB3": "Q. 귀하께서 [#YEAR#]년에 제품을 구입하신 이유/계기(상황)는 무엇입니까? 가장 주요한 이유/계기를 한 가지만 선택해주세요",
|
||||||
|
"KQB4_NET": "Q. 최종적으로 제품을 구매하신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||||
|
"KQB4": "Q. 최종적으로 제품을 구매하신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||||
|
"KQX3_2_1": "Q. 귀하께서는 제품을 어떤 방식으로 구입하셨습니까? 한가지만 선택해주세요",
|
||||||
|
|
||||||
|
"KQC2": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 브랜드로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||||
|
"KQC3_1": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 타입으로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||||
|
"KQC3_2": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 깊이 타입으로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||||
|
"KQC3_3": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 설치 형태로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||||
|
"KQC3_4": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 설치 방식을 실제 공간에 구현하기 위해서 다음 중 어떤 방식의 시공이 필요하다고 생각하십니까?",
|
||||||
|
"KQC3_5": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 <냉장고와 김치냉장고>를 어떤 형태로 설치하실 계획이십니까?",
|
||||||
|
"KQC3_6": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품은 어디에 설치하실 계획이십니까?",
|
||||||
|
"KQC3_7": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품은 어떤 환경에 설치하실 계획이십니까?",
|
||||||
|
"KQC3_8": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 특징으로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||||
|
"KQC5": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 신규로 구입하실 건가요? 교체/추가 구입하실 건가요? 한 가지만 선택해주세요",
|
||||||
|
"KQC6_NET": "Q. [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 구매하고 싶으신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||||
|
"KQC6": "Q. [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 구매하고 싶으신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||||
|
"KQC7": "Q. 그렇다면, [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 어떤 방식으로 구입하길 원하십니까? 한가지만 선택해주세요",
|
||||||
|
}
|
||||||
@@ -1,511 +0,0 @@
|
|||||||
import {BannerKey, CategoryFieldSpec, LifeStageRow} from "@/types/lg";
|
|
||||||
import {GaugeColumn} from "@/components/lge-dashboard";
|
|
||||||
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
|
|
||||||
|
|
||||||
export const SITE_TITLE = 'LGE CX Dashboard';
|
|
||||||
|
|
||||||
export const YEARS = ["2023", "2024", "2025"];
|
|
||||||
export const LAST_YEAR = YEARS.at(-1)!;
|
|
||||||
|
|
||||||
export const GAP_WORDING = "전년 대비 GAP(%p)";
|
|
||||||
export const UNIT_TEXT = "(단위 %)"
|
|
||||||
export const SAMPLE_SIZE_NOTICE = "* 30표본 미만 해석에 주의";
|
|
||||||
|
|
||||||
export const BRAND_LIST = ['Cbrand', '삼성', 'LG'];
|
|
||||||
|
|
||||||
export const PRODUCT_KEY_MAP = {
|
|
||||||
"KPRODUCT#1": "냉장고",
|
|
||||||
"KPRODUCT#2": "김치 냉장고",
|
|
||||||
"KPRODUCT#3": "식기 세척기",
|
|
||||||
"KPRODUCT#4": "정수기",
|
|
||||||
"KPRODUCT#5": "전기 레인지",
|
|
||||||
"KPRODUCT#6": "음식물처리기",
|
|
||||||
|
|
||||||
"KPRODUCT#7": "세탁기",
|
|
||||||
"KPRODUCT#8": "건조기",
|
|
||||||
"KPRODUCT#9": "청소기",
|
|
||||||
"KPRODUCT#10": "로봇 청소기",
|
|
||||||
"KPRODUCT#11": "의류 관리기",
|
|
||||||
|
|
||||||
"KPRODUCT#12": "에어컨",
|
|
||||||
"KPRODUCT#13": "공기 청정기",
|
|
||||||
|
|
||||||
"KPRODUCT#14": "TV",
|
|
||||||
"KPRODUCT#15": "모니터",
|
|
||||||
"KPRODUCT#16": "노트북",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const BANNER_KEY_MAP = {
|
|
||||||
// 라이프 스테이지
|
|
||||||
"KLIFEstAGE#1": "미혼",
|
|
||||||
"KLIFEstAGE#2": "무자녀",
|
|
||||||
"KLIFEstAGE#3": "미취학",
|
|
||||||
"KLIFEstAGE#4": "취학자녀",
|
|
||||||
"KLIFEstAGE#5": "성인자녀",
|
|
||||||
"KLIFEstAGE#6": "독립시니어",
|
|
||||||
|
|
||||||
// 가구원수
|
|
||||||
"KSQ8_R_DB#1": "1인 가구",
|
|
||||||
"KSQ8_R_DB#2": "2인 가구",
|
|
||||||
"KSQ8_R_DB#3": "3인 가구",
|
|
||||||
"KSQ8_R_DB#4": "4인 이상 가구",
|
|
||||||
|
|
||||||
// 연령
|
|
||||||
"KSQ2_R_R#1": "20대",
|
|
||||||
"KSQ2_R_R#2": "30대",
|
|
||||||
"KSQ2_R_R#3": "40대",
|
|
||||||
"KSQ2_R_R#4": "50대",
|
|
||||||
"KSQ2_R_R#5": "60대",
|
|
||||||
|
|
||||||
// 점유형태
|
|
||||||
"KDQ6#1": "자가",
|
|
||||||
"KDQ6#2": "전세",
|
|
||||||
"KDQ6#3": "전+월세 (보증금有)",
|
|
||||||
"KDQ6#4": "월세 (보증금無)",
|
|
||||||
"KDQ6#5": "기타",
|
|
||||||
|
|
||||||
// 주거형태
|
|
||||||
"KDQ4#1": "아파트",
|
|
||||||
"KDQ4#2": "주택",
|
|
||||||
"KDQ4#3": "오피스텔",
|
|
||||||
"KDQ4#4": "(연립)빌라",
|
|
||||||
"KDQ4#5": "원룸",
|
|
||||||
"KDQ4#6": "기타",
|
|
||||||
|
|
||||||
// 평형
|
|
||||||
"KDQ5#1": "19평 이하",
|
|
||||||
"KDQ5#2": "20평형 대",
|
|
||||||
"KDQ5#3": "30평형 대",
|
|
||||||
"KDQ5#4": "40평형 대",
|
|
||||||
"KDQ5#5": "50평형 대 이상",
|
|
||||||
|
|
||||||
// 권역
|
|
||||||
"KSQ4_R_R#1": "서울, 인천, 경기도",
|
|
||||||
"KSQ4_R_R#2": "경남, 부산, 울산",
|
|
||||||
"KSQ4_R_R#3": "경북, 대구",
|
|
||||||
"KSQ4_R_R#4": "전라도, 광주",
|
|
||||||
"KSQ4_R_R#5": "충청, 대전, 세종",
|
|
||||||
"KSQ4_R_R#6": "강원, 제주",
|
|
||||||
|
|
||||||
// 소득
|
|
||||||
"KDQ3_DB#1": "299만원 이하",
|
|
||||||
"KDQ3_DB#2": "300~599만원 이하",
|
|
||||||
"KDQ3_DB#3": "600~899만원 이하",
|
|
||||||
"KDQ3_DB#4": "900만원 이상",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
|
||||||
{ key: "item", header: "", headRowSpan:2, rowHead: true, render: (r) => r.item },
|
|
||||||
|
|
||||||
{ key: "total", header: "전체", headRowSpan:2, max: 100, align: "left", cellType:"number"},
|
|
||||||
{ key: "KLIFEstAGE#1", header: "미혼" , headRowSpan:2, max: 100 , align: "left"},
|
|
||||||
|
|
||||||
{ key: "KLIFEstAGE#2", header: "무자녀", group: "기혼", max: 100 , align: "left"},
|
|
||||||
{ key: "KLIFEstAGE#3", header: "미취학", group: "기혼", max: 100 , align: "left"},
|
|
||||||
{ key: "KLIFEstAGE#4", header: "취학자녀", group: "기혼", max: 100 , align: "left"},
|
|
||||||
{ key: "KLIFEstAGE#5", header: "성인자녀", group: "기혼", max: 100 , align: "left"},
|
|
||||||
|
|
||||||
{ key: "KLIFEstAGE#6", header: "독립\n시니어", headRowSpan:2, max: 100 , align: "left"},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const LIFE_STAGE_GROUPS = [
|
|
||||||
{ title: "대형가전 군", items: ["KPRODUCT#1", "KPRODUCT#7", "KPRODUCT#8", "KPRODUCT#12", "KPRODUCT#14", "KPRODUCT#2", "KPRODUCT#3", "KPRODUCT#11"] },
|
|
||||||
{ title: "소형가전 군", items: ["KPRODUCT#9", "KPRODUCT#13", "KPRODUCT#4"] },
|
|
||||||
{ title: "신가전 군", items: ["KPRODUCT#10", "KPRODUCT#6"] },
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as Array<keyof typeof PRODUCT_KEY_MAP>;
|
|
||||||
export const PRODUCTS = Object.values(PRODUCT_KEY_MAP) as Array<string>;
|
|
||||||
|
|
||||||
export const PRODUCTS_FILTER_ITEM = [
|
|
||||||
{
|
|
||||||
path: "kitchen",
|
|
||||||
items: [
|
|
||||||
"KPRODUCT#1", // 냉장고
|
|
||||||
"KPRODUCT#2", // 김치 냉장고
|
|
||||||
"KPRODUCT#3", // 식기 세척기
|
|
||||||
"KPRODUCT#4", // 정수기
|
|
||||||
"KPRODUCT#5", // 전기 레인지
|
|
||||||
"KPRODUCT#6", // 음식물처리기
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "living",
|
|
||||||
items: [
|
|
||||||
"KPRODUCT#7", // 세탁기
|
|
||||||
"KPRODUCT#8", // 건조기
|
|
||||||
"KPRODUCT#9", // 청소기
|
|
||||||
"KPRODUCT#10", // 로봇 청소기
|
|
||||||
"KPRODUCT#11", // 의류 관리기
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "es",
|
|
||||||
items: [
|
|
||||||
"KPRODUCT#12", // 에어컨
|
|
||||||
"KPRODUCT#13", // 공기 청정기
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "ms",
|
|
||||||
items: [
|
|
||||||
"KPRODUCT#14", // TV
|
|
||||||
"KPRODUCT#15", // 모니터
|
|
||||||
"KPRODUCT#16", // 노트북
|
|
||||||
],
|
|
||||||
},
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export const BANNER_KEYS = Object.keys(BANNER_KEY_MAP) as Array<keyof typeof BANNER_KEY_MAP>;
|
|
||||||
export const BANNER_KEY = Object.keys(BANNER_KEY_MAP).reduce((acc, k) => {
|
|
||||||
(acc as any)[k] = k;
|
|
||||||
return acc;
|
|
||||||
}, {} as { [K in BannerKey]: K });
|
|
||||||
|
|
||||||
export const BANNER_GROUP = {
|
|
||||||
lifeStage: {
|
|
||||||
label: "라이프스테이지 별",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KLIFEstAGE#1"],
|
|
||||||
BANNER_KEY["KLIFEstAGE#2"],
|
|
||||||
BANNER_KEY["KLIFEstAGE#3"],
|
|
||||||
BANNER_KEY["KLIFEstAGE#4"],
|
|
||||||
BANNER_KEY["KLIFEstAGE#5"],
|
|
||||||
BANNER_KEY["KLIFEstAGE#6"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
household: {
|
|
||||||
label: "가구원수 별",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KSQ8_R_DB#1"],
|
|
||||||
BANNER_KEY["KSQ8_R_DB#2"],
|
|
||||||
BANNER_KEY["KSQ8_R_DB#3"],
|
|
||||||
BANNER_KEY["KSQ8_R_DB#4"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
age: {
|
|
||||||
label: "연령",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KSQ2_R_R#1"],
|
|
||||||
BANNER_KEY["KSQ2_R_R#2"],
|
|
||||||
BANNER_KEY["KSQ2_R_R#3"],
|
|
||||||
BANNER_KEY["KSQ2_R_R#4"],
|
|
||||||
BANNER_KEY["KSQ2_R_R#5"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
occupancy: {
|
|
||||||
label: "입주 형태",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KDQ6#1"],
|
|
||||||
BANNER_KEY["KDQ6#2"],
|
|
||||||
BANNER_KEY["KDQ6#3"],
|
|
||||||
BANNER_KEY["KDQ6#4"],
|
|
||||||
BANNER_KEY["KDQ6#5"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
housing: {
|
|
||||||
label: "주거 형태",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KDQ4#1"],
|
|
||||||
BANNER_KEY["KDQ4#2"],
|
|
||||||
BANNER_KEY["KDQ4#3"],
|
|
||||||
BANNER_KEY["KDQ4#4"],
|
|
||||||
BANNER_KEY["KDQ4#5"],
|
|
||||||
BANNER_KEY["KDQ4#6"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
houseSize: {
|
|
||||||
label: "거주 평형",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KDQ5#1"],
|
|
||||||
BANNER_KEY["KDQ5#2"],
|
|
||||||
BANNER_KEY["KDQ5#3"],
|
|
||||||
BANNER_KEY["KDQ5#4"],
|
|
||||||
BANNER_KEY["KDQ5#5"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
region: {
|
|
||||||
label: "거주 지역",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KSQ4_R_R#1"],
|
|
||||||
BANNER_KEY["KSQ4_R_R#2"],
|
|
||||||
BANNER_KEY["KSQ4_R_R#3"],
|
|
||||||
BANNER_KEY["KSQ4_R_R#4"],
|
|
||||||
BANNER_KEY["KSQ4_R_R#5"],
|
|
||||||
BANNER_KEY["KSQ4_R_R#6"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
income: {
|
|
||||||
label: "소득수준",
|
|
||||||
keys: [
|
|
||||||
BANNER_KEY["KDQ3_DB#1"],
|
|
||||||
BANNER_KEY["KDQ3_DB#2"],
|
|
||||||
BANNER_KEY["KDQ3_DB#3"],
|
|
||||||
BANNER_KEY["KDQ3_DB#4"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const BANNER_GROUP_KEY = Object.keys(BANNER_GROUP) as string[];
|
|
||||||
|
|
||||||
export const CATEGORY_PAGE_FIELDS: Record<CategoryTargetData, CategoryFieldSpec[]> = {
|
|
||||||
[CategoryTargetData.PROFILE]: [
|
|
||||||
{
|
|
||||||
title: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "보유율"
|
|
||||||
, [CategoryTargetType.PURCHASE]: "구매율"
|
|
||||||
, [CategoryTargetType.INTENDED]: "향후 구매율"
|
|
||||||
},
|
|
||||||
requestKey: "category_${keyBase}",
|
|
||||||
chartMode:"none",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA1"
|
|
||||||
, [CategoryTargetType.PURCHASE]: "KQA3_2"
|
|
||||||
, [CategoryTargetType.INTENDED]: "KQC1"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "보유대수",
|
|
||||||
requestKey: "category_penetration_count",
|
|
||||||
chartMode:"none",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA2"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
[CategoryTargetData.PENETRATION_CHANGE]: [
|
|
||||||
{
|
|
||||||
title: "보급률 변화",
|
|
||||||
requestKey: "category_${keyBase}",
|
|
||||||
chartMode:"none",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA1"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
[CategoryTargetData.BRAND]: [
|
|
||||||
{
|
|
||||||
title: "브랜드",
|
|
||||||
requestKey: "category_${keyBase}_brand",
|
|
||||||
chartMode:"reverseStack",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_3",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_3",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "",
|
|
||||||
[CategoryTargetType.PURCHASE]: "구매 고려 브랜드",
|
|
||||||
[CategoryTargetType.INTENDED]: "브랜드",
|
|
||||||
},
|
|
||||||
requestKey: "category_${keyBase}_consider_brand",
|
|
||||||
chartMode:"horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQB1",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
[CategoryTargetData.TYPE_SPEC]: [
|
|
||||||
{
|
|
||||||
title: "타입",
|
|
||||||
requestKey: "category_${keyBase}_type",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_4",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_4",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_1" }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "깊이 타입",
|
|
||||||
requestKey: "category_${keyBase}_depthType",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_5",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_5",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "용량",
|
|
||||||
requestKey: "category_${keyBase}_capacity",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_6",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "설치 형태",
|
|
||||||
requestKey: "category_${keyBase}_installType",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_7",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_7",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "시공 방식",
|
|
||||||
requestKey: "category_${keyBase}_installMethod",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "냉장고 & 김치냉장고 설치 형태",
|
|
||||||
requestKey: "category_${keyBase}_fridgeInstallType",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "설치 위치",
|
|
||||||
requestKey: "category_${keyBase}_installLocation",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "배치/설치환경",
|
|
||||||
requestKey: "category_${keyBase}_installEnv",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_8",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_8",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_7"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "구입 고려 특징",
|
|
||||||
requestKey: "category_${keyBase}_buyConsiderations",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC3_8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "기능",
|
|
||||||
requestKey: "category_${keyBase}_features",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_9",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_9"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "스크린 사이즈",
|
|
||||||
requestKey: "category_${keyBase}_screenSize",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_10",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "용도",
|
|
||||||
requestKey: "category_${keyBase}_usage",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_11",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_11"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "스마트 모니터 여부",
|
|
||||||
requestKey: "category_${keyBase}_isSmartMonitor",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_12",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
[CategoryTargetData.BEHAVIOR]: [
|
|
||||||
{
|
|
||||||
title: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "보유 경로"
|
|
||||||
, [CategoryTargetType.PURCHASE]: "구입 행태"
|
|
||||||
, [CategoryTargetType.INTENDED]: "구입 행태"
|
|
||||||
},
|
|
||||||
requestKey: "category_${keyBase}_behavior",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_1",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQB2",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC5"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "구입 계기",
|
|
||||||
requestKey: "category_${keyBase}_chance",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQB3"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
[CategoryTargetData.PURCHASE_CHANNEL]: [
|
|
||||||
{
|
|
||||||
title: "구매 채널(온/오프라인)",
|
|
||||||
requestKey: "category_${keyBase}_channel",
|
|
||||||
chartMode: "reverseStack",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQB4_NET",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC6_NET"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "구매 채널(상세)",
|
|
||||||
requestKey: "category_${keyBase}_channel_detail",
|
|
||||||
chartMode: "horizontal",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQB4",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC6"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
[CategoryTargetData.PAYMENT_METHOD]: [
|
|
||||||
{
|
|
||||||
title: "구매형식",
|
|
||||||
requestKey: "category_${keyBase}_method",
|
|
||||||
chartMode:"reverseStack",
|
|
||||||
qidByMode: {
|
|
||||||
[CategoryTargetType.PENETRATION]: "KQA3_2_1",
|
|
||||||
[CategoryTargetType.PURCHASE]: "KQX3_2_1",
|
|
||||||
[CategoryTargetType.INTENDED]: "KQC7"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 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;
|
|
||||||
|
|
||||||
export const CHART_COLOR_BY_YEAR = Object.fromEntries(
|
|
||||||
YEARS.map((year, i) => [
|
|
||||||
year,
|
|
||||||
`--chart-${YEARS.length-i}-t`,
|
|
||||||
])
|
|
||||||
) as Record<(typeof YEARS)[number], string>;
|
|
||||||
|
|
||||||
export const CHART_FOCUS_COLOR_BY_YEAR = Object.fromEntries(
|
|
||||||
YEARS.map((year, i) => [
|
|
||||||
year,
|
|
||||||
`--chart-${YEARS.length-i}`,
|
|
||||||
])
|
|
||||||
) as Record<(typeof YEARS)[number], string>;
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import {SubMenuItem, TopMenuItem} from "@/config/menu.types";
|
import {SubMenuItem, TopMenuItem} from "@/types/menu.types";
|
||||||
|
|
||||||
export const topMenus: TopMenuItem[] = [
|
export const topMenus: TopMenuItem[] = [
|
||||||
{
|
{
|
||||||
@@ -59,4 +59,4 @@ export const categorySubMenus: SubMenuItem[] = [
|
|||||||
label: "MS",
|
label: "MS",
|
||||||
path: "/category/ms",
|
path: "/category/ms",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import {DEBOUNCE_TIME} from "@/const/lg-common.const";
|
||||||
|
|
||||||
export function useDebouncedValue<T>(value: T, delayMs = 1200) {
|
export function useDebouncedValue<T>(value: T, delayMs = DEBOUNCE_TIME) {
|
||||||
const [debounced, setDebounced] = useState(value);
|
const [debounced, setDebounced] = useState(value);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CHART_GRID_DEFAULTS, BAR_WIDTHS } from "@/const/chartConst";
|
import { AXIS_HIDE_Y_STYLE, BAR_WIDTHS, CHART_GRID_DEFAULTS } from "@/components/lge-dashboard/chart/chart.config";
|
||||||
import {ChartData, NewNumber} from "@/components/lge-dashboard";
|
import {ChartData, NewNumber} from "@/components/lge-dashboard";
|
||||||
|
|
||||||
export function reverseCategories<T extends ChartData>(data: T): T {
|
export function reverseCategories<T extends ChartData>(data: T): T {
|
||||||
@@ -180,9 +180,7 @@ export function createValueAxis(
|
|||||||
if (hideStyle) {
|
if (hideStyle) {
|
||||||
return {
|
return {
|
||||||
...base,
|
...base,
|
||||||
axisLabel: { show: false },
|
...AXIS_HIDE_Y_STYLE,
|
||||||
axisTick: { show: false },
|
|
||||||
axisLine: { show: false },
|
|
||||||
splitLine: { show: false },
|
splitLine: { show: false },
|
||||||
...overrides,
|
...overrides,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ import {
|
|||||||
BannerRow, BuildPageModeConfigResult,
|
BannerRow, BuildPageModeConfigResult,
|
||||||
ProductResponse, ProductRow,
|
ProductResponse, ProductRow,
|
||||||
StatisticsRequest
|
StatisticsRequest
|
||||||
} from "@/types/lg";
|
} from "@/types/lg.types";
|
||||||
import {ChartData} from "@/components/lge-dashboard";
|
import {ChartData} from "@/components/lge-dashboard";
|
||||||
import {
|
import type { DataColumn } from "@/components/lge-dashboard/types";
|
||||||
BANNER_GROUP,
|
import {API_DECIMAL_POINT, GAP_WORDING, VIEW_DECIMAL_POINT} from "@/const/lg-common.const";
|
||||||
BANNER_KEYS,
|
import {BANNER_GROUP, BANNER_KEYS, type BannerGroupDefinition, type BannerGroupNode, flattenBannerGroupKeys} from "@/const/lg-banner.const";
|
||||||
CATEGORY_PAGE_FIELDS,
|
import {PRODUCT_KEYS} from "@/const/lg-product.const";
|
||||||
GAP_WORDING,
|
import {CATEGORY_PAGE_FIELDS} from "@/config/lg-page.config";
|
||||||
PRODUCT_KEYS
|
|
||||||
} from "@/const/lgConst";
|
|
||||||
import {formatNumber} from "@/lib/utils";
|
import {formatNumber} from "@/lib/utils";
|
||||||
import {nextApi} from "@/lib/http-client";
|
import {nextApi} from "@/lib/http-client";
|
||||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||||
|
|
||||||
export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "").includes("사례수");
|
export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "").includes("사례수");
|
||||||
|
|
||||||
|
export const isHasCountRow = (raw: string) => raw.replace(/\s+/g, "").includes("보유대수");
|
||||||
|
|
||||||
export const isCagrRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("CAGR");
|
export const isCagrRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("CAGR");
|
||||||
|
|
||||||
export const isGapRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("GAP");
|
export const isGapRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("GAP");
|
||||||
@@ -56,7 +56,7 @@ export function formatRowLabel(
|
|||||||
|
|
||||||
if (convertSample && t === "사례수") return "(사례수)";
|
if (convertSample && t === "사례수") return "(사례수)";
|
||||||
if (convertGap && t.toLowerCase() === "gap") return GAP_WORDING;
|
if (convertGap && t.toLowerCase() === "gap") return GAP_WORDING;
|
||||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%p)";
|
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%)";
|
||||||
if (convertYear && /^\d{4}$/.test(t)) return `${t.substring(2,4)}년`;
|
if (convertYear && /^\d{4}$/.test(t)) return `${t.substring(2,4)}년`;
|
||||||
if (convertYear && /^\d{2}$/.test(t)) return `${t}년`;
|
if (convertYear && /^\d{2}$/.test(t)) return `${t}년`;
|
||||||
if (convertRate && t.endsWith("율")) return `${t.replaceAll('(%)','')}(%)`;
|
if (convertRate && t.endsWith("율")) return `${t.replaceAll('(%)','')}(%)`;
|
||||||
@@ -66,7 +66,7 @@ export function formatRowLabel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: string }>(
|
export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: string }>(
|
||||||
rows: T[]
|
rows: T[], replaceLabel: boolean = true
|
||||||
): T[] => {
|
): T[] => {
|
||||||
return rows.map((r) => {
|
return rows.map((r) => {
|
||||||
if (!isSampleRow(r.rowLabel)) return r;
|
if (!isSampleRow(r.rowLabel)) return r;
|
||||||
@@ -76,18 +76,23 @@ export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: st
|
|||||||
Object.entries(r).forEach(([k, v]) => {
|
Object.entries(r).forEach(([k, v]) => {
|
||||||
if (k == "year" || v == null) return;
|
if (k == "year" || v == null) return;
|
||||||
|
|
||||||
if (typeof v === "number") {
|
if (
|
||||||
out[k] = `(${formatNumber(v)})`;
|
typeof v === "number" ||
|
||||||
|
(typeof v === "string" && v.trim() !== "" && !Number.isNaN(Number(v)))
|
||||||
|
) {
|
||||||
|
out[k] = `(${formatNumber(Number(v))})`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof v === "string") {
|
if(replaceLabel){
|
||||||
// 이미 괄호면 그대로
|
if (typeof v === "string") {
|
||||||
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
// 이미 괄호면 그대로
|
||||||
return;
|
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
out[k] = `(${String(v)})`;
|
out[k] = `(${String(v)})`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return out as T;
|
return out as T;
|
||||||
@@ -189,6 +194,9 @@ export function buildOverlayBarData<T extends { year: number; rowLabel: string }
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shouldExcludeLabel = (excludeRowLabels: string[], label: string) =>
|
||||||
|
excludeRowLabels.some((el) => label.includes(el));
|
||||||
|
|
||||||
type Opts = {
|
type Opts = {
|
||||||
/** 기본: ["사례수", "gap"] 제외 */
|
/** 기본: ["사례수", "gap"] 제외 */
|
||||||
excludeRowLabels?: string[];
|
excludeRowLabels?: string[];
|
||||||
@@ -207,25 +215,22 @@ export function buildYearSeriesChartData(rows: BannerRow[], opts: Opts = {}): Ch
|
|||||||
|
|
||||||
const years = Array.from(new Set(rows.map((r) => r.year))).sort((a, b) => Number(a) - Number(b));
|
const years = Array.from(new Set(rows.map((r) => r.year))).sort((a, b) => Number(a) - Number(b));
|
||||||
|
|
||||||
// rowLabel 순서: 첫 연도 기준으로 고정(없으면 전체 unique)
|
|
||||||
const baseYear = years[0];
|
const baseYear = years[0];
|
||||||
const baseLabels = rows
|
const baseLabels = rows
|
||||||
.filter((r) => r.year === baseYear)
|
.filter((r) => r.year === baseYear)
|
||||||
.map((r) => r.rowLabel)
|
.map((r) => r.rowLabel)
|
||||||
.filter((l) => !excludeRowLabels.includes(l));
|
.filter((l) => !shouldExcludeLabel(excludeRowLabels, l));
|
||||||
|
|
||||||
const labels =
|
const labels =
|
||||||
baseLabels.length > 0
|
baseLabels.length > 0
|
||||||
? baseLabels
|
? baseLabels
|
||||||
: Array.from(
|
: Array.from(new Set(rows.map((r) => r.rowLabel).filter((l) => !shouldExcludeLabel(excludeRowLabels, l))));
|
||||||
new Set(rows.map((r) => r.rowLabel).filter((l) => !excludeRowLabels.includes(l)))
|
|
||||||
);
|
|
||||||
|
|
||||||
// 빠른 조회용: year -> (rowLabel -> total)
|
|
||||||
const map = new Map<string, Map<string, number>>();
|
const map = new Map<string, Map<string, number>>();
|
||||||
for (const y of years) map.set(y, new Map());
|
for (const y of years) map.set(y, new Map());
|
||||||
|
|
||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
if (excludeRowLabels.includes(r.rowLabel)) continue;
|
if (shouldExcludeLabel(excludeRowLabels, r.rowLabel)) continue;
|
||||||
map.get(r.year)?.set(r.rowLabel, Number(r.total ?? 0));
|
map.get(r.year)?.set(r.rowLabel, Number(r.total ?? 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +239,7 @@ export function buildYearSeriesChartData(rows: BannerRow[], opts: Opts = {}): Ch
|
|||||||
series: years.map((y) => ({
|
series: years.map((y) => ({
|
||||||
name: yearLabel(y),
|
name: yearLabel(y),
|
||||||
data: labels.map((lbl) => map.get(y)?.get(lbl) ?? null),
|
data: labels.map((lbl) => map.get(y)?.get(lbl) ?? null),
|
||||||
...(splitStackByYear ? { stack: String(y) } : {}), // 같은 stack이면 "연도끼리 스택"되어버리니 방지용
|
...(splitStackByYear ? { stack: String(y) } : {}),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -255,13 +260,13 @@ export function buildRowLabelSeriesChartData(
|
|||||||
const baseRowLabels = rows
|
const baseRowLabels = rows
|
||||||
.filter((r) => r.year === baseYear)
|
.filter((r) => r.year === baseYear)
|
||||||
.map((r) => r.rowLabel)
|
.map((r) => r.rowLabel)
|
||||||
.filter((l) => !excludeRowLabels.includes(l));
|
.filter((l) => !shouldExcludeLabel(excludeRowLabels, l));
|
||||||
|
|
||||||
const rowLabels =
|
const rowLabels =
|
||||||
baseRowLabels.length > 0
|
baseRowLabels.length > 0
|
||||||
? baseRowLabels
|
? baseRowLabels
|
||||||
: Array.from(
|
: Array.from(
|
||||||
new Set(rows.map((r) => r.rowLabel).filter((l) => !excludeRowLabels.includes(l)))
|
new Set(rows.map((r) => r.rowLabel).filter((l) => !shouldExcludeLabel(excludeRowLabels, l)))
|
||||||
);
|
);
|
||||||
|
|
||||||
// (year -> (rowLabel -> total)) 맵
|
// (year -> (rowLabel -> total)) 맵
|
||||||
@@ -269,7 +274,7 @@ export function buildRowLabelSeriesChartData(
|
|||||||
for (const y of years) valueMap.set(y, new Map());
|
for (const y of years) valueMap.set(y, new Map());
|
||||||
|
|
||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
if (excludeRowLabels.includes(r.rowLabel)) continue;
|
if (shouldExcludeLabel(excludeRowLabels, r.rowLabel)) continue;
|
||||||
valueMap.get(r.year)!.set(r.rowLabel, Number(r.total ?? 0));
|
valueMap.get(r.year)!.set(r.rowLabel, Number(r.total ?? 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,6 +319,47 @@ export const buildGapRow = (
|
|||||||
|
|
||||||
export const isBannerGroupKey = (v: string): v is BannerGroupKey => v in BANNER_GROUP;
|
export const isBannerGroupKey = (v: string): v is BannerGroupKey => v in BANNER_GROUP;
|
||||||
|
|
||||||
|
export function buildBannerGroupColumns<T extends Record<string, unknown>>(
|
||||||
|
group: BannerGroupDefinition,
|
||||||
|
keyLabelMap: Record<string, string>,
|
||||||
|
options: {
|
||||||
|
width?: number | string;
|
||||||
|
numeric?: boolean;
|
||||||
|
resolveLeafMeta?: (key: string, index: number, total: number) => {
|
||||||
|
headerClassName?: string;
|
||||||
|
cellClassName?: string;
|
||||||
|
};
|
||||||
|
} = {}
|
||||||
|
): DataColumn<T>[] {
|
||||||
|
const leafKeys = flattenBannerGroupKeys(group.children);
|
||||||
|
let leafIndex = 0;
|
||||||
|
|
||||||
|
const visit = (nodes: readonly BannerGroupNode[]): DataColumn<T>[] =>
|
||||||
|
nodes.map((node) => {
|
||||||
|
if (node.type === "leaf") {
|
||||||
|
const currentLeafIndex = leafIndex++;
|
||||||
|
const meta = options.resolveLeafMeta?.(node.key, currentLeafIndex, leafKeys.length);
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: node.key as keyof T,
|
||||||
|
header: keyLabelMap[node.key] ?? String(node.key),
|
||||||
|
numeric: options.numeric,
|
||||||
|
width: options.width,
|
||||||
|
headerClassName: meta?.headerClassName,
|
||||||
|
cellClassName: meta?.cellClassName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: node.id,
|
||||||
|
header: node.label,
|
||||||
|
children: visit(node.children),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return visit(group.children);
|
||||||
|
}
|
||||||
|
|
||||||
export const fetchProductStatistics = (req: StatisticsRequest) =>
|
export const fetchProductStatistics = (req: StatisticsRequest) =>
|
||||||
nextApi.post<ProductResponse>("/statistics/product", req);
|
nextApi.post<ProductResponse>("/statistics/product", req);
|
||||||
|
|
||||||
@@ -393,16 +439,29 @@ export const buildCategoryFilter = (
|
|||||||
return Object.keys(out).length ? out : undefined;
|
return Object.keys(out).length ? out : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fixedDecimalPoint = (n: number, decimalPoint?: number): string => {
|
||||||
|
decimalPoint ??= API_DECIMAL_POINT;
|
||||||
|
return n.toFixed(decimalPoint);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const roundNumber = (num: number|null, decimalPoint?: number) => {
|
||||||
|
if(num == null) return null;
|
||||||
|
|
||||||
|
decimalPoint ??= VIEW_DECIMAL_POINT;
|
||||||
|
const factor = 10 ** decimalPoint;
|
||||||
|
return Math.round(num * factor) / factor;
|
||||||
|
};
|
||||||
|
|
||||||
export const calcGapProductRow = (after: ProductRow, before: ProductRow): ProductRow => {
|
export const calcGapProductRow = (after: ProductRow, before: ProductRow): ProductRow => {
|
||||||
const out: ProductRow = {
|
const out: ProductRow = {
|
||||||
year: after?.year ?? "",
|
year: after?.year ?? "",
|
||||||
rowLabel: "gap",
|
rowLabel: "gap",
|
||||||
total: String(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
total: fixedDecimalPoint(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
||||||
};
|
};
|
||||||
for (const k of PRODUCT_KEYS) {
|
for (const k of PRODUCT_KEYS) {
|
||||||
const a = after? after[k] ?? "0" : "0";
|
const a = after? after[k] ?? "0" : "0";
|
||||||
const b = before? before[k] ?? "0" : "0";
|
const b = before? before[k] ?? "0" : "0";
|
||||||
out[k] = String(Number(a) - Number(b));
|
out[k] = fixedDecimalPoint(Number(a) - Number(b));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
@@ -411,17 +470,23 @@ export const calcGapBannerRow = (after: BannerRow, before: BannerRow): BannerRow
|
|||||||
const out: BannerRow = {
|
const out: BannerRow = {
|
||||||
year: after?.year ?? "",
|
year: after?.year ?? "",
|
||||||
rowLabel: "gap",
|
rowLabel: "gap",
|
||||||
total: String(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
total: fixedDecimalPoint(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
||||||
};
|
};
|
||||||
for (const k of BANNER_KEYS) {
|
for (const k of BANNER_KEYS) {
|
||||||
const a = after? after[k] ?? "0" : "0";
|
const a = after? after[k] ?? "0" : "0";
|
||||||
const b = before? before[k] ?? "0" : "0";
|
const b = before? before[k] ?? "0" : "0";
|
||||||
out[k] = String(Number(a) - Number(b));
|
out[k] = fixedDecimalPoint(Number(a) - Number(b));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
const round1 = (n: number) => Math.round(n * 10) / 10;
|
const calcCagr = (after: number, before: number, years:number): number => {
|
||||||
|
const power = Math.pow(after / before, 1 / years);
|
||||||
|
const cagr = power - 1;
|
||||||
|
const cagr100 = cagr * 100;
|
||||||
|
|
||||||
|
return cagr100;
|
||||||
|
};
|
||||||
|
|
||||||
export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow => {
|
export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow => {
|
||||||
const years = 2; // 24 -> 26
|
const years = 2; // 24 -> 26
|
||||||
@@ -433,32 +498,33 @@ export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow =
|
|||||||
|
|
||||||
// total은 참고용으로만: (26/24) CAGR %
|
// total은 참고용으로만: (26/24) CAGR %
|
||||||
out.total =
|
out.total =
|
||||||
Number(before?.total ?? "0") > 0 ? String(round1((Math.pow(Number(after?.total ?? "0") / Number(before?.total ?? "0"), 1 / years) - 1) * 100)) : "0";
|
fixedDecimalPoint((before?.total ?? "0") > "0" ? calcCagr(Number(after?.total ?? "0"), Number(before?.total ?? "0"), years) : 0, 1);
|
||||||
|
|
||||||
for (const k of PRODUCT_KEYS) {
|
for (const k of PRODUCT_KEYS) {
|
||||||
const vBefore = before? before[k] ?? "0" : "0";
|
const vBefore = before? before[k] ?? "0" : "0";
|
||||||
const vAfter = after? after[k] ?? "0" : "0";
|
const vAfter = after? after[k] ?? "0" : "0";
|
||||||
out[k] = Number(vBefore) > 0 ? String(round1((Math.pow(Number(vAfter) / Number(vBefore), 1 / years) - 1) * 100)) : "0";
|
out[k] = fixedDecimalPoint(Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : 0, 1);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const makeTotalBasePct = (t:number|string, f:number|string):number => {
|
export const makeTotalBasePct = (t:number|string, f:number|string):number => {
|
||||||
return Number(t) > 0 ? Math.round((Number(f) / Number(t)) * 100) : 0;
|
return Number(t) > 0 ? (Number(f) * 100) / Number(t) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow: ProductRow): ProductRow => {
|
export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow: ProductRow): ProductRow => {
|
||||||
const out: ProductRow = {
|
const out: ProductRow = {
|
||||||
year: targetRow?.year ?? "",
|
year: targetRow?.year ?? "",
|
||||||
rowLabel: `전체 ${label} 중 자사제품 비율`,
|
//rowLabel: `**조사 년도 ${label} 중 자사제품 비율`,
|
||||||
total: String(makeTotalBasePct(totalRow.total, targetRow.total))
|
rowLabel: `**자사제품 비율`,
|
||||||
|
total: fixedDecimalPoint(makeTotalBasePct(totalRow.total, targetRow.total))
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const k of PRODUCT_KEYS) {
|
for (const k of PRODUCT_KEYS) {
|
||||||
const t = totalRow? totalRow[k] ?? "0" : "0";
|
const t = totalRow? totalRow[k] ?? "0" : "0";
|
||||||
const f = targetRow? targetRow[k] ?? "0" : "0";
|
const f = targetRow? targetRow[k] ?? "0" : "0";
|
||||||
out[k] = String(makeTotalBasePct(t, f));
|
out[k] = fixedDecimalPoint(makeTotalBasePct(t, f));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
@@ -466,20 +532,24 @@ export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow:
|
|||||||
|
|
||||||
export const withGapRow = <T>(
|
export const withGapRow = <T>(
|
||||||
rows: T[],
|
rows: T[],
|
||||||
calcGapRow: (last: T, secondLast: T) => T
|
calcGapRow: (last: T, secondLast: T) => T,
|
||||||
|
lastIndex: number,
|
||||||
|
secondLastIndex: number,
|
||||||
): T[] => {
|
): T[] => {
|
||||||
const last = rows.at(-1);
|
const last = rows.at(lastIndex);
|
||||||
const secondLast = rows.at(-2);
|
const secondLast = rows.at(secondLastIndex);
|
||||||
if (!last || !secondLast) return rows;
|
if (!last || !secondLast) return rows;
|
||||||
return [calcGapRow(last, secondLast), ...rows];
|
return [calcGapRow(last, secondLast), ...rows];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const withCagrRow = <T>(
|
export const withCagrRow = <T>(
|
||||||
rows: T[],
|
rows: T[],
|
||||||
calcCagrRow: (last: T, first: T) => T
|
calcCagrRow: (last: T, first: T) => T,
|
||||||
|
lastIndex: number,
|
||||||
|
firstIndex: number,
|
||||||
): T[] => {
|
): T[] => {
|
||||||
const first = rows.at(0);
|
const first = rows.at(firstIndex);
|
||||||
const last = rows.at(-1);
|
const last = rows.at(lastIndex);
|
||||||
if (!first || !last) return rows;
|
if (!first || !last) return rows;
|
||||||
return [...rows, calcCagrRow(last, first)];
|
return [...rows, calcCagrRow(last, first)];
|
||||||
}
|
}
|
||||||
@@ -515,4 +585,4 @@ export const buildPageModeConfig = (
|
|||||||
const variableIdMap = Object.fromEntries(fields.map((f) => [f.requestKeyResolved, f.qid])) as Record<string, string>;
|
const variableIdMap = Object.fromEntries(fields.map((f) => [f.requestKeyResolved, f.qid])) as Record<string, string>;
|
||||||
|
|
||||||
return { fields, variableIdMap };
|
return { fields, variableIdMap };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
// exportDashboardExcel.ts
|
// exportDashboardExcel.ts
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {formatRowLabel} from "@/lib/lg-dashboard";
|
import { buildBannerGroupColumns, formatRowLabel } from "@/lib/lg-dashboard";
|
||||||
import {DataColumn} from "@/components/lge-dashboard";
|
import { DataColumn, GaugeColumn } from "@/components/lge-dashboard";
|
||||||
|
import { buildHeaderRows, getLeafColumns, type TableColumnNode } from "@/components/lge-dashboard/table/core/table-core.helpers";
|
||||||
|
import type { BannerGroupDefinition } from "@/const/lg-banner.const";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 요구사항:
|
* 요구사항:
|
||||||
* - 한 파일에 (1) PRODUCT_KEY_MAP 헤더, (2) LIFE_STAGE_COLUMNS 헤더(그룹 머지), (3) BANNER_GROUP 헤더(좌측 2칸 rowspan2 + 그룹 머지)
|
* - 한 파일에 (1) PRODUCT_KEY_MAP 헤더, (2) LIFE_STAGE_COLUMNS 헤더, (3) BANNER_GROUP 헤더를 함께 지원
|
||||||
* - Excel export (한 시트, 섹션 간 1행 띄움)
|
* - Excel export는 한 시트에 여러 섹션을 순서대로 기록
|
||||||
* - 헤더 스타일:
|
* - 헤더 스타일:
|
||||||
* group: background = --lg-gray-400
|
* group: background = --lg-gray-400
|
||||||
* header: background = --lg-gray-600
|
* header: background = --lg-gray-600
|
||||||
* font: #fff, bold
|
* font: #fff, bold
|
||||||
*/
|
*/
|
||||||
@@ -47,9 +49,9 @@ type ExportOptions<T extends Record<string, any>> = {
|
|||||||
sheetName?: string;
|
sheetName?: string;
|
||||||
sections: Section<T>[];
|
sections: Section<T>[];
|
||||||
// CSS 변수(없으면 기본값)
|
// CSS 변수(없으면 기본값)
|
||||||
groupBgVar?: string; // default "--lg-gray-400"
|
groupBgVar?: string; // default "--lg-gray-400"
|
||||||
headerBgVar?: string; // default "--lg-gray-600"
|
headerBgVar?: string; // default "--lg-gray-600"
|
||||||
borderVar?: string; // default "--lg-gray-300"
|
borderVar?: string; // default "--lg-gray-300"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
@@ -208,11 +210,11 @@ function writeMergedHeader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AutoFitOpt = {
|
type AutoFitOpt = {
|
||||||
minColWidth?: number; // Excel column width units
|
minColWidth?: number; // Excel column width units
|
||||||
maxColWidth?: number;
|
maxColWidth?: number;
|
||||||
padding?: number; // width 여유(문자수 기준)
|
padding?: number; // width 여유(문자수 기준)
|
||||||
baseRowHeight?: number; // pt
|
baseRowHeight?: number; // pt
|
||||||
maxRowHeight?: number; // pt
|
maxRowHeight?: number; // pt
|
||||||
useCanvasMeasure?: boolean; // 브라우저에서 measureText로 더 정확하게
|
useCanvasMeasure?: boolean; // 브라우저에서 measureText로 더 정확하게
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -257,7 +259,7 @@ function fitColumns(ws: any, mergeMap: Map<string, MergeInfo>, o: Required<AutoF
|
|||||||
const w = estimateWidth(text, cell, o); // width in "excel-char-like units"
|
const w = estimateWidth(text, cell, o); // width in "excel-char-like units"
|
||||||
|
|
||||||
if (mi && mi.colSpan > 1) {
|
if (mi && mi.colSpan > 1) {
|
||||||
// 머지된 텍스트는 span만큼 나눠서 분배(머지 텍스트 때문에 한 컬럼이 과대해지는 현상 방지)
|
// 머지된 텍스트는 span만큼 나눠서 분배(한 컬럼 폭이 과대해지는 현상 방지)
|
||||||
const perCol = w / mi.colSpan;
|
const perCol = w / mi.colSpan;
|
||||||
for (let c = mi.leftCol; c <= mi.rightCol; c++) {
|
for (let c = mi.leftCol; c <= mi.rightCol; c++) {
|
||||||
widths[c] = Math.max(widths[c], perCol);
|
widths[c] = Math.max(widths[c], perCol);
|
||||||
@@ -299,7 +301,7 @@ function fitRows(ws: any, mergeMap: Map<string, MergeInfo>, o: Required<AutoFitO
|
|||||||
? sumColumnWidth(ws, mi.leftCol, mi.rightCol, o)
|
? sumColumnWidth(ws, mi.leftCol, mi.rightCol, o)
|
||||||
: getColumnWidth(ws, colNumber, o);
|
: getColumnWidth(ws, colNumber, o);
|
||||||
|
|
||||||
// 각 라인 별로 "줄바꿈이 몇 줄로 늘어나는지" 근사
|
// 각 라인별로 줄바꿈이 몇 줄로 늘어나는지 근사
|
||||||
let cellLines = 0;
|
let cellLines = 0;
|
||||||
for (const line of explicitLines) {
|
for (const line of explicitLines) {
|
||||||
const lineW = estimateWidth(line, cell, o);
|
const lineW = estimateWidth(line, cell, o);
|
||||||
@@ -326,11 +328,11 @@ function estimateWidth(text: string, cell: any, o: Required<AutoFitOpt>) {
|
|||||||
|
|
||||||
if (o.useCanvasMeasure && typeof document !== "undefined") {
|
if (o.useCanvasMeasure && typeof document !== "undefined") {
|
||||||
const px = measureTextPx(maxLine, cell);
|
const px = measureTextPx(maxLine, cell);
|
||||||
// Excel column width 단위는 폰트마다 다르지만 Calibri 11 기준으로 px/7 정도가 근사치로 많이 씀
|
// Excel column width 단위는 폰트마다 다르지만 Calibri 11 기준으로 px/7 정도를 사용
|
||||||
return px / 7;
|
return px / 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
// canvas 못 쓰는 환경(또는 성능 이유) -> 문자폭 가중치 근사
|
// canvas를 못 쓰는 환경이면 문자 폭 가중치로 근사
|
||||||
return estimateByCharWeight(maxLine);
|
return estimateByCharWeight(maxLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,11 +352,11 @@ function getMeasureCanvas() {
|
|||||||
return __canvas;
|
return __canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 한글/중국어/일본어 등 wide char 가중치 + 숫자/영문 가중치
|
// 한글/CJK wide char 가중치 + 숫자/영문 가중치
|
||||||
function estimateByCharWeight(s: string) {
|
function estimateByCharWeight(s: string) {
|
||||||
let w = 0;
|
let w = 0;
|
||||||
for (const ch of s) {
|
for (const ch of s) {
|
||||||
if (isWideChar(ch)) w += 1.7; // 한글/한자/가나 등
|
if (isWideChar(ch)) w += 1.7; // 한글/한자/가나 등
|
||||||
else if (ch === " ") w += 0.6;
|
else if (ch === " ") w += 0.6;
|
||||||
else if (/[A-Z]/.test(ch)) w += 1.1;
|
else if (/[A-Z]/.test(ch)) w += 1.1;
|
||||||
else if (/[0-9]/.test(ch)) w += 1.0;
|
else if (/[0-9]/.test(ch)) w += 1.0;
|
||||||
@@ -441,7 +443,7 @@ function buildMergeMap(ws: any) {
|
|||||||
const merges = ws?._merges;
|
const merges = ws?._merges;
|
||||||
if (!merges) return map;
|
if (!merges) return map;
|
||||||
|
|
||||||
// ws._merges: Map<string, any> 형태인 경우가 많음. key가 "A1:C1" 같은 range
|
// ws._merges: Map<string, any> 형태인 경우가 많고 key는 "A1:C1" 같은 range
|
||||||
const keys: string[] =
|
const keys: string[] =
|
||||||
merges instanceof Map ? Array.from(merges.keys()) : Object.keys(merges);
|
merges instanceof Map ? Array.from(merges.keys()) : Object.keys(merges);
|
||||||
|
|
||||||
@@ -459,7 +461,7 @@ function buildMergeMap(ws: any) {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "A1:C3" -> 좌표
|
// "A1:C3" -> 醫뚰몴
|
||||||
function parseRange(range: string): Omit<MergeInfo, "colSpan"> | null {
|
function parseRange(range: string): Omit<MergeInfo, "colSpan"> | null {
|
||||||
const parts = range.split(":");
|
const parts = range.split(":");
|
||||||
if (parts.length !== 2) return null;
|
if (parts.length !== 2) return null;
|
||||||
@@ -507,7 +509,7 @@ function colToLetters(col: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
* 3) 헤더 빌더 3종
|
* 3) 헤더 빌더
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -517,12 +519,16 @@ function colToLetters(col: number) {
|
|||||||
*/
|
*/
|
||||||
export function buildHeader_ProductKeyMap(
|
export function buildHeader_ProductKeyMap(
|
||||||
productKeyMap: Record<string, string>,
|
productKeyMap: Record<string, string>,
|
||||||
|
sampleHeadKey? :string,
|
||||||
rowHeadKey = "rowLabel"
|
rowHeadKey = "rowLabel"
|
||||||
): HeaderBlock {
|
): HeaderBlock {
|
||||||
const entries = typedEntries(productKeyMap);
|
const entries = typedEntries(productKeyMap);
|
||||||
|
|
||||||
const headerRow: HeaderCell[] = [
|
const headerRow: HeaderCell[] = [
|
||||||
{ text: "", styleKey: "header", align: "center" },
|
{ text: "", styleKey: "header", align: "center" },
|
||||||
|
...(sampleHeadKey
|
||||||
|
? [{ text: "사례수", styleKey: "header", align: "center" } as const]
|
||||||
|
: []),
|
||||||
...entries.map(([, label]) => ({
|
...entries.map(([, label]) => ({
|
||||||
text: String(label),
|
text: String(label),
|
||||||
styleKey: "header" as const,
|
styleKey: "header" as const,
|
||||||
@@ -530,180 +536,63 @@ export function buildHeader_ProductKeyMap(
|
|||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
|
|
||||||
const leafKeys = [rowHeadKey, ...entries.map(([k]) => String(k))];
|
|
||||||
|
const leafKeys = [rowHeadKey, ...(sampleHeadKey? [sampleHeadKey]: []), ...entries.map(([k]) => String(k))];
|
||||||
return { headerRows: [headerRow], leafKeys, totalCols: headerRow.length };
|
return { headerRows: [headerRow], leafKeys, totalCols: headerRow.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (2) LIFE_STAGE_COLUMNS:
|
* (2) LIFE_STAGE_COLUMNS:
|
||||||
* - 1행: group 머지(같은 group 연속 구간)
|
* - 트리 기반 컬럼에서 header row를 계산
|
||||||
* - 2행: header 텍스트
|
* - HTML 테이블과 동일한 merge 구조를 Excel에 적용
|
||||||
*
|
|
||||||
* group 없는 컬럼은 1행에 빈 셀(그룹 스타일) 1칸 채움
|
|
||||||
*/
|
*/
|
||||||
export type GaugeColumn = {
|
function buildHeaderBlockFromColumns<T>(cols: TableColumnNode<T>[]): HeaderBlock {
|
||||||
key: string;
|
const headerRows = buildHeaderRows(cols).map((row) =>
|
||||||
header: string;
|
row.map((cell) => ({
|
||||||
rowHead?: boolean;
|
text: cell.label,
|
||||||
group?: string;
|
styleKey: (cell.isLeaf ? "header" : "group") as HeaderStyleKey,
|
||||||
align?: "left" | "center" | "right";
|
rowSpan: cell.rowSpan,
|
||||||
};
|
colSpan: cell.colSpan,
|
||||||
|
align: "center" as const,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
export function buildHeader_LifeStageColumns(cols: GaugeColumn[]): HeaderBlock {
|
const leafKeys = getLeafColumns(cols).map((column) => String(column.key));
|
||||||
const row1: HeaderCell[] = [];
|
return { headerRows, leafKeys, totalCols: leafKeys.length };
|
||||||
const row2: HeaderCell[] = [];
|
}
|
||||||
const leafKeys = cols.map((c) => c.key);
|
|
||||||
|
|
||||||
let i = 0;
|
export function buildHeader_LifeStageColumns<T>(cols: GaugeColumn<T>[]): HeaderBlock {
|
||||||
while (i < cols.length) {
|
return buildHeaderBlockFromColumns(cols);
|
||||||
const c = cols[i];
|
|
||||||
const g = c.group;
|
|
||||||
|
|
||||||
if (!g) {
|
|
||||||
row1.push({ text: "", styleKey: "group", colSpan: 1, align: "center" });
|
|
||||||
i += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let j = i + 1;
|
|
||||||
while (j < cols.length && cols[j].group === g) j += 1;
|
|
||||||
const span = j - i;
|
|
||||||
|
|
||||||
row1.push({ text: g, styleKey: "group", colSpan: span, align: "center" });
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const c of cols) {
|
|
||||||
row2.push({ text: c.header ?? "", styleKey: "header", colSpan: 1, align: "center" });
|
|
||||||
}
|
|
||||||
|
|
||||||
return { headerRows: [row1, row2], leafKeys, totalCols: cols.length };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildHeader_DataColumn<T>(cols: DataColumn<T>[]): HeaderBlock {
|
export function buildHeader_DataColumn<T>(cols: DataColumn<T>[]): HeaderBlock {
|
||||||
const row1: HeaderCell[] = [];
|
return buildHeaderBlockFromColumns(cols);
|
||||||
const row2: HeaderCell[] = [];
|
|
||||||
|
|
||||||
const leafKeys = cols.map((c) => String(c.key));
|
|
||||||
|
|
||||||
// 1행: 그룹 머지 / rowspan 처리
|
|
||||||
let i = 0;
|
|
||||||
while (i < cols.length) {
|
|
||||||
const c = cols[i];
|
|
||||||
const rs = c.headRowSpan ?? 1;
|
|
||||||
|
|
||||||
// (A) rowspan=2면: 1행에 header를 올리고(세로머지), 2행은 빈 칸(placeholder)
|
|
||||||
if (rs === 2) {
|
|
||||||
row1.push({
|
|
||||||
text: c.header ?? "",
|
|
||||||
styleKey: "header",
|
|
||||||
colSpan: 1,
|
|
||||||
rowSpan: 2,
|
|
||||||
align: c.align ?? "center",
|
|
||||||
});
|
|
||||||
i += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// (B) 그룹 구간 처리
|
|
||||||
const gKey = c.groupKey ?? c.group;
|
|
||||||
if (gKey) {
|
|
||||||
let j = i + 1;
|
|
||||||
while (j < cols.length) {
|
|
||||||
const cj = cols[j];
|
|
||||||
const rsj = cj.headRowSpan ?? 1;
|
|
||||||
const gKeyJ = cj.groupKey ?? cj.group;
|
|
||||||
|
|
||||||
// rowspan=2가 섞이면 그룹 머지 끊음(안정성)
|
|
||||||
if (rsj === 2) break;
|
|
||||||
if (gKeyJ !== gKey) break;
|
|
||||||
|
|
||||||
j += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const span = j - i;
|
|
||||||
|
|
||||||
row1.push({
|
|
||||||
text: c.group ?? "",
|
|
||||||
styleKey: "group",
|
|
||||||
colSpan: span,
|
|
||||||
align: "center",
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2행: 그룹 구간의 각 컬럼 header
|
|
||||||
for (let k = i; k < j; k++) {
|
|
||||||
const ck = cols[k];
|
|
||||||
row2.push({
|
|
||||||
text: ck.header ?? "",
|
|
||||||
styleKey: "header",
|
|
||||||
colSpan: 1,
|
|
||||||
align: ck.align ?? "center",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
i = j;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// (C) 그룹도 없고 rowspan도 아니면: 1행에 빈 group 셀 1개, 2행에 header
|
|
||||||
row1.push({
|
|
||||||
text: "",
|
|
||||||
styleKey: "group",
|
|
||||||
colSpan: 1,
|
|
||||||
align: "center",
|
|
||||||
});
|
|
||||||
row2.push({
|
|
||||||
text: c.header ?? "",
|
|
||||||
styleKey: "header",
|
|
||||||
colSpan: 1,
|
|
||||||
align: c.align ?? "center",
|
|
||||||
});
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
headerRows: [row1, row2],
|
|
||||||
leafKeys,
|
|
||||||
totalCols: cols.length,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (3) BANNER_GROUP + BANNER_KEY_MAP:
|
* (3) BANNER_GROUP + BANNER_KEY_MAP:
|
||||||
* - A1: "" (rowspan2)
|
* - A1: "" (rowspan2)
|
||||||
* - B1: "전체" (rowspan2) key=total
|
* - B1: "전체" (rowspan2) key=total
|
||||||
* - C1~: group(label) (colSpan = keys.length)
|
* - C1~: group(label) (colSpan = keys.ts.length)
|
||||||
* - 2행: 각 key의 라벨(BANNER_KEY_MAP[key])
|
* - 2행: 각 key의 라벨(BANNER_KEY_MAP[key])
|
||||||
*/
|
*/
|
||||||
export function buildHeader_Banner<K extends string>(
|
export function buildHeader_Banner<K extends string>(
|
||||||
bannerGroup: Record<string, { label: string; keys: readonly K[] }>,
|
bannerGroup: Record<string, BannerGroupDefinition>,
|
||||||
bannerKeyMap: Record<K, string>,
|
bannerKeyMap: Record<K, string>,
|
||||||
rowHeadKey = "rowLabel",
|
rowHeadKey = "rowLabel",
|
||||||
totalKey = "total"
|
totalKey = "total"
|
||||||
): HeaderBlock {
|
): HeaderBlock {
|
||||||
const groups = Object.values(bannerGroup);
|
const columns: DataColumn<Record<string, unknown>>[] = [
|
||||||
|
{ key: rowHeadKey, header: "" },
|
||||||
const row1: HeaderCell[] = [
|
{ key: totalKey, header: "전체" },
|
||||||
{ text: "", styleKey: "header", rowSpan: 2, colSpan: 1, align: "center" },
|
...Object.entries(bannerGroup).map(([groupKey, group]) => ({
|
||||||
{ text: "전체", styleKey: "header", rowSpan: 2, colSpan: 1, align: "center" },
|
id: `banner-${groupKey}`,
|
||||||
|
header: group.label,
|
||||||
|
children: buildBannerGroupColumns<Record<string, unknown>>(group, bannerKeyMap),
|
||||||
|
})),
|
||||||
];
|
];
|
||||||
|
|
||||||
const row2: HeaderCell[] = [];
|
return buildHeaderBlockFromColumns(columns);
|
||||||
const leafKeys: string[] = [rowHeadKey, totalKey];
|
|
||||||
|
|
||||||
for (const g of groups) {
|
|
||||||
row1.push({ text: g.label, styleKey: "group", colSpan: g.keys.length, align: "center" });
|
|
||||||
|
|
||||||
for (const k of g.keys) {
|
|
||||||
row2.push({ text: bannerKeyMap[k] ?? k, styleKey: "header", colSpan: 1, align: "center" });
|
|
||||||
leafKeys.push(k);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const totalCols = 2 + groups.reduce((acc, g) => acc + g.keys.length, 0);
|
|
||||||
return { headerRows: [row1, row2], leafKeys, totalCols };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
* 4) Export (one sheet, 섹션 간 1행 띄움)
|
* 4) Export (one sheet, 섹션 간 1행 띄움)
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
@@ -717,7 +606,7 @@ export async function exportDashboardExcel<T extends Record<string, any>>(opts:
|
|||||||
borderVar = "--lg-gray-300",
|
borderVar = "--lg-gray-300",
|
||||||
} = opts;
|
} = opts;
|
||||||
|
|
||||||
// ExcelJS import (환경에 따라 min 빌드가 더 잘 먹는 경우가 있음)
|
// ExcelJS import (환경에 따라 min 빌드가 더 잘 동작하는 경우가 있음)
|
||||||
const ExcelJS = await import("exceljs");
|
const ExcelJS = await import("exceljs");
|
||||||
const wb = new ExcelJS.Workbook();
|
const wb = new ExcelJS.Workbook();
|
||||||
const ws = wb.addWorksheet(sheetName);
|
const ws = wb.addWorksheet(sheetName);
|
||||||
@@ -735,7 +624,7 @@ export async function exportDashboardExcel<T extends Record<string, any>>(opts:
|
|||||||
const gap = sec.rowGap ?? 1;
|
const gap = sec.rowGap ?? 1;
|
||||||
const { header, rows } = sec;
|
const { header, rows } = sec;
|
||||||
|
|
||||||
// (선택) 섹션 타이틀
|
// 섹션 타이틀
|
||||||
if (sec.title) {
|
if (sec.title) {
|
||||||
const r = ws.getRow(rowCursor);
|
const r = ws.getRow(rowCursor);
|
||||||
const c = r.getCell(1);
|
const c = r.getCell(1);
|
||||||
@@ -827,4 +716,6 @@ export async function exportDashboardExcel<T extends Record<string, any>>(opts:
|
|||||||
a.download = fileName;
|
a.download = fileName;
|
||||||
a.click();
|
a.click();
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import type {StatisticsRequest} from "@/types/lg.types";
|
||||||
import type { StatisticsRequest, ProductResponse, BannerResponse } from "@/types/lg";
|
|
||||||
import {fetchBannerStatistics, fetchProductStatistics} from "@/lib/lg-dashboard";
|
|
||||||
|
|
||||||
const sortRecord = <T,>(obj?: Record<string, T> | null): Record<string, T> => {
|
const sortRecord = <T,>(obj?: Record<string, T> | null): Record<string, T> => {
|
||||||
if (!obj) return {};
|
if (!obj) return {};
|
||||||
@@ -20,7 +18,6 @@ const sortNumberArrayRecord = (obj?: Record<string, number[]> | null): Record<st
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// queryKey에 넣을 “안정적인 req”
|
|
||||||
const normalizeReqForKey = (req: StatisticsRequest) => ({
|
const normalizeReqForKey = (req: StatisticsRequest) => ({
|
||||||
variableIdMap: sortRecord(req.variableIdMap),
|
variableIdMap: sortRecord(req.variableIdMap),
|
||||||
bannerIdList: [...(req.bannerIdList ?? [])].sort(),
|
bannerIdList: [...(req.bannerIdList ?? [])].sort(),
|
||||||
@@ -33,27 +30,3 @@ export const productStatisticsKey = (req: StatisticsRequest) =>
|
|||||||
|
|
||||||
export const bannerStatisticsKey = (req: StatisticsRequest) =>
|
export const bannerStatisticsKey = (req: StatisticsRequest) =>
|
||||||
["statistics", "banner", normalizeReqForKey(req)] as const;
|
["statistics", "banner", normalizeReqForKey(req)] as const;
|
||||||
|
|
||||||
export function useProductStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
|
||||||
return useQuery<ProductResponse>({
|
|
||||||
queryKey: productStatisticsKey(req),
|
|
||||||
queryFn: () => fetchProductStatistics(req),
|
|
||||||
enabled,
|
|
||||||
staleTime: 60_000,
|
|
||||||
gcTime: 10 * 60_000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useBannerStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
|
||||||
return useQuery<BannerResponse>({
|
|
||||||
queryKey: bannerStatisticsKey(req),
|
|
||||||
queryFn: () => fetchBannerStatistics(req),
|
|
||||||
enabled,
|
|
||||||
/*
|
|
||||||
refetchOnMount: "always",
|
|
||||||
staleTime: 0,
|
|
||||||
*/
|
|
||||||
staleTime: 60_000,
|
|
||||||
gcTime: 10 * 60_000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
28
src/query/statistics.ts
Normal file
28
src/query/statistics.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import {BannerResponse, ProductResponse, StatisticsRequest} from "@/types/lg.types";
|
||||||
|
import {useQuery} from "@tanstack/react-query";
|
||||||
|
import {bannerStatisticsKey, productStatisticsKey} from "@/query/keys";
|
||||||
|
import {fetchBannerStatistics, fetchProductStatistics} from "@/lib/lg-dashboard";
|
||||||
|
|
||||||
|
export function useProductStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||||
|
return useQuery<ProductResponse>({
|
||||||
|
queryKey: productStatisticsKey(req),
|
||||||
|
queryFn: () => fetchProductStatistics(req),
|
||||||
|
enabled,
|
||||||
|
staleTime: 60_000,
|
||||||
|
gcTime: 10 * 60_000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useBannerStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||||
|
return useQuery<BannerResponse>({
|
||||||
|
queryKey: bannerStatisticsKey(req),
|
||||||
|
queryFn: () => fetchBannerStatistics(req),
|
||||||
|
enabled,
|
||||||
|
/*
|
||||||
|
refetchOnMount: "always",
|
||||||
|
staleTime: 0,
|
||||||
|
*/
|
||||||
|
staleTime: 60_000,
|
||||||
|
gcTime: 10 * 60_000,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -3,6 +3,11 @@ export type LoginRequest = {
|
|||||||
userPw: string;
|
userPw: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LoginResponse = {
|
||||||
|
accessToken: string;
|
||||||
|
user: LoginUser;
|
||||||
|
};
|
||||||
|
|
||||||
export type LoginUser = {
|
export type LoginUser = {
|
||||||
userId: string;
|
userId: string;
|
||||||
userName: string;
|
userName: string;
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ export type PageResponse<T> = {
|
|||||||
empty: boolean;
|
empty: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SelectedMap = Record<string, string>;
|
export type SelectedMap = Record<string, string[]>;
|
||||||
@@ -3,9 +3,12 @@ export type FilterChild = {
|
|||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TotalFilterItem = {
|
export type FilterItem = {
|
||||||
variable: string;
|
variable: string;
|
||||||
variableName: string;
|
variableName: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TotalFilterItem = FilterItem & {
|
||||||
children: FilterChild[];
|
children: FilterChild[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -17,6 +20,7 @@ export enum CategoryTargetType {
|
|||||||
|
|
||||||
export enum CategoryTargetData {
|
export enum CategoryTargetData {
|
||||||
PROFILE = 11,
|
PROFILE = 11,
|
||||||
|
PROFILE_ALL = 10,
|
||||||
PENETRATION_CHANGE = 21,
|
PENETRATION_CHANGE = 21,
|
||||||
BRAND = 12,
|
BRAND = 12,
|
||||||
TYPE_SPEC = 13,
|
TYPE_SPEC = 13,
|
||||||
@@ -38,4 +42,4 @@ export type TargetChild = {
|
|||||||
export type CategoryTargetItem = {
|
export type CategoryTargetItem = {
|
||||||
type: CategoryTargetType[];
|
type: CategoryTargetType[];
|
||||||
children: TargetChild[];
|
children: TargetChild[];
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
import {BANNER_GROUP, BANNER_KEY_MAP, PRODUCT_KEY_MAP, PRODUCTS_FILTER_ITEM} from "@/const/lgConst";
|
import {BANNER_GROUP} from "@/const/lg-banner.const";
|
||||||
import {CategoryTargetType} from "@/config/filter.types";
|
import {BANNER_KEY_MAP, PRODUCT_KEY_MAP} from "@/const/lg-schema.const";
|
||||||
|
import {PRODUCTS_FILTER_ITEM} from "@/const/lg-product.const";
|
||||||
|
import {CategoryTargetType} from "@/types/filter.types";
|
||||||
|
import {EChartsOption} from "echarts";
|
||||||
|
|
||||||
export type ProductKey = keyof typeof PRODUCT_KEY_MAP;
|
export type ProductKey = keyof typeof PRODUCT_KEY_MAP;
|
||||||
export type BannerKey = keyof typeof BANNER_KEY_MAP;
|
export type BannerKey = keyof typeof BANNER_KEY_MAP;
|
||||||
@@ -12,7 +15,7 @@ export type BaseRow = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// { year, rowLabel, total, ...category }
|
// { year, rowLabel, total, ...category }
|
||||||
export type ProductRow = BaseRow & Partial<Record<ProductKey, string>>;
|
export type ProductRow = BaseRow & Partial<{sample: string;}> & Partial<Record<ProductKey, string>>;
|
||||||
|
|
||||||
// { year, rowLabel, total, ...banner }
|
// { year, rowLabel, total, ...banner }
|
||||||
// (배너는 기본 41개 키 + 차트별 추가 키가 생길 수 있으니 확장 허용)
|
// (배너는 기본 41개 키 + 차트별 추가 키가 생길 수 있으니 확장 허용)
|
||||||
@@ -63,6 +66,8 @@ export type LifeStageRow = Record<string, unknown> & {
|
|||||||
"KLIFEstAGE#4": string;
|
"KLIFEstAGE#4": string;
|
||||||
"KLIFEstAGE#5": string;
|
"KLIFEstAGE#5": string;
|
||||||
"KLIFEstAGE#6": string;
|
"KLIFEstAGE#6": string;
|
||||||
|
"KLIFEstAGE#7": string;
|
||||||
|
"KLIFEstAGE#8": string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LifeStageGroup = {
|
export type LifeStageGroup = {
|
||||||
@@ -76,16 +81,23 @@ export type CategoryChartMode = "none" | "stack" | "reverseStack" | "horizontal"
|
|||||||
|
|
||||||
export type PageData<T> = {
|
export type PageData<T> = {
|
||||||
title: string;
|
title: string;
|
||||||
|
surveyTitle: string;
|
||||||
chartMode: CategoryChartMode;
|
chartMode: CategoryChartMode;
|
||||||
data: T[];
|
chartLegend?: LegendOption;
|
||||||
|
chartTopMargin?:number;
|
||||||
chartHeight?: number | string;
|
chartHeight?: number | string;
|
||||||
chartWidth?: number;
|
chartWidth?: number;
|
||||||
|
data: T[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LegendOption = EChartsOption["legend"];
|
||||||
|
|
||||||
export type CategoryFieldSpec = {
|
export type CategoryFieldSpec = {
|
||||||
title: string | Record<CategoryTargetType, string>;
|
title: string | Record<CategoryTargetType, string>;
|
||||||
requestKey: string;
|
requestKey: string;
|
||||||
chartMode:CategoryChartMode;
|
chartMode:CategoryChartMode;
|
||||||
|
chartLegend?: LegendOption;
|
||||||
|
chartTopMargin?:number;
|
||||||
qidByMode: Partial<Record<CategoryTargetType, string>>; // mode별 qid (없으면 숨김/요청 제외)
|
qidByMode: Partial<Record<CategoryTargetType, string>>; // mode별 qid (없으면 숨김/요청 제외)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -97,4 +109,4 @@ export type CategoryResolvedField = CategoryFieldSpec & {
|
|||||||
export type BuildPageModeConfigResult = {
|
export type BuildPageModeConfigResult = {
|
||||||
fields: CategoryResolvedField[];
|
fields: CategoryResolvedField[];
|
||||||
variableIdMap: Record<string, string>;
|
variableIdMap: Record<string, string>;
|
||||||
};
|
};
|
||||||
@@ -10,4 +10,4 @@ export type SubMenuItem = {
|
|||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
path: string;
|
path: string;
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user