How to use getBoundingBox method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

else-statement-view.js

Source: else-statement-view.js Github

copy
1/**
2 * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 *
4 * WSO2 Inc. licenses this file to you under the Apache License,
5 * Version 2.0 (the "License"); you may not use this file except
6 * in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18define(['require', 'lodash', 'jquery', 'log', './ballerina-statement-view', './../ast/else-statement', 'd3utils', 'd3', './point', 'ballerina/ast/ballerina-ast-factory'],
19    function (require, _, $, log, BallerinaStatementView, ElseStatement, D3Utils, d3, Point, BallerinaASTFactory) {
20
21        /**
22         * The view to represent a Else statement which is an AST visitor.
23         * @param {Object} args - Arguments for creating the view.
24         * @param {IfElseStatement} args.model - The Else statement model.
25         * @param {Object} args.container - The HTML container to which the view should be added to.
26         * @param {Object} args.parent - Parent Statement View, which in this case the if-else statement
27         * @param {Object} [args.viewOptions={}] - Configuration values for the view.
28         * @constructor
29         */
30        var ElseStatementView = function (args) {
31            BallerinaStatementView.call(this, args);
32            _.set(this._viewOptions, 'width', _.get(this._viewOptions, 'width', 140));
33            _.set(this._viewOptions, 'height', _.get(this._viewOptions, 'height', 100));
34            _.set(this._viewOptions, 'contentOffset', _.get(this._viewOptions, 'contentOffset', {top: 10, bottom: 10}));
35            // Initialize the bounding box
36            this.getBoundingBox().fromTopCenter(this.getTopCenter(),
37                _.get(this._viewOptions, 'width'),  _.get(this._viewOptions, 'height'));
38        };
39
40        ElseStatementView.prototype = Object.create(BallerinaStatementView.prototype);
41        ElseStatementView.prototype.constructor = ElseStatementView;
42
43        ElseStatementView.prototype.canVisitElseStatement = function(){
44            return true;
45        };
46
47        /**
48         * Render the else statement
49         */
50        ElseStatementView.prototype.render = function (diagramRenderingContext) {
51            this._diagramRenderingContext = diagramRenderingContext;
52            var elseGroup = D3Utils.group(d3.select(this._container));
53            elseGroup.attr("id","_" + this._model.id);
54            var self = this;
55
56            var title_rect = D3Utils.rect(this.getBoundingBox().x(), this.getBoundingBox().y(), this.getBoundingBox().w(), 25, 0, 0, elseGroup).classed('statement-title-rect', true);
57            var outer_rect = D3Utils.rect(this.getBoundingBox().x(), this.getBoundingBox().y(), this.getBoundingBox().w(),
58                this.getBoundingBox().h(), 0, 0, elseGroup).classed('background-empty-rect', true);
59            var title_text = D3Utils.textElement(this.getBoundingBox().x() + 20, this.getBoundingBox().y() + 12, 'Else', elseGroup).classed('statement-text', true);
60            var points = "" + this.getBoundingBox().x() + "," + (parseInt(this.getBoundingBox().y()) + 25) + " " +
61                (parseInt(this.getBoundingBox().x()) + 35) + "," + (parseInt(this.getBoundingBox().y()) + 25) + " " +
62                (parseInt(this.getBoundingBox().x()) + 45) + "," + this.getBoundingBox().y();
63            var title_wrapper_polyline = D3Utils.polyline(points, elseGroup).classed('statement-title-polyline', true);
64            elseGroup.outerRect = outer_rect;
65            elseGroup.titleRect = title_rect;
66            elseGroup.titleText = title_text;
67            elseGroup.title_wrapper_polyline = title_wrapper_polyline;
68            this.setStatementGroup(elseGroup);
69
70            this.getBoundingBox().on('moved', function(offset){
71                outer_rect.attr("y", parseFloat(outer_rect.attr('y')) + offset.dy);
72                outer_rect.attr("x", parseFloat(outer_rect.attr('x')) + offset.dx);
73                title_rect.attr("y", parseFloat(title_rect.attr('y')) + offset.dy);
74                title_rect.attr("x", parseFloat(title_rect.attr('x')) + offset.dx);
75                title_text.attr("y", parseFloat(title_text.attr('y')) + offset.dy);
76                title_text.attr("x", parseFloat(title_text.attr('x')) + offset.dx);
77                var newPolylinePoints = "" + self.getBoundingBox().x() + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
78                    (parseInt(self.getBoundingBox().x()) + 35) + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
79                    (parseInt(self.getBoundingBox().x()) + 45) + "," + self.getBoundingBox().y();
80                title_wrapper_polyline.attr("points", newPolylinePoints);
81            });
82
83            this.getBoundingBox().on('width-changed', function(dw){
84                outer_rect.attr("x", parseFloat(outer_rect.attr('x')) - dw/2);
85                outer_rect.attr("width", parseFloat(outer_rect.attr('width')) + dw);
86                title_rect.attr("x", parseFloat(title_rect.attr('x')) - dw/2);
87                title_text.attr("x", parseFloat(title_text.attr('x')) - dw/2);
88                var newPolylinePoints = "" + self.getBoundingBox().x() + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
89                    (parseInt(self.getBoundingBox().x()) + 35) + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
90                    (parseInt(self.getBoundingBox().x()) + 45) + "," + self.getBoundingBox().y();
91                title_wrapper_polyline.attr("points", newPolylinePoints);
92            });
93
94            this.getBoundingBox().on('height-changed', function(dh){
95                outer_rect.attr("height", parseFloat(outer_rect.attr('height')) + dh);
96                var newHeight = dh + self.getParent().getBoundingBox().h();
97                self.getParent().getBoundingBox().h(newHeight);
98            });
99
100            this._rootGroup = elseGroup;
101            this._statementContainerGroup = D3Utils.group(elseGroup);
102            this.renderStatementContainer();
103            this._model.accept(this);
104            //Removing all the registered 'child-added' event listeners for this model.
105            //This is needed because we are not unregistering registered event while the diagram element deletion.
106            //Due to that, sometimes we are having two or more view elements listening to the 'child-added' event of same model.
107            this._model.off('child-added');
108            this._model.on('child-added', function(child){
109                this.visit(child);
110            }, this);
111        };
112
113        /**
114         * @param {BallerinaStatementView} statement
115         */
116        ElseStatementView.prototype.visit = function (statement) {
117            var args = {model: statement, container: this._rootGroup.node(), viewOptions: {},
118                toolPalette: this.toolPalette, messageManager: this.messageManager, parent: this};
119            this._statementContainer.renderStatement(statement, args);
120        };
121
122        /**
123         * Render statement container
124         */
125        ElseStatementView.prototype.renderStatementContainer = function(){
126            var statementContainerOpts = {};
127            _.set(statementContainerOpts, 'model', this._model);
128            _.set(statementContainerOpts, 'topCenter', this.getTopCenter().clone().move(0, _.get(this._viewOptions, 'contentOffset.top')));
129            var height = _.get(this._viewOptions, 'height') -
130                _.get(this._viewOptions, 'contentOffset.top') - _.get(this._viewOptions, 'contentOffset.bottom');
131            _.set(statementContainerOpts, 'bottomCenter', this.getTopCenter().clone().move(0,  _.get(this._viewOptions, 'height')));
132            _.set(statementContainerOpts, 'width', _.get(this._viewOptions, 'width'));
133            _.set(statementContainerOpts, 'offset', {top: 40, bottom: 40});
134            _.set(statementContainerOpts, 'parent', this);
135            _.set(statementContainerOpts, 'container', this._statementContainerGroup.node());
136            _.set(statementContainerOpts, 'toolPalette', this.toolPalette);
137            var StatementContainer = require('./statement-container');
138            this._statementContainer = new StatementContainer(statementContainerOpts);
139            this.listenTo(this._statementContainer.getBoundingBox(), 'height-changed', function(dh){
140                this.getBoundingBox().h(this.getBoundingBox().h() + dh);
141            });
142
143            this.getBoundingBox().on('top-edge-moved', function (dy) {
144                this._statementContainer.isOnWholeContainerMove = true;
145                this._statementContainer.getBoundingBox().y(this._statementContainer.getBoundingBox().y() + dy);
146            }, this);
147
148            this.listenTo(this._statementContainer.getBoundingBox(), 'width-changed', function(dw){
149                if(this.getBoundingBox().w() < this._statementContainer.getBoundingBox().w()){
150                    this.getBoundingBox().w(this.getBoundingBox().w() + dw);
151                }
152            });
153
154            this._statementContainer.render(this._diagramRenderingContext);
155        };
156
157        /**
158         * set the else statement model
159         * @param {ElseStatement} model
160         */
161        ElseStatementView.prototype.setModel = function (model) {
162            if (!_.isNil(model) && model instanceof ElseStatement) {
163                this._model = model;
164            } else {
165                log.error("Else statement definition is undefined or is of different type." + model);
166                throw "Else statement definition is undefined or is of different type." + model;
167            }
168        };
169
170        /**
171         * Set the container to draw the else statement
172         * @param {svgGroup} container
173         */
174        ElseStatementView.prototype.setContainer = function (container) {
175            if (!_.isNil(container)) {
176                this._container = container;
177            } else {
178                log.error("Container for Else statement is undefined." + container);
179                throw "Container for Else statement is undefined." + container;
180            }
181        };
182
183        ElseStatementView.prototype.getModel = function () {
184            return this._model;
185        };
186
187        ElseStatementView.prototype.getContainer = function () {
188            return this._container;
189        };
190
191        /**
192         * Get the statement container
193         * @return {StatementContainer} - Statement container
194         */
195        ElseStatementView.prototype.getStatementContainer = function () {
196            return this._statementContainer;
197        };
198
199        /**
200         * Override Child remove callback
201         * @param {ASTNode} child - removed child
202         */
203        ElseStatementView.prototype.childRemovedCallback = function (child) {
204            if (BallerinaASTFactory.isStatement(child)) {
205                this.getStatementContainer().childStatementRemovedCallback(child);
206            }
207        };
208
209        return ElseStatementView;
210    });
Full Screen

