forcegraph.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. define(["d3"], function (d3) {
  2. var margin = 200
  3. var NODE_RADIUS = 15
  4. var LINE_RADIUS = 12
  5. return function (config, linkScale, sidebar, router) {
  6. var self = this
  7. var canvas, ctx, screenRect
  8. var nodesDict, linksDict
  9. var zoomBehavior
  10. var force
  11. var el
  12. var doAnimation = false
  13. var intNodes = []
  14. var intLinks = []
  15. var highlight
  16. var highlightedNodes = []
  17. var highlightedLinks = []
  18. var nodes = []
  19. var unknownNodes = []
  20. var savedPanZoom
  21. var draggedNode
  22. var LINK_DISTANCE = 70
  23. function graphDiameter(nodes) {
  24. return Math.sqrt(nodes.length / Math.PI) * LINK_DISTANCE * 1.41
  25. }
  26. function savePositions() {
  27. if (!localStorageTest())
  28. return
  29. var save = intNodes.map( function (d) {
  30. return { id: d.o.id, x: d.x, y: d.y }
  31. })
  32. localStorage.setItem("graph/nodeposition", JSON.stringify(save))
  33. }
  34. function nodeName(d) {
  35. if (d.o.node && d.o.node.nodeinfo)
  36. return d.o.node.nodeinfo.hostname
  37. else
  38. return d.o.id
  39. }
  40. function dragstart() {
  41. var e = translateXY(d3.mouse(el))
  42. var nodes = intNodes.filter(function (d) {
  43. return distancePoint(e, d) < NODE_RADIUS
  44. })
  45. if (nodes.length === 0)
  46. return
  47. draggedNode = nodes[0]
  48. d3.event.sourceEvent.stopPropagation()
  49. d3.event.sourceEvent.preventDefault()
  50. draggedNode.fixed |= 2
  51. draggedNode.px = draggedNode.x
  52. draggedNode.py = draggedNode.y
  53. }
  54. function dragmove() {
  55. if (draggedNode) {
  56. var e = translateXY(d3.mouse(el))
  57. draggedNode.px = e.x
  58. draggedNode.py = e.y
  59. force.resume()
  60. }
  61. }
  62. function dragend() {
  63. if (draggedNode) {
  64. d3.event.sourceEvent.stopPropagation()
  65. d3.event.sourceEvent.preventDefault()
  66. draggedNode.fixed &= ~2
  67. draggedNode = undefined
  68. }
  69. }
  70. var draggableNode = d3.behavior.drag()
  71. .on("dragstart", dragstart)
  72. .on("drag", dragmove)
  73. .on("dragend", dragend)
  74. function animatePanzoom(translate, scale) {
  75. var translateP = zoomBehavior.translate()
  76. var scaleP = zoomBehavior.scale()
  77. if (!doAnimation) {
  78. zoomBehavior.translate(translate)
  79. zoomBehavior.scale(scale)
  80. panzoom()
  81. } else {
  82. var start = {x: translateP[0], y: translateP[1], scale: scaleP}
  83. var end = {x: translate[0], y: translate[1], scale: scale}
  84. var interpolate = d3.interpolateObject(start, end)
  85. var duration = 500
  86. var ease = d3.ease("cubic-in-out")
  87. d3.timer(function (t) {
  88. if (t >= duration)
  89. return true
  90. var v = interpolate(ease(t / duration))
  91. zoomBehavior.translate([v.x, v.y])
  92. zoomBehavior.scale(v.scale)
  93. panzoom()
  94. return false
  95. })
  96. }
  97. }
  98. var translateP, scaleP
  99. function onPanZoom() {
  100. savedPanZoom = {translate: zoomBehavior.translate(),
  101. scale: zoomBehavior.scale()}
  102. panzoom()
  103. }
  104. function panzoom() {
  105. var translate = zoomBehavior.translate()
  106. var scale = zoomBehavior.scale()
  107. panzoomReal(translate, scale)
  108. }
  109. function panzoomReal(translate, scale) {
  110. screenRect = {left: -translate[0] / scale, top: -translate[1] / scale,
  111. right: (canvas.width - translate[0]) / scale,
  112. bottom: (canvas.height - translate[1]) / scale}
  113. requestAnimationFrame(redraw)
  114. }
  115. function getSize() {
  116. var sidebarWidth = sidebar()
  117. var width = el.offsetWidth - sidebarWidth
  118. var height = el.offsetHeight
  119. return [width, height]
  120. }
  121. function panzoomTo(a, b) {
  122. var sidebarWidth = sidebar()
  123. var size = getSize()
  124. var targetWidth = Math.max(1, b[0] - a[0])
  125. var targetHeight = Math.max(1, b[1] - a[1])
  126. var scaleX = size[0] / targetWidth
  127. var scaleY = size[1] / targetHeight
  128. var scaleMax = zoomBehavior.scaleExtent()[1]
  129. var scale = 0.5 * Math.min(scaleMax, Math.min(scaleX, scaleY))
  130. var centroid = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2]
  131. var x = -centroid[0] * scale + size[0] / 2
  132. var y = -centroid[1] * scale + size[1] / 2
  133. var translate = [x + sidebarWidth, y]
  134. animatePanzoom(translate, scale)
  135. }
  136. function updateHighlight(nopanzoom) {
  137. highlightedNodes = []
  138. highlightedLinks = []
  139. if (highlight !== undefined)
  140. if (highlight.type === "node") {
  141. var n = nodesDict[highlight.o.nodeinfo.node_id]
  142. if (n) {
  143. highlightedNodes = [n]
  144. if (!nopanzoom)
  145. panzoomTo([n.x, n.y], [n.x, n.y])
  146. }
  147. return
  148. } else if (highlight.type === "link") {
  149. var l = linksDict[highlight.o.id]
  150. if (l) {
  151. highlightedLinks = [l]
  152. if (!nopanzoom) {
  153. var x = d3.extent([l.source, l.target], function (d) { return d.x })
  154. var y = d3.extent([l.source, l.target], function (d) { return d.y })
  155. panzoomTo([x[0], y[0]], [x[1], y[1]])
  156. }
  157. }
  158. return
  159. }
  160. if (!nopanzoom)
  161. if (!savedPanZoom)
  162. panzoomTo([0, 0], force.size())
  163. else
  164. animatePanzoom(savedPanZoom.translate, savedPanZoom.scale)
  165. }
  166. function drawLabel(d) {
  167. var neighbours = d.neighbours.filter(function (d) {
  168. return !d.link.o.vpn
  169. })
  170. var sum = neighbours.reduce(function (a, b) {
  171. return [a[0] + b.node.x, a[1] + b.node.y]
  172. }, [0, 0])
  173. var sumCos = sum[0] - d.x * neighbours.length
  174. var sumSin = sum[1] - d.y * neighbours.length
  175. var angle = Math.PI / 2
  176. if (neighbours.length > 0)
  177. angle = Math.PI + Math.atan2(sumSin, sumCos)
  178. var cos = Math.cos(angle)
  179. var sin = Math.sin(angle)
  180. var width = d.labelWidth
  181. var height = d.labelHeight
  182. var x = d.x + d.labelA * Math.pow(Math.abs(cos), 2 / 5) * Math.sign(cos) - width / 2
  183. var y = d.y + d.labelB * Math.pow(Math.abs(sin), 2 / 5) * Math.sign(sin) - height / 2
  184. ctx.drawImage(d.label, x, y, width, height)
  185. }
  186. function visibleLinks(d) {
  187. return (d.source.x > screenRect.left && d.source.x < screenRect.right &&
  188. d.source.y > screenRect.top && d.source.y < screenRect.bottom) ||
  189. (d.target.x > screenRect.left && d.target.x < screenRect.right &&
  190. d.target.y > screenRect.top && d.target.y < screenRect.bottom) ||
  191. d.o.vpn
  192. }
  193. function visibleNodes(d) {
  194. return d.x + margin > screenRect.left && d.x - margin < screenRect.right &&
  195. d.y + margin > screenRect.top && d.y - margin < screenRect.bottom
  196. }
  197. function redraw() {
  198. var translate = zoomBehavior.translate()
  199. var scale = zoomBehavior.scale()
  200. var links = intLinks.filter(visibleLinks)
  201. var xExtent = d3.extent(intNodes, function (d) { return d.px })
  202. var yExtent = d3.extent(intNodes, function (d) { return d.py })
  203. if (translateP) {
  204. ctx.save()
  205. ctx.translate(translateP[0], translateP[1])
  206. ctx.scale(scaleP, scaleP)
  207. ctx.clearRect(xExtent[0] - margin, yExtent[0] - margin,
  208. xExtent[1] - xExtent[0] + 2 * margin,
  209. yExtent[1] - yExtent[0] + 2 * margin)
  210. ctx.restore()
  211. }
  212. ctx.save()
  213. ctx.translate(translate[0], translate[1])
  214. ctx.scale(scale, scale)
  215. if (!translateP)
  216. ctx.clearRect(xExtent[0] - margin, yExtent[0] - margin,
  217. xExtent[1] - xExtent[0] + 2 * margin,
  218. yExtent[1] - yExtent[0] + 2 * margin)
  219. // Remeber last translate/scale state
  220. translateP = translate
  221. scaleP = scale
  222. var clientColor = "rgba(230, 50, 75, 1.0)"
  223. var unknownColor = "#D10E2A"
  224. var nodeColor = "#F2E3C6"
  225. var highlightColor = "rgba(252, 227, 198, 0.15)"
  226. var nodeRadius = 6
  227. // -- draw links --
  228. ctx.save()
  229. links.forEach(function (d) {
  230. var dx = d.target.x - d.source.x
  231. var dy = d.target.y - d.source.y
  232. var a = Math.sqrt(dx * dx + dy * dy)
  233. dx /= a
  234. dy /= a
  235. ctx.beginPath()
  236. ctx.moveTo(d.source.x + dx * nodeRadius, d.source.y + dy * nodeRadius)
  237. ctx.lineTo(d.target.x - dx * nodeRadius, d.target.y - dy * nodeRadius)
  238. ctx.strokeStyle = d.color
  239. ctx.globalAlpha = d.o.vpn ? 0.1 : 0.8
  240. ctx.lineWidth = d.o.vpn ? 1.5 : 2.5
  241. ctx.stroke()
  242. })
  243. ctx.restore()
  244. // -- draw labels --
  245. if (scale > 0.9)
  246. intNodes.filter(visibleNodes).forEach(drawLabel, scale)
  247. // -- draw unknown nodes --
  248. ctx.beginPath()
  249. unknownNodes.filter(visibleNodes).forEach(function (d) {
  250. ctx.moveTo(d.x + nodeRadius, d.y)
  251. ctx.arc(d.x, d.y, nodeRadius, 0, 2 * Math.PI)
  252. })
  253. ctx.strokeStyle = unknownColor
  254. ctx.lineWidth = nodeRadius
  255. ctx.stroke()
  256. // -- draw nodes --
  257. ctx.beginPath()
  258. nodes.filter(visibleNodes).forEach(function (d) {
  259. ctx.moveTo(d.x + nodeRadius, d.y)
  260. ctx.arc(d.x, d.y, nodeRadius, 0, 2 * Math.PI)
  261. })
  262. ctx.strokeStyle = nodeColor
  263. ctx.lineWidth = nodeRadius
  264. ctx.stroke()
  265. // -- draw clients --
  266. ctx.save()
  267. ctx.beginPath()
  268. nodes.filter(visibleNodes).forEach(function (d) {
  269. var clients = d.o.node.statistics.clients
  270. if (clients === 0)
  271. return
  272. var startDistance = 16
  273. var radius = 3
  274. var a = 1.2
  275. var startAngle = Math.PI
  276. for (var orbit = 0, i = 0; i < clients; orbit++) {
  277. var distance = startDistance + orbit * 2 * radius * a
  278. var n = Math.floor((Math.PI * distance) / (a * radius))
  279. var delta = clients - i
  280. for (var j = 0; j < Math.min(delta, n); i++, j++) {
  281. var angle = 2 * Math.PI / n * j
  282. var x = d.x + distance * Math.cos(angle + startAngle)
  283. var y = d.y + distance * Math.sin(angle + startAngle)
  284. ctx.moveTo(x, y)
  285. ctx.arc(x, y, radius, 0, 2 * Math.PI)
  286. }
  287. }
  288. })
  289. ctx.fillStyle = clientColor
  290. ctx.globalCompositeOperation = "overlay"
  291. ctx.fill()
  292. ctx.restore()
  293. // -- draw node highlights --
  294. if (highlightedNodes.length) {
  295. ctx.save()
  296. ctx.shadowColor = "rgba(255, 255, 255, 1.0)"
  297. ctx.shadowBlur = 10 * nodeRadius
  298. ctx.shadowOffsetX = 0
  299. ctx.shadowOffsetY = 0
  300. ctx.globalCompositeOperation = "lighten"
  301. ctx.fillStyle = highlightColor
  302. highlightedNodes.forEach(function (d) {
  303. ctx.beginPath()
  304. ctx.moveTo(d.x + 5 * nodeRadius, d.y)
  305. ctx.arc(d.x, d.y, 5 * nodeRadius, 0, 2 * Math.PI)
  306. ctx.fill()
  307. ctx.restore()
  308. })
  309. ctx.restore()
  310. }
  311. // -- draw link highlights --
  312. if (highlightedLinks.length) {
  313. ctx.save()
  314. ctx.lineWidth = 2 * 5 * nodeRadius
  315. ctx.shadowColor = "rgba(255, 255, 255, 1.0)"
  316. ctx.shadowBlur = 10 * nodeRadius
  317. ctx.shadowOffsetX = 0
  318. ctx.shadowOffsetY = 0
  319. ctx.globalCompositeOperation = "lighten"
  320. ctx.strokeStyle = highlightColor
  321. ctx.lineCap = "round"
  322. highlightedLinks.forEach(function (d) {
  323. ctx.beginPath()
  324. ctx.moveTo(d.source.x, d.source.y)
  325. ctx.lineTo(d.target.x, d.target.y)
  326. ctx.stroke()
  327. })
  328. ctx.restore()
  329. }
  330. ctx.restore()
  331. }
  332. function tickEvent() {
  333. redraw()
  334. }
  335. function resizeCanvas() {
  336. var r = window.devicePixelRatio
  337. canvas.width = el.offsetWidth * r
  338. canvas.height = el.offsetHeight * r
  339. canvas.style.width = el.offsetWidth + "px"
  340. canvas.style.height = el.offsetHeight + "px"
  341. ctx.setTransform(1, 0, 0, 1, 0, 0)
  342. ctx.scale(r, r)
  343. requestAnimationFrame(redraw)
  344. }
  345. function distance(a, b) {
  346. return Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)
  347. }
  348. function distancePoint(a, b) {
  349. return Math.sqrt(distance(a, b))
  350. }
  351. function distanceLink(p, a, b) {
  352. /* http://stackoverflow.com/questions/849211 */
  353. var l2 = distance(a, b)
  354. if (l2 === 0)
  355. return distance(p, a)
  356. var t = ((p.x - a.x) * (b.x - a.x) + (p.y - a.y) * (b.y - a.y)) / l2
  357. if (t < 0)
  358. return distance(p, a)
  359. if (t > 1)
  360. return distance(p, b)
  361. return Math.sqrt(distance(p, { x: a.x + t * (b.x - a.x),
  362. y: a.y + t * (b.y - a.y) }))
  363. }
  364. function translateXY(d) {
  365. var translate = zoomBehavior.translate()
  366. var scale = zoomBehavior.scale()
  367. return {x: (d[0] - translate[0]) / scale,
  368. y: (d[1] - translate[1]) / scale
  369. }
  370. }
  371. function onClick() {
  372. if (d3.event.defaultPrevented)
  373. return
  374. var e = translateXY(d3.mouse(el))
  375. var nodes = intNodes.filter(function (d) {
  376. return distancePoint(e, d) < NODE_RADIUS
  377. })
  378. if (nodes.length > 0) {
  379. router.node(nodes[0].o.node)()
  380. return
  381. }
  382. var links = intLinks.filter(function (d) {
  383. return !d.o.vpn
  384. }).filter(function (d) {
  385. return distanceLink(e, d.source, d.target) < LINE_RADIUS
  386. })
  387. if (links.length > 0) {
  388. router.link(links[0].o)()
  389. return
  390. }
  391. }
  392. function zoom(z, scale) {
  393. var size = getSize()
  394. var newSize = [size[0] / scale, size[1] / scale]
  395. var sidebarWidth = sidebar()
  396. var delta = [size[0] - newSize[0], size[1] - newSize[1]]
  397. var translate = z.translate()
  398. var translateNew = [sidebarWidth + (translate[0] - sidebarWidth - delta[0] / 2) * scale, (translate[1] - delta[1] / 2) * scale]
  399. animatePanzoom(translateNew, z.scale() * scale)
  400. }
  401. function keyboardZoom(z) {
  402. return function () {
  403. var e = d3.event
  404. if (e.altKey || e.ctrlKey || e.metaKey)
  405. return
  406. if (e.keyCode === 43)
  407. zoom(z, 1.41)
  408. if (e.keyCode === 45)
  409. zoom(z, 1 / 1.41)
  410. }
  411. }
  412. el = document.createElement("div")
  413. el.classList.add("graph")
  414. zoomBehavior = d3.behavior.zoom()
  415. .scaleExtent([1 / 3, 3])
  416. .on("zoom", onPanZoom)
  417. .translate([sidebar(), 0])
  418. canvas = d3.select(el)
  419. .attr("tabindex", 1)
  420. .on("keypress", keyboardZoom(zoomBehavior))
  421. .call(zoomBehavior)
  422. .append("canvas")
  423. .on("click", onClick)
  424. .call(draggableNode)
  425. .node()
  426. ctx = canvas.getContext("2d")
  427. force = d3.layout.force()
  428. .charge(-250)
  429. .gravity(0.1)
  430. .linkDistance(function (d) {
  431. if (d.o.vpn)
  432. return 0
  433. else
  434. return LINK_DISTANCE
  435. })
  436. .linkStrength(function (d) {
  437. if (d.o.vpn)
  438. return 0
  439. else
  440. return Math.max(0.5, 1 / d.o.tq)
  441. })
  442. .on("tick", tickEvent)
  443. .on("end", savePositions)
  444. window.addEventListener("resize", resizeCanvas)
  445. panzoom()
  446. self.setData = function (data) {
  447. var oldNodes = {}
  448. intNodes.forEach( function (d) {
  449. oldNodes[d.o.id] = d
  450. })
  451. intNodes = data.graph.nodes.map( function (d) {
  452. var e
  453. if (d.id in oldNodes)
  454. e = oldNodes[d.id]
  455. else
  456. e = {}
  457. e.o = d
  458. return e
  459. })
  460. var newNodesDict = {}
  461. intNodes.forEach( function (d) {
  462. newNodesDict[d.o.id] = d
  463. })
  464. var oldLinks = {}
  465. intLinks.forEach( function (d) {
  466. oldLinks[d.o.id] = d
  467. })
  468. intLinks = data.graph.links.map( function (d) {
  469. var e
  470. if (d.id in oldLinks)
  471. e = oldLinks[d.id]
  472. else
  473. e = {}
  474. e.o = d
  475. e.source = newNodesDict[d.source.id]
  476. e.target = newNodesDict[d.target.id]
  477. if (d.vpn)
  478. e.color = "rgba(255, 255, 255, " + (0.6 / d.tq) + ")"
  479. else
  480. e.color = linkScale(d.tq).hex()
  481. return e
  482. })
  483. linksDict = {}
  484. nodesDict = {}
  485. intNodes.forEach(function (d) {
  486. d.neighbours = {}
  487. if (d.o.node)
  488. nodesDict[d.o.node.nodeinfo.node_id] = d
  489. var name = nodeName(d)
  490. var offset = 8
  491. var lineWidth = 3
  492. var buffer = document.createElement("canvas")
  493. var r = window.devicePixelRatio
  494. var bctx = buffer.getContext("2d")
  495. bctx.font = "11px Roboto"
  496. var width = bctx.measureText(name).width
  497. var scale = zoomBehavior.scaleExtent()[1] * r
  498. buffer.width = (width + 2 * lineWidth) * scale
  499. buffer.height = (16 + 2 * lineWidth) * scale
  500. bctx.scale(scale, scale)
  501. bctx.textBaseline = "middle"
  502. bctx.textAlign = "center"
  503. bctx.lineWidth = lineWidth
  504. bctx.lineCap = "round"
  505. bctx.strokeStyle = "rgba(53, 54, 52, 0.1)"
  506. bctx.fillStyle = "rgba(242, 227, 198, 0.8)"
  507. bctx.miterLimit = 2
  508. bctx.strokeText(name, buffer.width / (2 * scale), buffer.height / (2 * scale))
  509. bctx.fillText(name, buffer.width / (2 * scale), buffer.height / (2 * scale))
  510. d.label = buffer
  511. d.labelWidth = buffer.width / scale
  512. d.labelHeight = buffer.height / scale
  513. d.labelA = offset + buffer.width / (2 * scale)
  514. d.labelB = offset + buffer.height / (2 * scale)
  515. })
  516. intLinks.forEach(function (d) {
  517. d.source.neighbours[d.target.o.id] = {node: d.target, link: d}
  518. d.target.neighbours[d.source.o.id] = {node: d.source, link: d}
  519. if (d.o.source.node && d.o.target.node)
  520. linksDict[d.o.id] = d
  521. })
  522. intNodes.forEach(function (d) {
  523. d.neighbours = Object.keys(d.neighbours).map(function (k) {
  524. return d.neighbours[k]
  525. })
  526. })
  527. nodes = intNodes.filter(function (d) { return d.o.node })
  528. unknownNodes = intNodes.filter(function (d) { return !d.o.node })
  529. if (localStorageTest()) {
  530. var save = JSON.parse(localStorage.getItem("graph/nodeposition"))
  531. if (save) {
  532. var nodePositions = {}
  533. save.forEach( function (d) {
  534. nodePositions[d.id] = d
  535. })
  536. intNodes.forEach( function (d) {
  537. if (nodePositions[d.o.id] && (d.x === undefined || d.y === undefined)) {
  538. d.x = nodePositions[d.o.id].x
  539. d.y = nodePositions[d.o.id].y
  540. }
  541. })
  542. }
  543. }
  544. var diameter = graphDiameter(intNodes)
  545. force.nodes(intNodes)
  546. .links(intLinks)
  547. .size([diameter, diameter])
  548. updateHighlight(true)
  549. force.start()
  550. resizeCanvas()
  551. }
  552. self.resetView = function () {
  553. highlight = undefined
  554. updateHighlight()
  555. doAnimation = true
  556. }
  557. self.gotoNode = function (d) {
  558. highlight = {type: "node", o: d}
  559. updateHighlight()
  560. doAnimation = true
  561. }
  562. self.gotoLink = function (d) {
  563. highlight = {type: "link", o: d}
  564. updateHighlight()
  565. doAnimation = true
  566. }
  567. self.destroy = function () {
  568. force.stop()
  569. canvas.remove()
  570. force = null
  571. if (el.parentNode)
  572. el.parentNode.removeChild(el)
  573. }
  574. self.render = function (d) {
  575. d.appendChild(el)
  576. resizeCanvas()
  577. updateHighlight()
  578. }
  579. return self
  580. }
  581. })