# GTFS-to-Chart GTFS-to-Chart Generate interactive stringline charts from GTFS Schedule data. Stations run across the horizontal axis, spaced by distance. Each line follows a vehicle through the service day; its slope shows speed and vertical segments show dwell time. Hover over a stop to see trip and time details. SFMTA 14R stringline chart ## Installation Requires Node.js 24.22.3 or later. ```sh npm install -g gtfs-to-chart ``` For use in an application: ```sh npm install gtfs-to-chart ``` ## Quick start Save this as `config.json`, replacing the feed path with a local GTFS ZIP or directory: ```json { "database": { "path": "./gtfs.sqlite" }, "sources": [{ "schedule": { "path": "./gtfs.zip" } }], "charts": { "serviceDate": 20261110 }, "output": { "directory": "./charts" } } ``` ```sh gtfs-to-chart generate --config config.json gtfs-to-chart serve --output ./charts ``` Open `http://127.0.0.1:3000`. You can also open `charts/index.html` directly or upload the output directory to a static host. Charts load D3 and Bootstrap from a CDN, so viewing requires internet access. To regenerate from the existing database: ```sh gtfs-to-chart generate --config config.json --skip-import --overwrite ``` ## Configuration Use the same `database`, `sources`, `extensions`, `realtime`, and `reporting` groups as a node-GTFS v5 instance. Chart generation imports Schedule data; it does not refresh Realtime feeds. See the [node-GTFS configuration reference](https://github.com/BlinkTagInc/node-gtfs/blob/main/docs/configuration.md) for feed download, CSV parsing, validation, and database options. `extensions` accepts an explicit array, as on `new Gtfs()`. A source can use `schedule.path` or `schedule.url`. Configure request headers as `schedule.requestHeaders`. For multiple feeds, give each source a unique `sourceId`; a single source defaults to `default`. ```json { "database": { "path": "./gtfs.sqlite" }, "sources": [ { "sourceId": "caltrain", "schedule": { "url": "https://data.trilliumtransit.com/gtfs/caltrain-ca-us/caltrain-ca-us.zip" } } ], "charts": { "serviceDate": 20261110, "timepointsOnly": true }, "output": { "directory": "./charts", "overwrite": false, "pretty": false }, "reporting": { "level": "info" } } ``` | Option | Default | Description | | -------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------ | | `charts.serviceDate` | Today's local date | Valid `YYYYMMDD` integer. Calendar exceptions are respected. | | `charts.routeIds` | All routes | Array of route IDs to generate in each source. Unknown IDs are errors. | | `charts.timepointsOnly` | `true` | Exclude stops explicitly marked `timepoint=0`. Stops without both arrival and departure times are always excluded. | | `output.directory` | `./charts` | Directory containing the source indexes, route pages, and shared assets. | | `output.overwrite` | `false` | Replace output previously generated by v3, after generation succeeds. The whole output directory is replaced. | | `output.templateDirectory` | Built-in templates | Custom Pug template directory. | | `output.pretty` | `false` | Indent generated HTML. | | `reporting.level` | `info` | `silent`, `error`, `warn`, or `info`. Library calls are silent unless given a reporter. | Paths are relative to the current working directory, including when `--config` points elsewhere. Use a persistent database for `--skip-import`; `:memory:` works when importing and generating in one call. Existing v4 databases must be reimported into a fresh v5 database. Output directories and filenames use IDs with stable hash suffixes to avoid collisions. Follow the generated index links instead of constructing filenames from route names. Routes without service on the selected date are skipped. Other generation errors fail the operation and preserve previous output. ### Custom templates Copy `templates/` from the package and set `output.templateDirectory` to your copy. Entry templates are `chart-page.pug` and `overview-page.pug`. Chart templates receive `route`, `chartData`, `serializedData`, `serviceDate`, `assetPath`, `title`, and `version`; overview templates receive `agency`, `routes`, `assetPath`, `title`, and `version`. Use `serializedData` when embedding chart data in a script element: it escapes HTML-sensitive characters. ## JavaScript API ```js import { generateCharts, createConsoleReporter } from 'gtfs-to-chart'; const result = await generateCharts({ database: { path: './gtfs.sqlite' }, sources: [{ schedule: { path: './gtfs.zip' } }], charts: { serviceDate: 20261110 }, output: { directory: './charts' }, reporting: { reporter: createConsoleReporter() }, }); console.log(result.directory); console.log(result.sources); // sourceId, directory, charts, skippedRouteIds ``` `generateCharts(config, { import: false })` reuses an existing database. The returned result includes `success: true`, `directory`, `sources`, and `durationMs`. Failures reject. Database connections owned by the operation are closed on success and failure; borrowed connections follow node-GTFS ownership rules. TypeScript declarations are included. `reporting.reporter` receives node-GTFS structured events, including chart-generation status events. The CLI sends diagnostics to stderr and exits with status 1 on failure. ## CLI `generate` is the default command. Run `gtfs-to-chart --help` for all options. | Flag | Purpose | | ----------------- | --------------------------------------------------- | | `--config`, `-c` | JSON file; defaults to `config.json` | | `--service-date` | Override `charts.serviceDate` | | `--output` | Override output directory | | `--overwrite` | Replace previously generated output | | `--skip-import` | Reuse the configured database | | `--quiet`, `-q` | Suppress informational output | | `--port` | Preview server port; defaults to 3000; `serve` only | | `--help`, `-h` | Show help | | `--version`, `-v` | Show version | `serve` previews existing output on localhost and accepts `--output`, `--port`, and `--quiet`. It does not import or generate data. ## Migrating from v2 This is a breaking release; legacy options and flags are rejected. | v2 | v3 | | ----------------------------- | ----------------------------------------------------------- | | Default `gtfsToChart` export | Named `generateCharts` export | | `agencies` | `sources` | | `agencies[].path` / `.url` | `sources[].schedule.path` / `.url` | | `sqlitePath` | `database.path` | | `chartDate` string | `charts.serviceDate` integer | | `showOnlyTimepoint` | `charts.timepointsOnly` (now implemented) | | `beautify` | `output.pretty` | | `templatePath` | `output.templateDirectory` | | `skipImport` config | Second API argument `{ import: false }`, or `--skip-import` | | `verbose` / `logFunction` | `reporting.level` / `reporting.reporter` | | `--configPath` | `--config` | | `npm start` live database app | `gtfs-to-chart serve` static preview | | `views/chart/*_page.pug` | `templates/*-page.pug` | | Automatic overwrite | Explicit `output.overwrite` / `--overwrite` | Move other feed import settings into the corresponding v5 `schedule` groups. Existing custom templates must use the new template variables. Generate into a new directory for the first v3 run; v3 will not overwrite an unmarked v2 output directory. ## Chart limitations Charts work best for routes with consistent stop patterns. The longest timed trip in each direction defines that direction's station axis. Trips containing stops outside that pattern are omitted with a note on the chart. Circular routes, repeated stops, and significantly different return paths may not render meaningfully. Distances use `shape_dist_traveled` when complete and nondecreasing, otherwise straight-line distances between stop coordinates. Opposite directions are scaled to the same total distance. Times beyond midnight retain their service-day hours, and frequency-based service is expanded at the stated headway; non-exact frequencies are labeled as representative departures. ## Credits and contributing Based on [Mike Bostock's Marey's Trains](https://observablehq.com/@mbostock/mareys-trains), inspired by E.J. Marey's graphical schedules. Licensed under [MIT](LICENSE.txt). See [CONTRIBUTING.md](CONTRIBUTING.md) for development and release checks. Issues and pull requests are welcome.