@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,46 +1,37 @@
1
- import { useMemo } from "react";
2
1
  import { getLegendIcon } from "../utils/index.js";
3
- const useLegend = ({
4
- series,
5
- show,
6
- icon,
7
- formatter,
8
- position: positionProp,
9
- direction = "horizontal"
10
- }) => {
11
- const option = useMemo(() => {
12
- const position = {
13
- y: positionProp?.y ?? "top",
14
- x: positionProp?.x ?? "center"
15
- };
16
- return {
17
- legend: {
18
- show: show ?? (Array.isArray(series) && series.length > 1),
19
- itemGap: 20,
20
- formatter,
21
- orient: direction,
22
- ...position,
23
- ...icon && { icon: getLegendIcon(icon) },
24
- ...!icon && {
25
- data: show !== false && Array.isArray(series) ? series.map((s) => {
26
- let iconType = "line";
27
- if (s.areaStyle != null) {
28
- iconType = "square";
29
- }
30
- if (s.type === "scatter") {
31
- iconType = "circle";
32
- }
33
- return {
34
- name: s.name,
35
- icon: getLegendIcon(iconType)
36
- };
37
- }) : void 0
38
- }
39
- }
40
- };
41
- }, [series, show, icon, formatter, positionProp, direction]);
42
- return option;
43
- };
44
- export {
45
- useLegend
2
+ import { useMemo } from "react";
3
+ //#region src/hooks/useLegend.tsx
4
+ var useLegend = ({ series, show, icon, formatter, position: positionProp, direction = "horizontal" }) => {
5
+ return useMemo(() => {
6
+ const position = {
7
+ y: positionProp?.y ?? "top",
8
+ x: positionProp?.x ?? "center"
9
+ };
10
+ return { legend: {
11
+ show: show ?? (Array.isArray(series) && series.length > 1),
12
+ itemGap: 20,
13
+ formatter,
14
+ orient: direction,
15
+ ...position,
16
+ ...icon && { icon: getLegendIcon(icon) },
17
+ ...!icon && { data: show !== false && Array.isArray(series) ? series.map((s) => {
18
+ let iconType = "line";
19
+ if (s.areaStyle != null) iconType = "square";
20
+ if (s.type === "scatter") iconType = "circle";
21
+ return {
22
+ name: s.name,
23
+ icon: getLegendIcon(iconType)
24
+ };
25
+ }) : void 0 }
26
+ } };
27
+ }, [
28
+ series,
29
+ show,
30
+ icon,
31
+ formatter,
32
+ positionProp,
33
+ direction
34
+ ]);
46
35
  };
36
+ //#endregion
37
+ export { useLegend };
@@ -1,20 +1,14 @@
1
1
  import { useMemo } from "react";
2
- const useOption = ({
3
- option: optionProp,
4
- onOptionChange
5
- }) => {
6
- const option = useMemo(() => {
7
- const baseOption = {
8
- aria: {
9
- enabled: true
10
- },
11
- animation: false
12
- };
13
- const opt = { ...baseOption, ...optionProp };
14
- return onOptionChange ? onOptionChange(opt) : opt;
15
- }, [onOptionChange, optionProp]);
16
- return option;
17
- };
18
- export {
19
- useOption
2
+ //#region src/hooks/useOption.ts
3
+ var useOption = ({ option: optionProp, onOptionChange }) => {
4
+ return useMemo(() => {
5
+ const opt = {
6
+ aria: { enabled: true },
7
+ animation: false,
8
+ ...optionProp
9
+ };
10
+ return onOptionChange ? onOptionChange(opt) : opt;
11
+ }, [onOptionChange, optionProp]);
20
12
  };
13
+ //#endregion
14
+ export { useOption };
@@ -1,119 +1,86 @@
1
- import { useMemo } from "react";
2
1
  import { getGroupKey, getMeasure } from "../utils/index.js";
3
- const useSeries = ({
4
- groupBy,
5
- type,
6
- data,
7
- measuresMapping,
8
- nameFormatter,
9
- stack,
10
- emptyCellMode,
11
- radius,
12
- horizontal = false,
13
- area = false,
14
- areaOpacity = 0.5
15
- }) => {
16
- const groupByKey = getGroupKey(groupBy);
17
- const option = useMemo(() => {
18
- return {
19
- series: data.columnNames().filter((c) => c !== groupByKey).map((c) => {
20
- const measure = getMeasure(c, measuresMapping);
21
- let pieOps = {};
22
- let lineOps = {};
23
- let barOps = {};
24
- let scatterOps = {};
25
- if (type === "scatter") {
26
- const yAxisId = typeof measure !== "string" ? measure.yAxis : void 0;
27
- scatterOps = {
28
- yAxisId,
29
- encode: {
30
- x: groupByKey,
31
- y: c
32
- }
33
- };
34
- }
35
- if (type === "pie") {
36
- pieOps = {
37
- encode: {
38
- value: c,
39
- itemName: groupByKey
40
- },
41
- labelLine: {
42
- show: false
43
- },
44
- label: {
45
- show: false
46
- },
47
- emphasis: {
48
- label: {
49
- show: false
50
- }
51
- },
52
- radius
53
- };
54
- }
55
- if (type === "line" || type === "bar") {
56
- const sampling = typeof measure !== "string" ? measure.sampling : void 0;
57
- const yAxisId = typeof measure !== "string" ? measure.yAxis : void 0;
58
- const stackName = typeof measure !== "string" ? measure.stack ?? stack ?? void 0 : stack ?? void 0;
59
- const axisOps = {
60
- sampling,
61
- yAxisId,
62
- stack: stackName,
63
- encode: horizontal ? {
64
- x: c,
65
- y: groupByKey
66
- } : {
67
- x: groupByKey,
68
- y: c
69
- }
70
- };
71
- if (type === "bar") {
72
- barOps = {
73
- ...axisOps,
74
- barMaxWidth: 90,
75
- barMinWidth: 3
76
- };
77
- }
78
- if (type === "line") {
79
- const showSymbol = typeof measure !== "string" ? !measure.hideSymbol : true;
80
- const connectNulls = typeof measure !== "string" && measure.emptyCellMode ? measure.emptyCellMode === "connect" : emptyCellMode === "connect";
81
- const isArea = typeof measure !== "string" ? measure.area ?? area : area;
82
- const aOpacity = typeof measure !== "string" ? measure.areaOpacity ?? areaOpacity : areaOpacity;
83
- lineOps = {
84
- ...axisOps,
85
- connectNulls,
86
- showSymbol,
87
- areaStyle: isArea ? { opacity: aOpacity } : void 0
88
- };
89
- }
90
- }
91
- return {
92
- id: `series~${groupByKey}~${c}`,
93
- type,
94
- name: nameFormatter ? nameFormatter(c) : c,
95
- ...pieOps,
96
- ...barOps,
97
- ...lineOps,
98
- ...scatterOps
99
- };
100
- })
101
- };
102
- }, [
103
- data,
104
- groupByKey,
105
- measuresMapping,
106
- type,
107
- nameFormatter,
108
- radius,
109
- stack,
110
- horizontal,
111
- emptyCellMode,
112
- area,
113
- areaOpacity
114
- ]);
115
- return option;
116
- };
117
- export {
118
- useSeries
2
+ import { useMemo } from "react";
3
+ //#region src/hooks/useSeries.tsx
4
+ var useSeries = ({ groupBy, type, data, measuresMapping, nameFormatter, stack, emptyCellMode, radius, horizontal = false, area = false, areaOpacity = .5 }) => {
5
+ const groupByKey = getGroupKey(groupBy);
6
+ return useMemo(() => {
7
+ return { series: data.columnNames().filter((c) => c !== groupByKey).map((c) => {
8
+ const measure = getMeasure(c, measuresMapping);
9
+ let pieOps = {};
10
+ let lineOps = {};
11
+ let barOps = {};
12
+ let scatterOps = {};
13
+ if (type === "scatter") scatterOps = {
14
+ yAxisId: typeof measure !== "string" ? measure.yAxis : void 0,
15
+ encode: {
16
+ x: groupByKey,
17
+ y: c
18
+ }
19
+ };
20
+ if (type === "pie") pieOps = {
21
+ encode: {
22
+ value: c,
23
+ itemName: groupByKey
24
+ },
25
+ labelLine: { show: false },
26
+ label: { show: false },
27
+ emphasis: { label: { show: false } },
28
+ radius
29
+ };
30
+ if (type === "line" || type === "bar") {
31
+ const axisOps = {
32
+ sampling: typeof measure !== "string" ? measure.sampling : void 0,
33
+ yAxisId: typeof measure !== "string" ? measure.yAxis : void 0,
34
+ stack: typeof measure !== "string" ? measure.stack ?? stack ?? void 0 : stack ?? void 0,
35
+ encode: horizontal ? {
36
+ x: c,
37
+ y: groupByKey
38
+ } : {
39
+ x: groupByKey,
40
+ y: c
41
+ }
42
+ };
43
+ if (type === "bar") barOps = {
44
+ ...axisOps,
45
+ barMaxWidth: 90,
46
+ barMinWidth: 3
47
+ };
48
+ if (type === "line") {
49
+ const showSymbol = typeof measure !== "string" ? !measure.hideSymbol : true;
50
+ const connectNulls = typeof measure !== "string" && measure.emptyCellMode ? measure.emptyCellMode === "connect" : emptyCellMode === "connect";
51
+ const isArea = typeof measure !== "string" ? measure.area ?? area : area;
52
+ const aOpacity = typeof measure !== "string" ? measure.areaOpacity ?? areaOpacity : areaOpacity;
53
+ lineOps = {
54
+ ...axisOps,
55
+ connectNulls,
56
+ showSymbol,
57
+ areaStyle: isArea ? { opacity: aOpacity } : void 0
58
+ };
59
+ }
60
+ }
61
+ return {
62
+ id: `series~${groupByKey}~${c}`,
63
+ type,
64
+ name: nameFormatter ? nameFormatter(c) : c,
65
+ ...pieOps,
66
+ ...barOps,
67
+ ...lineOps,
68
+ ...scatterOps
69
+ };
70
+ }) };
71
+ }, [
72
+ data,
73
+ groupByKey,
74
+ measuresMapping,
75
+ type,
76
+ nameFormatter,
77
+ radius,
78
+ stack,
79
+ horizontal,
80
+ emptyCellMode,
81
+ area,
82
+ areaOpacity
83
+ ]);
119
84
  };
85
+ //#endregion
86
+ export { useSeries };
@@ -1,57 +1,40 @@
1
- import { useMemo } from "react";
2
1
  import { getLegendIcon } from "../utils/index.js";
3
- const useVisualMap = ({
4
- show = true,
5
- direction = "horizontal",
6
- type = "continuous",
7
- pieces,
8
- max,
9
- min,
10
- colorScale,
11
- position: positionProp,
12
- ...others
13
- }) => {
14
- const option = useMemo(() => {
15
- return {
16
- visualMap: {
17
- type,
18
- show,
19
- ...pieces && {
20
- pieces
21
- },
22
- ...type === "piecewise" && {
23
- itemSymbol: getLegendIcon("square"),
24
- itemGap: 20,
25
- itemHeight: 16,
26
- itemWidth: 16
27
- },
28
- ...colorScale && {
29
- max,
30
- min,
31
- inRange: {
32
- color: colorScale
33
- }
34
- },
35
- orient: direction,
36
- top: positionProp?.y || "top",
37
- left: positionProp?.x || "center",
38
- ...others
39
- }
40
- };
41
- }, [
42
- colorScale,
43
- direction,
44
- max,
45
- min,
46
- others,
47
- pieces,
48
- positionProp?.x,
49
- positionProp?.y,
50
- show,
51
- type
52
- ]);
53
- return option;
54
- };
55
- export {
56
- useVisualMap
2
+ import { useMemo } from "react";
3
+ //#region src/hooks/useVisualMap.tsx
4
+ var useVisualMap = ({ show = true, direction = "horizontal", type = "continuous", pieces, max, min, colorScale, position: positionProp, ...others }) => {
5
+ return useMemo(() => {
6
+ return { visualMap: {
7
+ type,
8
+ show,
9
+ ...pieces && { pieces },
10
+ ...type === "piecewise" && {
11
+ itemSymbol: getLegendIcon("square"),
12
+ itemGap: 20,
13
+ itemHeight: 16,
14
+ itemWidth: 16
15
+ },
16
+ ...colorScale && {
17
+ max,
18
+ min,
19
+ inRange: { color: colorScale }
20
+ },
21
+ orient: direction,
22
+ top: positionProp?.y || "top",
23
+ left: positionProp?.x || "center",
24
+ ...others
25
+ } };
26
+ }, [
27
+ colorScale,
28
+ direction,
29
+ max,
30
+ min,
31
+ others,
32
+ pieces,
33
+ positionProp?.x,
34
+ positionProp?.y,
35
+ show,
36
+ type
37
+ ]);
57
38
  };
39
+ //#endregion
40
+ export { useVisualMap };
@@ -1,64 +1,45 @@
1
+ import { getAxisType } from "../utils/index.js";
1
2
  import { useMemo } from "react";
2
3
  import { useTheme } from "@hitachivantara/uikit-react-utils";
3
- import { getAxisType } from "../utils/index.js";
4
- const useXAxis = ({
5
- id,
6
- type = "categorical",
7
- labelFormatter,
8
- labelRotation,
9
- name,
10
- maxValue,
11
- minValue,
12
- scale = false,
13
- data,
14
- position,
15
- nameProps
16
- }) => {
17
- const { colors } = useTheme();
18
- const option = useMemo(() => {
19
- const nameStyleKeys = nameProps ? Object.keys(nameProps).filter((key) => key !== "location") : void 0;
20
- const nameStyle = nameProps && nameStyleKeys ? nameStyleKeys.reduce((acc, curr) => {
21
- acc[curr] = curr === "color" && colors?.[nameProps[curr]] || nameProps[curr];
22
- return acc;
23
- }, {}) : void 0;
24
- return {
25
- xAxis: {
26
- id,
27
- type: getAxisType(type),
28
- name,
29
- scale,
30
- axisLabel: {
31
- rotate: labelRotation ?? 0,
32
- formatter: labelFormatter
33
- },
34
- max: maxValue === "max" ? "dataMax" : maxValue,
35
- min: minValue === "min" ? "dataMin" : minValue,
36
- ...nameProps?.location && {
37
- nameLocation: nameProps.location
38
- },
39
- ...nameStyle && {
40
- nameTextStyle: nameStyle
41
- },
42
- ...data && { data },
43
- ...position && { position }
44
- }
45
- };
46
- }, [
47
- nameProps,
48
- id,
49
- type,
50
- name,
51
- scale,
52
- labelRotation,
53
- labelFormatter,
54
- maxValue,
55
- minValue,
56
- data,
57
- position,
58
- colors
59
- ]);
60
- return option;
61
- };
62
- export {
63
- useXAxis
4
+ //#region src/hooks/useXAxis.tsx
5
+ var useXAxis = ({ id, type = "categorical", labelFormatter, labelRotation, name, maxValue, minValue, scale = false, data, position, nameProps }) => {
6
+ const { colors } = useTheme();
7
+ return useMemo(() => {
8
+ const nameStyleKeys = nameProps ? Object.keys(nameProps).filter((key) => key !== "location") : void 0;
9
+ const nameStyle = nameProps && nameStyleKeys ? nameStyleKeys.reduce((acc, curr) => {
10
+ acc[curr] = curr === "color" && colors?.[nameProps[curr]] || nameProps[curr];
11
+ return acc;
12
+ }, {}) : void 0;
13
+ return { xAxis: {
14
+ id,
15
+ type: getAxisType(type),
16
+ name,
17
+ scale,
18
+ axisLabel: {
19
+ rotate: labelRotation ?? 0,
20
+ formatter: labelFormatter
21
+ },
22
+ max: maxValue === "max" ? "dataMax" : maxValue,
23
+ min: minValue === "min" ? "dataMin" : minValue,
24
+ ...nameProps?.location && { nameLocation: nameProps.location },
25
+ ...nameStyle && { nameTextStyle: nameStyle },
26
+ ...data && { data },
27
+ ...position && { position }
28
+ } };
29
+ }, [
30
+ nameProps,
31
+ id,
32
+ type,
33
+ name,
34
+ scale,
35
+ labelRotation,
36
+ labelFormatter,
37
+ maxValue,
38
+ minValue,
39
+ data,
40
+ position,
41
+ colors
42
+ ]);
64
43
  };
44
+ //#endregion
45
+ export { useXAxis };
@@ -1,58 +1,34 @@
1
+ import { getAxisType } from "../utils/index.js";
1
2
  import { useCallback, useMemo } from "react";
2
3
  import { useTheme } from "@hitachivantara/uikit-react-utils";
3
- import { getAxisType } from "../utils/index.js";
4
- const useYAxis = ({
5
- axes,
6
- defaultType = "continuous"
7
- }) => {
8
- const { colors } = useTheme();
9
- const createAxis = useCallback(
10
- ({
11
- id,
12
- type,
13
- name,
14
- labelFormatter,
15
- labelRotation,
16
- maxValue,
17
- minValue,
18
- nameProps,
19
- data,
20
- position
21
- }) => {
22
- const nameStyleKeys = nameProps ? Object.keys(nameProps).filter((key) => key !== "location") : void 0;
23
- const nameStyle = nameProps && nameStyleKeys ? nameStyleKeys.reduce((acc, curr) => {
24
- acc[curr] = curr === "color" && colors?.[nameProps[curr]] || nameProps[curr];
25
- return acc;
26
- }, {}) : void 0;
27
- return {
28
- id,
29
- type: getAxisType(type) ?? getAxisType(defaultType),
30
- name,
31
- axisLabel: {
32
- rotate: labelRotation ?? 0,
33
- formatter: labelFormatter
34
- },
35
- max: maxValue === "max" ? "dataMax" : maxValue,
36
- min: minValue === "min" ? "dataMin" : minValue,
37
- ...nameProps?.location && {
38
- nameLocation: nameProps?.location
39
- },
40
- ...nameStyle && {
41
- nameTextStyle: nameStyle
42
- },
43
- ...data && { data },
44
- ...position && { position }
45
- };
46
- },
47
- [colors, defaultType]
48
- );
49
- const option = useMemo(() => {
50
- return {
51
- yAxis: Array.isArray(axes) ? axes.map((axis) => createAxis(axis)) : [createAxis({})]
52
- };
53
- }, [axes, createAxis]);
54
- return option;
55
- };
56
- export {
57
- useYAxis
4
+ //#region src/hooks/useYAxis.tsx
5
+ var useYAxis = ({ axes, defaultType = "continuous" }) => {
6
+ const { colors } = useTheme();
7
+ const createAxis = useCallback(({ id, type, name, labelFormatter, labelRotation, maxValue, minValue, nameProps, data, position }) => {
8
+ const nameStyleKeys = nameProps ? Object.keys(nameProps).filter((key) => key !== "location") : void 0;
9
+ const nameStyle = nameProps && nameStyleKeys ? nameStyleKeys.reduce((acc, curr) => {
10
+ acc[curr] = curr === "color" && colors?.[nameProps[curr]] || nameProps[curr];
11
+ return acc;
12
+ }, {}) : void 0;
13
+ return {
14
+ id,
15
+ type: getAxisType(type) ?? getAxisType(defaultType),
16
+ name,
17
+ axisLabel: {
18
+ rotate: labelRotation ?? 0,
19
+ formatter: labelFormatter
20
+ },
21
+ max: maxValue === "max" ? "dataMax" : maxValue,
22
+ min: minValue === "min" ? "dataMin" : minValue,
23
+ ...nameProps?.location && { nameLocation: nameProps?.location },
24
+ ...nameStyle && { nameTextStyle: nameStyle },
25
+ ...data && { data },
26
+ ...position && { position }
27
+ };
28
+ }, [colors, defaultType]);
29
+ return useMemo(() => {
30
+ return { yAxis: Array.isArray(axes) ? axes.map((axis) => createAxis(axis)) : [createAxis({})] };
31
+ }, [axes, createAxis]);
58
32
  };
33
+ //#endregion
34
+ export { useYAxis };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { HvVizContext, HvVizProvider, useVizTheme } from "./providers/Provider.js";
2
+ import { HvBaseChart } from "./BaseChart/BaseChart.js";
2
3
  import { getHvArqueroCombinedFilters } from "./utils/index.js";
3
4
  import { HvBarChart } from "./BarChart/BarChart.js";
4
- import { HvBaseChart } from "./BaseChart/BaseChart.js";
5
5
  import { HvBoxplot } from "./Boxplot/Boxplot.js";
6
6
  import { HvConfusionMatrix } from "./ConfusionMatrix/ConfusionMatrix.js";
7
7
  import { HvDonutChart } from "./DonutChart/DonutChart.js";
@@ -9,18 +9,4 @@ import { HvHeatmap } from "./Heatmap/Heatmap.js";
9
9
  import { HvLineChart } from "./LineChart/LineChart.js";
10
10
  import { HvScatterPlot } from "./ScatterPlot/ScatterPlot.js";
11
11
  import { HvTreemapChart } from "./Treemap/Treemap.js";
12
- export {
13
- HvBarChart,
14
- HvBaseChart,
15
- HvBoxplot,
16
- HvConfusionMatrix,
17
- HvDonutChart,
18
- HvHeatmap,
19
- HvLineChart,
20
- HvScatterPlot,
21
- HvTreemapChart,
22
- HvVizContext,
23
- HvVizProvider,
24
- getHvArqueroCombinedFilters,
25
- useVizTheme
26
- };
12
+ export { HvBarChart, HvBaseChart, HvBoxplot, HvConfusionMatrix, HvDonutChart, HvHeatmap, HvLineChart, HvScatterPlot, HvTreemapChart, HvVizContext, HvVizProvider, getHvArqueroCombinedFilters, useVizTheme };