react-spatial 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/.github/workflows/conventional-pr-title.yml +21 -0
  2. package/.github/workflows/main.yml +28 -0
  3. package/.husky/commit-msg +4 -0
  4. package/.husky/post-checkout +4 -0
  5. package/.husky/post-merge +4 -0
  6. package/.husky/post-rebase +4 -0
  7. package/.husky/pre-commit +4 -0
  8. package/.nvmrc +1 -0
  9. package/.whitesource +8 -0
  10. package/CHANGELOG.md +54 -0
  11. package/DEVELOP.md +113 -0
  12. package/README.md +1 -1
  13. package/__mocks__/mapbox-gl.js +11 -0
  14. package/__mocks__/resize-observer-polyfill.js +9 -0
  15. package/babel.config.js +3 -0
  16. package/commitlint.config.js +1 -0
  17. package/data/topic1.js +119 -0
  18. package/data/topic2.js +28 -0
  19. package/doc/README.md +21 -0
  20. package/doc/doc-config.json +4 -0
  21. package/netlify.toml +3 -0
  22. package/package.json +30 -41
  23. package/pull_request_template.md +16 -0
  24. package/renovate.json +4 -0
  25. package/scripts/read-pkg-json.js +17 -0
  26. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.js +322 -0
  27. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +69 -0
  28. package/src/components/BaseLayerSwitcher/README.md +61 -0
  29. package/src/components/BaseLayerSwitcher/__snapshots__/BaseLayerSwitcher.test.js.snap +88 -0
  30. package/src/components/BaseLayerSwitcher/index.js +1 -0
  31. package/src/components/BasicMap/BasicMap.js +413 -0
  32. package/src/components/BasicMap/BasicMap.test.js +281 -0
  33. package/src/components/BasicMap/README.md +18 -0
  34. package/src/components/BasicMap/index.js +1 -0
  35. package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.js +320 -93
  36. package/src/components/CanvasSaveButton/CanvasSaveButton.test.js +148 -0
  37. package/src/components/CanvasSaveButton/README.md +76 -0
  38. package/src/components/CanvasSaveButton/__snapshots__/CanvasSaveButton.test.js.snap +76 -0
  39. package/src/components/CanvasSaveButton/index.js +1 -0
  40. package/src/components/Copyright/Copyright.js +89 -0
  41. package/src/components/Copyright/Copyright.test.js +134 -0
  42. package/src/components/Copyright/README.md +36 -0
  43. package/src/components/Copyright/index.js +1 -0
  44. package/src/components/FeatureExportButton/FeatureExportButton.js +118 -0
  45. package/src/components/FeatureExportButton/FeatureExportButton.test.js +417 -0
  46. package/src/components/FeatureExportButton/README.md +76 -0
  47. package/src/components/FeatureExportButton/__snapshots__/FeatureExportButton.test.js.snap +67 -0
  48. package/src/components/FeatureExportButton/index.js +1 -0
  49. package/src/components/FitExtent/FitExtent.js +62 -0
  50. package/src/components/FitExtent/FitExtent.test.js +48 -0
  51. package/src/components/FitExtent/README.md +34 -0
  52. package/src/components/FitExtent/__snapshots__/FitExtent.test.js.snap +13 -0
  53. package/src/components/FitExtent/index.js +1 -0
  54. package/{components → src/components}/Geolocation/Geolocation.js +144 -61
  55. package/src/components/Geolocation/Geolocation.test.js +267 -0
  56. package/src/components/Geolocation/README.md +25 -0
  57. package/src/components/Geolocation/__snapshots__/Geolocation.test.js.snap +92 -0
  58. package/src/components/Geolocation/index.js +1 -0
  59. package/src/components/LayerTree/LayerTree.js +487 -0
  60. package/src/components/LayerTree/LayerTree.test.js +337 -0
  61. package/src/components/LayerTree/README.md +92 -0
  62. package/src/components/LayerTree/__snapshots__/LayerTree.test.js.snap +1746 -0
  63. package/src/components/LayerTree/index.js +1 -0
  64. package/src/components/MousePosition/MousePosition.js +175 -0
  65. package/src/components/MousePosition/MousePosition.test.js +132 -0
  66. package/src/components/MousePosition/README.md +50 -0
  67. package/src/components/MousePosition/__snapshots__/MousePosition.test.js.snap +76 -0
  68. package/src/components/MousePosition/index.js +1 -0
  69. package/src/components/NorthArrow/NorthArrow.js +75 -0
  70. package/src/components/NorthArrow/NorthArrow.test.js +104 -0
  71. package/src/components/NorthArrow/README.md +59 -0
  72. package/src/components/NorthArrow/__snapshots__/NorthArrow.test.js.snap +117 -0
  73. package/src/components/NorthArrow/index.js +1 -0
  74. package/src/components/Overlay/Overlay.js +176 -0
  75. package/src/components/Overlay/Overlay.test.js +149 -0
  76. package/src/components/Overlay/README.md +59 -0
  77. package/src/components/Overlay/__snapshots__/Overlay.test.js.snap +9 -0
  78. package/src/components/Overlay/index.js +1 -0
  79. package/src/components/Permalink/Permalink.js +326 -0
  80. package/src/components/Permalink/Permalink.test.js +285 -0
  81. package/src/components/Permalink/README.md +105 -0
  82. package/src/components/Permalink/index.js +1 -0
  83. package/{components → src/components}/Popup/Popup.js +165 -55
  84. package/src/components/Popup/Popup.test.js +307 -0
  85. package/src/components/Popup/README.md +93 -0
  86. package/src/components/Popup/__snapshots__/Popup.test.js.snap +180 -0
  87. package/src/components/Popup/index.js +1 -0
  88. package/src/components/README.md +41 -0
  89. package/{components → src/components}/ResizeHandler/ResizeHandler.js +50 -15
  90. package/src/components/ResizeHandler/ResizeHandler.test.js +344 -0
  91. package/src/components/ResizeHandler/index.js +1 -0
  92. package/src/components/RouteSchedule/README.md +118 -0
  93. package/src/components/RouteSchedule/RouteSchedule.js +364 -0
  94. package/src/components/RouteSchedule/RouteSchedule.test.js +113 -0
  95. package/src/components/RouteSchedule/__snapshots__/RouteSchedule.test.js.snap +248 -0
  96. package/src/components/RouteSchedule/index.js +1 -0
  97. package/src/components/ScaleLine/README.md +29 -0
  98. package/src/components/ScaleLine/ScaleLine.js +50 -0
  99. package/src/components/ScaleLine/ScaleLine.test.js +30 -0
  100. package/src/components/ScaleLine/__snapshots__/ScaleLine.test.js.snap +7 -0
  101. package/src/components/ScaleLine/index.js +1 -0
  102. package/src/components/StopsFinder/README.md +50 -0
  103. package/src/components/StopsFinder/StopsFinder.js +284 -0
  104. package/src/components/StopsFinder/StopsFinder.test.js +17 -0
  105. package/src/components/StopsFinder/StopsFinderOption.js +61 -0
  106. package/src/components/StopsFinder/__snapshots__/StopsFinder.test.js.snap +133 -0
  107. package/src/components/StopsFinder/index.js +1 -0
  108. package/src/components/Zoom/README.md +25 -0
  109. package/src/components/Zoom/Zoom.js +180 -0
  110. package/src/components/Zoom/Zoom.test.js +141 -0
  111. package/src/components/Zoom/__snapshots__/Zoom.test.js.snap +201 -0
  112. package/src/components/Zoom/index.js +1 -0
  113. package/{propTypes.js → src/propTypes.js} +16 -12
  114. package/{setupTests.js → src/setupTests.js} +1 -1
  115. package/src/styleguidist/ComponentsList.js +52 -0
  116. package/src/styleguidist/StyleGuide.js +277 -0
  117. package/src/styleguidist/styleguidist.css +38 -0
  118. package/src/utils/GlobalsForOle.js +99 -0
  119. package/src/utils/KML.js +594 -0
  120. package/src/utils/KML.test.js +337 -0
  121. package/src/utils/KMLFormat.js +100 -0
  122. package/src/utils/KMLFormat.test.js +50 -0
  123. package/{utils → src/utils}/Styles.js +20 -14
  124. package/src/utils/__snapshots__/KML.test.js.snap.KML-readFeatures()-and-writeFeatures()-should-read-and-write-lineDash-and-fillPattern-style-for-polygon.canvas-image.png +0 -0
  125. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-2-(cross)-color-and-(light-blue)-opacity.canvas-image.png +0 -0
  126. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-3-(diagonal-line-from-bottom-left-tot-top-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
  127. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-4-(diagonal-line-from-top-left-to-bottom-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
  128. package/{utils → src/utils}/getPolygonPattern.js +34 -6
  129. package/src/utils/getPolygonPattern.test.js +61 -0
  130. package/{utils → src/utils}/timeUtils.js +22 -5
  131. package/src/utils/timeUtils.test.js +30 -0
  132. package/styleguide.config.js +251 -0
  133. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +0 -231
  134. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +0 -7
  135. package/components/BaseLayerSwitcher/index.js +0 -1
  136. package/components/BaseLayerSwitcher/index.js.map +0 -7
  137. package/components/BasicMap/BasicMap.js +0 -278
  138. package/components/BasicMap/BasicMap.js.map +0 -7
  139. package/components/BasicMap/index.js +0 -1
  140. package/components/BasicMap/index.js.map +0 -7
  141. package/components/CanvasSaveButton/CanvasSaveButton.js.map +0 -7
  142. package/components/CanvasSaveButton/index.js +0 -1
  143. package/components/CanvasSaveButton/index.js.map +0 -7
  144. package/components/Copyright/Copyright.js +0 -55
  145. package/components/Copyright/Copyright.js.map +0 -7
  146. package/components/Copyright/index.js +0 -1
  147. package/components/Copyright/index.js.map +0 -7
  148. package/components/FeatureExportButton/FeatureExportButton.js +0 -62
  149. package/components/FeatureExportButton/FeatureExportButton.js.map +0 -7
  150. package/components/FeatureExportButton/index.js +0 -1
  151. package/components/FeatureExportButton/index.js.map +0 -7
  152. package/components/FitExtent/FitExtent.js +0 -32
  153. package/components/FitExtent/FitExtent.js.map +0 -7
  154. package/components/FitExtent/index.js +0 -1
  155. package/components/FitExtent/index.js.map +0 -7
  156. package/components/Geolocation/Geolocation.js.map +0 -7
  157. package/components/Geolocation/index.js +0 -1
  158. package/components/Geolocation/index.js.map +0 -7
  159. package/components/LayerTree/LayerTree.js +0 -278
  160. package/components/LayerTree/LayerTree.js.map +0 -7
  161. package/components/LayerTree/index.js +0 -1
  162. package/components/LayerTree/index.js.map +0 -7
  163. package/components/MousePosition/MousePosition.js +0 -110
  164. package/components/MousePosition/MousePosition.js.map +0 -7
  165. package/components/MousePosition/index.js +0 -1
  166. package/components/MousePosition/index.js.map +0 -7
  167. package/components/NorthArrow/NorthArrow.js +0 -43
  168. package/components/NorthArrow/NorthArrow.js.map +0 -7
  169. package/components/NorthArrow/index.js +0 -1
  170. package/components/NorthArrow/index.js.map +0 -7
  171. package/components/Overlay/Overlay.js +0 -122
  172. package/components/Overlay/Overlay.js.map +0 -7
  173. package/components/Overlay/index.js +0 -1
  174. package/components/Overlay/index.js.map +0 -7
  175. package/components/Permalink/Permalink.js +0 -206
  176. package/components/Permalink/Permalink.js.map +0 -7
  177. package/components/Permalink/index.js +0 -1
  178. package/components/Permalink/index.js.map +0 -7
  179. package/components/Popup/Popup.js.map +0 -7
  180. package/components/Popup/index.js +0 -1
  181. package/components/Popup/index.js.map +0 -7
  182. package/components/ResizeHandler/ResizeHandler.js.map +0 -7
  183. package/components/ResizeHandler/index.js +0 -1
  184. package/components/ResizeHandler/index.js.map +0 -7
  185. package/components/RouteSchedule/RouteSchedule.js +0 -220
  186. package/components/RouteSchedule/RouteSchedule.js.map +0 -7
  187. package/components/RouteSchedule/index.js +0 -1
  188. package/components/RouteSchedule/index.js.map +0 -7
  189. package/components/ScaleLine/ScaleLine.js +0 -32
  190. package/components/ScaleLine/ScaleLine.js.map +0 -7
  191. package/components/ScaleLine/index.js +0 -1
  192. package/components/ScaleLine/index.js.map +0 -7
  193. package/components/StopsFinder/StopsFinder.js +0 -210
  194. package/components/StopsFinder/StopsFinder.js.map +0 -7
  195. package/components/StopsFinder/StopsFinderOption.js +0 -50
  196. package/components/StopsFinder/StopsFinderOption.js.map +0 -7
  197. package/components/StopsFinder/index.js +0 -1
  198. package/components/StopsFinder/index.js.map +0 -7
  199. package/components/Zoom/Zoom.js +0 -120
  200. package/components/Zoom/Zoom.js.map +0 -7
  201. package/components/Zoom/index.js +0 -1
  202. package/components/Zoom/index.js.map +0 -7
  203. package/propTypes.js.map +0 -7
  204. package/setupTests.js.map +0 -7
  205. package/utils/GlobalsForOle.js +0 -94
  206. package/utils/GlobalsForOle.js.map +0 -7
  207. package/utils/KML.js +0 -412
  208. package/utils/KML.js.map +0 -7
  209. package/utils/KMLFormat.js +0 -69
  210. package/utils/KMLFormat.js.map +0 -7
  211. package/utils/Styles.js.map +0 -7
  212. package/utils/getPolygonPattern.js.map +0 -7
  213. package/utils/timeUtils.js.map +0 -7
  214. /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.md.scss +0 -0
  215. /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.scss +0 -0
  216. /package/{components → src/components}/BasicMap/BasicMap.md.scss +0 -0
  217. /package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.md.scss +0 -0
  218. /package/{components → src/components}/Copyright/Copyright.md.scss +0 -0
  219. /package/{components → src/components}/FeatureExportButton/FeatureExportButton.md.scss +0 -0
  220. /package/{components → src/components}/FitExtent/FitExtent.md.scss +0 -0
  221. /package/{components → src/components}/Geolocation/Geolocation.md.scss +0 -0
  222. /package/{components → src/components}/Geolocation/Geolocation.scss +0 -0
  223. /package/{components → src/components}/LayerTree/LayerTree.md.scss +0 -0
  224. /package/{components → src/components}/LayerTree/LayerTree.scss +0 -0
  225. /package/{components → src/components}/MousePosition/MousePosition.md.scss +0 -0
  226. /package/{components → src/components}/NorthArrow/NorthArrow.scss +0 -0
  227. /package/{components → src/components}/Overlay/Overlay.md.scss +0 -0
  228. /package/{components → src/components}/Overlay/Overlay.scss +0 -0
  229. /package/{components → src/components}/Permalink/Permalink.md.scss +0 -0
  230. /package/{components → src/components}/Popup/Popup.md.scss +0 -0
  231. /package/{components → src/components}/Popup/Popup.scss +0 -0
  232. /package/{components → src/components}/RouteSchedule/RouteSchedule.md.scss +0 -0
  233. /package/{components → src/components}/RouteSchedule/RouteSchedule.scss +0 -0
  234. /package/{components → src/components}/ScaleLine/ScaleLine.scss +0 -0
  235. /package/{components → src/components}/Zoom/Zoom.md.scss +0 -0
  236. /package/{components → src/components}/Zoom/Zoom.scss +0 -0
  237. /package/{images → src/images}/RouteSchedule/firstStation.png +0 -0
  238. /package/{images → src/images}/RouteSchedule/lastStation.png +0 -0
  239. /package/{images → src/images}/RouteSchedule/line.png +0 -0
  240. /package/{images → src/images}/RouteSchedule/station.png +0 -0
  241. /package/{images → src/images}/baselayer/baselayer.basebright.png +0 -0
  242. /package/{images → src/images}/baselayer/baselayer.osm.png +0 -0
  243. /package/{images → src/images}/baselayer/baselayer.travic.png +0 -0
  244. /package/{images → src/images}/baselayer/open.topo.map.png +0 -0
  245. /package/{images → src/images}/baselayer/osm.baselayer.hot.png +0 -0
  246. /package/{images → src/images}/baselayer/osm.baselayer.png +0 -0
  247. /package/{images → src/images}/favicon.png +0 -0
  248. /package/{images → src/images}/geops_logo.png +0 -0
  249. /package/{images → src/images}/geops_logo.svg +0 -0
  250. /package/{images → src/images}/geops_qr.png +0 -0
  251. /package/{images → src/images}/mots/bus_poi-blue-01.svg +0 -0
  252. /package/{images → src/images}/mots/bus_poi-grey-01.svg +0 -0
  253. /package/{images → src/images}/mots/bus_round-blue-01.svg +0 -0
  254. /package/{images → src/images}/mots/bus_round-grey-01.svg +0 -0
  255. /package/{images → src/images}/mots/bus_square-blue-01.svg +0 -0
  256. /package/{images → src/images}/mots/bus_square-grey-01.svg +0 -0
  257. /package/{images → src/images}/mots/cable_car_poi-blue-01.svg +0 -0
  258. /package/{images → src/images}/mots/cable_car_poi-grey-01.svg +0 -0
  259. /package/{images → src/images}/mots/cable_car_round-blue-01.svg +0 -0
  260. /package/{images → src/images}/mots/cable_car_round-grey-01.svg +0 -0
  261. /package/{images → src/images}/mots/cable_car_square-blue-01.svg +0 -0
  262. /package/{images → src/images}/mots/cable_car_square-grey-01.svg +0 -0
  263. /package/{images → src/images}/mots/ferry_poi-blue-01.svg +0 -0
  264. /package/{images → src/images}/mots/ferry_poi-grey-01.svg +0 -0
  265. /package/{images → src/images}/mots/ferry_round-blue-01.svg +0 -0
  266. /package/{images → src/images}/mots/ferry_round-grey-01.svg +0 -0
  267. /package/{images → src/images}/mots/ferry_square-blue-01.svg +0 -0
  268. /package/{images → src/images}/mots/ferry_square-grey-01.svg +0 -0
  269. /package/{images → src/images}/mots/funicular_round-blue-01.svg +0 -0
  270. /package/{images → src/images}/mots/funicular_round-grey-01.svg +0 -0
  271. /package/{images → src/images}/mots/funicular_square-blue-01.svg +0 -0
  272. /package/{images → src/images}/mots/gondola_round-blue-01.svg +0 -0
  273. /package/{images → src/images}/mots/rail_poi-blue-01.svg +0 -0
  274. /package/{images → src/images}/mots/rail_poi-grey-01.svg +0 -0
  275. /package/{images → src/images}/mots/rail_round-blue-01.svg +0 -0
  276. /package/{images → src/images}/mots/rail_round-grey-01.svg +0 -0
  277. /package/{images → src/images}/mots/rail_square-blue-01.svg +0 -0
  278. /package/{images → src/images}/mots/rail_square-grey-01.svg +0 -0
  279. /package/{images → src/images}/mots/subway_round blue-01.svg +0 -0
  280. /package/{images → src/images}/mots/subway_round-blue-01.svg +0 -0
  281. /package/{images → src/images}/mots/tram_poi-blue-01.svg +0 -0
  282. /package/{images → src/images}/mots/tram_poi-grey-01.svg +0 -0
  283. /package/{images → src/images}/mots/tram_round-blue-01.svg +0 -0
  284. /package/{images → src/images}/mots/tram_round-grey-01.svg +0 -0
  285. /package/{images → src/images}/mots/tram_square-blue-01.svg +0 -0
  286. /package/{images → src/images}/mots/tram_square-grey-01.svg +0 -0
  287. /package/{images → src/images}/northArrow.svg +0 -0
  288. /package/{images → src/images}/northArrow.url.svg +0 -0
  289. /package/{images → src/images}/northArrowCircle.svg +0 -0
  290. /package/{images → src/images}/northArrowCircle.url.svg +0 -0
  291. /package/{themes → src/themes}/README.md +0 -0
  292. /package/{themes → src/themes}/default/components.scss +0 -0
  293. /package/{themes → src/themes}/default/examples.scss +0 -0
  294. /package/{themes → src/themes}/default/index.scss +0 -0
  295. /package/{themes → src/themes}/default/mixins.scss +0 -0
  296. /package/{themes → src/themes}/default/variables.scss +0 -0
@@ -0,0 +1,364 @@
1
+ /* eslint-disable react/no-unused-prop-types */
2
+ /* eslint-disable react/prop-types */
3
+ import React from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import {
6
+ RealtimeLayer as TrackerLayer,
7
+ realtimeConfig,
8
+ } from 'mobility-toolbox-js/ol';
9
+ import { getHoursAndMinutes, getDelayString } from '../../utils/timeUtils';
10
+ import ReactTransitPropTypes from '../../propTypes';
11
+ import firstStation from '../../images/RouteSchedule/firstStation.png';
12
+ import station from '../../images/RouteSchedule/station.png';
13
+ import lastStation from '../../images/RouteSchedule/lastStation.png';
14
+ import line from '../../images/RouteSchedule/line.png';
15
+
16
+ const { getBgColor } = realtimeConfig;
17
+
18
+ /**
19
+ * Returns a color class to display the delay.
20
+ * @param {Number} time Delay time in milliseconds.
21
+ */
22
+ const getDelayColor = (time) => {
23
+ const secs = Math.round(((time / 1800 / 2) * 3600) / 1000);
24
+ if (secs >= 3600) {
25
+ return 'dark-red';
26
+ }
27
+ if (secs >= 500) {
28
+ return 'middle-red';
29
+ }
30
+ if (secs >= 300) {
31
+ return 'light-red';
32
+ }
33
+ if (secs >= 180) {
34
+ return 'orange';
35
+ }
36
+ return 'green';
37
+ };
38
+
39
+ /**
40
+ * Returns true if the train doesn't stop to the station.
41
+ * @param {Object} stop Station information.
42
+ */
43
+ const isNotStop = (stop) => {
44
+ return !stop.arrivalTime && !stop.departureTime;
45
+ };
46
+
47
+ /**
48
+ * Returns if the station has already been passed by the vehicule.
49
+ * @param {Object} stop Station information.
50
+ * @param {number} time The current time to test in ms.
51
+ * @param {Array<Object>} stops the list of all stops of the train.
52
+ * @param {idx} idx The index of the stop object in the stops array.
53
+ */
54
+ const isPassed = (stop, time, stops, idx) => {
55
+ // If the train doesn't stop to the stop object, we test if the stop just before has been passed or not.
56
+ // if yes the current stop is considered as passed.
57
+ if (isNotStop(stop)) {
58
+ if (stops[idx - 1] && idx > 0) {
59
+ return isPassed(stops[idx - 1], time, stops, idx);
60
+ }
61
+ return true;
62
+ }
63
+
64
+ // Sometimes stop.departureDelay is undefined.
65
+ const timeToCompare = stop.aimedDepartureTime || stop.aimedArrivalTime || 0;
66
+ const delayToCompare = stop.departureDelay || stop.arrivalDelay || 0;
67
+ return timeToCompare + delayToCompare <= time;
68
+ };
69
+
70
+ /**
71
+ * Returns an image for first, middle or last stations.
72
+ * @param {Number} stations The stations list.
73
+ * @param {Number} index Index of the station in the list.
74
+ * @param {Boolean} isStationPassed If the train is already passed at this station.
75
+ * @param {Boolean} isNotStation If the train doesn't stop to this station.
76
+ */
77
+ const defaultRenderStationImg = (
78
+ stations,
79
+ index,
80
+ isStationPassed,
81
+ isNotStation,
82
+ ) => {
83
+ const { length } = stations;
84
+ let src = station.src || station;
85
+ if (index === 0) {
86
+ src = firstStation.src || firstStation;
87
+ } else if (index === length - 1) {
88
+ src = lastStation.src || lastStation;
89
+ } else if (isNotStation) {
90
+ src = line.src || line;
91
+ }
92
+ return <img src={src} alt="routeScheduleLine" className="rt-route-icon" />;
93
+ };
94
+
95
+ const defaultRenderStation = ({
96
+ lineInfos,
97
+ onStationClick,
98
+ trackerLayer,
99
+ renderStationImg,
100
+ stop,
101
+ idx,
102
+ }) => {
103
+ const {
104
+ stationId,
105
+ arrivalDelay,
106
+ departureDelay,
107
+ arrivalTime,
108
+ departureTime,
109
+ state,
110
+ stationName,
111
+ aimedArrivalTime,
112
+ aimedDepartureTime,
113
+ } = stop;
114
+ const cancelled = state === 'JOURNEY_CANCELLED' || state === 'STOP_CANCELLED';
115
+ const { stations } = lineInfos;
116
+ const isFirstStation = idx === 0;
117
+ const isLastStation = idx === stations.length - 1;
118
+ const isStationPassed = isPassed(stop, trackerLayer.time, stations, idx);
119
+ const isNotStation = isNotStop(stop);
120
+ return (
121
+ <div
122
+ // Train line can go in circle so begin and end have the same id,
123
+ // using the time in the key should fix the issue.
124
+ key={(stationId || stationName) + arrivalTime + departureTime}
125
+ role="button"
126
+ className={[
127
+ 'rt-route-station',
128
+ isStationPassed ? ' rt-passed' : '',
129
+ isNotStation ? ' rt-no-stop' : '',
130
+ ].join('')}
131
+ onClick={(e) => {
132
+ return onStationClick(stop, e);
133
+ }}
134
+ tabIndex={0}
135
+ onKeyPress={(e) => {
136
+ return e.which === 13 && onStationClick(stop, e);
137
+ }}
138
+ >
139
+ <div className="rt-route-delay">
140
+ {typeof arrivalDelay === 'undefined' || isFirstStation || cancelled ? (
141
+ ''
142
+ ) : (
143
+ <span
144
+ className={`rt-route-delay-arrival${` ${getDelayColor(
145
+ arrivalDelay,
146
+ )}`}`}
147
+ >
148
+ {`+${getDelayString(arrivalDelay)}`}
149
+ </span>
150
+ )}
151
+ {typeof departureDelay === 'undefined' || isLastStation || cancelled ? (
152
+ ''
153
+ ) : (
154
+ <span
155
+ className={`rt-route-delay-departure${` ${getDelayColor(
156
+ departureDelay,
157
+ )}`}`}
158
+ >
159
+ {`+${getDelayString(departureDelay)}`}
160
+ </span>
161
+ )}
162
+ </div>
163
+ <div className="rt-route-times">
164
+ <span
165
+ className={`rt-route-time-arrival ${
166
+ cancelled ? 'rt-route-cancelled' : ''
167
+ }`}
168
+ >
169
+ {getHoursAndMinutes(aimedArrivalTime)}
170
+ </span>
171
+ <span
172
+ className={`rt-route-time-departure ${
173
+ cancelled ? 'rt-route-cancelled' : ''
174
+ }`}
175
+ >
176
+ {getHoursAndMinutes(aimedDepartureTime)}
177
+ </span>
178
+ </div>
179
+ {renderStationImg(stations, idx, isStationPassed, isNotStation)}
180
+ <div className={cancelled ? 'rt-route-cancelled' : ''}>{stationName}</div>
181
+ </div>
182
+ );
183
+ };
184
+
185
+ const renderRouteIdentifier = ({ routeIdentifier, longName }) => {
186
+ if (routeIdentifier) {
187
+ // first part of the id, without leading zeros.
188
+ const id = parseInt(routeIdentifier.split('.')[0], 10);
189
+ if (!longName.includes(id)) {
190
+ return ` (${id})`;
191
+ }
192
+ }
193
+ return null;
194
+ };
195
+
196
+ const defaultRenderHeader = ({ lineInfos, renderHeaderButtons }) => {
197
+ const {
198
+ type,
199
+ vehicleType,
200
+ shortName,
201
+ longName,
202
+ stroke,
203
+ destination,
204
+ routeIdentifier,
205
+ text_color: textColor,
206
+ } = lineInfos;
207
+ return (
208
+ <div className="rt-route-header">
209
+ <span
210
+ className="rt-route-icon"
211
+ style={{
212
+ /* stylelint-disable-next-line value-keyword-case */
213
+ backgroundColor: stroke || getBgColor(type || vehicleType),
214
+ color: textColor || 'black',
215
+ }}
216
+ >
217
+ {shortName}
218
+ </span>
219
+ <div className="rt-route-title">
220
+ <span className="rt-route-name">{destination}</span>
221
+ <span>
222
+ {longName}
223
+ {renderRouteIdentifier(lineInfos)}
224
+ </span>
225
+ </div>
226
+ <div className="rt-route-buttons">
227
+ {renderHeaderButtons(routeIdentifier)}
228
+ </div>
229
+ </div>
230
+ );
231
+ };
232
+
233
+ const defaultRenderFooter = (props) => {
234
+ const { lineInfos, renderCopyright } = props;
235
+ if (!lineInfos.operator && !lineInfos.publisher) {
236
+ return null;
237
+ }
238
+ return <div className="rt-route-footer">{renderCopyright({ ...props })}</div>;
239
+ };
240
+
241
+ const defaultRenderLink = (text, url) => {
242
+ return (
243
+ <div className="rt-route-copyright-link">
244
+ {url ? (
245
+ <a href={url} target="_blank" rel="noreferrer">
246
+ {text}
247
+ </a>
248
+ ) : (
249
+ <>{text}</>
250
+ )}
251
+ </div>
252
+ );
253
+ };
254
+
255
+ const defaultRenderCopyright = ({ lineInfos }) => {
256
+ return (
257
+ <span className="rt-route-copyright">
258
+ {lineInfos.operator &&
259
+ defaultRenderLink(lineInfos.operator, lineInfos.operatorUrl)}
260
+ {lineInfos.operator && lineInfos.publisher && <span>&nbsp;-&nbsp;</span>}
261
+ {lineInfos.publisher &&
262
+ defaultRenderLink(lineInfos.publisher, lineInfos.publisherUrl)}
263
+ {lineInfos.license && <span>&nbsp;(</span>}
264
+ {lineInfos.license &&
265
+ defaultRenderLink(lineInfos.license, lineInfos.licenseUrl)}
266
+ {lineInfos.license && ')'}
267
+ </span>
268
+ );
269
+ };
270
+
271
+ const propTypes = {
272
+ /**
273
+ * CSS class of the route schedule wrapper.
274
+ */
275
+ className: PropTypes.string,
276
+
277
+ /**
278
+ * Trajectory stations informations.
279
+ */
280
+ lineInfos: ReactTransitPropTypes.lineInfos,
281
+
282
+ /**
283
+ * Trackerlayer.
284
+ */
285
+ trackerLayer: PropTypes.instanceOf(TrackerLayer).isRequired,
286
+
287
+ /**
288
+ * Render Header of the route scheduler.
289
+ */
290
+ renderHeader: PropTypes.func,
291
+
292
+ /**
293
+ * Render Footer of the route scheduler.
294
+ */
295
+ renderFooter: PropTypes.func,
296
+
297
+ /**
298
+ * Render Copyright of the route scheduler.
299
+ */
300
+ renderCopyright: PropTypes.func,
301
+
302
+ /**
303
+ * Render the status of the station image.
304
+ */
305
+ renderStationImg: PropTypes.func,
306
+
307
+ /**
308
+ * Render a station.
309
+ */
310
+ renderStation: PropTypes.func,
311
+
312
+ /**
313
+ * Function triggered on station's click event.
314
+ */
315
+ onStationClick: PropTypes.func,
316
+
317
+ /**
318
+ * Function to render header buttons.
319
+ */
320
+ renderHeaderButtons: PropTypes.func,
321
+ };
322
+
323
+ const defaultProps = {
324
+ className: 'rt-route-schedule',
325
+ lineInfos: null,
326
+ renderHeader: defaultRenderHeader,
327
+ renderStation: defaultRenderStation,
328
+ renderStationImg: defaultRenderStationImg,
329
+ renderCopyright: defaultRenderCopyright,
330
+ renderFooter: defaultRenderFooter,
331
+ renderHeaderButtons: () => {
332
+ return null;
333
+ },
334
+ onStationClick: () => {},
335
+ };
336
+
337
+ /**
338
+ * RouteSchedule displays information, stops and punctuality about the clicked route.
339
+ */
340
+ function RouteSchedule(props) {
341
+ const { lineInfos, className, renderStation, renderHeader, renderFooter } =
342
+ props;
343
+
344
+ if (!lineInfos) {
345
+ return null;
346
+ }
347
+
348
+ return (
349
+ <div className={className}>
350
+ {renderHeader({ ...props })}
351
+ <div className="rt-route-body">
352
+ {lineInfos.stations.map((stop, idx) => {
353
+ return renderStation({ ...props, stop, idx });
354
+ })}
355
+ </div>
356
+ {renderFooter({ ...props })}
357
+ </div>
358
+ );
359
+ }
360
+
361
+ RouteSchedule.propTypes = propTypes;
362
+ RouteSchedule.defaultProps = defaultProps;
363
+
364
+ export default React.memo(RouteSchedule);
@@ -0,0 +1,113 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import 'jest-date-mock';
4
+ import { RealtimeLayer as TrackerLayer } from 'mobility-toolbox-js/ol';
5
+ import RouteSchedule from '.';
6
+
7
+ const RealDate = Date;
8
+
9
+ const lineInfos = {
10
+ backgroundColor: 'ff8a00',
11
+ destination: 'Station name',
12
+ id: 9959310,
13
+ routeIdentifier: '03634.003849.004:9',
14
+ longName: 'T 3',
15
+ shortName: '3',
16
+ operator: 'foo',
17
+ operatorUrl: 'foo.ch',
18
+ publisher: 'bar',
19
+ publisherUrl: 'bar.ch',
20
+ stations: [
21
+ {
22
+ stationId: '1',
23
+ stationName: 'first stop',
24
+ coordinates: [8.51772, 47.3586],
25
+ arrivalDelay: 60000, // +1m
26
+ arrivalTime: 1571729580000 + 60000,
27
+ aimedArrivalTime: 1571729580000,
28
+ departureDelay: 60000,
29
+ aimedDepartureTime: 1571729580000,
30
+ departureTime: 1571729580000 + 60000,
31
+ },
32
+ {
33
+ stationId: '2',
34
+ stationName: 'second stop',
35
+ coordinates: [8.54119, 47.36646],
36
+ arrivalDelay: 0, // +0
37
+ arrivalTime: 1571729903000,
38
+ aimedArrivalTime: 1571729903000,
39
+ departureDelay: 120000, // +2m
40
+ aimedDepartureTime: 1571729903000,
41
+ departureTime: 1571729903000 + 120000,
42
+ },
43
+ {
44
+ stationId: '4',
45
+ stationName: 'no stop',
46
+ coordinates: [8.54119, 47.36646],
47
+ arrivalDelay: null, // +0
48
+ arrivalTime: 0,
49
+ aimedArrivalTime: 0,
50
+ departureDelay: null, // +2m
51
+ departureTime: 0,
52
+ aimedDepartureTime: 0,
53
+ },
54
+ {
55
+ stationId: '3',
56
+ stationName: 'third stop',
57
+ coordinates: [8.54119, 50],
58
+ arrivalDelay: 240000, // +4m
59
+ aimedArrivalTime: 1571730323000,
60
+ arrivalTime: 1571730323000 + 240000,
61
+ departureDelay: 0, // +0
62
+ departureTime: 0,
63
+ aimedDepartureTime: 0,
64
+ },
65
+ ],
66
+ vehicleType: 0,
67
+ };
68
+
69
+ describe('RouteSchedule', () => {
70
+ beforeEach(() => {
71
+ global.Date = jest.fn(() => {
72
+ return {
73
+ getHours: () => {
74
+ return 9;
75
+ },
76
+ getMinutes: () => {
77
+ return 1;
78
+ },
79
+ };
80
+ });
81
+ Object.assign(Date, RealDate);
82
+ });
83
+
84
+ afterEach(() => {
85
+ global.Date = RealDate;
86
+ });
87
+
88
+ test('matches snapshots.', () => {
89
+ const trackerLayer = new TrackerLayer({});
90
+ const component = renderer.create(
91
+ <RouteSchedule
92
+ lineInfos={lineInfos}
93
+ trackerLayer={trackerLayer}
94
+ setCenter={() => {}}
95
+ renderHeaderButtons={() => {
96
+ return <div>Button</div>;
97
+ }}
98
+ />,
99
+ );
100
+ const tree = component.toJSON();
101
+ expect(tree).toMatchSnapshot();
102
+ });
103
+
104
+ // to test: on station click
105
+ // to test: time formating
106
+ // to test: delay formating
107
+ // to test: delay color
108
+ // to test: no arrival delay on first station
109
+ // to test: no arrival date on first station
110
+ // to test: no departure delay on last station
111
+ // to test: no departure date on last station
112
+ // to test: font bold on first and last station
113
+ });
@@ -0,0 +1,248 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`RouteSchedule matches snapshots. 1`] = `
4
+ <div
5
+ className="rt-route-schedule"
6
+ >
7
+ <div
8
+ className="rt-route-header"
9
+ >
10
+ <span
11
+ className="rt-route-icon"
12
+ style={
13
+ {
14
+ "backgroundColor": "#ffb400",
15
+ "color": "black",
16
+ }
17
+ }
18
+ >
19
+ 3
20
+ </span>
21
+ <div
22
+ className="rt-route-title"
23
+ >
24
+ <span
25
+ className="rt-route-name"
26
+ >
27
+ Station name
28
+ </span>
29
+ <span>
30
+ T 3
31
+ (3634)
32
+ </span>
33
+ </div>
34
+ <div
35
+ className="rt-route-buttons"
36
+ >
37
+ <div>
38
+ Button
39
+ </div>
40
+ </div>
41
+ </div>
42
+ <div
43
+ className="rt-route-body"
44
+ >
45
+ <div
46
+ className="rt-route-station"
47
+ onClick={[Function]}
48
+ onKeyPress={[Function]}
49
+ role="button"
50
+ tabIndex={0}
51
+ >
52
+ <div
53
+ className="rt-route-delay"
54
+ >
55
+ <span
56
+ className="rt-route-delay-departure green"
57
+ >
58
+ +1m
59
+ </span>
60
+ </div>
61
+ <div
62
+ className="rt-route-times"
63
+ >
64
+ <span
65
+ className="rt-route-time-arrival "
66
+ >
67
+ 09:01
68
+ </span>
69
+ <span
70
+ className="rt-route-time-departure "
71
+ >
72
+ 09:01
73
+ </span>
74
+ </div>
75
+ <img
76
+ alt="routeScheduleLine"
77
+ className="rt-route-icon"
78
+ src="src"
79
+ />
80
+ <div
81
+ className=""
82
+ >
83
+ first stop
84
+ </div>
85
+ </div>
86
+ <div
87
+ className="rt-route-station"
88
+ onClick={[Function]}
89
+ onKeyPress={[Function]}
90
+ role="button"
91
+ tabIndex={0}
92
+ >
93
+ <div
94
+ className="rt-route-delay"
95
+ >
96
+ <span
97
+ className="rt-route-delay-arrival green"
98
+ >
99
+ +0
100
+ </span>
101
+ <span
102
+ className="rt-route-delay-departure green"
103
+ >
104
+ +2m
105
+ </span>
106
+ </div>
107
+ <div
108
+ className="rt-route-times"
109
+ >
110
+ <span
111
+ className="rt-route-time-arrival "
112
+ >
113
+ 09:01
114
+ </span>
115
+ <span
116
+ className="rt-route-time-departure "
117
+ >
118
+ 09:01
119
+ </span>
120
+ </div>
121
+ <img
122
+ alt="routeScheduleLine"
123
+ className="rt-route-icon"
124
+ src="src"
125
+ />
126
+ <div
127
+ className=""
128
+ >
129
+ second stop
130
+ </div>
131
+ </div>
132
+ <div
133
+ className="rt-route-station rt-no-stop"
134
+ onClick={[Function]}
135
+ onKeyPress={[Function]}
136
+ role="button"
137
+ tabIndex={0}
138
+ >
139
+ <div
140
+ className="rt-route-delay"
141
+ >
142
+ <span
143
+ className="rt-route-delay-arrival green"
144
+ >
145
+ +0
146
+ </span>
147
+ <span
148
+ className="rt-route-delay-departure green"
149
+ >
150
+ +0
151
+ </span>
152
+ </div>
153
+ <div
154
+ className="rt-route-times"
155
+ >
156
+ <span
157
+ className="rt-route-time-arrival "
158
+ />
159
+ <span
160
+ className="rt-route-time-departure "
161
+ />
162
+ </div>
163
+ <img
164
+ alt="routeScheduleLine"
165
+ className="rt-route-icon"
166
+ src="src"
167
+ />
168
+ <div
169
+ className=""
170
+ >
171
+ no stop
172
+ </div>
173
+ </div>
174
+ <div
175
+ className="rt-route-station"
176
+ onClick={[Function]}
177
+ onKeyPress={[Function]}
178
+ role="button"
179
+ tabIndex={0}
180
+ >
181
+ <div
182
+ className="rt-route-delay"
183
+ >
184
+ <span
185
+ className="rt-route-delay-arrival orange"
186
+ >
187
+ +4m
188
+ </span>
189
+ </div>
190
+ <div
191
+ className="rt-route-times"
192
+ >
193
+ <span
194
+ className="rt-route-time-arrival "
195
+ >
196
+ 09:01
197
+ </span>
198
+ <span
199
+ className="rt-route-time-departure "
200
+ />
201
+ </div>
202
+ <img
203
+ alt="routeScheduleLine"
204
+ className="rt-route-icon"
205
+ src="src"
206
+ />
207
+ <div
208
+ className=""
209
+ >
210
+ third stop
211
+ </div>
212
+ </div>
213
+ </div>
214
+ <div
215
+ className="rt-route-footer"
216
+ >
217
+ <span
218
+ className="rt-route-copyright"
219
+ >
220
+ <div
221
+ className="rt-route-copyright-link"
222
+ >
223
+ <a
224
+ href="foo.ch"
225
+ rel="noreferrer"
226
+ target="_blank"
227
+ >
228
+ foo
229
+ </a>
230
+ </div>
231
+ <span>
232
+  - 
233
+ </span>
234
+ <div
235
+ className="rt-route-copyright-link"
236
+ >
237
+ <a
238
+ href="bar.ch"
239
+ rel="noreferrer"
240
+ target="_blank"
241
+ >
242
+ bar
243
+ </a>
244
+ </div>
245
+ </span>
246
+ </div>
247
+ </div>
248
+ `;