Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def limit_tree_map(limit, root):
tree_layers = TreeMapReducer.create_tree_layers(root)
mapper = TreeMapReducer.reduce_tree_map_children(limit, tree_layers)
return mapper[root]
def create_next_tree_layer(tree_layer, tree_layers):
new_tree_layer = TreeMapReducer.create_tree_layer(tree_layer.get_node_layers())
if len(new_tree_layer.get_node_layers()) != 0:
tree_layers.append(new_tree_layer)
TreeMapReducer.create_next_tree_layer(new_tree_layer, tree_layers)
def create_tree_layers(root):
tree_layers = []
tree_layer = TreeLayer()
tree_layer.add_node_layer(NodeLayer(root, root.children))
tree_layers.append(tree_layer)
TreeMapReducer.create_next_tree_layer(tree_layer, tree_layers)
return tree_layers
def limit_tree_map(limit, root):
tree_layers = TreeMapReducer.create_tree_layers(root)
mapper = TreeMapReducer.reduce_tree_map_children(limit, tree_layers)
return mapper[root]
def transform(self):
tree_map = self
tree_map.process(tree_map.graphics_list)
count_nodes = tree_map.count_nodes(self.graphics_list, self.increase_by_one, 0)
to_many_rows = count_nodes > TreeMapChart.ROWS_LIMIT
if to_many_rows:
tree_map = copy.copy(self)
tree_map.totalNumberOfPoints = count_nodes
tree_map.rowsLimitItems = TreeMapChart.ROWS_LIMIT
tree_map.graphics_list = TreeMapReducer.limit_tree_map(TreeMapChart.ROWS_LIMIT, self.graphics_list)
tree_map.numberOfPointsToDisplay = str(
tree_map.count_nodes(tree_map.graphics_list, self.increase_by_one_when_leaf, 0)
) + " leaves"
tree_map.tooManyRows = to_many_rows
return super(TreeMapChart, tree_map).transform()