-
-
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 all 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 |
---|---|---|
|
@@ -437,6 +437,26 @@ lib.castOption = function(trace, ptNumber, astr, fn) { | |
} | ||
}; | ||
|
||
/** Extract option from calcdata item, correctly falling back to | ||
* trace value if not found. | ||
* | ||
* @param {object} calcPt : calcdata[i][j] item | ||
* @param {object} trace : (full) trace object | ||
* @param {string} calcKey : calcdata key | ||
* @param {string} traceKey : aka trace attribute string | ||
* @return {any} | ||
*/ | ||
lib.extractOption = function(calcPt, trace, calcKey, traceKey) { | ||
if(calcKey in calcPt) return calcPt[calcKey]; | ||
|
||
// fallback to trace value, | ||
// must check if value isn't itself an array | ||
// which means the trace attribute has a corresponding | ||
// calcdata key, but its value is falsy | ||
var traceVal = lib.nestedProperty(trace, traceKey).get(); | ||
if(!Array.isArray(traceVal)) return traceVal; | ||
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, I like it. Thanks for accepting
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 Also a style question: I just noticed all over this file we start the docs immediately after 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.
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 commentThe reason will be displayed to describe this comment to others. Learn more. perhaps overly pedantic, but I read that as
|
||
}; | ||
|
||
/** Returns target as set by 'target' transform attribute | ||
* | ||
* @param {object} trace : full trace object | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* 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(isValid(htx)) return fill(htx); | ||
|
||
var tx = Lib.extractOption(calcPt, trace, 'tx', 'text'); | ||
if(isValid(tx)) return fill(tx); | ||
}; | ||
|
||
// accept all truthy values and 0 (which gets cast to '0' in the hover labels) | ||
function isValid(v) { | ||
return v || v === 0; | ||
} |
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.
Caught another bug.
dragmode: 'pan'
is broken on http://rickyreusser.com/plotly-mock-viewer/#text_chart_arraysThis fixes it:
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.
ha, good catch! 🎉