Projekt

Obecné

Profil

Stáhnout (2.2 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 MultiGraph implements Graph{
6
7
  isAnalytics: boolean;
8
  data: any [];
9
  interval: number;
10 66c042f1 Štěpán Červenka
  legend: {};
11 8cca41c0 Štěpán Červenka
12 66c042f1 Štěpán Červenka
  constructor(isAnalytics: boolean, data: any [], legend: {}, interval: number) {
13 8cca41c0 Štěpán Červenka
    this.isAnalytics = isAnalytics;
14
    this.data = data;
15
    this.interval = interval;
16 66c042f1 Štěpán Červenka
    this.legend = this.getLegend(legend);
17 8cca41c0 Štěpán Červenka
18
  }
19
20
21
  getConfig(): {} {
22
    const lodash = require('lodash/object');
23
    const rvalue: any = {};
24
    let config1 = require('/src/vega/config/config.json');
25
    lodash.merge(rvalue, config1);
26 c4f90f7b Štěpán Červenka
27
    let config2;
28
    if (this.isAnalytics) {
29
      config2 = require('/src/vega/config/config-multiline-analytics.json');
30
    } else {
31
      config2 = require('/src/vega/config/config-multiline-observations.json');
32
    }
33
34 66c042f1 Štěpán Červenka
    let config3 = require('/src/vega/config/config-barline.json');
35 8cca41c0 Štěpán Červenka
36
37
    for(let key in config2.signals) {
38
      let obj = config2.signals[key];
39
      rvalue.signals.push(obj);
40
    }
41
42 66c042f1 Štěpán Červenka
    for(let key in config3.signals) {
43
      let obj = config3.signals[key];
44
      rvalue.signals.push(obj);
45
    }
46
47
    return rvalue;
48 8cca41c0 Štěpán Červenka
  }
49
50
  getSpec(): {} {
51
    const lodash = require('lodash/object');
52
    const rvalue: any = {};
53
    const base = require('/src/vega/base/default.json');
54
    const body = require('/src/vega/body/multilinechart.json');
55 66c042f1 Štěpán Červenka
    const legend = require('/src/vega/miscs/legend.json');
56
    const tooltip = require('/src/vega/miscs/multiline-tooltip.json');
57 8cca41c0 Štěpán Červenka
58 66c042f1 Štěpán Červenka
    lodash.merge(rvalue, base, body, legend, tooltip);
59 8cca41c0 Štěpán Červenka
60 66c042f1 Štěpán Červenka
    rvalue.data[1].values = this.data;
61
    rvalue.data[0].values = this.legend;
62 8cca41c0 Štěpán Červenka
    rvalue.signals[0].value = this.interval;
63
    rvalue.marks[0].marks[0].marks[0].marks[2].encode.enter.tooltip.signal = this.getTooltipMessage();
64
65
    return rvalue;
66
  }
67
68
  private getTooltipMessage() {
69
    let message = "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')";
70
    this.data.forEach(function (e) {
71
      message += (", '" + e.sensor.sensorName + "': datum['" + e.sensor.sensorName + "'] + ' " + e.sensor.phenomenon.unit +"' ");
72
    })
73
74
    message += "}";
75
    return message;
76
  }
77
78 66c042f1 Štěpán Červenka
  private getLegend(legend: any) {
79
    if(Array.isArray(legend)) {
80
      return legend[0];
81
    } else {
82
      return legend;
83
    }
84
  }
85
86
87 8cca41c0 Štěpán Červenka
}