From c98185eb55ba658490a01e834f58a75bed46cd06 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 28 Jan 2018 09:07:16 +0000 Subject: [PATCH 01/27] Refactor updateElement and removeHoverStyle --- src/controllers/controller.bar.js | 55 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ff2b56ae5a0..0f04296b608 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -213,28 +213,9 @@ module.exports = function(Chart) { updateElement: function(rectangle, index, reset) { var me = this; - var chart = me.chart; - var meta = me.getMeta(); - var dataset = me.getDataset(); - var custom = rectangle.custom || {}; - var rectangleOptions = chart.options.elements.rectangle; - - rectangle._xScale = me.getScaleForId(meta.xAxisID); - rectangle._yScale = me.getScaleForId(meta.yAxisID); - rectangle._datasetIndex = me.index; rectangle._index = index; - - rectangle._model = { - datasetLabel: dataset.label, - label: chart.data.labels[index], - borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped, - backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor), - borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor), - borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth) - }; - + me.updateRectangle(rectangle); me.updateElementGeometry(rectangle, index, reset); - rectangle.pivot(); }, @@ -474,16 +455,38 @@ module.exports = function(Chart) { }, removeHoverStyle: function(rectangle) { - var dataset = this.chart.data.datasets[rectangle._datasetIndex]; + this.updateRectangle(rectangle); + }, + + updateRectangle: function(rectangle, options) { + var me = this; + var chart = this.chart; + var dataset = this.getDataset(); var index = rectangle._index; var custom = rectangle.custom || {}; - var model = rectangle._model; - var rectangleElementOptions = this.chart.options.elements.rectangle; + var meta = me.getMeta(); + options = options ? options : this.getElementOptions(); - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth); + rectangle._xScale = me.getScaleForId(meta.xAxisID); + rectangle._yScale = me.getScaleForId(meta.yAxisID); + rectangle._datasetIndex = me.index; + + if (!rectangle._model) { + rectangle._model = {}; + } + + rectangle._model.datasetLabel = dataset.label; + rectangle._model.label = chart.data.labels[index]; + rectangle._model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; + rectangle._model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); + rectangle._model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); + rectangle._model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); + }, + + getElementOptions: function() { + return this.chart.options.elements.rectangle; } + }); Chart.controllers.horizontalBar = Chart.controllers.bar.extend({ From 8de5a316ec587f99ca962be90e4f092098d0d9c4 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 28 Jan 2018 09:46:14 +0000 Subject: [PATCH 02/27] Update style only --- src/controllers/controller.bar.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 0f04296b608..ac096434d26 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -213,7 +213,20 @@ module.exports = function(Chart) { updateElement: function(rectangle, index, reset) { var me = this; + var meta = me.getMeta(); + var chart = me.chart; + var dataset = me.getDataset(); + + rectangle._xScale = me.getScaleForId(meta.xAxisID); + rectangle._yScale = me.getScaleForId(meta.yAxisID); + rectangle._datasetIndex = me.index; rectangle._index = index; + + rectangle._model = { + datasetLabel: dataset.label, + label: chart.data.labels[index] + }; + me.updateRectangle(rectangle); me.updateElementGeometry(rectangle, index, reset); rectangle.pivot(); @@ -460,23 +473,11 @@ module.exports = function(Chart) { updateRectangle: function(rectangle, options) { var me = this; - var chart = this.chart; - var dataset = this.getDataset(); + var dataset = me.getDataset(); var index = rectangle._index; var custom = rectangle.custom || {}; - var meta = me.getMeta(); options = options ? options : this.getElementOptions(); - rectangle._xScale = me.getScaleForId(meta.xAxisID); - rectangle._yScale = me.getScaleForId(meta.yAxisID); - rectangle._datasetIndex = me.index; - - if (!rectangle._model) { - rectangle._model = {}; - } - - rectangle._model.datasetLabel = dataset.label; - rectangle._model.label = chart.data.labels[index]; rectangle._model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; rectangle._model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); rectangle._model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); From 87929a44bc83bb4f105a91a15fa1e6a6b787cc8d Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 28 Jan 2018 09:48:10 +0000 Subject: [PATCH 03/27] typo --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ac096434d26..b2ce4dfb444 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -213,8 +213,8 @@ module.exports = function(Chart) { updateElement: function(rectangle, index, reset) { var me = this; - var meta = me.getMeta(); var chart = me.chart; + var meta = me.getMeta(); var dataset = me.getDataset(); rectangle._xScale = me.getScaleForId(meta.xAxisID); From 0bf19105d61f5632581c68e9fbab4be2dd473a68 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 28 Jan 2018 10:54:39 +0000 Subject: [PATCH 04/27] Refactor --- src/controllers/controller.bar.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index b2ce4dfb444..01c2a88b3d6 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -476,12 +476,13 @@ module.exports = function(Chart) { var dataset = me.getDataset(); var index = rectangle._index; var custom = rectangle.custom || {}; + var model = rectangle._model; options = options ? options : this.getElementOptions(); - rectangle._model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; - rectangle._model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); - rectangle._model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); - rectangle._model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); + model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); }, getElementOptions: function() { From 8f664f15cc94002e20e2aa2513ecdac539735a5b Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Mon, 29 Jan 2018 20:28:42 +0000 Subject: [PATCH 05/27] Revert "Refactor" This reverts commit 0bf19105d61f5632581c68e9fbab4be2dd473a68. --- src/controllers/controller.bar.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 01c2a88b3d6..b2ce4dfb444 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -476,13 +476,12 @@ module.exports = function(Chart) { var dataset = me.getDataset(); var index = rectangle._index; var custom = rectangle.custom || {}; - var model = rectangle._model; options = options ? options : this.getElementOptions(); - model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); + rectangle._model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; + rectangle._model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); + rectangle._model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); + rectangle._model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); }, getElementOptions: function() { From bb2c547dc0bf9f485a822e4c67ce7597e3323df5 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Mon, 29 Jan 2018 20:29:04 +0000 Subject: [PATCH 06/27] Revert "typo" This reverts commit 87929a44bc83bb4f105a91a15fa1e6a6b787cc8d. --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index b2ce4dfb444..ac096434d26 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -213,8 +213,8 @@ module.exports = function(Chart) { updateElement: function(rectangle, index, reset) { var me = this; - var chart = me.chart; var meta = me.getMeta(); + var chart = me.chart; var dataset = me.getDataset(); rectangle._xScale = me.getScaleForId(meta.xAxisID); From 9388dd84efa5031a29e79170657f19a61ac889ea Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Mon, 29 Jan 2018 20:29:18 +0000 Subject: [PATCH 07/27] Revert "Update style only" This reverts commit 8de5a316ec587f99ca962be90e4f092098d0d9c4. --- src/controllers/controller.bar.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ac096434d26..0f04296b608 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -213,20 +213,7 @@ module.exports = function(Chart) { updateElement: function(rectangle, index, reset) { var me = this; - var meta = me.getMeta(); - var chart = me.chart; - var dataset = me.getDataset(); - - rectangle._xScale = me.getScaleForId(meta.xAxisID); - rectangle._yScale = me.getScaleForId(meta.yAxisID); - rectangle._datasetIndex = me.index; rectangle._index = index; - - rectangle._model = { - datasetLabel: dataset.label, - label: chart.data.labels[index] - }; - me.updateRectangle(rectangle); me.updateElementGeometry(rectangle, index, reset); rectangle.pivot(); @@ -473,11 +460,23 @@ module.exports = function(Chart) { updateRectangle: function(rectangle, options) { var me = this; - var dataset = me.getDataset(); + var chart = this.chart; + var dataset = this.getDataset(); var index = rectangle._index; var custom = rectangle.custom || {}; + var meta = me.getMeta(); options = options ? options : this.getElementOptions(); + rectangle._xScale = me.getScaleForId(meta.xAxisID); + rectangle._yScale = me.getScaleForId(meta.yAxisID); + rectangle._datasetIndex = me.index; + + if (!rectangle._model) { + rectangle._model = {}; + } + + rectangle._model.datasetLabel = dataset.label; + rectangle._model.label = chart.data.labels[index]; rectangle._model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; rectangle._model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); rectangle._model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); From ac189533d8f79b64fc38f4234cd259a85dc75a15 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Mon, 29 Jan 2018 20:29:30 +0000 Subject: [PATCH 08/27] Revert "Refactor updateElement and removeHoverStyle" This reverts commit c98185eb55ba658490a01e834f58a75bed46cd06. --- src/controllers/controller.bar.js | 55 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 0f04296b608..ff2b56ae5a0 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -213,9 +213,28 @@ module.exports = function(Chart) { updateElement: function(rectangle, index, reset) { var me = this; + var chart = me.chart; + var meta = me.getMeta(); + var dataset = me.getDataset(); + var custom = rectangle.custom || {}; + var rectangleOptions = chart.options.elements.rectangle; + + rectangle._xScale = me.getScaleForId(meta.xAxisID); + rectangle._yScale = me.getScaleForId(meta.yAxisID); + rectangle._datasetIndex = me.index; rectangle._index = index; - me.updateRectangle(rectangle); + + rectangle._model = { + datasetLabel: dataset.label, + label: chart.data.labels[index], + borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped, + backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor), + borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor), + borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth) + }; + me.updateElementGeometry(rectangle, index, reset); + rectangle.pivot(); }, @@ -455,38 +474,16 @@ module.exports = function(Chart) { }, removeHoverStyle: function(rectangle) { - this.updateRectangle(rectangle); - }, - - updateRectangle: function(rectangle, options) { - var me = this; - var chart = this.chart; - var dataset = this.getDataset(); + var dataset = this.chart.data.datasets[rectangle._datasetIndex]; var index = rectangle._index; var custom = rectangle.custom || {}; - var meta = me.getMeta(); - options = options ? options : this.getElementOptions(); - - rectangle._xScale = me.getScaleForId(meta.xAxisID); - rectangle._yScale = me.getScaleForId(meta.yAxisID); - rectangle._datasetIndex = me.index; - - if (!rectangle._model) { - rectangle._model = {}; - } - - rectangle._model.datasetLabel = dataset.label; - rectangle._model.label = chart.data.labels[index]; - rectangle._model.borderSkipped = custom.borderSkipped ? custom.borderSkipped : options.borderSkipped; - rectangle._model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); - rectangle._model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); - rectangle._model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); - }, + var model = rectangle._model; + var rectangleElementOptions = this.chart.options.elements.rectangle; - getElementOptions: function() { - return this.chart.options.elements.rectangle; + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth); } - }); Chart.controllers.horizontalBar = Chart.controllers.bar.extend({ From a9af225122b14d8ab2f297d639086132c8039d56 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Mon, 29 Jan 2018 20:39:36 +0000 Subject: [PATCH 09/27] Implement @simonbrunel solution --- src/controllers/controller.bar.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ff2b56ae5a0..0ed41d29bc8 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -468,21 +468,20 @@ module.exports = function(Chart) { var custom = rectangle.custom || {}; var model = rectangle._model; + rectangle.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth + }; + model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor)); model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); }, removeHoverStyle: function(rectangle) { - var dataset = this.chart.data.datasets[rectangle._datasetIndex]; - var index = rectangle._index; - var custom = rectangle.custom || {}; - var model = rectangle._model; - var rectangleElementOptions = this.chart.options.elements.rectangle; - - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth); + helpers.merge(rectangle._model, rectangle.$previousStyle || {}); + delete rectangle.$previousStyle; } }); From dc2a66e4f866f35d06b7b96a9757c6ef0fd37153 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Mon, 29 Jan 2018 21:04:44 +0000 Subject: [PATCH 10/27] Mix @simbrunel solution with previous implementation --- src/controllers/controller.bar.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 0ed41d29bc8..bf350f6458f 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -480,7 +480,16 @@ module.exports = function(Chart) { }, removeHoverStyle: function(rectangle) { - helpers.merge(rectangle._model, rectangle.$previousStyle || {}); + var dataset = this.chart.data.datasets[rectangle._datasetIndex]; + var index = rectangle._index; + var custom = rectangle.custom || {}; + var model = rectangle._model; + var options = rectangle.$previousStyle ? rectangle.$previousStyle : this.chart.options.elements.rectangle; + + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); + delete rectangle.$previousStyle; } }); From af1abd2649c0916f2010cde28ef73a35b0b30d95 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Wed, 31 Jan 2018 20:19:07 +0000 Subject: [PATCH 11/27] Update failing test --- src/controllers/controller.bar.js | 11 +--------- test/specs/controller.bar.tests.js | 32 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index bf350f6458f..0ed41d29bc8 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -480,16 +480,7 @@ module.exports = function(Chart) { }, removeHoverStyle: function(rectangle) { - var dataset = this.chart.data.datasets[rectangle._datasetIndex]; - var index = rectangle._index; - var custom = rectangle.custom || {}; - var model = rectangle._model; - var options = rectangle.$previousStyle ? rectangle.$previousStyle : this.chart.options.elements.rectangle; - - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, options.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, options.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, options.borderWidth); - + helpers.merge(rectangle._model, rectangle.$previousStyle || {}); delete rectangle.$previousStyle; } }); diff --git a/test/specs/controller.bar.tests.js b/test/specs/controller.bar.tests.js index 096b2e8e116..691f80de997 100644 --- a/test/specs/controller.bar.tests.js +++ b/test/specs/controller.bar.tests.js @@ -1372,13 +1372,23 @@ describe('Chart.controllers.bar', function() { var meta = chart.getDatasetMeta(1); var bar = meta.data[0]; + var helpers = window.Chart.helpers; // Change default chart.options.elements.rectangle.backgroundColor = 'rgb(128, 128, 128)'; chart.options.elements.rectangle.borderColor = 'rgb(15, 15, 15)'; chart.options.elements.rectangle.borderWidth = 3.14; - // Remove to defaults + chart.update(); + expect(bar._model.backgroundColor).toBe('rgb(128, 128, 128)'); + expect(bar._model.borderColor).toBe('rgb(15, 15, 15)'); + expect(bar._model.borderWidth).toBe(3.14); + meta.controller.setHoverStyle(bar); + expect(bar._model.backgroundColor).not.toBe('rgb(128, 128, 128)'); + expect(bar._model.borderColor).not.toBe('rgb(15, 15, 15)'); + expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(128, 128, 128)')); + expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(15, 15, 15)')); + expect(bar._model.borderWidth).toBe(3.14); meta.controller.removeHoverStyle(bar); expect(bar._model.backgroundColor).toBe('rgb(128, 128, 128)'); expect(bar._model.borderColor).toBe('rgb(15, 15, 15)'); @@ -1389,6 +1399,16 @@ describe('Chart.controllers.bar', function() { chart.data.datasets[1].borderColor = ['rgb(9, 9, 9)', 'rgb(0, 0, 0)']; chart.data.datasets[1].borderWidth = [2.5, 5]; + chart.update(); + expect(bar._model.backgroundColor).toBe('rgb(255, 255, 255)'); + expect(bar._model.borderColor).toBe('rgb(9, 9, 9)'); + expect(bar._model.borderWidth).toBe(2.5); + meta.controller.setHoverStyle(bar); + expect(bar._model.backgroundColor).not.toBe('rgb(255, 255, 255)'); + expect(bar._model.borderColor).not.toBe('rgb(9, 9, 9)'); + expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 255, 255)')); + expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(9, 9, 9)')); + expect(bar._model.borderWidth).toBe(2.5); meta.controller.removeHoverStyle(bar); expect(bar._model.backgroundColor).toBe('rgb(255, 255, 255)'); expect(bar._model.borderColor).toBe('rgb(9, 9, 9)'); @@ -1401,6 +1421,16 @@ describe('Chart.controllers.bar', function() { borderWidth: 1.5 }; + chart.update(); + expect(bar._model.backgroundColor).toBe('rgb(255, 0, 0)'); + expect(bar._model.borderColor).toBe('rgb(0, 255, 0)'); + expect(bar._model.borderWidth).toBe(1.5); + meta.controller.setHoverStyle(bar); + expect(bar._model.backgroundColor).not.toBe('rgb(255, 0, 0)'); + expect(bar._model.borderColor).not.toBe('rgb(0, 255, 0)'); + expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 0, 0)')); + expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(0, 255, 0)')); + expect(bar._model.borderWidth).toBe(1.5); meta.controller.removeHoverStyle(bar); expect(bar._model.backgroundColor).toBe('rgb(255, 0, 0)'); expect(bar._model.borderColor).toBe('rgb(0, 255, 0)'); From 2527620e1fc8b40dacf5323261355262d023b0ce Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Thu, 1 Feb 2018 11:17:26 +0000 Subject: [PATCH 12/27] Remove not.toBe() --- test/specs/controller.bar.tests.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/specs/controller.bar.tests.js b/test/specs/controller.bar.tests.js index 691f80de997..7957b6ab5db 100644 --- a/test/specs/controller.bar.tests.js +++ b/test/specs/controller.bar.tests.js @@ -1384,8 +1384,6 @@ describe('Chart.controllers.bar', function() { expect(bar._model.borderColor).toBe('rgb(15, 15, 15)'); expect(bar._model.borderWidth).toBe(3.14); meta.controller.setHoverStyle(bar); - expect(bar._model.backgroundColor).not.toBe('rgb(128, 128, 128)'); - expect(bar._model.borderColor).not.toBe('rgb(15, 15, 15)'); expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(128, 128, 128)')); expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(15, 15, 15)')); expect(bar._model.borderWidth).toBe(3.14); @@ -1404,8 +1402,6 @@ describe('Chart.controllers.bar', function() { expect(bar._model.borderColor).toBe('rgb(9, 9, 9)'); expect(bar._model.borderWidth).toBe(2.5); meta.controller.setHoverStyle(bar); - expect(bar._model.backgroundColor).not.toBe('rgb(255, 255, 255)'); - expect(bar._model.borderColor).not.toBe('rgb(9, 9, 9)'); expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 255, 255)')); expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(9, 9, 9)')); expect(bar._model.borderWidth).toBe(2.5); @@ -1426,8 +1422,6 @@ describe('Chart.controllers.bar', function() { expect(bar._model.borderColor).toBe('rgb(0, 255, 0)'); expect(bar._model.borderWidth).toBe(1.5); meta.controller.setHoverStyle(bar); - expect(bar._model.backgroundColor).not.toBe('rgb(255, 0, 0)'); - expect(bar._model.borderColor).not.toBe('rgb(0, 255, 0)'); expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 0, 0)')); expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(0, 255, 0)')); expect(bar._model.borderWidth).toBe(1.5); From 4b30773af5793449eac7cd2ffd2ac3ca9e070141 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 04:46:47 +0000 Subject: [PATCH 13/27] Refactor --- src/controllers/controller.bar.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 0ed41d29bc8..ab48c1d9b44 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -474,9 +474,18 @@ module.exports = function(Chart) { borderWidth: model.borderWidth }; - model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); - model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor)); - model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); + model.backgroundColor + = custom.hoverBackgroundColor + ? custom.hoverBackgroundColor + : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); + model.borderColor + = custom.hoverBorderColor + ? custom.hoverBorderColor + : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor)); + model.borderWidth + = custom.hoverBorderWidth + ? custom.hoverBorderWidth + : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); }, removeHoverStyle: function(rectangle) { From c8064d6e7d8d4ee8359218d564bc66cd373f6b8a Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 05:27:13 +0000 Subject: [PATCH 14/27] Better hover style for line --- src/controllers/controller.bar.js | 8 ++++---- src/controllers/controller.line.js | 30 ++++++++++++----------------- test/specs/controller.line.tests.js | 8 ++++++++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ab48c1d9b44..f7a41b6af4c 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -488,10 +488,10 @@ module.exports = function(Chart) { : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); }, - removeHoverStyle: function(rectangle) { - helpers.merge(rectangle._model, rectangle.$previousStyle || {}); - delete rectangle.$previousStyle; - } + removeHoverStyle: function(element) { + helpers.merge(element._model, element.$previousStyle || {}); + delete element.$previousStyle; + }, }); Chart.controllers.horizontalBar = Chart.controllers.bar.extend({ diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 9d9206d5cb2..5376908dacd 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -306,28 +306,22 @@ module.exports = function(Chart) { var custom = point.custom || {}; var model = point._model; - model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); + point.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth, + radius: model.radius + }; + model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); + model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); }, - removeHoverStyle: function(point) { - var me = this; - var dataset = me.chart.data.datasets[point._datasetIndex]; - var index = point._index; - var custom = point.custom || {}; - var model = point._model; - - // Compatibility: If the properties are defined with only the old name, use those values - if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) { - dataset.pointRadius = dataset.radius; - } - - model.radius = custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius); - model.backgroundColor = me.getPointBackgroundColor(point, index); - model.borderColor = me.getPointBorderColor(point, index); - model.borderWidth = me.getPointBorderWidth(point, index); - } + removeHoverStyle: function(element) { + helpers.merge(element._model, element.$previousStyle || {}); + delete element.$previousStyle; + }, }); }; diff --git a/test/specs/controller.line.tests.js b/test/specs/controller.line.tests.js index 31c0763a8fe..fb6c8b39094 100644 --- a/test/specs/controller.line.tests.js +++ b/test/specs/controller.line.tests.js @@ -703,6 +703,8 @@ describe('Chart.controllers.line', function() { chart.options.elements.point.radius = 1.01; meta.controller.removeHoverStyle(point); + chart.update(); + expect(point._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(point._model.borderColor).toBe('rgb(50, 51, 52)'); expect(point._model.borderWidth).toBe(10.1); @@ -715,6 +717,8 @@ describe('Chart.controllers.line', function() { chart.data.datasets[0].pointBorderWidth = 2.1; meta.controller.removeHoverStyle(point); + chart.update(); + expect(point._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(point._model.borderColor).toBe('rgb(123, 125, 127)'); expect(point._model.borderWidth).toBe(2.1); @@ -726,6 +730,8 @@ describe('Chart.controllers.line', function() { chart.data.datasets[0].radius = 20; meta.controller.removeHoverStyle(point); + chart.update(); + expect(point._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(point._model.borderColor).toBe('rgb(123, 125, 127)'); expect(point._model.borderWidth).toBe(2.1); @@ -740,6 +746,8 @@ describe('Chart.controllers.line', function() { }; meta.controller.removeHoverStyle(point); + chart.update(); + expect(point._model.backgroundColor).toBe('rgb(0, 0, 0)'); expect(point._model.borderColor).toBe('rgb(10, 10, 10)'); expect(point._model.borderWidth).toBe(5.5); From fcef4b6e80802e6bf0f9b0caeaee4659b76ee5f3 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 05:33:12 +0000 Subject: [PATCH 15/27] Update radar hover style logic --- src/controllers/controller.radar.js | 16 ++++++++++++++-- test/specs/controller.radar.tests.js | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index 5de4e4ede0a..f80d764a7b3 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -146,13 +146,25 @@ module.exports = function(Chart) { var index = point._index; var model = point._model; + point.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth, + radius: model.radius + }; + model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); }, - removeHoverStyle: function(point) { + removeHoverStyle: function(element) { + helpers.merge(element._model, element.$previousStyle || {}); + delete element.$previousStyle; + }, + + /*removeHoverStyle: function(point) { var dataset = this.chart.data.datasets[point._datasetIndex]; var custom = point.custom || {}; var index = point._index; @@ -163,6 +175,6 @@ module.exports = function(Chart) { model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor); model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth); - } + }*/ }); }; diff --git a/test/specs/controller.radar.tests.js b/test/specs/controller.radar.tests.js index df1001420c4..8e3b8d49130 100644 --- a/test/specs/controller.radar.tests.js +++ b/test/specs/controller.radar.tests.js @@ -410,6 +410,7 @@ describe('Chart.controllers.radar', function() { chart.options.elements.point.radius = 1.01; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(point._model.borderColor).toBe('rgb(50, 51, 52)'); expect(point._model.borderWidth).toBe(10.1); @@ -422,6 +423,7 @@ describe('Chart.controllers.radar', function() { chart.data.datasets[0].pointBorderWidth = 2.1; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(point._model.borderColor).toBe('rgb(123, 125, 127)'); expect(point._model.borderWidth).toBe(2.1); @@ -436,6 +438,7 @@ describe('Chart.controllers.radar', function() { }; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(0, 0, 0)'); expect(point._model.borderColor).toBe('rgb(10, 10, 10)'); expect(point._model.borderWidth).toBe(5.5); From fad0561922400018c5df99db02c7331b7fc6fa62 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 05:33:30 +0000 Subject: [PATCH 16/27] cleanup --- src/controllers/controller.radar.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index f80d764a7b3..ab577df0d06 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -163,18 +163,5 @@ module.exports = function(Chart) { helpers.merge(element._model, element.$previousStyle || {}); delete element.$previousStyle; }, - - /*removeHoverStyle: function(point) { - var dataset = this.chart.data.datasets[point._datasetIndex]; - var custom = point.custom || {}; - var index = point._index; - var model = point._model; - var pointElementOptions = this.chart.options.elements.point; - - model.radius = custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius); - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth); - }*/ }); }; From 743a1237b76f9d0562acfa929b6eda3d320ee9a2 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 05:34:35 +0000 Subject: [PATCH 17/27] refactor --- src/controllers/controller.radar.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index ab577df0d06..51f41a499b0 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -153,10 +153,22 @@ module.exports = function(Chart) { radius: model.radius }; - model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); - model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); - model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); - model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); + model.radius + = custom.hoverRadius + ? custom.hoverRadius + : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); + model.backgroundColor + = custom.hoverBackgroundColor + ? custom.hoverBackgroundColor + : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); + model.borderColor + = custom.hoverBorderColor + ? custom.hoverBorderColor + : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); + model.borderWidth + = custom.hoverBorderWidth + ? custom.hoverBorderWidth + : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); }, removeHoverStyle: function(element) { From 57f3df04dae7bf9b76af9fde611baec265b217c1 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 05:51:25 +0000 Subject: [PATCH 18/27] refactor --- src/controllers/controller.bar.js | 12 ++++++------ src/controllers/controller.line.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index f7a41b6af4c..f8abf1dd661 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -462,13 +462,13 @@ module.exports = function(Chart) { helpers.canvas.unclipArea(chart.ctx); }, - setHoverStyle: function(rectangle) { - var dataset = this.chart.data.datasets[rectangle._datasetIndex]; - var index = rectangle._index; - var custom = rectangle.custom || {}; - var model = rectangle._model; + setHoverStyle: function(element) { + var dataset = this.chart.data.datasets[element._datasetIndex]; + var index = element._index; + var custom = element.custom || {}; + var model = element._model; - rectangle.$previousStyle = { + element.$previousStyle = { backgroundColor: model.backgroundColor, borderColor: model.borderColor, borderWidth: model.borderWidth diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 5376908dacd..da271358bd8 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -299,14 +299,14 @@ module.exports = function(Chart) { } }, - setHoverStyle: function(point) { + setHoverStyle: function(element) { // Point - var dataset = this.chart.data.datasets[point._datasetIndex]; - var index = point._index; - var custom = point.custom || {}; - var model = point._model; + var dataset = this.chart.data.datasets[element._datasetIndex]; + var index = element._index; + var custom = element.custom || {}; + var model = element._model; - point.$previousStyle = { + element.$previousStyle = { backgroundColor: model.backgroundColor, borderColor: model.borderColor, borderWidth: model.borderWidth, From 07bf637badefd7f70b9b207511f356e6c73933dc Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 05:57:16 +0000 Subject: [PATCH 19/27] refactor --- src/controllers/controller.doughnut.js | 13 +++++++++++-- src/controllers/controller.polarArea.js | 13 +++++++++++++ src/controllers/controller.radar.js | 2 +- src/core/core.datasetController.js | 11 +++++++++++ test/specs/controller.polarArea.tests.js | 11 ++++++++++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index f7b36e989a9..ce898febd57 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -246,8 +246,17 @@ module.exports = function(Chart) { arc.pivot(); }, - removeHoverStyle: function(arc) { - Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc); + removeHoverStyle: function(element, elementOpts) { + elementOpts = elementOpts || {}; + var dataset = this.chart.data.datasets[element._datasetIndex]; + var index = element._index; + var custom = element.custom || {}; + var valueOrDefault = helpers.valueAtIndexOrDefault; + var model = element._model; + + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); }, calculateTotal: function() { diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index e59aedfb98a..9e93c9bb1bc 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -197,6 +197,19 @@ module.exports = function(Chart) { Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc); }, + /* removeHoverStyle: function(element, elementOpts) { + elementOpts = elementOpts || {}; + var dataset = this.chart.data.datasets[element._datasetIndex]; + var index = element._index; + var custom = element.custom || {}; + var valueOrDefault = helpers.valueAtIndexOrDefault; + var model = element._model; + + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); + }, */ + countVisibleElements: function() { var dataset = this.getDataset(); var meta = this.getMeta(); diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index 51f41a499b0..0799fdb6895 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -157,7 +157,7 @@ module.exports = function(Chart) { = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); - model.backgroundColor + model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index ee6158c35b1..142d7cd736b 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -239,6 +239,7 @@ module.exports = function(Chart) { }, removeHoverStyle: function(element, elementOpts) { + elementOpts = elementOpts || {}; var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; var custom = element.custom || {}; @@ -249,6 +250,10 @@ module.exports = function(Chart) { model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); }, + /* removeHoverStyle: function(element) { + helpers.merge(element._model, element.$previousStyle || {}); + delete element.$previousStyle; + }, */ setHoverStyle: function(element) { var dataset = this.chart.data.datasets[element._datasetIndex]; @@ -258,6 +263,12 @@ module.exports = function(Chart) { var getHoverColor = helpers.getHoverColor; var model = element._model; + element.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth + }; + model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor)); model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor)); model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); diff --git a/test/specs/controller.polarArea.tests.js b/test/specs/controller.polarArea.tests.js index 050bd68b80f..0ff9a62a12f 100644 --- a/test/specs/controller.polarArea.tests.js +++ b/test/specs/controller.polarArea.tests.js @@ -301,7 +301,7 @@ describe('Chart.controllers.polarArea', function() { expect(arc._model.borderWidth).toBe(5.5); }); - it('should remove hover styles', function() { + fit('should remove hover styles', function() { var chart = window.acquireChart({ type: 'polarArea', data: { @@ -329,8 +329,15 @@ describe('Chart.controllers.polarArea', function() { chart.options.elements.arc.backgroundColor = 'rgb(45, 46, 47)'; chart.options.elements.arc.borderColor = 'rgb(50, 51, 52)'; chart.options.elements.arc.borderWidth = 10.1; + chart.update(); + expect(arc._model.backgroundColor).toBe('rgb(45, 46, 47)'); + expect(arc._model.borderColor).toBe('rgb(50, 51, 52)'); + expect(arc._model.borderWidth).toBe(10.1); + meta.controller.setHoverStyle(arc); + chart.update(); meta.controller.removeHoverStyle(arc); + chart.update(); expect(arc._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(arc._model.borderColor).toBe('rgb(50, 51, 52)'); expect(arc._model.borderWidth).toBe(10.1); @@ -341,6 +348,7 @@ describe('Chart.controllers.polarArea', function() { chart.data.datasets[0].borderWidth = 2.1; meta.controller.removeHoverStyle(arc); + chart.update(); expect(arc._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(arc._model.borderColor).toBe('rgb(123, 125, 127)'); expect(arc._model.borderWidth).toBe(2.1); @@ -353,6 +361,7 @@ describe('Chart.controllers.polarArea', function() { }; meta.controller.removeHoverStyle(arc); + chart.update(); expect(arc._model.backgroundColor).toBe('rgb(0, 0, 0)'); expect(arc._model.borderColor).toBe('rgb(10, 10, 10)'); expect(arc._model.borderWidth).toBe(5.5); From 7448c51c76b6f041cce4ebd99b6b7ca730ae5527 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 05:57:58 +0000 Subject: [PATCH 20/27] refactor --- src/core/core.datasetController.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 142d7cd736b..baf6fe8eb6b 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -238,7 +238,7 @@ module.exports = function(Chart) { } }, - removeHoverStyle: function(element, elementOpts) { + /* removeHoverStyle: function(element, elementOpts) { elementOpts = elementOpts || {}; var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; @@ -249,11 +249,11 @@ module.exports = function(Chart) { model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - }, - /* removeHoverStyle: function(element) { + }, */ + removeHoverStyle: function(element) { helpers.merge(element._model, element.$previousStyle || {}); delete element.$previousStyle; - }, */ + }, setHoverStyle: function(element) { var dataset = this.chart.data.datasets[element._datasetIndex]; From 0d9a74b82fef478ade4788261a178a3318cbb822 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 06:02:06 +0000 Subject: [PATCH 21/27] Pass tests --- src/controllers/controller.doughnut.js | 8 ++++++-- src/core/core.datasetController.js | 8 ++++---- test/specs/controller.polarArea.tests.js | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index ce898febd57..9209b12425f 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -246,7 +246,11 @@ module.exports = function(Chart) { arc.pivot(); }, - removeHoverStyle: function(element, elementOpts) { + removeHoverStyle: function(element) { + Chart.DatasetController.prototype.removeHoverStyle.call(this, element, this.chart.options.elements.arc); + }, + + /* removeHoverStyle: function(element, elementOpts) { elementOpts = elementOpts || {}; var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; @@ -257,7 +261,7 @@ module.exports = function(Chart) { model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - }, + },*/ calculateTotal: function() { var dataset = this.getDataset(); diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index baf6fe8eb6b..68170f460b8 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -238,7 +238,7 @@ module.exports = function(Chart) { } }, - /* removeHoverStyle: function(element, elementOpts) { + removeHoverStyle: function(element, elementOpts) { elementOpts = elementOpts || {}; var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; @@ -249,11 +249,11 @@ module.exports = function(Chart) { model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - }, */ - removeHoverStyle: function(element) { + }, + /*removeHoverStyle: function(element) { helpers.merge(element._model, element.$previousStyle || {}); delete element.$previousStyle; - }, + },*/ setHoverStyle: function(element) { var dataset = this.chart.data.datasets[element._datasetIndex]; diff --git a/test/specs/controller.polarArea.tests.js b/test/specs/controller.polarArea.tests.js index 0ff9a62a12f..08693db0a7b 100644 --- a/test/specs/controller.polarArea.tests.js +++ b/test/specs/controller.polarArea.tests.js @@ -301,7 +301,7 @@ describe('Chart.controllers.polarArea', function() { expect(arc._model.borderWidth).toBe(5.5); }); - fit('should remove hover styles', function() { + it('should remove hover styles', function() { var chart = window.acquireChart({ type: 'polarArea', data: { From d89c57281699b8f9e1278c16184dc729d0d30bb3 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 06:10:37 +0000 Subject: [PATCH 22/27] Refactor --- src/controllers/controller.bar.js | 5 ----- src/controllers/controller.bubble.js | 20 ++++++-------------- src/controllers/controller.doughnut.js | 8 ++------ src/controllers/controller.line.js | 21 ++++++++++++--------- src/controllers/controller.polarArea.js | 10 +++------- src/controllers/controller.radar.js | 5 ----- src/core/core.datasetController.js | 16 ++-------------- 7 files changed, 25 insertions(+), 60 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index f8abf1dd661..30afe562112 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -487,11 +487,6 @@ module.exports = function(Chart) { ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); }, - - removeHoverStyle: function(element) { - helpers.merge(element._model, element.$previousStyle || {}); - delete element.$previousStyle; - }, }); Chart.controllers.horizontalBar = Chart.controllers.bar.extend({ diff --git a/src/controllers/controller.bubble.js b/src/controllers/controller.bubble.js index 65c6fae01b8..b808b366b1f 100644 --- a/src/controllers/controller.bubble.js +++ b/src/controllers/controller.bubble.js @@ -102,26 +102,18 @@ module.exports = function(Chart) { setHoverStyle: function(point) { var model = point._model; var options = point._options; - + point.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth, + radius: model.radius + }; model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor)); model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor)); model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth); model.radius = options.radius + options.hoverRadius; }, - /** - * @protected - */ - removeHoverStyle: function(point) { - var model = point._model; - var options = point._options; - - model.backgroundColor = options.backgroundColor; - model.borderColor = options.borderColor; - model.borderWidth = options.borderWidth; - model.radius = options.radius; - }, - /** * @private */ diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 9209b12425f..4cf676049e3 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -247,11 +247,7 @@ module.exports = function(Chart) { }, removeHoverStyle: function(element) { - Chart.DatasetController.prototype.removeHoverStyle.call(this, element, this.chart.options.elements.arc); - }, - - /* removeHoverStyle: function(element, elementOpts) { - elementOpts = elementOpts || {}; + var elementOpts = this.chart.options.elements.arc; var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; var custom = element.custom || {}; @@ -261,7 +257,7 @@ module.exports = function(Chart) { model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - },*/ + }, calculateTotal: function() { var dataset = this.getDataset(); diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index da271358bd8..86707684b18 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -313,15 +313,18 @@ module.exports = function(Chart) { radius: model.radius }; - model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); - model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); - model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); - model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); - }, - - removeHoverStyle: function(element) { - helpers.merge(element._model, element.$previousStyle || {}); - delete element.$previousStyle; + model.backgroundColor + = custom.hoverBackgroundColor + || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); + model.borderColor + = custom.hoverBorderColor + || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); + model.borderWidth + = custom.hoverBorderWidth + || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); + model.radius + = custom.hoverRadius + || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); }, }); }; diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index 9e93c9bb1bc..c80025e50cc 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -193,12 +193,8 @@ module.exports = function(Chart) { arc.pivot(); }, - removeHoverStyle: function(arc) { - Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc); - }, - - /* removeHoverStyle: function(element, elementOpts) { - elementOpts = elementOpts || {}; + removeHoverStyle: function(element) { + var elementOpts = this.chart.options.elements.arc; var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; var custom = element.custom || {}; @@ -208,7 +204,7 @@ module.exports = function(Chart) { model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - }, */ + }, countVisibleElements: function() { var dataset = this.getDataset(); diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index 0799fdb6895..b1f0964a390 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -170,10 +170,5 @@ module.exports = function(Chart) { ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); }, - - removeHoverStyle: function(element) { - helpers.merge(element._model, element.$previousStyle || {}); - delete element.$previousStyle; - }, }); }; diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 68170f460b8..4928f98913e 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -238,22 +238,10 @@ module.exports = function(Chart) { } }, - removeHoverStyle: function(element, elementOpts) { - elementOpts = elementOpts || {}; - var dataset = this.chart.data.datasets[element._datasetIndex]; - var index = element._index; - var custom = element.custom || {}; - var valueOrDefault = helpers.valueAtIndexOrDefault; - var model = element._model; - - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - }, - /*removeHoverStyle: function(element) { + removeHoverStyle: function(element) { helpers.merge(element._model, element.$previousStyle || {}); delete element.$previousStyle; - },*/ + }, setHoverStyle: function(element) { var dataset = this.chart.data.datasets[element._datasetIndex]; From 2d9a387964a58d85d31be18175d0ce8db6d493ef Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 06:32:52 +0000 Subject: [PATCH 23/27] refactor --- src/controllers/controller.bar.js | 26 ------------------------ src/core/core.datasetController.js | 15 +++++++++++--- test/specs/controller.polarArea.tests.js | 6 ++++-- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 30afe562112..cadae3fdb6c 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -461,32 +461,6 @@ module.exports = function(Chart) { helpers.canvas.unclipArea(chart.ctx); }, - - setHoverStyle: function(element) { - var dataset = this.chart.data.datasets[element._datasetIndex]; - var index = element._index; - var custom = element.custom || {}; - var model = element._model; - - element.$previousStyle = { - backgroundColor: model.backgroundColor, - borderColor: model.borderColor, - borderWidth: model.borderWidth - }; - - model.backgroundColor - = custom.hoverBackgroundColor - ? custom.hoverBackgroundColor - : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); - model.borderColor - = custom.hoverBorderColor - ? custom.hoverBorderColor - : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor)); - model.borderWidth - = custom.hoverBorderWidth - ? custom.hoverBorderWidth - : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); - }, }); Chart.controllers.horizontalBar = Chart.controllers.bar.extend({ diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 4928f98913e..c08857c6015 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -257,9 +257,18 @@ module.exports = function(Chart) { borderWidth: model.borderWidth }; - model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor)); - model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor)); - model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); + model.backgroundColor + = custom.hoverBackgroundColor + ? custom.hoverBackgroundColor + : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor)); + model.borderColor + = custom.hoverBorderColor + ? custom.hoverBorderColor + : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor)); + model.borderWidth + = custom.hoverBorderWidth + ? custom.hoverBorderWidth + : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); }, /** diff --git a/test/specs/controller.polarArea.tests.js b/test/specs/controller.polarArea.tests.js index 08693db0a7b..93b05c07804 100644 --- a/test/specs/controller.polarArea.tests.js +++ b/test/specs/controller.polarArea.tests.js @@ -329,15 +329,17 @@ describe('Chart.controllers.polarArea', function() { chart.options.elements.arc.backgroundColor = 'rgb(45, 46, 47)'; chart.options.elements.arc.borderColor = 'rgb(50, 51, 52)'; chart.options.elements.arc.borderWidth = 10.1; + + meta.controller.setHoverStyle(arc); chart.update(); + expect(arc._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(arc._model.borderColor).toBe('rgb(50, 51, 52)'); expect(arc._model.borderWidth).toBe(10.1); - meta.controller.setHoverStyle(arc); - chart.update(); meta.controller.removeHoverStyle(arc); chart.update(); + expect(arc._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(arc._model.borderColor).toBe('rgb(50, 51, 52)'); expect(arc._model.borderWidth).toBe(10.1); From ea376e6e222a968c1e76ae0c4cce6b68cb4c77f5 Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 07:00:47 +0000 Subject: [PATCH 24/27] setup test --- test/specs/controller.doughnut.tests.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/specs/controller.doughnut.tests.js b/test/specs/controller.doughnut.tests.js index a4d6526c912..08df65ff1e5 100644 --- a/test/specs/controller.doughnut.tests.js +++ b/test/specs/controller.doughnut.tests.js @@ -294,6 +294,7 @@ describe('Chart.controllers.doughnut', function() { var meta = chart.getDatasetMeta(0); var arc = meta.data[0]; + meta.controller.setHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(230, 0, 0)'); expect(arc._model.borderColor).toBe('rgb(0, 0, 230)'); @@ -355,6 +356,10 @@ describe('Chart.controllers.doughnut', function() { var meta = chart.getDatasetMeta(0); var arc = meta.data[0]; + chart.update(); + // + meta.controller.setHoverStyle(arc); + // meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(255, 0, 0)'); expect(arc._model.borderColor).toBe('rgb(0, 0, 255)'); @@ -364,7 +369,10 @@ describe('Chart.controllers.doughnut', function() { chart.data.datasets[0].backgroundColor = 'rgb(9, 9, 9)'; chart.data.datasets[0].borderColor = 'rgb(18, 18, 18)'; chart.data.datasets[0].borderWidth = 1.56; - + chart.update(); + // + meta.controller.setHoverStyle(arc); + // meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(9, 9, 9)'); expect(arc._model.borderColor).toBe('rgb(18, 18, 18)'); @@ -374,7 +382,10 @@ describe('Chart.controllers.doughnut', function() { chart.data.datasets[0].backgroundColor = ['rgb(255, 255, 255)', 'rgb(9, 9, 9)']; chart.data.datasets[0].borderColor = ['rgb(18, 18, 18)']; chart.data.datasets[0].borderWidth = [0.1, 1.56]; - + chart.update(); + // + meta.controller.setHoverStyle(arc); + // meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(255, 255, 255)'); expect(arc._model.borderColor).toBe('rgb(18, 18, 18)'); @@ -387,6 +398,10 @@ describe('Chart.controllers.doughnut', function() { borderWidth: 3.14159, }; + chart.update(); + // + meta.controller.setHoverStyle(arc); + // meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(7, 7, 7)'); expect(arc._model.borderColor).toBe('rgb(17, 17, 17)'); From 693fb03e2e8f06c3abd8e5b7868b9ae016bc34ce Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 07:01:07 +0000 Subject: [PATCH 25/27] Comment seamingly unecessary code --- src/controllers/controller.doughnut.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 4cf676049e3..e5962b6cee1 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -246,18 +246,18 @@ module.exports = function(Chart) { arc.pivot(); }, - removeHoverStyle: function(element) { - var elementOpts = this.chart.options.elements.arc; - var dataset = this.chart.data.datasets[element._datasetIndex]; - var index = element._index; - var custom = element.custom || {}; - var valueOrDefault = helpers.valueAtIndexOrDefault; - var model = element._model; - - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - }, +// removeHoverStyle: function(element) { +// var elementOpts = this.chart.options.elements.arc; +// var dataset = this.chart.data.datasets[element._datasetIndex]; +// var index = element._index; +// var custom = element.custom || {}; +// var valueOrDefault = helpers.valueAtIndexOrDefault; +// var model = element._model; +// +// model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); +// model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); +// model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); +// }, calculateTotal: function() { var dataset = this.getDataset(); From 92cb84016418486556582053f97235301680bb8e Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 07:08:03 +0000 Subject: [PATCH 26/27] Setup test for doughnut.controller.removeHoverStyle() --- src/controllers/controller.doughnut.js | 24 ++++++++++++------------ src/core/core.datasetController.js | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index e5962b6cee1..4cf676049e3 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -246,18 +246,18 @@ module.exports = function(Chart) { arc.pivot(); }, -// removeHoverStyle: function(element) { -// var elementOpts = this.chart.options.elements.arc; -// var dataset = this.chart.data.datasets[element._datasetIndex]; -// var index = element._index; -// var custom = element.custom || {}; -// var valueOrDefault = helpers.valueAtIndexOrDefault; -// var model = element._model; -// -// model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); -// model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); -// model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); -// }, + removeHoverStyle: function(element) { + var elementOpts = this.chart.options.elements.arc; + var dataset = this.chart.data.datasets[element._datasetIndex]; + var index = element._index; + var custom = element.custom || {}; + var valueOrDefault = helpers.valueAtIndexOrDefault; + var model = element._model; + + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); + }, calculateTotal: function() { var dataset = this.getDataset(); diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index c08857c6015..0c2f23f746f 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -247,7 +247,6 @@ module.exports = function(Chart) { var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; var custom = element.custom || {}; - var valueOrDefault = helpers.valueAtIndexOrDefault; var getHoverColor = helpers.getHoverColor; var model = element._model; From 9cd06866dac9fbfae628da33dd57bc23303010ba Mon Sep 17 00:00:00 2001 From: loicbourgois Date: Sun, 11 Feb 2018 07:09:33 +0000 Subject: [PATCH 27/27] Test commenting seamingly unnecessary code --- src/controllers/controller.doughnut.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 4cf676049e3..58cc1224fd1 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -246,7 +246,7 @@ module.exports = function(Chart) { arc.pivot(); }, - removeHoverStyle: function(element) { + /* removeHoverStyle: function(element) { var elementOpts = this.chart.options.elements.arc; var dataset = this.chart.data.datasets[element._datasetIndex]; var index = element._index; @@ -257,7 +257,7 @@ module.exports = function(Chart) { model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - }, + }, */ calculateTotal: function() { var dataset = this.getDataset();