| 575 | .attr("y1", d => d.source.y) |
| 576 | .attr("x2", d => d.target.x) |
| 577 | .attr("y2", d => d.target.y) |
| 578 | arrow |
| 579 | .attr("x1", d => d.source.x) |
| 580 | .attr("y1", d => d.source.y) |
| 581 | .attr("x2", d => d.target.x - (d.target.x - d.source.x) / 2) |
| 582 | .attr("y2", d => d.target.y - (d.target.y - d.source.y) / 2) |
| 583 | }); |
| 584 | |
| 585 | function dragstarted(event) { |
| 586 | if (!event.active) simulation.alphaTarget(0.3).restart(); |
| 587 | event.subject.fx = event.subject.x; |
| 588 | event.subject.fy = event.subject.y; |
| 589 | } |
| 590 | |
| 591 | function dragged(event) { |
| 592 | event.subject.fx = event.x; |
| 593 | event.subject.fy = event.y; |
| 594 | } |
| 595 | |
| 596 | function dragended(event) { |
| 597 | if (!event.active) simulation.alphaTarget(0); |
| 598 | event.subject.fx = null; |
| 599 | event.subject.fy = null; |
| 600 | } |
| 601 | |
| 602 | return svg.node(); |
| 603 | } |
| 604 | |
| 605 | function forceDirectedTree(data) { |
| 606 | const width = window.innerWidth; |
| 607 | const height = width; |
| 608 | |
| 609 | // Compute the graph and start the force simulation. |
| 610 | const root = d3.hierarchy(data); |
| 611 | const links = root.links(); |
| 612 | const nodes = root.descendants(); |
| 613 | |
| 614 | var radiusMap={ |
| 615 | num:1, |
| 616 | kw:1, |
| 617 | id:1, |
| 618 | str:1, |
| 619 | punc:1, |
| 620 | sp:1, |
| 621 | op:1, |
| 622 | Comment:2, |
| 623 | BlockStatement:2, |
| 624 | Condition:1, |
| 625 | Arguments:1, |
| 626 | Arg:1, |
| 627 | Variable:2, |
| 628 | ClassDefine:20, |
| 629 | InterfaceDefine:20, |
| 630 | NamespaceDefine:25, |
| 631 | MethodDefine:10, |
| 632 | PropertyDefine:5, |
| 633 | NewExpression:5, |
| 634 | CallExpression:5, |