*/
distribution: 'linear',
+ /**
+ * Scale boundary strategy (bypassed by min/max time options)
+ * - `data`: make sure data are fully visible, ticks outside are removed
+ * - `ticks`: make sure ticks are fully visible, data outside are truncated
+ * @see https://github.com/chartjs/Chart.js/pull/4556
+ * @since 2.7.0
+ */
+ bounds: 'data',
+
time: {
parser: false, // false == a pattern string from http://momentjs.com/docs/#/parsing/string-format/ or a custom callback that converts its argument to a moment
format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
* @see https://github.com/chartjs/Chart.js/pull/4507
* @since 2.7.0
*/
- source: 'auto',
-
- /**
- * Ticks boundary strategy (bypassed by min/max time options)
- * - `data`: make sure data are fully visible, labels outside are removed
- * - `labels`: make sure labels are fully visible, data outside are truncated
- * @see https://github.com/chartjs/Chart.js/pull/4556
- * @since 2.7.0
- */
- bounds: 'data'
+ source: 'auto'
}
};
var max = me.max;
var options = me.options;
var timeOpts = options.time;
- var ticksOpts = options.ticks;
var formats = timeOpts.displayFormats;
var capacity = me.getLabelCapacity(min);
var unit = timeOpts.unit || determineUnit(timeOpts.minUnit, min, max, capacity);
var ticks = [];
var i, ilen, timestamp;
- switch (ticksOpts.source) {
+ switch (options.ticks.source) {
case 'data':
timestamps = me._timestamps.data;
break;
timestamps = generate(min, max, unit, majorUnit, capacity, timeOpts);
}
- if (ticksOpts.bounds === 'labels' && timestamps.length) {
+ if (options.bounds === 'ticks' && timestamps.length) {
min = timestamps[0];
max = timestamps[timestamps.length - 1];
}
labelString: '',
lineHeight: 1.2
},
+ bounds: 'data',
distribution: 'linear',
ticks: {
beginAtZero: false,
maxRotation: 50,
mirror: false,
source: 'auto',
- bounds: 'data',
padding: 0,
reverse: false,
display: true,
scale.update(1000, 200);
var ticks = getTicksLabels(scale);
- // `ticks.bounds === 'data'`: first and last ticks removed since outside the data range
+ // `bounds === 'data'`: first and last ticks removed since outside the data range
expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
});
scale.update(1000, 200);
var ticks = getTicksLabels(scale);
- // `ticks.bounds === 'data'`: first and last ticks removed since outside the data range
+ // `bounds === 'data'`: first and last ticks removed since outside the data range
expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
});
xScale.update(800, 200);
var ticks = getTicksLabels(xScale);
- // `ticks.bounds === 'data'`: first and last ticks removed since outside the data range
+ // `bounds === 'data'`: first and last ticks removed since outside the data range
expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
});
tScale.update(800, 200);
var ticks = getTicksLabels(tScale);
- // `ticks.bounds === 'data'`: first and last ticks removed since outside the data range
+ // `bounds === 'data'`: first and last ticks removed since outside the data range
expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
});
});
};
var config = Chart.helpers.mergeIf({
+ bounds: 'ticks',
time: {
minUnit: 'day'
- },
- ticks: {
- bounds: 'labels'
}
}, Chart.scaleService.getScaleDefaults('time'));
};
var config = Chart.helpers.mergeIf({
+ bounds: 'ticks',
time: {
unit: 'week',
round: 'week'
- },
- ticks: {
- bounds: 'labels'
}
}, Chart.scaleService.getScaleDefaults('time'));
};
var config = Chart.helpers.mergeIf({
+ bounds: 'ticks',
time: {
unit: 'hour',
stepSize: 2
- },
- ticks: {
- bounds: 'labels'
}
}, Chart.scaleService.getScaleDefaults('time'));
};
var config = Chart.helpers.mergeIf({
+ bounds: 'ticks',
time: {
unit: 'week',
isoWeekday: 3 // Wednesday
- },
- ticks: {
- bounds: 'labels'
}
}, Chart.scaleService.getScaleDefaults('time'));
xAxes: [{
id: 'xScale0',
type: 'time',
- position: 'bottom',
- ticks: {
- bounds: 'labels'
- }
+ bounds: 'ticks',
+ position: 'bottom'
}],
}
}
});
});
- describe('when ticks.bounds', function() {
+ describe('when bounds', function() {
describe('is "data"', function() {
it ('should preserve the data range', function() {
var chart = window.acquireChart({
xAxes: [{
id: 'x',
type: 'time',
+ bounds: 'data',
time: {
parser: 'MM/DD HH:mm',
unit: 'day'
- },
- ticks: {
- bounds: 'data'
}
}],
yAxes: [{
xAxes: [{
id: 'x',
type: 'time',
+ bounds: 'ticks',
time: {
parser: 'MM/DD HH:mm',
unit: 'day'
- },
- ticks: {
- bounds: 'labels'
}
}],
yAxes: [{
describe('when time.min and/or time.max are defined', function() {
['auto', 'data', 'labels'].forEach(function(source) {
- ['data', 'labels'].forEach(function(bounds) {
- describe('and source is "' + source + '" and bounds "' + bounds + '"', function() {
+ ['data', 'ticks'].forEach(function(bounds) {
+ describe('and ticks.source is "' + source + '" and bounds "' + bounds + '"', function() {
beforeEach(function() {
this.chart = window.acquireChart({
type: 'line',
xAxes: [{
id: 'x',
type: 'time',
+ bounds: bounds,
time: {
parser: 'MM/DD HH:mm',
unit: 'day'
},
ticks: {
- source: source,
- bounds: bounds
+ source: source
}
}],
yAxes: [{