Skip to content

Commit ad2ad74

Browse files
committed
add space around (x|y)other label only when there is a differing position
1 parent 3fa20fb commit ad2ad74

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ function templateFormatString(string, labels, d3locale) {
11041104
}
11051105

11061106
if(isOther) {
1107-
value = '(' + value + ')';
1107+
value = ' (' + value + ') ';
11081108
}
11091109

11101110
return value;

test/jasmine/tests/hover_label_test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -4834,14 +4834,14 @@ describe('hovermode: (x|y)unified', function() {
48344834
it('should format differing position using *xother* `hovertemplate` and in respect to `xhoverformat`', function(done) {
48354835
Plotly.newPlot(gd, [{
48364836
type: 'bar',
4837-
hovertemplate: '%{y:.1f} %{xother:.2f}',
4837+
hovertemplate: '%{y:.1f}%{xother:.2f}',
48384838
x: [0, 1.001],
48394839
y: [1.001, 2.001]
48404840
}, {
48414841
x: [0, 0.749],
48424842
y: [1.999, 0.999]
48434843
}, {
4844-
hovertemplate: '%{y:.1f} %{xother}',
4844+
hovertemplate: '%{y:.1f}%{xother}',
48454845
xhoverformat: '.1f',
48464846
x: [0, 1.251],
48474847
y: [2.001, 3.001]
@@ -4861,25 +4861,25 @@ describe('hovermode: (x|y)unified', function() {
48614861
.then(function() {
48624862
_hover(gd, { xpx: 100, ypx: 200 });
48634863
assertLabel({title: '0', items: [
4864-
'trace 0 : 1.0 ',
4864+
'trace 0 : 1.0',
48654865
'trace 1 : 1.999',
4866-
'trace 2 : 2.0 (0.0)'
4866+
'trace 2 : 2.0 (0.0) '
48674867
]});
48684868
})
48694869
.then(function() {
48704870
_hover(gd, { xpx: 250, ypx: 200 });
48714871
assertLabel({title: '0.749', items: [
4872-
'trace 0 : 2.0 (1.00)',
4872+
'trace 0 : 2.0 (1.00) ',
48734873
'trace 1 : 0.999',
4874-
'trace 2 : 3.0 (1.3)'
4874+
'trace 2 : 3.0 (1.3) '
48754875
]});
48764876
})
48774877
.then(function() {
48784878
_hover(gd, { xpx: 350, ypx: 200 });
48794879
assertLabel({title: '1.3', items: [
4880-
'trace 0 : 2.0 (1.00)',
4880+
'trace 0 : 2.0 (1.00) ',
48814881
'trace 1 : (0.749, 0.999)',
4882-
'trace 2 : 3.0 '
4882+
'trace 2 : 3.0'
48834883
]});
48844884
})
48854885
.then(done, done.fail);

0 commit comments

Comments
 (0)