Skip to content

Commit

Permalink
Don't show y-axis endpoints for horizontal bar charts (#1757)
Browse files Browse the repository at this point in the history
* Don't show endpoints for horizontal bar charts

* Add test
  • Loading branch information
mure committed May 6, 2020
1 parent 45516c4 commit 20355f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/jquery.flot.js
Expand Up @@ -1761,7 +1761,7 @@ Licensed under the MIT license.
}
if (axis.options.showTickLabels === 'all') {
var associatedSeries = series.filter(function(s) {
return s.xaxis === axis;
return s.bars.horizontal ? s.yaxis === axis : s.xaxis === axis;
}),
notAllBarSeries = associatedSeries.some(function(s) {
return !s.bars.show;
Expand Down
31 changes: 31 additions & 0 deletions tests/jquery.flot.Test.js
Expand Up @@ -951,6 +951,37 @@ describe('flot', function() {
expect(yaxis.max).toEqual(ticks[ticks.length - 1].v);
});

it('should not show y axis endpoints for horizontal bars with showTickLabels = all', function() {
var plot = $.plot(placeholder, [[[1, -3], [15, 30], [7, 20], [2, 5]]], {
xaxis: {
autoScale: 'exact',
showTickLabels: 'all'
},
yaxis: {
autoScale: 'exact',
showTickLabels: 'all'
},
series: {
bars: {
lineWidth: 1,
show: true,
fillColor: 'blue',
barWidth: 0.8,
horizontal: true
}
}
});

var xaxis = plot.getXAxes()[0],
yaxis = plot.getYAxes()[0],
ticks = yaxis.ticks;
expect(yaxis.min).not.toEqual(ticks[0].v);
expect(yaxis.max).not.toEqual(ticks[ticks.length - 1].v);
ticks = xaxis.ticks;
expect(xaxis.min).toEqual(ticks[0].v);
expect(xaxis.max).toEqual(ticks[ticks.length - 1].v);
});

it('should show endpoints for multiple series type where showTickLabels = all', function() {
var plot = $.plot(placeholder, [{
data: [[-3, 2], [20, 15], [4, 5]],
Expand Down

0 comments on commit 20355f4

Please sign in to comment.