' + txt + '<\/div>'
);
}
function gReplace(x)
{
return x.replace(/%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]*);([^;]+);([^%%]*)/g,
'
');
}
function paint(cnv, htm, add)
{
if (cnv)
{
if (add)
{
var o;
if (g_adhtm) cnv.insertAdjacentHTML("BeforeEnd", gReplace(htm));
else if (g_dom)
{
o = document.createRange();
o.setStartBefore(cnv);
o = o.createContextualFragment(htm);
cnv.appendChild(o);
}
else cnv.innerHTML += htm;
}
else cnv.innerHTML = g_ie? gReplace(htm) : htm;
}
}
function scaleY(x)
{
return (Math.min(Math.max(g_h+Math.round((g_ya-x)/g_dy), -1), g_h+1));
}
function mkTerm(x)
{
x = x.toLowerCase().replace(/\s/g,'').
replace(/f(\(|\{|\[)x(\)|\}|\])\=/g, '').
replace(/math\./g,'').
replace(/\.*\;+/g,';').
replace(/[\.\;]*$/,'').
replace(/\|([^\|]*)\|/g,'abs($1)').
replace(/:/g,'\/').
replace(/²/g,'^2').
replace(/³/g,'^3').
replace(/[\"\']/g,'^').
replace(/e/g,'E').
replace(/log(\d)/g,'LOG$1').
replace(/ln(\d)/g,'LN$1').
replace(/arc(us)?|arEa|ar/g,'a').
replace(/hyp(Erbolicus)?/g,'h').
replace(/cosin(us|E)?/g,'cos').
replace(/sin(us|E)/g,'sin').
replace(/sEc(an(s|t))?/g,'sec').
replace(/cosec/g,'csc').
replace(/tangEn[st]/g,'tan').
replace(/cotan/g,'cot').
replace(/random(\(|\{|\[)(\)|\}|\])|rand(om)?/g,'random()').
replace(/(p|power)(\(|\{|\[)/g,'pow$2').
replace(/(b|q)r(\(|\{|\[)/g,'$1rt$2').
replace(/(sqr|sqrt)(\d)/g,'SQRT$2').
replace(/tan2/g, 'tanz').
replace(/max/g,'maz').
replace(/pi/g,'PI').
replace(/phi/g,'PHI').
replace(/y/,'nuts').
replace(/cEil/g,'ceil').
replace(/Expow|Exp/g,'exp').
replace(/([^m]|^)(\(|\{|\[)(\)|\}|\])/g,'$1$2x$3').
replace(/(\(|\{|\[)\,/g,'$1x,').
replace(/\,(\)|\}|\])/g,',x$1').
replace(/\,\,/g,',x,');
x = x.replace(/([^G]\d\d|[^G\d]\d|^\d|^\d\d)E/g,'$1*E');
x = x.replace(/(RT1_2|RT2|LN10|LN2)(\d)/g,'$1*$2');
var reg = /(x|E|PI|\)|\}|\])(E|\d)/g;
while (x.match(reg)) x = x.replace(reg,'$1*$2');
reg = /(\d|E|PI|x|\)|\}|\])(\(|\{|\[|x|a|c|exp|f|gaus|l|m|pow|r|s|tan|L|PI|SQRT)/g;
while (x.match(reg)) x = x.replace(reg,'$1*$2');
x = x.replace(/tanz/g,'tan2').replace(/maz/g,'max');
return x;
}
function WzMath()
{
this.PHI = 1.6180339887498948482045868343656;
this.root = function(x, xp) {return Math.pow(x, 1/xp);};
this.cbrt = function(x) {return Math.pow(x, 1/3);};
this.logn = function(x, bs) {return Math.log(x)/Math.log(bs);};
this.ln = function(x) {return Math.log(x);};
this.lg = function (x) {return Math.log(x)/Math.LN10;};
this.lb = function(x) {return Math.log(x)/Math.LN2;};
this.cot = function(x) {return Math.cos(x)/Math.sin(x);};
this.sec = function(x) {return 1/Math.cos(x);};
this.csc = function(x) {return 1/Math.sin(x);};
this.acot = function(x) {return Math.atan(-x)+Math.PI/2;};
this.asec = function(x) {return Math.acos(1/x);};
this.acsc = function(x) {return Math.asin(1/x);};
this.sinh = function(x) {return (Math.exp(x)-Math.exp(-x))/2;};
this.cosh = function(x) {return (Math.exp(x)+Math.exp(-x))/2;};
this.sech = function(x) {return 2/(Math.exp(x)+Math.exp(-x));};
this.csch = function(x) {return 2/(Math.exp(x)-Math.exp(-x));};
this.tanh = function(x) {return (Math.exp(2*x)-1)/(Math.exp(2*x)+1);};
this.coth = function(x) {return (Math.exp(2*x)+1)/(Math.exp(2*x)-1);};
this.asinh = function(x) {return Math.log(x+Math.sqrt(x*x+1));};
this.acosh = function(x) {return Math.log(x+Math.sqrt(x*x-1));};
this.atanh = function(x) {return Math.log((1+x)/(1-x))/2;};
this.acoth = function(x) {return Math.log((x+1)/(x-1))/2;};
this.asech = function(x) {return Math.log(1/x+Math.sqrt(1/(x*x)-1));};
this.acsch = function(x) {return Math.log(1/x+Math.sqrt(1/(x*x)+1));};
this.gaussd = function(x,m,s) {return 1/(s*2.5066282746310002)*Math.exp(-(x -= m)*x/(2*s*s));};
this.sgn = function(x) {return (x < 0)? -1 : (x > 0)? 1 : 0;};
this.fact = function(x)
{
x = Math.round(Math.abs(x));
if (x > 1) return x*this.fact(x-1);
return 1;
};
}
WzMath.prototype = Math;
WzMath = new WzMath();
function mkPow(x)
{
x = x.replace(/\{|\[/g,'(').replace(/\}|\]/g,')');
while (/\^/.test(x))
{
var az = x.search(/\^/),
a = x.substring(0, az), z = x.substring(az+1),
p = 0, ch, lim = az-1;
while (true)
{
ch = a.charAt(lim);
if (ch == ')') p++;
else if (ch == '(') p--;
if (p < 0 || !p && (!(lim+1) || /[\+\-\*\/\,]/.test(ch))) break;
lim--;
}
a = a.substring(0, lim+1) + 'pow(' + a.substring(lim+1, az);
lim = 0; p = 0;
while (true)
{
ch = z.charAt(lim);
if (ch == '(') p++;
else if (ch == ')') p--;
if (p < 0 || !p && (lim == z.length || lim > 0 && /[\+\-\*\/\^\,]/.test(ch))) break;
lim++;
}
z = z.substring(0, lim) + ')' + z.substring(lim);
x = a+','+z;
}
return x;
}
Number.prototype.lim = function(i, j, xdir, ydir)
{
var yy = parseFloat(this), y,
incr = g_dx/100, _incr = incr*xdir, qt = 1, lim = (g_xa+(j+xdir)*g_dx),
x = g_xa+j*g_dx;
while (qt < 0x100000 && !!((xdir < 0)? (x-lim > 0) : (x-lim < 0)))
{
x += _incr;
y = gEval(x, g_term[i]);
if (isNum(y) && y*ydir-yy*ydir > 0) yy = y;
else
{
x -= _incr;
_incr = incr*xdir/(qt <<= 3);
}
}
return yy;
}
function gEval(x, term, y)
{
with (WzMath) return Math.min(Math.max(parseFloat(eval(term)),-g_infin),g_infin);
}
function mkGraph(f)
{
if (!g_cnv)
{
alert(S_OLDBROWSER);
return;
}
g_htm = '';
var xa = getVal(f.XA),
xz = getVal(f.XZ);
if (!isNum(xa)) return alertErr(f.XA, 'x min');
if (!isNum(xz)) return alertErr(f.XZ, 'x max');
if (xa >= xz) return alertErr(f.XA, S_ERR_XRANGE);
if (!f.Add.checked) g_n = 0;
if (!g_n)
{
var ya = getVal(f.YA),
yz = getVal(f.YZ);
if (!isNum(ya) && ya != '') return alertErr(f.YA, 'y min');
if (!isNum(yz) && yz != '') return alertErr(f.YZ, 'y max');
if (isNum(ya) && isNum(yz) && ya >= yz) return alertErr(f.YA, S_ERR_YRANGE);
fitWnd();
g_xa = xa;
g_xz = xz;
g_dx = (xz-xa)/g_w;
g_ya = ya;
g_yz = yz;
if (!isNum(ya)) ya = g_infin;
if (!isNum(yz)) yz = -g_infin;
delGraphs();
}
g_term = mkTerm(f.F.value).split(';');
var term = [];
var yy = [], y;
try
{
for (i = 0; i < g_term.length; i++)
{
g_term[i] = mkPow(term[i] = g_term[i]);
while (true)
{
var coms = (g_term[i].match(/\,/g) || []).length, meths = (g_term[i].match(/pow|min|max|atan2|root|logn|gau|ssd?/g) || []).length;
if (coms > meths && g_term[i].match(/\d+\,\d/)) return alertErr(f.F, S_ERR_TDECI);
else if (coms > meths) return alertErr(f.F, S_ERR_TCOMM);
else if (coms < meths) return alertErr(f.F, S_ERR_TMISSCOMM);
else break;
}
if (/\|/.test(g_term[i])) return alertErr(f.F, S_ERR_TPIPE);
if ((g_term[i].match(/\(/g) || []).length != (g_term[i].match(/\)/g) || []).length) return alertErr(f.F, S_ERR_TPARENTH);
var rand = !(g_term[i].indexOf('ran') < 0);
yy[i] = [];
yy[i][g_w] = gEval(g_xz, g_term[i]);
var j = g_w+1; while (j--)
{
if (j) yy[i][j-1] = gEval(g_xa+(j-1)*g_dx, g_term[i]);
if (isNum(y = yy[i][j]))
{
if (!rand)
{
if (isNum(yy[i][j-1]) && isNum(yy[i][j+1]))
{
if (yy[i][j-1] < 0 && y > 0 && yy[i][j+1]-y < 0)
y = y.lim(i,j,-1,1);
else if (yy[i][j-1] > 0 && y < 0 && yy[i][j+1]-y > 0)
y = y.lim(i,j,-1,-1);
else if (yy[i][j+1] > 0 && y < 0 && yy[i][j-1]-y > 0)
y = y.lim(i,j,1,-1);
else if (yy[i][j+1] < 0 && y > 0 && yy[i][j-1]-y < 0)
y = y.lim(i,j,1,1);
}
else if (j-g_w && !isNum(yy[i][j+1]) && isNum(yy[i][j-1]))
y = y.lim(i,j,1,(y-yy[i][j-1] > 0)? 1 : -1);
else if (j && !isNum(yy[i][j-1]) && isNum(yy[i][j+1]))
y = y.lim(i,j,-1,(y-yy[i][j+1] > 0)? 1 : -1);
yy[i][j] = y;
}
if (!isNum(g_ya)) ya = Math.min(ya, y);
if (!isNum(g_yz)) yz = Math.max(yz, y);
}
}
}
}
catch (err)
{
alertErr(f.F, S_ERR_TERM);
return;
}
if (!g_n)
{
g_yz = yz;
g_ya = ya;
var oldh = g_h;
if (document.forms.fo.XYRATIO.checked)
{
g_dy = g_dx;
var h = (g_yz-g_ya)/g_dy;
if (h > 100*g_w)
{
if (g_ya < 0 && g_ya < -g_w*g_dy) g_ya *= 100*g_w/h;
if (g_yz > 0 && g_yz > g_w*g_dy) g_yz *= 100*g_w/h;
}
if (h-1 < 0) g_ya -= g_dy;
g_h = Math.round((g_yz-g_ya)/g_dy);
}
else
{
if (!(g_yz-g_ya))
{
g_ya -= (g_xz-g_xa)/2;
g_yz += (g_xz-g_xa)/2;
}
g_h = g_w;
g_dy = (g_yz-g_ya)/g_h;
}
if (oldh != g_h) resizeCnv();
mkScale();
}
var termhtm = '', ci = 0, x;
//var t0 = (new Date()).getTime();
for (i = 0; i < g_term.length; i++)
{
var c = '#' + GRAPHCOLOR[(ci++)%GRAPHCOLOR.length];
var tp, bot;
var ox = g_w+1;
var oy = '';
var ny = (isNum(yy[i][g_w]))? scaleY(yy[i][g_w]) : '';
x = g_w+1; while (x--)
{
y = ny;
ny = (x && isNum(yy[i][x-1]))? scaleY(yy[i][x-1]) : '';
if (isNum(y))
{
if (!isNum(oy)) oy = y;
if (!isNum(ny))
{
if (ox-x-1 || !(oy-y))
{
tp = y;
bot = y+1;
}
else if (oy-y < 0)
{
tp = oy;
bot = y+1;
}
else
{
tp = y;
bot = oy;
}
g_htm += mkDiv('', '', x, tp, ox-x, bot-tp, c, '', false, true);
ox = x;
oy = '';
}
else if (ny-y > 0)
{
if (ox-x-1)
{
bot = y+1;
tp = y;
}
else if ((oy-y > 0 || !(oy-y) && y < 0) && ny > oy && (isNum(yy[i][x-2])? yy[i][x-2]-yy[i][x-1] >= 0 : true))
{
tp = y;
bot = !isNum(yy[i][x+1])? ny : oy;
}
else
{
if (isNum(yy[i][x-2]) && scaleY(yy[i][x-2])-ny <= 0) bot = ny;
else bot = y+Math.round((ny-y)/2);
tp = (oy-y > 0)? y : oy;
}
g_htm += mkDiv('', '', x, tp, ox-x, bot-tp, c, '', false, true);
oy = bot;
ox = x;
}
else if (ny-y < 0)
{
if (ox-x-1)
{
tp = y;
bot = y+1;
}
else if ((oy-y < 0 || !(oy-y) && y-g_h > 0) && ny < oy)
{
tp = !isNum(yy[i][x+1])? ny+1 : oy;
bot = y+1;
}
else
{
if (isNum(yy[i][x-2]) && scaleY(yy[i][x-2])-ny >= 0) tp = ny+1;
else tp = y-Math.floor((y-ny)/2);
bot = (oy-y <= 0)? y+1 : oy;
}
g_htm += mkDiv('', '', x, tp, ox-x, bot-tp, c, '', false, true);
oy = tp;
ox = x;
}
}
else
{
oy = '';
ox = x;
}
}
//term[i] = g_term[i];
termhtm += ('' + term[i].replace(/random\(\)/g,'rand').replace(/pow/g,'p').replace(/log\(/g,'ln(').replace(/rt\(/g,'r(').replace(/RT/g,'R') + '<\/b><\/small>
');
g_n ++;
}
paint(g_cnv, g_htm, true);
//alert((new Date()).getTime()-t0);
paint(g_termlyr, termhtm, true);
if (!g_coordtip) initCoordtip();
}
function coordTip(e)
{
if (g_wait) return;
g_wait = 1;
setTimeout('g_wait = 0;', 1);
var x = (e = e || window.event).pageX || e.clientX || 0,
y = e.pageY || e.clientY || 0;
if (g_ie || g_kq)
{
x += g_db.scrollLeft-(g_ie && !g_iemac)*2;
y += g_db.scrollTop-(g_ie && !g_iemac)*2;
}
if (x-g_pageX >= 0 && x-g_pageX-g_w <= 0 && y-g_pageY >= 0 && y-g_pageY-g_h <= 0)
{
g_coordtip.style.left = (x+16)+'px';
g_coordtip.style.top = (y-12)+'px';
paint(g_coordtip,
'x = '+
mkNumStr(x-g_pageX+Math.round(g_xa/g_dx), g_dx)+'
y = '+
mkNumStr(g_h-y+g_pageY+Math.round(g_ya/g_dy), g_dy)+' <\/small>',
false
);
if (g_coordtip.style.visibility == 'hidden') g_coordtip.style.visibility = 'visible';
}
else g_coordtip.style.visibility = 'hidden';
}
document.write(g_ie? gReplace(mkDiv('', '', 0, 0, 0, 0, '', 'coordtip', true)) : mkDiv('', '', 0, 0, 0, 0, '', 'coordtip', true));
window.onload = init;