vzlogger/htdocs/frontend/javascripts/options.js
Jakob Hirsch 98300a7aa0 added "steps" display
this should much better represent the output from s0 electricity meters
and water meters, where we get one impuls per energy or volume unit and
(more important) the time interval depends on the throughput.
this does not make much sense for temperature, though. unfortunately,
we have currently no means to select different chart types depending
on the entity type.
also, I had to change the backend to output the starting time of the
interval (flot needs that) instead of the ending time, which changes
the "lines" chart. but since this chart is wrong for electricity and
water anyway, it doesn't realy matter, though.
2011-03-17 03:11:24 +01:00

107 lines
3.1 KiB
JavaScript

/**
* Frontend configuration
*
* @author Florian Ziegler <fz@f10-home.de>
* @author Justin Otherguy <justin@justinotherguy.org>
* @author Steffen Vogel <info@steffenvogel.de>
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package default
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
// default time interval to show
vz.options = {
language: 'de',
backendUrl: '../backend.php', // TODO default backend, store backend urls in cookies
tuples: 300,
precission: 2, // TODO update from backend capabilities?
render: 'steps',
refresh: false,
defaultInterval: 24*60*60*1000, // 1 day
timezoneOffset: -(new Date().getTimezoneOffset() * 60000) // TODO add option with timezone dropdown
};
vz.options.plot = {
colors: ['#579D1C', '#7E0021', '#FFD320', '#FF420E', '#004586', '#0084D1', '#C5000B', '#FF950E', '#4B1F6F', '#AECF00', '#314004', '#83CAFF'],
series: {
lines: { show: true },
shadowSize: 0,
points: {
show: false,
radius: 1,
//symbol: 'square'
symbol: function(ctx, x, y, radius, shadow) { // just draw simple pixels
ctx.lineWidth = 1;
ctx.strokeRect(x-1, y-1, 2, 2);
}
}
},
legend: { show: false },
xaxis: {
mode: 'time',
max: new Date().getTime(), // timeinterval to request
min: new Date().getTime() - vz.options.defaultInterval,
timeformat: '%d. %b %h:%M',
monthNames: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
tickFormatter: function(val, axis) {
var date = new Date(val + vz.options.timezoneOffset); /* add timezone offset */
return $.plot.formatDate(date, this.timeformat, this.monthNames);
}
},
yaxis: {
min: 0,
max: null
},
selection: { mode: 'x' },
crosshair: { mode: 'x' },
grid: {
hoverable: true,
autoHighlight: false
}
}
vz.options.save = function() {
for (var key in vz.options) {
if (vz.options.hasOwnProperty(key) &&
typeof vz.options[key] != 'function' &&
typeof vz.options[key] != 'object' &&
typeof vz.options[key] != 'undefined'
) {
$.setCookie('vz_' + key, vz.options[key]);
}
}
};
vz.options.load = function() {
for (var key in this) {
var value = $.getCookie('vz_' + key);
if (value !== undefined) {
switch(typeof this[key]) {
case 'string':
this[key] = value;
break;
case 'number':
this[key] = Number(value);
break;
case 'boolean':
this[key] = (value == 'true');
break;
}
}
}
};