Comparar commits
127 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| a62537a800 | |||
| 4495b63d0a | |||
| 75ce567d05 | |||
| ae103c3d0f | |||
| 1ccb100739 | |||
| 09efe9e6e2 | |||
| 31b883f815 | |||
| ef923dfe28 | |||
| 3f73433831 | |||
| d7117bc792 | |||
| cf767f71a2 | |||
| 668b532fbe | |||
| 6507f5c087 | |||
| 131b18059a | |||
| 48c082b04a | |||
| cf47543243 | |||
| 3f2119526d | |||
| d17c76ea1a | |||
| af3bcd5cfe | |||
| ea0d93c970 | |||
| 43606d1faa | |||
| 6009b00f74 | |||
| 8d6209271b | |||
| 57753b8280 | |||
| 111ada730c | |||
| 4aa274d5b2 | |||
| 4f4f804a71 | |||
| d4917afba9 | |||
| 37883689ad | |||
| cf0b550a80 | |||
| 3f658555ba | |||
| 1f1e6b4e44 | |||
| 3ac54b8790 | |||
| 126e318fef | |||
| 1d3cb8ec41 | |||
| 57bd8c7715 | |||
| 104143672b | |||
| c5f141306f | |||
| 299c4b3ae1 | |||
| cea557849a | |||
| 12a35b5d7b | |||
| cfa6eb1289 | |||
| 92d4d989f5 | |||
| cebbca67d1 | |||
| c47e4c1da1 | |||
| b06344563d | |||
| 77185993df | |||
| fd2344dd5f | |||
| e949edacf5 | |||
| a868a2f61e | |||
| ee6aabaffc | |||
| 69695235ac | |||
| 5cdd7a0893 | |||
| f63debe2c7 | |||
| 3c6a736413 | |||
| e94bd460a7 | |||
| 4297672424 | |||
| 07aa9473f1 | |||
| 2e9c3d3109 | |||
| a5e382ab8a | |||
| 4476c698c5 | |||
| 257da76b4c | |||
| a169e5ad41 | |||
| 682545e1e3 | |||
| 69e886ad5b | |||
| 249ca0cef7 | |||
| f1a3fb2361 | |||
| b87106c181 | |||
| b4856d2e24 | |||
| a68c53cf1e | |||
| 891bd63ac7 | |||
| 70b437b41a | |||
| 07b1758c2e | |||
| 55235ef03c | |||
| dfdd865508 | |||
| c11145bb2d | |||
| 9c39d47bc7 | |||
| 0510ba4139 | |||
| 85e6d1ae71 | |||
| 322abd4361 | |||
| f992ddd0d7 | |||
| 407eb846d0 | |||
| dd4a67e85c | |||
| 7fcd4dcae8 | |||
| 8481811110 | |||
| c38e852b61 | |||
| b601e2c2a1 | |||
| b41ba24fff | |||
| 8983929f18 | |||
| 2fff73f9e3 | |||
| 1ae2884a04 | |||
| 2b9a575d4d | |||
| 41fb914952 | |||
| a14309d95f | |||
| 80ba5aa1c5 | |||
| ac5bf729c5 | |||
| 3f77eb83b2 | |||
| ac360b8dd1 | |||
| c276c3a974 | |||
| d7ee18372a | |||
| 43f19359a9 | |||
| f56a7db8fc | |||
| 804fcea46a | |||
| 0bb3a9b024 | |||
| 961fd11098 | |||
| 66cf8ab787 | |||
| 79b02bcf26 | |||
| d5f1738a3f | |||
| f7e3962087 | |||
| 1367a234ee | |||
| 02616b9f17 | |||
| 3d389d7c09 | |||
| 28d30b4f5b | |||
| d1cccd3546 | |||
| 8db79ae365 | |||
| 8ef3aaa87d | |||
| e093fdf572 | |||
| 73b0d587ba | |||
| 2ce4291e98 | |||
| 598a6f3485 | |||
| b8691c9581 | |||
| 1df2b37bc5 | |||
| 66f7f96d4b | |||
| d91c4a14e9 | |||
| 9eedf9adb6 | |||
| 7045fdbb5a | |||
| ca7a39232a |
@@ -0,0 +1,19 @@
|
||||
---
|
||||
engines:
|
||||
duplication:
|
||||
enabled: true
|
||||
config:
|
||||
languages:
|
||||
- javascript
|
||||
eslint:
|
||||
enabled: true
|
||||
fixme:
|
||||
enabled: true
|
||||
ratings:
|
||||
paths:
|
||||
- "**.js"
|
||||
exclude_paths:
|
||||
- dist/
|
||||
- node_modules/
|
||||
- test/
|
||||
- coverage/
|
||||
@@ -0,0 +1 @@
|
||||
**/*{.,-}min.js
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
ecmaFeatures:
|
||||
modules: true
|
||||
jsx: true
|
||||
|
||||
env:
|
||||
amd: true
|
||||
browser: true
|
||||
es6: true
|
||||
jquery: true
|
||||
node: true
|
||||
|
||||
# http://eslint.org/docs/rules/
|
||||
rules:
|
||||
# Possible Errors
|
||||
comma-dangle: [2, never]
|
||||
no-cond-assign: 2
|
||||
no-console: 0
|
||||
no-constant-condition: 2
|
||||
no-control-regex: 2
|
||||
no-debugger: 2
|
||||
no-dupe-args: 2
|
||||
no-dupe-keys: 2
|
||||
no-duplicate-case: 2
|
||||
no-empty: 2
|
||||
no-empty-character-class: 2
|
||||
no-ex-assign: 2
|
||||
no-extra-boolean-cast: 2
|
||||
no-extra-parens: 0
|
||||
no-extra-semi: 2
|
||||
no-func-assign: 2
|
||||
no-inner-declarations: [2, functions]
|
||||
no-invalid-regexp: 2
|
||||
no-irregular-whitespace: 2
|
||||
no-negated-in-lhs: 2
|
||||
no-obj-calls: 2
|
||||
no-regex-spaces: 2
|
||||
no-sparse-arrays: 2
|
||||
no-unexpected-multiline: 2
|
||||
no-unreachable: 2
|
||||
use-isnan: 2
|
||||
valid-jsdoc: 0
|
||||
valid-typeof: 2
|
||||
|
||||
# Best Practices
|
||||
accessor-pairs: 2
|
||||
block-scoped-var: 0
|
||||
complexity: [2, 6]
|
||||
consistent-return: 0
|
||||
curly: 0
|
||||
default-case: 0
|
||||
dot-location: 0
|
||||
dot-notation: 0
|
||||
eqeqeq: 2
|
||||
guard-for-in: 2
|
||||
no-alert: 2
|
||||
no-caller: 2
|
||||
no-case-declarations: 2
|
||||
no-div-regex: 2
|
||||
no-else-return: 0
|
||||
no-empty-label: 2
|
||||
no-empty-pattern: 2
|
||||
no-eq-null: 2
|
||||
no-eval: 2
|
||||
no-extend-native: 2
|
||||
no-extra-bind: 2
|
||||
no-fallthrough: 2
|
||||
no-floating-decimal: 0
|
||||
no-implicit-coercion: 0
|
||||
no-implied-eval: 2
|
||||
no-invalid-this: 0
|
||||
no-iterator: 2
|
||||
no-labels: 0
|
||||
no-lone-blocks: 2
|
||||
no-loop-func: 2
|
||||
no-magic-number: 0
|
||||
no-multi-spaces: 0
|
||||
no-multi-str: 0
|
||||
no-native-reassign: 2
|
||||
no-new-func: 2
|
||||
no-new-wrappers: 2
|
||||
no-new: 2
|
||||
no-octal-escape: 2
|
||||
no-octal: 2
|
||||
no-proto: 2
|
||||
no-redeclare: 2
|
||||
no-return-assign: 2
|
||||
no-script-url: 2
|
||||
no-self-compare: 2
|
||||
no-sequences: 0
|
||||
no-throw-literal: 0
|
||||
no-unused-expressions: 2
|
||||
no-useless-call: 2
|
||||
no-useless-concat: 2
|
||||
no-void: 2
|
||||
no-warning-comments: 0
|
||||
no-with: 2
|
||||
radix: 2
|
||||
vars-on-top: 0
|
||||
wrap-iife: 2
|
||||
yoda: 0
|
||||
|
||||
# Strict
|
||||
strict: 0
|
||||
|
||||
# Variables
|
||||
init-declarations: 0
|
||||
no-catch-shadow: 2
|
||||
no-delete-var: 2
|
||||
no-label-var: 2
|
||||
no-shadow-restricted-names: 2
|
||||
no-shadow: 0
|
||||
no-undef-init: 2
|
||||
no-undef: 0
|
||||
no-undefined: 0
|
||||
no-unused-vars: 0
|
||||
no-use-before-define: 0
|
||||
|
||||
# Node.js and CommonJS
|
||||
callback-return: 2
|
||||
global-require: 2
|
||||
handle-callback-err: 2
|
||||
no-mixed-requires: 0
|
||||
no-new-require: 0
|
||||
no-path-concat: 2
|
||||
no-process-exit: 2
|
||||
no-restricted-modules: 0
|
||||
no-sync: 0
|
||||
|
||||
# Stylistic Issues
|
||||
array-bracket-spacing: 0
|
||||
block-spacing: 0
|
||||
brace-style: 0
|
||||
camelcase: 0
|
||||
comma-spacing: 0
|
||||
comma-style: 0
|
||||
computed-property-spacing: 0
|
||||
consistent-this: 0
|
||||
eol-last: 0
|
||||
func-names: 0
|
||||
func-style: 0
|
||||
id-length: 0
|
||||
id-match: 0
|
||||
indent: 0
|
||||
jsx-quotes: 0
|
||||
key-spacing: 0
|
||||
linebreak-style: 0
|
||||
lines-around-comment: 0
|
||||
max-depth: 0
|
||||
max-len: 0
|
||||
max-nested-callbacks: 0
|
||||
max-params: 0
|
||||
max-statements: [2, 30]
|
||||
new-cap: 0
|
||||
new-parens: 0
|
||||
newline-after-var: 0
|
||||
no-array-constructor: 0
|
||||
no-bitwise: 0
|
||||
no-continue: 0
|
||||
no-inline-comments: 0
|
||||
no-lonely-if: 0
|
||||
no-mixed-spaces-and-tabs: 0
|
||||
no-multiple-empty-lines: 0
|
||||
no-negated-condition: 0
|
||||
no-nested-ternary: 0
|
||||
no-new-object: 0
|
||||
no-plusplus: 0
|
||||
no-restricted-syntax: 0
|
||||
no-spaced-func: 0
|
||||
no-ternary: 0
|
||||
no-trailing-spaces: 0
|
||||
no-underscore-dangle: 0
|
||||
no-unneeded-ternary: 0
|
||||
object-curly-spacing: 0
|
||||
one-var: 0
|
||||
operator-assignment: 0
|
||||
operator-linebreak: 0
|
||||
padded-blocks: 0
|
||||
quote-props: 0
|
||||
quotes: 0
|
||||
require-jsdoc: 0
|
||||
semi-spacing: 0
|
||||
semi: 0
|
||||
sort-vars: 0
|
||||
space-after-keywords: 0
|
||||
space-before-blocks: 0
|
||||
space-before-function-paren: 0
|
||||
space-before-keywords: 0
|
||||
space-in-parens: 0
|
||||
space-infix-ops: 0
|
||||
space-return-throw-case: 0
|
||||
space-unary-ops: 0
|
||||
spaced-comment: 0
|
||||
wrap-regex: 0
|
||||
|
||||
# ECMAScript 6
|
||||
arrow-body-style: 0
|
||||
arrow-parens: 0
|
||||
arrow-spacing: 0
|
||||
constructor-super: 0
|
||||
generator-star-spacing: 0
|
||||
no-arrow-condition: 0
|
||||
no-class-assign: 0
|
||||
no-const-assign: 0
|
||||
no-dupe-class-members: 0
|
||||
no-this-before-super: 0
|
||||
no-var: 0
|
||||
object-shorthand: 0
|
||||
prefer-arrow-callback: 0
|
||||
prefer-const: 0
|
||||
prefer-reflect: 0
|
||||
prefer-spread: 0
|
||||
prefer-template: 0
|
||||
require-yield: 0
|
||||
@@ -3,5 +3,8 @@
|
||||
|
||||
node_modules/*
|
||||
custom/*
|
||||
coverage/*
|
||||
|
||||
docs/index.md
|
||||
|
||||
.settings/
|
||||
|
||||
+3
-1
@@ -35,6 +35,8 @@ Pull requests
|
||||
|
||||
Clear, concise pull requests are excellent at continuing the project's community driven growth. But please review [these guidelines](https://github.com/blog/1943-how-to-write-the-perfect-pull-request) and the guidelines below before starting work on the project.
|
||||
|
||||
Be advised that **Chart.js 1.0.2 is in feature-complete status**. Pull requests adding new features to the 1.x branch will be disregarded.
|
||||
|
||||
Guidlines:
|
||||
|
||||
- Please create an issue first:
|
||||
@@ -45,7 +47,7 @@ Guidlines:
|
||||
- If adding new functionality, please also update the relevant `.md` file in [`/docs`](https://github.com/nnnick/Chart.js/tree/master/docs)
|
||||
- Please make your commits in logical sections with clear commit messages
|
||||
|
||||
Joining the Project
|
||||
Joining the project
|
||||
-------------
|
||||
- Active committers and contributors are invited to introduce yourself and request commit access to this project. Please send an email to hello@nickdownie.com or file an issue.
|
||||
|
||||
|
||||
externo
+354
-95
@@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* Chart.js
|
||||
* http://chartjs.org/
|
||||
* Version: 1.0.2
|
||||
* Version: 1.1.1
|
||||
*
|
||||
* Copyright 2015 Nick Downie
|
||||
* Released under the MIT license
|
||||
@@ -35,17 +35,11 @@
|
||||
{
|
||||
return document.defaultView.getComputedStyle(element).getPropertyValue(dimension);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var width = this.width = computeDimension(context.canvas,'Width');
|
||||
var height = this.height = computeDimension(context.canvas,'Height');
|
||||
var width = this.width = computeDimension(context.canvas,'Width') || context.canvas.width;
|
||||
var height = this.height = computeDimension(context.canvas,'Height') || context.canvas.height;
|
||||
|
||||
// Firefox requires this to work correctly
|
||||
context.canvas.width = width;
|
||||
context.canvas.height = height;
|
||||
|
||||
var width = this.width = context.canvas.width;
|
||||
var height = this.height = context.canvas.height;
|
||||
this.aspectRatio = this.width / this.height;
|
||||
//High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
|
||||
helpers.retinaScale(this);
|
||||
@@ -150,6 +144,9 @@
|
||||
// String - Tooltip title font colour
|
||||
tooltipTitleFontColor: "#fff",
|
||||
|
||||
// String - Tooltip title template
|
||||
tooltipTitleTemplate: "<%= label%>",
|
||||
|
||||
// Number - pixel width of padding around tooltip text
|
||||
tooltipYPadding: 6,
|
||||
|
||||
@@ -169,11 +166,17 @@
|
||||
tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",
|
||||
|
||||
// String - Template string for single tooltips
|
||||
multiTooltipTemplate: "<%= value %>",
|
||||
multiTooltipTemplate: "<%= datasetLabel %>: <%= value %>",
|
||||
|
||||
// String - Colour behind the legend colour block
|
||||
multiTooltipKeyBackground: '#fff',
|
||||
|
||||
// Array - A list of colors to use as the defaults
|
||||
segmentColorDefault: ["#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00", "#CAB2D6", "#6A3D9A", "#B4B482", "#B15928" ],
|
||||
|
||||
// Array - A list of highlight colors to use as the defaults
|
||||
segmentHighlightColorDefaults: [ "#CEF6FF", "#47A0DC", "#DAFFB2", "#5BC854", "#FFC2C1", "#FF4244", "#FFE797", "#FFA728", "#F2DAFE", "#9265C2", "#DCDCAA", "#D98150" ],
|
||||
|
||||
// Function - Will fire on animation progression.
|
||||
onAnimationProgress: function(){},
|
||||
|
||||
@@ -210,14 +213,18 @@
|
||||
clone = helpers.clone = function(obj){
|
||||
var objClone = {};
|
||||
each(obj,function(value,key){
|
||||
if (obj.hasOwnProperty(key)) objClone[key] = value;
|
||||
if (obj.hasOwnProperty(key)){
|
||||
objClone[key] = value;
|
||||
}
|
||||
});
|
||||
return objClone;
|
||||
},
|
||||
extend = helpers.extend = function(base){
|
||||
each(Array.prototype.slice.call(arguments,1), function(extensionObject) {
|
||||
each(extensionObject,function(value,key){
|
||||
if (extensionObject.hasOwnProperty(key)) base[key] = value;
|
||||
if (extensionObject.hasOwnProperty(key)){
|
||||
base[key] = value;
|
||||
}
|
||||
});
|
||||
});
|
||||
return base;
|
||||
@@ -300,9 +307,9 @@
|
||||
})(),
|
||||
warn = helpers.warn = function(str){
|
||||
//Method for warning of errors
|
||||
if (window.console && typeof window.console.warn == "function") console.warn(str);
|
||||
if (window.console && typeof window.console.warn === "function") console.warn(str);
|
||||
},
|
||||
amd = helpers.amd = (typeof define == 'function' && define.amd),
|
||||
amd = helpers.amd = (typeof define === 'function' && define.amd),
|
||||
//-- Math methods
|
||||
isNumber = helpers.isNumber = function(n){
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
@@ -328,7 +335,20 @@
|
||||
},
|
||||
getDecimalPlaces = helpers.getDecimalPlaces = function(num){
|
||||
if (num%1!==0 && isNumber(num)){
|
||||
return num.toString().split(".")[1].length;
|
||||
var s = num.toString();
|
||||
if(s.indexOf("e-") < 0){
|
||||
// no exponent, e.g. 0.01
|
||||
return s.split(".")[1].length;
|
||||
}
|
||||
else if(s.indexOf(".") < 0) {
|
||||
// no decimal point, e.g. 1e-9
|
||||
return parseInt(s.split("e-")[1]);
|
||||
}
|
||||
else {
|
||||
// exponent and decimal point, e.g. 1.23e-9
|
||||
var parts = s.split(".")[1].split("e-");
|
||||
return parts[0].length + parseInt(parts[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
@@ -387,10 +407,15 @@
|
||||
maxSteps = Math.floor(drawingSize/(textSize * 1.5)),
|
||||
skipFitting = (minSteps >= maxSteps);
|
||||
|
||||
var maxValue = max(valuesArray),
|
||||
minValue = min(valuesArray);
|
||||
// Filter out null values since these would min() to zero
|
||||
var values = [];
|
||||
each(valuesArray, function( v ){
|
||||
v == null || values.push( v );
|
||||
});
|
||||
var minValue = min(values),
|
||||
maxValue = max(values);
|
||||
|
||||
// We need some degree of seperation here to calculate the scales if all the values are the same
|
||||
// We need some degree of separation here to calculate the scales if all the values are the same
|
||||
// Adding/minusing 0.5 will give us a range of 1.
|
||||
if (maxValue === minValue){
|
||||
maxValue += 0.5;
|
||||
@@ -505,7 +530,7 @@
|
||||
/* jshint ignore:end */
|
||||
generateLabels = helpers.generateLabels = function(templateString,numberOfSteps,graphMin,stepValue){
|
||||
var labelsArray = new Array(numberOfSteps);
|
||||
if (labelTemplateString){
|
||||
if (templateString){
|
||||
each(labelsArray,function(val,index){
|
||||
labelsArray[index] = template(templateString,{value: (graphMin + (stepValue*(index+1)))});
|
||||
});
|
||||
@@ -526,7 +551,9 @@
|
||||
return -1 * t * (t - 2);
|
||||
},
|
||||
easeInOutQuad: function (t) {
|
||||
if ((t /= 1 / 2) < 1) return 1 / 2 * t * t;
|
||||
if ((t /= 1 / 2) < 1){
|
||||
return 1 / 2 * t * t;
|
||||
}
|
||||
return -1 / 2 * ((--t) * (t - 2) - 1);
|
||||
},
|
||||
easeInCubic: function (t) {
|
||||
@@ -536,7 +563,9 @@
|
||||
return 1 * ((t = t / 1 - 1) * t * t + 1);
|
||||
},
|
||||
easeInOutCubic: function (t) {
|
||||
if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t;
|
||||
if ((t /= 1 / 2) < 1){
|
||||
return 1 / 2 * t * t * t;
|
||||
}
|
||||
return 1 / 2 * ((t -= 2) * t * t + 2);
|
||||
},
|
||||
easeInQuart: function (t) {
|
||||
@@ -546,7 +575,9 @@
|
||||
return -1 * ((t = t / 1 - 1) * t * t * t - 1);
|
||||
},
|
||||
easeInOutQuart: function (t) {
|
||||
if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t;
|
||||
if ((t /= 1 / 2) < 1){
|
||||
return 1 / 2 * t * t * t * t;
|
||||
}
|
||||
return -1 / 2 * ((t -= 2) * t * t * t - 2);
|
||||
},
|
||||
easeInQuint: function (t) {
|
||||
@@ -556,7 +587,9 @@
|
||||
return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
|
||||
},
|
||||
easeInOutQuint: function (t) {
|
||||
if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t * t;
|
||||
if ((t /= 1 / 2) < 1){
|
||||
return 1 / 2 * t * t * t * t * t;
|
||||
}
|
||||
return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
|
||||
},
|
||||
easeInSine: function (t) {
|
||||
@@ -575,60 +608,95 @@
|
||||
return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
|
||||
},
|
||||
easeInOutExpo: function (t) {
|
||||
if (t === 0) return 0;
|
||||
if (t === 1) return 1;
|
||||
if ((t /= 1 / 2) < 1) return 1 / 2 * Math.pow(2, 10 * (t - 1));
|
||||
if (t === 0){
|
||||
return 0;
|
||||
}
|
||||
if (t === 1){
|
||||
return 1;
|
||||
}
|
||||
if ((t /= 1 / 2) < 1){
|
||||
return 1 / 2 * Math.pow(2, 10 * (t - 1));
|
||||
}
|
||||
return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
|
||||
},
|
||||
easeInCirc: function (t) {
|
||||
if (t >= 1) return t;
|
||||
if (t >= 1){
|
||||
return t;
|
||||
}
|
||||
return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
|
||||
},
|
||||
easeOutCirc: function (t) {
|
||||
return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
|
||||
},
|
||||
easeInOutCirc: function (t) {
|
||||
if ((t /= 1 / 2) < 1) return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
|
||||
if ((t /= 1 / 2) < 1){
|
||||
return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
|
||||
}
|
||||
return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
|
||||
},
|
||||
easeInElastic: function (t) {
|
||||
var s = 1.70158;
|
||||
var p = 0;
|
||||
var a = 1;
|
||||
if (t === 0) return 0;
|
||||
if ((t /= 1) == 1) return 1;
|
||||
if (!p) p = 1 * 0.3;
|
||||
if (t === 0){
|
||||
return 0;
|
||||
}
|
||||
if ((t /= 1) == 1){
|
||||
return 1;
|
||||
}
|
||||
if (!p){
|
||||
p = 1 * 0.3;
|
||||
}
|
||||
if (a < Math.abs(1)) {
|
||||
a = 1;
|
||||
s = p / 4;
|
||||
} else s = p / (2 * Math.PI) * Math.asin(1 / a);
|
||||
} else{
|
||||
s = p / (2 * Math.PI) * Math.asin(1 / a);
|
||||
}
|
||||
return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
|
||||
},
|
||||
easeOutElastic: function (t) {
|
||||
var s = 1.70158;
|
||||
var p = 0;
|
||||
var a = 1;
|
||||
if (t === 0) return 0;
|
||||
if ((t /= 1) == 1) return 1;
|
||||
if (!p) p = 1 * 0.3;
|
||||
if (t === 0){
|
||||
return 0;
|
||||
}
|
||||
if ((t /= 1) == 1){
|
||||
return 1;
|
||||
}
|
||||
if (!p){
|
||||
p = 1 * 0.3;
|
||||
}
|
||||
if (a < Math.abs(1)) {
|
||||
a = 1;
|
||||
s = p / 4;
|
||||
} else s = p / (2 * Math.PI) * Math.asin(1 / a);
|
||||
} else{
|
||||
s = p / (2 * Math.PI) * Math.asin(1 / a);
|
||||
}
|
||||
return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
|
||||
},
|
||||
easeInOutElastic: function (t) {
|
||||
var s = 1.70158;
|
||||
var p = 0;
|
||||
var a = 1;
|
||||
if (t === 0) return 0;
|
||||
if ((t /= 1 / 2) == 2) return 1;
|
||||
if (!p) p = 1 * (0.3 * 1.5);
|
||||
if (t === 0){
|
||||
return 0;
|
||||
}
|
||||
if ((t /= 1 / 2) == 2){
|
||||
return 1;
|
||||
}
|
||||
if (!p){
|
||||
p = 1 * (0.3 * 1.5);
|
||||
}
|
||||
if (a < Math.abs(1)) {
|
||||
a = 1;
|
||||
s = p / 4;
|
||||
} else s = p / (2 * Math.PI) * Math.asin(1 / a);
|
||||
if (t < 1) return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
|
||||
} else {
|
||||
s = p / (2 * Math.PI) * Math.asin(1 / a);
|
||||
}
|
||||
if (t < 1){
|
||||
return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));}
|
||||
return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
|
||||
},
|
||||
easeInBack: function (t) {
|
||||
@@ -641,7 +709,9 @@
|
||||
},
|
||||
easeInOutBack: function (t) {
|
||||
var s = 1.70158;
|
||||
if ((t /= 1 / 2) < 1) return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
|
||||
if ((t /= 1 / 2) < 1){
|
||||
return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
|
||||
}
|
||||
return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
|
||||
},
|
||||
easeInBounce: function (t) {
|
||||
@@ -659,7 +729,9 @@
|
||||
}
|
||||
},
|
||||
easeInOutBounce: function (t) {
|
||||
if (t < 1 / 2) return easingEffects.easeInBounce(t * 2) * 0.5;
|
||||
if (t < 1 / 2){
|
||||
return easingEffects.easeInBounce(t * 2) * 0.5;
|
||||
}
|
||||
return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
|
||||
}
|
||||
},
|
||||
@@ -762,14 +834,21 @@
|
||||
});
|
||||
},
|
||||
getMaximumWidth = helpers.getMaximumWidth = function(domNode){
|
||||
var container = domNode.parentNode;
|
||||
var container = domNode.parentNode,
|
||||
padding = parseInt(getStyle(container, 'padding-left')) + parseInt(getStyle(container, 'padding-right'));
|
||||
// TODO = check cross browser stuff with this.
|
||||
return container.clientWidth;
|
||||
return container ? container.clientWidth - padding : 0;
|
||||
},
|
||||
getMaximumHeight = helpers.getMaximumHeight = function(domNode){
|
||||
var container = domNode.parentNode;
|
||||
var container = domNode.parentNode,
|
||||
padding = parseInt(getStyle(container, 'padding-bottom')) + parseInt(getStyle(container, 'padding-top'));
|
||||
// TODO = check cross browser stuff with this.
|
||||
return container.clientHeight;
|
||||
return container ? container.clientHeight - padding : 0;
|
||||
},
|
||||
getStyle = helpers.getStyle = function (el, property) {
|
||||
return el.currentStyle ?
|
||||
el.currentStyle[property] :
|
||||
document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
|
||||
},
|
||||
getMaximumSize = helpers.getMaximumSize = helpers.getMaximumWidth, // legacy support
|
||||
retinaScale = helpers.retinaScale = function(chart){
|
||||
@@ -844,7 +923,7 @@
|
||||
},
|
||||
stop : function(){
|
||||
// Stops any current animation loop occuring
|
||||
cancelAnimFrame(this.animationFrame);
|
||||
Chart.animationService.cancelAnimation(this);
|
||||
return this;
|
||||
},
|
||||
resize : function(callback){
|
||||
@@ -868,15 +947,26 @@
|
||||
if (reflow){
|
||||
this.reflow();
|
||||
}
|
||||
|
||||
if (this.options.animation && !reflow){
|
||||
helpers.animationLoop(
|
||||
this.draw,
|
||||
this.options.animationSteps,
|
||||
this.options.animationEasing,
|
||||
this.options.onAnimationProgress,
|
||||
this.options.onAnimationComplete,
|
||||
this
|
||||
);
|
||||
var animation = new Chart.Animation();
|
||||
animation.numSteps = this.options.animationSteps;
|
||||
animation.easing = this.options.animationEasing;
|
||||
|
||||
// render function
|
||||
animation.render = function(chartInstance, animationObject) {
|
||||
var easingFunction = helpers.easingEffects[animationObject.easing];
|
||||
var stepDecimal = animationObject.currentStep / animationObject.numSteps;
|
||||
var easeDecimal = easingFunction(stepDecimal);
|
||||
|
||||
chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
|
||||
};
|
||||
|
||||
// user events
|
||||
animation.onAnimationProgress = this.options.onAnimationProgress;
|
||||
animation.onAnimationComplete = this.options.onAnimationComplete;
|
||||
|
||||
Chart.animationService.addAnimation(this, animation);
|
||||
}
|
||||
else{
|
||||
this.draw();
|
||||
@@ -885,9 +975,10 @@
|
||||
return this;
|
||||
},
|
||||
generateLegend : function(){
|
||||
return template(this.options.legendTemplate,this);
|
||||
return helpers.template(this.options.legendTemplate, this);
|
||||
},
|
||||
destroy : function(){
|
||||
this.stop();
|
||||
this.clear();
|
||||
unbindEvents(this, this.events);
|
||||
var canvas = this.chart.canvas;
|
||||
@@ -1015,7 +1106,7 @@
|
||||
labels: tooltipLabels,
|
||||
legendColors: tooltipColors,
|
||||
legendColorBackground : this.options.multiTooltipKeyBackground,
|
||||
title: ChartElements[0].label,
|
||||
title: template(this.options.tooltipTitleTemplate,ChartElements[0]),
|
||||
chart: this.chart,
|
||||
ctx: this.chart.ctx,
|
||||
custom: this.options.customTooltips
|
||||
@@ -1199,9 +1290,18 @@
|
||||
y: chartY
|
||||
});
|
||||
|
||||
// Normalize all angles to 0 - 2*PI (0 - 360°)
|
||||
var pointRelativeAngle = pointRelativePosition.angle % (Math.PI * 2),
|
||||
startAngle = (Math.PI * 2 + this.startAngle) % (Math.PI * 2),
|
||||
endAngle = (Math.PI * 2 + this.endAngle) % (Math.PI * 2) || 360;
|
||||
|
||||
// Calculate wether the pointRelativeAngle is between the start and the end angle
|
||||
var betweenAngles = (endAngle < startAngle) ?
|
||||
pointRelativeAngle <= endAngle || pointRelativeAngle >= startAngle:
|
||||
pointRelativeAngle >= startAngle && pointRelativeAngle <= endAngle;
|
||||
|
||||
//Check if within the range of the open/close angle
|
||||
var betweenAngles = (pointRelativePosition.angle >= this.startAngle && pointRelativePosition.angle <= this.endAngle),
|
||||
withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
|
||||
var withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
|
||||
|
||||
return (betweenAngles && withinRadius);
|
||||
//Ensure within the outside of the arc centre, but inside arc outer
|
||||
@@ -1222,9 +1322,9 @@
|
||||
|
||||
ctx.beginPath();
|
||||
|
||||
ctx.arc(this.x, this.y, this.outerRadius, this.startAngle, this.endAngle);
|
||||
ctx.arc(this.x, this.y, this.outerRadius < 0 ? 0 : this.outerRadius, this.startAngle, this.endAngle);
|
||||
|
||||
ctx.arc(this.x, this.y, this.innerRadius, this.endAngle, this.startAngle, true);
|
||||
ctx.arc(this.x, this.y, this.innerRadius < 0 ? 0 : this.innerRadius, this.endAngle, this.startAngle, true);
|
||||
|
||||
ctx.closePath();
|
||||
ctx.strokeStyle = this.strokeColor;
|
||||
@@ -1283,6 +1383,16 @@
|
||||
}
|
||||
});
|
||||
|
||||
Chart.Animation = Chart.Element.extend({
|
||||
currentStep: null, // the current animation step
|
||||
numSteps: 60, // default number of steps
|
||||
easing: "", // the easing to use for this animation
|
||||
render: null, // render function used by the animation service
|
||||
|
||||
onAnimationProgress: null, // user specified callback to fire on each step of the animation
|
||||
onAnimationComplete: null, // user specified callback to fire when the animation finishes
|
||||
});
|
||||
|
||||
Chart.Tooltip = Chart.Element.extend({
|
||||
draw : function(){
|
||||
|
||||
@@ -1372,7 +1482,8 @@
|
||||
|
||||
this.titleFont = fontString(this.titleFontSize,this.titleFontStyle,this.titleFontFamily);
|
||||
|
||||
this.height = (this.labels.length * this.fontSize) + ((this.labels.length-1) * (this.fontSize/2)) + (this.yPadding*2) + this.titleFontSize *1.5;
|
||||
this.titleHeight = this.title ? this.titleFontSize * 1.5 : 0;
|
||||
this.height = (this.labels.length * this.fontSize) + ((this.labels.length-1) * (this.fontSize/2)) + (this.yPadding*2) + this.titleHeight;
|
||||
|
||||
this.ctx.font = this.titleFont;
|
||||
|
||||
@@ -1408,9 +1519,9 @@
|
||||
|
||||
//If the index is zero, we're getting the title
|
||||
if (index === 0){
|
||||
return baseLineHeight + this.titleFontSize/2;
|
||||
return baseLineHeight + this.titleHeight / 3;
|
||||
} else{
|
||||
return baseLineHeight + ((this.fontSize*1.5*afterTitleIndex) + this.fontSize/2) + this.titleFontSize * 1.5;
|
||||
return baseLineHeight + ((this.fontSize * 1.5 * afterTitleIndex) + this.fontSize / 2) + this.titleHeight;
|
||||
}
|
||||
|
||||
},
|
||||
@@ -1466,7 +1577,7 @@
|
||||
for (var i=0; i<=this.steps; i++){
|
||||
this.yLabels.push(template(this.templateString,{value:(this.min + (i * this.stepValue)).toFixed(stepDecimalPlaces)}));
|
||||
}
|
||||
this.yLabelWidth = (this.display && this.showLabels) ? longestText(this.ctx,this.font,this.yLabels) : 0;
|
||||
this.yLabelWidth = (this.display && this.showLabels) ? longestText(this.ctx,this.font,this.yLabels) + 10 : 0;
|
||||
},
|
||||
addXLabel : function(label){
|
||||
this.xLabels.push(label);
|
||||
@@ -1490,6 +1601,9 @@
|
||||
this.startPoint += this.padding;
|
||||
this.endPoint -= this.padding;
|
||||
|
||||
// Cache the starting endpoint, excluding the space for x labels
|
||||
var cachedEndPoint = this.endPoint;
|
||||
|
||||
// Cache the starting height, so can determine if we need to recalculate the scale yAxis
|
||||
var cachedHeight = this.endPoint - this.startPoint,
|
||||
cachedYLabelWidth;
|
||||
@@ -1521,6 +1635,7 @@
|
||||
|
||||
// Only go through the xLabel loop again if the yLabel width has changed
|
||||
if (cachedYLabelWidth < this.yLabelWidth){
|
||||
this.endPoint = cachedEndPoint;
|
||||
this.calculateXLabelRotation();
|
||||
}
|
||||
}
|
||||
@@ -1539,7 +1654,7 @@
|
||||
|
||||
|
||||
this.xScalePaddingRight = lastWidth/2 + 3;
|
||||
this.xScalePaddingLeft = (firstWidth/2 > this.yLabelWidth + 10) ? firstWidth/2 : this.yLabelWidth + 10;
|
||||
this.xScalePaddingLeft = (firstWidth/2 > this.yLabelWidth) ? firstWidth/2 : this.yLabelWidth;
|
||||
|
||||
this.xLabelRotation = 0;
|
||||
if (this.display){
|
||||
@@ -1558,7 +1673,7 @@
|
||||
lastRotated = cosRotation * lastWidth;
|
||||
|
||||
// We're right aligning the text now.
|
||||
if (firstRotated + this.fontSize / 2 > this.yLabelWidth + 8){
|
||||
if (firstRotated + this.fontSize / 2 > this.yLabelWidth){
|
||||
this.xScalePaddingLeft = firstRotated + this.fontSize / 2;
|
||||
}
|
||||
this.xScalePaddingRight = this.fontSize/2;
|
||||
@@ -1940,14 +2055,40 @@
|
||||
ctx.lineWidth = this.angleLineWidth;
|
||||
ctx.strokeStyle = this.angleLineColor;
|
||||
for (var i = this.valuesCount - 1; i >= 0; i--) {
|
||||
if (this.angleLineWidth > 0){
|
||||
var outerPosition = this.getPointPosition(i, this.calculateCenterOffset(this.max));
|
||||
var centerOffset = null, outerPosition = null;
|
||||
|
||||
if (this.angleLineWidth > 0 && (i % this.angleLineInterval === 0)){
|
||||
centerOffset = this.calculateCenterOffset(this.max);
|
||||
outerPosition = this.getPointPosition(i, centerOffset);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.xCenter, this.yCenter);
|
||||
ctx.lineTo(outerPosition.x, outerPosition.y);
|
||||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
if (this.backgroundColors && this.backgroundColors.length == this.valuesCount) {
|
||||
if (centerOffset == null)
|
||||
centerOffset = this.calculateCenterOffset(this.max);
|
||||
|
||||
if (outerPosition == null)
|
||||
outerPosition = this.getPointPosition(i, centerOffset);
|
||||
|
||||
var previousOuterPosition = this.getPointPosition(i === 0 ? this.valuesCount - 1 : i - 1, centerOffset);
|
||||
var nextOuterPosition = this.getPointPosition(i === this.valuesCount - 1 ? 0 : i + 1, centerOffset);
|
||||
|
||||
var previousOuterHalfway = { x: (previousOuterPosition.x + outerPosition.x) / 2, y: (previousOuterPosition.y + outerPosition.y) / 2 };
|
||||
var nextOuterHalfway = { x: (outerPosition.x + nextOuterPosition.x) / 2, y: (outerPosition.y + nextOuterPosition.y) / 2 };
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.xCenter, this.yCenter);
|
||||
ctx.lineTo(previousOuterHalfway.x, previousOuterHalfway.y);
|
||||
ctx.lineTo(outerPosition.x, outerPosition.y);
|
||||
ctx.lineTo(nextOuterHalfway.x, nextOuterHalfway.y);
|
||||
ctx.fillStyle = this.backgroundColors[i];
|
||||
ctx.fill();
|
||||
ctx.closePath();
|
||||
}
|
||||
// Extra 3px out for some label spacing
|
||||
var pointLabelPosition = this.getPointPosition(i, this.calculateCenterOffset(this.max) + 5);
|
||||
ctx.font = fontString(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily);
|
||||
@@ -1984,6 +2125,93 @@
|
||||
}
|
||||
});
|
||||
|
||||
Chart.animationService = {
|
||||
frameDuration: 17,
|
||||
animations: [],
|
||||
dropFrames: 0,
|
||||
addAnimation: function(chartInstance, animationObject) {
|
||||
for (var index = 0; index < this.animations.length; ++ index){
|
||||
if (this.animations[index].chartInstance === chartInstance){
|
||||
// replacing an in progress animation
|
||||
this.animations[index].animationObject = animationObject;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.animations.push({
|
||||
chartInstance: chartInstance,
|
||||
animationObject: animationObject
|
||||
});
|
||||
|
||||
// If there are no animations queued, manually kickstart a digest, for lack of a better word
|
||||
if (this.animations.length == 1) {
|
||||
helpers.requestAnimFrame.call(window, this.digestWrapper);
|
||||
}
|
||||
},
|
||||
// Cancel the animation for a given chart instance
|
||||
cancelAnimation: function(chartInstance) {
|
||||
var index = helpers.findNextWhere(this.animations, function(animationWrapper) {
|
||||
return animationWrapper.chartInstance === chartInstance;
|
||||
});
|
||||
|
||||
if (index)
|
||||
{
|
||||
this.animations.splice(index, 1);
|
||||
}
|
||||
},
|
||||
// calls startDigest with the proper context
|
||||
digestWrapper: function() {
|
||||
Chart.animationService.startDigest.call(Chart.animationService);
|
||||
},
|
||||
startDigest: function() {
|
||||
|
||||
var startTime = Date.now();
|
||||
var framesToDrop = 0;
|
||||
|
||||
if(this.dropFrames > 1){
|
||||
framesToDrop = Math.floor(this.dropFrames);
|
||||
this.dropFrames -= framesToDrop;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.animations.length; i++) {
|
||||
|
||||
if (this.animations[i].animationObject.currentStep === null){
|
||||
this.animations[i].animationObject.currentStep = 0;
|
||||
}
|
||||
|
||||
this.animations[i].animationObject.currentStep += 1 + framesToDrop;
|
||||
if(this.animations[i].animationObject.currentStep > this.animations[i].animationObject.numSteps){
|
||||
this.animations[i].animationObject.currentStep = this.animations[i].animationObject.numSteps;
|
||||
}
|
||||
|
||||
this.animations[i].animationObject.render(this.animations[i].chartInstance, this.animations[i].animationObject);
|
||||
|
||||
// Check if executed the last frame.
|
||||
if (this.animations[i].animationObject.currentStep == this.animations[i].animationObject.numSteps){
|
||||
// Call onAnimationComplete
|
||||
this.animations[i].animationObject.onAnimationComplete.call(this.animations[i].chartInstance);
|
||||
// Remove the animation.
|
||||
this.animations.splice(i, 1);
|
||||
// Keep the index in place to offset the splice
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
var endTime = Date.now();
|
||||
var delay = endTime - startTime - this.frameDuration;
|
||||
var frameDelay = delay / this.frameDuration;
|
||||
|
||||
if(frameDelay > 1){
|
||||
this.dropFrames += frameDelay;
|
||||
}
|
||||
|
||||
// Do we have more stuff to animate?
|
||||
if (this.animations.length > 0){
|
||||
helpers.requestAnimFrame.call(window, this.digestWrapper);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Attach global event to resize each chart instance when the browser resizes
|
||||
helpers.addEvent(window, "resize", (function(){
|
||||
// Basic debounce of resize function so it doesn't hurt performance when resizing browser.
|
||||
@@ -2004,7 +2232,7 @@
|
||||
|
||||
|
||||
if (amd) {
|
||||
define(function(){
|
||||
define('Chart', [], function(){
|
||||
return Chart;
|
||||
});
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
@@ -2060,7 +2288,7 @@
|
||||
barDatasetSpacing : 1,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=datasets[i].fillColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
|
||||
};
|
||||
|
||||
@@ -2105,8 +2333,10 @@
|
||||
bar.restore(['fillColor', 'strokeColor']);
|
||||
});
|
||||
helpers.each(activeBars, function(activeBar){
|
||||
activeBar.fillColor = activeBar.highlightFill;
|
||||
activeBar.strokeColor = activeBar.highlightStroke;
|
||||
if (activeBar) {
|
||||
activeBar.fillColor = activeBar.highlightFill;
|
||||
activeBar.strokeColor = activeBar.highlightStroke;
|
||||
}
|
||||
});
|
||||
this.showTooltip(activeBars);
|
||||
});
|
||||
@@ -2137,10 +2367,10 @@
|
||||
value : dataPoint,
|
||||
label : data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
strokeColor : dataset.strokeColor,
|
||||
fillColor : dataset.fillColor,
|
||||
highlightFill : dataset.highlightFill || dataset.fillColor,
|
||||
highlightStroke : dataset.highlightStroke || dataset.strokeColor
|
||||
strokeColor : (typeof dataset.strokeColor == 'object') ? dataset.strokeColor[index] : dataset.strokeColor,
|
||||
fillColor : (typeof dataset.fillColor == 'object') ? dataset.fillColor[index] : dataset.fillColor,
|
||||
highlightFill : (dataset.highlightFill) ? (typeof dataset.highlightFill == 'object') ? dataset.highlightFill[index] : dataset.highlightFill : (typeof dataset.fillColor == 'object') ? dataset.fillColor[index] : dataset.fillColor,
|
||||
highlightStroke : (dataset.highlightStroke) ? (typeof dataset.highlightStroke == 'object') ? dataset.highlightStroke[index] : dataset.highlightStroke : (typeof dataset.strokeColor == 'object') ? dataset.strokeColor[index] : dataset.strokeColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
@@ -2262,6 +2492,7 @@
|
||||
this.datasets[datasetIndex].bars.push(new this.BarClass({
|
||||
value : value,
|
||||
label : label,
|
||||
datasetLabel: this.datasets[datasetIndex].label,
|
||||
x: this.scale.calculateBarX(this.datasets.length, datasetIndex, this.scale.valuesCount+1),
|
||||
y: this.scale.endPoint,
|
||||
width : this.scale.calculateBarWidth(this.datasets.length),
|
||||
@@ -2357,15 +2588,14 @@
|
||||
animateScale : false,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=segments[i].fillColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
|
||||
};
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
//Passing in a name registers this chart in the Chart namespace
|
||||
name: "Doughnut",
|
||||
//Providing a defaults will also register the deafults in the chart namespace
|
||||
//Providing a defaults will also register the defaults in the chart namespace
|
||||
defaults : defaultConfig,
|
||||
//Initialize is fired when the chart is initialized - Data is passed in as a parameter
|
||||
//Config is automatically merged by the core of Chart.js, and is available at this.options
|
||||
@@ -2398,6 +2628,9 @@
|
||||
this.calculateTotal(data);
|
||||
|
||||
helpers.each(data,function(datapoint, index){
|
||||
if (!datapoint.color) {
|
||||
datapoint.color = 'hsl(' + (360 * index / data.length) + ', 100%, 50%)';
|
||||
}
|
||||
this.addData(datapoint, index, true);
|
||||
},this);
|
||||
|
||||
@@ -2414,7 +2647,11 @@
|
||||
return segmentsArray;
|
||||
},
|
||||
addData : function(segment, atIndex, silent){
|
||||
var index = atIndex || this.segments.length;
|
||||
var index = atIndex !== undefined ? atIndex : this.segments.length;
|
||||
if ( typeof(segment.color) === "undefined" ) {
|
||||
segment.color = Chart.defaults.global.segmentColorDefault[index % Chart.defaults.global.segmentColorDefault.length];
|
||||
segment.highlight = Chart.defaults.global.segmentHighlightColorDefaults[index % Chart.defaults.global.segmentHighlightColorDefaults.length];
|
||||
}
|
||||
this.segments.splice(index, 0, new this.SegmentArc({
|
||||
value : segment.value,
|
||||
outerRadius : (this.options.animateScale) ? 0 : this.outerRadius,
|
||||
@@ -2433,8 +2670,12 @@
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
calculateCircumference : function(value){
|
||||
return (Math.PI*2)*(Math.abs(value) / this.total);
|
||||
calculateCircumference : function(value) {
|
||||
if ( this.total > 0 ) {
|
||||
return (Math.PI*2)*(value / this.total);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
calculateTotal : function(data){
|
||||
this.total = 0;
|
||||
@@ -2507,6 +2748,7 @@
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
@@ -2559,7 +2801,10 @@
|
||||
datasetFill : true,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=datasets[i].strokeColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>",
|
||||
|
||||
//Boolean - Whether to horizontally center the label and point dot inside the grid
|
||||
offsetGridLines : false
|
||||
|
||||
};
|
||||
|
||||
@@ -2570,6 +2815,7 @@
|
||||
initialize: function(data){
|
||||
//Declare the extension of the default point, to cater for the options passed in to the constructor
|
||||
this.PointClass = Chart.Point.extend({
|
||||
offsetGridLines : this.options.offsetGridLines,
|
||||
strokeWidth : this.options.pointDotStrokeWidth,
|
||||
radius : this.options.pointDotRadius,
|
||||
display: this.options.pointDot,
|
||||
@@ -2685,6 +2931,7 @@
|
||||
width : this.chart.width,
|
||||
ctx : this.chart.ctx,
|
||||
textColor : this.options.scaleFontColor,
|
||||
offsetGridLines : this.options.offsetGridLines,
|
||||
fontSize : this.options.scaleFontSize,
|
||||
fontStyle : this.options.scaleFontStyle,
|
||||
fontFamily : this.options.scaleFontFamily,
|
||||
@@ -2735,6 +2982,7 @@
|
||||
this.datasets[datasetIndex].points.push(new this.PointClass({
|
||||
value : value,
|
||||
label : label,
|
||||
datasetLabel: this.datasets[datasetIndex].label,
|
||||
x: this.scale.calculateX(this.scale.valuesCount+1),
|
||||
y: this.scale.endPoint,
|
||||
strokeColor : this.datasets[datasetIndex].pointStrokeColor,
|
||||
@@ -2778,6 +3026,7 @@
|
||||
return helpers.findPreviousWhere(collection, hasValue, index) || point;
|
||||
};
|
||||
|
||||
if (!this.scale) return;
|
||||
this.scale.draw(easingDecimal);
|
||||
|
||||
|
||||
@@ -2797,7 +3046,7 @@
|
||||
},this);
|
||||
|
||||
|
||||
// Control points need to be calculated in a seperate loop, because we need to know the current x/y of the point
|
||||
// Control points need to be calculated in a separate loop, because we need to know the current x/y of the point
|
||||
// This would cause issues when there is no animation, because the y of the next point would be 0, so beziers would be skewed
|
||||
if (this.options.bezierCurve){
|
||||
helpers.each(pointsWithValues, function(point, index){
|
||||
@@ -2858,7 +3107,9 @@
|
||||
}
|
||||
}, this);
|
||||
|
||||
ctx.stroke();
|
||||
if (this.options.datasetStroke) {
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
if (this.options.datasetFill && pointsWithValues.length > 0){
|
||||
//Round off the line by going to the base of the chart, back to the start, then fill.
|
||||
@@ -2912,7 +3163,7 @@
|
||||
//Boolean - Stroke a line around each segment in the chart
|
||||
segmentShowStroke : true,
|
||||
|
||||
//String - The colour of the stroke on each segement.
|
||||
//String - The colour of the stroke on each segment.
|
||||
segmentStrokeColor : "#fff",
|
||||
|
||||
//Number - The width of the stroke value in pixels
|
||||
@@ -2931,14 +3182,14 @@
|
||||
animateScale : false,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=segments[i].fillColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
};
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
//Passing in a name registers this chart in the Chart namespace
|
||||
name: "PolarArea",
|
||||
//Providing a defaults will also register the deafults in the chart namespace
|
||||
//Providing a defaults will also register the defaults in the chart namespace
|
||||
defaults : defaultConfig,
|
||||
//Initialize is fired when the chart is initialized - Data is passed in as a parameter
|
||||
//Config is automatically merged by the core of Chart.js, and is available at this.options
|
||||
@@ -3132,6 +3383,7 @@
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
@@ -3162,6 +3414,9 @@
|
||||
//Number - Pixel width of the angle line
|
||||
angleLineWidth : 1,
|
||||
|
||||
//Number - Interval at which to draw angle lines ("every Nth point")
|
||||
angleLineInterval: 1,
|
||||
|
||||
//String - Point label font declaration
|
||||
pointLabelFontFamily : "'Arial'",
|
||||
|
||||
@@ -3196,7 +3451,7 @@
|
||||
datasetFill : true,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=datasets[i].strokeColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
|
||||
},
|
||||
|
||||
@@ -3308,12 +3563,14 @@
|
||||
showLabels: this.options.scaleShowLabels,
|
||||
showLabelBackdrop: this.options.scaleShowLabelBackdrop,
|
||||
backdropColor: this.options.scaleBackdropColor,
|
||||
backgroundColors: this.options.scaleBackgroundColors,
|
||||
backdropPaddingY : this.options.scaleBackdropPaddingY,
|
||||
backdropPaddingX: this.options.scaleBackdropPaddingX,
|
||||
lineWidth: (this.options.scaleShowLine) ? this.options.scaleLineWidth : 0,
|
||||
lineColor: this.options.scaleLineColor,
|
||||
angleLineColor : this.options.angleLineColor,
|
||||
angleLineWidth : (this.options.angleShowLineOut) ? this.options.angleLineWidth : 0,
|
||||
angleLineInterval: (this.options.angleLineInterval) ? this.options.angleLineInterval : 1,
|
||||
// Point labels at the edge of each line
|
||||
pointLabelFontColor : this.options.pointLabelFontColor,
|
||||
pointLabelFontSize : this.options.pointLabelFontSize,
|
||||
@@ -3379,6 +3636,7 @@
|
||||
this.datasets[datasetIndex].points.push(new this.PointClass({
|
||||
value : value,
|
||||
label : label,
|
||||
datasetLabel: this.datasets[datasetIndex].label,
|
||||
x: pointPosition.x,
|
||||
y: pointPosition.y,
|
||||
strokeColor : this.datasets[datasetIndex].pointStrokeColor,
|
||||
@@ -3453,8 +3711,9 @@
|
||||
ctx.stroke();
|
||||
|
||||
ctx.fillStyle = dataset.fillColor;
|
||||
ctx.fill();
|
||||
|
||||
if(this.options.datasetFill){
|
||||
ctx.fill();
|
||||
}
|
||||
//Now draw the points over the line
|
||||
//A little inefficient double looping, but better than the line
|
||||
//lagging behind the point positions
|
||||
@@ -3474,4 +3733,4 @@
|
||||
|
||||
|
||||
|
||||
}).call(this);
|
||||
}).call(this);
|
||||
|
||||
externo
+3
-3
Diff do arquivo suprimido porque uma ou mais linhas são muito longas
+2
-1
@@ -1,4 +1,5 @@
|
||||
Copyright (c) 2013-2015 Nick Downie
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2013-2016 Nick Downie
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
+46
-5
@@ -1,15 +1,56 @@
|
||||
[](http://www.chartjs.org/docs/)
|
||||
|
||||
# Chart.js
|
||||
|
||||
[](https://travis-ci.org/nnnick/Chart.js) [](https://codeclimate.com/github/nnnick/Chart.js)
|
||||
[](https://travis-ci.org/nnnick/Chart.js) [](https://codeclimate.com/github/nnnick/Chart.js) [](https://chartjs-slack-automation.herokuapp.com/)
|
||||
|
||||
|
||||
*Simple HTML5 Charts using the canvas element* [chartjs.org](http://www.chartjs.org)
|
||||
|
||||
## Documentation
|
||||
## v1.0.2 Stable
|
||||
|
||||
You can find documentation at [chartjs.org/docs](http://www.chartjs.org/docs/). The markdown files that build the site are available under `/docs`. Please note - in some of the json examples of configuration you might notice some liquid tags - this is just for the generating the site html, please disregard.
|
||||
- NPM: `npm install chart.js --save`
|
||||
- Bower: `bower install Chart.js --save`
|
||||
- CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js
|
||||
- Zip: [Download](https://github.com/nnnick/Chart.js/archive/master.zip)
|
||||
|
||||
## Bugs, issues and contributing
|
||||
[Examples](https://github.com/nnnick/Chart.js/tree/master/samples) | [Documentation](http://www.chartjs.org/docs/)
|
||||
|
||||
## v2.0 Beta
|
||||
|
||||
- Release: [2.0.0-beta](https://github.com/nnnick/Chart.js/releases/tag/2.0.0-beta)
|
||||
- Zip: [Download](https://github.com/nnnick/Chart.js/archive/2.0.0-beta2.zip)
|
||||
|
||||
Documentation for v2.0 is currently located [here](http://nnnick.github.io/Chart.js/docs-v2/).
|
||||
|
||||
## v2.0 Bleeding-Edge
|
||||
|
||||
- Branch: [v2.0-dev](https://github.com/nnnick/Chart.js/tree/v2.0-dev)
|
||||
- Zip: [Download](https://github.com/nnnick/Chart.js/archive/v2.0-dev.zip)
|
||||
|
||||
The next generation and release of Chart.js (v2.0) has been well under way this year and we are very close to releasing some amazing new features including, but not limited to:
|
||||
- Rewritten, optimized, and unit-tested
|
||||
- New and improved scales (log, time, linear, category, multiple scales)
|
||||
- Improved Tooltips and tooltip callbacks for customization
|
||||
- Improved responsiveness and resizing
|
||||
- Powerful support for adding, removing, changing, and updating data on the fly
|
||||
- Animations for everything, including all elements, colors and tooltips
|
||||
- Powerful customization when you need it. Automatic and dynamic when you don't.
|
||||
- Excellent support for modern frameworks and modular build systems.
|
||||
- Even more extensible via new element controllers, core scale classes, combo chart support, and hook systems
|
||||
- Bug fixes, stability improvements, etc.
|
||||
|
||||
#####Contributing to 2.0
|
||||
Submit PR's to the v2.0-dev branch.
|
||||
|
||||
#####Building and Testing
|
||||
`gulp build`, `gulp test`, `gulp watch --test`
|
||||
|
||||
#####v1.x Status: Feature Complete
|
||||
v1.x is now considered feature complete. PR's for bug fixes are still extremely welcome. Any open PR's for v1.x features will need to be reconsidered, refactored and resubmitted for v2.x (if the feature has not already been implemented). For questions on new features refer to the docs in the v2.0-dev branch
|
||||
|
||||
|
||||
## Bugs, Issues and Contributing
|
||||
|
||||
Before submitting an issue or a pull request to the project, please take a moment to look over the [contributing guidelines](https://github.com/nnnick/Chart.js/blob/master/CONTRIBUTING.md) first.
|
||||
|
||||
@@ -17,4 +58,4 @@ For support using Chart.js, please post questions with the [`chartjs` tag on Sta
|
||||
|
||||
## License
|
||||
|
||||
Chart.js is available under the [MIT license](http://opensource.org/licenses/MIT).
|
||||
Chart.js is available under the [MIT license](https://github.com/nnnick/Chart.js/blob/master/LICENSE.md).
|
||||
|
||||
+12
-2
@@ -1,11 +1,21 @@
|
||||
{
|
||||
"name": "Chart.js",
|
||||
"version": "1.0.2",
|
||||
"description": "Simple HTML5 Charts using the canvas element",
|
||||
"homepage": "https://github.com/nnnick/Chart.js",
|
||||
"author": "nnnick",
|
||||
"main": [
|
||||
"Chart.js"
|
||||
],
|
||||
"dependencies": {}
|
||||
"ignore": [
|
||||
"**/*",
|
||||
".travis.yml",
|
||||
"CONTRIBUTING.md",
|
||||
"Chart.js",
|
||||
"LICENSE.md",
|
||||
"README.md",
|
||||
"gulpfile.js",
|
||||
"package.json"
|
||||
],
|
||||
"dependencies": {},
|
||||
"version": "1.1.1"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "nnnick/chartjs",
|
||||
"type": "library",
|
||||
"description": "Simple HTML5 charts using the canvas element.",
|
||||
"keywords": [
|
||||
"chart",
|
||||
"js"
|
||||
],
|
||||
"homepage": "http://www.chartjs.org/",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "NICK DOWNIE",
|
||||
"email": "hello@nickdownie.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"release/2.0": "v2.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,14 @@ First we need to include the Chart.js library on the page. The library occupies
|
||||
<script src="Chart.js"></script>
|
||||
```
|
||||
|
||||
Alternatively, if you're using an AMD loader for JavaScript modules, that is also supported in the Chart.js core. Please note: the library will still occupy a global variable of `Chart`, even if it detects `define` and `define.amd`. If this is a problem, you can call `noConflict` to restore the global Chart variable to it's previous owner.
|
||||
Alternatively, if you're using an AMD loader for JavaScript modules, that is also supported in the Chart.js core. Please note: the library will still occupy a global variable of `Chart`, even if it detects `define` and `define.amd`. If this is a problem, you can call `noConflict` to restore the global Chart variable to its previous owner.
|
||||
|
||||
```javascript
|
||||
// Using requirejs
|
||||
require(['path/to/Chartjs'], function(Chart){
|
||||
// Use Chart.js as normal here.
|
||||
|
||||
// Chart.noConflict restores the Chart global variable to it's previous owner
|
||||
// Chart.noConflict restores the Chart global variable to its previous owner
|
||||
// The function returns what was previously Chart, allowing you to reassign.
|
||||
var Chartjs = Chart.noConflict();
|
||||
|
||||
@@ -31,9 +31,15 @@ You can also grab Chart.js using bower:
|
||||
bower install Chart.js --save
|
||||
```
|
||||
|
||||
or NPM:
|
||||
|
||||
```bash
|
||||
npm install chart.js --save
|
||||
```
|
||||
|
||||
Also, Chart.js is available from CDN:
|
||||
|
||||
https://cdnjs.com/libraries/chart.js
|
||||
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js
|
||||
|
||||
###Creating a chart
|
||||
|
||||
@@ -72,6 +78,10 @@ We call a method of the name of the chart we want to create. We pass in the data
|
||||
|
||||
This concept was introduced in Chart.js 1.0 to keep configuration DRY, and allow for changing options globally across chart types, avoiding the need to specify options for each instance, or the default for a particular chart type.
|
||||
|
||||
Templates are based on micro templating by John Resig:
|
||||
|
||||
http://ejohn.org/blog/javascript-micro-templating/
|
||||
|
||||
```javascript
|
||||
Chart.defaults.global = {
|
||||
// Boolean - Whether to animate the chart
|
||||
@@ -144,7 +154,7 @@ Chart.defaults.global = {
|
||||
// Boolean - Determines whether to draw tooltips on the canvas or not
|
||||
showTooltips: true,
|
||||
|
||||
// Function - Determines whether to execute the customTooltips function instead of drawing the built in tooltips (See [Advanced - External Tooltips](#advanced-usage-custom-tooltips))
|
||||
// Function - Determines whether to execute the customTooltips function instead of drawing the built in tooltips (See [Advanced - External Tooltips](#advanced-usage-external-tooltips))
|
||||
customTooltips: false,
|
||||
|
||||
// Array - Array of string names to attach tooltip events
|
||||
@@ -177,6 +187,9 @@ Chart.defaults.global = {
|
||||
// String - Tooltip title font colour
|
||||
tooltipTitleFontColor: "#fff",
|
||||
|
||||
// String - Tooltip title template
|
||||
tooltipTitleTemplate: "<%= label%>",
|
||||
|
||||
// Number - pixel width of padding around tooltip text
|
||||
tooltipYPadding: 6,
|
||||
|
||||
@@ -213,3 +226,22 @@ Chart.defaults.global.responsive = true;
|
||||
```
|
||||
|
||||
Now, every time we create a chart, `options.responsive` will be `true`.
|
||||
|
||||
###Tooltip Templates
|
||||
For the `tooltipTemplate` and `multiTooltipTemplate` configuration options, you may use special template blocks. **Do not use user input in the tooltip template, as it may be executed as raw JavaScript.**
|
||||
|
||||
Anything in between `<%` and `%>` will be executed as JavaScript. As in the example shown above, `<% if (label) { %>` and later `<% } %>`. Using `<%= expr %>` will print the value of the variable named by `expr` into the tooltip.
|
||||
|
||||
The available variables to print into the tooltip depends on the chart type. In general, the following variables are available:
|
||||
|
||||
```javascript
|
||||
{
|
||||
value : "value of the data point",
|
||||
label : "label for the position the data point is at",
|
||||
datasetLabel: "label for the dataset the point is from",
|
||||
strokeColor : "stroke color for the dataset",
|
||||
fillColor : "fill color for the dataset",
|
||||
highlightFill : "highlight fill color for the dataset",
|
||||
highlightStroke : "highlight stroke color for the dataset"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -45,7 +45,7 @@ var data = {
|
||||
};
|
||||
```
|
||||
|
||||
The line chart requires an array of labels for each of the data points. This is shown on the X axis.
|
||||
The line chart requires an array of labels. This labels are shown on the X axis. There must be one label for each data point. More labels than datapoints are allowed, in which case the line ends at the last data point.
|
||||
The data for line charts is broken up into an array of datasets. Each dataset has a colour for the fill, a colour for the line and colours for the points and strokes of the points. These colours are strings just like CSS. You can use RGBA, RGB, HEX or HSL notation.
|
||||
|
||||
The label key on each dataset is optional, and can be used when generating a scale for the chart.
|
||||
@@ -100,7 +100,7 @@ These are the customisation options specific to Line charts. These options are m
|
||||
datasetFill : true,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
|
||||
//Boolean - Whether to horizontally center the label and point dot inside the grid
|
||||
|
||||
@@ -84,7 +84,7 @@ These are the customisation options specific to Bar charts. These options are me
|
||||
barDatasetSpacing : 1,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -76,6 +76,9 @@ These are the customisation options specific to Radar charts. These options are
|
||||
//Number - Pixel width of the angle line
|
||||
angleLineWidth : 1,
|
||||
|
||||
//Number - Interval at which to draw angle lines ("every Nth point")
|
||||
angleLineInterval: 1,
|
||||
|
||||
//String - Point label font declaration
|
||||
pointLabelFontFamily : "'Arial'",
|
||||
|
||||
@@ -110,7 +113,7 @@ These are the customisation options specific to Radar charts. These options are
|
||||
datasetFill : true,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
@@ -174,4 +177,4 @@ Calling `removeData()` on your Chart instance will remove the first value for al
|
||||
```javascript
|
||||
myRadarChart.removeData();
|
||||
// Other points will now animate to their correct positions.
|
||||
```
|
||||
```
|
||||
|
||||
@@ -102,7 +102,7 @@ These are the customisation options specific to Polar Area charts. These options
|
||||
animateScale : false,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -88,7 +88,7 @@ These are the customisation options specific to Pie & Doughnut charts. These opt
|
||||
animateScale : false,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
@@ -137,6 +137,8 @@ myDoughnutChart.update();
|
||||
|
||||
Calling `addData(segmentData, index)` on your Chart instance passing an object in the same format as in the constructor. There is an optional second argument of 'index', this determines at what index the new segment should be inserted into the chart.
|
||||
|
||||
If you don't specify a color and highliht, one will be chosen from the global default array: segmentColorDefault and the corresponding segmentHighlightColorDefault. The index of the addded data is used to lookup a corresponding color from the defaults.
|
||||
|
||||
```javascript
|
||||
// An object in the same format as the original data source
|
||||
myDoughnutChart.addData({
|
||||
|
||||
@@ -54,7 +54,7 @@ myLineChart.destroy();
|
||||
|
||||
#### .toBase64Image()
|
||||
|
||||
This returns a base 64 encoded string of the chart in it's current state.
|
||||
This returns a base 64 encoded string of the chart in its current state.
|
||||
|
||||
```javascript
|
||||
myLineChart.toBase64Image();
|
||||
@@ -96,7 +96,7 @@ var myPieChart = new Chart(ctx).Pie(data, {
|
||||
// tooltip.y
|
||||
// etc...
|
||||
|
||||
};
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
@@ -176,7 +176,7 @@ npm install -g gulp
|
||||
|
||||
This will install the local development dependencies for Chart.js, along with a CLI for the JavaScript task runner <a href="http://gulpjs.com/" target="_blank">gulp</a>.
|
||||
|
||||
Now, we can run the `gulp build` task, and pass in a comma seperated list of types as an argument to build a custom version of Chart.js with only specified chart types.
|
||||
Now, we can run the `gulp build` task, and pass in a comma-separated list of types as an argument to build a custom version of Chart.js with only specified chart types.
|
||||
|
||||
Here we will create a version of Chart.js with only Line, Radar and Bar charts included:
|
||||
|
||||
|
||||
+11
-1
@@ -12,7 +12,8 @@ var gulp = require('gulp'),
|
||||
exec = require('child_process').exec,
|
||||
fs = require('fs'),
|
||||
package = require('./package.json'),
|
||||
bower = require('./bower.json');
|
||||
bower = require('./bower.json'),
|
||||
livereload = require('gulp-livereload');
|
||||
|
||||
var srcDir = './src/';
|
||||
/*
|
||||
@@ -114,6 +115,15 @@ gulp.task('module-sizes', function(){
|
||||
|
||||
gulp.task('watch', function(){
|
||||
gulp.watch('./src/*', ['build']);
|
||||
|
||||
livereload.listen(35729);
|
||||
|
||||
var reloadPage = function (evt) {
|
||||
livereload.changed(evt.path);
|
||||
};
|
||||
|
||||
gulp.watch(['Chart.js', 'samples/*'], reloadPage);
|
||||
|
||||
});
|
||||
|
||||
gulp.task('test', ['jshint', 'valid']);
|
||||
|
||||
+6
-4
@@ -2,25 +2,27 @@
|
||||
"name": "chart.js",
|
||||
"homepage": "http://www.chartjs.org",
|
||||
"description": "Simple HTML5 charts using the canvas element.",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.1",
|
||||
"main": "Chart.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nnnick/Chart.js.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependences": {},
|
||||
"devDependencies": {
|
||||
"gulp": "3.5.x",
|
||||
"gulp": "3.9.x",
|
||||
"gulp-concat": "~2.1.x",
|
||||
"gulp-connect": "~2.0.5",
|
||||
"gulp-jshint": "~1.5.1",
|
||||
"gulp-replace": "^0.4.0",
|
||||
"gulp-size": "~0.4.0",
|
||||
"gulp-uglify": "~0.2.x",
|
||||
"gulp-uglify": "~1.5.x",
|
||||
"gulp-util": "~2.2.x",
|
||||
"gulp-html-validator": "^0.0.2",
|
||||
"inquirer": "^0.5.1",
|
||||
"semver": "^3.0.1"
|
||||
"semver": "^3.0.1",
|
||||
"gulp-livereload": "^3.8.0"
|
||||
},
|
||||
"spm": {
|
||||
"main": "Chart.js"
|
||||
|
||||
+1
-13
@@ -3,17 +3,15 @@
|
||||
<head>
|
||||
<title>Bar Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width: 50%">
|
||||
<canvas id="canvas" height="450" width="600"></canvas>
|
||||
</div>
|
||||
<button id="randomizeData">Randomize Data</button>
|
||||
|
||||
|
||||
<script>
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
var randomColorFactor = function(){ return Math.round(Math.random()*255)};
|
||||
|
||||
var barChartData = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
@@ -42,16 +40,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
$('#randomizeData').click(function(){
|
||||
barChartData.datasets[0].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
||||
barChartData.datasets[0].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
|
||||
|
||||
barChartData.datasets[1].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
||||
barChartData.datasets[1].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
|
||||
|
||||
window.myBar.update();
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+5
-18
@@ -3,7 +3,6 @@
|
||||
<head>
|
||||
<title>Doughnut Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
<style>
|
||||
body{
|
||||
padding: 0;
|
||||
@@ -18,41 +17,37 @@
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area" width="500" height="500"/>
|
||||
</div>
|
||||
<button id="randomizeData">Randomize Data</button>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
var randomColorFactor = function(){ return Math.round(Math.random()*255)};
|
||||
|
||||
var doughnutData = [
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
@@ -65,14 +60,6 @@
|
||||
window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {responsive : true});
|
||||
};
|
||||
|
||||
$('#randomizeData').click(function(){
|
||||
$.each(doughnutData, function(i, piece){
|
||||
doughnutData[i].value = randomScalingFactor();
|
||||
doughnutData[i].color = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
||||
});
|
||||
window.myDoughnut.update();
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<head>
|
||||
<title>Line Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width:30%">
|
||||
@@ -11,13 +10,10 @@
|
||||
<canvas id="canvas" height="450" width="600"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<button id="randomizeData">Randomize Data</button>
|
||||
|
||||
|
||||
<script>
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
var randomColorFactor = function(){ return Math.round(Math.random()*255)};
|
||||
|
||||
var lineChartData = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
@@ -52,16 +48,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
$('#randomizeData').click(function(){
|
||||
lineChartData.datasets[0].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
|
||||
lineChartData.datasets[0].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
|
||||
|
||||
lineChartData.datasets[1].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
|
||||
lineChartData.datasets[1].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
|
||||
|
||||
window.myLine.update();
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
+6
-18
@@ -3,46 +3,42 @@
|
||||
<head>
|
||||
<title>Pie Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area" width="300" height="300"/>
|
||||
</div>
|
||||
<button id="randomizeData">Randomize Data</button>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
var randomColorFactor = function(){ return Math.round(Math.random()*255)};
|
||||
|
||||
var pieData = [
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
@@ -55,14 +51,6 @@
|
||||
window.myPie = new Chart(ctx).Pie(pieData);
|
||||
};
|
||||
|
||||
$('#randomizeData').click(function(){
|
||||
$.each(pieData, function(i, piece){
|
||||
pieData[i].value = randomScalingFactor();
|
||||
pieData[i].color = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
||||
});
|
||||
window.myPie.update();
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
@@ -3,47 +3,42 @@
|
||||
<head>
|
||||
<title>Polar Area Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas-holder" style="width:30%">
|
||||
<canvas id="chart-area" width="300" height="300"/>
|
||||
</div>
|
||||
<button id="randomizeData">Randomize Data</button>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
var randomColorFactor = function(){ return Math.round(Math.random()*255)};
|
||||
|
||||
var polarData = [
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
},
|
||||
{
|
||||
value: randomScalingFactor(),
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
@@ -58,14 +53,6 @@
|
||||
});
|
||||
};
|
||||
|
||||
$('#randomizeData').click(function(){
|
||||
$.each(polarData, function(i, piece){
|
||||
polarData[i].value = randomScalingFactor();
|
||||
polarData[i].color = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
||||
});
|
||||
window.myPolarArea.update();
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
+7
-18
@@ -3,20 +3,19 @@
|
||||
<head>
|
||||
<title>Radar Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
canvas{
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width:30%">
|
||||
<canvas id="canvas" height="450" width="450"></canvas>
|
||||
</div>
|
||||
<button id="randomizeData">Randomize Data</button>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
var randomColorFactor = function(){ return Math.round(Math.random()*255)};
|
||||
|
||||
var radarChartData = {
|
||||
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
|
||||
datasets: [
|
||||
@@ -28,7 +27,7 @@
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(220,220,220,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
data: [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
@@ -38,7 +37,7 @@
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(151,187,205,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
data: [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -49,16 +48,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
$('#randomizeData').click(function(){
|
||||
radarChartData.datasets[0].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
|
||||
radarChartData.datasets[0].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
|
||||
|
||||
radarChartData.datasets[1].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
|
||||
radarChartData.datasets[1].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
|
||||
|
||||
window.myRadar.update();
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+9
-33
@@ -38,7 +38,7 @@
|
||||
barDatasetSpacing : 1,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=datasets[i].fillColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
|
||||
};
|
||||
|
||||
@@ -48,9 +48,6 @@
|
||||
defaults : defaultConfig,
|
||||
initialize: function(data){
|
||||
|
||||
// Save data as a source for updating of values & methods
|
||||
this.data = data;
|
||||
|
||||
//Expose options as a scope variable here so we can access it in the ScaleClass
|
||||
var options = this.options;
|
||||
|
||||
@@ -86,8 +83,10 @@
|
||||
bar.restore(['fillColor', 'strokeColor']);
|
||||
});
|
||||
helpers.each(activeBars, function(activeBar){
|
||||
activeBar.fillColor = activeBar.highlightFill;
|
||||
activeBar.strokeColor = activeBar.highlightStroke;
|
||||
if (activeBar) {
|
||||
activeBar.fillColor = activeBar.highlightFill;
|
||||
activeBar.strokeColor = activeBar.highlightStroke;
|
||||
}
|
||||
});
|
||||
this.showTooltip(activeBars);
|
||||
});
|
||||
@@ -118,10 +117,10 @@
|
||||
value : dataPoint,
|
||||
label : data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
strokeColor : dataset.strokeColor,
|
||||
fillColor : dataset.fillColor,
|
||||
highlightFill : dataset.highlightFill || dataset.fillColor,
|
||||
highlightStroke : dataset.highlightStroke || dataset.strokeColor
|
||||
strokeColor : (typeof dataset.strokeColor == 'object') ? dataset.strokeColor[index] : dataset.strokeColor,
|
||||
fillColor : (typeof dataset.fillColor == 'object') ? dataset.fillColor[index] : dataset.fillColor,
|
||||
highlightFill : (dataset.highlightFill) ? (typeof dataset.highlightFill == 'object') ? dataset.highlightFill[index] : dataset.highlightFill : (typeof dataset.fillColor == 'object') ? dataset.fillColor[index] : dataset.fillColor,
|
||||
highlightStroke : (dataset.highlightStroke) ? (typeof dataset.highlightStroke == 'object') ? dataset.highlightStroke[index] : dataset.highlightStroke : (typeof dataset.strokeColor == 'object') ? dataset.strokeColor[index] : dataset.strokeColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
@@ -143,29 +142,6 @@
|
||||
this.render();
|
||||
},
|
||||
update : function(){
|
||||
//Iterate through each of the datasets, and build this into a property of the chart
|
||||
helpers.each(this.data.datasets,function(dataset,datasetIndex){
|
||||
|
||||
helpers.extend(this.datasets[datasetIndex], {
|
||||
label : dataset.label || null,
|
||||
fillColor : dataset.fillColor,
|
||||
strokeColor : dataset.strokeColor,
|
||||
});
|
||||
|
||||
helpers.each(dataset.data,function(dataPoint,index){
|
||||
helpers.extend(this.datasets[datasetIndex].bars[index], {
|
||||
value : dataPoint,
|
||||
label : this.data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
strokeColor : dataset.strokeColor,
|
||||
fillColor : dataset.fillColor,
|
||||
highlightFill : dataset.highlightFill || dataset.fillColor,
|
||||
highlightStroke : dataset.highlightStroke || dataset.strokeColor
|
||||
});
|
||||
},this);
|
||||
|
||||
},this);
|
||||
|
||||
this.scale.update();
|
||||
// Reset any highlight colours before updating.
|
||||
helpers.each(this.activeElements, function(activeElement){
|
||||
|
||||
+73
-25
@@ -40,12 +40,6 @@
|
||||
var width = this.width = computeDimension(context.canvas,'Width') || context.canvas.width;
|
||||
var height = this.height = computeDimension(context.canvas,'Height') || context.canvas.height;
|
||||
|
||||
// Firefox requires this to work correctly
|
||||
context.canvas.width = width;
|
||||
context.canvas.height = height;
|
||||
|
||||
width = this.width = context.canvas.width;
|
||||
height = this.height = context.canvas.height;
|
||||
this.aspectRatio = this.width / this.height;
|
||||
//High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
|
||||
helpers.retinaScale(this);
|
||||
@@ -150,6 +144,9 @@
|
||||
// String - Tooltip title font colour
|
||||
tooltipTitleFontColor: "#fff",
|
||||
|
||||
// String - Tooltip title template
|
||||
tooltipTitleTemplate: "<%= label%>",
|
||||
|
||||
// Number - pixel width of padding around tooltip text
|
||||
tooltipYPadding: 6,
|
||||
|
||||
@@ -169,11 +166,17 @@
|
||||
tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",
|
||||
|
||||
// String - Template string for single tooltips
|
||||
multiTooltipTemplate: "<%= value %>",
|
||||
multiTooltipTemplate: "<%= datasetLabel %>: <%= value %>",
|
||||
|
||||
// String - Colour behind the legend colour block
|
||||
multiTooltipKeyBackground: '#fff',
|
||||
|
||||
// Array - A list of colors to use as the defaults
|
||||
segmentColorDefault: ["#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00", "#CAB2D6", "#6A3D9A", "#B4B482", "#B15928" ],
|
||||
|
||||
// Array - A list of highlight colors to use as the defaults
|
||||
segmentHighlightColorDefaults: [ "#CEF6FF", "#47A0DC", "#DAFFB2", "#5BC854", "#FFC2C1", "#FF4244", "#FFE797", "#FFA728", "#F2DAFE", "#9265C2", "#DCDCAA", "#D98150" ],
|
||||
|
||||
// Function - Will fire on animation progression.
|
||||
onAnimationProgress: function(){},
|
||||
|
||||
@@ -404,10 +407,15 @@
|
||||
maxSteps = Math.floor(drawingSize/(textSize * 1.5)),
|
||||
skipFitting = (minSteps >= maxSteps);
|
||||
|
||||
var maxValue = max(valuesArray),
|
||||
minValue = min(valuesArray);
|
||||
// Filter out null values since these would min() to zero
|
||||
var values = [];
|
||||
each(valuesArray, function( v ){
|
||||
v == null || values.push( v );
|
||||
});
|
||||
var minValue = min(values),
|
||||
maxValue = max(values);
|
||||
|
||||
// We need some degree of seperation here to calculate the scales if all the values are the same
|
||||
// We need some degree of separation here to calculate the scales if all the values are the same
|
||||
// Adding/minusing 0.5 will give us a range of 1.
|
||||
if (maxValue === minValue){
|
||||
maxValue += 0.5;
|
||||
@@ -829,13 +837,13 @@
|
||||
var container = domNode.parentNode,
|
||||
padding = parseInt(getStyle(container, 'padding-left')) + parseInt(getStyle(container, 'padding-right'));
|
||||
// TODO = check cross browser stuff with this.
|
||||
return container.clientWidth - padding;
|
||||
return container ? container.clientWidth - padding : 0;
|
||||
},
|
||||
getMaximumHeight = helpers.getMaximumHeight = function(domNode){
|
||||
var container = domNode.parentNode,
|
||||
padding = parseInt(getStyle(container, 'padding-bottom')) + parseInt(getStyle(container, 'padding-top'));
|
||||
// TODO = check cross browser stuff with this.
|
||||
return container.clientHeight - padding;
|
||||
return container ? container.clientHeight - padding : 0;
|
||||
},
|
||||
getStyle = helpers.getStyle = function (el, property) {
|
||||
return el.currentStyle ?
|
||||
@@ -967,9 +975,10 @@
|
||||
return this;
|
||||
},
|
||||
generateLegend : function(){
|
||||
return template(this.options.legendTemplate,this);
|
||||
return helpers.template(this.options.legendTemplate, this);
|
||||
},
|
||||
destroy : function(){
|
||||
this.stop();
|
||||
this.clear();
|
||||
unbindEvents(this, this.events);
|
||||
var canvas = this.chart.canvas;
|
||||
@@ -1097,7 +1106,7 @@
|
||||
labels: tooltipLabels,
|
||||
legendColors: tooltipColors,
|
||||
legendColorBackground : this.options.multiTooltipKeyBackground,
|
||||
title: ChartElements[0].label,
|
||||
title: template(this.options.tooltipTitleTemplate,ChartElements[0]),
|
||||
chart: this.chart,
|
||||
ctx: this.chart.ctx,
|
||||
custom: this.options.customTooltips
|
||||
@@ -1281,9 +1290,18 @@
|
||||
y: chartY
|
||||
});
|
||||
|
||||
// Normalize all angles to 0 - 2*PI (0 - 360°)
|
||||
var pointRelativeAngle = pointRelativePosition.angle % (Math.PI * 2),
|
||||
startAngle = (Math.PI * 2 + this.startAngle) % (Math.PI * 2),
|
||||
endAngle = (Math.PI * 2 + this.endAngle) % (Math.PI * 2) || 360;
|
||||
|
||||
// Calculate wether the pointRelativeAngle is between the start and the end angle
|
||||
var betweenAngles = (endAngle < startAngle) ?
|
||||
pointRelativeAngle <= endAngle || pointRelativeAngle >= startAngle:
|
||||
pointRelativeAngle >= startAngle && pointRelativeAngle <= endAngle;
|
||||
|
||||
//Check if within the range of the open/close angle
|
||||
var betweenAngles = (pointRelativePosition.angle >= this.startAngle && pointRelativePosition.angle <= this.endAngle),
|
||||
withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
|
||||
var withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
|
||||
|
||||
return (betweenAngles && withinRadius);
|
||||
//Ensure within the outside of the arc centre, but inside arc outer
|
||||
@@ -1304,9 +1322,9 @@
|
||||
|
||||
ctx.beginPath();
|
||||
|
||||
ctx.arc(this.x, this.y, this.outerRadius, this.startAngle, this.endAngle);
|
||||
ctx.arc(this.x, this.y, this.outerRadius < 0 ? 0 : this.outerRadius, this.startAngle, this.endAngle);
|
||||
|
||||
ctx.arc(this.x, this.y, this.innerRadius, this.endAngle, this.startAngle, true);
|
||||
ctx.arc(this.x, this.y, this.innerRadius < 0 ? 0 : this.innerRadius, this.endAngle, this.startAngle, true);
|
||||
|
||||
ctx.closePath();
|
||||
ctx.strokeStyle = this.strokeColor;
|
||||
@@ -1464,7 +1482,8 @@
|
||||
|
||||
this.titleFont = fontString(this.titleFontSize,this.titleFontStyle,this.titleFontFamily);
|
||||
|
||||
this.height = (this.labels.length * this.fontSize) + ((this.labels.length-1) * (this.fontSize/2)) + (this.yPadding*2) + this.titleFontSize *1.5;
|
||||
this.titleHeight = this.title ? this.titleFontSize * 1.5 : 0;
|
||||
this.height = (this.labels.length * this.fontSize) + ((this.labels.length-1) * (this.fontSize/2)) + (this.yPadding*2) + this.titleHeight;
|
||||
|
||||
this.ctx.font = this.titleFont;
|
||||
|
||||
@@ -1500,9 +1519,9 @@
|
||||
|
||||
//If the index is zero, we're getting the title
|
||||
if (index === 0){
|
||||
return baseLineHeight + this.titleFontSize/2;
|
||||
return baseLineHeight + this.titleHeight / 3;
|
||||
} else{
|
||||
return baseLineHeight + ((this.fontSize*1.5*afterTitleIndex) + this.fontSize/2) + this.titleFontSize * 1.5;
|
||||
return baseLineHeight + ((this.fontSize * 1.5 * afterTitleIndex) + this.fontSize / 2) + this.titleHeight;
|
||||
}
|
||||
|
||||
},
|
||||
@@ -2036,14 +2055,40 @@
|
||||
ctx.lineWidth = this.angleLineWidth;
|
||||
ctx.strokeStyle = this.angleLineColor;
|
||||
for (var i = this.valuesCount - 1; i >= 0; i--) {
|
||||
if (this.angleLineWidth > 0){
|
||||
var outerPosition = this.getPointPosition(i, this.calculateCenterOffset(this.max));
|
||||
var centerOffset = null, outerPosition = null;
|
||||
|
||||
if (this.angleLineWidth > 0 && (i % this.angleLineInterval === 0)){
|
||||
centerOffset = this.calculateCenterOffset(this.max);
|
||||
outerPosition = this.getPointPosition(i, centerOffset);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.xCenter, this.yCenter);
|
||||
ctx.lineTo(outerPosition.x, outerPosition.y);
|
||||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
if (this.backgroundColors && this.backgroundColors.length == this.valuesCount) {
|
||||
if (centerOffset == null)
|
||||
centerOffset = this.calculateCenterOffset(this.max);
|
||||
|
||||
if (outerPosition == null)
|
||||
outerPosition = this.getPointPosition(i, centerOffset);
|
||||
|
||||
var previousOuterPosition = this.getPointPosition(i === 0 ? this.valuesCount - 1 : i - 1, centerOffset);
|
||||
var nextOuterPosition = this.getPointPosition(i === this.valuesCount - 1 ? 0 : i + 1, centerOffset);
|
||||
|
||||
var previousOuterHalfway = { x: (previousOuterPosition.x + outerPosition.x) / 2, y: (previousOuterPosition.y + outerPosition.y) / 2 };
|
||||
var nextOuterHalfway = { x: (outerPosition.x + nextOuterPosition.x) / 2, y: (outerPosition.y + nextOuterPosition.y) / 2 };
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.xCenter, this.yCenter);
|
||||
ctx.lineTo(previousOuterHalfway.x, previousOuterHalfway.y);
|
||||
ctx.lineTo(outerPosition.x, outerPosition.y);
|
||||
ctx.lineTo(nextOuterHalfway.x, nextOuterHalfway.y);
|
||||
ctx.fillStyle = this.backgroundColors[i];
|
||||
ctx.fill();
|
||||
ctx.closePath();
|
||||
}
|
||||
// Extra 3px out for some label spacing
|
||||
var pointLabelPosition = this.getPointPosition(i, this.calculateCenterOffset(this.max) + 5);
|
||||
ctx.font = fontString(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily);
|
||||
@@ -2141,8 +2186,11 @@
|
||||
|
||||
this.animations[i].animationObject.render(this.animations[i].chartInstance, this.animations[i].animationObject);
|
||||
|
||||
// Check if executed the last frame.
|
||||
if (this.animations[i].animationObject.currentStep == this.animations[i].animationObject.numSteps){
|
||||
// executed the last frame. Remove the animation.
|
||||
// Call onAnimationComplete
|
||||
this.animations[i].animationObject.onAnimationComplete.call(this.animations[i].chartInstance);
|
||||
// Remove the animation.
|
||||
this.animations.splice(i, 1);
|
||||
// Keep the index in place to offset the splice
|
||||
i--;
|
||||
@@ -2184,7 +2232,7 @@
|
||||
|
||||
|
||||
if (amd) {
|
||||
define(function(){
|
||||
define('Chart', [], function(){
|
||||
return Chart;
|
||||
});
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
|
||||
+7
-25
@@ -32,22 +32,19 @@
|
||||
animateScale : false,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=segments[i].fillColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
|
||||
};
|
||||
|
||||
Chart.Type.extend({
|
||||
//Passing in a name registers this chart in the Chart namespace
|
||||
name: "Doughnut",
|
||||
//Providing a defaults will also register the deafults in the chart namespace
|
||||
//Providing a defaults will also register the defaults in the chart namespace
|
||||
defaults : defaultConfig,
|
||||
//Initialize is fired when the chart is initialized - Data is passed in as a parameter
|
||||
//Config is automatically merged by the core of Chart.js, and is available at this.options
|
||||
initialize: function(data){
|
||||
|
||||
// Save data as a source for updating of values & methods
|
||||
this.data = data;
|
||||
|
||||
//Declare segments as a static property to prevent inheriting across the Chart type prototype
|
||||
this.segments = [];
|
||||
this.outerRadius = (helpers.min([this.chart.width,this.chart.height]) - this.options.segmentStrokeWidth/2)/2;
|
||||
@@ -94,7 +91,11 @@
|
||||
return segmentsArray;
|
||||
},
|
||||
addData : function(segment, atIndex, silent){
|
||||
var index = atIndex || this.segments.length;
|
||||
var index = atIndex !== undefined ? atIndex : this.segments.length;
|
||||
if ( typeof(segment.color) === "undefined" ) {
|
||||
segment.color = Chart.defaults.global.segmentColorDefault[index % Chart.defaults.global.segmentColorDefault.length];
|
||||
segment.highlight = Chart.defaults.global.segmentHighlightColorDefaults[index % Chart.defaults.global.segmentHighlightColorDefaults.length];
|
||||
}
|
||||
this.segments.splice(index, 0, new this.SegmentArc({
|
||||
value : segment.value,
|
||||
outerRadius : (this.options.animateScale) ? 0 : this.outerRadius,
|
||||
@@ -127,25 +128,6 @@
|
||||
},this);
|
||||
},
|
||||
update : function(){
|
||||
|
||||
// Map new data to data points
|
||||
if(this.data.length == this.segments.length){
|
||||
helpers.each(this.data, function(segment, i){
|
||||
helpers.extend(this.segments[i], {
|
||||
value : segment.value,
|
||||
fillColor : segment.color,
|
||||
highlightColor : segment.highlight || segment.color,
|
||||
showStroke : this.options.segmentShowStroke,
|
||||
strokeWidth : this.options.segmentStrokeWidth,
|
||||
strokeColor : this.options.segmentStrokeColor,
|
||||
label : segment.label
|
||||
});
|
||||
}, this);
|
||||
} else{
|
||||
// Data size changed without properly inserting, just redraw the chart
|
||||
this.initialize(this.data);
|
||||
}
|
||||
|
||||
this.calculateTotal(this.segments);
|
||||
|
||||
// Reset any highlight colours before updating.
|
||||
|
||||
+6
-31
@@ -50,7 +50,7 @@
|
||||
datasetFill : true,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>",
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=datasets[i].strokeColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>",
|
||||
|
||||
//Boolean - Whether to horizontally center the label and point dot inside the grid
|
||||
offsetGridLines : false
|
||||
@@ -62,9 +62,6 @@
|
||||
name: "Line",
|
||||
defaults : defaultConfig,
|
||||
initialize: function(data){
|
||||
// Save data as a source for updating of values & methods
|
||||
this.data = data;
|
||||
|
||||
//Declare the extension of the default point, to cater for the options passed in to the constructor
|
||||
this.PointClass = Chart.Point.extend({
|
||||
offsetGridLines : this.options.offsetGridLines,
|
||||
@@ -140,31 +137,6 @@
|
||||
this.render();
|
||||
},
|
||||
update : function(){
|
||||
//Iterate through each of the datasets, and build this into a property of the chart
|
||||
helpers.each(this.data.datasets,function(dataset,datasetIndex){
|
||||
|
||||
helpers.extend(this.datasets[datasetIndex], {
|
||||
label : dataset.label || null,
|
||||
fillColor : dataset.fillColor,
|
||||
strokeColor : dataset.strokeColor,
|
||||
pointColor : dataset.pointColor,
|
||||
pointStrokeColor : dataset.pointStrokeColor,
|
||||
});
|
||||
|
||||
helpers.each(dataset.data,function(dataPoint,index){
|
||||
helpers.extend(this.datasets[datasetIndex].points[index], {
|
||||
value : dataPoint,
|
||||
label : this.data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
strokeColor : dataset.pointStrokeColor,
|
||||
fillColor : dataset.pointColor,
|
||||
highlightFill : dataset.pointHighlightFill || dataset.pointColor,
|
||||
highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor
|
||||
});
|
||||
},this);
|
||||
|
||||
},this);
|
||||
|
||||
this.scale.update();
|
||||
// Reset any highlight colours before updating.
|
||||
helpers.each(this.activeElements, function(activeElement){
|
||||
@@ -303,6 +275,7 @@
|
||||
return helpers.findPreviousWhere(collection, hasValue, index) || point;
|
||||
};
|
||||
|
||||
if (!this.scale) return;
|
||||
this.scale.draw(easingDecimal);
|
||||
|
||||
|
||||
@@ -322,7 +295,7 @@
|
||||
},this);
|
||||
|
||||
|
||||
// Control points need to be calculated in a seperate loop, because we need to know the current x/y of the point
|
||||
// Control points need to be calculated in a separate loop, because we need to know the current x/y of the point
|
||||
// This would cause issues when there is no animation, because the y of the next point would be 0, so beziers would be skewed
|
||||
if (this.options.bezierCurve){
|
||||
helpers.each(pointsWithValues, function(point, index){
|
||||
@@ -383,7 +356,9 @@
|
||||
}
|
||||
}, this);
|
||||
|
||||
ctx.stroke();
|
||||
if (this.options.datasetStroke) {
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
if (this.options.datasetFill && pointsWithValues.length > 0){
|
||||
//Round off the line by going to the base of the chart, back to the start, then fill.
|
||||
|
||||
@@ -47,21 +47,18 @@
|
||||
animateScale : false,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=segments[i].fillColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
};
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
//Passing in a name registers this chart in the Chart namespace
|
||||
name: "PolarArea",
|
||||
//Providing a defaults will also register the deafults in the chart namespace
|
||||
//Providing a defaults will also register the defaults in the chart namespace
|
||||
defaults : defaultConfig,
|
||||
//Initialize is fired when the chart is initialized - Data is passed in as a parameter
|
||||
//Config is automatically merged by the core of Chart.js, and is available at this.options
|
||||
initialize: function(data){
|
||||
// Save data as a source for updating of values & methods
|
||||
this.data = data;
|
||||
|
||||
this.segments = [];
|
||||
//Declare segment class as a chart instance specific class, so it can share props for this instance
|
||||
this.SegmentArc = Chart.Arc.extend({
|
||||
@@ -193,22 +190,6 @@
|
||||
|
||||
},
|
||||
update : function(){
|
||||
|
||||
// Map new data to data points
|
||||
if(this.data.length == this.segments.length){
|
||||
helpers.each(this.data, function(segment, i){
|
||||
helpers.extend(this.segments[i], {
|
||||
fillColor: segment.color,
|
||||
highlightColor: segment.highlight || segment.color,
|
||||
label: segment.label,
|
||||
value: segment.value,
|
||||
});
|
||||
},this);
|
||||
} else{
|
||||
// Data size changed without properly inserting, just redraw the chart
|
||||
this.initialize(this.data);
|
||||
}
|
||||
|
||||
this.calculateTotal(this.segments);
|
||||
|
||||
helpers.each(this.segments,function(segment){
|
||||
|
||||
+9
-31
@@ -28,6 +28,9 @@
|
||||
//Number - Pixel width of the angle line
|
||||
angleLineWidth : 1,
|
||||
|
||||
//Number - Interval at which to draw angle lines ("every Nth point")
|
||||
angleLineInterval: 1,
|
||||
|
||||
//String - Point label font declaration
|
||||
pointLabelFontFamily : "'Arial'",
|
||||
|
||||
@@ -62,14 +65,11 @@
|
||||
datasetFill : true,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span class=\"<%=name.toLowerCase()%>-legend-icon\" style=\"background-color:<%=datasets[i].strokeColor%>\"></span><span class=\"<%=name.toLowerCase()%>-legend-text\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
|
||||
},
|
||||
|
||||
initialize: function(data){
|
||||
// Save data as a source for updating of values & methods
|
||||
this.data = data;
|
||||
|
||||
this.PointClass = Chart.Point.extend({
|
||||
strokeWidth : this.options.pointDotStrokeWidth,
|
||||
radius : this.options.pointDotRadius,
|
||||
@@ -177,12 +177,14 @@
|
||||
showLabels: this.options.scaleShowLabels,
|
||||
showLabelBackdrop: this.options.scaleShowLabelBackdrop,
|
||||
backdropColor: this.options.scaleBackdropColor,
|
||||
backgroundColors: this.options.scaleBackgroundColors,
|
||||
backdropPaddingY : this.options.scaleBackdropPaddingY,
|
||||
backdropPaddingX: this.options.scaleBackdropPaddingX,
|
||||
lineWidth: (this.options.scaleShowLine) ? this.options.scaleLineWidth : 0,
|
||||
lineColor: this.options.scaleLineColor,
|
||||
angleLineColor : this.options.angleLineColor,
|
||||
angleLineWidth : (this.options.angleShowLineOut) ? this.options.angleLineWidth : 0,
|
||||
angleLineInterval: (this.options.angleLineInterval) ? this.options.angleLineInterval : 1,
|
||||
// Point labels at the edge of each line
|
||||
pointLabelFontColor : this.options.pointLabelFontColor,
|
||||
pointLabelFontSize : this.options.pointLabelFontSize,
|
||||
@@ -272,31 +274,6 @@
|
||||
this.update();
|
||||
},
|
||||
update : function(){
|
||||
//Iterate through each of the datasets, and build this into a property of the chart
|
||||
helpers.each(this.data.datasets,function(dataset,datasetIndex){
|
||||
|
||||
helpers.extend(this.datasets[datasetIndex], {
|
||||
label : dataset.label || null,
|
||||
fillColor : dataset.fillColor,
|
||||
strokeColor : dataset.strokeColor,
|
||||
pointColor : dataset.pointColor,
|
||||
pointStrokeColor : dataset.pointStrokeColor,
|
||||
});
|
||||
|
||||
helpers.each(dataset.data,function(dataPoint,index){
|
||||
helpers.extend(this.datasets[datasetIndex].points[index], {
|
||||
value : dataPoint,
|
||||
label : this.data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
strokeColor : dataset.pointStrokeColor,
|
||||
fillColor : dataset.pointColor,
|
||||
highlightFill : dataset.pointHighlightFill || dataset.pointColor,
|
||||
highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor
|
||||
});
|
||||
},this);
|
||||
|
||||
},this);
|
||||
|
||||
this.eachPoints(function(point){
|
||||
point.save();
|
||||
});
|
||||
@@ -348,8 +325,9 @@
|
||||
ctx.stroke();
|
||||
|
||||
ctx.fillStyle = dataset.fillColor;
|
||||
ctx.fill();
|
||||
|
||||
if(this.options.datasetFill){
|
||||
ctx.fill();
|
||||
}
|
||||
//Now draw the points over the line
|
||||
//A little inefficient double looping, but better than the line
|
||||
//lagging behind the point positions
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário