mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 20:29:12 +02:00
time type xAxis height crah in line chart
if input only one data in dataset and xAxis type is date make offset crash. check offset value and don't devide 0 value. Add xAxis check test case.
This commit is contained in:
parent
29bc3b0b8b
commit
7d63bf085a
2
src/scales/scale.time.js
Normal file → Executable file
2
src/scales/scale.time.js
Normal file → Executable file
@ -332,7 +332,7 @@ module.exports = function(Chart) {
|
||||
if (labelMoment) {
|
||||
var offset = labelMoment.diff(me.firstTick, me.tickUnit, true);
|
||||
|
||||
var decimal = offset / me.scaleSizeInUnits;
|
||||
var decimal = offset !== 0 ? offset / me.scaleSizeInUnits : offset;
|
||||
|
||||
if (me.isHorizontal()) {
|
||||
var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
|
||||
|
43
test/scale.time.tests.js
Normal file → Executable file
43
test/scale.time.tests.js
Normal file → Executable file
@ -435,4 +435,47 @@ describe('Time scale tests', function() {
|
||||
expect(xScale.getLabelForIndex(6, 0)).toBe('2015-01-10T12:00');
|
||||
|
||||
});
|
||||
it('should get the correct pixel for only one data in the dataset', function() {
|
||||
var chart = window.acquireChart({
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: ["2016-05-27"],
|
||||
datasets: [{
|
||||
type: "line",
|
||||
data: [5]
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
display: true,
|
||||
type: "time",
|
||||
time: {
|
||||
displayFormats: {
|
||||
"day": "YYYY-MM-DD"
|
||||
}
|
||||
}
|
||||
}],
|
||||
yAxes: [{
|
||||
type: "linear",
|
||||
ticks: {
|
||||
reverse: true,
|
||||
min: 0,
|
||||
max: 10
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var xScale = chartInstance.scales.xScale0;
|
||||
|
||||
expect(xScale.getPixelForValue('', 0, 0)).toBeCloseToPixel(78);
|
||||
|
||||
expect(xScale.getValueForPixel(78)).toBeCloseToTime({
|
||||
value: moment(chartInstance.data.labels[0]),
|
||||
unit: 'day',
|
||||
threshold: 0.75
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user