Search

Filtering

Interactions

Filter the timeline by various criteria on entities and events.

Filtering
View live example →

Change the filter criteria using the controls to filter items out of the timeline.

This story filters the timeline by removing items from the data and calling set().

Change the filter criteria using the controls to filter items out of the timeline.

This story filters the timeline by removing items from the state.

import { createTimeline } from "kronograph";
import data from "./data";

const timeline = createTimeline("my-timeline");

timeline.set(data);
timeline.fit();

const allCheckboxes = Array.from(document.querySelectorAll('input[type="checkbox"]'));
const checkboxesByType = allCheckboxes.reduce((result, checkbox) => {
  return {
    ...result,
    [checkbox.name]: checkbox,
  };
}, {});

function filter(items) {
  return Object.entries(items).reduce((result, [id, item]) => {
    if (checkboxesByType[item.type].checked) {
      result[id] = item;
    }
    return result;
  }, {});
}

function updateFilter() {
  const newEntities = filter(data.entities);
  const newEvents = filter(data.events);
  timeline.set({ ...data, entities: newEntities, events: newEvents });
}

allCheckboxes.forEach((checkbox) => {
  checkbox.addEventListener("change", updateFilter);
});
export default {
  entityTypes: {
    Claim: {
      order: 2,
    },
    Investigated: {
      baseType: "Claim",
      color: "#EA3C53",
      labelColor: "#fc4c63",
    },
    Accepted: {
      baseType: "Claim",
      color: "#1BBC9B",
      labelColor: "#21deb8",
    },
    Claimant: {
      color: "#b2bfd8",
      lineWidth: 10,
      order: 1,
    },
  },
  eventTypes: {
    default: {
      showArrows: true,
    },
    "Not Flagged": {
      baseType: "default",
      color: "#1BBC9B",
      lineWidth: 2,
    },
    Flagged: {
      baseType: "default",
      color: "#EA3C53",
      lineWidth: 6,
    },
  },
  entities: {
    "smith-johnathan-151": {
      label: "John Smith",
      type: "Claimant",
    },
    "west-josephine-126": {
      label: "Josephine West",
      type: "Claimant",
    },
    "roberts-nathaniel-023": {
      label: "Nathan Roberts",
      type: "Claimant",
    },
    "baxter-eleanor-004": {
      label: "Ella Baxter",
      type: "Claimant",
    },
    "Claim MF-1883": {
      type: "Accepted",
    },
    "Claim DO-1748": {
      type: "Accepted",
    },
    "Claim EF-8738": {
      type: "Accepted",
    },
    "Claim PD-9393": {
      type: "Investigated",
    },
    "Claim SL-8745": {
      type: "Investigated",
    },
    "Claim IE-9393": {
      type: "Accepted",
    },
    "Claim GZ-2012": {
      type: "Investigated",
    },
    "Claim SQ-5563": {
      type: "Accepted",
    },
    "Claim FW-1888": {
      type: "Investigated",
    },
  },
  events: {
    "claim 1": {
      entityIds: ["smith-johnathan-151", "Claim MF-1883"],
      type: "Not Flagged",
      time: new Date(2027, 3, 4),
    },
    "claim 2": {
      entityIds: ["baxter-eleanor-004", "Claim SL-8745"],
      type: "Flagged",
      time: new Date(2025, 2, 25),
    },
    "claim 3": {
      entityIds: ["west-josephine-126", "Claim DO-1748"],
      type: "Not Flagged",
      time: new Date(2028, 12, 8),
    },
    "claim 4": {
      entityIds: ["roberts-nathaniel-023", "Claim EF-8738"],
      type: "Not Flagged",
      time: new Date(2025, 6, 13),
    },
    "claim 5": {
      entityIds: ["smith-johnathan-151", "Claim PD-9393"],
      type: "Flagged",
      time: new Date(2027, 10, 16),
    },
    "claim 6": {
      entityIds: ["baxter-eleanor-004", "Claim IE-9393"],
      type: "Not Flagged",
      time: new Date(2028, 2, 25),
    },
    "claim 7": {
      entityIds: ["roberts-nathaniel-023", "Claim GZ-2012"],
      type: "Flagged",
      time: new Date(2027, 4, 11),
    },
    "claim 8": {
      entityIds: ["baxter-eleanor-004", "Claim SQ-5563"],
      type: "Not Flagged",
      time: new Date(2025, 11, 2),
    },
    "claim 9": {
      entityIds: ["west-josephine-126", "Claim FW-1888"],
      type: "Flagged",
      time: new Date(2026, 8, 5),
    },
  },
};
<!doctype html>
<html>
  <head>
    <link rel="stylesheet" href="@ci/theme/kg/css/examples.css" />
  </head>
  <body>
    <div class="story">
      <div class="story__timeline" id="my-timeline"></div>
      <div class="story__controls story__controls--row">
        <div class="stack" id="entity-selection">
          <h2 class="story__controls__heading">Filter Entities by Type</h2>
          <label
            >Claimants
            <input type="checkbox" name="Claimant" checked />
          </label>
          <label
            >Accepted Claims
            <input type="checkbox" name="Accepted" checked />
          </label>
          <label
            >Investigated Claims
            <input type="checkbox" name="Investigated" checked />
          </label>
        </div>
        <div class="stack" id="event-selection">
          <h2 class="story__controls__heading">Filter Events by Type</h2>
          <label
            >Flagged
            <input type="checkbox" name="Flagged" checked />
          </label>
          <label
            >Not Flagged
            <input type="checkbox" name="Not Flagged" checked />
          </label>
        </div>
      </div>
    </div>
    <script type="module" src="./code.js"></script>
  </body>
