@hpcc-js/react 3.4.15 → 3.4.17

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/vertex3.tsx CHANGED
@@ -1,238 +1,238 @@
1
- import * as PReact from "./preact-shim.ts";
2
- import { Utility } from "@hpcc-js/common";
3
- import { Icon, IconProps } from "./icon.tsx";
4
- import { TextBox, TextBoxProps } from "./text.tsx";
5
- import { VertexProps } from "./vertex.tsx";
6
-
7
- export interface Vertex3Props extends VertexProps {
8
- id: string;
9
- origData?: any;
10
- categoryID?: string;
11
- text: string;
12
- textHeight?: number;
13
- textPadding?: number;
14
- textboxStrokeWidth?: number;
15
- icon?: IconProps;
16
- annotations?: IconProps[];
17
- annotationsHeight?: number;
18
- annotationGutter?: number;
19
- textFill?: string;
20
- textboxFill?: string;
21
- textboxStroke?: string;
22
- textFontFamily?: string;
23
- cornerRadius?: number;
24
- subText?: TextBoxProps;
25
- onSizeUpdate?: (size: { width: number, height: number }) => void;
26
- showLabel?: boolean;
27
- noLabelRadius?: number;
28
- expansionIcon?: IconProps;
29
- scale?: number;
30
- }
31
-
32
- export const Vertex3: PReact.FunctionComponent<Vertex3Props> = ({
33
- text = "",
34
- textHeight = 10,
35
- textPadding = 4,
36
- textFill = "#287EC4",
37
- textboxFill = "white",
38
- textboxStroke = "#CCCCCC",
39
- textboxStrokeWidth = 1,
40
- textFontFamily = "Verdana",
41
- annotationGutter = 2,
42
- annotations = [],
43
- cornerRadius = 3,
44
- icon = {} as IconProps,
45
- subText = { text: "" } as TextBoxProps,
46
- showLabel = true,
47
- noLabelRadius = 5,
48
- expansionIcon,
49
- scale = 1
50
- }) => {
51
- icon = {
52
- height: 50,
53
- imageChar: "?",
54
- imageFontFamily: "FontAwesome",
55
- imageCharFill: "#555555",
56
- fill: "transparent",
57
- strokeWidth: 0,
58
- ...icon
59
- };
60
- subText = {
61
- text: "",
62
- fill: "white",
63
- textFill: "#555555",
64
- ...subText
65
- };
66
- expansionIcon = expansionIcon ? {
67
- height: 16,
68
- shape: "circle",
69
- padding: 6,
70
- imageChar: "?",
71
- imageFontFamily: "FontAwesome",
72
- imageCharFill: "black",
73
- fill: "whitesmoke",
74
- stroke: "whitesmoke",
75
- strokeWidth: 0,
76
- ...expansionIcon
77
- } : undefined;
78
- let fullAnnotationWidth = 0;
79
-
80
- const annoOffsetY = 0;
81
-
82
- const labelWidth = PReact.useMemo(() => {
83
- return Utility.textSize(text, textFontFamily, textHeight, false).width;
84
- }, [text, textFontFamily, textHeight]);
85
-
86
- let labelShapeWidth = 0;
87
- if (text !== "") {
88
- labelShapeWidth = labelWidth + (textPadding * 2) + (textboxStrokeWidth * 2);
89
- }
90
- fullAnnotationWidth += labelShapeWidth + annotationGutter;
91
- const textOffsetX = fullAnnotationWidth - (labelShapeWidth / 2);
92
-
93
- const textShapeHeight = textHeight + (textPadding * 2) + (textboxStrokeWidth * 2);
94
- const annotationArr = [];
95
- annotations.forEach((anno, idx) => {
96
- const annoText = anno.imageChar;
97
- const annoShapeWidth = textShapeHeight;
98
- fullAnnotationWidth += annoShapeWidth + annotationGutter;
99
- const annoOffsetX = fullAnnotationWidth - (annoShapeWidth / 2);
100
- annotationArr.push(
101
- <g key={idx} className="vertex3-anno" data-click={"annotation"} data-click-data={JSON.stringify(anno)} transform={`translate(${annoOffsetX} ${annoOffsetY})`}>
102
- <Icon
103
- {...anno}
104
- shape="square"
105
- height={textShapeHeight}
106
- imageChar={annoText}
107
- imageFontFamily={anno.imageFontFamily}
108
- cornerRadius={cornerRadius}
109
- strokeWidth={0}
110
- />
111
- </g>
112
- );
113
- });
114
- if (annotations.length > 0) {
115
- fullAnnotationWidth += annotationGutter * (annotations.length - 1);
116
- }
117
- const textElement = <g data-click={"text"} transform={`translate(${textOffsetX} ${annoOffsetY})`}>
118
- {!showLabel || text === "" ? <circle r={noLabelRadius} stroke={textboxStroke} fill={textFill} /> : <TextBox
119
- text={text}
120
- height={textHeight}
121
- padding={textPadding}
122
- strokeWidth={textboxStrokeWidth}
123
- stroke={textboxStroke}
124
- fill={textboxFill}
125
- textFill={textFill}
126
- fontFamily={textFontFamily}
127
- cornerRadius={cornerRadius}
128
- />}
129
- </g>;
130
- const iconHeight = icon.height || 20;
131
- const iconStrokeWidth = icon.strokeWidth || 0;
132
- const iconOffsetX = 0;
133
- let iconOffsetY = 0;
134
-
135
- const subTextOffsetX = 0;
136
- let subTextOffsetY = textShapeHeight + (annotationGutter * 2);
137
-
138
- if (text !== "" || annotationArr.length > 0) {
139
- iconOffsetY = - (iconHeight / 2) - (iconStrokeWidth) - (textShapeHeight / 2) - (annotationGutter * 2);
140
- } else if (subText.text !== "") {
141
- subTextOffsetY = (iconHeight / 2) + iconStrokeWidth + (annotationGutter * 2);
142
- }
143
-
144
- const subtextElement = subText.text === "" ? null : <g data-click={"subtext"}
145
- transform={`translate(${subTextOffsetX} ${subTextOffsetY})`}
146
- >
147
- <TextBox
148
- fill={subText.fill || "#FFFFFF"}
149
- textFill={subText.textFill || textFill}
150
- {...subText}
151
- height={textHeight}
152
- padding={textPadding}
153
- strokeWidth={0}
154
- stroke={textboxStroke}
155
- fontFamily={textFontFamily}
156
- cornerRadius={cornerRadius}
157
- />
158
- </g>;
159
-
160
- return <g transform={`scale(${scale})`}>
161
- <g data-click={"icon"} transform={`translate(${iconOffsetX} ${iconOffsetY})`}>
162
- <Icon {...icon} />
163
- {expansionIcon &&
164
- <g data-click={"expanded-icon"} data-click-data={JSON.stringify(expansionIcon)} transform={`translate(${(icon.height + iconStrokeWidth) / 2 - expansionIcon.height / 2} ${-(icon.height + iconStrokeWidth) / 2 + expansionIcon.height / 2})`}>
165
- <Icon {...expansionIcon} />
166
- </g>
167
- }
168
- </g>
169
- <g transform={`translate(${-fullAnnotationWidth / 2} ${annoOffsetY})`} >
170
- {textElement}
171
- {annotationArr}
172
- </g>
173
- {subtextElement}
174
- </g >;
175
- };
176
-
177
- export const CentroidVertex3: PReact.FunctionComponent<Vertex3Props> = function ({
178
- id,
179
- categoryID = "",
180
- text = "",
181
- textHeight = 12,
182
- textPadding = 10,
183
- textFill = "#287EC4",
184
- textboxFill = "white",
185
- textboxStroke = "#CCCCCC",
186
- textboxStrokeWidth = 1,
187
- textFontFamily = "Verdana",
188
- annotationGutter = 2,
189
- annotations = [],
190
- cornerRadius,
191
- icon = {},
192
- subText = {},
193
- expansionIcon,
194
- scale = 1
195
- }) {
196
- icon = {
197
- height: 91,
198
- padding: 40,
199
- imageCharFill: "#555555",
200
- imageFontFamily: "FontAwesome",
201
- fill: "#FFCC33",
202
- stroke: "#DFDFDF",
203
- imageChar: "?",
204
- strokeWidth: 4,
205
- yOffset: -15,
206
- ...icon
207
- };
208
- subText = {
209
- text: "",
210
- fill: "transparent",
211
- textFill: "#555555",
212
- ...subText
213
- };
214
- const props = {
215
- id,
216
- categoryID,
217
- text,
218
- textHeight,
219
- textPadding,
220
- textFill,
221
- textboxFill,
222
- textboxStroke,
223
- textboxStrokeWidth,
224
- textFontFamily,
225
- annotationGutter,
226
- annotations,
227
- cornerRadius,
228
- icon,
229
- subText,
230
- expansionIcon,
231
- scale
232
- };
233
- return <Vertex3
234
- {...props}
235
- icon={icon}
236
- subText={subText}
237
- />;
238
- };
1
+ import * as PReact from "./preact-shim.ts";
2
+ import { Utility } from "@hpcc-js/common";
3
+ import { Icon, IconProps } from "./icon.tsx";
4
+ import { TextBox, TextBoxProps } from "./text.tsx";
5
+ import { VertexProps } from "./vertex.tsx";
6
+
7
+ export interface Vertex3Props extends VertexProps {
8
+ id: string;
9
+ origData?: any;
10
+ categoryID?: string;
11
+ text: string;
12
+ textHeight?: number;
13
+ textPadding?: number;
14
+ textboxStrokeWidth?: number;
15
+ icon?: IconProps;
16
+ annotations?: IconProps[];
17
+ annotationsHeight?: number;
18
+ annotationGutter?: number;
19
+ textFill?: string;
20
+ textboxFill?: string;
21
+ textboxStroke?: string;
22
+ textFontFamily?: string;
23
+ cornerRadius?: number;
24
+ subText?: TextBoxProps;
25
+ onSizeUpdate?: (size: { width: number, height: number }) => void;
26
+ showLabel?: boolean;
27
+ noLabelRadius?: number;
28
+ expansionIcon?: IconProps;
29
+ scale?: number;
30
+ }
31
+
32
+ export const Vertex3: PReact.FunctionComponent<Vertex3Props> = ({
33
+ text = "",
34
+ textHeight = 10,
35
+ textPadding = 4,
36
+ textFill = "#287EC4",
37
+ textboxFill = "white",
38
+ textboxStroke = "#CCCCCC",
39
+ textboxStrokeWidth = 1,
40
+ textFontFamily = "Verdana",
41
+ annotationGutter = 2,
42
+ annotations = [],
43
+ cornerRadius = 3,
44
+ icon = {} as IconProps,
45
+ subText = { text: "" } as TextBoxProps,
46
+ showLabel = true,
47
+ noLabelRadius = 5,
48
+ expansionIcon,
49
+ scale = 1
50
+ }) => {
51
+ icon = {
52
+ height: 50,
53
+ imageChar: "?",
54
+ imageFontFamily: "FontAwesome",
55
+ imageCharFill: "#555555",
56
+ fill: "transparent",
57
+ strokeWidth: 0,
58
+ ...icon
59
+ };
60
+ subText = {
61
+ text: "",
62
+ fill: "white",
63
+ textFill: "#555555",
64
+ ...subText
65
+ };
66
+ expansionIcon = expansionIcon ? {
67
+ height: 16,
68
+ shape: "circle",
69
+ padding: 6,
70
+ imageChar: "?",
71
+ imageFontFamily: "FontAwesome",
72
+ imageCharFill: "black",
73
+ fill: "whitesmoke",
74
+ stroke: "whitesmoke",
75
+ strokeWidth: 0,
76
+ ...expansionIcon
77
+ } : undefined;
78
+ let fullAnnotationWidth = 0;
79
+
80
+ const annoOffsetY = 0;
81
+
82
+ const labelWidth = PReact.useMemo(() => {
83
+ return Utility.textSize(text, textFontFamily, textHeight, false).width;
84
+ }, [text, textFontFamily, textHeight]);
85
+
86
+ let labelShapeWidth = 0;
87
+ if (text !== "") {
88
+ labelShapeWidth = labelWidth + (textPadding * 2) + (textboxStrokeWidth * 2);
89
+ }
90
+ fullAnnotationWidth += labelShapeWidth + annotationGutter;
91
+ const textOffsetX = fullAnnotationWidth - (labelShapeWidth / 2);
92
+
93
+ const textShapeHeight = textHeight + (textPadding * 2) + (textboxStrokeWidth * 2);
94
+ const annotationArr = [];
95
+ annotations.forEach((anno, idx) => {
96
+ const annoText = anno.imageChar;
97
+ const annoShapeWidth = textShapeHeight;
98
+ fullAnnotationWidth += annoShapeWidth + annotationGutter;
99
+ const annoOffsetX = fullAnnotationWidth - (annoShapeWidth / 2);
100
+ annotationArr.push(
101
+ <g key={idx} className="vertex3-anno" data-click={"annotation"} data-click-data={JSON.stringify(anno)} transform={`translate(${annoOffsetX} ${annoOffsetY})`}>
102
+ <Icon
103
+ {...anno}
104
+ shape="square"
105
+ height={textShapeHeight}
106
+ imageChar={annoText}
107
+ imageFontFamily={anno.imageFontFamily}
108
+ cornerRadius={cornerRadius}
109
+ strokeWidth={0}
110
+ />
111
+ </g>
112
+ );
113
+ });
114
+ if (annotations.length > 0) {
115
+ fullAnnotationWidth += annotationGutter * (annotations.length - 1);
116
+ }
117
+ const textElement = <g data-click={"text"} transform={`translate(${textOffsetX} ${annoOffsetY})`}>
118
+ {!showLabel || text === "" ? <circle r={noLabelRadius} stroke={textboxStroke} fill={textFill} /> : <TextBox
119
+ text={text}
120
+ height={textHeight}
121
+ padding={textPadding}
122
+ strokeWidth={textboxStrokeWidth}
123
+ stroke={textboxStroke}
124
+ fill={textboxFill}
125
+ textFill={textFill}
126
+ fontFamily={textFontFamily}
127
+ cornerRadius={cornerRadius}
128
+ />}
129
+ </g>;
130
+ const iconHeight = icon.height || 20;
131
+ const iconStrokeWidth = icon.strokeWidth || 0;
132
+ const iconOffsetX = 0;
133
+ let iconOffsetY = 0;
134
+
135
+ const subTextOffsetX = 0;
136
+ let subTextOffsetY = textShapeHeight + (annotationGutter * 2);
137
+
138
+ if (text !== "" || annotationArr.length > 0) {
139
+ iconOffsetY = - (iconHeight / 2) - (iconStrokeWidth) - (textShapeHeight / 2) - (annotationGutter * 2);
140
+ } else if (subText.text !== "") {
141
+ subTextOffsetY = (iconHeight / 2) + iconStrokeWidth + (annotationGutter * 2);
142
+ }
143
+
144
+ const subtextElement = subText.text === "" ? null : <g data-click={"subtext"}
145
+ transform={`translate(${subTextOffsetX} ${subTextOffsetY})`}
146
+ >
147
+ <TextBox
148
+ fill={subText.fill || "#FFFFFF"}
149
+ textFill={subText.textFill || textFill}
150
+ {...subText}
151
+ height={textHeight}
152
+ padding={textPadding}
153
+ strokeWidth={0}
154
+ stroke={textboxStroke}
155
+ fontFamily={textFontFamily}
156
+ cornerRadius={cornerRadius}
157
+ />
158
+ </g>;
159
+
160
+ return <g transform={`scale(${scale})`}>
161
+ <g data-click={"icon"} transform={`translate(${iconOffsetX} ${iconOffsetY})`}>
162
+ <Icon {...icon} />
163
+ {expansionIcon &&
164
+ <g data-click={"expanded-icon"} data-click-data={JSON.stringify(expansionIcon)} transform={`translate(${(icon.height + iconStrokeWidth) / 2 - expansionIcon.height / 2} ${-(icon.height + iconStrokeWidth) / 2 + expansionIcon.height / 2})`}>
165
+ <Icon {...expansionIcon} />
166
+ </g>
167
+ }
168
+ </g>
169
+ <g transform={`translate(${-fullAnnotationWidth / 2} ${annoOffsetY})`} >
170
+ {textElement}
171
+ {annotationArr}
172
+ </g>
173
+ {subtextElement}
174
+ </g >;
175
+ };
176
+
177
+ export const CentroidVertex3: PReact.FunctionComponent<Vertex3Props> = function ({
178
+ id,
179
+ categoryID = "",
180
+ text = "",
181
+ textHeight = 12,
182
+ textPadding = 10,
183
+ textFill = "#287EC4",
184
+ textboxFill = "white",
185
+ textboxStroke = "#CCCCCC",
186
+ textboxStrokeWidth = 1,
187
+ textFontFamily = "Verdana",
188
+ annotationGutter = 2,
189
+ annotations = [],
190
+ cornerRadius,
191
+ icon = {},
192
+ subText = {},
193
+ expansionIcon,
194
+ scale = 1
195
+ }) {
196
+ icon = {
197
+ height: 91,
198
+ padding: 40,
199
+ imageCharFill: "#555555",
200
+ imageFontFamily: "FontAwesome",
201
+ fill: "#FFCC33",
202
+ stroke: "#DFDFDF",
203
+ imageChar: "?",
204
+ strokeWidth: 4,
205
+ yOffset: -15,
206
+ ...icon
207
+ };
208
+ subText = {
209
+ text: "",
210
+ fill: "transparent",
211
+ textFill: "#555555",
212
+ ...subText
213
+ };
214
+ const props = {
215
+ id,
216
+ categoryID,
217
+ text,
218
+ textHeight,
219
+ textPadding,
220
+ textFill,
221
+ textboxFill,
222
+ textboxStroke,
223
+ textboxStrokeWidth,
224
+ textFontFamily,
225
+ annotationGutter,
226
+ annotations,
227
+ cornerRadius,
228
+ icon,
229
+ subText,
230
+ expansionIcon,
231
+ scale
232
+ };
233
+ return <Vertex3
234
+ {...props}
235
+ icon={icon}
236
+ subText={subText}
237
+ />;
238
+ };