Search

Font Awesome

Styles

Use Font Awesome font icons on nodes and glyphs.

Font Awesome
View live example →

ReGraph can display font icons on nodes and glyphs.

Pass the CSS class name and the style class, e.g. 'fas' or 'far', into the fontIcon property.

You can load in font libraries using the document.fonts.load function.

See the FontReadyChart and Demo components in the Story tab for how to wait for fonts to load before rendering the chart.

See also

import React from "react";
import { createRoot } from "react-dom/client";

import { Chart } from "regraph";

import items from "./data";

import "@fortawesome/fontawesome-free/css/fontawesome.css";
import "@fortawesome/fontawesome-free/css/solid.css";

function FontAwesome() {
  return (
    <Chart
      items={items}
      options={{
        imageAlignment: { "fas fa-car": { size: 1.2 }, "fas fa-comment": { size: 2 } },
        iconFontFamily: "Font Awesome 5 Free",
        navigation: false,
        overview: false,
      }}
    />
  );
}

const FontReadyChart = React.lazy(() =>
  // Ensure that the CSS containing the @font-face declaration
  // has been loaded before attempting to load the font here.
  document.fonts.load("24px 'Font Awesome 5 Free'").then(() => ({
    default: FontAwesome,
  }))
);

export function Demo() {
  return (
    <React.Suspense fallback="">
      <FontReadyChart />
    </React.Suspense>
  );
}

const root = createRoot(document.getElementById("regraph"));
root.render(<Demo />);
import { style } from "@ci/theme/rg/js/storyStyles";

const items = {
  3: {
    fontIcon: { text: "fas fa-user", ...style.primary1 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "fas fa-credit-card", color: style.tertiary2.color },
      },
    ],
  },
  4: {
    fontIcon: { text: "fas fa-user", ...style.primary1 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "fas fa-comment", color: style.secondary2.color },
      },
    ],
  },
  5: {
    fontIcon: { text: "fas fa-user", ...style.primary3 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "fas fa-exclamation-circle", color: "black" },
      },
    ],
  },
  6: {
    fontIcon: { text: "fas fa-university", ...style.secondary1 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "fas fa-at", color: style.secondary2.color },
      },
    ],
  },
  7: {
    fontIcon: { text: "fas fa-car", ...style.primary2 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "fas fa-phone-square", color: "black" },
      },
    ],
  },
  8: {
    fontIcon: { text: "fas fa-building", ...style.secondary2 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "fas fa-at", color: style.secondary2.color },
      },
    ],
  },
  9: {
    fontIcon: { text: "fas fa-home", ...style.secondary3 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "fas fa-info-circle", color: style.secondary2.color },
      },
    ],
  },
  l1: { id1: "3", id2: "7" },
  l2: { id1: "4", id2: "6" },
  l3: { id1: "4", id2: "9" },
  l4: { id1: "5", id2: "7" },
  l5: { id1: "5", id2: "8" },
  l6: { id1: "5", id2: "9" },
  l7: { id1: "5", id2: "6" },
};

export default items;
<!doctype html>
<html>
  <body>
    <div id="regraph" 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.