-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.js
More file actions
142 lines (115 loc) · 3.1 KB
/
grid.js
File metadata and controls
142 lines (115 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var width = window.innerWidth;
var height = window.innerHeight;
var shadowOffset = 20;
var tween = null;
var blockSnapSize = 30;
var shadowRectangle = new Konva.Rect({
x: 0,
y: 0,
width: blockSnapSize * 1,
height: blockSnapSize * 1,
fill: '#FF7B17',
opacity: 0.6,
stroke: '#CF6412',
strokeWidth: 3,
dash: [20, 2]
});
function newRectangle(x, y, layer, stage, text) {
var group = new Konva.Group({
x: x,
y: y,
draggable: true
});
let rectangle = new Konva.Rect({
width: blockSnapSize * 1,
height: blockSnapSize * 1,
fill: '#fff',
stroke: '#ddd',
strokeWidth: 1,
shadowColor: 'black',
shadowBlur: 2,
shadowOffset: { x: 1, y: 1 },
shadowOpacity: 0.4,
draggable: false,
});
group.on('dragstart', e => {
shadowRectangle.show();
shadowRectangle.moveToTop();
group.moveToTop();
});
group.on('dragend', e => {
group.position({
x: Math.round(group.x() / blockSnapSize) * blockSnapSize,
y: Math.round(group.y() / blockSnapSize) * blockSnapSize
});
stage.batchDraw();
shadowRectangle.hide();
});
group.on('dragmove', e => {
shadowRectangle.position({
x: Math.round(group.x() / blockSnapSize) * blockSnapSize,
y: Math.round(group.y() / blockSnapSize) * blockSnapSize
});
stage.batchDraw();
});
var text = new Konva.Text({
fontSize: 16,
fontFamily: 'Arial',
text: text,
fill: 'black',
padding: 10,
align: "center",
verticalAlign: "middle",
});
group.on('mouseout', e => {
// $("#skillIdBtn_"+text.textArr[0].text).addClass("skill-on-grid");
});
group.on('mouseover', e => {
// $("#skillIdBtn_"+text.textArr[0].text).removeClass("skill-on-grid");
});
group.add(rectangle).add(text);
return group;
}
var stage = new Konva.Stage({
container: 'grid',
width: width,
height: height
});
stage.on('mousedown', (e) => {
const isRight = e.evt.button === 2;
if (isRight) {
if (e.target === stage) {
return;
}
if (e.target.parent.nodeType === "Group") {
e.target.parent.destroy();
layer.draw();
}
}
});
var gridLayer = new Konva.Layer();
var padding = blockSnapSize;
var MAX_X = 0;
var MAX_Y = 0;
for (var i = 0; i < width / padding; i++) {
gridLayer.add(new Konva.Line({
points: [Math.round(i * padding) + 0.5, 0, Math.round(i * padding) + 0.5, height],
stroke: '#ddd',
strokeWidth: 1
}));
MAX_X = i;
}
gridLayer.add(new Konva.Line({ points: [0, 0, 10, 10] }));
for (var j = 0; j < height / padding; j++) {
gridLayer.add(new Konva.Line({
points: [0, Math.round(j * padding), width, Math.round(j * padding)],
stroke: '#ddd',
strokeWidth: 0.5
}));
MAX_Y = j;
}
var layer = new Konva.Layer();
shadowRectangle.hide();
layer.add(shadowRectangle);
stage.add(gridLayer);
stage.add(layer);