Giter VIP home page Giter VIP logo

Comments (3)

SimonGolms avatar SimonGolms commented on May 24, 2024 14

In case someone else comes here and is still looking for a solution. Here's how I was able to solve it with the cytoscape-popper extension and a reference to cytoscape/cytoscape.js-popper#35:

import React, { useEffect, useRef } from 'react';
import ReactDOM from 'react-dom';

import Cytoscape from 'cytoscape';
import CytoscapeComponent from 'react-cytoscapejs';
import popper from 'cytoscape-popper';

import { Button } from 'semantic-ui-react';

Cytoscape.use(popper);

const ReactButton = () => {
  return <Button type="button">React Button</Button>;
};

const createContentFromComponent = (component) => {
  const dummyDomEle = document.createElement('div');
  ReactDOM.render(component, dummyDomEle);
  document.body.appendChild(dummyDomEle);
  return dummyDomEle;
};

export const OmniGram = () => {
  const cyRef = useRef(null);
  const cyPopperRef = useRef(null);

  useEffect(() => {
    const cy = cyRef.current;

    cy.nodes().on('mouseover', (event) => {
      cyPopperRef.current = event.target.popper({
        content: createContentFromComponent(<ReactButton />),
        popper: {
          placement: 'right',
          removeOnDestroy: true,
        },
      });
    });

    cy.nodes().on('mouseout', () => {
      if (cyPopperRef) {
        cyPopperRef.current.destroy();
      }
    });
  }, []);

  const elements = {
    ...
  };

  return (
    <CytoscapeComponent
      elements={elements}
      cy={(cy) => {
        cyRef.current = cy;
      }}
    />
  );
};

from react-cytoscapejs.

maxkfranz avatar maxkfranz commented on May 24, 2024

Anything imperative should use the cy ref.

from react-cytoscapejs.

nitinreddy3 avatar nitinreddy3 commented on May 24, 2024

Ok Thanks

from react-cytoscapejs.

Related Issues (20)

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.