Skip to content

Commit

Permalink
[graph-] add symbol to mark x axis ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Jun 22, 2023
1 parent 923e1b2 commit 5e74150
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions visidata/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math

vd.option('color_graph_axis', 'bold', 'color for graph axis labels')
vd.option('disp_graph_tick_x', '╵', 'character for graph x-axis ticks')


@VisiData.api
Expand Down Expand Up @@ -149,13 +150,23 @@ def add_y_axis_label(self, frac):

def add_x_axis_label(self, frac):
txt = self.formatXLabel(self.visibleBox.xmin + frac*self.visibleBox.w)
tick = vd.options.disp_graph_tick_x or ''

# plot x-axis labels below the plotviewBox.ymax, but within the plotview width-wise
attr = colors.color_graph_axis
x = self.plotviewBox.xmin + frac*self.plotviewBox.w
if frac == 1.0:
# shift rightmost label to be readable
x -= 2*max(len(txt) - math.ceil(self.rightMarginPixels/2), 0)

if frac < 1.0:
txt = tick + txt
else:
if (len(txt)+len(tick))*2 <= self.rightMarginPixels:
txt = tick + txt
else:
# shift rightmost label to be left of its tick
x -= len(txt)*2
if len(tick) == 0:
x += 1
txt = txt + tick

self.plotlabel(x, self.plotviewBox.ymax+4, txt, attr)

Expand Down

0 comments on commit 5e74150

Please sign in to comment.