def render_ingroup(self, content_ids): """ Function to render each elements inside one group defined by their id in content_ids """ #link the current slide slide = document._slides[self.slide_id] #Add the group id to all the elements in this group cptcache = 0 groupsid = content_ids #First loop render elements in group allwidth = [] allheight = [] for k in groupsid: elem = slide.contents[k] #Add group id to the element elem.group_id = self.idg #Render the element or read rendered svg from cache if not elem.rendered: elem.run_render() #Get element size allwidth += [elem.positionner.width] allheight += [elem.positionner.height+elem.positionner.y['shift']] #Compute group size if needed if self.width == None: self.width = max( allwidth ) self.positionner.width = self.width if self.height == None: self.height = sum( allheight ) self.positionner.height = sum( allheight ) #Re loop over element to place them all_height = {} #To store height of element for automatic placement for i, key in enumerate(groupsid): elem = slide.contents[key] if elem.positionner.y['align'] == 'auto': all_height[i] = {"height":elem.positionner.height, "id":key} else: elem.positionner.place( (self.width, self.height) ) #Manage autoplacement #print(all_height) if all_height != {}: auto_place_elements(all_height, (self.width, self.height), 'y', slide.contents, ytop=0) for key in groupsid: elem = slide.contents[key] if elem.type not in ['html']: if elem.svgout != None: self.content += [ elem.export_svg() ] if elem.jsout != None: slide.add_rendered( js=elem.jsout ) if elem.animout != None: tmpsvg, tmpanim = elem.export_animation() self.content += [tmpsvg] slide.add_rendered(animate_svg=tmpanim)
def render_ingroup(self, content_ids): """ Function to render each elements inside one group defined by their id in content_ids """ #link the current slide slide = document._slides[self.slide_id] #Add the group id to all the elements in this group cptcache = 0 groupsid = content_ids #First loop render elements in group allwidth = [] allheight = [] for k in groupsid: elem = slide.contents[k] #Add group id to the element elem.group_id = self.idg #Render the element or read rendered svg from cache if not elem.rendered: elem.run_render() #Get element size allwidth += [elem.positionner.width] allheight += [ elem.positionner.height + elem.positionner.y['shift'] ] #Compute group size if needed if self.width == None: self.width = max(allwidth) self.positionner.width = self.width if self.height == None: self.height = sum(allheight) self.positionner.height = sum(allheight) #Re loop over element to place them all_height = {} #To store height of element for automatic placement for i, key in enumerate(groupsid): elem = slide.contents[key] if elem.positionner.y['align'] == 'auto': all_height[i] = {"height": elem.positionner.height, "id": key} else: elem.positionner.place((self.width, self.height)) #Manage autoplacement #print(all_height) if all_height != {}: auto_place_elements(all_height, (self.width, self.height), 'y', slide.contents, ytop=0) for key in groupsid: elem = slide.contents[key] if elem.type not in ['html']: if elem.svgout != None: self.content += [elem.export_svg()] if elem.jsout != None: slide.add_rendered(js=elem.jsout) if elem.animout != None: tmpsvg, tmpanim = elem.export_animation() self.content += [tmpsvg] slide.add_rendered(animate_svg=tmpanim)
def render(self): """ Function to render a slide to an svg figure """ pre = """<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> """ print( '-'*20 + ' slide_%i '%self.num + '-'*20 ) out = pre+"""\n<svg width='%ipx' height='%ipx' style='background-color: "%s";' xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >"""%(document._width, document._height, self.args['background']) #Add the svg header to svg dict of the slide self.svgheader = out #self.add_rendered( svg=out ) #Run render of each elements t = time.time() for i, ct in self.contents.iteritems(): if not ct.rendered: ct.run_render() #print ct.keys() print('Rendering elements in %0.3f sec'%(time.time()-t)) t = time.time() #Place contents that's are not inside groups htmlingroup = [] all_height = {} for cpt, i in enumerate(self.element_keys): ct = self.contents[i] if ct.group_id != None: #Check if it's an html inside one group if ct.type == 'html': htmlingroup += [i] else: if ct.type != None: #print(ct['type']) #Check if it's a group #if ct.type == 'group': #render the group # ct.run_render() #Check if it's an auto placement or we can place the element if ct.positionner.y['align'] == 'auto': all_height[cpt] = {"height": ct.positionner.height, "id":i} else: ct.positionner.place( (document._width, document._height), ytop=self.ytop ) #Manage auto placement if all_height != {}: auto_place_elements(all_height, (document._width, document._height), 'y', self.contents, self.ytop) #Extra operations for html contents if htmlingroup != []: for i in htmlingroup: ct = self.contents[i] #add off set to the html div position group = self.groups[ ct.group_id ] ct.positionner.x['final'] += group.positionner.x['final'] ct.positionner.y['final'] += group.positionner.y['final'] #Store rendered contents in svgout, htmlout, jsout for key in self.element_keys: ct = self.contents[key] if ct.group_id == None: svgo = None htmlo = None animo = None jso = None if ct.svgout != None: svgo = ct.export_svg() if ct.htmlout != None: htmlo = ct.export_html() if ct.animout != None: svgo, animo = ct.export_animation() if ct.jsout != None: jso = ct.jsout self.add_rendered(svgo, htmlo, jso, animo) #For group we need to output html even if the elem is in one group #(html is absolute positionning see line 180 just above) else: if ct.htmlout != None: htmlo = ct.export_html() self.add_rendered(html=htmlo) #Add grid and fancy stuff... if document._guide: available_height = document._height - self.ytop out = '' out += '<g><line x1="400" y1="0" x2="400" y2="600" style="stroke: #777"/></g>' out += '<g><line x1="0" y1="%0.1f" x2="800" y2="%0.1f" style="stroke: #777"/></g>'%(self.ytop + available_height/2.0, self.ytop + available_height/2.0) out += '<g><line x1="0" y1="%0.1f" x2="800" y2="%0.1f" style="stroke: #777"/></g>'%(self.ytop, self.ytop) self.add_rendered(svg=out) #Close the main svg #self.add_rendered( svg="\n</svg>\n" ) print('Placing elements in %0.3f'%(time.time()-t))
def render(self): """ Function to render a slide to an svg figure """ pre = """<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> """ print('-' * 20 + ' slide_%i ' % self.num + '-' * 20) out = pre + """\n<svg width='%ipx' height='%ipx' style='background-color: "%s";' xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >""" % (document._width, document._height, self.args['background']) #Add the svg header to svg dict of the slide self.svgheader = out #self.add_rendered( svg=out ) #Check if we have a background layout to render if self.render_layout: if self.args['layout'] != None and 'function' in str( type(self.args['layout'])): #We need to restor the id of the slide for each module produced in the layout save_global_ct = document._global_counter[ 'slide'] #backup the total number of slides document._global_counter[ 'slide'] = self.slide_num #put the slide number in the counter #Run the layout function (which contains beampy modules) self.args['layout']() document._global_counter[ 'slide'] = save_global_ct #restor the slide counter #Run render of each elements t = time.time() for i, key in enumerate(self.element_keys): ct = self.contents[key] if not ct.rendered: ct.run_render() #print ct.keys() print('Rendering elements in %0.3f sec' % (time.time() - t)) t = time.time() #Place contents that's are not inside groups htmlingroup = [] all_height = {} for cpt, i in enumerate(self.element_keys): ct = self.contents[i] if ct.group_id != None: #Check if it's an html inside one group if ct.type == 'html': htmlingroup += [i] else: if ct.type != None: #print(ct['type']) #Check if it's an auto placement or we can place the element if ct.positionner.y['align'] == 'auto': all_height[cpt] = { "height": ct.positionner.height, "id": i } else: ct.positionner.place( (document._width, document._height), ytop=self.ytop) #Manage auto placement if all_height != {}: auto_place_elements(all_height, (document._width, document._height), 'y', self.contents, self.ytop) #Extra operations for html contents if htmlingroup != []: for i in htmlingroup: ct = self.contents[i] #add off set to the html div position group = self.groups[ct.group_id] ct.positionner.x['final'] += group.positionner.x['final'] ct.positionner.y['final'] += group.positionner.y['final'] #Store rendered contents in svgout, htmlout, jsout for key in self.element_keys: ct = self.contents[key] if ct.group_id == None: svgo = None htmlo = None animo = None jso = None if ct.svgout != None: svgo = ct.export_svg() if ct.htmlout != None: htmlo = ct.export_html() if ct.animout != None: svgo, animo = ct.export_animation() if ct.jsout != None: jso = ct.jsout self.add_rendered(svgo, htmlo, jso, animo) #For group we need to output html even if the elem is in one group #(html is absolute positionning see line 180 just above) else: if ct.htmlout != None: htmlo = ct.export_html() self.add_rendered(html=htmlo) #Add grid and fancy stuff... if document._guide: available_height = document._height - self.ytop out = '' out += '<g><line x1="400" y1="0" x2="400" y2="600" style="stroke: #777"/></g>' out += '<g><line x1="0" y1="%0.1f" x2="800" y2="%0.1f" style="stroke: #777"/></g>' % ( self.ytop + available_height / 2.0, self.ytop + available_height / 2.0) out += '<g><line x1="0" y1="%0.1f" x2="800" y2="%0.1f" style="stroke: #777"/></g>' % ( self.ytop, self.ytop) self.add_rendered(svg=out) #Close the main svg #self.add_rendered( svg="\n</svg>\n" ) print('Placing elements in %0.3f' % (time.time() - t))