add legend entries dynamically

This commit is contained in:
karthikmurakonda 2022-11-10 11:21:36 +05:30
parent a8faacf61f
commit 6a733aa270
4 changed files with 28 additions and 111 deletions

View File

@ -897,44 +897,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="rgba">rgb(253,0,0)</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">IITdh</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
@ -974,39 +936,7 @@
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="rgba">rgb(253,0,0)</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">IITdh</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
<child>
<placeholder/>
@ -1050,39 +980,7 @@
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="rgba">rgb(253,0,0)</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">IITdh</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
<child>
<placeholder/>

View File

@ -932,12 +932,6 @@
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
@ -1123,7 +1117,7 @@
<property name="can-focus">False</property>
<property name="label" translatable="yes">Voltage Magnitude</property>
<attributes>
<attribute name="scale" value="2"/>
<attribute name="scale" value="1"/>
</attributes>
</object>
<packing>

View File

@ -41,6 +41,9 @@ struct _UtData
GtkWidget *swad;
GtkWidget *maplabel;
GtkWidget *graphlabel;
GtkWidget *gl1;
GtkWidget *gl2;
GtkWidget *gl3;
};
UtData *utdata;

View File

@ -313,6 +313,9 @@ void utility_tools(GtkButton *but, gpointer udata)
utdata->swdfreq = GTK_WIDGET(gtk_builder_get_object(builder, "swdfreq"));
utdata->maplabel = GTK_WIDGET(gtk_builder_get_object(builder, "maplabel"));
utdata->graphlabel = GTK_WIDGET(gtk_builder_get_object(builder, "graphlabel"));
utdata->gl1 = GTK_WIDGET(gtk_builder_get_object(builder, "gl1"));
utdata->gl2 = GTK_WIDGET(gtk_builder_get_object(builder, "gl2"));
utdata->gl3 = GTK_WIDGET(gtk_builder_get_object(builder, "gl3"));
gtk_widget_set_sensitive(utdata->voltage, FALSE);
gtk_widget_set_visible(utdata->algorithm, FALSE);
@ -407,6 +410,25 @@ void utility_tools(GtkButton *but, gpointer udata)
live_chart_path_set_color(live_chart_serie_get_line(temp_visptr->serie_dfreq), &color);
live_chart_chart_add_serie(chart_dfreq, temp_visptr->serie_dfreq);
// create a grid with gtkcolorbutton and gtklabel
GtkWidget *grid = gtk_grid_new();
GtkWidget *color_button = gtk_color_button_new_with_rgba(&color);
gtk_grid_attach(GTK_GRID(grid), color_button, 0, 0, 1, 1);
gchar *label_text = g_strdup_printf("%d", llptr->pmuid);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new(label_text), 1, 0, 1, 1);
// TODO: customise the line color
gtk_box_pack_start(GTK_BOX(utdata->gl1), grid, FALSE, FALSE, 0);
GtkWidget *grid2 = gtk_grid_new();
GtkWidget *color_button2 = gtk_color_button_new_with_rgba(&color);
gtk_grid_attach(GTK_GRID(grid2), color_button2, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid2), gtk_label_new(label_text), 1, 0, 1, 1);
gtk_box_pack_start(GTK_BOX(utdata->gl2), grid2, FALSE, FALSE, 0);
GtkWidget *grid3 = gtk_grid_new();
GtkWidget *color_button3 = gtk_color_button_new_with_rgba(&color);
gtk_grid_attach(GTK_GRID(grid3), color_button3, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid3), gtk_label_new(label_text), 1, 0, 1, 1);
gtk_box_pack_start(GTK_BOX(utdata->gl3), grid3, FALSE, FALSE, 0);
temp_visptr->next = (struct vis_data *)malloc(sizeof(struct vis_data));
temp_visptr = temp_visptr->next;
index++;