]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Move location of dataset options (#6955)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Tue, 14 Jan 2020 00:39:30 +0000 (16:39 -0800)
committerEvert Timberg <evert.timberg+github@gmail.com>
Tue, 14 Jan 2020 00:39:30 +0000 (19:39 -0500)
* Move location of dataset options
* Fix misplaced period

17 files changed:
docs/configuration/README.md
docs/developers/charts.md
docs/getting-started/v3-migration.md
src/controllers/controller.bar.js
src/controllers/controller.horizontalBar.js
src/controllers/controller.scatter.js
src/core/core.datasetController.js
test/fixtures/controller.bar/bar-thickness-multiple.json
test/fixtures/controller.bar/bar-thickness-no-overlap.json
test/fixtures/controller.bar/bar-thickness-offset.json
test/fixtures/controller.bar/bar-thickness-reverse.json
test/fixtures/controller.bar/bar-thickness-stacked.json
test/fixtures/controller.bar/stacking/logarithmic-strings.js
test/fixtures/controller.bar/stacking/logarithmic.js
test/fixtures/plugin.filler/fill-line-dataset-interpolated.js
test/specs/controller.bar.tests.js
test/specs/controller.line.tests.js

index d9152d9f4efc44b99df3885d65f89af12ec784d0..e75a42b0af427dc953db2427dedc2b51bd955d1f 100644 (file)
@@ -37,8 +37,8 @@ var chartDifferentHoverMode = new Chart(ctx, {
 Options may be configured directly on the dataset. The dataset options can be changed at 3 different levels and are evaluated with the following priority:
 
 - per dataset: dataset.*
-- per chart: options.datasets[type].*
-- or globally: Chart.defaults.datasets[type].*
+- per chart: options[type].datasets.*
+- or globally: Chart.defaults[type].datasets.*
 
 where type corresponds to the dataset type.
 
index 99c11f89407404b2c54dcf10b70cb3a2d572e658..1a2dffd55b2310f0116a7a5c003486ba77252346 100644 (file)
@@ -81,10 +81,6 @@ For example, to derive a new chart type that extends from a bubble chart, you wo
 // It looks like a bug exists when the defaults don't exist
 Chart.defaults.derivedBubble = Chart.defaults.bubble;
 
-// Sets the default dataset config for 'derivedBubble' to be the same as the bubble dataset defaults.
-// It looks like a bug exists when the dataset defaults don't exist
-Chart.defaults.datasets.derivedBubble = Chart.defaults.datasets.bubble;
-
 // I think the recommend using Chart.controllers.bubble.extend({ extensions here });
 var custom = Chart.controllers.bubble.extend({
     draw: function(ease) {
index c5e39e11d67ac78edf26e0c636d9e7dac48cd3ef..dafe825732836f91031f6fd17ccb703fe29993c2 100644 (file)
@@ -45,6 +45,7 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released
 
 ### Options
 
+* Dataset options are now configured as `options[type].datasets` rather than `options.datasets[type]`
 * `Polar area` `startAngle` option is now consistent with `Radar`, 0 is at top and value is in degrees. Default is changed from `-½π` to  `0`.
 * `scales.[x/y]Axes` arrays were removed. Scales are now configured directly to `options.scales` object with the object key being the scale Id.
 * `scales.[x/y]Axes.barPercentage` was moved to dataset option `barPercentage`
index 5792ef213caa9147cc892b021da1c77363e7c68b..43c34a0087c87c4280dad262a323a34e10b69942 100644 (file)
@@ -12,6 +12,17 @@ defaults._set('bar', {
                mode: 'index'
        },
 
+       datasets: {
+               categoryPercentage: 0.8,
+               barPercentage: 0.9,
+               animation: {
+                       numbers: {
+                               type: 'number',
+                               properties: ['x', 'y', 'base', 'width', 'height']
+                       }
+               }
+       },
+
        scales: {
                x: {
                        type: 'category',
@@ -27,19 +38,6 @@ defaults._set('bar', {
        }
 });
 
-defaults._set('datasets', {
-       bar: {
-               categoryPercentage: 0.8,
-               barPercentage: 0.9,
-               animation: {
-                       numbers: {
-                               type: 'number',
-                               properties: ['x', 'y', 'base', 'width', 'height']
-                       }
-               }
-       }
-});
-
 /**
  * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
  * @private
index 449cf666521c49cd14db10f1164d3f4bfb97f82e..3463eb72a4389c8fc4797233beceeb0d47906bdb 100644 (file)
@@ -25,6 +25,11 @@ defaults._set('horizontalBar', {
                }
        },
 
+       datasets: {
+               categoryPercentage: 0.8,
+               barPercentage: 0.9
+       },
+
        elements: {
                rectangle: {
                        borderSkipped: 'left'
@@ -37,13 +42,6 @@ defaults._set('horizontalBar', {
        }
 });
 
-defaults._set('datasets', {
-       horizontalBar: {
-               categoryPercentage: 0.8,
-               barPercentage: 0.9
-       }
-});
-
 export default BarController.extend({
        /**
         * @private
index 25e90c1a7bac912ef0bf1cfe3fc6ac133bf42e22..a2c421b99267406d4d266cf7c5520d6a94d8ee9e 100644 (file)
@@ -15,6 +15,10 @@ defaults._set('scatter', {
                }
        },
 
+       datasets: {
+               showLine: false
+       },
+
        tooltips: {
                callbacks: {
                        title: function() {
@@ -27,11 +31,5 @@ defaults._set('scatter', {
        }
 });
 
-defaults._set('datasets', {
-       scatter: {
-               showLine: false
-       }
-});
-
 // Scatter charts use line controllers
 export default LineController;
index d89e1af0b4d2f318c5399297c39061c6fc6693fa..b0a63f02f483cddc7fceee202232c469d306e591 100644 (file)
@@ -476,7 +476,7 @@ helpers.extend(DatasetController.prototype, {
        _configure: function() {
                const me = this;
                me._config = helpers.merge({}, [
-                       me.chart.options.datasets[me._type],
+                       me.chart.options[me._type].datasets,
                        me.getDataset(),
                ], {
                        merger: function(key, target, source) {
index 7e42b142c7d53973882a22974a7077a3c3d0fac2..ba9d783d0fcd33d58a40dbad393d9faddc847362 100644 (file)
@@ -18,8 +18,8 @@
             "responsive": false,
             "legend": false,
             "title": false,
-            "datasets": {
-                "bar": {
+            "bar": {
+                "datasets": {
                     "barPercentage": 1,
                     "categoryPercentage": 1
                 }
index 1570191beebe529a76d0c910a64493db4de614da..742f9a3e803ea49e63f361910d8aee260b088831 100644 (file)
@@ -18,8 +18,8 @@
             "responsive": false,
             "legend": false,
             "title": false,
-            "datasets": {
-                "bar": {
+            "bar": {
+                "datasets": {
                     "barPercentage": 1,
                     "categoryPercentage": 1
                 }
index ce3141ee6b221dce87fd48e4433ff83b8a5eeece..54a2ddf588df8500480c76b913705693fc75e5ef 100644 (file)
@@ -18,8 +18,8 @@
             "responsive": false,
             "legend": false,
             "title": false,
-            "datasets": {
-                "bar": {
+            "bar": {
+                "datasets": {
                     "barPercentage": 1,
                     "categoryPercentage": 1
                 }
index 950f18d2f6be8958d53788e8d0f453cd7ab32305..c794e217c818ee3de015933389c8bf19e46b8edd 100644 (file)
@@ -18,8 +18,8 @@
             "responsive": false,
             "legend": false,
             "title": false,
-            "datasets": {
-                "bar": {
+            "bar": {
+                "datasets": {
                     "barPercentage": 1,
                     "categoryPercentage": 1
                 }
index a9c24a4980812753af0bfdf9f48dd121a9470568..02ac19ccfc406c5c5644100f9531d6b882410c79 100644 (file)
@@ -18,8 +18,8 @@
             "responsive": false,
             "legend": false,
             "title": false,
-            "datasets": {
-                "bar": {
+            "bar": {
+                "datasets": {
                     "barPercentage": 1,
                     "categoryPercentage": 1
                 }
index e23a01c635e99da2c231a0ee4989c6c952a37d08..ec90866f5810c0051111367f4c89f0d47c676dd2 100644 (file)
@@ -14,8 +14,8 @@ module.exports = {
                options: {
                        legend: false,
                        title: false,
-                       datasets: {
-                               bar: {
+                       bar: {
+                               datasets: {
                                        barPercentage: 1,
                                }
                        },
index 34e0c6c9aa2e73a84c79340415a0200786400d8a..375179fd658e5a81bd8c2192a2fa4d15830c3f7d 100644 (file)
@@ -14,8 +14,8 @@ module.exports = {
                options: {
                        legend: false,
                        title: false,
-                       datasets: {
-                               bar: {
+                       bar: {
+                               datasets: {
                                        barPercentage: 1,
                                }
                        },
index ca216e37e5814fa7de27f81f5f46b545d7e7195f..d0b26190e65f47980ff13323439aba37d5539749 100644 (file)
@@ -41,8 +41,8 @@ module.exports = {
                        responsive: false,
                        legend: false,
                        title: false,
-                       datasets: {
-                               line: {
+                       line: {
+                               datasets: {
                                        lineTension: 0.4,
                                        borderWidth: 1,
                                        pointRadius: 1.5,
index 240d2e554bbe3adc350fb7b95415ee71ee9571d9..5bf4318dbfe5ab66e092fd17543501528fdab2fa 100644 (file)
@@ -1387,7 +1387,7 @@ describe('Chart.controllers.bar', function() {
                        var chart = window.acquireChart(this.config);
                        var meta = chart.getDatasetMeta(0);
                        var xScale = chart.scales[meta.xAxisID];
-                       var options = Chart.defaults.datasets.bar;
+                       var options = Chart.defaults.bar.datasets;
 
                        var categoryPercentage = options.categoryPercentage;
                        var barPercentage = options.barPercentage;
@@ -1535,8 +1535,8 @@ describe('Chart.controllers.bar', function() {
                                                options: {
                                                        legend: false,
                                                        title: false,
-                                                       datasets: {
-                                                               bar: {
+                                                       bar: {
+                                                               datasets: {
                                                                        barThickness: barThickness
                                                                }
                                                        },
@@ -1561,7 +1561,7 @@ describe('Chart.controllers.bar', function() {
                                                expected = barThickness;
                                        } else {
                                                var scale = chart.scales.x;
-                                               var options = Chart.defaults.datasets.bar;
+                                               var options = Chart.defaults.bar.datasets;
                                                var categoryPercentage = options.categoryPercentage;
                                                var barPercentage = options.barPercentage;
                                                var tickInterval = scale.getPixelForTick(1) - scale.getPixelForTick(0);
index 09c148049d7f36822b5d92b5f44cd5ae1f286a65..ea332008ba9bc36913278c8bb403c85dae2db29d 100644 (file)
@@ -559,18 +559,18 @@ describe('Chart.controllers.line', function() {
 
        describe('dataset global defaults', function() {
                beforeEach(function() {
-                       this._defaults = Chart.helpers.clone(Chart.defaults.datasets.line);
+                       this._defaults = Chart.helpers.clone(Chart.defaults.line.datasets);
                });
 
                afterEach(function() {
-                       Chart.defaults.datasets.line = this._defaults;
+                       Chart.defaults.line.datasets = this._defaults;
                        delete this._defaults;
                });
 
                it('should utilize the dataset global default options', function() {
-                       Chart.defaults.datasets.line = Chart.defaults.datasets.line || {};
+                       Chart.defaults.line.datasets = Chart.defaults.line.datasets || {};
 
-                       Chart.helpers.merge(Chart.defaults.datasets.line, {
+                       Chart.helpers.merge(Chart.defaults.line.datasets, {
                                spanGaps: true,
                                lineTension: 0.231,
                                backgroundColor: '#add',
@@ -611,9 +611,9 @@ describe('Chart.controllers.line', function() {
                });
 
                it('should be overriden by user-supplied values', function() {
-                       Chart.defaults.datasets.line = Chart.defaults.datasets.line || {};
+                       Chart.defaults.line.datasets = Chart.defaults.line.datasets || {};
 
-                       Chart.helpers.merge(Chart.defaults.datasets.line, {
+                       Chart.helpers.merge(Chart.defaults.line.datasets, {
                                spanGaps: true,
                                lineTension: 0.231
                        });
@@ -630,8 +630,8 @@ describe('Chart.controllers.line', function() {
                                        labels: ['label1', 'label2']
                                },
                                options: {
-                                       datasets: {
-                                               line: {
+                                       line: {
+                                               datasets: {
                                                        lineTension: 0.345,
                                                        backgroundColor: '#add'
                                                }
@@ -661,8 +661,8 @@ describe('Chart.controllers.line', function() {
                                labels: ['label1', 'label2']
                        },
                        options: {
-                               datasets: {
-                                       line: {
+                               line: {
+                                       datasets: {
                                                spanGaps: true,
                                                lineTension: 0.231,
                                                backgroundColor: '#add',