-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathhover.js
52 lines (38 loc) · 1.64 KB
/
hover.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
42
43
44
45
46
47
48
49
50
51
52
/**
* Copyright 2012-2016, 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 scatterHover = require('../scatter/hover');
var Axes = require('../../plots/cartesian/axes');
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
var scatterPointData = scatterHover(pointData, xval, yval, hovermode);
if(!scatterPointData || scatterPointData[0].index === false) return;
// if hovering on a fill, we don't show any point data so the label is
// unchanged from what scatter gives us.
if(scatterPointData[0].index === undefined) return scatterPointData;
var newPointData = scatterPointData[0],
cdi = newPointData.cd[newPointData.index];
newPointData.a = cdi.a;
newPointData.b = cdi.b;
newPointData.c = cdi.c;
newPointData.xLabelVal = undefined;
newPointData.yLabelVal = undefined;
// TODO: nice formatting, and label by axis title, for a, b, and c?
var trace = newPointData.trace,
ternary = trace._ternary,
hoverinfo = trace.hoverinfo.split('+'),
text = [];
function textPart(ax, val) {
text.push(ax._hovertitle + ': ' + Axes.tickText(ax, val, 'hover').text);
}
if(hoverinfo.indexOf('all') !== -1) hoverinfo = ['a', 'b', 'c'];
if(hoverinfo.indexOf('a') !== -1) textPart(ternary.aaxis, cdi.a);
if(hoverinfo.indexOf('b') !== -1) textPart(ternary.baxis, cdi.b);
if(hoverinfo.indexOf('c') !== -1) textPart(ternary.caxis, cdi.c);
newPointData.extraText = text.join('<br>');
return scatterPointData;
};