1
|
import {Graph} from "./graph";
|
2
|
|
3
|
declare var require: any
|
4
|
|
5
|
export class MultiGraph implements Graph{
|
6
|
|
7
|
isAnalytics: boolean;
|
8
|
data: any [];
|
9
|
interval: number;
|
10
|
|
11
|
constructor(isAnalytics: boolean, data: any [], interval: number) {
|
12
|
this.isAnalytics = isAnalytics;
|
13
|
this.data = data;
|
14
|
this.interval = interval;
|
15
|
|
16
|
}
|
17
|
|
18
|
|
19
|
getConfig(): {} {
|
20
|
const lodash = require('lodash/object');
|
21
|
const rvalue: any = {};
|
22
|
let config1 = require('/src/vega/config/config.json');
|
23
|
lodash.merge(rvalue, config1);
|
24
|
let config2 = require('/src/vega/config/config-multiline.json');
|
25
|
|
26
|
|
27
|
for(let key in config2.signals) {
|
28
|
let obj = config2.signals[key];
|
29
|
rvalue.signals.push(obj);
|
30
|
}
|
31
|
|
32
|
return config1;
|
33
|
}
|
34
|
|
35
|
getSpec(): {} {
|
36
|
const lodash = require('lodash/object');
|
37
|
const rvalue: any = {};
|
38
|
const base = require('/src/vega/base/default.json');
|
39
|
const body = require('/src/vega/body/multilinechart.json');
|
40
|
const tooltip = require('/src/vega/tooltip/multiline-tooltip.json');
|
41
|
|
42
|
lodash.merge(rvalue, base, body, tooltip);
|
43
|
|
44
|
rvalue.data[0].values = this.data;
|
45
|
rvalue.signals[0].value = this.interval;
|
46
|
rvalue.marks[0].marks[0].marks[0].marks[2].encode.enter.tooltip.signal = this.getTooltipMessage();
|
47
|
|
48
|
return rvalue;
|
49
|
}
|
50
|
|
51
|
private getTooltipMessage() {
|
52
|
let message = "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')";
|
53
|
this.data.forEach(function (e) {
|
54
|
message += (", '" + e.sensor.sensorName + "': datum['" + e.sensor.sensorName + "'] + ' " + e.sensor.phenomenon.unit +"' ");
|
55
|
})
|
56
|
|
57
|
message += "}";
|
58
|
return message;
|
59
|
}
|
60
|
|
61
|
}
|