Subversion Repositories wimsdev

Rev

Rev 20 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20 Rev 13572
Line 13... Line 13...
13
This program is free software; you can redistribute it and/or modify
13
This program is free software; you can redistribute it and/or modify
14
it under the terms of the GNU General Public License as published by
14
it under the terms of the GNU General Public License as published by
15
the Free Software Foundation; either version 2 of the License, or (at
15
the Free Software Foundation; either version 2 of the License, or (at
16
your option) any later version.
16
your option) any later version.
17
 
17
 
18
This program is distributed in the hope that it will be useful,
18
This program is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
General Public License (at http://www.gnu.org/copyleft/gpl.html)
21
General Public License (at http://www.gnu.org/copyleft/gpl.html)
22
for more details.*/
22
for more details.*/
23
 
23
 
24
var checkIfSVGavailable = true;
24
var checkIfSVGavailable = true;
25
var notifyIfNoSVG = true;
25
var notifyIfNoSVG = true;
26
var alertIfNoSVG = false;
26
var alertIfNoSVG = false;
Line 54... Line 54...
54
var pi = Math.PI, ln = Math.log, e = Math.E;
54
var pi = Math.PI, ln = Math.log, e = Math.E;
55
var arcsin = Math.asin, arccos = Math.acos, arctan = Math.atan;
55
var arcsin = Math.asin, arccos = Math.acos, arctan = Math.atan;
56
var sec = function(x) { return 1/Math.cos(x) };
56
var sec = function(x) { return 1/Math.cos(x) };
57
var csc = function(x) { return 1/Math.sin(x) };
57
var csc = function(x) { return 1/Math.sin(x) };
58
var cot = function(x) { return 1/Math.tan(x) };
58
var cot = function(x) { return 1/Math.tan(x) };
59
var xmin, xmax, ymin, ymax, xscl, yscl,
59
var xmin, xmax, ymin, ymax, xscl, yscl,
60
    xgrid, ygrid, xtick, ytick, initialized;
60
    xgrid, ygrid, xtick, ytick, initialized;
61
var isIE = document.createElementNS==null;
61
var isIE = document.createElementNS==null;
62
var picture, svgpicture, doc, width, height, a, b, c, d, i, n, p, t, x, y;
62
var picture, svgpicture, doc, width, height, a, b, c, d, i, n, p, t, x, y;
63
var arcsec = function(x) { return arccos(1/x) };
63
var arcsec = function(x) { return arccos(1/x) };
64
var arccsc = function(x) { return arcsin(1/x) };
64
var arccsc = function(x) { return arcsin(1/x) };
65
var arccot = function(x) { return arctan(1/x) };
65
var arccot = function(x) { return arctan(1/x) };
66
var sinh = function(x) { return (Math.exp(x)-Math.exp(-x))/2 };
66
var sinh = function(x) { return (Math.exp(x)-Math.exp(-x))/2 };
67
var cosh = function(x) { return (Math.exp(x)+Math.exp(-x))/2 };
67
var cosh = function(x) { return (Math.exp(x)+Math.exp(-x))/2 };
68
var tanh =
68
var tanh =
69
  function(x) { return (Math.exp(x)-Math.exp(-x))/(Math.exp(x)+Math.exp(-x)) };
69
  function(x) { return (Math.exp(x)-Math.exp(-x))/(Math.exp(x)+Math.exp(-x)) };
70
var sech = function(x) { return 1/cosh(x) };
70
var sech = function(x) { return 1/cosh(x) };
71
var csch = function(x) { return 1/sinh(x) };
71
var csch = function(x) { return 1/sinh(x) };
72
var coth = function(x) { return 1/tanh(x) };
72
var coth = function(x) { return 1/tanh(x) };
73
var arcsinh = function(x) { return ln(x+Math.sqrt(x*x+1)) };
73
var arcsinh = function(x) { return ln(x+Math.sqrt(x*x+1)) };
Line 124... Line 124...
124
  an = myCreateElementXHTML("a");
124
  an = myCreateElementXHTML("a");
125
  an.appendChild(document.createTextNode("SVG enabled Mozilla/Firefox"));
125
  an.appendChild(document.createTextNode("SVG enabled Mozilla/Firefox"));
126
  an.setAttribute("href",
126
  an.setAttribute("href",
127
    "http://www.chapman.edu/~jipsen/svg/svgenabledmozillafirefox.html");
127
    "http://www.chapman.edu/~jipsen/svg/svgenabledmozillafirefox.html");
128
  nd.appendChild(an);
128
  nd.appendChild(an);
129
  if (navigator.appName.slice(0,8)=="Netscape")
129
  if (navigator.appName.slice(0,8)=="Netscape")
130
    if (window['SVGElement']) return null;
130
    if (window['SVGElement']) return null;
131
    else return nd;
131
    else return nd;
132
  else if (navigator.appName.slice(0,9)=="Microsoft")
132
  else if (navigator.appName.slice(0,9)=="Microsoft")
133
    try {
133
    try {
134
      var oSVG=eval("new ActiveXObject('Adobe.SVGCtl.3');");
134
      var oSVG=eval("new ActiveXObject('Adobe.SVGCtl.3');");
135
        return null;
135
      return null;
136
    } catch (e) {
136
    } catch (e) {
137
        return nd;
137
      return nd;
138
    }
138
    }
139
  else return nd;
139
  else return nd;
140
}
140
}
141
 
