Search

Styling Entities

Entities

Change the styling of individual entities or entity groups.

Styling Entities
View live example →

Use the controls below the timeline to change the styles of entities.

Properties for each entity are stored within its object in a simple format.

Each entity can be styled individually.

See also:

import { createTimeline } from "kronograph";
import { entities, events } from "./data";

const defaultEntityType = {
  color: "#e12d39",
  labelColor: "#e12d39",
  lineWidth: 8,
};
const entityTypes = { default: defaultEntityType };

const timeline = createTimeline("my-timeline");
timeline.set({ entities, events, entityTypes });
timeline.fit();

// Define the setting for each select control
const selectToProp = {
  color: (value) => {
    return { color: value };
  },
  "fade-outside-range": (value) => {
    return { fadeOutsideRange: value === "true" };
  },
  "label-color": (value) => {
    return { labelColor: value };
  },
  "line-width": (value) => {
    return { lineWidth: Number(value) };
  },
};

// When a select control changes, apply the setting to the default entity type or entity and update the timeline
Object.keys(selectToProp).forEach((selectName) => {
  document.getElementById(selectName).addEventListener("change", (e) => {
    // Update the default entity type
    Object.assign(defaultEntityType, selectToProp[selectName](e.target.value));
    timeline.set({ entities, events, entityTypes });
  });
});
export const entities = {
  "smith-johnathan-151": {
    label: "John Smith",
  },
  "west-josephine-126": {
    label: "Josephine West",
  },
  "roberts-nathaniel-023": {
    label: "Nathan Roberts",
  },
  "baxter-eleanor-004": {
    label: "Ella Baxter",
  },
};

export const events = {
  "email 1": {
    entityIds: ["smith-johnathan-151", "roberts-nathaniel-023"],
    time: new Date(2025, 7, 14, 8, 49),
  },
  "email 2": {
    entityIds: ["smith-johnathan-151", "baxter-eleanor-004"],
    time: new Date(2025, 7, 14, 8, 56),
  },
  "email 3": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 9, 2),
  },
  "email 4": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 9, 27),
  },
  "email 5": {
    entityIds: ["baxter-eleanor-004", "roberts-nathaniel-023"],
    time: new Date(2025, 7, 14, 10, 20),
  },
  "email 6": {
    entityIds: ["roberts-nathaniel-023", "smith-johnathan-151"],
    time: new Date(2025, 7, 14, 10, 30),
  },
  "email 7": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 10, 34),
  },
  "email 8": {
    entityIds: ["west-josephine-126", "smith-johnathan-151"],
    time: new Date(2025, 7, 14, 10, 40),
  },
  "email 9": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 10, 51),
  },
  "email 10": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 10, 34),
  },
  "email 11": {
    entityIds: ["west-josephine-126", "smith-johnathan-151"],
    time: new Date(2025, 7, 14, 12, 5),
  },
  "email 12": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 14, 37),
  },
  "email 13": {
    entityIds: ["baxter-eleanor-004", "west-josephine-126"],
    time: new Date(2025, 7, 14, 16, 7),
  },
  "email 14": {
    entityIds: ["west-josephine-126", "roberts-nathaniel-023"],
    time: new Date(2025, 7, 14, 17, 42),
  },
};
<!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">
          <div class="story__controls__item">
            <label for="color">Color</label>
            <select id="color" class="select">
              <option value="#e12d39" selected>Red</option>
              <option value="#ff8838">Orange</option>
              <option value="#fb8db9">Pink</option>
            </select>
          </div>
          <div class="story__controls__item">
            <label for="label-color">Label Color</label>
            <select id="label-color" class="select">
              <option value="#e12d39" selected>Red</option>
              <option value="#ff8838">Orange</option>
              <option value="#fb8db9">Pink</option>
            </select>
          </div>
        </div>
        <div class="stack">
          <div class="story__controls__item">
            <label class="story__controls__item__child--flex-2" for="line-width">Line Width</label>
            <select id="line-width" class="select">
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="4">4</option>
              <option value="8" selected>8</option>
              <option value="16">16</option>
            </select>
          </div>
          <div class="story__controls__item">
            <label class="story__controls__item__child--flex-2" for="fade-outside-range"
              >Fade Outside Range</label
            >
            <select id="fade-outside-range" class="select">
              <option value="true">True</option>
              <option value="false" selected>False</option>
            </select>
          </div>
        </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 { entities, events } from "./data";

