@hpcc-js/react 2.50.0 → 2.52.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/react",
3
- "version": "2.50.0",
3
+ "version": "2.52.0",
4
4
  "description": "hpcc-js - Viz React",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es6",
@@ -35,15 +35,15 @@
35
35
  "stamp": "node ../../node_modules/@hpcc-js/bundle/src/stamp.js",
36
36
  "lint": "eslint ./src",
37
37
  "docs": "typedoc --options tdoptions.json .",
38
- "update": "npx npm-check-updates -u -t minor"
38
+ "update": "npx --yes npm-check-updates -u -t minor"
39
39
  },
40
40
  "dependencies": {
41
- "@hpcc-js/common": "^2.71.0",
42
- "@hpcc-js/preact-shim": "^2.15.0"
41
+ "@hpcc-js/common": "^2.71.1",
42
+ "@hpcc-js/preact-shim": "^2.16.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@hpcc-js/bundle": "^2.11.1",
46
- "tslib": "2.3.1"
45
+ "@hpcc-js/bundle": "^2.11.2",
46
+ "tslib": "2.4.0"
47
47
  },
48
48
  "repository": {
49
49
  "type": "git",
@@ -56,5 +56,5 @@
56
56
  "url": "https://github.com/hpcc-systems/Visualization/issues"
57
57
  },
58
58
  "homepage": "https://github.com/hpcc-systems/Visualization",
59
- "gitHead": "62cc2d8321326a26647c5ab7e408ece836bfe193"
59
+ "gitHead": "3a4f1ba7a59e2e7f5283830e0a884187a6c42fe7"
60
60
  }
package/src/ImageChar.tsx CHANGED
@@ -20,7 +20,13 @@ export const ImageChar: React.FunctionComponent<ImageChar> = ({
20
20
  stroke,
21
21
  fontFamily = "FontAwesome",
22
22
  char = ""
23
- }) => <text
23
+ }) => {
24
+
25
+ const renderChar = React.useMemo(() => {
26
+ return fontFamily === "FontAwesome" ? Utility.faChar(char) : char;
27
+ }, [char, fontFamily]);
28
+
29
+ return <text
24
30
  x={x}
25
31
  y={y}
26
32
  fill={fill}
@@ -29,4 +35,5 @@ export const ImageChar: React.FunctionComponent<ImageChar> = ({
29
35
  font-size={`${height}px`}
30
36
  dominant-baseline="middle"
31
37
  style="text-anchor: middle;alignment-baseline:middle;"
32
- >{fontFamily === "FontAwesome" ? Utility.faChar(char) : char}</text>;
38
+ >{renderChar}</text>;
39
+ };
@@ -1,3 +1,3 @@
1
1
  export const PKG_NAME = "@hpcc-js/react";
2
- export const PKG_VERSION = "2.50.0";
3
- export const BUILD_VERSION = "2.104.0";
2
+ export const PKG_VERSION = "2.52.0";
3
+ export const BUILD_VERSION = "2.104.3";
package/src/edge.tsx CHANGED
@@ -37,5 +37,8 @@ export const Edge: React.FunctionComponent<Edge> = ({
37
37
  stroke = "black",
38
38
  strokeDasharray
39
39
  }) => {
40
- return <path stroke={stroke} stroke-dasharray={strokeDasharray} d={line(calcArc(points, curveDepth))}></path>;
40
+ const d = React.useMemo(() => {
41
+ return line(calcArc(points, curveDepth));
42
+ }, [curveDepth, points]);
43
+ return <path stroke={stroke} stroke-dasharray={strokeDasharray} d={d}></path>;
41
44
  };
package/src/icon.tsx CHANGED
@@ -4,7 +4,8 @@ import { ImageChar } from "./ImageChar";
4
4
  import { Shape } from "./shape";
5
5
 
6
6
  export interface Icon {
7
- shape?: "circle" | "square";
7
+ shape?: "circle" | "square" | "rectangle";
8
+ width?: number;
8
9
  height?: number;
9
10
  padding?: number;
10
11
  fill?: string;
@@ -13,6 +14,7 @@ export interface Icon {
13
14
  imageFontFamily?: string;
14
15
  imageChar?: string;
15
16
  imageCharFill?: string;
17
+ xOffset?: number;
16
18
  yOffset?: number;
17
19
  cornerRadius?: number;
18
20
  shapeRendering?: "auto" | "optimizeSpeed" | "crispEdges" | "geometricPrecision";
@@ -20,6 +22,7 @@ export interface Icon {
20
22
 
21
23
  export const Icon: React.FunctionComponent<Icon> = ({
22
24
  shape = "circle",
25
+ width,
23
26
  height = 32,
24
27
  fill,
25
28
  stroke,
@@ -28,6 +31,7 @@ export const Icon: React.FunctionComponent<Icon> = ({
28
31
  imageChar = "",
29
32
  imageCharFill = Palette.textColor(fill),
30
33
  padding = height / 5,
34
+ xOffset = 0,
31
35
  yOffset = 0,
32
36
  cornerRadius,
33
37
  shapeRendering
@@ -35,6 +39,7 @@ export const Icon: React.FunctionComponent<Icon> = ({
35
39
  return <>
36
40
  <Shape
37
41
  shape={shape}
42
+ width={width}
38
43
  height={height}
39
44
  fill={fill}
40
45
  stroke={stroke}
@@ -43,6 +48,7 @@ export const Icon: React.FunctionComponent<Icon> = ({
43
48
  cornerRadius={cornerRadius}
44
49
  />
45
50
  <ImageChar
51
+ x={xOffset}
46
52
  y={yOffset}
47
53
  height={height - padding}
48
54
  fontFamily={imageFontFamily}
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export * from "./text";
9
9
  export * from "./vertex";
10
10
  export * from "./vertex2";
11
11
  export * from "./vertex3";
12
+ export * from "./vertex4";
12
13
  export * from "./subgraph";
13
14
 
14
15
  import * as React from "@hpcc-js/preact-shim";
package/src/shape.tsx CHANGED
@@ -85,8 +85,9 @@ export const Rectangle: React.FunctionComponent<Rectangle> = ({
85
85
  };
86
86
 
87
87
  interface Shape {
88
- shape?: "circle" | "square";
88
+ shape?: "circle" | "square" | "rectangle";
89
89
  height?: number;
90
+ width?: number;
90
91
  fill?: string;
91
92
  stroke?: string;
92
93
  strokeWidth?: number;
@@ -97,6 +98,7 @@ interface Shape {
97
98
  export const Shape: React.FunctionComponent<Shape> = ({
98
99
  shape = "circle",
99
100
  height = 128,
101
+ width,
100
102
  fill,
101
103
  stroke,
102
104
  strokeWidth = 1,
@@ -113,6 +115,16 @@ export const Shape: React.FunctionComponent<Shape> = ({
113
115
  shapeRendering={shapeRendering}
114
116
  cornerRadius={cornerRadius}
115
117
  />;
118
+ case "rectangle":
119
+ return <Rectangle
120
+ width={width ?? height}
121
+ height={height}
122
+ fill={fill}
123
+ stroke={stroke}
124
+ strokeWidth={strokeWidth}
125
+ shapeRendering={shapeRendering}
126
+ cornerRadius={cornerRadius}
127
+ />;
116
128
  case "circle":
117
129
  default:
118
130
  return <Circle
package/src/text.tsx CHANGED
@@ -44,28 +44,37 @@ export const Text: React.FunctionComponent<Text> = ({
44
44
  fill = "black",
45
45
  onSizeUpdate
46
46
  }) => {
47
- const [totalWidth, onTotalWidthUpdate] = React.useState(0);
48
- const [totalHeight, onTotalHeightUpdate] = React.useState(0);
47
+ const [totalWidth, setTotalWidthUpdate] = React.useState(0);
48
+ const [totalHeight, setTotalHeightUpdate] = React.useState(0);
49
+
49
50
  React.useEffect(() => {
50
51
  onSizeUpdate && onSizeUpdate({ width: totalWidth, height: totalHeight });
51
52
  }, [totalWidth, totalHeight, onSizeUpdate]);
52
53
 
53
- const parts = text.split("\n");
54
- const ts = Utility.textSize(parts, fontFamily, height);
55
- onTotalWidthUpdate(ts.width);
56
- onTotalHeightUpdate(parts.length * (height + 2) - 2);
54
+ const parts = React.useMemo(() => {
55
+ return text.split("\n");
56
+ }, [text]);
57
+
58
+ const ts = React.useMemo(() => {
59
+ return Utility.textSize(parts, fontFamily, height);
60
+ }, [fontFamily, height, parts]);
61
+
62
+ setTotalWidthUpdate(ts.width);
63
+ setTotalHeightUpdate(parts.length * (height + 2) - 2);
57
64
 
58
65
  const yOffset = -(totalHeight / 2) + (height / 2);
59
- const TextLines = parts.map((p, i) => {
60
- return <g transform={`translate(0 ${yOffset + i * (height + 2)})`}>
61
- <TextLine
62
- text={p}
63
- height={height}
64
- fontFamily={fontFamily}
65
- fill={fill}
66
- />
67
- </g>;
68
- });
66
+ const TextLines = React.useMemo(() => {
67
+ return parts.map((p, i) => {
68
+ return <g key={i} transform={`translate(0 ${yOffset + i * (height + 2)})`}>
69
+ <TextLine
70
+ text={p}
71
+ height={height}
72
+ fontFamily={fontFamily}
73
+ fill={fill}
74
+ />
75
+ </g>;
76
+ });
77
+ }, [fill, fontFamily, height, parts, yOffset]);
69
78
 
70
79
  return <>{TextLines}</>;
71
80
  };
@@ -96,15 +105,22 @@ export const TextBox: React.FunctionComponent<TextBox> = ({
96
105
  cornerRadius = 0,
97
106
  onSizeUpdate
98
107
  }) => {
99
- const [textWidth, onTextWidthUpdate] = React.useState(0);
100
- const [textHeight, onTextHeightUpdate] = React.useState(0);
108
+ const [textWidth, setTextWidthUpdate] = React.useState(0);
109
+ const [textHeight, setTextHeightUpdate] = React.useState(0);
110
+
101
111
  React.useEffect(() => {
102
112
  onSizeUpdate && onSizeUpdate({ width: textWidth, height: textHeight });
103
113
  }, [textWidth, textHeight, onSizeUpdate]);
104
114
 
115
+ const onTextSizeUpdate = React.useCallback(size => {
116
+ setTextWidthUpdate(size.width);
117
+ setTextHeightUpdate(size.height);
118
+ }, []);
119
+
105
120
  const w = textWidth + padding * 2 + strokeWidth;
106
121
  const h = textHeight + padding * 2 + strokeWidth;
107
122
  const textOffsetY = Math.floor(height / 10);
123
+
108
124
  return <>
109
125
  <Rectangle
110
126
  width={w}
@@ -123,13 +139,7 @@ export const TextBox: React.FunctionComponent<TextBox> = ({
123
139
  onSizeUpdate={onTextSizeUpdate}
124
140
  />
125
141
  </g>
126
- </>
127
- ;
128
-
129
- function onTextSizeUpdate(size) {
130
- onTextWidthUpdate(size.width);
131
- onTextHeightUpdate(size.height);
132
- }
142
+ </>;
133
143
  };
134
144
 
135
145
  export interface LabelledRect extends TextBox {
@@ -176,8 +186,7 @@ export const LabelledRect: React.FunctionComponent<LabelledRect> = ({
176
186
  baseline="hanging"
177
187
  />
178
188
  </g>
179
- </>
180
- ;
189
+ </>;
181
190
  };
182
191
 
183
192
  export const IconLabelledRect: React.FunctionComponent<IconLabelledRect> = ({
@@ -225,6 +234,5 @@ export const IconLabelledRect: React.FunctionComponent<IconLabelledRect> = ({
225
234
  baseline="hanging"
226
235
  />
227
236
  </g>
228
- </>
229
- ;
237
+ </>;
230
238
  };
package/src/vertex.tsx CHANGED
@@ -58,8 +58,9 @@ export const Vertex: React.FunctionComponent<Vertex> = ({
58
58
  onSizeUpdate,
59
59
  showLabel = true
60
60
  }) => {
61
- const [textBoxWidth, onTextBoxWidthUpdate] = React.useState(0);
62
- const [textBoxHeight, onTextBoxHeightUpdate] = React.useState(0);
61
+ const [textBoxWidth, setTextBoxWidthUpdate] = React.useState(0);
62
+ const [textBoxHeight, setTextBoxHeightUpdate] = React.useState(0);
63
+
63
64
  React.useEffect(() => {
64
65
  onSizeUpdate && onSizeUpdate({ width: 0, height: 0 });
65
66
  }, [textBoxWidth, textBoxHeight, onSizeUpdate]);
@@ -79,6 +80,12 @@ export const Vertex: React.FunctionComponent<Vertex> = ({
79
80
  offsetY += (textHeight + 8) / 2;
80
81
  annotationOffsetY -= textBoxHeight + textPadding;
81
82
  }
83
+
84
+ const onTextBoxSizeUpdate = React.useCallback(size => {
85
+ setTextBoxWidthUpdate(size.width);
86
+ setTextBoxHeightUpdate(size.height);
87
+ }, []);
88
+
82
89
  const label = showLabel ? <g transform={`translate(0 ${textboxOffsetY})`}>
83
90
  <TextBox
84
91
  text={text}
@@ -101,9 +108,4 @@ export const Vertex: React.FunctionComponent<Vertex> = ({
101
108
  <Icon {...icon} />
102
109
  {label}
103
110
  </g>;
104
-
105
- function onTextBoxSizeUpdate(size) {
106
- onTextBoxWidthUpdate(size.width);
107
- onTextBoxHeightUpdate(size.height);
108
- }
109
111
  };
package/src/vertex2.tsx CHANGED
@@ -26,7 +26,9 @@ export const Vertex2: React.FunctionComponent<Vertex> = ({
26
26
  ...icon
27
27
  };
28
28
  const textBoxHeight = textHeight + textPadding * 2;
29
- const { width } = Utility.textSize(text, textFontFamily, textHeight, false);
29
+ const { width } = React.useMemo(() => {
30
+ return Utility.textSize(text, textFontFamily, textHeight, false);
31
+ }, [text, textFontFamily, textHeight]);
30
32
 
31
33
  const stepSize = annotationsHeight;
32
34
  const textboxStrokeWidth = 1;
package/src/vertex3.tsx CHANGED
@@ -23,6 +23,7 @@ export interface IVertex3 extends Vertex {
23
23
  onSizeUpdate?: (size: { width: number, height: number }) => void;
24
24
  showLabel?: boolean;
25
25
  noLabelRadius?: number;
26
+ expansionIcon?: Icon;
26
27
  }
27
28
 
28
29
  export const Vertex3: React.FunctionComponent<IVertex3> = ({
@@ -41,8 +42,8 @@ export const Vertex3: React.FunctionComponent<IVertex3> = ({
41
42
  icon = {},
42
43
  subText = {},
43
44
  showLabel = true,
44
- noLabelRadius = 5
45
-
45
+ noLabelRadius = 5,
46
+ expansionIcon
46
47
  }) => {
47
48
  icon = {
48
49
  height: 50,
@@ -59,11 +60,26 @@ export const Vertex3: React.FunctionComponent<IVertex3> = ({
59
60
  textFill: "#555555",
60
61
  ...subText
61
62
  };
63
+ expansionIcon = expansionIcon ? {
64
+ height: 16,
65
+ shape: "circle",
66
+ padding: 6,
67
+ imageChar: "?",
68
+ imageFontFamily: "FontAwesome",
69
+ imageCharFill: "black",
70
+ fill: "whitesmoke",
71
+ stroke: "whitesmoke",
72
+ strokeWidth: 0,
73
+ ...expansionIcon
74
+ } : undefined;
62
75
  let fullAnnotationWidth = 0;
63
76
 
64
77
  const annoOffsetY = 0;
65
78
 
66
- const labelWidth = Utility.textSize(text, textFontFamily, textHeight, false).width;
79
+ const labelWidth = React.useMemo(() => {
80
+ return Utility.textSize(text, textFontFamily, textHeight, false).width;
81
+ }, [text, textFontFamily, textHeight]);
82
+
67
83
  let labelShapeWidth = 0;
68
84
  if (text !== "") {
69
85
  labelShapeWidth = labelWidth + (textPadding * 2) + (textboxStrokeWidth * 2);
@@ -73,13 +89,13 @@ export const Vertex3: React.FunctionComponent<IVertex3> = ({
73
89
 
74
90
  const textShapeHeight = textHeight + (textPadding * 2) + (textboxStrokeWidth * 2);
75
91
  const annotationArr = [];
76
- annotations.forEach(anno => {
92
+ annotations.forEach((anno, idx) => {
77
93
  const annoText = anno.imageChar;
78
94
  const annoShapeWidth = textShapeHeight;
79
95
  fullAnnotationWidth += annoShapeWidth + annotationGutter;
80
96
  const annoOffsetX = fullAnnotationWidth - (annoShapeWidth / 2);
81
97
  annotationArr.push(
82
- <g class="vertex3-anno" transform={`translate(${annoOffsetX} ${annoOffsetY})`}>
98
+ <g key={idx} class="vertex3-anno" data-click={"annotation"} data-click-data={JSON.stringify(anno)} transform={`translate(${annoOffsetX} ${annoOffsetY})`}>
83
99
  <Icon
84
100
  {...anno}
85
101
  shape="square"
@@ -95,7 +111,7 @@ export const Vertex3: React.FunctionComponent<IVertex3> = ({
95
111
  if (annotations.length > 0) {
96
112
  fullAnnotationWidth += annotationGutter * (annotations.length - 1);
97
113
  }
98
- const textElement = <g transform={`translate(${textOffsetX} ${annoOffsetY})`}>
114
+ const textElement = <g data-click={"text"} transform={`translate(${textOffsetX} ${annoOffsetY})`}>
99
115
  {!showLabel || text === "" ? <circle r={noLabelRadius} stroke={textboxStroke} fill={textFill} /> : <TextBox
100
116
  text={text}
101
117
  height={textHeight}
@@ -121,7 +137,8 @@ export const Vertex3: React.FunctionComponent<IVertex3> = ({
121
137
  } else if (subText.text !== "") {
122
138
  subTextOffsetY = (iconHeight / 2) + iconStrokeWidth + (annotationGutter * 2);
123
139
  }
124
- const subtextElement = subText.text === "" ? null : <g
140
+
141
+ const subtextElement = subText.text === "" ? null : <g data-click={"subtext"}
125
142
  transform={`translate(${subTextOffsetX} ${subTextOffsetY})`}
126
143
  >
127
144
  <TextBox
@@ -136,23 +153,22 @@ export const Vertex3: React.FunctionComponent<IVertex3> = ({
136
153
  cornerRadius={cornerRadius}
137
154
  />
138
155
  </g>;
156
+
139
157
  return <g>
140
- <g
141
- transform={`translate(${iconOffsetX} ${iconOffsetY})`}
142
- >
143
- <Icon
144
- {...icon}
145
- />
158
+ <g data-click={"icon"} transform={`translate(${iconOffsetX} ${iconOffsetY})`}>
159
+ <Icon {...icon} />
160
+ {expansionIcon &&
161
+ <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})`}>
162
+ <Icon {...expansionIcon} />
163
+ </g>
164
+ }
146
165
  </g>
147
- <g
148
- transform={`translate(${-fullAnnotationWidth / 2} ${annoOffsetY})`}
149
- >
166
+ <g transform={`translate(${-fullAnnotationWidth / 2} ${annoOffsetY})`} >
150
167
  {textElement}
151
168
  {annotationArr}
152
169
  </g>
153
170
  {subtextElement}
154
- </g>
155
- ;
171
+ </g >;
156
172
  };
157
173
 
158
174
  export const CentroidVertex3: React.FunctionComponent<IVertex3> = function ({
@@ -169,7 +185,8 @@ export const CentroidVertex3: React.FunctionComponent<IVertex3> = function ({
169
185
  annotations = [],
170
186
  cornerRadius,
171
187
  icon = {},
172
- subText = {}
188
+ subText = {},
189
+ expansionIcon
173
190
  }) {
174
191
  icon = {
175
192
  height: 91,
@@ -203,7 +220,8 @@ export const CentroidVertex3: React.FunctionComponent<IVertex3> = function ({
203
220
  annotations,
204
221
  cornerRadius,
205
222
  icon,
206
- subText
223
+ subText,
224
+ expansionIcon
207
225
  };
208
226
  return <Vertex3
209
227
  {...props}