Skip to content

Commit

Permalink
Fix/0 number id edge case (#161)
Browse files Browse the repository at this point in the history
* Change custom-node sample to have 0 valued id

* Quick fix for 0 number id edge case
  • Loading branch information
danielcaldas authored Jan 11, 2019
1 parent 520d2bd commit 8247431
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
46 changes: 23 additions & 23 deletions sandbox/data/custom-node/custom-node.data.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
module.exports = {
links: [
{
source: 1,
target: 2
source: 0,
target: 2,
},
{
source: 1,
target: 3
source: 0,
target: 3,
},
{
source: 1,
target: 4
source: 0,
target: 4,
},
{
source: 3,
target: 4
}
target: 4,
},
],
nodes: [
{
id: 1,
name: 'Mary',
gender: 'female',
id: 0,
name: "Mary",
gender: "female",
hasCar: false,
hasBike: false
hasBike: false,
},
{
id: 2,
name: 'Roy',
gender: 'male',
name: "Roy",
gender: "male",
hasCar: false,
hasBike: true
hasBike: true,
},
{
id: 3,
name: 'Frank',
gender: 'male',
name: "Frank",
gender: "male",
hasCar: true,
hasBike: true
hasBike: true,
},
{
id: 4,
name: 'Melanie',
gender: 'female',
name: "Melanie",
gender: "female",
hasCar: true,
hasBike: false
}
]
hasBike: false,
},
],
};
8 changes: 4 additions & 4 deletions src/components/graph/graph.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function _createForceSimulation(width, height, gravity) {
*/
function _initializeLinks(graphLinks, config) {
return graphLinks.reduce((links, l) => {
const source = l.source.id || l.source;
const target = l.target.id || l.target;
const source = l.source.id !== undefined && l.source.id !== null ? l.source.id : l.source;
const target = l.target.id !== undefined && l.target.id !== null ? l.target.id : l.target;

if (!links[source]) {
links[source] = {};
Expand Down Expand Up @@ -245,8 +245,8 @@ function checkForGraphElementsChanges(nextProps, currentState) {
const stateD3Nodes = currentState.d3Nodes.map(n => utils.antiPick(n, NODE_PROPERTIES_DISCARD_TO_COMPARE));
const stateD3Links = currentState.d3Links.map(l => ({
// FIXME: solve this source data inconsistency later
source: l.source.id || l.source,
target: l.target.id || l.target,
source: l.source.id !== undefined && l.source.id !== null ? l.source.id : l.source,
target: l.target.id !== undefined && l.target.id !== null ? l.target.id : l.target,
}));
const graphElementsUpdated = !(
utils.isDeepEqual(nextNodes, stateD3Nodes) && utils.isDeepEqual(nextLinks, stateD3Links)
Expand Down
4 changes: 2 additions & 2 deletions src/components/graph/graph.renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function _renderLinks(nodes, links, linksMatrix, config, linkCallbacks, highligh
return outLinks.map(link => {
const { source, target } = link;
// FIXME: solve this source data inconsistency later
const sourceId = source.id || source;
const targetId = target.id || target;
const sourceId = source.id !== undefined && source.id !== null ? source.id : source;
const targetId = target.id !== undefined && target.id !== null ? target.id : target;
const key = `${sourceId}${CONST.COORDS_SEPARATOR}${targetId}`;
const props = buildLinkProps(
{ ...link, source: `${sourceId}`, target: `${targetId}` },
Expand Down

0 comments on commit 8247431

Please sign in to comment.