Giter VIP home page Giter VIP logo

Comments (5)

xhluca avatar xhluca commented on May 24, 2024 8

It is possible to rerun it, using the cy handler. Here's what I'm using for Dash Cytoscape:

    handleCy(cy) {
        ...
        SELECT_THRESHOLD = 100;

        // Refresh Layout if needed
        const refreshLayout = _.debounce(() => {
            const {
                autoRefreshLayout,
                layout
            } = this.props;

            if (autoRefreshLayout) {
                cy.layout(layout).run()
            }
        }, SELECT_THRESHOLD);

        cy.on('add remove', () => {
            refreshLayout();
        });
    }

where autoRefreshLayout is a prop indicating whether to refresh the layout or not when a new element is added. The function handleCy() is used specifically to handle the cy, which is passed in the render() method, which would look something like that:

render() {
        const {
        ...
        } = this.props;

        return (
            <CytoscapeComponent
                cy={this.handleCy}
                elements={...}
                stylesheet={...}
            />
        )
    }

from react-cytoscapejs.

invisibleroads avatar invisibleroads commented on May 24, 2024 1

@xhlulu
Thank you sir! Your comment was a lifesaver.

from react-cytoscapejs.

xhluca avatar xhluca commented on May 24, 2024

Note here I'm using lodash for the debounce method. Please check out the official docs, or the react component for Dash Cytoscape

from react-cytoscapejs.

maxkfranz avatar maxkfranz commented on May 24, 2024

This isn't possible to do declaratively, because each layout has a different set of options: The diff would be handled differently in each case. I suppose it could be supported for the simple === case, though that would have some caveats.

from react-cytoscapejs.

erikhofer avatar erikhofer commented on May 24, 2024

Another option, if you don't want to use debounce, is using useEffect to re-run the layouts when elements change:

const elements = [ /* ... */ ]
const layout = { /* ... */ }

const [cy, setCy] = useState<Cytoscape.Core | null>(null)

useEffect(() => {
  cy?.layout(layout).run()
}, [cy, elements]) // make sure to add elements here

return <CytoscapeComponent cy={setCy} elements={elements} />

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.