Rev 11005 | Rev 11017 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8299 | schaersvoo | 1 | /*27/7/2013 version 0.01 |
7614 | schaersvoo | 2 | "Inspired" by FLY program: http://martin.gleeson.com/fly |
3 | ********************************************************************************* |
||
4 | * J.M. Evers 7/2013 * |
||
5 | * This is all just amateur scriblings... So no copyrights. * |
||
6 | * This source code file, and compiled objects derived from it, * |
||
7 | * can be used and distributed without restriction, including for commercial use * |
||
8 | * No warrenty whatsoever * |
||
9 | ********************************************************************************* |
||
10 | */ |
||
7848 | bpr | 11 | #include "canvasdraw.h" |
7614 | schaersvoo | 12 | |
13 | /****************************************************************************** |
||
14 | ** Internal Functions |
||
15 | ******************************************************************************/ |
||
16 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
17 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
18 | void add_javascript_functions(int js_functions[], int canvas_root_id); |
||
19 | void reset();/* reset some global variables like "use_filled" , "use_dashed" */ |
||
20 | int get_token(FILE *infile); /* read next char until EOL*/ |
||
8225 | bpr | 21 | /* |
7614 | schaersvoo | 22 | int x2px(double x); |
23 | int y2px(double y); |
||
8225 | bpr | 24 | */ |
7614 | schaersvoo | 25 | double px2x(int x); |
26 | double px2y(int y); |
||
7906 | schaersvoo | 27 | double get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */ |
7614 | schaersvoo | 28 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
29 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
||
7906 | schaersvoo | 30 | char *get_string(FILE *infile,int last); /* get the string at the end of a command */ |
7614 | schaersvoo | 31 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
32 | char *convert_hex2rgb(char *hexcolor); |
||
8257 | schaersvoo | 33 | void add_read_canvas(int canvas_root_id,int reply_format,int reply_precision); |
7614 | schaersvoo | 34 | void make_js_include(int canvas_root_id); |
35 | void check_string_length(int length);/* checks if the length of string argument of command is correct */ |
||
8224 | bpr | 36 | FILE *js_include_file; |
7614 | schaersvoo | 37 | FILE *get_file(int *line_number, char **filename); |
38 | FILE *infile; /* will be stdin */ |
||
39 | /****************************************************************************** |
||
40 | ** global |
||
41 | ******************************************************************************/ |
||
42 | int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */ |
||
43 | int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */ |
||
44 | /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */ |
||
45 | int xsize = 320; |
||
46 | int ysize = 320; |
||
47 | double xmin = 0.0; |
||
48 | double xmax = 320.0; |
||
49 | double ymin = 0.0; |
||
50 | double ymax = 320.0; |
||
51 | double tmax = 2; |
||
52 | double tmin = -2; |
||
53 | /* flag to indicate parsing of line status */ |
||
8224 | bpr | 54 | int done = FALSE; |
7614 | schaersvoo | 55 | int type; /* eg command number */ |
56 | int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/ |
||
8097 | schaersvoo | 57 | int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */ |
7785 | schaersvoo | 58 | int use_affine = FALSE; |
7614 | schaersvoo | 59 | int use_rotate = FALSE; |
60 | int use_filled = FALSE; |
||
61 | int use_dashed = FALSE; /* dashing not natively supported in firefox , for now... */ |
||
8097 | schaersvoo | 62 | |
7614 | schaersvoo | 63 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
9329 | schaersvoo | 64 | char *getfile_cmd = ""; |
7614 | schaersvoo | 65 | /****************************************************************************** |
66 | ** Main Program |
||
67 | ******************************************************************************/ |
||
68 | int main(int argc, char *argv[]){ |
||
69 | /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */ |
||
70 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec; |
||
71 | infile = stdin;/* read flyscript via stdin */ |
||
72 | int i,c; |
||
73 | double double_data[MAX_INT+1]; |
||
74 | int int_data[MAX_INT+1]; |
||
75 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
||
76 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
||
77 | int use_axis = FALSE; |
||
78 | int use_axis_numbering = FALSE; |
||
7797 | schaersvoo | 79 | int use_pan_and_zoom = FALSE; |
7956 | schaersvoo | 80 | int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */ |
7858 | schaersvoo | 81 | int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */ |
82 | int use_js_plot = FALSE; /* if true , let js-engine plot the curve */ |
||
11006 | schaersvoo | 83 | int jsplot_cnt = 0; /* keepint track on the curve identity */ |
8448 | schaersvoo | 84 | int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */ |
7614 | schaersvoo | 85 | int line_width = 1; |
86 | int decimals = 2; |
||
8365 | schaersvoo | 87 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */ |
88 | int use_userdraw = FALSE; /* flag to indicate user interaction */ |
||
7614 | schaersvoo | 89 | int drag_type = -1;/* 0,1,2 : xy,x,y */ |
9329 | schaersvoo | 90 | int use_tooltip = -1; /* 1= tooltip 2= popup window*/ |
7614 | schaersvoo | 91 | char *tooltip_text = "Click here"; |
92 | char *temp = ""; /* */ |
||
93 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
94 | char *stroke_color = "255,0,0"; |
||
95 | char *fill_color = "0,255,0"; |
||
96 | char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
||
97 | char *font_color = "#00000"; |
||
98 | char *draw_type = "points"; |
||
99 | char *fly_font = "normal"; |
||
8815 | schaersvoo | 100 | char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;"; |
7614 | schaersvoo | 101 | char *flytext = ""; |
7785 | schaersvoo | 102 | char *affine_matrix = "[1,0,0,1,0,0]"; |
8297 | schaersvoo | 103 | char *function_label = "f(x)="; |
11006 | schaersvoo | 104 | int canvas_type = DRAG_CANVAS; /* to use a specific canvas for filling etc */ |
7614 | schaersvoo | 105 | int pixelsize = 1; |
106 | int reply_format = 0; |
||
107 | int input_cnt = 0; |
||
108 | int ext_img_cnt = 0; |
||
8071 | schaersvoo | 109 | int slider_cnt = 0; |
10953 | bpr | 110 | int font_size = 12;/* this may lead to problems when using something like "fontfamily Italic 24px Ariel" the "font_size" value is not substituted into fontfamily !! */ |
8388 | schaersvoo | 111 | int fly_font_size = 12; /*fly_font_size is relative to this... */ |
8365 | schaersvoo | 112 | int dashtype[2] = { 4 , 4 }; /* just line_px and space_px : may have more arguments...if needed in future*/ |
7614 | schaersvoo | 113 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */ |
114 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
||
8365 | schaersvoo | 115 | int arrow_head = 8; /* size in px needed for arrow based userdraw: "userdraw arrow,color" */ |
7833 | schaersvoo | 116 | int crosshair_size = 5; /* size in px*/ |
8365 | schaersvoo | 117 | int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required */ |
118 | int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange :just to flag an error message */ |
||
8448 | schaersvoo | 119 | int click_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[click_cnt]=1 when clicked ; otherwise reply[click_cnt]=0 ; click_cnt is only increased when another object is set again */ |
7614 | schaersvoo | 120 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
121 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
7989 | schaersvoo | 122 | int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/ |
9433 | schaersvoo | 123 | int boxplot_cnt = 0; |
7956 | schaersvoo | 124 | int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc */ |
8074 | schaersvoo | 125 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
7614 | schaersvoo | 126 | double angle = 0.0; |
10953 | bpr | 127 | char *rotation_center = "null"; |
8365 | schaersvoo | 128 | int clickfillmarge = 20; /* in pixels : if the 'remove click' is within this marge, the filling is removed */ |
129 | int animation_type = 9; /* REMOVED == object type curve in drag library */ |
||
7823 | schaersvoo | 130 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
10953 | bpr | 131 | int use_slider_display = 0; /* in case of a slider, should we display its value ?*/ |
8365 | schaersvoo | 132 | size_t string_length = 0; /* measure the size of the user input fly-string */ |
133 | double stroke_opacity = 0.8; /* use some opacity as default */ |
||
134 | double fill_opacity = 0.8;/* use some opacity as default */ |
||
7614 | schaersvoo | 135 | char *URL = "http://localhost/images"; |
9213 | schaersvoo | 136 | char *slider_function_x = "x"; |
137 | char *slider_function_y = "y"; |
||
7614 | schaersvoo | 138 | memset(buffer,'\0',MAX_BUFFER); |
139 | void *tmp_buffer = ""; |
||
8224 | bpr | 140 | |
7614 | schaersvoo | 141 | /* default writing a unzipped js-include file into wims getfile directory */ |
142 | char *w_wims_session = getenv("w_wims_session"); |
||
8224 | bpr | 143 | if( w_wims_session == NULL || *w_wims_session == 0 ){ |
7614 | schaersvoo | 144 | canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims."); |
145 | } |
||
146 | int L0=strlen(w_wims_session) + 21; |
||
147 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
148 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
149 | mode_t process_mask = umask(0); /* check if file exists */ |
||
150 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
151 | if( result == 0 || errno == EEXIST ){ |
||
152 | umask(process_mask); /* be sure to set correct permission */ |
||
8224 | bpr | 153 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 154 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
9329 | schaersvoo | 155 | getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
8224 | bpr | 156 | snprintf(getfile_cmd,L1,"wims.cgi?session=%s&cmd=getfile&special_parm=%d.js",w_session,canvas_root_id);/* extension ".gz" is MANDATORY for webserver */ |
7614 | schaersvoo | 157 | /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
158 | /* now write file into getfile dir*/ |
||
159 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */ |
||
160 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
||
161 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
162 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
163 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
164 | /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */ |
||
165 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );} |
||
166 | |||
167 | /* ----------------------------------------------------- */ |
||
168 | /* while more lines to process */ |
||
169 | |||
170 | while(!finished){ |
||
9329 | schaersvoo | 171 | if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
7614 | schaersvoo | 172 | type = get_token(infile); |
173 | done = FALSE; |
||
174 | /* |
||
9385 | schaersvoo | 175 | @ canvasdraw |
176 | @ will try use the same syntax as flydraw or svgdraw to paint a html5 bitmap image<br />by generating a tailor-made javascript include file: providing only the js-functionality needed to perform the job.<br />thus ensuring a minimal strain on the client browser <br />(unlike some popular 'canvas-do-it-all' libraries, who have proven to be not suitable for low-end computers found in schools...) |
||
9386 | schaersvoo | 177 | @ general syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">'opacity [0-255],[0,255]'</a></il><li>line width of any object can be controlled by command <a href="#linewidth">'linewidth int'</a></li><li>any may be dashed by using keyword <a href="#dashed">'dashed'</a> before the object command.<br />the dashing type can be controled by command <a href="#dashtype">'dashtype int,int'</a></li><li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword <a href="#filled">'filled'</a> before the object command.<br />The fill colour of 'non_userdraw' objects will be the stroke colour...(flydraw harmonization 19/10/2013)</li><li>all draggable objects may have a <a href="#slider">slider</a> for translation / rotation; several objects may be translated / rotated by a single slider</li> <li> a draggable object can be set draggable by a preceding command <a href="#drag">'drag x/y/xy'</a><br />The translation can be read by javascript:read_dragdrop();The replyformat is : object_number : x-orig : y-orig : x-drag : y-drag<br />The x-orig/y-orig will be returned in maximum precision (javascript float)...<br />the x-drag/y-drag will be returned in defined 'precision' number of decimals<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on <a href="#zoom">zoom</a> and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword <a href="#onclick">'onclick'</a><br />not all flydraw objects can be set clickable</li><li><b>remarks using a ';' as command separator</b><br />commands with only numeric or colour arguments may be using a ';' as command separator (instead of a new line)<br />commands with a string argument may not use a ';' as command separator !<br />these exceptions are not really straight forward... so keep this in mind.</li><li>almost every <a href="#userdraw">"userdraw object,color"</a> or <a href="#multidraw">"multidraw"</a> command 'family' may be combined with keywords <a href="#snaptogrid">"snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..." </li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..." </li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntaxrule:<li><em>single_object</em> x1,y1,...,color</li><li><em>multi_object</em> color,x1,y1,...</li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#inputstyle">'inputstyle some_css'</a><br/>the fontsize used for labeling these elements can be controlled by command <a href="fontsize">'fontsize int'</a> <br />command 'fontfamily' is <b>not</b> active for these elements </li></ul> |
10953 | bpr | 178 | @ If needed multiple interactive scripts may be used in a single webpage.<br />A function 'read_canvas()' and / or 'read_dragdrop()' can read all interactive userdata from these images.<br />The global array 'canvas_scripts' will contain all unique random "canvas_root_id" of the included scripts.<br />The included local javascript "read" functions "read_canvas%d()" and "read_dragdrop%d()" will have this "%d = canvas_root_id"<br />e.g. canvas_scripts[0] will be the random id of the first script in the page and will thus provide a function<br />fun = eval("read_canvas"+canvas_scripts[0]) to read user based drawings / inputfield in this first image.<br />The read_dragdrop is analogue.<br />If the default reply formatting is not suitable, use command <a href='#replyformat'>'replyformat'</a> to format the replies for an individual canvas script,<br />To read all user interactions from all included canvas scripts , use something like:<br /><em>function read_all_canvas_images(){<br /> var script_len = canvas_scripts.length;<br /> var draw_reply = "";<br /> var found_result = false;<br /> for(var p = 0 ; p < script_len ; p++){<br /> var fun = eval("read_canvas"+canvas_scripts[p]);<br /> if( typeof fun === 'function'){<br /> var result = fun();<br /> if( result && result.length != 0){<br /> if(script_len == 1 ){ return result;};<br /> found_result = true;<br /> draw_reply = draw_reply + result + "\\n";<br /> };<br /> };<br /> };<br /> if( found_result ){return draw_reply;}else{return null;};<br />};</em> |
11006 | schaersvoo | 179 | @ you can check the javascript reply format in the wims tool <a href="http://localhost/wims/wims.cgi?lang=en&module=tool/directexec">direct exec</a> |
10962 | schaersvoo | 180 | @ for usage within OEF (without anstype "draw"), something like this (a popup function plotter) will work:<br /><small>\\text{popup_grapher=wims(exec canvasdraw <br />popup<br />size 400,400<br />xrange -10,10<br />yrange -10,10<br />axis<br />axisnumbering<br />opacity 100,100<br />grid 2,2,grey,2,2,6,black<br />snaptogrid<br />linewidth 2<br />jsplot red,5*sin(1/x)<br />strokecolor green<br />functionlabel f(x)=<br />userinput function<br />mouse blue,22<br />)<br />}<br />\\statement{<br />\\popup_grapher<br />}</small> |
9427 | schaersvoo | 181 | @ be aware that older browsers will probably not work correctly<br />no effort has been undertaken to add glue code for older browsers !! <br />in any case it's not wise to use older browsers...not just for canvasdraw |
10827 | schaersvoo | 182 | @ if you find flaws, errors or other incompatibilities -not those mentioned in this document- send <a href='mailto:jm.evers-at-schaersvoorde.nl'>me</a> an email with screenshots and the generated javascript include file. |
11002 | schaersvoo | 183 | @ there is limited support for touch devices : touchstart,touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#protractor">protractor</a> and <a href="#ruler">ruler</a><br />only single finger gestures are supported (for now)<br />for more accurate user-interaction with canvasdraw on touch devices: use the command family <a href="userinput_xy">userinput</a> |
7614 | schaersvoo | 184 | */ |
185 | switch(type){ |
||
186 | case END: |
||
187 | finished = 1; |
||
188 | done = TRUE; |
||
189 | break; |
||
190 | case 0: |
||
191 | sync_input(infile); |
||
192 | break; |
||
193 | case COMMENT: |
||
194 | sync_input(infile); |
||
195 | break; |
||
196 | case EMPTY: |
||
197 | sync_input(infile); |
||
198 | break; |
||
199 | case SIZE: |
||
200 | /* |
||
9385 | schaersvoo | 201 | @ size width,height |
202 | @ set canvas size in pixels |
||
9386 | schaersvoo | 203 | @ mandatory first command (can only be preceded by keyword <a href="#popup">'popup'</a>) |
9385 | schaersvoo | 204 | @ if xrange and/or yrange is not given the range will be set to pixels :<br />xrange 0,xsize yrange 0,ysize<br /><b>note</b>: lower left corner is Origin (0:0) !!! this in contrast to flydraw |
7614 | schaersvoo | 205 | */ |
7983 | schaersvoo | 206 | found_size_command = 1; |
8813 | schaersvoo | 207 | /* using fabs : however "xsize == int" : so "xsize = abs( (int) get_real(infile,0))" would be the idea... */ |
208 | xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
||
209 | ysize = (int)(fabs(round(get_real(infile,1)))); |
||
7614 | schaersvoo | 210 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
211 | xmin = 0;xmax = xsize; |
||
7647 | schaersvoo | 212 | ymin = 0;ymax = ysize; |
7614 | schaersvoo | 213 | |
8224 | bpr | 214 | /* |
7614 | schaersvoo | 215 | The sequence in which stuff is finally printed is important !! |
216 | */ |
||
8784 | schaersvoo | 217 | fprintf(stdout,"\n\ |
218 | <script type=\"text/javascript\">\n\ |
||
219 | /*<![CDATA[*/\n\ |
||
8257 | schaersvoo | 220 | if( typeof wims_status === 'undefined' ){ var wims_status = \"$status\";};\ |
221 | if( typeof use_dragdrop_reply === 'undefined' ){ var use_dragdrop_reply = false;};\ |
||
222 | if( typeof canvas_scripts === 'undefined' ){ var canvas_scripts = new Array();};\ |
||
8784 | schaersvoo | 223 | canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\ |
9331 | schaersvoo | 224 | ",canvas_root_id); |
9329 | schaersvoo | 225 | |
11004 | schaersvoo | 226 | /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */ |
9329 | schaersvoo | 227 | if( use_tooltip != 2){ |
228 | fprintf(stdout,"<!-- canvasdraw div -->\n\ |
||
11006 | schaersvoo | 229 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" oncontextmenu=\"return false;\"></div>\n\ |
9331 | schaersvoo | 230 | <!-- tooltip and input placeholder -->\n\ |
11004 | schaersvoo | 231 | <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
9329 | schaersvoo | 232 | <!-- include actual object code via include file -->\n\ |
9331 | schaersvoo | 233 | <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
234 | } |
||
235 | else |
||
236 | { |
||
10953 | bpr | 237 | /* |
238 | set canvas_div invisible and do not include placeholder in main html page : |
||
239 | the js-include will also be in a popup window...to be shown when wims $status = done |
||
9331 | schaersvoo | 240 | */ |
241 | fprintf(stdout,"<!-- canvasdraw div invisible -->\n\ |
||
9868 | schaersvoo | 242 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\ |
9332 | schaersvoo | 243 | <div id=\"tooltip_placeholder_div%d\" style=\"display:none;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
9331 | schaersvoo | 244 | <!-- include actual object code via include file -->\n\ |
9332 | schaersvoo | 245 | <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
9329 | schaersvoo | 246 | } |
9331 | schaersvoo | 247 | |
9329 | schaersvoo | 248 | /* these must be global...it's all really very poor javascript :( */ |
8146 | schaersvoo | 249 | fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\ |
8108 | schaersvoo | 250 | \"use strict\";\n\ |
8146 | schaersvoo | 251 | <!-- these variables and functions must be global -->\n\ |
8257 | schaersvoo | 252 | var read_dragdrop%d;\ |
253 | var read_canvas%d;\ |
||
8130 | schaersvoo | 254 | var set_clock;\ |
8349 | schaersvoo | 255 | var clear_draw_area%d;\ |
9213 | schaersvoo | 256 | var update_draw_area%d;\ |
9465 | schaersvoo | 257 | var draw_boxplot;\ |
9406 | schaersvoo | 258 | var redraw_all%d;\ |
9213 | schaersvoo | 259 | var userdraw_primitive;\n\ |
8257 | schaersvoo | 260 | var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\ |
8146 | schaersvoo | 261 | var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\ |
7729 | schaersvoo | 262 | var xsize = %d;\ |
263 | var ysize = %d;\ |
||
7797 | schaersvoo | 264 | var precision = 100;\ |
7729 | schaersvoo | 265 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
8105 | schaersvoo | 266 | var create_canvas%d = function(canvas_type,size_x,size_y){var cnv;if(document.getElementById(\"wims_canvas%d\"+canvas_type)){ cnv = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{try{ cnv = document.createElement(\"canvas\"); }catch(e){alert(\"Your browser does not support HTML5 CANVAS:GET FIREFOX !\");return;};canvas_div.appendChild(cnv);};cnv.width = size_x;cnv.height = size_y;cnv.style.top = 0;cnv.style.left = 0;cnv.style.position = \"absolute\";cnv.id = \"wims_canvas%d\"+canvas_type;return cnv;};\ |
7729 | schaersvoo | 267 | function findPosX(i){ var obj = i;var curleft = 0;if(obj.offsetParent){while(1){curleft += obj.offsetLeft;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.x){curleft += obj.x;};};return curleft;};function findPosY(i){var obj = i;var curtop = 0;if(obj.offsetParent){while(1){curtop += obj.offsetTop;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.y){curtop += obj.y;};};return curtop;};\ |
7990 | schaersvoo | 268 | function x2px(x){if(use_xlogscale == 0 ){return parseFloat(x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin));}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_in = Math.log(x)/Math.log(xlogbase);return x_in*xsize/(x_max - x_min) - xsize*x_min/(x_max - x_min);};};\ |
269 | function px2x(px){if(use_xlogscale == 0 ){return parseFloat(px*(xmax - xmin)/xsize + xmin);}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_out = x_min +px*(x_max - x_min)/(xsize);return Math.pow(xlogbase,x_out);};};\ |
||
270 | function px2y(py){if(use_ylogscale == 0 ){return parseFloat(ymax - py*(ymax - ymin)/ysize);}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_out = y_max +py*(y_min - y_max)/(ysize);return Math.pow(ylogbase,y_out);};};\ |
||
271 | function y2px(y){if(use_ylogscale == 0){return parseFloat(-1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin));}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_in = Math.log(y)/Math.log(ylogbase);return (y_max - y_in)*ysize/(y_max - y_min);};};\ |
||
8071 | schaersvoo | 272 | function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\ |
273 | function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\ |
||
8389 | schaersvoo | 274 | function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\ |
7729 | schaersvoo | 275 | function distance_to_line (r,q,x,y){var c = (y) - (-1/r)*(x);var xs = r*(c - q)/(r*r+1);var ys = (r)*(xs)+(q);return parseInt(Math.sqrt( (xs-x)*(xs-x) + (ys-y)*(ys-y) ));};\ |
8105 | schaersvoo | 276 | function move(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = obj.x[p] + dx;obj.y[p] = obj.y[p] + dy;};return obj;};\ |
277 | function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = x2px(obj.xorg[p] + dx);obj.y[p] = y2px(obj.yorg[p] + dy);};return obj;};\ |
||
11002 | schaersvoo | 278 | var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));\ |
7881 | schaersvoo | 279 | var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\ |
8379 | schaersvoo | 280 | var use_snap_to_points = 0;\ |
7881 | schaersvoo | 281 | function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\ |
8379 | schaersvoo | 282 | function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n\ |
7735 | schaersvoo | 283 | var xlogbase = 10;\ |
284 | var ylogbase = 10;\ |
||
7729 | schaersvoo | 285 | var use_xlogscale = 0;\ |
286 | var use_ylogscale = 0;\ |
||
9341 | schaersvoo | 287 | var x_strings = null;var x_strings_up = null;\ |
7729 | schaersvoo | 288 | var y_strings = null;\ |
289 | var use_pan_and_zoom = 0;\ |
||
7858 | schaersvoo | 290 | var use_jsmath = 0;\ |
7729 | schaersvoo | 291 | var xstart = 0;\ |
7996 | schaersvoo | 292 | var ystart = 0;\ |
293 | var unit_x=\" \";\ |
||
8448 | schaersvoo | 294 | var unit_y=\" \";\ |
9406 | schaersvoo | 295 | var external_canvas = create_canvas%d(%d,xsize,ysize);\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,EXTERNAL_IMAGE_CANVAS); |
7614 | schaersvoo | 296 | /* default add the drag code : nearly always used ...*/ |
8257 | schaersvoo | 297 | add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id); |
298 | |||
7614 | schaersvoo | 299 | break; |
8386 | schaersvoo | 300 | |
7614 | schaersvoo | 301 | case XRANGE: |
302 | /* |
||
303 | @ xrange xmin,xmax |
||
9386 | schaersvoo | 304 | @ alternative : rangex |
8224 | bpr | 305 | @ if not given: 0,xsize (eg in pixels) |
7614 | schaersvoo | 306 | */ |
307 | for(i = 0 ; i<2; i++){ |
||
308 | switch(i){ |
||
309 | case 0: xmin = get_real(infile,0);break; |
||
310 | case 1: xmax = get_real(infile,1);break; |
||
311 | default: break; |
||
312 | } |
||
313 | } |
||
314 | if(xmin >= xmax){canvas_error(" xrange is not OK : xmin < xmax !\n");} |
||
8448 | schaersvoo | 315 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax); |
7983 | schaersvoo | 316 | found_size_command++; |
7614 | schaersvoo | 317 | break; |
8386 | schaersvoo | 318 | |
7614 | schaersvoo | 319 | case YRANGE: |
320 | /* |
||
321 | @ yrange ymin,ymax |
||
9386 | schaersvoo | 322 | @ alternative : rangey |
7614 | schaersvoo | 323 | @ if not given 0,ysize (eg in pixels) |
324 | */ |
||
325 | for(i = 0 ; i<2; i++){ |
||
326 | switch(i){ |
||
327 | case 0: ymin = get_real(infile,0);break; |
||
328 | case 1: ymax = get_real(infile,1);break; |
||
329 | default: break; |
||
330 | } |
||
331 | } |
||
332 | if(ymin >= ymax){canvas_error(" yrange is not OK : ymin < ymax !\n");} |
||
8448 | schaersvoo | 333 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax); |
7983 | schaersvoo | 334 | found_size_command++; |
7614 | schaersvoo | 335 | break; |
8386 | schaersvoo | 336 | |
7614 | schaersvoo | 337 | case TRANGE: |
338 | /* |
||
339 | @ trange tmin,tmax |
||
9386 | schaersvoo | 340 | @ alternative : ranget |
7614 | schaersvoo | 341 | @ default -2,2 |
342 | */ |
||
343 | use_parametric = TRUE; |
||
344 | for(i = 0 ; i<2; i++){ |
||
345 | switch(i){ |
||
346 | case 0: tmin = get_real(infile,0);break; |
||
347 | case 1: tmax = get_real(infile,1);break; |
||
348 | default: break; |
||
349 | } |
||
350 | } |
||
351 | if(tmin >= tmax ){canvas_error(" trange is not OK : tmin < tmax!\n");} |
||
352 | break; |
||
8386 | schaersvoo | 353 | |
7614 | schaersvoo | 354 | case LINEWIDTH: |
355 | /* |
||
356 | @ linewidth int |
||
357 | @ default 1 |
||
358 | */ |
||
359 | line_width = (int) (get_real(infile,1)); |
||
360 | break; |
||
8386 | schaersvoo | 361 | |
7614 | schaersvoo | 362 | case CROSSHAIRSIZE: |
363 | /* |
||
364 | @ crosshairsize int |
||
8347 | schaersvoo | 365 | @ default 8 (px) |
7614 | schaersvoo | 366 | */ |
367 | crosshair_size = (int) (get_real(infile,1)); |
||
368 | break; |
||
8386 | schaersvoo | 369 | |
7614 | schaersvoo | 370 | case CROSSHAIR: |
371 | /* |
||
372 | @ crosshair x,y,color |
||
373 | @ draw a single crosshair point at (x;y) in color 'color' |
||
7956 | schaersvoo | 374 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
9406 | schaersvoo | 375 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 376 | */ |
377 | for(i=0;i<3;i++){ |
||
378 | switch(i){ |
||
379 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
380 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
381 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
382 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 383 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 384 | if(onclick > 0){click_cnt++;} |
385 | /* click_cnt++ */ |
||
386 | reset(); |
||
7614 | schaersvoo | 387 | break; |
388 | default:break; |
||
389 | } |
||
390 | } |
||
391 | break; |
||
8386 | schaersvoo | 392 | |
7614 | schaersvoo | 393 | case CROSSHAIRS: |
394 | /* |
||
395 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
396 | @ draw multiple crosshair points at given coordinates in color 'color' |
||
7956 | schaersvoo | 397 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
9406 | schaersvoo | 398 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
7614 | schaersvoo | 399 | */ |
400 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
401 | fill_color = stroke_color; |
||
402 | i=0; |
||
403 | while( ! done ){ /* get next item until EOL*/ |
||
404 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
405 | if(i%2 == 0 ){ |
||
406 | double_data[i] = get_real(infile,0); /* x */ |
||
407 | } |
||
408 | else |
||
409 | { |
||
410 | double_data[i] = get_real(infile,1); /* y */ |
||
411 | } |
||
412 | i++; |
||
413 | } |
||
414 | decimals = find_number_of_digits(precision); |
||
415 | for(c=0 ; c < i-1 ; c = c+2){ |
||
9907 | schaersvoo | 416 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 417 | if(onclick > 0){click_cnt++;} |
418 | /* click_cnt++; */ |
||
7614 | schaersvoo | 419 | } |
420 | reset(); |
||
421 | break; |
||
8386 | schaersvoo | 422 | |
7614 | schaersvoo | 423 | case POINT: |
424 | /* |
||
425 | @ point x,y,color |
||
426 | @ draw a single point at (x;y) in color 'color' |
||
7956 | schaersvoo | 427 | @ use command 'linewidth int' to adust size |
9406 | schaersvoo | 428 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8224 | bpr | 429 | @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming) |
10953 | bpr | 430 | @ attention: in case of command <a href="#rotate">'rotate angle'</a> a point has rotation center (0:0) in x/y-range |
7614 | schaersvoo | 431 | */ |
432 | for(i=0;i<3;i++){ |
||
433 | switch(i){ |
||
434 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
435 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
436 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
437 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 438 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 439 | /* click_cnt++; */ |
440 | if(onclick > 0){click_cnt++;} |
||
441 | break; |
||
7614 | schaersvoo | 442 | default: break; |
443 | } |
||
444 | } |
||
445 | reset(); |
||
446 | break; |
||
8386 | schaersvoo | 447 | |
7614 | schaersvoo | 448 | case POINTS: |
449 | /* |
||
7634 | schaersvoo | 450 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
7614 | schaersvoo | 451 | @ draw multiple points at given coordinates in color 'color' |
7956 | schaersvoo | 452 | @ use command 'linewidth int' to adust size |
9406 | schaersvoo | 453 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
10953 | bpr | 454 | @ attention: in case of command <a href="#rotate">'rotate angle'</a> the points have rotation center (0:0) in x/y-range |
7614 | schaersvoo | 455 | */ |
456 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
457 | fill_color = stroke_color; |
||
458 | i=0; |
||
459 | while( ! done ){ /* get next item until EOL*/ |
||
460 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
461 | if(i%2 == 0 ){ |
||
462 | double_data[i] = get_real(infile,0); /* x */ |
||
463 | } |
||
464 | else |
||
465 | { |
||
466 | double_data[i] = get_real(infile,1); /* y */ |
||
467 | } |
||
468 | i++; |
||
469 | } |
||
8224 | bpr | 470 | decimals = find_number_of_digits(precision); |
7614 | schaersvoo | 471 | for(c = 0 ; c < i-1 ; c = c+2){ |
9907 | schaersvoo | 472 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 473 | /* click_cnt++; */ |
474 | if(onclick > 0){click_cnt++;} |
||
7614 | schaersvoo | 475 | } |
476 | reset(); |
||
477 | break; |
||
9427 | schaersvoo | 478 | case YERRORBARS: |
479 | /* |
||
480 | @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
||
9433 | schaersvoo | 481 | @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color' |
10953 | bpr | 482 | @ the errors E1 and E2 values are in yrange. |
9427 | schaersvoo | 483 | @ use command 'linewidth int' to adust size |
484 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
||
485 | */ |
||
486 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
487 | fill_color = stroke_color; |
||
488 | i=0; |
||
489 | while( ! done ){ /* get next item until EOL*/ |
||
490 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
491 | if(i%2 == 0 ){ |
||
492 | double_data[i] = get_real(infile,0); /* x */ |
||
493 | } |
||
494 | else |
||
495 | { |
||
496 | double_data[i] = get_real(infile,1); /* y */ |
||
497 | } |
||
498 | i++; |
||
499 | } |
||
500 | for(c = 2 ; c < i-1 ; c = c+2){ |
||
9908 | schaersvoo | 501 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n", |
9907 | schaersvoo | 502 | click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
9427 | schaersvoo | 503 | /* click_cnt++; */ |
504 | if(onclick > 0){click_cnt++;} |
||
505 | } |
||
506 | decimals = find_number_of_digits(precision); |
||
507 | reset(); |
||
508 | break; |
||
509 | case XERRORBARS: |
||
510 | /* |
||
511 | @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
||
9433 | schaersvoo | 512 | @ draw multiple points with x-errorbars E1 (error value left from point) and E2 (error value right from point) at given coordinates in color 'color' |
10953 | bpr | 513 | @ the errors E1 and E2 values are in xrange. |
9427 | schaersvoo | 514 | @ use command 'linewidth int' to adust size |
515 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
||
516 | */ |
||
517 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
518 | fill_color = stroke_color; |
||
519 | i=0; |
||
520 | while( ! done ){ /* get next item until EOL*/ |
||
521 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
522 | if(i%2 == 0 ){ |
||
523 | double_data[i] = get_real(infile,0); /* x */ |
||
524 | } |
||
525 | else |
||
526 | { |
||
527 | double_data[i] = get_real(infile,1); /* y */ |
||
528 | } |
||
529 | i++; |
||
530 | } |
||
531 | decimals = find_number_of_digits(precision); |
||
532 | for(c = 2 ; c < i-1 ; c = c+2){ |
||
9908 | schaersvoo | 533 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
9427 | schaersvoo | 534 | /* click_cnt++; */ |
535 | if(onclick > 0){click_cnt++;} |
||
536 | } |
||
537 | reset(); |
||
538 | break; |
||
8386 | schaersvoo | 539 | |
540 | case CIRCLE: |
||
8299 | schaersvoo | 541 | /* |
8386 | schaersvoo | 542 | @ circle xc,yc,width (2*r in pixels),color |
9383 | schaersvoo | 543 | @ use command 'fcircle xc,yc,d,color' |
544 | @ alternative: disk for a filled circle |
||
8386 | schaersvoo | 545 | @ use command 'fillcolor color' to set the fillcolor |
9406 | schaersvoo | 546 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8386 | schaersvoo | 547 | @ will shrink / expand on zoom out / zoom in |
8299 | schaersvoo | 548 | */ |
8386 | schaersvoo | 549 | for(i=0;i<4;i++){ |
550 | switch(i){ |
||
551 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
552 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
553 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/ |
||
554 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
||
555 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 556 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8386 | schaersvoo | 557 | if(onclick > 0){click_cnt++;} |
558 | /* click_cnt++;*/ |
||
559 | reset(); |
||
560 | break; |
||
561 | default : break; |
||
562 | } |
||
563 | } |
||
564 | break; |
||
565 | |||
566 | case CIRCLES: |
||
567 | /* |
||
568 | @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n |
||
9383 | schaersvoo | 569 | @ <b>attention</b> r = radius in x-range (!) |
570 | @ use keyword 'filled' or command 'fcircles' to produce solid circles |
||
571 | @ alternative : disks for filled circles |
||
8386 | schaersvoo | 572 | @ use command 'fillcolor color' to set the fillcolor |
9406 | schaersvoo | 573 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (individually) |
8386 | schaersvoo | 574 | @ will shrink / expand on zoom out / zoom in |
575 | */ |
||
8299 | schaersvoo | 576 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
577 | fill_color = stroke_color; |
||
8386 | schaersvoo | 578 | i=1; |
8299 | schaersvoo | 579 | while( ! done ){ /* get next item until EOL*/ |
580 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
8386 | schaersvoo | 581 | switch (i%3){ |
582 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
583 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
584 | case 0:double_data[i-1] = get_real(infile,1);break; /* r */ |
||
8299 | schaersvoo | 585 | } |
586 | i++; |
||
587 | } |
||
588 | decimals = find_number_of_digits(precision); |
||
8386 | schaersvoo | 589 | for(c = 0 ; c < i-1 ; c = c+3){ |
9907 | schaersvoo | 590 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[c+2],double_data[c+2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 591 | if(onclick > 0){click_cnt++;} |
8386 | schaersvoo | 592 | /* click_cnt++; */ |
8299 | schaersvoo | 593 | } |
594 | reset(); |
||
595 | break; |
||
8386 | schaersvoo | 596 | |
7614 | schaersvoo | 597 | case SEGMENT: |
598 | /* |
||
599 | @ segment x1,y1,x2,y2,color |
||
9383 | schaersvoo | 600 | @ alternative : seg |
7614 | schaersvoo | 601 | @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color' |
9406 | schaersvoo | 602 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 603 | */ |
604 | for(i=0;i<5;i++) { |
||
605 | switch(i){ |
||
606 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
||
607 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
608 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
609 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
610 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
611 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 612 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 613 | if(onclick > 0){click_cnt++;} |
614 | /* click_cnt++; */ |
||
615 | reset(); |
||
7614 | schaersvoo | 616 | break; |
617 | default: break; |
||
618 | } |
||
619 | } |
||
620 | break; |
||
8386 | schaersvoo | 621 | |
622 | case SEGMENTS: |
||
623 | /* |
||
624 | @ segments color,x1,y1,x2,y2,...,x_n,y_n |
||
9383 | schaersvoo | 625 | @ alternative : segs |
8386 | schaersvoo | 626 | @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color' |
627 | @ use command 'linewidth int' to adust size |
||
9406 | schaersvoo | 628 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
8386 | schaersvoo | 629 | */ |
630 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
631 | fill_color = stroke_color; |
||
632 | i=0; |
||
633 | while( ! done ){ /* get next item until EOL*/ |
||
634 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
635 | if(i%2 == 0 ){ |
||
636 | double_data[i] = get_real(infile,0); /* x */ |
||
637 | } |
||
638 | else |
||
639 | { |
||
640 | double_data[i] = get_real(infile,1); /* y */ |
||
641 | } |
||
642 | i++; |
||
643 | } |
||
644 | decimals = find_number_of_digits(precision); |
||
645 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
9907 | schaersvoo | 646 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8386 | schaersvoo | 647 | if(onclick > 0){click_cnt++;} |
648 | /* click_cnt++;*/ |
||
649 | } |
||
650 | reset(); |
||
651 | break; |
||
652 | |||
7614 | schaersvoo | 653 | case LINE: |
654 | /* |
||
655 | @ line x1,y1,x2,y2,color |
||
656 | @ draw a line through points (x1:y1)--(x2:y2) in color 'color' |
||
657 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
9406 | schaersvoo | 658 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 659 | */ |
660 | for(i=0;i<5;i++){ |
||
661 | switch(i){ |
||
662 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
663 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
664 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
665 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
666 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
667 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
668 | double_data[1] = xmin; |
||
669 | double_data[3] = ymax; |
||
670 | double_data[0] = double_data[10]; |
||
671 | double_data[2] = double_data[10]; |
||
672 | } |
||
673 | else |
||
674 | { |
||
675 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
676 | double_data[1] = double_data[11]; |
||
677 | double_data[3] = double_data[11]; |
||
678 | double_data[0] = ymin; |
||
679 | double_data[2] = xmax; |
||
680 | } |
||
681 | else |
||
682 | { |
||
683 | /* m */ |
||
684 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
685 | /* q */ |
||
686 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
8224 | bpr | 687 | |
7614 | schaersvoo | 688 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
8224 | bpr | 689 | |
7614 | schaersvoo | 690 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
691 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
692 | double_data[0] = xmin; |
||
693 | double_data[2] = xmax; |
||
694 | } |
||
695 | } |
||
696 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 697 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 698 | if(onclick > 0){click_cnt++;} |
699 | /* click_cnt++;*/ |
||
700 | reset(); |
||
7614 | schaersvoo | 701 | break; |
702 | } |
||
703 | } |
||
704 | break; |
||
8386 | schaersvoo | 705 | |
8351 | schaersvoo | 706 | case LINES: |
707 | /* |
||
708 | @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n |
||
709 | @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color' |
||
710 | @ or use multiple commands 'curve color,formula' or "jscurve color,formule" to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
9406 | schaersvoo | 711 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
10975 | schaersvoo | 712 | @ <b>attention</b>: the flydraw command "lines" is equivalent to canvasdraw command <a href="#polyline">"polyline"</a> |
8351 | schaersvoo | 713 | */ |
714 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
715 | fill_color = stroke_color; |
||
716 | i=0; |
||
717 | while( ! done ){ /* get next item until EOL*/ |
||
718 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
719 | if(i%2 == 0 ){ |
||
720 | double_data[i] = get_real(infile,0); /* x */ |
||
721 | } |
||
722 | else |
||
723 | { |
||
724 | double_data[i] = get_real(infile,1); /* y */ |
||
725 | } |
||
726 | i++; |
||
727 | } |
||
728 | decimals = find_number_of_digits(precision); |
||
729 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
730 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
||
731 | double_data[c+1] = xmin; |
||
732 | double_data[c+3] = ymax; |
||
733 | double_data[c+2] = double_data[c]; |
||
734 | } |
||
735 | else |
||
736 | { |
||
737 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
738 | double_data[c+3] = double_data[c+1]; |
||
739 | double_data[c] = ymin; |
||
740 | double_data[c+2] = xmax; |
||
741 | } |
||
742 | else |
||
743 | { |
||
744 | /* m */ |
||
745 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
746 | /* q */ |
||
747 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
748 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
749 | double_data[c+1] = (m)*(xmin)+(q); |
||
750 | double_data[c+3] = (m)*(xmax)+(q); |
||
751 | double_data[c] = xmin; |
||
752 | double_data[c+2] = xmax; |
||
753 | } |
||
754 | } |
||
9907 | schaersvoo | 755 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 756 | if(onclick > 0){click_cnt++;} |
757 | /* click_cnt++; */ |
||
8351 | schaersvoo | 758 | } |
759 | reset(); |
||
760 | break; |
||
8386 | schaersvoo | 761 | |
8244 | schaersvoo | 762 | case HALFLINE: |
763 | /* |
||
764 | @ demiline x1,y1,x2,y2,color |
||
765 | @ alternative : halfline |
||
766 | @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) |
||
9406 | schaersvoo | 767 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8244 | schaersvoo | 768 | */ |
769 | for(i=0;i<5;i++){ |
||
770 | switch(i){ |
||
771 | case 0: double_data[0]= get_real(infile,0);break; /* x-values */ |
||
772 | case 1: double_data[1]= get_real(infile,0);break; /* y-values */ |
||
773 | case 2: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
774 | case 3: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
775 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
776 | if(double_data[0] == double_data[10]){ /* vertical halfline */ |
||
777 | if(double_data[1] < double_data[11]){ |
||
778 | double_data[3] = ymax + 1000; |
||
779 | } |
||
780 | else |
||
781 | { |
||
782 | double_data[3] = ymin - 1000; |
||
783 | } |
||
10953 | bpr | 784 | double_data[2] = double_data[0]; |
8244 | schaersvoo | 785 | } |
786 | else |
||
787 | { /* horizontal halfline*/ |
||
788 | if( double_data[1] == double_data[11] ){ |
||
789 | if( double_data[0] < double_data[10] ){ |
||
790 | double_data[2] = xmax + 1000; /* halfline to the right */ |
||
791 | } |
||
792 | else |
||
793 | { |
||
794 | double_data[2] = xmin - 1000; /* halfline to the left */ |
||
795 | } |
||
796 | double_data[3] = double_data[1]; |
||
797 | } |
||
798 | else |
||
799 | { |
||
800 | /* any other halfline */ |
||
801 | /* slope */ |
||
802 | double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]); |
||
803 | /* const */ |
||
804 | double_data[13] = double_data[1] - double_data[12]*double_data[0]; |
||
805 | if( double_data[0] < double_data[10] ){ |
||
806 | double_data[2] = double_data[2] + 1000; |
||
807 | } |
||
808 | else |
||
809 | { |
||
810 | double_data[2] = double_data[2] - 1000; |
||
811 | } |
||
812 | double_data[3] = double_data[12]*double_data[2] + double_data[13]; |
||
813 | } |
||
10953 | bpr | 814 | } |
8244 | schaersvoo | 815 | decimals = find_number_of_digits(precision); |
9907 | schaersvoo | 816 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 817 | if(onclick > 0){click_cnt++;} |
818 | /* click_cnt++; */ |
||
819 | reset(); |
||
8244 | schaersvoo | 820 | break; |
821 | } |
||
822 | } |
||
823 | break; |
||
8386 | schaersvoo | 824 | |
8365 | schaersvoo | 825 | case HALFLINES: |
826 | /* |
||
827 | @ demilines color,x1,y1,x2,y2,.... |
||
828 | @ alternative : halflines |
||
829 | @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc |
||
9406 | schaersvoo | 830 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually |
8365 | schaersvoo | 831 | */ |
832 | stroke_color=get_color(infile,0); |
||
833 | fill_color = stroke_color; |
||
834 | i=0; |
||
835 | while( ! done ){ /* get next item until EOL*/ |
||
836 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
837 | if(i%2 == 0 ){ |
||
838 | double_data[i] = get_real(infile,0); /* x */ |
||
839 | } |
||
840 | else |
||
841 | { |
||
842 | double_data[i] = get_real(infile,1); /* y */ |
||
843 | } |
||
844 | i++; |
||
845 | } |
||
846 | decimals = find_number_of_digits(precision); |
||
847 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
848 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
||
849 | if(double_data[c+1] < double_data[c+3]){ /* upright halfline */ |
||
850 | double_data[c+3] = ymax + 1000; |
||
851 | } |
||
852 | else |
||
853 | { |
||
854 | double_data[c+3] = ymin - 1000;/* descending halfline */ |
||
855 | } |
||
856 | } |
||
857 | else |
||
858 | { |
||
859 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
860 | if(double_data[c] < double_data[c+2] ){ /* halfline to the right */ |
||
861 | double_data[c+2] = xmax+100; |
||
862 | } |
||
863 | else |
||
864 | { |
||
865 | double_data[c+2] = xmin-1000; /* halfline to the right */ |
||
866 | } |
||
867 | } |
||
868 | else |
||
869 | { |
||
870 | /* m */ |
||
871 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
872 | /* q */ |
||
873 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
874 | if(double_data[c] < double_data[c+2]){ /* to the right */ |
||
875 | double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it's just segment */ |
||
876 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
877 | } |
||
878 | else |
||
879 | { /* to the left */ |
||
880 | double_data[c+2] = xmin - 1000; |
||
881 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
882 | } |
||
883 | } |
||
884 | } |
||
9907 | schaersvoo | 885 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 886 | if(onclick > 0){click_cnt++;} |
887 | /* click_cnt++; */ |
||
8365 | schaersvoo | 888 | } |
889 | reset(); |
||
890 | break; |
||
8386 | schaersvoo | 891 | |
8224 | bpr | 892 | case HLINE: |
7614 | schaersvoo | 893 | /* |
894 | @ hline x,y,color |
||
9383 | schaersvoo | 895 | @ alternative : horizontalline |
7614 | schaersvoo | 896 | @ draw a horizontal line through point (x:y) in color 'color' |
9373 | schaersvoo | 897 | @ or use command <a href='#curve'>'curve color,formula'</a> to draw the line <br />(uses more points to draw the line; is however better draggable) |
9406 | schaersvoo | 898 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 899 | */ |
900 | for(i=0;i<3;i++) { |
||
901 | switch(i){ |
||
902 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
903 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
904 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
905 | double_data[3] = double_data[1]; |
||
906 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 907 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 908 | if(onclick > 0){click_cnt++;} |
909 | /* click_cnt++; */ |
||
910 | reset(); |
||
7614 | schaersvoo | 911 | break; |
912 | } |
||
913 | } |
||
914 | break; |
||
8366 | schaersvoo | 915 | |
916 | case HLINES: |
||
917 | /* |
||
918 | @ hlines color,x1,y1,x2,y2,... |
||
9383 | schaersvoo | 919 | @ alternative : horizontallines |
8366 | schaersvoo | 920 | @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color' |
9406 | schaersvoo | 921 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8366 | schaersvoo | 922 | */ |
923 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
924 | fill_color = stroke_color; |
||
925 | i=0; |
||
926 | while( ! done ){ /* get next item until EOL*/ |
||
927 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
928 | if(i%2 == 0 ){ |
||
929 | double_data[i] = get_real(infile,0); /* x */ |
||
930 | } |
||
931 | else |
||
932 | { |
||
933 | double_data[i] = get_real(infile,1); /* y */ |
||
934 | } |
||
935 | i++; |
||
936 | } |
||
937 | decimals = find_number_of_digits(precision); |
||
938 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
9907 | schaersvoo | 939 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[c+1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 940 | if(onclick > 0){click_cnt++;} |
941 | /* click_cnt++; */ |
||
8366 | schaersvoo | 942 | } |
943 | reset(); |
||
944 | break; |
||
8386 | schaersvoo | 945 | |
7614 | schaersvoo | 946 | case VLINE: |
947 | /* |
||
948 | @ vline x,y,color |
||
9383 | schaersvoo | 949 | @ alternative : verticalline |
9213 | schaersvoo | 950 | @ draw a vertical line through point (x:y) in color 'color' |
9406 | schaersvoo | 951 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 952 | */ |
953 | for(i=0;i<3;i++) { |
||
954 | switch(i){ |
||
955 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
956 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
957 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
958 | double_data[2] = double_data[0]; |
||
959 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 960 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 961 | if(onclick > 0){click_cnt++;} |
962 | /* click_cnt++; */ |
||
963 | reset(); |
||
7614 | schaersvoo | 964 | break; |
965 | } |
||
966 | } |
||
967 | break; |
||
8386 | schaersvoo | 968 | |
8366 | schaersvoo | 969 | case VLINES: |
970 | /* |
||
971 | @ vlines color,x1,y1,x2,y2.... |
||
9383 | schaersvoo | 972 | @ alternative : verticallines |
9213 | schaersvoo | 973 | @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color' |
9406 | schaersvoo | 974 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8366 | schaersvoo | 975 | */ |
976 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
977 | fill_color = stroke_color; |
||
978 | i=0; |
||
979 | while( ! done ){ /* get next item until EOL*/ |
||
980 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
981 | if(i%2 == 0 ){ |
||
982 | double_data[i] = get_real(infile,0); /* x */ |
||
983 | } |
||
984 | else |
||
985 | { |
||
986 | double_data[i] = get_real(infile,1); /* y */ |
||
987 | } |
||
988 | i++; |
||
989 | } |
||
990 | decimals = find_number_of_digits(precision); |
||
991 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
9907 | schaersvoo | 992 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 993 | if(onclick > 0){click_cnt++;} |
994 | /* click_cnt++; */ |
||
8366 | schaersvoo | 995 | } |
996 | reset(); |
||
997 | break; |
||
8386 | schaersvoo | 998 | |
7614 | schaersvoo | 999 | case SQUARE: |
1000 | /* |
||
8071 | schaersvoo | 1001 | @ square x,y,side (px) ,color |
7614 | schaersvoo | 1002 | @ draw a square with left top corner (x:y) with side 'side' in color 'color' |
1003 | @ use command 'fsquare x,y,side,color' for a filled square |
||
9373 | schaersvoo | 1004 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'square x,y,side,color' |
9406 | schaersvoo | 1005 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1006 | */ |
1007 | for(i=0;i<5;i++){ |
||
1008 | switch(i){ |
||
8071 | schaersvoo | 1009 | case 0:double_data[0] = get_real(infile,0);break; /* x1-values */ |
1010 | case 1:double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
1011 | case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */ |
||
1012 | case 3: |
||
1013 | stroke_color = get_color(infile,1);/* name or hex color */ |
||
7614 | schaersvoo | 1014 | decimals = find_number_of_digits(precision); |
8071 | schaersvoo | 1015 | double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize; |
1016 | double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize; |
||
9907 | schaersvoo | 1017 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1018 | if(onclick > 0){click_cnt++;} |
1019 | /* click_cnt++; */ |
||
1020 | reset(); |
||
7614 | schaersvoo | 1021 | break; |
1022 | } |
||
1023 | } |
||
1024 | break; |
||
8386 | schaersvoo | 1025 | |
1026 | case RECT: |
||
7614 | schaersvoo | 1027 | /* |
8386 | schaersvoo | 1028 | @ rect x1,y1,x2,y2,color |
1029 | @ use command 'frect x1,y1,x2,y2,color' for a filled rectangle |
||
9373 | schaersvoo | 1030 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'rect x1,y1,x2,y2,color' |
9406 | schaersvoo | 1031 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1032 | */ |
8386 | schaersvoo | 1033 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 1034 | switch(i){ |
1035 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1036 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
1037 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
1038 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
8386 | schaersvoo | 1039 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
7614 | schaersvoo | 1040 | decimals = find_number_of_digits(precision); |
9907 | schaersvoo | 1041 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[2],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[3],decimals,double_data[3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1042 | if(onclick > 0){click_cnt++;} |
8386 | schaersvoo | 1043 | /* click_cnt++; */ |
8379 | schaersvoo | 1044 | reset(); |
8386 | schaersvoo | 1045 | break; |
7614 | schaersvoo | 1046 | } |
1047 | } |
||
1048 | break; |
||
8386 | schaersvoo | 1049 | |
1050 | case RECTS: |
||
8370 | schaersvoo | 1051 | /* |
8386 | schaersvoo | 1052 | @ rects color,x1,y1,x2,y2,..... |
1053 | @ use command 'frect color,x1,y1,x2,y2,.....' for a filled rectangle |
||
9373 | schaersvoo | 1054 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'rects color,x1,y1,x2,y2,....' |
8386 | schaersvoo | 1055 | @ use command 'fillcolor color' before 'frects' to set the fill colour. |
9406 | schaersvoo | 1056 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8370 | schaersvoo | 1057 | */ |
1058 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1059 | fill_color = stroke_color; |
||
1060 | i=0; |
||
1061 | while( ! done ){ /* get next item until EOL*/ |
||
1062 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1063 | if(i%2 == 0 ){ |
||
1064 | double_data[i] = get_real(infile,0); /* x */ |
||
1065 | } |
||
1066 | else |
||
1067 | { |
||
1068 | double_data[i] = get_real(infile,1); /* y */ |
||
1069 | } |
||
1070 | i++; |
||
1071 | } |
||
1072 | decimals = find_number_of_digits(precision); |
||
1073 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
9907 | schaersvoo | 1074 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+2],decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+1],decimals,double_data[c+3],decimals,double_data[c+3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1075 | if(onclick > 0){click_cnt++;} |
1076 | /* click_cnt++; */ |
||
8370 | schaersvoo | 1077 | } |
1078 | reset(); |
||
1079 | break; |
||
8386 | schaersvoo | 1080 | |
1081 | case ROUNDRECT: |
||
7614 | schaersvoo | 1082 | /* |
8386 | schaersvoo | 1083 | @ roundrect x1,y1,x2,y2,radius in px,color |
1084 | @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle |
||
9373 | schaersvoo | 1085 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'roundrect x1,y1,x2,y2,radius,color' |
8386 | schaersvoo | 1086 | @ fillcolor will be identical to 'color' |
9406 | schaersvoo | 1087 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1088 | */ |
8386 | schaersvoo | 1089 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 1090 | switch(i){ |
1091 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1092 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
1093 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
1094 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
8386 | schaersvoo | 1095 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
1096 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
1097 | /* ensure no inverted roundrect is produced... */ |
||
1098 | if( double_data[0] > double_data[2] ){double_data[4] = double_data[0];double_data[0] = double_data[2];double_data[2] = double_data[4];} |
||
1099 | if( double_data[3] > double_data[1] ){double_data[4] = double_data[1];double_data[1] = double_data[3];double_data[3] = double_data[4];} |
||
7614 | schaersvoo | 1100 | decimals = find_number_of_digits(precision); |
9907 | schaersvoo | 1101 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1102 | if(onclick > 0){click_cnt++;} |
8386 | schaersvoo | 1103 | /* click_cnt++;*/ |
8379 | schaersvoo | 1104 | reset(); |
8386 | schaersvoo | 1105 | break; |
7614 | schaersvoo | 1106 | } |
1107 | } |
||
1108 | break; |
||
8363 | schaersvoo | 1109 | |
8386 | schaersvoo | 1110 | case ROUNDRECTS: |
8363 | schaersvoo | 1111 | /* |
8386 | schaersvoo | 1112 | @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,.... |
9373 | schaersvoo | 1113 | @ for filled roundrects use command/keyword <a href='#filled'>'filled'</a> before command |
9406 | schaersvoo | 1114 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8363 | schaersvoo | 1115 | */ |
8386 | schaersvoo | 1116 | |
8363 | schaersvoo | 1117 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
8386 | schaersvoo | 1118 | int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */ |
8363 | schaersvoo | 1119 | fill_color = stroke_color; |
1120 | i=0; |
||
1121 | while( ! done ){ /* get next item until EOL*/ |
||
1122 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1123 | if(i%2 == 0 ){ |
||
1124 | double_data[i] = get_real(infile,0); /* x */ |
||
1125 | } |
||
1126 | else |
||
1127 | { |
||
1128 | double_data[i] = get_real(infile,1); /* y */ |
||
1129 | } |
||
1130 | i++; |
||
1131 | } |
||
1132 | decimals = find_number_of_digits(precision); |
||
1133 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
8386 | schaersvoo | 1134 | /* ensure no inverted roundrect is produced... */ |
1135 | if( double_data[c] > double_data[c+2] ){double_data[c+4] = double_data[c];double_data[c] = double_data[c+2];double_data[c+2] = double_data[c+4];} |
||
1136 | if( double_data[c+3] > double_data[c+1] ){double_data[c+4] = double_data[c+1];double_data[c+1] = double_data[c+3];double_data[c+3] = double_data[c+4];} |
||
9907 | schaersvoo | 1137 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1138 | if(onclick > 0){click_cnt++;} |
1139 | /* click_cnt++; */ |
||
8363 | schaersvoo | 1140 | } |
1141 | reset(); |
||
1142 | break; |
||
7614 | schaersvoo | 1143 | case POLYLINE: |
1144 | /* |
||
1145 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
10975 | schaersvoo | 1146 | @ brokenline color,x1,y1,x2,y2...x_n,y_n |
1147 | @ path color,x1,y1,x2,y2...x_n,y_n |
||
1148 | @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands "polyline ,x1,y1,x2,y2...x_n,y_n" |
||
1149 | @ remark: there are commands "userdraw path(s),color" and "userdraw polyline,color"... these are two entirely different things !<br />the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command |
||
1150 | @ the command interconnects the points in the given order with a line (canvasdraw will not close the drawing: use command <a href="#poly">polygon</a> for this) |
||
1151 | @ use command <a href='#segments'>'segments'</a> for a series of segments.<br />these may be clicked/dragged individually |
||
9406 | schaersvoo | 1152 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1153 | */ |
1154 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1155 | i=0; |
||
1156 | c=0; |
||
1157 | while( ! done ){ /* get next item until EOL*/ |
||
1158 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1159 | for( c = 0 ; c < 2; c++){ |
||
1160 | if(c == 0 ){ |
||
1161 | double_data[i] = get_real(infile,0); |
||
1162 | i++; |
||
1163 | } |
||
1164 | else |
||
1165 | { |
||
1166 | double_data[i] = get_real(infile,1); |
||
1167 | i++; |
||
1168 | } |
||
1169 | } |
||
1170 | } |
||
1171 | /* draw path : not closed & not filled */ |
||
1172 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1173 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1174 | if(onclick > 0){click_cnt++;} |
1175 | /* click_cnt++;*/ |
||
1176 | reset(); |
||
7614 | schaersvoo | 1177 | break; |
1178 | case POLY: |
||
1179 | /* |
||
1180 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
10975 | schaersvoo | 1181 | @ polygon color,x1,y1,x2,y2...x_n,y_n |
7614 | schaersvoo | 1182 | @ draw closed polygon |
9373 | schaersvoo | 1183 | @ use command 'fpoly' to fill it or use keyword <a href='#filled'>'filled'</a> |
9406 | schaersvoo | 1184 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1185 | */ |
1186 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1187 | i=0; |
||
1188 | c=0; |
||
1189 | while( ! done ){ /* get next item until EOL*/ |
||
1190 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1191 | for( c = 0 ; c < 2; c++){ |
||
1192 | if(c == 0 ){ |
||
1193 | double_data[i] = get_real(infile,0); |
||
1194 | i++; |
||
1195 | } |
||
1196 | else |
||
1197 | { |
||
1198 | double_data[i] = get_real(infile,1); |
||
1199 | i++; |
||
1200 | } |
||
1201 | } |
||
1202 | } |
||
1203 | /* draw path : closed & optional filled */ |
||
1204 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1205 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1206 | if(onclick > 0){click_cnt++;} |
1207 | /* click_cnt++; */ |
||
1208 | reset(); |
||
7614 | schaersvoo | 1209 | break; |
8224 | bpr | 1210 | case ARC: |
7614 | schaersvoo | 1211 | /* |
1212 | @ arc xc,yc,width,height,start_angle,end_angle,color |
||
8816 | schaersvoo | 1213 | @ can <b>not</b> be set "onclick" or "drag xy" |
10953 | bpr | 1214 | @ <b>attention</b>: width in height in x/y-range |
8105 | schaersvoo | 1215 | @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work |
9373 | schaersvoo | 1216 | @ use command <a href='#angle'>'angle'</a> for scalable angle |
7614 | schaersvoo | 1217 | */ |
1218 | for(i=0;i<7;i++){ |
||
1219 | switch(i){ |
||
1220 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1221 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
8448 | schaersvoo | 1222 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */ |
1223 | case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */ |
||
1224 | case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */ |
||
1225 | case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */ |
||
7614 | schaersvoo | 1226 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
1227 | /* in Shape library: |
||
8448 | schaersvoo | 1228 | x[0] = x[1] = xc = double_data[0] |
1229 | y[0] = y[1] = yc = double_data[1] |
||
1230 | w[0] = width = double_data[2] |
||
1231 | w[1] = height = double_data[3] |
||
1232 | h[0] = start_angle = double_data[4] |
||
1233 | h[1] = end_angle = double_data[5] |
||
7614 | schaersvoo | 1234 | */ |
1235 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1236 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
7614 | schaersvoo | 1237 | reset(); |
1238 | break; |
||
1239 | } |
||
1240 | } |
||
1241 | break; |
||
8224 | bpr | 1242 | case ANGLE: |
8105 | schaersvoo | 1243 | /* |
1244 | @ angle xc,yc,width,start_angle,end_angle,color |
||
1245 | @ width is in x-range |
||
1246 | @ will zoom in/out |
||
9373 | schaersvoo | 1247 | @ if size is controlled by command <a href='#slider'>'slider'</a> use radians to set limits of slider. |
8105 | schaersvoo | 1248 | */ |
1249 | for(i=0;i<7;i++){ |
||
1250 | switch(i){ |
||
1251 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1252 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
1253 | case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */ |
||
1254 | case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */ |
||
1255 | case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */ |
||
1256 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
1257 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1258 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,17,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8105 | schaersvoo | 1259 | reset(); |
1260 | break; |
||
1261 | } |
||
1262 | } |
||
1263 | break; |
||
1264 | |||
7614 | schaersvoo | 1265 | case ELLIPSE: |
1266 | /* |
||
1267 | @ ellipse xc,yc,radius_x,radius_y,color |
||
8224 | bpr | 1268 | @ a ellipse with center xc/yc in x/y-range |
7614 | schaersvoo | 1269 | @ radius_x and radius_y are in pixels |
9406 | schaersvoo | 1270 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8224 | bpr | 1271 | @ will shrink / expand on zoom out / zoom in |
7614 | schaersvoo | 1272 | */ |
1273 | for(i=0;i<5;i++){ |
||
1274 | switch(i){ |
||
1275 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1276 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
1277 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
||
8224 | bpr | 1278 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
7614 | schaersvoo | 1279 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
1280 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1281 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1282 | if(onclick > 0){click_cnt++;} |
1283 | /* click_cnt++; */ |
||
1284 | reset(); |
||
7614 | schaersvoo | 1285 | break; |
1286 | } |
||
1287 | } |
||
1288 | break; |
||
1289 | case DASHTYPE: |
||
1290 | /* |
||
8383 | schaersvoo | 1291 | @ dashtype line_width_px,space_width_px |
10953 | bpr | 1292 | @ every indiviual object may have its own dashtype, if needed... |
9373 | schaersvoo | 1293 | @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype |
8383 | schaersvoo | 1294 | @ default value "dashtype 2,2" e.g. 2px line and 2px space |
1295 | @ html5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable |
||
7614 | schaersvoo | 1296 | */ |
1297 | for(i=0;i<2;i++){ |
||
1298 | switch(i){ |
||
1299 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
1300 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
1301 | } |
||
1302 | } |
||
1303 | break; |
||
8304 | schaersvoo | 1304 | |
7614 | schaersvoo | 1305 | case RAYS: |
1306 | /* |
||
1307 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
1308 | @ draw rays in color 'color' and center (xc:yc) |
||
7786 | schaersvoo | 1309 | @ may be set draggable or onclick (every individual ray) |
7614 | schaersvoo | 1310 | */ |
1311 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 1312 | fill_color = stroke_color; |
1313 | double_data[0] = get_real(infile,0);/* xc */ |
||
1314 | double_data[1] = get_real(infile,0);/* yc */ |
||
1315 | i=2; |
||
1316 | while( ! done ){ /* get next item until EOL*/ |
||
1317 | if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");} |
||
1318 | if(i%2 == 0 ){ |
||
1319 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 1320 | } |
7786 | schaersvoo | 1321 | else |
1322 | { |
||
1323 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 1324 | } |
7786 | schaersvoo | 1325 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
1326 | i++; |
||
7614 | schaersvoo | 1327 | } |
8224 | bpr | 1328 | |
1329 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
||
1330 | decimals = find_number_of_digits(precision); |
||
7786 | schaersvoo | 1331 | for(c=2; c<i;c = c+2){ |
9907 | schaersvoo | 1332 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1333 | /* click_cnt++; */ |
1334 | if(onclick > 0){click_cnt++;} |
||
7614 | schaersvoo | 1335 | } |
1336 | reset(); |
||
1337 | break; |
||
8304 | schaersvoo | 1338 | |
8386 | schaersvoo | 1339 | case ARROWHEAD: |
1340 | /* |
||
1341 | @ arrowhead int |
||
1342 | @ default 8 (pixels) |
||
1343 | */ |
||
1344 | arrow_head = (int) (get_real(infile,1)); |
||
1345 | break; |
||
1346 | |||
1347 | case ARROW: |
||
1348 | /* |
||
1349 | @ arrow x1,y1,x2,y2,h,color |
||
9382 | schaersvoo | 1350 | @ alternative : vector |
1351 | @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
8386 | schaersvoo | 1352 | @ use command 'linewidth int' to adjust thickness of the arrow |
9406 | schaersvoo | 1353 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8386 | schaersvoo | 1354 | */ |
1355 | for(i=0;i<6;i++){ |
||
1356 | switch(i){ |
||
1357 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1358 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1359 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
1360 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
1361 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
1362 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1363 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1364 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8386 | schaersvoo | 1365 | if(onclick > 0){click_cnt++;} |
1366 | /* click_cnt++;*/ |
||
1367 | reset(); |
||
1368 | break; |
||
1369 | } |
||
1370 | } |
||
1371 | break; |
||
1372 | |||
8304 | schaersvoo | 1373 | case ARROWS: |
1374 | /* |
||
1375 | @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n |
||
9382 | schaersvoo | 1376 | @ alternative : vectors |
8304 | schaersvoo | 1377 | @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color' |
1378 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
9406 | schaersvoo | 1379 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8304 | schaersvoo | 1380 | */ |
1381 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1382 | fill_color = stroke_color; |
||
1383 | arrow_head = (int) get_real(infile,0);/* h */ |
||
1384 | i=0; |
||
1385 | while( ! done ){ /* get next item until EOL*/ |
||
1386 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1387 | if(i%2 == 0 ){ |
||
1388 | double_data[i] = get_real(infile,0); /* x */ |
||
1389 | } |
||
1390 | else |
||
1391 | { |
||
1392 | double_data[i] = get_real(infile,1); /* y */ |
||
1393 | } |
||
1394 | i++; |
||
1395 | } |
||
1396 | decimals = find_number_of_digits(precision); |
||
1397 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
9907 | schaersvoo | 1398 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1399 | if(onclick > 0){click_cnt++;} |
1400 | /* click_cnt++; */ |
||
8304 | schaersvoo | 1401 | } |
1402 | reset(); |
||
1403 | break; |
||
8386 | schaersvoo | 1404 | |
7614 | schaersvoo | 1405 | case ARROW2: |
1406 | /* |
||
1407 | @ arrow2 x1,y1,x2,y2,h,color |
||
1408 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
1409 | @ use command 'arrowhead int' to adjust the arrow head size |
||
1410 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
9406 | schaersvoo | 1411 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1412 | */ |
1413 | for(i=0;i<6;i++){ |
||
1414 | switch(i){ |
||
1415 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1416 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1417 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
1418 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
1419 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
1420 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1421 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1422 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1423 | if(onclick > 0){click_cnt++;} |
1424 | /* click_cnt++;*/ |
||
1425 | reset(); |
||
7614 | schaersvoo | 1426 | break; |
1427 | } |
||
1428 | } |
||
1429 | break; |
||
8386 | schaersvoo | 1430 | |
8347 | schaersvoo | 1431 | case ARROWS2: |
1432 | /* |
||
1433 | @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n |
||
1434 | @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color' |
||
1435 | @ use command 'linewidth int' to adjust thickness of the arrows |
||
9406 | schaersvoo | 1436 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8347 | schaersvoo | 1437 | */ |
1438 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1439 | fill_color = stroke_color; |
||
1440 | arrow_head = (int) get_real(infile,0);/* h */ |
||
1441 | i=0; |
||
1442 | while( ! done ){ /* get next item until EOL*/ |
||
1443 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1444 | if(i%2 == 0 ){ |
||
1445 | double_data[i] = get_real(infile,0); /* x */ |
||
1446 | } |
||
1447 | else |
||
1448 | { |
||
1449 | double_data[i] = get_real(infile,1); /* y */ |
||
1450 | } |
||
1451 | i++; |
||
1452 | } |
||
1453 | decimals = find_number_of_digits(precision); |
||
1454 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
9907 | schaersvoo | 1455 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1456 | if(onclick > 0){click_cnt++;} |
1457 | /* click_cnt++; */ |
||
10953 | bpr | 1458 | |
8347 | schaersvoo | 1459 | } |
1460 | reset(); |
||
1461 | break; |
||
8386 | schaersvoo | 1462 | |
8224 | bpr | 1463 | case PARALLEL: |
7614 | schaersvoo | 1464 | /* |
1465 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
8816 | schaersvoo | 1466 | @ can <b>not</b> be set "onclick" or "drag xy" |
7614 | schaersvoo | 1467 | */ |
1468 | for( i = 0;i < 8; i++ ){ |
||
1469 | switch(i){ |
||
1470 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values -> x-pixels*/ |
||
1471 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values -> y-pixels*/ |
||
1472 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values -> x-pixels*/ |
||
1473 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values -> y-pixels*/ |
||
1474 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */ |
||
1475 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */ |
||
1476 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
1477 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
||
1478 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1479 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1480 | if(onclick > 0){click_cnt++;} |
1481 | /* click_cnt++*/; |
||
1482 | reset(); |
||
7614 | schaersvoo | 1483 | break; |
1484 | default: break; |
||
1485 | } |
||
1486 | } |
||
1487 | break; |
||
8386 | schaersvoo | 1488 | |
7614 | schaersvoo | 1489 | case TRIANGLE: |
1490 | /* |
||
9385 | schaersvoo | 1491 | @ triangle x1,y1,x2,y2,x3,y3,color |
1492 | @ use ftriangle or keyword <a href='#filled'>'filled'</a> for a solid triangle |
||
9406 | schaersvoo | 1493 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1494 | */ |
1495 | for(i=0;i<7;i++){ |
||
1496 | switch(i){ |
||
1497 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1498 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1499 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
1500 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
1501 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
1502 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
1503 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1504 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 1505 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 1506 | if(onclick > 0){click_cnt++;} |
1507 | /* click_cnt++;*/ |
||
1508 | reset(); |
||
7614 | schaersvoo | 1509 | break; |
1510 | default: break; |
||
1511 | } |
||
1512 | } |
||
1513 | break; |
||
9306 | schaersvoo | 1514 | case TRIANGLES: |
1515 | /* |
||
9385 | schaersvoo | 1516 | @ triangles color,x1,y1,x2,y2,x3,y3,... |
1517 | @ use ftriangles or keyword <a href='#filled'>'filled'</a> for solid triangles |
||
9406 | schaersvoo | 1518 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
9306 | schaersvoo | 1519 | */ |
1520 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1521 | i = 0; |
||
1522 | decimals = find_number_of_digits(precision); |
||
1523 | while( ! done ){ |
||
1524 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1525 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1526 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1527 | double_data[2] = get_real(infile,0); /* x2 */ |
||
1528 | double_data[3] = get_real(infile,0); /* y2 */ |
||
1529 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1530 | double_data[5] = get_real(infile,1); /* y3 */ |
||
9907 | schaersvoo | 1531 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
10953 | bpr | 1532 | if(onclick > 0){click_cnt++;} |
9306 | schaersvoo | 1533 | i = i + 6; |
1534 | } |
||
1535 | reset(); |
||
1536 | break; |
||
7614 | schaersvoo | 1537 | case LATTICE: |
1538 | /* |
||
9385 | schaersvoo | 1539 | @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
1540 | @ can <b>not</b> be set "onclick" or "drag xy" |
||
7614 | schaersvoo | 1541 | */ |
1542 | if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;} |
||
1543 | for( i = 0; i<9; i++){ |
||
1544 | switch(i){ |
||
1545 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
||
1546 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
1547 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
8071 | schaersvoo | 1548 | case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values -> y-pixels*/ |
7614 | schaersvoo | 1549 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
8071 | schaersvoo | 1550 | case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values -> y-pixels*/ |
7614 | schaersvoo | 1551 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
1552 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
1553 | case 8: stroke_color=get_color(infile,1); |
||
1554 | decimals = find_number_of_digits(precision); |
||
8071 | schaersvoo | 1555 | string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 1556 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 1557 | snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix); |
8370 | schaersvoo | 1558 | add_to_buffer(tmp_buffer);break; |
7614 | schaersvoo | 1559 | default:break; |
1560 | } |
||
1561 | } |
||
1562 | reset(); |
||
1563 | break; |
||
10953 | bpr | 1564 | |
9213 | schaersvoo | 1565 | case MULTISTROKEOPACITY: |
1566 | /* |
||
9250 | schaersvoo | 1567 | @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7 |
10953 | bpr | 1568 | @ float values 0 - 1 or integer values 0 - 255 |
9373 | schaersvoo | 1569 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9270 | schaersvoo | 1570 | @ if not set all stroke opacity_ will be set by previous command <em>'opacity int,int'</em> |
1571 | @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em> |
||
9213 | schaersvoo | 1572 | @ wims will not check the amount or validity of your input |
1573 | @ always use the same sequence as is used for 'multidraw' |
||
1574 | */ |
||
9332 | schaersvoo | 1575 | if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1576 | temp = get_string(infile,1); |
1577 | temp = str_replace(temp,",","\",\""); |
||
1578 | fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp); |
||
1579 | break; |
||
1580 | case MULTIFILLOPACITY: |
||
1581 | /* |
||
9372 | schaersvoo | 1582 | @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8 |
10953 | bpr | 1583 | @ float values 0 - 1 or integer values 0 - 255 |
9373 | schaersvoo | 1584 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9270 | schaersvoo | 1585 | @ if not set all fill opacity_ will be set by previous command <em>'opacity int,int'</em> and keyword <em>'filled'</em> |
1586 | @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_y</em> |
||
9213 | schaersvoo | 1587 | @ wims will not check the amount or validity of your input |
1588 | @ always use the same sequence as is used for 'multidraw' |
||
1589 | */ |
||
9332 | schaersvoo | 1590 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1591 | temp = get_string(infile,1); |
1592 | temp = str_replace(temp,",","\",\""); |
||
1593 | fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp); |
||
1594 | break; |
||
1595 | case MULTILABEL: |
||
1596 | /* |
||
9372 | schaersvoo | 1597 | @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text' |
9373 | schaersvoo | 1598 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9213 | schaersvoo | 1599 | @ if not set all labels (e.g. the value='' of input type 'button') will be set by the english names for the draw_primitives (like 'point','circle'...) |
9270 | schaersvoo | 1600 | @ the 'stop drawing' button text <b>must</b> be the last item on the 'multilabel' -list <br />for example:<br /><em>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</em> |
9378 | schaersvoo | 1601 | @ all buttons can be 'styled' by using commant 'inputstyle'<br /><b><b>note</b>:</b><em>If you want to add some CSS style to the buttons...<br />the id's of the 'draw buttons' are their english command argument<br />(e.g. id="canvasdraw_points" for the draw points button).<br />the id of the 'stop drawing' button is "canvasdraw_stop_drawing".<br />the id of the "OK" button is"canvasdraw_ok_button"</em> |
9213 | schaersvoo | 1602 | @ wims will not check the amount or validity of your input |
1603 | @ always use the same sequence as is used for 'multidraw' |
||
1604 | */ |
||
9332 | schaersvoo | 1605 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1606 | temp = get_string(infile,1); |
1607 | temp = str_replace(temp,",","\",\""); |
||
1608 | fprintf(js_include_file,"var multilabel = [\"%s\"];",temp); |
||
1609 | break; |
||
1610 | case MULTILINEWIDTH: |
||
1611 | /* |
||
9372 | schaersvoo | 1612 | @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8 |
9373 | schaersvoo | 1613 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9270 | schaersvoo | 1614 | @ if not set all line width will be set by a previous command <em>'linewidth int'</em> |
1615 | @ use these up to 7 different line widths for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em> |
||
9213 | schaersvoo | 1616 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
1617 | @ always use the same sequence as is used for 'multidraw' |
||
1618 | */ |
||
9332 | schaersvoo | 1619 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1620 | temp = get_string(infile,1); |
1621 | temp = str_replace(temp,",","\",\""); |
||
1622 | fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp); |
||
1623 | break; |
||
1624 | case MULTIDASH: |
||
1625 | /* |
||
1626 | @ multidash 0,1,1 |
||
9270 | schaersvoo | 1627 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, are dashed |
9373 | schaersvoo | 1628 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9270 | schaersvoo | 1629 | @ if not set all objects will be set 'not dashed'...<br />unless a generic keyword <em>'dashed'</em> was given before command <em>'multidraw'</em> |
1630 | @ the dash-type is not -yet- adjustable <br />(e.g. command <em>dashtype line_px,space_px</em> will give no control over multidraw objects) |
||
9213 | schaersvoo | 1631 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
1632 | @ always use the same sequence as is used for 'multidraw' |
||
1633 | */ |
||
9332 | schaersvoo | 1634 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1635 | temp = get_string(infile,1); |
1636 | temp = str_replace(temp,",","\",\""); |
||
1637 | fprintf(js_include_file,"var multidash = [\"%s\"];",temp); |
||
1638 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
1639 | break; |
||
1640 | case MULTISNAPTOGRID: |
||
1641 | /* |
||
1642 | @ multisnaptogrid 0,1,1 |
||
9373 | schaersvoo | 1643 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>'snaptogrid'</a>) |
9270 | schaersvoo | 1644 | @ only the x-values snap_to_grid: <em>multisnaptogrid 0,2,2</em> |
1645 | @ only the y-values snap_to_grid: <em>multisnaptogrid 0,3,3</em> |
||
1646 | @ mixing allowed: <em>multisnaptogrid 1,2,3,0</em> e.g. the first object will snap to the xy-grid, the second draw object will snap to the x-values, the third object will snap to the y-valeus of the grid, the last object may be placed anywhere on the canvas |
||
9373 | schaersvoo | 1647 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9213 | schaersvoo | 1648 | @ if not set all objects will be set 'no snap'...<br />unless a generic command 'snaptogrid' was given before command 'multidraw' |
9373 | schaersvoo | 1649 | @ commands <a href='#xsnaptogrid'>'xsnaptogrid'</a>, <a href='#ysnaptogrid'>'ysnaptogrid'</a>, <a href='#snaptofunction'>'snaptofunction'</a> and <a href='#snaptopoints'>'snaptopoints</a> x1,y1,x2,y2...' are <b>not</b> supported at this time |
9213 | schaersvoo | 1650 | @ always use the same sequence as is used for 'multidraw' |
1651 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
||
1652 | */ |
||
9332 | schaersvoo | 1653 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1654 | temp = get_string(infile,1); |
1655 | temp = str_replace(temp,",","\",\""); |
||
1656 | fprintf(js_include_file,"var multisnaptogrid = [\"%s\"];",temp); |
||
1657 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
1658 | break; |
||
1659 | case MULTIFILL: |
||
1660 | /* |
||
9372 | schaersvoo | 1661 | @ multifill 0,0,1,0,1,0,0 |
9213 | schaersvoo | 1662 | @ meaning draw objects no. 3 and 5, in the list of command 'multifill', are filled<br />(if the object is fillable...and not a line,segment,arrow or point...) |
9373 | schaersvoo | 1663 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9213 | schaersvoo | 1664 | @ if not set all objects -except point|points- will be set 'not filled'...<br />unless a command 'filled' was given before command 'multifill' |
1665 | @ only suitable for draw_primitives like 'circle | circles' , 'triangle | triangles' and 'polygon' |
||
1666 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
||
1667 | @ always use the same sequence as is used for 'multidraw' |
||
1668 | */ |
||
9332 | schaersvoo | 1669 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1670 | temp = get_string(infile,1); |
1671 | temp = str_replace(temp,",","\",\""); |
||
1672 | fprintf(js_include_file,"var multifill = [\"%s\"];",temp); |
||
1673 | break; |
||
1674 | case MULTISTROKECOLORS: |
||
1675 | /* |
||
9372 | schaersvoo | 1676 | @ multistrokecolors color_name_1,color_name_2,...,color_name_8 |
9373 | schaersvoo | 1677 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9213 | schaersvoo | 1678 | @ if not set all colors will be 'stroke_color' , 'stroke_opacity' |
9270 | schaersvoo | 1679 | @ use these up to 6 colors for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em> |
9213 | schaersvoo | 1680 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
1681 | @ always use the same sequence as is used for 'multidraw' |
||
1682 | */ |
||
9332 | schaersvoo | 1683 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1684 | fprintf(js_include_file,"var multistrokecolors = ["); |
1685 | while( ! done ){ |
||
1686 | temp = get_color(infile,1); |
||
1687 | fprintf(js_include_file,"\"%s\",",temp); |
||
1688 | } |
||
1689 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
1690 | break; |
||
1691 | case MULTIFILLCOLORS: |
||
1692 | /* |
||
9372 | schaersvoo | 1693 | @ multifillcolors color_name_1,color_name_2,...,color_name_8 |
9373 | schaersvoo | 1694 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9250 | schaersvoo | 1695 | @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be 'stroke_color' , 'fill_opacity' |
9213 | schaersvoo | 1696 | @ use these up to 6 colors for the draw primitives used by command 'multidraw obj_type_1,obj_type_2...obj_type_n |
1697 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
||
1698 | @ always use the same sequence as is used for 'multidraw' |
||
1699 | */ |
||
9332 | schaersvoo | 1700 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1701 | fprintf(js_include_file,"var multifillcolors = ["); |
1702 | while( ! done ){ |
||
1703 | temp = get_color(infile,1); |
||
1704 | fprintf(js_include_file,"\"%s\",",temp); |
||
1705 | } |
||
1706 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
1707 | break; |
||
1708 | case MULTIUSERINPUT: |
||
1709 | /* |
||
1710 | @ multiuserinput 0,1,1,0 |
||
1711 | @ meaning, when the command 'multidraw' is used <br />multidraw circles,points,lines,triangles<br />objects 'points' and 'lines' may additionally be 'drawn' by direct input (inputfields)<br/>all other objects must be drawn with a mouse |
||
9378 | schaersvoo | 1712 | @ in case of circle | circles a third inputfield for Radius (R) is added.<br />the radius must be in the x/y coordinate system (x-range) and <b>not</b> in pixels...students don't think in pixels.<br /><b>note</b>: R-values will not snap-to-grid |
9213 | schaersvoo | 1713 | @ in case of line(s) | segment(s) | arrow(s) the user should write <b>x1:y1</b> in the first inputfield and <b/>x2:y2</b> in the second.<br />These 'hints' are pre-filled into the input field.<br />other coordinate delimiters are ";" and "," e.g. <b>x1;y1</b> or <b>x1,y1</b>.<br />An error message (alert box) will popup when things are not correctly... |
1714 | @ in case of a triangle | poly3, three inputfields are provided. |
||
9383 | schaersvoo | 1715 | @ may be styled using command <a href="#inputstyle">"inputstyle"</a> |
9213 | schaersvoo | 1716 | @ an additional button 'stop drawing' may be used to combine userbased drawings with 'drag&drop' or 'onclick' elements |
9270 | schaersvoo | 1717 | @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword 'status' |
9373 | schaersvoo | 1718 | @ use before command <a href='#multidraw'>'multidraw'</a> |
9213 | schaersvoo | 1719 | @ always use the same sequence as is used for 'multidraw' |
1720 | */ |
||
1721 | /* simple rawmath and input check */ |
||
1722 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
1723 | temp = get_string(infile,1); |
||
1724 | temp = str_replace(temp,",","\",\""); |
||
1725 | fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp); |
||
1726 | break; |
||
1727 | case MULTIDRAW: |
||
1728 | /* |
||
9372 | schaersvoo | 1729 | @ multidraw obj_type_1,obj_type_2...obj_type_8 |
9385 | schaersvoo | 1730 | @ for single object user drawings you may also use command <a href="#userdraw">'userdraw'</a> |
9372 | schaersvoo | 1731 | @ implemented obj_types:<ul><li>point | points </li><li>circle | circles </li><li>line | lines </li><li>segment | segments </li><li>arrow | arrows <br />use command 'arrowhead int' for size (default value 8 pixels)</li><li>rect | rects </li><li>closedpoly<br />only one closedpolygon may be drawn.The number of 'corner points' is not preset (e.g. not limited,freestyle)<br />the polygone is closed when clicking on the first point again..(+/- 10px) </li><li>triangle | triangles<br />poly3, poly4, ... poly9 | polys3, polys4, ... polys9 <br />(<em>only 3 inputfields for poly*</em>)<br />parallelogram | parallelograms <br />(<em>no inputfields: parallelogram can be used for vector "contructions"</em>)</li></ul> |
9378 | schaersvoo | 1732 | @ additionally objects may be user labelled, using obj_type 'text'...<br >in this case allways a text input field and a (x:y) inputfield will be added to the page.<br />use commands 'fontfamily' and 'fontcolor' to adjust. (command 'multistrokeopacity' may be set to adjust text opacity)<br /><b>note</b>: no keyboard listeners are used |
9213 | schaersvoo | 1733 | @ it makes no sense using something like "multidraw point,points" ... |
9378 | schaersvoo | 1734 | @ <b>note</b>: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required) |
9338 | schaersvoo | 1735 | @ buttons for changing the obj_type (and incase of 'multiuserinput' , some inputfields and buttons) <br />will be present in the reserved div 'tooltip_div' and can be styled using command 'inputstyle some_css' |
9373 | schaersvoo | 1736 | @ the button label will be default the 'object primitive name' (like 'point', 'circles').<br />If you want a different label (e.g. an other language) ,use command 'multilabel'<br />for example in dutch: <br /><em>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</em><br />(see command <a href='#multilabel'>'multilabel'</a> for more details) |
9213 | schaersvoo | 1737 | @ multidraw is incompatible with command 'tooltip' |
10953 | bpr | 1738 | @ all 'multidraw' drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">'userdraw'</a>. |
9213 | schaersvoo | 1739 | @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's ) |
9406 | schaersvoo | 1740 | @ a local function read_canvas%d will read all userbased drawings.<br />The output is always a 9 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circlespoint_y+";"+multi_radius+"\\n"<br/>line 3 = segments_x+";"+segments_y+"\\n"<br/>line 4 = arrows_x+";"+arrows_y+"\\n"<br/>line 5 = lines_x+";"+lines_y+"\\n"<br/>line 6 = triangles_x+";"+triangles_y+"\\n"<br/>line 7 = rects_x +";"+rects_y+"\\n"<br />line 8 = closedpoly_x+";"+closedpoly_y+"\\n"<br/>line 9 = text_x+";"+text_y+";"+text"\\n"<br/>The x/y-data are in x/y-coordinate system and display precision may be set by a previous command 'precision 0 | 10 | 100 | 1000...'<br />In case of circles the radius is -for the time being- rounded to pixels<br /><b>use the wims "direct exec" tool to see the format of the reply</b> |
10953 | bpr | 1741 | @ <b>attention</b>: for command argument 'closedpoly' only one polygone can be drawn.<br />The last point (e.g. the point clicked near the first point) of the array is removed. |
9372 | schaersvoo | 1742 | @ <em>technical: all 8 'draw primitives' + 'text' will have their own -transparent- PNG bitmap canvas. <br />So for example there can be a points_canvas entirely separated from a line_canvas.<br />This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn)<br />This in contrast to many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element.</em> |
9213 | schaersvoo | 1743 | */ |
9332 | schaersvoo | 1744 | // if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
9213 | schaersvoo | 1745 | if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");} |
1746 | use_userdraw = TRUE; |
||
9338 | schaersvoo | 1747 | /* LET OP max 6 DRAW PRIMITIVES + TEXT */ |
9213 | schaersvoo | 1748 | temp = get_string(infile,1); |
1749 | temp = str_replace(temp,",","\",\""); |
||
9338 | schaersvoo | 1750 | /* if these are not set, set the default values for the 6 (!!!) draw_primitives + draw_text */ |
9213 | schaersvoo | 1751 | fprintf(js_include_file,"\ |
9372 | schaersvoo | 1752 | if( typeof multistrokecolors === 'undefined' ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
1753 | if( typeof multifillcolors === 'undefined' ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
||
1754 | if( typeof multistrokeopacity === 'undefined' ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
1755 | if( typeof multifillopacity === 'undefined' ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
1756 | if( typeof multilinewidth === 'undefined' ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
1757 | if( typeof multifill === 'undefined' ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
1758 | if( typeof multidash === 'undefined' ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
9329 | schaersvoo | 1759 | if( typeof multilabel === 'undefined' ){ var multilabel = [\"%s\",\"stop drawing\"];};\ |
9338 | schaersvoo | 1760 | if( typeof multiuserinput === 'undefined' ){ var multiuserinput= ['0','0','0','0','0','0','0','1'];};\ |
9329 | schaersvoo | 1761 | if( typeof multisnaptogrid == 'undefined'){var multisnaptogrid;if( x_use_snap_to_grid == 1 && y_use_snap_to_grid == 1){ multisnaptogrid = [1,1,1,1,1,1,1];}else{if( x_use_snap_to_grid == 1 ){ multisnaptogrid = [2,2,2,2,2,2,2];}else{if( y_use_snap_to_grid == 1 ){ multisnaptogrid = [3,3,3,3,3,3,3];}else{ multisnaptogrid = [0,0,0,0,0,0,0];};};};};\ |
9338 | schaersvoo | 1762 | var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';", |
9372 | schaersvoo | 1763 | stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color, |
1764 | fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color, |
||
1765 | stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity, |
||
1766 | fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity, |
||
1767 | line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width, |
||
1768 | use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled, |
||
1769 | use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed, |
||
9338 | schaersvoo | 1770 | temp,arrow_head,font_color,font_family); |
10953 | bpr | 1771 | |
9338 | schaersvoo | 1772 | if(strstr(temp,"text") != NULL){ |
1773 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
10953 | bpr | 1774 | } |
9338 | schaersvoo | 1775 | |
9383 | schaersvoo | 1776 | /* the canvasses range from 1000 ... 1008 */ |
9213 | schaersvoo | 1777 | add_js_multidraw(js_include_file,canvas_root_id,temp,input_style); |
1778 | reply_precision = precision; |
||
1779 | if( reply_format == 0){reply_format = 29;} |
||
1780 | reset();/* if command 'filled' / 'dashed' was given...reset all */ |
||
1781 | break; |
||
9289 | schaersvoo | 1782 | case RULER: |
1783 | /* |
||
1784 | @ ruler x,y,x-width ,y-height,passive_mode |
||
1785 | @ x,y are the initial location |
||
1786 | @ x-width , y-height are the ruler dimensions width & height in xy-coordinate system |
||
10953 | bpr | 1787 | @ the ruler scale is by definition the x-scale, set by command 'xrange'<br />for example: a ruler x-width of 6 will have a scale ranging from 0 to 6 |
9289 | schaersvoo | 1788 | @ passive_mode : use -1 to set the ruler interactive (eg mouse movement of ruler; drag & rotate)<br />use passive_mode = '0° - 360°' to set the ruler with a static angle of some value |
1789 | @ if combined with a protractor, use replyformat = 32 |
||
1790 | @ only one ruler allowed (for the time being) |
||
10953 | bpr | 1791 | @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'ruler' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize × ysize e.g. the same size as the visual canvas... </em> |
9289 | schaersvoo | 1792 | @ usage: first left click on the ruler will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence... |
1793 | */ |
||
1794 | for( i = 0;i < 5; i++ ){ |
||
1795 | switch(i){ |
||
1796 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
||
1797 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
1798 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
1799 | case 3: double_data[3] = get_real(infile,0);break; /* y-width */ |
||
1800 | case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */ |
||
1801 | decimals = find_number_of_digits(precision); |
||
1802 | add_js_ruler(js_include_file,canvas_root_id,double_data[0],double_data[1],double_data[2],double_data[3],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[0]); |
||
1803 | string_length = snprintf(NULL,0,";ruler%d();",canvas_root_id); |
||
1804 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1805 | snprintf(tmp_buffer,string_length,";ruler%d();",canvas_root_id); |
||
1806 | add_to_buffer(tmp_buffer); |
||
1807 | reply_precision = precision; |
||
1808 | /* no reply from ruler if non-interactive */ |
||
1809 | if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;} |
||
1810 | break; |
||
1811 | default: break; |
||
1812 | } |
||
1813 | } |
||
1814 | break; |
||
1815 | case PROTRACTOR: |
||
1816 | /* |
||
1817 | @ protractor x,y,x-width,type,passive_mode,value_display,use_scale |
||
1818 | @ x,y are the initial location |
||
1819 | @ x-width : give the width in x-coordinate system |
||
1820 | @ type = 1 : a triangle range 0 - 180<br />type = 2 : a circle shape 0 - 360<br />to do: degree scale optional |
||
1821 | @ passive_mode : use -1 to set the protractor interactive (mouse movement of protractor)<br />use passive_mode = '0° - 360°' to set the protractor with a static angle of some value |
||
1822 | @ value_display = 0 : no display of the angle value<br />value_display = 1 : value display in degrees<br />value_display = 2 : value display in radians<br />the display of the angle may cause some hickups in the smooth rotation of the protractor... |
||
1823 | @ use_scale = 1 : the protractor will have some scale values printed; use_scale=0 to disable |
||
1824 | @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor... |
||
1825 | @ commands <em>stroke_color | fill_color | linewidth | opacity | font_family</em> will determine the looks of the protractor. |
||
9354 | schaersvoo | 1826 | @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command 'precision' to set the reply precision. |
9289 | schaersvoo | 1827 | @ if combined with a ruler, use replyformat = 32 |
10953 | bpr | 1828 | @ command <em>snap_to_grid</em> may be used to assist the pupil at placing the protractor |
1829 | @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'protractor' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize × ysize e.g. the same size as the visual canvas... </em> |
||
9289 | schaersvoo | 1830 | @ only one protractor allowed (for the time being) |
1831 | @ usage: first left click on the protractor will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence... |
||
1832 | */ |
||
1833 | for( i = 0;i < 7; i++ ){ |
||
1834 | switch(i){ |
||
1835 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
||
1836 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
1837 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
1838 | case 3: int_data[0] = (int)(get_real(infile,0));break; /* type */ |
||
1839 | case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode */ |
||
1840 | case 5: int_data[2] = (int)(get_real(infile,0));break; /* value display */ |
||
1841 | case 6: int_data[3] = (int)(get_real(infile,1)); /* use scale */ |
||
1842 | decimals = find_number_of_digits(precision); |
||
1843 | if( int_data[2] > 0 ){ |
||
1844 | add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity); |
||
1845 | } |
||
1846 | add_js_protractor(js_include_file,canvas_root_id,int_data[0],double_data[0],double_data[1],double_data[2],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[2]+1,int_data[3],int_data[1]); |
||
10953 | bpr | 1847 | |
9289 | schaersvoo | 1848 | string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id); |
1849 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1850 | snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id); |
||
1851 | add_to_buffer(tmp_buffer); |
||
1852 | reply_precision = precision; |
||
1853 | /* no reply from protractor if non-interactive */ |
||
1854 | if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;} |
||
1855 | break; |
||
1856 | default: break; |
||
1857 | } |
||
1858 | } |
||
1859 | break; |
||
7614 | schaersvoo | 1860 | case USERDRAW: |
1861 | /* |
||
1862 | @ userdraw object_type,color |
||
9213 | schaersvoo | 1863 | @ only a single object_type is allowed. |
9385 | schaersvoo | 1864 | @ for multiple object user drawings use command <a href="#multidraw">'multidraw'</a> |
11006 | schaersvoo | 1865 | @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>demiline</li><li>demilines</li><li>segment</li><li>segments</li><li>polyline | brokenline </li><li>circle</li><li>circles</li><li>arrow</li><li>arrow2 (double arrow)</li><li>arrows</li><li>arrows2 (double arrows)</li><li>triangle</li><li>polygon</li><li>poly[3-9] (e.g poly3 ... poly7...poly9 </li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline | path</li><li>freehandlines | paths</li><li>clickfill : fill the clicked area with a color<br />the click may be set <a href="#snaptogrid">snapped...</a></ br>only one area can be selected <br />use command <a href="#canvastype">'canvastype'</a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)</li><li>text</li><li>arc</li><li>arcs</li><li>input<br/>place a single inputfield on 'canvas'<br />use commands 'inputstyle' for css styling: use command 'linewidth' for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield : placing inputfields on top of each other is not possible</li></ul> |
9378 | schaersvoo | 1866 | @ <b>note</b>: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required) |
1867 | @ <b>note</b>: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />while typing the background of every typed char will be lightblue..."backspace / delete / esc" will remove typed text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt()" : lightblue background will disappear<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" , a confirm will popup asking to delete the selected text.This text will be removed from the "userdraw_txt()" answer array.<br />Use commands 'fontsize' and 'fontfamily' to control the text appearance |
||
1868 | @ <b>note</b>: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
||
10975 | schaersvoo | 1869 | @ <b>note</b>: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse button (e.g. event.which != 1 : all buttons but left) |
7614 | schaersvoo | 1870 | @ use command "filled", "opacity int,int" and "fillcolor color" to trigger coloured filling of fillable objects |
8224 | bpr | 1871 | @ use command "dashed" and/or "dashtype int,int" to trigger dashing |
7614 | schaersvoo | 1872 | @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas(); |
1873 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very usefull...) |
||
10953 | bpr | 1874 | @ may be combined with keyword 'userinput_xy' |
10975 | schaersvoo | 1875 | @ <b>note</b>: when zooming / panning after a drawing, the drawing will NOT be zoomed / panned...this is a "design" flaw and not a feature <br />To avoid trouble do not use zooming / panning together width userdraw.!<br />use command <a href="#multidraw">multidraw</a> is this is a problem for you... |
7614 | schaersvoo | 1876 | */ |
1877 | if( use_userdraw == TRUE ){ /* only one object type may be drawn*/ |
||
9213 | schaersvoo | 1878 | canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this..."); |
7614 | schaersvoo | 1879 | } |
8074 | schaersvoo | 1880 | reply_precision = precision; |
7614 | schaersvoo | 1881 | use_userdraw = TRUE; |
11001 | schaersvoo | 1882 | fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();\ |
1883 | userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\ |
||
1884 | var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\ |
||
1885 | if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\ |
||
1886 | if(wims_status != \"done\"){\ |
||
11006 | schaersvoo | 1887 | canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\ |
1888 | canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\ |
||
1889 | canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
1890 | canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\ |
||
1891 | canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
11001 | schaersvoo | 1892 | }\n<!-- end userdraw mouse & touch events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]); |
7614 | schaersvoo | 1893 | draw_type = get_string_argument(infile,0); |
1894 | stroke_color = get_color(infile,1); |
||
1895 | if( strcmp(draw_type,"point") == 0 ){ |
||
1896 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1897 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 1898 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 1899 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1900 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1901 | add_input_circle(js_include_file,1,1); |
8815 | schaersvoo | 1902 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 1903 | } |
7614 | schaersvoo | 1904 | add_js_points(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1); |
1905 | } |
||
1906 | else |
||
1907 | if( strcmp(draw_type,"points") == 0 ){ |
||
1908 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1909 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 1910 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 1911 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1912 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1913 | add_input_circle(js_include_file,1,2); |
8815 | schaersvoo | 1914 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 1915 | } |
7614 | schaersvoo | 1916 | add_js_points(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1); |
1917 | } |
||
1918 | else |
||
1919 | if( strcmp(draw_type,"segment") == 0 ){ |
||
1920 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1921 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 1922 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 1923 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1924 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1925 | add_input_segment(js_include_file,1); |
8815 | schaersvoo | 1926 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 1927 | } |
7614 | schaersvoo | 1928 | add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
1929 | } |
||
1930 | else |
||
10975 | schaersvoo | 1931 | if( strcmp(draw_type,"polyline") == 0 || strcmp(draw_type,"brokenline") == 0 ){ |
7663 | schaersvoo | 1932 | if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;} |
7876 | schaersvoo | 1933 | if(reply_format == 0){reply_format = 23;} |
8071 | schaersvoo | 1934 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7780 | schaersvoo | 1935 | if( use_input_xy == 1 ){ |
1936 | add_input_polyline(js_include_file); |
||
8815 | schaersvoo | 1937 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7663 | schaersvoo | 1938 | } |
1939 | add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1940 | } |
||
1941 | else |
||
7614 | schaersvoo | 1942 | if( strcmp(draw_type,"segments") == 0 ){ |
1943 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1944 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 1945 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 1946 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1947 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1948 | add_input_segment(js_include_file,2); |
8815 | schaersvoo | 1949 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 1950 | } |
7614 | schaersvoo | 1951 | add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
1952 | } |
||
1953 | else |
||
1954 | if( strcmp(draw_type,"circle") == 0 ){ |
||
1955 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1956 | if(reply_format == 0){reply_format = 10;} |
7614 | schaersvoo | 1957 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
8071 | schaersvoo | 1958 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1959 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1960 | add_input_circle(js_include_file,2,1); |
8815 | schaersvoo | 1961 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 1962 | } |
7614 | schaersvoo | 1963 | add_js_circles(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
1964 | } |
||
1965 | else |
||
1966 | if( strcmp(draw_type,"circles") == 0 ){ |
||
1967 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1968 | if(reply_format == 0){reply_format = 10;} |
7614 | schaersvoo | 1969 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
1970 | add_js_circles(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 1971 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1972 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1973 | add_input_circle(js_include_file,2,2); |
8815 | schaersvoo | 1974 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 1975 | } |
7614 | schaersvoo | 1976 | } |
1977 | else |
||
1978 | if(strcmp(draw_type,"crosshair") == 0 ){ |
||
1979 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 1980 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 1981 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
1982 | add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
8071 | schaersvoo | 1983 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1984 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1985 | add_input_crosshair(js_include_file,1); |
8815 | schaersvoo | 1986 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 1987 | } |
7614 | schaersvoo | 1988 | } |
1989 | else |
||
1990 | if(strcmp(draw_type,"crosshairs") == 0 ){ |
||
1991 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 1992 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 1993 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
1994 | add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
8071 | schaersvoo | 1995 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1996 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1997 | add_input_crosshair(js_include_file,2); |
8815 | schaersvoo | 1998 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 1999 | } |
7614 | schaersvoo | 2000 | } |
2001 | else |
||
2002 | if(strcmp(draw_type,"freehandline") == 0 ){ |
||
2003 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 2004 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 2005 | add_js_paths(js_include_file,1,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2006 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2007 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2008 | } |
2009 | else |
||
2010 | if(strcmp(draw_type,"freehandlines") == 0 ){ |
||
2011 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 2012 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 2013 | add_js_paths(js_include_file,2,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2014 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2015 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2016 | } |
2017 | else |
||
2018 | if(strcmp(draw_type,"path") == 0 ){ |
||
2019 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 2020 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 2021 | add_js_paths(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2022 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2023 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2024 | } |
2025 | else |
||
2026 | if(strcmp(draw_type,"paths") == 0 ){ |
||
2027 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 2028 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 2029 | add_js_paths(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2030 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2031 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2032 | } |
2033 | else |
||
2034 | if(strcmp(draw_type,"arrows") == 0 ){ |
||
2035 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 2036 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 2037 | add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 2038 | if(use_input_xy == 1){ |
7654 | schaersvoo | 2039 | add_input_arrow(js_include_file,2); |
8815 | schaersvoo | 2040 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 2041 | } |
8071 | schaersvoo | 2042 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2043 | } |
2044 | else |
||
7874 | schaersvoo | 2045 | if(strcmp(draw_type,"arrows2") == 0 ){ |
2046 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 2047 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 2048 | add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 2049 | if(use_input_xy == 1){ |
7874 | schaersvoo | 2050 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 2051 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 2052 | } |
8071 | schaersvoo | 2053 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 2054 | } |
2055 | else |
||
2056 | if(strcmp(draw_type,"arrow2") == 0 ){ |
||
2057 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 2058 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 2059 | add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 2060 | if(use_input_xy == 1){ |
7874 | schaersvoo | 2061 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 2062 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 2063 | } |
8071 | schaersvoo | 2064 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 2065 | } |
2066 | else |
||
7614 | schaersvoo | 2067 | if(strcmp(draw_type,"arrow") == 0 ){ |
2068 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 2069 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 2070 | add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 2071 | if(use_input_xy == 1){ |
7654 | schaersvoo | 2072 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 2073 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 2074 | } |
8071 | schaersvoo | 2075 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2076 | } |
2077 | else |
||
2078 | if(strcmp(draw_type,"polygon") == 0){ |
||
2079 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 2080 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 2081 | add_js_poly(js_include_file,-1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
8071 | schaersvoo | 2082 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
2083 | if(use_input_xy == 2){ |
||
7780 | schaersvoo | 2084 | add_textarea_polygon(js_include_file); |
8815 | schaersvoo | 2085 | add_textarea_xy(js_include_file,canvas_root_id,input_style); |
7746 | schaersvoo | 2086 | } |
7614 | schaersvoo | 2087 | } |
8224 | bpr | 2088 | else |
7614 | schaersvoo | 2089 | if(strncmp(draw_type,"poly",4) == 0){ |
2090 | if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");} |
||
2091 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 2092 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 2093 | add_js_poly(js_include_file,(int) (draw_type[4]-'0'),draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2094 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2095 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2096 | } |
8224 | bpr | 2097 | else |
7614 | schaersvoo | 2098 | if(strcmp(draw_type,"triangle") == 0){ |
2099 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 2100 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 2101 | add_js_poly(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2102 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2103 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2104 | } |
8224 | bpr | 2105 | else |
7989 | schaersvoo | 2106 | if( strcmp(draw_type,"hline") == 0 ){ |
2107 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
2108 | if(reply_format == 0){reply_format = 11;} |
||
2109 | add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 2110 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
2111 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 2112 | } |
2113 | else |
||
2114 | if( strcmp(draw_type,"hlines") == 0 ){ |
||
2115 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
2116 | if(reply_format == 0){reply_format = 11;} |
||
2117 | add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 2118 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
2119 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 2120 | } |
2121 | else |
||
2122 | if( strcmp(draw_type,"vline") == 0 ){ |
||
2123 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
2124 | if(reply_format == 0){reply_format = 11;} |
||
2125 | add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 2126 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
2127 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 2128 | } |
2129 | else |
||
2130 | if( strcmp(draw_type,"vlines") == 0 ){ |
||
2131 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
2132 | if(reply_format == 0){reply_format = 11;} |
||
2133 | add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 2134 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
2135 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 2136 | } |
2137 | else |
||
7614 | schaersvoo | 2138 | if( strcmp(draw_type,"line") == 0 ){ |
2139 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
2140 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 2141 | if(reply_format == 0){reply_format = 11;} |
7614 | schaersvoo | 2142 | add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
7747 | schaersvoo | 2143 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 2144 | add_input_line(js_include_file,1); |
8815 | schaersvoo | 2145 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7747 | schaersvoo | 2146 | } |
8071 | schaersvoo | 2147 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2148 | } |
2149 | else |
||
2150 | if( strcmp(draw_type,"lines") == 0 ){ |
||
2151 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
2152 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 2153 | if(reply_format == 0){reply_format = 11;} |
7614 | schaersvoo | 2154 | add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
7747 | schaersvoo | 2155 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 2156 | add_input_line(js_include_file,2); |
8815 | schaersvoo | 2157 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7746 | schaersvoo | 2158 | } |
8071 | schaersvoo | 2159 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2160 | } |
2161 | else |
||
8362 | schaersvoo | 2162 | if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){ |
8244 | schaersvoo | 2163 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
2164 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
2165 | if(reply_format == 0){reply_format = 11;} |
||
2166 | add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
2167 | if( use_input_xy == 1 ){ |
||
2168 | add_input_demiline(js_include_file,2); |
||
8815 | schaersvoo | 2169 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 2170 | } |
2171 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
2172 | } |
||
2173 | else |
||
8362 | schaersvoo | 2174 | if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){ |
8244 | schaersvoo | 2175 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
2176 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
2177 | if(reply_format == 0){reply_format = 11;} |
||
2178 | add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
2179 | if( use_input_xy == 1 ){ |
||
2180 | add_input_demiline(js_include_file,1); |
||
8815 | schaersvoo | 2181 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 2182 | } |
2183 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
2184 | } |
||
2185 | else |
||
7614 | schaersvoo | 2186 | if( strcmp(draw_type,"rects") == 0){ |
2187 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
7876 | schaersvoo | 2188 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 2189 | add_js_rect(js_include_file,2,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2190 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2191 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2192 | } |
8224 | bpr | 2193 | else |
7614 | schaersvoo | 2194 | if( strcmp(draw_type,"roundrects") == 0){ |
2195 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
7876 | schaersvoo | 2196 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 2197 | add_js_rect(js_include_file,2,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2198 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2199 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2200 | } |
8224 | bpr | 2201 | else |
7614 | schaersvoo | 2202 | if( strcmp(draw_type,"rect") == 0){ |
2203 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
7876 | schaersvoo | 2204 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 2205 | add_js_rect(js_include_file,1,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2206 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2207 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2208 | } |
8224 | bpr | 2209 | else |
7614 | schaersvoo | 2210 | if( strcmp(draw_type,"roundrect") == 0){ |
2211 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
7876 | schaersvoo | 2212 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 2213 | add_js_rect(js_include_file,1,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 2214 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2215 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2216 | } |
2217 | else |
||
8083 | schaersvoo | 2218 | if( strcmp(draw_type,"arcs") == 0){ |
2219 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
2220 | if(reply_format == 0){reply_format = 25;} |
||
2221 | add_js_arc(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
2222 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
||
2223 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
2224 | } |
||
2225 | else |
||
8071 | schaersvoo | 2226 | if( strcmp(draw_type,"arc") == 0){ |
2227 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
8083 | schaersvoo | 2228 | if(reply_format == 0){reply_format = 25;} |
2229 | add_js_arc(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 2230 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
2231 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
2232 | } |
||
2233 | else |
||
7614 | schaersvoo | 2234 | if( strcmp(draw_type,"text") == 0){ |
8224 | bpr | 2235 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
7876 | schaersvoo | 2236 | if(reply_format == 0){reply_format = 17;} |
8071 | schaersvoo | 2237 | add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity); |
7652 | schaersvoo | 2238 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 2239 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 2240 | } |
8116 | schaersvoo | 2241 | else |
2242 | if( strcmp(draw_type,"inputs") == 0){ |
||
8224 | bpr | 2243 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 2244 | if(reply_format == 0){reply_format = 27;} |
8116 | schaersvoo | 2245 | add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width); |
2246 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
||
2247 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
2248 | } |
||
2249 | else |
||
2250 | if( strcmp(draw_type,"input") == 0){ |
||
8224 | bpr | 2251 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 2252 | if(reply_format == 0){reply_format = 27;} |
8116 | schaersvoo | 2253 | add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width); |
2254 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
||
2255 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
2256 | } |
||
8193 | schaersvoo | 2257 | else |
11005 | schaersvoo | 2258 | if( strcmp(draw_type,"clickfill") == 0){ |
2259 | decimals = find_number_of_digits(precision); |
||
2260 | if(reply_format == 0){reply_format = 22;} |
||
2261 | add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215)); |
||
2262 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
2263 | js_function[DRAW_FILLTOBORDER] = 1; |
||
11006 | schaersvoo | 2264 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
11005 | schaersvoo | 2265 | } |
2266 | } |
||
2267 | else |
||
7614 | schaersvoo | 2268 | { |
2269 | canvas_error("unknown drawtype or typo? "); |
||
2270 | } |
||
2271 | reset(); |
||
2272 | break; |
||
9213 | schaersvoo | 2273 | case SNAPTOFUNCTION: |
2274 | /* |
||
2275 | @ snaptofunction some_function_in_x,some_funtion_in_y |
||
9382 | schaersvoo | 2276 | @ alternative : snaptofun some_function_in_x,some_funtion_in_y |
9213 | schaersvoo | 2277 | @ the next object will snap to the calculated values |
2278 | @ if you want only modification of y-values,just use: snaptofunction x,5*sin(1/y) |
||
2279 | @ if you want only modification of x-values,just use: snaptofunction 5*sin(1/x),y |
||
2280 | @ for now only one instance of 'snaptofunction' is allowed |
||
2281 | @ use rwamath on your functions: no validity checking is done by wims ! |
||
2282 | @ example:<br />....<br />snaptofunction 5*(cos(x),4*sin(y)<br />linewidth 3<br />userdraw points,blue<br />....<br /> |
||
2283 | @ example : switching x and y coordinates?<br />snaptofunction y,x |
||
2284 | */ |
||
2285 | temp = get_string_argument(infile,0); |
||
2286 | fprintf(js_include_file,"\nuse_snap_to_points = 2;"); |
||
2287 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
10953 | bpr | 2288 | add_to_js_math(js_include_file); use_js_math = TRUE; |
9213 | schaersvoo | 2289 | } |
2290 | fprintf(js_include_file,"var snap_fun = {x:to_js_math('%s'),y:to_js_math('%s')};function snap_to_fun(px,py){ var x = px2x(px); var y = px2y(py); return [ x2px(eval(snap_fun.x)) , y2px(eval(snap_fun.y)) ];};",temp,get_string(infile,1)); |
||
2291 | break; |
||
8386 | schaersvoo | 2292 | case SNAPTOPOINTS: |
2293 | /* |
||
2294 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
||
2295 | @ a userdraw object will snap to these points. |
||
8815 | schaersvoo | 2296 | @ the array size (e.g. the number of points) of command 'snaptopoints' is limited by constant MAX_INT (canvasdraw.h) |
8386 | schaersvoo | 2297 | @ a draggable object (use command "drag x|y|xy") will snap to the clossed of these points when dragged (mouseup) |
10953 | bpr | 2298 | @ other options: use keyword "snaptogrid", "xsnaptogrid" or "ysnaptogrid" |
8386 | schaersvoo | 2299 | */ |
2300 | i = 0; |
||
2301 | while( ! done ){ /* get next item until EOL*/ |
||
2302 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2303 | if(i%2 == 0 ){ |
||
2304 | double_data[i] = get_real(infile,0); /* x */ |
||
2305 | } |
||
2306 | else |
||
2307 | { |
||
2308 | double_data[i] = get_real(infile,1); /* y */ |
||
2309 | } |
||
2310 | i++; |
||
2311 | } |
||
2312 | decimals = find_number_of_digits(precision); |
||
2313 | fprintf(js_include_file,"\nuse_snap_to_points = 1;\nfunction find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;for(var p = 0 ; p < %d ; p++){chk = distance(x,y,X[p],Y[p]);if( chk < diff ){ diff = chk; idx = p;};};return idx;};\nfunction snap_to_points(x,y){x = px2x(x); y = px2y(y);var points = [%s];var xpoints = points[0];var ypoints = points[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};\n",(int) (0.5*i),double_xy2js_array(double_data,i,decimals)); |
||
2314 | break; |
||
2315 | |||
2316 | case SNAPTOGRID: |
||
2317 | /* |
||
2318 | @ snaptogrid |
||
2319 | @ keyword (no arguments required) |
||
2320 | @ a draggable object (use command "drag x|y|xy") will snap to the given grid when dragged (mouseup) |
||
2321 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
||
2322 | @ if no grid is defined ,points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1) |
||
2323 | @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0. |
||
2324 | @ if xminor / yminor is defined,(use keyword 'axis' to activate the minor steps) the drawing will snap to xminor and yminor<br />use only even dividers in x/y-minor...for example<br />snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
||
2325 | */ |
||
2326 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;"); |
||
2327 | break; |
||
2328 | |||
2329 | case XSNAPTOGRID: |
||
2330 | /* |
||
2331 | @ xsnaptogrid |
||
10953 | bpr | 2332 | @ keyword (no arguments required) |
8386 | schaersvoo | 2333 | @ a draggable object (use command "drag x|y|xy") will snap to the given x-grid values when dragged (mouseup) |
2334 | @ in case of userdraw the drawn points will snap to xmajor grid |
||
2335 | @ if no grid is defined ,points will snap to every integer xrange value. (eg snap_x=1) |
||
2336 | @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0. |
||
2337 | @ if xminor is defined (use keyword 'axis' to activate xminor), the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br />xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
||
2338 | */ |
||
2339 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;"); |
||
2340 | break; |
||
2341 | |||
2342 | case YSNAPTOGRID: |
||
2343 | /* |
||
2344 | @ ysnaptogrid |
||
10953 | bpr | 2345 | @ keyword (no arguments required) |
8386 | schaersvoo | 2346 | @ a draggable object (use command "drag x|y|xy") will snap to the given y-grid values when dragged (mouseup) |
2347 | @ in case of userdraw the drawn points will snap to ymajor grid |
||
2348 | @ if no grid is defined ,points will snap to every integer yrange value. (eg snap_y=1) |
||
2349 | @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0. |
||
2350 | @ if yminor is defined (use keyword 'axis' to activate yminor), the drawing will snap to yminor <br />use only even dividers in y-minor...for example<br />ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
||
2351 | */ |
||
2352 | fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;"); |
||
2353 | break; |
||
2354 | |||
2355 | case USERINPUT: |
||
2356 | /* |
||
2357 | @ userinput function | textarea | inputfield |
||
9382 | schaersvoo | 2358 | @ alternative : userinput_function |
2359 | @ alternative : userinput_textarea |
||
2360 | @ alternative : userinput_xy |
||
8386 | schaersvoo | 2361 | @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type' |
2362 | @ function may be used any time (e.g. without userdraw) |
||
8815 | schaersvoo | 2363 | @ multiple 'userinput function' commands may be used. |
8386 | schaersvoo | 2364 | @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)=" |
2365 | @ use command 'strokecolor some_color' to adjust the plot / functionlabel color |
||
8815 | schaersvoo | 2366 | @ use command 'inputstyle some_css' to adjust the inputfields |
2367 | @ use command 'fontsize int' to adjust the label fonts. (default 12px) |
||
2368 | @ the user input for the function will be corrected by a simple 'rawmath' implementation...<br />an error message will be shown if javascript can not interpret the user input |
||
8386 | schaersvoo | 2369 | */ |
2370 | temp = get_string_argument(infile,1); |
||
2371 | if(strstr(temp,"function") != 0 || strstr(temp,"curve") != 0 || strstr(temp,"plot") != 0 ){ |
||
2372 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
2373 | add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */ |
||
2374 | js_function[DRAW_JSFUNCTION] = 1; |
||
2375 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 2376 | add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 2377 | input_cnt++; |
2378 | } |
||
10953 | bpr | 2379 | else |
8386 | schaersvoo | 2380 | { |
2381 | /* no need to add DRAW_JSFUNCTION , just call it with the parameters */ |
||
8815 | schaersvoo | 2382 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 2383 | input_cnt++; |
2384 | } |
||
2385 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
2386 | add_to_js_math(js_include_file); |
||
2387 | use_js_math = TRUE; |
||
2388 | } |
||
2389 | if( use_js_plot == FALSE){ |
||
2390 | use_js_plot = TRUE; |
||
2391 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
2392 | } |
||
2393 | } |
||
2394 | else |
||
2395 | { |
||
2396 | if(strstr(temp,"inputfield") != 0 ){ |
||
2397 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
2398 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2399 | use_input_xy = 1; |
||
2400 | } |
||
2401 | else |
||
2402 | { |
||
2403 | if(strstr(temp,"textarea") != 0 ){ |
||
2404 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
2405 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2406 | use_input_xy = 2; |
||
2407 | } |
||
2408 | else |
||
2409 | { |
||
2410 | canvas_error("userinput argument may be \"function,inputfield,textarea\""); |
||
2411 | } |
||
2412 | } |
||
2413 | } |
||
2414 | break; |
||
2415 | |||
2416 | case USERTEXTAREA_XY: |
||
2417 | /* |
||
2418 | @ usertextarea_xy |
||
9372 | schaersvoo | 2419 | @ keyword (no arguments required) |
8386 | schaersvoo | 2420 | @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being... |
2421 | @ if set two textareas are added to the document<br />(one for x-values , one for y-values) |
||
2422 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
||
2423 | @ user drawings will not zoom on zooming (or pan on panning) |
||
8815 | schaersvoo | 2424 | @ use command 'inputstyle some_css' to adjust the inputarea. |
2425 | @ use command 'fontsize int' to adjust the text labels (if needed) |
||
8386 | schaersvoo | 2426 | */ |
2427 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
2428 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2429 | use_input_xy = 2; |
||
2430 | break; |
||
2431 | |||
2432 | case USERINPUT_XY: |
||
2433 | /* |
||
2434 | @ userinput_xy |
||
9372 | schaersvoo | 2435 | @ keyword (no arguments required) |
8386 | schaersvoo | 2436 | @ to be used in combination with command "userdraw object_type,color" |
2437 | @ if set two (or three) input fields are added to the document<br />(one for x-values , one for y-values and in case of drawing circle one for radius-values) |
||
2438 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
||
2439 | @ math input is allowed (e.g something like: 1+3,2*6,1/3,sqrt(3), sin(pi/4),10^-2,log(2)...)<br />eval function is 'protected' against code injection. |
||
9378 | schaersvoo | 2440 | @ can <b>not</b> be combined with command "intooltip tiptext" <br /><b>note</b>: the 'tooltip div element' is used for placing inputfields |
8386 | schaersvoo | 2441 | @ user drawings will not zoom on zooming (or pan on panning) |
8815 | schaersvoo | 2442 | @ use command 'inputstyle some_css' to adjust the inputarea. |
2443 | @ use command 'fontsize int' to adjust the text labels (if needed) |
||
8386 | schaersvoo | 2444 | */ |
2445 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
2446 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
2447 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2448 | use_input_xy = 1; |
||
2449 | break; |
||
2450 | |||
2451 | case FUNCTION_LABEL: |
||
2452 | /* |
||
2453 | @ functionlabel 'some string' |
||
2454 | @ default value "f(x)=" |
||
2455 | @ no mathml allowed (just ascii string) |
||
8815 | schaersvoo | 2456 | @ use command 'fontsize int' to adjust the size |
2457 | @ use command 'strokecolor colorname' to adjust the labels (individually, if needed) |
||
8386 | schaersvoo | 2458 | @ if needed, use before every command 'userinput function | inputfield | textarea' |
2459 | */ |
||
2460 | function_label = get_string_argument(infile,1); |
||
2461 | break; |
||
2462 | |||
2463 | case USERINPUT_FUNCTION: |
||
2464 | /* |
||
2465 | @ userinput_function |
||
9372 | schaersvoo | 2466 | @ keyword (no arguments required) |
8386 | schaersvoo | 2467 | @ if set , a inputfield will be added to the page |
2468 | @ repeat keyword for more function input fields |
||
2469 | @ the userinput value will be plotted in the canvas |
||
10953 | bpr | 2470 | @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, its id is canvas_input0 |
8386 | schaersvoo | 2471 | @ use before this command 'userinput_function',<br />commands like 'inputstyle some_css' , 'xlabel some_description' , 'opacity int,int' , 'linewidth int' , 'dashed' and 'dashtype int,int' to modify |
8815 | schaersvoo | 2472 | @ fontsize can be set using command 'fontsize int' |
8386 | schaersvoo | 2473 | @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield |
2474 | */ |
||
2475 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
2476 | js_function[DRAW_JSFUNCTION] = 1; |
||
2477 | add_rawmath(js_include_file); |
||
2478 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 2479 | add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 2480 | input_cnt++; |
2481 | } |
||
10953 | bpr | 2482 | else |
8386 | schaersvoo | 2483 | { |
2484 | /* no need to add DRAW_JSFUNCTION , just call it with the parameters */ |
||
8815 | schaersvoo | 2485 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 2486 | input_cnt++; |
2487 | } |
||
2488 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
2489 | add_to_js_math(js_include_file); |
||
2490 | use_js_math = TRUE; |
||
2491 | } |
||
2492 | if( use_js_plot == FALSE){ |
||
2493 | use_js_plot = TRUE; |
||
2494 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
2495 | } |
||
2496 | break; |
||
2497 | |||
7614 | schaersvoo | 2498 | case PLOTSTEPS: |
2499 | /* |
||
2500 | @ plotsteps a_number |
||
2501 | @ default 150 |
||
10953 | bpr | 2502 | @ only used for commands <a href="#curve">"curve / plot"</a> and <a href="#levelcurve">"levelcurve"</a> |
7614 | schaersvoo | 2503 | @ use with care ! |
2504 | */ |
||
2505 | plot_steps = (int) (get_real(infile,1)); |
||
2506 | break; |
||
2507 | case FONTSIZE: |
||
2508 | /* |
||
9385 | schaersvoo | 2509 | @ fontsize font_size |
2510 | @ default value 12 |
||
9427 | schaersvoo | 2511 | @ <b>note</b>:for some macro's (like grid | legend | xaxistext | xlabel etc) sometimes command <a href="#fontfamily">"fontfamily"</a> can be used for some specific font-setting<br />this is however not always very straight forward...so just try and see what happens |
7614 | schaersvoo | 2512 | */ |
2513 | font_size = (int) (get_real(infile,1)); |
||
2514 | break; |
||
2515 | case FONTCOLOR: |
||
2516 | /* |
||
9385 | schaersvoo | 2517 | @ fontcolor color |
2518 | @ color: hexcolor or colorname |
||
2519 | @ default: black |
||
2520 | @ example usage: x/y-axis text |
||
7614 | schaersvoo | 2521 | */ |
2522 | font_color = get_color(infile,1); |
||
2523 | break; |
||
8386 | schaersvoo | 2524 | case JSCURVE: |
7614 | schaersvoo | 2525 | /* |
9385 | schaersvoo | 2526 | @ jscurve color,formula(x) |
9462 | schaersvoo | 2527 | @ alternative : jsplot color,formula(x) |
9385 | schaersvoo | 2528 | @ your function will be plotted by the javascript engine of the client browser. |
2529 | @ use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e |
||
2530 | @ use parenthesis and rawmath : use 2*x instead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors... |
||
2531 | @ <b>attention</b> : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot ! |
||
2532 | @ no validity check is done by wims. |
||
2533 | @ zooming & panning are implemented :<br />use command 'zoom color' for mouse driven zooming<br />or use keyword 'setlimits' for inputfields setting xmin/xmax, ymin/ymax |
||
2534 | @ use command 'trace_jscurve formula(x)` for tracing |
||
2535 | @ use command 'jsmath formula(x)` for calculating and displaying indiviual points on the curve |
||
9406 | schaersvoo | 2536 | @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet) |
9385 | schaersvoo | 2537 | @ commands plotjump / plotstep are not active for 'jscurve' |
7614 | schaersvoo | 2538 | */ |
8386 | schaersvoo | 2539 | stroke_color = get_color(infile,0); |
2540 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
2541 | add_to_js_math(js_include_file); |
||
2542 | use_js_math = TRUE; |
||
2543 | } |
||
2544 | if( use_js_plot == FALSE){ |
||
2545 | use_js_plot = TRUE; |
||
2546 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
2547 | } |
||
2548 | temp = get_string_argument(infile,1); |
||
11006 | schaersvoo | 2549 | string_length = snprintf(NULL,0, "jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
8386 | schaersvoo | 2550 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11006 | schaersvoo | 2551 | snprintf(tmp_buffer,string_length,"jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
8386 | schaersvoo | 2552 | add_to_buffer(tmp_buffer); |
11006 | schaersvoo | 2553 | jsplot_cnt++; |
2554 | /* we need to create multiple canvasses, so we may zoom and pan ?? */ |
||
8386 | schaersvoo | 2555 | break; |
2556 | |||
2557 | case CURVE: |
||
2558 | /* |
||
9385 | schaersvoo | 2559 | @ curve color,formula(x) |
9462 | schaersvoo | 2560 | @ alernative : plot color,formula(x) |
9385 | schaersvoo | 2561 | @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot (trange -pi,pi)<br />curve color,formula1(t),formula2(t) |
2562 | @ use command <a href="#precision">"precision" </a>to ncrease the number of digits of the plotted points |
||
2563 | @ use command <a href="#plotsteps">"plotsteps"</a> to increase / decrease the amount of plotted points (default 150) |
||
9406 | schaersvoo | 2564 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
9462 | schaersvoo | 2565 | @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">"jsplot"'</a><br />(command "curve" will only calculate points within the xrange) |
8386 | schaersvoo | 2566 | */ |
2567 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
||
2568 | use_parametric = FALSE; |
||
2569 | stroke_color = get_color(infile,0); |
||
2570 | char *fun1 = get_string_argument(infile,0); |
||
2571 | char *fun2 = get_string_argument(infile,1); |
||
2572 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
9907 | schaersvoo | 2573 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,animation_type,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8386 | schaersvoo | 2574 | } |
2575 | else |
||
2576 | { |
||
2577 | stroke_color = get_color(infile,0); |
||
2578 | char *fun1 = get_string_argument(infile,1); |
||
2579 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
9907 | schaersvoo | 2580 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,animation_type,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8386 | schaersvoo | 2581 | } |
2582 | if(onclick > 0){click_cnt++;} |
||
2583 | /* click_cnt++; */ |
||
2584 | reset(); |
||
7614 | schaersvoo | 2585 | break; |
8386 | schaersvoo | 2586 | |
7788 | schaersvoo | 2587 | case LEVELCURVE: |
2588 | /* |
||
9385 | schaersvoo | 2589 | @ levelcurve color,expression in x/y,l1,l2,... |
2590 | @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n |
||
2591 | @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...) |
||
2592 | @ every individual level curve may be set 'onclick / drag xy' <br />e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier |
||
2593 | @ note : the arrays for holding the javascript data are limited in size |
||
2594 | @ note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...) |
||
7788 | schaersvoo | 2595 | */ |
7792 | schaersvoo | 2596 | fill_color = get_color(infile,0); |
7788 | schaersvoo | 2597 | char *fun1 = get_string_argument(infile,0); |
2598 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
2599 | i = 0; |
||
2600 | done = FALSE; |
||
2601 | while( !done ){ |
||
2602 | double_data[i] = get_real(infile,1); |
||
2603 | i++; |
||
2604 | } |
||
2605 | for(c = 0 ; c < i; c++){ |
||
9907 | schaersvoo | 2606 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 2607 | if(onclick > 0){click_cnt++;} |
2608 | /* click_cnt++; */ |
||
7788 | schaersvoo | 2609 | } |
2610 | reset(); |
||
2611 | break; |
||
8386 | schaersvoo | 2612 | |
2613 | case BEZIER: |
||
2614 | /* |
||
9385 | schaersvoo | 2615 | @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end |
2616 | @ draw a bezier curve between points, starting from (x_start:y_start) |
||
2617 | @ can <b>not</b> be dragged or set onclick |
||
8386 | schaersvoo | 2618 | */ |
2619 | if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;} |
||
2620 | decimals = find_number_of_digits(precision); |
||
2621 | for(i = 0 ; i < 9; i++){ |
||
2622 | switch(i){ |
||
2623 | case 0: stroke_color = get_color(infile,0);break; |
||
2624 | case 1: double_data[0] = get_real(infile,0);break;/* start x */ |
||
2625 | case 2: double_data[1] = get_real(infile,0);break;/* start y */ |
||
2626 | case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */ |
||
2627 | case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */ |
||
2628 | case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */ |
||
2629 | case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */ |
||
2630 | case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */ |
||
2631 | case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */ |
||
2632 | string_length = snprintf(NULL,0,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix); |
||
2633 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2634 | snprintf(tmp_buffer,string_length,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix); |
||
2635 | add_to_buffer(tmp_buffer); |
||
2636 | break; |
||
2637 | default: break; |
||
2638 | } |
||
2639 | } |
||
2640 | reset(); |
||
2641 | break; |
||
2642 | |||
7858 | schaersvoo | 2643 | case TRACE_JSCURVE: |
7823 | schaersvoo | 2644 | /* |
9385 | schaersvoo | 2645 | @ trace_jscurve some_math_function |
2646 | @ will use a crosshair to trace the jsmath curve |
||
2647 | @ two inputfields will display the current x/y-values (numerical evaluation by javascript) |
||
2648 | @ default labels 'x' and 'y'<br />use commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' to customize the labels for the input fields |
||
2649 | @ use commands fontsize and inputstyle to format the fonts for labels and inputfields. |
||
2650 | @ use commands linewidth,strokecolor,crosshairsize to adjust the corsshair. |
||
2651 | @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors... |
||
2652 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
||
7823 | schaersvoo | 2653 | */ |
2654 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7833 | schaersvoo | 2655 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
7858 | schaersvoo | 2656 | if( use_js_math == FALSE){ |
2657 | add_to_js_math(js_include_file); |
||
2658 | use_js_math = TRUE; |
||
2659 | } |
||
8815 | schaersvoo | 2660 | add_trace_js_mouse(js_include_file,TRACE_CANVAS,canvas_root_id,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size,input_style); |
7823 | schaersvoo | 2661 | break; |
8386 | schaersvoo | 2662 | |
7823 | schaersvoo | 2663 | case JSMATH: |
2664 | /* |
||
9385 | schaersvoo | 2665 | @ jsmath some_math_function |
2666 | @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates. |
||
2667 | @ default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields |
||
2668 | @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels 'x' and 'y' |
||
2669 | @ example: jsmath sin(x^2) |
||
2670 | @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors... |
||
2671 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
||
7823 | schaersvoo | 2672 | */ |
2673 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7858 | schaersvoo | 2674 | if( use_js_math == FALSE){ |
2675 | add_to_js_math(js_include_file); |
||
2676 | use_js_math = TRUE; |
||
2677 | } |
||
8815 | schaersvoo | 2678 | add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style); |
7823 | schaersvoo | 2679 | break; |
7858 | schaersvoo | 2680 | |
8386 | schaersvoo | 2681 | |
7614 | schaersvoo | 2682 | case FLY_TEXT: |
2683 | /* |
||
2684 | @ text fontcolor,x,y,font,text_string |
||
2685 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
8224 | bpr | 2686 | @ use command 'fontsize' to increase base fontsize for these keywords |
7614 | schaersvoo | 2687 | @ may be set "onclick" or "drag xy" |
2688 | @ backwards compatible with flydraw |
||
2689 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
7874 | schaersvoo | 2690 | @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element |
2691 | @ Avoid mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
||
7614 | schaersvoo | 2692 | */ |
2693 | for(i = 0; i < 5 ;i++){ |
||
2694 | switch(i){ |
||
2695 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
2696 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
2697 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
2698 | case 3: fly_font = get_string_argument(infile,0); |
||
2699 | if(strcmp(fly_font,"giant") == 0){ |
||
8388 | schaersvoo | 2700 | fly_font_size = (int)(font_size + 24); |
7614 | schaersvoo | 2701 | } |
2702 | else |
||
2703 | { |
||
2704 | if(strcmp(fly_font,"huge") == 0){ |
||
8388 | schaersvoo | 2705 | fly_font_size = (int)(font_size + 14); |
7614 | schaersvoo | 2706 | } |
2707 | else |
||
2708 | { |
||
2709 | if(strcmp(fly_font,"large") == 0){ |
||
8388 | schaersvoo | 2710 | fly_font_size = (int)(font_size + 6); |
7614 | schaersvoo | 2711 | } |
2712 | else |
||
2713 | { |
||
2714 | if(strcmp(fly_font,"small") == 0){ |
||
8388 | schaersvoo | 2715 | fly_font_size = (int)(font_size - 4); |
2716 | if(fly_font_size<0){fly_font_size = 8;} |
||
7614 | schaersvoo | 2717 | } |
2718 | } |
||
2719 | } |
||
2720 | } |
||
10953 | bpr | 2721 | break; |
8224 | bpr | 2722 | case 4: |
7614 | schaersvoo | 2723 | temp = get_string_argument(infile,1); |
2724 | decimals = find_number_of_digits(precision); |
||
9908 | schaersvoo | 2725 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,fly_font_size,"null",use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 2726 | if(onclick > 0){click_cnt++;} |
10953 | bpr | 2727 | /* click_cnt++;*/ |
8379 | schaersvoo | 2728 | reset(); |
2729 | break; |
||
7614 | schaersvoo | 2730 | default:break; |
2731 | } |
||
2732 | } |
||
2733 | break; |
||
2734 | case FLY_TEXTUP: |
||
2735 | /* |
||
2736 | @ textup fontcolor,x,y,font,text_string |
||
2737 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
||
2738 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
8224 | bpr | 2739 | @ use command 'fontsize' to increase base fontsize for the keywords |
7614 | schaersvoo | 2740 | @ backwards compatible with flydraw |
2741 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
2742 | @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element |
||
7874 | schaersvoo | 2743 | @ Avoid mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
7614 | schaersvoo | 2744 | */ |
8224 | bpr | 2745 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
7614 | schaersvoo | 2746 | for(i = 0; i<5 ;i++){ |
2747 | switch(i){ |
||
2748 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
2749 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
2750 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
2751 | case 3: fly_font = get_string_argument(infile,0); |
||
2752 | if(strcmp(fly_font,"giant") == 0){ |
||
8388 | schaersvoo | 2753 | fly_font_size = (int)(font_size + 24); |
7614 | schaersvoo | 2754 | } |
2755 | else |
||
2756 | { |
||
2757 | if(strcmp(fly_font,"huge") == 0){ |
||
8388 | schaersvoo | 2758 | fly_font_size = (int)(font_size + 14); |
7614 | schaersvoo | 2759 | } |
2760 | else |
||
2761 | { |
||
2762 | if(strcmp(fly_font,"large") == 0){ |
||
8388 | schaersvoo | 2763 | fly_font_size = (int)(font_size + 6); |
7614 | schaersvoo | 2764 | } |
2765 | else |
||
2766 | { |
||
2767 | if(strcmp(fly_font,"small") == 0){ |
||
8388 | schaersvoo | 2768 | fly_font_size = (int)(font_size - 4); |
2769 | if(fly_font_size<0){fly_font_size = 8;} |
||
7614 | schaersvoo | 2770 | } |
2771 | } |
||
2772 | } |
||
2773 | } |
||
8388 | schaersvoo | 2774 | break; |
8224 | bpr | 2775 | case 4: |
7614 | schaersvoo | 2776 | decimals = find_number_of_digits(precision); |
2777 | temp = get_string_argument(infile,1); |
||
8388 | schaersvoo | 2778 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 2779 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8388 | schaersvoo | 2780 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 2781 | add_to_buffer(tmp_buffer); |
2782 | break; |
||
2783 | default:break; |
||
2784 | } |
||
2785 | } |
||
2786 | reset(); |
||
2787 | break; |
||
2788 | case FONTFAMILY: |
||
2789 | /* |
||
2790 | @ fontfamily font_description |
||
2791 | @ set the font family; for browsers that support it |
||
2792 | @ font_description: Ariel ,Courier, Helvetica etc |
||
2793 | @ in case commands<br /> 'string color,x,y,the string'<br /> 'stringup color,x,y,rotation,the string'<br />fontfamily can be something like:<br />italic 34px Ariel |
||
2794 | @ use correct syntax : 'font style' 'font size'px 'fontfamily' |
||
2795 | */ |
||
2796 | font_family = get_string(infile,1); |
||
2797 | break; |
||
2798 | case STRINGUP: |
||
8224 | bpr | 2799 | /* |
2800 | @ stringup color,x,y,rotation_degrees,the text string |
||
7614 | schaersvoo | 2801 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
2802 | @ unicode supported: stringup red,0,0,45,\\u2232 |
||
2803 | @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change |
||
2804 | |||
2805 | */ |
||
2806 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} /* can not be added to shape library : rotate / mouse issues */ |
||
2807 | for(i=0;i<6;i++){ |
||
2808 | switch(i){ |
||
2809 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
2810 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
2811 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
2812 | case 3: double_data[0] = get_real(infile,0);break;/* rotation */ |
||
2813 | case 4: decimals = find_number_of_digits(precision); |
||
2814 | temp = get_string_argument(infile,1); |
||
8071 | schaersvoo | 2815 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 2816 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 2817 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 2818 | add_to_buffer(tmp_buffer); |
2819 | break; |
||
2820 | default:break; |
||
2821 | } |
||
2822 | } |
||
2823 | reset(); |
||
2824 | break; |
||
2825 | case STRING: |
||
8224 | bpr | 2826 | /* |
7614 | schaersvoo | 2827 | @ string color,x,y,the text string |
2828 | @ may be set "onclick" or "drag xy" |
||
2829 | @ unicode supported: string red,0,0,\\u2232 |
||
8224 | bpr | 2830 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
7614 | schaersvoo | 2831 | */ |
2832 | for(i=0;i<5;i++){ |
||
2833 | switch(i){ |
||
2834 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
2835 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
2836 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
2837 | case 3: decimals = find_number_of_digits(precision); |
||
2838 | temp = get_string_argument(infile,1); |
||
2839 | decimals = find_number_of_digits(precision); |
||
9907 | schaersvoo | 2840 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center); |
8379 | schaersvoo | 2841 | if(onclick > 0){click_cnt++;} |
2842 | /* click_cnt++;*/ |
||
2843 | reset(); |
||
2844 | break; |
||
7614 | schaersvoo | 2845 | default:break; |
2846 | } |
||
2847 | } |
||
2848 | break; |
||
7983 | schaersvoo | 2849 | case CENTERSTRING: |
8224 | bpr | 2850 | /* |
7983 | schaersvoo | 2851 | @ centerstring color,y-value,the text string |
7984 | schaersvoo | 2852 | @ title color,y-value,the text string |
7983 | schaersvoo | 2853 | @ draw a string centered on the canvas at y = y-value |
9383 | schaersvoo | 2854 | @ can not be set "onclick" or "drag xy" (...) |
7983 | schaersvoo | 2855 | @ unicode supported: centerstring red,5,\\u2232 |
8224 | bpr | 2856 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
7983 | schaersvoo | 2857 | */ |
2858 | if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;} |
||
2859 | for(i=0;i<3;i++){ |
||
2860 | switch(i){ |
||
2861 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
2862 | case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/ |
||
2863 | case 2: temp = get_string_argument(infile,1); |
||
2864 | /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */ |
||
2865 | decimals = find_number_of_digits(precision); |
||
2866 | string_length = snprintf(NULL,0, |
||
2867 | "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
||
2868 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2869 | snprintf(tmp_buffer,string_length,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
||
2870 | add_to_buffer(tmp_buffer); |
||
2871 | break; |
||
2872 | default:break; |
||
2873 | } |
||
2874 | } |
||
2875 | break; |
||
7614 | schaersvoo | 2876 | case MATHML: |
2877 | /* |
||
2878 | @ mathml x1,y1,x2,y2,mathml_string |
||
8224 | bpr | 2879 | @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2) |
7614 | schaersvoo | 2880 | @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object |
9383 | schaersvoo | 2881 | @ if inputfields are incorporated in mathml (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_mathml();<br /><b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();" |
7614 | schaersvoo | 2882 | @ If other inputfields (command input / command textarea) or userdraw is performed, the function read_canvas() will not read mathml. Use some generic function to read it.... |
8224 | bpr | 2883 | |
7614 | schaersvoo | 2884 | */ |
2885 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
||
2886 | for(i=0;i<5;i++){ |
||
2887 | switch(i){ |
||
2888 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
2889 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
2890 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
2891 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
2892 | case 4: decimals = find_number_of_digits(precision); |
||
2893 | temp = get_string(infile,1); |
||
2894 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
8379 | schaersvoo | 2895 | string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d,%d,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick,click_cnt,stroke_color,stroke_opacity); |
7614 | schaersvoo | 2896 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8379 | schaersvoo | 2897 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d,%d,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick,click_cnt,stroke_color,stroke_opacity); |
7614 | schaersvoo | 2898 | add_to_buffer(tmp_buffer); |
8379 | schaersvoo | 2899 | if(onclick == 1 ){click_cnt++;} |
8224 | bpr | 2900 | /* |
2901 | in case inputs are present , trigger adding the read_mathml() |
||
7614 | schaersvoo | 2902 | if no other reply_format is defined |
2903 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
2904 | */ |
||
2905 | if(strstr(temp,"mathml0") != NULL){ |
||
7876 | schaersvoo | 2906 | if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */ |
7614 | schaersvoo | 2907 | } |
2908 | break; |
||
2909 | default:break; |
||
2910 | } |
||
2911 | } |
||
2912 | reset(); |
||
2913 | break; |
||
2914 | case HTTP: |
||
2915 | /* |
||
9385 | schaersvoo | 2916 | @ http x1,y1,x2,y2,http://some_adress.com |
2917 | @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2) |
||
2918 | @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
||
2919 | @ can <b>not</b> be 'set onclick' or 'drag xy' |
||
7614 | schaersvoo | 2920 | */ |
8224 | bpr | 2921 | if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;} |
7614 | schaersvoo | 2922 | for(i=0;i<5;i++){ |
2923 | switch(i){ |
||
2924 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
2925 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
2926 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
2927 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
2928 | case 4: decimals = find_number_of_digits(precision); |
||
2929 | temp = get_string(infile,1); |
||
2930 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
2931 | string_length = snprintf(NULL,0,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
9289 | schaersvoo | 2932 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+2); |
7614 | schaersvoo | 2933 | snprintf(tmp_buffer,string_length,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
2934 | add_to_buffer(tmp_buffer); |
||
2935 | break; |
||
2936 | } |
||
2937 | } |
||
2938 | reset(); |
||
2939 | break; |
||
2940 | case HTML: |
||
2941 | /* |
||
2942 | @ html x1,y1,x2,y2,html_string |
||
8816 | schaersvoo | 2943 | @ all tags are allowed<br /> html-code using inputfields could be read using your own javascript-code. Do not use id's like 'canvas_input0' etc. |
2944 | @ can be set onclick <br />(however dragging not supported) |
||
7614 | schaersvoo | 2945 | */ |
2946 | break; |
||
2947 | case X_AXIS_STRINGS: |
||
2948 | /* |
||
2949 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
9385 | schaersvoo | 2950 | @ alternative : xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
9346 | schaersvoo | 2951 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
10953 | bpr | 2952 | @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br /><b>note</b>: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>) |
9346 | schaersvoo | 2953 | @ a javascript error message will flag non-matching value:name pairs |
9341 | schaersvoo | 2954 | @ if the 'x-axis words' are too big and will overlap, a simple alternating offset will be applied |
7614 | schaersvoo | 2955 | @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 1,100,grey,1,4,6,grey |
2956 | */ |
||
2957 | temp = get_string(infile,1); |
||
2958 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
2959 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
2960 | fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp); |
||
2961 | use_axis_numbering = 1; |
||
2962 | break; |
||
9341 | schaersvoo | 2963 | case X_AXIS_STRINGS_UP: |
2964 | /* |
||
2965 | @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
9385 | schaersvoo | 2966 | @ alternative : xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
9341 | schaersvoo | 2967 | @ the text will be rotated 90° up |
9346 | schaersvoo | 2968 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
10953 | bpr | 2969 | @ use command "fontcolor","fontfamily" to adjust font <br />defaults: black,12,Ariel<br /><b>note</b>: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>) |
9346 | schaersvoo | 2970 | @ a javascript error message will flag non-matching value:name pairs |
9341 | schaersvoo | 2971 | @ if the 'x-axis words' are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards) |
2972 | @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxisup 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 1,100,grey,1,4,6,grey |
||
2973 | */ |
||
2974 | temp = get_string(infile,1); |
||
2975 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
2976 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
2977 | fprintf(js_include_file,"x_strings_up = 1;x_strings = [\"%s\"];\n ",temp); |
||
2978 | use_axis_numbering = 1; |
||
2979 | break; |
||
7614 | schaersvoo | 2980 | case Y_AXIS_STRINGS: |
2981 | /* |
||
2982 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
9385 | schaersvoo | 2983 | @ alternativ : yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
10953 | bpr | 2984 | @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br /> <b>note</b>: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>) |
9346 | schaersvoo | 2985 | @ use these y-axis num1...num_n values instead of default ymin...ymax |
2986 | @ a javascript error message will flag non-matching value:name pairs |
||
7614 | schaersvoo | 2987 | @ example:<br />size 400,400<br />yrange 0,13<br />xrange -100,500<br />axis<br />yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'ymajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 100,1,grey,4,1,6,grey |
2988 | */ |
||
2989 | temp = get_string(infile,1); |
||
2990 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
2991 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
2992 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
2993 | use_axis_numbering = 1; |
||
2994 | break; |
||
8224 | bpr | 2995 | |
7614 | schaersvoo | 2996 | case AXIS_NUMBERING: |
2997 | /* |
||
8224 | bpr | 2998 | @ axisnumbering |
9372 | schaersvoo | 2999 | @ keyword (no arguments required) |
9373 | schaersvoo | 3000 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
7614 | schaersvoo | 3001 | */ |
3002 | use_axis_numbering = 1; |
||
3003 | break; |
||
3004 | case AXIS: |
||
3005 | /* |
||
3006 | @ axis |
||
9372 | schaersvoo | 3007 | @ keyword (no arguments required) |
9373 | schaersvoo | 3008 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
7614 | schaersvoo | 3009 | |
3010 | */ |
||
3011 | use_axis = TRUE; |
||
3012 | break; |
||
8101 | schaersvoo | 3013 | case KILLSLIDER: |
3014 | /* |
||
3015 | @ killslider |
||
9372 | schaersvoo | 3016 | @ keyword (no arguments required) |
3017 | @ ends grouping of object under a previously defined slider |
||
8101 | schaersvoo | 3018 | */ |
3019 | slider = 0; |
||
3020 | break; |
||
9213 | schaersvoo | 3021 | case SLIDER_X: |
3022 | /* |
||
3023 | @ sliderfunction_x some_function_in_x |
||
3024 | @ default value "x" |
||
3025 | @ the x-value of the slider object(s) will be calculated with this function. |
||
3026 | @ default is the x-slider value itself |
||
3027 | @ only used by command 'slider' |
||
3028 | @ define before a slider command ! |
||
3029 | */ |
||
3030 | slider_function_x = get_string(infile,1); |
||
3031 | break; |
||
3032 | case SLIDER_Y: |
||
3033 | slider_function_y = get_string(infile,1); |
||
3034 | /* |
||
3035 | @ sliderfunction_y some_function_in_y |
||
3036 | @ default value "y" |
||
3037 | @ the y-value of the slider object(s) will be calculated with this function. |
||
3038 | @ only used by command 'slider' |
||
3039 | @ define before a slider command ! |
||
3040 | */ |
||
3041 | break; |
||
8071 | schaersvoo | 3042 | case SLIDER: |
3043 | /* |
||
10952 | schaersvoo | 3044 | @ slider start_value,end_value,width px,height px,<em>type</em>,label |
3045 | @ <em>type</em> may be : xy,x,y,angle |
||
3046 | @ if a slider value display is desired, use for argument <em>type</em>:<br />xy display<br />x display<br />y display<br />angle radian<br />angle degree |
||
10953 | bpr | 3047 | @ if a unit (or something like that...) for x/y-value display is needed, use commands 'xunit' and / or 'yunit' |
3048 | @ if the translation should be performed using a function, use for type: xy function,x function,y function<br />use commands sliderfunction_x and/or sliderfunction_y before the slider command to define the functions<br />example:<br />sliderfunction_x x^2<br />sliderfunction_y y^2<br />slider -5,5,100,100,xy function,Some_Text<br />...some stuff to slide<br />killslider<br />sliderfunction_x x^2-2<br />slider -15,15,100,10,x function,Some_Other_Text<br />...more stuff to slide<br />killslider<br />... etc |
||
9354 | schaersvoo | 3049 | @ use command 'slider' before draggable/clickable objects. |
9244 | schaersvoo | 3050 | @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<em>size 300,300<br />xrange -5,5<br />yrange -5,5<br />grid 1,1,grey<br />linewidth 3<br />drag xy<br />fillcolor orange<br />strokecolor blue<br />slider 0,2*pi,250,30,angle degrees,Rotate arrow<br />arrow 2,2,5,5,8,red</em> |
8815 | schaersvoo | 3051 | @ no slider for a math function, these can be traced using command 'trace_jscurve some_function_in_x' |
8101 | schaersvoo | 3052 | @ a slider will affect all draggable objects after the 'slider' command...<br />and can be used to group translate / rotate several objects...<br />until a next 'slider' or keyword 'killslider' |
8097 | schaersvoo | 3053 | @ amount of sliders is not limited. |
8101 | schaersvoo | 3054 | @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value' |
8097 | schaersvoo | 3055 | @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page |
10953 | bpr | 3056 | @ every draggable object may have its own slider (no limit in amount of sliders) |
8071 | schaersvoo | 3057 | @ label: some slider text |
3058 | @ use fillcolor for slider ball |
||
3059 | @ use strokecolor for slider bar |
||
8097 | schaersvoo | 3060 | @ use fontfamily / fontcolor to set used fonts |
8071 | schaersvoo | 3061 | @ use opacity (only fill opacity will be used) to set transparency |
8111 | schaersvoo | 3062 | @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc |
8071 | schaersvoo | 3063 | */ |
9213 | schaersvoo | 3064 | slider_cnt++;/* slider starts at 1 */ |
8071 | schaersvoo | 3065 | for(i=0; i<6 ; i++){ |
3066 | switch(i){ |
||
3067 | case 0: double_data[0] = get_real(infile,0);break; /* start value */ |
||
3068 | case 1: double_data[1] = get_real(infile,0);break; /* end value */ |
||
3069 | case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */ |
||
3070 | case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */ |
||
8111 | schaersvoo | 3071 | case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */ |
9213 | schaersvoo | 3072 | if(strstr(temp,"xy")!= 0){ |
3073 | slider = 4; |
||
3074 | } |
||
3075 | else |
||
3076 | { |
||
3077 | if(strstr(temp,"x") != 0){ |
||
3078 | slider = 1; |
||
3079 | } |
||
3080 | else |
||
3081 | { |
||
3082 | if(strstr(temp,"y") != 0){ |
||
3083 | slider = 2; |
||
3084 | } |
||
3085 | else |
||
3086 | { |
||
3087 | if(strstr(temp,"angle") != 0){ /* angle diplay radian */ |
||
3088 | slider = 3; |
||
3089 | } |
||
3090 | else |
||
3091 | { |
||
3092 | canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y"); |
||
3093 | } |
||
3094 | } |
||
3095 | } |
||
3096 | } |
||
3097 | if(strstr(temp,"display")!=0){ |
||
10952 | schaersvoo | 3098 | if( slider == 4 ){ /* show x:y */ |
3099 | use_slider_display = 1; /* show x xy values in canvas window */ |
||
3100 | } |
||
3101 | else |
||
3102 | { |
||
3103 | if( slider == 1 ){ /* show only x -values */ |
||
3104 | use_slider_display = 10; |
||
3105 | } |
||
3106 | else |
||
3107 | { |
||
3108 | use_slider_display = 11; /* show only y -values*/ |
||
3109 | } |
||
3110 | } |
||
9213 | schaersvoo | 3111 | } |
3112 | else |
||
3113 | { |
||
3114 | if(strstr(temp,"degree")!= 0){ |
||
3115 | use_slider_display = 2; /* show angle values in canvas window */ |
||
3116 | } |
||
3117 | else |
||
3118 | { |
||
3119 | if(strstr(temp,"radian")!=0){ |
||
3120 | use_slider_display = 3; /* show radian values in canvas window */ |
||
3121 | } |
||
3122 | } |
||
3123 | } |
||
3124 | if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */ |
||
3125 | add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity); |
||
3126 | } |
||
3127 | if(strstr(temp,"fun")!= 0){ |
||
3128 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
10953 | bpr | 3129 | add_to_js_math(js_include_file); use_js_math = TRUE; |
9213 | schaersvoo | 3130 | } |
3131 | fprintf(js_include_file,"var slider_function%d = {x:to_js_math('%s'),y:to_js_math('%s')};",slider_cnt,slider_function_x,slider_function_y); |
||
3132 | slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/ |
||
3133 | } |
||
3134 | else |
||
3135 | { |
||
3136 | fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt); |
||
3137 | /* we must define these, otherwise 'use stict' will cause an error */ |
||
3138 | } |
||
8097 | schaersvoo | 3139 | break; |
3140 | case 5: /* some string used for slider description */ |
||
9213 | schaersvoo | 3141 | if(slider == 4){ |
3142 | add_xyslider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display); |
||
3143 | } |
||
3144 | else |
||
3145 | { |
||
3146 | add_slider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display); |
||
3147 | } |
||
8071 | schaersvoo | 3148 | break; |
3149 | } |
||
8097 | schaersvoo | 3150 | } |
8071 | schaersvoo | 3151 | break; |
7654 | schaersvoo | 3152 | case SGRAPH: |
3153 | /* |
||
3154 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
3155 | @ primitive implementation of a 'broken scale' graph... |
||
7976 | schaersvoo | 3156 | @ not very versatile: only usable in combination with userdraw <br />eg no other objects will obey this "coordinate system"<br />if you want to place an object into this coordinate system, be aware that 10% or 20% of xsize and/or ysize is 'lost'.<br />Use these "formulas" to recalculate the virtual coordinates:<br />factor=0.8 in case xstart != xmin (or ystart != ymin)<br />factor=0.9 in case xstart = xmin (or ystart = ymin)<br />px_x_point = ((factor*xsize)/(xmax - xstart))*(x_point - xmax)+xsize<br />x_recalculated = px*(xmax - xmin)/xsize + $xmin<br />px_y_point = -1*factor*y_point*ysize/(ymax - ystart) + ymax*factor*ysize/(ymax - ystart)<br />y_recalculated = ymax - py*(ymax - ymin)/ysize<br /> |
8224 | bpr | 3157 | @ example:<br />size 400,400<br />xrange 0,10000<br />yrange 0,100<br />sgraph 9000,50,100,10,4,4,grey,blue<br />userinput_xy<br />linewidth 2<br />userdraw segments,red |
7654 | schaersvoo | 3158 | */ |
8224 | bpr | 3159 | if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;} |
7654 | schaersvoo | 3160 | for(i = 0 ; i < 8 ;i++){ |
3161 | switch(i){ |
||
3162 | case 0:double_data[0] = get_real(infile,0);break; |
||
3163 | case 1:double_data[1] = get_real(infile,0);break; |
||
3164 | case 2:double_data[2] = get_real(infile,0);break; |
||
3165 | case 3:double_data[3] = get_real(infile,0);break; |
||
3166 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
3167 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
3168 | case 6:stroke_color = get_color(infile,0);break; |
||
3169 | case 7:font_color = get_color(infile,1); |
||
7658 | schaersvoo | 3170 | string_length = snprintf(NULL,0,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size); |
7654 | schaersvoo | 3171 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7658 | schaersvoo | 3172 | snprintf(tmp_buffer,string_length,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size); |
7654 | schaersvoo | 3173 | add_to_buffer(tmp_buffer); |
3174 | break; |
||
3175 | default:break; |
||
3176 | } |
||
3177 | } |
||
3178 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
3179 | break; |
||
9406 | schaersvoo | 3180 | case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px) ,axis/tickscolor]*/ |
7614 | schaersvoo | 3181 | /* |
3182 | @ grid step_x,step_y,gridcolor |
||
9373 | schaersvoo | 3183 | @ if keywords <a href="#axis">"axis"</a> or <a href="#axisnumbering">"axisnumbering"</a> are set, use :<br />grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color<br />minor x step = step_x / minor_x |
9406 | schaersvoo | 3184 | @ in that case, use command <a href="#fontcolor">"fontcolor"</a>, <a href="#fontsize">"fontsize"</a> and / or <a href="#fontfamily">"fontfamily"</a> to adjust font <br />defaults: black,12,Ariel |
7654 | schaersvoo | 3185 | @ if xmin > 0 and/or ymin > 0 and zooming / panning is not activ: <br /> be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual <br /> as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV) |
9373 | schaersvoo | 3186 | @ can <b>not</b> be set <a href="#onclick">"onclick"</a> or <a href="#drag">"drag xy"</a> |
9406 | schaersvoo | 3187 | @ use commands <a href="#xlabel">'xlabel some_string'</a> and/or <a href="#ylabel">'ylabel some_string'</a> to label axis;<br />use command "fontsize" to adjust size:the font family is non-configurable 'italic your_fontsize px Ariel' ! |
9373 | schaersvoo | 3188 | @ see commands (see <a href="#xaxis">"xaxis" or xaxistext"</a>, <a href="#yaxis">"yaxis" or "yaxistext"</a> to set tailormade values on axis (the used font is set by <a href="fontfamily">command fontfamily</a>; default '12px Ariel') |
3189 | @ see command <a href="#legend">"legend"</a>to set a legend for the graph ;<br />use command <a href="#fontsize">"fontsize"</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel') |
||
7614 | schaersvoo | 3190 | */ |
7729 | schaersvoo | 3191 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
7614 | schaersvoo | 3192 | if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;} |
3193 | for(i=0;i<4;i++){ |
||
3194 | switch(i){ |
||
3195 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
3196 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
3197 | case 2: |
||
3198 | if( use_axis == TRUE ){ |
||
3199 | stroke_color = get_color(infile,0); |
||
3200 | done = FALSE; |
||
3201 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
3202 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
3203 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
3204 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
3205 | } |
||
3206 | else |
||
3207 | { |
||
3208 | int_data[0] = 1; |
||
3209 | int_data[1] = 1; |
||
3210 | stroke_color = get_color(infile,1); |
||
3211 | fill_color = stroke_color; |
||
3212 | } |
||
9340 | schaersvoo | 3213 | if( double_data[0] <= 0 || double_data[1] <= 0 || int_data[0] <= 0 || int_data[1] <= 0 ){canvas_error("major or minor ticks must be positive !");} |
7634 | schaersvoo | 3214 | /* set snap_x snap_y values in pixels */ |
7988 | schaersvoo | 3215 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
9289 | schaersvoo | 3216 | string_length = snprintf(NULL,0, ";draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n ",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
7614 | schaersvoo | 3217 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
9289 | schaersvoo | 3218 | snprintf(tmp_buffer,string_length,";draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n ",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
7614 | schaersvoo | 3219 | add_to_buffer(tmp_buffer); |
3220 | break; |
||
3221 | } |
||
3222 | } |
||
3223 | reset(); |
||
3224 | break; |
||
3225 | case OPACITY: |
||
3226 | /* |
||
3227 | @ opacity 0-255,0-255 |
||
9267 | schaersvoo | 3228 | @ opacity 0.0 - 1.0,0.0 - 1.0 |
9385 | schaersvoo | 3229 | @ alternative : transparent |
9267 | schaersvoo | 3230 | @ first item is stroke opacity, second is fill opacity |
7614 | schaersvoo | 3231 | */ |
3232 | for(i = 0 ; i<2;i++){ |
||
3233 | switch(i){ |
||
9267 | schaersvoo | 3234 | case 0: double_data[0]= get_real(infile,0);break; |
3235 | case 1: double_data[1]= get_real(infile,1);break; |
||
7614 | schaersvoo | 3236 | default: break; |
3237 | } |
||
3238 | } |
||
9267 | schaersvoo | 3239 | if( double_data[0] > 255 || double_data[1] > 255 ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */ |
3240 | if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = double_data[0];} /* 0.0 - 1.0 */ |
||
3241 | if( double_data[0] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = double_data[0];} /* 0.0 - 1.0 */ |
||
7614 | schaersvoo | 3242 | break; |
9907 | schaersvoo | 3243 | case ROTATION_CENTER: |
3244 | /* |
||
3245 | @ rotationcenter x_center,y_center |
||
3246 | @ define an rotation center in your x/y-coordinate system |
||
3247 | @ wims will not check the validity of your input; use javascript console to debug any erors |
||
3248 | @ if not defined a rotation will be around the first point of an object |
||
10953 | bpr | 3249 | @ to be used before command <a href="#rotate">rotate</a> |
9907 | schaersvoo | 3250 | @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given |
3251 | */ |
||
3252 | temp = get_string(infile,1); |
||
3253 | string_length = snprintf(NULL,0,"[ %s ]",temp); |
||
3254 | check_string_length(string_length); |
||
3255 | rotation_center = my_newmem(string_length+1); |
||
3256 | snprintf(rotation_center,string_length,"[%s]",temp); |
||
3257 | break; |
||
7614 | schaersvoo | 3258 | case ROTATE: |
3259 | /* |
||
9385 | schaersvoo | 3260 | @ rotate rotation_angle |
3261 | @ angle in degrees |
||
3262 | @ (only) the next object will be rotated is given angle |
||
3263 | @ positive values rotate counter clockwise |
||
10953 | bpr | 3264 | @ attention: all objects will be rotated around their first point...<br /><em>rotate 45</em><br /> <em>triangle 1,1,5,1,3,4,red</em><br />will rotate 45 degrees around point (1:1) |
9907 | schaersvoo | 3265 | @ if another rotation center is needed, use command <a href="#rotationcenter">'rotationcenter xc,yc'</a>.<br />to reset this rotationcenter, use keyword <a href="killrotate">'killrotate'</a> |
3266 | @ attention: rotate will mess up the interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">"drag xy"</a> or keyword <a href="onclick">"onclick"</a> : the mouse recognises the original -unrotated- coordinates of the object |
||
7614 | schaersvoo | 3267 | */ |
3268 | use_rotate = TRUE; |
||
8097 | schaersvoo | 3269 | angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */ |
7614 | schaersvoo | 3270 | break; |
9907 | schaersvoo | 3271 | case KILLROTATE: |
3272 | /* |
||
3273 | @ killrotate will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a> |
||
3274 | @ a following rotate command will have the first object point as rotation center |
||
3275 | @ if not set, the rotation center will remain unchanged |
||
3276 | */ |
||
3277 | rotation_center= my_newmem(6); |
||
3278 | snprintf(rotation_center,5,"null"); |
||
3279 | break; |
||
7785 | schaersvoo | 3280 | case KILLAFFINE: |
3281 | /* |
||
3282 | @ killaffine |
||
3283 | @ keyword : resets the transformation matrix to 1,0,0,1,0,0 |
||
3284 | */ |
||
3285 | use_affine = FALSE; |
||
8224 | bpr | 3286 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
7785 | schaersvoo | 3287 | break; |
3288 | case AFFINE: |
||
3289 | /* |
||
9383 | schaersvoo | 3290 | @ affine a,b,c,d,tx,ty |
8224 | bpr | 3291 | @ defines a transformation matrix for subsequent objects |
10953 | bpr | 3292 | @ images drawn by setting skew params a & d will be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !! |
7785 | schaersvoo | 3293 | @ use keyword 'killaffine' to end the transformation |
3294 | @ note 1: only 'draggable' / 'noclick' objects can be transformed. |
||
3295 | @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet) |
||
3296 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
||
3297 | @ a : Scales the drawings horizontally |
||
3298 | @ b : Skews the drawings horizontally |
||
3299 | @ c : Skews the drawings vertically |
||
3300 | @ d : Scales the drawings vertically |
||
8071 | schaersvoo | 3301 | @ tx: Moves the drawings horizontally in xrange coordinate system |
8224 | bpr | 3302 | @ ty: Moves the drawings vertically in yrange coordinate system |
8448 | schaersvoo | 3303 | @ the data precision may be set by preceding command "precision int" |
7785 | schaersvoo | 3304 | */ |
3305 | for(i = 0 ; i<6;i++){ |
||
3306 | switch(i){ |
||
3307 | case 0: double_data[0] = get_real(infile,0);break; |
||
3308 | case 1: double_data[1] = get_real(infile,0);break; |
||
3309 | case 2: double_data[2] = get_real(infile,0);break; |
||
3310 | case 3: double_data[3] = get_real(infile,0);break; |
||
8071 | schaersvoo | 3311 | case 4: double_data[4] = get_real(infile,0);break; |
3312 | case 5: double_data[5] = get_real(infile,1); |
||
7785 | schaersvoo | 3313 | use_affine = TRUE; |
8448 | schaersvoo | 3314 | decimals = find_number_of_digits(precision); |
3315 | string_length = snprintf(NULL,0, "[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin)); |
||
7785 | schaersvoo | 3316 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
8448 | schaersvoo | 3317 | snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin)); |
8071 | schaersvoo | 3318 | break; |
7785 | schaersvoo | 3319 | default: break; |
3320 | } |
||
3321 | } |
||
3322 | break; |
||
7614 | schaersvoo | 3323 | case KILLTRANSLATION: |
3324 | /* |
||
9385 | schaersvoo | 3325 | @ killtranslation |
3326 | @ alternative : killtranslate |
||
3327 | @ resets the translation matrix to 1,0,0,1,0,0 |
||
7614 | schaersvoo | 3328 | */ |
8071 | schaersvoo | 3329 | use_affine = FALSE; |
8224 | bpr | 3330 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
7614 | schaersvoo | 3331 | break; |
3332 | case TRANSLATION: |
||
3333 | /* |
||
9385 | schaersvoo | 3334 | @ translation tx,ty |
3335 | @ alternative : translate |
||
3336 | @ will translate the next objects tx in xrange and ty in yrange |
||
3337 | @ use command 'killtranstation' to end the command |
||
7614 | schaersvoo | 3338 | */ |
8071 | schaersvoo | 3339 | for(i = 0 ; i<2;i++){ |
3340 | switch(i){ |
||
3341 | case 0: double_data[0] = get_real(infile,0);break; |
||
3342 | case 1: double_data[1] = get_real(infile,1); |
||
3343 | use_affine = TRUE; |
||
8448 | schaersvoo | 3344 | decimals = find_number_of_digits(precision); |
3345 | string_length = snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin)); |
||
8071 | schaersvoo | 3346 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
8448 | schaersvoo | 3347 | snprintf(affine_matrix,string_length,"[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin)); |
8071 | schaersvoo | 3348 | break; |
3349 | default: break; |
||
3350 | } |
||
3351 | } |
||
3352 | break; |
||
8386 | schaersvoo | 3353 | case ANIMATE: |
3354 | /* |
||
9385 | schaersvoo | 3355 | @ animate type |
3356 | @ REMOVED : this should be done with a slider |
||
3357 | @ type may be "point" (nothing else , yet...) |
||
3358 | @ the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber' |
||
3359 | @ will animate a point on the next plot/curve command |
||
3360 | @ the curve will not be draw |
||
3361 | @ moves repeatedly from xmin to xmax |
||
8386 | schaersvoo | 3362 | */ |
3363 | if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");} |
||
3364 | break; |
||
3365 | |||
7614 | schaersvoo | 3366 | case DASHED: |
3367 | /* |
||
9372 | schaersvoo | 3368 | @ dashed |
3369 | @ keyword (no arguments required) |
||
7614 | schaersvoo | 3370 | @ next object will be drawn with a dashed line |
9383 | schaersvoo | 3371 | @ change dashing scheme by using command <a href="#dashtype">dashtype</a> |
7614 | schaersvoo | 3372 | */ |
3373 | use_dashed = TRUE; |
||
3374 | break; |
||
3375 | case FILLED: |
||
3376 | /* |
||
9372 | schaersvoo | 3377 | @ filled |
3378 | @ keyword (no arguments required) |
||
8224 | bpr | 3379 | @ the next 'fillable' object (only) will be filled |
7614 | schaersvoo | 3380 | @ use command "fillcolor color" to set fillcolor |
3381 | @ use command "opacity 0-255,0-255" to set stroke and fill-opacity |
||
3382 | @ use command "fill x,y,color" or "floodfill x,y,color" to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care ! |
||
3383 | */ |
||
3384 | use_filled = TRUE; |
||
3385 | break; |
||
3386 | case STYLE: |
||
3387 | /* |
||
9385 | schaersvoo | 3388 | @ highlight color,opacity,linewidth |
7614 | schaersvoo | 3389 | @ NOT IMPLEMENTED |
10953 | bpr | 3390 | @ use command "onclick" : when the object receives a userclick it will increase its linewidth |
7614 | schaersvoo | 3391 | */ |
3392 | break; |
||
8386 | schaersvoo | 3393 | |
7614 | schaersvoo | 3394 | case FILLCOLOR: |
3395 | /* |
||
3396 | @ fillcolor colorname or #hex |
||
9383 | schaersvoo | 3397 | @ set the color for a filled object : mainly used for command 'userdraw obj,stroke_color' |
3398 | @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
||
7614 | schaersvoo | 3399 | */ |
3400 | fill_color = get_color(infile,1); |
||
3401 | break; |
||
8386 | schaersvoo | 3402 | |
7614 | schaersvoo | 3403 | case STROKECOLOR: |
3404 | /* |
||
3405 | @ strokecolor colorname or #hex |
||
3406 | @ to be used for commands that do not supply a color argument (like command 'linegraph') |
||
3407 | */ |
||
3408 | stroke_color = get_color(infile,1); |
||
3409 | break; |
||
8386 | schaersvoo | 3410 | |
8224 | bpr | 3411 | case BGIMAGE: |
7614 | schaersvoo | 3412 | /* |
9385 | schaersvoo | 3413 | @ bgimage image_location |
10953 | bpr | 3414 | @ use an image as background .<br />technical: we use the background of 'canvas_div' |
9385 | schaersvoo | 3415 | @ the background image will be resized to match "width = xsize" and "height = ysize" |
7614 | schaersvoo | 3416 | */ |
3417 | URL = get_string(infile,1); |
||
3418 | fprintf(js_include_file,"<!-- set background image to canvas div -->\ncanvas_div.style.backgroundImage = \"url(%s)\";canvas_div.style.backgroundSize = \"%dpx %dpx\";\n",URL,xsize,ysize); |
||
3419 | break; |
||
8386 | schaersvoo | 3420 | |
8224 | bpr | 3421 | case BGCOLOR: |
7614 | schaersvoo | 3422 | /* |
9385 | schaersvoo | 3423 | @ bgcolor colorname or #hex |
3424 | @ use this color as background of the "div" containing the canvas(es) |
||
7614 | schaersvoo | 3425 | */ |
3426 | /* [255,255,255]*/ |
||
3427 | bgcolor = get_string(infile,1); |
||
3428 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
3429 | int found = 0; |
||
3430 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
3431 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
3432 | bgcolor = colors[i].hex; |
||
3433 | found = 1; |
||
3434 | break; |
||
3435 | } |
||
3436 | } |
||
3437 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");} |
||
3438 | } |
||
3439 | fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity); |
||
3440 | break; |
||
8386 | schaersvoo | 3441 | |
7614 | schaersvoo | 3442 | case COPY: |
3443 | /* |
||
3444 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
8448 | schaersvoo | 3445 | @ The image may be "bitmap" or "SVG" |
7614 | schaersvoo | 3446 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
3447 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
8224 | bpr | 3448 | @ [filename] is the URL of the image |
7614 | schaersvoo | 3449 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
9379 | schaersvoo | 3450 | @ if command <a href="#drag">'drag x/y/xy'</a> is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...' |
3451 | @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates |
||
8448 | schaersvoo | 3452 | @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc) |
3453 | @ you may draw / userdraw / drag other stuff on top of an "imported" image |
||
7614 | schaersvoo | 3454 | */ |
3455 | for(i = 0 ; i<7;i++){ |
||
3456 | switch(i){ |
||
3457 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range */ |
||
3458 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */ |
||
3459 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
||
3460 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
3461 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
3462 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
3463 | case 6: URL = get_string(infile,1); |
||
3464 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
||
3465 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
8448 | schaersvoo | 3466 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
3467 | int_data[9] = click_cnt; |
||
3468 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
3469 | if( reply_format == 0 ){ reply_format = 20; } |
||
3470 | int_data[8] = 2;/* drag & drop */ |
||
7614 | schaersvoo | 3471 | } |
3472 | else |
||
3473 | { |
||
8448 | schaersvoo | 3474 | if( onclick == 1 ){ |
3475 | reply_format = 20; |
||
3476 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
||
3477 | click_cnt++; /* will also be used in dragstuff ! */ |
||
3478 | } |
||
3479 | else |
||
3480 | { |
||
3481 | int_data[8] = 0; /* just static image */ |
||
3482 | } |
||
7614 | schaersvoo | 3483 | } |
8448 | schaersvoo | 3484 | /* |
3485 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,ext_img_cnt,resizable,draggable,click_cnt) |
||
3486 | */ |
||
3487 | string_length = snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
3488 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3489 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
3490 | drag_type = -1; /* reset the drag_type indicator */ |
||
3491 | ext_img_cnt++; |
||
3492 | onclick=0; |
||
7614 | schaersvoo | 3493 | add_to_buffer(tmp_buffer); |
3494 | break; |
||
3495 | default: break; |
||
3496 | } |
||
3497 | } |
||
3498 | break; |
||
3499 | /* |
||
8448 | schaersvoo | 3500 | HTML5 specs: |
7614 | schaersvoo | 3501 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
3502 | img Specifies the image, canvas, or video element to use |
||
3503 | sx The x coordinate where to start clipping : x1 = int_data[0] |
||
3504 | sy The y coordinate where to start clipping : x2 = int_data[1] |
||
8224 | bpr | 3505 | swidth The width of the clipped image : int_data[2] - int_data[0] |
7614 | schaersvoo | 3506 | sheight The height of the clipped image : int_data[3] - int_data[1] |
3507 | x The x coordinate where to place the image on the canvas : dx1 = int_data[4] |
||
3508 | y The y coordinate where to place the image on the canvas : dy1 = int_data[5] |
||
3509 | width The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6] |
||
3510 | height The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7] |
||
3511 | */ |
||
3512 | case COPYRESIZED: |
||
3513 | /* |
||
3514 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
||
9379 | schaersvoo | 3515 | @ The image may be any "bitmap" or "SVG" |
8224 | bpr | 3516 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [ filename], <br />possibly resized,<br />to the region of (dx1,dy1) to (dx2,dy2) in x/y-range |
8448 | schaersvoo | 3517 | @ (dx1:dy1) must be left top corner; (dx2 :dy2) must be right bottom corner of inserted image |
7614 | schaersvoo | 3518 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
8448 | schaersvoo | 3519 | @ URL is normal URL of network reachable image file location<br />(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br />(eg no special wims paths are searched !!) |
9379 | schaersvoo | 3520 | @ if command <a href="#drag">'drag x/y/xy'</a> is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...' |
3521 | @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates |
||
8448 | schaersvoo | 3522 | @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc) |
3523 | @ you may draw / userdraw / drag stuff on top of an "imported" image |
||
7614 | schaersvoo | 3524 | */ |
3525 | for(i = 0 ; i<9;i++){ |
||
3526 | switch(i){ |
||
3527 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
3528 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
3529 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
3530 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
3531 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
3532 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
3533 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
3534 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
3535 | case 8: URL = get_string(infile,1); |
||
8448 | schaersvoo | 3536 | /* flag error when wrong diagonal: copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */ |
3537 | if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){ |
||
3538 | canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! "); |
||
7614 | schaersvoo | 3539 | } |
8448 | schaersvoo | 3540 | int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */ |
3541 | int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */ |
||
3542 | int_data[6] = abs(int_data[6] - int_data[4]);/* width */ |
||
3543 | int_data[7] = abs(int_data[7] - int_data[5]);/* height */ |
||
3544 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
3545 | int_data[9] = click_cnt; |
||
3546 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
3547 | if( reply_format == 0 ){ reply_format = 20; } |
||
3548 | int_data[8] = 2;/* drag & drop */ |
||
3549 | } |
||
7614 | schaersvoo | 3550 | else |
3551 | { |
||
8448 | schaersvoo | 3552 | if( onclick == 1 ){ |
3553 | reply_format = 20; |
||
3554 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
||
3555 | click_cnt++; /* will also be used in dragstuff ! */ |
||
3556 | } |
||
3557 | else |
||
3558 | { |
||
3559 | int_data[8] = 0; /* just static image */ |
||
3560 | } |
||
7614 | schaersvoo | 3561 | } |
8448 | schaersvoo | 3562 | /* |
3563 | (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt) |
||
3564 | URL,[2],[3],[6], [7], [4],[5],[6],[7],ext_img_cnt,1, [8], [9] |
||
3565 | */ |
||
3566 | string_length = snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
3567 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3568 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
3569 | drag_type = -1; /* reset the drag_type indicator */ |
||
3570 | ext_img_cnt++; |
||
3571 | onclick=0; |
||
7614 | schaersvoo | 3572 | add_to_buffer(tmp_buffer); |
8448 | schaersvoo | 3573 | break; |
7614 | schaersvoo | 3574 | default: break; |
3575 | } |
||
3576 | } |
||
3577 | break; |
||
8146 | schaersvoo | 3578 | case CLEARBUTTON: |
7614 | schaersvoo | 3579 | /* |
9385 | schaersvoo | 3580 | @ clearbutton value |
9386 | schaersvoo | 3581 | @ alternative : delete |
3582 | @ alternative : erase |
||
9385 | schaersvoo | 3583 | @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text 'value' |
3584 | @ <b>attention</b> command 'clearbutton' is incompatible with <a href="multidraw">multidraw</a> based drawings<br/>(in 'multidraw' there is always a remove_object_button for every drawprimitive) |
||
3585 | @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings |
||
3586 | @ uses the tooltip placeholder div element: may not be used with command 'intooltip' |
||
3587 | @ use command <a href="#inputstyle">'inputstyle'</a> to style the button... |
||
7614 | schaersvoo | 3588 | */ |
9378 | schaersvoo | 3589 | if(reply_format == 29){/* eg multidraw is selected */ |
3590 | canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw"); |
||
3591 | } |
||
8146 | schaersvoo | 3592 | add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1)); |
7614 | schaersvoo | 3593 | break; |
3594 | case INPUTSTYLE: |
||
3595 | /* |
||
3596 | @ inputstyle style_description |
||
9383 | schaersvoo | 3597 | @ may be used before any 'style-able' html object.(like inputfields or buttons)<br />or any html objects that are generated by some canvasdraw commands |
7614 | schaersvoo | 3598 | @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt |
3599 | */ |
||
3600 | input_style = get_string(infile,1); |
||
3601 | break; |
||
3602 | case INPUT: |
||
8224 | bpr | 3603 | /* |
7614 | schaersvoo | 3604 | @ input x,y,size,editable,value |
8224 | bpr | 3605 | @ to set inputfield "readonly", use editable = 0 |
7614 | schaersvoo | 3606 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
9379 | schaersvoo | 3607 | @ if "$status=done" (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'</a> |
3608 | @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> (inputcss is not yet implemented...) |
||
9378 | schaersvoo | 3609 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
10953 | bpr | 3610 | */ |
8224 | bpr | 3611 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
7614 | schaersvoo | 3612 | for(i = 0 ; i<5;i++){ |
3613 | switch(i){ |
||
3614 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
3615 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
3616 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
3617 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
8224 | bpr | 3618 | case 4: |
7614 | schaersvoo | 3619 | temp = get_string_argument(infile,1); |
3620 | string_length = snprintf(NULL,0, "draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp); |
||
3621 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3622 | snprintf(tmp_buffer,string_length,"draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp); |
||
3623 | add_to_buffer(tmp_buffer); |
||
3624 | input_cnt++;break; |
||
3625 | default: break; |
||
3626 | } |
||
3627 | } |
||
7876 | schaersvoo | 3628 | if(reply_format == 0 ){reply_format = 15;} |
7614 | schaersvoo | 3629 | reset(); |
3630 | break; |
||
3631 | case TEXTAREA: |
||
8224 | bpr | 3632 | /* |
7614 | schaersvoo | 3633 | @ textarea x,y,cols,rows,readonly,value |
9383 | schaersvoo | 3634 | @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> |
9379 | schaersvoo | 3635 | @ if "$status=done" (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'.</a> |
9378 | schaersvoo | 3636 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
7614 | schaersvoo | 3637 | */ |
8224 | bpr | 3638 | if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;} |
7614 | schaersvoo | 3639 | for(i = 0 ; i<6;i++){ |
3640 | switch(i){ |
||
3641 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
||
3642 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
3643 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
3644 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
3645 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
3646 | case 5: temp = get_string_argument(infile,1); |
||
3647 | string_length = snprintf(NULL,0, "draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp); |
||
3648 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3649 | snprintf(tmp_buffer,string_length,"draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp); |
||
3650 | add_to_buffer(tmp_buffer); |
||
3651 | input_cnt++;break; |
||
3652 | default: break; |
||
3653 | } |
||
3654 | } |
||
7876 | schaersvoo | 3655 | if(reply_format == 0 ){reply_format = 15;} |
7614 | schaersvoo | 3656 | reset(); |
3657 | break; |
||
3658 | case MOUSE_PRECISION: |
||
3659 | /* |
||
3660 | @ precision int |
||
8074 | schaersvoo | 3661 | @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc |
7614 | schaersvoo | 3662 | @ may be used / changed before every object |
9378 | schaersvoo | 3663 | @ In case of user interaction (like 'userdraw' or 'multidraw') this value will be used to determine the amount of decimals in the reply / answer |
7614 | schaersvoo | 3664 | */ |
3665 | precision = (int) (get_real(infile,1)); |
||
8074 | schaersvoo | 3666 | if(precision < 1 ){precision = 1;}; |
7614 | schaersvoo | 3667 | break; |
7838 | schaersvoo | 3668 | case SETLIMITS: |
3669 | /* |
||
9385 | schaersvoo | 3670 | @ setlimits |
3671 | @ keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button |
||
3672 | @ may be used for inputfield based zooming / panning |
||
3673 | @ may be styled using command <a href="#inputstyle">inputstyle</a> |
||
3674 | @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to 'xlabel' etc |
||
3675 | @ <b>note</b>:the input value will not be checked on validity |
||
7838 | schaersvoo | 3676 | */ |
7956 | schaersvoo | 3677 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
8815 | schaersvoo | 3678 | add_setlimits(js_include_file,canvas_root_id,font_size,input_style); |
7838 | schaersvoo | 3679 | /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */ |
3680 | use_pan_and_zoom = TRUE; |
||
3681 | done = TRUE; |
||
3682 | break; |
||
7614 | schaersvoo | 3683 | case ZOOM: |
3684 | /* |
||
3685 | @ zoom button_color |
||
9378 | schaersvoo | 3686 | @ introduce a very small 'controlpanel' at the lower right corner |
3687 | @ giving six 15×15px 'active' rectangle areas<br />(for ×,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image |
||
7614 | schaersvoo | 3688 | @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings. |
3689 | @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible |
||
8224 | bpr | 3690 | @ command 'opacity' may be used to set stroke_opacity of 'buttons |
9378 | schaersvoo | 3691 | @ <b>note</b>: use command 'zoom' at the end of your script code (the same is true for command 'mouse') |
3692 | @ <b>note</b>: only objects that may be set draggable / clickable will be zoomed / panned |
||
3693 | @ <b>note</b>: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !! |
||
7614 | schaersvoo | 3694 | */ |
7653 | schaersvoo | 3695 | fprintf(js_include_file,"use_pan_and_zoom = 1;"); |
7797 | schaersvoo | 3696 | use_pan_and_zoom = TRUE; |
7988 | schaersvoo | 3697 | stroke_color = get_color(infile,1); |
7614 | schaersvoo | 3698 | /* we use BG_CANVAS (0) */ |
7988 | schaersvoo | 3699 | add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity); |
7614 | schaersvoo | 3700 | done = TRUE; |
3701 | break; |
||
3702 | case ONCLICK: |
||
3703 | /* |
||
3704 | @ onclick |
||
9372 | schaersvoo | 3705 | @ keyword (no arguments required) |
10953 | bpr | 3706 | @ if the next object is clicked, its 'object onclick_or_drag sequence number' in fly script is returned <br /> by javascript:read_canvas(); |
8816 | schaersvoo | 3707 | @ onclick seqeuence numbering starts at '0'.<br />e.g. if there are 6 objects set onclick, the first onclick object will have id-number '0', the last id-number '5' |
9378 | schaersvoo | 3708 | @ line based objects will show an increase in line width<br />font based objects will show the text in 'bold' when clicked. |
10951 | schaersvoo | 3709 | @ the click zone (accuracy) is determined by 2× the line width of the object |
10953 | bpr | 3710 | @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript <br />(although a single object can <b>not</b> be onclick and draggable at the same time...) |
9378 | schaersvoo | 3711 | @ <b>note</b>: not all objects may be set onclick |
7614 | schaersvoo | 3712 | */ |
8257 | schaersvoo | 3713 | fprintf(js_include_file,"use_dragdrop_reply = true;"); |
7614 | schaersvoo | 3714 | onclick = 1; |
8816 | schaersvoo | 3715 | |
7614 | schaersvoo | 3716 | break; |
3717 | case DRAG: |
||
3718 | /* |
||
3719 | @ drag [x][y][xy] |
||
3720 | @ the next object will be draggable in x / y / xy direction |
||
3721 | @ the displacement can be read by 'javascript:read_dragdrop();' |
||
9379 | schaersvoo | 3722 | @ the precision (default 2 decimals) in the student reply may be set with command <a href="#precision">'precision'.</a><br />Use this 'precision' command before this command 'drag x|y|xy' ! |
8379 | schaersvoo | 3723 | @ 'onclick' and 'drag x|y|xy' may be combined (for different objects: a single object can either be onclick or drag , not both ) |
3724 | @ 'multi_objects' will be numbered in the given x/y-sequence (example: points red,0,0,1,1,2,2,3,3 : point (0:0) is object_number 1) |
||
9383 | schaersvoo | 3725 | @ <b>attention</b>: static objects and 'onclick/drag' objects of the same type (like point,circle,etc) with the same coordinates (e.g. objects that overlap) will give problems in the 'recognition algorithm')<br />in this example<br /><em>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>the blue point will not be recognised as draggable !<br /><em>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>both points will be recognised |
8379 | schaersvoo | 3726 | @ the answer is : drag_or_onclick_object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the sequence number of the draggable & onclick objects in your script.<br />Only draggable & onclick objects will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc) |
3727 | @ use keyword 'snaptogrid' , 'xsnaptogrid' , 'ysnaptogrid' or command 'snaptopoints x1,y1,x2,y2,...' to switch from free to discrete movement |
||
8224 | bpr | 3728 | @ in case of external images (commands copy / copyresized) the external image can be set draggable ; always xy. <br />The function javascript;read_canvas() will return the xy-coordinates of all images. |
9378 | schaersvoo | 3729 | @ <b>note</b>: in case an object is dragged , zooming or panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !! |
7614 | schaersvoo | 3730 | */ |
3731 | temp = get_string(infile,1); |
||
8224 | bpr | 3732 | if(strstr(temp,"xy") != NULL ){ |
7614 | schaersvoo | 3733 | drag_type = 0; |
3734 | } |
||
3735 | else |
||
3736 | { |
||
8224 | bpr | 3737 | if(strstr(temp,"x") != NULL ){ |
7614 | schaersvoo | 3738 | drag_type = 1; |
3739 | } |
||
3740 | else |
||
3741 | { |
||
3742 | drag_type = 2; |
||
3743 | } |
||
3744 | } |
||
8448 | schaersvoo | 3745 | /* assuming all drag&drop coordinates the same precision: so set only once */ |
3746 | if( print_drag_params_only_once == FALSE ){ |
||
3747 | fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision); |
||
3748 | print_drag_params_only_once = TRUE; |
||
3749 | } |
||
7614 | schaersvoo | 3750 | onclick = 2; |
3751 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
3752 | break; |
||
3753 | case BLINK: |
||
3754 | /* |
||
3755 | @ blink time(seconds) |
||
3756 | @ NOT IMPLEMETED -YET |
||
3757 | */ |
||
3758 | break; |
||
7996 | schaersvoo | 3759 | case XUNIT: |
3760 | /* |
||
3761 | @ xunit some_unit_for_x-values |
||
3762 | @ unicode allowed (no html code) |
||
3763 | @ use together with command mousex |
||
9372 | schaersvoo | 3764 | @ will display the cursor x-coordinate in 'unit' |
7996 | schaersvoo | 3765 | */ |
3766 | fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1)); |
||
3767 | break; |
||
3768 | case YUNIT: |
||
3769 | /* |
||
3770 | @ yunit some_unit_for_y-values |
||
3771 | @ unicode allowed (no html code) |
||
9379 | schaersvoo | 3772 | @ use together with command mousey |
9372 | schaersvoo | 3773 | @ will display the cursor y-coordinate in 'unit' |
7996 | schaersvoo | 3774 | */ |
3775 | fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1)); |
||
3776 | break; |
||
9386 | schaersvoo | 3777 | case CURSOR: |
3778 | /* |
||
3779 | @ cursor 'some CSS cursor_style' |
||
3780 | @ alternative : pointer |
||
3781 | @ style can be any valid CSS property value, like crosshair,grabbing,move etc |
||
3782 | @ wims will not check the validity of your cursor declaration |
||
3783 | */ |
||
3784 | fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1)); |
||
3785 | break; |
||
8071 | schaersvoo | 3786 | case MOUSE_DISPLAY: |
3787 | /* |
||
9385 | schaersvoo | 3788 | @ display x|y|xy|degree|radius,color,fontsize |
3789 | @ will display the mouse cursor coordinates as x-only,y-only,(x:y),<br />the radius of a circle (this only in case 'userdraw circle(s),color' !!<br />or the angle in degrees ( rhe angle between x-axis;(0:0);(x:y) |
||
3790 | @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values |
||
3791 | @ just like commands 'mouse','mousex','mousey','mouse_degree'...only other name) |
||
8071 | schaersvoo | 3792 | */ |
3793 | temp = get_string_argument(infile,0); |
||
8112 | schaersvoo | 3794 | if( strstr(temp,"xy") != NULL ){ |
3795 | int_data[0] = 2; |
||
8071 | schaersvoo | 3796 | }else{ |
8112 | schaersvoo | 3797 | if( strstr(temp,"y") != NULL ){ |
3798 | int_data[0] = 1; |
||
8071 | schaersvoo | 3799 | }else{ |
8112 | schaersvoo | 3800 | if( strstr(temp,"x") != NULL ){ |
3801 | int_data[0] = 0; |
||
8129 | schaersvoo | 3802 | }else{ |
8112 | schaersvoo | 3803 | if(strstr(temp,"degree") != NULL){ |
3804 | int_data[0] = 3; |
||
8071 | schaersvoo | 3805 | }else{ |
8129 | schaersvoo | 3806 | if(strstr(temp,"radius") != NULL){ |
3807 | int_data[0] = 4; |
||
3808 | }else{ |
||
3809 | int_data[0] = 2; |
||
3810 | } |
||
8112 | schaersvoo | 3811 | } |
8129 | schaersvoo | 3812 | } |
8071 | schaersvoo | 3813 | } |
8129 | schaersvoo | 3814 | } |
8071 | schaersvoo | 3815 | stroke_color = get_color(infile,0); |
3816 | font_size = (int) (get_real(infile,1)); |
||
3817 | tmp_buffer = my_newmem(26); |
||
3818 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
3819 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]); |
||
3820 | break; |
||
3821 | case MOUSE_DEGREE: |
||
3822 | /* |
||
3823 | @ mouse_degree color,fontsize |
||
9373 | schaersvoo | 3824 | @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using a fontfamily Ariel |
8071 | schaersvoo | 3825 | @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV |
9378 | schaersvoo | 3826 | @ <b>note</b>: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
8071 | schaersvoo | 3827 | |
3828 | */ |
||
3829 | stroke_color = get_color(infile,0); |
||
3830 | font_size = (int) (get_real(infile,1)); |
||
3831 | tmp_buffer = my_newmem(26); |
||
3832 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
3833 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3); |
||
3834 | break; |
||
7991 | schaersvoo | 3835 | case MOUSEX: |
3836 | /* |
||
3837 | @ mousex color,fontsize |
||
9373 | schaersvoo | 3838 | @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using the fontfamily Ariel |
9378 | schaersvoo | 3839 | @ <b>note</b>: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
7991 | schaersvoo | 3840 | |
3841 | */ |
||
3842 | stroke_color = get_color(infile,0); |
||
3843 | font_size = (int) (get_real(infile,1)); |
||
3844 | tmp_buffer = my_newmem(26); |
||
3845 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
3846 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0); |
||
3847 | break; |
||
3848 | case MOUSEY: |
||
3849 | /* |
||
3850 | @ mousey color,fontsize |
||
3851 | @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
9378 | schaersvoo | 3852 | @ <b>note</b>: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
7991 | schaersvoo | 3853 | |
3854 | */ |
||
3855 | stroke_color = get_color(infile,0); |
||
3856 | font_size = (int) (get_real(infile,1)); |
||
3857 | tmp_buffer = my_newmem(26); |
||
3858 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
3859 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1); |
||
3860 | break; |
||
7614 | schaersvoo | 3861 | case MOUSE: |
3862 | /* |
||
3863 | @ mouse color,fontsize |
||
7991 | schaersvoo | 3864 | @ will display the cursor (x:y) coordinates in 'color' and 'font size'<br /> using default fontfamily Ariel |
9378 | schaersvoo | 3865 | @ <b>note</b>: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
7988 | schaersvoo | 3866 | |
7614 | schaersvoo | 3867 | */ |
3868 | stroke_color = get_color(infile,0); |
||
3869 | font_size = (int) (get_real(infile,1)); |
||
7839 | schaersvoo | 3870 | tmp_buffer = my_newmem(26); |
3871 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
7991 | schaersvoo | 3872 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2); |
7614 | schaersvoo | 3873 | break; |
3874 | case INTOOLTIP: |
||
3875 | /* |
||
3876 | @ intooltip link_text |
||
3877 | @ link_text is a single line (span-element) |
||
8816 | schaersvoo | 3878 | @ link_text may also be an image URL 'http://some_server/images/my_image.png' or '$module_dir/gifs/my_image.jpg' |
7614 | schaersvoo | 3879 | @ link_text may contain HTML markup |
3880 | @ the canvas will be displayed in a tooltip on 'link_text' |
||
9379 | schaersvoo | 3881 | @ the canvas is default transparent: use command <a href="#bgcolor">'bgcolor color'</a> to adjust background-color<br />the link text will also be shown with this 'bgcolor'. |
9329 | schaersvoo | 3882 | @ many 'userinput stuff' will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefor these commands are mutually exclusive.<br />keep this in mind... |
7614 | schaersvoo | 3883 | */ |
9329 | schaersvoo | 3884 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");} |
9332 | schaersvoo | 3885 | if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");} |
7614 | schaersvoo | 3886 | tooltip_text = get_string(infile,1); |
3887 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
9329 | schaersvoo | 3888 | use_tooltip = 1; |
7614 | schaersvoo | 3889 | break; |
9329 | schaersvoo | 3890 | case POPUP: |
3891 | /* |
||
3892 | @ popup |
||
3893 | @ keyword (no arguments) |
||
3894 | @ if fly-script starts with keyword 'popup', the canvas image will be exclusively in a popup window (xsize px × ysize px) |
||
3895 | @ if keyword 'popup' is used after command 'size xsize,ysize' the canvas will also be displayed in a popup window with size 'xsize × ysize' |
||
9379 | schaersvoo | 3896 | @ the popup window will be embedded into the page as a 'normal' image , when 'status=done' ; override with keyword <a href="#status"> 'nostatus'</a> |
10961 | schaersvoo | 3897 | @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br /><em><br /> function read_all(){<br /> if( typeof popup !== 'undefined' ){<br /> var fun1 = popup['read_dragdrop'+canvas_scripts[0]];<br /> var fun2 = popup['read_canvas'+canvas_scripts[0]];<br /> popup.close();<br /> return "dragdrop="+fun1()+"\\ncanvas="+fun2();<br /> };<br /></em> |
3898 | @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like:<br /><em>popup.set_clock(clock_id,type,diff);</em><br />as js-function for a button (or something else) in your document page.<br />wherein <b>clock_id</b> starts with 0 for the first clock<br /><b>type</b> is 1 for Hours,2 for Minutes and 3 for Seconds<br /><b>diff</b> is the increment (positive or negative) per click |
||
9329 | schaersvoo | 3899 | */ |
3900 | use_tooltip = 2; |
||
3901 | break; |
||
7614 | schaersvoo | 3902 | case AUDIO: |
3903 | /* |
||
3904 | @ audio x,y,w,h,loop,visible,audiofile location |
||
3905 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
3906 | @ w,y : width and height in pixels |
||
3907 | @ loop : 0 or 1 ( 1 = loop audio fragment) |
||
3908 | @ visible : 0 or 1 (1 = show controls) |
||
3909 | @ audio format may be in *.mp3 or *.ogg |
||
3910 | @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format) |
||
3911 | @ if you are using *.ogg : be aware that Microsoft based systems not support it natively |
||
3912 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
||
3913 | @ example: upload both audio1.ogg and audio1.mp3 to http://server/files/<br />audio 0,0,http://server/files/audio1.mp3<br />svdraw will copy html-tag audio1.mp3 to audio1.ogg<br /> and the browser will play the compatible file (audio1.ogg or audio1.mp3)<br /> |
||
3914 | */ |
||
3915 | if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;} |
||
3916 | for(i=0;i<7;i++){ |
||
3917 | switch(i){ |
||
3918 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
3919 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
3920 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
3921 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
3922 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
3923 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
8224 | bpr | 3924 | case 6: |
7614 | schaersvoo | 3925 | temp = get_string(infile,1); |
3926 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
3927 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
3928 | string_length = snprintf(NULL,0, "draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp); |
||
3929 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3930 | snprintf(tmp_buffer,string_length,"draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp); |
||
3931 | add_to_buffer(tmp_buffer); |
||
3932 | break; |
||
3933 | default:break; |
||
3934 | } |
||
3935 | } |
||
3936 | reset(); |
||
3937 | break; |
||
3938 | case VIDEO: |
||
3939 | /* |
||
3940 | @ video x,y,w,h,videofile location |
||
3941 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
3942 | @ w,y : width and height in pixels |
||
3943 | @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4 |
||
3944 | @ video format may be in *.mp4 (todo:other formats) |
||
3945 | */ |
||
3946 | if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;} |
||
3947 | for(i=0;i<5;i++){ |
||
3948 | switch(i){ |
||
3949 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
3950 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
3951 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
3952 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
3953 | case 4: temp = get_string(infile,1); |
||
3954 | string_length = snprintf(NULL,0, "draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
3955 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3956 | snprintf(tmp_buffer,string_length,"draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
3957 | add_to_buffer(tmp_buffer); |
||
3958 | break; |
||
3959 | default:break; |
||
3960 | } |
||
3961 | } |
||
3962 | reset(); |
||
3963 | break; |
||
3964 | case HATCHFILL: |
||
3965 | /* |
||
3966 | @ hatchfill x0,y0,dx,dy,color |
||
3967 | @ x0,y0 in xrange / yrange |
||
3968 | @ distances dx,dy in pixels |
||
3969 | */ |
||
3970 | if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;} |
||
3971 | for(i=0;i<5;i++){ |
||
3972 | switch(i){ |
||
3973 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
3974 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
3975 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
3976 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
3977 | case 4: stroke_color = get_color(infile,1); |
||
3978 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
3979 | string_length = snprintf(NULL,0, "draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
3980 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3981 | snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
3982 | add_to_buffer(tmp_buffer); |
||
3983 | break; |
||
3984 | default:break; |
||
3985 | } |
||
3986 | } |
||
3987 | reset(); |
||
3988 | break; |
||
7647 | schaersvoo | 3989 | case DIAMONDFILL: |
3990 | /* |
||
3991 | @ diamondfill x0,y0,dx,dy,color |
||
3992 | @ x0,y0 in xrange / yrange |
||
3993 | @ distances dx,dy in pixels |
||
3994 | */ |
||
3995 | if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;} |
||
3996 | for(i=0;i<5;i++){ |
||
3997 | switch(i){ |
||
3998 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
3999 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
4000 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
4001 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
4002 | case 4: stroke_color = get_color(infile,1); |
||
4003 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
4004 | string_length = snprintf(NULL,0, "draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
4005 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4006 | snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
4007 | add_to_buffer(tmp_buffer); |
||
4008 | break; |
||
4009 | default:break; |
||
4010 | } |
||
4011 | } |
||
4012 | reset(); |
||
4013 | break; |
||
7614 | schaersvoo | 4014 | case GRIDFILL: |
4015 | /* |
||
4016 | @ gridfill x0,y0,dx,dy,color |
||
4017 | @ x0,y0 in xrange / yrange |
||
4018 | @ distances dx,dy in pixels |
||
9379 | schaersvoo | 4019 | @ a draggable object may <a href="#snaptogrid">snap_to_grid</a> (using keywords snaptogrid,xsnaprogrid, ysnaptogrid or snaptopoints) |
7883 | schaersvoo | 4020 | @ userdraw object may snap_to_grid |
7614 | schaersvoo | 4021 | */ |
4022 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
||
4023 | for(i=0;i<5;i++){ |
||
4024 | switch(i){ |
||
4025 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
4026 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
4027 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
4028 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
4029 | case 4: stroke_color = get_color(infile,1); |
||
4030 | string_length = snprintf(NULL,0, "draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
4031 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4032 | snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
4033 | add_to_buffer(tmp_buffer); |
||
4034 | break; |
||
4035 | default:break; |
||
4036 | } |
||
4037 | } |
||
4038 | reset(); |
||
4039 | break; |
||
4040 | case DOTFILL: |
||
4041 | /* |
||
4042 | @ dotfill x0,y0,dx,dy,color |
||
4043 | @ x0,y0 in xrange / yrange |
||
4044 | @ distances dx,dy in pixels |
||
4045 | @ radius of dots is linewidth |
||
4046 | */ |
||
4047 | if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;} |
||
4048 | for(i=0;i<5;i++){ |
||
4049 | switch(i){ |
||
4050 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
4051 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
4052 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
4053 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
4054 | case 4: stroke_color = get_color(infile,1); |
||
4055 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
||
4056 | string_length = snprintf(NULL,0, "draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
4057 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4058 | snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
4059 | add_to_buffer(tmp_buffer); |
||
4060 | break; |
||
4061 | default:break; |
||
4062 | } |
||
4063 | } |
||
4064 | reset(); |
||
4065 | break; |
||
4066 | case IMAGEFILL: |
||
4067 | /* |
||
4068 | @ imagefill dx,dy,image_url |
||
4069 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
||
4070 | @ After pattern filling ,the fill-color should be reset ! |
||
4071 | @ wims getins / image from class directory : imagefill 80,80,my_image.gif |
||
4072 | @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif |
||
4073 | @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg |
||
4074 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
||
4075 | */ |
||
4076 | if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;} |
||
4077 | for(i=0 ;i < 3 ; i++){ |
||
4078 | switch(i){ |
||
4079 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
||
4080 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
4081 | case 2: URL = get_string_argument(infile,1); |
||
4082 | string_length = snprintf(NULL,0, "draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize); |
||
4083 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4084 | snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize); |
||
4085 | add_to_buffer(tmp_buffer); |
||
4086 | break; |
||
4087 | } |
||
4088 | } |
||
8083 | schaersvoo | 4089 | reset(); |
7614 | schaersvoo | 4090 | break; |
11006 | schaersvoo | 4091 | case CANVASTYPE: |
4092 | canvas_type = (int) (get_real(infile,1)); |
||
4093 | /* |
||
4094 | @ canvastype TYPE |
||
4095 | @ for now only usefull before commands filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled |
||
4096 | @ default value of TYPE is DRAG_CANVAS e.g. 5 |
||
4097 | @ use another TYPE if you know what you are doing... |
||
4098 | @ other possible canvasses (transparent PNG pictures xsize x ysize on top of eachother)<ul><li>EXTERNAL_IMAGE_CANVAS = 0</li><li>BG_CANVAS = 1</li><li> STATIC_CANVAS = 2</li><li> MOUSE_CANVAS = 3 : used for command "mouse"</li><li> GRID_CANVAS = 4 :used for command "grid"</li><li> DRAG_CANVAS = 5 :default</li><li> DRAW_CANVAS = 6 :used for some static drawings</li><li> TEXT_CANVAS = 7 : used for text-strings</li><li> CLOCK_CANVAS = 8 : used for command "clock"</li><li> ANIMATE_CANVAS = 9 : not used for now</li><li> TRACE_CANVAS = 10 : used for command "trace_jscurve"</li><li> JSPLOT_CANVAS = 111 : will be increased with every new command "jscurve"</li> <li> FILL_CANVAS = 12 : this will be filled...so do not use ! </li><li> USERDRAW_JSPLOT 13 : will be increased with every new command "userinput function"</li></ul> |
||
4099 | */ |
||
4100 | break; |
||
7614 | schaersvoo | 4101 | case FILLTOBORDER: |
4102 | /* |
||
4103 | @ filltoborder x,y,bordercolor,color |
||
11006 | schaersvoo | 4104 | @ fill the region of point (x:y) with color 'color' |
7614 | schaersvoo | 4105 | @ any other color will not act as border to the bucket fill |
4106 | @ use this command after all boundary objects are declared. |
||
11006 | schaersvoo | 4107 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
9378 | schaersvoo | 4108 | @ <b>note</b>: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
7614 | schaersvoo | 4109 | */ |
4110 | for(i=0 ;i < 4 ; i++){ |
||
4111 | switch(i){ |
||
4112 | case 0:double_data[0] = get_real(infile,0);break; |
||
4113 | case 1:double_data[1] = get_real(infile,0);break; |
||
4114 | case 2:bgcolor = get_color(infile,0);break; |
||
4115 | case 3:fill_color = get_color(infile,1); |
||
4116 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
4117 | js_function[DRAW_FILLTOBORDER] = 1; |
||
11006 | schaersvoo | 4118 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
7614 | schaersvoo | 4119 | } |
4120 | decimals = find_number_of_digits(precision); |
||
7895 | schaersvoo | 4121 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
8071 | schaersvoo | 4122 | string_length = snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
7614 | schaersvoo | 4123 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 4124 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
7614 | schaersvoo | 4125 | add_to_buffer(tmp_buffer); |
4126 | break; |
||
4127 | default:break; |
||
8083 | schaersvoo | 4128 | } |
4129 | } |
||
4130 | reset(); |
||
7614 | schaersvoo | 4131 | break; |
4132 | case FLOODFILL: |
||
4133 | /* |
||
4134 | @ floodfill x,y,color |
||
9382 | schaersvoo | 4135 | @ alternative : fill x,y,color |
7614 | schaersvoo | 4136 | @ fill the region of point (x:y) with color 'color' |
4137 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
||
4138 | @ use this command after all boundary objects are declared. |
||
11006 | schaersvoo | 4139 | @ Use command 'userdraw clickfill,color' for user click driven flood fill. |
4140 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
||
9378 | schaersvoo | 4141 | @ <b>note</b>: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
7614 | schaersvoo | 4142 | */ |
4143 | for(i=0 ;i < 4 ; i++){ |
||
4144 | switch(i){ |
||
4145 | case 0:double_data[0] = get_real(infile,0);break; |
||
4146 | case 1:double_data[1] = get_real(infile,0);break; |
||
4147 | case 2:fill_color = get_color(infile,1); |
||
11005 | schaersvoo | 4148 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
4149 | js_function[DRAW_FILLTOBORDER] = 1; |
||
11006 | schaersvoo | 4150 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
7614 | schaersvoo | 4151 | } |
11005 | schaersvoo | 4152 | decimals = find_number_of_digits(precision); |
4153 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
4154 | string_length = snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
||
4155 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4156 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
||
4157 | add_to_buffer(tmp_buffer); |
||
4158 | |||
7614 | schaersvoo | 4159 | break; |
4160 | default:break; |
||
8083 | schaersvoo | 4161 | } |
4162 | } |
||
4163 | reset(); |
||
7614 | schaersvoo | 4164 | break; |
4165 | case SETPIXEL: |
||
4166 | /* |
||
4167 | @ setpixel x,y,color |
||
9379 | schaersvoo | 4168 | @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange |
8816 | schaersvoo | 4169 | @ pixels can <b>not</b> be dragged or clicked |
7614 | schaersvoo | 4170 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
4171 | */ |
||
4172 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
4173 | for(i=0;i<3;i++){ |
||
4174 | switch(i){ |
||
4175 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
4176 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
4177 | case 2: stroke_color = get_color(infile,1); |
||
4178 | string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
4179 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4180 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
4181 | add_to_buffer(tmp_buffer); |
||
4182 | break; |
||
4183 | default:break; |
||
4184 | } |
||
4185 | } |
||
4186 | reset(); |
||
4187 | break; |
||
4188 | case PIXELSIZE: |
||
4189 | /* |
||
4190 | @ pixelsize int |
||
9379 | schaersvoo | 4191 | @ in case you want to deviate from default pixelsize = 1(...) |
7614 | schaersvoo | 4192 | */ |
4193 | pixelsize = (int) get_real(infile,1); |
||
4194 | break; |
||
4195 | case PIXELS: |
||
4196 | /* |
||
4197 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
9379 | schaersvoo | 4198 | @ draw rectangular "points" with diameter 1 pixel |
8816 | schaersvoo | 4199 | @ pixels can <b>not</b> be dragged or clicked |
7614 | schaersvoo | 4200 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
4201 | */ |
||
4202 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
4203 | stroke_color=get_color(infile,0); |
||
4204 | i=0; |
||
4205 | c=0; |
||
4206 | while( ! done ){ /* get next item until EOL*/ |
||
4207 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
4208 | for( c = 0 ; c < 2; c++){ |
||
4209 | if(c == 0 ){ |
||
4210 | double_data[i] = get_real(infile,0); |
||
4211 | i++; |
||
4212 | } |
||
4213 | else |
||
4214 | { |
||
4215 | double_data[i] = get_real(infile,1); |
||
4216 | i++; |
||
4217 | } |
||
4218 | } |
||
4219 | } |
||
4220 | decimals = find_number_of_digits(precision); |
||
4221 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
4222 | string_length = snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
4223 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4224 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
4225 | add_to_buffer(tmp_buffer); |
||
8083 | schaersvoo | 4226 | reset(); |
7614 | schaersvoo | 4227 | break; |
4228 | case REPLYFORMAT: |
||
4229 | /* |
||
4230 | @ replyformat number |
||
8257 | schaersvoo | 4231 | @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop() |
7614 | schaersvoo | 4232 | @ default values should be fine ! |
8074 | schaersvoo | 4233 | @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing |
7963 | schaersvoo | 4234 | @ the last value for 'precision int' will be used to calculate the reply coordinates, if needed (read_canvas();) |
10965 | bpr | 4235 | @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br /><br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n<br /> x/y in pixels <br /> r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n<br /> x/y in xrange / yrange coordinate system<br /> r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n<br /> x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br /> x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br /> x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br /> x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br /> x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br /> Bx1,By1,Bx2,By2<br /> Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2<br /> x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br /> Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2<br /> x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br /> x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br /> x/y in pixels</li><li>15 = reply from inputfields,textareas<br /> reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>20 = read_canvas() will reply "object_number:x:y" of external images : object_number of the first draggable external image in the fly-script starts with 0 <br />e.g. expect something like 0:-5:4,1:6:2,2:-2:-5 <br /> the first image position is (-5:4) , the second image position is (6:2) and the third image position is (-2:-5) <li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li><li>22 = returns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br /> x/y in xrange / yrange coordinate system</li><li>23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline is x1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li><li>24 = read all inputfield values: even those set 'readonly'</li><li>25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>26 = rad1,rad2...rad_n : will return the radius (one or many) of the user drawn circle segment in radians </li><li>27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...</li><li>28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n <br />x / y / r in xrange / yrange coordinate system: may be used to reinput into command 'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'<br /> will not return anything else (e.g. no inputfields , text etc)</li></ul> |
7614 | schaersvoo | 4236 | @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...) |
4237 | */ |
||
4238 | reply_format = (int) get_real(infile,1); |
||
8074 | schaersvoo | 4239 | reply_precision = precision; |
7614 | schaersvoo | 4240 | break; |
4241 | case LEGENDCOLORS: |
||
4242 | /* |
||
4243 | @ legendcolors color1:color2:color3:...:color_n |
||
7956 | schaersvoo | 4244 | @ will be used to colour a legend: use this command after the legend command ! e.g.<br />legend test1:test2:test3<br />legendcolors blue:red:orange<br /> |
7614 | schaersvoo | 4245 | @ make sure the number of colours match the number of legend items |
8224 | bpr | 4246 | @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors' |
7614 | schaersvoo | 4247 | */ |
7956 | schaersvoo | 4248 | if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");} |
7614 | schaersvoo | 4249 | temp = get_string(infile,1); |
4250 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7956 | schaersvoo | 4251 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp); |
7614 | schaersvoo | 4252 | break; |
4253 | case LEGEND: |
||
4254 | /* |
||
4255 | @ legend string1:string2:string3....string_n |
||
4256 | @ will be used to create a legend for a graph |
||
9373 | schaersvoo | 4257 | @ also see command <a href='#piechart'>'piechart'</a> |
4258 | @ will use the same colors per default as used in the graphs : use command <a href='#legendcolors'>'legendcolors'</a> to override the default |
||
9427 | schaersvoo | 4259 | @ use command <a href="#fontsize">fontsize</a> to adjust. (command "fontfamily" is not active for command "legend") |
7614 | schaersvoo | 4260 | */ |
4261 | temp = get_string(infile,1); |
||
4262 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7956 | schaersvoo | 4263 | legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */ |
4264 | fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp); |
||
7614 | schaersvoo | 4265 | break; |
4266 | case XLABEL: |
||
4267 | /* |
||
4268 | @ xlabel some_string |
||
4269 | @ will be used to create a label for the x-axis (label is in quadrant I) |
||
9379 | schaersvoo | 4270 | @ can only be used together with command 'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering' |
10953 | bpr | 4271 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command) |
7614 | schaersvoo | 4272 | */ |
4273 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 4274 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 4275 | break; |
4276 | case YLABEL: |
||
4277 | /* |
||
4278 | @ ylabel some_string |
||
8224 | bpr | 4279 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
9379 | schaersvoo | 4280 | @ can only be used together with command <a href="#grid">'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering' |
10953 | bpr | 4281 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command) |
7614 | schaersvoo | 4282 | */ |
4283 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 4284 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 4285 | break; |
4286 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
||
4287 | /* |
||
9354 | schaersvoo | 4288 | @ linegraph x1:y1:x2:y2...x_n:y_n |
7614 | schaersvoo | 4289 | @ will plot your data in a graph |
9373 | schaersvoo | 4290 | @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a> |
4291 | @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a> |
||
4292 | @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner |
||
4293 | @ also see command <a href='#piechart'>'piechart'</a> |
||
7614 | schaersvoo | 4294 | @ multiple linegraphs may be used in a single plot |
9378 | schaersvoo | 4295 | @ <b>note</b>: your arguments are not checked by canvasdraw : use your javascript console in case of trouble... |
9373 | schaersvoo | 4296 | @ <ul><li>use command <a href='#strokecolor'>'strokecolor'</a> before a command 'linegraph' to set the color of this graph</li><li>use command <a href='#linewidth'>'linewidth'</a> before command 'linegraph' to set linewidth of this graph</li><li>use keyword <a href='#dashed'>'dashed'</a> before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command <a href='#dashtype'>'dashtype'</a> before command 'linegraph' to set the type of dashing of the (individual) graph</li></ul> |
8224 | bpr | 4297 | */ |
7614 | schaersvoo | 4298 | temp = get_string(infile,1); |
4299 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 4300 | fprintf(js_include_file,"var linegraph_%d = [\"%s\",\"%d\",\"%d\",\"%d\",\"%d\",\"%s\"];",linegraph_cnt,stroke_color,line_width,use_dashed,dashtype[0],dashtype[1],temp); |
7614 | schaersvoo | 4301 | linegraph_cnt++; |
4302 | reset(); |
||
4303 | break; |
||
7989 | schaersvoo | 4304 | case BARCHART: |
4305 | /* |
||
4306 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
9373 | schaersvoo | 4307 | @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a> |
4308 | @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a> |
||
4309 | @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner |
||
9406 | schaersvoo | 4310 | @ multiple barchart command may be used in a single script |
9373 | schaersvoo | 4311 | @ also see command <a href='#piechart'>'piechart'</a> |
9378 | schaersvoo | 4312 | @ <b>note</b>: your arguments are not checked by canvasdraw : use your javascript console in case of trouble... |
7989 | schaersvoo | 4313 | */ |
4314 | temp = get_string(infile,1); |
||
4315 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
4316 | fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp); |
||
4317 | barchart_cnt++; |
||
4318 | reset(); |
||
4319 | break; |
||
7614 | schaersvoo | 4320 | case CLOCK: |
4321 | /* |
||
4322 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
||
7997 | schaersvoo | 4323 | @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency |
7614 | schaersvoo | 4324 | @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments |
9478 | schaersvoo | 4325 | @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2<br />custom colours: clock 0,0,60,4,35,45,1,2,,,,yellow,red<br />custom colours: clock 0,0,60,4,35,45,1,2,white,green,blue,black,yellow |
7862 | schaersvoo | 4326 | @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass... |
10956 | schaersvoo | 4327 | @ interactive <ul><li>0 : not interactive, just clock(s)</li><li>1 : function read_canvas() will read all active clocks in H:M:S format<br />The active clock(s) can be adjusted by pupils</li><li>2 : function read_canvas() will return the clicked clock <br />(like multiplechoice; first clock in script in nr. 0 )</li><li>3: no prefab buttons...create your own buttons (or other means) to make the clock(s) adjustable by javascript function set_clock(num,type,diff)<br />wherein: num = clock id (starts with 0) ; type = 1 (hours) ; type = 2 (minutes) ; type = 3 (seconds) <br />and diff = the increment of 'type' (positive or negative) </li></ul> |
7614 | schaersvoo | 4328 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
4329 | @ no combinations with other reply_types allowed, for now |
||
8816 | schaersvoo | 4330 | @ if interactive is set to '1', 6 buttons per clock will be displayed for adjusting a clock (H+ M+ S+ H- M- S-)<br /> set_clock(clock_id,type,incr) <br />first clock has clock_id=0 ; type : H=1,M=2,S=3 ; incr : increment integer |
10957 | schaersvoo | 4331 | @ <b>note</b>: if you need multiple -interactive- clocks on a webpage, use multiple 'clock' commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page |
9438 | schaersvoo | 4332 | @ <b>note</b>: clocks will not zoom or pan, when using command <a href='#zoom'>'zoom'</a> |
7614 | schaersvoo | 4333 | */ |
4334 | if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;} |
||
4335 | |||
4336 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
4337 | for(i=0;i<9;i++){ |
||
4338 | switch(i){ |
||
4339 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
4340 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
4341 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
4342 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
4343 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
4344 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
7783 | schaersvoo | 4345 | case 6: int_data[6] = get_real(infile,0);if(int_data[6] < 0 || int_data[6] > 2){canvas_error("hourglass can be 0,1 or 2");}break;/* type hourglass */ |
9478 | schaersvoo | 4346 | case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/ |
7783 | schaersvoo | 4347 | switch(int_data[7]){ |
4348 | case 0:break; |
||
4349 | case 1:if(clock_cnt == 0){ |
||
10956 | schaersvoo | 4350 | if( reply_format == 0 ){ |
4351 | reply_format = 18; /* user sets clock */ |
||
4352 | /* string_length = snprintf(NULL,0,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
4353 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4354 | snprintf(tmp_buffer,string_length,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
4355 | add_to_buffer(tmp_buffer); |
||
4356 | */ |
||
4357 | fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
4358 | } |
||
4359 | else |
||
4360 | { |
||
4361 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
4362 | } |
||
4363 | } |
||
4364 | fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt); |
||
4365 | break; |
||
4366 | case 3:if(clock_cnt == 0){ |
||
4367 | if( reply_format == 0 ){ |
||
4368 | reply_format = 18; /* user sets clock */ |
||
4369 | fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,1,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
4370 | } |
||
4371 | else |
||
4372 | { |
||
4373 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
4374 | } |
||
4375 | } |
||
10965 | bpr | 4376 | /* |
8130 | schaersvoo | 4377 | fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt); |
10956 | schaersvoo | 4378 | */ |
7783 | schaersvoo | 4379 | break; |
4380 | case 2:if( reply_format == 0 ){ |
||
4381 | reply_format = 19; /* "onclick */ |
||
9478 | schaersvoo | 4382 | fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();canvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();var x = evt.clientX - canvas_rect.left;var y = evt.clientY - canvas_rect.top;var p = 0;var name;var t = true;while(t){try{name = eval('clocks'+p);if( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,\"lightblue\",name.fg_color);};}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};p++;}catch(e){t=false;};};};};\n"); |
7783 | schaersvoo | 4383 | } |
4384 | else |
||
4385 | { |
||
4386 | if( reply_format != 19){ |
||
7614 | schaersvoo | 4387 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
4388 | } |
||
7783 | schaersvoo | 4389 | } |
4390 | break; |
||
4391 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
4392 | } |
||
4393 | break; |
||
8224 | bpr | 4394 | case 8: |
8130 | schaersvoo | 4395 | if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */ |
4396 | fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity); |
||
4397 | } |
||
9478 | schaersvoo | 4398 | temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/ |
7614 | schaersvoo | 4399 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
4400 | if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";} |
||
9438 | schaersvoo | 4401 | string_length = snprintf(NULL,0,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp); |
7614 | schaersvoo | 4402 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
9438 | schaersvoo | 4403 | snprintf(tmp_buffer,string_length,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp); |
7614 | schaersvoo | 4404 | add_to_buffer(tmp_buffer); |
9438 | schaersvoo | 4405 | fprintf(js_include_file,"var clocks%d;",clock_cnt); |
7614 | schaersvoo | 4406 | clock_cnt++; |
4407 | break; |
||
4408 | default:break; |
||
4409 | } |
||
4410 | } |
||
4411 | break; |
||
4412 | case PIECHART: |
||
4413 | /* |
||
4414 | @ piechart xc,yc,radius,'data+colorlist' |
||
4415 | @ (xc : yc) center of circle diagram in xrange/yrange |
||
4416 | @ radius in pixels |
||
4417 | @ data+color list: a colon separated list of raw data and corresponding colours<br />canvasdraw will not check validity of colornames...<br />in case of trouble look into javascript debugging of your browser |
||
4418 | @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white |
||
4419 | @ the number of colors must match the number of data. |
||
9373 | schaersvoo | 4420 | @ use command "<a href='#opacity'>'opacity'</a> to adjust fill_opacity of colours |
4421 | @ use command <a href='#legend'>'legend'</a> to automatically create a legend <br />using the same colours as pie segments<br />unicode allowed in legend<br />expect javascript trouble if the amount of 'pie-slices', 'pie-colours' 'pie-legend-titles' do not match<br />a javascript console is your best friend...<br />use command 'fontfamily' to set the font of the legend. |
||
7614 | schaersvoo | 4422 | */ |
8224 | bpr | 4423 | if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;} |
7614 | schaersvoo | 4424 | for(i=0;i<5;i++){ |
4425 | switch(i){ |
||
4426 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
4427 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
4428 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
||
4429 | case 3: temp = get_string(infile,1); |
||
4430 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
7956 | schaersvoo | 4431 | string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family); |
7614 | schaersvoo | 4432 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7956 | schaersvoo | 4433 | snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family); |
7614 | schaersvoo | 4434 | add_to_buffer(tmp_buffer); |
4435 | break; |
||
4436 | default:break; |
||
4437 | } |
||
4438 | } |
||
4439 | reset(); |
||
4440 | break; |
||
9465 | schaersvoo | 4441 | case USERBOXPLOTDATA: |
9433 | schaersvoo | 4442 | /* |
10953 | bpr | 4443 | @ userboxplotdata |
9465 | schaersvoo | 4444 | @ keyword, no arguments |
4445 | @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a> |
||
4446 | @ if set, the student will have to generate some statistical data. These data should be put in a named array "student_boxplot_data" |
||
4447 | @ "min,Q1,median,Q3,max" are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot. |
||
4448 | @ see command <a href="#userboxplot">'userboxplot'</a> for calling 'draw_boxplot()' |
||
4449 | */ |
||
4450 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
4451 | fprintf(js_include_file,"var boxplot_source = 2;\n"); |
||
4452 | js_function[DRAW_JSBOXPLOT] = 1; |
||
10953 | bpr | 4453 | |
9465 | schaersvoo | 4454 | break; |
4455 | case USERBOXPLOT: |
||
4456 | /* |
||
10953 | bpr | 4457 | @ userboxplot |
9465 | schaersvoo | 4458 | @ keyword, no arguments |
4459 | @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a> |
||
4460 | @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the 'draw_boxplot' function |
||
4461 | @ for example:<br />put the canvas-script into a html element with id='boxplot'and set style='display:none'<br />define a variable called 'student_boxplot' and fill it with the 5 student-data (from inputfields or something)<br />var student_boxplot = new Array(5)<br />function show_boxplot(){<br />student_boxplot[0] = min;<br />student_boxplot[1] = Q1;<br />student_boxplot[2] = median;<br />student_boxplot[3] = Q3;<br />student_boxplot[4] = max;<br />document.getElementById('boxplot').style.display = "block";<br />draw_boxplot(12345,1,2.00,5.00,[0,0,0,0,0],4,"0,0,255",0.78,"255,165,0",0.60,1,0,1,1);<br />};<br />In the canvas-script the function draw_boxplot has the following arguments:<br />draw_boxplot=function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1) |
||
4462 | */ |
||
4463 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
4464 | fprintf(js_include_file,"var boxplot_source = 3;\n"); |
||
4465 | js_function[DRAW_JSBOXPLOT] = 2; |
||
4466 | break; |
||
4467 | case BOXPLOTDATA: |
||
4468 | /* |
||
4469 | @ boxplotdata some_data |
||
9433 | schaersvoo | 4470 | @ 'some_data' are a list of numbers separated by a comma "," (items) |
4471 | @ only be used before command 'boxplot': the command <a href="#boxplot">'boxplot'</a> will provide the boxplot drawing of the data. |
||
9465 | schaersvoo | 4472 | @ xrange 0,100<br />yrange 0,10<br />boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23<br />boxplot x,4,5 |
9433 | schaersvoo | 4473 | @ <b>note</b>: wims will not check your data input | format. use js-error console to debug any problems. |
4474 | @ a javascript function 'statistics()' will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function. |
||
4475 | */ |
||
4476 | if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;} |
||
4477 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
9465 | schaersvoo | 4478 | fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1)); |
10953 | bpr | 4479 | |
9433 | schaersvoo | 4480 | break; |
4481 | case BOXPLOT: |
||
4482 | /* |
||
9465 | schaersvoo | 4483 | @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max |
9433 | schaersvoo | 4484 | @ example:<br />xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245<br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8 |
4485 | @ example:<br />xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245<br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8 |
||
9465 | schaersvoo | 4486 | @ use command <a href='filled'>'filled'</a> to fill the box<br /><b>note:</b> the strokecolor is used for filling Q1, the fillcolor is used for filling Q3 |
4487 | @ use command <a href='#opacity'>'opacity'</a> to adjust fill_opacity of stroke and fill colours |
||
9433 | schaersvoo | 4488 | @ use command <a href='#legend'>'legend'</a> to automatically create a legend <br />unicode allowed in legend<br />use command 'fontfamily' to set the font of the legend. |
9434 | schaersvoo | 4489 | @ there is no limit to the number of boxplots used. |
9465 | schaersvoo | 4490 | @ can <b>not</b> be set draggable (<a href='#onclick'>'onclick'</a> is not ready ,yet) |
4491 | @ use keyword <a href="#userboxplot">'userboxplot'</a> before command boxplot, if a pupil must draw a boxplot (using his own min,Q1,median,Q3,max data) |
||
4492 | @ use keyword <a href="#userboxplotdata">'userboxplotdata'</a> before command boxplot, if a pupil must generate the data by some means. |
||
4493 | @ use command <a href="#boxplotdata">'boxplotdata'</a> when the boxplot should be drawn from wims-generated raw statistical date |
||
9433 | schaersvoo | 4494 | */ |
4495 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
4496 | for(i=0;i<8;i++){ |
||
4497 | switch(i){ |
||
9466 | schaersvoo | 4498 | case 0: temp = get_string_argument(infile,0); |
4499 | if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */ |
||
9433 | schaersvoo | 4500 | case 1: double_data[0] = get_real(infile,0);break;/* height | width */ |
10953 | bpr | 4501 | case 2: |
4502 | if( js_function[DRAW_JSBOXPLOT] == 0 ){ |
||
9466 | schaersvoo | 4503 | double_data[1] = get_real(infile,0); |
9465 | schaersvoo | 4504 | fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */ |
9466 | schaersvoo | 4505 | } |
4506 | else |
||
4507 | { |
||
4508 | double_data[1] = get_real(infile,1); |
||
4509 | double_data[2] = 1; |
||
4510 | double_data[3] = 1; |
||
4511 | double_data[4] = 1; |
||
4512 | double_data[5] = 1; |
||
4513 | double_data[6] = 1; |
||
4514 | double_data[7] = 1; |
||
4515 | i=8; |
||
4516 | } |
||
4517 | break;/* center value x or y */ |
||
4518 | case 3: double_data[2] = get_real(infile,0); break;/* min */ |
||
4519 | case 4: double_data[3] = get_real(infile,0); break;/* Q1 */ |
||
4520 | case 5: double_data[4] = get_real(infile,0); break;/* median */ |
||
4521 | case 6: double_data[5] = get_real(infile,0); break;/* Q3 */ |
||
4522 | case 7: double_data[6] = get_real(infile,1); break;/* max */ |
||
9433 | schaersvoo | 4523 | default:break; |
4524 | } |
||
4525 | } |
||
9466 | schaersvoo | 4526 | decimals = find_number_of_digits(precision); |
4527 | /*function draw_boxplot(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)*/ |
||
4528 | string_length = snprintf(NULL,0, "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]); |
||
4529 | check_string_length(string_length); |
||
4530 | tmp_buffer = my_newmem(string_length+1); |
||
4531 | snprintf(tmp_buffer,string_length, "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]); |
||
4532 | add_to_buffer(tmp_buffer); |
||
4533 | boxplot_cnt++; |
||
9433 | schaersvoo | 4534 | reset(); |
4535 | break; |
||
7614 | schaersvoo | 4536 | case STATUS: |
7877 | schaersvoo | 4537 | /* |
9385 | schaersvoo | 4538 | @ status |
4539 | @ keyword |
||
4540 | @ alernative : nostatus |
||
4541 | @ used to override the effects of "status=done" in wims (answer.phtml) |
||
4542 | @ affects 'readonly' in inputfields / textarea's in canvasimage and all userdraw based commands |
||
4543 | @ e.g.: if keyword 'status' is set, the pupil will be able to modify the canvas when the 'wims $status variable' is set to 'done' |
||
7877 | schaersvoo | 4544 | */ |
8224 | bpr | 4545 | |
7877 | schaersvoo | 4546 | fprintf(js_include_file,"\nwims_status=\"waiting\";\n"); |
7614 | schaersvoo | 4547 | break; |
7735 | schaersvoo | 4548 | case XLOGBASE: |
7729 | schaersvoo | 4549 | /* |
7735 | schaersvoo | 4550 | @ xlogbase number |
4551 | @ sets the logbase number for the x-axis |
||
7729 | schaersvoo | 4552 | @ default value 10 |
7735 | schaersvoo | 4553 | @ use together with commands xlogscale / xylogscale |
7729 | schaersvoo | 4554 | */ |
7735 | schaersvoo | 4555 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7729 | schaersvoo | 4556 | break; |
7735 | schaersvoo | 4557 | case YLOGBASE: |
4558 | /* |
||
4559 | @ ylogbase number |
||
4560 | @ sets the logbase number for the y-axis |
||
4561 | @ default value 10 |
||
4562 | @ use together with commands ylogscale / xylogscale |
||
4563 | */ |
||
4564 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
4565 | break; |
||
7614 | schaersvoo | 4566 | case XLOGSCALE: |
4567 | /* |
||
7735 | schaersvoo | 4568 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
4569 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
4570 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
||
4571 | @ the linewidth is set using command 'linewidth int' |
||
9373 | schaersvoo | 4572 | @ the opacity of major / minor grid lines is set by command <a href='#opacity'>'opacity</a>' |
7735 | schaersvoo | 4573 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' |
8224 | bpr | 4574 | @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'xlogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul> |
9378 | schaersvoo | 4575 | @ <b>note</b>: the complete canvas will be used for the 'log paper' |
4576 | @ <b>note</b>: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
4577 | @ <b>note</b>: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
4578 | @ <b>note</b>: when using something like 'xrange 0.0001,0.01'...combined with commands <a href='#mouse'>'mouse'</a> and/or <a href='#userdraw'>'userdraw</a>...<br /> make sure the <a href='#precision'>precision</a> is set accordingly |
||
4579 | @ <b>note</b>: in case of userdraw , the use of keyword <a href='#userinput_xy'>'userinput_xy'</a> may be handy ! |
||
9383 | schaersvoo | 4580 | @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result... |
7614 | schaersvoo | 4581 | */ |
7735 | schaersvoo | 4582 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
4583 | if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;} |
||
4584 | for(i=0;i<4;i++){ |
||
4585 | switch(i){ |
||
4586 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
4587 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
4588 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 4589 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 4590 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
7735 | schaersvoo | 4591 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 4592 | snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
7735 | schaersvoo | 4593 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
4594 | add_to_buffer(tmp_buffer); |
||
4595 | break; |
||
4596 | default:break; |
||
4597 | } |
||
4598 | } |
||
7614 | schaersvoo | 4599 | break; |
4600 | case YLOGSCALE: |
||
7729 | schaersvoo | 4601 | /* |
4602 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
4603 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
4604 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
||
4605 | @ the linewidth is set using command 'linewidth int' |
||
4606 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
7735 | schaersvoo | 4607 | @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number' |
8224 | bpr | 4608 | @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'ylogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul> |
9378 | schaersvoo | 4609 | @ <b>note</b>: the complete canvas will be used for the 'log paper' |
4610 | @ <b>note</b>: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
4611 | @ <b>note</b>: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
4612 | @ <b>note</b>: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000') |
||
4613 | @ <b>note</b>: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
||
9383 | schaersvoo | 4614 | @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result... |
7729 | schaersvoo | 4615 | */ |
4616 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
4617 | if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;} |
||
4618 | for(i=0;i<4;i++){ |
||
4619 | switch(i){ |
||
4620 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
4621 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
4622 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 4623 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 4624 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
7729 | schaersvoo | 4625 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 4626 | snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
7735 | schaersvoo | 4627 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 4628 | add_to_buffer(tmp_buffer); |
4629 | break; |
||
4630 | default:break; |
||
4631 | } |
||
4632 | } |
||
7614 | schaersvoo | 4633 | break; |
4634 | case XYLOGSCALE: |
||
7735 | schaersvoo | 4635 | /* |
4636 | @ xylogscale majorcolor,minorcolor |
||
4637 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
4638 | @ the linewidth is set using command 'linewidth int' |
||
4639 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
4640 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number' |
||
8224 | bpr | 4641 | @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul> |
9378 | schaersvoo | 4642 | @ <b>note</b>: the complete canvas will be used for the 'log paper' |
4643 | @ <b>note</b>: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
4644 | @ <b>note</b>: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
4645 | @ <b>note</b>: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000') |
||
4646 | @ <b>note</b>: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
||
9383 | schaersvoo | 4647 | @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result... |
7735 | schaersvoo | 4648 | */ |
4649 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
4650 | if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;} |
||
4651 | for(i=0;i<2;i++){ |
||
4652 | switch(i){ |
||
4653 | case 0: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 4654 | case 1: fill_color = get_color(infile,1); |
7779 | schaersvoo | 4655 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision); |
7735 | schaersvoo | 4656 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 4657 | snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision); |
7735 | schaersvoo | 4658 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
4659 | add_to_buffer(tmp_buffer); |
||
4660 | break; |
||
4661 | default:break; |
||
4662 | } |
||
4663 | } |
||
4664 | break; |
||
7614 | schaersvoo | 4665 | default:sync_input(infile); |
4666 | break; |
||
4667 | } |
||
8224 | bpr | 4668 | } |
7614 | schaersvoo | 4669 | /* we are done parsing script file */ |
7983 | schaersvoo | 4670 | /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */ |
4671 | if( found_size_command == 1 ){ |
||
4672 | fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize); |
||
4673 | } |
||
4674 | else |
||
4675 | { |
||
4676 | if( found_size_command != 3 ){ |
||
8222 | schaersvoo | 4677 | canvas_error("Please specify both xrange and yrange ..."); |
7983 | schaersvoo | 4678 | } |
4679 | } |
||
8257 | schaersvoo | 4680 | |
8222 | schaersvoo | 4681 | /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects ! */ |
7614 | schaersvoo | 4682 | add_javascript_functions(js_function,canvas_root_id); |
4683 | /* add read_canvas() etc functions if needed */ |
||
8257 | schaersvoo | 4684 | if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);} |
7797 | schaersvoo | 4685 | if( use_pan_and_zoom == TRUE ){ |
4686 | /* in case of zooming ... */ |
||
7729 | schaersvoo | 4687 | fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\ |
7797 | schaersvoo | 4688 | precision = %d;var xmin_start=xmin;var xmax_start=xmax;\ |
7729 | schaersvoo | 4689 | var ymin_start=ymin;var ymax_start=xmax;\ |
4690 | var zoom_x_increment=0;var zoom_y_increment=0;\ |
||
4691 | var pan_x_increment=0;var pan_y_increment=0;\ |
||
4692 | if(use_ylogscale == 0 ){\ |
||
7956 | schaersvoo | 4693 | zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\ |
7729 | schaersvoo | 4694 | }else{\ |
4695 | zoom_x_increment = (xmax - xmin)/20;\ |
||
4696 | pan_x_increment = (xmax - xmin)/20;\ |
||
4697 | };\ |
||
9406 | schaersvoo | 4698 | var zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 4699 | function start_canvas%d(type){\ |
9406 | schaersvoo | 4700 | zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 4701 | switch(type){\ |
7729 | schaersvoo | 4702 | case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\ |
4703 | case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\ |
||
7653 | schaersvoo | 4704 | case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\ |
4705 | case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\ |
||
4706 | case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\ |
||
4707 | case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\ |
||
11004 | schaersvoo | 4708 | case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\ |
7653 | schaersvoo | 4709 | default:break;\ |
4710 | };\ |
||
4711 | if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\ |
||
4712 | if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\ |
||
9406 | schaersvoo | 4713 | try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\ |
4714 | if(typeof redraw_all%d === 'function' ){redraw_all%d(zoom_xy);}\ |
||
4715 | %s ;\ |
||
7653 | schaersvoo | 4716 | };\ |
7797 | schaersvoo | 4717 | start_canvas%d(333);\ |
9438 | schaersvoo | 4718 | };\ |
4719 | \n<!-- end wims_canvas_function -->\n\ |
||
9406 | schaersvoo | 4720 | wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id); |
7797 | schaersvoo | 4721 | } |
4722 | else |
||
4723 | { |
||
4724 | /* no zoom, just add buffer */ |
||
4725 | fprintf(js_include_file,"\n<!-- add buffer -->\n\ |
||
4726 | %s\ |
||
4727 | };\n\ |
||
4728 | <!-- end wims_canvas_function -->\n\ |
||
4729 | wims_canvas_function%d();\n",buffer,canvas_root_id); |
||
4730 | } |
||
7614 | schaersvoo | 4731 | /* done writing the javascript include file */ |
4732 | fclose(js_include_file); |
||
4733 | |||
4734 | } |
||
4735 | |||
4736 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
9329 | schaersvoo | 4737 | if( use_tooltip > 0 ){ |
4738 | if( use_tooltip == 1 ){ |
||
4739 | add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize); |
||
4740 | } |
||
4741 | else |
||
4742 | { |
||
4743 | if( use_tooltip == 2 ){ |
||
4744 | add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd); |
||
4745 | } |
||
4746 | } |
||
4747 | } |
||
7614 | schaersvoo | 4748 | exit(EXIT_SUCCESS); |
4749 | } |
||
4750 | /* end main() */ |
||
4751 | |||
4752 | /****************************************************************************** |
||
4753 | ** |
||
4754 | ** sync_input |
||
4755 | ** |
||
4756 | ** synchronises input line - reads to end of line, leaving file pointer |
||
4757 | ** at first character of next line. |
||
4758 | ** |
||
4759 | ** Used by: |
||
4760 | ** main program - error handling. |
||
4761 | ** |
||
4762 | ******************************************************************************/ |
||
4763 | void sync_input(FILE *infile) |
||
4764 | { |
||
4765 | int c = 0; |
||
4766 | |||
7658 | schaersvoo | 4767 | if( c == '\n' || c == ';' ) return; |
4768 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 4769 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 4770 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 4771 | return; |
4772 | } |
||
4773 | |||
4774 | /******************************************************************************/ |
||
4775 | |||
4776 | char *str_replace(const char *str, const char *old, const char *new){ |
||
4777 | /* http://creativeandcritical.net/str-replace-c/ */ |
||
4778 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
4779 | char *ret, *r; |
||
4780 | const char *p, *q; |
||
4781 | size_t oldlen = strlen(old); |
||
4782 | size_t count = 0; |
||
4783 | size_t retlen = 0; |
||
4784 | size_t newlen = strlen(new); |
||
4785 | if (oldlen != newlen){ |
||
4786 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
4787 | count++; |
||
4788 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
4789 | } |
||
8224 | bpr | 4790 | } |
7614 | schaersvoo | 4791 | else |
4792 | { |
||
4793 | retlen = strlen(str); |
||
4794 | } |
||
8224 | bpr | 4795 | |
7614 | schaersvoo | 4796 | if ((ret = malloc(retlen + 1)) == NULL){ |
4797 | ret = NULL; |
||
4798 | canvas_error("string argument is NULL"); |
||
4799 | } |
||
4800 | else |
||
4801 | { |
||
4802 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
4803 | size_t l = q - p; |
||
4804 | memcpy(r, p, l); |
||
4805 | r += l; |
||
4806 | memcpy(r, new, newlen); |
||
4807 | r += newlen; |
||
4808 | } |
||
4809 | strcpy(r, p); |
||
4810 | } |
||
4811 | return ret; |
||
4812 | } |
||
4813 | |||
4814 | /******************************************************************************/ |
||
7848 | bpr | 4815 | |
7614 | schaersvoo | 4816 | char *get_color(FILE *infile , int last){ |
4817 | int c,i = 0,is_hex = 0; |
||
4818 | char temp[MAX_COLOR_STRING], *string; |
||
8305 | schaersvoo | 4819 | const char *not_allowed = "0123456789"; |
10891 | schaersvoo | 4820 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) && ( c != '\t' ) ){ |
7614 | schaersvoo | 4821 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
4822 | if( c == '#' ){ |
||
4823 | is_hex = 1; |
||
4824 | } |
||
4825 | if( c != ' '){ |
||
8304 | schaersvoo | 4826 | if( is_hex == 0 ){if(strchr(not_allowed,c) != 0){canvas_error("found something like a number...but is should have been a colour or #hex color number...<br />Do not use R,G,B !!! ");}} |
7614 | schaersvoo | 4827 | temp[i]=tolower(c); |
4828 | i++; |
||
4829 | } |
||
4830 | } |
||
10891 | schaersvoo | 4831 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
4832 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 4833 | if( c == EOF ){finished = 1;} |
4834 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
4835 | temp[i]='\0'; |
||
4836 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
4837 | if( is_hex == 1 ){ |
||
4838 | char red[3], green[3], blue[3]; |
||
4839 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
4840 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
4841 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
4842 | int r = (int) strtol(red, NULL, 16); |
||
4843 | int g = (int) strtol(green, NULL, 16); |
||
4844 | int b = (int) strtol(blue, NULL, 16); |
||
4845 | string = (char *)my_newmem(12); |
||
4846 | snprintf(string,11,"%d,%d,%d",r,g,b); |
||
4847 | return string; |
||
4848 | } |
||
4849 | else |
||
4850 | { |
||
4851 | string = (char *)my_newmem(sizeof(temp)); |
||
4852 | snprintf(string,sizeof(temp),"%s",temp); |
||
8304 | schaersvoo | 4853 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
7614 | schaersvoo | 4854 | if( strcmp( colors[i].name , string ) == 0 ){ |
4855 | return colors[i].rgb; |
||
4856 | } |
||
4857 | } |
||
8304 | schaersvoo | 4858 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
7614 | schaersvoo | 4859 | } |
8304 | schaersvoo | 4860 | return "0,0,255"; |
7614 | schaersvoo | 4861 | } |
4862 | |||
4863 | char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
4864 | int c,i=0; |
||
4865 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 4866 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){ |
7614 | schaersvoo | 4867 | temp[i]=c; |
4868 | i++; |
||
4869 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
4870 | } |
||
10891 | schaersvoo | 4871 | if( ( c == '\n' || c == '\t' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
4872 | if( c == '\n' || c == '\t') { done = TRUE; line_number++; } |
||
7614 | schaersvoo | 4873 | if( c == EOF ) { |
4874 | finished = 1; |
||
4875 | if( last != 1 ){ canvas_error("expected more arguments");} |
||
4876 | } |
||
4877 | temp[i]='\0'; |
||
4878 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");} |
||
4879 | string=(char *)my_newmem(strlen(temp)); |
||
4880 | snprintf(string,sizeof(temp),"%s",temp); |
||
4881 | return string; |
||
4882 | } |
||
4883 | |||
4884 | char *get_string_argument(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
4885 | int c,i=0; |
||
4886 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 4887 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){ |
7614 | schaersvoo | 4888 | temp[i]=c; |
4889 | i++; |
||
4890 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
4891 | } |
||
8224 | bpr | 4892 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
10891 | schaersvoo | 4893 | if( c == '\n' || c == '\t' ) { line_number++; } |
7614 | schaersvoo | 4894 | if( c == EOF ) {finished = 1;} |
9478 | schaersvoo | 4895 | if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");} |
7614 | schaersvoo | 4896 | temp[i]='\0'; |
10953 | bpr | 4897 | /* |
8322 | schaersvoo | 4898 | 17.10.2014 removed (question Perrin) |
4899 | may cause some unwanted effects... |
||
7614 | schaersvoo | 4900 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");} |
8322 | schaersvoo | 4901 | */ |
7614 | schaersvoo | 4902 | string=(char *)my_newmem(sizeof(temp)); |
4903 | snprintf(string,sizeof(temp),"%s",temp); |
||
4904 | done = TRUE; |
||
4905 | return string; |
||
4906 | } |
||
4907 | |||
4908 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0 : more arguments ; last=1 final argument */ |
||
4909 | int c,i=0,found_calc = 0; |
||
4910 | double y; |
||
4911 | char tmp[MAX_INT]; |
||
10953 | bpr | 4912 | /* |
4913 | these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs |
||
8383 | schaersvoo | 4914 | but there should be a better way to avoid segfaults ! |
8348 | schaersvoo | 4915 | */ |
4916 | const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/ |
||
4917 | const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */ |
||
10891 | schaersvoo | 4918 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){ |
7614 | schaersvoo | 4919 | if( c != ' ' ){ |
8224 | bpr | 4920 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 4921 | continue; |
8224 | bpr | 4922 | } |
7614 | schaersvoo | 4923 | else |
4924 | { |
||
8304 | schaersvoo | 4925 | c = tolower(c); |
4926 | if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");} |
||
4927 | if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */ |
||
7614 | schaersvoo | 4928 | tmp[i] = c; |
4929 | i++; |
||
4930 | } |
||
4931 | } |
||
4932 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
4933 | } |
||
10891 | schaersvoo | 4934 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
4935 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 4936 | if( c == EOF ){done = TRUE ; finished = 1;} |
4937 | tmp[i]='\0'; |
||
4938 | if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");} |
||
8304 | schaersvoo | 4939 | if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */ |
7848 | bpr | 4940 | void *f = eval_create(tmp); |
7614 | schaersvoo | 4941 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 4942 | y = eval_x(f, 1); |
7614 | schaersvoo | 4943 | /* if function is bogus; y = 1 : so no core dumps */ |
7848 | bpr | 4944 | eval_destroy(f); |
7614 | schaersvoo | 4945 | } |
4946 | else |
||
4947 | { |
||
4948 | y = atof(tmp); |
||
4949 | } |
||
4950 | return y; |
||
4951 | } |
||
8304 | schaersvoo | 4952 | |
4953 | |||
7614 | schaersvoo | 4954 | void canvas_error(char *msg){ |
8383 | schaersvoo | 4955 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg); |
7614 | schaersvoo | 4956 | finished = 1; |
4957 | exit(EXIT_SUCCESS); |
||
4958 | } |
||
4959 | |||
4960 | |||
4961 | /* convert x/y coordinates to pixel */ |
||
4962 | int x2px(double x){ |
||
4963 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
4964 | } |
||
4965 | |||
4966 | int y2px(double y){ |
||
4967 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
4968 | } |
||
4969 | |||
4970 | double px2x(int x){ |
||
4971 | return (x*(xmax - xmin)/xsize + xmin); |
||
4972 | } |
||
4973 | double px2y(int y){ |
||
4974 | return (y*(ymax - ymin)/ysize + ymin); |
||
4975 | } |
||
4976 | |||
4977 | void add_to_buffer(char *tmp){ |
||
4978 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
||
4979 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
4980 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
4981 | if( space_left > strlen(tmp)){ |
||
4982 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
4983 | } |
||
4984 | else |
||
4985 | { |
||
4986 | canvas_error("buffer is too big\n"); |
||
4987 | } |
||
4988 | tmp = NULL;free(tmp); |
||
4989 | return; |
||
4990 | } |
||
4991 | |||
4992 | void reset(){ |
||
4993 | if(use_filled == TRUE){use_filled = FALSE;} |
||
4994 | if(use_dashed == TRUE){use_dashed = FALSE;} |
||
4995 | if(use_rotate == TRUE){use_rotate = FALSE;} |
||
8379 | schaersvoo | 4996 | onclick = 0; |
7614 | schaersvoo | 4997 | } |
4998 | |||
4999 | |||
5000 | |||
5001 | /* What reply format in read_canvas(); |
||
5002 | |||
5003 | note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and inputfield.value() |
||
5004 | 1 = x1,x2,x3,x4....x_n |
||
5005 | y1,y2,y3,y4....y_n |
||
5006 | |||
5007 | x/y in pixels |
||
5008 | |||
5009 | 2 = x1,x2,x3,x4....x_n |
||
5010 | y1,y2,y3,y4....y_n |
||
5011 | x/y in xrange / yrange coordinate system |
||
5012 | |||
5013 | 3 = x1,x2,x3,x4....x_n |
||
5014 | y1,y2,y3,y4....y_n |
||
5015 | r1,r2,r3,r4....r_n |
||
5016 | |||
8224 | bpr | 5017 | x/y in pixels |
7614 | schaersvoo | 5018 | r in pixels |
5019 | |||
5020 | 4 = x1,x2,x3,x4....x_n |
||
5021 | y1,y2,y3,y4....y_n |
||
5022 | r1,r2,r3,r4....r_n |
||
5023 | |||
5024 | x/y in xrange / yrange coordinate system |
||
5025 | r in pixels |
||
5026 | |||
5027 | 5 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
5028 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
5029 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
5030 | By1,By2,By3,By4....By_n |
||
5031 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
5032 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
5033 | .... |
||
5034 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
5035 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
8224 | bpr | 5036 | |
7614 | schaersvoo | 5037 | x/y in pixels |
5038 | |||
5039 | 6 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
5040 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
5041 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
5042 | By1,By2,By3,By4....By_n |
||
5043 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
5044 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
5045 | .... |
||
5046 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
5047 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
5048 | |||
5049 | x/y in xrange / yrange coordinate system |
||
8224 | bpr | 5050 | |
7614 | schaersvoo | 5051 | 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
8224 | bpr | 5052 | |
7614 | schaersvoo | 5053 | x/y in pixels |
5054 | |||
5055 | 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
8224 | bpr | 5056 | |
7614 | schaersvoo | 5057 | x/y in xrange / yrange coordinate system |
5058 | |||
8224 | bpr | 5059 | 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 5060 | |
5061 | x/y in pixels |
||
5062 | |||
8224 | bpr | 5063 | 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 5064 | |
5065 | x/y in xrange / yrange coordinate system |
||
5066 | |||
5067 | 11 = Ax1,Ay1,Ax2,Ay2 |
||
5068 | Bx1,By1,Bx2,By2 |
||
5069 | Cx1,Cy1,Cx2,Cy2 |
||
5070 | Dx1,Dy1,Dx2,Dy2 |
||
5071 | ...... |
||
5072 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 5073 | |
7614 | schaersvoo | 5074 | x/y in xrange / yrange coordinate system |
5075 | |||
5076 | 12 = Ax1,Ay1,Ax2,Ay2 |
||
5077 | Bx1,By1,Bx2,By2 |
||
5078 | Cx1,Cy1,Cx2,Cy2 |
||
5079 | Dx1,Dy1,Dx2,Dy2 |
||
5080 | ...... |
||
5081 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 5082 | |
7614 | schaersvoo | 5083 | x/y in pixels |
5084 | |||
5085 | 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2 |
||
5086 | |||
5087 | x/y in xrange / yrange coordinate system |
||
5088 | 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2 |
||
5089 | x/y in pixels |
||
5090 | 15 = reply from inputfields,textareas |
||
5091 | reply1,reply2,reply3,...,reply_n |
||
7984 | schaersvoo | 5092 | only fields set write (a.g. will not read 'readonly' inputfield values' |
7614 | schaersvoo | 5093 | |
5094 | 16 = read mathml inputfields only |
||
5095 | |||
5096 | 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n |
||
5097 | when ready : calculate size_t of string via snprintf(NULL,0,"blah blah..."); |
||
5098 | |||
5099 | 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n |
||
5100 | 19 = return clicked object number (analogue to shape-library onclick) |
||
5101 | 20 = return x/y-data in x-range/y-range of all 'draggable' images |
||
5102 | 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n) |
||
5103 | 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n |
||
5104 | x/y in xrange / yrange coordinate system |
||
8224 | bpr | 5105 | 23 = answertype for a polyline : remove multiple occurences due to reclick on a point to create next polyline segment |
7984 | schaersvoo | 5106 | 24 = read all inputfield values: even those set 'readonly' |
8224 | bpr | 5107 | 25 = return all userdrawn arcs in degrees: |
5108 | 26 = return all userdrawn arcs in radians: |
||
8127 | schaersvoo | 5109 | 27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2... |
8322 | schaersvoo | 5110 | 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n |
10953 | bpr | 5111 | x/y/r in xrange / yrange coordinate system: may be used to reinput into command |
8322 | schaersvoo | 5112 | 'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n' |
5113 | will not return anything else (e.g. no inputfields , text etc) |
||
10953 | bpr | 5114 | 29 = mulidraw read : |
5115 | |||
7614 | schaersvoo | 5116 | */ |
5117 | |||
5118 | |||
8257 | schaersvoo | 5119 | void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){ |
7614 | schaersvoo | 5120 | /* just 1 reply type allowed */ |
8074 | schaersvoo | 5121 | fprintf(js_include_file,"\ |
5122 | \n<!-- begin set_reply_precision() -->\n\ |
||
5123 | function set_reply_precision(){\ |
||
5124 | var len = userdraw_x.length;\ |
||
5125 | var prec = %d;\ |
||
5126 | for(var p = 0 ; p < len ; p++ ){\ |
||
5127 | userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\ |
||
5128 | userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\ |
||
5129 | };\ |
||
5130 | len = userdraw_radius.length;\ |
||
5131 | if( len > 0 ){\ |
||
5132 | for(var p = 0 ; p < len ; p++ ){\ |
||
5133 | userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\ |
||
5134 | };\ |
||
5135 | };\ |
||
5136 | };",reply_precision); |
||
7963 | schaersvoo | 5137 | |
7614 | schaersvoo | 5138 | switch(type_reply){ |
8224 | bpr | 5139 | /* |
7614 | schaersvoo | 5140 | answers may have: |
5141 | x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers |
||
5142 | */ |
||
5143 | case 1: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5144 | \n<!-- begin function 1 read_canvas%d() -->\n\ |
5145 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5146 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 5147 | set_reply_precision();\ |
7614 | schaersvoo | 5148 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
5149 | var p = 0;var input_reply = new Array();\ |
||
5150 | if( document.getElementById(\"canvas_input0\")){\ |
||
5151 | var t = 0;\ |
||
5152 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5153 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5154 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5155 | p++;\ |
||
5156 | };\ |
||
5157 | t++;\ |
||
5158 | };\ |
||
5159 | };\ |
||
5160 | if( typeof userdraw_text != 'undefined' ){\ |
||
5161 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\ |
||
5162 | }\ |
||
5163 | else\ |
||
5164 | {\ |
||
5165 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\ |
||
5166 | }\ |
||
5167 | }\ |
||
5168 | else\ |
||
5169 | {\ |
||
5170 | if( typeof userdraw_text != 'undefined' ){\ |
||
5171 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\ |
||
5172 | }\ |
||
5173 | else\ |
||
5174 | {\ |
||
5175 | return userdraw_x+\"\\n\"+userdraw_y;\ |
||
5176 | }\ |
||
5177 | };\ |
||
8108 | schaersvoo | 5178 | };\n\ |
8257 | schaersvoo | 5179 | <!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5180 | break; |
5181 | case 2: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5182 | \n<!-- begin function 2 read_canvas%d() -->\n\ |
5183 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5184 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 5185 | set_reply_precision();\ |
7614 | schaersvoo | 5186 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
8074 | schaersvoo | 5187 | var prec = %d;\ |
7614 | schaersvoo | 5188 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5189 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
5190 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
7614 | schaersvoo | 5191 | p++;\ |
5192 | };\ |
||
5193 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5194 | if( document.getElementById(\"canvas_input0\")){\ |
||
5195 | var p = 0;var input_reply = new Array();\ |
||
5196 | if( document.getElementById(\"canvas_input0\")){\ |
||
5197 | var t = 0;\ |
||
5198 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5199 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5200 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5201 | p++;\ |
||
5202 | };\ |
||
5203 | t++;\ |
||
5204 | };\ |
||
5205 | };\ |
||
5206 | if( typeof userdraw_text != 'undefined' ){\ |
||
5207 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5208 | }\ |
||
5209 | else\ |
||
5210 | {\ |
||
5211 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
5212 | }\ |
||
5213 | }\ |
||
5214 | else\ |
||
5215 | {\ |
||
5216 | if( typeof userdraw_text != 'undefined' ){\ |
||
5217 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
5218 | }\ |
||
5219 | else\ |
||
5220 | {\ |
||
5221 | return reply_x+\"\\n\"+reply_y;\ |
||
5222 | };\ |
||
5223 | };\ |
||
8108 | schaersvoo | 5224 | };\n\ |
8257 | schaersvoo | 5225 | <!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5226 | break; |
5227 | case 3: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5228 | \n<!-- begin function 3 read_canvas%d() -->\n\ |
5229 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5230 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 5231 | set_reply_precision();\ |
7614 | schaersvoo | 5232 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
5233 | var p = 0;var input_reply = new Array();\ |
||
5234 | if( document.getElementById(\"canvas_input0\")){\ |
||
5235 | var t = 0;\ |
||
5236 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5237 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5238 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5239 | p++;\ |
||
5240 | };\ |
||
5241 | t++;\ |
||
5242 | };\ |
||
5243 | };\ |
||
5244 | if( typeof userdraw_text != 'undefined' ){\ |
||
5245 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5246 | }\ |
||
5247 | else\ |
||
5248 | {\ |
||
5249 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
5250 | }\ |
||
5251 | }\ |
||
5252 | else\ |
||
5253 | {\ |
||
5254 | if( typeof userdraw_text != 'undefined' ){\ |
||
5255 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\ |
||
5256 | }\ |
||
5257 | else\ |
||
5258 | {\ |
||
5259 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\ |
||
5260 | }\ |
||
5261 | }\ |
||
8108 | schaersvoo | 5262 | };\n\ |
8257 | schaersvoo | 5263 | <!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5264 | break; |
5265 | case 4: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5266 | \n<!-- begin function 4 read_canvas%d() -->\n\ |
5267 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5268 | var prec = %d;\ |
7614 | schaersvoo | 5269 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
5270 | while(userdraw_x[p]){\ |
||
8074 | schaersvoo | 5271 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
5272 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\ |
||
7614 | schaersvoo | 5273 | p++;\ |
5274 | };\ |
||
5275 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5276 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
5277 | var p = 0;var input_reply = new Array();\ |
||
5278 | if( document.getElementById(\"canvas_input0\")){\ |
||
5279 | var t = 0;\ |
||
5280 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5281 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5282 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5283 | p++;\ |
||
5284 | };\ |
||
5285 | t++;\ |
||
5286 | };\ |
||
5287 | };\ |
||
5288 | if( typeof userdraw_text != 'undefined' ){\ |
||
5289 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5290 | }\ |
||
5291 | else\ |
||
5292 | {\ |
||
5293 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
5294 | }\ |
||
5295 | }\ |
||
5296 | else\ |
||
5297 | {\ |
||
5298 | if( typeof userdraw_text != 'undefined' ){\ |
||
5299 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\ |
||
5300 | }\ |
||
5301 | else\ |
||
5302 | {\ |
||
5303 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\ |
||
5304 | }\ |
||
5305 | };\ |
||
8108 | schaersvoo | 5306 | };\n\ |
8257 | schaersvoo | 5307 | <!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5308 | break; |
8224 | bpr | 5309 | /* |
5310 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
5311 | used for userdraw multiple paths |
||
7614 | schaersvoo | 5312 | */ |
5313 | case 5: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5314 | \n<!-- begin function 5 read_canvas%d() -->\n\ |
5315 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5316 | set_reply_precision();\ |
7614 | schaersvoo | 5317 | var p = 0;\ |
5318 | var reply = \"\";\ |
||
5319 | for(p = 0; p < userdraw_x.length;p++){\ |
||
5320 | if(userdraw_x[p] != null ){\ |
||
5321 | reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\ |
||
5322 | };\ |
||
5323 | };\ |
||
5324 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5325 | userdraw_x = [];userdraw_y = [];\ |
||
5326 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
5327 | var p = 0;var input_reply = new Array();\ |
||
5328 | if( document.getElementById(\"canvas_input0\")){\ |
||
5329 | var t = 0;\ |
||
5330 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5331 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5332 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5333 | p++;\ |
||
5334 | };\ |
||
5335 | t++;\ |
||
5336 | };\ |
||
5337 | };\ |
||
5338 | if( typeof userdraw_text != 'undefined' ){\ |
||
5339 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5340 | }\ |
||
5341 | else\ |
||
5342 | {\ |
||
5343 | return reply +\"\\n\"+input_reply;\ |
||
5344 | }\ |
||
5345 | }\ |
||
5346 | else\ |
||
5347 | {\ |
||
5348 | if( typeof userdraw_text != 'undefined' ){\ |
||
5349 | return reply+\"\\n\"+userdraw_text;\ |
||
5350 | }\ |
||
5351 | else\ |
||
5352 | {\ |
||
5353 | return reply;\ |
||
5354 | }\ |
||
5355 | };\ |
||
8108 | schaersvoo | 5356 | };\n\ |
8257 | schaersvoo | 5357 | <!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5358 | break; |
8224 | bpr | 5359 | /* |
5360 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
5361 | used for userdraw multiple paths |
||
7614 | schaersvoo | 5362 | */ |
5363 | case 6: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5364 | \n<!-- begin function 6 read_canvas%d() -->\n\ |
5365 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5366 | var p = 0;\ |
5367 | var reply = \"\";\ |
||
5368 | var tmp_x = new Array();\ |
||
5369 | var tmp_y = new Array();\ |
||
8074 | schaersvoo | 5370 | var prec = %d;\ |
7614 | schaersvoo | 5371 | for(p = 0 ; p < userdraw_x.length; p++){\ |
5372 | tmp_x = userdraw_x[p];\ |
||
5373 | tmp_y = userdraw_y[p];\ |
||
5374 | if(tmp_x != null){\ |
||
5375 | for(var i = 0 ; i < tmp_x.length ; i++){\ |
||
8074 | schaersvoo | 5376 | tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\ |
5377 | tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\ |
||
7614 | schaersvoo | 5378 | };\ |
5379 | reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\ |
||
5380 | };\ |
||
5381 | };\ |
||
5382 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5383 | userdraw_x = [];userdraw_y = [];\ |
||
5384 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5385 | var p = 0;var input_reply = new Array();\ |
||
5386 | if( document.getElementById(\"canvas_input0\")){\ |
||
5387 | var t = 0;\ |
||
5388 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5389 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5390 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5391 | p++;\ |
||
5392 | };\ |
||
5393 | t++;\ |
||
5394 | };\ |
||
5395 | };\ |
||
5396 | if( typeof userdraw_text != 'undefined' ){\ |
||
5397 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5398 | }\ |
||
5399 | else\ |
||
5400 | {\ |
||
5401 | return reply +\"\\n\"+input_reply;\ |
||
5402 | }\ |
||
5403 | }\ |
||
5404 | else\ |
||
5405 | {\ |
||
5406 | if( typeof userdraw_text != 'undefined' ){\ |
||
5407 | return reply +\"\\n\"+userdraw_text;\ |
||
5408 | }\ |
||
5409 | else\ |
||
5410 | {\ |
||
5411 | return reply;\ |
||
5412 | }\ |
||
5413 | };\ |
||
8108 | schaersvoo | 5414 | };\n\ |
8257 | schaersvoo | 5415 | <!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5416 | break; |
5417 | case 7: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5418 | \n<!-- begin function 7 read_canvas%d() -->\n\ |
5419 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5420 | set_reply_precision();\ |
7614 | schaersvoo | 5421 | var reply = new Array();\ |
5422 | var p = 0;\ |
||
5423 | while(userdraw_x[p]){\ |
||
5424 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\ |
||
5425 | p++;\ |
||
5426 | };\ |
||
5427 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5428 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5429 | var p = 0;var input_reply = new Array();\ |
||
5430 | if( document.getElementById(\"canvas_input0\")){\ |
||
5431 | var t = 0;\ |
||
5432 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5433 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5434 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5435 | p++;\ |
||
5436 | };\ |
||
5437 | t++;\ |
||
5438 | };\ |
||
5439 | };\ |
||
5440 | if( typeof userdraw_text != 'undefined' ){\ |
||
5441 | return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5442 | }\ |
||
5443 | else\ |
||
5444 | {\ |
||
5445 | return reply+\"\\n\"+input_reply;\ |
||
5446 | }\ |
||
7862 | schaersvoo | 5447 | }\ |
7614 | schaersvoo | 5448 | else\ |
5449 | {\ |
||
5450 | if( typeof userdraw_text != 'undefined' ){\ |
||
5451 | return reply+\"\\n\"+userdraw_text;\ |
||
5452 | }\ |
||
5453 | else\ |
||
5454 | {\ |
||
5455 | return reply;\ |
||
5456 | }\ |
||
5457 | };\ |
||
8108 | schaersvoo | 5458 | };\n\ |
8257 | schaersvoo | 5459 | <!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5460 | break; |
5461 | case 8: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5462 | \n<!-- begin function 8 read_canvas%d() -->\n\ |
5463 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5464 | var reply = new Array();\ |
5465 | var p = 0;\ |
||
8074 | schaersvoo | 5466 | var prec = %d;\ |
7614 | schaersvoo | 5467 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5468 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
7614 | schaersvoo | 5469 | p++;\ |
5470 | };\ |
||
5471 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5472 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
5473 | var p = 0;var input_reply = new Array();\ |
||
5474 | if( document.getElementById(\"canvas_input0\")){\ |
||
5475 | var t = 0;\ |
||
5476 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5477 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5478 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5479 | p++;\ |
||
5480 | };\ |
||
5481 | t++;\ |
||
5482 | };\ |
||
5483 | };\ |
||
5484 | if( typeof userdraw_text != 'undefined' ){\ |
||
5485 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5486 | }\ |
||
5487 | else\ |
||
5488 | {\ |
||
5489 | return reply +\"\\n\"+input_reply;\ |
||
5490 | }\ |
||
5491 | }\ |
||
5492 | else\ |
||
5493 | {\ |
||
5494 | if( typeof userdraw_text != 'undefined' ){\ |
||
5495 | return reply +\"\\n\"+userdraw_text;\ |
||
5496 | }\ |
||
5497 | else\ |
||
5498 | {\ |
||
5499 | return reply;\ |
||
5500 | }\ |
||
5501 | };\ |
||
8108 | schaersvoo | 5502 | };\n\ |
8257 | schaersvoo | 5503 | <!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5504 | break; |
5505 | case 9: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5506 | \n<!-- begin function 9 read_canvas%d() -->\n\ |
5507 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5508 | set_reply_precision();\ |
7614 | schaersvoo | 5509 | var reply = new Array();\ |
5510 | var p = 0;\ |
||
5511 | while(userdraw_x[p]){\ |
||
5512 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\ |
||
5513 | p++;\ |
||
5514 | };\ |
||
5515 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5516 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5517 | var p = 0;var input_reply = new Array();\ |
||
5518 | if( document.getElementById(\"canvas_input0\")){\ |
||
5519 | var t = 0;\ |
||
5520 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5521 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5522 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5523 | p++;\ |
||
5524 | };\ |
||
5525 | t++;\ |
||
5526 | };\ |
||
5527 | };\ |
||
5528 | if( typeof userdraw_text != 'undefined' ){\ |
||
5529 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5530 | }\ |
||
5531 | else\ |
||
5532 | {\ |
||
5533 | return reply +\"\\n\"+input_reply;\ |
||
5534 | }\ |
||
5535 | }\ |
||
5536 | else\ |
||
5537 | {\ |
||
5538 | if( typeof userdraw_text != 'undefined' ){\ |
||
5539 | return reply +\"\\n\"+userdraw_text;\ |
||
5540 | }\ |
||
5541 | else\ |
||
5542 | {\ |
||
5543 | return reply;\ |
||
5544 | }\ |
||
5545 | };\ |
||
8108 | schaersvoo | 5546 | };\n\ |
8257 | schaersvoo | 5547 | <!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5548 | break; |
5549 | case 10: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5550 | \n<!-- begin function 10 read_canvas%d() -->\n\ |
5551 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5552 | var reply = new Array();\ |
5553 | var p = 0;\ |
||
8074 | schaersvoo | 5554 | var prec = %d;\ |
7614 | schaersvoo | 5555 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5556 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*userdraw_radius[p]))/prec;\ |
7614 | schaersvoo | 5557 | p++;\ |
5558 | };\ |
||
5559 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5560 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5561 | var p = 0;var input_reply = new Array();\ |
||
5562 | if( document.getElementById(\"canvas_input0\")){\ |
||
5563 | var t = 0;\ |
||
5564 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5565 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5566 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5567 | p++;\ |
||
5568 | };\ |
||
5569 | t++;\ |
||
5570 | };\ |
||
5571 | };\ |
||
5572 | if( typeof userdraw_text != 'undefined' ){\ |
||
5573 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5574 | }\ |
||
5575 | else\ |
||
5576 | {\ |
||
5577 | return reply +\"\\n\"+input_reply;\ |
||
5578 | }\ |
||
5579 | }\ |
||
5580 | else\ |
||
5581 | {\ |
||
5582 | if( typeof userdraw_text != 'undefined' ){\ |
||
5583 | return reply +\"\\n\"+userdraw_text;\ |
||
5584 | }\ |
||
5585 | else\ |
||
5586 | {\ |
||
5587 | return reply;\ |
||
5588 | }\ |
||
5589 | };\ |
||
8108 | schaersvoo | 5590 | };\n\ |
8257 | schaersvoo | 5591 | <!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5592 | break; |
5593 | case 11: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5594 | \n<!-- begin function 11 read_canvas%d() -->\n\ |
5595 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5596 | var reply = \"\";\ |
5597 | var p = 0;\ |
||
8074 | schaersvoo | 5598 | var prec = %d;\ |
7614 | schaersvoo | 5599 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5600 | reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\",\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec +\"\\n\" ;\ |
7614 | schaersvoo | 5601 | p = p+2;\ |
5602 | };\ |
||
5603 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5604 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
5605 | var p = 0;var input_reply = new Array();\ |
||
5606 | if( document.getElementById(\"canvas_input0\")){\ |
||
5607 | var t = 0;\ |
||
5608 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5609 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5610 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5611 | p++;\ |
||
5612 | };\ |
||
5613 | t++;\ |
||
5614 | };\ |
||
5615 | };\ |
||
5616 | if( typeof userdraw_text != 'undefined' ){\ |
||
5617 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5618 | }\ |
||
5619 | else\ |
||
5620 | {\ |
||
5621 | return reply +\"\\n\"+input_reply;\ |
||
5622 | }\ |
||
5623 | }\ |
||
5624 | else\ |
||
5625 | {\ |
||
5626 | if( typeof userdraw_text != 'undefined' ){\ |
||
5627 | return reply +\"\\n\"+userdraw_text;\ |
||
5628 | }\ |
||
5629 | else\ |
||
5630 | {\ |
||
5631 | return reply;\ |
||
5632 | }\ |
||
5633 | };\ |
||
8108 | schaersvoo | 5634 | };\n\ |
8257 | schaersvoo | 5635 | <!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5636 | break; |
5637 | case 12: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5638 | \n<!-- begin function 12 read_canvas%d() -->\n\ |
5639 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5640 | set_reply_precision();\ |
7614 | schaersvoo | 5641 | var reply = \"\";\ |
5642 | var p = 0;\ |
||
5643 | for(p = 0; p< userdraw_x.lenght;p = p+2){\ |
||
5644 | if(userdraw_x[p] != null){\ |
||
5645 | reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\ |
||
5646 | };\ |
||
5647 | };\ |
||
5648 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5649 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5650 | var p = 0;var input_reply = new Array();\ |
||
5651 | if( document.getElementById(\"canvas_input0\")){\ |
||
5652 | var t = 0;\ |
||
5653 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5654 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5655 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5656 | p++;\ |
||
5657 | };\ |
||
5658 | t++;\ |
||
5659 | };\ |
||
5660 | };\ |
||
5661 | if( typeof userdraw_text != 'undefined' ){\ |
||
5662 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5663 | }\ |
||
5664 | else\ |
||
5665 | {\ |
||
5666 | return reply +\"\\n\"+input_reply;\ |
||
5667 | }\ |
||
5668 | }\ |
||
5669 | else\ |
||
5670 | {\ |
||
5671 | if( typeof userdraw_text != 'undefined' ){\ |
||
5672 | return reply +\"\\n\"+userdraw_text\ |
||
5673 | }\ |
||
5674 | else\ |
||
5675 | {\ |
||
5676 | return reply;\ |
||
5677 | }\ |
||
5678 | };\ |
||
8108 | schaersvoo | 5679 | };\n\ |
8257 | schaersvoo | 5680 | <!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5681 | break; |
5682 | case 13: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5683 | \n<!-- begin function 13 read_canvas%d() -->\n\ |
5684 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5685 | var reply = new Array();\ |
5686 | var p = 0;var i = 0;\ |
||
8074 | schaersvoo | 5687 | var prec = %d;\ |
7614 | schaersvoo | 5688 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5689 | reply[i] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec;\ |
7614 | schaersvoo | 5690 | p = p+2;i++;\ |
5691 | };\ |
||
5692 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5693 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5694 | var p = 0;var input_reply = new Array();\ |
||
5695 | if( document.getElementById(\"canvas_input0\")){\ |
||
5696 | var t = 0;\ |
||
5697 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5698 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5699 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5700 | p++;\ |
||
5701 | };\ |
||
5702 | t++;\ |
||
5703 | };\ |
||
5704 | };\ |
||
5705 | if( typeof userdraw_text != 'undefined' ){\ |
||
5706 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5707 | }\ |
||
5708 | else\ |
||
5709 | {\ |
||
5710 | return reply +\"\\n\"+input_reply;\ |
||
5711 | }\ |
||
5712 | }\ |
||
5713 | else\ |
||
5714 | {\ |
||
5715 | if( typeof userdraw_text != 'undefined' ){\ |
||
5716 | return reply +\"\\n\"+userdraw_text\ |
||
5717 | }\ |
||
5718 | else\ |
||
5719 | {\ |
||
5720 | return reply;\ |
||
5721 | }\ |
||
5722 | };\ |
||
8108 | schaersvoo | 5723 | };\n\ |
8257 | schaersvoo | 5724 | <!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5725 | break; |
5726 | case 14: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5727 | \n<!-- begin function 14 read_canvas%d() -->\n\ |
5728 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5729 | set_reply_precision();\ |
7614 | schaersvoo | 5730 | var reply = new Array();\ |
5731 | var p = 0;var i = 0;\ |
||
5732 | while(userdraw_x[p]){\ |
||
5733 | reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\ |
||
5734 | p = p+2;i++;\ |
||
5735 | };\ |
||
5736 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5737 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5738 | var p = 0;var input_reply = new Array();\ |
||
5739 | if( document.getElementById(\"canvas_input0\")){\ |
||
5740 | var t = 0;\ |
||
5741 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5742 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5743 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5744 | p++;\ |
||
5745 | };\ |
||
5746 | t++;\ |
||
5747 | };\ |
||
5748 | };\ |
||
5749 | if( typeof userdraw_text != 'undefined' ){\ |
||
5750 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5751 | }\ |
||
5752 | else\ |
||
5753 | {\ |
||
5754 | return reply +\"\\n\"+input_reply;\ |
||
5755 | }\ |
||
5756 | }\ |
||
5757 | else\ |
||
5758 | {\ |
||
5759 | if( typeof userdraw_text != 'undefined' ){\ |
||
5760 | return reply +\"\\n\"+userdraw_text;\ |
||
5761 | }\ |
||
5762 | else\ |
||
5763 | {\ |
||
5764 | return reply;\ |
||
5765 | }\ |
||
5766 | };\ |
||
8108 | schaersvoo | 5767 | };\n\ |
8257 | schaersvoo | 5768 | <!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5769 | break; |
5770 | case 15: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5771 | \n<!-- begin function 15 read_canvas%d() -->\n\ |
5772 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5773 | var input_reply = new Array();\ |
5774 | var p = 0;\ |
||
5775 | if( document.getElementById(\"canvas_input0\")){\ |
||
5776 | var t = 0;\ |
||
5777 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5778 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5779 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5780 | p++;\ |
||
5781 | };\ |
||
5782 | t++;\ |
||
5783 | };\ |
||
5784 | };\ |
||
5785 | if( typeof userdraw_text != 'undefined' ){\ |
||
5786 | return input_reply +\"\\n\"+userdraw_text;\ |
||
5787 | }\ |
||
5788 | else\ |
||
5789 | {\ |
||
5790 | return input_reply;\ |
||
5791 | };\ |
||
8108 | schaersvoo | 5792 | };\n\ |
8257 | schaersvoo | 5793 | <!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5794 | break; |
5795 | case 16: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 5796 | \n<!-- begin function 16 read_mathml() -->\n\ |
7614 | schaersvoo | 5797 | function read_mathml(){\ |
5798 | var reply = new Array();\ |
||
5799 | var p = 0;\ |
||
5800 | if( document.getElementById(\"mathml0\")){\ |
||
5801 | while(document.getElementById(\"mathml\"+p)){\ |
||
5802 | reply[p] = document.getElementById(\"mathml\"+p).value;\ |
||
5803 | p++;\ |
||
5804 | };\ |
||
5805 | };\ |
||
5806 | return reply;\ |
||
5807 | };\ |
||
5808 | this.read_mathml = read_mathml;\n\ |
||
7653 | schaersvoo | 5809 | <!-- end function 16 read_mathml() -->"); |
7614 | schaersvoo | 5810 | break; |
5811 | case 17: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5812 | \n<!-- begin function 17 read_canvas%d() -->\n\ |
5813 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5814 | if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\ |
5815 | return userdraw_text;\ |
||
8108 | schaersvoo | 5816 | };\n\ |
8257 | schaersvoo | 5817 | <!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5818 | break; |
5819 | case 18: fprintf(js_include_file,"\ |
||
10956 | schaersvoo | 5820 | \n<!-- javascript has no real modulo function -->\n\ |
5821 | function mod(n, m){\ |
||
5822 | var m = parseInt(((n %% m) + m) %% m);\ |
||
5823 | return m;\ |
||
5824 | };\ |
||
8257 | schaersvoo | 5825 | \n<!-- begin function 18 read_canvas%d() -->\n\ |
5826 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5827 | var p = 0;\ |
5828 | var reply = new Array();\ |
||
5829 | var name;\ |
||
5830 | var t = true;\ |
||
8000 | schaersvoo | 5831 | var h;var m;var s;\ |
7614 | schaersvoo | 5832 | while(t){\ |
8000 | schaersvoo | 5833 | try{\ |
5834 | name = eval('clocks'+p);\ |
||
5835 | h = name.H;m = name.M;s = name.S;\ |
||
10956 | schaersvoo | 5836 | h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\ |
8000 | schaersvoo | 5837 | reply[p] = h+\":\"+m+\":\"+s;\ |
5838 | p++;\ |
||
5839 | }catch(e){t=false;};\ |
||
7614 | schaersvoo | 5840 | };\ |
8000 | schaersvoo | 5841 | if( p == 0 ){alert(\"clock(s) not modified...\");return;}\ |
7614 | schaersvoo | 5842 | return reply;\ |
8108 | schaersvoo | 5843 | };\n\ |
8257 | schaersvoo | 5844 | <!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5845 | break; |
5846 | case 19: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5847 | \n<!-- begin function 19 read_canvas%d() -->\n\ |
5848 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5849 | return reply[0];\ |
8108 | schaersvoo | 5850 | };\n\ |
8257 | schaersvoo | 5851 | <!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
8130 | schaersvoo | 5852 | break; |
7614 | schaersvoo | 5853 | case 20: fprintf(js_include_file,"\ |
8257 | schaersvoo | 5854 | \n<!-- begin function 20 read_canvas%d() -->\n\ |
5855 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5856 | var prec = %d;\ |
7614 | schaersvoo | 5857 | var len = ext_drag_images.length;\ |
5858 | var reply = new Array(len);\ |
||
5859 | for(var p = 0 ; p < len ; p++){\ |
||
5860 | var img = ext_drag_images[p];\ |
||
8556 | schaersvoo | 5861 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
7614 | schaersvoo | 5862 | };\ |
5863 | return reply;\ |
||
8108 | schaersvoo | 5864 | };\n\ |
8257 | schaersvoo | 5865 | <!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5866 | break; |
5867 | case 21: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5868 | \n<!-- begin function 21 read_canvas%d() -->\n\ |
5869 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5870 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
5871 | var reply_coord = new Array();var p = 0;\ |
||
8074 | schaersvoo | 5872 | var prec = %d;\ |
7614 | schaersvoo | 5873 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5874 | reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\ |
7614 | schaersvoo | 5875 | p++;\ |
5876 | };\ |
||
5877 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
5878 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5879 | var p = 0;var input_reply = new Array();\ |
||
5880 | if( document.getElementById(\"canvas_input0\")){\ |
||
5881 | var t = 0;\ |
||
5882 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5883 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5884 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5885 | p++;\ |
||
5886 | };\ |
||
5887 | t++;\ |
||
5888 | };\ |
||
5889 | };\ |
||
5890 | if( typeof userdraw_text != 'undefined' ){\ |
||
5891 | return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5892 | }\ |
||
5893 | else\ |
||
5894 | {\ |
||
5895 | return reply_coord+\"\\n\"+input_reply;\ |
||
5896 | }\ |
||
5897 | }\ |
||
5898 | else\ |
||
5899 | {\ |
||
5900 | if( typeof userdraw_text != 'undefined' ){\ |
||
5901 | return reply_coord+\"\\n\"+userdraw_text;\ |
||
5902 | }\ |
||
5903 | else\ |
||
5904 | {\ |
||
5905 | return reply_coord;\ |
||
5906 | };\ |
||
5907 | };\ |
||
8108 | schaersvoo | 5908 | };\n\ |
8257 | schaersvoo | 5909 | <!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5910 | break; |
5911 | case 22: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5912 | \n<!-- begin function 22 read_canvas%d() -->\n\ |
5913 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5914 | var reply = new Array();\ |
7963 | schaersvoo | 5915 | var lu = userdraw_x.length;\ |
5916 | if(lu == 0){alert(\"nothing drawn...\");return;};\ |
||
7614 | schaersvoo | 5917 | var idx = 0;\ |
8074 | schaersvoo | 5918 | var prec = %d;\ |
7963 | schaersvoo | 5919 | for(var p = 0 ; p < lu ; p++){\ |
8074 | schaersvoo | 5920 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\ |
5921 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\ |
||
7614 | schaersvoo | 5922 | };\ |
5923 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5924 | var p = 0;var input_reply = new Array();\ |
||
5925 | if( document.getElementById(\"canvas_input0\")){\ |
||
5926 | var t = 0;\ |
||
5927 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5928 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5929 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5930 | p++;\ |
||
5931 | };\ |
||
5932 | t++;\ |
||
5933 | };\ |
||
5934 | };\ |
||
5935 | if( typeof userdraw_text != 'undefined' ){\ |
||
5936 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5937 | }\ |
||
5938 | else\ |
||
5939 | {\ |
||
5940 | return reply +\"\\n\"+input_reply;\ |
||
5941 | }\ |
||
5942 | }\ |
||
5943 | else\ |
||
5944 | {\ |
||
5945 | if( typeof userdraw_text != 'undefined' ){\ |
||
5946 | return reply +\"\\n\"+userdraw_text;\ |
||
5947 | }\ |
||
5948 | else\ |
||
5949 | {\ |
||
5950 | return reply;\ |
||
5951 | }\ |
||
5952 | };\ |
||
8108 | schaersvoo | 5953 | };\n\ |
8257 | schaersvoo | 5954 | <!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5955 | break; |
7782 | schaersvoo | 5956 | case 23: fprintf(js_include_file,"\ |
8257 | schaersvoo | 5957 | \n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\ |
5958 | read_canvas%d = function(){\ |
||
7782 | schaersvoo | 5959 | if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\ |
5960 | var lu = userdraw_x.length;\ |
||
5961 | if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\ |
||
7962 | schaersvoo | 5962 | var reply_x = new Array();var reply_y = new Array();\ |
5963 | var marge = 5;var p = 0;\ |
||
8074 | schaersvoo | 5964 | var prec = %d;\ |
7782 | schaersvoo | 5965 | for(var i = 0; i < lu - 1 ; i++ ){\ |
10987 | schaersvoo | 5966 | if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\ |
8074 | schaersvoo | 5967 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\ |
7962 | schaersvoo | 5968 | if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\ |
5969 | p++;\ |
||
7782 | schaersvoo | 5970 | };\ |
8074 | schaersvoo | 5971 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\ |
7782 | schaersvoo | 5972 | };\ |
5973 | if( document.getElementById(\"canvas_input0\")){\ |
||
5974 | var p = 0;var input_reply = new Array();\ |
||
5975 | if( document.getElementById(\"canvas_input0\")){\ |
||
5976 | var t = 0;\ |
||
5977 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5978 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5979 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5980 | p++;\ |
||
5981 | };\ |
||
5982 | t++;\ |
||
5983 | };\ |
||
5984 | };\ |
||
5985 | if( typeof userdraw_text != 'undefined' ){\ |
||
5986 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
5987 | }\ |
||
5988 | else\ |
||
5989 | {\ |
||
5990 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
5991 | }\ |
||
5992 | }\ |
||
5993 | else\ |
||
5994 | {\ |
||
5995 | if( typeof userdraw_text != 'undefined' ){\ |
||
5996 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
5997 | }\ |
||
5998 | else\ |
||
5999 | {\ |
||
6000 | return reply_x+\"\\n\"+reply_y;\ |
||
6001 | };\ |
||
6002 | };\ |
||
8108 | schaersvoo | 6003 | };\n\ |
8257 | schaersvoo | 6004 | <!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7782 | schaersvoo | 6005 | break; |
7984 | schaersvoo | 6006 | case 24: fprintf(js_include_file,"\n\ |
8257 | schaersvoo | 6007 | <!-- begin function 24 read_canvas%d() -->\n\ |
6008 | read_canvas%d = function(){\ |
||
7984 | schaersvoo | 6009 | var input_reply = new Array();\ |
6010 | var p = 0;\ |
||
6011 | if( document.getElementById(\"canvas_input0\")){\ |
||
6012 | while(document.getElementById(\"canvas_input\"+p)){\ |
||
6013 | input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\ |
||
6014 | p++;\ |
||
6015 | };\ |
||
6016 | return input_reply;\ |
||
6017 | };\ |
||
8108 | schaersvoo | 6018 | };\n\ |
8257 | schaersvoo | 6019 | <!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7984 | schaersvoo | 6020 | break; |
8083 | schaersvoo | 6021 | case 25: |
8257 | schaersvoo | 6022 | fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\ |
6023 | read_canvas%d = function(){\ |
||
8083 | schaersvoo | 6024 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
6025 | var lu = userdraw_radius.length;\ |
||
6026 | var prec = %d;\ |
||
6027 | var angle_reply = new Array(lu);\ |
||
6028 | for(var p = 0 ; p < lu ; p++){\ |
||
6029 | angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\ |
||
6030 | };\ |
||
6031 | return angle_reply;\ |
||
8108 | schaersvoo | 6032 | };\n\ |
8257 | schaersvoo | 6033 | <!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 6034 | break; |
6035 | case 26: |
||
8257 | schaersvoo | 6036 | fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\ |
6037 | read_canvas%d = function(){\ |
||
8083 | schaersvoo | 6038 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
6039 | var lu = userdraw_radius.length;\ |
||
6040 | var prec = %d;\ |
||
6041 | var angle_reply = new Array(lu);\ |
||
6042 | for(var p = 0 ; p < lu ; p++){\ |
||
6043 | angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\ |
||
6044 | };\ |
||
6045 | return angle_reply;\ |
||
8108 | schaersvoo | 6046 | };\n\ |
8257 | schaersvoo | 6047 | <!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 6048 | break; |
8127 | schaersvoo | 6049 | case 27: |
8257 | schaersvoo | 6050 | fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d() : inputfield(s) location and their values : -->\n\ |
6051 | read_canvas%d = function(){\ |
||
8127 | schaersvoo | 6052 | var lu = userdraw_x.length;\ |
6053 | if( lu < 1){alert(\"nothing drawn...\");return;}\ |
||
6054 | set_reply_precision();\ |
||
6055 | var prec = %d;\ |
||
6056 | for(var p = 0 ; p < lu ; p++){\ |
||
6057 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\ |
||
6058 | };\ |
||
6059 | return reply;\ |
||
6060 | };\n\ |
||
8257 | schaersvoo | 6061 | <!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8127 | schaersvoo | 6062 | break; |
8322 | schaersvoo | 6063 | case 28: |
6064 | fprintf(js_include_file,"\n<!-- begin function 28 read_canvas%d() -->\n\ |
||
6065 | read_canvas%d = function(){\ |
||
6066 | var prec = %d;\ |
||
6067 | var reply = new Array();var p = 0;\ |
||
6068 | var idx = 0;\ |
||
6069 | while(userdraw_x[p]){\ |
||
6070 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
||
6071 | idx++;\ |
||
6072 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
6073 | idx++;\ |
||
6074 | reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\ |
||
6075 | idx++;\ |
||
6076 | p++;\ |
||
6077 | };\ |
||
6078 | if( p == 0){alert(\"nothing drawn...\");return;}\ |
||
6079 | return reply;\ |
||
6080 | };\n\ |
||
9213 | schaersvoo | 6081 | <!-- end function 28 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8322 | schaersvoo | 6082 | break; |
9213 | schaersvoo | 6083 | case 29: |
6084 | fprintf(js_include_file,"\n<!-- begin function 29 read_canvas%d() -->\n\ |
||
6085 | function xy_precision(array_x,array_y){\ |
||
6086 | var len = array_x.length;\ |
||
6087 | var x_array = new Array(len);\ |
||
6088 | var y_array = new Array(len);\ |
||
6089 | var prec = %d;\ |
||
6090 | for(var p = 0 ; p < len ; p++ ){\ |
||
6091 | x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\ |
||
6092 | y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\ |
||
6093 | };\ |
||
9230 | schaersvoo | 6094 | return x_array+\";\"+y_array;\ |
9213 | schaersvoo | 6095 | };\n\ |
6096 | function round_to_pixel(array_r){\ |
||
6097 | var len = array_r.length;\ |
||
6098 | for(var p = 0 ; p < len ; p++ ){\ |
||
6099 | array_r[p] = Math.round(array_r[p]);\ |
||
6100 | };\ |
||
6101 | return array_r;\ |
||
6102 | };\ |
||
6103 | read_canvas%d = function(){\ |
||
9300 | schaersvoo | 6104 | var reply=\" \";\ |
6105 | if( points_x && points_x.length > 0 ){reply = reply + xy_precision(points_x,points_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6106 | if( circles_x && circles_x.length > 0 ){ reply = reply + xy_precision(circles_x,circles_y)+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6107 | if( segments_x && segments_x.length > 0 ){ reply = reply + xy_precision(segments_x,segments_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6108 | if( arrows_x && arrows_x.length > 0 ){ reply = reply + xy_precision(arrows_x,arrows_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6109 | if( lines_x && lines_x.length > 0 ){ reply = reply + xy_precision(lines_x,lines_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6110 | if( triangles_x && triangles_x.length > 0){ reply = reply + xy_precision(triangles_x,triangles_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
9372 | schaersvoo | 6111 | if( rects_x && rects_x.length > 0 ){ reply = reply + xy_precision(rects_x,rects_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
9300 | schaersvoo | 6112 | if( closedpoly_x && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();reply = reply + xy_precision(closedpoly_x,closedpoly_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
9338 | schaersvoo | 6113 | if( text_x && text_x.length > 0){ reply = reply + xy_precision(text_x,text_y)+\";\"+text_abc+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
9213 | schaersvoo | 6114 | return reply;\ |
6115 | };\n\ |
||
6116 | <!-- end function 29 read_canvas%d() -->",canvas_root_id,reply_precision,canvas_root_id,canvas_root_id); |
||
6117 | break; |
||
9289 | schaersvoo | 6118 | case 30: |
6119 | fprintf(js_include_file,"\n<!-- begin function 30 read_canvas%d() -->\n\ |
||
6120 | read_canvas%d = function(){\ |
||
6121 | var reply = new Array(3);\ |
||
6122 | var prec = %d;\ |
||
6123 | reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
6124 | reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
6125 | reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
6126 | return reply;\ |
||
6127 | };\n\ |
||
6128 | <!-- end function 30 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
||
6129 | break; |
||
6130 | case 31: |
||
6131 | fprintf(js_include_file,"\n<!-- begin function 31 read_canvas%d() -->\n\ |
||
6132 | read_canvas%d = function(){\ |
||
6133 | var reply = new Array(3);\ |
||
6134 | var prec = %d;\ |
||
6135 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
6136 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
6137 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
6138 | return reply;\ |
||
6139 | };\n\ |
||
6140 | <!-- end function 31 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
||
6141 | break; |
||
6142 | case 32: |
||
6143 | fprintf(js_include_file,"\n<!-- begin function 32 read_canvas%d() -->\n\ |
||
6144 | read_canvas%d = function(){\ |
||
6145 | var reply = new Array(6);\ |
||
6146 | var prec = %d;\ |
||
6147 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
6148 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
6149 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
6150 | reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
6151 | reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
6152 | reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
6153 | return reply;\ |
||
6154 | };\n\ |
||
6155 | <!-- end function 32 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
||
6156 | break; |
||
7614 | schaersvoo | 6157 | default: canvas_error("hmmm unknown replyformat...");break; |
6158 | } |
||
6159 | return; |
||
6160 | } |
||
6161 | |||
6162 | |||
8224 | bpr | 6163 | /* |
6164 | add drawfunction : |
||
7614 | schaersvoo | 6165 | - functions used by userdraw_primitives (circle,rect,path,triangle...) |
6166 | - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill) |
||
6167 | - grid / mathml |
||
6168 | - will not scale or zoom in |
||
6169 | - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill |
||
8224 | bpr | 6170 | - is printed directly into 'js_include_file' |
7614 | schaersvoo | 6171 | */ |
6172 | |||
6173 | void add_javascript_functions(int js_functions[],int canvas_root_id){ |
||
6174 | int i; |
||
6175 | for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){ |
||
6176 | if( js_functions[i] == 1){ |
||
6177 | switch(i){ |
||
8448 | schaersvoo | 6178 | case DRAW_EXTERNAL_IMAGE: |
10953 | bpr | 6179 | /* the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it |
8448 | schaersvoo | 6180 | draw_external_image(URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
6181 | */ |
||
7614 | schaersvoo | 6182 | fprintf(js_include_file,"\n<!-- drag external images --->\n\ |
7653 | schaersvoo | 6183 | var external_ctx = external_canvas.getContext(\"2d\");\ |
6184 | var external_canvas_rect = external_canvas.getBoundingClientRect();\ |
||
6185 | canvas_div.addEventListener(\"mousedown\",setxy,false);\ |
||
6186 | canvas_div.addEventListener(\"mouseup\",dragstop,false);\ |
||
6187 | canvas_div.addEventListener(\"mousemove\",dragxy,false);\ |
||
6188 | var selected_image = null;\ |
||
6189 | var ext_image_cnt = 0;\ |
||
6190 | var ext_drag_images = new Array();\ |
||
8448 | schaersvoo | 6191 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt){\ |
7653 | schaersvoo | 6192 | ext_image_cnt = idx;\ |
8448 | schaersvoo | 6193 | if(draggable == 1 ){\ |
6194 | reply[click_cnt] = 0;\ |
||
6195 | };\ |
||
7653 | schaersvoo | 6196 | var image = new Image();\ |
6197 | image.src = URL;\ |
||
6198 | image.onload = function(){\ |
||
8448 | schaersvoo | 6199 | if( sx < 1 ){ sx = 0; };\ |
6200 | if( sy < 1 ){ sy = 0; };\ |
||
6201 | if( swidth < 1 ){swidth = image.width;};\ |
||
6202 | if( sheight < 1 ){sheight = image.height;};\ |
||
6203 | if( width < 1 ){width = image.width;};\ |
||
6204 | if( height < 1 ){height = image.height;};\ |
||
6205 | if( resizable == 0 ){\ |
||
6206 | if( swidth > image.width ){ swidth = image.width; };\ |
||
6207 | if( sheight > image.height){ sheight = image.height;};\ |
||
6208 | if( width > image.width ){ width = image.width; };\ |
||
6209 | if( height > image.height){ height = image.height;};\ |
||
6210 | };\ |
||
6211 | var img = new Array(11);\ |
||
7653 | schaersvoo | 6212 | img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\ |
8448 | schaersvoo | 6213 | img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;img[10] = click_cnt;\ |
7653 | schaersvoo | 6214 | ext_drag_images[idx] = img;\ |
6215 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
6216 | };\ |
||
6217 | };\ |
||
6218 | function dragstop(evt){\ |
||
6219 | selected_image = null;return;\ |
||
6220 | };\ |
||
6221 | function dragxy(evt){\ |
||
6222 | if( selected_image != null ){\ |
||
6223 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
6224 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
6225 | var s_img = ext_drag_images[selected_image];\ |
||
6226 | s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\ |
||
6227 | s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\ |
||
8386 | schaersvoo | 6228 | if( use_snap_to_points == 1){\ |
6229 | var img_xy = snap_to_points(s_img[6],s_img[7]);\ |
||
6230 | s_img[6] = img_xy[0];s_img[7] = img_xy[1];\ |
||
6231 | }\ |
||
6232 | else\ |
||
6233 | {\ |
||
6234 | if( x_use_snap_to_grid == 1 ){\ |
||
6235 | s_img[6] = snap_to_x(s_img[6]);\ |
||
6236 | };\ |
||
6237 | if( y_use_snap_to_grid == 1 ){\ |
||
6238 | s_img[7] = snap_to_x(s_img[7]);\ |
||
6239 | };\ |
||
6240 | };\ |
||
7653 | schaersvoo | 6241 | ext_drag_images[selected_image] = s_img;\ |
6242 | external_ctx.clearRect(0,0,xsize,ysize);\ |
||
6243 | for(var i = 0; i <= ext_image_cnt ; i++){\ |
||
6244 | var img = ext_drag_images[i];\ |
||
6245 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
6246 | };\ |
||
6247 | };\ |
||
6248 | };\ |
||
6249 | function setxy(evt){\ |
||
6250 | if( ! selected_image && evt.which == 1 ){\ |
||
6251 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
6252 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
6253 | var xm = evt.clientX - external_canvas_rect.left + xoff;\ |
||
6254 | var ym = evt.clientY - external_canvas_rect.top + yoff;\ |
||
8448 | schaersvoo | 6255 | var img;\ |
7653 | schaersvoo | 6256 | for(var p = 0 ; p <= ext_image_cnt ; p++){\ |
8448 | schaersvoo | 6257 | if( ext_drag_images[p] ){\ |
6258 | img = ext_drag_images[p];\ |
||
6259 | if( img[0] != 0 ){\ |
||
6260 | if( xm > img[6] && xm < img[6] + img[8]){\ |
||
6261 | if( ym > img[7] && ym < img[7] + img[9]){\ |
||
6262 | if( img[0] == 1){\ |
||
6263 | if( reply[img[10]] == 1 ){\ |
||
6264 | reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\ |
||
6265 | }\ |
||
6266 | else\ |
||
6267 | {\ |
||
6268 | reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\ |
||
6269 | };\ |
||
6270 | external_ctx.lineWidth = 6;\ |
||
6271 | external_ctx.beginPath();\ |
||
6272 | external_ctx.rect(img[6],img[7],img[8],img[9]);\ |
||
6273 | external_ctx.closePath();\ |
||
6274 | external_ctx.stroke();\ |
||
6275 | return;\ |
||
6276 | }\ |
||
6277 | else\ |
||
6278 | {\ |
||
6279 | img[6] = xm;\ |
||
6280 | img[7] = ym;\ |
||
6281 | ext_drag_images[p] = img;\ |
||
6282 | selected_image = p;\ |
||
6283 | dragxy(evt);\ |
||
6284 | };\ |
||
6285 | };\ |
||
7653 | schaersvoo | 6286 | };\ |
6287 | };\ |
||
6288 | };\ |
||
6289 | };\ |
||
6290 | }\ |
||
6291 | else\ |
||
6292 | {\ |
||
6293 | selected_image = null;\ |
||
6294 | };\ |
||
8448 | schaersvoo | 6295 | };"); |
7614 | schaersvoo | 6296 | break; |
8370 | schaersvoo | 6297 | case DRAW_BEZIER: |
6298 | fprintf(js_include_file,"\n<!-- draw bezier curve -->\n\ |
||
6299 | var draw_bezier = function(canvas_type,linewidth,xy_points,fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
||
6300 | var obj;\ |
||
6301 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6302 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6303 | }\ |
||
6304 | else\ |
||
6305 | {\ |
||
6306 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6307 | };\ |
||
6308 | var ctx = obj.getContext(\"2d\");\ |
||
6309 | ctx.save();\ |
||
6310 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6311 | ctx.lineWidth = linewidth;\ |
||
11005 | schaersvoo | 6312 | if(linewidth%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
8370 | schaersvoo | 6313 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
6314 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
||
6315 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6316 | ctx.beginPath();\ |
||
6317 | ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\ |
||
6318 | ctx.bezierCurveTo(x2px(xy_points[2]),y2px(xy_points[3]),x2px(xy_points[4]),y2px(xy_points[5]),x2px(xy_points[6]),y2px(xy_points[7]));\ |
||
6319 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
6320 | ctx.stroke();\ |
||
6321 | ctx.restore();\ |
||
6322 | };\n",canvas_root_id,canvas_root_id,canvas_root_id); |
||
6323 | break; |
||
7614 | schaersvoo | 6324 | case DRAW_GRIDFILL:/* not used for userdraw */ |
6325 | fprintf(js_include_file,"\n<!-- draw gridfill -->\n\ |
||
8105 | schaersvoo | 6326 | var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\ |
7614 | schaersvoo | 6327 | var obj;\ |
6328 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6329 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6330 | }\ |
||
6331 | else\ |
||
6332 | {\ |
||
6333 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6334 | };\ |
||
6335 | var ctx = obj.getContext(\"2d\");\ |
||
6336 | var x,y;\ |
||
7883 | schaersvoo | 6337 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 6338 | ctx.save();\ |
9462 | schaersvoo | 6339 | ctx.lineWidth = line_width;\ |
9465 | schaersvoo | 6340 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6341 | ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
6342 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
6343 | ctx.moveTo(x,y0);\ |
||
6344 | ctx.lineTo(x,ysize);\ |
||
6345 | };\ |
||
7645 | schaersvoo | 6346 | for( y = y0 ; y < ysize+dy; y = y + dy ){\ |
7614 | schaersvoo | 6347 | ctx.moveTo(x0,y);\ |
6348 | ctx.lineTo(xsize,y);\ |
||
6349 | };\ |
||
6350 | ctx.stroke();\ |
||
6351 | ctx.restore();\ |
||
7653 | schaersvoo | 6352 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6353 | break; |
8224 | bpr | 6354 | |
7614 | schaersvoo | 6355 | case DRAW_IMAGEFILL:/* not used for userdraw */ |
6356 | fprintf(js_include_file,"\n<!-- draw imagefill -->\n\ |
||
8105 | schaersvoo | 6357 | var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\ |
7614 | schaersvoo | 6358 | var obj;\ |
6359 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6360 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6361 | }\ |
||
6362 | else\ |
||
6363 | {\ |
||
6364 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6365 | };\ |
||
6366 | var ctx = obj.getContext(\"2d\");\ |
||
6367 | ctx.save();\ |
||
6368 | var img = new Image();\ |
||
6369 | img.src = URL;\ |
||
6370 | img.onload = function(){\ |
||
6371 | if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\ |
||
6372 | ctx.drawImage(img,x0,y0,xsize,ysize);\ |
||
6373 | }\ |
||
6374 | else\ |
||
6375 | {\ |
||
6376 | var repeat = \"repeat\";\ |
||
6377 | if(img.width > xsize - x0){\ |
||
6378 | repeat = \"repeat-y\";\ |
||
6379 | }\ |
||
6380 | else\ |
||
6381 | {\ |
||
6382 | if( img.height > ysize -x0 ){\ |
||
6383 | repeat = \"repeat-x\";\ |
||
6384 | }\ |
||
6385 | }\ |
||
6386 | var pattern = ctx.createPattern(img,repeat);\ |
||
6387 | ctx.rect(x0,y0,xsize,ysize);\ |
||
6388 | ctx.fillStyle = pattern;\ |
||
6389 | }\ |
||
6390 | ctx.fill();\ |
||
6391 | };\ |
||
6392 | ctx.restore();\ |
||
6393 | return;\ |
||
7653 | schaersvoo | 6394 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6395 | break; |
8224 | bpr | 6396 | |
7614 | schaersvoo | 6397 | case DRAW_DOTFILL:/* not used for userdraw */ |
6398 | fprintf(js_include_file,"\n<!-- draw dotfill -->\n\ |
||
8105 | schaersvoo | 6399 | var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\ |
7614 | schaersvoo | 6400 | var obj;\ |
6401 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6402 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6403 | }\ |
||
6404 | else\ |
||
6405 | {\ |
||
6406 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6407 | };\ |
||
6408 | var ctx = obj.getContext(\"2d\");\ |
||
6409 | var x,y;\ |
||
6410 | ctx.closePath();\ |
||
6411 | ctx.save();\ |
||
7645 | schaersvoo | 6412 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 6413 | ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
6414 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
6415 | for( y = y0 ; y < ysize+dy ; y = y + dy ){\ |
||
6416 | ctx.arc(x,y,radius,0,2*Math.PI,false);\ |
||
6417 | ctx.closePath();\ |
||
6418 | }\ |
||
6419 | }\ |
||
6420 | ctx.fill();\ |
||
6421 | ctx.restore();\ |
||
7653 | schaersvoo | 6422 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6423 | break; |
7645 | schaersvoo | 6424 | |
7647 | schaersvoo | 6425 | case DRAW_DIAMONDFILL:/* not used for userdraw */ |
7614 | schaersvoo | 6426 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
8105 | schaersvoo | 6427 | var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7614 | schaersvoo | 6428 | var obj;\ |
6429 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6430 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6431 | }\ |
||
6432 | else\ |
||
6433 | {\ |
||
6434 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6435 | };\ |
||
6436 | var ctx = obj.getContext(\"2d\");\ |
||
6437 | var x;\ |
||
6438 | var y;\ |
||
6439 | ctx.save();\ |
||
6440 | ctx.lineWidth = linewidth;\ |
||
11005 | schaersvoo | 6441 | if(linewidth%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6442 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6443 | y = ysize;\ |
||
6444 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
6445 | ctx.moveTo(x,y0);\ |
||
6446 | ctx.lineTo(xsize,y);\ |
||
6447 | y = y - dy;\ |
||
6448 | };\ |
||
6449 | y = y0;\ |
||
6450 | for( x = xsize ; x > 0 ; x = x - dx){\ |
||
6451 | ctx.moveTo(x,ysize);\ |
||
6452 | ctx.lineTo(x0,y);\ |
||
6453 | y = y + dy;\ |
||
6454 | };\ |
||
6455 | x = x0;\ |
||
6456 | for( y = y0 ; y < ysize ; y = y + dy ){\ |
||
6457 | ctx.moveTo(xsize,y);\ |
||
6458 | ctx.lineTo(x,ysize);\ |
||
6459 | x = x + dx;\ |
||
6460 | };\ |
||
6461 | x = xsize;\ |
||
6462 | for( y = ysize ; y > y0 ; y = y - dy ){\ |
||
6463 | ctx.moveTo(x,y0);\ |
||
6464 | ctx.lineTo(x0,y);\ |
||
6465 | x = x - dx;\ |
||
6466 | };\ |
||
6467 | ctx.stroke();\ |
||
6468 | ctx.restore();\ |
||
6469 | return;\ |
||
7653 | schaersvoo | 6470 | }",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6471 | break; |
8224 | bpr | 6472 | |
7647 | schaersvoo | 6473 | case DRAW_HATCHFILL:/* not used for userdraw */ |
6474 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
||
8105 | schaersvoo | 6475 | var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7647 | schaersvoo | 6476 | var obj;\ |
6477 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6478 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6479 | }\ |
||
6480 | else\ |
||
6481 | {\ |
||
6482 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6483 | };\ |
||
6484 | var ctx = obj.getContext(\"2d\");\ |
||
6485 | var x;\ |
||
6486 | var y;\ |
||
6487 | ctx.save();\ |
||
6488 | ctx.lineWidth = linewidth;\ |
||
11005 | schaersvoo | 6489 | if(linewidth%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7647 | schaersvoo | 6490 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6491 | y = ysize;\ |
||
6492 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
6493 | ctx.moveTo(x,y0);\ |
||
6494 | ctx.lineTo(xsize,y);\ |
||
6495 | y = y - dy;\ |
||
6496 | };\ |
||
6497 | y = y0;\ |
||
6498 | for( x = xsize ; x >= dx ; x = x - dx){\ |
||
6499 | ctx.moveTo(x,ysize);\ |
||
6500 | ctx.lineTo(x0,y);\ |
||
6501 | y = y + dy;\ |
||
6502 | };\ |
||
6503 | ctx.stroke();\ |
||
6504 | ctx.restore();\ |
||
6505 | return;\ |
||
7653 | schaersvoo | 6506 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7647 | schaersvoo | 6507 | break; |
7614 | schaersvoo | 6508 | case DRAW_CIRCLES:/* used for userdraw */ |
6509 | fprintf(js_include_file,"\n<!-- draw circles -->\n\ |
||
8105 | schaersvoo | 6510 | var draw_circles = function(ctx,x_points,y_points,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6511 | ctx.save();\ |
8071 | schaersvoo | 6512 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6513 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6514 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6515 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6516 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
6517 | ctx.beginPath();\ |
||
6518 | ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\ |
||
6519 | ctx.closePath();\ |
||
6520 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6521 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
6522 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6523 | ctx.stroke();\ |
||
6524 | }\ |
||
6525 | ctx.restore();\ |
||
6526 | return;\ |
||
7653 | schaersvoo | 6527 | };"); |
7614 | schaersvoo | 6528 | break; |
7663 | schaersvoo | 6529 | case DRAW_POLYLINE:/* user for userdraw : draw lines through points */ |
6530 | fprintf(js_include_file,"\n<!-- draw polyline -->\n\ |
||
8105 | schaersvoo | 6531 | var draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7663 | schaersvoo | 6532 | ctx.save();\ |
8071 | schaersvoo | 6533 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7663 | schaersvoo | 6534 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6535 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6536 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7663 | schaersvoo | 6537 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6538 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6539 | ctx.clearRect(0,0,xsize,ysize);\ |
||
6540 | ctx.beginPath();\ |
||
6541 | for(var p = 0 ; p < x_points.length-1 ; p++ ){\ |
||
6542 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
6543 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
6544 | }\ |
||
6545 | ctx.closePath();\ |
||
6546 | ctx.stroke();\ |
||
6547 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6548 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
6549 | ctx.beginPath();\ |
||
6550 | ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\ |
||
6551 | ctx.closePath();ctx.fill();ctx.stroke();\ |
||
6552 | };\ |
||
6553 | ctx.restore();\ |
||
6554 | return;\ |
||
6555 | };"); |
||
6556 | break; |
||
8224 | bpr | 6557 | |
7614 | schaersvoo | 6558 | case DRAW_SEGMENTS:/* used for userdraw */ |
6559 | fprintf(js_include_file,"\n<!-- draw segments -->\n\ |
||
8105 | schaersvoo | 6560 | var draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6561 | ctx.save();\ |
8071 | schaersvoo | 6562 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6563 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6564 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6565 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6566 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6567 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6568 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
6569 | ctx.beginPath();\ |
||
6570 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
6571 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
6572 | ctx.closePath();\ |
||
6573 | ctx.stroke();\ |
||
6574 | }\ |
||
6575 | ctx.restore();\ |
||
6576 | return;\ |
||
6577 | };"); |
||
6578 | break; |
||
8224 | bpr | 6579 | |
7614 | schaersvoo | 6580 | case DRAW_LINES:/* used for userdraw */ |
6581 | fprintf(js_include_file,"\n<!-- draw lines -->\n\ |
||
6582 | function calc_line(x1,x2,y1,y2){\ |
||
6583 | var marge = 2;\ |
||
6584 | if(x1 < x2+marge && x1>x2-marge){\ |
||
6585 | return [x1,0,x1,ysize];\ |
||
6586 | };\ |
||
6587 | if(y1 < y2+marge && y1>y2-marge){\ |
||
6588 | return [0,y1,xsize,y1];\ |
||
6589 | };\ |
||
6590 | var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\ |
||
6591 | var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\ |
||
6592 | return [0,Y1,xsize,Y2];\ |
||
6593 | };\ |
||
8105 | schaersvoo | 6594 | var draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6595 | ctx.save();\ |
6596 | var line = new Array(4);\ |
||
8071 | schaersvoo | 6597 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6598 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6599 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6600 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6601 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6602 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6603 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
6604 | line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\ |
||
6605 | ctx.beginPath();\ |
||
6606 | ctx.moveTo(line[0],line[1]);\ |
||
6607 | ctx.lineTo(line[2],line[3]);\ |
||
6608 | ctx.closePath();\ |
||
6609 | ctx.stroke();\ |
||
6610 | }\ |
||
6611 | ctx.restore();\ |
||
6612 | return;\ |
||
6613 | };"); |
||
6614 | break; |
||
6615 | |||
8244 | schaersvoo | 6616 | case DRAW_DEMILINES:/* used for userdraw */ |
6617 | fprintf(js_include_file,"\n<!-- draw demilines -->\n\ |
||
6618 | function find_inf_point(x1,y1,x2,y2){\ |
||
6619 | if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\ |
||
6620 | var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\ |
||
6621 | if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\ |
||
6622 | };\ |
||
6623 | var draw_demilines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
||
6624 | ctx.save();\ |
||
6625 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
||
6626 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
6627 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6628 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
8244 | schaersvoo | 6629 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6630 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6631 | var pair = new Array(4);\ |
||
6632 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
6633 | pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\ |
||
6634 | ctx.beginPath();\ |
||
6635 | ctx.moveTo(pair[0],pair[1]);\ |
||
6636 | ctx.lineTo(pair[2],pair[3]);\ |
||
6637 | ctx.closePath();\ |
||
6638 | ctx.stroke();\ |
||
6639 | }\ |
||
6640 | ctx.restore();\ |
||
6641 | return;\ |
||
6642 | };"); |
||
6643 | break; |
||
6644 | |||
7614 | schaersvoo | 6645 | case DRAW_CROSSHAIRS:/* used for userdraw */ |
6646 | fprintf(js_include_file,"\n<!-- draw crosshairs -->\n\ |
||
8105 | schaersvoo | 6647 | var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
8071 | schaersvoo | 6648 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6649 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6650 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6651 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6652 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6653 | var x1,x2,y1,y2;\ |
||
6654 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
6655 | x1 = x_points[p] - crosshair_size;\ |
||
6656 | x2 = x_points[p] + crosshair_size;\ |
||
6657 | y1 = y_points[p] - crosshair_size;\ |
||
6658 | y2 = y_points[p] + crosshair_size;\ |
||
6659 | ctx.beginPath();\ |
||
6660 | ctx.moveTo(x1,y1);\ |
||
6661 | ctx.lineTo(x2,y2);\ |
||
6662 | ctx.closePath();\ |
||
6663 | ctx.stroke();\ |
||
6664 | ctx.beginPath();\ |
||
6665 | ctx.moveTo(x2,y1);\ |
||
6666 | ctx.lineTo(x1,y2);\ |
||
6667 | ctx.closePath();\ |
||
6668 | ctx.stroke();\ |
||
6669 | }\ |
||
6670 | ctx.restore();\ |
||
6671 | return;\ |
||
7653 | schaersvoo | 6672 | };"); |
7614 | schaersvoo | 6673 | break; |
6674 | |||
6675 | case DRAW_RECTS:/* used for userdraw */ |
||
6676 | fprintf(js_include_file,"\n<!-- draw rects -->\n\ |
||
8105 | schaersvoo | 6677 | var draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6678 | ctx.save();\ |
8071 | schaersvoo | 6679 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6680 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6681 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6682 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
8448 | schaersvoo | 6683 | ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\ |
7614 | schaersvoo | 6684 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\ |
6685 | for(var p = 0 ; p < x_points.length ; p = p + 2){\ |
||
6686 | ctx.beginPath();\ |
||
6687 | ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\ |
||
6688 | ctx.closePath();\ |
||
8448 | schaersvoo | 6689 | if(use_filled == 1 ){ctx.fillStyle = 'rgba('+fill_color+','+fill_opacity+')';ctx.fill();}\ |
7614 | schaersvoo | 6690 | ctx.stroke();\ |
6691 | };\ |
||
6692 | ctx.restore();\ |
||
6693 | return;\ |
||
7653 | schaersvoo | 6694 | };"); |
7614 | schaersvoo | 6695 | break; |
6696 | |||
6697 | case DRAW_ROUNDRECTS:/* used for userdraw */ |
||
6698 | fprintf(js_include_file,"\n<!-- draw round rects -->\n\ |
||
8105 | schaersvoo | 6699 | var draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6700 | ctx.save();\ |
8071 | schaersvoo | 6701 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6702 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
6703 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
9462 | schaersvoo | 6704 | ctx.lineWidth = line_width;\ |
9465 | schaersvoo | 6705 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6706 | var x,y,w,h,r;\ |
6707 | for(var p = 0; p < x_points.length; p = p+2){\ |
||
6708 | x = x_points[p];y = y_points[p];w = x_points[p+1] - x;h = y_points[p+1] - y;r = parseInt(0.1*w);\ |
||
6709 | ctx.beginPath();ctx.moveTo(x + r, y);\ |
||
6710 | ctx.lineTo(x + w - r, y);\ |
||
6711 | ctx.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
6712 | ctx.lineTo(x + w, y + h - r);\ |
||
6713 | ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
6714 | ctx.lineTo(x + r, y + h);\ |
||
6715 | ctx.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
6716 | ctx.lineTo(x, y + r);\ |
||
6717 | ctx.quadraticCurveTo(x, y, x + r, y);\ |
||
6718 | ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\ |
||
6719 | ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6720 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\ |
||
6721 | ctx.stroke();\ |
||
6722 | }\ |
||
6723 | ctx.restore();\ |
||
7653 | schaersvoo | 6724 | };"); |
8224 | bpr | 6725 | break; |
7614 | schaersvoo | 6726 | |
6727 | case DRAW_ELLIPSES:/* not used for userdraw */ |
||
6728 | fprintf(js_include_file,"\n<!-- draw ellipses -->\n\ |
||
8105 | schaersvoo | 6729 | var draw_ellipses = function(canvas_type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6730 | var obj;\ |
6731 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6732 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6733 | }\ |
||
6734 | else\ |
||
6735 | {\ |
||
6736 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6737 | };\ |
||
6738 | var ctx = obj.getContext(\"2d\");\ |
||
6739 | ctx.save();\ |
||
8071 | schaersvoo | 6740 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6741 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6742 | var cx,cy,ry,rx;\ |
||
6743 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6744 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6745 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\ |
6746 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6747 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6748 | for(var p=0;p< x_points.length;p = p+2){\ |
||
6749 | ctx.beginPath();\ |
||
6750 | cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\ |
||
6751 | ctx.translate(cx - rx, cy - ry);\ |
||
6752 | ctx.scale(rx, ry);\ |
||
6753 | ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\ |
||
6754 | if( use_filled == 1 ){ctx.fill();}\ |
||
6755 | ctx.stroke();\ |
||
6756 | };\ |
||
6757 | ctx.restore();\ |
||
7653 | schaersvoo | 6758 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6759 | break; |
6760 | |||
6761 | case DRAW_PATHS: /* used for userdraw */ |
||
6762 | fprintf(js_include_file,"\n<!-- draw paths -->\n\ |
||
8105 | schaersvoo | 6763 | var draw_paths = function(ctx,x_points,y_points,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6764 | ctx.save();\ |
8071 | schaersvoo | 6765 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6766 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6767 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6768 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6769 | ctx.lineJoin = \"round\";\ |
6770 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6771 | ctx.beginPath();\ |
||
6772 | ctx.moveTo(x_points[0],y_points[0]);\ |
||
6773 | for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\ |
||
6774 | if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\ |
||
6775 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6776 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
6777 | ctx.stroke();\ |
||
6778 | ctx.restore();\ |
||
6779 | return;\ |
||
6780 | };"); |
||
8224 | bpr | 6781 | |
7614 | schaersvoo | 6782 | break; |
6783 | case DRAW_ARROWS:/* used for userdraw */ |
||
6784 | fprintf(js_include_file,"\n<!-- draw arrows -->\n\ |
||
8105 | schaersvoo | 6785 | var draw_arrows = function(ctx,x_points,y_points,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6786 | ctx.save();\ |
8071 | schaersvoo | 6787 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6788 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6789 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6790 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6791 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 6792 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6793 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
6794 | ctx.lineCap = \"round\";\ |
||
6795 | var x1,y1,x2,y2,dx,dy,len;\ |
||
6796 | for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\ |
||
7874 | schaersvoo | 6797 | ctx.save();\ |
7614 | schaersvoo | 6798 | x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\ |
6799 | len = Math.sqrt(dx*dx+dy*dy);\ |
||
6800 | ctx.translate(x2,y2);\ |
||
6801 | ctx.rotate(Math.atan2(dy,dx));\ |
||
6802 | ctx.lineCap = \"round\";\ |
||
6803 | ctx.beginPath();\ |
||
6804 | ctx.moveTo(0,0);\ |
||
6805 | ctx.lineTo(-len,0);\ |
||
6806 | ctx.closePath();\ |
||
6807 | ctx.stroke();\ |
||
6808 | ctx.beginPath();\ |
||
6809 | ctx.moveTo(0,0);\ |
||
6810 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
6811 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
6812 | ctx.closePath();\ |
||
6813 | ctx.fill();\ |
||
7874 | schaersvoo | 6814 | ctx.restore();\ |
7614 | schaersvoo | 6815 | if( type == 2 ){\ |
6816 | ctx.save();\ |
||
6817 | ctx.translate(x1,y1);\ |
||
6818 | ctx.rotate(Math.atan2(-dy,-dx));\ |
||
6819 | ctx.beginPath();\ |
||
6820 | ctx.moveTo(0,0);\ |
||
8347 | schaersvoo | 6821 | ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\ |
6822 | ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\ |
||
7614 | schaersvoo | 6823 | ctx.closePath();\ |
6824 | ctx.stroke();\ |
||
6825 | ctx.fill();\ |
||
7874 | schaersvoo | 6826 | ctx.restore();\ |
8379 | schaersvoo | 6827 | };\ |
6828 | };\ |
||
7614 | schaersvoo | 6829 | ctx.restore();\ |
6830 | return;\ |
||
7653 | schaersvoo | 6831 | };"); |
7614 | schaersvoo | 6832 | break; |
6833 | |||
6834 | case DRAW_VIDEO:/* not used for userdraw */ |
||
6835 | fprintf(js_include_file,"\n<!-- draw video -->\n\ |
||
8105 | schaersvoo | 6836 | var draw_video = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 6837 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
6838 | var video_div = document.createElement(\"div\");\ |
||
6839 | canvas_div.appendChild(video_div);\ |
||
6840 | video_div.style.position = \"absolute\";\ |
||
6841 | video_div.style.left = x+\"px\";\ |
||
6842 | video_div.style.top = y+\"px\";\ |
||
6843 | video_div.style.width = w+\"px\";\ |
||
6844 | video_div.style.height = h+\"px\";\ |
||
6845 | var video = document.createElement(\"video\");\ |
||
6846 | video_div.appendChild(video);\ |
||
6847 | video.style.width = w+\"px\";\ |
||
6848 | video.style.height = h+\"px\";\ |
||
6849 | video.autobuffer = true;\ |
||
6850 | video.controls = true;video.autoplay = false;\ |
||
6851 | var src = document.createElement(\"source\");\ |
||
6852 | src.type = \"video/mp4\";\ |
||
6853 | src.src = URL;\ |
||
6854 | video.appendChild(src);\ |
||
6855 | video.load();\ |
||
6856 | return;\ |
||
8224 | bpr | 6857 | };"); |
7614 | schaersvoo | 6858 | break; |
8224 | bpr | 6859 | |
7614 | schaersvoo | 6860 | case DRAW_AUDIO:/* not used for userdraw */ |
6861 | fprintf(js_include_file,"\n<!-- draw audio -->\n\ |
||
8105 | schaersvoo | 6862 | var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\ |
7614 | schaersvoo | 6863 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
6864 | var audio_div = document.createElement(\"div\");\ |
||
6865 | canvas_div.appendChild(audio_div);\ |
||
6866 | audio_div.style.position = \"absolute\";\ |
||
6867 | audio_div.style.left = x+\"px\";\ |
||
6868 | audio_div.style.top = y+\"px\";\ |
||
6869 | audio_div.style.width = w+\"px\";\ |
||
6870 | audio_div.style.height = h+\"px\";\ |
||
6871 | var audio = document.createElement(\"audio\");\ |
||
6872 | audio_div.appendChild(audio);\ |
||
6873 | audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\ |
||
6874 | audio.autobuffer = true;\ |
||
8379 | schaersvoo | 6875 | if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\ |
6876 | if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\ |
||
7614 | schaersvoo | 6877 | var src1 = document.createElement(\"source\");\ |
6878 | src1.type = \"audio/ogg\";\ |
||
6879 | src1.src = URL1;\ |
||
6880 | audio.appendChild(src1);\ |
||
6881 | var src2 = document.createElement(\"source\");\ |
||
6882 | src2.type = \"audio/mpeg\";\ |
||
6883 | src2.src = URL2;\ |
||
6884 | audio.appendChild(src2);\ |
||
6885 | audio.load();\ |
||
6886 | return;\ |
||
7653 | schaersvoo | 6887 | };"); |
7614 | schaersvoo | 6888 | break; |
8224 | bpr | 6889 | |
7614 | schaersvoo | 6890 | case DRAW_HTTP:/* not used for userdraw */ |
6891 | fprintf(js_include_file,"\n<!-- draw http -->\n\ |
||
8105 | schaersvoo | 6892 | var draw_http = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 6893 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
6894 | var http_div = document.createElement(\"div\");\ |
||
6895 | var iframe = document.createElement(\"iframe\");\ |
||
6896 | canvas_div.appendChild(http_div);\ |
||
6897 | http_div.appendChild(iframe);\ |
||
6898 | iframe.src = URL;\ |
||
6899 | iframe.setAttribute(\"width\",w);\ |
||
6900 | iframe.setAttribute(\"height\",h);\ |
||
6901 | return;\ |
||
7653 | schaersvoo | 6902 | };"); |
7614 | schaersvoo | 6903 | break; |
8224 | bpr | 6904 | |
7614 | schaersvoo | 6905 | case DRAW_XML: |
6906 | fprintf(js_include_file,"\n<!-- draw xml -->\n\ |
||
8379 | schaersvoo | 6907 | var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick,click_cnt,stroke_color,stroke_opacity){\ |
7614 | schaersvoo | 6908 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
6909 | var xml_div = document.createElement(\"div\");\ |
||
6910 | canvas_div.appendChild(xml_div);\ |
||
6911 | xml_div.innerHTML = mathml;\ |
||
8379 | schaersvoo | 6912 | xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7614 | schaersvoo | 6913 | if(onclick != 0){\ |
6914 | xml_div.onclick = function(){\ |
||
8379 | schaersvoo | 6915 | reply[0] = click_cnt;\ |
7614 | schaersvoo | 6916 | };\ |
8379 | schaersvoo | 6917 | xml_div.onmouseover = function(){\ |
6918 | xml_div.style.color = \"red\";\ |
||
6919 | };\ |
||
6920 | xml_div.onmouseout = function(){\ |
||
6921 | xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6922 | };\ |
||
7614 | schaersvoo | 6923 | };\ |
6924 | xml_div.style.position = \"absolute\";\ |
||
6925 | xml_div.style.left = x+\"px\";\ |
||
6926 | xml_div.style.top = y+\"px\";\ |
||
6927 | xml_div.style.width = w+\"px\";\ |
||
6928 | xml_div.style.height = h+\"px\";\ |
||
6929 | return;\ |
||
7653 | schaersvoo | 6930 | };" |
7614 | schaersvoo | 6931 | ); |
6932 | break; |
||
7654 | schaersvoo | 6933 | case DRAW_SGRAPH: |
8224 | bpr | 6934 | /* |
7654 | schaersvoo | 6935 | xstart = given |
6936 | ystart = given |
||
6937 | sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily) |
||
6938 | */ |
||
6939 | fprintf(js_include_file,"\n<!-- draw sgraph -->\n\ |
||
8105 | schaersvoo | 6940 | var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\ |
7658 | schaersvoo | 6941 | var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{ obj = create_canvas%d(canvas_type,xsize,ysize);};\ |
6942 | var ctx = obj.getContext(\"2d\");\ |
||
6943 | ctx.font = fontfamily;\ |
||
6944 | var minor_opacity = 0.8*opacity;\ |
||
6945 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7976 | schaersvoo | 6946 | var zero_x = 0.1*xsize;\ |
6947 | var zero_y = 0.9*ysize;\ |
||
8129 | schaersvoo | 6948 | var snor_x;var snor_y;\ |
7654 | schaersvoo | 6949 | if( xstart != xmin){\ |
7658 | schaersvoo | 6950 | snor_x = 0.1*xsize;\ |
6951 | }\ |
||
6952 | else\ |
||
6953 | {\ |
||
6954 | snor_x = 0;\ |
||
6955 | xstart = xmin;\ |
||
6956 | };\ |
||
6957 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
6958 | ctx.lineWidth = 2;\ |
||
6959 | ctx.beginPath();\ |
||
6960 | ctx.moveTo(xsize,zero_y);\ |
||
6961 | ctx.lineTo(zero_x,zero_y);\ |
||
6962 | ctx.lineTo(zero_x,0);\ |
||
6963 | ctx.stroke();\ |
||
6964 | ctx.closePath();\ |
||
6965 | ctx.beginPath();\ |
||
6966 | ctx.moveTo(zero_x,zero_y);\ |
||
6967 | ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\ |
||
6968 | ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\ |
||
6969 | ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\ |
||
6970 | ctx.lineTo(zero_x + snor_x,zero_y);\ |
||
6971 | ctx.stroke();\ |
||
6972 | ctx.closePath();\ |
||
6973 | ctx.beginPath();\ |
||
6974 | var num = xstart;\ |
||
7660 | schaersvoo | 6975 | var flipflop = 1;\ |
7658 | schaersvoo | 6976 | var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\ |
7976 | schaersvoo | 6977 | var txtsize;var txt_marge=step_x - 5;\ |
7658 | schaersvoo | 6978 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
7976 | schaersvoo | 6979 | txtsize = ctx.measureText(num).width;\ |
6980 | if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\ |
||
6981 | if( flipflop == 1){\ |
||
6982 | ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\ |
||
6983 | }\ |
||
6984 | else\ |
||
6985 | {\ |
||
6986 | ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\ |
||
8379 | schaersvoo | 6987 | };\ |
7976 | schaersvoo | 6988 | num = num + xmajor;\ |
7658 | schaersvoo | 6989 | };\ |
6990 | ctx.stroke();\ |
||
6991 | ctx.closePath();\ |
||
6992 | ctx.lineWidth = 1;\ |
||
6993 | ctx.beginPath();\ |
||
6994 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
6995 | ctx.moveTo(x,zero_y);\ |
||
6996 | ctx.lineTo(x,0);\ |
||
6997 | };\ |
||
6998 | ctx.stroke();\ |
||
6999 | ctx.closePath();\ |
||
7000 | if( xminor > 1){\ |
||
7001 | ctx.lineWidth = 0.5;\ |
||
7002 | ctx.beginPath();\ |
||
7003 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
7004 | var minor_step_x = step_x / xminor;\ |
||
7005 | var nx;\ |
||
7006 | for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\ |
||
7007 | num = 1;\ |
||
7008 | for(var p = 1 ; p < xminor ; p++){\ |
||
7009 | nx = x + num*minor_step_x;\ |
||
7010 | ctx.moveTo(nx,zero_y);\ |
||
7011 | ctx.lineTo(nx,0);\ |
||
7012 | num++;\ |
||
7013 | };\ |
||
7014 | };\ |
||
7015 | ctx.stroke();\ |
||
7016 | ctx.closePath();\ |
||
7017 | ctx.beginPath();\ |
||
7018 | ctx.lineWidth = 2;\ |
||
7019 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
7020 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
7021 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\ |
||
7022 | };\ |
||
7023 | for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\ |
||
7024 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\ |
||
7025 | };\ |
||
7026 | ctx.stroke();\ |
||
7027 | ctx.closePath();\ |
||
7028 | ctx.lineWidth = 0.5;\ |
||
7029 | };\ |
||
7030 | xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\ |
||
7031 | if( ystart != ymin){\ |
||
7032 | snor_y = 0.1*ysize;\ |
||
7033 | }\ |
||
7034 | else\ |
||
7035 | {\ |
||
7036 | snor_y = 0;\ |
||
7037 | ystart = ymin;\ |
||
7038 | };\ |
||
7039 | ctx.lineWidth = 2;\ |
||
7040 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
7041 | ctx.beginPath();\ |
||
7042 | ctx.moveTo(zero_x,zero_y);\ |
||
7043 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\ |
||
7044 | ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\ |
||
7045 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\ |
||
7046 | ctx.lineTo(zero_x,zero_y - snor_y);\ |
||
7047 | ctx.stroke();\ |
||
7048 | ctx.closePath();\ |
||
7049 | ctx.beginPath();\ |
||
7050 | ctx.lineWidth = 1;\ |
||
7051 | num = ystart;\ |
||
7052 | var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\ |
||
7053 | for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\ |
||
7054 | ctx.moveTo(zero_x,y);\ |
||
7055 | ctx.lineTo(xsize,y);\ |
||
7056 | ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\ |
||
7057 | num = num + ymajor;\ |
||
7058 | };\ |
||
7059 | ctx.stroke();\ |
||
7060 | ctx.closePath();\ |
||
7061 | if( yminor > 1){\ |
||
7062 | ctx.lineWidth = 0.5;\ |
||
7063 | ctx.beginPath();\ |
||
7064 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
7065 | var minor_step_y = step_y / yminor;\ |
||
7066 | var ny;\ |
||
7067 | for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\ |
||
7068 | num = 1;\ |
||
7069 | for(var p = 1 ;p < yminor;p++){\ |
||
7070 | ny = y + num*minor_step_y;\ |
||
7071 | ctx.moveTo(zero_x,ny);\ |
||
7072 | ctx.lineTo(xsize,ny);\ |
||
7073 | num++;\ |
||
7074 | };\ |
||
7075 | };\ |
||
7076 | ctx.stroke();\ |
||
7077 | ctx.closePath();\ |
||
7078 | ctx.lineWidth = 2;\ |
||
7079 | ctx.beginPath();\ |
||
7080 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
7081 | for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\ |
||
7082 | ctx.moveTo(zero_x,y);\ |
||
7083 | ctx.lineTo(zero_x+12,y);\ |
||
7084 | };\ |
||
7085 | for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\ |
||
7086 | ctx.moveTo(zero_x,y);\ |
||
7087 | ctx.lineTo(zero_x+6,y);\ |
||
7088 | };\ |
||
7089 | ctx.stroke();\ |
||
7090 | ctx.closePath();\ |
||
7091 | };\ |
||
7092 | ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\ |
||
7654 | schaersvoo | 7093 | if( typeof legend%d !== 'undefined' ){\ |
7094 | ctx.globalAlpha = 1.0;\ |
||
7095 | var y_offset = 2*font_size;\ |
||
7096 | var txt;var txt_size;\ |
||
7097 | var x_offset = xsize - 2*font_size;\ |
||
7098 | var l_length = legend%d.length;var barcolor = new Array();\ |
||
7099 | if( typeof legendcolors%d !== 'undefined' ){\ |
||
7100 | for(var p = 0 ; p < l_length ; p++){\ |
||
7101 | barcolor[p] = legendcolors%d[p];\ |
||
7102 | };\ |
||
7103 | }else{\ |
||
7104 | if( barcolor.length == 0 ){\ |
||
7105 | for(var p = 0 ; p < l_length ; p++){\ |
||
7106 | barcolor[p] = stroke_color;\ |
||
7107 | };\ |
||
7108 | };\ |
||
7109 | };\ |
||
7110 | for(var p = 0; p < l_length; p++){\ |
||
7111 | ctx.fillStyle = barcolor[p];\ |
||
7112 | txt = legend%d[p];\ |
||
7113 | txt_size = ctx.measureText(txt).width;\ |
||
7114 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
7115 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
7116 | };\ |
||
7117 | };\ |
||
7660 | schaersvoo | 7118 | if( typeof xaxislabel !== 'undefined' ){\ |
7658 | schaersvoo | 7119 | ctx.fillStyle = \'#000000\';\ |
7120 | var txt_size = ctx.measureText(xaxislabel).width + 4 ;\ |
||
7121 | ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\ |
||
7122 | };\ |
||
7660 | schaersvoo | 7123 | if( typeof yaxislabel !== 'undefined'){\ |
7658 | schaersvoo | 7124 | ctx.save();\ |
7125 | ctx.fillStyle = \'#000000\';\ |
||
7126 | var txt_size = ctx.measureText(yaxislabel).width;\ |
||
7127 | ctx.translate(zero_x+8 + font_size,txt_size+font_size);\ |
||
7128 | ctx.rotate(-0.5*Math.PI);\ |
||
7129 | ctx.fillText(yaxislabel,0,0);\ |
||
7874 | schaersvoo | 7130 | ctx.restore();\ |
7658 | schaersvoo | 7131 | };\ |
7654 | schaersvoo | 7132 | };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7133 | break; |
||
7614 | schaersvoo | 7134 | |
7135 | case DRAW_GRID:/* not used for userdraw */ |
||
7136 | fprintf(js_include_file,"\n<!-- draw grid -->\n\ |
||
8105 | schaersvoo | 7137 | var draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\ |
7988 | schaersvoo | 7138 | var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{obj = create_canvas%d(canvas_type,xsize,ysize);};\ |
7139 | var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\ |
||
7614 | schaersvoo | 7140 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7141 | ctx.save();\ |
||
8071 | schaersvoo | 7142 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 7143 | if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\ |
7144 | var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7145 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\ |
||
7146 | var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\ |
||
7147 | ctx.font = font_family;\ |
||
7988 | schaersvoo | 7148 | var barcolor = new Array();\ |
7614 | schaersvoo | 7149 | var xstep = xsize*xmajor/(xmax - xmin);\ |
7150 | var ystep = ysize*ymajor/(ymax - ymin);\ |
||
7151 | var x2step = xstep / xminor;\ |
||
7152 | var y2step = ystep / yminor;\ |
||
7996 | schaersvoo | 7153 | var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\ |
7154 | if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\ |
||
7155 | if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\ |
||
9465 | schaersvoo | 7156 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7157 | ctx.beginPath();\ |
7158 | ctx.lineWidth = line_width;\ |
||
7159 | ctx.strokeStyle = stroke_color;\ |
||
7160 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
7161 | ctx.moveTo(p,0);\ |
||
7162 | ctx.lineTo(p,ysize);\ |
||
7163 | };\ |
||
7164 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
7165 | ctx.moveTo(p,0);\ |
||
7166 | ctx.lineTo(p,ysize);\ |
||
7167 | };\ |
||
7168 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
7169 | ctx.moveTo(0,p);\ |
||
7170 | ctx.lineTo(xsize,p);\ |
||
7171 | };\ |
||
7172 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
7173 | ctx.moveTo(0,p);\ |
||
7174 | ctx.lineTo(xsize,p);\ |
||
7175 | };\ |
||
7176 | if( typeof xaxislabel !== 'undefined' ){\ |
||
7177 | ctx.save();\ |
||
7178 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
7179 | var corr = ctx.measureText(xaxislabel).width;\ |
||
7180 | ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\ |
||
7181 | ctx.restore();\ |
||
7182 | };\ |
||
7183 | if( typeof yaxislabel !== 'undefined' ){\ |
||
7184 | ctx.save();\ |
||
7185 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
7988 | schaersvoo | 7186 | var corr = ctx.measureText(yaxislabel).width;\ |
7614 | schaersvoo | 7187 | ctx.translate(zero_x+tics_length + font_size,corr+font_size);\ |
7188 | ctx.rotate(-0.5*Math.PI);\ |
||
7189 | ctx.fillText(yaxislabel,0,0);\ |
||
7190 | ctx.restore();\ |
||
7191 | };\ |
||
7192 | ctx.stroke();\ |
||
7193 | ctx.closePath();\ |
||
7194 | if( use_axis == 1 ){\ |
||
7988 | schaersvoo | 7195 | ctx.save();\ |
7614 | schaersvoo | 7196 | ctx.beginPath();\ |
7197 | ctx.strokeStyle = stroke_color;\ |
||
7198 | ctx.lineWidth = 0.6*line_width;\ |
||
7199 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
7200 | ctx.moveTo(p,0);\ |
||
7201 | ctx.lineTo(p,ysize);\ |
||
7202 | };\ |
||
7203 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
7204 | ctx.moveTo(p,0);\ |
||
7205 | ctx.lineTo(p,ysize);\ |
||
7206 | };\ |
||
7207 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
7208 | ctx.moveTo(0,p);\ |
||
7209 | ctx.lineTo(xsize,p);\ |
||
7210 | };\ |
||
7211 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
7212 | ctx.moveTo(0,p);\ |
||
7213 | ctx.lineTo(xsize,p);\ |
||
7214 | };\ |
||
7215 | ctx.stroke();\ |
||
7216 | ctx.closePath();\ |
||
7217 | ctx.beginPath();\ |
||
7218 | ctx.lineWidth = 2*line_width;\ |
||
7219 | ctx.strokeStyle = axis_color;\ |
||
7220 | ctx.moveTo(0,zero_y);\ |
||
7221 | ctx.lineTo(xsize,zero_y);\ |
||
7222 | ctx.moveTo(zero_x,0);\ |
||
7223 | ctx.lineTo(zero_x,ysize);\ |
||
7224 | ctx.stroke();\ |
||
7225 | ctx.closePath();\ |
||
7226 | ctx.lineWidth = line_width+0.5;\ |
||
7227 | ctx.beginPath();\ |
||
7228 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
7229 | ctx.moveTo(p,zero_y-tics_length);\ |
||
7230 | ctx.lineTo(p,zero_y+tics_length);\ |
||
7231 | };\ |
||
7232 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
7233 | ctx.moveTo(p,zero_y-tics_length);\ |
||
7234 | ctx.lineTo(p,zero_y+tics_length);\ |
||
7235 | };\ |
||
7236 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
7237 | ctx.moveTo(zero_x-tics_length,p);\ |
||
7238 | ctx.lineTo(zero_x+tics_length,p);\ |
||
7239 | };\ |
||
7240 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
7241 | ctx.moveTo(zero_x-tics_length,p);\ |
||
7242 | ctx.lineTo(zero_x+tics_length,p);\ |
||
7243 | };\ |
||
7244 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
7245 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
7246 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
7247 | };\ |
||
7248 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
7249 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
7250 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
7251 | };\ |
||
7252 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
7253 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
7254 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
7255 | };\ |
||
7256 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
7257 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
7258 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
7259 | };\ |
||
7260 | ctx.stroke();\ |
||
7261 | ctx.closePath();\ |
||
7988 | schaersvoo | 7262 | ctx.restore();\ |
7263 | };\ |
||
7264 | if( use_axis_numbering == 1 ){\ |
||
7265 | ctx.save();\ |
||
7266 | ctx.fillColor = axis_color;\ |
||
8110 | schaersvoo | 7267 | ctx.strokeStyle = axis_color;\ |
7268 | ctx.lineWidth = 2*line_width;\ |
||
7988 | schaersvoo | 7269 | ctx.font = font_family;\ |
7270 | var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\ |
||
7271 | if( x_strings != null ){\ |
||
7272 | var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 7273 | ctx.beginPath();\ |
9341 | schaersvoo | 7274 | if( x_strings_up == null){\ |
7275 | for(var p = 0 ; p < len ; p = p+2){\ |
||
7276 | var x_nums = x2px(eval(x_strings[p]));\ |
||
7277 | var x_text = x_strings[p+1];\ |
||
7278 | corr = ctx.measureText(x_text).width;\ |
||
7279 | skip = 1.2*corr/xstep;\ |
||
7280 | if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\ |
||
7281 | if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\ |
||
7282 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\ |
||
7283 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
7284 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
7285 | };\ |
||
7286 | }\ |
||
7287 | else\ |
||
7288 | {\ |
||
7289 | for(var p = 0 ; p < len ; p = p+2){\ |
||
7290 | var x_nums = x2px(eval(x_strings[p]));\ |
||
7291 | var x_text = x_strings[p+1];\ |
||
7292 | corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\ |
||
7293 | if( corr > ysize ){corr = ysize;};\ |
||
7294 | ctx.save();\ |
||
9346 | schaersvoo | 7295 | ctx.translate(x_nums+0.25*font_size, corr);\ |
9341 | schaersvoo | 7296 | ctx.rotate(-1.5708);\ |
7297 | ctx.fillText(x_text,0,0);\ |
||
7298 | ctx.restore();\ |
||
7299 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
7300 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
7301 | };\ |
||
7988 | schaersvoo | 7302 | };\ |
8110 | schaersvoo | 7303 | ctx.closePath();\ |
7988 | schaersvoo | 7304 | }\ |
7305 | else\ |
||
7306 | {\ |
||
7307 | skip = 1;cnt = px2x(zero_x);\ |
||
7308 | prec = Math.log(precision)/(Math.log(10));\ |
||
7309 | var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\ |
||
7310 | for( var p = zero_x ; p < xsize ; p = p+xstep){\ |
||
7311 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 7312 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7313 | corr = ctx.measureText(disp_cnt).width;\ |
7314 | skip = parseInt(1.2*corr/xstep);\ |
||
7315 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
7614 | schaersvoo | 7316 | }\ |
7988 | schaersvoo | 7317 | else\ |
7318 | {\ |
||
7319 | skip--;\ |
||
7614 | schaersvoo | 7320 | };\ |
7988 | schaersvoo | 7321 | cnt = cnt + xmajor;\ |
7614 | schaersvoo | 7322 | };\ |
7988 | schaersvoo | 7323 | cnt = px2x(zero_x);skip = 1;\ |
7324 | for( var p = zero_x ; p > 0 ; p = p-xstep){\ |
||
7325 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 7326 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7327 | corr = ctx.measureText(disp_cnt).width;\ |
7328 | skip = parseInt(1.2*corr/xstep);\ |
||
7329 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
7330 | }\ |
||
7331 | else\ |
||
7332 | {\ |
||
7333 | skip--;\ |
||
7614 | schaersvoo | 7334 | };\ |
7988 | schaersvoo | 7335 | cnt = cnt - xmajor;\ |
7614 | schaersvoo | 7336 | };\ |
7337 | };\ |
||
7988 | schaersvoo | 7338 | if( y_strings != null ){\ |
7339 | var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 7340 | ctx.beginPath();\ |
7988 | schaersvoo | 7341 | for(var p = 0 ; p < len ; p = p+2){\ |
7342 | var y_nums = y2px(eval(y_strings[p]));\ |
||
7343 | var y_text = y_strings[p+1];\ |
||
7344 | corr = 2 + tics_length + ctx.measureText(y_text).width;\ |
||
7345 | if( corr > zero_x){corr = parseInt(zero_x+2); }\ |
||
8110 | schaersvoo | 7346 | ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\ |
7347 | ctx.moveTo(zero_x - tics_length,y_nums);\ |
||
7348 | ctx.lineTo(zero_x + tics_length,y_nums);\ |
||
7614 | schaersvoo | 7349 | };\ |
8110 | schaersvoo | 7350 | ctx.closePath();\ |
7988 | schaersvoo | 7351 | }\ |
7352 | else\ |
||
7353 | {\ |
||
7991 | schaersvoo | 7354 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 7355 | cnt = px2y(zero_y);skip = 1;\ |
7356 | for( var p = zero_y ; p < ysize ; p = p+ystep){\ |
||
7357 | if(skip == 0 ){\ |
||
7358 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 7359 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7360 | if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
7361 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
7362 | }\ |
||
7363 | else\ |
||
7364 | {\ |
||
7365 | skip--;\ |
||
7366 | };\ |
||
7367 | cnt = cnt - ymajor;\ |
||
7614 | schaersvoo | 7368 | };\ |
7988 | schaersvoo | 7369 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
7991 | schaersvoo | 7370 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 7371 | for( var p = zero_y ; p > 0 ; p = p-ystep){\ |
7372 | if(skip == 0 ){\ |
||
7373 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 7374 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7375 | if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
7376 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
7377 | }\ |
||
7378 | else\ |
||
7379 | {\ |
||
7380 | skip--;\ |
||
7381 | };\ |
||
7382 | cnt = cnt + ymajor;\ |
||
7614 | schaersvoo | 7383 | };\ |
7384 | };\ |
||
7988 | schaersvoo | 7385 | ctx.stroke();\ |
7614 | schaersvoo | 7386 | ctx.restore();\ |
7387 | };\ |
||
7956 | schaersvoo | 7388 | if( typeof legend0 !== 'undefined' ){\ |
7988 | schaersvoo | 7389 | ctx.save();\ |
7614 | schaersvoo | 7390 | ctx.globalAlpha = 1.0;\ |
7391 | ctx.font = \"bold \"+font_size+\"px Ariel\";\ |
||
7392 | var y_offset = 2*font_size;\ |
||
7393 | var txt;var txt_size;\ |
||
7394 | var x_offset = xsize - 2*font_size;\ |
||
7956 | schaersvoo | 7395 | var l_length = legend0.length;\ |
7396 | if( typeof legendcolors0 !== 'undefined' ){\ |
||
7614 | schaersvoo | 7397 | for(var p = 0 ; p < l_length ; p++){\ |
7956 | schaersvoo | 7398 | barcolor[p] = legendcolors0[p];\ |
7614 | schaersvoo | 7399 | };\ |
7988 | schaersvoo | 7400 | }\ |
7401 | else\ |
||
7402 | {\ |
||
7614 | schaersvoo | 7403 | if( barcolor.length == 0 ){\ |
7404 | for(var p = 0 ; p < l_length ; p++){\ |
||
7405 | barcolor[p] = stroke_color;\ |
||
7406 | };\ |
||
7407 | };\ |
||
7408 | };\ |
||
7409 | for(var p = 0; p < l_length; p++){\ |
||
7410 | ctx.fillStyle = barcolor[p];\ |
||
7956 | schaersvoo | 7411 | txt = legend0[p];\ |
7614 | schaersvoo | 7412 | txt_size = ctx.measureText(txt).width;\ |
7956 | schaersvoo | 7413 | ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\ |
7614 | schaersvoo | 7414 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
7415 | };\ |
||
7988 | schaersvoo | 7416 | ctx.restore();\ |
7614 | schaersvoo | 7417 | };\ |
7991 | schaersvoo | 7418 | if( typeof barchart_0 !== 'undefined' ){\ |
7419 | ctx.save();\ |
||
7420 | var num_barcharts = 0;\ |
||
7421 | var bar_name = eval('barchart_0');\ |
||
7422 | while( typeof bar_name !== 'undefined' ){\ |
||
7423 | try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\ |
||
7424 | };\ |
||
9346 | schaersvoo | 7425 | var bar_width = parseInt(0.8*x2step/(num_barcharts));\ |
7991 | schaersvoo | 7426 | for(var i=0 ; i< num_barcharts ; i++){\ |
7427 | bar_name = eval('barchart_'+i);\ |
||
7428 | var bar_x = new Array();\ |
||
7429 | var bar_y = new Array();\ |
||
7430 | var lb = bar_name.length;\ |
||
7431 | var idx = 0;\ |
||
7432 | var dx = parseInt(0.5*i*bar_width);\ |
||
7433 | for( var p = 0 ; p < lb ; p = p + 3 ){\ |
||
7434 | bar_x[idx] = x2px(bar_name[p]);\ |
||
7435 | bar_y[idx] = y2px(bar_name[p+1]);\ |
||
7436 | barcolor[idx] = bar_name[p+2];\ |
||
7437 | idx++;\ |
||
7438 | };\ |
||
7439 | ctx.globalAlpha = fill_opacity;\ |
||
7440 | ctx.beginPath();\ |
||
7441 | for( var p = 0; p < idx ; p++ ){\ |
||
7442 | ctx.strokeStyle = barcolor[p];\ |
||
7443 | ctx.fillStyle = barcolor[p];\ |
||
9346 | schaersvoo | 7444 | ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\ |
7991 | schaersvoo | 7445 | };\ |
7446 | ctx.fill();\ |
||
7447 | ctx.stroke();\ |
||
7448 | ctx.closePath();\ |
||
7449 | };\ |
||
7450 | ctx.restore();\ |
||
7451 | };\ |
||
7996 | schaersvoo | 7452 | if( typeof linegraph_0 !== 'undefined' ){\ |
7453 | ctx.save();\ |
||
7454 | ctx.globalAlpha = 1.0;\ |
||
7455 | var i = 0;\ |
||
7456 | var line_name = eval('linegraph_'+i);\ |
||
7457 | while ( typeof line_name !== 'undefined' ){\ |
||
7458 | ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\ |
||
7459 | ctx.lineWidth = parseInt(line_name[1]);\ |
||
7460 | if(line_name[2] == \"1\"){\ |
||
7461 | var d1 = parseInt(line_name[3]);\ |
||
7462 | var d2 = parseInt(line_name[4]);\ |
||
7463 | if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\ |
||
7464 | }\ |
||
7465 | else\ |
||
7466 | {\ |
||
7467 | if(ctx.setLineDash){ctx.setLineDash = null;}\ |
||
7468 | if(ctx.mozDash){ctx.mozDash = null;}\ |
||
7469 | };\ |
||
7470 | var data_x = new Array();\ |
||
7471 | var data_y = new Array();\ |
||
7472 | var lb = line_name.length;\ |
||
7473 | var idx = 0;\ |
||
7474 | for( var p = 5 ; p < lb ; p = p + 2 ){\ |
||
7475 | data_x[idx] = x2px(line_name[p]);\ |
||
7476 | data_y[idx] = y2px(line_name[p+1]);\ |
||
7477 | idx++;\ |
||
7478 | };\ |
||
7479 | for( var p = 0; p < idx ; p++){\ |
||
7480 | ctx.beginPath();\ |
||
7481 | ctx.moveTo(data_x[p],data_y[p]);\ |
||
7482 | ctx.lineTo(data_x[p+1],data_y[p+1]);\ |
||
7483 | ctx.stroke();\ |
||
7484 | ctx.closePath();\ |
||
7485 | };\ |
||
7486 | i++;\ |
||
7487 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
||
7488 | };\ |
||
7489 | ctx.restore();\ |
||
7490 | };\ |
||
7614 | schaersvoo | 7491 | return;\ |
7989 | schaersvoo | 7492 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7493 | break; |
8224 | bpr | 7494 | |
7614 | schaersvoo | 7495 | case DRAW_PIECHART: |
7987 | schaersvoo | 7496 | fprintf(js_include_file,"\n<!-- draw piecharts -->\n\ |
7956 | schaersvoo | 7497 | function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\ |
7614 | schaersvoo | 7498 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
7499 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7500 | }\ |
||
7501 | else\ |
||
7502 | {\ |
||
7503 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7504 | };\ |
||
7505 | var ld = data_color_list.length;\ |
||
7506 | var sum = 0;\ |
||
7507 | var idx = 0;\ |
||
7956 | schaersvoo | 7508 | var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\ |
7614 | schaersvoo | 7509 | var colors = new Array();\ |
7510 | var data = new Array();\ |
||
7511 | for(var p = 0;p < ld; p = p + 2){\ |
||
7512 | data[idx] = parseFloat(data_color_list[p]);\ |
||
7513 | sum = sum + data[idx];\ |
||
7514 | colors[idx] = data_color_list[p+1];\ |
||
7515 | idx++;\ |
||
7516 | };\ |
||
7517 | var ctx = obj.getContext(\"2d\");\ |
||
7518 | ctx.save();\ |
||
7519 | var angle;\ |
||
7520 | var angle_end = 0;\ |
||
7521 | var offset = Math.PI / 2;\ |
||
7522 | ctx.globalAlpha = fill_opacity;\ |
||
7523 | for(var p=0; p < idx; p++){\ |
||
7524 | ctx.beginPath();\ |
||
7525 | ctx.fillStyle = colors[p];\ |
||
7526 | ctx.moveTo(x_center,y_center);\ |
||
7527 | angle = Math.PI * (2 * data[p] / sum);\ |
||
7528 | ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\ |
||
7529 | ctx.lineTo(x_center, y_center);\ |
||
7530 | ctx.fill();\ |
||
7531 | ctx.closePath();\ |
||
7532 | angle_end = angle_end + angle;\ |
||
7533 | };\ |
||
7956 | schaersvoo | 7534 | if(typeof legend0 !== 'undefined'){\ |
7535 | var legenda = eval(\"legend\"+legend_cnt);\ |
||
7614 | schaersvoo | 7536 | ctx.globalAlpha = 1.0;\ |
7956 | schaersvoo | 7537 | ctx.font = font_family;\ |
7614 | schaersvoo | 7538 | var y_offset = font_size; \ |
7539 | var x_offset = 0;\ |
||
7540 | var txt;var txt_size;\ |
||
7541 | for(var p = 0; p < idx; p++){\ |
||
7542 | ctx.fillStyle = colors[p];\ |
||
7956 | schaersvoo | 7543 | txt = legenda[p];\ |
7614 | schaersvoo | 7544 | txt_size = ctx.measureText(txt).width;\ |
7545 | if( x_center + radius + txt_size > xsize ){ x_offset = x_center + radius + txt_size - xsize;} else { x_offset = 0; };\ |
||
7956 | schaersvoo | 7546 | ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\ |
7614 | schaersvoo | 7547 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
7548 | };\ |
||
7549 | };\ |
||
7550 | ctx.restore();\ |
||
7956 | schaersvoo | 7551 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
8224 | bpr | 7552 | |
7614 | schaersvoo | 7553 | break; |
9433 | schaersvoo | 7554 | case DRAW_JSBOXPLOT: |
7555 | fprintf(js_include_file,"\n<!-- draw jsboxplots -->\n\ |
||
7556 | function statistics(data){\ |
||
7557 | var len = data.length;\ |
||
7558 | var min = 10000000;\ |
||
7559 | var max = -10000000;\ |
||
7560 | var sum = 0;var d;\ |
||
7561 | for(var i=0;i<len;i++){\ |
||
7562 | d = data[i];\ |
||
7563 | if(d < min){min = d;}else{if(d > max){max = d;};};\ |
||
7564 | sum+= parseFloat(data[i]);\ |
||
7565 | };\ |
||
7566 | var mean = parseFloat(sum/len);\ |
||
7567 | var variance = 0;\ |
||
7568 | for(var i=0;i<len;i++){\ |
||
7569 | d = data[i];\ |
||
7570 | variance += (d - mean)*(d - mean);\ |
||
7571 | };\ |
||
7572 | variance = parseFloat(variance / len);\ |
||
7573 | var std = Math.sqrt(variance);\ |
||
7574 | data.sort(function(a,b){return a - b;});\ |
||
7575 | var median;var Q1;var Q3;\ |
||
7576 | var half = Math.floor(0.5*len);\ |
||
7577 | var q1 = Math.floor(0.25*len);\ |
||
7578 | var q3 = Math.floor(0.75*len);\ |
||
7579 | var half = Math.floor(0.5*len);\ |
||
7580 | if(len %%2 == 1){\ |
||
7581 | median = data[half];\ |
||
7582 | Q1 = data[q1];\ |
||
7583 | Q3 = data[q3];\ |
||
7584 | }\ |
||
7585 | else\ |
||
7586 | {\ |
||
7587 | median = (data[half - 1] + data[half] )/2;\ |
||
7588 | Q1 = (data[q1 - 1] + data[q1] )/2;\ |
||
7589 | Q3 = (data[q3 - 1] + data[q3] )/2;\ |
||
7590 | };\ |
||
7591 | return [min,Q1,median,Q3,max];\ |
||
7592 | };"); |
||
7593 | break; |
||
7594 | case DRAW_BOXPLOT: |
||
7595 | fprintf(js_include_file,"\n<!-- draw boxplots -->\n\ |
||
9465 | schaersvoo | 7596 | draw_boxplot = function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1){\ |
9433 | schaersvoo | 7597 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
7598 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7599 | }\ |
||
7600 | else\ |
||
7601 | {\ |
||
7602 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7603 | };\ |
||
7604 | var ctx = obj.getContext(\"2d\");\ |
||
7605 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7606 | ctx.save();\ |
||
7607 | ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 7608 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
9433 | schaersvoo | 7609 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7610 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
7611 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
7612 | var hh = 0.25*hw;\ |
||
9465 | schaersvoo | 7613 | switch(boxplot_source){\ |
7614 | case 1: if( typeof jsboxplot_data === 'undefined'){return;};data = statistics(jsboxplot_data);break;\ |
||
7615 | case 2: if( typeof student_boxplot_data === 'undefined'){return;};data = statistics(student_boxplot_data);break;\ |
||
7616 | case 3: if( typeof student_boxplot === 'undefined'){return;};data = student_boxplot;break;\ |
||
7617 | default: break;\ |
||
9433 | schaersvoo | 7618 | };\ |
7619 | var min,Q1,median,Q3,max;\ |
||
7620 | if(xy == 1 ){\ |
||
7621 | min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\ |
||
7622 | hh = Math.abs(y2px(hh) - y2px(ystart));\ |
||
7623 | hw = Math.abs(y2px(hw) - y2px(ystart));\ |
||
7624 | cxy = y2px(cxy);\ |
||
9465 | schaersvoo | 7625 | ctx.beginPath();\ |
9433 | schaersvoo | 7626 | ctx.moveTo(min,cxy);\ |
7627 | ctx.lineTo(Q1,cxy);\ |
||
7628 | ctx.moveTo(Q3,cxy);\ |
||
7629 | ctx.lineTo(max,cxy);\ |
||
7630 | ctx.moveTo(min,cxy+hh);\ |
||
7631 | ctx.lineTo(min,cxy-hh);\ |
||
7632 | ctx.moveTo(max,cxy+hh);\ |
||
7633 | ctx.lineTo(max,cxy-hh);\ |
||
9465 | schaersvoo | 7634 | ctx.closePath();\ |
7635 | ctx.stroke();\ |
||
7636 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7637 | ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\ |
9465 | schaersvoo | 7638 | ctx.closePath();\ |
7639 | if( use_filled == 1 ){\ |
||
7640 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\ |
||
7641 | ctx.fill();\ |
||
7642 | };\ |
||
7643 | ctx.stroke();\ |
||
7644 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7645 | ctx.rect(median,cxy-2*hh,Q3-median,hw);\ |
9465 | schaersvoo | 7646 | ctx.closePath();\ |
7647 | if( use_filled == 1 ){\ |
||
7648 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
7649 | ctx.fill();\ |
||
7650 | };\ |
||
7651 | ctx.stroke();\ |
||
9433 | schaersvoo | 7652 | }else{\ |
7653 | min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\ |
||
7654 | hh = Math.abs(x2px(hh) - x2px(xstart));\ |
||
7655 | hw = Math.abs(x2px(hw) - x2px(xstart));\ |
||
7656 | cxy = x2px(cxy);\ |
||
9465 | schaersvoo | 7657 | ctx.beginPath();\ |
9433 | schaersvoo | 7658 | ctx.moveTo(cxy,min);\ |
7659 | ctx.lineTo(cxy,Q1);\ |
||
7660 | ctx.moveTo(cxy,Q3);\ |
||
7661 | ctx.lineTo(cxy,max);\ |
||
7662 | ctx.moveTo(cxy + hh,min);\ |
||
7663 | ctx.lineTo(cxy - hh,min);\ |
||
7664 | ctx.moveTo(cxy + hh,max);\ |
||
7665 | ctx.lineTo(cxy - hh,max);\ |
||
9465 | schaersvoo | 7666 | ctx.closePath;\ |
7667 | ctx.stroke();\ |
||
7668 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7669 | ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\ |
9465 | schaersvoo | 7670 | ctx.closePath();\ |
7671 | if( use_filled == 1 ){\ |
||
7672 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\ |
||
7673 | ctx.fill();\ |
||
7674 | };\ |
||
7675 | ctx.stroke();\ |
||
7676 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7677 | ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\ |
9465 | schaersvoo | 7678 | ctx.closePath();\ |
7679 | if( use_filled == 1 ){\ |
||
7680 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
7681 | ctx.fill();\ |
||
7682 | };\ |
||
7683 | ctx.stroke();\ |
||
9433 | schaersvoo | 7684 | };\ |
7685 | ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id); |
||
7686 | break; |
||
7614 | schaersvoo | 7687 | case DRAW_ARCS: |
7688 | fprintf(js_include_file,"\n<!-- draw arcs -->\n\ |
||
8105 | schaersvoo | 7689 | var draw_arc = function(ctx,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7690 | ctx.save();\ |
7691 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
8071 | schaersvoo | 7692 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 7693 | if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
7694 | if(end < start){var tmp = end;end = start;start=tmp;};\ |
||
8071 | schaersvoo | 7695 | start = 360 - start;\ |
7696 | end = 360 - end;\ |
||
7614 | schaersvoo | 7697 | ctx.lineWidth = line_width;\ |
9465 | schaersvoo | 7698 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7699 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
8071 | schaersvoo | 7700 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
7701 | ctx.beginPath();\ |
||
7702 | ctx.moveTo(xc,yc);\ |
||
7703 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
7704 | ctx.lineTo(xc,yc);\ |
||
7705 | ctx.closePath();\ |
||
7614 | schaersvoo | 7706 | if( use_filled == 1 ){\ |
7707 | ctx.fill();\ |
||
8071 | schaersvoo | 7708 | };\ |
7709 | ctx.stroke();\ |
||
7614 | schaersvoo | 7710 | ctx.restore();\ |
8071 | schaersvoo | 7711 | };"); |
8224 | bpr | 7712 | |
7614 | schaersvoo | 7713 | break; |
7983 | schaersvoo | 7714 | case DRAW_CENTERSTRING: |
7715 | fprintf(js_include_file,"\n<!-- draw centerstring -->\n\ |
||
8105 | schaersvoo | 7716 | var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\ |
7983 | schaersvoo | 7717 | var obj;\ |
7718 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7719 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7720 | }\ |
||
7721 | else\ |
||
7722 | {\ |
||
7723 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7724 | };\ |
||
7725 | var ctx = obj.getContext(\"2d\");\ |
||
7726 | ctx.save();\ |
||
9481 | schaersvoo | 7727 | ctx.clearRect(0,0,xsize,ysize);\ |
7983 | schaersvoo | 7728 | ctx.font = font_family;\ |
7729 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7730 | var stringwidth = ctx.measureText(text).width;\ |
||
7731 | var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\ |
||
7732 | ctx.fillText(text,x,y2px(y));\ |
||
9481 | schaersvoo | 7733 | ctx.restore();\ |
7983 | schaersvoo | 7734 | return;\ |
7735 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
||
7736 | break; |
||
7614 | schaersvoo | 7737 | case DRAW_TEXTS: |
7738 | fprintf(js_include_file,"\n<!-- draw text -->\n\ |
||
8105 | schaersvoo | 7739 | var draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7740 | var obj;\ |
7741 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7742 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7743 | }\ |
||
7744 | else\ |
||
7745 | {\ |
||
7746 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7747 | };\ |
||
7748 | var ctx = obj.getContext(\"2d\");\ |
||
9868 | schaersvoo | 7749 | if( font_family != 'null' ){\ |
7750 | ctx.font = font_family;\ |
||
7751 | }\ |
||
7752 | else\ |
||
7753 | {\ |
||
7754 | ctx.font = font_size+'px Ariel';\ |
||
7755 | };\ |
||
7614 | schaersvoo | 7756 | if(angle2 == 0 && angle != 0){\ |
7757 | ctx.save();\ |
||
8071 | schaersvoo | 7758 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7759 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7760 | };\ |
||
7761 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7762 | if(angle2 != 0){\ |
||
7763 | ctx.save();\ |
||
7764 | ctx.translate(x,y);\ |
||
7765 | ctx.rotate((360-angle2)*(Math.PI / 180));\ |
||
7766 | ctx.fillText(text,0,0);\ |
||
7767 | ctx.restore();\ |
||
7768 | }else{ctx.fillText(text,x,y);};\ |
||
7769 | ctx.restore();\ |
||
7770 | return;\ |
||
7653 | schaersvoo | 7771 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7772 | break; |
7773 | case DRAW_CURVE: |
||
7774 | fprintf(js_include_file,"\n<!-- draw curve -->\n\ |
||
8105 | schaersvoo | 7775 | var draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7776 | var obj;\ |
7777 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7778 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7779 | }\ |
||
7780 | else\ |
||
7781 | {\ |
||
7782 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7783 | };\ |
||
7784 | var ctx = obj.getContext(\"2d\");\ |
||
7785 | ctx.save();\ |
||
8071 | schaersvoo | 7786 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7787 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7788 | ctx.beginPath();ctx.lineWidth = line_width;\ |
||
9465 | schaersvoo | 7789 | if(line_width%%2 == 1 && typeof zoom_x_increment === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7790 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7791 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7792 | ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\ |
||
7793 | for(var p = 1 ; p < x_points.length ; p++){\ |
||
7794 | if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\ |
||
7795 | ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
7796 | }\ |
||
7797 | else\ |
||
7798 | {\ |
||
7799 | ctx.stroke();\ |
||
7800 | ctx.beginPath();\ |
||
7801 | p++;\ |
||
7802 | ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
7803 | };\ |
||
7804 | };\ |
||
7805 | ctx.stroke();\ |
||
7806 | ctx.restore();\ |
||
7653 | schaersvoo | 7807 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7808 | break; |
8224 | bpr | 7809 | |
7614 | schaersvoo | 7810 | case DRAW_INPUTS: |
7811 | fprintf(js_include_file,"\n<!-- draw input fields -->\n\ |
||
8105 | schaersvoo | 7812 | var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\ |
7614 | schaersvoo | 7813 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
7814 | var input = document.createElement(\"input\");\ |
||
7815 | input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
7816 | input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
7817 | input.setAttribute(\"size\",size);\ |
||
7818 | input.setAttribute(\"value\",value);\ |
||
7877 | schaersvoo | 7819 | if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\ |
7653 | schaersvoo | 7820 | canvas_div.appendChild(input);};"); |
7614 | schaersvoo | 7821 | break; |
8224 | bpr | 7822 | |
7614 | schaersvoo | 7823 | case DRAW_TEXTAREAS: |
7824 | fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\ |
||
8105 | schaersvoo | 7825 | var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\ |
7614 | schaersvoo | 7826 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
7827 | var textarea = document.createElement(\"textarea\");\ |
||
7828 | textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
7829 | textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
7830 | textarea.setAttribute(\"cols\",cols);\ |
||
7831 | textarea.setAttribute(\"rows\",rows);\ |
||
7877 | schaersvoo | 7832 | textarea.value = value;\ |
7833 | if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\ |
||
7653 | schaersvoo | 7834 | canvas_div.appendChild(textarea);};"); |
7614 | schaersvoo | 7835 | break; |
8224 | bpr | 7836 | |
7614 | schaersvoo | 7837 | case DRAW_PIXELS: |
7838 | fprintf(js_include_file,"\n<!-- draw pixel -->\n\ |
||
8105 | schaersvoo | 7839 | var draw_setpixel = function(x,y,color,opacity,pixelsize){\ |
7614 | schaersvoo | 7840 | var canvas = create_canvas%d(10,xsize,ysize);\ |
7841 | var d = 0.5*pixelsize;\ |
||
7842 | var ctx = canvas.getContext(\"2d\");\ |
||
9462 | schaersvoo | 7843 | if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\ |
7614 | schaersvoo | 7844 | ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
7845 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7846 | for(var p=0; p<x.length;p++){\ |
||
7847 | ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\ |
||
7848 | };\ |
||
7849 | ctx.fill();ctx.stroke();\ |
||
7850 | };",canvas_root_id); |
||
7851 | break; |
||
7852 | |||
7853 | case DRAW_CLOCK: |
||
7854 | fprintf(js_include_file,"\n<!-- begin command clock -->\n\ |
||
7855 | var clock_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
7856 | var clock_ctx = clock_canvas.getContext(\"2d\");\ |
||
7857 | var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\ |
||
8130 | schaersvoo | 7858 | clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\ |
7614 | schaersvoo | 7859 | clock_ctx.save();\ |
7997 | schaersvoo | 7860 | clock_ctx.globalAlpha = clock_bg_opacity;\ |
7614 | schaersvoo | 7861 | this.type = type || 0;\ |
7862 | this.interaction = interaction || 0;\ |
||
7862 | schaersvoo | 7863 | this.H = H;\ |
7864 | this.M = M;\ |
||
7865 | this.S = S;\ |
||
7614 | schaersvoo | 7866 | this.xc = xc || xsize/2;\ |
7867 | this.yc = yc || ysize/2;\ |
||
7868 | this.radius = radius || xsize/4;\ |
||
7869 | var font_size = parseInt(0.2*this.radius);\ |
||
7870 | this.H_color = h_color || \"blue\";\ |
||
7871 | this.M_color = m_color || \"blue\";\ |
||
7872 | this.S_color = s_color || \"blue\";\ |
||
7873 | this.fg_color = fg_color || \"red\";\ |
||
7874 | this.bg_color = bg_color || \"white\";\ |
||
7875 | clock_ctx.translate(this.xc,this.yc);\ |
||
7876 | clock_ctx.beginPath();\ |
||
7877 | clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\ |
||
7878 | clock_ctx.fillStyle = this.bg_color;\ |
||
7879 | clock_ctx.fill();\ |
||
7880 | clock_ctx.closePath();\ |
||
7881 | clock_ctx.beginPath();\ |
||
7882 | clock_ctx.font = font_size+\"px Arial\";\ |
||
7883 | clock_ctx.fillStyle = this.fg_color;\ |
||
7884 | clock_ctx.textAlign = \"center\";\ |
||
7885 | clock_ctx.textBaseline = 'middle';\ |
||
7886 | var angle;var x1,y1,x2,y2;\ |
||
7887 | var angle_cos;var angle_sin;\ |
||
7997 | schaersvoo | 7888 | clock_ctx.globalAlpha = clock_fg_opacity;\ |
7614 | schaersvoo | 7889 | switch(type){\ |
7890 | case 0:clock_ctx.beginPath();\ |
||
7891 | for(var p = 1; p <= 12 ; p++){\ |
||
7892 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
7893 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
7894 | x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
7895 | clock_ctx.moveTo(x1,y1);\ |
||
7896 | clock_ctx.lineTo(x2,y2);\ |
||
7897 | };\ |
||
7898 | for(var p = 1; p <= 60 ; p++){\ |
||
7899 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
7900 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
7901 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
7902 | clock_ctx.moveTo(x1,y1);\ |
||
7903 | clock_ctx.lineTo(x2,y2);\ |
||
7904 | };\ |
||
7905 | clock_ctx.closePath();\ |
||
7906 | clock_ctx.stroke();\ |
||
7907 | break;\ |
||
7908 | case 1:\ |
||
7909 | for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.9*this.radius*Math.cos(angle);y1 = 0.9*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};break;\ |
||
7862 | schaersvoo | 7910 | case 2:\ |
7911 | for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.8*this.radius*Math.cos(angle);y1 = 0.8*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\ |
||
7614 | schaersvoo | 7912 | clock_ctx.beginPath();\ |
7913 | for(var p = 1; p <= 12 ; p++){\ |
||
7914 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
7915 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
7916 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
7917 | clock_ctx.moveTo(x1,y1);\ |
||
7918 | clock_ctx.lineTo(x2,y2);\ |
||
7919 | };\ |
||
7920 | for(var p = 1; p <= 60 ; p++){\ |
||
7921 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
7922 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
7923 | x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
7924 | clock_ctx.moveTo(x1,y1);\ |
||
7925 | clock_ctx.lineTo(x2,y2);\ |
||
7926 | };\ |
||
7927 | clock_ctx.closePath();\ |
||
7928 | clock_ctx.stroke();\ |
||
7929 | break;\ |
||
7930 | };\ |
||
7931 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
||
7932 | clock_ctx.rotate(angle);\ |
||
7933 | clock_ctx.beginPath();\ |
||
7934 | clock_ctx.moveTo(-3, -2);\ |
||
7935 | clock_ctx.lineTo(-3, 2);\ |
||
7936 | clock_ctx.lineTo(this.radius * 0.7, 1);\ |
||
7937 | clock_ctx.lineTo(this.radius * 0.7, -1);\ |
||
7938 | clock_ctx.fillStyle = this.H_color;\ |
||
7939 | clock_ctx.fill();\ |
||
7940 | clock_ctx.rotate(-angle);\ |
||
7941 | angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\ |
||
7942 | clock_ctx.rotate(angle);\ |
||
7943 | clock_ctx.beginPath();\ |
||
7944 | clock_ctx.moveTo(-3, -2);\ |
||
7945 | clock_ctx.lineTo(-3, 2);\ |
||
7946 | clock_ctx.lineTo(this.radius * 0.8, 1);\ |
||
7947 | clock_ctx.lineTo(this.radius * 0.8, -1);\ |
||
7948 | clock_ctx.fillStyle = this.M_color;\ |
||
7949 | clock_ctx.fill();\ |
||
7950 | clock_ctx.rotate(-angle);\ |
||
7951 | angle = (this.S - 15) * 2 * Math.PI / 60;\ |
||
7952 | clock_ctx.rotate(angle);\ |
||
7953 | clock_ctx.beginPath();\ |
||
7954 | clock_ctx.moveTo(0,0);\ |
||
7955 | clock_ctx.lineTo(this.radius * 0.95, 0);\ |
||
7956 | clock_ctx.lineTo(this.radius * 0.9, -1);\ |
||
7957 | clock_ctx.strokeStyle = this.S_color;\ |
||
7958 | clock_ctx.stroke();\ |
||
7959 | clock_ctx.restore();\ |
||
7653 | schaersvoo | 7960 | };",canvas_root_id,CLOCK_CANVAS); |
7614 | schaersvoo | 7961 | break; |
7962 | |||
7963 | case DRAW_LATTICE: |
||
7964 | fprintf(js_include_file,"\n<!-- draw lattice -->\n\ |
||
8105 | schaersvoo | 7965 | var draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7966 | var obj;\ |
7967 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7968 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7969 | }\ |
||
7970 | else\ |
||
7971 | {\ |
||
7972 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7973 | };\ |
||
7974 | var ctx = obj.getContext(\"2d\");\ |
||
7975 | ctx.save();\ |
||
8071 | schaersvoo | 7976 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7977 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7978 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7979 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7980 | var radius = line_width;\ |
||
7981 | var x = 0;\ |
||
7982 | var y = 0;\ |
||
7983 | var x_step_px = xsize/(xmax-xmin);\ |
||
7984 | var y_step_px = ysize/(ymax-ymin);\ |
||
7985 | var xv1 = dx1*x_step_px;\ |
||
7986 | var yv1 = dy1*y_step_px;\ |
||
7987 | var xv2 = dx2*x_step_px;\ |
||
7988 | var yv2 = dy2*y_step_px;\ |
||
7989 | for(var p = 0; p < n1 ;p++){\ |
||
7990 | x = p*xv1 + x0;\ |
||
7991 | y = p*yv1 + y0;\ |
||
7992 | for(var c = 0; c < n2 ; c++){\ |
||
7993 | ctx.beginPath();\ |
||
7994 | ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\ |
||
7995 | ctx.fill();\ |
||
7996 | ctx.stroke();\ |
||
7997 | ctx.closePath();\ |
||
7998 | };\ |
||
7999 | };\ |
||
8000 | ctx.restore();\ |
||
8001 | return;\ |
||
7653 | schaersvoo | 8002 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8003 | break; |
7735 | schaersvoo | 8004 | case DRAW_XYLOGSCALE: |
8005 | fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\ |
||
8105 | schaersvoo | 8006 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,precision){\ |
7956 | schaersvoo | 8007 | var obj;\ |
8008 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8009 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8010 | }\ |
||
8011 | else\ |
||
8012 | {\ |
||
8013 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8014 | };\ |
||
8015 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 8016 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 8017 | ctx.save();\ |
7739 | schaersvoo | 8018 | var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\ |
7956 | schaersvoo | 8019 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
8020 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
8021 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
||
8022 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
7739 | schaersvoo | 8023 | if(use_axis_numbering == 1){\ |
7956 | schaersvoo | 8024 | ctx.font = font_family;\ |
8025 | xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\ |
||
8026 | ymarge = parseInt(1.5*font_size);\ |
||
8027 | ctx.save();\ |
||
8028 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
8029 | ctx.rect(0,0,xmarge,ysize);\ |
||
8030 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
8031 | ctx.fill();\ |
||
8032 | ctx.restore();\ |
||
8033 | }else{xmarge = 0;ymarge = 0;};\ |
||
7735 | schaersvoo | 8034 | if( typeof xaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 8035 | ctx.save();\ |
8036 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8037 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8038 | corr = ctx.measureText(xaxislabel).width;\ |
||
8039 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
8040 | ctx.restore();\ |
||
8041 | };\ |
||
7735 | schaersvoo | 8042 | if( typeof yaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 8043 | ctx.save();\ |
8044 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8045 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8046 | corr = ctx.measureText(yaxislabel).width;\ |
||
8047 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
8048 | ctx.rotate(-0.5*Math.PI);\ |
||
8049 | ctx.fillText(yaxislabel,0,0);\ |
||
8050 | ctx.restore();\ |
||
8051 | };\ |
||
8052 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8053 | ctx.lineWidth = line_width;\ |
||
8054 | for(var p = x_min; p <= x_max ; p++){\ |
||
8055 | num = Math.pow(xlogbase,p);\ |
||
8056 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
8057 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 8058 | if( i == 1 ){\ |
7956 | schaersvoo | 8059 | ctx.lineWidth = line_width;\ |
8060 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
7738 | schaersvoo | 8061 | if( use_axis_numbering == 1 && p > x_min){\ |
7956 | schaersvoo | 8062 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
8063 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
8064 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
8065 | };\ |
||
7735 | schaersvoo | 8066 | }else{\ |
7956 | schaersvoo | 8067 | ctx.lineWidth = 0.2*line_width;\ |
8068 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
8069 | };\ |
||
7738 | schaersvoo | 8070 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 8071 | ctx.beginPath();\ |
8072 | ctx.moveTo(x_e,0);\ |
||
8073 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
8074 | ctx.stroke();\ |
||
8075 | ctx.closePath();\ |
||
7738 | schaersvoo | 8076 | };\ |
7956 | schaersvoo | 8077 | };\ |
8078 | };\ |
||
8079 | for(var p = y_min; p <= y_max ; p++){\ |
||
8080 | num = Math.pow(ylogbase,p);\ |
||
8081 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
8082 | y_e = y2px(i*num);\ |
||
8083 | if( i == 1 ){\ |
||
8084 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 8085 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 8086 | if( use_axis_numbering == 1 && p > y_min){\ |
8087 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
||
8088 | };\ |
||
8089 | }else{\ |
||
8090 | ctx.lineWidth = 0.2*line_width;\ |
||
8091 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
8092 | };\ |
||
8093 | ctx.beginPath();\ |
||
8094 | ctx.moveTo(xmarge,y_e);\ |
||
8095 | ctx.lineTo(xsize,y_e);\ |
||
8096 | ctx.stroke();\ |
||
8097 | ctx.closePath();\ |
||
8098 | };\ |
||
8099 | };\ |
||
7735 | schaersvoo | 8100 | ctx.restore();\ |
8101 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
8102 | break; |
||
7614 | schaersvoo | 8103 | |
7735 | schaersvoo | 8104 | case DRAW_XLOGSCALE: |
8105 | fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\ |
||
8105 | schaersvoo | 8106 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\ |
7956 | schaersvoo | 8107 | var obj;\ |
8108 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8109 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8110 | }\ |
||
8111 | else\ |
||
8112 | {\ |
||
8113 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8114 | };\ |
||
8115 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 8116 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 8117 | ctx.save();\ |
8118 | ctx.lineWidth = line_width;\ |
||
7739 | schaersvoo | 8119 | var prec = Math.log(precision)/Math.log(10);\ |
7735 | schaersvoo | 8120 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
8121 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
8122 | var y_min = 0;var y_max = ysize;var x_e;var corr;\ |
||
7739 | schaersvoo | 8123 | var xtxt;var ytxt;var num;var xmarge;var ymarge;\ |
8124 | if(use_axis_numbering == 1){\ |
||
7956 | schaersvoo | 8125 | ctx.font = font_family;\ |
8126 | xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\ |
||
8127 | ymarge = parseInt(1.5*font_size);\ |
||
8128 | ctx.save();\ |
||
8129 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
8130 | ctx.rect(0,0,xmarge,ysize);\ |
||
8131 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
8132 | ctx.fill();\ |
||
8133 | ctx.restore();\ |
||
8134 | }else{xmarge = 0;ymarge = 0;};\ |
||
7739 | schaersvoo | 8135 | if( typeof xaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 8136 | ctx.save();\ |
8137 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8138 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8139 | corr = ctx.measureText(xaxislabel).width;\ |
||
8140 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
8141 | ctx.restore();\ |
||
8142 | };\ |
||
7739 | schaersvoo | 8143 | if( typeof yaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 8144 | ctx.save();\ |
8145 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8146 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8147 | corr = ctx.measureText(yaxislabel).width;\ |
||
8148 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
8149 | ctx.rotate(-0.5*Math.PI);\ |
||
8150 | ctx.fillText(yaxislabel,0,0);\ |
||
8151 | ctx.restore();\ |
||
8152 | };\ |
||
8153 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8154 | ctx.lineWidth = line_width;\ |
||
8155 | for(var p = x_min; p <= x_max ; p++){\ |
||
8156 | num = Math.pow(xlogbase,p);\ |
||
8157 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
8158 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 8159 | if( i == 1 ){\ |
7956 | schaersvoo | 8160 | ctx.lineWidth = line_width;\ |
7739 | schaersvoo | 8161 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
8162 | if( use_axis_numbering == 1 && p > x_min ){\ |
||
7735 | schaersvoo | 8163 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
8164 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
8165 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
8166 | };\ |
||
8167 | }else{\ |
||
7956 | schaersvoo | 8168 | ctx.lineWidth = 0.2*line_width;\ |
7735 | schaersvoo | 8169 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
8170 | };\ |
||
7739 | schaersvoo | 8171 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 8172 | ctx.beginPath();\ |
8173 | ctx.moveTo(x_e,0);\ |
||
8174 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
8175 | ctx.stroke();\ |
||
8176 | ctx.closePath();\ |
||
7739 | schaersvoo | 8177 | };\ |
8178 | };\ |
||
7956 | schaersvoo | 8179 | };\ |
7735 | schaersvoo | 8180 | var stepy = Math.abs(y2px(ymajor) - y2px(0));\ |
8181 | var minor_step = stepy / yminor;\ |
||
7749 | schaersvoo | 8182 | for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\ |
7735 | schaersvoo | 8183 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 8184 | ctx.lineWidth = line_width;\ |
8185 | ctx.beginPath();\ |
||
8186 | ctx.moveTo(xmarge,y);\ |
||
8187 | ctx.lineTo(xsize,y);\ |
||
8188 | ctx.stroke();\ |
||
8189 | ctx.closePath();\ |
||
7735 | schaersvoo | 8190 | if( use_axis_numbering == 1){\ |
8191 | ytxt = (px2y(y)).toFixed(prec);\ |
||
8192 | ctx.fillText( ytxt,0 ,y + 0.5*font_size );\ |
||
8193 | };\ |
||
8194 | for(var dy = 1 ; dy < yminor ; dy++){\ |
||
8195 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 8196 | ctx.lineWidth = 0.2*line_width;\ |
8197 | ctx.beginPath();\ |
||
7739 | schaersvoo | 8198 | ctx.moveTo(xmarge,y+dy*minor_step);\ |
7956 | schaersvoo | 8199 | ctx.lineTo(xsize,y+dy*minor_step);\ |
8200 | ctx.stroke();\ |
||
8201 | ctx.closePath();\ |
||
7735 | schaersvoo | 8202 | };\ |
8203 | };\ |
||
7956 | schaersvoo | 8204 | ctx.restore();\ |
8205 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7735 | schaersvoo | 8206 | break; |
7729 | schaersvoo | 8207 | case DRAW_YLOGSCALE: |
8208 | fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\ |
||
8105 | schaersvoo | 8209 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,xmajor,xminor,precision){\ |
7956 | schaersvoo | 8210 | var obj;\ |
8211 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8212 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8213 | }\ |
||
8214 | else\ |
||
8215 | {\ |
||
8216 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8217 | };\ |
||
8218 | var ctx = obj.getContext(\"2d\");\ |
||
7729 | schaersvoo | 8219 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 8220 | ctx.save();\ |
8221 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 8222 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
8223 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
8109 | schaersvoo | 8224 | var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\ |
7739 | schaersvoo | 8225 | if(use_axis_numbering == 1){\ |
7956 | schaersvoo | 8226 | ctx.font = font_family;\ |
8227 | xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\ |
||
8228 | ymarge = 2*font_size;\ |
||
8229 | ctx.save();\ |
||
8230 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
8231 | ctx.rect(0,0,xmarge,ysize);\ |
||
8232 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
8233 | ctx.fill();\ |
||
8234 | ctx.restore();\ |
||
8235 | }else{xmarge = 0;ymarge = 0;};\ |
||
7739 | schaersvoo | 8236 | if( typeof xaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 8237 | ctx.save();\ |
8238 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8239 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8240 | corr = ctx.measureText(xaxislabel).width;\ |
||
8241 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
8242 | ctx.restore();\ |
||
8243 | };\ |
||
7739 | schaersvoo | 8244 | if( typeof yaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 8245 | ctx.save();\ |
8246 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8247 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8248 | corr = ctx.measureText(yaxislabel).width;\ |
||
8249 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
8250 | ctx.rotate(-0.5*Math.PI);\ |
||
8251 | ctx.fillText(yaxislabel,0,0);\ |
||
8252 | ctx.restore();\ |
||
8253 | };\ |
||
8254 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8255 | ctx.lineWidth = line_width;\ |
||
8256 | for(var p = y_min; p <= y_max ; p++){\ |
||
8257 | num = Math.pow(ylogbase,p);\ |
||
8258 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
8259 | y_e = y2px(i*num);\ |
||
7729 | schaersvoo | 8260 | if( i == 1 ){\ |
7956 | schaersvoo | 8261 | ctx.lineWidth = line_width;\ |
7729 | schaersvoo | 8262 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7739 | schaersvoo | 8263 | if( use_axis_numbering == 1 && p > y_min){\ |
7735 | schaersvoo | 8264 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
7729 | schaersvoo | 8265 | };\ |
8266 | }else{\ |
||
7956 | schaersvoo | 8267 | ctx.lineWidth = 0.2*line_width;\ |
7729 | schaersvoo | 8268 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
8269 | };\ |
||
7956 | schaersvoo | 8270 | ctx.beginPath();\ |
8271 | ctx.moveTo(xmarge,y_e);\ |
||
8272 | ctx.lineTo(xsize,y_e);\ |
||
8273 | ctx.stroke();\ |
||
8274 | ctx.closePath();\ |
||
8275 | };\ |
||
8276 | };\ |
||
7729 | schaersvoo | 8277 | var stepx = Math.abs(x2px(xmajor) - x2px(0));\ |
8278 | var minor_step = stepx / xminor;\ |
||
8279 | var prec = Math.log(precision)/Math.log(10);\ |
||
8280 | var xtxt;var corr;var flip = 0;\ |
||
7749 | schaersvoo | 8281 | for(var x = stepx ; x < xsize ; x = x + stepx){\ |
7729 | schaersvoo | 8282 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 8283 | ctx.lineWidth = line_width;\ |
8284 | ctx.beginPath();\ |
||
8285 | ctx.moveTo(x,ysize-ymarge);\ |
||
8286 | ctx.lineTo(x,0);\ |
||
8287 | ctx.stroke();\ |
||
8288 | ctx.closePath();\ |
||
7729 | schaersvoo | 8289 | if( use_axis_numbering == 1){\ |
8290 | xtxt = (px2x(x)).toFixed(prec);\ |
||
8291 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
8292 | if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\ |
||
8293 | flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\ |
||
8294 | };\ |
||
8295 | for(var dx = 1 ; dx < xminor ; dx++){\ |
||
8296 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 8297 | ctx.lineWidth = 0.2*line_width;\ |
8298 | ctx.beginPath();\ |
||
7739 | schaersvoo | 8299 | ctx.moveTo(x+dx*minor_step,ysize - ymarge);\ |
7956 | schaersvoo | 8300 | ctx.lineTo(x+dx*minor_step,0);\ |
8301 | ctx.stroke();\ |
||
8302 | ctx.closePath();\ |
||
7735 | schaersvoo | 8303 | };\ |
8304 | };\ |
||
7956 | schaersvoo | 8305 | ctx.restore();\ |
8306 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7729 | schaersvoo | 8307 | break; |
9213 | schaersvoo | 8308 | |
7614 | schaersvoo | 8309 | default:break; |
8310 | } |
||
8311 | } |
||
8312 | } |
||
8313 | return; |
||
8314 | } |
||
8315 | |||
8316 | void check_string_length(int L){ |
||
9466 | schaersvoo | 8317 | if( L > MAX_BUFFER-1){ |
7614 | schaersvoo | 8318 | canvas_error("problem with your arguments to command..."); |
8319 | } |
||
8320 | return; |
||
8321 | } |
||
8322 | |||
8323 | |||
8324 | int get_token(FILE *infile){ |
||
8325 | int c,i=0; |
||
8326 | char temp[MAX_INT], *input_type; |
||
8327 | char *line="line", |
||
8328 | *audio="audio", |
||
8329 | *blink="blink", |
||
8330 | *arrowhead="arrowhead", |
||
8331 | *crosshairsize="crosshairsize", |
||
8332 | *crosshair="crosshair", |
||
8333 | *crosshairs="crosshairs", |
||
8334 | *audioobject="audioobject", |
||
8335 | *style="style", |
||
8336 | *mouse="mouse", |
||
7991 | schaersvoo | 8337 | *mousex="mousex", |
8338 | *mousey="mousey", |
||
8071 | schaersvoo | 8339 | *mouse_display="display", |
8340 | *mouse_degree="mouse_degree", |
||
7614 | schaersvoo | 8341 | *userdraw="userdraw", |
8342 | *highlight="highlight", |
||
8343 | *http="http", |
||
8344 | *rays="rays", |
||
8345 | *dashtype="dashtype", |
||
8346 | *dashed="dashed", |
||
8347 | *filled="filled", |
||
8348 | *lattice="lattice", |
||
8349 | *parallel="parallel", |
||
8350 | *segment="segment", |
||
8299 | schaersvoo | 8351 | *segments="segments", |
7614 | schaersvoo | 8352 | *dsegment="dsegment", |
9374 | schaersvoo | 8353 | *dsegments="dsegments", |
7614 | schaersvoo | 8354 | *seg="seg", |
9383 | schaersvoo | 8355 | *segs="segs", |
7614 | schaersvoo | 8356 | *bgimage="bgimage", |
8357 | *bgcolor="bgcolor", |
||
8358 | *strokecolor="strokecolor", |
||
8359 | *backgroundimage="backgroundimage", |
||
8360 | *text="text", |
||
8361 | *textup="textup", |
||
8362 | *mouseprecision="mouseprecision", |
||
8363 | *precision="precision", |
||
8364 | *plotsteps="plotsteps", |
||
8365 | *plotstep="plotstep", |
||
8366 | *tsteps="tsteps", |
||
8367 | *curve="curve", |
||
8368 | *dcurve="dcurve", |
||
8369 | *plot="plot", |
||
8370 | *dplot="dplot", |
||
7788 | schaersvoo | 8371 | *levelcurve="levelcurve", |
7614 | schaersvoo | 8372 | *fontsize="fontsize", |
8373 | *fontcolor="fontcolor", |
||
8374 | *axis="axis", |
||
8375 | *axisnumbering="axisnumbering", |
||
8376 | *axisnumbers="axisnumbers", |
||
8377 | *arrow="arrow", |
||
9382 | schaersvoo | 8378 | *vector="vector", |
8379 | *vectors="vectors", |
||
7614 | schaersvoo | 8380 | *darrow="darrow", |
8381 | *arrow2="arrow2", |
||
8382 | *darrow2="darrow2", |
||
8304 | schaersvoo | 8383 | *arrows="arrows", |
8347 | schaersvoo | 8384 | *arrows2="arrows2", |
7614 | schaersvoo | 8385 | *zoom="zoom", |
8386 | *grid="grid", |
||
8387 | *hline="hline", |
||
7786 | schaersvoo | 8388 | *dhline="dhline", |
7614 | schaersvoo | 8389 | *drag="drag", |
8390 | *horizontalline="horizontalline", |
||
9383 | schaersvoo | 8391 | *horizontallines="horizontallines", |
7614 | schaersvoo | 8392 | *vline="vline", |
7786 | schaersvoo | 8393 | *dvline="dvline", |
7614 | schaersvoo | 8394 | *verticalline="verticalline", |
9383 | schaersvoo | 8395 | *verticallines="verticallines", |
7614 | schaersvoo | 8396 | *triangle="triangle", |
9306 | schaersvoo | 8397 | *triangles="triangles", |
7614 | schaersvoo | 8398 | *ftriangle="ftriangle", |
9374 | schaersvoo | 8399 | *ftriangles="ftriangles", |
7614 | schaersvoo | 8400 | *mathml="mathml", |
8401 | *html="html", |
||
8402 | *input="input", |
||
8146 | schaersvoo | 8403 | *clearbutton="clearbutton", |
9386 | schaersvoo | 8404 | *erase="erase", |
8405 | *delete="delete", |
||
7614 | schaersvoo | 8406 | *inputstyle="inputstyle", |
8407 | *textarea="textarea", |
||
8408 | *trange="trange", |
||
8409 | *ranget="ranget", |
||
8410 | *xrange="xrange", |
||
8411 | *yrange="yrange", |
||
8412 | *rangex="rangex", |
||
8413 | *rangey="rangey", |
||
8370 | schaersvoo | 8414 | *path="path", |
7614 | schaersvoo | 8415 | *polyline="polyline", |
8351 | schaersvoo | 8416 | *brokenline="brokenline", |
7614 | schaersvoo | 8417 | *lines="lines", |
8418 | *poly="poly", |
||
8419 | *polygon="polygon", |
||
8420 | *fpolygon="fpolygon", |
||
8421 | *fpoly="fpoly", |
||
8422 | *filledpoly="filledpoly", |
||
8423 | *filledpolygon="filledpolygon", |
||
8424 | *rect="rect", |
||
8425 | *frect="frect", |
||
8426 | *rectangle="rectangle", |
||
8427 | *frectangle="frectangle", |
||
8428 | *square="square", |
||
8429 | *fsquare="fsquare", |
||
9374 | schaersvoo | 8430 | *fsquares="fsquares", |
8363 | schaersvoo | 8431 | *rects="rects", |
8432 | *frects="frects", |
||
7614 | schaersvoo | 8433 | *dline="dline", |
8434 | *arc="arc", |
||
8435 | *filledarc="filledarc", |
||
9374 | schaersvoo | 8436 | *farc="farc", |
7614 | schaersvoo | 8437 | *size="size", |
8438 | *string="string", |
||
8439 | *stringup="stringup", |
||
8440 | *copy="copy", |
||
8441 | *copyresized="copyresized", |
||
8442 | *opacity="opacity", |
||
8443 | *transparent="transparent", |
||
8444 | *fill="fill", |
||
8445 | *point="point", |
||
8446 | *points="points", |
||
8447 | *linewidth="linewidth", |
||
8448 | *circle="circle", |
||
8304 | schaersvoo | 8449 | *circles="circles", |
7614 | schaersvoo | 8450 | *fcircle="fcircle", |
9374 | schaersvoo | 8451 | *fcircles="fcircles", |
7614 | schaersvoo | 8452 | *disk="disk", |
9374 | schaersvoo | 8453 | *disks="disks", |
7614 | schaersvoo | 8454 | *comment="#", |
8455 | *end="end", |
||
8456 | *ellipse="ellipse", |
||
8457 | *fellipse="fellipse", |
||
8458 | *rotate="rotate", |
||
7785 | schaersvoo | 8459 | *affine="affine", |
9907 | schaersvoo | 8460 | *rotationcenter="rotationcenter", |
8461 | *killrotate="killrotate", |
||
7785 | schaersvoo | 8462 | *killaffine="killaffine", |
7614 | schaersvoo | 8463 | *fontfamily="fontfamily", |
8464 | *fillcolor="fillcolor", |
||
8465 | *clicktile="clicktile", |
||
8466 | *clicktile_colors="clicktile_colors", |
||
8467 | *translation="translation", |
||
8468 | *translate="translate", |
||
8469 | *killtranslation="killtranslation", |
||
8470 | *killtranslate="killtranslate", |
||
8471 | *onclick="onclick", |
||
8370 | schaersvoo | 8472 | *roundrects="roundrects", |
7614 | schaersvoo | 8473 | *roundrect="roundrect", |
8474 | *froundrect="froundrect", |
||
9374 | schaersvoo | 8475 | *froundrects="froundrects", |
7614 | schaersvoo | 8476 | *roundrectangle="roundrectangle", |
8477 | *patternfill="patternfill", |
||
8478 | *hatchfill="hatchfill", |
||
8479 | *diafill="diafill", |
||
7647 | schaersvoo | 8480 | *diamondfill="diamondfill", |
7614 | schaersvoo | 8481 | *dotfill="dotfill", |
8482 | *gridfill="gridfill", |
||
8483 | *imagefill="imagefill", |
||
7735 | schaersvoo | 8484 | *xlogbase="xlogbase", |
8485 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 8486 | *xlogscale="xlogscale", |
8487 | *ylogscale="ylogscale", |
||
8488 | *xylogscale="xylogscale", |
||
8489 | *intooltip="intooltip", |
||
9329 | schaersvoo | 8490 | *popup="popup", |
7614 | schaersvoo | 8491 | *replyformat="replyformat", |
8492 | *floodfill="floodfill", |
||
8493 | *filltoborder="filltoborder", |
||
8494 | *setpixel="setpixel", |
||
8495 | *pixels="pixels", |
||
8496 | *pixelsize="pixelsize", |
||
8497 | *xaxis="xaxis", |
||
9341 | schaersvoo | 8498 | *xaxisup="xaxisup", |
7614 | schaersvoo | 8499 | *yaxis="yaxis", |
8500 | *xaxistext="xaxistext", |
||
9341 | schaersvoo | 8501 | *xaxistextup="xaxistextup", |
7614 | schaersvoo | 8502 | *yaxistext="yaxistext", |
8503 | *piechart="piechart", |
||
9433 | schaersvoo | 8504 | *boxplot="boxplot", |
9465 | schaersvoo | 8505 | *boxplotdata="boxplotdata", |
8506 | *userboxplot="userboxplot", |
||
8507 | *userboxplotdata="userboxplotdata", |
||
7614 | schaersvoo | 8508 | *legend="legend", |
8509 | *legendcolors="legendcolors", |
||
8510 | *xlabel="xlabel", |
||
8511 | *ylabel="ylabel", |
||
8512 | *barchart="barchart", |
||
8513 | *linegraph="linegraph", |
||
8514 | *clock="clock", |
||
8515 | *animate="animate", |
||
8516 | *video="video", |
||
8517 | *status="status", |
||
7877 | schaersvoo | 8518 | *nostatus="nostatus", |
7652 | schaersvoo | 8519 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 8520 | *xsnaptogrid="xsnaptogrid", |
8521 | *ysnaptogrid="ysnaptogrid", |
||
8379 | schaersvoo | 8522 | *snaptopoints="snaptopoints", |
9213 | schaersvoo | 8523 | *snaptofunction="snaptofunction", |
8524 | *snaptofun="snaptofun", |
||
7654 | schaersvoo | 8525 | *userinput_xy="userinput_xy", |
8193 | schaersvoo | 8526 | *userinput_function="userinput_function", |
7663 | schaersvoo | 8527 | *usertextarea_xy="usertextarea_xy", |
8222 | schaersvoo | 8528 | *userinput="userinput", |
7823 | schaersvoo | 8529 | *jsmath="jsmath", |
7858 | schaersvoo | 8530 | *trace_jscurve="trace_jscurve", |
7838 | schaersvoo | 8531 | *setlimits="setlimits", |
7858 | schaersvoo | 8532 | *jscurve="jscurve", |
8533 | *jsplot="jsplot", |
||
7983 | schaersvoo | 8534 | *sgraph="sgraph", |
7984 | schaersvoo | 8535 | *title="title", |
7996 | schaersvoo | 8536 | *centerstring="centerstring", |
8537 | *xunit="xunit", |
||
8071 | schaersvoo | 8538 | *yunit="yunit", |
8101 | schaersvoo | 8539 | *slider="slider", |
8105 | schaersvoo | 8540 | *killslider="killslider", |
8244 | schaersvoo | 8541 | *angle="angle", |
8365 | schaersvoo | 8542 | *halflines="halflines", |
8543 | *demilines="demilines", |
||
8244 | schaersvoo | 8544 | *halfline="halfline", |
8297 | schaersvoo | 8545 | *demiline="demiline", |
8366 | schaersvoo | 8546 | *hlines="hlines", |
8547 | *vlines="vlines", |
||
8370 | schaersvoo | 8548 | *bezier="bezier", |
9213 | schaersvoo | 8549 | *functionlabel="functionlabel", |
8550 | *sliderfunction_x="sliderfunction_x", |
||
8551 | *sliderfunction_y="sliderfunction_y", |
||
8552 | *multidraw="multidraw", |
||
8553 | *multilinewidth="multilinewidth", |
||
8554 | *multistrokecolors="multistrokecolors", |
||
8555 | *multifillcolors="multifillcolors", |
||
8556 | *multistrokeopacity="multistrokeopacity", |
||
8557 | *multifillopacity="multifillopacity", |
||
8558 | *multifill="multifill", |
||
8559 | *multidash="multidash", |
||
8560 | *multilabel="multilabel", |
||
8561 | *multiuserinput="multiuserinput", |
||
9289 | schaersvoo | 8562 | *multisnaptogrid="multisnaptogrid", |
8563 | *protractor="protractor", |
||
9386 | schaersvoo | 8564 | *ruler="ruler", |
8565 | *cursor="cursor", |
||
9427 | schaersvoo | 8566 | *pointer="pointer", |
8567 | *yerrorbars="yerrorbars", |
||
11006 | schaersvoo | 8568 | *xerrorbars="xerrorbars", |
8569 | *canvastype="canvastype"; |
||
7614 | schaersvoo | 8570 | |
10891 | schaersvoo | 8571 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){ |
8572 | if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */ |
||
8573 | }else{ |
||
8574 | if( c == ' ' ){ |
||
7614 | schaersvoo | 8575 | break; |
10891 | schaersvoo | 8576 | }else{ |
8577 | temp[i] = c; |
||
8578 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
8579 | i++; |
||
8580 | } |
||
8581 | } |
||
8582 | if(temp[0] == '#'){ break; } |
||
7614 | schaersvoo | 8583 | } |
10891 | schaersvoo | 8584 | if (c == '\n' || c == '\r' || c == '\t' ){ line_number++; } |
7614 | schaersvoo | 8585 | if (i == 0) { return EMPTY; } |
10891 | schaersvoo | 8586 | if (c == EOF) {finished=1;return 0;} |
7614 | schaersvoo | 8587 | |
8588 | temp[i]='\0'; |
||
8589 | input_type=(char*)my_newmem(strlen(temp)); |
||
8590 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
10891 | schaersvoo | 8591 | /* fprintf(stdout,"temp = %s <br/>",input_type); */ |
7614 | schaersvoo | 8592 | if( strcmp(input_type, size) == 0 ){ |
8593 | free(input_type); |
||
8594 | return SIZE; |
||
8595 | } |
||
8596 | if( strcmp(input_type, xrange) == 0 ){ |
||
8597 | free(input_type); |
||
8598 | return XRANGE; |
||
8599 | } |
||
8600 | if( strcmp(input_type, rangex) == 0 ){ |
||
8601 | free(input_type); |
||
8602 | return XRANGE; |
||
8603 | } |
||
8604 | if( strcmp(input_type, trange) == 0 ){ |
||
8605 | free(input_type); |
||
8606 | return TRANGE; |
||
8607 | } |
||
8608 | if( strcmp(input_type, ranget) == 0 ){ |
||
8609 | free(input_type); |
||
8610 | return TRANGE; |
||
8611 | } |
||
8612 | if( strcmp(input_type, yrange) == 0 ){ |
||
8613 | free(input_type); |
||
8614 | return YRANGE; |
||
8615 | } |
||
8616 | if( strcmp(input_type, rangey) == 0 ){ |
||
8617 | free(input_type); |
||
8618 | return YRANGE; |
||
8619 | } |
||
8620 | if( strcmp(input_type, linewidth) == 0 ){ |
||
8621 | free(input_type); |
||
8622 | return LINEWIDTH; |
||
8623 | } |
||
8624 | if( strcmp(input_type, dashed) == 0 ){ |
||
8625 | free(input_type); |
||
8626 | return DASHED; |
||
8627 | } |
||
8628 | if( strcmp(input_type, dashtype) == 0 ){ |
||
8629 | free(input_type); |
||
8630 | return DASHTYPE; |
||
8631 | } |
||
8632 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
8633 | free(input_type); |
||
8634 | return AXIS_NUMBERING; |
||
8635 | } |
||
8636 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
8637 | free(input_type); |
||
8638 | return AXIS_NUMBERING; |
||
8639 | } |
||
8640 | if( strcmp(input_type, axis) == 0 ){ |
||
8641 | free(input_type); |
||
8642 | return AXIS; |
||
8643 | } |
||
8644 | if( strcmp(input_type, grid) == 0 ){ |
||
8645 | free(input_type); |
||
8646 | return GRID; |
||
8647 | } |
||
9383 | schaersvoo | 8648 | if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){ |
8366 | schaersvoo | 8649 | free(input_type); |
8650 | return HLINES; |
||
8651 | } |
||
9383 | schaersvoo | 8652 | if( strcmp(input_type, vlines) == 0 || strcmp(input_type, verticallines) == 0 ){ |
8366 | schaersvoo | 8653 | free(input_type); |
8654 | return VLINES; |
||
8655 | } |
||
9383 | schaersvoo | 8656 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
7614 | schaersvoo | 8657 | free(input_type); |
8658 | return HLINE; |
||
8659 | } |
||
8660 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
8661 | free(input_type); |
||
8662 | return VLINE; |
||
8663 | } |
||
8664 | if( strcmp(input_type, line) == 0 ){ |
||
8665 | free(input_type); |
||
8666 | return LINE; |
||
8667 | } |
||
9383 | schaersvoo | 8668 | if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){ |
8299 | schaersvoo | 8669 | free(input_type); |
8670 | return SEGMENTS; |
||
8671 | } |
||
7614 | schaersvoo | 8672 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
8673 | free(input_type); |
||
8674 | return SEGMENT; |
||
8675 | } |
||
9374 | schaersvoo | 8676 | if( strcmp(input_type, dsegments) == 0 ){ |
8677 | free(input_type); |
||
8678 | use_dashed = TRUE; |
||
8679 | return SEGMENTS; |
||
8680 | } |
||
7614 | schaersvoo | 8681 | if( strcmp(input_type, dsegment) == 0 ){ |
8682 | free(input_type); |
||
8683 | use_dashed = TRUE; |
||
8684 | return SEGMENT; |
||
8685 | } |
||
8686 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
8687 | free(input_type); |
||
8688 | return CROSSHAIRSIZE; |
||
8689 | } |
||
8690 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
8691 | free(input_type); |
||
8692 | return ARROWHEAD; |
||
8693 | } |
||
8694 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
8695 | free(input_type); |
||
8696 | return CROSSHAIRS; |
||
8697 | } |
||
8698 | if( strcmp(input_type, crosshair) == 0 ){ |
||
8699 | free(input_type); |
||
8700 | return CROSSHAIR; |
||
8701 | } |
||
8702 | if( strcmp(input_type, onclick) == 0 ){ |
||
8703 | free(input_type); |
||
8704 | return ONCLICK; |
||
8705 | } |
||
8706 | if( strcmp(input_type, drag) == 0 ){ |
||
8707 | free(input_type); |
||
8708 | return DRAG; |
||
8709 | } |
||
8710 | if( strcmp(input_type, userdraw) == 0 ){ |
||
8711 | free(input_type); |
||
8712 | return USERDRAW; |
||
8713 | } |
||
8714 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
8715 | free(input_type); |
||
8716 | return STYLE; |
||
8717 | } |
||
8718 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
8719 | free(input_type); |
||
8720 | return FILLCOLOR; |
||
8721 | } |
||
8722 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
8723 | free(input_type); |
||
8724 | return STROKECOLOR; |
||
8725 | } |
||
8726 | if( strcmp(input_type, filled) == 0 ){ |
||
8727 | free(input_type); |
||
8728 | return FILLED; |
||
8729 | } |
||
8730 | if( strcmp(input_type, http) == 0 ){ |
||
8731 | free(input_type); |
||
8732 | return HTTP; |
||
8733 | } |
||
8734 | if( strcmp(input_type, rays) == 0 ){ |
||
8735 | free(input_type); |
||
8736 | return RAYS; |
||
8737 | } |
||
8738 | if( strcmp(input_type, lattice) == 0 ){ |
||
8739 | free(input_type); |
||
8740 | return LATTICE; |
||
8741 | } |
||
8742 | if( strcmp(input_type, bgimage) == 0 ){ |
||
8743 | free(input_type); |
||
8744 | return BGIMAGE; |
||
8745 | } |
||
8746 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
8747 | free(input_type); |
||
8748 | return BGCOLOR; |
||
8749 | } |
||
8750 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
8751 | free(input_type); |
||
8752 | return BGIMAGE; |
||
8753 | } |
||
8754 | if( strcmp(input_type, text) == 0 ){ |
||
8755 | free(input_type); |
||
8756 | return FLY_TEXT; |
||
8757 | } |
||
8758 | if( strcmp(input_type, textup) == 0 ){ |
||
8759 | free(input_type); |
||
8760 | return FLY_TEXTUP; |
||
8761 | } |
||
8762 | if( strcmp(input_type, mouse) == 0 ){ |
||
8763 | free(input_type); |
||
8764 | return MOUSE; |
||
8765 | } |
||
7991 | schaersvoo | 8766 | if( strcmp(input_type, mousex) == 0 ){ |
8767 | free(input_type); |
||
8768 | return MOUSEX; |
||
8769 | } |
||
8770 | if( strcmp(input_type, mousey) == 0 ){ |
||
8771 | free(input_type); |
||
8772 | return MOUSEY; |
||
8773 | } |
||
8071 | schaersvoo | 8774 | if( strcmp(input_type, mouse_degree) == 0 ){ |
8775 | free(input_type); |
||
8776 | return MOUSE_DEGREE; |
||
8777 | } |
||
8778 | if( strcmp(input_type, mouse_display) == 0 ){ |
||
8779 | free(input_type); |
||
8780 | return MOUSE_DISPLAY; |
||
8781 | } |
||
7614 | schaersvoo | 8782 | if( strcmp(input_type, mouseprecision) == 0 ){ |
8783 | free(input_type); |
||
8784 | return MOUSE_PRECISION; |
||
8785 | } |
||
8786 | if( strcmp(input_type, precision) == 0 ){ |
||
8787 | free(input_type); |
||
8788 | return MOUSE_PRECISION; |
||
8789 | } |
||
8790 | if( strcmp(input_type, curve) == 0 ){ |
||
8791 | free(input_type); |
||
8792 | return CURVE; |
||
8793 | } |
||
8794 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 8795 | use_dashed = TRUE; |
7614 | schaersvoo | 8796 | free(input_type); |
8797 | return CURVE; |
||
8798 | } |
||
8799 | if( strcmp(input_type, plot) == 0 ){ |
||
8800 | free(input_type); |
||
8801 | return CURVE; |
||
8802 | } |
||
8803 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 8804 | use_dashed = TRUE; |
7614 | schaersvoo | 8805 | free(input_type); |
8806 | return CURVE; |
||
8807 | } |
||
7788 | schaersvoo | 8808 | if( strcmp(input_type, levelcurve) == 0 ){ |
8809 | free(input_type); |
||
8810 | return LEVELCURVE; |
||
8811 | } |
||
7614 | schaersvoo | 8812 | if( strcmp(input_type, plotsteps) == 0 ){ |
8813 | free(input_type); |
||
8814 | return PLOTSTEPS; |
||
8815 | } |
||
8816 | if( strcmp(input_type, plotstep) == 0 ){ |
||
8817 | free(input_type); |
||
8818 | return PLOTSTEPS; |
||
8819 | } |
||
8820 | if( strcmp(input_type, tsteps) == 0 ){ |
||
8821 | free(input_type); |
||
8822 | return PLOTSTEPS; |
||
8823 | } |
||
8824 | if( strcmp(input_type, fontsize) == 0 ){ |
||
8825 | free(input_type); |
||
8826 | return FONTSIZE; |
||
8827 | } |
||
8828 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
8829 | free(input_type); |
||
8830 | return FONTCOLOR; |
||
8831 | } |
||
8832 | if( strcmp(input_type, arrow2) == 0 ){ |
||
8833 | free(input_type); |
||
8834 | return ARROW2; |
||
8835 | } |
||
8836 | if( strcmp(input_type, darrow) == 0 ){ |
||
8837 | free(input_type); |
||
8071 | schaersvoo | 8838 | use_dashed = TRUE; |
7614 | schaersvoo | 8839 | return ARROW; |
8840 | } |
||
8841 | if( strcmp(input_type, darrow2) == 0 ){ |
||
8842 | free(input_type); |
||
8843 | use_dashed = TRUE; |
||
8844 | return ARROW2; |
||
8845 | } |
||
8347 | schaersvoo | 8846 | if( strcmp(input_type, arrows2) == 0 ){ |
8847 | free(input_type); |
||
8848 | return ARROWS2; |
||
8849 | } |
||
9382 | schaersvoo | 8850 | if( strcmp(input_type, arrows) == 0 || strcmp(input_type, vectors) == 0 ){ |
8304 | schaersvoo | 8851 | free(input_type); |
8852 | return ARROWS; |
||
8853 | } |
||
9382 | schaersvoo | 8854 | if( strcmp(input_type, arrow) == 0 || strcmp(input_type, vector) == 0 ){ |
8304 | schaersvoo | 8855 | free(input_type); |
8856 | return ARROW; |
||
8857 | } |
||
7614 | schaersvoo | 8858 | if( strcmp(input_type, zoom) == 0 ){ |
8859 | free(input_type); |
||
8860 | return ZOOM; |
||
8861 | } |
||
8862 | if( strcmp(input_type, triangle) == 0 ){ |
||
8863 | free(input_type); |
||
8864 | return TRIANGLE; |
||
8865 | } |
||
9306 | schaersvoo | 8866 | if( strcmp(input_type, triangles) == 0 ){ |
8867 | free(input_type); |
||
8868 | return TRIANGLES; |
||
8869 | } |
||
9374 | schaersvoo | 8870 | if( strcmp(input_type, ftriangles) == 0 ){ |
8871 | free(input_type); |
||
8872 | use_filled = TRUE; |
||
8873 | return TRIANGLES; |
||
8874 | } |
||
7614 | schaersvoo | 8875 | if( strcmp(input_type, ftriangle) == 0 ){ |
8876 | free(input_type); |
||
8877 | use_filled = TRUE; |
||
8878 | return TRIANGLE; |
||
8879 | } |
||
8880 | if( strcmp(input_type, input) == 0 ){ |
||
8881 | free(input_type); |
||
8882 | return INPUT; |
||
8883 | } |
||
8884 | if( strcmp(input_type, inputstyle) == 0 ){ |
||
8885 | free(input_type); |
||
8886 | return INPUTSTYLE; |
||
8887 | } |
||
8888 | if( strcmp(input_type, textarea) == 0 ){ |
||
8889 | free(input_type); |
||
8890 | return TEXTAREA; |
||
8891 | } |
||
8892 | if( strcmp(input_type, mathml) == 0 ){ |
||
8893 | free(input_type); |
||
8894 | return MATHML; |
||
8895 | } |
||
8896 | if( strcmp(input_type, html) == 0 ){ |
||
8897 | free(input_type); |
||
8898 | return MATHML; |
||
8899 | } |
||
8900 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
8901 | free(input_type); |
||
8902 | return FONTFAMILY; |
||
8903 | } |
||
10975 | schaersvoo | 8904 | if( strcmp(input_type, polyline) == 0 || strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){ |
7614 | schaersvoo | 8905 | free(input_type); |
8906 | return POLYLINE; |
||
8907 | } |
||
8351 | schaersvoo | 8908 | if( strcmp(input_type, lines) == 0 ){ |
8909 | free(input_type); |
||
8910 | return LINES; |
||
8911 | } |
||
9374 | schaersvoo | 8912 | if( strcmp(input_type, rects) == 0){ |
8363 | schaersvoo | 8913 | free(input_type); |
8914 | return RECTS; |
||
8915 | } |
||
9383 | schaersvoo | 8916 | if( strcmp(input_type, frects) == 0 ){ |
8363 | schaersvoo | 8917 | free(input_type); |
9374 | schaersvoo | 8918 | use_filled = TRUE; |
8363 | schaersvoo | 8919 | return RECTS; |
8920 | } |
||
7614 | schaersvoo | 8921 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
8922 | free(input_type); |
||
8923 | return RECT; |
||
8924 | } |
||
9374 | schaersvoo | 8925 | if( strcmp(input_type, square) == 0 ){ |
8926 | free(input_type); |
||
8927 | return RECT; |
||
8928 | } |
||
8929 | if( strcmp(input_type, fsquare) == 0 ){ |
||
8930 | free(input_type); |
||
8931 | use_filled = TRUE; |
||
8932 | return SQUARE; |
||
8933 | } |
||
8934 | if( strcmp(input_type, fsquares) == 0 ){ |
||
8935 | free(input_type); |
||
8936 | use_filled = TRUE; |
||
8937 | return RECTS; |
||
8938 | } |
||
8370 | schaersvoo | 8939 | if( strcmp(input_type, roundrects) == 0 ){ |
8940 | free(input_type); |
||
8941 | return ROUNDRECTS; |
||
8942 | } |
||
7614 | schaersvoo | 8943 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
8944 | free(input_type); |
||
8945 | return ROUNDRECT; |
||
8946 | } |
||
9374 | schaersvoo | 8947 | if( strcmp(input_type, froundrects) == 0 ){ |
7614 | schaersvoo | 8948 | free(input_type); |
8949 | use_filled = TRUE; |
||
9374 | schaersvoo | 8950 | return ROUNDRECTS; |
7614 | schaersvoo | 8951 | } |
9374 | schaersvoo | 8952 | if( strcmp(input_type, froundrect) == 0 ){ |
7614 | schaersvoo | 8953 | free(input_type); |
8954 | use_filled = TRUE; |
||
9374 | schaersvoo | 8955 | return ROUNDRECT; |
7614 | schaersvoo | 8956 | } |
8957 | if( strcmp(input_type, dline) == 0 ){ |
||
8958 | use_dashed = TRUE; |
||
8959 | free(input_type); |
||
8960 | return LINE; |
||
8961 | } |
||
7786 | schaersvoo | 8962 | if( strcmp(input_type, dvline) == 0 ){ |
8963 | use_dashed = TRUE; |
||
8964 | free(input_type); |
||
8965 | return VLINE; |
||
8966 | } |
||
8967 | if( strcmp(input_type, dhline) == 0 ){ |
||
8968 | use_dashed = TRUE; |
||
8969 | free(input_type); |
||
8970 | return HLINE; |
||
8971 | } |
||
9386 | schaersvoo | 8972 | if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0 ){ |
8973 | free(input_type); |
||
8974 | return HALFLINES; |
||
8975 | } |
||
8976 | if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){ |
||
8977 | free(input_type); |
||
8978 | return HALFLINE; |
||
8979 | } |
||
7614 | schaersvoo | 8980 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
8981 | use_filled = TRUE; |
||
8982 | free(input_type); |
||
8983 | return RECT; |
||
8984 | } |
||
8304 | schaersvoo | 8985 | if( strcmp(input_type, circles) == 0 ){ |
8986 | free(input_type); |
||
8987 | return CIRCLES; |
||
8988 | } |
||
7614 | schaersvoo | 8989 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
8990 | use_filled = TRUE; |
||
8991 | free(input_type); |
||
8992 | return CIRCLE; |
||
8993 | } |
||
9374 | schaersvoo | 8994 | if( strcmp(input_type, fcircles) == 0 || strcmp(input_type, disks) == 0 ){ |
8995 | use_filled = TRUE; |
||
8996 | free(input_type); |
||
8997 | return CIRCLES; |
||
8998 | } |
||
7614 | schaersvoo | 8999 | if( strcmp(input_type, circle) == 0 ){ |
9000 | free(input_type); |
||
9001 | return CIRCLE; |
||
9002 | } |
||
9003 | if( strcmp(input_type, point) == 0 ){ |
||
9004 | free(input_type); |
||
9005 | return POINT; |
||
9006 | } |
||
9007 | if( strcmp(input_type, points) == 0 ){ |
||
9008 | free(input_type); |
||
9009 | return POINTS; |
||
9010 | } |
||
9374 | schaersvoo | 9011 | if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){ |
7614 | schaersvoo | 9012 | use_filled = TRUE; |
9013 | free(input_type); |
||
9014 | return ARC; |
||
9015 | } |
||
9016 | if( strcmp(input_type, arc) == 0 ){ |
||
9017 | free(input_type); |
||
9018 | return ARC; |
||
9019 | } |
||
9020 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
9021 | free(input_type); |
||
9022 | return POLY; |
||
9023 | } |
||
9024 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
9025 | use_filled = TRUE; |
||
9026 | free(input_type); |
||
9027 | return POLY; |
||
9028 | } |
||
9029 | if( strcmp(input_type, ellipse) == 0){ |
||
9030 | free(input_type); |
||
9031 | return ELLIPSE; |
||
9032 | } |
||
9033 | if( strcmp(input_type, string) == 0 ){ |
||
9034 | free(input_type); |
||
9035 | return STRING; |
||
9036 | } |
||
9037 | if( strcmp(input_type, stringup) == 0 ){ |
||
9038 | free(input_type); |
||
9039 | return STRINGUP; |
||
9040 | } |
||
9385 | schaersvoo | 9041 | if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){ |
7614 | schaersvoo | 9042 | free(input_type); |
9043 | return OPACITY; |
||
9044 | } |
||
9045 | if( strcmp(input_type, comment) == 0){ |
||
9046 | free(input_type); |
||
9047 | return COMMENT; |
||
9048 | } |
||
9049 | if( strcmp(input_type, fellipse) == 0){ |
||
9050 | free(input_type); |
||
9051 | use_filled = TRUE; |
||
9052 | return ELLIPSE; |
||
8224 | bpr | 9053 | } |
9386 | schaersvoo | 9054 | if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){ |
7614 | schaersvoo | 9055 | free(input_type); |
8146 | schaersvoo | 9056 | return CLEARBUTTON; |
7614 | schaersvoo | 9057 | } |
9058 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
||
9059 | free(input_type); |
||
9060 | return TRANSLATION; |
||
9061 | } |
||
9062 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
9063 | free(input_type); |
||
9064 | return KILLTRANSLATION; |
||
9065 | } |
||
9066 | if( strcmp(input_type, rotate) == 0){ |
||
9067 | free(input_type); |
||
9068 | return ROTATE; |
||
9069 | } |
||
9907 | schaersvoo | 9070 | if( strcmp(input_type, killrotate) == 0){ |
9071 | free(input_type); |
||
9072 | return KILLROTATE; |
||
9073 | } |
||
9074 | if( strcmp(input_type, rotationcenter) == 0){ |
||
9075 | free(input_type); |
||
9076 | return ROTATION_CENTER; |
||
9077 | } |
||
7785 | schaersvoo | 9078 | if( strcmp(input_type, affine) == 0){ |
9079 | free(input_type); |
||
9080 | return AFFINE; |
||
9081 | } |
||
9082 | if( strcmp(input_type, killaffine) == 0){ |
||
9083 | free(input_type); |
||
9084 | return KILLAFFINE; |
||
9085 | } |
||
7614 | schaersvoo | 9086 | if( strcmp(input_type, slider) == 0 ){ |
9087 | free(input_type); |
||
9088 | return SLIDER; |
||
9089 | } |
||
8101 | schaersvoo | 9090 | if( strcmp(input_type, killslider) == 0 ){ |
9091 | free(input_type); |
||
9092 | return KILLSLIDER; |
||
9093 | } |
||
7614 | schaersvoo | 9094 | if( strcmp(input_type, copy) == 0 ){ |
9095 | free(input_type); |
||
9096 | return COPY; |
||
9097 | } |
||
9098 | if( strcmp(input_type, copyresized) == 0 ){ |
||
9099 | free(input_type); |
||
9100 | return COPYRESIZED; |
||
9101 | } |
||
9102 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
9103 | free(input_type); |
||
9104 | return XLOGSCALE; |
||
9105 | } |
||
9106 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
9107 | free(input_type); |
||
9108 | return YLOGSCALE; |
||
9109 | } |
||
9110 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
9111 | free(input_type); |
||
9112 | return XYLOGSCALE; |
||
9113 | } |
||
9114 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
9115 | free(input_type); |
||
9116 | return YLOGSCALE; |
||
9117 | } |
||
7735 | schaersvoo | 9118 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 9119 | free(input_type); |
7735 | schaersvoo | 9120 | return XLOGBASE; |
7614 | schaersvoo | 9121 | } |
7735 | schaersvoo | 9122 | if( strcmp(input_type, ylogbase) == 0 ){ |
9123 | free(input_type); |
||
9124 | return YLOGBASE; |
||
9125 | } |
||
7614 | schaersvoo | 9126 | if( strcmp(input_type, intooltip) == 0 ){ |
9127 | free(input_type); |
||
9128 | return INTOOLTIP; |
||
9129 | } |
||
9329 | schaersvoo | 9130 | if( strcmp(input_type, popup) == 0 ){ |
9131 | free(input_type); |
||
9132 | return POPUP; |
||
9133 | } |
||
7614 | schaersvoo | 9134 | if( strcmp(input_type,video) == 0 ){ |
9135 | free(input_type); |
||
9136 | return VIDEO; |
||
9137 | } |
||
9138 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
||
9139 | free(input_type); |
||
9140 | return FLOODFILL; |
||
8224 | bpr | 9141 | } |
7614 | schaersvoo | 9142 | if( strcmp(input_type,filltoborder) == 0 ){ |
9143 | free(input_type); |
||
9144 | return FILLTOBORDER; |
||
8224 | bpr | 9145 | } |
7614 | schaersvoo | 9146 | if( strcmp(input_type, replyformat) == 0 ){ |
9147 | free(input_type); |
||
9148 | return REPLYFORMAT; |
||
9149 | } |
||
9150 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
9151 | free(input_type); |
||
9152 | return PIXELSIZE; |
||
9153 | } |
||
9154 | if( strcmp(input_type, setpixel) == 0 ){ |
||
9155 | free(input_type); |
||
9156 | return SETPIXEL; |
||
9157 | } |
||
9158 | if( strcmp(input_type, pixels) == 0 ){ |
||
9159 | free(input_type); |
||
9160 | return PIXELS; |
||
9161 | } |
||
9162 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
9163 | free(input_type); |
||
9164 | return X_AXIS_STRINGS; |
||
9165 | } |
||
9341 | schaersvoo | 9166 | if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){ |
9167 | free(input_type); |
||
9168 | return X_AXIS_STRINGS_UP; |
||
9169 | } |
||
7614 | schaersvoo | 9170 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
9171 | free(input_type); |
||
9172 | return Y_AXIS_STRINGS; |
||
9173 | } |
||
9174 | if( strcmp(input_type, legend) == 0 ){ |
||
9175 | free(input_type); |
||
9176 | return LEGEND; |
||
9177 | } |
||
9178 | if( strcmp(input_type, legendcolors) == 0 ){ |
||
9179 | free(input_type); |
||
9180 | return LEGENDCOLORS; |
||
9181 | } |
||
9182 | if( strcmp(input_type, xlabel) == 0 ){ |
||
9183 | free(input_type); |
||
9184 | return XLABEL; |
||
9185 | } |
||
9186 | if( strcmp(input_type, ylabel) == 0 ){ |
||
9187 | free(input_type); |
||
9188 | return YLABEL; |
||
9189 | } |
||
8370 | schaersvoo | 9190 | if( strcmp(input_type, bezier) == 0 ){ |
9191 | free(input_type); |
||
9192 | return BEZIER; |
||
9193 | } |
||
7614 | schaersvoo | 9194 | if( strcmp(input_type, animate) == 0 ){ |
9195 | free(input_type); |
||
9196 | return ANIMATE; |
||
9197 | } |
||
9354 | schaersvoo | 9198 | /* these are bitmap related flydraw commands...must be removed. eventually */ |
7614 | schaersvoo | 9199 | if( strcmp(input_type, transparent) == 0 ){ |
9200 | free(input_type); |
||
9201 | return TRANSPARENT; |
||
9202 | } |
||
7877 | schaersvoo | 9203 | if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){ |
7614 | schaersvoo | 9204 | free(input_type); |
9205 | return STATUS; |
||
9206 | } |
||
7784 | schaersvoo | 9207 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
9208 | free(input_type); |
||
9209 | return XSNAPTOGRID; |
||
9210 | } |
||
9211 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
9212 | free(input_type); |
||
9213 | return YSNAPTOGRID; |
||
9214 | } |
||
8379 | schaersvoo | 9215 | if( strcmp(input_type, snaptogrid) == 0 ){ |
9216 | free(input_type); |
||
9217 | return SNAPTOGRID; |
||
9218 | } |
||
9219 | if( strcmp(input_type, snaptopoints) == 0 ){ |
||
9220 | free(input_type); |
||
9221 | return SNAPTOPOINTS; |
||
9222 | } |
||
9213 | schaersvoo | 9223 | if( strcmp(input_type, snaptofunction) == 0 || strcmp(input_type, snaptofun) == 0 ){ |
9224 | free(input_type); |
||
9225 | return SNAPTOFUNCTION; |
||
9226 | } |
||
7652 | schaersvoo | 9227 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 9228 | free(input_type); |
7652 | schaersvoo | 9229 | return USERINPUT_XY; |
9230 | } |
||
8193 | schaersvoo | 9231 | if( strcmp(input_type, userinput_function) == 0 ){ |
9232 | free(input_type); |
||
9233 | return USERINPUT_FUNCTION; |
||
9234 | } |
||
7663 | schaersvoo | 9235 | if( strcmp(input_type, usertextarea_xy) == 0 ){ |
9236 | free(input_type); |
||
9237 | return USERTEXTAREA_XY; |
||
9238 | } |
||
8222 | schaersvoo | 9239 | if( strcmp(input_type, userinput) == 0 ){ |
9240 | free(input_type); |
||
9241 | return USERINPUT; |
||
9242 | } |
||
8105 | schaersvoo | 9243 | if( strcmp(input_type, angle) == 0 ){ |
7996 | schaersvoo | 9244 | free(input_type); |
8105 | schaersvoo | 9245 | return ANGLE; |
9246 | } |
||
8297 | schaersvoo | 9247 | if( strcmp(input_type, functionlabel) == 0 ){ |
8244 | schaersvoo | 9248 | free(input_type); |
8297 | schaersvoo | 9249 | return FUNCTION_LABEL; |
9250 | } |
||
9213 | schaersvoo | 9251 | if( strcmp(input_type, sliderfunction_x) == 0 ){ |
8297 | schaersvoo | 9252 | free(input_type); |
9213 | schaersvoo | 9253 | return SLIDER_X; |
9254 | } |
||
9255 | if( strcmp(input_type, sliderfunction_y) == 0 ){ |
||
9256 | free(input_type); |
||
9257 | return SLIDER_Y; |
||
9258 | } |
||
9259 | if( strcmp(input_type, multidraw) == 0 ){ |
||
9260 | free(input_type); |
||
9261 | return MULTIDRAW; |
||
9262 | } |
||
9263 | if( strcmp(input_type, multistrokeopacity) == 0 ){ |
||
9264 | free(input_type); |
||
9265 | return MULTISTROKEOPACITY; |
||
9266 | } |
||
9267 | if( strcmp(input_type, multifillopacity) == 0 ){ |
||
9268 | free(input_type); |
||
9269 | return MULTIFILLOPACITY; |
||
9270 | } |
||
9271 | if( strcmp(input_type, multilinewidth) == 0 ){ |
||
9272 | free(input_type); |
||
9273 | return MULTILINEWIDTH; |
||
9274 | } |
||
9275 | if( strcmp(input_type, multistrokecolors) == 0 ){ |
||
9276 | free(input_type); |
||
9277 | return MULTISTROKECOLORS; |
||
9278 | } |
||
9279 | if( strcmp(input_type, multifill) == 0 ){ |
||
9280 | free(input_type); |
||
9281 | return MULTIFILL; |
||
9282 | } |
||
9283 | if( strcmp(input_type, multifillcolors) == 0 ){ |
||
9284 | free(input_type); |
||
9285 | return MULTIFILLCOLORS; |
||
9286 | } |
||
9287 | if( strcmp(input_type, multilabel) == 0 ){ |
||
9288 | free(input_type); |
||
9289 | return MULTILABEL; |
||
9290 | } |
||
9291 | if( strcmp(input_type, multidash) == 0 ){ |
||
9292 | free(input_type); |
||
9293 | return MULTIDASH; |
||
9294 | } |
||
9295 | if( strcmp(input_type, multisnaptogrid) == 0 ){ |
||
9296 | free(input_type); |
||
9297 | return MULTISNAPTOGRID; |
||
9298 | } |
||
9299 | if( strcmp(input_type, multiuserinput) == 0 ){ |
||
9300 | free(input_type); |
||
9301 | return MULTIUSERINPUT; |
||
9302 | } |
||
9386 | schaersvoo | 9303 | if( strcmp(input_type, parallel) == 0 ){ |
9304 | free(input_type); |
||
9305 | return PARALLEL; |
||
9306 | } |
||
9289 | schaersvoo | 9307 | if( strcmp(input_type, protractor) == 0 ){ |
9308 | free(input_type); |
||
9309 | return PROTRACTOR; |
||
9310 | } |
||
9311 | if( strcmp(input_type, ruler) == 0 ){ |
||
9312 | free(input_type); |
||
9313 | return RULER; |
||
9314 | } |
||
9386 | schaersvoo | 9315 | if( strcmp(input_type, cursor) == 0 || strcmp(input_type, pointer) == 0 ){ |
9213 | schaersvoo | 9316 | free(input_type); |
9386 | schaersvoo | 9317 | return CURSOR; |
9318 | } |
||
9319 | if( strcmp(input_type, sgraph) == 0 ){ |
||
9320 | free(input_type); |
||
9321 | return SGRAPH; |
||
9322 | } |
||
9323 | if( strcmp(input_type, jsmath) == 0 ){ |
||
9324 | free(input_type); |
||
9325 | return JSMATH; |
||
9326 | } |
||
9327 | if( strcmp(input_type, trace_jscurve) == 0 ){ |
||
9328 | free(input_type); |
||
9329 | return TRACE_JSCURVE; |
||
9330 | } |
||
9331 | if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){ |
||
9332 | free(input_type); |
||
9333 | return JSCURVE; |
||
9334 | } |
||
9335 | if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){ |
||
9336 | free(input_type); |
||
9337 | return CENTERSTRING; |
||
9338 | } |
||
9339 | if( strcmp(input_type, setlimits) == 0 ){ |
||
9340 | free(input_type); |
||
9341 | return SETLIMITS; |
||
9342 | } |
||
9343 | if( strcmp(input_type, xunit) == 0 ){ |
||
9344 | free(input_type); |
||
9345 | return XUNIT; |
||
9346 | } |
||
9347 | if( strcmp(input_type, yunit) == 0 ){ |
||
9348 | free(input_type); |
||
9349 | return YUNIT; |
||
9350 | } |
||
9351 | if( strcmp(input_type, fill) == 0 ){ |
||
9352 | free(input_type); |
||
9353 | return FLOODFILL; |
||
9354 | } |
||
9355 | if( strcmp(input_type, end) == 0){ |
||
9356 | free(input_type); |
||
9357 | return END; |
||
9358 | } |
||
9359 | if( strcmp(input_type, blink) == 0 ){ |
||
9360 | free(input_type); |
||
9361 | return BLINK; |
||
9362 | } |
||
9363 | if( strcmp(input_type, audio) == 0 ){ |
||
9364 | free(input_type); |
||
9365 | return AUDIO; |
||
9366 | } |
||
9367 | if( strcmp(input_type, audioobject) == 0 ){ |
||
9368 | free(input_type); |
||
9369 | return AUDIOOBJECT; |
||
9370 | } |
||
9371 | if( strcmp(input_type, patternfill) == 0 ){ |
||
9372 | free(input_type); |
||
9373 | return PATTERNFILL; |
||
9374 | } |
||
9375 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
9376 | free(input_type); |
||
9377 | return HATCHFILL; |
||
9378 | } |
||
9379 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
||
9380 | free(input_type); |
||
9381 | return DIAMONDFILL; |
||
9382 | } |
||
9383 | if( strcmp(input_type, dotfill) == 0 ){ |
||
9384 | free(input_type); |
||
9385 | return DOTFILL; |
||
9386 | } |
||
9387 | if( strcmp(input_type, gridfill) == 0 ){ |
||
9388 | free(input_type); |
||
9389 | return GRIDFILL; |
||
9390 | } |
||
9391 | if( strcmp(input_type, imagefill) == 0 ){ |
||
9392 | free(input_type); |
||
9393 | return IMAGEFILL; |
||
9394 | } |
||
9395 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
9396 | free(input_type); |
||
9397 | return CLICKTILE_COLORS; |
||
9398 | } |
||
9399 | if( strcmp(input_type, clicktile) == 0 ){ |
||
9400 | free(input_type); |
||
9401 | return CLICKTILE; |
||
9402 | } |
||
9403 | if( strcmp(input_type, piechart) == 0 ){ |
||
9404 | free(input_type); |
||
9405 | return PIECHART; |
||
9406 | } |
||
9433 | schaersvoo | 9407 | if( strcmp(input_type, boxplot) == 0 ){ |
9408 | free(input_type); |
||
9409 | return BOXPLOT; |
||
9410 | } |
||
9465 | schaersvoo | 9411 | if( strcmp(input_type, boxplotdata) == 0 ){ |
9433 | schaersvoo | 9412 | free(input_type); |
9465 | schaersvoo | 9413 | return BOXPLOTDATA; |
9433 | schaersvoo | 9414 | } |
9465 | schaersvoo | 9415 | if( strcmp(input_type, userboxplot) == 0 ){ |
9416 | free(input_type); |
||
9417 | return USERBOXPLOT; |
||
9418 | } |
||
9419 | if( strcmp(input_type, userboxplotdata) == 0 ){ |
||
9420 | free(input_type); |
||
9421 | return USERBOXPLOT; |
||
9422 | } |
||
9386 | schaersvoo | 9423 | if( strcmp(input_type, barchart) == 0 ){ |
9424 | free(input_type); |
||
9425 | return BARCHART; |
||
9426 | } |
||
9427 | if( strcmp(input_type, linegraph) == 0 ){ |
||
9428 | free(input_type); |
||
9429 | return LINEGRAPH; |
||
9430 | } |
||
9431 | if( strcmp(input_type, clock) == 0 ){ |
||
9432 | free(input_type); |
||
9433 | return CLOCK; |
||
9434 | } |
||
9427 | schaersvoo | 9435 | if( strcmp(input_type, yerrorbars) == 0 ){ |
9386 | schaersvoo | 9436 | free(input_type); |
9427 | schaersvoo | 9437 | return YERRORBARS; |
9438 | } |
||
9439 | if( strcmp(input_type, xerrorbars) == 0 ){ |
||
9440 | free(input_type); |
||
9441 | return XERRORBARS; |
||
9442 | } |
||
11006 | schaersvoo | 9443 | if( strcmp(input_type, canvastype) == 0 ){ |
9427 | schaersvoo | 9444 | free(input_type); |
11006 | schaersvoo | 9445 | return CANVASTYPE; |
9446 | } |
||
9447 | free(input_type); |
||
7614 | schaersvoo | 9448 | ungetc(c,infile); |
9449 | return 0; |
||
9450 | } |