-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathfill_hover_text.js
41 lines (35 loc) · 1.24 KB
/
fill_hover_text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Copyright 2012-2019, 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;
}