Examples

Timeline Navigation

Fit content, pan to a date, or change zoom with the timeline's viewport APIs.

Choose the API that matches the navigation task

fitDateRange() fitArticleRange() fitArticles() setStartDate() setCentreDate() setZoom() canonical date/time strings onComplete

Fit methods pan and zoom until the requested content fits. Date methods pan without changing zoom. setZoom() changes scale around the viewport center by default; lower values show a closer view and higher values show a wider view.

The status reports completion from onComplete after the final viewport draw. Disable animation to try the same asynchronous callback for immediate requests; another navigation or gesture cancels pending completion. See completion rules.

Need to limit how far users can navigate? See the Date Bounds example.

Try a navigation task

// Run these navigation examples separately.
// A new request cancels any pending completion callback.
const fitOptions = {
  padding: { left: 70, right: 70 },
  animation: { active: true, duration: 350, easing: "swing" },
  onComplete: () => console.log("Final viewport drawn")
};

timeline.fitDateRange(
  { year: 1957, month: 1, day: 1 },
  { year: 1969, month: 12, day: 31 },
  fitOptions
);

const apollo = timeline.getArticleById("navigation-apollo");
timeline.fitArticleRange(apollo, fitOptions);

timeline.fitArticles(fitOptions);