Skip to content

Conversation

@markov00
Copy link
Member

Improve legend rendering efficiency by avoiding unnecessary re-renders when the legend configuration changes. This change enhances performance and maintains the integrity of the displayed legend items.

@markov00 markov00 requested a review from Copilot April 10, 2025 21:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

packages/charts/src/state/chart_selectors.ts:148

  • Removing the export from ChartSelectorsFactory may lead to breakages if it is expected to be used externally. Confirm that this type is intended for internal use only.
type ChartSelectorsFactory = () => ChartSelectors;

packages/charts/src/chart_types/xy_chart/state/selectors/get_legend_item_extra_values.ts:24

  • Using legendValues.length directly assumes that legendValues is always an array; ensure that getLegendConfigSelector always returns an array to prevent potential runtime errors.
type === ScaleType.Ordinal || legendValues.length === 0

@markov00 markov00 marked this pull request as ready for review October 27, 2025 08:39
@markov00 markov00 requested a review from a team October 27, 2025 08:40
@mariairiartef mariairiartef self-requested a review October 27, 2025 15:56
Copy link
Contributor

@mariairiartef mariairiartef left a comment

Choose a reason for hiding this comment

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

I've left some comments!

@elastic-datavis
Copy link
Contributor

Copy link
Contributor

@mariairiartef mariairiartef left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments!

type ChartSelectorsFactory = () => ChartSelectors;

const EMPTY_TOOLTIP = Object.freeze({ header: null, values: [] });
const EMPTY_LEGEND_ITEM_LIST: LegendItemLabel[] = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const EMPTY_LEGEND_ITEM_LIST: LegendItemLabel[] = [];
const EMPTY_LEGEND_ITEM_LIST: LegendItemLabel[] = Object.freeze([]);

Do you think it's too much to use Object.freeze on all these? It's unlikely they would change based on our aversion to mutations but still you never know. I don't think freeze affects runtime performance in any meaningful way.

Up to you...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants