1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
|
/* $Id: gtkdatabox_markers.c 4 2008-06-22 09:19:11Z rbock $ */
/* GtkDatabox - An extension to the gtk+ library
* Copyright (C) 1998 - 2008 Dr. Roland Bock
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <gtkdatabox_markers.h>
#include <pango/pango.h>
static void gtk_databox_markers_real_draw (GtkDataboxGraph * markers,
GtkDatabox* box);
static cairo_t* gtk_databox_markers_real_create_gc (GtkDataboxGraph * graph,
GtkDatabox* box);
/* IDs of properties */
enum
{
PROP_TYPE = 1
};
typedef struct
{
GtkDataboxMarkersPosition position; /* relative to data point */
gchar *text;
PangoLayout *label; /* the label for markers */
GtkDataboxMarkersTextPosition label_position; /* position relative to markers */
gboolean boxed; /* label in a box? */
}
GtkDataboxMarkersInfo;
/**
* GtkDataboxMarkersPrivate:
*
* A private data structure used by the #GtkDataboxMarkers. It shields all internal things
* from developers who are just using the object.
*
**/
typedef struct _GtkDataboxMarkersPrivate GtkDataboxMarkersPrivate;
struct _GtkDataboxMarkersPrivate
{
GtkDataboxMarkersType type;
GtkDataboxMarkersInfo *markers_info;
gint16 *xpixels;
gint16 *ypixels;
guint pixelsalloc;
};
G_DEFINE_TYPE_WITH_PRIVATE(GtkDataboxMarkers, gtk_databox_markers,
GTK_DATABOX_TYPE_XYC_GRAPH)
static void
gtk_databox_markers_set_mtype (GtkDataboxMarkers * markers, gint type)
{
g_return_if_fail (GTK_DATABOX_IS_MARKERS (markers));
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
priv->type = type;
g_object_notify (G_OBJECT (markers), "markers-type");
}
static void
gtk_databox_markers_set_property (GObject * object,
guint property_id,
const GValue * value, GParamSpec * pspec)
{
GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (object);
switch (property_id)
{
case PROP_TYPE:
{
gtk_databox_markers_set_mtype (markers, g_value_get_int (value));
}
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gint
gtk_databox_markers_get_mtype (GtkDataboxMarkers * markers)
{
g_return_val_if_fail (GTK_DATABOX_IS_MARKERS (markers), 0);
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
return priv->type;
}
static void
gtk_databox_markers_get_property (GObject * object,
guint property_id,
GValue * value, GParamSpec * pspec)
{
GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (object);
switch (property_id)
{
case PROP_TYPE:
{
g_value_set_int (value, gtk_databox_markers_get_mtype (markers));
}
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
markers_finalize (GObject * object)
{
GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (object);
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
int i;
int len;
len = gtk_databox_xyc_graph_get_length (GTK_DATABOX_XYC_GRAPH (markers));
for (i = 0; i < len; ++i)
{
if (priv->markers_info[i].label)
g_object_unref (priv->markers_info[i].label);
if (priv->markers_info[i].text)
g_free (priv->markers_info[i].text);
}
g_free (priv->markers_info);
g_free (priv->xpixels);
g_free (priv->ypixels);
/* Chain up to the parent class */
G_OBJECT_CLASS (gtk_databox_markers_parent_class)->finalize (object);
}
static cairo_t *
gtk_databox_markers_real_create_gc (GtkDataboxGraph * graph,
GtkDatabox* box)
{
GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (graph);
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
cairo_t *cr;
static const double dash = 5.0f;
g_return_val_if_fail (GTK_DATABOX_IS_MARKERS (graph), NULL);
cr = GTK_DATABOX_GRAPH_CLASS (gtk_databox_markers_parent_class)->create_gc (graph, box);
if (cr)
{
if (priv->type == GTK_DATABOX_MARKERS_DASHED_LINE)
cairo_set_dash (cr, &dash, 1, 0.0);
}
return cr;
}
static void
gtk_databox_markers_class_init (GtkDataboxMarkersClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkDataboxGraphClass *graph_class = GTK_DATABOX_GRAPH_CLASS (klass);
GParamSpec *markers_param_spec;
gobject_class->set_property = gtk_databox_markers_set_property;
gobject_class->get_property = gtk_databox_markers_get_property;
gobject_class->finalize = markers_finalize;
markers_param_spec = g_param_spec_int ("markers-type", "Type of markers", "Type of markers for this graph, e.g. triangles or lines", G_MININT, G_MAXINT, 0, /* default value */
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_TYPE, markers_param_spec);
graph_class->draw = gtk_databox_markers_real_draw;
graph_class->create_gc = gtk_databox_markers_real_create_gc;
}
static void
complete (GtkDataboxMarkers * markers)
{
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
priv->markers_info =
g_new0 (GtkDataboxMarkersInfo,
gtk_databox_xyc_graph_get_length
(GTK_DATABOX_XYC_GRAPH (markers)));
}
static void
gtk_databox_markers_init (GtkDataboxMarkers *markers)
{
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
priv->markers_info = NULL;
priv->xpixels = NULL;
priv->ypixels = NULL;
priv->pixelsalloc = 0;
g_signal_connect (markers, "notify::length", G_CALLBACK (complete), NULL);
}
/**
* gtk_databox_markers_new:
* @len: length of @X and @Y
* @X: array of horizontal position values of markers
* @Y: array of vertical position values of markers
* @color: color of the markers
* @size: marker size or line width (depending on the @type)
* @type: type of markers (e.g. triangle or circle)
*
* Creates a new #GtkDataboxMarkers object which can be added to a #GtkDatabox widget as nice decoration for other graphs.
*
* Return value: A new #GtkDataboxMarkers object
**/
GtkDataboxGraph *
gtk_databox_markers_new (guint len, gfloat * X, gfloat * Y,
GdkRGBA * color, guint size,
GtkDataboxMarkersType type)
{
GtkDataboxMarkers *markers;
g_return_val_if_fail (X, NULL);
g_return_val_if_fail (Y, NULL);
g_return_val_if_fail ((len > 0), NULL);
markers = g_object_new (GTK_DATABOX_TYPE_MARKERS,
"X-Values", X,
"Y-Values", Y,
"xstart", 0,
"ystart", 0,
"xstride", 1,
"ystride", 1,
"xtype", G_TYPE_FLOAT,
"ytype", G_TYPE_FLOAT,
"length", len,
"maxlen", len,
"color", color,
"size", size, "markers-type", type, NULL);
return GTK_DATABOX_GRAPH (markers);
}
/**
* gtk_databox_markers_new_full:
* @maxlen: maximum length of @X and @Y
* @len: actual number of @X and @Y values to plot
* @X: array of horizontal position values of markers
* @Y: array of vertical position values of markers
* @xstart: the first element in the X array to plot (usually 0)
* @ystart: the first element in the Y array to plot (usually 0)
* @xstride: successive elements in the X array are separated by this much (1 if array, ncols if matrix)
* @ystride: successive elements in the Y array are separated by this much (1 if array, ncols if matrix)
* @xtype: the GType of the X array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
* @ytype: the GType of the Y array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
* @color: color of the markers
* @size: marker size or line width (depending on the @type)
* @type: type of markers (e.g. triangle or circle)
*
* Creates a new #GtkDataboxMarkers object which can be added to a #GtkDatabox widget as nice decoration for other graphs.
*
* Return value: A new #GtkDataboxMarkers object
**/
GtkDataboxGraph *
gtk_databox_markers_new_full (guint maxlen, guint len,
void * X, guint xstart, guint xstride, GType xtype,
void * Y, guint ystart, guint ystride, GType ytype,
GdkRGBA * color, guint size,
GtkDataboxMarkersType type)
{
GtkDataboxMarkers *markers;
g_return_val_if_fail (X, NULL);
g_return_val_if_fail (Y, NULL);
g_return_val_if_fail ((len > 0), NULL);
markers = g_object_new (GTK_DATABOX_TYPE_MARKERS,
"X-Values", X,
"Y-Values", Y,
"xstart", xstart,
"ystart", ystart,
"xstride", xstride,
"ystride", ystride,
"xtype", xtype,
"ytype", ytype,
"length", len,
"maxlen", maxlen,
"color", color,
"size", size, "markers-type", type, NULL);
return GTK_DATABOX_GRAPH (markers);
}
static gint
gtk_databox_label_write_at (cairo_t *cr,
PangoLayout * pl,
GdkPoint coord,
GtkDataboxMarkersTextPosition position,
gint distance, gboolean boxed)
{
gint hdist_text;
gint vdist_text;
gint hdist_box;
gint vdist_box;
gint width;
gint height;
gint offset = (boxed) ? 2 : 0;
pango_layout_get_pixel_size (pl, &width, &height);
switch (position)
{
case GTK_DATABOX_MARKERS_TEXT_N:
hdist_text = -width / 2;
vdist_text = -distance - offset - height;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
case GTK_DATABOX_MARKERS_TEXT_NE:
hdist_text = +distance + offset;
vdist_text = -distance - offset - height;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
case GTK_DATABOX_MARKERS_TEXT_E:
hdist_text = +distance + offset;
vdist_text = -height / 2;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
case GTK_DATABOX_MARKERS_TEXT_SE:
hdist_text = +distance + offset;
vdist_text = +distance + offset;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
case GTK_DATABOX_MARKERS_TEXT_S:
hdist_text = -width / 2;
vdist_text = +distance + offset;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
case GTK_DATABOX_MARKERS_TEXT_SW:
hdist_text = -distance - offset - width;
vdist_text = +distance + offset;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
case GTK_DATABOX_MARKERS_TEXT_W:
hdist_text = -distance - offset - width;
vdist_text = -height / 2;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
case GTK_DATABOX_MARKERS_TEXT_NW:
hdist_text = -distance - offset - width;
vdist_text = -distance - offset - height;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
break;
default:
hdist_text = -width / 2;
vdist_text = -height / 2;
hdist_box = hdist_text - offset;
vdist_box = vdist_text - offset;
}
cairo_move_to(cr, coord.x + hdist_text, coord.y + vdist_text);
pango_cairo_show_layout(cr, pl);
if (boxed) {
cairo_save (cr);
cairo_set_line_width (cr, 1.0);
cairo_set_dash (cr, NULL, 0, 0.0);
cairo_rectangle (cr, coord.x + hdist_box - 0.5,
coord.y + vdist_box - 0.5, width + 3.5, height + 3.5);
cairo_stroke(cr);
cairo_restore(cr);
}
return (0);
}
static void
gtk_databox_markers_real_draw (GtkDataboxGraph * graph,
GtkDatabox* box)
{
GtkWidget *widget;
GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (graph);
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
GdkPoint points[3];
PangoContext *context;
void *X;
void *Y;
guint len, maxlen;
gint16 x;
gint16 y;
gint16 widget_width;
gint16 widget_height;
GdkPoint coord;
gint size;
guint i;
cairo_t *cr;
GtkAllocation allocation;
gint16 *xpixels, *ypixels;
guint xstart, xstride, ystart, ystride;
GType xtype, ytype;
g_return_if_fail (GTK_DATABOX_IS_MARKERS (markers));
g_return_if_fail (GTK_IS_DATABOX (box));
widget = GTK_WIDGET(box);
gtk_widget_get_allocation(widget, &allocation);
context = gtk_widget_get_pango_context(widget);
len = gtk_databox_xyc_graph_get_length (GTK_DATABOX_XYC_GRAPH (graph));
maxlen = gtk_databox_xyc_graph_get_maxlen (GTK_DATABOX_XYC_GRAPH (graph));
if (priv->pixelsalloc < len)
{
priv->pixelsalloc = len;
priv->xpixels = (gint16 *)g_realloc(priv->xpixels, len * sizeof(gint16));
priv->ypixels = (gint16 *)g_realloc(priv->ypixels, len * sizeof(gint16));
}
xpixels = priv->xpixels;
ypixels = priv->ypixels;
X = gtk_databox_xyc_graph_get_X (GTK_DATABOX_XYC_GRAPH (graph));
xstart = gtk_databox_xyc_graph_get_xstart (GTK_DATABOX_XYC_GRAPH (graph));
xstride = gtk_databox_xyc_graph_get_xstride (GTK_DATABOX_XYC_GRAPH (graph));
xtype = gtk_databox_xyc_graph_get_xtype (GTK_DATABOX_XYC_GRAPH (graph));
gtk_databox_values_to_xpixels(box, xpixels, X, xtype, maxlen, xstart, xstride, len);
Y = gtk_databox_xyc_graph_get_Y (GTK_DATABOX_XYC_GRAPH (graph));
ystart = gtk_databox_xyc_graph_get_ystart (GTK_DATABOX_XYC_GRAPH (graph));
ystride = gtk_databox_xyc_graph_get_ystride (GTK_DATABOX_XYC_GRAPH (graph));
ytype = gtk_databox_xyc_graph_get_ytype (GTK_DATABOX_XYC_GRAPH (graph));
gtk_databox_values_to_ypixels(box, ypixels, Y, ytype, maxlen, ystart, ystride, len);
size = gtk_databox_graph_get_size (graph);
widget_width = allocation.width;
widget_height = allocation.height;
cr = gtk_databox_graph_create_gc (graph, box);
for (i = 0; i < len; ++i)
{
coord.x = x = xpixels[i];
coord.y = y = ypixels[i];
switch (priv->type)
{
case GTK_DATABOX_MARKERS_TRIANGLE:
switch (priv->markers_info[i].position)
{
case GTK_DATABOX_MARKERS_C:
y = y - size / 2;
points[0].x = x;
points[0].y = y;
points[1].x = x - size / 2;
points[1].y = y + size;
points[2].x = x + size / 2;
points[2].y = y + size;
break;
case GTK_DATABOX_MARKERS_N:
coord.y = y - 2 - size / 2;
y = y - 2;
points[0].x = x;
points[0].y = y;
points[1].x = x - size / 2;
points[1].y = y - size;
points[2].x = x + size / 2;
points[2].y = y - size;
break;
case GTK_DATABOX_MARKERS_E:
coord.x = x + 2 + size / 2;
x = x + 2;
points[0].x = x;
points[0].y = y;
points[1].x = x + size;
points[1].y = y + size / 2;
points[2].x = x + size;
points[2].y = y - size / 2;
break;
case GTK_DATABOX_MARKERS_S:
coord.y = y + 2 + size / 2;
y = y + 2;
points[0].x = x;
points[0].y = y;
points[1].x = x - size / 2;
points[1].y = y + size;
points[2].x = x + size / 2;
points[2].y = y + size;
break;
case GTK_DATABOX_MARKERS_W:
default:
coord.x = x - 2 - size / 2;
x = x - 2;
points[0].x = x;
points[0].y = y;
points[1].x = x - size;
points[1].y = y + size / 2;
points[2].x = x - size;
points[2].y = y - size / 2;
break;
}
cairo_move_to(cr, points[0].x + 0.5, points[0].y + 0.5);
cairo_line_to(cr, points[1].x + 0.5, points[1].y + 0.5);
cairo_line_to(cr, points[2].x + 0.5, points[2].y + 0.5);
cairo_close_path (cr);
cairo_fill(cr);
break;
/* End of GTK_DATABOX_MARKERS_TRIANGLE */
case GTK_DATABOX_MARKERS_SOLID_LINE:
case GTK_DATABOX_MARKERS_DASHED_LINE:
switch (priv->markers_info[i].position)
{
case GTK_DATABOX_MARKERS_C:
points[0].x = x;
points[0].y = 0;
points[1].x = x;
points[1].y = widget_height;
break;
case GTK_DATABOX_MARKERS_N:
points[0].x = x;
points[0].y = 0;
points[1].x = x;
points[1].y = widget_height;
break;
case GTK_DATABOX_MARKERS_E:
points[0].x = 0;
points[0].y = y;
points[1].x = widget_width;
points[1].y = y;
break;
case GTK_DATABOX_MARKERS_S:
points[0].x = x;
points[0].y = 0;
points[1].x = x;
points[1].y = widget_height;
break;
case GTK_DATABOX_MARKERS_W:
default:
points[0].x = 0;
points[0].y = y;
points[1].x = widget_width;
points[1].y = y;
break;
}
cairo_move_to(cr, points[0].x + 0.5, points[0].y + 0.5);
cairo_line_to(cr, points[1].x + 0.5, points[1].y + 0.5);
cairo_stroke(cr);
break;
/* End of GTK_DATABOX_MARKERS_LINE */
case GTK_DATABOX_MARKERS_NONE:
default:
break;
}
if (priv->markers_info[i].text)
{
if (!priv->markers_info[i].label)
{
priv->markers_info[i].label =
pango_layout_new (context);
pango_layout_set_text (priv->markers_info[i].label,
priv->markers_info[i].text, -1);
}
if (priv->type == GTK_DATABOX_MARKERS_SOLID_LINE
|| priv->type == GTK_DATABOX_MARKERS_DASHED_LINE)
{
gint width;
gint height;
pango_layout_get_pixel_size (priv->markers_info[i].label,
&width, &height);
width = (width + 1) / 2 + 2;
height = (height + 1) / 2 + 2;
size = 0;
switch (priv->markers_info[i].position)
{
case GTK_DATABOX_MARKERS_C:
break;
case GTK_DATABOX_MARKERS_N:
coord.y = height;
break;
case GTK_DATABOX_MARKERS_E:
coord.x = widget_width - width;
break;
case GTK_DATABOX_MARKERS_S:
coord.y = widget_height - height;
break;
case GTK_DATABOX_MARKERS_W:
coord.x = width;
break;
}
}
gtk_databox_label_write_at (cr,
priv->markers_info[i].label,
coord,
priv->markers_info[i].
label_position, (size + 1) / 2 + 2,
priv->markers_info[i].boxed);
}
}
cairo_destroy(cr);
return;
}
/**
* gtk_databox_markers_set_position:
* @markers: A #GtkDataboxMarkers object
* @index: index within the array of X/Y values
* @position: position of the marker (e.g. circle or triangle relative to their X/Y value
*
* Sets a position for one of the markers.
**/
void
gtk_databox_markers_set_position (GtkDataboxMarkers * markers,
guint index,
GtkDataboxMarkersPosition position)
{
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
guint len;
g_return_if_fail (GTK_DATABOX_IS_MARKERS (markers));
len = gtk_databox_xyc_graph_get_length (GTK_DATABOX_XYC_GRAPH (markers));
g_return_if_fail (index < len);
priv->markers_info[index].position = position;
}
/**
* gtk_databox_markers_set_label:
* @markers: A #GtkDataboxMarkers object
* @index: index within the array of X/Y values
* @label_position: position of the label relative to the marker
* @text: text to be displayed in the label
* @boxed: Whether the label is to be enclosed in a box (true) or not (false)
*
* Sets a label for one of the markers.
**/
void
gtk_databox_markers_set_label (GtkDataboxMarkers * markers,
guint index,
GtkDataboxMarkersTextPosition label_position,
gchar * text, gboolean boxed)
{
GtkDataboxMarkersPrivate *priv = gtk_databox_markers_get_instance_private (markers);
guint len;
g_return_if_fail (GTK_DATABOX_IS_MARKERS (markers));
len = gtk_databox_xyc_graph_get_length (GTK_DATABOX_XYC_GRAPH (markers));
g_return_if_fail (index < len);
priv->markers_info[index].label_position = label_position;
if (priv->markers_info[index].text)
g_free (priv->markers_info[index].text);
priv->markers_info[index].text = g_strdup (text);
priv->markers_info[index].boxed = boxed;
if (priv->markers_info[index].label)
{
pango_layout_set_text (priv->markers_info[index].label,
priv->markers_info[index].text, -1);
}
}
|