while-statement-view.js

Source: while-statement-view.js Github

copy
1/**
2 * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 *
4 * WSO2 Inc. licenses this file to you under the Apache License,
5 * Version 2.0 (the "License"); you may not use this file except
6 * in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18define(['require', 'lodash', 'jquery', 'log', './ballerina-statement-view', './../ast/while-statement', 'd3utils', 'd3', 'ballerina/ast/ballerina-ast-factory'],
19    function (require, _, $, log, BallerinaStatementView, WhileStatement, D3Utils, d3, BallerinaASTFactory) {
20
21        /**
22         * The view to represent a If statement which is an AST visitor.
23         * @param {Object} args - Arguments for creating the view.
24         * @param {WhileStatement} args.model - The If statement model.
25         * @param {Object} args.container - The HTML container to which the view should be added to.
26         * @param {Object} args.parent - Parent View, which in this case the parent model
27         * @param {Object} [args.viewOptions={}] - Configuration values for the view.
28         * @constructor
29         */
30        var WhileStatementView = function (args) {
31            BallerinaStatementView.call(this, args);
32            _.set(this._viewOptions, 'width', _.get(this._viewOptions, 'width', 140));
33            _.set(this._viewOptions, 'height', _.get(this._viewOptions, 'height', 100));
34            _.set(this._viewOptions, 'contentOffset', _.get(this._viewOptions, 'contentOffset', {top: 10, bottom: 10}));
35            // Initialize the bounding box
36            this.getBoundingBox().fromTopCenter(this.getTopCenter(),
37                _.get(this._viewOptions, 'width'),  _.get(this._viewOptions, 'height'));
38            this._statementContainer = undefined;
39        };
40
41        WhileStatementView.prototype = Object.create(BallerinaStatementView.prototype);
42        WhileStatementView.prototype.constructor = WhileStatementView;
43
44        WhileStatementView.prototype.canVisitWhileStatement = function(){
45            return true;
46        };
47
48        /**
49         * Remove View callback
50         * @param {ASTNode} parent - parent node
51         * @param {ASTNode} child - child node
52         */
53        WhileStatementView.prototype.onBeforeModelRemove = function () {
54            this._statementContainer.getBoundingBox().off('bottom-edge-moved');
55            d3.select("#_" +this._model.id).remove();
56            this.getBoundingBox().w(0).h(0);
57        };
58
59        /**
60         * Override Child remove callback
61         * @param {ASTNode} child - removed child
62         */
63        WhileStatementView.prototype.childRemovedCallback = function (child) {
64            if (BallerinaASTFactory.isStatement(child)) {
65                this.getStatementContainer().childStatementRemovedCallback(child);
66            }
67        };
68
69        /**
70         * Render the while statement
71         */
72        WhileStatementView.prototype.render = function (diagramRenderingContext) {
73            this._diagramRenderingContext = diagramRenderingContext;
74            var whileGroup = D3Utils.group(d3.select(this._container));
75            whileGroup.attr("id","_" +this._model.id);
76            var self = this;
77
78            var title_rect = D3Utils.rect(this.getBoundingBox().x(), this.getBoundingBox().y(), this.getBoundingBox().w(), 25, 0, 0, whileGroup).classed('statement-title-rect', true);
79            var outer_rect = D3Utils.rect(this.getBoundingBox().x(), this.getBoundingBox().y(), this.getBoundingBox().w(),
80                this.getBoundingBox().h(), 0, 0, whileGroup).classed('background-empty-rect', true);
81            var points = "" + this.getBoundingBox().x() + "," + (parseInt(this.getBoundingBox().y()) + 25) + " " +
82                (parseInt(this.getBoundingBox().x()) + 35) + "," + (parseInt(this.getBoundingBox().y()) + 25) + " " +
83                (parseInt(this.getBoundingBox().x()) + 45) + "," + this.getBoundingBox().y();
84            var title_wrapper_polyline = D3Utils.polyline(points, whileGroup).classed('statement-title-polyline', true);
85            var title_text = D3Utils.textElement(this.getBoundingBox().x() + 20, this.getBoundingBox().y() + 12, 'While', whileGroup).classed('statement-text', true);
86            whileGroup.outerRect = outer_rect;
87            whileGroup.titleRect = title_rect;
88            whileGroup.titleText = title_text;
89            whileGroup.title_wrapper_polyline = title_wrapper_polyline;
90            this.setStatementGroup(whileGroup);
91
92            this.getBoundingBox().on('moved', function(offset){
93                outer_rect.attr("y", parseFloat(outer_rect.attr('y')) + offset.dy);
94                outer_rect.attr("x", parseFloat(outer_rect.attr('x')) + offset.dx);
95                title_rect.attr("y", parseFloat(title_rect.attr('y')) + offset.dy);
96                title_rect.attr("x", parseFloat(title_rect.attr('x')) + offset.dx);
97                title_text.attr("y", parseFloat(title_text.attr('y')) + offset.dy);
98                title_text.attr("x", parseFloat(title_text.attr('x')) + offset.dx);
99                var newPolylinePoints = "" + self.getBoundingBox().x() + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
100                    (parseInt(self.getBoundingBox().x()) + 35) + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
101                    (parseInt(self.getBoundingBox().x()) + 45) + "," + self.getBoundingBox().y();
102                title_wrapper_polyline.attr("points", newPolylinePoints);
103            });
104
105            this.getBoundingBox().on('width-changed', function(dw){
106                outer_rect.attr("x", parseFloat(outer_rect.attr('x')) - dw/2);
107                outer_rect.attr("width", parseFloat(outer_rect.attr('width')) + dw);
108                title_rect.attr("x", parseFloat(title_rect.attr('x')) - dw/2);
109                title_text.attr("x", parseFloat(title_text.attr('x')) - dw/2);
110                var newPolylinePoints = "" + self.getBoundingBox().x() + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
111                    (parseInt(self.getBoundingBox().x()) + 35) + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
112                    (parseInt(self.getBoundingBox().x()) + 45) + "," + self.getBoundingBox().y();
113                title_wrapper_polyline.attr("points", newPolylinePoints);
114            });
115
116            // Creating property pane
117            var editableProperty = {
118                propertyType: "text",
119                key: "Condition",
120                model: this._model,
121                getterMethod: this._model.getCondition,
122                setterMethod: this._model.setCondition
123            };
124            this._createPropertyPane({
125                model: this._model,
126                statementGroup:whileGroup,
127                editableProperties: editableProperty
128            });
129
130            this.getBoundingBox().on('height-changed', function(dh){
131                outer_rect.attr("height", parseFloat(outer_rect.attr('height')) + dh);
132            });
133
134            this._rootGroup = whileGroup;
135            this._statementContainerGroup = D3Utils.group(whileGroup);
136            this.renderStatementContainer();
137            this._model.accept(this);
138            //Removing all the registered 'child-added' event listeners for this model.
139            //This is needed because we are not unregistering registered event while the diagram element deletion.
140            //Due to that, sometimes we are having two or more view elements listening to the 'child-added' event of same model.
141            this._model.off('child-added');
142            this._model.on('child-added', function(child){
143                this.visit(child);
144            }, this);
145        };
146
147        /**
148         * @param {BallerinaStatementView} statement
149         */
150        WhileStatementView.prototype.visit = function (statement) {
151            var args = {model: statement, container: this._rootGroup.node(), viewOptions: {},
152                toolPalette: this.toolPalette, messageManager: this.messageManager, parent: this};
153            this._statementContainer.renderStatement(statement, args);
154        };
155
156        /**
157         * Render statement container
158         */
159        WhileStatementView.prototype.renderStatementContainer = function(){
160            var statementContainerOpts = {};
161            _.set(statementContainerOpts, 'model', this._model);
162            _.set(statementContainerOpts, 'topCenter', this.getTopCenter().clone().move(0, _.get(this._viewOptions, 'contentOffset.top')));
163            var height = _.get(this._viewOptions, 'height') -
164                _.get(this._viewOptions, 'contentOffset.top') - _.get(this._viewOptions, 'contentOffset.bottom');
165            _.set(statementContainerOpts, 'bottomCenter', this.getTopCenter().clone().move(0, _.get(this._viewOptions, 'height')));
166            _.set(statementContainerOpts, 'width', _.get(this._viewOptions, 'width'));
167            _.set(statementContainerOpts, 'offset', {top: 40, bottom: 40});
168            _.set(statementContainerOpts, 'parent', this);
169            _.set(statementContainerOpts, 'container', this._statementContainerGroup.node());
170            _.set(statementContainerOpts, 'toolPalette', this.toolPalette);
171            var StatementContainer = require('./statement-container');
172            this._statementContainer = new StatementContainer(statementContainerOpts);
173            this.listenTo(this._statementContainer.getBoundingBox(), 'height-changed', function(dh){
174                this.getBoundingBox().h(this.getBoundingBox().h() + dh);
175            });
176            this.getBoundingBox().on('top-edge-moved', function (dy) {
177                this._statementContainer.isOnWholeContainerMove = true;
178                this._statementContainer.getBoundingBox().y(this._statementContainer.getBoundingBox().y() + dy);
179            }, this);
180
181            this.listenTo(this._statementContainer.getBoundingBox(), 'width-changed', function(dw){
182                this.getBoundingBox().w(this.getBoundingBox().w() + dw);
183            });
184
185            this._statementContainer.render(this._diagramRenderingContext);
186        };
187
188        /**
189         * Set the while statement model
190         * @param {WhileStatement} model
191         */
192        WhileStatementView.prototype.setModel = function (model) {
193            if (!_.isNil(model) && model instanceof WhileStatement) {
194                this._model = model;
195            } else {
196                log.error("While statement definition is undefined or is of different type." + model);
197                throw "While statement definition is undefined or is of different type." + model;
198            }
199        };
200
201        /**
202         * Set the container to draw the while statement
203         * @param container
204         */
205        WhileStatementView.prototype.setContainer = function (container) {
206            if (!_.isNil(container)) {
207                this._container = container;
208            } else {
209                log.error("Container for While statement is undefined." + container);
210                throw "Container for While statement is undefined." + container;
211            }
212        };
213
214        WhileStatementView.prototype.setViewOptions = function (viewOptions) {
215            this._viewOptions = viewOptions;
216        };
217
218        WhileStatementView.prototype.getModel = function () {
219            return this._model;
220        };
221
222        WhileStatementView.prototype.getContainer = function () {
223            return this._container;
224        };
225
226        WhileStatementView.prototype.getViewOptions = function () {
227            return this._viewOptions;
228        };
229
230        /**
231         * Get the statement container
232         * @return {StatementContainer} - statement container
233         */
234        WhileStatementView.prototype.getStatementContainer = function () {
235            return this._statementContainer;
236        };
237
238        return WhileStatementView;
239    });
Full Screen

