Comments (8)
No worries, I think I figured out quite a nice solution, I'll leave it here to help anyone else trying to start using this package in a JSX environment.
import React, { Component } from 'react'
import * as SRD from 'storm-react-diagrams'
import modelJSON from './test.json'
class Test extends Component {
constructor() {
super()
this.engine = new SRD.DiagramEngine()
this.engine.registerNodeFactory(new SRD.DefaultNodeFactory())
this.engine.registerLinkFactory(new SRD.DefaultLinkFactory())
this.engine.registerInstanceFactory(new SRD.DefaultNodeInstanceFactory())
this.engine.registerInstanceFactory(new SRD.DefaultPortInstanceFactory())
this.engine.registerInstanceFactory(new SRD.LinkInstanceFactory())
this.model = new SRD.DiagramModel()
this.model.deSerializeDiagram(modelJSON, this.engine)
this.engine.setDiagramModel(this.model)
}
buttonClick() {
console.log(this.model)
}
render() {
return (
<div className="Test">
<button onClick={this.buttonClick.bind(this)}>Button</button>
<SRD.DiagramWidget diagramEngine={this.engine} />
</div>
)
}
}
export default Test
That's not to say that point and node moving events wouldn't be useful :)
from react-diagrams.
model.addListener({
actionStoppedFiring:()=>{
},
linksUpdated:(entity, isAdded) => {
entity.addListener({
targetPortChanged:() => {
}
});
},
nodesUpdated: (entity, isAdded) => {
}
});
from react-diagrams.
None of those events triggered anything when I added a point or moved a node:
model.addListener({
actionStoppedFiring: () => {
console.log('actionStoppedFiring')
},
linksUpdated: (entity, isAdded) => {
console.log('linksUpdated')
entity.addListener({
targetPortChanged: () => {
console.log('targetPortChanged')
}
})
},
nodesUpdated: (entity, isAdded) => {
console.log('nodesUpdated')
}
})
from react-diagrams.
will take a look now, but I'm quite positive it will
from react-diagrams.
Okay so we implemented these as a properties in the DiagramCanvas:
actionStartedFiring?: (action: BaseAction) => boolean;
actionStillFiring?: (action: BaseAction) => void;
actionStoppedFiring?: (action: BaseAction) => void;
the action that gets sent in, which you will want to look for is:
https://github.com/projectstorm/react-diagrams/blob/master/src/widgets/DiagramWidget.ts#L60
do an instance check on the action to see if it is the one above, and then from that object you can the entities that are being moved
from react-diagrams.
We can of course also, implement additional listeners on the models themselves, but this just felt like a cleaner solution because with this, you get access to everything that is being selected
from react-diagrams.
Excuse my ignorance but how is that achieved in my code (below). Essentially my goal is to log out the model after each change so I can store it in my (currently named) testConfig file.
import React, { Component } from 'react'
import * as SRD from 'storm-react-diagrams'
import modelJSON from './testConfig.json'
class Test extends Component {
render() {
let engine = new SRD.DiagramEngine()
engine.registerNodeFactory(new SRD.DefaultNodeFactory())
engine.registerLinkFactory(new SRD.DefaultLinkFactory())
engine.registerInstanceFactory(new SRD.DefaultNodeInstanceFactory())
engine.registerInstanceFactory(new SRD.DefaultPortInstanceFactory())
engine.registerInstanceFactory(new SRD.LinkInstanceFactory())
let model = new SRD.DiagramModel()
model.deSerializeDiagram(modelJSON, engine)
engine.setDiagramModel(model)
/**
* LISTEN FOR ALL MODEL CHANGES HERE
*/
return (
<SRD.DiagramWidget diagramEngine={engine} />
)
}
}
export default Test
Other JSX will be going in there, hence writing it this way (please don't judge me). It certainly would be easier (as I could adapt the documented events) if it were attached to model; I can imagine points and node moving would be something others may be interested in too.
from react-diagrams.
Aparently there is a problem defining wasMoved in DiagramWidget. It get passed to the stopFiringAction as false always.
from react-diagrams.
Related Issues (20)
- custom code
- [Bug] Right angled links are diagonal if the points are added after the link is created
- 50 Errors in build HOT 2
- BezierCurve
- Tutorial not working HOT 1
- Deserialization not working HOT 2
- Demos should be refactored to be consistent with modern react standards and styles HOT 2
- I can't see the any nodes. HOT 1
- Is there a way with smart routing to ensure that the link line is never going through the node?
- Deregister Listener when links are created
- DragNewLinkState bug when pressing down with another mouse button while dragging.
- Does storm-react-diagrams support nonce attribute for CSP?
- Node EventListeners don't work when setting a state from component
- can't find createEngine export HOT 1
- Adding NodeModel to NodeLayer set itself as its parent, but NodeModel's parent must be a Diagram
- Module '"@projectstorm/react-diagrams"' has no exported member 'AbstractReactFactory'.
- Intermittent bug in dragNewLink with allowLooseLinks = false HOT 2
- Bug: running `diagrams-demo-project` error `TS2345: Argument of type 'Element' is not assignable to parameter of type 'ReactNode'. Property 'children' is missing in type 'Element' but required in type 'ReactPortal'.`
- Deserialization isn't working properly HOT 1
- got an error in gallary demo: diagrams-demo-gallery HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-diagrams.