-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathhover.js
64 lines (49 loc) · 1.93 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
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright 2012-2018, 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');
var Lib = require('../../lib');
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
var scatterPointData = scatterHover(pointData, xval, yval, hovermode);
if(!scatterPointData || scatterPointData[0].index === false) return;
var newPointData = scatterPointData[0];
// hovering on fill case
if(newPointData.index === undefined) {
return scatterPointData;
}
var subplot = pointData.subplot;
var cdi = newPointData.cd[newPointData.index];
if(!subplot.isPtWithinSector(cdi)) return;
newPointData.xLabelVal = undefined;
newPointData.yLabelVal = undefined;
var trace = newPointData.trace;
var radialAxis = subplot.radialAxis;
var angularAxis = subplot.angularAxis;
var hoverinfo = cdi.hi || trace.hoverinfo;
var parts = hoverinfo.split('+');
var text = [];
var rad = angularAxis._c2rad(cdi.theta, trace.thetaunit);
radialAxis._hovertitle = 'r';
angularAxis._hovertitle = 'θ';
// show theta value in unit of angular axis
var theta;
if(angularAxis.type === 'linear' && trace.thetaunit !== angularAxis.thetaunit) {
theta = angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(rad) : rad;
} else {
theta = cdi.theta;
}
function textPart(ax, val) {
text.push(ax._hovertitle + ': ' + Axes.tickText(ax, val, 'hover').text);
}
if(parts.indexOf('all') !== -1) parts = ['r', 'theta'];
if(parts.indexOf('r') !== -1) textPart(radialAxis, radialAxis.c2r(cdi.r));
if(parts.indexOf('theta') !== -1) textPart(angularAxis, theta);
newPointData.extraText = text.join('<br>');
return scatterPointData;
};