def translate( self, data: DataContainer, width: Width, height: Height, x_key: str = "x", y_key: str = "y", v_key: str = "value", is_1d: bool = False, colorScale: ColorScale = DEFAULT_COLOR_SCALE, grid: int = GRID, opacity: float = OPACITY, **kwargs: Any, ): """Points to Rect element translator for Simple SVG Heatmap renderer. Return SVG Group node that includes Rect node which been set attributes such as coordinate, fill color, opacity. Those attributes are based on applied data. :param colorScale: ColorScale array to use. :param grid: grid count. 32 or 64. :param opacity: alpha value for heatmap. """ isRelative = False if isinstance(width, str): if width.endswith("%"): gridSize = 3.125 if grid == 32 else 1.5625 isRelative = True else: gridSize = int(width, 10) / grid elif isinstance(width, int): gridSize = width / grid group = Group() if data and isinstance(data, list): for datum in data: extra = { "opacity": opacity, "fill": colorScale[datum[v_key] - 1], } insert_x = 0 if is_1d else gridSize * datum[x_key] insert_y = gridSize * datum[y_key] size_w = gridSize if not is_1d else 100.0 size_h = gridSize rect = Rect( insert=( insert_x if not isRelative else "%.4f%%" % insert_x, insert_y if not isRelative else "%.4f%%" % insert_y, ), size=( size_w if not isRelative else "%.4f%%" % size_w, size_h if not isRelative else "%.4f%%" % size_h, ), **extra, ) rect.set_desc(title="{0}%".format(datum[v_key] * 10)) group.add(rect) return group