Rev 14622 | Rev 14649 | 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 */ |
||
11021 | schaersvoo | 18 | void add_javascript_function(int js_function[], int canvas_root_id); |
14078 | bpr | 19 | void reset();/* reset some global variables like "use_filled", "use_dashed" */ |
7614 | schaersvoo | 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; |
||
11893 | schaersvoo | 51 | double tmax = 0; |
52 | double tmin = 0; |
||
7614 | schaersvoo | 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*/ |
||
14208 | schaersvoo | 57 | char *slider_type="0"; |
58 | int slider_cnt = 0; |
||
59 | int active_sliders[MAX_SLIDERS]; |
||
60 | char *current_sliders = "[-1]"; |
||
7785 | schaersvoo | 61 | int use_affine = FALSE; |
7614 | schaersvoo | 62 | int use_rotate = FALSE; |
14078 | bpr | 63 | int use_filled = 0; /* 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */ |
64 | int use_dashed = FALSE; /* dashing not natively supported in firefox, for now... */ |
||
8097 | schaersvoo | 65 | |
7614 | schaersvoo | 66 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
9329 | schaersvoo | 67 | char *getfile_cmd = ""; |
7614 | schaersvoo | 68 | /****************************************************************************** |
69 | ** Main Program |
||
70 | ******************************************************************************/ |
||
71 | int main(int argc, char *argv[]){ |
||
14066 | bpr | 72 | /* need unique id for every call to canvasdraw: rand(); is too slow...will result in many identical id's */ |
12104 | schaersvoo | 73 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz); |
74 | unsigned int canvas_root_id = (unsigned int) tv.tv_usec; |
||
7614 | schaersvoo | 75 | infile = stdin;/* read flyscript via stdin */ |
76 | int i,c; |
||
77 | double double_data[MAX_INT+1]; |
||
78 | int int_data[MAX_INT+1]; |
||
79 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
||
14208 | schaersvoo | 80 | for(i=0;i<MAX_SLIDERS;i++){active_sliders[i]=-1;} |
7614 | schaersvoo | 81 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
82 | int use_axis = FALSE; |
||
11891 | schaersvoo | 83 | int use_axis_numbering = -1; |
14066 | bpr | 84 | int use_snap = 0; /* 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */ |
14038 | schaersvoo | 85 | int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/ |
7797 | schaersvoo | 86 | int use_pan_and_zoom = FALSE; |
14066 | bpr | 87 | int use_safe_eval = FALSE; /* if true, add just once: js function to evaluate userinput values for plotting etc */ |
7858 | schaersvoo | 88 | int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */ |
14078 | bpr | 89 | int use_js_plot = FALSE; /* if true, let js-engine plot the curve */ |
11006 | schaersvoo | 90 | int jsplot_cnt = 0; /* keepint track on the curve identity */ |
8448 | schaersvoo | 91 | int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */ |
14543 | schaersvoo | 92 | int print_dragdrop_reply_only_once = FALSE;/* avoid multiple useless identical lines to be printed */ |
14038 | schaersvoo | 93 | int include_special_OEF_reply = FALSE; /* used for including extra read_canvas_images();*/ |
7614 | schaersvoo | 94 | int line_width = 1; |
95 | int decimals = 2; |
||
8365 | schaersvoo | 96 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */ |
97 | int use_userdraw = FALSE; /* flag to indicate user interaction */ |
||
14066 | bpr | 98 | int drag_type = -1;/* 0,1,2: xy,x,y */ |
9329 | schaersvoo | 99 | int use_tooltip = -1; /* 1= tooltip 2= popup window*/ |
7614 | schaersvoo | 100 | char *tooltip_text = "Click here"; |
101 | char *temp = ""; /* */ |
||
102 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
103 | char *stroke_color = "255,0,0"; |
||
14208 | schaersvoo | 104 | char *fill_color = "255,255,255"; |
7614 | schaersvoo | 105 | char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
106 | char *font_color = "#00000"; |
||
107 | char *draw_type = "points"; |
||
108 | char *fly_font = "normal"; |
||
8815 | schaersvoo | 109 | char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;"; |
7614 | schaersvoo | 110 | char *flytext = ""; |
7785 | schaersvoo | 111 | char *affine_matrix = "[1,0,0,1,0,0]"; |
8297 | schaersvoo | 112 | char *function_label = "f(x)="; |
14066 | bpr | 113 | int use_pattern = 0; /* used in drag&drop library: grid=2,hatch=3,diamond=4,dot=5*/ |
11006 | schaersvoo | 114 | int canvas_type = DRAG_CANVAS; /* to use a specific canvas for filling etc */ |
7614 | schaersvoo | 115 | int pixelsize = 1; |
116 | int reply_format = 0; |
||
117 | int input_cnt = 0; |
||
118 | int ext_img_cnt = 0; |
||
11763 | schaersvoo | 119 | int fill_cnt = 0; |
14086 | bpr | 120 | int font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Ariel</code> the ''fontsize`` value is not substituted into fontfamily !! */ |
8388 | schaersvoo | 121 | int fly_font_size = 12; /*fly_font_size is relative to this... */ |
14066 | bpr | 122 | int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */ |
123 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */ |
||
7614 | schaersvoo | 124 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
8365 | schaersvoo | 125 | int arrow_head = 8; /* size in px needed for arrow based userdraw: "userdraw arrow,color" */ |
7833 | schaersvoo | 126 | int crosshair_size = 5; /* size in px*/ |
8365 | schaersvoo | 127 | 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 */ |
14066 | bpr | 128 | int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */ |
8448 | schaersvoo | 129 | 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 | 130 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
131 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
7989 | schaersvoo | 132 | int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/ |
9433 | schaersvoo | 133 | int boxplot_cnt = 0; |
11890 | schaersvoo | 134 | int numberline_cnt = 0; |
7956 | schaersvoo | 135 | int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc */ |
8074 | schaersvoo | 136 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
7614 | schaersvoo | 137 | double angle = 0.0; |
10953 | bpr | 138 | char *rotation_center = "null"; |
11893 | schaersvoo | 139 | int use_animate = 0; /* used for jscurve / js parametric */ |
7823 | schaersvoo | 140 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
10953 | bpr | 141 | int use_slider_display = 0; /* in case of a slider, should we display its value ?*/ |
8365 | schaersvoo | 142 | size_t string_length = 0; /* measure the size of the user input fly-string */ |
143 | double stroke_opacity = 0.8; /* use some opacity as default */ |
||
14208 | schaersvoo | 144 | double fill_opacity = 0.5;/* use some opacity as default */ |
7614 | schaersvoo | 145 | char *URL = "http://localhost/images"; |
9213 | schaersvoo | 146 | char *slider_function_x = "x"; |
147 | char *slider_function_y = "y"; |
||
7614 | schaersvoo | 148 | memset(buffer,'\0',MAX_BUFFER); |
149 | void *tmp_buffer = ""; |
||
150 | /* default writing a unzipped js-include file into wims getfile directory */ |
||
151 | char *w_wims_session = getenv("w_wims_session"); |
||
12104 | schaersvoo | 152 | if( w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");} |
7614 | schaersvoo | 153 | int L0=strlen(w_wims_session) + 21; |
154 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
155 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
156 | mode_t process_mask = umask(0); /* check if file exists */ |
||
157 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
158 | if( result == 0 || errno == EEXIST ){ |
||
159 | umask(process_mask); /* be sure to set correct permission */ |
||
8224 | bpr | 160 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 161 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
12104 | schaersvoo | 162 | getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
8224 | bpr | 163 | 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 */ |
13306 | obado | 164 | /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
7614 | schaersvoo | 165 | /* now write file into getfile dir*/ |
14066 | bpr | 166 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */ |
7614 | schaersvoo | 167 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
168 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
169 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
170 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
14066 | bpr | 171 | /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */ |
172 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );} |
||
14227 | schaersvoo | 173 | char *user_agent = getenv("HTTP_USER_AGENT"); |
14230 | schaersvoo | 174 | int browser_type = 1;/* GECKO */ |
14227 | schaersvoo | 175 | if( (strcasestr(user_agent,"khtml" ) != NULL) || (strcasestr(user_agent,"opera" ) != NULL) || (strcasestr(user_agent,"trident" ) != NULL) ){ browser_type = 0; } |
7614 | schaersvoo | 176 | |
177 | /* ----------------------------------------------------- */ |
||
11997 | schaersvoo | 178 | |
7614 | schaersvoo | 179 | /* while more lines to process */ |
180 | |||
181 | while(!finished){ |
||
9329 | schaersvoo | 182 | if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
7614 | schaersvoo | 183 | type = get_token(infile); |
184 | done = FALSE; |
||
185 | /* |
||
9385 | schaersvoo | 186 | @ canvasdraw |
14415 | bpr | 187 | @ will try use the same syntax as@ 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`` (like ''frect``,''fcircle``,''ftriangle`` ...) 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)<br />non-solid filling (grid,hatch,diamond,dot,text) is provided using command <a href="#fillpattern">fillpattern a_pattern</a><br />for <a href="#filltoborder">filltoborder x0,y0,color</a> or <a href="#filltoborder">fill x0,y0,color</a> type filling (eg fill a region around x0,y0 with color until a border is encountered),<br />there are non-solid pattern fill analogues:<ul><li><a href="#gridfill">gridfill x,y,dx,dy,color</a></li><li><a href="#hatchfill">hatchfill x,y,dx,dy,color</a></li><li><a href="#diamondfill">diamondfill x,y,dx,dy,color</a></li><li><a href="#dotfill">dotfill x,y,dx,dy,color</a></li><li><a href="#textfill">textfill x,y,color,sometext_or_char</a></li></ul></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>. Commands with only numeric or colour arguments may be using a '';`` as command separator (instead of a new line). 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 <code>snaptopoints x1,y1,x2,y2,...</code></li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command <code>snaptopoints x1,y1,x2,y2,...</code></li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntax rule:<li><code>single_object x1,y1,...,color</code></li><li><code>multi_object color,x1,y1,...</code></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 <code>fontfamily</code> is <b>not</b> active for these elements</li></ul> |
14078 | bpr | 188 | @ If needed multiple interactive scripts may be used in a single webpage.<br />A function <code>read_canvas()</code> and / or <code>read_dragdrop()</code> can read all interactive userdata from these images.<br />The global array <code>canvas_scripts</code> 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 /><code>fun = eval("read_canvas"+canvas_scripts[0])</code> 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 /><code>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" 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...) ;<br /> };<br /> };<br /> };<br /> if( found_result ){return draw_reply;}else{return null;};<br />};</code> |
11006 | schaersvoo | 189 | @ 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> |
14379 | bpr | 190 | @ for usage within OEF (without anstype ''draw``), something like this (a popup function plotter) will work:<br /><code>\\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 />}</code>. |
191 | @ 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 is not wise to use older browsers...not just for canvasdraw. |
||
192 | @ 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. |
||
193 | @ 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>. Only single finger gestures are supported (for now). For more accurate user-interaction (numeric, eg keyboard driven drawings) with canvasdraw on touch devices: use the command family <a href="#userinput_xy">userinput</a>. |
||
7614 | schaersvoo | 194 | */ |
195 | switch(type){ |
||
196 | case END: |
||
197 | finished = 1; |
||
198 | done = TRUE; |
||
199 | break; |
||
200 | case 0: |
||
201 | sync_input(infile); |
||
202 | break; |
||
12063 | schaersvoo | 203 | |
204 | case CENTERED: |
||
205 | use_offset = 4; |
||
206 | /* |
||
207 | @ centered |
||
208 | @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y) |
||
14071 | bpr | 209 | @ may be used for text exactly centered on its (x;y) |
12063 | schaersvoo | 210 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
14071 | bpr | 211 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the ''drag/drop/onclick-library``) |
12107 | schaersvoo | 212 | @%centered%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
12063 | schaersvoo | 213 | */ |
214 | break; |
||
215 | |||
7614 | schaersvoo | 216 | case COMMENT: |
217 | sync_input(infile); |
||
218 | break; |
||
11806 | schaersvoo | 219 | case AFFINE: |
7614 | schaersvoo | 220 | /* |
11806 | schaersvoo | 221 | @ affine a,b,c,d,tx,ty |
222 | @ defines a transformation matrix for subsequent objects |
||
13957 | schaersvoo | 223 | @ follows the HTML5 / Canvas transformation standards<br />note: images drawn by setting skew params a & d will thus be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !! |
14066 | bpr | 224 | @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range |
14071 | bpr | 225 | @ note 1: only ''draggable`` / ''onclick`` type of objects (e.g. objects in the ''drag/drop/onclick-library``) can be transformed. |
14548 | schaersvoo | 226 | @ note 2: do not <code>drag xy</code> with tranformation / rotation objects: the mouse coordinates do not get transformed (yet) |
227 | @ note 3: ''onclick`` is supported on all transformations (mouse coordinates are corrected) |
||
14066 | bpr | 228 | @ a: Scales the drawings horizontally |
229 | @ b: Skews the drawings horizontally |
||
230 | @ c: Skews the drawings vertically |
||
231 | @ d: Scales the drawings vertically |
||
11806 | schaersvoo | 232 | @ tx: Moves the drawings horizontally in xrange coordinate system |
233 | @ ty: Moves the drawings vertically in yrange coordinate system |
||
14078 | bpr | 234 | @ the data precision may be set by preceding command ''precision int`` |
14548 | schaersvoo | 235 | (cos, sin, -sin, cos, 0, 0); |
12107 | schaersvoo | 236 | @%affine%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%fcircle 5,5,40,blue%affine 1,0,0,1,-10,-10%fcircle 5,5,40,green |
7614 | schaersvoo | 237 | */ |
11806 | schaersvoo | 238 | for(i = 0 ; i<6;i++){ |
7614 | schaersvoo | 239 | switch(i){ |
11806 | schaersvoo | 240 | case 0: double_data[0] = get_real(infile,0);break; |
241 | case 1: double_data[1] = get_real(infile,0);break; |
||
242 | case 2: double_data[2] = get_real(infile,0);break; |
||
243 | case 3: double_data[3] = get_real(infile,0);break; |
||
244 | case 4: double_data[4] = get_real(infile,0);break; |
||
245 | case 5: double_data[5] = get_real(infile,1); |
||
246 | use_affine = TRUE; |
||
247 | decimals = find_number_of_digits(precision); |
||
14548 | schaersvoo | 248 | string_length = 1 + snprintf(NULL,0, "[%.*f,%.*f,%.*f,%.*f,%d,%d]",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],(int) (double_data[4]*xsize/(xmax - xmin)),(int) (-1*double_data[5]*ysize/(ymax - ymin))); |
14208 | schaersvoo | 249 | check_string_length(string_length);affine_matrix = my_newmem(string_length); |
14548 | schaersvoo | 250 | snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%d,%d]",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],(int) (double_data[4]*xsize/(xmax - xmin)),(int) (-1*double_data[5]*ysize/(ymax - ymin))); |
251 | if( js_function[ADD_JS_TRANSFORM_MOUSE] != 1 ){ js_function[ADD_JS_TRANSFORM_MOUSE] = 1;} |
||
11806 | schaersvoo | 252 | break; |
7614 | schaersvoo | 253 | default: break; |
254 | } |
||
255 | } |
||
11806 | schaersvoo | 256 | break; |
8386 | schaersvoo | 257 | |
14394 | schaersvoo | 258 | case ALLOW_DUPLICATES: |
259 | /* |
||
14393 | schaersvoo | 260 | @ duplicates || allowdups |
261 | @ keyword (no arguments) |
||
14396 | bpr | 262 | @ only useful in case of a <a href="#multidraw">multidraw</a> student reply. |
263 | @ only useful in default <a href="#replyformat">replyformat</a> (eg in case of a not specified replyformat). |
||
264 | @ if set, duplicate (x:y) coordinates will not be removed from the student reply. |
||
265 | @ technical: a javascript variable "allow_duplicate_answer = 1;" is declared. |
||
266 | @ the default for command multidraw is : removal of duplicates. |
||
14393 | schaersvoo | 267 | */ |
268 | fprintf(js_include_file,"var allow_duplicate_answers = 1;"); |
||
269 | break; |
||
270 | |||
271 | |||
11806 | schaersvoo | 272 | case ANGLE: |
7614 | schaersvoo | 273 | /* |
11806 | schaersvoo | 274 | @ angle xc,yc,width,start_angle,end_angle,color |
275 | @ width is in x-range |
||
14208 | schaersvoo | 276 | @ angles are in degrees |
277 | @ not compatible with ''flydraw`` |
||
11806 | schaersvoo | 278 | @ will zoom in/out |
14208 | schaersvoo | 279 | @ if angle size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider |
280 | @ in case of a slider, command ''angle`` is always active ,controlled by the previous slider. |
||
12110 | schaersvoo | 281 | @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue |
14208 | schaersvoo | 282 | @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%# click on the arrow to activate slider%grid 1,1,grey%linewidth 3%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 24%centerstring red,8,click on the arrow to activate slider%slider -pi,pi,400,30,angle degrees,Rotate arrow%arrow 0,0,8,0,8,blue%fillpattern diamond%angle 0,0,4,0,0,red |
7614 | schaersvoo | 283 | */ |
11806 | schaersvoo | 284 | for(i=0;i<7;i++){ |
7614 | schaersvoo | 285 | switch(i){ |
11806 | schaersvoo | 286 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
287 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
14208 | schaersvoo | 288 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range ! */ |
289 | case 3:double_data[3] = 0.0174532925*(get_real(infile,0));break; /* start angle in degrees -> radians */ |
||
290 | case 4:double_data[4] = 0.0174532925*(get_real(infile,0));break; /* end angle in degrees -> radians */ |
||
11806 | schaersvoo | 291 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
292 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 293 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 294 | reset(); |
295 | break; |
||
7614 | schaersvoo | 296 | } |
297 | } |
||
14208 | schaersvoo | 298 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
299 | /* click_cnt++;*/ |
||
300 | |||
7614 | schaersvoo | 301 | break; |
8386 | schaersvoo | 302 | |
11806 | schaersvoo | 303 | case ANIMATE: |
7614 | schaersvoo | 304 | /* |
11930 | schaersvoo | 305 | @ animate |
11893 | schaersvoo | 306 | @ keyword |
14071 | bpr | 307 | @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code> |
11893 | schaersvoo | 308 | @ use linewidth to adjust size of the points |
14078 | bpr | 309 | @ will animate a point on -only- the next <a href='#jsplot'>jsplot/jscurve command</a>. Only a single call to <code>animate</code> is allowed...in case of multiple <code>animate</code> keywords, only the last one is valid |
13957 | schaersvoo | 310 | @ only usable for command jsplot (normal functions or parametric)<br />no other object/thing can be animated -for now |
311 | @ moves repeatedly from <a href='#xrange'>xmin to xmax</a> or in case of a parametric function from <a href='#trange'>tmin to tmax</a> |
||
14622 | schaersvoo | 312 | @ use commands <a href='#multilinewidth'>multilinewidth</a>, <a href='#multistrokecolor'>multistrokecolor or multicolors or colors</a> etc in case of multiple animated functions.<br/ >use multiple functions as argument in a single call to <a href='#jsplot'>jsplot color,fun1,fun2,fun3...fun_n</a> |
13939 | bpr | 313 | @%animate_1%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%linewidth 4%fillcolor red%animate%trange -2*pi,2*pi%linewidth 1%opacity 255,50%canvastype 100%fill 1.2,1.2,red%canvastype 101%fill -1.2,-1.2,blue%jsplot blue,7*cos(x),5*sin(2*x) |
314 | @%animate_2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%linewidth 4%fillcolor red%animate%trange -2*pi,2*pi%linewidth 1%opacity 255,50%canvastype 100%fill 1.2,1.2,red%canvastype 101%fill -1.2,-1.2,blue%multistrokecolors blue,blue,green,green,orange,orange%multilinewidth 2,2,3,3,1,1%jsplot blue,7*cos(x),5*sin(2*x),9*sin(x),5*cos(x),x^2,x |
||
7614 | schaersvoo | 315 | */ |
13512 | schaersvoo | 316 | use_animate++; |
317 | if( use_animate == 1 ){ |
||
318 | fprintf(js_include_file,"\nvar trace_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
319 | var trace_ctx = trace_canvas.getContext('2d');\ |
||
320 | trace_ctx.fillStyle = 'rgba(%s,%f)';\ |
||
321 | trace_ctx.strokeStyle = 'rgba(%s,%f)';\ |
||
322 | trace_ctx.lineWidth = %d;var anim_pos = 0;\n\ |
||
323 | function animate_this(){\ |
||
324 | var sync;\ |
||
325 | var synchrone = Math.floor(animation_steps/animation_funs);\ |
||
326 | trace_ctx.clearRect(0,0,xsize,ysize);\ |
||
327 | for(var p=0; p<animation_funs;p++){\ |
||
328 | sync = p*synchrone;\ |
||
329 | trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\ |
||
330 | };\ |
||
331 | setTimeout(function(){\ |
||
332 | requestAnimationFrame(animate_this); anim_pos++;}, 50\ |
||
333 | );\ |
||
334 | if(anim_pos >= animation_steps){anim_pos = 0;};\ |
||
335 | };",canvas_root_id,ANIMATE_CANVAS,fill_color,fill_opacity,stroke_color,stroke_opacity,line_width,line_width,line_width,2*line_width,2*line_width); |
||
336 | } |
||
337 | else |
||
338 | { |
||
13514 | schaersvoo | 339 | canvas_error("animate can only be used once<br />multiple curves may be animated using something like:<br />jsplot red,sin(x),cos(x),x^2,sin(2*x)"); |
13512 | schaersvoo | 340 | } |
7614 | schaersvoo | 341 | break; |
8386 | schaersvoo | 342 | |
11806 | schaersvoo | 343 | case ARC: |
7614 | schaersvoo | 344 | /* |
11997 | schaersvoo | 345 | @ arc xc,yc,x-width,y-height,start_angle,end_angle,color |
14208 | schaersvoo | 346 | @ can not be set ''onclick`` or ''drag xy`` |
347 | @ compatible with ''flydraw`` |
||
348 | @ attention: width & height in x/y-range |
||
349 | @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a> |
||
12110 | schaersvoo | 350 | @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red%zoom blue |
13961 | schaersvoo | 351 | @%arc_filled%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%filled%fillcolor green%arc 0,0,4,4,10,135,red |
7614 | schaersvoo | 352 | */ |
11806 | schaersvoo | 353 | for(i=0;i<7;i++){ |
354 | switch(i){ |
||
355 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
356 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
357 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */ |
||
358 | case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */ |
||
359 | case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */ |
||
360 | case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */ |
||
361 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
||
362 | /* in Shape library: |
||
363 | x[0] = x[1] = xc = double_data[0] |
||
364 | y[0] = y[1] = yc = double_data[1] |
||
365 | w[0] = width = double_data[2] |
||
366 | w[1] = height = double_data[3] |
||
367 | h[0] = start_angle = double_data[4] |
||
368 | h[1] = end_angle = double_data[5] |
||
369 | */ |
||
370 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 371 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 372 | reset(); |
373 | break; |
||
374 | } |
||
14208 | schaersvoo | 375 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
376 | /* click_cnt++;*/ |
||
377 | |||
11806 | schaersvoo | 378 | } |
7614 | schaersvoo | 379 | break; |
11806 | schaersvoo | 380 | case ARROW: |
7614 | schaersvoo | 381 | /* |
11806 | schaersvoo | 382 | @ arrow x1,y1,x2,y2,h,color |
14071 | bpr | 383 | @ alternative: <code>vector</code> |
14379 | bpr | 384 | @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color`` |
14077 | bpr | 385 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
9406 | schaersvoo | 386 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13957 | schaersvoo | 387 | @%arrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%arrow 0,0,4,3,8,blue%drag xy%arrow 0,0,-4,3,8,green%drag xy%arrow 0,0,4,-3,8,orange%drag xy%arrow 0,0,-4,-3,8,cyan |
388 | @%arrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%arrow 0,0,4,4,8,blue%onclick%arrow 0,0,-4,5,8,green%onclick%arrow 0,0,4,-6,8,orange%onclick%arrow 0,0,-4,-2,8,cyan |
||
7614 | schaersvoo | 389 | */ |
11806 | schaersvoo | 390 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 391 | switch(i){ |
392 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
393 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 394 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
395 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
396 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
397 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
7614 | schaersvoo | 398 | decimals = find_number_of_digits(precision); |
14208 | schaersvoo | 399 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
400 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 401 | /* click_cnt++;*/ |
402 | reset(); |
||
403 | break; |
||
404 | } |
||
405 | } |
||
406 | break; |
||
8386 | schaersvoo | 407 | |
11806 | schaersvoo | 408 | case ARROWS: |
7614 | schaersvoo | 409 | /* |
11806 | schaersvoo | 410 | @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n |
14071 | bpr | 411 | @ alternative: <code>vectors</code> |
14380 | bpr | 412 | @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``. |
14071 | bpr | 413 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
11806 | schaersvoo | 414 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13957 | schaersvoo | 415 | @%arrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2% |
416 | @%arrows_drag%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2% |
||
14208 | schaersvoo | 417 | @%arrows_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click arrow(s) to activate %slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2% |
7614 | schaersvoo | 418 | */ |
419 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
420 | fill_color = stroke_color; |
||
11806 | schaersvoo | 421 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 422 | i=0; |
423 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 424 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 425 | if(i%2 == 0 ){ |
426 | double_data[i] = get_real(infile,0); /* x */ |
||
427 | } |
||
428 | else |
||
429 | { |
||
430 | double_data[i] = get_real(infile,1); /* y */ |
||
431 | } |
||
432 | i++; |
||
433 | } |
||
434 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 435 | for(c = 0 ; c < i-1 ; c = c+4){ |
14208 | schaersvoo | 436 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
437 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 438 | /* click_cnt++; */ |
7614 | schaersvoo | 439 | } |
440 | reset(); |
||
441 | break; |
||
8386 | schaersvoo | 442 | |
11806 | schaersvoo | 443 | case ARROW2: |
7614 | schaersvoo | 444 | /* |
11806 | schaersvoo | 445 | @ arrow2 x1,y1,x2,y2,h,color |
14071 | bpr | 446 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color`` |
447 | @ use command <code>arrowhead int</code> to adjust the arrow head size |
||
448 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
||
9406 | schaersvoo | 449 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 450 | @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue% |
7614 | schaersvoo | 451 | */ |
11806 | schaersvoo | 452 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 453 | switch(i){ |
454 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
455 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 456 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
457 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
458 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
459 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
460 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 461 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
462 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 463 | /* click_cnt++;*/ |
464 | reset(); |
||
465 | break; |
||
466 | } |
||
467 | } |
||
468 | break; |
||
8386 | schaersvoo | 469 | |
11806 | schaersvoo | 470 | case ARROWS2: |
7614 | schaersvoo | 471 | /* |
11806 | schaersvoo | 472 | @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n |
14071 | bpr | 473 | @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color`` |
474 | @ use command <code>linewidth int</code> to adjust thickness of the arrows |
||
11806 | schaersvoo | 475 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12107 | schaersvoo | 476 | @%arrows2%size 400,400%xrange -10,10%yrange -10,10%onclick%arrows2 red,8,0,0,4,3,1,1,2,4,2,2,-2,4,3,3,-3,-4,0,0,3,-2% |
7614 | schaersvoo | 477 | */ |
478 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
479 | fill_color = stroke_color; |
||
11806 | schaersvoo | 480 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 481 | i=0; |
482 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 483 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 484 | if(i%2 == 0 ){ |
485 | double_data[i] = get_real(infile,0); /* x */ |
||
486 | } |
||
487 | else |
||
488 | { |
||
489 | double_data[i] = get_real(infile,1); /* y */ |
||
490 | } |
||
491 | i++; |
||
492 | } |
||
8224 | bpr | 493 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 494 | for(c = 0 ; c < i-1 ; c = c+4){ |
14208 | schaersvoo | 495 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
496 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 497 | /* click_cnt++; */ |
11806 | schaersvoo | 498 | |
7614 | schaersvoo | 499 | } |
500 | reset(); |
||
501 | break; |
||
11806 | schaersvoo | 502 | case ARROWHEAD: |
9427 | schaersvoo | 503 | /* |
11806 | schaersvoo | 504 | @ arrowhead int |
505 | @ default 8 (pixels) |
||
9427 | schaersvoo | 506 | */ |
11806 | schaersvoo | 507 | arrow_head = (int) (get_real(infile,1)); |
508 | break; |
||
509 | |||
510 | case AUDIO: |
||
511 | /* |
||
512 | @ audio x,y,w,h,loop,visible,audiofile location |
||
14066 | bpr | 513 | @ x,y: left top corner of audio element (in xrange / yrange) |
514 | @ w,y: width and height in pixels |
||
515 | @ loop: 0 or 1 ( 1 = loop audio fragment) |
||
516 | @ visible: 0 or 1 (1 = show controls) |
||
11806 | schaersvoo | 517 | @ audio format may be in *.mp3 or *.ogg |
14066 | bpr | 518 | @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format) |
519 | @ if you are using *.ogg: be aware that Microsoft based systems not support it natively |
||
11806 | schaersvoo | 520 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
521 | */ |
||
522 | if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;} |
||
523 | for(i=0;i<7;i++){ |
||
524 | switch(i){ |
||
525 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
526 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
527 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
528 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
529 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
530 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
531 | case 6: |
||
532 | temp = get_string(infile,1); |
||
533 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
534 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
14208 | schaersvoo | 535 | string_length = 1 + 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); |
536 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 537 | 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); |
538 | add_to_buffer(tmp_buffer); |
||
539 | break; |
||
540 | default:break; |
||
9427 | schaersvoo | 541 | } |
11806 | schaersvoo | 542 | } |
543 | reset(); |
||
544 | break; |
||
545 | |||
546 | |||
547 | case AXIS_NUMBERING: |
||
548 | /* |
||
549 | @ axisnumbering |
||
550 | @ keyword (no arguments required) |
||
14246 | bpr | 551 | @ for special numbering of x-axis or y-axis see grid related commands <a href="#axis">axis</a> <a href="#xaxis">xaxis</a>, <a href="#xaxisup">xaxisup</a>, <a href="#noxaxis">noxaxis</a>, <a href="#yaxis">yaxis</a>, <a href="#yaxisup">yaxisup</a>, <a href="#noyaxis">noyaxis</a> |
11806 | schaersvoo | 552 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
553 | */ |
||
11891 | schaersvoo | 554 | use_axis_numbering++; |
11806 | schaersvoo | 555 | break; |
556 | case AXIS: |
||
557 | /* |
||
558 | @ axis |
||
559 | @ keyword (no arguments required) |
||
560 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
561 | |||
562 | */ |
||
563 | use_axis = TRUE; |
||
564 | break; |
||
565 | |||
566 | case BARCHART: |
||
567 | /* |
||
568 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
14066 | bpr | 569 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
570 | @ 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> |
||
571 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
11806 | schaersvoo | 572 | @ multiple barchart command may be used in a single script |
14066 | bpr | 573 | @ also see command <a href='#piechart'>piechart</a> |
574 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
||
12107 | schaersvoo | 575 | @%barchart%size 400,400%xrange -1,10%yrange -2,14%legend legend Z:legend A:this is B:C:D:E:F:G:H:X%legendcolors green:red:orange:lightblue:cyan:gold:purple:darkred:yellow:lightgreen%xaxis 0:Z:1:A:2:B:3:C:4:D:5:E:6:F:7:G:8:H:9:X%noyaxis%precision 1%fontfamily bold 15px Ariel%grid 1,1,white%barchart 0:5.5:green:2:5.5:red:4:6.5:orange:6:8:lightblue:8:11:cyan:1:5.5:gold:3:9:purple:5:4:darkred:7:7:yellow:9:1:lightgreen%mouse red,14 |
11806 | schaersvoo | 576 | */ |
577 | temp = get_string(infile,1); |
||
578 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
579 | fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp); |
||
580 | barchart_cnt++; |
||
581 | reset(); |
||
582 | break; |
||
583 | |||
584 | case BEZIER: |
||
585 | /* |
||
586 | @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end |
||
587 | @ draw a bezier curve between points, starting from (x_start:y_start) |
||
588 | @ can <b>not</b> be dragged or set onclick |
||
589 | */ |
||
590 | if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;} |
||
591 | decimals = find_number_of_digits(precision); |
||
592 | for(i = 0 ; i < 9; i++){ |
||
593 | switch(i){ |
||
594 | case 0: stroke_color = get_color(infile,0);break; |
||
595 | case 1: double_data[0] = get_real(infile,0);break;/* start x */ |
||
596 | case 2: double_data[1] = get_real(infile,0);break;/* start y */ |
||
597 | case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */ |
||
598 | case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */ |
||
599 | case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */ |
||
600 | case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */ |
||
601 | case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */ |
||
602 | case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */ |
||
14208 | schaersvoo | 603 | string_length = 1 + 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); |
604 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 605 | 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); |
606 | add_to_buffer(tmp_buffer); |
||
607 | break; |
||
608 | default: break; |
||
9427 | schaersvoo | 609 | } |
610 | } |
||
611 | reset(); |
||
612 | break; |
||
11806 | schaersvoo | 613 | |
614 | |||
615 | case BGCOLOR: |
||
9427 | schaersvoo | 616 | /* |
11806 | schaersvoo | 617 | @ bgcolor colorname or #hex |
618 | @ use this color as background of the "div" containing the canvas(es) |
||
12110 | schaersvoo | 619 | @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue |
9427 | schaersvoo | 620 | */ |
11806 | schaersvoo | 621 | /* [255,255,255]*/ |
622 | bgcolor = get_string(infile,1); |
||
623 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
624 | int found = 0; |
||
625 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
626 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
627 | bgcolor = colors[i].hex; |
||
628 | found = 1; |
||
629 | break; |
||
630 | } |
||
9427 | schaersvoo | 631 | } |
14066 | bpr | 632 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");} |
11806 | schaersvoo | 633 | } |
13970 | obado | 634 | fprintf(js_include_file,"/* set background color of canvas div */\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity); |
11806 | schaersvoo | 635 | break; |
636 | |||
637 | case BGIMAGE: |
||
638 | /* |
||
639 | @ bgimage image_location |
||
14071 | bpr | 640 | @ use an image as background; technical: we use the background of ''canvas_div`` |
11806 | schaersvoo | 641 | @ the background image will be resized to match "width = xsize" and "height = ysize" |
12110 | schaersvoo | 642 | @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif |
11806 | schaersvoo | 643 | */ |
644 | URL = get_string(infile,1); |
||
13970 | obado | 645 | 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); |
11806 | schaersvoo | 646 | break; |
647 | |||
648 | case BLINK: |
||
649 | /* |
||
650 | @ blink time(seconds) |
||
651 | @ NOT IMPLEMETED -YET |
||
652 | */ |
||
653 | break; |
||
654 | |||
655 | case BOXPLOT: |
||
656 | /* |
||
657 | @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max |
||
14066 | bpr | 658 | @ example:<br /><code>xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8 |
659 | @ example:<br /><code>xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8 |
||
660 | @ 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 |
||
661 | @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern. |
||
662 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours |
||
14379 | bpr | 663 | @ use command <a href='#legend'>legend</a> to automatically create a legend <br />unicode allowed in legend<br />use command <a href='#fontfamily'>fontfamily</a> to set the font of the legend. |
11806 | schaersvoo | 664 | @ there is no limit to the number of boxplots used. |
14078 | bpr | 665 | @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet |
14066 | bpr | 666 | @ 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) |
667 | @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means. |
||
668 | @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date |
||
12110 | schaersvoo | 669 | @%boxplot_1%size 400,400%xrange 0,300%yrange 0,10%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot x,4,8,120,160,170,220,245 |
670 | @%boxplot_2%size 400,400%xrange 0,10%yrange 0,300%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot y,4,8,120,160,170,220,245 |
||
13958 | schaersvoo | 671 | @%boxplot_3%size 400,400%xrange 0,100%yrange 0,10%fillpattern hatch%linewidth 3%fillcolor red%strokecolor green%boxplot x,1,2,4,14,27,39,66%strokecolor blue%boxplot x,1,4,15,45,50,66,87%strokecolor red%boxplot x,1,6,45,70,80,90,100%strokecolor orange%boxplot x,1,8,28,38,48,56,77%mouse red,16 |
11806 | schaersvoo | 672 | */ |
673 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
674 | for(i=0;i<8;i++){ |
||
675 | switch(i){ |
||
676 | case 0: temp = get_string_argument(infile,0); |
||
677 | if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */ |
||
678 | case 1: double_data[0] = get_real(infile,0);break;/* height | width */ |
||
679 | case 2: |
||
680 | if( js_function[DRAW_JSBOXPLOT] == 0 ){ |
||
681 | double_data[1] = get_real(infile,0); |
||
682 | fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */ |
||
683 | } |
||
684 | else |
||
685 | { |
||
686 | double_data[1] = get_real(infile,1); |
||
687 | double_data[2] = 1; |
||
688 | double_data[3] = 1; |
||
689 | double_data[4] = 1; |
||
690 | double_data[5] = 1; |
||
691 | double_data[6] = 1; |
||
692 | double_data[7] = 1; |
||
693 | i=8; |
||
694 | } |
||
695 | break;/* center value x or y */ |
||
696 | case 3: double_data[2] = get_real(infile,0); break;/* min */ |
||
697 | case 4: double_data[3] = get_real(infile,0); break;/* Q1 */ |
||
698 | case 5: double_data[4] = get_real(infile,0); break;/* median */ |
||
699 | case 6: double_data[5] = get_real(infile,0); break;/* Q3 */ |
||
700 | case 7: double_data[6] = get_real(infile,1); break;/* max */ |
||
701 | default:break; |
||
9427 | schaersvoo | 702 | } |
703 | } |
||
704 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 705 | /*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)*/ |
14208 | schaersvoo | 706 | string_length = 1 + 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_CANVAS+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]); |
11806 | schaersvoo | 707 | check_string_length(string_length); |
14208 | schaersvoo | 708 | tmp_buffer = my_newmem(string_length); |
11806 | schaersvoo | 709 | 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_CANVAS+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]); |
710 | add_to_buffer(tmp_buffer); |
||
711 | boxplot_cnt++; |
||
712 | reset(); |
||
713 | break; |
||
714 | case BOXPLOTDATA: |
||
715 | /* |
||
716 | @ boxplotdata some_data |
||
14388 | bpr | 717 | @ ''some_data``are a list of numbers separated by a comma "," (items) |
14071 | bpr | 718 | @ only be used before command <code>boxplot</code>: the command <a href="#boxplot">boxplot</a> will provide the boxplot drawing of the data. |
11806 | schaersvoo | 719 | @ 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 |
720 | @ note: wims will not check your data input | format. use js-error console to debug any problems. |
||
14071 | bpr | 721 | @ a javascript function <code>statistics()</code> will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function. |
722 | @ only a single call to <code>boxplotdata</code> can be made. If multiple boxplots should be present in a single canvas, then use multiple calls to command <a href='#boxplot'>boxplot</a> |
||
13959 | bpr | 723 | @%boxplotdata%size 400,400%xrange 0,100%yrange 0,10%strokecolor orange%fillpattern hatch%linewidth 3%strokecolor green%boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23%boxplot x,2,2%mouse red,16 |
11806 | schaersvoo | 724 | */ |
725 | if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;} |
||
726 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
727 | fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1)); |
||
728 | |||
729 | break; |
||
730 | |||
731 | case CANVASTYPE: |
||
732 | canvas_type = (int) (get_real(infile,1)); |
||
733 | /* |
||
734 | @ canvastype TYPE |
||
14246 | bpr | 735 | @ for now only useful before commands filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled |
11806 | schaersvoo | 736 | @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas) |
737 | @ use another TYPE, if you know what you are doing... |
||
14246 | bpr | 738 | @ other possible canvasses (transparent PNG pictures xsize x ysize on top of each other)<ul><li> EXTERNAL_IMAGE_CANVAS 0</li><li> BG_CANVAS 1</li><li> STATIC_CANVAS 2</li><li> MOUSE_CANVAS 3</li><li> GRID_CANVAS 4</li><li> DRAG_CANVAS 5</li><li> DRAW_CANVAS 6</li><li> TEXT_CANVAS 7</li><li> CLOCK_CANVAS 8</li><li> ANIMATE_CANVAS 9</li><li> TRACE_CANVAS 10</li><li>BOXPLOT_CANVAS 11</li><li> JSPLOT_CANVAS 100, will increase with every call</li><li> FILL_CANVAS 200, will increase with every call</li><li> USERDRAW_JSPLOT 300, will increase with every call</li><li>CLICKFILL_CANVAS 400, will increase with every call/click</li><li>BOXPLOT_CANVAS 500, will increase with every call</li></ul> |
11806 | schaersvoo | 739 | */ |
740 | break; |
||
741 | |||
742 | case CENTERSTRING: |
||
743 | /* |
||
744 | @ centerstring color,y-value,the text string |
||
745 | @ title color,y-value,the text string |
||
746 | @ draw a string centered on the canvas at y = y-value |
||
14071 | bpr | 747 | @ can not be set ''onclick`` or ''drag xy`` (...) |
14162 | bpr | 748 | @ unicode supported: <code>centerstring red,5,\\u2232</code> |
14071 | bpr | 749 | @ use a command like <code>fontfamily italic 24pt Ariel</code> to set fonts on browser that support font change |
12110 | schaersvoo | 750 | @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center |
11806 | schaersvoo | 751 | */ |
752 | if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;} |
||
753 | for(i=0;i<3;i++){ |
||
754 | switch(i){ |
||
755 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
756 | case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/ |
||
757 | case 2: temp = get_string_argument(infile,1); |
||
758 | /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */ |
||
759 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 760 | string_length = 1 + snprintf(NULL,0, |
11806 | schaersvoo | 761 | "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
14208 | schaersvoo | 762 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
11806 | schaersvoo | 763 | 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); |
764 | add_to_buffer(tmp_buffer); |
||
765 | break; |
||
766 | default:break; |
||
767 | } |
||
9427 | schaersvoo | 768 | } |
769 | break; |
||
8386 | schaersvoo | 770 | |
11806 | schaersvoo | 771 | |
8386 | schaersvoo | 772 | case CIRCLE: |
8299 | schaersvoo | 773 | /* |
8386 | schaersvoo | 774 | @ circle xc,yc,width (2*r in pixels),color |
14388 | bpr | 775 | @ alernative: use command <code>fcircle xc,yc,d,color</code> for a filled circle. |
776 | @ use command <code>fillcolor color</code> to set the fillcolor. |
||
14071 | bpr | 777 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> |
14388 | bpr | 778 | @ will shrink / expand on zoom out / zoom in. |
12110 | schaersvoo | 779 | @%circle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circle 0,0,60,red%zoom red |
8299 | schaersvoo | 780 | */ |
8386 | schaersvoo | 781 | for(i=0;i<4;i++){ |
782 | switch(i){ |
||
783 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
784 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
14066 | bpr | 785 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/ |
8386 | schaersvoo | 786 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
787 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 788 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
789 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8386 | schaersvoo | 790 | /* click_cnt++;*/ |
791 | reset(); |
||
792 | break; |
||
793 | default : break; |
||
794 | } |
||
795 | } |
||
796 | break; |
||
797 | |||
798 | case CIRCLES: |
||
799 | /* |
||
800 | @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n |
||
9383 | schaersvoo | 801 | @ <b>attention</b> r = radius in x-range (!) |
14071 | bpr | 802 | @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles |
14066 | bpr | 803 | @ alternative: disks for filled circles |
14071 | bpr | 804 | @ use command <code>fillcolor color</code> to set the fillcolor |
805 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually) |
||
8386 | schaersvoo | 806 | @ will shrink / expand on zoom out / zoom in |
14208 | schaersvoo | 807 | @%circles_drag%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red |
808 | @%circles_onclick%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%onclick%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red |
||
809 | @%circles_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click circles(s) to activate%opacity 200,50%fillcolor orange%rotationcenter 2,3%slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%fcircles blue,0,0,0.5,2,2,1,-3,-3,1.5,3,3,0.5,3,-4,0.5 |
||
8386 | schaersvoo | 810 | */ |
8299 | schaersvoo | 811 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
812 | fill_color = stroke_color; |
||
8386 | schaersvoo | 813 | i=1; |
8299 | schaersvoo | 814 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 815 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 816 | switch (i%3){ |
817 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
818 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
819 | case 0:double_data[i-1] = get_real(infile,1);break; /* r */ |
||
8299 | schaersvoo | 820 | } |
821 | i++; |
||
822 | } |
||
823 | decimals = find_number_of_digits(precision); |
||
8386 | schaersvoo | 824 | for(c = 0 ; c < i-1 ; c = c+3){ |
14208 | schaersvoo | 825 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
826 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8386 | schaersvoo | 827 | /* click_cnt++; */ |
8299 | schaersvoo | 828 | } |
829 | reset(); |
||
830 | break; |
||
11806 | schaersvoo | 831 | case CLEARBUTTON: |
832 | /* |
||
833 | @ clearbutton value |
||
14071 | bpr | 834 | @ alternative: <code>delete</code> |
835 | @ alternative: <code>erase</code> |
||
14388 | bpr | 836 | @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value``. |
837 | @ <b>attention</b> command <code>clearbutton</code> is incompatible with <a href="#multidraw">multidraw</a> based drawings (in <code>multidraw</code>, there is a remove_object_button for every draw primitive). |
||
838 | @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on a point of the object to remove this specific object...this clear button will remove all drawings |
||
14071 | bpr | 839 | @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code> |
14066 | bpr | 840 | @ use command <a href="#inputstyle">inputstyle</a> to style the button... |
14388 | bpr | 841 | @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script to change the style of all ''clearbutton`` of all included canvasdraw scripts, use something like<br /><code>if(document.getElementById("clearbutton"+canvas_scripts[0])){<br /> var p = 0;<br /> while(document.getElementById("clearbutton"+canvas_scripts[p])){<br /> document.getElementById("clearbutton"+canvas_scripts[p]).className="some_class_name";<br /> <!−−</code> or <code>document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); −−><br /> p++;<br /> };<br />};</code> |
13935 | bpr | 842 | @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All |
11806 | schaersvoo | 843 | */ |
844 | if(reply_format == 29){/* eg multidraw is selected */ |
||
14054 | schaersvoo | 845 | // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw"); |
11806 | schaersvoo | 846 | } |
847 | add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1)); |
||
848 | break; |
||
8386 | schaersvoo | 849 | |
11806 | schaersvoo | 850 | case CLOCK: |
7614 | schaersvoo | 851 | /* |
11806 | schaersvoo | 852 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
14071 | bpr | 853 | @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency |
14066 | bpr | 854 | @ type hourglass:<br />type = 0: only segments<br />type = 1: only numbers<br />type = 2: numbers and segments |
11806 | schaersvoo | 855 | @ 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 |
856 | @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass... |
||
14162 | bpr | 857 | @ 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> |
11806 | schaersvoo | 858 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
859 | @ no combinations with other reply_types allowed, for now |
||
14077 | bpr | 860 | @ 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 |
861 | @ note: 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 |
||
14066 | bpr | 862 | @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a> |
12110 | schaersvoo | 863 | @%clock_1%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black |
864 | @%clock_2%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black |
||
865 | @%clock_3%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,3,15,65,2,2,red,green,blue,lightgrey,black |
||
866 | @%clock_4%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black |
||
867 | @%clock_5%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black |
||
868 | @%clock_6%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,8,55,15,2,2,red,green,blue,lightgrey,black |
||
869 | @%clock_7%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,2,0,red,green,blue,lightgrey,black |
||
7614 | schaersvoo | 870 | */ |
11806 | schaersvoo | 871 | if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;} |
872 | |||
873 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
874 | for(i=0;i<9;i++){ |
||
875 | switch(i){ |
||
876 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
877 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
878 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
879 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
880 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
881 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
882 | 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 */ |
||
883 | case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/ |
||
884 | switch(int_data[7]){ |
||
885 | case 0:break; |
||
886 | case 1:if(clock_cnt == 0){ |
||
887 | if( reply_format == 0 ){ |
||
888 | reply_format = 18; /* user sets clock */ |
||
14208 | schaersvoo | 889 | /* string_length = 1 + 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"); |
890 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 891 | 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"); |
892 | add_to_buffer(tmp_buffer); |
||
893 | */ |
||
894 | 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"); |
||
895 | } |
||
896 | else |
||
897 | { |
||
898 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
899 | } |
||
900 | } |
||
901 | 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); |
||
902 | break; |
||
903 | case 3:if(clock_cnt == 0){ |
||
904 | if( reply_format == 0 ){ |
||
905 | reply_format = 18; /* user sets clock */ |
||
906 | 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"); |
||
907 | } |
||
908 | else |
||
909 | { |
||
910 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
911 | } |
||
912 | } |
||
913 | /* |
||
914 | 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); |
||
915 | */ |
||
916 | break; |
||
917 | case 2:if( reply_format == 0 ){ |
||
918 | reply_format = 19; /* "onclick */ |
||
13970 | obado | 919 | 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"); |
11806 | schaersvoo | 920 | } |
921 | else |
||
922 | { |
||
923 | if( reply_format != 19){ |
||
924 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
||
925 | } |
||
926 | } |
||
927 | break; |
||
928 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
929 | } |
||
930 | break; |
||
931 | case 8: |
||
14078 | bpr | 932 | if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */ |
11806 | schaersvoo | 933 | fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity); |
934 | } |
||
935 | temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/ |
||
936 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
937 | else{ |
||
938 | /* h_color,m_color,s_color,bg_color,fg_color */ |
||
11991 | schaersvoo | 939 | temp = ",black\",\"black\",\"black\",\"white\",\"black";} |
14208 | schaersvoo | 940 | string_length = 1 + 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); |
941 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 942 | 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); |
943 | add_to_buffer(tmp_buffer); |
||
944 | fprintf(js_include_file,"var clocks%d;",clock_cnt); |
||
945 | clock_cnt++; |
||
946 | break; |
||
947 | default:break; |
||
948 | } |
||
949 | } |
||
950 | break; |
||
951 | |||
952 | |||
953 | case COLORPALETTE: |
||
954 | /* |
||
955 | @ colorpalette color_name_1,color_name_2,...,color_name_8 |
||
956 | @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a> |
||
14066 | bpr | 957 | @ can be used with command <a href='#userdraw'>userdraw clickfill,color</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the pupil can choose from the given colors by clicking small coloured buttons.<br /> the click coordinates and corresponding fillcolor will be stored in read_canvas()...when using the appropriate replyformat.<br />the first color of the palette is color=0 |
14077 | bpr | 958 | @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a> |
11806 | schaersvoo | 959 | */ |
960 | if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");} |
||
961 | fprintf(js_include_file,"var multifillcolors = [];var palettecolors = ["); |
||
962 | while( ! done ){ |
||
963 | temp = get_color(infile,1); |
||
964 | fprintf(js_include_file,"\"%s\",",temp); |
||
965 | } |
||
966 | fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */ |
||
967 | add_color_palette(js_include_file,canvas_root_id,input_style); |
||
968 | break; |
||
13829 | bpr | 969 | |
11806 | schaersvoo | 970 | case COPY: |
971 | /* |
||
972 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
973 | @ The image may be "bitmap" or "SVG" |
||
974 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
975 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
976 | @ [filename] is the URL of the image |
||
14388 | bpr | 977 | @ URL is normal URL of network reachable image file location (eg special url for ''classexo`` not -yet- implemented) |
978 | @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable. Javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images. 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 <code>snaptopoints x1,y1,x2,y2...</code>. |
||
14385 | bpr | 979 | @ 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 |
14077 | bpr | 980 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc) |
11806 | schaersvoo | 981 | @ you may draw / userdraw / drag other stuff on top of an "imported" image |
14388 | bpr | 982 | @ when set draggable, there will be special function <code>read_canvas_images()</code> now dragging external images may be combined with <code>read_canvas()</code> from <a href='#userdraw'>userdraw</a> or <a href='#multidraw'>multidraw</a>. Set command <a href='#precision'>precision</a> before command ''copy``<br />note: when dragging the image anchor is the center of the picture, this cannot be changed (it is a feature and not a flaw!) |
14077 | bpr | 983 | @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates. |
13967 | schaersvoo | 984 | @%copy_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%onclick%copy 5,5,-1,-1,-1,-1,gifs/en.gif%onclick%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%onclick%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif |
14066 | bpr | 985 | @%copy_drag_xy%size 400,400%xrange -10,10%yrange -10,10%# attention: left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%drag xy%copy 5,5,-1,-1,-1,-1,gifs/en.gif%drag xy%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%drag xy%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif |
986 | @%copy_drag_xy_snaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%# attention: left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%# a function read_canvas_images() %copy -6,6,-1,-1,-1,-1,gifs/fr.gif%snaptogrid%drag xy%copy 6,6,-1,-1,-1,-1,gifs/en.gif%snaptogrid%drag xy%copy 6,-6,-1,-1,-1,-1,gifs/it.gif%snaptogrid%drag xy%copy -6,-6,-1,-1,-1,-1,gifs/cn.gif |
||
11806 | schaersvoo | 987 | */ |
988 | for(i = 0 ; i<7;i++){ |
||
7614 | schaersvoo | 989 | switch(i){ |
11806 | schaersvoo | 990 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range */ |
991 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */ |
||
992 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
||
993 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
994 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
995 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
996 | case 6: URL = get_string(infile,1); |
||
997 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
||
998 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
999 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
1000 | int_data[9] = click_cnt; |
||
1001 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
14038 | schaersvoo | 1002 | //if( reply_format == 0 ){ reply_format = 20; } |
11806 | schaersvoo | 1003 | int_data[8] = 2;/* drag & drop */ |
14044 | schaersvoo | 1004 | if(use_offset == 0 ){use_offset = 4;} /* mouse is attached to the center of the image !! */ |
11806 | schaersvoo | 1005 | } |
1006 | else |
||
1007 | { |
||
1008 | if( onclick == 1 ){ |
||
14038 | schaersvoo | 1009 | // reply_format = 20; |
11806 | schaersvoo | 1010 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
1011 | click_cnt++; /* will also be used in dragstuff ! */ |
||
1012 | } |
||
1013 | else |
||
1014 | { |
||
1015 | int_data[8] = 0; /* just static image */ |
||
1016 | } |
||
1017 | } |
||
14038 | schaersvoo | 1018 | if( include_special_OEF_reply == FALSE){ |
1019 | if( int_data[8] == 1 || int_data[8] == 2 ){ |
||
1020 | include_special_OEF_reply = TRUE; |
||
1021 | fprintf(js_include_file,"\ |
||
1022 | \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\ |
||
1023 | read_canvas_images = function(){\ |
||
1024 | var prec = %d;\ |
||
1025 | var len = ext_drag_images.length;\ |
||
1026 | var reply = new Array(len);\ |
||
1027 | for(var p = 0 ; p < len ; p++){\ |
||
1028 | var img = ext_drag_images[p];\ |
||
1029 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
||
1030 | };\ |
||
1031 | return reply;\ |
||
1032 | };\n\ |
||
14062 | schaersvoo | 1033 | /* end function 34 read_canvas_images() */",reply_precision); |
14038 | schaersvoo | 1034 | } |
1035 | } |
||
11806 | schaersvoo | 1036 | /* |
14062 | schaersvoo | 1037 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\ |
11806 | schaersvoo | 1038 | */ |
14208 | schaersvoo | 1039 | string_length = 1 + snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%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],use_offset,use_snap); |
1040 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
14044 | schaersvoo | 1041 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%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],use_offset,use_snap); |
14038 | schaersvoo | 1042 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1043 | drag_type = -1; /* reset the drag_type indicator */ |
1044 | ext_img_cnt++; |
||
1045 | onclick=0; |
||
14038 | schaersvoo | 1046 | use_offset=0; |
1047 | reset(); |
||
11806 | schaersvoo | 1048 | break; |
7614 | schaersvoo | 1049 | default: break; |
1050 | } |
||
1051 | } |
||
1052 | break; |
||
11806 | schaersvoo | 1053 | /* |
1054 | HTML5 specs: |
||
1055 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1056 | img Specifies the image, canvas, or video element to use |
||
14066 | bpr | 1057 | sx The x coordinate where to start clipping: x1 = int_data[0] |
1058 | sy The y coordinate where to start clipping: x2 = int_data[1] |
||
1059 | swidth The width of the clipped image: int_data[2] - int_data[0] |
||
1060 | sheight The height of the clipped image: int_data[3] - int_data[1] |
||
1061 | x The x coordinate where to place the image on the canvas: dx1 = int_data[4] |
||
1062 | y The y coordinate where to place the image on the canvas: dy1 = int_data[5] |
||
1063 | width The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6] |
||
1064 | height The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7] |
||
11806 | schaersvoo | 1065 | */ |
1066 | case COPYRESIZED: |
||
1067 | /* |
||
14385 | bpr | 1068 | @ copyresized x1,y1,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
11806 | schaersvoo | 1069 | @ The image may be any "bitmap" or "SVG" |
1070 | @ 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 |
||
14066 | bpr | 1071 | @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image |
11806 | schaersvoo | 1072 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
14562 | bpr | 1073 | @ URL is normal URL of network reachable image file location (as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif', eg no special wims paths are searched !!) |
14385 | bpr | 1074 | @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable. Javascript <code>function read_canvas();</code> will return the x/y coordinate data in xrange/yrange of all -including non draggable- images. The command drag is only valid for the next image. Draggable / non-draggable images may be mixed. May be used together with preceding keywords ''snaptogrid``, ''xsnaptogrid``, ''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code> |
14380 | bpr | 1075 | @ 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 |
14562 | bpr | 1076 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines, curves etc). |
14380 | bpr | 1077 | @ you may draw / userdraw / drag stuff on top of an "imported" image. |
1078 | @ when set draggable, there will be special function 'read_canvas_images()'<br />now dragging external images may be combined with 'read_canvas()' from <a href='#userdraw'>userdraw</a> or <a href='#multidraw'>multidraw</a><br />set command <a href='#precision'>precision</a> before command ''copy``. |
||
1079 | @ use keyword <a href='#centered'>centered</a> before command ''copyresized`` to place image center at given coordinates. |
||
11806 | schaersvoo | 1080 | */ |
1081 | for(i = 0 ; i<9;i++){ |
||
1082 | switch(i){ |
||
1083 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
1084 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
1085 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
1086 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
1087 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
1088 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
1089 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
1090 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
1091 | case 8: URL = get_string(infile,1); |
||
1092 | /* flag error when wrong diagonal: copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */ |
||
1093 | if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){ |
||
1094 | canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! "); |
||
1095 | } |
||
1096 | int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */ |
||
1097 | int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */ |
||
1098 | int_data[6] = abs(int_data[6] - int_data[4]);/* width */ |
||
1099 | int_data[7] = abs(int_data[7] - int_data[5]);/* height */ |
||
1100 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
1101 | int_data[9] = click_cnt; |
||
1102 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
14038 | schaersvoo | 1103 | // if( reply_format == 0 ){ reply_format = 20; } |
11806 | schaersvoo | 1104 | int_data[8] = 2;/* drag & drop */ |
1105 | } |
||
1106 | else |
||
1107 | { |
||
1108 | if( onclick == 1 ){ |
||
14038 | schaersvoo | 1109 | // reply_format = 20; |
11806 | schaersvoo | 1110 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
1111 | click_cnt++; /* will also be used in dragstuff ! */ |
||
1112 | } |
||
1113 | else |
||
1114 | { |
||
1115 | int_data[8] = 0; /* just static image */ |
||
1116 | } |
||
1117 | } |
||
14038 | schaersvoo | 1118 | if( include_special_OEF_reply == FALSE){ |
1119 | if( int_data[8] == 1 || int_data[8] == 2 ){ |
||
1120 | include_special_OEF_reply = TRUE; |
||
1121 | fprintf(js_include_file,"\ |
||
1122 | \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\ |
||
1123 | read_canvas_images = function(){\ |
||
1124 | var prec = %d;\ |
||
1125 | var len = ext_drag_images.length;\ |
||
1126 | var reply = new Array(len);\ |
||
1127 | for(var p = 0 ; p < len ; p++){\ |
||
1128 | var img = ext_drag_images[p];\ |
||
1129 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
||
1130 | };\ |
||
1131 | return reply;\ |
||
1132 | };\n\ |
||
14062 | schaersvoo | 1133 | /* end function 34 read_canvas_images() */",reply_precision); |
14038 | schaersvoo | 1134 | } |
1135 | } |
||
1136 | |||
11806 | schaersvoo | 1137 | /* |
1138 | (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt) |
||
1139 | URL,[2],[3],[6], [7], [4],[5],[6],[7],ext_img_cnt,1, [8], [9] |
||
1140 | */ |
||
14208 | schaersvoo | 1141 | string_length = 1 + snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%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],use_offset,use_snap); |
1142 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
14044 | schaersvoo | 1143 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%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],use_offset,use_snap); |
14038 | schaersvoo | 1144 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1145 | drag_type = -1; /* reset the drag_type indicator */ |
1146 | ext_img_cnt++; |
||
1147 | onclick=0; |
||
14038 | schaersvoo | 1148 | use_offset=0; |
1149 | reset(); |
||
11806 | schaersvoo | 1150 | break; |
1151 | default: break; |
||
1152 | } |
||
1153 | } |
||
14038 | schaersvoo | 1154 | reset(); |
11806 | schaersvoo | 1155 | break; |
8386 | schaersvoo | 1156 | |
11806 | schaersvoo | 1157 | case CROSSHAIR: |
8386 | schaersvoo | 1158 | /* |
11806 | schaersvoo | 1159 | @ crosshair x,y,color |
14379 | bpr | 1160 | @ draw a single crosshair point at (x;y) in color ''color`` |
1161 | @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust |
||
11806 | schaersvoo | 1162 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 1163 | @%crosshair%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshair 0,0,red%linewidth 1%onclick%crosshair 1,1,blue%linewidth 3%onclick%crosshair 3,3,green%linewidth 4%xrosshair 4,4,orange |
11806 | schaersvoo | 1164 | */ |
1165 | for(i=0;i<3;i++){ |
||
1166 | switch(i){ |
||
1167 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1168 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1169 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1170 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 1171 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
1172 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 1173 | /* click_cnt++ */ |
1174 | reset(); |
||
1175 | break; |
||
1176 | default:break; |
||
1177 | } |
||
1178 | } |
||
1179 | break; |
||
1180 | |||
1181 | case CROSSHAIRS: |
||
1182 | /* |
||
1183 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
14077 | bpr | 1184 | @ draw multiple crosshair points at given coordinates in color ''color`` |
14246 | bpr | 1185 | @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust |
9406 | schaersvoo | 1186 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 1187 | @%crosshairs_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 2%drag xy%crosshairs red,0,0,1,1,2,2,3,3%drag x%crosshairs blue,0,1,1,2,2,3,3,4 |
1188 | @%crosshairs_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshairs red,0,0,1,1,2,2,3,3%onclick%crosshairs blue,0,1,1,2,2,3,3,4 |
||
1189 | */ |
||
8386 | schaersvoo | 1190 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1191 | fill_color = stroke_color; |
||
1192 | i=0; |
||
1193 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 1194 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 1195 | if(i%2 == 0 ){ |
1196 | double_data[i] = get_real(infile,0); /* x */ |
||
1197 | } |
||
1198 | else |
||
1199 | { |
||
1200 | double_data[i] = get_real(infile,1); /* y */ |
||
1201 | } |
||
1202 | i++; |
||
1203 | } |
||
1204 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1205 | for(c=0 ; c < i-1 ; c = c+2){ |
14208 | schaersvoo | 1206 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
1207 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 1208 | /* click_cnt++; */ |
8386 | schaersvoo | 1209 | } |
1210 | reset(); |
||
1211 | break; |
||
1212 | |||
11806 | schaersvoo | 1213 | case CROSSHAIRSIZE: |
7614 | schaersvoo | 1214 | /* |
11806 | schaersvoo | 1215 | @ crosshairsize int |
1216 | @ default 8 (px) |
||
7614 | schaersvoo | 1217 | */ |
11806 | schaersvoo | 1218 | crosshair_size = (int) (get_real(infile,1)); |
1219 | break; |
||
1220 | |||
1221 | case CURSOR: |
||
1222 | /* |
||
14086 | bpr | 1223 | @ cursor some CSS cursor_style |
14071 | bpr | 1224 | @ alternative: <code>pointer</code> |
13956 | schaersvoo | 1225 | @ style can be any valid CSS property value |
1226 | @ choose from these types:<br />alias,all-scroll,auto,cell,context-menu,col-resize,copy,crosshair,default,e-resize,<br />ew-resize,grab,grabbing,help,move,n-resize,ne-resize,nesw-resize,ns-resize,nw-resize,<br />nwse-resize,no-drop,none,not-allowed,pointer,progress,row-resize,s-resize,se-resize,<br />sw-resize,text,url(myBall.cur),auto,vertical-text,w-resize,wait,zoom-in,zoom-out,initial |
||
1227 | @ note: wims will not check the validity of your cursor declaration |
||
1228 | @%cursor_css%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 3%drag xy%opacity 200,75%fcircles blue,-5,5,3,-4,-2,6,0,0,5,3,4,2,4,-5,4 |
||
11806 | schaersvoo | 1229 | */ |
1230 | fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1)); |
||
1231 | break; |
||
1232 | |||
1233 | case CURVE: |
||
1234 | /* |
||
1235 | @ curve color,formula(x) |
||
14379 | bpr | 1236 | @ alternative: <code>plot color,formula(x)</code> |
14071 | bpr | 1237 | @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot <code>trange -pi,pi<br />curve color,formula1(t),formula2(t)</code> |
14086 | bpr | 1238 | @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points |
14066 | bpr | 1239 | @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150) |
11806 | schaersvoo | 1240 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14379 | bpr | 1241 | @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">jsplot</a> (command ''curve`` will only calculate points within the xrange) |
12107 | schaersvoo | 1242 | @%curve%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 1%grid 2,2,grey,2,2,6,grey%precision 1000%curve red,4*sqrt(x)%curve green,2*sqrt(abs(x)%curve blue,3*1/sqrt(x)%curve orange,4*sin(4/x)%dashed%curve red,4*cos(x) |
11806 | schaersvoo | 1243 | */ |
1244 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
||
1245 | use_parametric = FALSE; |
||
1246 | stroke_color = get_color(infile,0); |
||
1247 | char *fun1 = get_string_argument(infile,0); |
||
1248 | char *fun2 = get_string_argument(infile,1); |
||
1249 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
14208 | schaersvoo | 1250 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 1251 | } |
1252 | else |
||
1253 | { |
||
1254 | stroke_color = get_color(infile,0); |
||
1255 | char *fun1 = get_string_argument(infile,1); |
||
1256 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
14208 | schaersvoo | 1257 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 1258 | } |
14208 | schaersvoo | 1259 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
11806 | schaersvoo | 1260 | /* click_cnt++; */ |
1261 | reset(); |
||
1262 | break; |
||
14038 | schaersvoo | 1263 | case CURVEDARROW: |
1264 | /* |
||
1265 | @ curvedarrow x1,y1,xc,yc,x2,y2,color |
||
14388 | bpr | 1266 | @ draw a single headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2). Note: the curve will <b>not go through</b> point (xc:yc). |
14038 | schaersvoo | 1267 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14388 | bpr | 1268 | @ use command <code>linewidth int</code> to adjust thickness of the arrow. |
1269 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>. |
||
14038 | schaersvoo | 1270 | @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow -5,0,0,10,5,0,blue |
1271 | @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green |
||
11806 | schaersvoo | 1272 | |
14029 | schaersvoo | 1273 | h[0] = arrowhead |
14066 | bpr | 1274 | h[1] = type: 1 = single 2=double arrow |
14208 | schaersvoo | 1275 | function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1276 | */ |
1277 | for(i=0;i<7;i++){ |
||
1278 | switch(i){ |
||
1279 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1280 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1281 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1282 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1283 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1284 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1285 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1286 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 1287 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,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,current_sliders,rotation_center,use_offset,use_pattern); |
1288 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
14038 | schaersvoo | 1289 | /* click_cnt++;*/ |
1290 | reset(); |
||
1291 | break; |
||
1292 | } |
||
1293 | } |
||
1294 | break; |
||
14029 | schaersvoo | 1295 | |
14038 | schaersvoo | 1296 | case CURVEDARROW2: |
1297 | /* |
||
1298 | @ curvedarrow2 x1,y1,xc,yc,x2,y2,color |
||
14248 | bpr | 1299 | @ draw a double headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2)<br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1300 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1301 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1302 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1303 | @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow2 -5,0,0,10,5,0,blue |
||
1304 | @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%cuvedarrow2 -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green |
||
14029 | schaersvoo | 1305 | |
1306 | h[0] = arrowhead |
||
14066 | bpr | 1307 | h[1] = type: 1 = single 2=double arrow |
14208 | schaersvoo | 1308 | function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1309 | */ |
1310 | for(i=0;i<7;i++){ |
||
1311 | switch(i){ |
||
1312 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1313 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1314 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1315 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1316 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1317 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1318 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1319 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 1320 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,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,current_sliders,rotation_center,use_offset,use_pattern); |
1321 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
14038 | schaersvoo | 1322 | /* click_cnt++;*/ |
1323 | reset(); |
||
1324 | break; |
||
1325 | } |
||
1326 | } |
||
1327 | break; |
||
1328 | case CURVEDARROWS: |
||
1329 | /* |
||
14248 | bpr | 1330 | @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n |
1331 | @ draw curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc<br /> note: the curve will <b>not go through</b> point (xc:yc) |
||
14038 | schaersvoo | 1332 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1333 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1334 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1335 | @%curvedarrows_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
1336 | @%curvedarrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
14029 | schaersvoo | 1337 | |
14030 | schaersvoo | 1338 | h[0] = arrowhead |
14066 | bpr | 1339 | h[1] = type: 1 = single 2=double arrow |
14208 | schaersvoo | 1340 | function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1341 | */ |
1342 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1343 | i = 0; |
||
1344 | decimals = find_number_of_digits(precision); |
||
1345 | while( ! done ){ |
||
1346 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1347 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1348 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1349 | double_data[2] = get_real(infile,0); /* xc */ |
||
1350 | double_data[3] = get_real(infile,0); /* yc */ |
||
1351 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1352 | double_data[5] = get_real(infile,1); /* y3 */ |
||
14208 | schaersvoo | 1353 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,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,current_sliders,rotation_center,use_offset,use_pattern); |
1354 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
14038 | schaersvoo | 1355 | i = i + 6; |
1356 | } |
||
1357 | reset(); |
||
1358 | break; |
||
14030 | schaersvoo | 1359 | |
14038 | schaersvoo | 1360 | case CURVEDARROWS2: |
1361 | /* |
||
1362 | @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n |
||
14248 | bpr | 1363 | @ draw double headed curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc. <br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1364 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1365 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1366 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1367 | @%curvedarrows2_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
1368 | @%curvedarrows2_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
14030 | schaersvoo | 1369 | |
1370 | h[0] = arrowhead |
||
14066 | bpr | 1371 | h[1] = type: 1 = single 2=double arrow |
14208 | schaersvoo | 1372 | function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1373 | */ |
1374 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1375 | i = 0; |
||
1376 | decimals = find_number_of_digits(precision); |
||
1377 | while( ! done ){ |
||
1378 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1379 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1380 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1381 | double_data[2] = get_real(infile,0); /* xc */ |
||
1382 | double_data[3] = get_real(infile,0); /* yc */ |
||
1383 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1384 | double_data[5] = get_real(infile,1); /* y3 */ |
||
14208 | schaersvoo | 1385 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,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,current_sliders,rotation_center,use_offset,use_pattern); |
1386 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
14038 | schaersvoo | 1387 | i = i + 6; |
1388 | } |
||
1389 | reset(); |
||
1390 | break; |
||
11806 | schaersvoo | 1391 | case DASHED: |
1392 | /* |
||
1393 | @ dashed |
||
1394 | @ keyword (no arguments required) |
||
1395 | @ next object will be drawn with a dashed line |
||
1396 | @ change dashing scheme by using command <a href="#dashtype">dashtype</a> |
||
12107 | schaersvoo | 1397 | @%dashed%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%line -5,-5,-5,5,red%dashtype 1,1%dline -4,-5,-4,5,green%dashtype 2,2%dline -3,-5,-3,5,blue%dashtype 3,3%dline 0,-5,0,5,orange%dashtype 4,4%dline 3,-5,3,5,brown |
11806 | schaersvoo | 1398 | */ |
1399 | use_dashed = TRUE; |
||
1400 | break; |
||
1401 | |||
1402 | case DASHTYPE: |
||
1403 | /* |
||
1404 | @ dashtype line_width_px,space_width_px |
||
1405 | @ every indiviual object may have its own dashtype, if needed... |
||
1406 | @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype |
||
14086 | bpr | 1407 | @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space |
13957 | schaersvoo | 1408 | @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable |
13949 | schaersvoo | 1409 | @%dashtype%size 400,400%xrange -10,10%yrange -10,10%dashtype 1,1%dhline 0,9,red%dashtype 2,2%dhline 0,8,red%dashtype 4,4%dhline 0,7,red%dashtype 6,6%dhline 0,6,red%dashtype 8,8%dhline 0,5,red%dashtype 10,10%dhline 0,4,red%dashtype 1,2%dhline 0,3,red%dashtype 2,4%dhline 0,2,red%dashtype 3,6%dhline 0,1,red%dashtype 4,8%dhline 0,0,red%linewidth 2%dashtype 1,1%dhline 0,-9,red%dashtype 2,2%dhline 0,-8,red%dashtype 4,4%dhline 0,-7,red%dashtype 6,6%dhline 0,-6,red%dashtype 8,8%dhline 0,-5,red%dashtype 10,10%dhline 0,-4,red%dashtype 1,2%dhline 0,-3,red%dashtype 2,4%dhline 0,-2,red%dashtype 4,8%dhline 0,-1,red |
11806 | schaersvoo | 1410 | */ |
1411 | for(i=0;i<2;i++){ |
||
1412 | switch(i){ |
||
1413 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
1414 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
1415 | } |
||
1416 | } |
||
1417 | break; |
||
1418 | |||
1419 | case DIAMONDFILL: |
||
1420 | /* |
||
1421 | @ diamondfill x0,y0,dx,dy,color |
||
1422 | @ x0,y0 in xrange / yrange |
||
1423 | @ distances dx,dy in pixels |
||
13936 | bpr | 1424 | @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a> |
12110 | schaersvoo | 1425 | @%diamondfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%linewidth 1%diamondfill 0,0,5,8,blue%diamondfill 0,7,8,8,lightgreen |
11806 | schaersvoo | 1426 | */ |
1427 | if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;} |
||
11820 | schaersvoo | 1428 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1429 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1430 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1431 | } |
||
1432 | decimals = find_number_of_digits(precision); |
||
7614 | schaersvoo | 1433 | for(i=0;i<5;i++){ |
1434 | switch(i){ |
||
11820 | schaersvoo | 1435 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
14032 | schaersvoo | 1436 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11820 | schaersvoo | 1437 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
1438 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1439 | case 4: stroke_color = get_color(infile,1); |
1440 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
14208 | schaersvoo | 1441 | string_length = 1 + snprintf(NULL,0, "draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
1442 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 1443 | snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 1444 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1445 | fill_cnt++; |
11806 | schaersvoo | 1446 | break; |
1447 | default:break; |
||
1448 | } |
||
1449 | } |
||
1450 | reset(); |
||
1451 | break; |
||
8224 | bpr | 1452 | |
11806 | schaersvoo | 1453 | case DOTFILL: |
1454 | /* |
||
1455 | @ dotfill x0,y0,dx,dy,color |
||
1456 | @ x0,y0 in xrange / yrange |
||
1457 | @ distances dx,dy in pixels |
||
1458 | @ radius of dots is linewidth |
||
13936 | bpr | 1459 | @ there is also a command <a href="#userdraw">userdraw dotfill,color</a> |
12110 | schaersvoo | 1460 | @%dotfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%dotfill 0,0,5,8,blue%dotfill 0,7,8,8,lightgreen |
11806 | schaersvoo | 1461 | */ |
1462 | if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;} |
||
11817 | schaersvoo | 1463 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1464 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1465 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1466 | } |
||
1467 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1468 | for(i=0;i<5;i++){ |
1469 | switch(i){ |
||
11817 | schaersvoo | 1470 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
1471 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
1472 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1473 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1474 | case 4: stroke_color = get_color(infile,1); |
1475 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
||
14208 | schaersvoo | 1476 | string_length = 1 + snprintf(NULL,0, "draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
1477 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11817 | schaersvoo | 1478 | snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 1479 | add_to_buffer(tmp_buffer); |
11817 | schaersvoo | 1480 | fill_cnt++; |
7614 | schaersvoo | 1481 | break; |
11806 | schaersvoo | 1482 | default:break; |
7614 | schaersvoo | 1483 | } |
1484 | } |
||
11806 | schaersvoo | 1485 | reset(); |
1486 | break; |
||
1487 | |||
1488 | case DRAG: |
||
1489 | /* |
||
1490 | @ drag [x][y][xy] |
||
1491 | @ the next object will be draggable in x / y / xy direction |
||
14077 | bpr | 1492 | @ the displacement can be read by <code>javascript:read_dragdrop();</code> |
14380 | bpr | 1493 | @ 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' ! |
14078 | bpr | 1494 | @ <a href='#onclick'>onclick</a> and ''drag x|y|xy`` may be combined (for different objects: a single object can either be onclick or drag, not both ) |
14077 | bpr | 1495 | @ ''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) |
14379 | bpr | 1496 | @ <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``) in this example <code>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />the red point will not be recognised as draggable ! in the example <code>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code>both points will be recognised |
14066 | bpr | 1497 | @ 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) |
14078 | bpr | 1498 | @ use keyword <a href='#snaptogrid'>snaptogrid<a/>, <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a> or command <a href='#snaptopoints'>snaptopoints x1,y1,x2,y2,...</a> to switch from free to discrete movement |
11806 | schaersvoo | 1499 | @ 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. |
14177 | bpr | 1500 | @ note: in case an object is dragged, zooming or panning will cause the coordinates to be reset to the original position: e.g. dragging / panning will get lost (array with ''drag data`` is erased). This is a design flaw and not a feature !! |
13829 | bpr | 1501 | @%drag_x%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag x%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4 |
1502 | @%drag_y%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag y%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4 |
||
1503 | @%drag_xy%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag xy%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4 |
||
11806 | schaersvoo | 1504 | */ |
1505 | temp = get_string(infile,1); |
||
1506 | if(strstr(temp,"xy") != NULL ){ |
||
1507 | drag_type = 0; |
||
1508 | } |
||
1509 | else |
||
1510 | { |
||
1511 | if(strstr(temp,"x") != NULL ){ |
||
1512 | drag_type = 1; |
||
1513 | } |
||
1514 | else |
||
1515 | { |
||
1516 | drag_type = 2; |
||
1517 | } |
||
1518 | } |
||
1519 | /* assuming all drag&drop coordinates the same precision: so set only once */ |
||
1520 | if( print_drag_params_only_once == FALSE ){ |
||
1521 | fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision); |
||
1522 | print_drag_params_only_once = TRUE; |
||
1523 | } |
||
1524 | onclick = 2; |
||
1525 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
7614 | schaersvoo | 1526 | break; |
8386 | schaersvoo | 1527 | |
11806 | schaersvoo | 1528 | case ELLIPSE: |
8351 | schaersvoo | 1529 | /* |
11806 | schaersvoo | 1530 | @ ellipse xc,yc,radius_x,radius_y,color |
14379 | bpr | 1531 | @ an ellipse with center xc/yc in x/y-range |
11806 | schaersvoo | 1532 | @ radius_x and radius_y are in pixels |
9406 | schaersvoo | 1533 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
11806 | schaersvoo | 1534 | @ will shrink / expand on zoom out / zoom in |
13949 | schaersvoo | 1535 | @%ellipse%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%drag xy%ellipse 0,0,6,4,green%zoom blue |
8351 | schaersvoo | 1536 | */ |
11806 | schaersvoo | 1537 | for(i=0;i<5;i++){ |
1538 | switch(i){ |
||
1539 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1540 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
14066 | bpr | 1541 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
1542 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
||
11806 | schaersvoo | 1543 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
1544 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 1545 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
1546 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 1547 | /* click_cnt++; */ |
1548 | reset(); |
||
1549 | break; |
||
1550 | } |
||
1551 | } |
||
1552 | break; |
||
13829 | bpr | 1553 | |
12110 | schaersvoo | 1554 | case ELLIPSES: |
1555 | /* |
||
1556 | @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,... |
||
14379 | bpr | 1557 | @ ellipses with center xc1/yc1 in x/y-range, radius_x1 and radius_y1 are in pixels, etc |
12110 | schaersvoo | 1558 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1559 | @ will shrink / expand on zoom out / zoom in |
||
13949 | schaersvoo | 1560 | @%ellipses%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%onclick%ellipses red,-3,0,2,4,0,0,4,2,3,0,6,2 |
12110 | schaersvoo | 1561 | */ |
13829 | bpr | 1562 | |
12110 | schaersvoo | 1563 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1564 | fill_color = stroke_color; |
||
1565 | i=1; |
||
1566 | while( ! done ){ /* get next item until EOL*/ |
||
1567 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1568 | switch (i%4){ |
||
1569 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
1570 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
1571 | case 3:double_data[i-1] = get_real(infile,0);break; /* rx */ |
||
1572 | case 0:double_data[i-1] = get_real(infile,1);break; /* ry */ |
||
1573 | default: break; |
||
1574 | } |
||
1575 | i++; |
||
1576 | } |
||
1577 | decimals = find_number_of_digits(precision); |
||
1578 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
14208 | schaersvoo | 1579 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+2],decimals,double_data[c+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,current_sliders,rotation_center,use_offset,use_pattern); |
1580 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} /* click_cnt++; */ |
||
12110 | schaersvoo | 1581 | } |
1582 | reset(); |
||
1583 | break; |
||
1584 | |||
11806 | schaersvoo | 1585 | case FILLALL: |
1586 | /* |
||
1587 | @ fillall color,x1,y1,x2,y2...x_n,y_n |
||
14380 | bpr | 1588 | @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color ''color``. |
14388 | bpr | 1589 | @ any other colors (objects) in the <a href='#canvastype'>canvastype</a> will act as border to the bucket fill. |
14246 | bpr | 1590 | @ use this command after all boundary objects are declared. |
14380 | bpr | 1591 | @ Use command ''userdraw clickfill,color`` for user click driven flood fill. |
14388 | bpr | 1592 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5). |
14071 | bpr | 1593 | @ note: the fill-family of commands are very (client) cpu intensive operations!<br />filling is done pixel by pixel 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.. |
12110 | schaersvoo | 1594 | @%fillall%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%vlines black,-5,0,-5,0,-4,0,-4,0,3,0,3,0%hlines black,-5,0,-5,0,-5,4,-5,4,-5,-2,-5,-2%circles green,0,0,2,3,3,5,-5,-5,3%opacity 240,50%fillall blue,1,1,8,8,-8,-8 |
11806 | schaersvoo | 1595 | */ |
1596 | decimals = find_number_of_digits(precision); |
||
1597 | fill_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
8351 | schaersvoo | 1598 | i=0; |
11806 | schaersvoo | 1599 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1600 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1601 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1602 | } |
||
8351 | schaersvoo | 1603 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 1604 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8351 | schaersvoo | 1605 | if(i%2 == 0 ){ |
1606 | double_data[i] = get_real(infile,0); /* x */ |
||
1607 | } |
||
1608 | else |
||
1609 | { |
||
1610 | double_data[i] = get_real(infile,1); /* y */ |
||
14208 | schaersvoo | 1611 | string_length = 1 + snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
1612 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1613 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
11806 | schaersvoo | 1614 | add_to_buffer(tmp_buffer); |
1615 | fill_cnt++; |
||
8351 | schaersvoo | 1616 | } |
1617 | i++; |
||
1618 | } |
||
11806 | schaersvoo | 1619 | break; |
1620 | |||
1621 | case FILLED: |
||
1622 | /* |
||
1623 | @ filled |
||
1624 | @ keyword (no arguments required) |
||
14077 | bpr | 1625 | @ the next ''fillable`` object (only the next !) will be filled |
14066 | bpr | 1626 | @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor |
11839 | schaersvoo | 1627 | @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
14086 | bpr | 1628 | @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity |
14066 | bpr | 1629 | @ use command <a href='#fill'>fill x,y,color</a> or <a href="#floodfill">floodfill x,y,color</a> to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care ! |
11806 | schaersvoo | 1630 | */ |
11839 | schaersvoo | 1631 | use_filled = 1; |
11859 | schaersvoo | 1632 | use_pattern = 0; |
11806 | schaersvoo | 1633 | break; |
1634 | |||
1635 | case FILLCOLOR: |
||
1636 | /* |
||
1637 | @ fillcolor colorname or #hex |
||
14388 | bpr | 1638 | @ set the color: mainly used for command ''userdraw obj,stroke_color`` |
11806 | schaersvoo | 1639 | @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
11839 | schaersvoo | 1640 | @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
11806 | schaersvoo | 1641 | */ |
1642 | fill_color = get_color(infile,1); |
||
11874 | schaersvoo | 1643 | use_pattern = 0; |
11806 | schaersvoo | 1644 | break; |
1645 | |||
11837 | schaersvoo | 1646 | case FILLPATTERN: |
1647 | /* |
||
11854 | schaersvoo | 1648 | @ fillpattern grid | hatch | diamond | dot | image-url |
11837 | schaersvoo | 1649 | @ use a pattern as fillstyle |
14066 | bpr | 1650 | @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a> |
14077 | bpr | 1651 | @ not -yet- implemented in the <a href="#multidraw">multidraw objects family</a>...(will probably be too complex) |
14066 | bpr | 1652 | @ the fillcolor is set by the object command, for example:<br /><code>size 370,370<br />xrange -5,5<br />yrange -5,5<br />opacity 165,150<br />fillpattern grid<br />fcircle -6,3,160,blue<br />fillpattern dot<br />fcircle -3,-3,160,red<br />fillpattern hatch<br />fcircle 0,3,160,green<br />filpattern diamond<br />fcircle 3,-3,160,cyan<br />userdraw dotfill,blue<br />zoom red</code> |
14078 | bpr | 1653 | @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed) |
11837 | schaersvoo | 1654 | @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a> |
11839 | schaersvoo | 1655 | @ see <a href="#fillcolor">fillcolor</a> for solid color filling. |
14380 | bpr | 1656 | @ when using an image-url, make sure it contains an ''/`` in the filename...''fillpattern $$module_dir/gifs/test.jpg`` will fill the next fillable object with this image.<br />The argument to html5 canvas routine 'createPattern(img,argument)' is set to ''repeat`` e.g. if the image is smaller then the canvas, multiple copies will be used to fill the area ( e.g. ctx.fillStyle() = pattern)<br />for example:<br /><code>size 150,150<br />xrange -5,5<br />yrange -5,5<br />drag xy<br />fillpattern gifs/en.gif<br />fcircle 0,0,100,red<br />fillpattern gifs/nl.gif<br />drag xy<br />fcircle -3,2,100,green<br />fillpattern gifs/cn.gif<br />drag xy<br />fcircle 3,2,100,green</code> |
1657 | @ fillpattern is also active for <a href="#userdraw">userdraw object,color</a>...<br />the userdraw family a has also ''clickfill type`` (e.g. an object gets filled between boundaries, when clicked) commands like:<br />''userdraw dotfill,color``, ''userdraw hatchfill,color`` etc. |
||
13948 | schaersvoo | 1658 | @%fillpattern_1%size 400,400%xrange -5,5%yrange -5,5%opacity 165,150%fillpattern grid%fcircle -6,3,160,blue%fillpattern dot%fcircle -3,-3,160,red%fillpattern hatch%fcircle 0,3,160,green%filpattern diamond%fcircle 3,-3,160,cyan%zoom red |
1659 | @%fillpattern_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%fillcolor green%fillpattern hatch%#fillpattern dot,diamond,grid,imageurl%userdraw fcircle,red |
||
11837 | schaersvoo | 1660 | */ |
1661 | temp = get_string(infile,1); |
||
11875 | schaersvoo | 1662 | if( strstr(temp,"grid") != 0 ){ use_pattern = 2;use_filled = 2;} /* use_pattern is used in dragstuff library */ |
11837 | schaersvoo | 1663 | else |
11875 | schaersvoo | 1664 | if( strstr(temp,"hatch") != 0 ){ use_pattern = 3;use_filled = 3;} |
11837 | schaersvoo | 1665 | else |
11875 | schaersvoo | 1666 | if( strstr(temp,"diamond") != 0 ){ use_pattern = 4;use_filled = 4;} |
11837 | schaersvoo | 1667 | else |
11875 | schaersvoo | 1668 | if( strstr(temp,"dot") != 0 ){ use_pattern = 5;use_filled = 5;} |
11837 | schaersvoo | 1669 | else |
11875 | schaersvoo | 1670 | if( strstr(temp,"/") != 0 ){ use_pattern = 6;use_filled = 0;if( js_function[ADD_LOAD_IMAGE] != 1 ){ js_function[ADD_LOAD_IMAGE] = 1; add_js_load_image(js_include_file,canvas_root_id);} fprintf(js_include_file,"get_image_from_url(\"%s\"); ",temp); } |
11854 | schaersvoo | 1671 | else |
13829 | bpr | 1672 | canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot..."); |
11837 | schaersvoo | 1673 | break; |
11806 | schaersvoo | 1674 | case FILLTOBORDER: |
1675 | /* |
||
1676 | @ filltoborder x,y,bordercolor,color |
||
14380 | bpr | 1677 | @ fill the region of point (x:y) with color ''color`` |
11806 | schaersvoo | 1678 | @ any other color will not act as border to the bucket fill |
14246 | bpr | 1679 | @ use this command after all boundary objects are declared. |
11806 | schaersvoo | 1680 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1681 | @ note: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel 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.. |
11806 | schaersvoo | 1682 | @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a> |
12110 | schaersvoo | 1683 | @%filltoborder%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%filltoborder 6,6,blue,blue%filltoborder 6,-6,blue,red |
11806 | schaersvoo | 1684 | */ |
1685 | for(i=0 ;i < 4 ; i++){ |
||
1686 | switch(i){ |
||
1687 | case 0:double_data[0] = get_real(infile,0);break; |
||
1688 | case 1:double_data[1] = get_real(infile,0);break; |
||
1689 | case 2:bgcolor = get_color(infile,0);break; |
||
1690 | case 3:fill_color = get_color(infile,1); |
||
1691 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1692 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1693 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1694 | } |
||
1695 | decimals = find_number_of_digits(precision); |
||
1696 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
14208 | schaersvoo | 1697 | string_length = 1 + snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
1698 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1699 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
11806 | schaersvoo | 1700 | add_to_buffer(tmp_buffer); |
1701 | fill_cnt++; |
||
1702 | break; |
||
1703 | default:break; |
||
8351 | schaersvoo | 1704 | } |
11806 | schaersvoo | 1705 | } |
1706 | reset(); |
||
1707 | break; |
||
1708 | case FLOODFILL: |
||
1709 | /* |
||
1710 | @ floodfill x,y,color |
||
14071 | bpr | 1711 | @ alternative: <code>fill x,y,color</code> |
14380 | bpr | 1712 | @ fill the region of point (x:y) with color ''color`` |
11806 | schaersvoo | 1713 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
14246 | bpr | 1714 | @ use this command after all boundary objects are declared. |
14077 | bpr | 1715 | @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill. |
11806 | schaersvoo | 1716 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1717 | @ note: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel 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.. |
12110 | schaersvoo | 1718 | @%floodfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%floodfill 6,6,blue%floodfill 6,-6,red |
11806 | schaersvoo | 1719 | */ |
1720 | for(i=0 ;i < 4 ; i++){ |
||
1721 | switch(i){ |
||
1722 | case 0:double_data[0] = get_real(infile,0);break; |
||
1723 | case 1:double_data[1] = get_real(infile,0);break; |
||
1724 | case 2:fill_color = get_color(infile,1); |
||
1725 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1726 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1727 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1728 | } |
||
1729 | decimals = find_number_of_digits(precision); |
||
1730 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
14208 | schaersvoo | 1731 | string_length = 1 + snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
1732 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1733 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
11806 | schaersvoo | 1734 | add_to_buffer(tmp_buffer); |
1735 | fill_cnt++; |
||
1736 | break; |
||
1737 | default:break; |
||
1738 | } |
||
1739 | } |
||
1740 | reset(); |
||
1741 | break; |
||
1742 | |||
1743 | case FONTCOLOR: |
||
1744 | /* |
||
1745 | @ fontcolor color |
||
1746 | @ color: hexcolor or colorname |
||
1747 | @ default: black |
||
13956 | schaersvoo | 1748 | @ use command <a href="#fontfamily'>fontfamily</a> to deviate from default font type |
1749 | @%fontcolor%size 400,400%xrange -10,10%yrange -10,10%fontcolor red%#note: use command fontfamily to change size and shape%axis%axisnumbering%grid 2,2,grey,2,2,4,grey |
||
11806 | schaersvoo | 1750 | */ |
1751 | font_color = get_color(infile,1); |
||
1752 | break; |
||
1753 | |||
1754 | case FONTFAMILY: |
||
1755 | /* |
||
1756 | @ fontfamily font_description |
||
1757 | @ set the font family; for browsers that support it |
||
14078 | bpr | 1758 | @ font_description: Ariel, Courier, Helvetica etc |
14246 | bpr | 1759 | @ in case commands <code>string color,x,y,the string</code>, <code>stringup color,x,y,rotation,the string</code>, ''fontfamily`` can be something like:<code>fontfamily italic 34pt Ariel</code>. Use correct syntax: ''font style``, ''font size pt``, ''fontfamily`` |
13959 | bpr | 1760 | @%fontfamily%size 400,400%xrange -10,10%yrange -10,10 %fontfamily Bold 10pt Ariel%string blue,-9,9,10 pt Ariel%fontfamily Italic 20pt Ariel%string blue,0,9,20 pt Ariel%fontfamily Bold 10pt Helvetica%string blue,-9,5,10 pt Helvetica%fontfamily Italic 20pt Helvetica%string blue,0,5,20 pt Helvetica %fontfamily Bold 10pt Courier%string blue,-9,0,10 pt Courier%fontfamily Italic 20pt Courier%string blue,0,0,20 pt Courier%fontfamily Bold 10pt Fixed%string blue,-9,-5,10 pt Fixed%fontfamily Italic 20pt Fixed%string blue,0,-5,20 pt Fixed %fontfamily Bold 10pt Times%string blue,-9,-9,10 pt Times%fontfamily Italic 20pt Times%string blue,0,-9,20 pt Times |
1761 | |||
11806 | schaersvoo | 1762 | */ |
1763 | font_family = get_string(infile,1); |
||
1764 | break; |
||
1765 | |||
1766 | case FONTSIZE: |
||
1767 | /* |
||
1768 | @ fontsize font_size |
||
1769 | @ default value 12 |
||
14562 | bpr | 1770 | @ note: for some macros (like ''grid | legend | xaxistext | xlabel`` etc) sometimes command <a href="#fontfamily">fontfamily</a> can be used for some specific font-setting, this is however not always very straight forward... so just try and see what happens. |
11806 | schaersvoo | 1771 | */ |
1772 | font_size = (int) (get_real(infile,1)); |
||
1773 | break; |
||
1774 | |||
1775 | case FUNCTION_LABEL: |
||
1776 | /* |
||
14071 | bpr | 1777 | @ functionlabel some string |
14086 | bpr | 1778 | @ default value ''f(x)=`` |
11806 | schaersvoo | 1779 | @ no mathml allowed (just ascii string) |
13956 | schaersvoo | 1780 | @ use command <a href='#fontsize'>fontsize int</a> to adjust the size |
1781 | @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed) |
||
14066 | bpr | 1782 | @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a> |
14562 | bpr | 1783 | @ no limit in amount of inputfields for userbased function plotting. |
11806 | schaersvoo | 1784 | */ |
1785 | function_label = get_string_argument(infile,1); |
||
1786 | break; |
||
1787 | |||
14078 | bpr | 1788 | case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/ |
11806 | schaersvoo | 1789 | /* |
1790 | @ grid step_x,step_y,gridcolor |
||
14177 | bpr | 1791 | @ if keywords <a href="#axis">axis</a> or <a href="#axisnumbering">axisnumbering</a> are set, use: <code>grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color</code> minor x step = step_x / minor_x |
1792 | @ 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; defaults: black,12,Ariel |
||
14071 | bpr | 1793 | @ if xmin > 0 and/or ymin > 0 and zooming / panning is not active: be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV) |
14066 | bpr | 1794 | @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a> |
14177 | bpr | 1795 | @ use commands <a href="#xlabel">xlabel some_string</a> and/or <a href="#ylabel">ylabel some_string</a> to label axis; use command ''fontsize`` to adjust size: the font family is non-configurable 'italic your_fontsize px Ariel' ! |
14252 | bpr | 1796 | @ see commands <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 command <a href="#fontfamily">fontfamily</a>; default '12px Ariel') |
14177 | bpr | 1797 | @ see command <a href="#legend">legend</a> to set a legend for the graph; use command <a href="#fontsize">fontsize</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel') |
12110 | schaersvoo | 1798 | @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red |
1799 | @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red |
||
14634 | bpr | 1800 | @%grid_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red |
12110 | schaersvoo | 1801 | @%grid_axis_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red |
11806 | schaersvoo | 1802 | */ |
1803 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
||
1804 | if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;} |
||
1805 | for(i=0;i<4;i++){ |
||
1806 | switch(i){ |
||
1807 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
1808 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
1809 | case 2: |
||
1810 | if( use_axis == TRUE ){ |
||
1811 | stroke_color = get_color(infile,0); |
||
1812 | done = FALSE; |
||
1813 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
1814 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
1815 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
1816 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
8351 | schaersvoo | 1817 | } |
1818 | else |
||
1819 | { |
||
11806 | schaersvoo | 1820 | int_data[0] = 1; |
1821 | int_data[1] = 1; |
||
1822 | stroke_color = get_color(infile,1); |
||
1823 | fill_color = stroke_color; |
||
8351 | schaersvoo | 1824 | } |
11806 | schaersvoo | 1825 | 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 !");} |
1826 | /* set snap_x snap_y values in pixels */ |
||
1827 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
||
14208 | schaersvoo | 1828 | string_length = 1 + 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); |
1829 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 1830 | 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); |
1831 | add_to_buffer(tmp_buffer); |
||
1832 | break; |
||
8351 | schaersvoo | 1833 | } |
1834 | } |
||
1835 | reset(); |
||
1836 | break; |
||
11806 | schaersvoo | 1837 | case GRIDFILL: |
1838 | /* |
||
1839 | @ gridfill x0,y0,dx,dy,color |
||
1840 | @ x0,y0 in xrange / yrange |
||
1841 | @ distances dx,dy in pixels |
||
13936 | bpr | 1842 | @ there is also a command <a href="#userdraw">userdraw gridfill,color</a> |
12110 | schaersvoo | 1843 | @%gridfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%gridfill 6,6,10,10,blue%gridfill 6,-6,6,6,red |
1844 | |||
11806 | schaersvoo | 1845 | */ |
1846 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
||
11820 | schaersvoo | 1847 | decimals = find_number_of_digits(precision); |
1848 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1849 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1850 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1851 | } |
||
11806 | schaersvoo | 1852 | for(i=0;i<5;i++){ |
1853 | switch(i){ |
||
11820 | schaersvoo | 1854 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
1855 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
1856 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1857 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1858 | case 4: stroke_color = get_color(infile,1); |
14208 | schaersvoo | 1859 | string_length = 1 + snprintf(NULL,0, "draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
1860 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 1861 | snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 1862 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1863 | fill_cnt++; |
11806 | schaersvoo | 1864 | break; |
1865 | default:break; |
||
1866 | } |
||
1867 | } |
||
1868 | reset(); |
||
1869 | break; |
||
8386 | schaersvoo | 1870 | |
8244 | schaersvoo | 1871 | case HALFLINE: |
1872 | /* |
||
1873 | @ demiline x1,y1,x2,y2,color |
||
14071 | bpr | 1874 | @ alternative: <code>halfline</code> |
14380 | bpr | 1875 | @ draws a halfline starting in (x1:y1) and through (x2:y2) in color ''color`` (colorname or hex) |
9406 | schaersvoo | 1876 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 1877 | @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue |
8244 | schaersvoo | 1878 | */ |
1879 | for(i=0;i<5;i++){ |
||
1880 | switch(i){ |
||
1881 | case 0: double_data[0]= get_real(infile,0);break; /* x-values */ |
||
1882 | case 1: double_data[1]= get_real(infile,0);break; /* y-values */ |
||
1883 | case 2: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
1884 | case 3: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
1885 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
1886 | if(double_data[0] == double_data[10]){ /* vertical halfline */ |
||
1887 | if(double_data[1] < double_data[11]){ |
||
1888 | double_data[3] = ymax + 1000; |
||
1889 | } |
||
1890 | else |
||
1891 | { |
||
1892 | double_data[3] = ymin - 1000; |
||
1893 | } |
||
10953 | bpr | 1894 | double_data[2] = double_data[0]; |
8244 | schaersvoo | 1895 | } |
1896 | else |
||
1897 | { /* horizontal halfline*/ |
||
1898 | if( double_data[1] == double_data[11] ){ |
||
1899 | if( double_data[0] < double_data[10] ){ |
||
1900 | double_data[2] = xmax + 1000; /* halfline to the right */ |
||
1901 | } |
||
1902 | else |
||
1903 | { |
||
1904 | double_data[2] = xmin - 1000; /* halfline to the left */ |
||
1905 | } |
||
1906 | double_data[3] = double_data[1]; |
||
1907 | } |
||
1908 | else |
||
1909 | { |
||
1910 | /* any other halfline */ |
||
1911 | /* slope */ |
||
1912 | double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]); |
||
1913 | /* const */ |
||
1914 | double_data[13] = double_data[1] - double_data[12]*double_data[0]; |
||
1915 | if( double_data[0] < double_data[10] ){ |
||
1916 | double_data[2] = double_data[2] + 1000; |
||
1917 | } |
||
1918 | else |
||
1919 | { |
||
1920 | double_data[2] = double_data[2] - 1000; |
||
1921 | } |
||
1922 | double_data[3] = double_data[12]*double_data[2] + double_data[13]; |
||
1923 | } |
||
10953 | bpr | 1924 | } |
14208 | schaersvoo | 1925 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
1926 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 1927 | /* click_cnt++; */ |
1928 | reset(); |
||
8244 | schaersvoo | 1929 | break; |
1930 | } |
||
1931 | } |
||
1932 | break; |
||
8386 | schaersvoo | 1933 | |
8365 | schaersvoo | 1934 | case HALFLINES: |
1935 | /* |
||
1936 | @ demilines color,x1,y1,x2,y2,.... |
||
14071 | bpr | 1937 | @ alternative: <code>halflines</code> |
14380 | bpr | 1938 | @ draws halflines starting in (x1:y1) and through (x2:y2) in color ''color`` (colorname or hex) etc |
9406 | schaersvoo | 1939 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually |
12110 | schaersvoo | 1940 | @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0 |
8365 | schaersvoo | 1941 | */ |
1942 | stroke_color=get_color(infile,0); |
||
1943 | fill_color = stroke_color; |
||
1944 | i=0; |
||
1945 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 1946 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8365 | schaersvoo | 1947 | if(i%2 == 0 ){ |
1948 | double_data[i] = get_real(infile,0); /* x */ |
||
1949 | } |
||
1950 | else |
||
1951 | { |
||
1952 | double_data[i] = get_real(infile,1); /* y */ |
||
1953 | } |
||
1954 | i++; |
||
1955 | } |
||
1956 | decimals = find_number_of_digits(precision); |
||
1957 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
1958 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
||
1959 | if(double_data[c+1] < double_data[c+3]){ /* upright halfline */ |
||
1960 | double_data[c+3] = ymax + 1000; |
||
1961 | } |
||
1962 | else |
||
1963 | { |
||
1964 | double_data[c+3] = ymin - 1000;/* descending halfline */ |
||
1965 | } |
||
1966 | } |
||
1967 | else |
||
1968 | { |
||
1969 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
1970 | if(double_data[c] < double_data[c+2] ){ /* halfline to the right */ |
||
1971 | double_data[c+2] = xmax+100; |
||
1972 | } |
||
1973 | else |
||
1974 | { |
||
1975 | double_data[c+2] = xmin-1000; /* halfline to the right */ |
||
1976 | } |
||
1977 | } |
||
1978 | else |
||
1979 | { |
||
1980 | /* m */ |
||
1981 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
1982 | /* q */ |
||
1983 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
1984 | if(double_data[c] < double_data[c+2]){ /* to the right */ |
||
14071 | bpr | 1985 | double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */ |
8365 | schaersvoo | 1986 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
1987 | } |
||
1988 | else |
||
1989 | { /* to the left */ |
||
1990 | double_data[c+2] = xmin - 1000; |
||
1991 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
1992 | } |
||
1993 | } |
||
1994 | } |
||
14208 | schaersvoo | 1995 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
1996 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 1997 | /* click_cnt++; */ |
8365 | schaersvoo | 1998 | } |
1999 | reset(); |
||
2000 | break; |
||
11806 | schaersvoo | 2001 | case HATCHFILL: |
2002 | /* |
||
2003 | @ hatchfill x0,y0,dx,dy,color |
||
2004 | @ x0,y0 in xrange / yrange |
||
2005 | @ distances dx,dy in pixels |
||
13936 | bpr | 2006 | @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a> |
12110 | schaersvoo | 2007 | @%hatchfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%hatchfill 6,6,10,10,blue%hatchfill 6,-6,6,6,red |
11806 | schaersvoo | 2008 | */ |
2009 | if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;} |
||
11820 | schaersvoo | 2010 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
2011 | js_function[DRAW_FILLTOBORDER] = 1; |
||
2012 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
2013 | } |
||
2014 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 2015 | for(i=0;i<5;i++){ |
2016 | switch(i){ |
||
11820 | schaersvoo | 2017 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
2018 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
2019 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2020 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 2021 | case 4: stroke_color = get_color(infile,1); |
2022 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
14208 | schaersvoo | 2023 | string_length = 1 + snprintf(NULL,0, "draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
2024 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 2025 | snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 2026 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 2027 | fill_cnt++; |
11806 | schaersvoo | 2028 | break; |
2029 | default:break; |
||
2030 | } |
||
2031 | } |
||
2032 | reset(); |
||
2033 | break; |
||
8386 | schaersvoo | 2034 | |
8224 | bpr | 2035 | case HLINE: |
7614 | schaersvoo | 2036 | /* |
2037 | @ hline x,y,color |
||
14071 | bpr | 2038 | @ alternative: <code>horizontalline</code> |
14380 | bpr | 2039 | @ draw a horizontal line through point (x:y) in color ''color`` |
14385 | bpr | 2040 | @ or use command <a href='#curve'>curve color,formula</a> to draw the line (uses more points to draw the line; is however better draggable). |
9406 | schaersvoo | 2041 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 2042 | @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue |
7614 | schaersvoo | 2043 | */ |
2044 | for(i=0;i<3;i++) { |
||
2045 | switch(i){ |
||
2046 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
2047 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
2048 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
2049 | double_data[3] = double_data[1]; |
||
2050 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 2051 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,100*xmin,decimals,100*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,current_sliders,rotation_center,use_offset,use_pattern); |
2052 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 2053 | /* click_cnt++; */ |
2054 | reset(); |
||
7614 | schaersvoo | 2055 | break; |
2056 | } |
||
2057 | } |
||
2058 | break; |
||
8366 | schaersvoo | 2059 | |
2060 | case HLINES: |
||
2061 | /* |
||
2062 | @ hlines color,x1,y1,x2,y2,... |
||
14071 | bpr | 2063 | @ alternative: <code>horizontallines</code> |
14380 | bpr | 2064 | @ draw horizontal lines through points (x1:y1)...(xn:yn) in color ''color`` |
9406 | schaersvoo | 2065 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12110 | schaersvoo | 2066 | @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5 |
8366 | schaersvoo | 2067 | */ |
2068 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2069 | fill_color = stroke_color; |
||
2070 | i=0; |
||
2071 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2072 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8366 | schaersvoo | 2073 | if(i%2 == 0 ){ |
2074 | double_data[i] = get_real(infile,0); /* x */ |
||
2075 | } |
||
2076 | else |
||
2077 | { |
||
2078 | double_data[i] = get_real(infile,1); /* y */ |
||
2079 | } |
||
2080 | i++; |
||
2081 | } |
||
2082 | decimals = find_number_of_digits(precision); |
||
2083 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
14208 | schaersvoo | 2084 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
2085 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 2086 | /* click_cnt++; */ |
8366 | schaersvoo | 2087 | } |
2088 | reset(); |
||
2089 | break; |
||
11806 | schaersvoo | 2090 | case HTTP: |
7614 | schaersvoo | 2091 | /* |
11806 | schaersvoo | 2092 | @ http x1,y1,x2,y2,http://some_adress.com |
14078 | bpr | 2093 | @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2) |
11806 | schaersvoo | 2094 | @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
14071 | bpr | 2095 | @ can <b>not</b> be ''set onclick`` or ''drag xy`` |
12110 | schaersvoo | 2096 | @%http%size 400,400%xrange -10,10%yrange -10,10%http 0,10,10,0,http://wims.unice.fr%opacity 200,50%drag xy%fcircle 0,0,100,green |
7614 | schaersvoo | 2097 | */ |
11806 | schaersvoo | 2098 | if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;} |
2099 | for(i=0;i<5;i++){ |
||
7614 | schaersvoo | 2100 | switch(i){ |
11806 | schaersvoo | 2101 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
14032 | schaersvoo | 2102 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
11806 | schaersvoo | 2103 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
2104 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
2105 | case 4: decimals = find_number_of_digits(precision); |
||
2106 | temp = get_string(infile,1); |
||
2107 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
14208 | schaersvoo | 2108 | string_length = 1 + 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); |
11806 | schaersvoo | 2109 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+2); |
2110 | 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); |
||
2111 | add_to_buffer(tmp_buffer); |
||
7614 | schaersvoo | 2112 | break; |
2113 | } |
||
2114 | } |
||
11806 | schaersvoo | 2115 | reset(); |
7614 | schaersvoo | 2116 | break; |
11806 | schaersvoo | 2117 | case HTML: |
8366 | schaersvoo | 2118 | /* |
11806 | schaersvoo | 2119 | @ html x1,y1,x2,y2,html_string |
14071 | bpr | 2120 | @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc. |
2121 | @ can be set onclick (however dragging not supported) |
||
14038 | schaersvoo | 2122 | @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1) |
12110 | schaersvoo | 2123 | @%html%size 400,400%xrange -10,10%yrange -10,10%html 0,10,10,0,<table style="border:solid 2px;background-color:yellow"><tr><th>qwerty</th><th>qwerty</th></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr></table> %opacity 200,50%drag xy%fcircle 0,0,100,green |
8366 | schaersvoo | 2124 | */ |
11806 | schaersvoo | 2125 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
2126 | for(i=0;i<5;i++){ |
||
2127 | switch(i){ |
||
2128 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
14032 | schaersvoo | 2129 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
14066 | bpr | 2130 | case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow */ |
2131 | case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */ |
||
11806 | schaersvoo | 2132 | case 4: decimals = find_number_of_digits(precision); |
2133 | temp = get_string(infile,1); |
||
2134 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
14208 | schaersvoo | 2135 | string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
2136 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
14044 | schaersvoo | 2137 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
11806 | schaersvoo | 2138 | add_to_buffer(tmp_buffer); |
2139 | if(onclick == 1 || onclick == 2 ){click_cnt++;} |
||
14038 | schaersvoo | 2140 | use_offset = 0; |
11806 | schaersvoo | 2141 | break; |
2142 | default:break; |
||
8366 | schaersvoo | 2143 | } |
2144 | } |
||
2145 | break; |
||
8386 | schaersvoo | 2146 | |
11806 | schaersvoo | 2147 | case IMAGEFILL: |
7614 | schaersvoo | 2148 | /* |
11996 | schaersvoo | 2149 | @ imagefill x,y,scaling to xsize × ysize?,image_url |
11874 | schaersvoo | 2150 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
2151 | @ scaling to xsize × ysize ? ... 1 = yes 0 = no |
||
14078 | bpr | 2152 | @ After pattern filling, the fill-color should be reset ! |
14066 | bpr | 2153 | @ wims getins / image from class directory: imagefill 80,80,my_image.gif |
2154 | @ normal url: imagefill 80,80,0,$module_dir/gifs/my_image.gif |
||
2155 | @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg |
||
11874 | schaersvoo | 2156 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
13967 | schaersvoo | 2157 | @%imagefill_tile%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,0,gifs/en.gif%imagefill -5,5,0,gifs/logo/wimsedu.png |
2158 | @%imagefill_scale%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,1,gifs/en.gif%imagefill -5,5,1,gifs/logo/wimsedu.png |
||
7614 | schaersvoo | 2159 | */ |
11806 | schaersvoo | 2160 | if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;} |
11854 | schaersvoo | 2161 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
2162 | js_function[DRAW_FILLTOBORDER] = 1; |
||
2163 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
2164 | } |
||
11874 | schaersvoo | 2165 | for(i=0 ;i < 4 ; i++){ |
7614 | schaersvoo | 2166 | switch(i){ |
11806 | schaersvoo | 2167 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
2168 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
11874 | schaersvoo | 2169 | case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */ |
2170 | case 3: URL = get_string_argument(infile,1); |
||
14208 | schaersvoo | 2171 | string_length = 1 + snprintf(NULL,0, "draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]); |
2172 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11874 | schaersvoo | 2173 | snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]); |
11806 | schaersvoo | 2174 | add_to_buffer(tmp_buffer); |
11874 | schaersvoo | 2175 | fill_cnt++; |
11806 | schaersvoo | 2176 | break; |
7614 | schaersvoo | 2177 | } |
2178 | } |
||
11806 | schaersvoo | 2179 | reset(); |
2180 | break; |
||
14066 | bpr | 2181 | |
14038 | schaersvoo | 2182 | case IMAGEPALETTE: |
2183 | /* |
||
2184 | @ imagepalette image1,image2,image3,... |
||
14379 | bpr | 2185 | @ if used before and together with command <a href='#multidraw'>multidraw images,..,..., etc</a> the image will be presented in a small table in the ''control panel``. |
14246 | bpr | 2186 | @%imagepalette%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Ariel%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%inputstyle color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %# \u222D ---> u222D at least will sometimes work%# otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images |
14038 | schaersvoo | 2187 | */ |
2188 | temp = get_string(infile,1); |
||
2189 | temp = str_replace(temp,",","\",\""); |
||
2190 | if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");} |
||
2191 | fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp); |
||
2192 | break; |
||
14066 | bpr | 2193 | |
11806 | schaersvoo | 2194 | case INPUTSTYLE: |
2195 | /* |
||
2196 | @ inputstyle style_description |
||
14071 | bpr | 2197 | @ may be used before any ''style-able`` html object (like inputfields or buttons) or any html objects that are generated by some canvasdraw commands |
12107 | schaersvoo | 2198 | @%inputstyle%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt;text-align:center%input 0,0,10,1,Hello |
11806 | schaersvoo | 2199 | */ |
2200 | input_style = get_string(infile,1); |
||
7614 | schaersvoo | 2201 | break; |
11806 | schaersvoo | 2202 | case INPUT: |
2203 | /* |
||
2204 | @ input x,y,size,editable,value |
||
2205 | @ to set inputfield "readonly", use editable = 0 |
||
2206 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
||
14385 | bpr | 2207 | @ 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>. |
14066 | bpr | 2208 | @ may be further controlled by <a href="#inputstyle">inputstyle</a> (inputcss is not yet implemented...) |
11806 | schaersvoo | 2209 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
2210 | @ use keyword <a href='#xoffset'>xoffset | centered</a> if the inputfield should be centered on (x:y)<br /> default is the left top corner is (x:y) |
||
13953 | schaersvoo | 2211 | @ if the student must place an inputfield(s) somewhere on the canvas, use command <a href="#userdraw">userdraw input,color</a> or make use of a command like <a href="#userdraw">userdraw text,color</a> |
2212 | @%input%size 400,400%xrange -10,10%yrange -10,10%linewidth 6%point 1,2,red%input 1,2,5,1, ?%point -5,5,red%input -5,5,5,1, ?%point 6,-5,red%input 6,-5,5,1, ?%point -5,-8,red%input -5,-8,5,1, ? |
||
11806 | schaersvoo | 2213 | */ |
2214 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
||
2215 | for(i = 0 ; i<5;i++){ |
||
2216 | switch(i){ |
||
2217 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
2218 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
2219 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
2220 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
2221 | case 4: |
||
2222 | temp = get_string_argument(infile,1); |
||
14208 | schaersvoo | 2223 | string_length = 1 + snprintf(NULL,0, "draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp,use_offset); |
2224 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 2225 | snprintf(tmp_buffer,string_length,"draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp,use_offset); |
2226 | add_to_buffer(tmp_buffer); |
||
2227 | input_cnt++;break; |
||
2228 | default: break; |
||
2229 | } |
||
2230 | } |
||
2231 | if(reply_format == 0 ){reply_format = 15;} |
||
2232 | reset(); |
||
2233 | break; |
||
8386 | schaersvoo | 2234 | |
11806 | schaersvoo | 2235 | case INTOOLTIP: |
2236 | /* |
||
2237 | @ intooltip link_text |
||
2238 | @ link_text is a single line (span-element) |
||
14071 | bpr | 2239 | @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''$module_dir/gifs/my_image.jpg`` |
11806 | schaersvoo | 2240 | @ link_text may contain HTML markup |
14071 | bpr | 2241 | @ the canvas will be displayed in a tooltip on ''link_text`` |
14380 | bpr | 2242 | @ the canvas is default transparent: use command <a href="#bgcolor">bgcolor color</a> to adjust background-color, the link text will also be shown with this ''bgcolor``. |
14071 | bpr | 2243 | @ many ''userinput stuff`` will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefore these commands are mutually exclusive.<br />keep this in mind... |
14246 | bpr | 2244 | @%intooltip%size 400,400%xrange -10,10%yrange -10,10%fontfamily Bold 42pt Courier%string black,0,0,Hello World%intooltip <span style="background-color:black;color:white;font-style:bold;font-size:48pt;">CLICK <br />HERE</span> |
11806 | schaersvoo | 2245 | */ |
2246 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");} |
||
2247 | if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");} |
||
2248 | tooltip_text = get_string(infile,1); |
||
2249 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
2250 | use_tooltip = 1; |
||
2251 | break; |
||
2252 | |||
2253 | case JSCURVE: |
||
7614 | schaersvoo | 2254 | /* |
11893 | schaersvoo | 2255 | @ jscurve color,formula1(x),formula2(x),formula3(x),... |
14071 | bpr | 2256 | @ alternative: <code>jsplot color,formula(x)</code> |
11893 | schaersvoo | 2257 | @ your function will be plotted by the javascript engine of the client browser |
2258 | @ if <a href='trange'>trange</a> is defined, the two functions will be plotted parametric<br /><b>note</b>: use <i>x</i> as variable...and not <i>t</i>. Use keyword <a href='#animate'>animate</a> to animate a point on the curve |
||
14071 | bpr | 2259 | @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code> |
2260 | @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...) |
||
2261 | @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot ! |
||
11806 | schaersvoo | 2262 | @ no validity check is done by wims. |
14380 | bpr | 2263 | @ 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 |
11806 | schaersvoo | 2264 | @ zooming & panning is better than for curves produced by command <a href="#curve">curve color,formula</a> because for avery change in x/y-range the curve is recalculated in javascript |
11893 | schaersvoo | 2265 | @ use keyword <a href='animate'>animate</a> for animating a point on the curve |
14071 | bpr | 2266 | @ use command ''trace_jscurve formula(x)`` for tracing |
14246 | bpr | 2267 | @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve |
11806 | schaersvoo | 2268 | @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet) |
14071 | bpr | 2269 | @ commands plotjump / plotstep are not active for ''jscurve`` |
11806 | schaersvoo | 2270 | @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve. |
14071 | bpr | 2271 | @ plotting multiple js-curves on the same canvas (for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111, use:<br/> <code>jscurve red,fun1(x),fun2(x)...fun_n(x)</code>, you must specify individual multistrokecolors & multistrokeopacity & multilinewidth for these multiple js-curves to use different colors. Otherwise all curves will be the same color... Use commands like: <a href="#multistrokecolors">multistrokecolors</a>, <a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a>, <a href="#multistrokeopacity">multistroke</a>, <b>color</b> given for the command <code>jscurve color,formulas(x)</code> will not be used in that case... but the color argument must still be given in any case (otherwise syntax error...) |
14622 | schaersvoo | 2272 | @%jscurve%size 400,400%xrange -10,10%yrange -10,10%multistrokecolors red,green,blue,orange%multilinewidth 1,2,3%multistrokeopacity 0.5,0.8,1.0%jscurve red,sin(x),1/sin(x),sin(x^2) |
11806 | schaersvoo | 2273 | */ |
2274 | stroke_color = get_color(infile,0); |
||
2275 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
2276 | add_to_js_math(js_include_file); |
||
2277 | use_js_math = TRUE; |
||
2278 | } |
||
2279 | if( use_js_plot == FALSE){ |
||
2280 | use_js_plot = TRUE; |
||
2281 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
2282 | } |
||
11893 | schaersvoo | 2283 | int use_paramteric = 0; |
2284 | if( tmin != 0 && tmax !=0){use_parametric = 1;} |
||
11806 | schaersvoo | 2285 | temp = get_string(infile,1); |
2286 | temp = str_replace(temp,",","\",\""); |
||
14208 | schaersvoo | 2287 | string_length = 1 + snprintf(NULL,0, "jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate); |
2288 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11893 | schaersvoo | 2289 | snprintf(tmp_buffer,string_length,"jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate); |
11806 | schaersvoo | 2290 | add_to_buffer(tmp_buffer); |
2291 | jsplot_cnt++; |
||
2292 | /* we need to create multiple canvasses, so we may zoom and pan ?? */ |
||
2293 | break; |
||
2294 | |||
2295 | case JSMATH: |
||
2296 | /* |
||
2297 | @ jsmath some_math_function |
||
2298 | @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates. |
||
14246 | bpr | 2299 | @ default labels ''x`` and ''y``; the commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` will set the label for the input fields |
14077 | bpr | 2300 | @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y`` |
14066 | bpr | 2301 | @ 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... |
11806 | schaersvoo | 2302 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
12111 | schaersvoo | 2303 | @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2) |
11806 | schaersvoo | 2304 | */ |
2305 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
2306 | if( use_js_math == FALSE){ |
||
2307 | add_to_js_math(js_include_file); |
||
2308 | use_js_math = TRUE; |
||
2309 | } |
||
2310 | add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style); |
||
2311 | break; |
||
2312 | case KILLAFFINE: |
||
2313 | /* |
||
2314 | @ killaffine |
||
14066 | bpr | 2315 | @ keyword: resets the transformation matrix to 1,0,0,1,0,0 |
11806 | schaersvoo | 2316 | */ |
14548 | schaersvoo | 2317 | if( use_affine == TRUE ){ |
2318 | use_affine = FALSE; |
||
2319 | affine_matrix="[1,0,0,1,0,0]"; |
||
2320 | } |
||
11806 | schaersvoo | 2321 | break; |
2322 | |||
2323 | case KILLROTATE: |
||
2324 | /* |
||
14071 | bpr | 2325 | @ killrotate |
2326 | @ will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a> |
||
11806 | schaersvoo | 2327 | @ a following rotate command will have the first object point as rotation center |
2328 | @ if not set, the rotation center will remain unchanged |
||
2329 | */ |
||
14549 | schaersvoo | 2330 | rotation_center="null";; |
2331 | angle = 0.0; |
||
11806 | schaersvoo | 2332 | break; |
2333 | |||
2334 | case KILLSLIDER: |
||
2335 | /* |
||
2336 | @ killslider |
||
2337 | @ keyword (no arguments required) |
||
2338 | @ ends grouping of object under a previously defined slider |
||
2339 | */ |
||
14208 | schaersvoo | 2340 | slider_type = "0"; |
2341 | current_sliders = "[-1]"; |
||
14234 | schaersvoo | 2342 | for(i=0;i<slider_cnt;i++){active_sliders[i]=-1;} |
11806 | schaersvoo | 2343 | break; |
2344 | |||
2345 | case KILLTRANSLATION: |
||
2346 | /* |
||
2347 | @ killtranslation |
||
14071 | bpr | 2348 | @ alternative: <code>killtranslate</code> |
11806 | schaersvoo | 2349 | @ resets the translation matrix to 1,0,0,1,0,0 |
2350 | */ |
||
14548 | schaersvoo | 2351 | if(use_affine == TRUE ){ |
2352 | use_affine = FALSE; |
||
2353 | affine_matrix="[1,0,0,1,0,0]"; |
||
2354 | } |
||
11806 | schaersvoo | 2355 | break; |
14225 | schaersvoo | 2356 | case LATEX: |
2357 | /* |
||
2358 | @ latex x,y,latex string |
||
14385 | bpr | 2359 | @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br />if 4 clickable objects are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
14379 | bpr | 2360 | @ can be set draggable: <code>javascript:read_dragdrop();</code> will return all coordinates in the same order as the canvas script: unmoved object will have their original coordinates... |
14230 | schaersvoo | 2361 | @ snaptogrid is supported...snaptopoints will work, but use with care...due to the primitive dragging<br />technically: the dragstuff library is not used...the mathml is embedded in a new div element and not in the html5-canvas |
2362 | @ when clicked, the mathml object will be drawn in red color; the div background color will be determined by the <a href="#fillcolor">fillcolor</a> and <a href="#opacity">opacity</a> settings |
||
14380 | bpr | 2363 | @ userdraw may be combined with ''mathml`` ; the read_canvas() will contain the drawing. |
14246 | bpr | 2364 | @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml |
14230 | schaersvoo | 2365 | @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
14379 | bpr | 2366 | @ 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 <code>javascript:read_mathml();</code>. <b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();" |
2367 | @ If other inputfields (command input / command textarea) or userdraw are performed, the function read_canvas() will not read mathml. Use some generic function to read it.... |
||
14225 | schaersvoo | 2368 | @ use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1) |
14230 | schaersvoo | 2369 | @%latex_drag%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%snaptogrid%strokecolor red%drag xy%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%drag xy%snaptogrid%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%drag xy%snaptogrid%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%drag xy%snaptogrid%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6} |
2370 | @%latex_onclick%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%strokecolor red%onclick%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%onclick%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%onclick%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%onclick%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6} |
||
14225 | schaersvoo | 2371 | */ |
2372 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
||
14227 | schaersvoo | 2373 | drag_type=-1; /* hmmm */ |
14225 | schaersvoo | 2374 | for(i=0;i<4;i++){ |
2375 | switch(i){ |
||
2376 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
2377 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
2378 | case 2: decimals = find_number_of_digits(precision); |
||
14233 | schaersvoo | 2379 | temp = get_string(infile,1); |
14232 | schaersvoo | 2380 | /* !!!! UNTIL MATHJAX IS REPLACED BY KATEX !!!! */ |
14590 | schaersvoo | 2381 | browser_type = 1; |
14230 | schaersvoo | 2382 | if(browser_type == 1 ){ /* GECKO needs TEX --> MML */ |
2383 | temp = getMML(temp); |
||
2384 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
2385 | string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
||
2386 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2387 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
||
2388 | } |
||
2389 | else |
||
2390 | { |
||
2391 | if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); } |
||
2392 | string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"<div name='zoom_0' class='wims_katex' id='katex%d'>%s</div>\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],click_cnt,temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
||
2393 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2394 | snprintf(tmp_buffer,string_length, "draw_xml(%d,%d,%d,\"<div name='zoom_0' class='wims_katex' id='katex%d'>%s</div>\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],click_cnt,temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
||
2395 | } |
||
14225 | schaersvoo | 2396 | add_to_buffer(tmp_buffer); |
2397 | if(onclick == 1 || onclick == 2 ){click_cnt++;} |
||
2398 | use_offset = 0; |
||
2399 | break; |
||
2400 | default:break; |
||
2401 | } |
||
2402 | } |
||
2403 | break; |
||
14230 | schaersvoo | 2404 | case LATTICE: |
2405 | /* |
||
2406 | @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
2407 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` |
||
2408 | @%lattice%size 400,400%xrange -10,10%yrange -10,10%fillcolor red%linewidth 2%lattice -10,-10,0,1,1,1,10,10,red%fillcolor blue%lattice 10,-10,0,1,-1,1,10,10,blue |
||
2409 | */ |
||
2410 | if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;} |
||
2411 | for( i = 0; i<9; i++){ |
||
2412 | switch(i){ |
||
2413 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
||
2414 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
2415 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
2416 | case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values -> y-pixels*/ |
||
2417 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
||
2418 | case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values -> y-pixels*/ |
||
2419 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
||
2420 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
2421 | case 8: stroke_color=get_color(infile,1); |
||
2422 | decimals = find_number_of_digits(precision); |
||
2423 | string_length = 1 + snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s,%d); ",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,use_filled); |
||
2424 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2425 | 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,%d); ",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,use_filled); |
||
2426 | add_to_buffer(tmp_buffer);break; |
||
2427 | default:break; |
||
2428 | } |
||
2429 | } |
||
2430 | reset(); |
||
2431 | break; |
||
2432 | |||
11806 | schaersvoo | 2433 | case LINE: |
2434 | /* |
||
2435 | @ line x1,y1,x2,y2,color |
||
14379 | bpr | 2436 | @ draw a line through points (x1:y1)--(x2:y2) in color ''color`` |
14385 | bpr | 2437 | @ or use command ''curve color,formula`` to draw the line (uses more points to draw the line; is however better draggable). |
9406 | schaersvoo | 2438 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 2439 | @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green |
7614 | schaersvoo | 2440 | */ |
8386 | schaersvoo | 2441 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 2442 | switch(i){ |
11806 | schaersvoo | 2443 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
2444 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
2445 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
2446 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
2447 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
2448 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
2449 | double_data[1] = xmin; |
||
2450 | double_data[3] = ymax; |
||
2451 | double_data[0] = double_data[10]; |
||
2452 | double_data[2] = double_data[10]; |
||
2453 | } |
||
2454 | else |
||
2455 | { |
||
2456 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
2457 | double_data[1] = double_data[11]; |
||
2458 | double_data[3] = double_data[11]; |
||
2459 | double_data[0] = ymin; |
||
2460 | double_data[2] = xmax; |
||
2461 | } |
||
2462 | else |
||
2463 | { |
||
2464 | /* m */ |
||
2465 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
2466 | /* q */ |
||
2467 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
2468 | |||
2469 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2470 | |||
2471 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
||
2472 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
2473 | double_data[0] = xmin; |
||
2474 | double_data[2] = xmax; |
||
2475 | } |
||
2476 | } |
||
2477 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 2478 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
2479 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 2480 | /* click_cnt++;*/ |
2481 | reset(); |
||
2482 | break; |
||
7614 | schaersvoo | 2483 | } |
2484 | } |
||
2485 | break; |
||
8386 | schaersvoo | 2486 | |
11806 | schaersvoo | 2487 | case LINES: |
8370 | schaersvoo | 2488 | /* |
11806 | schaersvoo | 2489 | @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n |
14380 | bpr | 2490 | @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color ''color`` |
14385 | bpr | 2491 | @ or use multiple commands ''curve color,formula`` or ''jscurve color,formule`` to draw the line (uses more points to draw the line; is however better draggable). |
11806 | schaersvoo | 2492 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 2493 | @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a> |
12107 | schaersvoo | 2494 | @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1 |
8370 | schaersvoo | 2495 | */ |
2496 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2497 | fill_color = stroke_color; |
||
2498 | i=0; |
||
2499 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2500 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8370 | schaersvoo | 2501 | if(i%2 == 0 ){ |
2502 | double_data[i] = get_real(infile,0); /* x */ |
||
2503 | } |
||
2504 | else |
||
2505 | { |
||
2506 | double_data[i] = get_real(infile,1); /* y */ |
||
2507 | } |
||
2508 | i++; |
||
2509 | } |
||
2510 | decimals = find_number_of_digits(precision); |
||
2511 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 2512 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
2513 | double_data[c+1] = xmin; |
||
2514 | double_data[c+3] = ymax; |
||
2515 | double_data[c+2] = double_data[c]; |
||
2516 | } |
||
2517 | else |
||
2518 | { |
||
2519 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
2520 | double_data[c+3] = double_data[c+1]; |
||
2521 | double_data[c] = ymin; |
||
2522 | double_data[c+2] = xmax; |
||
2523 | } |
||
2524 | else |
||
2525 | { |
||
2526 | /* m */ |
||
2527 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
2528 | /* q */ |
||
2529 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
2530 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2531 | double_data[c+1] = (m)*(xmin)+(q); |
||
2532 | double_data[c+3] = (m)*(xmax)+(q); |
||
2533 | double_data[c] = xmin; |
||
2534 | double_data[c+2] = xmax; |
||
2535 | } |
||
2536 | } |
||
14208 | schaersvoo | 2537 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
2538 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 2539 | /* click_cnt++; */ |
8370 | schaersvoo | 2540 | } |
2541 | reset(); |
||
2542 | break; |
||
8386 | schaersvoo | 2543 | |
11806 | schaersvoo | 2544 | |
2545 | case LINEWIDTH: |
||
7614 | schaersvoo | 2546 | /* |
11806 | schaersvoo | 2547 | @ linewidth int |
2548 | @ default 1 |
||
12107 | schaersvoo | 2549 | @%linewidth%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%line -5,-5,-5,5,red%linewidth 2%line -4,-5,-4,5,green%linewidth 3%line -3,-5,-3,5,blue%linewidth 4%line -2,-5,-2,5,orange%linewidth 1%line -1,-5,-1,5,brown%linewidth 5%line 1,-5,1,5,cyan%linewidth 6%line 3,-5,3,5,purple%linewidth 7%line 5,-5,5,5,black |
7614 | schaersvoo | 2550 | */ |
11806 | schaersvoo | 2551 | line_width = (int) (get_real(infile,1)); |
2552 | break; |
||
2553 | |||
2554 | case LEVELCURVE: |
||
8363 | schaersvoo | 2555 | /* |
11806 | schaersvoo | 2556 | @ levelcurve color,expression in x/y,l1,l2,... |
14385 | bpr | 2557 | @ draws very primitive level curves for expression, with levels l1,l2,l3,...,ln |
2558 | @ the quality is <b>not to be compared</b> with the Flydraw levelcurve (choose flydraw if you want quality...). |
||
2559 | @ every individual level curve may be set ''onclick / drag xy`` e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier. |
||
2560 | @ note: the arrays for holding the javascript data are limited in size. |
||
2561 | @ note: reduce image size if javascript data arrays get overloaded (command ''plotsteps int`` will not control the data size of the plot...). |
||
12107 | schaersvoo | 2562 | @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4 |
8363 | schaersvoo | 2563 | */ |
11806 | schaersvoo | 2564 | fill_color = get_color(infile,0); |
2565 | char *fun1 = get_string_argument(infile,0); |
||
2566 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
2567 | i = 0; |
||
2568 | done = FALSE; |
||
2569 | while( !done ){ |
||
2570 | double_data[i] = get_real(infile,1); |
||
2571 | i++; |
||
2572 | } |
||
2573 | for(c = 0 ; c < i; c++){ |
||
14208 | schaersvoo | 2574 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
2575 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 2576 | /* click_cnt++; */ |
2577 | } |
||
2578 | reset(); |
||
2579 | break; |
||
8386 | schaersvoo | 2580 | |
11806 | schaersvoo | 2581 | case LEGEND: |
2582 | /* |
||
2583 | @ legend string1:string2:string3....string_n |
||
2584 | @ will be used to create a legend for a graph |
||
14066 | bpr | 2585 | @ also see command <a href='#piechart'>piechart</a> |
14071 | bpr | 2586 | @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default |
14385 | bpr | 2587 | @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``). |
14066 | bpr | 2588 | @%legend%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%fontsize 16%legend legend 1:legend 2:legend 3:legend 4:this is legend 5:legend 6:another legend abc%legendcolors red:green:blue%grid 1,1,white%# note: command "grid" is mandatory%# just set grid invisible if not wanted |
11806 | schaersvoo | 2589 | */ |
2590 | temp = get_string(infile,1); |
||
2591 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
14066 | bpr | 2592 | legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */ |
11806 | schaersvoo | 2593 | fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp); |
2594 | break; |
||
2595 | |||
2596 | case LEGENDCOLORS: |
||
2597 | /* |
||
2598 | @ legendcolors color1:color2:color3:...:color_n |
||
14379 | bpr | 2599 | @ will be used to color a legend: use this command after the legend command ! e.g. <code>legend test1:test2:test3<br />legendcolors blue:red:orange</code>. |
2600 | @ make sure the number of colors match the number of legend items |
||
14385 | bpr | 2601 | @ command ''legend`` in case of ''piechart`` and ''barchart`` will use these colours per default (no need to specify ''legendcolors``). |
13960 | bpr | 2602 | @%legendcolors%size 400,400%xrange -10,10%yrange -10,10%fontsize 18%legend legend 1:legend 2:legend 3%legendcolors red:green:blue%grid 1,1,grey |
11806 | schaersvoo | 2603 | */ |
2604 | if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");} |
||
2605 | temp = get_string(infile,1); |
||
2606 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2607 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp); |
||
2608 | break; |
||
2609 | |||
14078 | bpr | 2610 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
11806 | schaersvoo | 2611 | /* |
2612 | @ linegraph x1:y1:x2:y2...x_n:y_n |
||
2613 | @ will plot your data in a graph |
||
14066 | bpr | 2614 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
2615 | @ 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> |
||
2616 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
2617 | @ also see command <a href='#piechart'>piechart</a> |
||
11806 | schaersvoo | 2618 | @ multiple linegraphs may be used in a single plot |
14066 | bpr | 2619 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
14379 | bpr | 2620 | @ <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> |
12107 | schaersvoo | 2621 | @%linegraph%size 400,400%xrange -10,10%yrange -10,10%strokecolor red%linegraph -10:1:-5:-1:3:3:10:-5%strokecolor blue%linegraph -10:-1:-5:1:3:-3:10:5%dashed%strokecolor green%linegraph -10:2:-5:-2:3:4:10:2%grid 1,1,grey |
11806 | schaersvoo | 2622 | */ |
2623 | temp = get_string(infile,1); |
||
2624 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2625 | 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); |
||
2626 | linegraph_cnt++; |
||
2627 | reset(); |
||
2628 | break; |
||
2629 | |||
2630 | case MATHML: |
||
2631 | /* |
||
2632 | @ mathml x1,y1,x2,y2,mathml_string |
||
14230 | schaersvoo | 2633 | @ this command is special for GECKO browsers, and it makes use of Native Mathml |
14379 | bpr | 2634 | @ For use with all browsers, use command <a href='#latex'>latex</a> |
14038 | schaersvoo | 2635 | @ the mathml object is centered at (x1:y1) |
14379 | bpr | 2636 | @ the ''mathml_string`` can be produced using WIMS commands like ''texmath`` followed by ''mathmlmath``... or write correct TeX and use only ''mathmlmath`` |
13829 | bpr | 2637 | @ mathml will be displayed in a rectangle left top (x1:y1)...<br />x2 and y2 are still needed, but not used as the right bottom corner of the embedded div element. |
14246 | bpr | 2638 | @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor of the mathml object |
14247 | bpr | 2639 | @ can be set onclick <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects; if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
14379 | bpr | 2640 | @ can be set draggable: <code>javascript:read_dragdrop()</code> will return all coordinates in same order as the canvas script: unmoved objects will have their original coordinates... |
14247 | bpr | 2641 | @ snaptogrid is supported...snaptopoints will work, but use with care... due to the primitive dragging. Technically: the dragstuff library is not used... the mathml is embedded in a new div element and not in the html5-canvas. |
2642 | @ when clicked, the mathml object will be drawn in red color; the div background color will be determined by the <a href="#fillcolor">fillcolor</a> and <a href="#opacity">opacity</a> settings. |
||
14380 | bpr | 2643 | @ userdraw may be combined with ''mathml`` ; the read_canvas() will contain the drawing. |
14385 | bpr | 2644 | @ draggable or onclick ''external images`` from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml |
14078 | bpr | 2645 | @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
14066 | bpr | 2646 | @ 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();" |
11806 | schaersvoo | 2647 | @ 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.... |
14038 | schaersvoo | 2648 | @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1) |
14246 | bpr | 2649 | @%mathml_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%strokecolor red%mathml -5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines=" none " ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>⋅</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%onclick%strokecolor blue%mathml 5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines="none"><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span> |
2650 | @%mathml_drag%size 400,400%xrange -10,10%yrange -10,10%drag xy%strokecolor red%mathml -5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines=" none "><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>⋅</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%drag xy%strokecolor blue%mathml 5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines=" none "><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%#click left top corner...then drag... |
||
11806 | schaersvoo | 2651 | */ |
14227 | schaersvoo | 2652 | if( browser_type == 0 ){ break;} /* should use command latex */ |
14062 | schaersvoo | 2653 | if(use_offset == 0){use_offset = 4;} /* always centered if not otherwise stated ! */ |
11806 | schaersvoo | 2654 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
2655 | for(i=0;i<5;i++){ |
||
2656 | switch(i){ |
||
2657 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
14032 | schaersvoo | 2658 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
14066 | bpr | 2659 | case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow */ |
2660 | case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */ |
||
11806 | schaersvoo | 2661 | case 4: decimals = find_number_of_digits(precision); |
2662 | temp = get_string(infile,1); |
||
2663 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
14208 | schaersvoo | 2664 | string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
2665 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
14044 | schaersvoo | 2666 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
11806 | schaersvoo | 2667 | add_to_buffer(tmp_buffer); |
2668 | if(onclick == 1 || onclick == 2 ){click_cnt++;} |
||
14038 | schaersvoo | 2669 | use_offset=0; |
11806 | schaersvoo | 2670 | /* |
14078 | bpr | 2671 | in case inputs are present, trigger adding the read_mathml() |
11806 | schaersvoo | 2672 | if no other reply_format is defined |
2673 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
2674 | */ |
||
2675 | if(strstr(temp,"mathml0") != NULL){ |
||
2676 | if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */ |
||
2677 | } |
||
2678 | break; |
||
2679 | default:break; |
||
2680 | } |
||
2681 | } |
||
2682 | break; |
||
2683 | |||
2684 | case MOUSE: |
||
2685 | /* |
||
2686 | @ mouse color,fontsize |
||
14379 | bpr | 2687 | @ will display the cursor (x:y) coordinates in ''color`` and ''fontsize`` using default fontfamily Ariel |
2688 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``) |
||
12107 | schaersvoo | 2689 | @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22 |
11806 | schaersvoo | 2690 | */ |
2691 | stroke_color = get_color(infile,0); |
||
2692 | font_size = (int) (get_real(infile,1)); |
||
2693 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2694 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2695 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2); |
2696 | break; |
||
2697 | |||
2698 | |||
2699 | case MOUSE_DEGREE: |
||
2700 | /* |
||
2701 | @ mouse_degree color,fontsize |
||
14385 | bpr | 2702 | @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in ''color`` and ''font size`` using a fontfamily Ariel |
11806 | schaersvoo | 2703 | @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV |
14380 | bpr | 2704 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``) |
12107 | schaersvoo | 2705 | @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22 |
11806 | schaersvoo | 2706 | */ |
2707 | stroke_color = get_color(infile,0); |
||
2708 | font_size = (int) (get_real(infile,1)); |
||
2709 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2710 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2711 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3); |
2712 | js_function[JS_FIND_ANGLE] = 1; |
||
2713 | break; |
||
2714 | case MOUSE_DISPLAY: |
||
2715 | /* |
||
2716 | @ display TYPE,color,fontsize |
||
14380 | bpr | 2717 | @ TYPE may be <code>x | y | xy | degree | radian | radius</code>. |
2718 | @ will display the mouse cursor coordinates as x-only,y-only,(x:y), the radius of a circle (this only in case <code>userdraw circle(s),color</code>) or the angle in degrees or radians for commands <code>userdraw arc,color</code> or protractor, ruler (if set dynamic). |
||
14385 | bpr | 2719 | @ use commands ''xunit`` and / or ''yunit`` to add the units to the mouse values. The ''degree | radian`` will always have the appropriate symbol). |
14077 | bpr | 2720 | @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name |
12111 | schaersvoo | 2721 | @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22 |
12107 | schaersvoo | 2722 | @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22 |
13936 | bpr | 2723 | @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue |
12107 | schaersvoo | 2724 | @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue |
2725 | @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue |
||
12111 | schaersvoo | 2726 | @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue |
11806 | schaersvoo | 2727 | */ |
2728 | temp = get_string_argument(infile,0); |
||
2729 | if( strstr(temp,"xy") != NULL ){ |
||
2730 | int_data[0] = 2; |
||
2731 | }else{ |
||
2732 | if( strstr(temp,"y") != NULL ){ |
||
2733 | int_data[0] = 1; |
||
2734 | }else{ |
||
2735 | if( strstr(temp,"x") != NULL ){ |
||
2736 | int_data[0] = 0; |
||
2737 | }else{ |
||
2738 | if(strstr(temp,"degree") != NULL){ |
||
2739 | int_data[0] = 3; |
||
2740 | js_function[JS_FIND_ANGLE] = 1; |
||
2741 | }else{ |
||
2742 | if(strstr(temp,"radian") != NULL){ |
||
2743 | int_data[0] = 4; |
||
2744 | js_function[JS_FIND_ANGLE] = 1; |
||
2745 | }else{ |
||
2746 | if(strstr(temp,"radius") != NULL){ |
||
2747 | int_data[0] = 5; |
||
2748 | }else{ |
||
2749 | int_data[0] = 2; |
||
2750 | } |
||
2751 | } |
||
2752 | } |
||
2753 | } |
||
2754 | } |
||
2755 | } |
||
2756 | stroke_color = get_color(infile,0); |
||
2757 | font_size = (int) (get_real(infile,1)); |
||
2758 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2759 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2760 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]); |
2761 | break; |
||
2762 | |||
2763 | case MOUSE_PRECISION: |
||
2764 | /* |
||
2765 | @ precision int |
||
2766 | @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc |
||
2767 | @ may be used / changed before every object |
||
14385 | bpr | 2768 | @ In case of user interaction (like ''userdraw`` or ''multidraw``), this value will be used to determine the amount of decimals in the reply / answer. |
13936 | bpr | 2769 | @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red |
11806 | schaersvoo | 2770 | */ |
2771 | precision = (int) (get_real(infile,1)); |
||
2772 | if(precision < 1 ){precision = 1;}; |
||
2773 | break; |
||
2774 | |||
2775 | case MOUSEX: |
||
2776 | /* |
||
2777 | @ mousex color,fontsize |
||
14247 | bpr | 2778 | @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Ariel. |
2779 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``). |
||
11806 | schaersvoo | 2780 | |
2781 | */ |
||
2782 | stroke_color = get_color(infile,0); |
||
2783 | font_size = (int) (get_real(infile,1)); |
||
2784 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2785 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2786 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0); |
2787 | break; |
||
2788 | case MOUSEY: |
||
2789 | /* |
||
2790 | @ mousey color,fontsize |
||
14247 | bpr | 2791 | @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Ariel. |
2792 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``). |
||
11806 | schaersvoo | 2793 | |
2794 | */ |
||
2795 | stroke_color = get_color(infile,0); |
||
2796 | font_size = (int) (get_real(infile,1)); |
||
2797 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2798 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2799 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1); |
2800 | break; |
||
2801 | |||
2802 | case MULTIDASH: |
||
2803 | /* |
||
2804 | @ multidash 0,1,1 |
||
14071 | bpr | 2805 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, are dashed |
14066 | bpr | 2806 | @ use before command <a href='#multidraw'>multidraw</a> |
14247 | bpr | 2807 | @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw`` |
14380 | bpr | 2808 | @ the dash-type is not -yet- adjustable (e.g. command <code>dashtype line_px,space_px</code> will give no control over multidraw objects) |
11806 | schaersvoo | 2809 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14077 | bpr | 2810 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2811 | */ |
2812 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2813 | temp = get_string(infile,1); |
||
2814 | temp = str_replace(temp,",","\",\""); |
||
2815 | fprintf(js_include_file,"var multidash = [\"%s\"];",temp); |
||
2816 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
2817 | break; |
||
2818 | |||
2819 | case MULTIDRAW: |
||
2820 | /* |
||
2821 | @ multidraw obj_type_1,obj_type_2...obj_type_11 |
||
14066 | bpr | 2822 | @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a> |
14385 | bpr | 2823 | @ implemented obj_types:<ul><li>''point | points``</li><li>''circle | circles``</li><li>''line | lines``</li><li>''segment | segments``</li><li>''arrow | arrows`` (use command ''arrowhead int`` for size, default value 8 pixels)</li><li>''curvedarrow | curvedarrows``</li><li>''rect | rects``</li><li>''closedpoly``: <b>only one</b> closedpolygon may be drawn.The number of corner points is not preset (e.g. not limited, freestyle), the polygon is closed when clicking on the first point again..(+/- 10px)</li><li>''triangle | triangles``</li><li>''parallelogram | parallelograms``</li><li>''poly[3-9] | polys[3-9] `` draw 3...9 point polygone(s): polys3 is of course triangles</li><li>''images``</li></ul> |
2824 | @ additionally objects may be user labelled, using obj_type ''text``... in this case always a text input field and if <a href='#multiuserinput'> multiuserinput=1 </a> also (x:y) inputfields will be added to the page.<br />use commands ''fontfamily`` and ''fontcolor`` to adjust (command ''multistrokeopacity`` may be set to adjust text opacity)<br />note: text is always centered on the mouse-click or user-input coordinates !<br />note: no keyboard listeners are used |
||
2825 | @ it makes no sense using something like <code>multidraw point,points</code> ... <br />something like <code>multidraw polys4,polys7</code> will only result in drawing a ''4 point polygone`` and not a ''7 point polygone``: this is a design flaw and not a feature... |
||
2826 | @ note: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise). To overrule, use command/keyword ''status`` (no arguments required). |
||
2827 | @ buttons for changing the obj_type (and in case 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``. |
||
14380 | bpr | 2828 | @ the button label will be default the ''object primitive name`` (like ''point``, ''circles``). If you want a different label (e.g. an other language), use command ''multilabel``. For example in dutch: <code>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</code> (see command <a href='#multilabel'>multilabel</a> for more details). |
14063 | schaersvoo | 2829 | @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed |
14385 | bpr | 2830 | @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons). |
14380 | bpr | 2831 | @ all ''multidraw`` drawings will scale on zooming, this in contrast to the command <a href="#userdraw">userdraw</a>. |
2832 | @ wims will <b>not</b> check the amount or validity of your command arguments ! use javascript console to debug any typo. |
||
14385 | bpr | 2833 | @ a local function <code>read_canvas%d</code> will read all userbased drawings. The output is always a 16 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circles_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 = polys[3-9]_x+";"+polys[3-9]_y+"\\n"<br/>line 8 = rects_x +";"+rects_y+"\\n"<br />line 9 = closedpoly_x+";"+closedpoly_y+"\\n"<br/>line 10 = parallelogram_x+";"+parallelogram_y"\\n"<br/>line 11 = text_x+";"+text_y+";"+text"\\n"<br />line 12 = image_x+";"+image_y+";"+image_id<br />line 13 = curvedarrows_x +";"+ curvedarrows_y +"\\n"<br />line 14 = curvedarrows2_x +";"+ curvedarrows2_y +"\\n"<br />line 15 = userdraw_x +";"+userdraw_y + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<br/>line 16 = userdraw_x +";"+userdraw_y +";"+userdraw_radius + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<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> |
14380 | bpr | 2834 | @ It is best to prepare / format the student reply in clientside javascript. However in wims language you could use something like this: for example you are interested in the polys5 drawings of a pupil (the pupil may draw multiple poly5 objects...)<br />note: the reply for 2 poly5's is: x11,x12,x13,x14,x15,x21,x22,x23,x24,x25 ; y11,y12,y13,y14,y15,y21,y22,y23,y24,y25<br />rep = !line 7 of reply <br />rep = !translate ';' to '\\n' in $rep <br />pts = 5 # 5 points for polygon <br />x_rep = !line 1 of $rep <br />y_rep = !line 2 of $rep <br />tot = !itemcnt $x_rep <br />num_poly = $[$tot/$pts] <br />idx = 0 <br />!for p=1 to $num_poly <br /> !for s=1 to $pts <br /> !increase idx <br /> X = !item $idx of $x_rep <br /> Y = !item $idx of $y_rep <br /> # do some checking <br /> !next s <br />!next p <br /> |
14379 | bpr | 2835 | @ <b>attention</b>: for command argument ''closedpoly``, only one polygone can be drawn. The last point (e.g. the point clicked near the first point) of the array is removed. |
14380 | bpr | 2836 | @ technical: all 10 ''draw primitives`` + ''text`` will have their own -transparent- PNG bitmap canvas. So for example there can be a points_canvas entirely separated from a line_canvas. This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn), this in contrast too many very slow do-it-all HTML5 canvas javascript libraries. The mouselisteners are attached to the canvas-div element. |
2837 | @ a special object type is ''images``.<br />if used together with <a href='#imagepalette'>imagepalette</a> a image table will be integrated in the 'control section' of multidraw (set <code>multiuserinput 1</code> for ''images``) if not used with <a href='#imagepalette'>imagepalette</a>, provide the images or div's (<img> tag with bitmap or SVG or anything in a div element) somewhere on the html exercise page, with an onclick handler like:<br /><code><img src='gifs/images/dog.svg' onclick='javascript:place_image_on_canvas(this.id);' id="ext_image_1" /><br /><img src='gifs/fish.png' onclick='javascript:place_image_on_canvas(this.id);' id="another" /></code><br />etc ... when activating the multidraw ''image`` button, the images can be selected (left mouse button/onclick) and placed on the canvas...left mouse click. Using div's will enable you -amongst other content- to add math typesetting from the exercise page onto the canvas. |
||
2838 | @ When you are not content with the default ''multidraw control panel``, you can create your own interface, using a few javascript functions to call the drawprimitives, delete things and ''stop drawing`` in case you also want to drag&drop stuff...</br>To activate this feature, use <a href='#multilabel'>multilabel NOCONTROLS</a><br />The object types are internally represented by the following numbers (making typos will render your exercise null and void)<br/>point = 0<br />points =1<br />circle = 2<br />circles = 3<br />line = 4<br />lines = 5<br />segment = 6<br />segments = 7<br />arrow = 8<br />arrows = 9<br />triangle = 10<br />triangles = 11<br />closedspoly = 12<br />text = 13<br />rect = 14<br />rects = 15<br />poly[3-9] = 16<br />polys[3-9] = 17<br />parallelogram = 18<br />parallelograms = 19<br />images = 20<br />curvedarrow = 21<br />curvedarrows = 22<br />curvedarrow2 = 23<br />curvedarrows2 = 24<br />controls for example:<br /><code><input type='button' onclick='javascript:userdraw_primitive=null' value='STOP DRAWING' /><br /><input type='button' onclick='javascript:userdraw_primitive=24;multidraw_click_cnt = 0;' value='start drawing curvedarrows2' /> <br /><input type='button' onclick='javascript:var fun=eval("clear_draw_area"+canvas_scripts[0]);fun(24,0);' value='REMOVE LAST CURVEDARROW ' /> </code><br/> If using multiple canvas scripts in a single page, loop through the <code>canvas_scripts[n]</code>. <br />note: if using NOCONTROLS and just a single draw primitive (for example, just: ''multidraw circles``), the object may be drawn directly (analogue to ''userdraw circles,color``). And since a right mouse button click will always remove the last drawn object of the current object type, there is no need for a special "remove button". |
||
12107 | schaersvoo | 2839 | @%multidraw%size 400,400%xrange -10,10%yrange -10,10%multidash 1,0%multilinewidth 1,2%multistrokecolors red,blue%multisnaptogrid 1,1%multilabel LINES,CIRCLES,STOP DRAWING%multidraw lines,circles |
14246 | bpr | 2840 | @%multidraw_images%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%drag xy%# use special function to read the drag coordinates%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Ariel%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%inputstyle color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %# \u222D ---> u222D at least will sometimes work%# otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images |
14044 | schaersvoo | 2841 | @%multidraw_demo%size 800,800%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%inputstyle color:blue;%fontfamily Italic 42pt Ariel%precision 1%opacity 200,50%snaptogrid%linewidth 3%filled%multistrokecolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,green,purple,black,cyan%multifillcolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,brown,purple%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multidraw closedpoly,segments,rect,parallelogram,triangles,poly5,points,lines,arrows,circles,text,curvedarrows,curvedarrows2,images |
14063 | schaersvoo | 2842 | @%multidraw_NOCONTROLS%size 400,400%%xrange -10,10%yrange -10,10%grid 2,2,grey%linewidth 3%strokecolor green%fillcolor blue%filled%opacity 255,60%multilabel NOCONTROLS%multidraw circles%# RIGHT MOUSE CLICK REMOVES LAST OBJECT |
11806 | schaersvoo | 2843 | */ |
14038 | schaersvoo | 2844 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
11806 | schaersvoo | 2845 | if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");} |
2846 | use_userdraw = TRUE; |
||
2847 | /* LET OP max 6 DRAW PRIMITIVES + TEXT */ |
||
2848 | temp = get_string(infile,1); |
||
2849 | temp = str_replace(temp,",","\",\""); |
||
14044 | schaersvoo | 2850 | /* if these are not set, set the default values for the 18 (more than enough !) draw_primitives + draw_text */ |
14066 | bpr | 2851 | /* int use_snap = 0; 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */ |
14044 | schaersvoo | 2852 | |
11806 | schaersvoo | 2853 | fprintf(js_include_file,"\ |
14044 | schaersvoo | 2854 | if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];}\ |
14038 | schaersvoo | 2855 | if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
2856 | if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
||
2857 | if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
2858 | if( typeof(multifillopacity) === 'undefined' && multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
2859 | if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
2860 | if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
2861 | if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
11806 | schaersvoo | 2862 | if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\ |
14044 | schaersvoo | 2863 | if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput = ['0','0','0','0','0','0','0','0'];};\ |
11806 | schaersvoo | 2864 | var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';", |
14044 | schaersvoo | 2865 | use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap, |
14038 | schaersvoo | 2866 | stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color, |
2867 | fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color, |
||
2868 | stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity, |
||
2869 | fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity, |
||
2870 | line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width, |
||
2871 | use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled, |
||
2872 | use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed, |
||
11806 | schaersvoo | 2873 | temp,arrow_head,font_color,font_family); |
2874 | |||
2875 | if(strstr(temp,"text") != NULL){ |
||
2876 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2877 | } |
||
2878 | |||
2879 | /* the canvasses range from 1000 ... 1008 */ |
||
14038 | schaersvoo | 2880 | add_js_multidraw(js_include_file,canvas_root_id,temp,input_style,use_offset); |
11806 | schaersvoo | 2881 | reply_precision = precision; |
2882 | if( reply_format == 0){reply_format = 29;} |
||
2883 | reset();/* if command 'filled' / 'dashed' was given...reset all */ |
||
2884 | break; |
||
2885 | case MULTILABEL: |
||
2886 | /* |
||
2887 | @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text' |
||
14066 | bpr | 2888 | @ use before command <a href='#multidraw'>multidraw</a> |
14380 | bpr | 2889 | @ 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``...) |
14071 | bpr | 2890 | @ the ''stop drawing`` button text <b>must</b> be the last item on the ''multilabel`` -list <br />for example:<br /><code>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</code> |
14380 | bpr | 2891 | @ all buttons can be ''styled`` by using command <code>inputstyle</code><br /><b>note:</b>If you want to add some CSS style to the buttons... The id's of the ''draw buttons`` are their english command argument (e.g. id="canvasdraw_points" for the draw points button). The id of the ''stop drawing`` button is ''canvasdraw_stop_drawing``, the id of the "OK" button is ''canvasdraw_ok_button``. |
2892 | @ wims will not check the amount or validity of your input. |
||
2893 | @ always use the same sequence as is used for ''multidraw``. |
||
2894 | @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code>. |
||
11806 | schaersvoo | 2895 | */ |
2896 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2897 | temp = get_string(infile,1); |
||
2898 | temp = str_replace(temp,",","\",\""); |
||
2899 | fprintf(js_include_file,"var multilabel = [\"%s\"];",temp); |
||
2900 | break; |
||
2901 | case MULTILINEWIDTH: |
||
2902 | /* |
||
2903 | @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8 |
||
14622 | schaersvoo | 2904 | @ alternative:<code>linewidths</code> |
14066 | bpr | 2905 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2906 | @ if not set all line widths will be set by a previous command ''linewidth int`` |
2907 | @ use these up to 7 different line widths for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code> |
||
11806 | schaersvoo | 2908 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 2909 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2910 | */ |
2911 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2912 | temp = get_string(infile,1); |
||
2913 | temp = str_replace(temp,",","\",\""); |
||
2914 | fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp); |
||
2915 | break; |
||
2916 | case MULTIFILL: |
||
2917 | /* |
||
2918 | @ multifill 0,0,1,0,1,0,0 |
||
14071 | bpr | 2919 | @ meaning draw objects no. 3 and 5, in the list of command ''multifill``, are filled (if the object is fillable...and not a line,segment,arrow or point...) |
14066 | bpr | 2920 | @ use before command <a href='#multidraw'>multidraw</a> |
14246 | bpr | 2921 | @ if not set all objects -except point|points- will be set ''not filled``... unless a command <code>filled</code> was given before command <code>multifill</code> |
14078 | bpr | 2922 | @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles`` and ''polygon`` |
11806 | schaersvoo | 2923 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 2924 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2925 | */ |
2926 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2927 | temp = get_string(infile,1); |
||
2928 | temp = str_replace(temp,",","\",\""); |
||
2929 | fprintf(js_include_file,"var multifill = [\"%s\"];",temp); |
||
2930 | break; |
||
2931 | |||
2932 | case MULTIFILLCOLORS: |
||
2933 | /* |
||
2934 | @ multifillcolors color_name_1,color_name_2,...,color_name_8 |
||
14622 | schaersvoo | 2935 | @ alternative:<code>fillcolors</code> |
14066 | bpr | 2936 | @ use before command <a href='#multidraw'>multidraw</a> |
14078 | bpr | 2937 | @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity`` |
14071 | bpr | 2938 | @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_n</code> |
11806 | schaersvoo | 2939 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14379 | bpr | 2940 | @ always use the same sequence as is used for ''multidraw`` |
14380 | bpr | 2941 | @ can also be used with command <a href='#userdraw'>userdraw clickfill,color</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... <code>reply=x1:y1:color1,x2:y2:color2...</code> The colors will restart at the first color, when there are more fill-clicks than multi-fill-colors. If more control over the used colours is wanted, see command <a href='#colorpalette'>colorpalette color1,color2...</a> |
11806 | schaersvoo | 2942 | */ |
2943 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2944 | fprintf(js_include_file,"var multifillcolors = ["); |
||
2945 | while( ! done ){ |
||
2946 | temp = get_color(infile,1); |
||
2947 | fprintf(js_include_file,"\"%s\",",temp); |
||
2948 | } |
||
2949 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
2950 | break; |
||
2951 | |||
2952 | case MULTIFILLOPACITY: |
||
2953 | /* |
||
2954 | @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8 |
||
2955 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 2956 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2957 | @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled`` |
2958 | @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_y</code> |
||
11806 | schaersvoo | 2959 | @ wims will not check the amount or validity of your input |
14071 | bpr | 2960 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2961 | */ |
2962 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2963 | temp = get_string(infile,1); |
||
2964 | temp = str_replace(temp,",","\",\""); |
||
2965 | fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp); |
||
2966 | break; |
||
2967 | case MULTISNAPTOGRID: |
||
2968 | /* |
||
2969 | @ multisnaptogrid 0,1,1 |
||
14071 | bpr | 2970 | @ alternative: <code>multisnap</code> |
2971 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>snaptogrid</a>) |
||
2972 | @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
||
14246 | bpr | 2973 | @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
14071 | bpr | 2974 | @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code> |
2975 | @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code> |
||
2976 | @ if <a href='#snaptopoints'>snaptopoints</a> is defined: all objects snap to points <code>multisnaptogrid 4,4,4,...</code> <br /><b>make sure to define the points to snap on...</b> use command <a href='#snaptopoints'>snaptopoints</a> |
||
2977 | @ <code>multisnaptogrid 0,1,2,3,4<br />multidraw text,arrow,line,circle,image</code><br />''text`` is free hand, ''arrow`` is snap to grid, ''line`` is snap to x-grid, ''circle`` is snap to y-grid, ''image`` is snap to points defined by command <a href='#snaptopoints'>snaptopoints</a> |
||
14380 | bpr | 2978 | @ use before command <a href='#multidraw'>multidraw</a>. |
2979 | @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw``. |
||
14634 | bpr | 2980 | @ commands <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a>, <a href='#snaptofunction'>snaptofunction</a> are <b>not</b> supported and only functional for command <a href='#userdraw'>userdraw</a> |
14071 | bpr | 2981 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2982 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
2983 | */ |
||
2984 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2985 | temp = get_string(infile,1); |
||
14038 | schaersvoo | 2986 | fprintf(js_include_file,"var multisnaptogrid = [%s];",temp); |
14380 | bpr | 2987 | reset();/* if command ''dashed`` was given...reset to not-dashed */ |
11806 | schaersvoo | 2988 | break; |
2989 | case MULTISTROKECOLORS: |
||
2990 | /* |
||
2991 | @ multistrokecolors color_name_1,color_name_2,...,color_name_8 |
||
14622 | schaersvoo | 2992 | @ alternative: <code>multicolors</code> or <code>colors</code> |
14066 | bpr | 2993 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2994 | @ if not set all colors will be ''stroke_color``, ''stroke_opacity`` |
2995 | @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code> |
||
11806 | schaersvoo | 2996 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14071 | bpr | 2997 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2998 | */ |
2999 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3000 | fprintf(js_include_file,"var multistrokecolors = ["); |
||
3001 | while( ! done ){ |
||
3002 | temp = get_color(infile,1); |
||
3003 | fprintf(js_include_file,"\"%s\",",temp); |
||
3004 | } |
||
3005 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
3006 | break; |
||
3007 | case MULTISTROKEOPACITY: |
||
3008 | /* |
||
3009 | @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7 |
||
3010 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 3011 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3012 | @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code> |
14385 | bpr | 3013 | @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1, obj_type_2, ..., obj_type_7</code> |
11806 | schaersvoo | 3014 | @ wims will not check the amount or validity of your input |
14071 | bpr | 3015 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3016 | */ |
3017 | if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3018 | temp = get_string(infile,1); |
||
3019 | temp = str_replace(temp,",","\",\""); |
||
3020 | fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp); |
||
3021 | break; |
||
3022 | |||
3023 | case MULTIUSERINPUT: |
||
3024 | /* |
||
3025 | @ multiuserinput 0,1,1,0 |
||
14071 | bpr | 3026 | @ alternative: <code>multiinput</code> |
14380 | bpr | 3027 | @ meaning, when the command ''multidraw`` is used <code>multidraw circles,points,lines,triangles</code>, objects ''points`` and ''lines`` may additionally be ''drawn`` by direct input (inputfields). All other objects must be drawn with a mouse. |
14385 | bpr | 3028 | @ in case of ''circle | circles`` a third inputfield for Radius (R) is added. 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 />note: R-values will not snap-to-grid |
3029 | @ 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... |
||
3030 | @ in case of a ''triangle | poly3``, three inputfields are provided. |
||
3031 | @ in case of ''text`` and ''multiuserinput=1, 3`` inputfields will be shown: ''x,y,text`` |
||
3032 | @ in case of ''text`` and ''multiuserinput=0, 1`` inputfield will be shown: text ... a mouse click will place the text on the canvas. |
||
14066 | bpr | 3033 | @ may be styled using command <a href="#inputstyle">inputstyle</a> |
14071 | bpr | 3034 | @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag&drop`` or ''onclick`` elements |
14385 | bpr | 3035 | @ when exercise is finished (status=done), the buttons will not be shown. To override this default behaviour use command / keyword ''status`` |
3036 | @ use before command <a href='#multidraw'>multidraw</a>. |
||
3037 | @ always use the same sequence as is used for ''multidraw``. |
||
11806 | schaersvoo | 3038 | */ |
3039 | /* simple rawmath and input check */ |
||
3040 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
3041 | temp = get_string(infile,1); |
||
3042 | temp = str_replace(temp,",","\",\""); |
||
3043 | fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp); |
||
3044 | break; |
||
3045 | |||
3046 | case NOXAXIS: |
||
3047 | /* |
||
14252 | bpr | 3048 | @ noxaxis |
11806 | schaersvoo | 3049 | @ keyword |
3050 | @ if set, the automatic x-axis numbering will be ignored |
||
14252 | bpr | 3051 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>) |
11806 | schaersvoo | 3052 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
3053 | */ |
||
11891 | schaersvoo | 3054 | fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n"); |
3055 | use_axis_numbering = -1; |
||
11806 | schaersvoo | 3056 | break; |
3057 | case NOYAXIS: |
||
3058 | /* |
||
14251 | bpr | 3059 | @ noyaxis |
11806 | schaersvoo | 3060 | @ keyword |
3061 | @ if set, the automatic y-axis numbering will be ignored |
||
14252 | bpr | 3062 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>) |
11806 | schaersvoo | 3063 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
3064 | */ |
||
11891 | schaersvoo | 3065 | fprintf(js_include_file,"y_strings = {};\n"); |
11806 | schaersvoo | 3066 | break; |
11890 | schaersvoo | 3067 | case NUMBERLINE: |
3068 | /* |
||
3069 | @ numberline x0,x1,xmajor,xminor,y0,y1 |
||
3070 | @ numberline is using xrange/yrange system for all dimensions |
||
11996 | schaersvoo | 3071 | @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed |
11890 | schaersvoo | 3072 | @ x0 is start x-value in xrange |
3073 | @ x1 is end x-value in xrange |
||
3074 | @ xmajor is step for major division |
||
14071 | bpr | 3075 | @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded`` |
3076 | @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded`` |
||
11890 | schaersvoo | 3077 | @ y0 is bottom of numberline; y1 endpoint of major tics |
13829 | bpr | 3078 | @ use command <a href="#linewidth">linewidth</a> to control appearance |
11890 | schaersvoo | 3079 | @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line |
3080 | @ for all ticks linewidth and color / opacity are identical. |
||
3081 | @ if command <a href="#xaxis">xaxis</a> or <a href="#xaxisup">xaxisup</a> is not defined, the labeling will be on major ticks: x0...x1 |
||
13829 | bpr | 3082 | @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings |
14078 | bpr | 3083 | @ may be used together with <a href="#userdraw">userdraw</a>, <a href="#multidraw">multidraw</a> and <a href="#drag">user drag</a> command family for the extra object drawn onto the numberline |
11890 | schaersvoo | 3084 | @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported |
3085 | @ onclick and dragging of the numberline are not -yet- supported |
||
14071 | bpr | 3086 | @ note: in case of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first ! |
13829 | bpr | 3087 | @%numberline%size 400,400%xrange -10,10%yrange -10,10%precision 1%strokecolor black%numberline -8,8,1,6,-4,-3.5%strokecolor red%xaxis -4:AA:-2:BB:2:CC:4:DD%numberline -8,8,1,2,4,4.5%strokecolor green%xaxisup -4:AAA:-2:BBB:2:CCC:4:DDD%numberline -8,8,1,3,2,2.5%strokecolor blue%xaxis -4:AAAA:-2:BBBB:2:CCCC:4:DDDD%numberline -8,8,1,4,0,0.5%strokecolor brown%xaxis -4:AAAAA:-2:BBBBB:2:CCCCC:4:DDDDD%numberline -8,8,1,5,-2,-1.5%zoom red |
11890 | schaersvoo | 3088 | */ |
3089 | if( js_function[DRAW_NUMBERLINE] != 1 ){ js_function[DRAW_NUMBERLINE] = 1;} |
||
3090 | for(i=0;i<6;i++){ |
||
3091 | switch(i){ |
||
3092 | case 0: double_data[0] = get_real(infile,0);break;/* xmin */ |
||
3093 | case 1: double_data[1] = get_real(infile,0);break;/* xmax */ |
||
3094 | case 2: double_data[2] = get_real(infile,0);break;/* xmajor */ |
||
3095 | case 3: double_data[3] = get_real(infile,0);break;/* xminor */ |
||
3096 | case 4: double_data[4] = get_real(infile,0);break;/* ymin */ |
||
3097 | case 5: double_data[5] = get_real(infile,1);/* ymax */ |
||
3098 | /* |
||
3099 | var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor); |
||
3100 | */ |
||
3101 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] ); |
||
14208 | schaersvoo | 3102 | string_length = 1 + snprintf(NULL,0,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d); ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision); |
3103 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11996 | schaersvoo | 3104 | snprintf(tmp_buffer,string_length,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d); ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision); |
11890 | schaersvoo | 3105 | add_to_buffer(tmp_buffer); |
3106 | numberline_cnt++; |
||
3107 | break; |
||
3108 | default:break; |
||
3109 | } |
||
3110 | } |
||
3111 | reset(); |
||
3112 | break; |
||
3113 | |||
3114 | break; |
||
11806 | schaersvoo | 3115 | case OPACITY: |
3116 | /* |
||
13951 | schaersvoo | 3117 | @ opacity [0-255],[0-255] |
3118 | @ opacity [0.0 - 1.0],[0.0 - 1.0] |
||
14071 | bpr | 3119 | @ alternative: <code>transparent</code> |
11806 | schaersvoo | 3120 | @ first item is stroke opacity, second is fill opacity |
13951 | schaersvoo | 3121 | @%opacity%size 400,400%xrange -10,10%yrange -10,10%opacity 255,0%fcircle -10,0,100,blue%opacity 250,50%fcircle -5,0,100,blue%opacity 200,100%fcircle 0,0,100,blue%opacity 150,150%fcircle 5,0,100,blue%opacity 100,200%fcircle 10,0,100,blue |
11806 | schaersvoo | 3122 | */ |
3123 | for(i = 0 ; i<2;i++){ |
||
3124 | switch(i){ |
||
3125 | case 0: double_data[0]= get_real(infile,0);break; |
||
3126 | case 1: double_data[1]= get_real(infile,1);break; |
||
3127 | default: break; |
||
3128 | } |
||
3129 | } |
||
13951 | schaersvoo | 3130 | if( double_data[0] > 255 || double_data[1] > 255 || double_data[0] < 0 || double_data[1] < 0 ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */ |
11997 | schaersvoo | 3131 | if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */ |
3132 | if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */ |
||
11806 | schaersvoo | 3133 | break; |
3134 | |||
3135 | case ONCLICK: |
||
3136 | /* |
||
3137 | @ onclick |
||
3138 | @ keyword (no arguments required) |
||
14543 | schaersvoo | 3139 | @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>read_dragdrop();</code> |
14086 | bpr | 3140 | @ onclick seqeuence numbering starts at ''0``, e.g. if there are 6 objects set onclick, the first onclick object will have id-number ''0``, the last id-number ''5`` |
14543 | schaersvoo | 3141 | @ line based objects will show an increase in line width<br />font based objects (e.g. text / string ) will show a slight change in text size when clicked. |
14562 | bpr | 3142 | @ the click zone (accuracy) is determined by 2× the line width of the object |
14071 | bpr | 3143 | @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript (although a single object can <b>not</b> be onclick and draggable at the same time...) |
14543 | schaersvoo | 3144 | @ in that case <code>read_dragdrop()</code> will produce a javascript array reply containing for the moved objects:<br />x_org[0],y_org[0],x_new[0],y_new[0],new_angle<br/>the unmoved draggable objects are labelled 'not_moved'. The combined 'onclick' objects are labelled '0' or '1'<br />the array index in the reply in the same order as the draggable and clickable objects appear in the canvascript.<br />See tool directexec for an example |
11806 | schaersvoo | 3145 | @ note: not all objects may be set onclick |
14543 | schaersvoo | 3146 | @ note: onclick (or drag ) can not be combined with command <a href="#rotate">rotate or translate</a> ! |
12107 | schaersvoo | 3147 | @%onclick%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%linewidth 3%onclick%fcircles blue,-3,3,1,1,2,2,3,1,1%onclick%ftriangles red,-4,-4,-4,0,-3,-2,0,0,4,0,2,-4%onclick%frects green,-4,4,-2,2,1,-1,3,-4 |
14543 | schaersvoo | 3148 | @%onclick_drag%size 400,400%######%# to see reply string, load this example in directexec %######%xrange -10,10%yrange -10,10%linewidth 3%# command text large = fontsize+6%fontsize 34-6%fontfamily 34px Ariel%drag xy%circles red,-5,5,2,5,5,2,5,-5,2,-5,-5,2%onclick%string blue,-1,1,A%onclick%string blue,1,7,B%onclick%string blue,1,-1,C%onclick%string blue,-1,-7,D%onclick%text green,-8,1,large,E%onclick%text green,-6,7,large,F%onclick%text green,6,-1,large,G%onclick%text green,8,-7,large,H |
11806 | schaersvoo | 3149 | */ |
14562 | bpr | 3150 | if( print_drag_params_only_once == FALSE){ |
14548 | schaersvoo | 3151 | fprintf(js_include_file,"use_dragdrop_reply = true;\n"); |
14562 | bpr | 3152 | print_drag_params_only_once = TRUE; |
14543 | schaersvoo | 3153 | } |
11806 | schaersvoo | 3154 | onclick = 1; |
3155 | |||
3156 | break; |
||
3157 | |||
3158 | case PARALLEL: |
||
3159 | /* |
||
3160 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
14086 | bpr | 3161 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` |
12107 | schaersvoo | 3162 | @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red |
11806 | schaersvoo | 3163 | */ |
3164 | for( i = 0;i < 8; i++ ){ |
||
3165 | switch(i){ |
||
14032 | schaersvoo | 3166 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values -> x-pixels*/ |
3167 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values -> y-pixels*/ |
||
3168 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values -> x-pixels*/ |
||
3169 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values -> y-pixels*/ |
||
11806 | schaersvoo | 3170 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */ |
3171 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */ |
||
14032 | schaersvoo | 3172 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
11806 | schaersvoo | 3173 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
3174 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 3175 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3176 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 3177 | /* click_cnt++*/; |
3178 | reset(); |
||
3179 | break; |
||
3180 | default: break; |
||
3181 | } |
||
3182 | } |
||
3183 | break; |
||
3184 | |||
3185 | |||
3186 | case PLOTSTEPS: |
||
3187 | /* |
||
3188 | @ plotsteps a_number |
||
3189 | @ default 150 |
||
14066 | bpr | 3190 | @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a> |
11806 | schaersvoo | 3191 | @ use with care ! |
3192 | */ |
||
3193 | plot_steps = (int) (get_real(infile,1)); |
||
3194 | break; |
||
13829 | bpr | 3195 | |
11806 | schaersvoo | 3196 | case POINT: |
3197 | /* |
||
3198 | @ point x,y,color |
||
14380 | bpr | 3199 | @ draw a single point at (x;y) in color ''color`` |
14246 | bpr | 3200 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3201 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 3202 | @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming) |
14066 | bpr | 3203 | @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3204 | @%point%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%point 0,0,red%linewidth 2%onclick%point 1,1,blue%linewidth 3%onclick%point 3,3,green%linewidth 4%point 4,4,orange |
11806 | schaersvoo | 3205 | */ |
3206 | for(i=0;i<3;i++){ |
||
3207 | switch(i){ |
||
3208 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
3209 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
3210 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
3211 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 3212 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3213 | /* click_cnt++; */ |
14208 | schaersvoo | 3214 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
11806 | schaersvoo | 3215 | break; |
3216 | default: break; |
||
3217 | } |
||
3218 | } |
||
3219 | reset(); |
||
3220 | break; |
||
3221 | |||
3222 | case POINTS: |
||
3223 | /* |
||
3224 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
||
14380 | bpr | 3225 | @ draw multiple points at given coordinates in color ''color`` |
14246 | bpr | 3226 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3227 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
14066 | bpr | 3228 | @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3229 | @%points_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 1%drag xy%points red,0,0,1,1,2,2,3,3%drag x%points blue,0,1,1,2,2,3,3,4 |
3230 | @%points_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%points red,0,0,1,1,2,2,3,3%onclick%points blue,0,1,1,2,2,3,3,4 |
||
11806 | schaersvoo | 3231 | */ |
8363 | schaersvoo | 3232 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3233 | fill_color = stroke_color; |
||
3234 | i=0; |
||
3235 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3236 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8363 | schaersvoo | 3237 | if(i%2 == 0 ){ |
3238 | double_data[i] = get_real(infile,0); /* x */ |
||
3239 | } |
||
3240 | else |
||
3241 | { |
||
3242 | double_data[i] = get_real(infile,1); /* y */ |
||
3243 | } |
||
3244 | i++; |
||
3245 | } |
||
3246 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 3247 | for(c = 0 ; c < i-1 ; c = c+2){ |
14208 | schaersvoo | 3248 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 3249 | /* click_cnt++; */ |
14208 | schaersvoo | 3250 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
8363 | schaersvoo | 3251 | } |
3252 | reset(); |
||
3253 | break; |
||
11806 | schaersvoo | 3254 | |
3255 | case POLY: |
||
3256 | /* |
||
3257 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
3258 | @ polygon color,x1,y1,x2,y2...x_n,y_n |
||
3259 | @ draw closed polygon |
||
14071 | bpr | 3260 | @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a> |
11806 | schaersvoo | 3261 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3262 | @%polygon_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 2%drag xy%snaptogrid%poly blue,0,0,1,3,3,1,2,4,-1,3 |
3263 | @%polygon_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 1%onclick%poly green,0,0,1,3,3,1,2,4,-1,3 |
||
11806 | schaersvoo | 3264 | */ |
3265 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
3266 | i=0; |
||
3267 | c=0; |
||
3268 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3269 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 3270 | for( c = 0 ; c < 2; c++){ |
3271 | if(c == 0 ){ |
||
3272 | double_data[i] = get_real(infile,0); |
||
3273 | i++; |
||
3274 | } |
||
3275 | else |
||
3276 | { |
||
3277 | double_data[i] = get_real(infile,1); |
||
3278 | i++; |
||
3279 | } |
||
3280 | } |
||
3281 | } |
||
14066 | bpr | 3282 | /* draw path: closed & optional filled */ |
11806 | schaersvoo | 3283 | decimals = find_number_of_digits(precision); |
14208 | schaersvoo | 3284 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3285 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 3286 | /* click_cnt++; */ |
3287 | reset(); |
||
3288 | break; |
||
3289 | |||
7614 | schaersvoo | 3290 | case POLYLINE: |
3291 | /* |
||
3292 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
10975 | schaersvoo | 3293 | @ brokenline color,x1,y1,x2,y2...x_n,y_n |
3294 | @ path color,x1,y1,x2,y2...x_n,y_n |
||
14086 | bpr | 3295 | @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands <code>polyline, x1,y1,x2,y2...x_n,y_n</code> |
3296 | @ remark: there are commands <code>userdraw path(s),color</code> and <code>userdraw polyline,color</code>... these are two entirely different things ! the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command |
||
10975 | schaersvoo | 3297 | @ 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) |
14071 | bpr | 3298 | @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually |
9406 | schaersvoo | 3299 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3300 | @%polyline_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%snaptogrid%polyline blue,0,0,1,3,3,1,2,4,-1,3 |
3301 | @%polyline_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%onclick%polyline green,0,0,1,3,3,1,2,4,-1,3 |
||
7614 | schaersvoo | 3302 | */ |
13829 | bpr | 3303 | |
7614 | schaersvoo | 3304 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3305 | i=0; |
||
3306 | c=0; |
||
3307 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3308 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3309 | for( c = 0 ; c < 2; c++){ |
3310 | if(c == 0 ){ |
||
3311 | double_data[i] = get_real(infile,0); |
||
3312 | i++; |
||
3313 | } |
||
3314 | else |
||
3315 | { |
||
3316 | double_data[i] = get_real(infile,1); |
||
3317 | i++; |
||
3318 | } |
||
3319 | } |
||
3320 | } |
||
14066 | bpr | 3321 | /* draw path: not closed & not filled */ |
7614 | schaersvoo | 3322 | decimals = find_number_of_digits(precision); |
14208 | schaersvoo | 3323 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3324 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 3325 | /* click_cnt++;*/ |
3326 | reset(); |
||
7614 | schaersvoo | 3327 | break; |
11806 | schaersvoo | 3328 | |
3329 | case POPUP: |
||
3330 | /* |
||
3331 | @ popup |
||
3332 | @ keyword (no arguments) |
||
14086 | bpr | 3333 | @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px × ysize px) |
14071 | bpr | 3334 | @ if keyword ''popup`` is used after command <code>size xsize,ysize</code> the canvas will also be displayed in a popup window with size ''xsize × ysize`` |
14086 | bpr | 3335 | @ the popup window will be embedded into the page as a ''normal`` image, when ''status=done``; override with keyword <a href="#status">nostatus</a> |
14246 | bpr | 3336 | @ to access the read_canvas and read_dragdrop functions in a popup window, use: <code> 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 /> };</code> |
14071 | bpr | 3337 | @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like: <code>popup.set_clock(clock_id,type,diff);</code> as js-function for a button (or something else) in your document page.<br />where in <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 |
12107 | schaersvoo | 3338 | @%popup%popup%size 400,400%xrange -2*pi,2*pi%yrange -5,5%precision 0%axis%axisnumbering%opacity 100,190%grid 1,1,grey,2,2,5,black%linewidth 4%fillcolor blue%trange -pi,pi%animate%linewidth 1%precision 1000%jsplot red,4*cos(2*x),2*sin(3*x-pi/6)%strokecolor green%functionlabel f(x)=%userinput function |
11806 | schaersvoo | 3339 | */ |
3340 | use_tooltip = 2; |
||
3341 | break; |
||
3342 | |||
3343 | case PROTRACTOR: |
||
7614 | schaersvoo | 3344 | /* |
11806 | schaersvoo | 3345 | @ protractor x,y,x_width,type,mode,use_a_scale |
3346 | @ x,y are the initial location |
||
14066 | bpr | 3347 | @ x_width: give the width in x-coordinate system (e.g. not in pixels !) |
14246 | bpr | 3348 | @ type = 1: a triangle range 0 - 180<br />type = 2: a circle shape 0 - 360 |
14066 | bpr | 3349 | @ mode: use -1 to set the protractor interactive (mouse movement of protractor)<br />use mode = '0° - 360°' to set the protractor with a static angle of some value |
11806 | schaersvoo | 3350 | @ if the value of the user_rotation angle is to be shown...use command <a href='#display'>display degree,color,fontsize</a><a href='#display'>display radian,color,fontsize</a> |
14066 | bpr | 3351 | @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable |
11806 | schaersvoo | 3352 | @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor... |
14071 | bpr | 3353 | @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor. |
3354 | @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command ''precision`` to set the reply precision. |
||
11806 | schaersvoo | 3355 | @ if combined with a ruler, use replyformat = 32 |
14071 | bpr | 3356 | @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor |
3357 | @ 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 />technical: 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... |
||
11806 | schaersvoo | 3358 | @ only one protractor allowed (for the time being) |
14380 | bpr | 3359 | @ usage: first left click on the protractor will activate dragging; a second left click will activate rotating (just move mouse around); a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3); a next click will restart this sequence... |
12107 | schaersvoo | 3360 | @%protractor%size 400,400%xrange -5,10%yrange -5,10%hline 0,0,black%vline 0,0,black%fillcolor orange%opacity 255,40%protractor 2,-2,6,0,-1,1,1 |
7614 | schaersvoo | 3361 | */ |
11806 | schaersvoo | 3362 | for( i = 0;i < 6; i++ ){ |
3363 | switch(i){ |
||
3364 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
||
3365 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
3366 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
3367 | case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */ |
||
3368 | case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */ |
||
3369 | case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */ |
||
3370 | decimals = find_number_of_digits(precision); |
||
11821 | schaersvoo | 3371 | if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;} |
14057 | schaersvoo | 3372 | 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],int_data[1],use_snap); |
11806 | schaersvoo | 3373 | |
14208 | schaersvoo | 3374 | string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id); |
3375 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3376 | snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id); |
3377 | add_to_buffer(tmp_buffer); |
||
3378 | reply_precision = precision; |
||
3379 | /* no reply from protractor if non-interactive */ |
||
3380 | if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;} |
||
3381 | break; |
||
3382 | default: break; |
||
3383 | } |
||
3384 | } |
||
3385 | break; |
||
3386 | |||
3387 | case PIXELS: |
||
3388 | /* |
||
3389 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
3390 | @ draw rectangular "points" with diameter 1 pixel |
||
3391 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 3392 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12111 | schaersvoo | 3393 | @%pixels%size 400,400%opacity 255,255%pixelsize 5%pixels red,1,1,2,2,3,3,4,4,5,5,10,10,20,20,30,30,40,40,50,50,60,60,70,70,80,80,90,90,100,100,120,120,140,140,160,160,180,180,200,200,240,240,280,280,320,320,360,360,400,400%#NOTE pixelsize=5...otherwise you will not see them clearly... |
11806 | schaersvoo | 3394 | */ |
3395 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
3396 | stroke_color=get_color(infile,0); |
||
7614 | schaersvoo | 3397 | i=0; |
3398 | c=0; |
||
3399 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3400 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3401 | for( c = 0 ; c < 2; c++){ |
3402 | if(c == 0 ){ |
||
3403 | double_data[i] = get_real(infile,0); |
||
3404 | i++; |
||
3405 | } |
||
3406 | else |
||
3407 | { |
||
3408 | double_data[i] = get_real(infile,1); |
||
3409 | i++; |
||
3410 | } |
||
3411 | } |
||
3412 | } |
||
11806 | schaersvoo | 3413 | decimals = find_number_of_digits(precision); |
3414 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
14208 | schaersvoo | 3415 | string_length = 1 + snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
3416 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3417 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
3418 | add_to_buffer(tmp_buffer); |
||
3419 | reset(); |
||
7614 | schaersvoo | 3420 | break; |
11806 | schaersvoo | 3421 | |
3422 | case PIXELSIZE: |
||
7614 | schaersvoo | 3423 | /* |
11806 | schaersvoo | 3424 | @ pixelsize int |
3425 | @ in case you want to deviate from default pixelsize = 1(...) |
||
12111 | schaersvoo | 3426 | @ pixelsize 100 is of course a filled rectangle 100px × 100px |
7614 | schaersvoo | 3427 | */ |
11806 | schaersvoo | 3428 | pixelsize = (int) get_real(infile,1); |
3429 | break; |
||
8105 | schaersvoo | 3430 | |
11806 | schaersvoo | 3431 | case PIECHART: |
7614 | schaersvoo | 3432 | /* |
11806 | schaersvoo | 3433 | @ piechart xc,yc,radius,'data+colorlist' |
14066 | bpr | 3434 | @ (xc: yc) center of circle diagram in xrange/yrange |
11806 | schaersvoo | 3435 | @ radius in pixels |
3436 | @ 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 |
||
14066 | bpr | 3437 | @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white |
11806 | schaersvoo | 3438 | @ the number of colors must match the number of data. |
14066 | bpr | 3439 | @ if defined <a href='#fillpattern'>fillpattern some_pattern</a> then the pie pieces will be filled with the respective color and a fill pattern...<br />the pattern is cycled from the 4 pattern primitives: grid,hatch,diamond,dot,grid,hatch,diamond,dot,... |
14086 | bpr | 3440 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours |
3441 | @ use command <a href='#legend'>legend</a> to automatically create a legend using the same colours as pie segments; unicode allowed in legend; expect javascript trouble if the amount of ''pie-slices``, ''pie-colors``, ''pie-legend-titles`` do not match, a javascript console is your best friend...<br />use command ''fontfamily`` to set the font of the legend. |
||
14066 | bpr | 3442 | @ use command <a href='centered'>centered</a> to place <a href='#legend'>legend</a> text inside the piechart. The text is using the same color as the pie segment: use (fill) opacity to enhance visibility. |
12538 | schaersvoo | 3443 | @%piechart_1%size 300,200%xrange -10,10%yrange -10,10%legend cars:motorcycles:bicycles:trikes%opacity 255,120%piechart -5,0,75,22:red:8:blue:63:green:7:purple% |
3444 | @%piechart_2%size 200,200%xrange -10,10%yrange -10,10%fontfamily 16px Ariel%centered%legend cars:motorcycles:bicycles:trikes%opacity 255,60%piechart 0,0,100,22:red:8:blue:63:green:7:purple |
||
7614 | schaersvoo | 3445 | */ |
11806 | schaersvoo | 3446 | if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;} |
7614 | schaersvoo | 3447 | for(i=0;i<5;i++){ |
3448 | switch(i){ |
||
11806 | schaersvoo | 3449 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
14032 | schaersvoo | 3450 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
11806 | schaersvoo | 3451 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
3452 | case 3: temp = get_string(infile,1); |
||
3453 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
14208 | schaersvoo | 3454 | string_length = 1 + snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset); |
3455 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
12538 | schaersvoo | 3456 | snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset); |
11806 | schaersvoo | 3457 | add_to_buffer(tmp_buffer); |
3458 | break; |
||
3459 | default:break; |
||
7614 | schaersvoo | 3460 | } |
3461 | } |
||
11806 | schaersvoo | 3462 | reset(); |
7614 | schaersvoo | 3463 | break; |
8304 | schaersvoo | 3464 | |
7614 | schaersvoo | 3465 | case RAYS: |
3466 | /* |
||
3467 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
14380 | bpr | 3468 | @ draw rays in color ''color`` and center (xc:yc) |
7786 | schaersvoo | 3469 | @ may be set draggable or onclick (every individual ray) |
12111 | schaersvoo | 3470 | @%rays_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9 |
3471 | @%rays_drag_xy%size 400,400%xrange -10,10%yrange -10,10%drag xy%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9 |
||
7614 | schaersvoo | 3472 | */ |
3473 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 3474 | fill_color = stroke_color; |
3475 | double_data[0] = get_real(infile,0);/* xc */ |
||
3476 | double_data[1] = get_real(infile,0);/* yc */ |
||
3477 | i=2; |
||
3478 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3479 | if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");} |
7786 | schaersvoo | 3480 | if(i%2 == 0 ){ |
3481 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 3482 | } |
7786 | schaersvoo | 3483 | else |
3484 | { |
||
3485 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 3486 | } |
7786 | schaersvoo | 3487 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
3488 | i++; |
||
7614 | schaersvoo | 3489 | } |
8224 | bpr | 3490 | |
3491 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
||
3492 | decimals = find_number_of_digits(precision); |
||
7786 | schaersvoo | 3493 | for(c=2; c<i;c = c+2){ |
14208 | schaersvoo | 3494 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 3495 | /* click_cnt++; */ |
14208 | schaersvoo | 3496 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
7614 | schaersvoo | 3497 | } |
3498 | reset(); |
||
3499 | break; |
||
8304 | schaersvoo | 3500 | |
11806 | schaersvoo | 3501 | case RECT: |
8386 | schaersvoo | 3502 | /* |
11806 | schaersvoo | 3503 | @ rect x1,y1,x2,y2,color |
14071 | bpr | 3504 | @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle |
14246 | bpr | 3505 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code> |
9406 | schaersvoo | 3506 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12111 | schaersvoo | 3507 | @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red |
8386 | schaersvoo | 3508 | */ |
11806 | schaersvoo | 3509 | for(i=0;i<5;i++){ |
3510 | switch(i){ |
||
3511 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
3512 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
3513 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
3514 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
3515 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
8386 | schaersvoo | 3516 | decimals = find_number_of_digits(precision); |
14208 | schaersvoo | 3517 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3518 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 3519 | /* click_cnt++; */ |
8386 | schaersvoo | 3520 | reset(); |
3521 | break; |
||
11806 | schaersvoo | 3522 | } |
3523 | } |
||
3524 | break; |
||
8386 | schaersvoo | 3525 | |
11806 | schaersvoo | 3526 | case RECTS: |
8304 | schaersvoo | 3527 | /* |
11806 | schaersvoo | 3528 | @ rects color,x1,y1,x2,y2,..... |
14071 | bpr | 3529 | @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle |
14246 | bpr | 3530 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code> |
14071 | bpr | 3531 | @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour. |
9406 | schaersvoo | 3532 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12111 | schaersvoo | 3533 | @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1 |
8304 | schaersvoo | 3534 | */ |
3535 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
3536 | fill_color = stroke_color; |
||
3537 | i=0; |
||
3538 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3539 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8304 | schaersvoo | 3540 | if(i%2 == 0 ){ |
3541 | double_data[i] = get_real(infile,0); /* x */ |
||
3542 | } |
||
3543 | else |
||
3544 | { |
||
3545 | double_data[i] = get_real(infile,1); /* y */ |
||
3546 | } |
||
3547 | i++; |
||
3548 | } |
||
3549 | decimals = find_number_of_digits(precision); |
||
3550 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
14208 | schaersvoo | 3551 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3552 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 3553 | /* click_cnt++; */ |
8304 | schaersvoo | 3554 | } |
3555 | reset(); |
||
3556 | break; |
||
8386 | schaersvoo | 3557 | |
11806 | schaersvoo | 3558 | case REPLYFORMAT: |
7614 | schaersvoo | 3559 | /* |
11806 | schaersvoo | 3560 | @ replyformat number |
3561 | @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop() |
||
3562 | @ default values should be fine ! |
||
14071 | bpr | 3563 | @ use command <code>precision [0,1,10,100,1000,10000...]</code> before command ''replyformat`` to set the desired number of decimals in the student reply / drawing |
14246 | bpr | 3564 | @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();) |
14248 | bpr | 3565 | @ choose<ul><li>replyformat 1: <code>x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n</code> x/y in pixels</li><li>replyformat 2: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 3: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in pixels, r in pixels</li><li>replyformat 4: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in xrange / yrange coordinate system, r in pixels</li><li>replyformat 5: <code> 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</code> x/y in pixels</li><li>replyformat 6: <code> 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</code> x/y in xrange / yrange coordinate system</li><li>replyformat 7: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in pixels</li><li>replyformat 8: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 9: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in pixels</li><li>replyformat 10: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 11: <code> 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</code> x/y in xrange / yrange coordinate system</li><li>replyformat 12: <code> 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</code> x/y in pixels</li><li>replyformat 13: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2</code> x/y in xrange / yrange coordinate system</li><li>replyformat 14: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2</code> x/y in pixels</li><li>replyformat 15: reply from inputfields,textareas <code>reply1,reply2,reply3,...,reply_n</code></li><li>replyformat 16: mathml input fields</li><li>replyformat 17: read ''userdraw text,color`` only <code>x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n </code> x/y-values are in xrange/yrange</li><li>replyformat 18: read_canvas() will read all interactive clocks in <codeWH1:M1:S1,H2:M2:S2...Hn:Mn:Sn</code></li><li>replyformat 19: read_canvas() will return the object number of marked / clicked object (clock), analogue to (shape library) onclick command</li><li>replyformat 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, e.g. expect something like 0:-5:4,1:6:2,2:-2:-5, the first image position is (-5:4), the second image position is (6:2) and the third image position is (-2:-5) <li>replyformat 21: <code> (x1:y1) (x2:y2) ... (x_n:y_n)</code> verbatim coordinate return</li><li>replyformat 22: returns an array .... <code>reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 23: can only be used for drawtype ''polyline``. 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 gives <code>x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn</code>; multiple occurences will be filtered out. The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24: read all inputfield values: even those set ''readonly``</li><li>replyformat 25: <code> angle1,angle2;...;angle_n</code> will return the radius (one or many) of the user drawn circle segment in degrees</li><li>replyformat 26: <code> rad1,rad2,...rad_n</code> will return the radius (one or many) of the user drawn circle segment in radians</li><li>replyformat 27: return (only) userdraw inputfields <code>x1,y1,text1<br /> x2,y2,text2...<br />...x_n,y_n,textn</code></li><li>replyformat 28: <code> x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> x / y / r in xrange / yrange coordinate system: may be used to reinput into command <code>circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> will not return anything else (e.g. no inputfields, text etc)</li><li>replyformat 34: a special for OEF and dragging external images -included via commands <a href='#copy'>copy</a> or <a href='#copyresized'>copyresized</a> there will be an extra function <code>read_canvas_images()</code> for reading the coordinates of the images.<br />for now this is a unique function, e.g. there is no ''canvas id`` linked to it. (TO DO !!! 18/5/2019)</li></ul> |
11806 | schaersvoo | 3566 | */ |
3567 | reply_format = (int) get_real(infile,1); |
||
3568 | reply_precision = precision; |
||
3569 | break; |
||
3570 | |||
14546 | schaersvoo | 3571 | case RESETOFFSET: |
3572 | /* |
||
3573 | @ resetoffset |
||
3574 | @ keyword |
||
3575 | @ use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text |
||
3576 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library). |
||
3577 | */ |
||
3578 | use_offset = 0; |
||
3579 | break; |
||
3580 | |||
3581 | case ROTATE: |
||
3582 | /* |
||
3583 | @ rotate rotation_angle |
||
3584 | @ angle in degrees |
||
3585 | @ (only) the next object will be rotated is given angle |
||
3586 | @ positive values rotate counter clockwise |
||
3587 | @ attention: all objects will be rotated around their first point...<br /><code>rotate 45<br />triangle 1,1,5,1,3,4,red</code><br />will rotate 45 degrees around point (1:1) |
||
3588 | @ 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> |
||
3589 | @ attention: rotate will mess up the drag interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">drag xy</a> the mouse recognises the original -unrotated- coordinates of the object |
||
3590 | @ attention: <a href="#onclick">onclick</a> is compatible with rotate... |
||
3591 | @%rotate_1%size 400,400%xrange -10,10%yrange -10,10%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%killrotate%rotate 90%fpoly violet,0,0,4,3,2,5% |
||
3592 | @%rotate_onclick%size 600,300%xrange -26,88%yrange -26,26%fontsize 30%fontfamily 25px Ariel%vline 26,0,black%rotate 190%onclick%string black, 6, 8,77%rotate 190%onclick%string black, -2, 10,99%rotate 190%onclick%string red, -9, 4,114%rotate 0%onclick%string black, -9, -4,81%rotate 90%onclick%string black, -2, -10,45%rotate 190%onclick%string black, 6, -8,27%rotate 45%onclick%string black, 10, 0,110%rotate 90%onclick%string black, 0, 0,44%rotate 0%onclick%string black, 68, 8,26%rotate 0%onclick%string red, 59, 10,114%rotate 90%onclick%string black, 53, 4,65%rotate 90%onclick%string black, 53, -5,76%rotate 90%onclick%string black, 61, -10,108%rotate 0%onclick%string black, 69, -7,29%rotate 0%onclick%string black, 72, 1,28%rotate 90%onclick%string black, 62, 0,21% |
||
3593 | |||
3594 | */ |
||
3595 | use_rotate = TRUE; |
||
3596 | angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */ |
||
3597 | if( js_function[ADD_JS_ROTATE_MOUSE] != 1 ){ js_function[ADD_JS_ROTATE_MOUSE] = 1;} |
||
3598 | break; |
||
3599 | |||
3600 | case ROTATION_CENTER: |
||
3601 | /* |
||
3602 | @ rotationcenter x_center,y_center |
||
3603 | @ define an rotation center in your x/y-coordinate system |
||
3604 | @ wims will not check the validity of your input; use javascript console to debug any erors |
||
3605 | @ if not defined a rotation will be around the first point of an object |
||
3606 | @ to be used before command <a href="#rotate">rotate</a> |
||
3607 | @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given |
||
3608 | @%rotationcenter%size 400,400%xrange -5,10%yrange -5,10%circles green,3,3,4.25%rotationcenter 3,3%opacity 255,80%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%rotate 90%fpoly lightblue,0,0,4,3,2,5%rotate 135%fpoly blue,0,0,4,3,2,5%rotate 180%fpoly orange,0,0,4,3,2,5%rotate 225%fpoly green,0,0,4,3,2,5%rotate 270%fpoly cyan,0,0,4,3,2,5%rotate 315%fpoly purple,0,0,4,3,2,5%linewidth 3%point 3,3,red%mouse red,22 |
||
3609 | @%rotationcenter_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 24%slider 0,2*pi,400,30,angle degrees,rotate...%plot red,5*sin(x)%filled%linewidth 1%opacity 150,50%fillcolor orange%angle 0,0,pi,0,0,blue |
||
3610 | */ |
||
3611 | temp = get_string(infile,1); |
||
3612 | string_length = 1 + snprintf(NULL,0,"[ %s ]",temp); |
||
3613 | check_string_length(string_length); |
||
3614 | rotation_center = my_newmem(string_length); |
||
3615 | snprintf(rotation_center,string_length,"[%s]",temp); |
||
3616 | break; |
||
3617 | |||
11806 | schaersvoo | 3618 | case ROUNDRECT: |
3619 | /* |
||
3620 | @ roundrect x1,y1,x2,y2,radius in px,color |
||
14071 | bpr | 3621 | @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle |
3622 | @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code> |
||
3623 | @ fillcolor will be identical to ''color`` |
||
9406 | schaersvoo | 3624 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12111 | schaersvoo | 3625 | @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red |
7614 | schaersvoo | 3626 | */ |
11806 | schaersvoo | 3627 | for(i=0;i<6;i++){ |
3628 | switch(i){ |
||
3629 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
3630 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
3631 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
3632 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
3633 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
3634 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
3635 | /* ensure no inverted roundrect is produced... */ |
||
3636 | 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];} |
||
3637 | 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 | 3638 | decimals = find_number_of_digits(precision); |
14208 | schaersvoo | 3639 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3640 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 3641 | /* click_cnt++;*/ |
3642 | reset(); |
||
11806 | schaersvoo | 3643 | break; |
3644 | } |
||
3645 | } |
||
3646 | break; |
||
8386 | schaersvoo | 3647 | |
11806 | schaersvoo | 3648 | case ROUNDRECTS: |
8347 | schaersvoo | 3649 | /* |
11806 | schaersvoo | 3650 | @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,.... |
14066 | bpr | 3651 | @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command |
9406 | schaersvoo | 3652 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13935 | bpr | 3653 | @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2 |
8347 | schaersvoo | 3654 | */ |
11806 | schaersvoo | 3655 | |
8347 | schaersvoo | 3656 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
11806 | schaersvoo | 3657 | int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */ |
8347 | schaersvoo | 3658 | fill_color = stroke_color; |
3659 | i=0; |
||
3660 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3661 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8347 | schaersvoo | 3662 | if(i%2 == 0 ){ |
3663 | double_data[i] = get_real(infile,0); /* x */ |
||
3664 | } |
||
3665 | else |
||
3666 | { |
||
3667 | double_data[i] = get_real(infile,1); /* y */ |
||
3668 | } |
||
3669 | i++; |
||
3670 | } |
||
3671 | decimals = find_number_of_digits(precision); |
||
3672 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 3673 | /* ensure no inverted roundrect is produced... */ |
3674 | 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];} |
||
3675 | 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];} |
||
14208 | schaersvoo | 3676 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3677 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
8379 | schaersvoo | 3678 | /* click_cnt++; */ |
8347 | schaersvoo | 3679 | } |
3680 | reset(); |
||
3681 | break; |
||
8386 | schaersvoo | 3682 | |
11806 | schaersvoo | 3683 | case RULER: |
7614 | schaersvoo | 3684 | /* |
14078 | bpr | 3685 | @ ruler x,y,x-width,y-height,mode |
11806 | schaersvoo | 3686 | @ x,y are the initial location |
14078 | bpr | 3687 | @ x-width, y-height are the ruler dimensions width & height in xy-coordinate system |
14071 | bpr | 3688 | @ the ruler scale is by definition the x-scale, set by command ''xrange``. For example: a ruler x-width of 6 will have a scale ranging from 0 to 6 |
14066 | bpr | 3689 | @ mode: use -1 to set the ruler interactive (eg mouse movement of ruler; drag & rotate)<br />use mode = '0° - 360°' to set the ruler with a static angle of some value |
11806 | schaersvoo | 3690 | @ if combined with a protractor, use replyformat = 32 |
3691 | @ only one ruler allowed (for the time being) |
||
14385 | bpr | 3692 | @ when using command ''zoom``, pay <b>attention</b> to the size and symmetry of your canvas to avoid a partial image, locate the start position near the center of the visual canvas; technical: the actual ''ruler`` is just a static generated image in a new canvas-memory. This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas. That is the reason for the ''high-speed dragging and rotating``. I have limited its size to xsize × ysize e.g. the same size as the visual canvas... |
14247 | bpr | 3693 | @ usage: first left click on the ruler will activate dragging; a second left click will activate rotating (just move mouse around), a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3), a next click will restart this sequence... |
12111 | schaersvoo | 3694 | @%ruler_interactive%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler -9,0,10,2,-1%display degree,blue,22%zoom red |
3695 | @%ruler_set_degree_45%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,45%zoom red |
||
3696 | @%ruler_set_degree_125%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,125%zoom red |
||
7614 | schaersvoo | 3697 | */ |
11806 | schaersvoo | 3698 | for( i = 0;i < 5; i++ ){ |
7614 | schaersvoo | 3699 | switch(i){ |
11806 | schaersvoo | 3700 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
3701 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
3702 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
3703 | case 3: double_data[3] = get_real(infile,0);break; /* y-width */ |
||
3704 | case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */ |
||
3705 | decimals = find_number_of_digits(precision); |
||
3706 | if( int_data[0] < 0 ){ |
||
14032 | schaersvoo | 3707 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1; } |
11806 | schaersvoo | 3708 | } |
14057 | schaersvoo | 3709 | 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],use_snap); |
14208 | schaersvoo | 3710 | string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id); |
3711 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3712 | snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id); |
3713 | add_to_buffer(tmp_buffer); |
||
3714 | reply_precision = precision; |
||
3715 | /* no reply from ruler if non-interactive */ |
||
3716 | if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;} |
||
7614 | schaersvoo | 3717 | break; |
3718 | default: break; |
||
3719 | } |
||
3720 | } |
||
3721 | break; |
||
8386 | schaersvoo | 3722 | |
11806 | schaersvoo | 3723 | |
3724 | |||
3725 | case SIZE: |
||
3726 | /* |
||
3727 | @ size width,height |
||
3728 | @ set canvas size in pixels |
||
14066 | bpr | 3729 | @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>) |
14162 | bpr | 3730 | @ if xrange and/or yrange is not given the range will be set to pixels:<br />xrange 0,xsize yrange 0,ysize<br />note: lower left corner is origin (0:0) !!! this in contrast to flydraw |
11806 | schaersvoo | 3731 | */ |
3732 | found_size_command = 1; |
||
14066 | bpr | 3733 | /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */ |
11806 | schaersvoo | 3734 | xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
3735 | ysize = (int)(fabs(round(get_real(infile,1)))); |
||
3736 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
3737 | xmin = 0;xmax = xsize; |
||
3738 | ymin = 0;ymax = ysize; |
||
3739 | |||
3740 | /* |
||
3741 | The sequence in which stuff is finally printed is important !! |
||
3742 | */ |
||
3743 | fprintf(stdout,"\n\ |
||
13970 | obado | 3744 | <script>\n\ |
11806 | schaersvoo | 3745 | /*<![CDATA[*/\n\ |
3746 | if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\ |
||
3747 | if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\ |
||
3748 | if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\ |
||
3749 | canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\ |
||
3750 | ",canvas_root_id); |
||
3751 | |||
3752 | /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */ |
||
3753 | if( use_tooltip != 2){ |
||
3754 | fprintf(stdout,"<!-- canvasdraw div -->\n\ |
||
3755 | <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\ |
||
3756 | <!-- tooltip and input placeholder -->\n\ |
||
3757 | <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
||
3758 | <!-- include actual object code via include file -->\n\ |
||
13970 | obado | 3759 | <script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
11806 | schaersvoo | 3760 | } |
3761 | else |
||
3762 | { |
||
3763 | /* |
||
14066 | bpr | 3764 | set canvas_div invisible and do not include placeholder in main html page: |
11806 | schaersvoo | 3765 | the js-include will also be in a popup window...to be shown when wims $status = done |
3766 | */ |
||
3767 | fprintf(stdout,"<!-- canvasdraw div invisible -->\n\ |
||
3768 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\ |
||
3769 | <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>\ |
||
3770 | <!-- include actual object code via include file -->\n\ |
||
13970 | obado | 3771 | <script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
11806 | schaersvoo | 3772 | } |
3773 | |||
14071 | bpr | 3774 | /* these must be global...it is all really very poor javascript:( */ |
13970 | obado | 3775 | fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw */\n\ |
11806 | schaersvoo | 3776 | \"use strict\";\n\ |
13970 | obado | 3777 | /* these variables and functions must be global */\n\ |
11806 | schaersvoo | 3778 | var read_dragdrop%d;\ |
14038 | schaersvoo | 3779 | var read_canvas_images;\ |
11806 | schaersvoo | 3780 | var read_canvas%d;\ |
3781 | var set_clock;\ |
||
3782 | var clear_draw_area%d;\ |
||
3783 | var update_draw_area%d;\ |
||
14038 | schaersvoo | 3784 | var place_image_on_canvas;\ |
11806 | schaersvoo | 3785 | var draw_boxplot;\ |
3786 | var redraw_all%d;\ |
||
3787 | var userdraw_primitive;\n\ |
||
13970 | obado | 3788 | var wims_canvas_function%d = function(){\n/* common used stuff */\n\ |
11806 | schaersvoo | 3789 | var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\ |
3790 | var xsize = %d;\ |
||
3791 | var ysize = %d;\ |
||
3792 | var precision = 100;\ |
||
3793 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
||
3794 | 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;};\ |
||
3795 | 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;};\ |
||
3796 | 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);};};\ |
||
3797 | 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);};};\ |
||
3798 | 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);};};\ |
||
3799 | 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);};};\ |
||
3800 | function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\ |
||
3801 | function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\ |
||
3802 | function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\ |
||
3803 | 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) ));};\ |
||
3804 | 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;};\ |
||
14208 | schaersvoo | 3805 | function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = parseInt(obj.x[p] + dx);obj.y[p] = parseInt(obj.y[p] + dy);};return obj;};\ |
14044 | schaersvoo | 3806 | var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));var snap_x = 1;var snap_y = 1;\ |
11806 | schaersvoo | 3807 | function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\ |
11890 | schaersvoo | 3808 | function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\ |
14044 | schaersvoo | 3809 | function multisnap_check(x,y,snap){switch(snap){case 1:return [snap_to_x(x),snap_to_y(y)];break;case 2:return [snap_to_x(x),y];break;case 3:return [x,snap_to_y(y)];break;case 4:return snap_to_points(x,y);break;default: return [x,y];break;};};\ |
11806 | schaersvoo | 3810 | var xlogbase = 10;\ |
3811 | var ylogbase = 10;\ |
||
3812 | var use_xlogscale = 0;\ |
||
3813 | var use_ylogscale = 0;\ |
||
11891 | schaersvoo | 3814 | var x_strings = {};var x_strings_up = [];\ |
11806 | schaersvoo | 3815 | var y_strings = null;\ |
3816 | var use_pan_and_zoom = 0;\ |
||
3817 | var use_jsmath = 0;\ |
||
3818 | var xstart = 0;\ |
||
3819 | var ystart = 0;\ |
||
3820 | var unit_x=\" \";\ |
||
3821 | var unit_y=\" \";\ |
||
14038 | schaersvoo | 3822 | var external_canvas = create_canvas%d(%d,xsize,ysize);",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); |
14066 | bpr | 3823 | /* default add the drag code: nearly always used ...*/ |
11806 | schaersvoo | 3824 | add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id); |
3825 | |||
3826 | break; |
||
3827 | |||
3828 | |||
3829 | case SEGMENT: |
||
7614 | schaersvoo | 3830 | /* |
11806 | schaersvoo | 3831 | @ segment x1,y1,x2,y2,color |
14071 | bpr | 3832 | @ alternative: <code>seg</code> |
3833 | @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color`` |
||
11806 | schaersvoo | 3834 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14061 | schaersvoo | 3835 | @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green |
3836 | @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green |
||
7614 | schaersvoo | 3837 | */ |
11806 | schaersvoo | 3838 | for(i=0;i<5;i++) { |
7614 | schaersvoo | 3839 | switch(i){ |
11806 | schaersvoo | 3840 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
3841 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
3842 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
3843 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
3844 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
3845 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 3846 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3847 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 3848 | /* click_cnt++; */ |
3849 | reset(); |
||
3850 | break; |
||
3851 | default: break; |
||
7614 | schaersvoo | 3852 | } |
3853 | } |
||
3854 | break; |
||
10953 | bpr | 3855 | |
11806 | schaersvoo | 3856 | case SEGMENTS: |
9213 | schaersvoo | 3857 | /* |
11806 | schaersvoo | 3858 | @ segments color,x1,y1,x2,y2,...,x_n,y_n |
14071 | bpr | 3859 | @ alternative: <code>segs</code> |
3860 | @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color`` |
||
14162 | bpr | 3861 | @ use command ''linewidth int'' to adust size |
11806 | schaersvoo | 3862 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12111 | schaersvoo | 3863 | @%segments_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1 |
3864 | @%segments_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1 |
||
9213 | schaersvoo | 3865 | */ |
11806 | schaersvoo | 3866 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3867 | fill_color = stroke_color; |
||
3868 | i=0; |
||
3869 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3870 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 3871 | if(i%2 == 0 ){ |
3872 | double_data[i] = get_real(infile,0); /* x */ |
||
3873 | } |
||
3874 | else |
||
3875 | { |
||
3876 | double_data[i] = get_real(infile,1); /* y */ |
||
3877 | } |
||
3878 | i++; |
||
3879 | } |
||
3880 | decimals = find_number_of_digits(precision); |
||
3881 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
14208 | schaersvoo | 3882 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
3883 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 3884 | /* click_cnt++;*/ |
3885 | } |
||
3886 | reset(); |
||
9213 | schaersvoo | 3887 | break; |
11806 | schaersvoo | 3888 | |
3889 | case SETLIMITS: |
||
9213 | schaersvoo | 3890 | /* |
11806 | schaersvoo | 3891 | @ setlimits |
14071 | bpr | 3892 | @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button |
11806 | schaersvoo | 3893 | @ may be used for inputfield based zooming / panning |
3894 | @ may be styled using command <a href="#inputstyle">inputstyle</a> |
||
14071 | bpr | 3895 | @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc |
14247 | bpr | 3896 | @ note: the input value will not be checked on validity |
12107 | schaersvoo | 3897 | @%setlimits%size 400,400%xrange -10,10%yrange -10,10%precision 1%xlabel T%ylabel H%axis%axisnumbering%grid 2,2,grey,2,2,5,grey%precision 100%multistrokecolors red,green,blue,orange%multilinewidth 1,1,2,2%multistrokeopacity 0.6,0.7,0.8,0.9%jsplot red,1/x,-1,x,1/(x-3),1/(x+3)%setlimits |
9213 | schaersvoo | 3898 | */ |
11806 | schaersvoo | 3899 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
3900 | add_setlimits(js_include_file,canvas_root_id,font_size,input_style); |
||
3901 | /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */ |
||
3902 | use_pan_and_zoom = TRUE; |
||
3903 | done = TRUE; |
||
9213 | schaersvoo | 3904 | break; |
11806 | schaersvoo | 3905 | |
3906 | case SETPIXEL: |
||
9213 | schaersvoo | 3907 | /* |
11806 | schaersvoo | 3908 | @ setpixel x,y,color |
3909 | @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange |
||
3910 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 3911 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12107 | schaersvoo | 3912 | @%setpixel%size 400,400%xrange -10,10%yrange -10,10%setpixel 1,1,red%pixelsize 2%setpixel 2,2,green%pixelsize 3%setpixel 3,3,blue% |
9213 | schaersvoo | 3913 | */ |
11806 | schaersvoo | 3914 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
3915 | for(i=0;i<3;i++){ |
||
3916 | switch(i){ |
||
3917 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
14162 | bpr | 3918 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11806 | schaersvoo | 3919 | case 2: stroke_color = get_color(infile,1); |
14208 | schaersvoo | 3920 | string_length = 1 + snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
3921 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3922 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
3923 | add_to_buffer(tmp_buffer); |
||
3924 | break; |
||
3925 | default:break; |
||
3926 | } |
||
3927 | } |
||
3928 | reset(); |
||
3929 | break; |
||
3930 | case SLIDER: |
||
9213 | schaersvoo | 3931 | /* |
14071 | bpr | 3932 | @ slider start_value,end_value,width px,height px,type,label |
14385 | bpr | 3933 | @ type may be: ''xy,x,y,angle`` |
11806 | schaersvoo | 3934 | @ 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 |
14071 | bpr | 3935 | @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit`` |
14066 | bpr | 3936 | @ 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 /><code>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... etc</code> |
14071 | bpr | 3937 | @ use command ''slider`` before draggable/clickable objects. |
14066 | bpr | 3938 | @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<br /><code>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</code> |
14071 | bpr | 3939 | @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x`` |
3940 | @ 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`` |
||
11806 | schaersvoo | 3941 | @ amount of sliders is not limited. |
14208 | schaersvoo | 3942 | @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects |
14071 | bpr | 3943 | @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value`` |
3944 | @ type=xy: will produce a 2D ''slider`` [rectangle width x heigh px] in your web page |
||
11806 | schaersvoo | 3945 | @ every draggable object may have its own slider (no limit in amount of sliders) |
3946 | @ label: some slider text |
||
3947 | @ use fillcolor for slider ball |
||
3948 | @ use strokecolor for slider bar |
||
3949 | @ use fontfamily / fontcolor to set used fonts |
||
3950 | @ use opacity (only fill opacity will be used) to set transparency |
||
14071 | bpr | 3951 | @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc |
13950 | schaersvoo | 3952 | @%slider_angle%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,angle degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue |
3953 | @%slider_x%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,x,move arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue%display x,red,12 |
||
13951 | schaersvoo | 3954 | @%slider_x_y_angle%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,angle degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%killslider%opacity 200,100%slider -2,2,300,30,x,move blue rectangle%frect -4,4,1,-1,blue%killslider%slider -2,2,300,30,y,move green rectangle%frect -4,4,1,-1,green |
9213 | schaersvoo | 3955 | */ |
14208 | schaersvoo | 3956 | int_data[2] = 0; /* --> show_display = 0; */ |
11806 | schaersvoo | 3957 | for(i=0; i<6 ; i++){ |
3958 | switch(i){ |
||
3959 | case 0: double_data[0] = get_real(infile,0);break; /* start value */ |
||
3960 | case 1: double_data[1] = get_real(infile,0);break; /* end value */ |
||
3961 | case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */ |
||
3962 | case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */ |
||
14066 | bpr | 3963 | case 4: temp = get_string_argument(infile,0); /* type: xy,x,y,angle */ |
14208 | schaersvoo | 3964 | if( ( strstr(temp,"displ")!=0 || strstr(temp,"deg")!=0 || strstr(temp,"rad")!=0 ) && int_data[2] == 0 ){ |
11806 | schaersvoo | 3965 | add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity); |
3966 | } |
||
14208 | schaersvoo | 3967 | if(strstr(temp,"angle")!= 0){slider_type="R";if( strstr(temp,"rad")!= 0){int_data[2] = 3;}if( strstr(temp,"deg")!= 0){int_data[2] = 4;}} |
11806 | schaersvoo | 3968 | else |
14208 | schaersvoo | 3969 | if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}} |
11806 | schaersvoo | 3970 | else |
14208 | schaersvoo | 3971 | if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}} |
3972 | else |
||
3973 | if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}} |
||
3974 | else |
||
3975 | canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y"); |
||
3976 | break; |
||
3977 | case 5: temp = get_string_argument(infile,1); /* slider label */ break; |
||
11806 | schaersvoo | 3978 | } |
3979 | } |
||
14208 | schaersvoo | 3980 | /* |
3981 | function add_slider(type,titletext,id,width,height,linewidth,fillcolor,strokecolor,opacity,min,max,fun,fontfamily) |
||
3982 | */ |
||
3983 | if(slider_cnt == 0){ |
||
3984 | add_slider(js_include_file,canvas_root_id); |
||
3985 | active_sliders[0] = 0; |
||
3986 | } |
||
3987 | string_length = 1 + snprintf(NULL,0,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,null,'%s',%d);\n",slider_cnt,slider_type,temp,slider_cnt,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]); |
||
3988 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3989 | snprintf(tmp_buffer,string_length ,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,null,'%s',%d);\n",slider_cnt,slider_type,temp,slider_cnt,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]); |
||
3990 | add_to_buffer(tmp_buffer); |
||
3991 | fprintf(js_include_file,"var slider%d;",slider_cnt); |
||
3992 | /* increment here */ |
||
3993 | slider_cnt++; |
||
3994 | active_sliders[slider_cnt] = slider_cnt; |
||
3995 | current_sliders = data2js_array(active_sliders,slider_cnt); |
||
3996 | break; |
||
3997 | |||
14246 | bpr | 3998 | case SLIDER_X: |
9213 | schaersvoo | 3999 | /* |
11806 | schaersvoo | 4000 | @ sliderfunction_x some_function_in_x |
4001 | @ default value "x" |
||
14208 | schaersvoo | 4002 | @ the x-value of the slider object will be calculated with this function. |
11806 | schaersvoo | 4003 | @ default is the x-slider value itself |
14071 | bpr | 4004 | @ only used by command ''slider`` |
11806 | schaersvoo | 4005 | @ define before a slider command ! |
9213 | schaersvoo | 4006 | */ |
11806 | schaersvoo | 4007 | slider_function_x = get_string(infile,1); |
4008 | break; |
||
4009 | case SLIDER_Y: |
||
4010 | slider_function_y = get_string(infile,1); |
||
4011 | /* |
||
4012 | @ sliderfunction_y some_function_in_y |
||
4013 | @ default value "y" |
||
4014 | @ the y-value of the slider object(s) will be calculated with this function. |
||
14071 | bpr | 4015 | @ only used by command ''slider`` |
11806 | schaersvoo | 4016 | @ define before a slider command ! |
4017 | */ |
||
4018 | break; |
||
4019 | case SGRAPH: |
||
4020 | /* |
||
4021 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
14071 | bpr | 4022 | @ primitive implementation of a ''broken scale`` graph... |
4023 | @ 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 /> |
||
12111 | schaersvoo | 4024 | @%sgraph%size 400,400%xrange 0,10000%yrange 0,100%sgraph 9000,50,100,10,4,4,grey,blue%userinput_xy%linewidth 2%userdraw segments,red%precision 0%mouse blue,22 |
11806 | schaersvoo | 4025 | */ |
4026 | if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;} |
||
4027 | for(i = 0 ; i < 8 ;i++){ |
||
4028 | switch(i){ |
||
4029 | case 0:double_data[0] = get_real(infile,0);break; |
||
4030 | case 1:double_data[1] = get_real(infile,0);break; |
||
4031 | case 2:double_data[2] = get_real(infile,0);break; |
||
4032 | case 3:double_data[3] = get_real(infile,0);break; |
||
4033 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
4034 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
4035 | case 6:stroke_color = get_color(infile,0);break; |
||
4036 | case 7:font_color = get_color(infile,1); |
||
14208 | schaersvoo | 4037 | string_length = 1 + 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); |
4038 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4039 | 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); |
4040 | add_to_buffer(tmp_buffer); |
||
4041 | break; |
||
4042 | default:break; |
||
4043 | } |
||
4044 | } |
||
4045 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
9213 | schaersvoo | 4046 | break; |
11806 | schaersvoo | 4047 | |
4048 | case SNAPTOFUNCTION: |
||
9213 | schaersvoo | 4049 | /* |
11806 | schaersvoo | 4050 | @ snaptofunction some_function_in_x,some_funtion_in_y |
14066 | bpr | 4051 | @ alternative: <code>snaptofun some_function_in_x,some_funtion_in_y</code> |
11806 | schaersvoo | 4052 | @ the next object will snap to the calculated values |
14071 | bpr | 4053 | @ note: snaptofun is probably not really useful feature... |
14066 | bpr | 4054 | @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code> |
4055 | @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code> |
||
14071 | bpr | 4056 | @ for now only one instance of ''snaptofunction`` is allowed |
11806 | schaersvoo | 4057 | @ use rawmath on your functions: no validity checking is done by wims ! |
14071 | bpr | 4058 | @ note: switching x and y coordinates? <code>snaptofunction y,x</code> |
13960 | bpr | 4059 | @%snaptofunction_1%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction x,5*sin(x)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,5*sin(x)%xunit = x-value%display x,blue,22 |
4060 | @%snaptofunction_2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction y^2-9,y%#snaptofunction y^2-9,abs(y)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,sqrt(x+9)%curve blue,-1*sqrt(x+9)%yunit = y-value%display y,blue,22 |
||
9213 | schaersvoo | 4061 | */ |
11806 | schaersvoo | 4062 | temp = get_string_argument(infile,0); |
14038 | schaersvoo | 4063 | use_snap = 2; |
11806 | schaersvoo | 4064 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
4065 | add_to_js_math(js_include_file); use_js_math = TRUE; |
||
4066 | } |
||
4067 | 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)); |
||
4068 | break; |
||
4069 | case SNAPTOPOINTS: |
||
4070 | /* |
||
4071 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
||
4072 | @ a userdraw object will snap to these points. |
||
14071 | bpr | 4073 | @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h) |
14162 | bpr | 4074 | @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup) |
14078 | bpr | 4075 | @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid`` |
13950 | schaersvoo | 4076 | @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 2%points red,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%userdraw arrows,red |
11806 | schaersvoo | 4077 | */ |
4078 | i = 0; |
||
14038 | schaersvoo | 4079 | use_snap = 4; |
11806 | schaersvoo | 4080 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 4081 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4082 | if(i%2 == 0 ){ |
4083 | double_data[i] = get_real(infile,0); /* x */ |
||
4084 | } |
||
4085 | else |
||
4086 | { |
||
4087 | double_data[i] = get_real(infile,1); /* y */ |
||
4088 | } |
||
4089 | i++; |
||
4090 | } |
||
4091 | decimals = find_number_of_digits(precision); |
||
14044 | schaersvoo | 4092 | fprintf(js_include_file,"function 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;};function 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)];};",(int) (0.5*i),double_xy2js_array(double_data,i,decimals)); |
11806 | schaersvoo | 4093 | break; |
4094 | |||
4095 | case SNAPTOGRID: |
||
4096 | /* |
||
4097 | @ snaptogrid |
||
4098 | @ keyword (no arguments required) |
||
14162 | bpr | 4099 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup) |
11806 | schaersvoo | 4100 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
14078 | bpr | 4101 | @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1) |
14071 | bpr | 4102 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
14162 | bpr | 4103 | @ 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 <code>snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code> will snap on x=0, x=0.5, x=1, x=1.5 .... will snap on y=0, y=0.25 y=0.5 y=0.75 ... |
12311 | schaersvoo | 4104 | @%snaptogrid_1%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,2,2,6,grey%linewidth 2%snaptogrid%userdraw crosshairs,blue%mouse red,22 |
4105 | @%snaptogrid_2%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,4,1,6,grey%linewidth 1%snaptogrid%userdraw crosshairs,blue%mouse red,22 |
||
11806 | schaersvoo | 4106 | */ |
14038 | schaersvoo | 4107 | use_snap = 1; |
11806 | schaersvoo | 4108 | break; |
4109 | |||
4110 | case SQUARE: |
||
4111 | /* |
||
14078 | bpr | 4112 | @ square x,y,side (px),color |
14380 | bpr | 4113 | @ draw a square with left top corner (x:y) with side ''side`` in color ''color`` |
14071 | bpr | 4114 | @ use command <code>fsquare x,y,side,color</code> for a filled square |
14162 | bpr | 4115 | @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code> |
11806 | schaersvoo | 4116 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 4117 | @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green |
11806 | schaersvoo | 4118 | */ |
11991 | schaersvoo | 4119 | for(i=0;i<4;i++){ |
11806 | schaersvoo | 4120 | switch(i){ |
4121 | case 0:double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
4122 | case 1:double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
11991 | schaersvoo | 4123 | case 2:double_data[2] = get_real(infile,0);break; /* width in px */ |
4124 | case 3:stroke_color = get_color(infile,1);/* name or hex color */ |
||
4125 | decimals = find_number_of_digits(precision); |
||
4126 | double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize; |
||
4127 | double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize; |
||
14208 | schaersvoo | 4128 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
4129 | if(onclick > 0 || slider_cnt > 0){click_cnt++;}/* click_cnt++; */ |
||
11991 | schaersvoo | 4130 | reset();break; |
4131 | default: break; |
||
11806 | schaersvoo | 4132 | } |
4133 | } |
||
9213 | schaersvoo | 4134 | break; |
13829 | bpr | 4135 | |
11806 | schaersvoo | 4136 | case STATUS: |
9213 | schaersvoo | 4137 | /* |
11806 | schaersvoo | 4138 | @ status |
4139 | @ keyword |
||
14066 | bpr | 4140 | @ alernative: nostatus |
14078 | bpr | 4141 | @ used to override the effects of ''status=done`` in wims (answer.phtml) |
14071 | bpr | 4142 | @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands |
4143 | @ 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`` |
||
9213 | schaersvoo | 4144 | */ |
11806 | schaersvoo | 4145 | |
4146 | fprintf(js_include_file,"\nwims_status=\"waiting\";\n"); |
||
9213 | schaersvoo | 4147 | break; |
11806 | schaersvoo | 4148 | |
4149 | case STRING: |
||
9213 | schaersvoo | 4150 | /* |
11806 | schaersvoo | 4151 | @ string color,x,y,the text string |
14542 | schaersvoo | 4152 | @ may be set ''onclick`` or ''drag xy`` ; can not be combined with command ''rotate`` |
14545 | schaersvoo | 4153 | @ note: when set ''onclick`` ,use an extra command ''fontsize`` (default: fontsize=12) to adjust the size of the clicked text-string<br />note: a clicked text string will be hardcoded : fontsize+10 in the font family courier |
14071 | bpr | 4154 | @ unicode supported: <code>string red,0,0,\\u2232</code> |
14542 | schaersvoo | 4155 | @ use commands like ''centered``, ''xyoffset'' etc. for labelling objects |
14071 | bpr | 4156 | @ use a command like <code>fontfamily italic 24px Ariel</code> to set fonts on browser that support font change |
12311 | schaersvoo | 4157 | @%string%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Ariel%crosshair -3,-3,red%crosshair 3,3,blue%string red,-3,-3,Hello World%fontfamily Italic 18px Ariel%string red,3,3,Hello World%fontfamily 22pt STIX%string black,-10,8,\\u03B1 \\u03B2 \\u03B3 \\u03B4 \\u03B5 \\u03B6 \\u03B7 \\u03B8 \\u03B9 \\u03BA \\u03BB \\u03BC \\u03BD \\u03BE \\u03BF |
9213 | schaersvoo | 4158 | */ |
11806 | schaersvoo | 4159 | for(i=0;i<5;i++){ |
4160 | switch(i){ |
||
4161 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
4162 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
4163 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
4164 | case 3: decimals = find_number_of_digits(precision); |
||
4165 | temp = get_string_argument(infile,1); |
||
4166 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 4167 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
4168 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
14038 | schaersvoo | 4169 | onclick = 0; |
4170 | use_offset = 0; |
||
4171 | reset();; |
||
11806 | schaersvoo | 4172 | break; |
4173 | default:break; |
||
4174 | } |
||
9213 | schaersvoo | 4175 | } |
4176 | break; |
||
11806 | schaersvoo | 4177 | |
4178 | case STRINGUP: |
||
9213 | schaersvoo | 4179 | /* |
11806 | schaersvoo | 4180 | @ stringup color,x,y,rotation_degrees,the text string |
14634 | bpr | 4181 | @ can be set ''onclick`` |
14596 | schaersvoo | 4182 | @ note: when set ''onclick`` ,use an extra command ''fontsize`` (default: fontsize=12) to adjust the size of the clicked text-string<br />note: a clicked text string will be hardcoded : fontsize+10 in the font family courier |
4183 | @ can <b>not</b> be set ''drag xy`` (because of translation matrix...mouse incompatible). |
||
14385 | bpr | 4184 | @ unicode supported: <code>stringup red,0,0,45,\\u2232</code>. |
4185 | @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change. |
||
4186 | @ you could use keyword <a href='#yoffset'>yoffset</a> to -sometimes- do a small correction of text placement under/above a point (e.g. text & point have the same coordinates). |
||
14634 | bpr | 4187 | @ note: no need to ''killrotate`` after ''stringup``<br /><code>onclick<br />rotate 45<br />string red,0,0,AAAAAA<br/>killrotate<br />string red,4,4,BBBBBB</code><br />is identical with:<br /><code>onclick<br />stringup red,0,0,45,AAAAAA<br />string red,4,4,BBBBBB</code> |
14596 | schaersvoo | 4188 | @%stringup%size 400,400%xrange -10,10%yrange -10,10%fontsize 24%fontfamily 14px Ariel%crosshair -3,0,red%crosshair 3,0,blue%onclick%stringup green,-3,0,-90,Click me%stringup red,-3,0,-45,Hello World%stringup red,-3,0,45,Hello World%onclick%stringup green,-3,0,90,Click me%stringup blue,3,0,-90,Hello World%stringup blue,3,0,-45,Hello World%stringup blue,3,0,45,Hello World%stringup blue,3,0,90,Hello World |
11806 | schaersvoo | 4189 | |
14634 | bpr | 4190 | */ |
14596 | schaersvoo | 4191 | for(i=0;i<6;i++){ |
11806 | schaersvoo | 4192 | switch(i){ |
14596 | schaersvoo | 4193 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
4194 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
4195 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
4196 | case 3: angle = -1*(get_real(infile,0));break;/* rotation */ |
||
11806 | schaersvoo | 4197 | case 4: decimals = find_number_of_digits(precision); |
14596 | schaersvoo | 4198 | temp = get_string_argument(infile,1); |
4199 | use_rotate = TRUE; |
||
4200 | decimals = find_number_of_digits(precision); |
||
4201 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
||
14634 | bpr | 4202 | if(onclick > 0 || slider_cnt > 0){ |
4203 | if( js_function[ADD_JS_ROTATE_MOUSE] != 1 ){ |
||
14596 | schaersvoo | 4204 | js_function[ADD_JS_ROTATE_MOUSE] = 1; |
14634 | bpr | 4205 | } |
14596 | schaersvoo | 4206 | click_cnt++; |
4207 | } |
||
4208 | onclick = 0; |
||
4209 | use_offset = 0; |
||
4210 | reset(); |
||
4211 | break; |
||
11806 | schaersvoo | 4212 | default:break; |
4213 | } |
||
9213 | schaersvoo | 4214 | } |
14596 | schaersvoo | 4215 | angle = 0.0; |
4216 | use_rotate = FALSE; |
||
9213 | schaersvoo | 4217 | break; |
11767 | schaersvoo | 4218 | |
11806 | schaersvoo | 4219 | case STYLE: |
11767 | schaersvoo | 4220 | /* |
11806 | schaersvoo | 4221 | @ highlight color,opacity,linewidth |
4222 | @ NOT IMPLEMENTED |
||
14071 | bpr | 4223 | @ use command ''onclick``: when the object receives a userclick it will increase its linewidth |
11767 | schaersvoo | 4224 | */ |
4225 | break; |
||
11806 | schaersvoo | 4226 | |
4227 | |||
4228 | case STROKECOLOR: |
||
9213 | schaersvoo | 4229 | /* |
11806 | schaersvoo | 4230 | @ strokecolor colorname or #hex |
14071 | bpr | 4231 | @ to be used for commands that do not supply a color argument (like command ''linegraph``) |
9213 | schaersvoo | 4232 | */ |
11806 | schaersvoo | 4233 | stroke_color = get_color(infile,1); |
9213 | schaersvoo | 4234 | break; |
11806 | schaersvoo | 4235 | |
4236 | case FLY_TEXT: |
||
9213 | schaersvoo | 4237 | /* |
11806 | schaersvoo | 4238 | @ text fontcolor,x,y,font,text_string |
14066 | bpr | 4239 | @ font may be described by keywords: giant,huge,normal,small,tiny |
14542 | schaersvoo | 4240 | @ use command ''fontsize`` to increase the base fontsize for these keywords |
4241 | @ may be set ''onclick`` or ''drag xy`` ; may not be combined with command ''rotate`` |
||
11806 | schaersvoo | 4242 | @ backwards compatible with flydraw |
4243 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
14071 | bpr | 4244 | @ use command ''string`` combined with ''fontfamily`` for a more fine grained control over html5 canvas text element |
14542 | schaersvoo | 4245 | @ Aavoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``, ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something lke ''fontfamily Ariel`` before the old flydraw commands. |
12311 | schaersvoo | 4246 | @%text%size 400,400%xrange -10,10%yrange -10,10%fontsize 14%onclick%drag xy%text green,-4,-4,small,Hello World%drag xy%text red,-4,-2,large,Hello World%drag xy%text blue,-4,0,huge,Hello World%drag xy%text green,-4,3,giant,Hello World%drag xy |
9213 | schaersvoo | 4247 | */ |
11806 | schaersvoo | 4248 | for(i = 0; i < 5 ;i++){ |
4249 | switch(i){ |
||
4250 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
4251 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
4252 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
4253 | case 3: fly_font = get_string_argument(infile,0); |
||
4254 | if(strcmp(fly_font,"giant") == 0){ |
||
4255 | fly_font_size = (int)(font_size + 24); |
||
4256 | } |
||
4257 | else |
||
4258 | { |
||
4259 | if(strcmp(fly_font,"huge") == 0){ |
||
4260 | fly_font_size = (int)(font_size + 14); |
||
4261 | } |
||
4262 | else |
||
4263 | { |
||
4264 | if(strcmp(fly_font,"large") == 0){ |
||
4265 | fly_font_size = (int)(font_size + 6); |
||
4266 | } |
||
4267 | else |
||
4268 | { |
||
4269 | if(strcmp(fly_font,"small") == 0){ |
||
4270 | fly_font_size = (int)(font_size - 4); |
||
4271 | if(fly_font_size<0){fly_font_size = 8;} |
||
4272 | } |
||
4273 | } |
||
4274 | } |
||
4275 | } |
||
4276 | break; |
||
4277 | case 4: |
||
4278 | temp = get_string_argument(infile,1); |
||
4279 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 4280 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
4281 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
14038 | schaersvoo | 4282 | onclick=0; |
4283 | use_offset = 0; |
||
11806 | schaersvoo | 4284 | reset(); |
4285 | break; |
||
4286 | default:break; |
||
4287 | } |
||
10953 | bpr | 4288 | } |
9213 | schaersvoo | 4289 | break; |
11806 | schaersvoo | 4290 | case TEXTAREA: |
9289 | schaersvoo | 4291 | /* |
11806 | schaersvoo | 4292 | @ textarea x,y,cols,rows,readonly,value |
14066 | bpr | 4293 | @ may be further controlled by <a href="#inputstyle">inputstyle</a> |
14162 | bpr | 4294 | @ if ''$status=done`` (e.g. in answer.phtml) the inputfield will be cleared and set readonly. Override this by keyword <a href="#status">status</a>. |
14066 | bpr | 4295 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (<code>javascript:read_canvas();</code>) |
14071 | bpr | 4296 | @ keyword ''xoffset | centered`` is not active for command ''textarea`` |
12107 | schaersvoo | 4297 | @%textarea%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:red;background-color:lightblue;font-size:14px;text-align:center%textarea -3,-2,6,3,1,?%inputstyle color:blue;background-color:yellow;font-size:14px;text-align:center%textarea 0,-2,8,2,1,? |
9289 | schaersvoo | 4298 | */ |
11806 | schaersvoo | 4299 | if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;} |
4300 | for(i = 0 ; i<6;i++){ |
||
9289 | schaersvoo | 4301 | switch(i){ |
11806 | schaersvoo | 4302 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
4303 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
4304 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
4305 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
4306 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
4307 | case 5: temp = get_string_argument(infile,1); |
||
14208 | schaersvoo | 4308 | string_length = 1 + 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); |
4309 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4310 | 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); |
4311 | add_to_buffer(tmp_buffer); |
||
4312 | input_cnt++;break; |
||
9289 | schaersvoo | 4313 | default: break; |
4314 | } |
||
4315 | } |
||
11806 | schaersvoo | 4316 | if(reply_format == 0 ){reply_format = 15;} |
4317 | reset(); |
||
9289 | schaersvoo | 4318 | break; |
11806 | schaersvoo | 4319 | |
11830 | schaersvoo | 4320 | case TEXTFILL: |
4321 | /* |
||
4322 | @ textfill x0,y0,color,some_text |
||
4323 | @ x0,y0 in xrange / yrange |
||
4324 | @ color will be used for the font color |
||
4325 | @ use command <a href="#fontfamily">fontfamily</a> to set font type and size |
||
13829 | bpr | 4326 | @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a> |
13951 | schaersvoo | 4327 | @%textfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fontfamily 24pt Ariel%circles red,0,0,3,3,3,6%textfill 4,4,blue,HELLO WORLD |
11830 | schaersvoo | 4328 | */ |
4329 | |||
4330 | js_function[DRAW_TEXTFILL] = 1; |
||
4331 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
4332 | js_function[DRAW_FILLTOBORDER] = 1; |
||
4333 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
4334 | } |
||
4335 | decimals = find_number_of_digits(precision); |
||
4336 | for(i=0;i<4;i++){ |
||
4337 | switch(i){ |
||
4338 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
||
4339 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
13829 | bpr | 4340 | case 2: font_color = get_color(infile,0); break; |
11830 | schaersvoo | 4341 | case 3: temp = get_string(infile,1); |
14208 | schaersvoo | 4342 | string_length = 1 + snprintf(NULL,0,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp); |
4343 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11830 | schaersvoo | 4344 | snprintf(tmp_buffer,string_length,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp); |
4345 | add_to_buffer(tmp_buffer); |
||
4346 | fill_cnt++; |
||
4347 | break; |
||
4348 | default:break; |
||
4349 | } |
||
4350 | } |
||
4351 | reset(); |
||
4352 | break; |
||
4353 | |||
4354 | |||
11806 | schaersvoo | 4355 | case FLY_TEXTUP: |
9289 | schaersvoo | 4356 | /* |
11806 | schaersvoo | 4357 | @ textup fontcolor,x,y,font,text_string |
14078 | bpr | 4358 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible) |
14066 | bpr | 4359 | @ font may be described by keywords: giant,huge,normal,small,tiny |
14071 | bpr | 4360 | @ use command ''fontsize`` to increase base fontsize for the keywords |
11806 | schaersvoo | 4361 | @ backwards compatible with flydraw |
4362 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
14071 | bpr | 4363 | @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element |
14162 | bpr | 4364 | @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``; ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something like ''fontfamily Ariel`` before the old flydraw commands. |
9289 | schaersvoo | 4365 | */ |
11806 | schaersvoo | 4366 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
4367 | for(i = 0; i<5 ;i++){ |
||
9289 | schaersvoo | 4368 | switch(i){ |
11806 | schaersvoo | 4369 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
4370 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
4371 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
4372 | case 3: fly_font = get_string_argument(infile,0); |
||
4373 | if(strcmp(fly_font,"giant") == 0){ |
||
4374 | fly_font_size = (int)(font_size + 24); |
||
4375 | } |
||
4376 | else |
||
4377 | { |
||
4378 | if(strcmp(fly_font,"huge") == 0){ |
||
4379 | fly_font_size = (int)(font_size + 14); |
||
4380 | } |
||
4381 | else |
||
4382 | { |
||
4383 | if(strcmp(fly_font,"large") == 0){ |
||
4384 | fly_font_size = (int)(font_size + 6); |
||
4385 | } |
||
4386 | else |
||
4387 | { |
||
4388 | if(strcmp(fly_font,"small") == 0){ |
||
4389 | fly_font_size = (int)(font_size - 4); |
||
4390 | if(fly_font_size<0){fly_font_size = 8;} |
||
4391 | } |
||
4392 | } |
||
4393 | } |
||
4394 | } |
||
4395 | break; |
||
4396 | case 4: |
||
9289 | schaersvoo | 4397 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 4398 | temp = get_string_argument(infile,1); |
14208 | schaersvoo | 4399 | string_length = 1 + snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\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,use_offset); |
4400 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11811 | schaersvoo | 4401 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\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,use_offset); |
9289 | schaersvoo | 4402 | add_to_buffer(tmp_buffer); |
14038 | schaersvoo | 4403 | reset();use_offset = 0; |
9289 | schaersvoo | 4404 | break; |
11806 | schaersvoo | 4405 | default:break; |
4406 | } |
||
4407 | } |
||
4408 | break; |
||
4409 | |||
4410 | |||
4411 | case TRACE_JSCURVE: |
||
4412 | /* |
||
4413 | @ trace_jscurve some_math_function |
||
4414 | @ will use a crosshair to trace the jsmath curve |
||
4415 | @ two inputfields will display the current x/y-values (numerical evaluation by javascript) |
||
14071 | bpr | 4416 | @ default labels ''x`` and ''y``; use commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` to customize the labels for the input fields |
11806 | schaersvoo | 4417 | @ use commands fontsize and inputstyle to format the fonts for labels and inputfields. |
14071 | bpr | 4418 | @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair. |
4419 | @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath: use 2*x instead of 2x etc etc no check is done on the validity of your function and/or syntax (use error console to debug any errors...) |
||
4420 | @ be aware that the formulas of the plotted function(s) can be found in the page javascript source |
||
13959 | bpr | 4421 | @%trace_jscurve%size 400,400%xrange -10,10%yrange -10,10%precision 0%axis%axisnumbering%grid 2,2,grey,2,2,5,gray%recision 100%inputstyle color:blue;%linewidth 4%crosshairsize 8%trace_jscurve 5*sin(0.1*x^2)%linewidth 1%jsplot red,5*sin(0.1*x^2)%#only one curve can be traced |
11806 | schaersvoo | 4422 | */ |
4423 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
4424 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4425 | if( use_js_math == FALSE){ |
||
4426 | add_to_js_math(js_include_file); |
||
4427 | use_js_math = TRUE; |
||
4428 | } |
||
4429 | 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); |
||
4430 | break; |
||
4431 | |||
4432 | |||
4433 | case TRANGE: |
||
4434 | /* |
||
4435 | @ trange tmin,tmax |
||
14071 | bpr | 4436 | @ alternative: <code>ranget</code> |
11806 | schaersvoo | 4437 | @ default -2,2 |
4438 | */ |
||
4439 | use_parametric = TRUE; |
||
4440 | for(i = 0 ; i<2; i++){ |
||
4441 | switch(i){ |
||
4442 | case 0: tmin = get_real(infile,0);break; |
||
4443 | case 1: tmax = get_real(infile,1);break; |
||
9289 | schaersvoo | 4444 | default: break; |
4445 | } |
||
4446 | } |
||
14066 | bpr | 4447 | if(tmin >= tmax ){canvas_error(" trange is not OK: tmin < tmax!\n");} |
9289 | schaersvoo | 4448 | break; |
11806 | schaersvoo | 4449 | case TRANSLATION: |
4450 | /* |
||
4451 | @ translation tx,ty |
||
14071 | bpr | 4452 | @ alternative: <code>translate</code> |
11806 | schaersvoo | 4453 | @ will translate the next objects tx in xrange and ty in yrange |
14071 | bpr | 4454 | @ use command ''killtranstation`` to end the command |
13958 | schaersvoo | 4455 | @%translation%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%fillpattern grid%ftriangle -6,6,8,6,5,1,blue%translation 2,2%ftriangle -6,6,8,6,5,1,red |
11806 | schaersvoo | 4456 | */ |
4457 | for(i = 0 ; i<2;i++){ |
||
4458 | switch(i){ |
||
4459 | case 0: double_data[0] = get_real(infile,0);break; |
||
4460 | case 1: double_data[1] = get_real(infile,1); |
||
4461 | use_affine = TRUE; |
||
14548 | schaersvoo | 4462 | string_length = 1 + snprintf(NULL,0, "[1,0,0,1,%d,%d]",(int)(double_data[0]*xsize/(xmax - xmin)),(int)(-1*double_data[1]*ysize/(ymax - ymin))); |
14208 | schaersvoo | 4463 | check_string_length(string_length);affine_matrix = my_newmem(string_length); |
14548 | schaersvoo | 4464 | snprintf(affine_matrix,string_length,"[1,0,0,1,%d,%d]",(int)(double_data[0]*xsize/(xmax - xmin)),(int)(-1*double_data[1]*ysize/(ymax - ymin))); |
4465 | if( js_function[ADD_JS_TRANSFORM_MOUSE] != 1 ){ js_function[ADD_JS_TRANSFORM_MOUSE] = 1;} |
||
11806 | schaersvoo | 4466 | break; |
4467 | default: break; |
||
4468 | } |
||
4469 | } |
||
4470 | break; |
||
4471 | |||
4472 | case TRIANGLE: |
||
4473 | /* |
||
4474 | @ triangle x1,y1,x2,y2,x3,y3,color |
||
14066 | bpr | 4475 | @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle |
11806 | schaersvoo | 4476 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13948 | schaersvoo | 4477 | @%triangle%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%opacity 250,150%drag xy%triangle 0,0,-4,4,6,8,red%drag xy%ftriangle 0,0,-4,-4,6,-8,red%fillpattern grid%drag xy%ftriangle -6,6,8,6,5,1,blue |
11806 | schaersvoo | 4478 | */ |
4479 | for(i=0;i<7;i++){ |
||
4480 | switch(i){ |
||
4481 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
4482 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
4483 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
4484 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
4485 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
4486 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
4487 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
4488 | decimals = find_number_of_digits(precision); |
||
14208 | schaersvoo | 4489 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
4490 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 4491 | /* click_cnt++;*/ |
4492 | reset(); |
||
4493 | break; |
||
4494 | default: break; |
||
4495 | } |
||
4496 | } |
||
4497 | break; |
||
4498 | case TRIANGLES: |
||
4499 | /* |
||
4500 | @ triangles color,x1,y1,x2,y2,x3,y3,... |
||
14066 | bpr | 4501 | @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles |
11806 | schaersvoo | 4502 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
13948 | schaersvoo | 4503 | @%triangles%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%onclick%triangles red,0,0,-4,4,6,8,0,0,-4,-4,6,-8,-6,6,8,6,5,1%# the same as 3 calls to command triangle |
11806 | schaersvoo | 4504 | */ |
4505 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
4506 | i = 0; |
||
4507 | decimals = find_number_of_digits(precision); |
||
4508 | while( ! done ){ |
||
11997 | schaersvoo | 4509 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4510 | double_data[0] = get_real(infile,0); /* x1 */ |
4511 | double_data[1] = get_real(infile,0); /* y1 */ |
||
4512 | double_data[2] = get_real(infile,0); /* x2 */ |
||
4513 | double_data[3] = get_real(infile,0); /* y2 */ |
||
4514 | double_data[4] = get_real(infile,0); /* x3 */ |
||
4515 | double_data[5] = get_real(infile,1); /* y3 */ |
||
14208 | schaersvoo | 4516 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
4517 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 4518 | i = i + 6; |
4519 | } |
||
4520 | reset(); |
||
4521 | break; |
||
4522 | case USERBOXPLOT: |
||
4523 | /* |
||
4524 | @ userboxplot |
||
4525 | @ keyword, no arguments |
||
14066 | bpr | 4526 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 4527 | @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function |
4528 | @ for example: 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 /><code>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 />};</code><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) |
||
11806 | schaersvoo | 4529 | */ |
4530 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
4531 | fprintf(js_include_file,"var boxplot_source = 3;\n"); |
||
4532 | js_function[DRAW_JSBOXPLOT] = 2; |
||
4533 | break; |
||
4534 | |||
4535 | case USERBOXPLOTDATA: |
||
4536 | /* |
||
4537 | @ userboxplotdata |
||
4538 | @ keyword, no arguments |
||
14066 | bpr | 4539 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 4540 | @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data`` |
14380 | bpr | 4541 | @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the ''draw_boxplot`` function will draw a boxplot. |
14066 | bpr | 4542 | @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()' |
11806 | schaersvoo | 4543 | */ |
4544 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
4545 | fprintf(js_include_file,"var boxplot_source = 2;\n"); |
||
4546 | js_function[DRAW_JSBOXPLOT] = 1; |
||
4547 | |||
4548 | break; |
||
4549 | |||
7614 | schaersvoo | 4550 | case USERDRAW: |
4551 | /* |
||
4552 | @ userdraw object_type,color |
||
9213 | schaersvoo | 4553 | @ only a single object_type is allowed. |
14388 | bpr | 4554 | @ for multiple different ''userdraw`` objects in an exercise, use command <a href="#multidraw">multidraw</a> |
14385 | bpr | 4555 | @ 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>''curvedarrow``</li><li>''curvedarrows``</li><li>''curvedarrow2``</li><li>''curvedarrows2``</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 ''color``. Multiple areas may be selected, multiple colors may be provided using commands <a href='#colorpalette'>colorpalette color1,color2,color3,...</a> or <a href='#multifillcolors'>multifillcolors color1,color2,color_3,...</a> use <a href='#replyformat'>replyformat 10</a> for checking the user click color ... reply=x1:y1:color1,x2:y2:color2...<br/>attention: this will <b>not</b> work for pattern filling, because the pattern image is only generated once and after creation can not be changed ! the opacity of this image on a separate canvas is set to 0.01 and not 0 (!!)...in the ''fill algorithm`` the opacity of the matching pixels is set to 1</li><li>''dotfill``: fill the clicked area with a dot pattern; use command ''linewidth`` to change dot size</li><li>''diamondfill``: fill the clicked area with a diamond pattern</li><li>''hatchfill``: fill the clicked area with a hatch pattern</li><li>''gridfill``: fill the clicked area with a grid pattern</li><li>''textfill``: fill the clicked area with a repeating string <code>userdraw textfill,blue,some_text</code>. use command <a href="#fontfamily">fontfamily</a> to adjust text style and size</li><li>''clickfill | pattern filling`` in general: the clicks may be set <a href="#snaptogrid">snaptogrid</a><br />can be used together with command <a href="#floodfill">floodfill or fill</a><br /><b>always</b> use together with command <a href="#clearbutton">clearbutton some_text</a> for removal of all click_colored areas<br />the function read_canvas() will return the click coordinates in the sequence of the user clicks<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``: place a single inputfield on ''canvas`` ; use commands ''inputstyle`` for css styling; use command ''linewidth`` for adjusting the input field size (default 1)</li><li>''inputs``: place multiple inputfield; placing inputfields on top of each other is not possible.</li></ul> |
14078 | bpr | 4556 | @ note: 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) |
4557 | @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />''backspace / delete / esc`` will remove typed text if the mouse is clicked on the text.<br />You will need to hit ''enter`` to add the text to the array ''userdraw_txt``<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 |
||
11088 | schaersvoo | 4558 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
14066 | bpr | 4559 | @ note: 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) |
14380 | bpr | 4560 | @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles, filledcircles, etc) |
11839 | schaersvoo | 4561 | @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a> |
14071 | bpr | 4562 | @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects |
14078 | bpr | 4563 | @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing |
4564 | @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...) |
||
14071 | bpr | 4565 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...) |
14066 | bpr | 4566 | @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a> |
4567 | @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply |
||
13956 | schaersvoo | 4568 | @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a> |
14380 | bpr | 4569 | @ note: 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 widh userdraw! use command <a href="#multidraw">multidraw</a> is this is a problem for you... |
14247 | bpr | 4570 | @ note: the default replyformat for ''userdraw input(s),color`` used format x1;y1;text1 \n x2;y2;test2 \n x_n;y_n;text_n (e.g. it is not a comma separated array...use ''direct exec`` to test) |
14270 | schaersvoo | 4571 | @ note: a special case is ''userdraw images,boguscolor``. Images (bitmap or svg or div) present in the exercise page and the img/svg/div-tag with an unique 'id' and <code>onclick='javascript:place_image_on_canvas(this.id)'</code> can be placed onto the canvas.<br />The ''id`` and (x;y) coordinates will be returned using read_canvas();<br /> native MathML, MathJax or KaTeX typesetting may be included in div's.(experiments; wims_modules svn version only!) |
12107 | schaersvoo | 4572 | @%userdraw_canvastype_a%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%snaptogrid%replyformat 10%colorpalette orange,yellow,red,green,lightgreen,blue,lightblue,cyan%canvastype 4%userdraw clickfill,blue%clearbutton REMOVE LAST RECTANGLE |
4573 | @%userdraw_canvastype_b%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%canvastype 4%snaptogrid%replyformat 10%userdraw dotfill,blue%clearbutton REMOVE LAST RECTANGLE |
||
4574 | @%userdraw_rect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rect,green |
||
4575 | @%userdraw_rects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rects,green |
||
4576 | @%userdraw_frect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frect,green |
||
4577 | @%userdraw_frects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frects,green |
||
4578 | @%userdraw_roundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrect,green |
||
4579 | @%userdraw_roundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrects,green |
||
4580 | @%userdraw_froundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrect,green |
||
4581 | @%userdraw_froundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrects,green |
||
4582 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
4583 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
4584 | @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green |
||
4585 | @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green |
||
4586 | @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green |
||
4587 | @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green |
||
4588 | @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green |
||
4589 | @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green |
||
4590 | @%userdraw_arc%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arc,green |
||
4591 | @%userdraw_arcs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arcs,green |
||
4592 | @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green |
||
4593 | @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green |
||
4594 | @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green |
||
4595 | @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green |
||
4596 | @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green |
||
4597 | @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green |
||
14025 | schaersvoo | 4598 | @%userdraw_curvedarrow%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow,red%clearbutton REMOVE ALL ARROWS |
4599 | @%userdraw_curvedarrows%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows,red%clearbutton REMOVE ALL ARROWS |
||
14270 | schaersvoo | 4600 | @%userdraw_curvedarrow2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow2,red%clearbutton REMOVE ALL ARROWS |
4601 | @%userdraw_curvedarrows2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows2,red%clearbutton REMOVE ALL ARROWS |
||
12107 | schaersvoo | 4602 | @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green |
4603 | @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green |
||
4604 | @%userdraw_circle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circle,green |
||
4605 | @%userdraw_circles%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circles,green |
||
4606 | @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green |
||
4607 | @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green |
||
4608 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
4609 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
4610 | @%userdraw_triangle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw triangle,green |
||
4611 | @%userdraw_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly5,green |
||
4612 | @%userdraw_filled_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly5,green |
||
4613 | @%userdraw_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly7,green |
||
4614 | @%userdraw_filled_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly7,green |
||
4615 | @%userdraw_polyline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw polyline,green |
||
4616 | @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green |
||
4617 | @%userdraw_filled_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw freehandline,green |
||
4618 | @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green |
||
4619 | @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green |
||
4620 | @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green |
||
4621 | @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green |
||
14044 | schaersvoo | 4622 | @%userdraw_clickfill_colorpalette%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%colorpalette red,green,yellow,blue%userdraw clickfill,green |
13948 | schaersvoo | 4623 | @%userdraw_clickfill_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%userdraw clickfill,green |
4624 | @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw hatchfill,red%#userdraw dotfill,red%#userdraw diamonefill,red%#userdraw gridfill,red |
||
14071 | bpr | 4625 | @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%# to get nice click coordinates take invisible ''grid`` and use ''snaptogrid`` %grid 1,1,white%snaptogrid%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw gridfill,red |
7614 | schaersvoo | 4626 | */ |
4627 | if( use_userdraw == TRUE ){ /* only one object type may be drawn*/ |
||
14038 | schaersvoo | 4628 | canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this..."); |
7614 | schaersvoo | 4629 | } |
8074 | schaersvoo | 4630 | reply_precision = precision; |
7614 | schaersvoo | 4631 | use_userdraw = TRUE; |
13970 | obado | 4632 | fprintf(js_include_file,"\n/* begin userdraw mouse events */\n\ |
11839 | schaersvoo | 4633 | userdraw_x = new Array();userdraw_y = new Array();\ |
11041 | schaersvoo | 4634 | userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\ |
11001 | schaersvoo | 4635 | var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\ |
4636 | if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\ |
||
4637 | if(wims_status != \"done\"){\ |
||
14038 | schaersvoo | 4638 | canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\ |
4639 | canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\ |
||
4640 | canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
4641 | canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\ |
||
14044 | schaersvoo | 4642 | }\n/* end userdraw mouse & touch events */",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]); |
14123 | schaersvoo | 4643 | |
4644 | // canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false); |
||
7614 | schaersvoo | 4645 | draw_type = get_string_argument(infile,0); |
4646 | stroke_color = get_color(infile,1); |
||
4647 | if( strcmp(draw_type,"point") == 0 ){ |
||
4648 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 4649 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 4650 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
12006 | schaersvoo | 4651 | /* |
14066 | bpr | 4652 | type = 0: a point ...radius is fixed |
4653 | type = 1: a circle ... read inputfield userinput_r |
||
4654 | num = 1: a single point / circle |
||
4655 | num = 2: multiple points / circles |
||
12006 | schaersvoo | 4656 | */ |
8071 | schaersvoo | 4657 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4658 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4659 | add_input_circle(js_include_file,0,1); |
8815 | schaersvoo | 4660 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4661 | } |
14044 | schaersvoo | 4662 | 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,use_snap); |
7614 | schaersvoo | 4663 | } |
4664 | else |
||
4665 | if( strcmp(draw_type,"points") == 0 ){ |
||
4666 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 4667 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 4668 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 4669 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4670 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4671 | add_input_circle(js_include_file,0,2); |
8815 | schaersvoo | 4672 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4673 | } |
14044 | schaersvoo | 4674 | 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,use_snap); |
7614 | schaersvoo | 4675 | } |
4676 | else |
||
4677 | if( strcmp(draw_type,"segment") == 0 ){ |
||
4678 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4679 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 4680 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 4681 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4682 | if(use_input_xy == 1){ |
7652 | schaersvoo | 4683 | add_input_segment(js_include_file,1); |
8815 | schaersvoo | 4684 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4685 | } |
14044 | schaersvoo | 4686 | add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7614 | schaersvoo | 4687 | } |
4688 | else |
||
10975 | schaersvoo | 4689 | if( strcmp(draw_type,"polyline") == 0 || strcmp(draw_type,"brokenline") == 0 ){ |
7663 | schaersvoo | 4690 | if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;} |
7876 | schaersvoo | 4691 | if(reply_format == 0){reply_format = 23;} |
8071 | schaersvoo | 4692 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7780 | schaersvoo | 4693 | if( use_input_xy == 1 ){ |
4694 | add_input_polyline(js_include_file); |
||
8815 | schaersvoo | 4695 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7663 | schaersvoo | 4696 | } |
14044 | schaersvoo | 4697 | add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7663 | schaersvoo | 4698 | } |
4699 | else |
||
7614 | schaersvoo | 4700 | if( strcmp(draw_type,"segments") == 0 ){ |
4701 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4702 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 4703 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 4704 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4705 | if(use_input_xy == 1){ |
7652 | schaersvoo | 4706 | add_input_segment(js_include_file,2); |
8815 | schaersvoo | 4707 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4708 | } |
14044 | schaersvoo | 4709 | add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7614 | schaersvoo | 4710 | } |
4711 | else |
||
11839 | schaersvoo | 4712 | if( strcmp(draw_type,"circle") == 0 || strcmp(draw_type,"fcircle") == 0 || strcmp(draw_type,"filledcircle") == 0 ){ |
7614 | schaersvoo | 4713 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
7876 | schaersvoo | 4714 | if(reply_format == 0){reply_format = 10;} |
11875 | schaersvoo | 4715 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}} |
7614 | schaersvoo | 4716 | /* 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 | 4717 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4718 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4719 | /* |
14066 | bpr | 4720 | type = 0: a point ...radius is fixed |
4721 | type = 1: a circle ... read inputfield userinput_r |
||
4722 | num = 1: a single point / circle |
||
4723 | num = 2: multiple points / circles |
||
12006 | schaersvoo | 4724 | */ |
4725 | add_input_circle(js_include_file,1,1); |
||
8815 | schaersvoo | 4726 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4727 | } |
14044 | schaersvoo | 4728 | 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],use_snap); |
7614 | schaersvoo | 4729 | } |
4730 | else |
||
11839 | schaersvoo | 4731 | if( strcmp(draw_type,"circles") == 0 || strcmp(draw_type,"fcircles") == 0 || strcmp(draw_type,"filledcircles") == 0 ){ |
7614 | schaersvoo | 4732 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
7876 | schaersvoo | 4733 | if(reply_format == 0){reply_format = 10;} |
11839 | schaersvoo | 4734 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7614 | schaersvoo | 4735 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
14044 | schaersvoo | 4736 | 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],use_snap); |
8071 | schaersvoo | 4737 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4738 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4739 | add_input_circle(js_include_file,1,2); |
8815 | schaersvoo | 4740 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4741 | } |
7614 | schaersvoo | 4742 | } |
4743 | else |
||
4744 | if(strcmp(draw_type,"crosshair") == 0 ){ |
||
4745 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 4746 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 4747 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
14044 | schaersvoo | 4748 | add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap); |
8071 | schaersvoo | 4749 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4750 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4751 | add_input_crosshair(js_include_file,1); |
8815 | schaersvoo | 4752 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4753 | } |
7614 | schaersvoo | 4754 | } |
4755 | else |
||
4756 | if(strcmp(draw_type,"crosshairs") == 0 ){ |
||
4757 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 4758 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 4759 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
14044 | schaersvoo | 4760 | add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap); |
8071 | schaersvoo | 4761 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4762 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4763 | add_input_crosshair(js_include_file,2); |
8815 | schaersvoo | 4764 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4765 | } |
7614 | schaersvoo | 4766 | } |
4767 | else |
||
4768 | if(strcmp(draw_type,"freehandline") == 0 ){ |
||
4769 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4770 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4771 | 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],use_snap); |
7652 | schaersvoo | 4772 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4773 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4774 | } |
4775 | else |
||
4776 | if(strcmp(draw_type,"freehandlines") == 0 ){ |
||
4777 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4778 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4779 | 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],use_snap); |
7652 | schaersvoo | 4780 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4781 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4782 | } |
4783 | else |
||
11839 | schaersvoo | 4784 | if(strcmp(draw_type,"path") == 0 || strcmp(draw_type,"fpath") == 0 || strcmp(draw_type,"filledpath") == 0 ){ |
7614 | schaersvoo | 4785 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
13829 | bpr | 4786 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4787 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4788 | 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],use_snap); |
7652 | schaersvoo | 4789 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4790 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4791 | } |
4792 | else |
||
11839 | schaersvoo | 4793 | if(strcmp(draw_type,"paths") == 0 || strcmp(draw_type,"fpaths") == 0 || strcmp(draw_type,"filledpaths") == 0 ){ |
7614 | schaersvoo | 4794 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
13829 | bpr | 4795 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4796 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4797 | 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],use_snap); |
7652 | schaersvoo | 4798 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4799 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4800 | } |
4801 | else |
||
4802 | if(strcmp(draw_type,"arrows") == 0 ){ |
||
4803 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4804 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4805 | add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4806 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4807 | add_input_arrow(js_include_file,2); |
8815 | schaersvoo | 4808 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4809 | } |
8071 | schaersvoo | 4810 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4811 | } |
4812 | else |
||
7874 | schaersvoo | 4813 | if(strcmp(draw_type,"arrows2") == 0 ){ |
4814 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4815 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4816 | add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4817 | if(use_input_xy == 1){ |
7874 | schaersvoo | 4818 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4819 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 4820 | } |
8071 | schaersvoo | 4821 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 4822 | } |
4823 | else |
||
4824 | if(strcmp(draw_type,"arrow2") == 0 ){ |
||
4825 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4826 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4827 | add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4828 | if(use_input_xy == 1){ |
7874 | schaersvoo | 4829 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4830 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 4831 | } |
8071 | schaersvoo | 4832 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 4833 | } |
4834 | else |
||
7614 | schaersvoo | 4835 | if(strcmp(draw_type,"arrow") == 0 ){ |
4836 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4837 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4838 | add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4839 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4840 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4841 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4842 | } |
8071 | schaersvoo | 4843 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4844 | } |
4845 | else |
||
14027 | schaersvoo | 4846 | if( strcmp(draw_type,"curvedarrow2") == 0 ){ |
14035 | schaersvoo | 4847 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4848 | add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap); |
14027 | schaersvoo | 4849 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4850 | } |
4851 | else |
||
4852 | if( strcmp(draw_type,"curvedarrows2") == 0 ){ |
||
14035 | schaersvoo | 4853 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4854 | add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap); |
14027 | schaersvoo | 4855 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4856 | } |
4857 | else |
||
4858 | if( strcmp(draw_type,"curvedarrows") == 0 ){ |
||
14035 | schaersvoo | 4859 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4860 | add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap); |
14027 | schaersvoo | 4861 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4862 | } |
4863 | else |
||
4864 | if( strcmp(draw_type,"curvedarrow") == 0 ){ |
||
14035 | schaersvoo | 4865 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4866 | add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap); |
14027 | schaersvoo | 4867 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4868 | } |
14025 | schaersvoo | 4869 | else |
11839 | schaersvoo | 4870 | if(strcmp(draw_type,"polygon") == 0 || strcmp(draw_type,"fpolygon") == 0 || strcmp(draw_type,"filledpolygon") == 0){ |
7614 | schaersvoo | 4871 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
11839 | schaersvoo | 4872 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4873 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4874 | 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],use_snap); |
8071 | schaersvoo | 4875 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4876 | if(use_input_xy == 2){ |
||
7780 | schaersvoo | 4877 | add_textarea_polygon(js_include_file); |
8815 | schaersvoo | 4878 | add_textarea_xy(js_include_file,canvas_root_id,input_style); |
7746 | schaersvoo | 4879 | } |
7614 | schaersvoo | 4880 | } |
8224 | bpr | 4881 | else |
7614 | schaersvoo | 4882 | if(strncmp(draw_type,"poly",4) == 0){ |
4883 | if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");} |
||
4884 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4885 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4886 | 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],use_snap); |
7652 | schaersvoo | 4887 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4888 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4889 | } |
8224 | bpr | 4890 | else |
11839 | schaersvoo | 4891 | if(strcmp(draw_type,"triangle") == 0 || strcmp(draw_type,"ftriangle") == 0 || strcmp(draw_type,"filledtriangle") == 0){ |
7614 | schaersvoo | 4892 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
11839 | schaersvoo | 4893 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4894 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4895 | 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],use_snap); |
7652 | schaersvoo | 4896 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4897 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4898 | } |
8224 | bpr | 4899 | else |
7989 | schaersvoo | 4900 | if( strcmp(draw_type,"hline") == 0 ){ |
4901 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4902 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4903 | add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4904 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4905 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4906 | } |
4907 | else |
||
4908 | if( strcmp(draw_type,"hlines") == 0 ){ |
||
4909 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4910 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4911 | add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4912 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4913 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4914 | } |
4915 | else |
||
4916 | if( strcmp(draw_type,"vline") == 0 ){ |
||
4917 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4918 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4919 | add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4920 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4921 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4922 | } |
4923 | else |
||
4924 | if( strcmp(draw_type,"vlines") == 0 ){ |
||
4925 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4926 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4927 | add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4928 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4929 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4930 | } |
4931 | else |
||
7614 | schaersvoo | 4932 | if( strcmp(draw_type,"line") == 0 ){ |
4933 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4934 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 4935 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4936 | add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7747 | schaersvoo | 4937 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 4938 | add_input_line(js_include_file,1); |
8815 | schaersvoo | 4939 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7747 | schaersvoo | 4940 | } |
8071 | schaersvoo | 4941 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4942 | } |
4943 | else |
||
4944 | if( strcmp(draw_type,"lines") == 0 ){ |
||
4945 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4946 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 4947 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4948 | add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7747 | schaersvoo | 4949 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 4950 | add_input_line(js_include_file,2); |
8815 | schaersvoo | 4951 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7746 | schaersvoo | 4952 | } |
8071 | schaersvoo | 4953 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4954 | } |
4955 | else |
||
8362 | schaersvoo | 4956 | if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){ |
8244 | schaersvoo | 4957 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
4958 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
4959 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4960 | add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8244 | schaersvoo | 4961 | if( use_input_xy == 1 ){ |
4962 | add_input_demiline(js_include_file,2); |
||
8815 | schaersvoo | 4963 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 4964 | } |
4965 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4966 | } |
||
4967 | else |
||
8362 | schaersvoo | 4968 | if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){ |
8244 | schaersvoo | 4969 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
4970 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
4971 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4972 | add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8244 | schaersvoo | 4973 | if( use_input_xy == 1 ){ |
4974 | add_input_demiline(js_include_file,1); |
||
8815 | schaersvoo | 4975 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 4976 | } |
4977 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4978 | } |
||
4979 | else |
||
11839 | schaersvoo | 4980 | if( strcmp(draw_type,"rects") == 0 || strcmp(draw_type,"frects") == 0 || strcmp(draw_type,"filledrects") == 0 ){ |
7614 | schaersvoo | 4981 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
12008 | schaersvoo | 4982 | if(strstr(draw_type,"f") != NULL){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4983 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4984 | 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],use_snap); |
7652 | schaersvoo | 4985 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4986 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4987 | } |
8224 | bpr | 4988 | else |
11839 | schaersvoo | 4989 | if( strcmp(draw_type,"roundrects") == 0 || strcmp(draw_type,"froundrects") == 0 || strcmp(draw_type,"filledroundrects") == 0){ |
7614 | schaersvoo | 4990 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
11839 | schaersvoo | 4991 | if( strstr(draw_type,"f") != NULL ){ if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4992 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4993 | 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],use_snap); |
7652 | schaersvoo | 4994 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4995 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4996 | } |
8224 | bpr | 4997 | else |
11839 | schaersvoo | 4998 | if( strcmp(draw_type,"rect") == 0 || strcmp(draw_type,"frect") == 0 || strcmp(draw_type,"filledrect") == 0 ){ |
7614 | schaersvoo | 4999 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
13829 | bpr | 5000 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 5001 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 5002 | 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],use_snap); |
7652 | schaersvoo | 5003 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 5004 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 5005 | } |
8224 | bpr | 5006 | else |
11839 | schaersvoo | 5007 | if( strcmp(draw_type,"roundrect") == 0 || strcmp(draw_type,"froundrect") == 0 || strcmp(draw_type,"filledroundrect") == 0){ |
7614 | schaersvoo | 5008 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
11839 | schaersvoo | 5009 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}} |
7876 | schaersvoo | 5010 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 5011 | 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],use_snap); |
7652 | schaersvoo | 5012 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 5013 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 5014 | } |
5015 | else |
||
11839 | schaersvoo | 5016 | if( strcmp(draw_type,"arcs") == 0 || strcmp(draw_type,"farcs") == 0 || strcmp(draw_type,"filledarcs") == 0 ){ |
8083 | schaersvoo | 5017 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
11839 | schaersvoo | 5018 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;} |
5019 | if( strstr(draw_type,"f") != NULL ){use_filled =1;} |
||
8083 | schaersvoo | 5020 | if(reply_format == 0){reply_format = 25;} |
14044 | schaersvoo | 5021 | 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],use_filled,use_snap); |
8083 | schaersvoo | 5022 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
5023 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
5024 | } |
||
5025 | else |
||
11839 | schaersvoo | 5026 | if( strcmp(draw_type,"arc") == 0 || strcmp(draw_type,"farc") == 0 || strcmp(draw_type,"filledarc") == 0){ |
8071 | schaersvoo | 5027 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
11017 | schaersvoo | 5028 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;} |
11839 | schaersvoo | 5029 | if( strstr(draw_type,"f") != NULL ){use_filled =1;} |
8083 | schaersvoo | 5030 | if(reply_format == 0){reply_format = 25;} |
14044 | schaersvoo | 5031 | 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],use_filled,use_snap); |
8071 | schaersvoo | 5032 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
5033 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
5034 | } |
||
5035 | else |
||
7614 | schaersvoo | 5036 | if( strcmp(draw_type,"text") == 0){ |
7876 | schaersvoo | 5037 | if(reply_format == 0){reply_format = 17;} |
14044 | schaersvoo | 5038 | add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity,use_snap); |
7652 | schaersvoo | 5039 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 5040 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 5041 | } |
8116 | schaersvoo | 5042 | else |
14038 | schaersvoo | 5043 | if( strcmp(draw_type,"images") == 0){ |
5044 | if(reply_format == 0){reply_format = 29;} |
||
5045 | add_js_images(js_include_file,canvas_root_id,use_offset,use_snap); |
||
5046 | } |
||
5047 | else |
||
8116 | schaersvoo | 5048 | if( strcmp(draw_type,"inputs") == 0){ |
8224 | bpr | 5049 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 5050 | if(reply_format == 0){reply_format = 27;} |
14044 | schaersvoo | 5051 | add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset,use_snap); |
8116 | schaersvoo | 5052 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
5053 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
5054 | } |
||
5055 | else |
||
5056 | if( strcmp(draw_type,"input") == 0){ |
||
8224 | bpr | 5057 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 5058 | if(reply_format == 0){reply_format = 27;} |
14044 | schaersvoo | 5059 | add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset,use_snap); |
8116 | schaersvoo | 5060 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
5061 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
5062 | } |
||
11839 | schaersvoo | 5063 | else /* attention: THIS NEEDS TO BE LAST ! */ |
11825 | schaersvoo | 5064 | if( strstr(draw_type,"fill") != NULL ){ |
11005 | schaersvoo | 5065 | decimals = find_number_of_digits(precision); |
14044 | schaersvoo | 5066 | add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215),use_snap); |
5067 | if( reply_format == 0){reply_format = 10;} |
||
11825 | schaersvoo | 5068 | if( js_function[DRAW_FILLTOBORDER] != 1 ){js_function[DRAW_FILLTOBORDER] = 1;add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);} |
14208 | schaersvoo | 5069 | if( strcmp(draw_type,"gridfill") == 0){js_function[DRAW_GRIDFILL] = 1;string_length = 1 + snprintf(NULL,0,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length);snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
5070 | if( strcmp(draw_type,"diamondfill") == 0){js_function[DRAW_DIAMONDFILL] = 1;string_length = 1 + snprintf(NULL,0,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length);snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
5071 | if( strcmp(draw_type,"dotfill") == 0){js_function[DRAW_DOTFILL] = 1;string_length = 1 + snprintf(NULL,0,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length);snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
5072 | if( strcmp(draw_type,"hatchfill") == 0){js_function[DRAW_HATCHFILL] = 1;string_length = 1 + snprintf(NULL,0,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length);snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
5073 | if( strcmp(draw_type,"textfill") == 0){js_function[DRAW_TEXTFILL] = 1;temp = get_string(infile,1);string_length = 1 + snprintf(NULL,0,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);check_string_length(string_length);tmp_buffer = my_newmem(string_length);snprintf(tmp_buffer,string_length,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
11005 | schaersvoo | 5074 | } |
5075 | else |
||
7614 | schaersvoo | 5076 | { |
5077 | canvas_error("unknown drawtype or typo? "); |
||
5078 | } |
||
5079 | reset(); |
||
5080 | break; |
||
8386 | schaersvoo | 5081 | |
5082 | case USERINPUT: |
||
5083 | /* |
||
13955 | schaersvoo | 5084 | @ userinput function inputfield |
14071 | bpr | 5085 | @ alternative: <code>userinput_function</code> |
5086 | @ alternative: <code>userinput_xy</code> |
||
14086 | bpr | 5087 | @ textarea and inputfield are only usable in combination with some ''userdraw draw_ type`` |
8386 | schaersvoo | 5088 | @ function may be used any time (e.g. without userdraw) |
14071 | bpr | 5089 | @ multiple ''userinput function`` commands may be used. |
5090 | @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)=" |
||
5091 | @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color |
||
5092 | @ use command <code>inputstyle some_css</code> to adjust the inputfields |
||
5093 | @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px) |
||
5094 | @ 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 |
||
13959 | bpr | 5095 | @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%grid 2,2,grey,3,3,5,grey%inputstyle color:blue;text-align:center%userinput function%# note: number of function inputs not limited |
13955 | schaersvoo | 5096 | @%userinput_points%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%# adding 2 inputfields for x and y%userinput inputfield%userdraw points,blue |
5097 | @%userinput_arrows%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%#adding 4 inputfields for (x1;y1)---(x2;y2)%userinput inputfieldd%userdraw arrows,blue |
||
5098 | @%userinput_combined%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,3,3,5,grey%inputstyle color:blue;text-align:center%precision 1000%strokecolor red%opacity 255,255%userinput function%# note: number of function inputs not limited%userdraw line,blue |
||
8386 | schaersvoo | 5099 | */ |
5100 | temp = get_string_argument(infile,1); |
||
5101 | if(strstr(temp,"function") != 0 || strstr(temp,"curve") != 0 || strstr(temp,"plot") != 0 ){ |
||
5102 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
5103 | add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */ |
||
5104 | js_function[DRAW_JSFUNCTION] = 1; |
||
5105 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 5106 | 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 | 5107 | input_cnt++; |
5108 | } |
||
10953 | bpr | 5109 | else |
8386 | schaersvoo | 5110 | { |
14078 | bpr | 5111 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
8815 | schaersvoo | 5112 | 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 | 5113 | input_cnt++; |
5114 | } |
||
5115 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
5116 | add_to_js_math(js_include_file); |
||
5117 | use_js_math = TRUE; |
||
5118 | } |
||
5119 | if( use_js_plot == FALSE){ |
||
5120 | use_js_plot = TRUE; |
||
5121 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
5122 | } |
||
5123 | } |
||
5124 | else |
||
5125 | { |
||
5126 | if(strstr(temp,"inputfield") != 0 ){ |
||
5127 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
5128 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5129 | use_input_xy = 1; |
||
5130 | } |
||
5131 | else |
||
5132 | { |
||
5133 | if(strstr(temp,"textarea") != 0 ){ |
||
5134 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
5135 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5136 | use_input_xy = 2; |
||
5137 | } |
||
5138 | else |
||
5139 | { |
||
5140 | canvas_error("userinput argument may be \"function,inputfield,textarea\""); |
||
5141 | } |
||
5142 | } |
||
5143 | } |
||
5144 | break; |
||
5145 | case USERINPUT_XY: |
||
5146 | /* |
||
5147 | @ userinput_xy |
||
9372 | schaersvoo | 5148 | @ keyword (no arguments required) |
8386 | schaersvoo | 5149 | @ to be used in combination with command "userdraw object_type,color" |
14078 | bpr | 5150 | @ 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) |
8386 | schaersvoo | 5151 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
14071 | bpr | 5152 | @ 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. |
14086 | bpr | 5153 | @ can <b>not</b> be combined with command ''intooltip tiptext`` <br />note: the ''tooltip div element`` is used for placing inputfields |
8386 | schaersvoo | 5154 | @ user drawings will not zoom on zooming (or pan on panning) |
14071 | bpr | 5155 | @ use command inputstyle some_css`` to adjust the inputarea. |
5156 | @ use command ''fontsize int`` to adjust the text labels (if needed) |
||
13950 | schaersvoo | 5157 | @%userinput_xy%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 2,2,grey,3,3,6,black%# provides inputfields for (x1:y1)---(x2:y2)%userinput_xy%linewidth 2%precision 1000%userdraw lines,blue |
8386 | schaersvoo | 5158 | */ |
5159 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
5160 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
5161 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5162 | use_input_xy = 1; |
||
5163 | break; |
||
5164 | |||
5165 | case USERINPUT_FUNCTION: |
||
5166 | /* |
||
5167 | @ userinput_function |
||
9372 | schaersvoo | 5168 | @ keyword (no arguments required) |
14078 | bpr | 5169 | @ if set, a inputfield will be added to the page |
8386 | schaersvoo | 5170 | @ repeat keyword for more function input fields |
5171 | @ the userinput value will be plotted in the canvas |
||
14071 | bpr | 5172 | @ this value may be read with <code>read_canvas()</code>. <br />for do it yourself js-scripters: If this is the first inputfield in the script, its id is canvas_input0 |
14078 | bpr | 5173 | @ 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 |
14071 | bpr | 5174 | @ fontsize can be set using command ''fontsize int`` |
5175 | @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield |
||
13950 | schaersvoo | 5176 | @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,2,2,5,grey%precision 1000%linewidth 2%# first inputfield%inputstyle color:blue;text-align:center;font-family:Italic;%strokecolor blue%functionlabel g(x)=%userinput function%# second inputfield%inputstyle color:green;text-align:center;font-family:Italic;%strokecolor green%functionlabel h(x)=%userinput function%# third inputfield%inputstyle color:purple;text-align:center;font-family:Italic;%strokecolor purple%functionlabel k(x)=%userinput function%# no limit in number of function inputfields |
8386 | schaersvoo | 5177 | */ |
5178 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
5179 | js_function[DRAW_JSFUNCTION] = 1; |
||
5180 | add_rawmath(js_include_file); |
||
5181 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 5182 | 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 | 5183 | input_cnt++; |
5184 | } |
||
10953 | bpr | 5185 | else |
8386 | schaersvoo | 5186 | { |
14078 | bpr | 5187 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
8815 | schaersvoo | 5188 | 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 | 5189 | input_cnt++; |
5190 | } |
||
5191 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
5192 | add_to_js_math(js_include_file); |
||
5193 | use_js_math = TRUE; |
||
5194 | } |
||
5195 | if( use_js_plot == FALSE){ |
||
5196 | use_js_plot = TRUE; |
||
5197 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
5198 | } |
||
5199 | break; |
||
5200 | |||
5201 | |||
5202 | |||
11806 | schaersvoo | 5203 | case USERTEXTAREA_XY: |
7788 | schaersvoo | 5204 | /* |
11806 | schaersvoo | 5205 | @ usertextarea_xy |
13955 | schaersvoo | 5206 | @ NOT IMPLEMENTED !! |
11806 | schaersvoo | 5207 | @ keyword (no arguments required) |
14086 | bpr | 5208 | @ to be used in combination with command <code>userdraw object_type,color</code> wherein object_type is only segment / polyline for the time being... |
5209 | @ if set two textareas are added to the document (one for x-values, one for y-values) |
||
11806 | schaersvoo | 5210 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
5211 | @ user drawings will not zoom on zooming (or pan on panning) |
||
14071 | bpr | 5212 | @ use command ''inputstyle some_css`` to adjust the inputarea. |
5213 | @ use command ''fontsize int`` to adjust the text labels (if needed) |
||
7788 | schaersvoo | 5214 | */ |
11806 | schaersvoo | 5215 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
5216 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5217 | use_input_xy = 2; |
||
7788 | schaersvoo | 5218 | break; |
8386 | schaersvoo | 5219 | |
11806 | schaersvoo | 5220 | case VLINE: |
8386 | schaersvoo | 5221 | /* |
11806 | schaersvoo | 5222 | @ vline x,y,color |
14071 | bpr | 5223 | @ alternative: <code>verticalline</code> |
14380 | bpr | 5224 | @ draw a vertical line through point (x:y) in color ''color`` |
11806 | schaersvoo | 5225 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 5226 | @%vline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vline 0,0,red%onclick%vline 1,0,orange%onclick%vline 2,0,blue%onclick%vline 3,0,green |
8386 | schaersvoo | 5227 | */ |
11806 | schaersvoo | 5228 | for(i=0;i<3;i++) { |
7614 | schaersvoo | 5229 | switch(i){ |
11806 | schaersvoo | 5230 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
5231 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
5232 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
5233 | double_data[2] = double_data[0]; |
||
7614 | schaersvoo | 5234 | decimals = find_number_of_digits(precision); |
14208 | schaersvoo | 5235 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,100*ymin,decimals,100*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,current_sliders,rotation_center,use_offset,use_pattern); |
5236 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 5237 | /* click_cnt++; */ |
8379 | schaersvoo | 5238 | reset(); |
7614 | schaersvoo | 5239 | break; |
5240 | } |
||
5241 | } |
||
5242 | break; |
||
5243 | |||
11806 | schaersvoo | 5244 | case VLINES: |
11802 | schaersvoo | 5245 | /* |
11806 | schaersvoo | 5246 | @ vlines color,x1,y1,x2,y2.... |
14071 | bpr | 5247 | @ alternative: <code>verticallines</code> |
14380 | bpr | 5248 | @ draw vertical lines through points (x1:y1),(x2:y2)... in color ''color`` |
11806 | schaersvoo | 5249 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13939 | bpr | 5250 | @%vlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0 |
11802 | schaersvoo | 5251 | */ |
11806 | schaersvoo | 5252 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5253 | fill_color = stroke_color; |
||
5254 | i=0; |
||
5255 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5256 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5257 | if(i%2 == 0 ){ |
5258 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 5259 | } |
11806 | schaersvoo | 5260 | else |
5261 | { |
||
5262 | double_data[i] = get_real(infile,1); /* y */ |
||
7983 | schaersvoo | 5263 | } |
11806 | schaersvoo | 5264 | i++; |
7983 | schaersvoo | 5265 | } |
11806 | schaersvoo | 5266 | decimals = find_number_of_digits(precision); |
5267 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
14208 | schaersvoo | 5268 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
5269 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
||
11806 | schaersvoo | 5270 | /* click_cnt++; */ |
5271 | } |
||
5272 | reset(); |
||
7983 | schaersvoo | 5273 | break; |
11806 | schaersvoo | 5274 | |
5275 | case VIDEO: |
||
7614 | schaersvoo | 5276 | /* |
11806 | schaersvoo | 5277 | @ video x,y,w,h,videofile location |
14066 | bpr | 5278 | @ x,y: left top corner of audio element (in xrange / yrange) |
5279 | @ w,y: width and height in pixels |
||
5280 | @ video format may be in *.mp4 (todo: other formats) |
||
13950 | schaersvoo | 5281 | @%video%size 400,400%xrange -10,10%yrange -10,10%opacity 200,100%frect -9,9,6,-6,green%video -5,5,200,200,http://techslides.com/demos/sample-videos/small.mp4 |
7614 | schaersvoo | 5282 | */ |
11806 | schaersvoo | 5283 | if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;} |
7614 | schaersvoo | 5284 | for(i=0;i<5;i++){ |
5285 | switch(i){ |
||
11806 | schaersvoo | 5286 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
14162 | bpr | 5287 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
11806 | schaersvoo | 5288 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
5289 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
5290 | case 4: temp = get_string(infile,1); |
||
14208 | schaersvoo | 5291 | string_length = 1 + 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); |
5292 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5293 | 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); |
7614 | schaersvoo | 5294 | add_to_buffer(tmp_buffer); |
5295 | break; |
||
5296 | default:break; |
||
5297 | } |
||
5298 | } |
||
5299 | reset(); |
||
5300 | break; |
||
11806 | schaersvoo | 5301 | |
7614 | schaersvoo | 5302 | case X_AXIS_STRINGS: |
5303 | /* |
||
5304 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
14071 | bpr | 5305 | @ alternative: <code>xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
13936 | bpr | 5306 | @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof |
9346 | schaersvoo | 5307 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
14071 | bpr | 5308 | @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5309 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
14086 | bpr | 5310 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Ariel<br />note: 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 | 5311 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5312 | @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied |
11044 | schaersvoo | 5313 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14078 | bpr | 5314 | @ ''xmajor`` steps should be synchronised with numbers eg. ''1`` in the next example <code>grid 1,100,grey,1,4,6,grey</code> |
13937 | schaersvoo | 5315 | @%xaxistext%size 800,200%xrange -1,13%yrange -5,10%axis%xaxistext 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red |
7614 | schaersvoo | 5316 | */ |
11891 | schaersvoo | 5317 | use_axis_numbering++; |
7614 | schaersvoo | 5318 | temp = get_string(infile,1); |
5319 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5320 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5321 | fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering); |
7614 | schaersvoo | 5322 | break; |
9341 | schaersvoo | 5323 | case X_AXIS_STRINGS_UP: |
5324 | /* |
||
5325 | @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
14071 | bpr | 5326 | @ alternative: <code>xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
9341 | schaersvoo | 5327 | @ the text will be rotated 90° up |
11044 | schaersvoo | 5328 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5329 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
9346 | schaersvoo | 5330 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
14086 | bpr | 5331 | @ use command ''fontcolor``, <a href="#fontfamily">fontfamily</a> to adjust font <br />defaults: black,12,Ariel<br />note: 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 | 5332 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5333 | @ if the ''x-axis words`` are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards) |
11044 | schaersvoo | 5334 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14086 | bpr | 5335 | @''xmajor`` steps should be synchronised with numbers eg. "1" in the next example <code>grid 1,100,grey,1,4,6,grey</code> |
13937 | schaersvoo | 5336 | @%xaxistextup%size 800,300%xrange -1,13%yrange -10,10%fontfamily Italic 18pt Courier%axis%xaxistextup 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red |
9341 | schaersvoo | 5337 | */ |
11891 | schaersvoo | 5338 | use_axis_numbering++; |
9341 | schaersvoo | 5339 | temp = get_string(infile,1); |
5340 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5341 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5342 | fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp); |
9341 | schaersvoo | 5343 | break; |
8224 | bpr | 5344 | |
11806 | schaersvoo | 5345 | case XERRORBARS: |
7614 | schaersvoo | 5346 | /* |
11806 | schaersvoo | 5347 | @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
14380 | bpr | 5348 | @ 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``. |
11806 | schaersvoo | 5349 | @ the errors E1 and E2 values are in xrange. |
14071 | bpr | 5350 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5351 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5352 | @%xerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%xerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1 |
12006 | schaersvoo | 5353 | |
7614 | schaersvoo | 5354 | */ |
11806 | schaersvoo | 5355 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5356 | fill_color = stroke_color; |
||
5357 | i=0; |
||
5358 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5359 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5360 | if(i%2 == 0 ){ |
5361 | double_data[i] = get_real(infile,0); /* x */ |
||
8071 | schaersvoo | 5362 | } |
11806 | schaersvoo | 5363 | else |
5364 | { |
||
5365 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 5366 | } |
11806 | schaersvoo | 5367 | i++; |
7614 | schaersvoo | 5368 | } |
11806 | schaersvoo | 5369 | decimals = find_number_of_digits(precision); |
5370 | for(c = 2 ; c < i-1 ; c = c+2){ |
||
14208 | schaersvoo | 5371 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 5372 | /* click_cnt++; */ |
14208 | schaersvoo | 5373 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
11806 | schaersvoo | 5374 | } |
7614 | schaersvoo | 5375 | reset(); |
5376 | break; |
||
11806 | schaersvoo | 5377 | |
5378 | case XRANGE: |
||
7614 | schaersvoo | 5379 | /* |
11806 | schaersvoo | 5380 | @ xrange xmin,xmax |
14071 | bpr | 5381 | @ alternative: <code>rangex</code> |
11806 | schaersvoo | 5382 | @ if not given: 0,xsize (eg in pixels) |
7614 | schaersvoo | 5383 | */ |
11806 | schaersvoo | 5384 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5385 | switch(i){ |
11806 | schaersvoo | 5386 | case 0: xmin = get_real(infile,0);break; |
5387 | case 1: xmax = get_real(infile,1);break; |
||
7614 | schaersvoo | 5388 | default: break; |
5389 | } |
||
5390 | } |
||
14066 | bpr | 5391 | if(xmin >= xmax){canvas_error(" xrange is not OK: xmin < xmax !\n");} |
11806 | schaersvoo | 5392 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax); |
5393 | found_size_command++; |
||
7614 | schaersvoo | 5394 | break; |
8386 | schaersvoo | 5395 | |
5396 | |||
5397 | |||
11806 | schaersvoo | 5398 | case XSNAPTOGRID: |
7614 | schaersvoo | 5399 | /* |
11806 | schaersvoo | 5400 | @ xsnaptogrid |
5401 | @ keyword (no arguments required) |
||
14385 | bpr | 5402 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup). |
5403 | @ in case of userdraw the drawn points will snap to xmajor grid. |
||
14078 | bpr | 5404 | @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1) |
14071 | bpr | 5405 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
14385 | bpr | 5406 | @ 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, <code>xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><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 ... |
13939 | bpr | 5407 | @%xsnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%xsnaptogrid%userdraw segments,red%precision 1%display x,red,12 |
5408 | @%xsnaptogrid_2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%drag x%points red,0,0,0,0,0,0,0,0,0,0 |
||
12007 | schaersvoo | 5409 | |
7614 | schaersvoo | 5410 | */ |
14038 | schaersvoo | 5411 | use_snap = 2; |
11806 | schaersvoo | 5412 | break; |
8386 | schaersvoo | 5413 | |
11806 | schaersvoo | 5414 | case XOFFSET: |
7614 | schaersvoo | 5415 | /* |
12063 | schaersvoo | 5416 | @ xoffset |
13829 | bpr | 5417 | @ keyword ; to place the text centered above the text coordinates(x:y) ... |
5418 | @ may be used for points or other things requiring centered labels |
||
12063 | schaersvoo | 5419 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11811 | schaersvoo | 5420 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library) |
12107 | schaersvoo | 5421 | @%xoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
7614 | schaersvoo | 5422 | */ |
12063 | schaersvoo | 5423 | use_offset = 2; |
11806 | schaersvoo | 5424 | break; |
8386 | schaersvoo | 5425 | |
11806 | schaersvoo | 5426 | case XYOFFSET: |
7614 | schaersvoo | 5427 | /* |
11806 | schaersvoo | 5428 | @ xyoffset |
5429 | @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily |
||
13829 | bpr | 5430 | @ may be used for points or other things requiring labels |
12063 | schaersvoo | 5431 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11806 | schaersvoo | 5432 | @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy |
14071 | bpr | 5433 | @ in case of inputfields the inputfield will be centered x and y on its coordinates.<br />for example:<br />inputs 1,1,10,? <br />point 1,1,red <br /> the point will be completely invisible<br />note: keyword ''xyoffset`` will also provide centering if used with <a href='#@userdraw'>input(s),color</a> |
12107 | schaersvoo | 5434 | @%xyoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
7614 | schaersvoo | 5435 | */ |
12063 | schaersvoo | 5436 | use_offset = 3; |
11806 | schaersvoo | 5437 | break; |
8386 | schaersvoo | 5438 | |
7996 | schaersvoo | 5439 | case XUNIT: |
5440 | /* |
||
5441 | @ xunit some_unit_for_x-values |
||
5442 | @ unicode allowed (no html code) |
||
12007 | schaersvoo | 5443 | @ use together with command <a href='#display'>display or mouse</a> |
14071 | bpr | 5444 | @ will display the cursor x-coordinate in ''unit`` |
12107 | schaersvoo | 5445 | @%xunit%size 400,400%xrange -10,10%yrange -10,10%xunit cm \\u00B2%grid 2,2,grey%linewidth 2%userdraw segments,blue%display x,blue,18 |
7996 | schaersvoo | 5446 | */ |
5447 | fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1)); |
||
5448 | break; |
||
11806 | schaersvoo | 5449 | |
5450 | case XLABEL: |
||
7996 | schaersvoo | 5451 | /* |
11806 | schaersvoo | 5452 | @ xlabel some_string |
14385 | bpr | 5453 | @ will be used to create a label for the x-axis (label is in quadrant I). |
5454 | @ can only be used together with command ''grid``<br />not depending on keywords ''axis`` and ''axisnumbering``. |
||
5455 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust (command ''fontfamily`` is not active for this command). |
||
5456 | @ see <a href='z#ylabel'>ylabel</a>. |
||
12107 | schaersvoo | 5457 | @%xlabel%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel cm\u00B2 %ylabel v\u00B2 %precision 1%grid 2,2,grey,2,2,5,grey |
7996 | schaersvoo | 5458 | */ |
11806 | schaersvoo | 5459 | temp = get_string(infile,1); |
5460 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
||
7996 | schaersvoo | 5461 | break; |
8071 | schaersvoo | 5462 | |
11806 | schaersvoo | 5463 | case XLOGBASE: |
7991 | schaersvoo | 5464 | /* |
11806 | schaersvoo | 5465 | @ xlogbase number |
5466 | @ sets the logbase number for the x-axis |
||
5467 | @ default value 10 |
||
5468 | @ use together with commands xlogscale / xylogscale |
||
7991 | schaersvoo | 5469 | */ |
11806 | schaersvoo | 5470 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7991 | schaersvoo | 5471 | break; |
5472 | |||
11806 | schaersvoo | 5473 | case XLOGSCALE: |
7614 | schaersvoo | 5474 | /* |
11806 | schaersvoo | 5475 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
14071 | bpr | 5476 | @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code> |
11806 | schaersvoo | 5477 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
14071 | bpr | 5478 | @ the linewidth is set using command ''linewidth int`` |
14066 | bpr | 5479 | @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a> |
14379 | bpr | 5480 | @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` |
14071 | bpr | 5481 | @ 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> |
5482 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5483 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5484 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5485 | @ note: 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 |
||
14078 | bpr | 5486 | @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy ! |
14071 | bpr | 5487 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
12107 | schaersvoo | 5488 | @%xlogscale%size 400,400%xrange 10,50000%yrange -5,5%xlabel x-axis%ylabel y-axis%xlogscale 10,1,black,grey%display x,red,22 |
7614 | schaersvoo | 5489 | */ |
11972 | schaersvoo | 5490 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5491 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
5492 | if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;} |
||
5493 | for(i=0;i<4;i++){ |
||
7614 | schaersvoo | 5494 | switch(i){ |
11806 | schaersvoo | 5495 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
5496 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5497 | case 2: stroke_color = get_color(infile,0); break; |
||
5498 | case 3: fill_color = get_color(infile,1); |
||
14208 | schaersvoo | 5499 | string_length = 1 + 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); |
5500 | tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5501 | 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); |
5502 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
||
5503 | add_to_buffer(tmp_buffer); |
||
5504 | break; |
||
7614 | schaersvoo | 5505 | default:break; |
5506 | } |
||
5507 | } |
||
5508 | break; |
||
11806 | schaersvoo | 5509 | |
5510 | case XYLOGSCALE: |
||
7614 | schaersvoo | 5511 | /* |
11806 | schaersvoo | 5512 | @ xylogscale majorcolor,minorcolor |
14071 | bpr | 5513 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
5514 | @ the linewidth is set using command ''linewidth int`` |
||
5515 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5516 | @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number`` |
14071 | bpr | 5517 | @ 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> |
5518 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5519 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5520 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5521 | @ note: 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``) |
||
14078 | bpr | 5522 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
14071 | bpr | 5523 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
13829 | bpr | 5524 | @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xylogscale black,grey%display xy,red,22 |
7614 | schaersvoo | 5525 | */ |
11972 | schaersvoo | 5526 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5527 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
5528 | if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;} |
||
5529 | for(i=0;i<2;i++){ |
||
7614 | schaersvoo | 5530 | switch(i){ |
11806 | schaersvoo | 5531 | case 0: stroke_color = get_color(infile,0); break; |
5532 | case 1: fill_color = get_color(infile,1); |
||
14208 | schaersvoo | 5533 | string_length = 1 + 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); |
5534 | tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5535 | 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); |
5536 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
||
5537 | add_to_buffer(tmp_buffer); |
||
5538 | break; |
||
7614 | schaersvoo | 5539 | default:break; |
5540 | } |
||
5541 | } |
||
5542 | break; |
||
11806 | schaersvoo | 5543 | |
5544 | |||
5545 | case Y_AXIS_STRINGS: |
||
7647 | schaersvoo | 5546 | /* |
11806 | schaersvoo | 5547 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
14071 | bpr | 5548 | @ alternative: <code>yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
14086 | bpr | 5549 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Ariel<br /> note: 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>) |
11806 | schaersvoo | 5550 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5551 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
14071 | bpr | 5552 | @ use these y-axis num1...num_n values instead of default ymin...ymax |
11806 | schaersvoo | 5553 | @ a javascript error message will flag non-matching value:name pairs |
5554 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
12107 | schaersvoo | 5555 | @%yaxistext%size 400,400%yrange 0,13%xrange -100,500%axis%yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%#'ymajor' steps should be synchronised with numbers eg. "1" in this example%grid 100,1,grey,4,1,6,grey |
7647 | schaersvoo | 5556 | */ |
11806 | schaersvoo | 5557 | temp = get_string(infile,1); |
5558 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5559 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
5560 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
11891 | schaersvoo | 5561 | use_axis_numbering++; |
11806 | schaersvoo | 5562 | break; |
5563 | |||
5564 | |||
5565 | case YERRORBARS: |
||
7614 | schaersvoo | 5566 | /* |
11806 | schaersvoo | 5567 | @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
14380 | bpr | 5568 | @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color ''color``. |
11806 | schaersvoo | 5569 | @ the errors E1 and E2 values are in yrange. |
14071 | bpr | 5570 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5571 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5572 | @%yerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%yerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1 |
7614 | schaersvoo | 5573 | */ |
11806 | schaersvoo | 5574 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5575 | fill_color = stroke_color; |
||
11772 | schaersvoo | 5576 | i=0; |
5577 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5578 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11772 | schaersvoo | 5579 | if(i%2 == 0 ){ |
5580 | double_data[i] = get_real(infile,0); /* x */ |
||
5581 | } |
||
5582 | else |
||
5583 | { |
||
5584 | double_data[i] = get_real(infile,1); /* y */ |
||
5585 | } |
||
5586 | i++; |
||
5587 | } |
||
11806 | schaersvoo | 5588 | for(c = 2 ; c < i-1 ; c = c+2){ |
14208 | schaersvoo | 5589 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 5590 | /* click_cnt++; */ |
14208 | schaersvoo | 5591 | if(onclick > 0 || slider_cnt > 0){click_cnt++;} |
8083 | schaersvoo | 5592 | } |
11806 | schaersvoo | 5593 | decimals = find_number_of_digits(precision); |
8083 | schaersvoo | 5594 | reset(); |
11806 | schaersvoo | 5595 | break; |
11811 | schaersvoo | 5596 | case YOFFSET: |
5597 | /* |
||
5598 | @ yoffset |
||
14162 | bpr | 5599 | @ keyword; to place the text centered above the text coordinates(x:y) ... |
13829 | bpr | 5600 | @ may be used for points or other things requiring centered labels |
12063 | schaersvoo | 5601 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
5602 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library) |
||
12107 | schaersvoo | 5603 | @%yoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
11811 | schaersvoo | 5604 | */ |
12063 | schaersvoo | 5605 | use_offset = 1; |
11811 | schaersvoo | 5606 | break; |
5607 | |||
11806 | schaersvoo | 5608 | case YRANGE: |
7614 | schaersvoo | 5609 | /* |
11806 | schaersvoo | 5610 | @ yrange ymin,ymax |
14071 | bpr | 5611 | @ alternative: <code>rangey</code> |
11806 | schaersvoo | 5612 | @ if not given 0,ysize (eg in pixels) |
7614 | schaersvoo | 5613 | */ |
11806 | schaersvoo | 5614 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5615 | switch(i){ |
11806 | schaersvoo | 5616 | case 0: ymin = get_real(infile,0);break; |
5617 | case 1: ymax = get_real(infile,1);break; |
||
5618 | default: break; |
||
7614 | schaersvoo | 5619 | } |
5620 | } |
||
14066 | bpr | 5621 | if(ymin >= ymax){canvas_error(" yrange is not OK: ymin < ymax !\n");} |
11806 | schaersvoo | 5622 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax); |
5623 | found_size_command++; |
||
5624 | break; |
||
5625 | |||
5626 | case YSNAPTOGRID: |
||
7614 | schaersvoo | 5627 | /* |
11806 | schaersvoo | 5628 | @ ysnaptogrid |
5629 | @ keyword (no arguments required) |
||
14162 | bpr | 5630 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup) |
11806 | schaersvoo | 5631 | @ in case of userdraw the drawn points will snap to ymajor grid |
14078 | bpr | 5632 | @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1) |
14071 | bpr | 5633 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
5634 | @ 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 /><code>ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><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 /> |
||
13959 | bpr | 5635 | @%ysnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%inputstyle font-size:8px;color:blue%clearbutton delete all crosshairs |
5636 | @%ysnaptogrid_2%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 3%drag y%points red,0,0,0,0,0,0,0,0,0,0 |
||
7614 | schaersvoo | 5637 | */ |
14038 | schaersvoo | 5638 | use_snap = 3; |
7614 | schaersvoo | 5639 | break; |
11080 | schaersvoo | 5640 | |
7614 | schaersvoo | 5641 | case YLABEL: |
5642 | /* |
||
5643 | @ ylabel some_string |
||
8224 | bpr | 5644 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
14071 | bpr | 5645 | @ can only be used together with command <a href="#grid">grid</a><br />not depending on keywords ''axis`` and ''axisnumbering`` |
14086 | bpr | 5646 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust (command ''fontsize`` is not active for this command) |
12107 | schaersvoo | 5647 | @%ylabel%size 400,400%xrange -10,10%yrange -10,10%fontsize 8%axis%axisnumbering%precision 1%xlabel x-axis%ylabel y-axis%grid 1,1,grey,2,2,2,red |
7614 | schaersvoo | 5648 | */ |
5649 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 5650 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 5651 | break; |
7735 | schaersvoo | 5652 | case YLOGBASE: |
5653 | /* |
||
5654 | @ ylogbase number |
||
5655 | @ sets the logbase number for the y-axis |
||
5656 | @ default value 10 |
||
5657 | @ use together with commands ylogscale / xylogscale |
||
5658 | */ |
||
5659 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
5660 | break; |
||
7614 | schaersvoo | 5661 | case YLOGSCALE: |
7729 | schaersvoo | 5662 | /* |
5663 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
14071 | bpr | 5664 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
7729 | schaersvoo | 5665 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
14071 | bpr | 5666 | @ the linewidth is set using command ''linewidth int`` |
5667 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5668 | @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number`` |
14071 | bpr | 5669 | @ 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 color</li></ul> |
5670 | @ note: the complete canvas will be used for the ''log paper`` |
||
11088 | schaersvoo | 5671 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5672 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5673 | @ note: 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``) |
||
14078 | bpr | 5674 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
14071 | bpr | 5675 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
7729 | schaersvoo | 5676 | */ |
11972 | schaersvoo | 5677 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
7729 | schaersvoo | 5678 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
5679 | if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;} |
||
5680 | for(i=0;i<4;i++){ |
||
5681 | switch(i){ |
||
5682 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
5683 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5684 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 5685 | case 3: fill_color = get_color(infile,1); |
14208 | schaersvoo | 5686 | string_length = 1 + 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); |
5687 | tmp_buffer = my_newmem(string_length); |
||
7779 | schaersvoo | 5688 | 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 | 5689 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 5690 | add_to_buffer(tmp_buffer); |
5691 | break; |
||
5692 | default:break; |
||
5693 | } |
||
5694 | } |
||
7614 | schaersvoo | 5695 | break; |
11806 | schaersvoo | 5696 | |
5697 | case YUNIT: |
||
7735 | schaersvoo | 5698 | /* |
11806 | schaersvoo | 5699 | @ yunit some_unit_for_y-values |
5700 | @ unicode allowed (no html code) |
||
5701 | @ use together with command mousey |
||
14071 | bpr | 5702 | @ will display the cursor y-coordinate in ''unit`` |
7735 | schaersvoo | 5703 | */ |
11806 | schaersvoo | 5704 | fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1)); |
5705 | break; |
||
5706 | |||
5707 | case ZOOM: |
||
5708 | /* |
||
5709 | @ zoom button_color |
||
14071 | bpr | 5710 | @ introduce a very small ''controlpanel`` at the lower right corner |
5711 | @ 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 |
||
5712 | @ the ''x`` symbol will do a <code>location.reload</code> of the page, and thus reset all canvas drawings. |
||
14247 | bpr | 5713 | @ choose an appropriate color, so the small ''x,arrows,-,+`` are clearly visible |
14071 | bpr | 5714 | @ command ''opacity`` may be used to set stroke_opacity of buttons |
5715 | @ note: use command ''zoom`` at the end of your script code (the same is true for command ''mouse``) |
||
11806 | schaersvoo | 5716 | @ note: only objects that may be set draggable / clickable will be zoomed / panned |
14071 | bpr | 5717 | @ note: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position: e.g. dragging / panning will get lost. (array with ''drag data`` is erased). This is a design flaw and not a feature !! |
11806 | schaersvoo | 5718 | */ |
5719 | fprintf(js_include_file,"use_pan_and_zoom = 1;"); |
||
5720 | use_pan_and_zoom = TRUE; |
||
5721 | stroke_color = get_color(infile,1); |
||
5722 | /* we use BG_CANVAS (0) */ |
||
5723 | add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity); |
||
5724 | done = TRUE; |
||
5725 | break; |
||
5726 | |||
5727 | /* ready */ |
||
7614 | schaersvoo | 5728 | default:sync_input(infile); |
5729 | break; |
||
5730 | } |
||
8224 | bpr | 5731 | } |
7614 | schaersvoo | 5732 | /* we are done parsing script file */ |
14066 | bpr | 5733 | /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */ |
7983 | schaersvoo | 5734 | if( found_size_command == 1 ){ |
5735 | fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize); |
||
5736 | } |
||
5737 | else |
||
5738 | { |
||
5739 | if( found_size_command != 3 ){ |
||
8222 | schaersvoo | 5740 | canvas_error("Please specify both xrange and yrange ..."); |
7983 | schaersvoo | 5741 | } |
5742 | } |
||
8257 | schaersvoo | 5743 | |
14066 | bpr | 5744 | /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects ! */ |
11021 | schaersvoo | 5745 | add_javascript_function(js_function,canvas_root_id); |
7614 | schaersvoo | 5746 | /* add read_canvas() etc functions if needed */ |
8257 | schaersvoo | 5747 | if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);} |
7797 | schaersvoo | 5748 | if( use_pan_and_zoom == TRUE ){ |
5749 | /* in case of zooming ... */ |
||
13970 | obado | 5750 | fprintf(js_include_file,"\n/* some extra global stuff : need to rethink panning and zooming !!! */\n\ |
7797 | schaersvoo | 5751 | precision = %d;var xmin_start=xmin;var xmax_start=xmax;\ |
7729 | schaersvoo | 5752 | var ymin_start=ymin;var ymax_start=xmax;\ |
5753 | var zoom_x_increment=0;var zoom_y_increment=0;\ |
||
5754 | var pan_x_increment=0;var pan_y_increment=0;\ |
||
5755 | if(use_ylogscale == 0 ){\ |
||
7956 | schaersvoo | 5756 | 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 | 5757 | }else{\ |
5758 | zoom_x_increment = (xmax - xmin)/20;\ |
||
5759 | pan_x_increment = (xmax - xmin)/20;\ |
||
5760 | };\ |
||
9406 | schaersvoo | 5761 | var zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 5762 | function start_canvas%d(type){\ |
9406 | schaersvoo | 5763 | zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 5764 | switch(type){\ |
7729 | schaersvoo | 5765 | case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\ |
5766 | 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 | 5767 | case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\ |
5768 | case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\ |
||
5769 | case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\ |
||
5770 | case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\ |
||
11004 | schaersvoo | 5771 | case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\ |
7653 | schaersvoo | 5772 | default:break;\ |
5773 | };\ |
||
5774 | if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\ |
||
5775 | if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\ |
||
9406 | schaersvoo | 5776 | try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\ |
11088 | schaersvoo | 5777 | if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\ |
9406 | schaersvoo | 5778 | %s ;\ |
7653 | schaersvoo | 5779 | };\ |
7797 | schaersvoo | 5780 | start_canvas%d(333);\ |
9438 | schaersvoo | 5781 | };\ |
13970 | obado | 5782 | \n/* end wims_canvas_function */\n\ |
9406 | schaersvoo | 5783 | wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id); |
7797 | schaersvoo | 5784 | } |
5785 | else |
||
5786 | { |
||
5787 | /* no zoom, just add buffer */ |
||
13970 | obado | 5788 | fprintf(js_include_file,"\n/* add buffer */\n\ |
7797 | schaersvoo | 5789 | %s\ |
5790 | };\n\ |
||
13970 | obado | 5791 | /* end wims_canvas_function */\n\ |
7797 | schaersvoo | 5792 | wims_canvas_function%d();\n",buffer,canvas_root_id); |
5793 | } |
||
7614 | schaersvoo | 5794 | /* done writing the javascript include file */ |
5795 | fclose(js_include_file); |
||
5796 | |||
5797 | } |
||
5798 | |||
5799 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
9329 | schaersvoo | 5800 | if( use_tooltip > 0 ){ |
5801 | if( use_tooltip == 1 ){ |
||
5802 | add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize); |
||
5803 | } |
||
5804 | else |
||
5805 | { |
||
5806 | if( use_tooltip == 2 ){ |
||
5807 | add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd); |
||
5808 | } |
||
5809 | } |
||
5810 | } |
||
7614 | schaersvoo | 5811 | exit(EXIT_SUCCESS); |
5812 | } |
||
5813 | /* end main() */ |
||
5814 | |||
5815 | /****************************************************************************** |
||
5816 | ** |
||
5817 | ** sync_input |
||
5818 | ** |
||
5819 | ** synchronises input line - reads to end of line, leaving file pointer |
||
5820 | ** at first character of next line. |
||
5821 | ** |
||
5822 | ** Used by: |
||
5823 | ** main program - error handling. |
||
5824 | ** |
||
5825 | ******************************************************************************/ |
||
5826 | void sync_input(FILE *infile) |
||
5827 | { |
||
5828 | int c = 0; |
||
5829 | |||
7658 | schaersvoo | 5830 | if( c == '\n' || c == ';' ) return; |
5831 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 5832 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 5833 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 5834 | return; |
5835 | } |
||
5836 | |||
5837 | /******************************************************************************/ |
||
5838 | |||
5839 | char *str_replace(const char *str, const char *old, const char *new){ |
||
5840 | /* http://creativeandcritical.net/str-replace-c/ */ |
||
5841 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
5842 | char *ret, *r; |
||
5843 | const char *p, *q; |
||
5844 | size_t oldlen = strlen(old); |
||
5845 | size_t count = 0; |
||
5846 | size_t retlen = 0; |
||
5847 | size_t newlen = strlen(new); |
||
5848 | if (oldlen != newlen){ |
||
5849 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
5850 | count++; |
||
5851 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
5852 | } |
||
8224 | bpr | 5853 | } |
7614 | schaersvoo | 5854 | else |
5855 | { |
||
5856 | retlen = strlen(str); |
||
5857 | } |
||
8224 | bpr | 5858 | |
7614 | schaersvoo | 5859 | if ((ret = malloc(retlen + 1)) == NULL){ |
5860 | ret = NULL; |
||
5861 | canvas_error("string argument is NULL"); |
||
5862 | } |
||
5863 | else |
||
5864 | { |
||
5865 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
5866 | size_t l = q - p; |
||
5867 | memcpy(r, p, l); |
||
5868 | r += l; |
||
5869 | memcpy(r, new, newlen); |
||
5870 | r += newlen; |
||
5871 | } |
||
5872 | strcpy(r, p); |
||
5873 | } |
||
5874 | return ret; |
||
5875 | } |
||
5876 | |||
5877 | /******************************************************************************/ |
||
7848 | bpr | 5878 | |
7614 | schaersvoo | 5879 | char *get_color(FILE *infile , int last){ |
5880 | int c,i = 0,is_hex = 0; |
||
5881 | char temp[MAX_COLOR_STRING], *string; |
||
8305 | schaersvoo | 5882 | const char *not_allowed = "0123456789"; |
10891 | schaersvoo | 5883 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) && ( c != '\t' ) ){ |
7614 | schaersvoo | 5884 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
5885 | if( c == '#' ){ |
||
5886 | is_hex = 1; |
||
5887 | } |
||
5888 | if( c != ' '){ |
||
8304 | schaersvoo | 5889 | 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 | 5890 | temp[i]=tolower(c); |
5891 | i++; |
||
5892 | } |
||
5893 | } |
||
10891 | schaersvoo | 5894 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
5895 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 5896 | if( c == EOF ){finished = 1;} |
5897 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
5898 | temp[i]='\0'; |
||
5899 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
5900 | if( is_hex == 1 ){ |
||
5901 | char red[3], green[3], blue[3]; |
||
5902 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
5903 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
5904 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
5905 | int r = (int) strtol(red, NULL, 16); |
||
5906 | int g = (int) strtol(green, NULL, 16); |
||
5907 | int b = (int) strtol(blue, NULL, 16); |
||
14408 | schaersvoo | 5908 | int L0 = 1+snprintf(NULL,0,"%d,%d,%d",r,g,b); |
5909 | string = my_newmem(L0); |
||
5910 | snprintf(string,L0,"%d,%d,%d",r,g,b); |
||
7614 | schaersvoo | 5911 | return string; |
5912 | } |
||
5913 | else |
||
5914 | { |
||
5915 | string = (char *)my_newmem(sizeof(temp)); |
||
5916 | snprintf(string,sizeof(temp),"%s",temp); |
||
8304 | schaersvoo | 5917 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
7614 | schaersvoo | 5918 | if( strcmp( colors[i].name , string ) == 0 ){ |
5919 | return colors[i].rgb; |
||
5920 | } |
||
5921 | } |
||
8304 | schaersvoo | 5922 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
7614 | schaersvoo | 5923 | } |
8304 | schaersvoo | 5924 | return "0,0,255"; |
7614 | schaersvoo | 5925 | } |
5926 | |||
14066 | bpr | 5927 | char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 5928 | int c,i=0; |
5929 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 5930 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){ |
7614 | schaersvoo | 5931 | temp[i]=c; |
5932 | i++; |
||
5933 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
5934 | } |
||
10891 | schaersvoo | 5935 | if( ( c == '\n' || c == '\t' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
5936 | if( c == '\n' || c == '\t') { done = TRUE; line_number++; } |
||
11022 | schaersvoo | 5937 | if( c == EOF ) {finished = 1;} |
7614 | schaersvoo | 5938 | temp[i]='\0'; |
11022 | schaersvoo | 5939 | if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");} |
7614 | schaersvoo | 5940 | string=(char *)my_newmem(strlen(temp)); |
5941 | snprintf(string,sizeof(temp),"%s",temp); |
||
5942 | return string; |
||
5943 | } |
||
5944 | |||
14066 | bpr | 5945 | char *get_string_argument(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 5946 | int c,i=0; |
5947 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 5948 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){ |
7614 | schaersvoo | 5949 | temp[i]=c; |
5950 | i++; |
||
5951 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
5952 | } |
||
8224 | bpr | 5953 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
10891 | schaersvoo | 5954 | if( c == '\n' || c == '\t' ) { line_number++; } |
7614 | schaersvoo | 5955 | if( c == EOF ) {finished = 1;} |
9478 | schaersvoo | 5956 | if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");} |
7614 | schaersvoo | 5957 | temp[i]='\0'; |
10953 | bpr | 5958 | /* |
8322 | schaersvoo | 5959 | 17.10.2014 removed (question Perrin) |
5960 | may cause some unwanted effects... |
||
14078 | bpr | 5961 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");} |
8322 | schaersvoo | 5962 | */ |
7614 | schaersvoo | 5963 | string=(char *)my_newmem(sizeof(temp)); |
5964 | snprintf(string,sizeof(temp),"%s",temp); |
||
5965 | done = TRUE; |
||
5966 | return string; |
||
5967 | } |
||
5968 | |||
14066 | bpr | 5969 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 5970 | int c,i=0,found_calc = 0; |
5971 | double y; |
||
5972 | char tmp[MAX_INT]; |
||
10953 | bpr | 5973 | /* |
14066 | bpr | 5974 | these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs |
8383 | schaersvoo | 5975 | but there should be a better way to avoid segfaults ! |
8348 | schaersvoo | 5976 | */ |
5977 | const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/ |
||
5978 | const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */ |
||
10891 | schaersvoo | 5979 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){ |
7614 | schaersvoo | 5980 | if( c != ' ' ){ |
8224 | bpr | 5981 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 5982 | continue; |
8224 | bpr | 5983 | } |
7614 | schaersvoo | 5984 | else |
5985 | { |
||
8304 | schaersvoo | 5986 | c = tolower(c); |
5987 | if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");} |
||
5988 | if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */ |
||
7614 | schaersvoo | 5989 | tmp[i] = c; |
5990 | i++; |
||
5991 | } |
||
5992 | } |
||
5993 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
5994 | } |
||
10891 | schaersvoo | 5995 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
5996 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 5997 | if( c == EOF ){done = TRUE ; finished = 1;} |
5998 | tmp[i]='\0'; |
||
5999 | if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");} |
||
8304 | schaersvoo | 6000 | if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */ |
7848 | bpr | 6001 | void *f = eval_create(tmp); |
7614 | schaersvoo | 6002 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 6003 | y = eval_x(f, 1); |
14066 | bpr | 6004 | /* if function is bogus; y = 1: so no core dumps */ |
7848 | bpr | 6005 | eval_destroy(f); |
7614 | schaersvoo | 6006 | } |
6007 | else |
||
6008 | { |
||
6009 | y = atof(tmp); |
||
6010 | } |
||
6011 | return y; |
||
6012 | } |
||
8304 | schaersvoo | 6013 | |
13829 | bpr | 6014 | |
7614 | schaersvoo | 6015 | void canvas_error(char *msg){ |
14066 | bpr | 6016 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d: %s</span><hr />",line_number,msg); |
7614 | schaersvoo | 6017 | finished = 1; |
6018 | exit(EXIT_SUCCESS); |
||
6019 | } |
||
6020 | |||
6021 | |||
6022 | /* convert x/y coordinates to pixel */ |
||
6023 | int x2px(double x){ |
||
6024 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
6025 | } |
||
6026 | |||
6027 | int y2px(double y){ |
||
6028 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
6029 | } |
||
6030 | |||
6031 | double px2x(int x){ |
||
6032 | return (x*(xmax - xmin)/xsize + xmin); |
||
6033 | } |
||
6034 | double px2y(int y){ |
||
6035 | return (y*(ymax - ymin)/ysize + ymin); |
||
6036 | } |
||
6037 | |||
6038 | void add_to_buffer(char *tmp){ |
||
6039 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
||
6040 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
6041 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
6042 | if( space_left > strlen(tmp)){ |
||
6043 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
6044 | } |
||
6045 | else |
||
6046 | { |
||
6047 | canvas_error("buffer is too big\n"); |
||
6048 | } |
||
6049 | tmp = NULL;free(tmp); |
||
6050 | return; |
||
6051 | } |
||
6052 | |||
6053 | void reset(){ |
||
14038 | schaersvoo | 6054 | use_filled = FALSE; |
6055 | use_dashed = FALSE; |
||
6056 | use_rotate = FALSE; |
||
8379 | schaersvoo | 6057 | onclick = 0; |
7614 | schaersvoo | 6058 | } |
6059 | |||
6060 | |||
6061 | |||
6062 | /* What reply format in read_canvas(); |
||
6063 | |||
14247 | bpr | 6064 | note: if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and inputfield.value() |
7614 | schaersvoo | 6065 | 1 = x1,x2,x3,x4....x_n |
6066 | y1,y2,y3,y4....y_n |
||
6067 | |||
6068 | x/y in pixels |
||
6069 | |||
6070 | 2 = x1,x2,x3,x4....x_n |
||
6071 | y1,y2,y3,y4....y_n |
||
14162 | bpr | 6072 | x/y in xrange / yrange coordinate system |
7614 | schaersvoo | 6073 | |
6074 | 3 = x1,x2,x3,x4....x_n |
||
6075 | y1,y2,y3,y4....y_n |
||
6076 | r1,r2,r3,r4....r_n |
||
6077 | |||
8224 | bpr | 6078 | x/y in pixels |
7614 | schaersvoo | 6079 | r in pixels |
6080 | |||
6081 | 4 = x1,x2,x3,x4....x_n |
||
6082 | y1,y2,y3,y4....y_n |
||
6083 | r1,r2,r3,r4....r_n |
||
6084 | |||
14162 | bpr | 6085 | x/y in xrange / yrange coordinate system |
7614 | schaersvoo | 6086 | r in pixels |
6087 | |||
6088 | 5 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
6089 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
6090 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
6091 | By1,By2,By3,By4....By_n |
||
6092 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
6093 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
6094 | .... |
||
6095 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
6096 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
8224 | bpr | 6097 | |
7614 | schaersvoo | 6098 | x/y in pixels |
6099 | |||
6100 | 6 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
6101 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
6102 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
6103 | By1,By2,By3,By4....By_n |
||
6104 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
6105 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
6106 | .... |
||
6107 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
6108 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
6109 | |||
14162 | bpr | 6110 | x/y in xrange / yrange coordinate system |
8224 | bpr | 6111 | |
7614 | schaersvoo | 6112 | 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
8224 | bpr | 6113 | |
7614 | schaersvoo | 6114 | x/y in pixels |
6115 | |||
6116 | 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
8224 | bpr | 6117 | |
14162 | bpr | 6118 | x/y in xrange / yrange coordinate system |
7614 | schaersvoo | 6119 | |
8224 | bpr | 6120 | 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 6121 | |
6122 | x/y in pixels |
||
6123 | |||
14044 | schaersvoo | 6124 | 10 = x1 ; y1 ;r1 \n x2;y2;r2 \n x3;y3;r3 \n ...x_n:y_n:r_n \n |
7614 | schaersvoo | 6125 | |
14162 | bpr | 6126 | x/y in xrange / yrange coordinate system |
14044 | schaersvoo | 6127 | r is userdraw_radius |
7614 | schaersvoo | 6128 | |
6129 | 11 = Ax1,Ay1,Ax2,Ay2 |
||
6130 | Bx1,By1,Bx2,By2 |
||
6131 | Cx1,Cy1,Cx2,Cy2 |
||
6132 | Dx1,Dy1,Dx2,Dy2 |
||
6133 | ...... |
||
6134 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 6135 | |
7614 | schaersvoo | 6136 | x/y in xrange / yrange coordinate system |
6137 | |||
6138 | 12 = Ax1,Ay1,Ax2,Ay2 |
||
6139 | Bx1,By1,Bx2,By2 |
||
6140 | Cx1,Cy1,Cx2,Cy2 |
||
6141 | Dx1,Dy1,Dx2,Dy2 |
||
6142 | ...... |
||
6143 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 6144 | |
7614 | schaersvoo | 6145 | x/y in pixels |
6146 | |||
14078 | bpr | 6147 | 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ..., Zx1:Zy1:Zx2:Zy2 |
7614 | schaersvoo | 6148 | |
14162 | bpr | 6149 | x/y in xrange / yrange coordinate system |
7614 | schaersvoo | 6150 | 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2 |
6151 | x/y in pixels |
||
6152 | 15 = reply from inputfields,textareas |
||
6153 | reply1,reply2,reply3,...,reply_n |
||
14071 | bpr | 6154 | only fields set write (e.g. will not read readonly inputfield values. |
7614 | schaersvoo | 6155 | |
6156 | 16 = read mathml inputfields only |
||
6157 | |||
11080 | schaersvoo | 6158 | 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n |
14066 | bpr | 6159 | when ready: calculate size_t of string via snprintf(NULL,0,"blah blah..."); |
7614 | schaersvoo | 6160 | |
14066 | bpr | 6161 | 18 = read clock(s): H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n |
7614 | schaersvoo | 6162 | 19 = return clicked object number (analogue to shape-library onclick) |
14071 | bpr | 6163 | 20 = return x/y-data in x-range/y-range of all ''draggable`` images |
7614 | schaersvoo | 6164 | 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n) |
14066 | bpr | 6165 | 22 = array: x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n |
14162 | bpr | 6166 | x/y in xrange / yrange coordinate system |
14071 | bpr | 6167 | 23 = answertype for a polyline: remove multiple occurences due to reclick on a point to create next polyline segment |
6168 | 24 = read all inputfield values: even those set <code>readonly</code> |
||
8224 | bpr | 6169 | 25 = return all userdrawn arcs in degrees: |
6170 | 26 = return all userdrawn arcs in radians: |
||
11080 | schaersvoo | 6171 | 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2... |
8322 | schaersvoo | 6172 | 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n |
14162 | bpr | 6173 | x/y/r in xrange / yrange coordinate system: may be used to reinput into command |
6174 | circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n |
||
14078 | bpr | 6175 | will not return anything else (e.g. no inputfields, text etc) |
14066 | bpr | 6176 | 29 = mulidraw read: |
10953 | bpr | 6177 | |
7614 | schaersvoo | 6178 | */ |
6179 | |||
14066 | bpr | 6180 | /* |
6181 | SCHAERSVOORDE: replyformat 2,7,8,21,22,23,24 |
||
14044 | schaersvoo | 6182 | USERDRAW DEFAULTS: 2,6,8,10,11,15,16,17,18,19,20,23,24,25,27,29,31 |
14066 | bpr | 6183 | OEF: 22,23,28 |
14044 | schaersvoo | 6184 | */ |
8257 | schaersvoo | 6185 | void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){ |
14038 | schaersvoo | 6186 | /* just 1 reply type allowed...except for format 34 !!! */ |
8074 | schaersvoo | 6187 | fprintf(js_include_file,"\ |
13970 | obado | 6188 | \n/* begin set_reply_precision() */\n\ |
8074 | schaersvoo | 6189 | function set_reply_precision(){\ |
6190 | var len = userdraw_x.length;\ |
||
6191 | var prec = %d;\ |
||
6192 | for(var p = 0 ; p < len ; p++ ){\ |
||
6193 | userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\ |
||
6194 | userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\ |
||
6195 | };\ |
||
6196 | len = userdraw_radius.length;\ |
||
6197 | if( len > 0 ){\ |
||
6198 | for(var p = 0 ; p < len ; p++ ){\ |
||
6199 | userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\ |
||
6200 | };\ |
||
6201 | };\ |
||
6202 | };",reply_precision); |
||
7963 | schaersvoo | 6203 | |
7614 | schaersvoo | 6204 | switch(type_reply){ |
8224 | bpr | 6205 | /* |
7614 | schaersvoo | 6206 | answers may have: |
6207 | x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers |
||
6208 | */ |
||
6209 | case 1: fprintf(js_include_file,"\ |
||
13970 | obado | 6210 | \n/* begin function 1 read_canvas%d() */\n\ |
8257 | schaersvoo | 6211 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6212 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 6213 | set_reply_precision();\ |
7614 | schaersvoo | 6214 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6215 | var p = 0;var input_reply = new Array();\ |
||
6216 | if( document.getElementById(\"canvas_input0\")){\ |
||
6217 | var t = 0;\ |
||
6218 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6219 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6220 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6221 | p++;\ |
||
6222 | };\ |
||
6223 | t++;\ |
||
6224 | };\ |
||
6225 | };\ |
||
11088 | schaersvoo | 6226 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6227 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\ |
6228 | }\ |
||
6229 | else\ |
||
6230 | {\ |
||
6231 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\ |
||
6232 | }\ |
||
6233 | }\ |
||
6234 | else\ |
||
6235 | {\ |
||
11088 | schaersvoo | 6236 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6237 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\ |
6238 | }\ |
||
6239 | else\ |
||
6240 | {\ |
||
6241 | return userdraw_x+\"\\n\"+userdraw_y;\ |
||
6242 | }\ |
||
6243 | };\ |
||
8108 | schaersvoo | 6244 | };\n\ |
13970 | obado | 6245 | /* end function 1 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6246 | break; |
6247 | case 2: fprintf(js_include_file,"\ |
||
13970 | obado | 6248 | \n/* begin function 2 read_canvas%d() */\n\ |
8257 | schaersvoo | 6249 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6250 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 6251 | set_reply_precision();\ |
7614 | schaersvoo | 6252 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
8074 | schaersvoo | 6253 | var prec = %d;\ |
7614 | schaersvoo | 6254 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 6255 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
6256 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
7614 | schaersvoo | 6257 | p++;\ |
6258 | };\ |
||
11806 | schaersvoo | 6259 | if(p == 0){return;};\ |
7614 | schaersvoo | 6260 | if( document.getElementById(\"canvas_input0\")){\ |
6261 | var p = 0;var input_reply = new Array();\ |
||
6262 | if( document.getElementById(\"canvas_input0\")){\ |
||
6263 | var t = 0;\ |
||
6264 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6265 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6266 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6267 | p++;\ |
||
6268 | };\ |
||
6269 | t++;\ |
||
6270 | };\ |
||
6271 | };\ |
||
11088 | schaersvoo | 6272 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6273 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6274 | }\ |
||
6275 | else\ |
||
6276 | {\ |
||
6277 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
6278 | }\ |
||
6279 | }\ |
||
6280 | else\ |
||
6281 | {\ |
||
11088 | schaersvoo | 6282 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6283 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
6284 | }\ |
||
6285 | else\ |
||
6286 | {\ |
||
6287 | return reply_x+\"\\n\"+reply_y;\ |
||
6288 | };\ |
||
6289 | };\ |
||
8108 | schaersvoo | 6290 | };\n\ |
13970 | obado | 6291 | /* end function 2 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6292 | break; |
6293 | case 3: fprintf(js_include_file,"\ |
||
13970 | obado | 6294 | \n/* begin function 3 read_canvas%d() */\n\ |
8257 | schaersvoo | 6295 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6296 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 6297 | set_reply_precision();\ |
7614 | schaersvoo | 6298 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6299 | var p = 0;var input_reply = new Array();\ |
||
6300 | if( document.getElementById(\"canvas_input0\")){\ |
||
6301 | var t = 0;\ |
||
6302 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6303 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6304 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6305 | p++;\ |
||
6306 | };\ |
||
6307 | t++;\ |
||
6308 | };\ |
||
6309 | };\ |
||
11088 | schaersvoo | 6310 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6311 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6312 | }\ |
||
6313 | else\ |
||
6314 | {\ |
||
6315 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
6316 | }\ |
||
6317 | }\ |
||
6318 | else\ |
||
6319 | {\ |
||
11088 | schaersvoo | 6320 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6321 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\ |
6322 | }\ |
||
6323 | else\ |
||
6324 | {\ |
||
6325 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\ |
||
6326 | }\ |
||
6327 | }\ |
||
8108 | schaersvoo | 6328 | };\n\ |
13970 | obado | 6329 | /* end function 3 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6330 | break; |
6331 | case 4: fprintf(js_include_file,"\ |
||
13970 | obado | 6332 | \n/* begin function 4 read_canvas%d() */\n\ |
8257 | schaersvoo | 6333 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6334 | var prec = %d;\ |
7614 | schaersvoo | 6335 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
6336 | while(userdraw_x[p]){\ |
||
8074 | schaersvoo | 6337 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
6338 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\ |
||
7614 | schaersvoo | 6339 | p++;\ |
6340 | };\ |
||
11806 | schaersvoo | 6341 | if(p == 0){return;};\ |
7614 | schaersvoo | 6342 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6343 | var p = 0;var input_reply = new Array();\ |
||
6344 | if( document.getElementById(\"canvas_input0\")){\ |
||
6345 | var t = 0;\ |
||
6346 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6347 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6348 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6349 | p++;\ |
||
6350 | };\ |
||
6351 | t++;\ |
||
6352 | };\ |
||
6353 | };\ |
||
11088 | schaersvoo | 6354 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6355 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6356 | }\ |
||
6357 | else\ |
||
6358 | {\ |
||
6359 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
6360 | }\ |
||
6361 | }\ |
||
6362 | else\ |
||
6363 | {\ |
||
11088 | schaersvoo | 6364 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6365 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\ |
6366 | }\ |
||
6367 | else\ |
||
6368 | {\ |
||
6369 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\ |
||
6370 | }\ |
||
6371 | };\ |
||
8108 | schaersvoo | 6372 | };\n\ |
13970 | obado | 6373 | /* end function 4 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6374 | break; |
8224 | bpr | 6375 | /* |
14066 | bpr | 6376 | attention: we reset userdraw_x / userdraw_y: because userdraw_x = [][] userdraw_y = [][] |
8224 | bpr | 6377 | used for userdraw multiple paths |
7614 | schaersvoo | 6378 | */ |
6379 | case 5: fprintf(js_include_file,"\ |
||
13970 | obado | 6380 | \n/* begin function 5 read_canvas%d() */\n\ |
8257 | schaersvoo | 6381 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6382 | set_reply_precision();\ |
7614 | schaersvoo | 6383 | var p = 0;\ |
6384 | var reply = \"\";\ |
||
6385 | for(p = 0; p < userdraw_x.length;p++){\ |
||
6386 | if(userdraw_x[p] != null ){\ |
||
6387 | reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\ |
||
6388 | };\ |
||
6389 | };\ |
||
11806 | schaersvoo | 6390 | if(p == 0){return;};\ |
7614 | schaersvoo | 6391 | userdraw_x = [];userdraw_y = [];\ |
6392 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
6393 | var p = 0;var input_reply = new Array();\ |
||
6394 | if( document.getElementById(\"canvas_input0\")){\ |
||
6395 | var t = 0;\ |
||
6396 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6397 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6398 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6399 | p++;\ |
||
6400 | };\ |
||
6401 | t++;\ |
||
6402 | };\ |
||
6403 | };\ |
||
11088 | schaersvoo | 6404 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6405 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6406 | }\ |
||
6407 | else\ |
||
6408 | {\ |
||
6409 | return reply +\"\\n\"+input_reply;\ |
||
6410 | }\ |
||
6411 | }\ |
||
6412 | else\ |
||
6413 | {\ |
||
11088 | schaersvoo | 6414 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6415 | return reply+\"\\n\"+userdraw_text;\ |
6416 | }\ |
||
6417 | else\ |
||
6418 | {\ |
||
6419 | return reply;\ |
||
6420 | }\ |
||
6421 | };\ |
||
8108 | schaersvoo | 6422 | };\n\ |
13970 | obado | 6423 | /* end function 5 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6424 | break; |
8224 | bpr | 6425 | /* |
14162 | bpr | 6426 | attention: we reset userdraw_x / userdraw_y: because userdraw_x = [][] userdraw_y = [][] |
8224 | bpr | 6427 | used for userdraw multiple paths |
7614 | schaersvoo | 6428 | */ |
6429 | case 6: fprintf(js_include_file,"\ |
||
13970 | obado | 6430 | \n/* begin function 6 read_canvas%d() */\n\ |
8257 | schaersvoo | 6431 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6432 | var p = 0;\ |
6433 | var reply = \"\";\ |
||
6434 | var tmp_x = new Array();\ |
||
6435 | var tmp_y = new Array();\ |
||
8074 | schaersvoo | 6436 | var prec = %d;\ |
7614 | schaersvoo | 6437 | for(p = 0 ; p < userdraw_x.length; p++){\ |
6438 | tmp_x = userdraw_x[p];\ |
||
6439 | tmp_y = userdraw_y[p];\ |
||
6440 | if(tmp_x != null){\ |
||
6441 | for(var i = 0 ; i < tmp_x.length ; i++){\ |
||
8074 | schaersvoo | 6442 | tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\ |
6443 | tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\ |
||
7614 | schaersvoo | 6444 | };\ |
6445 | reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\ |
||
6446 | };\ |
||
6447 | };\ |
||
11806 | schaersvoo | 6448 | if(p == 0){return;};\ |
7614 | schaersvoo | 6449 | userdraw_x = [];userdraw_y = [];\ |
6450 | if( document.getElementById(\"canvas_input0\") ){\ |
||
6451 | var p = 0;var input_reply = new Array();\ |
||
6452 | if( document.getElementById(\"canvas_input0\")){\ |
||
6453 | var t = 0;\ |
||
6454 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6455 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6456 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6457 | p++;\ |
||
6458 | };\ |
||
6459 | t++;\ |
||
6460 | };\ |
||
6461 | };\ |
||
11088 | schaersvoo | 6462 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6463 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6464 | }\ |
||
6465 | else\ |
||
6466 | {\ |
||
6467 | return reply +\"\\n\"+input_reply;\ |
||
6468 | }\ |
||
6469 | }\ |
||
6470 | else\ |
||
6471 | {\ |
||
11088 | schaersvoo | 6472 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6473 | return reply +\"\\n\"+userdraw_text;\ |
6474 | }\ |
||
6475 | else\ |
||
6476 | {\ |
||
6477 | return reply;\ |
||
6478 | }\ |
||
6479 | };\ |
||
8108 | schaersvoo | 6480 | };\n\ |
13970 | obado | 6481 | /* end function 6 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6482 | break; |
6483 | case 7: fprintf(js_include_file,"\ |
||
13970 | obado | 6484 | \n/* begin function 7 read_canvas%d() */\n\ |
8257 | schaersvoo | 6485 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6486 | set_reply_precision();\ |
7614 | schaersvoo | 6487 | var reply = new Array();\ |
6488 | var p = 0;\ |
||
6489 | while(userdraw_x[p]){\ |
||
6490 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\ |
||
6491 | p++;\ |
||
6492 | };\ |
||
11806 | schaersvoo | 6493 | if(p == 0){return;};\ |
7614 | schaersvoo | 6494 | if( document.getElementById(\"canvas_input0\") ){\ |
6495 | var p = 0;var input_reply = new Array();\ |
||
6496 | if( document.getElementById(\"canvas_input0\")){\ |
||
6497 | var t = 0;\ |
||
6498 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6499 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6500 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6501 | p++;\ |
||
6502 | };\ |
||
6503 | t++;\ |
||
6504 | };\ |
||
6505 | };\ |
||
11088 | schaersvoo | 6506 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6507 | return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6508 | }\ |
||
6509 | else\ |
||
6510 | {\ |
||
6511 | return reply+\"\\n\"+input_reply;\ |
||
6512 | }\ |
||
7862 | schaersvoo | 6513 | }\ |
7614 | schaersvoo | 6514 | else\ |
6515 | {\ |
||
11088 | schaersvoo | 6516 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6517 | return reply+\"\\n\"+userdraw_text;\ |
6518 | }\ |
||
6519 | else\ |
||
6520 | {\ |
||
6521 | return reply;\ |
||
6522 | }\ |
||
6523 | };\ |
||
8108 | schaersvoo | 6524 | };\n\ |
13970 | obado | 6525 | /* end function 7 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6526 | break; |
6527 | case 8: fprintf(js_include_file,"\ |
||
13970 | obado | 6528 | \n/* begin function 8 read_canvas%d() */\n\ |
8257 | schaersvoo | 6529 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6530 | var reply = new Array();\ |
6531 | var p = 0;\ |
||
8074 | schaersvoo | 6532 | var prec = %d;\ |
7614 | schaersvoo | 6533 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 6534 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
7614 | schaersvoo | 6535 | p++;\ |
6536 | };\ |
||
11806 | schaersvoo | 6537 | if(p == 0){return;};\ |
7614 | schaersvoo | 6538 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6539 | var p = 0;var input_reply = new Array();\ |
||
6540 | if( document.getElementById(\"canvas_input0\")){\ |
||
6541 | var t = 0;\ |
||
6542 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6543 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6544 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6545 | p++;\ |
||
6546 | };\ |
||
6547 | t++;\ |
||
6548 | };\ |
||
6549 | };\ |
||
11088 | schaersvoo | 6550 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6551 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6552 | }\ |
||
6553 | else\ |
||
6554 | {\ |
||
6555 | return reply +\"\\n\"+input_reply;\ |
||
6556 | }\ |
||
6557 | }\ |
||
6558 | else\ |
||
6559 | {\ |
||
11088 | schaersvoo | 6560 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6561 | return reply +\"\\n\"+userdraw_text;\ |
6562 | }\ |
||
6563 | else\ |
||
6564 | {\ |
||
6565 | return reply;\ |
||
6566 | }\ |
||
6567 | };\ |
||
8108 | schaersvoo | 6568 | };\n\ |
13970 | obado | 6569 | /* end function 8 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6570 | break; |
6571 | case 9: fprintf(js_include_file,"\ |
||
13970 | obado | 6572 | \n/* begin function 9 read_canvas%d() */\n\ |
8257 | schaersvoo | 6573 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6574 | set_reply_precision();\ |
7614 | schaersvoo | 6575 | var reply = new Array();\ |
6576 | var p = 0;\ |
||
6577 | while(userdraw_x[p]){\ |
||
6578 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\ |
||
6579 | p++;\ |
||
6580 | };\ |
||
11806 | schaersvoo | 6581 | if(p == 0){return;};\ |
7614 | schaersvoo | 6582 | if( document.getElementById(\"canvas_input0\") ){\ |
6583 | var p = 0;var input_reply = new Array();\ |
||
6584 | if( document.getElementById(\"canvas_input0\")){\ |
||
6585 | var t = 0;\ |
||
6586 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6587 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6588 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6589 | p++;\ |
||
6590 | };\ |
||
6591 | t++;\ |
||
6592 | };\ |
||
6593 | };\ |
||
11088 | schaersvoo | 6594 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6595 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6596 | }\ |
||
6597 | else\ |
||
6598 | {\ |
||
6599 | return reply +\"\\n\"+input_reply;\ |
||
6600 | }\ |
||
6601 | }\ |
||
6602 | else\ |
||
6603 | {\ |
||
11088 | schaersvoo | 6604 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6605 | return reply +\"\\n\"+userdraw_text;\ |
6606 | }\ |
||
6607 | else\ |
||
6608 | {\ |
||
6609 | return reply;\ |
||
6610 | }\ |
||
6611 | };\ |
||
8108 | schaersvoo | 6612 | };\n\ |
13970 | obado | 6613 | /* end function 9 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6614 | break; |
6615 | case 10: fprintf(js_include_file,"\ |
||
13970 | obado | 6616 | \n/* begin function 10 read_canvas%d() */\n\ |
8257 | schaersvoo | 6617 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6618 | var reply = new Array();\ |
6619 | var p = 0;\ |
||
8074 | schaersvoo | 6620 | var prec = %d;\ |
14044 | schaersvoo | 6621 | var reply = \"\";\ |
7614 | schaersvoo | 6622 | while(userdraw_x[p]){\ |
14044 | schaersvoo | 6623 | reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\";\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec + \";\" + (Math.round(prec*userdraw_radius[p]))/prec + \"\\n\";\ |
7614 | schaersvoo | 6624 | p++;\ |
6625 | };\ |
||
11806 | schaersvoo | 6626 | if(p == 0){return;};\ |
14044 | schaersvoo | 6627 | return reply;\ |
8108 | schaersvoo | 6628 | };\n\ |
13970 | obado | 6629 | /* end function 10 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6630 | break; |
6631 | case 11: fprintf(js_include_file,"\ |
||
13970 | obado | 6632 | \n/* begin function 11 read_canvas%d() */\n\ |
8257 | schaersvoo | 6633 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6634 | var reply = \"\";\ |
6635 | var p = 0;\ |
||
8074 | schaersvoo | 6636 | var prec = %d;\ |
13521 | schaersvoo | 6637 | while(userdraw_x[p+1]){\ |
8074 | schaersvoo | 6638 | 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 | 6639 | p = p+2;\ |
6640 | };\ |
||
11806 | schaersvoo | 6641 | if(p == 0){return;};\ |
7614 | schaersvoo | 6642 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6643 | var p = 0;var input_reply = new Array();\ |
||
6644 | if( document.getElementById(\"canvas_input0\")){\ |
||
6645 | var t = 0;\ |
||
6646 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6647 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6648 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6649 | p++;\ |
||
6650 | };\ |
||
6651 | t++;\ |
||
6652 | };\ |
||
6653 | };\ |
||
11088 | schaersvoo | 6654 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6655 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6656 | }\ |
||
6657 | else\ |
||
6658 | {\ |
||
6659 | return reply +\"\\n\"+input_reply;\ |
||
6660 | }\ |
||
6661 | }\ |
||
6662 | else\ |
||
6663 | {\ |
||
11088 | schaersvoo | 6664 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6665 | return reply +\"\\n\"+userdraw_text;\ |
6666 | }\ |
||
6667 | else\ |
||
6668 | {\ |
||
6669 | return reply;\ |
||
6670 | }\ |
||
6671 | };\ |
||
8108 | schaersvoo | 6672 | };\n\ |
13970 | obado | 6673 | /* end function 11 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6674 | break; |
6675 | case 12: fprintf(js_include_file,"\ |
||
13970 | obado | 6676 | \n/* begin function 12 read_canvas%d() */\n\ |
8257 | schaersvoo | 6677 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6678 | set_reply_precision();\ |
7614 | schaersvoo | 6679 | var reply = \"\";\ |
6680 | var p = 0;\ |
||
13522 | schaersvoo | 6681 | while(userdraw_x[p+1]){\ |
6682 | reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\ |
||
6683 | p=p+2;\ |
||
7614 | schaersvoo | 6684 | };\ |
13522 | schaersvoo | 6685 | };\ |
11806 | schaersvoo | 6686 | if(p == 0){return;};\ |
7614 | schaersvoo | 6687 | if( document.getElementById(\"canvas_input0\") ){\ |
6688 | var p = 0;var input_reply = new Array();\ |
||
6689 | if( document.getElementById(\"canvas_input0\")){\ |
||
6690 | var t = 0;\ |
||
6691 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6692 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6693 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6694 | p++;\ |
||
6695 | };\ |
||
6696 | t++;\ |
||
6697 | };\ |
||
6698 | };\ |
||
11088 | schaersvoo | 6699 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6700 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6701 | }\ |
||
6702 | else\ |
||
6703 | {\ |
||
6704 | return reply +\"\\n\"+input_reply;\ |
||
6705 | }\ |
||
6706 | }\ |
||
6707 | else\ |
||
6708 | {\ |
||
11088 | schaersvoo | 6709 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6710 | return reply +\"\\n\"+userdraw_text\ |
6711 | }\ |
||
6712 | else\ |
||
6713 | {\ |
||
6714 | return reply;\ |
||
6715 | }\ |
||
6716 | };\ |
||
8108 | schaersvoo | 6717 | };\n\ |
13970 | obado | 6718 | /* end function 12 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6719 | break; |
6720 | case 13: fprintf(js_include_file,"\ |
||
13970 | obado | 6721 | \n/* begin function 13 read_canvas%d() */\n\ |
8257 | schaersvoo | 6722 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6723 | var reply = new Array();\ |
6724 | var p = 0;var i = 0;\ |
||
8074 | schaersvoo | 6725 | var prec = %d;\ |
13521 | schaersvoo | 6726 | while(userdraw_x[p+1]){\ |
8074 | schaersvoo | 6727 | 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 | 6728 | p = p+2;i++;\ |
6729 | };\ |
||
11806 | schaersvoo | 6730 | if(p == 0){return;};\ |
7614 | schaersvoo | 6731 | if( document.getElementById(\"canvas_input0\") ){\ |
6732 | var p = 0;var input_reply = new Array();\ |
||
6733 | if( document.getElementById(\"canvas_input0\")){\ |
||
6734 | var t = 0;\ |
||
6735 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6736 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6737 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6738 | p++;\ |
||
6739 | };\ |
||
6740 | t++;\ |
||
6741 | };\ |
||
6742 | };\ |
||
11088 | schaersvoo | 6743 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6744 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6745 | }\ |
||
6746 | else\ |
||
6747 | {\ |
||
6748 | return reply +\"\\n\"+input_reply;\ |
||
6749 | }\ |
||
6750 | }\ |
||
6751 | else\ |
||
6752 | {\ |
||
11088 | schaersvoo | 6753 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6754 | return reply +\"\\n\"+userdraw_text\ |
6755 | }\ |
||
6756 | else\ |
||
6757 | {\ |
||
6758 | return reply;\ |
||
6759 | }\ |
||
6760 | };\ |
||
8108 | schaersvoo | 6761 | };\n\ |
13970 | obado | 6762 | /* end function 13 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6763 | break; |
6764 | case 14: fprintf(js_include_file,"\ |
||
13970 | obado | 6765 | \n/* begin function 14 read_canvas%d() */\n\ |
8257 | schaersvoo | 6766 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6767 | set_reply_precision();\ |
7614 | schaersvoo | 6768 | var reply = new Array();\ |
6769 | var p = 0;var i = 0;\ |
||
13521 | schaersvoo | 6770 | while(userdraw_x[p+1]){\ |
7614 | schaersvoo | 6771 | reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\ |
6772 | p = p+2;i++;\ |
||
6773 | };\ |
||
11806 | schaersvoo | 6774 | if(p == 0){return;};\ |
7614 | schaersvoo | 6775 | if( document.getElementById(\"canvas_input0\") ){\ |
6776 | var p = 0;var input_reply = new Array();\ |
||
6777 | if( document.getElementById(\"canvas_input0\")){\ |
||
6778 | var t = 0;\ |
||
6779 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6780 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6781 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6782 | p++;\ |
||
6783 | };\ |
||
6784 | t++;\ |
||
6785 | };\ |
||
6786 | };\ |
||
11088 | schaersvoo | 6787 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6788 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6789 | }\ |
||
6790 | else\ |
||
6791 | {\ |
||
6792 | return reply +\"\\n\"+input_reply;\ |
||
6793 | }\ |
||
6794 | }\ |
||
6795 | else\ |
||
6796 | {\ |
||
11088 | schaersvoo | 6797 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6798 | return reply +\"\\n\"+userdraw_text;\ |
6799 | }\ |
||
6800 | else\ |
||
6801 | {\ |
||
6802 | return reply;\ |
||
6803 | }\ |
||
6804 | };\ |
||
8108 | schaersvoo | 6805 | };\n\ |
13970 | obado | 6806 | /* end function 14 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6807 | break; |
6808 | case 15: fprintf(js_include_file,"\ |
||
13970 | obado | 6809 | \n/* begin function 15 read_canvas%d() */\n\ |
8257 | schaersvoo | 6810 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6811 | var input_reply = new Array();\ |
6812 | var p = 0;\ |
||
6813 | if( document.getElementById(\"canvas_input0\")){\ |
||
6814 | var t = 0;\ |
||
6815 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6816 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6817 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6818 | p++;\ |
||
6819 | };\ |
||
6820 | t++;\ |
||
6821 | };\ |
||
6822 | };\ |
||
11088 | schaersvoo | 6823 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6824 | return input_reply +\"\\n\"+userdraw_text;\ |
6825 | }\ |
||
6826 | else\ |
||
6827 | {\ |
||
6828 | return input_reply;\ |
||
6829 | };\ |
||
8108 | schaersvoo | 6830 | };\n\ |
13970 | obado | 6831 | /* end function 15 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6832 | break; |
6833 | case 16: fprintf(js_include_file,"\ |
||
13970 | obado | 6834 | \n/* begin function 16 read_mathml() */\n\ |
7614 | schaersvoo | 6835 | function read_mathml(){\ |
6836 | var reply = new Array();\ |
||
6837 | var p = 0;\ |
||
6838 | if( document.getElementById(\"mathml0\")){\ |
||
6839 | while(document.getElementById(\"mathml\"+p)){\ |
||
6840 | reply[p] = document.getElementById(\"mathml\"+p).value;\ |
||
6841 | p++;\ |
||
6842 | };\ |
||
6843 | };\ |
||
6844 | return reply;\ |
||
6845 | };\ |
||
6846 | this.read_mathml = read_mathml;\n\ |
||
13970 | obado | 6847 | /* end function 16 read_mathml() */"); |
7614 | schaersvoo | 6848 | break; |
6849 | case 17: fprintf(js_include_file,"\ |
||
13970 | obado | 6850 | \n/* begin function 17 read_canvas%d() */\n\ |
8257 | schaersvoo | 6851 | read_canvas%d = function(){\ |
11080 | schaersvoo | 6852 | var len = userdraw_x.length;\ |
6853 | if( len == 0){alert(\"no text typed...\");return;}\ |
||
6854 | var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\ |
||
6855 | for(var p = 1 ; p < len ; p++){\ |
||
6856 | rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\ |
||
6857 | };\ |
||
6858 | return rep;\ |
||
8108 | schaersvoo | 6859 | };\n\ |
13970 | obado | 6860 | /* end function 17 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6861 | break; |
6862 | case 18: fprintf(js_include_file,"\ |
||
13970 | obado | 6863 | \n/* javascript has no real modulo function */\n\ |
10956 | schaersvoo | 6864 | function mod(n, m){\ |
6865 | var m = parseInt(((n %% m) + m) %% m);\ |
||
6866 | return m;\ |
||
6867 | };\ |
||
13970 | obado | 6868 | \n/* begin function 18 read_canvas%d() */\n\ |
8257 | schaersvoo | 6869 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6870 | var p = 0;\ |
6871 | var reply = new Array();\ |
||
6872 | var name;\ |
||
6873 | var t = true;\ |
||
8000 | schaersvoo | 6874 | var h;var m;var s;\ |
7614 | schaersvoo | 6875 | while(t){\ |
8000 | schaersvoo | 6876 | try{\ |
6877 | name = eval('clocks'+p);\ |
||
6878 | h = name.H;m = name.M;s = name.S;\ |
||
10956 | schaersvoo | 6879 | h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\ |
8000 | schaersvoo | 6880 | reply[p] = h+\":\"+m+\":\"+s;\ |
6881 | p++;\ |
||
6882 | }catch(e){t=false;};\ |
||
7614 | schaersvoo | 6883 | };\ |
8000 | schaersvoo | 6884 | if( p == 0 ){alert(\"clock(s) not modified...\");return;}\ |
7614 | schaersvoo | 6885 | return reply;\ |
8108 | schaersvoo | 6886 | };\n\ |
13970 | obado | 6887 | /* end function 18 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6888 | break; |
6889 | case 19: fprintf(js_include_file,"\ |
||
13970 | obado | 6890 | \n/* begin function 19 read_canvas%d() */\n\ |
8257 | schaersvoo | 6891 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6892 | return reply[0];\ |
8108 | schaersvoo | 6893 | };\n\ |
13970 | obado | 6894 | /* end function 19 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
8130 | schaersvoo | 6895 | break; |
7614 | schaersvoo | 6896 | case 20: fprintf(js_include_file,"\ |
13970 | obado | 6897 | \n/* begin function 20 read_canvas%d() */\n\ |
8257 | schaersvoo | 6898 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6899 | var prec = %d;\ |
7614 | schaersvoo | 6900 | var len = ext_drag_images.length;\ |
6901 | var reply = new Array(len);\ |
||
6902 | for(var p = 0 ; p < len ; p++){\ |
||
6903 | var img = ext_drag_images[p];\ |
||
8556 | schaersvoo | 6904 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
7614 | schaersvoo | 6905 | };\ |
6906 | return reply;\ |
||
8108 | schaersvoo | 6907 | };\n\ |
13970 | obado | 6908 | /* end function 20 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6909 | break; |
6910 | case 21: fprintf(js_include_file,"\ |
||
13970 | obado | 6911 | \n/* begin function 21 read_canvas%d() */\n\ |
8257 | schaersvoo | 6912 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6913 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
6914 | var reply_coord = new Array();var p = 0;\ |
||
8074 | schaersvoo | 6915 | var prec = %d;\ |
7614 | schaersvoo | 6916 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 6917 | reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\ |
7614 | schaersvoo | 6918 | p++;\ |
6919 | };\ |
||
11806 | schaersvoo | 6920 | if(p == 0){return;};\ |
7614 | schaersvoo | 6921 | if( document.getElementById(\"canvas_input0\") ){\ |
6922 | var p = 0;var input_reply = new Array();\ |
||
6923 | if( document.getElementById(\"canvas_input0\")){\ |
||
6924 | var t = 0;\ |
||
6925 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6926 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6927 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6928 | p++;\ |
||
6929 | };\ |
||
6930 | t++;\ |
||
6931 | };\ |
||
6932 | };\ |
||
11088 | schaersvoo | 6933 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6934 | return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6935 | }\ |
||
6936 | else\ |
||
6937 | {\ |
||
6938 | return reply_coord+\"\\n\"+input_reply;\ |
||
6939 | }\ |
||
6940 | }\ |
||
6941 | else\ |
||
6942 | {\ |
||
11088 | schaersvoo | 6943 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6944 | return reply_coord+\"\\n\"+userdraw_text;\ |
6945 | }\ |
||
6946 | else\ |
||
6947 | {\ |
||
6948 | return reply_coord;\ |
||
6949 | };\ |
||
6950 | };\ |
||
8108 | schaersvoo | 6951 | };\n\ |
13970 | obado | 6952 | /* end function 21 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6953 | break; |
6954 | case 22: fprintf(js_include_file,"\ |
||
13970 | obado | 6955 | \n/* begin function 22 read_canvas%d() */\n\ |
8257 | schaersvoo | 6956 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6957 | var reply = new Array();\ |
7963 | schaersvoo | 6958 | var lu = userdraw_x.length;\ |
11806 | schaersvoo | 6959 | if(lu == 0){return;};\ |
7614 | schaersvoo | 6960 | var idx = 0;\ |
8074 | schaersvoo | 6961 | var prec = %d;\ |
7963 | schaersvoo | 6962 | for(var p = 0 ; p < lu ; p++){\ |
8074 | schaersvoo | 6963 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\ |
6964 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\ |
||
7614 | schaersvoo | 6965 | };\ |
6966 | if( document.getElementById(\"canvas_input0\") ){\ |
||
6967 | var p = 0;var input_reply = new Array();\ |
||
6968 | if( document.getElementById(\"canvas_input0\")){\ |
||
6969 | var t = 0;\ |
||
6970 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6971 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6972 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6973 | p++;\ |
||
6974 | };\ |
||
6975 | t++;\ |
||
6976 | };\ |
||
6977 | };\ |
||
11088 | schaersvoo | 6978 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6979 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6980 | }\ |
||
6981 | else\ |
||
6982 | {\ |
||
6983 | return reply +\"\\n\"+input_reply;\ |
||
6984 | }\ |
||
6985 | }\ |
||
6986 | else\ |
||
6987 | {\ |
||
11088 | schaersvoo | 6988 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6989 | return reply +\"\\n\"+userdraw_text;\ |
6990 | }\ |
||
6991 | else\ |
||
6992 | {\ |
||
6993 | return reply;\ |
||
6994 | }\ |
||
6995 | };\ |
||
8108 | schaersvoo | 6996 | };\n\ |
13970 | obado | 6997 | /* end function 22 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6998 | break; |
7782 | schaersvoo | 6999 | case 23: fprintf(js_include_file,"\ |
13970 | obado | 7000 | \n/* begin function 23 read_canvas%d() default 5 px marge */\n\ |
8257 | schaersvoo | 7001 | read_canvas%d = function(){\ |
7782 | schaersvoo | 7002 | if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\ |
7003 | var lu = userdraw_x.length;\ |
||
7004 | if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\ |
||
7962 | schaersvoo | 7005 | var reply_x = new Array();var reply_y = new Array();\ |
7006 | var marge = 5;var p = 0;\ |
||
8074 | schaersvoo | 7007 | var prec = %d;\ |
7782 | schaersvoo | 7008 | for(var i = 0; i < lu - 1 ; i++ ){\ |
10987 | schaersvoo | 7009 | if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\ |
8074 | schaersvoo | 7010 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\ |
7962 | schaersvoo | 7011 | if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\ |
7012 | p++;\ |
||
7782 | schaersvoo | 7013 | };\ |
8074 | schaersvoo | 7014 | 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 | 7015 | };\ |
7016 | if( document.getElementById(\"canvas_input0\")){\ |
||
7017 | var p = 0;var input_reply = new Array();\ |
||
7018 | if( document.getElementById(\"canvas_input0\")){\ |
||
7019 | var t = 0;\ |
||
7020 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
7021 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
7022 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
7023 | p++;\ |
||
7024 | };\ |
||
7025 | t++;\ |
||
7026 | };\ |
||
7027 | };\ |
||
11088 | schaersvoo | 7028 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7782 | schaersvoo | 7029 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
7030 | }\ |
||
7031 | else\ |
||
7032 | {\ |
||
7033 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
7034 | }\ |
||
7035 | }\ |
||
7036 | else\ |
||
7037 | {\ |
||
11088 | schaersvoo | 7038 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7782 | schaersvoo | 7039 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
7040 | }\ |
||
7041 | else\ |
||
7042 | {\ |
||
7043 | return reply_x+\"\\n\"+reply_y;\ |
||
7044 | };\ |
||
7045 | };\ |
||
8108 | schaersvoo | 7046 | };\n\ |
13970 | obado | 7047 | /* end function 23 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7782 | schaersvoo | 7048 | break; |
7984 | schaersvoo | 7049 | case 24: fprintf(js_include_file,"\n\ |
13970 | obado | 7050 | /* begin function 24 read_canvas%d() */\n\ |
8257 | schaersvoo | 7051 | read_canvas%d = function(){\ |
7984 | schaersvoo | 7052 | var input_reply = new Array();\ |
7053 | var p = 0;\ |
||
7054 | if( document.getElementById(\"canvas_input0\")){\ |
||
7055 | while(document.getElementById(\"canvas_input\"+p)){\ |
||
7056 | input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\ |
||
7057 | p++;\ |
||
7058 | };\ |
||
7059 | return input_reply;\ |
||
7060 | };\ |
||
8108 | schaersvoo | 7061 | };\n\ |
13970 | obado | 7062 | /* end function 24 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7984 | schaersvoo | 7063 | break; |
8083 | schaersvoo | 7064 | case 25: |
14066 | bpr | 7065 | fprintf(js_include_file,"\n/* begin function 25 read_canvas%d(): angle(s) in degrees */\n\ |
8257 | schaersvoo | 7066 | read_canvas%d = function(){\ |
8083 | schaersvoo | 7067 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
7068 | var lu = userdraw_radius.length;\ |
||
7069 | var prec = %d;\ |
||
7070 | var angle_reply = new Array(lu);\ |
||
7071 | for(var p = 0 ; p < lu ; p++){\ |
||
7072 | angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\ |
||
7073 | };\ |
||
7074 | return angle_reply;\ |
||
8108 | schaersvoo | 7075 | };\n\ |
13970 | obado | 7076 | /* end function 25 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 7077 | break; |
7078 | case 26: |
||
14066 | bpr | 7079 | fprintf(js_include_file,"\n/* begin function 26 read_canvas%d(): angle(s) in radians */\n\ |
8257 | schaersvoo | 7080 | read_canvas%d = function(){\ |
8083 | schaersvoo | 7081 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
7082 | var lu = userdraw_radius.length;\ |
||
7083 | var prec = %d;\ |
||
7084 | var angle_reply = new Array(lu);\ |
||
7085 | for(var p = 0 ; p < lu ; p++){\ |
||
7086 | angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\ |
||
7087 | };\ |
||
7088 | return angle_reply;\ |
||
8108 | schaersvoo | 7089 | };\n\ |
13970 | obado | 7090 | /* end function 26 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 7091 | break; |
8127 | schaersvoo | 7092 | case 27: |
14066 | bpr | 7093 | fprintf(js_include_file,"\n/* begin function 27 read_canvas%d(): inputfield(s) location and their values: */\n\ |
8257 | schaersvoo | 7094 | read_canvas%d = function(){\ |
8127 | schaersvoo | 7095 | var lu = userdraw_x.length;\ |
14044 | schaersvoo | 7096 | if( lu < 1){alert(\"nothing drawn...\");return;};\ |
8127 | schaersvoo | 7097 | set_reply_precision();\ |
14044 | schaersvoo | 7098 | var prec = %d;var rep = \"\";\ |
8127 | schaersvoo | 7099 | for(var p = 0 ; p < lu ; p++){\ |
14044 | schaersvoo | 7100 | rep = rep + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\";\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\";\"+ document.getElementById(\"canvas_input\"+p).value + \"\\n\";\ |
8127 | schaersvoo | 7101 | };\ |
11080 | schaersvoo | 7102 | return rep;\ |
8127 | schaersvoo | 7103 | };\n\ |
13970 | obado | 7104 | /* end function 27 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8127 | schaersvoo | 7105 | break; |
8322 | schaersvoo | 7106 | case 28: |
13970 | obado | 7107 | fprintf(js_include_file,"\n/* begin function 28 read_canvas%d() */\n\ |
8322 | schaersvoo | 7108 | read_canvas%d = function(){\ |
7109 | var prec = %d;\ |
||
7110 | var reply = new Array();var p = 0;\ |
||
7111 | var idx = 0;\ |
||
7112 | while(userdraw_x[p]){\ |
||
7113 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
||
7114 | idx++;\ |
||
7115 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
7116 | idx++;\ |
||
7117 | reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\ |
||
7118 | idx++;\ |
||
7119 | p++;\ |
||
7120 | };\ |
||
7121 | if( p == 0){alert(\"nothing drawn...\");return;}\ |
||
7122 | return reply;\ |
||
7123 | };\n\ |
||
13970 | obado | 7124 | /* end function 28 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8322 | schaersvoo | 7125 | break; |
9213 | schaersvoo | 7126 | case 29: |
13970 | obado | 7127 | fprintf(js_include_file,"\n/* begin function 29 read_canvas%d() */\n\ |
14038 | schaersvoo | 7128 | function x_precision(array_x){\ |
9213 | schaersvoo | 7129 | var len = array_x.length;\ |
7130 | var x_array = new Array(len);\ |
||
14038 | schaersvoo | 7131 | var prec = %d;\ |
7132 | for(var p = 0 ; p < len ; p++ ){\ |
||
7133 | x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\ |
||
7134 | };\ |
||
7135 | return x_array;\ |
||
7136 | };\ |
||
7137 | function y_precision(array_y){\ |
||
7138 | var len = array_y.length;\ |
||
9213 | schaersvoo | 7139 | var y_array = new Array(len);\ |
7140 | var prec = %d;\ |
||
7141 | for(var p = 0 ; p < len ; p++ ){\ |
||
7142 | y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\ |
||
7143 | };\ |
||
14038 | schaersvoo | 7144 | return y_array;\ |
7145 | };\ |
||
14381 | schaersvoo | 7146 | function radius_to_x(array_r){\ |
7147 | var len = array_r.length;\ |
||
7148 | var ff = (xmax - xmin)/xsize;\ |
||
7149 | var r_array = new Array(len);\ |
||
7150 | var prec = %d;\ |
||
9213 | schaersvoo | 7151 | for(var p = 0 ; p < len ; p++ ){\ |
14381 | schaersvoo | 7152 | r_array[p] = (Math.round(prec*(ff*(array_r[p]))))/prec;\ |
9213 | schaersvoo | 7153 | };\ |
14381 | schaersvoo | 7154 | return r_array;\ |
9213 | schaersvoo | 7155 | };\ |
7156 | read_canvas%d = function(){\ |
||
14038 | schaersvoo | 7157 | function uniq_fast(arr){\ |
7158 | var seen = {};\ |
||
7159 | var out = [];\ |
||
7160 | var len = arr.length;\ |
||
7161 | var j = 0;\ |
||
7162 | for(var i = 0; i < len; i++){\ |
||
7163 | var item = arr[i];\ |
||
7164 | if(seen[item] !== 1) {\ |
||
7165 | seen[item] = 1;out[j++] = item;\ |
||
7166 | };\ |
||
7167 | };\ |
||
7168 | return out;\ |
||
7169 | };\ |
||
7170 | function list_unique(arr1,arr2,arr3){\ |
||
14393 | schaersvoo | 7171 | if( typeof( allow_duplicate_answers ) === 'number' ){ return [ x_precision(arr1),y_precision(arr2),arr3 ];};\ |
14038 | schaersvoo | 7172 | var len1 = arr1.length;\ |
7173 | if(len1 != arr2.length){alert('mismatch in number of x and y values...');return;};\ |
||
7174 | var sum = [];var R1=[];var R2=[];\ |
||
7175 | arr1 = x_precision(arr1);\ |
||
7176 | arr2 = y_precision(arr2);\ |
||
7177 | if(arr3 == null){\ |
||
7178 | for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]; };\ |
||
7179 | sum = uniq_fast(sum);var len2=sum.length;\ |
||
7180 | for(var p=0;p<len2;p++){\ |
||
7181 | var tmp = (sum[p]).split('#');\ |
||
7182 | R1[p] = tmp[0];\ |
||
7183 | R2[p] = tmp[1];\ |
||
7184 | };\ |
||
7185 | return [R1,R2];\ |
||
7186 | }else{\ |
||
7187 | var R3 = [];\ |
||
7188 | for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]+'#'+arr3[p];};\ |
||
7189 | sum = uniq_fast(sum);var len2=sum.length;\ |
||
7190 | for(var p=0;p<len2;p++){\ |
||
7191 | var tmp = (sum[p]).split('#');\ |
||
7192 | R1[p] = tmp[0];\ |
||
7193 | R2[p] = tmp[1];\ |
||
7194 | R3[p] = tmp[2];\ |
||
7195 | };\ |
||
7196 | return [R1,R2,R3];\ |
||
7197 | };\ |
||
7198 | };\ |
||
9300 | schaersvoo | 7199 | var reply=\" \";\ |
14038 | schaersvoo | 7200 | if( typeof(points_x) === 'object' && points_x.length > 0 ){var xyz = list_unique(points_x,points_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
14382 | schaersvoo | 7201 | if( typeof(circles_x) === 'object' && circles_x.length > 0 ){var xyz = list_unique(circles_x,circles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+radius_to_x(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
14038 | schaersvoo | 7202 | if( typeof(segments_x) === 'object' && segments_x.length > 0 ){ var xyz = list_unique(segments_x,segments_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
7203 | if( typeof(arrows_x) === 'object' && arrows_x.length > 0 ){var xyz = list_unique(arrows_x,arrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7204 | if( typeof(lines_x) === 'object' && lines_x.length > 0 ){ var xyz = list_unique(lines_x,lines_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7205 | if( typeof(triangles_x) === 'object' && triangles_x.length > 0){var xyz = list_unique(triangles_x,triangles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7206 | if( typeof(polys_x) === 'object' && polys_x.length > 0){ var xyz = list_unique(polys_x,polys_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7207 | if( typeof(rects_x) === 'object' && rects_x.length > 0 ){var xyz = list_unique(rects_x,rects_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7208 | if( typeof(closedpoly_x) === 'object' && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();var xyz = list_unique(closedpoly_x,closedpoly_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
||
7209 | if( typeof(parallelogram_x) === 'object' && parallelogram_x.length > 0){var xyz = list_unique(parallelogram_x,parallelogram_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7210 | if( typeof(text_x) === 'object' && text_x.length > 0){var xyz = list_unique(text_x,text_y,text_abc);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
||
7211 | if( typeof(images_x) === 'object' && images_x.length > 0){var xyz = list_unique(images_x,images_y,images_id);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
||
7212 | if( typeof(curvedarrows_x) === 'object' && curvedarrows_x.length > 0){var xyz = list_unique(curvedarrows_x,curvedarrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\ |
||
7213 | if( typeof(curvedarrows2_x) === 'object' && curvedarrows2_x.length > 0){var xyz = list_unique(curvedarrows2_x,curvedarrows2_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\ |
||
7214 | if( typeof(userdraw_x) === 'object' && userdraw_radius.x> 0){var xyz = list_unique(userdraw_x,userdraw_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; return reply;;};\ |
||
7215 | if( typeof(userdraw_radius) === 'object' && userdraw_radius.length > 0){var xyz = list_unique(userdraw_x,userdraw_y,userdraw_radius);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\"; return reply;;};\ |
||
9213 | schaersvoo | 7216 | return reply;\ |
14038 | schaersvoo | 7217 | };\ |
14381 | schaersvoo | 7218 | /* end function 29 read_canvas%d() */",canvas_root_id,reply_precision,reply_precision,reply_precision,canvas_root_id,canvas_root_id); |
9213 | schaersvoo | 7219 | break; |
9289 | schaersvoo | 7220 | case 30: |
13970 | obado | 7221 | fprintf(js_include_file,"\n/* begin function 30 read_canvas%d() */\n\ |
9289 | schaersvoo | 7222 | read_canvas%d = function(){\ |
7223 | var reply = new Array(3);\ |
||
7224 | var prec = %d;\ |
||
7225 | reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
7226 | reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
7227 | reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
7228 | return reply;\ |
||
7229 | };\n\ |
||
13970 | obado | 7230 | /* end function 30 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
9289 | schaersvoo | 7231 | break; |
7232 | case 31: |
||
13970 | obado | 7233 | fprintf(js_include_file,"\n/* begin function 31 read_canvas%d() */\n\ |
9289 | schaersvoo | 7234 | read_canvas%d = function(){\ |
7235 | var reply = new Array(3);\ |
||
7236 | var prec = %d;\ |
||
7237 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
7238 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
7239 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
7240 | return reply;\ |
||
7241 | };\n\ |
||
13970 | obado | 7242 | /* end function 31 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
9289 | schaersvoo | 7243 | break; |
7244 | case 32: |
||
13970 | obado | 7245 | fprintf(js_include_file,"\n/* begin function 32 read_canvas%d() */\n\ |
9289 | schaersvoo | 7246 | read_canvas%d = function(){\ |
7247 | var reply = new Array(6);\ |
||
7248 | var prec = %d;\ |
||
7249 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
7250 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
7251 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
7252 | reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
7253 | reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
7254 | reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
7255 | return reply;\ |
||
7256 | };\n\ |
||
13970 | obado | 7257 | /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
9289 | schaersvoo | 7258 | break; |
14038 | schaersvoo | 7259 | case 33: |
7260 | fprintf(js_include_file,"\n/* begin function 33 read_canvas%d() */\n\ |
||
7261 | read_canvas%d = function(){\ |
||
7262 | var reply = userdraw_x+'\\n'+userdraw_y;\ |
||
7263 | return reply;\ |
||
7264 | };\n\ |
||
7265 | /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
||
7266 | break; |
||
7267 | case 34: fprintf(js_include_file,"\ |
||
7268 | \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\ |
||
7269 | var read_canvas_images = function(){\ |
||
7270 | var prec = %d;\ |
||
7271 | var len = ext_drag_images.length;\ |
||
7272 | var reply = new Array(len);\ |
||
7273 | for(var p = 0 ; p < len ; p++){\ |
||
7274 | var img = ext_drag_images[p];\ |
||
7275 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
||
7276 | };\ |
||
7277 | return reply;\ |
||
7278 | };\n\ |
||
7279 | /* end function 20 read_canvas_images() */",reply_precision); |
||
7280 | break; |
||
7281 | |||
7614 | schaersvoo | 7282 | default: canvas_error("hmmm unknown replyformat...");break; |
7283 | } |
||
7284 | return; |
||
7285 | } |
||
7286 | |||
7287 | |||
8224 | bpr | 7288 | /* |
14066 | bpr | 7289 | add drawfunction: |
7614 | schaersvoo | 7290 | - functions used by userdraw_primitives (circle,rect,path,triangle...) |
14078 | bpr | 7291 | - things not covered by the drag&drop library (static objects like parallel, lattice, gridfill, imagefill) |
7614 | schaersvoo | 7292 | - grid / mathml |
7293 | - will not scale or zoom in |
||
7294 | - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill |
||
8224 | bpr | 7295 | - is printed directly into 'js_include_file' |
7614 | schaersvoo | 7296 | */ |
7297 | |||
11021 | schaersvoo | 7298 | void add_javascript_function(int js_function[],int canvas_root_id){ |
7614 | schaersvoo | 7299 | int i; |
7300 | for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){ |
||
11017 | schaersvoo | 7301 | if( js_function[i] == 1){ |
7614 | schaersvoo | 7302 | switch(i){ |
14546 | schaersvoo | 7303 | case ADD_JS_ROTATE_MOUSE: |
14549 | schaersvoo | 7304 | /* identify mouse coordinates on rotated objects |
7305 | used for command rotate : faster than transform matrix */ |
||
14546 | schaersvoo | 7306 | fprintf(js_include_file,"\n/* begin rotate mouse */\n\ |
7307 | function rotate_mouse(mx,my,obj){\ |
||
7308 | if( typeof(obj.angle) === 'undefined' ){console.log('rotate_mouse() angle undefined');return {x:mx,y:my};};\ |
||
7309 | var cos = Math.cos(obj.angle);\ |
||
7310 | var sin = Math.sin(obj.angle);\ |
||
7311 | var xc = obj.rotation_center[0];\ |
||
7312 | var yc = obj.rotation_center[1];\ |
||
14548 | schaersvoo | 7313 | var x_r = parseInt((cos * (mx - xc)) + (sin * (my - yc)) + xc);\ |
7314 | var y_r = parseInt((cos * (my - yc)) - (sin * (mx - xc)) + yc);\ |
||
14546 | schaersvoo | 7315 | return {x:x_r,y:y_r};\ |
7316 | };"); |
||
7317 | break; |
||
14548 | schaersvoo | 7318 | case ADD_JS_TRANSFORM_MOUSE: |
14549 | schaersvoo | 7319 | /* identify mouse coordinates on transformed objects using command affine */ |
14548 | schaersvoo | 7320 | fprintf(js_include_file,"\n/* begin translate mouse */\n\ |
7321 | function transform_mouse(mx,my,obj){\ |
||
7322 | if( typeof(obj.affine_matrix) === 'undefined' ){console.log('translate_mouse() affine_matrix undefined');return {x:mx,y:my};};\ |
||
7323 | var m = obj.affine_matrix;\ |
||
7324 | var d = 1/(m[0]*m[3]-m[1]*m[2]);\ |
||
7325 | var im = [ m[3]*d, -m[1]*d,-m[2]*d,m[0]*d,d*(m[2]*m[5]-m[3]*m[4]),d*(m[1]*m[4]-m[0]*m[5]) ];\ |
||
7326 | return { x:mx*im[0]+my*im[2]+im[4], y:mx*im[1]+my*im[3]+im[5] };};" |
||
7327 | ); |
||
14562 | bpr | 7328 | |
14548 | schaersvoo | 7329 | break; |
11026 | bpr | 7330 | case JS_FIND_ANGLE: |
11025 | schaersvoo | 7331 | fprintf(js_include_file,"\n\ |
13970 | obado | 7332 | /* function find_angle() */\n\ |
14044 | schaersvoo | 7333 | function find_angle(xc,yc,x1,y1){var dx = x1 - xc;var dy = yc - y1;return Math.atan2(dx,dy);};"); |
11017 | schaersvoo | 7334 | break; |
8448 | schaersvoo | 7335 | case DRAW_EXTERNAL_IMAGE: |
14066 | bpr | 7336 | /* |
13969 | schaersvoo | 7337 | the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it |
7338 | only drag_xy ! |
||
7339 | snaptogrid | xsnaptogrid | ysnaptogrid works |
||
7340 | 14/5/2019 |
||
7341 | on heavy styled wims (unice.fr etc problems with mouse? |
||
7342 | now uniform method of retreiving mouse coordinates dragstuff.getMouse() |
||
8448 | schaersvoo | 7343 | */ |
13970 | obado | 7344 | fprintf(js_include_file,"\n/* drag external images */\n\ |
7653 | schaersvoo | 7345 | var external_ctx = external_canvas.getContext(\"2d\");\ |
7346 | var external_canvas_rect = external_canvas.getBoundingClientRect();\ |
||
7347 | canvas_div.addEventListener(\"mousedown\",setxy,false);\ |
||
7348 | canvas_div.addEventListener(\"mouseup\",dragstop,false);\ |
||
7349 | canvas_div.addEventListener(\"mousemove\",dragxy,false);\ |
||
7350 | var selected_image = null;\ |
||
7351 | var ext_image_cnt = 0;\ |
||
7352 | var ext_drag_images = new Array();\ |
||
14038 | schaersvoo | 7353 | var ext_centered = 0;\ |
14044 | schaersvoo | 7354 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\ |
14038 | schaersvoo | 7355 | ext_centered = centered;\ |
7653 | schaersvoo | 7356 | ext_image_cnt = idx;\ |
8448 | schaersvoo | 7357 | if(draggable == 1 ){\ |
7358 | reply[click_cnt] = 0;\ |
||
7359 | };\ |
||
7653 | schaersvoo | 7360 | var image = new Image();\ |
7361 | image.src = URL;\ |
||
7362 | image.onload = function(){\ |
||
8448 | schaersvoo | 7363 | if( sx < 1 ){ sx = 0; };\ |
7364 | if( sy < 1 ){ sy = 0; };\ |
||
7365 | if( swidth < 1 ){swidth = image.width;};\ |
||
7366 | if( sheight < 1 ){sheight = image.height;};\ |
||
7367 | if( width < 1 ){width = image.width;};\ |
||
7368 | if( height < 1 ){height = image.height;};\ |
||
7369 | if( resizable == 0 ){\ |
||
7370 | if( swidth > image.width ){ swidth = image.width; };\ |
||
7371 | if( sheight > image.height){ sheight = image.height;};\ |
||
7372 | if( width > image.width ){ width = image.width; };\ |
||
7373 | if( height > image.height){ height = image.height;};\ |
||
7374 | };\ |
||
14044 | schaersvoo | 7375 | var img = new Array(12);\ |
7653 | schaersvoo | 7376 | img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\ |
14044 | schaersvoo | 7377 | img[8] = width;img[9] = height;img[10] = click_cnt;img[11] = use_snap;\ |
14062 | schaersvoo | 7378 | img[6] = x0;img[7] = y0;\ |
7653 | schaersvoo | 7379 | ext_drag_images[idx] = img;\ |
14062 | schaersvoo | 7380 | if(centered == 4){\ |
7381 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],parseInt(img[6] - 0.5*img[8]),parseInt(img[7] - 0.5*img[9]),img[8],img[9]);\ |
||
7382 | }else{\ |
||
7383 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
7384 | };\ |
||
7653 | schaersvoo | 7385 | };\ |
7386 | };\ |
||
7387 | function dragstop(evt){\ |
||
7388 | selected_image = null;return;\ |
||
7389 | };\ |
||
7390 | function dragxy(evt){\ |
||
7391 | if( selected_image != null ){\ |
||
14044 | schaersvoo | 7392 | var s_img = ext_drag_images[selected_image];\ |
13969 | schaersvoo | 7393 | var mouse = dragstuff.getMouse(evt,external_canvas);\ |
14044 | schaersvoo | 7394 | var xy = multisnap_check(mouse.x,mouse.y,s_img[11]);\ |
14201 | schaersvoo | 7395 | xy[0] = parseInt(xy[0] - 0.5*s_img[8]);\ |
7396 | xy[1] = parseInt(xy[1] - 0.5*s_img[9]);\ |
||
14062 | schaersvoo | 7397 | s_img[6] = xy[0];s_img[7] = xy[1];\ |
7653 | schaersvoo | 7398 | ext_drag_images[selected_image] = s_img;\ |
7399 | external_ctx.clearRect(0,0,xsize,ysize);\ |
||
7400 | for(var i = 0; i <= ext_image_cnt ; i++){\ |
||
7401 | var img = ext_drag_images[i];\ |
||
14201 | schaersvoo | 7402 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
7653 | schaersvoo | 7403 | };\ |
7404 | };\ |
||
7405 | };\ |
||
7406 | function setxy(evt){\ |
||
7407 | if( ! selected_image && evt.which == 1 ){\ |
||
13969 | schaersvoo | 7408 | var mouse = dragstuff.getMouse(evt,external_canvas);\ |
7409 | var xm = mouse.x;\ |
||
7410 | var ym = mouse.y;\ |
||
14062 | schaersvoo | 7411 | var img;var xmarge;var ymarge;\ |
7653 | schaersvoo | 7412 | for(var p = 0 ; p <= ext_image_cnt ; p++){\ |
8448 | schaersvoo | 7413 | if( ext_drag_images[p] ){\ |
7414 | img = ext_drag_images[p];\ |
||
7415 | if( img[0] != 0 ){\ |
||
14062 | schaersvoo | 7416 | xmarge = 0.5*img[8];ymarge = 0.5*img[9];\ |
7417 | if( xm > img[6] - xmarge && xm < img[6] + img[8]){\ |
||
7418 | if( ym > img[7] - ymarge && ym < img[7] + img[9]){\ |
||
8448 | schaersvoo | 7419 | if( img[0] == 1){\ |
7420 | if( reply[img[10]] == 1 ){\ |
||
7421 | reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\ |
||
7422 | }\ |
||
7423 | else\ |
||
7424 | {\ |
||
7425 | reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\ |
||
7426 | };\ |
||
13969 | schaersvoo | 7427 | external_ctx.lineWidth = 4;\ |
8448 | schaersvoo | 7428 | external_ctx.beginPath();\ |
7429 | external_ctx.rect(img[6],img[7],img[8],img[9]);\ |
||
7430 | external_ctx.closePath();\ |
||
7431 | external_ctx.stroke();\ |
||
7432 | return;\ |
||
7433 | }\ |
||
7434 | else\ |
||
7435 | {\ |
||
7436 | img[6] = xm;\ |
||
7437 | img[7] = ym;\ |
||
7438 | ext_drag_images[p] = img;\ |
||
7439 | selected_image = p;\ |
||
7440 | dragxy(evt);\ |
||
7441 | };\ |
||
7442 | };\ |
||
7653 | schaersvoo | 7443 | };\ |
7444 | };\ |
||
7445 | };\ |
||
7446 | };\ |
||
7447 | }\ |
||
7448 | else\ |
||
7449 | {\ |
||
7450 | selected_image = null;\ |
||
7451 | };\ |
||
8448 | schaersvoo | 7452 | };"); |
7614 | schaersvoo | 7453 | break; |
8370 | schaersvoo | 7454 | case DRAW_BEZIER: |
13970 | obado | 7455 | fprintf(js_include_file,"\n/* draw bezier curve */\n\ |
11874 | schaersvoo | 7456 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8370 | schaersvoo | 7457 | 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){\ |
7458 | var obj;\ |
||
7459 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7460 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7461 | }\ |
||
7462 | else\ |
||
7463 | {\ |
||
7464 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7465 | };\ |
||
7466 | var ctx = obj.getContext(\"2d\");\ |
||
7467 | ctx.save();\ |
||
7468 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7469 | ctx.lineWidth = linewidth;\ |
||
11088 | schaersvoo | 7470 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8370 | schaersvoo | 7471 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7472 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
||
7473 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7474 | ctx.beginPath();\ |
||
7475 | ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\ |
||
7476 | 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]));\ |
||
11874 | schaersvoo | 7477 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 7478 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
8370 | schaersvoo | 7479 | ctx.stroke();\ |
7480 | ctx.restore();\ |
||
7481 | };\n",canvas_root_id,canvas_root_id,canvas_root_id); |
||
7482 | break; |
||
13829 | bpr | 7483 | |
7614 | schaersvoo | 7484 | case DRAW_GRIDFILL:/* not used for userdraw */ |
13970 | obado | 7485 | fprintf(js_include_file,"\n/* draw gridfill */\n\ |
11827 | schaersvoo | 7486 | var grid_fill_pattern;\ |
11823 | schaersvoo | 7487 | var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize,use_userdraw){\ |
11820 | schaersvoo | 7488 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
7489 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
14208 | schaersvoo | 7490 | var fc = %d+canvas_type;\ |
11820 | schaersvoo | 7491 | fill_canvas_no.push(fc);\ |
14208 | schaersvoo | 7492 | var obj = create_canvas%d(fc,xsize,ysize);\ |
7493 | var ctx = obj.getContext('2d');\ |
||
7614 | schaersvoo | 7494 | var x,y;\ |
14208 | schaersvoo | 7495 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
7496 | ctx.rect(0,0,xsize,ysize);\ |
||
7497 | ctx.fill();\ |
||
11820 | schaersvoo | 7498 | ctx.lineWidth = linewidth;\ |
7499 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
||
7500 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7501 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7502 | ctx.beginPath();\ |
||
7503 | ctx.moveTo(x,0);\ |
||
7504 | ctx.lineTo(x,ysize);\ |
||
7505 | ctx.closePath();\ |
||
7506 | ctx.stroke();\ |
||
7614 | schaersvoo | 7507 | };\ |
11820 | schaersvoo | 7508 | for( y = 0 ; y < ysize; y = y + dy ){\ |
7509 | ctx.beginPath();\ |
||
7510 | ctx.moveTo(0,y);\ |
||
7511 | ctx.lineTo(xsize,y);\ |
||
7512 | ctx.closePath();\ |
||
7513 | ctx.stroke();\ |
||
7614 | schaersvoo | 7514 | };\ |
11823 | schaersvoo | 7515 | if( use_userdraw ){\ |
7516 | grid_fill_pattern = ctx;\ |
||
7517 | }\ |
||
7518 | else\ |
||
7519 | {\ |
||
11874 | schaersvoo | 7520 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};return;\ |
7521 | };",canvas_root_id,canvas_root_id); |
||
7614 | schaersvoo | 7522 | break; |
8224 | bpr | 7523 | |
7614 | schaersvoo | 7524 | case DRAW_IMAGEFILL:/* not used for userdraw */ |
13970 | obado | 7525 | fprintf(js_include_file,"\n/* draw imagefill */\n\ |
11874 | schaersvoo | 7526 | var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize,use_userdraw,use_scaling){\ |
11854 | schaersvoo | 7527 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
7528 | var fc = %d+canvas_type;\ |
||
7529 | fill_canvas_no.push(fc);\ |
||
7530 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7531 | var ctx = obj.getContext('2d');\ |
||
7532 | var img = new Image();\ |
||
7533 | img.src = URL;\ |
||
11857 | schaersvoo | 7534 | obj.style.visibility = 'hidden';\ |
7535 | img.onload = function(){\ |
||
11874 | schaersvoo | 7536 | if( use_scaling == 1 ){\ |
7537 | ctx.drawImage(img,x0,y0,xsize,ysize);\ |
||
7538 | }else{\ |
||
7539 | var w0 = img.width;var h0 = img.height;var w;var h;\ |
||
7540 | for( w = x0; w < xsize ; w = w + w0 ){\ |
||
7541 | for( h = y0; h < ysize; h = h + h0){\ |
||
7542 | ctx.drawImage(img,w,h,w0,h0);\ |
||
7543 | };\ |
||
7544 | };\ |
||
7545 | };\ |
||
11857 | schaersvoo | 7546 | if( use_userdraw ){\ |
7547 | image_pattern = ctx;\ |
||
7548 | }\ |
||
7549 | else\ |
||
7550 | {\ |
||
7551 | setTimeout(function(){ filltoborder( x0,y0,'red','red',canvas_type,true,ctx); },500);\ |
||
7552 | };\ |
||
7553 | };\ |
||
11854 | schaersvoo | 7554 | };",canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7555 | break; |
8224 | bpr | 7556 | |
7614 | schaersvoo | 7557 | case DRAW_DOTFILL:/* not used for userdraw */ |
13970 | obado | 7558 | fprintf(js_include_file,"\n/* draw dotfill */\n\ |
11827 | schaersvoo | 7559 | var dot_fill_pattern;\ |
11823 | schaersvoo | 7560 | var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize,use_userdraw){\n\ |
11820 | schaersvoo | 7561 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
11818 | schaersvoo | 7562 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
11820 | schaersvoo | 7563 | var fc = %d+canvas_type;\ |
11818 | schaersvoo | 7564 | fill_canvas_no.push(fc);\ |
11820 | schaersvoo | 7565 | var obj = create_canvas%d(fc,xsize,ysize);\ |
7566 | var ctx = obj.getContext('2d');\ |
||
7567 | var x,y;\ |
||
7568 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
||
7569 | ctx.rect(0,0,xsize,ysize);\ |
||
7570 | ctx.fill();\ |
||
7571 | ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7572 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7573 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7574 | for( y = 0 ; y < ysize ; y = y + dy ){\ |
||
7575 | ctx.beginPath();\ |
||
7576 | ctx.arc(x,y,radius,0,2*Math.PI,false);\ |
||
7577 | ctx.closePath();\ |
||
7578 | ctx.fill();\ |
||
7579 | };\ |
||
7580 | };\ |
||
11823 | schaersvoo | 7581 | if( use_userdraw ){\ |
11824 | schaersvoo | 7582 | dot_fill_pattern = ctx;\ |
11823 | schaersvoo | 7583 | }\ |
7584 | else\ |
||
7585 | {\ |
||
11874 | schaersvoo | 7586 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\ |
7587 | };\ |
||
7588 | return;\ |
||
7589 | };",canvas_root_id,canvas_root_id); |
||
7614 | schaersvoo | 7590 | break; |
7645 | schaersvoo | 7591 | |
11830 | schaersvoo | 7592 | case DRAW_TEXTFILL:/* not used for userdraw */ |
13970 | obado | 7593 | fprintf(js_include_file,"\n/* draw textfill */\n\ |
11830 | schaersvoo | 7594 | var text_fill_pattern;\ |
7595 | var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw){\n\ |
||
7596 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
7597 | var fc = %d+canvas_type;\ |
||
7598 | fill_canvas_no.push(fc);\ |
||
7599 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7600 | var ctx = obj.getContext('2d');\ |
||
7601 | ctx.font = fontfamily;\ |
||
11832 | schaersvoo | 7602 | var dx = (ctx.measureText(txt)).width;\ |
11830 | schaersvoo | 7603 | var dy = parseInt(fontfamily)+2;\ |
7604 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
||
7605 | ctx.rect(0,0,xsize,ysize);\ |
||
7606 | ctx.fill();\ |
||
7607 | ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7608 | for(var x = 0 ; x < xsize ; x = x + dx ){\ |
||
7609 | for(var y = 0 ; y < ysize ; y = y + dy ){\ |
||
7610 | ctx.fillText(txt,x,y);\ |
||
7611 | };\ |
||
7612 | };\ |
||
7613 | if( use_userdraw ){\ |
||
7614 | text_fill_pattern = ctx;\ |
||
7615 | }\ |
||
7616 | else\ |
||
7617 | {\ |
||
7618 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\ |
||
7619 | return;};",canvas_root_id,canvas_root_id); |
||
7620 | break; |
||
7621 | |||
7647 | schaersvoo | 7622 | case DRAW_DIAMONDFILL:/* not used for userdraw */ |
13970 | obado | 7623 | fprintf(js_include_file,"\n/* draw hatch fill */\n\ |
11827 | schaersvoo | 7624 | var diamond_fill_pattern;\ |
11823 | schaersvoo | 7625 | var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\ |
11820 | schaersvoo | 7626 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
7627 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
7628 | var fc = %d+canvas_type;\ |
||
7629 | fill_canvas_no.push(fc);\ |
||
7630 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7631 | var ctx = obj.getContext('2d');\ |
||
7614 | schaersvoo | 7632 | var x;\ |
7633 | var y;\ |
||
7634 | ctx.lineWidth = linewidth;\ |
||
11820 | schaersvoo | 7635 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
7636 | ctx.rect(0,0,xsize,ysize);\ |
||
7637 | ctx.fill();\ |
||
11088 | schaersvoo | 7638 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
11820 | schaersvoo | 7639 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
7614 | schaersvoo | 7640 | y = ysize;\ |
11820 | schaersvoo | 7641 | ctx.beginPath();\ |
7642 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7643 | ctx.moveTo(x,0);\ |
||
7614 | schaersvoo | 7644 | ctx.lineTo(xsize,y);\ |
7645 | y = y - dy;\ |
||
7646 | };\ |
||
11820 | schaersvoo | 7647 | y=0;\ |
7614 | schaersvoo | 7648 | for( x = xsize ; x > 0 ; x = x - dx){\ |
7649 | ctx.moveTo(x,ysize);\ |
||
11820 | schaersvoo | 7650 | ctx.lineTo(0,y);\ |
7614 | schaersvoo | 7651 | y = y + dy;\ |
7652 | };\ |
||
11820 | schaersvoo | 7653 | y = 0;\ |
7654 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7655 | ctx.moveTo(x,0);\ |
||
7656 | ctx.lineTo(0,y);\ |
||
7657 | y = y + dy;\ |
||
7658 | };\ |
||
7659 | y = 0;\ |
||
7660 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7614 | schaersvoo | 7661 | ctx.moveTo(xsize,y);\ |
7662 | ctx.lineTo(x,ysize);\ |
||
11820 | schaersvoo | 7663 | y = y + dy;\ |
7614 | schaersvoo | 7664 | };\ |
11820 | schaersvoo | 7665 | ctx.closePath();\ |
7614 | schaersvoo | 7666 | ctx.stroke();\ |
11823 | schaersvoo | 7667 | if( use_userdraw ){\ |
11827 | schaersvoo | 7668 | diamond_fill_pattern = ctx;\ |
11823 | schaersvoo | 7669 | }\ |
7670 | else\ |
||
7671 | {\ |
||
7672 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\ |
||
7614 | schaersvoo | 7673 | return;\ |
11820 | schaersvoo | 7674 | }",canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7675 | break; |
8224 | bpr | 7676 | |
7647 | schaersvoo | 7677 | case DRAW_HATCHFILL:/* not used for userdraw */ |
13970 | obado | 7678 | fprintf(js_include_file,"\n/* draw hatch fill */\n\ |
11827 | schaersvoo | 7679 | var hatch_fill_pattern;\ |
11823 | schaersvoo | 7680 | var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\ |
11820 | schaersvoo | 7681 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
7682 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
7683 | var fc = %d+canvas_type;\ |
||
7684 | fill_canvas_no.push(fc);\ |
||
7685 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7686 | var ctx = obj.getContext('2d');\ |
||
7687 | var x,y;\ |
||
7688 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
||
7689 | ctx.rect(0,0,xsize,ysize);\ |
||
7690 | ctx.fill();\ |
||
7691 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7647 | schaersvoo | 7692 | ctx.lineWidth = linewidth;\ |
11088 | schaersvoo | 7693 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7647 | schaersvoo | 7694 | y = ysize;\ |
11820 | schaersvoo | 7695 | ctx.beginPath();\ |
7696 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7697 | ctx.moveTo(x,0);\ |
||
7647 | schaersvoo | 7698 | ctx.lineTo(xsize,y);\ |
7699 | y = y - dy;\ |
||
7700 | };\ |
||
11820 | schaersvoo | 7701 | y = 0;\ |
7647 | schaersvoo | 7702 | for( x = xsize ; x >= dx ; x = x - dx){\ |
7703 | ctx.moveTo(x,ysize);\ |
||
11820 | schaersvoo | 7704 | ctx.lineTo(0,y);\ |
7647 | schaersvoo | 7705 | y = y + dy;\ |
7706 | };\ |
||
11820 | schaersvoo | 7707 | ctx.closePath();\ |
7647 | schaersvoo | 7708 | ctx.stroke();\ |
11823 | schaersvoo | 7709 | if( use_userdraw ){\ |
7710 | hatch_fill_pattern = ctx;\ |
||
7711 | }\ |
||
7712 | else\ |
||
7713 | {\ |
||
7714 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\ |
||
7647 | schaersvoo | 7715 | return;\ |
11820 | schaersvoo | 7716 | };",canvas_root_id,canvas_root_id); |
7647 | schaersvoo | 7717 | break; |
7614 | schaersvoo | 7718 | case DRAW_CIRCLES:/* used for userdraw */ |
13970 | obado | 7719 | fprintf(js_include_file,"\n/* draw circles */\n\ |
11874 | schaersvoo | 7720 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7721 | 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 | 7722 | ctx.save();\ |
8071 | schaersvoo | 7723 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7724 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7725 | ctx.lineWidth = line_width;\ |
||
11839 | schaersvoo | 7726 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
14208 | schaersvoo | 7727 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
11874 | schaersvoo | 7728 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 7729 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
11088 | schaersvoo | 7730 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7731 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
7732 | ctx.beginPath();\ |
||
7733 | ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\ |
||
7734 | ctx.closePath();\ |
||
11839 | schaersvoo | 7735 | if(use_filled != 0 ){ctx.fill();};\ |
7614 | schaersvoo | 7736 | ctx.stroke();\ |
7737 | }\ |
||
7738 | ctx.restore();\ |
||
7739 | return;\ |
||
7653 | schaersvoo | 7740 | };"); |
7614 | schaersvoo | 7741 | break; |
14066 | bpr | 7742 | case DRAW_POLYLINE:/* user for userdraw: draw lines through points */ |
13970 | obado | 7743 | fprintf(js_include_file,"\n/* draw polyline */\n\ |
11874 | schaersvoo | 7744 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7745 | 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 | 7746 | ctx.save();\ |
8071 | schaersvoo | 7747 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7663 | schaersvoo | 7748 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7749 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7750 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7663 | schaersvoo | 7751 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7752 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7753 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7754 | ctx.beginPath();\ |
||
7755 | for(var p = 0 ; p < x_points.length-1 ; p++ ){\ |
||
7756 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
7757 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
7758 | }\ |
||
7759 | ctx.closePath();\ |
||
7760 | ctx.stroke();\ |
||
7761 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
7762 | ctx.beginPath();\ |
||
7763 | ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\ |
||
7764 | ctx.closePath();ctx.fill();ctx.stroke();\ |
||
7765 | };\ |
||
7766 | ctx.restore();\ |
||
7767 | return;\ |
||
7768 | };"); |
||
7769 | break; |
||
8224 | bpr | 7770 | |
7614 | schaersvoo | 7771 | case DRAW_SEGMENTS:/* used for userdraw */ |
13970 | obado | 7772 | fprintf(js_include_file,"\n/* draw segments */\n\ |
8105 | schaersvoo | 7773 | 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 | 7774 | ctx.save();\ |
8071 | schaersvoo | 7775 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7776 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7777 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7778 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7779 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7780 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7781 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
7782 | ctx.beginPath();\ |
||
7783 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
7784 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
7785 | ctx.closePath();\ |
||
7786 | ctx.stroke();\ |
||
7787 | }\ |
||
7788 | ctx.restore();\ |
||
7789 | return;\ |
||
7790 | };"); |
||
7791 | break; |
||
8224 | bpr | 7792 | |
7614 | schaersvoo | 7793 | case DRAW_LINES:/* used for userdraw */ |
13970 | obado | 7794 | fprintf(js_include_file,"\n/* draw lines */\n\ |
7614 | schaersvoo | 7795 | function calc_line(x1,x2,y1,y2){\ |
7796 | var marge = 2;\ |
||
7797 | if(x1 < x2+marge && x1>x2-marge){\ |
||
7798 | return [x1,0,x1,ysize];\ |
||
7799 | };\ |
||
7800 | if(y1 < y2+marge && y1>y2-marge){\ |
||
7801 | return [0,y1,xsize,y1];\ |
||
7802 | };\ |
||
7803 | var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\ |
||
7804 | var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\ |
||
7805 | return [0,Y1,xsize,Y2];\ |
||
7806 | };\ |
||
8105 | schaersvoo | 7807 | 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 | 7808 | ctx.save();\ |
7809 | var line = new Array(4);\ |
||
8071 | schaersvoo | 7810 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7811 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7812 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7813 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7814 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7815 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7816 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
7817 | line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\ |
||
7818 | ctx.beginPath();\ |
||
7819 | ctx.moveTo(line[0],line[1]);\ |
||
7820 | ctx.lineTo(line[2],line[3]);\ |
||
7821 | ctx.closePath();\ |
||
7822 | ctx.stroke();\ |
||
7823 | }\ |
||
7824 | ctx.restore();\ |
||
7825 | return;\ |
||
7826 | };"); |
||
7827 | break; |
||
7828 | |||
8244 | schaersvoo | 7829 | case DRAW_DEMILINES:/* used for userdraw */ |
13970 | obado | 7830 | fprintf(js_include_file,"\n/* draw demilines */\n\ |
8244 | schaersvoo | 7831 | function find_inf_point(x1,y1,x2,y2){\ |
7832 | if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\ |
||
7833 | var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\ |
||
7834 | if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\ |
||
7835 | };\ |
||
7836 | 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){\ |
||
7837 | ctx.save();\ |
||
7838 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
||
7839 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
7840 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7841 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8244 | schaersvoo | 7842 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7843 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7844 | var pair = new Array(4);\ |
||
7845 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
7846 | pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\ |
||
7847 | ctx.beginPath();\ |
||
7848 | ctx.moveTo(pair[0],pair[1]);\ |
||
7849 | ctx.lineTo(pair[2],pair[3]);\ |
||
7850 | ctx.closePath();\ |
||
7851 | ctx.stroke();\ |
||
7852 | }\ |
||
7853 | ctx.restore();\ |
||
7854 | return;\ |
||
7855 | };"); |
||
7856 | break; |
||
7857 | |||
7614 | schaersvoo | 7858 | case DRAW_CROSSHAIRS:/* used for userdraw */ |
13970 | obado | 7859 | fprintf(js_include_file,"\n/* draw crosshairs */\n\ |
8105 | schaersvoo | 7860 | var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
12311 | schaersvoo | 7861 | ctx.save();\ |
8071 | schaersvoo | 7862 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7863 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7864 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7865 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7866 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7867 | var x1,x2,y1,y2;\ |
||
7868 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
7869 | x1 = x_points[p] - crosshair_size;\ |
||
7870 | x2 = x_points[p] + crosshair_size;\ |
||
7871 | y1 = y_points[p] - crosshair_size;\ |
||
7872 | y2 = y_points[p] + crosshair_size;\ |
||
7873 | ctx.beginPath();\ |
||
7874 | ctx.moveTo(x1,y1);\ |
||
7875 | ctx.lineTo(x2,y2);\ |
||
7876 | ctx.closePath();\ |
||
7877 | ctx.stroke();\ |
||
7878 | ctx.beginPath();\ |
||
7879 | ctx.moveTo(x2,y1);\ |
||
7880 | ctx.lineTo(x1,y2);\ |
||
7881 | ctx.closePath();\ |
||
7882 | ctx.stroke();\ |
||
7883 | }\ |
||
7884 | ctx.restore();\ |
||
7885 | return;\ |
||
7653 | schaersvoo | 7886 | };"); |
7614 | schaersvoo | 7887 | break; |
7888 | |||
7889 | case DRAW_RECTS:/* used for userdraw */ |
||
13970 | obado | 7890 | fprintf(js_include_file,"\n/* draw rects */\n\ |
11874 | schaersvoo | 7891 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7892 | 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){\ |
12000 | schaersvoo | 7893 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
7614 | schaersvoo | 7894 | ctx.save();\ |
8071 | schaersvoo | 7895 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7896 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7897 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7898 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8448 | schaersvoo | 7899 | ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\ |
7614 | schaersvoo | 7900 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\ |
11875 | schaersvoo | 7901 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7902 | for(var p = 0 ; p < x_points.length ; p = p + 2){\ |
7903 | ctx.beginPath();\ |
||
7904 | ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\ |
||
7905 | ctx.closePath();\ |
||
11839 | schaersvoo | 7906 | if(use_filled != 0 ){ctx.fill();}\ |
7614 | schaersvoo | 7907 | ctx.stroke();\ |
7908 | };\ |
||
7909 | ctx.restore();\ |
||
7910 | return;\ |
||
7653 | schaersvoo | 7911 | };"); |
7614 | schaersvoo | 7912 | break; |
7913 | |||
7914 | case DRAW_ROUNDRECTS:/* used for userdraw */ |
||
13970 | obado | 7915 | fprintf(js_include_file,"\n/* draw round rects */\n\ |
11874 | schaersvoo | 7916 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7917 | 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){\ |
12000 | schaersvoo | 7918 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
7614 | schaersvoo | 7919 | ctx.save();\ |
8071 | schaersvoo | 7920 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7921 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7922 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
9462 | schaersvoo | 7923 | ctx.lineWidth = line_width;\ |
11088 | schaersvoo | 7924 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
11875 | schaersvoo | 7925 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7926 | var x,y,w,h,r;\ |
7927 | for(var p = 0; p < x_points.length; p = p+2){\ |
||
7928 | 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);\ |
||
7929 | ctx.beginPath();ctx.moveTo(x + r, y);\ |
||
7930 | ctx.lineTo(x + w - r, y);\ |
||
7931 | ctx.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
7932 | ctx.lineTo(x + w, y + h - r);\ |
||
7933 | ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
7934 | ctx.lineTo(x + r, y + h);\ |
||
7935 | ctx.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
7936 | ctx.lineTo(x, y + r);\ |
||
7937 | ctx.quadraticCurveTo(x, y, x + r, y);\ |
||
7938 | ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\ |
||
7939 | ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
11839 | schaersvoo | 7940 | if( use_filled != 0 ){ctx.fill();};\ |
7614 | schaersvoo | 7941 | ctx.stroke();\ |
7942 | }\ |
||
7943 | ctx.restore();\ |
||
7653 | schaersvoo | 7944 | };"); |
8224 | bpr | 7945 | break; |
7614 | schaersvoo | 7946 | |
7947 | case DRAW_ELLIPSES:/* not used for userdraw */ |
||
13970 | obado | 7948 | fprintf(js_include_file,"\n/* draw ellipses */\n\ |
11874 | schaersvoo | 7949 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7950 | 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 | 7951 | var obj;\ |
7952 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7953 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7954 | }\ |
||
7955 | else\ |
||
7956 | {\ |
||
7957 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7958 | };\ |
||
7959 | var ctx = obj.getContext(\"2d\");\ |
||
7960 | ctx.save();\ |
||
8071 | schaersvoo | 7961 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7962 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
11875 | schaersvoo | 7963 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7964 | var cx,cy,ry,rx;\ |
7965 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7966 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7967 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7968 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7969 | for(var p=0;p< x_points.length;p = p+2){\ |
||
7970 | ctx.beginPath();\ |
||
7971 | cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\ |
||
7972 | ctx.translate(cx - rx, cy - ry);\ |
||
7973 | ctx.scale(rx, ry);\ |
||
7974 | ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\ |
||
11839 | schaersvoo | 7975 | if( use_filled != 0 ){ctx.fill();}\ |
7614 | schaersvoo | 7976 | ctx.stroke();\ |
7977 | };\ |
||
7978 | ctx.restore();\ |
||
7653 | schaersvoo | 7979 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7980 | break; |
7981 | |||
7982 | case DRAW_PATHS: /* used for userdraw */ |
||
13970 | obado | 7983 | fprintf(js_include_file,"\n/* draw paths */\n\ |
11874 | schaersvoo | 7984 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7985 | 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 | 7986 | ctx.save();\ |
8071 | schaersvoo | 7987 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7988 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7989 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7990 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7991 | ctx.lineJoin = \"round\";\ |
7992 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
11874 | schaersvoo | 7993 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 7994 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7995 | ctx.beginPath();\ |
7996 | ctx.moveTo(x_points[0],y_points[0]);\ |
||
7997 | for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\ |
||
7998 | if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\ |
||
7999 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
11839 | schaersvoo | 8000 | if(use_filled != 0){ctx.fill();}\ |
7614 | schaersvoo | 8001 | ctx.stroke();\ |
8002 | ctx.restore();\ |
||
8003 | return;\ |
||
8004 | };"); |
||
8224 | bpr | 8005 | |
7614 | schaersvoo | 8006 | break; |
8007 | case DRAW_ARROWS:/* used for userdraw */ |
||
13970 | obado | 8008 | fprintf(js_include_file,"\n/* draw arrows */\n\ |
8105 | schaersvoo | 8009 | 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 | 8010 | ctx.save();\ |
8071 | schaersvoo | 8011 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 8012 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
8013 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8014 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8015 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 8016 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 8017 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
8018 | ctx.lineCap = \"round\";\ |
||
8019 | var x1,y1,x2,y2,dx,dy,len;\ |
||
8020 | for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\ |
||
7874 | schaersvoo | 8021 | ctx.save();\ |
7614 | schaersvoo | 8022 | x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\ |
8023 | len = Math.sqrt(dx*dx+dy*dy);\ |
||
8024 | ctx.translate(x2,y2);\ |
||
8025 | ctx.rotate(Math.atan2(dy,dx));\ |
||
8026 | ctx.lineCap = \"round\";\ |
||
8027 | ctx.beginPath();\ |
||
8028 | ctx.moveTo(0,0);\ |
||
8029 | ctx.lineTo(-len,0);\ |
||
8030 | ctx.closePath();\ |
||
8031 | ctx.stroke();\ |
||
8032 | ctx.beginPath();\ |
||
8033 | ctx.moveTo(0,0);\ |
||
8034 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
8035 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
8036 | ctx.closePath();\ |
||
8037 | ctx.fill();\ |
||
7874 | schaersvoo | 8038 | ctx.restore();\ |
7614 | schaersvoo | 8039 | if( type == 2 ){\ |
8040 | ctx.save();\ |
||
8041 | ctx.translate(x1,y1);\ |
||
8042 | ctx.rotate(Math.atan2(-dy,-dx));\ |
||
8043 | ctx.beginPath();\ |
||
8044 | ctx.moveTo(0,0);\ |
||
8347 | schaersvoo | 8045 | ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\ |
8046 | ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\ |
||
7614 | schaersvoo | 8047 | ctx.closePath();\ |
8048 | ctx.stroke();\ |
||
8049 | ctx.fill();\ |
||
7874 | schaersvoo | 8050 | ctx.restore();\ |
8379 | schaersvoo | 8051 | };\ |
8052 | };\ |
||
7614 | schaersvoo | 8053 | ctx.restore();\ |
8054 | return;\ |
||
7653 | schaersvoo | 8055 | };"); |
7614 | schaersvoo | 8056 | break; |
8057 | |||
8058 | case DRAW_VIDEO:/* not used for userdraw */ |
||
13970 | obado | 8059 | fprintf(js_include_file,"\n/* draw video */\n\ |
8105 | schaersvoo | 8060 | var draw_video = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 8061 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
8062 | var video_div = document.createElement(\"div\");\ |
||
8063 | canvas_div.appendChild(video_div);\ |
||
8064 | video_div.style.position = \"absolute\";\ |
||
8065 | video_div.style.left = x+\"px\";\ |
||
8066 | video_div.style.top = y+\"px\";\ |
||
8067 | video_div.style.width = w+\"px\";\ |
||
8068 | video_div.style.height = h+\"px\";\ |
||
8069 | var video = document.createElement(\"video\");\ |
||
8070 | video_div.appendChild(video);\ |
||
8071 | video.style.width = w+\"px\";\ |
||
8072 | video.style.height = h+\"px\";\ |
||
8073 | video.autobuffer = true;\ |
||
8074 | video.controls = true;video.autoplay = false;\ |
||
8075 | var src = document.createElement(\"source\");\ |
||
8076 | src.type = \"video/mp4\";\ |
||
8077 | src.src = URL;\ |
||
8078 | video.appendChild(src);\ |
||
8079 | video.load();\ |
||
8080 | return;\ |
||
8224 | bpr | 8081 | };"); |
7614 | schaersvoo | 8082 | break; |
8224 | bpr | 8083 | |
7614 | schaersvoo | 8084 | case DRAW_AUDIO:/* not used for userdraw */ |
13970 | obado | 8085 | fprintf(js_include_file,"\n/* draw audio */\n\ |
8105 | schaersvoo | 8086 | var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\ |
7614 | schaersvoo | 8087 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
8088 | var audio_div = document.createElement(\"div\");\ |
||
8089 | canvas_div.appendChild(audio_div);\ |
||
8090 | audio_div.style.position = \"absolute\";\ |
||
8091 | audio_div.style.left = x+\"px\";\ |
||
8092 | audio_div.style.top = y+\"px\";\ |
||
8093 | audio_div.style.width = w+\"px\";\ |
||
8094 | audio_div.style.height = h+\"px\";\ |
||
8095 | var audio = document.createElement(\"audio\");\ |
||
8096 | audio_div.appendChild(audio);\ |
||
8097 | audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\ |
||
8098 | audio.autobuffer = true;\ |
||
8379 | schaersvoo | 8099 | if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\ |
8100 | if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\ |
||
7614 | schaersvoo | 8101 | var src1 = document.createElement(\"source\");\ |
8102 | src1.type = \"audio/ogg\";\ |
||
8103 | src1.src = URL1;\ |
||
8104 | audio.appendChild(src1);\ |
||
8105 | var src2 = document.createElement(\"source\");\ |
||
8106 | src2.type = \"audio/mpeg\";\ |
||
8107 | src2.src = URL2;\ |
||
8108 | audio.appendChild(src2);\ |
||
8109 | audio.load();\ |
||
8110 | return;\ |
||
7653 | schaersvoo | 8111 | };"); |
7614 | schaersvoo | 8112 | break; |
8224 | bpr | 8113 | |
7614 | schaersvoo | 8114 | case DRAW_HTTP:/* not used for userdraw */ |
13970 | obado | 8115 | fprintf(js_include_file,"\n/* draw http */\n\ |
8105 | schaersvoo | 8116 | var draw_http = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 8117 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
8118 | var http_div = document.createElement(\"div\");\ |
||
8119 | var iframe = document.createElement(\"iframe\");\ |
||
8120 | canvas_div.appendChild(http_div);\ |
||
8121 | http_div.appendChild(iframe);\ |
||
8122 | iframe.src = URL;\ |
||
8123 | iframe.setAttribute(\"width\",w);\ |
||
8124 | iframe.setAttribute(\"height\",h);\ |
||
8125 | return;\ |
||
7653 | schaersvoo | 8126 | };"); |
7614 | schaersvoo | 8127 | break; |
8224 | bpr | 8128 | |
13829 | bpr | 8129 | case DRAW_XML: /* |
14066 | bpr | 8130 | onclick=1: click |
14062 | schaersvoo | 8131 | onclick=2 drag ==> always centered (use_offset=4) |
11238 | schaersvoo | 8132 | xy:drag_type = 0; |
8133 | x: drag_type = 1; |
||
8134 | y: drag_type = 2; |
||
8135 | */ |
||
8136 | |||
13970 | obado | 8137 | fprintf(js_include_file,"\n/* draw xml */\n\ |
14044 | schaersvoo | 8138 | var draw_xml = function(canvas_root_id,x,y,mathml,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,centered,use_snap){\ |
7614 | schaersvoo | 8139 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
8140 | var xml_div = document.createElement(\"div\");\ |
||
8141 | canvas_div.appendChild(xml_div);\ |
||
8142 | xml_div.innerHTML = mathml;\ |
||
14038 | schaersvoo | 8143 | xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\ |
8144 | var factor = 1;\ |
||
8145 | if( centered > 0 ){ factor = 0.5;};\ |
||
8146 | var xml_div_width = factor*(parseInt(window.getComputedStyle(xml_div).width , 10));\ |
||
8147 | var xml_div_height = factor*(parseInt(window.getComputedStyle(xml_div).height ,10));\ |
||
8379 | schaersvoo | 8148 | xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11745 | schaersvoo | 8149 | var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11756 | schaersvoo | 8150 | var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
8151 | var no_color = \"rgba(255,255,255,0)\";\ |
||
11745 | schaersvoo | 8152 | var dragging = false;\ |
11747 | schaersvoo | 8153 | if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\ |
8154 | if( onclick == 1 ){reply[click_cnt] = 0;};\ |
||
8155 | if( onclick == 2 ){\ |
||
8156 | xml_div.onclick = function(){\ |
||
11756 | schaersvoo | 8157 | canvas_div.onclick = function(evt){if(dragging){dragging = false;xml_div.style.color = color_org; xml_div.style.backgroundColor = no_color;}else{dragging = true;xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;};};\ |
11747 | schaersvoo | 8158 | canvas_div.onmousemove = function(evt){\ |
8159 | if(!dragging){return;};\ |
||
8160 | var x1;var y1;\ |
||
8161 | var mouse = dragstuff.getMouse(evt,xml_div);\ |
||
14044 | schaersvoo | 8162 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
11747 | schaersvoo | 8163 | switch(drag_type){\ |
14044 | schaersvoo | 8164 | case 0: x1 = xy[0]-xml_div_width;y1=xy[1]-xml_div_height;break;\ |
8165 | case 1: x1 = xy[0]-xml_div_width;y1 = y;break;\ |
||
8166 | case 2: x1 = x;y1 = xy[1]-xml_div_height;break;\ |
||
8167 | default:x1 = xy[0];y1 = xy[1]; break;\ |
||
11747 | schaersvoo | 8168 | };\ |
8169 | xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\ |
||
14062 | schaersvoo | 8170 | reply[click_cnt] = px2x(xy[0])+','+px2y(xy[1]);\ |
11238 | schaersvoo | 8171 | };\ |
7614 | schaersvoo | 8172 | };\ |
11238 | schaersvoo | 8173 | };\ |
8174 | if(onclick == 1){\ |
||
11747 | schaersvoo | 8175 | xml_div.onclick = function(){\ |
11756 | schaersvoo | 8176 | if(reply[click_cnt] == 0){ reply[click_cnt] = 1; xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;}else{reply[click_cnt] = 0;xml_div.style.color = color_org;xml_div.style.backgroundColor = no_color;};};\ |
7614 | schaersvoo | 8177 | };\ |
8178 | return;\ |
||
11745 | schaersvoo | 8179 | };"); |
7614 | schaersvoo | 8180 | break; |
7654 | schaersvoo | 8181 | case DRAW_SGRAPH: |
8224 | bpr | 8182 | /* |
7654 | schaersvoo | 8183 | xstart = given |
8184 | ystart = given |
||
8185 | sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily) |
||
8186 | */ |
||
13970 | obado | 8187 | fprintf(js_include_file,"\n/* draw sgraph */\n\ |
8105 | schaersvoo | 8188 | var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\ |
7658 | schaersvoo | 8189 | 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);};\ |
8190 | var ctx = obj.getContext(\"2d\");\ |
||
8191 | ctx.font = fontfamily;\ |
||
8192 | var minor_opacity = 0.8*opacity;\ |
||
8193 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7976 | schaersvoo | 8194 | var zero_x = 0.1*xsize;\ |
8195 | var zero_y = 0.9*ysize;\ |
||
8129 | schaersvoo | 8196 | var snor_x;var snor_y;\ |
7654 | schaersvoo | 8197 | if( xstart != xmin){\ |
7658 | schaersvoo | 8198 | snor_x = 0.1*xsize;\ |
8199 | }\ |
||
8200 | else\ |
||
8201 | {\ |
||
8202 | snor_x = 0;\ |
||
8203 | xstart = xmin;\ |
||
8204 | };\ |
||
8205 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8206 | ctx.lineWidth = 2;\ |
||
8207 | ctx.beginPath();\ |
||
8208 | ctx.moveTo(xsize,zero_y);\ |
||
8209 | ctx.lineTo(zero_x,zero_y);\ |
||
8210 | ctx.lineTo(zero_x,0);\ |
||
8211 | ctx.stroke();\ |
||
8212 | ctx.closePath();\ |
||
8213 | ctx.beginPath();\ |
||
8214 | ctx.moveTo(zero_x,zero_y);\ |
||
8215 | ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\ |
||
8216 | ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\ |
||
8217 | ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\ |
||
8218 | ctx.lineTo(zero_x + snor_x,zero_y);\ |
||
8219 | ctx.stroke();\ |
||
8220 | ctx.closePath();\ |
||
8221 | ctx.beginPath();\ |
||
8222 | var num = xstart;\ |
||
7660 | schaersvoo | 8223 | var flipflop = 1;\ |
7658 | schaersvoo | 8224 | var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\ |
7976 | schaersvoo | 8225 | var txtsize;var txt_marge=step_x - 5;\ |
7658 | schaersvoo | 8226 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
7976 | schaersvoo | 8227 | txtsize = ctx.measureText(num).width;\ |
8228 | if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\ |
||
8229 | if( flipflop == 1){\ |
||
8230 | ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\ |
||
8231 | }\ |
||
8232 | else\ |
||
8233 | {\ |
||
8234 | ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\ |
||
8379 | schaersvoo | 8235 | };\ |
7976 | schaersvoo | 8236 | num = num + xmajor;\ |
7658 | schaersvoo | 8237 | };\ |
8238 | ctx.stroke();\ |
||
8239 | ctx.closePath();\ |
||
8240 | ctx.lineWidth = 1;\ |
||
8241 | ctx.beginPath();\ |
||
8242 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
8243 | ctx.moveTo(x,zero_y);\ |
||
8244 | ctx.lineTo(x,0);\ |
||
8245 | };\ |
||
8246 | ctx.stroke();\ |
||
8247 | ctx.closePath();\ |
||
8248 | if( xminor > 1){\ |
||
8249 | ctx.lineWidth = 0.5;\ |
||
8250 | ctx.beginPath();\ |
||
8251 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
8252 | var minor_step_x = step_x / xminor;\ |
||
8253 | var nx;\ |
||
8254 | for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\ |
||
8255 | num = 1;\ |
||
8256 | for(var p = 1 ; p < xminor ; p++){\ |
||
8257 | nx = x + num*minor_step_x;\ |
||
8258 | ctx.moveTo(nx,zero_y);\ |
||
8259 | ctx.lineTo(nx,0);\ |
||
8260 | num++;\ |
||
8261 | };\ |
||
8262 | };\ |
||
8263 | ctx.stroke();\ |
||
8264 | ctx.closePath();\ |
||
8265 | ctx.beginPath();\ |
||
8266 | ctx.lineWidth = 2;\ |
||
8267 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8268 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
8269 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\ |
||
8270 | };\ |
||
8271 | for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\ |
||
8272 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\ |
||
8273 | };\ |
||
8274 | ctx.stroke();\ |
||
8275 | ctx.closePath();\ |
||
8276 | ctx.lineWidth = 0.5;\ |
||
8277 | };\ |
||
8278 | xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\ |
||
8279 | if( ystart != ymin){\ |
||
8280 | snor_y = 0.1*ysize;\ |
||
8281 | }\ |
||
8282 | else\ |
||
8283 | {\ |
||
8284 | snor_y = 0;\ |
||
8285 | ystart = ymin;\ |
||
8286 | };\ |
||
8287 | ctx.lineWidth = 2;\ |
||
8288 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8289 | ctx.beginPath();\ |
||
8290 | ctx.moveTo(zero_x,zero_y);\ |
||
8291 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\ |
||
8292 | ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\ |
||
8293 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\ |
||
8294 | ctx.lineTo(zero_x,zero_y - snor_y);\ |
||
8295 | ctx.stroke();\ |
||
8296 | ctx.closePath();\ |
||
8297 | ctx.beginPath();\ |
||
8298 | ctx.lineWidth = 1;\ |
||
8299 | num = ystart;\ |
||
8300 | var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\ |
||
8301 | for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\ |
||
8302 | ctx.moveTo(zero_x,y);\ |
||
8303 | ctx.lineTo(xsize,y);\ |
||
8304 | ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\ |
||
8305 | num = num + ymajor;\ |
||
8306 | };\ |
||
8307 | ctx.stroke();\ |
||
8308 | ctx.closePath();\ |
||
8309 | if( yminor > 1){\ |
||
8310 | ctx.lineWidth = 0.5;\ |
||
8311 | ctx.beginPath();\ |
||
8312 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
8313 | var minor_step_y = step_y / yminor;\ |
||
8314 | var ny;\ |
||
8315 | for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\ |
||
8316 | num = 1;\ |
||
8317 | for(var p = 1 ;p < yminor;p++){\ |
||
8318 | ny = y + num*minor_step_y;\ |
||
8319 | ctx.moveTo(zero_x,ny);\ |
||
8320 | ctx.lineTo(xsize,ny);\ |
||
8321 | num++;\ |
||
8322 | };\ |
||
8323 | };\ |
||
8324 | ctx.stroke();\ |
||
8325 | ctx.closePath();\ |
||
8326 | ctx.lineWidth = 2;\ |
||
8327 | ctx.beginPath();\ |
||
8328 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8329 | for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\ |
||
8330 | ctx.moveTo(zero_x,y);\ |
||
8331 | ctx.lineTo(zero_x+12,y);\ |
||
8332 | };\ |
||
8333 | for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\ |
||
8334 | ctx.moveTo(zero_x,y);\ |
||
8335 | ctx.lineTo(zero_x+6,y);\ |
||
8336 | };\ |
||
8337 | ctx.stroke();\ |
||
8338 | ctx.closePath();\ |
||
8339 | };\ |
||
8340 | ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\ |
||
11088 | schaersvoo | 8341 | if( typeof(legend%d) !== 'undefined' ){\ |
7654 | schaersvoo | 8342 | ctx.globalAlpha = 1.0;\ |
8343 | var y_offset = 2*font_size;\ |
||
8344 | var txt;var txt_size;\ |
||
8345 | var x_offset = xsize - 2*font_size;\ |
||
8346 | var l_length = legend%d.length;var barcolor = new Array();\ |
||
11088 | schaersvoo | 8347 | if( typeof(legendcolors%d) !== 'undefined' ){\ |
7654 | schaersvoo | 8348 | for(var p = 0 ; p < l_length ; p++){\ |
8349 | barcolor[p] = legendcolors%d[p];\ |
||
8350 | };\ |
||
8351 | }else{\ |
||
8352 | if( barcolor.length == 0 ){\ |
||
8353 | for(var p = 0 ; p < l_length ; p++){\ |
||
8354 | barcolor[p] = stroke_color;\ |
||
8355 | };\ |
||
8356 | };\ |
||
8357 | };\ |
||
8358 | for(var p = 0; p < l_length; p++){\ |
||
8359 | ctx.fillStyle = barcolor[p];\ |
||
8360 | txt = legend%d[p];\ |
||
8361 | txt_size = ctx.measureText(txt).width;\ |
||
8362 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
8363 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
8364 | };\ |
||
8365 | };\ |
||
11088 | schaersvoo | 8366 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7658 | schaersvoo | 8367 | ctx.fillStyle = \'#000000\';\ |
8368 | var txt_size = ctx.measureText(xaxislabel).width + 4 ;\ |
||
8369 | ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\ |
||
8370 | };\ |
||
11088 | schaersvoo | 8371 | if( typeof(yaxislabel) !== 'undefined'){\ |
7658 | schaersvoo | 8372 | ctx.save();\ |
8373 | ctx.fillStyle = \'#000000\';\ |
||
8374 | var txt_size = ctx.measureText(yaxislabel).width;\ |
||
8375 | ctx.translate(zero_x+8 + font_size,txt_size+font_size);\ |
||
8376 | ctx.rotate(-0.5*Math.PI);\ |
||
8377 | ctx.fillText(yaxislabel,0,0);\ |
||
7874 | schaersvoo | 8378 | ctx.restore();\ |
7658 | schaersvoo | 8379 | };\ |
7654 | schaersvoo | 8380 | };\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); |
8381 | break; |
||
11890 | schaersvoo | 8382 | case DRAW_NUMBERLINE: |
13970 | obado | 8383 | fprintf(js_include_file,"\n/* draw numberline */\n\ |
11996 | schaersvoo | 8384 | var draw_numberline = function(canvas_type,use_axis_numbering,x0,x1,xmajor,xminor,y0,y1,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor,precision){\ |
11890 | schaersvoo | 8385 | var obj = create_canvas%d(canvas_type,xsize,ysize);\ |
8386 | var ctx = obj.getContext(\"2d\");\ |
||
8387 | ctx.lineWidth = linewidth || 1;\ |
||
8388 | ctx.strokeStyle = \"rgba(\"+strokecolor+\",\"+strokeopacity+\")\";\ |
||
8389 | ctx.font = fontfamily || 'Ariel 12px';\ |
||
8390 | var fontsize = parseInt(ctx.font);\ |
||
8391 | ctx.fillStyle = \"rgba(\"+fontcolor+\",\"+strokeopacity+\")\";\ |
||
8392 | x1 = x2px(x1);\ |
||
8393 | x0 = x2px(x0);\ |
||
8394 | y0 = y2px(y0);\ |
||
8395 | y1 = y2px(y1);\ |
||
8396 | var sub_devision = -1;\ |
||
8397 | if( xminor%%2 == 0 ){ sub_devision = xminor/2; };\ |
||
11892 | schaersvoo | 8398 | var ybase1 = parseInt( y0 + fontsize + 2 );\ |
8399 | var ybase2 = parseInt( ybase1 + fontsize + 2 );\ |
||
11890 | schaersvoo | 8400 | var yh = Math.abs(parseInt( y0 - 0.3*(y0 -y1)));\ |
8401 | var ys = Math.abs(parseInt( y0 - 0.6*(y0 -y1)));\ |
||
8402 | xmajor = x2px(xmajor) - x2px(0);\ |
||
8403 | var i;var len;var p;\ |
||
8404 | xminor = xmajor / xminor;\ |
||
8405 | ctx.beginPath();\ |
||
8406 | for(p = x0 ; p < x1 ; p = p + xmajor){\ |
||
8407 | ctx.moveTo(p,y0);ctx.lineTo(p,y1);i = 0;\ |
||
8408 | for(var s = p ; s < p + xmajor ; s = s + xminor ){\ |
||
8409 | ctx.moveTo(s,y0);\ |
||
8410 | if( sub_devision == i){ ctx.lineTo(s,ys); } else { ctx.lineTo(s,yh); };\ |
||
8411 | i++;\ |
||
8412 | };\ |
||
8413 | };\ |
||
8414 | ctx.moveTo(p,y0);ctx.lineTo(p,y1);\ |
||
8415 | ctx.closePath();\ |
||
8416 | ctx.stroke();\ |
||
11996 | schaersvoo | 8417 | if( use_axis_numbering >-1 ){\ |
11891 | schaersvoo | 8418 | var str = x_strings[use_axis_numbering];\ |
8419 | len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
11892 | schaersvoo | 8420 | var corr;var x_nums;var x_text;var flipflop = 0;var off = ybase1;\ |
11890 | schaersvoo | 8421 | ctx.beginPath();\ |
11891 | schaersvoo | 8422 | if( x_strings_up[use_axis_numbering] == null){\ |
11890 | schaersvoo | 8423 | for(var p = 0 ; p < len ; p = p+2){\ |
11891 | schaersvoo | 8424 | var x_nums = x2px(eval(str[p]));\ |
8425 | var x_text = str[p+1];\ |
||
11890 | schaersvoo | 8426 | corr = ctx.measureText(x_text).width;\ |
11892 | schaersvoo | 8427 | if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\ |
11996 | schaersvoo | 8428 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),off);\ |
11890 | schaersvoo | 8429 | };\ |
8430 | }\ |
||
8431 | else\ |
||
8432 | {\ |
||
8433 | for(var p = 0 ; p < len ; p = p+2){\ |
||
11891 | schaersvoo | 8434 | x_nums = x2px(eval(str[p]));\ |
8435 | x_text = str[p+1];\ |
||
11892 | schaersvoo | 8436 | corr = ctx.measureText(x_text).width + ybase1 - fontsize;\ |
11890 | schaersvoo | 8437 | ctx.save();\ |
8438 | ctx.translate(x_nums+0.5*fontsize, corr);\ |
||
8439 | ctx.rotate(-1.5708);\ |
||
8440 | ctx.fillText(x_text,0,0);\ |
||
8441 | ctx.restore();\ |
||
8442 | };\ |
||
8443 | }\ |
||
8444 | }\ |
||
8445 | else\ |
||
8446 | {\ |
||
11892 | schaersvoo | 8447 | var corr;var num;var flipflop = 0;var off = ybase1;\ |
8448 | var prec = parseInt(Math.log(precision)/Math.log(10));\ |
||
11890 | schaersvoo | 8449 | for(var p = x0 ; p < x1+xmajor ; p = p+xmajor){\ |
11892 | schaersvoo | 8450 | num = (px2x(p)).toFixed(prec);\ |
11996 | schaersvoo | 8451 | corr = ctx.measureText(num).width;\ |
11892 | schaersvoo | 8452 | if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\ |
11996 | schaersvoo | 8453 | ctx.fillText(num,parseInt(p - 0.5*corr),off);\ |
11890 | schaersvoo | 8454 | };\ |
8455 | };\ |
||
8456 | };",canvas_root_id); |
||
8457 | break; |
||
7614 | schaersvoo | 8458 | case DRAW_GRID:/* not used for userdraw */ |
13970 | obado | 8459 | fprintf(js_include_file,"\n/* draw grid */\n\ |
8105 | schaersvoo | 8460 | 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 | 8461 | 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);};\ |
8462 | var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\ |
||
7614 | schaersvoo | 8463 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
8464 | ctx.save();\ |
||
8071 | schaersvoo | 8465 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 8466 | if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\ |
8467 | var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8468 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\ |
||
8469 | var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\ |
||
8470 | ctx.font = font_family;\ |
||
7988 | schaersvoo | 8471 | var barcolor = new Array();\ |
7614 | schaersvoo | 8472 | var xstep = xsize*xmajor/(xmax - xmin);\ |
8473 | var ystep = ysize*ymajor/(ymax - ymin);\ |
||
8474 | var x2step = xstep / xminor;\ |
||
8475 | var y2step = ystep / yminor;\ |
||
7996 | schaersvoo | 8476 | var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\ |
8477 | if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\ |
||
8478 | if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\ |
||
11088 | schaersvoo | 8479 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 8480 | ctx.beginPath();\ |
8481 | ctx.lineWidth = line_width;\ |
||
8482 | ctx.strokeStyle = stroke_color;\ |
||
8483 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
8484 | ctx.moveTo(p,0);\ |
||
8485 | ctx.lineTo(p,ysize);\ |
||
8486 | };\ |
||
8487 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
8488 | ctx.moveTo(p,0);\ |
||
8489 | ctx.lineTo(p,ysize);\ |
||
8490 | };\ |
||
8491 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
8492 | ctx.moveTo(0,p);\ |
||
8493 | ctx.lineTo(xsize,p);\ |
||
8494 | };\ |
||
8495 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
8496 | ctx.moveTo(0,p);\ |
||
8497 | ctx.lineTo(xsize,p);\ |
||
8498 | };\ |
||
11088 | schaersvoo | 8499 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7614 | schaersvoo | 8500 | ctx.save();\ |
8501 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
12007 | schaersvoo | 8502 | var corr = parseInt(1.1*ctx.measureText(xaxislabel).width);\ |
8503 | ctx.fillText(xaxislabel,xsize - corr,zero_y - tics_length - 0.4*font_size);\ |
||
7614 | schaersvoo | 8504 | ctx.restore();\ |
8505 | };\ |
||
11088 | schaersvoo | 8506 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7614 | schaersvoo | 8507 | ctx.save();\ |
8508 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
12007 | schaersvoo | 8509 | var corr = parseInt(ctx.measureText(yaxislabel).width + font_size);\ |
8510 | ctx.translate(zero_x+tics_length + font_size,corr);\ |
||
7614 | schaersvoo | 8511 | ctx.rotate(-0.5*Math.PI);\ |
8512 | ctx.fillText(yaxislabel,0,0);\ |
||
8513 | ctx.restore();\ |
||
8514 | };\ |
||
8515 | ctx.stroke();\ |
||
8516 | ctx.closePath();\ |
||
8517 | if( use_axis == 1 ){\ |
||
7988 | schaersvoo | 8518 | ctx.save();\ |
7614 | schaersvoo | 8519 | ctx.beginPath();\ |
8520 | ctx.strokeStyle = stroke_color;\ |
||
8521 | ctx.lineWidth = 0.6*line_width;\ |
||
8522 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
8523 | ctx.moveTo(p,0);\ |
||
8524 | ctx.lineTo(p,ysize);\ |
||
8525 | };\ |
||
8526 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
8527 | ctx.moveTo(p,0);\ |
||
8528 | ctx.lineTo(p,ysize);\ |
||
8529 | };\ |
||
8530 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
8531 | ctx.moveTo(0,p);\ |
||
8532 | ctx.lineTo(xsize,p);\ |
||
8533 | };\ |
||
8534 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
8535 | ctx.moveTo(0,p);\ |
||
8536 | ctx.lineTo(xsize,p);\ |
||
8537 | };\ |
||
8538 | ctx.stroke();\ |
||
8539 | ctx.closePath();\ |
||
8540 | ctx.beginPath();\ |
||
8541 | ctx.lineWidth = 2*line_width;\ |
||
8542 | ctx.strokeStyle = axis_color;\ |
||
8543 | ctx.moveTo(0,zero_y);\ |
||
8544 | ctx.lineTo(xsize,zero_y);\ |
||
8545 | ctx.moveTo(zero_x,0);\ |
||
8546 | ctx.lineTo(zero_x,ysize);\ |
||
8547 | ctx.stroke();\ |
||
8548 | ctx.closePath();\ |
||
8549 | ctx.lineWidth = line_width+0.5;\ |
||
8550 | ctx.beginPath();\ |
||
8551 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
8552 | ctx.moveTo(p,zero_y-tics_length);\ |
||
8553 | ctx.lineTo(p,zero_y+tics_length);\ |
||
8554 | };\ |
||
8555 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
8556 | ctx.moveTo(p,zero_y-tics_length);\ |
||
8557 | ctx.lineTo(p,zero_y+tics_length);\ |
||
8558 | };\ |
||
8559 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
8560 | ctx.moveTo(zero_x-tics_length,p);\ |
||
8561 | ctx.lineTo(zero_x+tics_length,p);\ |
||
8562 | };\ |
||
8563 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
8564 | ctx.moveTo(zero_x-tics_length,p);\ |
||
8565 | ctx.lineTo(zero_x+tics_length,p);\ |
||
8566 | };\ |
||
8567 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
8568 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
8569 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
8570 | };\ |
||
8571 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
8572 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
8573 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
8574 | };\ |
||
8575 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
8576 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
8577 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
8578 | };\ |
||
8579 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
8580 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
8581 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
8582 | };\ |
||
8583 | ctx.stroke();\ |
||
8584 | ctx.closePath();\ |
||
7988 | schaersvoo | 8585 | ctx.restore();\ |
8586 | };\ |
||
11891 | schaersvoo | 8587 | if( use_axis_numbering != -1 ){\ |
7988 | schaersvoo | 8588 | ctx.save();\ |
8589 | ctx.fillColor = axis_color;\ |
||
8110 | schaersvoo | 8590 | ctx.strokeStyle = axis_color;\ |
8591 | ctx.lineWidth = 2*line_width;\ |
||
7988 | schaersvoo | 8592 | ctx.font = font_family;\ |
8593 | var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\ |
||
11891 | schaersvoo | 8594 | if( x_strings[use_axis_numbering] != null ){\ |
8595 | var str = x_strings[use_axis_numbering];\ |
||
8596 | var len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 8597 | ctx.beginPath();\ |
11891 | schaersvoo | 8598 | if( x_strings_up[use_axis_numbering] == null){\ |
9341 | schaersvoo | 8599 | for(var p = 0 ; p < len ; p = p+2){\ |
11891 | schaersvoo | 8600 | var x_nums = x2px(eval(str[p]));\ |
8601 | var x_text = str[p+1];\ |
||
9341 | schaersvoo | 8602 | corr = ctx.measureText(x_text).width;\ |
8603 | skip = 1.2*corr/xstep;\ |
||
8604 | if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\ |
||
8605 | if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\ |
||
8606 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\ |
||
8607 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
8608 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
8609 | };\ |
||
8610 | }\ |
||
8611 | else\ |
||
8612 | {\ |
||
8613 | for(var p = 0 ; p < len ; p = p+2){\ |
||
11891 | schaersvoo | 8614 | var x_nums = x2px(eval(str[p]));\ |
8615 | var x_text = str[p+1];\ |
||
9341 | schaersvoo | 8616 | corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\ |
8617 | if( corr > ysize ){corr = ysize;};\ |
||
8618 | ctx.save();\ |
||
9346 | schaersvoo | 8619 | ctx.translate(x_nums+0.25*font_size, corr);\ |
9341 | schaersvoo | 8620 | ctx.rotate(-1.5708);\ |
8621 | ctx.fillText(x_text,0,0);\ |
||
8622 | ctx.restore();\ |
||
8623 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
8624 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
8625 | };\ |
||
7988 | schaersvoo | 8626 | };\ |
8110 | schaersvoo | 8627 | ctx.closePath();\ |
7988 | schaersvoo | 8628 | }\ |
8629 | else\ |
||
8630 | {\ |
||
8631 | skip = 1;cnt = px2x(zero_x);\ |
||
8632 | prec = Math.log(precision)/(Math.log(10));\ |
||
8633 | var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\ |
||
8634 | for( var p = zero_x ; p < xsize ; p = p+xstep){\ |
||
8635 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 8636 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8637 | corr = ctx.measureText(disp_cnt).width;\ |
8638 | skip = parseInt(1.2*corr/xstep);\ |
||
8639 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
7614 | schaersvoo | 8640 | }\ |
7988 | schaersvoo | 8641 | else\ |
8642 | {\ |
||
8643 | skip--;\ |
||
7614 | schaersvoo | 8644 | };\ |
7988 | schaersvoo | 8645 | cnt = cnt + xmajor;\ |
7614 | schaersvoo | 8646 | };\ |
7988 | schaersvoo | 8647 | cnt = px2x(zero_x);skip = 1;\ |
8648 | for( var p = zero_x ; p > 0 ; p = p-xstep){\ |
||
8649 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 8650 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8651 | corr = ctx.measureText(disp_cnt).width;\ |
8652 | skip = parseInt(1.2*corr/xstep);\ |
||
8653 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
8654 | }\ |
||
8655 | else\ |
||
8656 | {\ |
||
8657 | skip--;\ |
||
7614 | schaersvoo | 8658 | };\ |
7988 | schaersvoo | 8659 | cnt = cnt - xmajor;\ |
7614 | schaersvoo | 8660 | };\ |
8661 | };\ |
||
7988 | schaersvoo | 8662 | if( y_strings != null ){\ |
8663 | var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 8664 | ctx.beginPath();\ |
7988 | schaersvoo | 8665 | for(var p = 0 ; p < len ; p = p+2){\ |
8666 | var y_nums = y2px(eval(y_strings[p]));\ |
||
8667 | var y_text = y_strings[p+1];\ |
||
8668 | corr = 2 + tics_length + ctx.measureText(y_text).width;\ |
||
8669 | if( corr > zero_x){corr = parseInt(zero_x+2); }\ |
||
8110 | schaersvoo | 8670 | ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\ |
8671 | ctx.moveTo(zero_x - tics_length,y_nums);\ |
||
8672 | ctx.lineTo(zero_x + tics_length,y_nums);\ |
||
7614 | schaersvoo | 8673 | };\ |
8110 | schaersvoo | 8674 | ctx.closePath();\ |
7988 | schaersvoo | 8675 | }\ |
8676 | else\ |
||
8677 | {\ |
||
7991 | schaersvoo | 8678 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 8679 | cnt = px2y(zero_y);skip = 1;\ |
8680 | for( var p = zero_y ; p < ysize ; p = p+ystep){\ |
||
8681 | if(skip == 0 ){\ |
||
8682 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 8683 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8684 | if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
8685 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
8686 | }\ |
||
8687 | else\ |
||
8688 | {\ |
||
8689 | skip--;\ |
||
8690 | };\ |
||
8691 | cnt = cnt - ymajor;\ |
||
7614 | schaersvoo | 8692 | };\ |
7988 | schaersvoo | 8693 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
7991 | schaersvoo | 8694 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 8695 | for( var p = zero_y ; p > 0 ; p = p-ystep){\ |
8696 | if(skip == 0 ){\ |
||
8697 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 8698 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8699 | if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
8700 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
8701 | }\ |
||
8702 | else\ |
||
8703 | {\ |
||
8704 | skip--;\ |
||
8705 | };\ |
||
8706 | cnt = cnt + ymajor;\ |
||
7614 | schaersvoo | 8707 | };\ |
8708 | };\ |
||
7988 | schaersvoo | 8709 | ctx.stroke();\ |
7614 | schaersvoo | 8710 | ctx.restore();\ |
8711 | };\ |
||
11088 | schaersvoo | 8712 | if( typeof(legend0) !== 'undefined' ){\ |
7988 | schaersvoo | 8713 | ctx.save();\ |
7614 | schaersvoo | 8714 | ctx.globalAlpha = 1.0;\ |
8715 | ctx.font = \"bold \"+font_size+\"px Ariel\";\ |
||
8716 | var y_offset = 2*font_size;\ |
||
8717 | var txt;var txt_size;\ |
||
8718 | var x_offset = xsize - 2*font_size;\ |
||
7956 | schaersvoo | 8719 | var l_length = legend0.length;\ |
11088 | schaersvoo | 8720 | if( typeof(legendcolors0) !== 'undefined' ){\ |
7614 | schaersvoo | 8721 | for(var p = 0 ; p < l_length ; p++){\ |
7956 | schaersvoo | 8722 | barcolor[p] = legendcolors0[p];\ |
7614 | schaersvoo | 8723 | };\ |
7988 | schaersvoo | 8724 | }\ |
8725 | else\ |
||
8726 | {\ |
||
7614 | schaersvoo | 8727 | if( barcolor.length == 0 ){\ |
8728 | for(var p = 0 ; p < l_length ; p++){\ |
||
8729 | barcolor[p] = stroke_color;\ |
||
8730 | };\ |
||
8731 | };\ |
||
8732 | };\ |
||
8733 | for(var p = 0; p < l_length; p++){\ |
||
8734 | ctx.fillStyle = barcolor[p];\ |
||
7956 | schaersvoo | 8735 | txt = legend0[p];\ |
7614 | schaersvoo | 8736 | txt_size = ctx.measureText(txt).width;\ |
7956 | schaersvoo | 8737 | ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\ |
7614 | schaersvoo | 8738 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
8739 | };\ |
||
7988 | schaersvoo | 8740 | ctx.restore();\ |
7614 | schaersvoo | 8741 | };\ |
11088 | schaersvoo | 8742 | if( typeof(barchart_0) !== 'undefined' ){\ |
7991 | schaersvoo | 8743 | ctx.save();\ |
8744 | var num_barcharts = 0;\ |
||
8745 | var bar_name = eval('barchart_0');\ |
||
11088 | schaersvoo | 8746 | while( typeof(bar_name) !== 'undefined' ){\ |
7991 | schaersvoo | 8747 | try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\ |
8748 | };\ |
||
9346 | schaersvoo | 8749 | var bar_width = parseInt(0.8*x2step/(num_barcharts));\ |
7991 | schaersvoo | 8750 | for(var i=0 ; i< num_barcharts ; i++){\ |
8751 | bar_name = eval('barchart_'+i);\ |
||
8752 | var bar_x = new Array();\ |
||
8753 | var bar_y = new Array();\ |
||
8754 | var lb = bar_name.length;\ |
||
8755 | var idx = 0;\ |
||
8756 | var dx = parseInt(0.5*i*bar_width);\ |
||
8757 | for( var p = 0 ; p < lb ; p = p + 3 ){\ |
||
8758 | bar_x[idx] = x2px(bar_name[p]);\ |
||
8759 | bar_y[idx] = y2px(bar_name[p+1]);\ |
||
8760 | barcolor[idx] = bar_name[p+2];\ |
||
8761 | idx++;\ |
||
8762 | };\ |
||
8763 | ctx.globalAlpha = fill_opacity;\ |
||
8764 | for( var p = 0; p < idx ; p++ ){\ |
||
11739 | schaersvoo | 8765 | ctx.beginPath();\ |
7991 | schaersvoo | 8766 | ctx.strokeStyle = barcolor[p];\ |
8767 | ctx.fillStyle = barcolor[p];\ |
||
9346 | schaersvoo | 8768 | ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\ |
11739 | schaersvoo | 8769 | ctx.fill();\ |
8770 | ctx.stroke();\ |
||
8771 | ctx.closePath();\ |
||
7991 | schaersvoo | 8772 | };\ |
8773 | };\ |
||
8774 | ctx.restore();\ |
||
8775 | };\ |
||
11088 | schaersvoo | 8776 | if( typeof(linegraph_0) !== 'undefined' ){\ |
7996 | schaersvoo | 8777 | ctx.save();\ |
8778 | ctx.globalAlpha = 1.0;\ |
||
8779 | var i = 0;\ |
||
8780 | var line_name = eval('linegraph_'+i);\ |
||
11088 | schaersvoo | 8781 | while ( typeof(line_name) !== 'undefined' ){\ |
7996 | schaersvoo | 8782 | ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\ |
8783 | ctx.lineWidth = parseInt(line_name[1]);\ |
||
8784 | if(line_name[2] == \"1\"){\ |
||
8785 | var d1 = parseInt(line_name[3]);\ |
||
8786 | var d2 = parseInt(line_name[4]);\ |
||
8787 | if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\ |
||
8788 | }\ |
||
8789 | else\ |
||
8790 | {\ |
||
8791 | if(ctx.setLineDash){ctx.setLineDash = null;}\ |
||
8792 | if(ctx.mozDash){ctx.mozDash = null;}\ |
||
8793 | };\ |
||
8794 | var data_x = new Array();\ |
||
8795 | var data_y = new Array();\ |
||
8796 | var lb = line_name.length;\ |
||
8797 | var idx = 0;\ |
||
8798 | for( var p = 5 ; p < lb ; p = p + 2 ){\ |
||
8799 | data_x[idx] = x2px(line_name[p]);\ |
||
8800 | data_y[idx] = y2px(line_name[p+1]);\ |
||
8801 | idx++;\ |
||
8802 | };\ |
||
8803 | for( var p = 0; p < idx ; p++){\ |
||
8804 | ctx.beginPath();\ |
||
8805 | ctx.moveTo(data_x[p],data_y[p]);\ |
||
8806 | ctx.lineTo(data_x[p+1],data_y[p+1]);\ |
||
8807 | ctx.stroke();\ |
||
8808 | ctx.closePath();\ |
||
8809 | };\ |
||
8810 | i++;\ |
||
8811 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
||
8812 | };\ |
||
8813 | ctx.restore();\ |
||
8814 | };\ |
||
7614 | schaersvoo | 8815 | return;\ |
7989 | schaersvoo | 8816 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8817 | break; |
8224 | bpr | 8818 | |
7614 | schaersvoo | 8819 | case DRAW_PIECHART: |
13970 | obado | 8820 | fprintf(js_include_file,"\n/* draw piecharts */\n\ |
11875 | schaersvoo | 8821 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
12538 | schaersvoo | 8822 | function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family,use_filled,use_offset){\ |
7614 | schaersvoo | 8823 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
8824 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8825 | }\ |
||
8826 | else\ |
||
8827 | {\ |
||
8828 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8829 | };\ |
||
12538 | schaersvoo | 8830 | var center_text = use_offset || 0;\ |
7614 | schaersvoo | 8831 | var ld = data_color_list.length;\ |
8832 | var sum = 0;\ |
||
8833 | var idx = 0;\ |
||
7956 | schaersvoo | 8834 | var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\ |
7614 | schaersvoo | 8835 | var colors = new Array();\ |
8836 | var data = new Array();\ |
||
8837 | for(var p = 0;p < ld; p = p + 2){\ |
||
8838 | data[idx] = parseFloat(data_color_list[p]);\ |
||
8839 | sum = sum + data[idx];\ |
||
8840 | colors[idx] = data_color_list[p+1];\ |
||
8841 | idx++;\ |
||
8842 | };\ |
||
11875 | schaersvoo | 8843 | if( use_filled > 1 ){\ |
8844 | var i = 2;\ |
||
8845 | for(var p = 0 ; p < idx ; p++){\ |
||
8846 | if(i > 5 ){ i = 2; };\ |
||
8847 | var pat = create_Pattern(0,0,i,colors[p]); all_fill_patterns[p] = pat;i++;\ |
||
8848 | };\ |
||
8849 | };\ |
||
7614 | schaersvoo | 8850 | var ctx = obj.getContext(\"2d\");\ |
8851 | ctx.save();\ |
||
8852 | var angle;\ |
||
8853 | var angle_end = 0;\ |
||
8854 | var offset = Math.PI / 2;\ |
||
8855 | ctx.globalAlpha = fill_opacity;\ |
||
12538 | schaersvoo | 8856 | var angles = [];\ |
7614 | schaersvoo | 8857 | for(var p=0; p < idx; p++){\ |
8858 | ctx.beginPath();\ |
||
8859 | ctx.moveTo(x_center,y_center);\ |
||
8860 | angle = Math.PI * (2 * data[p] / sum);\ |
||
8861 | ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\ |
||
8862 | ctx.lineTo(x_center, y_center);\ |
||
11875 | schaersvoo | 8863 | if( use_filled > 1 ){ ctx.fillStyle = all_fill_patterns[p]; }else{ ctx.fillStyle = colors[p];};\ |
7614 | schaersvoo | 8864 | ctx.fill();\ |
8865 | ctx.closePath();\ |
||
12538 | schaersvoo | 8866 | angles.push(angle_end + angle - offset);\ |
7614 | schaersvoo | 8867 | angle_end = angle_end + angle;\ |
8868 | };\ |
||
11088 | schaersvoo | 8869 | if(typeof(legend0) !== 'undefined'){\ |
7956 | schaersvoo | 8870 | var legenda = eval(\"legend\"+legend_cnt);\ |
7614 | schaersvoo | 8871 | ctx.globalAlpha = 1.0;\ |
7956 | schaersvoo | 8872 | ctx.font = font_family;\ |
12538 | schaersvoo | 8873 | var y_offset = font_size;\ |
7614 | schaersvoo | 8874 | var x_offset = 0;\ |
8875 | var txt;var txt_size;\ |
||
8876 | for(var p = 0; p < idx; p++){\ |
||
8877 | ctx.fillStyle = colors[p];\ |
||
7956 | schaersvoo | 8878 | txt = legenda[p];\ |
12538 | schaersvoo | 8879 | txt_size = ctx.measureText(txt).width + 2;\ |
8880 | if(center_text == 4){\ |
||
8881 | ctx.save();\ |
||
8882 | ctx.translate(x_center, y_center);\ |
||
8883 | ctx.rotate(angles[p]);\ |
||
8884 | ctx.fillText(txt,radius-txt_size,0);\ |
||
8885 | ctx.restore();\ |
||
8886 | }\ |
||
8887 | else\ |
||
8888 | {\ |
||
8889 | if( x_center + radius + txt_size > xsize ){ x_offset = x_center + radius + txt_size - xsize;} else { x_offset = 0; };\ |
||
8890 | ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\ |
||
8891 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
8892 | };\ |
||
7614 | schaersvoo | 8893 | };\ |
8894 | };\ |
||
8895 | ctx.restore();\ |
||
7956 | schaersvoo | 8896 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8897 | break; |
9433 | schaersvoo | 8898 | case DRAW_JSBOXPLOT: |
13970 | obado | 8899 | fprintf(js_include_file,"\n/* draw jsboxplots */\n\ |
11874 | schaersvoo | 8900 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
9433 | schaersvoo | 8901 | function statistics(data){\ |
8902 | var len = data.length;\ |
||
8903 | var min = 10000000;\ |
||
8904 | var max = -10000000;\ |
||
8905 | var sum = 0;var d;\ |
||
8906 | for(var i=0;i<len;i++){\ |
||
8907 | d = data[i];\ |
||
8908 | if(d < min){min = d;}else{if(d > max){max = d;};};\ |
||
8909 | sum+= parseFloat(data[i]);\ |
||
8910 | };\ |
||
8911 | var mean = parseFloat(sum/len);\ |
||
8912 | var variance = 0;\ |
||
8913 | for(var i=0;i<len;i++){\ |
||
8914 | d = data[i];\ |
||
8915 | variance += (d - mean)*(d - mean);\ |
||
8916 | };\ |
||
8917 | variance = parseFloat(variance / len);\ |
||
8918 | var std = Math.sqrt(variance);\ |
||
8919 | data.sort(function(a,b){return a - b;});\ |
||
8920 | var median;var Q1;var Q3;\ |
||
8921 | var half = Math.floor(0.5*len);\ |
||
8922 | var q1 = Math.floor(0.25*len);\ |
||
8923 | var q3 = Math.floor(0.75*len);\ |
||
8924 | var half = Math.floor(0.5*len);\ |
||
8925 | if(len %%2 == 1){\ |
||
8926 | median = data[half];\ |
||
8927 | Q1 = data[q1];\ |
||
8928 | Q3 = data[q3];\ |
||
8929 | }\ |
||
8930 | else\ |
||
8931 | {\ |
||
8932 | median = (data[half - 1] + data[half] )/2;\ |
||
8933 | Q1 = (data[q1 - 1] + data[q1] )/2;\ |
||
8934 | Q3 = (data[q3 - 1] + data[q3] )/2;\ |
||
8935 | };\ |
||
8936 | return [min,Q1,median,Q3,max];\ |
||
8937 | };"); |
||
8938 | break; |
||
8939 | case DRAW_BOXPLOT: |
||
13970 | obado | 8940 | fprintf(js_include_file,"\n/* draw boxplots */\n\ |
11874 | schaersvoo | 8941 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
9465 | schaersvoo | 8942 | 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){\ |
14044 | schaersvoo | 8943 | 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);};\ |
9433 | schaersvoo | 8944 | var ctx = obj.getContext(\"2d\");\ |
8945 | ctx.clearRect(0,0,xsize,ysize);\ |
||
8946 | ctx.save();\ |
||
8947 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 8948 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
9433 | schaersvoo | 8949 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11875 | schaersvoo | 8950 | var colors = new Array(2);\ |
8951 | colors[0] = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
8952 | colors[1] = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8953 | if( use_filled > 1 ){\ |
||
8954 | var pat = create_Pattern(0,0,3,colors[0]);\ |
||
8955 | all_fill_patterns[0] = pat;\ |
||
8956 | pat = create_Pattern(0,0,4,colors[1]);\ |
||
8957 | all_fill_patterns[1] = pat;\ |
||
8958 | };\ |
||
9433 | schaersvoo | 8959 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
8960 | var hh = 0.25*hw;\ |
||
9465 | schaersvoo | 8961 | switch(boxplot_source){\ |
11088 | schaersvoo | 8962 | case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\ |
8963 | case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\ |
||
8964 | case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\ |
||
9465 | schaersvoo | 8965 | default: break;\ |
9433 | schaersvoo | 8966 | };\ |
8967 | var min,Q1,median,Q3,max;\ |
||
8968 | if(xy == 1 ){\ |
||
8969 | min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\ |
||
8970 | hh = Math.abs(y2px(hh) - y2px(ystart));\ |
||
8971 | hw = Math.abs(y2px(hw) - y2px(ystart));\ |
||
8972 | cxy = y2px(cxy);\ |
||
9465 | schaersvoo | 8973 | ctx.beginPath();\ |
9433 | schaersvoo | 8974 | ctx.moveTo(min,cxy);\ |
8975 | ctx.lineTo(Q1,cxy);\ |
||
8976 | ctx.moveTo(Q3,cxy);\ |
||
8977 | ctx.lineTo(max,cxy);\ |
||
8978 | ctx.moveTo(min,cxy+hh);\ |
||
8979 | ctx.lineTo(min,cxy-hh);\ |
||
8980 | ctx.moveTo(max,cxy+hh);\ |
||
8981 | ctx.lineTo(max,cxy-hh);\ |
||
9465 | schaersvoo | 8982 | ctx.closePath();\ |
8983 | ctx.stroke();\ |
||
8984 | ctx.beginPath();\ |
||
9433 | schaersvoo | 8985 | ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\ |
9465 | schaersvoo | 8986 | ctx.closePath();\ |
11839 | schaersvoo | 8987 | if( use_filled != 0 ){\ |
12024 | schaersvoo | 8988 | if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\ |
9465 | schaersvoo | 8989 | ctx.fill();\ |
8990 | };\ |
||
8991 | ctx.stroke();\ |
||
8992 | ctx.beginPath();\ |
||
9433 | schaersvoo | 8993 | ctx.rect(median,cxy-2*hh,Q3-median,hw);\ |
9465 | schaersvoo | 8994 | ctx.closePath();\ |
11839 | schaersvoo | 8995 | if( use_filled != 0 ){\ |
12075 | schaersvoo | 8996 | if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\ |
9465 | schaersvoo | 8997 | ctx.fill();\ |
8998 | };\ |
||
8999 | ctx.stroke();\ |
||
9433 | schaersvoo | 9000 | }else{\ |
9001 | min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\ |
||
9002 | hh = Math.abs(x2px(hh) - x2px(xstart));\ |
||
9003 | hw = Math.abs(x2px(hw) - x2px(xstart));\ |
||
9004 | cxy = x2px(cxy);\ |
||
9465 | schaersvoo | 9005 | ctx.beginPath();\ |
9433 | schaersvoo | 9006 | ctx.moveTo(cxy,min);\ |
9007 | ctx.lineTo(cxy,Q1);\ |
||
9008 | ctx.moveTo(cxy,Q3);\ |
||
9009 | ctx.lineTo(cxy,max);\ |
||
9010 | ctx.moveTo(cxy + hh,min);\ |
||
9011 | ctx.lineTo(cxy - hh,min);\ |
||
9012 | ctx.moveTo(cxy + hh,max);\ |
||
9013 | ctx.lineTo(cxy - hh,max);\ |
||
9465 | schaersvoo | 9014 | ctx.closePath;\ |
9015 | ctx.stroke();\ |
||
9016 | ctx.beginPath();\ |
||
9433 | schaersvoo | 9017 | ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\ |
9465 | schaersvoo | 9018 | ctx.closePath();\ |
11839 | schaersvoo | 9019 | if( use_filled != 0 ){\ |
12075 | schaersvoo | 9020 | if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\ |
9465 | schaersvoo | 9021 | ctx.fill();\ |
9022 | };\ |
||
9023 | ctx.stroke();\ |
||
9024 | ctx.beginPath();\ |
||
9433 | schaersvoo | 9025 | ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\ |
9465 | schaersvoo | 9026 | ctx.closePath();\ |
11839 | schaersvoo | 9027 | if( use_filled != 0 ){\ |
12075 | schaersvoo | 9028 | if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\ |
9465 | schaersvoo | 9029 | ctx.fill();\ |
9030 | };\ |
||
9031 | ctx.stroke();\ |
||
9433 | schaersvoo | 9032 | };\ |
9033 | ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id); |
||
9034 | break; |
||
7614 | schaersvoo | 9035 | case DRAW_ARCS: |
13970 | obado | 9036 | fprintf(js_include_file,"\n/* draw arcs */\n\ |
11874 | schaersvoo | 9037 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 9038 | 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 | 9039 | ctx.save();\ |
9040 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
8071 | schaersvoo | 9041 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 9042 | if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
9043 | if(end < start){var tmp = end;end = start;start=tmp;};\ |
||
8071 | schaersvoo | 9044 | start = 360 - start;\ |
9045 | end = 360 - end;\ |
||
7614 | schaersvoo | 9046 | ctx.lineWidth = line_width;\ |
11088 | schaersvoo | 9047 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 9048 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11874 | schaersvoo | 9049 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 9050 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
8071 | schaersvoo | 9051 | ctx.beginPath();\ |
9052 | ctx.moveTo(xc,yc);\ |
||
9053 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
9054 | ctx.lineTo(xc,yc);\ |
||
9055 | ctx.closePath();\ |
||
11875 | schaersvoo | 9056 | if( use_filled != 0 ){ctx.fill();};\ |
8071 | schaersvoo | 9057 | ctx.stroke();\ |
7614 | schaersvoo | 9058 | ctx.restore();\ |
8071 | schaersvoo | 9059 | };"); |
8224 | bpr | 9060 | |
7614 | schaersvoo | 9061 | break; |
7983 | schaersvoo | 9062 | case DRAW_CENTERSTRING: |
13970 | obado | 9063 | fprintf(js_include_file,"\n/* draw centerstring */\n\ |
8105 | schaersvoo | 9064 | var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\ |
7983 | schaersvoo | 9065 | var obj;\ |
9066 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9067 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9068 | }\ |
||
9069 | else\ |
||
9070 | {\ |
||
9071 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9072 | };\ |
||
9073 | var ctx = obj.getContext(\"2d\");\ |
||
9074 | ctx.save();\ |
||
9481 | schaersvoo | 9075 | ctx.clearRect(0,0,xsize,ysize);\ |
7983 | schaersvoo | 9076 | ctx.font = font_family;\ |
9077 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
9078 | var stringwidth = ctx.measureText(text).width;\ |
||
9079 | var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\ |
||
9080 | ctx.fillText(text,x,y2px(y));\ |
||
9481 | schaersvoo | 9081 | ctx.restore();\ |
7983 | schaersvoo | 9082 | return;\ |
9083 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
||
9084 | break; |
||
7614 | schaersvoo | 9085 | case DRAW_TEXTS: |
13970 | obado | 9086 | fprintf(js_include_file,"\n/* draw text */\n\ |
11811 | schaersvoo | 9087 | 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,use_offset){\ |
12000 | schaersvoo | 9088 | var obj;\ |
9089 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9090 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9091 | }\ |
||
9092 | else\ |
||
9093 | {\ |
||
9094 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9095 | };\ |
||
9096 | var ctx = obj.getContext(\"2d\");\ |
||
9097 | if( font_family != 'null' ){\ |
||
9098 | ctx.font = font_family;\ |
||
9099 | }\ |
||
9100 | else\ |
||
9101 | {\ |
||
9102 | ctx.font = font_size+'px Ariel';\ |
||
9103 | };\ |
||
9104 | if( use_offset == 3 ){if(angle2 < 0 ){ y = y + 0.8*font_size; x = x + (Math.cos(angle2))*font_size; }else{y = y - 0.8*font_size; x = x + (Math.sin(angle2))*font_size;};};\ |
||
9105 | if(angle2 == 0 && angle != 0){\ |
||
9106 | ctx.save();\ |
||
9107 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
||
9108 | if(use_rotate == 1 ){\ |
||
9109 | ctx.rotate(angle*Math.PI/180);};\ |
||
9110 | ctx.restore();\ |
||
9111 | };\ |
||
9112 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
9113 | if(angle2 != 0){\ |
||
9114 | ctx.save();\ |
||
9115 | ctx.translate(x,y);\ |
||
9116 | ctx.rotate((360-angle2)*(Math.PI / 180));\ |
||
9117 | ctx.fillText(text,0,0);\ |
||
9118 | ctx.restore();\ |
||
9119 | }\ |
||
9120 | else\ |
||
9121 | {\ |
||
9122 | ctx.fillText(text,x,y);\ |
||
9123 | };\ |
||
7614 | schaersvoo | 9124 | return;\ |
12000 | schaersvoo | 9125 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 9126 | break; |
9127 | case DRAW_CURVE: |
||
13970 | obado | 9128 | fprintf(js_include_file,"\n/* draw curve */\n\ |
8105 | schaersvoo | 9129 | 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 | 9130 | var obj;\ |
9131 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9132 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9133 | }\ |
||
9134 | else\ |
||
9135 | {\ |
||
9136 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9137 | };\ |
||
9138 | var ctx = obj.getContext(\"2d\");\ |
||
9139 | ctx.save();\ |
||
8071 | schaersvoo | 9140 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 9141 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
9142 | ctx.beginPath();ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 9143 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 9144 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
9145 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
9146 | ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\ |
||
9147 | for(var p = 1 ; p < x_points.length ; p++){\ |
||
9148 | if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\ |
||
9149 | ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
9150 | }\ |
||
9151 | else\ |
||
9152 | {\ |
||
9153 | ctx.stroke();\ |
||
9154 | ctx.beginPath();\ |
||
9155 | p++;\ |
||
9156 | ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
9157 | };\ |
||
9158 | };\ |
||
9159 | ctx.stroke();\ |
||
9160 | ctx.restore();\ |
||
7653 | schaersvoo | 9161 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 9162 | break; |
8224 | bpr | 9163 | |
7614 | schaersvoo | 9164 | case DRAW_INPUTS: |
13970 | obado | 9165 | fprintf(js_include_file,"\n/* draw input fields */\n\ |
11803 | schaersvoo | 9166 | var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\ |
7614 | schaersvoo | 9167 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
9168 | var input = document.createElement(\"input\");\ |
||
9169 | input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
9170 | input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
9171 | input.setAttribute(\"size\",size);\ |
||
9172 | input.setAttribute(\"value\",value);\ |
||
14276 | schaersvoo | 9173 | input.addEventListener(\"touchstart\", function(e){this.focus();},false);\ |
7877 | schaersvoo | 9174 | if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\ |
11803 | schaersvoo | 9175 | canvas_div.appendChild(input);\ |
9176 | if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\ |
||
9177 | };\ |
||
9178 | function center_input(id,x,y,style){\ |
||
9179 | var inp = document.getElementById(id);\ |
||
9180 | var pos = inp.getBoundingClientRect();\ |
||
9181 | var center_x = parseInt(x - 0.5*(pos.width));\ |
||
9182 | var center_y = parseInt(y - 0.5*(pos.height));\ |
||
9183 | try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\ |
||
9184 | catch(e){return;};\ |
||
9185 | };"); |
||
7614 | schaersvoo | 9186 | break; |
8224 | bpr | 9187 | |
7614 | schaersvoo | 9188 | case DRAW_TEXTAREAS: |
13970 | obado | 9189 | fprintf(js_include_file,"\n/* draw text area inputfields */\n\ |
8105 | schaersvoo | 9190 | var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\ |
7614 | schaersvoo | 9191 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
9192 | var textarea = document.createElement(\"textarea\");\ |
||
9193 | textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
9194 | textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
9195 | textarea.setAttribute(\"cols\",cols);\ |
||
9196 | textarea.setAttribute(\"rows\",rows);\ |
||
7877 | schaersvoo | 9197 | textarea.value = value;\ |
9198 | if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\ |
||
7653 | schaersvoo | 9199 | canvas_div.appendChild(textarea);};"); |
7614 | schaersvoo | 9200 | break; |
8224 | bpr | 9201 | |
7614 | schaersvoo | 9202 | case DRAW_PIXELS: |
13970 | obado | 9203 | fprintf(js_include_file,"\n/* draw pixel */\n\ |
8105 | schaersvoo | 9204 | var draw_setpixel = function(x,y,color,opacity,pixelsize){\ |
11997 | schaersvoo | 9205 | var idx = 2000+Math.ceil(1000*(Math.random()));\ |
9206 | var canvas = create_canvas%d(idx,xsize,ysize);\ |
||
7614 | schaersvoo | 9207 | var d = 0.5*pixelsize;\ |
9208 | var ctx = canvas.getContext(\"2d\");\ |
||
9462 | schaersvoo | 9209 | if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\ |
7614 | schaersvoo | 9210 | ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
9211 | ctx.clearRect(0,0,xsize,ysize);\ |
||
9212 | for(var p=0; p<x.length;p++){\ |
||
9213 | ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\ |
||
9214 | };\ |
||
9215 | ctx.fill();ctx.stroke();\ |
||
9216 | };",canvas_root_id); |
||
9217 | break; |
||
9218 | |||
9219 | case DRAW_CLOCK: |
||
13970 | obado | 9220 | fprintf(js_include_file,"\n/* begin command clock */\n\ |
7614 | schaersvoo | 9221 | var clock_canvas = create_canvas%d(%d,xsize,ysize);\ |
9222 | var clock_ctx = clock_canvas.getContext(\"2d\");\ |
||
9223 | var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\ |
||
8130 | schaersvoo | 9224 | clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\ |
7614 | schaersvoo | 9225 | clock_ctx.save();\ |
7997 | schaersvoo | 9226 | clock_ctx.globalAlpha = clock_bg_opacity;\ |
7614 | schaersvoo | 9227 | this.type = type || 0;\ |
9228 | this.interaction = interaction || 0;\ |
||
7862 | schaersvoo | 9229 | this.H = H;\ |
9230 | this.M = M;\ |
||
9231 | this.S = S;\ |
||
7614 | schaersvoo | 9232 | this.xc = xc || xsize/2;\ |
9233 | this.yc = yc || ysize/2;\ |
||
9234 | this.radius = radius || xsize/4;\ |
||
9235 | var font_size = parseInt(0.2*this.radius);\ |
||
11991 | schaersvoo | 9236 | this.H_color = h_color || \"black\";\ |
9237 | this.M_color = m_color || \"black\";\ |
||
9238 | this.S_color = s_color || \"black\";\ |
||
9239 | this.fg_color = fg_color || \"black\";\ |
||
7614 | schaersvoo | 9240 | this.bg_color = bg_color || \"white\";\ |
9241 | clock_ctx.translate(this.xc,this.yc);\ |
||
9242 | clock_ctx.beginPath();\ |
||
9243 | clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\ |
||
9244 | clock_ctx.fillStyle = this.bg_color;\ |
||
9245 | clock_ctx.fill();\ |
||
9246 | clock_ctx.closePath();\ |
||
9247 | clock_ctx.beginPath();\ |
||
9248 | clock_ctx.font = font_size+\"px Arial\";\ |
||
9249 | clock_ctx.fillStyle = this.fg_color;\ |
||
9250 | clock_ctx.textAlign = \"center\";\ |
||
9251 | clock_ctx.textBaseline = 'middle';\ |
||
9252 | var angle;var x1,y1,x2,y2;\ |
||
9253 | var angle_cos;var angle_sin;\ |
||
7997 | schaersvoo | 9254 | clock_ctx.globalAlpha = clock_fg_opacity;\ |
7614 | schaersvoo | 9255 | switch(type){\ |
9256 | case 0:clock_ctx.beginPath();\ |
||
9257 | for(var p = 1; p <= 12 ; p++){\ |
||
9258 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
9259 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
9260 | x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9261 | clock_ctx.moveTo(x1,y1);\ |
||
9262 | clock_ctx.lineTo(x2,y2);\ |
||
9263 | };\ |
||
9264 | for(var p = 1; p <= 60 ; p++){\ |
||
9265 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
9266 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
9267 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9268 | clock_ctx.moveTo(x1,y1);\ |
||
9269 | clock_ctx.lineTo(x2,y2);\ |
||
9270 | };\ |
||
9271 | clock_ctx.closePath();\ |
||
9272 | clock_ctx.stroke();\ |
||
9273 | break;\ |
||
9274 | case 1:\ |
||
9275 | 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 | 9276 | case 2:\ |
9277 | 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 | 9278 | clock_ctx.beginPath();\ |
9279 | for(var p = 1; p <= 12 ; p++){\ |
||
9280 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
9281 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
9282 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9283 | clock_ctx.moveTo(x1,y1);\ |
||
9284 | clock_ctx.lineTo(x2,y2);\ |
||
9285 | };\ |
||
9286 | for(var p = 1; p <= 60 ; p++){\ |
||
9287 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
9288 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
9289 | x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9290 | clock_ctx.moveTo(x1,y1);\ |
||
9291 | clock_ctx.lineTo(x2,y2);\ |
||
9292 | };\ |
||
9293 | clock_ctx.closePath();\ |
||
9294 | clock_ctx.stroke();\ |
||
9295 | break;\ |
||
9296 | };\ |
||
9297 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
||
9298 | clock_ctx.rotate(angle);\ |
||
9299 | clock_ctx.beginPath();\ |
||
9300 | clock_ctx.moveTo(-3, -2);\ |
||
9301 | clock_ctx.lineTo(-3, 2);\ |
||
11026 | bpr | 9302 | clock_ctx.lineTo(this.radius * 0.6, 1);\ |
9303 | clock_ctx.lineTo(this.radius * 0.6, -1);\ |
||
7614 | schaersvoo | 9304 | clock_ctx.fillStyle = this.H_color;\ |
9305 | clock_ctx.fill();\ |
||
9306 | clock_ctx.rotate(-angle);\ |
||
9307 | angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\ |
||
9308 | clock_ctx.rotate(angle);\ |
||
9309 | clock_ctx.beginPath();\ |
||
9310 | clock_ctx.moveTo(-3, -2);\ |
||
9311 | clock_ctx.lineTo(-3, 2);\ |
||
9312 | clock_ctx.lineTo(this.radius * 0.8, 1);\ |
||
9313 | clock_ctx.lineTo(this.radius * 0.8, -1);\ |
||
9314 | clock_ctx.fillStyle = this.M_color;\ |
||
9315 | clock_ctx.fill();\ |
||
9316 | clock_ctx.rotate(-angle);\ |
||
9317 | angle = (this.S - 15) * 2 * Math.PI / 60;\ |
||
9318 | clock_ctx.rotate(angle);\ |
||
9319 | clock_ctx.beginPath();\ |
||
9320 | clock_ctx.moveTo(0,0);\ |
||
11026 | bpr | 9321 | clock_ctx.lineTo(this.radius * 0.9, 1);\ |
9322 | clock_ctx.lineTo(this.radius * 0.9, -1);\ |
||
7614 | schaersvoo | 9323 | clock_ctx.strokeStyle = this.S_color;\ |
9324 | clock_ctx.stroke();\ |
||
9325 | clock_ctx.restore();\ |
||
7653 | schaersvoo | 9326 | };",canvas_root_id,CLOCK_CANVAS); |
7614 | schaersvoo | 9327 | break; |
9328 | |||
9329 | case DRAW_LATTICE: |
||
13970 | obado | 9330 | fprintf(js_include_file,"\n/* draw lattice */\n\ |
11991 | schaersvoo | 9331 | 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,use_filled){\ |
7614 | schaersvoo | 9332 | var obj;\ |
9333 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9334 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9335 | }\ |
||
9336 | else\ |
||
9337 | {\ |
||
9338 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9339 | };\ |
||
9340 | var ctx = obj.getContext(\"2d\");\ |
||
9341 | ctx.save();\ |
||
8071 | schaersvoo | 9342 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 9343 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
11874 | schaersvoo | 9344 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 9345 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 9346 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
9347 | var radius = line_width;\ |
||
9348 | var x = 0;\ |
||
9349 | var y = 0;\ |
||
9350 | var x_step_px = xsize/(xmax-xmin);\ |
||
9351 | var y_step_px = ysize/(ymax-ymin);\ |
||
9352 | var xv1 = dx1*x_step_px;\ |
||
9353 | var yv1 = dy1*y_step_px;\ |
||
9354 | var xv2 = dx2*x_step_px;\ |
||
9355 | var yv2 = dy2*y_step_px;\ |
||
9356 | for(var p = 0; p < n1 ;p++){\ |
||
9357 | x = p*xv1 + x0;\ |
||
9358 | y = p*yv1 + y0;\ |
||
9359 | for(var c = 0; c < n2 ; c++){\ |
||
9360 | ctx.beginPath();\ |
||
9361 | ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\ |
||
9362 | ctx.fill();\ |
||
9363 | ctx.stroke();\ |
||
9364 | ctx.closePath();\ |
||
9365 | };\ |
||
9366 | };\ |
||
9367 | ctx.restore();\ |
||
9368 | return;\ |
||
7653 | schaersvoo | 9369 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 9370 | break; |
7735 | schaersvoo | 9371 | case DRAW_XYLOGSCALE: |
13970 | obado | 9372 | fprintf(js_include_file,"\n/* draw xylogscale */\n\ |
8105 | schaersvoo | 9373 | 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 | 9374 | var obj;\ |
9375 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9376 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9377 | }\ |
||
9378 | else\ |
||
9379 | {\ |
||
9380 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9381 | };\ |
||
9382 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 9383 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 9384 | ctx.save();\ |
7739 | schaersvoo | 9385 | var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\ |
7956 | schaersvoo | 9386 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
9387 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
9388 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
||
9389 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
11972 | schaersvoo | 9390 | if(use_axis_numbering != -1){\ |
7956 | schaersvoo | 9391 | ctx.font = font_family;\ |
9392 | xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\ |
||
9393 | ymarge = parseInt(1.5*font_size);\ |
||
9394 | ctx.save();\ |
||
9395 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
9396 | ctx.rect(0,0,xmarge,ysize);\ |
||
9397 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
9398 | ctx.fill();\ |
||
9399 | ctx.restore();\ |
||
9400 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 9401 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9402 | ctx.save();\ |
9403 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9404 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9405 | corr = ctx.measureText(xaxislabel).width;\ |
||
9406 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
9407 | ctx.restore();\ |
||
9408 | };\ |
||
11088 | schaersvoo | 9409 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9410 | ctx.save();\ |
9411 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9412 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9413 | corr = ctx.measureText(yaxislabel).width;\ |
||
9414 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
9415 | ctx.rotate(-0.5*Math.PI);\ |
||
9416 | ctx.fillText(yaxislabel,0,0);\ |
||
9417 | ctx.restore();\ |
||
9418 | };\ |
||
9419 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9420 | ctx.lineWidth = line_width;\ |
||
9421 | for(var p = x_min; p <= x_max ; p++){\ |
||
9422 | num = Math.pow(xlogbase,p);\ |
||
9423 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
9424 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 9425 | if( i == 1 ){\ |
7956 | schaersvoo | 9426 | ctx.lineWidth = line_width;\ |
9427 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
11972 | schaersvoo | 9428 | if( use_axis_numbering != -1 && p > x_min){\ |
7956 | schaersvoo | 9429 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
9430 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
9431 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
9432 | };\ |
||
7735 | schaersvoo | 9433 | }else{\ |
7956 | schaersvoo | 9434 | ctx.lineWidth = 0.2*line_width;\ |
9435 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
9436 | };\ |
||
7738 | schaersvoo | 9437 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 9438 | ctx.beginPath();\ |
9439 | ctx.moveTo(x_e,0);\ |
||
9440 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
9441 | ctx.stroke();\ |
||
9442 | ctx.closePath();\ |
||
7738 | schaersvoo | 9443 | };\ |
7956 | schaersvoo | 9444 | };\ |
9445 | };\ |
||
9446 | for(var p = y_min; p <= y_max ; p++){\ |
||
9447 | num = Math.pow(ylogbase,p);\ |
||
9448 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
9449 | y_e = y2px(i*num);\ |
||
9450 | if( i == 1 ){\ |
||
9451 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 9452 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
11972 | schaersvoo | 9453 | if( use_axis_numbering != -1 && p > y_min){\ |
7956 | schaersvoo | 9454 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
9455 | };\ |
||
9456 | }else{\ |
||
9457 | ctx.lineWidth = 0.2*line_width;\ |
||
9458 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
9459 | };\ |
||
9460 | ctx.beginPath();\ |
||
9461 | ctx.moveTo(xmarge,y_e);\ |
||
9462 | ctx.lineTo(xsize,y_e);\ |
||
9463 | ctx.stroke();\ |
||
9464 | ctx.closePath();\ |
||
9465 | };\ |
||
9466 | };\ |
||
7735 | schaersvoo | 9467 | ctx.restore();\ |
9468 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
9469 | break; |
||
7614 | schaersvoo | 9470 | |
7735 | schaersvoo | 9471 | case DRAW_XLOGSCALE: |
13970 | obado | 9472 | fprintf(js_include_file,"\n/* draw xlogscale */\n\ |
8105 | schaersvoo | 9473 | 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 | 9474 | var obj;\ |
9475 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9476 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9477 | }\ |
||
9478 | else\ |
||
9479 | {\ |
||
9480 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9481 | };\ |
||
9482 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 9483 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 9484 | ctx.save();\ |
9485 | ctx.lineWidth = line_width;\ |
||
7739 | schaersvoo | 9486 | var prec = Math.log(precision)/Math.log(10);\ |
7735 | schaersvoo | 9487 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
9488 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
9489 | var y_min = 0;var y_max = ysize;var x_e;var corr;\ |
||
7739 | schaersvoo | 9490 | var xtxt;var ytxt;var num;var xmarge;var ymarge;\ |
11972 | schaersvoo | 9491 | if(use_axis_numbering != -1){\ |
7956 | schaersvoo | 9492 | ctx.font = font_family;\ |
9493 | xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\ |
||
9494 | ymarge = parseInt(1.5*font_size);\ |
||
9495 | ctx.save();\ |
||
9496 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
9497 | ctx.rect(0,0,xmarge,ysize);\ |
||
9498 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
9499 | ctx.fill();\ |
||
9500 | ctx.restore();\ |
||
9501 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 9502 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9503 | ctx.save();\ |
9504 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9505 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9506 | corr = ctx.measureText(xaxislabel).width;\ |
||
9507 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
9508 | ctx.restore();\ |
||
9509 | };\ |
||
11088 | schaersvoo | 9510 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9511 | ctx.save();\ |
9512 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9513 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9514 | corr = ctx.measureText(yaxislabel).width;\ |
||
9515 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
9516 | ctx.rotate(-0.5*Math.PI);\ |
||
9517 | ctx.fillText(yaxislabel,0,0);\ |
||
9518 | ctx.restore();\ |
||
9519 | };\ |
||
9520 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9521 | ctx.lineWidth = line_width;\ |
||
9522 | for(var p = x_min; p <= x_max ; p++){\ |
||
9523 | num = Math.pow(xlogbase,p);\ |
||
9524 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
9525 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 9526 | if( i == 1 ){\ |
7956 | schaersvoo | 9527 | ctx.lineWidth = line_width;\ |
7739 | schaersvoo | 9528 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
11972 | schaersvoo | 9529 | if( use_axis_numbering != -1 && p > x_min ){\ |
7735 | schaersvoo | 9530 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
9531 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
9532 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
9533 | };\ |
||
9534 | }else{\ |
||
7956 | schaersvoo | 9535 | ctx.lineWidth = 0.2*line_width;\ |
7735 | schaersvoo | 9536 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
9537 | };\ |
||
7739 | schaersvoo | 9538 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 9539 | ctx.beginPath();\ |
9540 | ctx.moveTo(x_e,0);\ |
||
9541 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
9542 | ctx.stroke();\ |
||
9543 | ctx.closePath();\ |
||
7739 | schaersvoo | 9544 | };\ |
9545 | };\ |
||
7956 | schaersvoo | 9546 | };\ |
7735 | schaersvoo | 9547 | var stepy = Math.abs(y2px(ymajor) - y2px(0));\ |
9548 | var minor_step = stepy / yminor;\ |
||
7749 | schaersvoo | 9549 | for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\ |
7735 | schaersvoo | 9550 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 9551 | ctx.lineWidth = line_width;\ |
9552 | ctx.beginPath();\ |
||
9553 | ctx.moveTo(xmarge,y);\ |
||
9554 | ctx.lineTo(xsize,y);\ |
||
9555 | ctx.stroke();\ |
||
9556 | ctx.closePath();\ |
||
11972 | schaersvoo | 9557 | if( use_axis_numbering != -1){\ |
7735 | schaersvoo | 9558 | ytxt = (px2y(y)).toFixed(prec);\ |
9559 | ctx.fillText( ytxt,0 ,y + 0.5*font_size );\ |
||
9560 | };\ |
||
9561 | for(var dy = 1 ; dy < yminor ; dy++){\ |
||
9562 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 9563 | ctx.lineWidth = 0.2*line_width;\ |
9564 | ctx.beginPath();\ |
||
7739 | schaersvoo | 9565 | ctx.moveTo(xmarge,y+dy*minor_step);\ |
7956 | schaersvoo | 9566 | ctx.lineTo(xsize,y+dy*minor_step);\ |
9567 | ctx.stroke();\ |
||
9568 | ctx.closePath();\ |
||
7735 | schaersvoo | 9569 | };\ |
9570 | };\ |
||
7956 | schaersvoo | 9571 | ctx.restore();\ |
9572 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7735 | schaersvoo | 9573 | break; |
7729 | schaersvoo | 9574 | case DRAW_YLOGSCALE: |
13970 | obado | 9575 | fprintf(js_include_file,"\n/* draw ylogscale */\n\ |
8105 | schaersvoo | 9576 | 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 | 9577 | var obj;\ |
9578 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9579 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9580 | }\ |
||
9581 | else\ |
||
9582 | {\ |
||
9583 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9584 | };\ |
||
9585 | var ctx = obj.getContext(\"2d\");\ |
||
7729 | schaersvoo | 9586 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 9587 | ctx.save();\ |
9588 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 9589 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
9590 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
8109 | schaersvoo | 9591 | var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\ |
11972 | schaersvoo | 9592 | if(use_axis_numbering != -1){\ |
7956 | schaersvoo | 9593 | ctx.font = font_family;\ |
9594 | xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\ |
||
9595 | ymarge = 2*font_size;\ |
||
9596 | ctx.save();\ |
||
9597 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
9598 | ctx.rect(0,0,xmarge,ysize);\ |
||
9599 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
9600 | ctx.fill();\ |
||
9601 | ctx.restore();\ |
||
9602 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 9603 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9604 | ctx.save();\ |
9605 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9606 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9607 | corr = ctx.measureText(xaxislabel).width;\ |
||
9608 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
9609 | ctx.restore();\ |
||
9610 | };\ |
||
11088 | schaersvoo | 9611 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9612 | ctx.save();\ |
9613 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9614 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9615 | corr = ctx.measureText(yaxislabel).width;\ |
||
9616 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
9617 | ctx.rotate(-0.5*Math.PI);\ |
||
9618 | ctx.fillText(yaxislabel,0,0);\ |
||
9619 | ctx.restore();\ |
||
9620 | };\ |
||
9621 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9622 | ctx.lineWidth = line_width;\ |
||
9623 | for(var p = y_min; p <= y_max ; p++){\ |
||
9624 | num = Math.pow(ylogbase,p);\ |
||
9625 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
9626 | y_e = y2px(i*num);\ |
||
7729 | schaersvoo | 9627 | if( i == 1 ){\ |
7956 | schaersvoo | 9628 | ctx.lineWidth = line_width;\ |
7729 | schaersvoo | 9629 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
11972 | schaersvoo | 9630 | if( use_axis_numbering != -1 && p > y_min){\ |
7735 | schaersvoo | 9631 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
7729 | schaersvoo | 9632 | };\ |
9633 | }else{\ |
||
7956 | schaersvoo | 9634 | ctx.lineWidth = 0.2*line_width;\ |
7729 | schaersvoo | 9635 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
9636 | };\ |
||
7956 | schaersvoo | 9637 | ctx.beginPath();\ |
9638 | ctx.moveTo(xmarge,y_e);\ |
||
9639 | ctx.lineTo(xsize,y_e);\ |
||
9640 | ctx.stroke();\ |
||
9641 | ctx.closePath();\ |
||
9642 | };\ |
||
9643 | };\ |
||
7729 | schaersvoo | 9644 | var stepx = Math.abs(x2px(xmajor) - x2px(0));\ |
9645 | var minor_step = stepx / xminor;\ |
||
9646 | var prec = Math.log(precision)/Math.log(10);\ |
||
9647 | var xtxt;var corr;var flip = 0;\ |
||
7749 | schaersvoo | 9648 | for(var x = stepx ; x < xsize ; x = x + stepx){\ |
7729 | schaersvoo | 9649 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 9650 | ctx.lineWidth = line_width;\ |
9651 | ctx.beginPath();\ |
||
9652 | ctx.moveTo(x,ysize-ymarge);\ |
||
9653 | ctx.lineTo(x,0);\ |
||
9654 | ctx.stroke();\ |
||
9655 | ctx.closePath();\ |
||
11972 | schaersvoo | 9656 | if( use_axis_numbering != -1){\ |
7729 | schaersvoo | 9657 | xtxt = (px2x(x)).toFixed(prec);\ |
9658 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
9659 | if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\ |
||
9660 | flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\ |
||
9661 | };\ |
||
9662 | for(var dx = 1 ; dx < xminor ; dx++){\ |
||
9663 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 9664 | ctx.lineWidth = 0.2*line_width;\ |
9665 | ctx.beginPath();\ |
||
7739 | schaersvoo | 9666 | ctx.moveTo(x+dx*minor_step,ysize - ymarge);\ |
7956 | schaersvoo | 9667 | ctx.lineTo(x+dx*minor_step,0);\ |
9668 | ctx.stroke();\ |
||
9669 | ctx.closePath();\ |
||
7735 | schaersvoo | 9670 | };\ |
9671 | };\ |
||
7956 | schaersvoo | 9672 | ctx.restore();\ |
9673 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7729 | schaersvoo | 9674 | break; |
9213 | schaersvoo | 9675 | |
7614 | schaersvoo | 9676 | default:break; |
9677 | } |
||
9678 | } |
||
9679 | } |
||
9680 | return; |
||
9681 | } |
||
9682 | |||
9683 | void check_string_length(int L){ |
||
9466 | schaersvoo | 9684 | if( L > MAX_BUFFER-1){ |
7614 | schaersvoo | 9685 | canvas_error("problem with your arguments to command..."); |
9686 | } |
||
9687 | return; |
||
9688 | } |
||
9689 | |||
9690 | |||
9691 | int get_token(FILE *infile){ |
||
9692 | int c,i=0; |
||
9693 | char temp[MAX_INT], *input_type; |
||
9694 | char *line="line", |
||
9695 | *audio="audio", |
||
9696 | *blink="blink", |
||
9697 | *arrowhead="arrowhead", |
||
9698 | *crosshairsize="crosshairsize", |
||
9699 | *crosshair="crosshair", |
||
9700 | *crosshairs="crosshairs", |
||
9701 | *audioobject="audioobject", |
||
9702 | *style="style", |
||
9703 | *mouse="mouse", |
||
7991 | schaersvoo | 9704 | *mousex="mousex", |
9705 | *mousey="mousey", |
||
8071 | schaersvoo | 9706 | *mouse_display="display", |
9707 | *mouse_degree="mouse_degree", |
||
7614 | schaersvoo | 9708 | *userdraw="userdraw", |
9709 | *highlight="highlight", |
||
9710 | *http="http", |
||
9711 | *rays="rays", |
||
9712 | *dashtype="dashtype", |
||
9713 | *dashed="dashed", |
||
9714 | *filled="filled", |
||
9715 | *lattice="lattice", |
||
9716 | *parallel="parallel", |
||
9717 | *segment="segment", |
||
8299 | schaersvoo | 9718 | *segments="segments", |
7614 | schaersvoo | 9719 | *dsegment="dsegment", |
9374 | schaersvoo | 9720 | *dsegments="dsegments", |
7614 | schaersvoo | 9721 | *seg="seg", |
9383 | schaersvoo | 9722 | *segs="segs", |
7614 | schaersvoo | 9723 | *bgimage="bgimage", |
9724 | *bgcolor="bgcolor", |
||
9725 | *strokecolor="strokecolor", |
||
9726 | *backgroundimage="backgroundimage", |
||
9727 | *text="text", |
||
9728 | *textup="textup", |
||
9729 | *mouseprecision="mouseprecision", |
||
9730 | *precision="precision", |
||
9731 | *plotsteps="plotsteps", |
||
9732 | *plotstep="plotstep", |
||
9733 | *tsteps="tsteps", |
||
9734 | *curve="curve", |
||
9735 | *dcurve="dcurve", |
||
14038 | schaersvoo | 9736 | *curvedarrow="curvedarrow", |
9737 | *curvedarrows="curvedarrows", |
||
9738 | *curvedarrow2="curvedarrow2", |
||
9739 | *curvedarrows2="curvedarrows2", |
||
7614 | schaersvoo | 9740 | *plot="plot", |
9741 | *dplot="dplot", |
||
7788 | schaersvoo | 9742 | *levelcurve="levelcurve", |
7614 | schaersvoo | 9743 | *fontsize="fontsize", |
9744 | *fontcolor="fontcolor", |
||
9745 | *axis="axis", |
||
9746 | *axisnumbering="axisnumbering", |
||
9747 | *axisnumbers="axisnumbers", |
||
9748 | *arrow="arrow", |
||
9382 | schaersvoo | 9749 | *vector="vector", |
9750 | *vectors="vectors", |
||
7614 | schaersvoo | 9751 | *darrow="darrow", |
9752 | *arrow2="arrow2", |
||
9753 | *darrow2="darrow2", |
||
8304 | schaersvoo | 9754 | *arrows="arrows", |
8347 | schaersvoo | 9755 | *arrows2="arrows2", |
7614 | schaersvoo | 9756 | *zoom="zoom", |
9757 | *grid="grid", |
||
9758 | *hline="hline", |
||
7786 | schaersvoo | 9759 | *dhline="dhline", |
7614 | schaersvoo | 9760 | *drag="drag", |
9761 | *horizontalline="horizontalline", |
||
9383 | schaersvoo | 9762 | *horizontallines="horizontallines", |
7614 | schaersvoo | 9763 | *vline="vline", |
7786 | schaersvoo | 9764 | *dvline="dvline", |
7614 | schaersvoo | 9765 | *verticalline="verticalline", |
9383 | schaersvoo | 9766 | *verticallines="verticallines", |
7614 | schaersvoo | 9767 | *triangle="triangle", |
9306 | schaersvoo | 9768 | *triangles="triangles", |
7614 | schaersvoo | 9769 | *ftriangle="ftriangle", |
9374 | schaersvoo | 9770 | *ftriangles="ftriangles", |
7614 | schaersvoo | 9771 | *mathml="mathml", |
9772 | *html="html", |
||
9773 | *input="input", |
||
8146 | schaersvoo | 9774 | *clearbutton="clearbutton", |
9386 | schaersvoo | 9775 | *erase="erase", |
9776 | *delete="delete", |
||
7614 | schaersvoo | 9777 | *inputstyle="inputstyle", |
9778 | *textarea="textarea", |
||
9779 | *trange="trange", |
||
9780 | *ranget="ranget", |
||
9781 | *xrange="xrange", |
||
9782 | *yrange="yrange", |
||
9783 | *rangex="rangex", |
||
9784 | *rangey="rangey", |
||
8370 | schaersvoo | 9785 | *path="path", |
7614 | schaersvoo | 9786 | *polyline="polyline", |
8351 | schaersvoo | 9787 | *brokenline="brokenline", |
7614 | schaersvoo | 9788 | *lines="lines", |
9789 | *poly="poly", |
||
9790 | *polygon="polygon", |
||
9791 | *fpolygon="fpolygon", |
||
9792 | *fpoly="fpoly", |
||
9793 | *filledpoly="filledpoly", |
||
9794 | *filledpolygon="filledpolygon", |
||
9795 | *rect="rect", |
||
9796 | *frect="frect", |
||
9797 | *rectangle="rectangle", |
||
9798 | *frectangle="frectangle", |
||
9799 | *square="square", |
||
9800 | *fsquare="fsquare", |
||
9374 | schaersvoo | 9801 | *fsquares="fsquares", |
8363 | schaersvoo | 9802 | *rects="rects", |
9803 | *frects="frects", |
||
7614 | schaersvoo | 9804 | *dline="dline", |
9805 | *arc="arc", |
||
9806 | *filledarc="filledarc", |
||
9374 | schaersvoo | 9807 | *farc="farc", |
7614 | schaersvoo | 9808 | *size="size", |
9809 | *string="string", |
||
9810 | *stringup="stringup", |
||
9811 | *copy="copy", |
||
9812 | *copyresized="copyresized", |
||
9813 | *opacity="opacity", |
||
9814 | *transparent="transparent", |
||
9815 | *fill="fill", |
||
9816 | *point="point", |
||
9817 | *points="points", |
||
9818 | *linewidth="linewidth", |
||
9819 | *circle="circle", |
||
8304 | schaersvoo | 9820 | *circles="circles", |
7614 | schaersvoo | 9821 | *fcircle="fcircle", |
9374 | schaersvoo | 9822 | *fcircles="fcircles", |
7614 | schaersvoo | 9823 | *disk="disk", |
9374 | schaersvoo | 9824 | *disks="disks", |
7614 | schaersvoo | 9825 | *comment="#", |
9826 | *end="end", |
||
9827 | *ellipse="ellipse", |
||
12110 | schaersvoo | 9828 | *ellipses="ellipses", |
7614 | schaersvoo | 9829 | *fellipse="fellipse", |
9830 | *rotate="rotate", |
||
7785 | schaersvoo | 9831 | *affine="affine", |
9907 | schaersvoo | 9832 | *rotationcenter="rotationcenter", |
9833 | *killrotate="killrotate", |
||
7785 | schaersvoo | 9834 | *killaffine="killaffine", |
7614 | schaersvoo | 9835 | *fontfamily="fontfamily", |
9836 | *fillcolor="fillcolor", |
||
9837 | *clicktile="clicktile", |
||
9838 | *clicktile_colors="clicktile_colors", |
||
9839 | *translation="translation", |
||
9840 | *translate="translate", |
||
9841 | *killtranslation="killtranslation", |
||
9842 | *killtranslate="killtranslate", |
||
9843 | *onclick="onclick", |
||
8370 | schaersvoo | 9844 | *roundrects="roundrects", |
7614 | schaersvoo | 9845 | *roundrect="roundrect", |
9846 | *froundrect="froundrect", |
||
9374 | schaersvoo | 9847 | *froundrects="froundrects", |
7614 | schaersvoo | 9848 | *roundrectangle="roundrectangle", |
9849 | *patternfill="patternfill", |
||
9850 | *hatchfill="hatchfill", |
||
9851 | *diafill="diafill", |
||
7647 | schaersvoo | 9852 | *diamondfill="diamondfill", |
7614 | schaersvoo | 9853 | *dotfill="dotfill", |
11830 | schaersvoo | 9854 | *textfill="textfill", |
7614 | schaersvoo | 9855 | *gridfill="gridfill", |
9856 | *imagefill="imagefill", |
||
7735 | schaersvoo | 9857 | *xlogbase="xlogbase", |
9858 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 9859 | *xlogscale="xlogscale", |
9860 | *ylogscale="ylogscale", |
||
9861 | *xylogscale="xylogscale", |
||
9862 | *intooltip="intooltip", |
||
9329 | schaersvoo | 9863 | *popup="popup", |
7614 | schaersvoo | 9864 | *replyformat="replyformat", |
9865 | *floodfill="floodfill", |
||
11772 | schaersvoo | 9866 | *fillall="fillall", |
7614 | schaersvoo | 9867 | *filltoborder="filltoborder", |
9868 | *setpixel="setpixel", |
||
9869 | *pixels="pixels", |
||
9870 | *pixelsize="pixelsize", |
||
9871 | *xaxis="xaxis", |
||
9341 | schaersvoo | 9872 | *xaxisup="xaxisup", |
7614 | schaersvoo | 9873 | *yaxis="yaxis", |
9874 | *xaxistext="xaxistext", |
||
9341 | schaersvoo | 9875 | *xaxistextup="xaxistextup", |
7614 | schaersvoo | 9876 | *yaxistext="yaxistext", |
9877 | *piechart="piechart", |
||
9433 | schaersvoo | 9878 | *boxplot="boxplot", |
9465 | schaersvoo | 9879 | *boxplotdata="boxplotdata", |
9880 | *userboxplot="userboxplot", |
||
9881 | *userboxplotdata="userboxplotdata", |
||
7614 | schaersvoo | 9882 | *legend="legend", |
9883 | *legendcolors="legendcolors", |
||
9884 | *xlabel="xlabel", |
||
9885 | *ylabel="ylabel", |
||
9886 | *barchart="barchart", |
||
9887 | *linegraph="linegraph", |
||
9888 | *clock="clock", |
||
9889 | *animate="animate", |
||
9890 | *video="video", |
||
9891 | *status="status", |
||
7877 | schaersvoo | 9892 | *nostatus="nostatus", |
7652 | schaersvoo | 9893 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 9894 | *xsnaptogrid="xsnaptogrid", |
9895 | *ysnaptogrid="ysnaptogrid", |
||
8379 | schaersvoo | 9896 | *snaptopoints="snaptopoints", |
9213 | schaersvoo | 9897 | *snaptofunction="snaptofunction", |
9898 | *snaptofun="snaptofun", |
||
7654 | schaersvoo | 9899 | *userinput_xy="userinput_xy", |
8193 | schaersvoo | 9900 | *userinput_function="userinput_function", |
7663 | schaersvoo | 9901 | *usertextarea_xy="usertextarea_xy", |
8222 | schaersvoo | 9902 | *userinput="userinput", |
7823 | schaersvoo | 9903 | *jsmath="jsmath", |
7858 | schaersvoo | 9904 | *trace_jscurve="trace_jscurve", |
7838 | schaersvoo | 9905 | *setlimits="setlimits", |
7858 | schaersvoo | 9906 | *jscurve="jscurve", |
9907 | *jsplot="jsplot", |
||
7983 | schaersvoo | 9908 | *sgraph="sgraph", |
7984 | schaersvoo | 9909 | *title="title", |
7996 | schaersvoo | 9910 | *centerstring="centerstring", |
9911 | *xunit="xunit", |
||
8071 | schaersvoo | 9912 | *yunit="yunit", |
8101 | schaersvoo | 9913 | *slider="slider", |
8105 | schaersvoo | 9914 | *killslider="killslider", |
8244 | schaersvoo | 9915 | *angle="angle", |
8365 | schaersvoo | 9916 | *halflines="halflines", |
9917 | *demilines="demilines", |
||
8244 | schaersvoo | 9918 | *halfline="halfline", |
8297 | schaersvoo | 9919 | *demiline="demiline", |
8366 | schaersvoo | 9920 | *hlines="hlines", |
9921 | *vlines="vlines", |
||
8370 | schaersvoo | 9922 | *bezier="bezier", |
9213 | schaersvoo | 9923 | *functionlabel="functionlabel", |
9924 | *sliderfunction_x="sliderfunction_x", |
||
9925 | *sliderfunction_y="sliderfunction_y", |
||
9926 | *multidraw="multidraw", |
||
14622 | schaersvoo | 9927 | *linewidths="linewidths", |
9213 | schaersvoo | 9928 | *multilinewidth="multilinewidth", |
9929 | *multistrokecolors="multistrokecolors", |
||
14622 | schaersvoo | 9930 | *multicolors="multistrokecolors", |
9931 | *colors="colors", |
||
9213 | schaersvoo | 9932 | *multifillcolors="multifillcolors", |
14622 | schaersvoo | 9933 | *fillcolors="fillcolors", |
9213 | schaersvoo | 9934 | *multistrokeopacity="multistrokeopacity", |
9935 | *multifillopacity="multifillopacity", |
||
9936 | *multifill="multifill", |
||
9937 | *multidash="multidash", |
||
9938 | *multilabel="multilabel", |
||
9939 | *multiuserinput="multiuserinput", |
||
14038 | schaersvoo | 9940 | *multiinput="multiinput", |
9289 | schaersvoo | 9941 | *multisnaptogrid="multisnaptogrid", |
14038 | schaersvoo | 9942 | *multisnap="multisnap", |
9289 | schaersvoo | 9943 | *protractor="protractor", |
9386 | schaersvoo | 9944 | *ruler="ruler", |
9945 | *cursor="cursor", |
||
9427 | schaersvoo | 9946 | *pointer="pointer", |
9947 | *yerrorbars="yerrorbars", |
||
11006 | schaersvoo | 9948 | *xerrorbars="xerrorbars", |
11044 | schaersvoo | 9949 | *noxaxis="noxaxis", |
9950 | *noyaxis="noyaxis", |
||
11767 | schaersvoo | 9951 | *colorpalette="colorpalette", |
14038 | schaersvoo | 9952 | *imagepalette="imagepalette", |
12063 | schaersvoo | 9953 | *yoffset="yoffset", |
11802 | schaersvoo | 9954 | *xoffset="xoffset", |
14225 | schaersvoo | 9955 | *latex="latex", |
11802 | schaersvoo | 9956 | *centered="centered", |
9957 | *xyoffset="xyoffset", |
||
9958 | *resetoffset="resetoffset", |
||
11837 | schaersvoo | 9959 | *fillpattern="fillpattern", |
11890 | schaersvoo | 9960 | *numberline="numberline", |
14393 | schaersvoo | 9961 | *duplicates="duplicates", |
9962 | *allowdups="allowdups", |
||
11006 | schaersvoo | 9963 | *canvastype="canvastype"; |
7614 | schaersvoo | 9964 | |
10891 | schaersvoo | 9965 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){ |
9966 | if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */ |
||
9967 | }else{ |
||
9968 | if( c == ' ' ){ |
||
7614 | schaersvoo | 9969 | break; |
10891 | schaersvoo | 9970 | }else{ |
9971 | temp[i] = c; |
||
9972 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
9973 | i++; |
||
9974 | } |
||
9975 | } |
||
9976 | if(temp[0] == '#'){ break; } |
||
7614 | schaersvoo | 9977 | } |
10891 | schaersvoo | 9978 | if (c == '\n' || c == '\r' || c == '\t' ){ line_number++; } |
9979 | if (c == EOF) {finished=1;return 0;} |
||
7614 | schaersvoo | 9980 | |
9981 | temp[i]='\0'; |
||
9982 | input_type=(char*)my_newmem(strlen(temp)); |
||
9983 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
10891 | schaersvoo | 9984 | /* fprintf(stdout,"temp = %s <br/>",input_type); */ |
7614 | schaersvoo | 9985 | if( strcmp(input_type, size) == 0 ){ |
9986 | free(input_type); |
||
9987 | return SIZE; |
||
9988 | } |
||
9989 | if( strcmp(input_type, xrange) == 0 ){ |
||
9990 | free(input_type); |
||
9991 | return XRANGE; |
||
9992 | } |
||
9993 | if( strcmp(input_type, rangex) == 0 ){ |
||
9994 | free(input_type); |
||
9995 | return XRANGE; |
||
9996 | } |
||
9997 | if( strcmp(input_type, trange) == 0 ){ |
||
9998 | free(input_type); |
||
9999 | return TRANGE; |
||
10000 | } |
||
10001 | if( strcmp(input_type, ranget) == 0 ){ |
||
10002 | free(input_type); |
||
10003 | return TRANGE; |
||
10004 | } |
||
10005 | if( strcmp(input_type, yrange) == 0 ){ |
||
10006 | free(input_type); |
||
10007 | return YRANGE; |
||
10008 | } |
||
10009 | if( strcmp(input_type, rangey) == 0 ){ |
||
10010 | free(input_type); |
||
10011 | return YRANGE; |
||
10012 | } |
||
10013 | if( strcmp(input_type, linewidth) == 0 ){ |
||
10014 | free(input_type); |
||
10015 | return LINEWIDTH; |
||
10016 | } |
||
10017 | if( strcmp(input_type, dashed) == 0 ){ |
||
10018 | free(input_type); |
||
10019 | return DASHED; |
||
10020 | } |
||
10021 | if( strcmp(input_type, dashtype) == 0 ){ |
||
10022 | free(input_type); |
||
10023 | return DASHTYPE; |
||
10024 | } |
||
10025 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
10026 | free(input_type); |
||
10027 | return AXIS_NUMBERING; |
||
10028 | } |
||
10029 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
10030 | free(input_type); |
||
10031 | return AXIS_NUMBERING; |
||
10032 | } |
||
10033 | if( strcmp(input_type, axis) == 0 ){ |
||
10034 | free(input_type); |
||
10035 | return AXIS; |
||
10036 | } |
||
10037 | if( strcmp(input_type, grid) == 0 ){ |
||
10038 | free(input_type); |
||
10039 | return GRID; |
||
10040 | } |
||
9383 | schaersvoo | 10041 | if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){ |
8366 | schaersvoo | 10042 | free(input_type); |
10043 | return HLINES; |
||
10044 | } |
||
9383 | schaersvoo | 10045 | if( strcmp(input_type, vlines) == 0 || strcmp(input_type, verticallines) == 0 ){ |
8366 | schaersvoo | 10046 | free(input_type); |
10047 | return VLINES; |
||
10048 | } |
||
9383 | schaersvoo | 10049 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
7614 | schaersvoo | 10050 | free(input_type); |
10051 | return HLINE; |
||
10052 | } |
||
10053 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
10054 | free(input_type); |
||
10055 | return VLINE; |
||
10056 | } |
||
10057 | if( strcmp(input_type, line) == 0 ){ |
||
10058 | free(input_type); |
||
10059 | return LINE; |
||
10060 | } |
||
9383 | schaersvoo | 10061 | if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){ |
8299 | schaersvoo | 10062 | free(input_type); |
10063 | return SEGMENTS; |
||
10064 | } |
||
7614 | schaersvoo | 10065 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
10066 | free(input_type); |
||
10067 | return SEGMENT; |
||
10068 | } |
||
9374 | schaersvoo | 10069 | if( strcmp(input_type, dsegments) == 0 ){ |
10070 | free(input_type); |
||
10071 | use_dashed = TRUE; |
||
10072 | return SEGMENTS; |
||
10073 | } |
||
7614 | schaersvoo | 10074 | if( strcmp(input_type, dsegment) == 0 ){ |
10075 | free(input_type); |
||
10076 | use_dashed = TRUE; |
||
10077 | return SEGMENT; |
||
10078 | } |
||
10079 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
10080 | free(input_type); |
||
10081 | return CROSSHAIRSIZE; |
||
10082 | } |
||
10083 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
10084 | free(input_type); |
||
10085 | return ARROWHEAD; |
||
10086 | } |
||
10087 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
10088 | free(input_type); |
||
10089 | return CROSSHAIRS; |
||
10090 | } |
||
10091 | if( strcmp(input_type, crosshair) == 0 ){ |
||
10092 | free(input_type); |
||
10093 | return CROSSHAIR; |
||
10094 | } |
||
10095 | if( strcmp(input_type, onclick) == 0 ){ |
||
10096 | free(input_type); |
||
10097 | return ONCLICK; |
||
10098 | } |
||
10099 | if( strcmp(input_type, drag) == 0 ){ |
||
10100 | free(input_type); |
||
10101 | return DRAG; |
||
10102 | } |
||
10103 | if( strcmp(input_type, userdraw) == 0 ){ |
||
10104 | free(input_type); |
||
10105 | return USERDRAW; |
||
10106 | } |
||
10107 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
10108 | free(input_type); |
||
10109 | return STYLE; |
||
10110 | } |
||
10111 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
10112 | free(input_type); |
||
10113 | return FILLCOLOR; |
||
10114 | } |
||
10115 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
10116 | free(input_type); |
||
10117 | return STROKECOLOR; |
||
10118 | } |
||
10119 | if( strcmp(input_type, filled) == 0 ){ |
||
10120 | free(input_type); |
||
10121 | return FILLED; |
||
10122 | } |
||
10123 | if( strcmp(input_type, http) == 0 ){ |
||
10124 | free(input_type); |
||
10125 | return HTTP; |
||
10126 | } |
||
10127 | if( strcmp(input_type, rays) == 0 ){ |
||
10128 | free(input_type); |
||
10129 | return RAYS; |
||
10130 | } |
||
10131 | if( strcmp(input_type, lattice) == 0 ){ |
||
10132 | free(input_type); |
||
10133 | return LATTICE; |
||
10134 | } |
||
10135 | if( strcmp(input_type, bgimage) == 0 ){ |
||
10136 | free(input_type); |
||
10137 | return BGIMAGE; |
||
10138 | } |
||
10139 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
10140 | free(input_type); |
||
10141 | return BGCOLOR; |
||
10142 | } |
||
10143 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
10144 | free(input_type); |
||
10145 | return BGIMAGE; |
||
10146 | } |
||
10147 | if( strcmp(input_type, text) == 0 ){ |
||
10148 | free(input_type); |
||
10149 | return FLY_TEXT; |
||
10150 | } |
||
10151 | if( strcmp(input_type, textup) == 0 ){ |
||
10152 | free(input_type); |
||
10153 | return FLY_TEXTUP; |
||
10154 | } |
||
10155 | if( strcmp(input_type, mouse) == 0 ){ |
||
10156 | free(input_type); |
||
10157 | return MOUSE; |
||
10158 | } |
||
7991 | schaersvoo | 10159 | if( strcmp(input_type, mousex) == 0 ){ |
10160 | free(input_type); |
||
10161 | return MOUSEX; |
||
10162 | } |
||
10163 | if( strcmp(input_type, mousey) == 0 ){ |
||
10164 | free(input_type); |
||
10165 | return MOUSEY; |
||
10166 | } |
||
8071 | schaersvoo | 10167 | if( strcmp(input_type, mouse_degree) == 0 ){ |
10168 | free(input_type); |
||
10169 | return MOUSE_DEGREE; |
||
10170 | } |
||
10171 | if( strcmp(input_type, mouse_display) == 0 ){ |
||
10172 | free(input_type); |
||
10173 | return MOUSE_DISPLAY; |
||
10174 | } |
||
7614 | schaersvoo | 10175 | if( strcmp(input_type, mouseprecision) == 0 ){ |
10176 | free(input_type); |
||
10177 | return MOUSE_PRECISION; |
||
10178 | } |
||
10179 | if( strcmp(input_type, precision) == 0 ){ |
||
10180 | free(input_type); |
||
10181 | return MOUSE_PRECISION; |
||
10182 | } |
||
10183 | if( strcmp(input_type, curve) == 0 ){ |
||
10184 | free(input_type); |
||
10185 | return CURVE; |
||
10186 | } |
||
10187 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 10188 | use_dashed = TRUE; |
7614 | schaersvoo | 10189 | free(input_type); |
10190 | return CURVE; |
||
10191 | } |
||
10192 | if( strcmp(input_type, plot) == 0 ){ |
||
10193 | free(input_type); |
||
10194 | return CURVE; |
||
10195 | } |
||
10196 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 10197 | use_dashed = TRUE; |
7614 | schaersvoo | 10198 | free(input_type); |
10199 | return CURVE; |
||
10200 | } |
||
7788 | schaersvoo | 10201 | if( strcmp(input_type, levelcurve) == 0 ){ |
10202 | free(input_type); |
||
10203 | return LEVELCURVE; |
||
10204 | } |
||
7614 | schaersvoo | 10205 | if( strcmp(input_type, plotsteps) == 0 ){ |
10206 | free(input_type); |
||
10207 | return PLOTSTEPS; |
||
10208 | } |
||
10209 | if( strcmp(input_type, plotstep) == 0 ){ |
||
10210 | free(input_type); |
||
10211 | return PLOTSTEPS; |
||
10212 | } |
||
10213 | if( strcmp(input_type, tsteps) == 0 ){ |
||
10214 | free(input_type); |
||
10215 | return PLOTSTEPS; |
||
10216 | } |
||
10217 | if( strcmp(input_type, fontsize) == 0 ){ |
||
10218 | free(input_type); |
||
10219 | return FONTSIZE; |
||
10220 | } |
||
10221 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
10222 | free(input_type); |
||
10223 | return FONTCOLOR; |
||
10224 | } |
||
10225 | if( strcmp(input_type, arrow2) == 0 ){ |
||
10226 | free(input_type); |
||
10227 | return ARROW2; |
||
10228 | } |
||
10229 | if( strcmp(input_type, darrow) == 0 ){ |
||
10230 | free(input_type); |
||
8071 | schaersvoo | 10231 | use_dashed = TRUE; |
7614 | schaersvoo | 10232 | return ARROW; |
10233 | } |
||
10234 | if( strcmp(input_type, darrow2) == 0 ){ |
||
10235 | free(input_type); |
||
10236 | use_dashed = TRUE; |
||
10237 | return ARROW2; |
||
10238 | } |
||
8347 | schaersvoo | 10239 | if( strcmp(input_type, arrows2) == 0 ){ |
10240 | free(input_type); |
||
10241 | return ARROWS2; |
||
10242 | } |
||
9382 | schaersvoo | 10243 | if( strcmp(input_type, arrows) == 0 || strcmp(input_type, vectors) == 0 ){ |
8304 | schaersvoo | 10244 | free(input_type); |
10245 | return ARROWS; |
||
10246 | } |
||
9382 | schaersvoo | 10247 | if( strcmp(input_type, arrow) == 0 || strcmp(input_type, vector) == 0 ){ |
8304 | schaersvoo | 10248 | free(input_type); |
10249 | return ARROW; |
||
10250 | } |
||
7614 | schaersvoo | 10251 | if( strcmp(input_type, zoom) == 0 ){ |
10252 | free(input_type); |
||
10253 | return ZOOM; |
||
10254 | } |
||
10255 | if( strcmp(input_type, triangle) == 0 ){ |
||
10256 | free(input_type); |
||
10257 | return TRIANGLE; |
||
10258 | } |
||
9306 | schaersvoo | 10259 | if( strcmp(input_type, triangles) == 0 ){ |
10260 | free(input_type); |
||
10261 | return TRIANGLES; |
||
10262 | } |
||
9374 | schaersvoo | 10263 | if( strcmp(input_type, ftriangles) == 0 ){ |
10264 | free(input_type); |
||
10265 | use_filled = TRUE; |
||
10266 | return TRIANGLES; |
||
10267 | } |
||
7614 | schaersvoo | 10268 | if( strcmp(input_type, ftriangle) == 0 ){ |
10269 | free(input_type); |
||
10270 | use_filled = TRUE; |
||
10271 | return TRIANGLE; |
||
10272 | } |
||
10273 | if( strcmp(input_type, input) == 0 ){ |
||
10274 | free(input_type); |
||
10275 | return INPUT; |
||
10276 | } |
||
10277 | if( strcmp(input_type, inputstyle) == 0 ){ |
||
10278 | free(input_type); |
||
10279 | return INPUTSTYLE; |
||
10280 | } |
||
10281 | if( strcmp(input_type, textarea) == 0 ){ |
||
10282 | free(input_type); |
||
10283 | return TEXTAREA; |
||
10284 | } |
||
10285 | if( strcmp(input_type, mathml) == 0 ){ |
||
10286 | free(input_type); |
||
10287 | return MATHML; |
||
10288 | } |
||
10289 | if( strcmp(input_type, html) == 0 ){ |
||
10290 | free(input_type); |
||
10291 | return MATHML; |
||
10292 | } |
||
10293 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
10294 | free(input_type); |
||
10295 | return FONTFAMILY; |
||
10296 | } |
||
10975 | schaersvoo | 10297 | if( strcmp(input_type, polyline) == 0 || strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){ |
7614 | schaersvoo | 10298 | free(input_type); |
10299 | return POLYLINE; |
||
10300 | } |
||
8351 | schaersvoo | 10301 | if( strcmp(input_type, lines) == 0 ){ |
10302 | free(input_type); |
||
10303 | return LINES; |
||
10304 | } |
||
9374 | schaersvoo | 10305 | if( strcmp(input_type, rects) == 0){ |
8363 | schaersvoo | 10306 | free(input_type); |
10307 | return RECTS; |
||
10308 | } |
||
9383 | schaersvoo | 10309 | if( strcmp(input_type, frects) == 0 ){ |
8363 | schaersvoo | 10310 | free(input_type); |
9374 | schaersvoo | 10311 | use_filled = TRUE; |
8363 | schaersvoo | 10312 | return RECTS; |
10313 | } |
||
7614 | schaersvoo | 10314 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
10315 | free(input_type); |
||
10316 | return RECT; |
||
10317 | } |
||
9374 | schaersvoo | 10318 | if( strcmp(input_type, square) == 0 ){ |
10319 | free(input_type); |
||
11991 | schaersvoo | 10320 | return SQUARE; |
9374 | schaersvoo | 10321 | } |
10322 | if( strcmp(input_type, fsquare) == 0 ){ |
||
10323 | free(input_type); |
||
10324 | use_filled = TRUE; |
||
10325 | return SQUARE; |
||
10326 | } |
||
10327 | if( strcmp(input_type, fsquares) == 0 ){ |
||
10328 | free(input_type); |
||
10329 | use_filled = TRUE; |
||
10330 | return RECTS; |
||
10331 | } |
||
8370 | schaersvoo | 10332 | if( strcmp(input_type, roundrects) == 0 ){ |
10333 | free(input_type); |
||
10334 | return ROUNDRECTS; |
||
10335 | } |
||
7614 | schaersvoo | 10336 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
10337 | free(input_type); |
||
10338 | return ROUNDRECT; |
||
10339 | } |
||
9374 | schaersvoo | 10340 | if( strcmp(input_type, froundrects) == 0 ){ |
7614 | schaersvoo | 10341 | free(input_type); |
10342 | use_filled = TRUE; |
||
9374 | schaersvoo | 10343 | return ROUNDRECTS; |
7614 | schaersvoo | 10344 | } |
9374 | schaersvoo | 10345 | if( strcmp(input_type, froundrect) == 0 ){ |
7614 | schaersvoo | 10346 | free(input_type); |
10347 | use_filled = TRUE; |
||
9374 | schaersvoo | 10348 | return ROUNDRECT; |
7614 | schaersvoo | 10349 | } |
10350 | if( strcmp(input_type, dline) == 0 ){ |
||
10351 | use_dashed = TRUE; |
||
10352 | free(input_type); |
||
10353 | return LINE; |
||
10354 | } |
||
7786 | schaersvoo | 10355 | if( strcmp(input_type, dvline) == 0 ){ |
10356 | use_dashed = TRUE; |
||
10357 | free(input_type); |
||
10358 | return VLINE; |
||
10359 | } |
||
10360 | if( strcmp(input_type, dhline) == 0 ){ |
||
10361 | use_dashed = TRUE; |
||
10362 | free(input_type); |
||
10363 | return HLINE; |
||
10364 | } |
||
9386 | schaersvoo | 10365 | if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0 ){ |
10366 | free(input_type); |
||
10367 | return HALFLINES; |
||
10368 | } |
||
10369 | if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){ |
||
10370 | free(input_type); |
||
10371 | return HALFLINE; |
||
10372 | } |
||
7614 | schaersvoo | 10373 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
10374 | use_filled = TRUE; |
||
10375 | free(input_type); |
||
10376 | return RECT; |
||
10377 | } |
||
8304 | schaersvoo | 10378 | if( strcmp(input_type, circles) == 0 ){ |
10379 | free(input_type); |
||
10380 | return CIRCLES; |
||
10381 | } |
||
7614 | schaersvoo | 10382 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
10383 | use_filled = TRUE; |
||
10384 | free(input_type); |
||
10385 | return CIRCLE; |
||
10386 | } |
||
9374 | schaersvoo | 10387 | if( strcmp(input_type, fcircles) == 0 || strcmp(input_type, disks) == 0 ){ |
10388 | use_filled = TRUE; |
||
10389 | free(input_type); |
||
10390 | return CIRCLES; |
||
10391 | } |
||
7614 | schaersvoo | 10392 | if( strcmp(input_type, circle) == 0 ){ |
10393 | free(input_type); |
||
10394 | return CIRCLE; |
||
10395 | } |
||
10396 | if( strcmp(input_type, point) == 0 ){ |
||
10397 | free(input_type); |
||
10398 | return POINT; |
||
10399 | } |
||
10400 | if( strcmp(input_type, points) == 0 ){ |
||
10401 | free(input_type); |
||
10402 | return POINTS; |
||
10403 | } |
||
9374 | schaersvoo | 10404 | if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){ |
7614 | schaersvoo | 10405 | use_filled = TRUE; |
10406 | free(input_type); |
||
10407 | return ARC; |
||
10408 | } |
||
10409 | if( strcmp(input_type, arc) == 0 ){ |
||
10410 | free(input_type); |
||
10411 | return ARC; |
||
10412 | } |
||
10413 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
10414 | free(input_type); |
||
10415 | return POLY; |
||
10416 | } |
||
10417 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
10418 | use_filled = TRUE; |
||
10419 | free(input_type); |
||
10420 | return POLY; |
||
10421 | } |
||
10422 | if( strcmp(input_type, ellipse) == 0){ |
||
10423 | free(input_type); |
||
10424 | return ELLIPSE; |
||
10425 | } |
||
12110 | schaersvoo | 10426 | if( strcmp(input_type, ellipses) == 0){ |
10427 | free(input_type); |
||
10428 | return ELLIPSES; |
||
10429 | } |
||
7614 | schaersvoo | 10430 | if( strcmp(input_type, string) == 0 ){ |
10431 | free(input_type); |
||
10432 | return STRING; |
||
10433 | } |
||
10434 | if( strcmp(input_type, stringup) == 0 ){ |
||
10435 | free(input_type); |
||
10436 | return STRINGUP; |
||
10437 | } |
||
9385 | schaersvoo | 10438 | if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){ |
7614 | schaersvoo | 10439 | free(input_type); |
10440 | return OPACITY; |
||
10441 | } |
||
10442 | if( strcmp(input_type, comment) == 0){ |
||
10443 | free(input_type); |
||
10444 | return COMMENT; |
||
10445 | } |
||
10446 | if( strcmp(input_type, fellipse) == 0){ |
||
10447 | free(input_type); |
||
10448 | use_filled = TRUE; |
||
10449 | return ELLIPSE; |
||
8224 | bpr | 10450 | } |
9386 | schaersvoo | 10451 | if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){ |
7614 | schaersvoo | 10452 | free(input_type); |
8146 | schaersvoo | 10453 | return CLEARBUTTON; |
7614 | schaersvoo | 10454 | } |
10455 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
||
10456 | free(input_type); |
||
10457 | return TRANSLATION; |
||
10458 | } |
||
10459 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
10460 | free(input_type); |
||
10461 | return KILLTRANSLATION; |
||
10462 | } |
||
10463 | if( strcmp(input_type, rotate) == 0){ |
||
10464 | free(input_type); |
||
10465 | return ROTATE; |
||
10466 | } |
||
9907 | schaersvoo | 10467 | if( strcmp(input_type, killrotate) == 0){ |
10468 | free(input_type); |
||
10469 | return KILLROTATE; |
||
10470 | } |
||
10471 | if( strcmp(input_type, rotationcenter) == 0){ |
||
10472 | free(input_type); |
||
10473 | return ROTATION_CENTER; |
||
10474 | } |
||
7785 | schaersvoo | 10475 | if( strcmp(input_type, affine) == 0){ |
10476 | free(input_type); |
||
10477 | return AFFINE; |
||
10478 | } |
||
10479 | if( strcmp(input_type, killaffine) == 0){ |
||
10480 | free(input_type); |
||
10481 | return KILLAFFINE; |
||
10482 | } |
||
7614 | schaersvoo | 10483 | if( strcmp(input_type, slider) == 0 ){ |
10484 | free(input_type); |
||
10485 | return SLIDER; |
||
10486 | } |
||
8101 | schaersvoo | 10487 | if( strcmp(input_type, killslider) == 0 ){ |
10488 | free(input_type); |
||
10489 | return KILLSLIDER; |
||
10490 | } |
||
7614 | schaersvoo | 10491 | if( strcmp(input_type, copy) == 0 ){ |
10492 | free(input_type); |
||
10493 | return COPY; |
||
10494 | } |
||
10495 | if( strcmp(input_type, copyresized) == 0 ){ |
||
10496 | free(input_type); |
||
10497 | return COPYRESIZED; |
||
10498 | } |
||
10499 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
10500 | free(input_type); |
||
10501 | return XLOGSCALE; |
||
10502 | } |
||
10503 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
10504 | free(input_type); |
||
10505 | return YLOGSCALE; |
||
10506 | } |
||
10507 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
10508 | free(input_type); |
||
10509 | return XYLOGSCALE; |
||
10510 | } |
||
10511 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
10512 | free(input_type); |
||
10513 | return YLOGSCALE; |
||
10514 | } |
||
7735 | schaersvoo | 10515 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 10516 | free(input_type); |
7735 | schaersvoo | 10517 | return XLOGBASE; |
7614 | schaersvoo | 10518 | } |
7735 | schaersvoo | 10519 | if( strcmp(input_type, ylogbase) == 0 ){ |
10520 | free(input_type); |
||
10521 | return YLOGBASE; |
||
10522 | } |
||
7614 | schaersvoo | 10523 | if( strcmp(input_type, intooltip) == 0 ){ |
10524 | free(input_type); |
||
10525 | return INTOOLTIP; |
||
10526 | } |
||
9329 | schaersvoo | 10527 | if( strcmp(input_type, popup) == 0 ){ |
10528 | free(input_type); |
||
10529 | return POPUP; |
||
10530 | } |
||
7614 | schaersvoo | 10531 | if( strcmp(input_type,video) == 0 ){ |
10532 | free(input_type); |
||
10533 | return VIDEO; |
||
10534 | } |
||
14225 | schaersvoo | 10535 | if( strcmp(input_type,latex) == 0 ){ |
10536 | free(input_type); |
||
10537 | return LATEX; |
||
10538 | } |
||
11772 | schaersvoo | 10539 | if( strcmp(input_type,fillall) == 0 ){ |
10540 | free(input_type); |
||
10541 | return FILLALL; |
||
10542 | } |
||
7614 | schaersvoo | 10543 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
10544 | free(input_type); |
||
10545 | return FLOODFILL; |
||
8224 | bpr | 10546 | } |
7614 | schaersvoo | 10547 | if( strcmp(input_type,filltoborder) == 0 ){ |
10548 | free(input_type); |
||
10549 | return FILLTOBORDER; |
||
8224 | bpr | 10550 | } |
14038 | schaersvoo | 10551 | if( strcmp(input_type, curvedarrow2) == 0 ){ |
10552 | free(input_type); |
||
10553 | return CURVEDARROW2; |
||
10554 | } |
||
10555 | if( strcmp(input_type, curvedarrow) == 0 ){ |
||
10556 | free(input_type); |
||
10557 | return CURVEDARROW; |
||
10558 | } |
||
10559 | if( strcmp(input_type, curvedarrows) == 0 ){ |
||
10560 | free(input_type); |
||
10561 | return CURVEDARROWS; |
||
10562 | } |
||
10563 | if( strcmp(input_type, curvedarrows2) == 0 ){ |
||
10564 | free(input_type); |
||
10565 | return CURVEDARROWS2; |
||
10566 | } |
||
7614 | schaersvoo | 10567 | if( strcmp(input_type, replyformat) == 0 ){ |
10568 | free(input_type); |
||
10569 | return REPLYFORMAT; |
||
10570 | } |
||
10571 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
10572 | free(input_type); |
||
10573 | return PIXELSIZE; |
||
10574 | } |
||
10575 | if( strcmp(input_type, setpixel) == 0 ){ |
||
10576 | free(input_type); |
||
10577 | return SETPIXEL; |
||
10578 | } |
||
10579 | if( strcmp(input_type, pixels) == 0 ){ |
||
10580 | free(input_type); |
||
10581 | return PIXELS; |
||
10582 | } |
||
10583 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
10584 | free(input_type); |
||
10585 | return X_AXIS_STRINGS; |
||
10586 | } |
||
9341 | schaersvoo | 10587 | if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){ |
10588 | free(input_type); |
||
10589 | return X_AXIS_STRINGS_UP; |
||
10590 | } |
||
7614 | schaersvoo | 10591 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
10592 | free(input_type); |
||
10593 | return Y_AXIS_STRINGS; |
||
10594 | } |
||
10595 | if( strcmp(input_type, legend) == 0 ){ |
||
10596 | free(input_type); |
||
10597 | return LEGEND; |
||
10598 | } |
||
10599 | if( strcmp(input_type, legendcolors) == 0 ){ |
||
10600 | free(input_type); |
||
10601 | return LEGENDCOLORS; |
||
10602 | } |
||
10603 | if( strcmp(input_type, xlabel) == 0 ){ |
||
10604 | free(input_type); |
||
10605 | return XLABEL; |
||
10606 | } |
||
10607 | if( strcmp(input_type, ylabel) == 0 ){ |
||
10608 | free(input_type); |
||
10609 | return YLABEL; |
||
10610 | } |
||
8370 | schaersvoo | 10611 | if( strcmp(input_type, bezier) == 0 ){ |
10612 | free(input_type); |
||
10613 | return BEZIER; |
||
10614 | } |
||
7614 | schaersvoo | 10615 | if( strcmp(input_type, animate) == 0 ){ |
10616 | free(input_type); |
||
10617 | return ANIMATE; |
||
10618 | } |
||
9354 | schaersvoo | 10619 | /* these are bitmap related flydraw commands...must be removed. eventually */ |
7614 | schaersvoo | 10620 | if( strcmp(input_type, transparent) == 0 ){ |
10621 | free(input_type); |
||
10622 | return TRANSPARENT; |
||
10623 | } |
||
7877 | schaersvoo | 10624 | if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){ |
7614 | schaersvoo | 10625 | free(input_type); |
10626 | return STATUS; |
||
10627 | } |
||
7784 | schaersvoo | 10628 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
10629 | free(input_type); |
||
10630 | return XSNAPTOGRID; |
||
10631 | } |
||
10632 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
10633 | free(input_type); |
||
10634 | return YSNAPTOGRID; |
||
10635 | } |
||
8379 | schaersvoo | 10636 | if( strcmp(input_type, snaptogrid) == 0 ){ |
10637 | free(input_type); |
||
10638 | return SNAPTOGRID; |
||
10639 | } |
||
10640 | if( strcmp(input_type, snaptopoints) == 0 ){ |
||
10641 | free(input_type); |
||
10642 | return SNAPTOPOINTS; |
||
10643 | } |
||
9213 | schaersvoo | 10644 | if( strcmp(input_type, snaptofunction) == 0 || strcmp(input_type, snaptofun) == 0 ){ |
10645 | free(input_type); |
||
10646 | return SNAPTOFUNCTION; |
||
10647 | } |
||
7652 | schaersvoo | 10648 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 10649 | free(input_type); |
7652 | schaersvoo | 10650 | return USERINPUT_XY; |
10651 | } |
||
8193 | schaersvoo | 10652 | if( strcmp(input_type, userinput_function) == 0 ){ |
10653 | free(input_type); |
||
10654 | return USERINPUT_FUNCTION; |
||
10655 | } |
||
7663 | schaersvoo | 10656 | if( strcmp(input_type, usertextarea_xy) == 0 ){ |
10657 | free(input_type); |
||
10658 | return USERTEXTAREA_XY; |
||
10659 | } |
||
8222 | schaersvoo | 10660 | if( strcmp(input_type, userinput) == 0 ){ |
10661 | free(input_type); |
||
10662 | return USERINPUT; |
||
10663 | } |
||
8105 | schaersvoo | 10664 | if( strcmp(input_type, angle) == 0 ){ |
7996 | schaersvoo | 10665 | free(input_type); |
8105 | schaersvoo | 10666 | return ANGLE; |
10667 | } |
||
8297 | schaersvoo | 10668 | if( strcmp(input_type, functionlabel) == 0 ){ |
8244 | schaersvoo | 10669 | free(input_type); |
8297 | schaersvoo | 10670 | return FUNCTION_LABEL; |
10671 | } |
||
9213 | schaersvoo | 10672 | if( strcmp(input_type, sliderfunction_x) == 0 ){ |
8297 | schaersvoo | 10673 | free(input_type); |
9213 | schaersvoo | 10674 | return SLIDER_X; |
10675 | } |
||
10676 | if( strcmp(input_type, sliderfunction_y) == 0 ){ |
||
10677 | free(input_type); |
||
10678 | return SLIDER_Y; |
||
10679 | } |
||
10680 | if( strcmp(input_type, multidraw) == 0 ){ |
||
10681 | free(input_type); |
||
10682 | return MULTIDRAW; |
||
10683 | } |
||
10684 | if( strcmp(input_type, multistrokeopacity) == 0 ){ |
||
10685 | free(input_type); |
||
10686 | return MULTISTROKEOPACITY; |
||
10687 | } |
||
10688 | if( strcmp(input_type, multifillopacity) == 0 ){ |
||
10689 | free(input_type); |
||
10690 | return MULTIFILLOPACITY; |
||
10691 | } |
||
14622 | schaersvoo | 10692 | if( strcmp(input_type, multilinewidth) == 0 || strcmp(input_type, linewidths) == 0 ){ |
9213 | schaersvoo | 10693 | free(input_type); |
10694 | return MULTILINEWIDTH; |
||
10695 | } |
||
14622 | schaersvoo | 10696 | if( strcmp(input_type, multistrokecolors) == 0 ||strcmp(input_type, multicolors) == 0 ||strcmp(input_type,colors) == 0 ){ |
9213 | schaersvoo | 10697 | free(input_type); |
10698 | return MULTISTROKECOLORS; |
||
10699 | } |
||
10700 | if( strcmp(input_type, multifill) == 0 ){ |
||
10701 | free(input_type); |
||
10702 | return MULTIFILL; |
||
10703 | } |
||
14622 | schaersvoo | 10704 | if( strcmp(input_type, multifillcolors) == 0 || strcmp(input_type, fillcolors) == 0 ){ |
9213 | schaersvoo | 10705 | free(input_type); |
10706 | return MULTIFILLCOLORS; |
||
10707 | } |
||
10708 | if( strcmp(input_type, multilabel) == 0 ){ |
||
10709 | free(input_type); |
||
10710 | return MULTILABEL; |
||
10711 | } |
||
10712 | if( strcmp(input_type, multidash) == 0 ){ |
||
10713 | free(input_type); |
||
10714 | return MULTIDASH; |
||
10715 | } |
||
14038 | schaersvoo | 10716 | if( strcmp(input_type, multisnaptogrid) == 0 || strcmp(input_type, multisnap) == 0 ){ |
9213 | schaersvoo | 10717 | free(input_type); |
10718 | return MULTISNAPTOGRID; |
||
10719 | } |
||
14038 | schaersvoo | 10720 | if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0 ){ |
9213 | schaersvoo | 10721 | free(input_type); |
10722 | return MULTIUSERINPUT; |
||
10723 | } |
||
9386 | schaersvoo | 10724 | if( strcmp(input_type, parallel) == 0 ){ |
10725 | free(input_type); |
||
10726 | return PARALLEL; |
||
10727 | } |
||
9289 | schaersvoo | 10728 | if( strcmp(input_type, protractor) == 0 ){ |
10729 | free(input_type); |
||
10730 | return PROTRACTOR; |
||
10731 | } |
||
10732 | if( strcmp(input_type, ruler) == 0 ){ |
||
10733 | free(input_type); |
||
10734 | return RULER; |
||
10735 | } |
||
9386 | schaersvoo | 10736 | if( strcmp(input_type, cursor) == 0 || strcmp(input_type, pointer) == 0 ){ |
9213 | schaersvoo | 10737 | free(input_type); |
9386 | schaersvoo | 10738 | return CURSOR; |
10739 | } |
||
10740 | if( strcmp(input_type, sgraph) == 0 ){ |
||
10741 | free(input_type); |
||
10742 | return SGRAPH; |
||
10743 | } |
||
10744 | if( strcmp(input_type, jsmath) == 0 ){ |
||
10745 | free(input_type); |
||
10746 | return JSMATH; |
||
10747 | } |
||
10748 | if( strcmp(input_type, trace_jscurve) == 0 ){ |
||
10749 | free(input_type); |
||
10750 | return TRACE_JSCURVE; |
||
10751 | } |
||
10752 | if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){ |
||
10753 | free(input_type); |
||
10754 | return JSCURVE; |
||
10755 | } |
||
10756 | if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){ |
||
10757 | free(input_type); |
||
10758 | return CENTERSTRING; |
||
10759 | } |
||
10760 | if( strcmp(input_type, setlimits) == 0 ){ |
||
10761 | free(input_type); |
||
10762 | return SETLIMITS; |
||
10763 | } |
||
10764 | if( strcmp(input_type, xunit) == 0 ){ |
||
10765 | free(input_type); |
||
10766 | return XUNIT; |
||
10767 | } |
||
10768 | if( strcmp(input_type, yunit) == 0 ){ |
||
10769 | free(input_type); |
||
10770 | return YUNIT; |
||
10771 | } |
||
10772 | if( strcmp(input_type, fill) == 0 ){ |
||
10773 | free(input_type); |
||
10774 | return FLOODFILL; |
||
10775 | } |
||
10776 | if( strcmp(input_type, end) == 0){ |
||
10777 | free(input_type); |
||
10778 | return END; |
||
10779 | } |
||
10780 | if( strcmp(input_type, blink) == 0 ){ |
||
10781 | free(input_type); |
||
10782 | return BLINK; |
||
10783 | } |
||
10784 | if( strcmp(input_type, audio) == 0 ){ |
||
10785 | free(input_type); |
||
10786 | return AUDIO; |
||
10787 | } |
||
10788 | if( strcmp(input_type, audioobject) == 0 ){ |
||
10789 | free(input_type); |
||
10790 | return AUDIOOBJECT; |
||
10791 | } |
||
10792 | if( strcmp(input_type, patternfill) == 0 ){ |
||
10793 | free(input_type); |
||
10794 | return PATTERNFILL; |
||
10795 | } |
||
10796 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
10797 | free(input_type); |
||
10798 | return HATCHFILL; |
||
10799 | } |
||
10800 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
||
10801 | free(input_type); |
||
10802 | return DIAMONDFILL; |
||
10803 | } |
||
10804 | if( strcmp(input_type, dotfill) == 0 ){ |
||
10805 | free(input_type); |
||
10806 | return DOTFILL; |
||
10807 | } |
||
11830 | schaersvoo | 10808 | if( strcmp(input_type, textfill) == 0 ){ |
10809 | free(input_type); |
||
10810 | return TEXTFILL; |
||
10811 | } |
||
9386 | schaersvoo | 10812 | if( strcmp(input_type, gridfill) == 0 ){ |
10813 | free(input_type); |
||
10814 | return GRIDFILL; |
||
10815 | } |
||
10816 | if( strcmp(input_type, imagefill) == 0 ){ |
||
10817 | free(input_type); |
||
10818 | return IMAGEFILL; |
||
10819 | } |
||
10820 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
10821 | free(input_type); |
||
10822 | return CLICKTILE_COLORS; |
||
10823 | } |
||
10824 | if( strcmp(input_type, clicktile) == 0 ){ |
||
10825 | free(input_type); |
||
10826 | return CLICKTILE; |
||
10827 | } |
||
10828 | if( strcmp(input_type, piechart) == 0 ){ |
||
10829 | free(input_type); |
||
10830 | return PIECHART; |
||
10831 | } |
||
9433 | schaersvoo | 10832 | if( strcmp(input_type, boxplot) == 0 ){ |
10833 | free(input_type); |
||
10834 | return BOXPLOT; |
||
10835 | } |
||
9465 | schaersvoo | 10836 | if( strcmp(input_type, boxplotdata) == 0 ){ |
9433 | schaersvoo | 10837 | free(input_type); |
9465 | schaersvoo | 10838 | return BOXPLOTDATA; |
9433 | schaersvoo | 10839 | } |
9465 | schaersvoo | 10840 | if( strcmp(input_type, userboxplot) == 0 ){ |
10841 | free(input_type); |
||
10842 | return USERBOXPLOT; |
||
10843 | } |
||
10844 | if( strcmp(input_type, userboxplotdata) == 0 ){ |
||
10845 | free(input_type); |
||
10846 | return USERBOXPLOT; |
||
10847 | } |
||
9386 | schaersvoo | 10848 | if( strcmp(input_type, barchart) == 0 ){ |
10849 | free(input_type); |
||
10850 | return BARCHART; |
||
10851 | } |
||
10852 | if( strcmp(input_type, linegraph) == 0 ){ |
||
10853 | free(input_type); |
||
10854 | return LINEGRAPH; |
||
10855 | } |
||
10856 | if( strcmp(input_type, clock) == 0 ){ |
||
10857 | free(input_type); |
||
10858 | return CLOCK; |
||
10859 | } |
||
9427 | schaersvoo | 10860 | if( strcmp(input_type, yerrorbars) == 0 ){ |
9386 | schaersvoo | 10861 | free(input_type); |
9427 | schaersvoo | 10862 | return YERRORBARS; |
10863 | } |
||
10864 | if( strcmp(input_type, xerrorbars) == 0 ){ |
||
10865 | free(input_type); |
||
10866 | return XERRORBARS; |
||
10867 | } |
||
11006 | schaersvoo | 10868 | if( strcmp(input_type, canvastype) == 0 ){ |
9427 | schaersvoo | 10869 | free(input_type); |
11006 | schaersvoo | 10870 | return CANVASTYPE; |
10871 | } |
||
11044 | schaersvoo | 10872 | if( strcmp(input_type, noyaxis) == 0 ){ |
11006 | schaersvoo | 10873 | free(input_type); |
11044 | schaersvoo | 10874 | return NOYAXIS; |
10875 | } |
||
10876 | if( strcmp(input_type, noxaxis) == 0 ){ |
||
10877 | free(input_type); |
||
10878 | return NOXAXIS; |
||
10879 | } |
||
11767 | schaersvoo | 10880 | if( strcmp(input_type, colorpalette) == 0 ){ |
11044 | schaersvoo | 10881 | free(input_type); |
11767 | schaersvoo | 10882 | return COLORPALETTE; |
10883 | } |
||
14038 | schaersvoo | 10884 | if( strcmp(input_type, imagepalette) == 0 ){ |
10885 | free(input_type); |
||
10886 | return IMAGEPALETTE; |
||
10887 | } |
||
11802 | schaersvoo | 10888 | if( strcmp(input_type, resetoffset) == 0 ){ |
11767 | schaersvoo | 10889 | free(input_type); |
11802 | schaersvoo | 10890 | return RESETOFFSET; |
10891 | } |
||
10892 | if( strcmp(input_type, xyoffset) == 0 ){ |
||
10893 | free(input_type); |
||
10894 | return XYOFFSET; |
||
10895 | } |
||
12063 | schaersvoo | 10896 | if( strcmp(input_type, centered) == 0 ){ |
11802 | schaersvoo | 10897 | free(input_type); |
12063 | schaersvoo | 10898 | return CENTERED; |
11802 | schaersvoo | 10899 | } |
12063 | schaersvoo | 10900 | if( strcmp(input_type, yoffset) == 0 ){ |
11802 | schaersvoo | 10901 | free(input_type); |
11811 | schaersvoo | 10902 | return YOFFSET; |
10903 | } |
||
12063 | schaersvoo | 10904 | if( strcmp(input_type, xoffset) == 0 ){ |
10905 | free(input_type); |
||
10906 | return XOFFSET; |
||
10907 | } |
||
11837 | schaersvoo | 10908 | if( strcmp(input_type, fillpattern) == 0 ){ |
11811 | schaersvoo | 10909 | free(input_type); |
11837 | schaersvoo | 10910 | return FILLPATTERN; |
10911 | } |
||
11890 | schaersvoo | 10912 | if( strcmp(input_type, numberline) == 0 ){ |
11837 | schaersvoo | 10913 | free(input_type); |
11890 | schaersvoo | 10914 | return NUMBERLINE; |
10915 | } |
||
14393 | schaersvoo | 10916 | if( strcmp(input_type, duplicates) == 0 || strcmp(input_type, allowdups) == 0 ){ |
11890 | schaersvoo | 10917 | free(input_type); |
14393 | schaersvoo | 10918 | return ALLOW_DUPLICATES; |
10919 | } |
||
10920 | free(input_type); |
||
7614 | schaersvoo | 10921 | ungetc(c,infile); |
10922 | return 0; |
||
10923 | } |
||
14038 | schaersvoo | 10924 | |
10925 | |||
10926 | |||
10927 | |||
10928 | |||
10929 | |||
10930 | |||
10931 | |||
10932 | |||
10933 | |||
10934 | |||
10935 | |||
10936 | |||
14208 | schaersvoo | 10937 |