Revize 66c042f1
Přidáno uživatelem Štěpán Červenka před více než 3 roky(ů)
src/app/shared/graph-loading/singlegraph.ts | ||
---|---|---|
1 | 1 |
import {Graph} from "./graph"; |
2 |
import {SingleGraphType} from "./singlegraphtype"; |
|
2 | 3 |
|
3 | 4 |
declare var require: any |
4 | 5 |
|
5 |
export class SingleGraph implements Graph{ |
|
6 |
export class SingleGraph implements Graph {
|
|
6 | 7 |
isAnalytics: boolean; |
7 | 8 |
sensorId: number; |
8 | 9 |
interval: number; |
9 | 10 |
data: any []; |
11 |
legend: {}; |
|
12 |
type: SingleGraphType; |
|
10 | 13 |
|
11 |
constructor(sensorId: number, isAnalytics: boolean, data: any[], interval: number) { |
|
14 |
constructor(sensorId: number, isAnalytics: boolean, data: any[], legend: {}, interval: number) {
|
|
12 | 15 |
this.sensorId = sensorId; |
13 | 16 |
this.isAnalytics = isAnalytics; |
14 | 17 |
this.interval = interval; |
15 | 18 |
this.data = data; |
19 |
this.legend = this.getLegend(legend); |
|
20 |
this.type = this.getGraphType(); |
|
21 |
|
|
16 | 22 |
} |
17 | 23 |
|
24 |
|
|
18 | 25 |
getConfig(): {} { |
19 | 26 |
const lodash = require('lodash/object'); |
20 | 27 |
const rvalue: any = {}; |
21 | 28 |
let config1 = require('/src/vega/config/config.json'); |
22 | 29 |
lodash.merge(rvalue, config1); |
30 |
|
|
23 | 31 |
let config2; |
24 |
if(this.isAnalytics) { |
|
32 |
if (this.isAnalytics) {
|
|
25 | 33 |
config2 = require('/src/vega/config/config-analytics.json'); |
26 | 34 |
} else { |
27 | 35 |
config2 = require('/src/vega/config/config-observations.json'); |
28 | 36 |
} |
29 | 37 |
|
30 |
for(let key in config2.signals) { |
|
38 |
let config3; |
|
39 |
switch (this.type) { |
|
40 |
case SingleGraphType.LINECHART: |
|
41 |
case SingleGraphType.BARCHART: |
|
42 |
config3 = require('/src/vega/config/config-barline.json'); |
|
43 |
break; |
|
44 |
case SingleGraphType.WINDCHART: |
|
45 |
config3 = require('/src/vega/config/config-wind.json'); |
|
46 |
break; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
for (let key in config2.signals) { |
|
31 | 51 |
let obj = config2.signals[key]; |
32 | 52 |
rvalue.signals.push(obj); |
33 | 53 |
} |
34 | 54 |
|
35 |
return config1; |
|
55 |
for (let key in config3.signals) { |
|
56 |
let obj = config3.signals[key]; |
|
57 |
rvalue.signals.push(obj); |
|
58 |
} |
|
59 |
|
|
60 |
return rvalue; |
|
36 | 61 |
} |
37 | 62 |
|
38 | 63 |
getSpec(): {} { |
... | ... | |
40 | 65 |
const rvalue: any = {}; |
41 | 66 |
const base = require('/src/vega/base/default.json'); |
42 | 67 |
const body = this.getBodySpec(); |
68 |
const legend = this.getLegendSpec(); |
|
43 | 69 |
const tooltip = this.getTooltipSpec(); |
44 |
lodash.merge(rvalue, base, body, tooltip); |
|
70 |
lodash.merge(rvalue, base, body, legend, tooltip);
|
|
45 | 71 |
|
46 | 72 |
|
47 |
rvalue.data[0].values = this.data; |
|
73 |
this.setData(rvalue, this.data); |
|
74 |
rvalue['data'][0].values = this.legend; |
|
48 | 75 |
rvalue.signals[0].value = this.interval; |
49 | 76 |
|
50 | 77 |
return rvalue; |
51 | 78 |
} |
52 | 79 |
|
53 | 80 |
|
54 |
private getBodySpec() { |
|
81 |
private getLegendSpec() { |
|
82 |
switch (this.type) { |
|
83 |
case SingleGraphType.BARCHART: |
|
84 |
case SingleGraphType.LINECHART: |
|
85 |
return require('/src/vega/miscs/legend.json'); |
|
86 |
case SingleGraphType.WINDCHART: |
|
87 |
return {}; |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
private getBodySpec() { |
|
92 |
switch (this.type) { |
|
93 |
case SingleGraphType.BARCHART: |
|
94 |
return require('/src/vega/body/barchart.json'); |
|
95 |
case SingleGraphType.WINDCHART: |
|
96 |
return require('/src/vega/body/windchart.json'); |
|
97 |
case SingleGraphType.LINECHART: |
|
98 |
//TODO pridat min/max |
|
99 |
return require('/src/vega/body/linechart.json'); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
|
|
104 |
private getTooltipSpec() { |
|
105 |
let lodash = require('lodash'); |
|
106 |
let tooltipMessage; |
|
107 |
let rvalue: any = {}; |
|
108 |
if (this.isAnalytics) { |
|
109 |
lodash.merge(rvalue, require('/src/vega/miscs/samm-tooltip.json')); |
|
110 |
tooltipMessage = this.getSammTooltip(); |
|
111 |
} else { |
|
112 |
lodash.merge(rvalue, require('/src/vega/miscs/value-tooltip.json')); |
|
113 |
tooltipMessage = this.getValueTooltip(); |
|
114 |
} |
|
115 |
|
|
116 |
rvalue.marks[0].marks[0].marks[0].encode.enter.tooltip.signal = tooltipMessage; |
|
117 |
return rvalue; |
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
private getValueTooltip() { |
|
122 |
return "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X') , 'value': datum.value + ' " + this.legend['phenomenon']['unit'] + "', 'gid': datum.gid }" |
|
123 |
} |
|
124 |
|
|
125 |
private getSammTooltip() { |
|
126 |
return "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X') " + |
|
127 |
" , 'avg': datum.avg + ' " + this.legend['phenomenon']['unit'] + |
|
128 |
"', 'sum': datum.sum + ' " + this.legend['phenomenon']['unit'] + |
|
129 |
"', 'max': datum.max + ' " + this.legend['phenomenon']['unit'] + |
|
130 |
"', 'min': datum.min + ' " + this.legend['phenomenon']['unit'] + "'}" |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
private setData(spec: any, data: any) { |
|
135 |
if(data.length > 0 && 'data' in data[0]) { |
|
136 |
spec['data'][1].values = data[0].data; |
|
137 |
} else { |
|
138 |
spec['data'][1].values = data; |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
private getLegend(legend: any) { |
|
143 |
if (Array.isArray(legend)) { |
|
144 |
return legend[0]; |
|
145 |
} else { |
|
146 |
return legend; |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
150 |
private getGraphType() { |
|
55 | 151 |
if (this.sensorId >= 480000000 && this.sensorId < 490000000) { |
56 |
return require('/src/vega/body/barchart.json');
|
|
152 |
return SingleGraphType.BARCHART;
|
|
57 | 153 |
} else if ((this.sensorId >= 470020000 && this.sensorId < 470030000) || (this.sensorId >= 470060000 && this.sensorId < 470090000) || |
58 | 154 |
(this.sensorId >= 470130000 && this.sensorId < 470140000) || (this.sensorId >= 470180000 && this.sensorId < 470190000)) { |
59 |
return require('/src/vega/body/windchart.json');
|
|
155 |
return SingleGraphType.WINDCHART;
|
|
60 | 156 |
} else { |
61 | 157 |
//TODO pridat min/max |
62 |
return require('/src/vega/body/linechart.json');
|
|
158 |
return SingleGraphType.LINECHART;
|
|
63 | 159 |
} |
64 | 160 |
} |
65 | 161 |
|
66 | 162 |
|
67 |
private getTooltipSpec() { |
|
68 |
if(this.isAnalytics) { |
|
69 |
return require('/src/vega/tooltip/samm-tooltip.json'); |
|
70 |
} else { |
|
71 |
return require('/src/vega/tooltip/value-tooltip.json'); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 | 163 |
} |
Také k dispozici: Unified diff
Re #8775 - Agregovat grafy se stejným typem sensoru