def __init__(self, world_ltrb, max_z, **kwargs): x1, y1, x2, y2 = world_ltrb verts = np.array([ [x1, y1, 0], [x2 + 10, y1, 0], [x1, y1, 0], [x1, y2 + 10, 0], [x1, y1, 0], [x1, y1, max_z + 10], ]) color = np.array([ [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0, 0, 1, 1], ]) LineVisual.__init__(self, pos=verts, color=color, connect="segments", method="gl", **kwargs)
def __init__(self, pos=None, domain=(0., 1.), tick_direction=(-1., 0.), scale_type="linear", axis_color=(1, 1, 1), tick_color=(0.7, 0.7, 0.7), text_color='w', minor_tick_length=5, major_tick_length=10, tick_width=2, tick_label_margin=5, tick_font_size=8, axis_width=3, axis_label=None, axis_label_margin=35, axis_font_size=10, font_size=None, anchors=None): if scale_type not in ('linear', 'logarithmic'): raise NotImplementedError('only linear scaling is currently ' 'supported') if font_size is not None: tick_font_size = font_size axis_font_size = font_size self._pos = None self._domain = None # If True, then axis stops at the first / last major tick. # If False, then axis extends to edge of *pos* # (private until we come up with a better name for this) self._stop_at_major = (False, False) self.ticker = ExtTicker(self, anchors=anchors) self.tick_direction = np.array(tick_direction, float) self.tick_direction = self.tick_direction self.scale_type = scale_type self.axis_color = axis_color self.tick_color = tick_color self.minor_tick_length = minor_tick_length # px self.major_tick_length = major_tick_length # px self.tick_label_margin = tick_label_margin # px self.axis_label_margin = axis_label_margin # px self.axis_label = axis_label self._need_update = True self._line = LineVisual(method='gl', width=axis_width) self._ticks = LineVisual(method='gl', width=tick_width, connect='segments') self._text = TextVisual(font_size=tick_font_size, color=text_color) self._axis_label = TextVisual(font_size=axis_font_size, color=text_color) CompoundVisual.__init__(self, [self._line, self._text, self._ticks, self._axis_label]) if pos is not None: self.pos = pos self.domain = domain
def __init__(self, vertices=None, simplices=None, vertex_colors=None, edge_color=None, edge_width=1, markers=None, marker_colors=None, marker_size=1, **kwargs): """ a mesh visualization toolkit that can also plot edges or markers Parameters ---------- Notes ----- """ self._mesh = MeshVisual() self._edge = LineVisual() self._edge_color = Color(edge_color) self._marker = MarkersVisual() # self._vertex_colors = vertex_colors self._update() # initialize visuals CompoundVisual.__init__(self, [self._mesh, self._edge, self._marker], **kwargs) # set default state, 'opaque', 'translucent' or 'additive' self._mesh.set_gl_state( preset="translucent", blend=True, depth_test=False, cull_face=False, polygon_offset_fill=True, polygon_offset=(1, 1), ) # end self.freeze() def _update(self): """ update parameters to visuals """ raise NotImplementedError() @property def edge_color(self): """ get """ return self._edge_color @edge_color.setter def edge_color(self, edge_color): """ set """ self._edge_color = Color(edge_color) self._update()
def __init__(self, **kwargs): pos = np.asarray(kwargs.pop('pos', (0,0,0))) width = kwargs.pop('width', 1) scale = kwargs.pop('scale', 1) verts = np.array([[0, 0, 0], [1, 0, 0], [0, 0, 0], [0, 1, 0], [0, 0, 0], [0, 0, 1]]) * scale + pos color = np.array([[1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0, 0, 1, 1]]) LineVisual.__init__(self, pos=verts, color=color, width = width, connect='segments', method='gl', **kwargs)
def __init__(self, origin=[0, 0, 0], length=1): verts = origin + np.array([[0, 0, 0], [length, 0, 0], [0, 0, 0], [0, length, 0], [0, 0, 0], [0, 0, length]]) line = LineVisual(pos=verts, color=np.array([0, 0, 0, 1]), connect='segments', method='gl') x = TextVisual('x', font_size=12, pos=origin + np.array([1.25 * length, 0, 0])) y = TextVisual('y', font_size=12, pos=origin + np.array([0, 1.25 * length, 0])) z = TextVisual('z', font_size=12, pos=origin + np.array([0, 0, 1.25 * length])) CompoundVisual.__init__(self, [line, x, y, z])
class AxisVisual(CompoundVisual): """Axis visual Parameters ---------- pos : array Co-ordinates of start and end of the axis. domain : tuple The data values at the beginning and end of the axis, used for tick labels. i.e. (5, 10) means the axis starts at 5 and ends at 10. Default is (0, 1). tick_direction : array The tick direction to use (in document coordinates). scale_type : str The type of scale. For now only 'linear' is supported. axis_color : tuple RGBA values for the axis colour. Default is black. tick_color : tuple RGBA values for the tick colours. The colour for the major and minor ticks is currently fixed to be the same. Default is a dark grey. text_color : Color The color to use for drawing tick and axis labels minor_tick_length : float The length of minor ticks, in pixels major_tick_length : float The length of major ticks, in pixels tick_width : float Line width for the ticks tick_label_margin : float Margin between ticks and tick labels tick_font_size : float The font size to use for rendering tick labels. axis_width : float Line width for the axis axis_label : str Text to use for the axis label axis_label_margin : float Margin between ticks and axis labels axis_font_size : float The font size to use for rendering axis labels. font_size : float Font size for both the tick and axis labels. If this is set, tick_font_size and axis_font_size are ignored. anchors : iterable A 2-element iterable (tuple, list, etc.) giving the horizontal and vertical alignment of the tick labels. The first element should be one of 'left', 'center', or 'right', and the second element should be one of 'bottom', 'middle', or 'top'. If this is not specified, it is determined automatically. """ def __init__(self, pos=None, domain=(0., 1.), tick_direction=(-1., 0.), scale_type="linear", axis_color=(1, 1, 1), tick_color=(0.7, 0.7, 0.7), text_color='w', minor_tick_length=5, major_tick_length=10, tick_width=2, tick_label_margin=5, tick_font_size=8, axis_width=3, axis_label=None, axis_label_margin=35, axis_font_size=10, font_size=None, anchors=None): if scale_type != 'linear': raise NotImplementedError('only linear scaling is currently ' 'supported') if font_size is not None: tick_font_size = font_size axis_font_size = font_size self._pos = None self._domain = None # If True, then axis stops at the first / last major tick. # If False, then axis extends to edge of *pos* # (private until we come up with a better name for this) self._stop_at_major = (False, False) self.ticker = Ticker(self, anchors=anchors) self.tick_direction = np.array(tick_direction, float) self.tick_direction = self.tick_direction self.scale_type = scale_type self.minor_tick_length = minor_tick_length # px self.major_tick_length = major_tick_length # px self.tick_label_margin = tick_label_margin # px self.axis_label_margin = axis_label_margin # px self._axis_label_text = axis_label self._need_update = True self._line = LineVisual(method='gl', width=axis_width, antialias=True, color=axis_color) self._ticks = LineVisual(method='gl', width=tick_width, connect='segments', antialias=True, color=tick_color) self._text = TextVisual(font_size=tick_font_size, color=text_color) self._axis_label = TextVisual(font_size=axis_font_size, color=text_color) CompoundVisual.__init__( self, [self._line, self._text, self._ticks, self._axis_label]) if pos is not None: self.pos = pos self.domain = domain @property def label_color(self): return self._text.color @label_color.setter def label_color(self, value): self._text.color = value self._axis_label.color = value @property def axis_color(self): return self._line.color @axis_color.setter def axis_color(self, value): self._line.set_data(color=value) @property def tick_color(self): return self._ticks.color @tick_color.setter def tick_color(self, value): self._ticks.set_data(color=value) @property def tick_font_size(self): return self._text.font_size @tick_font_size.setter def tick_font_size(self, value): self._text.font_size = value @property def axis_font_size(self): return self._axis_label.font_size @axis_font_size.setter def axis_font_size(self, value): self._axis_label.font_size = value @property def axis_label(self): return self._axis_label_text @axis_label.setter def axis_label(self, axis_label): self._axis_label_text = axis_label self._need_update = True self.update() @property def pos(self): return self._pos @pos.setter def pos(self, pos): self._pos = np.array(pos, float) self._need_update = True self.update() @property def domain(self): return self._domain @domain.setter def domain(self, d): if self._domain is None or d != self._domain: self._domain = d self._need_update = True self.update() @property def _vec(self): """Vector in the direction of the axis line""" return self.pos[1] - self.pos[0] def _update_subvisuals(self): tick_pos, labels, tick_label_pos, anchors, axis_label_pos = \ self.ticker.get_update() self._line.set_data(pos=self.pos, color=self.axis_color) self._ticks.set_data(pos=tick_pos, color=self.tick_color) self._text.text = list(labels) self._text.pos = tick_label_pos self._text.anchors = anchors if self.axis_label is not None: self._axis_label.text = self.axis_label self._axis_label.pos = axis_label_pos self._need_update = False def _prepare_draw(self, view): if self._pos is None: return False if self.axis_label is not None: # TODO: make sure we only call get_transform if the transform for # the line is updated tr = self._line.get_transform(map_from='visual', map_to='canvas') trpos = tr.map(self.pos) trpos /= trpos[:, 3:] x1, y1, x2, y2 = trpos[:, :2].ravel() if x1 > x2: x1, y1, x2, y2 = x2, y2, x1, y1 self._axis_label.rotation = math.degrees( math.atan2(y2 - y1, x2 - x1)) if self._need_update: self._update_subvisuals() def _compute_bounds(self, axis, view): if axis == 2: return (0., 0.) # now axis in (0, 1) return self.pos[:, axis].min(), self.pos[:, axis].max()