Beispiel #1
0
def rectangle_with_latex(width,
                         expr,
                         rectangle_tikz_str="",
                         latex_tikz_str=""):
    r_fmt = fmt.combine_tikz_strs([
        # fmt.alignment("center"),
        fmt.rounded_corners(roundness_in_cm),
        fmt.line_width(line_width),
        rectangle_tikz_str
    ])
    l_fmt = fmt.combine_tikz_strs([latex_tikz_str])
    r = stz.rectangle_from_width_and_height([0, 0], square_side, width, r_fmt)
    l = stz.latex(stz.center_coords(r), expr, l_fmt)
    return [r, l]
Beispiel #2
0
def rectangle(height, color_name):
    s_fmt = fmt.combine_tikz_strs([
        fmt.line_width(line_width),
        fmt.fill_color(color_name),
        fmt.rounded_corners(rectangle_roundness)
    ])
    return stz.rectangle_from_width_and_height([0, 0], height, width, s_fmt)
Beispiel #3
0
def connect(e_from, e_to):
    cs_from = stz.coords_from_bbox_with_fn(e_from, stz.top_center_coords)
    cs_to = stz.coords_from_bbox_with_fn(e_to, stz.bottom_center_coords)
    s_fmt = fmt.combine_tikz_strs(
        [fmt.line_width(line_width),
         fmt.arrow_heads("end")])
    return stz.line_segment(cs_from, cs_to, s_fmt)
Beispiel #4
0
def rectangle_with_text(color_name, s_lst):
    height = 0.1 + per_line_height * len(s_lst)
    s_width = fmt.combine_tikz_strs([fmt.text_width(width), "align=center"])
    r = rectangle(height, color_name)
    cs = stz.center_coords(r)
    s = " \\vspace{-0.05cm} \\linebreak ".join(s_lst)
    t = stz.latex(cs, s, s_width)
    return [r, t]
Beispiel #5
0
def connect(e_from, e_to, color_name="black"):
    s_fmt = fmt.combine_tikz_strs(
        [fmt.arrow_heads("end"),
         fmt.line_color(color_name), s_lw])
    from_cs = stz.center_coords(e_from)
    to_cs = stz.center_coords(e_to)
    out_angle = stz.vector_to_angle([from_cs, to_cs])
    in_angle = out_angle + 180.0
    return stz.line_segment_between_circles(from_cs, node_radius, out_angle,
                                            to_cs, node_radius, in_angle,
                                            s_fmt)
def label_small_node(label, e_small, angle, distance, label_width):
    s_fmt = fmt.combine_tikz_strs([
        fmt.rounded_corners(rectangle_roundness),
        fmt.fill_color_with_no_line('gray!20')
    ])
    s_fmt_t = fmt.fill_color_with_no_line('gray!20')
    r = stz.rectangle_from_width_and_height([0, 0], 1.8 * node_radius,
                                            label_width, s_fmt)
    cs = stz.center_coords(e_small)
    cs_label = stz.coords_on_circle(cs, distance, angle)
    stz.translate_bbox_center_to_coords(r, cs_label)
    l = stz.latex(cs_label, label)
    t = stz.closed_path([
        stz.coords_on_circle(cs, filled_node_radius, angle), cs_label,
        stz.coords_on_circle(cs_label, triangle_radius,
                             angle + 180.0 + triangle_angle_delta)
    ], s_fmt_t)
    return [r, t, l]
Beispiel #7
0
                                             2.0 * horizontal_plate_spacing,
                                             2.0 * vertical_plate_spacing)
    l_cs = stz.translate_coords_antidiagonally(
        stz.bbox(r)[1], -plate_label_spacing)
    l = stz.latex(l_cs, expr)
    return [r, l]


alpha_c = stz.circle([0, 0], node_radius)
theta_c = stz.circle([0, 0], node_radius)
z_c = stz.circle([0, 0], node_radius)
w_c = stz.circle([0, 0], node_radius)
eta_c = stz.circle([0, 0], node_radius)
beta_c = stz.circle([0, 0], node_radius)

w_c["tikz_str"] = fmt.combine_tikz_strs(
    [w_c["tikz_str"], fmt.fill_color("gray")])

stz.distribute_horizontally_with_spacing([alpha_c, theta_c, z_c, w_c],
                                         node_spacing)
stz.distribute_horizontally_with_spacing([eta_c, beta_c], node_spacing)
stz.place_above_and_align_to_the_center(
    [eta_c, beta_c], [alpha_c, theta_c, z_c, w_c], node_spacing)

alpha_l = label_below(alpha_c, "$\\alpha$")
theta_l = label_below(theta_c, "$\\theta$")
z_l = label_below(z_c, "$z$")
w_l = label_below(w_c, "$w$")
eta_l = label_left(eta_c, "$\\eta$")
beta_l = label_right(beta_c, "$\\beta$")

