Revize 8cca41c0
Přidáno uživatelem Štěpán Červenka před více než 3 roky(ů)
src/app/shared/graph-loading/graphloader.ts | ||
---|---|---|
1 |
declare var require: any |
|
1 |
import {Graph} from './graph'; |
|
2 |
import {EmptyGraph} from "./emptygraph"; |
|
3 |
import {SingleGraph} from "./singlegraph"; |
|
4 |
import {MultiGraph} from "./multigraph"; |
|
2 | 5 |
|
3 |
export class GraphLoader {
|
|
6 |
declare var require: any
|
|
4 | 7 |
|
5 | 8 |
|
6 |
static getGraphType(sensorId) { |
|
7 |
const lodash = require('lodash/object'); |
|
8 | 9 |
|
9 |
if (sensorId >= 480000000 && sensorId < 490000000) {
|
|
10 |
export class GraphLoader {
|
|
10 | 11 |
|
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 | 12 |
|
18 |
} else if ((sensorId >= 470020000 && sensorId < 470030000) || (sensorId >= 470060000 && sensorId < 470090000) || |
|
19 |
(sensorId >= 470130000 && sensorId < 470140000) || (sensorId >= 470180000 && sensorId < 470190000)) { |
|
13 |
static getGraphType(sensors, data, isAnalytics): Graph { |
|
14 |
if (sensors == null) { |
|
15 |
return new EmptyGraph("Selected no sensors."); |
|
20 | 16 |
|
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; |
|
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 |
} |
|
27 | 25 |
|
28 | 26 |
} 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 |
|
|
27 |
return new SingleGraph(sensors, isAnalytics, data, 10000); |
|
37 | 28 |
} |
38 | 29 |
} |
39 | 30 |
|
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 config = require('/src/vega/config/config-analytics.json'); |
|
55 |
|
|
56 |
spec.data[0].values = data; |
|
57 |
spec.signals[0].value = interval; |
|
58 |
|
|
59 |
|
|
60 |
this.showGraph(spec, config, element); |
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
} |
|
65 |
|
|
66 |
static getObservationGraph(sensorId, data, element) { |
|
67 | 31 |
|
68 |
const spec = this.getObservationSpec(sensorId); |
|
69 |
const config = require('/src/vega/config/config-observations.json'); |
|
70 |
|
|
71 |
spec.data[0].values = data; |
|
72 |
spec.signals[0].value = 3600; |
|
73 |
|
|
74 |
|
|
75 |
this.showGraph(spec, config, element); |
|
76 |
|
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
static getMultilineGraph(sensors, data, element) { |
|
81 |
let spec = this.getMultilineSpec(sensors); |
|
82 |
|
|
83 |
const config = require('/src/vega/config/config-multiline.json'); |
|
84 |
|
|
85 |
spec.data[0].values = data; |
|
86 |
spec.signals[0].value = 3600; |
|
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; |
|
87 | 37 |
|
88 | 38 |
this.showGraph(spec, config, element); |
89 |
} |
|
90 |
|
|
91 |
static getMultilineSpec(sensors) { |
|
92 |
const lodash = require('lodash/object'); |
|
93 |
|
|
94 |
const rvalue: any = {}; |
|
95 |
const base = require('/src/vega/base/default.json'); |
|
96 |
const chart = require('/src/vega/body/multilinechart.json'); |
|
97 |
const tooltip = require('/src/vega/tooltip/multiline-tooltip.json') |
|
98 |
lodash.merge(rvalue, base, chart, tooltip); |
|
99 |
rvalue.marks[0].marks[0].marks[0].marks[2].encode.enter.tooltip.signal = this.getTooltipMessage(sensors); |
|
100 |
return rvalue; |
|
101 |
} |
|
102 |
|
|
103 |
static getTooltipMessage(sensors) { |
|
104 |
let message = "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X'), "; |
|
105 |
|
|
106 |
for(const key of sensors) { |
|
107 |
message += ("'" + key + "': datum['" + key + "'], "); |
|
108 |
} |
|
109 |
|
|
110 |
message += "}"; |
|
111 |
|
|
112 |
return message; |
|
113 | 39 |
|
114 | 40 |
} |
115 | 41 |
|
Také k dispozici: Unified diff
Re #8775 - Agregovat grafy se stejným typem sensoru