141
 
142
 
142
 
143
function less(x,y) { return x < y }  // used for scripts in XML files
143
function less(x,y) { return x < y }  // used for scripts in XML files
144
                                     // since IE does not handle CDATA well
144
                                     // since IE does not handle CDATA well
145
function setText(st,id) {
145
function setText(st,id) {
146
  var node = document.getElementById(id);
146
  var node = document.getElementById(id);
147
  if (node!=null)
147
  if (node!=null)
148
    if (node.childNodes.length!=0) node.childNodes[0].nodeValue = st;
148
    if (node.childNodes.length!=0) node.childNodes[0].nodeValue = st;
149
    else node.appendChild(document.createTextNode(st));
149
    else node.appendChild(document.createTextNode(st));
150
}
150
}
Line 171... Line 171...
171
 
171
 
172
function top_listener(evt) {
172
function top_listener(evt) {
173
  svgpicture.setAttribute("ybase",evt.clientY);
173
  svgpicture.setAttribute("ybase",evt.clientY);
174
}
174
}
175
 
175
 
176
function bottom_listener(evt) {
176
function bottom_listener(evt) {
177
  svgpicture.setAttribute("ybase",evt.clientY-height+1);
177
  svgpicture.setAttribute("ybase",evt.clientY-height+1);
178
}
178
}
179
 
179
 