</html>
import React, { useState } from "react";
import { createRoot } from "react-dom/client";
import Timeline from "kronograph/react/Timeline";
import data from "./data";

function Checkbox({ title, name, checked, onChange }) {
  return (
    <label>
      {title}
      <input type="checkbox" name={name} checked={checked} onChange={onChange} />
    </label>
  );
}

export const Demo = () => {
  const [checked, setChecked] = useState({
    Claimant: true,
    Accepted: true,
    Investigated: true,
    Flagged: true,
    "Not Flagged": true,
  });

  function updateChecked(event) {
    setChecked({
      ...checked,
      [event.target.name]: event.target.checked,
    });
  }

  function filter(items) {
    return Object.entries(items).reduce((result, [id, item]) => {
      if (checked[item.type]) {
        result[id] = item;
      }
      return result;
    }, {});
  }

  return (
    <div className="story">
      <Timeline
        className="story__timeline"
        events={filter(data.events)}
        entities={filter(data.entities)}
        eventTypes={data.eventTypes}
        entityTypes={data.entityTypes}
      />
      <div className="story__controls story__controls--row">
        <div className="stack">
          <h2 className="story__controls__heading">Filter Entities by Type</h2>
          {[
            { title: "Claimants", type: "Claimant" },
            { title: "Accepted Claims", type: "Accepted" },
            { title: "Investigated Claims", type: "Investigated" },
          ].map(({ title, type }) => (
            <Checkbox
              title={title}
              name={type}
              checked={checked[type]}
              onChange={updateChecked}
              key={title}
            />
          ))}
        </div>
        <div className="stack">
          <h2 className="story__controls__heading">Filter Events by Type</h2>
          {[
            { title: "Flagged", type: "Flagged" },
            { title: "Not Flagged", type: "Not Flagged" },
          ].map(({ title, type }) => (
            <Checkbox
              title={title}
              name={type}
              checked={checked[type]}
              onChange={updateChecked}
              key={title}
            />
          ))}
        </div>
      </div>
    </div>
  );
};

const root = createRoot(document.getElementById("my-timeline"));
root.render(<Demo />);
export default {
  entityTypes: {
    Claim: {
      order: 2,
    },
    Investigated: {
      baseType: "Claim",
      color: "#EA3C53",
      labelColor: "#fc4c63",
    },
    Accepted: {
      baseType: "Claim",
      color: "#1BBC9B",
      labelColor: "#21deb8",
    },
    Claimant: {
      color: "#b2bfd8",
      lineWidth: 10,
      order: 1,
    },
  },
  eventTypes: {
    default: {
      showArrows: true,
    },
    "Not Flagged": {
      baseType: "default",
      color: "#1BBC9B",
      lineWidth: 2,
    },
    Flagged: {
      baseType: "default",
      color: "#EA3C53",
      lineWidth: 6,
    },
  },
  entities: {
    "smith-johnathan-151": {
      label: "John Smith",
      type: "Claimant",
    },
    "west-josephine-126": {
      label: "Josephine West",
      type: "Claimant",
    },
    "roberts-nathaniel-023": {
      label: "Nathan Roberts",
      type: "Claimant",
    },
    "baxter-eleanor-004": {
      label: "Ella Baxter",
      type: "Claimant",
    },
    "Claim MF-1883": {
      type: "Accepted",
    },
    "Claim DO-1748": {
      type: "Accepted",
    },
    "Claim EF-8738": {
      type: "Accepted",
    },
    "Claim PD-9393": {
      type: "Investigated",
    },
    "Claim SL-8745": {
      type: "Investigated",
    },
    "Claim IE-9393": {
      type: "Accepted",
    },
    "Claim GZ-2012": {
      type: "Investigated",
    },
    "Claim SQ-5563": {
      type: "Accepted",
    },
    "Claim FW-1888": {
      type: "Investigated",
    },
  },
  events: {
    "claim 1": {
      entityIds: ["smith-johnathan-151", "Claim MF-1883"],
      type: "Not Flagged",
      time: new Date(2027, 3, 4),
    },
    "claim 2": {
      entityIds: ["baxter-eleanor-004", "Claim SL-8745"],
      type: "Flagged",
      time: new Date(2025, 2, 25),
    },
    "claim 3": {
      entityIds: ["west-josephine-126", "Claim DO-1748"],
      type: "Not Flagged",
      time: new Date(2028, 12, 8),
    },
    "claim 4": {
      entityIds: ["roberts-nathaniel-023", "Claim EF-8738"],
      type: "Not Flagged",
      time: new Date(2025, 6, 13),
    },
    "claim 5": {
      entityIds: ["smith-johnathan-151", "Claim PD-9393"],
      type: "Flagged",
      time: new Date(2027, 10, 16),
    },
    "claim 6": {
      entityIds: ["baxter-eleanor-004", "Claim IE-9393"],
      type: "Not Flagged",
      time: new Date(2028, 2, 25),
    },
    "claim 7": {
      entityIds: ["roberts-nathaniel-023", "Claim GZ-2012"],
      type: "Flagged",
      time: new Date(2027, 4, 11),
    },
    "claim 8": {
      entityIds: ["baxter-eleanor-004", "Claim SQ-5563"],
      type: "Not Flagged",
      time: new Date(2025, 11, 2),
    },
    "claim 9": {
      entityIds: ["west-josephine-126", "Claim FW-1888"],
      type: "Flagged",
      time: new Date(2026, 8, 5),
    },
  },
};
<!doctype html>
<html>
  <head>
    <link rel="stylesheet" href="@ci/theme/kg/css/examples.css" />
  </head>
  <body>
    <div id="my-timeline" style="height: 100vh"></div>
    <script type="module" src="./code.jsx"></script>
  </body>
</html>

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.