mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
fixed test and added a test for a custom date parser
This commit is contained in:
parent
b69b388b31
commit
fc46e25f23
@ -42,6 +42,7 @@ describe('Time scale tests', function() {
|
|||||||
autoSkipPadding: 20
|
autoSkipPadding: 20
|
||||||
},
|
},
|
||||||
time: {
|
time: {
|
||||||
|
parser: false,
|
||||||
format: false,
|
format: false,
|
||||||
unit: false,
|
unit: false,
|
||||||
round: false,
|
round: false,
|
||||||
@ -168,6 +169,43 @@ describe('Time scale tests', function() {
|
|||||||
expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015']);
|
expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow custom time parsers', function() {
|
||||||
|
// Helper to build date objects
|
||||||
|
|
||||||
|
|
||||||
|
var scaleID = 'myScale';
|
||||||
|
var mockData = {
|
||||||
|
datasets: [{
|
||||||
|
data: [{
|
||||||
|
x: 375058800,
|
||||||
|
y: 1
|
||||||
|
}],
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
var verticalScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
|
||||||
|
verticalScaleConfig.time.unit = 'day';
|
||||||
|
verticalScaleConfig.time.round = true;
|
||||||
|
verticalScaleConfig.time.parser = function customTimeParser(label) {
|
||||||
|
console.log("got "+label+" returning "+moment.unix(label))
|
||||||
|
return moment.unix(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
var mockContext = window.createMockContext();
|
||||||
|
var Constructor = Chart.scaleService.getScaleConstructor('time');
|
||||||
|
var scale = new Constructor({
|
||||||
|
ctx: mockContext,
|
||||||
|
options: verticalScaleConfig,
|
||||||
|
chart: {
|
||||||
|
data: mockData
|
||||||
|
},
|
||||||
|
id: scaleID
|
||||||
|
});
|
||||||
|
scale.update(400, 50);
|
||||||
|
|
||||||
|
// Counts down because the lines are drawn top to bottom
|
||||||
|
expect(scale.ticks).toEqual(['Nov 20, 1981', 'Nov 20, 1981']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should build ticks using the config unit', function() {
|
it('should build ticks using the config unit', function() {
|
||||||
var scaleID = 'myScale';
|
var scaleID = 'myScale';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user