Projekt

Obecné

Profil

Stáhnout (4.27 KB) Statistiky
| Větev: | Tag: | Revize:
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 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

    
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;
87

    
88
    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

    
114
  }
115

    
116

    
117
  static showGraph(spec, config, element) {
118
    const vega = require('vega');
119
    const vegaTooltip = require('vega-tooltip');
120
    const handler = new vegaTooltip.Handler();
121

    
122
    const loc = vega.locale({
123
      decimal: ',',
124
      thousands: '\u00a0',
125
      grouping: [3],
126
      currency: ['', '\u00a0Kč']
127
    },{
128
      dateTime: '%A,%e.%B %Y, %X',
129
      date: '%-d.%-m.%Y',
130
      time: '%H:%M:%S',
131
      periods: ['AM', 'PM'],
132
      days: ['neděle', 'pondělí', 'úterý', 'středa', 'čvrtek', 'pátek', 'sobota'],
133
      shortDays: ['ne.', 'po.', 'út.', 'st.', 'čt.', 'pá.', 'so.'],
134
      months: ['leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'],
135
      shortMonths: ['led', 'úno', 'břez', 'dub', 'kvě', 'čer', 'červ', 'srp', 'zář', 'říj', 'list', 'pros']
136
    });
137

    
138
    const view = new vega.View(vega.parse(spec, config))
139
      .tooltip(handler.call)
140
      .initialize(element)
141
      .hover()
142
      .locale(loc)
143
      .runAsync();
144
  }
145

    
146

    
147

    
148
}
(2-2/2)