Skip to content

Commit

Permalink
Add maxPrecison number format (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jan 16, 2017
1 parent d580217 commit 8d346a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion htdocs/frontend/javascripts/options.js
Expand Up @@ -27,6 +27,9 @@
vz.options = {
language: 'de',
precision: 2, // TODO update from middleware capabilities?
maxPrecision: { // override precision for certain units
'°C': 1
},
tuples: null, // automatically determined by plot size
refresh: true, // update chart if zoomed to current timestamp
interval: 24*60*60*1000, // 1 day default time interval to show
Expand All @@ -48,7 +51,7 @@ vz.options = {
url: '//demo.volkszaehler.org/middleware.php'
}
],
monthNames: ['Jan', 'Feb', unescape('M%E4r'), 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
monthNames: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
dayNames: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
lineWidthDefault: 2,
lineWidthSelected: 4,
Expand Down
4 changes: 4 additions & 0 deletions htdocs/frontend/javascripts/wui.js
Expand Up @@ -733,6 +733,10 @@ vz.wui.formatNumber = function(number, unit, prefix) {
// avoid infinities/NaN
if (number < 0 || number > 0) {
var precision = Math.max(0, vz.options.precision - Math.floor(Math.log(Math.abs(number))/Math.LN10));
// apply maximum precision e.g. for °C values
if (vz.options.maxPrecision[unit] !== undefined) {
precision = Math.min(vz.options.maxPrecision[unit], precision);
}
number = Math.round(number * Math.pow(10, precision)) / Math.pow(10, precision); // rounding
}

Expand Down

0 comments on commit 8d346a2

Please sign in to comment.