Projekt

Obecné

Profil

Stáhnout (2.2 KB) Statistiky
| Větev: | Tag: | Revize:
1
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
  legend: {};
11

    
12
  constructor(isAnalytics: boolean, data: any [], legend: {}, interval: number) {
13
    this.isAnalytics = isAnalytics;
14
    this.data = data;
15
    this.interval = interval;
16
    this.legend = this.getLegend(legend);
17

    
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

    
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
    let config3 = require('/src/vega/config/config-barline.json');
35

    
36

    
37
    for(let key in config2.signals) {
38
      let obj = config2.signals[key];
39
      rvalue.signals.push(obj);
40
    }
41

    
42
    for(let key in config3.signals) {
43
      let obj = config3.signals[key];
44
      rvalue.signals.push(obj);
45
    }
46

    
47
    return rvalue;
48
  }
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
    const legend = require('/src/vega/miscs/legend.json');
56
    const tooltip = require('/src/vega/miscs/multiline-tooltip.json');
57

    
58
    lodash.merge(rvalue, base, body, legend, tooltip);
59

    
60
    rvalue.data[1].values = this.data;
61
    rvalue.data[0].values = this.legend;
62
    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
  private getLegend(legend: any) {
79
    if(Array.isArray(legend)) {
80
      return legend[0];
81
    } else {
82
      return legend;
83
    }
84
  }
85

    
86

    
87
}
(4-4/6)