Пример #1
0
 def colour(self, colour):
     if isinstance(colour, str):
         colour = Colour(obj=colour)
     self._colour = colour
     if self._text_colour is None:
         self._text_colour = colour
         self._text_colour_based_on_main_colour = True
Пример #2
0
	def __init__(
			self, colour=DEFAULT_COLOUR, fill_colour=None, border_colour=None, opacity=None,
			font=DEFAULT_FONT, text_colour=None, text_size=DEFAULT_TEXT_SIZE,
			shape=DEFAULT_SHAPE, shape_style=DEFAULT_SHAPE_STYLE, lighter_fill=True
	):
		colour = colour or fill_colour or border_colour or DEFAULT_COLOUR
		colour = Colour(obj=colour)

		self._fill_colour_based_on_main_colour = False
		self._border_colour_based_on_main_colour = False
		self._text_colour_based_on_main_colour = False
		self._lighter_fill = lighter_fill

		self._colour = colour
		self._fill_colour = None
		self._border_colour = None
		self._text_colour = None

		self.fill_colour = fill_colour
		self.border_colour = border_colour
		self.text_colour = text_colour
		self.colour = colour

		self._opacity = opacity
		self._font = font
		self._text_size = text_size
		self._shape = shape
		self._shape_style = shape_style
    def background_colour(self, background_colour):
        """
		:type background_colour: Colour or str
		"""
        if not isinstance(background_colour, Colour):
            background_colour = Colour(obj=background_colour)
        self._background_colour = background_colour
Пример #4
0
    def __init__(self,
                 colour=DEFAULT_COLOUR,
                 opacity=DEFAULT_EDGE_OPACITY,
                 font=DEFAULT_FONT,
                 text_colour=None,
                 text_size=DEFAULT_EDGE_TEXT_SIZE,
                 arrow_size=DEFAULT_ARROW_SIZE,
                 label_style=DEFAULT_EDGE_LABEL_STYLE,
                 line_width=1):
        colour = colour or text_colour or DEFAULT_COLOUR
        colour = Colour(colour)
        self._colour = colour
        self._text_colour = None

        self._text_colour_based_on_main_colour = False

        self.text_colour = text_colour
        self.colour = colour

        self._opacity = opacity
        self._font = font
        self._text_size = text_size
        self._arrow_size = arrow_size
        self._label_style = label_style
        self._line_width = line_width
Пример #5
0
	def border_colour(self, border_colour):
		if border_colour is None:
			if self.colour is not None:
				self._border_colour = self.colour.darken_or_lighten(ratio=DEFAULT_NODE_COLOUR_DIFFERENCE_RATIO)
				self._border_colour_based_on_main_colour = True
		else:
			self._border_colour = Colour(border_colour)
			self._border_colour_based_on_main_colour = False
Пример #6
0
 def text_colour(self, text_colour):
     if text_colour is None:
         if self.colour is not None:
             self._text_colour = self.colour
             self._text_colour_based_on_main_colour = True
     else:
         self._text_colour = Colour(text_colour)
         self._text_colour_based_on_main_colour = False
Пример #7
0
	def fill_colour(self, fill_colour):
		if fill_colour is None:
			self._fill_colour = None
			if self.colour is not None:
				self._fill_colour = self.colour
				self._fill_colour_based_on_main_colour = True
		else:
			self._fill_colour = Colour(fill_colour)
			self._fill_colour_based_on_main_colour = False
Пример #8
0
 def add_colours(self, name, colour_scheme, background_colour):
     colour_scheme = Scheme.auto(obj=colour_scheme or DEFAULT_COLOUR_SCHEME)
     self._background_colour = Colour.auto(obj=background_colour)
     self._node_styles[name] = [
         create_node_colour_inheritance_style(colour=colour)
         for colour in colour_scheme.colours
     ]
     self._edge_styles[name] = [
         inherit_colour_from_start_node for colour in colour_scheme.colours
     ]
Пример #9
0
	def text_colour(self, text_colour):
		if text_colour is None:
			if self.fill_colour is not None:
				self._text_colour = self.fill_colour.farthest_gray
				self._text_colour_based_on_main_colour = True
			elif self.colour is not None:
				self._text_colour = self.colour.farthest_gray
				self._text_colour_based_on_main_colour = True
		else:
			self._text_colour = Colour(text_colour)
			self._text_colour_based_on_main_colour = False
Пример #10
0
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
Пример #11
0
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
Пример #12
0
	def colour(self, colour):
		if isinstance(colour, str):
			colour = Colour(obj=colour)
		self._colour = colour
		if self._fill_colour is None:
			if self._lighter_fill:
				self._fill_colour = colour.lighten(ratio=DEFAULT_NODE_COLOUR_DIFFERENCE_RATIO)
			else:
				self._fill_colour = colour.darken(ratio=DEFAULT_NODE_COLOUR_DIFFERENCE_RATIO)
			self._fill_colour_based_on_main_colour = True
		if self._border_colour is None:
			if self._lighter_fill:
				self._border_colour = colour.darken(ratio=DEFAULT_NODE_COLOUR_DIFFERENCE_RATIO / 3)
			else:
				self._border_colour = colour.lighten(ratio=DEFAULT_NODE_COLOUR_DIFFERENCE_RATIO / 3)
			self._border_colour_based_on_main_colour = True
		if self._text_colour is None:
			self._text_colour = self.fill_colour.farthest_gray
			self._text_colour_based_on_main_colour = True
Пример #13
0
from colouration import Colour


DEFAULT_COLOUR = Colour(hexadecimal='#AAAAAA')
DEFAULT_TEXT_SIZE = 10
DEFAULT_FONT = 'helvetica'
DEFAULT_SHAPE = 'box'
DEFAULT_SHAPE_STYLE = 'rounded, filled'
DEFAULT_NODE_COLOUR_DIFFERENCE_RATIO = 0.5


class NodeStyle:
	def __init__(
			self, colour=DEFAULT_COLOUR, fill_colour=None, border_colour=None, opacity=None,
			font=DEFAULT_FONT, text_colour=None, text_size=DEFAULT_TEXT_SIZE,
			shape=DEFAULT_SHAPE, shape_style=DEFAULT_SHAPE_STYLE, lighter_fill=True
	):
		colour = colour or fill_colour or border_colour or DEFAULT_COLOUR
		colour = Colour(obj=colour)

		self._fill_colour_based_on_main_colour = False
		self._border_colour_based_on_main_colour = False
		self._text_colour_based_on_main_colour = False
		self._lighter_fill = lighter_fill

		self._colour = colour
		self._fill_colour = None
		self._border_colour = None
		self._text_colour = None

		self.fill_colour = fill_colour
Пример #14
0
def colour(text, text_colour='blue', background_colour=None):
    return Colour(name=text_colour).colourize(string=text,
                                              background=background_colour)