Skip to content

Commit

Permalink
feat: update value of CdCl3 ref value and fix typo (#126) (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
baolanlequang authored Aug 16, 2023
1 parent 3bc250d commit b6db567
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 25 deletions.
3 changes: 2 additions & 1 deletion dist/components/cmd_bar/r01_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var _list_layout = require("../../constants/list_layout");
var _list_shift = require("../../constants/list_shift");
var _cfg = _interopRequireDefault(require("../../helpers/cfg"));
var _common = require("./common");
var _format = _interopRequireDefault(require("../../helpers/format"));
/* eslint-disable prefer-object-spread, function-paren-newline,
react/function-component-definition */

Expand Down Expand Up @@ -58,7 +59,7 @@ const shiftSelect = (classes, layoutSt, setShiftRefAct, shiftSt, curveSt) => {
key: ref.name
}, /*#__PURE__*/_react.default.createElement("span", {
className: (0, _classnames.default)(classes.txtOpt, 'option-sv-bar-shift')
}, `${ref.name}: ${ref.value} ppm`)));
}, `${ref.name}: ${_format.default.strNumberFixedDecimal(ref.value, 2)} ppm`)));
return /*#__PURE__*/_react.default.createElement(_FormControl.default, {
className: (0, _classnames.default)(classes.fieldShift),
variant: "outlined"
Expand Down
18 changes: 9 additions & 9 deletions dist/constants/list_shift.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const noReference = {
label: false
};
const cActicAcidD4Sept = {
name: 'Actic acid-d4 (sept)',
name: 'Acetic acid-d4 (sept)',
value: 20.0,
label: 'Actic acid-d4'
label: 'Acetic acid-d4'
};
const cActicAcidD4S = {
name: 'Actic acid-d4 (s)',
name: 'Acetic acid-d4 (s)',
value: 178.990,
label: 'Actic acid-d4'
label: 'Acetic acid-d4'
};
const cAcetoneD6Sep = {
name: 'Acetone-d6 (sep)',
Expand Down Expand Up @@ -193,14 +193,14 @@ const cTrifluoroethanolD3Broad = {
const LIST_SHIFT_13C = [noReference, cActicAcidD4Sept, cActicAcidD4S, cAcetoneD6Sep, cAcetoneD6Broad, cAcetonitrileD3Sep, cAcetonitrileD3S, cBenzeneT, cChloroformDT, cCyclohexaneD12Quin, cDichloromethaneD2Quin, cDmfD7Sep1, cDmfD7Sep2, cDmfD7T3, cDioxaneD8Quin, cDmsoD6, cEthanolD6Sep, cEthanolD6Quin, cMethanolD4Sep, cPyridineD5T1, cPyridineD5T2, cPyridineD5T3, cThfD8Quin1, cThfD8Quin2, cTmsS, cTolueneD8Sep1, cTolueneD8T2, cTolueneD8T3, cTolueneD8T4, cTolueneD8T5, cTfaDQ1, cTfaDQ2, cTrifluoroethanolD3Quin, cTrifluoroethanolD3Broad];
exports.LIST_SHIFT_13C = LIST_SHIFT_13C;
const hActicAcidD4Quin = {
name: 'Actic acid-d4 (quin)',
name: 'Acetic acid-d4 (quin)',
value: 2.04,
label: 'Actic acid-d4'
label: 'Acetic acid-d4'
};
const hActicAcidD4S = {
name: 'Actic acid-d4 (s)',
name: 'Acetic acid-d4 (s)',
value: 11.65,
label: 'Actic acid-d4'
label: 'Acetic acid-d4'
};
const hAcetoneD6Quin = {
name: 'Acetone-d6 (quin)',
Expand All @@ -222,7 +222,7 @@ const hBenzeneS = {
};
const hChloroformDS = {
name: 'Chloroform-d (s)',
value: 7.27,
value: 7.26,
label: 'CDCl$3',
nsdb: 'Chloroform-D1 (CDCl3)'
};
Expand Down
10 changes: 9 additions & 1 deletion dist/helpers/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ const formatPeaksByPrediction = function (peaks, layout, isAscend, decimal) {
};
const compareColors = idx => ['#ABB2B9', '#EDBB99', '#ABEBC6', '#D2B4DE', '#F9E79F'][idx % 5];
const mutiEntitiesColors = idx => ['#fa8231', '#f7b731', '#0fb9b1', '#2d98da', '#3867d6', '#8854d0', '#4b6584'][idx % 7];
const strNumberFixedDecimal = function (number) {
let decimal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
if (decimal <= 0) {
return `${number}`;
}
return number.toFixed(Math.max(decimal, (number.toString().split('.')[1] || []).length));
};
const Format = {
toPeakStr,
buildData,
Expand Down Expand Up @@ -518,7 +525,8 @@ const Format = {
mutiEntitiesColors,
hasMultiCurves,
isAIFLayout,
isDLSACFLayout
isDLSACFLayout,
strNumberFixedDecimal
};
var _default = Format;
exports.default = _default;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@complat/react-spectra-editor",
"version": "1.0.0-rc13",
"version": "1.0.0-rc14",
"description": "An editor to View and Edit Chemical Spectra data (NMR, IR and MS, CV, UIVIS, XRD).",
"repository": {
"type": "git",
Expand Down
30 changes: 29 additions & 1 deletion src/__tests__/units/helpers/format.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('Test format helper', () => {

it('Wrapper from specific layout', () => {
const wrapper = Format.peaksWrapper(LIST_LAYOUT.H1, shift, 0)
const expectedWrapper = {head: '1H (Actic acid-d4) = ', tail: '.'}
const expectedWrapper = {head: '1H (Acetic acid-d4) = ', tail: '.'}
expect(wrapper).toEqual(expectedWrapper)
})
})
Expand Down Expand Up @@ -367,4 +367,32 @@ describe('Test format helper', () => {
})
})

describe('Test format string number', () => {
describe('.strNumberFixedDecimal()', () => {
it('number without fixed', () => {
const strNumber = Format.strNumberFixedDecimal(2.50);
const expected = '2.5'
expect(strNumber).toEqual(expected)
})

it('number with at least 1 decimal', () => {
const strNumber = Format.strNumberFixedDecimal(2.5, 1);
const expected = '2.5'
expect(strNumber).toEqual(expected)
})

it('number with at least 2 decimal', () => {
const strNumber = Format.strNumberFixedDecimal(2.5, 2);
const expected = '2.50'
expect(strNumber).toEqual(expected)
})

it('long number with at least 2 decimal', () => {
const strNumber = Format.strNumberFixedDecimal(2.567, 2);
const expected = '2.567'
expect(strNumber).toEqual(expected)
})
})

})
})
3 changes: 2 additions & 1 deletion src/components/cmd_bar/r01_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { LIST_LAYOUT } from '../../constants/list_layout';
import { getListShift } from '../../constants/list_shift';
import Cfg from '../../helpers/cfg';
import { commonStyle } from './common';
import Format from '../../helpers/format';

const styles = () => (
Object.assign(
Expand Down Expand Up @@ -55,7 +56,7 @@ const shiftSelect = (
const content = listShift.map((ref) => (
<MenuItem value={ref} key={ref.name}>
<span className={classNames(classes.txtOpt, 'option-sv-bar-shift')}>
{ `${ref.name}: ${ref.value} ppm` }
{ `${ref.name}: ${Format.strNumberFixedDecimal(ref.value, 2)} ppm` }
</span>
</MenuItem>
));
Expand Down
18 changes: 9 additions & 9 deletions src/constants/list_shift.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const noReference = {
};

const cActicAcidD4Sept = {
name: 'Actic acid-d4 (sept)',
name: 'Acetic acid-d4 (sept)',
value: 20.0,
label: 'Actic acid-d4',
label: 'Acetic acid-d4',
};

const cActicAcidD4S = {
name: 'Actic acid-d4 (s)',
name: 'Acetic acid-d4 (s)',
value: 178.990,
label: 'Actic acid-d4',
label: 'Acetic acid-d4',
};

const cAcetoneD6Sep = {
Expand Down Expand Up @@ -230,15 +230,15 @@ const LIST_SHIFT_13C = [
];

const hActicAcidD4Quin = {
name: 'Actic acid-d4 (quin)',
name: 'Acetic acid-d4 (quin)',
value: 2.04,
label: 'Actic acid-d4',
label: 'Acetic acid-d4',
};

const hActicAcidD4S = {
name: 'Actic acid-d4 (s)',
name: 'Acetic acid-d4 (s)',
value: 11.65,
label: 'Actic acid-d4',
label: 'Acetic acid-d4',
};

const hAcetoneD6Quin = {
Expand All @@ -264,7 +264,7 @@ const hBenzeneS = {

const hChloroformDS = {
name: 'Chloroform-d (s)',
value: 7.27,
value: 7.26,
label: 'CDCl$3',
nsdb: 'Chloroform-D1 (CDCl3)',
};
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ const compareColors = (idx) => ['#ABB2B9', '#EDBB99', '#ABEBC6', '#D2B4DE', '#F9

const mutiEntitiesColors = (idx) => ['#fa8231', '#f7b731', '#0fb9b1', '#2d98da', '#3867d6', '#8854d0', '#4b6584'][idx % 7];

const strNumberFixedDecimal = (number, decimal = -1) => {
if (decimal <= 0) {
return `${number}`;
}
return number.toFixed(Math.max(decimal, (number.toString().split('.')[1] || []).length));
};

const Format = {
toPeakStr,
buildData,
Expand Down Expand Up @@ -451,6 +458,7 @@ const Format = {
hasMultiCurves,
isAIFLayout,
isDLSACFLayout,
strNumberFixedDecimal,
};

export default Format;
2 changes: 1 addition & 1 deletion stories/source/C13_DEPT135.js
Original file line number Diff line number Diff line change
Expand Up @@ -3341,7 +3341,7 @@ $$ === CHEMSPECTRA PEAK ASSIGNMENTS EDIT ===
##MAXY=266635237.0
##MINX=44.40398973029076
##MINY=-283555411.0
##$CSSOLVENTNAME=Actic acid-d4 (s)
##$CSSOLVENTNAME=Acetic acid-d4 (s)
##$CSSOLVENTVALUE=178.99
##$CSSOLVENTX=119.12759305537116
##NPOINTS=7
Expand Down
2 changes: 1 addition & 1 deletion stories/source/H1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4383,7 +4383,7 @@ $$ === CHEMSPECTRA PEAK ASSIGNMENTS EDIT ===
##MINX=-0.10814116830427345
##MINY=-18850.0
##$CSSOLVENTNAME=Chloroform-d (s)
##$CSSOLVENTVALUE=7.27
##$CSSOLVENTVALUE=7.26
##$CSSOLVENTX=3.3657939039615012
##NPOINTS=3
##PEAK ASSIGNMENTS=(XYA)
Expand Down

0 comments on commit b6db567

Please sign in to comment.