mobility-toolbox-js 2.0.0-beta.8 → 2.0.1-beta.13
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/api/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/{src/api/tralis → api}/TralisAPIUtils.js +2 -32
- package/api/index.js +3 -0
- package/{index.html → api/typedefs.js} +0 -0
- package/common/Tracker.js +93 -0
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{src/api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +81 -0
- package/{src/common → common}/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +213 -0
- package/{src/common → common}/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +24 -0
- package/common/mixins/SearchMixin.js +110 -0
- package/common/mixins/TralisLayerMixin.js +479 -0
- package/common/styles/index.js +4 -0
- package/{src/common → common}/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +8 -0
- package/{src/common → common}/styles/trackerSimpleStyle.js +4 -8
- package/{src/common → common}/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +23 -0
- package/{src/doc/examples/ol-mapbox-layer.md → common/typedefs.js} +0 -0
- package/common/utils/createTrackerFilters.js +56 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/{src/common → common}/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/{src/common → common}/utils/getMapboxStyleUrl.js +3 -13
- package/{src/common → common}/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -0
- package/common/utils/removeDuplicate.js +8 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/{src/common → common}/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +20 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/index.js +8 -0
- package/mapbox/controls/CopyrightControl.js +29 -0
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -0
- package/mapbox/layers/Layer.js +57 -0
- package/mapbox/layers/Layer.test.js +182 -0
- package/mapbox/layers/TralisLayer.js +182 -0
- package/{src/mapbox → mapbox}/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/{src/mapbox → mapbox}/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +42 -0
- package/ol/controls/CopyrightControl.test.js +165 -0
- package/ol/controls/RoutingControl.js +387 -0
- package/ol/controls/RoutingControl.test.js +151 -0
- package/ol/controls/StopFinderControl.js +10 -0
- package/ol/controls/StopFinderControl.test.js +48 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -0
- package/ol/layers/Layer.js +88 -0
- package/ol/layers/Layer.test.js +174 -0
- package/ol/layers/MapboxLayer.js +203 -0
- package/{src/ol → ol}/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +187 -0
- package/{src/ol → ol}/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +139 -0
- package/ol/layers/RoutingLayer.js +61 -0
- package/{src/ol → ol}/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +185 -0
- package/ol/layers/TralisLayer.test.js +79 -0
- package/ol/layers/VectorLayer.js +22 -0
- package/{src/ol → ol}/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +38 -0
- package/ol/layers/WMSLayer.test.js +76 -0
- package/ol/layers/index.js +8 -0
- package/{src/ol → ol}/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +43 -0
- package/ol/styles/index.js +2 -0
- package/package.json +34 -74
- package/.babelrc +0 -6
- package/.esdoc.json +0 -17
- package/.eslintignore +0 -1
- package/.github/workflows/conventional-pr-title.yml +0 -21
- package/.github/workflows/cypress.yml +0 -29
- package/.github/workflows/nodejs.yml +0 -28
- package/.husky/commit-msg +0 -4
- package/.husky/post-checkout +0 -4
- package/.husky/post-merge +0 -4
- package/.husky/post-rebase +0 -4
- package/.husky/pre-commit +0 -4
- package/.neutrinorc.js +0 -176
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -10
- package/LICENSE +0 -21
- package/__mocks__/mapbox-gl.js +0 -81
- package/__mocks__/maplibre-gl.js +0 -81
- package/commitlint.config.js +0 -1
- package/cypress/fixtures/example.json +0 -5
- package/cypress/integration/examples/api.spec.js +0 -7
- package/cypress/integration/examples/examples.spec.js +0 -7
- package/cypress/integration/examples/navigation.spec.js +0 -29
- package/cypress/plugins/index.js +0 -21
- package/cypress/support/commands.js +0 -25
- package/cypress/support/index.js +0 -20
- package/cypress.json +0 -4
- package/data/fetchRoute.json +0 -292
- package/data/fetchTrajectories.json +0 -18
- package/data/fetchTrajectoryById.json +0 -3
- package/data/fetchTrajectoryStations.json +0 -18
- package/data/stopsSearch.json +0 -15
- package/documentation.yml +0 -4
- package/esdoc/README.md +0 -27
- package/esdoc/plugins/MyPlugin.js +0 -69
- package/esdoc/plugins/dynamic-property-plugin/Plugin.js +0 -50
- package/esdoc/plugins/externals-plugin/Plugin.js +0 -45
- package/esdoc/plugins/externals-plugin/externals.js +0 -96
- package/global-setup.js +0 -3
- package/indexweb.html +0 -49
- package/jest.config.js +0 -5
- package/pull_request_template.md +0 -17
- package/renovate.json +0 -4
- package/scripts/read-pkg-json.js +0 -22
- package/src/api/index.js +0 -3
- package/src/api/routing/RoutingAPI.js +0 -44
- package/src/api/routing/RoutingAPI.test.js +0 -41
- package/src/api/stops/StopsAPI.js +0 -41
- package/src/api/stops/StopsAPI.test.js +0 -34
- package/src/api/tralis/TralisAPI.js +0 -731
- package/src/api/tralis/TralisAPI.test.js +0 -75
- package/src/api/tralis/WebSocketConnector.js +0 -338
- package/src/api/tralis/typedefs.js +0 -81
- package/src/assets/Lato-Black.ttf +0 -0
- package/src/assets/Lato-BlackItalic.ttf +0 -0
- package/src/assets/Lato-Bold.ttf +0 -0
- package/src/assets/Lato-BoldItalic.ttf +0 -0
- package/src/assets/Lato-Italic.ttf +0 -0
- package/src/assets/Lato-Light.ttf +0 -0
- package/src/assets/Lato-LightItalic.ttf +0 -0
- package/src/assets/Lato-Regular.ttf +0 -0
- package/src/assets/Lato-Thin.ttf +0 -0
- package/src/assets/Lato-ThinItalic.ttf +0 -0
- package/src/assets/OFL.txt +0 -93
- package/src/common/Tracker.js +0 -197
- package/src/common/api/api.js +0 -64
- package/src/common/api/api.test.js +0 -68
- package/src/common/controls/Control.js +0 -146
- package/src/common/index.js +0 -5
- package/src/common/layers/Layer.js +0 -404
- package/src/common/mixins/CopyrightMixin.js +0 -48
- package/src/common/mixins/SearchMixin.js +0 -176
- package/src/common/mixins/TralisLayerMixin.js +0 -930
- package/src/common/styles/index.js +0 -4
- package/src/common/styles/trackerDelayStyle.js +0 -17
- package/src/common/trackerConfig.test.js +0 -25
- package/src/common/typedefs.js +0 -23
- package/src/common/utils/createTrackerFilters.js +0 -87
- package/src/common/utils/createTrackerFilters.test.js +0 -95
- package/src/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/src/common/utils/index.js +0 -5
- package/src/common/utils/removeDuplicate.js +0 -22
- package/src/common/utils/removeDuplicate.test.js +0 -22
- package/src/common/utils/timeUtils.js +0 -44
- package/src/common/utils/timeUtils.test.js +0 -16
- package/src/doc/App.js +0 -116
- package/src/doc/App.scss +0 -51
- package/src/doc/_redirects +0 -2
- package/src/doc/components/CodeSandboxButton.js +0 -103
- package/src/doc/components/Documentation.js +0 -40
- package/src/doc/components/Esdoc/Anchor.js +0 -57
- package/src/doc/components/Esdoc/ClassDoc.js +0 -272
- package/src/doc/components/Esdoc/DeprecatedHTML.js +0 -16
- package/src/doc/components/Esdoc/DetailDocs.js +0 -281
- package/src/doc/components/Esdoc/DetailHTML.js +0 -33
- package/src/doc/components/Esdoc/DirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/DocBuilderUtils.js +0 -694
- package/src/doc/components/Esdoc/DocLinkHTML.js +0 -62
- package/src/doc/components/Esdoc/DocsLinkHTML.js +0 -38
- package/src/doc/components/Esdoc/Esdoc.js +0 -63
- package/src/doc/components/Esdoc/EsdocContent.js +0 -51
- package/src/doc/components/Esdoc/EsdocNavigation.js +0 -13
- package/src/doc/components/Esdoc/EsdocSearch.js +0 -81
- package/src/doc/components/Esdoc/ExperimentalHTML.js +0 -17
- package/src/doc/components/Esdoc/ExtendsChainHTML.js +0 -32
- package/src/doc/components/Esdoc/FileDocLinkHTML.js +0 -60
- package/src/doc/components/Esdoc/IdentifiersDoc.js +0 -113
- package/src/doc/components/Esdoc/IndirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/InheritedSummaryDoc.js +0 -70
- package/src/doc/components/Esdoc/InheritedSummaryHTML.js +0 -38
- package/src/doc/components/Esdoc/MixinClassesHTML.js +0 -29
- package/src/doc/components/Esdoc/NavDoc.js +0 -112
- package/src/doc/components/Esdoc/OverrideMethod.js +0 -44
- package/src/doc/components/Esdoc/OverrideMethodDescription.js +0 -35
- package/src/doc/components/Esdoc/Properties.js +0 -89
- package/src/doc/components/Esdoc/README.md +0 -45
- package/src/doc/components/Esdoc/SignatureHTML.js +0 -123
- package/src/doc/components/Esdoc/SingleDoc.js +0 -31
- package/src/doc/components/Esdoc/SummaryDoc.js +0 -160
- package/src/doc/components/Esdoc/SummaryHTML.js +0 -96
- package/src/doc/components/Esdoc/TypeDocLinkHTML.js +0 -249
- package/src/doc/components/Esdoc/css/identifiers.css +0 -38
- package/src/doc/components/Esdoc/css/search.css +0 -76
- package/src/doc/components/Esdoc/css/style.css +0 -603
- package/src/doc/components/Esdoc/index.js +0 -7
- package/src/doc/components/Example.js +0 -153
- package/src/doc/components/Examples.js +0 -183
- package/src/doc/components/Home.js +0 -106
- package/src/doc/components/TrackerExample.js +0 -38
- package/src/doc/examples/assets/tralis-live-map/index.js +0 -11
- package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +0 -105
- package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +0 -101
- package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +0 -93
- package/src/doc/examples/assets/tralis-live-map/unknown.svg +0 -107
- package/src/doc/examples/mb-copyright.html +0 -26
- package/src/doc/examples/mb-copyright.js +0 -37
- package/src/doc/examples/mb-tracker.html +0 -1
- package/src/doc/examples/mb-tracker.js +0 -39
- package/src/doc/examples/mb-tracker.md +0 -1
- package/src/doc/examples/mb-tralis.html +0 -1
- package/src/doc/examples/mb-tralis.js +0 -34
- package/src/doc/examples/ol-copyright.html +0 -26
- package/src/doc/examples/ol-copyright.js +0 -43
- package/src/doc/examples/ol-mapbox-layer.html +0 -1
- package/src/doc/examples/ol-mapbox-layer.js +0 -28
- package/src/doc/examples/ol-mapbox-style-layer.html +0 -12
- package/src/doc/examples/ol-mapbox-style-layer.js +0 -44
- package/src/doc/examples/ol-query.html +0 -32
- package/src/doc/examples/ol-query.js +0 -83
- package/src/doc/examples/ol-routing.html +0 -26
- package/src/doc/examples/ol-routing.js +0 -59
- package/src/doc/examples/ol-routing.md +0 -1
- package/src/doc/examples/ol-stop-finder.html +0 -15
- package/src/doc/examples/ol-stop-finder.js +0 -31
- package/src/doc/examples/ol-stop-finder.md +0 -1
- package/src/doc/examples/ol-tracker.html +0 -1
- package/src/doc/examples/ol-tracker.js +0 -44
- package/src/doc/examples/ol-tracker.md +0 -1
- package/src/doc/examples/ol-tralis.html +0 -5
- package/src/doc/examples/ol-tralis.js +0 -57
- package/src/doc/examples/tralis-live-map.html +0 -1
- package/src/doc/examples/tralis-live-map.js +0 -51
- package/src/doc/examples/tralis-live-map.md +0 -3
- package/src/doc/examples.js +0 -107
- package/src/doc/img/examples/live_tracker_mb.jpg +0 -0
- package/src/doc/img/examples/live_tracker_munich.jpg +0 -0
- package/src/doc/img/examples/live_tracker_ol.jpg +0 -0
- package/src/doc/img/examples/mapbox.jpg +0 -0
- package/src/doc/img/examples/mapbox_style.jpg +0 -0
- package/src/doc/img/examples/ol-copyright.png +0 -0
- package/src/doc/img/examples/query_objects.jpg +0 -0
- package/src/doc/img/examples/routing.jpg +0 -0
- package/src/doc/img/examples/simple_map.jpg +0 -0
- package/src/doc/img/examples/stops.jpg +0 -0
- package/src/doc/img/favico.ico +0 -0
- package/src/doc/index.js +0 -21
- package/src/iife.js +0 -7
- package/src/index.js +0 -10
- package/src/mapbox/controls/CopyrightControl.js +0 -58
- package/src/mapbox/controls/index.js +0 -2
- package/src/mapbox/index.js +0 -4
- package/src/mapbox/layers/Layer.js +0 -118
- package/src/mapbox/layers/Layer.test.js +0 -202
- package/src/mapbox/layers/TralisLayer.js +0 -329
- package/src/mapbox/layers/index.js +0 -2
- package/src/ol/README.md +0 -0
- package/src/ol/controls/CopyrightControl.js +0 -80
- package/src/ol/controls/CopyrightControl.test.js +0 -211
- package/src/ol/controls/RoutingControl.js +0 -752
- package/src/ol/controls/RoutingControl.test.js +0 -216
- package/src/ol/controls/StopFinderControl.js +0 -38
- package/src/ol/controls/StopFinderControl.test.js +0 -59
- package/src/ol/controls/index.js +0 -3
- package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/src/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/src/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/src/ol/index.js +0 -5
- package/src/ol/layers/Layer.js +0 -193
- package/src/ol/layers/Layer.test.js +0 -197
- package/src/ol/layers/MapboxLayer.js +0 -378
- package/src/ol/layers/MapboxStyleLayer.js +0 -417
- package/src/ol/layers/MaplibreLayer.js +0 -280
- package/src/ol/layers/RoutingLayer.js +0 -91
- package/src/ol/layers/TralisLayer.js +0 -359
- package/src/ol/layers/TralisLayer.test.js +0 -97
- package/src/ol/layers/VectorLayer.js +0 -43
- package/src/ol/layers/WMSLayer.js +0 -80
- package/src/ol/layers/WMSLayer.test.js +0 -84
- package/src/ol/layers/index.js +0 -8
- package/src/ol/styles/fullTrajectoryStyle.js +0 -51
- package/src/ol/styles/index.js +0 -2
- package/src/setupTests.js +0 -15
- package/webpack.config.js +0 -6
|
@@ -4,50 +4,37 @@ import {
|
|
|
4
4
|
getDelayColor,
|
|
5
5
|
getDelayText,
|
|
6
6
|
getTextColor,
|
|
7
|
-
getTextSize
|
|
8
|
-
} from
|
|
9
|
-
|
|
7
|
+
getTextSize
|
|
8
|
+
} from "../trackerConfig";
|
|
10
9
|
const createCanvas = (width, height) => {
|
|
11
|
-
const canvas = document.createElement(
|
|
10
|
+
const canvas = document.createElement("canvas");
|
|
12
11
|
canvas.width = width;
|
|
13
12
|
canvas.height = height;
|
|
14
13
|
return canvas;
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
// Draw circle delay background
|
|
18
15
|
const cacheDelayBg = {};
|
|
19
16
|
export const getDelayBgCanvas = (origin, radius, color) => {
|
|
20
17
|
const key = `${origin}, ${radius}, ${color}`;
|
|
21
18
|
if (!cacheDelayBg[key]) {
|
|
22
19
|
const canvas = createCanvas(origin * 2, origin * 2);
|
|
23
|
-
const ctx = canvas.getContext(
|
|
20
|
+
const ctx = canvas.getContext("2d");
|
|
24
21
|
ctx.beginPath();
|
|
25
22
|
ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
|
|
26
23
|
ctx.fillStyle = color;
|
|
27
|
-
ctx.filter =
|
|
24
|
+
ctx.filter = "blur(1px)";
|
|
28
25
|
ctx.fill();
|
|
29
26
|
cacheDelayBg[key] = canvas;
|
|
30
27
|
}
|
|
31
28
|
return cacheDelayBg[key];
|
|
32
29
|
};
|
|
33
|
-
|
|
34
|
-
// Draw delay text
|
|
35
30
|
const cacheDelayText = {};
|
|
36
|
-
export const getDelayTextCanvas = (
|
|
37
|
-
width,
|
|
38
|
-
text,
|
|
39
|
-
fontSize,
|
|
40
|
-
font,
|
|
41
|
-
delayColor,
|
|
42
|
-
delayOutlineColor,
|
|
43
|
-
pixelRatio,
|
|
44
|
-
) => {
|
|
31
|
+
export const getDelayTextCanvas = (width, text, fontSize, font, delayColor, delayOutlineColor, pixelRatio) => {
|
|
45
32
|
const key = `${width}, ${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
|
|
46
33
|
if (!cacheDelayText[key]) {
|
|
47
34
|
const canvas = createCanvas(width, fontSize + 8 * pixelRatio);
|
|
48
|
-
const ctx = canvas.getContext(
|
|
49
|
-
ctx.textAlign =
|
|
50
|
-
ctx.textBaseline =
|
|
35
|
+
const ctx = canvas.getContext("2d");
|
|
36
|
+
ctx.textAlign = "left";
|
|
37
|
+
ctx.textBaseline = "middle";
|
|
51
38
|
ctx.font = font;
|
|
52
39
|
ctx.fillStyle = delayColor;
|
|
53
40
|
ctx.strokeStyle = delayOutlineColor;
|
|
@@ -59,94 +46,56 @@ export const getDelayTextCanvas = (
|
|
|
59
46
|
}
|
|
60
47
|
return cacheDelayText[key];
|
|
61
48
|
};
|
|
62
|
-
|
|
63
|
-
// Draw colored circle with black border
|
|
64
49
|
const cacheCircle = {};
|
|
65
|
-
export const getCircleCanvas = (
|
|
66
|
-
origin,
|
|
67
|
-
radius,
|
|
68
|
-
color,
|
|
69
|
-
hasStroke,
|
|
70
|
-
hasDash,
|
|
71
|
-
pixelRatio,
|
|
72
|
-
) => {
|
|
50
|
+
export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixelRatio) => {
|
|
73
51
|
const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
|
|
74
52
|
if (!cacheCircle[key]) {
|
|
75
53
|
const canvas = createCanvas(origin * 2, origin * 2);
|
|
76
|
-
const ctx = canvas.getContext(
|
|
54
|
+
const ctx = canvas.getContext("2d");
|
|
77
55
|
ctx.fillStyle = color;
|
|
78
|
-
|
|
79
56
|
if (hasStroke) {
|
|
80
57
|
ctx.lineWidth = 1 * pixelRatio;
|
|
81
|
-
ctx.strokeStyle =
|
|
58
|
+
ctx.strokeStyle = "#000000";
|
|
82
59
|
}
|
|
83
|
-
|
|
84
60
|
ctx.beginPath();
|
|
85
61
|
ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
|
|
86
62
|
ctx.fill();
|
|
87
|
-
|
|
88
63
|
if (hasDash) {
|
|
89
64
|
ctx.setLineDash([5, 3]);
|
|
90
65
|
}
|
|
91
|
-
|
|
92
66
|
if (hasStroke) {
|
|
93
67
|
ctx.stroke();
|
|
94
68
|
}
|
|
95
|
-
|
|
96
69
|
cacheCircle[key] = canvas;
|
|
97
70
|
}
|
|
98
71
|
return cacheCircle[key];
|
|
99
72
|
};
|
|
100
|
-
|
|
101
|
-
// Draw text in the circle
|
|
102
73
|
const cacheText = {};
|
|
103
|
-
export const getTextCanvas = (
|
|
104
|
-
text,
|
|
105
|
-
origin,
|
|
106
|
-
textSize,
|
|
107
|
-
fillColor,
|
|
108
|
-
strokeColor,
|
|
109
|
-
hasStroke,
|
|
110
|
-
pixelRatio,
|
|
111
|
-
) => {
|
|
74
|
+
export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) => {
|
|
112
75
|
const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
|
|
113
76
|
if (!cacheText[key]) {
|
|
114
77
|
const canvas = createCanvas(origin * 2, origin * 2);
|
|
115
|
-
const ctx = canvas.getContext(
|
|
116
|
-
|
|
117
|
-
// Draw a stroke to the text only if a provider provides realtime but we don't use it.
|
|
78
|
+
const ctx = canvas.getContext("2d");
|
|
118
79
|
if (hasStroke) {
|
|
119
80
|
ctx.save();
|
|
120
|
-
ctx.textBaseline =
|
|
121
|
-
ctx.textAlign =
|
|
81
|
+
ctx.textBaseline = "middle";
|
|
82
|
+
ctx.textAlign = "center";
|
|
122
83
|
ctx.font = `bold ${textSize + 2}px Arial`;
|
|
123
84
|
ctx.strokeStyle = strokeColor;
|
|
124
85
|
ctx.strokeText(text, origin, origin);
|
|
125
86
|
ctx.restore();
|
|
126
87
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
ctx.textBaseline = 'middle';
|
|
130
|
-
ctx.textAlign = 'center';
|
|
88
|
+
ctx.textBaseline = "middle";
|
|
89
|
+
ctx.textAlign = "center";
|
|
131
90
|
ctx.fillStyle = fillColor;
|
|
132
91
|
ctx.font = `bold ${textSize}px Arial`;
|
|
133
92
|
ctx.strokeStyle = strokeColor;
|
|
134
93
|
ctx.strokeText(text, origin, origin);
|
|
135
94
|
ctx.fillText(text, origin, origin);
|
|
136
|
-
|
|
137
95
|
cacheText[key] = canvas;
|
|
138
96
|
}
|
|
139
97
|
return cacheText[key];
|
|
140
98
|
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* A tracker style that take in account the delay.
|
|
144
|
-
*
|
|
145
|
-
* @param {*} trajectory The trajectory to render.
|
|
146
|
-
* @param {*} viewState The view state of the map.
|
|
147
|
-
* @param {*} options Some options to change the rendering
|
|
148
|
-
* @return a canvas
|
|
149
|
-
*/
|
|
150
99
|
const styleCache = {};
|
|
151
100
|
const style = (trajectory, viewState, options) => {
|
|
152
101
|
const {
|
|
@@ -154,9 +103,8 @@ const style = (trajectory, viewState, options) => {
|
|
|
154
103
|
selectedVehicleId,
|
|
155
104
|
useDelayStyle,
|
|
156
105
|
delayOutlineColor,
|
|
157
|
-
delayDisplay
|
|
106
|
+
delayDisplay
|
|
158
107
|
} = options;
|
|
159
|
-
|
|
160
108
|
const { zoom, pixelRatio } = viewState;
|
|
161
109
|
let { type, cancelled } = trajectory.properties;
|
|
162
110
|
const {
|
|
@@ -164,170 +112,86 @@ const style = (trajectory, viewState, options) => {
|
|
|
164
112
|
line,
|
|
165
113
|
delay,
|
|
166
114
|
state,
|
|
167
|
-
operator_provides_realtime_journey: operatorProvidesRealtime
|
|
115
|
+
operator_provides_realtime_journey: operatorProvidesRealtime
|
|
168
116
|
} = trajectory.properties;
|
|
169
117
|
let { name, text_color: textColor, color } = line || {};
|
|
170
|
-
|
|
171
|
-
// In the future, the cancelled property will be removed we still managed it
|
|
172
|
-
// until the backend change is on prod.
|
|
173
|
-
cancelled = cancelled === true || state === 'JOURNEY_CANCELLED';
|
|
174
|
-
|
|
118
|
+
cancelled = cancelled === true || state === "JOURNEY_CANCELLED";
|
|
175
119
|
if (!type) {
|
|
176
|
-
type =
|
|
120
|
+
type = "Rail";
|
|
177
121
|
}
|
|
178
|
-
|
|
179
122
|
if (!name) {
|
|
180
|
-
name =
|
|
123
|
+
name = "I";
|
|
181
124
|
}
|
|
182
|
-
|
|
183
125
|
if (!textColor) {
|
|
184
|
-
textColor =
|
|
126
|
+
textColor = "#000000";
|
|
185
127
|
}
|
|
186
|
-
|
|
187
|
-
if (color && color[0] !== '#') {
|
|
128
|
+
if (color && color[0] !== "#") {
|
|
188
129
|
color = `#${color}`;
|
|
189
130
|
}
|
|
190
|
-
|
|
191
|
-
if (textColor[0] !== '#') {
|
|
131
|
+
if (textColor[0] !== "#") {
|
|
192
132
|
textColor = `#${textColor}`;
|
|
193
133
|
}
|
|
194
|
-
|
|
195
134
|
const z = Math.min(Math.floor(zoom || 1), 16);
|
|
196
135
|
const hover = hoverVehicleId && hoverVehicleId === id;
|
|
197
136
|
const selected = selectedVehicleId && selectedVehicleId === id;
|
|
198
|
-
|
|
199
|
-
// Calcul the radius of the circle
|
|
200
137
|
let radius = getRadius(type, z) * pixelRatio;
|
|
201
138
|
const isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
|
|
202
139
|
if (hover || selected) {
|
|
203
|
-
radius = isDisplayStrokeAndDelay
|
|
204
|
-
? radius + 5 * pixelRatio
|
|
205
|
-
: 14 * pixelRatio;
|
|
140
|
+
radius = isDisplayStrokeAndDelay ? radius + 5 * pixelRatio : 14 * pixelRatio;
|
|
206
141
|
}
|
|
207
142
|
const mustDrawText = radius > 10 * pixelRatio;
|
|
208
|
-
|
|
209
|
-
// Optimize the cache key, very important in high zoom level
|
|
210
143
|
let key = `${radius}${type}${color}${hover}${selected}${cancelled}${delay}`;
|
|
211
|
-
|
|
212
144
|
if (useDelayStyle) {
|
|
213
145
|
key += `${operatorProvidesRealtime}`;
|
|
214
146
|
}
|
|
215
|
-
|
|
216
147
|
if (mustDrawText) {
|
|
217
148
|
key += `${name}${textColor}`;
|
|
218
149
|
}
|
|
219
|
-
|
|
220
150
|
if (!styleCache[key]) {
|
|
221
151
|
if (radius === 0) {
|
|
222
152
|
styleCache[key] = null;
|
|
223
153
|
return null;
|
|
224
154
|
}
|
|
225
|
-
|
|
226
155
|
const margin = 1 * pixelRatio;
|
|
227
156
|
const radiusDelay = radius + 2;
|
|
228
157
|
const markerSize = radius * 2;
|
|
229
|
-
const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio;
|
|
158
|
+
const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio;
|
|
230
159
|
const origin = size / 2;
|
|
231
|
-
|
|
232
|
-
// Create the canvas
|
|
233
160
|
const canvas = createCanvas(size, size);
|
|
234
|
-
const ctx = canvas.getContext(
|
|
235
|
-
|
|
161
|
+
const ctx = canvas.getContext("2d");
|
|
236
162
|
if (isDisplayStrokeAndDelay && delay !== null) {
|
|
237
|
-
|
|
238
|
-
const delayBg = getDelayBgCanvas(
|
|
239
|
-
origin,
|
|
240
|
-
radiusDelay,
|
|
241
|
-
getDelayColor(delay, cancelled),
|
|
242
|
-
);
|
|
163
|
+
const delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor(delay, cancelled));
|
|
243
164
|
ctx.drawImage(delayBg, 0, 0);
|
|
244
165
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
isDisplayStrokeAndDelay &&
|
|
249
|
-
(hover || delay >= delayDisplay || cancelled)
|
|
250
|
-
) {
|
|
251
|
-
// Draw delay text
|
|
252
|
-
const fontSize =
|
|
253
|
-
Math.max(
|
|
254
|
-
cancelled ? 19 : 14,
|
|
255
|
-
Math.min(cancelled ? 19 : 17, radius * 1.2),
|
|
256
|
-
) * pixelRatio;
|
|
166
|
+
if (isDisplayStrokeAndDelay && (hover || delay >= delayDisplay || cancelled)) {
|
|
167
|
+
const fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
|
|
257
168
|
const text = getDelayText(delay, cancelled);
|
|
258
|
-
|
|
259
169
|
if (text) {
|
|
260
170
|
const textWidth = text.length * fontSize;
|
|
261
|
-
const delayText = getDelayTextCanvas(
|
|
262
|
-
|
|
263
|
-
text,
|
|
264
|
-
fontSize,
|
|
265
|
-
`bold ${fontSize}px arial, sans-serif`,
|
|
266
|
-
getDelayColor(delay, cancelled, true),
|
|
267
|
-
delayOutlineColor,
|
|
268
|
-
pixelRatio,
|
|
269
|
-
);
|
|
270
|
-
ctx.drawImage(
|
|
271
|
-
delayText,
|
|
272
|
-
origin + radiusDelay + margin,
|
|
273
|
-
origin - fontSize,
|
|
274
|
-
);
|
|
171
|
+
const delayText = getDelayTextCanvas(textWidth, text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
|
|
172
|
+
ctx.drawImage(delayText, origin + radiusDelay + margin, origin - fontSize);
|
|
275
173
|
}
|
|
276
174
|
}
|
|
277
|
-
|
|
278
|
-
// Draw colored circle with black border
|
|
279
175
|
let circleFillColor;
|
|
280
176
|
if (useDelayStyle) {
|
|
281
177
|
circleFillColor = getDelayColor(delay, cancelled);
|
|
282
178
|
} else {
|
|
283
179
|
circleFillColor = color || getBgColor(type);
|
|
284
180
|
}
|
|
285
|
-
|
|
286
181
|
const hasStroke = isDisplayStrokeAndDelay || hover || selected;
|
|
287
|
-
|
|
288
|
-
const hasDash
|
|
289
|
-
isDisplayStrokeAndDelay &&
|
|
290
|
-
useDelayStyle &&
|
|
291
|
-
delay === null &&
|
|
292
|
-
operatorProvidesRealtime === 'yes';
|
|
293
|
-
|
|
294
|
-
const circle = getCircleCanvas(
|
|
295
|
-
origin,
|
|
296
|
-
radius,
|
|
297
|
-
circleFillColor,
|
|
298
|
-
hasStroke,
|
|
299
|
-
hasDash,
|
|
300
|
-
pixelRatio,
|
|
301
|
-
);
|
|
302
|
-
|
|
182
|
+
const hasDash = isDisplayStrokeAndDelay && useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
|
|
183
|
+
const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
|
|
303
184
|
ctx.drawImage(circle, 0, 0);
|
|
304
|
-
|
|
305
|
-
// Draw text in the circle
|
|
306
185
|
if (mustDrawText) {
|
|
307
186
|
const fontSize = Math.max(radius, 10);
|
|
308
187
|
const textSize = getTextSize(ctx, markerSize, name, fontSize);
|
|
309
|
-
const textColor2 = !useDelayStyle
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const hasStroke2 =
|
|
313
|
-
useDelayStyle && delay === null && operatorProvidesRealtime === 'yes';
|
|
314
|
-
|
|
315
|
-
const text = getTextCanvas(
|
|
316
|
-
name,
|
|
317
|
-
origin,
|
|
318
|
-
textSize,
|
|
319
|
-
textColor2,
|
|
320
|
-
circleFillColor,
|
|
321
|
-
hasStroke2,
|
|
322
|
-
pixelRatio,
|
|
323
|
-
);
|
|
324
|
-
|
|
188
|
+
const textColor2 = !useDelayStyle ? textColor || getTextColor(type) : "#000000";
|
|
189
|
+
const hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
|
|
190
|
+
const text = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
|
|
325
191
|
ctx.drawImage(text, 0, 0);
|
|
326
192
|
}
|
|
327
|
-
|
|
328
193
|
styleCache[key] = canvas;
|
|
329
194
|
}
|
|
330
|
-
|
|
331
195
|
return styleCache[key];
|
|
332
196
|
};
|
|
333
197
|
export default style;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A very simple tracker style.
|
|
3
|
-
* Display blue point for each train.
|
|
4
|
-
*/
|
|
5
1
|
let canvas;
|
|
6
2
|
const style = () => {
|
|
7
3
|
if (!canvas) {
|
|
8
|
-
document.createElement(
|
|
4
|
+
document.createElement("canvas");
|
|
9
5
|
canvas.width = 15;
|
|
10
6
|
canvas.height = 15;
|
|
11
|
-
const ctx = canvas.getContext(
|
|
7
|
+
const ctx = canvas.getContext("2d");
|
|
12
8
|
ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
|
|
13
|
-
ctx.fillStyle =
|
|
9
|
+
ctx.fillStyle = "#8ED6FF";
|
|
14
10
|
ctx.fill();
|
|
15
11
|
ctx.lineWidth = 3;
|
|
16
|
-
ctx.strokeStyle =
|
|
12
|
+
ctx.strokeStyle = "black";
|
|
17
13
|
ctx.stroke();
|
|
18
14
|
ctx.lineWidth = 3;
|
|
19
15
|
}
|
|
@@ -8,16 +8,8 @@ const trackerRadiusMapping = {
|
|
|
8
8
|
6: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
9
9
|
7: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
10
10
|
8: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
11
|
-
9: [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15]
|
|
11
|
+
9: [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15]
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Trajserv value: 'Tram', 'Subway / Metro / S-Bahn', 'Train', 'Bus', 'Ferry', 'Cable Car', 'Gondola', 'Funicular', 'Long distance bus', 'Rail',
|
|
16
|
-
* New endpoint use Rail instead of Train.
|
|
17
|
-
* New tracker values: null, "tram", "subway", "rail", "bus", "ferry", "cablecar", "gondola", "funicular", "coach".
|
|
18
|
-
*
|
|
19
|
-
* @ignore
|
|
20
|
-
*/
|
|
21
13
|
export const types = [
|
|
22
14
|
/^Tram/i,
|
|
23
15
|
/^Subway( \/ Metro \/ S-Bahn)?/i,
|
|
@@ -28,62 +20,61 @@ export const types = [
|
|
|
28
20
|
/^Gondola/i,
|
|
29
21
|
/^Funicular/i,
|
|
30
22
|
/^(Long distance bus|coach)/i,
|
|
31
|
-
/^Rail/i
|
|
23
|
+
/^Rail/i
|
|
32
24
|
];
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @ignore
|
|
36
|
-
*/
|
|
37
25
|
export const bgColors = [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
"#ffb400",
|
|
27
|
+
"#ff5400",
|
|
28
|
+
"#ff8080",
|
|
29
|
+
"#ea0000",
|
|
30
|
+
"#3000ff",
|
|
31
|
+
"#ffb400",
|
|
32
|
+
"#41a27b",
|
|
33
|
+
"#00d237",
|
|
34
|
+
"#b5b5b5",
|
|
35
|
+
"#ff8080"
|
|
48
36
|
];
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @ignore
|
|
52
|
-
*/
|
|
53
37
|
export const textColors = [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
38
|
+
"#000000",
|
|
39
|
+
"#ffffff",
|
|
40
|
+
"#000000",
|
|
41
|
+
"#ffffff",
|
|
42
|
+
"#ffffff",
|
|
43
|
+
"#000000",
|
|
44
|
+
"#ffffff",
|
|
45
|
+
"#000000",
|
|
46
|
+
"#000000",
|
|
47
|
+
"#000000"
|
|
64
48
|
];
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @ignore
|
|
68
|
-
*/
|
|
69
49
|
export const timeSteps = [
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
1e5,
|
|
51
|
+
5e4,
|
|
52
|
+
4e4,
|
|
53
|
+
3e4,
|
|
54
|
+
2e4,
|
|
55
|
+
15e3,
|
|
56
|
+
1e4,
|
|
57
|
+
5e3,
|
|
58
|
+
2e3,
|
|
59
|
+
1e3,
|
|
60
|
+
400,
|
|
61
|
+
300,
|
|
62
|
+
250,
|
|
63
|
+
180,
|
|
64
|
+
90,
|
|
65
|
+
60,
|
|
66
|
+
50,
|
|
67
|
+
50,
|
|
68
|
+
50,
|
|
69
|
+
50,
|
|
70
|
+
50
|
|
72
71
|
];
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @ignore
|
|
76
|
-
*/
|
|
77
72
|
export const getTypeIndex = (type) => {
|
|
78
|
-
if (typeof type ===
|
|
73
|
+
if (typeof type === "string") {
|
|
79
74
|
return types.findIndex((t) => t.test(type));
|
|
80
75
|
}
|
|
81
76
|
return type;
|
|
82
77
|
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @ignore
|
|
86
|
-
*/
|
|
87
78
|
export const getRadius = (type, zoom) => {
|
|
88
79
|
try {
|
|
89
80
|
const typeIdx = getTypeIndex(type || 0);
|
|
@@ -92,10 +83,6 @@ export const getRadius = (type, zoom) => {
|
|
|
92
83
|
return 1;
|
|
93
84
|
}
|
|
94
85
|
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @ignore
|
|
98
|
-
*/
|
|
99
86
|
export const getBgColor = (type = 0) => {
|
|
100
87
|
try {
|
|
101
88
|
const typeIdx = getTypeIndex(type);
|
|
@@ -104,10 +91,6 @@ export const getBgColor = (type = 0) => {
|
|
|
104
91
|
return 1;
|
|
105
92
|
}
|
|
106
93
|
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @ignore
|
|
110
|
-
*/
|
|
111
94
|
export const getTextColor = (type = 0) => {
|
|
112
95
|
try {
|
|
113
96
|
const typeIdx = getTypeIndex(type);
|
|
@@ -116,19 +99,12 @@ export const getTextColor = (type = 0) => {
|
|
|
116
99
|
return 1;
|
|
117
100
|
}
|
|
118
101
|
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @ignore
|
|
122
|
-
*/
|
|
123
102
|
export const getTextSize = (ctx, markerSize, text, fontSize) => {
|
|
124
103
|
ctx.font = `bold ${fontSize}px Arial`;
|
|
125
104
|
let newText = ctx.measureText(text);
|
|
126
|
-
|
|
127
105
|
const maxiter = 25;
|
|
128
106
|
let i = 0;
|
|
129
|
-
|
|
130
107
|
while (newText.width > markerSize - 6 && i < maxiter) {
|
|
131
|
-
// eslint-disable-next-line no-param-reassign
|
|
132
108
|
fontSize -= 0.5;
|
|
133
109
|
ctx.font = `bold ${fontSize}px arial, sans-serif`;
|
|
134
110
|
newText = ctx.measureText(text);
|
|
@@ -136,55 +112,41 @@ export const getTextSize = (ctx, markerSize, text, fontSize) => {
|
|
|
136
112
|
}
|
|
137
113
|
return fontSize;
|
|
138
114
|
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @ignore
|
|
142
|
-
* @param {number} delayInMs Delay in milliseconds.
|
|
143
|
-
* @param {boolean} cancelled true if the journey is cancelled.
|
|
144
|
-
* @param {boolean} isDelayText true if the color is used for delay text of the symbol.
|
|
145
|
-
*/
|
|
146
115
|
export const getDelayColor = (delayInMs, cancelled, isDelayText) => {
|
|
147
116
|
if (cancelled) {
|
|
148
|
-
return isDelayText ?
|
|
117
|
+
return isDelayText ? "#ff0000" : "#a0a0a0";
|
|
149
118
|
}
|
|
150
|
-
if (delayInMs >=
|
|
151
|
-
return
|
|
119
|
+
if (delayInMs >= 36e5) {
|
|
120
|
+
return "#ed004c";
|
|
152
121
|
}
|
|
153
|
-
if (delayInMs >=
|
|
154
|
-
return
|
|
122
|
+
if (delayInMs >= 5e5) {
|
|
123
|
+
return "#e80000";
|
|
155
124
|
}
|
|
156
|
-
if (delayInMs >=
|
|
157
|
-
return
|
|
125
|
+
if (delayInMs >= 3e5) {
|
|
126
|
+
return "#ff4a00";
|
|
158
127
|
}
|
|
159
|
-
if (delayInMs >=
|
|
160
|
-
return
|
|
128
|
+
if (delayInMs >= 18e4) {
|
|
129
|
+
return "#f7bf00";
|
|
161
130
|
}
|
|
162
131
|
if (delayInMs === null) {
|
|
163
|
-
return
|
|
132
|
+
return "#a0a0a0";
|
|
164
133
|
}
|
|
165
|
-
return
|
|
134
|
+
return "#00a00c";
|
|
166
135
|
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @ignore
|
|
170
|
-
*/
|
|
171
136
|
export const getDelayText = (delayInMs, cancelled) => {
|
|
172
137
|
if (cancelled) {
|
|
173
|
-
return String.fromCodePoint(
|
|
138
|
+
return String.fromCodePoint(215);
|
|
174
139
|
}
|
|
175
|
-
if (delayInMs >
|
|
176
|
-
const rounded = Math.round(delayInMs /
|
|
140
|
+
if (delayInMs > 36e5) {
|
|
141
|
+
const rounded = Math.round(delayInMs / 36e5);
|
|
177
142
|
return `+${rounded}h`;
|
|
178
143
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const rounded = Math.round(delayInMs / 60000);
|
|
144
|
+
if (delayInMs > 59e3) {
|
|
145
|
+
const rounded = Math.round(delayInMs / 6e4);
|
|
182
146
|
return `+${rounded}m`;
|
|
183
147
|
}
|
|
184
|
-
|
|
185
148
|
if (delayInMs > 0) {
|
|
186
149
|
return `+${delayInMs}s`;
|
|
187
150
|
}
|
|
188
|
-
|
|
189
|
-
return '';
|
|
151
|
+
return "";
|
|
190
152
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getTypeIndex } from "./trackerConfig";
|
|
2
|
+
describe("trackerConfig", () => {
|
|
3
|
+
describe("#getTypeIndex()", () => {
|
|
4
|
+
test("retrurn the type is it's not a string", () => {
|
|
5
|
+
const obj = { foo: "foo" };
|
|
6
|
+
expect(getTypeIndex(obj)).toBe(obj);
|
|
7
|
+
expect(getTypeIndex(0)).toBe(0);
|
|
8
|
+
expect(getTypeIndex(null)).toBe(null);
|
|
9
|
+
expect(getTypeIndex(void 0)).toBe(void 0);
|
|
10
|
+
});
|
|
11
|
+
test("find good index for new tracker values", () => {
|
|
12
|
+
expect(getTypeIndex("tram")).toBe(0);
|
|
13
|
+
expect(getTypeIndex("subway")).toBe(1);
|
|
14
|
+
expect(getTypeIndex("bus")).toBe(3);
|
|
15
|
+
expect(getTypeIndex("ferry")).toBe(4);
|
|
16
|
+
expect(getTypeIndex("cablecar")).toBe(5);
|
|
17
|
+
expect(getTypeIndex("gondola")).toBe(6);
|
|
18
|
+
expect(getTypeIndex("funicular")).toBe(7);
|
|
19
|
+
expect(getTypeIndex("coach")).toBe(8);
|
|
20
|
+
expect(getTypeIndex("rail")).toBe(9);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
File without changes
|