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-native-vis-network

v2.0.0

Published

Use vis-network in your React Native projects

Downloads

20

Readme

react-native-vis-network

react-native-vis-network lets you use vis-network in your React Native projects.

iOS example

Android example

Installation

# react-native-vis-network needs to use react-native-webview to work correctly,
# so install it if you haven't previously installed it in your project
npm install react-native-webview

npm install react-native-vis-network

Usage

import React, { useState } from 'react';
import VisNetwork, { Data } from 'react-native-vis-network';

export default function MyComponent() {
  const [data, setData] = useState<Data>({
    edges: [
      { from: 1, to: 3 },
      { from: 1, to: 2 },
      { from: 2, to: 4 },
      { from: 2, to: 5 },
      { from: 3, to: 3 },
    ],
    nodes: [
      { id: 1, label: 'Node 1' },
      { id: 2, label: 'Node 2' },
      { id: 3, label: 'Node 3' },
      { id: 4, label: 'Node 4' },
      { id: 5, label: 'Node 5' },
    ],
  });
  return <VisNetwork data={data} />;
}

Event Listeners

You can add event listeners for any vis-network Event.

Note that the earliest time you can successfully add an event listener is during the onLoad callback. If you try to add an event listener before then your callback won't be called.

export default function MyComponent() {
  const [loading, setLoading] = useState<boolean>(false);
  const visNetworkRef = useRef<VisNetworkRef>(null);

  useEffect(() => {
    if (!loading || !visNetworkRef.current) {
      return;
    }

    const subscription = visNetworkRef.current.addEventListener(
      'click',
      (event: any) => console.log(JSON.stringify(event, null, 2))
    );

    return subscription.remove;
  }, [loading]);

  // ...

  return (
    <VisNetwork
      data={data}
      onLoad={() => setLoading(true)}
      ref={visNetworkRef}
    />
  );
}

Methods

You can use any of the vis-network methods that are not discussed in the caveats below.

Caveats

  1. It's not possible to use the following methods due to their non-serializable parameters:
  2. It's not possible to use the following methods due to various issues discussed in 87da46d:
  3. Intentionally, the methods on, off, and once have not been implemented. Instead, use addEventListener as described in Event Listeners.
  4. While using methods like addEdgeMode, addNodeMode, setData, and setOptions will successfully update and re-render the network, they will not update the data or options props passed into VisNetwork. Using any of these methods will cause the props to become out-of-sync with what is actually displayed.

Example

export default function MyComponent() {
  const visNetworkRef = useRef<VisNetworkRef>(null);

  // ...

  return (
    <>
      <VisNetwork data={data} ref={visNetworkRef} />
      <Button
        title="Focus on node 1"
        onPress={() => {
          const nodeId = 1;
          visNetworkRef.current?.focus(nodeId, { animation: true, scale: 5 });
        }}
      />
    </>
  );
}

Options

You can use any of the vis-network options that are serializable as JSON (i.e. not functions or callbacks).

Example

export default function MyComponent() {
  const [options, setOptions] = useState<Options>({
    edges: {
      color: 'blue',
      width: 2,
    },
    interaction: {
      dragNodes: false,
      keyboard: false,
    },
    nodes: {
      borderWidth: 4,
      color: 'pink',
    },
  });

  // ...

  return <VisNetwork data={data} options={options} />;
}

Additional Options

In addition to the vis-network options mentioned in the Options section, the following props are also available.

zoomFitOnStabilized

  • If true, the network is zoomed in or out to fill its container.
  • If false, nothing is done. As a result, nodes may be smaller than expected.
  • Default value: true

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library