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