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
0 parents
commit 93a7bef
Showing
14 changed files
with
8,761 additions
and
0 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 @@ | ||
node_modules |
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,86 @@ | ||
module.exports = function(grunt) { | ||
|
||
"use strict"; | ||
|
||
grunt.initConfig({ | ||
meta: { | ||
pkg: grunt.file.readJSON("package.json"), | ||
srcFiles: [ | ||
"src/base.js" | ||
] | ||
}, | ||
watch: { | ||
scripts: { | ||
files: ["src/**/*.js"], | ||
tasks: ["jshint"] | ||
} | ||
}, | ||
jshint: { | ||
options: { | ||
curly: true, | ||
undef: true | ||
}, | ||
chart: { | ||
options: { | ||
browser: true, | ||
globals: { | ||
d3: true | ||
} | ||
}, | ||
files: { | ||
src: "<%= meta.srcFiles %>" | ||
} | ||
}, | ||
grunt: { | ||
options: { | ||
node: true | ||
}, | ||
files: { | ||
src: ["Gruntfile.js"] | ||
} | ||
} | ||
}, | ||
concat: { | ||
options: { | ||
banner: "/*! <%= meta.pkg.name %> - v<%= meta.pkg.version %>\n" + | ||
" * License: <%= meta.pkg.license %>\n" + | ||
" * Date: <%= grunt.template.today('yyyy-mm-dd') %>\n" + | ||
" */\n" | ||
}, | ||
dist: { | ||
files: { | ||
"dist/d3.chart.base.js": "<%= meta.srcFiles %>" | ||
} | ||
}, | ||
release: { | ||
files: { | ||
"d3.chart.base.js": "<%= meta.srcFiles %>" | ||
} | ||
} | ||
}, | ||
uglify: { | ||
options: { | ||
// Preserve banner | ||
preserveComments: "some" | ||
}, | ||
dist: { | ||
files: { | ||
"dist/d3.chart.base.min.js": "dist/d3.chart.base.js" | ||
} | ||
}, | ||
release: { | ||
files: { | ||
"d3.chart.base.min.js": "dist/d3.chart.base.js" | ||
} | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks("grunt-contrib-jshint"); | ||
grunt.loadNpmTasks("grunt-contrib-concat"); | ||
grunt.loadNpmTasks("grunt-contrib-uglify"); | ||
grunt.loadNpmTasks("grunt-contrib-watch"); | ||
|
||
grunt.registerTask("default", ["jshint", "concat:dist", "uglify:dist"]); | ||
grunt.registerTask("release", ["jshint", "concat", "uglify"]); | ||
}; |
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,22 @@ | ||
Copyright (c) 2013 Irene Ros | ||
|
||
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. |
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,140 @@ | ||
# d3.chart.base | ||
|
||
The `BaseChart` is a very small chart from which one can extend to build | ||
other d3.chart based charts. The purpose of the d3.chart.base is to provide | ||
common functionality that may be repetitive, such as creating height/width | ||
getters/setters. By default, `BaseChart` doesn't actually render anything | ||
itself and it has no layers. | ||
|
||
These are the only two getters/setters available in the base. | ||
They take care of: | ||
|
||
* Returning the value when no new value is provided | ||
* Saving the new value | ||
* Updating the chart base height/width | ||
* Redrawing the chart if the chart has data saved in a `.data` property | ||
* Broadcast a `change:width` or `change:height` events when the width/height changes | ||
|
||
We expect the base functionality to grow as we see more common pattenrs. Please | ||
submit issues when you have suggestions! | ||
|
||
### Sample Use | ||
|
||
See a sample chart in the `examples` folder. | ||
Here is a brief example: | ||
|
||
```javascript | ||
d3.chart("BaseChart").extend("MyChart", { | ||
initialize: function() { | ||
// ... | ||
} | ||
}); | ||
|
||
var chart = d3.select("#vis") | ||
.append("svg") | ||
.chart("MyChart") | ||
.height(100) | ||
.width(200); | ||
``` | ||
|
||
### API | ||
|
||
Sample API Documentation: | ||
|
||
#### `<instance>.height(newheight)` | ||
|
||
**Description:** | ||
|
||
Changes the height of the chart if `newHeight` is provided. Otherwise returns the | ||
current chart height. | ||
|
||
**Parameters:** | ||
|
||
* `newHeight` - number. Optional. The new height to set. | ||
|
||
**Uses:** | ||
|
||
Example: | ||
|
||
```javascript | ||
var chart = d3.select("#vis") | ||
.append("svg") | ||
.chart("MyChart") | ||
.height(200); | ||
``` | ||
|
||
#### `<instance>.width(newWidth)` | ||
|
||
**Description:** | ||
|
||
Changes the width of the chart if `newWidth` is provided. Otherwise returns the | ||
current chart width. | ||
|
||
**Parameters:** | ||
|
||
* `newWidth` - number. Optional. The new width to set. | ||
|
||
**Uses:** | ||
|
||
Example: | ||
|
||
```javascript | ||
var chart = d3.select("#vis") | ||
.append("svg") | ||
.chart("MyChart") | ||
.width(120); | ||
``` | ||
|
||
### Events | ||
|
||
Sample Event Documentation: | ||
|
||
#### `change:width` | ||
|
||
**Description:** | ||
|
||
Broadcast when the chart width changes | ||
|
||
**Arguments:** | ||
|
||
* `newWidth` - The new width | ||
* `oldWidth` - The old width | ||
|
||
**Uses:** | ||
|
||
Example: | ||
|
||
```javascript | ||
var chart = d3.select("#vis") | ||
.append("svg") | ||
.chart("MyChart"); | ||
|
||
chart.on("change:width", function(newWidth, oldWidth) { | ||
// handle event... | ||
}); | ||
``` | ||
|
||
#### `change:height` | ||
|
||
**Description:** | ||
|
||
Broadcast when the chart height changes | ||
|
||
**Arguments:** | ||
|
||
* `newHeight` - The new height | ||
* `oldHeight` - The old height | ||
|
||
**Uses:** | ||
|
||
Example: | ||
|
||
```javascript | ||
var chart = d3.select("#vis") | ||
.append("svg") | ||
.chart("MyChart"); | ||
|
||
chart.on("change:height", function(newHeight, oldHeight) { | ||
// handle event... | ||
}); | ||
``` |
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,64 @@ | ||
/*! d3.chart.base - v0.1.0 | ||
* License: MIT Expat | ||
* Date: 2013-05-28 | ||
*/ | ||
d3.chart("BaseChart", { | ||
initialize: function() { | ||
|
||
// setup some reasonable defaults | ||
this._width = this.base.attr("width") || 200; | ||
this._height = this.base.attr("height") || 200; | ||
|
||
}, | ||
|
||
width: function(newWidth) { | ||
if (arguments.length === 0) { | ||
return this._width; | ||
} | ||
|
||
var oldWidth = this._width; | ||
|
||
this._width = newWidth; | ||
|
||
// only if the width actually changed: | ||
if (this._width !== oldWidth) { | ||
|
||
// set higher container width | ||
this.base.attr("width", this._width); | ||
|
||
// trigger a change event | ||
this.trigger("change:width", this._width, oldWidth); | ||
|
||
// redraw if we saved the data on the chart | ||
if (this.data) { | ||
this.draw(this.data); | ||
} | ||
} | ||
|
||
// always return the chart, for chaining magic. | ||
return this; | ||
}, | ||
|
||
height: function(newHeight) { | ||
if (arguments.length === 0) { | ||
return this._height; | ||
} | ||
|
||
var oldHeight = this._height; | ||
|
||
this._height = newHeight; | ||
|
||
if (this._height !== oldHeight) { | ||
|
||
this.base.attr("height", this._height); | ||
|
||
this.trigger("change:height", this._height, oldHeight); | ||
|
||
if (this.data) { | ||
this.draw(this.data); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
}); |
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 @@ | ||
|
Oops, something went wrong.