d2-ui
Version:
53 lines (41 loc) • 1.25 kB
text/coffeescript
Node = (x, y, size, id, color, background) ->
= id
= [x, y]
= size
= color
= background
Node.prototype =
distanceTo: (otherNode) ->
diff = [ [0] - otherNode.position[0], [1] - otherNode.position[1] ]
return Math.abs( Math.sqrt((diff[0] * diff[0]) + (diff[1] * diff[1])) )
isConnectedTo: (otherNode) ->
?[otherNode.id] is true or otherNode.connected?[ ] is true
connectTo: (otherNode, context) ->
if not
= {}
if not otherNode.connected
otherNode.connected = {}
[otherNode.id] = true
otherNode.connected[ ] = true
(otherNode, context)
drawLineTo: (otherNode, context) ->
context.beginPath()
context.moveTo( [0], [1] )
context.lineTo( otherNode.position[0], otherNode.position[1] )
context.strokeStyle =
context.stroke()
draw: (context) ->
context.beginPath()
context.arc(
[0],
[1],
,
0,
Math.PI * 2
)
context.fillStyle =
context.fill()
context.lineWidth = 2
context.strokeStyle =
context.stroke()
module.exports = Node