2023-09-22 16:23:44 +02:00
|
|
|
import React, { useState, useCallback, useEffect } from 'react';
|
2022-11-16 20:19:52 +01:00
|
|
|
import IconButton from '../IconButton';
|
|
|
|
|
import Icon from '../Icon';
|
|
|
|
|
import './InputNumber.css';
|
2023-07-07 17:30:52 +02:00
|
|
|
import Label from '../Label';
|
2023-09-22 16:23:44 +02:00
|
|
|
import getMaxDigits from '../../utils/getMaxDigits';
|
2022-11-16 20:19:52 +01:00
|
|
|
|
|
|
|
|
/**
|
2023-07-07 17:30:52 +02:00
|
|
|
* React Number Input component'
|
2022-11-16 20:19:52 +01:00
|
|
|
* it has two props, value and onChange
|
|
|
|
|
* value is a number value
|
|
|
|
|
* onChange is a function that will be called when the number input is changed
|
|
|
|
|
* it can get changed by clicking on the up and down buttons
|
|
|
|
|
* or by typing a number in the input
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const sizesClasses = {
|
|
|
|
|
sm: 'w-[45px] h-[28px]',
|
2023-07-07 17:30:52 +02:00
|
|
|
lg: 'w-[206px] h-[35px]',
|
2022-11-16 20:19:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const InputNumber: React.FC<{
|
|
|
|
|
value: number;
|
2023-09-22 16:23:44 +02:00
|
|
|
onChange: (value: number) => void;
|
feat(RT): add dicom RT support via volume viewports (#3310)
* feat: initial RT support
* make the segmentation service work with representation data
* feat: make segmentation service work with representations
* fix rtss vis
* fix: rt hydration
* fix the rendering of rt names
* fix imports
* refactor: Modify status and click handling for hydration of RTStructures
Modify status and click handling for hydration of RTStructures by renaming `onPillClick` to `onStatusClick` in `OHIFCornerstoneRTViewport.tsx` and `_getStatusComponent.tsx` files. Also, update initial segmentation configurations in `PanelSegmentation.tsx` and simplify configuration changes and values for segmentation service in `SegmentationService.ts`. Finally, remove console debug in `CornerstoneViewportService.ts`.
* wip for highlighting contours
* refactor rt displayset code
* review code update
* update cornerstone dependencies
* refactor: Update license year, version number, and minor code cleanup
This commit updates the license year in several files, updates the version number in package.json, and contains minor code cleanup in two files.
* add bulkdataURI retrieve for RT
* fix package version
* apply review comments
* apply review comments
* apply review comments
* feat(panels): refactor and streamline segmentation configuration and inputs
Rewrote state hooks and streamlined the configuration input for `PanelSegmentation` to be more verbose and reusable. Included several new input types, including the `InputRange` component which now shows a fixed floating value based on the step provided. The `SegmentationConfig` component now works with dynamic values controlled by `initialConfig`. These changes should improve function usability and make the code more maintainable going forward.
* fix various bugs
* fix contour delete by upgrade cs3d version
* feat(viewport, inputNumber, segmentationConfig, orthanc): Implement minimum and maximum values for input number components, and useBulkDataURI for Orthanc configuration. Compare measurement view planes with absolute viewport view planes in Cornerstone viewport.
* update yarn lock
2023-04-26 18:21:08 +02:00
|
|
|
minValue?: number;
|
|
|
|
|
maxValue?: number;
|
2023-09-22 16:23:44 +02:00
|
|
|
step?: number;
|
|
|
|
|
size?: 'sm' | 'lg';
|
2022-11-16 20:19:52 +01:00
|
|
|
className?: string;
|
2023-07-07 17:30:52 +02:00
|
|
|
labelClassName?: string;
|
|
|
|
|
label?: string;
|
2023-09-22 16:23:44 +02:00
|
|
|
showAdjustmentArrows?: boolean;
|
feat(RT): add dicom RT support via volume viewports (#3310)
* feat: initial RT support
* make the segmentation service work with representation data
* feat: make segmentation service work with representations
* fix rtss vis
* fix: rt hydration
* fix the rendering of rt names
* fix imports
* refactor: Modify status and click handling for hydration of RTStructures
Modify status and click handling for hydration of RTStructures by renaming `onPillClick` to `onStatusClick` in `OHIFCornerstoneRTViewport.tsx` and `_getStatusComponent.tsx` files. Also, update initial segmentation configurations in `PanelSegmentation.tsx` and simplify configuration changes and values for segmentation service in `SegmentationService.ts`. Finally, remove console debug in `CornerstoneViewportService.ts`.
* wip for highlighting contours
* refactor rt displayset code
* review code update
* update cornerstone dependencies
* refactor: Update license year, version number, and minor code cleanup
This commit updates the license year in several files, updates the version number in package.json, and contains minor code cleanup in two files.
* add bulkdataURI retrieve for RT
* fix package version
* apply review comments
* apply review comments
* apply review comments
* feat(panels): refactor and streamline segmentation configuration and inputs
Rewrote state hooks and streamlined the configuration input for `PanelSegmentation` to be more verbose and reusable. Included several new input types, including the `InputRange` component which now shows a fixed floating value based on the step provided. The `SegmentationConfig` component now works with dynamic values controlled by `initialConfig`. These changes should improve function usability and make the code more maintainable going forward.
* fix various bugs
* fix contour delete by upgrade cs3d version
* feat(viewport, inputNumber, segmentationConfig, orthanc): Implement minimum and maximum values for input number components, and useBulkDataURI for Orthanc configuration. Compare measurement view planes with absolute viewport view planes in Cornerstone viewport.
* update yarn lock
2023-04-26 18:21:08 +02:00
|
|
|
}> = ({
|
|
|
|
|
value,
|
|
|
|
|
onChange,
|
|
|
|
|
step = 1,
|
|
|
|
|
className,
|
|
|
|
|
size = 'sm',
|
|
|
|
|
minValue = 0,
|
|
|
|
|
maxValue = 100,
|
2023-07-07 17:30:52 +02:00
|
|
|
labelClassName,
|
|
|
|
|
label,
|
2023-09-22 16:23:44 +02:00
|
|
|
showAdjustmentArrows = true,
|
feat(RT): add dicom RT support via volume viewports (#3310)
* feat: initial RT support
* make the segmentation service work with representation data
* feat: make segmentation service work with representations
* fix rtss vis
* fix: rt hydration
* fix the rendering of rt names
* fix imports
* refactor: Modify status and click handling for hydration of RTStructures
Modify status and click handling for hydration of RTStructures by renaming `onPillClick` to `onStatusClick` in `OHIFCornerstoneRTViewport.tsx` and `_getStatusComponent.tsx` files. Also, update initial segmentation configurations in `PanelSegmentation.tsx` and simplify configuration changes and values for segmentation service in `SegmentationService.ts`. Finally, remove console debug in `CornerstoneViewportService.ts`.
* wip for highlighting contours
* refactor rt displayset code
* review code update
* update cornerstone dependencies
* refactor: Update license year, version number, and minor code cleanup
This commit updates the license year in several files, updates the version number in package.json, and contains minor code cleanup in two files.
* add bulkdataURI retrieve for RT
* fix package version
* apply review comments
* apply review comments
* apply review comments
* feat(panels): refactor and streamline segmentation configuration and inputs
Rewrote state hooks and streamlined the configuration input for `PanelSegmentation` to be more verbose and reusable. Included several new input types, including the `InputRange` component which now shows a fixed floating value based on the step provided. The `SegmentationConfig` component now works with dynamic values controlled by `initialConfig`. These changes should improve function usability and make the code more maintainable going forward.
* fix various bugs
* fix contour delete by upgrade cs3d version
* feat(viewport, inputNumber, segmentationConfig, orthanc): Implement minimum and maximum values for input number components, and useBulkDataURI for Orthanc configuration. Compare measurement view planes with absolute viewport view planes in Cornerstone viewport.
* update yarn lock
2023-04-26 18:21:08 +02:00
|
|
|
}) => {
|
2022-11-16 20:19:52 +01:00
|
|
|
const [numberValue, setNumberValue] = useState(value);
|
|
|
|
|
|
2023-09-22 16:23:44 +02:00
|
|
|
const maxDigits = getMaxDigits(maxValue, step);
|
|
|
|
|
const inputWidth = Math.max(maxDigits * 10, showAdjustmentArrows ? 20 : 28);
|
|
|
|
|
const arrowWidth = showAdjustmentArrows ? 20 : 0;
|
|
|
|
|
const containerWidth = `${inputWidth + arrowWidth}px`;
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setNumberValue(value);
|
|
|
|
|
}, [value]);
|
|
|
|
|
|
feat(RT): add dicom RT support via volume viewports (#3310)
* feat: initial RT support
* make the segmentation service work with representation data
* feat: make segmentation service work with representations
* fix rtss vis
* fix: rt hydration
* fix the rendering of rt names
* fix imports
* refactor: Modify status and click handling for hydration of RTStructures
Modify status and click handling for hydration of RTStructures by renaming `onPillClick` to `onStatusClick` in `OHIFCornerstoneRTViewport.tsx` and `_getStatusComponent.tsx` files. Also, update initial segmentation configurations in `PanelSegmentation.tsx` and simplify configuration changes and values for segmentation service in `SegmentationService.ts`. Finally, remove console debug in `CornerstoneViewportService.ts`.
* wip for highlighting contours
* refactor rt displayset code
* review code update
* update cornerstone dependencies
* refactor: Update license year, version number, and minor code cleanup
This commit updates the license year in several files, updates the version number in package.json, and contains minor code cleanup in two files.
* add bulkdataURI retrieve for RT
* fix package version
* apply review comments
* apply review comments
* apply review comments
* feat(panels): refactor and streamline segmentation configuration and inputs
Rewrote state hooks and streamlined the configuration input for `PanelSegmentation` to be more verbose and reusable. Included several new input types, including the `InputRange` component which now shows a fixed floating value based on the step provided. The `SegmentationConfig` component now works with dynamic values controlled by `initialConfig`. These changes should improve function usability and make the code more maintainable going forward.
* fix various bugs
* fix contour delete by upgrade cs3d version
* feat(viewport, inputNumber, segmentationConfig, orthanc): Implement minimum and maximum values for input number components, and useBulkDataURI for Orthanc configuration. Compare measurement view planes with absolute viewport view planes in Cornerstone viewport.
* update yarn lock
2023-04-26 18:21:08 +02:00
|
|
|
const handleMinMax = useCallback(
|
2023-09-22 16:23:44 +02:00
|
|
|
(val: number) => Math.min(Math.max(val, minValue), maxValue),
|
feat(RT): add dicom RT support via volume viewports (#3310)
* feat: initial RT support
* make the segmentation service work with representation data
* feat: make segmentation service work with representations
* fix rtss vis
* fix: rt hydration
* fix the rendering of rt names
* fix imports
* refactor: Modify status and click handling for hydration of RTStructures
Modify status and click handling for hydration of RTStructures by renaming `onPillClick` to `onStatusClick` in `OHIFCornerstoneRTViewport.tsx` and `_getStatusComponent.tsx` files. Also, update initial segmentation configurations in `PanelSegmentation.tsx` and simplify configuration changes and values for segmentation service in `SegmentationService.ts`. Finally, remove console debug in `CornerstoneViewportService.ts`.
* wip for highlighting contours
* refactor rt displayset code
* review code update
* update cornerstone dependencies
* refactor: Update license year, version number, and minor code cleanup
This commit updates the license year in several files, updates the version number in package.json, and contains minor code cleanup in two files.
* add bulkdataURI retrieve for RT
* fix package version
* apply review comments
* apply review comments
* apply review comments
* feat(panels): refactor and streamline segmentation configuration and inputs
Rewrote state hooks and streamlined the configuration input for `PanelSegmentation` to be more verbose and reusable. Included several new input types, including the `InputRange` component which now shows a fixed floating value based on the step provided. The `SegmentationConfig` component now works with dynamic values controlled by `initialConfig`. These changes should improve function usability and make the code more maintainable going forward.
* fix various bugs
* fix contour delete by upgrade cs3d version
* feat(viewport, inputNumber, segmentationConfig, orthanc): Implement minimum and maximum values for input number components, and useBulkDataURI for Orthanc configuration. Compare measurement view planes with absolute viewport view planes in Cornerstone viewport.
* update yarn lock
2023-04-26 18:21:08 +02:00
|
|
|
[maxValue, minValue]
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-22 16:23:44 +02:00
|
|
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const inputValue = e.target.value;
|
2022-11-16 20:19:52 +01:00
|
|
|
|
2023-09-22 16:23:44 +02:00
|
|
|
// Allow negative sign, empty string, or single decimal point for user flexibility
|
|
|
|
|
if (inputValue === '-' || inputValue === '' || inputValue === '.') {
|
|
|
|
|
setNumberValue(inputValue);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-16 20:19:52 +01:00
|
|
|
|
2023-09-22 16:23:44 +02:00
|
|
|
const number = Number(inputValue);
|
|
|
|
|
|
|
|
|
|
// Filter out invalid inputs like 'NaN'
|
|
|
|
|
if (!isNaN(number)) {
|
|
|
|
|
updateValue(number);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const updateValue = (val: number) => {
|
|
|
|
|
const newValue = handleMinMax(val);
|
|
|
|
|
setNumberValue(newValue);
|
|
|
|
|
onChange(newValue);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const increment = () => updateValue(numberValue + step);
|
|
|
|
|
const decrement = () => updateValue(numberValue - step);
|
2022-11-16 20:19:52 +01:00
|
|
|
|
|
|
|
|
return (
|
2023-09-22 16:23:44 +02:00
|
|
|
<div className="flex flex-1 flex-col">
|
2023-09-01 22:19:39 +02:00
|
|
|
{label && (
|
|
|
|
|
<Label
|
|
|
|
|
className={labelClassName}
|
|
|
|
|
text={label}
|
2023-09-22 16:23:44 +02:00
|
|
|
/>
|
2023-09-01 22:19:39 +02:00
|
|
|
)}
|
2023-08-09 16:07:33 +02:00
|
|
|
<div
|
2023-09-01 22:19:39 +02:00
|
|
|
className={`border-secondary-light flex items-center justify-center overflow-hidden rounded-md border-2 bg-black px-1 ${
|
2023-08-09 16:07:33 +02:00
|
|
|
sizesClasses[size]
|
2023-09-22 16:23:44 +02:00
|
|
|
} ${className || ''}`}
|
|
|
|
|
style={{ width: containerWidth }}
|
2023-08-09 16:07:33 +02:00
|
|
|
>
|
|
|
|
|
<div className="flex">
|
|
|
|
|
<input
|
2023-09-22 16:23:44 +02:00
|
|
|
type="number"
|
2023-08-09 16:07:33 +02:00
|
|
|
value={numberValue}
|
2023-09-22 16:23:44 +02:00
|
|
|
step={step}
|
2023-08-09 16:07:33 +02:00
|
|
|
onChange={handleChange}
|
2023-09-22 16:23:44 +02:00
|
|
|
className={'input-number w-full bg-black text-center text-[12px] text-white'}
|
|
|
|
|
style={{ width: inputWidth }}
|
2023-08-09 16:07:33 +02:00
|
|
|
/>
|
2023-09-22 16:23:44 +02:00
|
|
|
{showAdjustmentArrows && (
|
|
|
|
|
<div className="up-arrowsize flex flex-col items-center justify-around">
|
|
|
|
|
<ArrowButton
|
|
|
|
|
onClick={increment}
|
|
|
|
|
rotate
|
|
|
|
|
/>
|
|
|
|
|
<ArrowButton onClick={decrement} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2022-11-16 20:19:52 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-22 16:23:44 +02:00
|
|
|
const ArrowButton = ({ onClick, rotate = false }: { onClick: () => void; rotate?: boolean }) => (
|
|
|
|
|
<IconButton
|
|
|
|
|
id="arrow-icon"
|
|
|
|
|
variant="text"
|
|
|
|
|
color="inherit"
|
|
|
|
|
size="initial"
|
|
|
|
|
className={`text-[#726f7e] ${rotate ? 'rotate-180 transform' : ''}`}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="ui-arrow-down" />
|
|
|
|
|
</IconButton>
|
|
|
|
|
);
|
|
|
|
|
|
2022-11-16 20:19:52 +01:00
|
|
|
export default InputNumber;
|