Blame view

src/app/component/graph/graph.component.ts 6.41 KB
8c0f5138e   lsagona   plot arbitrary da...
1
2
3
  import {Component, OnInit} from '@angular/core';
  import {SelectedVesselService} from '../../service/selected-vessel.service';
  import {Vessel} from '../../model/vessel';
c666d6db6   lsagona   add map graph and...
4
5
6
7
8
9
10
  
  @Component({
    selector: 'app-graph',
    templateUrl: './graph.component.html',
    styleUrls: ['./graph.component.scss']
  })
  export class GraphComponent implements OnInit {
34e0f9db4   lsagona   actualise map on ...
11
12
13
    private selectedVessel: Vessel;
    private yType = '';
    private xType = '';
76ed49493   lsagona   select X and Y value
14
15
16
17
18
19
20
    trace = {
      x: [],
      y: [],
      mode: 'markers',
      type: 'scatter',
      name: '',
    };
8c0f5138e   lsagona   plot arbitrary da...
21
22
    constructor(private selectedVesselService: SelectedVesselService) {
    }
8c0f5138e   lsagona   plot arbitrary da...
23
24
25
26
27
28
29
30
31
32
33
    public graph = {
      data: [],
      layout: {
        xaxis: {
          title: ''
        },
        yaxis: {
          title: ''
        }
      }
    };
c666d6db6   lsagona   add map graph and...
34
35
  
    ngOnInit(): void {
8c0f5138e   lsagona   plot arbitrary da...
36
37
38
39
40
41
      this.connectSelectVesselObservable();
    }
  
    connectSelectVesselObservable(): void {
      this.selectedVesselService.currentVessel.subscribe(vessels => {
        this.selectedVessel = vessels;
76ed49493   lsagona   select X and Y value
42
        this.initGraph();
8c0f5138e   lsagona   plot arbitrary da...
43
44
45
46
47
48
49
50
      });
    }
  
    cleanGraph(): void {
      this.graph.data = [];
      this.graph.layout.xaxis.title = '';
      this.graph.layout.yaxis.title = '';
    }
76ed49493   lsagona   select X and Y value
51
    updateXaxis(valueType: string): void {
34e0f9db4   lsagona   actualise map on ...
52
      this.xType = valueType;
76ed49493   lsagona   select X and Y value
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
      this.trace.x = [];
      switch (valueType) {
        case 'mmsi':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.mmsi);
          });
          break;
        case  'time':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(Date.parse(value.time) / 1000);
          });
          break;
        case  'latitude':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.latitude);
          });
          break;
        case  'longitude':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.longitude);
          });
          break;
        case  'speedOverGround':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.speedOverGround);
          });
          break;
        case  'courseOverGround':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.courseOverGround);
          });
          break;
        case  'heading':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.heading);
          });
          break;
        case  'vesselName':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.vesselName);
          });
          break;
        case  'imo':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.imo);
          });
          break;
        case  'callSign':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.callSign);
          });
          break;
        case  'vesselType':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.vesselType);
          });
          break;
        case  'status':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.status);
          });
          break;
        case  'length':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.length);
          });
          break;
        case  'width':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.width);
          });
          break;
        case  'draft':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.draft);
          });
          break;
        case  'cargo':
          this.selectedVessel.messages.forEach(value => {
            this.trace.x.push(value.cargo);
          });
          break;
      }
      this.graph.data = [];
      this.graph.layout.xaxis.title = valueType;
      this.graph.data.push(this.trace);
    }
8c0f5138e   lsagona   plot arbitrary da...
140

76ed49493   lsagona   select X and Y value
141
    updateYaxis(valueType: string): void {
34e0f9db4   lsagona   actualise map on ...
142
      this.yType = valueType;
76ed49493   lsagona   select X and Y value
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
      this.trace.y = [];
      switch (valueType) {
        case 'mmsi':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.mmsi);
          });
          break;
        case  'time':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(Date.parse(value.time) / 1000);
          });
          break;
        case  'latitude':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.latitude);
          });
          break;
        case  'longitude':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.longitude);
          });
          break;
        case  'speedOverGround':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.speedOverGround);
          });
          break;
        case  'courseOverGround':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.courseOverGround);
          });
          break;
        case  'heading':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.heading);
          });
          break;
        case  'vesselName':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.vesselName);
          });
          break;
        case  'imo':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.imo);
          });
          break;
        case  'callSign':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.callSign);
          });
          break;
        case  'vesselType':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.vesselType);
          });
          break;
        case  'status':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.status);
          });
          break;
        case  'length':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.length);
          });
          break;
        case  'width':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.width);
          });
          break;
        case  'draft':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.draft);
          });
          break;
        case  'cargo':
          this.selectedVessel.messages.forEach(value => {
            this.trace.y.push(value.cargo);
          });
          break;
      }
      this.graph.data = [];
      this.graph.layout.yaxis.title = valueType;
      this.graph.data.push(this.trace);
    }
  
  
    initGraph(): void {
34e0f9db4   lsagona   actualise map on ...
233
234
      this.updateXaxis(this.xType);
      this.updateYaxis(this.yType);
c666d6db6   lsagona   add map graph and...
235
236
237
    }
  
  }