From 91d9b963cdc0ab8c72402ab5d6a0da8cd5d836ee Mon Sep 17 00:00:00 2001 From: Haseeb-Afandi Date: Fri, 10 Oct 2025 16:54:26 +0500 Subject: [PATCH 1/3] export applyNewData as updateData --- src/ChartProComponent.tsx | 52 +++++++++++++++++++++------------------ src/KLineChartPro.tsx | 4 +++ src/types.ts | 1 + vite.config.ts | 16 ++++++++++++ 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/ChartProComponent.tsx b/src/ChartProComponent.tsx index 47696350..671afdc3 100644 --- a/src/ChartProComponent.tsx +++ b/src/ChartProComponent.tsx @@ -42,7 +42,7 @@ interface PrevSymbolPeriod { period: Period } -function createIndicator (widget: Nullable, indicatorName: string, isStack?: boolean, paneOptions?: PaneOptions): Nullable { +function createIndicator(widget: Nullable, indicatorName: string, isStack?: boolean, paneOptions?: PaneOptions): Nullable { if (indicatorName === 'VOL') { paneOptions = { gap: { bottom: 2 }, ...paneOptions } } @@ -101,21 +101,6 @@ const ChartProComponent: Component = props => { visible: false, indicatorName: '', paneId: '', calcParams: [] as Array }) - props.ref({ - setTheme, - getTheme: () => theme(), - setStyles, - getStyles: () => widget!.getStyles(), - setLocale, - getLocale: () => locale(), - setTimezone: (timezone: string) => { setTimezone({ key: timezone, text: translateTimezone(props.timezone, locale()) }) }, - getTimezone: () => timezone().key, - setSymbol, - getSymbol: () => symbol(), - setPeriod, - getPeriod: () => period() - }) - const documentResize = () => { widget?.resize() } @@ -211,6 +196,25 @@ const ChartProComponent: Component = props => { } }) + props.ref({ + setTheme, + getTheme: () => theme(), + setStyles, + getStyles: () => widget!.getStyles(), + setLocale, + getLocale: () => locale(), + setTimezone: (timezone: string) => { setTimezone({ key: timezone, text: translateTimezone(props.timezone, locale()) }) }, + getTimezone: () => timezone().key, + setSymbol, + getSymbol: () => symbol(), + setPeriod, + getPeriod: () => period(), + updateData: (data: any) => { + console.log(widget); + widget!.applyNewData(data); + } + }) + if (widget) { const watermarkContainer = widget.getDom('candle_pane', DomPosition.Main) if (watermarkContainer) { @@ -440,13 +444,13 @@ const ChartProComponent: Component = props => { return ( <> - + { setSymbol(symbol) }} - onClose={() => { setSymbolSearchModalVisible(false) }}/> + onClose={() => { setSymbolSearchModalVisible(false) }} /> = props => { } } setSubIndicators(newSubIndicators) - }}/> + }} /> = props => { locale={props.locale} params={indicatorSettingModalParams()} onClose={() => { setIndicatorSettingModalParams({ visible: false, indicatorName: '', paneId: '', calcParams: [] }) }} - onConfirm={(params)=> { + onConfirm={(params) => { const modalParams = indicatorSettingModalParams() widget?.overrideIndicator({ name: modalParams.indicatorName, calcParams: params }, modalParams.paneId) }} @@ -537,7 +541,7 @@ const ChartProComponent: Component = props => { try { await startTransition(() => setDrawingBarVisible(!drawingBarVisible())) widget?.resize() - } catch (e) {} + } catch (e) { } }} onSymbolClick={() => { setSymbolSearchModalVisible(!symbolSearchModalVisible()) }} onPeriodChange={setPeriod} @@ -554,7 +558,7 @@ const ChartProComponent: Component = props => {
- + = props => { onModeChange={mode => { widget?.overrideOverlay({ mode: mode as OverlayMode }) }} onLockChange={lock => { widget?.overrideOverlay({ lock }) }} onVisibleChange={visible => { widget?.overrideOverlay({ visible }) }} - onRemoveClick={(groupId) => { widget?.removeOverlay({ groupId }) }}/> + onRemoveClick={(groupId) => { widget?.removeOverlay({ groupId }) }} />
+ data-drawing-bar-visible={drawingBarVisible()} />
) diff --git a/src/KLineChartPro.tsx b/src/KLineChartPro.tsx index bac9e893..7b1acf09 100644 --- a/src/KLineChartPro.tsx +++ b/src/KLineChartPro.tsx @@ -128,4 +128,8 @@ export default class KLineChartPro implements ChartPro { getPeriod (): Period { return this._chartApi!.getPeriod() } + + updateData (data: any): void { + this._chartApi!.updateData(data); + } } diff --git a/src/types.ts b/src/types.ts index 8f1b97c9..8b302c92 100644 --- a/src/types.ts +++ b/src/types.ts @@ -71,4 +71,5 @@ export interface ChartPro { getSymbol(): SymbolInfo setPeriod(period: Period): void getPeriod(): Period + updateData(data : any): void } diff --git a/vite.config.ts b/vite.config.ts index 5e9176ec..65d78afa 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,9 +2,25 @@ import { defineConfig } from 'vite' import solidPlugin from 'vite-plugin-solid' +import path from "path" + export default defineConfig({ plugins: [solidPlugin()], + resolve: { + alias: { + "@klinecharts/pro": path.resolve(__dirname, "../pro/src"), + }, + }, + optimizeDeps: { + exclude: ["@klinecharts/pro"], // important — prevent prebundling + }, + server: { + fs: { + // allow vite to serve files outside project root + allow: [".."], + }, + }, build: { cssTarget: 'chrome61', sourcemap: true, From 5928b2fd4ba89c9cd086992e83bd1cf0c1ec7d5e Mon Sep 17 00:00:00 2001 From: Haseeb-Afandi Date: Mon, 13 Oct 2025 16:14:12 +0500 Subject: [PATCH 2/3] export name changed from updateData to applyNewData --- src/ChartProComponent.tsx | 2 +- src/KLineChartPro.tsx | 4 ++-- src/types.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ChartProComponent.tsx b/src/ChartProComponent.tsx index 671afdc3..411ff546 100644 --- a/src/ChartProComponent.tsx +++ b/src/ChartProComponent.tsx @@ -209,7 +209,7 @@ const ChartProComponent: Component = props => { getSymbol: () => symbol(), setPeriod, getPeriod: () => period(), - updateData: (data: any) => { + applyNewData: (data: any) => { console.log(widget); widget!.applyNewData(data); } diff --git a/src/KLineChartPro.tsx b/src/KLineChartPro.tsx index 7b1acf09..968d4289 100644 --- a/src/KLineChartPro.tsx +++ b/src/KLineChartPro.tsx @@ -129,7 +129,7 @@ export default class KLineChartPro implements ChartPro { return this._chartApi!.getPeriod() } - updateData (data: any): void { - this._chartApi!.updateData(data); + applyNewData (data: any): void { + this._chartApi!.applyNewData(data); } } diff --git a/src/types.ts b/src/types.ts index 8b302c92..3c2d6022 100644 --- a/src/types.ts +++ b/src/types.ts @@ -71,5 +71,5 @@ export interface ChartPro { getSymbol(): SymbolInfo setPeriod(period: Period): void getPeriod(): Period - updateData(data : any): void + applyNewData(data : any): void } From 9ae9fb04614a14d91c48ba1f1472694010def523 Mon Sep 17 00:00:00 2001 From: Haseeb-Afandi Date: Mon, 13 Oct 2025 18:36:59 +0500 Subject: [PATCH 3/3] added KLineChart export --- package.json | 2 +- src/ChartProComponent.tsx | 3 +++ src/KLineChartPro.tsx | 4 ++++ src/types.ts | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 71098f39..dadb300b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@klinecharts/pro", + "name": "@hasee_hive/klinecharts-pro", "version": "0.1.1", "description": "Financial chart built out of the box based on KLineChart.", "type": "module", diff --git a/src/ChartProComponent.tsx b/src/ChartProComponent.tsx index 411ff546..3ed08752 100644 --- a/src/ChartProComponent.tsx +++ b/src/ChartProComponent.tsx @@ -212,6 +212,9 @@ const ChartProComponent: Component = props => { applyNewData: (data: any) => { console.log(widget); widget!.applyNewData(data); + }, + getKLineChartWidget: () => { + return widget; } }) diff --git a/src/KLineChartPro.tsx b/src/KLineChartPro.tsx index 968d4289..22198243 100644 --- a/src/KLineChartPro.tsx +++ b/src/KLineChartPro.tsx @@ -132,4 +132,8 @@ export default class KLineChartPro implements ChartPro { applyNewData (data: any): void { this._chartApi!.applyNewData(data); } + + getKLineChartWidget () { + return this._chartApi!.getKLineChartWidget(); + } } diff --git a/src/types.ts b/src/types.ts index 3c2d6022..b73e434d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,7 @@ * limitations under the License. */ -import { KLineData, Styles, DeepPartial } from 'klinecharts' +import { KLineData, Styles, DeepPartial, Chart, Nullable } from 'klinecharts' export interface SymbolInfo { ticker: string @@ -72,4 +72,5 @@ export interface ChartPro { setPeriod(period: Period): void getPeriod(): Period applyNewData(data : any): void + getKLineChartWidget(): Nullable }