-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathgraphics.c
More file actions
5102 lines (4437 loc) · 154 KB
/
graphics.c
File metadata and controls
5102 lines (4437 loc) · 154 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
#ifndef lint
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.576 2017-10-31 18:52:59 sfeam Exp $"); }
#endif
/* 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 "gp_time.h"
#include "gadgets.h"
#include "jitter.h"
#include "plot2d.h" /* for boxwidth */
#include "term_api.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 */
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};
/* 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;
/* key placement is calculated in boundary, so we need file-wide variables
* To simplify adjustments to the key, we set all these once [depends on
* key->reverse] and use them throughout.
*/
/* radius used to draw ttics and radial grid lines. */
/* NB: x-axis coordinates, not polar. updated by xtick2d_callback. */
static double largest_polar_circle;
/*}}} */
/* Status information for stacked histogram plots */
static struct coordinate GPHUGE *stackheight = NULL; /* top of previous row */
static int stack_count; /* points actually used */
static void place_histogram_titles __PROTO((void));
/*{{{ static fns and local macros */
static void recheck_ranges __PROTO((struct curve_points * plot));
static void plot_border __PROTO((void));
static void plot_impulses __PROTO((struct curve_points * plot, int yaxis_x, int xaxis_y));
static void plot_lines __PROTO((struct curve_points * plot));
static void plot_points __PROTO((struct curve_points * plot));
static void plot_dots __PROTO((struct curve_points * plot));
static void plot_bars __PROTO((struct curve_points * plot));
static void plot_boxes __PROTO((struct curve_points * plot, int xaxis_y));
static void plot_filledcurves __PROTO((struct curve_points * plot));
static void finish_filled_curve __PROTO((int, gpiPoint *, struct curve_points *));
static void plot_betweencurves __PROTO((struct curve_points * plot));
static void plot_vectors __PROTO((struct curve_points * plot));
static void plot_f_bars __PROTO((struct curve_points * plot));
static void plot_c_bars __PROTO((struct curve_points * plot));
static int compare_ypoints __PROTO((SORTFUNC_ARGS arg1, SORTFUNC_ARGS arg2));
static void plot_boxplot __PROTO((struct curve_points * plot));
static void place_labels __PROTO((struct text_label * listhead, int layer, TBOOLEAN clip));
static void place_arrows __PROTO((int layer));
static void place_grid __PROTO((int layer));
static void place_raxis __PROTO((void));
static void place_parallel_axes __PROTO((struct curve_points *plots, int pcount, int layer));
static void plot_steps __PROTO((struct curve_points * plot)); /* JG */
static void plot_fsteps __PROTO((struct curve_points * plot)); /* HOE */
static void plot_histeps __PROTO((struct curve_points * plot)); /* CAC */
static int edge_intersect __PROTO((struct coordinate GPHUGE * points, int i, double *ex, double *ey));
static TBOOLEAN two_edge_intersect __PROTO((struct coordinate GPHUGE * points, int i, double *lx, double *ly));
static void ytick2d_callback __PROTO((struct axis *, double place, char *text, int ticlevel, struct lp_style_type grid, struct ticmark *userlabels));
static void xtick2d_callback __PROTO((struct axis *, double place, char *text, int ticlevel, struct lp_style_type grid, struct ticmark *userlabels));
static void ttick_callback __PROTO((struct axis *, double place, char *text, int ticlevel, struct lp_style_type grid, struct ticmark *userlabels));
static int histeps_compare __PROTO((SORTFUNC_ARGS p1, SORTFUNC_ARGS p2));
static void get_arrow __PROTO((struct arrow_def* arrow, int* sx, int* sy, int* ex, int* ey));
static void map_position_double __PROTO((struct position* pos, double* x, double* y, const char* what));
#ifdef EAM_OBJECTS
static void plot_circles __PROTO((struct curve_points *plot));
static void plot_ellipses __PROTO((struct curve_points *plot));
static void do_rectangle __PROTO((int dimensions, t_object *this_object, fill_style_type *fillstyle));
#endif
static double rgbscale __PROTO((double rawvalue));
static void draw_polar_circle __PROTO((double place));
static void plot_parallel __PROTO((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,
int* sx, int* sy,
int* ex, int* ey)
{
double sx_d, sy_d, ex_d, ey_d;
map_position_double(&arrow->start, &sx_d, &sy_d, "arrow");
*sx = (int)(sx_d);
*sy = (int)(sy_d);
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_d, &ey_d, "arrow");
*ex = (int)(ex_d + sx_d);
*ey = (int)(ey_d + sy_d);
} else if (arrow->type == arrow_end_oriented) {
double aspect = (double)term->v_tic / (double)term->h_tic;
double radius;
#ifdef _WIN32
if (strcmp(term->name, "windows") == 0)
aspect = 1.;
#endif
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_d, &ey_d, "arrow");
*ex = (int)(ex_d);
*ey = (int)(ey_d);
}
}
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;
/* We used to go through this process only once, drawing both the grid lines
* and the axis tic labels. Now we allow for a separate pass that redraws only
* the labels if the user has chosen "set tics front".
* This guarantees that the axis tic labels lie on top of all grid lines.
*/
if (layer == LAYER_FOREGROUND)
grid_lp.l_type = mgrid_lp.l_type = LT_NODRAW;
/* 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;
clip_area = &canvas;
/* 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 (polar_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 += polar_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 (largest_polar_circle <= 0)
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) {
int sx, sy, ex, ey;
if (this_arrow->arrow_properties.layer != layer)
continue;
if (this_arrow->type == arrow_end_undefined)
continue;
get_arrow(this_arrow, &sx, &sy, &ex, &ey);
term_apply_lp_properties(&(this_arrow->arrow_properties.lp_properties));
apply_head_properties(&(this_arrow->arrow_properties));
draw_clip_arrow(sx, sy, ex, ey, this_arrow->arrow_properties.head);
}
term_apply_lp_properties(&border_lp);
clip_area = clip_save;
}
static void
place_labels(struct text_label *listhead, int layer, TBOOLEAN clip)
{
struct text_label *this_label;
int x, y;
term->pointsize(pointsize);
for (this_label = listhead; this_label != NULL; this_label = this_label->next) {
if (this_label->layer != layer)
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);
}
}
#ifdef EAM_OBJECTS
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)
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) {
struct axis *axis = &axis_array[FIRST_X_AXIS];
double axis_frac = e->extent.x / (axis->max - axis->min);
radius = axis_frac * xscaler * surface_scale;
} 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;
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:
{
do_polygon(dimensions, &this_object->o.polygon, style, this_object->clip);
/* Retrace the border if the style requests it */
if (need_fill_border(fillstyle))
do_polygon(dimensions, &this_object->o.polygon, 0, this_object->clip);
break;
}
case OBJ_RECTANGLE:
{
do_rectangle(dimensions, this_object, fillstyle);
break;
}
default:
break;
} /* End switch(object_type) */
}
}
#endif
/*
* Apply axis range expansions from "set offsets" command
*/
static void
adjust_offsets()
{
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 (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.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]);
}
void
do_plot(struct curve_points *plots, int pcount)
{
struct termentry *t = term;
int curve;
struct curve_points *this_plot = NULL;
int xl = 0, yl = 0;
int key_count = 0;
TBOOLEAN key_pass = FALSE;
legend_key *key = &keyT;
int previous_plot_style;
x_axis = FIRST_X_AXIS;
y_axis = FIRST_Y_AXIS;
adjust_offsets();
/* EAM June 2003 - Although the comment below implies that font dimensions
* are known after term_initialise(), this is not true at least for the X11
* driver. X11 fonts are not set until an actual display window is
* opened, and that happens in term->graphics(), which is called from
* term_start_plot().
*/
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); /* EAM FIXME - 1st parameter is a dummy */
/* compute boundary for plot (plot_bounds.xleft, plot_bounds.xright, plot_bounds.ytop, plot_bounds.ybot)
* also calculates 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.
*/
boundary(plots, pcount);
/* Make palette */
if (is_plot_with_palette())
make_palette();
/* Give a chance for rectangles to be behind everything else */
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 */
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, pcount, 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);
/* And rectangles */
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 plot title and axis labels */
/* Note: As of Dec 2012 these are drawn as "front" text. */
draw_titles();
/* Draw the key, or at least reserve space for it (pass 1) */
if (key->visible)
draw_key( key, key_pass, &xl, &yl );
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 (this_plot->plot_style == HISTOGRAMS)
if ((!key_pass && key->front) && (prefer_line_styles)) {
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 && yl != yl_ref) {
if (++key_count >= key_rows) {
yl = yl_ref;
xl += key_col_wth;
key_count = 0;
} else
yl = yl - key_entry_height;
}
/* 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, xl, yl);
}
if (++key_count >= key_rows) {
yl = yl_ref;
xl += key_col_wth;
key_count = 0;
} else
yl = yl - key_entry_height;
}
free_labels(this_plot->labels);
this_plot->labels = NULL;
this_plot->lp_properties = save_lp;
}
} 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) {
key_count++;
if (key->invert)
yl = key->bounds.ybot + yl_ref + key_entry_height/2 - yl;
do_key_sample(this_plot, key, this_plot->title, xl, yl);
}
}
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);
break;
case FSTEPS:
plot_fsteps(this_plot);
break;
case HISTEPS:
plot_histeps(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:
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_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 &&
(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, so piggybacking on the */
/* code for 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:
plot_vectors(this_plot);
break;
case FINANCEBARS:
plot_f_bars(this_plot);
break;
case CANDLESTICKS:
plot_c_bars(this_plot);
break;
case BOXPLOT:
plot_boxplot(this_plot);
break;
case PM3DSURFACE:
case SURFACEGRID:
int_warn(NO_CARET, "Can't use pm3d or surface for 2d plots");
break;
case LABELPOINTS:
place_labels( this_plot->labels->next, LAYER_PLOTLABELS, TRUE);
break;
case IMAGE:
this_plot->image_properties.type = IC_PALETTE;
process_image(this_plot, IMG_PLOT);
break;
case RGBIMAGE:
this_plot->image_properties.type = IC_RGB;
process_image(this_plot, IMG_PLOT);
break;
case RGBA_IMAGE:
this_plot->image_properties.type = IC_RGBA;
process_image(this_plot, IMG_PLOT);
break;
#ifdef EAM_OBJECTS
case CIRCLES:
plot_circles(this_plot);
break;
case ELLIPSES:
plot_ellipses(this_plot);
break;
#endif
case PARALLELPLOT:
plot_parallel(this_plot);
break;
default:
int_error(NO_CARET, "unknown plot style");
}
}
/* If there are two passes, defer key sample till the second */
/* KEY SAMPLES */
if (key->front && !key_pass)
;
else if (localkey && this_plot->title && !this_plot->title_is_suppressed) {
/* we deferred point sample until now */
if (this_plot->plot_style & PLOT_STYLE_HAS_POINT)
do_key_sample_point(this_plot, key, xl, yl);
if (this_plot->plot_style == LABELPOINTS)
do_key_sample_point(this_plot, key, xl, yl);
if (this_plot->plot_style == DOTS)
do_key_sample_point(this_plot, key, xl, yl);
if (!this_plot->title_position) {
if (key->invert)
yl = key->bounds.ybot + yl_ref + key_entry_height/2 - yl;
if (key_count >= key_rows) {
yl = yl_ref;
xl += key_col_wth;
key_count = 0;
} else
yl = yl - key_entry_height;
}
}
/* Option to label the end of the curve on the plot itself */
if (this_plot->title_position && this_plot->title_position->scalex == character)
attach_title_to_plot(this_plot, key);
/* Sync point for end of this curve (used by svg, post, ...) */
(term->layer)(TERM_LAYER_AFTER_PLOT);
previous_plot_style = this_plot->plot_style;
}
/* Go back and draw the legend in a separate pass if necessary */
if (key->visible && key->front && !key_pass) {
key_pass = TRUE;
draw_key( key, key_pass, &xl, &yl );
goto SECOND_KEY_PASS;
}
/* DRAW TICS AND GRID */
if (grid_layer == LAYER_FRONT)
place_grid(grid_layer);
if (raxis)
place_raxis();
/* Redraw the axis tic labels and tic marks if "set tics front" */
if (grid_tics_in_front)
place_grid(LAYER_FOREGROUND);
/* DRAW ZERO AXES */
/* redraw after grid so that axes linetypes are on top */
if (grid_layer == LAYER_FRONT) {
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 */
if (parallel_axis_style.layer == LAYER_FRONT)
place_parallel_axes(plots, pcount, LAYER_FRONT);
/* REDRAW PLOT BORDER */
if (draw_border && border_layer == LAYER_FRONT)
plot_border();
/* Add front colorbox if appropriate */
if (is_plot_with_colorbox() && color_box.layer == LAYER_FRONT)
draw_color_smooth_box(MODE_PLOT);
/* And rectangles */
place_objects( first_object, LAYER_FRONT, 2);
/* PLACE LABELS */
place_labels( first_label, LAYER_FRONT, FALSE );
/* PLACE HISTOGRAM TITLES */
place_histogram_titles();
/* PLACE ARROWS */
place_arrows( LAYER_FRONT );
/* Release the palette if we have used one (PostScript only?) */
if (is_plot_with_palette() && term->previous_palette)
term->previous_palette();
term_end_plot();
}
/*
* Plots marked "noautoscale" do not yet have INRANGE/OUTRANGE flags set.
*/
static void
recheck_ranges(struct curve_points *plot)
{
int i; /* point index */
for (i = 0; i < plot->p_count; i++) {
if (plot->noautoscale) {
plot->points[i].type = INRANGE;
if (!inrange(plot->points[i].x, axis_array[plot->x_axis].min, axis_array[plot->x_axis].max))
plot->points[i].type = OUTRANGE;
if (!inrange(plot->points[i].y, axis_array[plot->y_axis].min, axis_array[plot->y_axis].max))
plot->points[i].type = OUTRANGE;
}
}
}