IoT - Kubus
/
Kubus
JNP3 16/17
Diff: frontend/kubus.js
- Revision:
- 23:e643afa16ad1
- Parent:
- 22:af4397ca4561
- Child:
- 24:a929fcdb1208
--- a/frontend/kubus.js Mon Jan 09 19:00:05 2017 +0100 +++ b/frontend/kubus.js Mon Jan 09 19:14:08 2017 +0100 @@ -2,6 +2,8 @@ Chart.defaults.global.defaultFontSize = 15; Chart.defaults.global.defaultFontColor = "#efefef"; +const UPDATE_INTERVAL_SECONDS = 5; + class Charts { constructor(containerId) { this.container = document.getElementById(containerId); @@ -101,13 +103,21 @@ scales: { xAxes: [{ type: 'time', - position: 'bottom' + position: 'bottom', + time: { + unit: 'second', + unitStepSize: UPDATE_INTERVAL_SECONDS + } }], yAxes: [{ display: true, ticks: { max: 100, min: 0 + }, + scaleLabel: { + display: false, + labelString: "" } }] }, @@ -123,6 +133,7 @@ constructor(name, options) { super(name); this.range = options.range; + this.unit = options.unit; } render() { @@ -133,6 +144,8 @@ const config = super._getConfig(data); config.options.scales.yAxes[0].ticks.max = this.range[1]; config.options.scales.yAxes[0].ticks.min = this.range[0]; + config.options.scales.yAxes[0].scaleLabel.display = true; + config.options.scales.yAxes[0].scaleLabel.labelString = this.unit; return config; } } @@ -156,7 +169,8 @@ switch (sensor.type) { case "number": return new NumberChart(sensor.name, { - "range": sensor.range + range: sensor.range, + unit: sensor.unit }); break; case "bool": @@ -186,7 +200,7 @@ } ]); - setTimeout(update, 5000); + setTimeout(update, UPDATE_INTERVAL_SECONDS * 1000); } update(); \ No newline at end of file