Commit 9b6264dd authored by murtech's avatar murtech

initial commit

parents
node_modules/
test/d3.chart.test-build.js
test/sample-cjs-app/packaged.js
bower_components/
{
"disallowMixedSpacesAndTabs": true,
"maximumLineLength": 80,
"validateIndentation": "\t",
"validateQuoteMarks": "\""
}
{
"curly": true,
"unused": true,
"undef": true,
"trailing": false
}
language: node_js
node_js:
- '0.10'
before_script:
- npm install -g bower grunt-cli
- bower install
branches:
only:
- master
# Authors ordered by first contribution.
Mike Pennisi <mike@mikepennisi.com>
Irene Ros <imirene@gmail.com>
module.exports = function(grunt) {
"use strict";
grunt.loadTasks("build/tasks");
grunt.registerTask("build", ["webpack:dist", "webpack:dist-min"]);
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"]);
grunt.registerTask("default", ["test"]);
grunt.registerTask("release", ["default", "build"]);
};
Copyright (c) 2014 Irene Ros & Mike Pennisi
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
{
"name": "d3.chart",
"main": "d3.chart.js",
"ignore": [
"**/.*",
"Gruntfile.js",
"bower_components",
"examples",
"package.json",
"src",
"test"
],
"dependencies": {
"d3": "~3.3.11"
},
"keywords": [
"d3.js",
"visualization"
],
"devDependencies": {
"mocha": "~1.20.1",
"aight": "~1.2.5",
"assert": "~0.1.0"
}
}
{
"extends": "../.jshintrc",
"node": true,
"scripturl": true
}
module.exports = function(grunt) {
"use strict";
grunt.config.set("browserify", {
"test-app": {
files: {
"test/sample-cjs-app/packaged.js": [
"test/sample-cjs-app/main.js"
]
},
options: {
alias: {
"d3.chart": "./test/d3.chart.test-build.js"
}
}
}
});
grunt.loadNpmTasks("grunt-browserify");
};
module.exports = function(grunt) {
"use strict";
grunt.config.set("jscs", {
src: {
options: {
config: ".jscsrc"
},
src: [
"<%= jshint.src.src %>",
"<%= jshint.build.src %>"
]
},
examples: {
options: {
config: "examples/.jscsrc"
},
src: ["<%= jshint.examples.src %>"]
},
test: {
options: {
config: "test/.jscsrc"
},
src: ["<%= jshint.test.src %>"]
}
});
grunt.loadNpmTasks("grunt-jscs");
};
module.exports = function(grunt) {
"use strict";
grunt.config.set("jshint", {
src: {
options: {
jshintrc: "src/.jshintrc"
},
src: ["src/*.js"]
},
examples: {
options: {
jshintrc: "examples/api/.jshintrc"
},
src: ["examples/api/*.js"]
},
test: {
options: {
jshintrc: "test/.jshintrc"
},
src: ["test/tests/*.js"]
},
build: {
options: {
jshintrc: "build/.jshintrc"
},
src: ["Gruntfile.js", "build/**/*.js"]
}
});
grunt.loadNpmTasks("grunt-contrib-jshint");
};
module.exports = function(grunt) {
"use strict";
/**
* In order to limit duplication (and promote consistency), the testing
* configuration re-uses the same `index.html` file for all tests. The
* test setup logic implements branching behavior based on the value of the
* userAgent string, which is set programatically according to the
* configuration below. (This information cannot be specified using a query
* string parameter because `index.html` is loaded via the file://
* protocol.)
*/
grunt.config.set("mocha", {
options: {
run: false
},
unit: {
src: ["test/index.html"],
options: {
page: {
settings: {
userAgent: "PhantomJS:testSource(direct)"
}
}
}
},
// Test that the distributed source files function correctly in AMD and
// "browser global" environments.
exportsAmd: {
src: ["test/index.html"],
options: {
page: {
settings: {
userAgent: "PhantomJS:testSource(amd)"
}
}
}
},
exportsCommonjs: {
src: ["test/index.html"],
options: {
page: {
settings: {
userAgent: "PhantomJS:testSource(commonjs)"
}
}
}
},
exportsGlobal: {
src: ["test/index.html"],
options: {
page: {
settings: {
userAgent: "PhantomJS:testSource(global)"
}
}
}
}
});
grunt.loadNpmTasks("grunt-mocha");
};
module.exports = function(grunt) {
"use strict";
grunt.config.set("watch", {
scripts: {
files: ["src/**/*.js", "test/tests/*.js"],
tasks: ["jshint"]
}
});
grunt.loadNpmTasks("grunt-contrib-watch");
};
var webpack = require("webpack");
module.exports = function(grunt) {
"use strict";
grunt.config.set("webpack", {
options: require("../webpack.config.js"),
dist: {
output: {
filename: "d3.chart.js"
}
},
"dist-min": {
output: {
filename: "d3.chart.min.js",
sourceMapFilename: "d3.chart.min.map",
},
devtool: "source-map",
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
},
test: {
output: {
filename: "test/d3.chart.test-build.js"
}
}
});
grunt.loadNpmTasks("grunt-webpack");
};
"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() + 1) + "-" +
pad(now.getDate())
].join("\n");
module.exports = {
context: "src",
entry: "./chart-extensions",
output: {
/**
* Ensure the name of the exported AMD module is "d3.chart". This makes
* the browser global somewhat awkward to use (`window["d3.chart"]`),
* but consumers in those contexts are most likely referencing the
* function through the `d3` global.
*/
library: "d3.chart",
libraryTarget: "umd",
umdNamedDefine: true
},
plugins: [
new webpack.BannerPlugin(banner)
],
externals: {
d3: true
}
};
# d3.chart change log
### 0.3.0 (01.23.2016)
- Define library using Universal Module Definition ("UMD") pattern
### 0.2.1 (06.24.2014)
- Add bower.json
### 0.2.0 (02.21.2014)
- Introduce more intuitive inheritance behavior for `Chart#transform`
- Limit Chart constructors to a single "options" parameter
- Implement `Chart#attach` as a different signature for `Chart#mixin`
- Implement `Chart#demux`
- Remove `Chart#mixin`
- Honor `transform` option specified at Chart initialization time
### 0.1.3 (10.07.2013)
- Fix bug in Chart#unlayer
- Extend Chart#layer to accept existing layers
### 0.1.2 (07.30.2013)
- Implement support for Internet Explorer
- Throw custom error when Chart lookup fails
### 0.1.1 (06.10.2013)
- Fix bug in event triggering
### 0.1.0 (05.27.2013)
- Initial release
This diff is collapsed.
/*!
* d3.chart - v0.3.0
* License: MIT
* Date: 2016-01-23
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("d3")):"function"==typeof define&&define.amd?define("d3.chart",["d3"],e):"object"==typeof exports?exports["d3.chart"]=e(require("d3")):t["d3.chart"]=e(t.d3)}(this,function(t){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){var n;n=function(t,e,n){"use strict";var i=r(1),o=r(2),a=r(3);a(/^3\./.test(i.version),"d3.js version 3 is required"),r(4),i.chart=function(t){return 0===arguments.length?o:1===arguments.length?o[t]:o.extend.apply(o,arguments)},i.selection.prototype.chart=function(t,e){if(0===arguments.length)return this._chart;var r=o[t];return a(r,"No chart registered with name '"+t+"'"),new r(this,e)},i.selection.enter.prototype.chart=function(){return this._chart},i.transition.prototype.chart=i.selection.enter.prototype.chart,n.exports=i.chart}.call(e,r,e,t),!(void 0!==n&&(t.exports=n))},function(e,r){e.exports=t},function(t,e,r){var n;n=function(t,e,n){"use strict";function i(t){var e,r,n,i;if(!t)return t;for(r=arguments.length,e=1;r>e;e++)if(n=arguments[e])for(i in n)t[i]=n[i];return t}var o=r(3),a=Object.hasOwnProperty,s=function(t,e){var r=this.constructor,n=r.__super__;n&&s.call(n,t,e),a.call(r.prototype,"initialize")&&this.initialize.apply(t,e)},c=function(t,e){var r=this.constructor,n=r.__super__;return this===t&&a.call(this,"transform")&&(e=this.transform(e)),a.call(r.prototype,"transform")&&(e=r.prototype.transform.call(t,e)),n&&(e=c.call(n,t,e)),e},h=function(t,e){this.base=t,this._layers={},this._attached={},this._events={},e&&e.transform&&(this.transform=e.transform),s.call(this,this,[e])};h.prototype.initialize=function(){},h.prototype.unlayer=function(t){var e=this.layer(t);return delete this._layers[t],delete e._chart,e},h.prototype.layer=function(t,e,r){var n;if(1===arguments.length)return this._layers[t];if(2===arguments.length){if("function"==typeof e.draw)return e._chart=this,this._layers[t]=e,this._layers[t];o(!1,"When reattaching a layer, the second argument must be a d3.chart layer")}return n=e.layer(r),this._layers[t]=n,e._chart=this,n},h.prototype.attach=function(t,e){return 1===arguments.length?this._attached[t]:(this._attached[t]=e,e)},h.prototype.transform=function(t){return t},h.prototype.draw=function(t){var e,r,n;t=c.call(this,this,t);for(e in this._layers)this._layers[e].draw(t);for(r in this._attached)n=this.demux?this.demux(r,t):t,this._attached[r].draw(n)},h.prototype.on=function(t,e,r){var n=this._events[t]||(this._events[t]=[]);return n.push({callback:e,context:r||this,_chart:this}),this},h.prototype.once=function(t,e,r){var n=this,i=function(){n.off(t,i),e.apply(this,arguments)};return this.on(t,i,r)},h.prototype.off=function(t,e,r){var n,i,o,a,s,c;if(0===arguments.length){for(t in this._events)this._events[t].length=0;return this}if(1===arguments.length)return o=this._events[t],o&&(o.length=0),this;for(n=t?[t]:Object.keys(this._events),s=0;s<n.length;s++)for(i=n[s],o=this._events[i],c=o.length;c--;)a=o[c],(e&&e===a.callback||r&&r===a.context)&&o.splice(c,1);return this},h.prototype.trigger=function(t){var e,r,n=Array.prototype.slice.call(arguments,1),i=this._events[t];if(void 0!==i)for(e=0;e<i.length;e++)r=i[e],r.callback.apply(r.context,n);return this},h.extend=function(t,e,r){var n,o=this;n=e&&a.call(e,"constructor")?e.constructor:function(){return o.apply(this,arguments)},i(n,o,r);var s=function(){this.constructor=n};return s.prototype=o.prototype,n.prototype=new s,e&&i(n.prototype,e),n.__super__=o.prototype,h[t]=n,n},n.exports=h}.call(e,r,e,t),!(void 0!==n&&(t.exports=n))},function(t,e,r){var n;n=function(t,e,r){"use strict";r.exports=function(t,e){if(!t)throw new Error("[d3.chart] "+e)}}.call(e,r,e,t),!(void 0!==n&&(t.exports=n))},function(t,e,r){var n;n=function(t){"use strict";var e=r(1),n=r(5);e.selection.prototype.layer=function(t){var e,r=new n(this);if(r.dataBind=t.dataBind,r.insert=t.insert,"events"in t)for(e in t.events)r.on(e,t.events[e]);return this.on=function(){return r.on.apply(r,arguments)},this.off=function(){return r.off.apply(r,arguments)},this.draw=function(){return r.draw.apply(r,arguments)},this}}.call(e,r,e,t),!(void 0!==n&&(t.exports=n))},function(t,e,r){var n;n=function(t,e,n){"use strict";var i=r(1),o=r(3),a=/^(enter|update|merge|exit)(:transition)?$/,s=function(t){o(t,"Layers must be initialized with a base."),this._base=t,this._handlers={}};s.prototype.dataBind=function(){o(!1,"Layers must specify a `dataBind` method.")},s.prototype.insert=function(){o(!1,"Layers must specify an `insert` method.")},s.prototype.on=function(t,e,r){return r=r||{},o(a.test(t),"Unrecognized lifecycle event name specified to `Layer#on`: '"+t+"'."),t in this._handlers||(this._handlers[t]=[]),this._handlers[t].push({callback:e,chart:r.chart||null}),this._base},s.prototype.off=function(t,e){var r,n=this._handlers[t];if(o(a.test(t),"Unrecognized lifecycle event name specified to `Layer#off`: '"+t+"'."),!n)return this._base;if(1===arguments.length)return n.length=0,this._base;for(r=n.length-1;r>-1;--r)n[r].callback===e&&n.splice(r,1);return this._base},s.prototype.draw=function(t){var e,r,n,a,s,c,h,l,u;e=this.dataBind.call(this._base,t),o(e&&e.call===i.selection.prototype.call,"Invalid selection defined by `Layer#dataBind` method."),o(e.enter,"Layer selection not properly bound."),r=e.enter(),r._chart=this._base._chart,n=[{name:"update",selection:e},{name:"enter",selection:r,method:this.insert},{name:"merge",selection:e},{name:"exit",selection:e,method:e.exit}];for(var p=0,f=n.length;f>p;++p)if(h=n[p].name,a=n[p].selection,s=n[p].method,"function"==typeof s&&(a=s.call(a)),!a.empty()){if(o(a&&a.call===i.selection.prototype.call,"Invalid selection defined for '"+h+"' lifecycle event."),c=this._handlers[h])for(l=0,u=c.length;u>l;++l)a._chart=c[l].chart||this._base._chart,a.call(c[l].callback);if(c=this._handlers[h+":transition"],c&&c.length)for(a=a.transition(),l=0,u=c.length;u>l;++l)a._chart=c[l].chart||this._base._chart,a.call(c[l].callback)}},n.exports=s}.call(e,r,e,t),!(void 0!==n&&(t.exports=n))}])});
//# sourceMappingURL=d3.chart.min.map
\ No newline at end of file
This diff is collapsed.
{
"disallowMixedSpacesAndTabs": true,
"maximumLineLength": 80,
"validateIndentation": 2,
"validateQuoteMarks": "\""
}
{
"extends": "../../.jshintrc",
"unused": false,
"globals": {
"log": true,
"output": true,
"d3": true
}
}
d3.chart("PieBars", {
initialize: function() {
var barchart = this.base.append("svg")
.chart("BarChart");
var piechart = this.base.append("svg")
.chart("PieChart")
.radius(10);
this.attach("bars", barchart);
this.attach("piechart", piechart);
}
});
// assume previously defined d3.chart called
// CircleChart
// create an instance of the chart on a d3 selection
var chart = d3.select(output)
.append("svg")
.attr("height", 30)
.attr("width", 400)
.chart("CircleChart");
// render it with some data
chart.draw([1,4,6,9,12,13,30]);
d3.chart("CircleChart", {
initialize: function() {
log("Hi! I'm a chart");
}
});
d3.chart("CircleChart").extend("OtherCircleChart", {
initialize: function() {
log("I am a circle chart based on the one above!");
}
});
var chart = d3.select(output)
.chart("OtherCircleChart");
d3.chart("CircleChart", {
initialize: function() {
// add a circles layer
var circleLayer = this.unlayer("circles");
// reattach layer
this.layer("circles", circleLayer);
}
});
d3.chart("CircleChart", {
initialize: function() {
},
action: function() {
this.trigger("acted", "action executed!");
}
});
var chart = d3.select(output)
.chart("CircleChart");
chart.on("acted", function(message){
log(message);
});
// will trigger
chart.action();
chart.off();
// won't trigger
chart.action();
d3.chart("CircleChart", {
initialize: function() {
},
action: function() {
this.trigger("acted", "action executed!");
}
});
var chart = d3.select(output)
.chart("CircleChart");
chart.on("acted", function(message){
log(message);
});
chart.action();
d3.chart("CircleChart", {
initialize: function() {
},
action: function() {
this.trigger("acted", "action executed!");
}
});
var chart = d3.select(output)
.chart("CircleChart");
chart.once("acted", function(message){
log(message);
});
// will only call the above callback once even
// though we will trigger twice
chart.action();
chart.action();
d3.chart("CircleChart", {
initialize: function() {
// assume we create layers and such here.
},
transform: function(data) {
// assume we recieve an object that has
// the data array under a values property like so:
// { values: [...] }
return data.values;
}
});
var chart = d3.select(output)
.append("svg")
.attr("height", 30)
.attr("width", 400)
.chart("CircleChart");
// render it with some data
log(chart.transform({ values: [1,4,6,9,12,13,30]}));
d3.chart("CircleChart", {
initialize: function() {
},
action: function() {
this.trigger("acted", "action executed!");
}
});
var chart = d3.select(output)
.chart("CircleChart");
chart.on("acted", function(message){
log(message);
});
chart.action();
d3.chart("CircleChart", {
initialize: function() {
// add a circles layer
var circleLayer = this.unlayer("circles");
// reattach layer
this.layer("circles", circleLayer);
}
});
d3.chart("CircleChart", {
initialize: function() {
log("Hi! I'm a chart");
}
});
var chart = d3.select(output)
.chart("CircleChart");
// define a layer
var layer = d3.select(output)
.append("svg")
.attr("width", 100)
.attr("height", 100)
.layer({
dataBind: function(data){
return this.selectAll("rect")
.data(data);
},
insert: function() {
return this.append("rect");
},
events: {
enter: function() {
return this.attr("x", function(d){ return d; })
.attr("y", 48)
.attr("width", 4)
.attr("height",4);
}
}
});
// render the layer
layer.draw([10,20,50,90]);
// define a new chart type: a circle chart
d3.chart("CircleChart", {
initialize: function() {
// create a layer of circles that will go into
// a new group element on the base of the chart
var circles = this.layer("circles", this.base.append("g"), {
// select the elements we wish to bind to and
// bind the data to them.
dataBind: function(data) {
return this.selectAll("circle")
.data(data);
},
// insert actual circles
insert: function() {