Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <script src="https://planner.js.org/js/planner-latest.js"></script>
  </head>
  <body>
    <div id="results">
      <div id='calculating'>Calculating results...</div>
    </div>
  </body>
</html>
              
            
!

CSS

              
                #results {
  display: flex;
  flex-direction: column;

  font-family: sans-serif;
}

.path {
  display: flex;
  flex-direction: column;
  margin: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.2);
  flex-wrap: wrap;
}

.step {
  display: flex;
  flex-direction: row;
  margin: 10px;
}

.travelMode {
  width: 45px;
  background-size: 20px 20px;
  background-repeat: no-repeat;
}

.details {
  
}

.travelMode.walking {
  background-image: url(data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0idHJ1ZSIgZGF0YS1wcmVmaXg9ImZhcyIgZGF0YS1pY29uPSJ3YWxraW5nIiBjbGFzcz0ic3ZnLWlubGluZS0tZmEgZmEtd2Fsa2luZyBmYS13LTEwIiByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDMyMCA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iI+PC9wYXRoPjwvc3ZnPg==);
}

.travelMode.train {
  background-image: url(data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0idHJ1ZSIgZGF0YS1wcmVmaXg9ImZhcyIgZGF0YS1pY29uPSJ0cmFpbiIgY2xhc3M9InN2Zy1pbmxpbmUtLWZhIGZhLXRyYWluIGZhLXctMTQiIHJvbGU9ImltZyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgNDQ4IDUxMiI+PHBhdGggZmlsbD0iY3VycmVudENvbG9yIiBkPSJNNDQ4IDk2djI1NmMwIDUxLjgxNS02MS42MjQgOTYtMTMwLjAyMiA5Nmw2Mi45OCA0OS43MjFDMzg2LjkwNSA1MDIuNDE3IDM4My41NjIgNTEyIDM3NiA1MTJINzJjLTcuNTc4IDAtMTAuODkyLTkuNTk0LTQuOTU3LTE0LjI3OUwxMzAuMDIyIDQ0OEM2MS44MiA0NDggMCA0MDMuOTU0IDAgMzUyVjk2QzAgNDIuOTgxIDY0IDAgMTI4IDBoMTkyYzY1IDAgMTI4IDQyLjk4MSAxMjggOTZ6bS00OCAxMzZWMTIwYzAtMTMuMjU1LTEwLjc0NS0yNC0yNC0yNEg3MmMtMTMuMjU1IDAtMjQgMTAuNzQ1LTI0IDI0djExMmMwIDEzLjI1NSAxMC43NDUgMjQgMjQgMjRoMzA0YzEzLjI1NSAwIDI0LTEwLjc0NSAyNC0yNHptLTE3NiA2NGMtMzAuOTI4IDAtNTYgMjUuMDcyLTU2IDU2czI1LjA3MiA1NiA1NiA1NiA1Ni0yNS4wNzIgNTYtNTYtMjUuMDcyLTU2LTU2LTU2eiI+PC9wYXRoPjwvc3ZnPg==)
}

.duration {
  margin-bottom: 5px;
  margin-top: 5px;
}

.enterConnectionId, .exitConnectionId {
  opacity: 0.5;
}
              
            
!

JS

              
                const results = document.getElementById("results");
const planner = new PlannerJS.FlexibleTransitPlanner();

async function run() {
  planner.addConnectionSource("https://graph.irail.be/sncb/connections");
  planner.addStopSource("https://irail.be/stations/NMBS");

  const paths = [];
  let departureTime = new Date();
  // Iterate on the planner while increasing the departure time based on each found path. Stop when 3 paths have been found
  while(paths.length < 5) {
    try {
      const path = await executePlanner(planner, departureTime);
      paths.push(path);
      await render(path);
      // Set next departure time to be 1 min after the latest found path
      departureTime = new Date(path.legs[0].steps[0].startTime.getTime() + (60 * 1000));
    } catch(err) {
      console.error(err);
    }
  }  
}

function executePlanner(planner, departureTime) {
  return new Promise((resolve, reject) => {
    planner.query({
      publicTransportOnly: true,
      from: {
        id: 'http://irail.be/stations/NMBS/008833001',
      },
      to: {
        id: 'http://irail.be/stations/NMBS/008892007',
      },
      minimumDepartureTime: departureTime,
      maximumTransferDuration: PlannerJS.Units.fromMinutes(30), // 30 minutes
      minimumWalkingSpeed: 3
      }).on("error", (error) => {
        reject(error);
      }).on("data", async path => {
        resolve(path);
      })
  });
}

async function render(path) {
  const calculating = document.getElementById("calculating");
  calculating && calculating.remove();

  const completePath = await planner.completePath(path);

  const pathElement = document.createElement("div");
  pathElement.className = "path";

  path.legs.forEach((leg) => {
    const step = leg.steps[0];
    const stepElement = document.createElement("div");
    stepElement.className = "step";

    const travelMode = document.createElement("div");
    if(leg.travelMode === 'profile') leg.travelMode = 'walking';
    travelMode.className = "travelMode " + leg.travelMode;
    stepElement.appendChild(travelMode);

    const details = document.createElement("div");
    details.className = "details";
    stepElement.appendChild(details);

    const startLocation = document.createElement("div");
    startLocation.className = "startLocation";
    startLocation.innerHTML = "Start location: " + step.startLocation.name;
    details.appendChild(startLocation);

    if (step.startTime) {
      const startTime = document.createElement("div");
      startTime.className = "startTime";
      startTime.innerHTML = step.startTime;
      details.appendChild(startTime);
    }

    if (step.enterConnectionId) {
      const enterConnectionId = document.createElement("div");
      enterConnectionId.className = "enterConnectionId";
      enterConnectionId.innerHTML = "Enter connection: " + step.enterConnectionId;
      details.appendChild(enterConnectionId);
    }

    if (step.duration) {
      const duration = document.createElement("div");
      duration.className = "duration";
      duration.innerHTML = "Duration: average " + Number(step.duration.average / (60 * 1000)).toFixed(1) + " min";
      details.appendChild(duration);
    }

    let stopLocationName = step.stopLocation.name || "Open Summer of Code 2019 - BOSA";
    const stopLocation = document.createElement("div");
    stopLocation.className = "stopLocation";
    stopLocation.innerHTML = "Stop location: " + stopLocationName;
    details.appendChild(stopLocation);

    if (step.stopTime) {
      const stopTime = document.createElement("div");
      stopTime.className = "stopTime";
      stopTime.innerHTML = step.stopTime;
      details.appendChild(stopTime);
    }

    if (step.exitConnectionId) {
      const exitConnectionId = document.createElement("div");
      exitConnectionId.className = "exitConnectionId";
      exitConnectionId.innerHTML = "Exit connection: " + step.exitConnectionId;
      details.appendChild(exitConnectionId);
    }

    pathElement.appendChild(stepElement);

  });

  results.appendChild(pathElement);
}

run();
              
            
!
999px

Console