Blame view
src/main/kotlin/application/controller/DataPanelController.kt
12.6 KB
513c0341c add chart |
1 2 3 4 5 6 7 |
package application.controller import application.model.* import javafx.collections.FXCollections import javafx.collections.ObservableList import javafx.fxml.FXML import javafx.fxml.Initializable |
513c0341c add chart |
8 9 |
import javafx.scene.control.ListCell import javafx.scene.control.ListView |
e220e082b graph binded to s... |
10 11 |
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch |
f15a58907 add better chart |
12 13 |
import org.charts.dataviewer.api.config.DataViewerConfiguration import org.charts.dataviewer.api.data.PlotData |
f15a58907 add better chart |
14 15 16 |
import org.charts.dataviewer.api.trace.ScatterTrace import org.charts.dataviewer.javafx.JavaFxDataViewer import org.charts.dataviewer.utils.TraceColour |
f15a58907 add better chart |
17 |
import org.charts.dataviewer.utils.TraceVisibility |
513c0341c add chart |
18 19 20 21 22 |
import java.net.URL import java.util.* class DataPanelController : Initializable, SelectedVesselListener { |
df68a9fdc refactor graph mi... |
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
private var dataList: ObservableList<String> = FXCollections.observableArrayList() private lateinit var timeData: ArrayList<String> private val latitude: ArrayList<Double> = arrayListOf() private val longitude: ArrayList<Double> = arrayListOf() private val speedOverGround: ArrayList<Double> = arrayListOf() private val courseOverGround: ArrayList<Double> = arrayListOf() private val heading: ArrayList<Double> = arrayListOf() private val vesselName: ArrayList<String> = arrayListOf() private val imo: ArrayList<String> = arrayListOf() private val callSign: ArrayList<String> = arrayListOf() private val vesselType: ArrayList<Double> = arrayListOf() private val status: ArrayList<String> = arrayListOf() private val length: ArrayList<Double> = arrayListOf() private val width: ArrayList<Double> = arrayListOf() private val draft: ArrayList<Double> = arrayListOf() private val cargo: ArrayList<Double> = arrayListOf() private var selectedItem: String? = null |
513c0341c add chart |
42 43 |
@FXML |
df68a9fdc refactor graph mi... |
44 |
var dataListView = ListView<String>() |
513c0341c add chart |
45 |
|
513c0341c add chart |
46 |
@FXML |
f15a58907 add better chart |
47 |
var dataViewer = JavaFxDataViewer() |
e220e082b graph binded to s... |
48 49 |
private val plotData = PlotData() private val config = DataViewerConfiguration() |
513c0341c add chart |
50 |
override fun initialize(location: URL?, resources: ResourceBundle?) { |
513c0341c add chart |
51 52 |
setObservableSelectedVesselListener() dataListView.items = dataList |
e220e082b graph binded to s... |
53 |
|
867a0df46 populate plot whe... |
54 |
config.showLegend(false) |
f15a58907 add better chart |
55 |
config.setLegendInsidePlot(false) |
513c0341c add chart |
56 |
|
e220e082b graph binded to s... |
57 |
setObservableCurrentTimeListener() |
513c0341c add chart |
58 |
dataListView.setCellFactory { |
df68a9fdc refactor graph mi... |
59 60 |
object : ListCell<String?>() { override fun updateItem(item: String?, empty: Boolean) { |
513c0341c add chart |
61 62 63 64 |
super.updateItem(item, empty) text = if (empty) { null } else { |
df68a9fdc refactor graph mi... |
65 |
item |
513c0341c add chart |
66 67 68 69 70 71 |
} } } } dataListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> |
e220e082b graph binded to s... |
72 |
selectedItem = newValue |
867a0df46 populate plot whe... |
73 |
updateDataList(observableSelectedVessel.value) |
e220e082b graph binded to s... |
74 75 76 77 78 79 80 81 82 83 |
plot(newValue) } plotData.allTraces.clear() config.setxAxisTitle("") config.setyAxisTitle("") config.plotTitle = "" dataViewer.updateConfiguration(config) dataViewer.updatePlot(plotData) initDataList() |
f39d90e60 Select/deselect MMSI |
84 |
|
e220e082b graph binded to s... |
85 |
} |
f15a58907 add better chart |
86 |
|
e220e082b graph binded to s... |
87 |
private fun plot() { |
93534e693 fix exception |
88 |
if (selectedItem != null && observableSelectedVessel.value.messages.size != 0) { |
e220e082b graph binded to s... |
89 90 |
GlobalScope.launch { plot(selectedItem) |
513c0341c add chart |
91 |
} |
e220e082b graph binded to s... |
92 93 |
} } |
513c0341c add chart |
94 |
|
df68a9fdc refactor graph mi... |
95 96 97 |
private fun plot(data: String?) { |
e220e082b graph binded to s... |
98 99 100 101 102 |
if (data == null) { plotData.allTraces.clear() config.setxAxisTitle("") config.setyAxisTitle("") dataViewer.updateConfiguration(config) |
513c0341c add chart |
103 |
|
e220e082b graph binded to s... |
104 |
dataViewer.resetPlot() |
513c0341c add chart |
105 |
|
e220e082b graph binded to s... |
106 |
return |
e220e082b graph binded to s... |
107 |
} |
513c0341c add chart |
108 |
|
e220e082b graph binded to s... |
109 110 111 |
val scatterTrace = ScatterTrace<Any>() scatterTrace.traceColour = TraceColour.RED scatterTrace.traceVisibility = TraceVisibility.TRUE |
f15a58907 add better chart |
112 |
|
df68a9fdc refactor graph mi... |
113 |
val serieStringX: Array<String> = timeData.toTypedArray() |
e220e082b graph binded to s... |
114 |
// val serieDoubleX: Array<Double> = arrayListDoubleX.toTypedArray() |
df68a9fdc refactor graph mi... |
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 153 154 155 156 157 158 159 160 |
var serieStringY: Array<String> = arrayOf() var serieDoubleY: Array<Double> = arrayOf() when (data) { "Latitude" -> { serieDoubleY = latitude.toTypedArray() } "Longitude" -> { serieDoubleY = longitude.toTypedArray() } "Speed Over Ground" -> { serieDoubleY = speedOverGround.toTypedArray() } "Course Over Ground" -> { serieDoubleY = courseOverGround.toTypedArray() } "Heading" -> { serieDoubleY = heading.toTypedArray() } "Vessel Name" -> { serieStringY = vesselName.toTypedArray() } "IMO" -> { serieStringY = imo.toTypedArray() } "Call Sign" -> { serieStringY = callSign.toTypedArray() } "Vessel Type" -> { serieDoubleY = vesselType.toTypedArray() } "Status" -> { serieStringY = status.toTypedArray() } "Length" -> { serieDoubleY = length.toTypedArray() } "Width" -> { serieDoubleY = width.toTypedArray() } "Draft" -> { serieDoubleY = draft.toTypedArray() } "Cargo" -> { serieDoubleY = cargo.toTypedArray() } } |
e220e082b graph binded to s... |
161 |
|
df68a9fdc refactor graph mi... |
162 |
if (serieStringY.isNotEmpty()) { |
e220e082b graph binded to s... |
163 164 165 166 167 |
scatterTrace.setxArray(serieStringX) scatterTrace.setyArray(serieStringY) } else { scatterTrace.setxArray(serieStringX) scatterTrace.setyArray(serieDoubleY) |
513c0341c add chart |
168 |
} |
8108656dd remove plot title |
169 |
config.plotTitle = "" |
e220e082b graph binded to s... |
170 |
config.setxAxisTitle("Time (s)") |
df68a9fdc refactor graph mi... |
171 |
config.setyAxisTitle(data) |
e220e082b graph binded to s... |
172 173 174 |
dataViewer.resetPlot() plotData.allTraces.clear() plotData.addTrace(scatterTrace) |
f15a58907 add better chart |
175 176 |
dataViewer.updateConfiguration(config) dataViewer.updatePlot(plotData) |
513c0341c add chart |
177 178 179 180 181 |
} private fun setObservableSelectedVesselListener() { observableSelectedVessel.listeners.add(this) } |
df68a9fdc refactor graph mi... |
182 |
private fun populateTime(vessel: Vessel): ArrayList<String> { |
e220e082b graph binded to s... |
183 184 185 186 187 |
return if (observableIsReplayState.value) { vessel.getAllTimeBeforeSelectedTime() } else { vessel.getAllTime() } |
513c0341c add chart |
188 |
} |
df68a9fdc refactor graph mi... |
189 |
private fun populateLatitude(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
190 191 192 193 194 |
return if (observableIsReplayState.value) { vessel.getAllLatitudeBeforeSelectedTime() } else { vessel.getAllLatitude() } |
513c0341c add chart |
195 |
} |
df68a9fdc refactor graph mi... |
196 |
private fun populateLongitude(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
197 198 199 200 201 |
return if (observableIsReplayState.value) { vessel.getAllLongitudeBeforeSelectedTime() } else { vessel.getAllLongitude() } |
513c0341c add chart |
202 |
} |
df68a9fdc refactor graph mi... |
203 |
private fun populateSpeedOverGround(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
204 205 206 207 208 |
return if (observableIsReplayState.value) { vessel.getAllSpeedOverGroundBeforeSelectedTime() } else { vessel.getAllSpeedOverGround() } |
513c0341c add chart |
209 |
} |
df68a9fdc refactor graph mi... |
210 |
private fun populateCourseOverGround(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
211 212 213 214 215 |
return if (observableIsReplayState.value) { vessel.getAllCourseOverGroundBeforeSelectedTime() } else { vessel.getAllCourseOverGround() } |
513c0341c add chart |
216 |
} |
df68a9fdc refactor graph mi... |
217 |
private fun populateHeading(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
218 219 220 221 222 |
return if (observableIsReplayState.value) { vessel.getAllHeadingBeforeSelectedTime() } else { vessel.getAllHeading() } |
513c0341c add chart |
223 |
} |
df68a9fdc refactor graph mi... |
224 |
private fun populateVesselName(vessel: Vessel): ArrayList<String> { |
e220e082b graph binded to s... |
225 226 227 228 229 |
return if (observableIsReplayState.value) { vessel.getAllVesselNameBeforeSelectedTime() } else { vessel.getAllVesselName() } |
513c0341c add chart |
230 |
} |
df68a9fdc refactor graph mi... |
231 |
private fun populateIMO(vessel: Vessel): ArrayList<String> { |
e220e082b graph binded to s... |
232 233 234 235 236 |
return if (observableIsReplayState.value) { vessel.getAllIMOBeforeSelectedTime() } else { vessel.getAllIMO() } |
513c0341c add chart |
237 |
} |
df68a9fdc refactor graph mi... |
238 |
private fun populateCallSign(vessel: Vessel): ArrayList<String> { |
e220e082b graph binded to s... |
239 240 241 242 243 |
return if (observableIsReplayState.value) { vessel.getAllCallSignBeforeSelectedTime() } else { vessel.getAllCallSign() } |
513c0341c add chart |
244 |
} |
df68a9fdc refactor graph mi... |
245 |
private fun populateVesselType(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
246 247 248 249 250 |
return if (observableIsReplayState.value) { vessel.getAllVesselTypeBeforeSelectedTime() } else { vessel.getAllVesselType() } |
513c0341c add chart |
251 |
} |
df68a9fdc refactor graph mi... |
252 |
private fun populateStatus(vessel: Vessel): ArrayList<String> { |
e220e082b graph binded to s... |
253 254 255 256 257 |
return if (observableIsReplayState.value) { vessel.getAllStatusBeforeSelectedTime() } else { vessel.getAllStatus() } |
513c0341c add chart |
258 |
} |
df68a9fdc refactor graph mi... |
259 |
private fun populateLength(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
260 261 262 263 264 |
return if (observableIsReplayState.value) { vessel.getAllLengthBeforeSelectedTime() } else { vessel.getAllLength() } |
513c0341c add chart |
265 |
} |
df68a9fdc refactor graph mi... |
266 |
private fun populateWidth(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
267 268 269 270 271 |
return if (observableIsReplayState.value) { vessel.getAllWidthBeforeSelectedTime() } else { vessel.getAllWidth() } |
513c0341c add chart |
272 |
} |
df68a9fdc refactor graph mi... |
273 |
private fun populateDraft(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
274 275 276 277 278 |
return if (observableIsReplayState.value) { vessel.getAllDraftBeforeSelectedTime() } else { vessel.getAllDraft() } |
513c0341c add chart |
279 |
} |
df68a9fdc refactor graph mi... |
280 |
private fun populateCargo(vessel: Vessel): ArrayList<Double> { |
e220e082b graph binded to s... |
281 282 283 284 285 |
return if (observableIsReplayState.value) { vessel.getAllCargoBeforeSelectedTime() } else { vessel.getAllCargo() } |
513c0341c add chart |
286 |
} |
e220e082b graph binded to s... |
287 |
private fun initDataList() { |
df68a9fdc refactor graph mi... |
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
val data = arrayListOf<String>() data.add("Latitude") data.add("Longitude") data.add("Speed Over Ground") data.add("Course Over Ground") data.add("Heading") data.add("Vessel Name") data.add("IMO") data.add("Call Sign") data.add("Vessel Type") data.add("Status") data.add("Length") data.add("Width") data.add("Draft") data.add("Cargo") |
e220e082b graph binded to s... |
304 305 306 307 308 |
dataList.addAll(data) } private fun updateDataList(vessel: Vessel) { |
513c0341c add chart |
309 |
timeData = populateTime(vessel) |
df68a9fdc refactor graph mi... |
310 311 312 |
if (dataListView.selectionModel.selectedItem == null) return //NOTE: Ajouter les nouvelles donnée à la fin when (dataListView.selectionModel.selectedItem) { |
867a0df46 populate plot whe... |
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
"Latitude" -> { latitude.clear() latitude.addAll(populateLatitude(vessel)) } "Longitude" -> { longitude.clear() longitude.addAll(populateLongitude(vessel)) } "Speed Over Ground" -> { speedOverGround.clear() speedOverGround.addAll(populateSpeedOverGround(vessel)) } "Course Over Ground" -> { courseOverGround.clear() courseOverGround.addAll(populateCourseOverGround(vessel)) } "Heading" -> { heading.clear() heading.addAll(populateHeading(vessel)) } "Vessel Name" -> { vesselName.clear() vesselName.addAll(populateVesselName(vessel)) } "IMO" -> { imo.clear() imo.addAll(populateIMO(vessel)) } "Call Sign" -> { callSign.clear() callSign.addAll(populateCallSign(vessel)) } "Vessel Type" -> { vesselType.clear() vesselType.addAll(populateVesselType(vessel)) } "Status" -> { status.clear() status.addAll(populateStatus(vessel)) } "Length" -> { length.clear() length.addAll(populateLength(vessel)) } "Width" -> { width.clear() width.addAll(populateWidth(vessel)) } "Draft" -> { draft.clear() draft.addAll(populateDraft(vessel)) } "Cargo" -> { cargo.clear() cargo.addAll(populateCargo(vessel)) } } |
513c0341c add chart |
370 |
} |
e220e082b graph binded to s... |
371 372 373 374 375 376 377 378 |
private fun setObservableCurrentTimeListener() { observableCurrentTime.listeners.add(object : CurrentTime { override fun onValueChanged(newValue: Int) { updateDataList(observableSelectedVessel.value) plot() } }) } |
513c0341c add chart |
379 |
|
e220e082b graph binded to s... |
380 381 382 |
override fun onValueChanged(newValue: Vessel) { updateDataList(newValue) plot() |
513c0341c add chart |
383 384 385 |
} } |