nmrium 0.45.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/lib/component/1d/tool/PeakPointer.js +6 -16
  2. package/lib/component/1d/utilities/scale.js +13 -8
  3. package/lib/component/1d-2d/components/SpectrumInfoBlock.js +15 -4
  4. package/lib/component/elements/ContextMenuBluePrint.d.ts +16 -0
  5. package/lib/component/elements/ContextMenuBluePrint.js +20 -0
  6. package/lib/component/elements/DropdownMenu.d.ts +9 -0
  7. package/lib/component/elements/DropdownMenu.js +7 -0
  8. package/lib/component/elements/Header.d.ts +1 -1
  9. package/lib/component/elements/Header.js +4 -6
  10. package/lib/component/elements/ReactTable/Elements/ReactTableRow.d.ts +2 -2
  11. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +2 -2
  12. package/lib/component/elements/ReactTable/ReactTable.d.ts +5 -5
  13. package/lib/component/elements/Select.js +11 -4
  14. package/lib/component/header/Header.js +3 -4
  15. package/lib/component/hooks/useActiveSpectrumIntegralsViewState.js +3 -1
  16. package/lib/component/hooks/useActiveSpectrumPeaksViewState.js +3 -1
  17. package/lib/component/hooks/useActiveSpectrumRangesViewState.js +3 -1
  18. package/lib/component/hooks/useActiveSpectrumStyleOptions.js +6 -2
  19. package/lib/component/hooks/useActiveSpectrumZonesViewState.js +3 -1
  20. package/lib/component/hooks/useCheckToolsVisibility.d.ts +1 -1
  21. package/lib/component/hooks/useSaveSettings.js +1 -1
  22. package/lib/component/hooks/useSpectrum.js +1 -1
  23. package/lib/component/hooks/useToolsFunctions.js +2 -2
  24. package/lib/component/modal/MoleculeStructureEditorModal.d.ts +0 -8
  25. package/lib/component/modal/MoleculeStructureEditorModal.js +31 -8
  26. package/lib/component/modal/MultipletAnalysisModal.d.ts +1 -2
  27. package/lib/component/modal/PredictSpectraModal.js +3 -2
  28. package/lib/component/modal/aboutUs/AboutUsModal.js +1 -5
  29. package/lib/component/modal/editRange/forms/components/AddSignalFormTab.js +1 -0
  30. package/lib/component/modal/editRange/forms/validation/EditRangeValidation.js +4 -1
  31. package/lib/component/modal/metaImportation/MetaImportationModal.js +1 -1
  32. package/lib/component/modal/setting/GeneralSettings.js +1 -1
  33. package/lib/component/modal/setting/settings-tabs/InfoBlockTabContent.js +1 -1
  34. package/lib/component/modal/setting/settingsValidation.js +3 -1
  35. package/lib/component/panels/MatrixGenerationPanel/FiltersOptions.js +7 -2
  36. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +7 -14
  37. package/lib/component/panels/RangesPanel/RangesHeader.js +1 -1
  38. package/lib/component/panels/RangesPanel/RangesPanel.js +1 -2
  39. package/lib/component/panels/RangesPanel/RangesTable.d.ts +2 -2
  40. package/lib/component/panels/RangesPanel/RangesTableRow.d.ts +2 -2
  41. package/lib/component/panels/RangesPanel/RangesTableRow.js +2 -2
  42. package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.js +3 -3
  43. package/lib/component/panels/SpectrumsPanel/SpectraTable.d.ts +1 -2
  44. package/lib/component/panels/SpectrumsPanel/SpectraTable.js +15 -18
  45. package/lib/component/panels/SummaryPanel/utilities/Utilities.d.ts +2 -2
  46. package/lib/component/panels/ZonesPanel/ZonesTableRow.d.ts +2 -2
  47. package/lib/component/panels/ZonesPanel/ZonesTableRow.js +2 -2
  48. package/lib/component/panels/extra/preferences/ColumnsHelper.js +1 -2
  49. package/lib/component/panels/filtersPanel/FiltersTable.js +1 -1
  50. package/lib/component/panels/multipleAnalysisPanel/preferences/index.js +6 -2
  51. package/lib/component/reducer/Reducer.d.ts +0 -4
  52. package/lib/component/reducer/actions/FiltersActions.d.ts +2 -1
  53. package/lib/component/reducer/actions/FiltersActions.js +1 -1
  54. package/lib/component/reducer/actions/MoleculeActions.d.ts +4 -1
  55. package/lib/component/reducer/actions/MoleculeActions.js +6 -2
  56. package/lib/component/reducer/actions/PeaksActions.js +4 -3
  57. package/lib/component/reducer/actions/SpectrumsActions.js +1 -0
  58. package/lib/component/reducer/actions/ToolsActions.js +8 -6
  59. package/lib/component/reducer/actions/utilities/deepReplaceDiaIDs.d.ts +3 -0
  60. package/lib/component/reducer/actions/utilities/deepReplaceDiaIDs.js +24 -0
  61. package/lib/component/reducer/helper/Zoom1DManager.js +1 -1
  62. package/lib/component/reducer/helper/getActiveSpectra.js +2 -1
  63. package/lib/component/reducer/helper/getActiveSpectrum.js +1 -1
  64. package/lib/component/reducer/preferences/panelsPreferencesDefaultValues.js +1 -1
  65. package/lib/component/toolbar/BasicToolBar.js +53 -34
  66. package/lib/component/toolbar/FunctionToolBar.js +102 -9
  67. package/lib/component/toolbar/ToolBar.js +1 -1
  68. package/lib/component/utility/getClosePeak.d.ts +10 -0
  69. package/lib/component/utility/getClosePeak.js +15 -0
  70. package/lib/component/utility/maxAbsoluteValue.d.ts +3 -0
  71. package/lib/component/utility/maxAbsoluteValue.js +21 -0
  72. package/lib/data/data1d/Spectrum1D/index.d.ts +0 -1
  73. package/lib/data/data1d/Spectrum1D/index.js +0 -1
  74. package/lib/data/data1d/Spectrum1D/initiateDatum1D.js +2 -2
  75. package/lib/data/data1d/Spectrum1D/peaks/autoPeakPicking.js +1 -1
  76. package/lib/data/data1d/Spectrum1D/ranges/addRange.js +1 -1
  77. package/lib/data/data1d/Spectrum1D/ranges/detectRange.js +1 -1
  78. package/lib/data/data2d/Spectrum2D/contours.js +2 -2
  79. package/lib/data/data2d/Spectrum2D/getMissingProjection.js +2 -2
  80. package/lib/data/data2d/Spectrum2D/getSlice.js +3 -3
  81. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js +1 -1
  82. package/lib/data/parseMeta/mapErrors.js +3 -1
  83. package/lib/data/utilities/generateNumbersPowerOfX.js +1 -1
  84. package/lib/versionInfo.js +1 -1
  85. package/package.json +39 -38
  86. package/lib/component/elements/ToolbarMenu.d.ts +0 -18
  87. package/lib/component/elements/ToolbarMenu.js +0 -102
  88. package/lib/component/elements/toggle/ToggleButton.d.ts +0 -13
  89. package/lib/component/elements/toggle/ToggleButton.js +0 -24
  90. package/lib/component/elements/toggle/ToggleButtonGroup.d.ts +0 -8
  91. package/lib/component/elements/toggle/ToggleButtonGroup.js +0 -48
  92. package/lib/data/data1d/Spectrum1D/peaks/lookupPeak.d.ts +0 -17
  93. package/lib/data/data1d/Spectrum1D/peaks/lookupPeak.js +0 -18
  94. package/lib/data/data2d/Processing2D.d.ts +0 -32
  95. package/lib/data/data2d/Processing2D.js +0 -130
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nmrium",
3
3
  "description": "React component to display and process nuclear magnetic resonance (NMR) spectra.",
