def __init__(self, camera = None, axis = [2,2], origin = [0,0], axis_units = [1,1], xlabel = None, ylabel = None, title = None, plotmode = None, colorlegend = None, axis_unit_symbols = [None,None], axis_subunits = [4,4], color_scheme = DEFAULT_COLORS, on_keyboard = (lambda s,a,p: None), graphs = {}, axis_measures = [], render_axis = (True, True), plotplane_margin=[5, 10, 40, 5], plotplane_minsize=(100, 100), min_label_space=(0,0), widget = None, axis_density=(80,80), ): plot_info('Yo bro', 'plotter cant wait to plot for you') Controller.__init__(self, camera) if GlApplication.DEBUG: color_scheme = DEBUG_COLORS self.graphs = graphs or OrderedDict() self.plot_camera = None self.color_scheme = color_scheme self.plotmode = plotmode self.widget = widget self.colorlegend = colorlegend self._on_keyboard = on_keyboard if type(plotmode) is str: if plotmode not in _PLOTMODE_ALIASES: raise ValueError('unkown plotmode "{}". Available aliases are: {}'.format( plotmode, ', '.join(_PLOTMODE_ALIASES.keys()) )) self.plotmode = _PLOTMODE_ALIASES[plotmode][0]( *_PLOTMODE_ALIASES[plotmode][1], **_PLOTMODE_ALIASES[plotmode][2] ) self._axis_measures = axis_measures self.on_state = Event() self.min_label_space = min_label_space self._axis_translation = (10, 0) self._plotplane_margin = plotplane_margin self._plot_plane_min_size = plotplane_minsize self._axis = axis self._axis_units = axis_units self.colorlegend_speed = 0.01 self._xlabel = xlabel self._ylabel = ylabel self._title = title self._title_font = None self._xlabel_font = None self._ylabel_font = None self._axis_density = axis_density self._axis_subunits = axis_subunits self._axis_unit_symbols = axis_unit_symbols self._origin = origin self._margin_changed = False self._plotframe = None self._xaxis = None self._yaxis = None self._colorlegend_axis = None self._debug = False self._fontrenderer = None self._render_axis = render_axis self._axis_texts = [[],[]] self._yboxwidths = [] # dstates self.render_graphs = True self._graphs_initialized = False self._has_rendered = False self._state = 0 self._select_area = [0,0,0,0] self._select_area_rectangle = None self._colorlegend_frame = None self._colorlegend = None self._colorlegend_graph = None self._colorlegend_texts = [] self.xlabel_text = None self.ylabel_text = None self.title_text = None self._fntrenderer = FontRenderer2() self._fntlayout = AlignedLayout(self.camera) self.on_cursor.append(self.cursor_reload) self.on_keyboard.append(self.keyboard_callback) self.on_mouse.append(self.mouse_callback) self.on_pre_render.insert(0, self.pre_render) self.on_pre_render.insert(0, self.check_graphs) self.on_post_render.append(self.post_render) self.on_render.append(self.render) if self.widget is not None: self.widget.attach(self)
def init(self): """ initializes plot2d """ self.shaperenderer = ShapeRenderer(self.camera) self.shaperenderer.shapes['default_rectangle'] = Rectangle() self.shaperenderer.gl_init() # setup axis self.init_labels() # setup plotplane plotframe = window.Framebuffer( camera = self.camera, screensize = self.plotframe_size, screen_mode = window.Framebuffer.SCREEN_MODE_STRECH, record_mode = self.plotmode.record_mode if self.plotmode is not None else window.Framebuffer.RECORD_CLEAR, clear_color = hex_to_rgba(self.color_scheme['plotplane-bgcolor']), multisampling = 8, blit_texture=True, ) self._fntrenderer.set_camera(self.camera) self._fntrenderer.init() self._fntlayout.camera = self.camera if self.plotmode is not None: plotframe.record_program = self.plotmode.get_shader() plotframe.init() plotframe.modelview.set_position(self._plotplane_margin[3], self._plotplane_margin[0]) plotframe.update_modelview() # setup plotplane camera plotframe.inner_camera.set_base_matrix(np.array([ 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, ], dtype=np.float32)) plotframe.inner_camera.set_scaling(self._axis) plotframe.inner_camera.set_position(*self._origin) self._plotframe = plotframe # parent controller initialization Controller.init(self) self.state = self.STATE_IDLE self._select_area_rectangle = ShapeInstance('default_rectangle', **{ 'size': (0,0), 'position': (0,0), 'border': { 'size': self.color_scheme['select-area-border-size'], 'color': hex_to_rgba(self.color_scheme['select-area-border-color']), }, 'color': hex_to_rgba(self.color_scheme['select-area-bgcolor']), }) self._plotplane = ShapeInstance('default_rectangle', **{ 'size': self.plotframe_size, 'position': self.plotframe_position, 'border': { 'size': self.color_scheme['plotframe-border-size'], 'color': hex_to_rgba(self.color_scheme['plotframe-border-color']), }, 'color': [0,0,0,0], 'texture': self._plotframe }) self.shaperenderer.draw_instance(self._plotplane) # setup axis if self._render_axis[0]: self._xaxis = axis.Scale( camera = self.camera, scale_camera = self._plotframe.inner_camera, size = self.get_xaxis_size(), unit = self._axis_units[0], subunits = self._axis_subunits[0], font = None, axis = axis.XAXIS, unit_symbol = self._axis_unit_symbols[0], bgcolor = hex_to_rgba(self.color_scheme['xaxis-bgcolor']), linecolor = hex_to_rgba(self.color_scheme['xaxis-linecolor']), fontcolor = hex_to_rgba(self.color_scheme['xaxis-fontcolor']), ) self._xaxis.density = self._axis_density[0] self._xaxis.init() self._update_xaxis() if self._render_axis[1]: self._yaxis = axis.Scale( camera = self.camera, scale_camera = self._plotframe.inner_camera, size = self.get_yaxis_size(), unit = self._axis_units[1], subunits = self._axis_subunits[1], font = None, axis = axis.YAXIS, unit_symbol = self._axis_unit_symbols[1], bgcolor = hex_to_rgba(self.color_scheme['yaxis-bgcolor']), linecolor = hex_to_rgba(self.color_scheme['yaxis-linecolor']), fontcolor = hex_to_rgba(self.color_scheme['yaxis-fontcolor']), ) self._yaxis.density = self._axis_density[1] self._yaxis.init() self._update_yaxis() self.init_colorlegend() self._plotplane.size = self.plotframe_size self._update_plotframe_camera() self._update_graph_matricies() glfwWindowHint(GLFW_SAMPLES, 4); glEnable(GL_MULTISAMPLE) if self.widget is not None: plot_info('Plotter2d', 'init widget...') self.widget.gl_init() plot_info('Plotter2d', 'inizialized!')