How lewis500/bus works
Purpose and entry points
This is a browser-based CoffeeScript simulation/visualization of bus movement and bus bunching (“bottleneck sim”). The HTML entry point is index.html; application bootstrap is app/app.coffee; the primary controller is app/mainCtrl.coffee. A prebuilt browser bundle exists at dist/bundle.js.
Application composition
The app is organized as an Angular-style component/directive system:
• Root/main presentation component: app/components/main/mainDer.coffee
• Map and vehicle visualization components: app/components/map/mapDer.coffee, app/components/map/busDer.coffee
• Shared behavioral bindings and interaction directives: app/directives/behavior.coffee, app/directives/shifter.coffee, app/directives/slider.coffee
Components own rendered regions; directives encapsulate reusable SVG/DOM behavior and controls.
Simulation domain model
The core simulation entities are:
• Buses: app/models/bus.coffee
• Bus stops: app/models/bus_stop.coffee
• Passengers/demand: app/models/pax.coffee
These models define the domain boundary between simulation state and visualization. Bus movement, stop interactions, and passenger accumulation/boarding behavior are expected to be represented through these entities rather than directly in rendering code.
Data, settings, and control flow
Runtime state and simulation inputs are centralized behind services:
• app/services/data.coffee
• app/services/settings.coffee
mainCtrl.coffee coordinates the application, consuming settings/data and exposing state to the main component tree. The likely control path is bootstrap → controller/service initialization → model/state updates → map/main component rendering. app/helpers.coffee provides shared support logic across these layers.
SVG map and chart rendering boundary
The map is a dedicated visualization subsystem:
• app/components/map/mapDer.coffee
• app/components/map/busDer.coffee
• app/directives/stopDer.coffee
Bus and stop models are transformed into SVG/DOM representations here. Chart-like primitives are separated into directives:
• app/directives/dot.coffee
• app/directives/line.coffee
• app/directives/xAxis.coffee
• app/directives/yAxis.coffee
This separation allows simulation state to drive both route/map views and time-series or quantitative displays.
Interaction and parameter adjustment
User-adjustable simulation behavior is handled through reusable directives:
• app/directives/slider.coffee
• app/directives/shifter.coffee
• app/directives/behavior.coffee
• app/directives/datum.coffee
These form the UI-to-settings/state boundary: controls should update service-backed configuration or selected data, while renderers consume resulting state.
Build and runtime assets
The project targets the browser, with CoffeeScript source compiled/bundled through gulpfile.js and dependencies declared in package.json. Styling is primarily LESS/CSS:
• styles/main.less
• styles/slider.css
• styles/flex.css
No backend, database, or external service integration is indicated by the repository tree. Font assets are bundled locally under styles/font/.
Main entry points: data.coffee Data service · mainCtrl.coffee Main controller · mapDer.coffee Map component · mainDer.coffee Main component
Components 19
Browser runtime
- HTML entry
index.html - Browser bundle
dist/bundle.js
Application core
- App bootstrap
app/app.coffee - Main controller · Coordinates state and exposes it to the component tree.
app/mainCtrl.coffee - Data service
app/services/data.coffee - Settings service
app/services/settings.coffee - Shared helpers
app/helpers.coffee
Simulation domain
- Bus model
app/models/bus.coffee - Bus stop model
app/models/bus_stop.coffee - Passenger model · Represents passenger accumulation and boarding demand.
app/models/pax.coffee
Visualization and controls
- Main component
app/components/main/mainDer.coffee - Map component
app/components/map/mapDer.coffee - Bus view
app/components/map/busDer.coffee - Stop directive
app/directives/stopDer.coffee - Chart directives · Dots, lines, and axes render state-driven charts.
app/directives/line.coffee - Interaction directives · Sliders, shifters, behavior, and datum bindings update configuration or selection.
app/directives/slider.coffee
Build assets
- Gulp build · Compiles and bundles CoffeeScript for the browser.
gulpfile.js - Stylesheets
styles/main.less - Package manifest
package.json
Connections 21
- HTML entry → Browser bundle: loads
- Browser bundle → App bootstrap: contains compiled app
- App bootstrap → Main controller: initializes
- Main controller → Data service: consumes
- Main controller → Settings service: consumes
- Main controller → Shared helpers: uses
- Data service → Bus model: holds simulation state
- Data service → Bus stop model: holds route stops
- Data service → Passenger model: holds demand state
- Settings service → Data service: configures simulation
- Main controller → Main component: provides state
- Main component → Map component: composes
- Map component → Bus view: renders vehicles
- Map component → Stop directive: renders stops
- Data service → Map component: drives map state
- Data service → Chart directives: drives chart data
- Main component → Interaction directives: hosts controls
- Interaction directives → Settings service: updates parameters
- Gulp build → Browser bundle: produces
- Package manifest → Gulp build: declares tooling
- Stylesheets → HTML entry: styles interface