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
|
legend: {};
|
11
|
|
12
|
constructor(isAnalytics: boolean, data: any [], legend: {}, interval: number) {
|
13
|
this.isAnalytics = isAnalytics;
|
14
|
this.data = data;
|
15
|
this.interval = interval;
|
16
|
this.legend = this.getLegend(legend);
|
17
|
|
18
|
}
|
19
|
|
20
|
|
21
|
getConfig(): {} {
|
22
|
const lodash = require('lodash/object');
|
23
|
const rvalue: any = {};
|
24
|
let config1 = require('/src/vega/config/config.json');
|
25
|
lodash.merge(rvalue, config1);
|
26
|
let config2 = require('/src/vega/config/config-multiline.json');
|
27
|
let config3 = require('/src/vega/config/config-barline.json');
|
28
|
|
29
|
|
30
|
for(let key in config2.signals) {
|
31
|
let obj = config2.signals[key];
|
32
|
rvalue.signals.push(obj);
|
33
|
}
|
34
|
|
35
|
for(let key in config3.signals) {
|
36
|
let obj = config3.signals[key];
|
37
|
rvalue.signals.push(obj);
|
38
|
}
|
39
|
|
40
|
return rvalue;
|
41
|
}
|
42
|
|
43
|
getSpec(): {} {
|
44
|
const lodash = require('lodash/object');
|
45
|
const rvalue: any = {};
|
46
|
const base = require('/src/vega/base/default.json');
|
47
|
const body = require('/src/vega/body/multilinechart.json');
|
48
|
const legend = require('/src/vega/miscs/legend.json');
|
49
|
const tooltip = require('/src/vega/miscs/multiline-tooltip.json');
|
50
|
|
51
|
lodash.merge(rvalue, base, body, legend, tooltip);
|
52
|
|
53
|
rvalue.data[1].values = this.data;
|
54
|
rvalue.data[0].values = this.legend;
|
55
|
rvalue.signals[0].value = this.interval;
|
56
|
rvalue.marks[0].marks[0].marks[0].marks[2].encode.enter.tooltip.signal = this.getTooltipMessage();
|
57
|
|
58
|
return rvalue;
|
59
|
}
|
60
|
|
61
|
private getTooltipMessage() {
|
62
|
let message = "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')";
|
63
|
this.data.forEach(function (e) {
|
64
|
message += (", '" + e.sensor.sensorName + "': datum['" + e.sensor.sensorName + "'] + ' " + e.sensor.phenomenon.unit +"' ");
|
65
|
})
|
66
|
|
67
|
message += "}";
|
68
|
return message;
|
69
|
}
|
70
|
|
71
|
private getLegend(legend: any) {
|
72
|
if(Array.isArray(legend)) {
|
73
|
return legend[0];
|
74
|
} else {
|
75
|
return legend;
|
76
|
}
|
77
|
}
|
78
|
|
79
|
|
80
|
}
|