Skip to content

Commit

Permalink
add ypad / xpad
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jan 26, 2013
1 parent 96635dd commit 480695f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/histo.c
Expand Up @@ -42,7 +42,8 @@ width_of(int n) {
void
draw_histogram(int data[], int len) {
int m = max(data, len);
int pad = 4;
int xpad = 4;
int ypad = 4;
int n = 0;

// term size
Expand All @@ -51,7 +52,7 @@ draw_histogram(int data[], int len) {

// histogram size
int xw = width_of(m);
int hh = h - pad - 1;
int hh = h - ypad - 1;

// clear
term_clear("screen");
Expand All @@ -69,7 +70,7 @@ draw_histogram(int data[], int len) {
// y-axis
n = 0;
term_move_to(3 + xw, 1);
while (n < (h - pad - 1)) {
while (n < (h - ypad - 1)) {
term_move_by(0, 2);
term_color("grey");
printf("․");
Expand All @@ -78,8 +79,8 @@ draw_histogram(int data[], int len) {

// x-axis
n = 0;
term_move_to(2 + pad, h - 2);
while (n < (w - pad * 3)) {
term_move_to(2 + xpad, h - 2);
while (n < (w - xpad * 3)) {
term_color("grey");
printf("․");
term_move_by(5, 0);
Expand All @@ -90,11 +91,11 @@ draw_histogram(int data[], int len) {
int x = 1;
for (int i = 0; i < len; ++i) {
float p = 0 == data[i] ? 0 : (float) data[i] / m;
int y = (h - pad) * p;
int y = (h - ypad) * p;
char *c = y < 0 ? "░" : "█";
if (y < 0) y = -y;
while (y--) {
term_move_to(x * 5 + 1, y - 1 - h + pad);
term_move_to(x * 5 + 1, y - 1 - h + ypad);
term_reset();
printf("%s", c);
}
Expand Down

0 comments on commit 480695f

Please sign in to comment.