@hitachivantara/uikit-react-viz 6.1.5 → 6.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,120 +1,94 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import { BarChart } from "echarts/charts";
4
- import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent, DataZoomSliderComponent, DataZoomInsideComponent, MarkLineComponent } from "echarts/components";
5
- import * as echarts from "echarts/core";
6
- import { useData } from "../hooks/useData.js";
7
- import { useDataset } from "../hooks/useDataset.js";
8
- import { useYAxis } from "../hooks/useYAxis.js";
9
- import { useXAxis } from "../hooks/useXAxis.js";
1
+ import { HvBaseChart } from "../BaseChart/BaseChart.js";
10
2
  import { useDataZoom } from "../hooks/useDataZoom.js";
3
+ import { useXAxis } from "../hooks/useXAxis.js";
4
+ import { useYAxis } from "../hooks/useYAxis.js";
11
5
  import { useGrid } from "../hooks/useGrid.js";
6
+ import { useData } from "../hooks/useData.js";
7
+ import { useDataset } from "../hooks/useDataset.js";
12
8
  import { useSeries } from "../hooks/useSeries.js";
13
9
  import { useLegend } from "../hooks/useLegend.js";
14
10
  import { useTooltip } from "../hooks/tooltip/useTooltip.js";
15
11
  import { useOption } from "../hooks/useOption.js";
16
- import { HvBaseChart } from "../BaseChart/BaseChart.js";
12
+ import { forwardRef } from "react";
13
+ import { DataZoomInsideComponent, DataZoomSliderComponent, DatasetComponent, GridComponent, LegendComponent, MarkLineComponent, TooltipComponent } from "echarts/components";
14
+ import * as echarts from "echarts/core";
15
+ import { jsx } from "react/jsx-runtime";
16
+ import { BarChart } from "echarts/charts";
17
+ //#region src/BarChart/BarChart.tsx
17
18
  echarts.use([
18
- BarChart,
19
- DatasetComponent,
20
- GridComponent,
21
- TooltipComponent,
22
- LegendComponent,
23
- DataZoomSliderComponent,
24
- DataZoomInsideComponent,
25
- MarkLineComponent
19
+ BarChart,
20
+ DatasetComponent,
21
+ GridComponent,
22
+ TooltipComponent,
23
+ LegendComponent,
24
+ DataZoomSliderComponent,
25
+ DataZoomInsideComponent,
26
+ MarkLineComponent
26
27
  ]);
