jquery - Improving speed and data efficiency with javascript calculator. -
i'm building javascript calculator (with jquery mobile) simplifying routine calculations in microscopy. i'm looking create more efficient code , love input... don't expect dig through whole thing, here link programme reference: http://www.iscopecalc.com
(the javascript calculator @ http://www.iscopecalc.com/js/calc.js )
the calculator consists of 12 inputs user can set. using values received these inputs, calculator generates values 15 different parameters , outputs results in display. currently, whenever state of input changes, bind alter event quick function writes value input cookie. meat of programme comes "updatecalc()" function reads values of inputs (from stored cookies) , recalculates every 1 of parameters displayed , outputs them. i've coped function here ease of access:
function updatecalc(){ readvalues(); //load current calculator state cookies var info = $.cookie(); //puts cookie info object var fluordata = fluorotable[data['fluorophore']]; //fluorophore info taken table @ end of file depending on chosen fluorophore var fluorem = fluordata['fluorem']; var fluorex = fluordata['fluorex']; var cameradata = cameratable[data['camera']]; //camera info taken table @ end of file depending on chosen photographic camera var campix = cameradata['campix']; var chipwidth = cameradata['chipwidth']; var chipheight = cameradata['chipheight']; var chiphpix = cameradata['chiphpix']; var chipvpix = cameradata['chipvpix']; var refind = data['media']; //simple variables taken straight calculator inputs var na = data['naslider']; var obj = data['objective']; var cammag = data['camerarelay']; var csumag = data['csurelay']; var bin = data['binning']; var pinholerad; var fovlimit; var mode; if (data['modality']=='widefield'){ //fovlimit, pinholerad, , csu mag depend on modality chosen fovlimit = 28; pinholerad = nan; mode = 'widefield'; csumag = 1; } else if (data['modality']=='confocal'){ if (data['csumodel']=='x1'){ pinholerad = 25; if(data['borealis']=='true'){ mode = "borealis csu-x1"; fovlimit = 9; } else { mode = "yokogawa csu-x1"; fovlimit = 7; csumag = 1; } } else if (data['csumodel']=='w1'){ mode = "yokogawa csu-w1"; fovlimit = 16; pinholerad = data['w1-disk']/2; csumag = 1; } } //these main outputs , depend on input variables above var latres = 0.61 * fluorem / na; var axres = 1.4 * fluorem * refind / (na*na); var bppinhole = 1000 * pinholerad / (obj * csumag); var au = bppinhole / latres; var totalmag = obj * cammag * csumag; var bppixel = 1000 * campix * bin / totalmag; var samples = latres / bppixel; var pixperpin = bppinhole * 2 / bppixel; var samplit = 1000 * fovlimit / (obj * csumag); var coverage = fovlimit * cammag / chipheight; if (coverage < 1) { chipused = coverage; fov = samplit; } else { chipused = 1; fov = samplit * chipheight / (fovlimit * cammag); } var sampwaste = 1 - fov / samplit; var imgpix = 1000 * fov / (chipvpix / bin); //function goes on update display calculated values... }
it works ok , i'm pleased results here's i'd advice on:
each of input variables affects handful of outputs (for instance, alter in input #3 alter calculation few of outputs... not 15), however, function recalculates outputs everytime of inputs changed, regardless of relevance... i've considered making giant if-then function selectively update outputs have changed based on input changed. take larger amount of code, i'm wondering if (once loaded) code faster when using calculator, of if waste of time , clutter code.
i'm wondering if storing inputs in cookies , reading values cookies reasonable way things , if should maybe create global variable instead stores state of calculator. (the cookies have added benefit of storing users calculator state later visits).
i'm pretty new @ stuff, , comments on how might improve efficiency of code appreciated (feel free link page should read, or method should using instance...)
if you've made far, time!!
javascript jquery jquery-mobile performance
No comments:
Post a Comment