1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2017 Maxime DOYEN
4 * This file is part of HomeBank.
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "gtk-chart-colors.h"
26 #include "gtk-chart.h"
41 static void gtk_chart_class_intern_init (gpointer
);
42 static void gtk_chart_class_init (GtkChartClass
*klass
);
43 static void gtk_chart_init (GtkChart
*chart
);
44 static void gtk_chart_dispose (GObject
* object
);
45 static void gtk_chart_finalize (GObject
* object
);
47 static gboolean
drawarea_configure_event(GtkWidget
*widget
, GdkEventConfigure
*event
, gpointer user_data
);
48 static void drawarea_realize_callback(GtkWidget
*widget
, gpointer user_data
);
49 static gboolean
drawarea_draw_callback(GtkWidget
*widget
, cairo_t
*wcr
, gpointer user_data
);
50 static gboolean
drawarea_motionnotifyevent_callback(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
51 static gboolean
drawarea_querytooltip_callback(GtkWidget
*widget
, gint x
, gint y
, gboolean keyboard_mode
, GtkTooltip
*tooltip
, gpointer user_data
);
53 static gboolean
drawarea_full_redraw(GtkWidget
*widget
, gpointer user_data
);
55 static void chart_calculation(GtkChart
*chart
);
56 static void chart_clear(GtkChart
*chart
);
58 static void colchart_first_changed( GtkAdjustment
*adj
, gpointer user_data
);
59 static void colchart_compute_range(GtkChart
*chart
);
60 static void colchart_calculation(GtkChart
*chart
);
61 static void colchart_scrollbar_setvalues(GtkChart
*chart
);
63 static void piechart_calculation(GtkChart
*chart
);
65 static GdkPixbuf
*create_color_pixbuf (struct rgbcol
*color
);
66 static GtkWidget
*legend_list_new(GtkChart
*chart
);
69 static GtkBoxClass
*gtk_chart_parent_class
= NULL
;
71 static const double dashed3
[] = {3.0};
76 static GType chart_type
= 0;
80 static const GTypeInfo chart_info
=
82 sizeof (GtkChartClass
),
84 NULL
, /* base_finalize */
85 (GClassInitFunc
) gtk_chart_class_intern_init
,
86 NULL
, /* class_finalize */
87 NULL
, /* class_data */
90 (GInstanceInitFunc
) gtk_chart_init
,
94 chart_type
= g_type_register_static (GTK_TYPE_BOX
, "GtkChart",
102 gtk_chart_class_intern_init (gpointer klass
)
104 gtk_chart_parent_class
= g_type_class_peek_parent (klass
);
105 gtk_chart_class_init ((GtkChartClass
*) klass
);
109 gtk_chart_class_init (GtkChartClass
* klass
)
111 GObjectClass
*gobject_class
;
113 DB( g_print("\n[gtkchart] class init\n") );
115 gobject_class
= G_OBJECT_CLASS (klass
);
117 //gobject_class->get_property = gtk_chart_get_property;
118 //gobject_class->set_property = gtk_chart_set_property;
119 gobject_class
->dispose
= gtk_chart_dispose
;
120 gobject_class
->finalize
= gtk_chart_finalize
;
125 gtk_chart_init (GtkChart
* chart
)
127 GtkWidget
*widget
, *vbox
;
128 GtkWidget
*scrollwin
, *treeview
;
130 DB( g_print("\n[gtkchart] init\n") );
133 chart
->surface
= NULL
;
141 chart
->barw
= GTK_CHART_BARW
;
142 chart
->show_mono
= FALSE
;
143 //chart->drawmode = CHART_DRAW_FULL;
145 chart
->lastactive
= -1;
147 chart
->minor_rate
= 1.0;
148 chart
->timer_tag
= 0;
150 gtk_chart_set_color_scheme(chart
, CHART_COLMAP_HOMEBANK
);
152 widget
=GTK_WIDGET(chart
);
154 gtk_box_set_homogeneous(GTK_BOX(widget
), FALSE
);
156 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
157 gtk_box_pack_start (GTK_BOX (widget
), vbox
, TRUE
, TRUE
, 0);
160 scrollwin
= gtk_frame_new(NULL
);
161 gtk_frame_set_shadow_type (GTK_FRAME(scrollwin
), GTK_SHADOW_ETCHED_IN
);
162 gtk_box_pack_start (GTK_BOX (vbox
), scrollwin
, TRUE
, TRUE
, 0);
164 //scrollwin = gtk_scrolled_window_new(NULL,NULL);
165 //gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
166 //gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
167 //gtk_box_pack_start (GTK_BOX (vbox), scrollwin, TRUE, TRUE, 0);
169 chart
->drawarea
= gtk_drawing_area_new();
170 //gtk_widget_set_double_buffered (GTK_WIDGET(widget), FALSE);
172 gtk_container_add( GTK_CONTAINER(scrollwin
), chart
->drawarea
);
173 gtk_widget_set_size_request(chart
->drawarea
, 100, 100 );
174 gtk_widget_set_has_tooltip(chart
->drawarea
, TRUE
);
175 gtk_widget_show(chart
->drawarea
);
179 PangoFontDescription *font_desc;
181 g_print("draw_area font\n");
183 style = gtk_widget_get_style(GTK_WIDGET(chart->drawarea));
184 font_desc = style->font_desc;
186 g_print("family: %s\n", pango_font_description_get_family(font_desc) );
187 g_print("size: %d (%d)\n", pango_font_description_get_size (font_desc), pango_font_description_get_size (font_desc )/PANGO_SCALE );
192 chart
->adjustment
= GTK_ADJUSTMENT(gtk_adjustment_new (0.0, 0.0, 1.0, 1.0, 1.0, 1.0));
193 chart
->scrollbar
= gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL
, GTK_ADJUSTMENT (chart
->adjustment
));
194 gtk_box_pack_start (GTK_BOX (vbox
), chart
->scrollbar
, FALSE
, TRUE
, 0);
196 /* legend treeview */
197 scrollwin
= gtk_scrolled_window_new(NULL
,NULL
);
198 chart
->scrollwin
= scrollwin
;
199 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin
), GTK_SHADOW_ETCHED_IN
);
200 //gtk_container_set_border_width (GTK_CONTAINER(scrollwin), 5);
201 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin
), GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
202 treeview
= legend_list_new(chart
);
203 chart
->treeview
= treeview
;
204 chart
->legend
= gtk_tree_view_get_model(GTK_TREE_VIEW(treeview
));
205 gtk_container_add(GTK_CONTAINER(scrollwin
), treeview
);
206 gtk_box_pack_start (GTK_BOX (widget
), scrollwin
, FALSE
, FALSE
, 0);
208 gtk_widget_add_events(GTK_WIDGET(chart
->drawarea
),
210 //GDK_POINTER_MOTION_MASK |
211 GDK_POINTER_MOTION_HINT_MASK
212 //GDK_BUTTON_PRESS_MASK |
213 //GDK_BUTTON_RELEASE_MASK
216 g_signal_connect( G_OBJECT(chart
->drawarea
), "configure-event", G_CALLBACK (drawarea_configure_event
), chart
);
217 g_signal_connect( G_OBJECT(chart
->drawarea
), "realize", G_CALLBACK(drawarea_realize_callback
), chart
) ;
218 g_signal_connect( G_OBJECT(chart
->drawarea
), "draw", G_CALLBACK(drawarea_draw_callback
), chart
) ;
220 g_signal_connect( G_OBJECT(chart
->drawarea
), "query-tooltip", G_CALLBACK(drawarea_querytooltip_callback
), chart
);
221 g_signal_connect( G_OBJECT(chart
->drawarea
), "motion-notify-event", G_CALLBACK(drawarea_motionnotifyevent_callback
), chart
);
223 g_signal_connect (G_OBJECT(chart
->adjustment
), "value-changed", G_CALLBACK (colchart_first_changed
), chart
);
225 //g_signal_connect( G_OBJECT(chart->drawarea), "map-event", G_CALLBACK(chart_map), chart ) ;
226 //g_signal_connect( G_OBJECT(chart->drawarea), "button-press-event", G_CALLBACK(chart_button_press), chart );
227 //g_signal_connect( G_OBJECT(chart->drawarea), "button-release-event", G_CALLBACK(chart_button_release), chart );
234 gtk_chart_new (gint type
)
238 DB( g_print("\n======================================================\n") );
239 DB( g_print("\n[gtkchart] new\n") );
241 chart
= g_object_new (GTK_TYPE_CHART
, NULL
);
244 return GTK_WIDGET(chart
);
249 gtk_chart_dispose (GObject
*gobject
)
251 //GtkChart *chart = GTK_CHART (object);
253 DB( g_print("\n[gtkchart] dispose\n") );
255 /* In dispose(), you are supposed to free all types referenced from this
256 * object which might themselves hold a reference to self. Generally,
257 * the most simple solution is to unref all members on which you own a
261 /* dispose() might be called multiple times, so we must guard against
262 * calling g_object_unref() on an invalid GObject by setting the member
263 * NULL; g_clear_object() does this for us, atomically.
265 //g_clear_object (&self->priv->an_object);
267 /* Always chain up to the parent class; there is no need to check if
268 * the parent class implements the dispose() virtual function: it is
269 * always guaranteed to do so
271 G_OBJECT_CLASS (gtk_chart_parent_class
)->dispose (gobject
);
278 gtk_chart_finalize (GObject
* object
)
280 GtkChart
*chart
= GTK_CHART (object
);
282 DB( g_print("\n[gtkchart] finalize\n") );
288 pango_font_description_free (chart
->pfd
);
294 cairo_surface_destroy (chart
->surface
);
295 chart
->surface
= NULL
;
298 G_OBJECT_CLASS (gtk_chart_parent_class
)->finalize (object
);
303 ** print a integer number
305 static gchar
*chart_print_int(GtkChart
*chart
, gint value
)
307 hb_strfmon_int(chart
->buffer1
, CHART_BUFFER_LENGTH
-1, (gdouble
)value
, chart
->kcur
, chart
->minor
);
308 return chart
->buffer1
;
312 ** print a double number
314 static gchar
*chart_print_double(GtkChart
*chart
, gchar
*buffer
, gdouble value
)
316 hb_strfmon(buffer
, CHART_BUFFER_LENGTH
-1, value
, chart
->kcur
, chart
->minor
);
322 ** clear any allocated memory
324 static void chart_clear(GtkChart
*chart
)
328 DB( g_print("\n[gtkchart] clear\n") );
330 //free & clear any previous allocated datas
331 if(chart
->title
!= NULL
)
333 g_free(chart
->title
);
337 if(chart
->subtitle
!= NULL
)
339 g_free(chart
->subtitle
);
340 chart
->subtitle
= NULL
;
343 if(chart
->items
!= NULL
)
345 for(i
=0;i
<chart
->nb_items
;i
++)
347 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
349 g_free(item
->legend
);
351 g_array_free(chart
->items
, TRUE
);
361 chart
->every_xval
= 7;
364 chart
->lastactive
= -1;
370 ** setup our chart with a model and column
372 static void chart_setup_with_model(GtkChart
*chart
, GtkTreeModel
*list_store
, guint column1
, guint column2
)
376 GtkTreeIter iter
, l_iter
;
379 DB( g_print("\n[chart] setup with model\n") );
383 if( GTK_IS_LIST_STORE(chart
->legend
) )
384 gtk_list_store_clear (GTK_LIST_STORE(chart
->legend
));
386 chart
->nb_items
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store
), NULL
);
388 chart
->items
= g_array_sized_new(FALSE
, FALSE
, sizeof(ChartItem
), chart
->nb_items
);
390 DB( g_print(" nb=%d, struct=%d\n", chart
->nb_items
, sizeof(ChartItem
)) );
392 chart
->dual
= (column1
== column2
) ? FALSE
: TRUE
;
394 /* Get the first iter in the list */
395 valid
= gtk_tree_model_get_iter_first (GTK_TREE_MODEL(list_store
), &iter
);
401 gdouble value1
, value2
;
405 /* column 0: pos (gint) */
406 /* column 1: key (gint) */
407 /* column 2: label (gchar) */
408 /* column x: values (double) */
410 gtk_tree_model_get (GTK_TREE_MODEL(list_store
), &iter
,
417 if(chart
->dual
|| chart
->abs
)
419 value1
= ABS(value1
);
420 value2
= ABS(value2
);
423 DB( g_print("%d: '%s' %.2f %2f\n", i
, label
, value1
, value2
) );
425 /* data1 value storage & min, max compute */
426 chart
->rawmin
= MIN(chart
->rawmin
, value1
);
427 chart
->rawmax
= MAX(chart
->rawmax
, value1
);
431 /* data2 value storage & min, max compute */
432 chart
->rawmin
= MIN(chart
->rawmin
, value2
);
433 chart
->rawmax
= MAX(chart
->rawmax
, value2
);
437 item
.serie1
= value1
;
438 item
.serie2
= value2
;
439 g_array_append_vals(chart
->items
, &item
, 1);
441 /* ensure rawmin rawmax not equal */
442 if(chart
->rawmin
== chart
->rawmax
)
448 /* populate our legend list */
449 color
= i
% chart
->color_scheme
.nb_cols
;
450 //color = id % chart->nb_cols;
452 //DB( g_print ("Row %d: (%s, %2.f) color %d\n", id, title, value, color) );
454 pixbuf
= create_color_pixbuf (&chart
->color_scheme
.colors
[color
]);
456 gtk_list_store_append (GTK_LIST_STORE(chart
->legend
), &l_iter
);
457 gtk_list_store_set (GTK_LIST_STORE(chart
->legend
), &l_iter
,
458 LST_LEGEND_COLOR
, pixbuf
,
459 LST_LEGEND_TITLE
, label
,
460 LST_LEGEND_AMOUNT
, value1
,
463 /* pie chart total sum */
464 chart
->total
+= ABS(value1
);
466 valid
= gtk_tree_model_iter_next (list_store
, &iter
);
470 // compute rate for legend for bar/pie
471 for(i
=0;i
<chart
->nb_items
;i
++)
473 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
475 item
->rate
= ABS(item
->serie1
*100/chart
->total
);
476 item
->legend
= g_markup_printf_escaped("%s (%.2f%%)", item
->label
, item
->rate
);
479 if( chart
->type
!= CHART_TYPE_LINE
)
482 valid
= gtk_tree_model_get_iter_first (GTK_TREE_MODEL(chart
->legend
), &iter
);
485 gdouble amount
, rate
;
487 gtk_tree_model_get(GTK_TREE_MODEL(chart
->legend
), &iter
,
488 LST_LEGEND_AMOUNT
, &amount
,
491 rate
= ABS( amount
*100/chart
->total
);
493 gtk_list_store_set(GTK_LIST_STORE(chart
->legend
), &iter
,
494 LST_LEGEND_RATE
, rate
,
497 valid
= gtk_tree_model_iter_next (GTK_TREE_MODEL(chart
->legend
), &iter
);
503 //g_print("total is %.2f\n", total);
504 //ensure the widget is mapped
505 //gtk_widget_map(chart);
510 static void chart_set_font_size(GtkChart
*chart
, gint font_size
)
514 //DB( g_print("\n[chart] set font size\n") );
518 case CHART_FONT_SIZE_TITLE
:
519 size
= chart
->pfd_size
+ 3;
521 case CHART_FONT_SIZE_SUBTITLE
:
522 size
= chart
->pfd_size
+ 1;
524 case CHART_FONT_SIZE_NORMAL
:
525 size
= chart
->pfd_size
- 1;
529 //DB( g_print(" size=%d\n", size) );
531 pango_font_description_set_size(chart
->pfd
, size
* PANGO_SCALE
);
537 ** recompute according to type
539 static void chart_recompute(GtkChart
*chart
)
542 DB( g_print("\n[gtkchart] recompute\n") );
544 chart_calculation (chart
);
548 case CHART_TYPE_LINE
:
550 colchart_compute_range(chart
);
551 colchart_calculation(chart
);
552 gtk_adjustment_set_value(chart
->adjustment
, 0);
553 colchart_scrollbar_setvalues(chart
);
554 gtk_widget_show(chart
->scrollbar
);
557 piechart_calculation(chart
);
558 gtk_widget_hide(chart
->scrollbar
);
569 static float CalculateStepSize(float range
, float targetSteps
)
571 // calculate an initial guess at step size
572 float tempStep
= range
/targetSteps
;
574 // get the magnitude of the step size
575 float mag
= (float)floor(log10(tempStep
));
576 float magPow
= (float)pow(10, mag
);
578 // calculate most significant digit of the new step size
579 float magMsd
= (int)(tempStep
/magPow
+ 0.5);
581 // promote the MSD to either 1, 2, or 5
584 else if (magMsd
> 2.0)
586 else if (magMsd
>= 1.0)
589 return magMsd
*magPow
;
593 static void colchart_compute_range(GtkChart
*chart
)
595 double lobound
=chart
->rawmin
, hibound
=chart
->rawmax
;
597 DB( g_print("\n[column] compute range\n") );
599 /* comptute max ticks */
600 chart
->range
= chart
->rawmax
- chart
->rawmin
;
601 gint maxticks
= MIN(10,floor(chart
->graph_height
/ (chart
->font_h
* 2)));
603 DB( g_print(" raw :: [%.2f - %.2f] range=%.2f\n", chart
->rawmin
, chart
->rawmax
, chart
->range
) );
604 DB( g_print(" raw :: maxticks=%d (%g / (%g*2))\n", maxticks
, chart
->graph_height
, chart
->font_h
) );
607 chart
->unit
= CalculateStepSize((hibound
-lobound
), maxticks
);
608 chart
->min
= -chart
->unit
* ceil(-lobound
/chart
->unit
);
609 chart
->max
= chart
->unit
* ceil(hibound
/chart
->unit
);
610 chart
->range
= chart
->max
- chart
->min
;
611 chart
->div
= chart
->range
/ chart
->unit
;
613 DB( g_print(" end :: interval=%.2f, ticks=%d\n", chart
->unit
, chart
->div
) );
614 DB( g_print(" end :: [%.2f - %.2f], range=%.2f\n", chart
->min
, chart
->max
, chart
->range
) );
619 static void chart_calculation(GtkChart
*chart
)
621 GtkWidget
*drawarea
= chart
->drawarea
;
622 GdkWindow
*gdkwindow
;
623 cairo_surface_t
*surf
= NULL
;
626 GtkAllocation allocation
;
632 DB( g_print("\n[gtkchart] calculation\n") );
634 gtk_widget_get_allocation(drawarea
, &allocation
);
636 chart
->l
= CHART_MARGIN
;
637 chart
->t
= CHART_MARGIN
;
638 chart
->r
= allocation
.width
- CHART_MARGIN
;
639 chart
->b
= allocation
.height
- CHART_MARGIN
;
640 chart
->w
= allocation
.width
- (CHART_MARGIN
*2);
641 chart
->h
= allocation
.height
- (CHART_MARGIN
*2);
644 gdkwindow
= gtk_widget_get_window(chart
->drawarea
);
647 surf
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
, allocation
.width
, allocation
.height
);
648 cr
= cairo_create (surf
);
651 cr
= gdk_cairo_create (gdkwindow
);
653 /* Create a PangoLayout, set the font and text */
654 layout
= pango_cairo_create_layout (cr
);
659 if(chart
->title
!= NULL
)
661 chart_set_font_size(chart
, CHART_FONT_SIZE_TITLE
);
662 pango_layout_set_font_description (layout
, chart
->pfd
);
664 pango_layout_set_text (layout
, chart
->title
, -1);
665 pango_layout_get_size (layout
, &tw
, &th
);
666 chart
->title_zh
= (th
/ PANGO_SCALE
);
667 DB( g_print(" - title: %s w=%d h=%d\n", chart
->title
, tw
, th
) );
671 chart
->subtitle_zh
= 0;
672 if(chart
->subtitle
!= NULL
)
674 chart_set_font_size(chart
, CHART_FONT_SIZE_SUBTITLE
);
675 pango_layout_set_font_description (layout
, chart
->pfd
);
677 pango_layout_set_text (layout
, chart
->subtitle
, -1);
678 pango_layout_get_size (layout
, &tw
, &th
);
679 chart
->subtitle_zh
= (th
/ PANGO_SCALE
);
680 DB( g_print(" - title: %s w=%d h=%d\n", chart
->subtitle
, tw
, th
) );
683 chart
->subtitle_y
= chart
->t
+ chart
->title_zh
;
685 // todo: compute maxwidth of item labels
687 for(i
=0;i
<chart
->nb_items
;i
++)
689 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
692 pango_layout_set_text (layout
, item
->label
, -1);
693 pango_layout_get_size (layout
, &tw
, &th
);
694 label_w
= MAX(label_w
, (tw
/ PANGO_SCALE
));
697 chart
->label_w
= label_w
+ CHART_SPACING
;
699 DB( g_print(" - label_w:%g\n", chart
->label_w
) );
702 // compute other text
703 chart_set_font_size(chart
, CHART_FONT_SIZE_NORMAL
);
704 pango_layout_set_font_description (layout
, chart
->pfd
);
706 // compute amount scale
707 valstr
= chart_print_int(chart
, (gint
)chart
->min
);
708 pango_layout_set_text (layout
, valstr
, -1);
709 pango_layout_get_size (layout
, &tw
, &th
);
710 chart
->scale_w
= (tw
/ PANGO_SCALE
);
712 valstr
= chart_print_int(chart
, (gint
)chart
->max
);
713 pango_layout_set_text (layout
, valstr
, -1);
714 pango_layout_get_size (layout
, &tw
, &th
);
715 chart
->scale_w
= MAX(chart
->scale_w
, (tw
/ PANGO_SCALE
));
716 DB( g_print(" - scale: %g,%g %g,%g\n", chart
->l
, 0.0, chart
->scale_w
, 0.0) );
718 // compute font height
719 chart
->font_h
= (th
/ PANGO_SCALE
);
721 // compute graph region
724 case CHART_TYPE_LINE
:
726 chart
->graph_x
= chart
->l
+ chart
->scale_w
+ 2;
727 chart
->graph_y
= chart
->t
+ chart
->title_zh
+ chart
->subtitle_zh
;
728 chart
->graph_width
= chart
->w
- chart
->scale_w
- 2;
729 chart
->graph_height
= chart
->h
- chart
->title_zh
- chart
->subtitle_zh
;
732 chart
->graph_x
= chart
->l
;
733 chart
->graph_y
= chart
->t
+ chart
->title_zh
+ chart
->subtitle_zh
;
734 chart
->graph_width
= chart
->w
;
735 chart
->graph_height
= chart
->h
- chart
->title_zh
- chart
->subtitle_zh
;
739 if(chart
->title_zh
> 0 || chart
->subtitle_zh
> 0)
741 chart
->graph_y
+= CHART_MARGIN
;
742 chart
->graph_height
-= CHART_MARGIN
;
745 if(chart
->type
!= CHART_TYPE_PIE
&& chart
->show_xval
)
746 chart
->graph_height
-= (chart
->font_h
+ CHART_SPACING
);
748 g_object_unref (layout
);
751 cairo_surface_destroy(surf
);
756 static void colchart_calculation(GtkChart
*chart
)
760 DB( g_print("\n[column] calculation\n") );
763 //if expand : we compute available space
764 //blkw = floor(MAX(8, (chart->graph_width)/chart->nb_items));
767 blkw
= chart
->barw
+ 3;
769 blkw
= (chart
->barw
* 2) + 3;
772 chart
->visible
= chart
->graph_width
/ blkw
;
773 chart
->visible
= MIN(chart
->visible
, chart
->nb_items
);
775 chart
->ox
= chart
->l
;
776 chart
->oy
= chart
->b
;
778 chart
->oy
= floor(chart
->graph_y
+ (chart
->max
/chart
->range
) * chart
->graph_height
);
780 DB( g_print(" + ox=%f oy=%f\n", chart
->ox
, chart
->oy
) );
782 /* todo: hack on every xval */
783 if(chart
->label_w
> 0)
785 blkw
= floor(MIN(chart
->nb_items
*chart
->blkw
, chart
->graph_width
) / chart
->label_w
);
787 blkw
= chart
->visible
/ blkw
;
789 chart
->every_xval
= MAX(1,blkw
);
791 //chart->every_xval = chart->visible - floor(chart->graph_width / chart->label_w);
793 DB( g_print("vis=%d, width=%g, lbl_w=%g :: %d\n", chart
->visible
, chart
->graph_width
, chart
->label_w
, blkw
) );
801 static void colchart_draw_scale(GtkWidget
*widget
, gpointer user_data
)
803 GtkChart
*chart
= GTK_CHART(user_data
);
808 DB( g_print("\n[column] draw scale\n") );
813 //gdkwindow = gtk_widget_get_window(widget);
814 //cr = gdk_cairo_create (gdkwindow);
815 //cr = gdk_cairo_create (widget->window);
816 cr
= cairo_create (chart
->surface
);
818 cairo_set_line_width(cr
, 1);
821 //cairo_rectangle(cr, CHART_MARGIN, 0, chart->w, chart->h + CHART_MARGIN);
824 /* draw vertical lines + legend */
827 x
= chart
->graph_x
+ 1.5 + (chart
->barw
/2);
829 first
= gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
831 cairo_set_dash(cr
, dashed3
, 1, 0);
832 for(i
=first
; i
<(first
+chart
->visible
) ;i
++)
834 if( !(i
% chart
->every_xval
) )
836 //cairo_user_set_rgbcol(cr, &global_colors[GREY1]);
837 cairo_user_set_rgbacol(cr
, &global_colors
[THTEXT
], 0.1);
839 //cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); //blue
841 cairo_move_to(cr
, x
, chart
->graph_y
);
842 cairo_line_to(cr
, x
, chart
->b
- chart
->font_h
);
850 /* horizontal lines */
852 curxval
= chart
->max
;
853 cairo_set_dash(cr
, 0, 0, 0);
854 for(i
=0;i
<=chart
->div
;i
++)
857 //if(i == 0 || i == chart->div) /* top/bottom line */
859 //cairo_set_dash(cr, 0, 0, 0);
860 //cairo_user_set_rgbcol(cr, &global_colors[GREY1]);
861 cairo_user_set_rgbacol(cr
, &global_colors
[THTEXT
], 0.1);
863 //else /* intermediate line (dotted) */
865 //cairo_set_dash(cr, dashed3, 1, 0);
866 //cairo_user_set_rgbcol(cr, &global_colors[GREY1]);
872 //cairo_set_dash(cr, 0, 0, 0);
873 cairo_user_set_rgbacol(cr
, &global_colors
[THTEXT
], 0.8);
876 y
= 0.5 + floor(chart
->graph_y
+ ((i
* chart
->unit
) / chart
->range
) * chart
->graph_height
);
878 DB( g_print(" + i=%d :: y=%f (%f / %f) * %f\n", i
, y
, i
*chart
->unit
, chart
->range
, chart
->graph_height
) );
880 cairo_move_to(cr
, chart
->graph_x
, y
);
881 cairo_line_to(cr
, chart
->graph_x
+ chart
->graph_width
, y
);
884 curxval
-= chart
->unit
;
892 static void colchart_draw_scale_text(GtkWidget
*widget
, gpointer user_data
)
894 GtkChart
*chart
= GTK_CHART(user_data
);
904 DB( g_print("\n([column] draw scale text\n") );
906 //GdkWindow *gdkwindow;
907 //gdkwindow = gtk_widget_get_window(widget);
909 //cr = gdk_cairo_create (gdkwindow);
910 //cr = gdk_cairo_create (widget->window);
911 cr
= cairo_create (chart
->surface
);
913 layout
= pango_cairo_create_layout (cr
);
915 cairo_set_line_width(cr
, 1);
918 //cairo_rectangle(cr, CHART_MARGIN, 0, chart->w, chart->h + CHART_MARGIN);
921 //cairo_set_operator(cr, CAIRO_OPERATOR_SATURATE);
923 chart_set_font_size(chart
, CHART_FONT_SIZE_NORMAL
);
924 pango_layout_set_font_description (layout
, chart
->pfd
);
928 /* draw x-legend (items) */
931 x
= chart
->graph_x
+ 1.5 + (chart
->barw
/2);
932 y
= chart
->b
- chart
->font_h
;
933 first
= (gint
)gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
935 for(i
=first
; i
<(first
+chart
->visible
) ;i
++)
937 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
939 if( !(i
% chart
->every_xval
) )
941 valstr
= item
->label
;
942 pango_layout_set_text (layout
, valstr
, -1);
943 pango_layout_get_size (layout
, &tw
, &th
);
945 DB( g_print("%s w=%d h=%d\n", valstr
, tw
, th
) );
947 cairo_user_set_rgbacol(cr
, &global_colors
[THTEXT
], 0.78);
948 cairo_move_to(cr
, x
- ((tw
/ PANGO_SCALE
)/2), y
);
949 //cairo_move_to(cr, x, y);
950 pango_cairo_show_layout (cr
, layout
);
952 /*cairo_user_set_rgbcol(cr, &global_colors[TEXT]);
953 cairo_move_to(cr, x, y);
954 cairo_line_to(cr, x, y + te.height);
962 /* draw y-legend (amount) */
964 curxval
= chart
->max
;
965 for(i
=0;i
<=chart
->div
;i
++)
967 y
= 0.5 + floor(chart
->graph_y
+ ((i
* chart
->unit
) / chart
->range
) * chart
->graph_height
);
969 DB( g_print(" + i=%d :: y=%f (%f / %f) * %f\n", i
, y
, i
*chart
->unit
, chart
->range
, chart
->graph_height
) );
973 valstr
= chart_print_int(chart
, (gint
)curxval
);
974 pango_layout_set_text (layout
, valstr
, -1);
975 pango_layout_get_size (layout
, &tw
, &th
);
977 //DB( g_print("'%s', %f %f %f %f %f %f\n", valstr, te.x_bearing, te.y_bearing, te.width, te.height, te.x_advance, te.y_advance) );
980 cairo_move_to(cr
, chart
->graph_x
- (tw
/ PANGO_SCALE
) - 2, y
- ((th
/ PANGO_SCALE
)*0.8) );
981 cairo_user_set_rgbacol (cr
, &global_colors
[THTEXT
], 0.78);
982 pango_cairo_show_layout (cr
, layout
);
986 curxval
-= chart
->unit
;
989 g_object_unref (layout
);
995 ** draw all visible bars
997 static void colchart_draw_bars(GtkWidget
*widget
, gpointer user_data
)
999 GtkChart
*chart
= GTK_CHART(user_data
);
1001 double x
, x2
, y2
, h
;
1004 DB( g_print("\n[column] draw bars\n") );
1007 first
= (gint
)gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
1009 cr
= gdk_cairo_create (gtk_widget_get_window(widget
));
1010 //cr = cairo_create (chart->surface);
1014 cairo_set_line_width(cr
, 1.0);
1015 cairo_set_source_rgb(cr
, 1.0, 0.0, 1.0); // violet
1016 for(i
=first
; i
<=(first
+chart
->visible
) ;i
++)
1018 cairo_move_to(cr
, x2
, chart
->graph_y
);
1019 cairo_line_to(cr
, x2
, chart
->graph_x
+ chart
->graph_height
);
1025 for(i
=first
; i
<(first
+chart
->visible
) ;i
++)
1027 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
1029 gint barw
= chart
->barw
;
1031 //if(!chart->datas1[i]) goto nextbar;
1033 if(!chart
->show_mono
)
1034 color
= i
% chart
->color_scheme
.nb_cols
;
1036 color
= chart
->color_scheme
.cs_green
;
1038 cairo_user_set_rgbcol_over(cr
, &chart
->color_scheme
.colors
[color
], i
== chart
->active
);
1043 h
= floor((item
->serie1
/ chart
->range
) * chart
->graph_height
);
1045 if(item
->serie1
< 0.0)
1048 if(chart
->show_mono
)
1050 color
= chart
->color_scheme
.cs_red
;
1051 cairo_user_set_rgbcol_over(cr
, &chart
->color_scheme
.colors
[color
], i
== chart
->active
);
1054 //DB( g_print(" + i=%d :: y2=%f h=%f (%f / %f) * %f\n", i, y2, h, chart->datas1[i], chart->range, chart->graph_height ) );
1056 cairo_rectangle(cr
, x2
+2, y2
, barw
, h
);
1061 if( chart
->dual
&& item
->serie2
)
1065 h
= floor((item
->serie2
/ chart
->range
) * chart
->graph_height
);
1068 cairo_rectangle(cr
, x2
+2, y2
, barw
, h
);
1076 //gdk_draw_line (widget->window, widget->style->fg_gc[widget->state], x, chart->oy-chart->posbarh, x, chart->oy+chart->negbarh);
1085 ** get the bar under the mouse pointer
1087 static gint
colchart_get_active(GtkWidget
*widget
, gint x
, gint y
, gpointer user_data
)
1089 GtkChart
*chart
= GTK_CHART(user_data
);
1091 gint index
, first
, px
;
1095 if( x
<= chart
->r
&& x
>= chart
->graph_x
&& y
>= chart
->graph_y
&& y
<= chart
->b
)
1097 px
= (x
- chart
->graph_x
);
1098 //py = (y - chart->oy);
1099 first
= gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
1100 index
= first
+ (px
/ chart
->blkw
);
1102 if(index
< chart
->nb_items
)
1109 static void colchart_first_changed( GtkAdjustment
*adj
, gpointer user_data
)
1111 GtkChart
*chart
= GTK_CHART(user_data
);
1114 DB( g_print("\n[column] first changed\n") );
1116 //first = gtk_adjustment_get_value(GTK_ADJUSTMENT(adj));
1118 //DB( g_print(" first=%d\n", first) );
1121 DB( g_print("scrollbar\n adj=%8x, low=%.2f upp=%.2f val=%.2f step=%.2f page=%.2f size=%.2f\n", adj,
1122 adj->lower, adj->upper, adj->value, adj->step_increment, adj->page_increment, adj->page_size) );
1124 /* Set the number of decimal places to which adj->value is rounded */
1125 //gtk_scale_set_digits (GTK_SCALE (hscale), (gint) adj->value);
1126 //gtk_scale_set_digits (GTK_SCALE (vscale), (gint) adj->value);
1128 drawarea_full_redraw (chart
->drawarea
, chart
);
1129 gtk_widget_queue_draw(chart
->drawarea
);
1134 ** scrollbar set values for upper, page size, and also show/hide
1136 static void colchart_scrollbar_setvalues(GtkChart
*chart
)
1138 GtkAdjustment
*adj
= chart
->adjustment
;
1141 g_return_if_fail (GTK_IS_ADJUSTMENT (adj
));
1143 DB( g_print("\n[column] sb_set_values\n") );
1145 first
= gtk_adjustment_get_value(GTK_ADJUSTMENT(adj
));
1147 DB( g_print(" entries=%d, visible=%d\n", chart
->nb_items
, chart
->visible
) );
1148 DB( g_print(" first=%d, upper=%d, pagesize=%d\n", first
, chart
->nb_items
, chart
->visible
) );
1150 gtk_adjustment_set_upper(adj
, (gdouble
)chart
->nb_items
);
1151 gtk_adjustment_set_page_size(adj
, (gdouble
)chart
->visible
);
1152 gtk_adjustment_set_page_increment(adj
, (gdouble
)chart
->visible
);
1154 if(first
+chart
->visible
> chart
->nb_items
)
1156 gtk_adjustment_set_value(adj
, (gdouble
)chart
->nb_items
- chart
->visible
);
1158 gtk_adjustment_changed (adj
);
1160 if( chart
->visible
< chart
->nb_items
)
1161 gtk_widget_hide(GTK_WIDGET(chart
->scrollbar
));
1163 gtk_widget_show(GTK_WIDGET(chart
->scrollbar
));
1170 ** draw all visible lines
1172 static void linechart_draw_plot(cairo_t
*cr
, double x
, double y
, double r
, GtkChart
*chart
)
1174 cairo_set_line_width(cr
, r
/ 2);
1176 cairo_user_set_rgbcol(cr
, &global_colors
[THBASE
]);
1177 cairo_arc(cr
, x
, y
, r
, 0, 2*M_PI
);
1178 cairo_stroke_preserve(cr
);
1180 //cairo_set_source_rgb(cr, COLTOCAIRO(0), COLTOCAIRO(119), COLTOCAIRO(204));
1181 cairo_user_set_rgbcol(cr
, &chart
->color_scheme
.colors
[chart
->color_scheme
.cs_blue
]);
1186 static void linechart_draw_lines(GtkWidget
*widget
, gpointer user_data
)
1188 GtkChart
*chart
= GTK_CHART(user_data
);
1190 double x
, y
, x2
, y2
, firstx
, lastx
, linew
;
1194 DB( g_print("\n[line] draw lines\n") );
1198 first
= (gint
)gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
1200 cr
= gdk_cairo_create (gtk_widget_get_window(widget
));
1201 //cr = cairo_create (chart->surface);
1204 //cairo_rectangle(cr, CHART_MARGIN, 0, chart->w, chart->h + CHART_MARGIN);
1210 cairo_set_line_width(cr
, 1.0);
1211 cairo_set_source_rgb(cr
, 1.0, 0.0, 1.0); // violet
1212 for(i
=first
; i
<=(first
+chart
->visible
) ;i
++)
1214 cairo_move_to(cr
, x2
, chart
->graph_y
);
1215 cairo_line_to(cr
, x2
, chart
->graph_x
+ chart
->graph_height
);
1222 //todo: it should be possible to draw line & plot together using surface and composite fill, or sub path ??
1226 if(chart
->barw
< 24)
1228 linew
= 1 + (chart
->barw
/ 8.0);
1231 cairo_set_line_join(cr
, CAIRO_LINE_JOIN_BEVEL
);
1232 cairo_set_line_width(cr
, linew
);
1234 for(i
=first
; i
<(first
+chart
->visible
) ;i
++)
1236 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
1238 x2
= x
+ (chart
->blkw
)/2;
1239 y2
= chart
->oy
- (item
->serie1
/ chart
->range
) * chart
->graph_height
;
1243 cairo_move_to(cr
, x2
, y2
);
1247 if( i
< (chart
->nb_items
) )
1249 cairo_line_to(cr
, x2
, y2
);
1253 lastx
= x2
- chart
->barw
;
1259 cairo_user_set_rgbcol(cr
, &chart
->color_scheme
.colors
[chart
->color_scheme
.cs_blue
]);
1260 cairo_stroke_preserve(cr
);
1262 cairo_line_to(cr
, lastx
, y
);
1263 cairo_line_to(cr
, firstx
, y
);
1264 cairo_close_path(cr
);
1266 cairo_user_set_rgbacol(cr
, &chart
->color_scheme
.colors
[chart
->color_scheme
.cs_blue
], AREA_ALPHA
);
1271 first
= (gint
)gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
1274 for(i
=first
; i
<(first
+chart
->visible
) ;i
++)
1276 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
1278 x2
= x
+ (chart
->blkw
)/2;
1279 y2
= chart
->oy
- (item
->serie1
/ chart
->range
) * chart
->graph_height
;
1280 linechart_draw_plot(cr
, x2
, y2
, i
== chart
->active
? linew
+1 : linew
, chart
);
1286 DB( g_print(" min=%.2f range=%.2f\n", chart
->min
, chart
->range
) );
1289 if( chart
->show_over
)
1291 if(chart
->minimum
!= 0 && chart
->minimum
>= chart
->min
)
1293 y
= 0.5 + chart
->oy
+ (ABS(chart
->minimum
)/chart
->range
) * chart
->graph_height
;
1294 y2
= (ABS(chart
->min
)/chart
->range
) * chart
->graph_height
- (y
- chart
->oy
) + 1;
1295 cairo_set_source_rgba(cr
, COLTOCAIRO(255), COLTOCAIRO(0), COLTOCAIRO(0), AREA_ALPHA
/ 2);
1297 DB( g_print(" draw over: x%f, y%f, w%f, h%f\n", chart
->l
, y
, chart
->w
, y2
) );
1299 cairo_rectangle(cr
, chart
->graph_x
, y
, chart
->graph_width
, y2
);
1302 cairo_set_line_width(cr
, 1.0);
1303 cairo_set_source_rgb(cr
, COLTOCAIRO(255), COLTOCAIRO(0), COLTOCAIRO(0));
1305 cairo_set_dash (cr
, dashed3
, 1, 0);
1306 cairo_move_to(cr
, chart
->graph_x
, y
);
1307 cairo_line_to (cr
, chart
->graph_x
+ chart
->graph_width
, y
);
1321 ** get the point under the mouse pointer
1323 static gint
linechart_get_active(GtkWidget
*widget
, gint x
, gint y
, gpointer user_data
)
1325 GtkChart
*chart
= GTK_CHART(user_data
);
1327 gint first
, index
, px
;
1329 DB( g_print("\n[line] get active\n") );
1333 if( x
<= chart
->r
&& x
>= chart
->graph_x
&& y
>= chart
->graph_y
&& y
<= chart
->b
)
1335 px
= (x
- chart
->graph_x
);
1336 //py = (y - chart->oy);
1337 first
= gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
1338 index
= first
+ (px
/ (chart
->blkw
));
1340 if(index
< chart
->nb_items
)
1351 static void piechart_calculation(GtkChart
*chart
)
1353 GtkWidget
*drawarea
= chart
->drawarea
;
1354 GtkAllocation allocation
;
1357 DB( g_print("\n[pie] calculation\n") );
1360 w
= chart
->graph_width
;
1361 h
= chart
->graph_height
;
1363 chart
->rayon
= MIN(w
, h
);
1365 gtk_widget_get_allocation(drawarea
, &allocation
);
1367 chart
->ox
= chart
->graph_x
+ (chart
->graph_width
/ 2);
1368 chart
->oy
= chart
->graph_y
+ (chart
->rayon
/ 2);
1373 static void piechart_draw_slices(GtkWidget
*widget
, gpointer user_data
)
1375 GtkChart
*chart
= GTK_CHART(user_data
);
1378 if(chart
->nb_items
<= 0)
1381 DB( g_print("\n[pie] draw slices\n") );
1386 double a1
= 0 * (M_PI
/ 180);
1387 double a2
= 360 * (M_PI
/ 180);
1389 //g_print("angle1=%.2f angle2=%.2f\n", a1, a2);
1391 double cx
= chart
->ox
;
1392 double cy
= chart
->oy
;
1393 double radius
= chart
->rayon
/2;
1399 cr
= gdk_cairo_create (gtk_widget_get_window(widget
));
1400 //cr = cairo_create (chart->surface);
1402 for(i
=0; i
< chart
->nb_items
;i
++)
1404 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, i
);
1406 a1
= ((360 * (sum
/ chart
->total
)) - 90) * (M_PI
/ 180);
1407 sum
+= ABS(item
->serie1
);
1408 a2
= ((360 * (sum
/ chart
->total
)) - 90) * (M_PI
/ 180);
1409 if(i
< chart
->nb_items
-1) a2
+= 0.0175;
1414 cairo_move_to(cr
, dx
, dy
);
1415 cairo_arc(cr
, dx
, dy
, radius
, a1
, a2
);
1417 #if PIE_LINE_SLICE == 1
1418 cairo_set_line_width(cr
, 1.0);
1419 cairo_set_source_rgb(cr
, 1.0, 1.0, 1.0);
1420 cairo_line_to(cr
, cx
, cy
);
1421 cairo_stroke_preserve(cr
);
1424 DB( g_print("%d: %.2f%% %.2f %.2f\n", i
, sum
/ chart
->total
, a1
, a2
) );
1426 //g_print("color : %f %f %f\n", COLTOCAIRO(colors[i].r), COLTOCAIRO(colors[i].g), COLTOCAIRO(colors[i].b));
1428 color
= i
% chart
->color_scheme
.nb_cols
;
1429 cairo_user_set_rgbcol_over(cr
, &chart
->color_scheme
.colors
[color
], i
== chart
->active
);
1434 cairo_pattern_t
*pat1
;
1439 pat1
= cairo_pattern_create_radial( cx
, cy
, 0, cx
, cy
, radius
);
1440 cairo_pattern_add_color_stop_rgba(pat1
, 0.0, 1.0, 1.0, 1.0, .50);
1441 cairo_pattern_add_color_stop_rgba(pat1
, 0.9, 1.0, 1.0, 1.0, 0.1);
1443 cairo_arc(cr
, cx
, cy
, radius
, a1
, a2
);
1444 cairo_set_source(cr
, pat1
);
1449 cairo_pattern_t
*pat1
;
1453 double gradius
= radius
- 8;
1455 // start point, end point
1456 pat1
= cairo_pattern_create_linear(cx
, cy
-gradius
, cx
, cy
+gradius
);
1458 cairo_pattern_add_color_stop_rgba(pat1
, 0.0, 1.0, 1.0, 1.0, .15);
1459 cairo_pattern_add_color_stop_rgba(pat1
, 1.0, 1.0, 1.0, 1.0, 0.0);
1462 //cairo_rectangle(cr, cx-radius, cy-radius, radius*2, radius*2);
1464 cairo_arc(cr
, cx
, cy
, gradius
, a1
, a2
);
1465 cairo_set_source(cr
, pat1
);
1470 #if CHART_PIE_DONUT == 1
1475 //radius = (gint)((chart->rayon/3) * (1 / PHI));
1477 //radius = (gint)((chart->rayon/2) * 2 / 3);
1479 radius
= (gint
)(chart
->rayon
/2) * 0.5;
1481 cairo_arc(cr
, cx
, cy
, radius
, a1
, a2
);
1482 cairo_user_set_rgbcol(cr
, &global_colors
[THBASE
]);
1491 static gint
piechart_get_active(GtkWidget
*widget
, gint x
, gint y
, gpointer user_data
)
1493 GtkChart
*chart
= GTK_CHART(user_data
);
1494 gint retval
, px
, py
;
1498 DB( g_print("\n[pie] get active\n") );
1502 h
= sqrt( pow(px
,2) + pow(py
,2) );
1505 if(h
< (chart
->rayon
/2))
1509 b
= (acos(px
/ h
) * 180) / M_PI
;
1510 angle
= py
> 0 ? b
: 360 - b
;
1512 if(angle
> 360) angle
-= 360;
1513 //angle = 360 - angle;
1517 for(index
=0; index
< chart
->nb_items
;index
++)
1519 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, index
);
1521 cumul
+= ABS(item
->serie1
/chart
->total
)*360;
1529 //DB( g_print(" inside: x=%d, y=%d\n", x, y) );
1530 //DB( g_print(" inside: b=%f angle=%f, slice is %d\n", b, angle, index) );
1536 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1537 static gboolean
drawarea_full_redraw(GtkWidget
*widget
, gpointer user_data
)
1539 GtkChart
*chart
= GTK_CHART(user_data
);
1541 PangoLayout
*layout
;
1544 DB( g_print("\n[gtkchart] drawarea full redraw\n") );
1546 cr
= cairo_create (chart
->surface
);
1548 /* fillin the back in white */
1549 //cairo_user_set_rgbcol(cr, &global_colors[WHITE]);
1550 cairo_user_set_rgbcol(cr
, &global_colors
[THBASE
]);
1554 if(chart
->nb_items
== 0)
1560 /*debug help draws */
1562 cairo_set_line_width(cr
, 1.0);
1563 cairo_set_source_rgb(cr
, 0.0, 1.0, 0.0); //green
1564 cairo_rectangle(cr
, chart
->l
+0.5, chart
->t
+0.5, chart
->w
, chart
->h
);
1567 cairo_set_source_rgb(cr
, 1.0, 0.5, 0.0); //orange
1568 cairo_rectangle(cr
, chart
->graph_x
+0.5, chart
->graph_y
+0.5, chart
->graph_width
, chart
->graph_height
);
1576 layout
= pango_cairo_create_layout (cr
);
1578 chart_set_font_size(chart
, CHART_FONT_SIZE_TITLE
);
1579 pango_layout_set_font_description (layout
, chart
->pfd
);
1580 pango_layout_set_text (layout
, chart
->title
, -1);
1581 pango_layout_get_size (layout
, &tw
, &th
);
1583 cairo_user_set_rgbcol(cr
, &global_colors
[THTEXT
]);
1584 cairo_move_to(cr
, chart
->l
, chart
->t
);
1585 pango_cairo_show_layout (cr
, layout
);
1589 cairo_set_source_rgb(cr
, 0.0, 0.0, 1.0); //blue
1591 cairo_set_dash (cr
, &dashlength
, 1, 0);
1592 cairo_move_to(cr
, chart
->l
, chart
->t
);
1593 cairo_rectangle(cr
, chart
->l
, chart
->t
, (tw
/ PANGO_SCALE
), (th
/ PANGO_SCALE
));
1597 g_object_unref (layout
);
1602 case CHART_TYPE_COL
:
1603 colchart_draw_scale(widget
, chart
);
1604 //colchart_draw_bars(widget, chart);
1605 colchart_draw_scale_text(widget
, chart
);
1607 case CHART_TYPE_LINE
:
1608 colchart_draw_scale(widget
, chart
);
1609 //linechart_draw_lines(widget, chart);
1610 colchart_draw_scale_text(widget
, chart
);
1612 case CHART_TYPE_PIE
:
1613 //piechart_draw_slices(widget, chart);
1625 drawarea_configure_event (GtkWidget
*widget
,
1626 GdkEventConfigure
*event
,
1629 GtkChart
*chart
= GTK_CHART(user_data
);
1630 GtkAllocation allocation
;
1631 GtkStyleContext
*context
;
1632 PangoFontDescription
*desc
;
1636 DB( g_print("\n[gtkchart] drawarea configure \n") );
1638 gtk_widget_get_allocation (widget
, &allocation
);
1640 DB( g_print("w=%d h=%d\n", allocation
.width
, allocation
.height
) );
1645 cairo_surface_destroy (chart
->surface
);
1647 chart
->surface
= gdk_window_create_similar_surface (gtk_widget_get_window (widget
),
1648 CAIRO_CONTENT_COLOR
,
1652 context
= gtk_widget_get_style_context (widget
);
1654 chart_color_global_default();
1657 colfound
= gtk_style_context_lookup_color(context
, "theme_base_color", &color
);
1659 colfound
= gtk_style_context_lookup_color(context
, "base_color", &color
);
1663 struct rgbcol
*tcol
= &global_colors
[THBASE
];
1664 tcol
->r
= color
.red
* 255;
1665 tcol
->g
= color
.green
* 255;
1666 tcol
->b
= color
.blue
* 255;
1667 DB( g_print(" - theme base col: %x %x %x\n", tcol
->r
, tcol
->g
, tcol
->b
) );
1671 colfound
= gtk_style_context_lookup_color(context
, "theme_fg_color", &color
);
1673 gtk_style_context_lookup_color(context
, "fg_color", &color
);
1677 struct rgbcol
*tcol
= &global_colors
[THTEXT
];
1678 tcol
->r
= color
.red
* 255;
1679 tcol
->g
= color
.green
* 255;
1680 tcol
->b
= color
.blue
* 255;
1681 DB( g_print(" - theme text (bg) col: %x %x %x\n", tcol
->r
, tcol
->g
, tcol
->b
) );
1685 /* get and copy the font */
1686 gtk_style_context_get(context
, GTK_STATE_FLAG_NORMAL
, "font", &desc
, NULL
);
1689 pango_font_description_free (chart
->pfd
);
1692 chart
->pfd
= pango_font_description_copy(desc
);
1693 chart
->pfd_size
= pango_font_description_get_size (desc
) / PANGO_SCALE
;
1694 //chart->barw = (6 + chart->pfd_size) * PHI;
1696 DB( g_print("family: %s\n", pango_font_description_get_family(chart
->pfd
) ) );
1697 DB( g_print("size : %d (%d)\n", chart
->pfd_size
, chart
->pfd_size
/PANGO_SCALE
) );
1698 DB( g_print("isabs : %d\n", pango_font_description_get_size_is_absolute (chart
->pfd
) ) );
1701 if( gtk_widget_get_realized(widget
))
1703 chart_recompute(chart
);
1704 drawarea_full_redraw(widget
, chart
);
1707 /* We've handled the configure event, no need for further processing. */
1712 static void drawarea_realize_callback(GtkWidget
*widget
, gpointer user_data
)
1714 //GtkChart *chart = GTK_CHART(user_data);
1716 DB( g_print("\n[gtkchart] drawarea realize\n") );
1718 //chart_recompute(chart);
1723 static gboolean
drawarea_draw_callback(GtkWidget
*widget
, cairo_t
*cr
, gpointer user_data
)
1725 GtkChart
*chart
= GTK_CHART(user_data
);
1727 if( !gtk_widget_get_realized(widget
) || chart
->surface
== NULL
)
1730 DB( g_print("\n[gtkchart] drawarea draw callback\n") );
1732 cairo_set_source_surface (cr
, chart
->surface
, 0, 0);
1737 case CHART_TYPE_COL
:
1738 colchart_draw_bars(widget
, chart
);
1740 case CHART_TYPE_LINE
:
1741 linechart_draw_lines(widget
, chart
);
1743 case CHART_TYPE_PIE
:
1744 piechart_draw_slices(widget
, chart
);
1752 static gboolean
drawarea_querytooltip_callback(GtkWidget
*widget
, gint x
, gint y
, gboolean keyboard_mode
, GtkTooltip
*tooltip
, gpointer user_data
)
1754 GtkChart
*chart
= GTK_CHART(user_data
);
1755 gchar
*strval
, *strval2
, *buffer
;
1756 gboolean retval
= FALSE
;
1758 if(chart
->surface
== NULL
)
1761 DB( g_print("\n[gtkchart] drawarea querytooltip\n") );
1763 DB( g_print(" x=%d, y=%d kbm=%d\n", x
, y
, keyboard_mode
) );
1764 if(chart
->lastactive
!= chart
->active
)
1769 if(chart
->active
>= 0)
1771 ChartItem
*item
= &g_array_index(chart
->items
, ChartItem
, chart
->active
);
1773 strval
= chart_print_double(chart
, chart
->buffer1
, item
->serie1
);
1776 //#1420495 don't use g_markup_printf_escaped
1777 if( chart
->type
== CHART_TYPE_PIE
)
1778 buffer
= g_strdup_printf("%s\n%s\n%.2f%%", item
->label
, strval
, item
->rate
);
1780 buffer
= g_strdup_printf("%s\n%s", item
->label
, strval
);
1785 strval2
= chart_print_double(chart
, chart
->buffer2
, item
->serie2
);
1786 buffer
= g_strdup_printf("%s\n+%s\n%s", item
->label
, strval2
, strval
);
1789 gtk_tooltip_set_text(tooltip
, buffer
);
1790 //gtk_label_set_markup(GTK_LABEL(chart->ttlabel), buffer);
1795 chart
->lastactive
= chart
->active
;
1801 static gboolean
drawarea_motionnotifyevent_callback(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1803 GtkChart
*chart
= GTK_CHART(user_data
);
1804 gboolean retval
= TRUE
;
1807 if(chart
->surface
== NULL
|| chart
->nb_items
== 0)
1810 DB( g_print("\n[gtkchart] drawarea motion\n") );
1817 DB( g_print(" is hint\n") );
1819 gdk_window_get_device_position(event
->window
, event
->device
, &x
, &y
, NULL
);
1820 //gdk_window_get_pointer(event->window, &x, &y, NULL);
1826 case CHART_TYPE_COL
:
1827 chart
->active
= colchart_get_active(widget
, x
, y
, chart
);
1829 case CHART_TYPE_LINE
:
1830 chart
->active
= linechart_get_active(widget
, x
, y
, chart
);
1832 case CHART_TYPE_PIE
:
1833 chart
->active
= piechart_get_active(widget
, x
, y
, chart
);
1837 // rollover redraw ?
1838 DB( g_print(" active: last=%d, curr=%d\n", chart
->lastactive
, chart
->active
) );
1840 if(chart
->lastactive
!= chart
->active
)
1842 GdkRectangle update_rect
;
1845 DB( g_print(" motion rollover redraw :: active=%d\n", chart
->active
) );
1847 first
= (gint
)gtk_adjustment_get_value(GTK_ADJUSTMENT(chart
->adjustment
));
1849 /* pie : always invalidate all graph area */
1850 if( chart
->type
== CHART_TYPE_PIE
)
1852 update_rect
.x
= chart
->graph_x
;
1853 update_rect
.y
= chart
->graph_y
;
1854 update_rect
.width
= chart
->graph_width
;
1855 update_rect
.height
= chart
->graph_height
;
1857 /* Now invalidate the affected region of the drawing area. */
1858 gdk_window_invalidate_rect (gtk_widget_get_window (widget
),
1863 if(chart
->lastactive
!= -1)
1865 /* column/line : invalidate rollover */
1866 if( chart
->type
!= CHART_TYPE_PIE
)
1868 update_rect
.x
= chart
->graph_x
+ (chart
->lastactive
- first
) * chart
->blkw
;
1869 update_rect
.y
= chart
->graph_y
- 6;
1870 update_rect
.width
= chart
->blkw
;
1871 update_rect
.height
= chart
->graph_height
+ 12;
1874 /* Now invalidate the affected region of the drawing area. */
1875 gdk_window_invalidate_rect (gtk_widget_get_window (widget
),
1880 /* column/line : invalidate current item */
1881 if(chart
->type
!= CHART_TYPE_PIE
)
1883 update_rect
.x
= chart
->graph_x
+ (chart
->active
- first
) * chart
->blkw
;
1884 update_rect
.y
= chart
->graph_y
- 6;
1885 update_rect
.width
= chart
->blkw
;
1886 update_rect
.height
= chart
->graph_height
+ 12;
1888 /* Now invalidate the affected region of the drawing area. */
1889 gdk_window_invalidate_rect (gtk_widget_get_window (widget
),
1894 //gtk_widget_queue_draw( widget );
1898 DB( g_print(" x=%d, y=%d, time=%d\n", x
, y
, event
->time
) );
1899 DB( g_print(" trigger tooltip query\n") );
1901 gtk_tooltip_trigger_tooltip_query(gtk_widget_get_display(chart
->drawarea
));
1907 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1908 /* public functions */
1909 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1911 void gtk_chart_queue_redraw(GtkChart
*chart
)
1913 DB( g_print("\n[gtkchart] queue redraw\n") );
1915 if( gtk_widget_get_realized(chart
->drawarea
) )
1917 chart_recompute(chart
);
1918 drawarea_full_redraw(chart
->drawarea
, chart
);
1919 gtk_widget_queue_draw( chart
->drawarea
);
1925 ** change the model and/or column
1927 void gtk_chart_set_datas(GtkChart
*chart
, GtkTreeModel
*model
, guint column
, gchar
*title
, gchar
*subtitle
)
1929 g_return_if_fail (GTK_IS_CHART (chart
));
1931 if( GTK_IS_TREE_MODEL(model
) )
1933 chart_setup_with_model(chart
, model
, column
, column
);
1935 chart
->title
= g_strdup(title
);
1936 if(subtitle
!= NULL
)
1937 chart
->subtitle
= g_strdup(subtitle
);
1939 gtk_chart_queue_redraw(chart
);
1944 if( GTK_IS_LIST_STORE(chart
->legend
) )
1945 gtk_list_store_clear (GTK_LIST_STORE(chart
->legend
));
1951 ** change the model and/or column
1953 void gtk_chart_set_dualdatas(GtkChart
*chart
, GtkTreeModel
*model
, guint column1
, guint column2
, gchar
*title
, gchar
*subtitle
)
1955 g_return_if_fail (GTK_IS_CHART (chart
));
1957 if( GTK_IS_TREE_MODEL(model
) )
1959 chart_setup_with_model(chart
, model
, column1
, column2
);
1961 chart
->title
= g_strdup(title
);
1962 if(subtitle
!= NULL
)
1963 chart
->subtitle
= g_strdup(subtitle
);
1965 gtk_chart_queue_redraw(chart
);
1970 if( GTK_IS_LIST_STORE(chart
->legend
) )
1971 gtk_list_store_clear (GTK_LIST_STORE(chart
->legend
));
1977 ** change the type dynamically
1979 void gtk_chart_set_type(GtkChart
* chart
, gint type
)
1981 g_return_if_fail (GTK_IS_CHART (chart
));
1982 //g_return_if_fail (type < CHART_TYPE_MAX);
1984 DB( g_print("\n[gtkchart] set type %d\n", type
) );
1987 chart
->dual
= FALSE
;
1989 gtk_chart_queue_redraw(chart
);
1992 /* = = = = = = = = = = parameters = = = = = = = = = = */
1994 void gtk_chart_set_color_scheme(GtkChart
* chart
, gint index
)
1996 colorscheme_init(&chart
->color_scheme
, index
);
2002 ** set the minor parameters
2004 void gtk_chart_set_minor_prefs(GtkChart
* chart
, gdouble rate
, gchar
*symbol
)
2006 g_return_if_fail (GTK_IS_CHART (chart
));
2008 chart
->minor_rate
= rate
;
2009 chart
->minor_symbol
= symbol
;
2013 void gtk_chart_set_absolute(GtkChart
* chart
, gboolean abs
)
2015 g_return_if_fail (GTK_IS_CHART (chart
));
2021 void gtk_chart_set_currency(GtkChart
* chart
, guint32 kcur
)
2023 g_return_if_fail (GTK_IS_CHART (chart
));
2030 ** set the overdrawn minimum
2032 void gtk_chart_set_overdrawn(GtkChart
* chart
, gdouble minimum
)
2034 g_return_if_fail (GTK_IS_CHART (chart
));
2036 chart
->minimum
= minimum
;
2038 //if(chart->type == CHART_TYPE_LINE)
2039 // chart_recompute(chart);
2043 ** set the every_xval
2045 void gtk_chart_set_every_xval(GtkChart
* chart
, gint gap
)
2047 g_return_if_fail (GTK_IS_CHART (chart
));
2049 chart
->every_xval
= gap
;
2051 //if(chart->type != CHART_TYPE_PIE)
2052 // chart_recompute(chart);
2059 void gtk_chart_set_barw(GtkChart
* chart
, gdouble barw
)
2061 g_return_if_fail (GTK_IS_CHART (chart
));
2065 if(chart
->type
!= CHART_TYPE_PIE
)
2066 gtk_chart_queue_redraw(chart
);
2070 ** set the show mono (colors)
2072 void gtk_chart_set_showmono(GtkChart
* chart
, gboolean mono
)
2074 g_return_if_fail (GTK_IS_CHART (chart
));
2076 chart
->show_mono
= mono
;
2078 if(chart
->type
!= CHART_TYPE_PIE
)
2079 gtk_chart_queue_redraw(chart
);
2083 /* = = = = = = = = = = visibility = = = = = = = = = = */
2086 ** change the legend visibility
2088 void gtk_chart_show_legend(GtkChart
* chart
, gboolean visible
, gboolean showextracol
)
2090 GtkTreeViewColumn
*column
;
2092 g_return_if_fail (GTK_IS_CHART (chart
));
2095 gtk_widget_show(chart
->scrollwin
);
2097 gtk_widget_hide(chart
->scrollwin
);
2099 /* manage column visibility */
2100 column
= gtk_tree_view_get_column (GTK_TREE_VIEW(chart
->treeview
), 1); //amount
2101 gtk_tree_view_column_set_visible (column
, showextracol
);
2103 column
= gtk_tree_view_get_column (GTK_TREE_VIEW(chart
->treeview
), 2); //percent
2104 gtk_tree_view_column_set_visible (column
, showextracol
);
2109 ** change the x-value visibility
2111 void gtk_chart_show_xval(GtkChart
* chart
, gboolean visible
)
2113 g_return_if_fail (GTK_IS_CHART (chart
));
2115 chart
->show_xval
= visible
;
2117 //if(chart->type != CHART_TYPE_PIE)
2118 // chart_recompute(chart);
2122 ** chnage the overdrawn visibility
2124 void gtk_chart_show_overdrawn(GtkChart
* chart
, gboolean visible
)
2126 g_return_if_fail (GTK_IS_CHART (chart
));
2128 chart
->show_over
= visible
;
2130 //if(chart->type == CHART_TYPE_LINE)
2131 // chart_recompute(chart);
2136 ** change the minor visibility
2138 void gtk_chart_show_minor(GtkChart
* chart
, gboolean minor
)
2140 g_return_if_fail (GTK_IS_CHART (chart
));
2142 chart
->minor
= minor
;
2144 if(chart
->type
!= CHART_TYPE_PIE
)
2145 gtk_chart_queue_redraw(chart
);
2147 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(chart
->treeview
));
2148 gtk_widget_queue_draw (chart
->treeview
);
2152 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
2156 #define LEG_SQUARE_SIZE 12
2158 static GdkPixbuf
*create_color_pixbuf (struct rgbcol
*color
)
2163 pixbuf
= gdk_pixbuf_new (GDK_COLORSPACE_RGB
, TRUE
, 8, LEG_SQUARE_SIZE
, LEG_SQUARE_SIZE
);
2166 pixel
|= (color
->r
<< 24);
2167 pixel
|= (color
->g
<< 16);
2168 pixel
|= (color
->b
<< 8);
2170 /*g_print("%08x\n", (0xFF & col->red) << 24 );
2171 g_print("%08x\n", (0xFF & col->green) << 16 );
2172 g_print("%08x\n", (0xFF & col->blue) << 8 );
2173 g_print("%x %x %x => %08x\n", col->red, col->green, col->blue, pixel);*/
2175 gdk_pixbuf_fill(pixbuf
, pixel
);
2181 static void legend_list_cell_data_function(GtkTreeViewColumn
*col
,
2182 GtkCellRenderer
*renderer
,
2183 GtkTreeModel
*model
,
2190 gtk_tree_model_get(model
, iter
,
2191 LST_LEGEND_COLOR
, &pixbuf
,
2192 LST_LEGEND_TITLE
, &title
,
2195 switch(GPOINTER_TO_INT(user_data
))
2197 case LST_LEGEND_COLOR
:
2198 g_object_set(renderer
, "pixbuf", pixbuf
, NULL
);
2200 case LST_LEGEND_TITLE
:
2201 g_object_set(renderer
, "text", title
, NULL
);
2208 legend_list_float_cell_data_function (GtkTreeViewColumn
*col
, GtkCellRenderer
*renderer
, GtkTreeModel
*model
, GtkTreeIter
*iter
, gpointer user_data
)
2210 GtkChart
*chart
= user_data
;
2211 gchar buf
[G_ASCII_DTOSTR_BUF_SIZE
];
2214 gtk_tree_model_get(model
, iter
,
2215 LST_LEGEND_AMOUNT
, &amount
,
2218 hb_strfmon(buf
, G_ASCII_DTOSTR_BUF_SIZE
-1, amount
, chart
->kcur
, chart
->minor
);
2220 g_object_set(renderer
,
2226 static void legend_list_rate_cell_data_function (GtkTreeViewColumn
*col
,
2227 GtkCellRenderer
*renderer
,
2228 GtkTreeModel
*model
,
2235 gtk_tree_model_get(model
, iter
,
2236 LST_LEGEND_RATE
, &rate
,
2239 g_snprintf(buf
, sizeof(buf
), "%.02f %%", rate
);
2240 g_object_set(renderer
, "text", buf
, NULL
);
2245 static GtkWidget
*legend_list_new(GtkChart
*chart
)
2247 GtkListStore
*store
;
2249 GtkCellRenderer
*renderer
;
2250 GtkTreeViewColumn
*column
;
2252 store
= gtk_list_store_new(NUM_LST_LEGEND
,
2261 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
));
2262 g_object_unref(store
);
2266 PangoFontDescription *font_desc;
2268 g_print("legend_list_new font\n");
2270 style = gtk_widget_get_style(GTK_WIDGET(view));
2271 font_desc = style->font_desc;
2273 g_print("family: %s\n", pango_font_description_get_family(font_desc) );
2274 g_print("size: %d (%d)\n", pango_font_description_get_size (font_desc), pango_font_description_get_size (font_desc )/PANGO_SCALE );
2278 // change the font size to a smaller one
2279 /*PangoFontDescription *font = pango_font_description_new();
2280 pango_font_description_set_size (font, 8 * PANGO_SCALE);
2281 gtk_widget_modify_font(GTK_WIDGET(view), font);
2282 pango_font_description_free( font );*/
2283 GtkStyleContext
*context
;
2284 PangoFontDescription
*desc
, *nfd
;
2287 context
= gtk_widget_get_style_context (chart
->drawarea
);
2288 gtk_style_context_get(context
, GTK_STATE_FLAG_NORMAL
, "font", &desc
, NULL
);
2289 nfd
= pango_font_description_copy(desc
);
2290 nfsize
= pango_font_description_get_size (desc
) / PANGO_SCALE
;
2291 pango_font_description_set_size(nfd
, MAX(8, nfsize
-2) * PANGO_SCALE
);
2292 gtk_widget_override_font(GTK_WIDGET(view
), nfd
);
2293 pango_font_description_free (nfd
);
2297 column
= gtk_tree_view_column_new();
2298 renderer
= gtk_cell_renderer_pixbuf_new ();
2299 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
2300 gtk_tree_view_column_set_cell_data_func(column
, renderer
, legend_list_cell_data_function
, GINT_TO_POINTER(LST_LEGEND_COLOR
), NULL
);
2302 renderer
= gtk_cell_renderer_text_new ();
2303 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
2304 gtk_tree_view_column_set_cell_data_func(column
, renderer
, legend_list_cell_data_function
, GINT_TO_POINTER(LST_LEGEND_TITLE
), NULL
);
2305 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2307 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
2310 column
= gtk_tree_view_column_new();
2311 //gtk_tree_view_column_set_title(column, name);
2313 renderer
= gtk_cell_renderer_text_new ();
2314 g_object_set(renderer
, "xalign", 1.0, NULL
);
2315 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
2316 gtk_tree_view_column_set_cell_data_func(column
, renderer
, legend_list_float_cell_data_function
, chart
, NULL
);
2317 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2318 //gtk_tree_view_column_set_resizable(column, TRUE);
2319 //gtk_tree_view_column_set_alignment (column, 0.5);
2320 //gtk_tree_view_column_set_spacing( column, 16 );
2322 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
2323 gtk_tree_view_column_set_visible (column
, FALSE
);
2326 column
= gtk_tree_view_column_new();
2327 //gtk_tree_view_column_set_title(column, "%");
2328 renderer
= gtk_cell_renderer_text_new ();
2329 g_object_set(renderer
, "xalign", 1.0, NULL
);
2330 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
2331 //gtk_tree_view_column_add_attribute(column, renderer, "text", id);
2332 gtk_tree_view_column_set_cell_data_func(column
, renderer
, legend_list_rate_cell_data_function
, GINT_TO_POINTER(3), NULL
);
2333 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2334 //gtk_tree_view_column_set_alignment (column, 0.5);
2335 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
2336 gtk_tree_view_column_set_visible (column
, FALSE
);
2339 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view
)), GTK_SELECTION_NONE
);
2340 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view
), FALSE
);
2341 //gtk_tree_view_set_reorderable (GTK_TREE_VIEW(view), TRUE);
2344 GValue value = { 0, };
2345 g_value_init (&value, G_TYPE_INT);
2346 g_value_set_int (&value, 20);
2347 g_object_set_property(view, "vertical-separator", &value);
2348 g_value_unset (&value);