From 44908118c9cc6cb0dc97b9d0a42ab67533f5d7a5 Mon Sep 17 00:00:00 2001 From: Ian Sillitoe Date: Thu, 20 Jul 2017 18:10:27 +0100 Subject: [PATCH 1/5] Allow custom node.value to be used (if specified) --- README.md | 2 +- src/sankey.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 17eb86d..0fee095 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Each *node* must be an object. The following properties are assigned by the [San * *node*.sourceLinks - the array of outgoing [links](#sankey_links) which have this node as their source * *node*.targetLinks - the array of incoming [links](#sankey_links) which have this node as their target -* *node*.value - the node’s value; the sum of *link*.value for the node’s incoming [links](#sankey_links) +* *node*.value - the node’s value; if not defined, this is the sum of *link*.value for the node’s incoming [links](#sankey_links) * *node*.index - the node’s zero-based index within the array of nodes * *node*.depth - the node’s zero-based graph depth, derived from the graph topology * *node*.height - the node’s zero-based graph height, derived from the graph topology diff --git a/src/sankey.js b/src/sankey.js index dd26a96..c5236e5 100644 --- a/src/sankey.js +++ b/src/sankey.js @@ -132,10 +132,12 @@ export default function() { // Compute the value (size) of each node by summing the associated links. function computeNodeValues(graph) { graph.nodes.forEach(function(node) { - node.value = Math.max( - sum(node.sourceLinks, value), - sum(node.targetLinks, value) - ); + if ( typeof node.value === 'undefined' ) { + node.value = Math.max( + sum(node.sourceLinks, value), + sum(node.targetLinks, value) + ); + } }); } From e8df1bfdeb7b3b0f09ee713e7a97c1f1c888897d Mon Sep 17 00:00:00 2001 From: Ian Sillitoe Date: Thu, 20 Jul 2017 19:04:33 +0100 Subject: [PATCH 2/5] include (optional) node.value in the max calc --- src/sankey.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/sankey.js b/src/sankey.js index c5236e5..9a47f51 100644 --- a/src/sankey.js +++ b/src/sankey.js @@ -132,12 +132,11 @@ export default function() { // Compute the value (size) of each node by summing the associated links. function computeNodeValues(graph) { graph.nodes.forEach(function(node) { - if ( typeof node.value === 'undefined' ) { - node.value = Math.max( - sum(node.sourceLinks, value), - sum(node.targetLinks, value) - ); - } + node.value = Math.max( + sum(node.sourceLinks, value), + sum(node.targetLinks, value), + typeof node.value !== 'undefined' ? node.value : 0 + ); }); } From c03678f6d9b9d9284d6a4e74c710255a84f1f4fd Mon Sep 17 00:00:00 2001 From: Ian Sillitoe Date: Mon, 4 Mar 2019 23:54:30 -0500 Subject: [PATCH 3/5] specify minimum value of node with node.minValue --- README.md | 2 +- src/sankey.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0fee095..8da2f19 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Each *node* must be an object. The following properties are assigned by the [San * *node*.sourceLinks - the array of outgoing [links](#sankey_links) which have this node as their source * *node*.targetLinks - the array of incoming [links](#sankey_links) which have this node as their target -* *node*.value - the node’s value; if not defined, this is the sum of *link*.value for the node’s incoming [links](#sankey_links) +* *node*.value - the node’s value; this is the sum of *link*.value for the node’s incoming [links](#sankey_links) (or *node*.minValue if defined and is greater) * *node*.index - the node’s zero-based index within the array of nodes * *node*.depth - the node’s zero-based graph depth, derived from the graph topology * *node*.height - the node’s zero-based graph height, derived from the graph topology diff --git a/src/sankey.js b/src/sankey.js index 9a47f51..f8895ca 100644 --- a/src/sankey.js +++ b/src/sankey.js @@ -135,7 +135,7 @@ export default function() { node.value = Math.max( sum(node.sourceLinks, value), sum(node.targetLinks, value), - typeof node.value !== 'undefined' ? node.value : 0 + typeof node.minValue !== 'undefined' ? node.minValue : 0 ); }); } From 0b4baa0e6ba3cdee2d49eaa07a8d1efc52ee82d6 Mon Sep 17 00:00:00 2001 From: Ian Sillitoe Date: Tue, 5 Mar 2019 00:27:30 -0500 Subject: [PATCH 4/5] use node.fixedValue (rather than node.minValue) --- README.md | 2 +- src/sankey.js | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8da2f19..8379e14 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Each *node* must be an object. The following properties are assigned by the [San * *node*.sourceLinks - the array of outgoing [links](#sankey_links) which have this node as their source * *node*.targetLinks - the array of incoming [links](#sankey_links) which have this node as their target -* *node*.value - the node’s value; this is the sum of *link*.value for the node’s incoming [links](#sankey_links) (or *node*.minValue if defined and is greater) +* *node*.value - the node’s value; this is the sum of *link*.value for the node’s incoming [links](#sankey_links) (or *node*.fixedValue if defined) * *node*.index - the node’s zero-based index within the array of nodes * *node*.depth - the node’s zero-based graph depth, derived from the graph topology * *node*.height - the node’s zero-based graph height, derived from the graph topology diff --git a/src/sankey.js b/src/sankey.js index f8895ca..939149b 100644 --- a/src/sankey.js +++ b/src/sankey.js @@ -132,11 +132,9 @@ export default function() { // Compute the value (size) of each node by summing the associated links. function computeNodeValues(graph) { graph.nodes.forEach(function(node) { - node.value = Math.max( - sum(node.sourceLinks, value), - sum(node.targetLinks, value), - typeof node.minValue !== 'undefined' ? node.minValue : 0 - ); + node.value = node.fixedValue === undefined + ? Math.max(sum(node.sourceLinks, value), sum(node.targetLinks, value)) + : node.minValue }); } From 2197f17c826003ad8e150df1fc7843315d7a4386 Mon Sep 17 00:00:00 2001 From: Ian Sillitoe Date: Thu, 14 Mar 2019 07:46:44 -0500 Subject: [PATCH 5/5] fix typo --- src/sankey.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sankey.js b/src/sankey.js index c54b402..7c826e4 100644 --- a/src/sankey.js +++ b/src/sankey.js @@ -146,7 +146,7 @@ export default function Sankey() { node.value = node.fixedValue === undefined ? Math.max(sum(node.sourceLinks, value), sum(node.targetLinks, value)) : node.fixedValue - }); + } } function computeNodeDepths({nodes}) {