Rev 15657 | Rev 15686 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
15111 | 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 * |
||
15111 | schaersvoo | 8 | * No warrenty whatsoever * |
7614 | schaersvoo | 9 | ********************************************************************************* |
10 | */ |
||
7848 | bpr | 11 | #include "canvasdraw.h" |
15348 | bpr | 12 | void *tmp_buffer; |
13 | FILE *js_include_file; |
||
7614 | schaersvoo | 14 | /****************************************************************************** |
15 | ** Internal Functions |
||
16 | ******************************************************************************/ |
||
17 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
18 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
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 | */ |
15111 | 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 ); |
15111 | schaersvoo | 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 */ |
15111 | schaersvoo | 32 | char *convert_hex2rgb(char *hexcolor); |
7614 | schaersvoo | 33 | void make_js_include(int canvas_root_id); |
34 | void check_string_length(int length);/* checks if the length of string argument of command is correct */ |
||
15111 | schaersvoo | 35 | FILE *js_include_file; |
7614 | schaersvoo | 36 | FILE *get_file(int *line_number, char **filename); |
15111 | schaersvoo | 37 | FILE *infile; /* will be stdin */ |
7614 | schaersvoo | 38 | /****************************************************************************** |
39 | ** global |
||
40 | ******************************************************************************/ |
||
41 | int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */ |
||
42 | int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */ |
||
43 | /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */ |
||
44 | int xsize = 320; |
||
45 | int ysize = 320; |
||
46 | double xmin = 0.0; |
||
47 | double xmax = 320.0; |
||
48 | double ymin = 0.0; |
||
49 | double ymax = 320.0; |
||
11893 | schaersvoo | 50 | double tmax = 0; |
51 | double tmin = 0; |
||
7614 | schaersvoo | 52 | /* flag to indicate parsing of line status */ |
8224 | bpr | 53 | int done = FALSE; |
7614 | schaersvoo | 54 | int type; /* eg command number */ |
15111 | schaersvoo | 55 | int onclick = 0; |
56 | /* |
||
15116 | bpr | 57 | |
58 | 1 = onclick ; |
||
59 | 2 = draggable ; |
||
60 | 3 = click+slideable ; |
||
61 | 4 = slideable without click |
||
15111 | schaersvoo | 62 | 5 = draggable + slideable |
63 | */ |
||
14208 | schaersvoo | 64 | char *slider_type="0"; |
15111 | schaersvoo | 65 | char *my_sliders = "[-1]"; |
66 | int use_slider = -1; |
||
67 | int last_slider = 0; |
||
68 | double double_data[MAX_INT+1]; |
||
69 | int int_data[MAX_INT+1]; |
||
70 | int dragstuff[MAX_DRAGSTUFF]; |
||
71 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */ |
||
72 | double affine_matrix[] = {1,0,0,1,0,0}; |
||
7785 | schaersvoo | 73 | int use_affine = FALSE; |
7614 | schaersvoo | 74 | int use_rotate = FALSE; |
14078 | bpr | 75 | int use_filled = 0; /* 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */ |
76 | int use_dashed = FALSE; /* dashing not natively supported in firefox, for now... */ |
||
15111 | schaersvoo | 77 | double angle = 0.0; |
7614 | schaersvoo | 78 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
9329 | schaersvoo | 79 | char *getfile_cmd = ""; |
15111 | schaersvoo | 80 | int reply_format = 0; |
81 | unsigned int canvas_root_id; |
||
82 | char *css_class; |
||
83 | int font_size; |
||
84 | char *draw_type; |
||
85 | int jsplot_cnt = -1; /* keepint track on the curve identity */ |
||
86 | int input_cnt = 0; |
||
87 | int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */ |
||
88 | char *function_label = "[\"f(x)=\",\"g(x)=\",\"h(x)=\"]"; |
||
89 | int drag_type = -1;/* 0,1,2: xy,x,y */ |
||
90 | int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/ |
||
91 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
92 | int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/ |
||
93 | int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc */ |
||
94 | int use_axis = FALSE; |
||
95 | int use_axis_numbering = -1; |
||
96 | int no_reset = FALSE; |
||
97 | |||
7614 | schaersvoo | 98 | /****************************************************************************** |
99 | ** Main Program |
||
100 | ******************************************************************************/ |
||
101 | int main(int argc, char *argv[]){ |
||
14066 | bpr | 102 | /* need unique id for every call to canvasdraw: rand(); is too slow...will result in many identical id's */ |
12104 | schaersvoo | 103 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz); |
15111 | schaersvoo | 104 | canvas_root_id = (unsigned int) tv.tv_usec; |
7614 | schaersvoo | 105 | infile = stdin;/* read flyscript via stdin */ |
106 | int i,c; |
||
15111 | schaersvoo | 107 | for(i=0;i<MAX_DRAGSTUFF;i++){dragstuff[i] = 0;} |
7614 | schaersvoo | 108 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
14066 | bpr | 109 | int use_snap = 0; /* 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */ |
8448 | schaersvoo | 110 | int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */ |
7614 | schaersvoo | 111 | int line_width = 1; |
112 | int decimals = 2; |
||
15111 | schaersvoo | 113 | int use_dragstuff = 0; |
8365 | schaersvoo | 114 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */ |
15111 | schaersvoo | 115 | int use_userdraw = 0; /* 0=none,1=userdraw,2=multidraw flag to indicate user interaction */ |
9329 | schaersvoo | 116 | int use_tooltip = -1; /* 1= tooltip 2= popup window*/ |
15601 | schaersvoo | 117 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
7614 | schaersvoo | 118 | char *tooltip_text = "Click here"; |
119 | char *temp = ""; /* */ |
||
120 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
121 | char *stroke_color = "255,0,0"; |
||
14208 | schaersvoo | 122 | char *fill_color = "255,255,255"; |
15313 | schaersvoo | 123 | char *font_family = "12px Arial"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
7614 | schaersvoo | 124 | char *font_color = "#00000"; |
15111 | schaersvoo | 125 | draw_type = "points"; |
7614 | schaersvoo | 126 | char *fly_font = "normal"; |
15111 | schaersvoo | 127 | css_class = "none"; |
7614 | schaersvoo | 128 | char *flytext = ""; |
11006 | schaersvoo | 129 | int canvas_type = DRAG_CANVAS; /* to use a specific canvas for filling etc */ |
7614 | schaersvoo | 130 | int pixelsize = 1; |
11763 | schaersvoo | 131 | int fill_cnt = 0; |
15111 | schaersvoo | 132 | int use_zoom = 0; |
15313 | schaersvoo | 133 | font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Arial</code> the ''fontsize`` value is not substituted into fontfamily !! */ |
8388 | schaersvoo | 134 | int fly_font_size = 12; /*fly_font_size is relative to this... */ |
7614 | schaersvoo | 135 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
8365 | schaersvoo | 136 | int arrow_head = 8; /* size in px needed for arrow based userdraw: "userdraw arrow,color" */ |
7833 | schaersvoo | 137 | int crosshair_size = 5; /* size in px*/ |
8365 | schaersvoo | 138 | 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 | 139 | int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */ |
15111 | schaersvoo | 140 | int object_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[object_cnt]=1 when clicked ; otherwise reply[object_cnt]=0 ; object_cnt is only increased when another object is set again */ |
7614 | schaersvoo | 141 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
9433 | schaersvoo | 142 | int boxplot_cnt = 0; |
15111 | schaersvoo | 143 | int drawxml_cnt = 0; |
11890 | schaersvoo | 144 | int numberline_cnt = 0; |
8074 | schaersvoo | 145 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
15111 | schaersvoo | 146 | char *rotation_center = "null";/* needs to be removed... but is used for canvas CTX based rotation*/ |
147 | double rotationcenter[] = {0,0}; /* use for recalculating x/y values on rotation() */ |
||
11893 | schaersvoo | 148 | int use_animate = 0; /* used for jscurve / js parametric */ |
7823 | schaersvoo | 149 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
8365 | schaersvoo | 150 | size_t string_length = 0; /* measure the size of the user input fly-string */ |
151 | double stroke_opacity = 0.8; /* use some opacity as default */ |
||
14208 | schaersvoo | 152 | double fill_opacity = 0.5;/* use some opacity as default */ |
7614 | schaersvoo | 153 | char *URL = "http://localhost/images"; |
154 | memset(buffer,'\0',MAX_BUFFER); |
||
155 | void *tmp_buffer = ""; |
||
156 | /* default writing a unzipped js-include file into wims getfile directory */ |
||
157 | char *w_wims_session = getenv("w_wims_session"); |
||
12104 | schaersvoo | 158 | 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 | 159 | int L0=strlen(w_wims_session) + 21; |
160 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
161 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
162 | mode_t process_mask = umask(0); /* check if file exists */ |
||
163 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
164 | if( result == 0 || errno == EEXIST ){ |
||
165 | umask(process_mask); /* be sure to set correct permission */ |
||
8224 | bpr | 166 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 167 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
12104 | schaersvoo | 168 | getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
8224 | bpr | 169 | 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 | 170 | /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
7614 | schaersvoo | 171 | /* now write file into getfile dir*/ |
14066 | bpr | 172 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */ |
7614 | schaersvoo | 173 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
174 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
175 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
176 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
14066 | bpr | 177 | /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */ |
178 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );} |
||
7614 | schaersvoo | 179 | |
180 | /* ----------------------------------------------------- */ |
||
11997 | schaersvoo | 181 | |
7614 | schaersvoo | 182 | /* while more lines to process */ |
183 | |||
184 | while(!finished){ |
||
9329 | schaersvoo | 185 | if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
7614 | schaersvoo | 186 | type = get_token(infile); |
187 | done = FALSE; |
||
188 | /* |
||
9385 | schaersvoo | 189 | @ canvasdraw |
15116 | bpr | 190 | @ Canvasdraw will try use the same basic syntax structure as flydraw |
15650 | reyssat | 191 | @ General syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">opacity [0-255],[0,255]</a></li><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 />note: do not use a <b>f</b> with this non-solid pattern filling !<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>object x1,y1,...,color</code></li><li><code>objects color,x1,y1,...</code></li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#css">css 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> |
15304 | schaersvoo | 192 | @ 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 + "newline";<br /> };<br /> };<br /> };<br /> if( found_result ){return draw_reply;}else{return null;};<br />};</code> <br />(*) Note: the speed advantage over <em>canvas-do-it-all</em> libraries is reduced to zero, when multiple canvasdraw scripts are present in a single page...<br />For example a typical canvasdraw script is between 5 and 40 kB...a large library like JSXgraph is approx 600 kB<br />In these cases it would be much faster to load a static general HTML5 canvas javascript draw library and parse it multiple raw fly instructions !<br /> |
15111 | schaersvoo | 193 | @ Canvasdraw can be used 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...) |
194 | @ 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> |
||
195 | @ 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>. |
||
14379 | bpr | 196 | @ 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. |
15111 | schaersvoo | 197 | @ Be aware that combining several different objects and interactivity may lead to problems. |
14379 | bpr | 198 | @ 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. |
15633 | bpr | 199 | @ There is limited support for touch devices: touchstart, touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#multidraw">multidraw primitives </a>, <a href="#protractor">protractor</a>, <a href="#ruler">ruler</a> and probably a few others... <br />Only single finger gestures are supported (for now).<br />The use of a special pen is advised for interactive drawing on touch devices.<br />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 | 200 | */ |
201 | switch(type){ |
||
15111 | schaersvoo | 202 | case END:finished = 1;done = TRUE;break; |
203 | case 0:sync_input(infile);break; |
||
11806 | schaersvoo | 204 | case AFFINE: |
7614 | schaersvoo | 205 | /* |
11806 | schaersvoo | 206 | @ affine a,b,c,d,tx,ty |
207 | @ defines a transformation matrix for subsequent objects |
||
14066 | bpr | 208 | @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range |
209 | @ a: Scales the drawings horizontally |
||
210 | @ b: Skews the drawings horizontally |
||
211 | @ c: Skews the drawings vertically |
||
212 | @ d: Scales the drawings vertically |
||
11806 | schaersvoo | 213 | @ tx: Moves the drawings horizontally in xrange coordinate system |
214 | @ ty: Moves the drawings vertically in yrange coordinate system |
||
14078 | bpr | 215 | @ the data precision may be set by preceding command ''precision int`` |
15541 | schaersvoo | 216 | @ <b>note</b>: not all affine operations on canvasdraw objects will be identical to flydraw's behaviour. Make sure to check ! |
15111 | schaersvoo | 217 | @%affine%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%#use larger linewith to improve selecting a draggable object !%linewidth 4%drag xy%frect 0,5,3,3,red%affine cos(pi/4),sin(pi/4),-cos(pi/2),sin(pi/2),-5,-5%drag xy%frect 0,5,3,3,red |
15313 | schaersvoo | 218 | @%affine+latex%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%strokecolor blue%fontfamily 42px Arial%centered%drag xy%latex 5,5,\\frac{123}{\\pi^{234}}%affine cos(pi/4),sin(pi/4),-cos(pi/2),sin(pi/2),-5,-5%drag xy%latex 5,5,\\frac{123}{\\pi^{234}} |
7614 | schaersvoo | 219 | */ |
11806 | schaersvoo | 220 | for(i = 0 ; i<6;i++){ |
7614 | schaersvoo | 221 | switch(i){ |
15111 | schaersvoo | 222 | case 0: affine_matrix[0] = get_real(infile,0);break; |
223 | case 1: affine_matrix[1] = get_real(infile,0);break; |
||
224 | case 2: affine_matrix[2] = get_real(infile,0);break; |
||
225 | case 3: affine_matrix[3] = get_real(infile,0);break; |
||
226 | case 4: affine_matrix[4] = get_real(infile,0);break; |
||
227 | case 5: affine_matrix[5] = get_real(infile,1); |
||
11806 | schaersvoo | 228 | use_affine = TRUE; |
229 | break; |
||
7614 | schaersvoo | 230 | default: break; |
231 | } |
||
232 | } |
||
11806 | schaersvoo | 233 | break; |
14394 | schaersvoo | 234 | case ALLOW_DUPLICATES: |
235 | /* |
||
14393 | schaersvoo | 236 | @ duplicates || allowdups |
237 | @ keyword (no arguments) |
||
15645 | bpr | 238 | @ only useful in case of a <a href="#multidraw">multidraw</a> student reply. |
239 | @ only useful in default <a href="#replyformat">replyformat</a> (eg in case of a not specified replyformat). |
||
14396 | bpr | 240 | @ if set, duplicate (x:y) coordinates will not be removed from the student reply. |
15645 | bpr | 241 | @ technical: a javascript variable "allow_duplicate_answer = 1;" is declared. |
242 | @ default for command multidraw is: removal of duplicates. |
||
14393 | schaersvoo | 243 | */ |
15111 | schaersvoo | 244 | fprintf(js_include_file,"var allow_duplicate_answers = 1;"); |
14393 | schaersvoo | 245 | break; |
11806 | schaersvoo | 246 | case ANGLE: |
7614 | schaersvoo | 247 | /* |
11806 | schaersvoo | 248 | @ angle xc,yc,width,start_angle,end_angle,color |
249 | @ width is in x-range |
||
14208 | schaersvoo | 250 | @ angles are in degrees |
251 | @ not compatible with ''flydraw`` |
||
11806 | schaersvoo | 252 | @ will zoom in/out |
14208 | schaersvoo | 253 | @ if angle size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider |
15111 | schaersvoo | 254 | @ ''angle`` and <a href="#arc">arc</a> are exceptions in case of sliders...they are always active (e.g. not click-activated) |
12110 | schaersvoo | 255 | @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue |
15111 | schaersvoo | 256 | @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%strokecolor blue%slider -2*pi,2*pi,260,28,angle active degree,blue arrow%arrow 0,0,8,0,8,blue%fillpattern diamond%angle 0,0,2,0,0,blue%killslider%strokecolor red%slider -2*pi,2*pi,260,28,angle active radian,red arrow%arrow 0,1,8,1,8,red%fillpattern dot%angle 0,1,2,0,0,red |
7614 | schaersvoo | 257 | */ |
11806 | schaersvoo | 258 | for(i=0;i<7;i++){ |
7614 | schaersvoo | 259 | switch(i){ |
11806 | schaersvoo | 260 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
15111 | schaersvoo | 261 | case 1:double_data[1] = get_real(infile,0); |
262 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
||
15116 | bpr | 263 | if(use_affine == TRUE ){ transform(2,2);} |
15111 | schaersvoo | 264 | break; /* y-values */ |
14208 | schaersvoo | 265 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range ! */ |
15111 | schaersvoo | 266 | case 3:double_data[3] = 0.0174532925*(get_real(infile,0) - angle);break; /* start angle in degrees -> radians */ |
267 | case 4:double_data[4] = 0.0174532925*(get_real(infile,0) - angle);break; /* end angle in degrees -> radians */ |
||
11806 | schaersvoo | 268 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
15111 | schaersvoo | 269 | if( use_slider != -1 ){ onclick = 3; }/* always active in case of slider */ |
270 | decimals = find_number_of_digits(precision); |
||
271 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
272 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
273 | snprintf(tmp_buffer,string_length, "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
274 | add_to_buffer(tmp_buffer); |
||
275 | dragstuff[17] = 1; |
||
276 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
277 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
11806 | schaersvoo | 278 | break; |
7614 | schaersvoo | 279 | } |
280 | } |
||
281 | break; |
||
8386 | schaersvoo | 282 | |
11806 | schaersvoo | 283 | case ANIMATE: |
7614 | schaersvoo | 284 | /* |
11930 | schaersvoo | 285 | @ animate |
11893 | schaersvoo | 286 | @ keyword |
15111 | schaersvoo | 287 | @ if set, it will animate a point on a curve |
288 | @ all other canvas object or group of objects (like lines,circles,rects,points...images,svg,latex,mathml etc)<br />may be animated using command <a href='#slider'>slider</a> with keyword 'anim' |
||
14071 | bpr | 289 | @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code> |
11893 | schaersvoo | 290 | @ use linewidth to adjust size of the points |
14078 | bpr | 291 | @ 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 |
15111 | schaersvoo | 292 | @ only usable in combination with command <a href='#jsplot'>jsplot</a> (normal functions or parametric) |
13957 | schaersvoo | 293 | @ 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> |
15650 | reyssat | 294 | @ use commands <a href='#multilinewidth'>multilinewidth</a>, <a href='#multistrokecolor'>multistrokecolor</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 | 295 | @%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) |
296 | @%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 | 297 | */ |
13512 | schaersvoo | 298 | use_animate++; |
299 | if( use_animate == 1 ){ |
||
300 | fprintf(js_include_file,"\nvar trace_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
301 | var trace_ctx = trace_canvas.getContext('2d');\ |
||
302 | trace_ctx.fillStyle = 'rgba(%s,%f)';\ |
||
303 | trace_ctx.strokeStyle = 'rgba(%s,%f)';\ |
||
304 | trace_ctx.lineWidth = %d;var anim_pos = 0;\n\ |
||
305 | function animate_this(){\ |
||
306 | var sync;\ |
||
307 | var synchrone = Math.floor(animation_steps/animation_funs);\ |
||
308 | trace_ctx.clearRect(0,0,xsize,ysize);\ |
||
309 | for(var p=0; p<animation_funs;p++){\ |
||
310 | sync = p*synchrone;\ |
||
311 | trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\ |
||
312 | };\ |
||
313 | setTimeout(function(){\ |
||
314 | requestAnimationFrame(animate_this); anim_pos++;}, 50\ |
||
315 | );\ |
||
316 | if(anim_pos >= animation_steps){anim_pos = 0;};\ |
||
317 | };",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); |
||
318 | } |
||
319 | else |
||
320 | { |
||
13514 | schaersvoo | 321 | 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 | 322 | } |
7614 | schaersvoo | 323 | break; |
8386 | schaersvoo | 324 | |
11806 | schaersvoo | 325 | case ARC: |
7614 | schaersvoo | 326 | /* |
11997 | schaersvoo | 327 | @ arc xc,yc,x-width,y-height,start_angle,end_angle,color |
14208 | schaersvoo | 328 | @ can not be set ''onclick`` or ''drag xy`` |
329 | @ compatible with ''flydraw`` |
||
330 | @ attention: width & height in x/y-range |
||
331 | @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a> |
||
15111 | schaersvoo | 332 | @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red |
13961 | schaersvoo | 333 | @%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 | 334 | */ |
11806 | schaersvoo | 335 | for(i=0;i<7;i++){ |
336 | switch(i){ |
||
337 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
15111 | schaersvoo | 338 | case 1:double_data[1] = get_real(infile,0); |
339 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
||
340 | if(use_affine == TRUE ){ transform(4,2);} |
||
341 | break; /* y-values */ |
||
11806 | schaersvoo | 342 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */ |
15111 | schaersvoo | 343 | case 3:double_data[3] = get_real(infile,0); |
344 | break; /* height y-range no pixels ! */ |
||
345 | case 4:double_data[4] = get_real(infile,0) - angle ;break; /* start angle in degrees */ |
||
346 | case 5:double_data[5] = get_real(infile,0) - angle;break; /* end angle in degrees */ |
||
11806 | schaersvoo | 347 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
348 | /* in Shape library: |
||
349 | x[0] = x[1] = xc = double_data[0] |
||
350 | y[0] = y[1] = yc = double_data[1] |
||
351 | w[0] = width = double_data[2] |
||
352 | w[1] = height = double_data[3] |
||
353 | h[0] = start_angle = double_data[4] |
||
354 | h[1] = end_angle = double_data[5] |
||
355 | */ |
||
15111 | schaersvoo | 356 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 357 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 358 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
359 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
360 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
361 | add_to_buffer(tmp_buffer);reset(); |
||
362 | dragstuff[12] = 1; |
||
363 | if(onclick != 0){object_cnt++;} |
||
364 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 365 | break; |
366 | } |
||
367 | } |
||
7614 | schaersvoo | 368 | break; |
11806 | schaersvoo | 369 | case ARROW: |
7614 | schaersvoo | 370 | /* |
11806 | schaersvoo | 371 | @ arrow x1,y1,x2,y2,h,color |
14071 | bpr | 372 | @ alternative: <code>vector</code> |
14379 | bpr | 373 | @ 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 | 374 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
9406 | schaersvoo | 375 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13957 | schaersvoo | 376 | @%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 |
377 | @%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 | 378 | */ |
11806 | schaersvoo | 379 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 380 | switch(i){ |
381 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
382 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 383 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
384 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
385 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
386 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 387 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
388 | if(use_affine == TRUE ){ transform(4,2);} |
||
389 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
390 | decimals = find_number_of_digits(precision); |
||
391 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
392 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
393 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
394 | if(onclick != 0){object_cnt++;} |
||
395 | /* object_cnt++;*/ |
||
396 | add_to_buffer(tmp_buffer);reset(); |
||
397 | dragstuff[8] = 1; |
||
398 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
399 | break; |
||
11806 | schaersvoo | 400 | } |
401 | } |
||
402 | break; |
||
8386 | schaersvoo | 403 | |
11806 | schaersvoo | 404 | case ARROWS: |
7614 | schaersvoo | 405 | /* |
11806 | schaersvoo | 406 | @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n |
14071 | bpr | 407 | @ alternative: <code>vectors</code> |
15111 | schaersvoo | 408 | @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color' |
14071 | bpr | 409 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
11806 | schaersvoo | 410 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13957 | schaersvoo | 411 | @%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% |
412 | @%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 | 413 | @%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 | 414 | */ |
415 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
416 | fill_color = stroke_color; |
||
11806 | schaersvoo | 417 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 418 | i=0; |
419 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 420 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 421 | if(i%2 == 0 ){ |
422 | double_data[i] = get_real(infile,0); /* x */ |
||
423 | } |
||
424 | else |
||
425 | { |
||
426 | double_data[i] = get_real(infile,1); /* y */ |
||
427 | } |
||
428 | i++; |
||
429 | } |
||
15111 | schaersvoo | 430 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
431 | if( use_affine == TRUE ){ transform(i-1,2);} |
||
432 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
7614 | schaersvoo | 433 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 434 | for(c = 0 ; c < i-1 ; c = c+4){ |
15111 | schaersvoo | 435 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
436 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
437 | snprintf(tmp_buffer,string_length, "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
438 | add_to_buffer(tmp_buffer); |
||
439 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
7614 | schaersvoo | 440 | } |
15111 | schaersvoo | 441 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
442 | dragstuff[8] = 1; |
||
7614 | schaersvoo | 443 | reset(); |
444 | break; |
||
8386 | schaersvoo | 445 | |
11806 | schaersvoo | 446 | case ARROW2: |
7614 | schaersvoo | 447 | /* |
11806 | schaersvoo | 448 | @ arrow2 x1,y1,x2,y2,h,color |
14071 | bpr | 449 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color`` |
450 | @ use command <code>arrowhead int</code> to adjust the arrow head size |
||
451 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
||
9406 | schaersvoo | 452 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 453 | @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue% |
7614 | schaersvoo | 454 | */ |
11806 | schaersvoo | 455 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 456 | switch(i){ |
457 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
458 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 459 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
460 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
461 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
462 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 463 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
464 | if( use_affine == 1 ){ transform(4,2);} |
||
465 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 466 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 467 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
468 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
469 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
470 | add_to_buffer(tmp_buffer); |
||
471 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
472 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
473 | dragstuff[10] = 1; |
||
11806 | schaersvoo | 474 | reset(); |
475 | break; |
||
476 | } |
||
477 | } |
||
478 | break; |
||
8386 | schaersvoo | 479 | |
11806 | schaersvoo | 480 | case ARROWS2: |
7614 | schaersvoo | 481 | /* |
11806 | schaersvoo | 482 | @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n |
14071 | bpr | 483 | @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color`` |
484 | @ use command <code>linewidth int</code> to adjust thickness of the arrows |
||
11806 | schaersvoo | 485 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12107 | schaersvoo | 486 | @%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 | 487 | */ |
488 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
489 | fill_color = stroke_color; |
||
11806 | schaersvoo | 490 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 491 | i=0; |
492 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 493 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 494 | if(i%2 == 0 ){ |
495 | double_data[i] = get_real(infile,0); /* x */ |
||
496 | } |
||
497 | else |
||
498 | { |
||
499 | double_data[i] = get_real(infile,1); /* y */ |
||
500 | } |
||
501 | i++; |
||
502 | } |
||
15111 | schaersvoo | 503 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
504 | if( use_affine == 1 ){ transform(i-1,2);} |
||
505 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
506 | |||
8224 | bpr | 507 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 508 | for(c = 0 ; c < i-1 ; c = c+4){ |
15111 | schaersvoo | 509 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
510 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
511 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
512 | add_to_buffer(tmp_buffer); |
||
513 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
7614 | schaersvoo | 514 | } |
15111 | schaersvoo | 515 | dragstuff[10] = 1; |
516 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 517 | reset(); |
518 | break; |
||
11806 | schaersvoo | 519 | case ARROWHEAD: |
9427 | schaersvoo | 520 | /* |
11806 | schaersvoo | 521 | @ arrowhead int |
522 | @ default 8 (pixels) |
||
9427 | schaersvoo | 523 | */ |
11806 | schaersvoo | 524 | arrow_head = (int) (get_real(infile,1)); |
525 | break; |
||
526 | |||
527 | case AUDIO: |
||
528 | /* |
||
529 | @ audio x,y,w,h,loop,visible,audiofile location |
||
14066 | bpr | 530 | @ x,y: left top corner of audio element (in xrange / yrange) |
531 | @ w,y: width and height in pixels |
||
532 | @ loop: 0 or 1 ( 1 = loop audio fragment) |
||
533 | @ visible: 0 or 1 (1 = show controls) |
||
11806 | schaersvoo | 534 | @ audio format may be in *.mp3 or *.ogg |
14066 | bpr | 535 | @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format) |
536 | @ if you are using *.ogg: be aware that Microsoft based systems not support it natively |
||
11806 | schaersvoo | 537 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
538 | */ |
||
15111 | schaersvoo | 539 | js_function[DRAW_AUDIO] = 1; |
11806 | schaersvoo | 540 | for(i=0;i<7;i++){ |
541 | switch(i){ |
||
542 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
543 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
544 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
545 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
546 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
547 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
548 | case 6: |
||
549 | temp = get_string(infile,1); |
||
550 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
551 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
14208 | schaersvoo | 552 | 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); |
553 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 554 | 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); |
555 | add_to_buffer(tmp_buffer); |
||
556 | break; |
||
557 | default:break; |
||
9427 | schaersvoo | 558 | } |
11806 | schaersvoo | 559 | } |
560 | reset(); |
||
561 | break; |
||
562 | |||
563 | |||
564 | case AXIS_NUMBERING: |
||
565 | /* |
||
566 | @ axisnumbering |
||
567 | @ keyword (no arguments required) |
||
14246 | bpr | 568 | @ 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 | 569 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
570 | */ |
||
11891 | schaersvoo | 571 | use_axis_numbering++; |
11806 | schaersvoo | 572 | break; |
573 | case AXIS: |
||
574 | /* |
||
575 | @ axis |
||
576 | @ keyword (no arguments required) |
||
577 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
578 | |||
579 | */ |
||
580 | use_axis = TRUE; |
||
581 | break; |
||
582 | |||
583 | case BARCHART: |
||
584 | /* |
||
585 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
14066 | bpr | 586 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
587 | @ 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> |
||
588 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
11806 | schaersvoo | 589 | @ multiple barchart command may be used in a single script |
14066 | bpr | 590 | @ also see command <a href='#piechart'>piechart</a> |
591 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
||
15313 | schaersvoo | 592 | @%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 Arial%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 | 593 | */ |
594 | temp = get_string(infile,1); |
||
595 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
596 | fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp); |
||
597 | barchart_cnt++; |
||
598 | reset(); |
||
599 | break; |
||
600 | |||
601 | case BEZIER: |
||
602 | /* |
||
603 | @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end |
||
604 | @ draw a bezier curve between points, starting from (x_start:y_start) |
||
605 | @ can <b>not</b> be dragged or set onclick |
||
606 | */ |
||
15111 | schaersvoo | 607 | js_function[DRAW_BEZIER] = 1; |
11806 | schaersvoo | 608 | decimals = find_number_of_digits(precision); |
609 | for(i = 0 ; i < 9; i++){ |
||
610 | switch(i){ |
||
611 | case 0: stroke_color = get_color(infile,0);break; |
||
612 | case 1: double_data[0] = get_real(infile,0);break;/* start x */ |
||
613 | case 2: double_data[1] = get_real(infile,0);break;/* start y */ |
||
614 | case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */ |
||
615 | case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */ |
||
616 | case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */ |
||
617 | case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */ |
||
618 | case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */ |
||
619 | case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */ |
||
15111 | schaersvoo | 620 | if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);} |
621 | if(use_affine == TRUE ){ transform(2,5);} |
||
622 | 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);",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); |
||
14208 | schaersvoo | 623 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 624 | 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);",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); |
11806 | schaersvoo | 625 | add_to_buffer(tmp_buffer); |
626 | break; |
||
627 | default: break; |
||
9427 | schaersvoo | 628 | } |
629 | } |
||
630 | reset(); |
||
631 | break; |
||
11806 | schaersvoo | 632 | |
633 | |||
634 | case BGCOLOR: |
||
9427 | schaersvoo | 635 | /* |
11806 | schaersvoo | 636 | @ bgcolor colorname or #hex |
637 | @ use this color as background of the "div" containing the canvas(es) |
||
12110 | schaersvoo | 638 | @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue |
9427 | schaersvoo | 639 | */ |
11806 | schaersvoo | 640 | /* [255,255,255]*/ |
641 | bgcolor = get_string(infile,1); |
||
642 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
643 | int found = 0; |
||
644 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
645 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
646 | bgcolor = colors[i].hex; |
||
647 | found = 1; |
||
648 | break; |
||
649 | } |
||
9427 | schaersvoo | 650 | } |
14066 | bpr | 651 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");} |
11806 | schaersvoo | 652 | } |
13970 | obado | 653 | 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 | 654 | break; |
655 | |||
656 | case BGIMAGE: |
||
657 | /* |
||
658 | @ bgimage image_location |
||
14071 | bpr | 659 | @ use an image as background; technical: we use the background of ''canvas_div`` |
11806 | schaersvoo | 660 | @ the background image will be resized to match "width = xsize" and "height = ysize" |
12110 | schaersvoo | 661 | @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif |
11806 | schaersvoo | 662 | */ |
663 | URL = get_string(infile,1); |
||
13970 | obado | 664 | 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 | 665 | break; |
666 | |||
667 | case BLINK: |
||
668 | /* |
||
669 | @ blink time(seconds) |
||
670 | @ NOT IMPLEMETED -YET |
||
671 | */ |
||
672 | break; |
||
673 | |||
674 | case BOXPLOT: |
||
675 | /* |
||
676 | @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max |
||
14066 | bpr | 677 | @ 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 |
678 | @ 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 |
||
679 | @ 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 |
||
680 | @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern. |
||
681 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours |
||
14379 | bpr | 682 | @ 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 | 683 | @ there is no limit to the number of boxplots used. |
14078 | bpr | 684 | @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet |
14066 | bpr | 685 | @ 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) |
686 | @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means. |
||
687 | @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date |
||
12110 | schaersvoo | 688 | @%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 |
689 | @%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 | 690 | @%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 | 691 | */ |
15111 | schaersvoo | 692 | js_function[DRAW_BOXPLOT] = 1; |
11806 | schaersvoo | 693 | for(i=0;i<8;i++){ |
694 | switch(i){ |
||
695 | case 0: temp = get_string_argument(infile,0); |
||
696 | if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */ |
||
697 | case 1: double_data[0] = get_real(infile,0);break;/* height | width */ |
||
698 | case 2: |
||
699 | if( js_function[DRAW_JSBOXPLOT] == 0 ){ |
||
700 | double_data[1] = get_real(infile,0); |
||
701 | fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */ |
||
702 | } |
||
703 | else |
||
704 | { |
||
705 | double_data[1] = get_real(infile,1); |
||
706 | double_data[2] = 1; |
||
707 | double_data[3] = 1; |
||
708 | double_data[4] = 1; |
||
709 | double_data[5] = 1; |
||
710 | double_data[6] = 1; |
||
711 | double_data[7] = 1; |
||
712 | i=8; |
||
713 | } |
||
714 | break;/* center value x or y */ |
||
715 | case 3: double_data[2] = get_real(infile,0); break;/* min */ |
||
716 | case 4: double_data[3] = get_real(infile,0); break;/* Q1 */ |
||
717 | case 5: double_data[4] = get_real(infile,0); break;/* median */ |
||
718 | case 6: double_data[5] = get_real(infile,0); break;/* Q3 */ |
||
719 | case 7: double_data[6] = get_real(infile,1); break;/* max */ |
||
720 | default:break; |
||
9427 | schaersvoo | 721 | } |
722 | } |
||
723 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 724 | /*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 | 725 | 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 | 726 | check_string_length(string_length); |
14208 | schaersvoo | 727 | tmp_buffer = my_newmem(string_length); |
11806 | schaersvoo | 728 | 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]); |
729 | add_to_buffer(tmp_buffer); |
||
730 | boxplot_cnt++; |
||
731 | reset(); |
||
732 | break; |
||
733 | case BOXPLOTDATA: |
||
734 | /* |
||
735 | @ boxplotdata some_data |
||
15111 | schaersvoo | 736 | @ 'some_data' are a list of numbers separated by a comma "," (items) |
14071 | bpr | 737 | @ 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 | 738 | @ 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 |
739 | @ note: wims will not check your data input | format. use js-error console to debug any problems. |
||
14071 | bpr | 740 | @ 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. |
741 | @ 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 | 742 | @%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 | 743 | */ |
15111 | schaersvoo | 744 | js_function[DRAW_JSBOXPLOT] = 1; |
745 | js_function[DRAW_BOXPLOT] = 1; |
||
11806 | schaersvoo | 746 | fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1)); |
747 | |||
748 | break; |
||
749 | |||
750 | case CANVASTYPE: |
||
751 | canvas_type = (int) (get_real(infile,1)); |
||
752 | /* |
||
753 | @ canvastype TYPE |
||
14246 | bpr | 754 | @ 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 | 755 | @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas) |
756 | @ use another TYPE, if you know what you are doing... |
||
15309 | schaersvoo | 757 | @ other possible canvasses (e.g. transparent PNG pictures, xsize × 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 | 758 | */ |
759 | break; |
||
760 | |||
15111 | schaersvoo | 761 | case CENTERED: |
762 | use_offset = 4; |
||
763 | /* |
||
764 | @ centered |
||
765 | @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y) |
||
766 | @ may be used for text exactly centered on its (x;y) |
||
767 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
||
768 | @ 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``) |
||
15313 | schaersvoo | 769 | @%centered%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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 |
15111 | schaersvoo | 770 | */ |
771 | break; |
||
772 | |||
11806 | schaersvoo | 773 | case CENTERSTRING: |
774 | /* |
||
775 | @ centerstring color,y-value,the text string |
||
776 | @ title color,y-value,the text string |
||
777 | @ draw a string centered on the canvas at y = y-value |
||
14071 | bpr | 778 | @ can not be set ''onclick`` or ''drag xy`` (...) |
14162 | bpr | 779 | @ unicode supported: <code>centerstring red,5,\\u2232</code> |
15313 | schaersvoo | 780 | @ use a command like <code>fontfamily italic 24pt Arial</code> to set fonts on browser that support font change |
12110 | schaersvoo | 781 | @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center |
11806 | schaersvoo | 782 | */ |
15111 | schaersvoo | 783 | js_function[DRAW_CENTERSTRING] = 1; |
11806 | schaersvoo | 784 | for(i=0;i<3;i++){ |
785 | switch(i){ |
||
786 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
787 | case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/ |
||
788 | case 2: temp = get_string_argument(infile,1); |
||
789 | /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */ |
||
790 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 791 | string_length = 1 + snprintf(NULL,0,"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 | 792 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
11806 | schaersvoo | 793 | 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); |
794 | add_to_buffer(tmp_buffer); |
||
795 | break; |
||
796 | default:break; |
||
797 | } |
||
9427 | schaersvoo | 798 | } |
799 | break; |
||
15111 | schaersvoo | 800 | case CHEMTEX: |
801 | /* |
||
15116 | bpr | 802 | chemtex |
803 | keyword...needs to be the first command in the script (even before the ''size`` command) |
||
804 | only for KaTeX enabled typesetting ! |
||
805 | will include 80kB large js-library for chemisty typesetting |
||
806 | using <a href="http://85.148.206.56/wims/download/katex.for.wims.tar.gz">KaTeX</a> : <code>katex x,y,\\ce{ chemistry tex code} like : \\ce{ Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2- }</code> |
||
807 | using MathJaX : <code>latex x,y,\\ce{ chemistry tex code} like : \\ce{ Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2- }</code> |
||
808 | see https://mhchem.github.io/MathJax-mhchem/ |
||
15313 | schaersvoo | 809 | %chemtex_katex_mathjax%chemtex%size 400,400%xrange -10,10%yrange -10,10%snaptogrid%fontfamily 22px Arial%strokecolor red%drag xy%centered%latex 0,8,\\ce{Hg^2+}%drag xy%centered%latex 0,4,\\ce{\\xrightarrow{\\text{I}^{-}}}%drag xy%centered%latex 0,0,\\ce{HgI2}%centered%drag xy%latex 0,-4,\\ce{\\xrightarrow{\\text{I}^{-}}}%drag xy%centered%latex 0,-8,\\ce{[Hg^{II}I4]^2-} |
15111 | schaersvoo | 810 | */ |
811 | found_size_command = 1; |
||
812 | fprintf(stdout,"\n<script src=\"scripts/js/KaTeX/mhchem.js\" defer></script>\n"); |
||
813 | break; |
||
8386 | schaersvoo | 814 | |
815 | case CIRCLE: |
||
8299 | schaersvoo | 816 | /* |
8386 | schaersvoo | 817 | @ circle xc,yc,width (2*r in pixels),color |
15111 | schaersvoo | 818 | @ use command <code>fcircle xc,yc,d,color</code> |
819 | @ alternative: disk for a filled circle |
||
820 | @ use command <code>fillcolor color</code> to set the fillcolor |
||
14071 | bpr | 821 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> |
15111 | schaersvoo | 822 | @ will shrink / expand on zoom out / zoom in |
12110 | schaersvoo | 823 | @%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 | 824 | */ |
8386 | schaersvoo | 825 | for(i=0;i<4;i++){ |
826 | switch(i){ |
||
827 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
828 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
14066 | bpr | 829 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/ |
8386 | schaersvoo | 830 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
15111 | schaersvoo | 831 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
832 | if(use_affine == TRUE ){ transform(2,2);} |
||
833 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8386 | schaersvoo | 834 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 835 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
836 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
837 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
838 | add_to_buffer(tmp_buffer); |
||
839 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
840 | dragstuff[13] = 1; |
||
841 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8386 | schaersvoo | 842 | reset(); |
843 | break; |
||
844 | default : break; |
||
845 | } |
||
846 | } |
||
847 | break; |
||
848 | |||
849 | case CIRCLES: |
||
850 | /* |
||
851 | @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n |
||
9383 | schaersvoo | 852 | @ <b>attention</b> r = radius in x-range (!) |
14071 | bpr | 853 | @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles |
14066 | bpr | 854 | @ alternative: disks for filled circles |
14071 | bpr | 855 | @ use command <code>fillcolor color</code> to set the fillcolor |
856 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually) |
||
8386 | schaersvoo | 857 | @ will shrink / expand on zoom out / zoom in |
14208 | schaersvoo | 858 | @%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 |
859 | @%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 |
||
860 | @%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 | 861 | */ |
8299 | schaersvoo | 862 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
863 | fill_color = stroke_color; |
||
8386 | schaersvoo | 864 | i=1; |
8299 | schaersvoo | 865 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 866 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 867 | switch (i%3){ |
868 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
869 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
870 | case 0:double_data[i-1] = get_real(infile,1);break; /* r */ |
||
8299 | schaersvoo | 871 | } |
872 | i++; |
||
873 | } |
||
15111 | schaersvoo | 874 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,3);} |
875 | if(use_affine == TRUE ){ transform(i-1,3);} |
||
876 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
877 | |||
8299 | schaersvoo | 878 | decimals = find_number_of_digits(precision); |
8386 | schaersvoo | 879 | for(c = 0 ; c < i-1 ; c = c+3){ |
15111 | schaersvoo | 880 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
881 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
882 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
883 | add_to_buffer(tmp_buffer); |
||
884 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8299 | schaersvoo | 885 | } |
886 | reset(); |
||
15111 | schaersvoo | 887 | dragstuff[13] = 1; |
888 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8299 | schaersvoo | 889 | break; |
11806 | schaersvoo | 890 | case CLEARBUTTON: |
891 | /* |
||
892 | @ clearbutton value |
||
14071 | bpr | 893 | @ alternative: <code>delete</code> |
894 | @ alternative: <code>erase</code> |
||
15111 | schaersvoo | 895 | @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value`` |
896 | @ <b>attention</b> command <code>clearbutton</code> is incompatible with <a href="#multidraw">multidraw</a> based drawings<br/>(in <code>multidraw</code> there is always a remove_object_button for every draw primitive) |
||
897 | @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings |
||
14071 | bpr | 898 | @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code> |
15111 | schaersvoo | 899 | @ use command <a href="#css">css</a> to style the button... |
900 | @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script<br />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 | 901 | @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All |
11806 | schaersvoo | 902 | */ |
903 | if(reply_format == 29){/* eg multidraw is selected */ |
||
14054 | schaersvoo | 904 | // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw"); |
11806 | schaersvoo | 905 | } |
15111 | schaersvoo | 906 | add_clear_button(css_class,get_string(infile,1)); |
11806 | schaersvoo | 907 | break; |
8386 | schaersvoo | 908 | |
11806 | schaersvoo | 909 | case CLOCK: |
7614 | schaersvoo | 910 | /* |
11806 | schaersvoo | 911 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
14071 | bpr | 912 | @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency |
14066 | bpr | 913 | @ type hourglass:<br />type = 0: only segments<br />type = 1: only numbers<br />type = 2: numbers and segments |
11806 | schaersvoo | 914 | @ 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 |
915 | @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass... |
||
14162 | bpr | 916 | @ 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 | 917 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
918 | @ no combinations with other reply_types allowed, for now |
||
14077 | bpr | 919 | @ 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 |
920 | @ 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 | 921 | @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a> |
12110 | schaersvoo | 922 | @%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 |
923 | @%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 |
||
924 | @%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 |
||
925 | @%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 |
||
926 | @%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 |
||
927 | @%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 |
||
928 | @%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 | 929 | */ |
15111 | schaersvoo | 930 | js_function[DRAW_CLOCK] = 1; |
931 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 932 | |
933 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
934 | for(i=0;i<9;i++){ |
||
935 | switch(i){ |
||
936 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
937 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
938 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
939 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
940 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
941 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
942 | 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 */ |
||
943 | case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/ |
||
944 | switch(int_data[7]){ |
||
945 | case 0:break; |
||
946 | case 1:if(clock_cnt == 0){ |
||
947 | if( reply_format == 0 ){ |
||
948 | reply_format = 18; /* user sets clock */ |
||
14208 | schaersvoo | 949 | /* 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"); |
950 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 951 | 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"); |
952 | add_to_buffer(tmp_buffer); |
||
953 | */ |
||
954 | 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"); |
||
955 | } |
||
956 | else |
||
957 | { |
||
958 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
959 | } |
||
960 | } |
||
15111 | schaersvoo | 961 | fprintf(stdout,"<p style=\"text-align:center\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt); |
11806 | schaersvoo | 962 | break; |
963 | case 3:if(clock_cnt == 0){ |
||
964 | if( reply_format == 0 ){ |
||
965 | reply_format = 18; /* user sets clock */ |
||
966 | 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"); |
||
967 | } |
||
968 | else |
||
969 | { |
||
970 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
971 | } |
||
972 | } |
||
973 | /* |
||
15111 | schaersvoo | 974 | fprintf(stdout,"<p style=\"text-align:center\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt); |
11806 | schaersvoo | 975 | */ |
976 | break; |
||
977 | case 2:if( reply_format == 0 ){ |
||
978 | reply_format = 19; /* "onclick */ |
||
15111 | schaersvoo | 979 | js_function[INTERACTIVE] = 1; |
980 | 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.button == 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 | 981 | } |
982 | else |
||
983 | { |
||
984 | if( reply_format != 19){ |
||
985 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
||
986 | } |
||
987 | } |
||
988 | break; |
||
989 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
990 | } |
||
991 | break; |
||
992 | case 8: |
||
14078 | bpr | 993 | if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */ |
11806 | schaersvoo | 994 | fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity); |
995 | } |
||
996 | temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/ |
||
997 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
998 | else{ |
||
999 | /* h_color,m_color,s_color,bg_color,fg_color */ |
||
11991 | schaersvoo | 1000 | temp = ",black\",\"black\",\"black\",\"white\",\"black";} |
14208 | schaersvoo | 1001 | 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); |
1002 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 1003 | 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); |
1004 | add_to_buffer(tmp_buffer); |
||
1005 | fprintf(js_include_file,"var clocks%d;",clock_cnt); |
||
1006 | clock_cnt++; |
||
1007 | break; |
||
1008 | default:break; |
||
1009 | } |
||
1010 | } |
||
1011 | break; |
||
1012 | |||
1013 | |||
1014 | case COLORPALETTE: |
||
1015 | /* |
||
1016 | @ colorpalette color_name_1,color_name_2,...,color_name_8 |
||
1017 | @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a> |
||
14066 | bpr | 1018 | @ 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 | 1019 | @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a> |
11806 | schaersvoo | 1020 | */ |
1021 | if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");} |
||
1022 | fprintf(js_include_file,"var multifillcolors = [];var palettecolors = ["); |
||
1023 | while( ! done ){ |
||
1024 | temp = get_color(infile,1); |
||
1025 | fprintf(js_include_file,"\"%s\",",temp); |
||
1026 | } |
||
1027 | fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */ |
||
15111 | schaersvoo | 1028 | add_color_palette(css_class); |
11806 | schaersvoo | 1029 | break; |
13829 | bpr | 1030 | |
15111 | schaersvoo | 1031 | case COMMENT: |
1032 | sync_input(infile); |
||
1033 | break; |
||
1034 | |||
1035 | |||
11806 | schaersvoo | 1036 | case COPY: |
1037 | /* |
||
1038 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
1039 | @ The image may be "bitmap" or "SVG" |
||
1040 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
1041 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
1042 | @ [filename] is the URL of the image |
||
15111 | schaersvoo | 1043 | @ <em>TODO:move special image functions to generic 'dragstuff' library</em> |
1044 | @ URL is normal URL of network reachable image file location |
||
1045 | @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords ''snaptogrid``, ''xsnaptogrid``, ''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code>. |
||
1046 | @ 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 |
||
1047 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves, embeded XML etc) |
||
11806 | schaersvoo | 1048 | @ you may draw / userdraw / drag other stuff on top of an "imported" image |
15633 | bpr | 1049 | @ the use of a slider is not possible: if needed, use command <a href='#html'>html x,y,<img src=my_image.svg /> </a> |
14077 | bpr | 1050 | @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates. |
13967 | schaersvoo | 1051 | @%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 | 1052 | @%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 |
1053 | @%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 | 1054 | */ |
1055 | for(i = 0 ; i<7;i++){ |
||
7614 | schaersvoo | 1056 | switch(i){ |
15111 | schaersvoo | 1057 | case 0: double_data[0]=get_real(infile,0);break; /* x left top corner in x/y range */ |
1058 | case 1: double_data[1]=get_real(infile,0);break; /* y left top corner in x/y range */ |
||
11806 | schaersvoo | 1059 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
1060 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
1061 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
1062 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
1063 | case 6: URL = get_string(infile,1); |
||
15111 | schaersvoo | 1064 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1065 | if(use_affine == TRUE ){transform(2,2);} |
||
1066 | int_data[0] = x2px(double_data[0]); |
||
1067 | int_data[1] = y2px(double_data[1]); |
||
11806 | schaersvoo | 1068 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
1069 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
15111 | schaersvoo | 1070 | if( onclick == 0 ){ /* no mouse needed static image copy */ |
1071 | if(js_function[DRAW_EXTERNAL_IMAGE] == 0){/* create canvas just once */ |
||
1072 | fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS); |
||
1073 | js_function[DRAW_EXTERNAL_IMAGE] = 1; |
||
1074 | } |
||
1075 | string_length = 1 + snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%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],use_offset,int_data[10]); |
||
1076 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1077 | snprintf(tmp_buffer,string_length, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%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],use_offset,int_data[10]); |
||
11806 | schaersvoo | 1078 | } |
15111 | schaersvoo | 1079 | else /* onclick or drag & drop external copy images */ |
11806 | schaersvoo | 1080 | { |
15111 | schaersvoo | 1081 | js_function[DRAG_EXTERNAL_IMAGE] = 1; |
1082 | string_length = 1 + snprintf(NULL,0, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%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],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
||
1083 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
15116 | bpr | 1084 | snprintf(tmp_buffer,string_length, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%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],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
11806 | schaersvoo | 1085 | } |
14038 | schaersvoo | 1086 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1087 | break; |
7614 | schaersvoo | 1088 | default: break; |
1089 | } |
||
1090 | } |
||
15111 | schaersvoo | 1091 | reset(); |
7614 | schaersvoo | 1092 | break; |
11806 | schaersvoo | 1093 | /* |
1094 | HTML5 specs: |
||
1095 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1096 | img Specifies the image, canvas, or video element to use |
||
14066 | bpr | 1097 | sx The x coordinate where to start clipping: x1 = int_data[0] |
1098 | sy The y coordinate where to start clipping: x2 = int_data[1] |
||
1099 | swidth The width of the clipped image: int_data[2] - int_data[0] |
||
1100 | sheight The height of the clipped image: int_data[3] - int_data[1] |
||
1101 | x The x coordinate where to place the image on the canvas: dx1 = int_data[4] |
||
1102 | y The y coordinate where to place the image on the canvas: dy1 = int_data[5] |
||
1103 | width The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6] |
||
1104 | height The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7] |
||
11806 | schaersvoo | 1105 | */ |
1106 | case COPYRESIZED: |
||
1107 | /* |
||
15111 | schaersvoo | 1108 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
11806 | schaersvoo | 1109 | @ The image may be any "bitmap" or "SVG" |
1110 | @ 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 | 1111 | @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image |
11806 | schaersvoo | 1112 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
15111 | schaersvoo | 1113 | @ URL is normal URL of network reachable image file location<br />(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br />(eg no special wims paths are searched !!) |
1114 | @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords ''snaptogrid``,''xsnaptogrid``,''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code> |
||
1115 | @ 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 |
||
1116 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc) |
||
1117 | @ you may draw / userdraw / drag stuff on top of an "imported" image |
||
1118 | @ 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`` |
||
1119 | @ use keyword <a href='#centered'>centered</a> before command 'copyresized' to place image center at given coordinates. |
||
1120 | @ <em>TODO:move special image functions to generic 'dragstuff' library</em> |
||
11806 | schaersvoo | 1121 | */ |
1122 | for(i = 0 ; i<9;i++){ |
||
1123 | switch(i){ |
||
1124 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
1125 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
1126 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
1127 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
1128 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
1129 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
1130 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
1131 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
1132 | case 8: URL = get_string(infile,1); |
||
15111 | schaersvoo | 1133 | if( int_data[1] == -1 ){ int_data[10] = 1; }else{int_data[10] = 0; }/* resized / not resized */ |
11806 | schaersvoo | 1134 | /* flag error when wrong diagonal: copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */ |
1135 | if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){ |
||
15633 | bpr | 1136 | canvas_error("in copyresized, use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! "); |
11806 | schaersvoo | 1137 | } |
1138 | int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */ |
||
1139 | int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */ |
||
1140 | int_data[6] = abs(int_data[6] - int_data[4]);/* width */ |
||
1141 | int_data[7] = abs(int_data[7] - int_data[5]);/* height */ |
||
15111 | schaersvoo | 1142 | if( onclick == 0 ){ /* no mouse needed static image copy */ |
1143 | if(js_function[DRAW_EXTERNAL_IMAGE] == 0){ |
||
1144 | fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS); |
||
1145 | js_function[DRAW_EXTERNAL_IMAGE] = 1; |
||
1146 | } |
||
1147 | string_length = 1 + snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%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],use_offset,int_data[10]); |
||
1148 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1149 | snprintf(tmp_buffer,string_length, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%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],use_offset,int_data[10]); |
||
11806 | schaersvoo | 1150 | } |
15111 | schaersvoo | 1151 | else /* onclick or drag & drop external copy images */ |
11806 | schaersvoo | 1152 | { |
15111 | schaersvoo | 1153 | js_function[DRAG_EXTERNAL_IMAGE] = 1; |
1154 | string_length = 1 + snprintf(NULL,0, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%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],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
||
1155 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
15116 | bpr | 1156 | snprintf(tmp_buffer,string_length, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%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],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
15111 | schaersvoo | 1157 | object_cnt++; |
11806 | schaersvoo | 1158 | } |
14038 | schaersvoo | 1159 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1160 | break; |
1161 | default: break; |
||
1162 | } |
||
1163 | } |
||
14038 | schaersvoo | 1164 | reset(); |
11806 | schaersvoo | 1165 | break; |
8386 | schaersvoo | 1166 | |
11806 | schaersvoo | 1167 | case CROSSHAIR: |
8386 | schaersvoo | 1168 | /* |
11806 | schaersvoo | 1169 | @ crosshair x,y,color |
14379 | bpr | 1170 | @ draw a single crosshair point at (x;y) in color ''color`` |
1171 | @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust |
||
11806 | schaersvoo | 1172 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 1173 | @%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 | 1174 | */ |
1175 | for(i=0;i<3;i++){ |
||
1176 | switch(i){ |
||
1177 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1178 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1179 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 1180 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1181 | if(use_affine == TRUE ){ transform(2,2);} |
||
1182 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 1183 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1184 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
1185 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1186 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1187 | add_to_buffer(tmp_buffer); |
||
1188 | if(onclick != 0){object_cnt++;} |
||
1189 | /* object_cnt++ */ |
||
11806 | schaersvoo | 1190 | reset(); |
15111 | schaersvoo | 1191 | dragstuff[7] = 1; |
11806 | schaersvoo | 1192 | break; |
1193 | default:break; |
||
1194 | } |
||
1195 | } |
||
15111 | schaersvoo | 1196 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
11806 | schaersvoo | 1197 | break; |
1198 | |||
1199 | case CROSSHAIRS: |
||
1200 | /* |
||
1201 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
14077 | bpr | 1202 | @ draw multiple crosshair points at given coordinates in color ''color`` |
14246 | bpr | 1203 | @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust |
9406 | schaersvoo | 1204 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 1205 | @%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 |
1206 | @%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 |
||
1207 | */ |
||
8386 | schaersvoo | 1208 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1209 | fill_color = stroke_color; |
||
1210 | i=0; |
||
1211 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 1212 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 1213 | if(i%2 == 0 ){ |
1214 | double_data[i] = get_real(infile,0); /* x */ |
||
1215 | } |
||
1216 | else |
||
1217 | { |
||
1218 | double_data[i] = get_real(infile,1); /* y */ |
||
1219 | } |
||
1220 | i++; |
||
1221 | } |
||
15111 | schaersvoo | 1222 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
1223 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
1224 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8386 | schaersvoo | 1225 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 1226 | for(c=0 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 1227 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
1228 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1229 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1230 | add_to_buffer(tmp_buffer); |
||
1231 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8386 | schaersvoo | 1232 | } |
15111 | schaersvoo | 1233 | dragstuff[7] = 1; |
1234 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8386 | schaersvoo | 1235 | reset(); |
1236 | break; |
||
1237 | |||
11806 | schaersvoo | 1238 | case CROSSHAIRSIZE: |
7614 | schaersvoo | 1239 | /* |
11806 | schaersvoo | 1240 | @ crosshairsize int |
1241 | @ default 8 (px) |
||
7614 | schaersvoo | 1242 | */ |
11806 | schaersvoo | 1243 | crosshair_size = (int) (get_real(infile,1)); |
1244 | break; |
||
15111 | schaersvoo | 1245 | case CSS: |
1246 | /* |
||
1247 | @ css css_class |
||
1248 | @ may be used before any ''style-able`` html object (like inputfields or buttons) or some html objects that are generated by some canvasdraw commands |
||
1249 | @ in case of <a href="#multidraw">multidraw</a> this command must be a table css class, for example "wimstable" |
||
1250 | @%css%size 400,400%xrange -10,10%yrange -10,10%css wims_button_help%input 0,0,10,1,Hello |
||
1251 | */ |
||
1252 | css_class = get_string(infile,1); |
||
1253 | break; |
||
11806 | schaersvoo | 1254 | |
1255 | case CURSOR: |
||
1256 | /* |
||
14086 | bpr | 1257 | @ cursor some CSS cursor_style |
14071 | bpr | 1258 | @ alternative: <code>pointer</code> |
13956 | schaersvoo | 1259 | @ style can be any valid CSS property value |
1260 | @ 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 |
||
1261 | @ note: wims will not check the validity of your cursor declaration |
||
1262 | @%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 | 1263 | */ |
1264 | fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1)); |
||
1265 | break; |
||
1266 | |||
1267 | case CURVE: |
||
1268 | /* |
||
1269 | @ curve color,formula(x) |
||
14379 | bpr | 1270 | @ alternative: <code>plot color,formula(x)</code> |
15601 | schaersvoo | 1271 | @ use command <a href="#trange">trange</a> in parametric functions before <b>every</b> command curve / plot <code>trange -pi,pi<br />curve color,formula1(t),formula2(t)</code><br />A next parametric curve will only be correctly plot when trange is set again !<br/>this is a design flaw and not a feature... |
14086 | bpr | 1272 | @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points |
14066 | bpr | 1273 | @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150) |
11806 | schaersvoo | 1274 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14379 | bpr | 1275 | @ 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 | 1276 | @%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 | 1277 | */ |
15111 | schaersvoo | 1278 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
1279 | |||
11806 | schaersvoo | 1280 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
1281 | use_parametric = FALSE; |
||
1282 | stroke_color = get_color(infile,0); |
||
1283 | char *fun1 = get_string_argument(infile,0); |
||
1284 | char *fun2 = get_string_argument(infile,1); |
||
1285 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
15601 | schaersvoo | 1286 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset); |
15116 | bpr | 1287 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15601 | schaersvoo | 1288 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset); |
15111 | schaersvoo | 1289 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1290 | } |
1291 | else |
||
1292 | { |
||
1293 | stroke_color = get_color(infile,0); |
||
1294 | char *fun1 = get_string_argument(infile,1); |
||
1295 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
15601 | schaersvoo | 1296 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset); |
15116 | bpr | 1297 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15601 | schaersvoo | 1298 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset); |
15111 | schaersvoo | 1299 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1300 | } |
15111 | schaersvoo | 1301 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
1302 | dragstuff[9] = 1; |
||
1303 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 1304 | reset(); |
1305 | break; |
||
15116 | bpr | 1306 | |
14038 | schaersvoo | 1307 | case CURVEDARROW: |
1308 | /* |
||
1309 | @ curvedarrow x1,y1,xc,yc,x2,y2,color |
||
15111 | schaersvoo | 1310 | @ draw a single 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 | 1311 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
15111 | schaersvoo | 1312 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
1313 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
14038 | schaersvoo | 1314 | @%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 |
1315 | @%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 | 1316 | |
14029 | schaersvoo | 1317 | h[0] = arrowhead |
14066 | bpr | 1318 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1319 | function Shape(object_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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1320 | */ |
15111 | schaersvoo | 1321 | for(i=0;i<7;i++){ |
14038 | schaersvoo | 1322 | switch(i){ |
1323 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1324 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1325 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1326 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1327 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1328 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1329 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 1330 | if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);} |
1331 | if(use_affine == TRUE ){ transform(6,2);} |
||
1332 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
14038 | schaersvoo | 1333 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1334 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
1335 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1336 | snprintf(tmp_buffer,string_length, "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1337 | add_to_buffer(tmp_buffer); |
||
1338 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
1339 | reset(); |
||
14038 | schaersvoo | 1340 | break; |
1341 | } |
||
15111 | schaersvoo | 1342 | } |
1343 | dragstuff[21] = 1; |
||
1344 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1345 | break; |
||
14029 | schaersvoo | 1346 | |
14038 | schaersvoo | 1347 | case CURVEDARROW2: |
1348 | /* |
||
1349 | @ curvedarrow2 x1,y1,xc,yc,x2,y2,color |
||
14248 | bpr | 1350 | @ 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 | 1351 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1352 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1353 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1354 | @%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 |
||
1355 | @%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 | 1356 | |
1357 | h[0] = arrowhead |
||
14066 | bpr | 1358 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1359 | function Shape(object_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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1360 | */ |
15111 | schaersvoo | 1361 | for(i=0;i<7;i++){ |
14038 | schaersvoo | 1362 | switch(i){ |
1363 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1364 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1365 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1366 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1367 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1368 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1369 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 1370 | if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);} |
1371 | if(use_affine == TRUE ){ transform(6,2);} |
||
1372 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
14038 | schaersvoo | 1373 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1374 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
1375 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1376 | snprintf(tmp_buffer,string_length, "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1377 | add_to_buffer(tmp_buffer); |
||
1378 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
1379 | dragstuff[21] = 1; |
||
1380 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1381 | reset(); |
||
1382 | break; |
||
14038 | schaersvoo | 1383 | } |
15111 | schaersvoo | 1384 | } |
1385 | break; |
||
14038 | schaersvoo | 1386 | case CURVEDARROWS: |
1387 | /* |
||
14248 | bpr | 1388 | @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n |
1389 | @ 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 | 1390 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1391 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1392 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1393 | @%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 |
||
1394 | @%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 | 1395 | |
14030 | schaersvoo | 1396 | h[0] = arrowhead |
14066 | bpr | 1397 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1398 | function Shape(object_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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1399 | */ |
1400 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1401 | i = 0; |
||
1402 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 1403 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
14038 | schaersvoo | 1404 | while( ! done ){ |
15111 | schaersvoo | 1405 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
1406 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1407 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1408 | double_data[2] = get_real(infile,0); /* xc */ |
||
1409 | double_data[3] = get_real(infile,0); /* yc */ |
||
1410 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1411 | double_data[5] = get_real(infile,1); /* y3 */ |
||
1412 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1413 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1414 | snprintf(tmp_buffer,string_length, "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1415 | add_to_buffer(tmp_buffer); |
||
1416 | if(onclick != 0){object_cnt++;} |
||
1417 | i = i + 6; |
||
1418 | } |
||
1419 | if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);} |
||
1420 | if(use_affine == TRUE ){ transform(i-6,2);} |
||
1421 | dragstuff[21] = 1; |
||
1422 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1423 | reset(); |
||
1424 | break; |
||
14030 | schaersvoo | 1425 | |
14038 | schaersvoo | 1426 | case CURVEDARROWS2: |
1427 | /* |
||
1428 | @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n |
||
14248 | bpr | 1429 | @ 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 | 1430 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1431 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1432 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1433 | @%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 |
||
1434 | @%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 | 1435 | |
1436 | h[0] = arrowhead |
||
14066 | bpr | 1437 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1438 | function Shape(object_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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1439 | */ |
1440 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1441 | i = 0; |
||
1442 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 1443 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
14038 | schaersvoo | 1444 | while( ! done ){ |
15111 | schaersvoo | 1445 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
1446 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1447 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1448 | double_data[2] = get_real(infile,0); /* xc */ |
||
1449 | double_data[3] = get_real(infile,0); /* yc */ |
||
1450 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1451 | double_data[5] = get_real(infile,1); /* y3 */ |
||
1452 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1453 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1454 | snprintf(tmp_buffer,string_length, "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1455 | add_to_buffer(tmp_buffer); |
||
1456 | if(onclick != 0){object_cnt++;} |
||
1457 | i = i + 6; |
||
1458 | } |
||
1459 | if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);} |
||
1460 | if(use_affine == TRUE ){ transform(i-6,2);} |
||
1461 | dragstuff[21] = 1; |
||
1462 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1463 | reset(); |
||
1464 | break; |
||
15116 | bpr | 1465 | |
11806 | schaersvoo | 1466 | case DASHED: |
1467 | /* |
||
1468 | @ dashed |
||
1469 | @ keyword (no arguments required) |
||
1470 | @ next object will be drawn with a dashed line |
||
1471 | @ change dashing scheme by using command <a href="#dashtype">dashtype</a> |
||
12107 | schaersvoo | 1472 | @%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 | 1473 | */ |
1474 | use_dashed = TRUE; |
||
1475 | break; |
||
1476 | |||
1477 | case DASHTYPE: |
||
1478 | /* |
||
1479 | @ dashtype line_width_px,space_width_px |
||
1480 | @ every indiviual object may have its own dashtype, if needed... |
||
1481 | @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype |
||
14086 | bpr | 1482 | @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space |
13957 | schaersvoo | 1483 | @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable |
13949 | schaersvoo | 1484 | @%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 | 1485 | */ |
1486 | for(i=0;i<2;i++){ |
||
1487 | switch(i){ |
||
1488 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
1489 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
1490 | } |
||
1491 | } |
||
1492 | break; |
||
1493 | |||
1494 | case DIAMONDFILL: |
||
1495 | /* |
||
1496 | @ diamondfill x0,y0,dx,dy,color |
||
1497 | @ x0,y0 in xrange / yrange |
||
1498 | @ distances dx,dy in pixels |
||
13936 | bpr | 1499 | @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a> |
12110 | schaersvoo | 1500 | @%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 | 1501 | */ |
15111 | schaersvoo | 1502 | js_function[DRAW_DIAMONDFILL] = 1; |
11820 | schaersvoo | 1503 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1504 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 1505 | add_js_filltoborder(canvas_type); |
11820 | schaersvoo | 1506 | } |
1507 | decimals = find_number_of_digits(precision); |
||
7614 | schaersvoo | 1508 | for(i=0;i<5;i++){ |
1509 | switch(i){ |
||
11820 | schaersvoo | 1510 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
14032 | schaersvoo | 1511 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11820 | schaersvoo | 1512 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
1513 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1514 | case 4: stroke_color = get_color(infile,1); |
15111 | schaersvoo | 1515 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1516 | if(use_affine == TRUE ){ transform(2,2);} |
||
11806 | schaersvoo | 1517 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
14208 | schaersvoo | 1518 | 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); |
1519 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 1520 | 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 | 1521 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1522 | fill_cnt++; |
15111 | schaersvoo | 1523 | reset(); |
11806 | schaersvoo | 1524 | break; |
1525 | default:break; |
||
1526 | } |
||
1527 | } |
||
1528 | break; |
||
8224 | bpr | 1529 | |
11806 | schaersvoo | 1530 | case DOTFILL: |
1531 | /* |
||
1532 | @ dotfill x0,y0,dx,dy,color |
||
1533 | @ x0,y0 in xrange / yrange |
||
1534 | @ distances dx,dy in pixels |
||
1535 | @ radius of dots is linewidth |
||
13936 | bpr | 1536 | @ there is also a command <a href="#userdraw">userdraw dotfill,color</a> |
12110 | schaersvoo | 1537 | @%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 | 1538 | */ |
15111 | schaersvoo | 1539 | js_function[DRAW_DOTFILL] = 1; |
11817 | schaersvoo | 1540 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1541 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 1542 | add_js_filltoborder(canvas_type); |
11817 | schaersvoo | 1543 | } |
1544 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1545 | for(i=0;i<5;i++){ |
1546 | switch(i){ |
||
11817 | schaersvoo | 1547 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
1548 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
1549 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1550 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1551 | case 4: stroke_color = get_color(infile,1); |
15111 | schaersvoo | 1552 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1553 | if(use_affine == TRUE ){ transform(2,2);} |
||
11806 | schaersvoo | 1554 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
14208 | schaersvoo | 1555 | 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); |
1556 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11817 | schaersvoo | 1557 | 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 | 1558 | add_to_buffer(tmp_buffer); |
11817 | schaersvoo | 1559 | fill_cnt++; |
15111 | schaersvoo | 1560 | reset(); |
7614 | schaersvoo | 1561 | break; |
11806 | schaersvoo | 1562 | default:break; |
7614 | schaersvoo | 1563 | } |
1564 | } |
||
11806 | schaersvoo | 1565 | break; |
1566 | |||
1567 | case DRAG: |
||
1568 | /* |
||
1569 | @ drag [x][y][xy] |
||
1570 | @ the next object will be draggable in x / y / xy direction |
||
14077 | bpr | 1571 | @ the displacement can be read by <code>javascript:read_dragdrop();</code> |
15111 | schaersvoo | 1572 | @ 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 | 1573 | @ <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 | 1574 | @ ''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) |
15313 | schaersvoo | 1575 | @ <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<br /> <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<br /><code>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />both points will be recognised |
14066 | bpr | 1576 | @ 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) |
15650 | reyssat | 1577 | @ 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 | 1578 | @ 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. |
13829 | bpr | 1579 | @%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 |
1580 | @%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 |
||
1581 | @%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 | 1582 | */ |
1583 | temp = get_string(infile,1); |
||
1584 | if(strstr(temp,"xy") != NULL ){ |
||
1585 | drag_type = 0; |
||
1586 | } |
||
1587 | else |
||
1588 | { |
||
1589 | if(strstr(temp,"x") != NULL ){ |
||
1590 | drag_type = 1; |
||
1591 | } |
||
1592 | else |
||
1593 | { |
||
1594 | drag_type = 2; |
||
1595 | } |
||
1596 | } |
||
1597 | /* assuming all drag&drop coordinates the same precision: so set only once */ |
||
1598 | if( print_drag_params_only_once == FALSE ){ |
||
15111 | schaersvoo | 1599 | fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;",precision); |
11806 | schaersvoo | 1600 | print_drag_params_only_once = TRUE; |
1601 | } |
||
1602 | onclick = 2; |
||
1603 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
15111 | schaersvoo | 1604 | use_dragstuff = 2; |
1605 | js_function[INTERACTIVE] = 1; |
||
7614 | schaersvoo | 1606 | break; |
8386 | schaersvoo | 1607 | |
11806 | schaersvoo | 1608 | case ELLIPSE: |
8351 | schaersvoo | 1609 | /* |
11806 | schaersvoo | 1610 | @ ellipse xc,yc,radius_x,radius_y,color |
15111 | schaersvoo | 1611 | @ ellipses with center xc/yc and radius in x/y-range etc (this differs from flydraw syntax!) |
11806 | schaersvoo | 1612 | @ radius_x and radius_y are in pixels |
9406 | schaersvoo | 1613 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
11806 | schaersvoo | 1614 | @ will shrink / expand on zoom out / zoom in |
13949 | schaersvoo | 1615 | @%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 | 1616 | */ |
11806 | schaersvoo | 1617 | for(i=0;i<5;i++){ |
1618 | switch(i){ |
||
1619 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1620 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
14066 | bpr | 1621 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
1622 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
||
11806 | schaersvoo | 1623 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
15111 | schaersvoo | 1624 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,4);} |
1625 | if(use_affine == TRUE ){ transform(2,4);} |
||
1626 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 1627 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1628 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
1629 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1630 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1631 | add_to_buffer(tmp_buffer); |
||
1632 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
1633 | dragstuff[3] = 1; |
||
1634 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 1635 | reset(); |
1636 | break; |
||
1637 | } |
||
1638 | } |
||
1639 | break; |
||
13829 | bpr | 1640 | |
12110 | schaersvoo | 1641 | case ELLIPSES: |
1642 | /* |
||
1643 | @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,... |
||
15111 | schaersvoo | 1644 | @ ellipses with center and radius in x/y-range etc (this differs from flydraw syntax!) |
12110 | schaersvoo | 1645 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1646 | @ will shrink / expand on zoom out / zoom in |
||
13949 | schaersvoo | 1647 | @%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 | 1648 | */ |
13829 | bpr | 1649 | |
15111 | schaersvoo | 1650 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
12110 | schaersvoo | 1651 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1652 | fill_color = stroke_color; |
||
1653 | i=1; |
||
1654 | while( ! done ){ /* get next item until EOL*/ |
||
1655 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1656 | switch (i%4){ |
||
1657 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
1658 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
1659 | case 3:double_data[i-1] = get_real(infile,0);break; /* rx */ |
||
1660 | case 0:double_data[i-1] = get_real(infile,1);break; /* ry */ |
||
1661 | default: break; |
||
1662 | } |
||
1663 | i++; |
||
1664 | } |
||
15111 | schaersvoo | 1665 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,4);} |
1666 | if(use_affine == TRUE ){ transform(i-1,4);} |
||
12110 | schaersvoo | 1667 | decimals = find_number_of_digits(precision); |
1668 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
15111 | schaersvoo | 1669 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
1670 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1671 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
1672 | add_to_buffer(tmp_buffer); |
||
1673 | if(onclick != 0){object_cnt++;} /* object_cnt++; */ |
||
12110 | schaersvoo | 1674 | } |
1675 | reset(); |
||
15111 | schaersvoo | 1676 | dragstuff[3] = 1; |
1677 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
12110 | schaersvoo | 1678 | break; |
1679 | |||
11806 | schaersvoo | 1680 | case FILLALL: |
1681 | /* |
||
1682 | @ fillall color,x1,y1,x2,y2...x_n,y_n |
||
15111 | schaersvoo | 1683 | @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color' |
15650 | reyssat | 1684 | @ any other colors (objects) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill |
14246 | bpr | 1685 | @ use this command after all boundary objects are declared. |
15111 | schaersvoo | 1686 | @ Use command 'userdraw clickfill,color' for user click driven flood fill. |
1687 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
||
14071 | bpr | 1688 | @ 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 | 1689 | @%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 | 1690 | */ |
1691 | decimals = find_number_of_digits(precision); |
||
1692 | fill_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
8351 | schaersvoo | 1693 | i=0; |
11806 | schaersvoo | 1694 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1695 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 1696 | add_js_filltoborder(canvas_type); |
11806 | schaersvoo | 1697 | } |
8351 | schaersvoo | 1698 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 1699 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8351 | schaersvoo | 1700 | if(i%2 == 0 ){ |
1701 | double_data[i] = get_real(infile,0); /* x */ |
||
1702 | } |
||
1703 | else |
||
1704 | { |
||
1705 | double_data[i] = get_real(infile,1); /* y */ |
||
14208 | schaersvoo | 1706 | 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); |
1707 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1708 | 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 | 1709 | add_to_buffer(tmp_buffer); |
1710 | fill_cnt++; |
||
8351 | schaersvoo | 1711 | } |
1712 | i++; |
||
1713 | } |
||
11806 | schaersvoo | 1714 | break; |
1715 | |||
1716 | case FILLED: |
||
1717 | /* |
||
1718 | @ filled |
||
1719 | @ keyword (no arguments required) |
||
14077 | bpr | 1720 | @ the next ''fillable`` object (only the next !) will be filled |
14066 | bpr | 1721 | @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor |
11839 | schaersvoo | 1722 | @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
14086 | bpr | 1723 | @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity |
14066 | bpr | 1724 | @ 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 | 1725 | */ |
11839 | schaersvoo | 1726 | use_filled = 1; |
11806 | schaersvoo | 1727 | break; |
1728 | |||
1729 | case FILLCOLOR: |
||
1730 | /* |
||
1731 | @ fillcolor colorname or #hex |
||
15111 | schaersvoo | 1732 | @ set the color: mainly used for command 'userdraw obj,stroke_color' |
11806 | schaersvoo | 1733 | @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
11839 | schaersvoo | 1734 | @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
11806 | schaersvoo | 1735 | */ |
1736 | fill_color = get_color(infile,1); |
||
1737 | break; |
||
1738 | |||
11837 | schaersvoo | 1739 | case FILLPATTERN: |
1740 | /* |
||
15601 | schaersvoo | 1741 | @ fillpattern grid | hatch | diamond | dot | image_url |
1742 | @ alternative: <code>settile image_url</code> (e.g. flydraw syntax for filling using a tiled image) |
||
11837 | schaersvoo | 1743 | @ use a pattern as fillstyle |
14066 | bpr | 1744 | @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a> |
15601 | schaersvoo | 1745 | @ note: do not use the ''f`` for a fillable object : this is used exclusively for solid colour filling. |
14066 | bpr | 1746 | @ 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 | 1747 | @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed) |
11837 | schaersvoo | 1748 | @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a> |
11839 | schaersvoo | 1749 | @ see <a href="#fillcolor">fillcolor</a> for solid color filling. |
15111 | schaersvoo | 1750 | @ 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> |
1751 | @ 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'<br />'userdraw hatchfill,color' etc |
||
1752 | @%fillpattern_1%size 400,400%xrange -5,5%yrange -5,5%opacity 165,150%fillpattern grid%circle -6,3,160,blue%fillpattern dot%circle -3,-3,160,red%fillpattern hatch%circle 0,3,160,green%filpattern diamond%circle 3,-3,160,cyan%zoom red |
||
1753 | @%fillpattern_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%fillcolor green%fillpattern hatch%#fillpattern dot,diamond,grid,imageurl%userdraw circle,red |
||
11837 | schaersvoo | 1754 | */ |
1755 | temp = get_string(infile,1); |
||
15111 | schaersvoo | 1756 | use_filled = 0; |
1757 | js_function[DRAW_FILL_PATTERN] = 1; |
||
15116 | bpr | 1758 | if( strstr(temp,"grid") != 0 ){ use_filled = 2;} |
15111 | schaersvoo | 1759 | else{ |
1760 | if( strstr(temp,"hatch") != 0 ){ use_filled = 3;} |
||
1761 | else{ |
||
1762 | if( strstr(temp,"diamond") != 0 ){ use_filled = 4;} |
||
1763 | else{ |
||
1764 | if( strstr(temp,"dot") != 0 ){ use_filled = 5;} |
||
1765 | else{ |
||
15600 | schaersvoo | 1766 | if( strstr(temp,"/") != 0 ){ /* get_image_from_url() needs to be called after function definition...*/ |
1767 | use_filled = 6;js_function[JS_LOAD_IMAGE] = 1; |
||
1768 | string_length = 1 + snprintf(NULL,0,"get_image_from_url(\"%s\");",temp); |
||
1769 | check_string_length(string_length); |
||
1770 | tmp_buffer = my_newmem(string_length); |
||
1771 | snprintf(tmp_buffer,string_length,"get_image_from_url(\"%s\");",temp); |
||
1772 | add_to_buffer(tmp_buffer); |
||
1773 | } |
||
15111 | schaersvoo | 1774 | } |
1775 | } |
||
1776 | } |
||
1777 | } |
||
1778 | if( use_filled == 0 ){canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");} |
||
11837 | schaersvoo | 1779 | break; |
11806 | schaersvoo | 1780 | case FILLTOBORDER: |
1781 | /* |
||
1782 | @ filltoborder x,y,bordercolor,color |
||
15111 | schaersvoo | 1783 | @ fill the region of point (x:y) with color 'color' |
11806 | schaersvoo | 1784 | @ any other color will not act as border to the bucket fill |
14246 | bpr | 1785 | @ use this command after all boundary objects are declared. |
11806 | schaersvoo | 1786 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1787 | @ 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 | 1788 | @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a> |
12110 | schaersvoo | 1789 | @%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 | 1790 | */ |
1791 | for(i=0 ;i < 4 ; i++){ |
||
1792 | switch(i){ |
||
1793 | case 0:double_data[0] = get_real(infile,0);break; |
||
1794 | case 1:double_data[1] = get_real(infile,0);break; |
||
1795 | case 2:bgcolor = get_color(infile,0);break; |
||
1796 | case 3:fill_color = get_color(infile,1); |
||
1797 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
15111 | schaersvoo | 1798 | js_function[DRAW_FILLTOBORDER] = 1; |
1799 | add_js_filltoborder(canvas_type); |
||
11806 | schaersvoo | 1800 | } |
1801 | decimals = find_number_of_digits(precision); |
||
1802 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
14208 | schaersvoo | 1803 | 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); |
1804 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1805 | 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 | 1806 | add_to_buffer(tmp_buffer); |
1807 | fill_cnt++; |
||
15111 | schaersvoo | 1808 | reset(); |
11806 | schaersvoo | 1809 | break; |
1810 | default:break; |
||
8351 | schaersvoo | 1811 | } |
11806 | schaersvoo | 1812 | } |
1813 | break; |
||
1814 | case FLOODFILL: |
||
1815 | /* |
||
1816 | @ floodfill x,y,color |
||
14071 | bpr | 1817 | @ alternative: <code>fill x,y,color</code> |
15111 | schaersvoo | 1818 | @ fill the region of point (x:y) with color 'color' |
11806 | schaersvoo | 1819 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
14246 | bpr | 1820 | @ use this command after all boundary objects are declared. |
14077 | bpr | 1821 | @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill. |
11806 | schaersvoo | 1822 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1823 | @ 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 | 1824 | @%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 | 1825 | */ |
1826 | for(i=0 ;i < 4 ; i++){ |
||
1827 | switch(i){ |
||
1828 | case 0:double_data[0] = get_real(infile,0);break; |
||
1829 | case 1:double_data[1] = get_real(infile,0);break; |
||
1830 | case 2:fill_color = get_color(infile,1); |
||
1831 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
15111 | schaersvoo | 1832 | js_function[DRAW_FILLTOBORDER] = 1; |
1833 | add_js_filltoborder(canvas_type); |
||
11806 | schaersvoo | 1834 | } |
1835 | decimals = find_number_of_digits(precision); |
||
1836 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
14208 | schaersvoo | 1837 | 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); |
1838 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1839 | 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 | 1840 | add_to_buffer(tmp_buffer); |
1841 | fill_cnt++; |
||
1842 | break; |
||
1843 | default:break; |
||
1844 | } |
||
1845 | } |
||
1846 | reset(); |
||
1847 | break; |
||
1848 | |||
1849 | case FONTCOLOR: |
||
1850 | /* |
||
1851 | @ fontcolor color |
||
1852 | @ color: hexcolor or colorname |
||
1853 | @ default: black |
||
15650 | reyssat | 1854 | @ use command <a href="#fontfamily">fontfamily</a> to deviate from default font type |
13956 | schaersvoo | 1855 | @%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 | 1856 | */ |
1857 | font_color = get_color(infile,1); |
||
1858 | break; |
||
1859 | |||
1860 | case FONTFAMILY: |
||
1861 | /* |
||
1862 | @ fontfamily font_description |
||
1863 | @ set the font family; for browsers that support it |
||
15313 | schaersvoo | 1864 | @ font_description: Arial, Courier, Helvetica etc |
1865 | @ 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 Arial</code>. Use correct syntax: ''font style``, ''font size pt``, ''fontfamily`` |
||
1866 | @%fontfamily%size 400,400%xrange -10,10%yrange -10,10 %fontfamily Bold 10pt Arial%string blue,-9,9,10 pt Arial%fontfamily Italic 20pt Arial%string blue,0,9,20 pt Arial%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 |
||
13959 | bpr | 1867 | |
11806 | schaersvoo | 1868 | */ |
1869 | font_family = get_string(infile,1); |
||
1870 | break; |
||
1871 | |||
1872 | case FONTSIZE: |
||
1873 | /* |
||
1874 | @ fontsize font_size |
||
1875 | @ default value 12 |
||
15111 | schaersvoo | 1876 | @ 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<br />this is however not always very straight forward... so just try and see what happens |
11806 | schaersvoo | 1877 | */ |
1878 | font_size = (int) (get_real(infile,1)); |
||
1879 | break; |
||
1880 | |||
1881 | case FUNCTION_LABEL: |
||
1882 | /* |
||
15313 | schaersvoo | 1883 | @ functionlabel label_1:label_2:label_3... |
15512 | bpr | 1884 | @ alternative: functionlabels |
15111 | schaersvoo | 1885 | @ default value ''f(x)=:g(x)=:h(x)=:i(x)=:j(x)=:k(x)=:m(x)=:n(x)=`` |
11806 | schaersvoo | 1886 | @ no mathml allowed (just ascii string) |
13956 | schaersvoo | 1887 | @ use command <a href='#fontsize'>fontsize int</a> to adjust the size |
1888 | @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed) |
||
14066 | bpr | 1889 | @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a> |
15111 | schaersvoo | 1890 | @ no limit in amount of inputfields for userbased function plotting |
15313 | schaersvoo | 1891 | @%function_label%size 400,400%xrange -5,5%yrange -5,5%precision 0%axis%axisnumbering%opacity 100,190%grid 1,1,grey,2,2,5,black%linewidth 3%linewidth 1%precision 1000%functionlabels F(x)=:H(x)=:Yield(x)=%strokecolor green%userinput function%strokecolor red%userinput function%strokecolor blue%userinput function |
11806 | schaersvoo | 1892 | */ |
15111 | schaersvoo | 1893 | temp = get_string_argument(infile,1); |
1894 | function_label = list2js_array(temp,":"); |
||
15116 | bpr | 1895 | |
11806 | schaersvoo | 1896 | break; |
1897 | |||
14078 | bpr | 1898 | case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/ |
11806 | schaersvoo | 1899 | /* |
1900 | @ grid step_x,step_y,gridcolor |
||
14177 | bpr | 1901 | @ 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 |
15313 | schaersvoo | 1902 | @ 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,Arial |
14071 | bpr | 1903 | @ 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 | 1904 | @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a> |
15313 | schaersvoo | 1905 | @ 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 Arial' ! |
1906 | @ 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 Arial') |
||
1907 | @ 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 Arial') |
||
12110 | schaersvoo | 1908 | @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red |
1909 | @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red |
||
15111 | schaersvoo | 1910 | @%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 |
1911 | @%grid_axis_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%fontfamily Italic 14px Courier%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red |
||
11806 | schaersvoo | 1912 | */ |
1913 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
||
15111 | schaersvoo | 1914 | js_function[DRAW_GRID] = 1; |
11806 | schaersvoo | 1915 | for(i=0;i<4;i++){ |
1916 | switch(i){ |
||
1917 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
1918 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
1919 | case 2: |
||
1920 | if( use_axis == TRUE ){ |
||
1921 | stroke_color = get_color(infile,0); |
||
1922 | done = FALSE; |
||
1923 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
1924 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
1925 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
1926 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
8351 | schaersvoo | 1927 | } |
1928 | else |
||
1929 | { |
||
11806 | schaersvoo | 1930 | int_data[0] = 1; |
1931 | int_data[1] = 1; |
||
1932 | stroke_color = get_color(infile,1); |
||
1933 | fill_color = stroke_color; |
||
8351 | schaersvoo | 1934 | } |
11806 | schaersvoo | 1935 | 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 !");} |
1936 | /* set snap_x snap_y values in pixels */ |
||
1937 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
||
15111 | schaersvoo | 1938 | fprintf(js_include_file,"\n/* add grid */function redraw_grid(){draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%d,%d,\"%s\",%.2f);return;};",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_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
1939 | string_length = 1 + snprintf(NULL,0, "redraw_grid();\n"); |
||
14208 | schaersvoo | 1940 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 1941 | snprintf(tmp_buffer,string_length, "redraw_grid();\n"); |
11806 | schaersvoo | 1942 | add_to_buffer(tmp_buffer); |
1943 | break; |
||
8351 | schaersvoo | 1944 | } |
1945 | } |
||
1946 | reset(); |
||
1947 | break; |
||
11806 | schaersvoo | 1948 | case GRIDFILL: |
1949 | /* |
||
1950 | @ gridfill x0,y0,dx,dy,color |
||
1951 | @ x0,y0 in xrange / yrange |
||
1952 | @ distances dx,dy in pixels |
||
13936 | bpr | 1953 | @ there is also a command <a href="#userdraw">userdraw gridfill,color</a> |
12110 | schaersvoo | 1954 | @%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 |
1955 | |||
11806 | schaersvoo | 1956 | */ |
15111 | schaersvoo | 1957 | js_function[DRAW_GRIDFILL] = 1; |
11820 | schaersvoo | 1958 | decimals = find_number_of_digits(precision); |
1959 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1960 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 1961 | add_js_filltoborder(canvas_type); |
11820 | schaersvoo | 1962 | } |
11806 | schaersvoo | 1963 | for(i=0;i<5;i++){ |
1964 | switch(i){ |
||
11820 | schaersvoo | 1965 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
1966 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
1967 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1968 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1969 | case 4: stroke_color = get_color(infile,1); |
14208 | schaersvoo | 1970 | 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); |
1971 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 1972 | 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 | 1973 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1974 | fill_cnt++; |
15111 | schaersvoo | 1975 | reset(); |
11806 | schaersvoo | 1976 | break; |
1977 | default:break; |
||
1978 | } |
||
1979 | } |
||
1980 | break; |
||
8386 | schaersvoo | 1981 | |
8244 | schaersvoo | 1982 | case HALFLINE: |
1983 | /* |
||
1984 | @ demiline x1,y1,x2,y2,color |
||
14071 | bpr | 1985 | @ alternative: <code>halfline</code> |
15111 | schaersvoo | 1986 | @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) |
9406 | schaersvoo | 1987 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 1988 | @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue |
8244 | schaersvoo | 1989 | */ |
1990 | for(i=0;i<5;i++){ |
||
1991 | switch(i){ |
||
1992 | case 0: double_data[0]= get_real(infile,0);break; /* x-values */ |
||
1993 | case 1: double_data[1]= get_real(infile,0);break; /* y-values */ |
||
1994 | case 2: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
1995 | case 3: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
1996 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
1997 | if(double_data[0] == double_data[10]){ /* vertical halfline */ |
||
1998 | if(double_data[1] < double_data[11]){ |
||
1999 | double_data[3] = ymax + 1000; |
||
2000 | } |
||
2001 | else |
||
2002 | { |
||
2003 | double_data[3] = ymin - 1000; |
||
2004 | } |
||
10953 | bpr | 2005 | double_data[2] = double_data[0]; |
8244 | schaersvoo | 2006 | } |
2007 | else |
||
2008 | { /* horizontal halfline*/ |
||
2009 | if( double_data[1] == double_data[11] ){ |
||
2010 | if( double_data[0] < double_data[10] ){ |
||
2011 | double_data[2] = xmax + 1000; /* halfline to the right */ |
||
2012 | } |
||
2013 | else |
||
2014 | { |
||
2015 | double_data[2] = xmin - 1000; /* halfline to the left */ |
||
2016 | } |
||
2017 | double_data[3] = double_data[1]; |
||
2018 | } |
||
2019 | else |
||
2020 | { |
||
2021 | /* any other halfline */ |
||
2022 | /* slope */ |
||
2023 | double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]); |
||
2024 | /* const */ |
||
2025 | double_data[13] = double_data[1] - double_data[12]*double_data[0]; |
||
2026 | if( double_data[0] < double_data[10] ){ |
||
2027 | double_data[2] = double_data[2] + 1000; |
||
2028 | } |
||
2029 | else |
||
2030 | { |
||
2031 | double_data[2] = double_data[2] - 1000; |
||
2032 | } |
||
2033 | double_data[3] = double_data[12]*double_data[2] + double_data[13]; |
||
2034 | } |
||
10953 | bpr | 2035 | } |
15111 | schaersvoo | 2036 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
2037 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
||
2038 | if(use_affine == TRUE ){ transform(4,2);} |
||
2039 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2040 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2041 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2042 | add_to_buffer(tmp_buffer); |
||
2043 | if(onclick != 0){object_cnt++;} |
||
2044 | /* object_cnt++; */ |
||
8379 | schaersvoo | 2045 | reset(); |
8244 | schaersvoo | 2046 | break; |
2047 | } |
||
2048 | } |
||
15111 | schaersvoo | 2049 | dragstuff[18] = 1; |
2050 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8244 | schaersvoo | 2051 | break; |
8386 | schaersvoo | 2052 | |
8365 | schaersvoo | 2053 | case HALFLINES: |
2054 | /* |
||
2055 | @ demilines color,x1,y1,x2,y2,.... |
||
14071 | bpr | 2056 | @ alternative: <code>halflines</code> |
15111 | schaersvoo | 2057 | @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc |
9406 | schaersvoo | 2058 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually |
12110 | schaersvoo | 2059 | @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0 |
8365 | schaersvoo | 2060 | */ |
2061 | stroke_color=get_color(infile,0); |
||
2062 | fill_color = stroke_color; |
||
2063 | i=0; |
||
2064 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2065 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8365 | schaersvoo | 2066 | if(i%2 == 0 ){ |
2067 | double_data[i] = get_real(infile,0); /* x */ |
||
2068 | } |
||
2069 | else |
||
2070 | { |
||
2071 | double_data[i] = get_real(infile,1); /* y */ |
||
2072 | } |
||
2073 | i++; |
||
2074 | } |
||
15111 | schaersvoo | 2075 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
8365 | schaersvoo | 2076 | decimals = find_number_of_digits(precision); |
2077 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
2078 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
||
2079 | if(double_data[c+1] < double_data[c+3]){ /* upright halfline */ |
||
2080 | double_data[c+3] = ymax + 1000; |
||
2081 | } |
||
2082 | else |
||
2083 | { |
||
2084 | double_data[c+3] = ymin - 1000;/* descending halfline */ |
||
2085 | } |
||
2086 | } |
||
2087 | else |
||
2088 | { |
||
2089 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
2090 | if(double_data[c] < double_data[c+2] ){ /* halfline to the right */ |
||
2091 | double_data[c+2] = xmax+100; |
||
2092 | } |
||
2093 | else |
||
2094 | { |
||
2095 | double_data[c+2] = xmin-1000; /* halfline to the right */ |
||
2096 | } |
||
2097 | } |
||
2098 | else |
||
2099 | { |
||
2100 | /* m */ |
||
2101 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
2102 | /* q */ |
||
2103 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
2104 | if(double_data[c] < double_data[c+2]){ /* to the right */ |
||
14071 | bpr | 2105 | double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */ |
8365 | schaersvoo | 2106 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
2107 | } |
||
2108 | else |
||
2109 | { /* to the left */ |
||
2110 | double_data[c+2] = xmin - 1000; |
||
2111 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
2112 | } |
||
2113 | } |
||
2114 | } |
||
15111 | schaersvoo | 2115 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
2116 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
2117 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2118 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2119 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2120 | add_to_buffer(tmp_buffer); |
||
2121 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8365 | schaersvoo | 2122 | } |
2123 | reset(); |
||
15111 | schaersvoo | 2124 | dragstuff[18] = 1; |
2125 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8365 | schaersvoo | 2126 | break; |
11806 | schaersvoo | 2127 | case HATCHFILL: |
2128 | /* |
||
2129 | @ hatchfill x0,y0,dx,dy,color |
||
2130 | @ x0,y0 in xrange / yrange |
||
2131 | @ distances dx,dy in pixels |
||
13936 | bpr | 2132 | @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a> |
12110 | schaersvoo | 2133 | @%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 | 2134 | */ |
15111 | schaersvoo | 2135 | js_function[DRAW_HATCHFILL] = 1; |
11820 | schaersvoo | 2136 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
2137 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 2138 | add_js_filltoborder(canvas_type); |
11820 | schaersvoo | 2139 | } |
2140 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 2141 | for(i=0;i<5;i++){ |
2142 | switch(i){ |
||
11820 | schaersvoo | 2143 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
2144 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
2145 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2146 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 2147 | case 4: stroke_color = get_color(infile,1); |
15111 | schaersvoo | 2148 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
2149 | if(use_affine == TRUE ){ transform(2,2);} |
||
11806 | schaersvoo | 2150 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
14208 | schaersvoo | 2151 | 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); |
2152 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 2153 | 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 | 2154 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 2155 | fill_cnt++; |
15111 | schaersvoo | 2156 | reset(); |
11806 | schaersvoo | 2157 | break; |
2158 | default:break; |
||
2159 | } |
||
2160 | } |
||
2161 | break; |
||
8386 | schaersvoo | 2162 | |
8224 | bpr | 2163 | case HLINE: |
7614 | schaersvoo | 2164 | /* |
2165 | @ hline x,y,color |
||
14071 | bpr | 2166 | @ alternative: <code>horizontalline</code> |
15111 | schaersvoo | 2167 | @ draw a horizontal line through point (x:y) in color 'color' |
2168 | @ 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 | 2169 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 2170 | @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue |
7614 | schaersvoo | 2171 | */ |
2172 | for(i=0;i<3;i++) { |
||
2173 | switch(i){ |
||
2174 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
2175 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
2176 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
2177 | double_data[3] = double_data[1]; |
||
15111 | schaersvoo | 2178 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
2179 | if(use_affine == TRUE ){ transform(2,2);} |
||
2180 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
7614 | schaersvoo | 2181 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 2182 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
2183 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2184 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2185 | add_to_buffer(tmp_buffer); |
||
2186 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
2187 | dragstuff[4] = 1; |
||
2188 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8379 | schaersvoo | 2189 | reset(); |
7614 | schaersvoo | 2190 | break; |
2191 | } |
||
2192 | } |
||
2193 | break; |
||
8366 | schaersvoo | 2194 | |
2195 | case HLINES: |
||
2196 | /* |
||
2197 | @ hlines color,x1,y1,x2,y2,... |
||
14071 | bpr | 2198 | @ alternative: <code>horizontallines</code> |
15111 | schaersvoo | 2199 | @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color' |
9406 | schaersvoo | 2200 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12110 | schaersvoo | 2201 | @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5 |
8366 | schaersvoo | 2202 | */ |
2203 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2204 | fill_color = stroke_color; |
||
2205 | i=0; |
||
2206 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2207 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8366 | schaersvoo | 2208 | if(i%2 == 0 ){ |
2209 | double_data[i] = get_real(infile,0); /* x */ |
||
2210 | } |
||
2211 | else |
||
2212 | { |
||
2213 | double_data[i] = get_real(infile,1); /* y */ |
||
2214 | } |
||
2215 | i++; |
||
2216 | } |
||
15111 | schaersvoo | 2217 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
2218 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
2219 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
2220 | |||
8366 | schaersvoo | 2221 | decimals = find_number_of_digits(precision); |
2222 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
15111 | schaersvoo | 2223 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
2224 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2225 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2226 | add_to_buffer(tmp_buffer); |
||
2227 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8366 | schaersvoo | 2228 | } |
2229 | reset(); |
||
15111 | schaersvoo | 2230 | dragstuff[4] = 1; |
2231 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8366 | schaersvoo | 2232 | break; |
11806 | schaersvoo | 2233 | case HTTP: |
7614 | schaersvoo | 2234 | /* |
11806 | schaersvoo | 2235 | @ http x1,y1,x2,y2,http://some_adress.com |
14078 | bpr | 2236 | @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2) |
11806 | schaersvoo | 2237 | @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
14071 | bpr | 2238 | @ can <b>not</b> be ''set onclick`` or ''drag xy`` |
12110 | schaersvoo | 2239 | @%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 | 2240 | */ |
15111 | schaersvoo | 2241 | js_function[DRAW_HTTP] = 1; |
11806 | schaersvoo | 2242 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 2243 | switch(i){ |
11806 | schaersvoo | 2244 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
14032 | schaersvoo | 2245 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
11806 | schaersvoo | 2246 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
2247 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
2248 | case 4: decimals = find_number_of_digits(precision); |
||
2249 | temp = get_string(infile,1); |
||
2250 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
14208 | schaersvoo | 2251 | 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 | 2252 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+2); |
2253 | 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); |
||
2254 | add_to_buffer(tmp_buffer); |
||
7614 | schaersvoo | 2255 | break; |
2256 | } |
||
2257 | } |
||
11806 | schaersvoo | 2258 | reset(); |
7614 | schaersvoo | 2259 | break; |
11806 | schaersvoo | 2260 | case HTML: |
8366 | schaersvoo | 2261 | /* |
15111 | schaersvoo | 2262 | @ html x1,y1,html_string |
14071 | bpr | 2263 | @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc. |
15111 | schaersvoo | 2264 | @ can be set <a href='#onclick'>onclick</a> and <a href='#drag'>drag&drop</a> |
2265 | @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations |
||
2266 | @ command <a href='#rotate'>rotate</a> will rotate the object |
||
14038 | schaersvoo | 2267 | @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1) |
15111 | schaersvoo | 2268 | @ note: using drag&drop for all external P,SPAN,DIV,IMG,SVG-images onto a canvasdraw element, use ''onclick=javascript:place_image_on_canvas(this.id)`` |
15629 | bpr | 2269 | @%html-text%size 500,500%xrange -10,10%yrange -10,10%drag xy%centered%fillcolor lightblue%html 2,2,<h1 style='color:red'>DRAG ME</h1> %opacity 200,50%drag xy%fcircle 0,0,100,green |
15111 | schaersvoo | 2270 | @%html-image-slider%size 500,500%xrange -10,10%yrange -10,10%fontsize 42%rotationcenter 0,0%centered%html 0,0,<img src="http://85.148.206.56/gifs/can1.gif" />%slider 0,pi,400,40,angle active degree, %centered%html 0,0,<img src="http://85.148.206.56/gifs/can2.gif" /> |
8366 | schaersvoo | 2271 | */ |
15111 | schaersvoo | 2272 | js_function[DRAW_XML] = 1; |
11806 | schaersvoo | 2273 | for(i=0;i<5;i++){ |
2274 | switch(i){ |
||
15111 | schaersvoo | 2275 | case 0: double_data[0] = get_real(infile,0);break; |
2276 | case 1: double_data[1] = get_real(infile,0);break; |
||
11806 | schaersvoo | 2277 | case 4: decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 2278 | if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */ |
2279 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
2280 | int_data[0] = x2px(double_data[0]);/* needs px */ |
||
2281 | int_data[1] = y2px(double_data[1]); |
||
2282 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
15116 | bpr | 2283 | if( use_slider != -1 && drag_type != -1){ onclick = 5; } |
11806 | schaersvoo | 2284 | temp = get_string(infile,1); |
15111 | schaersvoo | 2285 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","\\\""); } |
2286 | if( strstr(temp,"<img ")!= 0){URL="image";}else{URL="html";} |
||
2287 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'%s',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,URL,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
14208 | schaersvoo | 2288 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2289 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'%s',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,URL,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
11806 | schaersvoo | 2290 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2291 | if(onclick != 0 ){object_cnt++;} |
2292 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
11806 | schaersvoo | 2293 | break; |
2294 | default:break; |
||
8366 | schaersvoo | 2295 | } |
2296 | } |
||
15111 | schaersvoo | 2297 | reset(); |
8366 | schaersvoo | 2298 | break; |
8386 | schaersvoo | 2299 | |
11806 | schaersvoo | 2300 | case IMAGEFILL: |
7614 | schaersvoo | 2301 | /* |
11996 | schaersvoo | 2302 | @ imagefill x,y,scaling to xsize × ysize?,image_url |
11874 | schaersvoo | 2303 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
2304 | @ scaling to xsize × ysize ? ... 1 = yes 0 = no |
||
14078 | bpr | 2305 | @ After pattern filling, the fill-color should be reset ! |
14066 | bpr | 2306 | @ wims getins / image from class directory: imagefill 80,80,my_image.gif |
15111 | schaersvoo | 2307 | @ normal url: imagefill 80,80,0,$module_dir/gifs/my_image.gif |
14066 | bpr | 2308 | @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg |
11874 | schaersvoo | 2309 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
13967 | schaersvoo | 2310 | @%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 |
2311 | @%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 | 2312 | */ |
15111 | schaersvoo | 2313 | js_function[DRAW_IMAGEFILL] = 1; |
11854 | schaersvoo | 2314 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
2315 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 2316 | add_js_filltoborder(canvas_type); |
11854 | schaersvoo | 2317 | } |
11874 | schaersvoo | 2318 | for(i=0 ;i < 4 ; i++){ |
7614 | schaersvoo | 2319 | switch(i){ |
11806 | schaersvoo | 2320 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
2321 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
11874 | schaersvoo | 2322 | case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */ |
2323 | case 3: URL = get_string_argument(infile,1); |
||
14208 | schaersvoo | 2324 | 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]); |
2325 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11874 | schaersvoo | 2326 | 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 | 2327 | add_to_buffer(tmp_buffer); |
11874 | schaersvoo | 2328 | fill_cnt++; |
11806 | schaersvoo | 2329 | break; |
7614 | schaersvoo | 2330 | } |
2331 | } |
||
11806 | schaersvoo | 2332 | reset(); |
2333 | break; |
||
14066 | bpr | 2334 | |
14038 | schaersvoo | 2335 | case IMAGEPALETTE: |
2336 | /* |
||
2337 | @ imagepalette image1,image2,image3,... |
||
14379 | bpr | 2338 | @ 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``. |
15313 | schaersvoo | 2339 | @%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 Arial%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%css 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 | 2340 | */ |
2341 | temp = get_string(infile,1); |
||
2342 | temp = str_replace(temp,",","\",\""); |
||
2343 | if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");} |
||
2344 | fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp); |
||
2345 | break; |
||
14066 | bpr | 2346 | |
11806 | schaersvoo | 2347 | case INPUT: |
2348 | /* |
||
2349 | @ input x,y,size,editable,value |
||
2350 | @ to set inputfield "readonly", use editable = 0 |
||
15111 | schaersvoo | 2351 | @ if no preset 'value' is needed...use a 'space' as last item argument |
11806 | schaersvoo | 2352 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
15111 | schaersvoo | 2353 | @ 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> |
2354 | @ may be further controlled by <a href="#css">css</a> |
||
11806 | schaersvoo | 2355 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
2356 | @ 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 | 2357 | @ 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> |
2358 | @%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 | 2359 | */ |
15111 | schaersvoo | 2360 | js_function[DRAW_INPUTS] = 1; |
11806 | schaersvoo | 2361 | for(i = 0 ; i<5;i++){ |
2362 | switch(i){ |
||
2363 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
2364 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
2365 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
2366 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
15260 | schaersvoo | 2367 | case 4: temp = get_string(infile,3); |
15111 | schaersvoo | 2368 | string_length = 1 + snprintf(NULL,0, "draw_static_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],css_class,temp,use_offset); |
14208 | schaersvoo | 2369 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2370 | snprintf(tmp_buffer,string_length,"draw_static_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],css_class,temp,use_offset); |
11806 | schaersvoo | 2371 | add_to_buffer(tmp_buffer); |
2372 | input_cnt++;break; |
||
2373 | default: break; |
||
2374 | } |
||
2375 | } |
||
2376 | if(reply_format == 0 ){reply_format = 15;} |
||
2377 | reset(); |
||
2378 | break; |
||
8386 | schaersvoo | 2379 | |
11806 | schaersvoo | 2380 | case INTOOLTIP: |
2381 | /* |
||
2382 | @ intooltip link_text |
||
2383 | @ link_text is a single line (span-element) |
||
15111 | schaersvoo | 2384 | @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''$module_dir/gifs/my_image.jpg`` |
11806 | schaersvoo | 2385 | @ link_text may contain HTML markup |
14071 | bpr | 2386 | @ the canvas will be displayed in a tooltip on ''link_text`` |
15111 | schaersvoo | 2387 | @ 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 | 2388 | @ 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 | 2389 | @%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 | 2390 | */ |
2391 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");} |
||
2392 | if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");} |
||
2393 | tooltip_text = get_string(infile,1); |
||
2394 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
2395 | use_tooltip = 1; |
||
2396 | break; |
||
2397 | |||
2398 | case JSCURVE: |
||
7614 | schaersvoo | 2399 | /* |
11893 | schaersvoo | 2400 | @ jscurve color,formula1(x),formula2(x),formula3(x),... |
14071 | bpr | 2401 | @ alternative: <code>jsplot color,formula(x)</code> |
15111 | schaersvoo | 2402 | @ alternative: <code>userdraw function,color</code> |
11893 | schaersvoo | 2403 | @ your function will be plotted by the javascript engine of the client browser |
2404 | @ 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 | 2405 | @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code> |
2406 | @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...) |
||
2407 | @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot ! |
||
11806 | schaersvoo | 2408 | @ no validity check is done by wims. |
15111 | schaersvoo | 2409 | @ 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 | 2410 | @ 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 |
15116 | bpr | 2411 | @ zooming & panning in case of userbased functionplot: reclick the OK button to re-plot curve onto the resized grid |
11893 | schaersvoo | 2412 | @ use keyword <a href='animate'>animate</a> for animating a point on the curve |
14071 | bpr | 2413 | @ use command ''trace_jscurve formula(x)`` for tracing |
14246 | bpr | 2414 | @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve |
11806 | schaersvoo | 2415 | @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet) |
14071 | bpr | 2416 | @ commands plotjump / plotstep are not active for ''jscurve`` |
11806 | schaersvoo | 2417 | @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve. |
14071 | bpr | 2418 | @ 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 | 2419 | @%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 | 2420 | */ |
15111 | schaersvoo | 2421 | jsplot_cnt++;/* -1 --> 0 */ |
11806 | schaersvoo | 2422 | stroke_color = get_color(infile,0); |
15111 | schaersvoo | 2423 | js_function[JS_MATH] = 1; |
2424 | js_function[JS_PLOT] = 1; |
||
2425 | if( tmin != 0 && tmax !=0){use_parametric = TRUE;} |
||
11806 | schaersvoo | 2426 | temp = get_string(infile,1); |
2427 | temp = str_replace(temp,",","\",\""); |
||
15111 | schaersvoo | 2428 | string_length = 1 + snprintf(NULL,0, "var js_plot%d = function(){jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d,0);};js_plot%d();",jsplot_cnt,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,jsplot_cnt); |
14208 | schaersvoo | 2429 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2430 | snprintf(tmp_buffer,string_length, "var js_plot%d = function(){jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d,0);};js_plot%d();",jsplot_cnt,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,jsplot_cnt); |
11806 | schaersvoo | 2431 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2432 | fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;",jsplot_cnt); |
2433 | |||
11806 | schaersvoo | 2434 | /* we need to create multiple canvasses, so we may zoom and pan ?? */ |
2435 | break; |
||
2436 | |||
2437 | case JSMATH: |
||
2438 | /* |
||
2439 | @ jsmath some_math_function |
||
2440 | @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates. |
||
14246 | bpr | 2441 | @ 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 |
15111 | schaersvoo | 2442 | @ use command 'css some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y`` |
14066 | bpr | 2443 | @ 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 | 2444 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
12111 | schaersvoo | 2445 | @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2) |
11806 | schaersvoo | 2446 | */ |
15111 | schaersvoo | 2447 | js_function[DRAW_CROSSHAIRS] = 1; |
2448 | js_function[JS_MATH] = 1; |
||
2449 | add_calc_y(get_string(infile,1),font_size,css_class); |
||
2450 | break; |
||
2451 | |||
2452 | case KATEX: |
||
2453 | /* |
||
2454 | katex x,y,latex string |
||
2455 | for use on KaTeX enabled wims distributions. see <a href="http://85.148.206.56/wims/download/katex.for.wims.tar.gz">howto wims & katex [1.3MB] </a> |
||
2456 | on MathML / MathJaX enabled -default- wims, use command <a href="#latex">latex</a> ! |
||
15633 | bpr | 2457 | transformation commands <a href='#affine'>affine</a>, <a href='#translation'>translation</a> and <a href='#rotate'>rotate</a> are supported.(onclick and drag will work) |
15111 | schaersvoo | 2458 | can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br />if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
2459 | 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... |
||
2460 | can be moved/rotated with command <a href='#slider'>slider</a> |
||
2461 | snaptogrid is supported... |
||
2462 | when clicked, the colour of the 'div background' of the 'mathobject' will be determined by the <a href="#fillcolor">fillcolor</a> and <a href="#opacity">opacity</a> settings |
||
2463 | userdraw may be combined with 'katex' ; the js-function 'read_canvas()' will contain the coordinates of the drawing. |
||
2464 | draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> and all objects from commands <a href='#html'>html</a> or <a href='#obabel'>obabel</a> can be combined with drag and/or onclick mathml |
||
2465 | other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
||
2466 | 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();" |
||
2467 | 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.... |
||
2468 | use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1) |
||
15116 | bpr | 2469 | note: if you want to include external TeX via drag&drop onto a canvasdraw element, use \\mmlid{integer} in the tex-command:''!insmath \\mmlid{1}\\frac{1}{\pi}`` <br />(if your wims_mathml does not support it...use <a href="http://85.148.206.56/wims/download/Mathml.tar.gz">this version...</a>) |
15111 | schaersvoo | 2470 | note: the same is true for all external P,SPAN,DIV,IMG,SVG-images via drag&drop onto a canvasdraw element, use ''onclick=javascript:place_image_on_canvas(this.id)`` |
2471 | |||
2472 | */ |
||
2473 | js_function[DRAW_XML] = 1; |
||
2474 | for(i=0;i<3;i++){ |
||
2475 | switch(i){ |
||
2476 | case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */ |
||
2477 | case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system -> pixel height */ |
||
2478 | case 2: decimals = find_number_of_digits(precision); |
||
2479 | temp = get_string(infile,1); |
||
2480 | if(use_affine == TRUE ){ transform(2,2);}/* slider will use css-rotate transformation */ |
||
2481 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
2482 | int_data[0] = x2px(double_data[0]); |
||
2483 | int_data[1] = y2px(double_data[1]); |
||
2484 | if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */ |
||
15116 | bpr | 2485 | if( use_slider != -1 && drag_type != -1){ onclick = 5; } |
15111 | schaersvoo | 2486 | if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); } |
2487 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'katex',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
2488 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2489 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'katex',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
2490 | add_to_buffer(tmp_buffer); |
||
2491 | if(onclick != 0 ){object_cnt++;} |
||
2492 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
2493 | break; |
||
2494 | default:break; |
||
2495 | } |
||
11806 | schaersvoo | 2496 | } |
15111 | schaersvoo | 2497 | reset(); |
11806 | schaersvoo | 2498 | break; |
2499 | case KILLAFFINE: |
||
2500 | /* |
||
2501 | @ killaffine |
||
14066 | bpr | 2502 | @ keyword: resets the transformation matrix to 1,0,0,1,0,0 |
15633 | bpr | 2503 | @ note: any active linear transformation will also be reset: tx=0, ty=0 |
11806 | schaersvoo | 2504 | */ |
15111 | schaersvoo | 2505 | use_affine = FALSE; |
2506 | affine_matrix[0] = 1.0; |
||
2507 | affine_matrix[1] = 0.0; |
||
2508 | affine_matrix[2] = 0.0; |
||
2509 | affine_matrix[3] = 1.0; |
||
2510 | affine_matrix[4] = 0.0; |
||
2511 | affine_matrix[5] = 0.0; |
||
11806 | schaersvoo | 2512 | break; |
15111 | schaersvoo | 2513 | case KILLLINEAR: |
2514 | /* |
||
2515 | @ killlinear |
||
2516 | @ keyword: resets the transformation matrix to 1,0,0,1,tx,ty |
||
2517 | @ note:any active transformation or rotation will not be killed (tx,ty remain active) |
||
2518 | */ |
||
2519 | affine_matrix[0] = 1.0; |
||
2520 | affine_matrix[1] = 0.0; |
||
2521 | affine_matrix[2] = 0.0; |
||
2522 | affine_matrix[3] = 1.0; |
||
2523 | break; |
||
11806 | schaersvoo | 2524 | |
15111 | schaersvoo | 2525 | |
11806 | schaersvoo | 2526 | case KILLROTATE: |
2527 | /* |
||
14071 | bpr | 2528 | @ killrotate |
15111 | schaersvoo | 2529 | @ will set the rotation angle to 0. |
2530 | @ will also reset the command <a href="#rotationcenter">rotationcenter</a> to the first (x;y) of the next rotatable/slidable object(s) <br/>eg a following rotate command will have the first object point as rotation center |
||
11806 | schaersvoo | 2531 | @ if not set, the rotation center will remain unchanged |
15111 | schaersvoo | 2532 | @ note:any active transformation or linear will not be killed (e.g an active transformation matrix remains active) |
15116 | bpr | 2533 | @%killrotate%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%rotationcenter 0,0%# slider is active for all following objects until 'killslider'%slider -10,10,300,40,angle degree,Rotate%drag xy%# after dragging the object must be clicked to re-activate the slider%linewidth 4%arrow 0,0,6,0,9,blue%%# reset rotation center to the first (x,y) of the next object/arrow...%killrotate%drag xy%# after dragging the object must be clicked to re-activate the slider%arrow 0,0,6,1,9,red |
11806 | schaersvoo | 2534 | */ |
15111 | schaersvoo | 2535 | use_rotate = FALSE; |
14549 | schaersvoo | 2536 | angle = 0.0; |
15111 | schaersvoo | 2537 | rotation_center="null"; |
11806 | schaersvoo | 2538 | break; |
2539 | |||
2540 | case KILLSLIDER: |
||
2541 | /* |
||
2542 | @ killslider |
||
2543 | @ keyword (no arguments required) |
||
2544 | @ ends grouping of object under a previously defined slider |
||
2545 | */ |
||
14208 | schaersvoo | 2546 | slider_type = "0"; |
15111 | schaersvoo | 2547 | my_sliders = "[-1]"; |
2548 | last_slider = use_slider+1; |
||
11806 | schaersvoo | 2549 | break; |
2550 | |||
2551 | case KILLTRANSLATION: |
||
2552 | /* |
||
15116 | bpr | 2553 | @ killtranslation |
14071 | bpr | 2554 | @ alternative: <code>killtranslate</code> |
15111 | schaersvoo | 2555 | @ note: a active linear or affine transformation will not be 100% reset...only tx=0,ty=0 |
2556 | @ resets the translation matrix a,b,c,d,tx,ty to a,b,c,d,0,0 |
||
11806 | schaersvoo | 2557 | */ |
15111 | schaersvoo | 2558 | affine_matrix[4] = 0.0; |
2559 | affine_matrix[5] = 0.0; |
||
11806 | schaersvoo | 2560 | break; |
14225 | schaersvoo | 2561 | case LATEX: |
2562 | /* |
||
15111 | schaersvoo | 2563 | @ latex x,y,tex string |
2564 | @ alternative:math x,y,tex string |
||
2565 | @ you may also use command <a href="#mathml">mathml</a> for xml strings generated with wims commmand ''mathmlmath`` (will not work on KaTeX enabled WIMS) |
||
15633 | bpr | 2566 | @ transformation commands <a href='#affine'>affine</a>, <a href='#translation'>translation</a> and <a href='#rotate'>rotate</a> are supported.(onclick and drag will work) |
15111 | schaersvoo | 2567 | @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br />if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
2568 | @ 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... |
||
2569 | @ can be moved/rotated with command <a href='#slider'>slider</a> |
||
2570 | @ snaptogrid is supported |
||
2571 | @ when clicked, the colour of the 'div background' of the 'mathobject' will be determined by the <a href="#fillcolor">fillcolor</a> and <a href="#opacity">opacity</a> settings |
||
2572 | @ userdraw may be combined with 'latex' ; the js-function 'read_canvas()' will contain the coordinates of the drawing. |
||
2573 | @ userdraw may be combined; the read_canvas() will contain the drawing. |
||
2574 | @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> and all objects from commands <a href='#html'>html</a> or <a href='#obabel'>obabel</a> can be combined with drag and/or onclick mathml |
||
14230 | schaersvoo | 2575 | @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
14379 | bpr | 2576 | @ 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();" |
2577 | @ 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.... |
||
15116 | bpr | 2578 | @ use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1) <br />this may not work as expected for MathJaX [TO BE TESTED] |
15274 | bpr | 2579 | @ note: if you want to include external TeX via drag&drop onto a canvasdraw element, use \\mmlid{integer} in the tex-command:''!insmath \\mmlid{1}\\frac{1}{\pi}``<br /> (if your wims_mathml does not support it...use <a href="http://85.148.206.56/wims/download/Mathml.tar.gz">this version...</a>) |
15111 | schaersvoo | 2580 | @ note: the same is true for all external P,SPAN,DIV,IMG,SVG-images via drag&drop onto a canvasdraw element, use ''onclick=javascript:place_image_on_canvas(this.id)`` |
2581 | @%latex_drag%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%strokecolor red%drag xy%centered%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%drag xy%centered%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%drag xy%centered%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%drag xy%fontfamily 26px Times%centered%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6} |
||
15313 | schaersvoo | 2582 | @%latex%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%vline 0,0,green%hline 0,0,green%fontfamily 16px Arial%fillcolor orange%strokecolor blue%linewidth 2%slider 0,4*pi,400,40,angle degree active, %centered%latex 0,0,\\frac{12345}{23456} \\times \\frac{12345}{23456}%translate 4,4%centered%rotate 180%drag xy%html 0,0,<table><tr><th>HTML TABLE</th></tr><tr><th><a href="https://wimsedu.info/">WIMS EDU </a> </th></tr><tr><td><img src="gifs/en.gif" /></tr><tr><td><img src="gifs/nl.gif" /></tr><tr><td><img src="gifs/fr.gif" /></tr><tr><td><img src="gifs/cn.gif" /></tr><tr><td><img src="gifs/it.gif" /></tr></table>%userdraw arrow2,red |
14225 | schaersvoo | 2583 | */ |
15111 | schaersvoo | 2584 | js_function[DRAW_XML] = 1; |
14225 | schaersvoo | 2585 | for(i=0;i<4;i++){ |
2586 | switch(i){ |
||
15111 | schaersvoo | 2587 | case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */ |
2588 | case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system -> pixel height */ |
||
14225 | schaersvoo | 2589 | case 2: decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 2590 | if(use_affine == TRUE ){ transform(2,2);} |
2591 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
2592 | int_data[0] = x2px(double_data[0]); |
||
2593 | int_data[1] = y2px(double_data[1]); |
||
2594 | if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */ |
||
15116 | bpr | 2595 | if( use_slider != -1 && drag_type != -1){ onclick = 5; } |
15111 | schaersvoo | 2596 | temp = get_string(infile,1); |
2597 | temp = getMML(temp);/* generate MathML for Firefox or MathJaX */ |
||
2598 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
2599 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
2600 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2601 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
2602 | add_to_buffer(tmp_buffer); |
||
2603 | if(onclick != 0 ){object_cnt++;} |
||
2604 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
2605 | break; |
||
14225 | schaersvoo | 2606 | default:break; |
2607 | } |
||
2608 | } |
||
15111 | schaersvoo | 2609 | reset(); |
14225 | schaersvoo | 2610 | break; |
14230 | schaersvoo | 2611 | case LATTICE: |
2612 | /* |
||
2613 | @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
2614 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` |
||
2615 | @%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 |
||
2616 | */ |
||
15111 | schaersvoo | 2617 | js_function[DRAW_LATTICE] = 1; |
14230 | schaersvoo | 2618 | for( i = 0; i<9; i++){ |
2619 | switch(i){ |
||
2620 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
||
2621 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
2622 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
2623 | case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values -> y-pixels*/ |
||
2624 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
||
2625 | case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values -> y-pixels*/ |
||
2626 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
||
2627 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
2628 | case 8: stroke_color=get_color(infile,1); |
||
2629 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 2630 | 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); ",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_filled); |
14230 | schaersvoo | 2631 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2632 | snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%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_filled); |
14230 | schaersvoo | 2633 | add_to_buffer(tmp_buffer);break; |
2634 | default:break; |
||
2635 | } |
||
2636 | } |
||
2637 | reset(); |
||
2638 | break; |
||
15111 | schaersvoo | 2639 | case LINEAR: |
2640 | /* |
||
2641 | @ linear a,b,c,d |
||
2642 | @ defines a transformation matrix for subsequent objects |
||
2643 | @ use keyword <a href='#killlinear'>killlinear</a> to end the transformation...the next objects will be drawn in the original x/y-range |
||
2644 | @ a: Scales the drawings horizontally |
||
2645 | @ b: Skews the drawings horizontally |
||
2646 | @ c: Skews the drawings vertically |
||
2647 | @ d: Scales the drawings vertically |
||
2648 | @ the data precision may be set by preceding command ''precision int`` |
||
2649 | @ note: any active translation (tx,ty) is not changed |
||
15309 | schaersvoo | 2650 | @%linear%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%fcircle 5,5,40,blue%linear 0.2,0,0,0.2%fcircle 5,5,40,green |
15111 | schaersvoo | 2651 | */ |
2652 | for(i = 0 ; i<4;i++){ |
||
2653 | switch(i){ |
||
2654 | case 0: affine_matrix[0] = get_real(infile,0);break; |
||
2655 | case 1: affine_matrix[1] = get_real(infile,0);break; |
||
2656 | case 2: affine_matrix[2] = get_real(infile,0);break; |
||
2657 | case 3: affine_matrix[3] = get_real(infile,1); |
||
2658 | affine_matrix[4] = 0;affine_matrix[5] = 0; |
||
2659 | use_affine = TRUE; |
||
2660 | break; |
||
2661 | default: break; |
||
2662 | } |
||
2663 | } |
||
2664 | reset(); |
||
2665 | break; |
||
14230 | schaersvoo | 2666 | |
11806 | schaersvoo | 2667 | case LINE: |
2668 | /* |
||
2669 | @ line x1,y1,x2,y2,color |
||
14379 | bpr | 2670 | @ draw a line through points (x1:y1)--(x2:y2) in color ''color`` |
15111 | schaersvoo | 2671 | @ or use command ''curve color,formula`` to draw the line (uses more points to draw the line; is however better draggable) |
9406 | schaersvoo | 2672 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 2673 | @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green |
7614 | schaersvoo | 2674 | */ |
8386 | schaersvoo | 2675 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 2676 | switch(i){ |
11806 | schaersvoo | 2677 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
2678 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
2679 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
2680 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
2681 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
2682 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
2683 | double_data[1] = xmin; |
||
2684 | double_data[3] = ymax; |
||
2685 | double_data[0] = double_data[10]; |
||
2686 | double_data[2] = double_data[10]; |
||
2687 | } |
||
2688 | else |
||
2689 | { |
||
2690 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
2691 | double_data[1] = double_data[11]; |
||
2692 | double_data[3] = double_data[11]; |
||
2693 | double_data[0] = ymin; |
||
2694 | double_data[2] = xmax; |
||
2695 | } |
||
2696 | else |
||
2697 | { |
||
2698 | /* m */ |
||
2699 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
2700 | /* q */ |
||
2701 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
2702 | |||
2703 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2704 | |||
2705 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
||
2706 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
2707 | double_data[0] = xmin; |
||
2708 | double_data[2] = xmax; |
||
2709 | } |
||
2710 | } |
||
15111 | schaersvoo | 2711 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
2712 | if(use_affine == TRUE ){ transform(4,2);} |
||
2713 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
2714 | |||
11806 | schaersvoo | 2715 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 2716 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
2717 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2718 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2719 | add_to_buffer(tmp_buffer); |
||
2720 | if(onclick != 0){object_cnt++;} |
||
2721 | /* object_cnt++;*/ |
||
11806 | schaersvoo | 2722 | reset(); |
2723 | break; |
||
7614 | schaersvoo | 2724 | } |
2725 | } |
||
15111 | schaersvoo | 2726 | dragstuff[4] = 1; |
2727 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 2728 | break; |
8386 | schaersvoo | 2729 | |
11806 | schaersvoo | 2730 | case LINES: |
8370 | schaersvoo | 2731 | /* |
11806 | schaersvoo | 2732 | @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n |
15111 | schaersvoo | 2733 | @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color' |
2734 | @ or use multiple commands ''curve color,formula`` or ''jscurve color,formule`` to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
11806 | schaersvoo | 2735 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 2736 | @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a> |
12107 | schaersvoo | 2737 | @%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 | 2738 | */ |
2739 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2740 | fill_color = stroke_color; |
||
2741 | i=0; |
||
2742 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2743 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8370 | schaersvoo | 2744 | if(i%2 == 0 ){ |
2745 | double_data[i] = get_real(infile,0); /* x */ |
||
2746 | } |
||
2747 | else |
||
2748 | { |
||
2749 | double_data[i] = get_real(infile,1); /* y */ |
||
2750 | } |
||
2751 | i++; |
||
2752 | } |
||
2753 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 2754 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
8370 | schaersvoo | 2755 | for(c = 0 ; c < i-1 ; c = c+4){ |
11806 | schaersvoo | 2756 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
2757 | double_data[c+1] = xmin; |
||
2758 | double_data[c+3] = ymax; |
||
2759 | double_data[c+2] = double_data[c]; |
||
2760 | } |
||
2761 | else |
||
2762 | { |
||
2763 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
2764 | double_data[c+3] = double_data[c+1]; |
||
2765 | double_data[c] = ymin; |
||
2766 | double_data[c+2] = xmax; |
||
2767 | } |
||
2768 | else |
||
2769 | { |
||
2770 | /* m */ |
||
2771 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
2772 | /* q */ |
||
2773 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
2774 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2775 | double_data[c+1] = (m)*(xmin)+(q); |
||
2776 | double_data[c+3] = (m)*(xmax)+(q); |
||
2777 | double_data[c] = xmin; |
||
2778 | double_data[c+2] = xmax; |
||
2779 | } |
||
2780 | } |
||
15111 | schaersvoo | 2781 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
2782 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
2783 | |||
2784 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2785 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2786 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2787 | add_to_buffer(tmp_buffer); |
||
2788 | if(onclick != 0){object_cnt++;} |
||
2789 | /* object_cnt++; */ |
||
8370 | schaersvoo | 2790 | } |
15111 | schaersvoo | 2791 | dragstuff[4] = 1; |
2792 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8370 | schaersvoo | 2793 | reset(); |
2794 | break; |
||
8386 | schaersvoo | 2795 | |
11806 | schaersvoo | 2796 | |
2797 | case LINEWIDTH: |
||
7614 | schaersvoo | 2798 | /* |
11806 | schaersvoo | 2799 | @ linewidth int |
2800 | @ default 1 |
||
12107 | schaersvoo | 2801 | @%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 | 2802 | */ |
11806 | schaersvoo | 2803 | line_width = (int) (get_real(infile,1)); |
2804 | break; |
||
2805 | |||
2806 | case LEVELCURVE: |
||
8363 | schaersvoo | 2807 | /* |
11806 | schaersvoo | 2808 | @ levelcurve color,expression in x/y,l1,l2,... |
15111 | schaersvoo | 2809 | @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n |
2810 | @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...) |
||
2811 | @ every individual level curve may be set 'onclick / drag xy' <br />e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier |
||
2812 | @ note: the arrays for holding the javascript data are limited in size |
||
2813 | @ note: reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...) |
||
12107 | schaersvoo | 2814 | @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4 |
8363 | schaersvoo | 2815 | */ |
11806 | schaersvoo | 2816 | fill_color = get_color(infile,0); |
2817 | char *fun1 = get_string_argument(infile,0); |
||
2818 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
2819 | i = 0; |
||
2820 | done = FALSE; |
||
2821 | while( !done ){ |
||
2822 | double_data[i] = get_real(infile,1); |
||
2823 | i++; |
||
2824 | } |
||
15111 | schaersvoo | 2825 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
2826 | |||
11806 | schaersvoo | 2827 | for(c = 0 ; c < i; c++){ |
15111 | schaersvoo | 2828 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
2829 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2830 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
2831 | add_to_buffer(tmp_buffer); |
||
2832 | if(onclick != 0){object_cnt++;} |
||
2833 | /* object_cnt++; */ |
||
11806 | schaersvoo | 2834 | } |
15111 | schaersvoo | 2835 | dragstuff[16] = 1; |
2836 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 2837 | reset(); |
2838 | break; |
||
8386 | schaersvoo | 2839 | |
11806 | schaersvoo | 2840 | case LEGEND: |
2841 | /* |
||
2842 | @ legend string1:string2:string3....string_n |
||
2843 | @ will be used to create a legend for a graph |
||
14066 | bpr | 2844 | @ also see command <a href='#piechart'>piechart</a> |
14071 | bpr | 2845 | @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default |
15111 | schaersvoo | 2846 | @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``) |
14066 | bpr | 2847 | @%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 | 2848 | */ |
2849 | temp = get_string(infile,1); |
||
2850 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
14066 | bpr | 2851 | legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */ |
11806 | schaersvoo | 2852 | fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp); |
2853 | break; |
||
2854 | |||
2855 | case LEGENDCOLORS: |
||
2856 | /* |
||
2857 | @ legendcolors color1:color2:color3:...:color_n |
||
14379 | bpr | 2858 | @ 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>. |
2859 | @ make sure the number of colors match the number of legend items |
||
15111 | schaersvoo | 2860 | @ command ''legend`` in case of ''piechart`` and ''barchart`` will use these colours per default (no need to specify ''legendcolors``) |
13960 | bpr | 2861 | @%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 | 2862 | */ |
2863 | if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");} |
||
2864 | temp = get_string(infile,1); |
||
2865 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2866 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp); |
||
2867 | break; |
||
2868 | |||
14078 | bpr | 2869 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
11806 | schaersvoo | 2870 | /* |
2871 | @ linegraph x1:y1:x2:y2...x_n:y_n |
||
2872 | @ will plot your data in a graph |
||
14066 | bpr | 2873 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
2874 | @ 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> |
||
2875 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
2876 | @ also see command <a href='#piechart'>piechart</a> |
||
11806 | schaersvoo | 2877 | @ multiple linegraphs may be used in a single plot |
14066 | bpr | 2878 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
14379 | bpr | 2879 | @ <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 | 2880 | @%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 | 2881 | */ |
2882 | temp = get_string(infile,1); |
||
2883 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2884 | 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); |
||
2885 | linegraph_cnt++; |
||
2886 | reset(); |
||
2887 | break; |
||
2888 | |||
2889 | case MATHML: |
||
2890 | /* |
||
15111 | schaersvoo | 2891 | @ mathml x1,y1,mathml_string |
14230 | schaersvoo | 2892 | @ this command is special for GECKO browsers, and it makes use of Native Mathml |
15313 | schaersvoo | 2893 | @ For general use with all browsers, use command <a href='#latex'>latex</a> |
2894 | @ can be set <a href='onclick'>onclick</a> and <a href='drag'>drag&drop</a> <br />Note: dragging is fairly primitive dragging of the div-element, and is not done using the <em>dragstuff library</em> |
||
15111 | schaersvoo | 2895 | @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations |
2896 | @ command <a href='#rotate'>rotate</a> will rotate the object |
||
15315 | bpr | 2897 | @ the mathml object is centered at (x1:y1) |
14379 | bpr | 2898 | @ the ''mathml_string`` can be produced using WIMS commands like ''texmath`` followed by ''mathmlmath``... or write correct TeX and use only ''mathmlmath`` |
15313 | schaersvoo | 2899 | @ mathml will be displayed in a rectangle left top (x1:y1) |
14247 | bpr | 2900 | @ 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 | 2901 | @ 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 | 2902 | @ 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. |
2903 | @ 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. |
||
15111 | schaersvoo | 2904 | @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing. |
2905 | @ 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 | 2906 | @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
14066 | bpr | 2907 | @ 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 | 2908 | @ 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 | 2909 | @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1) |
15313 | schaersvoo | 2910 | @%mathml_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%strokecolor red%mathml -5,5,<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,<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> |
2911 | @%mathml_drag%size 400,400%xrange -10,10%yrange -10,10%drag xy%strokecolor red%mathml -5,5,<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,<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 | 2912 | */ |
15111 | schaersvoo | 2913 | js_function[DRAW_XML] = 1; |
2914 | for(i=0;i<3;i++){ |
||
11806 | schaersvoo | 2915 | switch(i){ |
15111 | schaersvoo | 2916 | case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */ |
2917 | case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system -> pixel height */ |
||
2918 | case 2: decimals = find_number_of_digits(precision); |
||
2919 | |||
2920 | if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */ |
||
2921 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
2922 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
2923 | int_data[0] = x2px(double_data[0]);/* needs px */ |
||
2924 | int_data[1] = y2px(double_data[1]); |
||
2925 | if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */ |
||
15116 | bpr | 2926 | if( use_slider != -1 && drag_type != -1){ onclick = 5; } |
11806 | schaersvoo | 2927 | temp = get_string(infile,1); |
2928 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
15111 | schaersvoo | 2929 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%d,rotation_center:%s,once:true};draw_xml(draw_xml%d);slidergroup[%d] = null;\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,use_slider,rotation_center,drawxml_cnt,object_cnt); |
14208 | schaersvoo | 2930 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2931 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%d,rotation_center:%s,once:true};draw_xml(draw_xml%d);slidergroup[%d] = null;\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,use_slider,rotation_center,drawxml_cnt,object_cnt); |
11806 | schaersvoo | 2932 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2933 | if(onclick != 0 ){object_cnt++;} |
2934 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
11806 | schaersvoo | 2935 | /* |
15111 | schaersvoo | 2936 | in case inputs are present, trigger adding the read_mathml() |
2937 | if no other reply_format is defined |
||
2938 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
2939 | */ |
||
2940 | if(strstr(temp,"mathml0") != NULL){ if(reply_format == 0 ){reply_format = 16;}} /* no other reply type is defined */ |
||
11806 | schaersvoo | 2941 | break; |
15116 | bpr | 2942 | default:break; |
11806 | schaersvoo | 2943 | } |
2944 | } |
||
15111 | schaersvoo | 2945 | reset(); |
11806 | schaersvoo | 2946 | break; |
2947 | |||
2948 | case MOUSE: |
||
2949 | /* |
||
2950 | @ mouse color,fontsize |
||
15313 | schaersvoo | 2951 | @ will display the cursor (x:y) coordinates in ''color`` and ''fontsize`` using default fontfamily Arial |
14379 | bpr | 2952 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``) |
12107 | schaersvoo | 2953 | @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22 |
11806 | schaersvoo | 2954 | */ |
2955 | stroke_color = get_color(infile,0); |
||
2956 | font_size = (int) (get_real(infile,1)); |
||
2957 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2958 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2959 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,2); |
2960 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 2961 | break; |
2962 | |||
2963 | |||
2964 | case MOUSE_DEGREE: |
||
2965 | /* |
||
2966 | @ mouse_degree color,fontsize |
||
15313 | schaersvoo | 2967 | @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using a fontfamily Arial |
11806 | schaersvoo | 2968 | @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV |
15111 | schaersvoo | 2969 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
12107 | schaersvoo | 2970 | @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22 |
11806 | schaersvoo | 2971 | */ |
2972 | stroke_color = get_color(infile,0); |
||
2973 | font_size = (int) (get_real(infile,1)); |
||
2974 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2975 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2976 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,3); |
11806 | schaersvoo | 2977 | js_function[JS_FIND_ANGLE] = 1; |
15111 | schaersvoo | 2978 | js_function[INTERACTIVE] = 1; |
11806 | schaersvoo | 2979 | break; |
2980 | case MOUSE_DISPLAY: |
||
2981 | /* |
||
2982 | @ display TYPE,color,fontsize |
||
15111 | schaersvoo | 2983 | @ TYPE may be x | y | xy | degree | radian | radius |
2984 | @ will display the mouse cursor coordinates as x-only,y-only,(x:y), the radius of a circle (this only in case 'userdraw circle(s),color') or the angle in degrees or radians for commands <code>userdraw arc,color</code> or protractor, ruler (if set dynamic). |
||
15650 | reyssat | 2985 | @ 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 | 2986 | @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name |
12111 | schaersvoo | 2987 | @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22 |
12107 | schaersvoo | 2988 | @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22 |
13936 | bpr | 2989 | @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue |
12107 | schaersvoo | 2990 | @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue |
2991 | @%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 | 2992 | @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue |
11806 | schaersvoo | 2993 | */ |
2994 | temp = get_string_argument(infile,0); |
||
2995 | if( strstr(temp,"xy") != NULL ){ |
||
2996 | int_data[0] = 2; |
||
2997 | }else{ |
||
2998 | if( strstr(temp,"y") != NULL ){ |
||
2999 | int_data[0] = 1; |
||
3000 | }else{ |
||
3001 | if( strstr(temp,"x") != NULL ){ |
||
3002 | int_data[0] = 0; |
||
3003 | }else{ |
||
3004 | if(strstr(temp,"degree") != NULL){ |
||
3005 | int_data[0] = 3; |
||
3006 | js_function[JS_FIND_ANGLE] = 1; |
||
3007 | }else{ |
||
3008 | if(strstr(temp,"radian") != NULL){ |
||
3009 | int_data[0] = 4; |
||
3010 | js_function[JS_FIND_ANGLE] = 1; |
||
3011 | }else{ |
||
3012 | if(strstr(temp,"radius") != NULL){ |
||
3013 | int_data[0] = 5; |
||
3014 | }else{ |
||
3015 | int_data[0] = 2; |
||
3016 | } |
||
3017 | } |
||
3018 | } |
||
3019 | } |
||
3020 | } |
||
3021 | } |
||
3022 | stroke_color = get_color(infile,0); |
||
3023 | font_size = (int) (get_real(infile,1)); |
||
3024 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 3025 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 3026 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,int_data[0]); |
3027 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3028 | break; |
3029 | |||
3030 | case MOUSE_PRECISION: |
||
3031 | /* |
||
3032 | @ precision int |
||
3033 | @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc |
||
3034 | @ may be used / changed before every object |
||
15111 | schaersvoo | 3035 | @ 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 | 3036 | @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red |
11806 | schaersvoo | 3037 | */ |
3038 | precision = (int) (get_real(infile,1)); |
||
3039 | if(precision < 1 ){precision = 1;}; |
||
3040 | break; |
||
3041 | |||
3042 | case MOUSEX: |
||
3043 | /* |
||
3044 | @ mousex color,fontsize |
||
15313 | schaersvoo | 3045 | @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Arial. |
14247 | bpr | 3046 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``). |
11806 | schaersvoo | 3047 | |
3048 | */ |
||
3049 | stroke_color = get_color(infile,0); |
||
3050 | font_size = (int) (get_real(infile,1)); |
||
3051 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 3052 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 3053 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,0); |
3054 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3055 | break; |
3056 | case MOUSEY: |
||
3057 | /* |
||
3058 | @ mousey color,fontsize |
||
15313 | schaersvoo | 3059 | @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Arial. |
14247 | bpr | 3060 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``). |
11806 | schaersvoo | 3061 | |
3062 | */ |
||
3063 | stroke_color = get_color(infile,0); |
||
3064 | font_size = (int) (get_real(infile,1)); |
||
3065 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 3066 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 3067 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,1); |
3068 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3069 | break; |
3070 | |||
3071 | case MULTIDASH: |
||
3072 | /* |
||
3073 | @ multidash 0,1,1 |
||
14071 | bpr | 3074 | @ 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 | 3075 | @ use before command <a href='#multidraw'>multidraw</a> |
14247 | bpr | 3076 | @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw`` |
15111 | schaersvoo | 3077 | @ the dash-type is not -yet- adjustable <br />(e.g. command <code>dashtype line_px,space_px</code> will give no control over multidraw objects) |
11806 | schaersvoo | 3078 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14077 | bpr | 3079 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3080 | */ |
3081 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3082 | temp = get_string(infile,1); |
||
3083 | temp = str_replace(temp,",","\",\""); |
||
3084 | fprintf(js_include_file,"var multidash = [\"%s\"];",temp); |
||
3085 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
3086 | break; |
||
3087 | |||
3088 | case MULTIDRAW: |
||
3089 | /* |
||
3090 | @ multidraw obj_type_1,obj_type_2...obj_type_11 |
||
14066 | bpr | 3091 | @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a> |
15651 | reyssat | 3092 | @ 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<br /><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><li>crosshair | crosshairs</li></ul> |
15111 | schaersvoo | 3093 | @ additionally objects may be user labelled, using obj_type ''text``...<br />in this case allways 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 |
3094 | @ it makes no sense using something like ''multidraw point,points`` ... <br />something like "multidraw polys4,polys7" will only result in drawing a ''4 point polygone`` and not a ''7 point polygone``: this is a design flaw and not a feature... |
||
3095 | @ 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) |
||
3096 | @ 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 'css some_css' |
||
3097 | @ the button label will be default the ''object primitive name`` (like ''point``, ''circles``).<br />If you want a different label (e.g. an other language), use command ''multilabel``<br />for example in dutch: <br /><code>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</code><br />(see command <a href='#multilabel'>multilabel</a> for more details) |
||
14063 | schaersvoo | 3098 | @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed |
15111 | schaersvoo | 3099 | @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons) |
3100 | @ all ''multidraw`` drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">userdraw</a>. |
||
3101 | @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's ) |
||
3102 | @ a local function <code>read_canvas%d</code> will read all userbased drawings.<br />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 = crosshairs_x +";"+ crosshairs_y +"\\n"<br />line 16 = userdraw_x +";"+userdraw_y + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<br/>line 17 = 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> |
||
3103 | @ It is best to prepare / format the student reply in clientside javascript.<br />However in ''wims`` language you could use something like this<br />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 | 3104 | @ <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. |
15111 | schaersvoo | 3105 | @ technical: all 10 ''draw primitives`` + ''text`` will have their own -transparent- PNG bitmap canvas. <br />So for example there can be a points_canvas entirely separated from a line_canvas.<br />This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn), this in contrast too many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element. |
3106 | @ 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<br /> (left mouse button/onclick) and placed on the canvas...left mouse click.<br />using div's will enable you -amongst other content- to add math typesetting from the exercise page onto the canvas. |
||
3107 | @ 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 />crosshair = 25<br />crosshairs = 26 <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_object_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 canvas_scripts[n] <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')<br />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 | 3108 | @%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 |
15313 | schaersvoo | 3109 | @%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 Arial%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%css 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 |
3110 | @%multidraw_demo%size 800,800%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%css color:blue;%fontfamily Italic 42pt Arial%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 | 3111 | @%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 | 3112 | */ |
15111 | schaersvoo | 3113 | js_function[INTERACTIVE] = 1; |
15633 | bpr | 3114 | if(js_function[JS_ZOOM] == 1){use_zoom = 1;} /* use noisy zoom_code, when command zoom is given before command 'multidraw' */ |
14038 | schaersvoo | 3115 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
15111 | schaersvoo | 3116 | if( use_userdraw == 1 ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");} |
3117 | use_userdraw = 2; |
||
11806 | schaersvoo | 3118 | temp = get_string(infile,1); |
3119 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 3120 | var MMP = %d;\ |
3121 | if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = new Array(MMP);for(var i=0;i<MMP;i++){multisnaptogrid[i] = %d;};};\ |
||
3122 | if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null){ var multistrokecolors = new Array(MMP);for(var i=0;i<MMP;i++){multistrokecolors[i] = '%s';};};\ |
||
3123 | if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){var multifillcolors = new Array(MMP);for(var i=0;i<MMP;i++){multifillcolors[i] = '%s';};};\ |
||
3124 | if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null){var multistrokeopacity = new Array(MMP);for(var i=0;i<MMP;i++){multistrokeopacity[i] = %.2f;};};\ |
||
3125 | if( typeof(multifillopacity) === 'undefined' && multifillopacity == null){var multifillopacity = new Array(MMP);for(var i=0;i<MMP;i++){multifillopacity[i] = %.2f;};};\ |
||
3126 | if( typeof(multilinewidth) === 'undefined' && multilinewidth == null){var multilinewidth = new Array(MMP);for(var i=0;i<MMP;i++){multilinewidth[i] = %d;};};\ |
||
3127 | if( typeof(multifill) === 'undefined' && multifill == null){var multifill = new Array(MMP);for(var i=0;i<MMP;i++){multifill[i] = %d;};};\ |
||
3128 | if( typeof(multidash) === 'undefined' && multidash == null){var multidash = new Array(MMP);for(var i=0;i<MMP;i++){multidash[i] = %d;};};\ |
||
3129 | if( typeof(multilabel) === 'undefined' && multilabel == null){var multilabel = [\"%s\",\"stop drawing\"];};\ |
||
3130 | if( typeof(multiuserinput) === 'undefined' && multiuserinput == null){var multiuserinput = new Array(MMP);for(var i=0;i<MMP;i++){multiuserinput[i] = '0';};};\ |
||
3131 | var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';var forbidden_zone = [xsize+2,ysize+2];", |
||
3132 | MAX_MULTI_PRIMITIVES, |
||
3133 | use_snap, |
||
3134 | stroke_color, |
||
3135 | fill_color, |
||
3136 | stroke_opacity, |
||
3137 | fill_opacity, |
||
3138 | line_width, |
||
3139 | use_filled, |
||
3140 | use_dashed, |
||
3141 | str_replace(temp,",","\",\""), |
||
3142 | arrow_head,font_color,font_family); |
||
11806 | schaersvoo | 3143 | if(strstr(temp,"text") != NULL){ |
15111 | schaersvoo | 3144 | js_function[JS_SAFE_EVAL] = 1; |
11806 | schaersvoo | 3145 | } |
3146 | |||
3147 | /* the canvasses range from 1000 ... 1008 */ |
||
15111 | schaersvoo | 3148 | add_js_multidraw(temp,css_class,use_offset,int_data[MAX_MULTI_PRIMITIVES+1],crosshair_size,use_zoom); |
3149 | /* no_controls == int_data[MAX_MULTI_PRIMITIVES+1] */ |
||
11806 | schaersvoo | 3150 | reply_precision = precision; |
3151 | if( reply_format == 0){reply_format = 29;} |
||
3152 | reset();/* if command 'filled' / 'dashed' was given...reset all */ |
||
3153 | break; |
||
3154 | case MULTILABEL: |
||
3155 | /* |
||
3156 | @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text' |
||
14066 | bpr | 3157 | @ use before command <a href='#multidraw'>multidraw</a> |
15111 | schaersvoo | 3158 | @ 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 | 3159 | @ 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> |
15111 | schaersvoo | 3160 | @ all buttons can be ''styled`` by using command <code>css</code><br /><b>note:</b>If you want to add some CSS style to the buttons...<br />the id's of the ''draw buttons`` are their english command argument<br />(e.g. id="canvasdraw_points" for the draw points button).<br />the id of the ''stop drawing`` button is "canvasdraw_stop_drawing".<br />the id of the "OK" button is ''canvasdraw_ok_button`` |
3161 | @ wims will not check the amount or validity of your input |
||
3162 | @ always use the same sequence as is used for ''multidraw`` |
||
3163 | @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code> |
||
11806 | schaersvoo | 3164 | */ |
3165 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3166 | temp = get_string(infile,1); |
||
15116 | bpr | 3167 | if( strcasestr(temp,"NOCONTROLS") ){ |
15111 | schaersvoo | 3168 | int_data[MAX_MULTI_PRIMITIVES+1] = 1; /*int_data[25] = 1 --> 'no_controls = 1' in canvasmacro.c */ |
3169 | fprintf(js_include_file,"var multilabel = null;"); |
||
3170 | } |
||
3171 | else |
||
3172 | { |
||
3173 | int_data[MAX_MULTI_PRIMITIVES+1] = 0; /* so DO use control buttons etc */ |
||
3174 | temp = str_replace(temp,",","\",\""); |
||
3175 | fprintf(js_include_file,"var multilabel = [\"%s\"];",temp); |
||
3176 | } |
||
11806 | schaersvoo | 3177 | break; |
3178 | case MULTILINEWIDTH: |
||
3179 | /* |
||
3180 | @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8 |
||
14066 | bpr | 3181 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3182 | @ if not set all line widths will be set by a previous command ''linewidth int`` |
3183 | @ 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 | 3184 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 3185 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3186 | */ |
3187 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3188 | temp = get_string(infile,1); |
||
3189 | temp = str_replace(temp,",","\",\""); |
||
3190 | fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp); |
||
3191 | break; |
||
3192 | case MULTIFILL: |
||
3193 | /* |
||
3194 | @ multifill 0,0,1,0,1,0,0 |
||
14071 | bpr | 3195 | @ 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...) |
15111 | schaersvoo | 3196 | @ using a fillpattern: multifill 0,1,2,5,3,4<br />meaning: first object is not filled...second object is solid color filled...2=grid | 3=hatch | 4=diamond | 5=dot |
14066 | bpr | 3197 | @ use before command <a href='#multidraw'>multidraw</a> |
14246 | bpr | 3198 | @ 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> |
15651 | reyssat | 3199 | @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles``, ''rect | rects``, ''poly[3-9] | polys[3-9]`` and ''polygon`` |
11806 | schaersvoo | 3200 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 3201 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3202 | */ |
3203 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
15111 | schaersvoo | 3204 | i=0; |
3205 | while( ! done ){ /* get next item until EOL*/ |
||
3206 | if(i > MAX_MULTI_PRIMITIVES){canvas_error("too many multidraw primitives...read the documentation...");} |
||
3207 | int_data[i] = (int)(get_real(infile,1)); /* 0,1,2,3,4,5 */ |
||
3208 | if(int_data[i] < 0 || int_data[i] > 5 ){canvas_error("the only possible multifill arguments are: 0,1,2,3,4,5 ");} |
||
3209 | if(int_data[i] > 1 ){use_filled = 2;js_function[DRAW_FILL_PATTERN] = 1;}/* switch to trigger pattern filling */ |
||
15116 | bpr | 3210 | i++; |
15111 | schaersvoo | 3211 | } |
3212 | fprintf(js_include_file,"var multifill = %s ;",data2js_array(int_data,i-1)); |
||
11806 | schaersvoo | 3213 | break; |
3214 | |||
3215 | case MULTIFILLCOLORS: |
||
3216 | /* |
||
3217 | @ multifillcolors color_name_1,color_name_2,...,color_name_8 |
||
14066 | bpr | 3218 | @ use before command <a href='#multidraw'>multidraw</a> |
14078 | bpr | 3219 | @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity`` |
14071 | bpr | 3220 | @ 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 | 3221 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14379 | bpr | 3222 | @ always use the same sequence as is used for ''multidraw`` |
15111 | schaersvoo | 3223 | @ 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> ... reply=x1:y1:color1,x2:y2:color2...<br />the colors will restart at the first color, when there are more fill-clicks than multi-fill-colors<br />if more control over the used colours is wanted, see command <a href='#colorpalette'>colorpalette color1,color2...</a> |
11806 | schaersvoo | 3224 | */ |
3225 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3226 | fprintf(js_include_file,"var multifillcolors = ["); |
||
3227 | while( ! done ){ |
||
3228 | temp = get_color(infile,1); |
||
3229 | fprintf(js_include_file,"\"%s\",",temp); |
||
3230 | } |
||
3231 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
3232 | break; |
||
3233 | |||
3234 | case MULTIFILLOPACITY: |
||
3235 | /* |
||
3236 | @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8 |
||
3237 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 3238 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3239 | @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled`` |
3240 | @ 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 | 3241 | @ wims will not check the amount or validity of your input |
14071 | bpr | 3242 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3243 | */ |
3244 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3245 | temp = get_string(infile,1); |
||
3246 | temp = str_replace(temp,",","\",\""); |
||
3247 | fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp); |
||
3248 | break; |
||
3249 | case MULTISNAPTOGRID: |
||
3250 | /* |
||
3251 | @ multisnaptogrid 0,1,1 |
||
14071 | bpr | 3252 | @ alternative: <code>multisnap</code> |
3253 | @ 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>) |
||
3254 | @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
||
14246 | bpr | 3255 | @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
14071 | bpr | 3256 | @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code> |
3257 | @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code> |
||
3258 | @ 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> |
||
3259 | @ <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> |
||
15111 | schaersvoo | 3260 | @ use before command <a href='#multidraw'>multidraw</a> |
3261 | @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw`` |
||
3262 | @ commands <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a>, <a href='#snaptofunction'>snaptofunction</a> are <b>not</b> supported amd only functional for command <a href='#userdraw'>userdraw</a> |
||
14071 | bpr | 3263 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3264 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
3265 | */ |
||
3266 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3267 | temp = get_string(infile,1); |
||
14038 | schaersvoo | 3268 | fprintf(js_include_file,"var multisnaptogrid = [%s];",temp); |
15111 | schaersvoo | 3269 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
11806 | schaersvoo | 3270 | break; |
3271 | case MULTISTROKECOLORS: |
||
3272 | /* |
||
3273 | @ multistrokecolors color_name_1,color_name_2,...,color_name_8 |
||
14066 | bpr | 3274 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3275 | @ if not set all colors will be ''stroke_color``, ''stroke_opacity`` |
3276 | @ 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 | 3277 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14071 | bpr | 3278 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3279 | */ |
3280 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3281 | fprintf(js_include_file,"var multistrokecolors = ["); |
||
3282 | while( ! done ){ |
||
3283 | temp = get_color(infile,1); |
||
3284 | fprintf(js_include_file,"\"%s\",",temp); |
||
3285 | } |
||
3286 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
3287 | break; |
||
3288 | case MULTISTROKEOPACITY: |
||
3289 | /* |
||
3290 | @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7 |
||
3291 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 3292 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3293 | @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code> |
15111 | schaersvoo | 3294 | @ 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 | 3295 | @ wims will not check the amount or validity of your input |
14071 | bpr | 3296 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3297 | */ |
3298 | if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3299 | temp = get_string(infile,1); |
||
3300 | temp = str_replace(temp,",","\",\""); |
||
3301 | fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp); |
||
3302 | break; |
||
3303 | |||
3304 | case MULTIUSERINPUT: |
||
3305 | /* |
||
3306 | @ multiuserinput 0,1,1,0 |
||
14071 | bpr | 3307 | @ alternative: <code>multiinput</code> |
15111 | schaersvoo | 3308 | @ meaning, when the command ''multidraw`` is used <code>multidraw circles,points,lines,triangles</code><br />objects ''points`` and ''lines`` may additionally be ''drawn`` by direct input (inputfields)<br/>all other objects must be drawn with a mouse |
3309 | @ 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 |
||
15651 | reyssat | 3310 | @ 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... |
15111 | schaersvoo | 3311 | @ in case of a triangle | poly3, three inputfields are provided. |
15651 | reyssat | 3312 | @ in case of ''text`` and ''multiuserinput=1, 3`` inputfields will be shown: ''x,y,text`` |
3313 | @ in case of ''text`` and ''multiuserinput=0, 1`` inputfield will be shown: text ... a mouse click will place the text on the canvas. |
||
15111 | schaersvoo | 3314 | @ may be styled using command <a href="#css">css</a> |
3315 | @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag∧drop`` or ''onclick`` elements |
||
3316 | @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword ''status`` |
||
3317 | @ use before command <a href='#multidraw'>multidraw</a> |
||
3318 | @ always use the same sequence as is used for ''multidraw`` |
||
11806 | schaersvoo | 3319 | */ |
3320 | /* simple rawmath and input check */ |
||
15111 | schaersvoo | 3321 | js_function[JS_SAFE_EVAL] = 1; |
11806 | schaersvoo | 3322 | temp = get_string(infile,1); |
3323 | temp = str_replace(temp,",","\",\""); |
||
3324 | fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp); |
||
3325 | break; |
||
15111 | schaersvoo | 3326 | case NORESET: |
3327 | /* |
||
3328 | @ killreset |
||
15512 | bpr | 3329 | @ alternative: noreset |
15111 | schaersvoo | 3330 | @ keyword |
3331 | @ may come in handy if canvas script code is generated using loops |
||
3332 | @ if used the following properties will remain to be valid<br /><ul><li>filled</li><li>dash settings</li><li>onclick or drag settings</li><li>centering or offset</li></ul> |
||
3333 | @ if used again, these properies will be reset to the default values and normal behaviour is continued (e.g. the above properties will be reset after 'use' on a canvas object) |
||
3334 | @ etc etc |
||
15633 | bpr | 3335 | @ commands <a href='#slider'>slider</a>, <a href='#linear'>linear</a>, <a href='#rotate'>rotate</a>, <a href='#translate'>translate</a>, <a href='#affine'>affine</a> are always active until the 'kill' commands are given: <br /><a href='#killlinear'>killlinear</a>, <a href='#killrotate'>killrotate</a>, <a href='#killtranslate'>killtranslate</a> and <a href='#killaffine'>killaffine</a> |
3336 | @ commands like 'opacity', 'linewidth', 'fontsize', 'fontfamily' are only changed when redefined again |
||
15111 | schaersvoo | 3337 | @%noreset%size 400,400%xrange -10,10%yrange -10,10%noreset%drag xy%linewidth 4%filled%rect -4,4,-2,2,blue%triangle -3,-3,0,0,1,-5,green%circle 0,0,50,orange%noreset%rect 2,4,4,2,blue |
3338 | */ |
||
3339 | if(no_reset == FALSE){no_reset = TRUE;}else{no_reset = FALSE;reset();} |
||
3340 | break; |
||
11806 | schaersvoo | 3341 | case NOXAXIS: |
3342 | /* |
||
14252 | bpr | 3343 | @ noxaxis |
11806 | schaersvoo | 3344 | @ keyword |
3345 | @ if set, the automatic x-axis numbering will be ignored |
||
14252 | bpr | 3346 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>) |
11806 | schaersvoo | 3347 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
3348 | */ |
||
11891 | schaersvoo | 3349 | fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n"); |
3350 | use_axis_numbering = -1; |
||
11806 | schaersvoo | 3351 | break; |
3352 | case NOYAXIS: |
||
3353 | /* |
||
14251 | bpr | 3354 | @ noyaxis |
11806 | schaersvoo | 3355 | @ keyword |
3356 | @ if set, the automatic y-axis numbering will be ignored |
||
14252 | bpr | 3357 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>) |
11806 | schaersvoo | 3358 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
3359 | */ |
||
11891 | schaersvoo | 3360 | fprintf(js_include_file,"y_strings = {};\n"); |
11806 | schaersvoo | 3361 | break; |
11890 | schaersvoo | 3362 | case NUMBERLINE: |
3363 | /* |
||
3364 | @ numberline x0,x1,xmajor,xminor,y0,y1 |
||
3365 | @ numberline is using xrange/yrange system for all dimensions |
||
11996 | schaersvoo | 3366 | @ 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 | 3367 | @ x0 is start x-value in xrange |
3368 | @ x1 is end x-value in xrange |
||
3369 | @ xmajor is step for major division |
||
14071 | bpr | 3370 | @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded`` |
3371 | @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded`` |
||
11890 | schaersvoo | 3372 | @ y0 is bottom of numberline; y1 endpoint of major tics |
13829 | bpr | 3373 | @ use command <a href="#linewidth">linewidth</a> to control appearance |
11890 | schaersvoo | 3374 | @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line |
3375 | @ for all ticks linewidth and color / opacity are identical. |
||
3376 | @ 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 | 3377 | @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings |
14078 | bpr | 3378 | @ 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 | 3379 | @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported |
3380 | @ onclick and dragging of the numberline are not -yet- supported |
||
14071 | bpr | 3381 | @ 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 | 3382 | @%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 | 3383 | */ |
15111 | schaersvoo | 3384 | js_function[DRAW_NUMBERLINE] = 1; |
11890 | schaersvoo | 3385 | for(i=0;i<6;i++){ |
3386 | switch(i){ |
||
3387 | case 0: double_data[0] = get_real(infile,0);break;/* xmin */ |
||
3388 | case 1: double_data[1] = get_real(infile,0);break;/* xmax */ |
||
3389 | case 2: double_data[2] = get_real(infile,0);break;/* xmajor */ |
||
3390 | case 3: double_data[3] = get_real(infile,0);break;/* xminor */ |
||
3391 | case 4: double_data[4] = get_real(infile,0);break;/* ymin */ |
||
3392 | case 5: double_data[5] = get_real(infile,1);/* ymax */ |
||
3393 | /* |
||
3394 | var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor); |
||
3395 | */ |
||
3396 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] ); |
||
14208 | schaersvoo | 3397 | 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); |
3398 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11996 | schaersvoo | 3399 | 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 | 3400 | add_to_buffer(tmp_buffer); |
3401 | numberline_cnt++; |
||
3402 | break; |
||
3403 | default:break; |
||
3404 | } |
||
3405 | } |
||
3406 | reset(); |
||
3407 | break; |
||
3408 | |||
15541 | schaersvoo | 3409 | case OBABEL: |
3410 | |||
3411 | /* |
||
3412 | @ obabel x,y,type input,molecule smiles-code or file location, extra arguments,extra arguments,... |
||
15633 | bpr | 3413 | @ will call the ''obabel`` program, if installed. |
15541 | schaersvoo | 3414 | @ output will be an svg file |
3415 | @ see documentation of obabel for specail keys |
||
3416 | @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations |
||
3417 | @ command <a href='#rotate'>rotate</a> will rotate the object |
||
3418 | @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br />if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
||
3419 | @ 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... |
||
3420 | @ 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 |
||
3421 | @ external files may be loaded if they are present on the server or in the modules <br />for example:<br /> obabel 0,0,mol,$module_dir/caffeine.mol,-P100,-xb none |
||
3422 | @%obabel_smi%size 400,400%xrange -10,10%yrange -10,10%fillcolor green%drag xy%centered%obabel 0,0,smi,-:c1cFccc1cc,-xb none,-xB blue,-xi,-xt,-xa,-xX,-xP180,-h |
||
3423 | */ |
||
3424 | js_function[DRAW_XML] = 1; |
||
3425 | for(i=0;i<4;i++){ |
||
3426 | switch(i){ |
||
3427 | case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */ |
||
3428 | case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system -> pixel height */ |
||
3429 | case 2: URL = get_string_argument(infile,0);break; |
||
3430 | case 3: |
||
3431 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3432 | temp = getSVGMOL(URL,get_string(infile,1)); |
||
3433 | decimals = find_number_of_digits(precision); |
||
3434 | if(use_affine == TRUE ){ transform(2,2);} |
||
3435 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
3436 | int_data[0] = x2px(double_data[0]); |
||
3437 | int_data[1] = y2px(double_data[1]); |
||
3438 | if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */ |
||
3439 | if( use_slider != -1 && drag_type > 0 ){ onclick = 5;}/* slider+drag*/ |
||
3440 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
3441 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'svg',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
3442 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3443 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'svg',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
3444 | add_to_buffer(tmp_buffer); |
||
3445 | if(onclick != 0 ){object_cnt++;} |
||
3446 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
3447 | break; |
||
3448 | default:break; |
||
3449 | } |
||
3450 | } |
||
3451 | reset(); |
||
3452 | break; |
||
3453 | |||
11806 | schaersvoo | 3454 | case OPACITY: |
3455 | /* |
||
13951 | schaersvoo | 3456 | @ opacity [0-255],[0-255] |
3457 | @ opacity [0.0 - 1.0],[0.0 - 1.0] |
||
14071 | bpr | 3458 | @ alternative: <code>transparent</code> |
11806 | schaersvoo | 3459 | @ first item is stroke opacity, second is fill opacity |
13951 | schaersvoo | 3460 | @%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 | 3461 | */ |
3462 | for(i = 0 ; i<2;i++){ |
||
3463 | switch(i){ |
||
3464 | case 0: double_data[0]= get_real(infile,0);break; |
||
3465 | case 1: double_data[1]= get_real(infile,1);break; |
||
3466 | default: break; |
||
3467 | } |
||
3468 | } |
||
15633 | bpr | 3469 | 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 | 3470 | if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */ |
3471 | if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */ |
||
11806 | schaersvoo | 3472 | break; |
3473 | |||
3474 | case ONCLICK: |
||
3475 | /* |
||
3476 | @ onclick |
||
3477 | @ keyword (no arguments required) |
||
15111 | schaersvoo | 3478 | @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>javascript:read_canvas();</code> |
14086 | bpr | 3479 | @ 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`` |
15111 | schaersvoo | 3480 | @ line based objects will show an increase in line width<br />font based objects will show the text in ''bold`` when clicked. |
14562 | bpr | 3481 | @ the click zone (accuracy) is determined by 2× the line width of the object |
14071 | bpr | 3482 | @ 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...) |
11806 | schaersvoo | 3483 | @ note: not all objects may be set onclick |
12107 | schaersvoo | 3484 | @%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 |
11806 | schaersvoo | 3485 | */ |
15111 | schaersvoo | 3486 | fprintf(js_include_file,"use_dragdrop_reply = true;"); |
11806 | schaersvoo | 3487 | onclick = 1; |
15111 | schaersvoo | 3488 | use_dragstuff=2; |
3489 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3490 | |
3491 | break; |
||
3492 | |||
3493 | case PARALLEL: |
||
3494 | /* |
||
3495 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
15611 | schaersvoo | 3496 | @ affine transformations should be identical to flydraw |
15613 | schaersvoo | 3497 | @ in case of <a href='#rotate'>rotation</a> or <a href='#affine'>affine transformation </a>, command parallel will produce <em>n</em> individual segments, and these may be set ''onclick`` or ''drag xy`` individually. |
3498 | @ in case of <em>no rotation or transformations</em> the lines can not be set ''onclick`` or ''drag xy``. |
||
15629 | bpr | 3499 | @ note: a large number of parallel lines (large <em>n</em>) may result in a canvasdraw error (...simplify your script...it produces too many lines...) |
15611 | schaersvoo | 3500 | @%parallel_click%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red%rotate 45%onclick%parallel -5,5,-4,-5,0.25,0,40,blue |
3501 | @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red |
||
3502 | */ |
||
15613 | schaersvoo | 3503 | decimals = find_number_of_digits(precision); |
15611 | schaersvoo | 3504 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
3505 | |||
15613 | schaersvoo | 3506 | if( use_rotate == TRUE || use_affine == TRUE ){ |
3507 | for( i = 0;i < 8; i++ ){ |
||
3508 | switch(i){ |
||
3509 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
3510 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
3511 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values */ |
||
3512 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values */ |
||
3513 | case 4: double_data[4] = get_real(infile,0);break; /* xv */ |
||
3514 | case 5: double_data[5] = get_real(infile,0);break; /* yv */ |
||
3515 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
3516 | case 7: stroke_color=get_color(infile,1);break;/* name or hex color */ |
||
3517 | default: break; |
||
3518 | } |
||
11806 | schaersvoo | 3519 | } |
15613 | schaersvoo | 3520 | double_data[6] = double_data[0]; /* x1 */ |
15629 | bpr | 3521 | double_data[7] = double_data[1]; /* y1 */ |
15613 | schaersvoo | 3522 | double_data[8] = double_data[2]; /* x2 */ |
15629 | bpr | 3523 | double_data[9] = double_data[3]; /* y2 */ |
15613 | schaersvoo | 3524 | for(i = 0 ; i < int_data[0] ; i++){ |
15629 | bpr | 3525 | double_data[0] = double_data[6] + i*double_data[4]; |
3526 | double_data[1] = double_data[7] + i*double_data[5]; |
||
3527 | double_data[2] = double_data[8] + i*double_data[4]; |
||
3528 | double_data[3] = double_data[9] + i*double_data[5]; |
||
15613 | schaersvoo | 3529 | if(use_rotate == TRUE ){ rotate(4,angle,rotationcenter,2);} |
3530 | if(use_affine == TRUE ){ transform(4,2);} |
||
3531 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3532 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3533 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3534 | add_to_buffer(tmp_buffer); |
||
3535 | if(onclick != 0){object_cnt++;} |
||
3536 | } |
||
3537 | dragstuff[4] = 1; |
||
11806 | schaersvoo | 3538 | } |
15613 | schaersvoo | 3539 | else /* use the old parallel version: calculations in javascript */ |
3540 | { |
||
3541 | for( i = 0;i < 8; i++ ){ |
||
3542 | switch(i){ |
||
3543 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
3544 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
3545 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values */ |
||
3546 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values */ |
||
3547 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv */ |
||
3548 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv */ |
||
3549 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
3550 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
||
3551 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3552 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3553 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3554 | add_to_buffer(tmp_buffer); |
||
3555 | if(onclick != 0){object_cnt++;} |
||
3556 | break; |
||
3557 | default: break; |
||
3558 | } |
||
3559 | dragstuff[11] = 1; |
||
3560 | } |
||
3561 | } |
||
15111 | schaersvoo | 3562 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
15613 | schaersvoo | 3563 | reset(); |
11806 | schaersvoo | 3564 | break; |
15629 | bpr | 3565 | |
11806 | schaersvoo | 3566 | case PLOTSTEPS: |
3567 | /* |
||
3568 | @ plotsteps a_number |
||
3569 | @ default 150 |
||
14066 | bpr | 3570 | @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a> |
11806 | schaersvoo | 3571 | @ use with care ! |
3572 | */ |
||
3573 | plot_steps = (int) (get_real(infile,1)); |
||
3574 | break; |
||
13829 | bpr | 3575 | |
11806 | schaersvoo | 3576 | case POINT: |
3577 | /* |
||
3578 | @ point x,y,color |
||
15111 | schaersvoo | 3579 | @ draw a single point at (x;y) in color 'color' |
14246 | bpr | 3580 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3581 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 3582 | @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming) |
14066 | bpr | 3583 | @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3584 | @%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 | 3585 | */ |
3586 | for(i=0;i<3;i++){ |
||
3587 | switch(i){ |
||
3588 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
3589 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
3590 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 3591 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
3592 | if(use_affine == TRUE ){ transform(2,2);} |
||
3593 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3594 | |||
11806 | schaersvoo | 3595 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 3596 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
3597 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3598 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3599 | add_to_buffer(tmp_buffer); |
||
3600 | /* object_cnt++; */ |
||
3601 | if(onclick != 0){object_cnt++;} |
||
11806 | schaersvoo | 3602 | break; |
3603 | default: break; |
||
3604 | } |
||
3605 | } |
||
15111 | schaersvoo | 3606 | dragstuff[2] = 1; |
3607 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 3608 | reset(); |
3609 | break; |
||
3610 | |||
3611 | case POINTS: |
||
3612 | /* |
||
3613 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
||
15111 | schaersvoo | 3614 | @ draw multiple points at given coordinates in color 'color' |
14246 | bpr | 3615 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3616 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
14066 | bpr | 3617 | @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3618 | @%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 |
3619 | @%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 | 3620 | */ |
8363 | schaersvoo | 3621 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3622 | fill_color = stroke_color; |
||
3623 | i=0; |
||
3624 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3625 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8363 | schaersvoo | 3626 | if(i%2 == 0 ){ |
3627 | double_data[i] = get_real(infile,0); /* x */ |
||
3628 | } |
||
3629 | else |
||
3630 | { |
||
3631 | double_data[i] = get_real(infile,1); /* y */ |
||
3632 | } |
||
3633 | i++; |
||
3634 | } |
||
15111 | schaersvoo | 3635 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3636 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
3637 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8363 | schaersvoo | 3638 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 3639 | for(c = 0 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 3640 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
3641 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3642 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3643 | add_to_buffer(tmp_buffer); |
||
3644 | /* object_cnt++; */ |
||
3645 | if(onclick != 0){object_cnt++;} |
||
8363 | schaersvoo | 3646 | } |
15111 | schaersvoo | 3647 | dragstuff[2] = 1; |
3648 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8363 | schaersvoo | 3649 | reset(); |
3650 | break; |
||
11806 | schaersvoo | 3651 | |
3652 | case POLY: |
||
3653 | /* |
||
3654 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
3655 | @ polygon color,x1,y1,x2,y2...x_n,y_n |
||
3656 | @ draw closed polygon |
||
14071 | bpr | 3657 | @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a> |
11806 | schaersvoo | 3658 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3659 | @%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 |
3660 | @%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 | 3661 | */ |
3662 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
3663 | i=0; |
||
3664 | c=0; |
||
3665 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3666 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 3667 | for( c = 0 ; c < 2; c++){ |
3668 | if(c == 0 ){ |
||
3669 | double_data[i] = get_real(infile,0); |
||
3670 | i++; |
||
3671 | } |
||
3672 | else |
||
3673 | { |
||
3674 | double_data[i] = get_real(infile,1); |
||
3675 | i++; |
||
3676 | } |
||
3677 | } |
||
3678 | } |
||
15111 | schaersvoo | 3679 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3680 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
3681 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3682 | |||
14066 | bpr | 3683 | /* draw path: closed & optional filled */ |
15111 | schaersvoo | 3684 | decimals = find_number_of_digits(precision); |
3685 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3686 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3687 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3688 | add_to_buffer(tmp_buffer); |
||
3689 | if(onclick != 0){object_cnt++;} |
||
3690 | reset(); |
||
3691 | dragstuff[5] = 1; |
||
3692 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 3693 | break; |
3694 | |||
7614 | schaersvoo | 3695 | case POLYLINE: |
3696 | /* |
||
3697 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
10975 | schaersvoo | 3698 | @ brokenline color,x1,y1,x2,y2...x_n,y_n |
3699 | @ path color,x1,y1,x2,y2...x_n,y_n |
||
14086 | bpr | 3700 | @ 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> |
3701 | @ 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 | 3702 | @ 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 | 3703 | @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually |
9406 | schaersvoo | 3704 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3705 | @%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 |
3706 | @%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 | 3707 | */ |
13829 | bpr | 3708 | |
7614 | schaersvoo | 3709 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3710 | i=0; |
||
3711 | c=0; |
||
3712 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3713 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3714 | for( c = 0 ; c < 2; c++){ |
3715 | if(c == 0 ){ |
||
3716 | double_data[i] = get_real(infile,0); |
||
3717 | i++; |
||
3718 | } |
||
3719 | else |
||
3720 | { |
||
3721 | double_data[i] = get_real(infile,1); |
||
3722 | i++; |
||
3723 | } |
||
3724 | } |
||
3725 | } |
||
15111 | schaersvoo | 3726 | |
3727 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
||
3728 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
3729 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3730 | |||
14066 | bpr | 3731 | /* draw path: not closed & not filled */ |
7614 | schaersvoo | 3732 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 3733 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
3734 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3735 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3736 | add_to_buffer(tmp_buffer); |
||
3737 | if(onclick != 0){object_cnt++;} |
||
3738 | /* object_cnt++;*/ |
||
8379 | schaersvoo | 3739 | reset(); |
15111 | schaersvoo | 3740 | dragstuff[4] = 1; |
3741 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 3742 | break; |
11806 | schaersvoo | 3743 | |
3744 | case POPUP: |
||
3745 | /* |
||
3746 | @ popup |
||
3747 | @ keyword (no arguments) |
||
14086 | bpr | 3748 | @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px × ysize px) |
14071 | bpr | 3749 | @ 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`` |
15309 | schaersvoo | 3750 | @ the popup window will be embedded into the page as a normal image, when ''status=done``; override with keyword <a href="#status">nostatus</a> |
3751 | @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br /> <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 | 3752 | @ 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 |
15313 | schaersvoo | 3753 | @%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 H(x)=%userinput function |
11806 | schaersvoo | 3754 | */ |
3755 | use_tooltip = 2; |
||
3756 | break; |
||
3757 | |||
3758 | case PROTRACTOR: |
||
7614 | schaersvoo | 3759 | /* |
11806 | schaersvoo | 3760 | @ protractor x,y,x_width,type,mode,use_a_scale |
3761 | @ x,y are the initial location |
||
14066 | bpr | 3762 | @ x_width: give the width in x-coordinate system (e.g. not in pixels !) |
14246 | bpr | 3763 | @ type = 1: a triangle range 0 - 180<br />type = 2: a circle shape 0 - 360 |
14066 | bpr | 3764 | @ 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 | 3765 | @ 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 | 3766 | @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable |
11806 | schaersvoo | 3767 | @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor... |
14071 | bpr | 3768 | @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor. |
3769 | @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command ''precision`` to set the reply precision. |
||
11806 | schaersvoo | 3770 | @ if combined with a ruler, use replyformat = 32 |
14071 | bpr | 3771 | @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor |
3772 | @ 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 | 3773 | @ only one protractor allowed (for the time being) |
15111 | schaersvoo | 3774 | @ usage: first left click on the protractor will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence... |
15313 | schaersvoo | 3775 | @%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%mouse red,22 |
7614 | schaersvoo | 3776 | */ |
11806 | schaersvoo | 3777 | for( i = 0;i < 6; i++ ){ |
3778 | switch(i){ |
||
3779 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
||
3780 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
3781 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
3782 | case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */ |
||
3783 | case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */ |
||
3784 | case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */ |
||
3785 | decimals = find_number_of_digits(precision); |
||
11821 | schaersvoo | 3786 | if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;} |
15111 | schaersvoo | 3787 | add_js_protractor(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 | 3788 | |
14208 | schaersvoo | 3789 | string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id); |
3790 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3791 | snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id); |
3792 | add_to_buffer(tmp_buffer); |
||
3793 | reply_precision = precision; |
||
3794 | /* no reply from protractor if non-interactive */ |
||
3795 | if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;} |
||
15111 | schaersvoo | 3796 | js_function[INTERACTIVE] = 1; |
11806 | schaersvoo | 3797 | break; |
3798 | default: break; |
||
3799 | } |
||
3800 | } |
||
3801 | break; |
||
3802 | |||
3803 | case PIXELS: |
||
3804 | /* |
||
3805 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
3806 | @ draw rectangular "points" with diameter 1 pixel |
||
3807 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 3808 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12111 | schaersvoo | 3809 | @%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 | 3810 | */ |
15111 | schaersvoo | 3811 | js_function[DRAW_PIXELS] = 1; |
11806 | schaersvoo | 3812 | stroke_color=get_color(infile,0); |
7614 | schaersvoo | 3813 | i=0; |
3814 | c=0; |
||
3815 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3816 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3817 | for( c = 0 ; c < 2; c++){ |
3818 | if(c == 0 ){ |
||
3819 | double_data[i] = get_real(infile,0); |
||
3820 | i++; |
||
3821 | } |
||
3822 | else |
||
3823 | { |
||
3824 | double_data[i] = get_real(infile,1); |
||
3825 | } |
||
3826 | } |
||
3827 | } |
||
15111 | schaersvoo | 3828 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3829 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
11806 | schaersvoo | 3830 | decimals = find_number_of_digits(precision); |
3831 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
14208 | schaersvoo | 3832 | 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); |
3833 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3834 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
3835 | add_to_buffer(tmp_buffer); |
||
3836 | reset(); |
||
7614 | schaersvoo | 3837 | break; |
11806 | schaersvoo | 3838 | |
3839 | case PIXELSIZE: |
||
7614 | schaersvoo | 3840 | /* |
11806 | schaersvoo | 3841 | @ pixelsize int |
3842 | @ in case you want to deviate from default pixelsize = 1(...) |
||
12111 | schaersvoo | 3843 | @ pixelsize 100 is of course a filled rectangle 100px × 100px |
7614 | schaersvoo | 3844 | */ |
11806 | schaersvoo | 3845 | pixelsize = (int) get_real(infile,1); |
3846 | break; |
||
8105 | schaersvoo | 3847 | |
11806 | schaersvoo | 3848 | case PIECHART: |
7614 | schaersvoo | 3849 | /* |
11806 | schaersvoo | 3850 | @ piechart xc,yc,radius,'data+colorlist' |
14066 | bpr | 3851 | @ (xc: yc) center of circle diagram in xrange/yrange |
11806 | schaersvoo | 3852 | @ radius in pixels |
3853 | @ 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 | 3854 | @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white |
11806 | schaersvoo | 3855 | @ the number of colors must match the number of data. |
14066 | bpr | 3856 | @ 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 | 3857 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours |
3858 | @ 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 | 3859 | @ 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 | 3860 | @%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% |
15313 | schaersvoo | 3861 | @%piechart_2%size 200,200%xrange -10,10%yrange -10,10%fontfamily 16px Arial%centered%legend cars:motorcycles:bicycles:trikes%opacity 255,60%piechart 0,0,100,22:red:8:blue:63:green:7:purple |
7614 | schaersvoo | 3862 | */ |
15111 | schaersvoo | 3863 | js_function[DRAW_PIECHART] = 1; |
7614 | schaersvoo | 3864 | for(i=0;i<5;i++){ |
3865 | switch(i){ |
||
11806 | schaersvoo | 3866 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
14032 | schaersvoo | 3867 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
11806 | schaersvoo | 3868 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
3869 | case 3: temp = get_string(infile,1); |
||
3870 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
14208 | schaersvoo | 3871 | 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); |
3872 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
12538 | schaersvoo | 3873 | 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 | 3874 | add_to_buffer(tmp_buffer); |
3875 | break; |
||
3876 | default:break; |
||
7614 | schaersvoo | 3877 | } |
3878 | } |
||
11806 | schaersvoo | 3879 | reset(); |
7614 | schaersvoo | 3880 | break; |
8304 | schaersvoo | 3881 | |
7614 | schaersvoo | 3882 | case RAYS: |
3883 | /* |
||
3884 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
15111 | schaersvoo | 3885 | @ draw rays in color 'color' and center (xc:yc) |
7786 | schaersvoo | 3886 | @ may be set draggable or onclick (every individual ray) |
12111 | schaersvoo | 3887 | @%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 |
3888 | @%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 | 3889 | */ |
3890 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 3891 | fill_color = stroke_color; |
3892 | double_data[0] = get_real(infile,0);/* xc */ |
||
3893 | double_data[1] = get_real(infile,0);/* yc */ |
||
3894 | i=2; |
||
3895 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3896 | if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");} |
7786 | schaersvoo | 3897 | if(i%2 == 0 ){ |
3898 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 3899 | } |
7786 | schaersvoo | 3900 | else |
3901 | { |
||
3902 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 3903 | } |
7786 | schaersvoo | 3904 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
3905 | i++; |
||
7614 | schaersvoo | 3906 | } |
15111 | schaersvoo | 3907 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3908 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
8224 | bpr | 3909 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
3910 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 3911 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
7786 | schaersvoo | 3912 | for(c=2; c<i;c = c+2){ |
15111 | schaersvoo | 3913 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
3914 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3915 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
3916 | add_to_buffer(tmp_buffer); |
||
3917 | /* object_cnt++; */ |
||
3918 | if(onclick != 0){object_cnt++;} |
||
7614 | schaersvoo | 3919 | } |
3920 | reset(); |
||
15111 | schaersvoo | 3921 | dragstuff[4] = 1; |
3922 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 3923 | break; |
8304 | schaersvoo | 3924 | |
11806 | schaersvoo | 3925 | case RECT: |
8386 | schaersvoo | 3926 | /* |
11806 | schaersvoo | 3927 | @ rect x1,y1,x2,y2,color |
14071 | bpr | 3928 | @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle |
14246 | bpr | 3929 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code> |
9406 | schaersvoo | 3930 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
15541 | schaersvoo | 3931 | @ note: internally a rect is defined with 4 points. So when performing some affine transformation, other than translation, it will result in some morphing of the rectangle !<br/>this is a deviation of flydraw's rect&affine |
12111 | schaersvoo | 3932 | @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red |
8386 | schaersvoo | 3933 | */ |
11806 | schaersvoo | 3934 | for(i=0;i<5;i++){ |
3935 | switch(i){ |
||
3936 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
3937 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
15111 | schaersvoo | 3938 | case 2:double_data[4] = get_real(infile,0);break; /* x-values */ |
3939 | case 3:double_data[5] = get_real(infile,0);break; /* y-values */ |
||
11806 | schaersvoo | 3940 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
8386 | schaersvoo | 3941 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 3942 | double_data[2] = double_data[4]; |
3943 | double_data[3] = double_data[1]; |
||
3944 | double_data[6] = double_data[0]; |
||
3945 | double_data[7] = double_data[5]; |
||
3946 | /* using closed PATH (type=5) in stead of ctx.rect (type=1)!!! |
||
3947 | 0,1 2,3 |
||
3948 | 6,7 4,5 |
||
3949 | x = [0,2,4,6] |
||
3950 | y = [1,3,5,7] |
||
3951 | */ |
||
3952 | if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);} |
||
3953 | if(use_affine == TRUE ){ transform(8,2);} |
||
3954 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3955 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[6],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],decimals,double_data[7],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,my_sliders,rotation_center,use_offset); |
||
3956 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3957 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[6],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],decimals,double_data[7],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,my_sliders,rotation_center,use_offset); |
||
3958 | add_to_buffer(tmp_buffer); |
||
3959 | if(onclick != 0){object_cnt++;} |
||
3960 | /* object_cnt++; */ |
||
8386 | schaersvoo | 3961 | reset(); |
3962 | break; |
||
11806 | schaersvoo | 3963 | } |
3964 | } |
||
15111 | schaersvoo | 3965 | dragstuff[5] = 1; |
3966 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 3967 | break; |
8386 | schaersvoo | 3968 | |
11806 | schaersvoo | 3969 | case RECTS: |
8304 | schaersvoo | 3970 | /* |
11806 | schaersvoo | 3971 | @ rects color,x1,y1,x2,y2,..... |
14071 | bpr | 3972 | @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle |
14246 | bpr | 3973 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code> |
14071 | bpr | 3974 | @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour. |
9406 | schaersvoo | 3975 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12111 | schaersvoo | 3976 | @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1 |
8304 | schaersvoo | 3977 | */ |
15111 | schaersvoo | 3978 | /* using closed PATH (type=5) in stead of ctx.rect (type=1)!!! |
3979 | 0,1 2,3 .....8,9 10,11..... |
||
3980 | 6,7 4,5 .....14,15 12,13..... |
||
3981 | x = [0,2,4,6,8,10,12,14...] |
||
3982 | y = [1,3,5,7,9,11,13,15...] |
||
3983 | */ |
||
8304 | schaersvoo | 3984 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3985 | fill_color = stroke_color; |
||
3986 | i=0; |
||
3987 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3988 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8304 | schaersvoo | 3989 | if(i%2 == 0 ){ |
3990 | double_data[i] = get_real(infile,0); /* x */ |
||
3991 | } |
||
3992 | else |
||
3993 | { |
||
3994 | double_data[i] = get_real(infile,1); /* y */ |
||
3995 | } |
||
3996 | i++; |
||
3997 | } |
||
15111 | schaersvoo | 3998 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3999 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
4000 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
15116 | bpr | 4001 | |
8304 | schaersvoo | 4002 | decimals = find_number_of_digits(precision); |
4003 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
15111 | schaersvoo | 4004 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
4005 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4006 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4007 | add_to_buffer(tmp_buffer); |
||
4008 | if(onclick != 0){object_cnt++;} |
||
4009 | /* object_cnt++; */ |
||
8304 | schaersvoo | 4010 | } |
15111 | schaersvoo | 4011 | dragstuff[5] = 1; |
4012 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
4013 | if(use_rotate == TRUE ){ |
||
4014 | rotate(i-1,angle,rotationcenter,2); |
||
4015 | } |
||
8304 | schaersvoo | 4016 | reset(); |
4017 | break; |
||
8386 | schaersvoo | 4018 | |
11806 | schaersvoo | 4019 | case REPLYFORMAT: |
7614 | schaersvoo | 4020 | /* |
11806 | schaersvoo | 4021 | @ replyformat number |
4022 | @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop() |
||
4023 | @ default values should be fine ! |
||
14071 | bpr | 4024 | @ 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 | 4025 | @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();) |
15651 | reyssat | 4026 | @ 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 <code>H1: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 | 4027 | */ |
4028 | reply_format = (int) get_real(infile,1); |
||
4029 | reply_precision = precision; |
||
4030 | break; |
||
4031 | |||
4032 | case ROUNDRECT: |
||
4033 | /* |
||
4034 | @ roundrect x1,y1,x2,y2,radius in px,color |
||
14071 | bpr | 4035 | @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle |
4036 | @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code> |
||
4037 | @ fillcolor will be identical to ''color`` |
||
9406 | schaersvoo | 4038 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12111 | schaersvoo | 4039 | @%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 | 4040 | */ |
11806 | schaersvoo | 4041 | for(i=0;i<6;i++){ |
4042 | switch(i){ |
||
4043 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
4044 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
4045 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
4046 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
4047 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
4048 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 4049 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
4050 | if(use_affine == TRUE ){ transform(2,4);} |
||
4051 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 4052 | /* ensure no inverted roundrect is produced... */ |
4053 | 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];} |
||
4054 | 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 | 4055 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4056 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
4057 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4058 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4059 | add_to_buffer(tmp_buffer); |
||
4060 | if(onclick != 0){object_cnt++;} |
||
4061 | /* object_cnt++;*/ |
||
8379 | schaersvoo | 4062 | reset(); |
11806 | schaersvoo | 4063 | break; |
4064 | } |
||
4065 | } |
||
15111 | schaersvoo | 4066 | dragstuff[6] = 1; |
4067 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 4068 | break; |
8386 | schaersvoo | 4069 | |
11806 | schaersvoo | 4070 | case ROUNDRECTS: |
8347 | schaersvoo | 4071 | /* |
11806 | schaersvoo | 4072 | @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,.... |
14066 | bpr | 4073 | @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command |
9406 | schaersvoo | 4074 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13935 | bpr | 4075 | @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2 |
8347 | schaersvoo | 4076 | */ |
11806 | schaersvoo | 4077 | |
8347 | schaersvoo | 4078 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
11806 | schaersvoo | 4079 | int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */ |
8347 | schaersvoo | 4080 | fill_color = stroke_color; |
4081 | i=0; |
||
4082 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 4083 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8347 | schaersvoo | 4084 | if(i%2 == 0 ){ |
4085 | double_data[i] = get_real(infile,0); /* x */ |
||
4086 | } |
||
4087 | else |
||
4088 | { |
||
4089 | double_data[i] = get_real(infile,1); /* y */ |
||
4090 | } |
||
4091 | i++; |
||
4092 | } |
||
15111 | schaersvoo | 4093 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
4094 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
4095 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8347 | schaersvoo | 4096 | decimals = find_number_of_digits(precision); |
4097 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 4098 | /* ensure no inverted roundrect is produced... */ |
4099 | 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];} |
||
4100 | 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];} |
||
15111 | schaersvoo | 4101 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
4102 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4103 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4104 | add_to_buffer(tmp_buffer); |
||
4105 | if(onclick != 0){object_cnt++;} |
||
4106 | /* object_cnt++; */ |
||
8347 | schaersvoo | 4107 | } |
15111 | schaersvoo | 4108 | dragstuff[6] = 1; |
4109 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8347 | schaersvoo | 4110 | reset(); |
4111 | break; |
||
8386 | schaersvoo | 4112 | |
11806 | schaersvoo | 4113 | case RULER: |
7614 | schaersvoo | 4114 | /* |
14078 | bpr | 4115 | @ ruler x,y,x-width,y-height,mode |
11806 | schaersvoo | 4116 | @ x,y are the initial location |
14078 | bpr | 4117 | @ x-width, y-height are the ruler dimensions width & height in xy-coordinate system |
14071 | bpr | 4118 | @ 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 | 4119 | @ 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 | 4120 | @ if combined with a protractor, use replyformat = 32 |
4121 | @ only one ruler allowed (for the time being) |
||
15651 | reyssat | 4122 | @ 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 | 4123 | @ 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... |
15313 | schaersvoo | 4124 | @%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 |
4125 | @%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 |
||
4126 | @%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 |
||
7614 | schaersvoo | 4127 | */ |
11806 | schaersvoo | 4128 | for( i = 0;i < 5; i++ ){ |
7614 | schaersvoo | 4129 | switch(i){ |
11806 | schaersvoo | 4130 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
4131 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
4132 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
4133 | case 3: double_data[3] = get_real(infile,0);break; /* y-width */ |
||
4134 | case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */ |
||
4135 | decimals = find_number_of_digits(precision); |
||
4136 | if( int_data[0] < 0 ){ |
||
15116 | bpr | 4137 | js_function[JS_FIND_ANGLE] = 1; |
11806 | schaersvoo | 4138 | } |
15111 | schaersvoo | 4139 | add_js_ruler(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 | 4140 | string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id); |
4141 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4142 | snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id); |
4143 | add_to_buffer(tmp_buffer); |
||
4144 | reply_precision = precision; |
||
4145 | /* no reply from ruler if non-interactive */ |
||
4146 | if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;} |
||
7614 | schaersvoo | 4147 | break; |
4148 | default: break; |
||
4149 | } |
||
4150 | } |
||
4151 | break; |
||
8386 | schaersvoo | 4152 | |
15111 | schaersvoo | 4153 | case RESETOFFSET: |
4154 | /* |
||
4155 | @ resetoffset |
||
4156 | @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text |
||
4157 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy |
||
4158 | */ |
||
4159 | use_offset = 0; |
||
4160 | break; |
||
11806 | schaersvoo | 4161 | |
15111 | schaersvoo | 4162 | case ROTATE: |
4163 | /* |
||
4164 | @ rotate rotation_angle |
||
4165 | @ angle in degrees |
||
4166 | @ (only) the next object will be rotated is given angle |
||
4167 | @ positive values rotate counter clockwise |
||
4168 | @ 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) |
||
4169 | @ 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> |
||
4170 | @ attention: rotate will mess up the interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">drag xy</a> or keyword <a href="#onclick">onclick</a>: the mouse recognises the original -unrotated- coordinates of the object |
||
4171 | @%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% |
||
4172 | */ |
||
4173 | use_rotate = TRUE; |
||
4174 | angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */ |
||
4175 | break; |
||
4176 | case ROTATION_CENTER: |
||
4177 | /* |
||
4178 | @ rotationcenter x_center,y_center |
||
4179 | @ define an rotation center in your x/y-coordinate system |
||
4180 | @ wims will not check the validity of your input; use javascript console to debug any erors |
||
4181 | @ if not defined a rotation will be around the first point of an object |
||
4182 | @ to be used before command <a href="#rotate">rotate</a> |
||
4183 | @ use <a href="#killrotate">killrotate</a> to reset to 'null' <br/>(eg. the rotationcenter of the next object(s) will be the first (x;y) coordinate of the object(s)) |
||
4184 | @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given |
||
4185 | @%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 |
||
15633 | bpr | 4186 | @%rotationcenter_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 28%slider 0,2*pi,400,30,angle degrees active, rotate...%plot red,5*sin(x)%filled%linewidth 1%opacity 150,50%fillcolor orange%angle 0,0,pi,0,0,blue |
15111 | schaersvoo | 4187 | */ |
4188 | for( i = 0;i < 2; i++ ){ |
||
4189 | switch(i){ |
||
4190 | case 0: rotationcenter[0] = get_real(infile,0);break; /* x-center */ |
||
4191 | case 1: rotationcenter[1] = get_real(infile,1);break; /* y-center */ |
||
4192 | } |
||
4193 | string_length = 1 + snprintf(NULL,0,"[%f,%f ]",rotationcenter[0],rotationcenter[1]); |
||
4194 | check_string_length(string_length); |
||
4195 | rotation_center = my_newmem(string_length); |
||
4196 | snprintf(rotation_center,string_length,"[%f,%f]",rotationcenter[0],rotationcenter[1]); |
||
4197 | } |
||
4198 | break; |
||
11806 | schaersvoo | 4199 | |
4200 | case SIZE: |
||
4201 | /* |
||
4202 | @ size width,height |
||
4203 | @ set canvas size in pixels |
||
14066 | bpr | 4204 | @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>) |
14162 | bpr | 4205 | @ 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 | 4206 | */ |
4207 | found_size_command = 1; |
||
14066 | bpr | 4208 | /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */ |
11806 | schaersvoo | 4209 | xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
4210 | ysize = (int)(fabs(round(get_real(infile,1)))); |
||
4211 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
4212 | xmin = 0;xmax = xsize; |
||
4213 | ymin = 0;ymax = ysize; |
||
4214 | |||
4215 | /* |
||
4216 | The sequence in which stuff is finally printed is important !! |
||
4217 | */ |
||
4218 | fprintf(stdout,"\n\ |
||
13970 | obado | 4219 | <script>\n\ |
11806 | schaersvoo | 4220 | /*<![CDATA[*/\n\ |
4221 | if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\ |
||
4222 | if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\ |
||
4223 | if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\ |
||
4224 | canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\ |
||
4225 | ",canvas_root_id); |
||
4226 | |||
4227 | /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */ |
||
4228 | if( use_tooltip != 2){ |
||
4229 | fprintf(stdout,"<!-- canvasdraw div -->\n\ |
||
4230 | <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\ |
||
4231 | <!-- tooltip and input placeholder -->\n\ |
||
4232 | <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
||
4233 | <!-- include actual object code via include file -->\n\ |
||
15111 | schaersvoo | 4234 | <script id=\"canvas_script%d\" src=\"%s\" defer></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
11806 | schaersvoo | 4235 | } |
4236 | else |
||
4237 | { |
||
4238 | /* |
||
14066 | bpr | 4239 | set canvas_div invisible and do not include placeholder in main html page: |
15111 | schaersvoo | 4240 | the js-include will also be in a popup window...to be shown when wims $status = done |
11806 | schaersvoo | 4241 | */ |
4242 | fprintf(stdout,"<!-- canvasdraw div invisible -->\n\ |
||
4243 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\ |
||
4244 | <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>\ |
||
4245 | <!-- include actual object code via include file -->\n\ |
||
13970 | obado | 4246 | <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 | 4247 | } |
4248 | |||
14071 | bpr | 4249 | /* these must be global...it is all really very poor javascript:( */ |
13970 | obado | 4250 | fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw */\n\ |
11806 | schaersvoo | 4251 | \"use strict\";\n\ |
15111 | schaersvoo | 4252 | /* these variables and functions must be global */\ |
11806 | schaersvoo | 4253 | var read_dragdrop%d;\ |
14038 | schaersvoo | 4254 | var read_canvas_images;\ |
11806 | schaersvoo | 4255 | var read_canvas%d;\ |
4256 | var set_clock;\ |
||
4257 | var clear_draw_area%d;\ |
||
4258 | var update_draw_area%d;\ |
||
14038 | schaersvoo | 4259 | var place_image_on_canvas;\ |
11806 | schaersvoo | 4260 | var draw_boxplot;\ |
4261 | var redraw_all%d;\ |
||
15111 | schaersvoo | 4262 | var userdraw_primitive;\ |
4263 | var wims_canvas_function%d = function(){\n/* common used stuff */\ |
||
4264 | var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\ |
||
11806 | schaersvoo | 4265 | var xsize = %d;\ |
4266 | var ysize = %d;\ |
||
4267 | var precision = 100;\ |
||
4268 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
||
4269 | 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;};\ |
||
4270 | 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;};\ |
||
15111 | schaersvoo | 4271 | 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);};};\ |
11806 | schaersvoo | 4272 | 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);};};\ |
4273 | 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);};};\ |
||
15111 | schaersvoo | 4274 | 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);};};\ |
11806 | schaersvoo | 4275 | function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\ |
4276 | function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\ |
||
4277 | function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\ |
||
4278 | 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) ));};\ |
||
4279 | 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;};\ |
||
15111 | schaersvoo | 4280 | var snap_x = 1;var snap_y = 1;\ |
11806 | schaersvoo | 4281 | function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\ |
11890 | schaersvoo | 4282 | function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\ |
15111 | schaersvoo | 4283 | 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;case 5: return snap_to_fun(x,y);break;default: return [x,y];break;};};\ |
11806 | schaersvoo | 4284 | var xlogbase = 10;\ |
4285 | var ylogbase = 10;\ |
||
4286 | var use_xlogscale = 0;\ |
||
4287 | var use_ylogscale = 0;\ |
||
11891 | schaersvoo | 4288 | var x_strings = {};var x_strings_up = [];\ |
11806 | schaersvoo | 4289 | var y_strings = null;\ |
4290 | var use_jsmath = 0;\ |
||
4291 | var xstart = 0;\ |
||
4292 | var ystart = 0;\ |
||
4293 | var unit_x=\" \";\ |
||
4294 | var unit_y=\" \";\ |
||
15111 | schaersvoo | 4295 | var dragdrop_reply = [];\ |
14038 | schaersvoo | 4296 | 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); |
15111 | schaersvoo | 4297 | /* var xstart,ystart are normally 0 : in case of sgraph they have the 'jump' in the graph */ |
11806 | schaersvoo | 4298 | break; |
4299 | |||
4300 | |||
4301 | case SEGMENT: |
||
7614 | schaersvoo | 4302 | /* |
11806 | schaersvoo | 4303 | @ segment x1,y1,x2,y2,color |
14071 | bpr | 4304 | @ alternative: <code>seg</code> |
4305 | @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color`` |
||
11806 | schaersvoo | 4306 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14061 | schaersvoo | 4307 | @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green |
4308 | @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green |
||
7614 | schaersvoo | 4309 | */ |
11806 | schaersvoo | 4310 | for(i=0;i<5;i++) { |
7614 | schaersvoo | 4311 | switch(i){ |
11806 | schaersvoo | 4312 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
4313 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
4314 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
4315 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
4316 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 4317 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
4318 | if(use_affine == TRUE ){ transform(4,2);} |
||
4319 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 4320 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4321 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
4322 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4323 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4324 | add_to_buffer(tmp_buffer); |
||
4325 | if(onclick != 0){object_cnt++;} |
||
4326 | /* object_cnt++; */ |
||
11806 | schaersvoo | 4327 | reset(); |
4328 | break; |
||
4329 | default: break; |
||
7614 | schaersvoo | 4330 | } |
4331 | } |
||
15111 | schaersvoo | 4332 | dragstuff[4] = 1; |
4333 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 4334 | break; |
10953 | bpr | 4335 | |
11806 | schaersvoo | 4336 | case SEGMENTS: |
9213 | schaersvoo | 4337 | /* |
11806 | schaersvoo | 4338 | @ segments color,x1,y1,x2,y2,...,x_n,y_n |
14071 | bpr | 4339 | @ alternative: <code>segs</code> |
4340 | @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color`` |
||
15318 | bpr | 4341 | @ use command ''linewidth int`` to adjust size |
11806 | schaersvoo | 4342 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12111 | schaersvoo | 4343 | @%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 |
4344 | @%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 | 4345 | */ |
11806 | schaersvoo | 4346 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
4347 | fill_color = stroke_color; |
||
4348 | i=0; |
||
4349 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 4350 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4351 | if(i%2 == 0 ){ |
4352 | double_data[i] = get_real(infile,0); /* x */ |
||
4353 | } |
||
4354 | else |
||
4355 | { |
||
4356 | double_data[i] = get_real(infile,1); /* y */ |
||
4357 | } |
||
4358 | i++; |
||
4359 | } |
||
15111 | schaersvoo | 4360 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
4361 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
4362 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 4363 | decimals = find_number_of_digits(precision); |
4364 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
15111 | schaersvoo | 4365 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
4366 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4367 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4368 | add_to_buffer(tmp_buffer); |
||
4369 | if(onclick != 0){object_cnt++;} |
||
4370 | /* object_cnt++;*/ |
||
11806 | schaersvoo | 4371 | } |
4372 | reset(); |
||
15111 | schaersvoo | 4373 | dragstuff[4] = 1; |
4374 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
9213 | schaersvoo | 4375 | break; |
11806 | schaersvoo | 4376 | |
4377 | case SETLIMITS: |
||
9213 | schaersvoo | 4378 | /* |
11806 | schaersvoo | 4379 | @ setlimits |
14071 | bpr | 4380 | @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button |
11806 | schaersvoo | 4381 | @ may be used for inputfield based zooming / panning |
15111 | schaersvoo | 4382 | @ may be styled using command <a href="#css">css</a> |
14071 | bpr | 4383 | @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc |
14247 | bpr | 4384 | @ note: the input value will not be checked on validity |
12107 | schaersvoo | 4385 | @%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 | 4386 | */ |
15111 | schaersvoo | 4387 | js_function[JS_SAFE_EVAL] = 1; |
4388 | js_function[JSPLOT_AND_ZOOM] = 1; |
||
4389 | add_setlimits(font_size,css_class); |
||
11806 | schaersvoo | 4390 | done = TRUE; |
9213 | schaersvoo | 4391 | break; |
11806 | schaersvoo | 4392 | |
4393 | case SETPIXEL: |
||
9213 | schaersvoo | 4394 | /* |
11806 | schaersvoo | 4395 | @ setpixel x,y,color |
4396 | @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange |
||
4397 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 4398 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12107 | schaersvoo | 4399 | @%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 | 4400 | */ |
15111 | schaersvoo | 4401 | js_function[DRAW_PIXELS] = 1; |
11806 | schaersvoo | 4402 | for(i=0;i<3;i++){ |
4403 | switch(i){ |
||
4404 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
14162 | bpr | 4405 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11806 | schaersvoo | 4406 | case 2: stroke_color = get_color(infile,1); |
14208 | schaersvoo | 4407 | 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); |
4408 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4409 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
4410 | add_to_buffer(tmp_buffer); |
||
4411 | break; |
||
4412 | default:break; |
||
4413 | } |
||
4414 | } |
||
4415 | reset(); |
||
4416 | break; |
||
4417 | case SLIDER: |
||
9213 | schaersvoo | 4418 | /* |
14071 | bpr | 4419 | @ slider start_value,end_value,width px,height px,type,label |
15655 | schaersvoo | 4420 | @ type may be: ''x,y,angle`` |
4421 | @ if a slider value display is desired, use for argument ''type``: ''x display``, ''y display``, ''angle radian``, ''angle degree`` |
||
15651 | reyssat | 4422 | @ is the slider is used for animation, add keyword ''anim`` or ''animate`` to ''type``; for now only one animated slider may be used... |
4423 | @ default behaviour is: click on an object to use its slider(s)<br/>to use sliders without clicking on an object, use for ''type`` keyword ''active``<br />eg: <code>slider -2*pi,2*pi,300,30,angle degree active,Rotate</code> |
||
14071 | bpr | 4424 | @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit`` |
15655 | schaersvoo | 4425 | @ if the translation should be performed using a function, use for type: ''x function``, ''y function``<br />use commands ''sliderfunction_x`` and/or ''sliderfunction_y`` before the slider command to define the functions. Example:<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 | 4426 | @ use command ''slider`` before draggable/clickable objects. |
15633 | bpr | 4427 | @ 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><br />note: except a combination 'drag' and 'slider' for command 'latex, katex, mathml, html, obabel' |
14071 | bpr | 4428 | @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x`` |
4429 | @ 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 | 4430 | @ amount of sliders is not limited. |
14208 | schaersvoo | 4431 | @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects |
14071 | bpr | 4432 | @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value`` |
11806 | schaersvoo | 4433 | @ every draggable object may have its own slider (no limit in amount of sliders) |
15657 | schaersvoo | 4434 | @ label: some slider text. <br />Note: on <a target='new' href='https://katex.org'>KaTeX</a> enabled wims, TeX produced by wims command ''mathmlmath``, is allowed. |
15111 | schaersvoo | 4435 | @ use fillcolor for slider controlkey |
11806 | schaersvoo | 4436 | @ use strokecolor for slider bar |
4437 | @ use fontfamily / fontcolor to set used fonts |
||
4438 | @ use opacity (only fill opacity will be used) to set transparency |
||
14071 | bpr | 4439 | @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc |
15655 | schaersvoo | 4440 | @%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 active degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%killslider%opacity 200,100%slider -2,2,300,30,x active,move blue rectangle%frect -4,4,1,-1,blue%killslider%linewidth 2%slider -2,2,300,30,y,move green rectangle%frect -4,4,1,-1,green |
15633 | bpr | 4441 | @%slider_click%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 2%slider 0,2*pi,300,28,angle degree, name%fillcolor lightgreen%#CLICK ON THE OBJECTS TO ACTIVATE%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black |
4442 | @%slider_active%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle degree active, name%fillcolor lightgreen%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black |
||
4443 | @%slider_animate%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle anim active, name%fillcolor lightgreen%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black |
||
15654 | bpr | 4444 | @%slider_html_image%%size 400,400%xrange -6,6%yrange -6,6%bgcolor white%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle active degree,%centered%html 0,0,<img src="gifs/domains/sciences/flasks.svg" width="100px" height="100px" /> |
9213 | schaersvoo | 4445 | */ |
14208 | schaersvoo | 4446 | int_data[2] = 0; /* --> show_display = 0; */ |
11806 | schaersvoo | 4447 | for(i=0; i<6 ; i++){ |
4448 | switch(i){ |
||
4449 | case 0: double_data[0] = get_real(infile,0);break; /* start value */ |
||
4450 | case 1: double_data[1] = get_real(infile,0);break; /* end value */ |
||
4451 | case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */ |
||
4452 | case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */ |
||
15655 | schaersvoo | 4453 | case 4: temp = get_string_argument(infile,0); /* type: x,y,angle */ |
15111 | schaersvoo | 4454 | if( strstr(temp,"displ")!=0 || strstr(temp,"deg")!=0 || strstr(temp,"rad")!=0 ){int_data[5] = 1; }else{int_data[5] = 0;} |
4455 | if(strstr(temp,"anim")!= 0){int_data[3] = 1;}else{int_data[3] = 0;} |
||
4456 | if(strstr(temp,"active")!= 0){onclick = 4;}else{onclick=0;} |
||
14208 | schaersvoo | 4457 | 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 | 4458 | else |
14208 | schaersvoo | 4459 | if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}} |
11806 | schaersvoo | 4460 | else |
14208 | schaersvoo | 4461 | if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}} |
4462 | else |
||
4463 | if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}} |
||
4464 | else |
||
15655 | schaersvoo | 4465 | canvas_error("slider can be of type: x,y,angle,fun_x:fun_y"); |
14208 | schaersvoo | 4466 | break; |
15655 | schaersvoo | 4467 | case 5: temp = get_string_argument(infile,1); if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\""," ");} |
4468 | /* slider label : in case of latex/mathmlmath we need to remove the extra " */ |
||
4469 | break; |
||
11806 | schaersvoo | 4470 | } |
4471 | } |
||
15111 | schaersvoo | 4472 | |
4473 | if(use_slider == -1 ){ /* add once */ |
||
4474 | add_slider(int_data[3]); |
||
4475 | if(int_data[5] == 1 ){add_slider_display(precision,font_size,font_color,stroke_opacity);} |
||
14208 | schaersvoo | 4476 | } |
15111 | schaersvoo | 4477 | use_slider++; |
4478 | if(int_data[3] == 0){\ |
||
4479 | string_length = 1 + snprintf(NULL,0,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]); |
||
4480 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4481 | snprintf(tmp_buffer,string_length ,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]); |
||
4482 | }else{ |
||
4483 | string_length = 1 + snprintf(NULL,0,"slider%d = new animslider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]); |
||
4484 | add_slider(int_data[3]);/* use only once !! */ |
||
4485 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4486 | snprintf(tmp_buffer,string_length ,"slider%d = new animslider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]); |
||
4487 | } |
||
14208 | schaersvoo | 4488 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 4489 | fprintf(js_include_file,"var slider%d;",use_slider); |
4490 | use_dragstuff = 2; |
||
4491 | // dragstuff[22] = 1; /* dragstuff switch no 22 is a slider...*/ |
||
4492 | if(onclick != 4 ){ js_function[INTERACTIVE] = 1; }/* no need to click on object to use slider... */ |
||
4493 | //js_function[JS_ROTATE_MOUSE] = 1; |
||
4494 | c = 0; |
||
4495 | for(i=last_slider;i<=use_slider;i++){ |
||
4496 | int_data[c] = i; c++; |
||
4497 | } |
||
4498 | my_sliders = data2js_array(int_data,use_slider - last_slider+1); |
||
14208 | schaersvoo | 4499 | break; |
4500 | |||
14246 | bpr | 4501 | case SLIDER_X: |
9213 | schaersvoo | 4502 | /* |
15111 | schaersvoo | 4503 | @ TEMPORARILY REMOVED |
11806 | schaersvoo | 4504 | @ sliderfunction_x some_function_in_x |
4505 | @ default value "x" |
||
14208 | schaersvoo | 4506 | @ the x-value of the slider object will be calculated with this function. |
11806 | schaersvoo | 4507 | @ default is the x-slider value itself |
14071 | bpr | 4508 | @ only used by command ''slider`` |
11806 | schaersvoo | 4509 | @ define before a slider command ! |
9213 | schaersvoo | 4510 | */ |
15111 | schaersvoo | 4511 | /* slider_function_x = get_string(infile,1);*/ |
11806 | schaersvoo | 4512 | break; |
4513 | case SLIDER_Y: |
||
15111 | schaersvoo | 4514 | /*slider_function_y = get_string(infile,1);*/ |
11806 | schaersvoo | 4515 | /* |
15111 | schaersvoo | 4516 | @ TEMPORARILY REMOVED |
11806 | schaersvoo | 4517 | @ sliderfunction_y some_function_in_y |
4518 | @ default value "y" |
||
4519 | @ the y-value of the slider object(s) will be calculated with this function. |
||
14071 | bpr | 4520 | @ only used by command ''slider`` |
11806 | schaersvoo | 4521 | @ define before a slider command ! |
4522 | */ |
||
4523 | break; |
||
4524 | case SGRAPH: |
||
4525 | /* |
||
4526 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
14071 | bpr | 4527 | @ primitive implementation of a ''broken scale`` graph... |
4528 | @ 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 | 4529 | @%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 | 4530 | */ |
15111 | schaersvoo | 4531 | js_function[DRAW_SGRAPH] = 1; |
11806 | schaersvoo | 4532 | for(i = 0 ; i < 8 ;i++){ |
4533 | switch(i){ |
||
4534 | case 0:double_data[0] = get_real(infile,0);break; |
||
4535 | case 1:double_data[1] = get_real(infile,0);break; |
||
4536 | case 2:double_data[2] = get_real(infile,0);break; |
||
4537 | case 3:double_data[3] = get_real(infile,0);break; |
||
4538 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
4539 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
4540 | case 6:stroke_color = get_color(infile,0);break; |
||
4541 | case 7:font_color = get_color(infile,1); |
||
14208 | schaersvoo | 4542 | 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); |
4543 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4544 | 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); |
4545 | add_to_buffer(tmp_buffer); |
||
4546 | break; |
||
4547 | default:break; |
||
4548 | } |
||
4549 | } |
||
4550 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
9213 | schaersvoo | 4551 | break; |
11806 | schaersvoo | 4552 | case SNAPTOFUNCTION: |
9213 | schaersvoo | 4553 | /* |
11806 | schaersvoo | 4554 | @ snaptofunction some_function_in_x,some_funtion_in_y |
14066 | bpr | 4555 | @ alternative: <code>snaptofun some_function_in_x,some_funtion_in_y</code> |
11806 | schaersvoo | 4556 | @ the next object will snap to the calculated values |
14071 | bpr | 4557 | @ note: snaptofun is probably not really useful feature... |
14066 | bpr | 4558 | @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code> |
4559 | @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code> |
||
14071 | bpr | 4560 | @ for now only one instance of ''snaptofunction`` is allowed |
11806 | schaersvoo | 4561 | @ use rawmath on your functions: no validity checking is done by wims ! |
14071 | bpr | 4562 | @ note: switching x and y coordinates? <code>snaptofunction y,x</code> |
13960 | bpr | 4563 | @%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 |
4564 | @%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 | 4565 | */ |
11806 | schaersvoo | 4566 | temp = get_string_argument(infile,0); |
14038 | schaersvoo | 4567 | use_snap = 2; |
15111 | schaersvoo | 4568 | use_snap = 5; |
4569 | js_function[JS_MATH] = 1; |
||
11806 | schaersvoo | 4570 | 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)); |
4571 | break; |
||
4572 | case SNAPTOPOINTS: |
||
4573 | /* |
||
4574 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
||
4575 | @ a userdraw object will snap to these points. |
||
14071 | bpr | 4576 | @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h) |
14162 | bpr | 4577 | @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup) |
14078 | bpr | 4578 | @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid`` |
13950 | schaersvoo | 4579 | @%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 | 4580 | */ |
4581 | i = 0; |
||
14038 | schaersvoo | 4582 | use_snap = 4; |
11806 | schaersvoo | 4583 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 4584 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4585 | if(i%2 == 0 ){ |
4586 | double_data[i] = get_real(infile,0); /* x */ |
||
4587 | } |
||
4588 | else |
||
4589 | { |
||
4590 | double_data[i] = get_real(infile,1); /* y */ |
||
4591 | } |
||
4592 | i++; |
||
4593 | } |
||
4594 | decimals = find_number_of_digits(precision); |
||
14044 | schaersvoo | 4595 | 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 | 4596 | break; |
4597 | |||
4598 | case SNAPTOGRID: |
||
4599 | /* |
||
4600 | @ snaptogrid |
||
4601 | @ keyword (no arguments required) |
||
14162 | bpr | 4602 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup) |
11806 | schaersvoo | 4603 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
14078 | bpr | 4604 | @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1) |
14071 | bpr | 4605 | @ 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 | 4606 | @ 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 | 4607 | @%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 |
4608 | @%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 | 4609 | */ |
14038 | schaersvoo | 4610 | use_snap = 1; |
11806 | schaersvoo | 4611 | break; |
4612 | |||
4613 | case SQUARE: |
||
4614 | /* |
||
14078 | bpr | 4615 | @ square x,y,side (px),color |
15111 | schaersvoo | 4616 | @ draw a square with left top corner (x:y) with side ''side`` in color 'color' |
14071 | bpr | 4617 | @ use command <code>fsquare x,y,side,color</code> for a filled square |
14162 | bpr | 4618 | @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code> |
11806 | schaersvoo | 4619 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 4620 | @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green |
11806 | schaersvoo | 4621 | */ |
11991 | schaersvoo | 4622 | for(i=0;i<4;i++){ |
11806 | schaersvoo | 4623 | switch(i){ |
4624 | case 0:double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
4625 | case 1:double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
11991 | schaersvoo | 4626 | case 2:double_data[2] = get_real(infile,0);break; /* width in px */ |
4627 | case 3:stroke_color = get_color(infile,1);/* name or hex color */ |
||
4628 | decimals = find_number_of_digits(precision); |
||
4629 | double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize; |
||
4630 | double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize; |
||
15111 | schaersvoo | 4631 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4632 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4633 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4634 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4635 | add_to_buffer(tmp_buffer); |
||
4636 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
11991 | schaersvoo | 4637 | reset();break; |
4638 | default: break; |
||
11806 | schaersvoo | 4639 | } |
4640 | } |
||
15111 | schaersvoo | 4641 | dragstuff[1] = 1; |
4642 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
9213 | schaersvoo | 4643 | break; |
13829 | bpr | 4644 | |
11806 | schaersvoo | 4645 | case STATUS: |
9213 | schaersvoo | 4646 | /* |
11806 | schaersvoo | 4647 | @ status |
4648 | @ keyword |
||
14066 | bpr | 4649 | @ alernative: nostatus |
14078 | bpr | 4650 | @ used to override the effects of ''status=done`` in wims (answer.phtml) |
14071 | bpr | 4651 | @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands |
4652 | @ 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 | 4653 | */ |
11806 | schaersvoo | 4654 | |
4655 | fprintf(js_include_file,"\nwims_status=\"waiting\";\n"); |
||
9213 | schaersvoo | 4656 | break; |
11806 | schaersvoo | 4657 | |
4658 | case STRING: |
||
9213 | schaersvoo | 4659 | /* |
11806 | schaersvoo | 4660 | @ string color,x,y,the text string |
15111 | schaersvoo | 4661 | @ may be set ''onclick`` or ''drag xy`` |
15633 | bpr | 4662 | @ 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 | 4663 | @ unicode supported: <code>string red,0,0,\\u2232</code> |
15313 | schaersvoo | 4664 | @ use a command like <code>fontfamily italic 24px Arial</code> to set fonts on browser that support font change |
4665 | @%string%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Arial%crosshair -3,-3,red%crosshair 3,3,blue%string red,-3,-3,Hello World%fontfamily Italic 18px Arial%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 | 4666 | */ |
15111 | schaersvoo | 4667 | if( use_rotate == TRUE ){js_function[JS_ROTATE_MOUSE] = 1; } |
4668 | dragstuff[14] = 1; |
||
4669 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 4670 | for(i=0;i<5;i++){ |
4671 | switch(i){ |
||
4672 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
4673 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
4674 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
4675 | case 3: decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 4676 | if(use_affine == TRUE ){ transform(2,2);} |
4677 | /* rotate is done by HTML5/CANVAS context rotation */ |
||
11806 | schaersvoo | 4678 | temp = get_string_argument(infile,1); |
4679 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 4680 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4681 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4682 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4683 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4684 | add_to_buffer(tmp_buffer); |
||
4685 | if(onclick != 0){object_cnt++;} |
||
14038 | schaersvoo | 4686 | onclick = 0; |
4687 | use_offset = 0; |
||
15111 | schaersvoo | 4688 | reset(); |
11806 | schaersvoo | 4689 | break; |
4690 | default:break; |
||
4691 | } |
||
9213 | schaersvoo | 4692 | } |
4693 | break; |
||
11806 | schaersvoo | 4694 | |
4695 | case STRINGUP: |
||
9213 | schaersvoo | 4696 | /* |
11806 | schaersvoo | 4697 | @ stringup color,x,y,rotation_degrees,the text string |
15111 | schaersvoo | 4698 | @ may be set ''onclick`` or ''drag xy`` |
15633 | bpr | 4699 | @ 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 |
15111 | schaersvoo | 4700 | @ unicode supported: <code>stringup red,0,0,45,\\u2232</code> |
4701 | @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change |
||
4702 | @ 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 thesame coordinates) |
||
14634 | bpr | 4703 | @ 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> |
15313 | schaersvoo | 4704 | @%stringup%size 400,400%xrange -10,10%yrange -10,10%fontsize 24%fontfamily 14px Arial%crosshair -3,0,red%crosshair 3,0,blue%onclick%stringup red,-3,0,-90,Hello World%drag xy%stringup red,-3,0,-45,Hello World%stringup red,-3,0,45,Hello World%stringup red,-3,0,90,Hello World%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 | 4705 | |
14634 | bpr | 4706 | */ |
15111 | schaersvoo | 4707 | /* html5 canvas rotation is only used for text objects */ |
4708 | use_rotate = TRUE ; |
||
4709 | dragstuff[14] = 1; |
||
4710 | js_function[JS_ROTATE_MOUSE] = 1; |
||
4711 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
15116 | bpr | 4712 | |
15111 | schaersvoo | 4713 | for(i=0;i<6;i++){ |
11806 | schaersvoo | 4714 | switch(i){ |
14596 | schaersvoo | 4715 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
4716 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
4717 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
15111 | schaersvoo | 4718 | case 3: angle = get_real(infile,0);break;/* rotation */ |
11806 | schaersvoo | 4719 | case 4: decimals = find_number_of_digits(precision); |
14596 | schaersvoo | 4720 | temp = get_string_argument(infile,1); |
4721 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 4722 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4723 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4724 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4725 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
4726 | add_to_buffer(tmp_buffer); |
||
4727 | if(onclick != 0){object_cnt++;} |
||
14596 | schaersvoo | 4728 | onclick = 0; |
4729 | use_offset = 0; |
||
4730 | reset(); |
||
4731 | break; |
||
11806 | schaersvoo | 4732 | default:break; |
4733 | } |
||
9213 | schaersvoo | 4734 | } |
14596 | schaersvoo | 4735 | use_rotate = FALSE; |
9213 | schaersvoo | 4736 | break; |
11767 | schaersvoo | 4737 | |
11806 | schaersvoo | 4738 | case STYLE: |
11767 | schaersvoo | 4739 | /* |
11806 | schaersvoo | 4740 | @ highlight color,opacity,linewidth |
4741 | @ NOT IMPLEMENTED |
||
14071 | bpr | 4742 | @ use command ''onclick``: when the object receives a userclick it will increase its linewidth |
11767 | schaersvoo | 4743 | */ |
4744 | break; |
||
11806 | schaersvoo | 4745 | |
4746 | |||
4747 | case STROKECOLOR: |
||
9213 | schaersvoo | 4748 | /* |
11806 | schaersvoo | 4749 | @ strokecolor colorname or #hex |
14071 | bpr | 4750 | @ to be used for commands that do not supply a color argument (like command ''linegraph``) |
9213 | schaersvoo | 4751 | */ |
11806 | schaersvoo | 4752 | stroke_color = get_color(infile,1); |
9213 | schaersvoo | 4753 | break; |
11806 | schaersvoo | 4754 | |
4755 | case FLY_TEXT: |
||
9213 | schaersvoo | 4756 | /* |
11806 | schaersvoo | 4757 | @ text fontcolor,x,y,font,text_string |
14066 | bpr | 4758 | @ font may be described by keywords: giant,huge,normal,small,tiny |
15111 | schaersvoo | 4759 | @ use command ''fontsize`` to increase base fontsize for these keywords |
4760 | @ may be set ''onclick`` or ''drag xy`` |
||
11806 | schaersvoo | 4761 | @ backwards compatible with flydraw |
4762 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
14071 | bpr | 4763 | @ use command ''string`` combined with ''fontfamily`` for a more fine grained control over html5 canvas text element |
15313 | schaersvoo | 4764 | @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``, ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Arial</code>. In that case reset ''fontfamily`` to something lke ''fontfamily Arial`` before the old flydraw commands. |
12311 | schaersvoo | 4765 | @%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 | 4766 | */ |
11806 | schaersvoo | 4767 | for(i = 0; i < 5 ;i++){ |
4768 | switch(i){ |
||
4769 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
4770 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
4771 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
4772 | case 3: fly_font = get_string_argument(infile,0); |
||
4773 | if(strcmp(fly_font,"giant") == 0){ |
||
4774 | fly_font_size = (int)(font_size + 24); |
||
4775 | } |
||
4776 | else |
||
4777 | { |
||
4778 | if(strcmp(fly_font,"huge") == 0){ |
||
4779 | fly_font_size = (int)(font_size + 14); |
||
4780 | } |
||
4781 | else |
||
4782 | { |
||
4783 | if(strcmp(fly_font,"large") == 0){ |
||
4784 | fly_font_size = (int)(font_size + 6); |
||
4785 | } |
||
4786 | else |
||
4787 | { |
||
4788 | if(strcmp(fly_font,"small") == 0){ |
||
4789 | fly_font_size = (int)(font_size - 4); |
||
4790 | if(fly_font_size<0){fly_font_size = 8;} |
||
4791 | } |
||
4792 | } |
||
4793 | } |
||
4794 | } |
||
4795 | break; |
||
4796 | case 4: |
||
4797 | temp = get_string_argument(infile,1); |
||
4798 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 4799 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
15646 | schaersvoo | 4800 | if(use_affine == TRUE ){ transform(2,2);} |
15111 | schaersvoo | 4801 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%s,%s,%d));\n",drag_type,object_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",my_sliders,rotation_center,use_offset); |
4802 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4803 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%s,%s,%d));\n",drag_type,object_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",my_sliders,rotation_center,use_offset); |
||
4804 | add_to_buffer(tmp_buffer); |
||
4805 | if(onclick != 0){object_cnt++;} |
||
14038 | schaersvoo | 4806 | onclick=0; |
4807 | use_offset = 0; |
||
11806 | schaersvoo | 4808 | reset(); |
4809 | break; |
||
4810 | default:break; |
||
4811 | } |
||
10953 | bpr | 4812 | } |
15111 | schaersvoo | 4813 | dragstuff[14] = 1; |
4814 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
9213 | schaersvoo | 4815 | break; |
11806 | schaersvoo | 4816 | case TEXTAREA: |
9289 | schaersvoo | 4817 | /* |
11806 | schaersvoo | 4818 | @ textarea x,y,cols,rows,readonly,value |
15111 | schaersvoo | 4819 | @ may be further controlled by <a href="#css">css</a> |
14162 | bpr | 4820 | @ 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 | 4821 | @ 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 | 4822 | @ keyword ''xoffset | centered`` is not active for command ''textarea`` |
15111 | schaersvoo | 4823 | @%textarea%size 400,400%xrange -10,10%yrange -10,10%css color:red;background-color:lightblue;font-size:14px;text-align:center%textarea -3,-2,6,3,1,?%css color:blue;background-color:yellow;font-size:14px;text-align:center%textarea 0,-2,8,2,1,? |
9289 | schaersvoo | 4824 | */ |
15111 | schaersvoo | 4825 | js_function[DRAW_TEXTAREAS] = 1; |
11806 | schaersvoo | 4826 | for(i = 0 ; i<6;i++){ |
9289 | schaersvoo | 4827 | switch(i){ |
11806 | schaersvoo | 4828 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
4829 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
4830 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
4831 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
4832 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
4833 | case 5: temp = get_string_argument(infile,1); |
||
15111 | schaersvoo | 4834 | 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],css_class,temp); |
14208 | schaersvoo | 4835 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 4836 | 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],css_class,temp); |
11806 | schaersvoo | 4837 | add_to_buffer(tmp_buffer); |
4838 | input_cnt++;break; |
||
9289 | schaersvoo | 4839 | default: break; |
4840 | } |
||
4841 | } |
||
11806 | schaersvoo | 4842 | if(reply_format == 0 ){reply_format = 15;} |
4843 | reset(); |
||
9289 | schaersvoo | 4844 | break; |
11806 | schaersvoo | 4845 | |
11830 | schaersvoo | 4846 | case TEXTFILL: |
4847 | /* |
||
4848 | @ textfill x0,y0,color,some_text |
||
4849 | @ x0,y0 in xrange / yrange |
||
4850 | @ color will be used for the font color |
||
4851 | @ use command <a href="#fontfamily">fontfamily</a> to set font type and size |
||
13829 | bpr | 4852 | @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a> |
15313 | schaersvoo | 4853 | @%textfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fontfamily 24pt Arial%circles red,0,0,3,3,3,6%textfill 4,4,blue,HELLO WORLD |
11830 | schaersvoo | 4854 | */ |
4855 | |||
4856 | js_function[DRAW_TEXTFILL] = 1; |
||
4857 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
4858 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 4859 | add_js_filltoborder(canvas_type); |
11830 | schaersvoo | 4860 | } |
4861 | decimals = find_number_of_digits(precision); |
||
4862 | for(i=0;i<4;i++){ |
||
4863 | switch(i){ |
||
4864 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
||
4865 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
13829 | bpr | 4866 | case 2: font_color = get_color(infile,0); break; |
11830 | schaersvoo | 4867 | case 3: temp = get_string(infile,1); |
14208 | schaersvoo | 4868 | 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); |
4869 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11830 | schaersvoo | 4870 | 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); |
4871 | add_to_buffer(tmp_buffer); |
||
4872 | fill_cnt++; |
||
4873 | break; |
||
4874 | default:break; |
||
4875 | } |
||
4876 | } |
||
4877 | reset(); |
||
4878 | break; |
||
4879 | |||
4880 | |||
11806 | schaersvoo | 4881 | case FLY_TEXTUP: |
9289 | schaersvoo | 4882 | /* |
11806 | schaersvoo | 4883 | @ textup fontcolor,x,y,font,text_string |
14078 | bpr | 4884 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible) |
14066 | bpr | 4885 | @ font may be described by keywords: giant,huge,normal,small,tiny |
14071 | bpr | 4886 | @ use command ''fontsize`` to increase base fontsize for the keywords |
11806 | schaersvoo | 4887 | @ backwards compatible with flydraw |
4888 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
14071 | bpr | 4889 | @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element |
15313 | schaersvoo | 4890 | @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``; ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Arial</code>. In that case reset ''fontfamily`` to something like ''fontfamily Arial`` before the old flydraw commands. |
9289 | schaersvoo | 4891 | */ |
15111 | schaersvoo | 4892 | js_function[DRAW_TEXTS] = 1; |
11806 | schaersvoo | 4893 | for(i = 0; i<5 ;i++){ |
9289 | schaersvoo | 4894 | switch(i){ |
11806 | schaersvoo | 4895 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
4896 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
4897 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
4898 | case 3: fly_font = get_string_argument(infile,0); |
||
4899 | if(strcmp(fly_font,"giant") == 0){ |
||
4900 | fly_font_size = (int)(font_size + 24); |
||
4901 | } |
||
4902 | else |
||
4903 | { |
||
4904 | if(strcmp(fly_font,"huge") == 0){ |
||
4905 | fly_font_size = (int)(font_size + 14); |
||
4906 | } |
||
4907 | else |
||
4908 | { |
||
4909 | if(strcmp(fly_font,"large") == 0){ |
||
4910 | fly_font_size = (int)(font_size + 6); |
||
4911 | } |
||
4912 | else |
||
4913 | { |
||
4914 | if(strcmp(fly_font,"small") == 0){ |
||
4915 | fly_font_size = (int)(font_size - 4); |
||
4916 | if(fly_font_size<0){fly_font_size = 8;} |
||
4917 | } |
||
4918 | } |
||
4919 | } |
||
4920 | } |
||
4921 | break; |
||
4922 | case 4: |
||
9289 | schaersvoo | 4923 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 4924 | temp = get_string_argument(infile,1); |
15111 | schaersvoo | 4925 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4926 | string_length = 1 + snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_offset); |
||
14208 | schaersvoo | 4927 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 4928 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_offset); |
9289 | schaersvoo | 4929 | add_to_buffer(tmp_buffer); |
14038 | schaersvoo | 4930 | reset();use_offset = 0; |
9289 | schaersvoo | 4931 | break; |
11806 | schaersvoo | 4932 | default:break; |
4933 | } |
||
4934 | } |
||
4935 | break; |
||
4936 | |||
4937 | |||
4938 | case TRACE_JSCURVE: |
||
4939 | /* |
||
4940 | @ trace_jscurve some_math_function |
||
4941 | @ will use a crosshair to trace the jsmath curve |
||
4942 | @ two inputfields will display the current x/y-values (numerical evaluation by javascript) |
||
14071 | bpr | 4943 | @ 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 |
15111 | schaersvoo | 4944 | @ use commands fontsize and css to format the fonts for labels and inputfields. |
14071 | bpr | 4945 | @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair. |
4946 | @ 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...) |
||
4947 | @ be aware that the formulas of the plotted function(s) can be found in the page javascript source |
||
15111 | schaersvoo | 4948 | @%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%css 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 | 4949 | */ |
15111 | schaersvoo | 4950 | js_function[INTERACTIVE] = 1; |
4951 | js_function[DRAW_CROSSHAIRS] = 1; |
||
4952 | js_function[DRAW_LINES] = 1; |
||
4953 | js_function[JS_MATH] = 1; |
||
4954 | add_trace_js_mouse(TRACE_CANVAS,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size,css_class); |
||
11806 | schaersvoo | 4955 | break; |
4956 | |||
4957 | |||
4958 | case TRANGE: |
||
4959 | /* |
||
4960 | @ trange tmin,tmax |
||
14071 | bpr | 4961 | @ alternative: <code>ranget</code> |
11806 | schaersvoo | 4962 | @ default -2,2 |
4963 | */ |
||
4964 | use_parametric = TRUE; |
||
4965 | for(i = 0 ; i<2; i++){ |
||
4966 | switch(i){ |
||
4967 | case 0: tmin = get_real(infile,0);break; |
||
4968 | case 1: tmax = get_real(infile,1);break; |
||
9289 | schaersvoo | 4969 | default: break; |
4970 | } |
||
4971 | } |
||
14066 | bpr | 4972 | if(tmin >= tmax ){canvas_error(" trange is not OK: tmin < tmax!\n");} |
9289 | schaersvoo | 4973 | break; |
11806 | schaersvoo | 4974 | case TRANSLATION: |
4975 | /* |
||
4976 | @ translation tx,ty |
||
14071 | bpr | 4977 | @ alternative: <code>translate</code> |
11806 | schaersvoo | 4978 | @ will translate the next objects tx in xrange and ty in yrange |
14071 | bpr | 4979 | @ use command ''killtranstation`` to end the command |
13958 | schaersvoo | 4980 | @%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 | 4981 | */ |
4982 | for(i = 0 ; i<2;i++){ |
||
4983 | switch(i){ |
||
15111 | schaersvoo | 4984 | case 0: affine_matrix[4] = get_real(infile,0);break; |
4985 | case 1: affine_matrix[5] = get_real(infile,1); |
||
11806 | schaersvoo | 4986 | use_affine = TRUE; |
15111 | schaersvoo | 4987 | /* the other values affine_matrix[0..3] remain untouched*/ |
11806 | schaersvoo | 4988 | break; |
4989 | default: break; |
||
4990 | } |
||
4991 | } |
||
4992 | break; |
||
4993 | |||
4994 | case TRIANGLE: |
||
4995 | /* |
||
4996 | @ triangle x1,y1,x2,y2,x3,y3,color |
||
14066 | bpr | 4997 | @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle |
11806 | schaersvoo | 4998 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13948 | schaersvoo | 4999 | @%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 | 5000 | */ |
5001 | for(i=0;i<7;i++){ |
||
5002 | switch(i){ |
||
5003 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
5004 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
5005 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
5006 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
5007 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
5008 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
5009 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
5010 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 5011 | if( use_rotate == TRUE ){ rotate(6,angle,rotationcenter,2);} |
5012 | if( use_affine == TRUE ){ transform(6,2);} |
||
5013 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
5014 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5015 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5016 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5017 | add_to_buffer(tmp_buffer); |
||
5018 | if(onclick != 0){object_cnt++;} |
||
5019 | /* object_cnt++;*/ |
||
11806 | schaersvoo | 5020 | reset(); |
5021 | break; |
||
5022 | default: break; |
||
5023 | } |
||
5024 | } |
||
15111 | schaersvoo | 5025 | dragstuff[5] = 1; |
5026 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 5027 | break; |
5028 | case TRIANGLES: |
||
5029 | /* |
||
5030 | @ triangles color,x1,y1,x2,y2,x3,y3,... |
||
14066 | bpr | 5031 | @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles |
11806 | schaersvoo | 5032 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
13948 | schaersvoo | 5033 | @%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 | 5034 | */ |
5035 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
5036 | i = 0; |
||
5037 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 5038 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
15116 | bpr | 5039 | |
11806 | schaersvoo | 5040 | while( ! done ){ |
11997 | schaersvoo | 5041 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5042 | double_data[0] = get_real(infile,0); /* x1 */ |
5043 | double_data[1] = get_real(infile,0); /* y1 */ |
||
5044 | double_data[2] = get_real(infile,0); /* x2 */ |
||
5045 | double_data[3] = get_real(infile,0); /* y2 */ |
||
5046 | double_data[4] = get_real(infile,0); /* x3 */ |
||
5047 | double_data[5] = get_real(infile,1); /* y3 */ |
||
15111 | schaersvoo | 5048 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
5049 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5050 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5051 | add_to_buffer(tmp_buffer); |
||
5052 | if(onclick != 0){object_cnt++;} |
||
11806 | schaersvoo | 5053 | i = i + 6; |
5054 | } |
||
5055 | reset(); |
||
15111 | schaersvoo | 5056 | dragstuff[5] = 1; |
5057 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 5058 | break; |
5059 | case USERBOXPLOT: |
||
5060 | /* |
||
5061 | @ userboxplot |
||
5062 | @ keyword, no arguments |
||
14066 | bpr | 5063 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 5064 | @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function |
5065 | @ 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 | 5066 | */ |
15111 | schaersvoo | 5067 | js_function[DRAW_BOXPLOT] = 1; |
11806 | schaersvoo | 5068 | fprintf(js_include_file,"var boxplot_source = 3;\n"); |
5069 | js_function[DRAW_JSBOXPLOT] = 2; |
||
5070 | break; |
||
5071 | |||
5072 | case USERBOXPLOTDATA: |
||
5073 | /* |
||
5074 | @ userboxplotdata |
||
5075 | @ keyword, no arguments |
||
14066 | bpr | 5076 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 5077 | @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data`` |
15111 | schaersvoo | 5078 | @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot. |
14066 | bpr | 5079 | @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()' |
11806 | schaersvoo | 5080 | */ |
15111 | schaersvoo | 5081 | js_function[DRAW_BOXPLOT] = 1; |
11806 | schaersvoo | 5082 | fprintf(js_include_file,"var boxplot_source = 2;\n"); |
5083 | js_function[DRAW_JSBOXPLOT] = 1; |
||
5084 | |||
5085 | break; |
||
5086 | |||
7614 | schaersvoo | 5087 | case USERDRAW: |
5088 | /* |
||
5089 | @ userdraw object_type,color |
||
9213 | schaersvoo | 5090 | @ only a single object_type is allowed. |
15111 | schaersvoo | 5091 | @ right mouse click will remove last drawn object. |
5092 | @ for multiple different 'userdraw' objects in an exercise, use command <a href="#multidraw">multidraw</a> |
||
5093 | @ 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<br />multiple areas may be selected <br />multiple colors may be provided using commands <a href='#colorpalette'>colorpalette color1,color2,color3,...</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 !<br />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<br />userdraw textfill,blue,some_text<br />use command <a href="#fontfamily">fontfamily</a> to adjust text style and size</li><li>''clickfill | pattern filling`` in general:<br />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 <br />an inputfield is provided, unicode allowed. The text is drawn a the mouse click, or if used with command ''userinput inputfield`` also at the given x/y-coordonates</li><li>arc</li><li>arcs</li><li>image<br/>only a single "image" of every supported type(*) may be added to canvas window from the surrounding html page.<br />the image should have an 'id' and an onclick handler.<br />(*) supported types are ''svg``,''bitmap``,''p-element``,''div-element`` and ''mathml/tex-code`` with ''\\mmlid{int}``.</li><li>images</li><li>input<br/>place a single inputfield on ''canvas`` <br />use commands 'css' for css styling: use command ''linewidth`` for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield: placing inputfields on top of each other is not possible</li><li>function : identical to <a href="#userinput">userinput function</a></li></ul> |
||
14078 | bpr | 5094 | @ 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) |
15111 | schaersvoo | 5095 | @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />Use command ''fontfamily`` to set font |
11088 | schaersvoo | 5096 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
15111 | schaersvoo | 5097 | @ 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.button != 1: all buttons but left) |
5098 | @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles,filledcircles etc)<br/> in case of ''fillpattern`` do not use the ''f`` prefix ! |
||
11839 | schaersvoo | 5099 | @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a> |
14071 | bpr | 5100 | @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects |
14078 | bpr | 5101 | @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing |
5102 | @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...) |
||
14071 | bpr | 5103 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...) |
14066 | bpr | 5104 | @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a> |
5105 | @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply |
||
13956 | schaersvoo | 5106 | @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a> |
15111 | schaersvoo | 5107 | @ 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 width userdraw.!<br />use command <a href="#multidraw">multidraw</a> is this is a problem for you... |
14247 | bpr | 5108 | @ 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) |
15111 | schaersvoo | 5109 | @ note: a special case is ''userdraw image,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!) |
15527 | bpr | 5110 | @ note: command <br /><code>userdraw function,color</code> is identical to acombination of <code>strokecolor color</code> and <code>userinput function</code><br /> |
15313 | schaersvoo | 5111 | @ note: commands :<br /><code>multicolors red,green,blue<br />multilabel f(x)=:g(x)=:h(x)=<br />userdraw functions3,color</code><br />is identical to commands :<br /><code>functionlabel f(x)=:p(x)=:w(x)=<br/>strokecolor red<br />userinput function <br />strokecolor green<br />userinput function <br />strokecolor blue<br />userinput function</code> |
12107 | schaersvoo | 5112 | @%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 |
5113 | @%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 |
||
5114 | @%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 |
||
5115 | @%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 |
||
5116 | @%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 |
||
5117 | @%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 |
||
5118 | @%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 |
||
5119 | @%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 |
||
5120 | @%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 |
||
5121 | @%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 |
||
5122 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
5123 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
5124 | @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green |
||
5125 | @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green |
||
5126 | @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green |
||
5127 | @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green |
||
5128 | @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green |
||
5129 | @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green |
||
5130 | @%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 |
||
5131 | @%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 |
||
5132 | @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green |
||
5133 | @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green |
||
5134 | @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green |
||
5135 | @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green |
||
5136 | @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green |
||
5137 | @%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 | 5138 | @%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 |
5139 | @%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 | 5140 | @%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 |
5141 | @%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 | 5142 | @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green |
5143 | @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green |
||
5144 | @%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 |
||
5145 | @%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 |
||
5146 | @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green |
||
5147 | @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green |
||
5148 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
5149 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
5150 | @%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 |
||
5151 | @%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 |
||
5152 | @%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 |
||
5153 | @%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 |
||
5154 | @%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 |
||
5155 | @%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 |
||
5156 | @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green |
||
5157 | @%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 |
||
5158 | @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green |
||
5159 | @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green |
||
5160 | @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green |
||
5161 | @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green |
||
15111 | schaersvoo | 5162 | @%userdraw_function%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%multicolors orange,red,green,blue,cyan%precision 1000%userdraw functions3,red%jscurve blue,x^2,-x^2,5*cos(x)%precision 1%mouse red,22 |
14044 | schaersvoo | 5163 | @%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 | 5164 | @%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 |
5165 | @%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 | 5166 | @%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 | 5167 | */ |
15111 | schaersvoo | 5168 | if( use_userdraw != 0 ){ /* only one object type may be drawn*/ |
14038 | schaersvoo | 5169 | canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this..."); |
7614 | schaersvoo | 5170 | } |
15111 | schaersvoo | 5171 | js_function[INTERACTIVE] = 1; |
7614 | schaersvoo | 5172 | draw_type = get_string_argument(infile,0); |
15111 | schaersvoo | 5173 | if( strcmp(draw_type,"textfill") == 0){ |
5174 | fprintf(js_include_file,"var userdraw_text_string = \"%s\";", get_string(infile,1)); |
||
7614 | schaersvoo | 5175 | } |
5176 | else |
||
15111 | schaersvoo | 5177 | { |
5178 | if( strcmp(draw_type,"imagefill") == 0){ |
||
5179 | fprintf(js_include_file,"var userdraw_image_url = \"%s\";", get_string(infile,1)); |
||
5180 | } |
||
5181 | else |
||
5182 | { |
||
5183 | stroke_color = get_color(infile,1); |
||
5184 | } |
||
7614 | schaersvoo | 5185 | } |
15116 | bpr | 5186 | |
15111 | schaersvoo | 5187 | if( strcmp(draw_type,"clickfill") == 0){use_filled = 1;fill_color = stroke_color;} |
5188 | reply_precision = precision; |
||
5189 | use_userdraw = 1; |
||
5190 | fprintf(js_include_file,"\n\ |
||
5191 | /* begin userdraw */\ |
||
5192 | userdraw_x = new Array();userdraw_y = new Array();userdraw_radius = new Array();\ |
||
5193 | var forbidden_zone=[xsize+1,ysize+1];var xy_cnt = 0;\ |
||
5194 | var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\ |
||
5195 | var context_userdraw = canvas_userdraw.getContext(\"2d\");\ |
||
5196 | var use_dashed = %d;\ |
||
5197 | var use_snap = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\ |
||
5198 | context_userdraw.lineWidth = %d;var use_filled = %d;\ |
||
5199 | context_userdraw.strokeStyle = \"rgba(%s,%.2f)\";\ |
||
5200 | context_userdraw.font = \"%s\";\ |
||
15128 | schaersvoo | 5201 | var user_is_dragging = false;\ |
15111 | schaersvoo | 5202 | if(wims_status != \"done\"){\ |
5203 | canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\ |
||
5204 | canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\ |
||
5205 | canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
5206 | canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\ |
||
15128 | schaersvoo | 5207 | canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_drawstop(e.changedTouches[0]);},false);\ |
15111 | schaersvoo | 5208 | };",canvas_root_id,DRAW_CANVAS,use_dashed,use_snap,dashtype[0],dashtype[1],dashtype[0],dashtype[1],line_width,use_filled,stroke_color,stroke_opacity,font_family); |
5209 | |||
5210 | if( use_filled == 0 ){ |
||
5211 | fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(255,255,255.0)\";"); |
||
7614 | schaersvoo | 5212 | } |
5213 | else |
||
5214 | { |
||
15111 | schaersvoo | 5215 | if( use_filled == 1 ){ |
5216 | fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(%s,%.2f)\";",fill_color,fill_opacity); |
||
5217 | } |
||
5218 | else |
||
5219 | { |
||
5220 | js_function[DRAW_FILL_PATTERN] = 1; |
||
5221 | fprintf(js_include_file,"context_userdraw.fillStyle = create_Pattern(0,0,%d,[%s]);\n",use_filled,fill_color); |
||
5222 | } |
||
7614 | schaersvoo | 5223 | } |
15111 | schaersvoo | 5224 | add_js_userdraw(draw_type,stroke_color,stroke_opacity,crosshair_size,arrow_head,use_offset,css_class,use_snap,canvas_type,use_filled,fill_color,fill_opacity,line_width,font_family); |
7614 | schaersvoo | 5225 | reset(); |
5226 | break; |
||
8386 | schaersvoo | 5227 | |
5228 | case USERINPUT: |
||
5229 | /* |
||
13955 | schaersvoo | 5230 | @ userinput function inputfield |
14071 | bpr | 5231 | @ alternative: <code>userinput_function</code> |
5232 | @ alternative: <code>userinput_xy</code> |
||
15111 | schaersvoo | 5233 | @ ''inputfield`` is only usable in combination with some ''userdraw draw_type`` |
5234 | @ note: the input fields are not cleared after the object is drawn...be aware of multiple idential drawings (many clicks on the ''ok`` button) |
||
5235 | @ ''userinput function`` may be used any time (e.g. without userdraw) |
||
14071 | bpr | 5236 | @ multiple ''userinput function`` commands may be used. |
5237 | @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)=" |
||
5238 | @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color |
||
15111 | schaersvoo | 5239 | @ use command <code>css some_css</code> to adjust the inputfields |
14071 | bpr | 5240 | @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px) |
5241 | @ 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 |
||
15111 | schaersvoo | 5242 | @%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%css color:blue;text-align:center%userinput function%# note: number of function inputs not limited |
13955 | schaersvoo | 5243 | @%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 |
5244 | @%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 |
||
15111 | schaersvoo | 5245 | @%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%css 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 | 5246 | */ |
5247 | temp = get_string_argument(infile,1); |
||
5248 | if(strstr(temp,"function") != 0 || strstr(temp,"curve") != 0 || strstr(temp,"plot") != 0 ){ |
||
5249 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
15111 | schaersvoo | 5250 | js_function[JS_RAWMATH] = 1; |
8386 | schaersvoo | 5251 | js_function[DRAW_JSFUNCTION] = 1; |
5252 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
15111 | schaersvoo | 5253 | add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5254 | input_cnt++; |
5255 | } |
||
10953 | bpr | 5256 | else |
8386 | schaersvoo | 5257 | { |
14078 | bpr | 5258 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
15111 | schaersvoo | 5259 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",%s,%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,css_class,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5260 | input_cnt++; |
5261 | } |
||
15111 | schaersvoo | 5262 | js_function[JS_MATH] = 1; |
5263 | js_function[JS_PLOT] = 1; |
||
8386 | schaersvoo | 5264 | } |
5265 | else |
||
5266 | { |
||
5267 | if(strstr(temp,"inputfield") != 0 ){ |
||
15111 | schaersvoo | 5268 | js_function[JS_SAFE_EVAL] = 1; |
5269 | js_function[ADD_USER_INPUTS] = 1; |
||
8386 | schaersvoo | 5270 | } |
5271 | else |
||
5272 | { |
||
15111 | schaersvoo | 5273 | canvas_error("userinput argument may be \"function\" or \"inputfield\""); |
8386 | schaersvoo | 5274 | } |
5275 | } |
||
5276 | break; |
||
5277 | case USERINPUT_XY: |
||
5278 | /* |
||
5279 | @ userinput_xy |
||
9372 | schaersvoo | 5280 | @ keyword (no arguments required) |
8386 | schaersvoo | 5281 | @ to be used in combination with command "userdraw object_type,color" |
14078 | bpr | 5282 | @ 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 | 5283 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
14071 | bpr | 5284 | @ 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 | 5285 | @ can <b>not</b> be combined with command ''intooltip tiptext`` <br />note: the ''tooltip div element`` is used for placing inputfields |
8386 | schaersvoo | 5286 | @ user drawings will not zoom on zooming (or pan on panning) |
15651 | reyssat | 5287 | @ use command ''css some_css`` to adjust the inputarea. |
14071 | bpr | 5288 | @ use command ''fontsize int`` to adjust the text labels (if needed) |
13950 | schaersvoo | 5289 | @%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 | 5290 | */ |
5291 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
15111 | schaersvoo | 5292 | js_function[JS_SAFE_EVAL] = 1; |
5293 | js_function[ADD_USER_INPUTS] = 1; |
||
8386 | schaersvoo | 5294 | break; |
5295 | |||
5296 | case USERINPUT_FUNCTION: |
||
5297 | /* |
||
5298 | @ userinput_function |
||
15313 | schaersvoo | 5299 | @ alternative: userinput function |
9372 | schaersvoo | 5300 | @ keyword (no arguments required) |
14078 | bpr | 5301 | @ if set, a inputfield will be added to the page |
8386 | schaersvoo | 5302 | @ repeat keyword for more function input fields |
5303 | @ the userinput value will be plotted in the canvas |
||
14071 | bpr | 5304 | @ 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 |
15111 | schaersvoo | 5305 | @ use before this command ''userinput_function``,<br />commands like ''css some_css``, ''xlabel some_description``, ''opacity int,int``, ''linewidth int``, ''dashed`` and ''dashtype int,int`` to modify |
14071 | bpr | 5306 | @ fontsize can be set using command ''fontsize int`` |
5307 | @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield |
||
15313 | schaersvoo | 5308 | @%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%css color:blue;text-align:center;font-family:Italic;%strokecolor blue%functionlabel g(x)=:p(x)=:k(x)=%userinput function%# second inputfield%css color:green;text-align:center;font-family:Italic;%strokecolor green%userinput function%# third inputfield%css color:purple;text-align:center;font-family:Italic;%strokecolor purple%userinput function%# no limit in number of function inputfields |
8386 | schaersvoo | 5309 | */ |
5310 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
5311 | js_function[DRAW_JSFUNCTION] = 1; |
||
15111 | schaersvoo | 5312 | js_function[JS_RAWMATH] = 1; |
8386 | schaersvoo | 5313 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
15111 | schaersvoo | 5314 | add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5315 | input_cnt++; |
5316 | } |
||
10953 | bpr | 5317 | else |
8386 | schaersvoo | 5318 | { |
14078 | bpr | 5319 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
15111 | schaersvoo | 5320 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",%s,%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,css_class,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5321 | input_cnt++; |
5322 | } |
||
15111 | schaersvoo | 5323 | js_function[JS_MATH] = 1; |
5324 | js_function[JS_PLOT] = 1; |
||
8386 | schaersvoo | 5325 | break; |
5326 | |||
11806 | schaersvoo | 5327 | case VLINE: |
8386 | schaersvoo | 5328 | /* |
11806 | schaersvoo | 5329 | @ vline x,y,color |
14071 | bpr | 5330 | @ alternative: <code>verticalline</code> |
15111 | schaersvoo | 5331 | @ draw a vertical line through point (x:y) in color 'color' |
11806 | schaersvoo | 5332 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 5333 | @%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 | 5334 | */ |
11806 | schaersvoo | 5335 | for(i=0;i<3;i++) { |
7614 | schaersvoo | 5336 | switch(i){ |
11806 | schaersvoo | 5337 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
5338 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
5339 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
5340 | double_data[2] = double_data[0]; |
||
7614 | schaersvoo | 5341 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 5342 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
5343 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5344 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5345 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5346 | add_to_buffer(tmp_buffer); |
||
5347 | if(onclick != 0){object_cnt++;} |
||
5348 | /* object_cnt++; */ |
||
8379 | schaersvoo | 5349 | reset(); |
7614 | schaersvoo | 5350 | break; |
5351 | } |
||
5352 | } |
||
15111 | schaersvoo | 5353 | dragstuff[4] = 1; |
5354 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 5355 | break; |
5356 | |||
11806 | schaersvoo | 5357 | case VLINES: |
11802 | schaersvoo | 5358 | /* |
11806 | schaersvoo | 5359 | @ vlines color,x1,y1,x2,y2.... |
14071 | bpr | 5360 | @ alternative: <code>verticallines</code> |
15111 | schaersvoo | 5361 | @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color' |
11806 | schaersvoo | 5362 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13939 | bpr | 5363 | @%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 | 5364 | */ |
11806 | schaersvoo | 5365 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5366 | fill_color = stroke_color; |
||
5367 | i=0; |
||
5368 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5369 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5370 | if(i%2 == 0 ){ |
5371 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 5372 | } |
11806 | schaersvoo | 5373 | else |
5374 | { |
||
5375 | double_data[i] = get_real(infile,1); /* y */ |
||
7983 | schaersvoo | 5376 | } |
11806 | schaersvoo | 5377 | i++; |
7983 | schaersvoo | 5378 | } |
11806 | schaersvoo | 5379 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 5380 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 5381 | for(c = 0 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 5382 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
5383 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5384 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5385 | add_to_buffer(tmp_buffer); |
||
5386 | if(onclick != 0){object_cnt++;} |
||
5387 | /* object_cnt++; */ |
||
11806 | schaersvoo | 5388 | } |
5389 | reset(); |
||
15111 | schaersvoo | 5390 | dragstuff[4] = 1; |
5391 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7983 | schaersvoo | 5392 | break; |
11806 | schaersvoo | 5393 | |
5394 | case VIDEO: |
||
7614 | schaersvoo | 5395 | /* |
11806 | schaersvoo | 5396 | @ video x,y,w,h,videofile location |
14066 | bpr | 5397 | @ x,y: left top corner of audio element (in xrange / yrange) |
5398 | @ w,y: width and height in pixels |
||
5399 | @ video format may be in *.mp4 (todo: other formats) |
||
13950 | schaersvoo | 5400 | @%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 | 5401 | */ |
15111 | schaersvoo | 5402 | js_function[DRAW_VIDEO] = 1; |
7614 | schaersvoo | 5403 | for(i=0;i<5;i++){ |
5404 | switch(i){ |
||
11806 | schaersvoo | 5405 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
14162 | bpr | 5406 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
11806 | schaersvoo | 5407 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
5408 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
5409 | case 4: temp = get_string(infile,1); |
||
14208 | schaersvoo | 5410 | 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); |
5411 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5412 | 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 | 5413 | add_to_buffer(tmp_buffer); |
5414 | break; |
||
5415 | default:break; |
||
5416 | } |
||
5417 | } |
||
5418 | reset(); |
||
5419 | break; |
||
11806 | schaersvoo | 5420 | |
7614 | schaersvoo | 5421 | case X_AXIS_STRINGS: |
5422 | /* |
||
5423 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
14071 | bpr | 5424 | @ alternative: <code>xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
13936 | bpr | 5425 | @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof |
9346 | schaersvoo | 5426 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
14071 | bpr | 5427 | @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5428 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
15313 | schaersvoo | 5429 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Arial<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 | 5430 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5431 | @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied |
11044 | schaersvoo | 5432 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14078 | bpr | 5433 | @ ''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 | 5434 | @%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 | 5435 | */ |
11891 | schaersvoo | 5436 | use_axis_numbering++; |
7614 | schaersvoo | 5437 | temp = get_string(infile,1); |
5438 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5439 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5440 | fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering); |
7614 | schaersvoo | 5441 | break; |
9341 | schaersvoo | 5442 | case X_AXIS_STRINGS_UP: |
5443 | /* |
||
5444 | @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
14071 | bpr | 5445 | @ alternative: <code>xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
9341 | schaersvoo | 5446 | @ the text will be rotated 90° up |
11044 | schaersvoo | 5447 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5448 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
9346 | schaersvoo | 5449 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
15313 | schaersvoo | 5450 | @ use command ''fontcolor``, <a href="#fontfamily">fontfamily</a> to adjust font <br />defaults: black,12,Arial<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 | 5451 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5452 | @ 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 | 5453 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14086 | bpr | 5454 | @''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 | 5455 | @%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 | 5456 | */ |
11891 | schaersvoo | 5457 | use_axis_numbering++; |
9341 | schaersvoo | 5458 | temp = get_string(infile,1); |
5459 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5460 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5461 | fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp); |
9341 | schaersvoo | 5462 | break; |
8224 | bpr | 5463 | |
11806 | schaersvoo | 5464 | case XERRORBARS: |
7614 | schaersvoo | 5465 | /* |
11806 | schaersvoo | 5466 | @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
15111 | schaersvoo | 5467 | @ 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 | 5468 | @ the errors E1 and E2 values are in xrange. |
14071 | bpr | 5469 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5470 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5471 | @%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 | 5472 | |
7614 | schaersvoo | 5473 | */ |
11806 | schaersvoo | 5474 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5475 | fill_color = stroke_color; |
||
5476 | i=0; |
||
5477 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5478 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5479 | if(i%2 == 0 ){ |
5480 | double_data[i] = get_real(infile,0); /* x */ |
||
8071 | schaersvoo | 5481 | } |
11806 | schaersvoo | 5482 | else |
5483 | { |
||
5484 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 5485 | } |
11806 | schaersvoo | 5486 | i++; |
7614 | schaersvoo | 5487 | } |
11806 | schaersvoo | 5488 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 5489 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 5490 | for(c = 2 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 5491 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
5492 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5493 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5494 | add_to_buffer(tmp_buffer); |
||
5495 | /* object_cnt++; */ |
||
5496 | if(onclick != 0){object_cnt++;} |
||
11806 | schaersvoo | 5497 | } |
7614 | schaersvoo | 5498 | reset(); |
15111 | schaersvoo | 5499 | dragstuff[20] = 1; |
5500 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 5501 | break; |
11806 | schaersvoo | 5502 | |
5503 | case XRANGE: |
||
7614 | schaersvoo | 5504 | /* |
11806 | schaersvoo | 5505 | @ xrange xmin,xmax |
14071 | bpr | 5506 | @ alternative: <code>rangex</code> |
11806 | schaersvoo | 5507 | @ if not given: 0,xsize (eg in pixels) |
7614 | schaersvoo | 5508 | */ |
11806 | schaersvoo | 5509 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5510 | switch(i){ |
11806 | schaersvoo | 5511 | case 0: xmin = get_real(infile,0);break; |
5512 | case 1: xmax = get_real(infile,1);break; |
||
7614 | schaersvoo | 5513 | default: break; |
5514 | } |
||
5515 | } |
||
15111 | schaersvoo | 5516 | if(xmin >= xmax){canvas_error(" xrange is not OK: xmin < xmax !");} |
5517 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax); |
||
11806 | schaersvoo | 5518 | found_size_command++; |
7614 | schaersvoo | 5519 | break; |
8386 | schaersvoo | 5520 | |
5521 | |||
5522 | |||
11806 | schaersvoo | 5523 | case XSNAPTOGRID: |
7614 | schaersvoo | 5524 | /* |
11806 | schaersvoo | 5525 | @ xsnaptogrid |
5526 | @ keyword (no arguments required) |
||
15111 | schaersvoo | 5527 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup) |
5528 | @ in case of userdraw the drawn points will snap to xmajor grid |
||
14078 | bpr | 5529 | @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1) |
14071 | bpr | 5530 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
15111 | schaersvoo | 5531 | @ if xminor is defined (use keyword ''axis`` to activate xminor), the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br /><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 ...<br /> |
13939 | bpr | 5532 | @%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 |
5533 | @%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 | 5534 | |
7614 | schaersvoo | 5535 | */ |
14038 | schaersvoo | 5536 | use_snap = 2; |
11806 | schaersvoo | 5537 | break; |
8386 | schaersvoo | 5538 | |
11806 | schaersvoo | 5539 | case XOFFSET: |
7614 | schaersvoo | 5540 | /* |
12063 | schaersvoo | 5541 | @ xoffset |
13829 | bpr | 5542 | @ keyword ; to place the text centered above the text coordinates(x:y) ... |
5543 | @ may be used for points or other things requiring centered labels |
||
12063 | schaersvoo | 5544 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11811 | schaersvoo | 5545 | @ 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) |
15313 | schaersvoo | 5546 | @%xoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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 | 5547 | */ |
12063 | schaersvoo | 5548 | use_offset = 2; |
11806 | schaersvoo | 5549 | break; |
8386 | schaersvoo | 5550 | |
11806 | schaersvoo | 5551 | case XYOFFSET: |
7614 | schaersvoo | 5552 | /* |
11806 | schaersvoo | 5553 | @ xyoffset |
5554 | @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily |
||
13829 | bpr | 5555 | @ may be used for points or other things requiring labels |
12063 | schaersvoo | 5556 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11806 | schaersvoo | 5557 | @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy |
15651 | reyssat | 5558 | @ 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> |
15313 | schaersvoo | 5559 | @%xyoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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 | 5560 | */ |
12063 | schaersvoo | 5561 | use_offset = 3; |
11806 | schaersvoo | 5562 | break; |
8386 | schaersvoo | 5563 | |
7996 | schaersvoo | 5564 | case XUNIT: |
5565 | /* |
||
5566 | @ xunit some_unit_for_x-values |
||
5567 | @ unicode allowed (no html code) |
||
15309 | schaersvoo | 5568 | @ use together with command <a href="#display">display or mouse</a> |
14071 | bpr | 5569 | @ will display the cursor x-coordinate in ''unit`` |
12107 | schaersvoo | 5570 | @%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 | 5571 | */ |
5572 | fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1)); |
||
5573 | break; |
||
11806 | schaersvoo | 5574 | |
5575 | case XLABEL: |
||
7996 | schaersvoo | 5576 | /* |
11806 | schaersvoo | 5577 | @ xlabel some_string |
15111 | schaersvoo | 5578 | @ will be used to create a label for the x-axis (label is in quadrant I) |
5579 | @ can only be used together with command ''grid``<br />not depending on keywords ''axis`` and ''axisnumbering`` |
||
5580 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust.<br />(command ''fontfamily`` is not active for this command) |
||
15309 | schaersvoo | 5581 | @ use <a href="#ylabel">ylabel</a> |
5582 | @%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 | 5583 | */ |
11806 | schaersvoo | 5584 | temp = get_string(infile,1); |
5585 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
||
7996 | schaersvoo | 5586 | break; |
8071 | schaersvoo | 5587 | |
11806 | schaersvoo | 5588 | case XLOGBASE: |
7991 | schaersvoo | 5589 | /* |
11806 | schaersvoo | 5590 | @ xlogbase number |
5591 | @ sets the logbase number for the x-axis |
||
5592 | @ default value 10 |
||
5593 | @ use together with commands xlogscale / xylogscale |
||
7991 | schaersvoo | 5594 | */ |
11806 | schaersvoo | 5595 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7991 | schaersvoo | 5596 | break; |
5597 | |||
11806 | schaersvoo | 5598 | case XLOGSCALE: |
7614 | schaersvoo | 5599 | /* |
11806 | schaersvoo | 5600 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
14071 | bpr | 5601 | @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code> |
11806 | schaersvoo | 5602 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
14071 | bpr | 5603 | @ the linewidth is set using command ''linewidth int`` |
14066 | bpr | 5604 | @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a> |
14379 | bpr | 5605 | @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` |
14071 | bpr | 5606 | @ 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> |
5607 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5608 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5609 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5610 | @ 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 | 5611 | @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy ! |
14071 | bpr | 5612 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
15111 | schaersvoo | 5613 | @ <b>attention</b>: do not use command ''zoom`` |
12107 | schaersvoo | 5614 | @%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 | 5615 | */ |
11972 | schaersvoo | 5616 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5617 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
15111 | schaersvoo | 5618 | js_function[DRAW_XLOGSCALE] = 1; |
11806 | schaersvoo | 5619 | for(i=0;i<4;i++){ |
7614 | schaersvoo | 5620 | switch(i){ |
11806 | schaersvoo | 5621 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
5622 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5623 | case 2: stroke_color = get_color(infile,0); break; |
||
5624 | case 3: fill_color = get_color(infile,1); |
||
14208 | schaersvoo | 5625 | 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); |
5626 | tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5627 | 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); |
5628 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
||
5629 | add_to_buffer(tmp_buffer); |
||
5630 | break; |
||
7614 | schaersvoo | 5631 | default:break; |
5632 | } |
||
5633 | } |
||
5634 | break; |
||
11806 | schaersvoo | 5635 | |
5636 | case XYLOGSCALE: |
||
7614 | schaersvoo | 5637 | /* |
11806 | schaersvoo | 5638 | @ xylogscale majorcolor,minorcolor |
14071 | bpr | 5639 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
5640 | @ the linewidth is set using command ''linewidth int`` |
||
5641 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5642 | @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number`` |
14071 | bpr | 5643 | @ 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> |
5644 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5645 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5646 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5647 | @ 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 | 5648 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
14071 | bpr | 5649 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
15111 | schaersvoo | 5650 | @ <b>attention</b>: do not use command ''zoom`` |
13829 | bpr | 5651 | @%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 | 5652 | */ |
11972 | schaersvoo | 5653 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5654 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
15111 | schaersvoo | 5655 | js_function[DRAW_XYLOGSCALE] = 1; |
11806 | schaersvoo | 5656 | for(i=0;i<2;i++){ |
7614 | schaersvoo | 5657 | switch(i){ |
11806 | schaersvoo | 5658 | case 0: stroke_color = get_color(infile,0); break; |
5659 | case 1: fill_color = get_color(infile,1); |
||
14208 | schaersvoo | 5660 | 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); |
5661 | tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5662 | 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); |
5663 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
||
5664 | add_to_buffer(tmp_buffer); |
||
5665 | break; |
||
7614 | schaersvoo | 5666 | default:break; |
5667 | } |
||
5668 | } |
||
5669 | break; |
||
11806 | schaersvoo | 5670 | |
5671 | |||
5672 | case Y_AXIS_STRINGS: |
||
7647 | schaersvoo | 5673 | /* |
11806 | schaersvoo | 5674 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
14071 | bpr | 5675 | @ alternative: <code>yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
15313 | schaersvoo | 5676 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Arial<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 | 5677 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5678 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
14071 | bpr | 5679 | @ use these y-axis num1...num_n values instead of default ymin...ymax |
11806 | schaersvoo | 5680 | @ a javascript error message will flag non-matching value:name pairs |
5681 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
12107 | schaersvoo | 5682 | @%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 | 5683 | */ |
11806 | schaersvoo | 5684 | temp = get_string(infile,1); |
5685 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5686 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
5687 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
11891 | schaersvoo | 5688 | use_axis_numbering++; |
11806 | schaersvoo | 5689 | break; |
5690 | |||
5691 | |||
5692 | case YERRORBARS: |
||
7614 | schaersvoo | 5693 | /* |
11806 | schaersvoo | 5694 | @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
15111 | schaersvoo | 5695 | @ 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 | 5696 | @ the errors E1 and E2 values are in yrange. |
14071 | bpr | 5697 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5698 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5699 | @%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 | 5700 | */ |
11806 | schaersvoo | 5701 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5702 | fill_color = stroke_color; |
||
11772 | schaersvoo | 5703 | i=0; |
5704 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5705 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11772 | schaersvoo | 5706 | if(i%2 == 0 ){ |
5707 | double_data[i] = get_real(infile,0); /* x */ |
||
5708 | } |
||
5709 | else |
||
5710 | { |
||
5711 | double_data[i] = get_real(infile,1); /* y */ |
||
5712 | } |
||
5713 | i++; |
||
5714 | } |
||
15111 | schaersvoo | 5715 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 5716 | for(c = 2 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 5717 | string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
5718 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5719 | snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset); |
||
5720 | add_to_buffer(tmp_buffer); |
||
5721 | /* object_cnt++; */ |
||
5722 | if(onclick != 0){object_cnt++;} |
||
8083 | schaersvoo | 5723 | } |
11806 | schaersvoo | 5724 | decimals = find_number_of_digits(precision); |
8083 | schaersvoo | 5725 | reset(); |
15111 | schaersvoo | 5726 | dragstuff[19] = 1; |
5727 | if(use_dragstuff == 0 ){ use_dragstuff = 1;} |
||
11806 | schaersvoo | 5728 | break; |
11811 | schaersvoo | 5729 | case YOFFSET: |
5730 | /* |
||
5731 | @ yoffset |
||
14162 | bpr | 5732 | @ keyword; to place the text centered above the text coordinates(x:y) ... |
13829 | bpr | 5733 | @ may be used for points or other things requiring centered labels |
12063 | schaersvoo | 5734 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
5735 | @ 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) |
||
15313 | schaersvoo | 5736 | @%yoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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 | 5737 | */ |
12063 | schaersvoo | 5738 | use_offset = 1; |
11811 | schaersvoo | 5739 | break; |
5740 | |||
11806 | schaersvoo | 5741 | case YRANGE: |
7614 | schaersvoo | 5742 | /* |
11806 | schaersvoo | 5743 | @ yrange ymin,ymax |
14071 | bpr | 5744 | @ alternative: <code>rangey</code> |
11806 | schaersvoo | 5745 | @ if not given 0,ysize (eg in pixels) |
7614 | schaersvoo | 5746 | */ |
11806 | schaersvoo | 5747 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5748 | switch(i){ |
11806 | schaersvoo | 5749 | case 0: ymin = get_real(infile,0);break; |
5750 | case 1: ymax = get_real(infile,1);break; |
||
5751 | default: break; |
||
7614 | schaersvoo | 5752 | } |
5753 | } |
||
15111 | schaersvoo | 5754 | if(ymin >= ymax){canvas_error(" yrange is not OK: ymin < ymax !<br />");} |
5755 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax); |
||
11806 | schaersvoo | 5756 | found_size_command++; |
5757 | break; |
||
5758 | |||
5759 | case YSNAPTOGRID: |
||
7614 | schaersvoo | 5760 | /* |
11806 | schaersvoo | 5761 | @ ysnaptogrid |
5762 | @ keyword (no arguments required) |
||
14162 | bpr | 5763 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup) |
11806 | schaersvoo | 5764 | @ in case of userdraw the drawn points will snap to ymajor grid |
14078 | bpr | 5765 | @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1) |
14071 | bpr | 5766 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
5767 | @ 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 /> |
||
15111 | schaersvoo | 5768 | @%ysnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%css font-size:8px;color:blue%clearbutton delete all crosshairs |
13959 | bpr | 5769 | @%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 | 5770 | */ |
14038 | schaersvoo | 5771 | use_snap = 3; |
7614 | schaersvoo | 5772 | break; |
11080 | schaersvoo | 5773 | |
7614 | schaersvoo | 5774 | case YLABEL: |
5775 | /* |
||
5776 | @ ylabel some_string |
||
8224 | bpr | 5777 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
14071 | bpr | 5778 | @ can only be used together with command <a href="#grid">grid</a><br />not depending on keywords ''axis`` and ''axisnumbering`` |
14086 | bpr | 5779 | @ 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) |
15309 | schaersvoo | 5780 | @ use <a href="#xlabel">xlabel</a> |
12107 | schaersvoo | 5781 | @%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 | 5782 | */ |
5783 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 5784 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 5785 | break; |
7735 | schaersvoo | 5786 | case YLOGBASE: |
5787 | /* |
||
5788 | @ ylogbase number |
||
5789 | @ sets the logbase number for the y-axis |
||
5790 | @ default value 10 |
||
5791 | @ use together with commands ylogscale / xylogscale |
||
5792 | */ |
||
5793 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
5794 | break; |
||
7614 | schaersvoo | 5795 | case YLOGSCALE: |
7729 | schaersvoo | 5796 | /* |
5797 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
14071 | bpr | 5798 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
7729 | schaersvoo | 5799 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
14071 | bpr | 5800 | @ the linewidth is set using command ''linewidth int`` |
5801 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5802 | @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number`` |
14071 | bpr | 5803 | @ 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> |
5804 | @ note: the complete canvas will be used for the ''log paper`` |
||
11088 | schaersvoo | 5805 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5806 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5807 | @ 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 | 5808 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
15111 | schaersvoo | 5809 | @ <b>attention</b>: do not use command ''zoom`` |
14071 | bpr | 5810 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
7729 | schaersvoo | 5811 | */ |
11972 | schaersvoo | 5812 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
7729 | schaersvoo | 5813 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
15111 | schaersvoo | 5814 | js_function[DRAW_YLOGSCALE] = 1; |
7729 | schaersvoo | 5815 | for(i=0;i<4;i++){ |
5816 | switch(i){ |
||
5817 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
5818 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5819 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 5820 | case 3: fill_color = get_color(infile,1); |
14208 | schaersvoo | 5821 | 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); |
5822 | tmp_buffer = my_newmem(string_length); |
||
7779 | schaersvoo | 5823 | 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 | 5824 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 5825 | add_to_buffer(tmp_buffer); |
5826 | break; |
||
5827 | default:break; |
||
5828 | } |
||
5829 | } |
||
7614 | schaersvoo | 5830 | break; |
11806 | schaersvoo | 5831 | |
5832 | case YUNIT: |
||
7735 | schaersvoo | 5833 | /* |
11806 | schaersvoo | 5834 | @ yunit some_unit_for_y-values |
5835 | @ unicode allowed (no html code) |
||
5836 | @ use together with command mousey |
||
14071 | bpr | 5837 | @ will display the cursor y-coordinate in ''unit`` |
7735 | schaersvoo | 5838 | */ |
11806 | schaersvoo | 5839 | fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1)); |
5840 | break; |
||
5841 | |||
5842 | case ZOOM: |
||
5843 | /* |
||
5844 | @ zoom button_color |
||
15313 | schaersvoo | 5845 | @ introduce a very small ''controlpanel`` at the lower right corner (font size of the panel is fixed to: 22px Arial) |
15111 | schaersvoo | 5846 | @ giving six 15×15px ''active`` rectangle areas<br />(''×,↓,↑,←,→,−,+``) for zooming and/or panning of the image |
5847 | @ a mouse wheel is active for in/out zooming. Drag panning is not supported (this will conflict with many ''userdraw`` or ''multidraw`` primitives) |
||
5848 | @ the ''controlpanel`` is not active for a ''userdraw`` mousedown (but it can interfere with some ''userdraw`` types) |
||
5849 | @ the ''×`` symbol will reset to your original xmax/xmin ymax/ymin values. |
||
5850 | @ choose an appropriate color, so the small ''×,↓,↑,←,→,−,+`` are clearly visible |
||
14071 | bpr | 5851 | @ command ''opacity`` may be used to set stroke_opacity of buttons |
15111 | schaersvoo | 5852 | @ note: on zooming, text will not increase / decrease the font size (todo??) |
15116 | bpr | 5853 | @ note: adding ''zooming`` will increase the size of the javascript include with approx. 11 kb |
11806 | schaersvoo | 5854 | */ |
15111 | schaersvoo | 5855 | js_function[INTERACTIVE] = 1; |
5856 | js_function[JS_ZOOM] = 1; |
||
5857 | if( use_userdraw == 1 ){ |
||
5858 | js_function[USERDRAW_AND_ZOOM] = 1; |
||
5859 | fprintf(js_include_file,"forbidden_zone = [%d,%d];",xsize-115,ysize - 20); |
||
5860 | } |
||
5861 | if(jsplot_cnt != -1){ js_function[JSPLOT_AND_ZOOM] = 1;} |
||
11806 | schaersvoo | 5862 | stroke_color = get_color(infile,1); |
5863 | /* we use BG_CANVAS (0) */ |
||
15111 | schaersvoo | 5864 | add_js_zoom_buttons(stroke_color,stroke_opacity); |
11806 | schaersvoo | 5865 | done = TRUE; |
5866 | break; |
||
5867 | |||
5868 | /* ready */ |
||
7614 | schaersvoo | 5869 | default:sync_input(infile); |
5870 | break; |
||
5871 | } |
||
8224 | bpr | 5872 | } |
7614 | schaersvoo | 5873 | /* we are done parsing script file */ |
15111 | schaersvoo | 5874 | if(use_dragstuff != 0){ |
5875 | /* add the 20kb drag code: nearly always used ... use_dragstuff==1: no-mouse ! */ |
||
5876 | add_drag_code(DRAG_CANVAS,use_dragstuff,dragstuff,reply_format); |
||
5877 | if(js_function[JS_ZOOM] == 1){ |
||
5878 | js_function[DRAG_AND_ZOOM] = 1; |
||
5879 | } |
||
5880 | } |
||
15116 | bpr | 5881 | |
14066 | bpr | 5882 | /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */ |
7983 | schaersvoo | 5883 | if( found_size_command == 1 ){ |
5884 | fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize); |
||
5885 | } |
||
5886 | else |
||
5887 | { |
||
5888 | if( found_size_command != 3 ){ |
||
15111 | schaersvoo | 5889 | canvas_error("Please specify size first and then both xrange and yrange ..."); |
7983 | schaersvoo | 5890 | } |
5891 | } |
||
8257 | schaersvoo | 5892 | |
14066 | bpr | 5893 | /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects ! */ |
15111 | schaersvoo | 5894 | add_javascript_function(); |
7614 | schaersvoo | 5895 | /* add read_canvas() etc functions if needed */ |
15111 | schaersvoo | 5896 | if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);} |
7797 | schaersvoo | 5897 | /* no zoom, just add buffer */ |
15111 | schaersvoo | 5898 | fprintf(js_include_file,"\n/* add buffer */\n%s};\n/* end wims_canvas_function */\nwims_canvas_function%d();\n",buffer,canvas_root_id); |
7614 | schaersvoo | 5899 | /* done writing the javascript include file */ |
5900 | fclose(js_include_file); |
||
5901 | } |
||
5902 | |||
5903 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
9329 | schaersvoo | 5904 | if( use_tooltip > 0 ){ |
5905 | if( use_tooltip == 1 ){ |
||
15111 | schaersvoo | 5906 | add_js_tooltip(tooltip_text,bgcolor); |
9329 | schaersvoo | 5907 | } |
5908 | else |
||
5909 | { |
||
5910 | if( use_tooltip == 2 ){ |
||
15111 | schaersvoo | 5911 | add_js_popup(getfile_cmd); |
9329 | schaersvoo | 5912 | } |
5913 | } |
||
5914 | } |
||
7614 | schaersvoo | 5915 | exit(EXIT_SUCCESS); |
5916 | } |
||
5917 | /* end main() */ |
||
5918 | |||
15111 | schaersvoo | 5919 | |
7614 | schaersvoo | 5920 | /****************************************************************************** |
5921 | ** |
||
5922 | ** sync_input |
||
5923 | ** |
||
5924 | ** synchronises input line - reads to end of line, leaving file pointer |
||
5925 | ** at first character of next line. |
||
5926 | ** |
||
5927 | ** Used by: |
||
5928 | ** main program - error handling. |
||
5929 | ** |
||
5930 | ******************************************************************************/ |
||
5931 | void sync_input(FILE *infile) |
||
5932 | { |
||
5933 | int c = 0; |
||
5934 | |||
7658 | schaersvoo | 5935 | if( c == '\n' || c == ';' ) return; |
5936 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 5937 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 5938 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 5939 | return; |
5940 | } |
||
5941 | |||
5942 | /******************************************************************************/ |
||
5943 | |||
15111 | schaersvoo | 5944 | |
5945 | void transform(int num,int incr){ |
||
5946 | /*. |
||
5947 | only "double_data[]" is used for transformations !! |
||
5948 | */ |
||
5949 | int i;int ii;double x,y; |
||
5950 | for(i=0;i<num;i = i+incr){ |
||
5951 | ii = i+1; |
||
5952 | x = double_data[i]*affine_matrix[0] + double_data[ii]*affine_matrix[1]+affine_matrix[4]; |
||
5953 | y = double_data[i]*affine_matrix[2] + double_data[ii]*affine_matrix[3]+affine_matrix[5]; |
||
15601 | schaersvoo | 5954 | /* |
5955 | printf("(%f:%f) → (%f:%f)<br />",double_data[i],double_data[ii],x,y); |
||
5956 | */ |
||
15111 | schaersvoo | 5957 | double_data[i] = x; |
5958 | double_data[ii] = y; |
||
5959 | } |
||
5960 | } |
||
5961 | |||
5962 | void rotate(int num,double angle,double center[],int incr){ |
||
5963 | int i;int ii;double rad = angle * 0.0174532925199; |
||
5964 | double c = cos(rad); |
||
5965 | double s = sin(rad); |
||
5966 | double x,y; |
||
5967 | for(i=0;i<num;i = i+incr){ |
||
5968 | ii = i+1; |
||
5969 | x = c*(double_data[i]-center[0]) + s*(double_data[ii] - center[1] ) + center[0]; |
||
5970 | y = c*(double_data[ii]-center[1]) - s*(double_data[i] - center[0] ) + center[1]; |
||
5971 | double_data[i] = x; |
||
5972 | double_data[ii] = y; |
||
15116 | bpr | 5973 | // printf("(x:y) - (%f:%f)<br />",x,y); |
15111 | schaersvoo | 5974 | } |
5975 | } |
||
5976 | /* not used: see transform() |
||
5977 | void translate(int num){ |
||
5978 | int i;int ii; |
||
5979 | double x,y; |
||
5980 | for(i=0;i<num;i = i+2){ |
||
5981 | ii = i+1; |
||
5982 | x = double_data[i] + affine_matrix[4]; |
||
5983 | y = double_data[ii] + affine_matrix[5]; |
||
5984 | double_data[i] = x; |
||
5985 | double_data[ii] = y; |
||
5986 | } |
||
5987 | } |
||
5988 | */ |
||
7614 | schaersvoo | 5989 | char *str_replace(const char *str, const char *old, const char *new){ |
5990 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
5991 | char *ret, *r; |
||
5992 | const char *p, *q; |
||
5993 | size_t oldlen = strlen(old); |
||
5994 | size_t count = 0; |
||
5995 | size_t retlen = 0; |
||
5996 | size_t newlen = strlen(new); |
||
5997 | if (oldlen != newlen){ |
||
5998 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
5999 | count++; |
||
6000 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
6001 | } |
||
8224 | bpr | 6002 | } |
7614 | schaersvoo | 6003 | else |
6004 | { |
||
6005 | retlen = strlen(str); |
||
6006 | } |
||
8224 | bpr | 6007 | |
7614 | schaersvoo | 6008 | if ((ret = malloc(retlen + 1)) == NULL){ |
6009 | ret = NULL; |
||
6010 | canvas_error("string argument is NULL"); |
||
6011 | } |
||
6012 | else |
||
6013 | { |
||
6014 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
6015 | size_t l = q - p; |
||
6016 | memcpy(r, p, l); |
||
6017 | r += l; |
||
6018 | memcpy(r, new, newlen); |
||
6019 | r += newlen; |
||
6020 | } |
||
6021 | strcpy(r, p); |
||
6022 | } |
||
6023 | return ret; |
||
6024 | } |
||
6025 | |||
6026 | /******************************************************************************/ |
||
7848 | bpr | 6027 | |
7614 | schaersvoo | 6028 | char *get_color(FILE *infile , int last){ |
6029 | int c,i = 0,is_hex = 0; |
||
6030 | char temp[MAX_COLOR_STRING], *string; |
||
8305 | schaersvoo | 6031 | const char *not_allowed = "0123456789"; |
10891 | schaersvoo | 6032 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) && ( c != '\t' ) ){ |
7614 | schaersvoo | 6033 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
6034 | if( c == '#' ){ |
||
6035 | is_hex = 1; |
||
6036 | } |
||
6037 | if( c != ' '){ |
||
8304 | schaersvoo | 6038 | 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 | 6039 | temp[i]=tolower(c); |
6040 | i++; |
||
6041 | } |
||
6042 | } |
||
10891 | schaersvoo | 6043 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
6044 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 6045 | if( c == EOF ){finished = 1;} |
6046 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
6047 | temp[i]='\0'; |
||
6048 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
6049 | if( is_hex == 1 ){ |
||
6050 | char red[3], green[3], blue[3]; |
||
6051 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
6052 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
6053 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
6054 | int r = (int) strtol(red, NULL, 16); |
||
6055 | int g = (int) strtol(green, NULL, 16); |
||
6056 | int b = (int) strtol(blue, NULL, 16); |
||
14408 | schaersvoo | 6057 | int L0 = 1+snprintf(NULL,0,"%d,%d,%d",r,g,b); |
6058 | string = my_newmem(L0); |
||
6059 | snprintf(string,L0,"%d,%d,%d",r,g,b); |
||
7614 | schaersvoo | 6060 | return string; |
6061 | } |
||
6062 | else |
||
6063 | { |
||
6064 | string = (char *)my_newmem(sizeof(temp)); |
||
6065 | snprintf(string,sizeof(temp),"%s",temp); |
||
8304 | schaersvoo | 6066 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
7614 | schaersvoo | 6067 | if( strcmp( colors[i].name , string ) == 0 ){ |
6068 | return colors[i].rgb; |
||
6069 | } |
||
6070 | } |
||
8304 | schaersvoo | 6071 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
7614 | schaersvoo | 6072 | } |
8304 | schaersvoo | 6073 | return "0,0,255"; |
7614 | schaersvoo | 6074 | } |
6075 | |||
14066 | bpr | 6076 | char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 6077 | int c,i=0; |
6078 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 6079 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){ |
7614 | schaersvoo | 6080 | temp[i]=c; |
6081 | i++; |
||
6082 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
6083 | } |
||
10891 | schaersvoo | 6084 | if( ( c == '\n' || c == '\t' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
6085 | if( c == '\n' || c == '\t') { done = TRUE; line_number++; } |
||
11022 | schaersvoo | 6086 | if( c == EOF ) {finished = 1;} |
7614 | schaersvoo | 6087 | temp[i]='\0'; |
11022 | schaersvoo | 6088 | if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");} |
7614 | schaersvoo | 6089 | string=(char *)my_newmem(strlen(temp)); |
6090 | snprintf(string,sizeof(temp),"%s",temp); |
||
6091 | return string; |
||
6092 | } |
||
6093 | |||
14066 | bpr | 6094 | char *get_string_argument(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 6095 | int c,i=0; |
6096 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 6097 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){ |
7614 | schaersvoo | 6098 | temp[i]=c; |
6099 | i++; |
||
6100 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
6101 | } |
||
8224 | bpr | 6102 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
10891 | schaersvoo | 6103 | if( c == '\n' || c == '\t' ) { line_number++; } |
7614 | schaersvoo | 6104 | if( c == EOF ) {finished = 1;} |
9478 | schaersvoo | 6105 | if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");} |
7614 | schaersvoo | 6106 | temp[i]='\0'; |
10953 | bpr | 6107 | /* |
8322 | schaersvoo | 6108 | 17.10.2014 removed (question Perrin) |
6109 | may cause some unwanted effects... |
||
14078 | bpr | 6110 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");} |
8322 | schaersvoo | 6111 | */ |
7614 | schaersvoo | 6112 | string=(char *)my_newmem(sizeof(temp)); |
6113 | snprintf(string,sizeof(temp),"%s",temp); |
||
6114 | done = TRUE; |
||
6115 | return string; |
||
6116 | } |
||
6117 | |||
14066 | bpr | 6118 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 6119 | int c,i=0,found_calc = 0; |
6120 | double y; |
||
6121 | char tmp[MAX_INT]; |
||
10953 | bpr | 6122 | /* |
14066 | bpr | 6123 | these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs |
8383 | schaersvoo | 6124 | but there should be a better way to avoid segfaults ! |
8348 | schaersvoo | 6125 | */ |
6126 | const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/ |
||
6127 | const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */ |
||
10891 | schaersvoo | 6128 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){ |
7614 | schaersvoo | 6129 | if( c != ' ' ){ |
8224 | bpr | 6130 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 6131 | continue; |
8224 | bpr | 6132 | } |
7614 | schaersvoo | 6133 | else |
6134 | { |
||
8304 | schaersvoo | 6135 | c = tolower(c); |
6136 | if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");} |
||
6137 | if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */ |
||
7614 | schaersvoo | 6138 | tmp[i] = c; |
6139 | i++; |
||
6140 | } |
||
6141 | } |
||
6142 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
6143 | } |
||
10891 | schaersvoo | 6144 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
6145 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 6146 | if( c == EOF ){done = TRUE ; finished = 1;} |
6147 | tmp[i]='\0'; |
||
15633 | bpr | 6148 | if( strlen(tmp) == 0 ){canvas_error("expected a number, but found nothing !!");} |
8304 | schaersvoo | 6149 | if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */ |
7848 | bpr | 6150 | void *f = eval_create(tmp); |
7614 | schaersvoo | 6151 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 6152 | y = eval_x(f, 1); |
14066 | bpr | 6153 | /* if function is bogus; y = 1: so no core dumps */ |
7848 | bpr | 6154 | eval_destroy(f); |
7614 | schaersvoo | 6155 | } |
6156 | else |
||
6157 | { |
||
6158 | y = atof(tmp); |
||
6159 | } |
||
6160 | return y; |
||
6161 | } |
||
8304 | schaersvoo | 6162 | |
13829 | bpr | 6163 | |
7614 | schaersvoo | 6164 | void canvas_error(char *msg){ |
14066 | bpr | 6165 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d: %s</span><hr />",line_number,msg); |
7614 | schaersvoo | 6166 | finished = 1; |
6167 | exit(EXIT_SUCCESS); |
||
6168 | } |
||
6169 | |||
6170 | |||
6171 | /* convert x/y coordinates to pixel */ |
||
6172 | int x2px(double x){ |
||
6173 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
6174 | } |
||
6175 | |||
6176 | int y2px(double y){ |
||
6177 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
6178 | } |
||
6179 | |||
6180 | double px2x(int x){ |
||
6181 | return (x*(xmax - xmin)/xsize + xmin); |
||
6182 | } |
||
6183 | double px2y(int y){ |
||
6184 | return (y*(ymax - ymin)/ysize + ymin); |
||
6185 | } |
||
6186 | |||
6187 | void add_to_buffer(char *tmp){ |
||
15111 | schaersvoo | 6188 | //fprintf(stdout,"tmp = %s<br />buffer = %s<br />",tmp,buffer); |
7614 | schaersvoo | 6189 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
6190 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
6191 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
6192 | if( space_left > strlen(tmp)){ |
||
6193 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
6194 | } |
||
6195 | else |
||
6196 | { |
||
15111 | schaersvoo | 6197 | canvas_error("your memory buffer is too big<br />simplify your script...it produces too many lines "); |
7614 | schaersvoo | 6198 | } |
6199 | tmp = NULL;free(tmp); |
||
6200 | return; |
||
6201 | } |
||
6202 | |||
6203 | void reset(){ |
||
15111 | schaersvoo | 6204 | if(no_reset == FALSE){ /* 8/5/2020 */ |
6205 | use_filled = FALSE; |
||
6206 | use_dashed = FALSE; |
||
6207 | if(onclick != 4 ){onclick = 0;} /* slider param 'active'... onclick=4 */ |
||
6208 | drag_type = -1; |
||
6209 | use_offset = 0; |
||
15601 | schaersvoo | 6210 | } |
7614 | schaersvoo | 6211 | } |
6212 | |||
15111 | schaersvoo | 6213 | char *getMML(char *tex){ |
6214 | int my_pipe[2];pid_t pid; |
||
6215 | if(pipe(my_pipe)){canvas_error("mathml(): pipe() failure.\n");} |
||
6216 | pid = fork(); |
||
6217 | if (pid == (pid_t) 0){ |
||
6218 | char *argv[]={"wims_mathml","--use-zoom","0","--tex-size 100%","--max-mml-size","1024","--tex-string",tex,NULL}; |
||
6219 | close(my_pipe[0]);dup2(my_pipe[1], 1);dup2(my_pipe[1], 2);close(my_pipe[1]); |
||
6220 | execv("../bin/wims_mathml",argv);canvas_error("could not execute wims_mathml\n"); |
||
6221 | } |
||
6222 | else |
||
15116 | bpr | 6223 | { |
15111 | schaersvoo | 6224 | if (pid < (pid_t) 0){ |
15116 | bpr | 6225 | close(my_pipe[0]);close(my_pipe[1]);canvas_error("mathml(): fork() failure.\n"); |
15111 | schaersvoo | 6226 | } |
6227 | int status;FILE *stream;close(my_pipe[1]);stream = fdopen (my_pipe[0], "r"); |
||
6228 | char buffer[MAX_BUFFER+1];memset(buffer,'\0',MAX_BUFFER); |
||
6229 | fgets(buffer, MAX_BUFFER, stream); |
||
6230 | int L0 = 1 + snprintf(NULL,0,"%s", buffer); |
||
6231 | tex = my_newmem(L0);memset(tex,'\0',L0); |
||
6232 | snprintf(tex,L0,"%s",buffer); |
||
15116 | bpr | 6233 | fclose (stream);close(my_pipe[0]);waitpid(pid, &status, 0); |
15111 | schaersvoo | 6234 | } |
6235 | return tex; |
||
6236 | } |
||
7614 | schaersvoo | 6237 | |
15111 | schaersvoo | 6238 | char *getSVGMOL(char *inputtype,char *keys){ |
6239 | int idx; |
||
6240 | char *forbidden[] = {"-O","-H","-z","-L","-o","-m"}; |
||
6241 | char *argv[1+strlen(keys)]; |
||
6242 | argv[0] = "obabel"; argv[1] = "-i"; argv[2] = inputtype; |
||
6243 | idx = 3;int i; |
||
6244 | char *ptr = strtok(keys,","); |
||
6245 | while(ptr != NULL ){ |
||
6246 | for(i = 0 ; i < 6; i++ ){if( strncmp(ptr,forbidden[i],2) == 0 ){return "NOT ALLOWED ARGUMENT";}} |
||
6247 | argv[idx] = ptr; idx++; |
||
6248 | if(idx > 18){canvas_error("too many arguments for obabel....see docs<br />");} |
||
6249 | ptr = strtok(NULL,","); |
||
6250 | } |
||
6251 | /* last arguments; no 'javascript', only 'svg to STDOUT' and 'NULL' */ |
||
6252 | argv[idx] = "-xj";argv[idx+1] = "-o"; argv[idx+2] = "svg";argv[idx+3] = NULL; |
||
6253 | int link[2]; |
||
6254 | pid_t pid; |
||
6255 | char buffer[MAX_BUFFER+1]; |
||
6256 | memset(buffer,'\0',MAX_BUFFER); |
||
6257 | if (pipe(link)==-1){canvas_error("pipe");} |
||
6258 | if ((pid = fork()) == -1){canvas_error("fork");} |
||
15116 | bpr | 6259 | |
15111 | schaersvoo | 6260 | char *svgmol = "error"; |
6261 | int string_length = 0; |
||
15116 | bpr | 6262 | |
15111 | schaersvoo | 6263 | if(pid == 0) { |
6264 | dup2 (link[1], STDOUT_FILENO); |
||
6265 | dup2(link[0], STDERR_FILENO);/* remove annoying messages '1 molecule converted' */ |
||
6266 | close(link[0]); |
||
6267 | close(link[1]); |
||
6268 | execvp("obabel",argv); |
||
6269 | } else { |
||
6270 | close(link[1]); |
||
6271 | read(link[0],buffer, 1+sizeof(buffer)); |
||
6272 | close(link[0]); |
||
6273 | /* need to remover newline from svg-string on freebsd */ |
||
6274 | char *pch = strstr(buffer, "\n"); |
||
6275 | while(pch != NULL){ |
||
6276 | strncpy(pch, " ", 1); |
||
6277 | pch = strstr(buffer, "\n"); |
||
6278 | } |
||
6279 | string_length = 1 + snprintf(NULL,0,"%s",buffer); |
||
6280 | svgmol= my_newmem(string_length); |
||
6281 | snprintf(svgmol,string_length,"%s",buffer); |
||
6282 | wait(NULL); |
||
6283 | } |
||
6284 | return svgmol; |
||
6285 | } |
||
7614 | schaersvoo | 6286 | |
6287 | |||
15111 | schaersvoo | 6288 | /* GNU libmatheval library for evaluating mathematical functions. */ |
15601 | schaersvoo | 6289 | char *eval(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double rotationcenter[]){ |
15111 | schaersvoo | 6290 | void *f; |
6291 | double x; |
||
6292 | double y; |
||
15601 | schaersvoo | 6293 | double xorg; |
15111 | schaersvoo | 6294 | int xv; |
6295 | int i = 0; |
||
6296 | int xstep =(int)(xsize/plotsteps); |
||
6297 | if( xstep == 0 ){xstep = 1;} |
||
6298 | double a = (xmax - xmin)/xsize; |
||
6299 | f = eval_create(fun); |
||
6300 | assert (f); |
||
6301 | if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
6302 | /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */ |
||
6303 | double xydata[MAX_BUFFER+1];/* hmmm */ |
||
6304 | int lim_ymin =(int)( ymin - 4*fabs(ymin));/* 19-4-2015 replacing "abs" by "fabs"*/ |
||
6305 | int lim_ymax =(int)( ymax + 4*fabs(ymax));/* 19-4-2015 replacing "abs" by "fabs"*/ |
||
15669 | schaersvoo | 6306 | double c = 1.0;double s = 1.0; |
15601 | schaersvoo | 6307 | if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);} |
15111 | schaersvoo | 6308 | for ( xv = 0 ;xv < xsize ; xv = xv+xstep ){ |
6309 | x = (double) (xv*a + xmin); |
||
15601 | schaersvoo | 6310 | xorg = x; |
15111 | schaersvoo | 6311 | if( i < MAX_BUFFER - 2){ |
6312 | y = eval_x(f, x); |
||
6313 | if(y < lim_ymax && y > lim_ymin ){ |
||
15540 | schaersvoo | 6314 | if( use_affine == TRUE ){ |
6315 | x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4]; |
||
15601 | schaersvoo | 6316 | y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5]; |
15540 | schaersvoo | 6317 | } |
15601 | schaersvoo | 6318 | if( use_rotate == TRUE){ |
6319 | x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0]; |
||
6320 | y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1]; |
||
6321 | } |
||
15111 | schaersvoo | 6322 | xydata[i++] = x; |
6323 | xydata[i++] = y; |
||
6324 | } |
||
6325 | } |
||
6326 | else |
||
6327 | { |
||
6328 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... "); |
||
6329 | } |
||
6330 | } |
||
6331 | eval_destroy(f); |
||
6332 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
6333 | } |
||
6334 | /* plot a very primitive (!) levelcurve : not to be compared with "flydraw levelcurve" */ |
||
6335 | char *eval_levelcurve(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double level){ |
||
6336 | void *f = eval_create(fun); |
||
6337 | assert (f); |
||
6338 | if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
6339 | double a = (double)((xmax - xmin)/plotsteps); |
||
6340 | double b = (double)((ymax - ymin)/plotsteps); |
||
15669 | schaersvoo | 6341 | double x;double y;double diff; |
15111 | schaersvoo | 6342 | double xydata[MAX_BUFFER+1]; |
6343 | int i = 0; |
||
6344 | ymin = ymin - 1; |
||
6345 | xmin = xmin - 1; |
||
6346 | ymax = ymax + 1; |
||
6347 | xmax = xmax + 1; |
||
6348 | for( x = xmin ;x < xmax ; x = x + a ){ |
||
6349 | for ( y = ymin ;y < ymax ; y = y + b ){ |
||
6350 | if( i < MAX_BUFFER - 2){ |
||
6351 | diff = level - eval_x_y(f, x,y); |
||
6352 | if(diff < 0.1 && diff > -0.1){ |
||
6353 | xydata[i++] = x; |
||
6354 | xydata[i++] = y; |
||
6355 | } |
||
6356 | } |
||
6357 | else |
||
6358 | { |
||
6359 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps, decrease image size...\nor some other means to reduce the amount of data... "); |
||
6360 | } |
||
6361 | } |
||
6362 | } |
||
6363 | eval_destroy(f); |
||
6364 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
6365 | } |
||
7614 | schaersvoo | 6366 | |
15111 | schaersvoo | 6367 | /* plot parametric function */ |
6368 | char *eval_parametric(int xsize,int ysize,char *fun1,char* fun2,double xmin,double xmax,double ymin,double ymax, |
||
15601 | schaersvoo | 6369 | double tmin,double tmax,int plotsteps,int precision,double rotationcenter[]){ |
15111 | schaersvoo | 6370 | void *fx; |
6371 | void *fy; |
||
6372 | double t; |
||
6373 | int i = 0; |
||
6374 | double tstep = (tmax-tmin)/plotsteps; |
||
6375 | if( tstep == 0 ){canvas_error("zero step for t variable : reduce plotsteps or inrease trange");} |
||
6376 | fx = eval_create(fun1); |
||
6377 | fy = eval_create(fun2); |
||
6378 | assert(fx); |
||
6379 | assert(fy); |
||
6380 | if( fx == NULL || fy == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
6381 | /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */ |
||
6382 | double xydata[MAX_BUFFER+1];/* hmmm */ |
||
6383 | double x; /* real x-values */ |
||
6384 | double y; /* real y-values */ |
||
15601 | schaersvoo | 6385 | double xorg; |
15623 | schaersvoo | 6386 | /* |
6387 | 29/12/2020 |
||
15633 | bpr | 6388 | disabled to try and synchronise curve+affine behaviour in complex scripts produced by "elec, tool circuit" (BPR) |
15623 | schaersvoo | 6389 | int lim_ymin =(int)( ymin - 4*fabs(ymin)); |
6390 | int lim_ymax =(int)( ymax + 4*fabs(ymax)); |
||
6391 | */ |
||
15669 | schaersvoo | 6392 | double c = 1.0;double s = 1.0;if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);} |
15111 | schaersvoo | 6393 | for( t = tmin ;t <= tmax ; t = t + tstep ){ |
6394 | if( i < MAX_BUFFER - 2 ){ |
||
6395 | y = eval_t(fy, t); |
||
15623 | schaersvoo | 6396 | /* if(y > lim_ymin && y < lim_ymax){*/ |
15111 | schaersvoo | 6397 | x = eval_t(fx, t); |
15628 | schaersvoo | 6398 | if( x == x){ /* no NaN */ |
6399 | xorg = x; |
||
6400 | if( use_affine == TRUE ){ |
||
6401 | x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4]; |
||
6402 | y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5]; |
||
6403 | } |
||
6404 | if( use_rotate == TRUE){ |
||
6405 | x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0]; |
||
6406 | y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1]; |
||
6407 | } |
||
6408 | xydata[i++] = x; |
||
6409 | xydata[i++] = y; |
||
15540 | schaersvoo | 6410 | } |
15629 | bpr | 6411 | |
15623 | schaersvoo | 6412 | /* } */ |
15111 | schaersvoo | 6413 | } |
6414 | else |
||
6415 | { |
||
6416 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... "); |
||
6417 | } |
||
6418 | } |
||
6419 | eval_destroy(fx); |
||
6420 | eval_destroy(fy); |
||
6421 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
6422 | } |
||
7614 | schaersvoo | 6423 | |
15111 | schaersvoo | 6424 | char *double_xy2js_array(double xy[],int len,int decimals){ |
6425 | /* |
||
6426 | 1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8] |
||
6427 | int xy[] is already checked for errors or overflow in "get_real()" |
||
6428 | just to be sure we double check the size of "temp" |
||
7614 | schaersvoo | 6429 | */ |
15111 | schaersvoo | 6430 | char temp[2*MAX_BUFFER], *string; |
6431 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6432 | memset(temp,'\0',2*MAX_BUFFER);/* clear memory */ |
||
6433 | int i;int space_left; |
||
6434 | temp[0] = '[';/* start js-array */ |
||
6435 | for(i = 0; i < len;i = i + 2){ /* x_points[] */ |
||
6436 | if(i == len - 2){sprintf(tmp, "%.*f",decimals, xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);} |
||
6437 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6438 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce your image size or plotsteps ");} |
||
6439 | } |
||
6440 | strncat(temp,"],[",4); /* close js x_values array and start new */ |
||
6441 | for(i = 1; i < len;i = i + 2){ /* y_points */ |
||
6442 | if(i == len - 1){ sprintf(tmp, "%.*f",decimals,xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);} |
||
6443 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6444 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce your image size or plotsteps");} |
||
6445 | } |
||
6446 | strncat(temp,"]",2); |
||
6447 | string=(char *)my_newmem(sizeof(temp)); |
||
6448 | snprintf(string,sizeof(temp),"%s",temp); |
||
6449 | return string; |
||
6450 | } |
||
7614 | schaersvoo | 6451 | |
15111 | schaersvoo | 6452 | char *list2js_array(char *list, char *s){/* abc:defg:hjiuy:qwer --> ["abc","defg","hjiuy","qwer"] */ |
6453 | #define MAX_ARG 128 |
||
15116 | bpr | 6454 | if( strlen(list)> MAX_ARG - 1){canvas_error("argument is too large (> 128)");} |
15111 | schaersvoo | 6455 | char tmp[MAX_ARG]; |
6456 | size_t p = 0; |
||
6457 | tmp[0] = '['; |
||
6458 | tmp[1] = '\"'; |
||
6459 | size_t t = 2; |
||
6460 | while(list[p] != '\0'){ |
||
6461 | if( list[p] == s[0] ){ |
||
6462 | tmp[t++]='\"';tmp[t++]=',';tmp[t++]='\"'; |
||
6463 | } |
||
6464 | else |
||
6465 | { |
||
6466 | tmp[t++] = list[p]; |
||
6467 | } |
||
6468 | p++; |
||
6469 | } |
||
6470 | tmp[t++]='\"';tmp[t++]=']';tmp[t++]= '\0'; |
||
6471 | char *js_array = (char *)my_newmem(sizeof(tmp)); |
||
6472 | snprintf(js_array,sizeof(tmp),"%s",tmp); |
||
6473 | return js_array; |
||
6474 | } |
||
7963 | schaersvoo | 6475 | |
15111 | schaersvoo | 6476 | char *xy2js_array(int xy[],int len){ |
6477 | /* |
||
6478 | 1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8] |
||
6479 | int xy[] is already checked for errors or overflow in "get_real()" |
||
6480 | just to be sure we double check the size of "temp" |
||
7614 | schaersvoo | 6481 | */ |
15111 | schaersvoo | 6482 | char temp[MAX_BUFFER], *string; |
6483 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6484 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
6485 | int i;int space_left; |
||
6486 | temp[0] = '[';/* start js-array */ |
||
6487 | for(i = 0; i < len;i = i + 2){ /* x_points[] */ |
||
6488 | if(i == len - 2){sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);} |
||
6489 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6490 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");} |
||
6491 | } |
||
6492 | strncat(temp,"],[",4); /* close js x_values array and start new */ |
||
6493 | for(i = 1; i < len;i = i + 2){ /* y_points */ |
||
6494 | if(i == len - 1){ sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);} |
||
6495 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6496 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data\nreduce image size or plotsteps \n");} |
||
6497 | } |
||
6498 | strncat(temp,"]",2); |
||
6499 | string=(char *)my_newmem(sizeof(temp)); |
||
6500 | snprintf(string,sizeof(temp),"%s",temp); |
||
6501 | return string; |
||
7614 | schaersvoo | 6502 | } |
6503 | |||
15111 | schaersvoo | 6504 | char *data2js_array(int data[],int len){ |
6505 | /* |
||
6506 | 1,2,3,4,5,6,7,8 --> [1,2,3,4,5,6,7,8] |
||
6507 | int data[] is already checked for errors or overflow in "get_real()" |
||
6508 | just to be sure we double check the size of "temp" |
||
7614 | schaersvoo | 6509 | */ |
15111 | schaersvoo | 6510 | char temp[MAX_BUFFER], *string; |
6511 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6512 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
6513 | int i;int space_left; |
||
6514 | temp[0] = '[';/* start js-array */ |
||
6515 | for(i = 0; i < len; i++){ |
||
6516 | if(i == len - 1){sprintf(tmp, "%d", data[i]);}else{sprintf(tmp, "%d,", data[i]);} |
||
6517 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6518 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");} |
||
6519 | } |
||
6520 | strncat(temp,"]",2); |
||
6521 | string=(char *)my_newmem(sizeof(temp)); |
||
6522 | snprintf(string,sizeof(temp),"%s",temp); |
||
6523 | return string; |
||
6524 | } |
||
7614 | schaersvoo | 6525 | |
15111 | schaersvoo | 6526 | char *doubledata2js_array(double data[],int len, int decimals){ |
6527 | /* |
||
15116 | bpr | 6528 | 1.4355,2.345353,3.3455 --> [1.44,2.35,3.35] |
15111 | schaersvoo | 6529 | double data[] is already checked for errors or overflow in "get_real()" |
6530 | just to be sure we double check the size of "temp" |
||
8448 | schaersvoo | 6531 | */ |
15111 | schaersvoo | 6532 | char temp[MAX_BUFFER], *string; |
6533 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6534 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
6535 | int i;int space_left; |
||
6536 | temp[0] = '[';/* start js-array */ |
||
6537 | for(i = 0; i < len; i++){ |
||
6538 | if(i == len - 1){sprintf(tmp, "%.*f",decimals,data[i]);}else{sprintf(tmp, "%.*f,",decimals,data[i]);} |
||
6539 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6540 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");} |
||
6541 | } |
||
6542 | strncat(temp,"]",2); |
||
6543 | string=(char *)my_newmem(sizeof(temp)); |
||
6544 | snprintf(string,sizeof(temp),"%s",temp); |
||
6545 | return string; |
||
6546 | } |
||
13829 | bpr | 6547 | |
8224 | bpr | 6548 | |
15111 | schaersvoo | 6549 | void *my_newmem(size_t size){ |
6550 | void *p; |
||
6551 | if((p = malloc(size +1)) == NULL){canvas_error("canvasdraw: ran out of memory\n");} |
||
6552 | return p; |
||
6553 | } |
||
8224 | bpr | 6554 | |
15111 | schaersvoo | 6555 | int find_number_of_digits(int i){ |
6556 | if(i < 0 ){ i = -1*i;} |
||
6557 | int digits = 0; |
||
6558 | while ( i > 0){ |
||
6559 | digits++; |
||
6560 | i = i/10; |
||
6561 | } |
||
6562 | return digits; |
||
6563 | } |
||
7645 | schaersvoo | 6564 | |
11830 | schaersvoo | 6565 | |
8224 | bpr | 6566 | |
6567 | |||
7614 | schaersvoo | 6568 | void check_string_length(int L){ |
9466 | schaersvoo | 6569 | if( L > MAX_BUFFER-1){ |
7614 | schaersvoo | 6570 | canvas_error("problem with your arguments to command..."); |
6571 | } |
||
6572 | return; |
||
6573 | } |
||
6574 | |||
6575 | int get_token(FILE *infile){ |
||
6576 | int c,i=0; |
||
6577 | char temp[MAX_INT], *input_type; |
||
6578 | char *line="line", |
||
6579 | *audio="audio", |
||
6580 | *blink="blink", |
||
6581 | *arrowhead="arrowhead", |
||
6582 | *crosshairsize="crosshairsize", |
||
6583 | *crosshair="crosshair", |
||
6584 | *crosshairs="crosshairs", |
||
6585 | *audioobject="audioobject", |
||
6586 | *style="style", |
||
6587 | *mouse="mouse", |
||
7991 | schaersvoo | 6588 | *mousex="mousex", |
6589 | *mousey="mousey", |
||
8071 | schaersvoo | 6590 | *mouse_display="display", |
6591 | *mouse_degree="mouse_degree", |
||
7614 | schaersvoo | 6592 | *userdraw="userdraw", |
6593 | *highlight="highlight", |
||
6594 | *http="http", |
||
6595 | *rays="rays", |
||
6596 | *dashtype="dashtype", |
||
6597 | *dashed="dashed", |
||
6598 | *filled="filled", |
||
6599 | *lattice="lattice", |
||
6600 | *parallel="parallel", |
||
6601 | *segment="segment", |
||
8299 | schaersvoo | 6602 | *segments="segments", |
7614 | schaersvoo | 6603 | *dsegment="dsegment", |
9374 | schaersvoo | 6604 | *dsegments="dsegments", |
7614 | schaersvoo | 6605 | *seg="seg", |
9383 | schaersvoo | 6606 | *segs="segs", |
7614 | schaersvoo | 6607 | *bgimage="bgimage", |
6608 | *bgcolor="bgcolor", |
||
6609 | *strokecolor="strokecolor", |
||
6610 | *backgroundimage="backgroundimage", |
||
6611 | *text="text", |
||
6612 | *textup="textup", |
||
6613 | *mouseprecision="mouseprecision", |
||
6614 | *precision="precision", |
||
6615 | *plotsteps="plotsteps", |
||
6616 | *plotstep="plotstep", |
||
6617 | *tsteps="tsteps", |
||
6618 | *curve="curve", |
||
6619 | *dcurve="dcurve", |
||
14038 | schaersvoo | 6620 | *curvedarrow="curvedarrow", |
6621 | *curvedarrows="curvedarrows", |
||
6622 | *curvedarrow2="curvedarrow2", |
||
6623 | *curvedarrows2="curvedarrows2", |
||
7614 | schaersvoo | 6624 | *plot="plot", |
6625 | *dplot="dplot", |
||
7788 | schaersvoo | 6626 | *levelcurve="levelcurve", |
7614 | schaersvoo | 6627 | *fontsize="fontsize", |
6628 | *fontcolor="fontcolor", |
||
6629 | *axis="axis", |
||
6630 | *axisnumbering="axisnumbering", |
||
6631 | *axisnumbers="axisnumbers", |
||
6632 | *arrow="arrow", |
||
9382 | schaersvoo | 6633 | *vector="vector", |
6634 | *vectors="vectors", |
||
7614 | schaersvoo | 6635 | *darrow="darrow", |
6636 | *arrow2="arrow2", |
||
6637 | *darrow2="darrow2", |
||
8304 | schaersvoo | 6638 | *arrows="arrows", |
8347 | schaersvoo | 6639 | *arrows2="arrows2", |
7614 | schaersvoo | 6640 | *zoom="zoom", |
6641 | *grid="grid", |
||
6642 | *hline="hline", |
||
7786 | schaersvoo | 6643 | *dhline="dhline", |
7614 | schaersvoo | 6644 | *drag="drag", |
6645 | *horizontalline="horizontalline", |
||
9383 | schaersvoo | 6646 | *horizontallines="horizontallines", |
7614 | schaersvoo | 6647 | *vline="vline", |
7786 | schaersvoo | 6648 | *dvline="dvline", |
7614 | schaersvoo | 6649 | *verticalline="verticalline", |
9383 | schaersvoo | 6650 | *verticallines="verticallines", |
7614 | schaersvoo | 6651 | *triangle="triangle", |
9306 | schaersvoo | 6652 | *triangles="triangles", |
7614 | schaersvoo | 6653 | *ftriangle="ftriangle", |
9374 | schaersvoo | 6654 | *ftriangles="ftriangles", |
7614 | schaersvoo | 6655 | *mathml="mathml", |
6656 | *html="html", |
||
6657 | *input="input", |
||
8146 | schaersvoo | 6658 | *clearbutton="clearbutton", |
9386 | schaersvoo | 6659 | *erase="erase", |
6660 | *delete="delete", |
||
15111 | schaersvoo | 6661 | *css="css", |
7614 | schaersvoo | 6662 | *textarea="textarea", |
6663 | *trange="trange", |
||
6664 | *ranget="ranget", |
||
6665 | *xrange="xrange", |
||
6666 | *yrange="yrange", |
||
6667 | *rangex="rangex", |
||
6668 | *rangey="rangey", |
||
8370 | schaersvoo | 6669 | *path="path", |
7614 | schaersvoo | 6670 | *polyline="polyline", |
8351 | schaersvoo | 6671 | *brokenline="brokenline", |
7614 | schaersvoo | 6672 | *lines="lines", |
6673 | *poly="poly", |
||
6674 | *polygon="polygon", |
||
6675 | *fpolygon="fpolygon", |
||
6676 | *fpoly="fpoly", |
||
6677 | *filledpoly="filledpoly", |
||
6678 | *filledpolygon="filledpolygon", |
||
6679 | *rect="rect", |
||
6680 | *frect="frect", |
||
6681 | *rectangle="rectangle", |
||
6682 | *frectangle="frectangle", |
||
6683 | *square="square", |
||
6684 | *fsquare="fsquare", |
||
9374 | schaersvoo | 6685 | *fsquares="fsquares", |
8363 | schaersvoo | 6686 | *rects="rects", |
6687 | *frects="frects", |
||
7614 | schaersvoo | 6688 | *dline="dline", |
6689 | *arc="arc", |
||
6690 | *filledarc="filledarc", |
||
9374 | schaersvoo | 6691 | *farc="farc", |
7614 | schaersvoo | 6692 | *size="size", |
6693 | *string="string", |
||
6694 | *stringup="stringup", |
||
6695 | *copy="copy", |
||
6696 | *copyresized="copyresized", |
||
6697 | *opacity="opacity", |
||
6698 | *transparent="transparent", |
||
6699 | *fill="fill", |
||
6700 | *point="point", |
||
6701 | *points="points", |
||
6702 | *linewidth="linewidth", |
||
6703 | *circle="circle", |
||
8304 | schaersvoo | 6704 | *circles="circles", |
7614 | schaersvoo | 6705 | *fcircle="fcircle", |
9374 | schaersvoo | 6706 | *fcircles="fcircles", |
7614 | schaersvoo | 6707 | *disk="disk", |
9374 | schaersvoo | 6708 | *disks="disks", |
7614 | schaersvoo | 6709 | *comment="#", |
6710 | *end="end", |
||
6711 | *ellipse="ellipse", |
||
12110 | schaersvoo | 6712 | *ellipses="ellipses", |
7614 | schaersvoo | 6713 | *fellipse="fellipse", |
6714 | *rotate="rotate", |
||
7785 | schaersvoo | 6715 | *affine="affine", |
9907 | schaersvoo | 6716 | *rotationcenter="rotationcenter", |
6717 | *killrotate="killrotate", |
||
7785 | schaersvoo | 6718 | *killaffine="killaffine", |
15111 | schaersvoo | 6719 | *killlinear="killlinear", |
6720 | *killinear="killinear", |
||
7614 | schaersvoo | 6721 | *fontfamily="fontfamily", |
6722 | *fillcolor="fillcolor", |
||
6723 | *clicktile="clicktile", |
||
6724 | *clicktile_colors="clicktile_colors", |
||
6725 | *translation="translation", |
||
6726 | *translate="translate", |
||
6727 | *killtranslation="killtranslation", |
||
6728 | *killtranslate="killtranslate", |
||
6729 | *onclick="onclick", |
||
8370 | schaersvoo | 6730 | *roundrects="roundrects", |
7614 | schaersvoo | 6731 | *roundrect="roundrect", |
6732 | *froundrect="froundrect", |
||
9374 | schaersvoo | 6733 | *froundrects="froundrects", |
7614 | schaersvoo | 6734 | *roundrectangle="roundrectangle", |
6735 | *patternfill="patternfill", |
||
6736 | *hatchfill="hatchfill", |
||
6737 | *diafill="diafill", |
||
7647 | schaersvoo | 6738 | *diamondfill="diamondfill", |
7614 | schaersvoo | 6739 | *dotfill="dotfill", |
11830 | schaersvoo | 6740 | *textfill="textfill", |
7614 | schaersvoo | 6741 | *gridfill="gridfill", |
6742 | *imagefill="imagefill", |
||
7735 | schaersvoo | 6743 | *xlogbase="xlogbase", |
6744 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 6745 | *xlogscale="xlogscale", |
6746 | *ylogscale="ylogscale", |
||
6747 | *xylogscale="xylogscale", |
||
6748 | *intooltip="intooltip", |
||
9329 | schaersvoo | 6749 | *popup="popup", |
7614 | schaersvoo | 6750 | *replyformat="replyformat", |
6751 | *floodfill="floodfill", |
||
11772 | schaersvoo | 6752 | *fillall="fillall", |
7614 | schaersvoo | 6753 | *filltoborder="filltoborder", |
6754 | *setpixel="setpixel", |
||
6755 | *pixels="pixels", |
||
6756 | *pixelsize="pixelsize", |
||
6757 | *xaxis="xaxis", |
||
9341 | schaersvoo | 6758 | *xaxisup="xaxisup", |
7614 | schaersvoo | 6759 | *yaxis="yaxis", |
6760 | *xaxistext="xaxistext", |
||
9341 | schaersvoo | 6761 | *xaxistextup="xaxistextup", |
7614 | schaersvoo | 6762 | *yaxistext="yaxistext", |
6763 | *piechart="piechart", |
||
9433 | schaersvoo | 6764 | *boxplot="boxplot", |
9465 | schaersvoo | 6765 | *boxplotdata="boxplotdata", |
6766 | *userboxplot="userboxplot", |
||
6767 | *userboxplotdata="userboxplotdata", |
||
7614 | schaersvoo | 6768 | *legend="legend", |
6769 | *legendcolors="legendcolors", |
||
6770 | *xlabel="xlabel", |
||
6771 | *ylabel="ylabel", |
||
6772 | *barchart="barchart", |
||
6773 | *linegraph="linegraph", |
||
6774 | *clock="clock", |
||
6775 | *animate="animate", |
||
6776 | *video="video", |
||
6777 | *status="status", |
||
7877 | schaersvoo | 6778 | *nostatus="nostatus", |
7652 | schaersvoo | 6779 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 6780 | *xsnaptogrid="xsnaptogrid", |
6781 | *ysnaptogrid="ysnaptogrid", |
||
8379 | schaersvoo | 6782 | *snaptopoints="snaptopoints", |
9213 | schaersvoo | 6783 | *snaptofunction="snaptofunction", |
6784 | *snaptofun="snaptofun", |
||
7654 | schaersvoo | 6785 | *userinput_xy="userinput_xy", |
8193 | schaersvoo | 6786 | *userinput_function="userinput_function", |
8222 | schaersvoo | 6787 | *userinput="userinput", |
7823 | schaersvoo | 6788 | *jsmath="jsmath", |
7858 | schaersvoo | 6789 | *trace_jscurve="trace_jscurve", |
7838 | schaersvoo | 6790 | *setlimits="setlimits", |
7858 | schaersvoo | 6791 | *jscurve="jscurve", |
6792 | *jsplot="jsplot", |
||
7983 | schaersvoo | 6793 | *sgraph="sgraph", |
7984 | schaersvoo | 6794 | *title="title", |
7996 | schaersvoo | 6795 | *centerstring="centerstring", |
6796 | *xunit="xunit", |
||
8071 | schaersvoo | 6797 | *yunit="yunit", |
8101 | schaersvoo | 6798 | *slider="slider", |
8105 | schaersvoo | 6799 | *killslider="killslider", |
8244 | schaersvoo | 6800 | *angle="angle", |
8365 | schaersvoo | 6801 | *halflines="halflines", |
6802 | *demilines="demilines", |
||
8244 | schaersvoo | 6803 | *halfline="halfline", |
8297 | schaersvoo | 6804 | *demiline="demiline", |
8366 | schaersvoo | 6805 | *hlines="hlines", |
6806 | *vlines="vlines", |
||
8370 | schaersvoo | 6807 | *bezier="bezier", |
9213 | schaersvoo | 6808 | *functionlabel="functionlabel", |
15313 | schaersvoo | 6809 | *functionlabels="functionlabels", |
9213 | schaersvoo | 6810 | *sliderfunction_x="sliderfunction_x", |
6811 | *sliderfunction_y="sliderfunction_y", |
||
6812 | *multidraw="multidraw", |
||
15111 | schaersvoo | 6813 | *multilinewidth="multilinewidth", |
14622 | schaersvoo | 6814 | *linewidths="linewidths", |
9213 | schaersvoo | 6815 | *multistrokecolors="multistrokecolors", |
15111 | schaersvoo | 6816 | *multicolors="multicolors", |
6817 | *strokecolors="strokecolors", |
||
14622 | schaersvoo | 6818 | *colors="colors", |
9213 | schaersvoo | 6819 | *multifillcolors="multifillcolors", |
14622 | schaersvoo | 6820 | *fillcolors="fillcolors", |
9213 | schaersvoo | 6821 | *multistrokeopacity="multistrokeopacity", |
6822 | *multifillopacity="multifillopacity", |
||
6823 | *multifill="multifill", |
||
6824 | *multidash="multidash", |
||
6825 | *multilabel="multilabel", |
||
6826 | *multiuserinput="multiuserinput", |
||
14038 | schaersvoo | 6827 | *multiinput="multiinput", |
9289 | schaersvoo | 6828 | *multisnaptogrid="multisnaptogrid", |
14038 | schaersvoo | 6829 | *multisnap="multisnap", |
9289 | schaersvoo | 6830 | *protractor="protractor", |
9386 | schaersvoo | 6831 | *ruler="ruler", |
6832 | *cursor="cursor", |
||
9427 | schaersvoo | 6833 | *pointer="pointer", |
6834 | *yerrorbars="yerrorbars", |
||
11006 | schaersvoo | 6835 | *xerrorbars="xerrorbars", |
11044 | schaersvoo | 6836 | *noxaxis="noxaxis", |
6837 | *noyaxis="noyaxis", |
||
11767 | schaersvoo | 6838 | *colorpalette="colorpalette", |
14038 | schaersvoo | 6839 | *imagepalette="imagepalette", |
12063 | schaersvoo | 6840 | *yoffset="yoffset", |
11802 | schaersvoo | 6841 | *xoffset="xoffset", |
14225 | schaersvoo | 6842 | *latex="latex", |
15111 | schaersvoo | 6843 | *katex="katex", |
6844 | *math="math", |
||
11802 | schaersvoo | 6845 | *centered="centered", |
6846 | *xyoffset="xyoffset", |
||
6847 | *resetoffset="resetoffset", |
||
11837 | schaersvoo | 6848 | *fillpattern="fillpattern", |
15601 | schaersvoo | 6849 | *settile="settile", |
11890 | schaersvoo | 6850 | *numberline="numberline", |
14393 | schaersvoo | 6851 | *duplicates="duplicates", |
6852 | *allowdups="allowdups", |
||
15111 | schaersvoo | 6853 | *linear="linear", |
6854 | *obabel="obabel", |
||
6855 | *chemtex="chemtex", |
||
6856 | *noreset="noreset", |
||
6857 | *killreset="killreset", |
||
11006 | schaersvoo | 6858 | *canvastype="canvastype"; |
7614 | schaersvoo | 6859 | |
10891 | schaersvoo | 6860 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){ |
6861 | if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */ |
||
6862 | }else{ |
||
6863 | if( c == ' ' ){ |
||
7614 | schaersvoo | 6864 | break; |
10891 | schaersvoo | 6865 | }else{ |
6866 | temp[i] = c; |
||
6867 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
6868 | i++; |
||
6869 | } |
||
6870 | } |
||
6871 | if(temp[0] == '#'){ break; } |
||
7614 | schaersvoo | 6872 | } |
10891 | schaersvoo | 6873 | if (c == '\n' || c == '\r' || c == '\t' ){ line_number++; } |
6874 | if (c == EOF) {finished=1;return 0;} |
||
7614 | schaersvoo | 6875 | |
6876 | temp[i]='\0'; |
||
6877 | input_type=(char*)my_newmem(strlen(temp)); |
||
6878 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
10891 | schaersvoo | 6879 | /* fprintf(stdout,"temp = %s <br/>",input_type); */ |
7614 | schaersvoo | 6880 | if( strcmp(input_type, size) == 0 ){ |
6881 | free(input_type); |
||
6882 | return SIZE; |
||
6883 | } |
||
6884 | if( strcmp(input_type, xrange) == 0 ){ |
||
6885 | free(input_type); |
||
6886 | return XRANGE; |
||
6887 | } |
||
6888 | if( strcmp(input_type, rangex) == 0 ){ |
||
6889 | free(input_type); |
||
6890 | return XRANGE; |
||
6891 | } |
||
6892 | if( strcmp(input_type, trange) == 0 ){ |
||
6893 | free(input_type); |
||
6894 | return TRANGE; |
||
6895 | } |
||
6896 | if( strcmp(input_type, ranget) == 0 ){ |
||
6897 | free(input_type); |
||
6898 | return TRANGE; |
||
6899 | } |
||
6900 | if( strcmp(input_type, yrange) == 0 ){ |
||
6901 | free(input_type); |
||
6902 | return YRANGE; |
||
6903 | } |
||
6904 | if( strcmp(input_type, rangey) == 0 ){ |
||
6905 | free(input_type); |
||
6906 | return YRANGE; |
||
6907 | } |
||
6908 | if( strcmp(input_type, linewidth) == 0 ){ |
||
6909 | free(input_type); |
||
6910 | return LINEWIDTH; |
||
6911 | } |
||
6912 | if( strcmp(input_type, dashed) == 0 ){ |
||
6913 | free(input_type); |
||
6914 | return DASHED; |
||
6915 | } |
||
6916 | if( strcmp(input_type, dashtype) == 0 ){ |
||
6917 | free(input_type); |
||
6918 | return DASHTYPE; |
||
6919 | } |
||
6920 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
6921 | free(input_type); |
||
6922 | return AXIS_NUMBERING; |
||
6923 | } |
||
6924 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
6925 | free(input_type); |
||
6926 | return AXIS_NUMBERING; |
||
6927 | } |
||
6928 | if( strcmp(input_type, axis) == 0 ){ |
||
6929 | free(input_type); |
||
6930 | return AXIS; |
||
6931 | } |
||
6932 | if( strcmp(input_type, grid) == 0 ){ |
||
6933 | free(input_type); |
||
6934 | return GRID; |
||
6935 | } |
||
9383 | schaersvoo | 6936 | if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){ |
8366 | schaersvoo | 6937 | free(input_type); |
6938 | return HLINES; |
||
6939 | } |
||
9383 | schaersvoo | 6940 | if( strcmp(input_type, vlines) == 0 || strcmp(input_type, verticallines) == 0 ){ |
8366 | schaersvoo | 6941 | free(input_type); |
6942 | return VLINES; |
||
6943 | } |
||
9383 | schaersvoo | 6944 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
7614 | schaersvoo | 6945 | free(input_type); |
6946 | return HLINE; |
||
6947 | } |
||
6948 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
6949 | free(input_type); |
||
6950 | return VLINE; |
||
6951 | } |
||
6952 | if( strcmp(input_type, line) == 0 ){ |
||
6953 | free(input_type); |
||
6954 | return LINE; |
||
6955 | } |
||
9383 | schaersvoo | 6956 | if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){ |
8299 | schaersvoo | 6957 | free(input_type); |
6958 | return SEGMENTS; |
||
6959 | } |
||
7614 | schaersvoo | 6960 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
6961 | free(input_type); |
||
6962 | return SEGMENT; |
||
6963 | } |
||
9374 | schaersvoo | 6964 | if( strcmp(input_type, dsegments) == 0 ){ |
6965 | free(input_type); |
||
6966 | use_dashed = TRUE; |
||
6967 | return SEGMENTS; |
||
6968 | } |
||
7614 | schaersvoo | 6969 | if( strcmp(input_type, dsegment) == 0 ){ |
6970 | free(input_type); |
||
6971 | use_dashed = TRUE; |
||
6972 | return SEGMENT; |
||
6973 | } |
||
6974 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
6975 | free(input_type); |
||
6976 | return CROSSHAIRSIZE; |
||
6977 | } |
||
6978 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
6979 | free(input_type); |
||
6980 | return ARROWHEAD; |
||
6981 | } |
||
6982 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
6983 | free(input_type); |
||
6984 | return CROSSHAIRS; |
||
6985 | } |
||
6986 | if( strcmp(input_type, crosshair) == 0 ){ |
||
6987 | free(input_type); |
||
6988 | return CROSSHAIR; |
||
6989 | } |
||
6990 | if( strcmp(input_type, onclick) == 0 ){ |
||
6991 | free(input_type); |
||
6992 | return ONCLICK; |
||
6993 | } |
||
6994 | if( strcmp(input_type, drag) == 0 ){ |
||
6995 | free(input_type); |
||
6996 | return DRAG; |
||
6997 | } |
||
6998 | if( strcmp(input_type, userdraw) == 0 ){ |
||
6999 | free(input_type); |
||
7000 | return USERDRAW; |
||
7001 | } |
||
7002 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
7003 | free(input_type); |
||
7004 | return STYLE; |
||
7005 | } |
||
7006 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
7007 | free(input_type); |
||
7008 | return FILLCOLOR; |
||
7009 | } |
||
7010 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
7011 | free(input_type); |
||
7012 | return STROKECOLOR; |
||
7013 | } |
||
15111 | schaersvoo | 7014 | if( strcmp(input_type, filled) == 0 ){ |
7614 | schaersvoo | 7015 | free(input_type); |
7016 | return FILLED; |
||
7017 | } |
||
7018 | if( strcmp(input_type, http) == 0 ){ |
||
7019 | free(input_type); |
||
7020 | return HTTP; |
||
7021 | } |
||
7022 | if( strcmp(input_type, rays) == 0 ){ |
||
7023 | free(input_type); |
||
7024 | return RAYS; |
||
7025 | } |
||
7026 | if( strcmp(input_type, lattice) == 0 ){ |
||
7027 | free(input_type); |
||
7028 | return LATTICE; |
||
7029 | } |
||
7030 | if( strcmp(input_type, bgimage) == 0 ){ |
||
7031 | free(input_type); |
||
7032 | return BGIMAGE; |
||
7033 | } |
||
7034 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
7035 | free(input_type); |
||
7036 | return BGCOLOR; |
||
7037 | } |
||
7038 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
7039 | free(input_type); |
||
7040 | return BGIMAGE; |
||
7041 | } |
||
7042 | if( strcmp(input_type, text) == 0 ){ |
||
7043 | free(input_type); |
||
7044 | return FLY_TEXT; |
||
7045 | } |
||
7046 | if( strcmp(input_type, textup) == 0 ){ |
||
7047 | free(input_type); |
||
7048 | return FLY_TEXTUP; |
||
7049 | } |
||
7050 | if( strcmp(input_type, mouse) == 0 ){ |
||
7051 | free(input_type); |
||
7052 | return MOUSE; |
||
7053 | } |
||
7991 | schaersvoo | 7054 | if( strcmp(input_type, mousex) == 0 ){ |
7055 | free(input_type); |
||
7056 | return MOUSEX; |
||
7057 | } |
||
7058 | if( strcmp(input_type, mousey) == 0 ){ |
||
7059 | free(input_type); |
||
7060 | return MOUSEY; |
||
7061 | } |
||
8071 | schaersvoo | 7062 | if( strcmp(input_type, mouse_degree) == 0 ){ |
7063 | free(input_type); |
||
7064 | return MOUSE_DEGREE; |
||
7065 | } |
||
7066 | if( strcmp(input_type, mouse_display) == 0 ){ |
||
7067 | free(input_type); |
||
7068 | return MOUSE_DISPLAY; |
||
7069 | } |
||
7614 | schaersvoo | 7070 | if( strcmp(input_type, mouseprecision) == 0 ){ |
7071 | free(input_type); |
||
7072 | return MOUSE_PRECISION; |
||
7073 | } |
||
7074 | if( strcmp(input_type, precision) == 0 ){ |
||
7075 | free(input_type); |
||
7076 | return MOUSE_PRECISION; |
||
7077 | } |
||
7078 | if( strcmp(input_type, curve) == 0 ){ |
||
7079 | free(input_type); |
||
7080 | return CURVE; |
||
7081 | } |
||
7082 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 7083 | use_dashed = TRUE; |
7614 | schaersvoo | 7084 | free(input_type); |
7085 | return CURVE; |
||
7086 | } |
||
7087 | if( strcmp(input_type, plot) == 0 ){ |
||
7088 | free(input_type); |
||
7089 | return CURVE; |
||
7090 | } |
||
7091 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 7092 | use_dashed = TRUE; |
7614 | schaersvoo | 7093 | free(input_type); |
7094 | return CURVE; |
||
7095 | } |
||
7788 | schaersvoo | 7096 | if( strcmp(input_type, levelcurve) == 0 ){ |
7097 | free(input_type); |
||
7098 | return LEVELCURVE; |
||
7099 | } |
||
7614 | schaersvoo | 7100 | if( strcmp(input_type, plotsteps) == 0 ){ |
7101 | free(input_type); |
||
7102 | return PLOTSTEPS; |
||
7103 | } |
||
7104 | if( strcmp(input_type, plotstep) == 0 ){ |
||
7105 | free(input_type); |
||
7106 | return PLOTSTEPS; |
||
7107 | } |
||
7108 | if( strcmp(input_type, tsteps) == 0 ){ |
||
7109 | free(input_type); |
||
7110 | return PLOTSTEPS; |
||
7111 | } |
||
7112 | if( strcmp(input_type, fontsize) == 0 ){ |
||
7113 | free(input_type); |
||
7114 | return FONTSIZE; |
||
7115 | } |
||
7116 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
7117 | free(input_type); |
||
7118 | return FONTCOLOR; |
||
7119 | } |
||
7120 | if( strcmp(input_type, arrow2) == 0 ){ |
||
7121 | free(input_type); |
||
7122 | return ARROW2; |
||
7123 | } |
||
7124 | if( strcmp(input_type, darrow) == 0 ){ |
||
7125 | free(input_type); |
||
8071 | schaersvoo | 7126 | use_dashed = TRUE; |
7614 | schaersvoo | 7127 | return ARROW; |
7128 | } |
||
7129 | if( strcmp(input_type, darrow2) == 0 ){ |
||
7130 | free(input_type); |
||
7131 | use_dashed = TRUE; |
||
7132 | return ARROW2; |
||
7133 | } |
||
8347 | schaersvoo | 7134 | if( strcmp(input_type, arrows2) == 0 ){ |
7135 | free(input_type); |
||
7136 | return ARROWS2; |
||
7137 | } |
||
9382 | schaersvoo | 7138 | if( strcmp(input_type, arrows) == 0 || strcmp(input_type, vectors) == 0 ){ |
8304 | schaersvoo | 7139 | free(input_type); |
7140 | return ARROWS; |
||
7141 | } |
||
9382 | schaersvoo | 7142 | if( strcmp(input_type, arrow) == 0 || strcmp(input_type, vector) == 0 ){ |
8304 | schaersvoo | 7143 | free(input_type); |
7144 | return ARROW; |
||
7145 | } |
||
7614 | schaersvoo | 7146 | if( strcmp(input_type, zoom) == 0 ){ |
7147 | free(input_type); |
||
7148 | return ZOOM; |
||
7149 | } |
||
7150 | if( strcmp(input_type, triangle) == 0 ){ |
||
7151 | free(input_type); |
||
7152 | return TRIANGLE; |
||
7153 | } |
||
9306 | schaersvoo | 7154 | if( strcmp(input_type, triangles) == 0 ){ |
7155 | free(input_type); |
||
7156 | return TRIANGLES; |
||
7157 | } |
||
9374 | schaersvoo | 7158 | if( strcmp(input_type, ftriangles) == 0 ){ |
7159 | free(input_type); |
||
7160 | use_filled = TRUE; |
||
7161 | return TRIANGLES; |
||
7162 | } |
||
7614 | schaersvoo | 7163 | if( strcmp(input_type, ftriangle) == 0 ){ |
7164 | free(input_type); |
||
7165 | use_filled = TRUE; |
||
7166 | return TRIANGLE; |
||
7167 | } |
||
7168 | if( strcmp(input_type, input) == 0 ){ |
||
7169 | free(input_type); |
||
7170 | return INPUT; |
||
7171 | } |
||
15111 | schaersvoo | 7172 | if( strcmp(input_type, css) == 0 ){ |
7614 | schaersvoo | 7173 | free(input_type); |
15111 | schaersvoo | 7174 | return CSS; |
7614 | schaersvoo | 7175 | } |
7176 | if( strcmp(input_type, textarea) == 0 ){ |
||
7177 | free(input_type); |
||
7178 | return TEXTAREA; |
||
7179 | } |
||
7180 | if( strcmp(input_type, mathml) == 0 ){ |
||
7181 | free(input_type); |
||
7182 | return MATHML; |
||
7183 | } |
||
7184 | if( strcmp(input_type, html) == 0 ){ |
||
7185 | free(input_type); |
||
15111 | schaersvoo | 7186 | return HTML; |
7614 | schaersvoo | 7187 | } |
7188 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
7189 | free(input_type); |
||
7190 | return FONTFAMILY; |
||
7191 | } |
||
10975 | schaersvoo | 7192 | if( strcmp(input_type, polyline) == 0 || strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){ |
7614 | schaersvoo | 7193 | free(input_type); |
7194 | return POLYLINE; |
||
7195 | } |
||
8351 | schaersvoo | 7196 | if( strcmp(input_type, lines) == 0 ){ |
7197 | free(input_type); |
||
7198 | return LINES; |
||
7199 | } |
||
9374 | schaersvoo | 7200 | if( strcmp(input_type, rects) == 0){ |
8363 | schaersvoo | 7201 | free(input_type); |
7202 | return RECTS; |
||
7203 | } |
||
9383 | schaersvoo | 7204 | if( strcmp(input_type, frects) == 0 ){ |
8363 | schaersvoo | 7205 | free(input_type); |
9374 | schaersvoo | 7206 | use_filled = TRUE; |
8363 | schaersvoo | 7207 | return RECTS; |
7208 | } |
||
7614 | schaersvoo | 7209 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
7210 | free(input_type); |
||
7211 | return RECT; |
||
7212 | } |
||
9374 | schaersvoo | 7213 | if( strcmp(input_type, square) == 0 ){ |
7214 | free(input_type); |
||
11991 | schaersvoo | 7215 | return SQUARE; |
9374 | schaersvoo | 7216 | } |
7217 | if( strcmp(input_type, fsquare) == 0 ){ |
||
7218 | free(input_type); |
||
7219 | use_filled = TRUE; |
||
7220 | return SQUARE; |
||
7221 | } |
||
7222 | if( strcmp(input_type, fsquares) == 0 ){ |
||
7223 | free(input_type); |
||
7224 | use_filled = TRUE; |
||
7225 | return RECTS; |
||
7226 | } |
||
8370 | schaersvoo | 7227 | if( strcmp(input_type, roundrects) == 0 ){ |
7228 | free(input_type); |
||
7229 | return ROUNDRECTS; |
||
7230 | } |
||
7614 | schaersvoo | 7231 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
7232 | free(input_type); |
||
7233 | return ROUNDRECT; |
||
7234 | } |
||
9374 | schaersvoo | 7235 | if( strcmp(input_type, froundrects) == 0 ){ |
7614 | schaersvoo | 7236 | free(input_type); |
7237 | use_filled = TRUE; |
||
9374 | schaersvoo | 7238 | return ROUNDRECTS; |
7614 | schaersvoo | 7239 | } |
9374 | schaersvoo | 7240 | if( strcmp(input_type, froundrect) == 0 ){ |
7614 | schaersvoo | 7241 | free(input_type); |
7242 | use_filled = TRUE; |
||
9374 | schaersvoo | 7243 | return ROUNDRECT; |
7614 | schaersvoo | 7244 | } |
7245 | if( strcmp(input_type, dline) == 0 ){ |
||
7246 | use_dashed = TRUE; |
||
7247 | free(input_type); |
||
7248 | return LINE; |
||
7249 | } |
||
7786 | schaersvoo | 7250 | if( strcmp(input_type, dvline) == 0 ){ |
7251 | use_dashed = TRUE; |
||
7252 | free(input_type); |
||
7253 | return VLINE; |
||
7254 | } |
||
7255 | if( strcmp(input_type, dhline) == 0 ){ |
||
7256 | use_dashed = TRUE; |
||
7257 | free(input_type); |
||
7258 | return HLINE; |
||
7259 | } |
||
15111 | schaersvoo | 7260 | if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0 ){ |
9386 | schaersvoo | 7261 | free(input_type); |
7262 | return HALFLINES; |
||
7263 | } |
||
15111 | schaersvoo | 7264 | if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){ |
9386 | schaersvoo | 7265 | free(input_type); |
7266 | return HALFLINE; |
||
7267 | } |
||
7614 | schaersvoo | 7268 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
7269 | use_filled = TRUE; |
||
7270 | free(input_type); |
||
7271 | return RECT; |
||
7272 | } |
||
8304 | schaersvoo | 7273 | if( strcmp(input_type, circles) == 0 ){ |
7274 | free(input_type); |
||
7275 | return CIRCLES; |
||
7276 | } |
||
7614 | schaersvoo | 7277 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
7278 | use_filled = TRUE; |
||
7279 | free(input_type); |
||
7280 | return CIRCLE; |
||
7281 | } |
||
9374 | schaersvoo | 7282 | if( strcmp(input_type, fcircles) == 0 || strcmp(input_type, disks) == 0 ){ |
7283 | use_filled = TRUE; |
||
7284 | free(input_type); |
||
7285 | return CIRCLES; |
||
7286 | } |
||
7614 | schaersvoo | 7287 | if( strcmp(input_type, circle) == 0 ){ |
7288 | free(input_type); |
||
7289 | return CIRCLE; |
||
7290 | } |
||
7291 | if( strcmp(input_type, point) == 0 ){ |
||
7292 | free(input_type); |
||
7293 | return POINT; |
||
7294 | } |
||
7295 | if( strcmp(input_type, points) == 0 ){ |
||
7296 | free(input_type); |
||
7297 | return POINTS; |
||
7298 | } |
||
9374 | schaersvoo | 7299 | if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){ |
7614 | schaersvoo | 7300 | use_filled = TRUE; |
7301 | free(input_type); |
||
7302 | return ARC; |
||
7303 | } |
||
7304 | if( strcmp(input_type, arc) == 0 ){ |
||
7305 | free(input_type); |
||
7306 | return ARC; |
||
7307 | } |
||
7308 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
7309 | free(input_type); |
||
7310 | return POLY; |
||
7311 | } |
||
7312 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
7313 | use_filled = TRUE; |
||
7314 | free(input_type); |
||
7315 | return POLY; |
||
7316 | } |
||
7317 | if( strcmp(input_type, ellipse) == 0){ |
||
7318 | free(input_type); |
||
7319 | return ELLIPSE; |
||
7320 | } |
||
12110 | schaersvoo | 7321 | if( strcmp(input_type, ellipses) == 0){ |
7322 | free(input_type); |
||
7323 | return ELLIPSES; |
||
7324 | } |
||
7614 | schaersvoo | 7325 | if( strcmp(input_type, string) == 0 ){ |
7326 | free(input_type); |
||
7327 | return STRING; |
||
7328 | } |
||
7329 | if( strcmp(input_type, stringup) == 0 ){ |
||
7330 | free(input_type); |
||
7331 | return STRINGUP; |
||
7332 | } |
||
9385 | schaersvoo | 7333 | if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){ |
7614 | schaersvoo | 7334 | free(input_type); |
7335 | return OPACITY; |
||
7336 | } |
||
7337 | if( strcmp(input_type, comment) == 0){ |
||
7338 | free(input_type); |
||
7339 | return COMMENT; |
||
7340 | } |
||
7341 | if( strcmp(input_type, fellipse) == 0){ |
||
7342 | free(input_type); |
||
7343 | use_filled = TRUE; |
||
7344 | return ELLIPSE; |
||
8224 | bpr | 7345 | } |
9386 | schaersvoo | 7346 | if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){ |
7614 | schaersvoo | 7347 | free(input_type); |
8146 | schaersvoo | 7348 | return CLEARBUTTON; |
7614 | schaersvoo | 7349 | } |
15111 | schaersvoo | 7350 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
7614 | schaersvoo | 7351 | free(input_type); |
7352 | return TRANSLATION; |
||
7353 | } |
||
7354 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
7355 | free(input_type); |
||
7356 | return KILLTRANSLATION; |
||
7357 | } |
||
7358 | if( strcmp(input_type, rotate) == 0){ |
||
7359 | free(input_type); |
||
7360 | return ROTATE; |
||
7361 | } |
||
9907 | schaersvoo | 7362 | if( strcmp(input_type, killrotate) == 0){ |
7363 | free(input_type); |
||
7364 | return KILLROTATE; |
||
7365 | } |
||
7366 | if( strcmp(input_type, rotationcenter) == 0){ |
||
7367 | free(input_type); |
||
7368 | return ROTATION_CENTER; |
||
7369 | } |
||
7785 | schaersvoo | 7370 | if( strcmp(input_type, affine) == 0){ |
7371 | free(input_type); |
||
7372 | return AFFINE; |
||
7373 | } |
||
15111 | schaersvoo | 7374 | if( strcmp(input_type, linear) == 0){ |
7375 | free(input_type); |
||
7376 | return LINEAR; |
||
7377 | } |
||
7785 | schaersvoo | 7378 | if( strcmp(input_type, killaffine) == 0){ |
7379 | free(input_type); |
||
7380 | return KILLAFFINE; |
||
7381 | } |
||
15111 | schaersvoo | 7382 | if( strcmp(input_type, killlinear) == 0 || strcmp(input_type, killinear) == 0 ){ |
7383 | free(input_type); |
||
7384 | return KILLLINEAR; |
||
7385 | } |
||
7614 | schaersvoo | 7386 | if( strcmp(input_type, slider) == 0 ){ |
7387 | free(input_type); |
||
7388 | return SLIDER; |
||
7389 | } |
||
8101 | schaersvoo | 7390 | if( strcmp(input_type, killslider) == 0 ){ |
7391 | free(input_type); |
||
7392 | return KILLSLIDER; |
||
7393 | } |
||
7614 | schaersvoo | 7394 | if( strcmp(input_type, copy) == 0 ){ |
7395 | free(input_type); |
||
7396 | return COPY; |
||
7397 | } |
||
7398 | if( strcmp(input_type, copyresized) == 0 ){ |
||
7399 | free(input_type); |
||
7400 | return COPYRESIZED; |
||
7401 | } |
||
7402 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
7403 | free(input_type); |
||
7404 | return XLOGSCALE; |
||
7405 | } |
||
7406 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
7407 | free(input_type); |
||
7408 | return YLOGSCALE; |
||
7409 | } |
||
7410 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
7411 | free(input_type); |
||
7412 | return XYLOGSCALE; |
||
7413 | } |
||
7414 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
7415 | free(input_type); |
||
7416 | return YLOGSCALE; |
||
7417 | } |
||
7735 | schaersvoo | 7418 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 7419 | free(input_type); |
7735 | schaersvoo | 7420 | return XLOGBASE; |
7614 | schaersvoo | 7421 | } |
7735 | schaersvoo | 7422 | if( strcmp(input_type, ylogbase) == 0 ){ |
7423 | free(input_type); |
||
7424 | return YLOGBASE; |
||
7425 | } |
||
7614 | schaersvoo | 7426 | if( strcmp(input_type, intooltip) == 0 ){ |
7427 | free(input_type); |
||
7428 | return INTOOLTIP; |
||
7429 | } |
||
9329 | schaersvoo | 7430 | if( strcmp(input_type, popup) == 0 ){ |
7431 | free(input_type); |
||
7432 | return POPUP; |
||
7433 | } |
||
7614 | schaersvoo | 7434 | if( strcmp(input_type,video) == 0 ){ |
7435 | free(input_type); |
||
7436 | return VIDEO; |
||
7437 | } |
||
15111 | schaersvoo | 7438 | if( strcmp(input_type,math) == 0 || strcmp(input_type,latex) == 0 || strcmp(input_type,katex) == 0 ){ |
14225 | schaersvoo | 7439 | free(input_type); |
15111 | schaersvoo | 7440 | #ifdef KATEX_INSTALLED |
7441 | return KATEX; |
||
7442 | #else |
||
14225 | schaersvoo | 7443 | return LATEX; |
15116 | bpr | 7444 | #endif |
14225 | schaersvoo | 7445 | } |
11772 | schaersvoo | 7446 | if( strcmp(input_type,fillall) == 0 ){ |
7447 | free(input_type); |
||
7448 | return FILLALL; |
||
7449 | } |
||
7614 | schaersvoo | 7450 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
7451 | free(input_type); |
||
7452 | return FLOODFILL; |
||
8224 | bpr | 7453 | } |
7614 | schaersvoo | 7454 | if( strcmp(input_type,filltoborder) == 0 ){ |
7455 | free(input_type); |
||
7456 | return FILLTOBORDER; |
||
8224 | bpr | 7457 | } |
14038 | schaersvoo | 7458 | if( strcmp(input_type, curvedarrow2) == 0 ){ |
7459 | free(input_type); |
||
7460 | return CURVEDARROW2; |
||
7461 | } |
||
7462 | if( strcmp(input_type, curvedarrow) == 0 ){ |
||
7463 | free(input_type); |
||
7464 | return CURVEDARROW; |
||
7465 | } |
||
7466 | if( strcmp(input_type, curvedarrows) == 0 ){ |
||
7467 | free(input_type); |
||
7468 | return CURVEDARROWS; |
||
7469 | } |
||
7470 | if( strcmp(input_type, curvedarrows2) == 0 ){ |
||
7471 | free(input_type); |
||
7472 | return CURVEDARROWS2; |
||
7473 | } |
||
7614 | schaersvoo | 7474 | if( strcmp(input_type, replyformat) == 0 ){ |
7475 | free(input_type); |
||
7476 | return REPLYFORMAT; |
||
7477 | } |
||
7478 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
7479 | free(input_type); |
||
7480 | return PIXELSIZE; |
||
7481 | } |
||
7482 | if( strcmp(input_type, setpixel) == 0 ){ |
||
7483 | free(input_type); |
||
7484 | return SETPIXEL; |
||
7485 | } |
||
7486 | if( strcmp(input_type, pixels) == 0 ){ |
||
7487 | free(input_type); |
||
7488 | return PIXELS; |
||
7489 | } |
||
7490 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
7491 | free(input_type); |
||
7492 | return X_AXIS_STRINGS; |
||
7493 | } |
||
9341 | schaersvoo | 7494 | if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){ |
7495 | free(input_type); |
||
7496 | return X_AXIS_STRINGS_UP; |
||
7497 | } |
||
7614 | schaersvoo | 7498 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
7499 | free(input_type); |
||
7500 | return Y_AXIS_STRINGS; |
||
7501 | } |
||
15111 | schaersvoo | 7502 | if( strcmp(input_type, legend) == 0 ){ |
7614 | schaersvoo | 7503 | free(input_type); |
7504 | return LEGEND; |
||
7505 | } |
||
15111 | schaersvoo | 7506 | if( strcmp(input_type, legendcolors) == 0 ){ |
7614 | schaersvoo | 7507 | free(input_type); |
7508 | return LEGENDCOLORS; |
||
7509 | } |
||
15111 | schaersvoo | 7510 | if( strcmp(input_type, xlabel) == 0 ){ |
7614 | schaersvoo | 7511 | free(input_type); |
7512 | return XLABEL; |
||
7513 | } |
||
15111 | schaersvoo | 7514 | if( strcmp(input_type, ylabel) == 0 ){ |
7614 | schaersvoo | 7515 | free(input_type); |
7516 | return YLABEL; |
||
7517 | } |
||
15111 | schaersvoo | 7518 | if( strcmp(input_type, bezier) == 0 ){ |
8370 | schaersvoo | 7519 | free(input_type); |
7520 | return BEZIER; |
||
7521 | } |
||
15111 | schaersvoo | 7522 | if( strcmp(input_type, animate) == 0 ){ |
7614 | schaersvoo | 7523 | free(input_type); |
7524 | return ANIMATE; |
||
7525 | } |
||
9354 | schaersvoo | 7526 | /* these are bitmap related flydraw commands...must be removed. eventually */ |
7614 | schaersvoo | 7527 | if( strcmp(input_type, transparent) == 0 ){ |
7528 | free(input_type); |
||
7529 | return TRANSPARENT; |
||
7530 | } |
||
7877 | schaersvoo | 7531 | if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){ |
7614 | schaersvoo | 7532 | free(input_type); |
7533 | return STATUS; |
||
7534 | } |
||
7784 | schaersvoo | 7535 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
7536 | free(input_type); |
||
7537 | return XSNAPTOGRID; |
||
7538 | } |
||
7539 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
7540 | free(input_type); |
||
7541 | return YSNAPTOGRID; |
||
7542 | } |
||
8379 | schaersvoo | 7543 | if( strcmp(input_type, snaptogrid) == 0 ){ |
7544 | free(input_type); |
||
7545 | return SNAPTOGRID; |
||
7546 | } |
||
7547 | if( strcmp(input_type, snaptopoints) == 0 ){ |
||
7548 | free(input_type); |
||
7549 | return SNAPTOPOINTS; |
||
7550 | } |
||
9213 | schaersvoo | 7551 | if( strcmp(input_type, snaptofunction) == 0 || strcmp(input_type, snaptofun) == 0 ){ |
7552 | free(input_type); |
||
7553 | return SNAPTOFUNCTION; |
||
7554 | } |
||
7652 | schaersvoo | 7555 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 7556 | free(input_type); |
7652 | schaersvoo | 7557 | return USERINPUT_XY; |
7558 | } |
||
8193 | schaersvoo | 7559 | if( strcmp(input_type, userinput_function) == 0 ){ |
7560 | free(input_type); |
||
7561 | return USERINPUT_FUNCTION; |
||
7562 | } |
||
8222 | schaersvoo | 7563 | if( strcmp(input_type, userinput) == 0 ){ |
7564 | free(input_type); |
||
7565 | return USERINPUT; |
||
7566 | } |
||
8105 | schaersvoo | 7567 | if( strcmp(input_type, angle) == 0 ){ |
7996 | schaersvoo | 7568 | free(input_type); |
8105 | schaersvoo | 7569 | return ANGLE; |
7570 | } |
||
15315 | bpr | 7571 | if( strcmp(input_type, functionlabel) == 0 || strcmp(input_type, functionlabels) == 0 ){ |
8244 | schaersvoo | 7572 | free(input_type); |
8297 | schaersvoo | 7573 | return FUNCTION_LABEL; |
7574 | } |
||
9213 | schaersvoo | 7575 | if( strcmp(input_type, sliderfunction_x) == 0 ){ |
8297 | schaersvoo | 7576 | free(input_type); |
9213 | schaersvoo | 7577 | return SLIDER_X; |
7578 | } |
||
7579 | if( strcmp(input_type, sliderfunction_y) == 0 ){ |
||
7580 | free(input_type); |
||
7581 | return SLIDER_Y; |
||
7582 | } |
||
7583 | if( strcmp(input_type, multidraw) == 0 ){ |
||
7584 | free(input_type); |
||
7585 | return MULTIDRAW; |
||
7586 | } |
||
7587 | if( strcmp(input_type, multistrokeopacity) == 0 ){ |
||
7588 | free(input_type); |
||
7589 | return MULTISTROKEOPACITY; |
||
7590 | } |
||
7591 | if( strcmp(input_type, multifillopacity) == 0 ){ |
||
7592 | free(input_type); |
||
7593 | return MULTIFILLOPACITY; |
||
7594 | } |
||
15111 | schaersvoo | 7595 | if( strcmp(input_type, multilinewidth) == 0 || strcmp(input_type, linewidths) == 0 ){ |
9213 | schaersvoo | 7596 | free(input_type); |
7597 | return MULTILINEWIDTH; |
||
7598 | } |
||
15111 | schaersvoo | 7599 | if( strcmp(input_type, multistrokecolors) == 0 || strcmp(input_type,multicolors) == 0 || strcmp(input_type,strokecolors) == 0 || strcmp(input_type,colors) == 0 ){ |
9213 | schaersvoo | 7600 | free(input_type); |
7601 | return MULTISTROKECOLORS; |
||
7602 | } |
||
7603 | if( strcmp(input_type, multifill) == 0 ){ |
||
7604 | free(input_type); |
||
7605 | return MULTIFILL; |
||
7606 | } |
||
15111 | schaersvoo | 7607 | if( strcmp(input_type, multifillcolors) == 0 || strcmp(input_type, fillcolors) == 0 ){ |
9213 | schaersvoo | 7608 | free(input_type); |
7609 | return MULTIFILLCOLORS; |
||
7610 | } |
||
7611 | if( strcmp(input_type, multilabel) == 0 ){ |
||
7612 | free(input_type); |
||
7613 | return MULTILABEL; |
||
7614 | } |
||
7615 | if( strcmp(input_type, multidash) == 0 ){ |
||
7616 | free(input_type); |
||
7617 | return MULTIDASH; |
||
7618 | } |
||
14038 | schaersvoo | 7619 | if( strcmp(input_type, multisnaptogrid) == 0 || strcmp(input_type, multisnap) == 0 ){ |
9213 | schaersvoo | 7620 | free(input_type); |
7621 | return MULTISNAPTOGRID; |
||
7622 | } |
||
15111 | schaersvoo | 7623 | if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0 ){ |
9213 | schaersvoo | 7624 | free(input_type); |
7625 | return MULTIUSERINPUT; |
||
7626 | } |
||
9386 | schaersvoo | 7627 | if( strcmp(input_type, parallel) == 0 ){ |
7628 | free(input_type); |
||
7629 | return PARALLEL; |
||
7630 | } |
||
9289 | schaersvoo | 7631 | if( strcmp(input_type, protractor) == 0 ){ |
7632 | free(input_type); |
||
7633 | return PROTRACTOR; |
||
7634 | } |
||
7635 | if( strcmp(input_type, ruler) == 0 ){ |
||
7636 | free(input_type); |
||
7637 | return RULER; |
||
7638 | } |
||
9386 | schaersvoo | 7639 | if( strcmp(input_type, cursor) == 0 || strcmp(input_type, pointer) == 0 ){ |
9213 | schaersvoo | 7640 | free(input_type); |
9386 | schaersvoo | 7641 | return CURSOR; |
7642 | } |
||
7643 | if( strcmp(input_type, sgraph) == 0 ){ |
||
7644 | free(input_type); |
||
7645 | return SGRAPH; |
||
7646 | } |
||
7647 | if( strcmp(input_type, jsmath) == 0 ){ |
||
7648 | free(input_type); |
||
7649 | return JSMATH; |
||
7650 | } |
||
7651 | if( strcmp(input_type, trace_jscurve) == 0 ){ |
||
7652 | free(input_type); |
||
7653 | return TRACE_JSCURVE; |
||
7654 | } |
||
7655 | if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){ |
||
7656 | free(input_type); |
||
7657 | return JSCURVE; |
||
7658 | } |
||
7659 | if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){ |
||
7660 | free(input_type); |
||
7661 | return CENTERSTRING; |
||
7662 | } |
||
7663 | if( strcmp(input_type, setlimits) == 0 ){ |
||
7664 | free(input_type); |
||
7665 | return SETLIMITS; |
||
7666 | } |
||
7667 | if( strcmp(input_type, xunit) == 0 ){ |
||
7668 | free(input_type); |
||
7669 | return XUNIT; |
||
7670 | } |
||
7671 | if( strcmp(input_type, yunit) == 0 ){ |
||
7672 | free(input_type); |
||
7673 | return YUNIT; |
||
7674 | } |
||
7675 | if( strcmp(input_type, fill) == 0 ){ |
||
7676 | free(input_type); |
||
7677 | return FLOODFILL; |
||
7678 | } |
||
7679 | if( strcmp(input_type, end) == 0){ |
||
7680 | free(input_type); |
||
7681 | return END; |
||
7682 | } |
||
7683 | if( strcmp(input_type, blink) == 0 ){ |
||
7684 | free(input_type); |
||
7685 | return BLINK; |
||
7686 | } |
||
7687 | if( strcmp(input_type, audio) == 0 ){ |
||
7688 | free(input_type); |
||
7689 | return AUDIO; |
||
7690 | } |
||
7691 | if( strcmp(input_type, audioobject) == 0 ){ |
||
7692 | free(input_type); |
||
7693 | return AUDIOOBJECT; |
||
7694 | } |
||
7695 | if( strcmp(input_type, patternfill) == 0 ){ |
||
7696 | free(input_type); |
||
7697 | return PATTERNFILL; |
||
7698 | } |
||
7699 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
7700 | free(input_type); |
||
7701 | return HATCHFILL; |
||
7702 | } |
||
15111 | schaersvoo | 7703 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
9386 | schaersvoo | 7704 | free(input_type); |
7705 | return DIAMONDFILL; |
||
7706 | } |
||
7707 | if( strcmp(input_type, dotfill) == 0 ){ |
||
7708 | free(input_type); |
||
7709 | return DOTFILL; |
||
7710 | } |
||
11830 | schaersvoo | 7711 | if( strcmp(input_type, textfill) == 0 ){ |
7712 | free(input_type); |
||
7713 | return TEXTFILL; |
||
7714 | } |
||
9386 | schaersvoo | 7715 | if( strcmp(input_type, gridfill) == 0 ){ |
7716 | free(input_type); |
||
7717 | return GRIDFILL; |
||
7718 | } |
||
7719 | if( strcmp(input_type, imagefill) == 0 ){ |
||
7720 | free(input_type); |
||
7721 | return IMAGEFILL; |
||
7722 | } |
||
7723 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
7724 | free(input_type); |
||
7725 | return CLICKTILE_COLORS; |
||
7726 | } |
||
7727 | if( strcmp(input_type, clicktile) == 0 ){ |
||
7728 | free(input_type); |
||
7729 | return CLICKTILE; |
||
7730 | } |
||
15111 | schaersvoo | 7731 | if( strcmp(input_type, piechart) == 0 ){ |
9386 | schaersvoo | 7732 | free(input_type); |
7733 | return PIECHART; |
||
7734 | } |
||
15111 | schaersvoo | 7735 | if( strcmp(input_type, boxplot) == 0 ){ |
9433 | schaersvoo | 7736 | free(input_type); |
7737 | return BOXPLOT; |
||
7738 | } |
||
15111 | schaersvoo | 7739 | if( strcmp(input_type, boxplotdata) == 0 ){ |
9433 | schaersvoo | 7740 | free(input_type); |
9465 | schaersvoo | 7741 | return BOXPLOTDATA; |
9433 | schaersvoo | 7742 | } |
15111 | schaersvoo | 7743 | if( strcmp(input_type, userboxplot) == 0 ){ |
9465 | schaersvoo | 7744 | free(input_type); |
7745 | return USERBOXPLOT; |
||
7746 | } |
||
15111 | schaersvoo | 7747 | if( strcmp(input_type, userboxplotdata) == 0 ){ |
9465 | schaersvoo | 7748 | free(input_type); |
7749 | return USERBOXPLOT; |
||
7750 | } |
||
15111 | schaersvoo | 7751 | if( strcmp(input_type, barchart) == 0 ){ |
9386 | schaersvoo | 7752 | free(input_type); |
7753 | return BARCHART; |
||
7754 | } |
||
15111 | schaersvoo | 7755 | if( strcmp(input_type, linegraph) == 0 ){ |
9386 | schaersvoo | 7756 | free(input_type); |
7757 | return LINEGRAPH; |
||
7758 | } |
||
15111 | schaersvoo | 7759 | if( strcmp(input_type, clock) == 0 ){ |
9386 | schaersvoo | 7760 | free(input_type); |
7761 | return CLOCK; |
||
7762 | } |
||
15111 | schaersvoo | 7763 | if( strcmp(input_type, yerrorbars) == 0 ){ |
9386 | schaersvoo | 7764 | free(input_type); |
9427 | schaersvoo | 7765 | return YERRORBARS; |
7766 | } |
||
15111 | schaersvoo | 7767 | if( strcmp(input_type, xerrorbars) == 0 ){ |
9427 | schaersvoo | 7768 | free(input_type); |
7769 | return XERRORBARS; |
||
7770 | } |
||
15111 | schaersvoo | 7771 | if( strcmp(input_type, canvastype) == 0 ){ |
9427 | schaersvoo | 7772 | free(input_type); |
11006 | schaersvoo | 7773 | return CANVASTYPE; |
7774 | } |
||
15111 | schaersvoo | 7775 | if( strcmp(input_type, noyaxis) == 0 ){ |
11006 | schaersvoo | 7776 | free(input_type); |
11044 | schaersvoo | 7777 | return NOYAXIS; |
7778 | } |
||
15111 | schaersvoo | 7779 | if( strcmp(input_type, noxaxis) == 0 ){ |
11044 | schaersvoo | 7780 | free(input_type); |
7781 | return NOXAXIS; |
||
7782 | } |
||
15111 | schaersvoo | 7783 | if( strcmp(input_type, colorpalette) == 0 ){ |
11044 | schaersvoo | 7784 | free(input_type); |
11767 | schaersvoo | 7785 | return COLORPALETTE; |
7786 | } |
||
15111 | schaersvoo | 7787 | if( strcmp(input_type, imagepalette) == 0 ){ |
14038 | schaersvoo | 7788 | free(input_type); |
7789 | return IMAGEPALETTE; |
||
7790 | } |
||
15111 | schaersvoo | 7791 | if( strcmp(input_type, resetoffset) == 0 ){ |
11767 | schaersvoo | 7792 | free(input_type); |
11802 | schaersvoo | 7793 | return RESETOFFSET; |
7794 | } |
||
15111 | schaersvoo | 7795 | if( strcmp(input_type, xyoffset) == 0 ){ |
11802 | schaersvoo | 7796 | free(input_type); |
7797 | return XYOFFSET; |
||
7798 | } |
||
12063 | schaersvoo | 7799 | if( strcmp(input_type, centered) == 0 ){ |
11802 | schaersvoo | 7800 | free(input_type); |
12063 | schaersvoo | 7801 | return CENTERED; |
11802 | schaersvoo | 7802 | } |
15111 | schaersvoo | 7803 | if( strcmp(input_type, yoffset) == 0 ){ |
11802 | schaersvoo | 7804 | free(input_type); |
11811 | schaersvoo | 7805 | return YOFFSET; |
7806 | } |
||
15111 | schaersvoo | 7807 | if( strcmp(input_type, xoffset) == 0 ){ |
12063 | schaersvoo | 7808 | free(input_type); |
7809 | return XOFFSET; |
||
7810 | } |
||
15601 | schaersvoo | 7811 | if( strcmp(input_type, fillpattern) == 0 || strcmp(input_type, settile) == 0 ){ |
11811 | schaersvoo | 7812 | free(input_type); |
11837 | schaersvoo | 7813 | return FILLPATTERN; |
7814 | } |
||
11890 | schaersvoo | 7815 | if( strcmp(input_type, numberline) == 0 ){ |
11837 | schaersvoo | 7816 | free(input_type); |
11890 | schaersvoo | 7817 | return NUMBERLINE; |
7818 | } |
||
15111 | schaersvoo | 7819 | if( strcmp(input_type, obabel) == 0 ){ |
7820 | free(input_type); |
||
7821 | return OBABEL; |
||
7822 | } |
||
7823 | if( strcmp(input_type, chemtex) == 0 ){ |
||
7824 | free(input_type); |
||
7825 | return CHEMTEX; |
||
7826 | } |
||
7827 | if( strcmp(input_type, noreset) == 0 || strcmp(input_type, killreset) == 0 ){ |
||
7828 | return NORESET; |
||
7829 | } |
||
14393 | schaersvoo | 7830 | if( strcmp(input_type, duplicates) == 0 || strcmp(input_type, allowdups) == 0 ){ |
11890 | schaersvoo | 7831 | free(input_type); |
14393 | schaersvoo | 7832 | return ALLOW_DUPLICATES; |
7833 | } |
||
7834 | free(input_type); |
||
7614 | schaersvoo | 7835 | ungetc(c,infile); |
7836 | return 0; |
||
7837 | } |
||
15611 | schaersvoo | 7838 | |
15613 | schaersvoo | 7839 | |
7840 |