Skip to content

Commit

Permalink
Allow nodes to override strokeColor (#123)
Browse files Browse the repository at this point in the history
* feat: Allow nodes to override strokeColor #122

* docs: Update jsdoc for strokeColor

* test: Add test case for strokeColor node granularity
  • Loading branch information
Andras-Simon authored and danielcaldas committed Oct 3, 2018
1 parent 382cd08 commit 6c1ebce
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/graph/graph.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
* @param {boolean} [node.renderLabel=true] - when set to false no labels will appear along side nodes in the
* graph.
* @param {number} [node.size=200] - 🔍🔍🔍 defines the size of all nodes.
* @param {string} [node.strokeColor='none'] - color for the stroke of each node.
* @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** ).
* @param {number} [node.strokeWidth=1.5] - the width of the all node strokes.
* @param {string} [node.svg=''] - 🔍🔍🔍 render custom svg for nodes in alternative to **node.symbolType**. This svg can
* be provided as a string to either a remote svg resource or for a local one.
Expand Down
2 changes: 1 addition & 1 deletion src/components/graph/graph.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
fill = config.node.highlightColor;
}

let stroke = config.node.strokeColor;
let stroke = node.strokeColor || config.node.strokeColor;

if (highlight && config.node.highlightStrokeColor !== CONST.KEYWORDS.SAME) {
stroke = config.node.highlightStrokeColor;
Expand Down
21 changes: 21 additions & 0 deletions test/component/graph/graph.helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,27 @@ describe('Graph Helper', () => {
});
});
});
describe('and no custom strokeColor is set', () => {
test('should return the default strokeColor in the props', () => {
const props = graphHelper.buildNodeProps(that.node, that.config, undefined, undefined, undefined, 1);

expect(props.stroke).toEqual('none');
});
});
describe('and custom strokeColor is set to yellow', () => {
test('should return yellow strokeColor in the props', () => {
const props = graphHelper.buildNodeProps(
{ ...that.node, strokeColor: 'yellow' },
that.config,
undefined,
undefined,
undefined,
1
);

expect(props.stroke).toEqual('yellow');
});
});
});

describe('#initializeGraphState', () => {
Expand Down

0 comments on commit 6c1ebce

Please sign in to comment.