Code Monkey home page Code Monkey logo

react-sigma's Introduction

npm version Build Status

It makes easy to publish networks on Web pages and allows developers to integrate network exploration in rich Web applications. Use JSX for graph configuration, including asynchronous graph loading. Library is lightweight and modular, so you can bundle only what you use. Easy to extend with additional components.

Table of Contents

Usage

See storybook for working examples.

Please make sure to read CONTRIBUTION prerequisites section if you want to fork & change or contribute.

Install

npm install --save react-sigma

or

yarn add react-sigma

or

bower install https://unpkg.com/[email protected]/dist/react-sigma.min.js

If you don't want to use webpack or browserify, you could always reference the single file distribution, library will be available under global var ReactSigma:

<script src="https://unpkg.com/[email protected]/dist/react-sigma.min.js"/>

Simple use case with embedded graph

import {Sigma, RandomizeNodePositions, RelativeSize} from 'react-sigma';
...
let myGraph = {nodes:[{id:"n1", label:"Alice"}, {id:"n2", label:"Rabbit"}], edges:[{id:"e1",source:"n1",target:"n2",label:"SEES"}]};
...
<Sigma graph={myGraph} settings={{drawEdges: true, clone: false}}>
  <RelativeSize initialSize={15}/>
  <RandomizeNodePositions/>
</Sigma>

Note that graph nodes require x, y and size defined in order to be displayed, plugins like RelativeSize and RandomizeNodePositions might help to generate those. Sigma updates graph positions, therefore if to keep track of nodes in this example we use <Sigma settings={{clone: false}}>

Simple use case with graph loaded from external file

import {Sigma, LoadJSON} from 'react-sigma'
...
<Sigma style={{width:"200px", height:"200px"}}>
  <LoadJSON path="/public/data.json" />
</Sigma>

Advanced use case

...
<Sigma renderer="canvas">
	<EdgeShapes default="tapered"/>
	<NodeShapes default="star"/>
	<LoadGEXF path={String(process.env.PUBLIC_URL) + "/arctic.gexf"}>
		<Filter neighborsOf={ this.state.filterNeighbours } />
		<ForceAtlas2 worker barnesHutOptimize barnesHutTheta={0.6} iterationsPerRender={10} linLogMode timeout={3000}/>
		<RelativeSize initialSize={15}/>
	</LoadGEXF>
</Sigma>

Components reference

Please see react-sigma reference for details. Below is a brief concept.

Sigma

Sigma is the main component which reserves

area with a given style (default is full width, 500px height), initializes renderer and camera in the given area and starts rendering graph. be composed with sigma plugins using JSX syntax, e.g.:

<Sigma renderer="webgl" style={{maxWidth:"inherit", height:"400px"}}
		settings={{drawEdges:false}}
		onOverNode={e => console.log("Mouse over node: " + e.data.node.label)}
		graph={{nodes:["id0", "id1"], edges:[{id:"e0",source:"id0",target:"id1"}]}}>
	<RelativeSize initialSize={8} />
</Sigma>

SigmaEnableWebGL

By default sigma package includes only canvas rendering functions with webpack2, though it can be easily extended with WebGL or SVG (see next topic). Importing SigmaEnableWebGL enables WebGL renderer, setting it as default renderer if WebGL is supported by browser.

import { Sigma, SigmaEnableWebGL } from 'react-sigma'
...
<Sigma /> // will use webgl renderer if supported by browser

SigmaEnableSVG

Sigma can be easily extended with SVG renderer. Importing SigmaEnableSVG enables SVG renderer, though it does not set it as default so renderer should be explicitly specified in sigma options.

import { Sigma, SigmaEnableSVG } from 'react-sigma'
...
<Sigma renderer="svg" /> 

Extending sigma components

Sigma container will mount any child component with sigma instance under props.sigma. This way you can write custom sigma-aware components:

class MyCustomSigma extends React.Component {
	constructor(props) {
		super(props)
		props.sigma.graph.addNode({id:"n3", label:props.label})
	}
}
...
return  <Sigma>
	<MyCustomSigma label="Label">
</Sigma>

Components composition

Component which initialize or provide graph changes asynchronously are supposed to mount children after initialized. For instance LoadJSON will render child subcomponents only after loading. This makes possible to build sequential composition in the pure JSX without any callbacks or handlers. In the following example RelativeSize will be instantiated only after loading from arctic.json file.

<Sigma>
	<LoadJSON url="/arctic.json">
		<RelativeSize initialSize={8}/>
	</LoadJSON>
</Sigma>

Types

All defined Sigma types stored under /types/sigma.js, can be used as a reference for objects and parameters. TODO: move to flow-typed

Attributions

  • this project is a React wrapper around excellent Sigma.JS library built by @jacomyal and @Yomguithereal

react-sigma's People

Contributors

dependabot[bot] avatar dunnock avatar frejonb avatar jnmandal avatar jstafford avatar jvansan avatar jvkersch avatar kartikchugh avatar kpbode avatar osela avatar rogertangos avatar yomguithereal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-sigma's Issues

Cant npm install / npm build in local development

When trying to build the code, I am getting a webpack failure at the npm install step.

Here is the error:

> [email protected] prepublish /Users/georgemichael/Code/react-sigma
> npm run build


> [email protected] build /Users/georgemichael/Code/react-sigma
> babel-node scripts/build-cli.js

Error: Command failed: webpack --bail --config /Users/georgemichael/Code/react-sigma/sigma-src/webpack.config.sigma.js
(node:83839) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/is
sues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
ModuleNotFoundError: Module not found: Error: Can't resolve '/Users/georgemichael/Code/react-sigma/node_modules/sigma-react/plugins/sigma.layouts.forceLink/wo
rker.js' in '/Users/georgemichael/Code/react-sigma'
...
... bunch of stuff about Field `browser` doesn't contain a valid alias configuration
...
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `babel-node scripts/build-cli.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.

use with svg renderer?

I'm trying to make a sigma.js graph with complex (and nested) react components as nodes. I think the only way to make this work is with something like the sigma.js svg renderer. When I came across this library, I hoped it might help, but maybe not...

There's a lot of great stuff here for integrating sigma into a react app, but I'm not sure how to accomplish my use case. Any suggestions?

Using node properties as node position

Is it possible to use node properties for example x,y properties, to fix node position in drawing?
I wanna use node properties as position instead of using drawing layouts,FA, FA2, Randomized.

react-sigmajs is old

When I yarn add react-sigmajs, an old version of react-sigma is installed. It might be useful to just deprecate the package to avoid confusion.

(I only found this out because I was looking for a feature from 1.2.17 and didn't find it.)

Dotted Arrows in Sigma

Hello!

I would like to add dotted arrows in sigma, but would require that I fork both Sigma.js and react-sigma.

It would require that I add a file that combines the arrows customEdge and the dashed and dotted customEdge

I am pretty sure I can just get by with adding it to my local dev, but it is hacktober fest so I figured I should at least try and contribute! :)

Loading gzipped json file.

Is it possible to load gzipped json file instead of uncompressed file. for example using

<LoadJSON path={"/NG/sample.json.gz"}/>

enableEdgeHovering efficiency

I was trying a 700 nodes and 1600 edges graph. If I don't set the "enableEdgeHovering", the graph will be rendered in a second.

However, if I set "enableEdgeHovering:true", it will have a 4 second delay before rendering the graph.

I know to set "enableEdgeHovering" will affect performance, but 4 second delay is too big.

Could you take a test to see if anything goes wrong? Because I think SigmaJS should not have such a long delay be setting the "enableEdgeHovering" flag.

How would I implement node selection?

In (plain / non-react) Sigma, I can do something like this:

s.bind('clickNode', e => {
  if (e.data.node.isSelected) {
    e.data.node.color = e.data.node.originalColor;
    e.data.node.isSelected = false;
  } else {
    e.data.node.originalColor = e.data.node.color;
    e.data.node.color = '#0000ff';
    e.data.node.isSelected = true;
  }

  s.refresh()
});

That is: onClick, I select the clicked node and color it blue, then stash its original color. How would I do the same in React-Sigma? I expect calling refresh() is not the way to go?

react-scripts coulnd't build project that depends on react-sigma

I just created simple react project ,https://github.com/alishir/NG, with create-react-app, then added react-sigma depencey via npm install --save react-sigma. But when I want to build project for hosting on github pages, the following error pops up.

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file: 

 	./node_modules/react-sigma/es/tools.js:4 

Read more here: http://bit.ly/2tRViJ9

And here is the instructions to fix the issue, copied from http://bit.ly/2tRViJ9:

npm run build fails to minify

You may occasionally find a package you depend on needs compiled or ships code for a non-browser environment.
This is considered poor practice in the ecosystem and does not have an escape hatch in Create React App.

To resolve this:
  - Open an issue on the dependency's issue tracker and ask that the package be published pre-compiled (retaining ES6 Modules).
  - Fork the package and publish a corrected version yourself.
  - If the dependency is small enough, copy it to your src/ folder and treat it as application code.

would you please publish this package in pre-compiled mode?

Get to the sigma instance

I'm trying to get to the sigma instance to refresh the graph when i add a new Node.
how can i get to it?
i'm using also ForceAtlas2 how can i get to the API?

Problem embedding Noverlap into Atlas2

Hi Maxim,

Not sure if I'm doing anything wrong as React is quite new to me but I'm facing an issue when trying to use Noverlap after ForceAtlas2.

Here's what I did:

<LoadJSON path="/data/pairsGraph_Group4.json">
    <RelativeSize initialSize={20}/>
    <RandomizeNodePositions/>
    <ForceAtlas2 scalingRatio={5}>
            <NOverlap/>
    </ForceAtlas2>  
</LoadJSON>

And here's what I get when executing my App:
image

Did I miss anything?

Thanks!

edge don't change colors when SigmaEnableSVG enabled

When Sigm'as renderer is set to svg
<Sigma renderer='svg' />

I am unable to dynamically update node colors

const graph = sigma.graph;
graph.edges().forEach( e => {
   e.color = '#eeeeee';
});
sigma.refresh();

I have also tried
e.stroke = '#eeeeee';

However it work perfectly fine without SigmaEnableSVG

SSR bypass

It breaks SSR, as no window is defined. There are various workarounds, but it's nicer handled in the library itself by checking for window.

I thought it's only this line, but your build adds bindings to window .call(window).

Thanks!

Use async/await instead of callbacks

	_load(url: string) {
		sigma.parsers.gexf(
			this.props.path ,
			this.props.sigma ,
			this.onLoad
		)
	}

	_onLoad() {
		if(this.props.sigma)
		this.props.sigma.refresh()
		this.setState({loaded:true})
		if(this.props.onGraphLoaded)
			return this.props.onGraphLoaded()
	}

can be written as:

  loadGexf() {
    return new Promise((resolve) => sigma.parsers.gexf(this.props.path, this.props.sigma, resolve));
  }

  async load() {
    const sigma = this.props.sigma;
    if(!sigma) return;
    await loadGexf();
    sigmaI.refresh();
    this.setState({loaded:true});
    this.props.onGraphLoaded &&
      this.props.onGraphLoaded();
  }

Dependencies have several issues - missing dependencies, conflicting dependencies, out of date dependencies

I wanted to take a look at this package, so I cloned it. Unfortunately I missed the line in the Contributing readme about setting up for canvas (that might need to be highlighted a little more), so when I did "yarn install" I got the errors below. Since there were so many, I just started at the top.

  • webpack dependency conflicting with webpack devDependency looks like the case of someone using an old version of yarn and doing a yarn add without the -D flag. Easy enough to update the devDependency to the newer version and remove webpack from the dependency list.
  • Same issue for whatwg-fetch.
  • While I was there I noticed that react and react-dom were both listed as dependencies and peerDependencies, when clearly they should have been devDependencies and peerDependencies.
  • The unmet dependency of @kadira/storybook-addons was easy to fix.
  • react-dev-utils 0.3.0 depending on webpack 1 was easy to fix by going up to 0.5.2.
  • ajv-keywords having the wrong peer dependency on ajv had me stumped for a while, but it was a problem with the versions in the yarn.lock file that was fixed with a "yarn upgrade"

Finally I got to the real failure and it still wasn't fixed. I decided to go ahead and upgrade everything else, thinking that would surely fix the problem. Of course it didn't. Eventually I took a more careful look at the error message, and realized that all I needed to do was a "brew install pkg-config"

Long story short, I have a pull request to go along with this issue if you are interested in taking all or part of it.

yarn install v0.21.3 warning [email protected]: "dependencies" has dependency "webpack" with range "^2.2.1" that collides with a dependency in "devDependencies" of the same name with version "2.2.0-rc.3" warning [email protected]: "dependencies" has dependency "whatwg-fetch" with range "^2.0.1" that collides with a dependency in "devDependencies" of the same name with version "1.0.0" [1/4] ๐Ÿ” Resolving packages... [2/4] ๐Ÿšš Fetching packages... [3/4] ๐Ÿ”— Linking dependencies... warning "@kadira/[email protected]" has unmet peer dependency "@kadira/storybook-addons@^1.3.0". warning "@kadira/[email protected]" has unmet peer dependency "@kadira/storybook-addons@^1.5.0". warning "[email protected]" has incorrect peer dependency "webpack@^1.13.2". warning "[email protected]" has incorrect peer dependency "ajv@>=4.10.0". [4/4] ๐Ÿ“ƒ Building fresh packages... [1/2] โ „ fsevents: info ok [2/2] โ „ canvas: spawn args '-Goutput_dir=.' ] [-/2] โ „ waiting... [-/2] โ „ waiting... error /Users/jason/code/react-sigma/node_modules/canvas: Command failed. Exit code: 1 Command: sh Arguments: -c node-gyp rebuild Directory: /Users/jason/code/react-sigma/node_modules/canvas Output: gyp info it worked if it ends with ok gyp info using [email protected] gyp info using [email protected] | darwin | x64 gyp info spawn /usr/local/bin/python2 gyp info spawn args [ '/usr/local/Cellar/yarn/0.21.3/libexec/lib/node_modules/yarn/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/Users/jason/code/react-sigma/node_modules/canvas/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/usr/local/Cellar/yarn/0.21.3/libexec/lib/node_modules/yarn/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/Users/jason/.node-gyp/7.6.0/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/Users/jason/.node-gyp/7.6.0', gyp info spawn args '-Dnode_gyp_dir=/usr/local/Cellar/yarn/0.21.3/libexec/lib/node_modules/yarn/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=node.lib', gyp info spawn args '-Dmodule_root_dir=/Users/jason/code/react-sigma/node_modules/canvas', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' ] ./util/has_lib.sh: line 31: pkg-config: command not found gyp: Call to './util/has_lib.sh freetype' returned exit status 0 while in binding.gyp. while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: gypfailed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/local/Cellar/yarn/0.21.3/libexec/lib/node_modules/yarn/node_modules/node-gyp/lib/configure.js:308:16) gyp ERR! stack at emitTwo (events.js:106:13) gyp ERR! stack at ChildProcess.emit (events.js:192:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12) gyp ERR! System Darwin 16.4.0 gyp ERR! command "/usr/local/Cellar/node/7.6.0/bin/node" "/usr/local/Cellar/yarn/0.21.3/libexec/lib/node_modules/yarn/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /Users/jason/code/react-sigma/node_modules/canvas gyp ERR! node -v v7.6.0 gyp ERR! node-gyp -v v3.5.0 gyp ERR! not ok info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

React 15.5.0 deprecation warnings

Using this library in my project, I get the following warning on my console: "Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.".

The problem is that the version of babel-plugin-flow-react-proptypes you use is quite old, and still uses React.PropTypes when generating propTypes, instead of using the new separate prop-types package.

This could be easily fixed by upgrading to a newer version of the plugin and publishing a new version to npm.

Can't catch an exception on sigma's read method

Any kind of exception that sigma throws as result of addEdge and addNode while is reading graph data can't be caught.

  constructor(props: Props) {
    super(props);
    this.state = {renderer:false}
    let settings = this.props.settings ? this.props.settings : {}
    this.sigma = new sigma({settings})
    this.initRenderer = this.initRenderer.bind(this)
    Sigma.bindHandlers(this.props, this.sigma)
    if(this.props.graph)
      this.sigma.graph.read(this.props.graph)
  }

What about adding a try/catch for the read method?

Regards,
Martin

Storybook does not work

I think there are 404 for the JSONs, I'm not sure.
But on my machine the Storybook does not work (macOS, Safari and Chrome)

The Demo Sigma Embedded Graph Is Not visible

Do you know why this is the case?

Starting up a brand new react project, and adding the Sigma Component, as detailed in the demo.

Start a new app:

npm install -g create-react-app
create-react-app test-graph
cd test-graph
yarn add react-sigmajs
npm start

Add the import and embed sigma in App.js

import {Sigma} from 'react-sigmajs'
...
<Sigma graph={{nodes:[{id:"n1", label:"Alice"}, {id:"n2", label:"Rabbit"}], edges:[{id:"e1",source:"n1",target:"n2",label:"SEES"}]}}/>

My packages.json file:

{
  "name": "react-sigmajs",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-scripts": "0.8.4"
  },
  "dependencies": {
    "react": "^15.4.1",
    "react-dom": "^15.4.1",
    "react-sigmajs": "^0.4.13"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

Screenshot:
image

Help needed: Add nodes via click

Hi.
I am trying to add nodes by click. I just can't figure out how to actually convert the coordinates correctly.
I was trying to follow the sigma example at https://github.com/jacomyal/sigma.js/blob/master/examples/add-node-on-click.html#L410-L415

I created a repo at https://github.com/loopmode/react-sigma-experiments

The relevant lines there are https://github.com/loopmode/react-sigma-experiments/blob/master/src/App.js#L84-L88 but I just can't make it work :/

I appreciate any help. Ideally, someone would actually clone and launch my demo project..

Also: Am I just making things complicated while it's much easier?
Is there an example of how to add nodes via click with react-sigma somewhere?

sigma.refresh() with a new graph hides the graph

When Sigma is passed a new graph prop and sigma.refresh() is called, the graph disappears.

// Instantiate Sigma with an existing graph

      <Sigma graph={this.props.graph} settings={{drawEdges:true}}>
         <RelativeSize initialSize={15}/>
         <RandomizeNodePositions/>
      </Sigma>

// update this.props.graph, which calls Sigma.componentDidUpdate() and Sigma.sigma.refresh()

// The graph disappears from the screen, though the Sigma.graph object is updated

Maybe Sigma.sigma isn't able to handle other Sigma.props like RelativeSize or RandomNodePosition?

Dragging nodes

Hi, how is possible to activate the node dragging plugin of sigma?

Thanks

Running NOverlap after ForceLink is finised

Greetings!

It's a pretty common issue in sigma that thinks like ForceAtlas2 and ForceLink can cause a lot of node overlap (i.e. sigma issues 613, 107, and 687).

The approach I'm trying to take (and the one I think makes the most sense) is to perform ForceLink and then remove the overlap once that's complete. I've tried composing both <ForceLink/> and <NOverlap/> on the same level, but doing that has NOverlap mount and run immediately (which is before ForceLink is done). I've also tried comopsing it inside of ForceLink, but that results in an error.

Is it possible for me to force NOverlap to run once ForceLink is done using some composition? Or is that something that I'll have to handle in Sigma directly? Thanks!

Nodes overlapping Issue

How do I avoid nodes from overlapping using ForceAtlas2 ?
I have tried a bunch of different setting but nothing helped so far

Are edge arrows working?

Adding defaultEdgeArrow={'both'} to the Sigma component does nothing. Is the sigma version included in the React component already compatible with the edge's arrow funcionality?

Inheriting NeoGraphItemsProducers

Hi,

Should it be possible to inherit or overload the two factory functions (node() & edge() ) in this class?
I ended up monkey patching it by adding decorators on a runtime instance by adjusting the prototype - pretty nasty stuff.

    this.myProducers = new NeoGraphItemsProducers()
    const myProto = Object.getPrototypeOf(this.myProducers)

    const baseNodeFactory = myProto.node.bind(this.myProducers)
    const baseEdgeFactory = myProto.edge.bind(this.myProducers)

    myProto.node = (n) => {
      var x = baseNodeFactory(n)
      x.label = n.properties.Name
      return x
    }

    myProto.edge = (e) => {
      var x = baseEdgeFactory(e)
      x.label = e.properties.Name
      return x
    }

    Object.setPrototypeOf(this.myProducers, myProto)

I tried to extend the ES6 version of the NeoGraphItemsProducers class, but when I try to instantiate the inherited class, I end up with TypeError: Class constructor NeoGraphItemsProducers cannot be invoked without 'new'

./node_modules/react-sigma/es/tools.js:4

Hi,

When I'm running npm run build I am getting an error with one of your files

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file: 
 	./node_modules/react-sigma/es/tools.js:4 

Read more here: http://bit.ly/2tRViJ9

Default edge size prevents onClick, onHover, from firing

I have a graph with nodes connected by edges. When I set my edge size to >= 1, onClick, onHover, etc, work as expected. However, when I do not explicitly set my edge size, none of them work (although the edges still render). It's a pretty confusing and unexpected behavior for edges.

Graph.js:

...
return (
 <div id="graph">
      <Sigma
        settings={this.state.sigmaSettings}
        renderer="canvas"
        onOverEdge={e => console.log('onOverEdge')}
        >
        {
          Object.keys(this.props.selection).map(
              key=>
                <SigmaNode ...>
                </SigmaNode>
              )
        }
        {
          Object.keys(this.props.graphEdges).map(
              key=>
                <SigmaEdge
                  key={key}
                  edge={this.props.graphEdges[key]}
                  ...
                  >
                </SigmaEdge>
              )
        }
      </Sigma>
    </div>
    )

GraphEdges.js:

class SigmaEdge extends React.Component {
  constructor(props){
    super(props);
    this.embedProps = this.embedProps.bind(this);

    // This puts edges on the graph
    props.sigma.graph.addEdge({
      id:props.edge.eid,
      source:props.edge.source,
      target:props.edge.target,
      label:props.edge.label,
      color:props.color, // have to specify color here. Not in the paren't sigma settings
      size: 4 // THIS MATTERS FOR HOVER, BUT NOT FOR RENDERING
    })
  }
...

Slow <ForceLink> and <ForceAtlas2> on production build

I'm using standart webpack + react + babel + ES6 setup for my project. The following setup works well while running webpack-dev-server, the transitions are smooth (nice UX), but the gets slow, nodes hops from one position to another, it looks terrible while running production build of code. What may cause this kind of behaviour?

 const settings = {
     defaultNodeColor: "#3388AA",
     defaultEdgeColor: "#e9eef1",
     defaultLabelColor: "#777",
     labelThreshold: 7,
     hoverFontStyle: "text-size: 14",
     minNodeSize: 1,
     maxNodeSize: 10,
     zoomingRation: 10,
     maxRatio: 20,
     minRatio: 0.75,
};

<Sigma
    renderer="canvas"
    graph={graph}
    style={{width: '100%', height: "800px"}}
    settings={settings}
     onClickNode={e => this.setState({ selectedNode: e.data.node.id})}
     onClickStage={e => this.setState({selectedNode: null})}>
     <Filter
         neighborsOf={this.state.selectedNode}
         nodesBy={this.handleSearch.bind(this)}/>
      <ForceLink
          strongGravityMode={true}
          alignNodeSiblings={true}
          slowDown={10}
          iterationsPerRender={2}
          easing="cubicInOut"/>
   </Sigma>

sigma.plugins.dragNodes.js Question

I am wondering if you can provide some examples for how to use this plugin?

For example:

        <Sigma graph={graph} settings={{drawEdges: true, clone: false, animationsTime: 3000}} style={{width:"100%", height:"500px"}}>
          <ForceLink
            randomize="locally"
            barnesHutOptimize={false}
            barnesHutTheta={0.5}
            background
            easing="cubicInOut"
            gravity={1}
            edgeWeightInfluence={0}
            alignNodeSiblings={false}
            timeout={2000}
            outboundAttractionDistribution={false}
          />
          <RelativeSize initialSize={15}/>
          <RandomizeNodePositions/>
        </Sigma>

This is an example you provided in the website. How can I add the plugin into this Sigma element?

I know the interface should be:

var dragNodesListener = sigma.plugins.dragNodes(s, s.renderers[0]);

But where to define the renderers?

I am sorry I am new to react-sigma. If you can provide a simple example for how to do dragnode, I will appreciate it.

Thank you so much.

Plugin - dragNodes

I'm trying to add dragNodes plugin. But have error with internal instanceof check in dragNodes plugin. It's trying to check is renderer is svg renderer but sigma.renderer does not have svg property. Am I missing something?

// @flow

import React from 'react';
import '../sigma/plugins.dragNodes';

type Props = {
  sigma?: sigma
  // TODO: Add listeners
};

/**
  TODO: Add plugin description
**/

class DragNodes extends React.Component {
  props: Props;

  componentDidMount() {
    const s = this.props.sigma;
    if (s) {
      console.log(s, s.renderers, sigma.renderers);
      const dragListener = new sigma.plugins.dragNodes(s, s.renderers[0]);
      // TODO: Add listeners
    }
  }

  componentWillUnmount() {
    if (this.props.sigma) {
      sigma.plugins.killDragNodes(this.props.sigma);
    }
  }

  render = () => null;
}

export default DragNodes;

forked repo saying: sigma is not declared

i forked the repo, because there are some sigma changes we need to make, then build with:
npm run build , then install the repo from our repository, but when it runs we get:
sigma is not declared from the main.js
our files and the files from the official repo are the same.

;(function(undefined) {
  'use strict';

  if (typeof sigma === 'undefined')
    throw 'sigma is not declared';

i see that we are not even using the dist/react-sigma.js (also not the oficial repo)
some one can help?

Pushing new nodes to a graph/updating graph data

Sorry if this is a noob react question. I'm trying to add and delete nodes and edges from an existing Sigma component. Currently, my component is set up as so:

<Sigma graph={{nodes:[{id:"n1", label:"Alice"}, {id:"n2", label:"Rabbit"}], edges:[{id:"e1",source:"n1",target:"n2",label:"SEES"}]}} settings={{drawEdges:true}}>
   <RelativeSize initialSize={15}/>
   <RandomizeNodePositions/>
</Sigma>

I can reach into the component and change Sigma.props.graph, but have trouble forcing the graph to re-render. How would you recommend doing this?

Duplicating Nodes on Refresh

Here is my minimal component for reproduction of this issue: https://gist.github.com/PeteMichaud/67ee2f617652113525d4160a0aefcb8d

This is being rendered through react-router like: <Route path="/market/graph" component={MarketGraph} />

It goes through render once without breaking, and it renders the html as seen in the gist output.html, but nothing actually displays.

After that initial render all subsequent refreshes throw: "Uncaught The node "n-1" already exists." from line 3095: throw 'The node "' + node.id + '" already exists.'; which is inside graph.addMethod()

The graph is obviously trying to add the nodes again after they are already added. Not sure why this is happening or how to fix this.

I also suspect the failure to display in the first place is a separate issue, because when I pause execution before the second render, still nothing is visible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.