180
function left_listener(evt) {
180
function left_listener(evt) {
181
  svgpicture.setAttribute("xbase",evt.clientX);
181
  svgpicture.setAttribute("xbase",evt.clientX);
Line 192... Line 192...
192
    if (pictures[index].className=="ASCIIsvg"){
192
    if (pictures[index].className=="ASCIIsvg"){
193
      pictures[index].style.display="none";  // hide the textarea
193
      pictures[index].style.display="none";  // hide the textarea
194
    }
194
    }
195
  pictures = document.getElementsByTagName("embed");
195
  pictures = document.getElementsByTagName("embed");
196
  var len = pictures.length;
196
  var len = pictures.length;
197
 if (checkIfSVGavailable) {
197
  if (checkIfSVGavailable) {
198
  nd = isSVGavailable();
198
    nd = isSVGavailable();
199
  if (nd != null && notifyIfNoSVG && len>0)
199
    if (nd != null && notifyIfNoSVG && len>0)
200
    if (alertIfNoSVG)
200
      if (alertIfNoSVG)
201
      alert("To view the SVG pictures in Internet Explorer\n\
201
        alert("To view the SVG pictures in Internet Explorer\n\
202
download the free Adobe SVGviewer from www.adobe.com/svg or\n\
202
download the free Adobe SVGviewer from www.adobe.com/svg or\n\
203
use Firefox 1.5 preview (called Deerpark)");
203
use Firefox 1.5 preview (called Deerpark)");
204
    else {
204
      else {
205
    var ASbody = document.getElementsByTagName("body")[0];
205
        var ASbody = document.getElementsByTagName("body")[0];
206
    ASbody.insertBefore(nd,ASbody.childNodes[0]);
206
        ASbody.insertBefore(nd,ASbody.childNodes[0]);
207
  }
207
      }
208
 }
208
  }
209
 if (nd == null) {
209
  if (nd == null) {
210
  for (index = 0; index < len; index++) {
210
    for (index = 0; index < len; index++) {
211
    xmin = null; xmax = null; ymin = null; ymax = null;
211
      xmin = null; xmax = null; ymin = null; ymax = null;
212
    xscl = null; xgrid = null; yscl = null; ygrid = null;
212
      xscl = null; xgrid = null; yscl = null; ygrid = null;
213
    initialized = false;
213
      initialized = false;
214
    picture = (isIE ? pictures[index] : pictures[0]);
214
      picture = (isIE ? pictures[index] : pictures[0]);
215
    src = picture.getAttribute("script");
215
      src = picture.getAttribute("script");
216
    if (src==null) src = "";
216
      if (src==null) src = "";
217
    ht = picture.getAttribute("height");
217
      ht = picture.getAttribute("height");
218
    if (ht==null) ht ="";
218
      if (ht==null) ht ="";
219
   if (ht!="") defaultborder = 25;
219
      if (ht!="") defaultborder = 25;
220
   if (ht=="" || src=="")
220
      if (ht=="" || src=="")
221
    if (document.getElementById("picture"+(index+1)+"input")==null) {
221
        if (document.getElementById("picture"+(index+1)+"input")==null) {
222
      if (isIE && src.indexOf("nobutton()")==-1)
222
          if (isIE && src.indexOf("nobutton()")==-1)
223
        picture.parentNode.insertBefore(myCreateElementXHTML("br"),picture);
223
            picture.parentNode.insertBefore(myCreateElementXHTML("br"),picture);
224
      node = myCreateElementXHTML("textarea");
224
          node = myCreateElementXHTML("textarea");
225
      node.setAttribute("rows","10");
225
          node.setAttribute("rows","10");
226
      node.setAttribute("cols","60");
226
          node.setAttribute("cols","60");
227
//      node.setAttribute("style","display:block");
227
          // node.setAttribute("style","display:block");
228
      if (isIE) src = src.replace(/([^\r])\n/g,"$1\r").slice(1);
228
          if (isIE) src = src.replace(/([^\r])\n/g,"$1\r").slice(1);
229
      node.appendChild(document.createTextNode(src));
229
          node.appendChild(document.createTextNode(src));
230
      if (src.indexOf("showcode()")==-1) node.style.display = "none";
230
          if (src.indexOf("showcode()")==-1) node.style.display = "none";
231
      node.setAttribute("id","picture"+(index+1)+"input");
231
          node.setAttribute("id","picture"+(index+1)+"input");
232
      picture.parentNode.insertBefore(node,picture);
232
          picture.parentNode.insertBefore(node,picture);
233
 
233
 
234
      if (src.indexOf("nobutton()")==-1) {
234
          if (src.indexOf("nobutton()")==-1) {
235
        picture.parentNode.insertBefore(myCreateElementXHTML("br"),picture);
235
            picture.parentNode.insertBefore(myCreateElementXHTML("br"),picture);
236
 
-
 
237
        node = myCreateElementXHTML("button");
-
 
238
        if (isIE) node.onclick = function() { showHideCode(this) };
-
 
239
        else node.setAttribute("onclick","showHideCode(this)");
-
 
240
        node.appendChild(document.createTextNode("Show/Hide"));
-
 
241
        picture.parentNode.insertBefore(node,picture);
-
 
242
 
236
 
243
        node = myCreateElementXHTML("button");
237
            node = myCreateElementXHTML("button");
244
        if (isIE) node.onclick = ASfn[index];
238
            if (isIE) node.onclick = function() { showHideCode(this) };
245
        else node.setAttribute("onclick","updatePicture("+index+")");
239
            else node.setAttribute("onclick","showHideCode(this)");
246
        node.appendChild(document.createTextNode("Update"));
240
            node.appendChild(document.createTextNode("Show/Hide"));
247
        if (src.indexOf("showCode()")==-1) node.style.display = "none";
-
 
248
        picture.parentNode.insertBefore(node,picture);
241
            picture.parentNode.insertBefore(node,picture);
249
 
242
 
250
/*      node = myCreateElementXHTML("span");
243
            node = myCreateElementXHTML("button");
-
 
244
            if (isIE) node.onclick = ASfn[index];
251
//      node.setAttribute("id","AScoord"+index);
245
            else node.setAttribute("onclick","updatePicture("+index+")");
252
        node.appendChild(document.createTextNode("(x,y)"));
246
            node.appendChild(document.createTextNode("Update"));
-
 
247
            if (src.indexOf("showCode()")==-1) node.style.display = "none";
253
        picture.parentNode.insertBefore(node,picture);
248
            picture.parentNode.insertBefore(node,picture);
254
*/
249
 
-
 
250
            /* node = myCreateElementXHTML("span");
-
 
251
            // node.setAttribute("id","AScoord"+index);
-
 
252
               node.appendChild(document.createTextNode("(x,y)"));
-
 
253
               picture.parentNode.insertBefore(node,picture);
-
 
254
            */
255
        picture.parentNode.insertBefore(myCreateElementXHTML("br"),picture);
255
            picture.parentNode.insertBefore(myCreateElementXHTML("br"),picture);
-
 
256
          }
-
 
257
          if (isIE) picture.onmousemove = ASupdateCoords[index];
-
 
258
          else picture.setAttribute("onmousemove","updateCoords"+index+"()");
-
 
259
        } else src = document.getElementById("picture"+(index+1)+"input").value;
-
 
260
      src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+?)\,/g,"plot\(\"$1\",");
-
 
261
      src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+)\)/g,"plot(\"$1\")");
-
 
262
      src = src.replace(/([0-9])([a-zA-Z])/g,"$1*$2");
-
 
263
      src = src.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
-
 
264
      //    eval(src.replace(/\s\s/g,";")); //for XML version
-
 
265
      id = picture.getAttribute("id");
-
 
266
      dsvg = picture.getAttribute("src");
-
 
267
      onmov = picture.getAttribute("onmousemove");
-
 
268
      if (id == null || id == "") {
-
 
269
        id = "picture"+(index+1);
-
 
270
        picture.setAttribute("id",id);
256
      }
271
      }
257
      if (isIE) picture.onmousemove = ASupdateCoords[index];
-
 
258
      else picture.setAttribute("onmousemove","updateCoords"+index+"()");
-
 
259
    } else src = document.getElementById("picture"+(index+1)+"input").value;
-
 
260
    src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+?)\,/g,"plot\(\"$1\",");
-
 
261
    src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+)\)/g,"plot(\"$1\")");
-
 
262
    src = src.replace(/([0-9])([a-zA-Z])/g,"$1*$2");
-
 
263
    src = src.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
-
 
264
//    eval(src.replace(/\s\s/g,";")); //for XML version
-
 
265
    id = picture.getAttribute("id");
-
 
266
    dsvg = picture.getAttribute("src");
-
 
267
    onmov = picture.getAttribute("onmousemove");
-
 
