| 646 | self._graph = graph |
| 647 | |
| 648 | def write(self, file_name): |
| 649 | |
| 650 | print('Writing to '+file_name) |
| 651 | |
| 652 | output_topics = self._graph.output_topics |
| 653 | output_scopes = self._graph.output_scopes |
| 654 | topic_colors = self._graph.topic_colors |
| 655 | |
| 656 | data = {} |
| 657 | nodes = [] |
| 658 | |
| 659 | # nodes |
| 660 | # (sort by length, such that short names are last. The rendering order |
| 661 | # will be the same, so that in case of an overlap, the shorter label |
| 662 | # will be on top) |
| 663 | for scope_tuple in sorted(output_scopes.items(), key=(lambda st: len(st[0])), reverse=True): |
| 664 | node = {} |
| 665 | node['id'] = 'm_'+scope_tuple[0] |
| 666 | node['name'] = scope_tuple[0] |
| 667 | node['type'] = scope_tuple[1].typename |
| 668 | node['color'] = '#666666' |
| 669 | # TODO: add url to open module documentation? |
| 670 | nodes.append(node) |
| 671 | |
| 672 | for topic in sorted(output_topics, key=len, reverse=True): |
| 673 | node = {} |
| 674 | node['id'] = 't_'+topic |
| 675 | node['name'] = topic |
| 676 | node['type'] = 'topic' |
| 677 | node['color'] = topic_colors[topic] |
| 678 | # url is opened when double-clicking on the node |
| 679 | node['url'] = 'https://github.com/PX4/PX4-Autopilot/blob/main/msg/'+topic_filename(topic)+'.msg' |
| 680 | nodes.append(node) |
| 681 | |
| 682 | data['nodes'] = nodes |
| 683 | |
| 684 | edges = [] |
| 685 | |
| 686 | |
| 687 | # edges |
| 688 | for name,scope in output_scopes.items(): |
| 689 | for topic in scope.publications: |
| 690 | if topic in output_topics: |
| 691 | edge = {} |
| 692 | edge['source'] = 'm_'+name |
| 693 | edge['target'] = 't_'+topic |
| 694 | edge['color'] = topic_colors[topic] |
| 695 | edge['style'] = 'dashed' |
| 696 | edges.append(edge) |
| 697 | |
| 698 | for name,scope in output_scopes.items(): |
| 699 | for topic in scope.subscriptions: |
| 700 | if topic in output_topics: |
| 701 | edge = {} |
| 702 | edge['source'] = 't_'+topic |
| 703 | edge['target'] = 'm_'+name |
| 704 | edge['color'] = topic_colors[topic] |
| 705 | edge['style'] = 'normal' |