4
- "version": "0.45.0",
4
+ "version": "0.46.0",
5
5
  "license": "MIT",
6
6
  "module": "lib/component/main/index.js",
7
7
  "types": "lib/component/main/index.d.ts",
@@ -45,7 +45,7 @@
45
45
  "url": "git+https://github.com/cheminfo/nmrium.git"
46
46
  },
47
47
  "volta": {
48
- "node": "20.8.1"
48
+ "node": "20.10.0"
49
49
  },
50
50
  "overrides": {
51
51
  "react": "$react",
@@ -56,7 +56,8 @@
56
56
  "react-dom": ">=18.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@blueprintjs/core": "^5.6.0",
59
+ "@blueprintjs/core": "^5.7.2",
60
+ "@blueprintjs/icons": "^5.5.0",
60
61
  "@emotion/react": "^11.11.1",
61
62
  "@emotion/styled": "^11.11.0",
62
63
  "@lukeed/uuid": "^2.0.1",
@@ -80,71 +81,71 @@
80
81
  "ml-baseline-correction-regression": "^1.0.2",
81
82
  "ml-conrec": "^5.0.2",
82
83
  "ml-gsd": "^12.1.3",
83
- "ml-matrix": "^6.10.8",
84
- "ml-spectra-processing": "^12.6.0",
84
+ "ml-matrix": "^6.11.0",
85
+ "ml-spectra-processing": "^12.8.0",
85
86
  "ml-stat": "^1.3.3",
86
87
  "multiplet-analysis": "^2.1.2",
87
88
  "nmr-correlation": "^2.3.3",
88
- "nmr-load-save": "^0.23.6",
89
- "nmr-processing": "^11.6.0",
90
- "nmredata": "^0.9.7",
89
+ "nmr-load-save": "^0.23.11",
90
+ "nmr-processing": "^11.6.1",
91
+ "nmredata": "^0.9.9",
91
92
  "numeral": "^2.0.6",
92
- "openchemlib": "^8.7.1",
93
- "openchemlib-utils": "^5.4.0",
93
+ "openchemlib": "^8.7.2",
94
+ "openchemlib-utils": "^5.6.1",
94
95
  "papaparse": "^5.4.1",
95
96
  "re-resizable": "6.9.11",
96
97
  "react-d3-utils": "^1.0.0",
97
98
  "react-dropzone": "^14.2.3",
98
99
  "react-error-boundary": "^4.0.11",
99
- "react-icons": "^4.11.0",
100
+ "react-icons": "^4.12.0",
100
101
  "react-inspector": "^6.0.2",
101
102
  "react-mf": "^2.0.2",
102
103
  "react-ocl": "^6.1.0",
103
104
  "react-ocl-nmr": "^3.0.1",
104
105
  "react-plot": "^1.4.2",
105
106
  "react-rnd": "^10.4.1",
106
- "react-science": "^0.27.0",
107
+ "react-science": "^0.32.1",
107
108
  "react-slider": "^2.0.6",
108
109
  "react-table": "^7.8.0",
109
110
  "react-transition-group": "^4.4.5",
110
- "react-use": "^17.4.0",
111
+ "react-use": "^17.4.2",
111
112
  "smart-array-filter": "^4.0.2",
112
113
  "yup": "^1.3.2"
113
114
  },