27
- const HvBarChart = forwardRef(
28
- function HvBarChart2(props, ref) {
29
- const {
30
- yAxis,
31
- xAxis,
32
- horizontal = false,
33
- horizontalRangeSlider,
34
- grid,
35
- data,
36
- groupBy,
37
- splitBy,
38
- sortBy,
39
- filters,
40
- stack,
41
- seriesNameFormatter,
42
- measures,
43
- legend,
44
- tooltip,
45
- classes,
46
- height,
47
- width,
48
- onOptionChange,
49
- ...others
50
- } = props;
51
- const { data: chartData, mapping: measuresMapping } = useData({
52
- data,
53
- groupBy,
54
- sortBy,
55
- splitBy,
56
- measures,
57
- filters
58
- });
59
- const chartDataset = useDataset(chartData);
60
- const chartYAxis = useYAxis({
61
- axes: Array.isArray(yAxis) || yAxis == null ? yAxis : [yAxis],
62
- defaultType: horizontal ? "categorical" : "continuous"
63
- });
64
- const chartXAxis = useXAxis({
65
- type: horizontal ? "continuous" : "categorical",
66
- ...xAxis
67
- });
68
- const chartSlider = useDataZoom({
69
- showHorizontal: horizontalRangeSlider?.show
70
- });
71
- const chartGrid = useGrid({ ...grid });
72
- const chartSeries = useSeries({
73
- type: "bar",
74
- data: chartData,
75
- groupBy,
76
- measuresMapping,
77
- stack,
78
- nameFormatter: seriesNameFormatter,
79
- horizontal
80
- });
81
- const chartLegend = useLegend({
82
- ...legend,
83
- series: chartSeries.series,
84
- icon: "square"
85
- });
86
- const chartTooltip = useTooltip({
87
- ...tooltip,
88
- trigger: "axis",
89
- measuresMapping,
90
- classes,
91
- horizontal
92
- });
93
- const option = useOption({
94
- option: {
95
- ...chartYAxis,
96
- ...chartXAxis,
97
- ...chartSlider,
98
- ...chartGrid,
99
- ...chartDataset,
100
- ...chartSeries,
101
- ...chartLegend,
102
- ...chartTooltip
103
- },
104
- onOptionChange
105
- });
106
- return /* @__PURE__ */ jsx(
107
- HvBaseChart,
108
- {
109
- ref,
110
- option,
111
- width,
112
- height,
113
- ...others
114
- }
115
- );
116
- }
117
- );
118
- export {
119
- HvBarChart
120
- };
28
+ /**
29
+ * A bar chart is a chart or graph that presents categorical data with rectangular bars.
30
+ */
31
+ var HvBarChart = forwardRef(function HvBarChart(props, ref) {
32
+ const { yAxis, xAxis, horizontal = false, horizontalRangeSlider, grid, data, groupBy, splitBy, sortBy, filters, stack, seriesNameFormatter, measures, legend, tooltip, classes, height, width, onOptionChange, ...others } = props;
33
+ const { data: chartData, mapping: measuresMapping } = useData({
34
+ data,
35
+ groupBy,
36
+ sortBy,
37
+ splitBy,
38
+ measures,
39
+ filters
40
+ });
41
+ const chartDataset = useDataset(chartData);
42
+ const chartYAxis = useYAxis({
43
+ axes: Array.isArray(yAxis) || yAxis == null ? yAxis : [yAxis],
44
+ defaultType: horizontal ? "categorical" : "continuous"
45
+ });
46
+ const chartXAxis = useXAxis({
47
+ type: horizontal ? "continuous" : "categorical",
48
+ ...xAxis
49
+ });
50
+ const chartSlider = useDataZoom({ showHorizontal: horizontalRangeSlider?.show });
51
+ const chartGrid = useGrid({ ...grid });
52
+ const chartSeries = useSeries({
53
+ type: "bar",
54
+ data: chartData,
55
+ groupBy,
56
+ measuresMapping,
57
+ stack,
58
+ nameFormatter: seriesNameFormatter,
59
+ horizontal
60
+ });
61
+ const chartLegend = useLegend({
62
+ ...legend,
63
+ series: chartSeries.series,
64
+ icon: "square"
65
+ });
66
+ const chartTooltip = useTooltip({
67
+ ...tooltip,
68
+ trigger: "axis",
69
+ measuresMapping,
70
+ classes,
71
+ horizontal
72
+ });
73
+ return /* @__PURE__ */ jsx(HvBaseChart, {
74
+ ref,
75
+ option: useOption({
76
+ option: {
77
+ ...chartYAxis,
78
+ ...chartXAxis,
79
+ ...chartSlider,
80
+ ...chartGrid,
81
+ ...chartDataset,
82
+ ...chartSeries,
83
+ ...chartLegend,
84
+ ...chartTooltip
85
+ },
86
+ onOptionChange
87
+ }),
88
+ width,
89
+ height,
90
+ ...others
91
+ });
92
+ });
93
+ //#endregion
94
+ export { HvBarChart };
@@ -1,57 +1,59 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef, useRef, useState, useEffect } from "react";
1
+ import { useVizTheme } from "../providers/Provider.js";
2
+ import { forwardRef, useEffect, useRef, useState } from "react";
3
3
  import { useForkRef } from "@mui/material/utils";
4
4
  import ReactECharts from "echarts-for-react";
5
5
  import { AriaComponent } from "echarts/components";
6
6
  import * as echarts from "echarts/core";
