Skip to content

Commit

Permalink
Feature/47 update all chart snapshots (#48)
Browse files Browse the repository at this point in the history
* [#47] Refactoring useEcharts hooks to support unit tests

* [#47] Implements latest useEcharts in Bar chart

* [#47] Update Bar chart snapshot test

* [#47] Implements latest useEcharts in Doughnut chart

* [#47] Update Doughnut chart snapshot test

s

* [#47] Implements latest useEcharts in Line chart

* [#47] Update Line chart snapshot test

* [#47] Implements latest useEcharts in Pie chart

* [#47] Update Pie chart snapshot test

* [#47] Implements latest useEcharts in ScatterPlot chart

* [#47] Update ScatterPlot snapshot test

* [#47] Implements latest useEcharts in StackBar chart

* [#47] Update SnackBar chart snapshot test

* [#47] Implements latest useEcharts in StackClusterColumn chart

* [#47] Update StackClusterColumn chart snapshot test

* [#47] Implements latest useEcharts in StackLine chart

* [#47] Update StackLine chart snapshot test

* [#47] Update dist: implements latest useEcharts to support unit tests
  • Loading branch information
ifirmawan authored Sep 12, 2024
1 parent 0c5596c commit 19a8888
Show file tree
Hide file tree
Showing 30 changed files with 1,977 additions and 740 deletions.
499 changes: 274 additions & 225 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

487 changes: 268 additions & 219 deletions dist/index.modern.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.modern.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/components/Bar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand All @@ -22,8 +22,8 @@ const getOptions = ({
};
};

const Bar = ({ config, data, rawConfig }) => {
const chartRef = useECharts({
const Bar = ({ config, data, rawConfig }, ref) => {
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'bar'
},
Expand All @@ -34,6 +34,8 @@ const Bar = ({ config, data, rawConfig }) => {
getOptions({ horizontal, dimensions, overrideItemStyle })
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -43,4 +45,4 @@ const Bar = ({ config, data, rawConfig }) => {
);
};

export default Bar;
export default forwardRef(Bar);
10 changes: 6 additions & 4 deletions src/components/Doughnut.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { forwardRef, useImperativeHandle, useMemo } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand All @@ -22,15 +22,15 @@ const getOptions = ({ dimensions = [], radius, overrideItemStyle }) => {
};
};

const Doughnut = ({ config, data, size = 40, rawConfig }) => {
const Doughnut = ({ config, data, size = 40, rawConfig }, ref) => {
const torus = useMemo(() => {
if (size >= MAX) {
return 0;
}
return MAX - size;
}, [size]);

const chartRef = useECharts({
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'pie',
radius: [`${torus}%`, `${MAX}%`]
Expand All @@ -46,6 +46,8 @@ const Doughnut = ({ config, data, size = 40, rawConfig }) => {
})
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -55,4 +57,4 @@ const Doughnut = ({ config, data, size = 40, rawConfig }) => {
);
};

export default Doughnut;
export default forwardRef(Doughnut);
10 changes: 6 additions & 4 deletions src/components/Line.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand All @@ -22,8 +22,8 @@ const getOptions = ({
};
};

const Line = ({ config, data, rawConfig }) => {
const chartRef = useECharts({
const Line = ({ config, data, rawConfig }, ref) => {
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'line'
},
Expand All @@ -34,6 +34,8 @@ const Line = ({ config, data, rawConfig }) => {
getOptions({ horizontal, dimensions, overrideItemStyle })
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -43,4 +45,4 @@ const Line = ({ config, data, rawConfig }) => {
);
};

export default Line;
export default forwardRef(Line);
10 changes: 6 additions & 4 deletions src/components/Pie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand All @@ -20,8 +20,8 @@ const getOptions = ({ dimensions = [], overrideItemStyle }) => {
};
};

const Pie = ({ config, data, rawConfig }) => {
const chartRef = useECharts({
const Pie = ({ config, data, rawConfig }, ref) => {
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'pie'
},
Expand All @@ -32,6 +32,8 @@ const Pie = ({ config, data, rawConfig }) => {
getOptions({ dimensions, overrideItemStyle })
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -41,4 +43,4 @@ const Pie = ({ config, data, rawConfig }) => {
);
};

export default Pie;
export default forwardRef(Pie);
19 changes: 9 additions & 10 deletions src/components/ScatterPlot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand Down Expand Up @@ -59,14 +59,11 @@ const getOptions = ({
};
};

const ScatterPlot = ({
config,
data,
symbolSize = 10,
showLabel = true,
rawConfig
}) => {
const chartRef = useECharts({
const ScatterPlot = (
{ config, data, symbolSize = 10, showLabel = true, rawConfig },
ref
) => {
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'scatter'
},
Expand All @@ -82,6 +79,8 @@ const ScatterPlot = ({
})
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -91,4 +90,4 @@ const ScatterPlot = ({
);
};

export default ScatterPlot;
export default forwardRef(ScatterPlot);
10 changes: 6 additions & 4 deletions src/components/StackBar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand Down Expand Up @@ -38,8 +38,8 @@ const getOptions = ({
};
};

const StackBar = ({ config, data, stackMapping = {}, rawConfig }) => {
const chartRef = useECharts({
const StackBar = ({ config, data, stackMapping = {}, rawConfig }, ref) => {
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'bar',
stack: 'defaultStack'
Expand All @@ -62,6 +62,8 @@ const StackBar = ({ config, data, stackMapping = {}, rawConfig }) => {
})
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -71,4 +73,4 @@ const StackBar = ({ config, data, stackMapping = {}, rawConfig }) => {
);
};

export default StackBar;
export default forwardRef(StackBar);
10 changes: 6 additions & 4 deletions src/components/StackClusterColumn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand Down Expand Up @@ -28,8 +28,8 @@ const getOptions = ({
};
};

const StackClusterColumn = ({ config, data, rawConfig }) => {
const chartRef = useECharts({
const StackClusterColumn = ({ config, data, rawConfig }, ref) => {
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'bar',
barGap: 0
Expand All @@ -51,6 +51,8 @@ const StackClusterColumn = ({ config, data, rawConfig }) => {
})
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -60,4 +62,4 @@ const StackClusterColumn = ({ config, data, rawConfig }) => {
);
};

export default StackClusterColumn;
export default forwardRef(StackClusterColumn);
10 changes: 6 additions & 4 deletions src/components/StackLine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';
import { useECharts } from '../hooks';
import styles from '../styles.module.css';

Expand Down Expand Up @@ -39,8 +39,8 @@ const getOptions = ({
};
};

const StacLine = ({ config, data, rawConfig }) => {
const chartRef = useECharts({
const StacLine = ({ config, data, rawConfig }, ref) => {
const [chartRef, chartInstance] = useECharts({
rawOverrides: {
type: 'line',
stack: 'defaultStack'
Expand All @@ -62,6 +62,8 @@ const StacLine = ({ config, data, rawConfig }) => {
})
});

useImperativeHandle(ref, () => chartInstance);

return (
<div
ref={chartRef}
Expand All @@ -71,4 +73,4 @@ const StacLine = ({ config, data, rawConfig }) => {
);
};

export default StacLine;
export default forwardRef(StacLine);
Loading

0 comments on commit 19a8888

Please sign in to comment.