-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(tooltip): improve placement logic (#2310)
- Loading branch information
1 parent
2c8eb29
commit cac5f49
Showing
3 changed files
with
42 additions
and
21 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
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
34 changes: 34 additions & 0 deletions
34
packages/charts/src/state/selectors/get_tooltip_settings.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,34 @@ | ||
/* | ||
* 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 { Selector } from 're-reselect'; | ||
|
||
import { getInternalIsTooltipVisibleSelector } from './get_internal_is_tooltip_visible'; | ||
import { getSettingsSpecSelector } from './get_settings_spec'; | ||
import { getTooltipSpecSelector } from './get_tooltip_spec'; | ||
import type { TooltipProps } from '../../specs'; | ||
import { GlobalChartState } from '../chart_state'; | ||
import { createCustomCachedSelector } from '../create_selector'; | ||
|
||
const getChartId: Selector<GlobalChartState, string> = ({ chartId }) => chartId; | ||
|
||
/** @internal */ | ||
const getTooltipSettingsSingleton = createCustomCachedSelector([getChartId], (): Record<string, never> => ({})); | ||
|
||
/** @internal */ | ||
export const getTooltipSettings = createCustomCachedSelector( | ||
[getTooltipSettingsSingleton, getTooltipSpecSelector, getSettingsSpecSelector, getInternalIsTooltipVisibleSelector], | ||
(settingsBase, tooltip, { externalPointerEvents }, { isExternal }): TooltipProps => { | ||
if (!isExternal) return tooltip; | ||
|
||
return Object.assign(settingsBase, { | ||
...tooltip, | ||
...externalPointerEvents.tooltip, | ||
}); | ||
}, | ||
); |