Skip to content

Commit

Permalink
Merge pull request traviscross#16 from rpwoodbu/fix_sizes
Browse files Browse the repository at this point in the history
Convey static array sizes with a constant instead of manual immediate values.
Good work. You say "log scale" while it is quadratic. wouldn't 
for (i=NUM_FACTORS-1,t=1.0;i>0;i--, t = t/2.5) factors[i] = t;
work better? (I'm away, I remember seeing factors 0.02 and 0.05 next to each other hence the 2.5 )
  • Loading branch information
rewolff committed Jun 18, 2013
2 parents 16c6a85 + 795925c commit 6a9f5a0
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ void mtr_curses_hosts(int startstat)
move(2, 0);
}


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

void mtr_gen_scale(void)
Expand All @@ -439,7 +439,7 @@ void mtr_gen_scale(void)
low_ms = 1000000;
high_ms = -1;

for (i = 0; i < 8; i++) {
for (i = 0; i < NUM_FACTORS; i++) {
scale[i] = 0;
}
max = net_max();
Expand All @@ -456,19 +456,45 @@ void mtr_gen_scale(void)
}
}
range = high_ms - low_ms;
for (i = 0; i < 8; i++) {
for (i = 0; i < NUM_FACTORS; i++) {
scale[i] = low_ms + ((double)range * factors[i]);
}
}


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)
{
int i;

for (i = 0; i < 8; i++) {
for (i = 0; i < NUM_FACTORS; i++) {
if (ms <= scale[i]) {
printw("%c", block_map[i]);
return;
Expand All @@ -494,7 +520,7 @@ void mtr_fill_graph(int at, int cols)
} else {
if (display_mode == 1) {
if (saved[i] > scale[6]) {
printw("%c", block_map[7]);
printw("%c", block_map[NUM_FACTORS-1]);
} else {
printw(".");
}
Expand Down Expand Up @@ -637,7 +663,7 @@ void mtr_curses_redraw(void)
printw("Scale:");
attroff(A_BOLD);

for (i = 0; i < 7; i++) {
for (i = 0; i < NUM_FACTORS-1; i++) {
printw(" %c:%d ms", block_map[i], scale[i]/1000);
}
}
Expand All @@ -652,6 +678,7 @@ void mtr_curses_open(void)
raw();
noecho();

mtr_curses_init();
mtr_curses_redraw();
}

Expand Down

0 comments on commit 6a9f5a0

Please sign in to comment.