Skip to content

Commit e25d653

Browse files
committed
fix: remove use of any in 1D components and brush tracker
1 parent a6098c8 commit e25d653

File tree

17 files changed

+85
-53
lines changed

17 files changed

+85
-53
lines changed

src/component/1d-2d/FieldEdition.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { PopoverProps } from '@blueprintjs/core';
22
import { Popover } from '@blueprintjs/core';
33
import styled from '@emotion/styled';
44
import { yupResolver } from '@hookform/resolvers/yup';
5-
import type { ReactNode } from 'react';
5+
import type { MouseEvent, ReactNode } from 'react';
66
import { useState } from 'react';
77
import { useForm } from 'react-hook-form';
88
import * as Yup from 'yup';
@@ -34,7 +34,7 @@ const validationSchema = (inputType: 'number' | 'text') =>
3434
value: (inputType === 'number' ? Yup.number() : Yup.string()).required(),
3535
});
3636

37-
function stopPropagation(e: any) {
37+
function stopPropagation(e: MouseEvent) {
3838
e.stopPropagation();
3939
}
4040

src/component/1d/BrushTracker1D.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PropsWithChildren } from 'react';
1+
import type { MouseEvent, PropsWithChildren } from 'react';
22
import { useCallback, useRef, useState } from 'react';
33
import { useOnOff } from 'react-science/ui';
44

@@ -106,7 +106,7 @@ export function BrushTracker1D({ children }: Required<PropsWithChildren>) {
106106

107107
const [brushData, setBrushData] = useState<BrushTrackerData | null>(null);
108108

109-
function handleBrush(brushData: any) {
109+
function handleBrush(brushData: BrushTrackerData) {
110110
const { mouseButton } = brushData;
111111
const brushDataInPPM = convertToPPM(brushData);
112112

@@ -120,7 +120,7 @@ export function BrushTracker1D({ children }: Required<PropsWithChildren>) {
120120
dispatch({ type: 'MOVE', payload: { shiftX, shiftY: 0 } });
121121
}
122122
}
123-
function handleInsetBrush(brushData: any) {
123+
function handleInsetBrush(brushData: BrushTrackerData) {
124124
const { mouseButton } = brushData;
125125
const brushDataInPPM = convertToPPM(brushData);
126126

@@ -140,13 +140,13 @@ export function BrushTracker1D({ children }: Required<PropsWithChildren>) {
140140
}
141141

142142
const handleBrushEnd = useCallback<OnBrush>(
143-
(brushData) => {
143+
(brushData: BrushTrackerData) => {
144144
//reset the brush start
145145
brushStartRef.current = null;
146146
setBrushData(brushData);
147147
const brushDataInPPM = convertToPPM(brushData);
148148

149-
const keyModifiers = getModifiersKey(brushData as unknown as MouseEvent);
149+
const keyModifiers = getModifiersKey(brushData);
150150

151151
const selectRange = sortRange(brushDataInPPM.startX, brushDataInPPM.endX);
152152

@@ -339,8 +339,8 @@ export function BrushTracker1D({ children }: Required<PropsWithChildren>) {
339339
);
340340

341341
const handleOnDoubleClick = useCallback(
342-
(event: any) => {
343-
const keyModifiers = getModifiersKey(event as unknown as MouseEvent);
342+
(event: MouseEvent) => {
343+
const keyModifiers = getModifiersKey(event);
344344
if (primaryKeyIdentifier === keyModifiers && !isClickDebounced) return;
345345

346346
dispatch({
@@ -352,8 +352,8 @@ export function BrushTracker1D({ children }: Required<PropsWithChildren>) {
352352
);
353353

354354
const handleInsetOnDoubleClick = useCallback(
355-
(event: any) => {
356-
const keyModifiers = getModifiersKey(event as unknown as MouseEvent);
355+
(event: MouseEvent) => {
356+
const keyModifiers = getModifiersKey(event);
357357
if (primaryKeyIdentifier === keyModifiers) return;
358358

359359
if (!inset) {
@@ -420,7 +420,7 @@ export function BrushTracker1D({ children }: Required<PropsWithChildren>) {
420420
xPPM,
421421
});
422422

423-
const keyModifiers = getModifiersKey(event as unknown as MouseEvent);
423+
const keyModifiers = getModifiersKey(event);
424424

425425
switch (keyModifiers) {
426426
case primaryKeyIdentifier: {

src/component/1d/FooterBanner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ function FooterBannerInner({
7474
return <FooterContainer />;
7575
}
7676

77-
function getXIndex(xPosition: any) {
77+
function getXIndex(xPosition: number) {
7878
if (spectrum) {
7979
const data = get1DDataXY(spectrum);
8080
return xFindClosestIndex(data.x, scaleX().invert(xPosition));
8181
}
8282
return 0;
8383
}
8484

85-
function getYValue(xPosition: any) {
85+
function getYValue(xPosition: number) {
8686
if (spectrum) {
8787
const data = get1DDataXY(spectrum);
8888
const xIndex = getXIndex(xPosition);

src/component/1d/LinesSeries.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ function HeadlightRectStackMode(props: HeadlightRectStackModeProps) {
9494
x={margin.left}
9595
width={`${innerWidth}px`}
9696
height={`${BOX_SIZE}px`}
97-
onClick={(e) => {
98-
setActiveSpectrum(e as unknown as MouseEvent, spectrumID);
97+
onClick={(event) => {
98+
setActiveSpectrum(event, spectrumID);
9999
}}
100100
data-no-export="true"
101101
/>

src/component/1d/SimilarityTree.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Tree } from 'ml-tree-similarity';
12
import { createTree } from 'ml-tree-similarity';
23
import type { CSSProperties } from 'react';
34
import { Fragment } from 'react';
@@ -93,9 +94,9 @@ interface TreeItem {
9394
}
9495

9596
function mapTreeToArray(
96-
node: any,
97+
node: Tree | null,
9798
level: number,
98-
parentCenter = null,
99+
parentCenter: number | null = null,
99100
parentLevel = -1,
100101
): TreeItem[] {
101102
if (!node) return [];

src/component/1d/integral/IntegralResizable.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useChartData } from '../../context/ChartContext.js';
55
import { useDispatch } from '../../context/DispatchContext.js';
66
import { useScaleChecked } from '../../context/ScaleContext.js';
77
import { ResizerWithScale } from '../../elements/ResizerWithScale.js';
8+
import type { Position } from '../../elements/resizer/SVGResizer.tsx';
89
import { useHighlight } from '../../highlight/index.js';
910
import { useResizerStatus } from '../../hooks/useResizerStatus.js';
1011
import useSpectrum from '../../hooks/useSpectrum.js';
@@ -41,7 +42,7 @@ function IntegralResizable({
4142
extra: { id, spectrumID: spectrum.id },
4243
});
4344

44-
function handleOnStopResizing(position: any) {
45+
function handleOnStopResizing(position: Position) {
4546
dispatch({
4647
type: 'RESIZE_INTEGRAL',
4748
payload: {

src/component/1d/matrix/Boxplot.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface UsePathAreaPoints {
4343
y2: NumberArray;
4444
}
4545

46-
function useYScale(scaleRatio: number, yDomain: any) {
46+
function useYScale(scaleRatio: number, yDomain: number[]) {
4747
const { margin, height } = useChartData();
4848
const { spectraBottomMargin } = useScaleChecked();
4949

@@ -59,7 +59,7 @@ function useYScale(scaleRatio: number, yDomain: any) {
5959
function usePath(
6060
pathPoints: UsePathLinePoints,
6161
scaleRatio: number,
62-
yDomain: any,
62+
yDomain: number[],
6363
) {
6464
const { scaleX } = useScaleChecked();
6565
const scaleY = useYScale(scaleRatio, yDomain);
@@ -78,7 +78,7 @@ function usePath(
7878
function useAreaPath(
7979
pathPoints: UsePathAreaPoints,
8080
scaleRatio: number,
81-
yDomain: any,
81+
yDomain: number[],
8282
) {
8383
const { scaleX } = useScaleChecked();
8484
const scaleY = useYScale(scaleRatio, yDomain);

src/component/1d/multiAnalysis/AnalysisRange.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useCallback } from 'react';
44
import { usePreferences } from '../../context/PreferencesContext.js';
55
import { useScaleChecked } from '../../context/ScaleContext.js';
66
import { ResizerWithScale } from '../../elements/ResizerWithScale.js';
7+
import type { Position } from '../../elements/resizer/SVGResizer.tsx';
78
import { useHighlight } from '../../highlight/index.js';
89
import { useResizerStatus } from '../../hooks/useResizerStatus.js';
910

@@ -34,7 +35,7 @@ function AnalysisRange({
3435
const { dispatch } = usePreferences();
3536

3637
const resizeEndHandler = useCallback(
37-
(resized: any) => {
38+
(resized: Position) => {
3839
const { x1, x2 } = resized;
3940
const start = scaleX().invert(x2);
4041
const end = scaleX().invert(x1);

src/component/1d/peaks/PeakEditionManager.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { yupResolver } from '@hookform/resolvers/yup';
2-
import type { KeyboardEvent, PropsWithChildren, ReactNode } from 'react';
2+
import type {
3+
KeyboardEvent,
4+
MouseEvent,
5+
PropsWithChildren,
6+
ReactNode,
7+
} from 'react';
38
import {
49
createContext,
510
useCallback,
@@ -60,7 +65,7 @@ function usePeaksEditionManager() {
6065
return context;
6166
}
6267

63-
function stopPropagation(e: any) {
68+
function stopPropagation(e: MouseEvent) {
6469
e.stopPropagation();
6570
}
6671

src/component/1d/peaks/Peaks.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ const MemoizedPeaksPanel = memo(InnerPeaks);
170170

171171
const emptyData = { peaks: {}, ranges: {}, info: {}, display: {} };
172172

173-
export default function Peaks(props: any) {
173+
interface PeaksProps {
174+
peaksSource: PeaksSource;
175+
}
176+
177+
export default function Peaks(props: PeaksProps) {
174178
const { peaksSource } = props;
175179
const {
176180
view: {

0 commit comments

Comments
 (0)