diff --git a/js/parts/Legend.js b/js/parts/Legend.js index 068b284e86d..518265936ce 100644 --- a/js/parts/Legend.js +++ b/js/parts/Legend.js @@ -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, diff --git a/samples/unit-tests/legend/checkbox/demo.js b/samples/unit-tests/legend/checkbox/demo.js index 0e49673cc0a..ddeb24029ff 100644 --- a/samples/unit-tests/legend/checkbox/demo.js +++ b/samples/unit-tests/legend/checkbox/demo.js @@ -3,7 +3,8 @@ QUnit.test( function (assert) { var chart = Highcharts.chart('container', { chart: { - width: 600 + width: 600, + animation: false }, legend: { borderWidth: 1, @@ -23,7 +24,7 @@ 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' ); @@ -31,7 +32,7 @@ QUnit.test( 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' ); @@ -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' ); @@ -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' ); @@ -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' ); diff --git a/samples/unit-tests/legend/legend-general/demo.js b/samples/unit-tests/legend/legend-general/demo.js index d7fc02324b5..848d5176db7 100644 --- a/samples/unit-tests/legend/legend-general/demo.js +++ b/samples/unit-tests/legend/legend-general/demo.js @@ -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); +}); \ No newline at end of file