Skip to content

Commit 6c1ebce

Browse files
Andras-Simondanielcaldas
authored andcommitted
Allow nodes to override strokeColor (#123)
* feat: Allow nodes to override strokeColor #122 * docs: Update jsdoc for strokeColor * test: Add test case for strokeColor node granularity
1 parent 382cd08 commit 6c1ebce

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/components/graph/graph.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
* @param {boolean} [node.renderLabel=true] - when set to false no labels will appear along side nodes in the
9797
* graph.
9898
* @param {number} [node.size=200] - 🔍🔍🔍 defines the size of all nodes.
99-
* @param {string} [node.strokeColor='none'] - color for the stroke of each node.
99+
* @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** ).
100100
* @param {number} [node.strokeWidth=1.5] - the width of the all node strokes.
101101
* @param {string} [node.svg=''] - 🔍🔍🔍 render custom svg for nodes in alternative to **node.symbolType**. This svg can
102102
* be provided as a string to either a remote svg resource or for a local one.

src/components/graph/graph.helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
316316
fill = config.node.highlightColor;
317317
}
318318

319-
let stroke = config.node.strokeColor;
319+
let stroke = node.strokeColor || config.node.strokeColor;
320320

321321
if (highlight && config.node.highlightStrokeColor !== CONST.KEYWORDS.SAME) {
322322
stroke = config.node.highlightStrokeColor;

test/component/graph/graph.helper.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,27 @@ describe('Graph Helper', () => {
218218
});
219219
});
220220
});
221+
describe('and no custom strokeColor is set', () => {
222+
test('should return the default strokeColor in the props', () => {
223+
const props = graphHelper.buildNodeProps(that.node, that.config, undefined, undefined, undefined, 1);
224+
225+
expect(props.stroke).toEqual('none');
226+
});
227+
});
228+
describe('and custom strokeColor is set to yellow', () => {
229+
test('should return yellow strokeColor in the props', () => {
230+
const props = graphHelper.buildNodeProps(
231+
{ ...that.node, strokeColor: 'yellow' },
232+
that.config,
233+
undefined,
234+
undefined,
235+
undefined,
236+
1
237+
);
238+
239+
expect(props.stroke).toEqual('yellow');
240+
});
241+
});
221242
});
222243

223244
describe('#initializeGraphState', () => {

0 commit comments

Comments
 (0)