diff --git a/src/components/d3/D3MouseZone.tsx b/src/components/d3/D3MouseZone.tsx index fb85a4a..464d814 100644 --- a/src/components/d3/D3MouseZone.tsx +++ b/src/components/d3/D3MouseZone.tsx @@ -1,9 +1,10 @@ import { createContext, memo, ReactNode, useCallback, useContext, useEffect, useState } from 'react' import * as d3 from 'd3' -import '@styles/d3.less' import { ChartOffset } from './types' +import '@styles/d3.less' + export type D3MouseState = { /** Позиция мыши по оси X */ x: number @@ -13,7 +14,7 @@ export type D3MouseState = { visible: boolean } -type SubscribeFunction = (name: keyof SVGElementEventMap, handler: EventListenerOrEventListenerObject) => null | (() => boolean) +type SubscribeFunction = (name: K, handler: (this: SVGRectElement, ev: SVGElementEventMap[K]) => any) => null | (() => boolean) export type D3MouseZoneContext = { /** Состояние мыши */ diff --git a/src/components/d3/plugins/D3HorizontalCursor.tsx b/src/components/d3/plugins/D3HorizontalCursor.tsx index 2b0c687..2a3f212 100644 --- a/src/components/d3/plugins/D3HorizontalCursor.tsx +++ b/src/components/d3/plugins/D3HorizontalCursor.tsx @@ -92,8 +92,8 @@ const _D3HorizontalCursor = ({ const getXLine = useMemo(() => zone ? (() => zone().select('.tooltip-x-line')) : null, [zone]) useEffect(() => { - const onMiddleClick = (e: Event) => { - if ((e as MouseEvent).button === 1) + const onMiddleClick = (e: MouseEvent) => { + if (e.button === 1) setFixed((prev) => !prev) } diff --git a/src/components/d3/plugins/D3Tooltip.tsx b/src/components/d3/plugins/D3Tooltip.tsx index 9440e42..8622d59 100644 --- a/src/components/d3/plugins/D3Tooltip.tsx +++ b/src/components/d3/plugins/D3Tooltip.tsx @@ -98,8 +98,8 @@ function _D3Tooltip>({ const tooltipRef = useRef(null) useEffect(() => { - const onMiddleClick = (e: Event) => { - if ((e as MouseEvent).button === 1 && visible) + const onMiddleClick = (e: MouseEvent) => { + if (e.button === 1 && visible) setFixed((prev) => !prev) } diff --git a/src/utils/hooks/cachedFetch.ts b/src/utils/hooks/cachedFetch.ts index 1f559ee..f3cdaf2 100644 --- a/src/utils/hooks/cachedFetch.ts +++ b/src/utils/hooks/cachedFetch.ts @@ -1,7 +1,7 @@ import { useCallback, useEffect, useState } from 'react' import { FunctionalValue, useFunctionalValue } from './functionalValue' -export const useCachedMethod =

(method: (...props: P) => R, expires: FunctionalValue = 60, initialValue?: R | (() => R), storeValue: boolean = false) => { +export const useCachedMethod =

(method: (...props: P) => R, expires: FunctionalValue<() => number> = 60, initialValue?: R | (() => R), storeValue: boolean = false) => { const [value, setValue] = useState(initialValue) const [lastUpdate, setLastUpdate] = useState<{ date: number, props: P }>({ date: 0, props: [] as P }) const exp = useFunctionalValue(expires) diff --git a/src/utils/hooks/usePartialProps.ts b/src/utils/hooks/usePartialProps.ts index c24fca1..50121cf 100644 --- a/src/utils/hooks/usePartialProps.ts +++ b/src/utils/hooks/usePartialProps.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { FunctionalValue, useFunctionalValue } from './functionalValue' -export const usePartialProps = (prop: Partial | null | undefined, defaultValue: FunctionalValue): T => { +export const usePartialProps = (prop: Partial | null | undefined, defaultValue: FunctionalValue<() => T>): T => { const def = useFunctionalValue(defaultValue) const result: T = useMemo(() => {