Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Refactor Legend Implementation for V5

Open etimberg opened this issue 3 years ago • 2 comments

The v3 legend implementation is largely carried over from v2 and needs a refactor to match the scriptable options introduced in v3 while at the same time resolving long standing pain points in the code. This ticket is to track that refactor, but since this will be a breaking change it will not be possible to introduce this until v4.

State Changes

  • The legend items & hitboxes state should be combined into a single object

Option Changes

  • generateLabels should not be responsible for determining the item styles. Should consider renaming to generate
  • A legend context should be created for scriptable options
  • Disabled styling should be a property of the scriptable context

Code Changes

  • All of the RTL handling should be moved from the draw method to the fit method
  • The drawing should be a simple loop over the items to draw based on pre-computed properties

etimberg avatar Jul 01 '21 16:07 etimberg

Related #5564, #4438

etimberg avatar Jul 01 '21 16:07 etimberg

This is exactly how I do that in the iOS Charts framework. Compute everything upfront, including multiline handling, rotations etc.

danielgindi avatar Jul 05 '21 06:07 danielgindi