Projekt

Obecné

Profil

Stáhnout (2.04 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
    let config2 = require('/src/vega/config/config-multiline.json');
27 66c042f1 Štěpán Červenka
    let config3 = require('/src/vega/config/config-barline.json');
28 8cca41c0 Štěpán Červenka
29
30
    for(let key in config2.signals) {
31
      let obj = config2.signals[key];
32
      rvalue.signals.push(obj);
33
    }
34
35 66c042f1 Štěpán Červenka
    for(let key in config3.signals) {
36
      let obj = config3.signals[key];
37
      rvalue.signals.push(obj);
38
    }
39
40
    return rvalue;
41 8cca41c0 Štěpán Červenka
  }
42
43
  getSpec(): {} {
44
    const lodash = require('lodash/object');
45
    const rvalue: any = {};
46
    const base = require('/src/vega/base/default.json');
47
    const body = require('/src/vega/body/multilinechart.json');
48 66c042f1 Štěpán Červenka
    const legend = require('/src/vega/miscs/legend.json');
49
    const tooltip = require('/src/vega/miscs/multiline-tooltip.json');
50 8cca41c0 Štěpán Červenka
51 66c042f1 Štěpán Červenka
    lodash.merge(rvalue, base, body, legend, tooltip);
52 8cca41c0 Štěpán Červenka
53 66c042f1 Štěpán Červenka
    rvalue.data[1].values = this.data;
54
    rvalue.data[0].values = this.legend;
55 8cca41c0 Štěpán Červenka
    rvalue.signals[0].value = this.interval;
56
    rvalue.marks[0].marks[0].marks[0].marks[2].encode.enter.tooltip.signal = this.getTooltipMessage();
57
58
    return rvalue;
59
  }
60
61
  private getTooltipMessage() {
62
    let message = "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')";
63
    this.data.forEach(function (e) {
64
      message += (", '" + e.sensor.sensorName + "': datum['" + e.sensor.sensorName + "'] + ' " + e.sensor.phenomenon.unit +"' ");
65
    })
66
67
    message += "}";
68
    return message;
69
  }
70
71 66c042f1 Štěpán Červenka
  private getLegend(legend: any) {
72
    if(Array.isArray(legend)) {
73
      return legend[0];
74
    } else {
75
      return legend;
76
    }
77
  }
78
79
80 8cca41c0 Štěpán Červenka
}