Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 66c042f1

Přidáno uživatelem Štěpán Červenka před více než 3 roky(ů)

Re #8775 - Agregovat grafy se stejným typem sensoru

  • bugs fixed
  • sensors and units sending request to new methods
  • ready for observation data

Zobrazit rozdíly:

src/app/sensor/components/dummysensor.json
1
[
2
  {
3
    "firstObservationTime": "2019-03-07 06:10:16+02",
4
    "lastObservationTime": "2021-05-12 18:00:06+03",
5
    "phenomenon": {
6
      "phenomenonId": "1",
7
      "phenomenonName": "Temperature",
8
      "unit": "°C"
9
    },
10
    "sensorId": 340400000,
11
    "sensorName": "iMetos HC Air temp",
12
    "sensorType": "Thermometer"
13
  }
14
]
src/app/sensor/components/sensor.component.ts
9 9
import {map} from 'rxjs/operators';
10 10
import {ToastService} from '../../shared/services/toast.service';
11 11

  
12
declare var require: any
13

  
12 14
@Component({
13 15
  selector: 'app-sensor',
14 16
  templateUrl: './sensor.component.html',
15 17
  styleUrls: ['./sensor.component.scss']
16 18
})
19

  
20

  
21

  
17 22
export class SensorComponent implements OnInit {
18 23

  
19 24
  sensorId: number;
......
89 94
      observations => {
90 95
        if (observations) {
91 96
        //  GraphLoader.getGraph(this.sensorId, observations[this.sensorId].data, observations[this.sensorId].interval, '#view');
92
          GraphLoader.getGraph(this.sensorId, observations[this.sensorId].data, '#view', true);
97
          GraphLoader.getGraph(this.sensorId, observations, this.getDummySensor(), '#view', true);
93 98
        } else {
94
          GraphLoader.getGraph(null, null, '#view', null);
99
          GraphLoader.getGraph(null, null, null, '#view', null);
95 100
        }
96 101
      }, err => this.toastService.showError(err.error.message));
97 102
  }
......
117 122
      observations => {
118 123
        if (observations) {
119 124
         // GraphLoader.getObservationGraph(this.sensorId, observations, '#view');
120
          GraphLoader.getGraph(this.sensorId, observations[this.sensorId].data, '#view', false);
125
          GraphLoader.getGraph(this.sensorId, observations, this.getDummySensor(), '#view', false);
121 126
        } else {
122 127
         // GraphLoader.getObservationGraph(null, null, null);
123
          GraphLoader.getGraph(null, null, '#view', null);
128
          GraphLoader.getGraph(null, null, null,'#view', null);
124 129
        }
125 130
      }, err => this.toastService.showError(err.error.message));
126 131
  }
132

  
133
  getDummySensor() {
134
    return require('/src/app/sensor/components/dummysensor.json');
135
  }
127 136
}
src/app/shared/graph-loading/emptygraph.ts
24 24
    return rvalue;
25 25
  }
26 26

  
27
  setData(spec, data) {
28
    //DO NOTHING
29
  }
30

  
31
  setLegendInfo(spec, legend) {
32
    //DO NOTHING
33
  }
34

  
27 35
}
src/app/shared/graph-loading/graphloader.ts
10 10
export class GraphLoader {
11 11

  
12 12

  
13
  static getGraphType(sensors, data, isAnalytics): Graph {
13
  static getGraphType(sensors, data, legend, isAnalytics): Graph {
14 14
    if (sensors == null) {
15 15
      return new EmptyGraph("Selected no sensors.");
16 16

  
17
    } else if (Array.isArray(sensors)) {
17
    }  else if (Array.isArray(sensors)) {
18 18
      if (sensors.length == 0) {
19 19
        return new EmptyGraph("Selected no sensors.");
20 20
      } else if (sensors.length == 1) {
21
        return new SingleGraph(sensors[0], isAnalytics, data, 10000);
21
        return new SingleGraph(sensors[0], isAnalytics, data, legend,10000);
22 22
      } else {
23
        return new MultiGraph(isAnalytics, data, 10000);
23
        return new MultiGraph(isAnalytics, data, legend,10000);
24 24
      }
25 25

  
26 26
    } else {
27
      return new SingleGraph(sensors, isAnalytics, data, 10000);
27
      return new SingleGraph(sensors, isAnalytics, data, legend, 10000);
28 28
    }
29 29
  }
30 30

  
31 31

  
32
  static getGraph(sensors, data, element, isAnalytics) {
33
    let graph = this.getGraphType(sensors,data, isAnalytics);
32
  static getGraph(sensors, data, legendInfo, element, isAnalytics) {
33
    let graph = this.getGraphType(sensors,data, legendInfo, isAnalytics);
34 34
    let config = graph.getConfig();
35 35
    let spec = graph.getSpec();
36
    spec['data'][0].values = data;
36

  
37 37

  
38 38
    this.showGraph(spec, config, element);
39 39

  
src/app/shared/graph-loading/multigraph.ts
7 7
  isAnalytics: boolean;
8 8
  data: any [];
9 9
  interval: number;
10
  legend: {};
10 11

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

  
16 18
  }
17 19

  
......
22 24
    let config1 = require('/src/vega/config/config.json');
23 25
    lodash.merge(rvalue, config1);
24 26
    let config2 = require('/src/vega/config/config-multiline.json');
27
    let config3 = require('/src/vega/config/config-barline.json');
25 28

  
26 29

  
27 30
    for(let key in config2.signals) {
......
29 32
      rvalue.signals.push(obj);
30 33
    }
31 34

  
32
    return config1;
35
    for(let key in config3.signals) {
36
      let obj = config3.signals[key];
37
      rvalue.signals.push(obj);
38
    }
39

  
40
    return rvalue;
33 41
  }
34 42

  
35 43
  getSpec(): {} {
......
37 45
    const rvalue: any = {};
38 46
    const base = require('/src/vega/base/default.json');
39 47
    const body = require('/src/vega/body/multilinechart.json');
40
    const tooltip = require('/src/vega/tooltip/multiline-tooltip.json');
48
    const legend = require('/src/vega/miscs/legend.json');
49
    const tooltip = require('/src/vega/miscs/multiline-tooltip.json');
41 50

  
42
    lodash.merge(rvalue, base, body, tooltip);
51
    lodash.merge(rvalue, base, body, legend, tooltip);
43 52

  
44
    rvalue.data[0].values = this.data;
53
    rvalue.data[1].values = this.data;
54
    rvalue.data[0].values = this.legend;
45 55
    rvalue.signals[0].value = this.interval;
46 56
    rvalue.marks[0].marks[0].marks[0].marks[2].encode.enter.tooltip.signal = this.getTooltipMessage();
47 57

  
......
58 68
    return message;
59 69
  }
60 70

  
71
  private getLegend(legend: any) {
72
    if(Array.isArray(legend)) {
73
      return legend[0];
74
    } else {
75
      return legend;
76
    }
77
  }
78

  
79

  
61 80
}
src/app/shared/graph-loading/singlegraph.ts
1 1
import {Graph} from "./graph";
2
import {SingleGraphType} from "./singlegraphtype";
2 3

  
3 4
declare var require: any
4 5

  
5
export class SingleGraph implements Graph{
6
export class SingleGraph implements Graph {
6 7
  isAnalytics: boolean;
7 8
  sensorId: number;
8 9
  interval: number;
9 10
  data: any [];
11
  legend: {};
12
  type: SingleGraphType;
10 13

  
11
  constructor(sensorId: number, isAnalytics: boolean, data: any[], interval: number) {
14
  constructor(sensorId: number, isAnalytics: boolean, data: any[], legend: {}, interval: number) {
12 15
    this.sensorId = sensorId;
13 16
    this.isAnalytics = isAnalytics;
14 17
    this.interval = interval;
15 18
    this.data = data;
19
    this.legend = this.getLegend(legend);
20
    this.type = this.getGraphType();
21

  
16 22
  }
17 23

  
24

  
18 25
  getConfig(): {} {
19 26
    const lodash = require('lodash/object');
20 27
    const rvalue: any = {};
21 28
    let config1 = require('/src/vega/config/config.json');
22 29
    lodash.merge(rvalue, config1);
30

  
23 31
    let config2;
24
    if(this.isAnalytics) {
32
    if (this.isAnalytics) {
25 33
      config2 = require('/src/vega/config/config-analytics.json');
26 34
    } else {
27 35
      config2 = require('/src/vega/config/config-observations.json');
28 36
    }
29 37

  
30
    for(let key in config2.signals) {
38
    let config3;
39
    switch (this.type) {
40
      case SingleGraphType.LINECHART:
41
      case SingleGraphType.BARCHART:
42
        config3 = require('/src/vega/config/config-barline.json');
43
        break;
44
      case SingleGraphType.WINDCHART:
45
        config3 = require('/src/vega/config/config-wind.json');
46
        break;
47
    }
48

  
49

  
50
    for (let key in config2.signals) {
31 51
      let obj = config2.signals[key];
32 52
      rvalue.signals.push(obj);
33 53
    }
34 54

  
35
    return config1;
55
    for (let key in config3.signals) {
56
      let obj = config3.signals[key];
57
      rvalue.signals.push(obj);
58
    }
59

  
60
    return rvalue;
36 61
  }
37 62

  
38 63
  getSpec(): {} {
......
40 65
    const rvalue: any = {};
41 66
    const base = require('/src/vega/base/default.json');
42 67
    const body = this.getBodySpec();
68
    const legend = this.getLegendSpec();
43 69
    const tooltip = this.getTooltipSpec();
44
    lodash.merge(rvalue, base, body, tooltip);
70
    lodash.merge(rvalue, base, body, legend, tooltip);
45 71

  
46 72

  
47
    rvalue.data[0].values = this.data;
73
    this.setData(rvalue, this.data);
74
    rvalue['data'][0].values = this.legend;
48 75
    rvalue.signals[0].value = this.interval;
49 76

  
50 77
    return rvalue;
51 78
  }
52 79

  
53 80

  
54
 private getBodySpec() {
81
  private getLegendSpec() {
82
    switch (this.type) {
83
      case SingleGraphType.BARCHART:
84
      case SingleGraphType.LINECHART:
85
        return require('/src/vega/miscs/legend.json');
86
      case SingleGraphType.WINDCHART:
87
        return {};
88
    }
89
  }
90

  
91
  private getBodySpec() {
92
    switch (this.type) {
93
      case SingleGraphType.BARCHART:
94
        return require('/src/vega/body/barchart.json');
95
      case SingleGraphType.WINDCHART:
96
        return require('/src/vega/body/windchart.json');
97
      case SingleGraphType.LINECHART:
98
        //TODO pridat min/max
99
        return require('/src/vega/body/linechart.json');
100
    }
101
  }
102

  
103

  
104
  private getTooltipSpec() {
105
    let lodash = require('lodash');
106
    let tooltipMessage;
107
    let rvalue: any = {};
108
    if (this.isAnalytics) {
109
      lodash.merge(rvalue, require('/src/vega/miscs/samm-tooltip.json'));
110
      tooltipMessage = this.getSammTooltip();
111
    } else {
112
      lodash.merge(rvalue, require('/src/vega/miscs/value-tooltip.json'));
113
      tooltipMessage = this.getValueTooltip();
114
    }
115

  
116
    rvalue.marks[0].marks[0].marks[0].encode.enter.tooltip.signal = tooltipMessage;
117
    return rvalue;
118
  }
119

  
120

  
121
  private getValueTooltip() {
122
    return "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')  ,  'value': datum.value + ' " + this.legend['phenomenon']['unit'] + "', 'gid': datum.gid }"
123
  }
124

  
125
  private getSammTooltip() {
126
    return "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X') " +
127
      " , 'avg': datum.avg + ' " + this.legend['phenomenon']['unit'] +
128
      "', 'sum': datum.sum + ' " + this.legend['phenomenon']['unit'] +
129
      "', 'max': datum.max + ' " + this.legend['phenomenon']['unit'] +
130
      "', 'min': datum.min + ' " + this.legend['phenomenon']['unit'] + "'}"
131
  }
132

  
133

  
134
  private setData(spec: any, data: any) {
135
    if(data.length > 0 && 'data' in data[0]) {
136
      spec['data'][1].values = data[0].data;
137
    } else {
138
      spec['data'][1].values = data;
139
    }
140
  }
141

  
142
  private getLegend(legend: any) {
143
    if (Array.isArray(legend)) {
144
      return legend[0];
145
    } else {
146
      return legend;
147
    }
148
  }
149

  
150
  private getGraphType() {
55 151
    if (this.sensorId >= 480000000 && this.sensorId < 490000000) {
56
      return require('/src/vega/body/barchart.json');
152
      return SingleGraphType.BARCHART;
57 153
    } else if ((this.sensorId >= 470020000 && this.sensorId < 470030000) || (this.sensorId >= 470060000 && this.sensorId < 470090000) ||
58 154
      (this.sensorId >= 470130000 && this.sensorId < 470140000) || (this.sensorId >= 470180000 && this.sensorId < 470190000)) {
59
      return require('/src/vega/body/windchart.json');
155
      return SingleGraphType.WINDCHART;
60 156
    } else {
61 157
      //TODO pridat min/max
62
      return require('/src/vega/body/linechart.json');
158
      return SingleGraphType.LINECHART;
63 159
    }
64 160
  }
65 161

  
66 162

  
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 163
}
src/app/shared/graph-loading/singlegraphtype.ts
1
export enum SingleGraphType{
2
  LINECHART,
3
  BARCHART,
4
  WINDCHART
5
}
src/app/unit/components/unit.component.ts
65 65
              this.sensorGroups.push(sensorType);
66 66
              setTimeout(() => {
67 67
                //GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5));
68
                GraphLoader.getGraph(null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5),null );
68
                GraphLoader.getGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5),null );
69 69
              }, 0);
70 70
            }
71 71
          });
......
101 101
  }
102 102

  
103 103
  getAnalytics(range: Date[], changedDate: boolean, changedSensor: string) {
104
    const groupId = changedSensor.toString().slice(0, 5);
104 105
    if (changedDate) {
105 106
      this.selectedSensors.forEach(selectSens => {
106 107
        this.analyticsService.getAnalytics$Response({unit_id: this.unitId, sensor_id: parseInt(selectSens, 10),
......
111 112
              return response.body;
112 113
            } else if (response.status === 204) {
113 114
              //GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + selectSens.toString().slice(0, 5));
114
              GraphLoader.getGraph(null, null, '#vega_container_' + selectSens.toString().slice(0, 5),null );
115
              GraphLoader.getGraph(null, null, null, '#vega_container_' + selectSens.toString().slice(0, 5),null );
115 116
              this.toastService.showWarningNoData();
116 117
              return response.body;
117 118
            } else {
......
129 130
                  //GraphLoader.getAnalyticsGraph(key, data[key].data, data[key].interval, view);
130 131
                  //GraphLoader.getGraph(this.selectedSensors, this.filteredAnalyticsData(groupId), view, true);
131 132
                } else {
132
                  GraphLoader.getGraph(null, null, view, null);
133
                  GraphLoader.getGraph(null, null, null, view, null);
133 134
                }
134 135
              }
135 136
            }
......
159 160
              const view = '#vega_container_' + key.slice(0, 5);
160 161
              if (this.selectedSensors.some(sens => sens.toString() === key)) {
161 162
               // GraphLoader.getAnalyticsGraph(key, data[key].data, data[key].interval, view);
162
                GraphLoader.getGraph(this.selectedSensors, this.analyticsData, view, true);
163
                GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), view, true);
163 164
              } else {
164 165
                //GraphLoader.getAnalyticsGraph(null, null, null, view);
165
                GraphLoader.getGraph(null, null, view, null);
166
                GraphLoader.getGraph(null, null, null, view, null);
166 167
              }
167 168
            }
