From 5d9963468229f8f233859916ec98193ac3d16e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Mon, 28 Dec 2015 17:37:17 -0500 Subject: [PATCH 01/11] Fixed promise return (Promise.resolve is not a constructor) --- src/plot_api/plot_api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 2c3476a5579..524c9c754bf 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1647,11 +1647,11 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { if(typeof astr === 'string') aobj[astr] = val; else if(Plotly.Lib.isPlainObject(astr)) { aobj = astr; - if(traces===undefined) traces = val; // the 3-arg form + if(traces === undefined) traces = val; // the 3-arg form } else { console.log('restyle fail',astr,val,traces); - return new Promise.reject(); + return Promise.reject(); } if(Object.keys(aobj).length) gd.changed = true; @@ -2173,7 +2173,7 @@ Plotly.relayout = function relayout(gd, astr, val) { gd = getGraphDiv(gd); if(gd.framework && gd.framework.isPolar) { - return new Promise.resolve(gd); + return Promise.resolve(gd); } var layout = gd.layout, From ab2ebf443f795985f89515537db030a463f1bb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Mon, 28 Dec 2015 17:57:07 -0500 Subject: [PATCH 02/11] Re-set autobins after supplying defaulys if initially set --- src/plots/plots.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plots/plots.js b/src/plots/plots.js index f82051e2f93..d7f9553b1c2 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -426,6 +426,15 @@ plots.supplyDefaults = function(gd) { trace = newData[i]; fullTrace = plots.supplyDataDefaults(trace, i, newFullLayout); + + // If autobinned before, autobin again. supplyDataDefaults sees + // the generated bin object and assumes it has been set manually + // so we need to override that behaviour. + if (oldFullData[i]){ + fullTrace.autobinx = oldFullData[i].autobinx || fullTrace.autobinx; + fullTrace.autobiny = oldFullData[i].autobiny || fullTrace.autobiny; + } + newFullData.push(fullTrace); // DETECT 3D, Cartesian, and Polar From 8273beab79e4d827a07aed1da49c54dc30a2d50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Tue, 29 Dec 2015 13:49:19 -0500 Subject: [PATCH 03/11] add condition for hover events on pie charts --- src/plots/cartesian/graph_interact.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index 623e802fc88..9f3ccfa014d 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -309,6 +309,13 @@ fx.unhover = function (gd, evt, subplot) { // The actual implementation is here: function hover(gd, evt, subplot){ + if(gd._fullLayout._hasPie){ + gd.emit('plotly_hover', { + points: [evt] + }); + return; + } + if(!subplot) subplot = 'xy'; var fullLayout = gd._fullLayout, From b5125664226cbcc97be8dcbe9bbb4d4c20deea19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Tue, 29 Dec 2015 13:50:03 -0500 Subject: [PATCH 04/11] Add call to fx.hover onhover --- src/traces/pie/plot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index 264902a03e2..91420deb68f 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -82,7 +82,7 @@ module.exports = function plot(gd, cdpie) { slicePath = sliceTop.selectAll('path.surface').data([pt]), hasHoverData = false; - function handleMouseOver() { + function handleMouseOver(evt) { // in case fullLayout or fullData has changed without a replot var fullLayout2 = gd._fullLayout, trace2 = gd._fullData[trace.index], @@ -123,6 +123,8 @@ module.exports = function plot(gd, cdpie) { } ); + Plotly.Fx.hover(gd, evt, 'pie'); + hasHoverData = true; } From b89720b150ad98c87c41d3712f6d1aab5e81dfb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Tue, 29 Dec 2015 14:13:08 -0500 Subject: [PATCH 05/11] Whoops. Undo changes from a different branch --- src/plot_api/plot_api.js | 6 +++--- src/plots/plots.js | 9 --------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 524c9c754bf..2c3476a5579 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1647,11 +1647,11 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { if(typeof astr === 'string') aobj[astr] = val; else if(Plotly.Lib.isPlainObject(astr)) { aobj = astr; - if(traces === undefined) traces = val; // the 3-arg form + if(traces===undefined) traces = val; // the 3-arg form } else { console.log('restyle fail',astr,val,traces); - return Promise.reject(); + return new Promise.reject(); } if(Object.keys(aobj).length) gd.changed = true; @@ -2173,7 +2173,7 @@ Plotly.relayout = function relayout(gd, astr, val) { gd = getGraphDiv(gd); if(gd.framework && gd.framework.isPolar) { - return Promise.resolve(gd); + return new Promise.resolve(gd); } var layout = gd.layout, diff --git a/src/plots/plots.js b/src/plots/plots.js index d7f9553b1c2..f82051e2f93 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -426,15 +426,6 @@ plots.supplyDefaults = function(gd) { trace = newData[i]; fullTrace = plots.supplyDataDefaults(trace, i, newFullLayout); - - // If autobinned before, autobin again. supplyDataDefaults sees - // the generated bin object and assumes it has been set manually - // so we need to override that behaviour. - if (oldFullData[i]){ - fullTrace.autobinx = oldFullData[i].autobinx || fullTrace.autobinx; - fullTrace.autobiny = oldFullData[i].autobiny || fullTrace.autobiny; - } - newFullData.push(fullTrace); // DETECT 3D, Cartesian, and Polar From 6ade9de344deeac0136ec6149c58a9a763db6a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Mon, 4 Jan 2016 15:17:53 -0500 Subject: [PATCH 06/11] Mouse simulation function for testing --- test/jasmine/assets/mouse_event.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/jasmine/assets/mouse_event.js diff --git a/test/jasmine/assets/mouse_event.js b/test/jasmine/assets/mouse_event.js new file mode 100644 index 00000000000..036e33f0a4f --- /dev/null +++ b/test/jasmine/assets/mouse_event.js @@ -0,0 +1,6 @@ +module.exports = function (type, x, y, opts) { + var el = document.elementFromPoint(x,y); + var options = opts || { bubbles: true }; + var ev = new window.MouseEvent(type, options); + el.dispatchEvent(ev); +}; From b8527bdfca41bb7838158ea06cd5581b84600a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Mon, 4 Jan 2016 15:18:08 -0500 Subject: [PATCH 07/11] pie chart hover tests --- test/jasmine/tests/hover_pie_test.js | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/jasmine/tests/hover_pie_test.js diff --git a/test/jasmine/tests/hover_pie_test.js b/test/jasmine/tests/hover_pie_test.js new file mode 100644 index 00000000000..247a2e4cc82 --- /dev/null +++ b/test/jasmine/tests/hover_pie_test.js @@ -0,0 +1,73 @@ +var Plotly = require('@src/index'); +var Lib = require('@src/lib'); + +var createGraphDiv = require('../assets/create_graph_div'); +var destroyGraphDiv = require('../assets/destroy_graph_div'); +var mouseEvent = require('../assets/mouse_event'); + +describe('pie hovering', function () { + var mock = require('@mocks/pie_simple.json'); + + describe('event data', function () { + var mockCopy = Lib.extendDeep({}, mock), + width = mockCopy.layout.width, + height = mockCopy.layout.height, + gd; + + beforeEach(function (done) { + gd = createGraphDiv(); + + Plotly.plot(gd, mockCopy.data, mockCopy.layout) + .then(done); + }); + + afterEach(destroyGraphDiv); + + it('should contain the correct fields', function () { + + var expected = [{ + "v":4, + "label":"3", + "color":"#ff7f0e", + "i":3, + "hidden":false, + "text":"26.7%", + "px1":[0,-60], + "pxmid":[-44.588689528643656,-40.14783638153149], + "midangle":-0.8377580409572781, + "px0":[-59.67131372209641,6.2717077960592], + "largeArc":0, + "cxFinal":200, + "cyFinal":160 + }], + futureData; + + + gd.on('plotly_hover', function (data) { + futureData = data; + }); + + mouseEvent('mouseover', width / 2, height / 2); + expect(futureData.points).toEqual(expected); + }); + + it('should fire when moving from one slice to another', function (done) { + var count = 0 + futureData = []; + + gd.on('plotly_hover', function (data) { + count++; + futureData.push(data); + console.log(data); + }); + + mouseEvent('mouseover', 180, 140); + setTimeout(function () { + mouseEvent('mouseover', 240, 200); + expect(count).toEqual(2); + expect(futureData[0]).not.toEqual(futureData[1]) + done(); + }, 100); + }); + }); +}); From ac887f113e6c0065002905010b5006d17baccfe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Mon, 4 Jan 2016 15:37:02 -0500 Subject: [PATCH 08/11] Removed unnecessary console.log --- test/jasmine/tests/hover_pie_test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/jasmine/tests/hover_pie_test.js b/test/jasmine/tests/hover_pie_test.js index 247a2e4cc82..6ba097967ff 100644 --- a/test/jasmine/tests/hover_pie_test.js +++ b/test/jasmine/tests/hover_pie_test.js @@ -58,7 +58,6 @@ describe('pie hovering', function () { gd.on('plotly_hover', function (data) { count++; futureData.push(data); - console.log(data); }); mouseEvent('mouseover', 180, 140); From 6bdfdbbb8bcd7cd0945767a4469253ec8fbf4a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Mon, 4 Jan 2016 16:31:09 -0500 Subject: [PATCH 09/11] Fix test to work on ff and chrome --- test/jasmine/tests/hover_pie_test.js | 36 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/jasmine/tests/hover_pie_test.js b/test/jasmine/tests/hover_pie_test.js index 6ba097967ff..2be49b71bbc 100644 --- a/test/jasmine/tests/hover_pie_test.js +++ b/test/jasmine/tests/hover_pie_test.js @@ -5,7 +5,7 @@ var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var mouseEvent = require('../assets/mouse_event'); -describe('pie hovering', function () { +fdescribe('pie hovering', function () { var mock = require('@mocks/pie_simple.json'); describe('event data', function () { @@ -26,19 +26,19 @@ describe('pie hovering', function () { it('should contain the correct fields', function () { var expected = [{ - "v":4, - "label":"3", - "color":"#ff7f0e", - "i":3, - "hidden":false, - "text":"26.7%", - "px1":[0,-60], - "pxmid":[-44.588689528643656,-40.14783638153149], - "midangle":-0.8377580409572781, - "px0":[-59.67131372209641,6.2717077960592], - "largeArc":0, - "cxFinal":200, - "cyFinal":160 + v: 4, + label: '3', + color: '#ff7f0e', + i: 3, + hidden: false, + text: '26.7%', + px1: [0,-60], + pxmid: [-44.588689528643656,-40.14783638153149], + midangle: -0.8377580409572781, + px0: [-59.67131372209641,6.2717077960592], + largeArc: 0, + cxFinal: 200, + cyFinal: 160 }], futureData; @@ -48,7 +48,13 @@ describe('pie hovering', function () { }); mouseEvent('mouseover', width / 2, height / 2); - expect(futureData.points).toEqual(expected); + expect(futureData.points.length).toEqual(1); + expect(Object.keys(futureData.points[0])).toEqual([ + 'v', 'label', 'color', 'i', 'hidden', + 'text', 'px1', 'pxmid', 'midangle', + 'px0', 'largeArc', 'cxFinal', 'cyFinal' + ]); + expect(futureData.points[0].i).toEqual(3); }); it('should fire when moving from one slice to another', function (done) { From 8e511fcb471bdac3949d51b13ee2f532618d234c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Mon, 4 Jan 2016 16:40:26 -0500 Subject: [PATCH 10/11] remove fdescribe test --- test/jasmine/tests/hover_pie_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jasmine/tests/hover_pie_test.js b/test/jasmine/tests/hover_pie_test.js index 2be49b71bbc..cc52e8130e4 100644 --- a/test/jasmine/tests/hover_pie_test.js +++ b/test/jasmine/tests/hover_pie_test.js @@ -5,7 +5,7 @@ var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var mouseEvent = require('../assets/mouse_event'); -fdescribe('pie hovering', function () { +describe('pie hovering', function () { var mock = require('@mocks/pie_simple.json'); describe('event data', function () { From 66eade7ccf651766e3492c74979d7cf0fad98ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Tue, 5 Jan 2016 14:10:41 -0500 Subject: [PATCH 11/11] Changed hover event to check if subplot === pie --- src/plots/cartesian/graph_interact.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index 9f3ccfa014d..d2af96f5e48 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -309,7 +309,7 @@ fx.unhover = function (gd, evt, subplot) { // The actual implementation is here: function hover(gd, evt, subplot){ - if(gd._fullLayout._hasPie){ + if(subplot === 'pie'){ gd.emit('plotly_hover', { points: [evt] });