AlexRu
AlexRu

Reputation: 85

Change the interaction attribute of JointJs Paper?

Recently I needed to make an interactive mode of a JointJs diagram. As one knows, the creation of a paper object goes like this:

    paper = new joint.dia.Paper({
      el: $(#myDiagram),
      width: this.props.width,
      height: this.props.height,
      model: this.state.graph,
      gridSize: 1,
      interactive: false
    });

You create a new paper with the options you want for it. In this case the interaction (the "interactive" flag) is set to false. Unfortunately there are no get, attrs, set methods on a paper object. I would like to create a button that changes the interactive flag. The location of it is in the options object inside the paper. Manual access changes the value but this does not reflect the paper at all. Is the only solution to reinitialize it every time you change the interaction? Thanks beforehand.

Upvotes: 2

Views: 1587

Answers (3)

Sebastian Kropp
Sebastian Kropp

Reputation: 376

This has changed and got a lot better. I am using jointjs 1.0.3 and this works for me now:

  edit() {
    const self = this
    this.graph.getCells().forEach(function (cell) {
      const c = cell.findView(self.paper)
      c.setInteractivity(true)
    })
  }

Upvotes: 1

DenEwout
DenEwout

Reputation: 944

My fix for this issue was the following:

_.forEach(this.graph.getLinks(), function (link:joint.dia.Link) {
    self.paper.findViewByModel(link).options.interactive = {
        vertexAdd: true,
        vertexMove: true,
        vertexRemove: true,
        arrowheadMove: false
    }
});

(I used David Durman's answer on this question: https://groups.google.com/forum/#!searchin/jointjs/interactive/jointjs/h7tVqVUTd2E/VfA1BaQaFFAJ)

This allowed me to change the interactivity (specifically changing vertices) of all my links without having to go through paper initialization again.

Upvotes: 0

ppareja
ppareja

Reputation: 760

Did you already try calling

paper.render()

after changing the value?

Upvotes: 0

Related Questions