| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
+| `min` | `number` | | User defined minimum value for the scale, overrides minimum value from data.
+| `max` | `number` | | User defined maximum value for the scale, overrides maximum value from data.
| `autoSkip` | `boolean` | `true` | If true, automatically calculates how many labels can be shown and hides labels accordingly. Labels will be rotated up to `maxRotation` before skipping any. Turn `autoSkip` off to show all labels no matter what.
| `autoSkipPadding` | `number` | `0` | Padding between the ticks on the horizontal axis when `autoSkip` is enabled.
| `labelOffset` | `number` | `0` | Distance in pixels to offset the label from the centre point of the tick (in the x direction for the x axis, and the y direction for the y axis). *Note: this can cause labels at the edges to be cropped by the edge of the canvas*
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| `beginAtZero` | `boolean` | | if true, scale will include 0 if it is not already included.
-| `min` | `number` | | User defined minimum number for the scale, overrides minimum value from data. [more...](#axis-range-settings)
-| `max` | `number` | | User defined maximum number for the scale, overrides maximum value from data. [more...](#axis-range-settings)
| `maxTicksLimit` | `number` | `11` | Maximum number of ticks and gridlines to show.
| `precision` | `number` | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
| `stepSize` | `number` | | User defined fixed step size for the scale. [more...](#step-size)
## Tick Configuration Options
-The following options are provided by the logarithmic scale. They are all located in the `ticks` sub options. These options extend the [common tick configuration](README.md#tick-configuration).
-
-| Name | Type | Default | Description
-| ---- | ---- | ------- | -----------
-| `min` | `number` | | User defined minimum number for the scale, overrides minimum value from data.
-| `max` | `number` | | User defined maximum number for the scale, overrides maximum value from data.
+The logarithmic scale options extend the [common tick configuration](README.md#tick-configuration). This scale does not define any options that are unique to it.
| `ticks.source` | `string` | `'auto'` | How ticks are generated. [more...](#ticks-source)
| `time.displayFormats` | `object` | | Sets how different time units are displayed. [more...](#display-formats)
| `time.isoWeekday` | `boolean` | `false` | If true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday.
-| `time.max` | [Time](#date-formats) | | If defined, this will override the data maximum.
-| `time.min` | [Time](#date-formats) | | If defined, this will override the data minimum.
| `time.parser` | <code>string|function</code> | | Custom parser for dates. [more...](#parser)
| `time.round` | `string` | `false` | If defined, dates will be rounded to the start of this unit. See [Time Units](#time-units) below for the allowed units.
| `time.tooltipFormat` | `string` | | The Moment.js format string to use for the tooltip.
var UNITS = Object.keys(INTERVALS);
+function deprecated(value, previous, current) {
+ if (value !== undefined) {
+ console.warn(
+ 'time scale: "' + previous + '" is deprecated. ' +
+ 'Please use "' + current + '" instead');
+ }
+}
+
function sorter(a, b) {
return a - b;
}
return out;
}
+function getMin(options) {
+ return helpers.valueOrDefault(options.time.min, options.ticks.min);
+}
+
+function getMax(options) {
+ return helpers.valueOrDefault(options.time.max, options.ticks.max);
+}
+
/**
* Returns an array of {time, pos} objects used to interpolate a specific `time` or position
* (`pos`) on the scale, by searching entries before and after the requested value. `pos` is
var first, last;
if (options.offset && ticks.length) {
- if (!options.time.min) {
+ if (!getMin(options)) {
first = interpolate(table, 'time', ticks[0], 'pos');
if (ticks.length === 1) {
start = 1 - first;
start = (interpolate(table, 'time', ticks[1], 'pos') - first) / 2;
}
}
- if (!options.time.max) {
+ if (!getMax(options)) {
last = interpolate(table, 'time', ticks[ticks.length - 1], 'pos');
if (ticks.length === 1) {
end = last;
var adapter = me._adapter = new adapters._date(options.adapters.date);
// DEPRECATIONS: output a message only one time per update
- if (time.format) {
- console.warn('options.time.format is deprecated and replaced by options.time.parser.');
- }
+ deprecated(time.format, 'time.format', 'time.parser');
+ deprecated(time.min, 'time.min', 'ticks.min');
+ deprecated(time.max, 'time.max', 'ticks.max');
// Backward compatibility: before introducing adapter, `displayFormats` was
// supposed to contain *all* unit/string pairs but this can't be resolved
var me = this;
var chart = me.chart;
var adapter = me._adapter;
- var timeOpts = me.options.time;
- var unit = timeOpts.unit || 'day';
+ var options = me.options;
+ var unit = options.time.unit || 'day';
var min = MAX_INTEGER;
var max = MIN_INTEGER;
var timestamps = [];
max = Math.max(max, timestamps[timestamps.length - 1]);
}
- min = parse(me, timeOpts.min) || min;
- max = parse(me, timeOpts.max) || max;
+ min = parse(me, getMin(options)) || min;
+ max = parse(me, getMax(options)) || max;
// In case there is no valid min/max, set limits based on unit time option
min = min === MAX_INTEGER ? +adapter.startOf(Date.now(), unit) : min;
}
// Enforce limits with user min/max options
- min = parse(me, timeOpts.min) || min;
- max = parse(me, timeOpts.max) || max;
+ min = parse(me, getMin(options)) || min;
+ max = parse(me, getMax(options)) || max;
// Remove ticks outside the min/max range
for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
config.time.unit = 'day';
});
+ it('should use the min option when less than first label for building ticks', function() {
+ config.ticks.min = '2014-12-29T04:00:00';
+
+ var scale = createScale(mockData, config);
+ expect(scale.ticks[0]).toEqual('Jan 1');
+ });
+
+ it('should use the min option when greater than first label for building ticks', function() {
+ config.ticks.min = '2015-01-02T04:00:00';
+
+ var scale = createScale(mockData, config);
+ expect(scale.ticks[0]).toEqual('Jan 2');
+ });
+
+ it('should use the max option when greater than last label for building ticks', function() {
+ config.ticks.max = '2015-01-05T06:00:00';
+
+ var scale = createScale(mockData, config);
+ expect(scale.ticks[scale.ticks.length - 1]).toEqual('Jan 3');
+ });
+
+ it('should use the max option when less than last label for building ticks', function() {
+ config.ticks.max = '2015-01-02T23:00:00';
+
+ var scale = createScale(mockData, config);
+ expect(scale.ticks[scale.ticks.length - 1]).toEqual('Jan 2');
+ });
+ });
+
+ describe('when specifying limits in a deprecated fashion', function() {
+ var mockData = {
+ labels: ['2015-01-01T20:00:00', '2015-01-02T20:00:00', '2015-01-03T20:00:00'],
+ };
+
+ var config;
+ beforeEach(function() {
+ config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
+ config.ticks.source = 'labels';
+ config.time.unit = 'day';
+ });
+
it('should use the min option when less than first label for building ticks', function() {
config.time.min = '2014-12-29T04:00:00';