Skip to content

Commit

Permalink
Fixed #6330, minor ticks were not applied outside major ticks on a lo…
Browse files Browse the repository at this point in the history
…garithmic axis.
  • Loading branch information
TorsteinHonsi committed Feb 6, 2017
1 parent b0ddd34 commit 9f0dc86
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
29 changes: 19 additions & 10 deletions js/parts/Axis.js
Expand Up @@ -727,23 +727,31 @@ H.Axis.prototype = {
minorTickInterval = axis.minorTickInterval,
minorTickPositions = [],
pos,
i,
pointRangePadding = axis.pointRangePadding || 0,
min = axis.min - pointRangePadding, // #1498
max = axis.max + pointRangePadding, // #1498
range = max - min,
len;
range = max - min;

// If minor ticks get too dense, they are hard to read, and may cause long running script. So we don't draw them.
if (range && range / minorTickInterval < axis.len / 3) { // #3875

if (axis.isLog) {
len = tickPositions.length;
for (i = 1; i < len; i++) {
minorTickPositions = minorTickPositions.concat(
axis.getLogTickPositions(minorTickInterval, tickPositions[i - 1], tickPositions[i], true)
);
}
// For each interval in the major ticks, compute the minor ticks
// separately.
each(this.paddedTicks, function (pos, i, paddedTicks) {
if (i) {
minorTickPositions.push.apply(
minorTickPositions,
axis.getLogTickPositions(
minorTickInterval,
paddedTicks[i - 1],
paddedTicks[i],
true
)
);
}
});

} else if (axis.isDatetimeAxis && options.minorTickInterval === 'auto') { // #1314
minorTickPositions = minorTickPositions.concat(
axis.getTimeTicks(
Expand Down Expand Up @@ -1300,7 +1308,8 @@ H.Axis.prototype = {

}

// reset min/max or remove extremes based on start/end on tick
// Reset min/max or remove extremes based on start/end on tick
this.paddedTicks = tickPositions.slice(0); // Used for logarithmic minor
this.trimTicks(tickPositions, startOnTick, endOnTick);
if (!this.isLinked) {

Expand Down
3 changes: 2 additions & 1 deletion js/parts/Utilities.js
Expand Up @@ -1533,9 +1533,10 @@ H.stop = function (el, prop) {
* @function #each
* @memberOf Highcharts
* @param {Array} arr - The array to iterate over.
* @param {Function} fn - The iterator callback. It passes two arguments:
* @param {Function} fn - The iterator callback. It passes three arguments:
* * item - The array item.
* * index - The item's index in the array.
* * arr - The array that each is being applied to.
* @param {Object} [ctx] The context.
*/
H.each = function (arr, fn, ctx) { // modern browsers
Expand Down
42 changes: 41 additions & 1 deletion samples/unit-tests/axis/type-logarithmic/demo.js
Expand Up @@ -45,4 +45,44 @@ QUnit.test('Minor ticks should not affect extremes (#6330)', function (assert) {
'Y axis max is bigger than data'
);

});
});

QUnit.test(
'Minor ticks should extend past major ticks (#6330)',
function (assert) {
var chart = Highcharts.chart('container', {
chart: {
width: 600,
height: 300
},

xAxis: {
type: 'logarithmic',
minorTickInterval: 'auto'
},

series: [{
data: [
[0.42, 1],
[1.7, 2]
]
}]
});

var gridLines = chart.container.querySelectorAll(
'.highcharts-grid-line'
);
var minorGridLines = chart.container.querySelectorAll(
'.highcharts-minor-grid-line'
);
assert.ok(
minorGridLines[0].getBBox().x < gridLines[0].getBBox().x,
'Minor grid lines outside major grid lines'
);
assert.ok(
minorGridLines[minorGridLines.length - 1].getBBox().x >
gridLines[gridLines.length - 1].getBBox().x,
'Minor grid lines outside major grid lines'
);
}
);

0 comments on commit 9f0dc86

Please sign in to comment.