Skip to content

Commit ee02ea3

Browse files
committed
feat(charts): add Sankey chart
1 parent fc874c9 commit ee02ea3

File tree

73 files changed

+3392
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3392
-31
lines changed

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const config: Config = {
1919
'^.+\\.m?[jt]sx?$': 'babel-jest',
2020
'^.+\\.svg$': 'jest-transform-stub'
2121
},
22-
setupFilesAfterEnv: ['<rootDir>/packages/testSetup.ts'],
22+
setupFilesAfterEnv: ['<rootDir>/packages/testSetup.ts', 'jest-canvas-mock'],
2323
testPathIgnorePatterns: ['<rootDir>/packages/react-integration/'],
24-
transformIgnorePatterns: ['node_modules/victory-*/', '/node_modules/(?!(case-anything)/)'],
24+
transformIgnorePatterns: ['/node_modules/victory-*/', '/node_modules/(?!(chart\\.js|echarts|zrender)).*\\.js$'],
2525
coveragePathIgnorePatterns: ['/dist/'],
2626
moduleNameMapper: {
2727
'\\.(css|less)$': '<rootDir>/packages/react-styles/__mocks__/styleMock.js'

packages/react-charts/package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"types": "dist/esm/index.d.ts",
88
"typesVersions": {
99
"*": {
10+
"echarts": [
11+
"dist/esm/echarts/index.d.ts"
12+
],
1013
"victory": [
1114
"dist/esm/victory/index.d.ts"
1215
]
@@ -42,7 +45,13 @@
4245
"lodash": "^4.17.21",
4346
"tslib": "^2.8.1"
4447
},
48+
"devDependencies": {
49+
"@types/lodash": "^4.17.15",
50+
"fs-extra": "^11.3.0",
51+
"jest-canvas-mock": "^2.5.2"
52+
},
4553
"peerDependencies": {
54+
"echarts": "^5.6.0",
4655
"react": "^17 || ^18",
4756
"react-dom": "^17 || ^18",
4857
"victory-area": "^37.3.6",
@@ -64,6 +73,9 @@
6473
"victory-zoom-container": "^37.3.6"
6574
},
6675
"peerDependenciesMeta": {
76+
"echarts": {
77+
"optional": true
78+
},
6779
"victory-area": {
6880
"optional": true
6981
},
@@ -120,9 +132,5 @@
120132
"clean": "rimraf dist echarts victory",
121133
"build:single:packages": "node ../../scripts/build-single-packages.mjs --config single-packages.config.json",
122134
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
123-
},
124-
"devDependencies": {
125-
"@types/lodash": "^4.17.15",
126-
"fs-extra": "^11.3.0"
127135
}
128136
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"packageName": "@patternfly/react-charts",
3-
"exclude": ["dist/esm/deprecated/index.js", "dist/esm/next/index.js"]
3+
"exclude": ["dist/esm/deprecated/index.js"]
44
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const echarts: any = jest.createMockFromModule('echarts');
2+
echarts.init = jest.fn(() => ({
3+
setOption: jest.fn(),
4+
dispose: jest.fn()
5+
}));
6+
module.exports = echarts;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import defaultsDeep from 'lodash/defaultsDeep';
2+
3+
import { ThemeDefinition } from '../../themes/Theme';
4+
5+
export const getLineSeries = (serie: any, theme: ThemeDefinition, isSkeleton: boolean) => {
6+
const defaults = {
7+
emphasis: {
8+
...(isSkeleton ? { disabled: true } : { focus: 'adjacency' })
9+
},
10+
type: 'line'
11+
};
12+
return defaultsDeep(serie, defaults);
13+
};
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import React from 'react';
2+
import { setupJestCanvasMock } from 'jest-canvas-mock';
3+
import { render, screen } from '@testing-library/react';
4+
import { PatternflyECharts } from '@patternfly/react-charts/echarts';
5+
6+
import * as echarts from 'echarts/core';
7+
import { LineChart } from 'echarts/charts';
8+
import { GridComponent, TitleComponent, TooltipComponent } from 'echarts/components';
9+
import { SVGRenderer } from 'echarts/renderers';
10+
11+
// Register required components
12+
echarts.use([GridComponent, LineChart, SVGRenderer, TitleComponent, TooltipComponent]);
13+
14+
beforeEach(() => {
15+
jest.resetAllMocks();
16+
jest.mock('echarts');
17+
setupJestCanvasMock();
18+
});
19+
20+
const props: any = {
21+
height: 400,
22+
id: 'line-chart',
23+
option: {
24+
xAxis: {
25+
type: 'category',
26+
data: ['2015', '2016', '2017', '2018']
27+
},
28+
yAxis: {
29+
axisLabel: {
30+
formatter: (value) => (value !== 0 ? `${value}` : '')
31+
},
32+
splitNumber: 3,
33+
type: 'value'
34+
},
35+
series: [
36+
{
37+
data: [1, 2, 5, 3],
38+
name: 'Cats',
39+
type: 'line'
40+
},
41+
{
42+
data: [2, 1, 7, 4],
43+
name: 'Dogs',
44+
lineStyle: {
45+
type: 'dashed'
46+
},
47+
type: 'line'
48+
},
49+
{
50+
data: [3, 4, 9, 5],
51+
name: 'Birds',
52+
type: 'line'
53+
},
54+
{
55+
data: [3, 3, 8, 7],
56+
name: 'Mice',
57+
type: 'line'
58+
}
59+
],
60+
title: {
61+
text: 'This is a Line chart'
62+
}
63+
},
64+
width: 800
65+
};
66+
67+
// Remove dynamic _echarts_instance_ ID
68+
const removeInstanceID = (fragment) => {
69+
fragment.getElementById('line-chart').removeAttribute('_echarts_instance_');
70+
return fragment;
71+
};
72+
73+
test('renders component', () => {
74+
const { asFragment } = render(<PatternflyECharts {...props} />);
75+
expect(removeInstanceID(asFragment())).toMatchSnapshot();
76+
});
77+
78+
test('renders title', async () => {
79+
render(<PatternflyECharts {...props} />);
80+
81+
const title = await screen.findByText(props.option.title.text);
82+
expect(title).toMatchSnapshot();
83+
});
84+
85+
test('renders height and width', async () => {
86+
const { asFragment } = render(<PatternflyECharts {...props} />);
87+
88+
const svg = asFragment().querySelector('svg');
89+
expect(svg).toHaveAttribute('height', `${props.height}`);
90+
expect(svg).toHaveAttribute('width', `${props.width}`);
91+
});

0 commit comments

Comments
 (0)