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

scale service - respect new weight scale option for axes ordering #4094

Merged
merged 4 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/axes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/core/core.scaleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
121 changes: 121 additions & 0 deletions test/specs/core.layoutService.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});