First running version

This commit is contained in:
rxf
2023-03-24 13:49:54 +01:00
parent be8d364116
commit d10b274fe0
18 changed files with 1377 additions and 645 deletions
+112
View File
@@ -0,0 +1,112 @@
// Sh0w the hour average chart
import {logit, logerror} from './logit.js'
import * as utils from './chart_utilities.js'
import {DateTime, Duration} from "./luxon.min.js"
// ******************************************************************
// PlotLDEN_Noise
// ******************************************************************
export const showLden = async (params) => {
await PlotLDEN_Noise(params.sid)
}
const PlotLDEN_Noise = async function (sid) {
let series1 = []
// read the data from the server
const url = `${utils.url}/getsensordata?sensorid=${sid}&data=lden`
let ret = await fetch(url)
.catch(e => {
logerror(e)
})
let data = await ret.json()
if (!data.err) {
// Put values into the serieses
let cnt = 0
data.values.forEach((x) => {
if(x.n_AVG != -1) {
let dat = new Date(x.datetime).getTime() // retrieve the date
series1.push([dat, x.lden])
}
})
} else {
utils.showError(data.err)
}
let dlt = DateTime.now() // retrieve the date
dlt = dlt.minus({day:30})
// Plot-Options
let options = utils.createGlobObtions()
options.xAxis.plotBands = utils.calcWeekends(data, true)
options.xAxis.tickInterval = 24 * 3600 * 1000
options.xAxis.title = 'Date'
options.xAxis.labels = {
formatter: function () {
let lbl = this.axis.defaultLabelFormatter.call(this);
this.value += 86400000;
let lbl1 = this.axis.defaultLabelFormatter.call(this);
return parseInt(lbl) + '/' + lbl1;
}
}
options.chart.type = 'column'
options.yAxis = {
title: {
text: 'dbA',
useHTML: true,
},
min: utils.noise_ymin,
tickAmount: 10,
gridLineColor: 'lightgray',
}
options.series = [
{
name: 'lden',
data: series1,
color: utils.colors.eq,
type: 'column',
zIndex: 2,
}
]
options.plotOptions.series = {
animation: false
}
options.plotOptions.column = {
pointWidth: 20,
groupPadding: 0.1
}
options.title.text = 'Noise L<sub>DEN</sub>-Index'
options.subtitle.text = 'Daily mean values of L<sub>DEN</sub>\-Index'
options.subtitle.useHTML = true
options.chart.zoomType = 'x'
options.chart.resetZoomButton= {
position: {
align: 'left',
// verticalAlign: 'bottom',
x: 20,
y: 300,
},
relativeTo: 'chart'
}
options.tooltip.formatter = function () {
let d = DateTime.fromMillis(this.x, {zone: 'utc'})
let d1 = d.plus({days: 1})
let txt = d.toFormat('dd') + '/' + d1.toFormat('dd.LL')
return '<div style="border: 2px solid ' + this.point.color + '; padding: 3px;">' +
'&nbsp;&nbsp;' + txt + '<br />' +
'<span style="color: ' + this.point.color + '">&#9679;&nbsp;</span>' +
this.series.name + ':&nbsp; <b>' +
Highcharts.numberFormat(this.y, 1) +
'</b></div>';
}
let ch = Highcharts.chart('dlden', options, function (chart) {
utils.addSensorID2chart(chart, {sid: data.sid, indoor: data.indoor}, document.getElementById('dlden').offsetWidth)
})
}