if-statement-view.js

Source: if-statement-view.js Github

copy
1/**
2 * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 *
4 * WSO2 Inc. licenses this file to you under the Apache License,
5 * Version 2.0 (the "License"); you may not use this file except
6 * in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18define(['require', 'lodash', 'jquery', 'log', './ballerina-statement-view', './../ast/if-statement', 'd3utils', 'd3', 'ballerina/ast/ballerina-ast-factory'],
19    function (require, _, $, log, BallerinaStatementView, IfStatement, D3Utils, d3, BallerinaASTFactory) {
20
21        /**
22         * The view to represent a If statement which is an AST visitor.
23         * @param {Object} args - Arguments for creating the view.
24         * @param {IfStatement} args.model - The If statement model.
25         * @param {Object} args.container - The HTML container to which the view should be added to.
26         * @param {Object} args.parent - Parent Statement View, which in this case the if-else statement
27         * @param {Object} [args.viewOptions={}] - Configuration values for the view.
28         * @constructor
29         */
30        var IfStatementView = function (args) {
31            BallerinaStatementView.call(this, args);
32            _.set(this._viewOptions, 'width', _.get(this._viewOptions, 'width', 140));
33            _.set(this._viewOptions, 'height', _.get(this._viewOptions, 'height', 100));
34            _.set(this._viewOptions, 'contentOffset', _.get(this._viewOptions, 'contentOffset', {top: 10, bottom: 10}));
35            // Initialize the bounding box
36            this.getBoundingBox().fromTopCenter(this.getTopCenter(),
37                _.get(this._viewOptions, 'width'),  _.get(this._viewOptions, 'height'));
38            this._statementContainer = undefined;
39        };
40
41        IfStatementView.prototype = Object.create(BallerinaStatementView.prototype);
42        IfStatementView.prototype.constructor = IfStatementView;
43
44        IfStatementView.prototype.canVisitIfStatement = function(){
45            return true;
46        };
47
48        /**
49         * Render the if statement
50         */
51        IfStatementView.prototype.render = function (diagramRenderingContext) {
52            this._diagramRenderingContext = diagramRenderingContext;
53            var ifGroup = D3Utils.group(d3.select(this._container));
54            ifGroup.attr("id","_" +this._model.id);
55            var self = this;
56
57            var title_rect = D3Utils.rect(this.getBoundingBox().x(), this.getBoundingBox().y(), this.getBoundingBox().w(), 25, 0, 0, ifGroup).classed('statement-title-rect', true);
58            var outer_rect = D3Utils.rect(this.getBoundingBox().x(), this.getBoundingBox().y(), this.getBoundingBox().w(),
59                this.getBoundingBox().h(), 0, 0, ifGroup).classed('background-empty-rect', true);
60            var points = "" + this.getBoundingBox().x() + "," + (parseInt(this.getBoundingBox().y()) + 25) + " " +
61                (parseInt(this.getBoundingBox().x()) + 35) + "," + (parseInt(this.getBoundingBox().y()) + 25) + " " +
62                (parseInt(this.getBoundingBox().x()) + 45) + "," + this.getBoundingBox().y();
63            var title_wrapper_polyline = D3Utils.polyline(points, ifGroup).classed('statement-title-polyline', true);
64            var title_text = D3Utils.textElement(this.getBoundingBox().x() + 20, this.getBoundingBox().y() + 12, 'If', ifGroup).classed('statement-text', true);
65            ifGroup.outerRect = outer_rect;
66            ifGroup.titleRect = title_rect;
67            ifGroup.titleText = title_text;
68            ifGroup.title_wrapper_polyline = title_wrapper_polyline;
69            this.setStatementGroup(ifGroup);
70
71            this.getBoundingBox().on('moved', function(offset){
72                outer_rect.attr("y", parseFloat(outer_rect.attr('y')) + offset.dy);
73                outer_rect.attr("x", parseFloat(outer_rect.attr('x')) + offset.dx);
74                title_rect.attr("y", parseFloat(title_rect.attr('y')) + offset.dy);
75                title_rect.attr("x", parseFloat(title_rect.attr('x')) + offset.dx);
76                title_text.attr("y", parseFloat(title_text.attr('y')) + offset.dy);
77                title_text.attr("x", parseFloat(title_text.attr('x')) + offset.dx);
78                var newPolylinePoints = "" + self.getBoundingBox().x() + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
79                    (parseInt(self.getBoundingBox().x()) + 35) + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
80                    (parseInt(self.getBoundingBox().x()) + 45) + "," + self.getBoundingBox().y();
81                title_wrapper_polyline.attr("points", newPolylinePoints);
82            });
83
84            this.getBoundingBox().on('width-changed', function(dw){
85                outer_rect.attr("x", parseFloat(outer_rect.attr('x')) - dw/2);
86                outer_rect.attr("width", parseFloat(outer_rect.attr('width')) + dw);
87                title_rect.attr("x", parseFloat(title_rect.attr('x')) - dw/2);
88                title_text.attr("x", parseFloat(title_text.attr('x')) - dw/2);
89                var newPolylinePoints = "" + self.getBoundingBox().x() + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
90                    (parseInt(self.getBoundingBox().x()) + 35) + "," + (parseInt(self.getBoundingBox().y()) + 25) + " " +
91                    (parseInt(self.getBoundingBox().x()) + 45) + "," + self.getBoundingBox().y();
92                title_wrapper_polyline.attr("points", newPolylinePoints);
93            });
94
95            this.getBoundingBox().on('height-changed', function(dh){
96                outer_rect.attr("height", parseFloat(outer_rect.attr('height')) + dh);
97                var newHeight = dh + self.getParent().getBoundingBox().h() + 20;
98                self.getParent().getBoundingBox().h(newHeight);
99            });
100
101            this._rootGroup = ifGroup;
102            this._statementContainerGroup = D3Utils.group(ifGroup);
103            this.renderStatementContainer();
104            this._model.accept(this);
105            //Removing all the registered 'child-added' event listeners for this model.
106            //This is needed because we are not unregistering registered event while the diagram element deletion.
107            //Due to that, sometimes we are having two or more view elements listening to the 'child-added' event of same model.
108            this._model.off('child-added');
109            this._model.on('child-added', function(child){
110                this.visit(child);
111            }, this);
112        };
113
114        /**
115         * @param {BallerinaStatementView} statement
116         */
117        IfStatementView.prototype.visit = function (statement) {
118            var args = {model: statement, container: this._rootGroup.node(), viewOptions: {},
119                toolPalette: this.toolPalette, messageManager: this.messageManager, parent: this};
120            this._statementContainer.renderStatement(statement, args);
121        };
122
123        /**
124         * Render statement container
125         */
126        IfStatementView.prototype.renderStatementContainer = function(){
127            var statementContainerOpts = {};
128            _.set(statementContainerOpts, 'model', this._model);
129            _.set(statementContainerOpts, 'topCenter', this.getTopCenter().clone().move(0, _.get(this._viewOptions, 'contentOffset.top')));
130            var height = _.get(this._viewOptions, 'height') -
131                _.get(this._viewOptions, 'contentOffset.top') - _.get(this._viewOptions, 'contentOffset.bottom');
132            _.set(statementContainerOpts, 'bottomCenter', this.getTopCenter().clone().move(0, _.get(this._viewOptions, 'height')));
133            _.set(statementContainerOpts, 'width', _.get(this._viewOptions, 'width'));
134            _.set(statementContainerOpts, 'offset', {top: 40, bottom: 40});
135            _.set(statementContainerOpts, 'parent', this);
136            _.set(statementContainerOpts, 'container', this._statementContainerGroup.node());
137            _.set(statementContainerOpts, 'toolPalette', this.toolPalette);
138            var StatementContainer = require('./statement-container');
139            this._statementContainer = new StatementContainer(statementContainerOpts);
140            this.listenTo(this._statementContainer.getBoundingBox(), 'height-changed', function(dh){
141                this.getBoundingBox().h(this.getBoundingBox().h() + dh);
142            });
143            this.getBoundingBox().on('top-edge-moved', function (dy) {
144                this._statementContainer.isOnWholeContainerMove = true;
145                this._statementContainer.getBoundingBox().y(this._statementContainer.getBoundingBox().y() + dy);
146            }, this);
147
148            this.listenTo(this._statementContainer.getBoundingBox(), 'width-changed', function(dw){
149                this.getBoundingBox().w(this.getBoundingBox().w() + dw);
150            });
151
152            this._statementContainer.render(this._diagramRenderingContext);
153        };
154
155        /**
156         * Set the if statement model
157         * @param {IfStatement} model
158         */
159        IfStatementView.prototype.setModel = function (model) {
160            if (!_.isNil(model) && model instanceof IfStatement) {
161                this._model = model;
162            } else {
163                log.error("If Else statement definition is undefined or is of different type." + model);
164                throw "If Else statement definition is undefined or is of different type." + model;
165            }
166        };
167
168        /**
169         * Set the container to draw the if statement
170         * @param container
171         */
172        IfStatementView.prototype.setContainer = function (container) {
173            if (!_.isNil(container)) {
174                this._container = container;
175            } else {
176                log.error("Container for If Else statement is undefined." + container);
177                throw "Container for If Else statement is undefined." + container;
178            }
179        };
180
181        IfStatementView.prototype.setViewOptions = function (viewOptions) {
182            this._viewOptions = viewOptions;
183        };
184
185        IfStatementView.prototype.getModel = function () {
186            return this._model;
187        };
188
189        IfStatementView.prototype.getContainer = function () {
190            return this._container;
191        };
192
193        IfStatementView.prototype.getViewOptions = function () {
194            return this._viewOptions;
195        };
196
197        /**
198         * Get the statement container
199         * @return {StatementContainer} - Statement container
200         */
201        IfStatementView.prototype.getStatementContainer = function () {
202            return this._statementContainer;
203        };
204
205        /**
206         * Override Child remove callback
207         * @param {ASTNode} child - removed child
208         */
209        IfStatementView.prototype.childRemovedCallback = function (child) {
210            if (BallerinaASTFactory.isStatement(child)) {
211                this.getStatementContainer().childStatementRemovedCallback(child);
212            }
213        };
214
215        return IfStatementView;
216    });
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)