-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: fix unnecessary re-render (#2573)
fix unnecessary renrender
- Loading branch information
Showing
3 changed files
with
53 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/charts/src/state/selectors/chart_container_updates.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getChartThemeSelector } from './get_chart_theme'; | ||
import { getInternalCanDisplayChartTitles } from './get_internal_can_display_chart_titles'; | ||
import { getLegendConfigSelector } from './get_legend_config_selector'; | ||
import { LegendPositionConfig } from '../../specs'; | ||
import { createCustomCachedSelector } from '../create_selector'; | ||
|
||
/** @internal */ | ||
export const getChartContainerUpdateStateSelector = createCustomCachedSelector( | ||
[getLegendConfigSelector, getChartThemeSelector, getInternalCanDisplayChartTitles], | ||
( | ||
legendConfig, | ||
theme, | ||
displayTitles, | ||
): { | ||
paddingLeft: number; | ||
paddingRight: number; | ||
displayTitles: boolean; | ||
legendDirection: LegendPositionConfig['direction']; | ||
} => { | ||
return { | ||
paddingLeft: theme.chartMargins.left, | ||
paddingRight: theme.chartMargins.right, | ||
displayTitles, | ||
legendDirection: legendConfig.legendPosition.direction, | ||
}; | ||
}, | ||
); |
13 changes: 13 additions & 0 deletions
13
packages/charts/src/state/selectors/get_internal_can_display_chart_titles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { GlobalChartState } from '../chart_state'; | ||
|
||
/** @internal */ | ||
export const getInternalCanDisplayChartTitles = (state: GlobalChartState): boolean => | ||
state.internalChartState?.canDisplayChartTitles(state) ?? true; |