Skip to content

Commit b2431a7

Browse files
committed
refactor: minor improvements for recently merged PRs
1 parent e5cd27e commit b2431a7

File tree

6 files changed

+386
-355
lines changed

6 files changed

+386
-355
lines changed

sandbox/data/custom-node/custom-node.config.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,48 @@ import React from "react";
22
import CustomNode from "./CustomNode";
33

44
export default {
5-
automaticRearrangeAfterDropNode: false,
6-
collapsible: false,
7-
height: 400,
8-
highlightDegree: 1,
9-
highlightOpacity: 0.2,
10-
linkHighlightBehavior: true,
11-
maxZoom: 8,
12-
minZoom: 0.1,
13-
nodeHighlightBehavior: true,
14-
panAndZoom: false,
15-
staticGraph: false,
16-
width: 800,
17-
node: {
18-
color: "#d3d3d3",
19-
fontColor: "black",
20-
fontSize: 12,
21-
fontWeight: "normal",
22-
highlightColor: "red",
23-
highlightFontSize: 12,
24-
highlightFontWeight: "bold",
25-
highlightStrokeColor: "SAME",
26-
highlightStrokeWidth: 1.5,
27-
labelProperty: "name",
28-
labelClass: "person-node-label",
29-
mouseCursor: "pointer",
30-
opacity: 1,
31-
renderLabel: false,
32-
size: {
33-
width: 700,
34-
height: 900,
35-
},
36-
strokeColor: "none",
37-
strokeWidth: 1.5,
38-
svg: "",
39-
symbolType: "circle",
40-
viewGenerator: node => <CustomNode person={node} />,
41-
},
42-
link: {
43-
color: "#d3d3d3",
44-
opacity: 1,
45-
semanticStrokeWidth: false,
46-
strokeWidth: 4,
47-
highlightColor: "blue",
5+
automaticRearrangeAfterDropNode: false,
6+
collapsible: false,
7+
height: 400,
8+
highlightDegree: 1,
9+
highlightOpacity: 0.2,
10+
linkHighlightBehavior: true,
11+
maxZoom: 8,
12+
minZoom: 0.1,
13+
nodeHighlightBehavior: true,
14+
panAndZoom: false,
15+
staticGraph: false,
16+
width: 800,
17+
node: {
18+
color: "#d3d3d3",
19+
fontColor: "black",
20+
fontSize: 12,
21+
fontWeight: "normal",
22+
highlightColor: "red",
23+
highlightFontSize: 12,
24+
highlightFontWeight: "bold",
25+
highlightStrokeColor: "SAME",
26+
highlightStrokeWidth: 1.5,
27+
labelProperty: "name",
28+
// labelClass: "person-node-label",
29+
mouseCursor: "pointer",
30+
opacity: 1,
31+
renderLabel: true,
32+
size: {
33+
width: 700,
34+
height: 900,
4835
},
36+
strokeColor: "none",
37+
strokeWidth: 1.5,
38+
svg: "",
39+
symbolType: "circle",
40+
viewGenerator: node => <CustomNode person={node} />,
41+
},
42+
link: {
43+
color: "#d3d3d3",
44+
opacity: 1,
45+
semanticStrokeWidth: false,
46+
strokeWidth: 4,
47+
highlightColor: "blue",
48+
},
4949
};
Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,75 @@
11
/* --- Generic styles --- */
22

33
.flex-container {
4-
flex-direction: column;
5-
display: flex;
4+
flex-direction: column;
5+
display: flex;
66
}
77

88
.flex-container-column {
9-
flex-direction: column;
9+
flex-direction: column;
1010
}
1111

1212
.flex-container-row {
13-
flex-direction: row;
13+
flex-direction: row;
1414
}
1515

1616
.fill-space {
17-
flex-grow: 1;
17+
flex-grow: 1;
1818
}
1919

2020
.icon {
21-
width: 100%;
22-
height: 100%;
23-
background-size: contain;
24-
background-position: center;
25-
background-repeat: no-repeat;
21+
width: 100%;
22+
height: 100%;
23+
background-size: contain;
24+
background-position: center;
25+
background-repeat: no-repeat;
2626
}
2727

2828
/* --- Shape for the nodes --- */
2929

3030
.person-node {
31-
width: 100%;
32-
height: 100%;
33-
border-radius: 35% 5% 35% 5%;
34-
overflow: hidden;
35-
box-sizing: border-box;
36-
display: flex;
31+
width: 100%;
32+
height: 100%;
33+
border-radius: 35% 5% 35% 5%;
34+
overflow: hidden;
35+
box-sizing: border-box;
36+
display: flex;
3737
}
3838

3939
.person-node.male {
40-
background-color: lightblue;
41-
box-shadow: 25px 15px cadetblue;
40+
background-color: lightblue;
41+
box-shadow: 25px 15px cadetblue;
4242
}
4343

4444
.person-node.female {
45-
background-color: pink;
46-
box-shadow: 25px 15px palevioletred;
45+
background-color: pink;
46+
box-shadow: 25px 15px palevioletred;
4747
}
4848

4949
/* --- Other styles for node content --- */
5050

5151
.person-node .name {
52-
padding: 5%;
53-
font-size: 0.8rem;
54-
font-weight: bold;
55-
text-align: center;
56-
text-transform: uppercase;
52+
padding: 5%;
53+
font-size: 0.8rem;
54+
font-weight: bold;
55+
text-align: center;
56+
text-transform: uppercase;
5757
}
5858

5959
.person-node .icon-bar {
60-
width: 20%;
61-
margin-right: 5%;
60+
width: 20%;
61+
margin-right: 5%;
6262
}
6363

6464
.person-node .icon-bar > .icon {
65-
width: 80%;
66-
height: 30%;
65+
width: 80%;
66+
height: 30%;
6767
}
6868

69-
/* --- Node label style --- */
70-
69+
/* you need to toggle `node.renderLabel` to see this class in action */
7170
.person-node-label {
72-
fill: black;
73-
text-shadow: rgb(255, 255, 255) 0px -2px 0px, rgb(255, 255, 255) 0px 2px 0px, rgb(255, 255, 255) 2px 0px 0px,
74-
rgb(255, 255, 255) -2px 0px 0px;
75-
transform: rotate(-25deg) translateX(40px) translateY(15px);
71+
fill: black;
72+
text-shadow: rgb(255, 255, 255) 0px -2px 0px, rgb(255, 255, 255) 0px 2px 0px, rgb(255, 255, 255) 2px 0px 0px,
73+
rgb(255, 255, 255) -2px 0px 0px;
74+
transform: rotate(-25deg) translateX(40px) translateY(15px);
7675
}

src/components/graph/graph.builder.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Offers a series of methods that isolate the way graph elements are built (nodes and links mainly).
55
*/
66
import CONST from "./graph.const";
7+
import { isNil } from "../../utils";
78

89
import { buildLinkPathDefinition } from "../link/link.helper";
910
import { getMarkerId } from "../marker/marker.helper";
@@ -232,12 +233,12 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
232233
const fontColor = node.fontColor || config.node.fontColor;
233234

234235
let renderLabel = config.node.renderLabel;
235-
if (node.renderLabel !== undefined && typeof node.renderLabel === "boolean") {
236+
if (!isNil(node.renderLabel) && typeof node.renderLabel === "boolean") {
236237
renderLabel = node.renderLabel;
237238
}
238239

239240
var labelClass = config.node.labelClass;
240-
if (node.labelClass !== undefined && typeof node.labelClass === "string") {
241+
if (!isNil(node.labelClass) && typeof node.labelClass === "string") {
241242
labelClass = node.labelClass;
242243
}
243244

src/components/node/Node.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class Node extends React.Component {
9494
fontSize: this.props.fontSize,
9595
fontWeight: this.props.fontWeight,
9696
opacity: this.props.opacity,
97-
...(this.props.labelClass !== "" && { className: this.props.labelClass }),
97+
...(this.props.labelClass && { className: this.props.labelClass }),
9898
};
9999

100100
let size = this.props.size;

src/utils.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ function isEmptyObject(o) {
8484
return !!o && typeof o === "object" && !Object.keys(o).length;
8585
}
8686

87+
/**
88+
* Checks if given input is undefined or null
89+
* @param {any} o variable target
90+
* @returns {boolean} true if input is either undefined or null
91+
* @memberof utils
92+
*/
93+
function isNil(o) {
94+
return o === undefined || o === null;
95+
}
96+
8797
/**
8898
* Function to deep clone plain javascript objects.
8999
* @param {Object} o - the object to clone.
@@ -238,4 +248,16 @@ function logWarning(component, msg) {
238248
console.warn(warning);
239249
}
240250

241-
export { isDeepEqual, isEmptyObject, deepClone, merge, pick, antiPick, debounce, throwErr, logError, logWarning };
251+
export {
252+
isDeepEqual,
253+
isEmptyObject,
254+
isNil,
255+
deepClone,
256+
merge,
257+
pick,
258+
antiPick,
259+
debounce,
260+
throwErr,
261+
logError,
262+
logWarning,
263+
};

0 commit comments

Comments
 (0)