Skip to content

Commit 3f39792

Browse files
committed
implement layout.showarrow attribute
1 parent e2fd2bb commit 3f39792

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/components/fx/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
}),
2222
align: extendFlat({}, hoverLabelAttrs.align, {arrayOk: true}),
2323
namelength: extendFlat({}, hoverLabelAttrs.namelength, {arrayOk: true}),
24+
showarrow: extendFlat({}, hoverLabelAttrs.showarrow, {arrayOk: true}),
2425
editType: 'none'
2526
}
2627
};

src/components/fx/hover.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
913913

914914
if(!helpers.isUnifiedHover(hovermode)) {
915915
hoverAvoidOverlaps(hoverLabels, rotateLabels, fullLayout, hoverText.commonLabelBoundingBox);
916-
alignHoverText(hoverLabels, rotateLabels, fullLayout._invScaleX, fullLayout._invScaleY);
916+
alignHoverText(hoverLabels, rotateLabels, fullLayout._invScaleX, fullLayout._invScaleY, fullLayout.hoverlabel.showarrow);
917917
} // TODO: tagName hack is needed to appease geo.js's hack of using eventTarget=true
918918
// we should improve the "fx" API so other plots can use it without these hack.
919919
if(eventTarget && eventTarget.tagName) {
@@ -1903,7 +1903,7 @@ function getTextShiftX(hoverLabel) {
19031903
};
19041904
}
19051905

1906-
function alignHoverText(hoverLabels, rotateLabels, scaleX, scaleY) {
1906+
function alignHoverText(hoverLabels, rotateLabels, scaleX, scaleY, showArrow) {
19071907
var pX = function(x) { return x * scaleX; };
19081908
var pY = function(y) { return y * scaleY; };
19091909

@@ -1923,19 +1923,26 @@ function alignHoverText(hoverLabels, rotateLabels, scaleX, scaleY) {
19231923

19241924
var isMiddle = anchor === 'middle';
19251925

1926-
g.select('path')
1927-
.attr('d', isMiddle ?
1926+
var pathStr;
1927+
if(isMiddle) {
19281928
// middle aligned: rect centered on data
1929-
('M-' + pX(d.bx / 2 + d.tx2width / 2) + ',' + pY(offsetY - d.by / 2) +
1930-
'h' + pX(d.bx) + 'v' + pY(d.by) + 'h-' + pX(d.bx) + 'Z') :
1929+
pathStr = 'M-' + pX(d.bx / 2 + d.tx2width / 2) + ',' + pY(offsetY - d.by / 2) +
1930+
'h' + pX(d.bx) + 'v' + pY(d.by) + 'h-' + pX(d.bx) + 'Z';
1931+
} else if(showArrow !== false) {
19311932
// left or right aligned: side rect with arrow to data
1932-
('M0,0L' + pX(horzSign * HOVERARROWSIZE + offsetX) + ',' + pY(HOVERARROWSIZE + offsetY) +
1933-
'v' + pY(d.by / 2 - HOVERARROWSIZE) +
1934-
'h' + pX(horzSign * d.bx) +
1935-
'v-' + pY(d.by) +
1936-
'H' + pX(horzSign * HOVERARROWSIZE + offsetX) +
1937-
'V' + pY(offsetY - HOVERARROWSIZE) +
1938-
'Z'));
1933+
pathStr = 'M0,0L' + pX(horzSign * HOVERARROWSIZE + offsetX) + ',' + pY(HOVERARROWSIZE + offsetY) +
1934+
'v' + pY(d.by / 2 - HOVERARROWSIZE) +
1935+
'h' + pX(horzSign * d.bx) +
1936+
'v-' + pY(d.by) +
1937+
'H' + pX(horzSign * HOVERARROWSIZE + offsetX) +
1938+
'V' + pY(offsetY - HOVERARROWSIZE) +
1939+
'Z';
1940+
} else {
1941+
// left or right aligned: side rect without arrow
1942+
pathStr = 'M' + pX(horzSign * HOVERARROWSIZE + offsetX) + ',' + pY(offsetY - d.by / 2) +
1943+
'h' + pX(horzSign * d.bx) + 'v' + pY(d.by) + 'h' + pX(-horzSign * d.bx) + 'Z';
1944+
}
1945+
g.select('path').attr('d', pathStr);
19391946

19401947
var posX = offsetX + shiftX.textShiftX;
19411948
var posY = offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD;

src/components/fx/hoverlabel_defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts
3636
coerce('hoverlabel.bgcolor', opts.bgcolor);
3737
coerce('hoverlabel.bordercolor', opts.bordercolor);
3838
coerce('hoverlabel.namelength', opts.namelength);
39+
coerce('hoverlabel.showarrow', opts.showarrow);
3940
Lib.coerceFont(coerce, 'hoverlabel.font', opts.font);
4041
coerce('hoverlabel.align', opts.align);
4142
};

src/components/fx/layout_attributes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ module.exports = {
165165
'`namelength - 3` characters and add an ellipsis.'
166166
].join(' ')
167167
},
168+
showarrow: {
169+
valType: 'boolean',
170+
dflt: true,
171+
editType: 'none',
172+
description: [
173+
'Sets whether or not to show the hover label arrow/triangle',
174+
'pointing to the data point.'
175+
].join(' ')
176+
},
168177

169178
editType: 'none'
170179
},

0 commit comments

Comments
 (0)