@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,40 +1,37 @@
1
+ import { getHvArqueroCombinedFilters, normalizeColumnName, processTableData } from "../utils/index.js";
1
2
  import { useMemo } from "react";
2
3
  import { escape } from "arquero";
3
- import { processTableData, normalizeColumnName, getHvArqueroCombinedFilters } from "../utils/index.js";
4
- const useBoxplotData = ({
5
- data,
6
- groupBy: groupByProp,
7
- measures,
8
- filters: filtersProp
9
- }) => {
10
- const chartData = useMemo(() => {
11
- const { data: processedData } = processTableData(data);
12
- let tableData = processedData;
13
- if (filtersProp) {
14
- const filters = (Array.isArray(filtersProp) ? filtersProp : [filtersProp]).map((filter) => ({
15
- ...filter,
16
- field: normalizeColumnName(filter.field)
17
- // normalize
18
- }));
19
- tableData = tableData.filter(
20
- escape((row) => getHvArqueroCombinedFilters(row, filters))
21
- );
22
- }
23
- const normalizedGroupBy = normalizeColumnName(groupByProp || "");
24
- const uniqueGroupBy = new Set(
25
- tableData.array(normalizedGroupBy)
26
- );
27
- const results = {};
28
- uniqueGroupBy.forEach((group) => {
29
- results[group] = {};
30
- Object.keys(measures).forEach((measure) => {
31
- results[group][measure] = tableData.params({ group, groupBy: normalizedGroupBy }).filter((d, $) => d[$.groupBy] === $.group).array(normalizeColumnName(measure));
32
- });
33
- });
34
- return results;
35
- }, [data, filtersProp, groupByProp, measures]);
36
- return chartData;
37
- };
38
- export {
39
- useBoxplotData
4
+ //#region src/Boxplot/useBoxplotData.tsx
5
+ var useBoxplotData = ({ data, groupBy: groupByProp, measures, filters: filtersProp }) => {
6
+ return useMemo(() => {
7
+ const { data: processedData } = processTableData(data);
8
+ let tableData = processedData;
9
+ if (filtersProp) {
10
+ const filters = (Array.isArray(filtersProp) ? filtersProp : [filtersProp]).map((filter) => ({
11
+ ...filter,
12
+ field: normalizeColumnName(filter.field)
13
+ }));
14
+ tableData = tableData.filter(escape((row) => getHvArqueroCombinedFilters(row, filters)));
15
+ }
16
+ const normalizedGroupBy = normalizeColumnName(groupByProp || "");
17
+ const uniqueGroupBy = new Set(tableData.array(normalizedGroupBy));
18
+ const results = {};
19
+ uniqueGroupBy.forEach((group) => {
20
+ results[group] = {};
21
+ Object.keys(measures).forEach((measure) => {
22
+ results[group][measure] = tableData.params({
23
+ group,
24
+ groupBy: normalizedGroupBy
25
+ }).filter((d, $) => d[$.groupBy] === $.group).array(normalizeColumnName(measure));
26
+ });
27
+ });
28
+ return results;
29
+ }, [
30
+ data,
31
+ filtersProp,
32
+ groupByProp,
33
+ measures
34
+ ]);
40
35
  };
36
+ //#endregion
37
+ export { useBoxplotData };
@@ -1,79 +1,64 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef, useMemo } from "react";
3
- import { HeatmapChart } from "echarts/charts";
4
- import { VisualMapComponent, GridComponent, TooltipComponent } from "echarts/components";
5
- import * as echarts from "echarts/core";
1
+ import { HvBaseChart } from "../BaseChart/BaseChart.js";
6
2
  import { getGroupKey } from "../utils/index.js";
7
- import { useClasses } from "./ConfusionMatrix.styles.js";
8
- import { useColorScale, useSeries, useGridLayout } from "./utils.js";
9
- import { useVisualMap } from "../hooks/useVisualMap.js";
10
- import { useData } from "../hooks/useData.js";
11
- import { useTooltip } from "../hooks/tooltip/useTooltip.js";
12
- import { useYAxis } from "../hooks/useYAxis.js";
13
3
  import { useXAxis } from "../hooks/useXAxis.js";
4
+ import { useYAxis } from "../hooks/useYAxis.js";
14
5
  import { useGrid } from "../hooks/useGrid.js";
