2015-06-15 02:10:00 +02:00
|
|
|
/*!
|
|
|
|
* Chart.js
|
|
|
|
* http://chartjs.org/
|
|
|
|
* Version: {{ version }}
|
|
|
|
*
|
|
|
|
* Copyright 2015 Nick Downie
|
|
|
|
* Released under the MIT license
|
|
|
|
* https://github.com/nnnick/Chart.js/blob/master/LICENSE.md
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//Declare root variable - window in the browser, global on the server
|
|
|
|
var root = this,
|
|
|
|
previous = root.Chart;
|
|
|
|
|
|
|
|
//Occupy the global variable of Chart, and create a simple base class
|
2015-06-15 03:15:10 +02:00
|
|
|
var Chart = function(context, config) {
|
|
|
|
this.config = config;
|
2015-06-15 02:10:00 +02:00
|
|
|
|
|
|
|
// Support a jQuery'd canvas element
|
|
|
|
if (context.length && context[0].getContext) {
|
|
|
|
context = context[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Support a canvas domnode
|
|
|
|
if (context.getContext) {
|
|
|
|
context = context.getContext("2d");
|
|
|
|
}
|
|
|
|
|
2015-09-20 16:30:12 +02:00
|
|
|
this.ctx = context;
|
2015-06-15 02:10:00 +02:00
|
|
|
this.canvas = context.canvas;
|
|
|
|
|
2015-09-20 16:30:12 +02:00
|
|
|
// Figure out what the size of the chart will be.
|
|
|
|
// If the canvas has a specified width and height, we use those else
|
|
|
|
// we look to see if the canvas node has a CSS width and height.
|
|
|
|
// If there is still no height, fill the parent container
|
|
|
|
this.width = context.canvas.width || parseInt(Chart.helpers.getStyle(context.canvas, 'width')) || Chart.helpers.getMaximumWidth(context.canvas);
|
|
|
|
this.height = context.canvas.height || parseInt(Chart.helpers.getStyle(context.canvas, 'height')) || Chart.helpers.getMaximumHeight(context.canvas);
|
2015-06-15 02:10:00 +02:00
|
|
|
|
2015-09-20 16:30:12 +02:00
|
|
|
this.aspectRatio = this.width / this.height;
|
2015-06-15 02:10:00 +02:00
|
|
|
|
2015-09-20 16:30:12 +02:00
|
|
|
if (isNaN(this.aspectRatio) || isFinite(this.aspectRatio) === false) {
|
|
|
|
// If the canvas has no size, try and figure out what the aspect ratio will be.
|
|
|
|
// Some charts prefer square canvases (pie, radar, etc). If that is specified, use that
|
|
|
|
// else use the canvas default ratio of 2
|
|
|
|
this.aspectRatio = config.aspectRatio !== undefined ? config.aspectRatio : 2;
|
|
|
|
}
|
2015-06-15 02:10:00 +02:00
|
|
|
|
2015-09-23 01:22:55 +02:00
|
|
|
// Store the original style of the element so we can set it back
|
|
|
|
this.originalCanvasStyleWidth = context.canvas.style.width;
|
|
|
|
this.originalCanvasStyleHeight = context.canvas.style.height;
|
|
|
|
|
2015-09-20 16:30:12 +02:00
|
|
|
// High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
|
2015-09-19 23:52:58 +02:00
|
|
|
Chart.helpers.retinaScale(this);
|
2015-09-15 00:50:52 +02:00
|
|
|
|
2015-10-12 15:16:49 +02:00
|
|
|
if (config) {
|
|
|
|
this.controller = new Chart.Controller(this);
|
|
|
|
}
|
|
|
|
|
2015-09-20 16:30:12 +02:00
|
|
|
// Always bind this so that if the responsive state changes we still work
|
|
|
|
var _this = this;
|
|
|
|
Chart.helpers.addResizeListener(context.canvas.parentNode, function() {
|
2015-10-12 15:16:49 +02:00
|
|
|
if (_this.controller && _this.controller.config.options.responsive) {
|
2015-09-20 16:30:12 +02:00
|
|
|
_this.controller.resize();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-12 15:16:49 +02:00
|
|
|
return this.controller ? this.controller : this;
|
2015-06-15 02:10:00 +02:00
|
|
|
|
2015-06-15 22:36:02 +02:00
|
|
|
};
|
2015-06-15 02:10:00 +02:00
|
|
|
|
|
|
|
//Globally expose the defaults to allow for user updating/changing
|
|
|
|
Chart.defaults = {
|
|
|
|
global: {
|
|
|
|
responsive: true,
|
2015-06-16 21:06:34 +02:00
|
|
|
responsiveAnimationDuration: 0,
|
2015-06-15 02:10:00 +02:00
|
|
|
maintainAspectRatio: true,
|
2015-11-12 03:21:25 +01:00
|
|
|
events: ["mousemove", "mouseout", "click", "touchstart", "touchmove"],
|
2015-06-15 02:10:00 +02:00
|
|
|
hover: {
|
|
|
|
onHover: null,
|
|
|
|
mode: 'single',
|
|
|
|
animationDuration: 400,
|
|
|
|
},
|
|
|
|
onClick: null,
|
2015-06-15 22:36:02 +02:00
|
|
|
defaultColor: 'rgba(0,0,0,0.1)',
|
2016-02-02 03:06:54 +01:00
|
|
|
defaultFontColor: '#666',
|
|
|
|
defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
|
|
|
|
defaultFontSize: 12,
|
|
|
|
defaultFontStyle: 'normal',
|
2015-06-15 02:10:00 +02:00
|
|
|
|
|
|
|
// Element defaults defined in element extensions
|
2015-07-05 20:47:56 +02:00
|
|
|
elements: {},
|
2015-06-16 21:06:34 +02:00
|
|
|
|
2015-10-07 04:40:25 +02:00
|
|
|
// Legend callback string
|
|
|
|
legendCallback: function(chart) {
|
|
|
|
var text = [];
|
|
|
|
text.push('<ul class="' + chart.id + '-legend">');
|
|
|
|
for (var i = 0; i < chart.data.datasets.length; i++) {
|
|
|
|
text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '">');
|
|
|
|
if (chart.data.datasets[i].label) {
|
|
|
|
text.push(chart.data.datasets[i].label);
|
|
|
|
}
|
|
|
|
text.push('</span></li>');
|
|
|
|
}
|
|
|
|
text.push('</ul>');
|
|
|
|
|
|
|
|
return text.join("");
|
|
|
|
}
|
2015-06-15 02:10:00 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
root.Chart = Chart;
|
|
|
|
|
|
|
|
Chart.noConflict = function() {
|
|
|
|
root.Chart = previous;
|
|
|
|
return Chart;
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|