Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time type xAxis height crah in line chart #2622 #2741

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scales/scale.time.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 43 additions & 0 deletions test/scale.time.tests.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
});