Skip to content

Commit

Permalink
Make block_map dynamically constructed.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpwoodbu committed Jun 16, 2013
1 parent 11f5f44 commit 795925c
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void mtr_curses_hosts(int startstat)
}

#define NUM_FACTORS 8
static double factors[NUM_FACTORS] = { 0.02, 0.05, 0.08, 0.15, 0.33, 0.50, 0.80, 1.00 };
static double factors[NUM_FACTORS];
static int scale[NUM_FACTORS];
static int low_ms, high_ms;

Expand Down Expand Up @@ -462,8 +462,33 @@ void mtr_gen_scale(void)
}


/* NB: Must have NUM_FACTORS elements. */
static const char* block_map = ".123abc>";
static char block_map[NUM_FACTORS];

void mtr_curses_init() {
int i;
int block_split;

/* Initialize factors to a log scale. */
for (i = 0; i < NUM_FACTORS; i++) {
factors[i] = ((double)1 / NUM_FACTORS) * (i + 1);
factors[i] *= factors[i]; /* Squared. */
}

/* Initialize block_map. */
block_split = (NUM_FACTORS - 2) / 2;
if (block_split > 9) {
block_split = 9;
}
for (i = 1; i <= block_split; i++) {
block_map[i] = '0' + i;
}
for (i = block_split+1; i < NUM_FACTORS-1; i++) {
block_map[i] = 'a' + i - block_split - 1;
}
block_map[0] = '.';
block_map[NUM_FACTORS-1] = '>';
}


void mtr_print_scaled(int ms)
{
Expand Down Expand Up @@ -653,6 +678,7 @@ void mtr_curses_open(void)
raw();
noecho();

mtr_curses_init();
mtr_curses_redraw();
}

Expand Down

0 comments on commit 795925c

Please sign in to comment.