|
| 1 | +var Plotly = require('@src/index'); |
| 2 | +var Lib = require('@src/lib'); |
| 3 | + |
| 4 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 5 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 6 | +var mouseEvent = require('../assets/mouse_event'); |
| 7 | + |
| 8 | +describe('pie hovering', function () { |
| 9 | + var mock = require('@mocks/pie_simple.json'); |
| 10 | + |
| 11 | + describe('event data', function () { |
| 12 | + var mockCopy = Lib.extendDeep({}, mock), |
| 13 | + width = mockCopy.layout.width, |
| 14 | + height = mockCopy.layout.height, |
| 15 | + gd; |
| 16 | + |
| 17 | + beforeEach(function (done) { |
| 18 | + gd = createGraphDiv(); |
| 19 | + |
| 20 | + Plotly.plot(gd, mockCopy.data, mockCopy.layout) |
| 21 | + .then(done); |
| 22 | + }); |
| 23 | + |
| 24 | + afterEach(destroyGraphDiv); |
| 25 | + |
| 26 | + it('should contain the correct fields', function () { |
| 27 | + |
| 28 | + var expected = [{ |
| 29 | + "v":4, |
| 30 | + "label":"3", |
| 31 | + "color":"#ff7f0e", |
| 32 | + "i":3, |
| 33 | + "hidden":false, |
| 34 | + "text":"26.7%", |
| 35 | + "px1":[0,-60], |
| 36 | + "pxmid":[-44.588689528643656,-40.14783638153149], |
| 37 | + "midangle":-0.8377580409572781, |
| 38 | + "px0":[-59.67131372209641,6.2717077960592], |
| 39 | + "largeArc":0, |
| 40 | + "cxFinal":200, |
| 41 | + "cyFinal":160 |
| 42 | + }], |
| 43 | + futureData; |
| 44 | + |
| 45 | + |
| 46 | + gd.on('plotly_hover', function (data) { |
| 47 | + futureData = data; |
| 48 | + }); |
| 49 | + |
| 50 | + mouseEvent('mouseover', width / 2, height / 2); |
| 51 | + expect(futureData.points).toEqual(expected); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should fire when moving from one slice to another', function (done) { |
| 55 | + var count = 0 |
| 56 | + futureData = []; |
| 57 | + |
| 58 | + gd.on('plotly_hover', function (data) { |
| 59 | + count++; |
| 60 | + futureData.push(data); |
| 61 | + console.log(data); |
| 62 | + }); |
| 63 | + |
| 64 | + mouseEvent('mouseover', 180, 140); |
| 65 | + setTimeout(function () { |
| 66 | + mouseEvent('mouseover', 240, 200); |
| 67 | + expect(count).toEqual(2); |
| 68 | + expect(futureData[0]).not.toEqual(futureData[1]) |
| 69 | + done(); |
| 70 | + }, 100); |
| 71 | + }); |
| 72 | + }); |
| 73 | +}); |
0 commit comments