diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-03-06 21:21:12 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-03-06 21:30:39 +0100 |
commit | 45267e41368fbb9fb318fb455981110e83c97953 (patch) | |
tree | fc4b819604081076ec97962a5f2dad3b99f51399 /web/static/app/diller/line-chart.js | |
parent | 7ca173de3de046501d79164da0c8c8871a03089b (diff) | |
download | diller-server-45267e41368fbb9fb318fb455981110e83c97953.tar.gz diller-server-45267e41368fbb9fb318fb455981110e83c97953.tar.bz2 diller-server-45267e41368fbb9fb318fb455981110e83c97953.tar.xz diller-server-45267e41368fbb9fb318fb455981110e83c97953.zip |
web:
o Adding level to Interval that specifies what kind of aggregate level the server should use.
Diffstat (limited to 'web/static/app/diller/line-chart.js')
-rw-r--r-- | web/static/app/diller/line-chart.js | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/web/static/app/diller/line-chart.js b/web/static/app/diller/line-chart.js index 69b6f77..4c93b03 100644 --- a/web/static/app/diller/line-chart.js +++ b/web/static/app/diller/line-chart.js @@ -14,7 +14,7 @@ interval: '=' }, replace: true, - template: '<div/>', + templateUrl: 'app/templates/line-chart.html', link: function (scope, element, attrs) { var elementId = element.attr('id'); if (!elementId) { @@ -24,34 +24,60 @@ var deviceId = scope.device; var propertyId = scope.property; - var interval = Diller.Interval.create(scope.interval); + var interval = scope.interval; // TODO: watch scope.interval var property = DillerClient.getDevice(deviceId).getProperty(propertyId); + var chart, chartData; var options = { axisX: { showLabel: true, showGrid: true, + labelInterval: 1, labelInterpolationFnc: function (value, index) { - return index % 4 === 0 ? value.format('HH:mm') : null; + return index % options.labelInterval === 0 ? value.format('HH:mm') : null; } } }; - property.getInterval(interval).then(function (data) { - var avgs = _.pluck(data.values, 'avg'); - var timestamps = _.map(data.values, function (row) { - return moment(row.timestamp, isoFormat); + function refresh() { + property.getInterval(interval).then(function (data) { + var avgs = _.pluck(data.values, 'avg'); + var timestamps = _.map(data.values, function (row) { + return moment(row.timestamp, isoFormat); + }); + + chartData = { + labels: timestamps, + series: [ + avgs + ] + }; + + options.labelInterval = Math.round(data.values.length / 10); + + if (!chart) { + chart = new Chartist.Line('#' + elementId + ' .chart', chartData, options); + } else { + chart.update(chartData); + } }); + } - var chartData = { - labels: timestamps, - series: [ - avgs - ] - }; + scope.setInterval = function (amount, type) { + if (type == 'hours') { + interval = Diller.Interval.hours(amount); + } else if (type == 'days') { + interval = Diller.Interval.days(amount); + } else if (type == 'months') { + interval = Diller.Interval.months(amount); + } + + console.log('new interval', interval); + + interval && refresh(); + }; - var chart = new Chartist.Line('#' + elementId, chartData, options); - }); + interval && refresh(); } }; } |