Skip to content

Commit

Permalink
add space around (x|y)other label only when there is a differing posi…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
archmoj committed May 31, 2021
1 parent 3fa20fb commit ad2ad74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(isOther) {
value = '(' + value + ')';
value = ' (' + value + ') ';
}

return value;
Expand Down
16 changes: 8 additions & 8 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4834,14 +4834,14 @@ describe('hovermode: (x|y)unified', function() {
it('should format differing position using *xother* `hovertemplate` and in respect to `xhoverformat`', function(done) {
Plotly.newPlot(gd, [{
type: 'bar',
hovertemplate: '%{y:.1f} %{xother:.2f}',
hovertemplate: '%{y:.1f}%{xother:.2f}',
x: [0, 1.001],
y: [1.001, 2.001]
}, {
x: [0, 0.749],
y: [1.999, 0.999]
}, {
hovertemplate: '%{y:.1f} %{xother}',
hovertemplate: '%{y:.1f}%{xother}',
xhoverformat: '.1f',
x: [0, 1.251],
y: [2.001, 3.001]
Expand All @@ -4861,25 +4861,25 @@ describe('hovermode: (x|y)unified', function() {
.then(function() {
_hover(gd, { xpx: 100, ypx: 200 });
assertLabel({title: '0', items: [
'trace 0 : 1.0 ',
'trace 0 : 1.0',
'trace 1 : 1.999',
'trace 2 : 2.0 (0.0)'
'trace 2 : 2.0 (0.0) '
]});
})
.then(function() {
_hover(gd, { xpx: 250, ypx: 200 });
assertLabel({title: '0.749', items: [
'trace 0 : 2.0 (1.00)',
'trace 0 : 2.0 (1.00) ',
'trace 1 : 0.999',
'trace 2 : 3.0 (1.3)'
'trace 2 : 3.0 (1.3) '
]});
})
.then(function() {
_hover(gd, { xpx: 350, ypx: 200 });
assertLabel({title: '1.3', items: [
'trace 0 : 2.0 (1.00)',
'trace 0 : 2.0 (1.00) ',
'trace 1 : (0.749, 0.999)',
'trace 2 : 3.0 '
'trace 2 : 3.0'
]});
})
.then(done, done.fail);
Expand Down

0 comments on commit ad2ad74

Please sign in to comment.