From 081fade06ef634478ac2087c501bcd42c0535e52 Mon Sep 17 00:00:00 2001 From: Artem Panchuk Date: Mon, 25 Dec 2023 12:37:01 +0300 Subject: [PATCH] Fix dashStyle type --- .../hooks/useSeries/prepare-line-series.ts | 10 +++--- .../d3/renderer/hooks/useSeries/types.ts | 2 +- .../renderer/hooks/useShapes/line/index.tsx | 4 +-- .../d3/renderer/hooks/useShapes/line/types.ts | 2 +- src/types/widget-data/series.ts | 36 +++++++++++-------- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/plugins/d3/renderer/hooks/useSeries/prepare-line-series.ts b/src/plugins/d3/renderer/hooks/useSeries/prepare-line-series.ts index 27f9b772..f7ab69fb 100644 --- a/src/plugins/d3/renderer/hooks/useSeries/prepare-line-series.ts +++ b/src/plugins/d3/renderer/hooks/useSeries/prepare-line-series.ts @@ -5,6 +5,7 @@ import merge from 'lodash/merge'; import { ChartKitWidgetSeries, ChartKitWidgetSeriesOptions, + DashStyle, LineSeries, RectLegendSymbolOptions, } from '../../../../../types'; @@ -36,6 +37,10 @@ type PrepareLineSeriesArgs = { legend: PreparedLegend; }; +function prepareDashStyle(series: LineSeries) { + return series.dashStyle || DashStyle.Solid; +} + function prepareLineLegendSymbol( series: ChartKitWidgetSeries, seriesOptions?: ChartKitWidgetSeriesOptions, @@ -103,12 +108,9 @@ export function prepareLineSeries(args: PrepareLineSeriesArgs) { allowOverlap: get(series, 'dataLabels.allowOverlap', false), }, marker: prepareMarker(series, seriesOptions), + dashStyle: prepareDashStyle(series), }; - if (series.dashStyle) { - prepared.dashStyle = series.dashStyle; - } - return prepared; }, []); } diff --git a/src/plugins/d3/renderer/hooks/useSeries/types.ts b/src/plugins/d3/renderer/hooks/useSeries/types.ts index 9a24cd0b..0eabdaf0 100644 --- a/src/plugins/d3/renderer/hooks/useSeries/types.ts +++ b/src/plugins/d3/renderer/hooks/useSeries/types.ts @@ -156,7 +156,7 @@ export type PreparedLineSeries = { }; }; }; - dashStyle?: DashStyle; + dashStyle: DashStyle; } & BasePreparedSeries; export type PreparedAreaSeries = { diff --git a/src/plugins/d3/renderer/hooks/useShapes/line/index.tsx b/src/plugins/d3/renderer/hooks/useShapes/line/index.tsx index 62503463..53697e36 100644 --- a/src/plugins/d3/renderer/hooks/useShapes/line/index.tsx +++ b/src/plugins/d3/renderer/hooks/useShapes/line/index.tsx @@ -48,8 +48,8 @@ function getMarkerSymbol(type: string, radius: number) { } } -const getLineDashArray = (dashStyle: DashStyle = 'Solid', strokeWidth = 2) => { - const value = dashStyle && dashStyle.toLowerCase(); +const getLineDashArray = (dashStyle: DashStyle, strokeWidth = 2) => { + const value = dashStyle.toLowerCase(); const arrayValue = value .replace('shortdashdotdot', '3,1,1,1,1,1,') diff --git a/src/plugins/d3/renderer/hooks/useShapes/line/types.ts b/src/plugins/d3/renderer/hooks/useShapes/line/types.ts index 9397d1fc..5a79d10a 100644 --- a/src/plugins/d3/renderer/hooks/useShapes/line/types.ts +++ b/src/plugins/d3/renderer/hooks/useShapes/line/types.ts @@ -25,5 +25,5 @@ export type PreparedLineData = { hovered: boolean; active: boolean; labels: LabelData[]; - dashStyle?: DashStyle; + dashStyle: DashStyle; }; diff --git a/src/types/widget-data/series.ts b/src/types/widget-data/series.ts index 32981c19..95ecfc00 100644 --- a/src/types/widget-data/series.ts +++ b/src/types/widget-data/series.ts @@ -27,18 +27,21 @@ export type DataLabelRendererData = { data: ChartKitWidgetSeriesData; }; -export type DashStyle = - | 'Dash' - | 'DashDot' - | 'Dot' - | 'LongDash' - | 'LongDashDot' - | 'LongDashDotDot' - | 'ShortDash' - | 'ShortDashDot' - | 'ShortDashDotDot' - | 'ShortDot' - | 'Solid'; +export enum DashStyle { + Dash = 'Dash', + DashDot = 'DashDot', + Dot = 'Dot', + LongDash = 'LongDash', + LongDashDot = 'LongDashDot', + LongDashDotDot = 'LongDashDotDot', + ShortDash = 'ShortDash', + ShortDashDot = 'ShortDashDot', + ShortDashDotDot = 'ShortDashDotDot', + ShortDot = 'ShortDot', + Solid = 'Solid', +} + +export enum LineCap {} type BasicHoverState = { /** @@ -186,6 +189,12 @@ export type ChartKitWidgetSeriesOptions = { }; /** Options for the point markers of line series */ marker?: LineMarkerOptions; + + /** Options for line style + * + * @default 'Solid' + * */ + dashStyle?: DashStyle; }; area?: { /** Pixel width of the graph line. @@ -205,8 +214,5 @@ export type ChartKitWidgetSeriesOptions = { }; /** Options for the point markers of line series */ marker?: LineMarkerOptions; - - /** Options for line style */ - dashStyle?: DashStyle; }; };