Skip to content

Commit

Permalink
Fixed #7260, a regression causing the legend box not being resized wh…
Browse files Browse the repository at this point in the history
…en dynamically adding and removing series.
  • Loading branch information
TorsteinHonsi committed Oct 16, 2017
1 parent b399225 commit 4e8367e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion js/parts/Legend.js
Expand Up @@ -688,7 +688,7 @@ Highcharts.Legend.prototype = {

if (legendWidth > 0 && legendHeight > 0) {
box[box.isNew ? 'attr' : 'animate'](
box.crisp({
box.crisp.call({}, { // #7260
x: 0,
y: 0,
width: legendWidth,
Expand Down
13 changes: 7 additions & 6 deletions samples/unit-tests/legend/checkbox/demo.js
Expand Up @@ -3,7 +3,8 @@ QUnit.test(
function (assert) {
var chart = Highcharts.chart('container', {
chart: {
width: 600
width: 600,
animation: false
},
legend: {
borderWidth: 1,
Expand All @@ -23,15 +24,15 @@ QUnit.test(
});

assert.strictEqual(
chart.legend.box.width > 340 && chart.legend.box.width < 360,
chart.legend.box.getBBox().width > 340 && chart.legend.box.getBBox().width < 360,
true,
'Legend box contains checkboxes - 2 items'
);

chart.series[0].remove();

assert.strictEqual(
chart.legend.box.width > 170 && chart.legend.box.width < 190,
chart.legend.box.getBBox().width > 170 && chart.legend.box.getBBox().width < 190,
true,
'Legend box contains checkbox - 1 item'
);
Expand All @@ -45,7 +46,7 @@ QUnit.test(
});

assert.strictEqual(
chart.legend.box.width > 70 && chart.legend.box.width < 90,
chart.legend.box.getBBox().width > 70 && chart.legend.box.getBBox().width < 90,
true,
'Legend box without checkboxes is of proper size - 1 item'
);
Expand All @@ -61,7 +62,7 @@ QUnit.test(
});

assert.strictEqual(
chart.legend.box.width > 370 && chart.legend.box.width < 390,
chart.legend.box.getBBox().width > 370 && chart.legend.box.getBBox().width < 395,
true,
'Legend box without checkboxes is of proper size - 4 items'
);
Expand All @@ -75,7 +76,7 @@ QUnit.test(
});

assert.strictEqual(
chart.legend.box.width > 510 && chart.legend.box.width < 530,
chart.legend.box.getBBox().width > 510 && chart.legend.box.getBBox().width < 535,
true,
'Legend box contains checkboxes - 4 items'
);
Expand Down
33 changes: 33 additions & 0 deletions samples/unit-tests/legend/legend-general/demo.js
Expand Up @@ -63,3 +63,36 @@ QUnit.test('Hidden legend bogus SVG (#6769', function (assert) {
);

});

QUnit.test('Legend resize', function (assert) {
var chart = Highcharts.chart('container', {
chart: {
width: 600,
animation: {
duration: 1
}
},
legend: {
borderWidth: 2
},
series: [{
data: [1, 3, 2, 4]
}]
});
var done = assert.async();

var legendWidth = chart.legend.box.getBBox().width;

chart.addSeries({
data: [2, 4, 3, 5]
});

setTimeout(function () {
assert.notEqual(
chart.legend.box.getBBox().width,
legendWidth,
'Legend width has changed (#7260)'
);
done();
}, 50);
});

0 comments on commit 4e8367e

Please sign in to comment.