Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support to pass a function to node.labelProperty #135

Merged
merged 9 commits into from Oct 17, 2018

Conversation

@dgautsch
Copy link
Contributor

dgautsch commented Oct 16, 2018

Changes

  • If config.node.labelProperty is a string follow the current approach
  • If config.node.labelProperty is a function then call that function and pass in the node as parameter
  • Implement a sample config.node.labelProperty in the marvel dataset where the output of labelProperty is the concatenation of the characterid+ the charactername`

Fixes #133

@dgautsch dgautsch changed the title Adds Support to pass a function to node.labelProperty Add Support to pass a function to node.labelProperty Oct 16, 2018
@@ -30,7 +30,7 @@ module.exports = {
highlightFontWeight: 'bold',
highlightStrokeColor: 'red',
highlightStrokeWidth: 1.5,
labelProperty: 'id',
labelProperty: n => n.id + n.name,

This comment has been minimized.

Copy link
@danielcaldas

danielcaldas Oct 16, 2018

Owner
Suggested change
labelProperty: n => n.id + n.name,
labelProperty: n => `${n.id} - ${n.name}`,
@@ -7,7 +7,7 @@
"scripts": {

This comment has been minimized.

Copy link
@danielcaldas

danielcaldas Oct 16, 2018

Owner

Please rebase with master and also drop the changes on sandbox/rd3g.sandbox.**

@@ -331,6 +331,7 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
node.id === (highlightedLink && highlightedLink.target));
const opacity = _getNodeOpacity(node, highlightedNode, highlightedLink, config);
let fill = node.color || config.node.color;
let labelProperty = node[config.node.labelProperty] || node.id;

This comment has been minimized.

Copy link
@danielcaldas

danielcaldas Oct 16, 2018

Owner

Please rename labelProperty to label and move this assignment next to the new logic that you added

Copy link
Owner

danielcaldas left a comment

Left some minor comments.

@dgautsch dgautsch force-pushed the dgautsch:fix/133 branch from 82a521b to e8c9c00 Oct 17, 2018
@dgautsch

This comment has been minimized.

Copy link
Contributor Author

dgautsch commented Oct 17, 2018

@danielcaldas Thanks for the feedback! I made the changes you suggested.

@danielcaldas danielcaldas force-pushed the dgautsch:fix/133 branch from 5d45fbe to 9d03c39 Oct 17, 2018
@danielcaldas

This comment has been minimized.

Copy link
Owner

danielcaldas commented Oct 17, 2018

Sweet!

@danielcaldas danielcaldas merged commit 390e5d5 into danielcaldas:master Oct 17, 2018
@dgautsch dgautsch deleted the dgautsch:fix/133 branch Oct 17, 2018
zvolchak added a commit to zvolchak/react-d3-graph that referenced this pull request Oct 29, 2018
* Checking for function in labelProperty and assigning output as new value, otherwise defaulting to original method

* Applying marvel config to demonstrate function usage.

* Updating sandbox bundle

* Adding try catch in case user function fails

* Applying string template suggested changes

* Removing try catch and renaming variable assignment to utilize short hand

* Reverting sandbox changes

* Update graph.config labelProperty jsdoc

* Improve labelProperty function in sandbox marvel.config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.