]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
fixed test and added a test for a custom date parser
authorMatthias Winkelmann <matthi@matthi.coffee>
Wed, 2 Mar 2016 15:40:58 +0000 (16:40 +0100)
committerMatthias Winkelmann <matthi@matthi.coffee>
Wed, 2 Mar 2016 15:40:58 +0000 (16:40 +0100)
test/scale.time.tests.js

index 93b963dfbefd60ae709af50e831a53888b6775b9..2558f046e5c97aeeef7ac14cf377b1f0bfed96b4 100644 (file)
@@ -42,6 +42,7 @@ describe('Time scale tests', function() {
                                autoSkipPadding: 20
                        },
                        time: {
+                               parser: false,
                                format: false,
                                unit: 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']);
        });
 
+       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() {
                var scaleID = 'myScale';