Commit bf1050e5 authored by Eric Duminil's avatar Eric Duminil
Browse files

Minimize JS

parent c6fb16c8
Pipeline #5859 passed with stage
in 2 minutes and 20 seconds
......@@ -125,11 +125,11 @@ namespace web_server {
script_template = PSTR("<script>"
"document.body.style.cursor = 'default';"
"fetch('%s',{credentials:'include'})"
".then(response=>response.text())"
".then(csvText=>csvToTable(csvText))"
".then(htmlTable=>addLogTableToPage(htmlTable))"
".then(r=>r.text())"
".then(c2t)"
".then(addLog)"
".then(_=>Plotly.newPlot('graph',data,layout,{displaylogo:false}))"
".catch(e=>console.error(e));"
".catch(console.error);"
"xs=[];"
"data=[{x:xs,y:[],type:'scatter',name:'CO<sub>2</sub>',line:{color:'#2ca02c'}},"
"{x:xs,y:[],type:'scatter',name:'Temperature',yaxis:'y2',line:{color:'#ff7f0e',dash:'dot'}},"
......@@ -139,30 +139,30 @@ namespace web_server {
"yaxis2:{overlaying:'y',side:'right',ticksuffix:'°C',position:0.9,anchor:'free',range:[0,30],dtick:3},"
"yaxis3:{overlaying:'y',side:'right',ticksuffix:'%%',position:0.95,anchor:'free',range:[0,100],dtick:10}"
"};"
"function csvToTable(csvText){"
"csvText=csvText.trim();"
"lines=csvText.split('\\n');"
"table=document.createElement('table');"
"table.className='pure-table-striped';"
"n=lines.length;"
"lines.forEach((line,i)=>{"
"fields=line.split(';');"
"function c2t(t){"
"t=t.trim();"
"ls=t.split('\\n');"
"tb=document.createElement('table');"
"tb.className='pure-table-striped';"
"n=ls.length;"
"ls.forEach((l,i)=>{"
"fs=l.split(';');"
//Don't display points without time
"if (!fields[0].includes('1970-')){"
"xs.push(fields[0]);"
"data[0]['y'].push(fields[1]);"
"data[1]['y'].push(fields[2]);"
"data[2]['y'].push(fields[3]);"
"if (!fs[0].includes('1970-')){"
"xs.push(fs[0]);"
"data[0]['y'].push(fs[1]);"
"data[1]['y'].push(fs[2]);"
"data[2]['y'].push(fs[3]);"
"};"
"if(i>4 && i<n-12){if(i==5){fields=['...','...','...','...']}else{return;}}"
"row=document.createElement('tr');"
"fields.forEach((field,index)=>{"
"cell=document.createElement(i<2?'th':'td');"
"cell.appendChild(document.createTextNode(field));"
"row.appendChild(cell);});"
"table.appendChild(row);});"
"return table;}"
"function addLogTableToPage(table){document.getElementById('log').appendChild(table);}"
"if(i>4 && i<n-12){if(i==5){fs=['...','...','...','...']}else{return;}}"
"r=document.createElement('tr');"
"fs.forEach((f,_)=>{"
"c=document.createElement(i<2?'th':'td');"
"c.appendChild(document.createTextNode(f));"
"r.appendChild(c);});"
"tb.appendChild(r);});"
"return tb;}"
"function addLog(t){document.getElementById('log').appendChild(t);}"
"</script>"
"</body>"
"</html>");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment