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, isAnalytics): Graph {
|
14
|
if (sensors == null) {
|
15
|
return new EmptyGraph("Selected no sensors.");
|
16
|
|
17
|
} else if (Array.isArray(sensors)) {
|
18
|
if (sensors.length == 0) {
|
19
|
return new EmptyGraph("Selected no sensors.");
|
20
|
} else if (sensors.length == 1) {
|
21
|
return new SingleGraph(sensors[0], isAnalytics, data, 10000);
|
22
|
} else {
|
23
|
return new MultiGraph(isAnalytics, data, 10000);
|
24
|
}
|
25
|
|
26
|
} else {
|
27
|
return new SingleGraph(sensors, isAnalytics, data, 10000);
|
28
|
}
|
29
|
}
|
30
|
|
31
|
|
32
|
static getGraph(sensors, data, element, isAnalytics) {
|
33
|
let graph = this.getGraphType(sensors,data, isAnalytics);
|
34
|
let config = graph.getConfig();
|
35
|
let spec = graph.getSpec();
|
36
|
spec['data'][0].values = data;
|
37
|
|
38
|
this.showGraph(spec, config, element);
|
39
|
|
40
|
}
|
41
|
|
42
|
|
43
|
static showGraph(spec, config, element) {
|
44
|
const vega = require('vega');
|
45
|
const vegaTooltip = require('vega-tooltip');
|
46
|
const handler = new vegaTooltip.Handler();
|
47
|
|
48
|
const loc = vega.locale({
|
49
|
decimal: ',',
|
50
|
thousands: '\u00a0',
|
51
|
grouping: [3],
|
52
|
currency: ['', '\u00a0Kč']
|
53
|
},{
|
54
|
dateTime: '%A,%e.%B %Y, %X',
|
55
|
date: '%-d.%-m.%Y',
|
56
|
time: '%H:%M:%S',
|
57
|
periods: ['AM', 'PM'],
|
58
|
days: ['neděle', 'pondělí', 'úterý', 'středa', 'čvrtek', 'pátek', 'sobota'],
|
59
|
shortDays: ['ne.', 'po.', 'út.', 'st.', 'čt.', 'pá.', 'so.'],
|
60
|
months: ['leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'],
|
61
|
shortMonths: ['led', 'úno', 'břez', 'dub', 'kvě', 'čer', 'červ', 'srp', 'zář', 'říj', 'list', 'pros']
|
62
|
});
|
63
|
|
64
|
const view = new vega.View(vega.parse(spec, config))
|
65
|
.tooltip(handler.call)
|
66
|
.initialize(element)
|
67
|
.hover()
|
68
|
.locale(loc)
|
69
|
.runAsync();
|
70
|
}
|
71
|
|
72
|
|
73
|
|
74
|
}
|