Skip to content

Commit

Permalink
feat: add threshold for multi spectra (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
baolanlequang authored Aug 19, 2024
1 parent d171a17 commit 62eeb9a
Show file tree
Hide file tree
Showing 18 changed files with 418 additions and 78 deletions.
2 changes: 1 addition & 1 deletion dist/components/cmd_bar/03_peak.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const mapStateToProps = (state, props) => (
cyclicVotaSt: state.cyclicvolta,
curveSt: state.curve,
editPeakSt: state.editPeak.present,
thresSt: state.threshold,
thresSt: state.threshold.list[state.curve.curveIdx],
layoutSt: state.layout,
shiftSt: state.shift
});
Expand Down
29 changes: 22 additions & 7 deletions dist/components/cmd_bar/r03_threshold.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,24 @@ const txtPercent = () => /*#__PURE__*/_react.default.createElement(_material.Inp
}, /*#__PURE__*/_react.default.createElement("span", {
className: "txt-percent"
}, "%"));
const setThreshold = (classes, thresVal, updateThresholdValueAct) => {
const onBlur = e => updateThresholdValueAct(e.target.value);
const onChange = e => updateThresholdValueAct(e.target.value);
const setThreshold = (classes, thresVal, updateThresholdValueAct, curveSt) => {
const {
curveIdx
} = curveSt;
const onBlur = e => updateThresholdValueAct({
value: e.target.value,
curveIdx
});
const onChange = e => updateThresholdValueAct({
value: e.target.value,
curveIdx
});
const onEnterPress = e => {
if (e.key === 'Enter') {
updateThresholdValueAct(e.target.value);
updateThresholdValueAct({
value: e.target.value,
curveIdx
});
}
};
return /*#__PURE__*/_react.default.createElement(_material.FormControl, {
Expand Down Expand Up @@ -78,14 +90,15 @@ const Threshold = _ref => {
hideThresSt,
thresValSt,
isEditSt,
curveSt,
updateThresholdValueAct,
resetThresholdValueAct,
toggleThresholdIsEditAct
} = _ref;
const thresVal = thresValSt || feature.thresRef;
return /*#__PURE__*/_react.default.createElement("span", {
className: classes.groupRight
}, setThreshold(classes, thresVal, updateThresholdValueAct), /*#__PURE__*/_react.default.createElement(_material.Tooltip, {
}, setThreshold(classes, thresVal, updateThresholdValueAct, curveSt), /*#__PURE__*/_react.default.createElement(_material.Tooltip, {
title: /*#__PURE__*/_react.default.createElement("span", {
className: "txt-sv-tp"
}, "Restore Threshold")
Expand All @@ -109,8 +122,9 @@ const mapStateToProps = (state, props) => (
// eslint-disable-line
{
hideThresSt: _cfg.default.hideCmdThres(state.layout),
isEditSt: state.threshold.isEdit,
thresValSt: parseFloat(state.threshold.value) || 0
isEditSt: state.threshold.list[state.curve.curveIdx].isEdit,
thresValSt: parseFloat(state.threshold.list[state.curve.curveIdx].value) || 0,
curveSt: state.curve
});
const mapDispatchToProps = dispatch => (0, _redux.bindActionCreators)({
updateThresholdValueAct: _threshold.updateThresholdValue,
Expand All @@ -124,6 +138,7 @@ Threshold.propTypes = {
hideThresSt: _propTypes.default.bool.isRequired,
isEditSt: _propTypes.default.bool.isRequired,
thresValSt: _propTypes.default.number.isRequired,
curveSt: _propTypes.default.object.isRequired,
updateThresholdValueAct: _propTypes.default.func.isRequired,
resetThresholdValueAct: _propTypes.default.func.isRequired,
toggleThresholdIsEditAct: _propTypes.default.func.isRequired
Expand Down
2 changes: 1 addition & 1 deletion dist/components/cmd_bar/r05_submit_btn.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const mapStateToProps = (state, props) => (
// eslint-disable-line
{
editPeakSt: state.editPeak.present,
thresSt: state.threshold,
thresSt: state.threshold.list[state.curve.curveIdx],
layoutSt: state.layout,
shiftSt: state.shift,
scanSt: state.scan,
Expand Down
2 changes: 1 addition & 1 deletion dist/components/cmd_bar/r06_predict_btn.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const mapStateToProps = (state, props) => (
editPeakSt: state.editPeak.present,
scanSt: state.scan,
shiftSt: state.shift,
thresSt: state.threshold,
thresSt: state.threshold.list[state.curve.curveIdx],
integrationSt: state.integration.present,
multiplicitySt: state.multiplicity.present,
curveSt: state.curve
Expand Down
2 changes: 1 addition & 1 deletion dist/helpers/chem.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const convertFrequency = (layout, feature) => {
return parseFloat(freq) || false;
};
const ToFrequency = exports.ToFrequency = (0, _reselect.createSelector)(getLayout, getFeature, convertFrequency);
const getThreshold = state => state.threshold ? state.threshold.value * 1.0 : false;
const getThreshold = state => state.threshold ? state.threshold.list[state.curve.curveIdx].value * 1.0 : false;
const Convert2Peak = function (feature, threshold, offset) {
let upThreshold = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
let lowThreshold = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
Expand Down
2 changes: 1 addition & 1 deletion dist/layer_prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const mapStateToProps = (state, props) => (
// eslint-disable-line
{
scanSt: state.scan,
thresSt: state.threshold,
thresSt: state.threshold.list[state.curve.curveIdx],
uiSt: state.ui
});
const mapDispatchToProps = dispatch => (0, _redux.bindActionCreators)({}, dispatch);
Expand Down
4 changes: 3 additions & 1 deletion dist/reducers/reducer_curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const setAllCurves = (state, action) => {
feature,
hasEdit,
integration
} = (0, _extractParams.extractParams)(entity, 1);
} = (0, _extractParams.extractParams)(entity, {
isEdit: true
});
// const layout = entity.layout;
const {
layout
Expand Down
222 changes: 197 additions & 25 deletions dist/reducers/reducer_threshold.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,215 @@ var _action_type = require("../constants/action_type");
/* eslint-disable prefer-object-spread, default-param-last */

const initialState = {
isEdit: true,
value: false,
upper: false,
lower: false
selectedIdx: 0,
list: [{
isEdit: true,
value: false,
upper: false,
lower: false
}]
};

// const defaultThresHold = {
// isEdit: true,
// value: false,
// upper: false,
// lower: false,
// };

const setThresHoldValue = (state, action) => {
const {
payload
} = action;
const {
list,
selectedIdx
} = state;
if (payload) {
const {
value,
curveIdx
} = payload;
const selectedThres = list[curveIdx];
const newSelectedThres = Object.assign({}, selectedThres, {
value
});
const newListThres = [...list];
newListThres[curveIdx] = newSelectedThres;
return Object.assign({}, state, {
list: newListThres,
selectedIdx: curveIdx
});
}
const selectedThres = list[selectedIdx];
const newSelectedThres = Object.assign({}, selectedThres, {
value: payload
});
const newListThres = [...list];
newListThres[selectedIdx] = newSelectedThres;
return Object.assign({}, state, {
list: newListThres
});
};
const setThresHoldUpper = (state, action) => {
const {
payload
} = action;
const {
list,
selectedIdx
} = state;
if (payload) {
const {
value,
curveIdx
} = payload;
const selectedThres = list[curveIdx];
const newSelectedThres = Object.assign({}, selectedThres, {
upper: value
});
const newListThres = [...list];
newListThres[curveIdx] = newSelectedThres;
return Object.assign({}, state, {
list: newListThres,
selectedIdx: curveIdx
});
}
const selectedThres = list[selectedIdx];
const newSelectedThres = Object.assign({}, selectedThres, {
upper: payload
});
const newListThres = [...list];
newListThres[selectedIdx] = newSelectedThres;
return Object.assign({}, state, {
list: newListThres
});
};
const setThresHoldLower = (state, action) => {
const {
payload
} = action;
const {
list,
selectedIdx
} = state;
if (payload) {
const {
value,
curveIdx
} = payload;
const selectedThres = list[curveIdx];
const newSelectedThres = Object.assign({}, selectedThres, {
lower: value
});
const newListThres = [...list];
newListThres[curveIdx] = newSelectedThres;
return Object.assign({}, state, {
list: newListThres,
selectedIdx: curveIdx
});
}
const selectedThres = list[selectedIdx];
const newSelectedThres = Object.assign({}, selectedThres, {
lower: payload
});
const newListThres = [...list];
newListThres[selectedIdx] = newSelectedThres;
return Object.assign({}, state, {
list: newListThres
});
};
const setThresHoldIsEdit = state => {
const {
list,
selectedIdx
} = state;
const selectedThres = list[selectedIdx];
const {
isEdit
} = selectedThres;
const newSelectedThres = Object.assign({}, selectedThres, {
isEdit: !isEdit
});
const newListThres = [...list];
newListThres[selectedIdx] = newSelectedThres;
return Object.assign({}, state, {
list: newListThres
});
};
const resetAll = (state, action) => {
const {
payload
} = action;
const {
list
} = state;
const newList = list.map(item => ({
isEdit: item.isEdit,
value: payload && payload.thresRef,
upper: item.upper,
lower: item.lower
}));
return Object.assign({}, state, {
selectedIdx: 0,
list: newList
});
};
const setListThreshold = (state, action) => {
const {
payload
} = action;
const {
list
} = state;
if (payload && payload.length > list.length) {
const newList = payload.map(() => ({
isEdit: true,
value: false,
upper: false,
lower: false
}));
return Object.assign({}, state, {
list: newList
});
}
return state;
};
const resetInitCommon = state => {
const {
list
} = state;
const newList = list.map(item => ({
isEdit: true,
value: item.value,
upper: item.upper,
lower: item.lower
}));
return Object.assign({}, state, {
selectedIdx: 0,
list: newList
});
};
const thresholdReducer = function () {
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
let action = arguments.length > 1 ? arguments[1] : undefined;
switch (action.type) {
case _action_type.CURVE.SET_ALL_CURVES:
return setListThreshold(state, action);
case _action_type.THRESHOLD.UPDATE_VALUE:
return Object.assign({}, state, {
value: action.payload
});
return setThresHoldValue(state, action);
case _action_type.THRESHOLD.UPDATE_UPPER_VALUE:
return Object.assign({}, state, {
upper: action.payload
});
return setThresHoldUpper(state, action);
case _action_type.THRESHOLD.UPDATE_LOWER_VALUE:
return Object.assign({}, state, {
lower: action.payload
});
return setThresHoldLower(state, action);
case _action_type.THRESHOLD.RESET_VALUE:
return Object.assign({}, state, {
value: action.payload
});
return setThresHoldValue(state, action);
case _action_type.THRESHOLD.TOGGLE_ISEDIT:
return Object.assign({}, state, {
isEdit: !state.isEdit
});
return setThresHoldIsEdit(state);
case _action_type.MANAGER.RESET_INIT_COMMON:
return Object.assign({}, state, {
isEdit: true
});
return resetInitCommon(state);
case _action_type.MANAGER.RESETALL:
return Object.assign({}, state, {
value: action.payload && action.payload.thresRef
});
return resetAll(state, action);
default:
return state;
}
Expand Down
Loading

0 comments on commit 62eeb9a

Please sign in to comment.