etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
773 stars 216 forks source link

Misaligned between alignment and scale when column of alinged panel is more than one during zooming in #673

Closed dengzq1234 closed 1 year ago

dengzq1234 commented 1 year ago

If more than one TreeLayouts in differnt columns, alignment will be misaligned with the scale face under the format 'seq' and 'compactseq' during zooming in.

Here is example, normal situation(only one treelayout) download (alignment aligned with the position 1817 when zoom in alined panel, perfect)

example when more one treelayout, image (now column 1 is Rectangular face, column 2 is alignment face)

image (alignment fails to align with the position 1817 when zoom in alined panel and cannot be recovered)

Issue tracked down: ete4/smartview/renderer/faces.py line 1401

    posw = self.poswidth * self.w_scale
    viewport_start = vx0 - self.viewport_margin / zx
    viewport_end = vx1 + self.viewport_margin / zx
    sm_x = max(viewport_start - x0, 0)
    sm_start = round(sm_x / posw)
    w = self.seqlength * posw
    sm_x0 = x0 if drawer.TYPE == "rect" else 0
    sm_end = self.seqlength - round(max(sm_x0 + w - viewport_end, 0) / posw)

    if too_small or self.seq_format == "[]":
        for start, end in self.blocks:
            if end >= sm_start and start <= sm_end:
                bstart = max(sm_start, start)
                bend = min(sm_end, end)
                bx = x0 + bstart * posw
                by, bh = get_height(bx, y)
                box = Box(bx, by, (bend + 1 - bstart) * posw, bh)
                yield [ "pixi-block", box ]

    else:
        seq = self.get_seq(sm_start, sm_end)
        sm_x = sm_x if drawer.TYPE == 'rect' else x0
        y, h = get_height(sm_x, y)
        sm_box = Box(sm_x+sm_x0, y, posw * len(seq), h)

        if self.seq_format == 'compactseq' or posw * zx < self._min_fsize:
            aa_type = "notext"
        else:
            aa_type = "text"
        yield [ f'pixi-aa_{aa_type}', sm_box, seq ]

if sm_box start with sm_x is correct only there is no other layouts in previous aligned panel.

Solution: line 1424 sm_box = Box(sm_x, y, posw * len(seq), h) should be sm_box = Box(sm_x+sm_x0, y, posw * len(seq), h)

jordibc commented 1 year ago

This issue should be solved with commit https://github.com/etetoolkit/ete/commit/d2d59b7af33874fe5fbaf378f7b0c8e5841cb681