Skip to content

Commit 5bfcd0a

Browse files
committed
feat: add slider to set min. rel. intensity in spectrum view
1 parent c8a13ca commit 5bfcd0a

File tree

3 files changed

+126
-11
lines changed

3 files changed

+126
-11
lines changed

web-frontend/src/elements/basic/Chart.tsx

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import copyTextToClipboard from '../../utils/copyTextToClipboard';
1717
import routes from '../../constants/routes';
1818
import { usePropertiesContext } from '../../context/properties/properties';
1919
import NeutralLoss from '../../types/peak/NeutralLoss';
20+
import Slider from './Slider';
2021

2122
const toolButtonStyle = {
2223
width: 20,
@@ -30,7 +31,7 @@ type InputProps = {
3031
peakData: Peak[];
3132
peakData2?: Peak[];
3233
neutralLossData?: NeutralLoss[];
33-
onZoom?: ({
34+
onFilter?: ({
3435
fpd1,
3536
nld,
3637
fpd2,
@@ -51,7 +52,7 @@ function Chart({
5152
peakData,
5253
peakData2 = [],
5354
neutralLossData = [],
54-
onZoom = () => {},
55+
onFilter = () => {},
5556
width = 400,
5657
height = 300,
5758
disableLabels = false,
@@ -64,6 +65,7 @@ function Chart({
6465
const { baseUrl, frontendUrl } = usePropertiesContext();
6566

6667
const [isShowLabel, setIsShowLabel] = useState<boolean>(false);
68+
const [minRelIntensity, setMinRelativeIntensity] = useState<number>(0);
6769

6870
const MARGIN = useMemo(() => {
6971
const defaultMargin = 5;
@@ -91,7 +93,7 @@ function Chart({
9193

9294
const getFilteredPeakData = useCallback(
9395
(peakDataTemp: Peak[]) => {
94-
let _peakData = peakDataTemp;
96+
let _peakData = peakDataTemp.filter((pd) => pd.rel >= minRelIntensity);
9597
if (brushXDomains) {
9698
_peakData = peakDataTemp.filter(
9799
(pd) =>
@@ -102,7 +104,7 @@ function Chart({
102104

103105
return _peakData;
104106
},
105-
[brushXDomains],
107+
[brushXDomains, minRelIntensity],
106108
);
107109

108110
const filteredPeakData = useMemo(
@@ -140,13 +142,13 @@ function Chart({
140142
rel: -1 * p.rel,
141143
} as Peak;
142144
});
143-
onZoom({
145+
onFilter({
144146
fpd1: _filteredPeakData,
145147
fpd2: _filteredPeakData2_temp,
146148
nld: filteredNeutralLossData,
147149
});
148150
},
149-
[filteredNeutralLossData, onZoom],
151+
[filteredNeutralLossData, onFilter],
150152
);
151153

152154
useEffect(
@@ -510,6 +512,29 @@ function Chart({
510512
[baseUrl, frontendUrl],
511513
);
512514

515+
const handleOnSetMinRelativeIntensity = useCallback(
516+
(value: number) => {
517+
setMinRelativeIntensity(value);
518+
const _filteredPeakData = peakData.filter((p) => p.rel >= value);
519+
const _filteredPeakData2 = peakData2
520+
? peakData2
521+
.filter((p) => p.rel >= value)
522+
.map((p) => {
523+
const _p: Peak = { ...p };
524+
_p.intensity = -1 * _p.intensity;
525+
_p.rel = -1 * _p.rel;
526+
return _p;
527+
})
528+
: undefined;
529+
onFilter({
530+
fpd1: _filteredPeakData,
531+
fpd2: _filteredPeakData2,
532+
nld: filteredNeutralLossData,
533+
});
534+
},
535+
[filteredNeutralLossData, onFilter, peakData, peakData2],
536+
);
537+
513538
return useMemo(
514539
() => (
515540
<Content
@@ -564,7 +589,7 @@ function Chart({
564589
height: MARGIN.button,
565590
marginLeft: 5,
566591
display: 'flex',
567-
justifyContent: 'flex-start',
592+
justifyContent: 'left',
568593
alignItems: 'center',
569594
}}
570595
>
@@ -589,7 +614,7 @@ function Chart({
589614
{!disableExport && (
590615
<Content
591616
style={{
592-
width: '100%',
617+
width: 80,
593618
height: MARGIN.button,
594619
display: 'flex',
595620
justifyContent: 'left',
@@ -616,6 +641,25 @@ function Chart({
616641
/>
617642
</Content>
618643
)}
644+
<Content
645+
style={{
646+
width: '100%',
647+
height: MARGIN.button,
648+
display: 'flex',
649+
justifyContent: 'left',
650+
alignItems: 'center',
651+
marginLeft: 20,
652+
}}
653+
>
654+
<Slider
655+
width={150}
656+
height={MARGIN.button}
657+
min={0}
658+
max={999}
659+
value={0}
660+
onChange={handleOnSetMinRelativeIntensity}
661+
/>
662+
</Content>
619663
</Content>
620664
<Content
621665
style={{
@@ -656,6 +700,7 @@ function Chart({
656700
filteredPeakData2,
657701
handleOnCopy,
658702
handleOnDownload,
703+
handleOnSetMinRelativeIntensity,
659704
height,
660705
isShowLabel,
661706
peakData.length,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { useCallback, useEffect, useMemo, useState } from 'react';
2+
import type { InputNumberProps, SliderSingleProps } from 'antd';
3+
import { Slider as SliderAntD } from 'antd';
4+
import { Content } from 'antd/es/layout/layout';
5+
6+
type InputProps = {
7+
min: number;
8+
max: number;
9+
value: number;
10+
onChange: (value: number) => void;
11+
width?: number;
12+
height?: number;
13+
};
14+
15+
function Slider({
16+
min,
17+
max,
18+
value,
19+
width = 150,
20+
height,
21+
onChange,
22+
}: InputProps) {
23+
const [inputValue, setInputValue] = useState(1);
24+
25+
const handleOnChange: InputNumberProps['onChange'] = useCallback(
26+
(newValue: unknown) => {
27+
setInputValue(newValue as number);
28+
onChange(newValue as number);
29+
},
30+
[onChange],
31+
);
32+
33+
useEffect(() => {
34+
if (value >= min && value <= max) {
35+
setInputValue(value);
36+
} else {
37+
setInputValue(min);
38+
}
39+
}, [max, min, value]);
40+
41+
const formatter: NonNullable<SliderSingleProps['tooltip']>['formatter'] = (
42+
value,
43+
) => `Minimal relative intensity: ${value}`;
44+
45+
return useMemo(
46+
() => (
47+
<Content
48+
style={{
49+
width,
50+
height,
51+
display: 'flex',
52+
justifyContent: 'left',
53+
alignItems: 'center',
54+
}}
55+
>
56+
<SliderAntD
57+
min={min}
58+
max={max}
59+
onChange={handleOnChange}
60+
value={typeof inputValue === 'number' ? inputValue : 0}
61+
style={{ width }}
62+
tooltip={{ formatter }}
63+
/>
64+
</Content>
65+
),
66+
[handleOnChange, height, inputValue, max, min, width],
67+
);
68+
}
69+
70+
export default Slider;

web-frontend/src/elements/common/Resizable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function Resizable({
5656
NeutralLoss[]
5757
>(record.peak.neutral_loss);
5858

59-
const handleOnZoom = useCallback(
59+
const handleOnFilter = useCallback(
6060
({
6161
fpd1,
6262
nld,
@@ -86,13 +86,13 @@ function Resizable({
8686
peakData={getRecordPeakListWithPrecursor(record)}
8787
peakData2={record2 ? record2.peak.peak.values : undefined}
8888
neutralLossData={record.peak.neutral_loss}
89-
onZoom={handleOnZoom}
89+
onFilter={handleOnFilter}
9090
width={chartWidth}
9191
height={height}
9292
disableExport={disableExport}
9393
/>
9494
),
95-
[chartWidth, disableExport, handleOnZoom, height, record, record2],
95+
[chartWidth, disableExport, handleOnFilter, height, record, record2],
9696
);
9797

9898
const peakTable = useMemo(() => {

0 commit comments

Comments
 (0)