From 4c3db97ae6ad9180576a8036e51673027e8a27d2 Mon Sep 17 00:00:00 2001 From: mawsyh Date: Mon, 24 Apr 2023 11:36:49 +0330 Subject: [PATCH 1/2] overlay create and removal api --- src/ChartProComponent.tsx | 2 ++ src/KLineChartPro.tsx | 9 ++++++++- src/types.ts | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ChartProComponent.tsx b/src/ChartProComponent.tsx index 37d4d176..7b99e834 100644 --- a/src/ChartProComponent.tsx +++ b/src/ChartProComponent.tsx @@ -102,6 +102,8 @@ const ChartProComponent: Component = props => { }) props.ref({ + createOverlay: (value: any) => widget!.createOverlay(value), + removeOverlay: (value) => widget!.removeOverlay(value), setTheme, getTheme: () => theme(), setStyles, diff --git a/src/KLineChartPro.tsx b/src/KLineChartPro.tsx index 8f5722dd..94b71d32 100644 --- a/src/KLineChartPro.tsx +++ b/src/KLineChartPro.tsx @@ -14,7 +14,7 @@ import { render } from 'solid-js/web' -import { utils, Nullable, DeepPartial, Styles } from 'klinecharts' +import { utils, Nullable, DeepPartial, Styles, OverlayRemove } from 'klinecharts' import ChartProComponent from './ChartProComponent' @@ -83,6 +83,13 @@ export default class KLineChartPro implements ChartPro { private _chartApi: Nullable = null + createOverlay (value: any): void { + return this._chartApi!.createOverlay(value) + } + + removeOverlay (value?: string | OverlayRemove): void { + return this._chartApi!.removeOverlay(value) + } setTheme (theme: string): void { this._container?.setAttribute('data-theme', theme) diff --git a/src/types.ts b/src/types.ts index 8f1b97c9..1a246b25 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, OverlayRemove } from 'klinecharts' export interface SymbolInfo { ticker: string @@ -66,6 +66,8 @@ export interface ChartPro { setLocale(locale: string): void getLocale(): string setTimezone(timezone: string): void + createOverlay (value: any, paneId?: string): any + removeOverlay: (remove?: string | OverlayRemove) => void getTimezone(): string setSymbol(symbol: SymbolInfo): void getSymbol(): SymbolInfo From ffe20af2c99c039dbb971703dc64e49a4f2515de Mon Sep 17 00:00:00 2001 From: mawsyh Date: Mon, 24 Apr 2023 18:45:35 +0330 Subject: [PATCH 2/2] added registerOverlay as well --- src/ChartProComponent.tsx | 3 ++- src/KLineChartPro.tsx | 6 +++++- src/types.ts | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ChartProComponent.tsx b/src/ChartProComponent.tsx index 7b99e834..45f9d204 100644 --- a/src/ChartProComponent.tsx +++ b/src/ChartProComponent.tsx @@ -16,7 +16,7 @@ import { createSignal, createEffect, onMount, Show, onCleanup, startTransition, import { init, dispose, utils, Nullable, Chart, OverlayMode, Styles, - TooltipIconPosition, ActionType, PaneOptions, Indicator, DomPosition, FormatDateType, DeepPartial + TooltipIconPosition, ActionType, PaneOptions, Indicator, DomPosition, FormatDateType, DeepPartial, registerOverlay } from 'klinecharts' import lodashSet from 'lodash/set' @@ -104,6 +104,7 @@ const ChartProComponent: Component = props => { props.ref({ createOverlay: (value: any) => widget!.createOverlay(value), removeOverlay: (value) => widget!.removeOverlay(value), + registerOverlay: (value) => registerOverlay(value), setTheme, getTheme: () => theme(), setStyles, diff --git a/src/KLineChartPro.tsx b/src/KLineChartPro.tsx index 94b71d32..0b1bdf2f 100644 --- a/src/KLineChartPro.tsx +++ b/src/KLineChartPro.tsx @@ -14,7 +14,7 @@ import { render } from 'solid-js/web' -import { utils, Nullable, DeepPartial, Styles, OverlayRemove } from 'klinecharts' +import { utils, Nullable, DeepPartial, Styles, OverlayRemove, OverlayTemplate } from 'klinecharts' import ChartProComponent from './ChartProComponent' @@ -91,6 +91,10 @@ export default class KLineChartPro implements ChartPro { return this._chartApi!.removeOverlay(value) } + registerOverlay (template: OverlayTemplate): void { + return this._chartApi!.registerOverlay(template) + } + setTheme (theme: string): void { this._container?.setAttribute('data-theme', theme) this._chartApi!.setTheme(theme) diff --git a/src/types.ts b/src/types.ts index 1a246b25..0300892a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,7 @@ * limitations under the License. */ -import { KLineData, Styles, DeepPartial, OverlayRemove } from 'klinecharts' +import { KLineData, Styles, DeepPartial, OverlayRemove, OverlayTemplate } from 'klinecharts' export interface SymbolInfo { ticker: string @@ -68,6 +68,7 @@ export interface ChartPro { setTimezone(timezone: string): void createOverlay (value: any, paneId?: string): any removeOverlay: (remove?: string | OverlayRemove) => void + registerOverlay(template: OverlayTemplate): void getTimezone(): string setSymbol(symbol: SymbolInfo): void getSymbol(): SymbolInfo