diff --git a/.gitignore b/.gitignore index 69caa028..5d31208f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,9 @@ node_modules/* .idea/* dist -docs +bundle.js +bundle.js.map +stats.json +lib +docs/code/* +docs/js/planner* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..94fa2e2d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +language: node_js +node_js: + - "node" +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.9 +install: + - CC=gcc-4.9 CXX=g++-4.9 npm install +script: + - npm test + - npm run doc +cache: + npm: true + apt: true + directories: + - node_modules +deploy: + - provider: pages + skip-cleanup: true + github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable + keep-history: true + local-dir: docs + on: + tags: false + branch: dev + node_js: "node" diff --git a/README.md b/README.md index d37c9cbc..2a98f708 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,46 @@ -# 🛸 Planner.js +# Planner.js: A JS library for route planning -The JavaScript library for journey 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) 🚉 -CDN versions: _coming in February_ +Current status: _to be launched in February_ 🚀 -For now: clone the repository, run `npm install` and use your [typescript compiler](https://www.typescriptlang.org/) (`tsc`) to create the files. +For now: clone the repository, run `npm install` and `npm build`. Afterwards you can use it as follows: -Next, use it as follows: +Include it in the browser: +```html + +``` -_TODO_ +Include it in your JavaScript project: +```javascript +// Not yet published on NPM... +const Planner = require('plannerjs').default; +``` +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(), + maximumTransferDuration: 30 * 60 * 1000, // 30 minutes +}).then((publicTransportResult) => { + publicTransportResult.take(15).on('data', (path) => { + console.log(path); + }); +}).catch((reason) => { + console.error(reason); +}); +``` +## Documentation + +For further instructions, follow the documentation at https://openplannerteam.github.io/planner.js/ + +## Developing + + * Building the docs with typedoc: `npm run doc` + * Testing with jest: `npm test` + * Create a new browser version with `npm run browser` diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..6ee16ea2 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,5 @@ +## Documentation + +This folder is used for the documentation website at https://openplannerteam.github.io/planner.js/ + +Travis-CI will automatically add a folder code/ in here with the TypeDoc documentation extracted from the codebase. Do not change the gh-pages branch manually. Instead, change the contents of docs/ in the master branch, or change the documentation in the codebase itself to change the code documentation. \ No newline at end of file diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000..8ff8f211 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,185 @@ + +
+The ultimate JavaScript framework for journey planning
+Your next steps: + +
++ See the Pen Using the new JavaScript route + planner on CodePen. +
++ Planner.js makes heavy use of inversify, a dependency injection + framework. + This allows anyone to make a quick custom build of a route planner, with specific needs. + Configuration of what classes should be injected where, happens by inside an inversify Container. + The default Container (used by the CDN version) can be found + in inversify.config.ts +
++ For a full overview, please consult our code documentation. + The interfaces for the Planner are split in: +
++ Providers serve as data interfaces for all fetchers of the same type (registered in the inversify + Container). + When a class needs some data, it injects a Provider of the right type. + The Provider determines the right fetcher and passes any data requests through to that fetcher. +
++ Right now, there are two types of data, so there are two types of providers: + connections providers and + stops providers +
++ These are ways to fetch data from different sources. Each fetcher corresponds to one source. + We will use the Comunica framework to fetch the data as an intelligent agent. + For now, we are just using the Linked Data Fetch NPM package and manually implement the routable + tiles and Linked Connections specification. +
++ Right now, there are two types of data, so there are two types of fetchers: + connections fetchers and + stops fetchers +
+These represent the core algorithms of this library. There are + road planners and + public-transport planners. + Additionally, there are + reachable stops finders, + which are used in certain steps of public-transport planner algorithms +
+ ++ We still need to properly write this part of the documentation. + However, the code may help you out understanding how it currently works. + By default, the file inversify.config.ts is going to be used to build the Planner. + The Planner instance must be instantiated with the dependencies container. + If you bundle a different dependencies container with your Planner, + your specific Planner will be able to act differently. +
++ To allow maximum flexibility, some algorithms allow injecting multiple implementations of the same interface, + depending on the phase of the algorithm. For example: +
+container.bind<IJourneyExtractor>(TYPES.JourneyExtractor).to(JourneyExtractorDefault);
+container.bind<IRoadPlanner>(TYPES.RoadPlanner).to(RoadPlannerBirdsEye).whenTargetTagged("phase", JourneyExtractionPhase.Initial);
+container.bind<IRoadPlanner>(TYPES.RoadPlanner).to(RoadPlannerBirdsEye).whenTargetTagged("phase", JourneyExtractionPhase.Transfer);
+container.bind<IRoadPlanner>(TYPES.RoadPlanner).to(RoadPlannerBirdsEye).whenTargetTagged("phase", JourneyExtractionPhase.Final);
+ + This example is pointless right now, because only one road planner is implemented +
++ Each container should have a Catalog which holds the access URLs (and other meta data) of all data sources. + For example, a planner that should only plan NMBS routes could have this catalog: +
+const catalog = new Catalog();
+catalog.addStopsFetcher("http://irail.be/stations/NMBS/", "https://irail.be/stations/NMBS");
+catalog.addConnectionsFetcher("https://graph.irail.be/sncb/connections", TravelMode.Train);
+
+container.bind<Catalog>(TYPES.Catalog).toConstantValue(catalog);
+
+ + Providers create all the necessary fetchers based on the data sources configured in the catalog. + Factories form the glue between all these parts: they create a fetcher based on a catalog entry on + behalf of a provider. Warning: subject to change +
++ For example: +
+container.bind<IConnectionsProvider>(TYPES.ConnectionsProvider).to(ConnectionsProviderPassthrough).inSingletonScope();
+container.bind<IConnectionsFetcher>(TYPES.ConnectionsFetcher).to(ConnectionsFetcherLazy);
+container.bind<interfaces.Factory<IConnectionsFetcher>>(TYPES.ConnectionsFetcherFactory)
+ .toFactory<IConnectionsFetcher>(
+ (context: interfaces.Context) =>
+ (accessUrl: string, travelMode: TravelMode) => {
+ const fetcher = context.container.get<ConnectionsFetcherLazy>(TYPES.ConnectionsFetcher);
+
+ fetcher.setAccessUrl(accessUrl);
+ fetcher.setTravelMode(travelMode);
+
+ return fetcher;
+ },
+ );
+
+ + One could make a dependency container specifically for shared bikes and public transport. +
++ Another example would be to create a dependency container for public transport systems only. + In this case, we would change the RoadPlanner to just using RoadPlannerBirdsEye, in order to + understand where we can transfer. +
+