168 169
          }
......
181 182
    const sensorGroupElement = '#vega_container_' + groupId;
182 183
    if (!this.selectedSensors.find(sensId => sensId.toString().slice(0, 5) === groupId)) { // if group of sensors is empty show empty graph
183 184
      //GraphLoader.getAnalyticsGraph(null, null, null, sensorGroupElement);
184
      GraphLoader.getGraph(null, null, sensorGroupElement, null);
185
      GraphLoader.getGraph(null, null, null, sensorGroupElement, null);
185 186
    } else {
186 187
      if (this.useAnalyticsData) { // use analytics data
187 188
        if (event.checked) { // if checked > add to graph
188 189
          if (this.analyticsData.some(sens => sens.sensorId === sensorId)) { // if already data for selected sensor in memory
189 190
            //GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
190 191
            // this.analyticsData.find((sens => sens.sensorId === sensorId).interval, sensorGroupElement);
191
            GraphLoader.getGraph(this.selectedSensors, this.analyticsData, sensorGroupElement, true);
192
            GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), sensorGroupElement, true);
192 193

  
193 194
          } else { // get data from server for added sensor and show graph for selected sensors
194 195
            this.showGraph(false, sensorId);
......
196 197
        } else { // remove sensor from graph
197 198
          //GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
198 199
          // this.analyticsData.find(sens => sens.sensorId === sensorId).interval, sensorGroupElement);
199
          GraphLoader.getGraph(this.selectedSensors, this.analyticsData, sensorGroupElement, true);
200
          GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), sensorGroupElement, true);
200 201

  
201 202
        }
202 203
      } else { // use observations data
203 204
        if (event.checked) { // if checked > add to graph
204 205
          if (this.observationsData.some(sens => sens.sensorId.toString() === sensorId)) { // if already data for selected sensor in memory
205
            GraphLoader.getGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement, false);
206
            GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), sensorGroupElement, false);
206 207
            //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
207 208
          } else { // get data from server for added sensor and show graph for selected sensors
208 209
            this.showGraph(false, sensorId);
209 210
          }
210 211
        } else { // remove sensor from graph
211 212
          //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
212
          GraphLoader.getGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement, false);
213
          GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), sensorGroupElement, false);
214

  
213 215
        }
214 216
      }
215 217
    }
......
232 234
      sen.sensorId.toString().slice(0, 5) === sensorGroupId);
233 235
  }
234 236

  
237

  
238
  filteredSelectedSensors(sensorGroupId: string): any {
239
    return this.selectedSensors.filter(sen => sen.toString().slice(0, 5) == sensorGroupId );
240
  }
241

  
242
  filteredSensorsInfos(sensorGroupId: string): any {
243
    return this.sensors.filter(sen => this.selectedSensors.includes(sen.sensorId.toString()) &&
244
      sen.sensorId.toString().slice(0, 5) == sensorGroupId);
245
  }
246

  
235 247
  private getObservations(range: Date[], changedDate: boolean, changedSensorId: string) {
248
    const groupId = changedSensorId.toString().slice(0, 5);
236 249
    if (changedDate) { // if changed date we need new data for all sensors
237 250
      this.observationsData = []; // empty observation data
238 251
      this.selectedSensors.forEach(selectSens => {
......
264 277
              setTimeout(() => {
265 278
                console.log(this.selectedSensors);
266 279
                //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(selectSens.toString().slice(0, 5)), view);
267
                GraphLoader.getGraph(this.selectedSensors,  this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view, false);
280
                GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), view, false);
268 281
              }, 10);
269 282
            }
270 283
          })
......
292 305
          this.observationsData.push({sensorId: changedSensorId, sensor:
293 306
              this.sensors.find(sens => sens.sensorId.toString() === changedSensorId.toString()), data: observations});
294 307
          const view = '#vega_container_' + changedSensorId.toString().slice(0, 5);
