def render_content(self, svg, x, y): shape_builder = ShapeBuilder() frame = shape_builder.createRect(x, y, self.content_width, self.content_height, self.content_height / 2 - 1, self.content_height / 2 - 1, strokewidth=self.conf.terminal.thickness) svg.addElement(frame) x += max(1, (self.content_width - self.text.width - 2 * self.padding) / 2) self.text.render(svg, x + self.padding, y + self.padding)
def write_label(svg,labeltext,x=0,y=0): if args.toupper: labeltext = str.upper(labeltext) #if autofontsize, work out max fontsize that will fit if args.autofontsize: autofontsize = 1 textWidth=0 textHeight=0 while textWidth+label_margin < width and textHeight+label_margin < height: (textWidth,textHeight)=get_font_size(autofontsize,labeltext) autofontsize+=1 autofontsize-=1 global fontsize fontsize=autofontsize #otherwise just check the default font size will fit else: (textWidth,textHeight)=get_font_size(fontsize,labeltext) if textWidth+label_margin > width or textHeight+label_margin > height: print "text too big, try a smaller font" exit(1) #positioning x+=(width-textWidth)/2 y+=height/2+textHeight/2 y=y+args.y_offset x=x+args.x_offset t=text(labeltext,x+margin,y+margin) t.set_style(get_font_style(fontsize)) svg.addElement(t)
def write_label(svg,labeltext,x=0,y=0): #xml escape labeltext = escape(labeltext) if args.toupper: labeltext = str.upper(labeltext) #if autofontsize, work out max fontsize that will fit if args.autofontsize: autofontsize = 1 textWidth=0 textHeight=0 while textWidth+label_margin < width and textHeight+label_margin < height: (textWidth,textHeight)=get_font_size(autofontsize,labeltext) autofontsize+=1 autofontsize-=1 global fontsize fontsize=autofontsize #otherwise just check the default font size will fit else: (textWidth,textHeight)=get_font_size(fontsize,labeltext) if textWidth+label_margin > width or textHeight+label_margin > height: print "text too big, try a smaller font" exit(1) #positioning x+=(width-textWidth)/2 y+=height/2+textHeight/2 y=y+args.y_offset x=x+args.x_offset t=text(labeltext,x+margin,y+margin) t.set_style(get_font_style(fontsize)) svg.addElement(t)
def render(self, svg, x, y): stroke_width = self.conf.connection.thickness shape_builder = ShapeBuilder() connect_y = y + self.connect_y bottom_y = y + self.content.height + 10 tmp = 0 if isinstance(self.content.children[0], QuantityAbove): t = self.content.height - self.content.children[0].content.height tmp = t / 2 elif isinstance(self.content.children[0], Sequence): if isinstance(self.content.children[0].children[0], QuantityAbove): t = self.content.height - self.content.children[0].children[0].content.height tmp = t / 2 self.content.render(svg, x + 20, y - tmp) path_data = "m {0},{1} c 10,0 10,{3} {2},{3}".format(x, connect_y, 20, bottom_y - connect_y) svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width)) path_data = "m {0},{1} c 10,0 10,{3} {2},{3}".format(x + 20 + self.content.width, bottom_y, 20, connect_y - bottom_y) svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width)) Line(10, 0, self.conf, arrow=True).render(svg, x + 20 + self.content.width / 2, bottom_y) l = shape_builder.createLine(x + 20, bottom_y, x + 20 + self.content.width, bottom_y, strokewidth=stroke_width) svg.addElement(l) l = shape_builder.createLine(x, connect_y, x + 20, connect_y, strokewidth=stroke_width) svg.addElement(l) l = shape_builder.createLine(x + 20 + self.content.width, connect_y, x + 20 + self.content.width + 20, connect_y, strokewidth=stroke_width) svg.addElement(l)
def render(self, svg, x, y): self.render_content(svg, x + 10, y) shape_builder = ShapeBuilder() Line(10, 0, self.conf, arrow=True).render(svg, x, y + self.content_height / 2) l = shape_builder.createLine(x + self.content_width + 10, y + self.content_height / 2, x + self.content_width + 20, y + self.content_height / 2, strokewidth=self.conf.connection.thickness) svg.addElement(l)
def render_frame(self, svg, x, y): shape_builder = ShapeBuilder() frame = shape_builder.createRect(x, y, self.content_width, self.content_height, strokewidth=self.conf.group.thickness) svg.addElement(frame) #header_box = shape_builder.createRect(x, y, self.header_width, self.header_height, fill='black', strokewidth=self.conf.group.thickness) header_box = shape_builder.createRect(x, y, self.header_text.getWidth(), self.header_text.getHeight(), fill='black', strokewidth=self.conf.group.thickness) svg.addElement(header_box) self.header_text.renderHeader(svg, x + self.header_padding, y + self.header_padding)
def write_date(svg): print "date" now = datetime.datetime.now() date = now.strftime("%d/%m/%Y") print date t = text(date, 10, args.height) t.set_style(get_style()) svg.addElement(t) t = text("24:00", 110, args.height) t.set_style(get_style()) t.set_id("datetext") svg.addElement(t)
def write_date(svg): print "date" now = datetime.datetime.now() date = now.strftime("%d/%m/%Y") print date t=text(date,10,args.height) t.set_style(get_style()) svg.addElement(t) t=text("24:00",110,args.height) t.set_style(get_style()) t.set_id("datetext") svg.addElement(t)
def write_scale(svg): id = -1 #no id for the leaf leaf(10, args.height - 100, 1, svg, id, 0, args) #assume we get something every 5 minutes - wrong assumption but for now #the number we get in is in watts, eg 100 = 100W #so if scale is 100, 100W will result in leaf being scaled to 1(original size) #so a full size leaf is equal in energy to 100W for 5min #typical is in hours, so divide by (60/5) 12 = 100/12 = 8.3wH #if it was 100W but scale is 50, then a full size leaf is 50W for 5 mins #so leaf is 50/20 = 2wH #so scale text is args.scale/12 scale_text = "= %.1fWh" % (args.scale / 12) t = text(scale_text, 50, args.height - 60) t.set_style(get_style()) svg.addElement(t)
def render_content(self, svg, x, y): shape_builder = ShapeBuilder() frame = shape_builder.createRect(x, y, self.content_width, self.content_height, self.content_height / 2 - 1, self.content_height / 2 - 1, fill='black', strokewidth=self.conf.invterminal.thickness) svg.addElement(frame) first = True for child in self.children: if first: first = False else: l = shape_builder.createLine(x, y + 3, x, y + self.content_height - 3, stroke = 'white', strokewidth=self.conf.connection.thickness) svg.addElement(l) child.render(svg, x + self.padding, y + self.padding) x += child.width + 2 * self.padding
def write_scale(svg): id = -1 #no id for the leaf leaf(10,args.height - 100,1,svg,id,0,args) #assume we get something every 5 minutes - wrong assumption but for now #the number we get in is in watts, eg 100 = 100W #so if scale is 100, 100W will result in leaf being scaled to 1(original size) #so a full size leaf is equal in energy to 100W for 5min #typical is in hours, so divide by (60/5) 12 = 100/12 = 8.3wH #if it was 100W but scale is 50, then a full size leaf is 50W for 5 mins #so leaf is 50/20 = 2wH #so scale text is args.scale/12 scale_text = "= %.1fWh" % ( args.scale / 12 ) t=text(scale_text,50, args.height - 60) t.set_style(get_style()) svg.addElement(t)
def gen(self, svg): # outlines if self.opt.outline: t = Turtle(fill="lightgrey") t.moveTo(Vector(self.sx, self.sy)) t.penDown() for i in self.edges: p = i.basic(t) t.right(90) t.finish() for i in t.getSVGElements(): svg.addElement(i) ## fill # bodge up the insets self.edges[0].length = self.edges[0].length - self.edges[ 1].inset - self.edges[3].inset self.edges[1].length = self.edges[1].length - self.edges[ 0].inset - self.edges[2].inset self.edges[2].length = self.edges[2].length - self.edges[ 3].inset - self.edges[1].inset self.edges[3].length = self.edges[3].length - self.edges[ 2].inset - self.edges[0].inset #gr = g() gr = a() # gr.set_xlink_href('./?face='+self.name) # gr.set_target('_parent') t = Turtle() t.moveTo( Vector(self.sx + self.edges[3].inset, self.sy + self.edges[0].inset)) t.penDown() for i in self.edges: p = i.gen(t) t.right(90) t.penUp() t.finish() for i in t.getSVGElements(): gr.addElement(i) if self.opt.show_labels: te = text(self.name, self.sx + self.width / 2, self.sy + self.length / 2) te.setAttribute("text-anchor", "middle") gr.addElement(te) svg.addElement(gr)
def render(self, svg, x, y): self.content.render(svg, x + 20, y + 20) stroke_width = self.conf.connection.thickness connect_y = y + self.connect_y above_y = connect_y - self.content.height_above - 10 path_data = "m {0},{1} c -10,0 -10,{3} 0,{3}".format(x + 20, connect_y, 20, above_y - connect_y) svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width)) path_data = "m {0},{1} c 10,0 10,{3} 0,{3}".format(x + 20 + self.content.width, above_y, 20, connect_y - above_y) svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width)) shape_builder = ShapeBuilder() Line(0, 0, self.conf, arrow=True).render(svg, x + 25 + self.content.width / 2, above_y) l = shape_builder.createLine(x + 20, above_y, x + 20 + self.content.width, above_y, strokewidth=stroke_width) svg.addElement(l) l = shape_builder.createLine(x, connect_y, x + 20, connect_y, strokewidth=stroke_width) svg.addElement(l) l = shape_builder.createLine(x + 20 + self.content.width, connect_y, x + 20 + self.content.width + 20, connect_y, strokewidth=stroke_width) svg.addElement(l)
def gen(self,svg): # outlines if self.opt.outline: t = Turtle(fill="lightgrey") t.moveTo(Vector(self.sx,self.sy)) t.penDown() for i in self.edges: p = i.basic(t) t.right(90) t.finish() for i in t.getSVGElements(): svg.addElement(i) ## fill # bodge up the insets self.edges[0].length = self.edges[0].length - self.edges[1].inset - self.edges[3].inset self.edges[1].length = self.edges[1].length - self.edges[0].inset - self.edges[2].inset self.edges[2].length = self.edges[2].length - self.edges[3].inset - self.edges[1].inset self.edges[3].length = self.edges[3].length - self.edges[2].inset - self.edges[0].inset #gr = g() gr = a() # gr.set_xlink_href('./?face='+self.name) # gr.set_target('_parent') t = Turtle() t.moveTo(Vector(self.sx+self.edges[3].inset,self.sy+self.edges[0].inset)) t.penDown() for i in self.edges: p = i.gen(t) t.right(90) t.penUp() t.finish() for i in t.getSVGElements(): gr.addElement(i) if self.opt.show_labels: te = text(self.name,self.sx+self.width/2,self.sy+self.length/2) te.setAttribute("text-anchor","middle") gr.addElement(te) svg.addElement(gr)
def render(self, svg, x, y): stroke_width = self.conf.connection.thickness shape_builder = ShapeBuilder() start_x = x start_y = y + self.connect_y end_x = x + self.content_width + 20 x += 20 for child in self.children: child.render(svg, x, y) l = shape_builder.createLine(x + child.width, y + child.connect_y, x + self.content_width, y + child.connect_y, strokewidth=stroke_width) svg.addElement(l) path_data = "m {0},{1} c {2},0 0,{3} {2},{3}".format(start_x, start_y, 20, y + child.connect_y - start_y) svg.addElement(path(path_data, stroke = "black", fill="none", stroke_width=stroke_width)) path_data = "m {0},{1} c {2},0 0,{3} {2},{3}".format(end_x, y + child.connect_y, 20, start_y - (y + child.connect_y)) svg.addElement(path(path_data, stroke = "black", fill="none", stroke_width=stroke_width)) y += child.height + self.padding