Skip to content

Commit

Permalink
refactor(D3 plugin): add dict for widget types (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
korvin89 authored Dec 28, 2023
1 parent 5a8dab7 commit 54633c1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/constants/widget-data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
export const WidgetType = {
Area: 'area',
BarX: 'bar-x',
BarY: 'bar-y',
Line: 'line',
Pie: 'pie',
Scatter: 'scatter',
} as const;

export enum DashStyle {
Dash = 'Dash',
DashDot = 'DashDot',
Expand Down
12 changes: 4 additions & 8 deletions src/plugins/d3/renderer/validation/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';

import {WidgetType} from '../../../../constants';
import {ChartKitError, CHARTKIT_ERROR_CODE} from '../../../../libs';
import {
BarXSeries,
Expand All @@ -12,18 +14,12 @@ import {
ScatterSeries,
} from '../../../../types';
import {i18n} from '../../../../i18n';

import {DEFAULT_AXIS_TYPE} from '../constants';

type XYSeries = ScatterSeries | BarXSeries | BarYSeries | LineSeries;

const AVAILABLE_SERIES_TYPES: ChartKitWidgetSeries['type'][] = [
'area',
'bar-x',
'bar-y',
'line',
'pie',
'scatter',
];
const AVAILABLE_SERIES_TYPES = Object.values(WidgetType);

const validateXYSeries = (args: {
series: XYSeries;
Expand Down
3 changes: 2 additions & 1 deletion src/types/widget-data/area.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {WidgetType} from '../../constants';
import type {BaseSeries, BaseSeriesData} from './base';
import type {ChartKitWidgetLegend, RectLegendSymbolOptions} from './legend';
import type {PointMarkerOptions} from './marker';
Expand Down Expand Up @@ -28,7 +29,7 @@ export type AreaMarkerOptions = PointMarkerOptions & {
};

export type AreaSeries<T = any> = BaseSeries & {
type: 'area';
type: typeof WidgetType.Area;
data: AreaSeriesData<T>[];
/** The name of the series (used in legend, tooltip etc) */
name: string;
Expand Down
3 changes: 2 additions & 1 deletion src/types/widget-data/bar-x.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {WidgetType} from '../../constants';
import type {BaseSeries, BaseSeriesData} from './base';
import type {ChartKitWidgetSeriesOptions} from './series';
import {ChartKitWidgetLegend, RectLegendSymbolOptions} from './legend';
Expand Down Expand Up @@ -28,7 +29,7 @@ export type BarXSeriesData<T = any> = BaseSeriesData<T> & {
};

export type BarXSeries<T = any> = BaseSeries & {
type: 'bar-x';
type: typeof WidgetType.BarX;
data: BarXSeriesData<T>[];
/** The name of the series (used in legend, tooltip etc) */
name: string;
Expand Down
3 changes: 2 additions & 1 deletion src/types/widget-data/bar-y.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {WidgetType} from '../../constants';
import type {BaseSeries, BaseSeriesData} from './base';
import type {ChartKitWidgetSeriesOptions} from './series';
import {ChartKitWidgetLegend, RectLegendSymbolOptions} from './legend';
Expand All @@ -22,7 +23,7 @@ export type BarYSeriesData<T = any> = BaseSeriesData<T> & {
};

export type BarYSeries<T = any> = BaseSeries & {
type: 'bar-y';
type: typeof WidgetType.BarY;
data: BarYSeriesData<T>[];
/** The name of the series (used in legend, tooltip etc) */
name: string;
Expand Down
4 changes: 2 additions & 2 deletions src/types/widget-data/line.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {BaseSeries, BaseSeriesData} from './base';
import type {ChartKitWidgetLegend, RectLegendSymbolOptions} from './legend';
import type {PointMarkerOptions} from './marker';
import {DashStyle, LineCap} from '../../constants';
import {DashStyle, LineCap, WidgetType} from '../../constants';

export type LineSeriesData<T = any> = BaseSeriesData<T> & {
/**
Expand Down Expand Up @@ -29,7 +29,7 @@ export type LineMarkerOptions = PointMarkerOptions & {
};

export type LineSeries<T = any> = BaseSeries & {
type: 'line';
type: typeof WidgetType.Line;
data: LineSeriesData<T>[];
/** The name of the series (used in legend, tooltip etc) */
name: string;
Expand Down
3 changes: 2 additions & 1 deletion src/types/widget-data/pie.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {WidgetType} from '../../constants';
import type {BaseSeries, BaseSeriesData} from './base';
import {ChartKitWidgetLegend, RectLegendSymbolOptions} from './legend';

Expand All @@ -16,7 +17,7 @@ export type ConnectorShape = 'straight-line' | 'polyline';
export type ConnectorCurve = 'linear' | 'basic';

export type PieSeries<T = any> = BaseSeries & {
type: 'pie';
type: typeof WidgetType.Pie;
data: PieSeriesData<T>[];
/**
* The color of the border surrounding each segment.
Expand Down
3 changes: 2 additions & 1 deletion src/types/widget-data/scatter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {WidgetType} from '../../constants';
import type {BaseSeries, BaseSeriesData} from './base';
import type {ChartKitWidgetLegend, RectLegendSymbolOptions} from './legend';

Expand Down Expand Up @@ -26,7 +27,7 @@ export type ScatterSeriesData<T = any> = BaseSeriesData<T> & {
};

export type ScatterSeries<T = any> = BaseSeries & {
type: 'scatter';
type: typeof WidgetType.Scatter;
data: ScatterSeriesData<T>[];
/** The name of the series (used in legend, tooltip etc) */
name: string;
Expand Down

0 comments on commit 54633c1

Please sign in to comment.