-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Hover text bug #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hover text bug #70
Changes from 4 commits
69997b1
b45886f
9c5a14a
8e363e5
e51e0df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
var d3 = require('d3'); | ||
|
||
var Plotly = require('@src/index'); | ||
var Fx = require('@src/plots/cartesian/graph_interact'); | ||
var Lib = require('@src/lib'); | ||
|
||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
|
||
describe('hover info', function() { | ||
'use strict'; | ||
|
||
var mock = require('@mocks/14.json'), | ||
evt = { | ||
clientX: mock.layout.width/ 2, | ||
clientY: mock.layout.height / 2 | ||
}; | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
describe('hover info', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we could have 1 beforeEach and multiple var mockData, mockLayout
describe('hover tests', function () {
mockData = mockData()
mockLayout = mockLayout()
beforeEach( function (done) {
Plotly.plot(gd, mockData, mockLayout).then(done)
})
it('responds to hover', function () { // test that uses mockData and mockLayout }
it('resonds to hover x', function () { // test ... }
}) We can put the var declarations global scope and then assign fresh copies in the single BeforeEach. No need for multiple describes and beforeEach's. If that is dooable is should really clear up the test. For comparison check out the many Jest (Jasmine fork) tests in Filewell. We have a set of patterns that might be useful. https://github.com/plotly/streambed/blob/master/shelly/filewell/static/filewell/src/stores/__tests__/DirectoryStore-test.js Here there is one BeforeEach to refresh state before each test and a few describe blocks that break the test into logical chunks. If we are just testing hover here one describe is probably enough Check around the filewell src tree, every folder has a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nop. That won't because we call Plotly.plot with different data each time. We could only force update hovermode in gd directly without a plot call and test the labels then. But that feels kind of dirty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah aight - the only other suggestion I can think of is to remove the multiple BeforeEach and Describes and do something like it('does hover things', function(done) {
Plotly.plot(newGD(), newData(), newLayout()).then( function () {
expect(thingsToHappen()).toBe(true)
done()
})
}) where you get shorter code but have 1 level of nesting in the tests. |
||
}); | ||
|
||
it('responds to hover', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(1); | ||
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388'); | ||
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('1'); | ||
}); | ||
}); | ||
|
||
describe('hover info x', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another note on jasmine: the |
||
|
||
mockCopy.data[0].hoverinfo = 'x'; | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
}); | ||
|
||
it('responds to hover x', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(0); | ||
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388'); | ||
}); | ||
}); | ||
|
||
describe('hover info y', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
|
||
mockCopy.data[0].hoverinfo = 'y'; | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexcjohnson @bpostlethwaite @mdtusz a note on jasmine async testing: it's not very good. For example, it can't assert an One way around this problem is to make all the async stuff happen in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great trick to know! But is there actually anything async in this call? I thought it was sync unless it had gl or mathjax? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jasmine supports async as of 2.0. The done callback in passed in every test. Won't that work for our needs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bpostlethwaite Sure. Having Not sure what's better / cleaner. |
||
}); | ||
|
||
it('responds to hover y', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(0); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('1'); | ||
}); | ||
}); | ||
|
||
describe('hover info text', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
|
||
mockCopy.data[0].text = [] | ||
mockCopy.data[0].text[17] = 'hover text' | ||
mockCopy.data[0].hoverinfo = 'text'; | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
}); | ||
|
||
it('responds to hover text', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(0); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('hover text'); | ||
}); | ||
}); | ||
|
||
describe('hover info all', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
|
||
mockCopy.data[0].text = [] | ||
mockCopy.data[0].text[17] = 'hover text' | ||
mockCopy.data[0].hoverinfo = 'all'; | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
}); | ||
|
||
it('responds to hover all', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(1); | ||
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388'); | ||
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('<tspan class="line" dy="0em" x="9" y="-3.9453125">1</tspan><tspan class="line" dy="1.3em" x="9" y="-3.9453125">hover text</tspan>'); | ||
}); | ||
}); | ||
|
||
describe('hover info y+text', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
|
||
mockCopy.data[0].text = [] | ||
mockCopy.data[0].text[17] = 'hover text' | ||
mockCopy.data[0].hoverinfo = 'y+text'; | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
}); | ||
|
||
it('responds to hover y+text', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(0); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('<tspan class="line" dy="0em" x="9" y="-3.9453125">1</tspan><tspan class="line" dy="1.3em" x="9" y="-3.9453125">hover text</tspan>'); | ||
}); | ||
}); | ||
|
||
describe('hover info x+text', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
|
||
mockCopy.data[0].text = [] | ||
mockCopy.data[0].text[17] = 'hover text' | ||
mockCopy.data[0].hoverinfo = 'x+text'; | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
}); | ||
|
||
it('responds to hover x+text', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(1); | ||
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388'); | ||
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('hover text'); | ||
}); | ||
}); | ||
|
||
describe('hover info text with html', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
|
||
mockCopy.data[0].text = [] | ||
mockCopy.data[0].text[17] = 'hover<br>text' | ||
mockCopy.data[0].hoverinfo = 'text'; | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); | ||
}); | ||
|
||
it('responds to hover text with html', function() { | ||
var gd = document.getElementById('graph'); | ||
Fx.hover('graph', evt, 'xy'); | ||
|
||
var hoverTrace = gd._hoverdata[0]; | ||
|
||
expect(hoverTrace.curveNumber).toEqual(0); | ||
expect(hoverTrace.pointNumber).toEqual(17); | ||
expect(hoverTrace.x).toEqual(0.388); | ||
expect(hoverTrace.y).toEqual(1); | ||
|
||
expect(d3.selectAll('g.axistext').size()).toEqual(0); | ||
expect(d3.selectAll('g.hovertext').size()).toEqual(1); | ||
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('<tspan class="line" dy="0em" x="9" y="-3.9453125">hover</tspan><tspan class="line" dy="1.3em" x="9" y="-3.9453125">text</tspan>'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💥 nice |
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexcjohnson this has me thinking that perhaps
flaglist
attributes should be stored infullData
as arrays instead of strings, to make comparison more seamless. Moreover, maybe theall
flag should be expected to e.g.x+y+text+name
in the default step.Alternatively, we could cook a nice general lib function
isInFlagList
that would take care of the logic on demand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like
isInFlagList
better (I like it a lot, in fact 👍 ) -fullData
isn't supposed to change things fromdata
unless they're invalid, it's just supposed to fill in the blanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Let's keep that in mind when we get to #34. There are only a few
flaglist
attributes at the moment, but more are coming.