Search

Material Icons

Styles

Use Material Icons font icons on nodes and glyphs.

Material Icons
View live example →

ReGraph can display font icons on nodes and glyphs.

Pass the ligature string of the icon into the fontIcon property. If using multiple variants such as both Filled and Outlined, each variant must be specified in the fontFamily property.

Material Icons can be imported via url. See the CSS used in this story in the CSS tab.

As ReGraph cannot accept font icons as React Components, you must use the original Material Icons font. You can use the document.fonts.load module to load the font from Google Fonts.

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";

const imageAlignment = {
  directions_car: { dy: -10 },
  account_balance: { dy: -5 },
  chat: { size: 2 },
};

function MaterialDesign() {
  return (
    <Chart
      items={items}
      options={{
        imageAlignment,
        iconFontFamily: "Material Icons",
        navigation: false,
        overview: false,
      }}
    />
  );
}

const FontReadyChart = React.lazy(() =>
  // Ensure that the CSS containing the @font-face declarations
  // has been loaded before attempting to load the font here.
  // See CSS tab for the URL links used.
  document.fonts.ready
    .then(() =>
      Promise.all([
        document.fonts.load("24px 'Material Icons'"),
        document.fonts.load("24px 'Material Icons Outlined'"),
      ])
    )
    .then(() => ({
      default: MaterialDesign,
    }))
);

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: "person", ...style.primary1 },
    color: "rgba(0, 0, 0, 0)" /* transparent */,
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "credit_card", color: style.tertiary2.color },
      },
    ],
  },
  4: {
    fontIcon: {
      text: "person",
      fontFamily: "Material Icons Outlined",
      ...style.primary1,
    },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "chat", color: style.secondary2.color },
      },
    ],
  },
  5: {
    fontIcon: { text: "person", ...style.primary3 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "error_outline", color: "black" },
      },
    ],
  },
  6: {
    fontIcon: {
      text: "account_balance",
      fontFamily: "Material Icons Outlined",
      ...style.secondary1,
    },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "save", color: style.tertiary2.color },
      },
    ],
  },
  7: {
    fontIcon: { text: "directions_car", ...style.primary2 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "phone", color: "black" },
      },
    ],
  },
  8: {
    fontIcon: { text: "location_city", ...style.secondary2 },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "save", color: style.tertiary2.color },
      },
    ],
  },
  9: {
    fontIcon: {
      text: "home",
      fontFamily: "Material Icons Outlined",
      ...style.secondary3,
    },
    color: "rgba(0, 0, 0, 0)",
    glyphs: [
      {
        position: "ne",
        color: "rgba(0, 0, 0, 0)",
        fontIcon: { text: "error", 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>
  <head>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <div id="regraph" style="height: 100vh"></div>
    <script type="module" src="./code.jsx"></script>
  </body>
</html>
/* Import for Google's Material Icons */
@import url("https://fonts.googleapis.com/icon?family=Material+Icons");
@import url("https://fonts.googleapis.com/icon?family=Material+Icons+Outlined");

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.