10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 22:03:49 +01:00

replace forEach with for of when it's relevant

This commit is contained in:
Mickaël Véril 2019-09-26 20:25:51 +02:00
parent 73abfb7371
commit f27fcf013e
2 changed files with 174 additions and 176 deletions

View File

@ -19,12 +19,12 @@ draft: false
window.dats=await loadAllData() window.dats=await loadAllData()
window.data=new CombinedData() window.data=new CombinedData()
molecules=new Set(Object.values(window.dats).flat().map((d)=>d.molecule)) molecules=new Set(Object.values(window.dats).flat().map((d)=>d.molecule))
molecules.forEach(el=>{ for (const el of molecules) {
op=document.createElement("option") op=document.createElement("option")
op.value=el op.value=el
op.innerText=el op.innerText=el
document.getElementById("select_mol").appendChild(op) document.getElementById("select_mol").appendChild(op)
}) }
} }
function select_mol_onchange(event){ function select_mol_onchange(event){
update_mol(event.target.value) update_mol(event.target.value)
@ -39,20 +39,20 @@ draft: false
update_ZPE(window.dats["ZPE"][event.target.value]) update_ZPE(window.dats["ZPE"][event.target.value])
} }
async function update_mol(molecule){ async function update_mol(molecule){
Object.keys(window.dats).forEach((key)=>{ for (const [key,dat] of Object.entries(window.dats)) {
var s=document.getElementById(String.raw`select_${key}`) var s=document.getElementById(String.raw`select_${key}`)
while (s.options[s.options.length-1].value!= "") { while (s.options[s.options.length-1].value!= "") {
s.options.remove(s.options[s.options.length-1]) s.options.remove(s.options[s.options.length-1])
} }
window.dats[key].forEach(val=>{ dat.forEach((val,index)=>{
if(val.molecule==molecule){ if(val.molecule==molecule){
var op=document.createElement("option") var op=document.createElement("option")
op.value=window.dats[key].indexOf(val) op.value=index
op.innerText=val.method.toString() op.innerText=val.method.toString()
s.appendChild(op) s.appendChild(op)
} }
}) })
}) }
} }
async function update_abs(abs){ async function update_abs(abs){
window.data.Abs=abs window.data.Abs=abs
@ -91,7 +91,7 @@ draft: false
} }
div=document.getElementById("meta_div") div=document.getElementById("meta_div")
div.innerHTML="" div.innerHTML=""
for (element of md) { for (const element of md) {
var node =null; var node =null;
switch (trueTypeOf(element)) { switch (trueTypeOf(element)) {
case "string": case "string":
@ -123,19 +123,19 @@ draft: false
} }
var tb=document.getElementById("ex_table_b"); var tb=document.getElementById("ex_table_b");
tb.innerHTML='' tb.innerHTML=''
window.data.excitations.forEach(el=> { for (const el of window.data.excitations) {
var row=document.createElement("tr") var row=document.createElement("tr")
var rowd=[] var rowd=[]
rowd.push(String.raw`${LatexInline[0]} ${el.initial.toLaTeX()} \rightarrow ${el.final.toLaTeX()}${LatexInline[1]}`) rowd.push(String.raw`${LatexInline[0]} ${el.initial.toLaTeX()} \rightarrow ${el.final.toLaTeX()}${LatexInline[1]}`)
var e=[el.Eabs,el.Efluo,el.EZPE,el.Eadia,el.Ezz] var e=[el.Eabs,el.Efluo,el.EZPE,el.Eadia,el.Ezz]
e.forEach((val)=>rowd.push(noNanPrecision(val,3))) e.forEach((val)=>rowd.push(noNanPrecision(val,3)))
rowd.forEach((d)=>{ for(d of rowd) {
td=document.createElement("td") td=document.createElement("td")
td.innerText=d td.innerText=d
row.appendChild(td) row.appendChild(td)
}) }
tb.appendChild(row) tb.appendChild(row)
}); }
await MathJax.typesetPromise(); await MathJax.typesetPromise();
document.getElementById("ex_div").hidden=false document.getElementById("ex_div").hidden=false
var plotdat = [{ var plotdat = [{

View File

@ -162,7 +162,7 @@ class dataFileBase {
dat.excitations.push(ex); dat.excitations.push(ex);
}; };
text.split("\n").forEach(function(line) { for (var line of text.split("\n")) {
//if it's not empty line //if it's not empty line
line = line.trim(); line = line.trim();
if (line) { if (line) {
@ -177,7 +177,7 @@ class dataFileBase {
readrow(line); readrow(line);
} }
} }
}); }
return dat return dat
} }
} }
@ -187,10 +187,8 @@ class oneStateDataFile extends dataFileBase {
super() super()
this.geometry = null this.geometry = null
} }
static readmetaPair(key,value,dat) static readmetaPair(key, value, dat) {
{ if (key == "geom") {
if(key=="geom")
{
dat.geometry = method.fromString(value) dat.geometry = method.fromString(value)
} }
else { else {
@ -236,40 +234,39 @@ class CombinedData{
var exs = [] var exs = []
var dic = new Map() var dic = new Map()
if (this.Abs != null) { if (this.Abs != null) {
this.Abs.excitations.forEach((el)=>{ for (const el of this.Abs.excitations) {
var key = JSON.stringify([el.initial, el.final]) var key = JSON.stringify([el.initial, el.final])
if (!dic.has(key)) { if (!dic.has(key)) {
dic.set(key, {}) dic.set(key, {})
} }
dic.get(key)["abs"] = el.value dic.get(key)["abs"] = el.value
})
} }
if (this.Fluo != null) { if (this.Fluo != null) {
this.Fluo.excitations.forEach((el)=>{ for (const el of this.Fluo.excitations) {
var key = JSON.stringify([el.initial, el.final]) var key = JSON.stringify([el.initial, el.final])
if (!dic.has(key)) { if (!dic.has(key)) {
dic.set(key, {}) dic.set(key, {})
} }
dic.get(key)["fluo"] = el.value dic.get(key)["fluo"] = el.value
}) }
} }
if (this.ZPE != null) { if (this.ZPE != null) {
this.ZPE.excitations.forEach((el)=>{ for (const el of this.ZPE.excitations) {
var key = JSON.stringify([el.initial, el.final]) var key = JSON.stringify([el.initial, el.final])
if (!dic.has(key)) { if (!dic.has(key)) {
dic.set(key, {}) dic.set(key, {})
} }
dic.get(key)["ZPE"] = el.value dic.get(key)["ZPE"] = el.value
}) }
} }
dic.forEach((value, key) => { dic.forEach((value, key) => {
var eabs = NaN var eabs = NaN
var efluo = NaN var efluo = NaN
var eZPE = NaN var eZPE = NaN
var mykey = JSON.parse(key) var mykey = JSON.parse(key)
mykey.forEach(el=>{ for (var el of mykey) {
Reflect.setPrototypeOf(el, state.prototype) Reflect.setPrototypeOf(el, state.prototype)
}) }
if ("abs" in value) { if ("abs" in value) {
eabs = value["abs"] eabs = value["abs"]
} }
@ -282,5 +279,6 @@ class CombinedData{
exs.push(new excitation(mykey[0], mykey[1], eabs, efluo, eZPE)) exs.push(new excitation(mykey[0], mykey[1], eabs, efluo, eZPE))
}) })
return exs return exs
}; }
}
} }