Skip to content

[#603][3] Integrate JointJS to the new GUI - #606

Merged
zuozhiw merged 16 commits into
new-gui-operator-panelfrom
new-gui-jointjs
Apr 9, 2018
Merged

zuozhiw merged 16 commits into
new-gui-operator-panelfrom
new-gui-jointjs

Conversation

@zuozhiw

@zuozhiw zuozhiw commented Apr 5, 2018 •

Copy link
Copy Markdown
Contributor

This PR integrates JointJS to the codebase. JointJS is a Javascript Library we use to draw the workflow graph.

JointJS tutorial: https://resources.jointjs.com/tutorial
JointJS API: https://resources.jointjs.com/docs/jointjs/v2.0/joint.html

This PR adds the component WorkflowEditor, which is the main canvas to let user edit the workflow. JointJS is attached to the DOM element of this component. The JointJS paper is created with many custom options in this Component.

This PR also adds a service JointUIService The job of this service to provide JointJS Element (which contains all attributes and data for JointJS to create an Operator element) and JointJS link to other modules.

The current UI looks like this. The JointJS data model isn't fully integrated into our own data model yet, this PR only includes the UI part. The operators and links are temporary to show that JointJS works.

screen shot 2018-04-04 at 6 05 36 pm

New Frontend PR status:
[1]: PR #604 creates the app using Angular CLI, which sets up the project with basic templates. The basic components are created.
[2]: PR #605 adds the left side operator panel, which shows the operators and the groups. It adds OperatorMetadataService, which fetches metadata from the backend.
[3]: PR #606 integrates JointJS to the app. JointJS is used to display the operators and the links. This PR integrates JointJS in the View level.

@zuozhiw
zuozhiw changed the base branch from master to new-gui-operator-panel April 5, 2018 04:24
* for the delte button.
*/
public readonly deleteButtonSVG =
`<svg class="delete-button" fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F2F: What do these and above numbers mean? I mean how to interpret them?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewBox and xmlns is unnecessary (will be deleted). viewBox is basically "min-width, min-height, width, height", which is redundant with height and width attribute. Fill specifies the color of delete button, which doesn't do anything here

Only Height and Width are required for this svg. Height and width basically specify the dimension of the delete button on operators.

operatorType: string, operatorID: string, xPosition: number, yPosition: number
): joint.dia.Element {

const operatorSchema = this.operators.find(op => op.operatorType === operatorType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we know that the call in contructor has completed and this.operators is not empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we uses a timeout in workflow-editor.component.ts

capture

which is about the time where the service constructor is completed. This code will be
deleted later when drag and drop is implemented. Currently we need the time out because
there are 2 operators created as soon as ngAfterViewInit is called.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. so am I correct in saying that we assume that when drag and drop is used, the user will take some time to do that, and till then the operatorMetadataService.getOperatorMetadata() will finish and bring in the metadata? And if it hasn't finished and the user does something, the action will throw an error.

I realize that might not happen because if the service doesn't succeed in bringing the metadata, there will be nothing for the user to drag and drop. Is that correct?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, still we might have a to-do item which we can take up later, to do something like blurring out the screen and showing a loading sign till some initialization is taking place. At that time, we don't allow users to do anything

@zuozhiw zuozhiw Apr 6, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinash0161 we don't need that (at least for now). The operator panel won't show operators initially because the data hasn't arrived yet. And as you said, users have nothing to drag at this point of time.

But yeah, it is nice to have a initial loading animation if the loading takes long time. I think for what we are doing now, the loading animation might just flash because the data arrives very fast.

type: 'devs.TexeraModel',
markup:
`<g class="element-node">
<rect class="body" stroke-width="2" stroke="blue" rx="5px" ry="5px"></rect>

@avinash0161 avinash0161 Apr 5, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just to add a custom delete button to the operator's jointjs model and other properties of the model are being set in getJointjsOperatorElement()? If so, please mention that in the comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, setupCustomJointjsModel() basically creates an empty rectangle with delete button on the top-right hand corner. Other properties such as styles and texts are set in the getJointJsOperatorElement(). I will modify the comments ASAP.

styleUrls: ['./workflow-editor.component.scss']
})
export class WorkflowEditorComponent implements OnInit {
export class WorkflowEditorComponent implements AfterViewInit {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this implement AfterViewInit instead of OnInit()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We implement AfterViewInit instead of OnInit because we want to override the AfterViewInit method here. We use ngAfterViewInit in this component because we want to display JointJS element on the UI after the component view is fully initialized.

@zuozhiw zuozhiw Apr 6, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Angular's component lifecycle, afterViewInit() is called after onInit().

onInit is called after the data of the class are initialized, for example, if this component class needs any inputs from its parent component.

afterViewInit, as its name suggests, is called after the view (the DOM elements) are initialized. We bind JointJS paper to an DOM element, and we need to wait after the view is initialized.

workflow-editor works!
</p>
<div class="texera-workspace-workflow-editor-body texera-workflow-component-body" [attr.id]="WORKFLOW_EDITOR_JOINTJS_WRAPPER_ID">
<div class ="texera-workspace-workflow-jointjs" [attr.id]="WORKFLOW_EDITOR_JOINTJS_ID">

@avinash0161 avinash0161 Apr 5, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remind me how is the attr.id input used? Is this just a normal id being allotted to the tag?

@henrychen0220 henrychen0220 Apr 5, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[attr.id] is basically the same thing with doing the same thing as:

<div #id="WORKFLOW_EDITOR_JOINTJS_WRAPPER_ID"></div>

we uses attr.id because we want to use the variable defined in the workflow-editor.component.ts. Since resizing will also need the ID of the paper, we decided that it is better to defined the ID in the TS file to improve the structure of the code base.

// add some dummy operators and links to show that JointJS works
this.graph.addCell(
this.jointUIService.getJointjsOperatorElement(
'ScanSource',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these operators being added? Is it just for this PR?

@henrychen0220 henrychen0220 Apr 5, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for this PR and will be deleted in the future. These operators show that the custom element defined is successfully registered and being utilized by JointJS

*/
private getWrapperElementSize(): {width: number, height: number} {
return {
width: $('#' + this.WORKFLOW_EDITOR_JOINTJS_WRAPPER_ID).width(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this will give the size of div. But isn't the size of div 0 if there isn't anything inside it? If yes, then how are we using it in createJoinJSPaper to set the size?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the wrapper has the style texera-workflow-component-body, which is defined in `workspace.component.scss', the size of the div will be the entire area of the workflow-editor at the center of the browser.

Since all the sub components wrapper use the class texera-workflow-component-body. We defined it in `workspace.component.scss' to avoid redundancy.


import { OperatorMetadataService } from '../service/operator-metadata/operator-metadata.service';
import { JointUIService } from '../service/joint-ui/joint-ui.service';
import { StubOperatorMetadataService } from '../service/operator-metadata/stub-operator-metadata.service';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this imported in the previous PR? because I remember seeing stuboperatormetadatservice being used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stuboperatormetadatservice is used another file. This is imported here because in line 15 of this file, we added a line to use it to conveniently test things.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JointUIService needs to be important to the parent (in this case, workspace.component.ts file) for workflow-editor.component.ts to use.

As for the StubOperatorMetadataService, it is only used when we try to test the new-gui without opening the java backend server. Instead of fetching backend metadata, we would use the mock metadata defined in service/operator-metadata/mock-operator-metadata.data.ts

expect(outPortCount3).toEqual(0);

});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be a test to test that linking of two elements works?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since JointJS are managing all the links, there's no point of testing the correctness of JointJS. We trust the library is implemented correctly.

@avinash0161 avinash0161 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few more comments. Please take a look. Other than that, we are fine.

@zuozhiw
zuozhiw merged commit dc9506e into new-gui-operator-panel Apr 9, 2018
@zuozhiw
zuozhiw deleted the new-gui-jointjs branch April 9, 2018 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants