From 7dd3ba2992751976bfdff9603021afa8fad140d8 Mon Sep 17 00:00:00 2001 From: Dan Onoshko Date: Sat, 13 Aug 2022 18:51:44 +0400 Subject: [PATCH] feat: add ResponsiveOptions type helper, add generic type to Svg#getNode method (#1347) --- package.json | 1 + pnpm-lock.yaml | 23 +++++++---------------- src/charts/BarChart/BarChart.ts | 4 ++-- src/charts/BaseChart.ts | 4 ++-- src/charts/LineChart/LineChart.ts | 9 +++++++-- src/charts/PieChart/PieChart.ts | 3 ++- src/core/optionsProvider.ts | 4 ++-- src/core/types.ts | 2 ++ src/svg/Svg.ts | 4 ++-- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index b11a2f4f..49256f3d 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "@types/faker": "^5.5.8", "@types/jest": "^27.5.1", "@types/node": "^17.0.34", + "@types/testing-library__jest-dom": "^5.14.5", "@typescript-eslint/eslint-plugin": "^5.25.0", "@typescript-eslint/parser": "^5.25.0", "browserslist": "^4.20.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 773f3769..83a3d6c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,6 +22,7 @@ specifiers: '@types/faker': ^5.5.8 '@types/jest': ^27.5.1 '@types/node': ^17.0.34 + '@types/testing-library__jest-dom': ^5.14.5 '@typescript-eslint/eslint-plugin': ^5.25.0 '@typescript-eslint/parser': ^5.25.0 browserslist: ^4.20.2 @@ -81,6 +82,7 @@ devDependencies: '@types/faker': 5.5.9 '@types/jest': 27.5.1 '@types/node': 17.0.34 + '@types/testing-library__jest-dom': 5.14.5 '@typescript-eslint/eslint-plugin': 5.25.0_qo2hgs5jt7x2a3p77h2rutcdae '@typescript-eslint/parser': 5.25.0_hcfsmds2fshutdssjqluwm76uu browserslist: 4.20.2 @@ -4525,7 +4527,7 @@ packages: engines: {node: '>=8', npm: '>=6', yarn: '>=1'} dependencies: '@babel/runtime': 7.17.9 - '@types/testing-library__jest-dom': 5.14.3 + '@types/testing-library__jest-dom': 5.14.5 aria-query: 5.0.0 chalk: 3.0.0 css: 3.0.0 @@ -4815,8 +4817,8 @@ packages: resolution: {integrity: sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ==} dev: true - /@types/testing-library__jest-dom/5.14.3: - resolution: {integrity: sha512-oKZe+Mf4ioWlMuzVBaXQ9WDnEm1+umLx0InILg+yvZVBBDmzV5KfZyLrCvadtWcx8+916jLmHafcmqqffl+iIw==} + /@types/testing-library__jest-dom/5.14.5: + resolution: {integrity: sha512-SBwbxYoyPIvxHbeHxTZX2Pe/74F/tX2/D3mMvzabdeJ25bBojfW0TyB8BHrbq/9zaaKICJZjLP+8r6AeZMFCuQ==} dependencies: '@types/jest': 27.5.1 dev: true @@ -6270,7 +6272,7 @@ packages: mississippi: 3.0.0 mkdirp: 0.5.6 move-concurrently: 1.0.1 - promise-inflight: 1.0.1_bluebird@3.7.2 + promise-inflight: 1.0.1 rimraf: 2.7.1 ssri: 6.0.2 unique-filename: 1.1.1 @@ -7041,8 +7043,8 @@ packages: engines: {node: '>=10'} hasBin: true dependencies: - JSONStream: 1.3.5 is-text-path: 1.0.1 + JSONStream: 1.3.5 lodash: 4.17.21 meow: 8.1.2 split2: 3.2.2 @@ -13500,17 +13502,6 @@ packages: optional: true dev: true - /promise-inflight/1.0.1_bluebird@3.7.2: - resolution: {integrity: sha1-mEcocL8igTL8vdhoEputEsPAKeM=} - peerDependencies: - bluebird: '*' - peerDependenciesMeta: - bluebird: - optional: true - dependencies: - bluebird: 3.7.2 - dev: true - /promise.allsettled/1.0.5: resolution: {integrity: sha512-tVDqeZPoBC0SlzJHzWGZ2NKAguVq2oiYj7gbggbiTvH2itHohijTp7njOUA0aQ/nl+0lr/r6egmhoYu63UZ/pQ==} engines: {node: '>= 0.4'} diff --git a/src/charts/BarChart/BarChart.ts b/src/charts/BarChart/BarChart.ts index 927d79bb..c33b70db 100644 --- a/src/charts/BarChart/BarChart.ts +++ b/src/charts/BarChart/BarChart.ts @@ -7,7 +7,7 @@ import type { BarDrawEvent, BarChartEventsTypes } from './BarChart.types'; -import type { NormalizedSeries } from '../../core'; +import type { NormalizedSeries, ResponsiveOptions } from '../../core'; import { isNumeric, noop, @@ -180,7 +180,7 @@ export class BarChart extends BaseChart { query: string | Element | null, protected override data: BarChartData, options?: BarChartOptions, - responsiveOptions?: [string, BarChartOptions][] + responsiveOptions?: ResponsiveOptions ) { super( query, diff --git a/src/charts/BaseChart.ts b/src/charts/BaseChart.ts index 95f782e3..3d03f3a8 100644 --- a/src/charts/BaseChart.ts +++ b/src/charts/BaseChart.ts @@ -1,4 +1,4 @@ -import type { Data, Options, DataEvent } from '../core'; +import type { Data, Options, DataEvent, ResponsiveOptions } from '../core'; import type { Svg } from '../svg'; import type { BaseChartEventsTypes } from './types'; import { OptionsProvider, optionsProvider } from '../core'; @@ -25,7 +25,7 @@ export abstract class BaseChart { protected data: Data, private readonly defaultOptions: Options, private options: Options, - private readonly responsiveOptions?: [string, Options][] + private readonly responsiveOptions?: ResponsiveOptions ) { const container = typeof query === 'string' ? document.querySelector(query) : query; diff --git a/src/charts/LineChart/LineChart.ts b/src/charts/LineChart/LineChart.ts index ef8d4301..2459e5e1 100644 --- a/src/charts/LineChart/LineChart.ts +++ b/src/charts/LineChart/LineChart.ts @@ -9,7 +9,12 @@ import type { AreaDrawEvent, LineChartEventsTypes } from './LineChart.types'; -import type { SegmentData, Series, SeriesObject } from '../../core'; +import type { + SegmentData, + Series, + SeriesObject, + ResponsiveOptions +} from '../../core'; import { alphaNumerate, normalizeData, @@ -228,7 +233,7 @@ export class LineChart extends BaseChart { query: string | Element | null, protected override data: LineChartData, options?: LineChartOptions, - responsiveOptions?: [string, LineChartOptions][] + responsiveOptions?: ResponsiveOptions ) { super( query, diff --git a/src/charts/PieChart/PieChart.ts b/src/charts/PieChart/PieChart.ts index c2047a7d..cbcde742 100644 --- a/src/charts/PieChart/PieChart.ts +++ b/src/charts/PieChart/PieChart.ts @@ -11,6 +11,7 @@ import type { PieChartEventsTypes } from './PieChart.types'; import type { Svg } from '../../svg'; +import type { ResponsiveOptions } from '../../core'; import { alphaNumerate, quantity, @@ -169,7 +170,7 @@ export class PieChart extends BaseChart { query: string | Element | null, protected override data: PieChartData, options?: PieChartOptions, - responsiveOptions?: [string, PieChartOptions][] + responsiveOptions?: ResponsiveOptions ) { super( query, diff --git a/src/core/optionsProvider.ts b/src/core/optionsProvider.ts index bfc1060a..23d0e8dc 100644 --- a/src/core/optionsProvider.ts +++ b/src/core/optionsProvider.ts @@ -1,5 +1,5 @@ import type { EventEmitter } from '../event'; -import type { OptionsChangedEvent } from './types'; +import type { OptionsChangedEvent, ResponsiveOptions } from './types'; import { extend } from '../utils'; export interface OptionsProvider { @@ -16,7 +16,7 @@ export interface OptionsProvider { */ export function optionsProvider( options: T, - responsiveOptions: [string, T][] | undefined, + responsiveOptions: ResponsiveOptions | undefined, eventEmitter: EventEmitter ): OptionsProvider { let currentOptions: T; diff --git a/src/core/types.ts b/src/core/types.ts index ff67081e..8f7639ab 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -81,6 +81,8 @@ export type OptionsWithDefaults = RequiredKeys< 'axisX' | 'axisY' | 'classNames' >; +export type ResponsiveOptions = [string, T][]; + export interface Bounds { high: number; low: number; diff --git a/src/svg/Svg.ts b/src/svg/Svg.ts index d9b9c1c2..f17a9cad 100644 --- a/src/svg/Svg.ts +++ b/src/svg/Svg.ts @@ -167,8 +167,8 @@ export class Svg { /** * Returns the underlying SVG node for the current element. */ - getNode() { - return this._node; + getNode() { + return this._node as T; } /**