]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Bar options should not be defined on scale (#6249)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Fri, 25 Oct 2019 16:17:41 +0000 (09:17 -0700)
committerEvert Timberg <evert.timberg+github@gmail.com>
Fri, 25 Oct 2019 16:17:41 +0000 (12:17 -0400)
* Bar options should not be defined on scale

* Improve minimization

* Add tests

* Multiple datasets in test

13 files changed:
docs/axes/cartesian/README.md
docs/axes/styling.md
docs/charts/bar.md
samples/scales/time/financial.html
src/controllers/controller.bar.js
src/helpers/helpers.core.js
src/scales/scale.time.js
test/fixtures/controller.bar/bar-thickness-per-dataset-stacked.json [new file with mode: 0644]
test/fixtures/controller.bar/bar-thickness-per-dataset-stacked.png [new file with mode: 0644]
test/fixtures/controller.bar/bar-thickness-per-dataset.json [new file with mode: 0644]
test/fixtures/controller.bar/bar-thickness-per-dataset.png [new file with mode: 0644]
test/specs/controller.bar.tests.js
test/specs/scale.linear.tests.js

index 4a97dfb16b645cc02019e9e9a5a70a2ab03710a4..386fadc1114b00235acb7745cd77a70f6fb422d6 100644 (file)
@@ -15,7 +15,7 @@ All of the included cartesian axes support a number of common options.
 | ---- | ---- | ------- | -----------
 | `type` | `string` | | Type of scale being employed. Custom scales can be created and registered with a string key. This allows changing the type of an axis for a chart.
 | `position` | `string` | | Position of the axis in the chart. Possible values are: `'top'`, `'left'`, `'bottom'`, `'right'`
-| `offset` | `boolean` | `false` | If true, extra space is added to the both edges and the axis is scaled to fit into the chart area. This is set to `true` for a category scale in a bar chart by default.
+| `offset` | `boolean` | `false` | If true, extra space is added to the both edges and the axis is scaled to fit into the chart area. This is set to `true` for a bar chart by default.
 | `id` | `string` | | The ID is used to link datasets and scale axes together. [more...](#axis-id)
 | `gridLines` | `object` | | Grid line configuration. [more...](../styling.md#grid-line-configuration)
 | `scaleLabel` | `object` | | Scale title configuration. [more...](../labelling.md#scale-title-configuration)
index c5ae68df6939131dbf390f7d10e4c4a459c798de..e7ca3371412aff8f2cc0d49d90017e4d8b520d45 100644 (file)
@@ -22,7 +22,7 @@ The grid line configuration is nested under the scale configuration in the `grid
 | `zeroLineColor` | `Color` | `'rgba(0, 0, 0, 0.25)'` | Stroke color of the grid line for the first index (index 0).
 | `zeroLineBorderDash` | `number[]` | `[]` | Length and spacing of dashes of the grid line for the first index (index 0). See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash).
 | `zeroLineBorderDashOffset` | `number` | `0.0` | Offset for line dashes of the grid line for the first index (index 0). See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset).
-| `offsetGridLines` | `boolean` | `false` | If true, grid lines will be shifted to be between labels. This is set to `true` for a category scale in a bar chart by default.
+| `offsetGridLines` | `boolean` | `false` | If true, grid lines will be shifted to be between labels. This is set to `true` for a bar chart by default.
 | `z` | `number` | `0` | z-index of gridline layer. Values &lt;= 0 are drawn under datasets, &gt; 0 on top.
 
 ## Tick Configuration
index a4e54915ad46e22e022547d0f25172806ba80d2c..9bb8e4c8b4356af3fc7f701edab5d9de382e08ac 100644 (file)
@@ -134,8 +134,8 @@ The interaction with each bar can be controlled with the following properties:
 
 All these values, if `undefined`, fallback to the associated [`elements.rectangle.*`](../configuration/elements.md#rectangle-configuration) options.
 
-## Scale Configuration
-The bar chart accepts the following configuration from the associated `scale` options:
+## Dataset Configuration
+The bar chart accepts the following configuration from the associated dataset options:
 
 | Name | Type | Default | Description
 | ---- | ---- | ------- | -----------
@@ -144,6 +144,33 @@ The bar chart accepts the following configuration from the associated `scale` op
 | `barThickness` | <code>number&#124;string</code> | | Manually set width of each bar in pixels. If set to `'flex'`, it computes "optimal" sample widths that globally arrange bars side by side. If not set (default), bars are equally sized based on the smallest interval. [more...](#barthickness)
 | `maxBarThickness` | `number` | | Set this to ensure that bars are not sized thicker than this.
 | `minBarLength` | `number` | | Set this to ensure that bars have a minimum length in pixels.
+
+### Example Usage
+
+```javascript
+data: {
+    datasets: [{
+        barPercentage: 0.5,
+        barThickness: 6,
+        maxBarThickness: 8,
+        minBarLength: 2,
+        data: [10, 20, 30, 40, 50, 60, 70]
+    }]
+};
+```
+### barThickness
+If this value is a number, it is applied to the width of each bar, in pixels. When this is enforced, `barPercentage` and `categoryPercentage` are ignored.
+
+If set to `'flex'`, the base sample widths are calculated automatically based on the previous and following samples so that they take the full available widths without overlap. Then, bars are sized using `barPercentage` and `categoryPercentage`. There is no gap when the percentage options are 1. This mode generates bars with different widths when data are not evenly spaced.
+
+If not set (default), the base sample widths are calculated using the smallest interval that prevents bar overlapping, and bars are sized using `barPercentage` and `categoryPercentage`. This mode always generates bars equally sized.
+
+## Scale Configuration
+The bar chart sets unique default values for the following configuration from the associated `scale` options:
+
+| Name | Type | Default | Description
+| ---- | ---- | ------- | -----------
+| `offset` | `boolean` | `true` | If true, extra space is added to the both edges and the axis is scaled to fit into the chart area.
 | `gridLines.offsetGridLines` | `boolean` | `true` | If true, the bars for a particular data point fall between the grid lines. The grid line will move to the left by one half of the tick interval. If false, the grid line will go right down the middle of the bars. [more...](#offsetgridlines)
 
 ### Example Usage
@@ -152,10 +179,6 @@ The bar chart accepts the following configuration from the associated `scale` op
 options = {
     scales: {
         xAxes: [{
-            barPercentage: 0.5,
-            barThickness: 6,
-            maxBarThickness: 8,
-            minBarLength: 2,
             gridLines: {
                 offsetGridLines: true
             }
@@ -163,12 +186,6 @@ options = {
     }
 };
 ```
-### barThickness
-If this value is a number, it is applied to the width of each bar, in pixels. When this is enforced, `barPercentage` and `categoryPercentage` are ignored.
-
-If set to `'flex'`, the base sample widths are calculated automatically based on the previous and following samples so that they take the full available widths without overlap. Then, bars are sized using `barPercentage` and `categoryPercentage`. There is no gap when the percentage options are 1. This mode generates bars with different widths when data are not evenly spaced.
-
-If not set (default), the base sample widths are calculated using the smallest interval that prevents bar overlapping, and bars are sized using `barPercentage` and `categoryPercentage`. This mode always generates bars equally sized.
 
 ### offsetGridLines
 If true, the bars for a particular data point fall between the grid lines. The grid line will move to the left by one half of the tick interval, which is the space between the grid lines. If false, the grid line will go right down the middle of the bars. This is set to true for a category scale in a bar chart while false for other scales or chart types by default.
index c4eb040423f5ef3e6841a894aef6d48099477ee3..a402b0e959dc09fe6877d5d4b35fffe1bd022e38 100644 (file)
@@ -97,7 +97,6 @@
 
                var color = Chart.helpers.color;
                var cfg = {
-                       type: 'bar',
                        data: {
                                datasets: [{
                                        label: 'CHRT - Chart.js Corporation',
                                        xAxes: [{
                                                type: 'time',
                                                distribution: 'series',
+                                               offset: true,
                                                ticks: {
                                                        major: {
                                                                enabled: true,
                                                }
                                        }],
                                        yAxes: [{
+                                               gridLines: {
+                                                       drawBorder: false
+                                               },
                                                scaleLabel: {
                                                        display: true,
                                                        labelString: 'Closing price ($)'
index 4fa3f4290132bfbd2c5ccebd79ec22db04e676ff..e56d03ec552ec691c6b9eadba9e35d8cb9dd3ffc 100644 (file)
@@ -5,6 +5,9 @@ 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', {
        hover: {
                mode: 'label'
@@ -13,8 +16,6 @@ defaults._set('bar', {
        scales: {
                xAxes: [{
                        type: 'category',
-                       categoryPercentage: 0.8,
-                       barPercentage: 0.9,
                        offset: true,
                        gridLines: {
                                offsetGridLines: true
@@ -27,6 +28,15 @@ defaults._set('bar', {
        }
 });
 
+defaults._set('global', {
+       datasets: {
+               bar: {
+                       categoryPercentage: 0.8,
+                       barPercentage: 0.9
+               }
+       }
+});
+
 /**
  * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
  * @private
@@ -58,10 +68,13 @@ function computeFitCategoryTraits(index, ruler, options) {
        var thickness = options.barThickness;
        var count = ruler.stackCount;
        var curr = ruler.pixels[index];
+       var min = helpers.isNullOrUndef(thickness)
+               ? computeMinSampleSize(ruler.scale, ruler.pixels)
+               : -1;
        var size, ratio;
 
        if (helpers.isNullOrUndef(thickness)) {
-               size = ruler.min * options.categoryPercentage;
+               size = min * options.categoryPercentage;
                ratio = options.barPercentage;
        } else {
                // When bar thickness is enforced, category and bar percentages are ignored.
@@ -124,18 +137,30 @@ module.exports = DatasetController.extend({
                'backgroundColor',
                'borderColor',
                'borderSkipped',
-               'borderWidth'
+               'borderWidth',
+               'barPercentage',
+               'barThickness',
+               'categoryPercentage',
+               'maxBarThickness',
+               'minBarLength'
        ],
 
        initialize: function() {
                var me = this;
-               var meta;
+               var meta, scaleOpts;
 
                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) {
@@ -173,7 +198,7 @@ module.exports = DatasetController.extend({
                        rectangle._model.borderSkipped = null;
                }
 
-               me._updateElementGeometry(rectangle, index, reset);
+               me._updateElementGeometry(rectangle, index, reset, options);
 
                rectangle.pivot();
        },
@@ -181,15 +206,15 @@ module.exports = DatasetController.extend({
        /**
         * @private
         */
-       _updateElementGeometry: function(rectangle, index, reset) {
+       _updateElementGeometry: function(rectangle, index, reset, options) {
                var me = this;
                var model = rectangle._model;
                var vscale = me._getValueScale();
                var base = vscale.getBasePixel();
                var horizontal = vscale.isHorizontal();
                var ruler = me._ruler || me.getRuler();
-               var vpixels = me.calculateBarValuePixels(me.index, index);
-               var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);
+               var vpixels = me.calculateBarValuePixels(me.index, index, options);
+               var ipixels = me.calculateBarIndexPixels(me.index, index, ruler, options);
 
                model.horizontal = horizontal;
                model.base = reset ? base : vpixels.base;
@@ -266,18 +291,13 @@ module.exports = DatasetController.extend({
                var me = this;
                var scale = me._getIndexScale();
                var pixels = [];
-               var i, ilen, min;
+               var i, ilen;
 
                for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
                        pixels.push(scale.getPixelForValue(null, i, me.index));
                }
 
-               min = helpers.isNullOrUndef(scale.options.barThickness)
-                       ? computeMinSampleSize(scale, pixels)
-                       : -1;
-
                return {
-                       min: min,
                        pixels: pixels,
                        start: scale._startPixel,
                        end: scale._endPixel,
@@ -290,7 +310,7 @@ module.exports = DatasetController.extend({
         * Note: pixel values are not clamped to the scale area.
         * @private
         */
-       calculateBarValuePixels: function(datasetIndex, index) {
+       calculateBarValuePixels: function(datasetIndex, index, options) {
                var me = this;
                var chart = me.chart;
                var scale = me._getValueScale();
@@ -298,7 +318,7 @@ module.exports = DatasetController.extend({
                var datasets = chart.data.datasets;
                var metasets = scale._getMatchingVisibleMetas(me._type);
                var value = scale._parseValue(datasets[datasetIndex].data[index]);
-               var minBarLength = scale.options.minBarLength;
+               var minBarLength = options.minBarLength;
                var stacked = scale.options.stacked;
                var stack = me.getMeta().stack;
                var start = value.start === undefined ? 0 : value.max >= 0 && value.min >= 0 ? value.min : value.max;
@@ -349,9 +369,8 @@ module.exports = DatasetController.extend({
        /**
         * @private
         */
-       calculateBarIndexPixels: function(datasetIndex, index, ruler) {
+       calculateBarIndexPixels: function(datasetIndex, index, ruler, options) {
                var me = this;
-               var options = ruler.scale.options;
                var range = options.barThickness === 'flex'
                        ? computeFlexCategoryTraits(index, ruler, options)
                        : computeFitCategoryTraits(index, ruler, options);
@@ -359,7 +378,7 @@ module.exports = DatasetController.extend({
                var stackIndex = me.getStackIndex(datasetIndex, me.getMeta().stack);
                var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
                var size = Math.min(
-                       helpers.valueOrDefault(options.maxBarThickness, Infinity),
+                       valueOrDefault(options.maxBarThickness, Infinity),
                        range.chunk * range.ratio);
 
                return {
@@ -389,5 +408,24 @@ 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;
        }
+
 });
index a97b2f7e81486919c9f9f92911ffa28451894b4a..350a207509124a4aa64747c8fad72ac6b48dea8a 100644 (file)
@@ -306,6 +306,13 @@ var helpers = {
 
                ChartElement.__super__ = me.prototype;
                return ChartElement;
+       },
+
+       _deprecated: function(scope, value, previous, current) {
+               if (value !== undefined) {
+                       console.warn(scope + ': "' + previous +
+                               '" is deprecated. Please use "' + current + '" instead');
+               }
        }
 };
 
index 83bf4e496e52729a68ea49973f9cc6f5409ba3ca..49377b480a9c33ad11421da04695a694a1760fef 100644 (file)
@@ -5,6 +5,7 @@ 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;
 
@@ -61,14 +62,6 @@ var INTERVALS = {
 
 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;
 }
@@ -460,9 +453,9 @@ module.exports = Scale.extend({
                var adapter = me._adapter = new adapters._date(options.adapters.date);
 
                // DEPRECATIONS: output a message only one time per update
-               deprecated(time.format, 'time.format', 'time.parser');
-               deprecated(time.min, 'time.min', 'ticks.min');
-               deprecated(time.max, 'time.max', 'ticks.max');
+               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
diff --git a/test/fixtures/controller.bar/bar-thickness-per-dataset-stacked.json b/test/fixtures/controller.bar/bar-thickness-per-dataset-stacked.json
new file mode 100644 (file)
index 0000000..2921011
--- /dev/null
@@ -0,0 +1,55 @@
+{
+    "config": {
+        "data": {
+            "labels": ["2016", "2018", "2020", "2024", "2030"],
+            "datasets": [{
+                "type": "bar",
+                "barThickness": 16,
+                "backgroundColor": "#FF6384",
+                "data": [1, null, 3, 4, 5]
+            }, {
+                "type": "bar",
+                "barThickness": 8,
+                "backgroundColor": "#36A2EB",
+                "data": [5, 4, 3, null, 1]
+            }, {
+                "type": "bar",
+                "barThickness": 4,
+                "backgroundColor": "#FFCE56",
+                "data": [3, 5, 2, null, 4]
+            }]
+        },
+        "options": {
+            "responsive": false,
+            "legend": false,
+            "title": false,
+            "scales": {
+                "xAxes": [{
+                    "type": "time",
+                    "offset": true,
+                    "stacked": true,
+                    "display": false,
+                    "time": {
+                        "parser": "YYYY"
+                    },
+                    "ticks": {
+                        "source": "labels"
+                    }
+                }],
+                "yAxes": [{
+                    "display": false,
+                    "stacked": true,
+                    "ticks": {
+                        "beginAtZero": true
+                    }
+                }]
+            }
+        }
+    },
+    "options": {
+        "canvas": {
+            "height": 256,
+            "width": 512
+        }
+    }
+}
diff --git a/test/fixtures/controller.bar/bar-thickness-per-dataset-stacked.png b/test/fixtures/controller.bar/bar-thickness-per-dataset-stacked.png
new file mode 100644 (file)
index 0000000..5e6f153
Binary files /dev/null and b/test/fixtures/controller.bar/bar-thickness-per-dataset-stacked.png differ
diff --git a/test/fixtures/controller.bar/bar-thickness-per-dataset.json b/test/fixtures/controller.bar/bar-thickness-per-dataset.json
new file mode 100644 (file)
index 0000000..88f4ff1
--- /dev/null
@@ -0,0 +1,48 @@
+{
+    "config": {
+        "data": {
+            "labels": ["2016", "2018", "2020", "2024", "2030"],
+            "datasets": [{
+                "type": "bar",
+                "barThickness": 16,
+                "backgroundColor": "#FF6384",
+                "data": [1, null, 3, 4, 5]
+            }, {
+                "type": "bar",
+                "barThickness": 8,
+                "backgroundColor": "#36A2EB",
+                "data": [5, 4, 3, null, 1]
+            }]
+        },
+        "options": {
+            "responsive": false,
+            "legend": false,
+            "title": false,
+            "scales": {
+                "xAxes": [{
+                    "type": "time",
+                    "offset": true,
+                    "display": false,
+                    "time": {
+                        "parser": "YYYY"
+                    },
+                    "ticks": {
+                        "source": "labels"
+                    }
+                }],
+                "yAxes": [{
+                    "display": false,
+                    "ticks": {
+                        "beginAtZero": true
+                    }
+                }]
+            }
+        }
+    },
+    "options": {
+        "canvas": {
+            "height": 256,
+            "width": 512
+        }
+    }
+}
diff --git a/test/fixtures/controller.bar/bar-thickness-per-dataset.png b/test/fixtures/controller.bar/bar-thickness-per-dataset.png
new file mode 100644 (file)
index 0000000..1db187b
Binary files /dev/null and b/test/fixtures/controller.bar/bar-thickness-per-dataset.png differ
index 4b33c939c612f90ad7ac3908626d228c277d7e20..3874c3325df88295d2512b6ddfa50402935f1bc9 100644 (file)
@@ -1514,9 +1514,10 @@ 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.global.datasets.bar;
 
-                       var categoryPercentage = xScale.options.categoryPercentage;
-                       var barPercentage = xScale.options.barPercentage;
+                       var categoryPercentage = options.categoryPercentage;
+                       var barPercentage = options.barPercentage;
                        var stacked = xScale.options.stacked;
 
                        var totalBarWidth = 0;
@@ -1690,7 +1691,7 @@ describe('Chart.controllers.bar', function() {
                                                expected = barThickness;
                                        } else {
                                                var scale = chart.scales.x;
-                                               var options = chart.options.scales.xAxes[0];
+                                               var options = Chart.defaults.global.datasets.bar;
                                                var categoryPercentage = options.categoryPercentage;
                                                var barPercentage = options.barPercentage;
                                                var tickInterval = scale.getPixelForTick(1) - scale.getPixelForTick(0);
@@ -1706,6 +1707,21 @@ describe('Chart.controllers.bar', function() {
                                });
 
                                it('should correctly set bar width if maxBarThickness is specified', function() {
+                                       var chart = this.chart;
+                                       var i, ilen, meta;
+
+                                       chart.data.datasets[0].maxBarThickness = 10;
+                                       chart.data.datasets[1].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);
+                                       }
+                               });
+
+                               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;
@@ -1722,4 +1738,89 @@ describe('Chart.controllers.bar', function() {
                        });
                });
        });
+
+       it('minBarLength settings should be used on Y axis on bar chart', function() {
+               var minBarLength = 4;
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       minBarLength: minBarLength,
+                                       data: [0.05, -0.05, 10, 15, 20, 25, 30, 35]
+                               }]
+                       }
+               });
+
+               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('minBarLength settings should be used on X axis on horizontalBar chart', function() {
+               var minBarLength = 4;
+               var chart = window.acquireChart({
+                       type: 'horizontalBar',
+                       data: {
+                               datasets: [{
+                                       minBarLength: minBarLength,
+                                       data: [0.05, -0.05, 10, 15, 20, 25, 30, 35]
+                               }]
+                       }
+               });
+
+               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);
+       });
+
+       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);
+       });
+
 });
index ce59280028e0cea89029cc8ee778c136038f72a6..e99d101d785c0514bf8b248ef290dfddf05f9b99 100644 (file)
@@ -1124,54 +1124,6 @@ describe('Linear Scale', function() {
                expect(chart.scales['x-axis-0'].max).toEqual(0);
        });
 
-       it('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('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);
-       });
-
        it('Should generate max and min that are not equal when data contains values that are very close to each other', function() {
                var chart = window.acquireChart({
                        type: 'scatter',