Skip to content

Texts do not seem to respect viewport #387

@scottwittenburg

Description

@scottwittenburg

The following script should result in a plot where the text labels, as well as the line segments, are cropped to be within the viewport.

import vcs

x = vcs.init(geometry=(600, 600))

vp = [0.25, 0.75, 0.1, 0.9]

xs = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
ys = [0.2, 0.4, 0.6, 0.5, 0.7, 0.3, 0.2, 0.1, 0.9, 0.4]
txt = [str(idx) for idx in range(len(xs))]

xmin = min(xs)
xmax = max(xs)
ymin = min(xs)
ymax = max(ys)

dx = 2

l = x.createline()
l.color = ['Green',]
l.viewport = vp
l.worldcoordinate = [xmin + dx, xmax - dx, ymin, ymax]
l.x = xs
l.y = ys

t = x.createtext()
t.viewport = vp
t.worldcoordinate = [xmin + dx, xmax - dx, ymin, ymax]
t.color = 'Red'
t.x = xs
t.y = ys
t.string = txt
t.height = 10

x.plot(l)
x.plot(t)

x.png('texts-viewport-issue.png')

However, the lines are cropped within the viewport but texts are not, as can be seen in this image:

texts-viewport-issue

I do not think this issue was introduced by the update to Context2D rendering in the VTK backend, because the thermo repo has an old baseline which shows that the problem has existed all along, but `vcs didn't have a test that caught it.

I have a fix in a branch on my fork, here. However, that branch illustrates that there is a problem with the templated viewport coordinates, as in projected plots, the viewport isn't big enough to allow room for the tick labels.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions