react-spatial 1.5.2 → 1.5.3
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.
- package/.github/workflows/conventional-pr-title.yml +21 -0
- package/.github/workflows/main.yml +28 -0
- package/.husky/commit-msg +4 -0
- package/.husky/post-checkout +4 -0
- package/.husky/post-merge +4 -0
- package/.husky/post-rebase +4 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/.whitesource +8 -0
- package/CHANGELOG.md +65 -0
- package/DEVELOP.md +113 -0
- package/__mocks__/mapbox-gl.js +11 -0
- package/__mocks__/resize-observer-polyfill.js +9 -0
- package/babel.config.js +3 -0
- package/commitlint.config.js +1 -0
- package/data/topic1.js +119 -0
- package/data/topic2.js +28 -0
- package/doc/README.md +21 -0
- package/doc/doc-config.json +4 -0
- package/package.json +4 -3
- package/pull_request_template.md +16 -0
- package/renovate.json +4 -0
- package/scripts/read-pkg-json.js +17 -0
- package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.js +322 -0
- package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +69 -0
- package/src/components/BaseLayerSwitcher/README.md +61 -0
- package/src/components/BaseLayerSwitcher/__snapshots__/BaseLayerSwitcher.test.js.snap +88 -0
- package/src/components/BaseLayerSwitcher/index.js +1 -0
- package/src/components/BasicMap/BasicMap.js +413 -0
- package/src/components/BasicMap/BasicMap.test.js +281 -0
- package/src/components/BasicMap/README.md +18 -0
- package/src/components/BasicMap/index.js +1 -0
- package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.js +320 -93
- package/src/components/CanvasSaveButton/CanvasSaveButton.test.js +148 -0
- package/src/components/CanvasSaveButton/README.md +76 -0
- package/src/components/CanvasSaveButton/__snapshots__/CanvasSaveButton.test.js.snap +76 -0
- package/src/components/CanvasSaveButton/index.js +1 -0
- package/src/components/Copyright/Copyright.js +89 -0
- package/src/components/Copyright/Copyright.test.js +134 -0
- package/src/components/Copyright/README.md +36 -0
- package/src/components/Copyright/index.js +1 -0
- package/src/components/FeatureExportButton/FeatureExportButton.js +118 -0
- package/src/components/FeatureExportButton/FeatureExportButton.test.js +417 -0
- package/src/components/FeatureExportButton/README.md +76 -0
- package/src/components/FeatureExportButton/__snapshots__/FeatureExportButton.test.js.snap +67 -0
- package/src/components/FeatureExportButton/index.js +1 -0
- package/src/components/FitExtent/FitExtent.js +62 -0
- package/src/components/FitExtent/FitExtent.test.js +48 -0
- package/src/components/FitExtent/README.md +34 -0
- package/src/components/FitExtent/__snapshots__/FitExtent.test.js.snap +13 -0
- package/src/components/FitExtent/index.js +1 -0
- package/{components → src/components}/Geolocation/Geolocation.js +144 -61
- package/src/components/Geolocation/Geolocation.test.js +267 -0
- package/src/components/Geolocation/README.md +25 -0
- package/src/components/Geolocation/__snapshots__/Geolocation.test.js.snap +92 -0
- package/src/components/Geolocation/index.js +1 -0
- package/src/components/LayerTree/LayerTree.js +487 -0
- package/src/components/LayerTree/LayerTree.test.js +337 -0
- package/src/components/LayerTree/README.md +92 -0
- package/src/components/LayerTree/__snapshots__/LayerTree.test.js.snap +1746 -0
- package/src/components/LayerTree/index.js +1 -0
- package/src/components/MousePosition/MousePosition.js +175 -0
- package/src/components/MousePosition/MousePosition.test.js +132 -0
- package/src/components/MousePosition/README.md +50 -0
- package/src/components/MousePosition/__snapshots__/MousePosition.test.js.snap +76 -0
- package/src/components/MousePosition/index.js +1 -0
- package/src/components/NorthArrow/NorthArrow.js +75 -0
- package/src/components/NorthArrow/NorthArrow.test.js +104 -0
- package/src/components/NorthArrow/README.md +59 -0
- package/src/components/NorthArrow/__snapshots__/NorthArrow.test.js.snap +117 -0
- package/src/components/NorthArrow/index.js +1 -0
- package/src/components/Overlay/Overlay.js +176 -0
- package/src/components/Overlay/Overlay.test.js +149 -0
- package/src/components/Overlay/README.md +59 -0
- package/src/components/Overlay/__snapshots__/Overlay.test.js.snap +9 -0
- package/src/components/Overlay/index.js +1 -0
- package/src/components/Permalink/Permalink.js +326 -0
- package/src/components/Permalink/Permalink.test.js +285 -0
- package/src/components/Permalink/README.md +105 -0
- package/src/components/Permalink/index.js +1 -0
- package/{components → src/components}/Popup/Popup.js +165 -55
- package/src/components/Popup/Popup.test.js +307 -0
- package/src/components/Popup/README.md +93 -0
- package/src/components/Popup/__snapshots__/Popup.test.js.snap +180 -0
- package/src/components/Popup/index.js +1 -0
- package/src/components/README.md +41 -0
- package/{components → src/components}/ResizeHandler/ResizeHandler.js +50 -15
- package/src/components/ResizeHandler/ResizeHandler.test.js +344 -0
- package/src/components/ResizeHandler/index.js +1 -0
- package/src/components/RouteSchedule/README.md +118 -0
- package/src/components/RouteSchedule/RouteSchedule.js +370 -0
- package/src/components/RouteSchedule/RouteSchedule.test.js +113 -0
- package/src/components/RouteSchedule/__snapshots__/RouteSchedule.test.js.snap +248 -0
- package/src/components/RouteSchedule/index.js +1 -0
- package/src/components/ScaleLine/README.md +29 -0
- package/src/components/ScaleLine/ScaleLine.js +50 -0
- package/src/components/ScaleLine/ScaleLine.test.js +30 -0
- package/src/components/ScaleLine/__snapshots__/ScaleLine.test.js.snap +7 -0
- package/src/components/ScaleLine/index.js +1 -0
- package/src/components/StopsFinder/README.md +50 -0
- package/src/components/StopsFinder/StopsFinder.js +284 -0
- package/src/components/StopsFinder/StopsFinder.test.js +17 -0
- package/src/components/StopsFinder/StopsFinderOption.js +61 -0
- package/src/components/StopsFinder/__snapshots__/StopsFinder.test.js.snap +133 -0
- package/src/components/StopsFinder/index.js +1 -0
- package/src/components/Zoom/README.md +25 -0
- package/src/components/Zoom/Zoom.js +180 -0
- package/src/components/Zoom/Zoom.test.js +141 -0
- package/src/components/Zoom/__snapshots__/Zoom.test.js.snap +201 -0
- package/src/components/Zoom/index.js +1 -0
- package/{propTypes.js → src/propTypes.js} +16 -12
- package/{setupTests.js → src/setupTests.js} +1 -1
- package/src/styleguidist/ComponentsList.js +52 -0
- package/src/styleguidist/StyleGuide.js +277 -0
- package/src/styleguidist/styleguidist.css +38 -0
- package/src/utils/GlobalsForOle.js +99 -0
- package/src/utils/KML.js +594 -0
- package/src/utils/KML.test.js +337 -0
- package/src/utils/KMLFormat.js +100 -0
- package/src/utils/KMLFormat.test.js +50 -0
- package/{utils → src/utils}/Styles.js +20 -14
- 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
- package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-2-(cross)-color-and-(light-blue)-opacity.canvas-image.png +0 -0
- 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
- 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
- package/{utils → src/utils}/getPolygonPattern.js +34 -6
- package/src/utils/getPolygonPattern.test.js +61 -0
- package/src/utils/timeUtils.js +52 -0
- package/src/utils/timeUtils.test.js +30 -0
- package/styleguide.config.js +251 -0
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +0 -231
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +0 -7
- package/components/BaseLayerSwitcher/index.js +0 -1
- package/components/BaseLayerSwitcher/index.js.map +0 -7
- package/components/BasicMap/BasicMap.js +0 -278
- package/components/BasicMap/BasicMap.js.map +0 -7
- package/components/BasicMap/index.js +0 -1
- package/components/BasicMap/index.js.map +0 -7
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +0 -7
- package/components/CanvasSaveButton/index.js +0 -1
- package/components/CanvasSaveButton/index.js.map +0 -7
- package/components/Copyright/Copyright.js +0 -55
- package/components/Copyright/Copyright.js.map +0 -7
- package/components/Copyright/index.js +0 -1
- package/components/Copyright/index.js.map +0 -7
- package/components/FeatureExportButton/FeatureExportButton.js +0 -62
- package/components/FeatureExportButton/FeatureExportButton.js.map +0 -7
- package/components/FeatureExportButton/index.js +0 -1
- package/components/FeatureExportButton/index.js.map +0 -7
- package/components/FitExtent/FitExtent.js +0 -32
- package/components/FitExtent/FitExtent.js.map +0 -7
- package/components/FitExtent/index.js +0 -1
- package/components/FitExtent/index.js.map +0 -7
- package/components/Geolocation/Geolocation.js.map +0 -7
- package/components/Geolocation/index.js +0 -1
- package/components/Geolocation/index.js.map +0 -7
- package/components/LayerTree/LayerTree.js +0 -278
- package/components/LayerTree/LayerTree.js.map +0 -7
- package/components/LayerTree/index.js +0 -1
- package/components/LayerTree/index.js.map +0 -7
- package/components/MousePosition/MousePosition.js +0 -110
- package/components/MousePosition/MousePosition.js.map +0 -7
- package/components/MousePosition/index.js +0 -1
- package/components/MousePosition/index.js.map +0 -7
- package/components/NorthArrow/NorthArrow.js +0 -43
- package/components/NorthArrow/NorthArrow.js.map +0 -7
- package/components/NorthArrow/index.js +0 -1
- package/components/NorthArrow/index.js.map +0 -7
- package/components/Overlay/Overlay.js +0 -122
- package/components/Overlay/Overlay.js.map +0 -7
- package/components/Overlay/index.js +0 -1
- package/components/Overlay/index.js.map +0 -7
- package/components/Permalink/Permalink.js +0 -206
- package/components/Permalink/Permalink.js.map +0 -7
- package/components/Permalink/index.js +0 -1
- package/components/Permalink/index.js.map +0 -7
- package/components/Popup/Popup.js.map +0 -7
- package/components/Popup/index.js +0 -1
- package/components/Popup/index.js.map +0 -7
- package/components/ResizeHandler/ResizeHandler.js.map +0 -7
- package/components/ResizeHandler/index.js +0 -1
- package/components/ResizeHandler/index.js.map +0 -7
- package/components/RouteSchedule/RouteSchedule.js +0 -220
- package/components/RouteSchedule/RouteSchedule.js.map +0 -7
- package/components/RouteSchedule/index.js +0 -1
- package/components/RouteSchedule/index.js.map +0 -7
- package/components/ScaleLine/ScaleLine.js +0 -32
- package/components/ScaleLine/ScaleLine.js.map +0 -7
- package/components/ScaleLine/index.js +0 -1
- package/components/ScaleLine/index.js.map +0 -7
- package/components/StopsFinder/StopsFinder.js +0 -210
- package/components/StopsFinder/StopsFinder.js.map +0 -7
- package/components/StopsFinder/StopsFinderOption.js +0 -51
- package/components/StopsFinder/StopsFinderOption.js.map +0 -7
- package/components/StopsFinder/index.js +0 -1
- package/components/StopsFinder/index.js.map +0 -7
- package/components/Zoom/Zoom.js +0 -130
- package/components/Zoom/Zoom.js.map +0 -7
- package/components/Zoom/index.js +0 -1
- package/components/Zoom/index.js.map +0 -7
- package/propTypes.js.map +0 -7
- package/setupTests.js.map +0 -7
- package/utils/GlobalsForOle.js +0 -94
- package/utils/GlobalsForOle.js.map +0 -7
- package/utils/KML.js +0 -412
- package/utils/KML.js.map +0 -7
- package/utils/KMLFormat.js +0 -69
- package/utils/KMLFormat.js.map +0 -7
- package/utils/Styles.js.map +0 -7
- package/utils/getPolygonPattern.js.map +0 -7
- package/utils/timeUtils.js +0 -31
- package/utils/timeUtils.js.map +0 -7
- /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.md.scss +0 -0
- /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.scss +0 -0
- /package/{components → src/components}/BasicMap/BasicMap.md.scss +0 -0
- /package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.md.scss +0 -0
- /package/{components → src/components}/Copyright/Copyright.md.scss +0 -0
- /package/{components → src/components}/FeatureExportButton/FeatureExportButton.md.scss +0 -0
- /package/{components → src/components}/FitExtent/FitExtent.md.scss +0 -0
- /package/{components → src/components}/Geolocation/Geolocation.md.scss +0 -0
- /package/{components → src/components}/Geolocation/Geolocation.scss +0 -0
- /package/{components → src/components}/LayerTree/LayerTree.md.scss +0 -0
- /package/{components → src/components}/LayerTree/LayerTree.scss +0 -0
- /package/{components → src/components}/MousePosition/MousePosition.md.scss +0 -0
- /package/{components → src/components}/NorthArrow/NorthArrow.scss +0 -0
- /package/{components → src/components}/Overlay/Overlay.md.scss +0 -0
- /package/{components → src/components}/Overlay/Overlay.scss +0 -0
- /package/{components → src/components}/Permalink/Permalink.md.scss +0 -0
- /package/{components → src/components}/Popup/Popup.md.scss +0 -0
- /package/{components → src/components}/Popup/Popup.scss +0 -0
- /package/{components → src/components}/RouteSchedule/RouteSchedule.md.scss +0 -0
- /package/{components → src/components}/RouteSchedule/RouteSchedule.scss +0 -0
- /package/{components → src/components}/ScaleLine/ScaleLine.scss +0 -0
- /package/{components → src/components}/Zoom/Zoom.md.scss +0 -0
- /package/{components → src/components}/Zoom/Zoom.scss +0 -0
- /package/{images → src/images}/RouteSchedule/firstStation.png +0 -0
- /package/{images → src/images}/RouteSchedule/lastStation.png +0 -0
- /package/{images → src/images}/RouteSchedule/line.png +0 -0
- /package/{images → src/images}/RouteSchedule/station.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.basebright.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.osm.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.travic.png +0 -0
- /package/{images → src/images}/baselayer/open.topo.map.png +0 -0
- /package/{images → src/images}/baselayer/osm.baselayer.hot.png +0 -0
- /package/{images → src/images}/baselayer/osm.baselayer.png +0 -0
- /package/{images → src/images}/favicon.png +0 -0
- /package/{images → src/images}/geops_logo.png +0 -0
- /package/{images → src/images}/geops_logo.svg +0 -0
- /package/{images → src/images}/geops_qr.png +0 -0
- /package/{images → src/images}/mots/bus_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/bus_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/bus_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/gondola_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/rail_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/rail_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/subway_round blue-01.svg +0 -0
- /package/{images → src/images}/mots/subway_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/tram_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/tram_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_square-grey-01.svg +0 -0
- /package/{images → src/images}/northArrow.svg +0 -0
- /package/{images → src/images}/northArrow.url.svg +0 -0
- /package/{images → src/images}/northArrowCircle.svg +0 -0
- /package/{images → src/images}/northArrowCircle.url.svg +0 -0
- /package/{themes → src/themes}/README.md +0 -0
- /package/{themes → src/themes}/default/components.scss +0 -0
- /package/{themes → src/themes}/default/examples.scss +0 -0
- /package/{themes → src/themes}/default/index.scss +0 -0
- /package/{themes → src/themes}/default/mixins.scss +0 -0
- /package/{themes → src/themes}/default/variables.scss +0 -0
|
@@ -0,0 +1,370 @@
|
|
|
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
|
+
let delayToCompare = stop.departureDelay || stop.arrivalDelay || 0;
|
|
67
|
+
|
|
68
|
+
// It could happens that the delay is negative we simply ignores it.
|
|
69
|
+
if (delayToCompare < 0) {
|
|
70
|
+
delayToCompare = 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return timeToCompare + delayToCompare <= time;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns an image for first, middle or last stations.
|
|
78
|
+
* @param {Number} stations The stations list.
|
|
79
|
+
* @param {Number} index Index of the station in the list.
|
|
80
|
+
* @param {Boolean} isStationPassed If the train is already passed at this station.
|
|
81
|
+
* @param {Boolean} isNotStation If the train doesn't stop to this station.
|
|
82
|
+
*/
|
|
83
|
+
const defaultRenderStationImg = (
|
|
84
|
+
stations,
|
|
85
|
+
index,
|
|
86
|
+
isStationPassed,
|
|
87
|
+
isNotStation,
|
|
88
|
+
) => {
|
|
89
|
+
const { length } = stations;
|
|
90
|
+
let src = station.src || station;
|
|
91
|
+
if (index === 0) {
|
|
92
|
+
src = firstStation.src || firstStation;
|
|
93
|
+
} else if (index === length - 1) {
|
|
94
|
+
src = lastStation.src || lastStation;
|
|
95
|
+
} else if (isNotStation) {
|
|
96
|
+
src = line.src || line;
|
|
97
|
+
}
|
|
98
|
+
return <img src={src} alt="routeScheduleLine" className="rt-route-icon" />;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const defaultRenderStation = ({
|
|
102
|
+
lineInfos,
|
|
103
|
+
onStationClick,
|
|
104
|
+
trackerLayer,
|
|
105
|
+
renderStationImg,
|
|
106
|
+
stop,
|
|
107
|
+
idx,
|
|
108
|
+
}) => {
|
|
109
|
+
const {
|
|
110
|
+
stationId,
|
|
111
|
+
arrivalDelay,
|
|
112
|
+
departureDelay,
|
|
113
|
+
arrivalTime,
|
|
114
|
+
departureTime,
|
|
115
|
+
state,
|
|
116
|
+
stationName,
|
|
117
|
+
aimedArrivalTime,
|
|
118
|
+
aimedDepartureTime,
|
|
119
|
+
} = stop;
|
|
120
|
+
const cancelled = state === 'JOURNEY_CANCELLED' || state === 'STOP_CANCELLED';
|
|
121
|
+
const { stations } = lineInfos;
|
|
122
|
+
const isFirstStation = idx === 0;
|
|
123
|
+
const isLastStation = idx === stations.length - 1;
|
|
124
|
+
const isStationPassed = isPassed(stop, trackerLayer.time, stations, idx);
|
|
125
|
+
const isNotStation = isNotStop(stop);
|
|
126
|
+
return (
|
|
127
|
+
<div
|
|
128
|
+
// Train line can go in circle so begin and end have the same id,
|
|
129
|
+
// using the time in the key should fix the issue.
|
|
130
|
+
key={(stationId || stationName) + arrivalTime + departureTime}
|
|
131
|
+
role="button"
|
|
132
|
+
className={[
|
|
133
|
+
'rt-route-station',
|
|
134
|
+
isStationPassed ? ' rt-passed' : '',
|
|
135
|
+
isNotStation ? ' rt-no-stop' : '',
|
|
136
|
+
].join('')}
|
|
137
|
+
onClick={(e) => {
|
|
138
|
+
return onStationClick(stop, e);
|
|
139
|
+
}}
|
|
140
|
+
tabIndex={0}
|
|
141
|
+
onKeyPress={(e) => {
|
|
142
|
+
return e.which === 13 && onStationClick(stop, e);
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
<div className="rt-route-delay">
|
|
146
|
+
{typeof arrivalDelay === 'undefined' || isFirstStation || cancelled ? (
|
|
147
|
+
''
|
|
148
|
+
) : (
|
|
149
|
+
<span
|
|
150
|
+
className={`rt-route-delay-arrival${` ${getDelayColor(
|
|
151
|
+
arrivalDelay,
|
|
152
|
+
)}`}`}
|
|
153
|
+
>
|
|
154
|
+
{`+${getDelayString(arrivalDelay)}`}
|
|
155
|
+
</span>
|
|
156
|
+
)}
|
|
157
|
+
{typeof departureDelay === 'undefined' || isLastStation || cancelled ? (
|
|
158
|
+
''
|
|
159
|
+
) : (
|
|
160
|
+
<span
|
|
161
|
+
className={`rt-route-delay-departure${` ${getDelayColor(
|
|
162
|
+
departureDelay,
|
|
163
|
+
)}`}`}
|
|
164
|
+
>
|
|
165
|
+
{`+${getDelayString(departureDelay)}`}
|
|
166
|
+
</span>
|
|
167
|
+
)}
|
|
168
|
+
</div>
|
|
169
|
+
<div className="rt-route-times">
|
|
170
|
+
<span
|
|
171
|
+
className={`rt-route-time-arrival ${
|
|
172
|
+
cancelled ? 'rt-route-cancelled' : ''
|
|
173
|
+
}`}
|
|
174
|
+
>
|
|
175
|
+
{getHoursAndMinutes(aimedArrivalTime)}
|
|
176
|
+
</span>
|
|
177
|
+
<span
|
|
178
|
+
className={`rt-route-time-departure ${
|
|
179
|
+
cancelled ? 'rt-route-cancelled' : ''
|
|
180
|
+
}`}
|
|
181
|
+
>
|
|
182
|
+
{getHoursAndMinutes(aimedDepartureTime)}
|
|
183
|
+
</span>
|
|
184
|
+
</div>
|
|
185
|
+
{renderStationImg(stations, idx, isStationPassed, isNotStation)}
|
|
186
|
+
<div className={cancelled ? 'rt-route-cancelled' : ''}>{stationName}</div>
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const renderRouteIdentifier = ({ routeIdentifier, longName }) => {
|
|
192
|
+
if (routeIdentifier) {
|
|
193
|
+
// first part of the id, without leading zeros.
|
|
194
|
+
const id = parseInt(routeIdentifier.split('.')[0], 10);
|
|
195
|
+
if (!longName.includes(id)) {
|
|
196
|
+
return ` (${id})`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const defaultRenderHeader = ({ lineInfos, renderHeaderButtons }) => {
|
|
203
|
+
const {
|
|
204
|
+
type,
|
|
205
|
+
vehicleType,
|
|
206
|
+
shortName,
|
|
207
|
+
longName,
|
|
208
|
+
stroke,
|
|
209
|
+
destination,
|
|
210
|
+
routeIdentifier,
|
|
211
|
+
text_color: textColor,
|
|
212
|
+
} = lineInfos;
|
|
213
|
+
return (
|
|
214
|
+
<div className="rt-route-header">
|
|
215
|
+
<span
|
|
216
|
+
className="rt-route-icon"
|
|
217
|
+
style={{
|
|
218
|
+
/* stylelint-disable-next-line value-keyword-case */
|
|
219
|
+
backgroundColor: stroke || getBgColor(type || vehicleType),
|
|
220
|
+
color: textColor || 'black',
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
{shortName}
|
|
224
|
+
</span>
|
|
225
|
+
<div className="rt-route-title">
|
|
226
|
+
<span className="rt-route-name">{destination}</span>
|
|
227
|
+
<span>
|
|
228
|
+
{longName}
|
|
229
|
+
{renderRouteIdentifier(lineInfos)}
|
|
230
|
+
</span>
|
|
231
|
+
</div>
|
|
232
|
+
<div className="rt-route-buttons">
|
|
233
|
+
{renderHeaderButtons(routeIdentifier)}
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const defaultRenderFooter = (props) => {
|
|
240
|
+
const { lineInfos, renderCopyright } = props;
|
|
241
|
+
if (!lineInfos.operator && !lineInfos.publisher) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
return <div className="rt-route-footer">{renderCopyright({ ...props })}</div>;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const defaultRenderLink = (text, url) => {
|
|
248
|
+
return (
|
|
249
|
+
<div className="rt-route-copyright-link">
|
|
250
|
+
{url ? (
|
|
251
|
+
<a href={url} target="_blank" rel="noreferrer">
|
|
252
|
+
{text}
|
|
253
|
+
</a>
|
|
254
|
+
) : (
|
|
255
|
+
<>{text}</>
|
|
256
|
+
)}
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const defaultRenderCopyright = ({ lineInfos }) => {
|
|
262
|
+
return (
|
|
263
|
+
<span className="rt-route-copyright">
|
|
264
|
+
{lineInfos.operator &&
|
|
265
|
+
defaultRenderLink(lineInfos.operator, lineInfos.operatorUrl)}
|
|
266
|
+
{lineInfos.operator && lineInfos.publisher && <span> - </span>}
|
|
267
|
+
{lineInfos.publisher &&
|
|
268
|
+
defaultRenderLink(lineInfos.publisher, lineInfos.publisherUrl)}
|
|
269
|
+
{lineInfos.license && <span> (</span>}
|
|
270
|
+
{lineInfos.license &&
|
|
271
|
+
defaultRenderLink(lineInfos.license, lineInfos.licenseUrl)}
|
|
272
|
+
{lineInfos.license && ')'}
|
|
273
|
+
</span>
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const propTypes = {
|
|
278
|
+
/**
|
|
279
|
+
* CSS class of the route schedule wrapper.
|
|
280
|
+
*/
|
|
281
|
+
className: PropTypes.string,
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Trajectory stations informations.
|
|
285
|
+
*/
|
|
286
|
+
lineInfos: ReactTransitPropTypes.lineInfos,
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Trackerlayer.
|
|
290
|
+
*/
|
|
291
|
+
trackerLayer: PropTypes.instanceOf(TrackerLayer).isRequired,
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Render Header of the route scheduler.
|
|
295
|
+
*/
|
|
296
|
+
renderHeader: PropTypes.func,
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Render Footer of the route scheduler.
|
|
300
|
+
*/
|
|
301
|
+
renderFooter: PropTypes.func,
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Render Copyright of the route scheduler.
|
|
305
|
+
*/
|
|
306
|
+
renderCopyright: PropTypes.func,
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Render the status of the station image.
|
|
310
|
+
*/
|
|
311
|
+
renderStationImg: PropTypes.func,
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Render a station.
|
|
315
|
+
*/
|
|
316
|
+
renderStation: PropTypes.func,
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Function triggered on station's click event.
|
|
320
|
+
*/
|
|
321
|
+
onStationClick: PropTypes.func,
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Function to render header buttons.
|
|
325
|
+
*/
|
|
326
|
+
renderHeaderButtons: PropTypes.func,
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const defaultProps = {
|
|
330
|
+
className: 'rt-route-schedule',
|
|
331
|
+
lineInfos: null,
|
|
332
|
+
renderHeader: defaultRenderHeader,
|
|
333
|
+
renderStation: defaultRenderStation,
|
|
334
|
+
renderStationImg: defaultRenderStationImg,
|
|
335
|
+
renderCopyright: defaultRenderCopyright,
|
|
336
|
+
renderFooter: defaultRenderFooter,
|
|
337
|
+
renderHeaderButtons: () => {
|
|
338
|
+
return null;
|
|
339
|
+
},
|
|
340
|
+
onStationClick: () => {},
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* RouteSchedule displays information, stops and punctuality about the clicked route.
|
|
345
|
+
*/
|
|
346
|
+
function RouteSchedule(props) {
|
|
347
|
+
const { lineInfos, className, renderStation, renderHeader, renderFooter } =
|
|
348
|
+
props;
|
|
349
|
+
|
|
350
|
+
if (!lineInfos) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return (
|
|
355
|
+
<div className={className}>
|
|
356
|
+
{renderHeader({ ...props })}
|
|
357
|
+
<div className="rt-route-body">
|
|
358
|
+
{lineInfos.stations.map((stop, idx) => {
|
|
359
|
+
return renderStation({ ...props, stop, idx });
|
|
360
|
+
})}
|
|
361
|
+
</div>
|
|
362
|
+
{renderFooter({ ...props })}
|
|
363
|
+
</div>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
RouteSchedule.propTypes = propTypes;
|
|
368
|
+
RouteSchedule.defaultProps = defaultProps;
|
|
369
|
+
|
|
370
|
+
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
|
+
});
|