forked from jheinen/GR.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GR.jl
4146 lines (3531 loc) · 125 KB
/
GR.jl
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
__precompile__()
module GR
if Sys.KERNEL == :NT
const os = :Windows
else
const os = Sys.KERNEL
end
const None = Union{}
const depsfile = joinpath(dirname(@__DIR__), "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
const gr_provider = "BinaryBuilder"
else
if os == :Windows
const libGR = "libGR.dll"
const libGR3 = "libGR3.dll"
const libGRM = "libGRM.dll"
elseif os == :Darwin
const libGR = "libGR.dylib"
const libGR3 = "libGR3.dylib"
const libGRM = "libGRM.dylib"
else
const libGR = "libGR.so"
const libGR3 = "libGR3.so"
const libGRM = "libGRM.so"
end
const gr_provider = "GR"
end
import Base64
export
init,
initgr,
opengks,
closegks,
inqdspsize,
openws,
closews,
activatews,
deactivatews,
clearws,
updatews,
polyline,
polymarker,
text,
inqtext,
fillarea,
cellarray,
nonuniformcellarray,
polarcellarray,
nonuniformpolarcellarray,
gdp,
path,
spline,
gridit,
setlinetype,
setlinewidth,
setlinecolorind,
setmarkertype,
setmarkersize,
setmarkercolorind,
settextfontprec,
setcharexpan,
setcharspace,
settextcolorind,
setcharheight,
inqcharheight,
setcharup,
settextpath,
settextalign,
setfillintstyle,
setfillstyle,
setfillcolorind,
setcolorrep,
setscale,
inqscale,
setwindow,
inqwindow,
setviewport,
inqviewport,
selntran,
setclip,
setwswindow,
setwsviewport,
createseg,
copyseg,
redrawseg,
setsegtran,
closeseg,
emergencyclosegks,
updategks,
setspace,
textext,
inqtextext,
axes2d, # to avoid WARNING: both GR and Base export "axes"
axeslbl,
grid,
grid3d,
verrorbars,
herrorbars,
polyline3d,
polymarker3d,
axes3d,
titles3d,
surface,
volume,
contour,
hexbin,
setcolormap,
colorbar,
inqcolor,
inqcolorfromrgb,
hsvtorgb,
tick,
validaterange,
adjustlimits,
adjustrange,
beginprint,
beginprintext,
endprint,
ndctowc,
wctondc,
wc3towc,
drawrect,
fillrect,
drawarc,
fillarc,
drawpath,
setarrowstyle,
setarrowsize,
drawarrow,
readimage,
drawimage,
importgraphics,
setshadow,
settransparency,
setcoordxform,
begingraphics,
endgraphics,
getgraphics,
drawgraphics,
mathtex,
inqmathtex,
selectcontext,
destroycontext,
delaunay,
interp2,
trisurface,
tricontour,
# gradient, # deprecated, but still in Base
quiver,
reducepoints,
version,
check_for_updates,
openmeta,
sendmeta,
sendmetaref,
closemeta,
shadepoints,
shadelines,
setcolormapfromrgb,
setborderwidth,
setbordercolorind,
setprojectiontype,
setperspectiveprojection,
setorthographicprojection,
settransformationparameters,
setwindow3d,
setspace3d,
text3d,
inqtext3d,
settextencoding,
inqtextencoding,
# Convenience functions
jlgr,
colormap,
figure,
gcf,
hold,
usecolorscheme,
subplot,
plot,
oplot,
semilogx,
semilogy,
loglog,
step,
scatter,
stem,
barplot,
histogram,
polarhistogram,
contourf,
heatmap,
polarheatmap,
nonuniformpolarheatmap,
wireframe,
plot3,
scatter3,
redraw,
title,
xlabel,
ylabel,
drawgrid,
xticks,
yticks,
zticks,
xticklabels,
yticklabels,
legend,
xlim,
ylim,
savefig,
meshgrid,
peaks,
imshow,
isosurface,
cart2sph,
sph2cart,
polar,
trisurf,
tricont,
shade,
panzoom,
setpanzoom,
libGR3,
gr3,
libGRM,
isinline,
inline,
displayname,
mainloop
const ENCODING_LATIN1 = 300
const ENCODING_UTF8 = 301
grdir = None
display_name = None
mime_type = None
file_path = None
figure_count = None
send_c = C_NULL
recv_c = C_NULL
text_encoding = ENCODING_UTF8
check_env = true
isijulia() = isdefined(Main, :IJulia) && Main.IJulia isa Module && isdefined(Main.IJulia, :clear_output)
isatom() = isdefined(Main, :Atom) && Main.Atom isa Module && Main.Atom.isconnected() && (isdefined(Main.Atom, :PlotPaneEnabled) ? Main.Atom.PlotPaneEnabled[] : true)
ispluto() = isdefined(Main, :PlutoRunner) && Main.PlutoRunner isa Module
isvscode() = isdefined(Main, :VSCodeServer) && Main.VSCodeServer isa Module && (isdefined(Main.VSCodeServer, :PLOT_PANE_ENABLED) ? Main.VSCodeServer.PLOT_PANE_ENABLED[] : true)
function __init__()
global check_env
if "GRDIR" in keys(ENV)
grdir = ENV["GRDIR"]
if grdir == ""
grdir = None
end
elseif gr_provider == "BinaryBuilder"
grdir = joinpath(dirname(GR_jll.libGR_path), "..")
else
grdir = None
for d in ("/opt", "/usr/local", "/usr")
if isdir(joinpath(d, "gr", "fonts"))
grdir = joinpath(d, "gr")
break
end
end
end
if grdir == None
grdir = joinpath(dirname(@__FILE__), "..", "deps", "gr")
if !isdir(grdir)
println("Your GR installation is incomplete. Rerun build step for GR package.")
@eval GR begin
import Pkg
Pkg.build("GR")
end
end
end
ENV["GRDIR"] = grdir
ENV["GKS_FONTPATH"] = grdir
flag = occursin("site-packages", grdir)
if flag
ENV["GKS_FONTPATH"] = grdir
elseif os != :Windows
grdir = joinpath(grdir, "lib")
else
grdir = joinpath(grdir, "bin")
end
push!(Base.DL_LOAD_PATH, grdir)
check_env = true
init(true)
end
"""
function set_callback()
callback_c = @cfunction(callback, Cstring, (Cstring, ))
ccall((:gr_setcallback, libGR),
Nothing,
(Ptr{Cvoid}, ),
callback_c)
end
"""
function init(always=false)
global display_name, mime_type, file_path, send_c, recv_c, text_encoding, check_env
if check_env || always
ENV["GKS_USE_CAIRO_PNG"] = "true"
if "GRDISPLAY" in keys(ENV)
display_name = ENV["GRDISPLAY"]
if display_name == "js" || display_name == "pluto"
send_c, recv_c = js.initjs()
end
elseif "GKS_NO_GUI" in keys(ENV)
return
elseif isijulia() || ispluto() || isvscode() || isatom()
mime_type = "svg"
file_path = tempname() * ".svg"
ENV["GKSwstype"] = "svg"
ENV["GKS_FILEPATH"] = file_path
elseif gr_provider == "BinaryBuilder" && !haskey(ENV, "GKSwstype")
ENV["GKSwstype"] = "gksqt"
if os == :Windows
ENV["GKS_QT"] = string("set PATH=", GR_jll.LIBPATH[], " & ", GR_jll.gksqt_path)
else
env = (os == :Darwin) ? "DYLD_FALLBACK_LIBRARY_PATH" : "LD_LIBRARY_PATH"
ENV["GKS_QT"] = string("env $env=", GR_jll.LIBPATH[], " ", GR_jll.gksqt_path)
end
end
if "GKS_IGNORE_ENCODING" in keys(ENV)
text_encoding = ENCODING_UTF8
elseif "GKS_ENCODING" in keys(ENV)
if ENV["GKS_ENCODING"] in ("latin1", "latin-1")
text_encoding = ENCODING_LATIN1
else
text_encoding = ENCODING_UTF8
end
else
ENV["GKS_ENCODING"] = "utf8"
end
check_env = always
end
end
function initgr()
ccall( (:gr_initgr, libGR),
Nothing,
()
)
end
function opengks()
ccall( (:gr_opengks, libGR),
Nothing,
()
)
end
function closegks()
ccall( (:gr_closegks, libGR),
Nothing,
()
)
end
# (Information taken from <https://www.iterm2.com/utilities/imgcat>.)
# tmux requires unrecognized OSC sequences to be wrapped with DCS
# tmux; <sequence> ST, and for all ESCs in <sequence> to be replaced
# with ESC ESC. It only accepts ESC backslash for ST. We use TERM
# instead of TMUX because TERM gets passed through ssh.
function osc_seq()
if startswith(get(ENV, "TERM", ""), "screen")
"\033Ptmux;\033\033]"
else
"\033]"
end
end
function st_seq()
if startswith(get(ENV, "TERM", ""), "screen")
"\a\033\\"
else
"\a"
end
end
function inqdspsize()
mwidth = Cdouble[0]
mheight = Cdouble[0]
width = Cint[0]
height = Cint[0]
ccall( (:gr_inqdspsize, libGR),
Nothing,
(Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cint}, Ptr{Cint}),
mwidth, mheight, width, height)
return mwidth[1], mheight[1], width[1], height[1]
end
"""
openws(workstation_id::Int, connection, workstation_type::Int)
Open a graphical workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
`connection` :
A connection identifier.
`workstation_type` :
The desired workstation type.
Available workstation types:
+-------------+------------------------------------------------------+
| 5|Workstation Independent Segment Storage |
+-------------+------------------------------------------------------+
| 7, 8|Computer Graphics Metafile (CGM binary, clear text) |
+-------------+------------------------------------------------------+
| 41|Windows GDI |
+-------------+------------------------------------------------------+
| 51|Mac Quickdraw |
+-------------+------------------------------------------------------+
| 61 - 64|PostScript (b/w, color) |
+-------------+------------------------------------------------------+
| 101, 102|Portable Document Format (plain, compressed) |
+-------------+------------------------------------------------------+
| 210 - 213|X Windows |
+-------------+------------------------------------------------------+
| 214|Sun Raster file (RF) |
+-------------+------------------------------------------------------+
| 215, 218|Graphics Interchange Format (GIF87, GIF89) |
+-------------+------------------------------------------------------+
| 216|Motif User Interface Language (UIL) |
+-------------+------------------------------------------------------+
| 320|Windows Bitmap (BMP) |
+-------------+------------------------------------------------------+
| 321|JPEG image file |
+-------------+------------------------------------------------------+
| 322|Portable Network Graphics file (PNG) |
+-------------+------------------------------------------------------+
| 323|Tagged Image File Format (TIFF) |
+-------------+------------------------------------------------------+
| 370|Xfig vector graphics file |
+-------------+------------------------------------------------------+
| 371|Gtk |
+-------------+------------------------------------------------------+
| 380|wxWidgets |
+-------------+------------------------------------------------------+
| 381|Qt4 |
+-------------+------------------------------------------------------+
| 382|Scaleable Vector Graphics (SVG) |
+-------------+------------------------------------------------------+
| 390|Windows Metafile |
+-------------+------------------------------------------------------+
| 400|Quartz |
+-------------+------------------------------------------------------+
| 410|Socket driver |
+-------------+------------------------------------------------------+
| 415|0MQ driver |
+-------------+------------------------------------------------------+
| 420|OpenGL |
+-------------+------------------------------------------------------+
| 430|HTML5 Canvas |
+-------------+------------------------------------------------------+
"""
function openws(workstation_id::Int, connection, workstation_type::Int)
ccall( (:gr_openws, libGR),
Nothing,
(Int32, Ptr{Cchar}, Int32),
workstation_id, connection, workstation_type)
end
"""
closews(workstation_id::Int)
Close the specified workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
"""
function closews(workstation_id::Int)
ccall( (:gr_closews, libGR),
Nothing,
(Int32, ),
workstation_id)
end
"""
activatews(workstation_id::Int)
Activate the specified workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
"""
function activatews(workstation_id::Int)
ccall( (:gr_activatews, libGR),
Nothing,
(Int32, ),
workstation_id)
end
"""
deactivatews(workstation_id::Int)
Deactivate the specified workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
"""
function deactivatews(workstation_id::Int)
ccall( (:gr_deactivatews, libGR),
Nothing,
(Int32, ),
workstation_id)
end
function clearws()
ccall( (:gr_clearws, libGR),
Nothing,
()
)
end
function updatews()
ccall( (:gr_updatews, libGR),
Nothing,
()
)
end
"""
polyline(x, y)
Draw a polyline using the current line attributes, starting from the
first data point and ending at the last data point.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
The values for `x` and `y` are in world coordinates. The attributes that
control the appearance of a polyline are linetype, linewidth and color
index.
"""
function polyline(x, y)
@assert length(x) == length(y)
n = length(x)
ccall( (:gr_polyline, libGR),
Nothing,
(Int32, Ptr{Float64}, Ptr{Float64}),
n, convert(Vector{Float64}, x), convert(Vector{Float64}, y))
end
"""
polymarker(x, y)
Draw marker symbols centered at the given data points.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
The values for `x` and `y` are in world coordinates. The attributes that
control the appearance of a polymarker are marker type, marker size
scale factor and color index.
"""
function polymarker(x, y)
@assert length(x) == length(y)
n = length(x)
ccall( (:gr_polymarker, libGR),
Nothing,
(Int32, Ptr{Float64}, Ptr{Float64}),
n, convert(Vector{Float64}, x), convert(Vector{Float64}, y))
end
function latin1(string)
if text_encoding == ENCODING_UTF8
# add null character '\0' for SubString types (see GR.jl SubString issue #336)
if typeof(string) == SubString{String}
return string * "\0"
else
return string
end
end
b = unsafe_wrap(Array{UInt8,1}, pointer(string), sizeof(string))
s = zeros(UInt8, sizeof(string) * 2)
len = 0
mask = 0
for c in b
if mask == -1
mask = 0
continue
end
if c == 0xce || c == 0xcf
len += 1
s[len] = 0x3f
mask = -1
continue
end
if c != 0xc2 && c != 0xc3
len += 1
s[len] = c | mask
end
if c == 0xc3
mask = 0x40
else
mask = 0
end
end
return s[1:len]
end
"""
text(x::Real, y::Real, string)
Draw a text at position `x`, `y` using the current text attributes.
**Parameters:**
`x` :
The X coordinate of starting position of the text string
`y` :
The Y coordinate of starting position of the text string
`string` :
The text to be drawn
The values for `x` and `y` are in normalized device coordinates.
The attributes that control the appearance of text are text font and precision,
character expansion factor, character spacing, text color index, character
height, character up vector, text path and text alignment.
"""
function text(x::Real, y::Real, string)
ccall( (:gr_text, libGR),
Nothing,
(Float64, Float64, Ptr{UInt8}),
x, y, latin1(string))
end
function inqtext(x, y, string)
tbx = Cdouble[0, 0, 0, 0]
tby = Cdouble[0, 0, 0, 0]
ccall( (:gr_inqtext, libGR),
Nothing,
(Float64, Float64, Ptr{UInt8}, Ptr{Cdouble}, Ptr{Cdouble}),
x, y, latin1(string), tbx, tby)
return tbx, tby
end
"""
fillarea(x, y)
Allows you to specify a polygonal shape of an area to be filled.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
The attributes that control the appearance of fill areas are fill area interior
style, fill area style index and fill area color index.
"""
function fillarea(x, y)
@assert length(x) == length(y)
n = length(x)
ccall( (:gr_fillarea, libGR),
Nothing,
(Int32, Ptr{Float64}, Ptr{Float64}),
n, convert(Vector{Float64}, x), convert(Vector{Float64}, y))
end
"""
cellarray(xmin::Real, xmax::Real, ymin::Real, ymax::Real, dimx::Int, dimy::Int, color)
Display rasterlike images in a device-independent manner. The cell array
function partitions a rectangle given by two corner points into DIMX X DIMY
cells, each of them colored individually by the corresponding color index
of the given cell array.
**Parameters:**
`xmin`, `ymin` :
Lower left point of the rectangle
`xmax`, `ymax` :
Upper right point of the rectangle
`dimx`, `dimy` :
X and Y dimension of the color index array
`color` :
Color index array
The values for `xmin`, `xmax`, `ymin` and `ymax` are in world coordinates.
"""
function cellarray(xmin::Real, xmax::Real, ymin::Real, ymax::Real, dimx::Int, dimy::Int, color)
if ndims(color) == 2
color = reshape(color, dimx * dimy)
end
ccall( (:gr_cellarray, libGR),
Nothing,
(Float64, Float64, Float64, Float64, Int32, Int32, Int32, Int32, Int32, Int32, Ptr{Int32}),
xmin, xmax, ymin, ymax, dimx, dimy, 1, 1, dimx, dimy, convert(Vector{Int32}, color))
end
"""
nonuniformcellarray(x, y, dimx::Int, dimy::Int, color)
Display a two dimensional color index array with nonuniform cell sizes.
**Parameters:**
`x`, `y` :
X and Y coordinates of the cell edges
`dimx`, `dimy` :
X and Y dimension of the color index array
`color` :
Color index array
The values for `x` and `y` are in world coordinates. `x` must contain `dimx` + 1 elements
and `y` must contain `dimy` + 1 elements. The elements i and i+1 are respectively the edges
of the i-th cell in X and Y direction.
"""
function nonuniformcellarray(x, y, dimx::Int, dimy::Int, color)
@assert length(x) == dimx+1 && length(y) == dimy+1
if ndims(color) == 2
color = reshape(color, dimx * dimy)
end
ccall( (:gr_nonuniformcellarray, libGR),
Nothing,
(Ptr{Float64}, Ptr{Float64}, Int32, Int32, Int32, Int32, Int32, Int32, Ptr{Int32}),
convert(Vector{Float64}, x), convert(Vector{Float64}, y), dimx, dimy, 1, 1, dimx, dimy, convert(Vector{Int32}, color))
end
"""
polarcellarray(xorg::Real, yorg::Real, phimin::Real, phimax::Real, rmin::Real, rmax::Real, imphi::Int, dimr::Int, color)
Display a two dimensional color index array mapped to a disk using polar
coordinates.
**Parameters:**
`xorg` :
X coordinate of the disk center in world coordinates
`yorg` :
Y coordinate of the disk center in world coordinates
`phimin` :
start angle of the disk sector in degrees
`phimax` :
end angle of the disk sector in degrees
`rmin` :
inner radius of the punctured disk in world coordinates
`rmax` :
outer radius of the punctured disk in world coordinates
`dimiphi`, `dimr` :
Phi (X) and iR (Y) dimension of the color index array
`color` :
Color index array
The two dimensional color index array is mapped to the resulting image by
interpreting the X-axis of the array as the angle and the Y-axis as the radius.
The center point of the resulting disk is located at `xorg`, `yorg` and the
radius of the disk is `rmax`.
"""
function polarcellarray(xorg::Real, yorg::Real, phimin::Real, phimax::Real, rmin::Real, rmax::Real,
dimphi::Int, dimr::Int, color)
if ndims(color) == 2
color = reshape(color, dimphi * dimr)
end
ccall( (:gr_polarcellarray, libGR),
Nothing,
(Float64, Float64, Float64, Float64, Float64, Float64, Int32, Int32, Int32, Int32, Int32, Int32, Ptr{Int32}),
xorg, yorg, phimin, phimax, rmin, rmax, dimphi, dimr, 1, 1, dimphi, dimr, convert(Vector{Int32}, color))
end
"""
nonuniformpolarcellarray(x, y, dimx::Int, dimy::Int, color)
Display a two dimensional color index array mapped to a disk using nonuniform
polar coordinates.
**Parameters:**
`x`, `y` :
X and Y coordinates of the cell edges
`dimx`, `dimy` :
X and Y dimension of the color index array
`color` :
Color index array
The two dimensional color index array is mapped to the resulting image by
interpreting the X-axis of the array as the angle and the Y-axis as the radius.
"""
function nonuniformpolarcellarray(x, y, dimx::Int, dimy::Int, color)
@assert length(x) == dimx+1 && length(y) == dimy+1
if ndims(color) == 2
color = reshape(color, dimx * dimy)
end
ccall( (:gr_nonuniformpolarcellarray, libGR),
Nothing,
(Float64, Float64, Ptr{Float64}, Ptr{Float64}, Int32, Int32, Int32, Int32, Int32, Int32, Ptr{Int32}),
0, 0, convert(Vector{Float64}, x), convert(Vector{Float64}, y), dimx, dimy, 1, 1, dimx, dimy, convert(Vector{Int32}, color))
end
"""
gdp(x, y, primid, datrec)
Generates a generalized drawing primitive (GDP) of the type you specify,
using specified points and any additional information contained in a data
record.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
`primid` :
Primitive identifier
`datrec` :
Primitive data record
"""
function gdp(x, y, primid, datrec)
@assert length(x) == length(y)
n = length(x)
ldr = length(datrec)
ccall( (:gr_gdp, libGR),
Nothing,
(Int32, Ptr{Float64}, Ptr{Float64}, Int32, Int32, Ptr{Int32}),
n, convert(Vector{Float64}, x), convert(Vector{Float64}, y),
primid, ldr, convert(Vector{Int32}, datrec))
end
"""
path(x, y, codes)
Draw paths using the given vertices and path codes.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
`codes` :
A list containing the path codes
The values for `x` and `y` are in world coordinates.
The `codes` describe several path primitives that can be used to create compound paths.
The following path codes are recognized:
+----------+---------------------------------+-------------------+-------------------+
| **Code** | **Description** | **x** | **y** |
+----------+---------------------------------+-------------------+-------------------+
| M, m | move | x | y |
+----------+---------------------------------+-------------------+-------------------+
| L, l | line | x | y |
+----------+---------------------------------+-------------------+-------------------+
| Q, q | quadratic Bezier | x1, x2 | y1, y2 |
+----------+---------------------------------+-------------------+-------------------+
| C, c | cubic Bezier | x1, x2, x3 | y1, y2, y3 |
+----------+---------------------------------+-------------------+-------------------+
| A, a | arc | rx, a1, reserved | ry, a2, reserved |
+----------+---------------------------------+-------------------+-------------------+
| Z | close path | | |
+----------+---------------------------------+-------------------+-------------------+
| S | stroke | | |
+----------+---------------------------------+-------------------+-------------------+
| s | close path and stroke | | |
+----------+---------------------------------+-------------------+-------------------+
| f | close path and fill | | |
+----------+---------------------------------+-------------------+-------------------+
| F | close path, fill and stroke | | |
+----------+---------------------------------+-------------------+-------------------+
- Move: `M`, `m`
Moves the current position to (`x`, `y`). The new position is either absolute (`M`) or relative to the current
position (`m`). The initial position of :code:`path` is (0, 0).
Example:
>>> path([0.5, -0.1], [0.2, 0.1], "Mm")
The first move command in this example moves the current position to the absolute coordinates (0.5, 0.2). The
second move to performs a movement by (-0.1, 0.1) relative to the current position resulting in the point
(0.4, 0.3).
- Line: `L`, `l`
Draws a line from the current position to the given position (`x`, `y`). The end point of the line is either
absolute (`L`) or relative to the current position (`l`). The current position is set to the end point of the
line.
Example:
>>> path([0.1, 0.5, 0.0], [0.1, 0.1, 0.2], "MLlS")
The first line to command draws a straight line from the current position (0.1, 0.1) to the absolute position
(0.5, 0.1) resulting in a horizontal line. The second line to command draws a vertical line relative to the
current position resulting in the end point (0.5, 0.3).
- Quadratic Bezier curve: `Q`, `q`
Draws a quadratic bezier curve from the current position to the end point (`x2`, `y2`) using (`x1`, `y1`) as the
control point. Both points are either absolute (`Q`) or relative to the current position (`q`). The current
position is set to the end point of the bezier curve.
Example:
>>> path([0.1, 0.3, 0.5, 0.2, 0.4], [0.1, 0.2, 0.1, 0.1, 0.0], "MQqS")
This example will generate two bezier curves whose start and end points are each located at y=0.1. As the control
points are horizontally in the middle of each bezier curve with a higher y value both curves are symmetrical
and bend slightly upwards in the middle. The current position is set to (0.9, 0.1) at the end.
- Cubic Bezier curve: `C`, `c`
Draws a cubic bezier curve from the current position to the end point (`x3`, `y3`) using (`x1`, `y1`) and
(`x2`, `y2`) as the control points. All three points are either absolute (`C`) or relative to the current position
(`c`). The current position is set to the end point of the bezier curve.
Example:
>>> path(
... [0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3],
... [0.1, 0.2, 0.0, 0.1, 0.1, -0.1, 0.0],
... "MCcS"
... )
This example will generate two bezier curves whose start and end points are each located at y=0.1. As the control
points are equally spaced along the x-axis and the first is above and the second is below the start and end
points this creates a wave-like shape for both bezier curves. The current position is set to (0.8, 0.1) at the
end.
- Ellipctical arc: `A`, `a`
Draws an elliptical arc starting at the current position. The major axis of the ellipse is aligned with the x-axis
and the minor axis is aligned with the y-axis of the plot. `rx` and `ry` are the ellipses radii along the major
and minor axis. `a1` and `a2` define the start and end angle of the arc in radians. The current position is set
to the end point of the arc. If `a2` is greater than `a1` the arc is drawn counter-clockwise, otherwise it is
drawn clockwise. The `a` and `A` commands draw the same arc. The third coordinates of the `x` and `y` array are
ignored and reserved for future use.
Examples:
>>> path([0.1, 0.2, -3.14159 / 2, 0.0], [0.1, 0.4, 3.14159 / 2, 0.0], "MAS")
This example draws an arc starting at (0.1, 0.1). As the start angle -pi/2 is smaller than the end angle pi/2 the
arc is drawn counter-clockwise. In this case the right half of an ellipse with an x radius of 0.2 and a y radius
of 0.4 is shown. Therefore the current position is set to (0.1, 0.9) at the end.
>>> path([0.1, 0.2, 3.14159 / 2, 0.0], [0.9, 0.4, -3.14159 / 2, 0.0], "MAS")
This examples draws the same arc as the previous one. The only difference is that the starting point is now at
(0.1, 0.9) and the start angle pi/2 is greater than the end angle -pi/2 so that the ellipse arc is drawn
clockwise. Therefore the current position is set to (0.1, 0.1) at the end.
- Close path: `Z`
Closes the current path by connecting the current position to the target position of the last move command