UNPKG

plotly.js

Version:

The open source javascript graphing library that powers plotly

67 lines (52 loc) 1.79 kB
/** * Copyright 2012-2020, 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'); var Axes = require('../../plots/cartesian/axes'); var scatterMapboxHoverPoints = require('../scattermapbox/hover'); module.exports = function hoverPoints(pointData, xval, yval) { var pts = scatterMapboxHoverPoints(pointData, xval, yval); if(!pts) return; var newPointData = pts[0]; var cd = newPointData.cd; var trace = cd[0].trace; var di = cd[newPointData.index]; // let Fx.hover pick the color delete newPointData.color; if('z' in di) { var ax = newPointData.subplot.mockAxis; newPointData.z = di.z; newPointData.zLabel = Axes.tickText(ax, ax.c2l(di.z), 'hover').text; } newPointData.extraText = getExtraText(trace, di, cd[0].t.labels); return [newPointData]; }; function getExtraText(trace, di, labels) { if(trace.hovertemplate) return; var hoverinfo = di.hi || trace.hoverinfo; var parts = hoverinfo.split('+'); var isAll = parts.indexOf('all') !== -1; var hasLon = parts.indexOf('lon') !== -1; var hasLat = parts.indexOf('lat') !== -1; var lonlat = di.lonlat; var text = []; function format(v) { return v + '\u00B0'; } if(isAll || (hasLon && hasLat)) { text.push('(' + format(lonlat[0]) + ', ' + format(lonlat[1]) + ')'); } else if(hasLon) { text.push(labels.lon + format(lonlat[0])); } else if(hasLat) { text.push(labels.lat + format(lonlat[1])); } if(isAll || parts.indexOf('text') !== -1) { Lib.fillText(di, trace, text); } return text.join('<br>'); }