268
    if (id == null || id == "") {
-
 
269
      id = "picture"+(index+1);
-
 
270
      picture.setAttribute("id",id);
-
 
271
    }
-
 
272
    try {
272
      try {
273
      with (Math) eval(src);
273
        with (Math) eval(src);
274
    } catch(err) {alert(err+"\n"+src)}
274
      } catch(err) {alert(err+"\n"+src)}
275
    if (isIE) src = src.replace(/([^\r])\n/g,"$1\r");
275
      if (isIE) src = src.replace(/([^\r])\n/g,"$1\r");
276
    setText("<embed width=\""+width+"\" height=\""+height+"\" src=\""+
276
      setText("<embed width=\""+width+"\" height=\""+height+"\" src=\""+
277
            dsvg+"\" "+(onmov!=null?"onmousemove=\""+onmov+"\"":"")+
277
            dsvg+"\" "+(onmov!=null?"onmousemove=\""+onmov+"\"":"")+
278
            (isIE?"\r":"\n")+"script=\'"+src+"\'>",id+"script");
278
            (isIE?"\r":"\n")+"script=\'"+src+"\'>",id+"script");
279
//    setText(src.replace(/\s\s/g,"\r"),id+"script"); //for XML version
279
      //    setText(src.replace(/\s\s/g,"\r"),id+"script"); //for XML version
-
 
280
    }
280
  }
281
  }
281
 }
-
 
282
}
282
}
283
 
283
 
284
function switchTo(id) {
284
function switchTo(id) {
285
//alert(id);
285
//alert(id);
286
  picture = document.getElementById(id);
286
  picture = document.getElementById(id);
Line 293... Line 293...
293
  if ((picture.nodeName == "EMBED" || picture.nodeName == "embed") && isIE) {
293
  if ((picture.nodeName == "EMBED" || picture.nodeName == "embed") && isIE) {
294
    svgpicture = picture.getSVGDocument().getElementById("root");
294
    svgpicture = picture.getSVGDocument().getElementById("root");
295
    doc = picture.getSVGDocument();
295
    doc = picture.getSVGDocument();
296
  } else {
296
  } else {
297
    picture.setAttribute("onmousemove","updateCoords"+(id.slice(id.length-1)-1)+"()");
297
    picture.setAttribute("onmousemove","updateCoords"+(id.slice(id.length-1)-1)+"()");
298
//alert(picture.getAttribute("onmousemove")+"***");
298
    //alert(picture.getAttribute("onmousemove")+"***");
299
    svgpicture = picture;
299
    svgpicture = picture;
300
    doc = document;
300
    doc = document;
301
  }
301
  }
302
  xunitlength = svgpicture.getAttribute("xunitlength")-0;
302
  xunitlength = svgpicture.getAttribute("xunitlength")-0;
303
  yunitlength = svgpicture.getAttribute("yunitlength")-0;
303
  yunitlength = svgpicture.getAttribute("yunitlength")-0;
Line 318... Line 318...
318
  switchTo((typeof obj=="string"?obj.slice(0,8):"picture"+(obj+1)));
318
  switchTo((typeof obj=="string"?obj.slice(0,8):"picture"+(obj+1)));
319
  src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+?)\,/g,"plot\(\"$1\",");
319
  src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+?)\,/g,"plot\(\"$1\",");
320
  src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+)\)/g,"plot(\"$1\")");
