Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated code from time scale and bar chart #6622

Merged
merged 3 commits into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 1 addition & 27 deletions src/controllers/controller.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var defaults = require('../core/core.defaults');
var elements = require('../elements/index');
var helpers = require('../helpers/index');

var deprecated = helpers._deprecated;
var valueOrDefault = helpers.valueOrDefault;

defaults._set('bar', {
Expand Down Expand Up @@ -147,20 +146,13 @@ module.exports = DatasetController.extend({

initialize: function() {
var me = this;
var meta, scaleOpts;
var meta;

DatasetController.prototype.initialize.apply(me, arguments);

meta = me.getMeta();
meta.stack = me.getDataset().stack;
meta.bar = true;

scaleOpts = me._getIndexScale().options;
deprecated('bar chart', scaleOpts.barPercentage, 'scales.[x/y]Axes.barPercentage', 'dataset.barPercentage');
deprecated('bar chart', scaleOpts.barThickness, 'scales.[x/y]Axes.barThickness', 'dataset.barThickness');
deprecated('bar chart', scaleOpts.categoryPercentage, 'scales.[x/y]Axes.categoryPercentage', 'dataset.categoryPercentage');
deprecated('bar chart', me._getValueScale().options.minBarLength, 'scales.[x/y]Axes.minBarLength', 'dataset.minBarLength');
deprecated('bar chart', scaleOpts.maxBarThickness, 'scales.[x/y]Axes.maxBarThickness', 'dataset.maxBarThickness');
},

update: function(reset) {
Expand Down Expand Up @@ -405,24 +397,6 @@ module.exports = DatasetController.extend({
}

helpers.canvas.unclipArea(chart.ctx);
},

/**
* @private
*/
_resolveDataElementOptions: function() {
var me = this;
var values = helpers.extend({}, DatasetController.prototype._resolveDataElementOptions.apply(me, arguments));
var indexOpts = me._getIndexScale().options;
var valueOpts = me._getValueScale().options;

values.barPercentage = valueOrDefault(indexOpts.barPercentage, values.barPercentage);
values.barThickness = valueOrDefault(indexOpts.barThickness, values.barThickness);
values.categoryPercentage = valueOrDefault(indexOpts.categoryPercentage, values.categoryPercentage);
values.maxBarThickness = valueOrDefault(indexOpts.maxBarThickness, values.maxBarThickness);
values.minBarLength = valueOrDefault(valueOpts.minBarLength, values.minBarLength);

return values;
}

});
46 changes: 8 additions & 38 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var defaults = require('../core/core.defaults');
var helpers = require('../helpers/index');
var Scale = require('../core/core.scale');

var deprecated = helpers._deprecated;
var resolve = helpers.options.resolve;
var valueOrDefault = helpers.valueOrDefault;

Expand Down Expand Up @@ -82,14 +81,6 @@ function arrayUnique(items) {
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
Expand Down Expand Up @@ -191,7 +182,6 @@ function toTimestamp(scale, input) {
var adapter = scale._adapter;
var options = scale.options.time;
var parser = options.parser;
var format = parser || options.format;
var value = input;

if (typeof parser === 'function') {
Expand All @@ -200,27 +190,12 @@ function toTimestamp(scale, input) {

// Only parse if its not a timestamp already
if (!helpers.isFinite(value)) {
value = typeof format === 'string'
? adapter.parse(value, format)
value = typeof parser === 'string'
? adapter.parse(value, parser)
: adapter.parse(value);
}

if (value !== null) {
return +value;
}

// Labels are in an incompatible format and no `parser` has been provided.
// The user might still use the deprecated `format` option for parsing.
if (!parser && typeof format === 'function') {
value = format(input);

// `format` could return something else than a timestamp, if so, parse it
if (!helpers.isFinite(value)) {
value = adapter.parse(value);
}
}

return value;
return value !== null ? +value : value;
}

function parse(scale, input) {
Expand Down Expand Up @@ -416,7 +391,6 @@ var defaultConfig = {
parser: false, // false == a pattern string from https://momentjs.com/docs/#/parsing/string-format/ or a custom callback that converts its argument to a moment
unit: false, // false == automatic or override with week, month, year, etc.
round: false, // none, or override with week, month, year, etc.
displayFormat: false, // DEPRECATED
isoWeekday: false, // override week start day - see https://momentjs.com/docs/#/get-set/iso-weekday/
minUnit: 'millisecond',
displayFormats: {}
Expand Down Expand Up @@ -452,11 +426,6 @@ module.exports = Scale.extend({
var time = options.time || (options.time = {});
var adapter = me._adapter = new adapters._date(options.adapters.date);

// DEPRECATIONS: output a message only one time per update
deprecated('time scale', time.format, 'time.format', 'time.parser');
deprecated('time scale', time.min, 'time.min', 'ticks.min');
deprecated('time scale', 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
// when loading the scale (adapters are loaded afterward), so let's populate
Expand All @@ -481,6 +450,7 @@ module.exports = Scale.extend({
var chart = me.chart;
var adapter = me._adapter;
var options = me.options;
var tickOpts = options.ticks;
var unit = options.time.unit || 'day';
var min = MAX_INTEGER;
var max = MIN_INTEGER;
Expand Down Expand Up @@ -530,8 +500,8 @@ module.exports = Scale.extend({
max = Math.max(max, timestamps[timestamps.length - 1]);
}

min = parse(me, getMin(options)) || min;
max = parse(me, getMax(options)) || max;
min = parse(me, tickOpts.min) || min;
max = parse(me, tickOpts.max) || 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;
Expand Down Expand Up @@ -578,8 +548,8 @@ module.exports = Scale.extend({
}

// Enforce limits with user min/max options
min = parse(me, getMin(options)) || min;
max = parse(me, getMax(options)) || max;
min = parse(me, tickOpts.min) || min;
max = parse(me, tickOpts.max) || max;

// Remove ticks outside the min/max range
for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
Expand Down
63 changes: 0 additions & 63 deletions test/specs/controller.bar.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1699,21 +1699,6 @@ describe('Chart.controllers.bar', function() {
expect(meta.data[1]._model.width).toBeCloseToPixel(10);
}
});

it('should correctly set bar width if maxBarThickness is specified via deprecated option', function() {
var chart = this.chart;
var options = chart.options.scales.xAxes[0];
var i, ilen, meta;

options.maxBarThickness = 10;
chart.update();

for (i = 0, ilen = chart.data.datasets.length; i < ilen; ++i) {
meta = chart.getDatasetMeta(i);
expect(meta.data[0]._model.width).toBeCloseToPixel(10);
expect(meta.data[1]._model.width).toBeCloseToPixel(10);
}
});
});
});
});
Expand Down Expand Up @@ -1754,52 +1739,4 @@ describe('Chart.controllers.bar', function() {
expect(data[1]._model.base - minBarLength).toEqual(data[1]._model.x);
});

it('deprecated minBarLength settings should be used on Y axis on bar chart', function() {
var minBarLength = 4;
var chart = window.acquireChart({
type: 'bar',
data: {
datasets: [{
data: [0.05, -0.05, 10, 15, 20, 25, 30, 35]
}]
},
options: {
scales: {
yAxes: [{
minBarLength: minBarLength
}]
}
}
});

var data = chart.getDatasetMeta(0).data;

expect(data[0]._model.base - minBarLength).toEqual(data[0]._model.y);
expect(data[1]._model.base + minBarLength).toEqual(data[1]._model.y);
});

it('deprecated minBarLength settings should be used on X axis on horizontalBar chart', function() {
var minBarLength = 4;
var chart = window.acquireChart({
type: 'horizontalBar',
data: {
datasets: [{
data: [0.05, -0.05, 10, 15, 20, 25, 30, 35]
}]
},
options: {
scales: {
xAxes: [{
minBarLength: minBarLength
}]
}
}
});

var data = chart.getDatasetMeta(0).data;

expect(data[0]._model.base + minBarLength).toEqual(data[0]._model.x);
expect(data[1]._model.base - minBarLength).toEqual(data[1]._model.x);
});

});
1 change: 0 additions & 1 deletion test/specs/scale.time.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('Time scale tests', function() {
unit: false,
round: false,
isoWeekday: false,
displayFormat: false,
minUnit: 'millisecond',
displayFormats: {}
}
Expand Down