Skip to content

Commit 3f30041

Browse files
MaxTruphilippfromme
authored andcommitted
chore(api): update comments and README
1 parent fdc458d commit 3f30041

File tree

10 files changed

+52
-70
lines changed

10 files changed

+52
-70
lines changed

modeling-api/README.md

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
1-
# Modeling in bpmn-js using the API
1+
# bpmn-js Example: Modeling Using the Api
22

3-
This example builds a simple learning page to get started with modeling using the [bpmn-js](https://github.com/bpmn-io/bpmn-js) APIs.
3+
A step-by-step introduction to modeling using the API. You'll learn how create and edit shapes and connections.
44

5-
## About
5+
![Screenshot of the example](docs/screenshot.png "Screenshot of the example")
66

7-
The learning page built in this example includes various code snippets which show basic use cases of the modeling APIs.
8-
![Overview of the examples screenshot](docs/overview.png "Overview of the modeling via API example")
7+
## About This Example
98

10-
### APIs and concepts covered
9+
This example is built as a webpage that introduces you to the basics of working with bpmn-js' API, including:
1110

12-
In particular, the learning page covers:
11+
* creating and editing shapes and connections
12+
* editing the BPMN properties of an element
13+
* creating collaborations, participants and lanes
1314

14-
* `elementRegistry` a registry that keeps track of all shapes in a diagram
15-
* `elementFactory` a factory for [diagram-js](https://github.com/bpmn-io/diagram-js) shapes
16-
* `bpmnFactory` a factory for [bpmn-moddle](https://github.com/bpmn-io/bpmn-moddle) BPMN 2.0 XML element representations
17-
* `modeling` an API to perform BPMN 2.0 modeling operations
15+
## Running the Example
1816

19-
Using the learning page, you should get familiar with the these key APIs and concepts. However, this is not meant to be a full reference by any means. Therefore you are encouraged to use the learning page as a starting point and then continue with the various other resources:
20-
21-
* [Other examples](https://github.com/bpmn-io/bpmn-js-examples)
22-
* [Testing specification](https://github.com/bpmn-io/diagram-js/blob/develop/test/spec/core/ElementRegistrySpec.js) showing more `elementRegistry` methods
23-
* [Testing specification](https://github.com/bpmn-io/bpmn-js/blob/develop/test/spec/features/modeling/ElementFactorySpec.js) showing more `elementFactory` methods
24-
* [Testing specifications](https://github.com/bpmn-io/bpmn-js/tree/develop/test/spec/features/modeling) showing more `modeling` methods
25-
26-
## Running the example
27-
28-
Install all required dependencies:
17+
Install the dependencies:
2918

3019
```
3120
npm install
3221
```
3322

34-
Build and run the project in the browser
23+
Build and open the example in the browser:
24+
3525
```
36-
npm run dev
26+
npm start
3727
```
3828

3929
## License

modeling-api/app/snippets/businessObjects.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function fn(modeler) {
1414
* * ElementRegistry: A registry of all shapes and connections of the diagram.
1515
* * Modeling: The main module for modeling.
1616
*
17-
* We will use these modules to create a new shape and add it to the diagram, connect it to an
18-
* existing shape.
17+
* We will use these modules to create a new business object representing a shape,
18+
* add it to the diagram, and connect it to an existing shape.
1919
*/
2020

2121
// (1) Get the modules
@@ -38,7 +38,7 @@ function fn(modeler) {
3838
// (4) Create a new diagram shape using the business object you just created
3939
const task = elementFactory.createShape({ type: 'bpmn:Task', businessObject: taskBusinessObject });
4040

41-
// (4) Add the new task to the diagram
41+
// (5) Add the new task to the diagram
4242
modeling.createShape(task, { x: 400, y: 100 }, process);
4343

4444
// Using the `id` property we specified you can now access the new task through the element registry

modeling-api/app/snippets/collaborations.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ function fn(modeler) {
88
* * ElementRegistry: A registry of all shapes and connections of the diagram.
99
* * Modeling: The main module for modeling.
1010
*
11-
* We will use these modules to create a new shape and add it to the diagram, connect it to an
12-
* existing shape.
11+
* We will use these modules to create Participants, add them to the diagram (thereby
12+
* turning the process into a collaboration), create lanes and connect participants
13+
* using Message Flows.
1314
*/
1415

1516
// (1) Get the modules
@@ -30,19 +31,20 @@ function fn(modeler) {
3031
// The existing start event is now a child of the participant
3132
console.log(startEvent.parent); // Shape { "type": "bpmn:Participant", ... }
3233

33-
// (4) Create a lane
34+
// (5) Create a lane
3435
const lane = modeling.addLane(participant, 'bottom');
3536

36-
// (5) Create two nested lanes
37+
// (6) Create two nested lanes
3738
modeling.splitLane(lane, 2);
3839

39-
// (6) Create another participant shape that is collapsed
40-
const collapsedParticipant = elementFactory.createParticipantShape({ type: 'bpmn:Participant', isExpanded: false });
40+
// (7) Create another participant shape that is collapsed
41+
const collapsedParticipant = elementFactory
42+
.createParticipantShape({ type: 'bpmn:Participant', isExpanded: false });
4143

42-
// (7) Add the participant to the diagram
44+
// (8) Add the participant to the diagram
4345
modeling.createShape(collapsedParticipant, { x: 300, y: 500 }, process);
4446

45-
// (8) Connect the two participants through a message flow
47+
// (9) Connect the two participants through a message flow
4648
modeling.connect(collapsedParticipant, participant);
4749
}
4850

modeling-api/app/snippets/connectingShapes.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function fn(modeler) {
77
* * ElementFactory: Creates new shapes and connections.
88
* * ElementRegistry: A registry of all shapes and connections of the diagram.
99
* * Modeling: The main module for modeling.
10+
*
11+
* We will use these modules to create shapes and connect them on two different ways.
1012
*/
1113

1214
// (1) Get the modules
@@ -27,13 +29,13 @@ function fn(modeler) {
2729
// (5) Connect the existing start event to new task using `connect`
2830
modeling.connect(startEvent, task);
2931

30-
// (3) Create a end event shape
32+
// (6) Create a end event shape
3133
const endEvent = elementFactory.createShape({ type: 'bpmn:EndEvent' });
3234

33-
// (4) Add the new end event shape to the diagram
35+
// (7) Add the new end event shape to the diagram
3436
modeling.createShape(endEvent, { x: 600, y: 100 }, process);
3537

36-
// (5) Create a new sequence flow connection that connects the task to the end event
38+
// (8) Create a new sequence flow connection that connects the task to the end event
3739
modeling.createConnection(task, endEvent, { type: 'bpmn:SequenceFlow' }, process);
3840
}
3941

@@ -42,4 +44,4 @@ export default {
4244
name: 'Connecting Shapes',
4345
description: 'Various ways of connecting shapes.',
4446
fn
45-
}
47+
};

modeling-api/app/snippets/creatingShapes.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ function fn(modeler) {
88
* * ElementFactory: Creates new shapes and connections.
99
* * ElementRegistry: A registry of all shapes and connections of the diagram.
1010
* * Modeling: The main module for modeling.
11+
*
12+
* We will use these modules to create some more shapes including a BoundaryEvent and
13+
* a SubProcess.
1114
*/
1215

1316
// (1) Get the modules
@@ -33,39 +36,40 @@ function fn(modeler) {
3336
// (6) Add the new boundary event to the diagram attaching it to the service task
3437
modeling.createShape(boundaryEvent, { x: 400, y: 140 }, serviceTask, { attach: true });
3538

36-
// (7) Create an event sub process
39+
// (7) Create an event sub process business object
3740
const eventSubProcessBusinessObject = bpmnFactory.create('bpmn:SubProcess', {
3841
triggeredByEvent: true,
3942
isExpanded: true
4043
});
4144

45+
// (8) Create the SubProcess shape, set the previously created event sub process business object
4246
const eventSubProcess = elementFactory.createShape({
4347
type: 'bpmn:SubProcess',
4448
businessObject: eventSubProcessBusinessObject,
4549
isExpanded: true
4650
});
4751

48-
// (8) Add the event sub process
52+
// (9) Add the event sub process to the diagram
4953
modeling.createShape(eventSubProcess, { x: 300, y: 400 }, process);
5054

51-
// (9) Create a timer start event specifying `eventDefinitionType` so an event definition will
55+
// (10) Create a timer start event specifying `eventDefinitionType` so an event definition will
5256
// be added
5357
const timerStartEvent = elementFactory.createShape({
5458
type: 'bpmn:StartEvent',
5559
eventDefinitionType: 'bpmn:TimerEventDefinition'
5660
});
5761

58-
// (10) Add the new timer start event to the diagram specifying the event sub process as the target
62+
// (11) Add the new timer start event to the diagram specifying the event sub process as the target
5963
// so the event will be a child of it
6064
modeling.createShape(timerStartEvent, { x: 200, y: 400 }, eventSubProcess);
6165

62-
// (11) Finally, create a new group shape specifying width and height
66+
// (12) Finally, create a new group shape specifying width and height
6367
const group = elementFactory.createShape({ type: 'bpmn:Group', width: 400, height: 200 });
6468

65-
// (12) Add the new group to the diagram
69+
// (13) Add the new group to the diagram
6670
modeling.createShape(group, { x: 325, y: 100 }, process);
6771

68-
// (13) Create multiple elements at once specifying x and y which will be treated as relative
72+
// (14) Create two shapes specifying x and y which will be treated as relative
6973
// coordinates, not absolute
7074
const messageStartEvent = elementFactory.createShape({
7175
type: 'bpmn:StartEvent',
@@ -80,6 +84,7 @@ function fn(modeler) {
8084
y: 0
8185
});
8286

87+
// (15) Add multiple shapes to the diagram
8388
modeling.createElements([ messageStartEvent, userTask ], { x: 300, y: 600 }, process);
8489
}
8590

modeling-api/app/snippets/editingElements.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ function fn(modeler) {
1010
* * ElementRegistry: A registry of all shapes and connections of the diagram.
1111
* * Modeling: The main module for modeling.
1212
*
13-
* We will use these modules to create a new shape and add it to the diagram, connect it to an
14-
* existing shape.
13+
* We will use these modules to update the properties of two existing shapes.
1514
*/
16-
15+
1716
// (1) Get the modules
1817
const bpmnFactory = modeler.get('bpmnFactory'),
1918
elementRegistry = modeler.get('elementRegistry'),
@@ -33,7 +32,7 @@ function fn(modeler) {
3332
default: sequenceFlow.businessObject
3433
});
3534

36-
// (5) Make a task multi-instance
35+
// (5) Change a task to be multi-instance
3736
const multiInstanceLoopCharacteristics = bpmnFactory.create('bpmn:MultiInstanceLoopCharacteristics');
3837

3938
modeling.updateProperties(task, {
@@ -47,4 +46,4 @@ export default {
4746
description: 'How to edit existing elements.',
4847
diagram,
4948
fn
50-
}
49+
};

modeling-api/app/snippets/introduction.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ function fn(modeler) {
99
* * ElementRegistry: A registry of all shapes and connections of the diagram.
1010
* * Modeling: The main module for modeling.
1111
*
12-
* We will use these modules to create a new shape and add it to the diagram, connect it to an
13-
* existing shape.
12+
* We will use these modules to create a new shape, add it to the diagram, and
13+
* connect it to an existing shape.
1414
*/
15-
15+
1616
// (1) Get the modules
1717
const elementFactory = modeler.get('elementFactory'),
1818
elementRegistry = modeler.get('elementRegistry'),
@@ -40,4 +40,4 @@ export default {
4040
name: 'Introduction',
4141
description: 'An introduction to the modules of bpmn-js that can be used to create and connect shapes.',
4242
fn
43-
}
43+
};

modeling-api/docs/overview.png

-357 KB
Binary file not shown.

modeling-api/docs/screenshot.png

232 KB
Loading

modeling-api/index.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)