source:
issm/oecreview/Archive/19101-20495/ISSM-19943-19944.diff@
20498
| Last change on this file since 20498 was 20498, checked in by , 10 years ago | |
|---|---|
| File size: 9.2 KB | |
-
../trunk-jpl/src/m/classes/plotoptions.js
5 5 6 6 function plotoptions(args) { 7 7 //methods 8 this.disp = function (){ // {{{9 console.log(sprintf('\nplotoptions = \n'));10 console.log(sprintf(' figurenumber: %i',this.figurenumber));11 console.log(sprintf(' numberofplots: %i',this.numberofplots));12 if (this.list.length){13 for (var i=0;i<this.list.length;i++){14 console.log(sprintf('\n options of plot number %i',i+1));15 this.list[i].disp();16 }17 }18 else{19 console.log(sprintf(' list: empty'));20 }21 }22 //}}}23 this.constructor = function (args){ // {{{8 this.disp = function (){ // {{{ 9 console.log(sprintf('\nplotoptions = \n')); 10 console.log(sprintf(' figurenumber: %i',this.figurenumber)); 11 console.log(sprintf(' numberofplots: %i',this.numberofplots)); 12 if (this.list.length){ 13 for (var i=0;i<this.list.length;i++){ 14 console.log(sprintf('\n options of plot number %i',i+1)); 15 this.list[i].disp(); 16 } 17 } 18 else{ 19 console.log(sprintf(' list: empty')); 20 } 21 } 22 //}}} 23 this.constructor = function (args){ // {{{ 24 24 25 //check length of input26 if (args.length % 2){27 for (i=0;i<args.length;i+=2){28 if (!(typeof args[i] === 'string')){29 console.log('Last valid option: ' + args[i-2]);30 break;31 }32 }33 throw Error('plotoptions error message: invalid parameter/value pair arguments');34 }25 //check length of input 26 if (args.length % 2){ 27 for (i=0;i<args.length;i+=2){ 28 if (!(typeof args[i] === 'string')){ 29 console.log('Last valid option: ' + args[i-2]); 30 break; 31 } 32 } 33 throw Error('plotoptions error message: invalid parameter/value pair arguments'); 34 } 35 35 36 //go through varargin and build list (like pairoptions)37 var rawoptions=new pairoptions(args);38 numoptions=rawoptions.numoptions();36 //go through varargin and build list (like pairoptions) 37 var rawoptions=new pairoptions(args); 38 numoptions=rawoptions.numoptions(); 39 39 40 var counter=0;41 for (i=0;i<numoptions;i++){42 if(typeof args[2*i] === 'string')counter++;43 }44 rawlist=Create2DArray(counter,2);45 var counter=0;46 for (i=0;i<numoptions;i++){47 optionname=args[2*i];48 optionval=args[2*i+1];49 if(typeof optionname === 'string'){50 rawlist[counter][0]=optionname;51 rawlist[counter][1]=optionval;52 counter++;53 }54 else{55 //option is not a string, ignore it56 console.log(sprintf("%s%i%s\n",'WARNING: option number ',i,' is not a string, it will be ignored'));57 rawlist[counter]=[];58 continue59 }60 }61 62 63 //get number of data to be plotted64 numberofplots=rawoptions.fieldoccurrences('data');65 this.numberofplots=numberofplots;40 var counter=0; 41 for (i=0;i<numoptions;i++){ 42 if(typeof args[2*i] === 'string')counter++; 43 } 44 rawlist=Create2DArray(counter,2); 45 var counter=0; 46 for (i=0;i<numoptions;i++){ 47 optionname=args[2*i]; 48 optionval=args[2*i+1]; 49 if(typeof optionname === 'string'){ 50 rawlist[counter][0]=optionname; 51 rawlist[counter][1]=optionval; 52 counter++; 53 } 54 else{ 55 //option is not a string, ignore it 56 console.log(sprintf("%s%i%s\n",'WARNING: option number ',i,' is not a string, it will be ignored')); 57 rawlist[counter]=[]; 58 continue 59 } 60 } 61 62 63 //get number of data to be plotted 64 numberofplots=rawoptions.fieldoccurrences('data'); 65 this.numberofplots=numberofplots; 66 66 67 //figure out wether alloptions flog is on68 if (rawoptions.getfieldvalue('alloptions','off') === 'on') allflag=1;69 else allflag=0;67 //figure out wether alloptions flog is on 68 if (rawoptions.getfieldvalue('alloptions','off') === 'on') allflag=1; 69 else allflag=0; 70 70 71 //initialize list72 var list=new Array(numberofplots);73 for (i=0;i<numberofplots;i++){74 list[i]=new pairoptions([]);75 }76 71 //initialize list 72 var list=new Array(numberofplots); 73 for (i=0;i<numberofplots;i++){ 74 list[i]=new pairoptions([]); 75 } 76 77 77 //process plot options 78 for(var i=0;i<rawlist.length;i++){78 for(var i=0;i<rawlist.length;i++){ 79 79 80 //If alloptions flag has is on, apply to all plots81 if (allflag & !(rawlist[i][0] === 'data') & (rawlist[i][0].indexOf('#') == -1)){82 for(var j=0;j<numberofplots;j++){83 list[j].addfield(rawlist[i][0],rawlist[i][1]);84 }85 }86 else if (rawlist[i][0].indexOf('#') != -1){ //option contains '#'80 //If alloptions flag has is on, apply to all plots 81 if (allflag & !(rawlist[i][0] === 'data') & (rawlist[i][0].indexOf('#') == -1)){ 82 for(var j=0;j<numberofplots;j++){ 83 list[j].addfield(rawlist[i][0],rawlist[i][1]); 84 } 85 } 86 else if (rawlist[i][0].indexOf('#') != -1){ //option contains '#' 87 87 88 //get suplot(s) associated89 string=rawlist[i][0].split('#');90 plotnums=string[1];91 field=string[0];88 //get suplot(s) associated 89 string=rawlist[i][0].split('#'); 90 plotnums=string[1]; 91 field=string[0]; 92 92 93 //divide plotnums if there is a comma ','94 plotnums=plotnums.split(',');93 //divide plotnums if there is a comma ',' 94 plotnums=plotnums.split(','); 95 95 96 //loop over plotnums97 for (k=0;k<plotnums.length;k++){98 plotnum=plotnums[k];96 //loop over plotnums 97 for (k=0;k<plotnums.length;k++){ 98 plotnum=plotnums[k]; 99 99 100 //Empty101 if (plotnum === '') continue;100 //Empty 101 if (plotnum === '') continue; 102 102 103 else if (plotnum === 'all'){ //pound all104 for(var j=0;j<numberofplots;j++){105 list[j].addfield(field,rawlist[i][1]);106 }107 }108 else if (plotnum.indexOf('-')!=-1){ //pound i-j109 nums=plotnum.split('-');110 if (nums.length!=2) continue;111 if ((nums[0] == '') | (nums[1] === '')){112 throw Error(sprintf("%s%s\n",'the option #i-j is not set properly for ',field));113 }114 for (j=(Number(nums[0])-1);j<(Number(nums[1])); j++){115 list[j].addfield(field,rawlist[i][1]);116 }117 }118 else{ //pound i119 //assign to subplot120 if (Number(plotnum)>numberofplots){103 else if (plotnum === 'all'){ //pound all 104 for(var j=0;j<numberofplots;j++){ 105 list[j].addfield(field,rawlist[i][1]); 106 } 107 } 108 else if (plotnum.indexOf('-')!=-1){ //pound i-j 109 nums=plotnum.split('-'); 110 if (nums.length!=2) continue; 111 if ((nums[0] == '') | (nums[1] === '')){ 112 throw Error(sprintf("%s%s\n",'the option #i-j is not set properly for ',field)); 113 } 114 for (j=(Number(nums[0])-1);j<(Number(nums[1])); j++){ 115 list[j].addfield(field,rawlist[i][1]); 116 } 117 } 118 else{ //pound i 119 //assign to subplot 120 if (Number(plotnum)>numberofplots){ 121 121 throw Error(sprintf("%s%s%s%i%s\n",'plotoptions error message: ',field,' cannot be assigned (',plotnum,' exceeds maximum number of plot)')); 122 }123 list[Number(plotnum)-1].addfield(field,rawlist[i][1]);124 }125 }126 }127 else{ //assign option field to corresponding subplot122 } 123 list[Number(plotnum)-1].addfield(field,rawlist[i][1]); 124 } 125 } 126 } 127 else{ //assign option field to corresponding subplot 128 128 129 130 //go through all subplot and assign to the first one free131 var inc=0;132 133 while (inc<numberofplots){129 130 //go through all subplot and assign to the first one free 131 var inc=0; 132 133 while (inc<numberofplots){ 134 134 135 if (!list[inc].exist(rawlist[i][0])){136 list[inc].addfield(rawlist[i][0],rawlist[i][1]);137 break138 }139 else inc++;140 }135 if (!list[inc].exist(rawlist[i][0])){ 136 list[inc].addfield(rawlist[i][0],rawlist[i][1]); 137 break 138 } 139 else inc++; 140 } 141 141 142 if (inc>numberofplots-1){143 console.log(sprintf("%s%s%s\n",'plot info message: too many ',rawlist[i][0],' options'));144 }145 }146 }142 if (inc>numberofplots-1){ 143 console.log(sprintf("%s%s%s\n",'plot info message: too many ',rawlist[i][0],' options')); 144 } 145 } 146 } 147 147 148 //check that there is no duplicates149 for (var i=0;i<numberofplots;i++) list[i].deleteduplicates();148 //check that there is no duplicates 149 for (var i=0;i<numberofplots;i++) list[i].deleteduplicates(); 150 150 151 //allocate canvasid automatically 152 console.log(list); 153 for (var i=0;i<numberofplots;i++) { 151 //allocate canvasid automatically 152 for (var i=0;i<numberofplots;i++) { 154 153 if (!list[i].exist('canvasid')) { 155 154 list[i].addfield('canvasid',i); 156 155 } 157 156 } 158 157 159 //Get figure number (should be in options for subplot 1)160 this.figurenumber=list[0].getfieldvalue('figure',1);161 list[0].removefield('figure',0);158 //Get figure number (should be in options for subplot 1) 159 this.figurenumber=list[0].getfieldvalue('figure',1); 160 list[0].removefield('figure',0); 162 161 163 //asign output164 this.list=list;162 //asign output 163 this.list=list; 165 164 166 } //}}}167 //properties 168 // {{{169 this.numberofplots = 0;170 this.figurenumber = 1;171 this.list = [];172 this.constructor(args);173 //}}}165 } //}}} 166 //properties 167 // {{{ 168 this.numberofplots = 0; 169 this.figurenumber = 1; 170 this.list = []; 171 this.constructor(args); 172 //}}} 174 173 }
Note:
See TracBrowser
for help on using the repository browser.
![(please configure the [header_logo] section in trac.ini)](/trac/issm/chrome/common/trac_banner.png)