Comparar commits
15 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 87c8f51578 | |||
| 5fa6003361 | |||
| 00004fdd3b | |||
| 68b493732c | |||
| e93677e0c8 | |||
| 8fca9540ab | |||
| 8c2bc34b9c | |||
| ebb8ca233d | |||
| 6ba2efe3a4 | |||
| d5fd737058 | |||
| 93a2e9fc55 | |||
| a7fede4f46 | |||
| 488826ace3 | |||
| 9ee70d6d48 | |||
| 95bd0a54dd |
+11
-11
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "Chart.js",
|
||||
"version": "2.0.0-beta2",
|
||||
"description": "Simple HTML5 Charts using the canvas element",
|
||||
"homepage": "https://github.com/nnnick/Chart.js",
|
||||
"author": "nnnick",
|
||||
"main": [
|
||||
"Chart.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"jquery": "~2.1.4"
|
||||
}
|
||||
"name": "Chart.js",
|
||||
"version": "2.0.0",
|
||||
"description": "Simple HTML5 Charts using the canvas element",
|
||||
"homepage": "https://github.com/nnnick/Chart.js",
|
||||
"author": "nnnick",
|
||||
"main": [
|
||||
"dist/Chart.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"jquery": "~2.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
externo
+86
-34
@@ -5195,7 +5195,7 @@ module.exports = {
|
||||
/*!
|
||||
* Chart.js
|
||||
* http://chartjs.org/
|
||||
* Version: 2.0.0-beta2
|
||||
* Version: 2.0.0
|
||||
*
|
||||
* Copyright 2015 Nick Downie
|
||||
* Released under the MIT license
|
||||
@@ -7268,6 +7268,12 @@ module.exports = function(Chart) {
|
||||
this.scale.draw();
|
||||
}
|
||||
|
||||
// Clip out the chart area so that anything outside does not draw. This is necessary for zoom and pan to function
|
||||
this.chart.ctx.save();
|
||||
this.chart.ctx.beginPath();
|
||||
this.chart.ctx.rect(this.chartArea.left, this.chartArea.top, this.chartArea.right - this.chartArea.left, this.chartArea.bottom - this.chartArea.top);
|
||||
this.chart.ctx.clip();
|
||||
|
||||
// Draw each dataset via its respective controller (reversed to support proper line stacking)
|
||||
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
|
||||
if (helpers.isDatasetVisible(dataset)) {
|
||||
@@ -7275,6 +7281,9 @@ module.exports = function(Chart) {
|
||||
}
|
||||
}, null, true);
|
||||
|
||||
// Restore from the clipping operation
|
||||
this.chart.ctx.restore();
|
||||
|
||||
// Finally draw the tooltip
|
||||
this.tooltip.transition(easingDecimal).draw();
|
||||
},
|
||||
@@ -7305,11 +7314,13 @@ module.exports = function(Chart) {
|
||||
var elementsArray = [];
|
||||
|
||||
var found = (function() {
|
||||
for (var i = 0; i < this.data.datasets.length; i++) {
|
||||
if (helpers.isDatasetVisible(this.data.datasets[i])) {
|
||||
for (var j = 0; j < this.data.datasets[i].metaData.length; j++) {
|
||||
if (this.data.datasets[i].metaData[j].inRange(eventPosition.x, eventPosition.y)) {
|
||||
return this.data.datasets[i].metaData[j];
|
||||
if (this.data.datasets) {
|
||||
for (var i = 0; i < this.data.datasets.length; i++) {
|
||||
if (helpers.isDatasetVisible(this.data.datasets[i])) {
|
||||
for (var j = 0; j < this.data.datasets[i].metaData.length; j++) {
|
||||
if (this.data.datasets[i].metaData[j].inRange(eventPosition.x, eventPosition.y)) {
|
||||
return this.data.datasets[i].metaData[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8408,30 +8419,47 @@ module.exports = function(Chart) {
|
||||
helpers.removeEvent(chartInstance.chart.canvas, eventName, handler);
|
||||
});
|
||||
};
|
||||
helpers.getConstraintWidth = function(domNode) { // returns Number or undefined if no constraint
|
||||
var constrainedWidth;
|
||||
var constrainedWNode = document.defaultView.getComputedStyle(domNode)['max-width'];
|
||||
var constrainedWContainer = document.defaultView.getComputedStyle(domNode.parentNode)['max-width'];
|
||||
var hasCWNode = constrainedWNode !== null && constrainedWNode !== "none";
|
||||
var hasCWContainer = constrainedWContainer !== null && constrainedWContainer !== "none";
|
||||
|
||||
if (hasCWNode || hasCWContainer) {
|
||||
constrainedWidth = Math.min((hasCWNode ? parseInt(constrainedWNode, 10) : Number.POSITIVE_INFINITY), (hasCWContainer ? parseInt(constrainedWContainer, 10) : Number.POSITIVE_INFINITY));
|
||||
// Private helper function to convert max-width/max-height values that may be percentages into a number
|
||||
function parseMaxStyle(styleValue, node, parentProperty) {
|
||||
var valueInPixels;
|
||||
if (typeof(styleValue) === 'string') {
|
||||
valueInPixels = parseInt(styleValue, 10);
|
||||
|
||||
if (styleValue.indexOf('%') != -1) {
|
||||
// percentage * size in dimension
|
||||
valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
|
||||
}
|
||||
} else {
|
||||
valueInPixels = styleValue;
|
||||
}
|
||||
return constrainedWidth;
|
||||
|
||||
return valueInPixels;
|
||||
}
|
||||
|
||||
// Private helper to get a constraint dimension
|
||||
// @param domNode : the node to check the constraint on
|
||||
// @param maxStyle : the style that defines the maximum for the direction we are using (max-width / max-height)
|
||||
// @param percentageProperty : property of parent to use when calculating width as a percentage
|
||||
function getConstraintDimension(domNode, maxStyle, percentageProperty) {
|
||||
var constrainedDimension;
|
||||
var constrainedNode = document.defaultView.getComputedStyle(domNode)[maxStyle];
|
||||
var constrainedContainer = document.defaultView.getComputedStyle(domNode.parentNode)[maxStyle];
|
||||
var hasCNode = constrainedNode !== null && constrainedNode !== "none";
|
||||
var hasCContainer = constrainedContainer !== null && constrainedContainer !== "none";
|
||||
|
||||
if (hasCNode || hasCContainer) {
|
||||
constrainedDimension = Math.min((hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : Number.POSITIVE_INFINITY), (hasCContainer ? parseMaxStyle(constrainedContainer, domNode.parentNode, percentageProperty) : Number.POSITIVE_INFINITY));
|
||||
}
|
||||
return constrainedDimension;
|
||||
}
|
||||
// returns Number or undefined if no constraint
|
||||
helpers.getConstraintWidth = function(domNode) {
|
||||
return getConstraintDimension(domNode, 'max-width', 'clientWidth');
|
||||
};
|
||||
// returns Number or undefined if no constraint
|
||||
helpers.getConstraintHeight = function(domNode) {
|
||||
var constrainedHeight;
|
||||
var constrainedHNode = document.defaultView.getComputedStyle(domNode)['max-height'];
|
||||
var constrainedHContainer = document.defaultView.getComputedStyle(domNode.parentNode)['max-height'];
|
||||
var hasCHNode = constrainedHNode !== null && constrainedHNode !== "none";
|
||||
var hasCHContainer = constrainedHContainer !== null && constrainedHContainer !== "none";
|
||||
|
||||
if (constrainedHNode || constrainedHContainer) {
|
||||
constrainedHeight = Math.min((hasCHNode ? parseInt(constrainedHNode, 10) : Number.POSITIVE_INFINITY), (hasCHContainer ? parseInt(constrainedHContainer, 10) : Number.POSITIVE_INFINITY));
|
||||
}
|
||||
return constrainedHeight;
|
||||
return getConstraintDimension(domNode, 'max-height', 'clientHeight');
|
||||
};
|
||||
helpers.getMaximumWidth = function(domNode) {
|
||||
var container = domNode.parentNode;
|
||||
@@ -8750,8 +8778,8 @@ module.exports = function(Chart) {
|
||||
return;
|
||||
}
|
||||
|
||||
var xPadding = width > 30 ? 5 : 2;
|
||||
var yPadding = height > 30 ? 5 : 2;
|
||||
var xPadding = 0;
|
||||
var yPadding = 0;
|
||||
|
||||
var leftBoxes = helpers.where(chartInstance.boxes, function(box) {
|
||||
return box.options.position === "left";
|
||||
@@ -9039,6 +9067,7 @@ module.exports = function(Chart) {
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
},{}],28:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
@@ -9077,7 +9106,7 @@ module.exports = function(Chart) {
|
||||
// lineJoin :
|
||||
// lineWidth :
|
||||
generateLabels: function(data) {
|
||||
return data.datasets.map(function(dataset, i) {
|
||||
return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
|
||||
return {
|
||||
text: dataset.label,
|
||||
fillStyle: dataset.backgroundColor,
|
||||
@@ -9092,7 +9121,7 @@ module.exports = function(Chart) {
|
||||
// Below is extra data used for toggling the datasets
|
||||
datasetIndex: i
|
||||
};
|
||||
}, this);
|
||||
}, this) : [];
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -11423,7 +11452,24 @@ module.exports = function(Chart) {
|
||||
|
||||
var DatasetScale = Chart.Scale.extend({
|
||||
buildTicks: function(index) {
|
||||
this.ticks = this.chart.data.labels;
|
||||
this.startIndex = 0;
|
||||
this.endIndex = this.chart.data.labels.length;
|
||||
var findIndex;
|
||||
|
||||
if (this.options.ticks.min !== undefined) {
|
||||
// user specified min value
|
||||
findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.min);
|
||||
this.startIndex = findIndex !== -1 ? findIndex : this.startIndex;
|
||||
}
|
||||
|
||||
if (this.options.ticks.max !== undefined) {
|
||||
// user specified max value
|
||||
findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.max);
|
||||
this.endIndex = findIndex !== -1 ? findIndex : this.endIndex;
|
||||
}
|
||||
|
||||
// If we are viewing some subset of labels, slice the original array
|
||||
this.ticks = (this.startIndex === 0 && this.endIndex === this.chart.data.labels.length) ? this.chart.data.labels : this.chart.data.labels.slice(this.startIndex, this.endIndex + 1);
|
||||
},
|
||||
|
||||
getLabelForIndex: function(index, datasetIndex) {
|
||||
@@ -11432,10 +11478,13 @@ module.exports = function(Chart) {
|
||||
|
||||
// Used to get data value locations. Value can either be an index or a numerical value
|
||||
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
|
||||
// 1 is added because we need the length but we have the indexes
|
||||
var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
|
||||
if (this.isHorizontal()) {
|
||||
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
|
||||
var valueWidth = innerWidth / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
var widthOffset = (valueWidth * index) + this.paddingLeft;
|
||||
var valueWidth = innerWidth / offsetAmt;
|
||||
var widthOffset = (valueWidth * (index - this.startIndex)) + this.paddingLeft;
|
||||
|
||||
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
||||
widthOffset += (valueWidth / 2);
|
||||
@@ -11444,8 +11493,8 @@ module.exports = function(Chart) {
|
||||
return this.left + Math.round(widthOffset);
|
||||
} else {
|
||||
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
|
||||
var valueHeight = innerHeight / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
var heightOffset = (valueHeight * index) + this.paddingTop;
|
||||
var valueHeight = innerHeight / offsetAmt;
|
||||
var heightOffset = (valueHeight * (index - this.startIndex)) + this.paddingTop;
|
||||
|
||||
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
||||
heightOffset += (valueHeight / 2);
|
||||
@@ -11453,6 +11502,9 @@ module.exports = function(Chart) {
|
||||
|
||||
return this.top + Math.round(heightOffset);
|
||||
}
|
||||
},
|
||||
getPixelForTick: function(index, includeOffset) {
|
||||
return this.getPixelForValue(this.ticks[index], index + this.startIndex, null, includeOffset);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
externo
+7
-7
Diff do arquivo suprimido porque uma ou mais linhas são muito longas
externo
+86
-34
@@ -1590,7 +1590,7 @@ module.exports = {
|
||||
/*!
|
||||
* Chart.js
|
||||
* http://chartjs.org/
|
||||
* Version: 2.0.0-beta2
|
||||
* Version: 2.0.0
|
||||
*
|
||||
* Copyright 2015 Nick Downie
|
||||
* Released under the MIT license
|
||||
@@ -3663,6 +3663,12 @@ module.exports = function(Chart) {
|
||||
this.scale.draw();
|
||||
}
|
||||
|
||||
// Clip out the chart area so that anything outside does not draw. This is necessary for zoom and pan to function
|
||||
this.chart.ctx.save();
|
||||
this.chart.ctx.beginPath();
|
||||
this.chart.ctx.rect(this.chartArea.left, this.chartArea.top, this.chartArea.right - this.chartArea.left, this.chartArea.bottom - this.chartArea.top);
|
||||
this.chart.ctx.clip();
|
||||
|
||||
// Draw each dataset via its respective controller (reversed to support proper line stacking)
|
||||
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
|
||||
if (helpers.isDatasetVisible(dataset)) {
|
||||
@@ -3670,6 +3676,9 @@ module.exports = function(Chart) {
|
||||
}
|
||||
}, null, true);
|
||||
|
||||
// Restore from the clipping operation
|
||||
this.chart.ctx.restore();
|
||||
|
||||
// Finally draw the tooltip
|
||||
this.tooltip.transition(easingDecimal).draw();
|
||||
},
|
||||
@@ -3700,11 +3709,13 @@ module.exports = function(Chart) {
|
||||
var elementsArray = [];
|
||||
|
||||
var found = (function() {
|
||||
for (var i = 0; i < this.data.datasets.length; i++) {
|
||||
if (helpers.isDatasetVisible(this.data.datasets[i])) {
|
||||
for (var j = 0; j < this.data.datasets[i].metaData.length; j++) {
|
||||
if (this.data.datasets[i].metaData[j].inRange(eventPosition.x, eventPosition.y)) {
|
||||
return this.data.datasets[i].metaData[j];
|
||||
if (this.data.datasets) {
|
||||
for (var i = 0; i < this.data.datasets.length; i++) {
|
||||
if (helpers.isDatasetVisible(this.data.datasets[i])) {
|
||||
for (var j = 0; j < this.data.datasets[i].metaData.length; j++) {
|
||||
if (this.data.datasets[i].metaData[j].inRange(eventPosition.x, eventPosition.y)) {
|
||||
return this.data.datasets[i].metaData[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4803,30 +4814,47 @@ module.exports = function(Chart) {
|
||||
helpers.removeEvent(chartInstance.chart.canvas, eventName, handler);
|
||||
});
|
||||
};
|
||||
helpers.getConstraintWidth = function(domNode) { // returns Number or undefined if no constraint
|
||||
var constrainedWidth;
|
||||
var constrainedWNode = document.defaultView.getComputedStyle(domNode)['max-width'];
|
||||
var constrainedWContainer = document.defaultView.getComputedStyle(domNode.parentNode)['max-width'];
|
||||
var hasCWNode = constrainedWNode !== null && constrainedWNode !== "none";
|
||||
var hasCWContainer = constrainedWContainer !== null && constrainedWContainer !== "none";
|
||||
|
||||
if (hasCWNode || hasCWContainer) {
|
||||
constrainedWidth = Math.min((hasCWNode ? parseInt(constrainedWNode, 10) : Number.POSITIVE_INFINITY), (hasCWContainer ? parseInt(constrainedWContainer, 10) : Number.POSITIVE_INFINITY));
|
||||
// Private helper function to convert max-width/max-height values that may be percentages into a number
|
||||
function parseMaxStyle(styleValue, node, parentProperty) {
|
||||
var valueInPixels;
|
||||
if (typeof(styleValue) === 'string') {
|
||||
valueInPixels = parseInt(styleValue, 10);
|
||||
|
||||
if (styleValue.indexOf('%') != -1) {
|
||||
// percentage * size in dimension
|
||||
valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
|
||||
}
|
||||
} else {
|
||||
valueInPixels = styleValue;
|
||||
}
|
||||
return constrainedWidth;
|
||||
|
||||
return valueInPixels;
|
||||
}
|
||||
|
||||
// Private helper to get a constraint dimension
|
||||
// @param domNode : the node to check the constraint on
|
||||
// @param maxStyle : the style that defines the maximum for the direction we are using (max-width / max-height)
|
||||
// @param percentageProperty : property of parent to use when calculating width as a percentage
|
||||
function getConstraintDimension(domNode, maxStyle, percentageProperty) {
|
||||
var constrainedDimension;
|
||||
var constrainedNode = document.defaultView.getComputedStyle(domNode)[maxStyle];
|
||||
var constrainedContainer = document.defaultView.getComputedStyle(domNode.parentNode)[maxStyle];
|
||||
var hasCNode = constrainedNode !== null && constrainedNode !== "none";
|
||||
var hasCContainer = constrainedContainer !== null && constrainedContainer !== "none";
|
||||
|
||||
if (hasCNode || hasCContainer) {
|
||||
constrainedDimension = Math.min((hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : Number.POSITIVE_INFINITY), (hasCContainer ? parseMaxStyle(constrainedContainer, domNode.parentNode, percentageProperty) : Number.POSITIVE_INFINITY));
|
||||
}
|
||||
return constrainedDimension;
|
||||
}
|
||||
// returns Number or undefined if no constraint
|
||||
helpers.getConstraintWidth = function(domNode) {
|
||||
return getConstraintDimension(domNode, 'max-width', 'clientWidth');
|
||||
};
|
||||
// returns Number or undefined if no constraint
|
||||
helpers.getConstraintHeight = function(domNode) {
|
||||
var constrainedHeight;
|
||||
var constrainedHNode = document.defaultView.getComputedStyle(domNode)['max-height'];
|
||||
var constrainedHContainer = document.defaultView.getComputedStyle(domNode.parentNode)['max-height'];
|
||||
var hasCHNode = constrainedHNode !== null && constrainedHNode !== "none";
|
||||
var hasCHContainer = constrainedHContainer !== null && constrainedHContainer !== "none";
|
||||
|
||||
if (constrainedHNode || constrainedHContainer) {
|
||||
constrainedHeight = Math.min((hasCHNode ? parseInt(constrainedHNode, 10) : Number.POSITIVE_INFINITY), (hasCHContainer ? parseInt(constrainedHContainer, 10) : Number.POSITIVE_INFINITY));
|
||||
}
|
||||
return constrainedHeight;
|
||||
return getConstraintDimension(domNode, 'max-height', 'clientHeight');
|
||||
};
|
||||
helpers.getMaximumWidth = function(domNode) {
|
||||
var container = domNode.parentNode;
|
||||
@@ -5145,8 +5173,8 @@ module.exports = function(Chart) {
|
||||
return;
|
||||
}
|
||||
|
||||
var xPadding = width > 30 ? 5 : 2;
|
||||
var yPadding = height > 30 ? 5 : 2;
|
||||
var xPadding = 0;
|
||||
var yPadding = 0;
|
||||
|
||||
var leftBoxes = helpers.where(chartInstance.boxes, function(box) {
|
||||
return box.options.position === "left";
|
||||
@@ -5434,6 +5462,7 @@ module.exports = function(Chart) {
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
},{}],28:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
@@ -5472,7 +5501,7 @@ module.exports = function(Chart) {
|
||||
// lineJoin :
|
||||
// lineWidth :
|
||||
generateLabels: function(data) {
|
||||
return data.datasets.map(function(dataset, i) {
|
||||
return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
|
||||
return {
|
||||
text: dataset.label,
|
||||
fillStyle: dataset.backgroundColor,
|
||||
@@ -5487,7 +5516,7 @@ module.exports = function(Chart) {
|
||||
// Below is extra data used for toggling the datasets
|
||||
datasetIndex: i
|
||||
};
|
||||
}, this);
|
||||
}, this) : [];
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -7818,7 +7847,24 @@ module.exports = function(Chart) {
|
||||
|
||||
var DatasetScale = Chart.Scale.extend({
|
||||
buildTicks: function(index) {
|
||||
this.ticks = this.chart.data.labels;
|
||||
this.startIndex = 0;
|
||||
this.endIndex = this.chart.data.labels.length;
|
||||
var findIndex;
|
||||
|
||||
if (this.options.ticks.min !== undefined) {
|
||||
// user specified min value
|
||||
findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.min);
|
||||
this.startIndex = findIndex !== -1 ? findIndex : this.startIndex;
|
||||
}
|
||||
|
||||
if (this.options.ticks.max !== undefined) {
|
||||
// user specified max value
|
||||
findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.max);
|
||||
this.endIndex = findIndex !== -1 ? findIndex : this.endIndex;
|
||||
}
|
||||
|
||||
// If we are viewing some subset of labels, slice the original array
|
||||
this.ticks = (this.startIndex === 0 && this.endIndex === this.chart.data.labels.length) ? this.chart.data.labels : this.chart.data.labels.slice(this.startIndex, this.endIndex + 1);
|
||||
},
|
||||
|
||||
getLabelForIndex: function(index, datasetIndex) {
|
||||
@@ -7827,10 +7873,13 @@ module.exports = function(Chart) {
|
||||
|
||||
// Used to get data value locations. Value can either be an index or a numerical value
|
||||
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
|
||||
// 1 is added because we need the length but we have the indexes
|
||||
var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
|
||||
if (this.isHorizontal()) {
|
||||
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
|
||||
var valueWidth = innerWidth / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
var widthOffset = (valueWidth * index) + this.paddingLeft;
|
||||
var valueWidth = innerWidth / offsetAmt;
|
||||
var widthOffset = (valueWidth * (index - this.startIndex)) + this.paddingLeft;
|
||||
|
||||
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
||||
widthOffset += (valueWidth / 2);
|
||||
@@ -7839,8 +7888,8 @@ module.exports = function(Chart) {
|
||||
return this.left + Math.round(widthOffset);
|
||||
} else {
|
||||
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
|
||||
var valueHeight = innerHeight / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
var heightOffset = (valueHeight * index) + this.paddingTop;
|
||||
var valueHeight = innerHeight / offsetAmt;
|
||||
var heightOffset = (valueHeight * (index - this.startIndex)) + this.paddingTop;
|
||||
|
||||
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
||||
heightOffset += (valueHeight / 2);
|
||||
@@ -7848,6 +7897,9 @@ module.exports = function(Chart) {
|
||||
|
||||
return this.top + Math.round(heightOffset);
|
||||
}
|
||||
},
|
||||
getPixelForTick: function(index, includeOffset) {
|
||||
return this.getPixelForValue(this.ticks[index], index + this.startIndex, null, includeOffset);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
externo
+5
-5
Diff do arquivo suprimido porque uma ou mais linhas são muito longas
+3
-1
@@ -60,7 +60,7 @@ afterUpdate | Function | undefined | Callback that runs at the end of the update
|
||||
*ticks*.display | Boolean | true | If true, show the ticks.
|
||||
*ticks*.suggestedMin | Number | - | User defined minimum number for the scale, overrides minimum value *except for if* it is higher than the minimum value.
|
||||
*ticks*.suggestedMax | Number | - | User defined maximum number for the scale, overrides maximum value *except for if* it is lower than the maximum value.
|
||||
*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value
|
||||
*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value.
|
||||
*ticks*.max | Number | - | User defined minimum number for the scale, overrides maximum value
|
||||
*ticks*.autoSkip | Boolean | true | If true, automatically calculates how many labels that can be shown and hides labels accordingly. Turn it off to show all labels no matter what
|
||||
*ticks*.callback | Function | `function(value) { return '' + value; } ` | Returns the string representation of the tick value as it should be displayed on the chart.
|
||||
@@ -93,6 +93,8 @@ The category scale extends the core scale class with the following tick template
|
||||
}
|
||||
```
|
||||
|
||||
The `ticks.min` and `ticks.max` attributes may be used with the category scale. Unlike other scales, the value of these attributes must simply be something that can be found in the `labels` array of the data object.
|
||||
|
||||
### Linear Scale
|
||||
The linear scale can be used to display numerical data. It can be placed on either the x or y axis. The scatter chart type automatically configures a line chart to use one of these scales for the x axis.
|
||||
|
||||
|
||||
+13
-7
@@ -48,16 +48,16 @@ var data = {
|
||||
borderColor: "rgba(220,220,220,1)",
|
||||
|
||||
// String - cap style of the line. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap
|
||||
borderCapStyle: 'butt',
|
||||
borderCapStyle: 'butt',
|
||||
|
||||
// Array - Length and spacing of dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
||||
borderDash: [],
|
||||
// Array - Length and spacing of dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
||||
borderDash: [],
|
||||
|
||||
// Number - Offset for line dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
||||
borderDashOffset: 0.0,
|
||||
// Number - Offset for line dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
||||
borderDashOffset: 0.0,
|
||||
|
||||
// String - line join style. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
|
||||
borderJoinStyle: 'miter',
|
||||
// String - line join style. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
|
||||
borderJoinStyle: 'miter',
|
||||
|
||||
// String or array - Point stroke color
|
||||
pointBorderColor: "rgba(220,220,220,1)",
|
||||
@@ -83,6 +83,9 @@ var data = {
|
||||
// Tension - bezier curve tension of the line. Set to 0 to draw straight Wlines connecting points
|
||||
tension: 0.1,
|
||||
|
||||
// Number - the pixel size of the point shape. Can be set to 0 to not render a circle over the point
|
||||
radius: 1,
|
||||
|
||||
// The actual data
|
||||
data: [65, 59, 80, 81, 56, 55, 40],
|
||||
|
||||
@@ -123,6 +126,9 @@ Name | Type | Default | Description
|
||||
showLines | Boolean | true | If false, the lines between points are not drawn
|
||||
stacked | Boolean | false | If true, lines stack on top of each other along the y axis.
|
||||
*hover*.mode | String | "label" | Label's hover mode. "label" is used since the x axis displays data by the index in the dataset.
|
||||
elements | - | - | -
|
||||
*elements*.point | - | - | -
|
||||
*elements.point*.radius | Number | `3` | Defines the size of the Point shape. Can be set to zero to skip rendering a point.
|
||||
scales | - | - | -
|
||||
*scales*.xAxes | Array | `[{type:"category","id":"x-axis-1"}]` | Defines all of the x axes used in the chart. See the [scale documentation](#getting-started-scales) for details on the available options.
|
||||
*Options for xAxes* | | |
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
"name": "chart.js",
|
||||
"homepage": "http://www.chartjs.org",
|
||||
"description": "Simple HTML5 charts using the canvas element.",
|
||||
"version": "2.0.0-beta2",
|
||||
"version": "2.0.0",
|
||||
"main": "src/chart.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -48,4 +48,4 @@
|
||||
"chartjs-color": "^1.0.2",
|
||||
"moment": "^2.10.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,6 +310,12 @@ module.exports = function(Chart) {
|
||||
this.scale.draw();
|
||||
}
|
||||
|
||||
// Clip out the chart area so that anything outside does not draw. This is necessary for zoom and pan to function
|
||||
this.chart.ctx.save();
|
||||
this.chart.ctx.beginPath();
|
||||
this.chart.ctx.rect(this.chartArea.left, this.chartArea.top, this.chartArea.right - this.chartArea.left, this.chartArea.bottom - this.chartArea.top);
|
||||
this.chart.ctx.clip();
|
||||
|
||||
// Draw each dataset via its respective controller (reversed to support proper line stacking)
|
||||
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
|
||||
if (helpers.isDatasetVisible(dataset)) {
|
||||
@@ -317,6 +323,9 @@ module.exports = function(Chart) {
|
||||
}
|
||||
}, null, true);
|
||||
|
||||
// Restore from the clipping operation
|
||||
this.chart.ctx.restore();
|
||||
|
||||
// Finally draw the tooltip
|
||||
this.tooltip.transition(easingDecimal).draw();
|
||||
},
|
||||
|
||||
@@ -830,13 +830,18 @@ module.exports = function(Chart) {
|
||||
ctx.font = font;
|
||||
var longest = 0;
|
||||
helpers.each(arrayOfStrings, function(string) {
|
||||
var textWidth = cache.data[string];
|
||||
if (!textWidth) {
|
||||
textWidth = cache.data[string] = ctx.measureText(string).width;
|
||||
cache.garbageCollect.push(string);
|
||||
// Undefined strings should not be measured
|
||||
if (string !== undefined && string !== null) {
|
||||
var textWidth = cache.data[string];
|
||||
if (!textWidth) {
|
||||
textWidth = cache.data[string] = ctx.measureText(string).width;
|
||||
cache.garbageCollect.push(string);
|
||||
}
|
||||
|
||||
if (textWidth > longest) {
|
||||
longest = textWidth;
|
||||
}
|
||||
}
|
||||
if (textWidth > longest)
|
||||
longest = textWidth;
|
||||
});
|
||||
|
||||
var gcLen = cache.garbageCollect.length / 2;
|
||||
|
||||
@@ -10,7 +10,24 @@ module.exports = function(Chart) {
|
||||
|
||||
var DatasetScale = Chart.Scale.extend({
|
||||
buildTicks: function(index) {
|
||||
this.ticks = this.chart.data.labels;
|
||||
this.startIndex = 0;
|
||||
this.endIndex = this.chart.data.labels.length;
|
||||
var findIndex;
|
||||
|
||||
if (this.options.ticks.min !== undefined) {
|
||||
// user specified min value
|
||||
findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.min);
|
||||
this.startIndex = findIndex !== -1 ? findIndex : this.startIndex;
|
||||
}
|
||||
|
||||
if (this.options.ticks.max !== undefined) {
|
||||
// user specified max value
|
||||
findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.max);
|
||||
this.endIndex = findIndex !== -1 ? findIndex : this.endIndex;
|
||||
}
|
||||
|
||||
// If we are viewing some subset of labels, slice the original array
|
||||
this.ticks = (this.startIndex === 0 && this.endIndex === this.chart.data.labels.length) ? this.chart.data.labels : this.chart.data.labels.slice(this.startIndex, this.endIndex + 1);
|
||||
},
|
||||
|
||||
getLabelForIndex: function(index, datasetIndex) {
|
||||
@@ -19,10 +36,13 @@ module.exports = function(Chart) {
|
||||
|
||||
// Used to get data value locations. Value can either be an index or a numerical value
|
||||
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
|
||||
// 1 is added because we need the length but we have the indexes
|
||||
var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
|
||||
if (this.isHorizontal()) {
|
||||
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
|
||||
var valueWidth = innerWidth / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
var widthOffset = (valueWidth * index) + this.paddingLeft;
|
||||
var valueWidth = innerWidth / offsetAmt;
|
||||
var widthOffset = (valueWidth * (index - this.startIndex)) + this.paddingLeft;
|
||||
|
||||
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
||||
widthOffset += (valueWidth / 2);
|
||||
@@ -31,8 +51,8 @@ module.exports = function(Chart) {
|
||||
return this.left + Math.round(widthOffset);
|
||||
} else {
|
||||
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
|
||||
var valueHeight = innerHeight / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
var heightOffset = (valueHeight * index) + this.paddingTop;
|
||||
var valueHeight = innerHeight / offsetAmt;
|
||||
var heightOffset = (valueHeight * (index - this.startIndex)) + this.paddingTop;
|
||||
|
||||
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
||||
heightOffset += (valueHeight / 2);
|
||||
@@ -40,6 +60,9 @@ module.exports = function(Chart) {
|
||||
|
||||
return this.top + Math.round(heightOffset);
|
||||
}
|
||||
},
|
||||
getPixelForTick: function(index, includeOffset) {
|
||||
return this.getPixelForValue(this.ticks[index], index + this.startIndex, null, includeOffset);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -156,6 +156,68 @@ describe('Category scale tests', function() {
|
||||
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(557);
|
||||
});
|
||||
|
||||
it ('Should get the correct pixel for a value when horizontal and zoomed', function() {
|
||||
var scaleID = 'myScale';
|
||||
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
yAxisID: scaleID,
|
||||
data: [10, 5, 0, 25, 78]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick_last']
|
||||
};
|
||||
|
||||
var mockContext = window.createMockContext();
|
||||
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
|
||||
config.gridLines.offsetGridLines = true;
|
||||
config.ticks.min = "tick2";
|
||||
config.ticks.max = "tick4";
|
||||
|
||||
var Constructor = Chart.scaleService.getScaleConstructor('category');
|
||||
var scale = new Constructor({
|
||||
ctx: mockContext,
|
||||
options: config,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: scaleID
|
||||
});
|
||||
|
||||
var minSize = scale.update(600, 100);
|
||||
|
||||
expect(scale.width).toBe(600);
|
||||
expect(scale.height).toBe(28);
|
||||
expect(scale.paddingTop).toBe(0);
|
||||
expect(scale.paddingBottom).toBe(0);
|
||||
expect(scale.paddingLeft).toBe(28);
|
||||
expect(scale.paddingRight).toBe(28);
|
||||
expect(scale.labelRotation).toBe(0);
|
||||
|
||||
expect(minSize).toEqual({
|
||||
width: 600,
|
||||
height: 28,
|
||||
});
|
||||
|
||||
scale.left = 5;
|
||||
scale.top = 5;
|
||||
scale.right = 605;
|
||||
scale.bottom = 33;
|
||||
|
||||
expect(scale.getPixelForValue(0, 1, 0, false)).toBe(33);
|
||||
expect(scale.getPixelForValue(0, 1, 0, true)).toBe(124);
|
||||
|
||||
expect(scale.getPixelForValue(0, 3, 0, false)).toBe(396);
|
||||
expect(scale.getPixelForValue(0, 3, 0, true)).toBe(486);
|
||||
|
||||
config.gridLines.offsetGridLines = false;
|
||||
|
||||
expect(scale.getPixelForValue(0, 1, 0, false)).toBe(33);
|
||||
expect(scale.getPixelForValue(0, 1, 0, true)).toBe(33);
|
||||
|
||||
expect(scale.getPixelForValue(0, 3, 0, false)).toBe(577);
|
||||
expect(scale.getPixelForValue(0, 3, 0, true)).toBe(577);
|
||||
});
|
||||
|
||||
it ('should get the correct pixel for a value when vertical', function() {
|
||||
var scaleID = 'myScale';
|
||||
|
||||
@@ -215,4 +277,67 @@ describe('Category scale tests', function() {
|
||||
expect(scale.getPixelForValue(0, 4, 0, false)).toBe(199);
|
||||
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(199);
|
||||
});
|
||||
|
||||
it ('should get the correct pixel for a value when vertical and zoomed', function() {
|
||||
var scaleID = 'myScale';
|
||||
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
yAxisID: scaleID,
|
||||
data: [10, 5, 0, 25, 78]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick_last']
|
||||
};
|
||||
|
||||
var mockContext = window.createMockContext();
|
||||
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
|
||||
config.gridLines.offsetGridLines = true;
|
||||
config.ticks.min = "tick2";
|
||||
config.ticks.max = "tick4";
|
||||
config.position = "left";
|
||||
|
||||
var Constructor = Chart.scaleService.getScaleConstructor('category');
|
||||
var scale = new Constructor({
|
||||
ctx: mockContext,
|
||||
options: config,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: scaleID
|
||||
});
|
||||
|
||||
var minSize = scale.update(100, 200);
|
||||
|
||||
expect(scale.width).toBe(70);
|
||||
expect(scale.height).toBe(200);
|
||||
expect(scale.paddingTop).toBe(6);
|
||||
expect(scale.paddingBottom).toBe(6);
|
||||
expect(scale.paddingLeft).toBe(0);
|
||||
expect(scale.paddingRight).toBe(0);
|
||||
expect(scale.labelRotation).toBe(0);
|
||||
|
||||
expect(minSize).toEqual({
|
||||
width: 70,
|
||||
height: 200,
|
||||
});
|
||||
|
||||
scale.left = 5;
|
||||
scale.top = 5;
|
||||
scale.right = 75;
|
||||
scale.bottom = 205;
|
||||
|
||||
expect(scale.getPixelForValue(0, 1, 0, false)).toBe(11);
|
||||
expect(scale.getPixelForValue(0, 1, 0, true)).toBe(42);
|
||||
|
||||
expect(scale.getPixelForValue(0, 3, 0, false)).toBe(136);
|
||||
expect(scale.getPixelForValue(0, 3, 0, true)).toBe(168);
|
||||
|
||||
config.gridLines.offsetGridLines = false;
|
||||
|
||||
expect(scale.getPixelForValue(0, 1, 0, false)).toBe(11);
|
||||
expect(scale.getPixelForValue(0, 1, 0, true)).toBe(11);
|
||||
|
||||
expect(scale.getPixelForValue(0, 3, 0, false)).toBe(199);
|
||||
expect(scale.getPixelForValue(0, 3, 0, true)).toBe(199);
|
||||
});
|
||||
});
|
||||
Referência em uma Nova Issue
Bloquear um usuário