Skip to content

Commit b58426c

Browse files
committed
feat: add ResponsiveOptions type helper, add generic type to Svg#getNode method
1 parent 4f4bb29 commit b58426c

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"@types/faker": "^5.5.8",
9898
"@types/jest": "^27.5.1",
9999
"@types/node": "^17.0.34",
100+
"@types/testing-library__jest-dom": "^5.14.5",
100101
"@typescript-eslint/eslint-plugin": "^5.25.0",
101102
"@typescript-eslint/parser": "^5.25.0",
102103
"browserslist": "^4.20.2",

pnpm-lock.yaml

Lines changed: 7 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/charts/BarChart/BarChart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
BarDrawEvent,
88
BarChartEventsTypes
99
} from './BarChart.types';
10-
import type { NormalizedSeries } from '../../core';
10+
import type { NormalizedSeries, ResponsiveOptions } from '../../core';
1111
import {
1212
isNumeric,
1313
noop,
@@ -180,7 +180,7 @@ export class BarChart extends BaseChart<BarChartEventsTypes> {
180180
query: string | Element | null,
181181
protected override data: BarChartData,
182182
options?: BarChartOptions,
183-
responsiveOptions?: [string, BarChartOptions][]
183+
responsiveOptions?: ResponsiveOptions<BarChartOptions>
184184
) {
185185
super(
186186
query,

src/charts/BaseChart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Data, Options, DataEvent } from '../core';
1+
import type { Data, Options, DataEvent, ResponsiveOptions } from '../core';
22
import type { Svg } from '../svg';
33
import type { BaseChartEventsTypes } from './types';
44
import { OptionsProvider, optionsProvider } from '../core';
@@ -25,7 +25,7 @@ export abstract class BaseChart<TEventsTypes = BaseChartEventsTypes> {
2525
protected data: Data,
2626
private readonly defaultOptions: Options,
2727
private options: Options,
28-
private readonly responsiveOptions?: [string, Options][]
28+
private readonly responsiveOptions?: ResponsiveOptions<Options>
2929
) {
3030
const container =
3131
typeof query === 'string' ? document.querySelector(query) : query;

src/charts/LineChart/LineChart.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import type {
99
AreaDrawEvent,
1010
LineChartEventsTypes
1111
} from './LineChart.types';
12-
import type { SegmentData, Series, SeriesObject } from '../../core';
12+
import type {
13+
SegmentData,
14+
Series,
15+
SeriesObject,
16+
ResponsiveOptions
17+
} from '../../core';
1318
import {
1419
alphaNumerate,
1520
normalizeData,
@@ -228,7 +233,7 @@ export class LineChart extends BaseChart<LineChartEventsTypes> {
228233
query: string | Element | null,
229234
protected override data: LineChartData,
230235
options?: LineChartOptions,
231-
responsiveOptions?: [string, LineChartOptions][]
236+
responsiveOptions?: ResponsiveOptions<LineChartOptions>
232237
) {
233238
super(
234239
query,

src/charts/PieChart/PieChart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
PieChartEventsTypes
1212
} from './PieChart.types';
1313
import type { Svg } from '../../svg';
14+
import type { ResponsiveOptions } from '../../core';
1415
import {
1516
alphaNumerate,
1617
quantity,
@@ -169,7 +170,7 @@ export class PieChart extends BaseChart<PieChartEventsTypes> {
169170
query: string | Element | null,
170171
protected override data: PieChartData,
171172
options?: PieChartOptions,
172-
responsiveOptions?: [string, PieChartOptions][]
173+
responsiveOptions?: ResponsiveOptions<PieChartOptions>
173174
) {
174175
super(
175176
query,

src/core/optionsProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { EventEmitter } from '../event';
2-
import type { OptionsChangedEvent } from './types';
2+
import type { OptionsChangedEvent, ResponsiveOptions } from './types';
33
import { extend } from '../utils';
44

55
export interface OptionsProvider<T = unknown> {
@@ -16,7 +16,7 @@ export interface OptionsProvider<T = unknown> {
1616
*/
1717
export function optionsProvider<T = unknown>(
1818
options: T,
19-
responsiveOptions: [string, T][] | undefined,
19+
responsiveOptions: ResponsiveOptions<T> | undefined,
2020
eventEmitter: EventEmitter
2121
): OptionsProvider<T> {
2222
let currentOptions: T;

src/core/types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export type OptionsWithDefaults = RequiredKeys<
8181
'axisX' | 'axisY' | 'classNames'
8282
>;
8383

84+
export type ResponsiveOptions<T = Options> = [string, T][];
85+
8486
export interface Bounds {
8587
high: number;
8688
low: number;
@@ -109,14 +111,14 @@ export type AxisName = 'x' | 'y';
109111

110112
export type Multi =
111113
| {
112-
x: number | string | null;
113-
y: number | string | null;
114+
x: number | string | Date | null;
115+
y: number | string | Date | null;
114116
}
115117
| {
116-
x: number | string | null;
118+
x: number | string | Date | null;
117119
}
118120
| {
119-
y: number | string | null;
121+
y: number | string | Date | null;
120122
};
121123

122124
export type NormalizedMulti =

src/svg/Svg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ export class Svg {
167167
/**
168168
* Returns the underlying SVG node for the current element.
169169
*/
170-
getNode() {
171-
return this._node;
170+
getNode<T extends Element = Element>() {
171+
return this._node as T;
172172
}
173173

174174
/**

0 commit comments

Comments
 (0)