6
+ import { useData } from "../hooks/useData.js";
7
+ import { useVisualMap } from "../hooks/useVisualMap.js";
8
+ import { useTooltip } from "../hooks/tooltip/useTooltip.js";
15
9
  import { useOption } from "../hooks/useOption.js";
16
- import { HvBaseChart } from "../BaseChart/BaseChart.js";
10
+ import { useClasses } from "./ConfusionMatrix.styles.js";
11
+ import { useColorScale, useGridLayout, useSeries } from "./utils.js";
12
+ import { forwardRef, useMemo } from "react";
13
+ import { GridComponent, TooltipComponent, VisualMapComponent } from "echarts/components";
14
+ import * as echarts from "echarts/core";
15
+ import { jsx } from "react/jsx-runtime";
16
+ import { HeatmapChart } from "echarts/charts";
17
+ //#region src/ConfusionMatrix/ConfusionMatrix.tsx
17
18
  echarts.use([
18
- HeatmapChart,
19
- VisualMapComponent,
20
- GridComponent,
21
- TooltipComponent
19
+ HeatmapChart,
20
+ VisualMapComponent,
21
+ GridComponent,
22
+ TooltipComponent
22
23
  ]);
23
- const HvConfusionMatrix = forwardRef(function HvConfusionMatrix2(props, ref) {
24
- const {
25
- legend,
26
- groupBy,
27
- measure,
28
- sortBy,
29
- splitBy,
30
- filters,
31
- grid,
32
- data: dataProp,
33
- tooltip,
34
- xAxis,
35
- yAxis,
36
- colorScale: colorScaleProp,
37
- delta,
38
- valuesProps,
39
- width,
40
- height,
41
- format = "square",
42
- classes: classesProp,
43
- onOptionChange,
44
- ...others
45
- } = props;
46
- const { classes } = useClasses(classesProp);
47
- const groupByKey = getGroupKey(groupBy);
48
- const { data: chartData } = useData({
49
- data: dataProp,
50
- groupBy,
51
- measures: [measure],
52
- sortBy: sortBy ?? groupBy,
53
- // automatically orders x axis to create the confusion matrix
54
- splitBy,
55
- filters,
56
- delta: typeof delta === "string" ? delta : void 0
57
- });
58
- const colorScale = useColorScale({
59
- delta: !!delta,
60
- data: chartData,
61
- custom: colorScaleProp,
62
- filterKey: groupByKey
63
- });
64
- const chartVisualMap = useVisualMap({
65
- show: colorScale?.pieces != null,
66
- type: colorScale?.pieces != null ? "piecewise" : "continuous",
67
- ...colorScale,
68
- ...legend
69
- });
70
- const chartTooltip = useTooltip({
71
- component: (params) => {
72
- const value = params?.series?.[0].value;
73
- const fmtValue = typeof measure !== "string" && measure.valueFormatter ? measure.valueFormatter(value) : tooltip?.valueFormatter ? tooltip?.valueFormatter(value) : value;
74
- const ftmTitle = tooltip?.titleFormatter ? tooltip.titleFormatter(params?.title) : params?.title;
75
- const content = `${ftmTitle} - ${params?.series?.[0].name}: ${fmtValue}`;
76
- return `
24
+ /**
25
+ * A Confusion Matrix is a table used to evaluate the performance of a predictive model.
26
+ * Rows represent the actual classes, and columns show the predicted classes.
27
+ *
28
+ * - The diagonal cells show correct predictions and off-diagonal cells represent misclassifications.
29
+ *
30
+ */
31
+ var HvConfusionMatrix = forwardRef(function HvConfusionMatrix(props, ref) {
32
+ const { legend, groupBy, measure, sortBy, splitBy, filters, grid, data: dataProp, tooltip, xAxis, yAxis, colorScale: colorScaleProp, delta, valuesProps, width, height, format = "square", classes: classesProp, onOptionChange, ...others } = props;
33
+ const { classes } = useClasses(classesProp);
34
+ const groupByKey = getGroupKey(groupBy);
35
+ const { data: chartData } = useData({
36
+ data: dataProp,
37
+ groupBy,
38
+ measures: [measure],
39
+ sortBy: sortBy ?? groupBy,
40
+ splitBy,
41
+ filters,
42
+ delta: typeof delta === "string" ? delta : void 0
43
+ });
44
+ const colorScale = useColorScale({
45
+ delta: !!delta,
46
+ data: chartData,
47
+ custom: colorScaleProp,
48
+ filterKey: groupByKey
49
+ });
50
+ const chartVisualMap = useVisualMap({
51
+ show: colorScale?.pieces != null,
52
+ type: colorScale?.pieces != null ? "piecewise" : "continuous",
53
+ ...colorScale,
54
+ ...legend
55
+ });
56
+ const chartTooltip = useTooltip({
57
+ component: (params) => {
58
+ const value = params?.series?.[0].value;
59
+ const fmtValue = typeof measure !== "string" && measure.valueFormatter ? measure.valueFormatter(value) : tooltip?.valueFormatter ? tooltip?.valueFormatter(value) : value;
60
+ const content = `${tooltip?.titleFormatter ? tooltip.titleFormatter(params?.title) : params?.title} - ${params?.series?.[0].name}: ${fmtValue}`;
61
+ return `
77
62
  <div class="${classes.tooltipRoot}">
78
63
  <div class="${classes.tooltipContainer}">
79
64
  <div>
@@ -81,84 +66,100 @@ const HvConfusionMatrix = forwardRef(function HvConfusionMatrix2(props, ref) {
81
66
  </div>
82
67
  </div>
83
68
  </div>`;
84
- },
85
- ...tooltip
86
- });
87
- const chartYAxis = useYAxis({
88
- axes: [
89
- {
90
- type: "categorical",
91
- name: "True Label",
92
- position: "left",
93
- ...yAxis,
94
- nameProps: {
95
- location: "center",
96
- padding: yAxis?.nameProps?.location == null || yAxis?.nameProps?.location === "center" ? yAxis?.position === "right" ? [50, 0, 0, 0] : [0, 0, 50, 0] : void 0,
97
- ...yAxis?.nameProps
98
- },
99
- data: chartData.columnNames().filter((p) => p !== groupByKey).toReversed()
100
- }
101
- ]
102
- });
103
- const chartXAxis = useXAxis({
104
- name: "Predicted Value",
105
- position: "top",
106
- ...xAxis,
107
- nameProps: {
108
- location: "center",
109
- padding: xAxis?.nameProps?.location == null || xAxis?.nameProps?.location === "center" ? xAxis?.position === "bottom" ? [30, 0, 0, 0] : [0, 0, 30, 0] : void 0,
110
- ...xAxis?.nameProps
111
- },
112
- data: chartData.array(groupByKey)
113
- });
114
- const chartSeries = useSeries({
115
- data: chartData,
116
- filterKey: groupByKey,
117
- valuesProps,
118
- delta: !!(delta && colorScale == null)
119
- });
120
- const chartGridLayout = useGridLayout({
121
- data: chartData,
122
- format,
123
- filterKey: groupByKey,
124
- visualMapVisible: chartVisualMap.visualMap.show,
125
- visualMapYPosition: chartVisualMap.visualMap.top,
126
- xAxisPosition: chartXAxis.xAxis.position
127
- });
128
- const chartGrid = useGrid({
129
- // If sizes are provided, the grid size should automatically adapt to the values provided
130
- width: width != null ? void 0 : chartGridLayout.size.width,
131
- height: height != null ? void 0 : chartGridLayout.size.height,
132
- ...chartGridLayout.padding,
133
- ...grid
134
- });
135
- const size = useMemo(() => {
136
- return {
137
- width,
138
- // Echarts has a problem were the height is always set to 300px
139
- // Thus, we need to update the height to make sure the chart is not cut out
140
- height: height ?? chartGridLayout.size.height + chartGridLayout.padding.bottom + chartGridLayout.padding.top
141
- };
142
- }, [
143
- chartGridLayout.padding.bottom,
144
- chartGridLayout.padding.top,
145
- chartGridLayout.size.height,
146
- height,
147
- width
148
- ]);
149
- const option = useOption({
150
- option: {
151
- ...chartVisualMap,
152
- ...chartTooltip,
153
- ...chartGrid,
154
- ...chartXAxis,
155
- ...chartYAxis,
156
- ...chartSeries
157
- },
158
- onOptionChange
159
- });
160
- return /* @__PURE__ */ jsx(HvBaseChart, { ref, option, ...size, ...others });
69
+ },
70
+ ...tooltip
71
+ });
72
+ const chartYAxis = useYAxis({ axes: [{
73
+ type: "categorical",
74
+ name: "True Label",
75
+ position: "left",
76
+ ...yAxis,
77
+ nameProps: {
78
+ location: "center",
79
+ padding: yAxis?.nameProps?.location == null || yAxis?.nameProps?.location === "center" ? yAxis?.position === "right" ? [
80
+ 50,
81
+ 0,
82
+ 0,
83
+ 0
84
+ ] : [
85
+ 0,
86
+ 0,
87
+ 50,
88
+ 0
89
+ ] : void 0,
90
+ ...yAxis?.nameProps
91
+ },
92
+ data: chartData.columnNames().filter((p) => p !== groupByKey).toReversed()
93
+ }] });
94
+ const chartXAxis = useXAxis({
95
+ name: "Predicted Value",
96
+ position: "top",
97
+ ...xAxis,
98
+ nameProps: {
99
+ location: "center",
100
+ padding: xAxis?.nameProps?.location == null || xAxis?.nameProps?.location === "center" ? xAxis?.position === "bottom" ? [
101
+ 30,
102
+ 0,
103
+ 0,
104
+ 0
105
+ ] : [
106
+ 0,
107
+ 0,
108
+ 30,
109
+ 0
110
+ ] : void 0,
111
+ ...xAxis?.nameProps
112
+ },
113
+ data: chartData.array(groupByKey)
114
+ });
115
+ const chartSeries = useSeries({
116
+ data: chartData,
117
+ filterKey: groupByKey,
118
+ valuesProps,
119
+ delta: !!(delta && colorScale == null)
120
+ });
121
+ const chartGridLayout = useGridLayout({
122
+ data: chartData,
123
+ format,
124
+ filterKey: groupByKey,
125
+ visualMapVisible: chartVisualMap.visualMap.show,
126
+ visualMapYPosition: chartVisualMap.visualMap.top,
127
+ xAxisPosition: chartXAxis.xAxis.position
128
+ });
129
+ const chartGrid = useGrid({
130
+ width: width != null ? void 0 : chartGridLayout.size.width,
131
+ height: height != null ? void 0 : chartGridLayout.size.height,
132
+ ...chartGridLayout.padding,
133
+ ...grid
134
+ });
135
+ const size = useMemo(() => {
136
+ return {
137
+ width,
138
+ height: height ?? chartGridLayout.size.height + chartGridLayout.padding.bottom + chartGridLayout.padding.top
139
+ };
140
+ }, [
141
+ chartGridLayout.padding.bottom,
142
+ chartGridLayout.padding.top,
143
+ chartGridLayout.size.height,
144
+ height,
145
+ width
146
+ ]);
147
+ return /* @__PURE__ */ jsx(HvBaseChart, {
148
+ ref,
149
+ option: useOption({
150
+ option: {
151
+ ...chartVisualMap,
152
+ ...chartTooltip,
153
+ ...chartGrid,
154
+ ...chartXAxis,
155
+ ...chartYAxis,
156
+ ...chartSeries
157
+ },
158
+ onOptionChange
159
+ }),
160
+ ...size,
161
+ ...others
162
+ });
161
163
  });
162
- export {
163
- HvConfusionMatrix
164
- };
164
+ //#endregion
165
+ export { HvConfusionMatrix };
@@ -1,29 +1,25 @@
1
1
  import { createClasses } from "@hitachivantara/uikit-react-utils";
2
2
  import { theme } from "@hitachivantara/uikit-styles";
3
- const { useClasses, staticClasses } = createClasses(
4
- "HvConfusionMatrix",
5
- {
6
- tooltipRoot: {
7
- backgroundColor: theme.colors.bgContainer,
8
- width: "fit-content",
9
- minWidth: 150,
10
- boxShadow: theme.colors.shadow,
11
- zIndex: theme.zIndices.sticky
12
- },
13
- tooltipContainer: {
14
- padding: theme.spacing("15px", "sm"),
15
- display: "flex",
16
- flexDirection: "column"
17
- },
18
- tooltipText: {
19
- fontFamily: theme.fontFamily.body,
20
- fontWeight: theme.fontWeights.normal,
21
- fontSize: theme.fontSizes.sm,
22
- color: theme.colors.text
23
- }
24
- }
25
- );
26
- export {
27
- staticClasses,
28
- useClasses
29
- };
3
+ //#region src/ConfusionMatrix/ConfusionMatrix.styles.tsx
4
+ var { useClasses, staticClasses } = createClasses("HvConfusionMatrix", {
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
+ }
23
+ });
24
+ //#endregion
25
+ export { useClasses };