-
-
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
Conversation
cldougl
commented
Dec 3, 2015
- fix for hover label bug: Cartesian plot with 'hoverinfo': 'text' or 'y+text' and 'hovermode': 'x' does not show hover text #43
- add hover tests
@@ -12,7 +12,7 @@ describe('Test plot structure', function () { | |||
|
|||
afterEach(destroyGraphDiv); | |||
|
|||
describe('cartesian plots', function() { | |||
describe('cartesian plots', function() { |
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.
@cldougl you might want to try http://nategood.com/sublime-text-strip-whitespace-save
to avoid those nasty diff lines.
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.
will do
@@ -778,8 +778,9 @@ function createHoverText(hoverData, opts) { | |||
var i, traceHoverinfo; | |||
for (i = 0; i < hoverData.length; i++) { | |||
traceHoverinfo = hoverData[i].trace.hoverinfo; | |||
if (traceHoverinfo.indexOf('all')===-1 && | |||
traceHoverinfo.indexOf(hovermode)===-1) { | |||
var parts = traceHoverinfo.split('+'); |
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 in fullData
as arrays instead of strings, to make comparison more seamless. Moreover, maybe the all
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 from data
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.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
💥 nice <tspan>
s
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 comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we could have 1 beforeEach and multiple it
s?
pseudocode
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 __test__
folder with Jest tests.
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.
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 comment
The 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.
looks pretty good to me. I think we can refactor the test to simplify it somewhat. Let me know if I can help with that. We have written hundreds of these damn things in Filewell and have a set of test helpers and patterns for dealing with State refresh |
Okay previous suggestion was not going to work as @etpinard pointed out. Made another suggestion. It may or may not be worth it, your call. Looks 💃 to me! Nice work! |
Thanks for the tests suggestions/explanations @bpostlethwaite ! I have both options worked out- @etpinard or @mdtusz do you have a preference on which format we use for this (ben's nested suggestion or the current nested describes)? |
@bpostlethwaite @etpinard false alarm- the new (done) pattern doesn't actually work (same problem as yesterday you can test |
💃 |