-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathgraphics.c
More file actions
6242 lines (5412 loc) · 194 KB
/
graphics.c
File metadata and controls
6242 lines (5412 loc) · 194 KB
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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* GNUPLOT - graphics.c */
/*[
* Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/* Daniel Sebald: added plot_image_or_update_axes() routine for images.
* (5 November 2003)
*/
#include "graphics.h"
#include "boundary.h"
#include "color.h"
#include "pm3d.h"
#include "plot.h"
#include "alloc.h"
#include "axis.h"
#include "command.h"
#include "misc.h"
#include "gadgets.h"
#include "jitter.h"
#include "plot2d.h" /* for boxwidth */
#include "term_api.h"
#include "watch.h"
#include "util.h"
#include "util3d.h"
/* Externally visible/modifiable status variables */
/* 'set offset' --- artificial buffer zone between coordinate axes and
* the area actually covered by the data.
* The retain_offsets flag is an interlock to prevent repeated application
* of the offsets when a plot is refreshed or scrolled.
*/
t_position loff = {first_axes, first_axes, first_axes, 0.0, 0.0, 0.0};
t_position roff = {first_axes, first_axes, first_axes, 0.0, 0.0, 0.0};
t_position toff = {first_axes, first_axes, first_axes, 0.0, 0.0, 0.0};
t_position boff = {first_axes, first_axes, first_axes, 0.0, 0.0, 0.0};
TBOOLEAN retain_offsets = FALSE;
/* set bars */
double bar_size = 1.0;
int bar_layer = LAYER_FRONT;
struct lp_style_type bar_lp;
/* 'set rgbmax {0|255}' */
double rgbmax = 255;
/* radius used to draw ttics and radial grid lines. */
/* NB: x-axis coordinates, not polar. updated by xtick2d_callback. */
static double largest_polar_circle;
/* End points and tickmark offsets for radial axes in spiderplots */
static double spoke_x0, spoke_y0, spoke_x1, spoke_y1;
static double spoke_dx, spoke_dy;
/* Used to prevent tic labels from being drawn more than once */
static int current_layer = 0;
/*}}} */
/* Status information for stacked histogram plots */
static struct coordinate *stackheight = NULL; /* top of previous row */
static int stack_count; /* points actually used */
static void place_histogram_titles(void);
/*{{{ static fns and local macros */
static void adjust_offsets(void);
static void adjust_nonlinear_offset(struct axis *axis);
static void recheck_ranges(struct curve_points * plot);
static void plot_border(void);
static void plot_impulses(struct curve_points * plot, int yaxis_x, int xaxis_y);
static void plot_lines(struct curve_points * plot);
static void plot_points(struct curve_points * plot);
static void plot_dots(struct curve_points * plot);
static void plot_bars(struct curve_points * plot);
static void plot_boxes(struct curve_points * plot, int xaxis_y);
static void plot_filledcurves(struct curve_points * plot);
static void finish_filled_curve(int, gpiPoint *, struct curve_points *);
static void plot_betweencurves(struct curve_points * plot);
static void plot_vectors(struct curve_points * plot);
static void plot_f_bars(struct curve_points * plot);
static void plot_c_bars(struct curve_points * plot);
static int compare_ypoints(SORTFUNC_ARGS arg1, SORTFUNC_ARGS arg2);
static void plot_boxplot(struct curve_points * plot, TBOOLEAN only_autoscale);
static void place_labels(struct text_label * listhead, int layer, TBOOLEAN clip);
static void place_arrows(int layer);
static void place_grid(int layer);
static void place_raxis(void);
static void place_parallel_axes(struct curve_points *plots, int layer);
static void place_spiderplot_axes(struct curve_points *plots, int layer);
static void plot_polar_grid(struct curve_points *plot);
#if (0) /* STEPS FILLSTEPS FSTEPS HISTEPS now emulated by HSTEPS */
static void plot_steps(struct curve_points * plot); /* JG */
static void plot_fsteps(struct curve_points * plot); /* HOE */
static void plot_histeps(struct curve_points * plot); /* CAC */
static int histeps_compare(SORTFUNC_ARGS p1, SORTFUNC_ARGS p2);
#endif /* STEPS FILLSTEPS FSTEPS HISTEPS now emulated by HSTEPS */
static void plot_hsteps(struct curve_points * plot);
static void ytick2d_callback(struct axis *, double place, char *text, int ticlevel, struct lp_style_type grid, struct ticmark *userlabels);
static void xtick2d_callback(struct axis *, double place, char *text, int ticlevel, struct lp_style_type grid, struct ticmark *userlabels);
static void ttick_callback(struct axis *, double place, char *text, int ticlevel, struct lp_style_type grid, struct ticmark *userlabels);
static void spidertick_callback(struct axis *, double place, char *text, int ticlevel, struct lp_style_type grid, struct ticmark *userlabels);
static void get_arrow(struct arrow_def* arrow, double* sx, double* sy, double* ex, double* ey);
static void map_position_double(struct position* pos, double* x, double* y, const char* what);
static void plot_circles(struct curve_points *plot);
static void plot_sectors(struct curve_points *plot);
static void plot_ellipses(struct curve_points *plot);
static void do_rectangle(int dimensions, t_object *this_object, fill_style_type *fillstyle);
static void do_polygon(int dimensions, t_object *this_object, int style, int facing );
static double rgbscale(double rawvalue);
static void draw_polar_circle(double place);
static void plot_parallel(struct curve_points *plot);
static void plot_spiderplot(struct curve_points *plot);
/* for plotting error bars
* half the width of error bar tic mark
*/
#define ERRORBARTIC GPMAX((t->h_tic/2),1)
/* used by compare_ypoints via q_sort from filter_boxplot */
static TBOOLEAN boxplot_factor_sort_required;
/* For tracking exit and re-entry of bounding curves that extend out of plot */
/* these must match the bit values returned by clip_point(). */
#define LEFT_EDGE 1
#define RIGHT_EDGE 2
#define BOTTOM_EDGE 4
#define TOP_EDGE 8
#define f_max(a,b) GPMAX((a),(b))
#define f_min(a,b) GPMIN((a),(b))
/* True if a and b have the same sign or zero (positive or negative) */
#define samesign(a,b) ((sgn(a) * sgn(b)) >= 0)
/*}}} */
static void
get_arrow(
struct arrow_def *arrow,
double* sx, double* sy,
double* ex, double* ey)
{
map_position_double(&arrow->start, sx, sy, "arrow");
if (arrow->type == arrow_end_relative) {
/* different coordinate systems:
* add the values in the drivers coordinate system.
* For log scale: relative coordinate is factor */
map_position_r(&arrow->end, ex, ey, "arrow");
*ex += *sx;
*ey += *sy;
} else if (arrow->type == arrow_end_oriented) {
double aspect = effective_aspect_ratio();
double radius;
map_position_r(&arrow->end, &radius, NULL, "arrow");
*ex = *sx + cos(DEG2RAD * arrow->angle) * radius;
*ey = *sy + sin(DEG2RAD * arrow->angle) * radius * aspect;
} else {
map_position_double(&arrow->end, ex, ey, "arrow");
}
}
static void
place_grid(int layer)
{
struct termentry *t = term;
int save_lgrid = grid_lp.l_type;
int save_mgrid = mgrid_lp.l_type;
BoundingBox *clip_save = clip_area;
term_apply_lp_properties(&border_lp); /* border linetype */
largest_polar_circle = 0;
/* This suppresses redrawing the grid lines */
if (layer == LAYER_FOREGROUND)
grid_lp.l_type = mgrid_lp.l_type = LT_NODRAW;
if (TRUE) {
/* select first mapping */
x_axis = FIRST_X_AXIS;
y_axis = FIRST_Y_AXIS;
/* label first y axis tics */
axis_output_tics(FIRST_Y_AXIS, &ytic_x, FIRST_X_AXIS, ytick2d_callback);
/* label first x axis tics */
axis_output_tics(FIRST_X_AXIS, &xtic_y, FIRST_Y_AXIS, xtick2d_callback);
/* select second mapping */
x_axis = SECOND_X_AXIS;
y_axis = SECOND_Y_AXIS;
axis_output_tics(SECOND_Y_AXIS, &y2tic_x, SECOND_X_AXIS, ytick2d_callback);
axis_output_tics(SECOND_X_AXIS, &x2tic_y, SECOND_Y_AXIS, xtick2d_callback);
}
/* select first mapping */
x_axis = FIRST_X_AXIS;
y_axis = FIRST_Y_AXIS;
/* Sep 2018: polar grid is clipped to x/y range limits */
clip_area = &plot_bounds;
/* POLAR GRID circles */
if (R_AXIS.ticmode && (raxis || polar)) {
/* Piggyback on the xtick2d_callback. Avoid a call to the full */
/* axis_output_tics(), which wasn't really designed for this axis. */
tic_start = map_y(0); /* Always equivalent to tics on theta=0 axis */
tic_mirror = tic_start; /* tic extends on both sides of theta=0 */
tic_text = tic_start - t->v_char;
rotate_tics = R_AXIS.tic_rotate;
if (rotate_tics == 0)
tic_hjust = CENTRE;
else if ((*t->text_angle)(rotate_tics))
tic_hjust = (rotate_tics == TEXT_VERTICAL) ? RIGHT : LEFT;
if (R_AXIS.manual_justify)
tic_hjust = R_AXIS.tic_pos;
tic_direction = 1;
gen_tics(&axis_array[POLAR_AXIS], xtick2d_callback);
(*t->text_angle) (0);
}
/* POLAR GRID radial lines */
if (theta_grid_angle > 0) {
double theta = 0;
int ox = map_x(0);
int oy = map_y(0);
term->layer(TERM_LAYER_BEGIN_GRID);
term_apply_lp_properties(&grid_lp);
if (largest_polar_circle <= 0)
largest_polar_circle = polar_radius(R_AXIS.max);
for (theta = 0; theta < 6.29; theta += theta_grid_angle) {
int x = map_x(largest_polar_circle * cos(theta));
int y = map_y(largest_polar_circle * sin(theta));
draw_clip_line(ox, oy, x, y);
}
term->layer(TERM_LAYER_END_GRID);
}
/* POLAR GRID tickmarks along the perimeter of the outer circle */
if (THETA_AXIS.ticmode) {
term_apply_lp_properties(&border_lp);
if (draw_border & 0x1000)
largest_polar_circle = polar_radius(R_AXIS.max);
copy_or_invent_formatstring(&THETA_AXIS);
gen_tics(&THETA_AXIS, ttick_callback);
term->text_angle(0);
}
/* Restore the grid line types if we had turned them off to draw labels only */
grid_lp.l_type = save_lgrid;
mgrid_lp.l_type = save_mgrid;
clip_area = clip_save;
}
static void
place_arrows(int layer)
{
struct arrow_def *this_arrow;
BoundingBox *clip_save = clip_area;
/* Allow arrows to run off the plot, so long as they are still on the canvas */
if (term->flags & TERM_CAN_CLIP)
clip_area = NULL;
else
clip_area = &canvas;
for (this_arrow = first_arrow;
this_arrow != NULL;
this_arrow = this_arrow->next) {
double dsx=0, dsy=0, dex=0, dey=0;
if (this_arrow->arrow_properties.layer != layer)
continue;
if (this_arrow->type == arrow_end_undefined)
continue;
get_arrow(this_arrow, &dsx, &dsy, &dex, &dey);
term_apply_lp_properties(&(this_arrow->arrow_properties.lp_properties));
apply_head_properties(&(this_arrow->arrow_properties));
draw_clip_arrow(dsx, dsy, dex, dey, this_arrow->arrow_properties.head);
}
term_apply_lp_properties(&border_lp);
clip_area = clip_save;
}
/*
* place_pixmaps() handles both 2D and 3D pixmaps
* NOTE: implemented via term->image(), not individual pixels
*/
void
place_pixmaps(int layer, int dimensions)
{
t_pixmap *pixmap;
gpiPoint corner[4];
int x, y, dx, dy;
if (!term->image)
return;
for (pixmap = pixmap_listhead; pixmap; pixmap = pixmap->next) {
if (layer != pixmap->layer)
continue;
/* ignore zero-size pixmap from read failure */
if (!pixmap->nrows || !pixmap->ncols)
continue;
/* Allow a single backing pixmap behind multiple multiplot panels */
if (layer == LAYER_BEHIND && multiplot_count > 1)
continue;
if (dimensions == 3)
map3d_position(&pixmap->pin, &x, &y, "pixmap");
else
map_position(&pixmap->pin, &x, &y, "pixmap");
/* dx = dy = 0 means 1-to-1 representation of pixels */
if (pixmap->extent.x == 0 && pixmap->extent.y == 0) {
dx = pixmap->ncols * term->tscale;
dy = pixmap->ncols * term->tscale;
} else if (dimensions == 3) {
map3d_position_r(&pixmap->extent, &dx, &dy, "pixmap");
if (pixmap->extent.scalex == first_axes)
dx = pixmap->extent.x * radius_scaler;
if (pixmap->extent.scaley == first_axes)
dy = pixmap->extent.y * radius_scaler;
} else {
double Dx, Dy;
map_position_r(&pixmap->extent, &Dx, &Dy, "pixmap");
dx = fabs(Dx);
dy = fabs(Dy);
}
/* default is to keep original aspect ratio */
if (pixmap->extent.y == 0)
dy = dx * (double)(pixmap->nrows) / (double)(pixmap->ncols);
if (pixmap->extent.x == 0)
dx = dy * (double)(pixmap->ncols) / (double)(pixmap->nrows);
if (pixmap->center) {
x -= dx/2;
y -= dy/2;
}
corner[0].x = x;
corner[0].y = y + dy;
corner[1].x = x + dx;
corner[1].y = y;
corner[2].x = 0; /* no clipping */
corner[2].y = term->ymax;
corner[3].x = term->xmax;
corner[3].y = 0;
/* Check for horizontal named palette colorbox */
if (!pixmap->filename && dx > dy*2)
term->image(pixmap->nrows, pixmap->ncols, pixmap->image_data, corner, IC_RGBA);
else
term->image(pixmap->ncols, pixmap->nrows, pixmap->image_data, corner, IC_RGBA);
}
}
/*
* place_labels() handles both individual labels and 2D plot with labels
*/
static void
place_labels(struct text_label *listhead, int layer, TBOOLEAN clip)
{
struct text_label *this_label;
int x, y;
term->pointsize(pointsize);
/* Hypertext labels? */
/* NB: currently svg is the only terminal that needs this extra step */
if (layer == LAYER_PLOTLABELS && listhead && listhead->hypertext
&& term->hypertext) {
term->hypertext(TERM_HYPERTEXT_FONT, listhead->font);
}
for (this_label = listhead; this_label != NULL; this_label = this_label->next) {
if (this_label->layer != layer)
continue;
if (this_label->hidden)
continue;
if (layer == LAYER_PLOTLABELS) {
x = map_x(this_label->place.x);
y = map_y(this_label->place.y);
} else
map_position(&this_label->place, &x, &y, "label");
/* Trap undefined values from e.g. nonlinear axis mapping */
if (invalid_coordinate(x,y))
continue;
if (clip) {
if (this_label->place.scalex == first_axes)
if (!(inrange(this_label->place.x, axis_array[FIRST_X_AXIS].min, axis_array[FIRST_X_AXIS].max)))
continue;
if (this_label->place.scalex == second_axes)
if (!(inrange(this_label->place.x, axis_array[SECOND_X_AXIS].min, axis_array[SECOND_X_AXIS].max)))
continue;
if (this_label->place.scaley == first_axes)
if (!(inrange(this_label->place.y, axis_array[FIRST_Y_AXIS].min, axis_array[FIRST_Y_AXIS].max)))
continue;
if (this_label->place.scaley == second_axes)
if (!(inrange(this_label->place.y, axis_array[SECOND_Y_AXIS].min, axis_array[SECOND_Y_AXIS].max)))
continue;
}
write_label(x, y, this_label);
}
}
void
place_objects(struct object *listhead, int layer, int dimensions)
{
t_object *this_object;
double x1, y1;
int style;
for (this_object = listhead; this_object != NULL; this_object = this_object->next) {
struct lp_style_type lpstyle;
struct fill_style_type *fillstyle;
if (this_object->layer != layer && this_object->layer != LAYER_FRONTBACK)
continue;
/* Extract line and fill style, but don't apply it yet */
lpstyle = this_object->lp_properties;
if (this_object->fillstyle.fillstyle == FS_DEFAULT
&& this_object->object_type == OBJ_RECTANGLE)
fillstyle = &default_rectangle.fillstyle;
else
fillstyle = &this_object->fillstyle;
style = style_from_fill(fillstyle);
term_apply_lp_properties(&lpstyle);
switch (this_object->object_type) {
case OBJ_CIRCLE:
{
t_circle *e = &this_object->o.circle;
double radius;
BoundingBox *clip_save = clip_area;
if (dimensions == 2) {
map_position_double(&e->center, &x1, &y1, "object");
map_position_r(&e->extent, &radius, NULL, "object");
} else if (splot_map) {
int junkw, junkh;
map3d_position_double(&e->center, &x1, &y1, "object");
map3d_position_r(&e->extent, &junkw, &junkh, "object");
radius = junkw;
} else /* General 3D splot */ {
if (e->center.scalex == screen)
map_position_double(&e->center, &x1, &y1, "object");
else if (e->center.scalex == first_axes || e->center.scalex == polar_axes)
map3d_position_double(&e->center, &x1, &y1, "object");
else
break;
/* radius must not change with rotation */
if (e->extent.scalex == first_axes) {
radius = e->extent.x * radius_scaler;
} else {
map_position_r(&e->extent, &radius, NULL, "object");
}
}
if ((e->center.scalex == screen || e->center.scaley == screen)
|| (this_object->clip == OBJ_NOCLIP))
clip_area = &canvas;
if (style != FS_EMPTY)
do_arc((int)x1, (int)y1, radius, e->arc_begin, e->arc_end, style, FALSE);
/* Retrace the border if the style requests it */
if (need_fill_border(fillstyle))
do_arc((int)x1, (int)y1, radius, e->arc_begin, e->arc_end, 0, e->wedge);
clip_area = clip_save;
break;
}
case OBJ_ELLIPSE:
{
t_ellipse *e = &this_object->o.ellipse;
BoundingBox *clip_save = clip_area;
if ((e->center.scalex == screen || e->center.scaley == screen)
|| (this_object->clip == OBJ_NOCLIP))
clip_area = &canvas;
if (dimensions == 2)
do_ellipse(2, e, style, TRUE);
else if (splot_map)
do_ellipse(3, e, style, TRUE);
else
break;
/* Retrace the border if the style requests it */
if (need_fill_border(fillstyle))
do_ellipse(dimensions, e, 0, TRUE);
clip_area = clip_save;
break;
}
case OBJ_POLYGON:
{
/* Polygons have an extra option LAYER_FRONTBACK that matches
* FRONT or BACK depending on which way the polygon faces
*/
int facing = LAYER_BEHIND; /* This will be ignored */
if (this_object->layer == LAYER_FRONTBACK) {
if ((layer == LAYER_FRONT) || (layer == LAYER_BACK))
facing = layer;
else
break;
}
do_polygon(dimensions, this_object, style, facing);
/* Retrace the border if the style requests it */
if (this_object->layer != LAYER_DEPTHORDER)
if (need_fill_border(fillstyle))
do_polygon(dimensions, this_object, 0, facing);
break;
}
case OBJ_RECTANGLE:
{
do_rectangle(dimensions, this_object, fillstyle);
break;
}
default:
break;
} /* End switch(object_type) */
}
}
/*
* Apply axis range expansions from "set offsets" command
*/
static void
adjust_offsets(void)
{
double b = boff.scaley == graph ? fabs(Y_AXIS.max - Y_AXIS.min)*boff.y : boff.y;
double t = toff.scaley == graph ? fabs(Y_AXIS.max - Y_AXIS.min)*toff.y : toff.y;
double l = loff.scalex == graph ? fabs(X_AXIS.max - X_AXIS.min)*loff.x : loff.x;
double r = roff.scalex == graph ? fabs(X_AXIS.max - X_AXIS.min)*roff.x : roff.x;
if (retain_offsets) {
retain_offsets = FALSE;
return;
}
if ((Y_AXIS.autoscale & AUTOSCALE_BOTH) != AUTOSCALE_NONE) {
if (nonlinear(&Y_AXIS)) {
adjust_nonlinear_offset(&Y_AXIS);
} else {
if (Y_AXIS.min < Y_AXIS.max) {
Y_AXIS.min -= b;
Y_AXIS.max += t;
} else {
Y_AXIS.max -= b;
Y_AXIS.min += t;
}
}
}
if ((X_AXIS.autoscale & AUTOSCALE_BOTH) != AUTOSCALE_NONE) {
if (nonlinear(&X_AXIS)) {
adjust_nonlinear_offset(&X_AXIS);
} else {
if (X_AXIS.min < X_AXIS.max) {
X_AXIS.min -= l;
X_AXIS.max += r;
} else {
X_AXIS.max -= l;
X_AXIS.min += r;
}
}
}
if (X_AXIS.min == X_AXIS.max)
int_error(NO_CARET, "x_min should not equal x_max!");
if (Y_AXIS.min == Y_AXIS.max)
int_error(NO_CARET, "y_min should not equal y_max!");
if (axis_array[FIRST_X_AXIS].linked_to_secondary)
clone_linked_axes(&axis_array[FIRST_X_AXIS], &axis_array[SECOND_X_AXIS]);
if (axis_array[FIRST_Y_AXIS].linked_to_secondary)
clone_linked_axes(&axis_array[FIRST_Y_AXIS], &axis_array[SECOND_Y_AXIS]);
}
/*
* This routine is called only if we know the axis passed in is either
* nonlinear X or nonlinear Y. We apply the offsets to the primary (linear)
* end of the linkage and then transform back to the axis itself (seconary).
*/
static void
adjust_nonlinear_offset( struct axis *secondary)
{
struct axis *primary = secondary->linked_to_primary;
double range = fabs(primary->max - primary->min);
double offset1, offset2;
if (secondary->index == FIRST_X_AXIS) {
if ((loff.scalex != graph && loff.x != 0)
|| (roff.scalex != graph && roff.x != 0))
int_error(NO_CARET, "nonlinear axis offsets must be in graph units");
offset1 = loff.x;
offset2 = roff.x;
} else {
if ((boff.scaley != graph && boff.y != 0)
|| (toff.scaley != graph && toff.y != 0))
int_error(NO_CARET, "nonlinear axis offsets must be in graph units");
offset1 = boff.y;
offset2 = toff.y;
}
primary->min -= range * offset1;
primary->max += range * offset2;
secondary->min = eval_link_function(secondary, primary->min);
secondary->max = eval_link_function(secondary, primary->max);
}
void
do_plot(struct curve_points *plots, int pcount)
{
struct termentry *t = term;
int curve;
struct curve_points *this_plot = NULL;
TBOOLEAN key_pass = FALSE;
legend_key *key = &keyT;
int previous_plot_style;
x_axis = FIRST_X_AXIS;
y_axis = FIRST_Y_AXIS;
adjust_offsets();
term_initialise(); /* may set xmax/ymax */
term_start_plot();
/* Figure out if we need a colorbox for this plot */
set_plot_with_palette(0, MODE_PLOT);
/* Compute boundary plot_bounds.{xleft|xright|ytop|ybot}.
* Also calculate tics, since xtics depend on plot_bounds.xleft
* but plot_bounds.xleft depends on ytics. Boundary calculations depend
* on term->v_char etc, so terminal must be initialised first.
* NB: For some terminals (e.g. x11) even though the terminal is intialized
* the font dimensions are not known yet, so calculations are imperfect.
*/
boundary(plots, pcount);
/* Make palette */
if (is_plot_with_palette())
make_palette();
/* Give a chance for background items to be behind everything else */
current_layer = LAYER_BEHIND;
place_pixmaps(LAYER_BEHIND, 2);
place_objects( first_object, LAYER_BEHIND, 2);
screen_ok = FALSE;
/* Sync point for epslatex text positioning */
(term->layer)(TERM_LAYER_BACKTEXT);
/* DRAW TICS AND GRID */
current_layer = LAYER_BACK;
if (grid_layer == LAYER_BACK || grid_layer == LAYER_BEHIND)
place_grid(grid_layer);
/* DRAW ZERO AXES and update axis->term_zero */
axis_draw_2d_zeroaxis(FIRST_X_AXIS,FIRST_Y_AXIS);
axis_draw_2d_zeroaxis(FIRST_Y_AXIS,FIRST_X_AXIS);
axis_draw_2d_zeroaxis(SECOND_X_AXIS,SECOND_Y_AXIS);
axis_draw_2d_zeroaxis(SECOND_Y_AXIS,SECOND_X_AXIS);
/* DRAW VERTICAL AXES OF PARALLEL AXIS PLOTS */
place_parallel_axes(plots, LAYER_BACK);
/* DRAW RADIAL AXES OF SPIDERPLOTS */
place_spiderplot_axes(plots, LAYER_BACK);
/* DRAW PLOT BORDER */
if (draw_border)
plot_border();
/* Add back colorbox if appropriate */
if (is_plot_with_colorbox() && color_box.layer == LAYER_BACK)
draw_color_smooth_box(MODE_PLOT);
/* Pixmaps before objects */
place_pixmaps(LAYER_BACK, 2);
/* Fixed objects */
place_objects( first_object, LAYER_BACK, 2);
/* PLACE LABELS */
place_labels( first_label, LAYER_BACK, FALSE );
/* PLACE ARROWS */
place_arrows( LAYER_BACK );
/* Sync point for epslatex text positioning */
(term->layer)(TERM_LAYER_FRONTTEXT);
/* Draw the key, or at least reserve space for it (pass 1) */
if (key->visible)
draw_key( key, key_pass);
SECOND_KEY_PASS:
/* This tells the canvas, qt, and svg terminals to restart the plot */
/* count so that key titles are in sync with the plots they describe. */
(*t->layer)(TERM_LAYER_RESET_PLOTNO);
/* DRAW CURVES */
this_plot = plots;
previous_plot_style = 0;
for (curve = 0; curve < pcount; this_plot = this_plot->next, curve++) {
TBOOLEAN localkey = key->visible; /* a local copy */
this_plot->current_plotno = curve;
/* Sync point for start of new curve (used by svg, post, ...) */
if (term->hypertext) {
char *plaintext;
if (this_plot->title_no_enhanced)
plaintext = this_plot->title;
else
plaintext = estimate_plaintext(this_plot->title);
(term->hypertext)(TERM_HYPERTEXT_TITLE, plaintext);
}
(term->layer)(TERM_LAYER_BEFORE_PLOT);
/* set scaling for this plot's axes */
x_axis = this_plot->x_axis;
y_axis = this_plot->y_axis;
/* Crazy corner case handling Bug #3499425 */
if (prefer_line_styles
&& (this_plot->plot_style == HISTOGRAMS) && (!key_pass && key->front)) {
struct lp_style_type ls;
lp_use_properties(&ls, this_plot->lp_properties.l_type+1);
this_plot->lp_properties.pm3d_color = ls.pm3d_color;
}
term_apply_lp_properties(&(this_plot->lp_properties));
/* Skip a line in the key between histogram clusters */
if (this_plot->plot_style == HISTOGRAMS
&& previous_plot_style == HISTOGRAMS
&& this_plot->histogram_sequence == 0
&& this_plot->histogram->keyentry
&& !at_left_of_key()) {
key_count++;
advance_key(TRUE); /* correct for inverted key */
advance_key(0);
}
/* Column-stacked histograms store their key titles internally */
if (this_plot->plot_style == HISTOGRAMS
&& histogram_opts.type == HT_STACKED_IN_TOWERS) {
text_label *key_entry;
localkey = 0;
if (this_plot->labels && (key_pass || !key->front)) {
struct lp_style_type save_lp = this_plot->lp_properties;
for (key_entry = this_plot->labels->next; key_entry;
key_entry = key_entry->next) {
int histogram_linetype = key_entry->tag + this_plot->histogram->startcolor;
this_plot->lp_properties.l_type = histogram_linetype;
this_plot->fill_properties.fillpattern = histogram_linetype;
if (key_entry->text) {
if (prefer_line_styles)
lp_use_properties(&this_plot->lp_properties, histogram_linetype);
else
load_linetype(&this_plot->lp_properties, histogram_linetype);
do_key_sample(this_plot, key, key_entry->text, 0.0);
}
key_count++;
advance_key(0);
}
free_labels(this_plot->labels);
this_plot->labels = NULL;
this_plot->lp_properties = save_lp;
}
/* Parallel plot titles are placed as xtic labels */
} else if (this_plot->plot_style == PARALLELPLOT) {
localkey = FALSE;
/* Spiderplot key samples are handled in plot_spiderplot */
} else if (this_plot->plot_style == SPIDERPLOT && !(this_plot->plot_type == KEYENTRY)) {
localkey = FALSE;
} else if (this_plot->title && !*this_plot->title) {
localkey = FALSE;
} else if (this_plot->plot_type == NODATA) {
localkey = FALSE;
} else if (key_pass || !key->front) {
ignore_enhanced(this_plot->title_no_enhanced);
/* don't write filename or function enhanced */
if (localkey && this_plot->title && !this_plot->title_is_suppressed) {
/* If title is "at {end|beg}" do not draw it in the key */
if (!this_plot->title_position
|| this_plot->title_position->scalex != character) {
coordval var_color;
key_count++;
advance_key(TRUE); /* invert only */
var_color = (this_plot->varcolor) ? this_plot->varcolor[0] : 0.0;
do_key_sample(this_plot, key, this_plot->title, var_color);
}
}
ignore_enhanced(FALSE);
}
/* If any plots have opted out of autoscaling, we need to recheck */
/* whether their points are INRANGE or not. */
if (this_plot->noautoscale && !key_pass)
recheck_ranges(this_plot);
/* and now the curves, plus any special key requirements */
/* be sure to draw all lines before drawing any points */
/* Skip missing/empty curves */
if (this_plot->plot_type != NODATA && !key_pass) {
switch (this_plot->plot_style) {
case IMPULSES:
plot_impulses(this_plot, X_AXIS.term_zero, Y_AXIS.term_zero);
break;
case LINES:
plot_lines(this_plot);
break;
case STEPS:
case FILLSTEPS:
/* plot_steps(this_plot);*/
plot_hsteps(this_plot);
break;
case FSTEPS:
/* plot_fsteps(this_plot); */
plot_hsteps(this_plot);
break;
case HISTEPS:
/* plot_histeps(this_plot); */
plot_hsteps(this_plot);
break;
case HSTEPS:
plot_hsteps(this_plot);
break;
case POINTSTYLE:
plot_points(this_plot);
break;
case LINESPOINTS:
plot_lines(this_plot);
plot_points(this_plot);
break;
case DOTS:
plot_dots(this_plot);
break;
case YERRORLINES:
case XERRORLINES:
case XYERRORLINES:
plot_lines(this_plot);
plot_bars(this_plot);
plot_points(this_plot);
break;
case YERRORBARS:
case XERRORBARS:
case XYERRORBARS:
plot_bars(this_plot);
plot_points(this_plot);
break;
case BOXXYERROR:
case BOXES:
plot_boxes(this_plot, Y_AXIS.term_zero);
break;
case HISTOGRAMS:
if (bar_layer == LAYER_FRONT)
plot_boxes(this_plot, Y_AXIS.term_zero);
/* Draw the bars first, so that the box will cover the bottom half */
if (histogram_opts.type == HT_ERRORBARS) {
/* Note that the bar linewidth may not match the border or plot linewidth */
(term->linewidth)(histogram_opts.bar_lw);
if (!need_fill_border(&default_fillstyle))
(term->linetype)(this_plot->lp_properties.l_type);
plot_bars(this_plot);
term_apply_lp_properties(&(this_plot->lp_properties));
}
if (bar_layer != LAYER_FRONT)
plot_boxes(this_plot, Y_AXIS.term_zero);
break;
case BOXERROR:
if (bar_layer != LAYER_FRONT)
plot_bars(this_plot);
plot_boxes(this_plot, Y_AXIS.term_zero);
if (bar_layer == LAYER_FRONT)
plot_bars(this_plot);
break;
case FILLEDCURVES:
case POLYGONS:
if (this_plot->filledcurves_options.closeto == FILLEDCURVES_DEFAULT) {
if (this_plot->plot_type == DATA)
memcpy(&this_plot->filledcurves_options,
&filledcurves_opts_data, sizeof(filledcurves_opts));
else
memcpy(&this_plot->filledcurves_options,
&filledcurves_opts_func, sizeof(filledcurves_opts));
}
if (this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
&& this_plot->filledcurves_options.at > axis_array[FIRST_Y_AXIS].max)
this_plot->filledcurves_options.closeto = FILLEDCURVES_X2;
if (this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN
|| this_plot->filledcurves_options.closeto == FILLEDCURVES_ABOVE
|| this_plot->filledcurves_options.closeto == FILLEDCURVES_BELOW) {
plot_betweencurves(this_plot);
} else if (!this_plot->plot_smooth && !parametric &&
(this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
|| this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY2
|| this_plot->filledcurves_options.closeto == FILLEDCURVES_ATR)) {
/* Smoothing may have trashed the original contents of the
* 2nd y data column, and parametric code never loaded it at all.
* Either way piggybacking on FILLEDCURVES_BETWEEN will not work.
* FIXME: Maybe piggybacking is always a bad idea?
* IIRC the original rationale was to get better clipping
* but the general polygon clipping code should now work.
*/
plot_betweencurves(this_plot);
} else {
plot_filledcurves(this_plot);
}
break;
case VECTOR:
case ARROWS:
plot_vectors(this_plot);
break;
case FINANCEBARS:
plot_f_bars(this_plot);
break;
case CANDLESTICKS:
plot_c_bars(this_plot);
break;