1 /* gtkplot - 2d scientific plots widget for gtk+
2 * Copyright 1999-2001 Adrian E. Feiguin <feiguin@ifir.edu.ar>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 /**
21 * SECTION: gtkplot
22 * @short_description: 2d scientific plots widget
23 *
24 * GtkPlot allows to draw high quality scientific plots in two dimensions with a look and feel very similar to Microcal Origin for Windows.
25 * The distribution includes GtkPlotCanvas subclass, and a demo program showing two layered plots with different kind of curves.
26 * You can choose between a number of symbol types, lines, connectors -straight lines, steps, splines-, and change their attributes -color, size, width.
27 * You can also plot functions, add error bars, edit legends, rotate and move axis titles, change axis properties, etc.
28 */
29
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <math.h>
35 #include <gtk/gtk.h>
36 #include "gtkplot.h"
37 #include "gtkplotdata.h"
38 #include "gtkpsfont.h"
39 #include "gtkplotcairo.h"
40 #include "gtkextra-marshal.h"
41
42 #define DEFAULT_WIDTH 420
43 #define DEFAULT_HEIGHT 340
44 #define DEFAULT_FONT_HEIGHT 12
45 #define LABEL_MAX_LENGTH 100
46
47 #define P_(string) string
48
49 static gchar DEFAULT_FONT[] = "Helvetica";
50
51 /* Signals */
52
53 extern void
54 _gtkextra_signal_emit(GObject *object, guint signal_id, ...);
55
56 enum
57 {
58 ADD_DATA,
59 CHANGED,
60 UPDATE,
61 MOVED,
62 RESIZED,
63 PLOT_AXIS_CHANGED,
64 LAST_SIGNAL
65 };
66
67 enum
68 {
69 TICK_LABEL,
70 AXIS_CHANGED,
71 LAST_AXIS_SIGNAL
72 };
73
74 enum
75 {
76 ARG_PLOT_0,
77 ARG_BOTTOM,
78 ARG_TOP,
79 ARG_LEFT,
80 ARG_RIGHT,
81 ARG_ALLOCATION_X,
82 ARG_ALLOCATION_Y,
83 ARG_ALLOCATION_WIDTH,
84 ARG_ALLOCATION_HEIGHT,
85 ARG_USE_PIXMAP,
86 ARG_BG_PIXMAP,
87 ARG_TRANSPARENT,
88 ARG_MAGNIFICATION,
89 ARG_CLIP_DATA,
90 ARG_BG,
91 ARG_GRIDS_ON_TOP,
92 ARG_SHOW_X0,
93 ARG_SHOW_Y0,
94 ARG_X0_LINE,
95 ARG_Y0_LINE,
96 ARG_XMIN,
97 ARG_XMAX,
98 ARG_YMIN,
99 ARG_YMAX,
100 ARG_X,
101 ARG_Y,
102 ARG_WIDTH,
103 ARG_HEIGHT,
104 ARG_XSCALE,
105 ARG_YSCALE,
106 ARG_REFLECT_X,
107 ARG_REFLECT_Y,
108 ARG_BOTTOM_ALIGN,
109 ARG_TOP_ALIGN,
110 ARG_LEFT_ALIGN,
111 ARG_RIGHT_ALIGN,
112 ARG_LEGENDS_X,
113 ARG_LEGENDS_Y,
114 ARG_LEGENDS_WIDTH,
115 ARG_LEGENDS_HEIGHT,
116 ARG_LEGENDS_BORDER,
117 ARG_LEGENDS_LINE_WIDTH,
118 ARG_LEGENDS_BORDER_WIDTH,
119 ARG_LEGENDS_SHADOW_WIDTH,
120 ARG_LEGENDS_SHOW,
121 ARG_LEGENDS_ATTR,
122 ARG_LEGENDS_TRANSPARENT,
123 };
124
125 enum
126 {
127 ARG_AXIS_0,
128 ARG_VISIBLE,
129 ARG_TITLE,
130 ARG_TITLE_VISIBLE,
131 ARG_ORIENTATION,
132 ARG_LINE,
133 ARG_MAJOR_GRID,
134 ARG_MINOR_GRID,
135 ARG_MAJOR_MASK,
136 ARG_MINOR_MASK,
137 ARG_TICKS_LENGTH,
138 ARG_TICKS_WIDTH,
139 ARG_CUSTOM_LABELS,
140 ARG_LABELS_OFFSET,
141 ARG_LABELS_PREFIX,
142 ARG_LABELS_SUFFIX,
143 ARG_SHOW_MAJOR_GRID,
144 ARG_SHOW_MINOR_GRID,
145 ARG_LABELS_ATTR,
146 ARG_LABELS_PRECISION,
147 ARG_LABELS_STYLE,
148 ARG_LABELS_MASK,
149 ARG_TICKS_MIN,
150 ARG_TICKS_MAX,
151 ARG_TICK_LABELS,
152 ARG_SCALE,
153 ARG_NMAJORTICKS,
154 ARG_NMINORTICKS,
155 ARG_NTICKS,
156 ARG_STEP,
157 ARG_NMINOR,
158 ARG_APPLY_BREAK,
159 ARG_BREAK_SCALE,
160 ARG_BREAK_STEP,
161 ARG_BREAK_NMINOR,
162 ARG_BREAK_MIN,
163 ARG_BREAK_MAX,
164 ARG_BREAK_POSITION,
165 ARG_SET_LIMITS,
166 ARG_BEGIN,
167 ARG_END
168 };
169
170 /* Private methods for ticks */
171 void gtk_plot_ticks_recalc (GtkPlotAxis *ticks);
172 void gtk_plot_ticks_autoscale (GtkPlotAxis *ticks,
173 gdouble xmin, gdouble xmax,
174 gint *precision);
175 gdouble gtk_plot_ticks_transform (GtkPlotAxis *ticks, gdouble y);
176 gdouble gtk_plot_ticks_inverse (GtkPlotAxis *ticks, gdouble x);
177 void gtk_plot_parse_label (GtkPlotAxis *axis,
178 gdouble val,
179 gint precision,
180 gint style,
181 gchar *label);
182
183
184 static void gtk_plot_class_init (GtkPlotClass *klass, gpointer unused);
185 static void gtk_plot_init (GtkPlot *plot, gpointer unused);
186 static void gtk_plot_set_property (GObject *object,
187 guint prop_id,
188 const GValue *value,
189 GParamSpec *pspec);
190 static void gtk_plot_get_property (GObject *object,
191 guint prop_id,
192 GValue *value,
193 GParamSpec *pspec);
194 static void gtk_plot_axis_class_init (GtkPlotAxisClass *klass, gpointer unused);
195 static void gtk_plot_axis_init (GtkPlotAxis *axis, gpointer unused);
196 static void gtk_plot_axis_set_property (GObject *object,
197 guint prop_id,
198 const GValue *value,
199 GParamSpec *pspec);
200 static void gtk_plot_axis_get_property (GObject *object,
201 guint prop_id,
202 GValue *value,
203 GParamSpec *pspec);
204 static void gtk_plot_destroy (GtkWidget *object);
205 static void gtk_plot_axis_destroy (GtkWidget *object);
206 static void gtk_plot_real_set_pc (GtkPlot *plot, GtkPlotPC *pc);
207 static void gtk_plot_real_set_drawable (GtkPlot *plot, cairo_surface_t *drawable);
208 static void gtk_plot_get_preferred_width (GtkWidget *widget,
209 gint *min,
210 gint *nat);
211 static void gtk_plot_get_preferred_height (GtkWidget *widget,
212 gint *min,
213 gint *nat);
214 static void gtk_plot_size_allocate (GtkWidget *widget,
215 GtkAllocation *allocation);
216 static void gtk_plot_show_all (GtkWidget *widget);
217 static void gtk_plot_draw_grids (GtkPlot *plot);
218 static void gtk_plot_draw_axis (GtkPlot *plot,
219 GtkPlotAxis *axis,
220 GtkPlotVector tick_direction);
221 static void gtk_plot_draw_labels (GtkPlot *plot,
222 GtkPlotAxis *axis,
223 GtkPlotVector tick_direction);
224 static void gtk_plot_draw_legends (GtkWidget *widget);
225 static void gtk_plot_real_paint (GtkWidget *widget);
226 static void gtk_plot_paint_text (GtkPlot *plot,
227 gint x, gint y,
228 GtkPlotText text);
229 static void gtk_plot_real_get_pixel (GtkWidget *widget,
230 gdouble xx, gdouble yy ,
231 gdouble *x, gdouble *y);
232 static void gtk_plot_real_get_point (GtkWidget *widget,
233 gint x, gint y,
234 gdouble *px, gdouble *py);
235 void gtk_plot_remove_dimension (GtkPlot *plot,
236 const gchar *dimension);
237 gint roundint (gdouble x);
238 static void update_datasets (GtkPlot *plot, gboolean new_range);
239
240 static GtkWidgetClass *parent_class = NULL;
241 static guint plot_signals[LAST_SIGNAL] = {0};
242 static guint axis_signals[LAST_AXIS_SIGNAL] = {0};
243
244
245 GType
gtk_plot_get_type(void)246 gtk_plot_get_type (void)
247 {
248 static GType plot_type = 0;
249
250 if (!plot_type)
251 {
252 plot_type = g_type_register_static_simple (
253 gtk_widget_get_type (),
254 "GtkPlot",
255 sizeof (GtkPlotClass),
256 (GClassInitFunc) gtk_plot_class_init,
257 sizeof (GtkPlot),
258 (GInstanceInitFunc) gtk_plot_init,
259 0);
260 }
261 return plot_type;
262 }
263
264 static void
gtk_plot_class_init(GtkPlotClass * klass,gpointer unused)265 gtk_plot_class_init (GtkPlotClass *klass, gpointer unused)
266 {
267 GObjectClass *object_class;
268 GtkWidgetClass *widget_class;
269 GtkPlotClass *plot_class;
270 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
271
272 parent_class = g_type_class_ref (gtk_widget_get_type ());
273
274 object_class = (GObjectClass *) klass;
275 widget_class = (GtkWidgetClass *) klass;
276 plot_class = (GtkPlotClass *) klass;
277
278 widget_class->show_all = gtk_plot_show_all;
279 widget_class->get_preferred_width = gtk_plot_get_preferred_width;
280 widget_class->get_preferred_height = gtk_plot_get_preferred_height;
281 widget_class->size_allocate = gtk_plot_size_allocate;
282
283
284 /**
285 * GtkPlot::add_data:
286 * @plot: a #GtkPlot widget.
287 * @plotdata: a #GtkPlotData.
288 *
289 *
290 *
291 * Return value:
292 */
293 plot_signals[ADD_DATA] =
294 g_signal_new("add_data",
295 G_TYPE_FROM_CLASS(object_class),
296 G_SIGNAL_RUN_LAST,
297 G_STRUCT_OFFSET (GtkPlotClass, add_data),
298 NULL, NULL,
299 gtkextra_BOOL__POINTER,
300 G_TYPE_BOOLEAN, 1, G_TYPE_PLOT_DATA);
301
302 /**
303 * GtkPlot::changed:
304 * @plot: a #GtkPlot widget.
305 *
306 *
307 */
308 plot_signals[CHANGED] =
309 g_signal_new("changed",
310 G_TYPE_FROM_CLASS(object_class),
311 G_SIGNAL_RUN_LAST,
312 G_STRUCT_OFFSET (GtkPlotClass, changed),
313 NULL, NULL,
314 gtkextra_VOID__VOID,
315 G_TYPE_NONE, 0);
316
317
318 /**
319 * GtkPlot::update:
320 * @plot: a #GtkPlot widget.
321 * @new_range:
322 *
323 *
324 */
325 plot_signals[UPDATE] =
326 g_signal_new("update",
327 G_TYPE_FROM_CLASS(object_class),
328 G_SIGNAL_RUN_LAST,
329 G_STRUCT_OFFSET (GtkPlotClass, update),
330 NULL, NULL,
331 gtkextra_VOID__BOOL,
332 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
333
334 /**
335 * GtkPlot::moved:
336 * @plot: a #GtkPlot widget.
337 * @x:
338 * @y:
339 *
340 *
341 *
342 * Return value:
343 */
344 plot_signals[MOVED] =
345 g_signal_new("moved",
346 G_TYPE_FROM_CLASS(object_class),
347 G_SIGNAL_RUN_LAST,
348 G_STRUCT_OFFSET (GtkPlotClass, moved),
349 NULL, NULL,
350 gtkextra_BOOL__POINTER_POINTER,
351 G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_POINTER);
352
353 /**
354 * GtkPlot::resized:
355 * @plot: a #GtkPlot widget.
356 * @width:
357 * @height:
358 *
359 *
360 *
361 * Return value:
362 */
363 plot_signals[RESIZED] =
364 g_signal_new("resized",
365 G_TYPE_FROM_CLASS(object_class),
366 G_SIGNAL_RUN_LAST,
367 G_STRUCT_OFFSET (GtkPlotClass, resized),
368 NULL, NULL,
369 gtkextra_BOOL__POINTER_POINTER,
370 G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_POINTER);
371
372 plot_signals[PLOT_AXIS_CHANGED] =
373 g_signal_new("axis_changed",
374 G_TYPE_FROM_CLASS(object_class),
375 G_SIGNAL_RUN_LAST,
376 G_STRUCT_OFFSET (GtkPlotClass, moved),
377 NULL, NULL,
378 gtkextra_BOOL__POINTER,
379 G_TYPE_BOOLEAN, 1, G_TYPE_PLOT_AXIS);
380
381 widget_class->destroy = gtk_plot_destroy;
382 gobject_class->set_property = gtk_plot_set_property;
383 gobject_class->get_property = gtk_plot_get_property;
384
385 klass->changed = NULL;
386 klass->moved = NULL;
387 klass->resized = NULL;
388
389 plot_class->set_pc = gtk_plot_real_set_pc;
390 plot_class->set_drawable = gtk_plot_real_set_drawable;
391 plot_class->add_data = NULL;
392 plot_class->update = update_datasets;
393 plot_class->plot_paint = gtk_plot_real_paint;
394 plot_class->draw_legends = gtk_plot_draw_legends;
395 plot_class->get_point = gtk_plot_real_get_point;
396 plot_class->get_pixel = gtk_plot_real_get_pixel;
397
398
399 /**
400 * GtkPlot:bottom_axis:
401 *
402 *
403 **/
404 g_object_class_install_property(gobject_class,
405 ARG_BOTTOM,
406 g_param_spec_object ("bottom_axis",
407 P_(""),
408 P_(""),
409 G_TYPE_PLOT_AXIS,
410 G_PARAM_READABLE));
411
412 /**
413 * GtkPlot:top_axis:
414 *
415 *
416 **/
417 g_object_class_install_property(gobject_class,
418 ARG_TOP,
419 g_param_spec_object ("top_axis",
420 P_(""),
421 P_(""),
422 G_TYPE_PLOT_AXIS,
423 G_PARAM_READABLE));
424
425 /**
426 * GtkPlot:left_axis:
427 *
428 *
429 **/
430 g_object_class_install_property(gobject_class,
431 ARG_LEFT,
432 g_param_spec_object ("left_axis",
433 P_(""),
434 P_(""),
435 G_TYPE_PLOT_AXIS,
436 G_PARAM_READABLE));
437
438 /**
439 * GtkPlot:right_axis:
440 *
441 *
442 **/
443 g_object_class_install_property(gobject_class,
444 ARG_RIGHT,
445 g_param_spec_object ("right_axis",
446 P_(""),
447 P_(""),
448 G_TYPE_PLOT_AXIS,
449 G_PARAM_READABLE));
450
451 /**
452 * GtkPlot:allocation_x:
453 *
454 *
455 **/
456 g_object_class_install_property(gobject_class,
457 ARG_ALLOCATION_X,
458 g_param_spec_int ("allocation_x",
459 P_(""),
460 P_(""),
461 -G_MAXINT,G_MAXINT,0,
462 G_PARAM_READABLE|G_PARAM_WRITABLE));
463
464 /**
465 * GtkPlot:allocation_y:
466 *
467 *
468 **/
469 g_object_class_install_property(gobject_class,
470 ARG_ALLOCATION_Y,
471 g_param_spec_int ("allocation_y",
472 P_(""),
473 P_(""),
474 -G_MAXINT,G_MAXINT,0,
475 G_PARAM_READABLE|G_PARAM_WRITABLE));
476
477 /**
478 * GtkPlot:allocation_width:
479 *
480 *
481 **/
482 g_object_class_install_property(gobject_class,
483 ARG_ALLOCATION_WIDTH,
484 g_param_spec_int ("allocation_width",
485 P_(""),
486 P_(""),
487 -G_MAXINT,G_MAXINT,0,
488 G_PARAM_READABLE|G_PARAM_WRITABLE));
489
490 /**
491 * GtkPlot:allocation_height:
492 *
493 *
494 **/
495 g_object_class_install_property(gobject_class,
496 ARG_ALLOCATION_HEIGHT,
497 g_param_spec_int ("allocation_height",
498 P_(""),
499 P_(""),
500 -G_MAXINT,G_MAXINT,0,
501 G_PARAM_READABLE|G_PARAM_WRITABLE));
502
503 /**
504 * GtkPlot:use_pixmap:
505 *
506 *
507 **/
508 g_object_class_install_property(gobject_class,
509 ARG_USE_PIXMAP,
510 g_param_spec_boolean ("use_pixmap",
511 P_(""),
512 P_(""),
513 FALSE,
514 G_PARAM_READABLE|G_PARAM_WRITABLE));
515
516 /**
517 * GtkPlot:bg_pixmap:
518 *
519 *
520 **/
521 g_object_class_install_property(gobject_class,
522 ARG_BG_PIXMAP,
523 g_param_spec_pointer ("bg_pixmap",
524 P_(""),
525 P_(""),
526 G_PARAM_READABLE|G_PARAM_WRITABLE));
527
528 /**
529 * GtkPlot:transparent:
530 *
531 *
532 **/
533 g_object_class_install_property(gobject_class,
534 ARG_TRANSPARENT,
535 g_param_spec_boolean ("transparent",
536 P_(""),
537 P_(""),
538 FALSE,
539 G_PARAM_READABLE|G_PARAM_WRITABLE));
540
541 /**
542 * GtkPlot:magnification:
543 *
544 *
545 **/
546 g_object_class_install_property(gobject_class,
547 ARG_MAGNIFICATION,
548 g_param_spec_double ("magnification",
549 P_(""),
550 P_(""),
551 0,G_MAXDOUBLE,0.0,
552 G_PARAM_READABLE|G_PARAM_WRITABLE));
553
554 /**
555 * GtkPlot:clip_data:
556 *
557 *
558 **/
559 g_object_class_install_property(gobject_class,
560 ARG_CLIP_DATA,
561 g_param_spec_boolean ("clip_data",
562 P_(""),
563 P_(""),
564 FALSE,
565 G_PARAM_READABLE|G_PARAM_WRITABLE));
566
567 /**
568 * GtkPlot:bg_color:
569 *
570 *
571 **/
572 g_object_class_install_property(gobject_class,
573 ARG_BG,
574 g_param_spec_pointer ("bg_color",
575 P_(""),
576 P_(""),
577 G_PARAM_READABLE|G_PARAM_WRITABLE));
578
579 /**
580 * GtkPlot:grids_on_top:
581 *
582 *
583 **/
584 g_object_class_install_property(gobject_class,
585 ARG_GRIDS_ON_TOP,
586 g_param_spec_boolean ("grids_on_top",
587 P_(""),
588 P_(""),
589 FALSE,
590 G_PARAM_READABLE|G_PARAM_WRITABLE));
591
592 /**
593 * GtkPlot:show_x0:
594 *
595 *
596 **/
597 g_object_class_install_property(gobject_class,
598 ARG_SHOW_X0,
599 g_param_spec_boolean ("show_x0",
600 P_(""),
601 P_(""),
602 FALSE,
603 G_PARAM_READABLE|G_PARAM_WRITABLE));
604
605 /**
606 * GtkPlot:show_y0:
607 *
608 *
609 **/
610 g_object_class_install_property(gobject_class,
611 ARG_SHOW_Y0,
612 g_param_spec_boolean ("show_y0",
613 P_(""),
614 P_(""),
615 FALSE,
616 G_PARAM_READABLE|G_PARAM_WRITABLE));
617
618 /**
619 * GtkPlot:x0_line:
620 *
621 *
622 **/
623 g_object_class_install_property(gobject_class,
624 ARG_X0_LINE,
625 g_param_spec_pointer ("x0_line",
626 P_(""),
627 P_(""),
628 G_PARAM_READABLE|G_PARAM_WRITABLE));
629
630 /**
631 * GtkPlot:y0_line:
632 *
633 *
634 **/
635 g_object_class_install_property(gobject_class,
636 ARG_Y0_LINE,
637 g_param_spec_pointer ("y0_line",
638 P_(""),
639 P_(""),
640 G_PARAM_READABLE|G_PARAM_WRITABLE));
641
642
643 /**
644 * GtkPlot:xmin:
645 *
646 *
647 **/
648 g_object_class_install_property(gobject_class,
649 ARG_XMIN,
650 g_param_spec_double ("xmin",
651 P_(""),
652 P_(""),
653 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
654 G_PARAM_READABLE|G_PARAM_WRITABLE));
655
656 /**
657 * GtkPlot:xmax:
658 *
659 *
660 **/
661 g_object_class_install_property(gobject_class,
662 ARG_XMAX,
663 g_param_spec_double ("xmax",
664 P_(""),
665 P_(""),
666 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
667 G_PARAM_READABLE|G_PARAM_WRITABLE));
668
669 /**
670 * GtkPlot:ymin:
671 *
672 *
673 **/
674 g_object_class_install_property(gobject_class,
675 ARG_YMIN,
676 g_param_spec_double ("ymin",
677 P_(""),
678 P_(""),
679 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
680 G_PARAM_READABLE|G_PARAM_WRITABLE));
681
682 /**
683 * GtkPlot:ymax:
684 *
685 *
686 **/
687 g_object_class_install_property(gobject_class,
688 ARG_YMAX,
689 g_param_spec_double ("ymax",
690 P_(""),
691 P_(""),
692 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
693 G_PARAM_READABLE|G_PARAM_WRITABLE));
694
695 /**
696 * GtkPlot:x:
697 *
698 *
699 **/
700 g_object_class_install_property(gobject_class,
701 ARG_X,
702 g_param_spec_double ("x",
703 P_(""),
704 P_(""),
705 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
706 G_PARAM_READABLE|G_PARAM_WRITABLE));
707
708 /**
709 * GtkPlot:y:
710 *
711 *
712 **/
713
714 g_object_class_install_property(gobject_class,
715 ARG_Y,
716 g_param_spec_double ("y",
717 P_(""),
718 P_(""),
719 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
720 G_PARAM_READABLE|G_PARAM_WRITABLE));
721
722 /**
723 * GtkPlot:width:
724 *
725 *
726 **/
727 g_object_class_install_property(gobject_class,
728 ARG_WIDTH,
729 g_param_spec_double ("width",
730 P_(""),
731 P_(""),
732 0,G_MAXDOUBLE,0.0,
733 G_PARAM_READABLE|G_PARAM_WRITABLE));
734
735 /**
736 * GtkPlot:height:
737 *
738 *
739 **/
740
741 g_object_class_install_property(gobject_class,
742 ARG_HEIGHT,
743 g_param_spec_double ("height",
744 P_(""),
745 P_(""),
746 0,G_MAXDOUBLE,0.0,
747 G_PARAM_READABLE|G_PARAM_WRITABLE));
748
749 /**
750 * GtkPlot:xscale:
751 *
752 *
753 **/
754 g_object_class_install_property(gobject_class,
755 ARG_XSCALE,
756 g_param_spec_int ("xscale",
757 P_(""),
758 P_(""),
759 0,G_MAXINT,0,
760 G_PARAM_READABLE|G_PARAM_WRITABLE));
761
762 /**
763 * GtkPlot:yscale:
764 *
765 *
766 **/
767 g_object_class_install_property(gobject_class,
768 ARG_YSCALE,
769 g_param_spec_int ("yscale",
770 P_(""),
771 P_(""),
772 0,G_MAXINT,0,
773 G_PARAM_READABLE|G_PARAM_WRITABLE));
774
775 /**
776 * GtkPlot:reflect_x:
777 *
778 *
779 **/
780 g_object_class_install_property(gobject_class,
781 ARG_REFLECT_X,
782 g_param_spec_boolean ("reflect_x",
783 P_(""),
784 P_(""),
785 FALSE,
786 G_PARAM_READABLE|G_PARAM_WRITABLE));
787
788 /**
789 * GtkPlot:reflect_y:
790 *
791 *
792 **/
793 g_object_class_install_property(gobject_class,
794 ARG_REFLECT_Y,
795 g_param_spec_boolean ("reflect_y",
796 P_(""),
797 P_(""),
798 FALSE,
799 G_PARAM_READABLE|G_PARAM_WRITABLE));
800
801 /**
802 * GtkPlot:bottom_align:
803 *
804 *
805 **/
806 g_object_class_install_property(gobject_class,
807 ARG_BOTTOM_ALIGN,
808 g_param_spec_double ("bottom_align",
809 P_(""),
810 P_(""),
811 0,G_MAXDOUBLE,0.0,
812 G_PARAM_READABLE|G_PARAM_WRITABLE));
813
814 /**
815 * GtkPlot:top_align:
816 *
817 *
818 **/
819 g_object_class_install_property(gobject_class,
820 ARG_TOP_ALIGN,
821 g_param_spec_double ("top_align",
822 P_(""),
823 P_(""),
824 0,G_MAXDOUBLE,0.0,
825 G_PARAM_READABLE|G_PARAM_WRITABLE));
826
827 /**
828 * GtkPlot:left_align:
829 *
830 *
831 **/
832 g_object_class_install_property(gobject_class,
833 ARG_LEFT_ALIGN,
834 g_param_spec_double ("left_align",
835 P_(""),
836 P_(""),
837 0,G_MAXDOUBLE,0.0,
838 G_PARAM_READABLE|G_PARAM_WRITABLE));
839
840 /**
841 * GtkPlot:right_align:
842 *
843 *
844 **/
845 g_object_class_install_property(gobject_class,
846 ARG_RIGHT_ALIGN,
847 g_param_spec_double ("right_align",
848 P_(""),
849 P_(""),
850 0,G_MAXDOUBLE,0.0,
851 G_PARAM_READABLE|G_PARAM_WRITABLE));
852
853 /**
854 * GtkPlot:legends_x:
855 *
856 *
857 **/
858 g_object_class_install_property(gobject_class,
859 ARG_LEGENDS_X,
860 g_param_spec_double ("legends_x",
861 P_(""),
862 P_(""),
863 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
864 G_PARAM_READABLE|G_PARAM_WRITABLE));
865
866 /**
867 * GtkPlot:legends_y:
868 *
869 *
870 **/
871 g_object_class_install_property(gobject_class,
872 ARG_LEGENDS_Y,
873 g_param_spec_double ("legends_y",
874 P_(""),
875 P_(""),
876 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
877 G_PARAM_READABLE|G_PARAM_WRITABLE));
878
879 /**
880 * GtkPlot:legends_width:
881 *
882 *
883 **/
884 g_object_class_install_property(gobject_class,
885 ARG_LEGENDS_WIDTH,
886 g_param_spec_int ("legends_width",
887 P_(""),
888 P_(""),
889 0,G_MAXINT,0,
890 G_PARAM_READABLE|G_PARAM_WRITABLE));
891
892 /**
893 * GtkPlot:legends_height:
894 *
895 *
896 **/
897 g_object_class_install_property(gobject_class,
898 ARG_LEGENDS_HEIGHT,
899 g_param_spec_int ("legends_height",
900 P_(""),
901 P_(""),
902 0,G_MAXINT,0,
903 G_PARAM_READABLE|G_PARAM_WRITABLE));
904
905 /**
906 * GtkPlot:legends_border:
907 *
908 *
909 **/
910 g_object_class_install_property(gobject_class,
911 ARG_LEGENDS_BORDER,
912 g_param_spec_int ("legends_border",
913 P_(""),
914 P_(""),
915 0,G_MAXINT,0,
916 G_PARAM_READABLE|G_PARAM_WRITABLE));
917
918
919 /**
920 * GtkPlot:legends_line_width:
921 *
922 *
923 **/
924 g_object_class_install_property(gobject_class,
925 ARG_LEGENDS_LINE_WIDTH,
926 g_param_spec_int ("legends_line_width",
927 P_(""),
928 P_(""),
929 0,G_MAXINT,0,
930 G_PARAM_READABLE|G_PARAM_WRITABLE));
931
932 /**
933 * GtkPlot:legends_border_width:
934 *
935 *
936 **/
937 g_object_class_install_property(gobject_class,
938 ARG_LEGENDS_BORDER_WIDTH,
939 g_param_spec_int ("legends_border_width",
940 P_(""),
941 P_(""),
942 0,G_MAXINT,0,
943 G_PARAM_READABLE|G_PARAM_WRITABLE));
944
945 /**
946 * GtkPlot:legends_shadow_width:
947 *
948 *
949 **/
950 g_object_class_install_property(gobject_class,
951 ARG_LEGENDS_SHADOW_WIDTH,
952 g_param_spec_int ("legends_shadow_width",
953 P_(""),
954 P_(""),
955 0,G_MAXINT,0,
956 G_PARAM_READABLE|G_PARAM_WRITABLE));
957
958 /**
959 * GtkPlot:legends_show:
960 *
961 *
962 **/
963 g_object_class_install_property(gobject_class,
964 ARG_LEGENDS_SHOW,
965 g_param_spec_boolean ("legends_show",
966 P_(""),
967 P_(""),
968 FALSE,
969 G_PARAM_READABLE|G_PARAM_WRITABLE));
970
971 /**
972 * GtkPlot:legends_attr_text:
973 *
974 *
975 **/
976 g_object_class_install_property(gobject_class,
977 ARG_LEGENDS_ATTR,
978 g_param_spec_pointer ("legends_attr_text",
979 P_(""),
980 P_(""),
981 G_PARAM_READABLE|G_PARAM_WRITABLE));
982
983 /**
984 * GtkPlot:legends_transparent:
985 *
986 *
987 **/
988 g_object_class_install_property(gobject_class,
989 ARG_LEGENDS_TRANSPARENT,
990 g_param_spec_boolean ("legends_transparent",
991 P_(""),
992 P_(""),
993 FALSE,
994 G_PARAM_READABLE|G_PARAM_WRITABLE));
995 }
996
997 GType
gtk_plot_axis_get_type(void)998 gtk_plot_axis_get_type (void)
999 {
1000 static GType axis_type = 0;
1001
1002 if (!axis_type)
1003 {
1004 axis_type = g_type_register_static_simple (
1005 gtk_widget_get_type(),
1006 "GtkPlotAxis",
1007 sizeof (GtkPlotAxisClass),
1008 (GClassInitFunc) gtk_plot_axis_class_init,
1009 sizeof (GtkPlotAxis),
1010 (GInstanceInitFunc) gtk_plot_axis_init,
1011 0);
1012 }
1013 return axis_type;
1014 }
1015
1016
1017 static void
gtk_plot_axis_class_init(GtkPlotAxisClass * klass,gpointer unused)1018 gtk_plot_axis_class_init (GtkPlotAxisClass *klass, gpointer unused)
1019 {
1020 GtkWidgetClass *object_class;
1021 GtkPlotAxisClass *axis_class;
1022 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
1023
1024 object_class = (GtkWidgetClass *) klass;
1025 axis_class = (GtkPlotAxisClass *) klass;
1026
1027 /**
1028 * GtkPlotAxis::tick_label:
1029 * @axis:
1030 * @tick:
1031 * @label:
1032 *
1033 *
1034 *
1035 * Return value:
1036 */
1037 axis_signals[TICK_LABEL] =
1038 g_signal_new("tick_label",
1039 G_TYPE_FROM_CLASS(object_class),
1040 G_SIGNAL_RUN_LAST,
1041 G_STRUCT_OFFSET (GtkPlotAxisClass, tick_label),
1042 NULL, NULL,
1043 gtkextra_BOOL__POINTER_POINTER,
1044 G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_POINTER);
1045
1046
1047 /**
1048 * GtkPlotAxis::changed:
1049 * @axis:
1050 *
1051 *
1052 *
1053 * Return value:
1054 */
1055 axis_signals[AXIS_CHANGED] =
1056 g_signal_new("changed",
1057 G_TYPE_FROM_CLASS(object_class),
1058 G_SIGNAL_RUN_LAST,
1059 G_STRUCT_OFFSET (GtkPlotAxisClass, changed),
1060 NULL, NULL,
1061 gtkextra_VOID__VOID,
1062 G_TYPE_NONE, 0);
1063
1064 object_class->destroy = gtk_plot_axis_destroy;
1065 gobject_class->set_property = gtk_plot_axis_set_property;
1066 gobject_class->get_property = gtk_plot_axis_get_property;
1067
1068 axis_class->tick_label = NULL;
1069
1070
1071 /**
1072 * GtkPlotAxis:visible:
1073 *
1074 *
1075 **/
1076 g_object_class_install_property(gobject_class,
1077 ARG_VISIBLE,
1078 g_param_spec_boolean ("visible",
1079 P_(""),
1080 P_(""),
1081 FALSE,
1082 G_PARAM_READABLE|G_PARAM_WRITABLE));
1083
1084 /**
1085 * GtkPlotAxis:title_text:
1086 *
1087 *
1088 **/
1089 g_object_class_install_property(gobject_class,
1090 ARG_TITLE,
1091 g_param_spec_pointer ("title_text",
1092 P_(""),
1093 P_(""),
1094 G_PARAM_READABLE|G_PARAM_WRITABLE));
1095
1096 /**
1097 * GtkPlotAxis:title_visible:
1098 *
1099 *
1100 **/
1101 g_object_class_install_property(gobject_class,
1102 ARG_TITLE_VISIBLE,
1103 g_param_spec_boolean ("title_visible",
1104 P_(""),
1105 P_(""),
1106 FALSE,
1107 G_PARAM_READABLE|G_PARAM_WRITABLE));
1108
1109 /**
1110 * GtkPlotAxis:orientation:
1111 *
1112 *
1113 **/
1114 g_object_class_install_property(gobject_class,
1115 ARG_ORIENTATION,
1116 g_param_spec_int ("orientation",
1117 P_(""),
1118 P_(""),
1119 0,2,0,
1120 G_PARAM_READABLE|G_PARAM_WRITABLE));
1121
1122
1123 /**
1124 * GtkPlotAxis:line:
1125 *
1126 *
1127 **/
1128 g_object_class_install_property(gobject_class,
1129 ARG_LINE,
1130 g_param_spec_pointer ("line",
1131 P_(""),
1132 P_(""),
1133 G_PARAM_READABLE|G_PARAM_WRITABLE));
1134
1135 /**
1136 * GtkPlotAxis:major_grid_line:
1137 *
1138 *
1139 **/
1140 g_object_class_install_property(gobject_class,
1141 ARG_MAJOR_GRID,
1142 g_param_spec_pointer ("major_grid_line",
1143 P_(""),
1144 P_(""),
1145 G_PARAM_READABLE|G_PARAM_WRITABLE));
1146
1147 /**
1148 * GtkPlotAxis:minor_grid_line:
1149 *
1150 *
1151 **/
1152 g_object_class_install_property(gobject_class,
1153 ARG_MINOR_GRID,
1154 g_param_spec_pointer ("minor_grid_line",
1155 P_(""),
1156 P_(""),
1157 G_PARAM_READABLE|G_PARAM_WRITABLE));
1158
1159 /**
1160 * GtkPlotAxis:major_mask:
1161 *
1162 *
1163 **/
1164 g_object_class_install_property(gobject_class,
1165 ARG_MAJOR_MASK,
1166 g_param_spec_int ("major_mask",
1167 P_(""),
1168 P_(""),
1169 0,G_MAXINT,0,
1170 G_PARAM_READABLE|G_PARAM_WRITABLE));
1171
1172 /**
1173 * GtkPlotAxis:minor_mask:
1174 *
1175 *
1176 **/
1177 g_object_class_install_property(gobject_class,
1178 ARG_MINOR_MASK,
1179 g_param_spec_int ("minor_mask",
1180 P_(""),
1181 P_(""),
1182 0,G_MAXINT,0,
1183 G_PARAM_READABLE|G_PARAM_WRITABLE));
1184
1185 /**
1186 * GtkPlotAxis:ticks_length:
1187 *
1188 *
1189 **/
1190 g_object_class_install_property(gobject_class,
1191 ARG_TICKS_LENGTH,
1192 g_param_spec_int ("ticks_length",
1193 P_(""),
1194 P_(""),
1195 0,G_MAXINT,0,
1196 G_PARAM_READABLE|G_PARAM_WRITABLE));
1197
1198 /**
1199 * GtkPlotAxis:ticks_width:
1200 *
1201 *
1202 **/
1203 g_object_class_install_property(gobject_class,
1204 ARG_TICKS_WIDTH,
1205 g_param_spec_double ("ticks_width",
1206 P_(""),
1207 P_(""),
1208 0,G_MAXDOUBLE,0.0,
1209 G_PARAM_READABLE|G_PARAM_WRITABLE));
1210
1211 /**
1212 * GtkPlotAxis:custom_labels:
1213 *
1214 *
1215 **/
1216 g_object_class_install_property(gobject_class,
1217 ARG_CUSTOM_LABELS,
1218 g_param_spec_boolean ("custom_labels",
1219 P_(""),
1220 P_(""),
1221 FALSE,
1222 G_PARAM_READABLE|G_PARAM_WRITABLE));
1223
1224
1225 /**
1226 * GtkPlotAxis:labels_array:
1227 *
1228 *
1229 **/
1230 g_object_class_install_property(gobject_class,
1231 ARG_TICK_LABELS,
1232 g_param_spec_object ("labels_array",
1233 P_(""),
1234 P_(""),
1235 G_TYPE_PLOT_ARRAY,
1236 G_PARAM_READABLE|G_PARAM_WRITABLE));
1237
1238 /**
1239 * GtkPlotAxis:labels_offset:
1240 *
1241 *
1242 **/
1243 g_object_class_install_property(gobject_class,
1244 ARG_LABELS_OFFSET,
1245 g_param_spec_int ("labels_offset",
1246 P_(""),
1247 P_(""),
1248 0,G_MAXINT,0,
1249 G_PARAM_READABLE|G_PARAM_WRITABLE));
1250
1251 /**
1252 * GtkPlotAxis:labels_prefix:
1253 *
1254 *
1255 **/
1256 g_object_class_install_property(gobject_class,
1257 ARG_LABELS_PREFIX,
1258 g_param_spec_string ("labels_prefix",
1259 P_(""),
1260 P_(""),
1261 NULL,
1262 G_PARAM_READABLE|G_PARAM_WRITABLE));
1263
1264 /**
1265 * GtkPlotAxis:labels_suffix:
1266 *
1267 *
1268 **/
1269 g_object_class_install_property(gobject_class,
1270 ARG_LABELS_SUFFIX,
1271 g_param_spec_string ("labels_suffix",
1272 P_(""),
1273 P_(""),
1274 NULL,
1275 G_PARAM_READABLE|G_PARAM_WRITABLE));
1276
1277 /**
1278 * GtkPlotAxis:show_major_grid:
1279 *
1280 *
1281 **/
1282 g_object_class_install_property(gobject_class,
1283 ARG_SHOW_MAJOR_GRID,
1284 g_param_spec_boolean ("show_major_grid",
1285 P_(""),
1286 P_(""),
1287 FALSE,
1288 G_PARAM_READABLE|G_PARAM_WRITABLE));
1289
1290 /**
1291 * GtkPlotAxis:show_minor_grid:
1292 *
1293 *
1294 **/
1295 g_object_class_install_property(gobject_class,
1296 ARG_SHOW_MINOR_GRID,
1297 g_param_spec_boolean ("show_minor_grid",
1298 P_(""),
1299 P_(""),
1300 FALSE,
1301 G_PARAM_READABLE|G_PARAM_WRITABLE));
1302
1303 /**
1304 * GtkPlotAxis:labels_text:
1305 *
1306 *
1307 **/
1308 g_object_class_install_property(gobject_class,
1309 ARG_LABELS_ATTR,
1310 g_param_spec_pointer ("labels_text",
1311 P_(""),
1312 P_(""),
1313 G_PARAM_READABLE|G_PARAM_WRITABLE));
1314
1315 /**
1316 * GtkPlotAxis:labels_precision:
1317 *
1318 *
1319 **/
1320 g_object_class_install_property(gobject_class,
1321 ARG_LABELS_PRECISION,
1322 g_param_spec_int ("labels_precision",
1323 P_(""),
1324 P_(""),
1325 0,G_MAXINT,0,
1326 G_PARAM_READABLE|G_PARAM_WRITABLE));
1327
1328 /**
1329 * GtkPlotAxis:labels_style:
1330 *
1331 *
1332 **/
1333 g_object_class_install_property(gobject_class,
1334 ARG_LABELS_STYLE,
1335 g_param_spec_int ("labels_style",
1336 P_(""),
1337 P_(""),
1338 0,G_MAXINT,0,
1339 G_PARAM_READABLE|G_PARAM_WRITABLE));
1340
1341 /**
1342 * GtkPlotAxis:labels_mask:
1343 *
1344 *
1345 **/
1346 g_object_class_install_property(gobject_class,
1347 ARG_LABELS_MASK,
1348 g_param_spec_int ("labels_mask",
1349 P_(""),
1350 P_(""),
1351 0,G_MAXINT,0,
1352 G_PARAM_READABLE|G_PARAM_WRITABLE));
1353
1354 /**
1355 * GtkPlotAxis:min:
1356 *
1357 *
1358 **/
1359 g_object_class_install_property(gobject_class,
1360 ARG_TICKS_MIN,
1361 g_param_spec_double ("min",
1362 P_(""),
1363 P_(""),
1364 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
1365 G_PARAM_READABLE|G_PARAM_WRITABLE));
1366
1367 /**
1368 * GtkPlotAxis:max:
1369 *
1370 *
1371 **/
1372 g_object_class_install_property(gobject_class,
1373 ARG_TICKS_MAX,
1374 g_param_spec_double ("max",
1375 P_(""),
1376 P_(""),
1377 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
1378 G_PARAM_READABLE|G_PARAM_WRITABLE));
1379
1380 /**
1381 * GtkPlotAxis:scale:
1382 *
1383 *
1384 **/
1385 g_object_class_install_property(gobject_class,
1386 ARG_SCALE,
1387 g_param_spec_int ("scale",
1388 P_(""),
1389 P_(""),
1390 0,G_MAXINT,0,
1391 G_PARAM_READABLE|G_PARAM_WRITABLE));
1392
1393 /**
1394 * GtkPlotAxis:nmajorticks:
1395 *
1396 *
1397 **/
1398 g_object_class_install_property(gobject_class,
1399 ARG_NMAJORTICKS,
1400 g_param_spec_int ("nmajorticks",
1401 P_(""),
1402 P_(""),
1403 0,G_MAXINT,0,
1404 G_PARAM_READABLE|G_PARAM_WRITABLE));
1405
1406 /**
1407 * GtkPlotAxis:nminorticks:
1408 *
1409 *
1410 **/
1411 g_object_class_install_property(gobject_class,
1412 ARG_NMINORTICKS,
1413 g_param_spec_int ("nminorticks",
1414 P_(""),
1415 P_(""),
1416 0,G_MAXINT,0,
1417 G_PARAM_READABLE|G_PARAM_WRITABLE));
1418
1419 /**
1420 * GtkPlotAxis:nticks:
1421 *
1422 *
1423 **/
1424 g_object_class_install_property(gobject_class,
1425 ARG_NTICKS,
1426 g_param_spec_int ("nticks",
1427 P_(""),
1428 P_(""),
1429 0,G_MAXINT,0,
1430 G_PARAM_READABLE|G_PARAM_WRITABLE));
1431
1432 /**
1433 * GtkPlotAxis:step:
1434 *
1435 *
1436 **/
1437 g_object_class_install_property(gobject_class,
1438 ARG_STEP,
1439 g_param_spec_double ("step",
1440 P_(""),
1441 P_(""),
1442 0,G_MAXDOUBLE,0.0,
1443 G_PARAM_READABLE|G_PARAM_WRITABLE));
1444
1445 /**
1446 * GtkPlotAxis:nminor:
1447 *
1448 *
1449 **/
1450 g_object_class_install_property(gobject_class,
1451 ARG_NMINOR,
1452 g_param_spec_int ("nminor",
1453 P_(""),
1454 P_(""),
1455 0,G_MAXINT,0,
1456 G_PARAM_READABLE|G_PARAM_WRITABLE));
1457
1458 /**
1459 * GtkPlotAxis:apply_break:
1460 *
1461 *
1462 **/
1463 g_object_class_install_property(gobject_class,
1464 ARG_APPLY_BREAK,
1465 g_param_spec_boolean ("apply_break",
1466 P_(""),
1467 P_(""),
1468 FALSE,
1469 G_PARAM_READABLE|G_PARAM_WRITABLE));
1470
1471 /**
1472 * GtkPlotAxis:break_scale:
1473 *
1474 *
1475 **/
1476 g_object_class_install_property(gobject_class,
1477 ARG_BREAK_SCALE,
1478 g_param_spec_int ("break_scale",
1479 P_(""),
1480 P_(""),
1481 0,G_MAXINT,0,
1482 G_PARAM_READABLE|G_PARAM_WRITABLE));
1483
1484 /**
1485 * GtkPlotAxis:break_min:
1486 *
1487 *
1488 **/
1489 g_object_class_install_property(gobject_class,
1490 ARG_BREAK_MIN,
1491 g_param_spec_double ("break_min",
1492 P_(""),
1493 P_(""),
1494 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
1495 G_PARAM_READABLE|G_PARAM_WRITABLE));
1496
1497 /**
1498 * GtkPlotAxis:break_max:
1499 *
1500 *
1501 **/
1502 g_object_class_install_property(gobject_class,
1503 ARG_BREAK_MAX,
1504 g_param_spec_double ("break_max",
1505 P_(""),
1506 P_(""),
1507 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
1508 G_PARAM_READABLE|G_PARAM_WRITABLE));
1509
1510 /**
1511 * GtkPlotAxis:break_step:
1512 *
1513 *
1514 **/
1515 g_object_class_install_property(gobject_class,
1516 ARG_BREAK_STEP,
1517 g_param_spec_double ("break_step",
1518 P_(""),
1519 P_(""),
1520 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
1521 G_PARAM_READABLE|G_PARAM_WRITABLE));
1522
1523 /**
1524 * GtkPlotAxis:break_nminor:
1525 *
1526 *
1527 **/
1528 g_object_class_install_property(gobject_class,
1529 ARG_BREAK_NMINOR,
1530 g_param_spec_int ("break_nminor",
1531 P_(""),
1532 P_(""),
1533 0,G_MAXINT,0,
1534 G_PARAM_READABLE|G_PARAM_WRITABLE));
1535
1536 /**
1537 * GtkPlotAxis:break_position:
1538 *
1539 *
1540 **/
1541 g_object_class_install_property(gobject_class,
1542 ARG_BREAK_POSITION,
1543 g_param_spec_double ("break_position",
1544 P_(""),
1545 P_(""),
1546 0,G_MAXDOUBLE,0.0,
1547 G_PARAM_READABLE|G_PARAM_WRITABLE));
1548
1549 /**
1550 * GtkPlotAxis:set_limits:
1551 *
1552 *
1553 **/
1554 g_object_class_install_property(gobject_class,
1555 ARG_SET_LIMITS,
1556 g_param_spec_boolean ("set_limits",
1557 P_(""),
1558 P_(""),
1559 FALSE,
1560 G_PARAM_READABLE|G_PARAM_WRITABLE));
1561
1562 /**
1563 * GtkPlotAxis:begin:
1564 *
1565 *
1566 **/
1567 g_object_class_install_property(gobject_class,
1568 ARG_BEGIN,
1569 g_param_spec_double ("begin",
1570 P_(""),
1571 P_(""),
1572 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
1573 G_PARAM_READABLE|G_PARAM_WRITABLE));
1574
1575 /**
1576 * GtkPlotAxis:end:
1577 *
1578 *
1579 **/
1580 g_object_class_install_property(gobject_class,
1581 ARG_END,
1582 g_param_spec_double ("end",
1583 P_(""),
1584 P_(""),
1585 -G_MAXDOUBLE,G_MAXDOUBLE,0.0,
1586 G_PARAM_READABLE|G_PARAM_WRITABLE));
1587 }
1588
1589 static void
axis_changed(GtkPlotAxis * axis,GtkPlot * plot)1590 axis_changed(GtkPlotAxis *axis, GtkPlot *plot)
1591 {
1592 g_signal_emit (plot, plot_signals[CHANGED], 0);
1593 }
1594
1595 static void
gtk_plot_init(GtkPlot * plot,gpointer unused)1596 gtk_plot_init (GtkPlot *plot, gpointer unused)
1597 {
1598 GdkRGBA black, white;
1599
1600 gtk_widget_set_has_window(GTK_WIDGET(plot), FALSE);
1601
1602 gdk_rgba_parse(&black, "black");
1603 gdk_rgba_parse(&white, "white");
1604
1605 plot->bg_pixmap = NULL;
1606 plot->transparent = FALSE;
1607 plot->clip_data = FALSE;
1608 plot->grids_on_top = FALSE;
1609
1610 plot->reflect_x = FALSE;
1611 plot->reflect_y = FALSE;
1612
1613 plot->magnification = 1.;
1614
1615 plot->xmin = 0.;
1616 plot->xmax = 1.000000;
1617 plot->ymin = 0.;
1618 plot->ymax = 1.000000;
1619
1620 plot->show_x0 = FALSE;
1621 plot->show_y0 = FALSE;
1622
1623 plot->right = GTK_PLOT_AXIS(gtk_plot_axis_new(GTK_PLOT_AXIS_Y));
1624 g_object_ref(plot->right);
1625 g_object_ref_sink(plot->right);
1626 g_object_unref(plot->right);
1627 g_signal_connect(plot->right, "changed",
1628 (void *)axis_changed, plot);
1629 plot->left = GTK_PLOT_AXIS(gtk_plot_axis_new(GTK_PLOT_AXIS_Y));
1630 g_object_ref(plot->left);
1631 g_object_ref_sink(plot->left);
1632 g_object_unref(plot->left);
1633 g_signal_connect(plot->left, "changed",
1634 (void *)axis_changed, plot);
1635 plot->top = GTK_PLOT_AXIS(gtk_plot_axis_new(GTK_PLOT_AXIS_X));
1636 g_object_ref(plot->top);
1637 g_object_ref_sink(plot->top);
1638 g_object_unref(plot->top);
1639 g_signal_connect(plot->top, "changed",
1640 (void *)axis_changed, plot);
1641 plot->bottom = GTK_PLOT_AXIS(gtk_plot_axis_new(GTK_PLOT_AXIS_X));
1642 g_object_ref(plot->bottom);
1643 g_object_ref_sink(plot->bottom);
1644 g_object_unref(plot->bottom);
1645 g_signal_connect(plot->bottom, "changed",
1646 (void *)axis_changed, plot);
1647
1648 plot->left->labels_attr.justification = GTK_JUSTIFY_RIGHT;
1649 plot->right->labels_attr.justification = GTK_JUSTIFY_LEFT;
1650 plot->right->title.angle = 270;
1651
1652 gtk_plot_axis_ticks_recalc(plot->left);
1653 gtk_plot_axis_ticks_recalc(plot->right);
1654 gtk_plot_axis_ticks_recalc(plot->bottom);
1655 gtk_plot_axis_ticks_recalc(plot->top);
1656
1657 plot->bottom_align = 0.;
1658 plot->top_align = 1.;
1659 plot->left_align = 0.;
1660 plot->right_align = 1.;
1661
1662 plot->x0_line.line_style = GTK_PLOT_LINE_SOLID;
1663 plot->x0_line.cap_style = 0;
1664 plot->x0_line.join_style = 0;
1665 plot->x0_line.line_width = 0;
1666 plot->x0_line.color = black;
1667
1668 plot->y0_line.line_style = GTK_PLOT_LINE_SOLID;
1669 plot->y0_line.line_width = 0;
1670 plot->y0_line.cap_style = 0;
1671 plot->y0_line.join_style = 0;
1672 plot->y0_line.color = black;
1673
1674 plot->legends_x = .6;
1675 plot->legends_y = .1;
1676 plot->legends_width = 0;
1677 plot->legends_height = 0;
1678 plot->legends_line_width = 30;
1679 plot->legends_border_width = 1;
1680 plot->legends_shadow_width = 3;
1681 plot->legends_border = GTK_PLOT_BORDER_LINE;
1682 plot->show_legends = TRUE;
1683 plot->legends_attr.text = NULL;
1684 plot->legends_attr.font = g_strdup(DEFAULT_FONT);
1685 plot->legends_attr.height = DEFAULT_FONT_HEIGHT;
1686 plot->legends_attr.fg = black;
1687 plot->legends_attr.bg = white;
1688 plot->legends_attr.transparent = FALSE;
1689 plot->legends_attr.border = 0;
1690 plot->legends_attr.border_width = 0;
1691 plot->legends_attr.shadow_width = 0;
1692
1693 plot->background = white;
1694
1695 plot->xscale = GTK_PLOT_SCALE_LINEAR;
1696 plot->yscale = GTK_PLOT_SCALE_LINEAR;
1697
1698 plot->data_sets = NULL;
1699 plot->text = NULL;
1700
1701 gtk_psfont_init();
1702 plot->drawable = NULL;
1703
1704 plot->pc = NULL;
1705 gtk_plot_set_pc(plot, NULL);
1706 }
1707
1708 static void
gtk_plot_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)1709 gtk_plot_get_property (GObject *object,
1710 guint prop_id,
1711 GValue *value,
1712 GParamSpec *pspec)
1713 {
1714 GtkPlot *plot;
1715
1716 plot = GTK_PLOT (object);
1717
1718 switch(prop_id){
1719 case ARG_BOTTOM:
1720 g_value_set_object(value, plot->bottom);
1721 break;
1722 case ARG_TOP:
1723 g_value_set_object(value, plot->top);
1724 break;
1725 case ARG_LEFT:
1726 g_value_set_object(value, plot->left);
1727 break;
1728 case ARG_RIGHT:
1729 g_value_set_object(value, plot->right);
1730 break;
1731 case ARG_ALLOCATION_X:
1732 g_value_set_int(value, plot->internal_allocation.x);
1733 break;
1734 case ARG_ALLOCATION_Y:
1735 g_value_set_int(value, plot->internal_allocation.y);
1736 break;
1737 case ARG_ALLOCATION_WIDTH:
1738 g_value_set_int(value, plot->internal_allocation.width);
1739 break;
1740 case ARG_ALLOCATION_HEIGHT:
1741 g_value_set_int(value, plot->internal_allocation.height);
1742 break;
1743 case ARG_USE_PIXMAP:
1744 g_value_set_boolean(value, plot->use_pixmap);
1745 break;
1746 case ARG_BG_PIXMAP:
1747 g_value_set_pointer(value, plot->bg_pixmap);
1748 break;
1749 case ARG_TRANSPARENT:
1750 g_value_set_boolean(value, plot->transparent);
1751 break;
1752 case ARG_MAGNIFICATION:
1753 g_value_set_double(value, plot->magnification);
1754 break;
1755 case ARG_CLIP_DATA:
1756 g_value_set_boolean(value, plot->clip_data);
1757 break;
1758 case ARG_BG:
1759 g_value_set_pointer(value, &plot->background);
1760 break;
1761 case ARG_GRIDS_ON_TOP:
1762 g_value_set_boolean(value, plot->grids_on_top);
1763 break;
1764 case ARG_SHOW_X0:
1765 g_value_set_boolean(value, plot->show_x0);
1766 break;
1767 case ARG_SHOW_Y0:
1768 g_value_set_boolean(value, plot->show_y0);
1769 break;
1770 case ARG_X0_LINE:
1771 g_value_set_pointer(value, &plot->x0_line);
1772 break;
1773 case ARG_Y0_LINE:
1774 g_value_set_pointer(value, &plot->y0_line);
1775 break;
1776 case ARG_XMIN:
1777 g_value_set_double(value, plot->xmin);
1778 break;
1779 case ARG_XMAX:
1780 g_value_set_double(value, plot->xmax);
1781 break;
1782 case ARG_YMIN:
1783 g_value_set_double(value, plot->ymin);
1784 break;
1785 case ARG_YMAX:
1786 g_value_set_double(value, plot->ymax);
1787 break;
1788 case ARG_X:
1789 g_value_set_double(value, plot->x);
1790 break;
1791 case ARG_Y:
1792 g_value_set_double(value, plot->y);
1793 break;
1794 case ARG_WIDTH:
1795 g_value_set_double(value, plot->width);
1796 break;
1797 case ARG_HEIGHT:
1798 g_value_set_double(value, plot->height);
1799 break;
1800 case ARG_XSCALE:
1801 g_value_set_int(value, plot->xscale);
1802 break;
1803 case ARG_YSCALE:
1804 g_value_set_int(value, plot->yscale);
1805 break;
1806 case ARG_REFLECT_X:
1807 g_value_set_boolean(value, plot->reflect_x);
1808 break;
1809 case ARG_REFLECT_Y:
1810 g_value_set_boolean(value, plot->reflect_y);
1811 break;
1812 case ARG_BOTTOM_ALIGN:
1813 g_value_set_double(value, plot->bottom_align);
1814 break;
1815 case ARG_TOP_ALIGN:
1816 g_value_set_double(value, plot->top_align);
1817 break;
1818 case ARG_LEFT_ALIGN:
1819 g_value_set_double(value, plot->left_align);
1820 break;
1821 case ARG_RIGHT_ALIGN:
1822 g_value_set_double(value, plot->right_align);
1823 break;
1824 case ARG_LEGENDS_X:
1825 g_value_set_double(value, plot->legends_x);
1826 break;
1827 case ARG_LEGENDS_Y:
1828 g_value_set_double(value, plot->legends_y);
1829 break;
1830 case ARG_LEGENDS_WIDTH:
1831 g_value_set_int(value, plot->legends_width);
1832 break;
1833 case ARG_LEGENDS_HEIGHT:
1834 g_value_set_int(value, plot->legends_height);
1835 break;
1836 case ARG_LEGENDS_BORDER:
1837 g_value_set_int(value, plot->legends_border);
1838 break;
1839 case ARG_LEGENDS_LINE_WIDTH:
1840 g_value_set_int(value, plot->legends_line_width);
1841 break;
1842 case ARG_LEGENDS_BORDER_WIDTH:
1843 g_value_set_int(value, plot->legends_border_width);
1844 break;
1845 case ARG_LEGENDS_SHADOW_WIDTH:
1846 g_value_set_int(value, plot->legends_shadow_width);
1847 break;
1848 case ARG_LEGENDS_SHOW:
1849 g_value_set_boolean(value, plot->show_legends);
1850 break;
1851 case ARG_LEGENDS_ATTR:
1852 g_value_set_pointer(value, &plot->legends_attr);
1853 break;
1854 case ARG_LEGENDS_TRANSPARENT:
1855 g_value_set_boolean(value, plot->legends_attr.transparent);
1856 break;
1857 default:
1858 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1859 break;
1860 }
1861 }
1862
1863 static void
gtk_plot_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)1864 gtk_plot_set_property (GObject *object,
1865 guint prop_id,
1866 const GValue *value,
1867 GParamSpec *pspec)
1868 {
1869 GtkPlot *plot;
1870 GtkPlotText *text = NULL;
1871
1872 plot = GTK_PLOT (object);
1873
1874 switch(prop_id){
1875 case ARG_ALLOCATION_X:
1876 plot->internal_allocation.x = g_value_get_int(value);
1877 break;
1878 case ARG_ALLOCATION_Y:
1879 plot->internal_allocation.y = g_value_get_int(value);
1880 break;
1881 case ARG_ALLOCATION_WIDTH:
1882 plot->internal_allocation.width = g_value_get_int(value);
1883 break;
1884 case ARG_ALLOCATION_HEIGHT:
1885 plot->internal_allocation.height = g_value_get_int(value);
1886 break;
1887 case ARG_USE_PIXMAP:
1888 plot->use_pixmap = g_value_get_boolean(value);
1889 break;
1890 case ARG_BG_PIXMAP:
1891 if(plot->bg_pixmap) cairo_surface_destroy(plot->bg_pixmap);
1892 plot->bg_pixmap = (cairo_surface_t *)g_value_get_pointer(value);
1893 if(plot->bg_pixmap) cairo_surface_reference(plot->bg_pixmap);
1894 break;
1895 case ARG_TRANSPARENT:
1896 plot->transparent = g_value_get_boolean(value);
1897 break;
1898 case ARG_MAGNIFICATION:
1899 plot->magnification = g_value_get_double(value);
1900 break;
1901 case ARG_CLIP_DATA:
1902 plot->clip_data = g_value_get_boolean(value);
1903 break;
1904 case ARG_BG:
1905 plot->background = *((GdkRGBA *)g_value_get_pointer(value));
1906 break;
1907 case ARG_GRIDS_ON_TOP:
1908 plot->grids_on_top = g_value_get_boolean(value);
1909 break;
1910 case ARG_SHOW_X0:
1911 plot->show_x0 = g_value_get_boolean(value);
1912 break;
1913 case ARG_SHOW_Y0:
1914 plot->show_y0 = g_value_get_boolean(value);
1915 break;
1916 case ARG_X0_LINE:
1917 plot->x0_line = *((GtkPlotLine *)g_value_get_pointer(value));
1918 break;
1919 case ARG_Y0_LINE:
1920 plot->y0_line = *((GtkPlotLine *)g_value_get_pointer(value));
1921 break;
1922 case ARG_XMIN:
1923 plot->xmin = g_value_get_double(value);
1924 break;
1925 case ARG_XMAX:
1926 plot->xmax = g_value_get_double(value);
1927 break;
1928 case ARG_YMIN:
1929 plot->ymin = g_value_get_double(value);
1930 break;
1931 case ARG_YMAX:
1932 plot->ymax = g_value_get_double(value);
1933 break;
1934 case ARG_X:
1935 plot->x = g_value_get_double(value);
1936 break;
1937 case ARG_Y:
1938 plot->y = g_value_get_double(value);
1939 break;
1940 case ARG_WIDTH:
1941 plot->width = g_value_get_double(value);
1942 break;
1943 case ARG_HEIGHT:
1944 plot->height = g_value_get_double(value);
1945 break;
1946 case ARG_XSCALE:
1947 plot->xscale = g_value_get_int(value);
1948 break;
1949 case ARG_YSCALE:
1950 plot->yscale = g_value_get_int(value);
1951 break;
1952 case ARG_REFLECT_X:
1953 plot->reflect_x = g_value_get_boolean(value);
1954 break;
1955 case ARG_REFLECT_Y:
1956 plot->reflect_y = g_value_get_boolean(value);
1957 break;
1958 case ARG_BOTTOM_ALIGN:
1959 plot->bottom_align = g_value_get_double(value);
1960 break;
1961 case ARG_TOP_ALIGN:
1962 plot->top_align = g_value_get_double(value);
1963 break;
1964 case ARG_LEFT_ALIGN:
1965 plot->left_align = g_value_get_double(value);
1966 break;
1967 case ARG_RIGHT_ALIGN:
1968 plot->right_align = g_value_get_double(value);
1969 break;
1970 case ARG_LEGENDS_X:
1971 plot->legends_x = g_value_get_double(value);
1972 break;
1973 case ARG_LEGENDS_Y:
1974 plot->legends_y = g_value_get_double(value);
1975 break;
1976 case ARG_LEGENDS_WIDTH:
1977 plot->legends_width = g_value_get_int(value);
1978 break;
1979 case ARG_LEGENDS_HEIGHT:
1980 plot->legends_height = g_value_get_int(value);
1981 break;
1982 case ARG_LEGENDS_BORDER:
1983 plot->legends_border = g_value_get_int(value);
1984 break;
1985 case ARG_LEGENDS_LINE_WIDTH:
1986 plot->legends_line_width = g_value_get_int(value);
1987 break;
1988 case ARG_LEGENDS_BORDER_WIDTH:
1989 plot->legends_border_width = g_value_get_int(value);
1990 break;
1991 case ARG_LEGENDS_SHADOW_WIDTH:
1992 plot->legends_shadow_width = g_value_get_int(value);
1993 break;
1994 case ARG_LEGENDS_SHOW:
1995 plot->show_legends = g_value_get_boolean(value);
1996 break;
1997 case ARG_LEGENDS_ATTR:
1998 text = (GtkPlotText *)g_value_get_pointer(value);
1999 gtk_plot_legends_set_attributes(plot,
2000 text->font,
2001 text->height,
2002 &text->fg,
2003 &text->bg);
2004 break;
2005 case ARG_LEGENDS_TRANSPARENT:
2006 plot->legends_attr.transparent = g_value_get_boolean(value);
2007 break;
2008 default:
2009 break;
2010 }
2011 }
2012
2013 /**
2014 * gtk_plot_set_pc:
2015 * @plot: a #GtkPlot widget
2016 * @pc: a #GtkPlotPc
2017 *
2018 *
2019 */
2020 void
gtk_plot_set_pc(GtkPlot * plot,GtkPlotPC * pc)2021 gtk_plot_set_pc(GtkPlot *plot, GtkPlotPC *pc)
2022 {
2023 GTK_PLOT_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(plot)))->set_pc(plot, pc);
2024 }
2025
2026 static void
gtk_plot_real_set_pc(GtkPlot * plot,GtkPlotPC * pc)2027 gtk_plot_real_set_pc(GtkPlot *plot, GtkPlotPC *pc)
2028 {
2029 if(plot->pc)
2030 g_object_unref(plot->pc);
2031
2032 if(!pc){
2033 plot->pc = (GtkPlotPC *)gtk_plot_cairo_new(NULL);
2034 g_object_ref(plot->pc);
2035 g_object_ref_sink(plot->pc);
2036 g_object_unref(plot->pc);
2037 } else {
2038 plot->pc = pc;
2039 g_object_ref(plot->pc);
2040 g_object_ref_sink(plot->pc);
2041 g_object_unref(plot->pc);
2042 }
2043 }
2044
2045 static void
gtk_plot_axis_init(GtkPlotAxis * axis,gpointer unused)2046 gtk_plot_axis_init (GtkPlotAxis *axis, gpointer unused)
2047 {
2048 GdkRGBA black, white;
2049
2050 gdk_rgba_parse(&black, "black");
2051 gdk_rgba_parse(&white, "white");
2052
2053 axis->ticks.nmajorticks = 0;
2054 axis->ticks.nminorticks = 0;
2055 axis->ticks.values = NULL;
2056 axis->ticks.nticks = 0;
2057 axis->ticks.set_limits = FALSE;
2058 axis->ticks.begin = 0;
2059 axis->ticks.end = 0;
2060 axis->ticks.step = .100000000;
2061 axis->ticks.nminor = 1;
2062 axis->ticks.scale = GTK_PLOT_SCALE_LINEAR;
2063 axis->ticks.apply_break = FALSE;
2064 axis->ticks.break_min = 0.;
2065 axis->ticks.break_max = 0.;
2066 axis->ticks.break_step = .1;
2067 axis->ticks.break_nminor = 1;
2068 axis->ticks.break_scale = GTK_PLOT_SCALE_LINEAR;
2069 axis->ticks.break_position = 0.5;
2070
2071 axis->ticks.min = 0.0;
2072 axis->ticks.max = 1.0;
2073 axis->major_mask = GTK_PLOT_TICKS_IN;
2074 axis->minor_mask = GTK_PLOT_TICKS_IN;
2075 axis->ticks_length = 8;
2076 axis->ticks_width = 1;
2077 axis->labels_offset = 10;
2078 axis->orientation = GTK_PLOT_AXIS_X;
2079 axis->is_visible = TRUE;
2080 axis->custom_labels = FALSE;
2081
2082 axis->line.line_style = GTK_PLOT_LINE_SOLID;
2083 axis->line.cap_style = 3;
2084 axis->line.join_style = 0;
2085 axis->line.line_width = 2;
2086 axis->line.color = black;
2087 axis->labels_attr.text = NULL;
2088 axis->labels_attr.font = g_strdup(DEFAULT_FONT);
2089 axis->labels_attr.height = DEFAULT_FONT_HEIGHT;
2090 axis->labels_attr.fg = black;
2091 axis->labels_attr.bg = white;
2092 axis->labels_attr.transparent = TRUE;
2093 axis->labels_attr.angle = 0;
2094 axis->labels_attr.border = 0;
2095 axis->labels_attr.border_width = 0;
2096 axis->labels_attr.shadow_width = 0;
2097 axis->label_mask = GTK_PLOT_LABEL_OUT;
2098 axis->label_style = GTK_PLOT_LABEL_FLOAT;
2099 axis->label_precision = 1;
2100 axis->labels_attr.justification = GTK_JUSTIFY_CENTER;
2101 axis->labels_prefix = NULL;
2102 axis->labels_suffix = NULL;
2103 axis->title.angle = 0;
2104 axis->title.justification = GTK_JUSTIFY_CENTER;
2105 axis->title.font = g_strdup(DEFAULT_FONT);
2106 axis->title.height = DEFAULT_FONT_HEIGHT;
2107 axis->title.fg = black;
2108 axis->title.bg = white;
2109 axis->title.transparent = TRUE;
2110 axis->title.text = g_strdup("Title");
2111 axis->title.border = 0;
2112 axis->title.border_width = 0;
2113 axis->title.shadow_width = 0;
2114 axis->title_visible = TRUE;
2115
2116 axis->direction.x = 1.;
2117 axis->direction.y = 0.;
2118 axis->direction.z = 0.;
2119
2120 axis->show_major_grid = FALSE;
2121 axis->show_minor_grid = FALSE;
2122
2123 axis->major_grid.line_style = GTK_PLOT_LINE_SOLID;
2124 axis->major_grid.cap_style = 0;
2125 axis->major_grid.join_style = 0;
2126 axis->major_grid.line_width = 0;
2127 axis->major_grid.color = black;
2128
2129 axis->minor_grid.line_style = GTK_PLOT_LINE_DOTTED;
2130 axis->minor_grid.cap_style = 0;
2131 axis->minor_grid.join_style = 0;
2132 axis->minor_grid.line_width = 0;
2133 axis->minor_grid.color = black;
2134
2135 axis->tick_labels = NULL;
2136 }
2137
2138 static void
gtk_plot_axis_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)2139 gtk_plot_axis_set_property (GObject *object,
2140 guint prop_id,
2141 const GValue *value,
2142 GParamSpec *pspec)
2143 {
2144 GtkPlotAxis *axis;
2145 GtkPlotText *text = NULL;
2146
2147 axis = GTK_PLOT_AXIS (object);
2148 switch(prop_id){
2149 case ARG_VISIBLE:
2150 axis->is_visible = g_value_get_boolean(value);
2151 break;
2152 case ARG_TITLE:
2153 text = (GtkPlotText *)g_value_get_pointer(value);
2154 if(axis->title.text) g_free(axis->title.text);
2155 if(axis->title.font) g_free(axis->title.font);
2156 axis->title = *text;
2157 axis->title.text = g_strdup(text->text);
2158 axis->title.font = g_strdup(text->font);
2159 break;
2160 case ARG_TITLE_VISIBLE:
2161 axis->title_visible = g_value_get_boolean(value);
2162 break;
2163 case ARG_ORIENTATION:
2164 axis->orientation = g_value_get_int(value);
2165 break;
2166 case ARG_LINE:
2167 axis->line = *((GtkPlotLine *)g_value_get_pointer(value));
2168 break;
2169 case ARG_MAJOR_GRID:
2170 axis->major_grid = *((GtkPlotLine *)g_value_get_pointer(value));
2171 break;
2172 case ARG_MINOR_GRID:
2173 axis->minor_grid = *((GtkPlotLine *)g_value_get_pointer(value));
2174 break;
2175 case ARG_MAJOR_MASK:
2176 axis->major_mask = g_value_get_int(value);
2177 break;
2178 case ARG_MINOR_MASK:
2179 axis->minor_mask = g_value_get_int(value);
2180 break;
2181 case ARG_TICKS_LENGTH:
2182 axis->ticks_length = g_value_get_int(value);
2183 break;
2184 case ARG_TICKS_WIDTH:
2185 axis->ticks_width = g_value_get_double(value);
2186 break;
2187 case ARG_CUSTOM_LABELS:
2188 axis->custom_labels = g_value_get_boolean(value);
2189 break;
2190 case ARG_LABELS_OFFSET:
2191 axis->labels_offset = g_value_get_int(value);
2192 break;
2193 case ARG_LABELS_PREFIX:
2194 if(axis->labels_prefix) g_free(axis->labels_prefix);
2195 axis->labels_prefix = g_strdup(g_value_get_string(value));
2196 break;
2197 case ARG_LABELS_SUFFIX:
2198 if(axis->labels_suffix) g_free(axis->labels_suffix);
2199 axis->labels_suffix = g_strdup(g_value_get_string(value));
2200 break;
2201 case ARG_SHOW_MAJOR_GRID:
2202 axis->show_major_grid = g_value_get_boolean(value);
2203 break;
2204 case ARG_SHOW_MINOR_GRID:
2205 axis->show_minor_grid = g_value_get_boolean(value);
2206 break;
2207 case ARG_LABELS_ATTR:
2208 text = (GtkPlotText *)g_value_get_pointer(value);
2209 if(axis->labels_attr.text) g_free(axis->labels_attr.text);
2210 if(axis->labels_attr.font) g_free(axis->labels_attr.font);
2211 axis->labels_attr = *text;
2212 axis->labels_attr.text = g_strdup(text->text);
2213 axis->labels_attr.font = g_strdup(text->font);
2214 break;
2215 case ARG_LABELS_PRECISION:
2216 axis->label_precision = g_value_get_int(value);
2217 break;
2218 case ARG_LABELS_STYLE:
2219 axis->label_style = g_value_get_int(value);
2220 break;
2221 case ARG_LABELS_MASK:
2222 axis->label_mask = g_value_get_int(value);
2223 break;
2224 case ARG_TICKS_MIN:
2225 axis->ticks.min = g_value_get_double(value);
2226 break;
2227 case ARG_TICKS_MAX:
2228 axis->ticks.max = g_value_get_double(value);
2229 break;
2230 case ARG_SCALE:
2231 axis->ticks.scale = g_value_get_int(value);
2232 break;
2233 case ARG_NMAJORTICKS:
2234 axis->ticks.nmajorticks = g_value_get_int(value);
2235 break;
2236 case ARG_NMINORTICKS:
2237 axis->ticks.nminorticks = g_value_get_int(value);
2238 break;
2239 case ARG_NTICKS:
2240 axis->ticks.nticks = g_value_get_int(value);
2241 break;
2242 case ARG_STEP:
2243 axis->ticks.step = g_value_get_double(value);
2244 break;
2245 case ARG_NMINOR:
2246 axis->ticks.nminor = g_value_get_int(value);
2247 break;
2248 case ARG_APPLY_BREAK:
2249 axis->ticks.apply_break = g_value_get_boolean(value);
2250 break;
2251 case ARG_BREAK_SCALE:
2252 axis->ticks.break_scale = g_value_get_int(value);
2253 break;
2254 case ARG_BREAK_STEP:
2255 axis->ticks.break_step = g_value_get_double(value);
2256 break;
2257 case ARG_BREAK_NMINOR:
2258 axis->ticks.break_nminor = g_value_get_int(value);
2259 break;
2260 case ARG_BREAK_MIN:
2261 axis->ticks.break_min = g_value_get_double(value);
2262 break;
2263 case ARG_BREAK_MAX:
2264 axis->ticks.break_max = g_value_get_double(value);
2265 break;
2266 case ARG_BREAK_POSITION:
2267 axis->ticks.break_position = g_value_get_double(value);
2268 break;
2269 case ARG_SET_LIMITS:
2270 axis->ticks.set_limits = g_value_get_boolean(value);
2271 break;
2272 case ARG_BEGIN:
2273 axis->ticks.begin = g_value_get_double(value);
2274 break;
2275 case ARG_END:
2276 axis->ticks.end = g_value_get_double(value);
2277 break;
2278 case ARG_TICK_LABELS:
2279 if(g_value_get_object(value))
2280 gtk_plot_axis_set_tick_labels(axis, GTK_PLOT_ARRAY(g_value_get_object(value)));
2281 else
2282 gtk_plot_axis_set_tick_labels(axis, NULL);
2283 break;
2284 default:
2285 break;
2286 }
2287 }
2288
2289 static void
gtk_plot_axis_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)2290 gtk_plot_axis_get_property (GObject *object,
2291 guint prop_id,
2292 GValue *value,
2293 GParamSpec *pspec)
2294 {
2295 GtkPlotAxis *axis;
2296
2297 axis = GTK_PLOT_AXIS (object);
2298 switch(prop_id){
2299 case ARG_VISIBLE:
2300 g_value_set_boolean(value, axis->is_visible);
2301 break;
2302 case ARG_TITLE:
2303 g_value_set_pointer(value, &axis->title);
2304 break;
2305 case ARG_TITLE_VISIBLE:
2306 g_value_set_boolean(value, axis->title_visible);
2307 break;
2308 case ARG_ORIENTATION:
2309 g_value_set_int(value, axis->orientation);
2310 break;
2311 case ARG_LINE:
2312 g_value_set_pointer(value, &axis->line);
2313 break;
2314 case ARG_MAJOR_GRID:
2315 g_value_set_pointer(value, &axis->major_grid);
2316 break;
2317 case ARG_MINOR_GRID:
2318 g_value_set_pointer(value, &axis->minor_grid);
2319 break;
2320 case ARG_MAJOR_MASK:
2321 g_value_set_int(value, axis->major_mask);
2322 break;
2323 case ARG_MINOR_MASK:
2324 g_value_set_int(value, axis->minor_mask);
2325 break;
2326 case ARG_TICKS_LENGTH:
2327 g_value_set_int(value, axis->ticks_length);
2328 break;
2329 case ARG_TICKS_WIDTH:
2330 g_value_set_double(value, axis->ticks_width);
2331 break;
2332 case ARG_CUSTOM_LABELS:
2333 g_value_set_boolean(value, axis->custom_labels);
2334 break;
2335 case ARG_LABELS_OFFSET:
2336 g_value_set_int(value, axis->labels_offset);
2337 break;
2338 case ARG_LABELS_PREFIX:
2339 g_value_set_string(value, axis->labels_prefix);
2340 break;
2341 case ARG_LABELS_SUFFIX:
2342 g_value_set_string(value, axis->labels_suffix);
2343 break;
2344 case ARG_SHOW_MAJOR_GRID:
2345 g_value_set_boolean(value, axis->show_major_grid);
2346 break;
2347 case ARG_SHOW_MINOR_GRID:
2348 g_value_set_boolean(value, axis->show_minor_grid);
2349 break;
2350 case ARG_LABELS_ATTR:
2351 g_value_set_pointer(value, &axis->labels_attr);
2352 break;
2353 case ARG_LABELS_PRECISION:
2354 g_value_set_int(value, axis->label_precision);
2355 break;
2356 case ARG_LABELS_STYLE:
2357 g_value_set_int(value, axis->label_style);
2358 break;
2359 case ARG_LABELS_MASK:
2360 g_value_set_int(value, axis->label_mask);
2361 break;
2362 case ARG_TICKS_MIN:
2363 g_value_set_double(value, axis->ticks.min);
2364 break;
2365 case ARG_TICKS_MAX:
2366 g_value_set_double(value, axis->ticks.max);
2367 break;
2368 case ARG_SCALE:
2369 g_value_set_int(value, axis->ticks.scale);
2370 break;
2371 case ARG_NMAJORTICKS:
2372 g_value_set_int(value, axis->ticks.nmajorticks);
2373 break;
2374 case ARG_NMINORTICKS:
2375 g_value_set_int(value, axis->ticks.nminorticks);
2376 break;
2377 case ARG_NTICKS:
2378 g_value_set_int(value, axis->ticks.nticks);
2379 break;
2380 case ARG_STEP:
2381 g_value_set_double(value, axis->ticks.step);
2382 break;
2383 case ARG_NMINOR:
2384 g_value_set_int(value, axis->ticks.nminor);
2385 break;
2386 case ARG_APPLY_BREAK:
2387 g_value_set_boolean(value, axis->ticks.apply_break);
2388 break;
2389 case ARG_BREAK_SCALE:
2390 g_value_set_int(value, axis->ticks.break_scale);
2391 break;
2392 case ARG_BREAK_STEP:
2393 g_value_set_double(value, axis->ticks.break_step);
2394 break;
2395 case ARG_BREAK_NMINOR:
2396 g_value_set_int(value, axis->ticks.break_nminor);
2397 break;
2398 case ARG_BREAK_MIN:
2399 g_value_set_double(value, axis->ticks.break_min);
2400 break;
2401 case ARG_BREAK_MAX:
2402 g_value_set_double(value, axis->ticks.break_max);
2403 break;
2404 case ARG_BREAK_POSITION:
2405 g_value_set_double(value, axis->ticks.break_position);
2406 break;
2407 case ARG_SET_LIMITS:
2408 g_value_set_boolean(value, axis->ticks.set_limits);
2409 break;
2410 case ARG_BEGIN:
2411 g_value_set_double(value, axis->ticks.begin);
2412 break;
2413 case ARG_END:
2414 g_value_set_double(value, axis->ticks.end);
2415 break;
2416 case ARG_TICK_LABELS:
2417 if(axis->tick_labels)
2418 g_value_set_object(value, axis->tick_labels);
2419 else
2420 g_value_set_object(value, NULL);
2421 break;
2422 default:
2423 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2424 break;
2425 }
2426 }
2427
2428 static void
gtk_plot_destroy(GtkWidget * object)2429 gtk_plot_destroy (GtkWidget *object)
2430 {
2431 GtkPlot *plot;
2432 GList *list;
2433
2434 g_return_if_fail (object != NULL);
2435 g_return_if_fail (GTK_IS_PLOT (object));
2436
2437 plot = GTK_PLOT (object);
2438
2439 if (plot->top)
2440 g_object_unref(plot->top);
2441 if (plot->bottom)
2442 g_object_unref(plot->bottom);
2443 if (plot->left)
2444 g_object_unref(plot->left);
2445 if (plot->right)
2446 g_object_unref(plot->right);
2447 plot->top = plot->bottom = plot->left = plot->right = NULL;
2448
2449 if(plot->legends_attr.font) g_free (plot->legends_attr.font);
2450
2451 plot->legends_attr.font = NULL;
2452
2453 list = plot->text;
2454 while(list){
2455 GtkPlotText *text;
2456
2457 text = (GtkPlotText *) list->data;
2458 if(text->text) g_free(text->text);
2459 if(text->font) g_free(text->font);
2460
2461 g_free(text);
2462 plot->text = g_list_remove_link(plot->text, list);
2463 g_list_free_1(list);
2464 list = plot->text;
2465 }
2466 plot->text = NULL;
2467
2468
2469 list = plot->data_sets;
2470 while(list){
2471 g_object_unref(GTK_WIDGET(list->data));
2472
2473 plot->data_sets = g_list_remove_link(plot->data_sets, list);
2474 g_list_free_1(list);
2475 list = plot->data_sets;
2476 }
2477 plot->data_sets = NULL;
2478
2479 if ( GTK_WIDGET_CLASS (parent_class)->destroy )
2480 (* GTK_WIDGET_CLASS (parent_class)->destroy) (object);
2481
2482 if(plot->pc)
2483 g_object_unref(plot->pc);
2484 plot->pc = NULL;
2485
2486 gtk_psfont_unref();
2487 }
2488
2489 static void
gtk_plot_axis_destroy(GtkWidget * object)2490 gtk_plot_axis_destroy (GtkWidget *object)
2491 {
2492 GtkPlotAxis *axis;
2493
2494 g_return_if_fail (object != NULL);
2495 g_return_if_fail (GTK_IS_PLOT_AXIS (object));
2496
2497 axis = GTK_PLOT_AXIS (object);
2498
2499 if(axis->labels_attr.font) g_free (axis->labels_attr.font);
2500 if(axis->title.font) g_free (axis->title.font);
2501 if(axis->title.text) g_free (axis->title.text);
2502
2503 axis->labels_attr.font = NULL;
2504 axis->title.font = NULL;
2505 axis->title.text = NULL;
2506
2507 if(axis->labels_prefix) g_free(axis->labels_prefix);
2508 if(axis->labels_suffix) g_free(axis->labels_suffix);
2509
2510 if(axis->ticks.values){
2511 g_free (axis->ticks.values);
2512 axis->ticks.values = NULL;
2513 axis->ticks.nticks = 0;
2514 }
2515
2516 if(axis->tick_labels) g_object_unref(G_OBJECT(axis->tick_labels));
2517 axis->tick_labels = NULL;
2518 }
2519
2520 static void
gtk_plot_show_all(GtkWidget * widget)2521 gtk_plot_show_all (GtkWidget *widget)
2522 {
2523 GtkPlot *plot;
2524 GList *list;
2525
2526 g_return_if_fail (widget != NULL);
2527 g_return_if_fail (GTK_IS_PLOT (widget));
2528
2529 plot = GTK_PLOT (widget);
2530
2531 list = plot->data_sets;
2532 while(list)
2533 {
2534 if (GTK_IS_WIDGET (list->data))
2535 gtk_widget_show_all (GTK_WIDGET (list->data));
2536 list = list->next;
2537 }
2538
2539 gtk_widget_show (widget);
2540 }
2541
2542 /**
2543 * gtk_plot_paint:
2544 * @plot: a #GtkPlot widget
2545 *
2546 *
2547 */
2548 void
gtk_plot_paint(GtkPlot * plot)2549 gtk_plot_paint (GtkPlot *plot)
2550 {
2551 if(!plot->drawable) return;
2552
2553 gtk_plot_pc_init(plot->pc);
2554 GTK_PLOT_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(plot)))->plot_paint(GTK_WIDGET(plot));
2555 gtk_plot_pc_leave(plot->pc);
2556 }
2557
2558 static void
gtk_plot_real_paint(GtkWidget * widget)2559 gtk_plot_real_paint (GtkWidget *widget)
2560 {
2561 GtkPlot *plot;
2562 GtkPlotText *child_text;
2563 GList *dataset;
2564 GList *text;
2565 gint width, height;
2566 gint xoffset, yoffset ;
2567
2568 plot = GTK_PLOT(widget);
2569
2570 xoffset = plot->internal_allocation.x;
2571 yoffset = plot->internal_allocation.y;
2572 width = plot->internal_allocation.width;
2573 height = plot->internal_allocation.height;
2574
2575 gtk_plot_pc_gsave(plot->pc);
2576 gtk_plot_pc_set_color(plot->pc, &plot->background);
2577
2578 if(!gtk_plot_is_transparent(plot) && !plot->bg_pixmap)
2579 gtk_plot_pc_draw_rectangle (plot->pc, TRUE,
2580 xoffset, yoffset,
2581 width , height);
2582
2583 if(!gtk_plot_is_transparent(plot) && plot->bg_pixmap){
2584 gint pwidth, pheight;
2585 gdouble scale_x, scale_y;
2586
2587 pwidth = cairo_image_surface_get_width(plot->bg_pixmap);
2588 pheight = cairo_image_surface_get_height(plot->bg_pixmap);
2589
2590 scale_x = (gdouble)width / (gdouble)pwidth;
2591 scale_y = (gdouble)height / (gdouble)pheight;
2592
2593 gtk_plot_pc_draw_pixmap (plot->pc, plot->bg_pixmap, NULL,
2594 0, 0,
2595 xoffset, yoffset,
2596 pwidth , pheight, scale_x, scale_y);
2597 }
2598
2599 /* draw frame to guide the eyes*/
2600 /*
2601 gtk_plot_pc_draw_rectangle (plot->pc, FALSE,
2602 xoffset, yoffset,
2603 width , height);
2604 */
2605
2606 /* draw the ticks & grid lines */
2607
2608 gtk_plot_axis_ticks_recalc(plot->left);
2609 gtk_plot_axis_ticks_recalc(plot->right);
2610 gtk_plot_axis_ticks_recalc(plot->bottom);
2611 gtk_plot_axis_ticks_recalc(plot->top);
2612
2613 if(!plot->grids_on_top)
2614 gtk_plot_draw_grids(plot);
2615 else {
2616 dataset = plot->data_sets;
2617 while(dataset)
2618 {
2619 if(GTK_IS_PLOT_DATA(dataset->data))
2620 gtk_plot_data_paint(GTK_PLOT_DATA(dataset->data));
2621 dataset = dataset->next;
2622 }
2623 }
2624
2625 if(plot->bottom->is_visible)
2626 {
2627 GtkPlotVector tick;
2628 gboolean reflect;
2629
2630 tick.x = 0.;
2631 tick.y = -1.;
2632 plot->bottom->origin.x = plot->xmin;
2633 plot->bottom->origin.y = plot->ymin*(1.0-plot->bottom_align) +
2634 plot->ymax*plot->bottom_align;
2635 reflect = plot->reflect_y;
2636 plot->reflect_y = FALSE;
2637 gtk_plot_draw_axis(plot, plot->bottom, tick);
2638 gtk_plot_draw_labels(plot, plot->bottom, tick);
2639 plot->reflect_y = reflect;
2640 }
2641
2642 if(plot->top->is_visible)
2643 {
2644 GtkPlotVector tick;
2645 gboolean reflect;
2646
2647 tick.x = 0.;
2648 tick.y = 1.;
2649 plot->top->origin.x = plot->xmin;
2650 plot->top->origin.y = plot->ymin*(1.0-plot->top_align) +
2651 plot->ymax*plot->top_align;
2652 reflect = plot->reflect_y;
2653 plot->reflect_y = FALSE;
2654 gtk_plot_draw_axis(plot, plot->top, tick);
2655 gtk_plot_draw_labels(plot, plot->top, tick);
2656 plot->reflect_y = reflect;
2657 }
2658
2659 if(plot->left->is_visible)
2660 {
2661 GtkPlotVector tick;
2662 gboolean reflect;
2663
2664 tick.x = 1.;
2665 tick.y = 0.;
2666 plot->left->origin.x = plot->xmin*(1.0-plot->left_align) +
2667 plot->xmax*plot->left_align;
2668 plot->left->origin.y = plot->ymin;
2669 reflect = plot->reflect_x;
2670 plot->reflect_x = FALSE;
2671 gtk_plot_draw_axis(plot, plot->left, tick);
2672 gtk_plot_draw_labels(plot, plot->left, tick);
2673 plot->reflect_x = reflect;
2674 }
2675
2676 if(plot->right->is_visible)
2677 {
2678 GtkPlotVector tick;
2679 gboolean reflect;
2680
2681 tick.x = -1.;
2682 tick.y = 0.;
2683 plot->right->origin.x = plot->xmin*(1.0-plot->right_align) +
2684 plot->xmax*plot->right_align;
2685 plot->right->origin.y = plot->ymin;
2686 reflect = plot->reflect_x;
2687 plot->reflect_x = FALSE;
2688 gtk_plot_draw_axis(plot, plot->right, tick);
2689 gtk_plot_draw_labels(plot, plot->right, tick);
2690 plot->reflect_x = reflect;
2691 }
2692
2693 if(plot->grids_on_top)
2694 gtk_plot_draw_grids(plot);
2695 else {
2696 dataset = plot->data_sets;
2697 while(dataset)
2698 {
2699 if(GTK_IS_PLOT_DATA(dataset->data))
2700 gtk_plot_data_paint(GTK_PLOT_DATA(dataset->data));
2701 dataset = dataset->next;
2702 }
2703 }
2704
2705
2706 text = plot->text;
2707 while(text)
2708 {
2709 child_text = (GtkPlotText *) text->data;
2710 gtk_plot_draw_text(plot, *child_text);
2711 text = text->next;
2712 }
2713
2714 GTK_PLOT_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(plot)))->draw_legends(GTK_WIDGET(plot));
2715
2716 gtk_plot_pc_grestore(plot->pc);
2717 }
2718
2719 static void
gtk_plot_get_preferred_width(GtkWidget * widget,gint * min,gint * nat)2720 gtk_plot_get_preferred_width (GtkWidget *widget, gint *min, gint *nat)
2721 {
2722 *min = *nat = DEFAULT_WIDTH;
2723 }
2724
2725 static void
gtk_plot_get_preferred_height(GtkWidget * widget,gint * min,gint * nat)2726 gtk_plot_get_preferred_height (GtkWidget *widget, gint *min, gint *nat)
2727 {
2728 *min = *nat = DEFAULT_HEIGHT;
2729 }
2730
2731 static void
gtk_plot_size_allocate(GtkWidget * widget,GtkAllocation * arg_allocation)2732 gtk_plot_size_allocate (GtkWidget *widget, GtkAllocation *arg_allocation)
2733 {
2734 GtkPlot *plot;
2735 GtkAllocation allocation;
2736
2737 plot = GTK_PLOT(widget);
2738
2739 gtk_widget_set_allocation(widget, arg_allocation);
2740
2741 gtk_widget_get_allocation(GTK_WIDGET(plot), &allocation);
2742 plot->internal_allocation.x = allocation.x + roundint(plot->x * allocation.width);
2743 plot->internal_allocation.y = allocation.y + roundint(plot->y * allocation.height);
2744 plot->internal_allocation.width = roundint(plot->width * allocation.width);
2745 plot->internal_allocation.height = roundint(plot->height * allocation.height);
2746
2747 g_signal_emit (plot, plot_signals[UPDATE], 0, FALSE);
2748 }
2749
2750 /**
2751 * gtk_plot_axis_new:
2752 * @orientation:
2753 *
2754 *
2755 *
2756 * Return value:
2757 */
2758 GtkWidget*
gtk_plot_axis_new(GtkPlotOrientation orientation)2759 gtk_plot_axis_new (GtkPlotOrientation orientation)
2760 {
2761 GtkWidget *axis;
2762
2763 axis = g_object_new (gtk_plot_axis_get_type (), NULL);
2764
2765 gtk_plot_axis_construct(GTK_PLOT_AXIS(axis), orientation);
2766
2767 return axis;
2768 }
2769
2770 /**
2771 * gtk_plot_axis_construct:
2772 * @axis:
2773 * @orientation:
2774 *
2775 *
2776 */
2777 void
gtk_plot_axis_construct(GtkPlotAxis * axis,GtkPlotOrientation orientation)2778 gtk_plot_axis_construct(GtkPlotAxis *axis, GtkPlotOrientation orientation)
2779 {
2780 axis->orientation = orientation;
2781
2782 axis->title.border = GTK_PLOT_BORDER_NONE;
2783 axis->title.border_width = 0;
2784 axis->title.border_space = 2;
2785 axis->title.shadow_width = 3;
2786 axis->ticks.values = NULL;
2787 axis->ticks.nticks = 0;
2788
2789 axis->ticks_transform = gtk_plot_ticks_transform;
2790 axis->ticks_inverse = gtk_plot_ticks_inverse;
2791 axis->ticks_recalc = gtk_plot_ticks_recalc;
2792 axis->ticks_autoscale = gtk_plot_ticks_autoscale;
2793 axis->parse_label = gtk_plot_parse_label;
2794
2795 switch(orientation){
2796 case GTK_PLOT_AXIS_X:
2797 axis->direction.x = 1.0;
2798 axis->direction.y = 0.0;
2799 axis->direction.z = 0.0;
2800 g_free(axis->title.text);
2801 axis->title.text = g_strdup("X Title");
2802 axis->title.angle = 0;
2803 break;
2804 case GTK_PLOT_AXIS_Y:
2805 axis->direction.x = 0.0;
2806 axis->direction.y = -1.0;
2807 axis->direction.z = 0.0;
2808 g_free(axis->title.text);
2809 axis->title.text = g_strdup("Y Title");
2810 axis->title.angle = 90;
2811 break;
2812 case GTK_PLOT_AXIS_Z:
2813 axis->direction.x = 0.0;
2814 axis->direction.y = 0.0;
2815 axis->direction.z = 1.0;
2816 g_free(axis->title.text);
2817 axis->title.text = g_strdup("Z Title");
2818 axis->title.angle = 0;
2819 break;
2820 default:
2821 break;
2822 }
2823 }
2824
2825 /**
2826 * gtk_plot_new:
2827 * @drawable: a Gdk drawable
2828 *
2829 *
2830 *
2831 * Return value:
2832 */
2833 GtkWidget*
gtk_plot_new(cairo_surface_t * drawable)2834 gtk_plot_new (cairo_surface_t *drawable)
2835 {
2836 GtkWidget *plot;
2837
2838 plot = gtk_widget_new (gtk_plot_get_type (), NULL);
2839
2840 gtk_plot_construct(GTK_PLOT(plot), drawable);
2841
2842 return GTK_WIDGET (plot);
2843 }
2844
2845 /**
2846 * gtk_plot_construct:
2847 * @plot: a #GtkPlot widget
2848 * @drawable: a Gdk drawable
2849 *
2850 *
2851 */
2852 void
gtk_plot_construct(GtkPlot * plot,cairo_surface_t * drawable)2853 gtk_plot_construct(GtkPlot *plot, cairo_surface_t *drawable)
2854 {
2855 GtkAllocation allocation;
2856 gtk_plot_set_drawable(plot, drawable);
2857
2858 plot->x = .15;
2859 plot->y = .1;
2860 plot->width = .6;
2861 plot->height = .6;
2862
2863 gtk_widget_get_allocation(GTK_WIDGET(plot), &allocation);
2864 plot->internal_allocation.x = allocation.x + roundint(plot->x * allocation.width);
2865 plot->internal_allocation.y = allocation.y + roundint(plot->y * allocation.height);
2866 plot->internal_allocation.width = roundint(plot->width * allocation.width);
2867 plot->internal_allocation.height = roundint(plot->height * allocation.height);
2868
2869 plot->left->title.x = plot->x;
2870 plot->left->title.y = plot->y + plot->height / 2.;
2871 plot->right->title.x = plot->x + plot->width;
2872 plot->right->title.y = plot->y + plot->height / 2.;
2873 plot->top->title.x = plot->x + plot->width / 2.;
2874 plot->top->title.y = plot->y;
2875 plot->bottom->title.x = plot->x + plot->width / 2.;
2876 plot->bottom->title.y = plot->y + plot->height;
2877
2878 plot->left->title.x -= 45. / (gdouble)DEFAULT_WIDTH;
2879 plot->right->title.x += 45. / (gdouble)DEFAULT_WIDTH;
2880 plot->top->title.y -= 35. / (gdouble)DEFAULT_HEIGHT;
2881 plot->bottom->title.y += 35. / (gdouble)DEFAULT_HEIGHT;
2882 }
2883
2884 /**
2885 * gtk_plot_new_with_size:
2886 * @drawable: a Gdk drawable
2887 * @width: plot widget width
2888 * @height: plot widget height
2889 *
2890 * Returns: the plot widget
2891 */
2892 GtkWidget*
gtk_plot_new_with_size(cairo_surface_t * drawable,gdouble width,gdouble height)2893 gtk_plot_new_with_size (cairo_surface_t *drawable, gdouble width, gdouble height)
2894 {
2895 GtkWidget *plot;
2896
2897 plot = gtk_widget_new (gtk_plot_get_type (), NULL);
2898
2899 gtk_plot_construct_with_size(GTK_PLOT(plot), drawable, width, height);
2900
2901 return(plot);
2902 }
2903
2904 /**
2905 * gtk_plot_construct_with_size:
2906 * @plot: a #GtkPlot widget
2907 * @drawable: a Gdk drawable
2908 * @width:
2909 * @height:
2910 *
2911 *
2912 */
2913 void
gtk_plot_construct_with_size(GtkPlot * plot,cairo_surface_t * drawable,gdouble width,gdouble height)2914 gtk_plot_construct_with_size (GtkPlot *plot,
2915 cairo_surface_t *drawable,
2916 gdouble width, gdouble height)
2917 {
2918 gtk_plot_construct(plot, drawable);
2919
2920 gtk_plot_resize (GTK_PLOT(plot), width, height);
2921 }
2922
2923 /**
2924 * gtk_plot_set_drawable:
2925 * @plot: a #GtkPlot widget
2926 * @drawable: a Gdk drawable
2927 *
2928 *
2929 */
2930 void
gtk_plot_set_drawable(GtkPlot * plot,cairo_surface_t * drawable)2931 gtk_plot_set_drawable (GtkPlot *plot, cairo_surface_t *drawable)
2932 {
2933 GTK_PLOT_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(plot)))->set_drawable(plot, drawable);
2934 }
2935
2936 static void
gtk_plot_real_set_drawable(GtkPlot * plot,cairo_surface_t * drawable)2937 gtk_plot_real_set_drawable (GtkPlot *plot, cairo_surface_t *drawable)
2938 {
2939 plot->drawable = drawable;
2940
2941 if(GTK_IS_PLOT_CAIRO(plot->pc)) {
2942 if (gtk_widget_get_window(GTK_WIDGET(plot))) {
2943 gtk_plot_set_pc(plot,GTK_PLOT_PC(gtk_plot_cairo_new_with_drawable(drawable)));
2944 }
2945 }
2946
2947 }
2948
2949 /**
2950 * gtk_plot_get_drawable:
2951 * @plot: a #GtkPlot widget
2952 *
2953 * Return value: (transfer none) the #GdkDrawable of the plot
2954 */
2955 cairo_surface_t *
gtk_plot_get_drawable(GtkPlot * plot)2956 gtk_plot_get_drawable (GtkPlot *plot)
2957 {
2958 return(plot->drawable);
2959 }
2960
2961 /**
2962 * gtk_plot_set_background_pixmap:
2963 * @plot: a #GtkPlot widget
2964 * @pixmap: a Gdk pixmap
2965 *
2966 *
2967 */
2968 void
gtk_plot_set_background_pixmap(GtkPlot * plot,cairo_surface_t * pixmap)2969 gtk_plot_set_background_pixmap (GtkPlot *plot, cairo_surface_t *pixmap)
2970 {
2971 if(plot->bg_pixmap) cairo_surface_destroy(plot->bg_pixmap);
2972
2973 plot->bg_pixmap = pixmap;
2974 if(pixmap) cairo_surface_reference(pixmap);
2975 }
2976
2977 /**
2978 * gtk_plot_set_transparent:
2979 * @plot: a #GtkPlot widget
2980 * @transparent:
2981 *
2982 *
2983 */
2984 void
gtk_plot_set_transparent(GtkPlot * plot,gboolean transparent)2985 gtk_plot_set_transparent (GtkPlot *plot, gboolean transparent)
2986 {
2987 plot->transparent = transparent;
2988 }
2989
2990 /**
2991 * gtk_plot_is_transparent:
2992 * @plot: a #GtkPlot widget
2993 *
2994 *
2995 *
2996 * Return value:
2997 */
2998 gboolean
gtk_plot_is_transparent(GtkPlot * plot)2999 gtk_plot_is_transparent (GtkPlot *plot)
3000 {
3001 return(plot->transparent);
3002 }
3003
3004 static void
gtk_plot_draw_grids(GtkPlot * plot)3005 gtk_plot_draw_grids(GtkPlot *plot)
3006 {
3007 GdkRectangle clip_area;
3008 gdouble width, height;
3009 gdouble xp, yp;
3010 gdouble x1, y1, x2, y2;
3011 gdouble xx, yy;
3012 gdouble x_tick;
3013 gint ntick;
3014
3015 xp = plot->internal_allocation.x;
3016 yp = plot->internal_allocation.y;
3017 width = plot->internal_allocation.width;
3018 height = plot->internal_allocation.height;
3019
3020 clip_area.x = xp;
3021 clip_area.y = yp;
3022 clip_area.width = width;
3023 clip_area.height = height;
3024
3025 gtk_plot_pc_clip(plot->pc, &clip_area);
3026
3027 if(plot->show_x0)
3028 {
3029 if(plot->xmin <= 0. && plot->xmax >= 0.)
3030 {
3031 gtk_plot_get_pixel(plot, 0., plot->ymin, &x1, &y1);
3032 gtk_plot_get_pixel(plot, 0., plot->ymax, &x2, &y2);
3033 gtk_plot_draw_line(plot, plot->x0_line,
3034 x1, y1, x2, y2);
3035 }
3036 }
3037
3038 if(plot->show_y0)
3039 {
3040 if(plot->ymin <= 0. && plot->ymax >= 0.)
3041 {
3042 gtk_plot_get_pixel(plot, plot->xmin, 0., &x1, &y1);
3043 gtk_plot_get_pixel(plot, plot->xmax, 0., &x2, &y2);
3044 gtk_plot_draw_line(plot, plot->y0_line,
3045 x1, y1, x2, y2);
3046 }
3047 }
3048
3049 if(plot->bottom->show_minor_grid)
3050 {
3051 for(ntick = 0; ntick < plot->bottom->ticks.nticks; ntick++){
3052 if(!plot->bottom->ticks.values[ntick].minor) continue;
3053 if(plot->bottom->ticks.values[ntick].value >= plot->bottom->ticks.min){
3054 x_tick = plot->bottom->ticks.values[ntick].value;
3055 xx = x_tick;
3056 yy = plot->ymin;
3057 gtk_plot_get_pixel(plot, xx, yy, &x1, &y1);
3058 xx = x_tick;
3059 yy = plot->ymax;
3060 gtk_plot_get_pixel(plot, xx, yy, &x2, &y2);
3061 gtk_plot_draw_line(plot, plot->bottom->minor_grid,
3062 x1, y1, x2, y2);
3063 }
3064 }
3065 }
3066
3067 if(plot->bottom->show_major_grid)
3068 {
3069 for(ntick = 0; ntick < plot->bottom->ticks.nticks; ntick++){
3070 if(plot->bottom->ticks.values[ntick].minor) continue;
3071 if(plot->bottom->ticks.values[ntick].value >= plot->bottom->ticks.min){
3072 x_tick = plot->bottom->ticks.values[ntick].value;
3073 xx = x_tick;
3074 yy = plot->ymin;
3075 gtk_plot_get_pixel(plot, xx, yy, &x1, &y1);
3076 xx = x_tick;
3077 yy = plot->ymax;
3078 gtk_plot_get_pixel(plot, xx, yy, &x2, &y2);
3079 gtk_plot_draw_line(plot, plot->bottom->major_grid,
3080 x1, y1, x2, y2);
3081 }
3082 }
3083 }
3084
3085 if(plot->left->show_minor_grid)
3086 {
3087 for(ntick = 0; ntick < plot->left->ticks.nticks; ntick++){
3088 if(!plot->left->ticks.values[ntick].minor) continue;
3089 if(plot->left->ticks.values[ntick].value >= plot->left->ticks.min){
3090 x_tick = plot->left->ticks.values[ntick].value;
3091 xx = plot->xmin;
3092 yy = x_tick;
3093 gtk_plot_get_pixel(plot, xx, yy, &x1, &y1);
3094 xx = plot->xmax;
3095 yy = x_tick;
3096 gtk_plot_get_pixel(plot, xx, yy, &x2, &y2);
3097 gtk_plot_draw_line(plot, plot->left->minor_grid,
3098 x1, y1, x2, y2);
3099 }
3100 }
3101 }
3102
3103 if(plot->left->show_major_grid)
3104 {
3105 for(ntick = 0; ntick < plot->left->ticks.nticks; ntick++){
3106 if(plot->left->ticks.values[ntick].minor) continue;
3107 if(plot->left->ticks.values[ntick].value >= plot->left->ticks.min){
3108 x_tick = plot->left->ticks.values[ntick].value;
3109 xx = plot->xmin;
3110 yy = x_tick;
3111 gtk_plot_get_pixel(plot, xx, yy, &x1, &y1);
3112 xx = plot->xmax;
3113 yy = x_tick;
3114 gtk_plot_get_pixel(plot, xx, yy, &x2, &y2);
3115 gtk_plot_draw_line(plot, plot->left->major_grid,
3116 x1, y1, x2, y2);
3117 }
3118 }
3119 }
3120
3121 gtk_plot_pc_clip(plot->pc, NULL);
3122 }
3123
3124 static void
gtk_plot_draw_axis(GtkPlot * plot,GtkPlotAxis * axis,GtkPlotVector tick_direction)3125 gtk_plot_draw_axis(GtkPlot *plot, GtkPlotAxis *axis, GtkPlotVector tick_direction)
3126 {
3127 gdouble x_tick;
3128 gint ntick;
3129 gdouble m = plot->magnification;
3130 gdouble x1, y1, x2, y2;
3131 gdouble px, py;
3132 gdouble xx, yy;
3133
3134 gtk_plot_get_pixel(plot, axis->origin.x, axis->origin.y, &x1, &y1);
3135
3136 if(axis->ticks.apply_break){
3137 gdouble l = m * axis->ticks_length;
3138
3139 gtk_plot_get_pixel(plot,
3140 axis->origin.x+axis->direction.x*(axis->ticks.break_min-axis->ticks.min),
3141 axis->origin.y-axis->direction.y*(axis->ticks.break_min-axis->ticks.min),
3142 &x2, &y2);
3143 gtk_plot_draw_line(plot, axis->line, x1, y1, x2, y2);
3144 x1 = x2 + axis->direction.x * 6 * m;
3145 y1 = y2 + axis->direction.y * 6 * m;
3146 gtk_plot_draw_line(plot, axis->line,
3147 x1 - axis->direction.y * l + axis->direction.x * l/2,
3148 y1 - axis->direction.x * l + axis->direction.y * l/2,
3149 x1 + axis->direction.y * l - axis->direction.x * l/2,
3150 y1 + axis->direction.x * l - axis->direction.y * l/2);
3151 gtk_plot_draw_line(plot, axis->line,
3152 x2 - axis->direction.y * l + axis->direction.x * l/2,
3153 y2 - axis->direction.x * l + axis->direction.y * l/2,
3154 x2 + axis->direction.y * l - axis->direction.x * l/2,
3155 y2 + axis->direction.x * l - axis->direction.y * l/2);
3156 gtk_plot_get_pixel(plot,
3157 axis->origin.x+axis->direction.x*(axis->ticks.max-axis->ticks.min),
3158 axis->origin.y-axis->direction.y*(axis->ticks.max-axis->ticks.min),
3159 &x2, &y2);
3160 gtk_plot_draw_line(plot, axis->line, x1, y1, x2, y2);
3161
3162 } else {
3163 gtk_plot_get_pixel(plot,
3164 axis->origin.x+axis->direction.x*(axis->ticks.max-axis->ticks.min),
3165 axis->origin.y-axis->direction.y*(axis->ticks.max-axis->ticks.min),
3166 &x2, &y2);
3167
3168 gtk_plot_draw_line(plot, axis->line, x1, y1, x2, y2);
3169 }
3170
3171 if(!axis->ticks.values) return;
3172
3173 gtk_plot_pc_set_lineattr(plot->pc, axis->ticks_width, 0, 1, 0);
3174
3175 for(ntick = 0; ntick < axis->ticks.nticks; ntick++){
3176 GtkPlotTick tick = axis->ticks.values[ntick];
3177 x_tick = tick.value;
3178 xx = -axis->direction.y * axis->origin.x + x_tick * axis->direction.x;
3179 yy = axis->direction.x * axis->origin.y - x_tick * axis->direction.y;
3180 gtk_plot_get_pixel(plot, xx, yy, &px, &py);
3181 if(!tick.minor && x_tick >= axis->ticks.min){
3182 if(axis->major_mask & GTK_PLOT_TICKS_IN)
3183 gtk_plot_pc_draw_line(plot->pc,
3184 px,
3185 py,
3186 px + tick_direction.x * m * axis->ticks_length,
3187 py + tick_direction.y * m * axis->ticks_length);
3188 if(axis->major_mask & GTK_PLOT_TICKS_OUT)
3189 gtk_plot_pc_draw_line(plot->pc,
3190 px,
3191 py,
3192 px - tick_direction.x * m * axis->ticks_length,
3193 py - tick_direction.y * m * axis->ticks_length);
3194 }
3195 if(tick.minor && x_tick >= axis->ticks.min){
3196 if(axis->minor_mask & GTK_PLOT_TICKS_IN)
3197 gtk_plot_pc_draw_line(plot->pc,
3198 px,
3199 py,
3200 px + tick_direction.x * m * axis->ticks_length/2.,
3201 py + tick_direction.y * m * axis->ticks_length/2.);
3202 if(axis->minor_mask & GTK_PLOT_TICKS_OUT)
3203 gtk_plot_pc_draw_line(plot->pc,
3204 px,
3205 py,
3206 px - tick_direction.x * m * axis->ticks_length/2.,
3207 py - tick_direction.y * m * axis->ticks_length/2.);
3208 }
3209 }
3210 }
3211
3212
3213 static void
gtk_plot_draw_labels(GtkPlot * plot,GtkPlotAxis * axis,GtkPlotVector tick_direction)3214 gtk_plot_draw_labels(GtkPlot *plot,
3215 GtkPlotAxis *axis,
3216 GtkPlotVector tick_direction)
3217 {
3218 GtkWidget *widget;
3219 GtkPlotText title, tick;
3220 gchar label[LABEL_MAX_LENGTH], new_label[LABEL_MAX_LENGTH];
3221 gdouble x_tick;
3222 gdouble xx, yy;
3223 gint text_height;
3224 gint ntick;
3225 gdouble m = plot->magnification;
3226 gboolean veto = FALSE;
3227 gdouble px, py;
3228 gdouble y;
3229 gint n = 0;
3230 GtkAllocation allocation;
3231
3232 widget = GTK_WIDGET(plot);
3233
3234 gtk_plot_pc_set_color (plot->pc, &axis->labels_attr.fg);
3235
3236 text_height = roundint(axis->labels_attr.height*m);
3237
3238 y = 0.0;
3239 switch(axis->labels_attr.angle){
3240 case 0:
3241 y += text_height / 2.;
3242 break;
3243 case 90:
3244 break;
3245 case 180:
3246 y -= text_height / 2.;
3247 break;
3248 case 270:
3249 break;
3250 default:
3251 break;
3252 }
3253
3254 if(axis->ticks.values) {
3255
3256 tick = axis->labels_attr;
3257 for(ntick = 0; ntick < axis->ticks.nticks; ntick++){
3258 if(axis->ticks.values[ntick].minor) continue;
3259 x_tick = axis->ticks.values[ntick].value;
3260 xx = -axis->direction.y * axis->origin.x + x_tick * axis->direction.x;
3261 yy = axis->direction.x * axis->origin.y - x_tick * axis->direction.y;
3262 gtk_plot_get_pixel(plot, xx, yy, &px, &py);
3263 if(x_tick >= axis->ticks.min-1.e-9){
3264 if(!axis->custom_labels){
3265 gtk_plot_axis_parse_label(axis, x_tick, axis->label_precision, axis->label_style, label);
3266 }
3267 else
3268 {
3269 veto = FALSE;
3270 _gtkextra_signal_emit(G_OBJECT(axis), axis_signals[TICK_LABEL],
3271 &x_tick, label, &veto);
3272 if(!veto) {
3273 if(axis->tick_labels){
3274 gchar **array;
3275 array = gtk_plot_array_get_string(axis->tick_labels);
3276 if(array && n < gtk_plot_array_get_size(axis->tick_labels) && array[n]) {
3277 g_snprintf(label, LABEL_MAX_LENGTH, "%s", array[n++]);
3278 } else {
3279 g_snprintf(label, LABEL_MAX_LENGTH, " ");
3280 }
3281 } else {
3282 gtk_plot_axis_parse_label(axis, x_tick, axis->label_precision, axis->label_style, label);
3283 }
3284 }
3285 }
3286
3287 if(axis->labels_prefix){
3288 g_snprintf(new_label, LABEL_MAX_LENGTH, "%s%s", axis->labels_prefix, label);
3289 g_snprintf(label, LABEL_MAX_LENGTH, "%s", new_label);
3290 }
3291 if(axis->labels_suffix){
3292 g_snprintf(new_label, LABEL_MAX_LENGTH, "%s%s", label, axis->labels_suffix);
3293 g_snprintf(label, LABEL_MAX_LENGTH, "%s", new_label);
3294 }
3295
3296 tick.text = label;
3297 tick.x = px;
3298 tick.y = py + y;
3299
3300 gtk_widget_get_allocation(widget, &allocation);
3301 if(axis->label_mask & GTK_PLOT_LABEL_IN){
3302 tick.x = tick.x + tick_direction.x*roundint(axis->labels_offset * m);
3303 tick.y = tick.y + tick_direction.y*roundint(axis->labels_offset * m);
3304 tick.x = (gdouble)tick.x / (gdouble)allocation.width;
3305 tick.y = (gdouble)tick.y / (gdouble)allocation.height;
3306 gtk_plot_draw_text(plot, tick);
3307 }
3308 if(axis->label_mask & GTK_PLOT_LABEL_OUT){
3309 tick.x = tick.x - tick_direction.x*roundint(axis->labels_offset * m);
3310 tick.y = tick.y - tick_direction.y*roundint(axis->labels_offset * m);
3311 tick.x = (gdouble)tick.x / (gdouble)allocation.width;
3312 tick.y = (gdouble)tick.y / (gdouble)allocation.height;
3313 gtk_plot_draw_text(plot, tick);
3314 }
3315 }
3316 }
3317 }
3318
3319 if(axis->title_visible && axis->title.text)
3320 {
3321 title = axis->title;
3322 gtk_plot_draw_text(plot, title);
3323 }
3324 }
3325
3326 /**
3327 * gtk_plot_draw_line:
3328 * @plot: a #GtkPlot widget
3329 * @line:
3330 * @x1:
3331 * @y1:
3332 * @x2:
3333 * @y2:
3334 *
3335 *
3336 */
3337 void
gtk_plot_draw_line(GtkPlot * plot,GtkPlotLine line,gdouble x1,gdouble y1,gdouble x2,gdouble y2)3338 gtk_plot_draw_line(GtkPlot *plot,
3339 GtkPlotLine line,
3340 gdouble x1, gdouble y1, gdouble x2, gdouble y2)
3341 {
3342
3343 if(line.line_style == GTK_PLOT_LINE_NONE) return;
3344
3345
3346 gtk_plot_set_line_attributes(plot, line);
3347
3348 gtk_plot_pc_draw_line(plot->pc, x1, y1, x2, y2);
3349
3350 }
3351
3352 /**
3353 * gtk_plot_set_line_attributes:
3354 * @plot: a #GtkPlot widget
3355 * @line:
3356 *
3357 *
3358 */
3359 void
gtk_plot_set_line_attributes(GtkPlot * plot,GtkPlotLine line)3360 gtk_plot_set_line_attributes(GtkPlot *plot,
3361 GtkPlotLine line)
3362 {
3363 gdouble dot[] = {2., 3.};
3364 gdouble dash[] = {6., 4.};
3365 gdouble dot_dash[] = {6., 4., 2., 4.};
3366 gdouble dot_dot_dash[] = {6., 4., 2., 4., 2., 4.};
3367 gdouble dot_dash_dash[] = {6., 4., 6., 4., 2., 4.};
3368
3369 gtk_plot_pc_set_color (plot->pc, &line.color);
3370
3371 switch(line.line_style){
3372 case GTK_PLOT_LINE_SOLID:
3373 gtk_plot_pc_set_lineattr(plot->pc, line.line_width, 0,
3374 line.cap_style, line.join_style);
3375 gtk_plot_pc_set_dash(plot->pc, 0, 0, 0);
3376 break;
3377 case GTK_PLOT_LINE_DOTTED:
3378 gtk_plot_pc_set_lineattr(plot->pc, line.line_width,
3379 1,
3380 line.cap_style, line.join_style);
3381 gtk_plot_pc_set_dash(plot->pc, 0, dot, 2);
3382 break;
3383 case GTK_PLOT_LINE_DASHED:
3384 gtk_plot_pc_set_lineattr(plot->pc, line.line_width,
3385 1,
3386 line.cap_style, line.join_style);
3387 gtk_plot_pc_set_dash(plot->pc, 0, dash, 2);
3388 break;
3389 case GTK_PLOT_LINE_DOT_DASH:
3390 gtk_plot_pc_set_lineattr(plot->pc, line.line_width,
3391 1,
3392 line.cap_style, line.join_style);
3393 gtk_plot_pc_set_dash(plot->pc, 0, dot_dash, 4);
3394 break;
3395 case GTK_PLOT_LINE_DOT_DOT_DASH:
3396 gtk_plot_pc_set_lineattr(plot->pc, line.line_width,
3397 1,
3398 line.cap_style, line.join_style);
3399 gtk_plot_pc_set_dash(plot->pc, 0, dot_dot_dash, 6);
3400 break;
3401 case GTK_PLOT_LINE_DOT_DASH_DASH:
3402 gtk_plot_pc_set_lineattr(plot->pc, line.line_width,
3403 1,
3404 line.cap_style, line.join_style);
3405 gtk_plot_pc_set_dash(plot->pc, 0, dot_dash_dash, 6);
3406 break;
3407 case GTK_PLOT_LINE_NONE:
3408 default:
3409 break;
3410 }
3411 }
3412
3413 static void
gtk_plot_draw_legends(GtkWidget * widget)3414 gtk_plot_draw_legends (GtkWidget *widget)
3415 {
3416 GtkPlot *plot;
3417 GList *datasets;
3418 GtkPlotData *dataset;
3419 GtkAllocation legend_area;
3420 gint x, y;
3421 gint height;
3422 gint lwidth, lheight;
3423 gdouble m;
3424
3425 plot = GTK_PLOT(widget);
3426
3427 if(plot->show_legends){
3428
3429 m = plot->magnification;
3430 gtk_plot_pc_gsave(plot->pc);
3431
3432 /* first draw the white rectangle for the background */
3433 legend_area = gtk_plot_legends_get_allocation(plot);
3434
3435 if(!plot->legends_attr.transparent){
3436 gtk_plot_pc_set_color(plot->pc, &plot->legends_attr.bg);
3437 gtk_plot_pc_draw_rectangle(plot->pc,
3438 TRUE,
3439 legend_area.x, legend_area.y,
3440 legend_area.width, legend_area.height);
3441 }
3442
3443 plot->legends_width = legend_area.width;
3444 plot->legends_height = legend_area.height;
3445
3446 /* now draw the legends */
3447
3448 height = roundint(4 * m);
3449 y = legend_area.y + height;
3450 x = legend_area.x + roundint(4 * m);
3451
3452 datasets = plot->data_sets;
3453 while(datasets)
3454 {
3455 dataset = GTK_PLOT_DATA(datasets->data);
3456
3457 if(gtk_widget_get_visible(GTK_WIDGET(dataset)) && dataset->show_legend)
3458 {
3459 GTK_PLOT_DATA_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(dataset)))->get_legend_size(dataset, &lwidth, &lheight);
3460 GTK_PLOT_DATA_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(dataset)))->draw_legend(dataset, x, y);
3461 y += lheight;
3462 height += lheight;
3463 }
3464 datasets=datasets->next;
3465 }
3466
3467 gtk_plot_pc_set_lineattr(plot->pc, plot->legends_border_width, 0, 0, 0);
3468 gtk_plot_pc_set_color(plot->pc, &plot->legends_attr.fg);
3469 gtk_plot_pc_set_dash(plot->pc, 0, 0, 0);
3470
3471 if(plot->legends_border != GTK_PLOT_BORDER_NONE)
3472 {
3473 gtk_plot_pc_draw_rectangle(plot->pc,
3474 FALSE,
3475 legend_area.x, legend_area.y,
3476 legend_area.width, legend_area.height);
3477 }
3478
3479 gtk_plot_pc_set_lineattr(plot->pc, 0, 0, 0, 0);
3480 if(plot->legends_border == GTK_PLOT_BORDER_SHADOW)
3481 {
3482 gtk_plot_pc_draw_rectangle(plot->pc,
3483 TRUE,
3484 legend_area.x + roundint(plot->legends_shadow_width * m),
3485 legend_area.y + legend_area.height,
3486 legend_area.width,
3487 roundint(plot->legends_shadow_width * m));
3488 gtk_plot_pc_draw_rectangle(plot->pc,
3489 TRUE,
3490 legend_area.x + legend_area.width,
3491 legend_area.y + roundint(plot->legends_shadow_width * m),
3492 roundint(plot->legends_shadow_width * m),
3493 legend_area.height);
3494 }
3495 gtk_plot_pc_grestore(plot->pc);
3496 }
3497
3498 datasets = plot->data_sets;
3499 while(datasets)
3500 {
3501 dataset = GTK_PLOT_DATA(datasets->data);
3502
3503 if(gtk_widget_get_visible(GTK_WIDGET(dataset)) && dataset->show_gradient)
3504 {
3505 GTK_PLOT_DATA_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(dataset)))->draw_gradient(dataset);
3506 }
3507 datasets=datasets->next;
3508 }
3509
3510 }
3511
3512 void
gtk_plot_axis_ticks_recalc(GtkPlotAxis * axis)3513 gtk_plot_axis_ticks_recalc (GtkPlotAxis *axis)
3514 {
3515 if ( ! axis->frozen)
3516 axis->ticks_recalc(axis);
3517 }
3518
3519 void
gtk_plot_axis_freeze(GtkPlotAxis * axis)3520 gtk_plot_axis_freeze (GtkPlotAxis *axis)
3521 {
3522 axis->frozen = TRUE;
3523 }
3524
3525 void
gtk_plot_axis_thaw(GtkPlotAxis * axis)3526 gtk_plot_axis_thaw (GtkPlotAxis *axis)
3527 {
3528 axis->frozen = FALSE;
3529 gtk_plot_axis_ticks_recalc (axis);
3530 }
3531
3532 void
gtk_plot_axis_ticks_autoscale(GtkPlotAxis * axis,gdouble xmin,gdouble xmax,gint * precision)3533 gtk_plot_axis_ticks_autoscale (GtkPlotAxis *axis,
3534 gdouble xmin, gdouble xmax,
3535 gint *precision)
3536 {
3537 axis->ticks_autoscale(axis, xmin, xmax, precision);
3538 }
3539
3540 /**
3541 * gtk_plot_axis_ticks_transform:
3542 * @axis:
3543 * @y:
3544 *
3545 *
3546 *
3547 * Return value:
3548 */
3549 gdouble
gtk_plot_axis_ticks_transform(GtkPlotAxis * axis,gdouble y)3550 gtk_plot_axis_ticks_transform (GtkPlotAxis *axis, gdouble y)
3551 {
3552 return (axis->ticks_transform(axis, y));
3553 }
3554
3555 /**
3556 * gtk_plot_axis_ticks_inverse:
3557 * @axis:
3558 * @x:
3559 *
3560 *
3561 *
3562 * Return value:
3563 */
3564 gdouble
gtk_plot_axis_ticks_inverse(GtkPlotAxis * axis,gdouble x)3565 gtk_plot_axis_ticks_inverse (GtkPlotAxis *axis, gdouble x)
3566 {
3567 return (axis->ticks_inverse(axis, x));
3568 }
3569
3570 /**
3571 * gtk_plot_axis_parse_label:
3572 * @axis:
3573 * @val:
3574 * @precision:
3575 * @style:
3576 * @label:
3577 *
3578 *
3579 */
3580 void
gtk_plot_axis_parse_label(GtkPlotAxis * axis,gdouble val,gint precision,gint style,gchar * label)3581 gtk_plot_axis_parse_label (GtkPlotAxis *axis,
3582 gdouble val,
3583 gint precision,
3584 gint style,
3585 gchar *label)
3586 {
3587 axis->parse_label(axis, val, precision, style, label);
3588 }
3589
3590 /**
3591 * gtk_plot_ticks_transform:
3592 * @axis:
3593 * @x:
3594 *
3595 *
3596 *
3597 * Return value:
3598 */
3599 gdouble
gtk_plot_ticks_transform(GtkPlotAxis * axis,gdouble x)3600 gtk_plot_ticks_transform(GtkPlotAxis *axis, gdouble x)
3601 {
3602 gdouble position = 0;
3603 GtkPlotTicks *_ticks = &axis->ticks;
3604 GtkPlotTicks ticks = *_ticks;
3605
3606 switch( ticks.scale ){
3607 case GTK_PLOT_SCALE_LOG10:
3608 if( x <= 0.0 || ticks.min <= 0.0 || ticks.max <= 0.0 )
3609 return 0;
3610
3611 if(ticks.apply_break){
3612 if(x <= ticks.break_min) {
3613 position = log(x/ticks.min) / log(ticks.break_min / ticks.min);
3614 position *= ticks.break_position;
3615 } else {
3616 if(x <= ticks.break_max) return ticks.break_position;
3617
3618 if(ticks.break_scale == GTK_PLOT_SCALE_LOG10)
3619 position = log(x/ticks.break_max) / log(ticks.max/ticks.break_max);
3620 else
3621 position = (x - ticks.break_max) / (ticks.max - ticks.break_max);
3622 position = ticks.break_position + (1 - ticks.break_position) * position;
3623 }
3624 } else {
3625 position = log(x/ticks.min) / log(ticks.max/ticks.min);
3626 }
3627 break;
3628
3629 case GTK_PLOT_SCALE_LINEAR:
3630 default:
3631 if(ticks.apply_break){
3632 if(x <= ticks.break_min) {
3633 position = (x - ticks.min) / (ticks.break_min - ticks.min);
3634 position *= ticks.break_position;
3635 } else {
3636 if(x <= ticks.break_max) return ticks.break_position;
3637
3638 if(ticks.break_scale == GTK_PLOT_SCALE_LOG10)
3639 position = log(x/ticks.break_max) / log(ticks.max/ticks.break_max);
3640 else
3641 position = (x - ticks.break_max) / (ticks.max - ticks.break_max);
3642
3643 position = ticks.break_position + (1 - ticks.break_position) * position;
3644 }
3645
3646
3647 } else {
3648 position = (x - ticks.min) / (ticks.max - ticks.min);
3649 }
3650 break;
3651 }
3652
3653 return(position);
3654 }
3655
3656 /**
3657 * gtk_plot_ticks_inverse:
3658 * @axis:
3659 * @x:
3660 *
3661 *
3662 *
3663 * Return value:
3664 */
3665 gdouble
gtk_plot_ticks_inverse(GtkPlotAxis * axis,gdouble x)3666 gtk_plot_ticks_inverse(GtkPlotAxis *axis, gdouble x)
3667 {
3668 gdouble point = 0;
3669 GtkPlotTicks *_ticks = &axis->ticks;
3670 GtkPlotTicks ticks = *_ticks;
3671
3672 switch(ticks.scale){
3673 case GTK_PLOT_SCALE_LINEAR:
3674 if(ticks.apply_break){
3675 if(x <= ticks.break_position){
3676 point = ticks.min + x*(ticks.break_min-ticks.min)/ticks.break_position;
3677 } else {
3678 point = ticks.break_max + (x - ticks.break_position)*(ticks.max-ticks.break_max)/(1-ticks.break_position);
3679 }
3680 } else {
3681 point = ticks.min + x*(ticks.max-ticks.min);
3682 }
3683 break;
3684 case GTK_PLOT_SCALE_LOG10:
3685 /* FIXME */
3686 if(ticks.apply_break){
3687 if(x <= ticks.break_position){
3688 point = ticks.min + x*(ticks.break_min-ticks.min)/ticks.break_position;
3689 } else {
3690 point = ticks.break_max + (x - ticks.break_position)*(ticks.max-ticks.break_max)/(1-ticks.break_position);
3691 }
3692 } else {
3693 point = log(ticks.min) + x*(log(ticks.max/ticks.min));
3694 point = exp(point);
3695 }
3696 break;
3697 default:
3698 break;
3699 }
3700 return point;
3701 }
3702
3703 gint
roundint(gdouble x)3704 roundint (gdouble x)
3705 {
3706 return (x+.50999999471);
3707 }
3708
3709 /**
3710 * gtk_plot_parse_label:
3711 * @axis:
3712 * @val:
3713 * @precision:
3714 * @style:
3715 * @label:
3716 *
3717 *
3718 */
3719 void
gtk_plot_parse_label(GtkPlotAxis * axis,gdouble val,gint precision,gint style,gchar * label)3720 gtk_plot_parse_label(GtkPlotAxis *axis, gdouble val, gint precision, gint style, gchar *label)
3721 {
3722 gdouble auxval;
3723 gint intspace = 0;
3724 gint power = 0.0;
3725 gdouble v = 0.0;
3726 GtkPlotScale scale = axis->ticks.scale;
3727
3728 auxval = fabs(val);
3729
3730 switch(style){
3731 case GTK_PLOT_LABEL_EXP:
3732 g_snprintf (label, LABEL_MAX_LENGTH, "%*.*E", 1, precision, val);
3733 break;
3734 case GTK_PLOT_LABEL_POW:
3735 power = 0.0;
3736 if(auxval != 0.0)
3737 power = (gint)log10(auxval);
3738
3739 v = val / pow(10.0, power);
3740 if(fabs(v) < 1.0 && v != 0.0){
3741 v *= 10.0;
3742 power -= 1;
3743 }
3744 if(fabs(v) >= 10.0){
3745 v /= 10.0;
3746 power += 1;
3747 }
3748 /*
3749 if(power < -12){
3750 power = 0;
3751 v = 0.0f;
3752 }
3753 */
3754 if(scale == GTK_PLOT_SCALE_LOG10)
3755 g_snprintf (label, LABEL_MAX_LENGTH, "10\\S%i", power);
3756 else
3757 g_snprintf (label, LABEL_MAX_LENGTH, "%*.*f\\4x\\N10\\S%i", 1, precision, v, power);
3758 break;
3759 case GTK_PLOT_LABEL_FLOAT:
3760 default:
3761
3762 if (auxval > 1)
3763 intspace = (gint)log10(auxval);
3764 else if (auxval < pow(10,-precision))
3765 val = 0.0f;
3766 g_snprintf (label, LABEL_MAX_LENGTH, "%*.*f", intspace, precision, val);
3767 }
3768
3769 }
3770
3771 /**
3772 * gtk_plot_draw_text:
3773 * @plot:
3774 * @text:
3775 *
3776 *
3777 */
3778 void
gtk_plot_draw_text(GtkPlot * plot,GtkPlotText text)3779 gtk_plot_draw_text(GtkPlot *plot,
3780 GtkPlotText text)
3781 {
3782 gint x, y;
3783 GtkAllocation allocation;
3784
3785 if(!text.text) return;
3786 if(text.text[0] == '\0') return;
3787 if(plot->drawable == NULL) return;
3788
3789 gtk_widget_get_allocation(GTK_WIDGET(plot), &allocation);
3790 x = text.x * allocation.width;
3791 y = text.y * allocation.height;
3792
3793 gtk_plot_paint_text(plot, x, y, text);
3794 }
3795
3796 static void
gtk_plot_paint_text(GtkPlot * plot,gint x,gint y,GtkPlotText text)3797 gtk_plot_paint_text(GtkPlot *plot,
3798 gint x, gint y,
3799 GtkPlotText text)
3800 {
3801 gdouble m = plot->magnification;
3802
3803 if(!text.text) return;
3804 if(text.text[0] == '\0') return;
3805 if(plot->drawable == NULL) return;
3806
3807 gtk_plot_pc_draw_string(plot->pc,
3808 x, y,
3809 text.angle,
3810 &text.fg,
3811 &text.bg,
3812 text.transparent,
3813 text.border,
3814 roundint(m * text.border_space),
3815 roundint(m * text.border_width),
3816 roundint(m * text.shadow_width),
3817 text.font,
3818 roundint(m * text.height),
3819 text.justification,
3820 text.text);
3821
3822 g_signal_emit (plot, plot_signals[CHANGED],0);
3823 }
3824
3825 /**
3826 * gtk_plot_text_get_size:
3827 * @text:
3828 * @angle:
3829 * @text_font:
3830 * @text_height:
3831 * @width:
3832 * @height:
3833 * @ascent:
3834 * @descent:
3835 *
3836 *
3837 */
3838 void
gtk_plot_text_get_size(const gchar * text,gint angle,const gchar * text_font,gint text_height,gint * width,gint * height,gint * ascent,gint * descent)3839 gtk_plot_text_get_size(const gchar *text, gint angle,
3840 const gchar *text_font,
3841 gint text_height,
3842 gint *width, gint *height,
3843 gint *ascent, gint *descent)
3844 {
3845 PangoFontDescription *font, *latin_font;
3846 GtkPSFont *psfont, *base_psfont, *latin_psfont;
3847 gint old_width, old_height;
3848 gboolean italic, bold;
3849 gint fontsize;
3850 gint x, y, y0;
3851 GList *family;
3852 gint numf;
3853 const gchar *aux = text;
3854 const gchar *lastchar = text;
3855 const gchar *wtext = text;
3856 const gchar *xaux = text;
3857 PangoFontMetrics *metrics = NULL;
3858 PangoLayout *layout = NULL;
3859 PangoRectangle rect;
3860 PangoContext *context;
3861 gint i = 0;
3862
3863
3864 if (text == NULL || text[0] == '\0') {
3865 *width = *height = *ascent = *descent = 0;
3866 return;
3867 }
3868 layout = pango_layout_new(context = gdk_pango_context_get_for_screen(gdk_screen_get_default()));
3869 g_object_unref(G_OBJECT(context));
3870 pango_layout_set_text(layout, text, -1);
3871
3872 gtk_psfont_get_families(&family, &numf);
3873 base_psfont = psfont = gtk_psfont_get_by_name(text_font);
3874 font = gtk_psfont_get_font_description(psfont, text_height);
3875 pango_layout_get_extents(layout, NULL, &rect);
3876 old_width = PANGO_PIXELS(rect.width);
3877 old_height = PANGO_PIXELS(rect.height);
3878
3879 italic = psfont->italic;
3880 bold = psfont->bold;
3881 fontsize = text_height;
3882
3883 if (psfont->i18n_latinfamily) {
3884 latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic,
3885 bold);
3886 latin_font = gtk_psfont_get_font_description(latin_psfont, text_height);
3887 } else {
3888 latin_font = NULL;
3889 latin_psfont = NULL;
3890 }
3891
3892 metrics = pango_context_get_metrics(pango_layout_get_context(layout), font, gtk_get_default_language());
3893 y0 = y = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics));
3894 y0 = y = 0;
3895 x = 0;
3896 old_width = 0;
3897
3898 *ascent = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics));
3899 *descent = PANGO_PIXELS(pango_font_metrics_get_descent(metrics));
3900
3901 aux = wtext = text;
3902 while(aux && *aux != '\0' && *aux != '\n'){
3903 if(*aux == '\\'){
3904 aux = g_utf8_next_char(aux);
3905 switch(*aux){
3906 case '0': case '1': case '2': case '3':
3907 case '4': case '5': case '6': case '7': case '9':
3908 psfont = gtk_psfont_get_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold);
3909 pango_font_description_free(font);
3910 font = gtk_psfont_get_font_description(psfont, fontsize);
3911 /*
3912 The 0th-9th data of family is supposed to be a built-in Latin
3913 font defined in font_data[], so this code is not needed unless
3914 the font_data[] is modified.
3915
3916 if (psfont->i18n_latinfamily) {
3917 latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
3918 italic, bold);
3919 gdk_font_unref(latin_font);
3920 latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
3921 }
3922 */
3923
3924 aux = g_utf8_next_char(aux);
3925 break;
3926 case '8': case 'g':
3927 psfont = gtk_psfont_get_by_family("Symbol", italic, bold);
3928 pango_font_description_free(font);
3929 font = gtk_psfont_get_font_description(psfont, fontsize);
3930 /* The code commented out above might be needed here if the
3931 font_data[] is modified.
3932 */
3933 aux = g_utf8_next_char(aux);
3934 break;
3935 case 'B':
3936 bold = TRUE;
3937 psfont = gtk_psfont_get_by_family(psfont->family, italic, bold);
3938 pango_font_description_free(font);
3939 font = gtk_psfont_get_font_description(psfont, fontsize);
3940 if (psfont->i18n_latinfamily) {
3941 latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
3942 italic, bold);
3943 if(latin_font) pango_font_description_free(latin_font);
3944 latin_font = gtk_psfont_get_font_description(latin_psfont,
3945 fontsize);
3946 }
3947 aux = g_utf8_next_char(aux);
3948 break;
3949 case 'i':
3950 italic = TRUE;
3951 psfont = gtk_psfont_get_by_family(psfont->family, italic, bold);
3952 pango_font_description_free(font);
3953 font = gtk_psfont_get_font_description(psfont, fontsize);
3954 if (psfont->i18n_latinfamily) {
3955 latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
3956 italic, bold);
3957 if(latin_font) pango_font_description_free(latin_font);
3958 latin_font = gtk_psfont_get_font_description(latin_psfont,
3959 fontsize);
3960 }
3961 aux = g_utf8_next_char(aux);
3962 break;
3963 case 'S': case '^':
3964 fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
3965 pango_font_description_free(font);
3966 font = gtk_psfont_get_font_description(psfont, fontsize);
3967 pango_font_metrics_unref(metrics);
3968 metrics = pango_context_get_metrics(pango_layout_get_context(layout), font, gtk_get_default_language());
3969 y += PANGO_PIXELS(pango_font_metrics_get_ascent(metrics));
3970 if (psfont->i18n_latinfamily) {
3971 if(latin_font) pango_font_description_free(latin_font);
3972 latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
3973 }
3974 aux = g_utf8_next_char(aux);
3975 break;
3976 case 's': case '_':
3977 fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
3978 pango_font_description_free(font);
3979 font = gtk_psfont_get_font_description(psfont, fontsize);
3980 pango_font_metrics_unref(metrics);
3981 metrics = pango_context_get_metrics(pango_layout_get_context(layout), font, gtk_get_default_language());
3982 y -= PANGO_PIXELS(pango_font_metrics_get_descent(metrics));
3983 if (psfont->i18n_latinfamily) {
3984 if(latin_font) pango_font_description_free(latin_font);
3985 latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
3986 }
3987 aux = g_utf8_next_char(aux);
3988 break;
3989 case '+':
3990 fontsize += 3;
3991 pango_font_description_free(font);
3992 font = gtk_psfont_get_font_description(psfont, fontsize);
3993 if (psfont->i18n_latinfamily){
3994 if(latin_font) pango_font_description_free(latin_font);
3995 latin_font = gtk_psfont_get_font_description(latin_psfont,
3996 fontsize);
3997 }
3998 aux = g_utf8_next_char(aux);
3999 break;
4000 case '-':
4001 fontsize -= 3;
4002 pango_font_description_free(font);
4003 font = gtk_psfont_get_font_description(psfont, fontsize);
4004 if (psfont->i18n_latinfamily){
4005 if(latin_font) pango_font_description_free(latin_font);
4006 latin_font = gtk_psfont_get_font_description(latin_psfont,
4007 fontsize);
4008 }
4009 aux = g_utf8_next_char(aux);
4010 break;
4011 case 'N':
4012 psfont = base_psfont;
4013 pango_font_description_free(font);
4014 font = gtk_psfont_get_font_description(psfont, text_height);
4015 y = y0;
4016 italic = psfont->italic;
4017 bold = psfont->bold;
4018 fontsize = text_height;
4019 if (psfont->i18n_latinfamily) {
4020 latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
4021 italic, bold);
4022 if(latin_font) pango_font_description_free(latin_font);
4023 latin_font = gtk_psfont_get_font_description(latin_psfont,
4024 fontsize);
4025 }
4026 aux = g_utf8_next_char(aux);
4027 break;
4028 case 'b':
4029 if(lastchar){
4030 const gchar *aux2 = lastchar;
4031 i = g_utf8_next_char(aux) - aux2;
4032 pango_layout_set_text(layout, lastchar, i);
4033 pango_layout_get_extents(layout, NULL, &rect);
4034 x -= PANGO_PIXELS(rect.width);
4035
4036 if (lastchar == wtext)
4037 lastchar = NULL;
4038 else
4039 lastchar--;
4040 } else {
4041 pango_layout_set_text(layout, "X", 1);
4042 pango_layout_get_extents(layout, NULL, &rect);
4043 x -= PANGO_PIXELS(rect.width);
4044 }
4045 aux = g_utf8_next_char(aux);
4046 break;
4047 case 'x':
4048 xaux = aux + 1;
4049 for (i=0; i<3; i++){
4050 if (xaux[i] >= '0' && xaux[i] <= '9')
4051 ; //num[i] = xaux[i];
4052 else
4053 break;
4054 }
4055 if (i < 3){
4056 aux++;
4057 break;
4058 }
4059 //num[3] = '\0';
4060 /* insert_char = (gchar)atoi(num); */
4061 /* \xNNN is always outputted with latin fonts. */
4062 pango_layout_set_font_description(layout, font);
4063 pango_layout_set_text(layout, aux, 1);
4064 pango_layout_get_extents(layout, NULL, &rect);
4065 x += PANGO_PIXELS(rect.width);
4066 aux += 4;
4067 lastchar = aux - 1;
4068 break;
4069 default:
4070 if(aux && *aux != '\0' && *aux !='\n'){
4071 const gchar *aux2 = aux;
4072 i = g_utf8_next_char(aux) - aux2;
4073 pango_layout_set_font_description(layout, font);
4074 pango_layout_set_text(layout, aux, i);
4075 pango_layout_get_extents(layout, NULL, &rect);
4076 x += PANGO_PIXELS(rect.width);
4077 lastchar = aux;
4078 aux = g_utf8_next_char(aux);
4079 }
4080 break;
4081 }
4082 } else {
4083 if(aux && *aux != '\0' && *aux != '\n'){
4084 const gchar *aux2 = aux;
4085 i = g_utf8_next_char(aux) - aux2;
4086 pango_layout_set_font_description(layout, font);
4087 pango_layout_set_text(layout, aux, i);
4088 pango_layout_get_extents(layout, NULL, &rect);
4089 x += PANGO_PIXELS(rect.width);
4090 lastchar = aux;
4091 aux = g_utf8_next_char(aux);
4092 if(x > old_width) old_width = x;
4093 }
4094 }
4095 }
4096 pango_font_description_free(font);
4097 if(latin_font) pango_font_description_free(latin_font);
4098 pango_font_metrics_unref(metrics);
4099 g_object_unref(G_OBJECT(layout));
4100
4101 old_height = *ascent + *descent;
4102 *width = old_width;
4103 *height = old_height;
4104 if(angle == 90 || angle == 270)
4105 {
4106 *width = old_height;
4107 *height = old_width;
4108 }
4109 }
4110
4111 /**
4112 * gtk_plot_text_get_area:
4113 * @text:
4114 * @angle:
4115 * @just:
4116 * @font_name:
4117 * @font_size:
4118 * @x:
4119 * @y:
4120 * @width:
4121 * @height:
4122 *
4123 *
4124 */
4125 void
gtk_plot_text_get_area(const gchar * text,gint angle,GtkJustification just,const gchar * font_name,gint font_size,gint * x,gint * y,gint * width,gint * height)4126 gtk_plot_text_get_area(const gchar *text, gint angle, GtkJustification just,
4127 const gchar *font_name, gint font_size,
4128 gint *x, gint *y,
4129 gint *width, gint *height)
4130 {
4131 gint ascent, descent;
4132
4133 if(text == NULL) return;
4134
4135 gtk_plot_text_get_size(text, angle, font_name,
4136 font_size,
4137 width, height, &ascent, &descent);
4138
4139 *x = 0;
4140 *y = 0;
4141
4142 switch(just){
4143 case GTK_JUSTIFY_LEFT:
4144 switch(angle){
4145 case 0:
4146 *y -= ascent;
4147 break;
4148 case 90:
4149 *y -= *height;
4150 *x -= ascent;
4151 break;
4152 case 180:
4153 *x -= *width;
4154 *y -= descent;
4155 break;
4156 case 270:
4157 *x -= descent;
4158 break;
4159 default:
4160 break;
4161 }
4162 break;
4163 case GTK_JUSTIFY_RIGHT:
4164 switch(angle){
4165 case 0:
4166 *x -= *width;
4167 *y -= ascent;
4168 break;
4169 case 90:
4170 *x -= ascent;
4171 break;
4172 case 180:
4173 *y -= descent;
4174 break;
4175 case 270:
4176 *y -= *height;
4177 *x -= descent;
4178 break;
4179 default:
4180 break;
4181 }
4182 break;
4183 case GTK_JUSTIFY_CENTER:
4184 default:
4185 switch(angle){
4186 case 0:
4187 *x -= *width / 2.;
4188 *y -= ascent;
4189 break;
4190 case 90:
4191 *x -= ascent;
4192 *y -= *height / 2.;
4193 break;
4194 case 180:
4195 *x -= *width / 2.;
4196 *y -= descent;
4197 break;
4198 case 270:
4199 *x -= descent;
4200 *y -= *height / 2.;
4201 break;
4202 default:
4203 break;
4204 }
4205 }
4206
4207 }
4208
4209 /******************************************
4210 * gtk_plot_clip_data
4211 * gtk_plot_get_position
4212 * gtk_plot_get_size
4213 * gtk_plot_get_internal_allocation
4214 * gtk_plot_set_background
4215 * gtk_plot_move
4216 * gtk_plot_resize
4217 * gtk_plot_move_resize
4218 * gtk_plot_get_pixel
4219 * gtk_plot_get_point
4220 * gtk_plot_real_get_pixel
4221 * gtk_plot_set_xscale
4222 * gtk_plot_set_yscale
4223 * gtk_plot_draw_text
4224 ******************************************/
4225
4226 /**
4227 * gtk_plot_clip_data:
4228 * @plot: a #GtkPlot widget.
4229 * @clip:
4230 *
4231 *
4232 */
4233 void
gtk_plot_clip_data(GtkPlot * plot,gboolean clip)4234 gtk_plot_clip_data (GtkPlot *plot, gboolean clip)
4235 {
4236 plot->clip_data = clip;
4237 }
4238
4239 /**
4240 * gtk_plot_get_position:
4241 * @plot: a #GtkPlot widget.
4242 * @x:
4243 * @y
4244 *
4245 *
4246 */
4247 void
gtk_plot_get_position(GtkPlot * plot,gdouble * x,gdouble * y)4248 gtk_plot_get_position (GtkPlot *plot, gdouble *x, gdouble *y)
4249 {
4250 *x = plot->x;
4251 *y = plot->y;
4252 }
4253
4254 /**
4255 * gtk_plot_get_size:
4256 * @width:
4257 * @height:
4258 *
4259 *
4260 */
4261 void
gtk_plot_get_size(GtkPlot * plot,gdouble * width,gdouble * height)4262 gtk_plot_get_size (GtkPlot *plot, gdouble *width, gdouble *height)
4263 {
4264 *width = plot->width;
4265 *height = plot->height;
4266 }
4267
4268 /**
4269 * gtk_plot_get_internal_allocation:
4270 * @plot: a #GtkPlot widget.
4271 *
4272 * Return value: (transfer none) internal_allocation
4273 */
4274 GtkAllocation
gtk_plot_get_internal_allocation(GtkPlot * plot)4275 gtk_plot_get_internal_allocation (GtkPlot *plot)
4276 {
4277 return(plot->internal_allocation);
4278 }
4279
4280 /**
4281 * gtk_plot_set_background:
4282 * @plot: a #GtkPlot widget.
4283 * @bg_color:
4284 *
4285 *
4286 */
4287 void
gtk_plot_set_background(GtkPlot * plot,const GdkRGBA * bg_color)4288 gtk_plot_set_background(GtkPlot *plot, const GdkRGBA *bg_color)
4289 {
4290 plot->background = *bg_color;
4291
4292 gtk_plot_paint(plot);
4293
4294 g_signal_emit (plot, plot_signals[CHANGED],0);
4295 }
4296
4297 /**
4298 * gtk_plot_clip_move:
4299 * @x:
4300 * @y:
4301 *
4302 *
4303 */
4304 void
gtk_plot_move(GtkPlot * plot,gdouble x,gdouble y)4305 gtk_plot_move (GtkPlot *plot, gdouble x, gdouble y)
4306 {
4307 gboolean veto = TRUE;
4308 GtkAllocation allocation;
4309
4310 _gtkextra_signal_emit (G_OBJECT(plot), plot_signals[MOVED],
4311 &x, &y, &veto);
4312
4313 if(!veto) return;
4314
4315 plot->left->title.x += (x - plot->x);
4316 plot->left->title.y += (y - plot->y);
4317 plot->right->title.x += (x - plot->x);
4318 plot->right->title.y += (y - plot->y);
4319 plot->top->title.x += (x - plot->x);
4320 plot->top->title.y += (y - plot->y);
4321 plot->bottom->title.x += (x - plot->x);
4322 plot->bottom->title.y += (y - plot->y);
4323
4324 plot->x = x;
4325 plot->y = y;
4326
4327 gtk_widget_get_allocation(GTK_WIDGET(plot), &allocation);
4328 plot->internal_allocation.x = allocation.x + roundint(plot->x * allocation.width);
4329 plot->internal_allocation.y = allocation.y + roundint(plot->y * allocation.height);
4330 plot->internal_allocation.width = roundint(plot->width * allocation.width);
4331 plot->internal_allocation.height = roundint(plot->height * allocation.height);
4332
4333 g_signal_emit (plot, plot_signals[CHANGED], 0);
4334 }
4335
4336 /**
4337 * gtk_plot_resize:
4338 * @plot: a #GtkPlot widget.a #GtkPlot widget.
4339 * @width:
4340 * @height:
4341 *
4342 *
4343 */
4344 void
gtk_plot_resize(GtkPlot * plot,gdouble width,gdouble height)4345 gtk_plot_resize (GtkPlot *plot, gdouble width, gdouble height)
4346 {
4347 gboolean veto = TRUE;
4348 GtkAllocation allocation;
4349
4350 _gtkextra_signal_emit (G_OBJECT(plot), plot_signals[RESIZED],
4351 &width, &height, &veto);
4352
4353 if(!veto) return;
4354
4355 plot->left->title.y += (height - plot->height) / 2.;
4356 plot->right->title.x += (width - plot->width);
4357 plot->right->title.y += (height - plot->height) / 2.;
4358 plot->top->title.x += (width - plot->width) / 2.;
4359 plot->bottom->title.x += (width - plot->width) / 2.;
4360 plot->bottom->title.y += (height - plot->height);
4361
4362 plot->width = width;
4363 plot->height = height;
4364
4365 gtk_widget_get_allocation(GTK_WIDGET(plot), &allocation);
4366 plot->internal_allocation.x = allocation.x + roundint(plot->x * allocation.width);
4367 plot->internal_allocation.y = allocation.y + roundint(plot->y * allocation.height);
4368 plot->internal_allocation.width = roundint(plot->width * allocation.width);
4369 plot->internal_allocation.height = roundint(plot->height * allocation.height);
4370
4371 g_signal_emit (plot, plot_signals[UPDATE], 0, FALSE);
4372 g_signal_emit (plot, plot_signals[CHANGED], 0);
4373 }
4374
4375 /**
4376 * gtk_plot_set_magnification:
4377 * @plot: a #GtkPlot widget.
4378 * @magnification:
4379 *
4380 *
4381 */
4382 void
gtk_plot_set_magnification(GtkPlot * plot,gdouble magnification)4383 gtk_plot_set_magnification (GtkPlot *plot, gdouble magnification)
4384 {
4385 GtkAllocation allocation;
4386
4387 plot->magnification = magnification;
4388 gtk_widget_get_allocation(GTK_WIDGET(plot), &allocation);
4389
4390 plot->internal_allocation.x = allocation.x + roundint(plot->x * allocation.width);
4391 plot->internal_allocation.y = allocation.y + roundint(plot->y * allocation.height);
4392 plot->internal_allocation.width = roundint(plot->width * allocation.width);
4393 plot->internal_allocation.height = roundint(plot->height * allocation.height);
4394
4395 g_signal_emit (plot, plot_signals[UPDATE], 0, FALSE);
4396 g_signal_emit (plot, plot_signals[CHANGED], 0);
4397 }
4398
4399 /**
4400 * gtk_plot_move_resize:
4401 * @plot: a #GtkPlot widget.
4402 * @x:
4403 * @y:
4404 * @width:
4405 * @height:
4406 *
4407 *
4408 */
4409 void
gtk_plot_move_resize(GtkPlot * plot,gdouble x,gdouble y,gdouble width,gdouble height)4410 gtk_plot_move_resize (GtkPlot *plot,
4411 gdouble x, gdouble y,
4412 gdouble width, gdouble height)
4413 {
4414 gtk_plot_move(plot, x, y);
4415 gtk_plot_resize(plot, width, height);
4416
4417 g_signal_emit (plot, plot_signals[CHANGED], 0);
4418 }
4419
4420 /**
4421 * gtk_plot_get_pixel:
4422 * @plot: a #GtkPlot widget.
4423 * @xx:
4424 * @yy:
4425 * @x:
4426 * @y:
4427 *
4428 *
4429 */
4430 void
gtk_plot_get_pixel(GtkPlot * plot,gdouble xx,gdouble yy,gdouble * x,gdouble * y)4431 gtk_plot_get_pixel(GtkPlot *plot, gdouble xx, gdouble yy, gdouble *x, gdouble *y)
4432 {
4433 GTK_PLOT_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(plot)))->get_pixel (GTK_WIDGET(plot), xx, yy, x, y);
4434 }
4435
4436 /**
4437 * gtk_plot_get_point:
4438 * @plot: a #GtkPlot widget.
4439 * @x:
4440 * @y:
4441 * @xx:
4442 * @yy:
4443 *
4444 *
4445 */
4446 void
gtk_plot_get_point(GtkPlot * plot,gint x,gint y,gdouble * xx,gdouble * yy)4447 gtk_plot_get_point(GtkPlot *plot, gint x, gint y, gdouble *xx, gdouble *yy)
4448 {
4449 GTK_PLOT_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(plot)))->get_point (GTK_WIDGET(plot), x, y, xx, yy);
4450 }
4451
4452
4453 static void
gtk_plot_real_get_pixel(GtkWidget * widget,gdouble xx,gdouble yy,gdouble * x,gdouble * y)4454 gtk_plot_real_get_pixel(GtkWidget *widget,
4455 gdouble xx, gdouble yy ,
4456 gdouble *x, gdouble *y)
4457 {
4458 GtkPlot *plot;
4459 gint xp, yp, width, height;
4460 GtkAllocation allocation;
4461
4462 plot = GTK_PLOT(widget);
4463 xp = plot->internal_allocation.x;
4464 yp = plot->internal_allocation.y;
4465 width = plot->internal_allocation.width;
4466 height = plot->internal_allocation.height;
4467
4468 *y = gtk_plot_ticks_transform(plot->left, yy)*height;
4469 *x = gtk_plot_ticks_transform(plot->bottom, xx)*width;
4470
4471 gtk_widget_get_allocation(widget, &allocation);
4472 if(!plot->reflect_x)
4473 *x = allocation.x + xp + *x;
4474 else
4475 *x = allocation.x + xp + width - *x;
4476
4477 if(!plot->reflect_y)
4478 *y = allocation.y + yp + height - *y;
4479 else
4480 *y = allocation.y + yp + *y;
4481 }
4482
4483 static void
gtk_plot_real_get_point(GtkWidget * widget,gint x,gint y,gdouble * px,gdouble * py)4484 gtk_plot_real_get_point(GtkWidget *widget,
4485 gint x, gint y,
4486 gdouble *px, gdouble *py)
4487 {
4488 GtkPlot *plot;
4489 gdouble xx, yy;
4490 gdouble xp, yp, width, height;
4491 GtkAllocation allocation;
4492
4493
4494 plot = GTK_PLOT(widget);
4495 xp = plot->internal_allocation.x;
4496 yp = plot->internal_allocation.y;
4497 width = plot->internal_allocation.width;
4498 height = plot->internal_allocation.height;
4499
4500 gtk_widget_get_allocation(widget, &allocation);
4501 if(!plot->reflect_x)
4502 xx = x - allocation.x - xp;
4503 else
4504 xx = width - (x - allocation.x - xp);
4505
4506 if(!plot->reflect_y)
4507 yy = allocation.y + yp + height - y;
4508 else
4509 yy = y - allocation.y - yp;
4510
4511 *px = gtk_plot_axis_ticks_inverse(plot->bottom, xx / width);
4512 *py = gtk_plot_axis_ticks_inverse(plot->left, yy / height);
4513 }
4514
4515 /**
4516 * gtk_plot_set_xrange:
4517 * @plot: a #GtkPlot widget.
4518 * @xmin:
4519 * @xmax:
4520 *
4521 *
4522 */
4523 void
gtk_plot_set_xrange(GtkPlot * plot,gdouble xmin,gdouble xmax)4524 gtk_plot_set_xrange (GtkPlot *plot,
4525 gdouble xmin, gdouble xmax)
4526 {
4527 if(xmin > xmax) return;
4528
4529 plot->xmin = xmin;
4530 plot->xmax = xmax;
4531
4532 plot->bottom->ticks.min = xmin;
4533 plot->bottom->ticks.max = xmax;
4534 plot->top->ticks.min = xmin;
4535 plot->top->ticks.max = xmax;
4536
4537 g_signal_emit (plot, plot_signals[UPDATE], 0, TRUE);
4538 g_signal_emit (plot, plot_signals[CHANGED], 0);
4539 }
4540
4541 /**
4542 * gtk_plot_set_yrange:
4543 * @plot: a #GtkPlot widget.
4544 * @ymin:
4545 * @ymax:
4546 *
4547 *
4548 */
4549 void
gtk_plot_set_yrange(GtkPlot * plot,gdouble ymin,gdouble ymax)4550 gtk_plot_set_yrange (GtkPlot *plot,
4551 gdouble ymin, gdouble ymax)
4552 {
4553 if(ymin > ymax) return;
4554
4555 plot->ymin = ymin;
4556 plot->ymax = ymax;
4557
4558 plot->left->ticks.min = ymin;
4559 plot->left->ticks.max = ymax;
4560 plot->right->ticks.min = ymin;
4561 plot->right->ticks.max = ymax;
4562
4563 g_signal_emit (plot, plot_signals[UPDATE], 0, TRUE);
4564 g_signal_emit (plot, plot_signals[CHANGED], 0);
4565 }
4566
4567
4568 /**
4569 * gtk_plot_set_range:
4570 * @plot: a #GtkPlot widget.
4571 * @xmin:
4572 * @xmax:
4573 * @ymin:
4574 * @ymax:
4575 *
4576 *
4577 */
4578 void
gtk_plot_set_range(GtkPlot * plot,gdouble xmin,gdouble xmax,gdouble ymin,gdouble ymax)4579 gtk_plot_set_range (GtkPlot *plot,
4580 gdouble xmin, gdouble xmax,
4581 gdouble ymin, gdouble ymax)
4582 {
4583 if(xmin > xmax || ymin > ymax) return;
4584
4585 plot->xmin = xmin;
4586 plot->xmax = xmax;
4587 plot->ymin = ymin;
4588 plot->ymax = ymax;
4589
4590 plot->bottom->ticks.min = xmin;
4591 plot->bottom->ticks.max = xmax;
4592 plot->top->ticks.min = xmin;
4593 plot->top->ticks.max = xmax;
4594 plot->left->ticks.min = ymin;
4595 plot->left->ticks.max = ymax;
4596 plot->right->ticks.min = ymin;
4597 plot->right->ticks.max = ymax;
4598
4599 gtk_plot_axis_ticks_recalc(plot->bottom);
4600 gtk_plot_axis_ticks_recalc(plot->top);
4601 gtk_plot_axis_ticks_recalc(plot->left);
4602 gtk_plot_axis_ticks_recalc(plot->right);
4603 g_signal_emit (plot, plot_signals[UPDATE], 0, TRUE);
4604 g_signal_emit (plot, plot_signals[CHANGED], 0);
4605 }
4606
4607 /**
4608 * gtk_plot_ticks_autoscale:
4609 * @axis:
4610 * @xmin:
4611 * @xmax:
4612 * @precision:
4613 *
4614 *
4615 */
4616 void
gtk_plot_ticks_autoscale(GtkPlotAxis * axis,gdouble xmin,gdouble xmax,gint * precision)4617 gtk_plot_ticks_autoscale(GtkPlotAxis *axis, gdouble xmin, gdouble xmax, gint *precision)
4618 {
4619 GtkPlotTicks *ticks = &axis->ticks;
4620
4621 if(xmin > xmax) return;
4622
4623 if(ticks->scale == GTK_PLOT_SCALE_LOG10) {
4624 ticks->step = 1;
4625 ticks->nminor = 8;
4626 xmin = floor(log10(fabs(xmin))) - 1.;
4627 *precision = MAX(xmin + 1, 1);
4628 xmin = pow(10., xmin);
4629 xmax = ceil(log10(fabs(xmax)));
4630 xmax = pow(10., xmax);
4631 if(xmin == 0.0) xmin = xmax/1000.;
4632 } else {
4633 gdouble amin, amax;
4634 gdouble pmin, pmax;
4635 gdouble dx;
4636 gdouble pstep;
4637
4638 amin = xmin;
4639 amax = xmax;
4640 if(xmin == xmax){
4641 if(xmin == 0.0){
4642 amax = xmax = 0.1;
4643 }else{
4644 pstep = floor(log10(fabs(xmin)));
4645 dx = xmin/pow(10., pstep) * pow(10., pstep);
4646 amax = xmax = xmin + 2 * dx;
4647 amin = xmin = xmin - 2 * dx;
4648 }
4649 }
4650 dx = (xmax - xmin)/8.;
4651 xmin -= dx;
4652 xmax += dx;
4653 if(xmin == 0.0) xmin -= dx;
4654 if(xmax == 0.0) xmax += dx;
4655 pmin = floor(log10(fabs(xmin))) - 1.;
4656 pmax = floor(log10(fabs(xmax))) - 1.;
4657 xmin = floor(xmin/pow(10., pmin)) * pow(10., pmin);
4658 xmax = floor(xmax/pow(10., pmax)) * pow(10., pmax);
4659 pstep = floor(log10(fabs(dx)));
4660 dx = ticks->step = floor(dx/pow(10., pstep)) * pow(10., pstep);
4661 /* FIXME: this could lead to numerical trouble and infinite
4662 * loop if dx is too small compared to xmin or xmax */
4663 while(xmin >= amin) xmin -= dx;
4664 while(xmax <= amax) xmax += dx;
4665 dx = floor((xmax - xmin)/ticks->step);
4666 while(dx > 10.){
4667 ticks->step *= 2;
4668 dx = floor((xmax - xmin)/ticks->step);
4669 }
4670 xmin = floor(xmin/ticks->step) * ticks->step;
4671 xmax = ceil(xmax/ticks->step) * ticks->step;
4672 ticks->step = ticks->step;
4673 *precision = MAX(floor(fabs(pstep)), 0);
4674 }
4675
4676 ticks->min = xmin;
4677 ticks->max = xmax;
4678
4679 gtk_plot_axis_ticks_recalc(axis);
4680 axis->label_precision = *precision;
4681 }
4682
4683 /**
4684 * gtk_plot_autoscale:
4685 * @plot: a #GtkPlot widget.
4686 *
4687 *
4688 */
4689 void
gtk_plot_autoscale(GtkPlot * plot)4690 gtk_plot_autoscale(GtkPlot *plot)
4691 {
4692 GtkPlotData *dataset;
4693 GList *list;
4694 gdouble xmin, xmax;
4695 gdouble ymin, ymax;
4696 gint n;
4697 gboolean change = FALSE;
4698 gint labels_precision;
4699
4700 if(!plot->data_sets) return;
4701
4702 xmin = plot->xmax;
4703 xmax = plot->xmin;
4704 ymin = plot->ymax;
4705 ymax = plot->ymin;
4706
4707 list = plot->data_sets;
4708 while(list){
4709 dataset = GTK_PLOT_DATA(list->data);
4710 if(!dataset->is_function){
4711 for(n = 0; n < dataset->num_points; n++){
4712 gdouble fx, fy, fz, fa;
4713 gdouble fdx, fdy, fdz, fda;
4714 gchar *label;
4715 gboolean error;
4716 gtk_plot_data_get_point(dataset, n,
4717 &fx, &fy, &fz, &fa,
4718 &fdx, &fdy, &fdz, &fda,
4719 &label, &error);
4720 if(fx < xmin) xmin = fx;
4721 if(fy < ymin) ymin = fy;
4722 if(fx > xmax) xmax = fx;
4723 if(fy > ymax) ymax = fy;
4724 change = TRUE;
4725 }
4726 }
4727
4728 list = list->next;
4729 }
4730
4731 if(!change) return;
4732
4733 gtk_plot_axis_ticks_autoscale(plot->bottom, xmin, xmax, &labels_precision);
4734 gtk_plot_axis_ticks_autoscale(plot->left, ymin, ymax, &labels_precision);
4735 gtk_plot_axis_ticks_autoscale(plot->top, xmin, xmax, &labels_precision);
4736 gtk_plot_axis_ticks_autoscale(plot->right, ymin, ymax, &labels_precision);
4737
4738 plot->xmin = plot->bottom->ticks.min;
4739 plot->xmax = plot->bottom->ticks.max;
4740 plot->ymin = plot->left->ticks.min;
4741 plot->ymax = plot->left->ticks.max;
4742
4743 g_signal_emit (plot, plot_signals[UPDATE], 0, TRUE);
4744 g_signal_emit (plot, plot_signals[CHANGED], 0);
4745 }
4746
4747 /**
4748 * gtk_plot_get_xrange:
4749 * @plot: a #GtkPlot widget.
4750 * @xmin:
4751 * @xmax:
4752 *
4753 *
4754 */
4755 void
gtk_plot_get_xrange(GtkPlot * plot,gdouble * xmin,gdouble * xmax)4756 gtk_plot_get_xrange (GtkPlot *plot,
4757 gdouble *xmin, gdouble *xmax)
4758 {
4759 *xmax = plot->xmax;
4760 *xmin = plot->xmin;
4761 }
4762
4763 /**
4764 * gtk_plot_get_yrange:
4765 * @plot: a #GtkPlot widget.
4766 * @ymin:
4767 * @ymax:
4768 *
4769 *
4770 */
4771 void
gtk_plot_get_yrange(GtkPlot * plot,gdouble * ymin,gdouble * ymax)4772 gtk_plot_get_yrange (GtkPlot *plot,
4773 gdouble *ymin, gdouble *ymax)
4774 {
4775 *ymax = plot->ymax;
4776 *ymin = plot->ymin;
4777 }
4778
4779 /**
4780 * gtk_plot_set_xscale:
4781 * @plot: a #GtkPlot widget.
4782 * @scale_type:
4783 *
4784 *
4785 */
4786 void
gtk_plot_set_xscale(GtkPlot * plot,GtkPlotScale scale_type)4787 gtk_plot_set_xscale (GtkPlot *plot, GtkPlotScale scale_type)
4788 {
4789 plot->xscale = scale_type;
4790 plot->bottom->ticks.scale = scale_type;
4791 plot->top->ticks.scale = scale_type;
4792
4793 g_signal_emit (plot, plot_signals[UPDATE], 0, FALSE);
4794 g_signal_emit (plot, plot_signals[CHANGED], 0);
4795 }
4796
4797 /**
4798 * gtk_plot_set_yscale:
4799 * @plot: a #GtkPlot widget.
4800 * @scale_type:
4801 *
4802 *
4803 */
4804 void
gtk_plot_set_yscale(GtkPlot * plot,GtkPlotScale scale_type)4805 gtk_plot_set_yscale (GtkPlot *plot, GtkPlotScale scale_type)
4806 {
4807 plot->yscale = scale_type;
4808 plot->left->ticks.scale = scale_type;
4809 plot->right->ticks.scale = scale_type;
4810
4811 g_signal_emit (plot, plot_signals[UPDATE], 0, FALSE);
4812 g_signal_emit (plot, plot_signals[CHANGED], 0);
4813 }
4814
4815 /**
4816 * gtk_plot_get_xscale:
4817 * @plot: a #GtkPlot widget.
4818 *
4819 *
4820 *
4821 * Return value:
4822 */
4823 GtkPlotScale
gtk_plot_get_xscale(GtkPlot * plot)4824 gtk_plot_get_xscale (GtkPlot *plot)
4825 {
4826 return plot->bottom->ticks.scale;
4827 }
4828
4829 /**
4830 * gtk_plot_get_yscale:
4831 * @plot: a #GtkPlot widget.
4832 *
4833 *
4834 *
4835 * Return value:
4836 */
4837 GtkPlotScale
gtk_plot_get_yscale(GtkPlot * plot)4838 gtk_plot_get_yscale (GtkPlot *plot)
4839 {
4840 return plot->left->ticks.scale;
4841 }
4842
4843 /**
4844 * gtk_plot_reflect_x:
4845 * @plot: a #GtkPlot widget.
4846 * @reflect:
4847 *
4848 *
4849 */
4850 void
gtk_plot_reflect_x(GtkPlot * plot,gboolean reflect)4851 gtk_plot_reflect_x (GtkPlot *plot, gboolean reflect)
4852 {
4853 plot->reflect_x = reflect;
4854 }
4855
4856 /**
4857 * gtk_plot_reflect_y:
4858 * @plot: a #GtkPlot widget.
4859 * @reflect:
4860 *
4861 *
4862 */
4863 void
gtk_plot_reflect_y(GtkPlot * plot,gboolean reflect)4864 gtk_plot_reflect_y (GtkPlot *plot, gboolean reflect)
4865 {
4866 plot->reflect_y = reflect;
4867 }
4868
4869 /**
4870 * gtk_plot_is_x_reflected:
4871 * @plot: a #GtkPlot widget.
4872 *
4873 *
4874 *
4875 * Return value:
4876 */
4877 gboolean
gtk_plot_is_x_reflected(GtkPlot * plot)4878 gtk_plot_is_x_reflected (GtkPlot *plot)
4879 {
4880 return plot->reflect_x;
4881 }
4882
4883 /**
4884 * gtk_plot_is_y_reflected:
4885 * @plot: a #GtkPlot widget.
4886 *
4887 *
4888 *
4889 * Return value:
4890 */
4891 gboolean
gtk_plot_is_y_reflected(GtkPlot * plot)4892 gtk_plot_is_y_reflected (GtkPlot *plot)
4893 {
4894 return plot->reflect_y;
4895 }
4896
4897 void
gtk_plot_freeze(GtkPlot * plot)4898 gtk_plot_freeze (GtkPlot *plot)
4899 {
4900 gtk_plot_axis_freeze (plot->bottom);
4901 gtk_plot_axis_freeze (plot->top);
4902 gtk_plot_axis_freeze (plot->left);
4903 gtk_plot_axis_freeze (plot->right);
4904 }
4905
4906 void
gtk_plot_thaw(GtkPlot * plot)4907 gtk_plot_thaw (GtkPlot *plot)
4908 {
4909 gtk_plot_axis_thaw (plot->bottom);
4910 gtk_plot_axis_thaw (plot->top);
4911 gtk_plot_axis_thaw (plot->left);
4912 gtk_plot_axis_thaw (plot->right);
4913 }
4914
4915 /**
4916 * gtk_plot_put_text:
4917 * @plot: a #GtkPlot widget.
4918 * @x:
4919 * @y:
4920 * @font:
4921 * @height:
4922 * @angle:
4923 * @fg:
4924 * @bg:
4925 * @transparent:
4926 * @justification:
4927 * @text:
4928 *
4929 * Return value: (transfer none) the #GtkPlotText
4930 */
4931 GtkPlotText *
gtk_plot_put_text(GtkPlot * plot,gdouble x,gdouble y,const gchar * font,gint height,gint angle,const GdkRGBA * fg,const GdkRGBA * bg,gboolean transparent,GtkJustification justification,const gchar * text)4932 gtk_plot_put_text (GtkPlot *plot, gdouble x, gdouble y,
4933 const gchar *font, gint height, gint angle,
4934 const GdkRGBA *fg, const GdkRGBA *bg,
4935 gboolean transparent,
4936 GtkJustification justification,
4937 const gchar *text)
4938 {
4939 GtkWidget *widget;
4940 GtkStyleContext *ctxt;
4941 GtkPlotText *text_attr;
4942 GtkAllocation allocation;
4943
4944
4945 widget = GTK_WIDGET(plot);
4946 ctxt = gtk_widget_get_style_context(widget);
4947
4948 text_attr = g_new0(GtkPlotText, 1);
4949
4950 gtk_widget_get_allocation(widget, &allocation);
4951
4952 text_attr->x = x;
4953 text_attr->y = y;
4954 text_attr->angle = angle;
4955 text_attr->justification = justification;
4956 gtk_style_context_get(ctxt, GTK_STATE_FLAG_NORMAL,
4957 GTK_STYLE_PROPERTY_COLOR,
4958 &text_attr->fg,
4959 GTK_STYLE_PROPERTY_BACKGROUND_COLOR,
4960 &text_attr->bg, NULL);
4961 text_attr->transparent = transparent;
4962 text_attr->border = 0;
4963 text_attr->border_space = 2;
4964 text_attr->border_width = 0;
4965 text_attr->shadow_width = 3;
4966
4967 if(!font) {
4968 text_attr->font = g_strdup(DEFAULT_FONT);
4969 text_attr->height = DEFAULT_FONT_HEIGHT;
4970 } else {
4971 text_attr->font = g_strdup(font);
4972 text_attr->height = height;
4973 }
4974
4975 text_attr->text = NULL;
4976 if(text) text_attr->text = g_strdup(text);
4977
4978 if(fg != NULL)
4979 text_attr->fg = *fg;
4980
4981 if(bg != NULL)
4982 text_attr->bg = *bg;
4983
4984 plot->text = g_list_append(plot->text, text_attr);
4985 gtk_plot_draw_text(plot, *text_attr);
4986
4987 g_signal_emit (plot, plot_signals[CHANGED], 0);
4988 return text_attr;
4989 }
4990
4991 /**
4992 * gtk_plot_text_set_attributes:
4993 * @text_attr:
4994 * @font:
4995 * @height:
4996 * @angle:
4997 * @fg:
4998 * @bg:
4999 * @transparent:
5000 * @justification:
5001 * @text:
5002 *
5003 *
5004 */
5005 void
gtk_plot_text_set_attributes(GtkPlotText * text_attr,const gchar * font,gint height,gint angle,const GdkRGBA * fg,const GdkRGBA * bg,gboolean transparent,GtkJustification justification,const gchar * text)5006 gtk_plot_text_set_attributes (GtkPlotText *text_attr,
5007 const gchar *font,
5008 gint height,
5009 gint angle,
5010 const GdkRGBA *fg,
5011 const GdkRGBA *bg,
5012 gboolean transparent,
5013 GtkJustification justification,
5014 const gchar *text)
5015 {
5016 text_attr->angle = angle;
5017 gdk_rgba_parse(&text_attr->fg, "black");
5018 gdk_rgba_parse(&text_attr->bg, "white");
5019 text_attr->justification = justification;
5020 text_attr->transparent = transparent;
5021
5022 if(!font) {
5023 text_attr->font = g_strdup(DEFAULT_FONT);
5024 text_attr->height = DEFAULT_FONT_HEIGHT;
5025 } else {
5026 text_attr->font = g_strdup(font);
5027 text_attr->height = height;
5028 }
5029
5030 if(text_attr->text) g_free(text_attr->text);
5031 text_attr->text = NULL;
5032 if(text) text_attr->text = g_strdup(text);
5033
5034 if(bg != NULL)
5035 text_attr->bg = *bg;
5036
5037 if(fg != NULL)
5038 text_attr->fg = *fg;
5039
5040 }
5041
5042 /**
5043 * gtk_plot_text_set_border:
5044 * @text:
5045 * @border:
5046 * @border_space:
5047 * @border_width:
5048 * @shadow_width:
5049 *
5050 *
5051 */
5052 void
gtk_plot_text_set_border(GtkPlotText * text,GtkPlotBorderStyle border,gint border_space,gint border_width,gint shadow_width)5053 gtk_plot_text_set_border (GtkPlotText *text,
5054 GtkPlotBorderStyle border,
5055 gint border_space,
5056 gint border_width,
5057 gint shadow_width)
5058 {
5059 if(!text) return;
5060
5061 text->border = border;
5062 text->border_width = border_width;
5063 text->border_space = border_space;
5064 text->shadow_width = shadow_width;
5065 }
5066
5067 /******************************************/
5068
5069 /**
5070 * gtk_plot_set_ticks:
5071 * @plot: a #GtkPlot widget.
5072 * @orientation:
5073 * @major_step:
5074 * @nminor:
5075 *
5076 *
5077 */
gtk_plot_set_ticks(GtkPlot * plot,GtkPlotOrientation orientation,gdouble major_step,gint nminor)5078 void gtk_plot_set_ticks (GtkPlot *plot,
5079 GtkPlotOrientation orientation,
5080 gdouble major_step,
5081 gint nminor)
5082 {
5083 if(orientation == GTK_PLOT_AXIS_X){
5084 gtk_plot_axis_set_ticks(plot->top, major_step, nminor);
5085 gtk_plot_axis_set_ticks(plot->bottom, major_step, nminor);
5086 } else {
5087 gtk_plot_axis_set_ticks(plot->left, major_step, nminor);
5088 gtk_plot_axis_set_ticks(plot->right, major_step, nminor);
5089 }
5090 }
5091
5092 /**
5093 * gtk_plot_set_major_ticks:
5094 * @plot: a #GtkPlot widget.
5095 * @orientation:
5096 * @major_step:
5097 *
5098 *
5099 */
gtk_plot_set_major_ticks(GtkPlot * plot,GtkPlotOrientation orientation,gdouble major_step)5100 void gtk_plot_set_major_ticks (GtkPlot *plot,
5101 GtkPlotOrientation orientation,
5102 gdouble major_step)
5103 {
5104 if(orientation == GTK_PLOT_AXIS_X){
5105 gtk_plot_axis_set_major_ticks(plot->top, major_step);
5106 gtk_plot_axis_set_major_ticks(plot->bottom, major_step);
5107 } else {
5108 gtk_plot_axis_set_major_ticks(plot->left, major_step);
5109 gtk_plot_axis_set_major_ticks(plot->right, major_step);
5110 }
5111 }
5112
5113 /**
5114 * gtk_plot_set_minor_ticks:
5115 * @plot: a #GtkPlot widget.
5116 * @orientation:
5117 * @nminor:
5118 *
5119 *
5120 */
gtk_plot_set_minor_ticks(GtkPlot * plot,GtkPlotOrientation orientation,gint nminor)5121 void gtk_plot_set_minor_ticks (GtkPlot *plot,
5122 GtkPlotOrientation orientation,
5123 gint nminor)
5124 {
5125 if(orientation == GTK_PLOT_AXIS_X){
5126 gtk_plot_axis_set_minor_ticks(plot->top, nminor);
5127 gtk_plot_axis_set_minor_ticks(plot->bottom, nminor);
5128 } else {
5129 gtk_plot_axis_set_minor_ticks(plot->left, nminor);
5130 gtk_plot_axis_set_minor_ticks(plot->right, nminor);
5131 }
5132 }
5133
5134 /**
5135 * gtk_plot_set_ticks_limits:
5136 * @plot: a #GtkPlot widget.
5137 * @orientation:
5138 * @begin:
5139 * @end:
5140 *
5141 *
5142 */
5143
gtk_plot_set_ticks_limits(GtkPlot * plot,GtkPlotOrientation orientation,gdouble begin,gdouble end)5144 void gtk_plot_set_ticks_limits (GtkPlot *plot,
5145 GtkPlotOrientation orientation,
5146 gdouble begin, gdouble end)
5147 {
5148 if(orientation == GTK_PLOT_AXIS_X){
5149 gtk_plot_axis_set_ticks_limits(plot->top, begin, end);
5150 gtk_plot_axis_set_ticks_limits(plot->bottom, begin, end);
5151 } else {
5152 gtk_plot_axis_set_ticks_limits(plot->left, begin, end);
5153 gtk_plot_axis_set_ticks_limits(plot->right, begin, end);
5154 }
5155 }
5156
5157 /**
5158 * gtk_plot_unset_ticks_limits:
5159 * @plot: a #GtkPlot widget.
5160 * @orientation:
5161 *
5162 *
5163 */
gtk_plot_unset_ticks_limits(GtkPlot * plot,GtkPlotOrientation orientation)5164 void gtk_plot_unset_ticks_limits (GtkPlot *plot,
5165 GtkPlotOrientation orientation)
5166 {
5167 if(orientation == GTK_PLOT_AXIS_X){
5168 gtk_plot_axis_unset_ticks_limits(plot->top);
5169 gtk_plot_axis_unset_ticks_limits(plot->bottom);
5170 } else {
5171 gtk_plot_axis_unset_ticks_limits(plot->left);
5172 gtk_plot_axis_unset_ticks_limits(plot->right);
5173 }
5174 }
5175
5176 /**
5177 * gtk_plot_set_break:
5178 * @plot: a #GtkPlot widget.
5179 * @orientation:
5180 * @min:
5181 * @max:
5182 * @step_after:
5183 * @nminor_after:
5184 * @scale_after:
5185 * @pos:
5186 *
5187 *
5188 */
gtk_plot_set_break(GtkPlot * plot,GtkPlotOrientation orientation,gdouble min,gdouble max,gdouble step_after,gint nminor_after,GtkPlotScale scale_after,gdouble pos)5189 void gtk_plot_set_break (GtkPlot *plot,
5190 GtkPlotOrientation orientation,
5191 gdouble min, gdouble max,
5192 gdouble step_after,
5193 gint nminor_after,
5194 GtkPlotScale scale_after,
5195 gdouble pos)
5196 {
5197 if(orientation== GTK_PLOT_AXIS_X){
5198 gtk_plot_axis_set_break(plot->top, min, max, step_after, nminor_after, scale_after, pos);
5199 gtk_plot_axis_set_break(plot->bottom, min, max, step_after, nminor_after, scale_after, pos);
5200 } else {
5201 gtk_plot_axis_set_break(plot->left, min, max, step_after, nminor_after, scale_after, pos);
5202 gtk_plot_axis_set_break(plot->right, min, max, step_after, nminor_after, scale_after, pos);
5203 }
5204 }
5205
5206 /**
5207 * gtk_plot_remove_break:
5208 * @plot: a #GtkPlot widget.
5209 * @orientation:
5210 *
5211 *
5212 */
gtk_plot_remove_break(GtkPlot * plot,GtkPlotOrientation orientation)5213 void gtk_plot_remove_break (GtkPlot *plot,
5214 GtkPlotOrientation orientation)
5215 {
5216 if(orientation == GTK_PLOT_AXIS_X){
5217 gtk_plot_axis_remove_break(plot->top);
5218 gtk_plot_axis_remove_break(plot->bottom);
5219 } else {
5220 gtk_plot_axis_remove_break(plot->left);
5221 gtk_plot_axis_remove_break(plot->right);
5222 }
5223 }
5224
5225
5226
5227 /******************************************
5228 * gtk_plot_get_axis
5229 * gtk_plot_axis_set_visible
5230 * gtk_plot_axis_visible
5231 * gtk_plot_axis_set_title
5232 * gtk_plot_axis_show_title
5233 * gtk_plot_axis_hide_title
5234 * gtk_plot_axis_move_title
5235 * gtk_plot_axis_justify_title
5236 * gtk_plot_axis_show_labels
5237 * gtk_plot_axis_set_attributes
5238 * gtk_plot_axis_get_attributes
5239 * gtk_plot_axis_set_ticks
5240 * gtk_plot_axis_set_major_ticks
5241 * gtk_plot_axis_set_minor_ticks
5242 * gtk_plot_axis_set_ticks_length
5243 * gtk_plot_axis_show_ticks
5244 * gtk_plot_axis_set_ticks_limits
5245 * gtk_plot_axis_unset_ticks_limits
5246 * gtk_plot_axis_labels_set_attributes
5247 * gtk_plot_axis_labels_set_numbers
5248 ******************************************/
5249
5250 /**
5251 * gtk_plot_get_axis:
5252 * @plot: a #GtkPlot widget.
5253 * @axis: a #GtkPlotAxis.
5254 *
5255 * Return value: (transfer none) the #GtkPlotAxis at the given
5256 * position
5257 */
5258 GtkPlotAxis *
gtk_plot_get_axis(GtkPlot * plot,GtkPlotAxisPos axis)5259 gtk_plot_get_axis (GtkPlot *plot, GtkPlotAxisPos axis)
5260 {
5261 GtkPlotAxis *aux = NULL;
5262
5263 switch(axis){
5264 case GTK_PLOT_AXIS_LEFT:
5265 aux = plot->left;
5266 break;
5267 case GTK_PLOT_AXIS_RIGHT:
5268 aux = plot->right;
5269 break;
5270 case GTK_PLOT_AXIS_TOP:
5271 aux = plot->top;
5272 break;
5273 case GTK_PLOT_AXIS_BOTTOM:
5274 aux = plot->bottom;
5275 break;
5276 default:
5277 break;
5278 }
5279 return aux;
5280 }
5281
5282
5283 /**
5284 * gtk_plot_axis_set_visible:
5285 * @axis: a #GtkPlotAxis.
5286 * @visible:
5287 *
5288 *
5289 */
5290 void
gtk_plot_axis_set_visible(GtkPlotAxis * axis,gboolean visible)5291 gtk_plot_axis_set_visible (GtkPlotAxis *axis, gboolean visible)
5292 {
5293 GtkPlotAxis *aux = axis;
5294
5295 aux->is_visible = visible;
5296
5297 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5298 }
5299
5300 /**
5301 * gtk_plot_axis_visible:
5302 * @axis: a #GtkPlotAxis.
5303 *
5304 *
5305 *
5306 * Return value:
5307 */
5308 gboolean
gtk_plot_axis_visible(GtkPlotAxis * axis)5309 gtk_plot_axis_visible (GtkPlotAxis *axis)
5310 {
5311 GtkPlotAxis *aux = axis;
5312
5313 return aux->is_visible;
5314 }
5315
5316
5317 /**
5318 * gtk_plot_axis_set_title:
5319 * @axis: a #GtkPlotAxis.
5320 * @title
5321 *
5322 *
5323 */
5324 void
gtk_plot_axis_set_title(GtkPlotAxis * axis,const gchar * title)5325 gtk_plot_axis_set_title (GtkPlotAxis *axis, const gchar *title)
5326 {
5327 GtkPlotAxis *aux = axis;
5328
5329 if(aux->title.text)
5330 g_free(aux->title.text);
5331
5332 aux->title.text = g_strdup(title);
5333
5334 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5335 }
5336
5337 /**
5338 * gtk_plot_axis_show_title:
5339 * @axis: a #GtkPlotAxis.
5340 *
5341 *
5342 */
5343 void
gtk_plot_axis_show_title(GtkPlotAxis * axis)5344 gtk_plot_axis_show_title (GtkPlotAxis *axis)
5345 {
5346 GtkPlotAxis *aux = axis;
5347
5348 aux->title_visible = TRUE;
5349
5350 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5351 }
5352
5353 /**
5354 * gtk_plot_axis_hide_title:
5355 * @axis: a #GtkPlotAxis.
5356 *
5357 *
5358 */
5359 void
gtk_plot_axis_hide_title(GtkPlotAxis * axis)5360 gtk_plot_axis_hide_title (GtkPlotAxis *axis)
5361 {
5362 GtkPlotAxis *aux = axis;
5363
5364 aux->title_visible = FALSE;
5365
5366 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5367 }
5368
5369 /**
5370 * gtk_plot_axis_move_title:
5371 * @axis: a #GtkPlotAxis.
5372 * @angle:
5373 * @x:
5374 * @y:
5375 *
5376 *
5377 */
5378 void
gtk_plot_axis_move_title(GtkPlotAxis * axis,gint angle,gdouble x,gdouble y)5379 gtk_plot_axis_move_title (GtkPlotAxis *axis, gint angle, gdouble x, gdouble y)
5380 {
5381 GtkPlotAxis *aux = axis;
5382
5383 aux->title.angle = angle;
5384 aux->title.x = x;
5385 aux->title.y = y;
5386
5387 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5388 }
5389
5390 /**
5391 * gtk_plot_axis_justify_title:
5392 * @axis: a #GtkPlotAxis.
5393 * @justification:
5394 *
5395 *
5396 */
5397 void
gtk_plot_axis_justify_title(GtkPlotAxis * axis,GtkJustification justification)5398 gtk_plot_axis_justify_title (GtkPlotAxis *axis, GtkJustification justification)
5399 {
5400 GtkPlotAxis *aux = axis;
5401
5402 aux->title.justification = justification;
5403
5404 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5405 }
5406
5407 /**
5408 * gtk_plot_axis_set_attributes:
5409 * @axis: a #GtkPlotAxis.
5410 * @width:
5411 * @color:
5412 *
5413 *
5414 */
5415 void
gtk_plot_axis_set_attributes(GtkPlotAxis * axis,gfloat width,const GdkRGBA * color)5416 gtk_plot_axis_set_attributes (GtkPlotAxis *axis,
5417 gfloat width, const GdkRGBA *color)
5418 {
5419 GtkPlotAxis *aux = axis;
5420
5421 aux->line.line_width = width;
5422
5423 aux->line.color = *color;
5424
5425 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5426 }
5427
5428 /**
5429 * gtk_plot_axis_get_attributes:
5430 * @axis: a #GtkPlotAxis.
5431 * @width:
5432 * color:
5433 *
5434 *
5435 */
5436 void
gtk_plot_axis_get_attributes(GtkPlotAxis * axis,gfloat * width,GdkRGBA * color)5437 gtk_plot_axis_get_attributes (GtkPlotAxis *axis,
5438 gfloat *width, GdkRGBA *color)
5439 {
5440 GtkPlotAxis *aux = axis;
5441
5442 *width = aux->line.line_width;
5443 *color = aux->line.color;
5444 }
5445
5446 /**
5447 * gtk_plot_axis_set_ticks:
5448 * @axis: a #GtkPlotAxis.
5449 * @major_step:
5450 * @nminor:
5451 *
5452 *
5453 */
5454 void
gtk_plot_axis_set_ticks(GtkPlotAxis * axis,gdouble major_step,gint nminor)5455 gtk_plot_axis_set_ticks (GtkPlotAxis *axis,
5456 gdouble major_step,
5457 gint nminor)
5458 {
5459 axis->ticks.step = major_step;
5460 axis->ticks.nminor = nminor;
5461 gtk_plot_axis_ticks_recalc(axis);
5462 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5463 }
5464
5465 /**
5466 * gtk_plot_axis_set_major_ticks:
5467 * @axis: a #GtkPlotAxis.
5468 * @major_step:
5469 *
5470 *
5471 */
5472 void
gtk_plot_axis_set_major_ticks(GtkPlotAxis * axis,gdouble major_step)5473 gtk_plot_axis_set_major_ticks (GtkPlotAxis *axis,
5474 gdouble major_step)
5475 {
5476 axis->ticks.step = major_step;
5477 gtk_plot_axis_ticks_recalc(axis);
5478 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5479 }
5480
5481 /**
5482 * gtk_plot_axis_set_minor_ticks:
5483 * @axis: a #GtkPlotAxis.
5484 * @nminor:
5485 *
5486 *
5487 */
5488 void
gtk_plot_axis_set_minor_ticks(GtkPlotAxis * axis,gint nminor)5489 gtk_plot_axis_set_minor_ticks (GtkPlotAxis *axis,
5490 gint nminor)
5491 {
5492 axis->ticks.nminor = nminor;
5493 gtk_plot_axis_ticks_recalc(axis);
5494 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5495 }
5496
5497 /**
5498 * gtk_plot_axis_set_ticks_length:
5499 * @axis: a #GtkPlotAxis.
5500 * @length:
5501 *
5502 *
5503 */
5504 void
gtk_plot_axis_set_ticks_length(GtkPlotAxis * axis,gint length)5505 gtk_plot_axis_set_ticks_length (GtkPlotAxis *axis, gint length)
5506 {
5507 GtkPlotAxis *aux = axis;
5508 aux->ticks_length = length;
5509 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5510 }
5511
5512 /**
5513 * gtk_plot_axis_set_ticks_width:
5514 * @axis: a #GtkPlotAxis.
5515 * @width:
5516 *
5517 *
5518 */
5519 void
gtk_plot_axis_set_ticks_width(GtkPlotAxis * axis,gfloat width)5520 gtk_plot_axis_set_ticks_width (GtkPlotAxis *axis, gfloat width)
5521 {
5522 GtkPlotAxis *aux = axis;
5523
5524 aux->ticks_width = width;
5525 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5526 }
5527
5528 /**
5529 * gtk_plot_axis_show_ticks:
5530 * @axis: a #GtkPlotAxis.
5531 * @major_mask:
5532 * @minor_mask:
5533 *
5534 *
5535 */
5536 void
gtk_plot_axis_show_ticks(GtkPlotAxis * axis,gint major_mask,gint minor_mask)5537 gtk_plot_axis_show_ticks (GtkPlotAxis *axis,
5538 gint major_mask,
5539 gint minor_mask)
5540 {
5541 GtkPlotAxis *aux = axis;
5542
5543 aux->major_mask = major_mask;
5544 aux->minor_mask = minor_mask;
5545
5546 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5547 }
5548
5549 /**
5550 * gtk_plot_axis_set_ticks_limits:
5551 * @axis: a #GtkPlotAxis.
5552 * @begin:
5553 * @end:
5554 *
5555 *
5556 */
5557 void
gtk_plot_axis_set_ticks_limits(GtkPlotAxis * axis,gdouble begin,gdouble end)5558 gtk_plot_axis_set_ticks_limits (GtkPlotAxis *axis,
5559 gdouble begin, gdouble end)
5560 {
5561 if(end < begin) return;
5562
5563 axis->ticks.begin = begin;
5564 axis->ticks.end = end;
5565 axis->ticks.set_limits = TRUE;
5566 gtk_plot_axis_ticks_recalc(axis);
5567
5568 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5569 }
5570
5571 /**
5572 * gtk_plot_axis_unset_ticks_limits:
5573 * @axis: a #GtkPlotAxis.
5574 *
5575 *
5576 */
5577 void
gtk_plot_axis_unset_ticks_limits(GtkPlotAxis * axis)5578 gtk_plot_axis_unset_ticks_limits (GtkPlotAxis *axis)
5579 {
5580 axis->ticks.set_limits = FALSE;
5581 gtk_plot_axis_ticks_recalc(axis);
5582
5583 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5584 }
5585
5586 /**
5587 * gtk_plot_axis_set_ticks_labels:
5588 * @axis: a #GtkPlotAxis.
5589 * @labels:
5590 *
5591 *
5592 */
5593 void
gtk_plot_axis_set_tick_labels(GtkPlotAxis * axis,GtkPlotArray * labels)5594 gtk_plot_axis_set_tick_labels (GtkPlotAxis *axis, GtkPlotArray *labels)
5595 {
5596 if(axis->tick_labels) g_object_unref(G_OBJECT(axis->tick_labels));
5597 axis->tick_labels = labels;
5598
5599 if(labels){
5600 if(labels->name) g_free(labels->name);
5601 labels->name = g_strdup("tick_labels");
5602 g_object_ref(G_OBJECT(labels));
5603 }
5604 }
5605
5606 /**
5607 * gtk_plot_axis_set_break:
5608 * @axis: a #GtkPlotAxis.
5609 * @min:
5610 * @max:
5611 * @step_after:
5612 * @nminor_after:
5613 * @scale_after:
5614 * @pos:
5615 *
5616 *
5617 */
5618 void
gtk_plot_axis_set_break(GtkPlotAxis * axis,gdouble min,gdouble max,gdouble step_after,gint nminor_after,GtkPlotScale scale_after,gdouble pos)5619 gtk_plot_axis_set_break (GtkPlotAxis *axis,
5620 gdouble min, gdouble max,
5621 gdouble step_after,
5622 gint nminor_after,
5623 GtkPlotScale scale_after,
5624 gdouble pos)
5625 {
5626 axis->ticks.break_min = min;
5627 axis->ticks.break_max = max;
5628 axis->ticks.apply_break = TRUE;
5629 axis->ticks.break_step = step_after;
5630 axis->ticks.break_nminor = nminor_after;
5631 axis->ticks.break_position = pos;
5632 axis->ticks.break_scale = scale_after;
5633
5634 gtk_plot_axis_ticks_recalc(axis);
5635 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5636 }
5637
5638 /**
5639 * gtk_plot_axis_remove_break:
5640 * @axis: a #GtkPlotAxis.
5641 *
5642 *
5643 */
5644 void
gtk_plot_axis_remove_break(GtkPlotAxis * axis)5645 gtk_plot_axis_remove_break (GtkPlotAxis *axis)
5646 {
5647 axis->ticks.apply_break = FALSE;
5648 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5649 }
5650
5651 /**
5652 * gtk_plot_axis_show_labels:
5653 * @axis: a #GtkPlotAxis.
5654 * @labels_mask:
5655 *
5656 *
5657 */
5658 void
gtk_plot_axis_show_labels(GtkPlotAxis * axis,gint labels_mask)5659 gtk_plot_axis_show_labels (GtkPlotAxis *axis, gint labels_mask)
5660 {
5661 GtkPlotAxis *aux = axis;
5662
5663 aux->label_mask = labels_mask;
5664
5665 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5666 }
5667
5668
5669 /**
5670 * gtk_plot_axis_title_set_attributes:
5671 * @axis: a #GtkPlotAxis.
5672 * @font:
5673 * @height:
5674 * @angle:
5675 * @fg:
5676 * @bg:
5677 * @transparent:
5678 * @justification:
5679 *
5680 *
5681 */
5682 void
gtk_plot_axis_title_set_attributes(GtkPlotAxis * axis,const gchar * font,gint height,gint angle,const GdkRGBA * fg,const GdkRGBA * bg,gboolean transparent,GtkJustification justification)5683 gtk_plot_axis_title_set_attributes (GtkPlotAxis *axis,
5684 const gchar *font,
5685 gint height,
5686 gint angle,
5687 const GdkRGBA *fg,
5688 const GdkRGBA *bg,
5689 gboolean transparent,
5690 GtkJustification justification)
5691 {
5692 GtkPlotAxis *aux = axis;
5693
5694 if(!font){
5695 /* Use previous font */
5696 /* aux->title.font = g_strdup(DEFAULT_FONT);
5697 aux->title.height = DEFAULT_FONT_HEIGHT;
5698 */
5699 } else {
5700 if(aux->title.font) g_free(aux->title.font);
5701 aux->title.font = g_strdup(font);
5702 aux->title.height = height;
5703 }
5704
5705 gdk_rgba_parse(&axis->title.fg, "black");
5706 gdk_rgba_parse(&axis->title.bg, "white");
5707
5708 if(fg) aux->title.fg = *fg;
5709 if(bg) aux->title.bg = *bg;
5710
5711 aux->title.angle = angle;
5712 aux->title.transparent = transparent;
5713 aux->title.justification = justification;
5714
5715 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5716 }
5717
5718 /**
5719 * gtk_plot_axis_set_labels_offset:
5720 * @axis: a #GtkPlotAxis.
5721 * @offset:
5722 *
5723 *
5724 */
5725 void
gtk_plot_axis_set_labels_offset(GtkPlotAxis * axis,gint offset)5726 gtk_plot_axis_set_labels_offset (GtkPlotAxis *axis,
5727 gint offset)
5728 {
5729 GtkPlotAxis *aux = axis;
5730
5731 aux->labels_offset = offset;
5732 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5733 }
5734
5735 /**
5736 * gtk_plot_axis_get_labels_offset:
5737 * @axis: a #GtkPlotAxis.
5738 *
5739 *
5740 *
5741 * Return value:
5742 */
5743 gint
gtk_plot_axis_get_labels_offset(GtkPlotAxis * axis)5744 gtk_plot_axis_get_labels_offset (GtkPlotAxis *axis)
5745 {
5746 GtkPlotAxis *aux = axis;
5747
5748 return(aux->labels_offset);
5749 }
5750
5751 /**
5752 * gtk_plot_axis_set_labels_attributes:
5753 * @axis: a #GtkPlotAxis.
5754 * @font:
5755 * @height:
5756 * @angle:
5757 * @fg:
5758 * @bg:
5759 * @transparent:
5760 * @justification:
5761 *
5762 *
5763 */
5764 void
gtk_plot_axis_set_labels_attributes(GtkPlotAxis * axis,const gchar * font,gint height,gint angle,const GdkRGBA * fg,const GdkRGBA * bg,gboolean transparent,GtkJustification justification)5765 gtk_plot_axis_set_labels_attributes (GtkPlotAxis *axis,
5766 const gchar *font,
5767 gint height,
5768 gint angle,
5769 const GdkRGBA *fg,
5770 const GdkRGBA *bg,
5771 gboolean transparent,
5772 GtkJustification justification)
5773 {
5774 GtkPlotAxis *aux = axis;
5775
5776 if(!font){
5777 /* Use previous font */
5778 /* aux->labels_attr.font = g_strdup(DEFAULT_FONT);
5779 aux->labels_attr.height = DEFAULT_FONT_HEIGHT;
5780 */
5781 } else {
5782 if(aux->labels_attr.font) g_free(aux->labels_attr.font);
5783 aux->labels_attr.font = g_strdup(font);
5784 aux->labels_attr.height = height;
5785 }
5786
5787 aux->labels_attr.angle = angle;
5788
5789 gdk_rgba_parse(&axis->labels_attr.fg, "black");
5790 gdk_rgba_parse(&axis->labels_attr.bg, "white");
5791
5792 if(fg) aux->labels_attr.fg = *fg;
5793 if(bg) aux->labels_attr.bg = *bg;
5794
5795 aux->labels_attr.transparent = transparent;
5796 aux->labels_attr.justification = justification;
5797
5798 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5799 }
5800
5801 /**
5802 * gtk_plot_axis_set_labels_style:
5803 * @axis: a #GtkPlotAxis.
5804 * @style:
5805 * @precision:
5806 *
5807 *
5808 */
5809 void
gtk_plot_axis_set_labels_style(GtkPlotAxis * axis,GtkPlotLabelStyle style,gint precision)5810 gtk_plot_axis_set_labels_style (GtkPlotAxis *axis,
5811 GtkPlotLabelStyle style,
5812 gint precision)
5813 {
5814 GtkPlotAxis *aux = axis;
5815
5816 aux->label_style = style;
5817 aux->label_precision = precision;
5818
5819 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5820 }
5821
5822 /**
5823 * gtk_plot_axis_use_custom_ticks_labels:
5824 * @axis: a #GtkPlotAxis.
5825 * @use:
5826 *
5827 *
5828 */
5829 void
gtk_plot_axis_use_custom_tick_labels(GtkPlotAxis * axis,gboolean use)5830 gtk_plot_axis_use_custom_tick_labels (GtkPlotAxis *axis,
5831 gboolean use)
5832 {
5833 axis->custom_labels = use;
5834
5835 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5836 }
5837
5838 /**
5839 * gtk_plot_axis_set_labels_prefix:
5840 * @axis: a #GtkPlotAxis.
5841 * @text:
5842 *
5843 *
5844 */
5845 void
gtk_plot_axis_set_labels_prefix(GtkPlotAxis * axis,const gchar * text)5846 gtk_plot_axis_set_labels_prefix (GtkPlotAxis *axis,
5847 const gchar *text)
5848 {
5849 if(axis->labels_prefix) g_free(axis->labels_prefix);
5850
5851 if(text)
5852 axis->labels_prefix = g_strdup(text);
5853 else
5854 axis->labels_prefix = NULL;
5855
5856 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5857 }
5858
5859 /**
5860 * gtk_plot_axis_set_labels_suffix:
5861 * @axis: a #GtkPlotAxis.
5862 * @text:
5863 *
5864 *
5865 */
5866 void
gtk_plot_axis_set_labels_suffix(GtkPlotAxis * axis,const gchar * text)5867 gtk_plot_axis_set_labels_suffix (GtkPlotAxis *axis,
5868 const gchar *text)
5869 {
5870 if(axis->labels_suffix) g_free(axis->labels_suffix);
5871
5872 if(text)
5873 axis->labels_suffix = g_strdup(text);
5874 else
5875 axis->labels_suffix = NULL;
5876
5877 g_signal_emit (axis, axis_signals[AXIS_CHANGED], 0);
5878 }
5879
5880 /**
5881 * gtk_plot_axis_get_labels_prefix:
5882 * @axis: a #GtkPlotAxis.
5883 *
5884 *
5885 *
5886 * Return value:
5887 */
5888 gchar *
gtk_plot_axis_get_labels_prefix(GtkPlotAxis * axis)5889 gtk_plot_axis_get_labels_prefix (GtkPlotAxis *axis)
5890 {
5891 return (axis->labels_prefix);
5892 }
5893
5894 /**
5895 * gtk_plot_axis_get_labels_suffix:
5896 * @axis: a #GtkPlotAxis.
5897 *
5898 *
5899 *
5900 * Return value:
5901 */
5902 gchar *
gtk_plot_axis_get_labels_suffix(GtkPlotAxis * axis)5903 gtk_plot_axis_get_labels_suffix (GtkPlotAxis *axis)
5904 {
5905 return (axis->labels_suffix);
5906 }
5907
5908 /******************************************
5909 * gtk_plot_x0line_set_attributes
5910 * gtk_plot_y0line_set_attributes
5911 * gtk_plot_major_vgrid_set_attributes
5912 * gtk_plot_minor_vgrid_set_attributes
5913 * gtk_plot_major_hgrid_set_attributes
5914 * gtk_plot_minor_hgrid_set_attributes
5915 ******************************************/
5916
5917 /**
5918 * gtk_plot_x0_set_visible:
5919 * @plot: a #GtkPlot widget.
5920 * @visible:
5921 *
5922 *
5923 */
5924 void
gtk_plot_x0_set_visible(GtkPlot * plot,gboolean visible)5925 gtk_plot_x0_set_visible(GtkPlot *plot, gboolean visible)
5926 {
5927 plot->show_x0 = visible;
5928
5929 g_signal_emit (plot, plot_signals[CHANGED], 0);
5930 }
5931
5932 /**
5933 * gtk_plot_x0_visible:
5934 * @plot: a #GtkPlot widget.
5935 *
5936 *
5937 *
5938 * Return value:
5939 */
5940 gboolean
gtk_plot_x0_visible(GtkPlot * plot)5941 gtk_plot_x0_visible(GtkPlot *plot)
5942 {
5943 return plot->show_x0;
5944 }
5945
5946 /**
5947 * gtk_plot_y0_set_visible:
5948 * @plot: a #GtkPlot widget.
5949 * @visible:
5950 *
5951 *
5952 */
5953 void
gtk_plot_y0_set_visible(GtkPlot * plot,gboolean visible)5954 gtk_plot_y0_set_visible(GtkPlot *plot, gboolean visible)
5955 {
5956 plot->show_y0 = visible;
5957
5958 g_signal_emit (plot, plot_signals[CHANGED], 0);
5959 }
5960
5961 /**
5962 * gtk_plot_y0_visible:
5963 * @plot: a #GtkPlot widget.
5964 *
5965 *
5966 *
5967 * Return value:
5968 */
5969 gboolean
gtk_plot_y0_visible(GtkPlot * plot)5970 gtk_plot_y0_visible(GtkPlot *plot)
5971 {
5972 return plot->show_y0;
5973 }
5974
5975 /**
5976 * gtk_plot_grids_set_on_top:
5977 * @plot: a #GtkPlot widget.
5978 * @on_top:
5979 *
5980 *
5981 */
5982 void
gtk_plot_grids_set_on_top(GtkPlot * plot,gboolean on_top)5983 gtk_plot_grids_set_on_top(GtkPlot *plot, gboolean on_top)
5984 {
5985 plot->grids_on_top = on_top;
5986 }
5987
5988 /**
5989 * gtk_plot_grids_on_top:
5990 * @plot: a #GtkPlot widget.
5991 *
5992 *
5993 *
5994 * Return value:
5995 */
5996 gboolean
gtk_plot_grids_on_top(GtkPlot * plot)5997 gtk_plot_grids_on_top(GtkPlot *plot)
5998 {
5999 return(plot->grids_on_top);
6000 }
6001
6002 /**
6003 * gtk_plot_grids_set_visible:
6004 * @plot: a #GtkPlot widget.
6005 * @vmajor:
6006 * @vminor:
6007 * @hmajor:
6008 * @hminor:
6009 *
6010 *
6011 */
6012 void
gtk_plot_grids_set_visible(GtkPlot * plot,gboolean vmajor,gboolean vminor,gboolean hmajor,gboolean hminor)6013 gtk_plot_grids_set_visible(GtkPlot *plot,
6014 gboolean vmajor, gboolean vminor,
6015 gboolean hmajor, gboolean hminor)
6016 {
6017 plot->bottom->show_major_grid = vmajor;
6018 plot->bottom->show_minor_grid = vminor;
6019 plot->left->show_major_grid = hmajor;
6020 plot->left->show_minor_grid = hminor;
6021
6022 g_signal_emit (plot, plot_signals[CHANGED], 0);
6023 }
6024
6025 /**
6026 * gtk_plot_grids_visible:
6027 * @plot: a #GtkPlot widget.
6028 * @vmajor:
6029 * @vminor:
6030 * @hmajor:
6031 * @hminor:
6032 *
6033 *
6034 */
6035 void
gtk_plot_grids_visible(GtkPlot * plot,gboolean * vmajor,gboolean * vminor,gboolean * hmajor,gboolean * hminor)6036 gtk_plot_grids_visible(GtkPlot *plot,
6037 gboolean *vmajor, gboolean *vminor,
6038 gboolean *hmajor, gboolean *hminor)
6039 {
6040 *vmajor = plot->bottom->show_major_grid;
6041 *vminor = plot->bottom->show_minor_grid;
6042 *hmajor = plot->left->show_major_grid;
6043 *hminor = plot->left->show_minor_grid;
6044 }
6045
6046 /**
6047 * gtk_plot_x0line_set_visible:
6048 * @plot: a #GtkPlot widget.
6049 * @line_style:
6050 * @width:
6051 * @color:
6052 *
6053 *
6054 */
6055 void
gtk_plot_x0line_set_attributes(GtkPlot * plot,GtkPlotLineStyle line_style,gfloat width,const GdkRGBA * color)6056 gtk_plot_x0line_set_attributes(GtkPlot *plot,
6057 GtkPlotLineStyle line_style,
6058 gfloat width,
6059 const GdkRGBA *color)
6060 {
6061 plot->x0_line.line_style = line_style;
6062 plot->x0_line.line_width = width;
6063 if(color) plot->x0_line.color = *color;
6064
6065 g_signal_emit (plot, plot_signals[CHANGED], 0);
6066 }
6067
6068 /**
6069 * gtk_plot_y0line_set_attributes:
6070 * @plot: a #GtkPlot widget.
6071 * @line_style:
6072 * @width:
6073 * @color:
6074 *
6075 *
6076 */
6077 void
gtk_plot_y0line_set_attributes(GtkPlot * plot,GtkPlotLineStyle line_style,gfloat width,const GdkRGBA * color)6078 gtk_plot_y0line_set_attributes(GtkPlot *plot,
6079 GtkPlotLineStyle line_style,
6080 gfloat width,
6081 const GdkRGBA *color)
6082 {
6083 plot->y0_line.line_style = line_style;
6084 plot->y0_line.line_width = width;
6085 if(color) plot->y0_line.color = *color;
6086
6087 g_signal_emit (plot, plot_signals[CHANGED], 0);
6088 }
6089
6090 /**
6091 * gtk_plot_major_vgrid_set_Attributes:
6092 * @plot: a #GtkPlot widget.
6093 * @line_style:
6094 * @width:
6095 * @color:
6096 *
6097 *
6098 */
6099 void
gtk_plot_major_vgrid_set_attributes(GtkPlot * plot,GtkPlotLineStyle line_style,gfloat width,const GdkRGBA * color)6100 gtk_plot_major_vgrid_set_attributes(GtkPlot *plot,
6101 GtkPlotLineStyle line_style,
6102 gfloat width,
6103 const GdkRGBA *color)
6104 {
6105 plot->bottom->major_grid.line_style = line_style;
6106 plot->bottom->major_grid.line_width = width;
6107 if(color) plot->bottom->major_grid.color = *color;
6108
6109 g_signal_emit (plot, plot_signals[CHANGED], 0);
6110 }
6111
6112 /**
6113 * gtk_plot_minor_vgrid_set_attributes:
6114 * @plot: a #GtkPlot widget.
6115 * @line_style:
6116 * @width:
6117 * @color:
6118 *
6119 *
6120 */
6121 void
gtk_plot_minor_vgrid_set_attributes(GtkPlot * plot,GtkPlotLineStyle line_style,gfloat width,const GdkRGBA * color)6122 gtk_plot_minor_vgrid_set_attributes(GtkPlot *plot,
6123 GtkPlotLineStyle line_style,
6124 gfloat width,
6125 const GdkRGBA *color)
6126 {
6127 plot->bottom->minor_grid.line_style = line_style;
6128 plot->bottom->minor_grid.line_width = width;
6129 if(color) plot->bottom->minor_grid.color = *color;
6130
6131 g_signal_emit (plot, plot_signals[CHANGED], 0);
6132 }
6133
6134 /**
6135 * gtk_plot_major_hgrid_set_attributes:
6136 * @plot: a #GtkPlot widget.
6137 * @line_style:
6138 * @width:
6139 * @color:
6140 *
6141 *
6142 */
6143 void
gtk_plot_major_hgrid_set_attributes(GtkPlot * plot,GtkPlotLineStyle line_style,gfloat width,const GdkRGBA * color)6144 gtk_plot_major_hgrid_set_attributes(GtkPlot *plot,
6145 GtkPlotLineStyle line_style,
6146 gfloat width,
6147 const GdkRGBA *color)
6148 {
6149 plot->left->major_grid.line_style = line_style;
6150 plot->left->major_grid.line_width = width;
6151 if(color) plot->left->major_grid.color = *color;
6152
6153 g_signal_emit (plot, plot_signals[CHANGED], 0);
6154 }
6155
6156 /**
6157 * gtk_plot_minor_hgrid_set_attributes:
6158 * @plot: a #GtkPlot widget.
6159 * @line_style:
6160 * @width:
6161 * @color:
6162 *
6163 *
6164 */
6165 void
gtk_plot_minor_hgrid_set_attributes(GtkPlot * plot,GtkPlotLineStyle line_style,gfloat width,const GdkRGBA * color)6166 gtk_plot_minor_hgrid_set_attributes(GtkPlot *plot,
6167 GtkPlotLineStyle line_style,
6168 gfloat width,
6169 const GdkRGBA *color)
6170 {
6171 plot->left->minor_grid.line_style = line_style;
6172 plot->left->minor_grid.line_width = width;
6173 if(color) plot->left->minor_grid.color = *color;
6174
6175 g_signal_emit (plot, plot_signals[CHANGED], 0);
6176 }
6177
6178 /******************************************
6179 * gtk_plot_show_legends
6180 * gtk_plot_hide_legends
6181 * gtk_plot_show_legends_border
6182 * gtk_plot_hide_legends_border
6183 * gtk_plot_legends_move
6184 * gtk_plot_legends_get_position
6185 * gtk_plot_legends_get_allocation
6186 * gtk_plot_set_legends_attributes
6187 ******************************************/
6188
6189 /**
6190 * gtk_plot_show_legends:
6191 * @plot: a #GtkPlot widget.
6192 *
6193 *
6194 */
6195 void
gtk_plot_show_legends(GtkPlot * plot)6196 gtk_plot_show_legends(GtkPlot *plot)
6197 {
6198 plot->show_legends = TRUE;
6199
6200 g_signal_emit (plot, plot_signals[CHANGED], 0);
6201 }
6202
6203 /**
6204 * gtk_plot_hide_legends:
6205 * @plot: a #GtkPlot widget.
6206 *
6207 *
6208 */
6209 void
gtk_plot_hide_legends(GtkPlot * plot)6210 gtk_plot_hide_legends(GtkPlot *plot)
6211 {
6212 plot->show_legends = FALSE;
6213
6214 g_signal_emit (plot, plot_signals[CHANGED], 0);
6215 }
6216
6217 /**
6218 * gtk_plot_set_legends_border:
6219 * @plot: a #GtkPlot widget.
6220 * @legends_border:
6221 * @shadow_width:
6222 *
6223 *
6224 */
6225 void
gtk_plot_set_legends_border(GtkPlot * plot,GtkPlotBorderStyle legends_border,gint shadow_width)6226 gtk_plot_set_legends_border(GtkPlot *plot,
6227 GtkPlotBorderStyle legends_border,
6228 gint shadow_width)
6229 {
6230 plot->legends_border = legends_border;
6231 plot->legends_shadow_width = shadow_width;
6232
6233 g_signal_emit (plot, plot_signals[CHANGED], 0);
6234 }
6235
6236 /**
6237 * gtk_plot_legends_move:
6238 * @plot: a #GtkPlot widget.
6239 * @x:
6240 * @y:
6241 *
6242 *
6243 */
6244 void
gtk_plot_legends_move(GtkPlot * plot,gdouble x,gdouble y)6245 gtk_plot_legends_move(GtkPlot *plot, gdouble x, gdouble y)
6246 {
6247 plot->legends_x = x;
6248 plot->legends_y = y;
6249
6250 g_signal_emit (plot, plot_signals[CHANGED], 0);
6251 }
6252
6253 /**
6254 * gtk_plot_legends_get_position:
6255 * @plot: a #GtkPlot widget.
6256 * @x:
6257 * @y:
6258 *
6259 */
6260 void
gtk_plot_legends_get_position(GtkPlot * plot,gdouble * x,gdouble * y)6261 gtk_plot_legends_get_position(GtkPlot *plot, gdouble *x, gdouble *y)
6262 {
6263 *x = plot->legends_x;
6264 *y = plot->legends_y;
6265 }
6266
6267 /**
6268 * gtk_plot_legends_get_allocation:
6269 * @plot: a #GtkPlot widget.
6270 *
6271 * Return value: (transfer full) the #GtkAllocation
6272 */
6273 GtkAllocation
gtk_plot_legends_get_allocation(GtkPlot * plot)6274 gtk_plot_legends_get_allocation(GtkPlot *plot)
6275 {
6276 GtkAllocation allocation;
6277 GtkWidget *widget;
6278 GList *datasets;
6279 gdouble x, y, width, height;
6280 gdouble m;
6281
6282 widget = GTK_WIDGET(plot);
6283 m = plot->magnification;
6284
6285 gtk_widget_get_allocation(widget, &allocation);
6286 x = allocation.x + plot->x * allocation.width +
6287 plot->legends_x * plot->width * allocation.width;
6288 y = allocation.y + plot->y * allocation.height +
6289 plot->legends_y * plot->height * allocation.height;
6290
6291 width = 24 * m;
6292 height = 8 * m;
6293
6294 datasets = g_list_first(plot->data_sets);
6295 while(datasets)
6296 {
6297 GtkPlotData *dataset;
6298 gint lwidth, lheight;
6299
6300 dataset = GTK_PLOT_DATA(datasets->data);
6301
6302 if(gtk_widget_get_visible(GTK_WIDGET(dataset)) && dataset->show_legend)
6303 {
6304 GTK_PLOT_DATA_CLASS(GTK_WIDGET_GET_CLASS(GTK_WIDGET(dataset)))->get_legend_size(dataset, &lwidth, &lheight);
6305 width = MAX(width, lwidth);
6306 height += lheight;
6307 }
6308
6309 datasets = datasets->next;
6310 }
6311
6312 allocation.x = roundint(x);
6313 allocation.y = roundint(y);
6314 allocation.width = roundint(width);
6315 allocation.height = roundint(height);
6316
6317 return(allocation);
6318 }
6319
6320 /**
6321 * gtk_plot_legends_set_attributes:
6322 * @plot: a #GtkPlot widget.
6323 * @font:
6324 * @height:
6325 * @foreground:
6326 * @background:
6327 *
6328 *
6329 */
6330 void
gtk_plot_legends_set_attributes(GtkPlot * plot,const gchar * font,gint height,const GdkRGBA * foreground,const GdkRGBA * background)6331 gtk_plot_legends_set_attributes(GtkPlot *plot, const gchar *font, gint height,
6332 const GdkRGBA *foreground, const GdkRGBA *background)
6333 {
6334 GtkStyleContext *ctxt;
6335
6336 g_free(plot->legends_attr.font);
6337
6338 if(!font) {
6339 plot->legends_attr.font = g_strdup(DEFAULT_FONT);
6340 plot->legends_attr.height = DEFAULT_FONT_HEIGHT;
6341 } else {
6342 plot->legends_attr.font = g_strdup(font);
6343 plot->legends_attr.height = height;
6344 }
6345 ctxt = gtk_widget_get_style_context(GTK_WIDGET(plot));
6346 gtk_style_context_get(ctxt, GTK_STATE_FLAG_NORMAL,
6347 GTK_STYLE_PROPERTY_COLOR,
6348 &plot->legends_attr.fg,
6349 GTK_STYLE_PROPERTY_BACKGROUND_COLOR,
6350 &plot->legends_attr.bg, NULL);
6351
6352 if(foreground != NULL)
6353 plot->legends_attr.fg = *foreground;
6354
6355 plot->legends_attr.transparent = TRUE;
6356 if(background != NULL){
6357 plot->legends_attr.bg = *background;
6358 plot->legends_attr.transparent = FALSE;
6359 }
6360
6361 g_signal_emit (plot, plot_signals[CHANGED], 0);
6362 }
6363
6364 /**
6365 * gtk_plot_legends_add_data:
6366 * @plot: a #GtkPlot widget.
6367 * @dataset:
6368 *
6369 *
6370 */
6371 void
gtk_plot_add_data(GtkPlot * plot,GtkPlotData * dataset)6372 gtk_plot_add_data(GtkPlot *plot,
6373 GtkPlotData *dataset)
6374 {
6375 gboolean veto = TRUE;
6376
6377 _gtkextra_signal_emit (G_OBJECT(plot), plot_signals[ADD_DATA], dataset, &veto);
6378 plot->data_sets = g_list_append(plot->data_sets, dataset);
6379 g_object_ref(GTK_WIDGET(dataset));
6380 g_object_ref_sink(dataset);
6381 g_object_unref(dataset);
6382
6383 dataset->plot = plot;
6384
6385 g_signal_emit_by_name (dataset, "add_to_plot", plot, &veto);
6386 g_signal_emit (plot, plot_signals[CHANGED], 0);
6387 }
6388
6389 /**
6390 * gtk_plot_add_function:
6391 * @plot: a #GtkPlot widget.
6392 * @function: (scope async): the dataset generation function
6393 *
6394 * Return value: (transfer none) the #GtkPlotData
6395 */
6396
6397 GtkPlotData *
gtk_plot_add_function(GtkPlot * plot,GtkPlotFunc function)6398 gtk_plot_add_function(GtkPlot *plot, GtkPlotFunc function)
6399 {
6400 GtkPlotData *dataset;
6401
6402 dataset = GTK_PLOT_DATA(gtk_plot_data_new_function(function));
6403
6404 gtk_plot_add_data(plot, dataset);
6405
6406 return (dataset);
6407 }
6408
6409 /**
6410 * gtk_plot_remove_data:
6411 * @plot: a #GtkPlot widget.
6412 * @dataset:
6413 *
6414 *
6415 *
6416 * Return value:
6417 */
6418 gint
gtk_plot_remove_data(GtkPlot * plot,GtkPlotData * dataset)6419 gtk_plot_remove_data(GtkPlot *plot, GtkPlotData *dataset)
6420 {
6421 GList *datasets;
6422 gpointer data;
6423
6424 datasets = plot->data_sets;
6425
6426 while(datasets)
6427 {
6428 data = datasets->data;
6429
6430 if(GTK_PLOT_DATA(data) == dataset){
6431 g_object_unref(GTK_WIDGET(dataset));
6432 plot->data_sets = g_list_remove_link(plot->data_sets, datasets);
6433 g_list_free_1(datasets);
6434 g_signal_emit (plot, plot_signals[CHANGED], 0);
6435 return TRUE;
6436 }
6437 datasets = datasets->next;
6438 }
6439
6440 return FALSE;
6441 }
6442
6443 /**
6444 * gtk_plot_remove_text:
6445 * @plot: a #GtkPlot widget.
6446 * @text:
6447 *
6448 *
6449 *
6450 * Return value:
6451 */
6452 gint
gtk_plot_remove_text(GtkPlot * plot,GtkPlotText * text)6453 gtk_plot_remove_text(GtkPlot *plot, GtkPlotText *text)
6454 {
6455 GList *list;
6456 gpointer data;
6457
6458 list = plot->text;
6459
6460 while(list)
6461 {
6462 data = list->data;
6463
6464 if((GtkPlotText *)data == text){
6465 plot->text = g_list_remove_link(plot->text, list);
6466 g_list_free_1(list);
6467 g_signal_emit (plot, plot_signals[CHANGED], 0);
6468 return TRUE;
6469 }
6470 list = list->next;
6471 }
6472
6473 return FALSE;
6474 }
6475
6476
6477 static void
gtk_plot_real_ticks_recalc(GtkPlotTicks * ticks)6478 gtk_plot_real_ticks_recalc(GtkPlotTicks *ticks)
6479 {
6480 GtkPlotScale scale;
6481 gdouble min = 0., max = 0.;
6482 gdouble tick = 0.0;
6483 gdouble tick_step = 0.0;
6484 gdouble major_step;
6485 gdouble minor_step;
6486 gint nmajor = 0;
6487 gint n = 0;
6488 gdouble absmin, absmax;
6489 GtkPlotTick *major = NULL;
6490 gboolean changed = TRUE;
6491
6492 scale = ticks->scale;
6493
6494 max = ticks->max;
6495 min = ticks->min;
6496
6497 absmin = min;
6498 absmax = max;
6499
6500 if(ticks->set_limits){
6501 max = MIN(max, ticks->end);
6502 min = MAX(min, ticks->begin);
6503 absmin = min;
6504 absmax = max;
6505 } else {
6506 /*
6507 printf("%f\n",ticks->step);
6508 printf("%f %f\n",min/ticks->step,floor(min/ticks->step));
6509 printf("%f %f\n",max/ticks->step,ceil(max/ticks->step));
6510 */
6511 max = ceil(max/ticks->step) * ticks->step;
6512 min = floor(min/ticks->step) * ticks->step;
6513 }
6514
6515 if(scale == GTK_PLOT_SCALE_LOG10){
6516 min = ticks->min;
6517 max = ticks->max;
6518 if(max <= (double)0.0f) ticks->max = max = 1.E-11;
6519 if(max <= 0) ticks->max = max = fabs(max);
6520 if(min <= 0) ticks->min = min = max / 100.;
6521 min = floor(log10(min));
6522 min = pow(10., min);
6523 if(min == max){
6524 min /= 10;
6525 max *= 10;
6526 }
6527 absmin = ticks->min;
6528 absmax = ticks->max;
6529 }
6530
6531 if(ticks->values){
6532 g_free(ticks->values);
6533 ticks->values = NULL;
6534 ticks->nticks = 0;
6535 }
6536
6537 ticks->nmajorticks = 0;
6538 ticks->nminorticks = 0;
6539 major_step = ticks->step;
6540 minor_step = major_step / ((gdouble)ticks->nminor + 1.0);
6541
6542 if(scale == GTK_PLOT_SCALE_LOG10){
6543 if(major_step != 0.)
6544 major_step = floor(major_step);
6545
6546 if(major_step == 0.)
6547 major_step = 1.0;
6548
6549 ticks->nminor = 8;
6550 }
6551
6552 if(ticks->step > 0.){
6553 major = g_new0(GtkPlotTick,1);
6554 tick_step = min;
6555 tick = min;
6556 n = 0;
6557 while(tick <= max + 2*fabs(major_step)){
6558 if(tick >= min-major_step*1.E-2 && tick <= max+major_step*1.E-2){
6559 nmajor ++;
6560 major = g_realloc(major, nmajor*sizeof(GtkPlotTick));
6561 major[nmajor-1].value = tick;
6562 major[nmajor-1].minor = FALSE;
6563 }
6564 n++;
6565 switch(scale){
6566 case GTK_PLOT_SCALE_LINEAR:
6567 tick = min + n * major_step;
6568 break;
6569 case GTK_PLOT_SCALE_LOG10:
6570 tick = tick_step * pow(10., n*major_step);
6571 break;
6572 default:
6573 break;
6574 }
6575 /* FIXME: hard bailout limit in case something is totally off
6576 * to avoid locking up */
6577 if (nmajor > 1000) { printf("EEEEEEEEEEEEEEK!\n"); break;}
6578 }
6579 }
6580
6581 if(nmajor == 0) return;
6582
6583 ticks->nticks = 0;
6584 ticks->nmajorticks = nmajor;
6585 ticks->values = g_new0(GtkPlotTick, 1);
6586
6587 if(ticks->step >0.){
6588 gint i;
6589 n = 0;
6590 for(nmajor = 0; nmajor <= ticks->nmajorticks; nmajor++){
6591 if(nmajor < ticks->nmajorticks && major[nmajor].value >= absmin-major_step*1.E-2 && major[nmajor].value <= absmax+major_step*1.E-2){
6592 n++;
6593 ticks->values = g_realloc(ticks->values, n*sizeof(GtkPlotTick));
6594 ticks->values[n-1] = major[nmajor];
6595 }
6596 switch(scale){
6597 case GTK_PLOT_SCALE_LINEAR:
6598 if(nmajor < ticks->nmajorticks)
6599 tick_step = major[nmajor].value - major_step;
6600 else
6601 tick_step = major[nmajor-1].value;
6602 tick = tick_step;
6603 break;
6604 case GTK_PLOT_SCALE_LOG10:
6605 if(nmajor < ticks->nmajorticks)
6606 tick_step = major[nmajor].value/10.0;
6607 else
6608 tick_step = major[nmajor-1].value;
6609 tick = tick_step;
6610 break;
6611 default:
6612 break;
6613 }
6614 for(i = 0; i < ticks->nminor; i++){
6615 switch(scale){
6616 case GTK_PLOT_SCALE_LINEAR:
6617 /* we really do this but in a numerically safer way:
6618 tick += minor_step; */
6619 tick = tick_step + i * minor_step;
6620 break;
6621 case GTK_PLOT_SCALE_LOG10:
6622 /* FIXME: is this correct? this seems wrong */
6623 /* we really do this but in a numerically safer way:
6624 * tick += tick_step; */
6625 tick = tick_step + i * tick_step;
6626 break;
6627 default:
6628 break;
6629 }
6630 if(tick >= absmin-major_step*1.E-2 && tick <= absmax+major_step*1.E-2){
6631 n++;
6632 ticks->values = g_realloc(ticks->values, n*sizeof(GtkPlotTick));
6633 ticks->values[n-1].value = tick;
6634 ticks->values[n-1].minor = TRUE;
6635 ticks->nminorticks++;
6636 }
6637 }
6638 }
6639 }
6640
6641 ticks->nticks = n;
6642
6643 if(major) g_free(major);
6644
6645 /* sorting ticks */
6646 while(changed){
6647 gint i;
6648 changed = FALSE;
6649 for(i = 0; i < ticks->nticks - 1; i++){
6650 if(ticks->values[i].value > ticks->values[i+1].value) {
6651 GtkPlotTick aux = ticks->values[i];
6652 ticks->values[i] = ticks->values[i+1];
6653 ticks->values[i+1] = aux;
6654 changed = TRUE;
6655 }
6656 }
6657 }
6658
6659 /*
6660 ticks->values[0].value = absmin;
6661 ticks->values[n-1].value = absmax;
6662 */
6663 }
6664
6665 /**
6666 * gtk_plot_ticks_recalc:
6667 * @axis:
6668 *
6669 *
6670 */
6671 void
gtk_plot_ticks_recalc(GtkPlotAxis * axis)6672 gtk_plot_ticks_recalc(GtkPlotAxis *axis)
6673 {
6674 GtkPlotTicks *ticks = &axis->ticks;
6675
6676 if(ticks->apply_break){
6677 GtkPlotTicks a1, a2;
6678 gint i;
6679
6680 a1.scale = ticks->scale;
6681 a1.step = ticks->step;
6682 a1.begin = ticks->begin;
6683 a1.end = ticks->end;
6684 a1.nminor = ticks->nminor;
6685 a1.set_limits = ticks->set_limits;
6686 a1.min = ticks->min;
6687 a1.max = ticks->break_min;
6688 a1.values = NULL;
6689 a1.nticks = 0;
6690 gtk_plot_real_ticks_recalc(&a1);
6691
6692 a2.scale = ticks->break_scale;
6693 a2.step = ticks->break_step;
6694 a2.begin = ticks->begin;
6695 a2.end = ticks->end;
6696 a2.nminor = ticks->break_nminor;
6697 a2.set_limits = ticks->set_limits;
6698 a2.min = ticks->break_max;
6699 a2.max = ticks->max;
6700 a2.values = NULL;
6701 a2.nticks = 0;
6702 gtk_plot_real_ticks_recalc(&a2);
6703
6704 if(ticks->values){
6705 g_free(ticks->values);
6706 ticks->values = NULL;
6707 ticks->nticks = 0;
6708 }
6709 ticks->nmajorticks = a1.nmajorticks+a2.nmajorticks;
6710 ticks->nminorticks = a1.nminorticks+a2.nminorticks;
6711 ticks->nticks = a1.nticks+a2.nticks;
6712 ticks->values = g_new0(GtkPlotTick, ticks->nticks);
6713 for(i = 0; i < a1.nticks; i++)
6714 ticks->values[i] = a1.values[i];
6715 for(i = 0; i < a2.nticks; i++)
6716 ticks->values[a1.nticks+i] = a2.values[i];
6717
6718 if(a1.values) g_free(a1.values);
6719 if(a2.values) g_free(a2.values);
6720
6721 } else {
6722 gtk_plot_real_ticks_recalc(ticks);
6723 }
6724 }
6725
6726 static void
update_datasets(GtkPlot * plot,gboolean new_range)6727 update_datasets(GtkPlot *plot, gboolean new_range)
6728 {
6729 GList *list = NULL;
6730
6731 list = plot->data_sets;
6732 while(list) {
6733 g_signal_emit_by_name(list->data, "update", new_range);
6734
6735 list = list->next;
6736 }
6737 }
6738
6739