Skip to content

Commit

Permalink
refactor: clean up picked shapes selector
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 committed Sep 2, 2021
1 parent c4fb452 commit 8358dd8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@

import { DEFAULT_CSS_CURSOR } from '../../../../common/constants';
import { createCustomCachedSelector } from '../../../../state/create_selector';
import { getGridHeightParamsSelector } from './get_grid_full_height';
import { isBrushingSelector } from './is_brushing';
import { getPickedShapes } from './picked_shapes';

/** @internal */
export const getPointerCursorSelector = createCustomCachedSelector(
[getPickedShapes, isBrushingSelector, getGridHeightParamsSelector],
(pickedShapes, isBrushing, gridParams) => {
return isBrushing ||
(Array.isArray(pickedShapes) &&
pickedShapes.filter(({ y }) => y < gridParams.gridCellHeight * gridParams.pageSize).length > 0)
? 'pointer'
: DEFAULT_CSS_CURSOR;
[getPickedShapes, isBrushingSelector],
(pickedShapes, isBrushing) => {
return isBrushing || (Array.isArray(pickedShapes) && pickedShapes.length > 0) ? 'pointer' : DEFAULT_CSS_CURSOR;
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ import { GlobalChartState } from '../../../../state/chart_state';
import { createCustomCachedSelector } from '../../../../state/create_selector';
import { Cell, TextBox } from '../../layout/types/viewmodel_types';
import { geometries } from './geometries';
import { getGridHeightParamsSelector } from './get_grid_full_height';

function getCurrentPointerPosition(state: GlobalChartState) {
return state.interactions.pointer.current.position;
}

/** @internal */
export const getPickedShapes = createCustomCachedSelector(
[geometries, getCurrentPointerPosition],
(geoms, pointerPosition): Cell[] | TextBox => {
[geometries, getCurrentPointerPosition, getGridHeightParamsSelector],
(geoms, pointerPosition, gridParams): Cell[] | TextBox => {
const picker = geoms.pickQuads;
const { x, y } = pointerPosition;
return picker(x, y);
const arrayPicker = picker(x, y) as Cell[];
return Array.isArray(picker(x, y))
? arrayPicker.filter(({ y }) => y < gridParams.gridCellHeight * gridParams.pageSize)
: picker(x, y);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { RGBtoString } from '../../../../common/color_library_wrappers';
import { TooltipInfo } from '../../../../components/tooltip/types';
import { createCustomCachedSelector } from '../../../../state/create_selector';
import { getGridHeightParamsSelector } from './get_grid_full_height';
import { getHeatmapConfigSelector } from './get_heatmap_config';
import { getSpecOrNull } from './heatmap_spec';
import { getPickedShapes } from './picked_shapes';
Expand All @@ -21,8 +20,8 @@ const EMPTY_TOOLTIP = Object.freeze({

/** @internal */
export const getTooltipInfoSelector = createCustomCachedSelector(
[getSpecOrNull, getHeatmapConfigSelector, getPickedShapes, getGridHeightParamsSelector],
(spec, config, pickedShapes, gridParams): TooltipInfo => {
[getSpecOrNull, getHeatmapConfigSelector, getPickedShapes],
(spec, config, pickedShapes): TooltipInfo => {
if (!spec) {
return EMPTY_TOOLTIP;
}
Expand All @@ -34,7 +33,6 @@ export const getTooltipInfoSelector = createCustomCachedSelector(

if (Array.isArray(pickedShapes)) {
pickedShapes
.filter(({ y }) => y < gridParams.gridCellHeight * gridParams.pageSize)
.filter(({ visible }) => visible)
.forEach((shape) => {
// X-axis value
Expand Down

0 comments on commit 8358dd8

Please sign in to comment.