unitDefinition = time.units[unitDefinitionIndex];
this.tickUnit = unitDefinition.name;
- this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
+ this.leadingUnitBuffer = this.firstTick.diff(this.firstTick.clone().startOf(this.tickUnit), this.tickUnit, true);
+ this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true) + (this.leadingUnitBuffer > 0 ? 2 : 0);
this.displayFormat = this.options.time.displayFormats[unitDefinition.name];
}
}
if (labelMoment) {
var offset = labelMoment.diff(this.firstTick, this.tickUnit, true);
- var decimal = offset / this.scaleSizeInUnits;
+ var decimal = offset / (this.scaleSizeInUnits - (this.leadingUnitBuffer > 0 ? 1 : 0));
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 6, 2015', 'Jan 11, 2015' ]);
+ expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 11, 2015' ]);
});
it('should build ticks using date objects', function() {
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 6, 2015', 'Jan 11, 2015' ]);
+ expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 11, 2015' ]);
});
it('should build ticks when the data is xy points', function() {
}, {
x: newDateFromRef(9),
y: 5
- }], // days
+ }] // days
}]
};
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 6, 2015', 'Jan 11, 2015' ]);
+ expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 11, 2015' ]);
});
it('should allow custom time parsers', function() {
data: [{
x: 375068900,
y: 1
- }],
+ }]
}]
};
var verticalScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
});
scale.update(400, 50);
- expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015' ]);
+ expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 5, 2015' ]);
});
it('should get the correct pixel for a value', function() {
scale.top = 10;
scale.bottom = 38;
- expect(scale.getPixelForValue('', 0, 0)).toBe(81);
- expect(scale.getPixelForValue('', 6, 0)).toBe(323);
+ expect(scale.getPixelForValue('', 0, 0)).toBe(148);
+ expect(scale.getPixelForValue('', 6, 0)).toBe(299);
var verticalScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
verticalScaleConfig.position = "left";
verticalScale.right = 50;
verticalScale.bottom = 400;
- expect(verticalScale.getPixelForValue('', 0, 0)).toBe(38);
- expect(verticalScale.getPixelForValue('', 6, 0)).toBe(375);
+ expect(verticalScale.getPixelForValue('', 0, 0)).toBe(126);
+ expect(verticalScale.getPixelForValue('', 6, 0)).toBe(340);
});
it('should get the correct label for a data value', function() {