diff --git a/package.json b/package.json index 60074cf..4969b28 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "html-webpack-plugin": "5.3.1", "husky": "4.3.8", "jest": "27.3.1", - "lightweight-charts": "3.3.0", + "lightweight-charts": "3.7.0", "lint-staged": "10.5.4", "lodash": "4.17.21", "mini-css-extract-plugin": "1.3.4", diff --git a/src/demo/app.svelte b/src/demo/app.svelte index cf74cd0..f05cc8e 100644 --- a/src/demo/app.svelte +++ b/src/demo/app.svelte @@ -27,6 +27,7 @@ import HistogramSeries from 'svelte-lightweight-charts/components/histogram-series.svelte'; import BarSeries from 'svelte-lightweight-charts/components/bar-series.svelte'; import CandlestickSeries from 'svelte-lightweight-charts/components/candlestick-series.svelte'; + import BaselineSeries from 'svelte-lightweight-charts/components/baseline-series.svelte'; import PriceLine from 'svelte-lightweight-charts/components/price-line.svelte'; type EverySeriesApi = @@ -35,11 +36,12 @@ | ISeriesApi<'Histogram'> | ISeriesApi<'Candlestick'> | ISeriesApi<'Line'> + | ISeriesApi<'Baseline'> ; export let reference: Reference | undefined = undefined; - const SERIES_TYPES: SeriesType[] = ['Area', 'Bar', 'Histogram', 'Candlestick', 'Line']; + const SERIES_TYPES: SeriesType[] = ['Area', 'Bar', 'Histogram', 'Candlestick', 'Line', 'Baseline']; const lines: PriceLineParams[] = [{ id: 'price', @@ -196,7 +198,7 @@ clearTicker(); } if (daily) { - ticker = setInterval( + ticker = window.setInterval( () => { day.setDate(day.getDate() + 1); day = new Date(day); @@ -204,7 +206,7 @@ 1000 ); } else { - ticker = setInterval( + ticker = window.setInterval( () => { day.setHours(day.getHours() + 6); day = new Date(day); @@ -266,6 +268,22 @@ mainSeries = ref; }, } + case 'Baseline': + return { + id: 'main', + type, + data: [...LINE_DATA], + options: { + baseValue: { + type: "price", + price: 38, + }, + }, + priceLines: lines, + reference: (ref: ISeriesApi<'Baseline'> | null) => { + mainSeries = ref; + } + } default: throw new Error(); } @@ -361,7 +379,7 @@
Main Series type: - {#each SERIES_TYPES as type (type) } + {#each SERIES_TYPES as type (type)} @@ -452,6 +470,17 @@ {/each} {/if} + {#if mainProps.type === 'Baseline'} + + {#each lines as line (line.id)} + + {/each} + + {/if} {#if showVolume} {#key volumeProps.id} SERIES_API), addHistogramSeries: jest.fn(() => SERIES_API), addLineSeries: jest.fn(() => SERIES_API), + addBaselineSeries: jest.fn(() => SERIES_API), removeSeries: jest.fn(), } @@ -25,6 +26,7 @@ describe.each([ ['Candlestick', 'candlestick-series', 'addCandlestickSeries'], ['Histogram', 'histogram-series', 'addHistogramSeries'], ['Line', 'line-series', 'addLineSeries'], + ['Baseline', 'baseline-series', 'addBaselineSeries'], ])('%sSeries component', (type: SeriesType, name: string, method: keyof typeof CHART_API) => { beforeAll(() => { SERIES_API.seriesType = jest.fn(() => type); diff --git a/src/package/components/baseline-series.interface.ts b/src/package/components/baseline-series.interface.ts new file mode 100644 index 0000000..2a7983f --- /dev/null +++ b/src/package/components/baseline-series.interface.ts @@ -0,0 +1,16 @@ +import type { + BaselineSeriesPartialOptions, + ISeriesApi, + SeriesDataItemTypeMap +} from 'lightweight-charts'; +import type {Reference} from '../types'; + +export interface $$PROPS extends BaselineSeriesPartialOptions { + ref?: Reference>; + data: SeriesDataItemTypeMap['Baseline'][]; +} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface $$EVENTS { + +} diff --git a/src/package/components/baseline-series.svelte b/src/package/components/baseline-series.svelte new file mode 100644 index 0000000..5b4f703 --- /dev/null +++ b/src/package/components/baseline-series.svelte @@ -0,0 +1,163 @@ + + + +{#if reference !== null} + + + +{/if} diff --git a/src/package/internal/series.ts b/src/package/internal/series.ts index fbeabce..0f1e368 100644 --- a/src/package/internal/series.ts +++ b/src/package/internal/series.ts @@ -85,5 +85,10 @@ function createSeries( series.setData(params.data); return series; } + case 'Baseline': { + const series = chart.addBaselineSeries(params.options); + series.setData(params.data); + return series; + } } } diff --git a/src/package/types.ts b/src/package/types.ts index b6ece11..5660ff5 100644 --- a/src/package/types.ts +++ b/src/package/types.ts @@ -69,12 +69,22 @@ export interface LineSeriesParams { priceLines?: PriceLineParams[]; } +export type BaselineSeriesParams = 'Baseline' extends SeriesType ? { + id: string; + type: 'Baseline'; + options?: SeriesPartialOptionsMap['Baseline']; + data: SeriesDataItemTypeMap['Baseline'][]; + reference?: Reference>; + priceLines?: PriceLineParams[]; +} : never; + export type SeriesActionParams = | AreaSeriesParams | BarSeriesParams | CandlestickSeriesParams | HistogramSeriesParams | LineSeriesParams + | BaselineSeriesParams export interface SeriesParamsMap extends Record { Area: AreaSeriesParams; @@ -82,6 +92,7 @@ export interface SeriesParamsMap extends Record { Candlestick: CandlestickSeriesParams; Histogram: HistogramSeriesParams; Line: LineSeriesParams; + Baseline: BaselineSeriesParams; } export type Reference = (ref: T | null) => void;