114
115
  "devDependencies": {
115
- "@babel/plugin-transform-modules-commonjs": "^7.23.0",
116
- "@babel/preset-react": "^7.22.15",
117
- "@babel/preset-typescript": "^7.23.2",
118
- "@playwright/test": "^1.39.0",
116
+ "@babel/plugin-transform-modules-commonjs": "^7.23.3",
117
+ "@babel/preset-react": "^7.23.3",
118
+ "@babel/preset-typescript": "^7.23.3",
119
+ "@playwright/test": "^1.40.1",
119
120
  "@simbathesailor/use-what-changed": "^2.0.0",
120
- "@types/d3": "^7.4.2",
121
- "@types/lodash": "^4.14.200",
122
- "@types/node": "^20.8.10",
123
- "@types/papaparse": "^5.3.10",
124
- "@types/react": "^18.2.36",
125
- "@types/react-dom": "^18.2.14",
126
- "@types/react-table": "^7.7.17",
127
- "@vitejs/plugin-react-swc": "^3.4.1",
128
- "@vitest/coverage-v8": "^0.34.6",
121
+ "@types/d3": "^7.4.3",
122
+ "@types/lodash": "^4.14.202",
123
+ "@types/node": "^20.10.4",
124
+ "@types/papaparse": "^5.3.14",
125
+ "@types/react": "^18.2.45",
126
+ "@types/react-dom": "^18.2.17",
127
+ "@types/react-table": "^7.7.18",
128
+ "@vitejs/plugin-react-swc": "^3.5.0",
129
+ "@vitest/coverage-v8": "^1.0.4",
129
130
  "cross-env": "^7.0.3",
130
- "cspell": "^7.3.8",
131
- "eslint": "^8.53.0",
132
- "eslint-config-cheminfo-react": "^10.0.0",
133
- "eslint-config-cheminfo-typescript": "^12.0.4",
131
+ "cspell": "^8.1.3",
132
+ "eslint": "^8.55.0",
133
+ "eslint-config-cheminfo-react": "^10.1.0",
134
+ "eslint-config-cheminfo-typescript": "^12.1.0",
134
135
  "modern-normalize": "^2.0.0",
135
136
  "postcss-styled-syntax": "^0.5.0",
136
- "prettier": "^3.0.3",
137
- "rc-menu": "^9.12.2",
137
+ "prettier": "^3.1.1",
138
+ "rc-menu": "^9.12.4",
138
139
  "react": "^18.2.0",
139
140
  "react-dom": "^18.2.0",
140
- "react-router-dom": "^6.18.0",
141
+ "react-router-dom": "^6.21.0",
141
142
  "rimraf": "^5.0.5",
142
143
  "rollup-plugin-analyzer": "^4.0.0",
143
144
  "serve": "^14.2.1",
144
- "stylelint": "^15.11.0",
145
- "stylelint-config-standard": "^34.0.0",
146
- "typescript": "^5.2.2",
147
- "vite": "^4.5.0",
148
- "vitest": "^0.34.6"
145
+ "stylelint": "^16.0.2",
146
+ "stylelint-config-standard": "^35.0.0",
147
+ "typescript": "^5.3.3",
148
+ "vite": "^5.0.8",
149
+ "vitest": "^1.0.4"
149
150
  }
