Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,14 @@ function hoverChanged(gd, evt, oldhoverdata) {
}

// remove hover effects on mouse out, and emit unhover event
function unhover(gd, evt) {
function unhover(gd, evt, subplot) {
if (subplot === 'pie') {
gd.emit('plotly_unhover', {
points: [evt]
});
return;
}

var fullLayout = gd._fullLayout;
if(!evt) evt = {};
if(evt.target &&
Expand Down
4 changes: 3 additions & 1 deletion src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var Fx = require('../../plots/cartesian/graph_interact');
var Color = require('../../components/color');
var Drawing = require('../../components/drawing');
var svgTextUtils = require('../../lib/svg_text_utils');
var Plotly = require('../../plotly');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been favoring this pattern:

var Fx = require('../../plots/components/graph_interact')

lately.


var helpers = require('./helpers');

Expand Down Expand Up @@ -129,7 +130,8 @@ module.exports = function plot(gd, cdpie) {
hasHoverData = true;
}

function handleMouseOut() {
function handleMouseOut(evt) {
Plotly.Fx.unhover(gd, evt, 'pie');
if(hasHoverData) {
Fx.loneUnhover(fullLayout._hoverlayer.node());
hasHoverData = false;
Expand Down
63 changes: 63 additions & 0 deletions test/jasmine/tests/unhover_pie_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var Plotly = require('@lib/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 unhovering', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you merge this suite in test/jasmine/tests/hover_pie_test.js ?

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 futureData;

gd.on('plotly_unhover', function(data) {
futureData = data;
});

var x = width / 2
var y = height / 2
mouseEvent('mouseover', x, y);
mouseEvent('mouseout', x, y);

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 the mouse moves off the graph', function(done) {
var count = 0
futureData = [];

gd.on('plotly_unhover', function(data) {
count++;
});

setTimeout(function() {
mouseEvent('mouseover', 180, 140);
mouseEvent('mouseout', 180, 140);
expect(count).toEqual(1);
done();
}, 100);
});
});
});