Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/19078-proximate-legend-enabling #19153

Merged
merged 3 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions samples/unit-tests/legend/layout/demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
QUnit.test('Legend layout', function (assert) {
var chart = Highcharts.chart('container', {
legend: {
enabled: false,
layout: 'proximate',
align: 'right'
},
Expand Down Expand Up @@ -34,6 +35,13 @@ QUnit.test('Legend layout', function (assert) {
]
});

// We should be able to update the legend.enabled property, #19078.
chart.update({
legend: {
enabled: true
}
});

chart.series.forEach(function (s) {
var y = s.points[2].plotY || s.yAxis.height;

Expand Down Expand Up @@ -102,6 +110,7 @@ QUnit.test('Proximate layout and dataGrouping', assert => {
animation: false
},
legend: {
enabled: true,
align: 'right',
layout: 'proximate'
},
Expand Down Expand Up @@ -135,6 +144,19 @@ QUnit.test('Proximate layout and dataGrouping', assert => {
]
});

// These updates should not cause an error, #19028.
chart.update({
legend: {
enabled: false
}
});

chart.update({
legend: {
enabled: true
}
});

chart.series[1].hide();

// Avoid using strict position as it may vary between browsers
Expand Down
26 changes: 10 additions & 16 deletions ts/Core/Legend/Legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ class Legend {
* Legend options.
*/
public init(chart: Chart, options: LegendOptions): void {

/**
* Chart of this legend.
*
Expand All @@ -248,28 +247,23 @@ class Legend {
this.setOptions(options);

if (options.enabled) {

// Render it
this.render();

// move checkboxes
// Move checkboxes
addEvent(this.chart, 'endResize', function (): void {
this.legend.positionCheckboxes();
});

// On Legend.init and Legend.update, make sure that proximate layout
// events are either added or removed (#18362).
addEvent(
this.chart,
'render',
(): void => {
if (this.proximate) {
this.proximatePositions();
this.positionItems();
}
}
);
}

// On Legend.init and Legend.update, make sure that proximate layout
// events are either added or removed (#18362).
addEvent(this.chart, 'render', (): void => {
if (this.options.enabled && this.proximate) {
this.proximatePositions();
this.positionItems();
}
});
}

/**
Expand Down