diff --git a/dvc/dagascii.py b/dvc/dagascii.py index 728778ba2..ec6689fa8 100644 --- a/dvc/dagascii.py +++ b/dvc/dagascii.py @@ -1,13 +1,88 @@ import math -from asciicanvas.asciicanvas import AsciiCanvas -from asciicanvas.style import Style - from grandalf.graphs import Vertex, Edge, Graph from grandalf.layouts import SugiyamaLayout from grandalf.routing import route_with_lines, EdgeViewer +class AsciiCanvas(object): + def __init__(self, cols, lines): + assert cols > 1 + assert lines > 1 + + self.cols = cols + self.lines = lines + self.canvas = [[' '] * cols for l in range(lines)] + + def draw(self): + for line in self.canvas: + print(''.join(line)) + + def point(self, x, y, char): + assert x >= 0 + assert x < self.cols + assert y >= 0 + assert y < self.lines + + self.canvas[y][x] = char + + def line(self, x0, y0, x1, y1, char): + if x0 > x1: + x1, x0 = x0, x1 + y1, y0 = y0, y1 + + dx = x1 - x0 + dy = y1 - y0 + + if dx == 0 and dy == 0: + self.point(x0, y0, char) + elif abs(dx) >= abs(dy): + for x in range(x0, x1 + 1): + if dx == 0: + y = y0 + else: + y = y0 + int(round((x - x0) * dy / float((dx)))) + self.point(x, y, char) + elif y0 < y1: + for y in range(y0, y1 + 1): + if dy == 0: + x = x0 + else: + x = x0 + int(round((y - y0) * dx / float((dy)))) + self.point(x, y, char) + else: + for y in range(y1, y0 + 1): + if dy == 0: + x = x0 + else: + x = x1 + int(round((y - y1) * dx / float((dy)))) + self.point(x, y, char) + + def text(self, x, y, text): + for i, c in enumerate(text): + self.point(x + i, y, c) + + def box(self, x0, y0, w, h): + assert w > 1 + assert h > 1 + + w -= 1 + h -= 1 + + for x in range(x0, x0 + w): + self.point(x, y0, '-') + self.point(x, y0 + h, '-') + + for y in range(y0, y0 + h): + self.point(x0, y, '|') + self.point(x0 + w, y, '|') + + self.point(x0, y0, '+') + self.point(x0 + w, y0, '+') + self.point(x0, y0 + h, '+') + self.point(x0 + w, y0 + h, '+') + + class Dagascii(object): def __init__(self, vertexes, edges): # @@ -100,22 +175,22 @@ class Dagascii(object): assert end_x >= 0 assert end_y >= 0 - canvas.add_line(start_x, start_y, - end_x, end_y, - style=Style('*')) + canvas.line(start_x, start_y, + end_x, end_y, + '*') for v in self.sug.g.sV: # NOTE: moving boxes w/2 to the left x = v.view.xy[0] - v.view.w/2.0 y = v.view.xy[1] - canvas.add_nine_patch_rect(int(round(x - minx)), - int(round(y - miny)), - v.view.w, - v.view.h) + canvas.box(int(round(x - minx)), + int(round(y - miny)), + v.view.w, + v.view.h) - canvas.add_text(int(round(x - minx)) + 1, - int(round(y - miny)) + 1, - v.data) + canvas.text(int(round(x - minx)) + 1, + int(round(y - miny)) + 1, + v.data) - canvas.print_out() + canvas.draw() diff --git a/requirements.txt b/requirements.txt index 59a8f335a..ab85126e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,5 +22,4 @@ requests>=2.18.4 wheel>=0.31.1 futures>=3.2.0; python_version == "2.7" grandalf==0.6 -asciicanvas==0.0.3 pydot>=1.2.4 diff --git a/setup.py b/setup.py index c5807d915..7452bba39 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,6 @@ install_requires = [ "jsonpath-rw==1.4.0", "requests>=2.18.4", "grandalf==0.6", - "asciicanvas==0.0.3", ] # Extra dependencies for remote integrations