def _draw_track(self, dr: svgwrite.Drawing, tr: Track, size: XY, offset: XY): color = self.color(self.poster.length_range, tr.length, tr.special) str_length = format_float(self.poster.m2u(tr.length)) date_title = f"{str(tr.start_time_local)[:10]} {str_length}km" for line in project(tr.bbox(), size, offset, tr.polylines): distance1 = self.poster.special_distance["special_distance"] distance2 = self.poster.special_distance["special_distance2"] has_special = distance1 < tr.length / 1000 < distance2 color = self.color(self.poster.length_range_by_date, tr.length, has_special) if tr.length / 1000 >= distance2: color = self.poster.colors.get( "special2") or self.poster.colors.get("special") polyline = dr.polyline( points=line, stroke=color, fill="none", stroke_width=0.5, stroke_linejoin="round", stroke_linecap="round", ) polyline.set_desc(title=date_title) dr.add(polyline)
def draw(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, size: XY, offset: XY) -> None: """Draw the heatmap based on tracks.""" bbox = self._determine_bbox() year_groups: typing.Dict[int, svgwrite.container.Group] = {} for tr in self.poster.tracks: year = tr.start_time().year if year not in year_groups: g_year = dr.g(id=f"year{year}") g.add(g_year) year_groups[year] = g_year else: g_year = year_groups[year] color = self.color(self.poster.length_range, tr.length(), tr.special) for line in utils.project(bbox, size, offset, tr.polylines): for opacity, width in [(0.1, 5.0), (0.2, 2.0), (1.0, 0.3)]: g_year.add( dr.polyline( points=line, stroke=color, stroke_opacity=opacity, fill="none", stroke_width=width, stroke_linejoin="round", stroke_linecap="round", ))
def draw_svg(self, drawing: svgwrite.Drawing, g): glane = drawing.g() glane.attribs["class"] = "lane" cp1 = self.control_points[0] cp2 = self.control_points[-1] rel = relative_pose(cp1.as_SE2(), cp2.as_SE2()) _, theta = geo.translation_angle_from_SE2(rel) delta = int(np.sign(theta)) fill = {-1: "#577094", 0: "#709457", 1: "#947057"}[delta] points = self.lane_profile(points_per_segment=10) p = drawing.polygon(points=points, fill=fill, fill_opacity=0.5) glane.add(p) center_points = self.center_line_points(points_per_segment=10) center_points = [ geo.translation_angle_from_SE2(_)[0] for _ in center_points ] p = drawing.polyline( points=center_points, stroke=fill, fill="none", stroke_dasharray="0.02", stroke_width=0.01, ) glane.add(p) g.add(glane) for x in self.control_points: q = x.asmatrix2d().m p1, _ = geo.translation_angle_from_SE2(q) delta_arrow = np.array([self.width / 4, 0]) p2 = SE2_apply_R2(q, delta_arrow) gp = drawing.g() gp.attribs["class"] = "control-point" l = drawing.line( start=p1.tolist(), end=p2.tolist(), stroke="black", stroke_width=self.width / 20.0, ) gp.add(l) c = drawing.circle( center=p1.tolist(), r=self.width / 8, fill="white", stroke="black", stroke_width=self.width / 20.0, ) gp.add(c) g.add(gp)
def _draw_track(self, dr: svgwrite.Drawing, tr: Track, size: XY, offset: XY): color = self.color(self.poster.length_range, tr.length, tr.special) for line in utils.project(tr.bbox(), size, offset, tr.polylines): dr.add( dr.polyline( points=line, stroke=color, fill="none", stroke_width=0.5, stroke_linejoin="round", stroke_linecap="round", ))
def _draw_track(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, tr: Track, size: XY, offset: XY) -> None: color = self.color(self.poster.length_range, tr.length(), tr.special) str_length = utils.format_float(self.poster.m2u(tr.length())) date_title = str(tr.start_time.date()) if tr.start_time else "Unknown Date" for line in utils.project(tr.bbox(), size, offset, tr.polylines): polyline = dr.polyline( points=line, stroke=color, fill="none", stroke_width=0.5, stroke_linejoin="round", stroke_linecap="round", ) polyline.set_desc(title=f"{date_title} {str_length} {self.poster.u()}") g.add(polyline)
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): """Draw the heatmap based on tracks.""" bbox = self._determine_bbox() for tr in self.poster.tracks: color = self.color(self.poster.length_range, tr.length, tr.special) for line in utils.project(bbox, size, offset, tr.polylines): for opacity, width in [(0.1, 5.0), (0.2, 2.0), (1.0, 0.3)]: dr.add( dr.polyline( points=line, stroke=color, stroke_opacity=opacity, fill="none", stroke_width=width, stroke_linejoin="round", stroke_linecap="round", ))
def plot(self, shape="rect", scale=0, strand=True, **extra): svg = Drawing() g = svg.g() previous = None for feature in self.features: if not previous: previous = feature continue x1, y1 = previous.position x2, y2 = feature.position y1 += (2 + previous.strand) * previous.height + previous.height / 2 y2 += (feature.strand - 1) * feature.height - previous.height / 2 p1 = [x1, y1] p2 = [x1 + previous.length * scale, y1] p3 = [x2 + feature.length * scale, y2] p4 = [x2, y2] if shape == "rect": g.add( svg.polygon(points=[p1, p2, p3, p4], fill=self.color, fill_opacity=0.6)) if shape == "line": g.add( svg.polyline([ ((p1[0] + p2[0]) / 2, y1 - previous.height / 2), ((p1[0] + p2[0]) / 2, y1), ((p3[0] + p4[0]) / 2, y2), ((p3[0] + p4[0]) / 2, y2 + feature.height / 2), ], fill_opacity=0, stroke=self.color, stroke_width=2)) previous = feature return g
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): """Draw the heatmap based on tracks.""" normal_lines = [] special_lines = [] bbox = self._determine_bbox() for tr in self.poster.tracks: for line in utils.project(bbox, size, offset, tr.polylines): if tr.special: special_lines.append(line) else: normal_lines.append(line) for lines, color in [(normal_lines, self.poster.colors['track']), (special_lines, self.poster.colors['special'])]: for opacity, width in [(0.1, 5.0), (0.2, 2.0), (1.0, 0.3)]: for line in lines: dr.add( dr.polyline(points=line, stroke=color, stroke_opacity=opacity, fill='none', stroke_width=width, stroke_linejoin='round', stroke_linecap='round'))
else: y_use = y_mid line = dwg.line(start=(start, y_use), end=(end, y_use)) h_lines.add(line) # Arrowhead if end > start: ar_l = 10 else: ar_l = -10 ar_h = 7.5 pts = ((end - ar_l, y_use + ar_h), (end, y_use), (end - ar_l, y_use - ar_h)) arrow = dwg.polyline(pts) h_lines.add(arrow) y += delta_y # Phys vs scaling indicator scaled_regions = [ (1, (2, 5)), (1, (7, 8)), (1, (11, 22)), (1, (24, 26)), (2, (2, 5)), (2, (7, 8)), (2, (11, 22)), (2, (24, 26)), (4, (2, 5)),
g = im_to_graph(skeletonized) lines = list(partition_forest(g)) assert len(lines) == 1 line = lines.pop() smoothed = gaussian_filter1d(np.asarray(line, dtype=float), sigma=DEFAULT_SIGMA, axis=0) length = np.linalg.norm(np.diff(smoothed, axis=0), axis=1).sum() dwg = Drawing("line.svg") dwg.add(dwg.rect(size=drawn_arr.shape[::-1], fill="black")) dwg.add( dwg.polyline([tuple(pair[::-1]) for pair in smoothed], stroke="white", stroke_width=4, fill="none")) dwg.save(pretty=True, indent=2) def pad_dim(vals, pad, integer=True): vmin = vals.min() vmax = vals.max() vpad = (vmax - vmin) * pad if integer: vpad = int(np.ceil(vpad)) return vmin - vpad, vmax + vpad class Limits(NamedTuple):
for arrow in arrows: start = grid_pts[arrow[0]] end = grid_pts[arrow[1]] line = dwg.line(start=(start, y_mid), end=(end, y_mid)) h_lines.add(line) # Arrowhead if end > start: ar_l = 10 else: ar_l = -10 ar_h = 7.5 pts = ((end-ar_l, y_mid+ar_h), (end, y_mid), (end-ar_l, y_mid-ar_h)) arrow = dwg.polyline(pts) h_lines.add(arrow) y += delta_y # Phys vs scaling indicator scaled_regions = [(0, (7, 9)), (1, (2, 11)), (1, (13, 14)), (2, (2, 11)), (2, (13, 14)), ] for region in scaled_regions: x_line = vertical_locs[region[0]]