@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,24 +1,44 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { createContext, useMemo, useContext } from "react";
3
- import { useTheme } from "@hitachivantara/uikit-react-utils";
4
1
  import { registerTheme } from "../utils/registerTheme.js";
5
- const HvVizContext = createContext({
6
- theme: void 0
7
- });
8
- const HvVizProvider = ({ children }) => {
9
- const { activeTheme, selectedMode } = useTheme();
10
- const value = useMemo(() => {
11
- const themeName = `${activeTheme?.name}-${selectedMode}`;
12
- registerTheme(themeName, selectedMode, activeTheme);
13
- return { theme: themeName, activeTheme };
14
- }, [selectedMode, activeTheme]);
15
- return /* @__PURE__ */ jsx(HvVizContext.Provider, { value, children });
16
- };
17
- const useVizTheme = () => {
18
- return useContext(HvVizContext);
2
+ import { createContext, useContext, useMemo } from "react";
3
+ import { useTheme } from "@hitachivantara/uikit-react-utils";
4
+ import { jsx } from "react/jsx-runtime";
5
+ //#region src/providers/Provider.tsx
6
+ var HvVizContext = createContext({ theme: void 0 });
7
+ /**
8
+ * Enables theming capabilities for visualizations.
9
+ *
10
+ * Without this provider the visualizations will not comply to the UI Kit themes.
11
+ *
12
+ * This provider should always be used in combination with the `HvProvider` from
13
+ * the core package since the former uses the themes provided by the latter.
14
+ *
15
+ * `HvVizProvider` should always be used after `HvProvider` like so to work properly:
16
+ *
17
+ * ```
18
+ * <HvProvider>
19
+ * <HvVizProvider>
20
+ * (...)
21
+ * </HvVizProvider>
22
+ * </HvProvider>
23
+ * ```
24
+ */
25
+ var HvVizProvider = ({ children }) => {
26
+ const { activeTheme, selectedMode } = useTheme();
27
+ const value = useMemo(() => {
28
+ const themeName = `${activeTheme?.name}-${selectedMode}`;
29
+ registerTheme(themeName, selectedMode, activeTheme);
30
+ return {
31
+ theme: themeName,
32
+ activeTheme
33
+ };
34
+ }, [selectedMode, activeTheme]);
35
+ return /* @__PURE__ */ jsx(HvVizContext.Provider, {
36
+ value,
37
+ children
38
+ });
19
39
  };
20
- export {
21
- HvVizContext,
22
- HvVizProvider,
23
- useVizTheme
40
+ var useVizTheme = () => {
41
+ return useContext(HvVizContext);
24
42
  };
43
+ //#endregion
44
+ export { HvVizContext, HvVizProvider, useVizTheme };
@@ -1,193 +1,127 @@
1
- import { internal, from, table } from "arquero";
2
- const getAxisType = (type) => {
3
- switch (type) {
4
- case "categorical":
5
- return "category";
6
- case "time":
7
- return "time";
8
- case "continuous":
9
- return "value";
10
- default:
11
- return void 0;
12
- }
1
+ import { from, internal, table } from "arquero";
2
+ //#region src/utils/index.ts
3
+ var getAxisType = (type) => {
4
+ switch (type) {
5
+ case "categorical": return "category";
6
+ case "time": return "time";
7
+ case "continuous": return "value";
8
+ default: return;
9
+ }
13
10
  };
14
- const getGroupKey = (groupBy) => Array.isArray(groupBy) ? groupBy.join("_") : groupBy;
15
- const getLegendIcon = (icon) => {
16
- switch (icon) {
17
- case "circle":
18
- return "circle";
19
- case "square":
20
- return "path://M0,0L16,0L16,16L0,16L0,0Z";
21
- case "line":
22
- default:
23
- return "path://M0,0L16,0L16,2L0,2Z";
24
- }
11
+ var getGroupKey = (groupBy) => Array.isArray(groupBy) ? groupBy.join("_") : groupBy;
12
+ var getLegendIcon = (icon) => {
13
+ switch (icon) {
14
+ case "circle": return "circle";
15
+ case "square": return "path://M0,0L16,0L16,16L0,16L0,0Z";
16
+ default: return "path://M0,0L16,0L16,2L0,2Z";
17
+ }
25
18
  };
26
- const getMeasure = (name, mapping) => {
27
- let measure;
28
- let count = 0;
29
- for (const key of Object.keys(mapping)) {
30
- if (name.includes(key) && key.length >= count) {
31
- count = key.length;
32
- measure = mapping[key];
33
- }
34
- }
35
- return measure ?? Object.values(mapping)[0];
19
+ var getMeasure = (name, mapping) => {
20
+ let measure;
21
+ let count = 0;
22
+ for (const key of Object.keys(mapping)) if (name.includes(key) && key.length >= count) {
23
+ count = key.length;
24
+ measure = mapping[key];
25
+ }
26
+ return measure ?? Object.values(mapping)[0];
36
27
  };
37
- const getFilterFunction = (operation, field, value) => {
38
- const valueArray = Array.isArray(value) ? value : [value];
39
- if (valueArray.length === 0) return () => true;
40
- switch (operation) {
41
- case "is": {
42
- return (row) => valueArray.includes(row[field]);
43
- }
44
- case "isNot": {
45
- return (row) => !valueArray.includes(row[field]);
46
- }
47
- case "contains":
48
- return (row) => {
49
- let include = false;
50
- for (const val of valueArray) {
51
- if (String(row[field]).includes(String(val))) {
52
- include = true;
53
- }
54
- }
55
- return include;
56
- };
57
- case "notContains":
58
- return (row) => {
59
- let include = true;
60
- for (const val of valueArray) {
61
- if (String(row[field]).includes(String(val))) {
62
- include = false;
63
- }
64
- }
65
- return include;
66
- };
67
- case "greaterThan":
68
- return (row) => {
69
- let include = false;
70
- for (const val of valueArray) {
71
- if (row[field] > val) {
72
- include = true;
73
- }
74
- }
75
- return include;
76
- };
77
- case "greaterThanOrEqual":
78
- return (row) => {
79
- let include = false;
80
- for (const val of valueArray) {
81
- if (row[field] >= val) {
82
- include = true;
83
- }
84
- }
85
- return include;
86
- };
87
- case "lessThan":
88
- return (row) => {
89
- let include = false;
90
- for (const val of valueArray) {
91
- if (row[field] < val) {
92
- include = true;
93
- }
94
- }
95
- return include;
96
- };
97
- case "lessThanOrEqual":
98
- return (row) => {
99
- let include = false;
100
- for (const val of valueArray) {
101
- if (row[field] <= val) {
102
- include = true;
103
- }
104
- }
105
- return include;
106
- };
107
- case "between":
108
- return (row) => row[field] >= valueArray[0] && row[field] <= valueArray[1];
109
- case "ends":
110
- return (row) => {
111
- let include = false;
112
- for (const val of valueArray) {
113
- if (String(row[field]).endsWith(String(val))) {
114
- include = true;
115
- }
116
- }
117
- return include;
118
- };
119
- case "notEnds":
120
- return (row) => {
121
- let include = true;
122
- for (const val of valueArray) {
123
- if (String(row[field]).endsWith(String(val))) {
124
- include = false;
125
- }
126
- }
127
- return include;
128
- };
129
- case "starts":
130
- return (row) => {
131
- let include = false;
132
- for (const val of valueArray) {
133
- if (String(row[field]).startsWith(String(val))) {
134
- include = true;
135
- }
136
- }
137
- return include;
138
- };
139
- case "notStarts":
140
- return (row) => {
141
- let include = true;
142
- for (const val of valueArray) {
143
- if (String(row[field]).startsWith(String(val))) {
144
- include = false;
145
- }
146
- }
147
- return include;
148
- };
149
- default:
150
- throw new Error("Unsupported operation");
151
- }
28
+ var getFilterFunction = (operation, field, value) => {
29
+ const valueArray = Array.isArray(value) ? value : [value];
30
+ if (valueArray.length === 0) return () => true;
31
+ switch (operation) {
32
+ case "is": return (row) => valueArray.includes(row[field]);
33
+ case "isNot": return (row) => !valueArray.includes(row[field]);
34
+ case "contains": return (row) => {
35
+ let include = false;
36
+ for (const val of valueArray) if (String(row[field]).includes(String(val))) include = true;
37
+ return include;
38
+ };
39
+ case "notContains": return (row) => {
40
+ let include = true;
41
+ for (const val of valueArray) if (String(row[field]).includes(String(val))) include = false;
42
+ return include;
43
+ };
44
+ case "greaterThan": return (row) => {
45
+ let include = false;
46
+ for (const val of valueArray) if (row[field] > val) include = true;
47
+ return include;
48
+ };
49
+ case "greaterThanOrEqual": return (row) => {
50
+ let include = false;
51
+ for (const val of valueArray) if (row[field] >= val) include = true;
52
+ return include;
53
+ };
54
+ case "lessThan": return (row) => {
55
+ let include = false;
56
+ for (const val of valueArray) if (row[field] < val) include = true;
57
+ return include;
58
+ };
59
+ case "lessThanOrEqual": return (row) => {
60
+ let include = false;
61
+ for (const val of valueArray) if (row[field] <= val) include = true;
62
+ return include;
63
+ };
64
+ case "between": return (row) => row[field] >= valueArray[0] && row[field] <= valueArray[1];
65
+ case "ends": return (row) => {
66
+ let include = false;
67
+ for (const val of valueArray) if (String(row[field]).endsWith(String(val))) include = true;
68
+ return include;
69
+ };
70
+ case "notEnds": return (row) => {
71
+ let include = true;
72
+ for (const val of valueArray) if (String(row[field]).endsWith(String(val))) include = false;
73
+ return include;
74
+ };
75
+ case "starts": return (row) => {
76
+ let include = false;
77
+ for (const val of valueArray) if (String(row[field]).startsWith(String(val))) include = true;
78
+ return include;
79
+ };
80
+ case "notStarts": return (row) => {
81
+ let include = true;
82
+ for (const val of valueArray) if (String(row[field]).startsWith(String(val))) include = false;
83
+ return include;
84
+ };
85
+ default: throw new Error("Unsupported operation");
86
+ }
152
87
  };
153
- const getHvArqueroCombinedFilters = (row, filters) => {
154
- return filters.every((filter) => {
155
- const { field, operation, value } = filter;
156
- const filterFunction = Object.hasOwn(row, field) ? getFilterFunction(operation, field, value) : () => true;
157
- return filterFunction(row);
158
- });
88
+ /**
89
+ * Combine filter functions into a single function. Only rows that pass all filters will be included.
90
+ * Should be used inside the `escape` function provided by Arquero.
91
+ * */
92
+ var getHvArqueroCombinedFilters = (row, filters) => {
93
+ return filters.every((filter) => {
94
+ const { field, operation, value } = filter;
95
+ return (Object.hasOwn(row, field) ? getFilterFunction(operation, field, value) : () => true)(row);
96
+ });
159
97
  };
160
- const normalizeColumnName = (string) => {
161
- return string.replace(/[^a-zA-Z0-9]/g, "__");
98
+ /**
99
+ * Normalizes a column name by replacing all characters that are not letters or numbers by "__"
100
+ */
101
+ var normalizeColumnName = (string) => {
102
+ return string.replace(/[^a-zA-Z0-9]/g, "__");
162
103
  };
163
- const processTableData = (data) => {
164
- let tableData;
165
- if (data instanceof internal.ColumnTable) {
166
- tableData = data;
167
- } else if (Array.isArray(data)) {
168
- tableData = from(data);
169
- } else {
170
- tableData = table(data);
171
- }
172
- const nameMapping = {};
173
- const reversedNameMapping = {};
174
- for (const column of tableData.columnNames()) {
175
- const normalizedName = normalizeColumnName(column);
176
- nameMapping[column] = normalizedName;
177
- reversedNameMapping[normalizedName] = column;
178
- }
179
- return {
180
- data: tableData.select(nameMapping),
181
- mapping: reversedNameMapping
182
- };
183
- };
184
- export {
185
- getAxisType,
186
- getFilterFunction,
187
- getGroupKey,
188
- getHvArqueroCombinedFilters,
189
- getLegendIcon,
190
- getMeasure,
191
- normalizeColumnName,
192
- processTableData
104
+ /**
105
+ * Converts data to a arquero data table and normalizes the column names for data processing.
106
+ * @param data Chart data
107
+ * @returns Processed data and reversed columns mapping to switch the columns to their original name
108
+ */
109
+ var processTableData = (data) => {
110
+ let tableData;
111
+ if (data instanceof internal.ColumnTable) tableData = data;
112
+ else if (Array.isArray(data)) tableData = from(data);
113
+ else tableData = table(data);
114
+ const nameMapping = {};
115
+ const reversedNameMapping = {};
116
+ for (const column of tableData.columnNames()) {
117
+ const normalizedName = normalizeColumnName(column);
118
+ nameMapping[column] = normalizedName;
119
+ reversedNameMapping[normalizedName] = column;
120
+ }
121
+ return {
122
+ data: tableData.select(nameMapping),
123
+ mapping: reversedNameMapping
124
+ };
193
125
  };
126
+ //#endregion
127
+ export { getAxisType, getGroupKey, getHvArqueroCombinedFilters, getLegendIcon, getMeasure, normalizeColumnName, processTableData };
@@ -1,124 +1,86 @@
1
1
  import * as echarts from "echarts/core";
2
- const registerTheme = (themeName, mode, themeStructure) => {
3
- const colors = themeStructure?.colors[mode];
4
- if (!colors) return;
5
- const baseText = {
6
- color: colors?.text,
7
- fontWeight: themeStructure?.fontWeights.normal,
8
- fontSize: themeStructure?.fontSizes.sm,
9
- fontFamily: themeStructure?.fontFamily.body
10
- };
11
- const customAxis = {
12
- nameTextStyle: {
13
- ...baseText,
14
- color: colors?.textSubtle
15
- },
16
- axisLine: {
17
- show: true,
18
- lineStyle: {
19
- color: colors?.borderSubtle
20
- }
21
- },
22
- axisTick: {
23
- show: true,
24
- lineStyle: {
25
- color: colors?.borderSubtle
26
- }
27
- },
28
- axisLabel: {
29
- color: colors?.textSubtle,
30
- fontWeight: themeStructure?.fontWeights.normal,
31
- fontSize: themeStructure?.fontSizes.sm,
32
- fontFamily: themeStructure?.fontFamily.body
33
- },
34
- splitLine: {
35
- show: true,
36
- lineStyle: {
37
- color: colors?.borderSubtle
38
- }
39
- }
40
- };
41
- echarts.registerTheme(themeName, {
42
- color: [
43
- colors?.cat1,
44
- colors?.cat2,
45
- colors?.cat3,
46
- colors?.cat4,
47
- colors?.cat5,
48
- colors?.cat6,
49
- colors?.cat7,
50
- colors?.cat8,
51
- colors?.cat9,
52
- colors?.cat10,
53
- colors?.cat11,
54
- colors?.cat12
55
- ],
56
- legend: {
57
- textStyle: {
58
- ...baseText
59
- }
60
- },
61
- tooltip: {
62
- borderWidth: 0,
63
- padding: 0,
64
- textStyle: {
65
- ...baseText
66
- },
67
- axisPointer: {
68
- lineStyle: {
69
- color: colors?.text,
70
- width: 1
71
- }
72
- }
73
- },
74
- dataZoom: {
75
- textStyle: { ...baseText }
76
- },
77
- categoryAxis: {
78
- ...customAxis
79
- },
80
- valueAxis: {
81
- ...customAxis
82
- },
83
- logAxis: {
84
- ...customAxis
85
- },
86
- timeAxis: {
87
- ...customAxis
88
- },
89
- line: {
90
- lineStyle: {
91
- width: 2
92
- }
93
- },
94
- visualMap: {
95
- textStyle: {
96
- ...baseText
97
- }
98
- },
99
- heatmap: {
100
- label: {
101
- fontWeight: baseText.fontWeight,
102
- fontSize: baseText.fontSize,
103
- fontFamily: baseText.fontFamily
104
- },
105
- itemStyle: {
106
- borderColor: colors?.borderSubtle,
107
- borderWidth: 1
108
- }
109
- },
110
- treemap: {
111
- breadcrumb: {
112
- itemStyle: {
113
- color: colors?.text,
114
- textStyle: {
115
- color: colors?.bgContainer
116
- }
117
- }
118
- }
119
- }
120
- });
121
- };
122
- export {
123
- registerTheme
2
+ //#region src/utils/registerTheme.ts
3
+ var registerTheme = (themeName, mode, themeStructure) => {
4
+ const colors = themeStructure?.colors[mode];
5
+ if (!colors) return;
6
+ const baseText = {
7
+ color: colors?.text,
8
+ fontWeight: themeStructure?.fontWeights.normal,
9
+ fontSize: themeStructure?.fontSizes.sm,
10
+ fontFamily: themeStructure?.fontFamily.body
11
+ };
12
+ const customAxis = {
13
+ nameTextStyle: {
14
+ ...baseText,
15
+ color: colors?.textSubtle
16
+ },
17
+ axisLine: {
18
+ show: true,
19
+ lineStyle: { color: colors?.borderSubtle }
20
+ },
21
+ axisTick: {
22
+ show: true,
23
+ lineStyle: { color: colors?.borderSubtle }
24
+ },
25
+ axisLabel: {
26
+ color: colors?.textSubtle,
27
+ fontWeight: themeStructure?.fontWeights.normal,
28
+ fontSize: themeStructure?.fontSizes.sm,
29
+ fontFamily: themeStructure?.fontFamily.body
30
+ },
31
+ splitLine: {
32
+ show: true,
33
+ lineStyle: { color: colors?.borderSubtle }
34
+ }
35
+ };
36
+ echarts.registerTheme(themeName, {
37
+ color: [
38
+ colors?.cat1,
39
+ colors?.cat2,
40
+ colors?.cat3,
41
+ colors?.cat4,
42
+ colors?.cat5,
43
+ colors?.cat6,
44
+ colors?.cat7,
45
+ colors?.cat8,
46
+ colors?.cat9,
47
+ colors?.cat10,
48
+ colors?.cat11,
49
+ colors?.cat12
50
+ ],
51
+ legend: { textStyle: { ...baseText } },
52
+ tooltip: {
53
+ borderWidth: 0,
54
+ padding: 0,
55
+ textStyle: { ...baseText },
56
+ axisPointer: { lineStyle: {
57
+ color: colors?.text,
58
+ width: 1
59
+ } }
60
+ },
61
+ dataZoom: { textStyle: { ...baseText } },
62
+ categoryAxis: { ...customAxis },
63
+ valueAxis: { ...customAxis },
64
+ logAxis: { ...customAxis },
65
+ timeAxis: { ...customAxis },
66
+ line: { lineStyle: { width: 2 } },
67
+ visualMap: { textStyle: { ...baseText } },
68
+ heatmap: {
69
+ label: {
70
+ fontWeight: baseText.fontWeight,
71
+ fontSize: baseText.fontSize,
72
+ fontFamily: baseText.fontFamily
73
+ },
74
+ itemStyle: {
75
+ borderColor: colors?.borderSubtle,
76
+ borderWidth: 1
77
+ }
78
+ },
79
+ treemap: { breadcrumb: { itemStyle: {
80
+ color: colors?.text,
81
+ textStyle: { color: colors?.bgContainer }
82
+ } } }
83
+ });
124
84
  };
85
+ //#endregion
86
+ export { registerTheme };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitachivantara/uikit-react-viz",
3
- "version": "6.1.6",
3
+ "version": "6.1.7",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "author": "Hitachi Vantara UI Kit Team",
@@ -34,8 +34,8 @@
34
34
  "react-dom": ">=18.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@hitachivantara/uikit-react-utils": "^6.2.2",
38
- "@hitachivantara/uikit-styles": "^6.1.0"
37
+ "@hitachivantara/uikit-react-utils": "^6.2.3",
38
+ "@hitachivantara/uikit-styles": "^6.1.1"
39
39
  },
40
40
  "files": [
41
41
  "dist"
@@ -44,7 +44,7 @@
44
44
  "access": "public",
45
45
  "directory": "package"
46
46
  },
47
- "gitHead": "f79885f320f5cdf5b438ef8b2e866965c9626ce7",
47
+ "gitHead": "65c4f4394e8f8c7cccb58203e1c08c6832434638",
48
48
  "exports": {
49
49
  ".": {
50
50
  "types": "./dist/index.d.ts",