Skip to content

Commit

Permalink
testcase for scales options update;
Browse files Browse the repository at this point in the history
only update options when scale/scales/tooltip config exiest in user’s new input.
  • Loading branch information
xg-wang committed Apr 29, 2017
1 parent 012533c commit 7a42827
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/core.controller.js
Expand Up @@ -43,8 +43,8 @@ module.exports = function(Chart) {
function updateConfig(chart) {
var newOptions = chart.options;

// Update Scale(s) with options
if (newOptions.scale || newOptions.scales) {
// Update Scale(s) or Tooltip with options if needed
if (newOptions.scale || newOptions.scales || newOptions.tooltips) {
newOptions = helpers.configMerge(
Chart.defaults.global,
Chart.defaults[chart.config.type],
Expand All @@ -59,10 +59,10 @@ module.exports = function(Chart) {
chart.scales[scaleOptions.id].options = scaleOptions;
});
}
}

// Tooltip
chart.tooltip._options = newOptions.tooltips;
// Tooltip
chart.tooltip._options = newOptions.tooltips;
}
}

function positionIsHorizontal(position) {
Expand Down
31 changes: 31 additions & 0 deletions test/specs/core.controller.tests.js
Expand Up @@ -634,6 +634,37 @@ describe('Chart', function() {
expect(yScale.options.ticks.max).toBe(10);
});

it ('should update scales options from new object', function() {
var chart = acquireChart({
type: 'line',
data: {
labels: ['A', 'B', 'C', 'D'],
datasets: [{
data: [10, 20, 30, 100]
}]
},
options: {
responsive: true
}
});

var newScalesConfig = {
yAxes: [{
ticks: {
min: 0,
max: 10
}
}]
};
chart.options.scales = newScalesConfig;

chart.update();

var yScale = chart.scales['y-axis-0'];
expect(yScale.options.ticks.min).toBe(0);
expect(yScale.options.ticks.max).toBe(10);
});

it ('should update tooltip options', function() {
var chart = acquireChart({
type: 'line',
Expand Down

0 comments on commit 7a42827

Please sign in to comment.