Skip to content

Commit 43964c4

Browse files
khknoppRam81
authored andcommitted
Update UIdocumentation.md (#497)
* Updated UIdocumentation.md * Update UIDocumentation.md * Update UIDocumentation.md * Update UIDocumentation.md * Update UIDocumentation.md * Update UIDocumentation.md
1 parent 0c41f7a commit 43964c4

File tree

1 file changed

+193
-141
lines changed

1 file changed

+193
-141
lines changed

docs/source/UIDocumentation.md

+193-141
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,212 @@
1-
Frontend Design
2-
=======
3-
### Architecture
4-
```app.js``` hosts the main app and calls ```content.js```, which loads up the main app. This file contains a few functions:
5-
### ```content.js```
6-
(The top most bullet contains the name of the method and the inner bullets are params.)
7-
* ```openModal```
8-
* ```closeModal```
9-
* ```addNewLayer``` - invoked by ```handleClick``` and passed in a JS object with layer information.
10-
* layer
1+
Frontend Design
2+
========
3+
## Architecture
4+
(All javascript files described here can be found in the /ide/static/js/ directory of Fabrik)
5+
6+
#### ```addCommentModal.js```
7+
(The bullets contain methods specific to the file along with their explanations.)
8+
9+
```addCommentModal.js``` is responsible for adding comments into the interface. It has the following methods:
10+
* ```handleClick``` - invoked on click on modal
11+
* ```addComment``` - adds comment modal to RTC
12+
13+
***
14+
15+
#### ```app.js```
16+
```app.js``` hosts the main app, but contains nothing else than a call for ```content.js```.
17+
***
18+
19+
#### ```canvas.js```
20+
```content.js``` invokes an instance of ```canvas.js``` that contains the following methods:
21+
* ```clickLayerEvent``` - invoked on a click of a layer or on drag of that layer
22+
* ```hoverLayerEvent``` - invoked on a hover
23+
* ```scrollCanvas``` - scrolls canvas
24+
* ```clickCanvas``` - invoked on click
25+
* ```updateLayerPosition``` - changes layer positon based on event
26+
* ```mouseUpEvent``` - invoked when mouse key is up
27+
* ```connectionEvent``` - invoked on connection; checks for cycles and modifies layers
28+
* ```detachConnectionEvent``` - modifies layers
29+
* ```drop``` - invoked on layer drop onto canvas; checks for errors
30+
31+
```canvas.js``` also contains the code that decides whether a node's line needs to be rerouted if it is cutting through another node.
32+
33+
#### ```canvas.js```'s visualisation algorithm
34+
The method it uses is the following:
35+
```checkIfCuttingLine``` takes in 2 variables: net and pos, where net has an array of all the nodes, and pos is an array of x and y coordinates checked by this method to see whether a line will cut through.
36+
To put it more specifically, ```checkIfCuttingLine``` checks if the line formed with the coordinates in the positional block will cut through any other nodes between them.
37+
38+
```checkIfCuttingLine``` creates an equation from the x and y points by calculating the slope and using point slope form.
39+
40+
After this, it calls ```getBetween``` to get the nodes between the x and y coordinates of the created line.
41+
42+
The ```getBetween``` also serves the purpose of returning which direction the majority of the blocks between are. This implementation is purely for performance, otherwise it would be seperated into a seperate function.
43+
44+
After ```getBetween``` returns the IDs of the nodes between the x and y coordinate pair, it is checked if the cutting line loops through them (to see whether or not the resulting line will cut through the in between node).
45+
46+
If it does cut through, ```getBetween``` will return the direction the line needs to be shifted to the parent function, ```checkCutting```, to iterate once again 80 pixels to either the left or right (depending on the return.)
47+
48+
*This algorithmic design creates the possibility of an infinite loop if the canvas has been completely occupied and there is no more space remaining.*
49+
50+
***
51+
52+
#### ```commentSidebar.js```
53+
Is responsible for creating the comment sidebar. Consists of:
54+
* ```close``` - closes sidebar
55+
* ```addComment``` - adds comment
56+
57+
***
58+
59+
#### ```commentTooltip.js```
60+
Is responsible for creating the comment dialog box. Consists of:
61+
* ```handleClick``` - handles user click event
62+
* ```addComment``` - adds comment to RTC
63+
64+
***
65+
66+
#### ```content.js```
67+
```content.js``` is the most important file, as it loads the main app. Here are some of its important methods:
68+
* ```openModal``` - opens modals (such as "Help" or "About Us")
69+
* ```closeModal``` - closes previously opened modals
70+
* ```infoModal``` - sets info about infoModal state, and then opens that modal
71+
* ```faqModal``` - sets info about faqModal state, and then opens that modal
72+
* ```zooModal``` - imports and opens zooModal
73+
* ```addNewLayer``` - invoked by ```handleClick``` and passed in a JS object with layer information - adds a layer
1174
* ```changeSelectedLayer``` - changes which layer has the selected class on it, which outlines layer to emphasize a "selection"
12-
* layerId
1375
* ```changeHoveredLayer``` - changes which layer has the hover class on it, which outlines layer to emphasize a "hover"
14-
* layerId
15-
* ```modifyLayer``` - modifies layer, passed in layer is the new layer, and layer id is the id it needs to be replaced at.
16-
* layer
17-
* layerId
18-
* ```modifyLayerParams``` - modify layer params based on layer and layerId, invoked by setParams
19-
* layer
20-
* layerId
21-
* ```deleteLayer``` - deletes layers and removes inputs and outputs for it.
22-
* layerId
23-
* ```updateParameters``` - sums total amount of parameters and updates layer's parameters
24-
* layer
25-
* net
26-
* ```calculateParameters``` - loops through net and invokes ```updateParameters```
27-
* net
76+
* ```addHighlightOnLayer``` - highlights layer by ```layerId```
77+
* ```modifyLayer``` - modifies layer, passed in layer is the new layer, and layer id is the id it needs to be replaced at.
78+
* ```deleteLayer``` - deletes layers and removes inputs and outputs for it.
79+
* ```getLayerParameters``` - sums total amount of parameters and updates layer's parameters
80+
* ```calculateParameters``` - loops through net and invokes ```getLayerParameters```
81+
* ```adjustParameters``` - used to adjust layer parameters based on layer, change is passed in.
82+
* ```modifyLayerParams``` - modifies layer params based on layer and layerId, invoked by SetParams
2883
* ```loadLayerShapes``` - AJAXs to backend to model parameters
2984
* ```exportNet``` - AJAXs to backend and then passes back error/success
30-
* framework
85+
* ```exportPrep``` - invoked by ```exportNet```; preprocessed model object for export
3186
* ```importNet``` - AJAXs to backend and then passes back error/success
32-
* framework
33-
* id
3487
* ```initialiseImportedNet``` - starts prepping layer to be displayed by Fabrik, positions layers
35-
* net
36-
* net_name
37-
* ```changeNetName``` - invoked on the event of net name changed
38-
* event
39-
* ```adjustParameters``` - used to adjust layer parameters based on layer, change is passed in.
40-
* layer
41-
* para
42-
* value
43-
* ```changeNetStatus``` - changes boolean for rebuilding.
44-
* bool
45-
* ```changeNetPhase```
46-
* phase
47-
* ```dismissError```
48-
* errorIndex
49-
* ```addError```
50-
* errorText
51-
* ```dismissAllErrors```
52-
* ```copyTrain``` - copy's train net for test
53-
* ```trainOnly```
54-
* ```saveDb```
55-
* ```loadDb```
56-
* id
57-
* ```infoModal``` - sets info into state, and then open's modal
58-
* ```toggleSidebar```
59-
* ```zooModal```
60-
* ```handleClick``` - handles a click based on an event handles connections and adding layers.
61-
* event
62-
### ```canvas.js```
63-
```content.js``` invokes an instance of ```canvas.js``` that contains the following methods and params:
64-
* ```allowDrop```
65-
* event
66-
* ```clickLayerEvent``` - invoked on a click of a layer, invokes ```setParams.js```
67-
* event
68-
* layerId
69-
* ```hoverLayerEvent``` - invoked on a hover
70-
* event
71-
* layerId
72-
* ```scrollCanvas```
73-
* ```clickCanvas```
74-
* event
75-
* ```updateLayerPosition``` - changes layers positon based on event
76-
* event
77-
* ```connectionEvent``` - invoked on connection, checks for cycles and modifies layers.
78-
* connInfo
79-
* originalEvent
80-
* ```detachConnectionEvent``` - modifies layers
81-
* connInfo
82-
* originalEvent
83-
* ```drop```
84-
* event
85-
```canvas.js``` also contains the code that decides whether a node's line needs to be rerouted if it is cutting through another node.
86-
### ```canvas.js```'s placement algorithm
87-
The method it uses is the following:
88-
```checkIfCuttingLine``` is passed in a positional block that includes x and y coordinates (it assumes a px is at the end of each x and y) for each endpoint of the line it is checking.
89-
Specifically, it is checking if the line formed with the coordinates in the positional block will cut into any other nodes between them.
88+
* ```changeNetName``` - invoked after user starts typing in name box (placed above the model in the UI); changes the name of the net
89+
* ```changeNetStatus``` - takes in a boolean and changes its value (the boolean is responsible for the ```rebuildNet``` element)
90+
* ```changeNetPhase``` - changes the phase of the net (Train/Test)
91+
* ```copyTrain``` - copies the nets train phase for the test phase
92+
* ```copyTrain``` - copies the nets train option for the test option
93+
* ```trainOnly``` - mehod responsible for Train-only models
94+
* ```saveDb``` - creates RTC hyperlink
95+
* ```loadDb``` - loads model for RTC by ```id```
96+
* ```performSharedUpdate``` - updates RTC shared model using sockets
97+
* ```performSharedAdd``` - adds shared layer in RTC
98+
* ```performSharedDelete``` - deletes shared layer in RTC
99+
* ```addSharedComment``` - adds comment shared in RTC
100+
* ```toggleSidebar``` - toggles the visibilty of the sidebar
101+
* ```handleClick``` - handles a click based on an event: handles connections and adding layers.
90102

91-
```checkIfCuttingLine``` creates then creates an equation from the x and y points by calculating the slope and using point slope form.
103+
***
92104

93-
After this, it calls ```getBetween``` to get the nodes between the x and y coordinates of the created line.
105+
#### ```data.js```
106+
```data.js``` contains various different variables filled with data used throughout the application, it stores the layers
94107

95-
The ```getBetween``` also serves the purpose of returning which direction in which the majority of the blocks between are. This is purely for performance, otherwise it would be seperated into a seperate function.
108+
***
109+
#### ```error.js```
110+
```error.js``` contains Error React Component with two methods:
111+
* ```dismissError``` - dismisses opened error
112+
The error is passed in through props and then displayed to the user.
96113

97-
After ```getBetween``` returns with the id's of the nodes are between the x and y coordinate pair, check if cutting line loops through them to check whether or not the resultant line will cut through the in between node.
114+
***
98115

99-
If it does, it will return the direction the line needs to be shifted to the parent function, ```checkIfCuttingNet```, to iterate once again 80 pixels to either the left or right (depending on the return.)
116+
#### ```field.js```
117+
```field.js``` contains the various fields used by the layer editor.
118+
* ```change``` - used to change the state of checkboxes; it is passed in event e.
100119

101-
*This algorithmic design creates the possibility of an infinite loop if the canvas has been completely occupied and there is no more space remaining.*
120+
***
102121

103-
### ```topbar.js```
104-
```topbar.js``` has no methods. It is invoked by ```content.js``` to show the top section of the sidebar.
105-
### ```panZoom.js```
106-
```panZoom.js``` includes the functions that zoom the canvas in and out, based on various invocations.
107-
### ```pane.js```
108-
```pane.js``` contains one method:
109-
* toggleClass
110-
```pane.js``` invokes ```paneElement.js``` to render out each element.
111-
```toggleClass``` toggles classes for the dropdown on the sidebar for layer selection.
112-
### ```paneElement.js```
113-
```paneElement.js``` renders out each element of the pane, it is invoked by ```pane.js```
114-
```pane.js``` renders out all of the layers for selection by the user.
115-
### ```tabs.js```
116-
```tabs.js``` contains no methods and is used to switch between Train and Test layers.
117-
### ```layer.js```
118-
```layer.js``` contains no methods. It is invoked by the ```canvas.js``` and it displays the actual layering on the jsplumb container. The position of each layer is set in the state of the layer.
119-
### ```jsplumb.js```
120-
The ```jsplumb.js``` file contains code that handles the arrangement and the dragging/connecting of the layers. A new custom connector is created. There is an if function to check whether the node it is connecting is needing to be routed through an extension. A global variable stores this information, and the actual calculation is handled in ```checkIfCuttingNet``` and ```checkIfCuttingLine```. The global variable contains the amount of pixels it needs to move over, and it will contain direction it needs to go in (based on whether it is positive or
121-
negative.)
122-
123-
Please refer to the jsplumb documentation here to learn more about this API set. https://jsplumbtoolkit.com/docs.html
124-
### ```data.js```
125-
```data.js``` contains various different variables filled with data used throughout the application.
126-
### ```error.js```
127-
```error.js``` contains Error React Component with one method:
128-
* dismissError
129-
The error is passed in through props and then displayed to the user.
130-
### ```field.js```
131-
```field.js``` contains the various different fields used by the layer editor.
132-
* ```change```
133-
* e
122+
#### ```filterBar.js```
123+
This file filters layers based on framework. It uses two methods:
124+
* ```changeEvent``` - filters the layers
125+
126+
***
127+
128+
#### ```importTextbox.js```
129+
Renders the 'Load Model From Text Input' textbox (available in the top of the main sidebar).
130+
131+
***
132+
133+
#### ```jsplumb.js```
134+
The ```jsplumb.js``` file contains code that handles the arrangement and the dragging/connecting of layers. The file hosts a function, which created the arrow connector(```ArrowConnector```). Later, there is a function (```this._compute```), which draws the elements. It is responsible for creating the connectors and simultaneously checks if there isn't any cutting and if extending the connector isn't neccessary. It then creates the connectors segments and styles it appropriately. Then, in ```instance.addLayerEndpoints``` the anchors of the connector are defined.
135+
136+
Please refer to the jsplumb documentation here to learn more about this API set: https://jsplumbtoolkit.com/docs.html
134137

135-
The method change is used to change the state of checkboxes, and it is passed in event e.
136-
### ```modelElement.js```
138+
***
139+
140+
#### ```layer.js```
141+
```layer.js``` is invoked by ```canvas.js``` and it displays the actual layering on the jsplumb container. The position of each layer is set in the state of the layer. Its methods are:
142+
* ```onCloseCommentModal``` - closes comment modal
143+
* ```onAddComment``` - opens comment tooltip
144+
* ```doSharedUpdate``` - shares comment in RTC
145+
146+
***
147+
148+
#### ```login.js```
149+
```login.js``` is responsible for the login dialog in Fabrik. First it uses AJAX to process it and later renders the login dialog.
150+
151+
***
152+
153+
#### ```modelElement.js```
137154
```modelElement.js``` contains the component that renders out each model in the model zoo. It includes logic that onClick will trigger an importNet, as defined in ```content.js```.
138-
### ```modelZoo.js```
139-
```modelZoo.js``` contains the rendering of the modelZoo, it invokes modelElement to render the actual listing of the model.
140-
### ```netLayout_vertical.js``` and ```netLayout.js```
155+
***
156+
#### ```modelZoo.js```
157+
```modelZoo.js``` contains the rendering of the modelZoo, it invokes modelElement to render the actual listing of the model. Methods:
158+
159+
***
160+
161+
#### ```netLayout_vertical.js``` and ```netLayout.js```
141162
Both of these files contain code that determines positioning and layout of net. It is invoked by ```content.js```
142-
### ```setParams.js```
143-
Contains the following methods:
144-
* ```changeProps```
145-
* prop
146-
* value
147-
* ```changeParams```
148-
* para
149-
* value
150-
* ```close```
151-
* ```trainOnly```
152-
* e
153-
154-
### ```setParams.js```
155-
allows users to change layer parameters and reads paramters through ```data.js```
156-
### ```tooltip.js``` and ```tooltipData.js```
163+
164+
#### ```netLayout_vertical.js```
165+
Defines the vertical alignment of network elements. ```netLayout_vertical.js``` uses a function, called ```allocatePosition``` to give the layers their position on the canvas. It finds the closest position available to the preferred position, and checks if a node is already on that position on the X axis (if one is, a position left or right is assigned). The file also uses a custom Topolical Sort to give the nodes their position (it is based on the inputs and outputs of nodes). Later it is checked if any nodes overlap and in case they do, they are moved.
166+
167+
#### ```netLayout.js```
168+
```netLayout.js``` is used to check the Y attribute of nodes. The function ```allocatePosition``` finds the closest available position to the preffered one and allocates the module. Later the nodes are checked with a DFS algorithm (depth-first search algorithm).
169+
170+
***
171+
172+
#### ```pane.js```
173+
```pane.js``` handles the layer panel and contains these methods:
174+
* ```toggleClass``` - toggles classes for the dropdown on the sidebar for layer selection
175+
176+
```pane.js``` invokes ```paneElement.js``` to render out each element.
177+
178+
***
179+
180+
#### ```paneElement.js```
181+
```paneElement.js``` renders out each element of the pane, it is invoked by ```pane.js```. It includes:
182+
* ```drag``` - allows dragging of layers
183+
184+
```pane.js``` renders out all of the layers for selection by the user.
185+
***
186+
#### ```panZoom.js```
187+
```panZoom.js``` includes the functions that zoom the canvas in and out, based on various invocations.
188+
189+
***
190+
191+
#### ```setParams.js```
192+
Contains the following methods for the layer edition sidebar:
193+
* ```changeProps``` - changes layer properties
194+
* ```changeParams``` - changes layer parameters
195+
* ```trainOnly``` - turns model into a train-only
196+
* ```handleKeyPress``` - handles layer delete after the 'delete' key is pressed
197+
198+
```setParams.js``` allows users to change layer parameters and reads parameters through ```data.js```
199+
200+
***
201+
#### ```tabs.js```
202+
```tabs.js``` is used to switch between the Train and Test model buttons and to render.
203+
***
204+
#### ```tooltip.js``` and ```tooltipData.js```
157205
Both of these files contains code for tooltips and the ```tooltipData.js``` contains the actual tooltips that are rendered.
158206

159207
note: tooltips are "hover" messages, they tell more information about something when a user hovers over an object.
160-
208+
***
209+
210+
#### ```topbar.js```
211+
```topbar.js``` shows the top section of the sidebar. It has two methods:
212+
* ```checkURL``` - checks model import URL

0 commit comments

Comments
 (0)