diff --git a/src/common.cc b/src/common.cc index bcbaeebe..53a9fe7c 100644 --- a/src/common.cc +++ b/src/common.cc @@ -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) { diff --git a/src/core.cc b/src/core.cc index 0ce2cbdc..d4de97b4 100644 --- a/src/core.cc +++ b/src/core.cc @@ -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; @@ -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 @@ -1825,7 +1825,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, "lua_graph needs arguments: [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 { @@ -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; diff --git a/src/diskio.cc b/src/diskio.cc index 04f26771..130ff45c 100644 --- a/src/diskio.cc +++ b/src/diskio.cc @@ -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); diff --git a/src/exec.cc b/src/exec.cc index edd60571..81cf486c 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -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"); diff --git a/src/net_stat.cc b/src/net_stat.cc index b36e1ce4..4cfc55c6 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -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) { diff --git a/src/nvidia.cc b/src/nvidia.cc index 6f680339..a1f1ea31 100644 --- a/src/nvidia.cc +++ b/src/nvidia.cc @@ -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: diff --git a/src/specials.cc b/src/specials.cc index 44cecbf3..619faad1 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -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 graphs; @@ -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 { @@ -249,7 +251,7 @@ std::pair 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'}; @@ -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. @@ -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 */ @@ -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); } diff --git a/src/specials.h b/src/specials.h index c2c9114d..2bdc8603 100644 --- a/src/specials.h +++ b/src/specials.h @@ -80,6 +80,7 @@ struct special_node { Colour last_colour; short font_added; char tempgrad; + char speedgraph; struct special_node *next; }; @@ -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 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 *);