Skip to content

Commit

Permalink
Merge branch 'feature/docs' of https://github.com/openplannerteam/pla…
Browse files Browse the repository at this point in the history
…nner.js into feature/docs
  • Loading branch information
SimonVanneste committed Feb 12, 2019
2 parents ea38b08 + 53e78cd commit 9e73698
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 170 deletions.
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Planner.js: A JS library for route planning

🛸 [![Build Status](https://travis-ci.org/openplannerteam/planner.js.svg?branch=dev)](https://travis-ci.org/openplannerteam/planner.js) 🚴‍♂️ [![MIT License](https://img.shields.io/github/license/openplannerteam/planner.js.svg?maxAge=2592000)](https://github.com/openplannerteam/planner.js/blob/master/LICENSE) 🚉
🛸 [![Build Status](https://travis-ci.org/openplannerteam/planner.js.svg?branch=dev)](https://travis-ci.org/openplannerteam/planner.js) 🚴 [![MIT License](https://img.shields.io/github/license/openplannerteam/planner.js.svg?maxAge=2592000)](https://github.com/openplannerteam/planner.js/blob/master/LICENSE) 🚉 [![npm version](https://badge.fury.io/js/plannerjs.svg)](https://badge.fury.io/js/plannerjs) 🚀

Current status: _to be launched in February_ 🚀

For now: clone the repository, run `npm install` and `npm build`. Afterwards you can use it as follows:
```
$ npm install plannerjs
```

Include it in the browser:
```html
Expand All @@ -13,21 +13,35 @@ Include it in the browser:

Include it in your JavaScript project:
```javascript
// Not yet published on NPM...
const Planner = require('plannerjs').default;

// or

import Planner from 'plannerjs';
```

Use it in both environments:
```javascript
const planner = new Planner();

planner.query({
publicTransportOnly: true,
from: "http://irail.be/stations/NMBS/008812005", // Brussels North
to: "http://irail.be/stations/NMBS/008892007", // Ghent-Sint-Pieters
minimumDepartureTime: new Date(),
maximumWalkingDistance: 200, // 200 meters
maximumTransferDuration: 30 * 60 * 1000, // 30 minutes
minimumWalkingSpeed: 3 // 3 km/h
minimumDepartureTime: new Date("Mon Feb 11 2019 16:00:00"),
maximumArrivalTime: new Date("Mon Feb 11 2019 19:00:00"),
publicTransportOnly: true,

walkingSpeed: 3, // KmH
minimumWalkingSpeed: 3, // KmH

maximumWalkingDistance: 200, // meters

minimumTransferDuration: Planner.Units.fromMinutes(1),
maximumTransferDuration: Planner.Units.fromMinutes(30),

maximumTravelDuration: Planner.Units.fromHours(1.5),

maximumTransfers: 4,
})
.take(3)
.on('data', (path) => {
Expand All @@ -37,7 +51,7 @@ planner.query({
console.log('No more paths!')
})
.on('error', (error) => {
console.log(error);
console.error(error);
});
```

Expand All @@ -50,3 +64,4 @@ For further instructions, follow the documentation at https://openplannerteam.gi
* Building the docs with typedoc: `npm run doc`
* Testing with jest: `npm test`
* Build a new browser version with `npm run browser`
* Bundle the latest planner for the docs example `npm run doc-bundle`
6 changes: 5 additions & 1 deletion docs/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ body {
position: absolute;
top: 10px;
left: 54px;
max-width: calc(100% - 225px);
z-index: 500;
}

.prefetch-view {
width: 0px;
height: 6px;
margin-bottom: 3px;
border-radius: 30px;
Expand All @@ -117,5 +119,7 @@ body {
}

#prefetch-bar {
height: 18px;
height: 17px;
max-width: 100%;
overflow: hidden;
}
278 changes: 133 additions & 145 deletions docs/index.html

Large diffs are not rendered by default.

29 changes: 24 additions & 5 deletions docs/js/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const resetButton = document.querySelector("#reset");
const results = document.querySelector("#results");
const prefetchWrapper = document.querySelector("#prefetch");
const prefetchBar = document.querySelector("#prefetch-bar");
let prefetchBarWidth = 0;

let lines = [];
let polyLines = [];
Expand Down Expand Up @@ -64,7 +65,7 @@ const removePrefetchView = () => {
}
};

resetButton.onclick = e => {
resetButton.onclick = (e) => {
removeLines();
removeResultObjects();
query = [];
Expand Down Expand Up @@ -118,7 +119,7 @@ planner
minimumDepartureTime,
maximumArrivalTime,
maximumArrivalTime - minimumDepartureTime,
maximumTravelDuration,
maximumTravelDuration
);

removeLines();
Expand Down Expand Up @@ -181,8 +182,15 @@ planner
} else {
const width = getPrefetchViewWidth(firstPrefetch, departureTime);

prefetchBarWidth = width + 10;

const prefetch = document.getElementById("prefetch");
prefetch.style.width = `${prefetchBarWidth}px`;

prefetchBar.style.width = `${width}px`;
prefetchBar.setAttribute("data-last", departureTime.toLocaleTimeString());

drawPrefetchViews();
}
})
.on("connection-iterator-view", (lowerBound, upperBound, completed) => {
Expand All @@ -197,7 +205,7 @@ planner
const prefetchView = document.createElement("div");
prefetchView.className = "prefetch-view";
prefetchView.style.marginLeft = `${offset}px`;
prefetchView.style.width = `${width}px`;
prefetchView.style.width = `${width * 100 / prefetchBarWidth}%`;
prefetchView.style.backgroundColor = "red";

prefetchWrapper.appendChild(prefetchView);
Expand All @@ -208,17 +216,28 @@ planner
.find((view) => view.lowerBound === lowerBound && view.upperBound === upperBound);

if (!elem) {
console.warn("Wut");
return;
}

drawPrefetchViews();

elem.style.backgroundColor = "limegreen";
}
})
.on("warning", (warning) => {
console.warn(warning);
});

function drawPrefetchViews() {
for (const prefetchView of prefetchViews) {
const viewWidth = getPrefetchViewWidth(prefetchView.lowerBound, prefetchView.upperBound);
const offset = getPrefetchViewWidth(firstPrefetch, prefetchView.lowerBound);

prefetchView.elem.style.width = `${viewWidth * 100 / prefetchBarWidth}%`;
prefetchView.elem.style.marginLeft = `${offset}px`;
}
}

function onMapClick(e) {
selectRoute(e);
}
Expand Down Expand Up @@ -449,7 +468,7 @@ function runQuery(query) {
to: query[1],
minimumDepartureTime: new Date(),
maximumWalkingDistance,
maximumTransferDuration: 30 * 60 * 1000, // 30 minutes
maximumTransferDuration: Planner.Units.fromMinutes(30), // 30 minutes
minimumWalkingSpeed: 3
})
.take(amount)
Expand Down
6 changes: 3 additions & 3 deletions src/Defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Units from "./util/Units";
export default class Defaults {
public static readonly defaultMinimumWalkingSpeed = 3;
public static readonly defaultMaximumWalkingSpeed = 6;
public static readonly defaultWalkingDuration = Units.fromSeconds(10 * 60);
public static readonly defaultMinimumTransferDuration = Units.fromSeconds(60);
public static readonly defaultMaximumTransferDuration = Units.fromHours(.4);
public static readonly defaultWalkingDuration = Units.fromMinutes(10);
public static readonly defaultMinimumTransferDuration = Units.fromMinutes(1);
public static readonly defaultMaximumTransferDuration = Units.fromMinutes(25);
public static readonly defaultMaximumTransfers = 4;
}
3 changes: 3 additions & 0 deletions src/Planner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import IQuery from "./interfaces/IQuery";
import defaultContainer from "./inversify.config";
import IQueryRunner from "./query-runner/IQueryRunner";
import TYPES from "./types";
import Units from "./util/Units";

/**
* Allows to ask route planning queries. Emits events defined in [[EventType]]
*/
// @ts-ignore
export default class Planner implements EventEmitter {
public static Units = Units;

private context: Context;
private queryRunner: IQueryRunner;

Expand Down
2 changes: 1 addition & 1 deletion src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default async (logResults) => {
from: "Ingelmunster", // Ingelmunster
to: "http://irail.be/stations/NMBS/008892007", // Ghent-Sint-Pieters
minimumDepartureTime: new Date(),
maximumTransferDuration: Units.fromHours(0.5),
maximumTransferDuration: Units.fromMinutes(30),
})
.take(amount)
.on("error", (error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/fetcher/connections/prefetch/ConnectionsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import IExpandingForwardView from "./IExpandingForwardView";
*/
export default class ConnectionsStore {

private static REPORTING_THRESHOLD = Units.fromHours(.1);
private static REPORTING_THRESHOLD = Units.fromMinutes(6);

private readonly context: Context;
private readonly store: IConnection[];
Expand Down
2 changes: 1 addition & 1 deletion src/planner/stops/ReachableStopsFinderBirdsEye.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test("[ReachableStopsFinderBirdsEye] reachable stops", async () => {
const reachableStops = await reachableStopsFinder.findReachableStops(
sourceStop,
ReachableStopsFinderMode.Source,
Units.fromHours(0.25),
Units.fromMinutes(15),
4,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("[QueryRunnerExponential]", () => {
from: "http://irail.be/stations/NMBS/008896925", // Ingelmunster
to: "http://irail.be/stations/NMBS/008892007", // Ghent-Sint-Pieters
minimumDepartureTime: new Date(),
maximumTransferDuration: Units.fromHours(.5),
maximumTransferDuration: Units.fromHours(30),
};

const createEarliestArrivalQueryRunner = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("[QueryRunnerExponential]", () => {
from: "http://irail.be/stations/NMBS/008896925", // Ingelmunster
to: "http://irail.be/stations/NMBS/008892007", // Ghent-Sint-Pieters
minimumDepartureTime: new Date(),
maximumTransferDuration: Units.fromHours(.5),
maximumTransferDuration: Units.fromMinutes(30),
};

const createExponentialQueryRunner = () => {
Expand Down
4 changes: 4 additions & 0 deletions src/util/Units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class Units {
return hours * 3600000;
}

public static fromMinutes(minutes: number): DurationMs {
return minutes * 60000;
}

public static fromSeconds(seconds: number): DurationMs {
return seconds * 1000;
}
Expand Down

0 comments on commit 9e73698

Please sign in to comment.