7
7
  import { CanvasRenderer } from "echarts/renderers";
8
- import { useVizTheme } from "../providers/Provider.js";
8
+ import { jsx } from "react/jsx-runtime";
9
+ //#region src/BaseChart/BaseChart.tsx
9
10
  echarts.use([CanvasRenderer, AriaComponent]);
10
- const HvBaseChart = forwardRef(
11
- function HvBaseChart2(props, ref) {
12
- const { option, width, height, onEvents, ...others } = props;
13
- const { theme, activeTheme } = useVizTheme();
14
- const currentTheme = useRef(theme);
15
- const chartRef = useRef(null);
16
- const forkedRef = useForkRef(ref, chartRef);
17
- const [initialOption, setInitialOption] = useState(option);
18
- useEffect(() => {
19
- const instance = chartRef.current?.getEchartsInstance();
20
- if (!instance) return;
21
- return () => {
22
- instance.dispose();
23
- };
24
- }, [activeTheme]);
25
- useEffect(() => {
26
- if (theme !== currentTheme.current) {
27
- setInitialOption(option);
28
- currentTheme.current = theme;
29
- return;
30
- }
31
- const instance = chartRef.current?.getEchartsInstance();
32
- if (!instance) return;
33
- instance.setOption(option, {
34
- replaceMerge: ["xAxis", "yAxis", "series", "dataset", "dataZoom"]
35
- });
36
- }, [theme, option]);
37
- return /* @__PURE__ */ jsx(
38
- ReactECharts,
39
- {
40
- ref: forkedRef,
41
- echarts,
42
- option: initialOption,
43
- theme,
44
- notMerge: true,
45
- style: {
46
- width: width ?? "100%",
47
- height: height ?? "100%"
48
- },
49
- onEvents,
50
- ...others
51
- }
52
- );
53
- }
54
- );
55
- export {
56
- HvBaseChart
57
- };
11
+ /**
12
+ * Base chart.
13
+ */
14
+ var HvBaseChart = forwardRef(function HvBaseChart(props, ref) {
15
+ const { option, width, height, onEvents, ...others } = props;
16
+ const { theme, activeTheme } = useVizTheme();
17
+ const currentTheme = useRef(theme);
18
+ const chartRef = useRef(null);
19
+ const forkedRef = useForkRef(ref, chartRef);
20
+ const [initialOption, setInitialOption] = useState(option);
21
+ useEffect(() => {
22
+ const instance = chartRef.current?.getEchartsInstance();
23
+ if (!instance) return;
24
+ return () => {
25
+ instance.dispose();
26
+ };
27
+ }, [activeTheme]);
28
+ useEffect(() => {
29
+ if (theme !== currentTheme.current) {
30
+ setInitialOption(option);
31
+ currentTheme.current = theme;
32
+ return;
33
+ }
34
+ const instance = chartRef.current?.getEchartsInstance();
35
+ if (!instance) return;
36
+ instance.setOption(option, { replaceMerge: [
37
+ "xAxis",
38
+ "yAxis",
39
+ "series",
40
+ "dataset",
41
+ "dataZoom"
42
+ ] });
43
+ }, [theme, option]);
44
+ return /* @__PURE__ */ jsx(ReactECharts, {
45
+ ref: forkedRef,
46
+ echarts,
47
+ option: initialOption,
48
+ theme,
49
+ notMerge: true,
50
+ style: {
51
+ width: width ?? "100%",
52
+ height: height ?? "100%"
53
+ },
54
+ onEvents,
55
+ ...others
56
+ });
57
+ });
58
+ //#endregion
59
+ export { HvBaseChart };
@@ -1,47 +1,38 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import { BoxplotChart } from "echarts/charts";
4
- import { TooltipComponent, VisualMapComponent } from "echarts/components";
5
- import * as echarts from "echarts/core";
6
- import { useClasses } from "./Boxplot.styles.js";
7
- import { useBoxplot } from "./useBoxplot.js";
8
- import { useTooltip } from "../hooks/tooltip/useTooltip.js";
9
- import { useGrid } from "../hooks/useGrid.js";
10
- import { useLegend } from "../hooks/useLegend.js";
1
+ import { HvBaseChart } from "../BaseChart/BaseChart.js";
11
2
  import { useXAxis } from "../hooks/useXAxis.js";