export const Demo = () => {
  const [entityTypes, setEntityTypes] = useState({
    default: {
      color: "#e12d39",
      labelColor: "#e12d39",
      lineWidth: 8,
    },
  });

  return (
    <div className="story">
      <Timeline
        className="story__timeline"
        entities={entities}
        events={events}
        entityTypes={entityTypes}
      />

      <div className="story__controls story__controls--row">
        <div className="stack">
          <div className="story__controls__item">
            <label htmlFor="color">Color</label>
            <select
              id="color"
              className="select"
              defaultValue="Red"
              onChange={(e) => {
                setEntityTypes({ default: { ...entityTypes.default, color: e.target.value } });
              }}
            >
              <option value="#e12d39">Red</option>
              <option value="#ff8838">Orange</option>
              <option value="#fb8db9">Pink</option>
            </select>
          </div>
          <div className="story__controls__item">
            <label htmlFor="label-color">Label Color</label>
            <select
              id="label-color"
              className="select"
              defaultValue="Red"
              onChange={(e) => {
                setEntityTypes({ default: { ...entityTypes.default, labelColor: e.target.value } });
              }}
            >
              <option value="#e12d39">Red</option>
              <option value="#ff8838">Orange</option>
              <option value="#fb8db9">Pink</option>
            </select>
          </div>
        </div>
        <div className="stack">
          <div className="story__controls__item">
            <label className="story__controls__item__child--flex-2" htmlFor="line-width">
              Line Width
            </label>
            <select
              id="line-width"
              className="select"
              defaultValue="8"
              onChange={(e) => {
                setEntityTypes({
                  default: { ...entityTypes.default, lineWidth: Number(e.target.value) },
                });
              }}
            >
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="4">4</option>
              <option value="8">8</option>
              <option value="16">16</option>
            </select>
          </div>
          <div className="story__controls__item">
            <label className="story__controls__item__child--flex-2" htmlFor="fade-outside-range">
              Fade Outside Range
            </label>
            <select
              id="fade-outside-range"
              className="select"
              defaultValue="false"
              onChange={(e) => {
                setEntityTypes({
                  default: { ...entityTypes.default, fadeOutsideRange: e.target.value === "true" },
                });
              }}
            >
              <option value="true">True</option>
              <option value="false">False</option>
            </select>
          </div>
        </div>
      </div>
    </div>
  );
};

const root = createRoot(document.getElementById("my-timeline"));
root.render(<Demo />);
export const entities = {
  "smith-johnathan-151": {
    label: "John Smith",
  },
  "west-josephine-126": {
    label: "Josephine West",
  },
  "roberts-nathaniel-023": {
    label: "Nathan Roberts",
  },
  "baxter-eleanor-004": {
    label: "Ella Baxter",
  },
};

export const events = {
  "email 1": {
    entityIds: ["smith-johnathan-151", "roberts-nathaniel-023"],
    time: new Date(2025, 7, 14, 8, 49),
  },
  "email 2": {
    entityIds: ["smith-johnathan-151", "baxter-eleanor-004"],
    time: new Date(2025, 7, 14, 8, 56),
  },
  "email 3": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 9, 2),
  },
  "email 4": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 9, 27),
  },
  "email 5": {
    entityIds: ["baxter-eleanor-004", "roberts-nathaniel-023"],
    time: new Date(2025, 7, 14, 10, 20),
  },
  "email 6": {
    entityIds: ["roberts-nathaniel-023", "smith-johnathan-151"],
    time: new Date(2025, 7, 14, 10, 30),
  },
  "email 7": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 10, 34),
  },
  "email 8": {
    entityIds: ["west-josephine-126", "smith-johnathan-151"],
    time: new Date(2025, 7, 14, 10, 40),
  },
  "email 9": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 10, 51),
  },
  "email 10": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 10, 34),
  },
  "email 11": {
    entityIds: ["west-josephine-126", "smith-johnathan-151"],
    time: new Date(2025, 7, 14, 12, 5),
  },
  "email 12": {
    entityIds: ["smith-johnathan-151", "west-josephine-126"],
    time: new Date(2025, 7, 14, 14, 37),
  },
  "email 13": {
    entityIds: ["baxter-eleanor-004", "west-josephine-126"],
    time: new Date(2025, 7, 14, 16, 7),
  },
  "email 14": {
    entityIds: ["west-josephine-126", "roberts-nathaniel-023"],
    time: new Date(2025, 7, 14, 17, 42),
  },
};
<!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.