*** WIP WIP *** All charts work (mostly)

This commit is contained in:
rxf
2023-03-31 17:38:55 +02:00
parent 1cdf03b064
commit a1c1c93bc4
7 changed files with 69 additions and 19 deletions
+1 -11
View File
@@ -10,7 +10,7 @@ import * as chart_dayavg from './chart_dayavg.js'
import * as chart_daynight from './chart_daynight.js' import * as chart_daynight from './chart_daynight.js'
import * as chart_lden from './chart_lden.js' import * as chart_lden from './chart_lden.js'
import * as utils from "./chart_utilities.js"; import * as utils from "./chart_utilities.js";
import {showChart} from './showcharts.js' import {tabtable} from './showcharts.js'
(async () => { (async () => {
@@ -34,16 +34,6 @@ import {showChart} from './showcharts.js'
} }
// END global variables // END global variables
// table to distribute the different charts
const tabtable = [
{id: 'kartentab', type: 'map', container: 'map', func: map.showMap},
{id: 'livetab', type: 'live', container: 'dlive', func: showChart},
{id: 'houravgtab', type: 'havg', container: 'dhour', func: showChart},
{id: 'dayavgtab', type: 'davg', container: 'dday', func: showChart},
{id: 'daynighttab', type: 'daynight', container: 'ddaynight', func: showChart},
{id: 'ldentab', type: 'lden', container: 'dlden', func: showChart},
]
// remove the taps (if shownig the map) // remove the taps (if shownig the map)
const removeTabs = () => { const removeTabs = () => {
+1 -1
View File
@@ -13,7 +13,7 @@ let clickedSensor = 0
const colorscale = ['#d53e4f', '#fc8d59', '#fee08b', '#e6f598', '#99d594', '#3288bd', '#808080']; const colorscale = ['#d53e4f', '#fc8d59', '#fee08b', '#e6f598', '#99d594', '#3288bd', '#808080'];
const dba = [100, 80, 60, 40, 20, 0, -999]; const dba = [100, 80, 60, 40, 20, 0, -999];
export const showMap = async (params) => { export async function showMap(params) {
if (map) return if (map) return
map = L.map('map',{ scrollWheelZoom: false}).setView(params.center, parseInt(params.zoom)) map = L.map('map',{ scrollWheelZoom: false}).setView(params.center, parseInt(params.zoom))
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
+61 -1
View File
@@ -1,15 +1,75 @@
import {logerror} from "./logit.js"; import {logerror} from "./logit.js";
import * as utils from "./chart_utilities.js"; import * as utils from "./chart_utilities.js";
import { DateTime } from './luxon.min.js'
import * as map from "./map.js";
// table to distribute the different charts
export const tabtable = [
{id: 'kartentab', type: 'map', container: 'map', func: map.showMap, div: null, dformat: null},
{id: 'livetab', type: 'live', container: 'dlive', func: showChart, div: 100, dformat: "dd.LL - HH:mm:ss"},
{id: 'houravgtab', type: 'havg', container: 'dhour', func: showChart, div: 10, dformat: "dd.LL - HH'h'"},
{id: 'dayavgtab', type: 'davg', container: 'dday', func: showChart, div: 10, dformat: "dd.LL"},
{id: 'daynighttab', type: 'daynight', container: 'ddaynight', func: showChart, div: 10, dformat: "dd.LL"},
{id: 'ldentab', type: 'lden', container: 'dlden', func: showChart, div: 10, dformat: "dd.LL"},
]
export async function showChart(params, typ, container) { export async function showChart(params, typ, container) {
const url = `/chart/getsensordata?&sensorid=${params.sid}&data=${typ}` function form() {
for(let item of tabtable) {
if (item.type === typ) {
const d = DateTime.fromMillis(this.x, {zone: 'utc'})
const d1 = d.plus({days: 1})
let fmt = d.toFormat(item.dformat)
if(((typ === 'daynight') && (this.series.name.startsWith('N'))) || (typ === 'lden')) {
fmt = `${d.toFormat('dd')}/${d1.toFormat('dd.LL')}`
}
let y = Math.round(this.y * item.div) / item.div
return '<div style="border: 2px solid ' + this.point.color + '; padding: 3px;">' +
fmt + '<br />' +
'<span style="color: ' + this.point.color + '">&#9679;&nbsp;</span>' +
this.series.name + ':&nbsp; <b>' + y + '</b></div>'
}
}
}
function xformat() {
if(typ === 'lden') {
let lbl = this.axis.defaultLabelFormatter.call(this);
this.value += 86400000;
let lbl1 = this.axis.defaultLabelFormatter.call(this);
return parseInt(lbl) + '/' + lbl1;
} else if ((typ === 'live') || (typ === 'havg')) {
let v = this.axis.defaultLabelFormatter.call(this);
if (v.indexOf(':') == -1) {
return '<span style="font-weight:bold;color:red">' + v + '<span>';
} else {
return v;
}
} else {
return this.axis.defaultLabelFormatter.call(this);
}
}
const url = `/chart/getsensordata?sensorid=${params.sid}&data=${typ}`
let ret = await fetch(url) let ret = await fetch(url)
.catch(e => { .catch(e => {
logerror(e) logerror(e)
}); });
let erg = await ret.json() let erg = await ret.json()
erg.options.xAxis.labels.formatter = xformat
erg.options.tooltip.formatter = form
let chr = Highcharts.chart(container, erg.options, function (chart) { let chr = Highcharts.chart(container, erg.options, function (chart) {
utils.addSensorID2chart(chart, {sid: erg.params.sensorid, indoor: erg.params.indoor}, document.getElementById(container).offsetWidth) utils.addSensorID2chart(chart, {sid: erg.params.sensorid, indoor: erg.params.indoor}, document.getElementById(container).offsetWidth)
}) })
if((typ === 'havg') || (typ === 'davg')) {
erg.options2.tooltip.formatter = form
erg.options2.xAxis.labels.formatter = xformat
let ch1 = Highcharts.chart(typ === 'havg' ? 'dpeak1' : 'dpeak2', erg.options2)
} }
}
+1 -2
View File
@@ -154,9 +154,8 @@ footer #author #versn {
margin-top: 44px; margin-top: 44px;
} }
#dlive, #dhour, #dday, #ddaynight, #dlden, #dpeak { #dlive, #dhour, #dday, #ddaynight, #dlden, #dpeak1, #dpeak2 {
width: 100%; width: 100%;
height: 100%;
margin: auto; margin: auto;
} }
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sourceRoot":"","sources":["style.sass"],"names":[],"mappings":"AAWA;EACE;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAEF;EACE;EACA;EACA;EAEA;EACA;EACA;;;AAEF;EACE;;;AAEF;EACE,kBA7BoB;;AA+BpB;EACE;EACA;EACA;EACA;;AAEF;EACE;EACA;EACA;EACA;;AAEF;EACE;EACA;;;AAEJ;EACE;EACA;EACA;EACA;;AAEA;EACE;EACA;;AAEF;EACE;EACA;;AACA;EACE;;;AAEN;EACE;EAEA;EACA;EACA,eA3Ec;EA4Ed;EACA;EACA;;AAEA;EACE;EACA;EACA;;AACF;EACE;EACA;;;AAEJ;EACE;EACA;EACA;EACA;;AAEA;EACE;EACA;;AACF;EACE;EACA;;;AAEJ;EACE,kBA/FoB;;AAiGpB;EACE;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAEF;EACE;;;AAGN;EACE;EACA;EACA;EACA;EACA;;;AAEF;EACE;EACA;;;AAEF;EACE;EACA;EACA;;;AAEF;EACE;EACA;EACA;EACA;EACA;;;AAEF;EACE;;;AAEF;EACE;EACA;;;AAEF;EACE;;;AAEF;EACE;EACA;EACA;;;AAEF;EACE;;;AAEF;EACE","file":"style.css"} {"version":3,"sourceRoot":"","sources":["style.sass"],"names":[],"mappings":"AAWA;EACE;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAEF;EACE;EACA;EACA;EAEA;EACA;EACA;;;AAEF;EACE;;;AAEF;EACE,kBA7BoB;;AA+BpB;EACE;EACA;EACA;EACA;;AAEF;EACE;EACA;EACA;EACA;;AAEF;EACE;EACA;;;AAEJ;EACE;EACA;EACA;EACA;;AAEA;EACE;EACA;;AAEF;EACE;EACA;;AACA;EACE;;;AAEN;EACE;EAEA;EACA;EACA,eA3Ec;EA4Ed;EACA;EACA;;AAEA;EACE;EACA;EACA;;AACF;EACE;EACA;;;AAEJ;EACE;EACA;EACA;EACA;;AAEA;EACE;EACA;;AACF;EACE;EACA;;;AAEJ;EACE,kBA/FoB;;AAiGpB;EACE;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAEF;EACE;;;AAGN;EACE;EACA;EACA;EACA;EACA;;;AAEF;EACE;EACA;;;AAEF;EACE;EACA;EACA;;;AAEF;EACE;EACA;EACA;EACA;EACA;;;AAEF;EACE;;;AAEF;EACE;EACA;;;AAEF;EACE;;;AAEF;EACE;EAEA;;;AAEF;EACE;;;AAEF;EACE","file":"style.css"}
+2 -2
View File
@@ -150,9 +150,9 @@ footer
.tab-pane .tab-pane
margin-top: 44px margin-top: 44px
#dlive, #dhour, #dday, #ddaynight, #dlden, #dpeak #dlive, #dhour, #dday, #ddaynight, #dlden, #dpeak1, #dpeak2
width: 100% width: 100%
height: 100% // height: 100%
margin: auto margin: auto
#dialogError #dialogError
+2 -1
View File
@@ -35,9 +35,10 @@ block content
#dlive #dlive
.tab-pane.fade#t_houravg(role="tabpanel" aria-labelledby="map-tab") .tab-pane.fade#t_houravg(role="tabpanel" aria-labelledby="map-tab")
#dhour #dhour
#dpeak #dpeak1
.tab-pane.fade#t_dayavg(role="tabpanel" aria-labelledby="map-tab") .tab-pane.fade#t_dayavg(role="tabpanel" aria-labelledby="map-tab")
#dday #dday
#dpeak2
.tab-pane.fade#t_daynight(role="tabpanel" aria-labelledby="map-tab") .tab-pane.fade#t_daynight(role="tabpanel" aria-labelledby="map-tab")
#ddaynight DayNightTAB #ddaynight DayNightTAB
.tab-pane.fade#t_lden(role="tabpanel" aria-labelledby="map-tab") .tab-pane.fade#t_lden(role="tabpanel" aria-labelledby="map-tab")