Skip to content

Commit

Permalink
Fixed #7339, removed doubled axis ticks in case of too dense ticks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper Madej committed Nov 6, 2017
1 parent f458c1a commit 1d4ef93
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions js/parts/Axis.js
Expand Up @@ -2299,6 +2299,10 @@ H.extend(Axis.prototype, /** @lends Highcharts.Axis.prototype */{
// Too dense ticks, keep only the first and last (#4477)
if (tickPositions.length > this.len) {
tickPositions = [tickPositions[0], tickPositions.pop()];
// Reduce doubled value (#7339)
if (tickPositions[0] === tickPositions[1]) {
tickPositions.length = 1;
}
}

this.tickPositions = tickPositions;
Expand Down
4 changes: 3 additions & 1 deletion js/parts/Chart.js
Expand Up @@ -1708,7 +1708,9 @@ extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {

// Record preliminary dimensions for later comparison
tempWidth = chart.plotWidth;
tempHeight = chart.plotHeight = chart.plotHeight - 21; // 21 is the most common correction for X axis labels
// 21 is the most common correction for X axis labels
// use Math.max to prevent negative plotHeight
tempHeight = chart.plotHeight = Math.max(chart.plotHeight - 21, 0);

// Get margins by pre-rendering axes
each(axes, function (axis) {
Expand Down
31 changes: 31 additions & 0 deletions samples/unit-tests/axis/ticks/demo.js
Expand Up @@ -27,6 +27,37 @@ QUnit.test('Ticks for a single point.', function (assert) {
-0.3,
'single tick and increased extremes for a single point'
);

// Must be on init - redraw was fixing the issue
chart = Highcharts.chart('container', {
series: [{
type: 'bar',
data: [10]
}],
chart: {
height: 30,
inverted: true,
spacing: [6, 10, 6, 10]
},
legend: {
enabled: false
},
title: {
text: ''
},
yAxis: [{
visible: false
}],
xAxis: [{
visible: false
}]
});

assert.strictEqual(
chart.xAxis[0].tickPositions.length,
1,
'no doulbed tick for a small plot height (#7339)'
);
});

QUnit.test(
Expand Down

0 comments on commit 1d4ef93

Please sign in to comment.