1
|
import {Graph} from './graph';
|
2
|
import {EmptyGraph} from "./emptygraph";
|
3
|
import {SingleGraph} from "./singlegraph";
|
4
|
import {MultiGraph} from "./multigraph";
|
5
|
|
6
|
declare var require: any
|
7
|
|
8
|
|
9
|
|
10
|
export class GraphLoader {
|
11
|
|
12
|
|
13
|
static getGraphType(sensors, data, interval, legend, isAnalytics): Graph {
|
14
|
if (sensors == null) {
|
15
|
return new EmptyGraph("No sensors selected.");
|
16
|
|
17
|
} else if (Array.isArray(sensors)) {
|
18
|
if (sensors.length == 0) {
|
19
|
return new EmptyGraph("No sensors selected.");
|
20
|
} else if (sensors.length == 1) {
|
21
|
return new SingleGraph(sensors[0], isAnalytics, data, legend,interval);
|
22
|
} else {
|
23
|
return new MultiGraph(isAnalytics, data, legend,interval);
|
24
|
}
|
25
|
|
26
|
} else {
|
27
|
return new SingleGraph(sensors, isAnalytics, data, legend, interval);
|
28
|
}
|
29
|
}
|
30
|
|
31
|
|
32
|
static getGraphWithInterval(sensors, data, interval, legendInfo, element, isAnalytics) {
|
33
|
let graph = this.getGraphType(sensors,data, interval, legendInfo, isAnalytics);
|
34
|
let config = graph.getConfig();
|
35
|
let spec = graph.getSpec();
|
36
|
|
37
|
|
38
|
this.showGraph(spec, config, element);
|
39
|
}
|
40
|
|
41
|
static getGraph(sensors, data, legendInfo, element, isAnalytics) {
|
42
|
this.getGraphWithInterval(sensors, data, 1800000, legendInfo, element, isAnalytics);
|
43
|
}
|
44
|
|
45
|
|
46
|
static showGraph(spec, config, element) {
|
47
|
const vega = require('vega');
|
48
|
const vegaTooltip = require('vega-tooltip');
|
49
|
const handler = new vegaTooltip.Handler();
|
50
|
|
51
|
|
52
|
const view = new vega.View(vega.parse(spec, config))
|
53
|
.tooltip(handler.call)
|
54
|
.initialize(element)
|
55
|
.hover()
|
56
|
.runAsync();
|
57
|
}
|
58
|
|
59
|
|
60
|
|
61
|
}
|