Skip to content

Commit

Permalink
Invalidate bar label text measurer caches (#3546)
Browse files Browse the repository at this point in the history
A bug exists where bar chart labels render incorrectly
when the chart is first rendered into a invalid element,
such as one with zero size or display: none style.

Since text measurement is cached, these incorrect measurements
would perist and the labels would remain broken even
if the element becomes valid for rendering.

This change correctly invalidates all the bar chart
label measurer caches, and bar labels will then
render correctly when the element becomes valid.
  • Loading branch information
themadcreator authored Jun 1, 2020
1 parent f892066 commit d0fa461
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ export class Legend extends Component {
}

public invalidateCache() {
super.invalidateCache();
this._measurer.reset();
}
}
5 changes: 5 additions & 0 deletions src/plots/barPlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@ export class Bar<X, Y> extends XYPlot<X, Y> {
0, 0, plotWidth, plotHeight,
);
}

public invalidateCache() {
super.invalidateCache();
this.datasets().forEach((dataset) => this._labelConfig.get(dataset).measurer.reset());
}
}

/**
Expand Down

1 comment on commit d0fa461

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalidate bar label text measurer caches (#3546)

Demo: quicktests | fiddle

Please sign in to comment.