npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-gojs

v4.9.0

Published

GoJS React integration

Downloads

335

Readme

:warning: react-gojs is no longer under active development. Now, Northwoods provides an official React integration for GoJS: https://github.com/NorthwoodsSoftware/gojs-react. I will not add new features to this lib, only bug fixes. The migration to the official library is pretty easy. I migrated my example here.

NpmVersion npm Build Status Coverage Status TypeScript

react-gojs

react-gojs is a GoJS React integration.

Install

Install it from npm. It has peer dependencies of react and react-dom, which will have to be installed as well.

npm install --save react-gojs

or:

yarn add react-gojs

Usage

Import GojsDiagram in your React component:

import GojsDiagram from 'react-gojs';

To create a GoJS diagram, just use the GojsDiagram React component:

<GojsDiagram
    diagramId="myDiagramDiv"
    model={this.props.model}
    createDiagram={this.createDiagram}
    className="myDiagram"
    onModelChange={this.modelChangedhandler}
    updateDiagramProps={this.updateDiagramProps}
/>

GojsDiagram is a generic React component which is responsible for rendering and updating (when the model changes) the diagram. The render step is based on the model and the go.Diagram object provided as props. It acts as a go.Diagram wrapper.

GojsDiagram props:

  • diagramId: id required by GoJS.
  • model: generic model containing nodes and links.

Model type: DiagramModel<N extends BaseNodeModel, L extends LinkModel>

Example (Typescript / Javascript):

const model = {
    nodeDataArray: [
        { key: 'Alpha', color: 'lightblue' },
        { key: 'Beta', color: 'orange' },
        { key: 'Gamma', color: 'lightgreen' },
        { key: 'Delta', color: 'pink' },
        { key: 'Omega', color: 'grey' }
    ],
    linkDataArray: [
        { from: 'Alpha', to: 'Beta' },
        { from: 'Alpha', to: 'Gamma' },
        { from: 'Beta', to: 'Delta' },
        { from: 'Gamma', to: 'Omega' }
    ]
};
  • createDiagram: method called by the React component to create the customized GoJS diagram object. It enables you to customize the look and feel.

Typescript example:

const createDiagram = (diagramId: string): Diagram => {
    const $ = go.GraphObject.make;

    const myDiagram: Diagram = $(go.Diagram, diagramId, {
        initialContentAlignment: go.Spot.LeftCenter
    });

    myDiagram.nodeTemplate = $(
        go.Node,
        'Auto',
        $(go.Shape, 'RoundedRectangle', { strokeWidth: 0 }, new go.Binding('fill', 'color')),
        $(go.TextBlock, { margin: 8 }, new go.Binding('text', 'key'))
    );

    return myDiagram;
};

Javascript (ES6) example:

const createDiagram = diagramId => {
    const $ = go.GraphObject.make;

    const myDiagram = $(go.Diagram, diagramId, {
        initialContentAlignment: go.Spot.LeftCenter
    });

    myDiagram.nodeTemplate = $(
        go.Node,
        'Auto',
        $(go.Shape, 'RoundedRectangle', { strokeWidth: 0 }, new go.Binding('fill', 'color')),
        $(go.TextBlock, { margin: 8 }, new go.Binding('text', 'key'))
    );

    return myDiagram;
};
  • className: css applied to the div containing our diagram. You should define at least width and height.

Example:

.myDiagram {
    width: 70%;
    height: 400px;
}
  • onModelChange: the onModelChange event occurs when the diagram model has changed (add/remove nodes/links from the UI). This event is very useful to keep your model (provided as prop) in sync with the diagram.

For example, in a Redux environment, the diagram model should be immutable (and stored in the redux store). The onModelChange handler can dispatch actions to update the model.

  • updateDiagramProps (optional parameter): Method allows to update/modify Diagram properties dynamically once the diagram has been rendered. It gives more control to the user, as it is a user-defined. Basic implementation of the method.

Example 1:

const updateDiagramProps = (myDiagram: Diagram): void => {
	myDiagram.layout = go.GraphObject.make(go.LayeredDigraphLayout, { direction: 90 });

	// User can add more properties here.
};

Example 2:

const updateDiagramProps = (myDiagram: Diagram): void => {
	// Empty method.
};

Examples

  • Typescript: You can find a react / redux / react-gojs example + live demo here.

  • Javascript (ES6): You can find a react / react-gojs example + live demo here.

Contributing

Build and Test

yarn install
yarn build
yarn test

Submit a Pull Request

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Fix lint errors: yarn lint
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request

License

Apache License V2