-
Notifications
You must be signed in to change notification settings - Fork 1
/
groups.html
258 lines (203 loc) · 5.74 KB
/
groups.html
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.5/seedrandom.min.js"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
margin: 5%;
}
svg {
margin: 1%;
background-color: white;
}
.algorithm_header {
font-size: 2em;
font-weight: bold;
margin-top: 100px;
margin-bottom: 20px;
}
.rowDiv {
margin-top: 20px;
}
</style>
<body>
</body>
<script src="./dist/dist.js"></script>
<script>
const svg_height = 300
const svg_width = 600
const svg_height_s = 300
const svg_width_s = 600
const svg_height_m = 800
const svg_width_m = 1600
const svg_height_l = 1600
const svg_width_l = 3200
const attr_height = 15
const table_width = 70
const depth_distance = 150
let header_height = attr_height
let table_vert_space = 100
var depth = 3;
var seed = "hello."
var tableDistribution = [2, 3];
g = new GraphGenerator(depth, seed, tableDistribution)
g = g.generate()
g.setExactWeights()
g.sortGraph()
group = new Group()
table1 = g.tables.find(t => t.name == "T1y0")
group.addTable(table1)
table1 = g.tables.find(t => t.name == "T2y0")
group.addTable(table1)
g.addGroup(group)
svg = d3.select('body')
.append('svg')
.attr('width', svg_width_s)
.attr('height', svg_height_s)
drawGraph(svg, g)
rdiv = d3.select('body')
.append('div')
.text("solution:")
runLpWorker(g, rdiv, svg_width_s, svg_height_s)
d3.select('body')
.append('div')
.html("<br><br><br><br>**************************<br>**************************<br>**************************<br><br><br>")
g2 = new Graph();
a = new Table("a", "a", true, 0)
b = new Table("b", "b", true, 1)
c = new Table("c", "c", true, 1)
d = new Table("d", "d", true, 1)
e = new Table("e", "e", true, 1)
f = new Table("f", "f", true, 2)
g = new Table("g", "g", true, 2)
h = new Table("h", "h", true, 2)
i = new Table("i", "i", true, 2)
g2.addTable(a)
g2.addTable(b)
g2.addTable(c)
g2.addTable(d)
g2.addTable(e)
// g2.addTable(f)
g2.addTable(g)
g2.addTable(h)
g2.addTable(i)
a1 = new Attribute(a, "a1")
a.attributes.push(a1)
a2 = new Attribute(a, "a2")
a.attributes.push(a2)
b1 = new Attribute(b, "b1")
b.attributes.push(b1)
c1 = new Attribute(c, "c1")
c.attributes.push(c1)
d1 = new Attribute(d, "d1")
d.attributes.push(d1)
e1 = new Attribute(e, "e1")
e.attributes.push(e1)
// f1 = new Attribute(f, "f1")
// f.attributes.push(f1)
g1 = new Attribute(g, "g1")
g.attributes.push(g1)
h1 = new Attribute(h, "h1")
h.attributes.push(h1)
i1 = new Attribute(i, "i1")
i.attributes.push(i1)
g2.setExactWeights()
g2.sortGraph()
ed = new Edge(a, a1, c, c1)
g2.addEdge(ed)
ed = new Edge(a, a1, b, b1)
g2.addEdge(ed)
ed = new Edge(a, a1, d, d1)
g2.addEdge(ed)
ed = new Edge(a, a1, e, e1)
g2.addEdge(ed)
ed = new Edge(b, b1, i, i1)
g2.addEdge(ed)
ed = new Edge(c, c1, h, h1)
g2.addEdge(ed)
ed = new Edge(d, d1, g, g1)
g2.addEdge(ed)
group = new Group()
table1 = g2.tables.find(t => t.name == "c")
group.addTable(table1)
table1 = g2.tables.find(t => t.name == "h")
group.addTable(table1)
table1 = g2.tables.find(t => t.name == "d")
group.addTable(table1)
table1 = g2.tables.find(t => t.name == "g")
group.addTable(table1)
g2.addGroup(group)
svg2 = d3.select('body')
.append('svg')
.attr('width', svg_width_s*1.4)
.attr('height', svg_height_s*1.4)
drawGraph(svg2, g2)
rdiv2 = d3.select('body')
.append('div')
.text("solution:")
runLpWorker(g2, rdiv2, svg_width_s*2, svg_height_s*2)
d3.select('body')
.append('div')
.html("<br><br><br><br>**************************<br>**************************<br>**************************<br><br><br>")
var depth = 5;
var seed = "aaa."
var tableDistribution = [4, 5];
g3 = new GraphGenerator(depth, seed, tableDistribution)
g3 = g3.generate()
g3.setExactWeights()
g3.sortGraph()
// group = new Group()
// table1 = g3.tables.find(t => t.name == "T1y0")
// group.addTable(table1)
// table1 = g.tables.find(t => t.name == "T2y0")
// group.addTable(table1)
// g.addGroup(group)
svg = d3.select('body')
.append('svg')
.attr('width', svg_width_s*2)
.attr('height', svg_height_s*2)
drawGraph(svg, g3)
rdiv3 = d3.select('body')
.append('div')
.text("solution:")
runLpWorker(g3, rdiv3, svg_width_s*3, svg_height_s*3)
async function runLpWorker(g, rowDiv, cur_svg_width, cur_svg_height) {
let myWorker = new Worker('./js/worker.js')
myWorker.postMessage({'cmd': 'lp', 'graph': g});
let finished = false;
let algorithm;
myWorker.addEventListener('message', (msg) => {
finished = true;
algorithm = msg.data.algorithm;
for (table of msg.data.graph.tables){
t1 = g.tables.find(t => t.name == table.name)
t1.weight = table.weight
for (attribute of table.attributes){
a1 = t1.attributes.find(a => a.name == attribute.name)
a1.weight = attribute.weight
}
}
g.setExactWeights()
g.sortGraph()
g.adjustTableYPosition()
svg = rowDiv
.append('div')
.style('width', '50%')
.append('svg')
.attr('class', 'vis-svg')
.attr('easypz', '{"applyTransformTo":"svg > *"}')
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 " + cur_svg_width + " " + cur_svg_height)
drawGraph(svg, g, algorithm)
});
setTimeout(() => {
myWorker.terminate()
if (!finished) console.log('worker terminated')
}, 1000000);
}
</script>
</html>