-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ArrayOk hoverinfo fixups #2055
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
ArrayOk hoverinfo fixups #2055
Changes from 11 commits
4cf489e
90e2de1
c89c895
b24759d
0a77239
85d7061
bc8294d
b637179
294714b
2fe641d
7f2604a
6a44a9a
3931273
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
'use strict'; | ||
|
||
var Lib = require('../../lib'); | ||
var Axes = require('../../plots/cartesian/axes'); | ||
var attributes = require('./attributes'); | ||
|
||
|
@@ -53,17 +54,17 @@ module.exports = function hoverPoints(pointData, xval, yval) { | |
}; | ||
|
||
function makeHoverInfo(pointData, trace, pt, axis) { | ||
var hoverinfo = trace.hoverinfo; | ||
var hoverinfo = pt.hi || trace.hoverinfo; | ||
|
||
var parts = (hoverinfo === 'all') ? | ||
attributes.hoverinfo.flags : | ||
hoverinfo.split('+'); | ||
|
||
var hasName = (parts.indexOf('name') !== -1), | ||
hasLocation = (parts.indexOf('location') !== -1), | ||
hasZ = (parts.indexOf('z') !== -1), | ||
hasText = (parts.indexOf('text') !== -1), | ||
hasIdAsNameLabel = !hasName && hasLocation; | ||
var hasName = (parts.indexOf('name') !== -1); | ||
var hasLocation = (parts.indexOf('location') !== -1); | ||
var hasZ = (parts.indexOf('z') !== -1); | ||
var hasText = (parts.indexOf('text') !== -1); | ||
var hasIdAsNameLabel = !hasName && hasLocation; | ||
|
||
var text = []; | ||
|
||
|
@@ -79,7 +80,10 @@ function makeHoverInfo(pointData, trace, pt, axis) { | |
} | ||
|
||
if(hasZ) text.push(formatter(pt.z)); | ||
if(hasText) text.push(pt.tx); | ||
if(hasText) { | ||
var tx = Lib.extractOption(pt, trace, 'tx', 'text'); | ||
if(tx && tx !== '') text.push(tx); | ||
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 catch. Strictly speaking, I think this should be: if(tx !== undefined && tx !== '') {
text.push(tx);
} as To make this easier to maintain (and remember 🙂 ), I'm thinking either
{
text: 'on-chart text',
hovertext: ''
} would use
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. Here's what I came up with 3931273 I made 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. Yep, I like it. There are some edge cases this makes a little weird - eg trying to make one point have text but no hovertext, while all the others have both - but there are ways to get what you want (in that example using |
||
} | ||
|
||
pointData.extraText = text.join('<br>'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Lib = require('../../lib'); | ||
|
||
/** Fill hover 'pointData' container with 'correct' hover text value | ||
* | ||
* - If trace hoverinfo contains a 'text' flag and hovertext is not set, | ||
* the text elements will be seen in the hover labels. | ||
* | ||
* - If trace hoverinfo contains a 'text' flag and hovertext is set, | ||
* hovertext takes precedence over text | ||
* i.e. the hoverinfo elements will be seen in the hover labels | ||
* | ||
* @param {object} calcPt | ||
* @param {object} trace | ||
* @param {object || array} contOut (mutated here) | ||
*/ | ||
module.exports = function fillHoverText(calcPt, trace, contOut) { | ||
var fill = Array.isArray(contOut) ? | ||
function(v) { contOut.push(v); } : | ||
function(v) { contOut.text = v; }; | ||
|
||
var htx = Lib.extractOption(calcPt, trace, 'htx', 'hovertext'); | ||
if(htx && htx !== '') return fill(htx); | ||
|
||
var tx = Lib.extractOption(calcPt, trace, 'tx', 'text'); | ||
if(tx && tx !== '') return fill(tx); | ||
}; | ||
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! 🌴 Does this really belong in 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. I have no strong opinion here. This routine felt similar to https://github.com/plotly/plotly.js/blob/master/src/traces/scatter/arrays_to_calcdata.js that's why I put it in 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. That's fine, we certainly have a long history of traces pulling from each other, particularly from scatter, and there is something nice about it being in the |
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, I like it. Thanks for accepting
0
.meh, it's a very specific concept that we probably don't want to go into any more detail with in the name. Seems fine to me.
It definitely belongs next to
castOption
but yeah, if we make acommon/
that might be more appropriate for these.Also a style question: I just noticed all over this file we start the docs immediately after
/**
, I thought the convention was to leave that first line blank and start on the next line?Uh oh!
There was an error while loading. Please reload this page.
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.
from http://usejsdoc.org/howto-commonjs-modules.html
So, I think both are acceptable.
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.
perhaps overly pedantic, but I read that as
/** Single-line description */
or