diff --git a/src/components/chart/Chart.stories.mdx b/src/components/chart/Chart.stories.mdx index 4063346b..b64c79d2 100644 --- a/src/components/chart/Chart.stories.mdx +++ b/src/components/chart/Chart.stories.mdx @@ -1,7 +1,7 @@ import { Canvas, Meta, Story, ArgsTable, Source } from "@storybook/blocks"; import Chart from "./ChartWrapper"; import ChartWidget from "./ChartWidget"; -import { LineSeries, CandlestickSeries, HistogramSeries } from "./series"; +import { LineSeries, CandlestickSeries, HistogramSeries, AreaSeries } from "./series"; import { getFigmaParameters } from "../../shared/ui/getFigmaParameters"; @@ -84,6 +84,21 @@ export const lineData = [ > + + + diff --git a/src/components/chart/series/AreaSeries.tsx b/src/components/chart/series/AreaSeries.tsx new file mode 100644 index 00000000..8a00ed55 --- /dev/null +++ b/src/components/chart/series/AreaSeries.tsx @@ -0,0 +1,18 @@ +import { ForwardedRef, forwardRef } from "react"; +import SeriesTemplate from "./SeriesTemplate"; +import { SeriesApiRef, SeriesProps } from "./types"; + +const AreaSeriesRenderFunction = ( + { children, ...rest }: SeriesProps<"Area">, + ref: ForwardedRef> +) => { + return ( + + {children} + + ); +}; + +const AreaSeries = forwardRef(AreaSeriesRenderFunction); +AreaSeries.displayName = "AreaSeries"; +export default AreaSeries; diff --git a/src/components/chart/series/index.ts b/src/components/chart/series/index.ts index a7c9a11d..6ef8698e 100644 --- a/src/components/chart/series/index.ts +++ b/src/components/chart/series/index.ts @@ -1,4 +1,5 @@ export { default as LineSeries } from "./LineSeries"; export { default as HistogramSeries } from "./HistogramSeries"; export { default as CandlestickSeries } from "./CandlestickSeries"; +export { default as AreaSeries } from "./AreaSeries"; export * from "./types"; diff --git a/src/components/chart/series/seriesDefaultOptions.ts b/src/components/chart/series/seriesDefaultOptions.ts index f1427fd2..02556501 100644 --- a/src/components/chart/series/seriesDefaultOptions.ts +++ b/src/components/chart/series/seriesDefaultOptions.ts @@ -5,6 +5,7 @@ import type { CandlestickSeriesPartialOptions, LineSeriesPartialOptions, SeriesType, + AreaSeriesPartialOptions, } from "lightweight-charts"; import { COLORS } from "../../../shared"; @@ -42,6 +43,15 @@ const seriesHistogramDefaultOptions: HistogramSeriesPartialOptions = { base: 0, }; +const seriesAreaDefaultOptions: AreaSeriesPartialOptions = { + ...seriesBaseDefaultOptions, + topColor: COLORS.blue300, + bottomColor: "transparent", + lineColor: COLORS.blue300, + lineStyle: 0, + lineWidth: 2, +}; + export const getSeriesDefaultOptions = (type: SeriesType) => { switch (type) { case "Candlestick": @@ -50,6 +60,8 @@ export const getSeriesDefaultOptions = (type: SeriesType) => { return seriesLineDefaultOptions; case "Histogram": return seriesHistogramDefaultOptions; + case "Area": + return seriesAreaDefaultOptions; default: return {}; } diff --git a/src/components/chart/series/types.ts b/src/components/chart/series/types.ts index 4b5c7644..c040000c 100644 --- a/src/components/chart/series/types.ts +++ b/src/components/chart/series/types.ts @@ -8,7 +8,7 @@ import type { } from "lightweight-charts"; import { ReactNode } from "react"; -export type SeriesType = Extract; +export type SeriesType = Extract; export type SeriesParameters = { data: SeriesDataItemTypeMap[T][]; diff --git a/src/components/chart/series/useInitSeries.ts b/src/components/chart/series/useInitSeries.ts index e093a0a5..529e6d20 100644 --- a/src/components/chart/series/useInitSeries.ts +++ b/src/components/chart/series/useInitSeries.ts @@ -101,6 +101,9 @@ const addSeries = (chart: IChartApi, type: T) => { case "Histogram": series = chart.addHistogramSeries(); break; + case "Area": + series = chart.addAreaSeries(); + break; default: throw new Error(`Unknown series type: ${type}`); }