320
  src = src.replace(/plot\(\x20*([^\"f\[][^\n\r]+)\)/g,"plot(\"$1\")");
321
  src = src.replace(/([0-9])([a-zA-Z])/g,"$1*$2");
321
  src = src.replace(/([0-9])([a-zA-Z])/g,"$1*$2");
322
  src = src.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
322
  src = src.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
323
//alert(src);
323
  //alert(src);
324
  try {
324
  try {
325
    with (Math) eval(src);
325
    with (Math) eval(src);
326
  } catch(err) {alert(err+"\n"+src)}
326
  } catch(err) {alert(err+"\n"+src)}
327
}
327
}
328
 
328
 
329
function showHideCode(obj) {
329
function showHideCode(obj) {
330
  var node = obj.nextSibling;
330
  var node = obj.nextSibling;
331
  while (node != null && node.nodeName != "BUTTON" &&
331
  while (node != null && node.nodeName != "BUTTON" &&
332
    node.nodeName != "button") node = node.nextSibling;
332
    node.nodeName != "button") node = node.nextSibling;
333
  if (node.style.display == "none") node.style.display = "";
333
  if (node.style.display == "none") node.style.display = "";
334
  else node.style.display = "none";
334
  else node.style.display = "none";
335
  while (node != null && node.nodeName != "TEXTAREA" &&
335
  while (node != null && node.nodeName != "TEXTAREA" &&
336
    node.nodeName != "textarea") node = node.previousSibling;
336
    node.nodeName != "textarea") node = node.previousSibling;
337
  if (node.style.display == "none") node.style.display = "";
337
  if (node.style.display == "none") node.style.display = "";
338
  else node.style.display = "none";
338
  else node.style.display = "none";
339
//  updatePicture(node.getAttribute("id"));
339
//  updatePicture(node.getAttribute("id"));
340
}
340
}
Line 368... Line 368...
368
  if (x_max!=null) xmax = x_max;
368
  if (x_max!=null) xmax = x_max;
369
  if (y_min!=null) ymin = y_min;
369
  if (y_min!=null) ymin = y_min;
370
  if (y_max!=null) ymax = y_max;
370
  if (y_max!=null) ymax = y_max;
371
  if (xmin==null) xmin = -5;
371
  if (xmin==null) xmin = -5;
372
  if (xmax==null) xmax = 5;
372
  if (xmax==null) xmax = 5;
373
 if (typeof xmin != "number" || typeof xmax != "number" || xmin >= xmax)
373
 if (typeof xmin != "number" || typeof xmax != "number" || xmin >= xmax)
374
   alert("Picture requires at least two numbers: xmin < xmax");
374
   alert("Picture requires at least two numbers: xmin < xmax");
375
 else if (y_max != null && (typeof y_min != "number" ||
375
 else if (y_max != null && (typeof y_min != "number" ||
376
          typeof y_max != "number" || y_min >= y_max))
376
          typeof y_max != "number" || y_min >= y_max))
377
   alert("initPicture(xmin,xmax,ymin,ymax) requires numbers ymin < ymax");
377
   alert("initPicture(xmin,xmax,ymin,ymax) requires numbers ymin < ymax");
378
 else {
378
 else {
379
  if (width==null) width = picture.getAttribute("width");
379
  if (width==null) width = picture.getAttribute("width");
380
  else picture.setAttribute("width",width);
380
  else picture.setAttribute("width",width);
Line 395... Line 395...
395
    origin = [-xmin*xunitlength+border,-ymin*yunitlength+border];
395
    origin = [-xmin*xunitlength+border,-ymin*yunitlength+border];
396
  }
396
  }
397
//  if (true ||picture.nodeName == "EMBED" || picture.nodeName == "embed") {
397
//  if (true ||picture.nodeName == "EMBED" || picture.nodeName == "embed") {
398
    if (isIE) {
398
    if (isIE) {
399
      svgpicture = picture.getSVGDocument().getElementById("root");
399
      svgpicture = picture.getSVGDocument().getElementById("root");
400
      while (svgpicture.childNodes.length()>5)
400
      while (svgpicture.childNodes.length()>5)
401
        svgpicture.removeChild(svgpicture.lastChild);
401
        svgpicture.removeChild(svgpicture.lastChild);
402
      svgpicture.setAttribute("width",width);
402
      svgpicture.setAttribute("width",width);
403
      svgpicture.setAttribute("height",height);
403
      svgpicture.setAttribute("height",height);
404
      doc = picture.getSVGDocument();
404
      doc = picture.getSVGDocument();
405
    } else {
405
    } else {
406
      var qnode = document.createElementNS("http://www.w3.org/2000/svg","svg");
406
      var qnode = document.createElementNS("http://www.w3.org/2000/svg","svg");
Line 484... Line 484...
484
  }
484
  }
485
  node.setAttribute("d","M"+(p[0]*xunitlength+origin[0])+","+
485
  node.setAttribute("d","M"+(p[0]*xunitlength+origin[0])+","+
486
    (height-p[1]*yunitlength-origin[1])+" "+
486
    (height-p[1]*yunitlength-origin[1])+" "+
487
    (q[0]*xunitlength+origin[0])+","+(height-q[1]*yunitlength-origin[1]));
487
    (q[0]*xunitlength+origin[0])+","+(height-q[1]*yunitlength-origin[1]));
488
  node.setAttribute("stroke-width", strokewidth);
488
  node.setAttribute("stroke-width", strokewidth);
489
  if (strokedasharray!=null)
489
  if (strokedasharray!=null)
490
    node.setAttribute("stroke-dasharray", strokedasharray);
490
    node.setAttribute("stroke-dasharray", strokedasharray);
491
  node.setAttribute("stroke", stroke);
491
  node.setAttribute("stroke", stroke);
492
  node.setAttribute("fill", fill);
492
  node.setAttribute("fill", fill);
493
  if (marker=="dot" || marker=="arrowdot") {
493
  if (marker=="dot" || marker=="arrowdot") {
494
    ASdot(p,4,markerstroke,markerfill);
494
    ASdot(p,4,markerstroke,markerfill);
Line 515... Line 515...
515
      st += (plist[i][0]*xunitlength+origin[0])+","+
515
      st += (plist[i][0]*xunitlength+origin[0])+","+
516
            (height-plist[i][1]*yunitlength-origin[1])+" ";
516
            (height-plist[i][1]*yunitlength-origin[1])+" ";
517
  }
517
  }
518
  node.setAttribute("d", st);
518
  node.setAttribute("d", st);
519
  node.setAttribute("stroke-width", strokewidth);
519
  node.setAttribute("stroke-width", strokewidth);
520
  if (strokedasharray!=null)
520
  if (strokedasharray!=null)
521
    node.setAttribute("stroke-dasharray", strokedasharray);
521
    node.setAttribute("stroke-dasharray", strokedasharray);
522
  node.setAttribute("stroke", stroke);
522
  node.setAttribute("stroke", stroke);
523
  node.setAttribute("fill", fill);
523
  node.setAttribute("fill", fill);
524
  if (marker=="dot" || marker=="arrowdot")
524
  if (marker=="dot" || marker=="arrowdot")
525
    for (i=0; i<plist.length; i++)
525
    for (i=0; i<plist.length; i++)
Line 545... Line 545...
545
  node.setAttribute("stroke-width", strokewidth);
545
  node.setAttribute("stroke-width", strokewidth);
546
  node.setAttribute("stroke", stroke);
546
  node.setAttribute("stroke", stroke);
547
  node.setAttribute("fill", fill);
547
  node.setAttribute("fill", fill);
548
}
548
}
549
 
