From 7a42827f8c6775073aa3cee1c221f2a460ebe8b7 Mon Sep 17 00:00:00 2001 From: Xingan Wang Date: Sat, 29 Apr 2017 15:33:02 -0700 Subject: [PATCH] =?UTF-8?q?testcase=20for=20scales=20options=20update;=20o?= =?UTF-8?q?nly=20update=20options=20when=20scale/scales/tooltip=20config?= =?UTF-8?q?=20exiest=20in=20user=E2=80=99s=20new=20input.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/core.controller.js | 10 +++++----- test/specs/core.controller.tests.js | 31 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 98561209c2f..380f52e80dd 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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], @@ -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) { diff --git a/test/specs/core.controller.tests.js b/test/specs/core.controller.tests.js index 1849da8c363..87a8a709bbb 100644 --- a/test/specs/core.controller.tests.js +++ b/test/specs/core.controller.tests.js @@ -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',