def get_style(node, pale_ratio, divergence_ratio, main_style): """ :type node: Node :rtype: NodeStyle """ if is_root_or_parents_are_in_loop(node): if main_style is None: return node.style.copy() else: return main_style.copy() else: if len(node.parents) == 1: parent = node.parents[0] num_siblings = len(parent.children) rank = node.get_child_rank(parent=parent) if main_style is None: style = get_style( node=parent, pale_ratio=pale_ratio, divergence_ratio=divergence_ratio, main_style=main_style ) else: style = main_style if num_siblings == 0: colour = style.colour.copy(keep_id=True) else: colour = style.colour.increase_hue( amount=divergence_ratio * get_diverging_number(i=rank, n=num_siblings, reverse=False) ) #colour = colour.pale(ratio=pale_ratio) colour.saturation = colour.saturation * 3 / 4 new_style = style.copy() new_style.reset_colours() new_style.colour = colour return new_style else: styles = [ get_style(node=parent, pale_ratio=pale_ratio, divergence_ratio=0, main_style=main_style) for parent in node.parents if not node.is_in_loop_with(parent) ] colours = [style.colour for style in styles] if main_style is None: style = styles[0] else: style = main_style colour = Colour.mix(colours=colours).pale(ratio=pale_ratio) new_style = style.copy() new_style.reset_colours() new_style.colour = colour return new_style
def mix_node_style_of_parents(node, font=DEFAULT_FONT, shape=DEFAULT_SHAPE, shape_style=DEFAULT_SHAPE_STYLE): """ :type node: abstract.Node.Node :rtype: NodeStyle """ scheme = node.graph.colour_scheme style = None colour = None if node.has_parents(): candidates = [] for parent in node.parents: if not parent.is_in_loop() or not parent.is_style_callable(): style = parent.compiled_style.copy() candidates.append((style, node.get_child_rank(parent=parent), len(parent.children))) if len(candidates) > 0: colour = Colour.mix(colours=[ style.colour.increase_hue( amount=0.1 * get_diverging_number(i=rank, n=num_siblings, reverse=False) ) for style, rank, num_siblings in candidates ]) colour = colour.pale(ratio=0.2) colour.weight = colour.weight**(0.5) #colour = colour.mix_with_gray(gray_weight=2) style = NodeStyle(colour=colour, font=font, shape=shape, shape_style=shape_style) if style is None or colour is None: colour = scheme.least_used_colour style = NodeStyle(colour=colour, font=font, shape=shape, shape_style=shape_style) return style