(obj, el)
| 637 | } |
| 638 | |
| 639 | function selectObject(obj, el) { |
| 640 | var node; |
| 641 | if (el) { |
| 642 | node = d3.select(el); |
| 643 | } else { |
| 644 | graph.node.each(function (d) { |
| 645 | if (d === obj) { |
| 646 | node = d3.select(el = this); |
| 647 | } |
| 648 | }); |
| 649 | } |
| 650 | if (!node) return; |
| 651 | |
| 652 | if (node.classed('selected')) { |
| 653 | deselectObject(); |
| 654 | return; |
| 655 | } |
| 656 | deselectObject(false); |
| 657 | |
| 658 | selected = { |
| 659 | obj: obj, |
| 660 | el: el |
| 661 | }; |
| 662 | |
| 663 | highlightObject(null, obj); |
| 664 | |
| 665 | node.classed('selected', true); |
| 666 | $('#docs').html(createDocs(obj)); |
| 667 | $('#docs-container').scrollTop(0); |
| 668 | resize(true); |
| 669 | |
| 670 | var $graph = $('#graph-container'), |
| 671 | nodeRect = { |
| 672 | left: obj.x + obj.extent.left + graph.margin.left, |
| 673 | top: obj.y + obj.extent.top + graph.margin.top, |
| 674 | width: obj.extent.right - obj.extent.left, |
| 675 | height: obj.extent.bottom - obj.extent.top |
| 676 | }, |
| 677 | graphRect = { |
| 678 | left: $graph.scrollLeft(), |
| 679 | top: $graph.scrollTop(), |
| 680 | width: $graph.width(), |
| 681 | height: $graph.height() |
| 682 | }; |
| 683 | if (nodeRect.left < graphRect.left || |
| 684 | nodeRect.top < graphRect.top || |
| 685 | nodeRect.left + nodeRect.width > graphRect.left + graphRect.width || |
| 686 | nodeRect.top + nodeRect.height > graphRect.top + graphRect.height) { |
| 687 | |
| 688 | $graph.animate({ |
| 689 | scrollLeft: nodeRect.left + nodeRect.width / 2 - graphRect.width / 2, |
| 690 | scrollTop: nodeRect.top + nodeRect.height / 2 - graphRect.height / 2 |
| 691 | }, 500); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | function deselectObject(doResize) { |
| 696 | if (doResize || typeof doResize == 'undefined') { |
no test coverage detected