8000 Sankey feature branch by monfera · Pull Request #1591 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

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 26 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1656c5b
squashed Sankey feature branch for 1st look
monfera Feb 22, 2017
e7892fe
PR feedback and other updates to Sankey
monfera Apr 13, 2017
65b2d57
fix up bundle files
monfera Apr 28, 2017
aa41f28
removed colorbar leftover
monfera Apr 28, 2017
dec701a
unit shown in attribute doc
monfera Apr 28, 2017
1fb7cbd
removed vestigial attribs
monfera May 1, 2017
426b50d
flipping attrib representation to columnar
monfera May 1, 2017
dab87ae
circularity detection
monfera May 1, 2017
fdf9849
Revert "removed colorbar leftover"
monfera May 1, 2017
62257b4
restore dist to what was before
monfera May 1, 2017
4ea240f
mock update
monfera May 1, 2017
4e98b12
working around image gen sensitivity
monfera May 1, 2017
747eb23
Alex's suggestion for checking self-links too
monfera May 1, 2017
1cbc2f2
attribute work:
monfera May 1, 2017
e69e3a2
attribute work:
monfera May 1, 2017
90c003a
having published our d3-sankey fork under the @plotly scope
monfera May 2, 2017
3d10714
us 8000 ing traceOut in defaults for downstream default generation
monfera May 2, 2017
a2a416e
jasmine tests for Sankey
monfera May 2, 2017
3e2a455
jasmine tests for Sankey - warning / error test (and defaults.js improv)
monfera May 2, 2017
b91aa25
default empty arrays in attributes.js
monfera May 2, 2017
223421e
warning message update (PR feedback, thanks Alex!)
monfera May 2, 2017
4c3521a
removed unused colorbar
monfera May 2, 2017
af1c43b
PR feedback: noOpacity; no need to add toSVG; no empty line after fun…
monfera May 9, 2017
9214c92
PR feedback: moved circularity check into calc.js
monfera May 9, 2017
aa83612
PR feedback: testing lifecycle methods and visible; file rename
monfera May 9, 2017
7427284
PR feedback: hover tooltip tests; switching to addTraces
monfera May 9, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR feedback and other updates to Sankey
(cherry picked from commit b48bf7c)
  • Loading branch information
monfera committed Apr 28, 2017
commit e7892fefa895e6995c15900582fccd6a194e0763
28 changes: 0 additions & 28 deletions dist/plotly-sankey.min.js 10000

This file was deleted.

17 changes: 0 additions & 17 deletions lib/index-sankey.js

