@@ -32,7 +32,7 @@ static inline int data_level(double rows, double data, double increment) {
32
32
}
33
33
34
34
void nvtop_line_plot (WINDOW * win , size_t num_data , const double * data ,
35
- unsigned num_plots , bool legend_left ,
35
+ unsigned num_lines , bool legend_left ,
36
36
char legend [MAX_LINES_PER_PLOT ][PLOT_MAX_LEGEND_SIZE ]) {
37
37
if (num_data == 0 )
38
38
return ;
@@ -41,13 +41,13 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
41
41
rows -= 1 ;
42
42
double increment = 100. / (double )(rows );
43
43
44
- assert (num_plots <= MAX_LINES_PER_PLOT && "Cannot plot more than " EXPAND_AND_QUOTE (MAX_LINES_PER_PLOT ) " lines" );
44
+ assert (num_lines <= MAX_LINES_PER_PLOT && "Cannot plot more than " EXPAND_AND_QUOTE (MAX_LINES_PER_PLOT ) " lines" );
45
45
unsigned lvl_before [MAX_LINES_PER_PLOT ];
46
- for (size_t k = 0 ; k < num_plots ; ++ k )
46
+ for (size_t k = 0 ; k < num_lines ; ++ k )
47
47
lvl_before [k ] = data_level (rows , data [k ], increment );
48
48
49
- for (size_t i = 0 ; i < num_data || i < (size_t )cols ; i += num_plots ) {
50
- for (unsigned k = 0 ; k < num_plots ; ++ k ) {
49
+ for (size_t i = 0 ; i < num_data || i < (size_t )cols ; i += num_lines ) {
50
+ for (unsigned k = 0 ; k < num_lines ; ++ k ) {
51
51
unsigned lvl_now_k = data_level (rows , data [i + k ], increment );
52
52
wcolor_set (win , k + 1 , NULL );
53
53
// Three cases: has increased, has decreased and remained level
@@ -69,7 +69,7 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
69
69
}
70
70
71
71
// Draw the continuation of the other metrics
72
- for (unsigned j = 0 ; j < num_plots ; ++ j ) {
72
+ for (unsigned j = 0 ; j < num_lines ; ++ j ) {
73
73
if (j != k ) {
74
74
if (lvl_before [j ] == top )
75
75
// The continuation is at the same level as the bottom corner
@@ -92,7 +92,7 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
92
92
} else {
93
93
// Case 3: stayed level
94
94
mvwhline (win , lvl_now_k , i + k , 0 , 1 );
95
- for (unsigned j = 0 ; j < num_plots ; ++ j ) {
95
+ for (unsigned j = 0 ; j < num_lines ; ++ j ) {
96
96
if (j != k ) {
97
97
if (lvl_before [j ] != lvl_now_k ) {
98
98
// Add the continuation of other metric lines
@@ -107,21 +107,19 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
107
107
}
108
108
}
109
109
int plot_y_position = 0 ;
110
- for (unsigned i = 0 ; i < num_plots && plot_y_position < rows ; ++ i ) {
111
- if (legend [i ]) {
112
- wcolor_set (win , i + 1 , NULL );
113
- if (legend_left ) {
114
- mvwprintw (win , plot_y_position , 0 , "%.*s" , cols , legend [i ]);
110
+ for (unsigned i = 0 ; i < num_lines && plot_y_position < rows ; ++ i ) {
111
+ wcolor_set (win , i + 1 , NULL );
112
+ if (legend_left ) {
113
+ mvwprintw (win , plot_y_position , 0 , "%.*s" , cols , legend [i ]);
114
+ } else {
115
+ size_t length = strlen (legend [i ]);
116
+ if (length <= (size_t )cols ) {
117
+ mvwprintw (win , plot_y_position , cols - length , "%s" , legend [i ]);
115
118
} else {
116
- size_t length = strlen (legend [i ]);
117
- if (length <= (size_t )cols ) {
118
- mvwprintw (win , plot_y_position , cols - length , "%s" , legend [i ]);
119
- } else {
120
- mvwprintw (win , plot_y_position , 0 , "%.*s" , length - cols , legend [i ]);
121
- }
119
+ mvwprintw (win , plot_y_position , 0 , "%.*s" , length - cols , legend [i ]);
122
120
}
123
- plot_y_position ++ ;
124
121
}
122
+ plot_y_position ++ ;
125
123
}
126
124
}
127
125
0 commit comments