import fathom.geometry as geo import fathom.layout as layout import fathom.tikz.colors as colors import fathom.tikz.line_styles as line_styles import fathom.tikz.locations as locations from itertools import * from skiplist_lib import draw_doc_chain if __name__ == '__main__': tree = layout.tree( ['', ['a', ['al', ['ala', ['alan']], ['ali', ['alic', ['alice']]]]]], root=ORIGIN, h_sep=2, v_sep=1) canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) for k, v in tree.copy().items(): if k == '': continue if k == 'alan': tree['alan'] = canvas.new_bullet(center=v, brush_color=colors.RED) elif k == 'alice': tree['alice'] = canvas.new_bullet(center=v, brush_color=colors.RED) else: tree[k] = canvas.new_bullet(center=v) e = canvas.new_line(src=tree[''], dst=tree['a']) canvas.new_text(anchor=e.get_skeleton().center(), text='a', location=locations.WEST)
src=centroid([seg0.vertices()[2], seg0.vertices()[3]]), dst=centroid([seg1.vertices()[0], seg1.vertices()[1]])) draw_edge(root[0], left[0]) draw_edge(root[1], right[0]) if __name__ == '__main__': tree = layout.tree( ['root', ['left', ['left_left'], ['left_right']], ['right', ['right_left'], ['right_right']]], root=ORIGIN, h_sep=1.2, v_sep=1) canvas = Canvas( preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) segs_root = node(canvas, tree['root']) segs_left = node(canvas, tree['left'], pen_color=colors.RED) segs_right = node(canvas, tree['right'], pen_color=colors.RED) segs_left_left = node(canvas, tree['left_left'], pen_color=colors.BLUE) segs_left_right = node(canvas, tree['left_right'], pen_color=colors.BLUE) segs_right_left = node(canvas, tree['right_left'], pen_color=colors.BLUE) segs_right_right = node(canvas, tree['right_right'], pen_color=colors.BLUE) tree_edge(canvas, segs_root, segs_left, segs_right) tree_edge(canvas, segs_left, segs_left_left, segs_left_right) tree_edge(canvas, segs_right, segs_right_left, segs_right_right) segs = segs_left_left + segs_left_right + segs_right_left + segs_right_right
from fathom.tikz import Canvas import fathom.geometry as geo import fathom.layout as layout import fathom.tikz.colors as colors import fathom.tikz.line_styles as line_styles import fathom.tikz.locations as locations from itertools import * from skiplist_lib import draw_doc_chain if __name__ == '__main__': tree = layout.tree(['root', ['left'], ['right']], root=ORIGIN, h_sep=2, v_sep=1.5) canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) shawow_canvas = Canvas() tree['root'] = shawow_canvas.new_rectangle(center=tree['root'], width=1, height=0.5) tree['left'] = shawow_canvas.new_rectangle(center=tree['left'], width=1, height=0.5) tree['right'] = shawow_canvas.new_rectangle(center=tree['right'], width=1, height=0.5) canvas.new_line(src=tree['root'], dst=tree['left']) canvas.new_line(src=tree['root'], dst=tree['right']) canvas.new_text(anchor=tree['root'].get_skeleton().center(), text='[18,21]')
def bitmap(canvas): width = 0.4 height = 0.4 rects = repeat(ORIGIN) rects = accumulate(rects, lambda x, _: x + Point(width, 0)) rects = islice(rects, 7) rects = [canvas.new_rectangle( center=x, width=width, height=height) for x in rects] return rects def key(canvas, rects): p = Point(1, 1.5) canvas.new_text(anchor=p, text='$k$', location=locations.NORTH) canvas.new_arrow(src=p, dst=rects[0]) canvas.new_arrow(src=p, dst=rects[2]) canvas.new_arrow(src=p, dst=rects[5]) canvas.new_text(anchor=Point(0.2, 0.7), text='\\scriptsize $h_0(k)$') canvas.new_text(anchor=Point(1.2, 0.5), text='\\scriptsize $h_1(k)$') canvas.new_text(anchor=Point(1.8, 0.9), text='\\scriptsize $h_2(k)$') if __name__ == '__main__': canvas = Canvas( preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) rects = bitmap(canvas) key(canvas, rects) print(canvas.draw())
CELL_HEIGHT = 0.5 ps = repeat(leftmost + Point(CELL_WIDTH / 2, 0)) ps = accumulate(ps, lambda x, _: x + Point(CELL_WIDTH, 0)) ps = islice(ps, len(texts)) ps = list(ps) for p, t in zip(ps, texts): canvas.new_text(anchor=p, text=t) canvas.new_rectangle(center=centroid([ps[0], ps[-1]]), width=CELL_WIDTH * len(ps), height=CELL_HEIGHT) if __name__ == '__main__': canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) shadow_canvas = Canvas() segs = file_format(canvas) column_index_seg = segs[3] column_data_seg = segs[2] root, left, right = index_tree(canvas) bbox = Rectangle(center=centroid( [root, left.get_skeleton().center(), right.get_skeleton().center()]), width=1.5, height=1) canvas.new_arrow(src=centroid([ column_index_seg.get_skeleton().vertices()[1],
import fathom.geometry as geo import fathom.tikz.colors as colors import fathom.tikz.line_styles as line_styles import fathom.tikz.locations as locations from itertools import * SEG_WIDTH = 1 SEG_HEIGHT = 0.8 if __name__ == '__main__': rects = repeat(ORIGIN, 5) rects = accumulate(rects, lambda x, _: x + geo.Point(SEG_WIDTH, 0)) rects = [geo.Rectangle(center=x, width=SEG_WIDTH, height=SEG_HEIGHT) for x in rects] canvas = Canvas( preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) ops = ['$\\text{op}_{n-2}$', '$\\text{op}_{n-1}$', '$\\text{op}_{n}$'] sns = ['$\\text{SN}_{n-2}$', '$\\text{SN}_{n-1}$', '$\\text{SN}_{n}$'] for x, op, sn in zip(rects[2:], ops, sns): canvas.new_text(anchor=x.center(), text=op) canvas.new_text( anchor=x.vertices()[0], text=sn, location=locations.NORTH) canvas.new_text( anchor=geo.centroid([rects[0].center(), rects[1].center()]), text='\\normalsize \\dots')
Point(maxx, maxy), Point(maxx, miny), Point(minx, miny)] if __name__ == '__main__': a = Point(0, -1) b = Point(1, 0) c = Point(0.5, -1.5) d = Point(1.5, -2) e = Point(2, -1.75) f = Point(3, -2.5) g = Point(2.75, 0) h = Point(3.25, -0.5) canvas = Canvas( preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) canvas.new_text(anchor=a, text='$a$', location=locations.WEST) canvas.new_text(anchor=b, text='$b$', location=locations.NORTH) canvas.new_text(anchor=c, text='$c$', location=locations.NORTH) canvas.new_text(anchor=d, text='$d$', location=locations.SOUTH) canvas.new_text(anchor=e, text='$e$', location=locations.NORTHEAST) canvas.new_text(anchor=f, text='$f$', location=locations.SOUTH) canvas.new_text(anchor=g, text='$g$', location=locations.NORTH) canvas.new_text(anchor=h, text='$h$', location=locations.EAST) for p in [a, b, c, d, e, f, g, h]: canvas.new_bullet(center=p) canvas.new_rectangle(vertices=bbox([a, b, c, d, e, f, g, h]))
v_dsts = v_srcs[1:] for s, t in zip(v_srcs, v_dsts): canvas.new_line(src=s, dst=t, line_style=line_styles.DASHED) canvas.new_arrow(src=rects[-1].center(), dst=rects[-2].center()) canvas.new_text(anchor=rects[-1].center(), text='$\\text{op}_{m,i}$', location=locations.EAST) if __name__ == '__main__': matrix = layout.matrix(h_sep=1, v_sep=0.8, n_rows=3, n_cols=2, top_left=ORIGIN) canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) canvas.new_text(anchor=matrix[0][0], text='$\\text{epoch}_0$') canvas.new_text(anchor=matrix[1][1], text='\\normalsize\\dots', location=locations.EAST) canvas.new_text(anchor=matrix[2][0], text='$\\text{epoch}_m$') epoch0(canvas, matrix[0][1]) epoch_m(canvas, matrix[2][1]) print(canvas.draw())
from fathom import Point, ORIGIN from fathom.tikz import Canvas import fathom.geometry as geo import fathom.tikz.colors as colors import fathom.tikz.line_styles as line_styles import fathom.tikz.locations as locations from itertools import * from skiplist_lib import draw_doc_chain if __name__ == '__main__': canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) circles = draw_doc_chain(canvas, ORIGIN, ['1', '2', '3', '4', '5', '6', '7', '8', '9']) ps = [ circles[0].get_skeleton().center() + Point(0, 1.6), circles[0].get_skeleton().center() + Point(0, 1.1), circles[4].get_skeleton().center() + Point(0, 1.1), circles[4].get_skeleton().center() + Point(0, 0.6), circles[6].get_skeleton().center() + Point(0, 0.6), circles[6], circles[7], ] for s, t in zip(ps, ps[1:]): canvas.new_line(src=s, dst=t, pen_color=colors.RED) print(canvas.draw())
canvas.new_arrow(src=active, dst=shadow, pen_color=colors.BLUE, line_style=line_styles.DASHED) canvas.new_arrow(src=shadow, dst=Point(7, 4.5), pen_color=colors.BLUE, line_style=line_styles.DASHED) canvas.new_text(anchor=Point(7, 5), text='dump', location=locations.SOUTHEAST) if __name__ == '__main__': canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) for y in SEPS_Y: canvas.new_line(src=Point(0, y), dst=Point(10, y), line_style=line_styles.DASHED) for y in SEPS_Y[:2]: canvas.new_arrow(src=Point(5, y + 0.3), dst=Point(5, y - 0.3)) canvas.new_text(anchor=Point(5, y), text='compact', location=locations.NORTHEAST) level2(canvas) level1(canvas) level0(canvas) mem(canvas)
from fathom import Point, ORIGIN from fathom.tikz import Canvas import fathom.geometry as geo import fathom.tikz.colors as colors import fathom.tikz.line_styles as line_styles import fathom.tikz.locations as locations from itertools import * import b_plus_tree if __name__ == '__main__': canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) tree = b_plus_tree.tree() tree['root'].set_line_color(colors.BLUE) tree['left'].set_line_color(colors.BLUE) tree['left_mid'].set_line_color(colors.RED) for p in tree.values(): p.draw(canvas) canvas.new_arrow(src=tree['root'].pointers(canvas)[0], dst=tree['left'].upleft()) canvas.new_arrow(src=tree['root'].pointers(canvas)[1], dst=tree['right'].upleft()) canvas.new_arrow(src=tree['left'].pointers(canvas)[0], dst=tree['left_left'].upleft()) canvas.new_arrow(src=tree['left'].pointers(canvas)[1], dst=tree['left_mid'].upleft()) canvas.new_arrow(src=tree['left'].pointers(canvas)[2], dst=tree['left_right'].upleft()) canvas.new_arrow(src=tree['right'].pointers(canvas)[0],
segs[0].vertices()[3] ]) for x in segs[1:]: canvas.new_line(src=x.vertices()[0], dst=x.vertices()[3]) if __name__ == '__main__': tree = layout.tree( ['root', ['left', ['left_up']], ['right', ['right_up']]], root=ORIGIN, h_sep=2, v_sep=1.3) for k, v in tree.copy().items(): tree[k] = upside_down(v) canvas = Canvas(preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) canvas.new_text(anchor=tree['left_up'], text='$121^\\circ$E') left_up = canvas.new_rectangle(center=tree['left_up'], width=1, height=0.4, pen_color=colors.INVISIBLE) left = fraction(canvas, tree['left'], (180 + 121) / 360, colors.BLUE) canvas.new_arrow(src=left_up, dst=centroid( [left[1][0].vertices()[0], left[1][0].vertices()[1]])) canvas.new_text(anchor=tree['right_up'], text='$31^\\circ$N') right_up = canvas.new_rectangle(center=tree['right_up'], width=1, height=0.4,
from fathom import Point, ORIGIN from fathom.tikz import Canvas from fathom.geometry import * import fathom.tikz.colors as colors import fathom.tikz.line_styles as line_styles import fathom.tikz.locations as locations from itertools import * if __name__ == '__main__': canvas = Canvas( preamble=['\\usepackage{amsmath}'], leading_instructions=['\\footnotesize']) canvas.new_polygon( vertices=[ Point(0.8, 0.7), Point(0.5, 1.4), Point(1.1, 2.8), Point(2.2, 2.5), Point(2.5, 1.1), Point(1.2, 0.5)], brush_color=colors.GRAY, pen_color=colors.INVISIBLE) vs = repeat(ORIGIN) vs = accumulate(vs, lambda x, _: x + Point(1, 0)) vs = list(islice(vs, 4)) for x in vs: canvas.new_line( src=x, dst=x + Point(0, 3),