def __init__(self, tail, head, **kwargs): self.tail = tail self.head = head self.directional = process_directional(True, kwargs) if self.tail == self.head: sys.exit('Error: Cannot connect a node to itself. (' + str(self.tail) + ' -/-> ' + str(self.head) + ')') if self.directional: self.string_connector = " --> " else: self.string_connector = " --- " self.label_location = process_label_location('top', kwargs) self.label_shift = process_label_shift(0.0, kwargs) super(Edge, self).__init__(Point(0.0, 0.0), ll = self.label_location, **kwargs) self.reflect = process_reflect(None, kwargs) self.angle = None # Arrow property processing option self.edge_width = process_width(0.025, kwargs) self.head_width_to_edge_width = process_head_width_to_width(3.0, kwargs) self.head_length_to_head_width = process_head_length_to_head_width(2.0, kwargs) self.overhang = process_overhang(0.0, kwargs) self.alpha = process_alpha(1.0, kwargs) self.face_color = process_face_color((0.0, 0.0, 0.0), kwargs) self.draw_bool = process_draw(True, kwargs) self.draw_label_bool = process_draw_label(True, kwargs) self._instances[id(self)] = self
def draw(self, tail_coords, head_coords, node_radius, **kwargs): self.edge_width = process_width(self.edge_width, kwargs) self.head_width_to_edge_width = process_head_width_to_width( self.head_width_to_edge_width, kwargs) self.head_length_to_head_width = process_head_length_to_head_width( self.head_length_to_head_width, kwargs) self.overhang = process_overhang(self.overhang, kwargs) self.alpha = process_alpha(self.alpha, kwargs) self.face_color = process_face_color(self.face_color, kwargs) if self.angle == None: self.get_angle(tail_coords, head_coords) node_delta = Point(node_radius * cos(self._angle_radians), node_radius * sin(self._angle_radians)) if tail_coords.draw_bool: tail_delta = Point(node_delta.x, node_delta.y) else: tail_delta = Point() head_delta = Point(-1.0 * node_delta.x, -1.0 * node_delta.y) if self.directional: head_width = self.head_width_to_edge_width * self.edge_width head_length = self.head_length_to_head_width * head_width if not head_coords.draw_bool: head_delta = Point() else: head_width = 0.0 head_length = 0.0 if not head_coords.draw_bool: head_delta = Point( 0.5 * self.edge_width * cos(self._angle_radians), 0.5 * self.edge_width * sin(self._angle_radians)) tail_coords = tail_coords + tail_delta head_coords = head_coords + head_delta delta = head_coords - tail_coords if self.draw_bool: patch = FancyArrow(tail_coords.x, tail_coords.y, delta.x, delta.y, width=self.edge_width, length_includes_head=True, head_width=head_width, head_length=head_length, shape='full', overhang=self.overhang, head_starts_at_zero=False, fc=self.face_color, alpha=self.alpha) return patch else: return None
def draw(self, tail_coords, head_coords, node_radius, **kwargs): self.edge_width = process_width(self.edge_width, kwargs) self.head_width_to_edge_width = process_head_width_to_width(self.head_width_to_edge_width, kwargs) self.head_length_to_head_width = process_head_length_to_head_width(self.head_length_to_head_width, kwargs) self.overhang = process_overhang(self.overhang, kwargs) self.alpha = process_alpha(self.alpha, kwargs) self.face_color = process_face_color(self.face_color, kwargs) if self.angle == None: self.get_angle(tail_coords, head_coords) node_delta = Point( node_radius * cos( self._angle_radians ), node_radius * sin( self._angle_radians ) ) if tail_coords.draw_bool: tail_delta = Point(node_delta.x, node_delta.y) else: tail_delta = Point() head_delta = Point(-1.0 * node_delta.x, -1.0 * node_delta.y) if self.directional: head_width = self.head_width_to_edge_width * self.edge_width head_length = self.head_length_to_head_width * head_width if not head_coords.draw_bool: head_delta = Point() else: head_width = 0.0 head_length = 0.0 if not head_coords.draw_bool: head_delta = Point( 0.5 * self.edge_width * cos( self._angle_radians ), 0.5 * self.edge_width * sin( self._angle_radians ) ) tail_coords = tail_coords + tail_delta head_coords = head_coords + head_delta delta = head_coords - tail_coords if self.draw_bool: patch = FancyArrow( tail_coords.x, tail_coords.y, delta.x, delta.y, width = self.edge_width, length_includes_head = True, head_width = head_width, head_length = head_length, shape = 'full', overhang = self.overhang, head_starts_at_zero = False, fc = self.face_color, alpha = self.alpha ) return patch else: return None
def __init__(self, tail, head, **kwargs): self.tail = tail self.head = head self.directional = process_directional(True, kwargs) if self.tail == self.head: sys.exit('Error: Cannot connect a node to itself. (' + str(self.tail) + ' -/-> ' + str(self.head) + ')') if self.directional: self.string_connector = " --> " else: self.string_connector = " --- " self.label_location = process_label_location('top', kwargs) self.label_shift = process_label_shift(0.0, kwargs) super(Edge, self).__init__(Point(0.0, 0.0), ll=self.label_location, **kwargs) self.reflect = process_reflect(None, kwargs) self.angle = None # Arrow property processing option self.edge_width = process_width(0.025, kwargs) self.head_width_to_edge_width = process_head_width_to_width( 3.0, kwargs) self.head_length_to_head_width = process_head_length_to_head_width( 2.0, kwargs) self.overhang = process_overhang(0.0, kwargs) self.alpha = process_alpha(1.0, kwargs) self.face_color = process_face_color((0.0, 0.0, 0.0), kwargs) self.draw_bool = process_draw(True, kwargs) self.draw_label_bool = process_draw_label(True, kwargs) self._instances[id(self)] = self