Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made upspeedgraph and downspeed graph scale on a common axis #1991

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void print_no_update(struct text_object *obj, char *p,

#ifdef BUILD_GUI
void scan_loadgraph_arg(struct text_object *obj, const char *arg) {
scan_graph(obj, arg, 0);
scan_graph(obj, arg, 0, FALSE);
}

double loadgraphval(struct text_object *obj) {
Expand Down
10 changes: 5 additions & 5 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#ifdef BUILD_GUI
END OBJ(cpugraph, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
scan_graph(obj, arg, 1);
scan_graph(obj, arg, 1, FALSE);
DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
obj->callbacks.graphval = &cpu_barval;
obj->callbacks.free = &free_cpu;
Expand Down Expand Up @@ -1241,9 +1241,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(memwithbuffersbar, &update_meminfo) scan_bar(obj, arg, 1);
obj->callbacks.barval = &mem_with_buffers_barval;
#ifdef BUILD_GUI
END OBJ(memgraph, &update_meminfo) scan_graph(obj, arg, 1);
END OBJ(memgraph, &update_meminfo) scan_graph(obj, arg, 1, FALSE);
obj->callbacks.graphval = &mem_barval;
END OBJ(memwithbuffersgraph, &update_meminfo) scan_graph(obj, arg, 1);
END OBJ(memwithbuffersgraph, &update_meminfo) scan_graph(obj, arg, 1, FALSE);
obj->callbacks.graphval = &mem_with_buffers_barval;
#endif /* BUILD_GUI*/
#ifdef HAVE_SOME_SOUNDCARD_H
Expand Down Expand Up @@ -1825,7 +1825,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
"lua_graph needs arguments: <function name> [height],[width] [gradient "
"colour 1] [gradient colour 2] [scale] [-t] [-l]") auto [buf, skip] =
scan_command(arg);
scan_graph(obj, arg + skip, 100);
scan_graph(obj, arg + skip, 100, FALSE);
if (buf != nullptr) {
obj->data.s = buf;
} else {
Expand Down Expand Up @@ -1968,7 +1968,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(apcupsd_loadbar, &update_apcupsd) scan_bar(obj, arg, 100);
obj->callbacks.barval = &apcupsd_loadbarval;
#ifdef BUILD_GUI
END OBJ(apcupsd_loadgraph, &update_apcupsd) scan_graph(obj, arg, 100);
END OBJ(apcupsd_loadgraph, &update_apcupsd) scan_graph(obj, arg, 100, FALSE);
obj->callbacks.graphval = &apcupsd_loadbarval;
END OBJ(apcupsd_loadgauge, &update_apcupsd) scan_gauge(obj, arg, 100);
obj->callbacks.gaugeval = &apcupsd_loadbarval;
Expand Down
2 changes: 1 addition & 1 deletion src/diskio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void print_diskio_write(struct text_object *obj, char *p,
#ifdef BUILD_GUI
void parse_diskiograph_arg(struct text_object *obj, const char *arg) {
auto [buf, skip] = scan_command(arg);
scan_graph(obj, arg + skip, 0);
scan_graph(obj, arg + skip, 0, FALSE);

obj->data.opaque = prepare_diskio_stat(dev_name(buf));
free_and_zero(buf);
Expand Down
2 changes: 1 addition & 1 deletion src/exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void scan_exec_arg(struct text_object *obj, const char *arg,
cmd = scan_gauge(obj, cmd, 100);
} else if ((execflag & EF_GRAPH) != 0u) {
auto [buf, skip] = scan_command(cmd);
scan_graph(obj, cmd + skip, 100);
scan_graph(obj, cmd + skip, 100, FALSE);
cmd = buf;
if (cmd == nullptr) {
NORM_ERR("error parsing arguments to execgraph object");
Expand Down
2 changes: 1 addition & 1 deletion src/net_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void parse_net_stat_graph_arg(struct text_object *obj, const char *arg,
void *free_at_crash) {
/* scan arguments and get interface name back */
auto [buf, skip] = scan_command(arg);
scan_graph(obj, arg + skip, 0);
scan_graph(obj, arg + skip, 0, TRUE);

// default to DEFAULTNETDEV
if (buf != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/nvidia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ int set_nvidia_query(struct text_object *obj, const char *arg,
break;
case text_node_t::GRAPH: {
auto [buf, skip] = scan_command(arg);
scan_graph(obj, arg + skip, 100);
scan_graph(obj, arg + skip, 100, FALSE);
arg = buf;
} break;
case text_node_t::GAUGE:
Expand Down
16 changes: 15 additions & 1 deletion src/specials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct special_node *specials = nullptr;

int special_count;
int graph_count = 0;
double maxspeedval = 1e-47; /* The maximum value among the speed graphs */

std::map<int, double *> graphs;

Expand Down Expand Up @@ -106,6 +107,7 @@ struct graph {
Colour first_colour, last_colour;
double scale;
char tempgrad;
char speedgraph; /* If the current graph is a speed graph */
};

struct stippled_hr {
Expand Down Expand Up @@ -249,7 +251,7 @@ std::pair<char *, size_t> scan_command(const char *s) {
* @param[in] defscale default scale if no scale argument given
* @return whether parsing was successful
**/
bool scan_graph(struct text_object *obj, const char *argstr, double defscale) {
bool scan_graph(struct text_object *obj, const char *argstr, double defscale, char speedGraph) {
char first_colour_name[1024] = {'\0'};
char last_colour_name[1024] = {'\0'};

Expand All @@ -267,6 +269,10 @@ bool scan_graph(struct text_object *obj, const char *argstr, double defscale) {
g->scale = defscale;
g->tempgrad = FALSE;

if (speedGraph) {
g->speedgraph = TRUE;
}

if (argstr == nullptr) return false;

/* set tempgrad to true if '-t' specified.
Expand Down Expand Up @@ -486,6 +492,10 @@ static void graph_append(struct special_node *graph, double f, char showaslog) {
if (graph->scaled != 0) {
graph->scale =
*std::max_element(graph->graph + 0, graph->graph + graph->graph_width);
if (graph->speedgraph) {
maxspeedval = graph->scale < maxspeedval ? maxspeedval : graph->scale;
graph->scale = maxspeedval;
}
if (graph->scale < 1e-47) {
/* avoid NaN's when the graph is all-zero (e.g. before the first update)
* there is nothing magical about 1e-47 here */
Expand Down Expand Up @@ -610,6 +620,10 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size,
}
#endif

if (g->speedgraph) {
s->speedgraph = TRUE;
}

if (store_graph_data_explicitly.get(*state)) {
if (s->graph) { s->graph = retrieve_graph(g->id, s->graph_width); }

Expand Down
3 changes: 2 additions & 1 deletion src/specials.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct special_node {
Colour last_colour;
short font_added;
char tempgrad;
char speedgraph;
struct special_node *next;
};

Expand All @@ -97,7 +98,7 @@ const char *scan_gauge(struct text_object *, const char *, double);
#ifdef BUILD_GUI
void scan_font(struct text_object *, const char *);
std::pair<char *, size_t> scan_command(const char *);
bool scan_graph(struct text_object *, const char *, double);
bool scan_graph(struct text_object *, const char *, double, char);
void scan_tab(struct text_object *, const char *);
void scan_stippled_hr(struct text_object *, const char *);

Expand Down
2 changes: 1 addition & 1 deletion tests/test-graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct graph {

static std::pair<struct graph, bool> test_parse(const char *s) {
struct text_object obj;
bool result = scan_graph(&obj, s, default_scale);
bool result = scan_graph(&obj, s, default_scale,FALSE);
auto g = static_cast<struct graph *>(obj.special_data);
struct graph graph = *g;
free(g);
Expand Down
Loading