Search

Node

Styles

Customize the nodes in your chart.

Node
View live example →

Click on the buttons to cycle through styles for that property.

The style data for the node is shown in the overlay.

You can combine properties to fully customize nodes.

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

See also

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

import mapValues from "lodash/mapValues";
import pickBy from "lodash/pickBy";
import { Chart } from "regraph";

import { style } from "@ci/theme/rg/js/storyStyles";

import "@ci/theme/rg/css/properties.css";
import "@ci/theme/rg/css/button.css";

const regraphImage = "/img/regraph.png";

export const Demo = () => <NodeStyle />;

const { colorArrays } = style;

const nodeProps = {
  border: {
    values: [
      { color: colorArrays.dark[0] },
      { color: colorArrays.dark[1] },
      { color: colorArrays.dark[2] },
      { color: colorArrays.dark[3] },
      { width: 6, color: colorArrays.dark[0] },
      { width: 6, color: colorArrays.dark[1] },
      { width: 6, color: colorArrays.dark[2] },
      { width: 6, color: colorArrays.dark[3] },
      { width: 10, color: colorArrays.dark[0] },
      { width: 10, color: colorArrays.dark[1] },
      { width: 10, color: colorArrays.dark[2] },
      { width: 10, color: colorArrays.dark[3] },
      { lineStyle: "dashed", width: 10, color: colorArrays.dark[0] },
      { lineStyle: "dashed", width: 10, color: colorArrays.dark[1] },
      { lineStyle: "dashed", width: 10, color: colorArrays.dark[2] },
      { lineStyle: "dashed", width: 10, color: colorArrays.dark[3] },
      undefined,
    ],
    label: "Border",
  },
  label: {
    values: [
      { text: "Press the buttons above" },
      { text: "Bold label", bold: true },
      { text: "Color 1", color: colorArrays.dark[0] },
      { text: "Color 2", color: colorArrays.dark[1] },
      { text: "Color 3", color: colorArrays.dark[2] },
      { text: "Background color 1", backgroundColor: colorArrays.transparent[0] },
      { text: "Background color 2", backgroundColor: colorArrays.transparent[1] },
      { text: "Background color 3", backgroundColor: colorArrays.transparent[2] },
      {
        text: "Font size: 16",
        fontSize: 16,
      },
      {
        text: "Font size: 20",
        fontSize: 20,
      },
      [
        {
          text: "Not centered",
          position: "s",
        },
      ],
      {
        text: "Sans Serif",
        fontFamily: "sans serif",
      },
      {
        text: "Comic Sans",
        fontFamily: "comic sans ms",
      },
      { text: "Default font" },
      undefined,
    ],
    label: "Node label",
  },
  fade: { values: [undefined, true], label: "Fade" },
  color: { values: [...colorArrays.standard, undefined], label: "Fill color" },
  size: { values: [undefined, 2, 4, 0.5], label: "Size" },
  shape: { values: [undefined, "box"], label: "shape" },
  image: { values: [undefined, regraphImage], label: "image url" },
  cutout: { values: [undefined, true], label: "Cut out image (circle)" },
};

class NodeStyle extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = { ...mapValues(nodeProps, () => 0) };
  }

  update = (id) => {
    const { [id]: index } = this.state;
    const { [id]: property } = nodeProps;
    const { values } = property;
    let result = index + 1;
    if (result > values.length - 1) {
      result = 0;
    }
    this.setState({ [id]: result });
  };

  reset = () => {
    this.setState({ ...mapValues(nodeProps, () => 0) });
  };

  render = () => {
    const node1 = pickBy(
      mapValues(nodeProps, (value, key) => {
        const { [key]: index } = this.state;
        const newValue = value.values[index || 0];
        if (typeof newValue === "function") {
          return newValue(this.state);
        }
        return newValue;
      }),
      (value) => value !== undefined
    );

    return (
      <div style={{ width: "100%", height: "100%" }}>
        <Chart
          items={{ node1 }}
          animation={{ animate: true, time: 250 }}
          options={{ fit: "all", navigation: false, overview: false }}
        />
        <div style={{ position: "absolute", top: 0, left: 0 }}>
          <button type="button" onClick={this.reset}>
            Reset
          </button>
          {Object.keys(nodeProps)
            .filter((key) => key !== "ci") // ci property is controlled by u property
            .map((key) => (
              <button
                type="button"
                title={nodeProps[key].label}
                key={key}
                onClick={() => this.update(key)}
              >
                {key}
              </button>
            ))}
        </div>
        <pre className="properties">{JSON.stringify({ node1 }, null, 2)}</pre>
      </div>
    );
  };
}

const root = createRoot(document.getElementById("regraph"));
root.render(<Demo />);
<!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.