

lab18 subdirectory of your personal repo, the other submits a file report.txt in the lab18 subdirectory of your personal repo.graphed.html, graphed.js, graphed.css from the previous lab. Or if you couldn't get the previous lab to work, use this, this, and this.draw method of the circle node, draw on the canvas instead of generating SVG.
const canvas = ... const ctx = ... // No need for "if (canvas.getContext)" ctx.beginPath() ctx.arc(...) ctx.fillStyle = ... ctx.fill()
drawGrabber function.ctx.clearRect(0, 0, canvas.width, canvas.height)
function center(rect) {
return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 }
}
function createLineEdge() {
let start = undefined
let end = undefined
return {
connect: (s, e) => {
start = s
end = e
},
draw: () => {
const canvas = document.getElementById('graphpanel')
const ctx = canvas.getContext('2d')
ctx.beginPath()
const p = ... // Just pick the center of the bounds for now
const q = ... // Not the "connection points" that graphed2 uses
ctx.moveTo(p.x, p.y)
ctx.lineTo(q.x, q.y)
ctx.stroke()
}
}
}
Graph.java) to the Graph class:
connect(e, p1, p2) {
const n1 = this.findNode(p1)
const n2 = this.findNode(p2)
if (n1 !== undefined && n2 !== undefined) {
e.connect(n1, n2)
this.edges.push(e)
return true
}
return false
}
const e = createLineEdge()
graph.connect(e, { x: 20, y: 20 }, { x: 40, y: 40 })
Graph.draw.graphed <div height="150">
<div id="nodeContainer" style="position: absolute; width: 150; height: 150;">
</div>
<canvas id="graphpanel" style="position: absolute; z-index: 1" width="150" height="150"></canvas>
</div> const container = document.getElementById('nodeContainer')
const table = document.createElement('table')
const tr = document.createElement('tr')
const td = document.createElement('td')
table.appendChild(tr)
tr.appendChild(td)
table.style.position = 'absolute'
table.style.left = x + 'px'
table.style.top = y + 'px'
table.style.width = size + 'px'
table.style.height = size + 'px'
table.style.background = color
container.appendChild(table)
graphed.css:
table {
border-radius: 10px;
}