Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Commit

Permalink
Add UMD support (based on misoproject/d3.chart#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Dec 21, 2015
1 parent 17cfea0 commit a7682db
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 130 deletions.
6 changes: 6 additions & 0 deletions .jscsrc
@@ -0,0 +1,6 @@
{
"disallowMixedSpacesAndTabs": true,
"maximumLineLength": 80,
"validateIndentation": "\t",
"validateQuoteMarks": "\""
}
6 changes: 6 additions & 0 deletions .jshintrc
@@ -0,0 +1,6 @@
{
"curly": true,
"unused": true,
"undef": true,
"trailing": false
}
98 changes: 14 additions & 84 deletions Gruntfile.js
@@ -1,91 +1,21 @@
module.exports = function(grunt) {
"use strict";

grunt.initConfig({
"use strict";

meta: {
pkg: grunt.file.readJSON("package.json"),
grunt.loadTasks("build/tasks");

source: ["src/**/*.js", '!src/wrapper/*'],
grunt.registerTask("build", ["webpack:dist", "webpack:dist-min"]);

banner: "/*!\n" +
" * <%= meta.pkg.name %> - v<%= meta.pkg.version %>\n" +
" * <%= meta.pkg.homepage %>\n" +
" * \n" +
" * Copyright (c) 2015 <%= meta.pkg.author %>\n" +
" * Library released under <%= meta.pkg.license %> license.\n" +
" */\n"
},
grunt.registerTask("test-unit", ["mocha:unit"]);
grunt.registerTask(
"test-build",
[
"webpack:test", "browserify", "mocha:exportsAmd",
"mocha:exportsCommonjs", "mocha:exportsGlobal"
]
);
grunt.registerTask("test", ["jshint", "jscs", "test-unit", "test-build"]);

watch: {
scripts: {
files: "<%= meta.source %>",
tasks: ["concat"]
}
},

jshint: {
options: {
curly: true,
undef: true
},
chart: {
options: {
browser: true,
globals: {
d3: true
}
},
files: {
src: "<%= meta.source %>"
}
},
grunt: {
options: {
node: true
},
files: {
src: ["Gruntfile.js"]
}
}
},

concat: {
options: {
banner: "<%= meta.banner %>"
},
build: {
files: {
"d3.chart.sankey.js":
[
"src/wrapper/start.frag",
"src/base.js",
"src/sankey.js",
"src/selection.js",
"src/path.js",
"src/wrapper/end.frag"
]
}
}
},

uglify: {
options: {
preserveComments: "false"
},
release: {
files: {
"d3.chart.sankey.min.js": "d3.chart.sankey.js"
}
}
}
});

grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch");

grunt.registerTask("default", ["concat"]);
grunt.registerTask("release", ["jshint", "concat", "uglify"]);
grunt.registerTask("default", ["test"]);
grunt.registerTask("release", ["default", "build"]);
};
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -54,6 +54,19 @@ chart.on('node:click', function(node) {
});
```

### AMD, CommonJS, ...

This chart can also be loaded as a module:

```js
var d3 = require('d3');
var Sankey = require('d3.chart.sankey');

var g = d3.select('svg').append('g');
var chart = new Sankey(g);
```


### Chart types

There are three chart types: `Sankey`, `Sankey.Selection` and `Sankey.Path`.
Expand All @@ -62,6 +75,9 @@ when hovering a node or path, or when the `selection` method is called on the
chart (which accepts an array of nodes and links). `Sankey.Path` expands the
selection to connected nodes and links.

When loading as a module, you can also access these charts as properties, so
instead of `new Sankey(g)` you'd use `new Sankey.Selection(g)`;


## Building

Expand Down
6 changes: 3 additions & 3 deletions bower.json
@@ -1,9 +1,9 @@
{
"name": "d3.chart.sankey",
"description": "Reusable D3 Sankey diagram using d3.Chart",
"version": "0.1.0",
"version": "0.1.1",

"main": "./d3.chart.sankey.js",
"main": "d3.chart.sankey.js",
"license": "MIT",

"ignore": [
Expand Down Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"d3": "~3.5.6",
"d3-plugins-sankey": "1.0.0",
"d3.chart": "0.2.1"
"d3.chart": "jugglinmike/d3.chart#amd-3"
},
"resolutions": {
"d3": "~3.5.6"
Expand Down
5 changes: 5 additions & 0 deletions build/.jshintrc
@@ -0,0 +1,5 @@
{
"extends": "../.jshintrc",
"node": true,
"scripturl": true
}
8 changes: 8 additions & 0 deletions build/tasks/browserify.js
@@ -0,0 +1,8 @@
module.exports = function(grunt) {
"use strict";

grunt.config.set("browserify", {
});

grunt.loadNpmTasks("grunt-browserify");
};
17 changes: 17 additions & 0 deletions build/tasks/jscs.js
@@ -0,0 +1,17 @@
module.exports = function(grunt) {
"use strict";

grunt.config.set("jscs", {
src: {
options: {
config: ".jscsrc"
},
src: [
"<%= jshint.src.src %>",
"<%= jshint.build.src %>"
]
}
});

grunt.loadNpmTasks("grunt-jscs");
};
20 changes: 20 additions & 0 deletions build/tasks/jshint.js
@@ -0,0 +1,20 @@
module.exports = function(grunt) {
"use strict";

grunt.config.set("jshint", {
src: {
options: {
jshintrc: "src/.jshintrc"
},
src: ["src/*.js"]
},
build: {
options: {
jshintrc: "build/.jshintrc"
},
src: ["Gruntfile.js", "build/**/*.js"]
}
});

grunt.loadNpmTasks("grunt-contrib-jshint");
};
12 changes: 12 additions & 0 deletions build/tasks/watch.js
@@ -0,0 +1,12 @@
module.exports = function(grunt) {
"use strict";

grunt.config.set("watch", {
scripts: {
files: ["src/**/*.js"],
tasks: ["jshint", "build"]
}
});

grunt.loadNpmTasks("grunt-contrib-watch");
};
26 changes: 26 additions & 0 deletions build/tasks/webpack.js
@@ -0,0 +1,26 @@
var webpack = require("webpack");

module.exports = function(grunt) {
"use strict";

grunt.config.set("webpack", {
options: require("../webpack.config.js"),
dist: {
output: {
filename: "d3.chart.sankey.js"
}
},
"dist-min": {
output: {
filename: "d3.chart.sankey.min.js",
sourceMapFilename: "d3.chart.sankey.min.map",
},
devtool: "source-map",
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
}
});

grunt.loadNpmTasks("grunt-webpack");
};
37 changes: 37 additions & 0 deletions build/webpack.config.js
@@ -0,0 +1,37 @@
"use strict";
var webpack = require("webpack");

var pkg = require("../package.json");
var now = new Date();

function pad(num) {
return (num < 10 ? "0" : "") + num;
}

var banner = [
pkg.name + " - v" + pkg.version,
"License: " + pkg.license,
"Date: " + now.getFullYear() + "-" + pad(now.getMonth()) + "-" +
pad(now.getDate())
].join("\n");

module.exports = {
context: "src",
entry: "./index",
output: {
libraryTarget: "umd"
},
plugins: [
new webpack.BannerPlugin(banner)
],
externals: {
'd3': true,
'd3-plugins-sankey': true,
'd3.chart': {
'root': ['d3', 'chart'],
'commonjs': 'd3.chart',
'commonjs2': 'd3.chart',
'amd': 'd3.chart'
}
}
};
34 changes: 12 additions & 22 deletions package.json
@@ -1,58 +1,48 @@
{
"name": "d3.chart.sankey",
"description": "Reusable D3 Sankey diagram using d3.Chart",
"version": "0.1.0",

"main": "./d3.chart.sankey.js",
"version": "0.1.1",
"main": "d3.chart.sankey",
"license": "MIT",

"keywords": [
"d3.js",
"d3.chart",
"visualization",
"sankey"
],

"homepage": "https://github.com/q-m/d3.chart.sankey/",
"author": "wvengen <dev-js@willem.engen.nl>",

"repository": {
"type": "git",
"url": "git://github.com/q-m/d3.chart.sankey.git"
},

"bugs": {
"url": "https://github.com/q-m/d3.chart.sankey/issues"
},

"directories": {
"example": "./example"
},

"dependencies": {
"d3": "3",
"d3.chart": "0.2",
"d3.chart": "jugglinmike/d3.chart#amd-3",
"d3-plugins-sankey": "1.2.1"
},

"devDependencies": {
"exports-loader": "^0.6.2",
"grunt": "^0.4.5",
"grunt-browserify": "^4.0.1",
"grunt-cli": "^0.1.11",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-jshint": "^0.11.1",
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"vows": "^0.8.1"
"grunt-jscs": "^1.8.0",
"grunt-webpack": "^1.0.11",
"imports-loader": "^0.6.5",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.0"
},

"peerDependencies": {
"grunt": "~0.4.0"
},

"scripts": {
"test": "vows --spec"
},

"d3.chart": {
"version" : "0.2.1"
"version": "0.2.1"
}
}
9 changes: 9 additions & 0 deletions src/.jshintrc
@@ -0,0 +1,9 @@
{
"extends": "../.jshintrc",
"browser": true,
"globalstrict": true,
"globals": {
"require": false,
"define": false
}
}

0 comments on commit a7682db

Please sign in to comment.