Projekt

Obecné

Profil

Stáhnout (2.05 KB) Statistiky
| Větev: | Tag: | Revize:
1 8cca41c0 Štěpán Červenka
import {Graph} from "./graph";
2
3
declare var require: any
4
5
export class SingleGraph implements Graph{
6
  isAnalytics: boolean;
7
  sensorId: number;
8
  interval: number;
9
  data: any [];
10
11
  constructor(sensorId: number, isAnalytics: boolean, data: any[], interval: number) {
12
    this.sensorId = sensorId;
13
    this.isAnalytics = isAnalytics;
14
    this.interval = interval;
15
    this.data = data;
16
  }
17
18
  getConfig(): {} {
19
    const lodash = require('lodash/object');
20
    const rvalue: any = {};
21
    let config1 = require('/src/vega/config/config.json');
22
    lodash.merge(rvalue, config1);
23
    let config2;
24
    if(this.isAnalytics) {
25
      config2 = require('/src/vega/config/config-analytics.json');
26
    } else {
27
      config2 = require('/src/vega/config/config-observations.json');
28
    }
29
30
    for(let key in config2.signals) {
31
      let obj = config2.signals[key];
32
      rvalue.signals.push(obj);
33
    }
34
35
    return config1;
36
  }
37
38
  getSpec(): {} {
39
    const lodash = require('lodash/object');
40
    const rvalue: any = {};
41
    const base = require('/src/vega/base/default.json');
42
    const body = this.getBodySpec();
43
    const tooltip = this.getTooltipSpec();
44
    lodash.merge(rvalue, base, body, tooltip);
45
46
47
    rvalue.data[0].values = this.data;
48
    rvalue.signals[0].value = this.interval;
49
50
    return rvalue;
51
  }
52
53
54
 private getBodySpec() {
55
    if (this.sensorId >= 480000000 && this.sensorId < 490000000) {
56
      return require('/src/vega/body/barchart.json');
57
    } else if ((this.sensorId >= 470020000 && this.sensorId < 470030000) || (this.sensorId >= 470060000 && this.sensorId < 470090000) ||
58
      (this.sensorId >= 470130000 && this.sensorId < 470140000) || (this.sensorId >= 470180000 && this.sensorId < 470190000)) {
59
      return require('/src/vega/body/windchart.json');
60
    } else {
61
      //TODO pridat min/max
62
      return require('/src/vega/body/linechart.json');
63
    }
64
  }
65
66
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
}