connections = [
Beispiel #8
0
spacing_between_towers = 1.5
bbox_spacing = 0.45
bbox_roundness = 0.3

name2color = {
    "emb_color": (252, 224, 225),
    "multi_head_attention_color": (252, 226, 187),
    "add_norm_color": (242, 243, 193),
    "ff_color": (194, 232, 247),
    "softmax_color": (203, 231, 207),
    "linear_color": (220, 223, 240),
    "gray_bbox_color": (243, 243, 244)
}

s_arr = fmt.combine_tikz_strs(
    [fmt.line_width(line_width),
     fmt.arrow_heads("end")])

s_lw = fmt.combine_tikz_strs([fmt.line_width(line_width)])

s_con = s_bbox = fmt.combine_tikz_strs([
    fmt.arrow_heads("end"),
    fmt.line_width(line_width),
    fmt.rounded_corners(connector_roundness)
])

s_bbox = fmt.combine_tikz_strs([
    fmt.fill_color("gray_bbox_color"),
    fmt.line_width(line_width),
    fmt.rounded_corners(bbox_roundness)
])
Beispiel #9
0
 def highlight(e_frame, indices, idx, color):
     e = get_idx(e_frame, indices)
     s_fmt = fmt.combine_tikz_strs([e["tikz_str"], fmt.fill_color(color)])
     e['tikz_str'] = s_fmt
Beispiel #10
0
io_corner_roundness = 0.0
module_roundness = 0.0
line_width = 2.0 * fmt.standard_line_width
module_inner_vertical_spacing = 0.1
delta_increment = 0.0

horizontal_module_spacing = 0.2
vertical_module_spacing = 0.2
spacing_between_module_and_hyperp = 0.8
spacing_between_hyperp_and_hyperp = 0.4
arrow_length = vertical_module_spacing

name2color = fmt.google_slides_named_colors()

connect_s_fmt = fmt.combine_tikz_strs(
    [fmt.arrow_heads("end"),
     fmt.line_width(line_width)])

input_s_fmt = fmt.combine_tikz_strs([
    fmt.line_width(line_width),
])

output_s_fmt = fmt.combine_tikz_strs([
    fmt.line_width(line_width),
])

property_s_fmt = fmt.combine_tikz_strs([
    fmt.line_width(line_width),
])

module_s_fmt = fmt.combine_tikz_strs([
Beispiel #11
0
def dashed_bbox(e_lst):
    s_fmt = fmt.combine_tikz_strs([fmt.line_style("dashed"), s_lw])
    top_left_cs, bottom_right_cs = stz.bbox(e_lst)
    return stz.rectangle_from_additive_resizing(top_left_cs, bottom_right_cs,
                                                2.0 * bbox_spacing,
                                                2.0 * bbox_spacing, s_fmt)
Beispiel #12
0
place(nodes[7], [-1, 1, 1])
place(nodes[8], [1, 1, -1])

connections = [
    connect(nodes[0], nodes[1], "blue"),
    connect(nodes[0], nodes[2]),
    connect(nodes[1], nodes[3]),
    connect(nodes[1], nodes[4], "blue"),
    connect(nodes[2], nodes[5]),
    connect(nodes[4], nodes[6], "blue"),
    connect(nodes[4], nodes[7]),
    connect(nodes[5], nodes[8]),
]

nodes[-3][0]["tikz_str"] = fmt.combine_tikz_strs(
    [nodes[-3][0]["tikz_str"],
     fmt.line_and_fill_colors("mygreen", "mygreen")])
nodes[-3][1]["tikz_str"] = fmt.combine_tikz_strs(
    [nodes[-3][0]["tikz_str"], "text=white"])

bb1 = dashed_bbox([nodes[6]])
bb2 = dashed_bbox([bb1, nodes[4], nodes[7]])
bb3 = dashed_bbox([bb2, nodes[1], nodes[3]])
bboxes = [bb1, bb2, bb3]

labels = [
    label_left(nodes[0], "4 < 8"),
    label_left(nodes[1], "4 > 3"),
    label_left(nodes[4], "4 < 6"),
]
Beispiel #13
0
    "my_grey": (217, 217, 217),
    "my_yellow": (255, 212, 76),
    "my_blue": (1, 176, 240),
    "my_green": (50, 192, 115),
    "my_red": (255, 102, 102)
}

m_fmt = fmt.line_and_fill_colors("my_grey", "my_grey")
x1_fmt = fmt.line_and_fill_colors("my_yellow", "my_yellow")
x2_fmt = fmt.line_and_fill_colors("my_blue", "my_blue")
x3_fmt = fmt.line_and_fill_colors("my_green", "my_green")
x4_fmt = fmt.line_and_fill_colors("my_red", "my_red")
xs_fmt = [x1_fmt, x2_fmt, x3_fmt, x4_fmt]

h_green_rfmt = fmt.combine_tikz_strs(
    [fmt.line_width(2.0 * line_width),
     fmt.line_color("my_green")])
h_grey_rfmt = fmt.line_color("my_grey")
h_grey_lfmt = fmt.text_color("my_grey")


def rectangle_with_latex(width,
                         expr,
                         rectangle_tikz_str="",
                         latex_tikz_str=""):
    r_fmt = fmt.combine_tikz_strs([
        # fmt.alignment("center"),
        fmt.rounded_corners(roundness_in_cm),
        fmt.line_width(line_width),
        rectangle_tikz_str
    ])