|
| 1 | +The **Devs** demo introduces a ready-to-use shape with predefined input & output port groups and simplified API. |
| 2 | + |
| 3 | +### joint.shapes.devs.Model |
| 4 | + |
| 5 | +The Model shape implements simple API on top of the JointJS built-in ports. It splits ports into two semantic groups (**in** and **out**) and adds convenient methods for adding and removing ports. |
| 6 | + |
| 7 | +| Attribute | Description | |
| 8 | +| --- | --- | |
| 9 | +| inPorts | an array of all input ports | |
| 10 | +| outPorts | an array of all output ports | |
| 11 | + |
| 12 | +##### shapes.devs.Model.addInPort |
| 13 | + |
| 14 | + element.addInPort(port, [opt]) |
| 15 | + |
| 16 | +Add a single port into the \`inPorts\` array, where \`port\` is a name of the port. |
| 17 | + |
| 18 | +##### shapes.devs.Model.addOutPort |
| 19 | + |
| 20 | + element.addOutPort(port, [opt]) |
| 21 | + |
| 22 | +Add a single port into the \`outPorts\` array, where \`port\` is a name of the port. |
| 23 | + |
| 24 | +##### shapes.devs.Model.changeInGroup |
| 25 | + |
| 26 | + element.changeInGroup(properties, [opt]) |
| 27 | + |
| 28 | +Change the settings for the input ports, where \`properties\` is an object with a [group configuration](https://resources.jointjs.com/docs/jointjs/v3.7/joint.html#dia.Element.ports.interface). It extends the previous settings with the new configuration by default. Pass `{ rewrite: true }` via `opt` to invalidate the previous settings. |
| 29 | + |
| 30 | +##### shapes.devs.Model.changeOutGroup |
| 31 | + |
| 32 | + element.changeOutGroup(properties, [opt]) |
| 33 | + |
| 34 | +Change the settings for the output ports, where \`properties\` is an object with a [group configuration](https://resources.jointjs.com/docs/jointjs/v3.7/joint.html#dia.Element.ports.interface). It extends the previous settings with the new configuration by default. Pass `{ rewrite: true }` via `opt` to invalidate the previous settings. |
| 35 | + |
| 36 | +##### shapes.devs.Model.removeInPort |
| 37 | + |
| 38 | + element.removeInPort(port, [opt]) |
| 39 | + |
| 40 | +Remove a port from an element from the \`inPorts\` array, where \`port\` is a name of the port. |
| 41 | + |
| 42 | +##### shapes.devs.Model.removeOutPort |
| 43 | + |
| 44 | + element.removeOutPort(port, [opt]) |
| 45 | + |
| 46 | +Remove a port from an element from the \`outPorts\` array, where \`port\` is a name of the port. |
| 47 | + |
| 48 | +### joint.shapes.devs.Link |
| 49 | + |
| 50 | +The `devs.Link` extends the `joint.shapes.standard.Link` and changes the link appearance. |
| 51 | + |
| 52 | +#### Example usage |
| 53 | + |
| 54 | + const shape = new joint.shapes.devs.Model({ |
| 55 | + position: { |
| 56 | + x: 100, |
| 57 | + y: 100 |
| 58 | + }, |
| 59 | + inPorts: ['in1', 'in2'], |
| 60 | + outPorts: ['out1', 'out2'] |
| 61 | + }); |
| 62 | + |
| 63 | + shape.addTo(graph); |
| 64 | + |
| 65 | + // adding/removing ports dynamically |
| 66 | + shape.addInPort('in3'); |
| 67 | + shape.removeOutPort('out1').addOutPort('out3'); |
| 68 | + |
| 69 | + const link = new joint.shapes.devs.Link({ |
| 70 | + source: { |
| 71 | + id: shape.id, |
| 72 | + port: 'out3' |
| 73 | + }, |
| 74 | + target: { |
| 75 | + x: 200, |
| 76 | + y: 300 |
| 77 | + } |
| 78 | + }); |
| 79 | + link.addTo(graph); |
| 80 | + |
| 81 | + // moving the input ports from `left` to `top` |
| 82 | + shape.changeInGroup({ position: 'top' }); |
| 83 | + // moving the output ports 'right' to 'bottom' |
| 84 | + shape.changeOutGroup({ position: 'bottom' }); |
| 85 | + |
| 86 | + |
| 87 | +#### Hierarchical diagrams |
| 88 | + |
| 89 | +There are two more shapes designed for hierarchical diagrams as part of the demo - `devs.Atomic` and `devs.Coupled`. They inherit from the `devs.Model` and differ only in the color and size. The purpose of these shapes is to enable you to implement a custom logic in your application based on their type. For instance a `devs.Coupled` can embed `devs.Atomic`'s but not the other way round as shown in the demo below. |
| 90 | + |
| 91 | +When working with hierarchical diagrams there is a few methods, that might come in handy. |
| 92 | + |
| 93 | +[`coupled.embed(atomic)`](https://resources.jointjs.com/docs/jointjs/v3.7/joint.html#dia.Element.prototype.embed) that can put the \`atomic\` shape into the \`coupled\`. |
| 94 | + |
| 95 | +[`coupled.fitToChildren()`](https://resources.jointjs.com/docs/jointjs/v3.7/joint.html#dia.Element.prototype.fitToChildren) that resizes the \`coupled\` shape such that all embedded elements are visually contained within it. |
| 96 | + |
| 97 | +[`link.reparent()`](https://resources.jointjs.com/docs/jointjs/v3.7/joint.html#dia.Link.prototype.reparent) that finds the best parent for the \`link\` based on the source and target element. |
0 commit comments