12
3
  import { useYAxis } from "../hooks/useYAxis.js";
4
+ import { useGrid } from "../hooks/useGrid.js";
5
+ import { useLegend } from "../hooks/useLegend.js";
6
+ import { useTooltip } from "../hooks/tooltip/useTooltip.js";
13
7
  import { useOption } from "../hooks/useOption.js";
14
- import { HvBaseChart } from "../BaseChart/BaseChart.js";
15
- echarts.use([BoxplotChart, TooltipComponent, VisualMapComponent]);
16
- const HvBoxplot = forwardRef(
17
- function HvBoxplot2(props, ref) {
18
- const {
19
- name,
20
- data,
21
- xAxis,
22
- yAxis,
23
- grid,
24
- legend,
25
- measures,
26
- groupBy,
27
- tooltip,
28
- width,
29
- height,
30
- filters,
31
- classes: classesProp,
32
- onOptionChange,
33
- ...others
34
- } = props;
35
- const { classes } = useClasses(classesProp);
36
- const chartTooltip = useTooltip({
37
- component: (params) => {
38
- const title = params?.title;
39
- const upper = params?.value?.[5];
40
- const q3 = params?.value?.[4];
41
- const median = params?.value?.[3];
42
- const q1 = params?.value?.[2];
43
- const lower = params?.value?.[1];
44
- return `
8
+ import { useClasses } from "./Boxplot.styles.js";
9
+ import { useBoxplot } from "./useBoxplot.js";
10
+ import { forwardRef } from "react";
11
+ import { TooltipComponent, VisualMapComponent } from "echarts/components";
12
+ import * as echarts from "echarts/core";
13
+ import { jsx } from "react/jsx-runtime";
14
+ import { BoxplotChart } from "echarts/charts";
15
+ //#region src/Boxplot/Boxplot.tsx
16
+ echarts.use([
17
+ BoxplotChart,
18
+ TooltipComponent,
19
+ VisualMapComponent
20
+ ]);
21
+ /**
22
+ * A Boxplot chart visually summarizes the distribution of a dataset by depicting key statistical measures such as the median, quartiles, and outliers.
23
+ */
24
+ var HvBoxplot = forwardRef(function HvBoxplot(props, ref) {
25
+ const { name, data, xAxis, yAxis, grid, legend, measures, groupBy, tooltip, width, height, filters, classes: classesProp, onOptionChange, ...others } = props;
26
+ const { classes } = useClasses(classesProp);
27
+ const chartTooltip = useTooltip({
28
+ component: (params) => {
29
+ const title = params?.title;
30
+ const upper = params?.value?.[5];
31
+ const q3 = params?.value?.[4];
32
+ const median = params?.value?.[3];
33
+ const q1 = params?.value?.[2];
34
+ const lower = params?.value?.[1];
35
+ return `
45
36
  <div class="${classes.tooltipRoot}">
46
37
  <div class="${classes.tooltipContainer}">
47
38
  <div>
@@ -54,45 +45,39 @@ const HvBoxplot = forwardRef(
54
45
  </div>
55
46
  </div>
56
47
  </div>`;
57
- },
58
- ...tooltip
59
- });
60
- const chartGrid = useGrid({ ...grid });
61
- const chartLegend = useLegend({
62
- ...legend,
63
- icon: "square"
64
- });
65
- const chartXAxis = useXAxis({
66
- ...xAxis
67
- });
68
- const chartYAxis = useYAxis({
69
- axes: Array.isArray(yAxis) || yAxis == null ? yAxis : [yAxis],
70
- defaultType: "continuous",
71
- ...yAxis
72
- });
73
- const chartBoxplot = useBoxplot({ data, groupBy, measures, filters });
74
- const chartOption = useOption({
75
- option: {
76
- ...chartBoxplot,
77
- ...chartGrid,
78
- ...chartLegend,
79
- ...chartTooltip,
80
- ...chartXAxis,
81
- ...chartYAxis
82
- }
83
- });
84
- return /* @__PURE__ */ jsx(
85
- HvBaseChart,
86
- {
87
- ref,
88
- option: chartOption,
89
- width,
90
- height,
91
- ...others
92
- }
93
- );
94
- }
95
- );
96
- export {
97
- HvBoxplot
98
- };
48
+ },
49
+ ...tooltip
50
+ });
51
+ const chartGrid = useGrid({ ...grid });
52
+ const chartLegend = useLegend({
53
+ ...legend,
54
+ icon: "square"
55
+ });
56
+ const chartXAxis = useXAxis({ ...xAxis });
57
+ const chartYAxis = useYAxis({
58
+ axes: Array.isArray(yAxis) || yAxis == null ? yAxis : [yAxis],
59
+ defaultType: "continuous",
60
+ ...yAxis
61
+ });
62
+ return /* @__PURE__ */ jsx(HvBaseChart, {
63
+ ref,
64
+ option: useOption({ option: {
65
+ ...useBoxplot({
66
+ data,
67
+ groupBy,
68
+ measures,
69
+ filters
70
+ }),
71
+ ...chartGrid,
72
+ ...chartLegend,
73
+ ...chartTooltip,
74
+ ...chartXAxis,
75
+ ...chartYAxis
76
+ } }),
77
+ width,
78
+ height,
79
+ ...others
80
+ });
81
+ });
82
+ //#endregion
83
+ export { HvBoxplot };
@@ -1,26 +1,25 @@
1
1
  import { createClasses } from "@hitachivantara/uikit-react-utils";
2
2
  import { theme } from "@hitachivantara/uikit-styles";
3
- const { useClasses, staticClasses } = createClasses("HvBoxplot", {
4
- tooltipRoot: {
5
- backgroundColor: theme.colors.bgContainer,
6
- width: "fit-content",
7
- minWidth: 150,
8
- boxShadow: theme.colors.shadow,
9
- zIndex: theme.zIndices.sticky
10
- },
11
- tooltipContainer: {
12
- padding: theme.spacing("15px", "sm"),
13
- display: "flex",
14
- flexDirection: "column"
15
- },
16
- tooltipText: {
17
- fontFamily: theme.fontFamily.body,
18
- fontWeight: theme.fontWeights.normal,
19
- fontSize: theme.fontSizes.sm,
20
- color: theme.colors.text
21
- }
3
+ //#region src/Boxplot/Boxplot.styles.tsx
4
+ var { useClasses, staticClasses } = createClasses("HvBoxplot", {
5
+ tooltipRoot: {
6
+ backgroundColor: theme.colors.bgContainer,
7
+ width: "fit-content",
8
+ minWidth: 150,
9
+ boxShadow: theme.colors.shadow,
10
+ zIndex: theme.zIndices.sticky
11
+ },
12
+ tooltipContainer: {
13
+ padding: theme.spacing("15px", "sm"),
14
+ display: "flex",
15
+ flexDirection: "column"
16
+ },
17
+ tooltipText: {
18
+ fontFamily: theme.fontFamily.body,
19
+ fontWeight: theme.fontWeights.normal,
20
+ fontSize: theme.fontSizes.sm,
21
+ color: theme.colors.text
22
+ }
22
23
  });
23
- export {
24
- staticClasses,
25
- useClasses
26
- };
24
+ //#endregion
25
+ export { useClasses };
@@ -1,72 +1,58 @@
1
- import { useMemo } from "react";
2
1
  import { useBoxplotData } from "./useBoxplotData.js";
3
- const useBoxplot = ({
4
- data,
5
- groupBy,
6
- measures,
7
- filters
8
- }) => {
9
- const measuresFields = useMemo(() => {
10
- if (measures == null) return {};
11
- if (typeof measures === "string") return { [measures]: void 0 };
12
- if (Array.isArray(measures)) {
13
- return measures.reduce(
14
- (acc, value) => {
15
- const field = typeof value === "string" ? value : value.field;
16
- acc[field] = typeof value === "string" ? void 0 : value.yAxis;
17
- return acc;
18
- },
19
- {}
20
- );
21
- }
22
- return { [measures.field]: measures.yAxis };
23
- }, [measures]);
24
- const chartData = useBoxplotData({
25
- data,
26
- groupBy,
27
- measures: measuresFields,
28
- filters
29
- });
30
- const boxplotData = useMemo(() => {
31
- const setData = {};
32
- Object.keys(measuresFields).forEach((m) => {
33
- setData[m] = [];
34
- Object.keys(chartData).forEach((key) => {
35
- setData[m].push(chartData[key][m]);
36
- });
37
- });
38
- const sources = [];
39
- const transforms = [];
40
- const series = [];
41
- Object.keys(measuresFields).forEach((m, index) => {
42
- sources.push({
43
- source: setData[m],
44
- id: m
45
- });
46
- transforms.push({
47
- fromDatasetId: m,
48
- transform: {
49
- type: "boxplot",
50
- config: {
51
- itemNameFormatter: (params) => Object.keys(chartData)[params.value]
52
- }
53
- }
54
- });
55
- series.push({
56
- name: m,
57
- type: "boxplot",
58
- datasetIndex: Object.keys(measuresFields).length + index,
59
- yAxisId: measuresFields[m]
60
- });
61
- });
62
- const datasets = {
63
- dataset: [...sources, ...transforms],
64
- series
65
- };
66
- return datasets;
67
- }, [chartData, measuresFields]);
68
- return boxplotData;
69
- };
70
- export {
71
- useBoxplot
2
+ import { useMemo } from "react";
3
+ //#region src/Boxplot/useBoxplot.tsx
4
+ var useBoxplot = ({ data, groupBy, measures, filters }) => {
5
+ const measuresFields = useMemo(() => {
6
+ if (measures == null) return {};
7
+ if (typeof measures === "string") return { [measures]: void 0 };
8
+ if (Array.isArray(measures)) return measures.reduce((acc, value) => {
9
+ const field = typeof value === "string" ? value : value.field;
10
+ acc[field] = typeof value === "string" ? void 0 : value.yAxis;
11
+ return acc;
12
+ }, {});
13
+ return { [measures.field]: measures.yAxis };
14
+ }, [measures]);
15
+ const chartData = useBoxplotData({
16
+ data,
17
+ groupBy,
18
+ measures: measuresFields,
19
+ filters
20
+ });
21
+ return useMemo(() => {
22
+ const setData = {};
23
+ Object.keys(measuresFields).forEach((m) => {
24
+ setData[m] = [];
25
+ Object.keys(chartData).forEach((key) => {
26
+ setData[m].push(chartData[key][m]);
27
+ });
28
+ });
29
+ const sources = [];
30
+ const transforms = [];
31
+ const series = [];
32
+ Object.keys(measuresFields).forEach((m, index) => {
33
+ sources.push({
34
+ source: setData[m],
35
+ id: m
36
+ });
37
+ transforms.push({
38
+ fromDatasetId: m,
39
+ transform: {
40
+ type: "boxplot",
41
+ config: { itemNameFormatter: (params) => Object.keys(chartData)[params.value] }
42
+ }
43
+ });
44
+ series.push({
45
+ name: m,
46
+ type: "boxplot",
47
+ datasetIndex: Object.keys(measuresFields).length + index,
48
+ yAxisId: measuresFields[m]
49
+ });
50
+ });
51
+ return {
52
+ dataset: [...sources, ...transforms],
53
+ series
54
+ };
55
+ }, [chartData, measuresFields]);
72
56
  };
57
+ //#endregion
58
+ export { useBoxplot };