Skip to content

Commit

Permalink
Fix dashStyle type
Browse files Browse the repository at this point in the history
  • Loading branch information
artemipanchuk committed Dec 25, 2023
1 parent 9c88bd9 commit 081fade
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
10 changes: 6 additions & 4 deletions src/plugins/d3/renderer/hooks/useSeries/prepare-line-series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import merge from 'lodash/merge';
import {
ChartKitWidgetSeries,
ChartKitWidgetSeriesOptions,
DashStyle,
LineSeries,
RectLegendSymbolOptions,
} from '../../../../../types';
Expand Down Expand Up @@ -36,6 +37,10 @@ type PrepareLineSeriesArgs = {
legend: PreparedLegend;
};

function prepareDashStyle(series: LineSeries) {
return series.dashStyle || DashStyle.Solid;
}

function prepareLineLegendSymbol(
series: ChartKitWidgetSeries,
seriesOptions?: ChartKitWidgetSeriesOptions,
Expand Down Expand Up @@ -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;
}, []);
}
2 changes: 1 addition & 1 deletion src/plugins/d3/renderer/hooks/useSeries/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export type PreparedLineSeries = {
};
};
};
dashStyle?: DashStyle;
dashStyle: DashStyle;
} & BasePreparedSeries;

export type PreparedAreaSeries = {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/d3/renderer/hooks/useShapes/line/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,')
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/d3/renderer/hooks/useShapes/line/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export type PreparedLineData = {
hovered: boolean;
active: boolean;
labels: LabelData[];
dashStyle?: DashStyle;
dashStyle: DashStyle;
};
36 changes: 21 additions & 15 deletions src/types/widget-data/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ export type DataLabelRendererData<T = any> = {
data: ChartKitWidgetSeriesData<T>;
};

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 = {
/**
Expand Down Expand Up @@ -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.
Expand All @@ -205,8 +214,5 @@ export type ChartKitWidgetSeriesOptions = {
};
/** Options for the point markers of line series */
marker?: LineMarkerOptions;

/** Options for line style */
dashStyle?: DashStyle;
};
};

0 comments on commit 081fade

Please sign in to comment.