sgreben / jp

dead simple terminal plots from JSON data. single binary, no dependencies. linux, osx, windows.
MIT License
1.32k stars 33 forks source link

Histogram legend is missing the first interval #23

Open gsauthof opened 4 years ago

gsauthof commented 4 years ago

Example:

seq 1000 1000000 | jp -input csv  -x '[*]' -type hist -bins 15

When my terminal is wide enough then the 15 intervals are correctly included below each bar.

But when the terminal to small for inline display, the then displayed legend just includes 14 intervals, i.e. the interval for the zeroth bar is missing.

That means the legend looks like this:

1  [67600,134200) 
2  [134200,200800)
3  [200800,267400)
4  [267400,334000)
5  [334000,400600)
6  [400600,467200)
7  [467200,533800)
8  [533800,600400)
9  [600400,667000)
10 [667000,733600)
11 [733600,800200)
12 [800200,866800)
13 [866800,933400)
14 [933400,1e+06]

The inline display:

[1000,67600)   [67600,134200)   [134200,200800) [200800,267400)  [267400,334000) [334000,400600)  [400600,467200) [467200,533800)  [533800,600400) [600400,667000)  [667000,733600) [733600,800200)  [800200,866800) [866800,933400)  [933400,1e+06]
tberreis commented 7 months ago

I had the same issue and got it working by subtracting the height of the runes. Unfortunately it seems this project is no longer maintained so here's what I changed locally:

        if labelsRight {
                for i, group := range table.Columns {
-                       c.GetBuffer().WriteRight(c.GetBuffer().Height-i, paddingX+1+chartWidth/c.RuneSize().Width, []rune(Fi(i)))
-                       c.GetBuffer().WriteRight(c.GetBuffer().Height-i, paddingX+4+chartWidth/c.RuneSize().Width, []rune(group))
+                       c.GetBuffer().WriteRight(c.GetBuffer().Height-i-c.RuneSize().Height, paddingX+1+chartWidth/c.RuneSize().Width, []rune(Fi(i)))
+                       c.GetBuffer().WriteRight(c.GetBuffer().Height-i-c.RuneSize().Height, paddingX+4+chartWidth/c.RuneSize().Width, []rune(group))
                }
        }

image

Before image

After image