def _draw(self): res = [] # Borders res.append(self._get_borders()) # Title table res.append(self._get_table_line((0, 0), (self.width - 30, 0))) res.append( self._get_table_line((self.width - 30 - 65, 0), (self.width - 30 - 65, 25))) res.append( self._get_table_line((self.width - 30 - 165, 0), (self.width - 30 - 165, 25))) res.append( self._get_table_line((self.width - 30 - 265, 0), (self.width - 30 - 265, 25))) res.append( self._get_table_line((self.width - 30 - 245, 18), (self.width - 30 - 245, 25))) res.append( self._get_table_line((self.width - 30 - 265, 18), (self.width - 30 - 165, 18))) # Text # project title project_title_insert_point = (self.width - 30 - 195, self._base_point[1] + 11) res.append( text.Text(self.project_title, project_title_insert_point, **self.DEFAULT_LABEL_ATTRIBS)) # drawing title title_insert_point = (self.width - 30 - 95, self._base_point[1] + 15) res.append( text.Text(self.title, title_insert_point, **self.DEFAULT_LABEL_ATTRIBS)) # field title field_title_insert_point = (self.width - 10 - 255, self._base_point[1] + 23) res.append( text.Text(self.field_title, field_title_insert_point, **self.DEFAULT_LABEL_ATTRIBS)) # field value field_value_insert_point = (self.width - 10 - 205, self._base_point[1] + 23) res.append( text.Text(self.field_value, field_value_insert_point, **self.DEFAULT_LABEL_ATTRIBS)) # Logo logo = self._get_logo() if logo is not None: res = res + logo return res
def get_title_text(self): t = text.Text( "", insert=(self.x0, self.y0), dy=["-8px"], ) t.add(text.TSpan(f"{self.goal}% Leased Goal")) t.add( text.TSpan(f"by {self.goal_date:%-m/%d/%Y}", x=[self.x0], dy=["24px"])) return t.tostring()
def get_current_text(self): half_size = self.max_value / 2 if (half_size - 7 <= self.current <= half_size + 14) or \ (self.current >= self.max_value - 15) or (self.current <= self.max_value + 9): x, y = self.calc_slice_coord(self.current - 4, self.r0) else: x, y = self.calc_slice_coord(self.current - 3, self.r0) t = text.Text( "", insert=(x, y), ) t.add(text.TSpan("Current:")) t.add(text.TSpan(f"{self.current}%", x=[x], dy=["17px"])) return t.tostring()
def get_goal_text(self): if self.is_labels_overlap: x, y = self.calc_slice_coord(self.current - 10, self.r0) elif 0 <= self.goal - self.current <= 4: x, y = self.calc_slice_coord(self.current + 3, self.r0) else: x, y = self.calc_slice_coord(self.goal - 3, self.r0) t = text.Text( "", insert=(x, y), ) t.add(text.TSpan("Goal:")) t.add(text.TSpan(f"{self.goal}%", x=[x], dy=["17px"])) return t.tostring()
def _draw(self): res = [] # Borders res.append(self._get_borders()) # Title table title_insert_point = (self.width - 10 - 185, self.height - 10 - 55) res.append( shapes.Rect(title_insert_point, (185, 55), **self.LINE_ATTRIBS)) res.append(self._get_table_line((0, 5), (65, 5))) res.append(self._get_table_line((0, 10), (65, 10))) res.append(self._get_table_line((0, 15), (185, 15))) res.append(self._get_table_line((0, 20), (65, 20))) res.append(self._get_table_line((0, 25), (65, 25))) res.append(self._get_table_line((0, 30), (65, 30))) res.append(self._get_table_line((0, 35), (65, 35))) res.append(self._get_table_line((0, 40), (185, 40))) res.append(self._get_table_line((0, 45), (65, 45))) res.append(self._get_table_line((0, 50), (65, 50))) res.append(self._get_table_line((7, 0), (7, 25))) res.append(self._get_table_line((17, 0), (17, 55))) res.append(self._get_table_line((40, 0), (40, 55))) res.append(self._get_table_line((55, 0), (55, 55))) res.append(self._get_table_line((65, 0), (65, 55))) res.append(self._get_table_line((135, 15), (135, 55))) res.append(self._get_table_line((135, 20), (185, 20))) res.append(self._get_table_line((135, 35), (185, 35))) res.append(self._get_table_line((140, 20), (140, 35))) res.append(self._get_table_line((145, 20), (145, 35))) res.append(self._get_table_line((150, 15), (150, 35))) res.append(self._get_table_line((167, 15), (167, 35))) res.append(self._get_table_line((155, 35), (155, 40))) # Text res.append( text.Text( self.title, (title_insert_point[0] + 100, title_insert_point[1] + 30), **self.DEFAULT_LABEL_ATTRIBS)) return res
def _render_text(self, start_point, end_point, padding=True): middle_point = self._get_middle_point(start_point, end_point) attribs = self.DEFAULT_LABEL_ATTRIBS.copy() attribs.update(self.label_attribs) if (end_point[0] - start_point[0]) != 0: tan_angle = (end_point[1] - start_point[1]) / (end_point[0] - start_point[0]) angle = math.degrees(math.atan(tan_angle)) else: angle = -90 unit_vector = self._get_perpendicular_unit_vector( start_point, end_point, middle_point) if padding: draw_text_center_point = (middle_point[0] + unit_vector[0] * self.ARROW_PADDING, middle_point[1] + unit_vector[1] * self.ARROW_PADDING) else: draw_text_center_point = middle_point attribs['transform'] = "rotate({}, {}, {})".format( angle, draw_text_center_point[0], draw_text_center_point[1]) return text.Text(self.label, draw_text_center_point, **attribs)
def create_axes_elements( axes, window_size, *, length=15, font_size=14, inset=(20, 20), font_offset=1.0, line_width=1, line_color="black", labels=("X", "Y", "Z"), colors=("red", "green", "blue"), ): """Create the SVG elements, related to the axes.""" svg_elements = [] for i in axes[:, 2].argsort(): a = inset[0] b = window_size[1] - inset[1] c = int(axes[i][0] * length + a) d = int(axes[i][1] * length + b) e = int(axes[i][0] * length * font_offset + a) f = int(axes[i][1] * length * font_offset + b) svg_elements.append( shapes.Line([a, b], [c, d], stroke=line_color, stroke_width=line_width)) svg_elements.append( text.Text( labels[i], x=(e, ), y=(f, ), fill=colors[i], text_anchor="middle", dominant_baseline="middle", font_size=font_size, )) return svg_elements
def generate_svg_elements(element_group, element_colors=None, background_color="white"): """Create the SVG elements, related to the 3D objects. Parameters ---------- element_group : ase_notebook.draw_elements.DrawGroup Container of all element groups to be created. background_color : str Returns ------- list[svgwrite.base.BaseElement] """ svg_elements = [] for _, element in element_group.yield_zorder(): if element.name == "atoms": if not element.get("visible", True): continue if element.occupancy is not None: from ase.data import atomic_numbers if (np.sum([o for o in element.occupancy.values()])) < 1.0: # first draw an empty circle if a site is not fully occupied svg_elements.append( shapes.Circle( element.position[:2], r=element.sradius, fill=background_color, fill_opacity=element.get("fill_opacity", 0.95), stroke=element.get("stroke", "black"), stroke_width=element.get("stroke_width", 1), )) angle_start = 0 # start with the dominant species for sym, occ in sorted(element.occupancy.items(), key=lambda x: x[1], reverse=True): if np.round(occ, decimals=4) == 1.0: svg_elements.append( shapes.Circle( element.position[:2], r=element.sradius, fill=element_colors[atomic_numbers[sym]], fill_opacity=element.get("fill_opacity", 0.95), stroke=element.get("stroke_color", "black"), stroke_width=element.get("stroke_width", 1), )) else: angle_extent = 360.0 * occ svg_elements.append( create_arc_element( element.position[:2], angle_start, angle_start + angle_extent, element.sradius, fill=element_colors[atomic_numbers[sym]], fill_opacity=element.get("fill_opacity", 0.95), stroke=element.get("stroke_color", "black"), stroke_width=element.get("stroke_width", 1), )) angle_start += angle_extent else: svg_elements.append( shapes.Circle( element.position[:2], r=element.sradius, fill=element.color, fill_opacity=element.get("fill_opacity", 0.95), stroke=element.get("stroke_color", "black"), stroke_width=element.get("stroke_width", 1), )) if "label" in element and element.label is not None: svg_elements.append( text.Text( element.label, x=(int(element.position[0]), ), y=(int(element.position[1]), ), text_anchor="middle", dominant_baseline="middle", font_size=element.get("font_size", 20), fill=element.get("font_color", "black"), )) # TODO add force/velocity vectors # TODO add ghost crosses if element.name == "cell_lines": svg_elements.append( shapes.Line( element.position[0][:2], element.position[1][:2], stroke=element.get("color", "black"), # stroke_dasharray=f"{element.get('dashed', '6,4')}", )) if element.name == "bond_lines": start, end = element.position[0][:2], element.position[1][:2] svg_elements.append( shapes.Line( start, start + 0.5 * (end - start), stroke=element.color[0], stroke_width=element.get("stroke_width", 1), stroke_linecap="round", stroke_opacity=element.get("stroke_opacity", 0.8), )) svg_elements.append( shapes.Line( start + 0.5 * (end - start), end, stroke=element.color[1], stroke_width=element.get("stroke_width", 1), stroke_linecap="round", stroke_opacity=element.get("stroke_opacity", 0.8), )) if element.name == "miller_lines": svg_elements.append( shapes.Line( element.position[0][:2], element.position[1][:2], stroke=element.get("stroke_color", "blue"), stroke_width=element.get("stroke_width", 1), stroke_opacity=element.get("stroke_opacity", 0.8), )) if element.name == "miller_planes": svg_elements.append( shapes.Polygon( points=element.position[:, :2], fill=element.get("fill_color", "blue"), fill_opacity=element.get("fill_opacity", 0.5), stroke=element.get("stroke_color", "blue"), stroke_width=element.get("stroke_width", 0), stroke_opacity=element.get("stroke_opacity", 0.5), )) return svg_elements