Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ export default class TimeScale extends Scale {
const timestamps = tickOpts.source === 'labels' ? this.getLabelTimestamps() : this._generate();

if (options.bounds === 'ticks' && timestamps.length) {
this.min = this._userMin || timestamps[0];
this.max = this._userMax || timestamps[timestamps.length - 1];
this.min = isNullOrUndef(this._userMin) ? timestamps[0] : this._userMin;
this.max = isNullOrUndef(this._userMax) ? timestamps[timestamps.length - 1] : this._userMax;
}

const min = this.min;
Expand Down
18 changes: 18 additions & 0 deletions test/specs/scale.time.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ describe('Time scale tests', function() {
return scale.ticks.map(t => t.label);
}

['time', 'timeseries'].forEach(function(type) {
['min', 'max'].forEach(function(bound) {
['labels', 'auto'].forEach(function(source) {
it('should preserve an explicit epoch-zero ' + bound + ' for ' + type + ' with ' + source + ' ticks', function() {
var labels = bound === 'min' ? [1000, 2000] : [-2000, -1000];
var options = {type: type, bounds: 'ticks', ticks: {source: source}, time: {unit: 'second'}};
options[bound] = 0;
var chart = window.acquireChart({
type: 'line',
data: {labels: labels, datasets: [{data: [1, 2]}]},
options: {animation: false, scales: {x: options}}
});
expect(chart.scales.x[bound]).toBe(0);
});
});
});
});

beforeEach(function() {
// Need a time matcher for getValueFromPixel
jasmine.addMatchers({
Expand Down