From a142032f7257703a67e8af82d747678452ba9b2b Mon Sep 17 00:00:00 2001 From: Cizmarik Date: Thu, 30 Mar 2017 10:20:39 +0200 Subject: [PATCH 1/4] respect new scale option 'order' when ordering scales --- src/core/core.controller.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 1090aa9b80d..3e70ffc59e6 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -261,7 +261,9 @@ module.exports = function(Chart) { id: scaleOptions.id, options: scaleOptions, ctx: me.ctx, - chart: me + chart: me, + + weight = scaleOptions.order }); scales[scale.id] = scale; From b779867b1a02884206e9a8bdb73dcc707e4be877 Mon Sep 17 00:00:00 2001 From: Cizmarik Date: Fri, 31 Mar 2017 12:24:16 +0200 Subject: [PATCH 2/4] scale service - respect new weight scale option for axes ordering --- docs/axes/README.md | 1 + src/core/core.controller.js | 4 +--- src/core/core.scaleService.js | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/axes/README.md b/docs/axes/README.md index 9f53b14ab47..b7de691eae9 100644 --- a/docs/axes/README.md +++ b/docs/axes/README.md @@ -18,6 +18,7 @@ The following properties are common to all axes provided by Chart.js | ---- | ---- | ------- | ----------- | `display` | `Boolean` | `true` | If set to `false` the axis is hidden from view. Overrides *gridLines.display*, *scaleLabel.display*, and *ticks.display*. | `callbacks` | `Object` | | Callback functions to hook into the axis lifecycle. [more...](#callbacks) +| `weight` | `Number` | `0` | The weight used to sort the axis. Higher weights are further away from the chart area. ## Callbacks There are a number of config callbacks that can be used to change parameters in the scale at different points in the update process. diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 3e70ffc59e6..1090aa9b80d 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -261,9 +261,7 @@ module.exports = function(Chart) { id: scaleOptions.id, options: scaleOptions, ctx: me.ctx, - chart: me, - - weight = scaleOptions.order + chart: me }); scales[scale.id] = scale; diff --git a/src/core/core.scaleService.js b/src/core/core.scaleService.js index 9923bc922af..92e8136508b 100644 --- a/src/core/core.scaleService.js +++ b/src/core/core.scaleService.js @@ -36,6 +36,7 @@ module.exports = function(Chart) { // Set ILayoutItem parameters for backwards compatibility scale.fullWidth = scale.options.fullWidth; scale.position = scale.options.position; + scale.weight = scale.options.weight; Chart.layoutService.addBox(chart, scale); }); } From 078c227e2307038c4265a7340bcbe14df53dd884 Mon Sep 17 00:00:00 2001 From: Cizmarik Date: Mon, 3 Apr 2017 16:15:27 +0200 Subject: [PATCH 3/4] added test for scale ordering by weight --- test/specs/core.layoutService.tests.js | 121 +++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/test/specs/core.layoutService.tests.js b/test/specs/core.layoutService.tests.js index d5f5fab9125..89209b590b8 100644 --- a/test/specs/core.layoutService.tests.js +++ b/test/specs/core.layoutService.tests.js @@ -428,5 +428,126 @@ describe('Test the layout service', function() { expect(yAxis.left).toBe(legend.right); expect(xAxis.bottom).toBe(title.top); }); + + it('should correctly set weights of scales and order them', function() { + var chart = window.acquireChart({ + type: 'bar', + data: { + datasets: [ + { + data: [10, 5, 0, 25, 78, -10] + } + ], + labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6'] + }, + options: { + scales: { + xAxes: [{ + id: 'xScale0', + type: 'category', + display: true, + weight: 1 + }, { + id: 'xScale1', + type: 'category', + display: true, + weight: 2 + }, { + id: 'xScale2', + type: 'category', + display: true + }, { + id: 'xScale3', + type: 'category', + display: true, + position: 'top', + weight: 1 + }, { + id: 'xScale4', + type: 'category', + display: true, + position: 'top', + weight: 2 + }], + yAxes: [{ + id: 'yScale0', + type: 'linear', + display: true, + weight: 1 + }, { + id: 'yScale1', + type: 'linear', + display: true, + weight: 2 + }, { + id: 'yScale2', + type: 'linear', + display: true + }, { + id: 'yScale3', + type: 'linear', + display: true, + position: 'right', + weight: 1 + }, { + id: 'yScale4', + type: 'linear', + display: true, + position: 'right', + weight: 2 + }] + } + } + }, { + canvas: { + height: 150, + width: 250 + } + }); + + var xScale0 = chart.scales.xScale0; + var xScale1 = chart.scales.xScale1; + var xScale2 = chart.scales.xScale2; + var xScale3 = chart.scales.xScale3; + var xScale4 = chart.scales.xScale4; + + var yScale0 = chart.scales.yScale0; + var yScale1 = chart.scales.yScale1; + var yScale2 = chart.scales.yScale2; + var yScale3 = chart.scales.yScale3; + var yScale4 = chart.scales.yScale4; + + expect(xScale0.weight).toBe(1); + expect(xScale1.weight).toBe(2); + expect(xScale2.weight).toBe(0); + + expect(xScale3.weight).toBe(1); + expect(xScale4.weight).toBe(2); + + expect(yScale0.weight).toBe(1); + expect(yScale1.weight).toBe(2); + expect(yScale2.weight).toBe(0); + + expect(yScale3.weight).toBe(1); + expect(yScale4.weight).toBe(2); + + var isOrderCorrect = false; + + // bottom axes + isOrderCorrect = xScale2.top < xScale0.top && xScale0.top < xScale1.top; + expect(isOrderCorrect).toBe(true); + + // top axes + isOrderCorrect = xScale4.top < xScale3.top; + expect(isOrderCorrect).toBe(true); + + // left axes + isOrderCorrect = yScale1.left < yScale0.left && yScale0.left < yScale2.left; + expect(isOrderCorrect).toBe(true); + + // right axes + isOrderCorrect = yScale3.left < yScale4.left; + expect(isOrderCorrect).toBe(true); + }); }); }); From a9187671017063994d3fef5555289f4e7533ff37 Mon Sep 17 00:00:00 2001 From: Cizmarik Date: Tue, 4 Apr 2017 08:39:42 +0200 Subject: [PATCH 4/4] removed trailing spaces from layout weight scale order test --- test/specs/core.layoutService.tests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/specs/core.layoutService.tests.js b/test/specs/core.layoutService.tests.js index 89209b590b8..b3d57642666 100644 --- a/test/specs/core.layoutService.tests.js +++ b/test/specs/core.layoutService.tests.js @@ -532,7 +532,7 @@ describe('Test the layout service', function() { expect(yScale4.weight).toBe(2); var isOrderCorrect = false; - + // bottom axes isOrderCorrect = xScale2.top < xScale0.top && xScale0.top < xScale1.top; expect(isOrderCorrect).toBe(true); @@ -540,7 +540,7 @@ describe('Test the layout service', function() { // top axes isOrderCorrect = xScale4.top < xScale3.top; expect(isOrderCorrect).toBe(true); - + // left axes isOrderCorrect = yScale1.left < yScale0.left && yScale0.left < yScale2.left; expect(isOrderCorrect).toBe(true);