Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ResponsiveOptions type helper, add generic type to Svg#getNode method #1347

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 7 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/charts/BarChart/BarChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -180,7 +180,7 @@ export class BarChart extends BaseChart<BarChartEventsTypes> {
query: string | Element | null,
protected override data: BarChartData,
options?: BarChartOptions,
responsiveOptions?: [string, BarChartOptions][]
responsiveOptions?: ResponsiveOptions<BarChartOptions>
) {
super(
query,
Expand Down
4 changes: 2 additions & 2 deletions src/charts/BaseChart.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -25,7 +25,7 @@ export abstract class BaseChart<TEventsTypes = BaseChartEventsTypes> {
protected data: Data,
private readonly defaultOptions: Options,
private options: Options,
private readonly responsiveOptions?: [string, Options][]
private readonly responsiveOptions?: ResponsiveOptions<Options>
) {
const container =
typeof query === 'string' ? document.querySelector(query) : query;
Expand Down
9 changes: 7 additions & 2 deletions src/charts/LineChart/LineChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -228,7 +233,7 @@ export class LineChart extends BaseChart<LineChartEventsTypes> {
query: string | Element | null,
protected override data: LineChartData,
options?: LineChartOptions,
responsiveOptions?: [string, LineChartOptions][]
responsiveOptions?: ResponsiveOptions<LineChartOptions>
) {
super(
query,
Expand Down
3 changes: 2 additions & 1 deletion src/charts/PieChart/PieChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
PieChartEventsTypes
} from './PieChart.types';
import type { Svg } from '../../svg';
import type { ResponsiveOptions } from '../../core';
import {
alphaNumerate,
quantity,
Expand Down Expand Up @@ -169,7 +170,7 @@ export class PieChart extends BaseChart<PieChartEventsTypes> {
query: string | Element | null,
protected override data: PieChartData,
options?: PieChartOptions,
responsiveOptions?: [string, PieChartOptions][]
responsiveOptions?: ResponsiveOptions<PieChartOptions>
) {
super(
query,
Expand Down
4 changes: 2 additions & 2 deletions src/core/optionsProvider.ts
Original file line number Diff line number Diff line change
@@ -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<T = unknown> {
Expand All @@ -16,7 +16,7 @@ export interface OptionsProvider<T = unknown> {
*/
export function optionsProvider<T = unknown>(
options: T,
responsiveOptions: [string, T][] | undefined,
responsiveOptions: ResponsiveOptions<T> | undefined,
eventEmitter: EventEmitter
): OptionsProvider<T> {
let currentOptions: T;
Expand Down
2 changes: 2 additions & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export type OptionsWithDefaults = RequiredKeys<
'axisX' | 'axisY' | 'classNames'
>;

export type ResponsiveOptions<T = Options> = [string, T][];

export interface Bounds {
high: number;
low: number;
Expand Down
4 changes: 2 additions & 2 deletions src/svg/Svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ export class Svg {
/**
* Returns the underlying SVG node for the current element.
*/
getNode() {
return this._node;
getNode<T extends Element = Element>() {
return this._node as T;
}

/**
Expand Down