mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-07 20:59:08 +02:00
Fixed typo in core.helpers.js.
Added ticks.fixedStepSize configuration parameter to force linear scale steps.
This commit is contained in:
parent
df218ead82
commit
9a20381af4
@ -843,7 +843,7 @@
|
|||||||
},
|
},
|
||||||
isDatasetVisible = helpers.isDatasetVisible = function(dataset) {
|
isDatasetVisible = helpers.isDatasetVisible = function(dataset) {
|
||||||
return !dataset.hidden;
|
return !dataset.hidden;
|
||||||
};
|
},
|
||||||
pushAllIfDefined = helpers.pushAllIfDefined = function(element, array) {
|
pushAllIfDefined = helpers.pushAllIfDefined = function(element, array) {
|
||||||
if (typeof element == "undefined") {
|
if (typeof element == "undefined") {
|
||||||
return;
|
return;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
(function() {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var root = this,
|
var root = this,
|
||||||
@ -8,7 +8,7 @@
|
|||||||
var defaultConfig = {
|
var defaultConfig = {
|
||||||
position: "left",
|
position: "left",
|
||||||
ticks: {
|
ticks: {
|
||||||
callback: function(tickValue, index, ticks) {
|
callback: function (tickValue, index, ticks) {
|
||||||
var delta = ticks[1] - ticks[0];
|
var delta = ticks[1] - ticks[0];
|
||||||
|
|
||||||
// If we have a number like 2.5 as the delta, figure out how many decimal places we need
|
// If we have a number like 2.5 as the delta, figure out how many decimal places we need
|
||||||
@ -36,7 +36,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var LinearScale = Chart.Scale.extend({
|
var LinearScale = Chart.Scale.extend({
|
||||||
buildTicks: function() {
|
buildTicks: function () {
|
||||||
|
|
||||||
// First Calculate the range
|
// First Calculate the range
|
||||||
this.min = null;
|
this.min = null;
|
||||||
@ -45,7 +45,7 @@
|
|||||||
if (this.options.stacked) {
|
if (this.options.stacked) {
|
||||||
var valuesPerType = {};
|
var valuesPerType = {};
|
||||||
|
|
||||||
helpers.each(this.chart.data.datasets, function(dataset) {
|
helpers.each(this.chart.data.datasets, function (dataset) {
|
||||||
if (valuesPerType[dataset.type] === undefined) {
|
if (valuesPerType[dataset.type] === undefined) {
|
||||||
valuesPerType[dataset.type] = {
|
valuesPerType[dataset.type] = {
|
||||||
positiveValues: [],
|
positiveValues: [],
|
||||||
@ -58,7 +58,7 @@
|
|||||||
var negativeValues = valuesPerType[dataset.type].negativeValues;
|
var negativeValues = valuesPerType[dataset.type].negativeValues;
|
||||||
|
|
||||||
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
|
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
|
||||||
helpers.each(dataset.data, function(rawValue, index) {
|
helpers.each(dataset.data, function (rawValue, index) {
|
||||||
|
|
||||||
var value = +this.getRightValue(rawValue);
|
var value = +this.getRightValue(rawValue);
|
||||||
if (isNaN(value)) {
|
if (isNaN(value)) {
|
||||||
@ -81,7 +81,7 @@
|
|||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
helpers.each(valuesPerType, function(valuesForType) {
|
helpers.each(valuesPerType, function (valuesForType) {
|
||||||
var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
|
var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
|
||||||
var minVal = helpers.min(values);
|
var minVal = helpers.min(values);
|
||||||
var maxVal = helpers.max(values);
|
var maxVal = helpers.max(values);
|
||||||
@ -90,9 +90,9 @@
|
|||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
helpers.each(this.chart.data.datasets, function(dataset) {
|
helpers.each(this.chart.data.datasets, function (dataset) {
|
||||||
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
|
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
|
||||||
helpers.each(dataset.data, function(rawValue, index) {
|
helpers.each(dataset.data, function (rawValue, index) {
|
||||||
var value = +this.getRightValue(rawValue);
|
var value = +this.getRightValue(rawValue);
|
||||||
if (isNaN(value)) {
|
if (isNaN(value)) {
|
||||||
return;
|
return;
|
||||||
@ -156,6 +156,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (this.options.ticks.suggestedMin) {
|
if (this.options.ticks.suggestedMin) {
|
||||||
this.min = Math.min(this.min, this.options.ticks.suggestedMin);
|
this.min = Math.min(this.min, this.options.ticks.suggestedMin);
|
||||||
}
|
}
|
||||||
@ -169,6 +170,12 @@
|
|||||||
this.max++;
|
this.max++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.options.ticks.fixedStepSize) {
|
||||||
|
for (var j = this.min; j <= this.max; ++j) {
|
||||||
|
console.log(j * this.options.ticks.fixedStepSize);
|
||||||
|
this.ticks.push(j * this.options.ticks.fixedStepSize);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
var niceRange = helpers.niceNum(this.max - this.min, false);
|
var niceRange = helpers.niceNum(this.max - this.min, false);
|
||||||
var spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
|
var spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
|
||||||
var niceMin = Math.floor(this.min / spacing) * spacing;
|
var niceMin = Math.floor(this.min / spacing) * spacing;
|
||||||
@ -180,6 +187,7 @@
|
|||||||
for (var j = 0; j <= numSpaces; ++j) {
|
for (var j = 0; j <= numSpaces; ++j) {
|
||||||
this.ticks.push(niceMin + (j * spacing));
|
this.ticks.push(niceMin + (j * spacing));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.options.position == "left" || this.options.position == "right") {
|
if (this.options.position == "left" || this.options.position == "right") {
|
||||||
// We are in a vertical orientation. The top value is the highest. So reverse the array
|
// We are in a vertical orientation. The top value is the highest. So reverse the array
|
||||||
@ -203,13 +211,11 @@
|
|||||||
|
|
||||||
this.zeroLineIndex = this.ticks.indexOf(0);
|
this.zeroLineIndex = this.ticks.indexOf(0);
|
||||||
},
|
},
|
||||||
|
getLabelForIndex: function (index, datasetIndex) {
|
||||||
getLabelForIndex: function(index, datasetIndex) {
|
|
||||||
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
|
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
|
getPixelForValue: function (value, index, datasetIndex, includeOffset) {
|
||||||
// This must be called after fit has been run so that
|
// This must be called after fit has been run so that
|
||||||
// this.left, this.top, this.right, and this.bottom have been defined
|
// this.left, this.top, this.right, and this.bottom have been defined
|
||||||
var rightValue = +this.getRightValue(value);
|
var rightValue = +this.getRightValue(value);
|
||||||
|
Loading…
Reference in New Issue
Block a user