549
 
550
function loop(p,d,id) {
550
function loop(p,d,id) {
551
// d is a direction vector e.g. [1,0] means loop starts in that direction
551
// d is a direction vector e.g. [1,0] means loop starts in that direction
552
  if (d==null) d=[1,0];
552
  if (d==null) d=[1,0];
553
  path([p,[p[0]+d[0],p[1]+d[1]],[p[0]-d[1],p[1]+d[0]],p],id,"C");
553
  path([p,[p[0]+d[0],p[1]+d[1]],[p[0]-d[1],p[1]+d[0]],p],id,"C");
554
  if (marker=="arrow" || marker=="arrowdot")
554
  if (marker=="arrow" || marker=="arrowdot")
555
    arrowhead([p[0]+Math.cos(1.4)*d[0]-Math.sin(1.4)*d[1],
555
    arrowhead([p[0]+Math.cos(1.4)*d[0]-Math.sin(1.4)*d[1],
556
               p[1]+Math.sin(1.4)*d[0]+Math.cos(1.4)*d[1]],p);
556
               p[1]+Math.sin(1.4)*d[0]+Math.cos(1.4)*d[1]],p);
557
}
557
}
558
 
558
 
559
function arc(start,end,radius,id) { // coordinates in units
559
function arc(start,end,radius,id) { // coordinates in units
Line 605... Line 605...
605
  node.setAttribute("stroke", stroke);
605
  node.setAttribute("stroke", stroke);
606
  node.setAttribute("fill", fill);
606
  node.setAttribute("fill", fill);
607
}
607
}
608
 
608
 
609
function rect(p,q,id,rx,ry) { // opposite corners in units, rounded by radii
609
function rect(p,q,id,rx,ry) { // opposite corners in units, rounded by radii
610
  var node;
610
  var node;
611
  if (id!=null) node = doc.getElementById(id);
611
  if (id!=null) node = doc.getElementById(id);
612
  if (node==null) {
612
  if (node==null) {
613
    node = myCreateElementSVG("rect");
613
    node = myCreateElementSVG("rect");
614
    node.setAttribute("id", id);
614
    node.setAttribute("id", id);
615
    svgpicture.appendChild(node);
615
    svgpicture.appendChild(node);
616
  }
616
  }
Line 636... Line 636...
636
      dx = fontsize/2;
636
      dx = fontsize/2;
637
    }
637
    }
638
    if (pos.slice(0,4)=="left" || pos.slice(5,9)=="left") {
638
    if (pos.slice(0,4)=="left" || pos.slice(5,9)=="left") {
639
      textanchor = "end";
639
      textanchor = "end";
640
      dx = -fontsize/2;
640
      dx = -fontsize/2;
641
    }
641
    }
642
  }
642
  }
643
  var node;
643
  var node;
644
  if (id!=null) node = doc.getElementById(id);
644
  if (id!=null) node = doc.getElementById(id);
645
  if (node==null) {
645
  if (node==null) {
646
    node = myCreateElementSVG("text");
646
    node = myCreateElementSVG("text");
647
    node.setAttribute("id", id);
647
    node.setAttribute("id", id);
Line 657... Line 657...
657
  node.setAttribute("font-weight",fontweight);
657
  node.setAttribute("font-weight",fontweight);
658
  node.setAttribute("text-anchor",textanchor);
658
  node.setAttribute("text-anchor",textanchor);
659
  if (fontstroke!="none") node.setAttribute("stroke",fontstroke);
659
  if (fontstroke!="none") node.setAttribute("stroke",fontstroke);
660
  if (fontfill!="none") node.setAttribute("fill",fontfill);
660
  if (fontfill!="none") node.setAttribute("fill",fontfill);
661
  return p;
661
  return p;
662
}
662
}
663
 
663
 
