diff --git a/.size-limit.js b/.size-limit.js index 93858aec68..f5c70f02f7 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -8,7 +8,7 @@ export default [ { name: 'ESM', path: 'dist/lightweight-charts.production.mjs', - limit: '44.50 KB', + limit: '45.00 KB', import: '*', ignore: ['fancy-canvas'], brotli: true, @@ -16,7 +16,7 @@ export default [ { name: 'ESM createChart', path: 'dist/lightweight-charts.production.mjs', - limit: '41.30 KB', + limit: '45.00 KB', import: '{ createChart }', ignore: ['fancy-canvas'], brotli: true, @@ -24,7 +24,7 @@ export default [ { name: 'ESM createChartEx', path: 'dist/lightweight-charts.production.mjs', - limit: '40.00 KB', + limit: '45.00 KB', import: '{ createChartEx }', ignore: ['fancy-canvas'], brotli: true, @@ -32,7 +32,7 @@ export default [ { name: 'ESM Standalone', path: 'dist/lightweight-charts.standalone.production.mjs', - limit: '45.90 KB', + limit: '50.00 KB', import: '*', brotli: true, }, @@ -45,7 +45,7 @@ export default [ { name: 'Plugin: Text Watermark', path: 'dist/lightweight-charts.production.mjs', - import: '{ TextWatermark }', + import: '{ createTextWatermark }', ignore: ['fancy-canvas'], limit: '2.00 KB', brotli: true, @@ -53,7 +53,7 @@ export default [ { name: 'Plugin: Image Watermark', path: 'dist/lightweight-charts.production.mjs', - import: '{ ImageWatermark }', + import: '{ createImageWatermark }', ignore: ['fancy-canvas'], limit: '2.00 KB', brotli: true, @@ -61,9 +61,9 @@ export default [ { name: 'Plugin: Series Markers', path: 'dist/lightweight-charts.production.mjs', - import: '{ createSeriesMarkersPrimitive }', + import: '{ createSeriesMarkers }', ignore: ['fancy-canvas'], - limit: '3.90 KB', + limit: '4.08 KB', brotli: true, }, ]; diff --git a/package.json b/package.json index e63f6da591..fa6b1e5ff8 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "tslint-eslint-rules": "~5.4.0", "tslint-microsoft-contrib": "~6.2.0", "tsx": "~4.16.2", - "typescript": "~5.4.5", + "typescript": "~5.5.4", "yargs": "~17.7.2" }, "scripts": { diff --git a/src/index.ts b/src/index.ts index 138ebfbb1a..df8518928a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,9 +24,9 @@ export { createChart, createChartEx, defaultHorzScaleBehavior } from './api/crea /* Plugins */ -export { TextWatermark } from './plugins/text-watermark/primitive'; -export { ImageWatermark } from './plugins/image-watermark/primitive'; -export { createSeriesMarkersPrimitive } from './plugins/series-markers/primitive'; +export { createTextWatermark } from './plugins/text-watermark/primitive'; +export { createImageWatermark } from './plugins/image-watermark/primitive'; +export { createSeriesMarkers } from './plugins/series-markers/wrapper'; /** * Returns the current version as a string. For example `'3.3.0'`. diff --git a/src/model/autoscale-info-impl.ts b/src/model/autoscale-info-impl.ts index 469a6abc51..058f0b2f93 100644 --- a/src/model/autoscale-info-impl.ts +++ b/src/model/autoscale-info-impl.ts @@ -28,7 +28,7 @@ export class AutoscaleInfoImpl { return this._margins; } - public toRaw(): AutoscaleInfo | null { + public toRaw(): AutoscaleInfo { return { priceRange: this._priceRange === null ? null : this._priceRange.toRaw(), margins: this._margins || undefined, diff --git a/src/plugins/image-watermark/primitive.ts b/src/plugins/image-watermark/primitive.ts index ed84aacd9c..29253ae50d 100644 --- a/src/plugins/image-watermark/primitive.ts +++ b/src/plugins/image-watermark/primitive.ts @@ -1,3 +1,4 @@ +import { IPaneApi } from '../../api/ipane-api'; import { IPanePrimitive, PaneAttachedParameter, @@ -5,9 +6,9 @@ import { import { DeepPartial } from '../../helpers/strict-type-checks'; -import { Time } from '../../model/horz-scale-behavior-time/types'; import { IPanePrimitivePaneView } from '../../model/ipane-primitive'; +import { IPanePrimitiveWithOptions, PanePrimitiveWrapper } from '../pane-primitive-wrapper'; import { ImageWatermarkOptions, imageWatermarkOptionsDefaults, @@ -23,23 +24,7 @@ function mergeOptionsWithDefaults( }; } -/** - * A pane primitive for rendering a image watermark. - * - * @example - * ```js - * import { ImageWatermark } from 'lightweight-charts'; - * - * const imageWatermark = new ImageWatermark('/images/my-image.png', { - * alpha: 0.5, - * padding: 20, - * }); - * - * const firstPane = chart.panes()[0]; - * firstPane.attachPrimitive(imageWatermark); - * ``` - */ -export class ImageWatermark implements IPanePrimitive { +class ImageWatermark implements IPanePrimitive { private _requestUpdate?: () => void; private _paneViews: ImageWatermarkPaneView[]; private _options: ImageWatermarkOptions; @@ -109,3 +94,31 @@ export class ImageWatermark implements IPanePrimitive { ); } } + +/** + * Creates an image watermark. + * + * @param pane - Target pane. + * @param imageUrl - Image URL. + * @param options - Watermark options. + * + * @returns Image watermark wrapper. + * + * @example + * ```js + * import { createImageWatermark } from 'lightweight-charts'; + * + * const firstPane = chart.panes()[0]; + * const imageWatermark = createImageWatermark(firstPane, '/images/my-image.png', { + * alpha: 0.5, + * padding: 20, + * }); + * // to change options + * imageWatermark.applyOptions({ padding: 10 }); + * // to remove watermark from the pane + * imageWatermark.detach(); + * ``` + */ +export function createImageWatermark(pane: IPaneApi, imageUrl: string, options: DeepPartial): PanePrimitiveWrapper> { + return new PanePrimitiveWrapper>(pane, new ImageWatermark(imageUrl, options)); +} diff --git a/src/plugins/pane-primitive-wrapper.ts b/src/plugins/pane-primitive-wrapper.ts new file mode 100644 index 0000000000..c3994bff7c --- /dev/null +++ b/src/plugins/pane-primitive-wrapper.ts @@ -0,0 +1,43 @@ +import { IPaneApi } from '../api/ipane-api'; +import { IPanePrimitive } from '../api/ipane-primitive-api'; + +import { DeepPartial } from '../helpers/strict-type-checks'; + +import { IPrimitiveWrapper } from './primitive-wrapper-base'; + +/** + * Interface for a primitive with options. + */ +export interface IPanePrimitiveWithOptions extends IPanePrimitive { + /** + * @param options - Options to apply. The options are deeply merged with the current options. + */ + applyOptions?: (options: DeepPartial) => void; +} + +export class PanePrimitiveWrapper = IPanePrimitive> implements IPrimitiveWrapper { + protected _primitive: TPrimitive; + protected _pane: IPaneApi; + + public constructor(pane: IPaneApi, primitive: TPrimitive) { + this._pane = pane; + this._primitive = primitive; + this._attach(); + } + + public detach(): void { + this._pane.detachPrimitive(this._primitive); + } + + public getPane(): IPaneApi { + return this._pane; + } + + public applyOptions(options: DeepPartial): void { + this._primitive.applyOptions?.(options); + } + + private _attach(): void { + this._pane.attachPrimitive(this._primitive); + } +} diff --git a/src/plugins/primitive-wrapper-base.ts b/src/plugins/primitive-wrapper-base.ts new file mode 100644 index 0000000000..474d638ec2 --- /dev/null +++ b/src/plugins/primitive-wrapper-base.ts @@ -0,0 +1,25 @@ +import { DeepPartial } from '../helpers/strict-type-checks'; + +/** + * Interface for a primitive wrapper. It must be implemented to add some plugin to the chart. + */ +export interface IPrimitiveWrapper { + /** + * @param options - Options to apply. The options are deeply merged with the current options. + */ + applyOptions(options: DeepPartial): void; + /** + * Detaches the plugin from the pane/series. + */ + detach(): void; +} + +/** + * Interface for a plugin that adds primitive with options. + */ +export interface IPrimitiveWithOptions { + /** + * @param options - Options to apply. The options are deeply merged with the current options. + */ + applyOptions(options: DeepPartial): void; +} diff --git a/src/plugins/primitive-wrapper.ts b/src/plugins/primitive-wrapper.ts new file mode 100644 index 0000000000..cbcc41a7c0 --- /dev/null +++ b/src/plugins/primitive-wrapper.ts @@ -0,0 +1,27 @@ +import { IPanePrimitive, PaneAttachedParameter } from '../api/ipane-primitive-api'; + +import { DeepPartial } from '../helpers/strict-type-checks'; + +export abstract class PrimitiveWrapper { + protected _primitive: IPanePrimitive; + protected _options: Options; + + public constructor(primitive: IPanePrimitive, options: Options) { + this._primitive = primitive; + this._options = options; + } + + public detach(): void { + this._primitive.detached?.(); + } + + public abstract applyOptions(options: DeepPartial): void; + + protected _attachToPrimitive(params: PaneAttachedParameter): void { + this._primitive.attached?.(params); + } + + protected _requestUpdate(): void { + this._primitive.updateAllViews?.(); + } +} diff --git a/src/plugins/series-markers/primitive.ts b/src/plugins/series-markers/primitive.ts index 382451997d..d8debc4e63 100644 --- a/src/plugins/series-markers/primitive.ts +++ b/src/plugins/series-markers/primitive.ts @@ -19,8 +19,7 @@ import { shapeMargin as calculateShapeMargin, } from './utils'; -class SeriesMarkersPrimitive implements ISeriesPrimitive { - private _attached: SeriesAttachedParameter | null = null; +export class SeriesMarkersPrimitive implements ISeriesPrimitive { private _paneView: SeriesMarkersPaneView | null = null; private _markers: SeriesMarker[] = []; private _indexedMarkers: InternalSeriesMarker[] = []; @@ -33,7 +32,6 @@ class SeriesMarkersPrimitive implements ISeriesPrimitive): void { - this._attached = param; this._recalculateMarkers(); this._chart = param.chart; this._series = param.series; @@ -50,12 +48,11 @@ class SeriesMarkersPrimitive implements ISeriesPrimitive implements ISeriesPrimitive) => { @@ -187,43 +184,3 @@ class SeriesMarkersPrimitive implements ISeriesPrimitive( - series: ISeriesApi, - markers?: SeriesMarker[] -): SeriesMarkersPrimitive { - const primitive = new SeriesMarkersPrimitive(); - if (markers) { - primitive.setMarkers(markers); - } - series.attachPrimitive(primitive); - return primitive; -} diff --git a/src/plugins/series-markers/types.ts b/src/plugins/series-markers/types.ts index 71dea98fa0..cecae515d4 100644 --- a/src/plugins/series-markers/types.ts +++ b/src/plugins/series-markers/types.ts @@ -1,5 +1,3 @@ -import { Time } from '../../model/horz-scale-behavior-time/types'; - /** * Represents the position of a series marker relative to a bar. */ @@ -13,7 +11,7 @@ export type SeriesMarkerShape = 'circle' | 'square' | 'arrowUp' | 'arrowDown'; /** * Represents a series marker. */ -export interface SeriesMarker { +export interface SeriesMarker { /** * The time of the marker. */ @@ -44,11 +42,6 @@ export interface SeriesMarker { * @defaultValue `1` */ size?: number; - - /** - * @internal - */ - originalTime: unknown; } export type MarkerPositions = Record; diff --git a/src/plugins/series-markers/utils.ts b/src/plugins/series-markers/utils.ts index 97e0c81207..89e884ceaf 100644 --- a/src/plugins/series-markers/utils.ts +++ b/src/plugins/series-markers/utils.ts @@ -1,6 +1,6 @@ import { ceiledEven, ceiledOdd } from '../../helpers/mathex'; -import { SeriesMarker, SeriesMarkerShape } from './types'; +import { SeriesMarkerShape } from './types'; const enum Constants { MinShapeSize = 12, @@ -48,16 +48,3 @@ export function calculateAdjustedMargin(margin: number, hasSide: boolean, hasInB return 0; } -export function convertSeriesMarker(sm: SeriesMarker, newTime: OutTimeType, originalTime?: unknown): SeriesMarker { - const { time: inTime, originalTime: inOriginalTime, ...values } = sm; - /* eslint-disable @typescript-eslint/consistent-type-assertions */ - const res = { - time: newTime, - ...values, - } as SeriesMarker; - /* eslint-enable @typescript-eslint/consistent-type-assertions */ - if (originalTime !== undefined) { - res.originalTime = originalTime; - } - return res; -} diff --git a/src/plugins/series-markers/wrapper.ts b/src/plugins/series-markers/wrapper.ts new file mode 100644 index 0000000000..be2c1ab5b2 --- /dev/null +++ b/src/plugins/series-markers/wrapper.ts @@ -0,0 +1,63 @@ +import { ISeriesApi } from '../../api/iseries-api'; + +import { SeriesType } from '../../model/series-options'; + +import { SeriesPrimitiveAdapter } from '../series-primitive-adapter'; +import { SeriesMarkersPrimitive } from './primitive'; +import { SeriesMarker } from './types'; + +class SeriesMarkersPrimitiveWrapper extends SeriesPrimitiveAdapter> { + public constructor(series: ISeriesApi, primitive: SeriesMarkersPrimitive, markers?: SeriesMarker[]) { + super(series, primitive); + if (markers) { + this.setMarkers(markers); + } + } + public setMarkers(markers: SeriesMarker[]): void { + this._primitive.setMarkers(markers); + } + + public markers(): readonly SeriesMarker[] { + return this._primitive.markers(); + } +} + +/** + * A function to create a series markers primitive. + * + * @param series - The series to which the primitive will be attached. + * + * @param markers - An array of markers to be displayed on the series. + * + * @example + * ```js + * import { createSeriesMarkers } from 'lightweight-charts'; + * + * const seriesMarkersPrimitive = createSeriesMarkers( + * series, + * [ + * { + * color: 'green', + * position: 'inBar', + * shape: 'arrowDown', + * time: 1556880900, + * }, + * ] + * ); + * // and then you can modify the markers + * // set it to empty array to remove all markers + * seriesMarkersPrimitive.setMarkers([]); + * + * // `seriesMarkersPrimitive.markers()` returns current markers + * ``` + */ +export function createSeriesMarkers( + series: ISeriesApi, + markers?: SeriesMarker[] +): SeriesMarkersPrimitiveWrapper { + const wrapper = new SeriesMarkersPrimitiveWrapper(series, new SeriesMarkersPrimitive()); + if (markers) { + wrapper.setMarkers(markers); + } + return wrapper; +} diff --git a/src/plugins/series-primitive-adapter.ts b/src/plugins/series-primitive-adapter.ts new file mode 100644 index 0000000000..dfa22350da --- /dev/null +++ b/src/plugins/series-primitive-adapter.ts @@ -0,0 +1,47 @@ +import { ISeriesApi } from '../api/iseries-api'; +import { ISeriesPrimitive } from '../api/iseries-primitive-api'; + +import { DeepPartial } from '../helpers/strict-type-checks'; + +import { SeriesType } from '../model/series-options'; + +import { IPrimitiveWrapper } from './primitive-wrapper-base'; + +/** + * Interface for a primitive wrapper. It must be implemented to add some plugin to the chart. + */ +interface ISeriesPrimitiveWithOptions extends ISeriesPrimitive { + /** + * @param options - Options to apply. The options are deeply merged with the current options. + */ + applyOptions?: (options: DeepPartial) => void; +} + +export class SeriesPrimitiveAdapter = ISeriesPrimitive, TSeriesType extends SeriesType = SeriesType> implements IPrimitiveWrapper { + protected _primitive: IPrimitive; + protected _series: ISeriesApi; + + public constructor(series: ISeriesApi, primitive: IPrimitive) { + this._series = series; + this._primitive = primitive; + this._attach(); + } + + public detach(): void { + this._series.detachPrimitive(this._primitive); + } + + public getSeries(): ISeriesApi { + return this._series; + } + + public applyOptions(options: DeepPartial): void { + if (this._primitive && this._primitive.applyOptions) { + this._primitive.applyOptions(options); + } + } + + private _attach(): void { + this._series.attachPrimitive(this._primitive); + } +} diff --git a/src/plugins/text-watermark/primitive.ts b/src/plugins/text-watermark/primitive.ts index 3892b5107f..1f60c17ff1 100644 --- a/src/plugins/text-watermark/primitive.ts +++ b/src/plugins/text-watermark/primitive.ts @@ -1,3 +1,4 @@ +import { IPaneApi } from '../../api/ipane-api'; import { IPanePrimitive, PaneAttachedParameter, @@ -5,9 +6,10 @@ import { import { DeepPartial } from '../../helpers/strict-type-checks'; -import { Time } from '../../model/horz-scale-behavior-time/types'; import { IPanePrimitivePaneView } from '../../model/ipane-primitive'; +import { IPanePrimitiveWithOptions, PanePrimitiveWrapper } from '../pane-primitive-wrapper'; +import { IPrimitiveWithOptions } from '../primitive-wrapper-base'; import { TextWatermarkLineOptions, textWatermarkLineOptionsDefaults, @@ -35,34 +37,7 @@ function mergeOptionsWithDefaults( }; } -/** - * A pane primitive for rendering a text watermark. - * - * @example - * ```js - * const textWatermark = new TextWatermark({ - * horzAlign: 'center', - * vertAlign: 'center', - * lines: [ - * { - * text: 'Hello', - * color: 'rgba(255,0,0,0.5)', - * fontSize: 100, - * fontStyle: 'bold', - * }, - * { - * text: 'This is a text watermark', - * color: 'rgba(0,0,255,0.5)', - * fontSize: 50, - * fontStyle: 'italic', - * fontFamily: 'monospace', - * }, - * ], - * }); - * chart.panes()[0].attachPrimitive(textWatermark); - * ``` - */ -export class TextWatermark implements IPanePrimitive { +export class TextWatermark implements IPanePrimitive, IPrimitiveWithOptions { public requestUpdate?: () => void; private _paneViews: TextWatermarkPaneView[]; private _options: TextWatermarkOptions; @@ -97,3 +72,46 @@ export class TextWatermark implements IPanePrimitive { } } } + +/** + * Creates an image watermark. + * + * @param pane - Target pane. + * @param imageUrl - Image URL. + * @param options - Watermark options. + * + * @returns Image watermark wrapper. + * + * @example + * ```js + * import { createTextWatermark } from 'lightweight-charts'; + * + * const firstPane = chart.panes()[0]; + * const textWatermark = createTextWatermark(firstPane, { + * horzAlign: 'center', + * vertAlign: 'center', + * lines: [ + * { + * text: 'Hello', + * color: 'rgba(255,0,0,0.5)', + * fontSize: 100, + * fontStyle: 'bold', + * }, + * { + * text: 'This is a text watermark', + * color: 'rgba(0,0,255,0.5)', + * fontSize: 50, + * fontStyle: 'italic', + * fontFamily: 'monospace', + * }, + * ], + * }); + * // to change options + * textWatermark.applyOptions({ horzAlign: 'left' }); + * // to remove watermark from the pane + * textWatermark.detach(); + * ``` + */ +export function createTextWatermark(pane: IPaneApi, options: DeepPartial): PanePrimitiveWrapper> { + return new PanePrimitiveWrapper>(pane, new TextWatermark(options)); +} diff --git a/src/plugins/types.ts b/src/plugins/types.ts index b6f88ff426..143a49f69a 100644 --- a/src/plugins/types.ts +++ b/src/plugins/types.ts @@ -1,3 +1,7 @@ +import { ISeriesApi } from '../api/iseries-api'; + +import { SeriesType } from '../model/series-options'; + /** * Represents a horizontal alignment. */ @@ -6,3 +10,11 @@ export type HorzAlign = 'left' | 'center' | 'right'; * Represents a vertical alignment. */ export type VertAlign = 'top' | 'center' | 'bottom'; + +type DefaultOptionsType = Record; +export interface IPluginApiBase> { + series(): ISeriesApi; + detach(): void; + options(): Options; + applyOptions(options: Options | Partial): void; +} diff --git a/tests/e2e/coverage/test-cases/plugins/text-watermark.js b/tests/e2e/coverage/test-cases/plugins/text-watermark.js index 4c16bb78d5..9f995ae511 100644 --- a/tests/e2e/coverage/test-cases/plugins/text-watermark.js +++ b/tests/e2e/coverage/test-cases/plugins/text-watermark.js @@ -19,8 +19,8 @@ function beforeInteractions(container) { const mainSeries = chart.addLineSeries(); mainSeries.setData(simpleData()); - - textWatermark = new LightweightCharts.TextWatermark({ + const pane = chart.panes()[0]; + textWatermark = LightweightCharts.createTextWatermark(pane, { horzAlign: 'center', vertAlign: 'center', lines: [ @@ -40,9 +40,6 @@ function beforeInteractions(container) { ], }); - const pane = chart.panes()[0]; - pane.attachPrimitive(textWatermark); - return Promise.resolve(); } diff --git a/tests/e2e/coverage/test-cases/series/markers.js b/tests/e2e/coverage/test-cases/series/markers.js index a2df75665f..7a3ddd8ae6 100644 --- a/tests/e2e/coverage/test-cases/series/markers.js +++ b/tests/e2e/coverage/test-cases/series/markers.js @@ -15,7 +15,7 @@ function beforeInteractions(container) { const data = generateLineData(); mainSeries.setData(data); - seriesMarkerPrimitives = LightweightCharts.createSeriesMarkersPrimitive( + seriesMarkerPrimitives = LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 7].time, position: 'belowBar', color: 'rgb(255, 0, 0)', shape: 'arrowUp', text: 'test' }, diff --git a/tests/e2e/graphics/test-cases/add-markers-with-autosize-enabled.js b/tests/e2e/graphics/test-cases/add-markers-with-autosize-enabled.js index 2903831953..2de17a770b 100644 --- a/tests/e2e/graphics/test-cases/add-markers-with-autosize-enabled.js +++ b/tests/e2e/graphics/test-cases/add-markers-with-autosize-enabled.js @@ -70,7 +70,7 @@ function runTestCase(container) { }); } } - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( series, markers ); diff --git a/tests/e2e/graphics/test-cases/api/series-markers.js b/tests/e2e/graphics/test-cases/api/series-markers.js index abc7814508..45d41d831c 100644 --- a/tests/e2e/graphics/test-cases/api/series-markers.js +++ b/tests/e2e/graphics/test-cases/api/series-markers.js @@ -37,13 +37,14 @@ function runTestCase(container) { { time: '1990-04-30', position: 'aboveBar', color: 'red', shape: 'arrowDown' }, ]; - const markersPrimitive = LightweightCharts.createSeriesMarkersPrimitive( + const markersPrimitive = LightweightCharts.createSeriesMarkers( series, markers ); const seriesApiMarkers = markersPrimitive.markers(); - const textWatermark = new LightweightCharts.TextWatermark({ + const pane = chart.panes()[0]; + LightweightCharts.createTextWatermark(pane, { lines: [ { text: JSON.stringify(seriesApiMarkers[0]), @@ -51,8 +52,6 @@ function runTestCase(container) { }, ], }); - const pane = chart.panes()[0]; - pane.attachPrimitive(textWatermark); console.assert(compare(markers, seriesApiMarkers), `seriesMarkersPrimitive.markers() should return exactly the same that was provided to series.setMarkers()\n${JSON.stringify(seriesApiMarkers)}\n${JSON.stringify(markers)}`); } diff --git a/tests/e2e/graphics/test-cases/api/subscribe-crosshair-move.js b/tests/e2e/graphics/test-cases/api/subscribe-crosshair-move.js index 9e03dda8a5..e5f6c773b7 100644 --- a/tests/e2e/graphics/test-cases/api/subscribe-crosshair-move.js +++ b/tests/e2e/graphics/test-cases/api/subscribe-crosshair-move.js @@ -14,7 +14,7 @@ function runTestCase(container) { chart.timeScale().fitContent(); - const textWatermark = new LightweightCharts.TextWatermark({ + const textWatermark = LightweightCharts.createTextWatermark(chart.panes()[0], { lines: [ { text: '', @@ -23,8 +23,6 @@ function runTestCase(container) { }, ], }); - const pane = chart.panes()[0]; - pane.attachPrimitive(textWatermark); chart.subscribeCrosshairMove(param => { if (param.time) { diff --git a/tests/e2e/graphics/test-cases/applying-options/make-series-hidden.js b/tests/e2e/graphics/test-cases/applying-options/make-series-hidden.js index 6851630492..ea5eba465d 100644 --- a/tests/e2e/graphics/test-cases/applying-options/make-series-hidden.js +++ b/tests/e2e/graphics/test-cases/applying-options/make-series-hidden.js @@ -25,7 +25,7 @@ function runTestCase(container) { }); const data = generateData(); lineSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( lineSeries, [ { time: data[data.length - 30].time, position: 'belowBar', color: 'orange', shape: 'arrowUp' }, diff --git a/tests/e2e/graphics/test-cases/applying-options/make-series-visible.js b/tests/e2e/graphics/test-cases/applying-options/make-series-visible.js index 962604f235..ef91fa1b9c 100644 --- a/tests/e2e/graphics/test-cases/applying-options/make-series-visible.js +++ b/tests/e2e/graphics/test-cases/applying-options/make-series-visible.js @@ -26,7 +26,7 @@ function runTestCase(container) { }); const data = generateData(); lineSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( lineSeries, [ { time: data[data.length - 30].time, position: 'belowBar', color: 'orange', shape: 'arrowUp' }, diff --git a/tests/e2e/graphics/test-cases/applying-options/watermark.js b/tests/e2e/graphics/test-cases/applying-options/watermark.js index eddc3b25c5..1d1008ea58 100644 --- a/tests/e2e/graphics/test-cases/applying-options/watermark.js +++ b/tests/e2e/graphics/test-cases/applying-options/watermark.js @@ -33,7 +33,7 @@ function runTestCase(container) { mainSeries.setData(generateData()); - textWatermark = new LightweightCharts.TextWatermark({ + textWatermark = LightweightCharts.createTextWatermark(chart.panes()[0], { horzAlign: 'left', vertAlign: 'bottom', lines: [ @@ -44,8 +44,6 @@ function runTestCase(container) { }, ], }); - const pane = chart.panes()[0]; - pane.attachPrimitive(textWatermark); return new Promise(resolve => { setTimeout(() => { diff --git a/tests/e2e/graphics/test-cases/data-validation.js b/tests/e2e/graphics/test-cases/data-validation.js index d360e31686..3ad780dc70 100644 --- a/tests/e2e/graphics/test-cases/data-validation.js +++ b/tests/e2e/graphics/test-cases/data-validation.js @@ -29,20 +29,6 @@ function runTestCase(container) { // passed } - try { - LightweightCharts.createSeriesMarkersPrimitive( - lineSeries, - [ - { time: 1 }, - { time: 0, value: 0 }, - ] - ); - - console.assert(false, 'should fail if series markers is not ordered'); - } catch (e) { - // passed - } - try { lineSeries.setData([ { time: 0 }, @@ -96,7 +82,7 @@ function runTestCase(container) { } // should pass - several markers could be on the same bar - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( lineSeries, [ { diff --git a/tests/e2e/graphics/test-cases/initial-options/watermark.js b/tests/e2e/graphics/test-cases/initial-options/watermark.js index e48f1f7b7d..7442ed56f8 100644 --- a/tests/e2e/graphics/test-cases/initial-options/watermark.js +++ b/tests/e2e/graphics/test-cases/initial-options/watermark.js @@ -20,7 +20,7 @@ function runTestCase(container) { const mainSeries = chart.addAreaSeries(); mainSeries.setData(generateData()); - const textWatermark = new LightweightCharts.TextWatermark({ + LightweightCharts.createTextWatermark(chart.panes()[0], { visible: true, lines: [ { @@ -32,7 +32,4 @@ function runTestCase(container) { }, ], }); - - const pane = chart.panes()[0]; - pane.attachPrimitive(textWatermark); } diff --git a/tests/e2e/graphics/test-cases/plugins/image-watermark.js b/tests/e2e/graphics/test-cases/plugins/image-watermark.js index 0e2fd8a905..d2ed2d56c3 100644 --- a/tests/e2e/graphics/test-cases/plugins/image-watermark.js +++ b/tests/e2e/graphics/test-cases/plugins/image-watermark.js @@ -71,11 +71,8 @@ function runTestCase(container) { const mainSeries = chart.addAreaSeries(); mainSeries.setData(generateData()); - const imageWatermark = new LightweightCharts.ImageWatermark(imageDataUrl, { + LightweightCharts.createImageWatermark(chart.panes()[0], imageDataUrl, { alpha: 0.5, padding: 20, }); - - const pane = chart.panes()[0]; - pane.attachPrimitive(imageWatermark); } diff --git a/tests/e2e/graphics/test-cases/series-markers/marker-in-gap-from-left.js b/tests/e2e/graphics/test-cases/series-markers/marker-in-gap-from-left.js index a74067f0f4..713af824b9 100644 --- a/tests/e2e/graphics/test-cases/series-markers/marker-in-gap-from-left.js +++ b/tests/e2e/graphics/test-cases/series-markers/marker-in-gap-from-left.js @@ -25,7 +25,7 @@ function runTestCase(container) { { time: 1556892000, value: 132.24 }, { time: 1556895600, value: 132.52 }, ]); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( lineSeries, [ { diff --git a/tests/e2e/graphics/test-cases/series-markers/marker-in-gap.js b/tests/e2e/graphics/test-cases/series-markers/marker-in-gap.js index 8c5395ee90..1434a7a471 100644 --- a/tests/e2e/graphics/test-cases/series-markers/marker-in-gap.js +++ b/tests/e2e/graphics/test-cases/series-markers/marker-in-gap.js @@ -25,7 +25,7 @@ function runTestCase(container) { { time: 1556895600, value: 132.52 }, ]); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( lineSeries, [ { diff --git a/tests/e2e/graphics/test-cases/series-markers/series-arrow-markers.js b/tests/e2e/graphics/test-cases/series-markers/series-arrow-markers.js index 49424c0355..f66e6213ed 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-arrow-markers.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-arrow-markers.js @@ -30,7 +30,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 30].time, position: 'belowBar', color: 'orange', shape: 'arrowUp' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-circle-markers.js b/tests/e2e/graphics/test-cases/series-markers/series-circle-markers.js index a1ce3388ee..fb3e7ce8b9 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-circle-markers.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-circle-markers.js @@ -29,7 +29,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 30].time, position: 'belowBar', color: 'orange', shape: 'circle' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-aligned.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-aligned.js index f586c70b2b..4beb5411f8 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-aligned.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-aligned.js @@ -15,7 +15,7 @@ function runTestCase(container) { { time: '2017-04-23', value: 81.89 }, ]); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( line, [ { time: '2017-04-10', position: 'inBar', color: 'orange', shape: 'circle' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-all-above.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-all-above.js index 2c4ae32cbb..fe618756b6 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-all-above.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-all-above.js @@ -20,7 +20,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[0].time, position: 'aboveBar', color: 'red', shape: 'arrowUp' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-all-below.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-all-below.js index b44d5ef09a..287a0b6d26 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-all-below.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-all-below.js @@ -20,7 +20,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 3].time, position: 'belowBar', color: 'red', shape: 'arrowUp' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-all-inbar.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-all-inbar.js index a1cc6d5999..33cc25c8f9 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-all-inbar.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-all-inbar.js @@ -19,7 +19,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 3].time, position: 'inBar', color: 'red', shape: 'arrowUp' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-max-bar-spacing.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-max-bar-spacing.js index b4ada767aa..4e7803c7f6 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-max-bar-spacing.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-max-bar-spacing.js @@ -20,7 +20,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 4].time, position: 'inBar', color: 'red', shape: 'square' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-min-bar-spacing.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-min-bar-spacing.js index ba15c92396..5ee848a928 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-min-bar-spacing.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-min-bar-spacing.js @@ -27,7 +27,7 @@ function runTestCase(container) { { time: data[data.length - 10].time, position: 'inBar', color: 'red', shape: 'arrowUp' }, ]; - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, markers ); diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-object-business-day.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-object-business-day.js index 56f0c0dc4a..c2758d2d6f 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-object-business-day.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-object-business-day.js @@ -15,7 +15,7 @@ function runTestCase(container) { { time: '2017-04-23', value: 81.89 }, ]); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( line, [ { time: { year: 2017, month: 4, day: 11 }, position: 'inBar', color: 'orange', shape: 'circle' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-out-of-visible-range.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-out-of-visible-range.js index 51a9e30c33..25bc105757 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-out-of-visible-range.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-out-of-visible-range.js @@ -20,7 +20,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[0].time, position: 'belowBar', color: 'red', shape: 'arrowUp' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-re-aligned.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-re-aligned.js index 2c7033d055..a3f0801818 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-re-aligned.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-re-aligned.js @@ -15,7 +15,7 @@ function runTestCase(container) { { time: '2017-04-23', value: 91.89 }, ]); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( line, [ { time: '2017-04-10', position: 'inBar', color: 'orange', shape: 'circle' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-update.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-update.js index 62129560a9..f26c279c2a 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-update.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-update.js @@ -26,7 +26,7 @@ function runTestCase(container) { { time: data[data.length - 20].time, position: 'belowBar', color: 'red', shape: 'arrowUp' }, { time: data[data.length - 10].time, position: 'belowBar', color: 'red', shape: 'arrowUp' }, ]; - const markerPrimitive = LightweightCharts.createSeriesMarkersPrimitive( + const markerPrimitive = LightweightCharts.createSeriesMarkers( mainSeries, markers ); diff --git a/tests/e2e/graphics/test-cases/series-markers/series-markers-with-text.js b/tests/e2e/graphics/test-cases/series-markers/series-markers-with-text.js index 15450196a0..77b03da123 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-markers-with-text.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-markers-with-text.js @@ -37,7 +37,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 50].time, position: 'belowBar', color: 'red', shape: 'arrowUp', text: 'test' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/series-square-markers.js b/tests/e2e/graphics/test-cases/series-markers/series-square-markers.js index e9cdc52629..c9616d2c53 100644 --- a/tests/e2e/graphics/test-cases/series-markers/series-square-markers.js +++ b/tests/e2e/graphics/test-cases/series-markers/series-square-markers.js @@ -29,7 +29,7 @@ function runTestCase(container) { const data = generateData(); mainSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { time: data[data.length - 30].time, position: 'belowBar', color: 'orange', shape: 'square' }, diff --git a/tests/e2e/graphics/test-cases/series-markers/set-markers-before-series-data.js b/tests/e2e/graphics/test-cases/series-markers/set-markers-before-series-data.js index 61613d5330..5aa41db417 100644 --- a/tests/e2e/graphics/test-cases/series-markers/set-markers-before-series-data.js +++ b/tests/e2e/graphics/test-cases/series-markers/set-markers-before-series-data.js @@ -3,7 +3,7 @@ function runTestCase(container) { const mainSeries = chart.addLineSeries(); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { diff --git a/tests/e2e/graphics/test-cases/series/series-visibility.js b/tests/e2e/graphics/test-cases/series/series-visibility.js index 2abdd8de23..6eefd599a1 100644 --- a/tests/e2e/graphics/test-cases/series/series-visibility.js +++ b/tests/e2e/graphics/test-cases/series/series-visibility.js @@ -45,7 +45,7 @@ function runTestCase(container) { }); const data = generateData(); lineSeries.setData(data); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( lineSeries, [ { time: data[data.length - 30].time, position: 'belowBar', color: 'orange', shape: 'arrowUp' }, diff --git a/tests/e2e/interactions/test-cases/markers/text-hit-test.js b/tests/e2e/interactions/test-cases/markers/text-hit-test.js index fffc11ea59..1a7a4cc43f 100644 --- a/tests/e2e/interactions/test-cases/markers/text-hit-test.js +++ b/tests/e2e/interactions/test-cases/markers/text-hit-test.js @@ -49,7 +49,7 @@ function beforeInteractions(container) { const price = mainSeriesData[450].value; mainSeries.setData(mainSeriesData); - LightweightCharts.createSeriesMarkersPrimitive( + LightweightCharts.createSeriesMarkers( mainSeries, [ { diff --git a/tests/type-checks/non-time-based-custom-series.ts b/tests/type-checks/non-time-based-custom-series.ts index a30145a361..7a61994d6f 100644 --- a/tests/type-checks/non-time-based-custom-series.ts +++ b/tests/type-checks/non-time-based-custom-series.ts @@ -1,4 +1,4 @@ -import { createChartEx, customSeriesDefaultOptions, TextWatermark } from '../../src'; +import { createChartEx, createTextWatermark, customSeriesDefaultOptions } from '../../src'; import { CandlestickData, WhitespaceData } from '../../src/model/data-consumer'; import { Time } from '../../src/model/horz-scale-behavior-time/types'; import { CustomData, CustomSeriesPricePlotValues, ICustomSeriesPaneRenderer, ICustomSeriesPaneView, PaneRendererCustomData } from '../../src/model/icustom-series'; @@ -107,7 +107,6 @@ if (dataSet) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call dataSet.push({ time: 12 }); -const textWatermark = new TextWatermark({ +createTextWatermark(chart.panes()[1], { lines: [], }); -chart.panes()[1].attachPrimitive(textWatermark); diff --git a/tests/type-checks/series-markers.ts b/tests/type-checks/series-markers.ts new file mode 100644 index 0000000000..1b4aa1c99b --- /dev/null +++ b/tests/type-checks/series-markers.ts @@ -0,0 +1,122 @@ +import { createChart, createChartEx, createSeriesMarkers } from '../../src'; +import { Mutable } from '../../src/helpers/mutable'; +import { ChartOptionsImpl } from '../../src/model/chart-model'; +import { SeriesDataItemTypeMap } from '../../src/model/data-consumer'; +import { Time } from '../../src/model/horz-scale-behavior-time/types'; +import { DataItem, HorzScaleItemConverterToInternalObj, IHorzScaleBehavior, InternalHorzScaleItem } from '../../src/model/ihorz-scale-behavior'; +import { LocalizationOptions } from '../../src/model/localization-options'; +import { SeriesType } from '../../src/model/series-options'; +import { TickMark } from '../../src/model/tick-marks'; +import { TickMarkWeightValue, TimeScalePoint } from '../../src/model/time-data'; +import { TimeMark } from '../../src/model/time-scale'; + +const chart = createChart('container'); + +const mainSeries = chart.addLineSeries(); +mainSeries.setData([]); + +const seriesMarkersPrimitive = createSeriesMarkers(mainSeries, [ + { + color: 'green', + position: 'inBar', + shape: 'arrowDown', + time: 1556880900 as Time, + }, +]); + +seriesMarkersPrimitive.setMarkers([ + { + color: 'red', + position: 'aboveBar', + shape: 'arrowDown', + time: 1556880900 as Time, + }, +]); + +type HorizontalScaleType = number; + +class HorzScaleBehaviorPrice implements IHorzScaleBehavior { + private _options: ChartOptionsImpl; + + public constructor() { + this._options = {} as unknown as ChartOptionsImpl; + } + + public options(): ChartOptionsImpl { + return this._options; + } + + public setOptions(options: ChartOptionsImpl): void { + this._options = options; + } + + public preprocessData(data: DataItem | DataItem[]): void {} + + public updateFormatter(options: LocalizationOptions): void { + if (!this._options) { + return; + } + this._options.localization = options; + } + + public createConverterToInternalObj(data: SeriesDataItemTypeMap[SeriesType][]): HorzScaleItemConverterToInternalObj { + return (price: number): InternalHorzScaleItem => price as unknown as InternalHorzScaleItem; + } + + // @ts-expect-error Mock Method + public key(internalItem: InternalHorzScaleItem | HorizontalScaleType): InternalHorzScaleItem { + return internalItem as unknown as InternalHorzScaleItem; + } + + public cacheKey(internalItem: InternalHorzScaleItem): number { + return internalItem as unknown as number; + } + + public convertHorzItemToInternal(item: HorizontalScaleType): InternalHorzScaleItem { + return item as unknown as InternalHorzScaleItem; + } + + public formatHorzItem(item: InternalHorzScaleItem): string { + return (item as unknown as HorizontalScaleType).toFixed(this._precision()); + } + + public formatTickmark(item: TickMark, localizationOptions: LocalizationOptions): string { + return (item.time as unknown as HorizontalScaleType).toFixed(this._precision()); + } + + public maxTickMarkWeight(marks: TimeMark[]): TickMarkWeightValue { + return marks[0].weight; + } + + public fillWeightsForPoints(sortedTimePoints: readonly Mutable[], startIndex: number): void { + return; + } + + private _precision(): number { + return 2; + } +} +const horizontalScaleBehaviourMock = new HorzScaleBehaviorPrice(); + +// @ts-expect-error Mock Class +const nonDefaultChart = createChartEx('anything', horizontalScaleBehaviourMock); +const lineSeries = nonDefaultChart.addLineSeries(); +lineSeries.setData([]); + +const markerApi = createSeriesMarkers(mainSeries, [ + { + color: 'green', + position: 'inBar', + shape: 'arrowDown', + time: 1556880900 as Time, + }, +]); + +markerApi.setMarkers([ + { + color: 'red', + position: 'aboveBar', + shape: 'arrowDown', + time: 1556880900 as Time, + }, +]); diff --git a/tests/type-checks/watermarks.ts b/tests/type-checks/watermarks.ts index 2fe644860d..baae72d57b 100644 --- a/tests/type-checks/watermarks.ts +++ b/tests/type-checks/watermarks.ts @@ -1,19 +1,18 @@ -import { createChart, ImageWatermark, TextWatermark } from '../../src'; +import { createChart, createImageWatermark, createTextWatermark } from '../../src'; const chart = createChart('anything'); const mainSeries = chart.addLineSeries(); mainSeries.setData([]); -const imageWatermark = new ImageWatermark('/debug/image.svg', { +createImageWatermark(chart.panes()[0], '/debug/image.svg', { alpha: 0.5, padding: 50, maxHeight: 400, maxWidth: 400, }); -chart.panes()[0].attachPrimitive(imageWatermark); -const textWatermark = new TextWatermark({ +createTextWatermark(chart.panes()[1], { horzAlign: 'center', vertAlign: 'center', lines: [ @@ -25,4 +24,3 @@ const textWatermark = new TextWatermark({ }, ], }); -chart.panes()[1].attachPrimitive(textWatermark); diff --git a/website/tutorials/how_to/.eslintrc.js b/website/tutorials/how_to/.eslintrc.js index 379db16386..736a7aee55 100644 --- a/website/tutorials/how_to/.eslintrc.js +++ b/website/tutorials/how_to/.eslintrc.js @@ -3,7 +3,8 @@ module.exports = { document: false, createChart: false, createChartEx: false, - TextWatermark: false, - ImageWatermark: false, + createTextWatermark: false, + createImageWatermark: false, + createSeriesMarkers: false, }, }; diff --git a/website/tutorials/how_to/series-markers.js b/website/tutorials/how_to/series-markers.js index 178ba59976..f5fc973dd8 100644 --- a/website/tutorials/how_to/series-markers.js +++ b/website/tutorials/how_to/series-markers.js @@ -769,7 +769,8 @@ for (let i = 0; i < datesForMarkers.length; i++) { }); } } -series.setMarkers(markers); +/** @type {import('lightweight-charts').createSeriesMarkers} */ +createSeriesMarkers(series, markers); // highlight-end chart.timeScale().fitContent(); diff --git a/website/tutorials/how_to/series-markers.mdx b/website/tutorials/how_to/series-markers.mdx index 6e132adce2..b591a929ed 100644 --- a/website/tutorials/how_to/series-markers.mdx +++ b/website/tutorials/how_to/series-markers.mdx @@ -16,7 +16,7 @@ This example shows how to add series markers to your chart. ## Short answer You can add markers to a series by passing an array of [`seriesMarker`](/docs/api/interfaces/SeriesMarker) -objects to the [`setMarkers`](/docs/api/interfaces/ISeriesApi#setmarkers) method on +objects to the [`createSeriesMarkers`](/docs/api#createSeriesMarkers) method on an [`ISeriesApi`](/docs/api/interfaces/ISeriesApi) instance. ```js @@ -29,7 +29,7 @@ const markers = [ text: 'A', }, ]; -series.setMarkers(markers); +createSeriesMarkers(series, markers); ``` You can see a full [working example](#full-example) below. @@ -47,7 +47,7 @@ You can view the related APIs here: - [SeriesMarker](/docs/api/interfaces/SeriesMarker) - Series Marker interface. - [SeriesMarkerPosition](/docs/api/type-aliases/SeriesMarkerPosition) - Positions that can be set for the marker. - [SeriesMarkerShape](/docs/api/type-aliases/SeriesMarkerShape) - Shapes that can be set for the marker. -- [setMarkers](/docs/api/interfaces/ISeriesApi#setmarkers) - Method for adding markers to a series. +- [createSeriesMarkers](/docs/next/api/interfaces/ISeriesApi#setmarkers) - Method for adding markers to a series. - [Time Types](/docs/api/type-aliases/Time) - Different time formats available to use. ## Full example diff --git a/website/tutorials/how_to/watermark-advanced.js b/website/tutorials/how_to/watermark-advanced.js index 5ab395a50e..62da3a7343 100644 --- a/website/tutorials/how_to/watermark-advanced.js +++ b/website/tutorials/how_to/watermark-advanced.js @@ -16,13 +16,10 @@ const chart = createChart(document.getElementById('container'), chartOptions); // highlight-start // imageDataUrl would usually be an url like '/images/my-image.png' const imageDataUrl = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyOTIiIGhlaWdodD0iMTI4IiB2aWV3Qm94PSIwIDAgMjkyIDEyOCI+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBkPSJtMTgyLjkzIDcuNi42My0uMzdhNjQuMSA2NC4xIDAgMCAwIDIuNDMtNS4zMWw0Ljc3LTEuMzlhNjQuNjggNjQuNjggMCAwIDEtNC43MiAxMC41NGMuMzggMTAuNDUtMy45MyAyMS4xNS0xMS4xIDI5LjM3LTExLjY2IDEzLjQxLTI2Ljk4IDE1Ljk3LTQzLjU3IDEzLjc4bDEuMDctLjk4YTIxLjEgMjEuMSAwIDAgMCAzLjcyLTQuMDUgNDguMzcgNDguMzcgMCAwIDEtMTEuMDQgMi44NGMtMTAuNjUtNS41NC0yMS42NC0xNC45NC0yNC4yNy0yNy4yNyA5LjE5LTE3IDI4Ljk1LTI0LjAxIDQ3LjM5LTE5Ljk0YTIyLjU3IDIyLjU3IDAgMCAwIDUuODYgOS4wMmMtLjEyLTEuOTItLjEtMy44NC0uMS01Ljc2bC4wMS0xLjc4YzQuOCAyLjk2IDkuNjYgNS44NSAxNS41MiA1LjcgNC4wOC0uMSA4LjQtMS41MiAxMy40LTQuNFptLTIyLjU1IDIzLjI4YTguNDggOC40OCAwIDAgMC0xMi40NS0uMzNsLTcuOS03LjI2QTguNiA4Lj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DQuODgtMTEuMzZoLTEuMzVsLTQuMDMgOS4zOC00LjAzLTkuMzhoLTEuMzZsNC45IDExLjM2aC45OVptNy44NC0xMS4yNWMwIC40Ny0uMzcuODUtLjgzLjg1YS44Ni44NiAwIDAgMS0uODYtLjg1YzAtLjQ2LjM4LS44NS44Ni0uODUuNDcgMCAuODMuMzkuODMuODVabS0uMjggMTEuMjVoLTEuMTN2LThoMS4xM3Y4Wm02LjIuMTZhMy45IDMuOSAwIDAgMCAzLjU2LTEuOTVsLS45MS0uNmEyLjc4IDIuNzggMCAwIDEtMi42NCAxLjUxIDIuODcgMi44NyAwIDAgMS0yLjk2LTIuOTNoNi43NXYtLjNjLS4wMi0yLjU2LTEuNjgtNC4wNS0zLjc2LTQuMDVhNC4wNSA0LjA1IDAgMCAwLTQuMTUgNC4xNmMwIDIuMyAxLjYgNC4xNiA0LjEyIDQuMTZabS0uMDEtNy4yOGMxLjM0IDAgMi40NS44OCAyLjY0IDIuMzJoLTUuNDlhMi44NCAyLjg0IDAgMCAxIDIuODUtMi4zMlptMTMuNTUgNy4xMmgtLjkzbC0yLjEtNi4xLTIuMTQgNi4xaC0uOTJsLTIuNzQtOGgxLjE1bDIuMDggNi4wOCAyLjExLTYuMDhoLjg3bDIuMTEgNi4wOCAyLjA4LTYuMDhoMS4xN2wtMi43NCA4WiIgZmlsbD0iY3VycmVudENvbG9yIj48L3BhdGg+PC9zdmc+'; -const imageWatermark = new ImageWatermark(imageDataUrl, { +createImageWatermark(chart.panes()[0], imageDataUrl, { alpha: 0.5, padding: 20, }); - -const firstPane = chart.panes()[0]; -firstPane.attachPrimitive(imageWatermark); // highlight-end const lineSeries = chart.addAreaSeries({ diff --git a/website/tutorials/how_to/watermark-simple.js b/website/tutorials/how_to/watermark-simple.js index 73e09bfded..d2fbbfaabb 100644 --- a/website/tutorials/how_to/watermark-simple.js +++ b/website/tutorials/how_to/watermark-simple.js @@ -14,9 +14,9 @@ const chartOptions = { const chart = createChart(document.getElementById('container'), chartOptions); // remove-line -/** @type {import('lightweight-charts').TextWatermark} */ +/** @type {import('lightweight-charts').createTextWatermark} */ // highlight-start -const textWatermark = new TextWatermark({ +createTextWatermark(chart.panes()[0], { horzAlign: 'center', vertAlign: 'center', lines: [ @@ -27,8 +27,6 @@ const textWatermark = new TextWatermark({ }, ], }); -const firstPane = chart.panes()[0]; -firstPane.attachPrimitive(textWatermark); // highlight-end const lineSeries = chart.addAreaSeries({ diff --git a/website/tutorials/how_to/watermark.mdx b/website/tutorials/how_to/watermark.mdx index 6fe89b2a79..a956272616 100644 --- a/website/tutorials/how_to/watermark.mdx +++ b/website/tutorials/how_to/watermark.mdx @@ -16,13 +16,14 @@ included below. ## Short answer -A simple text watermark can be configured and added by using the [`TextWatermark`](/docs/next/api/classes/TextWatermark) pane primitive exported +A simple text watermark can be configured and added by using the [`createTextWatermark`](/docs/next/api#createTextWatermark) function exported from the library as follows: ```js -import { TextWatermark } from 'lightweight-charts'; +import { createTextWatermark } from 'lightweight-charts'; -const textWatermark = new TextWatermark({ +const firstPane = chart.panes()[0]; +const textWatermark = createTextWatermark(firstPane, { horzAlign: 'center', vertAlign: 'center', lines: [ @@ -34,8 +35,6 @@ const textWatermark = new TextWatermark({ ], }); -const firstPane = chart.panes()[0]; -firstPane.attachPrimitive(textWatermark); ``` The options available for the watermark are: [TextWatermark Options](/docs/next/api/interfaces/TextWatermarkOptions). @@ -44,7 +43,7 @@ You can see full [working examples](#examples) below. ## Resources -- [`TextWatermark` pane primitive](/docs/next/api/classes/TextWatermark). +- [`createTextWatermark` function](/docs/next/api#createTextWatermark). - [TextWatermark Options](/docs/next/api/interfaces/TextWatermarkOptions) ## Examples @@ -65,19 +64,17 @@ import codeSimple from "!!raw-loader!./watermark-simple.js"; ### Image Watermark Example -If a simple text watermark doesn't meet your requirements then you can use the [`ImageWatermark`](/docs/next/api/classes/ImageWatermark) pane primitive exported +If a simple text watermark doesn't meet your requirements then you can use the Image watermark via [`createImageWatermark`](/docs/next/api#createImageWatermark) function exported from the library as follows: ```js -import { ImageWatermark } from 'lightweight-charts'; +import { createImageWatermark } from 'lightweight-charts'; -const imageWatermark = new ImageWatermark('/images/my-image.png', { +const firstPane = chart.panes()[0]; +const imageWatermark = createImageWatermark(firstPane, '/images/my-image.png', { alpha: 0.5, padding: 20, }); - -const firstPane = chart.panes()[0]; -firstPane.attachPrimitive(imageWatermark); ``` The options available for the watermark are: [ImageWatermark Options](/docs/next/api/interfaces/ImageWatermarkOptions). @@ -86,7 +83,7 @@ You can see full [working examples](#examples) below. ## Resources -- [`ImageWatermark` pane primitive](/docs/next/api/classes/ImageWatermark). +- [`createImageWatermark` pane primitive](/docs/next/api#createImageWatermark). - [ImageWatermark Options](/docs/next/api/interfaces/ImageWatermarkOptions) :::tip