콘텐츠로 이동

프레임워크 바인딩

Lumen Ticks의 프레임워크 바인딩은 의도적으로 얇게 유지됩니다. 마운트 시 차트를 생성하고, 옵션 변경을 applyOptions로 전달하며, 언마운트 시 destroy()를 호출합니다.

시세 데이터는 props가 아니라 항상 ChartApi를 통해 전달합니다. 수백만 개의 바를 프레임워크 반응형 props로 넘기지 않기 때문에 틱마다 불필요한 diff와 할당이 발생하지 않습니다.

아래에서 탭을 선택하면 시작하기와 모든 가이드 문서의 코드 예시도 같은 프레임워크로 동기화됩니다.

theme, grid, crosshair, priceScales, localization 같은 표시 옵션은 래퍼의 options로 넘기고, 시리즈와 시세 데이터는 ChartApi로 제어합니다:

pnpm add @lumen-ticks/core
import { createChart } from '@lumen-ticks/core';
const chart = createChart(document.getElementById('chart')!, { theme: 'dark' });
const candles = chart.addSeries('candlestick', { id: 'BTCUSD' });
candles.setData(bars);
chart.timeScale().fitContent();
// 뷰를 떠날 때 리소스 해제
chart.destroy();

실시간 틱 스트리밍과 인디케이터

섹션 제목: “실시간 틱 스트리밍과 인디케이터”

시리즈 핸들을 프레임워크 상태 밖에 유지하고 수신되는 틱을 candles.update(tick)으로 직접 전달합니다. 시세 틱마다 컴포넌트가 다시 렌더링되지 않으며, 데이터 엔진이 마지막 바와 모든 인디케이터를 한 번의 원자적 패치로 갱신합니다:

import { createChart, type OhlcBar, type OhlcColumns } from '@lumen-ticks/core';
const chart = createChart(document.getElementById('chart')!, { theme: 'auto' });
const candles = chart.addSeries('candlestick', { id: 'BTCUSD' });
candles.setData(history);
candles.addIndicator('ema', { params: { period: 20 } });
chart.timeScale().fitContent();
const stopStream = subscribeTicks('BTCUSD', (tick: OhlcBar) => {
candles.update(tick);
});
// 정리 시
stopStream();
chart.destroy();

crosshairMove, click, error, timeScale().subscribe('visibleTimeRangeChange', ...) 같은 이벤트 구독은 해제 함수를 반환합니다. 이를 프레임워크 상태에 연결해 커스텀 범례, 툴바, 경고 배너를 구성할 수 있습니다:

import { createChart } from '@lumen-ticks/core';
const chart = createChart(document.getElementById('chart')!);
const legend = document.getElementById('legend')!;
const unsubscribe = chart.subscribe('crosshairMove', event => {
const bar = event.values.get('BTCUSD');
legend.textContent =
bar && 'close' in bar ? `O ${bar.open.toFixed(2)} H ${bar.high.toFixed(2)} C ${bar.close.toFixed(2)}` : '';
});
// 필요 없어지면 unsubscribe()를 호출합니다(chart.destroy() 시에도 모든 리스너가 해제됩니다).
패키지 내보내기 Props / 파라미터 ChartApi 접근 수명 주기
@lumen-ticks/core createChart (container, options?) 반환된 ChartApi 수동 destroy()
@lumen-ticks/core createChart (container, options?) 반환된 ChartApi 수동 destroy()
@lumen-ticks/react LumenChart options?, className?, style? ref (ChartApi | null) useEffect 마운트/언마운트 (StrictMode)
@lumen-ticks/vue LumenChart options? (및 fallthrough 속성) 템플릿 ref { chart: ChartApi | null } onMounted / onBeforeUnmount
@lumen-ticks/svelte lumenChart { options?, onReady? } onReady(chart) 콜백 Svelte 액션 update / destroy
@lumen-ticks/solid LumenChart options?, class?, onReady? onReady(chart) 콜백 onMount / onCleanup (클라이언트 전용)

모든 프레임워크 패키지는 ChartApi, ChartOptions, DeepPartial 타입과 워커 구성 헬퍼(configureWorker, createWorkerPool, getWorkerConfig, setMaxWorkers, getMaxWorkers), 그리고 독립 번들된 ./worker 서브패스 엔트리를 함께 re-export합니다. PanePrimitive나 OhlcColumns 같은 하위 타입은 @lumen-ticks/core(또는 lumen-ticks)에서 가져올 수 있습니다.

  • 서버 사이드 렌더링(SSR): 캔버스와 ResizeObserver는 브라우저 환경에서 동작합니다. Next.js App Router에서는 'use client'를 선언하고, Nuxt에서는 <ClientOnly>로 감싸며, SolidStart에서는 컴포넌트 초기화 시 document.createElement('div')를 호출하므로 clientOnly()로 로드하세요. SvelteKit의 액션은 브라우저에서만 실행됩니다.
  • 크기 지정: 차트 컨테이너에 명시적인 CSS 높이를 지정하세요(style={{ height: 420 }}, style="height: 420px", Solid는 높이가 지정된 CSS 클래스). autoSize가 기본 활성화되어 페이지 내 모든 차트가 하나의 ResizeObserver를 공유합니다.