Skip to content
Browse files

update built libs and add non-minified versions for easier debugging

  • Loading branch information...
1 parent 5a6dfad commit 043f6cbca6053bba90144167fadec7155de32ffb @dchester dchester committed Jan 21, 2012
Showing with 2,098 additions and 4 deletions.
  1. +0 −2 .gitignore
  2. +286 −0 rickshaw.css
  3. +1,810 −0 rickshaw.js
  4. +1 −1 rickshaw.min.css
  5. +1 −1 rickshaw.min.js
View
2 .gitignore
@@ -1,5 +1,3 @@
*.log
*swp
node_modules
-rickshaw.css
-rickshaw.js
View
286 rickshaw.css
@@ -0,0 +1,286 @@
+.rickshaw_graph .detail {
+ pointer-events: none;
+ position: absolute;
+ top: 0;
+ z-index: 2;
+ background: rgba(0, 0, 0, 0.1);
+ bottom: 0;
+ width: 1px;
+ transition: opacity 0.25s linear;
+ -moz-transition: opacity 0.25s linear;
+ -o-transition: opacity 0.25s linear;
+ -webkit-transition: opacity 0.25s linear;
+}
+.rickshaw_graph .detail.inactive {
+ opacity: 0;
+}
+.rickshaw_graph .detail .item.active {
+ opacity: 1;
+}
+.rickshaw_graph .detail .x_label {
+ font-family: Arial, sans-serif;
+ border-radius: 3px;
+ padding: 6px;
+ opacity: 0.5;
+ border: 1px solid #e0e0e0;
+ font-size: 12px;
+ position: absolute;
+ background: white;
+ white-space: nowrap;
+}
+.rickshaw_graph .detail .item {
+ position: absolute;
+ z-index: 2;
+ border-radius: 3px;
+ padding: 0.25em;
+ font-size: 12px;
+ font-family: Arial, sans-serif;
+ opacity: 0;
+ background: rgba(0, 0, 0, 0.4);
+ color: white;
+ border: 1px solid rgba(0, 0, 0, 0.4);
+ margin-left: 1em;
+ margin-top: -1em;
+ white-space: nowrap;
+}
+.rickshaw_graph .detail .item.active {
+ opacity: 1;
+ background: rgba(0, 0, 0, 0.8);
+}
+.rickshaw_graph .detail .item:before {
+ content: "\25c2";
+ position: absolute;
+ left: -0.5em;
+ color: rgba(0, 0, 0, 0.7);
+ width: 0;
+}
+.rickshaw_graph .detail .dot {
+ width: 5px;
+ height: 5px;
+ margin-left: -2px;
+ margin-top: -3px;
+ border-radius: 3px;
+ position: absolute;
+}
+.rickshaw_graph .detail .dot.active {
+ background: rgba(255, 255, 255, 0.8);
+ box-shadow: 0 0 1px rgba(0, 0, 0, 0.5);
+}
+/* graph */
+
+.rickshaw_graph {
+ position: relative;
+}
+.rickshaw_graph svg {
+ display: block;
+ overflow: hidden;
+}
+
+/* ticks */
+
+.rickshaw_graph .x_tick {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ width: 0px;
+ border-left: 1px dotted rgba(0, 0, 0, 0.2);
+ pointer-events: none;
+}
+.rickshaw_graph .x_tick .title {
+ position: absolute;
+ font-size: 12px;
+ font-family: Arial, sans-serif;
+ opacity: 0.5;
+ white-space: nowrap;
+ margin-left: 3px;
+ bottom: 1px;
+}
+
+/* annotations */
+
+.rickshaw_annotation_timeline {
+ height: 1px;
+ border-top: 1px solid #e0e0e0;
+ margin-top: 10px;
+ position: relative;
+}
+.rickshaw_annotation_timeline .annotation {
+ position: absolute;
+ height: 6px;
+ width: 6px;
+ margin-left: -2px;
+ top: -3px;
+ border-radius: 5px;
+ background-color: rgba(0, 0, 0, 0.25);
+}
+.rickshaw_graph .annotation_line {
+ position: absolute;
+ top: 0;
+ bottom: -6px;
+ width: 0px;
+ border-left: 2px solid rgba(0, 0, 0, 0.3);
+ display: none;
+}
+.rickshaw_graph .annotation_line.active {
+ display: block;
+}
+.rickshaw_annotation_timeline .annotation .content {
+ background: white;
+ color: black;
+ opacity: 0.9;
+ padding: 5px 5px;
+ box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
+ border-radius: 3px;
+ position: relative;
+ z-index: 20;
+ font-size: 12px;
+ padding: 6px 8px 8px;
+ top: 18px;
+ left: -11px;
+ width: 160px;
+ display: none;
+ cursor: pointer;
+}
+.rickshaw_annotation_timeline .annotation .content:before {
+ content: "\25b2";
+ position: absolute;
+ top: -11px;
+ color: white;
+ text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.8);
+}
+.rickshaw_annotation_timeline .annotation.active,
+.rickshaw_annotation_timeline .annotation:hover {
+ background-color: rgba(0, 0, 0, 0.8);
+ cursor: none;
+}
+.rickshaw_annotation_timeline .annotation .content:hover {
+ z-index: 50;
+}
+.rickshaw_annotation_timeline .annotation.active .content {
+ display: block;
+}
+.rickshaw_annotation_timeline .annotation:hover .content {
+ display: block;
+ z-index: 50;
+}
+.rickshaw_graph .y_axis {
+ fill: none;
+}
+.rickshaw_graph .y_ticks .tick {
+ stroke: rgba(0, 0, 0, 0.16);
+ stroke-width: 2px;
+ shape-rendering: crisp-edges;
+ pointer-events: none;
+}
+.rickshaw_graph .y_grid .tick {
+ z-index: -1;
+ stroke: rgba(0, 0, 0, 0.20);
+ stroke-width: 1px;
+ stroke-dasharray: 1 1;
+}
+.rickshaw_graph .y_grid path {
+ fill: none;
+ stroke: none;
+}
+.rickshaw_graph .y_ticks path {
+ fill: none;
+ stroke: #808080;
+}
+.rickshaw_graph .y_ticks text {
+ opacity: 0.5;
+ font-size: 12px;
+ pointer-events: none;
+}
+.rickshaw_graph .x_tick.glow .title,
+.rickshaw_graph .y_ticks.glow text {
+ fill: black;
+ color: black;
+ text-shadow:
+ -1px 1px 0 rgba(255, 255, 255, 0.1),
+ 1px -1px 0 rgba(255, 255, 255, 0.1),
+ 1px 1px 0 rgba(255, 255, 255, 0.1),
+ 0px 1px 0 rgba(255, 255, 255, 0.1),
+ 0px -1px 0 rgba(255, 255, 255, 0.1),
+ 1px 0px 0 rgba(255, 255, 255, 0.1),
+ -1px 0px 0 rgba(255, 255, 255, 0.1),
+ -1px -1px 0 rgba(255, 255, 255, 0.1);
+}
+.rickshaw_graph .x_tick.inverse .title,
+.rickshaw_graph .y_ticks.inverse text {
+ fill: white;
+ color: white;
+ text-shadow:
+ -1px 1px 0 rgba(0, 0, 0, 0.8),
+ 1px -1px 0 rgba(0, 0, 0, 0.8),
+ 1px 1px 0 rgba(0, 0, 0, 0.8),
+ 0px 1px 0 rgba(0, 0, 0, 0.8),
+ 0px -1px 0 rgba(0, 0, 0, 0.8),
+ 1px 0px 0 rgba(0, 0, 0, 0.8),
+ -1px 0px 0 rgba(0, 0, 0, 0.8),
+ -1px -1px 0 rgba(0, 0, 0, 0.8);
+}
+.rickshaw_legend {
+ font-family: Arial;
+ font-size: 12px;
+ color: white;
+ background: #404040;
+ display: inline-block;
+ padding: 12px 5px;
+ border-radius: 2px;
+ position: relative;
+}
+.rickshaw_legend:hover {
+ z-index: 10;
+}
+.rickshaw_legend .swatch {
+ width: 10px;
+ height: 10px;
+ border: 1px solid rgba(0, 0, 0, 0.2);
+}
+.rickshaw_legend .line {
+ clear: both;
+ line-height: 140%;
+ padding-right: 15px;
+}
+.rickshaw_legend .line .swatch {
+ display: inline-block;
+ margin-right: 3px;
+ border-radius: 2px;
+}
+.rickshaw_legend .label {
+ white-space: nowrap;
+ display: inline;
+}
+.rickshaw_legend .action:hover {
+ opacity: 0.6;
+}
+.rickshaw_legend .action {
+ margin-right: 0.2em;
+ font-size: 10px;
+ opacity: 0.2;
+ cursor: pointer;
+ font-size: 14px;
+}
+.rickshaw_legend .line.disabled {
+ opacity: 0.4;
+}
+.rickshaw_legend ul {
+ list-style-type: none;
+ margin: 0;
+ padding: 0;
+ margin: 2px;
+ cursor: pointer;
+}
+.rickshaw_legend li {
+ padding: 0 0 0 2px;
+ min-width: 80px;
+ white-space: nowrap;
+}
+.rickshaw_legend li:hover {
+ background: rgba(255, 255, 255, 0.08);
+ border-radius: 3px;
+}
+.rickshaw_legend li:active {
+ background: rgba(255, 255, 255, 0.2);
+ border-radius: 3px;
+}
View
1,810 rickshaw.js
@@ -0,0 +1,1810 @@
+Rickshaw = {
+
+ namespace: function(namespace, obj) {
+
+ var parts = namespace.split('.');
+
+ // for rudimentary compatibility w/ node
+ var root = typeof global != 'undefined' ? global : window;
+
+ var parent = root.Rickshaw;
+
+ for(var i = 1, length = parts.length; i < length; i++) {
+ currentPart = parts[i];
+ parent[currentPart] = parent[currentPart] || {};
+ parent = parent[currentPart];
+ }
+ return parent;
+ },
+
+ keys: function(obj) {
+ var keys = [];
+ for (var key in obj) keys.push(key);
+ return keys;
+ }
+}
+Rickshaw.namespace('Rickshaw.Compat.ClassList');
+
+Rickshaw.Compat.ClassList = function() {
+
+ /* adapted from http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
+
+ if (typeof document !== "undefined" && !("classList" in document.createElement("a"))) {
+
+ (function (view) {
+
+ "use strict";
+
+ var
+ classListProp = "classList"
+ , protoProp = "prototype"
+ , elemCtrProto = (view.HTMLElement || view.Element)[protoProp]
+ , objCtr = Object
+ , strTrim = String[protoProp].trim || function () {
+ return this.replace(/^\s+|\s+$/g, "");
+ }
+ , arrIndexOf = Array[protoProp].indexOf || function (item) {
+ var
+ i = 0
+ , len = this.length
+ ;
+ for (; i < len; i++) {
+ if (i in this && this[i] === item) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ // Vendors: please allow content code to instantiate DOMExceptions
+ , DOMEx = function (type, message) {
+ this.name = type;
+ this.code = DOMException[type];
+ this.message = message;
+ }
+ , checkTokenAndGetIndex = function (classList, token) {
+ if (token === "") {
+ throw new DOMEx(
+ "SYNTAX_ERR"
+ , "An invalid or illegal string was specified"
+ );
+ }
+ if (/\s/.test(token)) {
+ throw new DOMEx(
+ "INVALID_CHARACTER_ERR"
+ , "String contains an invalid character"
+ );
+ }
+ return arrIndexOf.call(classList, token);
+ }
+ , ClassList = function (elem) {
+ var
+ trimmedClasses = strTrim.call(elem.className)
+ , classes = trimmedClasses ? trimmedClasses.split(/\s+/) : []
+ , i = 0
+ , len = classes.length
+ ;
+ for (; i < len; i++) {
+ this.push(classes[i]);
+ }
+ this._updateClassName = function () {
+ elem.className = this.toString();
+ };
+ }
+ , classListProto = ClassList[protoProp] = []
+ , classListGetter = function () {
+ return new ClassList(this);
+ }
+ ;
+ // Most DOMException implementations don't allow calling DOMException's toString()
+ // on non-DOMExceptions. Error's toString() is sufficient here.
+ DOMEx[protoProp] = Error[protoProp];
+ classListProto.item = function (i) {
+ return this[i] || null;
+ };
+ classListProto.contains = function (token) {
+ token += "";
+ return checkTokenAndGetIndex(this, token) !== -1;
+ };
+ classListProto.add = function (token) {
+ token += "";
+ if (checkTokenAndGetIndex(this, token) === -1) {
+ this.push(token);
+ this._updateClassName();
+ }
+ };
+ classListProto.remove = function (token) {
+ token += "";
+ var index = checkTokenAndGetIndex(this, token);
+ if (index !== -1) {
+ this.splice(index, 1);
+ this._updateClassName();
+ }
+ };
+ classListProto.toggle = function (token) {
+ token += "";
+ if (checkTokenAndGetIndex(this, token) === -1) {
+ this.add(token);
+ } else {
+ this.remove(token);
+ }
+ };
+ classListProto.toString = function () {
+ return this.join(" ");
+ };
+
+ if (objCtr.defineProperty) {
+ var classListPropDesc = {
+ get: classListGetter
+ , enumerable: true
+ , configurable: true
+ };
+ try {
+ objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
+ } catch (ex) { // IE 8 doesn't support enumerable:true
+ if (ex.number === -0x7FF5EC54) {
+ classListPropDesc.enumerable = false;
+ objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
+ }
+ }
+ } else if (objCtr[protoProp].__defineGetter__) {
+ elemCtrProto.__defineGetter__(classListProp, classListGetter);
+ }
+
+ }(self));
+
+ }
+};
+
+if ( (typeof RICKSHAW_NO_COMPAT !== "undefined" && !RICKSHAW_NO_COMPAT) || typeof RICKSHAW_NO_COMPAT === "undefined") {
+ new Rickshaw.Compat.ClassList();
+}
+Rickshaw.namespace('Rickshaw.Graph');
+
+Rickshaw.Graph = function(args) {
+
+ this.element = args.element;
+ this.interpolation = args.interpolation || 'cardinal';
+ this.series = args.series;
+ this.offset = 'zero';
+
+ var style = window.getComputedStyle(this.element, null);
+ var elementWidth = parseInt(style.getPropertyValue('width'));
+ var elementHeight = parseInt(style.getPropertyValue('height'));
+
+ this.width = args.width || elementWidth || 400;
+ this.height = args.height || elementHeight || 250;
+
+ this.window = {};
+
+ this.updateCallbacks = [];
+
+ var self = this;
+
+ this.initialize = function(args) {
+
+ this.validateSeries(args.series);
+
+ this.series.active = function() { return self.series.filter( function(s) { return !s.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 renderers = [
+ Rickshaw.Graph.Renderer.Stack,
+ Rickshaw.Graph.Renderer.Line,
+ Rickshaw.Graph.Renderer.Bar
+ ];
+
+ renderers.forEach( function(r) {
+ if (!r) return;
+ self.registerRenderer(new r( { graph: self } ));
+ } );
+
+ this.setRenderer(args.renderer || 'stack');
+ this.discoverRange();
+ }
+
+ this.validateSeries = function(series) {
+
+ if (!(series instanceof Array) && !(series instanceof Rickshaw.Series)) {
+ var seriesSignature = Object.prototype.toString.apply(series);
+ throw "series is not an array: " + seriesSignature;
+ }
+
+ var pointsCount;
+
+ series.forEach( function(s) {
+
+ if (!(s instanceof Object)) {
+ throw "series element is not an object: " + s;
+ }
+ if (!(s.data)) {
+ throw "series has no data: " + JSON.stringify(s);
+ }
+ if (!(s.data instanceof Array)) {
+ throw "series data is not an array: " + JSON.stringify(s.data);
+ }
+
+ pointsCount = pointsCount || s.data.length;
+
+ if (pointsCount && s.data.length != pointsCount) {
+ throw "series cannot have differing numbers of points: " +
+ pointsCount + " vs " + s.data.length + "; see Rickshaw.Series.zeroFill()";
+ }
+
+ var dataTypeX = typeof s.data[0].x;
+ var dataTypeY = typeof s.data[0].y;
+
+ if (dataTypeX != 'number' || dataTypeY != 'number') {
+ throw "x and y properties of points should be numbers instead of " +
+ dataTypeX + " and " + dataTypeY;
+ }
+ } );
+ }
+
+ this.dataDomain = function() {
+
+ // take from the first series
+ var data = this.series[0].data;
+
+ return [ data[0].x, data.slice(-1).shift().x ];
+
+ }
+
+ this.discoverRange = function() {
+
+ var domain = this.renderer.domain();
+
+ this.x = d3.scale.linear().domain(domain.x).range([0, this.width]);
+
+ this.y = d3.scale.linear().domain(domain.y).range([this.height, 0]);
+ this.y.magnitude = d3.scale.linear().domain(domain.y).range([0, this.height]);
+
+ }
+
+ this.render = function() {
+
+ var stackedData = this.stackData();
+ this.discoverRange();
+
+ this.renderer.render();
+
+ this.updateCallbacks.forEach( function(callback) {
+ callback();
+ } );
+ }
+
+ this.update = this.render;
+
+ this.stackData = function() {
+
+ var data = this.series.active()
+ .map( function(d) { return d.data } )
+ .map( function(d) { return d.filter( function(d) { return this._slice(d) }, this ) }, this);
+
+ this.stackData.hooks.data.forEach( function(entry) {
+ data = entry.f.apply(self, [data]);
+ } );
+
+ var layout = d3.layout.stack();
+ layout.offset( self.offset );
+
+ var stackedData = layout(data);
+
+ this.stackData.hooks.after.forEach( function(entry) {
+ stackedData = entry.f.apply(self, [data]);
+ } );
+
+ var i = 0;
+ this.series.forEach( function(series) {
+ if (series.disabled) return;
+ series.stack = stackedData[i++];
+ } );
+
+ this.stackedData = stackedData;
+ return stackedData;
+ }
+
+ this.stackData.hooks = { data: [], after: [] };
+
+ this._slice = function(d) {
+
+ if (this.window.xMin || this.window.xMax) {
+
+ var isInRange = true;
+
+ if (this.window.xMin && d.x <= this.window.xMin) isInRange = false;
+ if (this.window.xMax && d.x >= this.window.xMax) isInRange = false;
+
+ return isInRange;
+ }
+
+ return true;
+ }
+
+ this.onUpdate = function(callback) {
+ this.updateCallbacks.push(callback);
+ }
+
+ this.registerRenderer = function(renderer) {
+ this._renderers = this._renderers || {};
+ this._renderers[renderer.name] = renderer;
+ }
+
+ this.setRenderer = function(name) {
+
+ if (!this._renderers[name]) {
+ throw "couldn't find renderer " + name;
+ }
+ this.renderer = this._renderers[name];
+ }
+
+ this.initialize(args);
+}
+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(timeInterval) {
+
+ var addData;
+ timeInterval = timeInterval || 1;
+
+ var lastRandomValue = 200;
+
+ var timeBase = Math.floor(new Date().getTime() / 1000);
+
+ this.addData = function(data) {
+
+ var randomValue = Math.random() * 100 + 15 + lastRandomValue;
+ var index = data[0].length;
+
+ var counter = 1;
+
+ data.forEach( function(series) {
+ var randomVariance = Math.random() * 20;
+ var v = randomValue / 25 + counter++
+ + (Math.cos((index * counter * 11) / 960) + 2) * 15
+ + (Math.cos(index / 7) + 2) * 7
+ + (Math.cos(index / 17) + 2) * 1;
+
+ series.push( { x: (index * timeInterval) + timeBase, y: v + randomVariance } );
+ } );
+
+ lastRandomValue = randomValue * .85;
+ }
+}
+
+Rickshaw.namespace('Rickshaw.Fixtures.Time');
+
+Rickshaw.Fixtures.Time = function() {
+
+ var tzOffset = new Date().getTimezoneOffset() * 60;
+
+ var self = this;
+
+ this.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+
+ this.units = [
+ {
+ name: 'decade',
+ seconds: 86400 * 365.25 * 10,
+ formatter: function(d) { return (parseInt(d.getUTCFullYear() / 10) * 10) }
+ }, {
+ name: 'year',
+ seconds: 86400 * 365.25,
+ formatter: function(d) { return d.getUTCFullYear() }
+ }, {
+ name: 'month',
+ seconds: 86400 * 30.5,
+ formatter: function(d) { return self.months[d.getUTCMonth()] }
+ }, {
+ name: 'week',
+ seconds: 86400 * 7,
+ formatter: function(d) { return self.formatDate(d) }
+ }, {
+ name: 'day',
+ seconds: 86400,
+ formatter: function(d) { return d.getUTCDate() }
+ }, {
+ name: '6 hour',
+ seconds: 3600 * 6,
+ formatter: function(d) { return self.formatTime(d) }
+ }, {
+ name: 'hour',
+ seconds: 3600,
+ formatter: function(d) { return self.formatTime(d) }
+ }, {
+ name: '15 minute',
+ seconds: 60 * 15,
+ formatter: function(d) { return self.formatTime(d) }
+ }, {
+ name: 'minute',
+ seconds: 60,
+ formatter: function(d) { return d.getUTCMinutes() }
+ }, {
+ name: '15 second',
+ seconds: 15,
+ formatter: function(d) { return d.getUTCSeconds() + 's' }
+ }, {
+ name: 'second',
+ seconds: 1,
+ formatter: function(d) { return d.getUTCSeconds() + 's' }
+ }
+ ];
+
+ this.unit = function(unitName) {
+ return this.units.filter( function(unit) { return unitName == unit.name } ).shift();
+ }
+
+ this.formatDate = function(d) {
+ return d.toUTCString().match(/, (\w+ \w+ \w+)/)[1];
+ }
+
+ this.formatTime = function(d) {
+ return d.toUTCString().match(/(\d+:\d+):/)[1];
+ }
+
+ this.ceil = function(time, unit) {
+
+ if (unit.name == 'month') {
+ var nearFuture = new Date((time + unit.seconds - 1) * 1000);
+ return new Date(nearFuture.getUTCFullYear(), nearFuture.getUTCMonth() + 1, 1, 0, 0, 0, 0).getTime() / 1000;
+ }
+
+ if (unit.name == 'year') {
+ var nearFuture = new Date((time + unit.seconds - 1) * 1000);
+ return new Date(nearFuture.getUTCFullYear(), 1, 1, 0, 0, 0, 0).getTime() / 1000;
+ }
+
+ return Math.ceil(time / unit.seconds) * unit.seconds;
+ }
+}
+Rickshaw.namespace('Rickshaw.Fixtures.Number');
+
+Rickshaw.Fixtures.Number.formatKMBT = function(y) {
+ if (y >= 1000000000000) { return y / 1000000000000 + "T" }
+ else if (y >= 1000000000) { return y / 1000000000 + "B" }
+ else if (y >= 1000000) { return y / 1000000 + "M" }
+ else if (y >= 1000) { return y / 1000 + "K" }
+ else if (y < 1 && y > 0) { return y.toFixed(2) }
+ else if (y == 0) { return '' }
+ else { return y }
+}
+Rickshaw.namespace("Rickshaw.Color.Palette");
+
+Rickshaw.Color.Palette = function(args) {
+
+ var color = new Rickshaw.Fixtures.Color();
+
+ args = args || {};
+ this.schemes = {};
+
+ this.scheme = color.schemes[args.scheme] || args.scheme || color.schemes.colorwheel;
+ this.runningIndex = 0;
+
+ this.color = function(key) {
+ return this.scheme[key] || 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) {
+
+ if (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;
+ }
+
+ if (args.series) {
+
+ args.series.forEach( function(s) {
+
+ var seriesKey = s.key || s.name;
+ if (!seriesKey) throw "series needs a key or a name";
+
+ data.forEach( function(d) {
+
+ var dataKey = d.key || d.name;
+ if (!dataKey) throw "data needs a key or a name";
+
+ if (seriesKey == dataKey) {
+ var properties = ['color', 'name', 'data'];
+ properties.forEach( function(p) {
+ s[p] = s[p] || d[p];
+ } );
+ }
+ } );
+ } );
+
+ } else {
+ args.series = data;
+ }
+
+ self.graph = new Rickshaw.Graph(args);
+ self.graph.render();
+
+ if (typeof args.onComplete == 'function') {
+ args.onComplete(self);
+ }
+ }
+ } );
+}
+
+Rickshaw.namespace('Rickshaw.Graph.Annotate');
+
+Rickshaw.Graph.Annotate = function(args) {
+
+ var graph = this.graph = args.graph;
+ this.elements = { timeline: args.element };
+
+ var self = this;
+
+ this.data = {};
+
+ this.elements.timeline.classList.add('rickshaw_annotation_timeline');
+
+ this.add = function(time, content) {
+ self.data[time] = self.data[time] || {'boxes': []};
+ self.data[time].boxes.push({content: content});
+ }
+
+ this.update = function() {
+
+ for (var time in self.data) {
+
+ var annotation = self.data[time];
+ var left = self.graph.x(time);
+
+ if (left > self.graph.x.range()[1]) {
+ if (annotation.element) {
+ annotation.element.style.display = 'none';
+ }
+ continue;
+ }
+
+ if (!annotation.element) {
+ var element = annotation.element = document.createElement('div');
+ element.classList.add('annotation');
+ this.elements.timeline.appendChild(element);
+ element.addEventListener('click', function(e) {
+ element.classList.toggle('active');
+ annotation.line.classList.toggle('active');
+ }, false);
+
+ }
+
+ annotation.element.style.left = left + 'px';
+ annotation.element.style.display = 'block';
+
+ annotation.boxes.forEach( function(box) {
+
+ var element = box.element;
+
+ if (!element) {
+ element = box.element = document.createElement('div');
+ element.classList.add('content');
+ element.innerHTML = box.content;
+ annotation.element.appendChild(element);
+
+ annotation.line = document.createElement('div');
+ annotation.line.classList.add('annotation_line');
+ self.graph.element.appendChild(annotation.line);
+ }
+
+ annotation.line.style.left = left + 'px';
+ } );
+ }
+ }
+
+ this.graph.onUpdate( function() { self.update() } );
+}
+Rickshaw.namespace('Rickshaw.Graph.Axis.Time');
+
+Rickshaw.Graph.Axis.Time = function(args) {
+
+ var self = this;
+
+ this.graph = args.graph;
+ this.elements = [];
+ this.ticksTreatment = args.ticksTreatment || 'plain';
+ this.fixedTimeUnit = args.timeUnit;
+
+ var time = new Rickshaw.Fixtures.Time();
+
+ this.appropriateTimeUnit = function() {
+
+ var unit;
+ var units = time.units;
+
+ var domain = this.graph.x.domain();
+ var rangeSeconds = domain[1] - domain[0];
+
+ units.forEach( function(u) {
+ if (Math.floor(rangeSeconds / u.seconds) >= 2) {
+ unit = unit || u;
+ }
+ } );
+
+ return (unit || time.units[time.units.length - 1]);
+ }
+
+ this.tickOffsets = function() {
+
+ var domain = this.graph.x.domain();
+
+ var unit = this.fixedTimeUnit || this.appropriateTimeUnit();
+ var count = Math.ceil((domain[1] - domain[0]) / unit.seconds);
+
+ var runningTick = domain[0];
+
+ var offsets = [];
+
+ for (var i = 0; i < count; i++) {
+
+ tickValue = time.ceil(runningTick, unit);
+ runningTick = tickValue + unit.seconds / 2;
+
+ offsets.push( { value: tickValue, unit: unit } );
+ }
+
+ return offsets;
+ }
+
+ this.render = function() {
+
+ this.elements.forEach( function(e) {
+ e.parentNode.removeChild(e);
+ } );
+
+ this.elements = [];
+
+ var offsets = this.tickOffsets();
+
+ offsets.forEach( function(o) {
+
+ if (self.graph.x(o.value) > self.graph.x.range()[1]) return;
+
+ var element = document.createElement('div');
+ element.style.left = self.graph.x(o.value) + 'px';
+ element.classList.add('x_tick');
+ element.classList.add(self.ticksTreatment);
+
+ var title = document.createElement('div');
+ title.classList.add('title');
+ title.innerHTML = o.unit.formatter(new Date(o.value * 1000));
+ element.appendChild(title);
+
+ self.graph.element.appendChild(element);
+ self.elements.push(element);
+
+ } );
+ }
+
+ this.graph.onUpdate( function() { self.render() } );
+};
+
+Rickshaw.namespace('Rickshaw.Graph.Axis.Y');
+
+Rickshaw.Graph.Axis.Y = function(args) {
+
+ var self = this;
+
+ this.graph = args.graph;
+ this.orientation = args.orientation || 'right';
+
+ var pixelsPerTick = 75;
+ this.ticks = args.ticks || Math.floor(this.graph.height / pixelsPerTick);
+ this.tickSize = args.tickSize || 4;
+ this.ticksTreatment = args.ticksTreatment || 'plain';
+
+ if (args.element) {
+
+ var berthRate = 0.10;
+
+ if (!args.width || !args.height) {
+ var style = window.getComputedStyle(args.element, null);
+ var elementWidth = parseInt(style.getPropertyValue('width'));
+ var elementHeight = parseInt(style.getPropertyValue('height'));
+ }
+
+ this.width = args.width || elementWidth || this.graph.width * berthRate;
+ this.height = args.height || elementHeight || this.graph.height;
+
+ this.vis = d3.select(args.element)
+ .append("svg:svg")
+ .attr('class', 'rickshaw_graph y_axis')
+ .attr('width', this.width)
+ .attr('height', this.height * (1 + berthRate));
+
+ this.element = this.vis[0][0];
+ this.element.style.position = 'relative';
+
+ var berth = this.height * berthRate;
+ this.element.style.top = -1 * berth + 'px';
+ this.element.style.paddingTop = berth + 'px';
+
+ } else {
+ this.vis = this.graph.vis;
+ }
+
+ this.render = function() {
+
+ var axis = d3.svg.axis().scale(this.graph.y).orient(this.orientation);
+ axis.tickFormat( args.tickFormat || function(y) { return y } );
+
+ if (this.orientation == 'left') {
+ var transform = 'translate(' + this.width + ', 0)';
+ }
+
+ if (this.element) {
+ this.vis.selectAll('*').remove();
+ }
+
+ this.vis
+ .append("svg:g")
+ .attr("class", ["y_ticks", this.ticksTreatment].join(" "))
+ .attr("transform", transform)
+ .call(axis.ticks(this.ticks).tickSubdivide(0).tickSize(this.tickSize))
+
+ var gridSize = (this.orientation == 'right' ? 1 : -1) * this.graph.width;
+
+ this.graph.vis
+ .append("svg:g")
+ .attr("class", "y_grid")
+ .call(axis.ticks(this.ticks).tickSubdivide(0).tickSize(gridSize));
+ }
+
+ this.graph.onUpdate( function() { self.render() } );
+};
+
+Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Highlight');
+
+Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
+
+ this.graph = args.graph;
+ this.legend = args.legend;
+
+ var self = this;
+
+ var colorSafe = {};
+
+ this.addHighlightEvents = function (l) {
+ l.element.addEventListener( 'mouseover', function(e) {
+
+ self.legend.lines.forEach( function(line) {
+ if (l === line) return;
+ colorSafe[line.series.name] = colorSafe[line.series.name] || line.series.color;
+ line.series.color = d3.interpolateRgb(line.series.color, d3.rgb('#d8d8d8'))(0.8).toString();
+ } );
+
+ self.graph.update();
+
+ }, false );
+
+ l.element.addEventListener( 'mouseout', function(e) {
+
+ self.legend.lines.forEach( function(line) {
+ if (colorSafe[line.series.name]) {
+ line.series.color = colorSafe[line.series.name];
+ }
+ } );
+
+ self.graph.update();
+
+ }, false );
+ }
+
+ if (this.legend) {
+ this.legend.lines.forEach( function(l) {
+ self.addHighlightEvents(l);
+ } );
+ }
+
+}
+Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Order');
+
+Rickshaw.Graph.Behavior.Series.Order = function(args) {
+
+ this.graph = args.graph;
+ this.legend = args.legend;
+
+ var self = this;
+
+ $(function() {
+ $(self.legend.list).sortable( {
+ containment: 'parent',
+ tolerance: 'pointer',
+ update: function( event, ui ) {
+ var series = [];
+ $(self.legend.list).find('li').each( function(index, item) {
+ if (!item.series) return;
+ series.push(item.series);
+ } );
+
+ for (var i = self.graph.series.length - 1; i >= 0; i--) {
+ self.graph.series[i] = series.shift();
+ }
+
+ self.graph.update();
+ }
+ } );
+ $(self.legend.list).disableSelection();
+ });
+
+ //hack to make jquery-ui sortable behave
+ this.graph.onUpdate( function() {
+ var h = window.getComputedStyle(self.legend.element).height;
+ self.legend.element.style.height = h;
+ } );
+}
+Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Toggle');
+
+Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
+
+ this.graph = args.graph;
+ this.legend = args.legend;
+
+ var self = this;
+
+ this.addAnchor = function(line) {
+ var anchor = document.createElement('a');
+ anchor.innerHTML = '&#10004;';
+ anchor.classList.add('action');
+ line.element.insertBefore(anchor, line.element.firstChild);
+
+ anchor.onclick = function(e) {
+ if (line.series.disabled) {
+ line.series.enable();
+ line.element.classList.remove('disabled');
+ } else {
+ line.series.disable();
+ line.element.classList.add('disabled');
+ }
+ }
+ }
+
+ if (this.legend) {
+
+ this.legend.lines.forEach( function(l) {
+ self.addAnchor(l);
+ } );
+ }
+
+ this._addBehavior = function() {
+
+ this.graph.series.forEach( function(s) {
+
+ s.disable = function() {
+
+ if (self.graph.series.length <= 1) {
+ throw('only one series left');
+ }
+
+ s.disabled = true;
+ self.graph.update();
+ }
+
+ s.enable = function() {
+ s.disabled = false;
+ self.graph.update();
+ }
+ } );
+ }
+ this._addBehavior();
+
+ this.updateBehaviour = function () { this._addBehavior() }
+
+}
+Rickshaw.namespace('Rickshaw.Graph.HoverDetail');
+
+Rickshaw.Graph.HoverDetail = function(args) {
+
+ var graph = this.graph = args.graph;
+
+ var element = this.element = document.createElement('div');
+ element.className = 'detail';
+
+ this.visible = true;
+
+ graph.element.appendChild(element);
+
+ var self = this;
+
+ this.lastEvent = null;
+
+ this.update = function(e) {
+
+ e = e || this.lastEvent;
+ if (!e) return;
+ this.lastEvent = e;
+
+ if (e.target.nodeName != 'path' && e.target.nodeName != 'svg') return;
+
+ var eventX = e.offsetX || e.layerX;
+ var eventY = e.offsetY || e.layerY;
+
+ var domainX = graph.x.invert(eventX);
+ var stackedData = graph.stackedData;
+
+ var topSeriesData = stackedData.slice(-1).shift();
+
+ var domainIndexScale = d3.scale.linear()
+ .domain([topSeriesData[0].x, topSeriesData.slice(-1).shift().x])
+ .range([0, topSeriesData.length]);
+
+ var approximateIndex = Math.floor(domainIndexScale(domainX));
+ var dataIndex = approximateIndex || 0;
+
+ for (var i = approximateIndex; i < stackedData[0].length - 1;) {
+
+ if (stackedData[0][i].x <= domainX && stackedData[0][i + 1].x > domainX) {
+ dataIndex = i;
+ break;
+ }
+ if (stackedData[0][i + 1] < domainX) { i++ } else { i-- }
+ }
+
+ domainX = stackedData[0][dataIndex].x;
+
+ var detail = graph.series.active()
+ .map( function(s) { return { name: s.name, value: s.stack[dataIndex] } } );
+
+ if (this.visible) {
+ self.render.call( self, domainX, detail, eventX, eventY);
+ }
+ }
+
+ this.xFormatter = function(x) {
+ return new Date( x * 1000 ).toUTCString();
+ }
+
+ this.graph.element.addEventListener(
+ 'mousemove',
+ function(e) {
+ self.visible = true;
+ self.update(e)
+ },
+ false
+ );
+
+ this.graph.onUpdate( function() { self.update() } );
+
+ this.graph.element.addEventListener(
+ 'mouseout',
+ function(e) {
+ if (e.relatedTarget && !(e.relatedTarget.compareDocumentPosition(self.graph.element) & Node.DOCUMENT_POSITION_CONTAINS)) {
+ self.hide();
+ }
+ },
+ false
+ );
+
+ this.hide = function() {
+ this.visible = false;
+ this.element.classList.add('inactive');
+ }
+
+ this.show = function() {
+ this.visible = true;
+ this.element.classList.remove('inactive');
+ }
+
+ this.render = function(domainX, detail, mouseX, mouseY) {
+
+ this.element.innerHTML = '';
+ this.element.style.left = graph.x(domainX) + 'px';
+
+ var xLabel = document.createElement('div');
+ xLabel.className = 'x_label';
+ xLabel.innerHTML = this.xFormatter(domainX);
+ this.element.appendChild(xLabel);
+
+ var activeItem = null;
+
+ var sortFn = function(a, b) {
+ return (a.value.y0 + a.value.y) - (b.value.y0 + b.value.y);
+ }
+
+ detail.sort(sortFn).forEach( function(d) {
+
+ var item = document.createElement('div');
+ item.className = 'item';
+ item.innerHTML = d.name + ':&nbsp;' + d.value.y.toFixed(2);
+ item.style.top = graph.y(d.value.y0 + d.value.y) + 'px';
+
+ var domainMouseY = graph.y.magnitude.invert(graph.element.offsetHeight - mouseY);
+
+ this.element.appendChild(item);
+
+ var dot = document.createElement('div');
+ dot.className = 'dot';
+ dot.style.top = item.style.top;
+
+ this.element.appendChild(dot);
+
+ if (domainMouseY > d.value.y0 && domainMouseY < d.value.y0 + d.value.y && !activeItem) {
+
+ activeItem = item;
+ item.className = 'item active';
+ dot.className = 'dot active';
+ }
+
+ }, this );
+
+ this.show();
+ }
+}
+
+Rickshaw.namespace('Rickshaw.Graph.JSONP');
+
+Rickshaw.Graph.JSONP = function(args) {
+
+ var self = this;
+ this.dataURL = args.dataURL;
+
+ $.ajax( {
+ url: this.dataURL,
+ dataType: 'jsonp',
+ success: function(data, status, response) {
+
+ if (status === 'error') {
+ console.log("error loading dataURL: " + this.dataURL);
+ }
+
+ if (typeof args.onData === 'function') {
+ var processedData = args.onData(data);
+ data = processedData;
+ }
+
+ if (args.series) {
+
+ args.series.forEach( function(s) {
+
+ var seriesKey = s.key || s.name;
+ if (!seriesKey) throw "series needs a key or a name";
+
+ data.forEach( function(d) {
+
+ var dataKey = d.key || d.name;
+ if (!dataKey) throw "data needs a key or a name";
+
+ if (seriesKey == dataKey) {
+ var properties = ['color', 'name', 'data'];
+ properties.forEach( function(p) {
+ s[p] = s[p] || d[p];
+ } );
+ }
+ } );
+ } );
+
+ } else {
+ args.series = data;
+ }
+
+ self.graph = new Rickshaw.Graph(args);
+ self.graph.render();
+
+ if (typeof args.onComplete == 'function') {
+ args.onComplete(self);
+ }
+ }
+ } );
+}
+
+Rickshaw.namespace('Rickshaw.Graph.Legend');
+
+Rickshaw.Graph.Legend = function(args) {
+
+ var element = this.element = args.element;
+ var graph = this.graph = args.graph;
+
+ var self = this;
+
+ element.classList.add('rickshaw_legend');
+
+ var list = this.list = document.createElement('ul');
+ element.appendChild(list);
+
+ var series = graph.series
+ .map( function(s) { return s } )
+ .reverse();
+
+ this.lines = [];
+
+ this.addLine = function (series) {
+ var line = document.createElement('li');
+ line.className = 'line';
+
+ var swatch = document.createElement('div');
+ swatch.className = 'swatch';
+ swatch.style.backgroundColor = series.color;
+
+ line.appendChild(swatch);
+
+ var label = document.createElement('span');
+ label.className = 'label';
+ label.innerHTML = series.name;
+
+ line.appendChild(label);
+ list.appendChild(line);
+
+ line.series = series;
+
+ if (series.noLegend) {
+ line.style.display = 'none';
+ }
+
+ var _line = { element: line, series: series };
+ if (self.shelving) {
+ self.shelving.addAnchor(_line);
+ self.shelving.updateBehaviour();
+ }
+ if (self.highlighter) {
+ self.highlighter.addHighlightEvents(_line);
+ }
+ self.lines.push(_line);
+ }
+
+ series.forEach( function(s) {
+ self.addLine(s);
+ } );
+
+ graph.onUpdate( function() {
+
+ } );
+}
+Rickshaw.namespace('Rickshaw.Graph.RangeSlider');
+
+Rickshaw.Graph.RangeSlider = function(args) {
+
+ var element = this.element = args.element;
+ var graph = this.graph = args.graph;
+
+ $( function() {
+ $(element).slider( {
+
+ range: true,
+ min: graph.dataDomain()[0],
+ max: graph.dataDomain()[1],
+ values: [
+ graph.dataDomain()[0],
+ graph.dataDomain()[1],
+ ],
+ slide: function( event, ui ) {
+
+ graph.window.xMin = ui.values[0];
+ graph.window.xMax = ui.values[1];
+ graph.update();
+
+ // if we're at an extreme, stick there
+ if (graph.dataDomain()[0] == ui.values[0]) {
+ graph.window.xMin = undefined;
+ }
+ if (graph.dataDomain()[1] == ui.values[1]) {
+ graph.window.xMax = undefined;
+ }
+ }
+ } );
+ } );
+
+ element[0].style.width = graph.width + 'px';
+
+ graph.onUpdate( function() {
+
+ var values = $(element).slider('option', 'values');
+
+ $(element).slider('option', 'min', graph.dataDomain()[0]);
+ $(element).slider('option', 'max', graph.dataDomain()[1]);
+
+ if (graph.window.xMin == undefined) {
+ values[0] = graph.dataDomain()[0];
+ }
+ if (graph.window.xMax == undefined) {
+ values[1] = graph.dataDomain()[1];
+ }
+
+ $(element).slider('option', 'values', values);
+
+ } );
+}
+
+Rickshaw.namespace('Rickshaw.Graph.Renderer.Line');
+
+Rickshaw.Graph.Renderer.Line = function(args) {
+
+ var graph = this.graph = args.graph;
+ var self = this;
+
+ 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);
+ }
+
+ 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);
+ }
+}
+
+Rickshaw.namespace('Rickshaw.Graph.Renderer.Stack');
+
+Rickshaw.Graph.Renderer.Stack = function(args) {
+
+ var graph = this.graph = args.graph;
+ var self = this;
+
+ this.name = 'stack';
+
+ this.seriesPathFactory = function() {
+
+ 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);
+ }
+
+ 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);
+ }
+}
+Rickshaw.namespace('Rickshaw.Graph.Renderer.Bar');
+
+Rickshaw.Graph.Renderer.Bar = function(args) {
+
+ var graph = this.graph = args.graph;
+ var self = this;
+
+ this.name = 'bar';
+ this.gapSize = args.gapSize || 0.05;
+
+ 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 } );
+
+ this._barWidth = null;
+
+ return { x: [xMin, xMax], y: [yMin, yMax] };
+ }
+
+ this.barWidth = function() {
+
+ if (this._barWidth) return this._barWidth;
+
+ var stackedData = graph.stackedData || graph.stackData();
+ var data = stackedData.slice(-1).shift();
+
+ var intervalCounts = {};
+
+ for (var i = 0; i < data.length - 1; i++) {
+ var interval = data[i + 1].x - data[i].x;
+ intervalCounts[interval] = intervalCounts[interval] || 0;
+ intervalCounts[interval]++;
+ }
+
+ var frequentInterval = { count: 0 };
+
+ d3.keys(intervalCounts).forEach( function(i) {
+ if (frequentInterval.count < intervalCounts[i]) {
+
+ frequentInterval = {
+ count: intervalCounts[i],
+ magnitude: i
+ };
+ }
+ } );
+
+ this._barWidth = this.graph.x(data[0].x + frequentInterval.magnitude * (1 - this.gapSize));
+ return this._barWidth;
+ }
+
+ this.render = function() {
+
+ graph.vis.selectAll('*').remove();
+
+ var barWidth = this.barWidth();
+
+ graph.series.forEach( function(series) {
+
+ if (series.disabled) return;
+
+ var nodes = graph.vis.selectAll("path")
+ .data(series.stack)
+ .enter().append("svg:rect")
+ .attr("x", function(d) { return graph.x(d.x) })
+ .attr("y", function(d) { return graph.y(d.y0 + d.y) })
+ .attr("width", barWidth)
+ .attr("height", function(d) { return graph.y.magnitude(d.y) });
+
+ 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);
+ }
+}
+Rickshaw.namespace('Rickshaw.Graph.Smoother');
+
+Rickshaw.Graph.Smoother = function(args) {
+
+ this.graph = args.graph;
+ this.element = args.element;
+
+ var self = this;
+
+ this.aggregationScale = 1;
+
+ if (this.element) {
+
+ $( function() {
+ $(self.element).slider( {
+ min: 1,
+ max: 100,
+ slide: function( event, ui ) {
+ self.setScale(ui.value);
+ self.graph.update();
+ }
+ } );
+ } );
+ }
+
+ self.graph.stackData.hooks.data.push( {
+ name: 'smoother',
+ orderPosition: 50,
+ f: function(data) {
+
+ var aggregatedData = [];
+
+ data.forEach( function(seriesData) {
+
+ var aggregatedSeriesData = [];
+
+ while (seriesData.length) {
+
+ var avgX = 0, avgY = 0;
+ var slice = seriesData.splice(0, self.aggregationScale);
+
+ slice.forEach( function(d) {
+ avgX += d.x / slice.length;
+ avgY += d.y / slice.length;
+ } );
+
+ aggregatedSeriesData.push( { x: avgX, y: avgY } );
+ }
+
+ aggregatedData.push(aggregatedSeriesData);
+ } );
+
+ return aggregatedData;
+ }
+ } );
+
+ this.setScale = function(scale) {
+
+ if (scale < 1) {
+ throw "scale out of range: " + scale;
+ }
+
+ this.aggregationScale = scale;
+ this.graph.update();
+ }
+}
+
+Rickshaw.namespace('Rickshaw.Graph.Unstacker');
+
+Rickshaw.Graph.Unstacker = function(args) {
+
+ this.graph = args.graph;
+ var self = this;
+
+ this.graph.stackData.hooks.after.push( {
+ name: 'unstacker',
+ f: function(data) {
+
+ if (!self.graph.renderer.unstack) return data;
+
+ data.forEach( function(seriesData) {
+ seriesData.forEach( function(d) {
+ d.y0 = 0;
+ } );
+ } );
+
+ return data;
+ }
+ } );
+}
+
+Rickshaw.namespace('Rickshaw.Series');
+
+Rickshaw.Series = function(data, palette, options) {
+
+ this.initialize(data, palette, options);
+}
+
+Rickshaw.Series.prototype = new Array;
+
+Rickshaw.Series.prototype.constructor = Rickshaw.Series;
+
+Rickshaw.Series.prototype.initialize = function (data, palette, options) {
+ var self = this;
+ options = options || {}
+
+ 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) { self.addItem(item) } );
+ }
+}
+
+Rickshaw.Series.prototype.addItem = function(item) {
+ var self = this;
+ if (typeof(item.name) === 'undefined') {
+ throw('addItem() needs a name');
+ }
+
+ item.color = (item.color || self.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 });
+ }
+
+ self.push(item);
+
+ if (self.legend) {
+ self.legend.addLine(self.itemByName(item.name));
+ }
+}
+
+Rickshaw.Series.prototype.addData = function(data) {
+ var self = this;
+ var index = this.getIndex();
+
+ Rickshaw.keys(data).forEach( function (name) {
+ if (! self.itemByName(name)) {
+ self.addItem({ name: name });
+ }
+ } );
+
+ self.forEach( function (item) {
+ item.data.push({ x: (index * self.timeInterval || 1) + self.timeBase, y: (data[item.name] || 0) });
+ } );
+}
+
+Rickshaw.Series.prototype.getIndex = function () {
+ var self = this;
+ return (self[0] && self[0].data && self[0].data.length) ? self[0].data.length : 0;
+}
+
+Rickshaw.Series.prototype.itemByName = function (name) {
+ var self = this;
+ var ret;
+ self.forEach( function (item) {
+ if (item.name == name) { ret = item }
+ } );
+ return ret;
+}
+
+Rickshaw.Series.prototype.setTimeInterval = function (iv) {
+ this.timeInterval = parseInt(iv/1000);
+}
+
+Rickshaw.Series.prototype.setTimeBase = function (t) {
+ this.timeBase = t;
+}
+
+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: []
+ };
+
+ item.data.forEach( function (plot) {
+ newItem.data.push({ x: plot.x, y: plot.y });
+ } );
+
+ data.items.push(newItem);
+ } );
+ return data;
+}
+
+Rickshaw.Series.prototype.load = function (data) {
+ var self = this;
+ if (data.timeInterval) {
+ self.timeInterval = data.timeInterval;
+ }
+
+ if (data.timeBase) {
+ self.timeBase = data.timeBase;
+ }
+
+ if (data.items) {
+ data.items.forEach( function (item) {
+ self.push(item);
+
+ if (self.legend) {
+ self.legend.addLine(self.itemByName(item.name));
+ }
+ } );
+ }
+}
+
+Rickshaw.Series.zeroFill = function(series) {
+
+ var x;
+ var i = 0;
+
+ var data = series.map( function(s) { return s.data } );
+
+ while ( i < Math.max.apply(null, data.map( function(d) { return d.length } )) ) {
+
+ x = Math.min.apply( null,
+ data
+ .filter(function(d) { return d[i] })
+ .map(function(d) { return d[i].x })
+ );
+
+ data.forEach( function(d) {
+ if (!d[i] || d[i].x != x) {
+ d.splice(i, 0, { x: x, y: 0 });
+ }
+ } );
+
+ i++;
+ }
+};
View
2 rickshaw.min.css
@@ -1 +1 @@
-.rickshaw_graph .detail{pointer-events:none;position:absolute;top:0;z-index:2;background:rgba(0,0,0,.1);bottom:0;width:1px;transition:opacity .25s linear;-moz-transition:opacity .25s linear;-o-transition:opacity .25s linear;-webkit-transition:opacity .25s linear}.rickshaw_graph .detail.inactive{opacity:0}.rickshaw_graph .detail .item.active{opacity:1}.rickshaw_graph .detail .x_label{font-family:Arial,sans-serif;border-radius:3px;padding:6px;opacity:.5;border:1px solid #e0e0e0;font-size:12px;position:absolute;background:#fff;white-space:nowrap}.rickshaw_graph .detail .item{position:absolute;z-index:2;border-radius:3px;padding:.25em;font-size:12px;font-family:Arial,sans-serif;opacity:0;background:rgba(0,0,0,.4);color:#fff;border:1px solid rgba(0,0,0,.4);margin-left:1em;margin-top:-1em;white-space:nowrap}.rickshaw_graph .detail .item.active{opacity:1;background:rgba(0,0,0,.8)}.rickshaw_graph .detail .item:before{content:"\25c2";position:absolute;left:-.5em;color:rgba(0,0,0,.7);width:0}.rickshaw_graph .detail .dot{width:5px;height:5px;margin-left:-2px;margin-top:-3px;border-radius:3px;position:absolute}.rickshaw_graph .detail .dot.active{background:rgba(255,255,255,.8);box-shadow:0 0 1px rgba(0,0,0,.5)}.rickshaw_graph{position:relative}.rickshaw_graph svg{display:block}.rickshaw_graph .x_tick{position:absolute;top:0;bottom:0;width:0;border-left:1px dotted rgba(0,0,0,.2);pointer-events:none}.rickshaw_graph .x_tick .title{position:absolute;font-size:12px;font-family:Arial,sans-serif;opacity:.5;white-space:nowrap;margin-left:3px;bottom:1px}.rickshaw_annotation_timeline{height:1px;border-top:1px solid #e0e0e0;margin-top:10px;position:relative}.rickshaw_annotation_timeline .annotation{position:absolute;height:6px;width:6px;margin-left:-2px;top:-3px;border-radius:5px;background-color:rgba(0,0,0,.25)}.rickshaw_graph .annotation_line{position:absolute;top:0;bottom:-6px;width:0;border-left:2px solid rgba(0,0,0,.3);display:none}.rickshaw_graph .annotation_line.active{display:block}.rickshaw_annotation_timeline .annotation .content{background:#fff;color:#000;opacity:.9;padding:5px 5px;box-shadow:0 0 2px rgba(0,0,0,.8);border-radius:3px;position:relative;z-index:20;font-size:12px;padding:6px 8px 8px;top:18px;left:-11px;width:160px;display:none;cursor:pointer}.rickshaw_annotation_timeline .annotation .content:before{content:"\25b2";position:absolute;top:-11px;color:#fff;text-shadow:0 -1px 1px rgba(0,0,0,.8)}.rickshaw_annotation_timeline .annotation.active,.rickshaw_annotation_timeline .annotation:hover{background-color:rgba(0,0,0,.8);cursor:none}.rickshaw_annotation_timeline .annotation .content:hover{z-index:50}.rickshaw_annotation_timeline .annotation.active .content{display:block}.rickshaw_annotation_timeline .annotation:hover .content{display:block;z-index:50}.rickshaw_graph .y_axis{fill:none}.rickshaw_graph .y_ticks .tick{stroke:rgba(0,0,0,.16);stroke-width:2px;shape-rendering:crisp-edges;pointer-events:none}.rickshaw_graph .y_grid .tick{z-index:-1;stroke:rgba(0,0,0,.20);stroke-width:1px;stroke-dasharray:1 1}.rickshaw_graph .y_grid path{fill:none;stroke:none}.rickshaw_graph .y_ticks path{fill:none;stroke:#808080}.rickshaw_graph .y_ticks text{opacity:.5;font-size:12px;pointer-events:none}.rickshaw_graph .x_tick.glow .title,.rickshaw_graph .y_ticks.glow text{fill:black;color:#000;text-shadow:-1px 1px 0 rgba(255,255,255,.1),1px -1px 0 rgba(255,255,255,.1),1px 1px 0 rgba(255,255,255,.1),0px 1px 0 rgba(255,255,255,.1),0px -1px 0 rgba(255,255,255,.1),1px 0 0 rgba(255,255,255,.1),-1px 0 0 rgba(255,255,255,.1),-1px -1px 0 rgba(255,255,255,.1)}.rickshaw_graph .x_tick.inverse .title,.rickshaw_graph .y_ticks.inverse text{fill:white;color:#fff;text-shadow:-1px 1px 0 rgba(0,0,0,.8),1px -1px 0 rgba(0,0,0,.8),1px 1px 0 rgba(0,0,0,.8),0px 1px 0 rgba(0,0,0,.8),0px -1px 0 rgba(0,0,0,.8),1px 0 0 rgba(0,0,0,.8),-1px 0 0 rgba(0,0,0,.8),-1px -1px 0 rgba(0,0,0,.8)}.rickshaw_legend{font-family:Arial;font-size:12px;color:#fff;background:#404040;display:inline-block;padding:12px 5px;border-radius:2px;position:relative}.rickshaw_legend:hover{z-index:10}.rickshaw_legend .swatch{width:10px;height:10px;border:1px solid rgba(0,0,0,.2)}.rickshaw_legend .line{clear:both;line-height:140%;padding-right:15px}.rickshaw_legend .line .swatch{display:inline-block;margin-right:3px;border-radius:2px}.rickshaw_legend .label{white-space:nowrap;display:inline}.rickshaw_legend .action:hover{opacity:.6}.rickshaw_legend .action{margin-right:.2em;font-size:10px;opacity:.2;cursor:pointer;font-size:14px}.rickshaw_legend .line.disabled{opacity:.4}.rickshaw_legend ul{list-style-type:none;margin:0;padding:0;margin:2px;cursor:pointer}.rickshaw_legend li{padding:0 0 0 2px;min-width:80px;white-space:nowrap}.rickshaw_legend li:hover{background:rgba(255,255,255,.08);border-radius:3px}.rickshaw_legend li:active{background:rgba(255,255,255,.2);border-radius:3px}
+.rickshaw_graph .detail{pointer-events:none;position:absolute;top:0;z-index:2;background:rgba(0,0,0,.1);bottom:0;width:1px;transition:opacity .25s linear;-moz-transition:opacity .25s linear;-o-transition:opacity .25s linear;-webkit-transition:opacity .25s linear}.rickshaw_graph .detail.inactive{opacity:0}.rickshaw_graph .detail .item.active{opacity:1}.rickshaw_graph .detail .x_label{font-family:Arial,sans-serif;border-radius:3px;padding:6px;opacity:.5;border:1px solid #e0e0e0;font-size:12px;position:absolute;background:#fff;white-space:nowrap}.rickshaw_graph .detail .item{position:absolute;z-index:2;border-radius:3px;padding:.25em;font-size:12px;font-family:Arial,sans-serif;opacity:0;background:rgba(0,0,0,.4);color:#fff;border:1px solid rgba(0,0,0,.4);margin-left:1em;margin-top:-1em;white-space:nowrap}.rickshaw_graph .detail .item.active{opacity:1;background:rgba(0,0,0,.8)}.rickshaw_graph .detail .item:before{content:"\25c2";position:absolute;left:-.5em;color:rgba(0,0,0,.7);width:0}.rickshaw_graph .detail .dot{width:5px;height:5px;margin-left:-2px;margin-top:-3px;border-radius:3px;position:absolute}.rickshaw_graph .detail .dot.active{background:rgba(255,255,255,.8);box-shadow:0 0 1px rgba(0,0,0,.5)}.rickshaw_graph{position:relative}.rickshaw_graph svg{display:block;overflow:hidden}.rickshaw_graph .x_tick{position:absolute;top:0;bottom:0;width:0;border-left:1px dotted rgba(0,0,0,.2);pointer-events:none}.rickshaw_graph .x_tick .title{position:absolute;font-size:12px;font-family:Arial,sans-serif;opacity:.5;white-space:nowrap;margin-left:3px;bottom:1px}.rickshaw_annotation_timeline{height:1px;border-top:1px solid #e0e0e0;margin-top:10px;position:relative}.rickshaw_annotation_timeline .annotation{position:absolute;height:6px;width:6px;margin-left:-2px;top:-3px;border-radius:5px;background-color:rgba(0,0,0,.25)}.rickshaw_graph .annotation_line{position:absolute;top:0;bottom:-6px;width:0;border-left:2px solid rgba(0,0,0,.3);display:none}.rickshaw_graph .annotation_line.active{display:block}.rickshaw_annotation_timeline .annotation .content{background:#fff;color:#000;opacity:.9;padding:5px 5px;box-shadow:0 0 2px rgba(0,0,0,.8);border-radius:3px;position:relative;z-index:20;font-size:12px;padding:6px 8px 8px;top:18px;left:-11px;width:160px;display:none;cursor:pointer}.rickshaw_annotation_timeline .annotation .content:before{content:"\25b2";position:absolute;top:-11px;color:#fff;text-shadow:0 -1px 1px rgba(0,0,0,.8)}.rickshaw_annotation_timeline .annotation.active,.rickshaw_annotation_timeline .annotation:hover{background-color:rgba(0,0,0,.8);cursor:none}.rickshaw_annotation_timeline .annotation .content:hover{z-index:50}.rickshaw_annotation_timeline .annotation.active .content{display:block}.rickshaw_annotation_timeline .annotation:hover .content{display:block;z-index:50}.rickshaw_graph .y_axis{fill:none}.rickshaw_graph .y_ticks .tick{stroke:rgba(0,0,0,.16);stroke-width:2px;shape-rendering:crisp-edges;pointer-events:none}.rickshaw_graph .y_grid .tick{z-index:-1;stroke:rgba(0,0,0,.20);stroke-width:1px;stroke-dasharray:1 1}.rickshaw_graph .y_grid path{fill:none;stroke:none}.rickshaw_graph .y_ticks path{fill:none;stroke:#808080}.rickshaw_graph .y_ticks text{opacity:.5;font-size:12px;pointer-events:none}.rickshaw_graph .x_tick.glow .title,.rickshaw_graph .y_ticks.glow text{fill:black;color:#000;text-shadow:-1px 1px 0 rgba(255,255,255,.1),1px -1px 0 rgba(255,255,255,.1),1px 1px 0 rgba(255,255,255,.1),0px 1px 0 rgba(255,255,255,.1),0px -1px 0 rgba(255,255,255,.1),1px 0 0 rgba(255,255,255,.1),-1px 0 0 rgba(255,255,255,.1),-1px -1px 0 rgba(255,255,255,.1)}.rickshaw_graph .x_tick.inverse .title,.rickshaw_graph .y_ticks.inverse text{fill:white;color:#fff;text-shadow:-1px 1px 0 rgba(0,0,0,.8),1px -1px 0 rgba(0,0,0,.8),1px 1px 0 rgba(0,0,0,.8),0px 1px 0 rgba(0,0,0,.8),0px -1px 0 rgba(0,0,0,.8),1px 0 0 rgba(0,0,0,.8),-1px 0 0 rgba(0,0,0,.8),-1px -1px 0 rgba(0,0,0,.8)}.rickshaw_legend{font-family:Arial;font-size:12px;color:#fff;background:#404040;display:inline-block;padding:12px 5px;border-radius:2px;position:relative}.rickshaw_legend:hover{z-index:10}.rickshaw_legend .swatch{width:10px;height:10px;border:1px solid rgba(0,0,0,.2)}.rickshaw_legend .line{clear:both;line-height:140%;padding-right:15px}.rickshaw_legend .line .swatch{display:inline-block;margin-right:3px;border-radius:2px}.rickshaw_legend .label{white-space:nowrap;display:inline}.rickshaw_legend .action:hover{opacity:.6}.rickshaw_legend .action{margin-right:.2em;font-size:10px;opacity:.2;cursor:pointer;font-size:14px}.rickshaw_legend .line.disabled{opacity:.4}.rickshaw_legend ul{list-style-type:none;margin:0;padding:0;margin:2px;cursor:pointer}.rickshaw_legend li{padding:0 0 0 2px;min-width:80px;white-space:nowrap}.rickshaw_legend li:hover{background:rgba(255,255,255,.08);border-radius:3px}.rickshaw_legend li:active{background:rgba(255,255,255,.2);border-radius:3px}
View
2 rickshaw.min.js
@@ -1 +1 @@
-Rickshaw={namespace:function(a,b){var c=a.split(".");parent=Rickshaw;for(var d=1,e=c.length;d<e;d++)currentPart=c[d],parent[currentPart]=parent[currentPart]||{},parent=parent[currentPart];return parent},keys:function(a){var b=[];for(var c in a)b.push(c);return b}},Rickshaw.namespace("Rickshaw.Graph"),Rickshaw.Graph=function(a){this.element=a.element,this.interpolation=a.interpolation||"cardinal",this.series=a.series,this.offset="zero";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];b.forEach(function(a){if(!a)return;e.registerRenderer(new a({graph:e}))}),this.setRenderer(a.renderer||"stack"),this.discoverRange()},this.validateSeries=function(a){var b=Object.prototype.toString.apply(a);if(b!=="[object Array]"&&!a instanceof Rickshaw.Series)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);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 Math.floor(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.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),d=[c.getUTCFullYear(),c.getUTCMonth()+1,1].join("-");return(new Date(d)).getTime()/1e3}if(b.name=="year"){var c=new Date((a+b.seconds-1)*1e3),e=[c.getUTCFullYear(),1,1].join("-");return(new Date(e)).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.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";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.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||graph.width*d,this.height=a.height||g||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.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 this._barWidth=null,{x:[d,e],y:[f,g]}},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.barWidth();b.series.forEach(function(c){if(c.disabled)return;var d=b.vis.selectAll("path").data(c.stack).enter().append("svg:rect").attr("x",function(a){return b.x(a.x)}).attr("y",function(a){return b.y(a.y0+a.y)}).attr("width",a).attr("height",function(a){return b.y.magnitude(a.y)});Array.prototype.forEach.call(d[0],function(a){a.setAttribute("fill",c.color)})})},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){var b=this;this.initialize=function(a,c,d){d=d||{},b.palette=new Rickshaw.Color.Palette(c),b.timeBase=typeof d.timeBase=="undefined"?Math.floor((new Date).getTime()/1e3):d.timeBase,a&&typeof a=="object"&&a instanceof Array&&a.forEach(function(a){b.addItem(a)})},this.addItem=function(a){if(typeof a.name=="undefined")throw"addItem() needs a name";a.color=a.color||b.palette.color(),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})}):a.data.push({x:b.timeBase,y:0}),b.push(a),b.legend&&b.legend.addLine(b.itemByName(a.name))},this.addData=function(a){var 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})})},this.getIndex=function(){return b[0]&&b[0].data&&b[0].data.length?b[0].data.length:0},this.itemByName=function(a){var c;return b.forEach(function(b){b.name==a&&(c=b)}),c},this.setTimeInterval=function(a){b.timeInterval=parseInt(a/1e3)},this.setTimeBase=function(a){b.timeBase=a},this.dump=function(){var a={timeBase:b.timeBase,timeInterval:b.timeInterval,items:[]};return b.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},this.load=function(a){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))})},this.initialize(a)},Rickshaw.Series.prototype=new Array,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}},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";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];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.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 this._barWidth=null,{x:[d,e],y:[f,g]}},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.barWidth();b.series.forEach(function(c){if(c.disabled)return;var d=b.vis.selectAll("path").data(c.stack).enter().append("svg:rect").attr("x",function(a){return b.x(a.x)}).attr("y",function(a){return b.y(a.y0+a.y)}).attr("width",a).attr("height",function(a){return b.y.magnitude(a.y)});Array.prototype.forEach.call(d[0],function(a){a.setAttribute("fill",c.color)})})},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++};

0 comments on commit 043f6cb

Please sign in to comment.
Something went wrong with that request. Please try again.