664
function ASdot(center,radius,s,f) { // coordinates in units, radius in pixel
664
function ASdot(center,radius,s,f) { // coordinates in units, radius in pixel
665
  if (s==null) s = stroke; if (f==null) f = fill;
665
  if (s==null) s = stroke; if (f==null) f = fill;
666
  var node = myCreateElementSVG("circle");
666
  var node = myCreateElementSVG("circle");
667
  node.setAttribute("cx",center[0]*xunitlength+origin[0]);
667
  node.setAttribute("cx",center[0]*xunitlength+origin[0]);
668
  node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
668
  node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
Line 688... Line 688...
688
      node.setAttribute("d",
688
      node.setAttribute("d",
689
        " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy+
689
        " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy+
690
        " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
690
        " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
691
      node.setAttribute("stroke-width", .5);
691
      node.setAttribute("stroke-width", .5);
692
      node.setAttribute("stroke", axesstroke);
692
      node.setAttribute("stroke", axesstroke);
693
    } else {
693
    } else {
694
      if (typ=="-") node.setAttribute("d",
694
      if (typ=="-") node.setAttribute("d",
695
        " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy);
695
        " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy);
696
      else node.setAttribute("d",
696
      else node.setAttribute("d",
697
        " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
697
        " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
698
      node.setAttribute("stroke-width", strokewidth);
698
      node.setAttribute("stroke-width", strokewidth);
Line 709... Line 709...
709
    node.setAttribute("r",dotradius);
709
    node.setAttribute("r",dotradius);
710
    node.setAttribute("stroke-width", strokewidth);
710
    node.setAttribute("stroke-width", strokewidth);
711
    node.setAttribute("stroke", stroke);
711
    node.setAttribute("stroke", stroke);
712
    node.setAttribute("fill", (typ=="open"?"white":stroke));
712
    node.setAttribute("fill", (typ=="open"?"white":stroke));
713
  }
713
  }
714
  if (label!=null)
714
  if (label!=null)
715
    text(center,label,(pos==null?"below":pos),(id==null?id:id+"label"))
715
    text(center,label,(pos==null?"below":pos),(id==null?id:id+"label"))
716
}
716
}
717
 
717
 
718
function arrowhead(p,q) { // draw arrowhead at q (in units)
718
function arrowhead(p,q) { // draw arrowhead at q (in units)
719
  var up;
719
  var up;
Line 729... Line 729...
729
      (w[1]-15*u[1]-4*up[1])+" L "+(w[0]-3*u[0])+" "+(w[1]-3*u[1])+" L "+
729
      (w[1]-15*u[1]-4*up[1])+" L "+(w[0]-3*u[0])+" "+(w[1]-3*u[1])+" L "+
730
      (w[0]-15*u[0]+4*up[0])+" "+(w[1]-15*u[1]+4*up[1])+" z");
730
      (w[0]-15*u[0]+4*up[0])+" "+(w[1]-15*u[1]+4*up[1])+" z");
731
    node.setAttribute("stroke-width", markerstrokewidth);
731
    node.setAttribute("stroke-width", markerstrokewidth);
732
    node.setAttribute("stroke", stroke); /*was markerstroke*/
732
    node.setAttribute("stroke", stroke); /*was markerstroke*/
733
    node.setAttribute("fill", stroke); /*was arrowfill*/
733
    node.setAttribute("fill", stroke); /*was arrowfill*/
734
    svgpicture.appendChild(node);    
734
    svgpicture.appendChild(node);
735
  }
735
  }
736
}
736
}
737
 
737
 
738
function chopZ(st) {
738
function chopZ(st) {
739
  var k = st.indexOf(".");
739
  var k = st.indexOf(".");
Line 854... Line 854...
854
  st = st.replace(/([^a-zA-Z])e([^a-zA-Z])/g,"$1(E)$2");
854
  st = st.replace(/([^a-zA-Z])e([^a-zA-Z])/g,"$1(E)$2");
855
  st = st.replace(/([0-9])([\(a-zA-Z])/g,"$1*$2");
855
  st = st.replace(/([0-9])([\(a-zA-Z])/g,"$1*$2");
856
  st = st.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
856
  st = st.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
857
  var i,j,k, ch, nested;
857
  var i,j,k, ch, nested;
858
  while ((i=st.indexOf("^"))!=-1) {
858
  while ((i=st.indexOf("^"))!=-1) {
859
    //find left argument
859
    //find left argument
860
    if (i==0) return "Error: missing argument";
860
    if (i==0) return "Error: missing argument";
861
    j = i-1;
861
    j = i-1;
862
    ch = st.charAt(j);
862
    ch = st.charAt(j);
863
    if (ch>="0" && ch<="9") {// look for (decimal) number
863
    if (ch>="0" && ch<="9") {// look for (decimal) number
864
      j--;
864
      j--;
865
      while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
865
      while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
866
      if (ch==".") {
866
      if (ch==".") {
867
        j--;
867
        j--;
868
        while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
868
        while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
869
      }
869
      }
870
    } else if (ch==")") {// look for matching opening bracket and function name
870
    } else if (ch==")") {// look for matching opening bracket and function name
871
      nested = 1;
871
      nested = 1;
872
      j--;
872
      j--;
873
      while (j>=0 && nested>0) {
873
      while (j>=0 && nested>0) {
874
        ch = st.charAt(j);
874
        ch = st.charAt(j);
875
        if (ch=="(") nested--;
875
        if (ch=="(") nested--;
876
        else if (ch==")") nested++;
876
        else if (ch==")") nested++;
877
        j--;
877
        j--;
878
      }
878
      }
879
      while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
879
      while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
880
        j--;
880
        j--;
881
    } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
881
    } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
882
      j--;
882
      j--;
883
      while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
883
      while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
884
        j--;
884
        j--;
885
    } else {
885
    } else {
886
      return "Error: incorrect syntax in "+st+" at position "+j;
886
      return "Error: incorrect syntax in "+st+" at position "+j;
887
    }
887
    }
888
    //find right argument
888
    //find right argument
889
    if (i==st.length-1) return "Error: missing argument";
889
    if (i==st.length-1) return "Error: missing argument";
890
    k = i+1;
890
    k = i+1;
Line 907... Line 907...
907
      }
907
      }
908
    } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
908
    } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
