1 |
8cca41c0
|
Štěpán Červenka
|
import {Graph} from './graph';
|
2 |
|
|
import {EmptyGraph} from "./emptygraph";
|
3 |
|
|
import {SingleGraph} from "./singlegraph";
|
4 |
|
|
import {MultiGraph} from "./multigraph";
|
5 |
72effbbe
|
Štěpán Červenka
|
|
6 |
8cca41c0
|
Štěpán Červenka
|
declare var require: any
|
7 |
72effbbe
|
Štěpán Červenka
|
|
8 |
|
|
|
9 |
|
|
|
10 |
8cca41c0
|
Štěpán Červenka
|
export class GraphLoader {
|
11 |
72effbbe
|
Štěpán Červenka
|
|
12 |
|
|
|
13 |
c1664074
|
Štěpán Červenka
|
static getGraphType(sensors, data, interval, legend, isAnalytics): Graph {
|
14 |
8cca41c0
|
Štěpán Červenka
|
if (sensors == null) {
|
15 |
c1664074
|
Štěpán Červenka
|
return new EmptyGraph("No sensors selected.");
|
16 |
72effbbe
|
Štěpán Červenka
|
|
17 |
66c042f1
|
Štěpán Červenka
|
} else if (Array.isArray(sensors)) {
|
18 |
8cca41c0
|
Štěpán Červenka
|
if (sensors.length == 0) {
|
19 |
c1664074
|
Štěpán Červenka
|
return new EmptyGraph("No sensors selected.");
|
20 |
8cca41c0
|
Štěpán Červenka
|
} else if (sensors.length == 1) {
|
21 |
c1664074
|
Štěpán Červenka
|
return new SingleGraph(sensors[0], isAnalytics, data, legend,interval);
|
22 |
8cca41c0
|
Štěpán Červenka
|
} else {
|
23 |
c1664074
|
Štěpán Červenka
|
return new MultiGraph(isAnalytics, data, legend,interval);
|
24 |
8cca41c0
|
Štěpán Červenka
|
}
|
25 |
72effbbe
|
Štěpán Červenka
|
|
26 |
|
|
} else {
|
27 |
c1664074
|
Štěpán Červenka
|
return new SingleGraph(sensors, isAnalytics, data, legend, interval);
|
28 |
72effbbe
|
Štěpán Červenka
|
}
|
29 |
|
|
}
|
30 |
|
|
|
31 |
b4b32b0e
|
Štěpán Červenka
|
|
32 |
c1664074
|
Štěpán Červenka
|
static getGraphWithInterval(sensors, data, interval, legendInfo, element, isAnalytics) {
|
33 |
|
|
let graph = this.getGraphType(sensors,data, interval, legendInfo, isAnalytics);
|
34 |
8cca41c0
|
Štěpán Červenka
|
let config = graph.getConfig();
|
35 |
|
|
let spec = graph.getSpec();
|
36 |
66c042f1
|
Štěpán Červenka
|
|
37 |
ec939478
|
Štěpán Červenka
|
|
38 |
|
|
this.showGraph(spec, config, element);
|
39 |
c1664074
|
Štěpán Červenka
|
}
|
40 |
ec939478
|
Štěpán Červenka
|
|
41 |
c1664074
|
Štěpán Červenka
|
static getGraph(sensors, data, legendInfo, element, isAnalytics) {
|
42 |
|
|
this.getGraphWithInterval(sensors, data, 1800000, legendInfo, element, isAnalytics);
|
43 |
ec939478
|
Štěpán Červenka
|
}
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
static showGraph(spec, config, element) {
|
47 |
|
|
const vega = require('vega');
|
48 |
|
|
const vegaTooltip = require('vega-tooltip');
|
49 |
b4b32b0e
|
Štěpán Červenka
|
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 |
ec939478
|
Štěpán Červenka
|
}
|
58 |
72effbbe
|
Štěpán Červenka
|
}
|