150
151
  }
@@ -1,18 +0,0 @@
1
- import { ReactNode } from 'react';
2
- interface MenuItemProps {
3
- icon: ReactNode;
4
- label: string;
5
- onClick?: () => void;
6
- }
7
- interface MenuButtonProps {
8
- component: ReactNode;
9
- toolTip: string;
10
- items?: Array<MenuItemProps & {
11
- id: string;
12
- }>;
13
- onClick?: (element: MenuItemProps & {
14
- id: string;
15
- }) => void;
16
- }
17
- export default function ToolbarMenu({ component, toolTip, items, onClick, }: MenuButtonProps): import("@emotion/react/jsx-runtime").JSX.Element;
18
- export {};
@@ -1,102 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
- /** @jsxImportSource @emotion/react */
3
- import { css } from '@emotion/react';
4
- import { useState, useCallback, useRef, useLayoutEffect, } from 'react';
5
- import { Toolbar } from 'react-science/ui';
6
- const menuStyles = css `
7
- .menu {
8
- box-shadow: 0 0 10px rgb(0 0 0 / 50%);
9
- margin: 0;
10
- border-radius: 5px;
11
- display: flex;
12
- flex-direction: column;
13
- position: absolute;
14
- z-index: 99999;
15
- padding: 2px;
16
- background-color: white;
17
-
18
- button:hover {
19
- background-color: #fafafa;
20
- }
21
- }
22
-
23
- .menu-cover {
24
- position: fixed;
25
- width: 100%;
26
- height: 100%;
27
- top: 0;
28
- left: 0;
29
- z-index: 1;
30
- }
31
-
32
- .menu-item {
33
- background-color: transparent;
34
- border: none;
35
- border-bottom: 0.55px solid whitesmoke;
36
- height: 35px;
37
- outline: outline;
38
- display: table-cell;
39
- vertical-align: middle;
40
- text-align: left;
41
- padding: 0 10px;
42
-
43
- svg {
44
- display: inline-block;
45
- }
46
-
47
- :focus {
48
- outline: none !important;
49
- }
50
-
51
- span {
52
- font-size: 10px;
53
- padding: 0 10px;
54
- }
55
- }
56
- `;
57
- function MenuItem({ icon, label, onClick }) {
58
- return (_jsxs("button", { type: "button", className: "menu-item", onClick: onClick, children: [icon, _jsx("span", { children: label })] }));
59
- }
60
- function MenuList({ items, boxBounding = { x: 0, y: 0, width: 0, height: 0 }, onClick, }) {
61
- const listRef = useRef();
62
- const [translate, setTranslate] = useState({
63
- x: boxBounding.width,
64
- y: boxBounding.height,
65
- });
66
- useLayoutEffect(() => {
67
- const boxSize = listRef.current.getBoundingClientRect();
68
- setTranslate((oldTransform) => {
69
- let y = boxBounding.height;
70
- if (boxSize.bottom > window.innerHeight) {
71
- y = boxBounding.height * 2 + (boxSize.bottom - window.innerHeight);
72
- }
73
- return {
74
- ...oldTransform,
75
- y,
76
- };
77
- });
78
- }, [boxBounding.height]);
79
- return (_jsx("div", { ref: listRef, className: "menu", style: {
80
- transform: `translate(${translate.x}px, -${translate.y}px) `,
81
- }, children: items?.map((item) => {
82
- return (_jsx(MenuItem, { ...item, onClick: () => onClick(item) }, item.id));
83
- }) }));
84
- }
85
- export default function ToolbarMenu({ component, toolTip = '', items = [], onClick = () => null, }) {
86
- const menuButtonRef = useRef(null);
87
- const [isShown, showMenu] = useState(false);
88
- const closeMenuButton = useCallback(() => {
89
- showMenu(false);
90
- }, []);
91
- const handleClick = useCallback(() => {
92
- showMenu((flag) => !flag);
93
- }, []);
94
- const clickHandler = useCallback((e) => {
95
- showMenu(false);
96
- onClick(e);
97
- }, [onClick]);
98
- const boxBounding = useCallback(() => {
99
- return menuButtonRef.current?.getBoundingClientRect();
100
- }, []);
101
- return (_jsxs("div", { style: { height: 'auto' }, css: menuStyles, children: [_jsx("div", { ref: menuButtonRef, children: _jsx(Toolbar.Item, { id: `menu-${toolTip}`, title: toolTip, active: isShown, onClick: handleClick, children: component }) }), isShown && (_jsx(MenuList, { items: items, boxBounding: boxBounding(), onClick: clickHandler })), isShown && _jsx("div", { className: "menu-cover", onClick: closeMenuButton })] }));
102
- }
@@ -1,13 +0,0 @@
1
- import { ReactElement } from 'react';
2
- interface ToggleButtonProps {
3
- isActive?: boolean;
4
- value?: any;
5
- onChange?: (value: any) => null;
6
- children: ReactElement;
7
- isVisible?: boolean;
8
- }
9
- export default function ToggleButton(props: ToggleButtonProps & {
10
- title: string;
11
- id: string;
12
- }): import("react/jsx-runtime").JSX.Element | null;
13
- export {};
@@ -1,24 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useCallback, useState, useEffect } from 'react';
3
- import { Toolbar } from 'react-science/ui';
4
- export default function ToggleButton(props) {
5
- const { children, value = null, isActive = false, onChange = () => null, isVisible = true, id, title, } = props;
6
- const [active, setActive] = useState(props.isActive);
7
- const toggleButton = useCallback(() => {
8
- const _isActive = !active;
9
- setActive(_isActive);
10
- if (_isActive) {
11
- onChange(value);
12
- }
13
- else {
14
- onChange(null);
15
- }
16
- }, [active, onChange, value]);
17
- useEffect(() => {
18
- setActive(isActive);
19
- }, [isActive]);
20
- if (!isVisible) {
21
- return null;
22
- }
23
- return (_jsx(Toolbar.Item, { onClick: toggleButton, title: title, id: id, active: active, children: children }));
24
- }
@@ -1,8 +0,0 @@
1
- import { ReactNode } from 'react';
2
- interface ToggleButtonGroupProps {
3
- children: ReactNode;
4
- value: string;
5
- onChange?: (value: any) => void;
6
- }
7
- export default function ToggleButtonGroup({ children, value, onChange, }: ToggleButtonGroupProps): import("react/jsx-runtime").JSX.Element;
8
- export {};
@@ -1,48 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import { useCallback, useState, useMemo, useEffect, Children, cloneElement, } from 'react';
3
- import ToggleButton from './ToggleButton';
4
- export default function ToggleButtonGroup({ children, value, onChange = () => null, }) {
5
- const [toggleButtons, setToggleButtons] = useState([]);
6
- const handleOnChange = useCallback((val) => {
7
- const _toggles = [...toggleButtons];
8
- const toggles = _toggles.map((toggle) => {
9
- return {
10
- value: toggle.value,
11
- isActive: toggle.value === val,
12
- };
13
- });
14
- setToggleButtons(toggles);
15
- onChange(val);
16
- }, [onChange, toggleButtons]);
17
- const mappedChildren = useMemo(() => {
18
- let index = 0;
19
- return Children.map(children, (child) => {
20
- if (child) {
21
- if (child.type === ToggleButton) {
22
- const _child = cloneElement(child, {
23
- onChange: handleOnChange,
24
- isActive: toggleButtons[index]?.isActive,
25
- index,
26
- });
27
- index++;
28
- return _child;
29
- }
30
- else {
31
- return cloneElement(child);
32
- }
33
- }
34
- });
35
- }, [children, handleOnChange, toggleButtons]);
36
- useEffect(() => {
37
- const val = Children.map(children, (child) => {
38
- if (child && child.type === ToggleButton) {
39
- return {
40
- value: child.props.value,
41
- isActive: child.props.value === value,
42
- };
43
- }
44
- });
45
- setToggleButtons(val);
46
- }, [children, value]);
47
- return _jsx(_Fragment, { children: mappedChildren });
48
- }
@@ -1,17 +0,0 @@
1
- import { NmrData1D } from 'cheminfo-types';
2
- /**
3
- *
4
- * @param {object<{x:Array<number>,re:Array<number>}>} data
5
- * @param {object<{from:number,to:number}>} options
6
- */
7
- interface LookupPeakOptions {
8
- from: number;
9
- to: number;
10
- }
11
- interface LookupPeakResult {
12
- x: number;
13
- y: number;
14
- xIndex: number;
15
- }
16
- export declare function lookupPeak(data: NmrData1D, options: LookupPeakOptions): LookupPeakResult | null;
17
- export {};
@@ -1,18 +0,0 @@
1
- import max from 'ml-array-max';
2
- export function lookupPeak(data, options) {
3
- const { from, to } = options;
4
- let minIndex = data.x.findIndex((number) => number >= from);
5
- let maxIndex = data.x.findIndex((number) => number >= to) - 1;
6
- if (minIndex > maxIndex) {
7
- minIndex = maxIndex;
8
- maxIndex = minIndex;
9
- }
10
- const dataRange = data.re.slice(minIndex, maxIndex);
11
- if (dataRange && dataRange.length > 0) {
12
- const yValue = max(dataRange);
13
- const xIndex = dataRange.indexOf(yValue);
14
- const xValue = data.x[minIndex + xIndex];
15
- return { x: xValue, y: yValue, xIndex: minIndex + xIndex };
16
- }
17
- return null;
18
- }
@@ -1,32 +0,0 @@
1
- export declare const defaultContourOptions: {
2
- positive: {
3
- contourLevels: number[];
4
- numberOfLayers: number;
5
- };
6
- negative: {
7
- contourLevels: number[];
8
- numberOfLayers: number;
9
- };
10
- };
11
- export default class Processing2D {
12
- private options;
13
- private currentLevelPositive;
14
- private currentLevelNegative;
15
- private conrec;
16
- private median;
17
- private minMax;
18
- constructor(minMax: any, options?: any, defaultLevel?: any);
19
- getLevel(): {
20
- levelPositive: number;
21
- levelNegative: number;
22
- };
23
- setLevel(levelPositive: any, levelNegative: any): void;
24
- setOptions(options: any): void;
25
- wheel(value: any): void;
26
- shiftWheel(value: any): never[] | undefined;
27
- drawContours(): {
28
- positive: Readonly<import("ml-conrec").DrawContourResult<"basic">>;
29
- negative: Readonly<import("ml-conrec").DrawContourResult<"basic">>;
30
- };
31
- getContours(zoomLevel: any, options?: any): Readonly<import("ml-conrec").DrawContourResult<"basic">>;
32
- }
@@ -1,130 +0,0 @@
1
- import { Conrec } from 'ml-conrec';
2
- import { calculateSanPlot } from '../utilities/calculateSanPlot';
3
- export const defaultContourOptions = {
4
- positive: {
5
- contourLevels: [0, 21],
6
- numberOfLayers: 10,
7
- },
8
- negative: {
9
- contourLevels: [0, 21],
10
- numberOfLayers: 10,
11
- },
12
- };
13
- export default class Processing2D {
14
- constructor(minMax, options = defaultContourOptions, defaultLevel = {}) {
15
- this.options = options;
16
- const { positive = 10, negative = 10 } = defaultLevel;
17
- this.currentLevelPositive = positive;
18
- this.currentLevelNegative = negative;
19
- const xs = getRange(minMax.minX, minMax.maxX, minMax.z[0].length);
20
- const ys = getRange(minMax.minY, minMax.maxY, minMax.z.length);
21
- this.conrec = new Conrec(minMax.z, { xs, ys, swapAxes: false });
22
- const sanResult = calculateSanPlot('2D', minMax);
23
- this.median = sanResult.positive;
24
- this.minMax = minMax;
25
- }
26
- getLevel() {
27
- return {
28
- levelPositive: this.currentLevelPositive,
29
- levelNegative: this.currentLevelNegative,
30
- };
31
- }
32
- setLevel(levelPositive, levelNegative) {
33
- this.currentLevelPositive = levelPositive;
34
- this.currentLevelNegative = levelNegative;
35
- }
36
- setOptions(options) {
37
- const positiveBoundary = options.positive.contourLevels;
38
- const negativeBoundary = options.negative.contourLevels;
39
- if (this.currentLevelPositive >= positiveBoundary[1]) {
40
- this.currentLevelPositive = positiveBoundary[1];
41
- }
42
- else if (this.currentLevelPositive <= positiveBoundary[0]) {
43
- this.currentLevelPositive = positiveBoundary[0];
44
- }
45
- if (this.currentLevelNegative >= negativeBoundary[1]) {
46
- this.currentLevelNegative = negativeBoundary[1];
47
- }
48
- else if (this.currentLevelNegative <= negativeBoundary[0]) {
49
- this.currentLevelNegative = negativeBoundary[0];
50
- }
51
- this.options = options;
52
- }
53
- wheel(value) {
54
- const sign = Math.sign(value);
55
- const positiveBoundary = this.options.positive.contourLevels;
56
- const negativeBoundary = this.options.negative.contourLevels;
57
- if ((this.currentLevelPositive > positiveBoundary[0] && sign === -1) ||
58
- (this.currentLevelPositive < positiveBoundary[1] && sign === 1)) {
59
- this.currentLevelPositive += sign;
60
- }
61
- if ((this.currentLevelNegative > negativeBoundary[0] && sign === -1) ||
62
- (this.currentLevelNegative < negativeBoundary[1] && sign === 1)) {
63
- this.currentLevelNegative += sign;
64
- }
65
- }
66
- shiftWheel(value) {
67
- const sign = Math.sign(value);
68
- const [min, max] = this.options.positive.contourLevels;
69
- if ((this.currentLevelPositive === min && sign === -1) ||
70
- (this.currentLevelPositive >= max && sign === 1)) {
71
- return;
72
- }
73
- this.currentLevelPositive += sign;
74
- return [];
75
- }
76
- drawContours() {
77
- const zoomPositive = this.currentLevelPositive / 2 + 1;
78
- const zoomNegative = this.currentLevelNegative / 2 + 1;
79
- const { positive: { numberOfLayers: numberOfPositiveLayer }, negative: { numberOfLayers: numberOfNegativeLayer }, } = this.options;
80
- return {
81
- positive: this.getContours(zoomPositive, {
82
- nbLevels: numberOfPositiveLayer,
83
- }),
84
- negative: this.getContours(zoomNegative, {
85
- negative: true,
86
- nbLevels: numberOfNegativeLayer,
87
- }),
88
- };
89
- }
90
- getContours(zoomLevel, options = {}) {
91
- const { negative = false, timeout = 2000, nbLevels = 10 } = options;
92
- const max = Math.max(Math.abs(this.minMax.maxZ), Math.abs(this.minMax.minZ));
93
- let _range = getRange(this.median * 1 * Math.pow(2, zoomLevel), max, nbLevels, 2);
94
- if (negative) {
95
- _range = _range.map((value) => -value);
96
- }
97
- const contours = this.conrec.drawContour({
98
- contourDrawer: 'basic',
99
- levels: _range,
100
- timeout,
101
- });
102
- return Object.freeze(contours);
103
- }
104
- }
105
- function getRange(min, max, length, exp) {
106
- if (exp !== undefined) {
107
- const factors = [];
108
- factors[0] = 0;
109
- for (let i = 1; i <= length; i++) {
110
- factors[i] = factors[i - 1] + (exp - 1) / Math.pow(exp, i);
111
- }
112
- const lastFactor = factors[length];
113
- const result = new Array(length);
114
- for (let i = 0; i < length; i++) {
115
- result[i] = (max - min) * (1 - factors[i + 1] / lastFactor) + min;
116
- }
117
- return result;
118
- }
119
- else {
120
- const step = (max - min) / (length - 1);
121
- return range(min, max + step / 2, step);
122
- }
123
- }
124
- function range(from, to, step) {
125
- const result = [];
126
- for (let i = from; i < to; i += step) {
127
- result.push(i);
128
- }
129
- return result;
130
- }