-
-
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
Sankey feature branch #1591
Changes from 1 commit
1656c5b
e7892fe
65b2d57
aa41f28
dec701a
1fb7cbd
426b50d
dab87ae
fdf9849
62257b4
4ea240f
4e98b12
747eb23
1cbc2f2
e69e3a2
90c003a
3d10714
a2a416e
3e2a455
b91aa25
223421e
4c3521a
af1c43b
9214c92
aa83612
7427284
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
(cherry picked from commit b48bf7c)
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
|
||
'use strict'; | ||
|
||
|
||
module.exports = function calc() { | ||
return [{}]; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = []; | ||
|
||
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -63,8 +68,6 @@ function nodesDefaults(traceIn, traceOut) { | |
for(i = 0; i < nodesIn.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
link = traceOut.links[j]; | ||
|
@@ -73,8 +76,9 @@ function nodesDefaults(traceIn, traceOut) { | |
|
||
indexMap.push(foundUse ? usedNodeCount : null); | ||
|
||
if(!foundUse) | ||
if(!foundUse) { | ||
continue; | ||
} | ||
|
||
if(!Lib.isPlainObject(nodeIn)) { | ||
continue; | ||
|
@@ -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)); | ||
} | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -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'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,12 @@ Plot.colorbar = require('./colorbar'); | |
Plot.moduleType = 'trace'; | ||
Plot.name = 'sankey'; | ||
Plot.basePlotModule = require('./base_plot'); | ||
Plot.categories = ['gl']; | ||
Plot.categories = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is trace-wide There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(' ') | ||
}; | ||
|
||
|
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.
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.