-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add 'hovertext' attribute in scatter* traces #1523
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
Changes from 1 commit
b91fd3b
2dc0250
253a29b
2b02c5f
7b6911f
a7b76ee
55a51f8
aa6eadf
b3448f0
4148cd4
b760fe8
a859464
1bf54e2
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ var customMatchers = require('../assets/custom_matchers'); | |
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
|
||
var d3 = require('d3'); | ||
var click = require('../assets/click'); | ||
var getClientPosition = require('../assets/get_client_position'); | ||
var mouseEvent = require('../assets/mouse_event'); | ||
|
@@ -175,9 +176,7 @@ describe('pie hovering', function() { | |
}); | ||
|
||
describe('labels', function() { | ||
|
||
var gd, | ||
mockCopy; | ||
var gd, mockCopy; | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
|
@@ -186,44 +185,60 @@ describe('pie hovering', function() { | |
|
||
afterEach(destroyGraphDiv); | ||
|
||
it('should show the default selected values', function(done) { | ||
|
||
var expected = ['4', '5', '33.3%']; | ||
|
||
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() { | ||
function _hover() { | ||
mouseEvent('mouseover', 223, 143); | ||
} | ||
|
||
mouseEvent('mouseover', 223, 143); | ||
function assertLabel(expected) { | ||
var labels = d3.selectAll('.hovertext .nums .line'); | ||
|
||
var labels = Plotly.d3.selectAll('.hovertext .nums .line'); | ||
expect(labels[0].length).toBe(expected.length); | ||
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. 🐄 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. Good 👁️ thanks! 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. done in 1bf54e2 |
||
|
||
expect(labels[0].length).toBe(3); | ||
labels.each(function(_, i) { | ||
expect(d3.select(this).text()).toBe(expected[i]); | ||
}); | ||
} | ||
|
||
labels.each(function(_, i) { | ||
expect(Plotly.d3.select(this).text()).toBe(expected[i]); | ||
}); | ||
}).then(done); | ||
it('should show the default selected values', function(done) { | ||
Plotly.plot(gd, mockCopy.data, mockCopy.layout) | ||
.then(_hover) | ||
.then(function() { | ||
assertLabel(['4', '5', '33.3%']); | ||
|
||
return Plotly.restyle(gd, 'text', [['A', 'B', 'C', 'D', 'E']]); | ||
}) | ||
.then(_hover) | ||
.then(function() { | ||
assertLabel(['4', 'E', '5', '33.3%']); | ||
|
||
return Plotly.restyle(gd, 'hovertext', [[ | ||
'Apple', 'Banana', 'Clementine', 'Dragon Fruit', 'Eggplant' | ||
]]); | ||
}) | ||
.then(_hover) | ||
.then(function() { | ||
assertLabel(['4', 'Eggplant', '5', '33.3%']); | ||
|
||
return Plotly.restyle(gd, 'hovertext', 'SUP'); | ||
}) | ||
.then(_hover) | ||
.then(function() { | ||
assertLabel(['4', 'SUP', '5', '33.3%']); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
it('should show the correct separators for values', function(done) { | ||
|
||
var expected = ['0', '12|345|678@91', '99@9%']; | ||
|
||
mockCopy.layout.separators = '@|'; | ||
mockCopy.data[0].values[0] = 12345678.912; | ||
mockCopy.data[0].values[1] = 10000; | ||
|
||
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() { | ||
|
||
mouseEvent('mouseover', 223, 143); | ||
|
||
var labels = Plotly.d3.selectAll('.hovertext .nums .line'); | ||
|
||
expect(labels[0].length).toBe(3); | ||
|
||
labels.each(function(_, i) { | ||
expect(Plotly.d3.select(this).text()).toBe(expected[i]); | ||
}); | ||
}).then(done); | ||
Plotly.plot(gd, mockCopy.data, mockCopy.layout) | ||
.then(_hover) | ||
.then(function() { | ||
assertLabel(['0', '12|345|678@91', '99@9%']); | ||
}) | ||
.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.
@alexcjohnson I just noticed that
text
for pie is declared as adata_array
whereas other trace types have it as astring
witharrayOk: true
. Was that on purpose? Or should we allow single-valuetext
input for pie traces?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.
That was on purpose - though probably never explicitly discussed. My rationale is that
text
is essentially thex
data for pies, and they would be meaningless without this being an array of data. Can you think of a counterexample?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 agree for the on-graph
textinfo: 'text'
part. But if someone wants to show the sametext
piece in all hover labels? But I guess after this PR,hovertext
will cover that case.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.
Oh sorry, that's
label
... I still don't see a good usage for a single-valuetext
but perhaps it would be better to define it consistently with other trace types anyway.