@hitachivantara/uikit-react-viz 6.1.6 → 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,142 +1,109 @@
1
- import { useMemo, useCallback } from "react";
1
+ import { useCallback, useMemo } from "react";
2
2
  import { useTheme } from "@hitachivantara/uikit-react-utils";
3
- const useColorScale = ({
4
- data,
5
- delta,
6
- custom,
7
- filterKey
8
- }) => {
9
- const { colors } = useTheme();
10
- const colorScale = useMemo(() => {
11
- if (custom == null && delta) {
12
- return;
13
- }
14
- if (custom && typeof custom[0] === "object") {
15
- return {
16
- pieces: custom.reduce((acc, curr) => {
17
- acc.push({
18
- ...curr,
19
- color: colors?.[curr.color] || curr.color
20
- });
21
- return acc;
22
- }, [])
23
- };
24
- }
25
- const flatData = data.columnNames().filter((p) => p !== filterKey).reduce((acc, c) => {
26
- acc.push(...data.array(c));
27
- return acc;
28
- }, []);
29
- const max = Math.max(...flatData);
30
- const min = Math.min(...flatData);
31
- const parsedColors = custom?.map(
32
- (c) => typeof c === "string" ? colors?.[c] || c : c.color
33
- );
34
- return {
35
- colorScale: parsedColors || [colors?.textLight || "", colors?.cat3 || ""],
36
- max,
37
- min
38
- };
39
- }, [colors, custom, data, filterKey, delta]);
40
- return colorScale;
3
+ //#region src/ConfusionMatrix/utils.ts
4
+ var useColorScale = ({ data, delta, custom, filterKey }) => {
5
+ const { colors } = useTheme();
6
+ return useMemo(() => {
7
+ if (custom == null && delta) return;
8
+ if (custom && typeof custom[0] === "object") return { pieces: custom.reduce((acc, curr) => {
9
+ acc.push({
10
+ ...curr,
11
+ color: colors?.[curr.color] || curr.color
12
+ });
13
+ return acc;
14
+ }, []) };
15
+ const flatData = data.columnNames().filter((p) => p !== filterKey).reduce((acc, c) => {
16
+ acc.push(...data.array(c));
17
+ return acc;
18
+ }, []);
19
+ const max = Math.max(...flatData);
20
+ const min = Math.min(...flatData);
21
+ return {
22
+ colorScale: custom?.map((c) => typeof c === "string" ? colors?.[c] || c : c.color) || [colors?.textLight || "", colors?.cat3 || ""],
23
+ max,
24
+ min
25
+ };
26
+ }, [
27
+ colors,
28
+ custom,
29
+ data,
30
+ filterKey,
31
+ delta
32
+ ]);
41
33
  };
42
- const useSeries = ({
43
- data,
44
- filterKey,
45
- delta,
46
- valuesProps
47
- }) => {
48
- const { colors } = useTheme();
49
- const getDeltaColor = useCallback(
50
- (value, diagonal) => {
51
- if (diagonal && value > 0 || !diagonal && value < 0) {
52
- return colors?.positive;
53
- }
54
- if (diagonal && value < 0 || !diagonal && value > 0) {
55
- return colors?.negative;
56
- }
57
- return colors?.textLight;
58
- },
59
- [colors]
60
- );
61
- const chartSeries = useMemo(() => {
62
- return {
63
- series: {
64
- id: `series~${filterKey}`,
65
- type: "heatmap",
66
- label: {
67
- show: true,
68
- ...valuesProps,
69
- ...valuesProps?.color && {
70
- color: colors?.[valuesProps.color] || valuesProps.color
71
- }
72
- },
73
- emphasis: {
74
- disabled: true
75
- },
76
- data: data.columnNames().filter((p) => p !== filterKey).reduce((acc, c, j) => {
77
- const row = data.array(c).reduce((racc, rv, i) => {
78
- racc.push({
79
- value: [data.array(filterKey)[i], c, rv != null ? rv : "-"],
80
- ...delta && {
81
- visualMap: false,
82
- itemStyle: {
83
- color: getDeltaColor(rv, i === j)
84
- }
85
- }
86
- });
87
- return racc;
88
- }, []);
89
- acc.push(...row);
90
- return acc;
91
- }, [])
92
- }
93
- };
94
- }, [colors, data, delta, filterKey, getDeltaColor, valuesProps]);
95
- return chartSeries;
34
+ var useSeries = ({ data, filterKey, delta, valuesProps }) => {
35
+ const { colors } = useTheme();
36
+ const getDeltaColor = useCallback((value, diagonal) => {
37
+ if (diagonal && value > 0 || !diagonal && value < 0) return colors?.positive;
38
+ if (diagonal && value < 0 || !diagonal && value > 0) return colors?.negative;
39
+ return colors?.textLight;
40
+ }, [colors]);
41
+ return useMemo(() => {
42
+ return { series: {
43
+ id: `series~${filterKey}`,
44
+ type: "heatmap",
45
+ label: {
46
+ show: true,
47
+ ...valuesProps,
48
+ ...valuesProps?.color && { color: colors?.[valuesProps.color] || valuesProps.color }
49
+ },
50
+ emphasis: { disabled: true },
51
+ data: data.columnNames().filter((p) => p !== filterKey).reduce((acc, c, j) => {
52
+ const row = data.array(c).reduce((racc, rv, i) => {
53
+ racc.push({
54
+ value: [
55
+ data.array(filterKey)[i],
56
+ c,
57
+ rv != null ? rv : "-"
58
+ ],
59
+ ...delta && {
60
+ visualMap: false,
61
+ itemStyle: { color: getDeltaColor(rv, i === j) }
62
+ }
63
+ });
64
+ return racc;
65
+ }, []);
66
+ acc.push(...row);
67
+ return acc;
68
+ }, [])
69
+ } };
70
+ }, [
71
+ colors,
72
+ data,
73
+ delta,
74
+ filterKey,
75
+ getDeltaColor,
76
+ valuesProps
77
+ ]);
96
78
  };
97
- const SQUARE_SIZE = 52;
98
- const useGridLayout = ({
99
- data,
100
- filterKey,
101
- format,
102
- xAxisPosition,
103
- visualMapVisible,
104
- visualMapYPosition
105
- }) => {
106
- const size = useMemo(() => {
107
- const nCols = data.array(filterKey).length;
108
- const nRows = data.columnNames().filter((p) => p !== filterKey).length;
109
- const itemHeight = format === "square" ? SQUARE_SIZE : SQUARE_SIZE / 2;
110
- return {
111
- padding: {
112
- bottom: xAxisPosition === "bottom" || visualMapVisible && visualMapYPosition === "bottom" ? 60 : 20,
113
- top: xAxisPosition === "top" || visualMapVisible && visualMapYPosition === "top" ? 60 : 20,
114
- ...visualMapVisible && visualMapYPosition === "bottom" && xAxisPosition === "bottom" && {
115
- bottom: 100
116
- },
117
- ...visualMapVisible && visualMapYPosition === "top" && xAxisPosition === "top" && {
118
- top: 100
119
- },
120
- left: 80,
121
- right: 80
122
- },
123
- size: {
124
- height: Math.max(itemHeight * nRows, itemHeight * 8),
125
- width: Math.max(SQUARE_SIZE * nCols, SQUARE_SIZE * 8)
126
- }
127
- };
128
- }, [
129
- data,
130
- filterKey,
131
- format,
132
- visualMapVisible,
133
- visualMapYPosition,
134
- xAxisPosition
135
- ]);
136
- return size;
137
- };
138
- export {
139
- useColorScale,
140
- useGridLayout,
141
- useSeries
79
+ var SQUARE_SIZE = 52;
80
+ var useGridLayout = ({ data, filterKey, format, xAxisPosition, visualMapVisible, visualMapYPosition }) => {
81
+ return useMemo(() => {
82
+ const nCols = data.array(filterKey).length;
83
+ const nRows = data.columnNames().filter((p) => p !== filterKey).length;
84
+ const itemHeight = format === "square" ? SQUARE_SIZE : SQUARE_SIZE / 2;
85
+ return {
86
+ padding: {
87
+ bottom: xAxisPosition === "bottom" || visualMapVisible && visualMapYPosition === "bottom" ? 60 : 20,
88
+ top: xAxisPosition === "top" || visualMapVisible && visualMapYPosition === "top" ? 60 : 20,
89
+ ...visualMapVisible && visualMapYPosition === "bottom" && xAxisPosition === "bottom" && { bottom: 100 },
90
+ ...visualMapVisible && visualMapYPosition === "top" && xAxisPosition === "top" && { top: 100 },
91
+ left: 80,
92
+ right: 80
93
+ },
94
+ size: {
95
+ height: Math.max(itemHeight * nRows, itemHeight * 8),
96
+ width: Math.max(SQUARE_SIZE * nCols, SQUARE_SIZE * 8)
97
+ }
98
+ };
99
+ }, [
100
+ data,
101
+ filterKey,
102
+ format,
103
+ visualMapVisible,
104
+ visualMapYPosition,
105
+ xAxisPosition
106
+ ]);
142
107
  };
108
+ //#endregion
109
+ export { useColorScale, useGridLayout, useSeries };
@@ -1,93 +1,75 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import { PieChart } from "echarts/charts";
4
- import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from "echarts/components";
5
- import * as echarts from "echarts/core";
1
+ import { HvBaseChart } from "../BaseChart/BaseChart.js";
2
+ import { useGrid } from "../hooks/useGrid.js";
6
3
  import { useData } from "../hooks/useData.js";
7
4
  import { useDataset } from "../hooks/useDataset.js";
8
5
  import { useSeries } from "../hooks/useSeries.js";
9
6
  import { useLegend } from "../hooks/useLegend.js";
10
7
  import { useTooltip } from "../hooks/tooltip/useTooltip.js";
11
- import { useGrid } from "../hooks/useGrid.js";
12
8
  import { useOption } from "../hooks/useOption.js";
13
- import { HvBaseChart } from "../BaseChart/BaseChart.js";
9
+ import { forwardRef } from "react";
10
+ import { DatasetComponent, GridComponent, LegendComponent, TooltipComponent } from "echarts/components";
11
+ import * as echarts from "echarts/core";
12
+ import { jsx } from "react/jsx-runtime";
13
+ import { PieChart } from "echarts/charts";
14
+ //#region src/DonutChart/DonutChart.tsx
14
15
  echarts.use([
15
- PieChart,
16
- DatasetComponent,
17
- GridComponent,
18
- TooltipComponent,
19
- LegendComponent
16
+ PieChart,
17
+ DatasetComponent,
18
+ GridComponent,
19
+ TooltipComponent,
20
+ LegendComponent
20
21
  ]);
21
- const HvDonutChart = forwardRef(
22
- function HvDonutChart2(props, ref) {
23
- const {
24
- data,
25
- groupBy,
26
- classes,
27
- legend,
28
- tooltip,
29
- measure: measures,
30
- sortBy,
31
- filters,
32
- grid,
33
- width,
34
- height,
35
- type = "regular",
36
- slicesNameFormatter,
37
- onOptionChange,
38
- ...others
39
- } = props;
40
- const { data: chartData, mapping: measuresMapping } = useData({
41
- data,
42
- groupBy,
43
- measures,
44
- sortBy,
45
- filters
46
- });
47
- const chartDataset = useDataset(chartData);
48
- const chartSeries = useSeries({
49
- type: "pie",
50
- data: chartData,
51
- groupBy,
52
- measuresMapping,
53
- radius: type === "thin" ? ["65%", "70%"] : ["55%", "70%"]
54
- });
55
- const chartLegend = useLegend({
56
- ...legend,
57
- show: legend?.show ?? true,
58
- icon: "square",
59
- series: chartSeries.series,
60
- formatter: slicesNameFormatter
61
- });
62
- const chartTooltip = useTooltip({
63
- ...tooltip,
64
- measuresMapping,
65
- classes,
66
- nameFormatter: slicesNameFormatter
67
- });
68
- const chartGrid = useGrid({ ...grid });
69
- const option = useOption({
70
- option: {
71
- ...chartSeries,
72
- ...chartDataset,
73
- ...chartLegend,
74
- ...chartTooltip,
75
- ...chartGrid
76
- },
77
- onOptionChange
78
- });
79
- return /* @__PURE__ */ jsx(
80
- HvBaseChart,
81
- {
82
- ref,
83
- option,
84
- width,
85
- height,
86
- ...others
87
- }
88
- );
89
- }
90
- );
91
- export {
92
- HvDonutChart
93
- };
22
+ /**
23
+ * Donut charts nicely convey the part-whole relationship and they have become
24
+ * the most recognizable chart types for representing proportions in business and data statistics.
25
+ */
26
+ var HvDonutChart = forwardRef(function HvDonutChart(props, ref) {
27
+ const { data, groupBy, classes, legend, tooltip, measure: measures, sortBy, filters, grid, width, height, type = "regular", slicesNameFormatter, onOptionChange, ...others } = props;
28
+ const { data: chartData, mapping: measuresMapping } = useData({
29
+ data,
30
+ groupBy,
31
+ measures,
32
+ sortBy,
33
+ filters
34
+ });
35
+ const chartDataset = useDataset(chartData);
36
+ const chartSeries = useSeries({
37
+ type: "pie",
38
+ data: chartData,
39
+ groupBy,
40
+ measuresMapping,
41
+ radius: type === "thin" ? ["65%", "70%"] : ["55%", "70%"]
42
+ });
43
+ const chartLegend = useLegend({
44
+ ...legend,
45
+ show: legend?.show ?? true,
46
+ icon: "square",
47
+ series: chartSeries.series,
48
+ formatter: slicesNameFormatter
49
+ });
50
+ const chartTooltip = useTooltip({
51
+ ...tooltip,
52
+ measuresMapping,
53
+ classes,
54
+ nameFormatter: slicesNameFormatter
55
+ });
56
+ const chartGrid = useGrid({ ...grid });
57
+ return /* @__PURE__ */ jsx(HvBaseChart, {
58
+ ref,
59
+ option: useOption({
60
+ option: {
61
+ ...chartSeries,
62
+ ...chartDataset,
63
+ ...chartLegend,
64
+ ...chartTooltip,
65
+ ...chartGrid
66
+ },
67
+ onOptionChange
68
+ }),
69
+ width,
70
+ height,
71
+ ...others
72
+ });
73
+ });
74
+ //#endregion
75
+ export { HvDonutChart };
@@ -1,42 +1,35 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import { HeatmapChart } from "echarts/charts";
4
- import { TooltipComponent, VisualMapComponent } from "echarts/components";
5
- import * as echarts from "echarts/core";
6
- import { useTheme } from "@hitachivantara/uikit-react-utils";
7
- import { useClasses } from "./Heatmap.styles.js";
8
- import { useTooltip } from "../hooks/tooltip/useTooltip.js";
1
+ import { HvBaseChart } from "../BaseChart/BaseChart.js";
9
2
  import { useXAxis } from "../hooks/useXAxis.js";
10
3
  import { useYAxis } from "../hooks/useYAxis.js";
11
4
  import { useVisualMap } from "../hooks/useVisualMap.js";
5
+ import { useTooltip } from "../hooks/tooltip/useTooltip.js";
12
6
  import { useOption } from "../hooks/useOption.js";
13
- import { HvBaseChart } from "../BaseChart/BaseChart.js";
14
- echarts.use([HeatmapChart, TooltipComponent, VisualMapComponent]);
15
- const HvHeatmap = forwardRef(
16
- function HvHeatmap2(props, ref) {
17
- const {
18
- name,
19
- data,
20
- min,
21
- max,
22
- colorScale,
23
- xAxis,
24
- yAxis,
25
- classes: classesProp,
26
- tooltip,
27
- width,
28
- height,
29
- onOptionChange,
30
- ...others
31
- } = props;
32
- const { classes } = useClasses(classesProp);
33
- const { colors } = useTheme();
34
- const chartTooltip = useTooltip({
35
- component: (params) => {
36
- const value = params?.value;
37
- const title = params?.title;
38
- const valueToShow = value ? `${yAxis?.data?.[Number(value[1])]} - ${xAxis?.data?.[Number(value[0])]}: ${params?.series?.[0]?.name}` : "-";
39
- return `
7
+ import { useClasses } from "./Heatmap.styles.js";
8
+ import { forwardRef } from "react";
9
+ import { TooltipComponent, VisualMapComponent } from "echarts/components";
10
+ import * as echarts from "echarts/core";
11
+ import { useTheme } from "@hitachivantara/uikit-react-utils";
12
+ import { jsx } from "react/jsx-runtime";
13
+ import { HeatmapChart } from "echarts/charts";
14
+ //#region src/Heatmap/Heatmap.tsx
15
+ echarts.use([
16
+ HeatmapChart,
17
+ TooltipComponent,
18
+ VisualMapComponent
19
+ ]);
20
+ /**
21
+ * A Heatmap uses color gradients to represent data intensity across a surface.
22
+ */
23
+ var HvHeatmap = forwardRef(function HvHeatmap(props, ref) {
24
+ const { name, data, min, max, colorScale, xAxis, yAxis, classes: classesProp, tooltip, width, height, onOptionChange, ...others } = props;
25
+ const { classes } = useClasses(classesProp);
26
+ const { colors } = useTheme();
27
+ const chartTooltip = useTooltip({
28
+ component: (params) => {
29
+ const value = params?.value;
30
+ const title = params?.title;
31
+ const valueToShow = value ? `${yAxis?.data?.[Number(value[1])]} - ${xAxis?.data?.[Number(value[0])]}: ${params?.series?.[0]?.name}` : "-";
32
+ return `
40
33
  <div class="${classes.tooltipRoot}">
41
34
  <div class="${classes.tooltipContainer}">
42
35
  <div>
@@ -45,65 +38,56 @@ const HvHeatmap = forwardRef(
45
38
  </div>
46
39
  </div>
47
40
  </div>`;
48
- },
49
- ...tooltip
50
- });
51
- const chartXAxis = useXAxis({ type: "categorical", ...xAxis });
52
- const chartYAxis = useYAxis({
53
- defaultType: "categorical",
54
- axes: yAxis ? [yAxis] : []
55
- });
56
- const convertedColors = colorScale?.map(
57
- (color) => colors?.[color] || color
58
- );
59
- const chartVisualMap = useVisualMap({
60
- min,
61
- max,
62
- orient: "horizontal",
63
- left: "center",
64
- calculable: true,
65
- position: {
66
- y: "bottom"
67
- },
68
- colorScale: convertedColors || ["#2D4B87", "#95AFE8", "#E7EDF9"]
69
- });
70
- const option = useOption({
71
- option: {
72
- xAxis: chartXAxis.xAxis,
73
- yAxis: chartYAxis.yAxis,
74
- visualMap: chartVisualMap.visualMap,
75
- series: [
76
- {
77
- name,
78
- type: "heatmap",
79
- data,
80
- label: {
81
- show: true
82
- },
83
- emphasis: {
84
- itemStyle: {
85
- shadowBlur: 10,
86
- shadowColor: "rgba(0, 0, 0, 0.5)"
87
- }
88
- }
89
- }
90
- ],
91
- ...chartTooltip
92
- },
93
- onOptionChange
94
- });
95
- return /* @__PURE__ */ jsx(
96
- HvBaseChart,
97
- {
98
- ref,
99
- option,
100
- width,
101
- height,
102
- ...others
103
- }
104
- );
105
- }
106
- );
107
- export {
108
- HvHeatmap
109
- };
41
+ },
42
+ ...tooltip
43
+ });
44
+ const chartXAxis = useXAxis({
45
+ type: "categorical",
46
+ ...xAxis
47
+ });
48
+ const chartYAxis = useYAxis({
49
+ defaultType: "categorical",
50
+ axes: yAxis ? [yAxis] : []
51
+ });
52
+ const convertedColors = colorScale?.map((color) => colors?.[color] || color);
53
+ const chartVisualMap = useVisualMap({
54
+ min,
55
+ max,
56
+ orient: "horizontal",
57
+ left: "center",
58
+ calculable: true,
59
+ position: { y: "bottom" },
60
+ colorScale: convertedColors || [
61
+ "#2D4B87",
62
+ "#95AFE8",
63
+ "#E7EDF9"
64
+ ]
65
+ });
66
+ return /* @__PURE__ */ jsx(HvBaseChart, {
67
+ ref,
68
+ option: useOption({
69
+ option: {
70
+ xAxis: chartXAxis.xAxis,
71
+ yAxis: chartYAxis.yAxis,
72
+ visualMap: chartVisualMap.visualMap,
73
+ series: [{
74
+ name,
75
+ type: "heatmap",
76
+ data,
77
+ label: { show: true },
78
+ emphasis: { itemStyle: {
79
+ shadowBlur: 10,
80
+ shadowColor: "rgba(0, 0, 0, 0.5)"
81
+ } }
82
+ }],
83
+ ...chartTooltip
84
+ },
85
+ onOptionChange
86
+ }),
87
+ width,
88
+ height,
89
+ ...others
90
+ });
91
+ });
92
+ //#endregion
93
+ export { HvHeatmap };
@@ -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("HvHeatmap", {
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/Heatmap/Heatmap.styles.tsx
4
+ var { useClasses, staticClasses } = createClasses("HvHeatmap", {
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 };