From 20355f401f57c125cd46a8b29b1b6554cdfdb941 Mon Sep 17 00:00:00 2001 From: mure Date: Wed, 6 May 2020 16:27:34 -0500 Subject: [PATCH] Don't show y-axis endpoints for horizontal bar charts (#1757) * Don't show endpoints for horizontal bar charts * Add test --- source/jquery.flot.js | 2 +- tests/jquery.flot.Test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/source/jquery.flot.js b/source/jquery.flot.js index 7055ba64..6caedadf 100644 --- a/source/jquery.flot.js +++ b/source/jquery.flot.js @@ -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; diff --git a/tests/jquery.flot.Test.js b/tests/jquery.flot.Test.js index 150e5eb3..4d8ea396 100644 --- a/tests/jquery.flot.Test.js +++ b/tests/jquery.flot.Test.js @@ -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]],