zjl9959 / algviz

Algorithm animation engine for Python in Jupyter.
https://zjl9959.github.io/algviz/
GNU General Public License v3.0
64 stars 6 forks source link

Access table with cursor throw exception when "show_index=False" #5

Closed zjl9959 closed 1 year ago

zjl9959 commented 1 year ago

Describe the bug:

  1. What's your test code?
import algviz
viz = algviz.Visualizer(1)
grid = viz.createTable(1, 1, [[1]], show_index=False)
r = viz.createCursor(0, 'r')
c = viz.createCursor(0, 'c')
grid[r][c]
viz.display()
  1. What's the exceptions?
  Table._add_cursor_(self, cursor, is_row)
  ...
  --> 413     self._svg.update_text_element(self._row_index2text[r], (pos_x, pos_y))
      414 for c in range(self._col):
      415     pos_x = (c + 0.5) * self._cell_width - self._label_font_size * len(str(c)) * 0.25 + self._cell_margin + self._row_cursor_mgr.get_cursors_occupy()

AttributeError: 'Table' object has no attribute '_row_index2text'
  1. [Optional] Add screenshots to help explain your problem.

Test enviroment:

Additional context: Add any other context about the problem here.

zjl9959 commented 1 year ago
import algviz
viz = algviz.Visualizer(1)
grid = viz.createTable(1, 1, [[1]], show_index=True)
r = viz.createCursor(0, 'r')
c = viz.createCursor(0, 'c')
grid[r][c]
viz.display()

This code can get the expect results.

zjl9959 commented 1 year ago

Fixed in commit: https://github.com/zjl9959/algviz/commit/3b7b6f76abdb16c819b18c204796fd7df3251b76