Node_Linear (subclass of Node_Base) is a node that represents a linear sequence of data used for most iterable type like list, tuple, set, etc.
| 10 | import memory_graph.utils as utils |
| 11 | |
| 12 | class Node_Linear(Node_Base): |
| 13 | """ |
| 14 | Node_Linear (subclass of Node_Base) is a node that represents a linear sequence |
| 15 | of data used for most iterable type like list, tuple, set, etc. |
| 16 | """ |
| 17 | |
| 18 | def __init__(self, data, children=None): |
| 19 | """ |
| 20 | Create a Node_Linear object. Use a Slicer to slice the children so the |
| 21 | Node_Base will not get to big or have too many childeren in the graph. |
| 22 | """ |
| 23 | super().__init__(data, Sequence1D(children)) |
| 24 | |
| 25 | def has_references(self, nodes, slices): |
| 26 | """ |
| 27 | Return if the node has references to other nodes. |
| 28 | """ |
| 29 | for index in slices: |
| 30 | child_id = id(self.children[index]) |
| 31 | if child_id in nodes: |
| 32 | child = nodes[child_id] |
| 33 | if not child.is_hidden_node(): |
| 34 | return True |
| 35 | return False |
| 36 | |
| 37 | def is_vertical(self, nodes, slices, id_to_slices): |
| 38 | """ |
| 39 | Return if the node is vertical or horizontal based on the orientation of the children. |
| 40 | """ |
| 41 | vertical = config_helpers.get_node_vertical(self, None) |
| 42 | if vertical is None: |
| 43 | vertical = not self.has_references(nodes, slices) |
| 44 | return vertical |
| 45 | |
| 46 | def fill_html_table(self, nodes, html_table, slices, id_to_slices): |
| 47 | """ |
| 48 | Fill the html_table with the children of the Node_Base. |
| 49 | """ |
| 50 | if slices is None: |
| 51 | return |
| 52 | vertical = self.is_vertical(nodes, slices, id_to_slices) |
| 53 | if config.horizontal: |
| 54 | vertical = not vertical # flip orientation if horizontal layout is set |
| 55 | if vertical: |
| 56 | html_table.reverse_rows() |
| 57 | if vertical: |
| 58 | self.fill_html_table_vertical(html_table, nodes, slices, id_to_slices) |
| 59 | else: |
| 60 | self.fill_html_table_horizontal(html_table, nodes, slices, id_to_slices) |
| 61 | |
| 62 | def fill_html_table_vertical(self, html_table, nodes, slices, id_to_slices): |
| 63 | """ |
| 64 | Helper function to fill the html_table with the children of the Node_Base in vertical orientation. |
| 65 | """ |
| 66 | show_index = not self.get_type() in config.no_index_types |
| 67 | for index in slices.table_iter(self.children.size()): |
| 68 | if index>=0: |
| 69 | if show_index: |
no outgoing calls
no test coverage detected