-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Sankey feature branch #1591
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
Merged
Merged
Sankey feature branch #1591
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
1656c5b
squashed Sankey feature branch for 1st look
monfera e7892fe
PR feedback and other updates to Sankey
monfera 65b2d57
fix up bundle files
monfera aa41f28
removed colorbar leftover
monfera dec701a
unit shown in attribute doc
monfera 1fb7cbd
removed vestigial attribs
monfera 426b50d
flipping attrib representation to columnar
monfera dab87ae
circularity detection
monfera fdf9849
Revert "removed colorbar leftover"
monfera 62257b4
restore dist to what was before
monfera 4ea240f
mock update
monfera 4e98b12
working around image gen sensitivity
monfera 747eb23
Alex's suggestion for checking self-links too
monfera 1cbc2f2
attribute work:
monfera e69e3a2
attribute work:
monfera 90c003a
having published our d3-sankey fork under the @plotly scope
monfera 3d10714
using traceOut in defaults for downstream default generation
monfera a2a416e
jasmine tests for Sankey
monfera 3e2a455
jasmine tests for Sankey - warning / error test (and defaults.js improv)
monfera b91aa25
default empty arrays in attributes.js
monfera 223421e
warning message update (PR feedback, thanks Alex!)
monfera 4c3521a
removed unused colorbar
monfera af1c43b
PR feedback: noOpacity; no need to add toSVG; no empty line after fun…
monfera 9214c92
PR feedback: moved circularity check into calc.js
monfera aa83612
PR feedback: testing lifecycle methods and visible; file rename
monfera 7427284
PR feedback: hover tooltip tests; switching to addTraces
monfera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = require('../src/traces/sankey'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var shapeAttrs = require('../../components/shapes/attributes'); | ||
var fontAttrs = require('../../plots/font_attributes'); | ||
var plotAttrs = require('../../plots/attributes'); | ||
var colorAttrs = require('../../components/color/attributes'); | ||
|
||
var extendFlat = require('../../lib/extend').extendFlat; | ||
|
||
module.exports = { | ||
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, { | ||
flags: ['label', 'text', 'value', 'percent', 'name'] | ||
}), | ||
domain: { | ||
x: { | ||
valType: 'info_array', | ||
role: 'info', | ||
items: [ | ||
{valType: 'number', min: 0, max: 1}, | ||
{valType: 'number', min: 0, max: 1} | ||
], | ||
dflt: [0, 1], | ||
description: [ | ||
'Sets the horizontal domain of this `sankey` trace', | ||
'(in plot fraction).' | ||
].join(' ') | ||
}, | ||
y: { | ||
valType: 'info_array', | ||
role: 'info', | ||
items: [ | ||
{valType: 'number', min: 0, max: 1}, | ||
{valType: 'number', min: 0, max: 1} | ||
], | ||
dflt: [0, 1], | ||
description: [ | ||
'Sets the vertical domain of this `sankey` trace', | ||
'(in plot fraction).' | ||
].join(' ') | ||
} | ||
}, | ||
|
||
orientation: { | ||
valType: 'enumerated', | ||
values: ['v', 'h'], | ||
dflt: 'h', | ||
role: 'style', | ||
description: 'Sets the orientation of the Sankey diagram.' | ||
}, | ||
|
||
valueformat: { | ||
valType: 'string', | ||
dflt: '.3s', | ||
role: 'style', | ||
description: [ | ||
'Sets the value formatting rule using d3 formatting mini-language', | ||
'which is similar to those of Python. See', | ||
'https://github.com/d3/d3-format/blob/master/README.md#locale_format' | ||
].join(' ') | ||
}, | ||
|
||
valuesuffix: { | ||
valType: 'string', | ||
dflt: '', | ||
role: 'style', | ||
description: [ | ||
'Adds a unit to follow the value in the hover tooltip. Add a space if a separation', | ||
'is necessary from the value.' | ||
].join(' ') | ||
}, | ||
|
||
arrangement: { | ||
valType: 'enumerated', | ||
values: ['snap', 'perpendicular', 'freeform', 'fixed'], | ||
dflt: 'snap', | ||
role: 'style', | ||
description: [ | ||
'If value is `snap` (the default), the node arrangement is assisted by automatic snapping of elements to', | ||
'preserve space between nodes specified via `nodepad`.', | ||
'If value is `perpendicular`, the nodes can only move along a line perpendicular to the flow.', | ||
'If value is `freeform`, the nodes can freely move on the plane.', | ||
'If value is `fixed`, the nodes are stationary.' | ||
].join(' ') | ||
}, | ||
|
||
textfont: fontAttrs, | ||
|
||
node: { | ||
label: { | ||
valType: 'data_array', | ||
dflt: [], | ||
role: 'info', | ||
description: 'The shown name of the node.' | ||
}, | ||
color: extendFlat({}, shapeAttrs.fillcolor, { | ||
arrayOk: true, | ||
description: [ | ||
'Sets the `node` color. It can be a single value, or an array for specifying color for each `node`.', | ||
'If `node.color` is omitted, then the default `Plotly` color palette will be cycled through', | ||
'to have a variety of colors. These defaults are not fully opaque, to allow some visibility of', | ||
'what is beneath the node.' | ||
].join(' ') | ||
}), | ||
line: { | ||
color: { | ||
valType: 'color', | ||
role: 'style', | ||
dflt: colorAttrs.defaultLine, | ||
arrayOk: true, | ||
description: [ | ||
'Sets the color of the `line` around each `node`.' | ||
].join(' ') | ||
}, | ||
width: { | ||
valType: 'number', | ||
role: 'style', | ||
min: 0, | ||
dflt: 0.5, | ||
arrayOk: true, | ||
description: [ | ||
'Sets the width (in px) of the `line` around each `node`.' | ||
].join(' ') | ||
} | ||
}, | ||
pad: { | ||
valType: 'number', | ||
arrayOk: false, | ||
min: 0, | ||
dflt: 20, | ||
role: 'style', | ||
description: 'Sets the padding (in px) between the `nodes`.' | ||
}, | ||
thickness: { | ||
valType: 'number', | ||
arrayOk: false, | ||
min: 1, | ||
dflt: 20, | ||
role: 'style', | ||
description: 'Sets the thickness (in px) of the `nodes`.' | ||
}, | ||
description: 'The nodes of the Sankey plot.' | ||
}, | ||
|
||
link: { | ||
label: { | ||
valType: 'data_array', | ||
dflt: [], | ||
role: 'info', | ||
description: 'The shown name of the link.' | ||
}, | ||
color: extendFlat({}, shapeAttrs.fillcolor, { | ||
arrayOk: true, | ||
description: [ | ||
'Sets the `link` color. It can be a single value, or an array for specifying color for each `link`.', | ||
'If `link.color` is omitted, then by default, a translucent grey link will be used.' | ||
].join(' ') | ||
}), | ||
line: { | ||
color: { | ||
valType: 'color', | ||
role: 'style', | ||
dflt: colorAttrs.defaultLine, | ||
arrayOk: true, | ||
description: [ | ||
'Sets the color of the `line` around each `link`.' | ||
].join(' ') | ||
}, | ||
width: { | ||
valType: 'number', | ||
role: 'style', | ||
min: 0, | ||
dflt: 0, | ||
arrayOk: true, | ||
description: [ | ||
'Sets the width (in px) of the `line` around each `link`.' | ||
].join(' ') | ||
} | ||
}, | ||
source: { | ||
valType: 'data_array', | ||
role: 'info', | ||
dflt: [], | ||
description: 'An integer number `[0..nodes.length - 1]` that represents the source node.' | ||
}, | ||
target: { | ||
valType: 'data_array', | ||
role: 'info', | ||
dflt: [], | ||
description: 'An integer number `[0..nodes.length - 1]` that represents the target node.' | ||
}, | ||
value: { | ||
valType: 'data_array', | ||
dflt: [], | ||
role: 'info', | ||
description: 'A numeric value representing the flow volume value.' | ||
}, | ||
description: 'The links of the Sankey plot.' | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Plots = require('../../plots/plots'); | ||
var plot = require('./plot'); | ||
|
||
exports.name = 'sankey'; | ||
|
||
exports.attr = 'type'; | ||
|
||
exports.plot = function(gd) { | ||
var calcData = Plots.getSubplotCalcData(gd.calcdata, 'sankey', 'sankey'); | ||
if(calcData.length) plot(gd, calcData); | ||
}; | ||
|
||
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) { | ||
var hadPlot = (oldFullLayout._has && oldFullLayout._has('sankey')); | ||
var hasPlot = (newFullLayout._has && newFullLayout._has('sankey')); | ||
|
||
if(hadPlot && !hasPlot) { | ||
oldFullLayout._paperdiv.selectAll('.sankey').remove(); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var tarjan = require('strongly-connected-components'); | ||
var Lib = require('../../lib'); | ||
|
||
function circularityPresent(nodeList, sources, targets) { | ||
|
||
var nodes = nodeList.map(function() {return [];}); | ||
|
||
for(var i = 0; i < Math.min(sources.length, targets.length); i++) { | ||
if(sources[i] === targets[i]) { | ||
return true; // self-link which is also a scc of one | ||
} | ||
nodes[sources[i]].push(targets[i]); | ||
} | ||
|
||
var scc = tarjan(nodes); | ||
|
||
// Tarján's strongly connected components algorithm coded by Mikola Lysenko | ||
// returns at least one non-singular component if there's circularity in the graph | ||
return scc.components.some(function(c) { | ||
return c.length > 1; | ||
}); | ||
} | ||
|
||
module.exports = function calc(gd, trace) { | ||
|
||
if(circularityPresent(trace.node.label, trace.link.source, trace.link.target)) { | ||
Lib.error('Circularity is present in the Sankey data. Removing all nodes and links.'); | ||
trace.link.label = []; | ||
trace.link.source = []; | ||
trace.link.target = []; | ||
trace.link.value = []; | ||
trace.link.color = []; | ||
trace.node.label = []; | ||
trace.node.color = []; | ||
} | ||
|
||
return [{ | ||
link: trace.link, | ||
node: trace.node | ||
}]; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
nodeTextOffsetHorizontal: 4, | ||
nodeTextOffsetVertical: 3, | ||
nodePadAcross: 10, | ||
sankeyIterations: 50, | ||
forceIterations: 5, | ||
forceTicksPerFrame: 10, | ||
duration: 500, | ||
ease: 'linear' | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very nice first step. Thanks @monfera !