909
      k++;
909
      k++;
910
      while (k<st.length && (ch=st.charAt(k))>="a" && ch<="z" ||
910
      while (k<st.length && (ch=st.charAt(k))>="a" && ch<="z" ||
911
               ch>="A" && ch<="Z") k++;
911
               ch>="A" && ch<="Z") k++;
912
    } else {
912
    } else {
913
      return "Error: incorrect syntax in "+st+" at position "+k;
913
      return "Error: incorrect syntax in "+st+" at position "+k;
914
    }
914
    }
915
    st = st.slice(0,j+1)+"pow("+st.slice(j+1,i)+","+st.slice(i+1,k)+")"+
915
    st = st.slice(0,j+1)+"pow("+st.slice(j+1,i)+","+st.slice(i+1,k)+")"+
916
           st.slice(k);
916
           st.slice(k);
917
  }
917
  }
Line 919... Line 919...
919
    //find left argument
919
    //find left argument
920
    if (i==0) return "Error: missing argument";
920
    if (i==0) return "Error: missing argument";
921
    j = i-1;
921
    j = i-1;
922
    ch = st.charAt(j);
922
    ch = st.charAt(j);
923
    if (ch>="0" && ch<="9") {// look for (decimal) number
923
    if (ch>="0" && ch<="9") {// look for (decimal) number
924
      j--;
924
      j--;
925
      while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
925
      while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
926
      if (ch==".") {
926
      if (ch==".") {
927
        j--;
927
        j--;
928
        while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
928
        while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
929
      }
929
      }
Line 940... Line 940...
940
        j--;
940
        j--;
941
    } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
941
    } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
942
      j--;
942
      j--;
943
      while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
943
      while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
944
        j--;
944
        j--;
945
    } else {
945
    } else {
946
      return "Error: incorrect syntax in "+st+" at position "+j;
946
      return "Error: incorrect syntax in "+st+" at position "+j;
947
    }
947
    }
948
    st = st.slice(0,j+1)+"factorial("+st.slice(j+1,i)+")"+st.slice(i+1);
948
    st = st.slice(0,j+1)+"factorial("+st.slice(j+1,i)+")"+st.slice(i+1);
949
  }
949
  }
950
  return st;
950
  return st;
Line 952... Line 952...
952
 
952
 
953
function plot(fun,x_min,x_max,points,id) {
953
function plot(fun,x_min,x_max,points,id) {
954
  var pth = [];
954
  var pth = [];
955
  var f = function(x) { return x }, g = fun;
955
  var f = function(x) { return x }, g = fun;
956
  var name = null;
956
  var name = null;
957
  if (typeof fun=="string")
957
  if (typeof fun=="string")
958
    eval("g = function(x){ with(Math) return "+mathjs(fun)+" }");
958
    eval("g = function(x){ with(Math) return "+mathjs(fun)+" }");
959
  else if (typeof fun=="object") {
959
  else if (typeof fun=="object") {
960
    eval("f = function(t){ with(Math) return "+mathjs(fun[0])+" }");
960
    eval("f = function(t){ with(Math) return "+mathjs(fun[0])+" }");
961
    eval("g = function(t){ with(Math) return "+mathjs(fun[1])+" }");
961
    eval("g = function(t){ with(Math) return "+mathjs(fun[1])+" }");
962
  }
962
  }
Line 976... Line 976...
976
  return p;
976
  return p;
977
}
977
}
978
 
978
 
979
function slopefield(fun,dx,dy) {
979
function slopefield(fun,dx,dy) {
980
  var g = fun;
980
  var g = fun;
981
  if (typeof fun=="string")
981
  if (typeof fun=="string")
982
    eval("g = function(x,y){ with(Math) return "+mathjs(fun)+" }");
982
    eval("g = function(x,y){ with(Math) return "+mathjs(fun)+" }");
983
  var gxy,x,y,u,v,dz;
983
  var gxy,x,y,u,v,dz;
984
  if (dx==null) dx=1;
984
  if (dx==null) dx=1;
985
  if (dy==null) dy=1;
985
  if (dy==null) dy=1;
986
  dz = Math.sqrt(dx*dx+dy*dy)/6;
986
  dz = Math.sqrt(dx*dx+dy*dy)/6;
Line 1035... Line 1035...
1035
  function() {updateCoords(6)},
1035
  function() {updateCoords(6)},
1036
  function() {updateCoords(7)},
1036
  function() {updateCoords(7)},
1037
  function() {updateCoords(8)},
1037
  function() {updateCoords(8)},
1038
  function() {updateCoords(9)}];
1038
  function() {updateCoords(9)}];
1039
 
1039
 
1040
// GO1.1 Generic onload by Brothercake 
1040
// GO1.1 Generic onload by Brothercake
1041
// http://www.brothercake.com/
1041
// http://www.brothercake.com/
1042
//onload function
1042
//onload function
1043
function generic()
1043
function generic()
1044
{
1044
{
1045
  drawPictures();
1045
  drawPictures();