Skip to content

Commit da2ef6d

Browse files
committed
Add a unit test
1 parent f63aaf1 commit da2ef6d

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/core/core.datasetControllers.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
var defaults = require('./core.defaults');
4+
var helpers = require('../helpers/index');
5+
6+
module.exports = {
7+
constructors: {},
8+
9+
defaults: {},
10+
registerControllerType: function(type, scaleConstructor, scaleDefaults) {
11+
this.constructors[type] = scaleConstructor;
12+
this.defaults[type] = helpers.clone(scaleDefaults);
13+
},
14+
15+
getControllerConstructor: function(type) {
16+
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
17+
},
18+
19+
getControllerDefaults: function(type) {
20+
// Return the scale defaults merged with the global settings so that we always use the latest ones
21+
return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
22+
},
23+
24+
updateControllerDefaults: function(type, additions) {
25+
var me = this;
26+
if (me.defaults.hasOwnProperty(type)) {
27+
me.defaults[type] = helpers.extend(me.defaults[type], additions);
28+
}
29+
},
30+
31+
addControllerToLayout: function(chart) {
32+
// Adds each scale to the chart.boxes array to be sized accordingly
33+
helpers.each(chart.scales, function(scale) {
34+
// Set ILayoutItem parameters for backwards compatibility
35+
scale.fullWidth = scale.options.fullWidth;
36+
scale.position = scale.options.position;
37+
scale.weight = scale.options.weight;
38+
layouts.addBox(chart, scale);
39+
});
40+
}
41+
};

test/specs/scale.time.tests.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ describe('Time scale tests', function() {
298298
expect(ticks).toEqual(['8PM', '9PM', '10PM', '11PM', '12AM', '1AM', '2AM', '3AM', '4AM', '5AM', '6AM', '7AM', '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM']);
299299
});
300300

301-
it('build ticks honoring the minUnit', function() {
301+
it('should build ticks honoring the minUnit', function() {
302302
var mockData = {
303303
labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00'], // days
304304
};
@@ -316,6 +316,26 @@ describe('Time scale tests', function() {
316316
expect(ticks).toEqual(['Jan 1', 'Jan 2', 'Jan 3']);
317317
});
318318

319+
it('should build ticks based on the appropriate label capacity', function() {
320+
var mockData = {
321+
labels: [
322+
'2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01',
323+
'2016-01-01', '2017-01-01',' 2018-01-01', '2019-01-01'
324+
]
325+
};
326+
327+
var config = Chart.helpers.mergeIf({
328+
time: {
329+
unit: 'year'
330+
}
331+
}, Chart.scaleService.getScaleDefaults('time'));
332+
333+
var scale = createScale(mockData, config);
334+
var ticks = getTicksLabels(scale);
335+
336+
expect(ticks).toEqual(['2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019']);
337+
});
338+
319339
it('should build ticks using the config diff', function() {
320340
var mockData = {
321341
labels: ['2015-01-01T20:00:00', '2015-02-02T21:00:00', '2015-02-21T01:00:00'], // days

0 commit comments

Comments
 (0)