Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor various renderers so they subclass a base class renerer

  • Loading branch information...
commit b69c8d1a31758ad296f75fcaf2d09444b01d14e0 1 parent 76f1cc5
David Chester dchester authored
3  Makefile
View
@@ -30,6 +30,7 @@ JS_FILES=\
src/js/Rickshaw.Graph.JSONP.js\
src/js/Rickshaw.Graph.Legend.js\
src/js/Rickshaw.Graph.RangeSlider.js\
+ src/js/Rickshaw.Graph.Renderer.js\
src/js/Rickshaw.Graph.Renderer.Line.js\
src/js/Rickshaw.Graph.Renderer.Stack.js\
src/js/Rickshaw.Graph.Renderer.Bar.js\
@@ -63,4 +64,4 @@ rickshaw.min.css: $(CSS_MIN) rickshaw.css
$(CSS_MIN) rickshaw.css > rickshaw.min.css
rickshaw.min.js: $(JS_MIN) rickshaw.js
- $(JS_MIN) rickshaw.js > rickshaw.min.js
+ $(JS_MIN) --reserved-names "\$$super" rickshaw.js > rickshaw.min.js
7 examples/ajax.html
View
@@ -8,12 +8,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
- <script src="../src/js/Rickshaw.js"></script>
- <script src="../src/js/Rickshaw.Compat.ClassList.js"></script>
- <script src="../src/js/Rickshaw.Graph.js"></script>
- <script src="../src/js/Rickshaw.Graph.Ajax.js"></script>
- <script src="../src/js/Rickshaw.Graph.Unstacker.js"></script>
- <script src="../src/js/Rickshaw.Graph.Renderer.Line.js"></script>
+ <script src="../rickshaw.js"></script>
</head>
<body>
6 examples/bars.html
View
@@ -8,11 +8,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js"></script>
- <script src="../src/js/Rickshaw.js"></script>
- <script src="../src/js/Rickshaw.Compat.ClassList.js"></script>
- <script src="../src/js/Rickshaw.Graph.js"></script>
- <script src="../src/js/Rickshaw.Graph.Renderer.Bar.js"></script>
- <script src="../src/js/Rickshaw.Fixtures.RandomData.js"></script>
+ <script src="../rickshaw.js"></script>
</head>
<body>
14 examples/data.json
View
@@ -1,14 +1,14 @@
[
{
- 'color': 'blue',
- 'name': 'New York',
- 'data': [ { x: 0, y: 40 }, { x: 1, y: 49 }, { x: 2, y: 38 }, { x: 3, y: 30 }, { x: 4, y: 32 } ],
+ "color": "blue",
+ "name": "New York",
+ "data": [ { "x": 0, "y": 40 }, { "x": 1, "y": 49 }, { "x": 2, "y": 38 }, { "x": 3, "y": 30 }, { "x": 4, "y": 32 } ]
}, {
- 'name': 'London',
- 'data': [ { x: 0, y: 19 }, { x: 1, y: 22 }, { x: 2, y: 29 }, { x: 3, y: 20 }, { x: 4, y: 14 } ],
+ "name": "London",
+ "data": [ { "x": 0, "y": 19 }, { "x": 1, "y": 22 }, { "x": 2, "y": 29 }, { "x": 3, "y": 20 }, { "x": 4, "y": 14 } ]
}, {
- 'name': 'Tokyo',
- 'data': [ { x: 0, y: 8 }, { x: 1, y: 12 }, { x: 2, y: 15 }, { x: 3, y: 11 }, { x: 4, y: 10 } ],
+ "name": "Tokyo",
+ "data": [ { "x": 0, "y": 8 }, { "x": 1, "y": 12 }, { "x": 2, "y": 15 }, { "x": 3, "y": 11 }, { "x": 4, "y": 10 } ]
}
]
2  examples/extensions.html
View
@@ -13,8 +13,10 @@
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js"></script>
<script src="../src/js/Rickshaw.js"></script>
+ <script src="../src/js/Rickshaw.Class.js"></script>
<script src="../src/js/Rickshaw.Compat.ClassList.js"></script>
<script src="../src/js/Rickshaw.Graph.js"></script>
+ <script src="../src/js/Rickshaw.Graph.Renderer.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Area.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Line.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Bar.js"></script>
1  examples/fixed.html
View
@@ -15,6 +15,7 @@
<script src="../src/js/Rickshaw.js"></script>
<script src="../src/js/Rickshaw.Class.js"></script>
<script src="../src/js/Rickshaw.Graph.js"></script>
+ <script src="../src/js/Rickshaw.Graph.Renderer.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Stack.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Line.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Area.js"></script>
12 examples/lines.html
View
@@ -12,17 +12,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js"></script>
- <script src="../src/js/Rickshaw.js"></script>
- <script src="../src/js/Rickshaw.Compat.ClassList.js"></script>
- <script src="../src/js/Rickshaw.Graph.js"></script>
- <script src="../src/js/Rickshaw.Graph.Renderer.Line.js"></script>
- <script src="../src/js/Rickshaw.Graph.HoverDetail.js"></script>
- <script src="../src/js/Rickshaw.Graph.Legend.js"></script>
- <script src="../src/js/Rickshaw.Graph.Axis.Time.js"></script>
- <script src="../src/js/Rickshaw.Graph.Behavior.Series.Toggle.js"></script>
- <script src="../src/js/Rickshaw.Graph.Unstacker.js"></script>
- <script src="../src/js/Rickshaw.Fixtures.Time.js"></script>
- <script src="../src/js/Rickshaw.Fixtures.RandomData.js"></script>
+ <script src="../rickshaw.js"></script>
</head>
<body>
7 examples/scatterplot.html
View
@@ -4,12 +4,7 @@
<script src="../vendor/d3.min.js"></script>
<script src="../vendor/d3.layout.min.js"></script>
-<script src="../src/js/Rickshaw.js"></script>
-<script src="../src/js/Rickshaw.Compat.ClassList.js"></script>
-<script src="../src/js/Rickshaw.Graph.js"></script>
-<script src="../src/js/Rickshaw.Graph.Unstacker.js"></script>
-<script src="../src/js/Rickshaw.Graph.Renderer.ScatterPlot.js"></script>
-<script src="../src/js/Rickshaw.Fixtures.RandomData.js"></script>
+<script src="../rickshaw.js"></script>
<div id="chart"></div>
1  examples/series.html
View
@@ -15,6 +15,7 @@
<script src="../src/js/Rickshaw.js"></script>
<script src="../src/js/Rickshaw.Class.js"></script>
<script src="../src/js/Rickshaw.Graph.js"></script>
+ <script src="../src/js/Rickshaw.Graph.Renderer.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Stack.js"></script>
<script src="../src/js/Rickshaw.Graph.Renderer.Line.js"></script>
<script src="../src/js/Rickshaw.Graph.RangeSlider.js"></script>
1  examples/start.html
View
@@ -1,6 +1,7 @@
<!doctype>
<script src="../vendor/d3.min.js"></script>
<script src="../vendor/d3.layout.min.js"></script>
+
<script src="../rickshaw.min.js"></script>
<div id="chart"></div>
915 rickshaw.js
View
@@ -22,7 +22,212 @@ Rickshaw = {
for (var key in obj) keys.push(key);
return keys;
}
+};
+
+/* Adapted from https://github.com/Jakobo/PTClass */
+
+/*
+Copyright (c) 2005-2010 Sam Stephenson
+
+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 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.
+*/
+/* Based on Alex Arnell's inheritance implementation. */
+/** section: Language
+ * class Class
+ *
+ * Manages Prototype's class-based OOP system.
+ *
+ * Refer to Prototype's web site for a [tutorial on classes and
+ * inheritance](http://prototypejs.org/learn/class-inheritance).
+**/
+(function(globalContext) {
+/* ------------------------------------ */
+/* Import from object.js */
+/* ------------------------------------ */
+var _toString = Object.prototype.toString,
+ NULL_TYPE = 'Null',
+ UNDEFINED_TYPE = 'Undefined',
+ BOOLEAN_TYPE = 'Boolean',
+ NUMBER_TYPE = 'Number',
+ STRING_TYPE = 'String',
+ OBJECT_TYPE = 'Object',
+ FUNCTION_CLASS = '[object Function]';
+function isFunction(object) {
+ return _toString.call(object) === FUNCTION_CLASS;
+}
+function extend(destination, source) {
+ for (var property in source) if (source.hasOwnProperty(property)) // modify protect primitive slaughter
+ destination[property] = source[property];
+ return destination;
+}
+function keys(object) {
+ if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
+ var results = [];
+ for (var property in object) {
+ if (object.hasOwnProperty(property)) {
+ results.push(property);
+ }
+ }
+ return results;
+}
+function Type(o) {
+ switch(o) {
+ case null: return NULL_TYPE;
+ case (void 0): return UNDEFINED_TYPE;
+ }
+ var type = typeof o;
+ switch(type) {
+ case 'boolean': return BOOLEAN_TYPE;
+ case 'number': return NUMBER_TYPE;
+ case 'string': return STRING_TYPE;
+ }
+ return OBJECT_TYPE;
+}
+function isUndefined(object) {
+ return typeof object === "undefined";
+}
+/* ------------------------------------ */
+/* Import from Function.js */
+/* ------------------------------------ */
+var slice = Array.prototype.slice;
+function argumentNames(fn) {
+ var names = fn.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
+ .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
+ .replace(/\s+/g, '').split(',');
+ return names.length == 1 && !names[0] ? [] : names;
+}
+function wrap(fn, wrapper) {
+ var __method = fn;
+ return function() {
+ var a = update([bind(__method, this)], arguments);
+ return wrapper.apply(this, a);
+ }
+}
+function update(array, args) {
+ var arrayLength = array.length, length = args.length;
+ while (length--) array[arrayLength + length] = args[length];
+ return array;
}
+function merge(array, args) {
+ array = slice.call(array, 0);
+ return update(array, args);
+}
+function bind(fn, context) {
+ if (arguments.length < 2 && isUndefined(arguments[0])) return this;
+ var __method = fn, args = slice.call(arguments, 2);
+ return function() {
+ var a = merge(args, arguments);
+ return __method.apply(context, a);
+ }
+}
+
+/* ------------------------------------ */
+/* Import from Prototype.js */
+/* ------------------------------------ */
+var emptyFunction = function(){};
+
+var Class = (function() {
+
+ // Some versions of JScript fail to enumerate over properties, names of which
+ // correspond to non-enumerable properties in the prototype chain
+ var IS_DONTENUM_BUGGY = (function(){
+ for (var p in { toString: 1 }) {
+ // check actual property name, so that it works with augmented Object.prototype
+ if (p === 'toString') return false;
+ }
+ return true;
+ })();
+
+ function subclass() {};
+ function create() {
+ var parent = null, properties = [].slice.apply(arguments);
+ if (isFunction(properties[0]))
+ parent = properties.shift();
+
+ function klass() {
+ this.initialize.apply(this, arguments);
+ }
+
+ extend(klass, Class.Methods);
+ klass.superclass = parent;
+ klass.subclasses = [];
+
+ if (parent) {
+ subclass.prototype = parent.prototype;
+ klass.prototype = new subclass;
+ try { parent.subclasses.push(klass) } catch(e) {}
+ }
+
+ for (var i = 0, length = properties.length; i < length; i++)
+ klass.addMethods(properties[i]);
+
+ if (!klass.prototype.initialize)
+ klass.prototype.initialize = emptyFunction;
+
+ klass.prototype.constructor = klass;
+ return klass;
+ }
+
+ function addMethods(source) {
+ var ancestor = this.superclass && this.superclass.prototype,
+ properties = keys(source);
+
+ // IE6 doesn't enumerate `toString` and `valueOf` (among other built-in `Object.prototype`) properties,
+ // Force copy if they're not Object.prototype ones.
+ // Do not copy other Object.prototype.* for performance reasons
+ if (IS_DONTENUM_BUGGY) {
+ if (source.toString != Object.prototype.toString)
+ properties.push("toString");
+ if (source.valueOf != Object.prototype.valueOf)
+ properties.push("valueOf");
+ }
+
+ for (var i = 0, length = properties.length; i < length; i++) {
+ var property = properties[i], value = source[property];
+ if (ancestor && isFunction(value) &&
+ argumentNames(value)[0] == "$super") {
+ var method = value;
+ value = wrap((function(m) {
+ return function() { return ancestor[m].apply(this, arguments); };
+ })(property), method);
+
+ value.valueOf = bind(method.valueOf, method);
+ value.toString = bind(method.toString, method);
+ }
+ this.prototype[property] = value;
+ }
+
+ return this;
+ }
+
+ return {
+ create: create,
+ Methods: {
+ addMethods: addMethods
+ }
+ };
+})();
+
+if (globalContext.exports) {
+ globalContext.exports.Class = Class;
+}
+else {
+ globalContext.Class = Class;
+}
+})(Rickshaw);
Rickshaw.namespace('Rickshaw.Compat.ClassList');
Rickshaw.Compat.ClassList = function() {
@@ -633,7 +838,7 @@ Rickshaw.Graph.Ajax = function(args) {
console.log("error loading dataURL: " + this.dataURL);
}
- var data = eval( '(' + response.responseText + ')' );
+ var data = JSON.parse(response.responseText);
if (typeof args.onData === 'function') {
var processedData = args.onData(data);
@@ -1045,6 +1250,14 @@ Rickshaw.namespace('Rickshaw.Graph.HoverDetail');
Rickshaw.Graph.HoverDetail = function(args) {
var graph = this.graph = args.graph;
+
+ var xFormatter = args.xFormatter || function(x) {
+ return new Date( x * 1000 ).toUTCString();
+ };
+
+ var yFormatter = args.yFormatter || function(y) {
+ return y.toFixed(2);
+ };
var element = this.element = document.createElement('div');
element.className = 'detail';
@@ -1099,10 +1312,6 @@ Rickshaw.Graph.HoverDetail = function(args) {
}
}
- this.xFormatter = function(x) {
- return new Date( x * 1000 ).toUTCString();
- }
-
this.graph.element.addEventListener(
'mousemove',
function(e) {
@@ -1141,7 +1350,7 @@ Rickshaw.Graph.HoverDetail = function(args) {
var xLabel = document.createElement('div');
xLabel.className = 'x_label';
- xLabel.innerHTML = this.xFormatter(domainX);
+ xLabel.innerHTML = xFormatter(domainX);
this.element.appendChild(xLabel);
var activeItem = null;
@@ -1152,9 +1361,13 @@ Rickshaw.Graph.HoverDetail = function(args) {
detail.sort(sortFn).forEach( function(d) {
+ var formattedYValue = (yFormatter.constructor == Array) ?
+ yFormatter[detail.indexOf(d)](d.value.y) :
+ yFormatter(d.value.y);
+
var item = document.createElement('div');
item.className = 'item';
- item.innerHTML = d.name + ':&nbsp;' + d.value.y.toFixed(2);
+ item.innerHTML = d.name + ':&nbsp;' + formattedYValue;
item.style.top = graph.y(d.value.y0 + d.value.y) + 'px';
var domainMouseY = graph.y.magnitude.invert(graph.element.offsetHeight - mouseY);
@@ -1353,170 +1566,167 @@ Rickshaw.Graph.RangeSlider = function(args) {
} );
}
-Rickshaw.namespace('Rickshaw.Graph.Renderer.Line');
+Rickshaw.namespace("Rickshaw.Graph.Renderer");
-Rickshaw.Graph.Renderer.Line = function(args) {
+Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
- var graph = this.graph = args.graph;
- var self = this;
+ name: undefined,
+ tension: 0.8,
+ strokeWidth: 2,
+ unstack: true,
+ padding: { top: 0.025, right: 0, bottom: 0, left: 0 },
+ stroke: false,
+ fill: false,
- this.name = 'line';
- this.unstack = true;
-
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
-
- this.seriesPathFactory = function() {
-
- return d3.svg.line()
- .x( function(d) { return graph.x(d.x) } )
- .y( function(d) { return graph.y(d.y) } )
- .interpolate(this.graph.interpolation).tension(0.8);
- }
+ initialize: function(args) {
+ this.graph = args.graph;
+ this.tension = args.tension || this.tension;
+ this.graph.unstacker = this.graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: this.graph } );
- this.domain = function() {
+ },
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
-
- stackedData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y )
- } );
- } );
+ seriesPathFactory: function() {
+ //implement in subclass
+ },
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
+ seriesStrokeFactory: function() {
+ // implement in subclass
+ },
- var yMin = 0;
- var yMax = d3.max( values );
+ domain: function() {
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
+ var values = [];
+ var stackedData = this.graph.stackedData || this.graph.stackData();
- this.render = function() {
+ var topSeriesData = this.unstack ? stackedData : [ stackedData.slice(-1).shift() ];
- graph.vis.selectAll('*').remove();
+ topSeriesData.forEach( function(series) {
+ series.forEach( function(d) {
+ values.push( d.y + d.y0 );
+ } );
+ } );
- var nodes = this.graph.vis.selectAll("path")
- .data(this.graph.stackedData)
- .enter().append("svg:path")
- .attr("d", this.seriesPathFactory());
+ var xMin = stackedData[0][0].x;
+ var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
- var i = 0;
- graph.series.forEach( function(series) {
- if (series.disabled) return;
- series.path = nodes[0][i++];
- self._styleSeries(series);
- } );
- }
+ xMin -= (xMax - xMin) * (this.padding.left);
+ xMax += (xMax - xMin) * (this.padding.right);
- this._styleSeries = function(series) {
- series.path.setAttribute('fill', 'none');
- series.path.setAttribute('stroke', series.color);
- series.path.setAttribute('stroke-width', 2);
- }
-}
+ var yMin = 0;
+ var yMax = d3.max( values ) * (1 + this.padding.top);
-Rickshaw.namespace('Rickshaw.Graph.Renderer.Stack');
+ return { x: [xMin, xMax], y: [yMin, yMax] };
+ },
-Rickshaw.Graph.Renderer.Stack = function(args) {
+ render: function() {
- var graph = this.graph = args.graph;
- var self = this;
+ var graph = this.graph;
- this.name = 'stack';
+ graph.vis.selectAll('*').remove();
- this.seriesPathFactory = function() {
+ var nodes = graph.vis.selectAll("path")
+ .data(this.graph.stackedData)
+ .enter().append("svg:path")
+ .attr("d", this.seriesPathFactory());
- return d3.svg.area()
- .x( function(d) { return graph.x(d.x) } )
- .y0( function(d) { return graph.y(d.y0) } )
- .y1( function(d) { return graph.y(d.y + d.y0)} )
- .interpolate(this.graph.interpolation).tension(0.8);
- }
+ var i = 0;
+ graph.series.forEach( function(series) {
+ if (series.disabled) return;
+ series.path = nodes[0][i++];
+ this._styleSeries(series);
+ }, this );
+ },
- this.domain = function() {
+ _styleSeries: function(series) {
- var stackedData = graph.stackedData || graph.stackData();
- var topSeriesData = stackedData.slice(-1).shift();
+ var fill = this.fill ? series.color : 'none';
+ var stroke = this.stroke ? series.color : 'none';
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
+ series.path.setAttribute('fill', fill);
+ series.path.setAttribute('stroke', stroke);
+ series.path.setAttribute('stroke-width', this.strokeWidth);
+ series.path.setAttribute('class', series.className);
+ },
- var yMin = 0;
- var yMax = d3.max( topSeriesData, function(d) { return d.y + d.y0 } );
+ setStrokeWidth: function(strokeWidth) {
+ if (strokeWidth !== undefined) {
+ this.strokeWidth = strokeWidth;
+ }
+ },
- return { x: [xMin, xMax], y: [yMin, yMax] };
+ setTension: function(tension) {
+ if (tension !== undefined) {
+ this.tension = tension;
}
+ }
+} );
- this.render = function() {
+Rickshaw.namespace('Rickshaw.Graph.Renderer.Line');
- graph.vis.selectAll('*').remove();
+Rickshaw.Graph.Renderer.Line = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var nodes = graph.vis.selectAll("path")
- .data(graph.stackedData)
- .enter().append("svg:path")
- .attr("d", this.seriesPathFactory());
-
- var i = 0;
- graph.series.forEach( function(series) {
- if (series.disabled) return;
- series.path = nodes[0][i++];
- self._styleSeries(series);
- } );
+ name: 'line',
+ unstack: true,
+ fill: false,
+ stroke: true,
- }
+ seriesPathFactory: function() {
- this._styleSeries = function(series) {
- if (!series.path) return;
- series.path.setAttribute('fill', series.color);
- series.path.setAttribute('stroke-width', 2);
- series.path.setAttribute('class', series.className);
- }
-}
-Rickshaw.namespace('Rickshaw.Graph.Renderer.Bar');
+ var graph = this.graph;
-Rickshaw.Graph.Renderer.Bar = function(args) {
+ return d3.svg.line()
+ .x( function(d) { return graph.x(d.x) } )
+ .y( function(d) { return graph.y(d.y) } )
+ .interpolate(this.graph.interpolation).tension(this.tension);
+ }
+} );
- var graph = this.graph = args.graph;
- var self = this;
+Rickshaw.namespace('Rickshaw.Graph.Renderer.Stack');
- this.name = 'bar';
- this.gapSize = args.gapSize || 0.05;
+Rickshaw.Graph.Renderer.Stack = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- this.unstack = false;
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
+ name: 'stack',
+ fill: true,
+ stroke: false,
+ unstack: false,
- this.domain = function() {
+ seriesPathFactory: function() {
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
+ var graph = this.graph;
- var topSeriesData = this.unstack ? stackedData : [ stackedData.slice(-1).shift() ];
+ return d3.svg.area()
+ .x( function(d) { return graph.x(d.x) } )
+ .y0( function(d) { return graph.y(d.y0) } )
+ .y1( function(d) { return graph.y(d.y + d.y0) } )
+ .interpolate(this.graph.interpolation).tension(this.tension);
+ }
+} );
- topSeriesData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y + d.y0 );
- } );
- } );
+Rickshaw.namespace('Rickshaw.Graph.Renderer.Bar');
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
+Rickshaw.Graph.Renderer.Bar = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var yMin = 0;
- var yMax = d3.max( values );
+ name: 'bar',
+ gapSize: 0.05,
+ unstack: false,
- this._barWidth = null;
+ initialize: function($super, args) {
+ args = args || {};
+ this.gapSize = args.gapSize || this.gapSize;
+ $super(args);
+ },
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
+ domain: function($super) {
+ this._barWidth = null;
+ return $super();
+ },
- this.barWidth = function() {
+ barWidth: function() {
if (this._barWidth) return this._barWidth;
- var stackedData = graph.stackedData || graph.stackData();
+ var stackedData = this.graph.stackedData || this.graph.stackData();
var data = stackedData.slice(-1).shift();
var intervalCounts = {};
@@ -1543,17 +1753,18 @@ Rickshaw.Graph.Renderer.Bar = function(args) {
this._barWidth = this.graph.x(data[0].x + frequentInterval.magnitude * (1 - this.gapSize));
return this._barWidth;
- }
+ },
- this.render = function() {
+ render: function() {
+
+ var graph = this.graph;
graph.vis.selectAll('*').remove();
- var barsPerSlot = this.unstack ? this.graph.series.length : 1;
var barWidth = this.barWidth();
var barXOffset = 0;
- var activeSeriesCount = graph.series.filter( function(s) { return !s.disabled } ).length;
+ var activeSeriesCount = graph.series.filter( function(s) { return !s.disabled; } ).length;
var seriesBarWidth = this.unstack ? barWidth / activeSeriesCount : barWidth;
graph.series.forEach( function(series) {
@@ -1572,80 +1783,49 @@ Rickshaw.Graph.Renderer.Bar = function(args) {
n.setAttribute('fill', series.color);
} );
- if (self.unstack) barXOffset += seriesBarWidth;
+ if (this.unstack) barXOffset += seriesBarWidth;
- } );
+ }, this );
}
+} );
- this._styleSeries = function(series) {
- if (!series.path) return;
- series.path.setAttribute('fill', series.color);
- series.path.setAttribute('stroke-width', 2);
- series.path.setAttribute('class', series.className);
- }
-}
Rickshaw.namespace('Rickshaw.Graph.Renderer.Area');
-Rickshaw.Graph.Renderer.Area = function(args) {
+Rickshaw.Graph.Renderer.Area = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var graph = this.graph = args.graph;
- var self = this;
+ name: 'area',
+ unstack: false,
- this.tension = 0.8;
- this.strokeWidth = 2;
- this.yBerth = 1.025;
+ seriesPathFactory: function() {
- this.name = 'area';
-
- this.unstack = false;
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
-
- this.seriesPathFactory = function() {
+ var graph = this.graph;
return d3.svg.area()
.x( function(d) { return graph.x(d.x) } )
.y0( function(d) { return graph.y(d.y0) } )
- .y1( function(d) { return graph.y(d.y + d.y0)} )
- .interpolate(this.graph.interpolation).tension(this.tension)
- }
+ .y1( function(d) { return graph.y(d.y + d.y0) } )
+ .interpolate(graph.interpolation).tension(this.tension);
+ },
- this.seriesLineFactory = function() {
+ seriesStrokeFactory: function() {
+
+ var graph = this.graph;
return d3.svg.line()
.x( function(d) { return graph.x(d.x) } )
- .y( function(d) { return graph.y(d.y + d.y0)} )
- .interpolate(this.graph.interpolation).tension(this.tension)
- }
-
- this.domain = function() {
-
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
-
- var topSeriesData = this.unstack ? stackedData : [ stackedData.slice(-1).shift() ];
-
- topSeriesData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y + d.y0 );
- } );
- } );
-
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
+ .y( function(d) { return graph.y(d.y + d.y0) } )
+ .interpolate(graph.interpolation).tension(this.tension);
+ },
- var yMin = 0;
- var yMax = d3.max( values ) * this.yBerth;
+ render: function() {
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
-
- this.render = function() {
+ var graph = this.graph;
graph.vis.selectAll('*').remove();
var nodes = graph.vis.selectAll("path")
- .data(graph.stackedData)
- .enter().insert("svg:g", 'g')
+ .data(this.graph.stackedData)
+ .enter().insert("svg:g", 'g');
nodes.append("svg:path")
.attr("d", this.seriesPathFactory())
@@ -1653,7 +1833,7 @@ Rickshaw.Graph.Renderer.Area = function(args) {
if (this.graph.stroke) {
nodes.append("svg:path")
- .attr("d", this.seriesLineFactory())
+ .attr("d", this.seriesStrokeFactory())
.attr("class", 'line');
}
@@ -1661,11 +1841,11 @@ Rickshaw.Graph.Renderer.Area = function(args) {
graph.series.forEach( function(series) {
if (series.disabled) return;
series.path = nodes[0][i++];
- self._styleSeries(series);
- } );
- }
+ this._styleSeries(series);
+ }, this );
+ },
- this._styleSeries = function(series) {
+ _styleSeries: function(series) {
if (!series.path) return;
@@ -1683,75 +1863,47 @@ Rickshaw.Graph.Renderer.Area = function(args) {
series.path.setAttribute('class', series.className);
}
}
-}
+} );
+
Rickshaw.namespace('Rickshaw.Graph.Renderer.ScatterPlot');
-Rickshaw.Graph.Renderer.ScatterPlot = function(args) {
+Rickshaw.Graph.Renderer.ScatterPlot = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var graph = this.graph = args.graph;
- var self = this;
+ name: 'scatterplot',
+ unstack: true,
+ fill: true,
+ stroke: false,
+ padding: { top: 0.025, right: 0.025, bottom: 0, left: 0.025 },
- this.name = 'scatterplot';
- this.unstack = true;
+ initialize: function($super, args) {
+ $super(args);
this.dotSize = args.dotSize || 4;
+ },
- this.xBerth = 1.0125;
- this.yBerth = 1.0125;
-
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
-
- this.domain = function() {
-
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
-
- stackedData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y )
- } );
- } );
-
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
-
- xMin -= (xMax - xMin) * (this.xBerth - 1);
- xMax += (xMax - xMin) * (this.xBerth - 1);
-
- var yMin = 0;
- var yMax = d3.max( values ) * this.yBerth;
-
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
-
- this.render = function() {
+ render: function() {
- graph.vis.selectAll('*').remove();
+ var graph = this.graph;
- graph.series.forEach( function(series) {
+ graph.vis.selectAll('*').remove();
- if (series.disabled) return;
+ graph.series.forEach( function(series) {
- var nodes = graph.vis.selectAll("path")
- .data(series.stack)
- .enter().append("svg:circle")
- .attr("cx", function(d) { return graph.x(d.x) })
- .attr("cy", function(d) { return graph.y(d.y) })
- .attr("r", this.dotSize);
+ if (series.disabled) return;
- Array.prototype.forEach.call(nodes[0], function(n) {
- n.setAttribute('fill', series.color);
- } );
+ var nodes = graph.vis.selectAll("path")
+ .data(series.stack)
+ .enter().append("svg:circle")
+ .attr("cx", function(d) { return graph.x(d.x) })
+ .attr("cy", function(d) { return graph.y(d.y) })
+ .attr("r", this.dotSize);
- }, this );
- }
+ Array.prototype.forEach.call(nodes[0], function(n) {
+ n.setAttribute('fill', series.color);
+ } );
- this._styleSeries = function(series) {
- if (!series.path) return;
- series.path.setAttribute('fill', series.color);
- series.path.setAttribute('stroke-width', 2);
- series.path.setAttribute('class', series.className);
- }
-}
+ }, this );
+ }
+} );
Rickshaw.namespace('Rickshaw.Graph.Smoother');
Rickshaw.Graph.Smoother = function(args) {
@@ -1841,138 +1993,137 @@ Rickshaw.Graph.Unstacker = function(args) {
return data;
}
} );
-}
+};
Rickshaw.namespace('Rickshaw.Series');
-Rickshaw.Series = function(data, palette, options) {
+Rickshaw.Series = Rickshaw.Class.create( Array, {
- this.initialize(data, palette, options);
-}
+ initialize: function (data, palette, options) {
-Rickshaw.Series.prototype = new Array;
+ options = options || {}
-Rickshaw.Series.prototype.constructor = Rickshaw.Series;
+ this.palette = new Rickshaw.Color.Palette(palette);
-Rickshaw.Series.prototype.initialize = function (data, palette, options) {
- var self = this;
- options = options || {}
+ this.timeBase = typeof(options.timeBase) === 'undefined' ?
+ Math.floor(new Date().getTime() / 1000) :
+ options.timeBase;
- self.palette = new Rickshaw.Color.Palette(palette);
- self.timeBase = typeof(options.timeBase) === 'undefined' ? Math.floor(new Date().getTime() / 1000) : options.timeBase;
+ if (data && (typeof(data) == "object") && (data instanceof Array)) {
+ data.forEach( function(item) { this.addItem(item) }, this );
+ }
+ },
- if (data && (typeof(data) == "object") && (data instanceof Array)) {
- data.forEach( function (item) { self.addItem(item) } );
- }
-}
+ addItem: function(item) {
-Rickshaw.Series.prototype.addItem = function(item) {
- var self = this;
- if (typeof(item.name) === 'undefined') {
- throw('addItem() needs a name');
- }
+ if (typeof(item.name) === 'undefined') {
+ throw('addItem() needs a name');
+ }
- item.color = (item.color || self.palette.color(item.name));
- item.data = (item.data || []);
+ item.color = (item.color || this.palette.color(item.name));
+ item.data = (item.data || []);
- // backfill, if necessary
- if ((item.data.length == 0) && (self.getIndex() > 0)) {
- self[0].data.forEach( function (plot) {
- item.data.push({ x: plot.x, y: 0 });
- } );
- } else {
- // otherwise add a first plot
- console.log(self.timeBase);
- item.data.push({ x: self.timeBase, y: 0 });
- }
+ // backfill, if necessary
+ if ((item.data.length == 0) && this.length && (this.getIndex() > 0)) {
+ this[0].data.forEach( function(plot) {
+ item.data.push({ x: plot.x, y: 0 });
+ } );
+ } else if (item.data.length == 0) {
+ item.data.push({ x: this.timeBase - (this.timeInterval || 0), y: 0 });
+ }
- self.push(item);
+ this.push(item);
- if (self.legend) {
- self.legend.addLine(self.itemByName(item.name));
- }
-}
+ if (this.legend) {
+ this.legend.addLine(this.itemByName(item.name));
+ }
+ },
-Rickshaw.Series.prototype.addData = function(data) {
- var self = this;
- var index = this.getIndex();
+ addData: function(data) {
- Rickshaw.keys(data).forEach( function (name) {
- if (! self.itemByName(name)) {
- self.addItem({ name: name });
- }
- } );
+ var index = this.getIndex();
- self.forEach( function (item) {
- item.data.push({ x: (index * self.timeInterval || 1) + self.timeBase, y: (data[item.name] || 0) });
- } );
-}
+ Rickshaw.keys(data).forEach( function(name) {
+ if (! this.itemByName(name)) {
+ this.addItem({ name: name });
+ }
+ }, this );
-Rickshaw.Series.prototype.getIndex = function () {
- var self = this;
- return (self[0] && self[0].data && self[0].data.length) ? self[0].data.length : 0;
-}
+ this.forEach( function(item) {
+ item.data.push({
+ x: (index * this.timeInterval || 1) + this.timeBase,
+ y: (data[item.name] || 0)
+ });
+ }, this );
+ },
-Rickshaw.Series.prototype.itemByName = function (name) {
- var self = this;
- var ret;
- self.forEach( function (item) {
- if (item.name == name) { ret = item }
- } );
- return ret;
-}
+ getIndex: function () {
+ return (this[0] && this[0].data && this[0].data.length) ? this[0].data.length : 0;
+ },
-Rickshaw.Series.prototype.setTimeInterval = function (iv) {
- this.timeInterval = parseInt(iv/1000);
-}
+ itemByName: function(name) {
-Rickshaw.Series.prototype.setTimeBase = function (t) {
- this.timeBase = t;
-}
+ for (var i = 0; i < this.length; i++) {
+ if (this[i].name == name)
+ return this[i];
+ }
+ },
-Rickshaw.Series.prototype.dump = function () {
- var self = this;
- var data = {
- timeBase: self.timeBase,
- timeInterval: self.timeInterval,
- items: [],
- };
- self.forEach( function (item) {
- var newItem = {
- color: item.color,
- name: item.name,
- data: []
+ setTimeInterval: function(iv) {
+ this.timeInterval = iv / 1000;
+ },
+
+ setTimeBase: function (t) {
+ this.timeBase = t;
+ },
+
+ dump: function() {
+
+ var data = {
+ timeBase: this.timeBase,
+ timeInterval: this.timeInterval,
+ items: [],
};
- item.data.forEach( function (plot) {
- newItem.data.push({ x: plot.x, y: plot.y });
+ this.forEach( function(item) {
+
+ var newItem = {
+ color: item.color,
+ name: item.name,
+ data: []
+ };
+
+ item.data.forEach( function(plot) {
+ newItem.data.push({ x: plot.x, y: plot.y });
+ } );
+
+ data.items.push(newItem);
} );
- data.items.push(newItem);
- } );
- return data;
-}
+ return data;
+ },
-Rickshaw.Series.prototype.load = function (data) {
- var self = this;
- if (data.timeInterval) {
- self.timeInterval = data.timeInterval;
- }
+ load: function(data) {
- if (data.timeBase) {
- self.timeBase = data.timeBase;
- }
+ if (data.timeInterval) {
+ this.timeInterval = data.timeInterval;
+ }
- if (data.items) {
- data.items.forEach( function (item) {
- self.push(item);
+ if (data.timeBase) {
+ this.timeBase = data.timeBase;
+ }
- if (self.legend) {
- self.legend.addLine(self.itemByName(item.name));
- }
- } );
+ if (data.items) {
+ data.items.forEach( function(item) {
+ this.push(item);
+ if (this.legend) {
+ this.legend.addLine(this.itemByName(item.name));
+ }
+
+ }, this );
+ }
}
-}
+} );
Rickshaw.Series.zeroFill = function(series) {
@@ -1998,3 +2149,83 @@ Rickshaw.Series.zeroFill = function(series) {
i++;
}
};
+Rickshaw.namespace('Rickshaw.Series.FixedDuration');
+
+Rickshaw.Series.FixedDuration = Rickshaw.Class.create(Rickshaw.Series, {
+
+ initialize: function (data, palette, options) {
+
+ var options = options || {}
+
+ if (typeof(options.timeInterval) === 'undefined') {
+ throw new Error('FixedDuration series requires timeInterval');
+ }
+
+ if (typeof(options.maxDataPoints) === 'undefined') {
+ throw new Error('FixedDuration series requires maxDataPoints');
+ }
+
+ this.palette = new Rickshaw.Color.Palette(palette);
+ this.timeBase = typeof(options.timeBase) === 'undefined' ? Math.floor(new Date().getTime() / 1000) : options.timeBase;
+ this.setTimeInterval(options.timeInterval);
+
+ if (this[0] && this[0].data && this[0].data.length) {
+ this.currentSize = this[0].data.length;
+ this.currentIndex = this[0].data.length;
+ } else {
+ this.currentSize = 0;
+ this.currentIndex = 0;
+ }
+
+ this.maxDataPoints = options.maxDataPoints;
+
+
+ if (data && (typeof(data) == "object") && (data instanceof Array)) {
+ data.forEach( function (item) { this.addItem(item) }, this );
+ this.currentSize += 1;
+ this.currentIndex += 1;
+ }
+
+ // reset timeBase for zero-filled values if needed
+ this.timeBase -= (this.maxDataPoints - this.currentSize) * this.timeInterval;
+
+ // zero-fill up to maxDataPoints size if we don't have that much data yet
+ if ((typeof(this.maxDataPoints) !== 'undefined') && (this.currentSize < this.maxDataPoints)) {
+ for (var i = this.maxDataPoints - this.currentSize - 1; i > 0; i--) {
+ this.currentSize += 1;
+ this.currentIndex += 1;
+ this.forEach( function (item) {
+ item.data.unshift({ x: ((i-1) * this.timeInterval || 1) + this.timeBase, y: 0, i: i });
+ }, this );
+ }
+ }
+ },
+
+ addData: function($super, data) {
+
+ $super(data)
+
+ this.currentSize += 1;
+ this.currentIndex += 1;
+
+ if (this.maxDataPoints !== undefined) {
+ while (this.currentSize > this.maxDataPoints) {
+ this.dropData();
+ }
+ }
+ },
+
+ dropData: function() {
+
+ this.forEach(function(item) {
+ item.data.splice(0, 1);
+ } );
+
+ this.currentSize -= 1;
+ },
+
+ getIndex: function () {
+ return this.currentIndex;
+ }
+} );
+
2  rickshaw.min.js
View
@@ -1 +1 @@
-Rickshaw={namespace:function(a,b){var c=a.split("."),d=typeof global!="undefined"?global:window,e=d.Rickshaw;for(var f=1,g=c.length;f<g;f++)currentPart=c[f],e[currentPart]=e[currentPart]||{},e=e[currentPart];return e},keys:function(a){var b=[];for(var c in a)b.push(c);return b}},Rickshaw.namespace("Rickshaw.Compat.ClassList"),Rickshaw.Compat.ClassList=function(){typeof document!="undefined"&&!("classList"in document.createElement("a"))&&function(a){"use strict";var b="classList",c="prototype",d=(a.HTMLElement||a.Element)[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){var b=0,c=this.length;for(;b<c;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(b==="")throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){var b=f.call(a.className),c=b?b.split(/\s+/):[],d=0,e=c.length;for(;d<e;d++)this.push(c[d]);this._updateClassName=function(){a.className=this.toString()}},k=j[c]=[],l=function(){return new j(this)};h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",i(this,a)!==-1},k.add=function(a){a+="",i(this,a)===-1&&(this.push(a),this._updateClassName())},k.remove=function(a){a+="";var b=i(this,a);b!==-1&&(this.splice(b,1),this._updateClassName())},k.toggle=function(a){a+="",i(this,a)===-1?this.add(a):this.remove(a)},k.toString=function(){return this.join(" ")};if(e.defineProperty){var m={get:l,enumerable:!0,configurable:!0};try{e.defineProperty(d,b,m)}catch(n){n.number===-2146823252&&(m.enumerable=!1,e.defineProperty(d,b,m))}}else e[c].__defineGetter__&&d.__defineGetter__(b,l)}(self)},(typeof RICKSHAW_NO_COMPAT!="undefined"&&!RICKSHAW_NO_COMPAT||typeof RICKSHAW_NO_COMPAT=="undefined")&&new Rickshaw.Compat.ClassList,Rickshaw.namespace("Rickshaw.Graph"),Rickshaw.Graph=function(a){this.element=a.element,this.interpolation=a.interpolation||"cardinal",this.series=a.series,this.offset="zero",this.stroke=a.stroke||!1;var b=window.getComputedStyle(this.element,null),c=parseInt(b.getPropertyValue("width")),d=parseInt(b.getPropertyValue("height"));this.width=a.width||c||400,this.height=a.height||d||250,this.window={},this.updateCallbacks=[];var e=this;this.initialize=function(a){this.validateSeries(a.series),this.series.active=function(){return e.series.filter(function(a){return!a.disabled})},this.element.classList.add("rickshaw_graph"),this.vis=d3.select(this.element).append("svg:svg").attr("width",this.width).attr("height",this.height);var b=[Rickshaw.Graph.Renderer.Stack,Rickshaw.Graph.Renderer.Line,Rickshaw.Graph.Renderer.Bar,Rickshaw.Graph.Renderer.Area,Rickshaw.Graph.Renderer.ScatterPlot];b.forEach(function(a){if(!a)return;e.registerRenderer(new a({graph:e}))}),this.setRenderer(a.renderer||"stack"),this.discoverRange()},this.validateSeries=function(a){if(!(a instanceof Array||a instanceof Rickshaw.Series)){var b=Object.prototype.toString.apply(a);throw"series is not an array: "+b}var c;a.forEach(function(a){if(!(a instanceof Object))throw"series element is not an object: "+a;if(!a.data)throw"series has no data: "+JSON.stringify(a);if(!(a.data instanceof Array))throw"series data is not an array: "+JSON.stringify(a.data);c=c||a.data.length;if(c&&a.data.length!=c)throw"series cannot have differing numbers of points: "+c+" vs "+a.data.length+"; see Rickshaw.Series.zeroFill()";var b=typeof a.data[0].x,d=typeof a.data[0].y;if(b!="number"||d!="number")throw"x and y properties of points should be numbers instead of "+b+" and "+d})},this.dataDomain=function(){var a=this.series[0].data;return[a[0].x,a.slice(-1).shift().x]},this.discoverRange=function(){var a=this.renderer.domain();this.x=d3.scale.linear().domain(a.x).range([0,this.width]),this.y=d3.scale.linear().domain(a.y).range([this.height,0]),this.y.magnitude=d3.scale.linear().domain(a.y).range([0,this.height])},this.render=function(){var a=this.stackData();this.discoverRange(),this.renderer.render(),this.updateCallbacks.forEach(function(a){a()})},this.update=this.render,this.stackData=function(){var a=this.series.active().map(function(a){return a.data}).map(function(a){return a.filter(function(a){return this._slice(a)},this)},this);this.stackData.hooks.data.forEach(function(b){a=b.f.apply(e,[a])});var b=d3.layout.stack();b.offset(e.offset);var c=b(a);this.stackData.hooks.after.forEach(function(b){c=b.f.apply(e,[a])});var d=0;return this.series.forEach(function(a){if(a.disabled)return;a.stack=c[d++]}),this.stackedData=c,c},this.stackData.hooks={data:[],after:[]},this._slice=function(a){if(this.window.xMin||this.window.xMax){var b=!0;return this.window.xMin&&a.x<=this.window.xMin&&(b=!1),this.window.xMax&&a.x>=this.window.xMax&&(b=!1),b}return!0},this.onUpdate=function(a){this.updateCallbacks.push(a)},this.registerRenderer=function(a){this._renderers=this._renderers||{},this._renderers[a.name]=a},this.setRenderer=function(a){if(!this._renderers[a])throw"couldn't find renderer "+a;this.renderer=this._renderers[a]},this.initialize(a)},Rickshaw.namespace("Rickshaw.Fixtures.Color"),Rickshaw.Fixtures.Color=function(){this.schemes={},this.schemes.spectrum14=["#ecb796","#dc8f70","#b2a470","#92875a","#716c49","#d2ed82","#bbe468","#a1d05d","#e7cbe6","#d8aad6","#a888c2","#9dc2d3","#649eb9","#387aa3"].reverse(),this.schemes.spectrum2000=["#57306f","#514c76","#646583","#738394","#6b9c7d","#84b665","#a7ca50","#bfe746","#e2f528","#fff726","#ecdd00","#d4b11d","#de8800","#de4800","#c91515","#9a0000","#7b0429","#580839","#31082b"],this.schemes.spectrum2001=["#2f243f","#3c2c55","#4a3768","#565270","#6b6b7c","#72957f","#86ad6e","#a1bc5e","#b8d954","#d3e04e","#ccad2a","#cc8412","#c1521d","#ad3821","#8a1010","#681717","#531e1e","#3d1818","#320a1b"],this.schemes.classic9=["#423d4f","#4a6860","#848f39","#a2b73c","#ddcb53","#c5a32f","#7d5836","#963b20","#7c2626","#491d37","#2f254a"].reverse(),this.schemes.httpStatus={503:"#ea5029",502:"#d23f14",500:"#bf3613",410:"#efacea",409:"#e291dc",403:"#f457e8",408:"#e121d2",401:"#b92dae",405:"#f47ceb",404:"#a82a9f",400:"#b263c6",301:"#6fa024",302:"#87c32b",307:"#a0d84c",304:"#28b55c",200:"#1a4f74",206:"#27839f",201:"#52adc9",202:"#7c979f",203:"#a5b8bd",204:"#c1cdd1"},this.schemes.colorwheel=["#b5b6a9","#858772","#785f43","#96557e","#4682b4","#65b9ac","#73c03a","#cb513a"].reverse(),this.schemes.cool=["#5e9d2f","#73c03a","#4682b4","#7bc3b8","#a9884e","#c1b266","#a47493","#c09fb5"]},Rickshaw.namespace("Rickshaw.Fixtures.RandomData"),Rickshaw.Fixtures.RandomData=function(a){var b;a=a||1;var c=200,d=Math.floor((new Date).getTime()/1e3);this.addData=function(b){var e=Math.random()*100+15+c,f=b[0].length,g=1;b.forEach(function(b){var c=Math.random()*20,h=e/25+g++ +(Math.cos(f*g*11/960)+2)*15+(Math.cos(f/7)+2)*7+(Math.cos(f/17)+2)*1;b.push({x:f*a+d,y:h+c})}),c=e*.85}},Rickshaw.namespace("Rickshaw.Fixtures.Time"),Rickshaw.Fixtures.Time=function(){var a=(new Date).getTimezoneOffset()*60,b=this;this.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.units=[{name:"decade",seconds:315576e3,formatter:function(a){return parseInt(a.getUTCFullYear()/10)*10}},{name:"year",seconds:31557600,formatter:function(a){return a.getUTCFullYear()}},{name:"month",seconds:2635200,formatter:function(a){return b.months[a.getUTCMonth()]}},{name:"week",seconds:604800,formatter:function(a){return b.formatDate(a)}},{name:"day",seconds:86400,formatter:function(a){return a.getUTCDate()}},{name:"6 hour",seconds:21600,formatter:function(a){return b.formatTime(a)}},{name:"hour",seconds:3600,formatter:function(a){return b.formatTime(a)}},{name:"15 minute",seconds:900,formatter:function(a){return b.formatTime(a)}},{name:"minute",seconds:60,formatter:function(a){return a.getUTCMinutes()}},{name:"15 second",seconds:15,formatter:function(a){return a.getUTCSeconds()+"s"}},{name:"second",seconds:1,formatter:function(a){return a.getUTCSeconds()+"s"}}],this.unit=function(a){return this.units.filter(function(b){return a==b.name}).shift()},this.formatDate=function(a){return a.toUTCString().match(/, (\w+ \w+ \w+)/)[1]},this.formatTime=function(a){return a.toUTCString().match(/(\d+:\d+):/)[1]},this.ceil=function(a,b){if(b.name=="month"){var c=new Date((a+b.seconds-1)*1e3);return(new Date(c.getUTCFullYear(),c.getUTCMonth()+1,1,0,0,0,0)).getTime()/1e3}if(b.name=="year"){var c=new Date((a+b.seconds-1)*1e3);return(new Date(c.getUTCFullYear(),1,1,0,0,0,0)).getTime()/1e3}return Math.ceil(a/b.seconds)*b.seconds}},Rickshaw.namespace("Rickshaw.Fixtures.Number"),Rickshaw.Fixtures.Number.formatKMBT=function(a){return a>=1e12?a/1e12+"T":a>=1e9?a/1e9+"B":a>=1e6?a/1e6+"M":a>=1e3?a/1e3+"K":a<1&&a>0?a.toFixed(2):a==0?"":a},Rickshaw.namespace("Rickshaw.Color.Palette"),Rickshaw.Color.Palette=function(a){var b=new Rickshaw.Fixtures.Color;a=a||{},this.schemes={},this.scheme=b.schemes[a.scheme]||a.scheme||b.schemes.colorwheel,this.runningIndex=0,this.color=function(a){return this.scheme[a]||this.scheme[this.runningIndex++]||"#808080"}},Rickshaw.namespace("Graph.Ajax"),Rickshaw.Graph.Ajax=function(args){var self=this;this.dataURL=args.dataURL,$.ajax({url:this.dataURL,complete:function(response,status){status==="error"&&console.log("error loading dataURL: "+this.dataURL);var data=eval("("+response.responseText+")");if(typeof args.onData=="function"){var processedData=args.onData(data);data=processedData}args.series?args.series.forEach(function(a){var b=a.key||a.name;if(!b)throw"series needs a key or a name";data.forEach(function(c){var d=c.key||c.name;if(!d)throw"data needs a key or a name";if(b==d){var e=["color","name","data"];e.forEach(function(b){a[b]=a[b]||c[b]})}})}):args.series=data,self.graph=new Rickshaw.Graph(args),self.graph.render(),typeof args.onComplete=="function"&&args.onComplete(self)}})},Rickshaw.namespace("Rickshaw.Graph.Annotate"),Rickshaw.Graph.Annotate=function(a){var b=this.graph=a.graph;this.elements={timeline:a.element};var c=this;this.data={},this.elements.timeline.classList.add("rickshaw_annotation_timeline"),this.add=function(a,b){c.data[a]=c.data[a]||{boxes:[]},c.data[a].boxes.push({content:b})},this.update=function(){for(var a in c.data){var b=c.data[a],d=c.graph.x(a);if(d>c.graph.x.range()[1]){b.element&&(b.element.style.display="none");continue}if(!b.element){var e=b.element=document.createElement("div");e.classList.add("annotation"),this.elements.timeline.appendChild(e),e.addEventListener("click",function(a){e.classList.toggle("active"),b.line.classList.toggle("active")},!1)}b.element.style.left=d+"px",b.element.style.display="block",b.boxes.forEach(function(a){var e=a.element;e||(e=a.element=document.createElement("div"),e.classList.add("content"),e.innerHTML=a.content,b.element.appendChild(e),b.line=document.createElement("div"),b.line.classList.add("annotation_line"),c.graph.element.appendChild(b.line)),b.line.style.left=d+"px"})}},this.graph.onUpdate(function(){c.update()})},Rickshaw.namespace("Rickshaw.Graph.Axis.Time"),Rickshaw.Graph.Axis.Time=function(a){var b=this;this.graph=a.graph,this.elements=[],this.ticksTreatment=a.ticksTreatment||"plain",this.fixedTimeUnit=a.timeUnit;var c=new Rickshaw.Fixtures.Time;this.appropriateTimeUnit=function(){var a,b=c.units,d=this.graph.x.domain(),e=d[1]-d[0];return b.forEach(function(b){Math.floor(e/b.seconds)>=2&&(a=a||b)}),a||c.units[c.units.length-1]},this.tickOffsets=function(){var a=this.graph.x.domain(),b=this.fixedTimeUnit||this.appropriateTimeUnit(),d=Math.ceil((a[1]-a[0])/b.seconds),e=a[0],f=[];for(var g=0;g<d;g++)tickValue=c.ceil(e,b),e=tickValue+b.seconds/2,f.push({value:tickValue,unit:b});return f},this.render=function(){this.elements.forEach(function(a){a.parentNode.removeChild(a)}),this.elements=[];var a=this.tickOffsets();a.forEach(function(a){if(b.graph.x(a.value)>b.graph.x.range()[1])return;var c=document.createElement("div");c.style.left=b.graph.x(a.value)+"px",c.classList.add("x_tick"),c.classList.add(b.ticksTreatment);var d=document.createElement("div");d.classList.add("title"),d.innerHTML=a.unit.formatter(new Date(a.value*1e3)),c.appendChild(d),b.graph.element.appendChild(c),b.elements.push(c)})},this.graph.onUpdate(function(){b.render()})},Rickshaw.namespace("Rickshaw.Graph.Axis.Y"),Rickshaw.Graph.Axis.Y=function(a){var b=this;this.graph=a.graph,this.orientation=a.orientation||"right";var c=75;this.ticks=a.ticks||Math.floor(this.graph.height/c),this.tickSize=a.tickSize||4,this.ticksTreatment=a.ticksTreatment||"plain";if(a.element){var d=.1;if(!a.width||!a.height)var e=window.getComputedStyle(a.element,null),f=parseInt(e.getPropertyValue("width")),g=parseInt(e.getPropertyValue("height"));this.width=a.width||f||this.graph.width*d,this.height=a.height||g||this.graph.height,this.vis=d3.select(a.element).append("svg:svg").attr("class","rickshaw_graph y_axis").attr("width",this.width).attr("height",this.height*(1+d)),this.element=this.vis[0][0],this.element.style.position="relative";var h=this.height*d;this.element.style.top=-1*h+"px",this.element.style.paddingTop=h+"px"}else this.vis=this.graph.vis;this.render=function(){var b=d3.svg.axis().scale(this.graph.y).orient(this.orientation);b.tickFormat(a.tickFormat||function(a){return a});if(this.orientation=="left")var c="translate("+this.width+", 0)";this.element&&this.vis.selectAll("*").remove(),this.vis.append("svg:g").attr("class",["y_ticks",this.ticksTreatment].join(" ")).attr("transform",c).call(b.ticks(this.ticks).tickSubdivide(0).tickSize(this.tickSize));var d=(this.orientation=="right"?1:-1)*this.graph.width;this.graph.vis.append("svg:g").attr("class","y_grid").call(b.ticks(this.ticks).tickSubdivide(0).tickSize(d))},this.graph.onUpdate(function(){b.render()})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Highlight"),Rickshaw.Graph.Behavior.Series.Highlight=function(a){this.graph=a.graph,this.legend=a.legend;var b=this,c={};this.addHighlightEvents=function(a){a.element.addEventListener("mouseover",function(d){b.legend.lines.forEach(function(b){if(a===b)return;c[b.series.name]=c[b.series.name]||b.series.color,b.series.color=d3.interpolateRgb(b.series.color,d3.rgb("#d8d8d8"))(.8).toString()}),b.graph.update()},!1),a.element.addEventListener("mouseout",function(a){b.legend.lines.forEach(function(a){c[a.series.name]&&(a.series.color=c[a.series.name])}),b.graph.update()},!1)},this.legend&&this.legend.lines.forEach(function(a){b.addHighlightEvents(a)})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Order"),Rickshaw.Graph.Behavior.Series.Order=function(a){this.graph=a.graph,this.legend=a.legend;var b=this;$(function(){$(b.legend.list).sortable({containment:"parent",tolerance:"pointer",update:function(a,c){var d=[];$(b.legend.list).find("li").each(function(a,b){if(!b.series)return;d.push(b.series)});for(var e=b.graph.series.length-1;e>=0;e--)b.graph.series[e]=d.shift();b.graph.update()}}),$(b.legend.list).disableSelection()}),this.graph.onUpdate(function(){var a=window.getComputedStyle(b.legend.element).height;b.legend.element.style.height=a})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Toggle"),Rickshaw.Graph.Behavior.Series.Toggle=function(a){this.graph=a.graph,this.legend=a.legend;var b=this;this.addAnchor=function(a){var b=document.createElement("a");b.innerHTML="&#10004;",b.classList.add("action"),a.element.insertBefore(b,a.element.firstChild),b.onclick=function(b){a.series.disabled?(a.series.enable(),a.element.classList.remove("disabled")):(a.series.disable(),a.element.classList.add("disabled"))}},this.legend&&this.legend.lines.forEach(function(a){b.addAnchor(a)}),this._addBehavior=function(){this.graph.series.forEach(function(a){a.disable=function(){if(b.graph.series.length<=1)throw"only one series left";a.disabled=!0,b.graph.update()},a.enable=function(){a.disabled=!1,b.graph.update()}})},this._addBehavior(),this.updateBehaviour=function(){this._addBehavior()}},Rickshaw.namespace("Rickshaw.Graph.HoverDetail"),Rickshaw.Graph.HoverDetail=function(a){var b=this.graph=a.graph,c=this.element=document.createElement("div");c.className="detail",this.visible=!0,b.element.appendChild(c);var d=this;this.lastEvent=null,this.update=function(a){a=a||this.lastEvent;if(!a)return;this.lastEvent=a;if(a.target.nodeName!="path"&&a.target.nodeName!="svg")return;var c=a.offsetX||a.layerX,e=a.offsetY||a.layerY,f=b.x.invert(c),g=b.stackedData,h=g.slice(-1).shift(),i=d3.scale.linear().domain([h[0].x,h.slice(-1).shift().x]).range([0,h.length]),j=Math.floor(i(f)),k=j||0;for(var l=j;l<g[0].length-1;){if(g[0][l].x<=f&&g[0][l+1].x>f){k=l;break}g[0][l+1]<f?l++:l--}f=g[0][k].x;var m=b.series.active().map(function(a){return{name:a.name,value:a.stack[k]}});this.visible&&d.render.call(d,f,m,c,e)},this.xFormatter=function(a){return(new Date(a*1e3)).toUTCString()},this.graph.element.addEventListener("mousemove",function(a){d.visible=!0,d.update(a)},!1),this.graph.onUpdate(function(){d.update()}),this.graph.element.addEventListener("mouseout",function(a){a.relatedTarget&&!(a.relatedTarget.compareDocumentPosition(d.graph.element)&Node.DOCUMENT_POSITION_CONTAINS)&&d.hide()},!1),this.hide=function(){this.visible=!1,this.element.classList.add("inactive")},this.show=function(){this.visible=!0,this.element.classList.remove("inactive")},this.render=function(a,c,d,e){this.element.innerHTML="",this.element.style.left=b.x(a)+"px";var f=document.createElement("div");f.className="x_label",f.innerHTML=this.xFormatter(a),this.element.appendChild(f);var g=null,h=function(a,b){return a.value.y0+a.value.y-(b.value.y0+b.value.y)};c.sort(h).forEach(function(a){var c=document.createElement("div");c.className="item",c.innerHTML=a.name+":&nbsp;"+a.value.y.toFixed(2),c.style.top=b.y(a.value.y0+a.value.y)+"px";var d=b.y.magnitude.invert(b.element.offsetHeight-e);this.element.appendChild(c);var f=document.createElement("div");f.className="dot",f.style.top=c.style.top,this.element.appendChild(f),d>a.value.y0&&d<a.value.y0+a.value.y&&!g&&(g=c,c.className="item active",f.className="dot active")},this),this.show()}},Rickshaw.namespace("Rickshaw.Graph.JSONP"),Rickshaw.Graph.JSONP=function(a){var b=this;this.dataURL=a.dataURL,$.ajax({url:this.dataURL,dataType:"jsonp",success:function(c,d,e){d==="error"&&console.log("error loading dataURL: "+this.dataURL);if(typeof a.onData=="function"){var f=a.onData(c);c=f}a.series?a.series.forEach(function(a){var b=a.key||a.name;if(!b)throw"series needs a key or a name";c.forEach(function(c){var d=c.key||c.name;if(!d)throw"data needs a key or a name";if(b==d){var e=["color","name","data"];e.forEach(function(b){a[b]=a[b]||c[b]})}})}):a.series=c,b.graph=new Rickshaw.Graph(a),b.graph.render(),typeof a.onComplete=="function"&&a.onComplete(b)}})},Rickshaw.namespace("Rickshaw.Graph.Legend"),Rickshaw.Graph.Legend=function(a){var b=this.element=a.element,c=this.graph=a.graph,d=this;b.classList.add("rickshaw_legend");var e=this.list=document.createElement("ul");b.appendChild(e);var f=c.series.map(function(a){return a}).reverse();this.lines=[],this.addLine=function(a){var b=document.createElement("li");b.className="line";var c=document.createElement("div");c.className="swatch",c.style.backgroundColor=a.color,b.appendChild(c);var f=document.createElement("span");f.className="label",f.innerHTML=a.name,b.appendChild(f),e.appendChild(b),b.series=a,a.noLegend&&(b.style.display="none");var g={element:b,series:a};d.shelving&&(d.shelving.addAnchor(g),d.shelving.updateBehaviour()),d.highlighter&&d.highlighter.addHighlightEvents(g),d.lines.push(g)},f.forEach(function(a){d.addLine(a)}),c.onUpdate(function(){})},Rickshaw.namespace("Rickshaw.Graph.RangeSlider"),Rickshaw.Graph.RangeSlider=function(a){var b=this.element=a.element,c=this.graph=a.graph;$(function(){$(b).slider({range:!0,min:c.dataDomain()[0],max:c.dataDomain()[1],values:[c.dataDomain()[0],c.dataDomain()[1]],slide:function(a,b){c.window.xMin=b.values[0],c.window.xMax=b.values[1],c.update(),c.dataDomain()[0]==b.values[0]&&(c.window.xMin=undefined),c.dataDomain()[1]==b.values[1]&&(c.window.xMax=undefined)}})}),b[0].style.width=c.width+"px",c.onUpdate(function(){var a=$(b).slider("option","values");$(b).slider("option","min",c.dataDomain()[0]),$(b).slider("option","max",c.dataDomain()[1]),c.window.xMin==undefined&&(a[0]=c.dataDomain()[0]),c.window.xMax==undefined&&(a[1]=c.dataDomain()[1]),$(b).slider("option","values",a)})},Rickshaw.namespace("Rickshaw.Graph.Renderer.Line"),Rickshaw.Graph.Renderer.Line=function(a){var b=this.graph=a.graph,c=this;this.name="line",this.unstack=!0,b.unstacker=b.unstacker||new Rickshaw.Graph.Unstacker({graph:b}),this.seriesPathFactory=function(){return d3.svg.line().x(function(a){return b.x(a.x)}).y(function(a){return b.y(a.y)}).interpolate(this.graph.interpolation).tension(.8)},this.domain=function(){var a=[],c=b.stackedData||b.stackData();c.forEach(function(b){b.forEach(function(b){a.push(b.y)})});var d=c[0][0].x,e=c[0][c[0].length-1].x,f=0,g=d3.max(a);return{x:[d,e],y:[f,g]}},this.render=function(){b.vis.selectAll("*").remove();var a=this.graph.vis.selectAll("path").data(this.graph.stackedData).enter().append("svg:path").attr("d",this.seriesPathFactory()),d=0;b.series.forEach(function(b){if(b.disabled)return;b.path=a[0][d++],c._styleSeries(b)})},this._styleSeries=function(a){a.path.setAttribute("fill","none"),a.path.setAttribute("stroke",a.color),a.path.setAttribute("stroke-width",2)}},Rickshaw.namespace("Rickshaw.Graph.Renderer.Stack"),Rickshaw.Graph.Renderer.Stack=function(a){var b=this.graph=a.graph,c=this;this.name="stack",this.seriesPathFactory=function(){return d3.svg.area().x(function(a){return b.x(a.x)}).y0(function(a){return b.y(a.y0)}).y1(function(a){return b.y(a.y+a.y0)}).interpolate(this.graph.interpolation).tension(.8)},this.domain=function(){var a=b.stackedData||b.stackData(),c=a.slice(-1).shift(),d=a[0][0].x,e=a[0][a[0].length-1].x,f=0,g=d3.max(c,function(a){return a.y+a.y0});return{x:[d,e],y:[f,g]}},this.render=function(){b.vis.selectAll("*").remove();var a=b.vis.selectAll("path").data(b.stackedData).enter().append("svg:path").attr("d",this.seriesPathFactory()),d=0;b.series.forEach(function(b){if(b.disabled)return;b.path=a[0][d++],c._styleSeries(b)})},this._styleSeries=function(a){if(!a.path)return;a.path.setAttribute("fill",a.color),a.path.setAttribute("stroke-width",2),a.path.setAttribute("class",a.className)}},Rickshaw.namespace("Rickshaw.Graph.Renderer.Bar"),Rickshaw.Graph.Renderer.Bar=function(a){var b=this.graph=a.graph,c=this;this.name="bar",this.gapSize=a.gapSize||.05,this.unstack=!1,b.unstacker=b.unstacker||new Rickshaw.Graph.Unstacker({graph:b}),this.domain=function(){var a=[],c=b.stackedData||b.stackData(),d=this.unstack?c:[c.slice(-1).shift()];d.forEach(function(b){b.forEach(function(b){a.push(b.y+b.y0)})});var e=c[0][0].x,f=c[0][c[0].length-1].x,g=0,h=d3.max(a);return this._barWidth=null,{x:[e,f],y:[g,h]}},this.barWidth=function(){if(this._barWidth)return this._barWidth;var a=b.stackedData||b.stackData(),c=a.slice(-1).shift(),d={};for(var e=0;e<c.length-1;e++){var f=c[e+1].x-c[e].x;d[f]=d[f]||0,d[f]++}var g={count:0};return d3.keys(d).forEach(function(a){g.count<d[a]&&(g={count:d[a],magnitude:a})}),this._barWidth=this.graph.x(c[0].x+g.magnitude*(1-this.gapSize)),this._barWidth},this.render=function(){b.vis.selectAll("*").remove();var a=this.unstack?this.graph.series.length:1,d=this.barWidth(),e=0,f=b.series.filter(function(a){return!a.disabled}).length,g=this.unstack?d/f:d;b.series.forEach(function(a){if(a.disabled)return;var d=b.vis.selectAll("path").data(a.stack).enter().append("svg:rect").attr("x",function(a){return b.x(a.x)+e}).attr("y",function(a){return b.y(a.y0+a.y)}).attr("width",g).attr("height",function(a){return b.y.magnitude(a.y)});Array.prototype.forEach.call(d[0],function(b){b.setAttribute("fill",a.color)}),c.unstack&&(e+=g)})},this._styleSeries=function(a){if(!a.path)return;a.path.setAttribute("fill",a.color),a.path.setAttribute("stroke-width",2),a.path.setAttribute("class",a.className)}},Rickshaw.namespace("Rickshaw.Graph.Renderer.Area"),Rickshaw.Graph.Renderer.Area=function(a){var b=this.graph=a.graph,c=this;this.tension=.8,this.strokeWidth=2,this.yBerth=1.025,this.name="area",this.unstack=!1,b.unstacker=b.unstacker||new Rickshaw.Graph.Unstacker({graph:b}),this.seriesPathFactory=function(){return d3.svg.area().x(function(a){return b.x(a.x)}).y0(function(a){return b.y(a.y0)}).y1(function(a){return b.y(a.y+a.y0)}).interpolate(this.graph.interpolation).tension(this.tension)},this.seriesLineFactory=function(){return d3.svg.line().x(function(a){return b.x(a.x)}).y(function(a){return b.y(a.y+a.y0)}).interpolate(this.graph.interpolation).tension(this.tension)},this.domain=function(){var a=[],c=b.stackedData||b.stackData(),d=this.unstack?c:[c.slice(-1).shift()];d.forEach(function(b){b.forEach(function(b){a.push(b.y+b.y0)})});var e=c[0][0].x,f=c[0][c[0].length-1].x,g=0,h=d3.max(a)*this.yBerth;return{x:[e,f],y:[g,h]}},this.render=function(){b.vis.selectAll("*").remove();var a=b.vis.selectAll("path").data(b.stackedData).enter().insert("svg:g","g");a.append("svg:path").attr("d",this.seriesPathFactory()).attr("class","area"),this.graph.stroke&&a.append("svg:path").attr("d",this.seriesLineFactory()).attr("class","line");var d=0;b.series.forEach(function(b){if(b.disabled)return;b.path=a[0][d++],c._styleSeries(b)})},this._styleSeries=function(a){if(!a.path)return;d3.select(a.path).select(".area").attr("fill",a.color),this.graph.stroke&&d3.select(a.path).select(".line").attr("fill","none").attr("stroke",a.stroke||d3.interpolateRgb(a.color,"black")(.125)).attr("stroke-width",this.strokeWidth),a.className&&a.path.setAttribute("class",a.className)}},Rickshaw.namespace("Rickshaw.Graph.Renderer.ScatterPlot"),Rickshaw.Graph.Renderer.ScatterPlot=function(a){var b=this.graph=a.graph,c=this;this.name="scatterplot",this.unstack=!0,this.dotSize=a.dotSize||4,this.xBerth=1.0125,this.yBerth=1.0125,b.unstacker=b.unstacker||new Rickshaw.Graph.Unstacker({graph:b}),this.domain=function(){var a=[],c=b.stackedData||b.stackData();c.forEach(function(b){b.forEach(function(b){a.push(b.y)})});var d=c[0][0].x,e=c[0][c[0].length-1].x;d-=(e-d)*(this.xBerth-1),e+=(e-d)*(this.xBerth-1);var f=0,g=d3.max(a)*this.yBerth;return{x:[d,e],y:[f,g]}},this.render=function(){b.vis.selectAll("*").remove(),b.series.forEach(function(a){if(a.disabled)return;var c=b.vis.selectAll("path").data(a.stack).enter().append("svg:circle").attr("cx",function(a){return b.x(a.x)}).attr("cy",function(a){return b.y(a.y)}).attr("r",this.dotSize);Array.prototype.forEach.call(c[0],function(b){b.setAttribute("fill",a.color)})},this)},this._styleSeries=function(a){if(!a.path)return;a.path.setAttribute("fill",a.color),a.path.setAttribute("stroke-width",2),a.path.setAttribute("class",a.className)}},Rickshaw.namespace("Rickshaw.Graph.Smoother"),Rickshaw.Graph.Smoother=function(a){this.graph=a.graph,this.element=a.element;var b=this;this.aggregationScale=1,this.element&&$(function(){$(b.element).slider({min:1,max:100,slide:function(a,c){b.setScale(c.value),b.graph.update()}})}),b.graph.stackData.hooks.data.push({name:"smoother",orderPosition:50,f:function(a){var c=[];return a.forEach(function(a){var d=[];while(a.length){var e=0,f=0,g=a.splice(0,b.aggregationScale);g.forEach(function(a){e+=a.x/g.length,f+=a.y/g.length}),d.push({x:e,y:f})}c.push(d)}),c}}),this.setScale=function(a){if(a<1)throw"scale out of range: "+a;this.aggregationScale=a,this.graph.update()}},Rickshaw.namespace("Rickshaw.Graph.Unstacker"),Rickshaw.Graph.Unstacker=function(a){this.graph=a.graph;var b=this;this.graph.stackData.hooks.after.push({name:"unstacker",f:function(a){return b.graph.renderer.unstack?(a.forEach(function(a){a.forEach(function(a){a.y0=0})}),a):a}})},Rickshaw.namespace("Rickshaw.Series"),Rickshaw.Series=function(a,b,c){this.initialize(a,b,c)},Rickshaw.Series.prototype=new Array,Rickshaw.Series.prototype.constructor=Rickshaw.Series,Rickshaw.Series.prototype.initialize=function(a,b,c){var d=this;c=c||{},d.palette=new Rickshaw.Color.Palette(b),d.timeBase=typeof c.timeBase=="undefined"?Math.floor((new Date).getTime()/1e3):c.timeBase,a&&typeof a=="object"&&a instanceof Array&&a.forEach(function(a){d.addItem(a)})},Rickshaw.Series.prototype.addItem=function(a){var b=this;if(typeof a.name=="undefined")throw"addItem() needs a name";a.color=a.color||b.palette.color(a.name),a.data=a.data||[],a.data.length==0&&b.getIndex()>0?b[0].data.forEach(function(b){a.data.push({x:b.x,y:0})}):(console.log(b.timeBase),a.data.push({x:b.timeBase,y:0})),b.push(a),b.legend&&b.legend.addLine(b.itemByName(a.name))},Rickshaw.Series.prototype.addData=function(a){var b=this,c=this.getIndex();Rickshaw.keys(a).forEach(function(a){b.itemByName(a)||b.addItem({name:a})}),b.forEach(function(d){d.data.push({x:(c*b.timeInterval||1)+b.timeBase,y:a[d.name]||0})})},Rickshaw.Series.prototype.getIndex=function(){var a=this;return a[0]&&a[0].data&&a[0].data.length?a[0].data.length:0},Rickshaw.Series.prototype.itemByName=function(a){var b=this,c;return b.forEach(function(b){b.name==a&&(c=b)}),c},Rickshaw.Series.prototype.setTimeInterval=function(a){this.timeInterval=parseInt(a/1e3)},Rickshaw.Series.prototype.setTimeBase=function(a){this.timeBase=a},Rickshaw.Series.prototype.dump=function(){var a=this,b={timeBase:a.timeBase,timeInterval:a.timeInterval,items:[]};return a.forEach(function(a){var c={color:a.color,name:a.name,data:[]};a.data.forEach(function(a){c.data.push({x:a.x,y:a.y})}),b.items.push(c)}),b},Rickshaw.Series.prototype.load=function(a){var b=this;a.timeInterval&&(b.timeInterval=a.timeInterval),a.timeBase&&(b.timeBase=a.timeBase),a.items&&a.items.forEach(function(a){b.push(a),b.legend&&b.legend.addLine(b.itemByName(a.name))})},Rickshaw.Series.zeroFill=function(a){var b,c=0,d=a.map(function(a){return a.data});while(c<Math.max.apply(null,d.map(function(a){return a.length})))b=Math.min.apply(null,d.filter(function(a){return a[c]}).map(function(a){return a[c].x})),d.forEach(function(a){(!a[c]||a[c].x!=b)&&a.splice(c,0,{x:b,y:0})}),c++};
+Rickshaw={namespace:function(a,b){var c=a.split("."),d=typeof global!="undefined"?global:window,e=d.Rickshaw;for(var f=1,g=c.length;f<g;f++)currentPart=c[f],e[currentPart]=e[currentPart]||{},e=e[currentPart];return e},keys:function(a){var b=[];for(var c in a)b.push(c);return b}},function(a){function j(a){return b.call(a)===i}function k(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function l(a){if(m(a)!==h)throw new TypeError;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}function m(a){switch(a){case null:return c;case void 0:return d}var b=typeof a;switch(b){case"boolean":return e;case"number":return f;case"string":return g}return h}function n(a){return typeof a=="undefined"}function p(a){var b=a.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1].replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g,"").replace(/\s+/g,"").split(",");return b.length==1&&!b[0]?[]:b}function q(a,b){var c=a;return function(){var a=r([t(c,this)],arguments);return b.apply(this,a)}}function r(a,b){var c=a.length,d=b.length;while(d--)a[c+d]=b[d];return a}function s(a,b){return a=o.call(a,0),r(a,b)}function t(a,b){if(arguments.length<2&&n(arguments[0]))return this;var c=a,d=o.call(arguments,2);return function(){var a=s(d,arguments);return c.apply(b,a)}}var b=Object.prototype.toString,c="Null",d="Undefined",e="Boolean",f="Number",g="String",h="Object",i="[object Function]",o=Array.prototype.slice,u=function(){},v=function(){function b(){}function c(){function d(){this.initialize.apply(this,arguments)}var a=null,c=[].slice.apply(arguments);j(c[0])&&(a=c.shift()),k(d,v.Methods),d.superclass=a,d.subclasses=[];if(a){b.prototype=a.prototype,d.prototype=new b;try{a.subclasses.push(d)}catch(e){}}for(var f=0,g=c.length;f<g;f++)d.addMethods(c[f]);return d.prototype.initialize||(d.prototype.initialize=u),d.prototype.constructor=d,d}function d(b){var c=this.superclass&&this.superclass.prototype,d=l(b);a&&(b.toString!=Object.prototype.toString&&d.push("toString"),b.valueOf!=Object.prototype.valueOf&&d.push("valueOf"));for(var e=0,f=d.length;e<f;e++){var g=d[e],h=b[g];if(c&&j(h)&&p(h)[0]=="$super"){var i=h;h=q(function(a){return function(){return c[a].apply(this,arguments)}}(g),i),h.valueOf=t(i.valueOf,i),h.toString=t(i.toString,i)}this.prototype[g]=h}return this}var a=function(){for(var a in{toString:1})if(a==="toString")return!1;return!0}();return{create:c,Methods:{addMethods:d}}}();a.exports?a.exports.Class=v:a.Class=v}(Rickshaw),Rickshaw.namespace("Rickshaw.Compat.ClassList"),Rickshaw.Compat.ClassList=function(){typeof document!="undefined"&&!("classList"in document.createElement("a"))&&function(a){"use strict";var b="classList",c="prototype",d=(a.HTMLElement||a.Element)[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){var b=0,c=this.length;for(;b<c;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(b==="")throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){var b=f.call(a.className),c=b?b.split(/\s+/):[],d=0,e=c.length;for(;d<e;d++)this.push(c[d]);this._updateClassName=function(){a.className=this.toString()}},k=j[c]=[],l=function(){return new j(this)};h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",i(this,a)!==-1},k.add=function(a){a+="",i(this,a)===-1&&(this.push(a),this._updateClassName())},k.remove=function(a){a+="";var b=i(this,a);b!==-1&&(this.splice(b,1),this._updateClassName())},k.toggle=function(a){a+="",i(this,a)===-1?this.add(a):this.remove(a)},k.toString=function(){return this.join(" ")};if(e.defineProperty){var m={get:l,enumerable:!0,configurable:!0};try{e.defineProperty(d,b,m)}catch(n){n.number===-2146823252&&(m.enumerable=!1,e.defineProperty(d,b,m))}}else e[c].__defineGetter__&&d.__defineGetter__(b,l)}(self)},(typeof RICKSHAW_NO_COMPAT!="undefined"&&!RICKSHAW_NO_COMPAT||typeof RICKSHAW_NO_COMPAT=="undefined")&&new Rickshaw.Compat.ClassList,Rickshaw.namespace("Rickshaw.Graph"),Rickshaw.Graph=function(a){this.element=a.element,this.interpolation=a.interpolation||"cardinal",this.series=a.series,this.offset="zero",this.stroke=a.stroke||!1;var b=window.getComputedStyle(this.element,null),c=parseInt(b.getPropertyValue("width")),d=parseInt(b.getPropertyValue("height"));this.width=a.width||c||400,this.height=a.height||d||250,this.window={},this.updateCallbacks=[];var e=this;this.initialize=function(a){this.validateSeries(a.series),this.series.active=function(){return e.series.filter(function(a){return!a.disabled})},this.element.classList.add("rickshaw_graph"),this.vis=d3.select(this.element).append("svg:svg").attr("width",this.width).attr("height",this.height);var b=[Rickshaw.Graph.Renderer.Stack,Rickshaw.Graph.Renderer.Line,Rickshaw.Graph.Renderer.Bar,Rickshaw.Graph.Renderer.Area,Rickshaw.Graph.Renderer.ScatterPlot];b.forEach(function(a){if(!a)return;e.registerRenderer(new a({graph:e}))}),this.setRenderer(a.renderer||"stack"),this.discoverRange()},this.validateSeries=function(a){if(!(a instanceof Array||a instanceof Rickshaw.Series)){var b=Object.prototype.toString.apply(a);throw"series is not an array: "+b}var c;a.forEach(function(a){if(!(a instanceof Object))throw"series element is not an object: "+a;if(!a.data)throw"series has no data: "+JSON.stringify(a);if(!(a.data instanceof Array))throw"series data is not an array: "+JSON.stringify(a.data);c=c||a.data.length;if(c&&a.data.length!=c)throw"series cannot have differing numbers of points: "+c+" vs "+a.data.length+"; see Rickshaw.Series.zeroFill()";var b=typeof a.data[0].x,d=typeof a.data[0].y;if(b!="number"||d!="number")throw"x and y properties of points should be numbers instead of "+b+" and "+d})},this.dataDomain=function(){var a=this.series[0].data;return[a[0].x,a.slice(-1).shift().x]},this.discoverRange=function(){var a=this.renderer.domain();this.x=d3.scale.linear().domain(a.x).range([0,this.width]),this.y=d3.scale.linear().domain(a.y).range([this.height,0]),this.y.magnitude=d3.scale.linear().domain(a.y).range([0,this.height])},this.render=function(){var a=this.stackData();this.discoverRange(),this.renderer.render(),this.updateCallbacks.forEach(function(a){a()})},this.update=this.render,this.stackData=function(){var a=this.series.active().map(function(a){return a.data}).map(function(a){return a.filter(function(a){return this._slice(a)},this)},this);this.stackData.hooks.data.forEach(function(b){a=b.f.apply(e,[a])});var b=d3.layout.stack();b.offset(e.offset);var c=b(a);this.stackData.hooks.after.forEach(function(b){c=b.f.apply(e,[a])});var d=0;return this.series.forEach(function(a){if(a.disabled)return;a.stack=c[d++]}),this.stackedData=c,c},this.stackData.hooks={data:[],after:[]},this._slice=function(a){if(this.window.xMin||this.window.xMax){var b=!0;return this.window.xMin&&a.x<=this.window.xMin&&(b=!1),this.window.xMax&&a.x>=this.window.xMax&&(b=!1),b}return!0},this.onUpdate=function(a){this.updateCallbacks.push(a)},this.registerRenderer=function(a){this._renderers=this._renderers||{},this._renderers[a.name]=a},this.setRenderer=function(a){if(!this._renderers[a])throw"couldn't find renderer "+a;this.renderer=this._renderers[a]},this.initialize(a)},Rickshaw.namespace("Rickshaw.Fixtures.Color"),Rickshaw.Fixtures.Color=function(){this.schemes={},this.schemes.spectrum14=["#ecb796","#dc8f70","#b2a470","#92875a","#716c49","#d2ed82","#bbe468","#a1d05d","#e7cbe6","#d8aad6","#a888c2","#9dc2d3","#649eb9","#387aa3"].reverse(),this.schemes.spectrum2000=["#57306f","#514c76","#646583","#738394","#6b9c7d","#84b665","#a7ca50","#bfe746","#e2f528","#fff726","#ecdd00","#d4b11d","#de8800","#de4800","#c91515","#9a0000","#7b0429","#580839","#31082b"],this.schemes.spectrum2001=["#2f243f","#3c2c55","#4a3768","#565270","#6b6b7c","#72957f","#86ad6e","#a1bc5e","#b8d954","#d3e04e","#ccad2a","#cc8412","#c1521d","#ad3821","#8a1010","#681717","#531e1e","#3d1818","#320a1b"],this.schemes.classic9=["#423d4f","#4a6860","#848f39","#a2b73c","#ddcb53","#c5a32f","#7d5836","#963b20","#7c2626","#491d37","#2f254a"].reverse(),this.schemes.httpStatus={503:"#ea5029",502:"#d23f14",500:"#bf3613",410:"#efacea",409:"#e291dc",403:"#f457e8",408:"#e121d2",401:"#b92dae",405:"#f47ceb",404:"#a82a9f",400:"#b263c6",301:"#6fa024",302:"#87c32b",307:"#a0d84c",304:"#28b55c",200:"#1a4f74",206:"#27839f",201:"#52adc9",202:"#7c979f",203:"#a5b8bd",204:"#c1cdd1"},this.schemes.colorwheel=["#b5b6a9","#858772","#785f43","#96557e","#4682b4","#65b9ac","#73c03a","#cb513a"].reverse(),this.schemes.cool=["#5e9d2f","#73c03a","#4682b4","#7bc3b8","#a9884e","#c1b266","#a47493","#c09fb5"]},Rickshaw.namespace("Rickshaw.Fixtures.RandomData"),Rickshaw.Fixtures.RandomData=function(a){var b;a=a||1;var c=200,d=Math.floor((new Date).getTime()/1e3);this.addData=function(b){var e=Math.random()*100+15+c,f=b[0].length,g=1;b.forEach(function(b){var c=Math.random()*20,h=e/25+g++ +(Math.cos(f*g*11/960)+2)*15+(Math.cos(f/7)+2)*7+(Math.cos(f/17)+2)*1;b.push({x:f*a+d,y:h+c})}),c=e*.85}},Rickshaw.namespace("Rickshaw.Fixtures.Time"),Rickshaw.Fixtures.Time=function(){var a=(new Date).getTimezoneOffset()*60,b=this;this.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.units=[{name:"decade",seconds:315576e3,formatter:function(a){return parseInt(a.getUTCFullYear()/10)*10}},{name:"year",seconds:31557600,formatter:function(a){return a.getUTCFullYear()}},{name:"month",seconds:2635200,formatter:function(a){return b.months[a.getUTCMonth()]}},{name:"week",seconds:604800,formatter:function(a){return b.formatDate(a)}},{name:"day",seconds:86400,formatter:function(a){return a.getUTCDate()}},{name:"6 hour",seconds:21600,formatter:function(a){return b.formatTime(a)}},{name:"hour",seconds:3600,formatter:function(a){return b.formatTime(a)}},{name:"15 minute",seconds:900,formatter:function(a){return b.formatTime(a)}},{name:"minute",seconds:60,formatter:function(a){return a.getUTCMinutes()}},{name:"15 second",seconds:15,formatter:function(a){return a.getUTCSeconds()+"s"}},{name:"second",seconds:1,formatter:function(a){return a.getUTCSeconds()+"s"}}],this.unit=function(a){return this.units.filter(function(b){return a==b.name}).shift()},this.formatDate=function(a){return a.toUTCString().match(/, (\w+ \w+ \w+)/)[1]},this.formatTime=function(a){return a.toUTCString().match(/(\d+:\d+):/)[1]},this.ceil=function(a,b){if(b.name=="month"){var c=new Date((a+b.seconds-1)*1e3);return(new Date(c.getUTCFullYear(),c.getUTCMonth()+1,1,0,0,0,0)).getTime()/1e3}if(b.name=="year"){var c=new Date((a+b.seconds-1)*1e3);return(new Date(c.getUTCFullYear(),1,1,0,0,0,0)).getTime()/1e3}return Math.ceil(a/b.seconds)*b.seconds}},Rickshaw.namespace("Rickshaw.Fixtures.Number"),Rickshaw.Fixtures.Number.formatKMBT=function(a){return a>=1e12?a/1e12+"T":a>=1e9?a/1e9+"B":a>=1e6?a/1e6+"M":a>=1e3?a/1e3+"K":a<1&&a>0?a.toFixed(2):a==0?"":a},Rickshaw.namespace("Rickshaw.Color.Palette"),Rickshaw.Color.Palette=function(a){var b=new Rickshaw.Fixtures.Color;a=a||{},this.schemes={},this.scheme=b.schemes[a.scheme]||a.scheme||b.schemes.colorwheel,this.runningIndex=0,this.color=function(a){return this.scheme[a]||this.scheme[this.runningIndex++]||"#808080"}},Rickshaw.namespace("Graph.Ajax"),Rickshaw.Graph.Ajax=function(a){var b=this;this.dataURL=a.dataURL,$.ajax({url:this.dataURL,complete:function(c,d){d==="error"&&console.log("error loading dataURL: "+this.dataURL);var e=JSON.parse(c.responseText);if(typeof a.onData=="function"){var f=a.onData(e);e=f}a.series?a.series.forEach(function(a){var b=a.key||a.name;if(!b)throw"series needs a key or a name";e.forEach(function(c){var d=c.key||c.name;if(!d)throw"data needs a key or a name";if(b==d){var e=["color","name","data"];e.forEach(function(b){a[b]=a[b]||c[b]})}})}):a.series=e,b.graph=new Rickshaw.Graph(a),b.graph.render(),typeof a.onComplete=="function"&&a.onComplete(b)}})},Rickshaw.namespace("Rickshaw.Graph.Annotate"),Rickshaw.Graph.Annotate=function(a){var b=this.graph=a.graph;this.elements={timeline:a.element};var c=this;this.data={},this.elements.timeline.classList.add("rickshaw_annotation_timeline"),this.add=function(a,b){c.data[a]=c.data[a]||{boxes:[]},c.data[a].boxes.push({content:b})},this.update=function(){for(var a in c.data){var b=c.data[a],d=c.graph.x(a);if(d>c.graph.x.range()[1]){b.element&&(b.element.style.display="none");continue}if(!b.element){var e=b.element=document.createElement("div");e.classList.add("annotation"),this.elements.timeline.appendChild(e),e.addEventListener("click",function(a){e.classList.toggle("active"),b.line.classList.toggle("active")},!1)}b.element.style.left=d+"px",b.element.style.display="block",b.boxes.forEach(function(a){var e=a.element;e||(e=a.element=document.createElement("div"),e.classList.add("content"),e.innerHTML=a.content,b.element.appendChild(e),b.line=document.createElement("div"),b.line.classList.add("annotation_line"),c.graph.element.appendChild(b.line)),b.line.style.left=d+"px"})}},this.graph.onUpdate(function(){c.update()})},Rickshaw.namespace("Rickshaw.Graph.Axis.Time"),Rickshaw.Graph.Axis.Time=function(a){var b=this;this.graph=a.graph,this.elements=[],this.ticksTreatment=a.ticksTreatment||"plain",this.fixedTimeUnit=a.timeUnit;var c=new Rickshaw.Fixtures.Time;this.appropriateTimeUnit=function(){var a,b=c.units,d=this.graph.x.domain(),e=d[1]-d[0];return b.forEach(function(b){Math.floor(e/b.seconds)>=2&&(a=a||b)}),a||c.units[c.units.length-1]},this.tickOffsets=function(){var a=this.graph.x.domain(),b=this.fixedTimeUnit||this.appropriateTimeUnit(),d=Math.ceil((a[1]-a[0])/b.seconds),e=a[0],f=[];for(var g=0;g<d;g++)tickValue=c.ceil(e,b),e=tickValue+b.seconds/2,f.push({value:tickValue,unit:b});return f},this.render=function(){this.elements.forEach(function(a){a.parentNode.removeChild(a)}),this.elements=[];var a=this.tickOffsets();a.forEach(function(a){if(b.graph.x(a.value)>b.graph.x.range()[1])return;var c=document.createElement("div");c.style.left=b.graph.x(a.value)+"px",c.classList.add("x_tick"),c.classList.add(b.ticksTreatment);var d=document.createElement("div");d.classList.add("title"),d.innerHTML=a.unit.formatter(new Date(a.value*1e3)),c.appendChild(d),b.graph.element.appendChild(c),b.elements.push(c)})},this.graph.onUpdate(function(){b.render()})},Rickshaw.namespace("Rickshaw.Graph.Axis.Y"),Rickshaw.Graph.Axis.Y=function(a){var b=this;this.graph=a.graph,this.orientation=a.orientation||"right";var c=75;this.ticks=a.ticks||Math.floor(this.graph.height/c),this.tickSize=a.tickSize||4,this.ticksTreatment=a.ticksTreatment||"plain";if(a.element){var d=.1;if(!a.width||!a.height)var e=window.getComputedStyle(a.element,null),f=parseInt(e.getPropertyValue("width")),g=parseInt(e.getPropertyValue("height"));this.width=a.width||f||this.graph.width*d,this.height=a.height||g||this.graph.height,this.vis=d3.select(a.element).append("svg:svg").attr("class","rickshaw_graph y_axis").attr("width",this.width).attr("height",this.height*(1+d)),this.element=this.vis[0][0],this.element.style.position="relative";var h=this.height*d;this.element.style.top=-1*h+"px",this.element.style.paddingTop=h+"px"}else this.vis=this.graph.vis;this.render=function(){var b=d3.svg.axis().scale(this.graph.y).orient(this.orientation);b.tickFormat(a.tickFormat||function(a){return a});if(this.orientation=="left")var c="translate("+this.width+", 0)";this.element&&this.vis.selectAll("*").remove(),this.vis.append("svg:g").attr("class",["y_ticks",this.ticksTreatment].join(" ")).attr("transform",c).call(b.ticks(this.ticks).tickSubdivide(0).tickSize(this.tickSize));var d=(this.orientation=="right"?1:-1)*this.graph.width;this.graph.vis.append("svg:g").attr("class","y_grid").call(b.ticks(this.ticks).tickSubdivide(0).tickSize(d))},this.graph.onUpdate(function(){b.render()})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Highlight"),Rickshaw.Graph.Behavior.Series.Highlight=function(a){this.graph=a.graph,this.legend=a.legend;var b=this,c={};this.addHighlightEvents=function(a){a.element.addEventListener("mouseover",function(d){b.legend.lines.forEach(function(b){if(a===b)return;c[b.series.name]=c[b.series.name]||b.series.color,b.series.color=d3.interpolateRgb(b.series.color,d3.rgb("#d8d8d8"))(.8).toString()}),b.graph.update()},!1),a.element.addEventListener("mouseout",function(a){b.legend.lines.forEach(function(a){c[a.series.name]&&(a.series.color=c[a.series.name])}),b.graph.update()},!1)},this.legend&&this.legend.lines.forEach(function(a){b.addHighlightEvents(a)})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Order"),Rickshaw.Graph.Behavior.Series.Order=function(a){this.graph=a.graph,this.legend=a.legend;var b=this;$(function(){$(b.legend.list).sortable({containment:"parent",tolerance:"pointer",update:function(a,c){var d=[];$(b.legend.list).find("li").each(function(a,b){if(!b.series)return;d.push(b.series)});for(var e=b.graph.series.length-1;e>=0;e--)b.graph.series[e]=d.shift();b.graph.update()}}),$(b.legend.list).disableSelection()}),this.graph.onUpdate(function(){var a=window.getComputedStyle(b.legend.element).height;b.legend.element.style.height=a})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Toggle"),Rickshaw.Graph.Behavior.Series.Toggle=function(a){this.graph=a.graph,this.legend=a.legend;var b=this;this.addAnchor=function(a){var b=document.createElement("a");b.innerHTML="&#10004;",b.classList.add("action"),a.element.insertBefore(b,a.element.firstChild),b.onclick=function(b){a.series.disabled?(a.series.enable(),a.element.classList.remove("disabled")):(a.series.disable(),a.element.classList.add("disabled"))}},this.legend&&this.legend.lines.forEach(function(a){b.addAnchor(a)}),this._addBehavior=function(){this.graph.series.forEach(function(a){a.disable=function(){if(b.graph.series.length<=1)throw"only one series left";a.disabled=!0,b.graph.update()},a.enable=function(){a.disabled=!1,b.graph.update()}})},this._addBehavior(),this.updateBehaviour=function(){this._addBehavior()}},Rickshaw.namespace("Rickshaw.Graph.HoverDetail"),Rickshaw.Graph.HoverDetail=function(a){var b=this.graph=a.graph,c=a.xFormatter||function(a){return(new Date(a*1e3)).toUTCString()},d=a.yFormatter||function(a){return a.toFixed(2)},e=this.element=document.createElement("div");e.className="detail",this.visible=!0,b.element.appendChild(e);var f=this;this.lastEvent=null,this.update=function(a){a=a||this.lastEvent;if(!a)return;this.lastEvent=a;if(a.target.nodeName!="path"&&a.target.nodeName!="svg")return;var c=a.offsetX||a.layerX,d=a.offsetY||a.layerY,e=b.x.invert(c),g=b.stackedData,h=g.slice(-1).shift(),i=d3.scale.linear().domain([h[0].x,h.slice(-1).shift().x]).range([0,h.length]),j=Math.floor(i(e)),k=j||0;for(var l=j;l<g[0].length-1;){if(g[0][l].x<=e&&g[0][l+1].x>e){k=l;break}g[0][l+1]<e?l++:l--}e=g[0][k].x;var m=b.series.active().map(function(a){return{name:a.name,value:a.stack[k]}});this.visible&&f.render.call(f,e,m,c,d)},this.graph.element.addEventListener("mousemove",function(a){f.visible=!0,f.update(a)},!1),this.graph.onUpdate(function(){f.update()}),this.graph.element.addEventListener("mouseout",function(a){a.relatedTarget&&!(a.relatedTarget.compareDocumentPosition(f.graph.element)&Node.DOCUMENT_POSITION_CONTAINS)&&f.hide()},!1),this.hide=function(){this.visible=!1,this.element.classList.add("inactive")},this.show=function(){this.visible=!0,this.element.classList.remove("inactive")},this.render=function(a,e,f,g){this.element.innerHTML="",this.element.style.left=b.x(a)+"px";var h=document.createElement("div");h.className="x_label",h.innerHTML=c(a),this.element.appendChild(h);var i=null,j=function(a,b){return a.value.y0+a.value.y-(b.value.y0+b.value.y)};e.sort(j).forEach(function(a){var c=d.constructor==Array?d[e.indexOf(a)](a.value.y):d(a.value.y),f=document.createElement("div");f.className="item",f.innerHTML=a.name+":&nbsp;"+c,f.style.top=b.y(a.value.y0+a.value.y)+"px";var h=b.y.magnitude.invert(b.element.offsetHeight-g);this.element.appendChild(f);var j=document.createElement("div");j.className="dot",j.style.top=f.style.top,this.element.appendChild(j),h>a.value.y0&&h<a.value.y0+a.value.y&&!i&&(i=f,f.className="item active",j.className="dot active")},this),this.show()}},Rickshaw.namespace("Rickshaw.Graph.JSONP"),Rickshaw.Graph.JSONP=function(a){var b=this;this.dataURL=a.dataURL,$.ajax({url:this.dataURL,dataType:"jsonp",success:function(c,d,e){d==="error"&&console.log("error loading dataURL: "+this.dataURL);if(typeof a.onData=="function"){var f=a.onData(c);c=f}a.series?a.series.forEach(function(a){var b=a.key||a.name;if(!b)throw"series needs a key or a name";c.forEach(function(c){var d=c.key||c.name;if(!d)throw"data needs a key or a name";if(b==d){var e=["color","name","data"];e.forEach(function(b){a[b]=a[b]||c[b]})}})}):a.series=c,b.graph=new Rickshaw.Graph(a),b.graph.render(),typeof a.onComplete=="function"&&a.onComplete(b)}})},Rickshaw.namespace("Rickshaw.Graph.Legend"),Rickshaw.Graph.Legend=function(a){var b=this.element=a.element,c=this.graph=a.graph,d=this;b.classList.add("rickshaw_legend");var e=this.list=document.createElement("ul");b.appendChild(e);var f=c.series.map(function(a){return a}).reverse();this.lines=[],this.addLine=function(a){var b=document.createElement("li");b.className="line";var c=document.createElement("div");c.className="swatch",c.style.backgroundColor=a.color,b.appendChild(c);var f=document.createElement("span");f.className="label",f.innerHTML=a.name,b.appendChild(f),e.appendChild(b),b.series=a,a.noLegend&&(b.style.display="none");var g={element:b,series:a};d.shelving&&(d.shelving.addAnchor(g),d.shelving.updateBehaviour()),d.highlighter&&d.highlighter.addHighlightEvents(g),d.lines.push(g)},f.forEach(function(a){d.addLine(a)}),c.onUpdate(function(){})},Rickshaw.namespace("Rickshaw.Graph.RangeSlider"),Rickshaw.Graph.RangeSlider=function(a){var b=this.element=a.element,c=this.graph=a.graph;$(function(){$(b).slider({range:!0,min:c.dataDomain()[0],max:c.dataDomain()[1],values:[c.dataDomain()[0],c.dataDomain()[1]],slide:function(a,b){c.window.xMin=b.values[0],c.window.xMax=b.values[1],c.update(),c.dataDomain()[0]==b.values[0]&&(c.window.xMin=undefined),c.dataDomain()[1]==b.values[1]&&(c.window.xMax=undefined)}})}),b[0].style.width=c.width+"px",c.onUpdate(function(){var a=$(b).slider("option","values");$(b).slider("option","min",c.dataDomain()[0]),$(b).slider("option","max",c.dataDomain()[1]),c.window.xMin==undefined&&(a[0]=c.dataDomain()[0]),c.window.xMax==undefined&&(a[1]=c.dataDomain()[1]),$(b).slider("option","values",a)})},Rickshaw.namespace("Rickshaw.Graph.Renderer"),Rickshaw.Graph.Renderer=Rickshaw.Class.create({name:undefined,tension:.8,strokeWidth:2,unstack:!0,padding:{top:.025,right:0,bottom:0,left:0},stroke:!1,fill:!1,initialize:function(a){this.graph=a.graph,this.tension=a.tension||this.tension,this.graph.unstacker=this.graph.unstacker||new Rickshaw.Graph.Unstacker({graph:this.graph})},seriesPathFactory:function(){},seriesStrokeFactory:function(){},domain:function(){var a=[],b=this.graph.stackedData||this.graph.stackData(),c=this.unstack?b:[b.slice(-1).shift()];c.forEach(function(b){b.forEach(function(b){a.push(b.y+b.y0)})});var d=b[0][0].x,e=b[0][b[0].length-1].x;d-=(e-d)*this.padding.left,e+=(e-d)*this.padding.right;var f=0,g=d3.max(a)*(1+this.padding.top);return{x:[d,e],y:[f,g]}},render:function(){var a=this.graph;a.vis.selectAll("*").remove();var b=a.vis.selectAll("path").data(this.graph.stackedData).enter().append("svg:path").attr("d",this.seriesPathFactory()),c=0;a.series.forEach(function(a){if(a.disabled)return;a.path=b[0][c++],this._styleSeries(a)},this)},_styleSeries:function(a){var b=this.fill?a.color:"none",c=this.stroke?a.color:"none";a.path.setAttribute("fill",b),a.path.setAttribute("stroke",c),a.path.setAttribute("stroke-width",this.strokeWidth),a.path.setAttribute("class",a.className)},setStrokeWidth:function(a){a!==undefined&&(this.strokeWidth=a)},setTension:function(a){a!==undefined&&(this.tension=a)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Line"),Rickshaw.Graph.Renderer.Line=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"line",unstack:!0,fill:!1,stroke:!0,seriesPathFactory:function(){var a=this.graph;return d3.svg.line().x(function(b){return a.x(b.x)}).y(function(b){return a.y(b.y)}).interpolate(this.graph.interpolation).tension(this.tension)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Stack"),Rickshaw.Graph.Renderer.Stack=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"stack",fill:!0,stroke:!1,unstack:!1,seriesPathFactory:function(){var a=this.graph;return d3.svg.area().x(function(b){return a.x(b.x)}).y0(function(b){return a.y(b.y0)}).y1(function(b){return a.y(b.y+b.y0)}).interpolate(this.graph.interpolation).tension(this.tension)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Bar"),Rickshaw.Graph.Renderer.Bar=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"bar",gapSize:.05,unstack:!1,initialize:function($super,a){a=a||{},this.gapSize=a.gapSize||this.gapSize,$super(a)},domain:function($super){return this._barWidth=null,$super()},barWidth:function(){if(this._barWidth)return this._barWidth;var a=this.graph.stackedData||this.graph.stackData(),b=a.slice(-1).shift(),c={};for(var d=0;d<b.length-1;d++){var e=b[d+1].x-b[d].x;c[e]=c[e]||0,c[e]++}var f={count:0};return d3.keys(c).forEach(function(a){f.count<c[a]&&(f={count:c[a],magnitude:a})}),this._barWidth=this.graph.x(b[0].x+f.magnitude*(1-this.gapSize)),this._barWidth},render:function(){var a=this.graph;a.vis.selectAll("*").remove();var b=this.barWidth(),c=0,d=a.series.filter(function(a){return!a.disabled}).length,e=this.unstack?b/d:b;a.series.forEach(function(b){if(b.disabled)return;var d=a.vis.selectAll("path").data(b.stack).enter().append("svg:rect").attr("x",function(b){return a.x(b.x)+c}).attr("y",function(b){return a.y(b.y0+b.y)}).attr("width",e).attr("height",function(b){return a.y.magnitude(b.y)});Array.prototype.forEach.call(d[0],function(a){a.setAttribute("fill",b.color)}),this.unstack&&(c+=e)},this)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Area"),Rickshaw.Graph.Renderer.Area=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"area",unstack:!1,seriesPathFactory:function(){var a=this.graph;return d3.svg.area().x(function(b){return a.x(b.x)}).y0(function(b){return a.y(b.y0)}).y1(function(b){return a.y(b.y+b.y0)}).interpolate(a.interpolation).tension(this.tension)},seriesStrokeFactory:function(){var a=this.graph;return d3.svg.line().x(function(b){return a.x(b.x)}).y(function(b){return a.y(b.y+b.y0)}).interpolate(a.interpolation).tension(this.tension)},render:function(){var a=this.graph;a.vis.selectAll("*").remove();var b=a.vis.selectAll("path").data(this.graph.stackedData).enter().insert("svg:g","g");b.append("svg:path").attr("d",this.seriesPathFactory()).attr("class","area"),this.graph.stroke&&b.append("svg:path").attr("d",this.seriesStrokeFactory()).attr("class","line");var c=0;a.series.forEach(function(a){if(a.disabled)return;a.path=b[0][c++],this._styleSeries(a)},this)},_styleSeries:function(a){if(!a.path)return;d3.select(a.path).select(".area").attr("fill",a.color),this.graph.stroke&&d3.select(a.path).select(".line").attr("fill","none").attr("stroke",a.stroke||d3.interpolateRgb(a.color,"black")(.125)).attr("stroke-width",this.strokeWidth),a.className&&a.path.setAttribute("class",a.className)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.ScatterPlot"),Rickshaw.Graph.Renderer.ScatterPlot=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"scatterplot",unstack:!0,fill:!0,stroke:!1,padding:{top:.025,right:.025,bottom:0,left:.025},initialize:function($super,a){$super(a),this.dotSize=a.dotSize||4},render:function(){var a=this.graph;a.vis.selectAll("*").remove(),a.series.forEach(function(b){if(b.disabled)return;var c=a.vis.selectAll("path").data(b.stack).enter().append("svg:circle").attr("cx",function(b){return a.x(b.x)}).attr("cy",function(b){return a.y(b.y)}).attr("r",this.dotSize);Array.prototype.forEach.call(c[0],function(a){a.setAttribute("fill",b.color)})},this)}}),Rickshaw.namespace("Rickshaw.Graph.Smoother"),Rickshaw.Graph.Smoother=function(a){this.graph=a.graph,this.element=a.element;var b=this;this.aggregationScale=1,this.element&&$(function(){$(b.element).slider({min:1,max:100,slide:function(a,c){b.setScale(c.value),b.graph.update()}})}),b.graph.stackData.hooks.data.push({name:"smoother",orderPosition:50,f:function(a){var c=[];return a.forEach(function(a){var d=[];while(a.length){var e=0,f=0,g=a.splice(0,b.aggregationScale);g.forEach(function(a){e+=a.x/g.length,f+=a.y/g.length}),d.push({x:e,y:f})}c.push(d)}),c}}),this.setScale=function(a){if(a<1)throw"scale out of range: "+a;this.aggregationScale=a,this.graph.update()}},Rickshaw.namespace("Rickshaw.Graph.Unstacker"),Rickshaw.Graph.Unstacker=function(a){this.graph=a.graph;var b=this;this.graph.stackData.hooks.after.push({name:"unstacker",f:function(a){return b.graph.renderer.unstack?(a.forEach(function(a){a.forEach(function(a){a.y0=0})}),a):a}})},Rickshaw.namespace("Rickshaw.Series"),Rickshaw.Series=Rickshaw.Class.create(Array,{initialize:function(a,b,c){c=c||{},this.palette=new Rickshaw.Color.Palette(b),this.timeBase=typeof c.timeBase=="undefined"?Math.floor((new Date).getTime()/1e3):c.timeBase,a&&typeof a=="object"&&a instanceof Array&&a.forEach(function(a){this.addItem(a)},this)},addItem:function(a){if(typeof a.name=="undefined")throw"addItem() needs a name";a.color=a.color||this.palette.color(a.name),a.data=a.data||[],a.data.length==0&&this.length&&this.getIndex()>0?this[0].data.forEach(function(b){a.data.push({x:b.x,y:0})}):a.data.length==0&&a.data.push({x:this.timeBase-(this.timeInterval||0),y:0}),this.push(a),this.legend&&this.legend.addLine(this.itemByName(a.name))},addData:function(a){var b=this.getIndex();Rickshaw.keys(a).forEach(function(a){this.itemByName(a)||this.addItem({name:a})},this),this.forEach(function(c){c.data.push({x:(b*this.timeInterval||1)+this.timeBase,y:a[c.name]||0})},this)},getIndex:function(){return this[0]&&this[0].data&&this[0].data.length?this[0].data.length:0},itemByName:function(a){for(var b=0;b<this.length;b++)if(this[b].name==a)return this[b]},setTimeInterval:function(a){this.timeInterval=a/1e3},setTimeBase:function(a){this.timeBase=a},dump:function(){var a={timeBase:this.timeBase,timeInterval:this.timeInterval,items:[]};return this.forEach(function(b){var c={color:b.color,name:b.name,data:[]};b.data.forEach(function(a){c.data.push({x:a.x,y:a.y})}),a.items.push(c)}),a},load:function(a){a.timeInterval&&(this.timeInterval=a.timeInterval),a.timeBase&&(this.timeBase=a.timeBase),a.items&&a.items.forEach(function(a){this.push(a),this.legend&&this.legend.addLine(this.itemByName(a.name))},this)}}),Rickshaw.Series.zeroFill=function(a){var b,c=0,d=a.map(function(a){return a.data});while(c<Math.max.apply(null,d.map(function(a){return a.length})))b=Math.min.apply(null,d.filter(function(a){return a[c]}).map(function(a){return a[c].x})),d.forEach(function(a){(!a[c]||a[c].x!=b)&&a.splice(c,0,{x:b,y:0})}),c++},Rickshaw.namespace("Rickshaw.Series.FixedDuration"),Rickshaw.Series.FixedDuration=Rickshaw.Class.create(Rickshaw.Series,{initialize:function(a,b,c){var c=c||{};if(typeof c.timeInterval=="undefined")throw new Error("FixedDuration series requires timeInterval");if(typeof c.maxDataPoints=="undefined")throw new Error("FixedDuration series requires maxDataPoints");this.palette=new Rickshaw.Color.Palette(b),this.timeBase=typeof c.timeBase=="undefined"?Math.floor((new Date).getTime()/1e3):c.timeBase,this.setTimeInterval(c.timeInterval),this[0]&&this[0].data&&this[0].data.length?(this.currentSize=this[0].data.length,this.currentIndex=this[0].data.length):(this.currentSize=0,this.currentIndex=0),this.maxDataPoints=c.maxDataPoints,a&&typeof a=="object"&&a instanceof Array&&(a.forEach(function(a){this.addItem(a)},this),this.currentSize+=1,this.currentIndex+=1),this.timeBase-=(this.maxDataPoints-this.currentSize)*this.timeInterval;if(typeof this.maxDataPoints!="undefined"&&this.currentSize<this.maxDataPoints)for(var d=this.maxDataPoints-this.currentSize-1;d>0;d--)this.currentSize+=1,this.currentIndex+=1,this.forEach(function(a){a.data.unshift({x:((d-1)*this.timeInterval||1)+this.timeBase,y:0,i:d})},this)},addData:function($super,a){$super(a),this.currentSize+=1,this.currentIndex+=1;if(this.maxDataPoints!==undefined)while(this.currentSize>this.maxDataPoints)this.dropData()},dropData:function(){this.forEach(function(a){a.data.splice(0,1)}),this.currentSize-=1},getIndex:function(){return this.currentIndex}});
95 src/js/Rickshaw.Class.js
View
@@ -125,36 +125,6 @@ var Class = (function() {
return true;
})();
- /**
- * Class.create([superclass][, methods...]) -> Class
- * - superclass (Class): The optional superclass to inherit methods from.
- * - methods (Object): An object whose properties will be "mixed-in" to the
- * new class. Any number of mixins can be added; later mixins take
- * precedence.
- *
- * [[Class.create]] creates a class and returns a constructor function for
- * instances of the class. Calling the constructor function (typically as
- * part of a `new` statement) will invoke the class's `initialize` method.
- *
- * [[Class.create]] accepts two kinds of arguments. If the first argument is
- * a [[Class]], it's used as the new class's superclass, and all its methods
- * are inherited. Otherwise, any arguments passed are treated as objects,
- * and their methods are copied over ("mixed in") as instance methods of the
- * new class. In cases of method name overlap, later arguments take
- * precedence over earlier arguments.
- *
- * If a subclass overrides an instance method declared in a superclass, the
- * subclass's method can still access the original method. To do so, declare
- * the subclass's method as normal, but insert `$super` as the first
- * argument. This makes `$super` available as a method for use within the
- * function.
- *
- * To extend a class after it has been defined, use [[Class#addMethods]].
- *
- * For details, see the
- * [inheritance tutorial](http://prototypejs.org/learn/class-inheritance)
- * on the Prototype website.
- **/
function subclass() {};
function create() {
var parent = null, properties = [].slice.apply(arguments);
@@ -185,71 +155,6 @@ var Class = (function() {
return klass;
}
- /**
- * Class#addMethods(methods) -> Class
- * - methods (Object): The methods to add to the class.
- *
- * Adds methods to an existing class.
- *
- * [[Class#addMethods]] is a method available on classes that have been
- * defined with [[Class.create]]. It can be used to add new instance methods
- * to that class, or overwrite existing methods, after the class has been
- * defined.
- *
- * New methods propagate down the inheritance chain. If the class has
- * subclasses, those subclasses will receive the new methods &mdash; even in
- * the context of `$super` calls. The new methods also propagate to instances
- * of the class and of all its subclasses, even those that have already been
- * instantiated.
- *
- * ##### Examples
- *
- * var Animal = Class.create({
- * initialize: function(name, sound) {
- * this.name = name;
- * this.sound = sound;
- * },
- *
- * speak: function() {
- * alert(this.name + " says: " + this.sound + "!");
- * }
- * });
- *
- * // subclassing Animal
- * var Snake = Class.create(Animal, {
- * initialize: function($super, name) {
- * $super(name, 'hissssssssss');
- * }
- * });
- *
- * var ringneck = new Snake("Ringneck");
- * ringneck.speak();
- *
- * //-> alerts "Ringneck says: hissssssss!"
- *
- * // adding Snake#speak (with a supercall)
- * Snake.addMethods({
- * speak: function($super) {
- * $super();
- * alert("You should probably run. He looks really mad.");
- * }
- * });
- *
- * ringneck.speak();
- * //-> alerts "Ringneck says: hissssssss!"
- * //-> alerts "You should probably run. He looks really mad."
- *
- * // redefining Animal#speak
- * Animal.addMethods({
- * speak: function() {
- * alert(this.name + 'snarls: ' + this.sound + '!');
- * }
- * });
- *
- * ringneck.speak();
- * //-> alerts "Ringneck snarls: hissssssss!"
- * //-> alerts "You should probably run. He looks really mad."
- **/
function addMethods(source) {
var ancestor = this.superclass && this.superclass.prototype,
properties = keys(source);
74 src/js/Rickshaw.Graph.Renderer.Area.js
View
@@ -1,65 +1,40 @@
Rickshaw.namespace('Rickshaw.Graph.Renderer.Area');
-Rickshaw.Graph.Renderer.Area = function(args) {
+Rickshaw.Graph.Renderer.Area = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var graph = this.graph = args.graph;
- var self = this;
+ name: 'area',
+ unstack: false,
- this.tension = 0.8;
- this.strokeWidth = 2;
- this.yBerth = 1.025;
+ seriesPathFactory: function() {
- this.name = 'area';
-
- this.unstack = false;
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
-
- this.seriesPathFactory = function() {
+ var graph = this.graph;
return d3.svg.area()
.x( function(d) { return graph.x(d.x) } )
.y0( function(d) { return graph.y(d.y0) } )
- .y1( function(d) { return graph.y(d.y + d.y0)} )
- .interpolate(this.graph.interpolation).tension(this.tension)
- }
+ .y1( function(d) { return graph.y(d.y + d.y0) } )
+ .interpolate(graph.interpolation).tension(this.tension);
+ },
+
+ seriesStrokeFactory: function() {
- this.seriesLineFactory = function() {
+ var graph = this.graph;
return d3.svg.line()
.x( function(d) { return graph.x(d.x) } )
- .y( function(d) { return graph.y(d.y + d.y0)} )
- .interpolate(this.graph.interpolation).tension(this.tension)
- }
-
- this.domain = function() {
-
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
+ .y( function(d) { return graph.y(d.y + d.y0) } )
+ .interpolate(graph.interpolation).tension(this.tension);
+ },
- var topSeriesData = this.unstack ? stackedData : [ stackedData.slice(-1).shift() ];
+ render: function() {
- topSeriesData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y + d.y0 );
- } );
- } );
-
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
-
- var yMin = 0;
- var yMax = d3.max( values ) * this.yBerth;
-
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
-
- this.render = function() {
+ var graph = this.graph;
graph.vis.selectAll('*').remove();
var nodes = graph.vis.selectAll("path")
- .data(graph.stackedData)
- .enter().insert("svg:g", 'g')
+ .data(this.graph.stackedData)
+ .enter().insert("svg:g", 'g');
nodes.append("svg:path")
.attr("d", this.seriesPathFactory())
@@ -67,7 +42,7 @@ Rickshaw.Graph.Renderer.Area = function(args) {
if (this.graph.stroke) {
nodes.append("svg:path")
- .attr("d", this.seriesLineFactory())
+ .attr("d", this.seriesStrokeFactory())
.attr("class", 'line');
}
@@ -75,11 +50,11 @@ Rickshaw.Graph.Renderer.Area = function(args) {
graph.series.forEach( function(series) {
if (series.disabled) return;
series.path = nodes[0][i++];
- self._styleSeries(series);
- } );
- }
+ this._styleSeries(series);
+ }, this );
+ },
- this._styleSeries = function(series) {
+ _styleSeries: function(series) {
if (!series.path) return;
@@ -97,4 +72,5 @@ Rickshaw.Graph.Renderer.Area = function(args) {
series.path.setAttribute('class', series.className);
}
}
-}
+} );
+
67 src/js/Rickshaw.Graph.Renderer.Bar.js
View
@@ -1,45 +1,27 @@
Rickshaw.namespace('Rickshaw.Graph.Renderer.Bar');
-Rickshaw.Graph.Renderer.Bar = function(args) {
+Rickshaw.Graph.Renderer.Bar = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var graph = this.graph = args.graph;
- var self = this;
+ name: 'bar',
+ gapSize: 0.05,
+ unstack: false,
- this.name = 'bar';
- this.gapSize = args.gapSize || 0.05;
-
- this.unstack = false;
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
-
- this.domain = function() {
-
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
-
- var topSeriesData = this.unstack ? stackedData : [ stackedData.slice(-1).shift() ];
-
- topSeriesData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y + d.y0 );
- } );
- } );
-
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
-
- var yMin = 0;
- var yMax = d3.max( values );
+ initialize: function($super, args) {
+ args = args || {};
+ this.gapSize = args.gapSize || this.gapSize;
+ $super(args);
+ },
+ domain: function($super) {
this._barWidth = null;
+ return $super();
+ },
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
-
- this.barWidth = function() {
+ barWidth: function() {
if (this._barWidth) return this._barWidth;
- var stackedData = graph.stackedData || graph.stackData();
+ var stackedData = this.graph.stackedData || this.graph.stackData();
var data = stackedData.slice(-1).shift();
var intervalCounts = {};
@@ -66,17 +48,18 @@ Rickshaw.Graph.Renderer.Bar = function(args) {
this._barWidth = this.graph.x(data[0].x + frequentInterval.magnitude * (1 - this.gapSize));
return this._barWidth;
- }
+ },
- this.render = function() {
+ render: function() {
+
+ var graph = this.graph;
graph.vis.selectAll('*').remove();
- var barsPerSlot = this.unstack ? this.graph.series.length : 1;
var barWidth = this.barWidth();
var barXOffset = 0;
- var activeSeriesCount = graph.series.filter( function(s) { return !s.disabled } ).length;
+ var activeSeriesCount = graph.series.filter( function(s) { return !s.disabled; } ).length;
var seriesBarWidth = this.unstack ? barWidth / activeSeriesCount : barWidth;
graph.series.forEach( function(series) {
@@ -95,15 +78,9 @@ Rickshaw.Graph.Renderer.Bar = function(args) {
n.setAttribute('fill', series.color);
} );
- if (self.unstack) barXOffset += seriesBarWidth;
+ if (this.unstack) barXOffset += seriesBarWidth;
- } );
+ }, this );
}
+} );
- this._styleSeries = function(series) {
- if (!series.path) return;
- series.path.setAttribute('fill', series.color);
- series.path.setAttribute('stroke-width', 2);
- series.path.setAttribute('class', series.className);
- }
-}
70 src/js/Rickshaw.Graph.Renderer.Line.js
View
@@ -1,64 +1,20 @@
Rickshaw.namespace('Rickshaw.Graph.Renderer.Line');
-Rickshaw.Graph.Renderer.Line = function(args) {
+Rickshaw.Graph.Renderer.Line = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var graph = this.graph = args.graph;
- var self = this;
+ name: 'line',
+ unstack: true,
+ fill: false,
+ stroke: true,
- this.name = 'line';
- this.unstack = true;
+ seriesPathFactory: function() {
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
+ var graph = this.graph;
- this.seriesPathFactory = function() {
-
- return d3.svg.line()
- .x( function(d) { return graph.x(d.x) } )
- .y( function(d) { return graph.y(d.y) } )
- .interpolate(this.graph.interpolation).tension(0.8);
- }
-
- this.domain = function() {
-
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
-
- stackedData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y )
- } );
- } );
-
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
-
- var yMin = 0;
- var yMax = d3.max( values );
-
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
-
- this.render = function() {
-
- graph.vis.selectAll('*').remove();
-
- var nodes = this.graph.vis.selectAll("path")
- .data(this.graph.stackedData)
- .enter().append("svg:path")
- .attr("d", this.seriesPathFactory());
-
- var i = 0;
- graph.series.forEach( function(series) {
- if (series.disabled) return;
- series.path = nodes[0][i++];
- self._styleSeries(series);
- } );
- }
-
- this._styleSeries = function(series) {
- series.path.setAttribute('fill', 'none');
- series.path.setAttribute('stroke', series.color);
- series.path.setAttribute('stroke-width', 2);
- }
-}
+ return d3.svg.line()
+ .x( function(d) { return graph.x(d.x) } )
+ .y( function(d) { return graph.y(d.y) } )
+ .interpolate(this.graph.interpolation).tension(this.tension);
+ }
+} );
81 src/js/Rickshaw.Graph.Renderer.ScatterPlot.js
View
@@ -1,68 +1,39 @@
Rickshaw.namespace('Rickshaw.Graph.Renderer.ScatterPlot');
-Rickshaw.Graph.Renderer.ScatterPlot = function(args) {
+Rickshaw.Graph.Renderer.ScatterPlot = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var graph = this.graph = args.graph;
- var self = this;
+ name: 'scatterplot',
+ unstack: true,
+ fill: true,
+ stroke: false,
+ padding: { top: 0.025, right: 0.025, bottom: 0, left: 0.025 },
- this.name = 'scatterplot';
- this.unstack = true;
+ initialize: function($super, args) {
+ $super(args);
this.dotSize = args.dotSize || 4;
+ },
- this.xBerth = 1.0125;
- this.yBerth = 1.0125;
+ render: function() {
- graph.unstacker = graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: graph } );
+ var graph = this.graph;
- this.domain = function() {
+ graph.vis.selectAll('*').remove();
- var values = [];
- var stackedData = graph.stackedData || graph.stackData();
-
- stackedData.forEach( function(series) {
- series.forEach( function(d) {
- values.push( d.y )
- } );
- } );
-
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
-
- xMin -= (xMax - xMin) * (this.xBerth - 1);
- xMax += (xMax - xMin) * (this.xBerth - 1);
-
- var yMin = 0;
- var yMax = d3.max( values ) * this.yBerth;
-
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
+ graph.series.forEach( function(series) {
- this.render = function() {
+ if (series.disabled) return;
- graph.vis.selectAll('*').remove();
+ var nodes = graph.vis.selectAll("path")
+ .data(series.stack)
+ .enter().append("svg:circle")
+ .attr("cx", function(d) { return graph.x(d.x) })
+ .attr("cy", function(d) { return graph.y(d.y) })
+ .attr("r", this.dotSize);
- graph.series.forEach( function(series) {
-
- if (series.disabled) return;
-
- var nodes = graph.vis.selectAll("path")
- .data(series.stack)
- .enter().append("svg:circle")
- .attr("cx", function(d) { return graph.x(d.x) })
- .attr("cy", function(d) { return graph.y(d.y) })
- .attr("r", this.dotSize);
-
- Array.prototype.forEach.call(nodes[0], function(n) {
- n.setAttribute('fill', series.color);
- } );
-
- }, this );
- }
+ Array.prototype.forEach.call(nodes[0], function(n) {
+ n.setAttribute('fill', series.color);
+ } );
- this._styleSeries = function(series) {
- if (!series.path) return;
- series.path.setAttribute('fill', series.color);
- series.path.setAttribute('stroke-width', 2);
- series.path.setAttribute('class', series.className);
- }
-}
+ }, this );
+ }
+} );
65 src/js/Rickshaw.Graph.Renderer.Stack.js
View
@@ -1,58 +1,21 @@
Rickshaw.namespace('Rickshaw.Graph.Renderer.Stack');
-Rickshaw.Graph.Renderer.Stack = function(args) {
+Rickshaw.Graph.Renderer.Stack = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
- var graph = this.graph = args.graph;
- var self = this;
+ name: 'stack',
+ fill: true,
+ stroke: false,
+ unstack: false,
- this.name = 'stack';
+ seriesPathFactory: function() {
- this.seriesPathFactory = function() {
+ var graph = this.graph;
- return d3.svg.area()
- .x( function(d) { return graph.x(d.x) } )
- .y0( function(d) { return graph.y(d.y0) } )
- .y1( function(d) { return graph.y(d.y + d.y0)} )
- .interpolate(this.graph.interpolation).tension(0.8);
- }
+ return d3.svg.area()
+ .x( function(d) { return graph.x(d.x) } )
+ .y0( function(d) { return graph.y(d.y0) } )
+ .y1( function(d) { return graph.y(d.y + d.y0) } )
+ .interpolate(this.graph.interpolation).tension(this.tension);
+ }
+} );
- this.domain = function() {
-
- var stackedData = graph.stackedData || graph.stackData();
-
- var topSeriesData = stackedData.slice(-1).shift();
-
- var xMin = stackedData[0][0].x;
- var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
-
- var yMin = 0;
- var yMax = d3.max( topSeriesData, function(d) { return d.y + d.y0 } );
-
- return { x: [xMin, xMax], y: [yMin, yMax] };
- }
-
- this.render = function() {
-
- graph.vis.selectAll('*').remove();
-
- var nodes = graph.vis.selectAll("path")
- .data(graph.stackedData)
- .enter().append("svg:path")
- .attr("d", this.seriesPathFactory());
-
- var i = 0;
- graph.series.forEach( function(series) {
- if (series.disabled) return;
- series.path = nodes[0][i++];
- self._styleSeries(series);
- } );
-
- }
-
- this._styleSeries = function(series) {
- if (!series.path) return;
- series.path.setAttribute('fill', series.color);
- series.path.setAttribute('stroke-width', 2);
- series.path.setAttribute('class', series.className);
- }
-}
96 src/js/Rickshaw.Graph.Renderer.js
View
@@ -0,0 +1,96 @@
+Rickshaw.namespace("Rickshaw.Graph.Renderer");
+
+Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
+
+ name: undefined,
+ tension: 0.8,
+ strokeWidth: 2,
+ unstack: true,
+ padding: { top: 0.025, right: 0, bottom: 0, left: 0 },
+ stroke: false,
+ fill: false,
+
+ initialize: function(args) {
+ this.graph = args.graph;
+ this.tension = args.tension || this.tension;
+ this.graph.unstacker = this.graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: this.graph } );
+
+ },
+
+ seriesPathFactory: function() {
+ //implement in subclass
+ },
+
+ seriesStrokeFactory: function() {
+ // implement in subclass
+ },
+
+ domain: function() {
+
+ var values = [];
+ var stackedData = this.graph.stackedData || this.graph.stackData();
+
+ var topSeriesData = this.unstack ? stackedData : [ stackedData.slice(-1).shift() ];
+
+ topSeriesData.forEach( function(series) {
+ series.forEach( function(d) {
+ values.push( d.y + d.y0 );
+ } );
+ } );
+
+ var xMin = stackedData[0][0].x;
+ var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
+
+ xMin -= (xMax - xMin) * (this.padding.left);
+ xMax += (xMax - xMin) * (this.padding.right);
+
+ var yMin = 0;
+ var yMax = d3.max( values ) * (1 + this.padding.top);
+
+ return { x: [xMin, xMax], y: [yMin, yMax] };
+ },
+
+ render: function() {
+
+ var graph = this.graph;
+
+ graph.vis.selectAll('*').remove();
+
+ var nodes = graph.vis.selectAll("path")
+ .data(this.graph.stackedData)
+ .enter().append("svg:path")
+ .attr("d", this.seriesPathFactory());
+
+ var i = 0;
+ graph.series.forEach( function(series) {
+ if (series.disabled) return;
+ series.path = nodes[0][i++];
+ this._styleSeries(series);
+ }, this );
+ },
+
+ _styleSeries: function(series) {
+
+
+ var fill = this.fill ? series.color : 'none';
+ var stroke = this.stroke ? series.color : 'none';
+
+ series.path.setAttribute('fill', fill);
+ series.path.setAttribute('stroke', stroke);
+ series.path.setAttribute('stroke-width', this.strokeWidth);
+ series.path.setAttribute('class', series.className);
+ },
+
+ setStrokeWidth: function(strokeWidth) {
+ if (strokeWidth !== undefined) {
+ this.strokeWidth = strokeWidth;
+ }
+ },
+
+ setTension: function(tension) {
+ if (tension !== undefined) {
+ this.tension = tension;
+ }
+ }
+} );
+
2  src/js/Rickshaw.Graph.Unstacker.js
View
@@ -20,5 +20,5 @@ Rickshaw.Graph.Unstacker = function(args) {
return data;
}
} );
-}
+};
3  src/js/Rickshaw.js
View
@@ -22,4 +22,5 @@ Rickshaw = {
for (var key in obj) keys.push(key);
return keys;
}
-}
+};
+
Please sign in to comment.
Something went wrong with that request. Please try again.