Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
bf1050e5
Commit
bf1050e5
authored
Feb 17, 2022
by
Eric Duminil
Browse files
Minimize JS
parent
c6fb16c8
Pipeline
#5859
passed with stage
in 2 minutes and 20 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/web_server.cpp
View file @
bf1050e5
...
...
@@ -125,11 +125,11 @@ namespace web_server {
script_template
=
PSTR
(
"<script>"
"document.body.style.cursor = 'default';"
"fetch('%s',{credentials:'include'})"
".then(r
esponse=>response
.text())"
".then(c
svText=>csvToTable(csvText)
)"
".then(
htmlTable=>addLogTableToPage(htmlTable)
)"
".then(r
=>r
.text())"
".then(c
2t
)"
".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 c
svToTable(csvTex
t){"
"
csvText=csvTex
t.trim();"
"l
ines=csvTex
t.split('
\\
n');"
"t
able
=document.createElement('table');"
"t
able
.className='pure-table-striped';"
"n=l
ine
s.length;"
"l
ine
s.forEach((l
ine
,i)=>{"
"f
ields=line
.split(';');"
"function c
2t(
t){"
"
t=
t.trim();"
"l
s=
t.split('
\\
n');"
"t
b
=document.createElement('table');"
"t
b
.className='pure-table-striped';"
"n=ls.length;"
"ls.forEach((l,i)=>{"
"f
s=l
.split(';');"
//Don't display points without time
"if (!f
ield
s[0].includes('1970-')){"
"xs.push(f
ield
s[0]);"
"data[0]['y'].push(f
ield
s[1]);"
"data[1]['y'].push(f
ield
s[2]);"
"data[2]['y'].push(f
ield
s[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){f
ield
s=['...','...','...','...']}else{return;}}"
"r
ow
=document.createElement('tr');"
"f
ield
s.forEach((f
ield,index
)=>{"
"c
ell
=document.createElement(i<2?'th':'td');"
"c
ell
.appendChild(document.createTextNode(f
ield
));"
"r
ow
.appendChild(c
ell
);});"
"t
able
.appendChild(r
ow
);});"
"return t
able
;}"
"function addLog
TableToPage(table
){document.getElementById('log').appendChild(t
able
);}"
"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);});"
"t
b
.appendChild(r);});"
"return t
b
;}"
"function addLog
(t
){document.getElementById('log').appendChild(t);}"
"</script>"
"</body>"
"</html>"
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment