dunnock / react-sigma

Lightweight React library for drawing network graphs built on top of SigmaJS
https://dunnock.github.io/react-sigma/
MIT License
258 stars 43 forks source link

[Example code] Weird graph initialization #82

Open mvbattan opened 4 years ago

mvbattan commented 4 years ago

Summary

The first example doesn't work very well. At least, it initialize a zone where the graph should live but the nodes and edges have a little offset from this zone.

This was done on a create-react-app example.

Evidence

GraphExample

Repr code

import React from 'react';
import { Sigma, RandomizeNodePositions, RelativeSize } from 'react-sigma';

import styles from './styles.module.scss';

const myGraph = {
  nodes: [
    { id: 'n1', label: 'Alice' },
    { id: 'n2', label: 'Rabbit' }
  ],
  edges: [{ id: 'e1', source: 'n1', target: 'n2', label: 'SEES' }]
};

function Graph() {
  return (
    <div className={styles.container}>
      <Sigma
        graph={myGraph}
        settings={{ drawEdges: true, clone: false }}
        style={{ position: 'relative', width: '50%', height: '50%', backgroundColor: 'red' }}
        renderer="canvas"
      >
        <RelativeSize initialSize={10} />
        <RandomizeNodePositions />
      </Sigma>
    </div>
  );
}

export default Graph;

Although I can modify Sigma's style, edges and nodes have an offset.

Workaround

Writing this in a .css as global classes worked:

canvas.sigma-mouse, canvas.sigma-scene {
  right: 0;
}

Screenshot

GraphExampleCorrected

RD7023 commented 4 years ago

Thank you. Really helped