Skip to content

Commit e33e266

Browse files
author
undefined
committed
fix canvas
1 parent 256c183 commit e33e266

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"grunt-string-replace": "^1.3.1",
5151
"grunt-uidocs-generator": "^0.6.1",
5252
"jasmine-core": "^2.9.0",
53-
"jquery-ui-dist": "^1.12.1",
53+
"jquery-ui-dist": "1.12.1",
5454
"karma": "^1.7.1",
5555
"karma-chrome-launcher": "^2.2.0",
5656
"karma-firefox-launcher": "^1.0.1",
@@ -73,11 +73,11 @@
7373
"bootstrap": "~3.3.7",
7474
"bootstrap-select": "~1.12.4",
7575
"c3": "~0.4.11",
76-
"jquery-ui-dist": "~1.12.1",
76+
"jquery-ui-dist": "1.12.1",
7777
"d3": "~3.5.17",
7878
"datatables.net": "^1.10.12",
7979
"datatables.net-select": "~1.2.0",
80-
"jquery": "~3.2.1",
80+
"jquery": "3.2.1",
8181
"moment": "~2.19.3"
8282
},
8383
"release": {

src/canvas-view/canvas-editor/canvas-editor.component.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,38 @@
1313
templateUrl: 'canvas-view/canvas-editor/canvas-editor.html',
1414
controller: function ($timeout) {
1515
var ctrl = this;
16-
var newNodeCount = 0;
17-
var prevClickedOnChart, prevInConnectingMode;
1816

1917
ctrl.$onInit = function () {
18+
console.log('canvas editor oninit');
19+
ctrl.newNodeCount = 0;
20+
ctrl.prevClickedOnChart = undefined;
21+
ctrl.prevInConnectingMode = undefined;
2022
ctrl.toolboxVisible = false;
2123
ctrl.hideConnectors = false;
2224
ctrl.draggedItem = null;
2325
};
2426

2527
// need to get these in next digest cycle, after pfCanvas sets chartViewModel
2628
$timeout(function () {
27-
prevClickedOnChart = ctrl.chartViewModel.clickedOnChart;
28-
prevInConnectingMode = ctrl.chartViewModel.inConnectingMode;
29+
ctrl.prevClickedOnChart = ctrl.chartViewModel.clickedOnChart;
30+
ctrl.prevInConnectingMode = ctrl.chartViewModel.inConnectingMode;
2931
});
3032

3133
ctrl.$doCheck = function () {
32-
if (angular.isDefined(prevClickedOnChart) && angular.isDefined(prevInConnectingMode)) {
33-
if (!angular.equals(ctrl.chartViewModel.clickedOnChart, prevClickedOnChart)) {
34+
if (angular.isDefined(ctrl.prevClickedOnChart) && angular.isDefined(ctrl.prevInConnectingMode)) {
35+
if (!angular.equals(ctrl.chartViewModel.clickedOnChart, ctrl.prevClickedOnChart)) {
3436
if (ctrl.chartViewModel.clickedOnChart) {
3537
ctrl.chartViewModel.clickedOnChart = false;
3638
ctrl.hideToolbox();
3739
}
38-
prevClickedOnChart = ctrl.chartViewModel.clickedOnChart;
40+
ctrl.prevClickedOnChart = ctrl.chartViewModel.clickedOnChart;
3941
}
40-
if (!angular.equals(ctrl.chartViewModel.inConnectingMode, prevInConnectingMode)) {
42+
if (!angular.equals(ctrl.chartViewModel.inConnectingMode, ctrl.prevInConnectingMode)) {
4143
if (ctrl.chartViewModel.inConnectingMode) {
4244
ctrl.hideConnectors = false;
4345
ctrl.hideToolbox();
4446
}
45-
prevInConnectingMode = ctrl.chartViewModel.inConnectingMode;
47+
ctrl.prevInConnectingMode = ctrl.chartViewModel.inConnectingMode;
4648
}
4749
}
4850
};
@@ -90,7 +92,7 @@
9092

9193
ctrl.dropCallback = function (event, ui) {
9294
var newNode = angular.copy(ctrl.draggedItem);
93-
newNodeCount++;
95+
ctrl.newNodeCount++;
9496
newNode.x = event.clientX - 600;
9597
newNode.y = event.clientY - 200;
9698
newNode.backgroundColor = newNode.backgroundColor ? newNode.backgroundColor : '#fff';
@@ -100,9 +102,9 @@
100102

101103
ctrl.addNodeByClick = function (item) {
102104
var newNode = angular.copy(item);
103-
newNodeCount++;
104-
newNode.x = 250 + (newNodeCount * 4 + 160);
105-
newNode.y = 200 + (newNodeCount * 4 + 160);
105+
ctrl.newNodeCount++;
106+
newNode.x = 250 + (ctrl.newNodeCount * 4 + 160);
107+
newNode.y = 200 + (ctrl.newNodeCount * 4 + 160);
106108
newNode.backgroundColor = newNode.backgroundColor ? newNode.backgroundColor : '#fff';
107109

108110
ctrl.chartViewModel.addNode(newNode);

src/canvas-view/canvas/canvas-component.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,6 @@
2222
controller: function CanvasController ($scope, dragging, $element, $document) {
2323
var ctrl = this;
2424

25-
ctrl.chart = new pfCanvas.ChartViewModel(ctrl.chartDataModel);
26-
ctrl.chartViewModel = ctrl.chart;
27-
28-
//
29-
// Init data-model variables.
30-
//
31-
ctrl.draggingConnection = false;
32-
ctrl.connectorSize = 6;
33-
ctrl.dragSelecting = false;
34-
35-
//
36-
// Reference to the connection, connector or node that the mouse is currently over.
37-
//
38-
ctrl.mouseOverConnector = null;
39-
ctrl.mouseOverConnection = null;
40-
ctrl.mouseOverNode = null;
41-
42-
4325
//
4426
// Translate the coordinates so they are relative to the svg element.
4527
//
@@ -365,6 +347,23 @@
365347
var aKeyCode = 65;
366348
var escKeyCode = 27;
367349

350+
ctrl.chart = new pfCanvas.ChartViewModel(ctrl.chartDataModel);
351+
ctrl.chartViewModel = ctrl.chart;
352+
353+
//
354+
// Init data-model variables.
355+
//
356+
ctrl.draggingConnection = false;
357+
ctrl.connectorSize = 6;
358+
ctrl.dragSelecting = false;
359+
360+
//
361+
// Reference to the connection, connector or node that the mouse is currently over.
362+
//
363+
ctrl.mouseOverConnector = null;
364+
ctrl.mouseOverConnection = null;
365+
ctrl.mouseOverNode = null;
366+
368367
$document.find('body').keydown(function (evt) {
369368

370369
if (evt.keyCode === aKeyCode && evt.ctrlKey === true) {

src/canvas-view/canvas/canvas-viewmodel.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var pfCanvas = {};
4949
// Compute the position of a connector in the graph.
5050
//
5151
pfCanvas.computeConnectorPos = function(node, connectorIndex, inputConnector) {
52+
console.log('d');
5253
return {
5354
x: node.x() + (inputConnector ? 0 : node.width ? node.width() : pfCanvas.defaultNodeWidth),
5455
y: node.y() + pfCanvas.computeConnectorY(connectorIndex)
@@ -157,6 +158,7 @@ var pfCanvas = {};
157158
//
158159
pfCanvas.NodeViewModel = function(nodeDataModel) {
159160
this.data = nodeDataModel;
161+
console.log('new node data', nodeDataModel.data);
160162

161163
// set the default width value of the node
162164
if (!this.data.width || this.data.width < 0) {
@@ -214,14 +216,14 @@ var pfCanvas = {};
214216
// X coordinate of the node.
215217
//
216218
this.x = function() {
217-
return this.data.x;
219+
return this.data.x || 0;
218220
};
219221

220222
//
221223
// Y coordinate of the node.
222224
//
223225
this.y = function() {
224-
return this.data.y;
226+
return this.data.y || 0;
225227
};
226228

227229
//
@@ -461,6 +463,7 @@ var pfCanvas = {};
461463
};
462464

463465
this.sourceCoordX = function() {
466+
console.log('a');
464467
return this.source.parentNode().x() + this.source.x();
465468
};
466469

@@ -484,6 +487,7 @@ var pfCanvas = {};
484487
};
485488

486489
this.destCoordX = function() {
490+
console.log('b', this.dest.parentNode().x(), this.dest.x());
487491
return this.dest.parentNode().x() + this.dest.x();
488492
};
489493

@@ -1010,6 +1014,7 @@ var pfCanvas = {};
10101014

10111015
for (var i = 0; i < this.nodes.length; ++i) {
10121016
var node = this.nodes[i];
1017+
console.log('c');
10131018
if (node.x() >= selectionRect.x
10141019
&& node.y() >= selectionRect.y
10151020
&& node.x() + node.width() <= selectionRect.x + selectionRect.width

src/canvas-view/canvas/canvas.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
<g class="svg-triangle" >
120120
<polyline points="4,152 14,140 24,152"></polyline>
121121
</g>
122-
<foreignobject ng-attr-x="{{node.x}}"
122+
<foreignobject x="0"
123123
ng-attr-y="{{node.height()+1}}"
124124
ng-mousedown="$event.stopPropagation()"
125125
height="100%"

0 commit comments

Comments
 (0)