FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot/term/canvas.trm at master · gnuplot/gnuplot · GitHub
gnuplot
gnuplot
Repository navigation
Code
Pull requests
2
(2)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot
/
term
/
canvas.trm
Copy path
More file actions
More file actions
Latest commit
History
History
History
1748 lines (1555 loc) · 56.3 KB
Breadcrumbs
gnuplot
/
term
/
canvas.trm
Copy path
File metadata and controls
1748 lines (1555 loc) · 56.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/* Hello, Emacs, this is -*-C-*- */
/* GNUPLOT - canvas.trm */
/*
* This file is included by ../term.c.
*
* This terminal driver supports:
* W3C HTML <canvas> tag
*
* AUTHOR
* Bruce Lueckenhoff, Aug 2008
* Bruce_Lueckenhoff@yahoo.com
*
* Additions
* Ethan A Merritt, Jan 2009
* CANVAS_set_color(), CANVAS_make_palette(), CANVAS_fillbox(), fillstyles,
* CANVAS_point(), CANVAS_pointsize()
* "name <foo>" option to create only a callable javascript file foo.js
* "fsize <F>" option to select font size (default remains 10.0)
* Ethan A Merritt, Jan 2009
* Prototype mousing code in separate file gnuplot_mouse.js
* Ethan A Merritt, Feb 2009
* Enhanced text support. Note: character placement could be done more
* precisely by moving the enhanced text code into the javascript routines,
* where exact character widths are known, and save/restore can be used.
* Ethan A Merritt, Mar 2009
* Oversampling and client-side zoom/unzoom, hotkeys
* Ethan A Merritt, May 2009
* Give each plot its own namespace for mousing (allows multiple mouseable
* plots in a single HTML document).
* Ethan A Merritt, Nov 2010
* Dashed line support, butt/rounded line properties
* revised javascript with all methods and variables in container gnuplot()
* Ethan A Merritt, Feb/Mar/Apr 2011
* Optional explicit background
* Wrap each plot in a test for gnuplot.hide_plot_N
* Handle image data by storing it in a parallel PNG file
* Ethan A Merritt, Mar 2012
* Hypertext
* Ethan A Merritt, Jan 2018
* Always apply new color, including alpha channel, to both strokeStyle
* and fillStyle. This allows the terminal to honor RGBA colors for
* lines and points (added to core code in version 4.6)
*
* send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
*
*/
#include
"driver.h"
#ifdef
TERM_REGISTER
register_term
(
canvas_driver
)
#endif
#ifdef
TERM_PROTO
TERM_PUBLIC
void
CANVAS_options
(
void
);
TERM_PUBLIC
void
CANVAS_init
(
void
);
TERM_PUBLIC
void
CANVAS_graphics
(
void
);
TERM_PUBLIC
int
CANVAS_justify_text
(
enum
JUSTIFY
mode
);
TERM_PUBLIC
void
CANVAS_text
(
void
);
TERM_PUBLIC
void
CANVAS_reset
(
void
);
TERM_PUBLIC
void
CANVAS_linetype
(
int
linetype
);
TERM_PUBLIC
void
CANVAS_dashtype
(
int
type
,
t_dashtype
*
custom_dash_type
);
TERM_PUBLIC
void
CANVAS_fillbox
(
int
style
,
unsigned
int
x1
,
unsigned
int
y1
,
unsigned
int
width
,
unsigned
int
height
);
TERM_PUBLIC
void
CANVAS_linewidth
(
double
linewidth
);
TERM_PUBLIC
void
CANVAS_move
(
unsigned
int
x
,
unsigned
int
y
);
TERM_PUBLIC
void
CANVAS_vector
(
unsigned
int
x
,
unsigned
int
y
);
TERM_PUBLIC
void
CANVAS_point
(
unsigned
int
x
,
unsigned
int
y
,
int
number
);
TERM_PUBLIC
void
CANVAS_pointsize
(
double
size
);
TERM_PUBLIC
void
CANVAS_put_text
(
unsigned
int
x
,
unsigned
int
y
,
const
char
*
str
);
TERM_PUBLIC
int
CANVAS_text_angle
(
float
ang
);
TERM_PUBLIC
void
CANVAS_filled_polygon
(
int
,
gpiPoint
*
);
TERM_PUBLIC
void
CANVAS_set_color
(
t_colorspec
*
colorspec
);
TERM_PUBLIC
int
CANVAS_make_palette
(
t_sm_palette
*
palette
);
TERM_PUBLIC
void
CANVAS_layer
(
t_termlayer
);
TERM_PUBLIC
void
CANVAS_path
(
int
);
TERM_PUBLIC
void
CANVAS_hypertext
(
int
,
const
char
*
);
TERM_PUBLIC
int
CANVAS_set_font
(
const
char
*
);
TERM_PUBLIC
void
ENHCANVAS_OPEN
(
char
*
,
double
,
double
,
TBOOLEAN
,
TBOOLEAN
,
int
);
TERM_PUBLIC
void
ENHCANVAS_FLUSH
(
void
);
TERM_PUBLIC
void
ENHCANVAS_put_text
(
unsigned
int
,
unsigned
int
,
const
char
*
);
#define
CANVAS_OVERSAMPLE
10.
#define
CANVAS_XMAX
(600 * CANVAS_OVERSAMPLE)
#define
CANVAS_YMAX
(400 * CANVAS_OVERSAMPLE)
#define
CANVASVTIC
(10 * CANVAS_OVERSAMPLE)
#define
CANVASHTIC
(10 * CANVAS_OVERSAMPLE)
#define
CANVASVCHAR
(10 * CANVAS_OVERSAMPLE)
#define
CANVASHCHAR
(8 * CANVAS_OVERSAMPLE)
#endif
/* TERM_PROTO */
#ifdef
TERM_BODY
#define
CANVAS_AXIS_CONST
'\1'
#define
CANVAS_BORDER_CONST
'\2'
static
int
canvas_x
=
-1
;
/* current X position */
static
int
canvas_y
=
-1
;
/* current Y position */
static
int
canvas_xmax
=
CANVAS_XMAX
;
static
int
canvas_ymax
=
CANVAS_YMAX
;
static
int
canvas_line_type
=
LT_UNDEFINED
;
static
int
canvas_dash_type
=
DASHTYPE_SOLID
;
static
double
canvas_linewidth
=
1.0
;
static
double
canvas_dashlength_factor
=
1.0
;
static
double
CANVAS_ps
=
1
;
/* pointsize multiplier */
static
double
CANVAS_default_fsize
=
10
;
static
double
canvas_font_size
=
10
;
static
double
canvas_fontscale
=
1.0
;
static
char
*
canvas_font_name
=
NULL
;
static
char
*
canvas_justify
=
""
;
static
int
canvas_text_angle
=
0
;
static
int
canvas_in_a_path
=
FALSE;
static
int
already_closed
=
FALSE;
static
TBOOLEAN
canvas_dashed
=
TRUE;
/* Version 5: dashes always enabled */
static
t_linecap
canvas_linecap
=
ROUNDED
;
static
TBOOLEAN
CANVAS_mouseable
=
FALSE;
static
TBOOLEAN
CANVAS_standalone
=
TRUE;
static
char
CANVAS_background
[
18
]
=
{
'\0'
};
static
char
*
CANVAS_name
=
NULL
;
static
char
*
CANVAS_scriptdir
=
NULL
;
static
char
*
CANVAS_title
=
NULL
;
static
char
*
CANVAS_hypertext_text
=
NULL
;
/*
* Stuff for tracking images stored in separate files
* to be referenced by canvas.drawImage();
*/
static
int
CANVAS_imageno
=
0
;
typedef
struct
canvas_imagefile
{
int
imageno
;
/* Used to generate the internal name */
char
*
filename
;
/* The parallel file that it maps to */
struct
canvas_imagefile
*
next
;
}
canvas_imagefile
;
static
canvas_imagefile
*
imagelist
=
NULL
;
static
struct
{
int
previous_linewidth
;
double
alpha
;
/* alpha channel */
char
color
[
24
];
/* rgba(rrr,ggg,bbb,aaaa) */
char
previous_color
[
24
];
/* rgba(rrr,ggg,bbb,aaaa) */
char
previous_fill
[
24
];
/* rgba(rrr,ggg,bbb,aaaa) */
int
plotno
;
/* Which plot are we in? */
}
canvas_state
;
enum
CANVAS_case
{
CANVAS_SIZE
,
CANVAS_FONT
,
CANVAS_FSIZE
,
CANVAS_NAME
,
CANVAS_STANDALONE
,
CANVAS_TITLE
,
CANVAS_LINEWIDTH
,
CANVAS_MOUSING
,
CANVAS_JSDIR
,
CANVAS_ENH
,
CANVAS_NOENH
,
CANVAS_FONTSCALE
,
CANVAS_SOLID
,
CANVAS_DASHED
,
CANVAS_DASHLENGTH
,
CANVAS_ROUNDED
,
CANVAS_BUTT
,
CANVAS_SQUARE
,
CANVAS_BACKGROUND
,
CANVAS_OTHER
};
static
struct
gen_table
CANVAS_opts
[]
=
{
{
"font"
,
CANVAS_FONT
},
{
"fsize"
,
CANVAS_FSIZE
},
{
"name"
,
CANVAS_NAME
},
{
"size"
,
CANVAS_SIZE
},
{
"standalone"
,
CANVAS_STANDALONE
},
{
"mous$ing"
,
CANVAS_MOUSING
},
{
"mouse"
,
CANVAS_MOUSING
},
{
"js$dir"
,
CANVAS_JSDIR
},
{
"enh$anced"
,
CANVAS_ENH
},
{
"noenh$anced"
,
CANVAS_NOENH
},
{
"lw"
,
CANVAS_LINEWIDTH
},
{
"linew$idth"
,
CANVAS_LINEWIDTH
},
{
"title"
,
CANVAS_TITLE
},
{
"fontscale"
,
CANVAS_FONTSCALE
},
{
"solid"
,
CANVAS_SOLID
},
{
"dash$ed"
,
CANVAS_DASHED
},
{
"dashl$ength"
,
CANVAS_DASHLENGTH
},
{
"dl"
,
CANVAS_DASHLENGTH
},
{
"round$ed"
,
CANVAS_ROUNDED
},
{
"butt"
,
CANVAS_BUTT
},
{
"square"
,
CANVAS_SQUARE
},
{
"backg$round"
,
CANVAS_BACKGROUND
},
{
NULL
,
CANVAS_OTHER
}
};
/* Fill patterns */
#define
PATTERN1
"tile.moveTo(0,0); tile.lineTo(32,32); tile.moveTo(0,16); tile.lineTo(16,32); tile.moveTo(16,0); tile.lineTo(32,16);"
#define
PATTERN2
"tile.moveTo(0,32); tile.lineTo(32,0); tile.moveTo(0,16); tile.lineTo(16,0); tile.moveTo(16,32); tile.lineTo(32,16);"
#define
PATTERN3
"tile.moveTo(8,0); tile.lineTo(32,24); tile.moveTo(0,8); tile.lineTo(24,32); tile.moveTo(24,0); tile.lineTo(32,8); tile.moveTo(0,24); tile.lineTo(8,32); tile.moveTo(8,32); tile.lineTo(32,8); tile.moveTo(0,24); tile.lineTo(24,0); tile.moveTo(24,32); tile.lineTo(32,24); tile.moveTo(0,8); tile.lineTo(8,0);"
static
void
CANVAS_start
(
void
)
{
if
(
canvas_in_a_path
)
return
;
fprintf
(
gpoutfile
,
"ctx.beginPath();\n"
);
canvas_in_a_path
=
TRUE;
already_closed
=
FALSE;
}
static
void
CANVAS_finish
(
void
)
{
if
(!
canvas_in_a_path
)
return
;
fprintf
(
gpoutfile
,
"ctx.stroke();\n"
);
if
(!
already_closed
)
fprintf
(
gpoutfile
,
"ctx.closePath();\n"
);
canvas_in_a_path
=
FALSE;
already_closed
=
TRUE;
}
TERM_PUBLIC
void
CANVAS_options
()
{
int
canvas_background
=
0
;
if
(!
almost_equals
(
c_token
-
1
,
"termopt$ion"
)) {
/* Re-initialize a few things */
canvas_font_size
=
CANVAS_default_fsize
=
10
;
canvas_fontscale
=
1.0
;
CANVAS_standalone
=
TRUE;
CANVAS_mouseable
=
FALSE;
free
(
CANVAS_name
);
CANVAS_name
=
NULL
;
free
(
CANVAS_title
);
CANVAS_title
=
NULL
;
free
(
CANVAS_scriptdir
);
CANVAS_scriptdir
=
NULL
;
canvas_linewidth
=
1.0
;
canvas_dashed
=
TRUE;
canvas_dashlength_factor
=
1.0
;
CANVAS_background
[
0
]
=
'\0'
;
/* Default to enhanced text mode */
term
->
put_text
=
ENHCANVAS_put_text
;
term
->
flags
|=
TERM_ENHANCED_TEXT
;
}
while
(!
END_OF_COMMAND
) {
switch
(
lookup_table
(
&
CANVAS_opts
[
0
],
c_token
++
)) {
case
CANVAS_SIZE
:
if
(
END_OF_COMMAND
) {
canvas_xmax
=
CANVAS_XMAX
;
canvas_ymax
=
CANVAS_YMAX
;
}
else
{
canvas_xmax
=
int_expression
()
*
CANVAS_OVERSAMPLE
;
if
(
equals
(
c_token
,
","
)) {
c_token
++
;
canvas_ymax
=
int_expression
()
*
CANVAS_OVERSAMPLE
;
}
}
if
(
canvas_xmax
<=
0
)
canvas_xmax
=
CANVAS_XMAX
;
if
(
canvas_ymax
<=
0
)
canvas_ymax
=
CANVAS_YMAX
;
term
->
xmax
=
canvas_xmax
;
term
->
ymax
=
canvas_ymax
;
break
;
case
CANVAS_TITLE
:
CANVAS_title
=
try_to_get_string
();
if
(!
CANVAS_title
)
int_error
(
c_token
,
"expecting an HTML title string"
);
break
;
case
CANVAS_NAME
:
CANVAS_name
=
try_to_get_string
();
if
(!
CANVAS_name
)
int_error
(
c_token
,
"expecting a javascript function name"
);
if
(
CANVAS_name
[
strspn
(
CANVAS_name
,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_1234567890"
)])
int_error
(
c_token
-
1
,
"illegal javascript function name"
);
CANVAS_standalone
=
FALSE;
break
;
case
CANVAS_STANDALONE
:
CANVAS_standalone
=
TRUE;
break
;
case
CANVAS_FONT
:
/* FIXME: See note at CANVAS_set_font() */
free
(
canvas_font_name
);
if
(!(
canvas_font_name
=
try_to_get_string
()))
int_error
(
c_token
,
"font: expecting string"
);
CANVAS_set_font
(
canvas_font_name
);
break
;
case
CANVAS_FSIZE
:
CANVAS_default_fsize
=
real_expression
();
if
(
CANVAS_default_fsize
<=
0
)
CANVAS_default_fsize
=
10
;
canvas_font_size
=
CANVAS_default_fsize
;
break
;
case
CANVAS_MOUSING
:
CANVAS_mouseable
=
TRUE;
break
;
case
CANVAS_JSDIR
:
CANVAS_scriptdir
=
try_to_get_string
();
break
;
case
CANVAS_ENH
:
term
->
put_text
=
ENHCANVAS_put_text
;
term
->
flags
|=
TERM_ENHANCED_TEXT
;
break
;
case
CANVAS_NOENH
:
term
->
put_text
=
CANVAS_put_text
;
term
->
flags
&= ~
TERM_ENHANCED_TEXT
;
break
;
case
CANVAS_LINEWIDTH
:
canvas_linewidth
=
real_expression
();
if
(
canvas_linewidth
<=
0
)
canvas_linewidth
=
1.0
;
break
;
case
CANVAS_FONTSCALE
:
canvas_fontscale
=
real_expression
();
if
(
canvas_fontscale
<=
0
)
canvas_fontscale
=
1.0
;
break
;
case
CANVAS_SOLID
:
case
CANVAS_DASHED
:
/* Version 5 always allows dashes */
canvas_dashed
=
TRUE;
break
;
case
CANVAS_DASHLENGTH
:
canvas_dashlength_factor
=
real_expression
();
if
(
canvas_dashlength_factor
<=
0.2
)
canvas_dashlength_factor
=
1.0
;
break
;
case
CANVAS_ROUNDED
:
canvas_linecap
=
ROUNDED
;
break
;
case
CANVAS_BUTT
:
canvas_linecap
=
BUTT
;
break
;
case
CANVAS_SQUARE
:
canvas_linecap
=
SQUARE
;
break
;
case
CANVAS_BACKGROUND
:
canvas_background
=
parse_color_name
();
sprintf
(
CANVAS_background
,
" rgb(%03d,%03d,%03d)"
,
(
canvas_background
>>
16
)
&
0xff
,
(
canvas_background
>>
8
)
&
0xff
,
canvas_background
&
0xff
);
break
;
default
:
int_warn
(
c_token
-
1
,
"unrecognized terminal option"
);
break
;
}
}
term
->
v_char
=
canvas_font_size
*
canvas_fontscale
*
CANVAS_OVERSAMPLE
;
term
->
h_char
=
canvas_font_size
*
canvas_fontscale
*
0.8
*
CANVAS_OVERSAMPLE
;
if
(
canvas_dashlength_factor
!=
1.0
)
sprintf
(
term_options
+
strlen
(
term_options
),
" dashlength %3.1f"
,
canvas_dashlength_factor
);
sprintf
(
term_options
+
strlen
(
term_options
),
canvas_linecap
==
ROUNDED
?
" rounded"
:
canvas_linecap
==
SQUARE
?
" square"
:
" butt"
);
sprintf
(
term_options
+
strlen
(
term_options
),
" size %d,%d"
, (
int
)(
term
->
xmax
/
CANVAS_OVERSAMPLE
), (
int
)(
term
->
ymax
/
CANVAS_OVERSAMPLE
));
sprintf
(
term_options
+
strlen
(
term_options
),
"%s fsize %g lw %g"
,
term
->
put_text
==
ENHCANVAS_put_text
?
" enhanced"
:
""
,
canvas_font_size
,
canvas_linewidth
);
sprintf
(
term_options
+
strlen
(
term_options
),
" fontscale %g"
,
canvas_fontscale
);
if
(
*
CANVAS_background
)
sprintf
(
term_options
+
strlen
(
term_options
),
" background \"#%06x\""
,
canvas_background
);
if
(
CANVAS_name
)
sprintf
(
term_options
+
strlen
(
term_options
),
" name \"%s\""
,
CANVAS_name
);
else
{
sprintf
(
term_options
+
strlen
(
term_options
),
" standalone"
);
if
(
CANVAS_mouseable
)
sprintf
(
term_options
+
strlen
(
term_options
),
" mousing"
);
if
(
CANVAS_title
)
sprintf
(
term_options
+
strlen
(
term_options
),
" title \"%s\""
,
CANVAS_title
);
}
if
(
CANVAS_scriptdir
)
sprintf
(
term_options
+
strlen
(
term_options
),
" jsdir \"%s\""
,
CANVAS_scriptdir
);
}
TERM_PUBLIC
void
CANVAS_init
()
{
}
TERM_PUBLIC
void
CANVAS_graphics
()
{
int
len
;
/* Force initialization at the beginning of each plot */
canvas_line_type
=
LT_UNDEFINED
;
canvas_text_angle
=
0
;
canvas_in_a_path
=
FALSE;
canvas_state
.
previous_linewidth
=
-1
;
canvas_state
.
previous_color
[
0
]
=
'\0'
;
canvas_state
.
previous_fill
[
0
]
=
'\0'
;
strcpy
(
canvas_state
.
color
,
"rgba(000,000,000,0.00)"
);
canvas_state
.
plotno
=
0
;
/*
* FIXME: This code could be shared with svg.trm
* Figure out where to find javascript support routines
* when the page is viewed.
*/
if
(
CANVAS_scriptdir
==
NULL
) {
#ifdef
GNUPLOT_JS_DIR
# if
defined(
_WIN32
)
||
defined(
MSDOS
)
||
defined(
OS2
)
CANVAS_scriptdir
=
RelativePathToGnuplot
(
GNUPLOT_JS_DIR
);
# else
/* use hardcoded _absolute_ path */
CANVAS_scriptdir
=
strdup
(
GNUPLOT_JS_DIR
);
# endif
#else
CANVAS_scriptdir
=
strdup
(
""
);
#endif
/* GNUPLOT_JS_DIR */
}
len
=
strlen
(
CANVAS_scriptdir
);
# if
defined(
_WIN32
)
||
defined(
MSDOS
)
||
defined(
OS2
)
if
(
*
CANVAS_scriptdir
&&
CANVAS_scriptdir
[
len
-
1
]
!=
'\\'
&&
CANVAS_scriptdir
[
len
-
1
]
!=
'/'
) {
CANVAS_scriptdir
=
gp_realloc
(
CANVAS_scriptdir
,
len
+
2
,
"jsdir"
);
if
(
CANVAS_scriptdir
[
len
-
1
]
==
'\\'
)
/* use backslash if used in jsdir, otherwise slash */
strcat
(
CANVAS_scriptdir
,
"\\"
);
else
strcat
(
CANVAS_scriptdir
,
"/"
);
}
# else
if
(
*
CANVAS_scriptdir
&&
CANVAS_scriptdir
[
len
-
1
]
!=
'/'
) {
CANVAS_scriptdir
=
gp_realloc
(
CANVAS_scriptdir
,
len
+
2
,
"jsdir"
);
strcat
(
CANVAS_scriptdir
,
"/"
);
}
# endif
if
(
CANVAS_standalone
) {
fprintf
(
gpoutfile
,
"<!DOCTYPE HTML>\n"
"<html>\n"
"<head>\n"
"<title>%s</title>\n"
,
CANVAS_title
?
CANVAS_title
:
"Gnuplot Canvas Graph"
);
if
(
encoding
==
S_ENC_UTF8
||
encoding
==
S_ENC_DEFAULT
)
fprintf
(
gpoutfile
,
"<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n"
);
fprintf
(
gpoutfile
,
"<!--[if IE]><script type=\"text/javascript\" src=\"excanvas.js\"></script><![endif]-->\n"
"<script src=\"%s%s.js\"></script>\n"
"<script src=\"%sgnuplot_common.js\"></script>\n"
,
CANVAS_scriptdir
, (
encoding
==
S_ENC_UTF8
) ?
"canvasmath"
:
"canvastext"
,
CANVAS_scriptdir
);
if
(
canvas_dashed
)
fprintf
(
gpoutfile
,
"<script src=\"%sgnuplot_dashedlines.js\"></script>\n"
,
CANVAS_scriptdir
);
if
(
CANVAS_mouseable
) {
fprintf
(
gpoutfile
,
"<script src=\"%sgnuplot_mouse.js\"></script>\n"
,
CANVAS_scriptdir
);
fprintf
(
gpoutfile
,
"<script type=\"text/javascript\"> "
"gnuplot.help_URL = \"%s/canvas_help.html\"; </script>\n"
,
CANVAS_scriptdir
);
}
else
{
fprintf
(
gpoutfile
,
"<script type=\"text/javascript\">"
"gnuplot.init = function() {};</script>\n"
);
}
fprintf
(
gpoutfile
,
"<script type=\"text/javascript\">\n"
"var canvas, ctx;\n"
"gnuplot.grid_lines = true;\n"
"gnuplot.zoomed = false;\n"
"gnuplot.active_plot_name = \"gnuplot_canvas\";\n\n"
"function gnuplot_canvas() {\n"
"canvas = document.getElementById(\"gnuplot_canvas\");\n"
"ctx = canvas.getContext(\"2d\");\n"
);
}
else
{
fprintf
(
gpoutfile
,
"function %s() {\n"
"canvas = document.getElementById(\"%s\");\n"
"ctx = canvas.getContext(\"2d\");\n"
,
CANVAS_name
,
CANVAS_name
);
fprintf
(
gpoutfile
,
"// Suppress refresh on mouseover if this was the plot we just left\n"
"if ((gnuplot.active_plot == %s && gnuplot.display_is_uptodate)) return;\n"
"else gnuplot.display_is_uptodate = true;\n"
,
CANVAS_name
);
fprintf
(
gpoutfile
,
"// Reinitialize mouse tracking and zoom for this particular plot\n"
"if ((typeof(gnuplot.active_plot) == \"undefined\" || gnuplot.active_plot != %s) && typeof(gnuplot.mouse_update) != \"undefined\") {\n"
" gnuplot.active_plot_name = \"%s\";\n"
" gnuplot.active_plot = %s;\n"
" canvas.onmousemove = gnuplot.mouse_update;\n"
" canvas.onmouseup = gnuplot.zoom_in;\n"
" canvas.onmousedown = gnuplot.saveclick;\n"
" canvas.onkeypress = gnuplot.do_hotkey;\n"
" if (canvas.attachEvent) {canvas.attachEvent('mouseover', %s);}\n"
" else if (canvas.addEventListener) {canvas.addEventListener('mouseover', %s, false);} \n"
" gnuplot.zoomed = false;\n"
" gnuplot.zoom_axis_width = 0;\n"
" gnuplot.zoom_in_progress = false;\n"
,
CANVAS_name
,
CANVAS_name
,
CANVAS_name
,
CANVAS_name
,
CANVAS_name
);
fprintf
(
gpoutfile
,
" gnuplot.polar_mode = %s;\n"
" gnuplot.polar_theta0 = %d;\n"
" gnuplot.polar_sense = %d;\n"
" ctx.clearRect(0,0,%d,%d);\n"
"}\n"
,
(
polar
) ?
"true"
:
"false"
, (
int
)
theta_origin
, (
int
)
theta_direction
,
(
int
)(
term
->
xmax
/
CANVAS_OVERSAMPLE
), (
int
)(
term
->
ymax
/
CANVAS_OVERSAMPLE
));
}
fprintf
(
gpoutfile
,
"// Gnuplot version %s.%s\n"
,
gnuplot_version
,
gnuplot_patchlevel
);
fprintf
(
gpoutfile
,
"// short forms of commands provided by gnuplot_common.js\n"
"function DT (dt) {gnuplot.dashtype(dt);};\n"
"function DS (x,y) {gnuplot.dashstart(x,y);};\n"
"function DL (x,y) {gnuplot.dashstep(x,y);};\n"
"function M (x,y) {if (gnuplot.pattern.length > 0) DS(x,y); else gnuplot.M(x,y);};\n"
"function L (x,y) {if (gnuplot.pattern.length > 0) DL(x,y); else gnuplot.L(x,y);};\n"
"function Dot (x,y) {gnuplot.Dot(x/10.,y/10.);};\n"
"function Pt (N,x,y,w) {gnuplot.Pt(N,x/10.,y/10.,w/10.);};\n"
"function R (x,y,w,h) {gnuplot.R(x,y,w,h);};\n"
"function T (x,y,fontsize,justify,string) {gnuplot.T(x,y,fontsize,justify,string);};\n"
"function TR (x,y,angle,fontsize,justify,string) {gnuplot.TR(x,y,angle,fontsize,justify,string);};\n"
"function bp (x,y) {gnuplot.bp(x,y);};\n"
"function cfp () {gnuplot.cfp();};\n"
"function cfsp() {gnuplot.cfsp();};\n"
"\n"
);
fprintf
(
gpoutfile
,
"gnuplot.hypertext_list = [];\n"
"gnuplot.on_hypertext = -1;\n"
"function Hypertext(x,y,w,text) {\n"
" newtext = {x:x, y:y, w:w, text:text};\n"
" gnuplot.hypertext_list.push(newtext);\n"
"}\n"
);
fprintf
(
gpoutfile
,
"gnuplot.dashlength = %d;\n"
,
(
int
)(
400
*
canvas_dashlength_factor
)
);
fprintf
(
gpoutfile
,
"ctx.lineCap = \"%s\"; ctx.lineJoin = \"%s\";\n"
,
canvas_linecap
==
ROUNDED
?
"round"
:
canvas_linecap
==
SQUARE
?
"square"
:
"butt"
,
canvas_linecap
==
ROUNDED
?
"round"
:
"miter"
);
if
(
*
CANVAS_background
) {
fprintf
(
gpoutfile
,
"ctx.fillStyle = \"%s\";\n"
"ctx.fillRect(0,0,%d,%d);\n"
,
CANVAS_background
,
(
int
)(
term
->
xmax
/
CANVAS_OVERSAMPLE
),
(
int
)(
term
->
ymax
/
CANVAS_OVERSAMPLE
));
}
fprintf
(
gpoutfile
,
"CanvasTextFunctions.enable(ctx);\n"
"ctx.strokeStyle = \" rgb(215,215,215)\";\n"
"ctx.lineWidth = %.1g;\n\n"
,
canvas_linewidth
);
}
static
void
CANVAS_mouse_param
(
char
*
gp_name
,
const
char
*
js_name
)
{
struct
udvt_entry
*
udv
;
if
((
udv
=
add_udv_by_name
(
gp_name
))) {
if
(
udv
->
udv_value
.
type
==
INTGR
) {
fprintf
(
gpoutfile
,
"%s = "
,
js_name
);
fprintf
(
gpoutfile
,
PLD
,
udv
->
udv_value
.
v
.
int_val
);
fprintf
(
gpoutfile
,
"\n"
);
}
else
if
(
udv
->
udv_value
.
type
==
CMPLX
) {
fprintf
(
gpoutfile
,
"%s = %g;\n"
,
js_name
,
udv
->
udv_value
.
v
.
cmplx_val
.
real
);
}
}
}
TERM_PUBLIC
void
CANVAS_text
()
{
struct
axis
*
this_axis
;
CANVAS_finish
();
/* FIXME: I am not sure whether these variable names should always be the */
/* same, so that they are re-used by all plots in a document, or whether */
/* they should be tied to the function name and hence private. */
if
(TRUE) {
fprintf
(
gpoutfile
,
"\n// plot boundaries and axis scaling information for mousing \n"
);
fprintf
(
gpoutfile
,
"gnuplot.plot_term_xmax = %d;\n"
, (
int
)(
term
->
xmax
/
CANVAS_OVERSAMPLE
));
fprintf
(
gpoutfile
,
"gnuplot.plot_term_ymax = %d;\n"
, (
int
)(
term
->
ymax
/
CANVAS_OVERSAMPLE
));
fprintf
(
gpoutfile
,
"gnuplot.plot_xmin = %.1f;\n"
, (
double
)
plot_bounds
.
xleft
/
CANVAS_OVERSAMPLE
);
fprintf
(
gpoutfile
,
"gnuplot.plot_xmax = %.1f;\n"
, (
double
)
plot_bounds
.
xright
/
CANVAS_OVERSAMPLE
);
fprintf
(
gpoutfile
,
"gnuplot.plot_ybot = %.1f;\n"
, (
double
)(
term
->
ymax
-
plot_bounds
.
ybot
) /
CANVAS_OVERSAMPLE
);
fprintf
(
gpoutfile
,
"gnuplot.plot_ytop = %.1f;\n"
, (
double
)(
term
->
ymax
-
plot_bounds
.
ytop
) /
CANVAS_OVERSAMPLE
);
fprintf
(
gpoutfile
,
"gnuplot.plot_width = %.1f;\n"
, (
double
)(
plot_bounds
.
xright
-
plot_bounds
.
xleft
) /
CANVAS_OVERSAMPLE
);
fprintf
(
gpoutfile
,
"gnuplot.plot_height = %.1f;\n"
, (
double
)(
plot_bounds
.
ytop
-
plot_bounds
.
ybot
) /
CANVAS_OVERSAMPLE
);
/* Get true axis ranges as used in the plot */
update_gpval_variables
(
1
);
#define
MOUSE_PARAM
(
GP_NAME
,
js_NAME
) CANVAS_mouse_param( GP_NAME, js_NAME)
if
(
axis_array
[
FIRST_X_AXIS
].
datatype
!=
DT_TIMEDATE
) {
MOUSE_PARAM
(
"GPVAL_X_MIN"
,
"gnuplot.plot_axis_xmin"
);
MOUSE_PARAM
(
"GPVAL_X_MAX"
,
"gnuplot.plot_axis_xmax"
);
}
/* FIXME: Should this inversion be done at a higher level? */
if
(
is_3d_plot
&&
splot_map
) {
MOUSE_PARAM
(
"GPVAL_Y_MAX"
,
"gnuplot.plot_axis_ymin"
);
MOUSE_PARAM
(
"GPVAL_Y_MIN"
,
"gnuplot.plot_axis_ymax"
);
}
else
{
MOUSE_PARAM
(
"GPVAL_Y_MIN"
,
"gnuplot.plot_axis_ymin"
);
MOUSE_PARAM
(
"GPVAL_Y_MAX"
,
"gnuplot.plot_axis_ymax"
);
}
if
(
polar
) {
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_rmin = %g;\n"
,
(
R_AXIS
.
autoscale
&
AUTOSCALE_MIN
) ?
0.0
:
R_AXIS
.
set_min
);
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_rmax = %g;\n"
,
R_AXIS
.
set_max
);
}
if
((
axis_array
[
SECOND_X_AXIS
].
ticmode
&
TICS_MASK
)
!=
NO_TICS
) {
MOUSE_PARAM
(
"GPVAL_X2_MIN"
,
"gnuplot.plot_axis_x2min"
);
MOUSE_PARAM
(
"GPVAL_X2_MAX"
,
"gnuplot.plot_axis_x2max"
);
}
else
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_x2min = \"none\"\n"
);
if
(
axis_array
[
SECOND_X_AXIS
].
linked_to_primary
&&
axis_array
[
FIRST_X_AXIS
].
link_udf
->
at
) {
fprintf
(
gpoutfile
,
"gnuplot.x2_mapping = function(x) { return x; };"
);
fprintf
(
gpoutfile
,
" // replace returned value with %s\n"
,
axis_array
[
FIRST_X_AXIS
].
link_udf
->
definition
);
}
if
((
axis_array
[
SECOND_Y_AXIS
].
ticmode
&
TICS_MASK
)
!=
NO_TICS
) {
MOUSE_PARAM
(
"GPVAL_Y2_MIN"
,
"gnuplot.plot_axis_y2min"
);
MOUSE_PARAM
(
"GPVAL_Y2_MAX"
,
"gnuplot.plot_axis_y2max"
);
}
else
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_y2min = \"none\"\n"
);
if
(
axis_array
[
SECOND_Y_AXIS
].
linked_to_primary
&&
axis_array
[
FIRST_Y_AXIS
].
link_udf
->
at
) {
fprintf
(
gpoutfile
,
"gnuplot.y2_mapping = function(y) { return y; };"
);
fprintf
(
gpoutfile
,
" // replace returned value with %s\n"
,
axis_array
[
FIRST_Y_AXIS
].
link_udf
->
definition
);
}
#undef
MOUSE_PARAM
/*
* Note:
* Offline mousing cannot automatically deal with
* (1) nonlinear axes other than logscale
* (2) [x,y]->plot_coordinates as specified by mouse_mode 8
* 'set mouse mouseformat function <foo>'
* Both of these states are noted by gnuplot_svg.plot_logaxis_* < 0
* Linked axes that happen to be nonlinear are incorrectly treated as linear
* (3) generic user-specified coordinate format (mouse_alt_string)
* 'set mouse mouseformat "foo"'
* Special case mouse_alt_string formats recognized by gnuplot_svg.js are
* "Time", "Date", and "DateTime".
* FIXME: This all needs to be documented somewhere!
*/
# define
is_nonlinear
(
axis
) ((axis)->linked_to_primary != NULL \
&& (axis)->link_udf->at != NULL \
&& (axis)->index == -((axis)->linked_to_primary->index))
this_axis
=
&
axis_array
[
FIRST_X_AXIS
];
fprintf
(
gpoutfile
,
"gnuplot.plot_logaxis_x = %d;\n"
,
this_axis
->
log
?
1
: (
mouse_mode
==
MOUSE_COORDINATES_FUNCTION
||
is_nonlinear
(
this_axis
)) ?
-1
:
0
);
this_axis
=
&
axis_array
[
FIRST_Y_AXIS
];
fprintf
(
gpoutfile
,
"gnuplot.plot_logaxis_y = %d;\n"
,
this_axis
->
log
?
1
: (
mouse_mode
==
MOUSE_COORDINATES_FUNCTION
||
is_nonlinear
(
this_axis
)) ?
-1
:
0
);
if
(
polar
)
fprintf
(
gpoutfile
,
"gnuplot.plot_logaxis_r = %d;\n"
,
axis_array
[
POLAR_AXIS
].
log
?
1
:
0
);
if
(
axis_array
[
FIRST_X_AXIS
].
datatype
==
DT_TIMEDATE
) {
/* May need to reconstruct time to millisecond precision */
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_xmin = %.3f;\n"
,
axis_array
[
FIRST_X_AXIS
].
min
);
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_xmax = %.3f;\n"
,
axis_array
[
FIRST_X_AXIS
].
max
);
fprintf
(
gpoutfile
,
"gnuplot.plot_timeaxis_x = \"%s\";\n"
,
(
mouse_alt_string
) ?
mouse_alt_string
: (
mouse_mode
==
4
) ?
"Date"
: (
mouse_mode
==
5
) ?
"Time"
:
"DateTime"
);
}
else
if
(
axis_array
[
FIRST_X_AXIS
].
datatype
==
DT_DMS
) {
fprintf
(
gpoutfile
,
"gnuplot.plot_timeaxis_x = \"%s\";\n"
,
(
mouse_alt_string
) ?
mouse_alt_string
:
"DMS"
);
}
else
fprintf
(
gpoutfile
,
"gnuplot.plot_timeaxis_x = \"\";\n"
);
if
(
axis_array
[
FIRST_Y_AXIS
].
datatype
==
DT_DMS
) {
fprintf
(
gpoutfile
,
"gnuplot.plot_timeaxis_y = \"%s\";\n"
,
(
mouse_alt_string
) ?
mouse_alt_string
:
"DMS"
);
}
else
fprintf
(
gpoutfile
,
"gnuplot.plot_timeaxis_y = \"\";\n"
);
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_width = gnuplot.plot_axis_xmax - gnuplot.plot_axis_xmin;\n"
);
fprintf
(
gpoutfile
,
"gnuplot.plot_axis_height = gnuplot.plot_axis_ymax - gnuplot.plot_axis_ymin;\n"
);
}
/* End of section writing out variables for mousing */
/* This is the end of the javascript plot */
fprintf
(
gpoutfile
,
"}\n"
);
#ifdef
WRITE_PNG_IMAGE
/* Link internal image structures to external PNG files */
if
(
imagelist
) {
canvas_imagefile
*
thisimage
=
imagelist
;
char
*
base_name
=
CANVAS_name
?
CANVAS_name
:
"gp"
;
while
(
thisimage
!=
NULL
) {
fprintf
(
stderr
,
" linking image %d to external file %s\n"
,
thisimage
->
imageno
,
thisimage
->
filename
);
fprintf
(
gpoutfile
,
" var %s_image_%02d = new Image();"
,
base_name
,
thisimage
->
imageno
);
fprintf
(
gpoutfile
,
" %s_image_%02d.src = \"%s\";\n"
,
base_name
,
thisimage
->
imageno
,
thisimage
->
filename
);
imagelist
=
thisimage
->
next
;
free
(
thisimage
->
filename
);
free
(
thisimage
);
thisimage
=
imagelist
;
}
}
#endif
if
(
CANVAS_standalone
) {
fprintf
(
gpoutfile
,
"</script>\n"
"<link type=\"text/css\" href=\"%sgnuplot_mouse.css\" rel=\"stylesheet\">\n"
"</head>\n"
"<body onload=\"gnuplot_canvas(); gnuplot.init();\" oncontextmenu=\"return false;\">\n\n"
"<div class=\"gnuplot\">\n"
,
CANVAS_scriptdir
?
CANVAS_scriptdir
:
""
);
/* Pattern-fill requires having a canvas element to hold a template
* pattern tile. Define it here but try to hide it (may not work in IE?)
*/
fprintf
(
gpoutfile
,
"<canvas id=\"Tile\" width=\"32\" height=\"32\" hidden></canvas>\n"
);
/* The format of the plot box and in particular the mouse tracking box
* are determined by the CSS specs in customizable file gnuplot_mouse.css
* We could make this even more customizable by providing an external HTML
* template, but in that case the user might as well just create a *.js
* file and provide his own wrapping HTML document.
*/
if
(
CANVAS_mouseable
) {
int
i
;
fprintf
(
gpoutfile
,
"<table class=\"mbleft\"><tr><td class=\"mousebox\">\n"
"<table class=\"mousebox\" border=0>\n"
" <tr><td class=\"mousebox\">\n"
" <table class=\"mousebox\" id=\"gnuplot_mousebox\" border=0>\n"
" <tr><td class=\"mbh\"></td></tr>\n"
" <tr><td class=\"mbh\">\n"
" <table class=\"mousebox\">\n"
" <tr>\n"
" <td class=\"icon\"></td>\n"
" <td class=\"icon\" onclick=gnuplot.toggle_grid><img src=\"%sgrid.png\" id=\"gnuplot_grid_icon\" class=\"icon-image\" alt=\"#\" title=\"toggle grid\"></td>\n"
" <td class=\"icon\" onclick=gnuplot.unzoom><img src=\"%spreviouszoom.png\" id=\"gnuplot_unzoom_icon\" class=\"icon-image\" alt=\"unzoom\" title=\"unzoom\"></td>\n"
" <td class=\"icon\" onclick=gnuplot.rezoom><img src=\"%snextzoom.png\" id=\"gnuplot_rezoom_icon\" class=\"icon-image\" alt=\"rezoom\" title=\"rezoom\"></td>\n"
" <td class=\"icon\" onclick=gnuplot.toggle_zoom_text><img src=\"%stextzoom.png\" id=\"gnuplot_textzoom_icon\" class=\"icon-image\" alt=\"zoom text\" title=\"zoom text with plot\"></td>\n"
" <td class=\"icon\" onclick=gnuplot.popup_help()><img src=\"%shelp.png\" id=\"gnuplot_help_icon\" class=\"icon-image\" alt=\"?\" title=\"help\"></td>\n"
" </tr>\n"
,
CANVAS_scriptdir
?
CANVAS_scriptdir
:
""
,
CANVAS_scriptdir
?
CANVAS_scriptdir
:
""
,
CANVAS_scriptdir
?
CANVAS_scriptdir
:
""
,
CANVAS_scriptdir
?
CANVAS_scriptdir
:
""
,
CANVAS_scriptdir
?
CANVAS_scriptdir
:
""
);
/* Table row of plot toggle icons goes here */
for
(
i
=
1
;
i
<=
6
*
((
canvas_state
.
plotno
+
5
)/
6
);
i
++
) {
if
((
i
%
6
)
==
1
)
fprintf
(
gpoutfile
,
" <tr>\n"
);
if
(
i
<=
canvas_state
.
plotno
)
fprintf
(
gpoutfile
,
" <td class=\"icon\" onclick=gnuplot.toggle_plot(\"gp_plot_%d\")>%d</td>\n"
,
i
,
i
);
else
fprintf
(
gpoutfile
,
" <td class=\"icon\" > </td>\n"
);
if
((
i
%
6
)
==
0
)
fprintf
(
gpoutfile
,
" </tr>\n"
);
}
fprintf
(
gpoutfile
,
" </table>\n"
" </td></tr>\n"
"</table></td></tr><tr><td class=\"mousebox\">\n"
);
fprintf
(
gpoutfile
,
"<table class=\"mousebox\" id=\"gnuplot_mousebox\" border=1>\n"
"<tr> <td class=\"mb0\">x </td> <td class=\"mb1\"><span id=\"gnuplot_canvas_x\"> </span></td> </tr>\n"
"<tr> <td class=\"mb0\">y </td> <td class=\"mb1\"><span id=\"gnuplot_canvas_y\"> </span></td> </tr>\n"
);
if
((
axis_array
[
SECOND_X_AXIS
].
ticmode
&
TICS_MASK
)
!=
NO_TICS
)
fprintf
(
gpoutfile
,
"<tr> <td class=\"mb0\">x2 </td> <td class=\"mb1\"><span id=\"gnuplot_canvas_x2\"> </span></td> </tr>\n"
);
if
((
axis_array
[
SECOND_Y_AXIS
].
ticmode
&
TICS_MASK
)
!=
NO_TICS
)
fprintf
(
gpoutfile
,
"<tr> <td class=\"mb0\">y2 </td> <td class=\"mb1\"><span id=\"gnuplot_canvas_y2\"> </span></td> </tr>\n"
);
fprintf
(
gpoutfile
,
"</table></td></tr>\n"
"</table>\n"
);
fprintf
(
gpoutfile
,
"</td><td>\n"
);
}
/* End if (CANVAS_mouseable) */
fprintf
(
gpoutfile
,
"<table class=\"plot\">\n"
"<tr><td>\n"
" <canvas id=\"gnuplot_canvas\" width=\"%d\" height=\"%d\" tabindex=\"0\">\n"
" Sorry, your browser seems not to support the HTML 5 canvas element\n"
" </canvas>\n"
"</td></tr>\n"
"</table>\n"
,
(
int
)(
term
->
xmax
/
CANVAS_OVERSAMPLE
), (
int
)(
term
->
ymax
/
CANVAS_OVERSAMPLE
)
);
if
(
CANVAS_mouseable
) {
fprintf
(
gpoutfile
,
"</td></tr></table>\n"
);
}
fprintf
(
gpoutfile
,
"</div>\n\n"
"</body>\n"
"</html>\n"
);
}
fflush
(
gpoutfile
);
}
TERM_PUBLIC
void
CANVAS_reset
()
{
;
}
TERM_PUBLIC
void
CANVAS_linetype
(
int
linetype
)
{
/* NB: These values are manipulated as numbers; */
/* it does not work to give only the color name */
static
const
char
*
pen_type
[
17
]
=
{
" rgb(255,255,255)"
,
/* should be background */
" rgb(000,000,000)"
,
/* black */
" rgb(160,160,160)"
,
/* grey */
" rgb(255,000,000)"
,
/* red */
" rgb(000,171,000)"
,
/* green */
" rgb(000,000,225)"
,
/* blue */
" rgb(190,000,190)"
,
/* purple */
" rgb(000,255,255)"
,
/* cyan */
" rgb(021,117,069)"
,
/* pine green*/
" rgb(000,000,148)"
,
/* navy */
" rgb(255,153,000)"
,
/* orange */
" rgb(000,153,161)"
,
/* green blue*/
" rgb(214,214,069)"
,
/* olive*/
" rgb(163,145,255)"
,
/* cornflower*/
" rgb(255,204,000)"
,
/* gold*/
" rgb(214,000,120)"
,
/* mulberry*/
" rgb(171,214,000)"
,
/* green yellow*/
};
/* FIXME if (linetype == canvas_line_type) return; */
canvas_line_type
=
linetype
;
CANVAS_finish
();
if
(
linetype
>=
14
)
linetype
%=
14
;
if
(
linetype
<=
LT_NODRAW
)
/* LT_NODRAW, LT_BACKGROUND, LT_UNDEFINED */
linetype
=
-3
;
if
(
linetype
==
-3
&&
*
CANVAS_background
)
strcpy
(
canvas_state
.
color
,
CANVAS_background
);
else
strcpy
(
canvas_state
.
color
,
pen_type
[
linetype
+
3
]);
if
(
strcmp
(
canvas_state
.
color
,
canvas_state
.
previous_color
)) {
fprintf
(
gpoutfile
,
"ctx.strokeStyle = \"%s\";\n"
,
canvas_state
.
color
);
strcpy
(
canvas_state
.
previous_color
,
canvas_state
.
color
);
}
if
(
canvas_line_type
==
LT_NODRAW
)
CANVAS_dashtype
(
DASHTYPE_NODRAW
,
NULL
);
}
TERM_PUBLIC
void
CANVAS_dashtype
(
int
type
,
t_dashtype
*
custom_dash_type
)
{
if
(
canvas_line_type
==
LT_NODRAW
)
type
=
DASHTYPE_NODRAW
;
if
(
canvas_line_type
==
LT_AXIS
)
type
=
DASHTYPE_AXIS
;
switch
(
type
) {
case
DASHTYPE_AXIS
:
fprintf
(
gpoutfile
,
"DT(gnuplot.dashpattern3);\n"
);
break
;
case
DASHTYPE_SOLID
:
if
(
canvas_dash_type
!=
DASHTYPE_SOLID
)
fprintf
(
gpoutfile
,
"DT(gnuplot.solid);\n"
);
break
;
case
DASHTYPE_NODRAW
:
fprintf
(
gpoutfile
,
"DT([0.0,1.0]);\n"
);
break
;
default
:
type
=
type
%
5
;
if
(
canvas_dash_type
!=
type
)
fprintf
(
gpoutfile
,
"DT(gnuplot.dashpattern%1d);\n"
,
type
+
1
);
break
;
case
DASHTYPE_CUSTOM
:
if
(
custom_dash_type
) {
double
length
=
0
;
double
cumulative
=
0
;
int
i
;
for
(
i
=
0
;
i
<
DASHPATTERN_LENGTH
&&
custom_dash_type
->
pattern
[
i
]
>
0
;
i
++
)
length
+=
custom_dash_type
->
pattern
[
i
];
fprintf
(
gpoutfile
,
"DT(["
);
for
(
i
=
0
;
i
<
DASHPATTERN_LENGTH
&&
custom_dash_type
->
pattern
[
i
]
>
0
;
i
++
) {
cumulative
+=
custom_dash_type
->
pattern
[
i
];
fprintf
(
gpoutfile
,
" %4.2f,"
,
cumulative
/
length
);
}
fprintf
(
gpoutfile
,
" 0]);\n"
);
}
break
;
}
canvas_dash_type
=
type
;
}
TERM_PUBLIC
void
CANVAS_move
(
unsigned
int
arg_x
,
unsigned
int
arg_y
)
{
if
(
canvas_in_a_path
&&
(
canvas_x
==
arg_x
)
&&
(
canvas_y
==
arg_y
)) {
return
;
}
CANVAS_start
();
fprintf
(
gpoutfile
,
"M(%u,%u);\n"
,
arg_x
,
canvas_ymax
-
arg_y
);
canvas_x
=
arg_x
;
canvas_y
=
arg_y
;
}
TERM_PUBLIC
void
CANVAS_vector
(
unsigned
int
arg_x
,
unsigned
int
arg_y
)
{
if
((
canvas_x
==
arg_x
)
&&
(
canvas_y
==
arg_y
))
return
;
if
(!
canvas_in_a_path
) {
/* Force a new path */
CANVAS_move
(
canvas_x
,
canvas_y
);
}
fprintf
(
gpoutfile
,
"L(%u,%u);\n"
,
arg_x
,
canvas_ymax
-
arg_y
);
canvas_x
=
arg_x
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL