[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,101 +2,253 @@
|
||||
id: wiki-2026-0508-실시간-데이터-대시보드-레이아웃-조절-시스템
|
||||
title: 실시간 데이터 대시보드 레이아웃 조절 시스템
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-BAC69B]
|
||||
aliases: [Real-time Dashboard Layout, Drag-and-drop Grid, Resizable Widget System, react-grid-layout]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
confidence_score: 0.86
|
||||
verification_status: applied
|
||||
tags: [frontend, dashboard, layout, drag-drop, grid, real-time, websocket]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - 실시간 데이터 대시보드 레이아웃 조절 시스템"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: TypeScript
|
||||
framework: React 19, react-grid-layout, dnd-kit, CSS Grid, WebSocket, SSE
|
||||
---
|
||||
|
||||
# [[실시간 데이터 대시보드 레이아웃 조절 시스템|실시간 데이터 대시보드 레이아웃 조절 시스템]]
|
||||
# 실시간 데이터 대시보드 레이아웃 조절 시스템
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> 실시간으로 쏟아지는 대규모 데이터를 시각화하는 대시보드 환경에서, 사용자의 레이아웃 변경(위젯 크기 조절, 드래그 등)과 잦은 데이터 업데이트가 충돌하여 UI가 멈추거나 버벅거리는 현상을 방지하는 고성능 렌더링 및 상태 제어 시스템입니다.
|
||||
## 매 한 줄
|
||||
> **"매 user-customizable dashboard — 매 widget 의 drag/resize/persist + 매 real-time data update — 매 layout state machine + 매 streaming connection (WS/SSE) + 매 efficient re-render strategy 의 결합"**. 매 2026 의 modern stack: react-grid-layout / dnd-kit, Server-Sent Events / WebSocket, virtualization, CSS Grid + container queries, IndexedDB persist.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
**1. 리사이즈 및 레이아웃 이벤트 제어 (Debouncing & Throttling)** 대시보드의 위젯 크기 조절이나 윈도우 창 변경 시에는 아주 짧은 시간에 수많은 레이아웃 연산 이벤트가 발생합니다. 브라우저 과부하와 UI 병목 현상을 막기 위해, `lodash`의 **디바운스(Debounce)나 스로틀(Throttle) 기법을 적용하여 무거운 연산이나 리렌더링이 연속적으로 실행되는 것을 제어**해야 합니다.
|
||||
## 매 핵심
|
||||
|
||||
**2. 고빈도 업데이트를 위한 상태 관리 최적화** 실시간 대시보드는 차트나 데이터 그리드가 초당 수십 번씩 업데이트될 수 있습니다. 이때 React의 기본 [[Context API|Context API]]를 전역 상태처럼 사용하면, 내부 값 하나만 변경되어도 이를 구독하는 모든 위젯과 컴포넌트가 리렌더링되는 심각한 폭포수(Cascading) 현상이 발생합니다. 이를 방지하려면 **컨텍스트를 도메인별로 잘게 분리하거나 `useContextSelector`를 도입**하고, 세밀한 단위의(Granular) 업데이트에 최적화된 **Zustand, Jotai, Valtio 같은 전용 상태 관리 라이브러리를 사용**해야 합니다.
|
||||
### 매 Layout 의 3 element
|
||||
- **Position** — column, row, x, y.
|
||||
- **Size** — width, height (in grid units or px).
|
||||
- **Constraint** — min/max width/height, lockable, draggable flag.
|
||||
|
||||
**3. 무거운 위젯의 지연 로딩(Lazy Loading)과 가상화(Virtualization)**
|
||||
### 매 Layout System 의 categories
|
||||
- **CSS Grid based** — declarative, 매 free-form 의 X.
|
||||
- **Coordinate based** (react-grid-layout) — 매 free, 매 collision 의 handle.
|
||||
- **Mosaic / split-pane** (golden-layout) — 매 nested split, 매 complete coverage.
|
||||
- **Free canvas** (Excalidraw, tldraw) — 매 absolute, 매 무한.
|
||||
|
||||
- **지연 로딩:** 초기 로딩 속도를 높이기 위해, 당장 화면에 보이지 않거나 무거운 대시보드 위젯(예: 차트 위젯)은 `React.lazy`와 `<Suspense>`를 활용해 온디맨드 방식으로 동적 로드해야 합니다.
|
||||
- **리스트 가상화:** 대규모 로그나 데이터 테이블을 렌더링할 때는 수천 개의 DOM 노드가 생성되어 메모리를 낭비하지 않도록, `react-window`나 `react-virtualized`를 사용하여 **현재 화면(Viewport)에 노출되는 항목만 렌더링**하는 가상화 기법을 적용해야 합니다.
|
||||
### 매 Real-time Data 의 channels
|
||||
- **WebSocket** — bidirectional, 매 high-frequency.
|
||||
- **Server-Sent Events** — server→client, 매 simple.
|
||||
- **HTTP/2 + Streaming JSON** — 매 partial response.
|
||||
- **WebTransport** (2026) — UDP-based, 매 unreliable streams.
|
||||
- **WebRTC DataChannel** — 매 P2P, 매 low-latency.
|
||||
|
||||
**4. 동시성(Concurrent) 기능을 통한 UI 반응성 확보** 무거운 차트를 렌더링하거나 대규모 데이터를 필터링할 때 사용자의 클릭이나 타이핑이 버벅거리지 않도록, [[React 18|React 18]]의 동시성 훅을 적극 활용합니다. **`useTransition`을 사용하여 무거운 필터링이나 뷰 업데이트를 비긴급 작업으로 미루고**, **`[[useDeferredValue|useDeferredValue]]`를 사용해 파생 데이터의 계산을 지연시켜 메인 스레드의 과부하 시에도 UI 입력 반응성을 부드럽게 유지**합니다.
|
||||
### 매 Render Strategy
|
||||
- **Memoization** — `React.memo`, 매 widget 별 의 isolation.
|
||||
- **Selector pattern** — Zustand/Redux selector, 매 specific slice subscribe.
|
||||
- **Virtualization** — 매 viewport 안 의 widget 만 의 render.
|
||||
- **Web Worker** — 매 computation off main thread.
|
||||
|
||||
**5. 웹 워커(Web Worker)를 이용한 연산 오프로딩** 대용량 JSON 파싱, 복잡한 데이터 정렬이나 물리 연산과 같이 CPU 집약적인 작업은 자바스크립트의 메인 스레드를 차단합니다. 이러한 작업은 **Web Worker나 `useWorker` 훅을 활용하여 백그라운드 스레드로 넘김(Offloading)으로써, 무거운 데이터 처리 중에도 대시보드가 60FPS의 매끄러운 반응성을 유지**할 수 있도록 설계해야 합니다.
|
||||
## 💻 패턴
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Design & Experience 분야의 자동 자산화 수행.
|
||||
### Pattern 1: react-grid-layout (drag/resize)
|
||||
```tsx
|
||||
import GridLayout from 'react-grid-layout';
|
||||
import 'react-grid-layout/css/styles.css';
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** Throttling & Debouncing, [[React 동시성 훅 (useTransition, useDeferredValue)|React 동시성 훅 (useTransition, useDeferredValue]], 상태 관리 최적화 (Zustand, Jotai, Valtio), Virtualization (리스트 가상화), [[Web Worker (웹 워커)|Web Worker (웹 워커]]
|
||||
- **Projects/Contexts:** 대용량 데이터 분석 플랫폼 및 모니터링 시스템, 고성능 금융/주식 실시간 거래 대시보드
|
||||
- **Contradictions/Notes:** React에 내장된 Context API는 테마나 로그인 정보처럼 가끔 변하는 데이터에는 훌륭하지만, 고빈도로 상태가 업데이트되는 실시간 대시보드에서는 성능을 조용히 갉아먹는 주범이 되므로 대안 상태 관리 도구가 필수적입니다.
|
||||
const layout = [
|
||||
{ i: 'sales', x: 0, y: 0, w: 6, h: 4 },
|
||||
{ i: 'orders', x: 6, y: 0, w: 6, h: 4 },
|
||||
{ i: 'users', x: 0, y: 4, w: 12, h: 3 },
|
||||
];
|
||||
|
||||
---
|
||||
|
||||
_Last updated: 2026-04-15_
|
||||
|
||||
---
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
<GridLayout
|
||||
className="layout"
|
||||
layout={layout}
|
||||
cols={12}
|
||||
rowHeight={50}
|
||||
width={1200}
|
||||
isDraggable
|
||||
isResizable
|
||||
onLayoutChange={(newLayout) => persist(newLayout)}
|
||||
>
|
||||
<div key="sales"><SalesWidget /></div>
|
||||
<div key="orders"><OrdersWidget /></div>
|
||||
<div key="users"><UsersWidget /></div>
|
||||
</GridLayout>
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Pattern 2: dnd-kit + CSS Grid (modern)
|
||||
```tsx
|
||||
import { DndContext, useDraggable, useDroppable } from '@dnd-kit/core';
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
function Widget({ id }: { id: string }) {
|
||||
const { attributes, listeners, setNodeRef, transform } = useDraggable({ id });
|
||||
return (
|
||||
<div
|
||||
ref={setNodeRef}
|
||||
style={{ transform: transform ? `translate3d(${transform.x}px, ${transform.y}px, 0)` : undefined }}
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
>
|
||||
...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Pattern 3: WebSocket data subscription
|
||||
```ts
|
||||
import { useEffect } from 'react';
|
||||
import { useStore } from './store';
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
export function useRealtimeMetric(channel: string) {
|
||||
const update = useStore(s => s.updateMetric);
|
||||
useEffect(() => {
|
||||
const ws = new WebSocket(`wss://api/stream?channel=${channel}`);
|
||||
ws.onmessage = (e) => {
|
||||
const { metric, value } = JSON.parse(e.data);
|
||||
update(channel, metric, value);
|
||||
};
|
||||
return () => ws.close();
|
||||
}, [channel, update]);
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Pattern 4: Zustand selector + memoization
|
||||
```ts
|
||||
import { create } from 'zustand';
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
type State = { metrics: Record<string, number> };
|
||||
const useStore = create<State>(() => ({ metrics: {} }));
|
||||
|
||||
function SalesWidget() {
|
||||
const sales = useStore(s => s.metrics.sales); // 매 sales 의 변화 만 의 re-render
|
||||
return <div>Sales: {sales}</div>;
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 5: SSE (one-way streaming)
|
||||
```ts
|
||||
const es = new EventSource('/api/dashboard/stream');
|
||||
es.addEventListener('metric', (e) => {
|
||||
const data = JSON.parse(e.data);
|
||||
store.update(data);
|
||||
});
|
||||
es.addEventListener('error', () => {
|
||||
/* 매 EventSource 의 자동 reconnect */
|
||||
});
|
||||
```
|
||||
|
||||
### Pattern 6: Layout persist (IndexedDB)
|
||||
```ts
|
||||
import { openDB } from 'idb';
|
||||
|
||||
const dbPromise = openDB('dashboard', 1, {
|
||||
upgrade(db) { db.createObjectStore('layouts'); }
|
||||
});
|
||||
|
||||
export async function saveLayout(userId: string, layout: any) {
|
||||
const db = await dbPromise;
|
||||
await db.put('layouts', layout, userId);
|
||||
}
|
||||
|
||||
export async function loadLayout(userId: string) {
|
||||
const db = await dbPromise;
|
||||
return await db.get('layouts', userId);
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 7: Virtualized widget list
|
||||
```tsx
|
||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
|
||||
function WidgetList({ widgets }: { widgets: Widget[] }) {
|
||||
const parentRef = useRef<HTMLDivElement>(null);
|
||||
const v = useVirtualizer({
|
||||
count: widgets.length,
|
||||
getScrollElement: () => parentRef.current,
|
||||
estimateSize: () => 200,
|
||||
});
|
||||
|
||||
return (
|
||||
<div ref={parentRef} style={{ height: '100vh', overflow: 'auto' }}>
|
||||
<div style={{ height: v.getTotalSize(), position: 'relative' }}>
|
||||
{v.getVirtualItems().map(item => (
|
||||
<div
|
||||
key={item.key}
|
||||
style={{ position: 'absolute', top: 0, transform: `translateY(${item.start}px)` }}
|
||||
>
|
||||
<WidgetRenderer widget={widgets[item.index]} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 8: Container queries 의 widget responsive
|
||||
```css
|
||||
.widget {
|
||||
container-type: inline-size;
|
||||
container-name: widget;
|
||||
}
|
||||
|
||||
@container widget (min-width: 400px) {
|
||||
.chart { display: grid; grid-template-columns: 2fr 1fr; }
|
||||
}
|
||||
@container widget (max-width: 200px) {
|
||||
.chart-detail { display: none; } /* 매 small widget 의 simplify */
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 9: Throttled chart update
|
||||
```ts
|
||||
import { throttle } from 'lodash-es';
|
||||
|
||||
const updateChart = throttle((data) => {
|
||||
chart.setOption({ series: [{ data }] });
|
||||
}, 100); // 매 100ms 의 max — 매 60fps 보다 매 throttle
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Free-form drag/resize | react-grid-layout |
|
||||
| Modern composable | dnd-kit + CSS Grid |
|
||||
| Nested split panes | golden-layout / react-mosaic |
|
||||
| Real-time tick | WebSocket + Zustand selector |
|
||||
| Server-push only | SSE |
|
||||
| 100+ widgets | Virtualization |
|
||||
| Persist across session | IndexedDB |
|
||||
| Widget responsive | Container queries |
|
||||
|
||||
**기본값**: dnd-kit + CSS Grid + WebSocket + Zustand selector + IndexedDB persist + container queries.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Frontend]] · [[Real-time Data]]
|
||||
- 변형: [[Drag and Drop]] · [[Grid Layout]]
|
||||
- 응용: [[Frontend Performance Optimization (FE 성능 최적화)]] · [[데이터 시각화 (Data Visualization)]]
|
||||
- Adjacent: [[WebSocket]] · [[Server-Sent Events]] · [[IndexedDB]] · [[Zustand]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: layout schema 설계, websocket reconnection 전략 권고, virtualization threshold 의 결정.
|
||||
**언제 X**: 매 specific chart visualization 의 design — 매 D3/ECharts 의 별도 영역.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **모든 widget 의 every tick re-render**: 매 selector 의 사용 X → main thread block.
|
||||
- **Layout 의 매 drag 의 server save**: 매 debounce 의 X.
|
||||
- **Polling 의 1초**: 매 SSE/WebSocket 의 사용.
|
||||
- **Grid library 의 unbounded widget count**: 매 virtualization 의 X.
|
||||
- **Layout state 의 React state 의 single global**: 매 매 widget 의 매 layout change 의 re-render.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (react-grid-layout docs, dnd-kit docs, Zustand docs, MDN WebSocket/EventSource 2026).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — grid systems, real-time channels, virtualization, persist patterns |
|
||||
|
||||
Reference in New Issue
Block a user