1
|
declare var require: any
|
2
|
|
3
|
export class GraphLoader {
|
4
|
|
5
|
|
6
|
static getGraphType(sensorId) {
|
7
|
const lodash = require('lodash/object');
|
8
|
|
9
|
if (sensorId >= 480000000 && sensorId < 490000000) {
|
10
|
|
11
|
const rvalue: any = {};
|
12
|
const base = require('/src/vega/base/default.json');
|
13
|
const chart = require('/src/vega/body/barchart.json');
|
14
|
const tooltip = require('/src/vega/tooltip/samm-tooltip.json')
|
15
|
lodash.merge(rvalue, base, chart, tooltip);
|
16
|
return rvalue;
|
17
|
|
18
|
} else if ((sensorId >= 470020000 && sensorId < 470030000) || (sensorId >= 470060000 && sensorId < 470090000) ||
|
19
|
(sensorId >= 470130000 && sensorId < 470140000) || (sensorId >= 470180000 && sensorId < 470190000)) {
|
20
|
|
21
|
const rvalue: any = {};
|
22
|
const base = require('/src/vega/base/default.json');
|
23
|
const chart = require('/src/vega/body/windchart.json');
|
24
|
const tooltip = require('/src/vega/tooltip/samm-tooltip.json')
|
25
|
lodash.merge(rvalue, base, chart, tooltip);
|
26
|
return rvalue;
|
27
|
|
28
|
} else {
|
29
|
|
30
|
const rvalue: any = {};
|
31
|
const base = require('/src/vega/base/default.json');
|
32
|
const chart = require('/src/vega/body/linechart.json');
|
33
|
const tooltip = require('/src/vega/tooltip/samm-tooltip.json')
|
34
|
lodash.merge(rvalue, base, chart, tooltip);
|
35
|
return rvalue;
|
36
|
|
37
|
}
|
38
|
}
|
39
|
|
40
|
static getObservationSpec(sensorId) {
|
41
|
const lodash = require('lodash/object');
|
42
|
|
43
|
const rvalue: any = {};
|
44
|
const base = require('/src/vega/base/default.json');
|
45
|
const chart = require('/src/vega/body/linechart-observations.json');
|
46
|
const tooltip = require('/src/vega/tooltip/value-tooltip.json')
|
47
|
lodash.merge(rvalue, base, chart, tooltip);
|
48
|
return rvalue;
|
49
|
|
50
|
}
|
51
|
|
52
|
static getGraph(sensorId, data, interval, element) {
|
53
|
const spec = this.getGraphType(sensorId);
|
54
|
const vega = require('vega');
|
55
|
const vegaTooltip = require('vega-tooltip');
|
56
|
const config = require('/src/vega/config/config-analytics.json');
|
57
|
|
58
|
spec.data[0].values = data;
|
59
|
spec.signals[0].value = interval;
|
60
|
|
61
|
|
62
|
const handler = new vegaTooltip.Handler();
|
63
|
|
64
|
const loc = vega.locale({
|
65
|
decimal: ',',
|
66
|
thousands: '\u00a0',
|
67
|
grouping: [3],
|
68
|
currency: ['', '\u00a0Kč']
|
69
|
},{
|
70
|
dateTime: '%A,%e.%B %Y, %X',
|
71
|
date: '%-d.%-m.%Y',
|
72
|
time: '%H:%M:%S',
|
73
|
periods: ['AM', 'PM'],
|
74
|
days: ['neděle', 'pondělí', 'úterý', 'středa', 'čvrtek', 'pátek', 'sobota'],
|
75
|
shortDays: ['ne.', 'po.', 'út.', 'st.', 'čt.', 'pá.', 'so.'],
|
76
|
months: ['leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'],
|
77
|
shortMonths: ['led', 'úno', 'břez', 'dub', 'kvě', 'čer', 'červ', 'srp', 'zář', 'říj', 'list', 'pros']
|
78
|
});
|
79
|
|
80
|
const view = new vega.View(vega.parse(spec, config))
|
81
|
.tooltip(handler.call)
|
82
|
.initialize(element)
|
83
|
.hover()
|
84
|
.locale(loc)
|
85
|
.runAsync();
|
86
|
|
87
|
|
88
|
|
89
|
}
|
90
|
|
91
|
static getObservationGraph(sensorId, data, element) {
|
92
|
|
93
|
const spec = this.getObservationSpec(sensorId);
|
94
|
const vega = require('vega');
|
95
|
const vegaTooltip = require('vega-tooltip');
|
96
|
const config = require('/src/vega/config/config-observations.json');
|
97
|
|
98
|
spec.data[0].values = data;
|
99
|
spec.signals[0].value = 3600;
|
100
|
|
101
|
const handler = new vegaTooltip.Handler();
|
102
|
|
103
|
const loc = vega.locale({
|
104
|
decimal: ',',
|
105
|
thousands: '\u00a0',
|
106
|
grouping: [3],
|
107
|
currency: ['', '\u00a0Kč']
|
108
|
},{
|
109
|
dateTime: '%A,%e.%B %Y, %X',
|
110
|
date: '%-d.%-m.%Y',
|
111
|
time: '%H:%M:%S',
|
112
|
periods: ['AM', 'PM'],
|
113
|
days: ['neděle', 'pondělí', 'úterý', 'středa', 'čvrtek', 'pátek', 'sobota'],
|
114
|
shortDays: ['ne.', 'po.', 'út.', 'st.', 'čt.', 'pá.', 'so.'],
|
115
|
months: ['leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'],
|
116
|
shortMonths: ['led', 'úno', 'břez', 'dub', 'kvě', 'čer', 'červ', 'srp', 'zář', 'říj', 'list', 'pros']
|
117
|
});
|
118
|
|
119
|
const view = new vega.View(vega.parse(spec, config))
|
120
|
.tooltip(handler.call)
|
121
|
.initialize(element)
|
122
|
.hover()
|
123
|
.locale(loc)
|
124
|
.runAsync();
|
125
|
|
126
|
|
127
|
|
128
|
}
|
129
|
|
130
|
}
|