Skip to content

Commit

Permalink
#9 chore: Add events example
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Jul 19, 2022
1 parent 185d1bc commit 6f9b247
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions dist/helpers/nodesHelper.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import { MetaNodeModel } from '../react-diagrams/MetaNodeModel';
import { MetaNode } from "../models/MetaNode";
export declare function getNode(id: string, nodes: MetaNodeModel[]): MetaNodeModel | undefined;
export declare function processNodes(metaNodes: MetaNode[]): MetaNodeModel[];
2 changes: 1 addition & 1 deletion dist/meta-diagram.cjs.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/meta-diagram.cjs.production.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/meta-diagram.esm.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion example/components/widgets/CustomNodeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class CustomNodeWidget extends React.Component<CustomNodeWidgetProps> {
render() {
const width = 250
const height = 200
console.log(this.props.model.getOptions())
// @ts-ignore
const customNodeStyle = {
zIndex: 999999999,
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/nodesHelper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { MetaNodeModel } from '../react-diagrams/MetaNodeModel';
import {MetaNode} from "../models/MetaNode";

export function getNode(
id: string,
nodes: MetaNodeModel[]
): MetaNodeModel | undefined {
return nodes.find(n => n.getOptions().id === id);
}

export function processNodes(metaNodes: MetaNode[]) : MetaNodeModel[] {
const metaNodeModels = []
for(const mn of metaNodes){
const metaNodeModel = new MetaNodeModel(Object.fromEntries(mn.options.options))
metaNodeModel.registerListener({positionChanged: () => { console.log("positionChanged") }})
metaNodeModels.push(metaNodeModel)
}
return metaNodeModels
}
5 changes: 2 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MetaNodeModel } from './react-diagrams/MetaNodeModel';
import { getLinkModel } from './helpers/linksHelper';
import { makeStyles } from '@material-ui/core';
import Sidebar from './components/Sidebar';
import {processNodes} from "./helpers/nodesHelper";

const useStyles = makeStyles(_ => ({
container: {
Expand Down Expand Up @@ -56,9 +57,7 @@ const MetaDiagram = ({
// set up the diagram model

const model = new DiagramModel();
const nodes = metaNodes.map(
mn => new MetaNodeModel(Object.fromEntries(mn.options.options))
);
const nodes = processNodes(metaNodes)
const links = metaLinks
.map(ml => getLinkModel(ml, nodes))
.filter(mlm => mlm !== undefined);
Expand Down

0 comments on commit 6f9b247

Please sign in to comment.