+var api_base_url_sensors = '/api/1/sensor/type/Wassertemperatur?mode=consolidated&format=c3';
+var api_base_url_weather = '/api/1/openweathermap/city/3319578?mode=consolidated&format=c3';
+var api_url_currentair = '/api/1/currentairtemperature';
+var api_url_currentwater = '/api/1/currentwatertemperature';
+var refresh_interval = 5 * 60 * 1000;
+
+function dayschart(element, title, days, xtickformat) {
+ var chartdata;
+ if (element.substr(0, 7) == 'chart_w') {
+ chartdata = {
+ url: api_base_url_sensors + beginend(days),
+ mimeType: 'json',
+ xs: {
+ '0416a1ac66ff': '0416a1ac66ff_x',
+ '0516a207a4ff': '0516a207a4ff_x',
+ '0416a1bab9ff': '0416a1bab9ff_x',
+ '0316a2193bff': '0316a2193bff_x'
+ },
+ names: {
+ '0416a1ac66ff': 'Wassertemperatur 30cm Tiefe',
+ '0516a207a4ff': 'Wassertemperatur 50cm Tiefe',
+ '0416a1bab9ff': 'Wassertemperatur 1m Tiefe',
+ '0316a2193bff': 'Wassertemperatur in 30 cm Tiefe'
+ },
+ xFormat: '%Y-%m-%d %H:%M:%S',
+ // https://en.wikipedia.org/wiki/Web_colors
+ colors: {
+ '0416a1ac66ff': 'lightskyblue',
+ '0516a207a4ff': 'royalblue',
+ '0416a1bab9ff': 'mediumblue',
+ '0316a2193bff': 'midnightblue'
+ },
+ /*
+ xSort: false,
+ order: function (a, b) {
+ // gets 2 x objects. seems to be a "sort function" for js's sort()
+ // -1: a before b etc.
+ // only handle cases that appear in the wild
+ // console.log("a.id", a.id, "b.id", b.id);
+ if (a.id == '0416a1ac66ff') {return -1};
+ if (a.id == '0416a1bab9ff') {return 1};
+ }
+ */
+ };
+ } else {
+ chartdata = {
+ url: api_base_url_weather + beginend(days),
+ mimeType: 'json',
+ xs: {
+ '3319578': '3319578_x'
+ },
+ names: {
+ '3319578': 'Lufttemperatur in Obsteig'
+ },
+ xFormat: '%Y-%m-%d %H:%M:%S',
+ colors: {
+ '3319578': 'red'
+ }
+ };
+ };
+ var chart = c3.generate({
+ bindto: '#' + element,
+ size: {
+ width: getwidth(element)
+ },
+ onresized: function () {
+ chart.resize({
+ width: getwidth(element)
+ });
+ // chart.flush();
+ },
+ transition: {
+ duration: null
+ },
+ title: {
+ text: title
+ },
+ data: chartdata,
+ point: {
+ r: 1.5 // default 2.5
+ },
+ axis: {
+ x: {
+ type: 'timeseries',
+ tick: {
+ format: function (d) {
+ var strftimeDE = strftime.localizeByIdentifier('de_DE');
+ return strftimeDE(xtickformat, new Date(d));
+ },
+ fit: false,
+ multiline: true, // broken? so →
+ rotate: -90
+ }
+ },
+ y: {
+ label: {
+ text: 'Temperatur in °C',
+ position: 'outer-middle'
+ },
+ tick: {
+ format: function (d) {
+ return d.toFixed(1) + '°';
+ }
+ }