Skip to content

Commit 0832e5f

Browse files
Nathaniel Sauldanielcaldas
authored andcommitted
More granular resolution of node and link parameters (#166)
* * node level setting for opacity and strokeWidth * link level setting for opacity * * add eyeglasses to config for node opacity and strokeWidth * add eyeglasses to config for link opacity * add prepare script so npm can install from github * pass linting * Update for code review: - revert version bump - set default strokeWidth to SAME - add link level resolution to strokeWidth (for issue 149) * add eyeglasses to link.strokeWidth * remove prepare script
1 parent 8247431 commit 0832e5f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/components/graph/graph.builder.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function _getNodeOpacity(node, highlightedNode, highlightedLink, config) {
3333
} else if (someNodeHighlighted) {
3434
opacity = highlight ? config.node.opacity : config.highlightOpacity;
3535
} else {
36-
opacity = config.node.opacity;
36+
opacity = node.opacity || config.node.opacity;
3737
}
3838

3939
return opacity;
@@ -81,7 +81,7 @@ function buildLinkProps(link, nodes, links, config, linkCallbacks, highlightedNo
8181
target === (highlightedLink && highlightedLink.target);
8282
const highlight = reasonNode || reasonLink;
8383

84-
let opacity = config.link.opacity;
84+
let opacity = link.opacity || config.link.opacity;
8585

8686
if (highlightedNode || (highlightedLink && highlightedLink.source)) {
8787
opacity = highlight ? config.link.opacity : config.highlightOpacity;
@@ -93,7 +93,7 @@ function buildLinkProps(link, nodes, links, config, linkCallbacks, highlightedNo
9393
stroke = config.link.highlightColor === CONST.KEYWORDS.SAME ? config.link.color : config.link.highlightColor;
9494
}
9595

96-
let strokeWidth = config.link.strokeWidth * (1 / transform);
96+
let strokeWidth = (link.strokeWidth || config.link.strokeWidth) * (1 / transform);
9797

9898
if (config.link.semanticStrokeWidth) {
9999
const linkValue = links[source][target] || links[target][source] || 1;
@@ -137,6 +137,7 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
137137
(node.id === (highlightedLink && highlightedLink.source) ||
138138
node.id === (highlightedLink && highlightedLink.target));
139139
const opacity = _getNodeOpacity(node, highlightedNode, highlightedLink, config);
140+
140141
let fill = node.color || config.node.color;
141142

142143
if (highlight && config.node.highlightColor !== CONST.KEYWORDS.SAME) {
@@ -155,11 +156,16 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
155156
label = config.node.labelProperty(node);
156157
}
157158

159+
let strokeWidth = node.strokeWidth || config.node.strokeWidth;
160+
161+
if (highlight && config.node.highlightStrokeWidth !== CONST.KEYWORDS.SAME) {
162+
strokeWidth = config.node.highlightStrokeWidth;
163+
}
164+
158165
const t = 1 / transform;
159166
const nodeSize = node.size || config.node.size;
160167
const fontSize = highlight ? config.node.highlightFontSize : config.node.fontSize;
161168
const dx = fontSize * t + nodeSize / 100 + 1.5;
162-
const strokeWidth = highlight ? config.node.highlightStrokeWidth : config.node.strokeWidth;
163169
const svg = node.svg || config.node.svg;
164170
const fontColor = node.fontColor || config.node.fontColor;
165171

src/components/graph/graph.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
* @param {number} [node.highlightFontSize=8] - fontSize in highlighted state.
108108
* @param {string} [node.highlightFontWeight='normal'] - fontWeight in highlighted state.
109109
* @param {string} [node.highlightStrokeColor='SAME'] - strokeColor in highlighted state.
110-
* @param {number} [node.highlightStrokeWidth=1.5] - strokeWidth in highlighted state.
110+
* @param {number} [node.highlightStrokeWidth='SAME'] - strokeWidth in highlighted state.
111111
* @param {string|Function} [node.labelProperty='id'] - this is the node property that will be used in runtime to
112112
* fetch the label content. You just need to add some property (e.g. firstName) to the node payload and then set
113113
* node.labelProperty to be **'firstName'**. **This can also be a function!**, if you pass a function here it will be called
@@ -123,12 +123,12 @@
123123
* <br/>
124124
* @param {string} [node.mouseCursor='pointer'] - {@link https://developer.mozilla.org/en/docs/Web/CSS/cursor?v=control|cursor}
125125
* property for when some node is mouse hovered.
126-
* @param {number} [node.opacity=1] - by default all nodes will have this opacity value.
126+
* @param {number} [node.opacity=1] 🔍🔍🔍 - by default all nodes will have this opacity value.
127127
* @param {boolean} [node.renderLabel=true] - when set to false no labels will appear along side nodes in the
128128
* graph.
129129
* @param {number} [node.size=200] - 🔍🔍🔍 defines the size of all nodes.
130130
* @param {string} [node.strokeColor='none'] - 🔍🔍🔍 this is the stroke color that will be applied to the node if no **strokeColor property** is found inside the node itself (yes **you can pass a property 'strokeColor' inside the node and that stroke color will override this default one** ).
131-
* @param {number} [node.strokeWidth=1.5] - the width of the all node strokes.
131+
* @param {number} [node.strokeWidth=1.5] 🔍🔍🔍 - the width of the all node strokes.
132132
* @param {string} [node.svg=''] - 🔍🔍🔍 render custom svg for nodes in alternative to **node.symbolType**. This svg can
133133
* be provided as a string to either a remote svg resource or for a local one.
134134
* <br/>
@@ -154,14 +154,14 @@
154154
* <img src="https://github.com/danielcaldas/react-d3-graph/blob/master/docs/rd3g-bend.gif?raw=true" width="820" height="480"/>
155155
* @param {string} [link.mouseCursor='pointer'] - {@link https://developer.mozilla.org/en/docs/Web/CSS/cursor?v=control|cursor}
156156
* property for when link is mouse hovered.
157-
* @param {number} [link.opacity=1] - the default opacity value for links.
157+
* @param {number} [link.opacity=1] 🔍🔍🔍 - the default opacity value for links.
158158
* @param {boolean} [link.semanticStrokeWidth=false] - when set to true all links will have
159159
* *"semantic width"*, this means that the width of the connections will be proportional to the value of each link.
160160
* This is how link strokeWidth will be calculated:
161161
* ```javascript
162162
* strokeWidth += (linkValue * strokeWidth) / 10;
163163
* ```
164-
* @param {number} [link.strokeWidth=1.5] - strokeWidth for all links. By default the actual value is obtain by the
164+
* @param {number} [link.strokeWidth=1.5] 🔍🔍🔍 - strokeWidth for all links. By default the actual value is obtain by the
165165
* following expression:
166166
* ```javascript
167167
* link.strokeWidth * (1 / transform); // transform is a zoom delta Δ value
@@ -219,7 +219,7 @@ export default {
219219
highlightFontSize: 8,
220220
highlightFontWeight: "normal",
221221
highlightStrokeColor: "SAME",
222-
highlightStrokeWidth: 1.5,
222+
highlightStrokeWidth: "SAME",
223223
labelProperty: "id",
224224
mouseCursor: "pointer",
225225
opacity: 1,

0 commit comments

Comments
 (0)