isotopic-distribution
Advanced tools
Comparing version 1.1.17 to 1.2.0
{ | ||
"name": "isotopic-distribution", | ||
"version": "1.1.17", | ||
"version": "1.2.0", | ||
"description": "Calculate the isotopic distribution of a molecular formula", | ||
@@ -22,7 +22,7 @@ "main": "src/index.js", | ||
"chemical-elements": "^1.1.10", | ||
"mf-parser": "^1.3.1", | ||
"mf-utilities": "^1.2.8", | ||
"mf-parser": "^1.3.2", | ||
"mf-utilities": "^1.2.9", | ||
"spectrum-generator": "^4.6.0" | ||
}, | ||
"gitHead": "d5a9a9672ccaa6a632ef89c815d42385b7ab36af" | ||
"gitHead": "b01931558f4a134c6e8547a379bada50af8ba8fc" | ||
} |
@@ -166,2 +166,12 @@ 'use strict'; | ||
it('create distribution of C10 and getXY with sumValue to 1', () => { | ||
let isotopicDistribution = new IsotopicDistribution('C10'); | ||
let xy = isotopicDistribution.getXY({ sumValue: 100 }); | ||
expect(isotopicDistribution.confidence).toBeGreaterThan(0.99999); | ||
expect(xy.x[0]).toStrictEqual(120); | ||
expect( | ||
xy.y.reduce((previous, current) => previous + current, 0), | ||
).toStrictEqual(100); | ||
}); | ||
it('create distribution of Ru5 and getXY', () => { | ||
@@ -168,0 +178,0 @@ let isotopicDistribution = new IsotopicDistribution('Ru5'); |
@@ -210,12 +210,26 @@ 'use strict'; | ||
getSumY(points) { | ||
let sumY = 0; | ||
for (let point of points) { | ||
sumY += point.y; | ||
} | ||
return sumY; | ||
} | ||
/** | ||
* Returns the isotopic distirubtion | ||
* @param {object} [options={}] | ||
* @param {number} [options.maxValue=100] | ||
* @param {number} [options.sumValue] // if sumValue is defined, maxValue is ignored | ||
* @return {XY} an object containing 2 properties: x:[] and y:[] | ||
*/ | ||
getXY(options = {}) { | ||
const { maxValue = 100 } = options; | ||
const { maxValue = 100, sumValue } = options; | ||
let points = this.getDistribution().array; | ||
if (points.length === 0) return []; | ||
let factor = 1; | ||
if (maxValue) { | ||
if (sumValue) { | ||
let sumY = this.getSumY(points); | ||
factor = sumY / sumValue; | ||
} else if (maxValue) { | ||
let maxY = this.getMaxY(points); | ||
@@ -222,0 +236,0 @@ factor = maxY / maxValue; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39004
1026
Updatedmf-parser@^1.3.2
Updatedmf-utilities@^1.2.9