Search

Ping Items

Styling

Use ping to highlight a node or link.

Ping Items
View live example →

This demo uses ping to animate a node or link.

Ping is a great way to draw attention to key items.For example, you can use it to alert users when a new node or link is added to a chart.

You can customise ping options including the width and colour of the animated effect, as well as the animation length and repetition.

Animation is a powerful visual tool that's best used in moderation. Using it too often may distract and confuse users.

Key function used:

import KeyLines from "keylines";
import { data } from "./data.js";

let chart;

function findAndPing(identifier) {
  // find the items associated with the button and ping them
  switch (identifier) {
    case "red":
      chart.ping("a", { c: identifier });
      break;
    case "green":
      chart.ping("b", { c: identifier });
      break;
    case "blue":
      chart.ping("c", { c: identifier });
      break;
    case "orange":
      chart.ping("a-b", { c: identifier });
      break;
    case "lightblue":
      chart.ping(["b-c", "c-b"], { c: "#5bc0de" });
      break;
    case "all":
      ["a", "b", "c", "a-b", "b-c", "c-b"].forEach((id) => {
        const item = chart.getItem(id);
        chart.ping(id, { c: item.c });
      });
      break;
    case "all3":
      ["a", "b", "c", "a-b", "b-c", "c-b"].forEach((id) => {
        const item = chart.getItem(id);
        chart.ping(id, { c: item.c, r: 20, w: 100, time: 1000, repeat: 3, lw: 30 });
      });
      break;
    default:
      break;
  }
}

function initialiseInteractions() {
  // listen for user clicks for each button
  Array.from(document.getElementsByClassName("ping")).forEach((el) => {
    el.addEventListener("click", () => {
      findAndPing(el.getAttributeNode("id").value);
    });
  });
}

async function loadKeyLines() {
  const options = {
    logo: { u: "/images/Logo.png" },
    handMode: true,
  };
  chart = await KeyLines.create({ container: "klchart", options });
  chart.load(data);
  chart.zoom("fit");
  // set up user interactions
  initialiseInteractions();
}

window.addEventListener("DOMContentLoaded", loadKeyLines);
export const data = {
  type: "LinkChart",
  items: [
    { type: "node", id: "a", c: "red", x: -150, y: 0 },
    { type: "node", id: "b", c: "green", x: 0, y: 0, w: 48, h: 28 },
    { type: "node", id: "c", c: "blue", x: 150, y: 0, sh: "box" },
    { type: "link", id: "a-b", id1: "a", id2: "b", c: "orange", a1: true, w: 3 },
    { type: "link", id: "b-c", id1: "b", id2: "c", c: "#5bc0de", off: 30, w: 3 },
    { type: "link", id: "c-b", id1: "c", id2: "b", c: "#5bc0de", off: 30, w: 3 },
  ],
};
<!doctype html>
<html lang="en" style="background-color: #2d383f">
  <head>
    <meta charset="utf-8" />
    <title>Ping Items</title>
    <link rel="stylesheet" type="text/css" href="@ci/theme/kl/css/keylines.css" />
    <link rel="stylesheet" type="text/css" href="@ci/theme/kl/css/minimalsdk.css" />
    <link rel="stylesheet" type="text/css" href="@ci/theme/kl/css/sdk-layout.css" />
    <link rel="stylesheet" type="text/css" href="@ci/theme/kl/css/demo.css" />
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <div id="klchart" class="klchart"></div>
    <script type="module" src="./code.js"></script>
  </body>
</html>
.btn.btn-block.faded {
  opacity: 0.75;
  margin-top: 10px;
}
.btn.btn-block.faded:hover {
  opacity: 1;
  margin-top: 10px;
}
#red {
  color: white;
  background-color: red;
  border-color: red;
}
#orange {
  color: white;
  background-color: orange;
  border-color: orange;
}
#green {
  color: white;
  background-color: green;
  border-color: green;
}
#lightblue {
  color: white;
  background-color: #5bc0de;
  border-color: #5bc0de;
}
#blue {
  color: white;
  background-color: blue;
  border-color: blue;
}
#all3 {
  margin-top: 10px;
}

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.