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-09-20 16:30:12 +02:00
// Always bind this so that if the responsive state changes we still work
2015-10-12 15:16:49 +02:00
if ( config ) {
this . controller = new Chart . Controller ( this ) ;
}
2015-09-20 16:30:12 +02:00
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 ,
events : [ "mousemove" , "mouseout" , "click" , "touchstart" , "touchmove" , "touchend" ] ,
hover : {
onHover : null ,
mode : 'single' ,
animationDuration : 400 ,
} ,
onClick : null ,
2015-06-15 22:36:02 +02:00
defaultColor : 'rgba(0,0,0,0.1)' ,
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-07-05 20:47:56 +02:00
// Legend template string
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i = 0; i < data.datasets.length; i++){%><li><span style=\"background-color:<%=data.datasets[i].backgroundColor%>\"><%if(data.datasets[i].label){%><%=data.datasets[i].label%><%}%></span></li><%}%></ul>" ,
2015-06-15 02:10:00 +02:00
} ,
} ;
if ( typeof amd !== 'undefined' ) {
define ( function ( ) {
return Chart ;
} ) ;
} else if ( typeof module === 'object' && module . exports ) {
module . exports = Chart ;
}
root . Chart = Chart ;
Chart . noConflict = function ( ) {
root . Chart = previous ;
return Chart ;
} ;
} ) . call ( this ) ;