Example #1
0
 def layout(self):
     world = rect_area(*self.bounds).sub_area(0.1, 0.05, 0.8, 0.85)
     logger.info('changing view size :%s' % world)
     ctx = uiView_context(self,
                          world_area=world,
                          user_area=rect_area(0, 0, 10, 30))
     self.grctx = {
         0: ctx,
         1: ctx
     }  # each channel has its own context i.e. left,right yaxis
Example #2
0
 def __init__(self, inView, world_area=None, *args, **kwargs):
     self.inView = inView
     if not world_area:
         world_area = plottls.rect_area(*inView.bounds).sub_area(
             0.1, 0.05, 0.85, 0.85)
     elif type(world_area) is tuple:
         world_area = plottls.rect_area(*world_area)
     #elif type(world_area) is scene.Rect:
     #	world_area = plottls.rect_area(*world_area)
     #wrld_frm = (frame[0],frame[1]+frame[3],frame[2],-frame[3]) # have low y at bottom
     self.path = ui.Path()
     super().__init__(
         world_area.yFlipped(), *args,
         **kwargs)  #world_frame,user_frame, font_name, font_size)
     logger.info('uiView ctx:wrld:%s user:%s' %
                 (self.world.frame(), self.user.frame()))
Example #3
0
            def __init__(self, frame=(100, 100, 600, 300), *args, **kwargs):
                """ clipping all beyond frame
				"""
                super().__init__(frame=frame, *args, **kwargs)
                user = plottls.rect_area(-2, -2, 4, 6)  # no autoscale
                self.background_color = 'white'
                world = None  #plottls.rect_area(50,10,540,260)
                ctx1 = uiView_context.uiView_context(self, world, user)
                self.graph = xy_graph(ctx1)
Example #4
0
        def __init__(self, frame=(100, 100, 600, 400), *args, **kwargs):
            """ (not) clipping all beyond frame
			"""
            super().__init__(frame=frame, *args, **kwargs)
            self.add_subview(
                vwDigitals(frame=(10, 340, 580, 30),
                           background_color='aquamarine',
                           name='digitals'))
            self.bg_color = 'white'
            frL = plottls.rect_area(10, 10, 280, 280)
            frR = frL.offset(300)
            print('iv.frame=%s iv.bounds=%s ' % (frL.frame(), self.bounds))
            self.ctx1 = uiView_context(self, world_area=frL, user_area=user)
            self.ctx2 = uiView_context(self,
                                       world_area=frR,
                                       user_area=user.sub_area(yofs=1,
                                                               yscale=-1))
Example #5
0
 def draw(self):
     if self.bitvals:
         n = len(self.bitvals)
         logger.debug('dig bnds:%s' % self.bounds)
         world = plottls.rect_area(*self.bounds)
         ctx = uiView_context(self,
                              world_area=world,
                              user_area=(0, 0, n,
                                         1))  # plottls.rect_area(0,0,n,1))
         #logger.debug('digitals:%s world:%s' % (self.bitvals, ctx.world.frame()))
         for i, bitv, mode in zip(range(n), self.bitvals, self.modes):
             if mode == 0b11:
                 ctx.fill_oval(i + 0.05, 0.05, 0.9, 0.9, 'darkkhaki')
             else:
                 ctx.fill_oval(i + 0.05, 0.05, 0.9, 0.9,
                               'brown' if mode == 0 else 'beige')
                 ctx.fill_oval(i + 0.2, 0.2, 0.6, 0.6,
                               'gold' if bitv else 'black')
Example #6
0
    def set_bounds(self, xmin, ymin, xsize, ysize, ctxId=0):
        '''
		Set x- and y-axis user coord limits.
		Will also recalculate tick positions.
		'''
        if xsize == 0 or ysize == 0 or math.isinf(xmin) or math.isinf(ymin):
            return
        wrld_frame = self.context[ctxId].world
        user_frame = plottls.rect_area(xmin, ymin, xsize, ysize)
        logger.info('scaling graph wrld:%s user:%s' %
                    (wrld_frame.frame(), user_frame.frame()))
        #self.innerbox = plottls.canvas_context(wrld_frame, user_frame)
        self.context[ctxId].user.set_origin(xmin, ymin)
        self.context[ctxId].user.set_size(xsize, ysize)
        xlim = (xmin, xmin + xsize)
        ylim = (ymin, ymin + ysize)
        if ctxId == 0:
            self.xticks = _calc_ticks(xlim)
            #self.yticks = _calc_ticks(ylim,ctxId)
        self.rescaling = True
Example #7
0
                                 user_area=(0, 0, n,
                                            1))  # plottls.rect_area(0,0,n,1))
            #logger.debug('digitals:%s world:%s' % (self.bitvals, ctx.world.frame()))
            for i, bitv, mode in zip(range(n), self.bitvals, self.modes):
                if mode == 0b11:
                    ctx.fill_oval(i + 0.05, 0.05, 0.9, 0.9, 'darkkhaki')
                else:
                    ctx.fill_oval(i + 0.05, 0.05, 0.9, 0.9,
                                  'brown' if mode == 0 else 'beige')
                    ctx.fill_oval(i + 0.2, 0.2, 0.6, 0.6,
                                  'gold' if bitv else 'black')


if __name__ == "__main__":  # testing and examples
    import time
    user = plottls.rect_area(0, 0, 60, 30)

    class gr_view(ui.View):
        """ 
		"""
        def __init__(self, frame=(100, 100, 600, 400), *args, **kwargs):
            """ (not) clipping all beyond frame
			"""
            super().__init__(frame=frame, *args, **kwargs)
            self.add_subview(
                vwDigitals(frame=(10, 340, 580, 30),
                           background_color='aquamarine',
                           name='digitals'))
            self.bg_color = 'white'
            frL = plottls.rect_area(10, 10, 280, 280)
            frR = frL.offset(300)
Example #8
0
if __name__ == "__main__":  # example and testing
    import ui

    # Plot a quadratic and a cubic curve in the same plot.
    xs = [(t - 40.0) / 30 for t in range(0, 101)]
    y1 = [x**2 - 0.3 for x in xs]
    y2 = [x**3 for x in xs]

    CANVAS = 0  # draw to canvas or to ui.view
    if CANVAS:
        import canvas_context

        # plotting on canvas #
        canvas.set_size(*ui.get_screen_size())

        canv_wrld = plottls.rect_area(700, 100, 300, 300)
        context = canvas_context.canvas_context(canv_wrld)
        grph = xy_graph(context)

        grph.set_bounds(40, 140, 0, 10)
        grph.draw()

        context = canvas_context.canvas_context(canv_wrld.offset(-500))
        grph = xy_graph(context)

        grph.add_plot(xs, y1, color='red')
        grph.add_plot(xs, y2, color=(0.00, 0.50, 0.80))
        grph.draw()
    else:
        import uiView_context