MCPcopy Index your code
hub / github.com/plotly/plotly.js / createHoverText

Function createHoverText

src/components/fx/hover.js:992–1673  ·  view source on GitHub ↗
(hoverData, opts)

Source from the content-addressed store, hash-verified

990var EXTRA_STRING_REGEX = /<extra>([\s\S]*)<\/extra>/;
991
992function createHoverText(hoverData, opts) {
993 var gd = opts.gd;
994 var fullLayout = gd._fullLayout;
995 var hovermode = opts.hovermode;
996 var rotateLabels = opts.rotateLabels;
997 var bgColor = opts.bgColor;
998 var container = opts.container;
999 var outerContainer = opts.outerContainer;
1000 var commonLabelOpts = opts.commonLabelOpts || {};
1001 // Early exit if no labels are drawn
1002 if (hoverData.length === 0) return [[]];
1003
1004 // opts.fontFamily/Size are used for the common label
1005 // and as defaults for each hover label, though the individual labels
1006 // can override this.
1007 var fontFamily = opts.fontFamily || constants.HOVERFONT;
1008 var fontSize = opts.fontSize || constants.HOVERFONTSIZE;
1009 var fontWeight = opts.fontWeight || fullLayout.font.weight;
1010 var fontStyle = opts.fontStyle || fullLayout.font.style;
1011 var fontVariant = opts.fontVariant || fullLayout.font.variant;
1012 var fontTextcase = opts.fontTextcase || fullLayout.font.textcase;
1013 var fontLineposition = opts.fontLineposition || fullLayout.font.lineposition;
1014 var fontShadow = opts.fontShadow || fullLayout.font.shadow;
1015
1016 var c0 = hoverData[0];
1017 var xa = c0.xa;
1018 var ya = c0.ya;
1019 var axLetter = hovermode.charAt(0);
1020 var axLabel = axLetter + 'Label';
1021 var t0 = c0[axLabel];
1022
1023 // search in array for the label
1024 if (t0 === undefined && xa.type === 'multicategory') {
1025 for (var q = 0; q < hoverData.length; q++) {
1026 t0 = hoverData[q][axLabel];
1027 if (t0 !== undefined) break;
1028 }
1029 }
1030
1031 var outerContainerBB = getBoundingClientRect(gd, outerContainer);
1032 var outerTop = outerContainerBB.top;
1033 var outerWidth = outerContainerBB.width;
1034 var outerHeight = outerContainerBB.height;
1035
1036 // show the common label, if any, on the axis
1037 // never show a common label in array mode,
1038 // even if sometimes there could be one
1039 var showCommonLabel =
1040 t0 !== undefined && c0.distance <= opts.hoverdistance && (hovermode === 'x' || hovermode === 'y');
1041
1042 // all hover traces hoverinfo must contain the hovermode
1043 // to have common labels
1044 if (showCommonLabel) {
1045 var allHaveZ = true;
1046 var i, traceHoverinfo;
1047 for (i = 0; i < hoverData.length; i++) {
1048 if (allHaveZ && hoverData[i].zLabel === undefined) allHaveZ = false;
1049

Callers 2

hover.jsFile · 0.85
_hoverFunction · 0.85

Calls 3

getBoundingClientRectFunction · 0.85
getHoverLabelTextFunction · 0.85
hoverDataKeyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…