-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
5,279 additions
and
1,331 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
;;; Directory Local Variables | ||
;;; For more information see (info "(emacs) Directory Variables") | ||
|
||
((js2-mode | ||
(flycheck-checker . javascript-standard))) | ||
|
This file contains 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 |
---|---|---|
@@ -1,57 +1,4 @@ | ||
/lib | ||
|
||
.tern-port | ||
/build | ||
/docs | ||
|
||
# Created by https://www.gitignore.io/api/node,linux | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
/d3-sankey-diagram.js | ||
/node_modules | ||
.tern-port |
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
var sankeyDiagram = require('./lib/diagram').default; | ||
export {default as sankey} from './src/sankey.js' | ||
export {default as sankeyPositionJustified} from './src/sankeyLayout/verticalJustified.js' | ||
export {default as sankeyPositionRelaxation} from './src/sankeyLayout/verticalRelaxation.js' | ||
|
||
module.exports = sankeyDiagram; | ||
export {default as sankeyLink} from './src/linkPath.js' | ||
export {default as sankeyNode} from './src/node.js' | ||
|
||
export {default as sankeyDiagram, linkTitleGenerator as sankeyLinkTitle} from './src/diagram.js' |
This file contains 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 |
---|---|---|
@@ -1,43 +1,54 @@ | ||
{ | ||
"name": "d3-sankey-diagram", | ||
"version": "0.4.4", | ||
"description": "Sankey diagram d3 component", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
"version": "0.5.0", | ||
"description": "Sankey diagram d3 plugin", | ||
"author": "Rick Lupton", | ||
"keywords": [ | ||
"d3", | ||
"d3-module", | ||
"sankey", | ||
"diagram" | ||
], | ||
"license": "MIT", | ||
"main": "build/d3-sankey-diagram.js", | ||
"jsnext:main": "index", | ||
"homepage": "https://github.com/ricklupton/d3-sankey-diagram", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ricklupton/d3-sankey-diagram.git" | ||
}, | ||
"scripts": { | ||
"pretest": "rm -rf build && mkdir build && rollup -c", | ||
"test": "tape -r ./test/buble-register -r reify 'test/**/*-test.js' && standard index.js src test", | ||
"test:watch": "tape-watch -r ../test/buble-register -r reify 'test/**/*-test.js'", | ||
"prepublishOnly": "npm run test && uglifyjs build/d3-sankey-diagram.js -c -m -o build/d3-sankey-diagram.min.js", | ||
"postpublish": "zip -j build/d3-sankey-diagram.zip -- LICENSE README.md build/d3-sankey-diagram.js build/d3-sankey-diagram.min.js" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^6.9.2", | ||
"d3": "~3.5.16", | ||
"defined": "^1.0.0", | ||
"graphlib": "~2.1.0", | ||
"sankey-layout": "~0.2.5" | ||
"d3-array": "^1.0.2", | ||
"d3-collection": "^1.0.2", | ||
"d3-dispatch": "^1.0.3", | ||
"d3-format": "^1.1.1", | ||
"d3-interpolate": "^1.1.3", | ||
"d3-selection": "^1.0.3", | ||
"d3-transition": "^1.0.4", | ||
"graphlib": "~2.1.0" | ||
}, | ||
"devDependencies": { | ||
"almost-equal": "~1.0.0", | ||
"babel-cli": "~6.5.1", | ||
"babel-core": "~6.5.2", | ||
"babel-plugin-transform-runtime": "^6.9.0", | ||
"babel-preset-es2015": "~6.5.0", | ||
"babel-tape-runner": "^2.0.1", | ||
"babelify": "~7.2.0", | ||
"browserify": "~13.0.0", | ||
"browserify-global-shim": "^1.0.3", | ||
"defined": "~1.0.0", | ||
"jsdoc": "~3.4.0", | ||
"jsdom": "^9.4.1", | ||
"tape": "^4.5.1", | ||
"tape-run": "^2.1.3" | ||
}, | ||
"scripts": { | ||
"prepublish": "npm run build && npm run bundle", | ||
"build": "babel src -d lib", | ||
"bundle": "browserify --standalone sankeyDiagram -t babelify -t [ browserify-global-shim --d3 d3 ] index.js > d3-sankey-diagram.js", | ||
"test": "browserify -t babelify test/test-*.js | tape-run", | ||
"test:node": "babel-tape-runner 'test/**/*.js'", | ||
"jsdoc": "jsdoc --package package.json -r lib/ -d docs" | ||
}, | ||
"author": "Rick Lupton", | ||
"repository": "https://github.com/ricklupton/d3-sankey-diagram", | ||
"license": "MIT" | ||
"almost-equal": "^1.1.0", | ||
"babel-eslint": "^7.1.1", | ||
"buble": "^0.15.2", | ||
"d3-scale": "^1.0.6", | ||
"faucet": "0.0.1", | ||
"jsdom": "^11.1.0", | ||
"reify": "^0.4.4", | ||
"rollup": "0.27", | ||
"rollup-plugin-buble": "^0.15.0", | ||
"rollup-plugin-commonjs": "^7.0.0", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"standard": "^8.6.0", | ||
"tape": "4", | ||
"tape-watch": "^2.2.4", | ||
"uglify-js": "2" | ||
} | ||
} |
This file contains 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,41 @@ | ||
// Rollup plugins | ||
import resolve from 'rollup-plugin-node-resolve' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import buble from 'rollup-plugin-buble' | ||
|
||
export default { | ||
entry: 'index.js', | ||
dest: 'build/d3-sankey-diagram.js', | ||
format: 'umd', | ||
moduleName: 'd3', | ||
globals: { | ||
'd3-collection': 'd3', | ||
'd3-array': 'd3', | ||
'd3-selection': 'd3', | ||
'd3-transition': 'd3', | ||
'd3-dispatch': 'd3', | ||
'd3-format': 'd3', | ||
'd3-interpolate': 'd3' | ||
}, | ||
external: [ | ||
'd3-collection', | ||
'd3-array', | ||
'd3-selection', | ||
'd3-transition', | ||
'd3-dispatch', | ||
'd3-format', | ||
'd3-interpolate' | ||
], | ||
plugins: [ | ||
resolve({ | ||
jsnext: true, | ||
main: true | ||
}), | ||
commonjs({ | ||
namedExports: { | ||
'node_modules/graphlib/index.js': ['Graph', 'alg'] | ||
} | ||
}), | ||
buble() | ||
] | ||
} |
This file contains 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,7 @@ | ||
;;; Directory Local Variables | ||
;;; For more information see (info "(emacs) Directory Variables") | ||
|
||
((js2-mode | ||
(flycheck-javascript-standard-executable . "/home/rick/ownCloud/devel/d3-sankey-diagram/node_modules/.bin/standard")) | ||
(flycheck-checker . javascript-standard))) | ||
|
This file contains 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,92 @@ | ||
import { Graph } from 'graphlib' | ||
import { map } from 'd3-collection' | ||
/** | ||
* Create a new graph where nodes in the same rank set are merged into one node. | ||
* | ||
* Depends on the "backwards" attribute of the nodes in G, and the "delta" | ||
* atribute of the edges. | ||
* | ||
*/ | ||
export default function groupedGraph (G, rankSets = []) { | ||
// Not multigraph because this is only used for calculating ranks | ||
const GG = new Graph({directed: true}) | ||
if (G.nodes().length === 0) return GG | ||
|
||
// Make sure there is a minimum-rank set | ||
rankSets = ensureSmin(G, rankSets) | ||
|
||
// Construct map of node ids to the set they are in, if any | ||
const nodeSets = map() | ||
var set | ||
var id | ||
var i | ||
var j | ||
for (i = 0; i < rankSets.length; ++i) { | ||
set = rankSets[i] | ||
if (!set.nodes || set.nodes.length === 0) continue | ||
id = '' + i | ||
for (j = 0; j < set.nodes.length; ++j) { | ||
nodeSets.set(set.nodes[j], id) | ||
} | ||
GG.setNode(id, { type: set.type, nodes: set.nodes }) | ||
} | ||
|
||
// use i to keep counting new ids | ||
var nodes = G.nodes() | ||
G.nodes().forEach(u => { | ||
const d = G.node(u) | ||
if (!nodeSets.has(u)) { | ||
id = '' + (i++) | ||
set = { type: 'same', nodes: [u] } | ||
nodeSets.set(u, id) | ||
GG.setNode(id, set) | ||
} | ||
}) | ||
|
||
// Add edges between nodes/groups | ||
G.edges().forEach(e => { | ||
const d = G.edge(e) | ||
const sourceSet = nodeSets.get(e.v) | ||
const targetSet = nodeSets.get(e.w) | ||
|
||
// Minimum edge length depends on direction of nodes: | ||
// -> to -> : 1 | ||
// -> to <- : 0 | ||
// <- to -> : 0 (in opposite direction??) | ||
// <- to <- : 1 in opposite direction | ||
const edge = GG.edge(sourceSet, targetSet) || { delta: 0 } | ||
if (sourceSet === targetSet) { | ||
edge.delta = 0 | ||
GG.setEdge(sourceSet, targetSet, edge) | ||
} else if (G.node(e.v).backwards) { | ||
edge.delta = Math.max(edge.delta, G.node(e.w).backwards ? 1 : 0) | ||
GG.setEdge(targetSet, sourceSet, edge) | ||
} else { | ||
edge.delta = Math.max(edge.delta, G.node(e.w).backwards ? 0 : 1) | ||
GG.setEdge(sourceSet, targetSet, edge) | ||
} | ||
}) | ||
|
||
return GG | ||
} | ||
|
||
// export function linkDelta (nodeBackwards, link) { | ||
// if (nodeBackwards(link.source)) { | ||
// return nodeBackwards(link.target) ? 1 : 0 | ||
// } else { | ||
// return nodeBackwards(link.target) ? 0 : 1 | ||
// } | ||
// } | ||
|
||
function ensureSmin (G, rankSets) { | ||
for (var i = 0; i < rankSets.length; ++i) { | ||
if (rankSets[i].type === 'min') { | ||
return rankSets // ok | ||
} | ||
} | ||
|
||
// find the first sourceSet node, or else use the first node | ||
var sources = G.sources() | ||
var n0 = sources.length ? sources[0] : G.nodes()[0] | ||
return [{ type: 'min', nodes: [ n0 ] }].concat(rankSets) | ||
} |
Oops, something went wrong.