295
          if (observations) {
296
            console.log(this.observationsData);
297
            GraphLoader.getGraph(this.selectedSensors,  this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view, false);
298
            //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view);
299
          } else {
300
            //GraphLoader.getMultilineGraph(null, null, null);
301
            GraphLoader.getGraph(this.selectedSensors,  this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view, false);
302
          }
308

  
309
            GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), view, false);
303 310
        }, err => this.toastService.showError(err.error.message));
304 311
    }
305 312
  }
src/vega/base/default.json
1 1
{
2 2
  "data": [
3
    {
4
      "name": "legend",
5
      "values": null
6
    },
3 7
    {
4 8
      "name": "source",
5 9
      "values": null
......
43 47
        },
44 48
        {
45 49
          "type": "formula",
46
          "expr":"time(datum[\"dateMinTemp\"]) - (timeStep * 500)",
50
          "expr":"time(datum[\"dateMinTemp\"]) - timeWindow",
47 51
          "as": "dateMin"
48 52
        },
49 53
        {
50 54
          "type": "formula",
51
          "expr":"time(datum[\"dateMaxTemp\"]) + (timeStep * 500)",
55
          "expr":"time(datum[\"dateMaxTemp\"]) + timeWindow",
52 56
          "as": "dateMax"
53 57
        },
54 58
        {
......
61 65
  ],
62 66

  
63 67
  "signals": [
64
    {
65
      "name": "timeStep",
66
      "value": null
67
    },
68 68
    {
69 69
      "name": "detailDomain"
70 70
    }
......
87 87
          "name": "xDetail",
88 88
          "type": "time",
89 89
          "range": "width",
90
          "domain": {"data": "table", "field": "dateTime"},
90
          "domain": {
91
          "data": "range",
92
          "fields": [
93
            "dateMin",
94
            "dateMax"
95
          ]
96
        },
91 97
          "domainRaw": {"signal": "detailDomain"}
92 98
        }
93 99
      ],
......
124 130
      "encode": {
125 131
        "enter": {
126 132
          "x": {"value": 0},
127
          "y": {"value": 430},
128
          "height": {"value": 70},
129
          "width": {"value": 720},
133
          "y": {"signal":  "overviewHeightStart"},
134
          "height": {"signal": "overviewHeight"},
135
          "width": {"signal":  "width"},
130 136
          "fill": {"value": "transparent"}
131 137
        }
132 138
      },
src/vega/base/empty.json
1 1
{
2 2

  
3 3
  "data":[
4
    {
5
      "name": "legend",
6
      "values": null
7
    },
4 8
    {
5 9
      "name": "source",
6 10
      "values": null
src/vega/body/barchart.json
1 1
{
2 2
  "data": [
3
    {},
4
    {},
5
    {},
6
    {},
3 7
    {},
4 8
    {
9
      "name": "ranks",
10
      "source": "table",
5 11
      "transform": [
6
        {},
7
        {},
8
        {},
9
        {},
10 12
        {
11
          "type": "timeunit",
12
          "field": "dateTime",
13
          "units": [
14
            "year",
15
            "month",
16
            "date",
17
            "hours",
18
            "minutes",
19
            "seconds"
13
          "type": "window",
14
          "sort": {
15
            "field": "dateTime",
16
            "order": "ascending"
17
          },
18
          "ops": [
19
            "rank"
20 20
          ],
21
          "step": {
22
            "signal": "timeStep"
23
          }
21
          "fields": [
22
            "value"
23
          ],
24
          "as": [
25
            "rank"
26
          ]
24 27
        },
25 28
        {
26 29
          "type": "formula",
27
          "expr": "time(datum[\"unit0\"] + (timeStep * 100))",
28
          "as": "barStart"
30
          "expr": "datum.rank + 1",
31
          "as": "nextRank"
29 32
        },
30 33
        {
31 34
          "type": "formula",
32
          "expr": "time(datum[\"unit1\"] - (timeStep * 100))",
33
          "as": "barEnd"
35
          "expr": "datum.rank - 1",
36
          "as": "prevRank"
37
        }
38
      ]
39
    },
40
    {
41
      "name": "lookup",
42
      "source": "ranks",
43
      "transform": [
44
        {
45
          "type": "lookup",
46
          "from": "ranks",
47
          "key": "rank",
48
          "fields": [
49
            "nextRank"
50
          ],
51
          "as": [
52
            "nextObj"
53
          ]
54
        },
55
        {
56
          "type": "lookup",
57
          "from": "ranks",
58
          "key": "rank",
59
          "fields": [
60
            "prevRank"
61
          ],
62
          "as": [
63
            "prevObj"
64
          ]
65
        },
66
        {
67
          "type": "formula",
68
          "expr": "datum.prevObj == null ?  data('range')[0].dateMin : (time(datum.prevObj.dateTime) + time(datum.dateTime)) / 2",
69
          "as": "tempDateStart"
70
        },
71
        {
72
          "type": "formula",
73
          "expr": "datum.nextObj == null ?  data('range')[0].dateMax : (time(datum.nextObj.dateTime) + time(datum.dateTime)) / 2",
74
          "as": "tempDateEnd"
75
        },
76
        {
77
          "type": "formula",
78
          "expr": "(datum.tempDateEnd - datum.tempDateStart) * 0.05",
79
          "as": "tempDateToAdd"
80
        },
81
        {
82
          "type": "formula",
83
          "expr": "datum.tempDateStart + datum.tempDateToAdd",
84
          "as": "dateStart"
85
        },
86
        {
87
          "type": "formula",
88
          "expr": "datum.tempDateEnd - datum.tempDateToAdd",
89
          "as": "dateEnd"
34 90
        }
35 91
      ]
36 92
    }
......
47 103
            0
48 104
          ],
49 105
          "domain": {
50
            "data": "table",
51
            "field": "value"
106
            "fields": [
107
              {"data": "range", "field": "valueMax"},
108
              {"data":  "table", "field": "value"}
109
            ]
52 110
          },
53 111
          "nice": true,
54 112
          "zero": true
......
67 125
            {
68 126
              "type": "rect",
69 127
              "from": {
70
                "data": "table"
128
                "data": "lookup"
71 129
              },
72 130
              "encode": {
73 131
                "enter": {
74 132
                  "tooltip": {
75
                    "signal": "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X') }"
133
                    "signal": "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')  ,  'value': datum.value + 'mm', 'gid': datum.gid }"
76 134
                  }
77 135
                },
78 136
                "update": {
79 137
                  "x": {
80 138
                    "scale": "xDetail",
81
                    "field": "barStart"
139
                    "field": "dateStart"
82 140
                  },
83 141
                  "x2": {
84 142
                    "scale": "xDetail",
85
                    "field": "barEnd"
143
                    "field": "dateEnd"
86 144
                  },
87 145
                  "y": {
88 146
                    "scale": "yDetail",
89
                    "field": "avg"
147
                    "field": "value"
90 148
                  },
91 149
                  "y2": {
92 150
                    "scale": "yDetail",
......
129 187
            }
130 188
          ]
131 189
        }
190
      ],
191
      "marks": [
192
        {},
193
        {},
194
        {},
195
        {
196
          "type": "rect",
197
          "from": {
198
            "data": "lookup"
199
          },
200
          "encode": {
201
            "update": {
202
              "x": {
203
                "scale": "xOverview",
204
                "field": "dateStart"
205
              },
206
              "x2": {
207
                "scale": "xOverview",
208
                "field": "dateEnd"
209
              },
210
              "y": {
211
                "scale": "yOverview",
212
                "field": "value"
213
              },
214
              "y2": {
215
                "scale": "yOverview",
216
                "value": 0
217
              },
218
              "color": {
219
                "value": "both"
220
              },
221
              "fill": {
222
                "value": "steelBlue"
223
              }
224
            }
225
          }
226
        }
132 227
      ]
133 228
    }
134 229
  ]
src/vega/body/linechart.json
4 4
    {},
5 5
    {},
6 6
    {},
7
    {},
7 8
    {
8 9
      "name": "ranks",
9 10
      "source": "table",
......
28 29
          "type": "formula",
29 30
          "expr": "datum.rank + 1",
30 31
          "as": "nextRank"
32
        },
33
        {
34
          "type": "formula",
35
          "expr": "datum.rank - 1",
36
          "as": "prevRank"
31 37
        }
32 38
      ]
33 39
    },
......
37 43
      "transform": [
38 44
        {
39 45
          "type": "lookup",
40
          "from": "table",
46
          "from": "ranks",
41 47
          "key": "rank",
42 48
          "fields": [
43 49
            "nextRank"
......
48 54
        },
49 55
        {
50 56
          "type": "lookup",
51
          "from": "table",
57
          "from": "ranks",
52 58
          "key": "rank",
53 59
          "fields": [
54 60
            "prevRank"
......
77 83
  ],
78 84

  
79 85
  "signals": [
80
    {},
81 86
    {},
82 87
    {
83 88
      "name": "tooltipSignal",
src/vega/body/multilinechart.json
1 1
{
2 2
  "data": [
3
    {},
3 4
    {},
4 5
    {
5 6
      "transform": [
......
26 27
            },
27 28
            {
28 29
              "signal": "sensorPath"
29
            },
30
            {
31
              "signal": "axeLegendPath"
32
            },
33
            {
34
              "signal": "axeLegendUnit"
35 30
            }
36 31
          ],
37 32
          "as": [
38 33
            "value",
39 34
            "timestamp",
40
            "sensor",
41
            "axeLegend",
42
            "axeUnit"
35
            "sensor"
43 36
          ]
44 37
        }
45 38
      ]
......
191 184
    }
192 185
  ],
193 186
  "signals": [
194
    {},
195 187
    {},
196 188
    {
197 189
      "name": "tooltipSignal",
......
269 261
        {},
270 262
        {
271 263
          "orient": "left",
272
          "scale": "yDetail",
273
          "grid": true,
274
          "title": {"signal":  "data('table')[0].axeLegend"},
275
          "encode": {
276
          "labels": {
277
            "update": {
278
              "text":  {"signal": "datum.value + ' ' + data('table')[0].axeUnit"}
279
            }
280
          }
281
        }
264
          "scale": "yDetail"
282 265
        }
283 266
      ],
284 267
      "marks": [
src/vega/body/windchart.json
1 1
{
2 2
  "signals": [
3
    {},
4 3
    {
5 4
      "name": "detailDomain",
6
      "update": "[time(data('range')[0].dateMin), time(data('range')[0].dateMin) + ((timeStep * 1000) * arrowCount)] "
7
    },
8
    {
9
      "name": "arrowCount",
10
      "value": 25
5
      "update": "[time(data('range')[0].dateMin), time(data('range')[0].dateMin) + (timeWindow * arrowCount)] "
11 6
    },
12 7
    {
13 8
      "name": "minMaxRange",
......
15 10
    },
16 11
    {
17 12
      "name": "selectionWidth",
18
      "update": "floor((arrowCount * (timeStep * 1000) * width) / minMaxRange)"
13
      "update": "floor((arrowCount * timeWindow * width) / minMaxRange)"
19 14
    }
20 15

  
21 16
  ],
......
45 40
                    "value": "arrow"
46 41
                  },
47 42
                  "size": {
48
                    "value": 500
43
                    "value": 700
49 44
                  },
50 45
                  "x": {
51 46
                    "scale": "xDetail",
52 47
                    "field": "dateTime"
53 48
                  },
54 49
                  "y": {
55
                    "value": 30
50
                    "signal":  "detailHeight / 2"
56 51
                  },
57 52
                  "angle": {
58
                    "field": "avg"
53
                    "field": "value"
59 54
                  },
60 55
                  "color": {
61 56
                    "value": "both"
......
78 73
        {
79 74
          "update": "[0,selectionWidth]"
80 75
        }
76
      ],
77
      "marks": [
78
        {},
79
        {},
80
        {},
81
        {
82
          "type": "symbol",
83
          "from": {
84
            "data": "table"
85
          },
86
          "encode": {
87
            "update": {
88
            "size": {
89
              "value": 10
90
            },
91
            "x": {
92
              "scale": "xOverview",
93
              "field": "dateTime"
94
            },
95
            "y": {
96
              "signal":  "overviewHeight / 2"
97
            },
98
            "color": {
99
              "value": "both"
100
            },
101
            "strokeWidth": {
102
              "value": 1
103
            },
104
            "fill": {
105
              "value": "steelblue"
106
            }
107
          }
108
          }
109
        }
81 110
      ]
82 111
    }
83 112
  ]
src/vega/config/config-barline.json
1
{
2
  "signals": [
3
    {"name":  "detailHeight", "value": 390},
4
    {"name":  "overviewHeightStart", "value" : 430}
5
  ]
6
}
src/vega/config/config-multiline.json
3 3
    {"name":  "dataPath", "value":  "data"},
4 4
    {"name": "valuePath", "value": "data.value"},
5 5
    {"name":  "timestampPath", "value":  "data.time"},
6
    {"name":  "sensorPath", "value":  "sensor.sensorName"},
7
    {"name":  "axeLegendPath", "value":  "sensor.phenomenon.phenomenonName"},
8
    {"name":  "axeLegendUnit", "value":  "sensor.phenomenon.unit"}
6
    {"name":  "sensorPath", "value":  "sensor.sensorName"}
9 7
  ]
10 8
}
src/vega/config/config-wind.json
1
{
2
  "signals": [
3
    {"name":  "detailHeight", "value": 100},
4
    {"name":  "overviewHeightStart", "value" : 140},
5
    {"name":  "arrowCount", "value": 20}
6
  ]
7
}
src/vega/config/config.json
1 1
{
2 2
  "$schema": "https://vega.github.io/schema/vega/v5.json",
3 3
  "width": 800,
4
  "height": 200,
5
  "padding": 5,
4
  "height": 300,
6 5
  "signals": [
7
    {"name":  "detailHeight", "value": 390},
8 6
    {"name": "overviewHeight", "value":  70},
9
    {"name":  "overviewHeightStart", "value" : 430},
10
    {"name":  "maxTimeDifference", "value": 10000000}
7
    {"name":  "maxTimeDifference", "value": 10000000},
8
    {"name":  "axeLegendPath", "value":  "phenomenon.phenomenonName"},
9
    {"name":  "axeUnitPath", "value":  "phenomenon.unit"},
10
    {"name": "timeWindow", "value": 1800000}
11 11
  ]
12 12
}
src/vega/miscs/legend.json
1
{
2
  "data": [
3
    {
4
      "transform": [
5
        {
6
          "type": "project",
7
          "fields": [
8
            {
9
              "signal": "axeLegendPath"
10
            },
11
            {
12
              "signal": "axeUnitPath"
13
            }
14
          ],
15
          "as": [
16
            "axeLegend",
17
            "axeUnit"
18
          ]
19
        }
20
      ]
21
    }
22
  ],
23
  "marks": [
24
    {
25
      "axes": [
26
        {},
27
        {
28
          "grid": true,
29
          "title": {"signal":  "data('legend')[0].axeLegend"},
30
          "encode": {
31
            "labels": {
32
              "update": {
33
                "text":  {"signal": "datum.value + ' ' + data('legend')[0].axeUnit"}
34
              }
35
            }
36
          }
37
        }
38
      ]
39
    }
40
  ]
41
}
src/vega/miscs/multiline-tooltip.json
1
{
2
  "marks": [
3
    {
4
      "marks": [
5
        {
6
          "marks": [
7
            {
8
              "marks": [
9
                {},
10
                {},
11
                {
12
                  "encode": {
13
                    "enter": {
14
                      "tooltip": {
15
                        "signal": null
16
                      }
17
                    }
18
                  }
19
                }
20
              ]
21
            }
22
          ]
23
        }
24
      ]
25
    }
26
  ]
27
}
src/vega/miscs/samm-tooltip.json
1
{
2
  "data": [
3
    {},
4
    {},
5
    {},
6
    {
7
      "transform": [
8
        {
9
          "fields": [
10
            {"signal" :  "valuePath"},
11
            {"signal":  "timestampPath"},
12
            "sum",
13
            "avg",
14
            "min",
15
            "max"
16

  
17
          ],
18
          "as": [
19
            "value",
20
            "timestamp",
21
            "sum",
22
            "avg",
23
            "min",
24
            "max"
25
          ]
26
        }
27
      ]
28
    }
29
  ],
30
  "marks": [
31
    {
32
      "marks": [
33
        {
34
          "marks": [
35
            {
36
              "encode": {
37
                "enter": {
38
                  "tooltip": {
39
                    "signal": null
40
                  }}
41
              }
42

  
43

  
44
            }
45
          ]
46
        }
47
      ]
48
    }
49
  ]
50
}
src/vega/miscs/value-tooltip.json
1
{
2
  "data": [
3
    {},
4
    {},
5
    {},
6
    {
7
      "transform": [
8
        {
9
          "fields": [
10
            {"signal" :  "valuePath"},
11
            {"signal":  "timestampPath"},
12
            {"signal":  "gidPath"}
13
          ],
14
          "as": [
15
            "value",
16
            "timestamp",
17
            "gid"
18
          ]
19
        }
20
      ]
21
    }
22
  ],
23
  "marks": [
24
    {
25
      "marks": [
26
        {
27
          "marks": [
28
            {
29
              "encode": {
30
                "enter": {
31
                  "tooltip": {
32
                    "signal": null
33
                  }}
34
              }
35

  
36

  
37
            }
38
          ]
39
        }
40
      ]
41
    }
42
  ]
43
}
src/vega/tooltip/multiline-tooltip.json
1
{
2
  "marks": [
3
    {
4
      "marks": [
5
        {
6
          "marks": [
7
            {
8
              "marks": [
9
                {},
10
                {},
11
                {
12
                  "encode": {
13
                    "enter": {
14
                      "tooltip": {
15
                        "signal": null
16
                      }
17
                    }
18
                  }
19
                }
20
              ]
21
            }
22
          ]
23
        }
24
      ]
25
    }
26
  ]
27
}
src/vega/tooltip/samm-tooltip.json
1
{
2
  "data": [
3
    {},
4
    {},
5
    {
6
      "transform": [
7
        {
8
          "fields": [
9
            {"signal" :  "valuePath"},
10
            {"signal":  "timestampPath"},
11
            "sum",
12
            "avg",
13
            "min",
14
            "max"
15

  
16
          ],
17
          "as": [
18
            "value",
19
            "timestamp",
20
            "sum",
21
            "avg",
22
            "min",
23
            "max"
24
          ]
25
        }
26
      ]
27
    }
28
  ],
29
  "marks": [
30
    {
31
      "marks": [
32
        {
33
          "marks": [
34
            {
35
              "encode": {
36
                "enter": {
37
                  "tooltip": {
38
                    "signal": "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')  ,  'avg': datum.avg, 'sum': datum.sum, 'max': datum.max, 'min': datum.min }"
39
                  }}
40
              }
41

  
42

  
43
            }
44
          ]
45
        }
46
      ]
47
    }
48
  ]
49
}
src/vega/tooltip/value-tooltip.json
1
{
2
  "data": [
3
    {},
4
    {},
5
    {
6
      "transform": [
7
        {
8
          "fields": [
9
            {"signal" :  "valuePath"},
10
            {"signal":  "timestampPath"},
11
            {"signal":  "gidPath"}
12
          ],
13
          "as": [
14
            "value",
15
            "timestamp",
16
            "gid"
17
          ]
18
        }
19
      ]
20
    }
21
  ],
22
  "marks": [
23
    {
24
      "marks": [
25
        {
26
          "marks": [
27
            {
28
              "encode": {
29
                "enter": {
30
                  "tooltip": {
31
                    "signal": "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')  ,  'value': datum.value, 'gid': datum.gid }"
32
                  }}
33
              }
34

  
35

  
36
            }
37
          ]
38
        }
39
      ]
40
    }
41
  ]
42
}

Také k dispozici: Unified diff