This file was deleted.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@
},
"dependencies": {
"3d-view": "^2.0.0",
"@monfera/d3-sankey": "^0.4.2",
"@monfera/d3-sankey": "^0.5.0",
"alpha-shape": "^1.0.0",
"arraytools": "^1.0.0",
"color-rgba": "^1.0.4",
"convex-hull": "^1.0.3",
"country-regex": "^1.1.0",
"d3": "^3.5.12",
"d3-array": "^1.1.0",
"d3-collection": "^1.0.2",
"d3-force": "^1.0.6",
"d3-interpolate": "^1.1.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.1",
Expand Down
33 changes: 26 additions & 7 deletions src/traces/sankey/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var plotAttrs = require('../../plots/attributes');

var extendFlat = require('../../lib/extend').extendFlat;


module.exports = {
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
flags: ['label', 'text', 'value', 'percent', 'name']
Expand Down Expand Up @@ -83,7 +82,7 @@ module.exports = {
].join(' ')
},

valueunit: {
valuesuffix: {
valType: 'string',
dflt: '',
role: 'style',
Expand All @@ -93,12 +92,18 @@ module.exports = {
].join(' ')
},

// followmouse for UX testing
followmouse: {
valType: 'boolean',
dflt: true,
arrangement: {
valType: 'enumerated',
values: ['snap', 'perpendicular', 'freeform', 'fixed'],
dflt: 'snap',
role: 'style',
description: 'Sets whether the hover tooltip follows the mouse.'
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,
Expand All @@ -111,6 +116,20 @@ module.exports = {
role: 'info',
description: 'The shown name of the node.'
},
parallel: {
valType: 'number',
role: 'style',
min: 0,
max: 1,
description: 'Node position parallel to the flow, e.g. left/right if `orientation` is `horizontal`.'
},
perpendicular: {
valType: 'number',
role: 'style',
min: 0,
max: 1,
description: 'Node position perpendicular to the flow, e.g. up/down if `orientation` is `horizontal`.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to say something here about the automatic layout system - how these get chosen if you don't specify them? Doesn't have to be detailed at all, just enough to let people know that you don't have to put a value in at all.

},
visible: shapeAttrs.visible,
color: extendFlat({}, shapeAttrs.fillcolor, {
dflt: 'rgb(0,255,0,0.5)'
Expand Down
1 change: 0 additions & 1 deletion src/traces/sankey/base_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)

if(hadPlot && !hasPlot) {
oldFullLayout._paperdiv.selectAll('.sankey').remove();
oldFullLayout._paperdiv.selectAll('.sankey').remove();
}
};

Expand Down
1 change: 0 additions & 1 deletion src/traces/sankey/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

'use strict';


module.exports = function calc() {
return [{}];
};
2 changes: 0 additions & 2 deletions src/traces/sankey/colorbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var isNumeric = require('fast-isnumeric');
Expand All @@ -16,7 +15,6 @@ var Plots = require('../../plots/plots');
var Colorscale = require('../../components/colorscale');
var drawColorbar = require('../../components/colorbar/draw');


module.exports = function colorbar(gd, cd) {
var trace = cd[0].trace,
line = trace.line,
Expand Down
4 changes: 0 additions & 4 deletions src/traces/sankey/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@

'use strict';


module.exports = {
nodeTextOffsetHorizontal: 4,
nodeTextOffsetVertical: 3,
nodePadAcross: 10,
sankeyIterations: 50,
movable: true,
sideways: true,
useForceSnap: true,
forceIterations: 5,
forceTicksPerFrame: 10,
duration: 500,
Expand Down
33 changes: 18 additions & 15 deletions src/traces/sankey/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

var Lib = require('../../lib');
var attributes = require('./attributes');
var d3 = require('d3');
var colors = require('../../components/color/attributes').defaults;
var Color = require('../../components/color');
var tinycolor = require('tinycolor2');


function linksDefaults(traceIn, traceOut) {
function linksDefaults(traceIn, traceOut, layout) {
var linksIn = traceIn.links || [],
linksOut = traceOut.links = [];

Expand All @@ -38,7 +39,11 @@ function linksDefaults(traceIn, traceOut) {
coerce('value');
coerce('source');
coerce('target');
coerce('color');
if(tinycolor(layout.paper_bgcolor).getLuminance() < 0.333) {
coerce('color', 'rgba(255, 255, 255, 0.6)');
} else {
coerce('color', 'rgba(0, 0, 0, 0.2)');
}
}

linkOut._index = i;
Expand All @@ -54,7 +59,7 @@ function nodesDefaults(traceIn, traceOut) {
usedNodeCount = 0,
indexMap = [];

var defaultPalette = d3.scale.category20();
var defaultPalette = function(i) {return colors[i % colors.length];};

function coerce(attr, dflt) {
return Lib.coerce(nodeIn, nodeOut, attributes.nodes, attr, dflt);
Expand All @@ -63,8 +68,6 @@ function nodesDefaults(traceIn, traceOut) {
for(i = 0; i < nodesIn.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty heavy operation. It would be nice to move it (or some of it) to the calc step.

nodeIn = nodesIn[i];



foundUse = false;
for(j = 0; j < traceOut.links.length && !foundUse; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I meant this one.

Defaults should still have to loop over all nodes and links to coerce their attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my education, since as you say, defaults must loop through it anyway (tho not nested) would putting it in calc result in more efficient code, or are you referring to the convention where computational things are usually in calc? I put it in defaults without much thought simply b/c filtering of unrendered elements is typically done in defaults and didn't think of it as 'calculation'.

link = traceOut.links[j];
Expand All @@ -73,8 +76,9 @@ function nodesDefaults(traceIn, traceOut) {

indexMap.push(foundUse ? usedNodeCount : null);

if(!foundUse)
if(!foundUse) {
continue;
}

if(!Lib.isPlainObject(nodeIn)) {
continue;
Expand All @@ -86,10 +90,12 @@ function nodesDefaults(traceIn, traceOut) {

if(visible) {
coerce('label');
coerce('parallel');
coerce('perpendicular');
if(nodeIn.color) {
coerce('color');
} else {
coerce('color', defaultPalette(i));
coerce('color', Color.addOpacity(defaultPalette(i), 0.8));
}
}

Expand All @@ -108,15 +114,12 @@ function nodesDefaults(traceIn, traceOut) {
return nodesOut;
}




module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

linksDefaults(traceIn, traceOut);
linksDefaults(traceIn, traceOut, layout);
nodesDefaults(traceIn, traceOut);

coerce('hoverinfo', layout._dataLength === 1 ? 'label+text+value+percent' : undefined);
Expand All @@ -127,8 +130,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('nodepad');
coerce('nodethickness');
coerce('valueformat');
coerce('valueunit');
coerce('followmouse');
coerce('valuesuffix');
coerce('arrangement');

// Prefer Sankey-specific font spec e.g. with smaller default size
var sankeyFontSpec = Lib.coerceFont(coerce, 'textfont');
Expand Down
4 changes: 2 additions & 2 deletions src/traces/sankey/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Plot.colorbar = require('./colorbar');
Plot.moduleType = 'trace';
Plot.name = 'sankey';
Plot.basePlotModule = require('./base_plot');
Plot.categories = ['gl'];
Plot.categories = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is trace-wide opacity a thing for sankey traces? If not, categories should include the noOpacity flag like we did for parcoords in #1506

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No trace- wide opacity so I'll add it, thanks!

Plot.meta = {
description: [
'Sankey plots for network flow data analysis.',
'The nodes are specified in `nodes` and the links between sources and targets in `links`.',
'The colors are set in `line.color`.'
'The colors are set in `nodes[i].color` and `links[i].color`; otherwise defaults are used.'
].join(' ')
};

Expand Down
Loading
< 305E /div>
0