Chart.js/Chart.min.js

38 lines
84 KiB
JavaScript
Raw Normal View History

2014-06-29 19:36:25 +02:00
/*!
* Chart.js
* http://chartjs.org/
2015-06-04 03:45:14 +02:00
* Version: 2.0.0-alpha
2014-06-29 19:36:25 +02:00
*
2015-01-07 23:49:33 +01:00
* Copyright 2015 Nick Downie
2014-06-29 19:36:25 +02:00
* Released under the MIT license
* https://github.com/nnnick/Chart.js/blob/master/LICENSE.md
*/
(function(){"use strict";var t=this,e=t.Chart,i=function(t,e){this.config=e,t.length&&t[0].getContext&&(t=t[0]),t.getContext&&(t=t.getContext("2d")),this.canvas=t.canvas,this.ctx=t;var a=function(t,e){return t["offset"+e]?t["offset"+e]:document.defaultView.getComputedStyle(t).getPropertyValue(e)},n=this.width=a(t.canvas,"Width")||t.canvas.width,s=this.height=a(t.canvas,"Height")||t.canvas.height;return t.canvas.width=n,t.canvas.height=s,n=this.width=t.canvas.width,s=this.height=t.canvas.height,this.aspectRatio=this.width/this.height,i.helpers.retinaScale(this),e?(this.controller=new i.Controller(this),this.controller):this};i.defaults={global:{responsive:!0,maintainAspectRatio:!0,events:["mousemove","mouseout","click","touchstart","touchmove","touchend"],hover:{onHover:null,mode:"single",animationDuration:400},onClick:null,defaultColor:"rgba(0,0,0,0.1)",elements:{}}},"undefined"!=typeof amd?define(function(){return i}):"object"==typeof module&&module.exports&&(module.exports=i),t.Chart=i,i.noConflict=function(){return t.Chart=e,i}}).call(this),function(){"use strict";var t=this,e=(t.Chart,Chart.helpers={}),i=e.each=function(t,e,i){var a=Array.prototype.slice.call(arguments,3);if(t)if(t.length===+t.length){var n;for(n=0;n<t.length;n++)e.apply(i,[t[n],n].concat(a))}else for(var s in t)e.apply(i,[t[s],s].concat(a))},a=e.clone=function(t){var n={};return i(t,function(i,s){t.hasOwnProperty(s)&&(e.isArray(i)?n[s]=i.slice(0):"object"==typeof i&&null!==i?n[s]=a(i):n[s]=i)}),n},n=e.extend=function(t){return i(Array.prototype.slice.call(arguments,1),function(e){i(e,function(i,a){e.hasOwnProperty(a)&&(t[a]=i)})}),t},s=(e.merge=function(t,e){var i=Array.prototype.slice.call(arguments,0);return i.unshift({}),n.apply(null,i)},e.configMerge=function(t){var i=a(t);return e.each(Array.prototype.slice.call(arguments,1),function(t){e.each(t,function(a,n){if(t.hasOwnProperty(n))if("scales"===n)i[n]=e.scaleMerge(i.hasOwnProperty(n)?i[n]:{},a);else if("scale"===n)i[n]=e.configMerge(i.hasOwnProperty(n)?i[n]:{},Chart.scaleService.getScaleDefaults(a.type),a);else if(i.hasOwnProperty(n)&&e.isArray(i[n])&&e.isArray(a)){var s=i[n];e.each(a,function(t,i){i<s.length?s[i]=e.configMerge(s[i],t):s.push(t)})}else i.hasOwnProperty(n)&&"object"==typeof i[n]&&null!==i[n]&&"object"==typeof a?i[n]=e.configMerge(i[n],a):i[n]=a})}),i},e.scaleMerge=function(t,i){var n=a(t);return e.each(i,function(t,a){i.hasOwnProperty(a)&&("xAxes"===a||"yAxes"===a?n.hasOwnProperty(a)?e.each(t,function(t,i){i>=n[a].length||!n[a][i].type?n[a].push(e.configMerge(t.type?Chart.scaleService.getScaleDefaults(t.type):{},t)):t.type!==n[a][i].type?n[a][i]=e.configMerge(n[a][i],t.type?Chart.scaleService.getScaleDefaults(t.type):{},t):n[a][i]=e.configMerge(n[a][i],t)}):(n[a]=[],e.each(t,function(t){n[a].push(e.configMerge(t.type?Chart.scaleService.getScaleDefaults(t.type):{},t))})):n.hasOwnProperty(a)&&"object"==typeof n[a]&&null!==n[a]&&"object"==typeof t?n[a]=e.configMerge(n[a],t):n[a]=t)}),n},e.getValueAtIndexOrDefault=function(t,i,a){return t?e.isArray(t)&&i<t.length?t[i]:t:a},e.indexOf=function(t,e){if(Array.prototype.indexOf)return t.indexOf(e);for(var i=0;i<t.length;i++)if(t[i]===e)return i;return-1},e.where=function(t,i){var a=[];return e.each(t,function(t){i(t)&&a.push(t)}),a},e.findNextWhere=function(t,e,i){i||(i=-1);for(var a=i+1;a<t.length;a++){var n=t[a];if(e(n))return n}},e.findPreviousWhere=function(t,e,i){i||(i=t.length);for(var a=i-1;a>=0;a--){var n=t[a];if(e(n))return n}},e.inherits=function(t){var e=this,i=t&&t.hasOwnProperty("constructor")?t.constructor:function(){return e.apply(this,arguments)},a=function(){this.constructor=i};return a.prototype=e.prototype,i.prototype=new a,i.extend=s,t&&n(i.prototype,t),i.__super__=e.prototype,i}),o=e.noop=function(){},r=(e.uid=function(){var t=0;return function(){return"chart-"+t++}}(),e.warn=function(t){window.console&&"function"==typeof window.console.warn&&console.warn(t)},e.amd="function"==typeof define&&define.amd,e.isNumber=function(t){return!isNaN(parseFloat(t))&&isFinite(t)}),h=e.max=function(t){return Math.max.apply(Math,t
}}),n.pivot()},this)},draw:function(t){var e=t||1;i.each(this.getDataset().metaData,function(t,i){t.transition(e).draw()},this)},getElementsAtEvent:function(t){for(var e,a=[],n=i.getRelativePosition(t),s=function(t){a.push(t.metaData[e])},o=0;o<this.chart.data.datasets.length;o++)for(e=0;e<this.chart.data.datasets[o].metaData.length;e++)this.chart.data.datasets[o].metaData[e].inGroupRange(n.x,n.y)&&i.each(this.chart.data.datasets,s);return a.length?a:[]},getElementAtEvent:function(t){for(var e=[],a=i.getRelativePosition(t),n=0;n<this.chart.data.datasets.length;++n)for(var s=0;s<this.chart.data.datasets[n].metaData.length;++s)if(this.chart.data.datasets[n].metaData[s].inRange(a.x,a.y))return e.push(this.chart.data.datasets[n].metaData[s]),e;return[]}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.controllers.line=function(t,e){this.initialize.call(this,t,e)},i.extend(e.controllers.line.prototype,{initialize:function(t,e){this.chart=t,this.index=e,this.linkScales(),this.addElements()},linkScales:function(){this.getDataset().xAxisID||(this.getDataset().xAxisID=this.chart.options.scales.xAxes[0].id),this.getDataset().yAxisID||(this.getDataset().yAxisID=this.chart.options.scales.yAxes[0].id)},getDataset:function(){return this.chart.data.datasets[this.index]},getScaleForId:function(t){return this.chart.scales[t]},addElements:function(){this.getDataset().metaData=this.getDataset().metaData||[],this.getDataset().metaDataset=this.getDataset().metaDataset||new e.elements.Line({_chart:this.chart.chart,_datasetIndex:this.index,_points:this.getDataset().metaData}),i.each(this.getDataset().data,function(t,i){this.getDataset().metaData[i]=this.getDataset().metaData[i]||new e.elements.Point({_chart:this.chart.chart,_datasetIndex:this.index,_index:i})},this)},reset:function(){this.update(!0)},update:function(t){var e,a=this.getDataset().metaDataset,n=this.getDataset().metaData,s=this.getScaleForId(this.getDataset().yAxisID),o=this.getScaleForId(this.getDataset().xAxisID);e=s.min<0&&s.max<0?s.getPixelForValue(s.max):s.min>0&&s.max>0?s.getPixelForValue(s.min):s.getPixelForValue(0),i.extend(a,{_scale:s,_datasetIndex:this.index,_children:n,_model:{tension:a.custom&&a.custom.tension?a.custom.tension:this.getDataset().tension||this.chart.options.elements.line.tension,backgroundColor:a.custom&&a.custom.backgroundColor?a.custom.backgroundColor:this.getDataset().backgroundColor||this.chart.options.elements.line.backgroundColor,borderWidth:a.custom&&a.custom.borderWidth?a.custom.borderWidth:this.getDataset().borderWidth||this.chart.options.elements.line.borderWidth,borderColor:a.custom&&a.custom.borderColor?a.custom.borderColor:this.getDataset().borderColor||this.chart.options.elements.line.borderColor,fill:a.custom&&a.custom.fill?a.custom.fill:void 0!==this.getDataset().fill?this.getDataset().fill:this.chart.options.elements.line.fill,skipNull:void 0!==this.getDataset().skipNull?this.getDataset().skipNull:this.chart.options.elements.line.skipNull,drawNull:void 0!==this.getDataset().drawNull?this.getDataset().drawNull:this.chart.options.elements.line.drawNull,scaleTop:s.top,scaleBottom:s.bottom,scaleZero:e}}),a.pivot(),i.each(n,function(t,e){i.extend(t,{_chart:this.chart.chart,_xScale:o,_yScale:s,_datasetIndex:this.index,_index:e,_model:{x:o.getPointPixelForValue(this.getDataset().data[e],e,this.index),y:s.getPointPixelForValue(this.getDataset().data[e],e,this.index),tension:t.custom&&t.custom.tension?t.custom.tension:this.chart.options.elements.line.tension,radius:t.custom&&t.custom.radius?t.custom.radius:i.getValueAtIndexOrDefault(this.getDataset().radius,e,this.chart.options.elements.point.radius),backgroundColor:t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor,e,this.chart.options.elements.point.backgroundColor),borderColor:t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().pointBorderColor,e,this.chart.options.elements.point.borderColor),borderWidth:t.custom&&t.custom.borderWidth?t.custom.border
2015-06-12 22:00:48 +02:00
* Chart.js
* http://chartjs.org/
* Version: 2.0.0-alpha
*
* Copyright 2015 Nick Downie
* Released under the MIT license
* https://github.com/nnnick/Chart.js/blob/master/LICENSE.md
*/
function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.global.elements.arc={backgroundColor:e.defaults.global.defaultColor,borderColor:"#fff",borderWidth:2},e.Arc=e.Element.extend({inGroupRange:function(t){var e=this._view;return e?Math.pow(t-e.x,2)<Math.pow(e.radius+e.hoverRadius,2):!1},inRange:function(t,e){var a=this._view,n=i.getAngleFromPoint(a,{x:t,y:e}),s=a.startAngle<-.5*Math.PI?a.startAngle+2*Math.PI:a.startAngle>1.5*Math.PI?a.startAngle-2*Math.PI:a.startAngle,o=a.endAngle<-.5*Math.PI?a.endAngle+2*Math.PI:a.endAngle>1.5*Math.PI?a.endAngle-2*Math.PI:a.endAngle,r=n.angle>=s&&n.angle<=o,h=n.distance>=a.innerRadius&&n.distance<=a.outerRadius;return r&&h},tooltipPosition:function(){var t=this._view,e=t.startAngle+(t.endAngle-t.startAngle)/2,i=(t.outerRadius-t.innerRadius)/2+t.innerRadius;return{x:t.x+Math.cos(e)*i,y:t.y+Math.sin(e)*i}},draw:function(){var t=this._chart.ctx,e=this._view;t.beginPath(),t.arc(e.x,e.y,e.outerRadius,e.startAngle,e.endAngle),t.arc(e.x,e.y,e.innerRadius,e.endAngle,e.startAngle,!0),t.closePath(),t.strokeStyle=e.borderColor,t.lineWidth=e.borderWidth,t.fillStyle=e.backgroundColor,t.fill(),t.lineJoin="bevel",e.borderWidth&&t.stroke()}})}.call(this),/*!
2015-06-12 22:00:48 +02:00
* Chart.js
* http://chartjs.org/
* Version: 2.0.0-alpha
*
* Copyright 2015 Nick Downie
* Released under the MIT license
* https://github.com/nnnick/Chart.js/blob/master/LICENSE.md
*/
function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.global.elements.line={tension:.4,backgroundColor:e.defaults.global.defaultColor,borderWidth:3,borderColor:e.defaults.global.defaultColor,fill:!0,skipNull:!0,drawNull:!1},e.elements.Line=e.Element.extend({draw:function(){var t=this._view,a=this._chart.ctx,n=this._children[0],s=this._children[this._children.length-1];i.each(this._children,function(e,n){var s=i.previousItem(this._children,n),o=i.nextItem(this._children,n);return 0===n?void a.moveTo(e._view.x,e._view.y):(e._view.skip&&t.skipNull&&!this._loop?(a.lineTo(s._view.x,e._view.y),a.moveTo(o._view.x,e._view.y)):s._view.skip&&t.skipNull&&!this._loop&&(a.moveTo(e._view.x,s._view.y),a.lineTo(e._view.x,e._view.y)),void(s._view.skip&&t.skipNull?a.moveTo(e._view.x,e._view.y):t.tension>0?a.bezierCurveTo(s._view.controlPointNextX,s._view.controlPointNextY,e._view.controlPointPreviousX,e._view.controlPointPreviousY,e._view.x,e._view.y):a.lineTo(e._view.x,e._view.y)))},this),this._loop&&(t.tension>0&&!n._view.skip?a.bezierCurveTo(s._view.controlPointNextX,s._view.controlPointNextY,n._view.controlPointPreviousX,n._view.controlPointPreviousY,n._view.x,n._view.y):a.lineTo(n._view.x,n._view.y)),this._children.length>0&&t.fill&&(a.lineTo(this._children[this._children.length-1]._view.x,t.scaleZero),a.lineTo(this._children[0]._view.x,t.scaleZero),a.fillStyle=t.backgroundColor||e.defaults.global.defaultColor,a.closePath(),a.fill()),a.lineWidth=t.borderWidth||e.defaults.global.defaultColor,a.strokeStyle=t.borderColor||e.defaults.global.defaultColor,a.beginPath(),i.each(this._children,function(e,n){var s=i.previousItem(this._children,n),o=i.nextItem(this._children,n);return 0===n?void a.moveTo(e._view.x,e._view.y):e._view.skip&&t.skipNull&&!this._loop?(a.moveTo(s._view.x,e._view.y),void a.moveTo(o._view.x,e._view.y)):s._view.skip&&t.skipNull&&!this._loop?(a.moveTo(e._view.x,s._view.y),void a.moveTo(e._view.x,e._view.y)):s._view.skip&&t.skipNull?void a.moveTo(e._view.x,e._view.y):void(t.tension>0?a.bezierCurveTo(s._view.controlPointNextX,s._view.controlPointNextY,e._view.controlPointPreviousX,e._view.controlPointPreviousY,e._view.x,e._view.y):a.lineTo(e._view.x,e._view.y))},this),this._loop&&!n._view.skip&&(t.tension>0?a.bezierCurveTo(s._view.controlPointNextX,s._view.controlPointNextY,n._view.controlPointPreviousX,n._view.controlPointPreviousY,n._view.x,n._view.y):a.lineTo(n._view.x,n._view.y)),a.stroke()}})}.call(this),/*!
2015-06-12 22:00:48 +02:00
* Chart.js
* http://chartjs.org/
* Version: 2.0.0-alpha
*
* Copyright 2015 Nick Downie
* Released under the MIT license
* https://github.com/nnnick/Chart.js/blob/master/LICENSE.md
*/
function(){"use strict";var t=this,e=t.Chart;e.helpers;e.defaults.global.elements.point={radius:3,backgroundColor:e.defaults.global.defaultColor,borderWidth:1,borderColor:e.defaults.global.defaultColor,hitRadius:1,hoverRadius:4,hoverBorderWidth:1},e.elements.Point=e.Element.extend({inRange:function(t,e){var i=this._view,a=i.hitRadius+i.radius;return Math.pow(t-i.x,2)+Math.pow(e-i.y,2)<Math.pow(a,2)},inGroupRange:function(t){var e=this._view;return e?Math.pow(t-e.x,2)<Math.pow(e.radius+e.hitRadius,2):!1},tooltipPosition:function(){var t=this._view;return{x:t.x,y:t.y,padding:t.radius+t.borderWidth}},draw:function(){var t=this._view,i=this._chart.ctx;t.skip||(t.radius>0||t.borderWidth>0)&&(i.beginPath(),i.arc(t.x,t.y,t.radius||e.defaults.global.elements.point.radius,0,2*Math.PI),i.closePath(),i.strokeStyle=t.borderColor||e.defaults.global.defaultColor,i.lineWidth=t.borderWidth||e.defaults.global.elements.point.borderWidth,i.fillStyle=t.backgroundColor||e.defaults.global.defaultColor,i.fill(),i.stroke())}})}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.defaults.global.elements.rectangle={backgroundColor:e.defaults.global.defaultColor,borderWidth:0,borderColor:e.defaults.global.defaultColor},e.elements.Rectangle=e.Element.extend({draw:function(){var t=this._chart.ctx,e=this._view,i=e.width/2,a=e.x-i,n=e.x+i,s=e.base-(e.base-e.y),o=e.borderWidth/2;e.borderWidth&&(a+=o,n-=o,s+=o),t.beginPath(),t.fillStyle=e.backgroundColor,t.strokeStyle=e.borderColor,t.lineWidth=e.borderWidth,t.moveTo(a,e.base),t.lineTo(a,s),t.lineTo(n,s),t.lineTo(n,e.base),t.fill(),e.borderWidth&&t.stroke()},height:function(){var t=this._view;return t.base-t.y},inRange:function(t,e){var i=this._view;return i.y<i.base?t>=i.x-i.width/2&&t<=i.x+i.width/2&&e>=i.y&&e<=i.base:t>=i.x-i.width/2&&t<=i.x+i.width/2&&e>=i.base&&e<=i.y},inGroupRange:function(t){var e=this._view;return t>=e.x-e.width/2&&t<=e.x+e.width/2},tooltipPosition:function(){var t=this._view;return t.y<t.base?{x:t.x,y:t.y}:{x:t.x,y:t.base}}})}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.defaults.bar={hover:{mode:"label"},scales:{xAxes:[{type:"category",categorySpacing:10,spacing:1,gridLines:{offsetGridLines:!0}}],yAxes:[{type:"linear"}]}}}.call(this),!function t(e,i,a){function n(o,r){if(!i[o]){if(!e[o]){var h="function"==typeof require&&require;if(!r&&h)return h(o,!0);if(s)return s(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var c=i[o]={exports:{}};e[o][0].call(c.exports,function(t){var i=e[o][1][t];return n(i?i:t)},c,c.exports,t,e,i,a)}return i[o].exports}for(var s="function"==typeof require&&require,o=0;o<a.length;o++)n(a[o]);return n}({1:[function(t,e,i){!function(){var i=t("color-convert"),a=t("color-string"),n=function(t){if(t instanceof n)return t;if(!(this instanceof n))return new n(t);if(this.values={rgb:[0,0,0],hsl:[0,0,0],hsv:[0,0,0],hwb:[0,0,0],cmyk:[0,0,0,0],alpha:1},"string"==typeof t){var e=a.getRgba(t);if(e)this.setValues("rgb",e);else if(e=a.getHsla(t))this.setValues("hsl",e);else{if(!(e=a.getHwb(t)))throw new Error('Unable to parse color from string "'+t+'"');this.setValues("hwb",e)}}else if("object"==typeof t){var e=t;if(void 0!==e.r||void 0!==e.red)this.setValues("rgb",e);else if(void 0!==e.l||void 0!==e.lightness)this.setValues("hsl",e);else if(void 0!==e.v||void 0!==e.value)this.setValues("hsv",e);else if(void 0!==e.w||void 0!==e.whiteness)this.setValues("hwb",e);else{if(void 0===e.c&&void 0===e.cyan)throw new Error("Unable to parse color from object "+JSON.stringify(t));this.setValues("cmyk",e)}}};n.prototype={rgb:function(t){return this.setSpace("rgb",arguments)},hsl:function(t){return this.setSpace("hsl",arguments)},hsv:function(t){return this.setSpace("hsv",arguments)},hwb:function(t){return this.setSpace("hwb",arguments)},cmyk:function(t){return this.setSpace("cmyk",arguments)},rgbArray:function(){return this.values.rgb},hslArray:function(){return this.values.hsl},hsvArray:function(){return this.values.hsv},hwbArray:function(){return 1!==this.values.alpha?this.values.hwb.concat([this.va