Skip to content
Open
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
33 changes: 33 additions & 0 deletions __tests__/charts/simple-spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import ReactECharts from '../../src/';
import type { EChartsOption } from '../../src/';
import type { Opts } from '../../src/types';
import { render, destroy, createDiv, removeDom } from '../utils';

const options: EChartsOption = {
Expand Down Expand Up @@ -199,6 +200,38 @@ describe('chart', () => {

removeDom(div);
});

it('every echarts init option', () => {
let instance;
const div = createDiv();
div.style.display = 'block';
div.style.width = '1200px';
div.style.height = '720px';

const opts: Opts = {
renderer: 'svg',
devicePixelRatio: 2,
useDirtyRect: false,
useCoarsePointer: true,
pointerSize: 30,
ssr: false,
width: '400px',
height: '150px',
locale: 'EN',
};

const Comp = <ReactECharts ref={(e) => (instance = e)} option={options} opts={opts} />;
render(Comp, div);

expect(instance.getEchartsInstance().getWidth()).toBe(400);
expect(instance.getEchartsInstance().getHeight()).toBe(150);
expect(div.querySelector('svg')).not.toBe(null);

destroy(div);
expect(div.querySelector('*')).toBe(null);

removeDom(div);
});
});
});

Expand Down
13 changes: 10 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ export type EChartsOption = any;

export type EChartsInstance = EChartsType;

/**
* echarts init opts, see https://echarts.apache.org/en/api.html#echarts.init
*/
export type Opts = {
readonly devicePixelRatio?: number;
readonly renderer?: 'canvas' | 'svg';
readonly width?: number | null | undefined | 'auto';
readonly height?: number | null | undefined | 'auto';
readonly locale?: string;
readonly useDirtyRect?: boolean;
readonly useCoarsePointer?: boolean;
readonly pointerSize?: number;
readonly ssr?: boolean;
readonly width?: number | string | null | undefined;
readonly height?: number | string | null | undefined;
readonly locale?: string | Record<string, any>;
};

export type EChartsReactProps = React.HTMLAttributes<HTMLDivElement> & {
Expand Down
Loading