Projekt

Obecné

Profil

Stáhnout (2.48 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 getGraph(sensorId, data, interval, element) {
41
    const spec = this.getGraphType(sensorId);
42
    const vega = require('vega');
43
    const vegaTooltip = require('vega-tooltip');
44
    const config = require('/src/vega/config.json');
45

    
46
    spec.data[0].values = data;
47
    spec.signals[0].value = interval;
48

    
49

    
50
    const handler = new vegaTooltip.Handler();
51

    
52
    const loc = vega.locale({
53
      decimal: ',',
54
      thousands: '\u00a0',
55
      grouping: [3],
56
      currency: ['', '\u00a0Kč']
57
    },{
58
      dateTime: '%A,%e.%B %Y, %X',
59
      date: '%-d.%-m.%Y',
60
      time: '%H:%M:%S',
61
      periods: ['AM', 'PM'],
62
      days: ['neděle', 'pondělí', 'úterý', 'středa', 'čvrtek', 'pátek', 'sobota'],
63
      shortDays: ['ne.', 'po.', 'út.', 'st.', 'čt.', 'pá.', 'so.'],
64
      months: ['leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'],
65
      shortMonths: ['led', 'úno', 'břez', 'dub', 'kvě', 'čer', 'červ', 'srp', 'zář', 'říj', 'list', 'pros']
66
    });
67

    
68
    const view = new vega.View(vega.parse(spec, config))
69
      .tooltip(handler.call)
70
      .initialize(element)
71
      .hover()
72
      .locale(loc)
73
      .runAsync();
74

    
75

    
76

    
77
  }
78

    
79
}
    (1-1/1)