-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start version of component Sankey D3 (SKD3)
- Loading branch information
1 parent
dd183fa
commit e409efa
Showing
15 changed files
with
2,557 additions
and
2 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,12 @@ | ||
parserOptions: | ||
sourceType: "module" | ||
|
||
env: | ||
es6: true | ||
|
||
extends: | ||
"eslint:recommended" | ||
|
||
rules: | ||
no-cond-assign: 0 | ||
no-constant-condition: 0 |
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,15 @@ | ||
.DS_Store* | ||
build/ | ||
node_modules | ||
.idea | ||
*.swp | ||
*~ | ||
*.log | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
bower_components | ||
coverage | ||
test-results.xml | ||
*.orig | ||
/tmp/ |
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,3 @@ | ||
*.sublime-* | ||
build/*.zip | ||
test/ |
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,134 @@ | ||
module.exports = function(grunt) { | ||
var _pkg = grunt.file.readJSON('package.json'); | ||
|
||
// allows autoprefixer to work on older node_js versions | ||
require('es6-promise').polyfill(); | ||
|
||
//Project configuration. | ||
grunt.initConfig({ | ||
pkg: _pkg, | ||
concat: { | ||
css: { | ||
options: { | ||
separator: '\n', | ||
banner: '/* skd3 version ' + _pkg.version + ' (' + _pkg.url + ') ' + | ||
'<%= grunt.template.today("yyyy-mm-dd") %> */\n' | ||
}, | ||
src: [ | ||
'src/css/*.css' | ||
], | ||
dest: 'build/sk.d3.css' | ||
}, | ||
js: { | ||
options: { | ||
separator: '', | ||
banner: '/* skd3 version ' + _pkg.version + ' (' + _pkg.url + ') ' + | ||
'<%= grunt.template.today("yyyy-mm-dd") %> */\n' + '(function(){\n', | ||
footer: '\nsk.version = "' + _pkg.version + '";\n})();', | ||
sourceMap: true, | ||
sourceMapName: 'build/sk.d3.js.map', | ||
sourceMapStyle: 'embed' | ||
}, | ||
src: [ | ||
'src/init.js', | ||
//Include d3-sankey core | ||
'node_modules/d3-sankey/build/d3-sankey.min.js', | ||
//Include d3-tip | ||
'node_modules/d3-tip/index.js', | ||
'src/core.js', | ||
'src/utils.js', | ||
// example to exclude files: '!src/models/excludeMe*' | ||
], | ||
dest: 'build/sk.d3.js' | ||
} | ||
}, | ||
uglify: { | ||
options: { | ||
sourceMap: true, | ||
sourceMapIncludeSources : true, | ||
sourceMapIn : 'build/sk.d3.js.map', | ||
banner: '/* skd3 version ' + _pkg.version + ' (' + _pkg.url + ') ' + | ||
'<%= grunt.template.today("yyyy-mm-dd") %> */\n' | ||
}, | ||
js: { | ||
files: { | ||
'build/sk.d3.min.js': ['build/sk.d3.js'] | ||
} | ||
} | ||
}, | ||
replace: { | ||
version: { | ||
src: [ | ||
'package.js' | ||
], | ||
overwrite: true, | ||
replacements: [{ | ||
from: /(version?\s?=?\:?\s\')([\d\.]*)\'/gi, | ||
to: '$1' + _pkg.version + "'" | ||
}] | ||
} | ||
}, | ||
jshint: { | ||
foo: { | ||
src: "src/**/*.js" | ||
}, | ||
options: { | ||
jshintrc: '.jshintrc' | ||
} | ||
}, | ||
watch: { | ||
js: { | ||
files: ["src/**/*.js"], | ||
tasks: ['concat'] | ||
} | ||
}, | ||
copy: { | ||
css: { | ||
files: [ | ||
{ src: 'src/sk.d3.css', dest: 'build/sk.d3.css' } | ||
] | ||
} | ||
}, | ||
postcss: { | ||
options: { | ||
processors: [ | ||
require('autoprefixer')({ | ||
browsers: [ | ||
'last 2 versions', | ||
'last 3 iOS versions', | ||
'last 2 safari versions', | ||
'ie >= 9'] | ||
}) | ||
] | ||
}, | ||
dist: { | ||
src: 'build/sk.d3.css' | ||
} | ||
}, | ||
cssmin: { | ||
options: { | ||
sourceMap: true | ||
}, | ||
dist: { | ||
files: { | ||
'build/sk.d3.min.css' : ['build/sk.d3.css'] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-contrib-concat'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
grunt.loadNpmTasks('grunt-postcss'); | ||
grunt.loadNpmTasks('grunt-contrib-cssmin'); | ||
grunt.loadNpmTasks('grunt-text-replace'); | ||
|
||
//grunt.registerTask('default', ['concat', 'copy', 'postcss']); | ||
grunt.registerTask('production', ['concat', 'uglify', 'copy', 'postcss', 'cssmin', 'replace']); | ||
grunt.registerTask('default', ['production']); | ||
grunt.registerTask('release', ['production']); | ||
grunt.registerTask('lint', ['jshint']); | ||
}; |
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,2 +1,113 @@ | ||
# skd3 | ||
Sankey Diagram made easy. A javascript library that extends the popular D3.js/d3-sankey to enable fast and beautiful. | ||
|
||
[![Build Status](https://travis-ci.org/fabriciorhs/skd3.svg?branch=master)](https://travis-ci.org/fabriciorhs/skd3) | ||
[![Dependencies Status](https://david-dm.org/fabriciorhs/skd3.svg)](https://david-dm.org/fabriciorhs/skd3) | ||
|
||
<sup>Inspired by the work of Mike Bostock's [`d3-sankey`](http://github.com/d3/d3-sankey)</sup> | ||
|
||
>As a proposal to simplify the generation of the sankey chart | ||
Sankey diagrams visualize the directed flow between nodes in an acyclic network. For example, this diagram shows a possible scenario of UK energy production and consumption in 2050: | ||
|
||
<img alt="Sankey diagram" src="https://raw.githubusercontent.com/fabriciorhs/skd3/master/img/energy.png" width="960"> | ||
|
||
Source: Department of Energy & Climate Change, from: [`Mike Bostock - json sample`](https://bl.ocks.org/mbostock/ca9a0bb7ba204d12974bca90acc507c0). | ||
|
||
## Dependencies | ||
|
||
SKD3 requires [d3.js](http://d3js.org/) version **[4.9.0](https://github.com/d3/d3/releases/tag/v4.9.0)** and later. | ||
|
||
## Installing | ||
|
||
If you use NPM, `npm install skd3`. Otherwise, download the [latest release](https://github.com/fabriciorhs/skd3/releases/latest). You can also load directly from [unpkg.com](https://cdn.rawgit.com/): | ||
|
||
```html | ||
<script src="https://cdn.rawgit.com/fabriciorhs/skd3/master/build/sk.d3.min.js"></script> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/fabriciorhs/skd3/master/build/sk.d3.min.css" /> | ||
<style> | ||
#sankeyChart { | ||
height: 500px; | ||
width: 960px; | ||
} | ||
</style> | ||
|
||
<div id="sankeyChart"/> | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
var objSankey = sk.createSankey('#sankeyChart', configSankey, datajson); | ||
``` | ||
|
||
Example of config: | ||
|
||
```js | ||
var configSankey = { | ||
margin: { top: 10, left: 10, right: 10, bottom: 10 }, | ||
nodes: { | ||
dynamicSizeFontNode: { | ||
enabled: true, | ||
minSize: 14, | ||
maxSize: 30 | ||
}, | ||
canDragNodes: true, | ||
colors: d3.scaleOrdinal(d3.schemeCategory10) | ||
}, | ||
links: { | ||
formatValue: function(val) { | ||
return d3.format(",.0f")(val) + ' TWh'; | ||
} | ||
}, | ||
tooltip: { | ||
infoDiv: true, | ||
labelSource: 'Input:', | ||
labelTarget: 'Output:' | ||
} | ||
} | ||
``` | ||
|
||
Example data json: | ||
|
||
```js | ||
var datajson = {nodes: [ | ||
{"id": "Alice"}, | ||
{"id": "Bob"}, | ||
{"id": "Carol"} | ||
], | ||
links: [ | ||
{"source": "Alice", "target": "Bob"}, | ||
{"source": "Bob", "target": "Carol"} | ||
]}; | ||
``` | ||
|
||
|
||
## Update links values using d3`s transitions: | ||
|
||
```js | ||
objSankey.updateData(new_dataJson); | ||
``` | ||
|
||
Result: | ||
|
||
<img alt="Sankey transitions" src="https://raw.githubusercontent.com/fabriciorhs/skd3/master/img/sankey_transitions.gif" width="400"> | ||
|
||
|
||
## Contributing | ||
|
||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/fabriciorhs/skd3/issues/new) | ||
|
||
## Author | ||
|
||
**Fabricio Rodrigues** | ||
|
||
+ [github/fabriciorhs](https://github.com/fabriciorhs) | ||
+ [twitter/fabriciorhs](http://twitter.com/fabriciorhs) | ||
|
||
## License | ||
|
||
Copyright © 2017 [Fabricio Rodrigues](https://github.com/fabriciorhs) | ||
Released under the MIT license. | ||
|
||
*** |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<meta charset="utf-8"> | ||
<title>Sankey Diagram</title> | ||
<body> | ||
<div id="chart"/> | ||
<script src="https://unpkg.com/d3@4.10.2"></script> | ||
<script src="../build/sk.d3.min.js"></script> | ||
<link rel="stylesheet" type="text/css" href="../build/sk.d3.min.css" /> | ||
<script src="data_energyjson.js"></script> | ||
<style> | ||
#chart { | ||
height: 500px; | ||
width: 960px; | ||
} | ||
</style> | ||
<script> | ||
var configSankey = { | ||
margin: { top: 10, left: 10, right: 10, bottom: 10 }, | ||
nodes: { | ||
dynamicSizeFontNode: { | ||
enabled: true, | ||
minSize: 14, | ||
maxSize: 30 | ||
}, | ||
canDragNodes: true, | ||
colors: d3.scaleOrdinal(d3.schemeCategory10) | ||
}, | ||
links: { | ||
formatValue: function(val) { | ||
return d3.format(",.0f")(val) + ' TWh'; | ||
} | ||
}, | ||
tooltip: { | ||
infoDiv: true, | ||
labelSource: 'Input:', | ||
labelTarget: 'Output:' | ||
} | ||
} | ||
|
||
var objSankey = sk.createSankey('#chart', configSankey, energyjson); | ||
</script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.