Skip to content

Commit 7a31f82

Browse files
authored
#1701 Elyra Canvas Documentation using mkdocs (#1702)
1 parent c20f637 commit 7a31f82

40 files changed

+6229
-1
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- main
6+
permissions:
7+
contents: write
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: 3.x
16+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
17+
- uses: actions/cache@v4
18+
with:
19+
key: mkdocs-material-${{ env.cache_id }}
20+
path: .cache
21+
restore-keys: |
22+
mkdocs-material-
23+
- run: pip install mkdocs-material
24+
- run: mkdocs gh-deploy --force

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ build/Release
4747
# Dependency directory
4848
node_modules
4949

50+
# Site folder generated by mkdocs-deploy
51+
site
52+
5053
config/app-local.json
5154

5255
/public/build/*

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ npm install -g grunt-cli sass
3737
```
3838
In your application's package.json replace
3939
```
40-
"@elyra/canvas": "<verson>"
40+
"@elyra/canvas": "<version>"
4141
```
4242
with
4343
```
@@ -50,3 +50,19 @@ Delete @elyra/canvas from node_modules of your application
5050
# Run npm install to get local copy of common-canvas and/or common-properties
5151
npm install
5252
```
53+
54+
### Contribute to the Elyra Canvas documentation (mkdocs)
55+
1. Python v3 needs to be available.
56+
2. Go to canvas directory.
57+
58+
3. Install required mkdocs packages using pip3.
59+
```
60+
pip3 install -r requirements.txt`
61+
```
62+
63+
4. Run below command to start mkdocs server.
64+
```
65+
mkdocs serve
66+
```
67+
68+
5. When complete, open the browser: http://127.0.0.1:8000/
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
## Introduction
2+
Common canvas displays a flow of data operations as nodes and links which the user can create and edit to get the flow they want. These visual flows of data operations are translated into data processing steps performed by a back-end server. Common canvas provides functionality for the visual display of flows in the browser and leaves persistence and execution of data flows to the application.
3+
Within common canvas the user can perform operations such as:
4+
5+
* Create a new node by dragging a node definition from a palette onto the canvas.
6+
* Create a new node by dragging a node from outside the canvas onto the canvas (you'll have to do some programming to get this to work).
7+
* Delete a node by clicking a context menu option.
8+
* Create a link by dragging a line from one node to another.
9+
* Delete a link by clicking a context menu option.
10+
* Add a comment to the canvas and draw a link from it to one or more nodes.
11+
* Edit a comment.
12+
* Move nodes and comments around in the canvas to get the desired arrangement.
13+
* And more! ...
14+
15+
# Architecture
16+
17+
## Common Canvas react object
18+
Common-canvas is a react component that can be used in your react application to display a fully-functional canvas user interface including the function mentioned above. The `<CommonCanvas>` component is displayed in a `<div>` provided by your application.
19+
20+
Common-canvas has these constituent parts that are visible to the user:
21+
22+
* [Canvas editor](2.0.1-Canvas-Editor.md) - the main area of the UI where the flow is displayed and edited
23+
* [Palette](2.0.2-Palette.md) - a set of node templates that can be dragged to the canvas to create new nodes
24+
* [Context menu](2.0.3-Context-Menu.md) - a menu of options for nodes, comments, etc
25+
* [Context toolbar](2.0.4-Context-Toolbar.md) - a menu of options for nodes, comments, etc presented as a small toolbar
26+
* Toolbar - a set of tools across the top of the UI
27+
* Notification panel - a panel for displaying runtime and other messages to your user
28+
* Right side flyout - a panel, often used to display node properties
29+
* Top panel - a panel which can be used to display other app related information
30+
* Bottom panel - a panel which can be used to display other app related information
31+
32+
and it handles:
33+
34+
1. the visual display of the flow of operations;
35+
2. any user gestures on the canvas;
36+
3. display of context menus;
37+
4. display and handling of the palette.
38+
5. provision of callbacks to tell your code what operations the user is performing on the canvas
39+
6. and much much more.
40+
41+
## Canvas Controller
42+
43+
The only mandatory parameter for the `<CommonCanvas>` component is a regular JavaScript object called the [CanvasController](2.4-Canvas-Controller-API.md).
44+
45+
The CanvasController routes handles calls from the host application and actions performed by the user. It then updates the internal object model which stores:
46+
47+
1. the data that describes the flow of nodes, links and comments (called a pipelineFlow);
48+
2. the data that describes the definition of the palette which contains node templates that can dragged to add nodes to the canvas;
49+
3. the set of currently selected objects.
50+
4. notification messages
51+
5. breadcrumbs that indicate which sub-flow is being viewed
52+
6. layout information
53+
54+
The [CanvasController](2.4-Canvas-Controller-API.md) provides an API which allows your code to:
55+
56+
1. set a new pipelineFlow;
57+
2. get the current pipelineFlow (after the user has edited it);
58+
3. update and edit objects in the canvas (for example, add node, delete link etc.);
59+
4. set the node definition data (for display of nodes in the palette)
60+
61+
# Getting started with common canvas programming
62+
63+
## Hello Canvas!
64+
You can start by looking at these two 'hello world' examples for using common canvas:
65+
66+
* This first one called [app-tiny.js](https://github.com/elyra-ai/canvas/blob/master/canvas_modules/harness/src/client/app-tiny.js) has the bare minimum necessary to get a fully functioning common-canvas to appear including all the basic functionality, a palette and a flow of nodes and links.
67+
* The second, called [app-small.js](https://github.com/elyra-ai/canvas/blob/master/canvas_modules/harness/src/client/app-small.js), shows many of the options available to a common-canvas developer such as configurations and callback handlers.
68+
69+
You can also look at the [App.js](https://github.com/elyra-ai/canvas/blob/49ed634e3353d8f5c58eb8409ed8e1009f19c87a/canvas_modules/harness/src/client/App.js) file in the test harness section of this repo to see examples of code that uses the common canvas component.
70+
71+
Now let's walk through the different steps to get common-canvas working:
72+
73+
74+
## Step 1 : Install Elyra Canvas NPM module
75+
76+
Enter:
77+
```
78+
npm install @elyra/canvas
79+
```
80+
81+
## Step 2 : Import Common-canvas
82+
83+
To use common canvas in your react application you need to do the following. First import the CommonCanvas react component and CanvasController class from the Elyra Canvas library. Elyra Canvas produces both `esm` and `cjs` outputs. By default `esm` will be used when webpack is used to build the consuming application.
84+
85+
**All Components**
86+
```js
87+
import { CommonCanvas, CanvasController } from "@elyra/canvas";
88+
```
89+
**Canvas only**
90+
91+
To import only canvas functionality in `cjs` format use:
92+
```js
93+
import { CommonCanvas, CanvasController } from "@elyra/canvas/dist/lib/canvas";
94+
```
95+
96+
In addition you'll need to import `<IntlProvider>` from the `react-intl` library.
97+
```js
98+
import { IntlProvider } from "react-intl";
99+
```
100+
101+
102+
## Step 3 : Create an instance of the canvas controller
103+
To control the canvas you'll need an instance of the canvas controller so create an instance of it like this (probably in the constructor of your object).
104+
```js
105+
this.canvasController = new CanvasController();
106+
```
107+
## Step 4 : Set the palette data
108+
Next you'll need to populate the palette data. This will specify the nodes (split into categories) that will appear in the palette. The user can drag them from the palette to build their flow. This is done by calling CanvasController with:
109+
```js
110+
this.canvasController.setPipelineFlowPalette(pipelineFlowPalette);
111+
```
112+
The pipelineFlowPalette object should conform to the JSON schema found here:
113+
https://github.com/elyra-ai/pipeline-schemas/tree/master/common-canvas/palette
114+
115+
Some examples of palette JSON files can be found here:
116+
https://github.com/elyra-ai/canvas/tree/master/canvas_modules/harness/test_resources/palettes
117+
118+
## Step 5 : (Optional) Set the flow data
119+
This is an optional step. If you want a previously saved flow to be shown in the canvas editor so the user can start to edit it, you will need to call the CanvasController with:
120+
```js
121+
this.canvasController.setPipelineFlow(pipelineFlow);
122+
```
123+
124+
The pipelineFlow object should conform to the JSON schema found here:
125+
https://github.com/elyra-ai/pipeline-schemas/tree/master/common-pipeline/pipeline-flow
126+
127+
Some examples of pipeline flow JSON files can be found here:
128+
https://github.com/elyra-ai/canvas/tree/master/canvas_modules/harness/test_resources/diagrams
129+
130+
## Step 6 : Pull in the CSS
131+
Check this section to find info on what CSS to include in your application's CSS. [Styling](4.0-Styling.md).
132+
133+
## Step 7 : Display the canvas
134+
135+
Finally you'll need to display the canvas object inside an `<IntlProvider>` object. Inside your render code, add the following:
136+
```html
137+
<div>
138+
<IntlProvider>
139+
<CommonCanvas canvasController={this.canvasController} />
140+
</IntlProvider>
141+
</div>
142+
```
143+
The div should have the dimensions you want for your canvas to display in your page. For the canvasController property, pass the instance of canvas controller you created earlier. This is the only mandatory property. After providing this and running your code you will have a fully functioning canvas including: a palette; default toolbar; context menus; direct manipulation (move and resize) etc. To customize these behaviors and presentation continue with the sections below.
144+
145+
## Common Canvas customization
146+
If you want to customize the behavior of common canvas you can specify any combination of the following optional settings:
147+
```html
148+
<div>
149+
<CommonCanvas
150+
canvasController={this.canvasController}
151+
152+
config={this.commonCanvasConfig}
153+
toolbarConfig={this.toolbarConfig}
154+
notificationConfig={this.notificationConfig}
155+
contextMenuConfig={this.contextMenuConfig}
156+
keyboardConfig={this.keyboardConfig}
157+
158+
contextMenuHandler={this.contextMenuHandler}
159+
beforeEditActionHandler={this.beforeEditActionHandler}
160+
editActionHandler={this.editActionHandler}
161+
clickActionHandler={this.clickActionHandler}
162+
decorationActionHandler={this.decorationActionHandler}
163+
layoutHandler={this.layoutHandler}
164+
tipHandler={this.tipHandler}
165+
idGeneratorHandler={this.idGeneratorHandler}
166+
selectionChangeHandler={this.selectionChangeHandler}
167+
actionLabelHandler={this.actionLabelHandler}
168+
169+
showRightFlyout={showRightFlyout}
170+
rightFlyoutContent={rightFlyoutContent}
171+
172+
showBottomPanel={showBottomPanel}
173+
bottomPanelContent={bottomPanelContent}
174+
175+
showTopPanel={showTopPanel}
176+
topPanelContent={topPanelContent}
177+
>
178+
</CommonCanvas>
179+
</div>
180+
```
181+
182+
### Config objects
183+
Common canvas has five **optional** configuration objects: config, toolbarConfig, notificationConfig, contextMenuConfig and keyboardConfig.
184+
They are documented here:
185+
[Config Objects](2.1-Config-Objects.md)
186+
187+
### Handlers
188+
There are several **optional** handlers implemented as callback functions. They are contextMenuHandler, editActionHandler, beforeEditActionHandler, clickActionHandler, decorationActionHandler, layoutHandler, tipHandler, idGeneratorHandler, selectionChangeHandler and actionLabelHandler. They are documented here:
189+
[Common Canvas Callback](2.2-Common-Canvas-callbacks.md)
190+
191+
### Right-flyout panel parameters
192+
The right flyout panel appears on the right of the canvas area. You can add whatever content you like to this panel. Typically, it is used to display properties of nodes on the canvas. There are two **optional** parameters to let you manage the right flyout panel These are:
193+
194+
- showRightFlyout: This can be true or false to indicate whether the flyout panel is shown or not. The default is false.
195+
- rightFlyoutContent: content to display in the right flyout which is a JSX object. Nothing is displayed by default.
196+
197+
### Bottom panel parameters
198+
The bottom panel appears below the canvas area and between the palette and the right flyout panel. You can add whatever content you like to this panel. There are two **optional** parameters to let you manage the bottom panel. These are:
199+
200+
- showBottomPanel: This can be true or false to indicate whether the bottom panel is shown or not. The default is false.
201+
- bottomPanelContent: content to display in the bottom panel which is a JSX object. Nothing is displayed by default.
202+
203+
### Top panel parameters
204+
The top panel appears below the toolbar and between the palette and the right flyout panel. You can add whatever content you like to this panel. There are two **optional** parameters to let you manage the top panel. These are:
205+
206+
- showTopPanel: This can be true or false to indicate whether the top panel is shown or not. The default is false.
207+
- topPanelContent: content to display in the top panel which is a JSX object. Nothing is displayed by default.
208+
209+
### Localization
210+
You can customize `<CommonCanvas>` using the `<IntlProvider>` object to [display translated test](#localization)
211+
212+
## Creating nodes on the canvas
213+
214+
Nodes can be created on the canvas by the user in two ways:
215+
216+
* By dragging a node from the palette onto the canvas background
217+
* By dragging a node from outside the canvas
218+
219+
The first technique is provided by Common canvas. The second requires some development work which is documented here:
220+
[Enabling node creation from external object](2.3-Enabling-node-creation-from-external-object.md)
221+
222+
223+
## Keyboard support
224+
225+
Common canvas supports a number of keyboard interactions as follows:
226+
227+
|Keyboard Shortcut|Action|Description|
228+
|---|---|---|
229+
|Ctrl/Cmnd + a|selectAll|Select All objects
230+
|delete|deleteSelectedObjects|Delete currently selected objects|
231+
|Ctrl/Cmnd + x|cut|Cut selected objects to the clipboard|
232+
|Ctrl/Cmnd + c|copy|Copy selected objects to the clipboard|
233+
|Ctrl/Cmnd + v|paste|Paste objects from the clipboard. If the mouse cursor is over <br>the canvas, objects will be pasted at the cursor position or, <br>if not, at a default position|
234+
|Ctrl/Cmnd + z|undo|Undo last command|
235+
|Ctrl/Cmnd + Shift + z|redo|Redo last undone command|
236+
|Ctrl/Cmnd + y|redo|Redo last undone command|
237+
238+
239+
Your application can disable any or all of these actions by providing the [keyboard config object](2.1-Config-Objects.md#keyboard-config-object) to the CommonCanvas react component.
240+
241+
When any of the shortcut keys are pressed the common-canvas object model will be updated and then the [editActionHandler](2.2-Common-Canvas-callbacks.md#editactionhandler) callback will be called with the `data.editType` parameter set to the action above and the `data.editSource` parameter set to "keyboard".

docs/2.0.1-Canvas-Editor.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The Canvas Editor displays the flow to the user and allows the user to interact with the flow using the mouse/trackpad and the keyboard.
2+
3+
The editor displays the following object types which the user can interact with:
4+
5+
## Nodes
6+
## Links
7+
## Comments
8+
## The Canvas background
9+
10+
11+
[Still under construction]

docs/2.0.1.1-Nodes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Under construction]

0 commit comments

Comments
 (0)