Skip to content

Commit

Permalink
[canvas- graph-] fix handling of label chars with screen width > 1
Browse files Browse the repository at this point in the history
Also fixes an arithmetic/logic bug in calculating label offset for
labels holding a row value that was not None. This will cause
labels to shift left for GeoJSONMap, PbfCanvas, and ShapeMap.
Labels on CanvasSheet and GraphSheet are unaffected.
  • Loading branch information
midichef authored and anjakefala committed Jan 12, 2025
1 parent f5fad14 commit de96aab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions visidata/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ def _mark_overlap_text(labels, textobj):
def _overlaps(a, b):
a_x1, _, a_txt, _, _ = a
b_x1, _, b_txt, _, _ = b
a_x2 = a_x1 + len(a_txt)
b_x2 = b_x1 + len(b_txt)
a_x2 = a_x1 + dispwidth(a_txt)
b_x2 = b_x1 + dispwidth(b_txt)
if a_x1 < b_x1 < a_x2 or a_x1 < b_x2 < a_x2 or \
b_x1 < a_x1 < b_x2 or b_x1 < a_x2 < b_x2:
return True
Expand All @@ -325,10 +325,10 @@ def _overlaps(a, b):
for pix_x, pix_y, txt, attr, row in self.labels:
if attr in self.hiddenAttrs:
continue
if row is not None:
pix_x -= len(txt)/2*2
char_y = int(pix_y/4)
char_x = int(pix_x/2)
if row is not None:
char_x -= math.ceil(dispwidth(txt)/2)*2
o = (char_x, char_y, txt, attr, row)
_mark_overlap_text(labels_by_line[char_y], o)

Expand Down
4 changes: 2 additions & 2 deletions visidata/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ def add_x_axis_label(self, frac):
txt = tick + txt
else:
right_margin = self.plotwidth - 1 - self.plotviewBox.xmax
if (len(txt)+len(tick))*2 <= right_margin:
if (dispwidth(txt)+dispwidth(tick))*2 <= right_margin:
txt = tick + txt
else:
# shift rightmost label to be left of its tick
x -= len(txt)*2
x -= dispwidth(txt)*2
if len(tick) == 0:
x += 1
txt = txt + tick
Expand Down

0 comments on commit de96aab

Please sign in to comment.