Blame view

src/app/component/graph/graph.component.ts 6.69 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 {
8c0f5138e   lsagona   plot arbitrary da...
11
    selectedVessel: Vessel;
c666d6db6   lsagona   add map graph and...
12

76ed49493   lsagona   select X and Y value
13
14
15
16
17
18
19
    trace = {
      x: [],
      y: [],
      mode: 'markers',
      type: 'scatter',
      name: '',
    };
8c0f5138e   lsagona   plot arbitrary da...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    constructor(private selectedVesselService: SelectedVesselService) {
    }
  
    // var trace1 = {
    //   x: [1, 2, 3, 4, 5],
    //   y: [1, 6, 3, 6, 1],
    //   mode: 'markers+text',
    //   type: 'scatter',
    //   name: 'Team A',
    //   text: ['A-1', 'A-2', 'A-3', 'A-4', 'A-5'],
    //   textposition: 'top center',
    //   textfont: {
    //     family:  'Raleway, sans-serif'
    //   },
    //   marker: { size: 12 }
    // };
  
    public graph = {
      data: [],
      layout: {
        xaxis: {
          title: ''
        },
        yaxis: {
          title: ''
        }
      }
    };
c666d6db6   lsagona   add map graph and...
48
49
  
    ngOnInit(): void {
8c0f5138e   lsagona   plot arbitrary da...
50
51
52
53
54
55
      this.connectSelectVesselObservable();
    }
  
    connectSelectVesselObservable(): void {
      this.selectedVesselService.currentVessel.subscribe(vessels => {
        this.selectedVessel = vessels;
76ed49493   lsagona   select X and Y value
56
        this.initGraph();
8c0f5138e   lsagona   plot arbitrary da...
57
58
59
60
61
62
63
64
      });
    }
  
    cleanGraph(): void {
      this.graph.data = [];
      this.graph.layout.xaxis.title = '';
      this.graph.layout.yaxis.title = '';
    }
76ed49493   lsagona   select X and Y value
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
140
141
142
143
144
145
146
147
148
149
150
151
152
    updateXaxis(valueType: string): void {
      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...
153

76ed49493   lsagona   select X and Y value
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    updateYaxis(valueType: string): void {
      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 {
      this.graph.data.push(this.trace);
      this.graph.layout.xaxis.title = '';
      this.graph.layout.yaxis.title = '';
c666d6db6   lsagona   add map graph and...
248
249
250
    }
  
  }