-
-
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 9 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 |
---|---|---|
|
@@ -53,17 +53,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 +79,14 @@ function makeHoverInfo(pointData, trace, pt, axis) { | |
} | ||
|
||
if(hasZ) text.push(formatter(pt.z)); | ||
if(hasText) text.push(pt.tx); | ||
if(hasText) { | ||
var tx; | ||
|
||
if(pt.tx) tx = pt.tx; | ||
else if(trace.text) tx = trace.text; | ||
|
||
if(!Array.isArray(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. nice careful logic - This seems like a bit of logic that's repeated a bunch - and is probably done wrong in some places where it's not repeated... worth abstracting? 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. Worth it for sure. Shouldn't be too bad. 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. (the hardest part will be to figure out how to call this new function) 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. Ooops I forget to update |
||
} | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,18 +46,19 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { | |
newPointData.yLabelVal = undefined; | ||
// TODO: nice formatting, and label by axis title, for a, b, and c? | ||
|
||
var trace = newPointData.trace, | ||
carpet = trace._carpet, | ||
hoverinfo = trace.hoverinfo.split('+'), | ||
text = []; | ||
var trace = newPointData.trace; | ||
var carpet = trace._carpet; | ||
var hoverinfo = cdi.hi || trace.hoverinfo; | ||
var parts = hoverinfo.split('+'); | ||
var text = []; | ||
|
||
function textPart(ax, val) { | ||
text.push(((ax.labelprefix && ax.labelprefix.length > 0) ? ax.labelprefix : (ax._hovertitle + ': ')) + val.toFixed(3) + ax.labelsuffix); | ||
} | ||
|
||
if(hoverinfo.indexOf('all') !== -1) hoverinfo = ['a', 'b']; | ||
if(hoverinfo.indexOf('a') !== -1) textPart(carpet.aaxis, cdi.a); | ||
if(hoverinfo.indexOf('b') !== -1) textPart(carpet.baxis, cdi.b); | ||
if(parts.indexOf('all') !== -1) parts = ['a', 'b']; | ||
if(parts.indexOf('a') !== -1) textPart(carpet.aaxis, cdi.a); | ||
if(parts.indexOf('b') !== -1) textPart(carpet.baxis, cdi.b); | ||
|
||
var ij = carpet.ab2ij([cdi.a, cdi.b]); | ||
var i0 = Math.floor(ij[0]); | ||
|
@@ -67,7 +68,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { | |
var tj = ij[1] - j0; | ||
|
||
var xy = carpet.evalxy([], i0, j0, ti, tj); | ||
text.push('y: ' + xy[1].toFixed(3)); | ||
text.push('y = ' + xy[1].toFixed(3)); | ||
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. cc @rreusser unless that 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. Most other places (heatmap/contour, 3d, ternary) we 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. Good catch. Thank you. That seems correct. 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. Oh. Haha, my mistake then. Perhaps it's the 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. Sorry, to be less vague, 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 2fe641d |
||
|
||
newPointData.extraText = text.join('<br>'); | ||
|
||
|
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