function useOnClickHandler()

in packages/react-heat-streams/src/components/HeatStreamsChart.tsx [303:334]


function useOnClickHandler(
	categoriesInView: ICategory[],
	rowHeight: number,
	rowGap: boolean,
	timeScrub: TimeDomain | undefined,
	onClearSelection: () => void,
	onClickCategory: (category: ICategory, ctrl: boolean) => void,
) {
	return useCallback(
		(x: number, y: number, ctrlKey: boolean): void => {
			if (timeScrub) {
				onClearSelection()
			} else {
				const gap = rowGap ? 1 : 0
				const category = categoriesInView[Math.floor(y / (rowHeight + gap))]
				if (category) {
					onClickCategory(category, ctrlKey)
				} else {
					onClearSelection()
				}
			}
		},
		[
			categoriesInView,
			onClearSelection,
			onClickCategory,
			rowGap,
			rowHeight,
			timeScrub,
		],
	)
}