@hpcc-js/react 2.55.1 → 2.55.3

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.
package/src/vertex.tsx CHANGED
@@ -1,116 +1,116 @@
1
- import * as React from "@hpcc-js/preact-shim";
2
- import { Icon } from "./icon";
3
- import { TextBox } from "./text";
4
-
5
- export interface Annotations {
6
- x: number;
7
- y: number;
8
- annotationIDs: string[];
9
- stepSize?: number;
10
- }
11
-
12
- export const Annotations: React.FunctionComponent<Annotations> = ({
13
- x,
14
- y,
15
- annotationIDs = [],
16
- stepSize = -16
17
- }) => {
18
- const IconComponents = annotationIDs.map((id, i) => <g
19
- key={id}
20
- transform={`translate(${x + i * stepSize} ${y})`}
21
- >
22
- <use
23
- href={"#" + id}
24
- />
25
- </g>
26
- );
27
- return <>{IconComponents}</>;
28
- };
29
-
30
- export interface VertexProps {
31
- id: string | number;
32
- origData?: any;
33
- centroid?: boolean;
34
- categoryID?: string;
35
- text: string;
36
- textHeight?: number;
37
- textPadding?: number;
38
- icon?: Icon;
39
- annotationsHeight?: number;
40
- annotationIDs?: string[];
41
- textFill?: string;
42
- textboxFill?: string;
43
- textboxStroke?: string;
44
- textFontFamily?: string;
45
- onSizeUpdate?: (size: { width: number, height: number }) => void;
46
- showLabel?: boolean;
47
- scale?: number
48
- }
49
-
50
- export const Vertex: React.FunctionComponent<VertexProps> = ({
51
- categoryID = "",
52
- text = "",
53
- textHeight = 12,
54
- textPadding = 4,
55
- icon = {},
56
- annotationsHeight = 12,
57
- annotationIDs = [],
58
- textFill,
59
- textboxFill,
60
- textboxStroke,
61
- textFontFamily,
62
- onSizeUpdate,
63
- showLabel = true,
64
- scale = 1
65
- }) => {
66
- const [textBoxWidth, setTextBoxWidthUpdate] = React.useState(0);
67
- const [textBoxHeight, setTextBoxHeightUpdate] = React.useState(0);
68
-
69
- React.useEffect(() => {
70
- onSizeUpdate && onSizeUpdate({ width: 0, height: 0 });
71
- }, [textBoxWidth, textBoxHeight, onSizeUpdate]);
72
-
73
- icon = {
74
- imageChar: "fa-question",
75
- height: 32,
76
- fill: "transparent",
77
- ...icon
78
- };
79
- let width = textBoxWidth;
80
- width += 4;
81
- let offsetY = -(icon.height * 2 / 6 + textHeight + 8) / 2;
82
- const textboxOffsetY = icon.height / 3 + textBoxHeight / 2 + textPadding;
83
- let annotationOffsetY = icon.height / 3 + textBoxHeight + textPadding + annotationsHeight / 3;
84
- if (!showLabel) {
85
- offsetY += (textHeight + 8) / 2;
86
- annotationOffsetY -= textBoxHeight + textPadding;
87
- }
88
-
89
- const onTextBoxSizeUpdate = React.useCallback(size => {
90
- setTextBoxWidthUpdate(size.width);
91
- setTextBoxHeightUpdate(size.height);
92
- }, []);
93
-
94
- const label = showLabel ? <g transform={`translate(0 ${textboxOffsetY})`}>
95
- <TextBox
96
- text={text}
97
- height={textHeight}
98
- padding={textPadding}
99
- onSizeUpdate={onTextBoxSizeUpdate}
100
- textFill={textFill}
101
- fill={textboxFill}
102
- stroke={textboxStroke}
103
- fontFamily={textFontFamily}
104
- />
105
- </g> : undefined;
106
- return categoryID ?
107
- <g transform={`translate(0 ${offsetY}) scale(${scale})`}>
108
- <use href={"#" + categoryID} />
109
- {label}
110
- <Annotations x={width / 2} y={annotationOffsetY} annotationIDs={annotationIDs} />
111
- </g> :
112
- <g transform={`translate(0 ${offsetY}) scale(${scale})`}>
113
- <Icon {...icon} />
114
- {label}
115
- </g>;
116
- };
1
+ import * as React from "@hpcc-js/preact-shim";
2
+ import { Icon } from "./icon";
3
+ import { TextBox } from "./text";
4
+
5
+ export interface Annotations {
6
+ x: number;
7
+ y: number;
8
+ annotationIDs: string[];
9
+ stepSize?: number;
10
+ }
11
+
12
+ export const Annotations: React.FunctionComponent<Annotations> = ({
13
+ x,
14
+ y,
15
+ annotationIDs = [],
16
+ stepSize = -16
17
+ }) => {
18
+ const IconComponents = annotationIDs.map((id, i) => <g
19
+ key={id}
20
+ transform={`translate(${x + i * stepSize} ${y})`}
21
+ >
22
+ <use
23
+ href={"#" + id}
24
+ />
25
+ </g>
26
+ );
27
+ return <>{IconComponents}</>;
28
+ };
29
+
30
+ export interface VertexProps {
31
+ id: string | number;
32
+ origData?: any;
33
+ centroid?: boolean;
34
+ categoryID?: string;
35
+ text: string;
36
+ textHeight?: number;
37
+ textPadding?: number;
38
+ icon?: Icon;
39
+ annotationsHeight?: number;
40
+ annotationIDs?: string[];
41
+ textFill?: string;
42
+ textboxFill?: string;
43
+ textboxStroke?: string;
44
+ textFontFamily?: string;
45
+ onSizeUpdate?: (size: { width: number, height: number }) => void;
46
+ showLabel?: boolean;
47
+ scale?: number
48
+ }
49
+
50
+ export const Vertex: React.FunctionComponent<VertexProps> = ({
51
+ categoryID = "",
52
+ text = "",
53
+ textHeight = 12,
54
+ textPadding = 4,
55
+ icon = {},
56
+ annotationsHeight = 12,
57
+ annotationIDs = [],
58
+ textFill,
59
+ textboxFill,
60
+ textboxStroke,
61
+ textFontFamily,
62
+ onSizeUpdate,
63
+ showLabel = true,
64
+ scale = 1
65
+ }) => {
66
+ const [textBoxWidth, setTextBoxWidthUpdate] = React.useState(0);
67
+ const [textBoxHeight, setTextBoxHeightUpdate] = React.useState(0);
68
+
69
+ React.useEffect(() => {
70
+ onSizeUpdate && onSizeUpdate({ width: 0, height: 0 });
71
+ }, [textBoxWidth, textBoxHeight, onSizeUpdate]);
72
+
73
+ icon = {
74
+ imageChar: "fa-question",
75
+ height: 32,
76
+ fill: "transparent",
77
+ ...icon
78
+ };
79
+ let width = textBoxWidth;
80
+ width += 4;
81
+ let offsetY = -(icon.height * 2 / 6 + textHeight + 8) / 2;
82
+ const textboxOffsetY = icon.height / 3 + textBoxHeight / 2 + textPadding;
83
+ let annotationOffsetY = icon.height / 3 + textBoxHeight + textPadding + annotationsHeight / 3;
84
+ if (!showLabel) {
85
+ offsetY += (textHeight + 8) / 2;
86
+ annotationOffsetY -= textBoxHeight + textPadding;
87
+ }
88
+
89
+ const onTextBoxSizeUpdate = React.useCallback(size => {
90
+ setTextBoxWidthUpdate(size.width);
91
+ setTextBoxHeightUpdate(size.height);
92
+ }, []);
93
+
94
+ const label = showLabel ? <g transform={`translate(0 ${textboxOffsetY})`}>
95
+ <TextBox
96
+ text={text}
97
+ height={textHeight}
98
+ padding={textPadding}
99
+ onSizeUpdate={onTextBoxSizeUpdate}
100
+ textFill={textFill}
101
+ fill={textboxFill}
102
+ stroke={textboxStroke}
103
+ fontFamily={textFontFamily}
104
+ />
105
+ </g> : undefined;
106
+ return categoryID ?
107
+ <g transform={`translate(0 ${offsetY}) scale(${scale})`}>
108
+ <use href={"#" + categoryID} />
109
+ {label}
110
+ <Annotations x={width / 2} y={annotationOffsetY} annotationIDs={annotationIDs} />
111
+ </g> :
112
+ <g transform={`translate(0 ${offsetY}) scale(${scale})`}>
113
+ <Icon {...icon} />
114
+ {label}
115
+ </g>;
116
+ };
package/src/vertex2.tsx CHANGED
@@ -1,100 +1,100 @@
1
- import { Utility } from "@hpcc-js/common";
2
- import * as React from "@hpcc-js/preact-shim";
3
- import { Icon } from "./icon";
4
- import { TextBox } from "./text";
5
- import { Annotations, VertexProps } from "./vertex";
6
-
7
- export const Vertex2: React.FunctionComponent<VertexProps> = ({
8
- categoryID = "",
9
- text = "",
10
- textHeight = 12,
11
- textPadding = 4,
12
- icon = {},
13
- textFill = "black",
14
- textboxFill = "white",
15
- textboxStroke = "black",
16
- textFontFamily,
17
- annotationsHeight = 12,
18
- annotationIDs = []
19
- }) => {
20
- icon = {
21
- imageChar: "fa-question",
22
- imageCharFill: "white",
23
- height: 32,
24
- fill: "black",
25
- shape: "square",
26
- ...icon
27
- };
28
- const textBoxHeight = textHeight + textPadding * 2;
29
- const { width } = React.useMemo(() => {
30
- return Utility.textSize(text, textFontFamily, textHeight, false);
31
- }, [text, textFontFamily, textHeight]);
32
-
33
- const stepSize = annotationsHeight;
34
- const textboxStrokeWidth = 1;
35
-
36
- const halfTextboxHeight = textBoxHeight / 2;
37
-
38
- const offsetX = 0;
39
- const offsetY = -(icon.height * 2 / 6 + textHeight + 8) / 2;
40
- const iconOffsetX = - icon.height / 2;
41
- const iconOffsetY = 0;
42
- const textboxOffsetX = Math.ceil((width / 2) + textPadding);
43
- const textboxOffsetY = halfTextboxHeight - (icon.height / 2);
44
- const annotationOffsetX = stepSize / 2;
45
- const annotationOffsetY = halfTextboxHeight;
46
- return categoryID ?
47
- <g
48
- transform={`translate(${offsetX} ${offsetY})`}
49
- >
50
- <g
51
- transform={`translate(${iconOffsetX} ${iconOffsetY})`}
52
- >
53
- <use
54
- href={"#" + categoryID}
55
- />
56
- </g>
57
- <g
58
- transform={`translate(${textboxOffsetX} ${textboxOffsetY})`}
59
- >
60
- <TextBox
61
- text={text}
62
- height={textHeight}
63
- padding={textPadding}
64
- strokeWidth={textboxStrokeWidth}
65
- stroke={textboxStroke}
66
- fill={textboxFill}
67
- textFill={textFill}
68
- fontFamily={textFontFamily}
69
- />
70
- </g>
71
- <Annotations
72
- x={annotationOffsetX}
73
- y={annotationOffsetY}
74
- annotationIDs={annotationIDs}
75
- stepSize={stepSize}
76
- />
77
- </g>
78
- :
79
- <>
80
- <g
81
- transform={`translate(${iconOffsetX} ${iconOffsetY})scale(1.0002)`}
82
- >
83
- <Icon
84
- {...icon}
85
- shape="square"
86
- />
87
- </g>
88
- <g
89
- transform={`translate(${textboxOffsetX} ${textboxOffsetY})scale(1.0002)`}
90
- >
91
- <TextBox
92
- text={text}
93
- height={textHeight}
94
- padding={textPadding}
95
- stroke={textboxStroke}
96
- fill={textboxFill}
97
- />
98
- </g>
99
- </>;
100
- };
1
+ import { Utility } from "@hpcc-js/common";
2
+ import * as React from "@hpcc-js/preact-shim";
3
+ import { Icon } from "./icon";
4
+ import { TextBox } from "./text";
5
+ import { Annotations, VertexProps } from "./vertex";
6
+
7
+ export const Vertex2: React.FunctionComponent<VertexProps> = ({
8
+ categoryID = "",
9
+ text = "",
10
+ textHeight = 12,
11
+ textPadding = 4,
12
+ icon = {},
13
+ textFill = "black",
14
+ textboxFill = "white",
15
+ textboxStroke = "black",
16
+ textFontFamily,
17
+ annotationsHeight = 12,
18
+ annotationIDs = []
19
+ }) => {
20
+ icon = {
21
+ imageChar: "fa-question",
22
+ imageCharFill: "white",
23
+ height: 32,
24
+ fill: "black",
25
+ shape: "square",
26
+ ...icon
27
+ };
28
+ const textBoxHeight = textHeight + textPadding * 2;
29
+ const { width } = React.useMemo(() => {
30
+ return Utility.textSize(text, textFontFamily, textHeight, false);
31
+ }, [text, textFontFamily, textHeight]);
32
+
33
+ const stepSize = annotationsHeight;
34
+ const textboxStrokeWidth = 1;
35
+
36
+ const halfTextboxHeight = textBoxHeight / 2;
37
+
38
+ const offsetX = 0;
39
+ const offsetY = -(icon.height * 2 / 6 + textHeight + 8) / 2;
40
+ const iconOffsetX = - icon.height / 2;
41
+ const iconOffsetY = 0;
42
+ const textboxOffsetX = Math.ceil((width / 2) + textPadding);
43
+ const textboxOffsetY = halfTextboxHeight - (icon.height / 2);
44
+ const annotationOffsetX = stepSize / 2;
45
+ const annotationOffsetY = halfTextboxHeight;
46
+ return categoryID ?
47
+ <g
48
+ transform={`translate(${offsetX} ${offsetY})`}
49
+ >
50
+ <g
51
+ transform={`translate(${iconOffsetX} ${iconOffsetY})`}
52
+ >
53
+ <use
54
+ href={"#" + categoryID}
55
+ />
56
+ </g>
57
+ <g
58
+ transform={`translate(${textboxOffsetX} ${textboxOffsetY})`}
59
+ >
60
+ <TextBox
61
+ text={text}
62
+ height={textHeight}
63
+ padding={textPadding}
64
+ strokeWidth={textboxStrokeWidth}
65
+ stroke={textboxStroke}
66
+ fill={textboxFill}
67
+ textFill={textFill}
68
+ fontFamily={textFontFamily}
69
+ />
70
+ </g>
71
+ <Annotations
72
+ x={annotationOffsetX}
73
+ y={annotationOffsetY}
74
+ annotationIDs={annotationIDs}
75
+ stepSize={stepSize}
76
+ />
77
+ </g>
78
+ :
79
+ <>
80
+ <g
81
+ transform={`translate(${iconOffsetX} ${iconOffsetY})scale(1.0002)`}
82
+ >
83
+ <Icon
84
+ {...icon}
85
+ shape="square"
86
+ />
87
+ </g>
88
+ <g
89
+ transform={`translate(${textboxOffsetX} ${textboxOffsetY})scale(1.0002)`}
90
+ >
91
+ <TextBox
92
+ text={text}
93
+ height={textHeight}
94
+ padding={textPadding}
95
+ stroke={textboxStroke}
96
+ fill={textboxFill}
97
+ />
98
+ </g>
99
+ </>;
100
+ };