aboutsummaryrefslogtreecommitdiff
path: root/remote_plot.c
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2025-04-30 03:08:12 -0700
committerXiao Pan <xyz@flylightning.xyz>2025-04-30 03:08:12 -0700
commit8ae8280e1d5e5af4f4f538a380535cd5048a7558 (patch)
tree7955abb132ee330a337708277352c73c9c8087d2 /remote_plot.c
parentde00233983f5df5158cbf7dfc14d493e985dda43 (diff)
cleaner code, return and continue instead of put inside a large if
Diffstat (limited to 'remote_plot.c')
-rw-r--r--remote_plot.c173
1 files changed, 86 insertions, 87 deletions
diff --git a/remote_plot.c b/remote_plot.c
index 512e40c..9fe3b1d 100644
--- a/remote_plot.c
+++ b/remote_plot.c
@@ -474,108 +474,107 @@ static void draw_function (GtkDrawingArea *area,
gpointer user_data)
{
DATA *data=user_data;
- if(!ListIsEmpty(&(data->cans)))
- {
- //printf("draw begin\n");
- //PLFLT xmin=data->cans.head->item.t;
- //PLFLT xmax=data->cans.end->item.t;
- PLFLT xmin,xmax;
- PLFLT ymin, ymax;
- int plot_counts=0;
- gboolean active_checkbutton[VOLTLEN+TEMPLEN];
-
- if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->live_toggle)))
- xmax=data->cans.end->item.t;
- else
- xmax=data->to_time;
+ if(ListIsEmpty(&data->cans))
+ return;
+
+ //printf("draw begin\n");
+ //PLFLT xmin=data->cans.head->item.t;
+ //PLFLT xmax=data->cans.end->item.t;
+ PLFLT xmin,xmax;
+ PLFLT ymin, ymax;
+ int plot_counts=0;
+ gboolean active_checkbutton[VOLTLEN+TEMPLEN];
+
+ if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->live_toggle)))
+ xmax=data->cans.end->item.t;
+ else
+ xmax=data->to_time;
- if(data->from_time_entered)
- xmin=data->from_time;
- else
- xmin=data->cans.head->item.t;
+ if(data->from_time_entered)
+ xmin=data->from_time;
+ else
+ xmin=data->cans.head->item.t;
- for(int i=0;i<(VOLTLEN+TEMPLEN);i++)
- if((active_checkbutton[i]=gtk_check_button_get_active(GTK_CHECK_BUTTON(data->checkbutton[i]))))
- plot_counts++;
+ for(int i=0;i<(VOLTLEN+TEMPLEN);i++)
+ if((active_checkbutton[i]=gtk_check_button_get_active(GTK_CHECK_BUTTON(data->checkbutton[i]))))
+ plot_counts++;
- plsdev( "extcairo" );
+ plsdev( "extcairo" );
+ {
+ char str[12];
+ sprintf(str,"%dx%d",
+ gtk_widget_get_width(data->area),
+ gtk_widget_get_height(data->area));
+ plsetopt("geometry", str);
+ }
+
+ // change to white background and black foreground, and gray color palette
+ // http://plplot.sourceforge.net/docbook-manual/plplot-html-5.15.0/color.html
+ // seems should be put before plinit; or need pladv(), plvpor(), plwind() for a new picture?
+ // more see example 16
+ // http://plplot.sourceforge.net/examples.php?demo=16
+ // /usr/share/plplot5.15.0/examples/c/x16c.c
+ plspal0("cmap0_black_on_white.pal");
+ plspal1("cmap1_gray.pal", 1);
+
+ // Initialize plplot
+ if(plot_counts>3)
+ plstar(3,(plot_counts+2)/3);
+ else
+ plstar(1,plot_counts);
+ pl_cmd( PLESC_DEVINIT, cr );
+
+ // 10 char unix time: 1745925459
+ // set numbers of digits to display x axis labels
+ plsxax(10,0);
+
+ for(int i=0;i<(VOLTLEN+TEMPLEN);i++)
+ {
+ if(!active_checkbutton[i])
+ continue;
+ if(i<VOLTLEN)
{
- char str[12];
- sprintf(str,"%dx%d",
- gtk_widget_get_width(data->area),
- gtk_widget_get_height(data->area));
- plsetopt("geometry", str);
+ // according to .dbc file
+ ymin=0;
+ ymax=6.;
}
-
- // change to white background and black foreground, and gray color palette
- // http://plplot.sourceforge.net/docbook-manual/plplot-html-5.15.0/color.html
- // seems should be put before plinit; or need pladv(), plvpor(), plwind() for a new picture?
- // more see example 16
- // http://plplot.sourceforge.net/examples.php?demo=16
- // /usr/share/plplot5.15.0/examples/c/x16c.c
- plspal0("cmap0_black_on_white.pal");
- plspal1("cmap1_gray.pal", 1);
-
- // Initialize plplot
- if(plot_counts>3)
- plstar(3,(plot_counts+2)/3);
else
- plstar(1,plot_counts);
- pl_cmd( PLESC_DEVINIT, cr );
-
- // 10 char unix time: 1745925459
- // set numbers of digits to display x axis labels
- plsxax(10,0);
+ {
+ // according to .dbc file
+ ymin=-50;
+ ymax=100;
+ }
- for(int i=0;i<(VOLTLEN+TEMPLEN);i++)
+ // Create a labelled box to hold the plot.
+ plenv(xmin, xmax, ymin, ymax, 0, 0);
+ if(i<VOLTLEN)
+ pllab("Time (s)","Voltage (V)",checkbutton_names[i]);
+ else
+ pllab("Time (s)","Temperature (C)",checkbutton_names[i]);
+ // Plot the data that was prepared above.
+ // plstring or plptex for scatter
+ // #(NNN) is Hershey font code, more see example 5, 6, 21
+ // #(727) is centred X symbol; other maybe useful codes: #(728)
+ // hershey font code see http://plplot.sourceforge.net/examples.php?demo=07 ?
{
- if(active_checkbutton[i])
+ Node * pnode = data->cans.head;
+ while(pnode!=NULL && ((pnode->item.t <= xmax) || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->live_toggle))) )
{
- if(i<VOLTLEN)
+ if(pnode->item.t >= xmin)
{
- // according to .dbc file
- ymin=0;
- ymax=6.;
- }
- else
- {
- // according to .dbc file
- ymin=-50;
- ymax=100;
- }
-
- // Create a labelled box to hold the plot.
- plenv(xmin, xmax, ymin, ymax, 0, 0);
- if(i<VOLTLEN)
- pllab("Time (s)","Voltage (V)",checkbutton_names[i]);
- else
- pllab("Time (s)","Temperature (C)",checkbutton_names[i]);
- // Plot the data that was prepared above.
- // plstring or plptex for scatter
- // #(NNN) is Hershey font code, more see example 5, 6, 21
- // #(727) is centred X symbol; other maybe useful codes: #(728)
- // hershey font code see http://plplot.sourceforge.net/examples.php?demo=07 ?
- {
- Node * pnode = data->cans.head;
- while(pnode!=NULL && ((pnode->item.t <= xmax) || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->live_toggle))) )
- {
- if(pnode->item.t >= xmin)
- {
- if(i<VOLTLEN)
- plptex(pnode->item.t,pnode->item.volt[i],1.,0.,0.5,"#(727)");
- else
- plptex(pnode->item.t,pnode->item.temp[i-VOLTLEN],1.,0.,0.5,"#(727)");
- }
- pnode=pnode->next;
- }
+ if(i<VOLTLEN)
+ plptex(pnode->item.t,pnode->item.volt[i],1.,0.,0.5,"#(727)");
+ else
+ plptex(pnode->item.t,pnode->item.temp[i-VOLTLEN],1.,0.,0.5,"#(727)");
}
+ pnode=pnode->next;
}
}
-
- // Close PLplot library
- plend();
}
+
+ // Close PLplot library
+ plend();
}
static void print_data (GtkWidget *widget, gpointer user_data)