var stepValue = interval[options.unit].size * stepSize;
var startFraction = startRange % stepValue;
var alignedTick = startTick;
- if (startFraction && majorUnit && !options.timeOpts.round && !options.timeOpts.isoWeekday) {
+
+ // first tick
+ if (startFraction && majorUnit && !options.timeOpts.round && !options.timeOpts.isoWeekday && helpers.isNullOrUndef(options.min)) {
alignedTick += startFraction - stepValue;
ticks.push(alignedTick);
} else {
ticks.push(startTick);
}
+
+ // generate remaining ticks
var cur = moment(alignedTick);
- var realMax = options.max || niceRange.max;
+ var realMax = helpers.isNullOrUndef(options.max) ? niceRange.max : options.max;
while (cur.add(stepSize, options.unit).valueOf() < realMax) {
ticks.push(cur.valueOf());
}
- ticks.push(cur.valueOf());
+
+ // last tick
+ if (helpers.isNullOrUndef(options.max)) {
+ ticks.push(cur.valueOf());
+ } else {
+ ticks.push(realMax);
+ }
}
return ticks;
}
});
});
- it('Should load moment.js as a dependency', function() {
+ it('should load moment.js as a dependency', function() {
expect(window.moment).not.toBe(undefined);
});
- it('Should register the constructor with the scale service', function() {
+ it('should register the constructor with the scale service', function() {
var Constructor = Chart.scaleService.getScaleConstructor('time');
expect(Constructor).not.toBe(undefined);
expect(typeof Constructor).toBe('function');
});
- it('Should have the correct default config', function() {
+ it('should have the correct default config', function() {
var defaultConfig = Chart.scaleService.getScaleDefaults('time');
expect(defaultConfig).toEqual({
display: true,
config.time.min = '2014-12-29T04:00:00';
var scale = createScale(mockData, config);
- expect(scale.ticks[0].value).toEqual('Dec 28');
+ expect(scale.ticks[0].value).toEqual('Dec 29');
});
it('should use the max option', function() {
var scale = createScale(mockData, config);
- expect(scale.ticks[scale.ticks.length - 1].value).toEqual('Jan 6');
+ expect(scale.ticks[scale.ticks.length - 1].value).toEqual('Jan 5');
});
});
- it('Should use the isoWeekday option', function() {
+ it('should use the isoWeekday option', function() {
var mockData = {
labels: [
'2015-01-01T20:00:00', // Thursday
var step = xScale.ticks[1].time - xScale.ticks[0].time;
var stepsAmount = Math.floor((xScale.max - xScale.min) / step);
- it('should be bounded by nearest step year starts', function() {
+ it('should be bounded by nearest step\'s year start and end', function() {
expect(xScale.getValueForPixel(xScale.left)).toBeCloseToTime({
value: moment(xScale.min).startOf('year'),
unit: 'hour',