Changeset 23189 for issm/trunk/src/m/plot/applyoptions.js
- Timestamp:
- 08/28/18 09:45:51 (7 years ago)
- Location:
- issm/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk ¶
- Property svn:mergeinfo changed
/issm/trunk-jpl merged: 22823-22871,22873-22887,22894-22903,22905-23090,23092-23185,23187
- Property svn:mergeinfo changed
-
issm/trunk/src ¶
- Property svn:mergeinfo changed
-
TabularUnified issm/trunk/src/m/plot/applyoptions.js ¶
r22758 r23189 13 13 //{{{ Variable options initialization 14 14 var caxis = options.getfieldvalue('caxis'); 15 var colorbarinnerlabels = options.getfieldvalue('colorbarinnerlabels','off');16 15 var ccanvasid, ctitleid, clabelsid, ccanvas, ctitle, clabels, ccontext, cmap, colorbar, cwidth, cheight, cgradient, color, y, x; 17 16 //}}} … … 49 48 } //}}} 50 49 //{{{ Initialize colorbar canvas 51 ccanvasid = options.getfieldvalue('colorbarid', options.getfieldvalue('canvasid').replace('canvas','colorbar-canvas')); 50 let colorbarSlug = options.getfieldvalue('colorbarSlug', options.getfieldvalue('canvasid') + '-colorbar'); 51 ccanvasid = colorbarSlug + '-canvas'; 52 52 ccanvas = $('#'+ccanvasid)[0]; 53 53 cwidth = ccanvas.width*options.getfieldvalue('colorbarwidth', 1); … … 81 81 //}}} 82 82 //{{{ Draw colorbar labels 83 clabelsid = options.getfieldvalue('colorbarid', ccanvasid).replace('canvas','labels');83 clabelsid = colorbarSlug + '-labels'; 84 84 clabels = $('#'+clabelsid); 85 if (colorbarinnerlabels=='on') {86 clabels.removeClass('sim-colorbar-labels-outer');87 clabels.addClass('sim-colorbar-labels-inner');88 }89 else {90 clabels.removeClass('sim-colorbar-labels-inner');91 clabels.addClass('sim-colorbar-labels-outer');92 }93 85 var clabelstring = ''; 94 86 clabels.empty(); … … 107 99 //}}} 108 100 //{{{ Draw colorbar title 109 ctitleid = options.getfieldvalue('colorbarid', ccanvasid).replace('canvas','heading');101 ctitleid = colorbarSlug + '-heading'; 110 102 ctitle = $('#'+ctitleid); 111 if (options.exist('colorbar title')) { ctitle.html(options.getfieldvalue('colorbartitle')); }103 if (options.exist('colorbarHeader')) { ctitle.html(options.getfieldvalue('colorbarHeader')); } 112 104 //}}} 113 105 } … … 123 115 tcontext = tcanvas.getContext('2d'); 124 116 tgradient = tcontext.createLinearGradient(0, 0, 0, 256); 125 117 126 118 var cmap = options.getfieldvalue('colormap','jet'); 127 119 var colorbar = colorbars[cmap]; … … 133 125 tcontext.fillStyle = tgradient; 134 126 tcontext.fillRect(0, 0, 256, 256); 135 127 136 128 //Allow for special texture colors, drawing each color in equal width vertical rectangles. The last rectanglar section is reserved for the colormap. 137 129 if (options.exist('maskregion')) { 138 130 var maskObject = options.getfieldvalue('maskregion',{'enabled':false}); 139 if (maskObject.enabled && ! VESL.Helpers.isEmptyOrUndefined(maskObject.colors)) {131 if (maskObject.enabled && !vesl.helpers.isEmptyOrUndefined(maskObject.colors)) { 140 132 var x = 0; 141 133 var sections = Object.keys(maskObject.colors).length + 1; … … 148 140 } 149 141 } 150 142 151 143 tURL = tcanvas.toDataURL(); 152 144 if (options.getfieldvalue('clf','on')=='off') { … … 157 149 //}}} 158 150 //{{{ text display 159 var overlaycanvasid = options.getfieldvalue('overlayid', options.getfieldvalue('canvasid')+'-overlay'); 160 var overlaycanvas = $('#'+overlaycanvasid)[0]; 161 if (!VESL.Helpers.isEmptyOrUndefined(overlaycanvas)) { 151 var ctx; 152 var overlaycanvasid; 153 var overlaycanvas; 154 //Only intialize overlay canvas once by checking if it's already been defined 155 if (vesl.helpers.isEmptyOrUndefined(canvas.overlaycanvas)) { 162 156 //Get drawing context and save reference on main WebGL canvas 163 var ctx = overlaycanvas.getContext('2d'); 157 overlaycanvasid = options.getfieldvalue('overlayid', options.getfieldvalue('canvasid') + '-overlay') 158 overlaycanvas = $('#' + overlaycanvasid)[0]; 159 ctx = overlaycanvas.getContext('2d'); 164 160 canvas.overlaycanvas = overlaycanvas; 165 166 //Resize interal viewport coordinates to match screenspace coordinates167 var rect = overlaycanvas.getBoundingClientRect();168 overlaycanvas.width = rect.width;169 overlaycanvas.height = rect.height;170 171 //Clear canvas each frame for any new drawings172 canvas.overlayHandlers['draw'] = function(overlaycanvas) {173 ctx.clearRect(0, 0, overlaycanvas.width, overlaycanvas.height);174 }175 161 } 176 //{{{ lat long overlay 177 if (options.exist('latlongoverlay')) { 178 var latitudes = { 179 //'-90': 1, 180 //'-65': .999, 181 '-60': 0.994046875, 182 '-45': 0.955729166666666, 183 '-30': 0.9226562500000024, 184 //'-15': 0.830729166666665, 185 '0': 0.74218749999999811, 186 //'15': 0.63932291666666663, 187 '30': 0.523390625000001, 188 '45': 0.4020001, 189 '60': 0.26953124999999978, 190 //'65': 0.225390625, 191 //'90': 0.0, 192 } 193 var longitudes = [-150, -120, -90, -60, -30, 0, 30, 60, 90, 120, 150, 180]; 194 canvas.overlayHandlers['latlong'] = function(canvas) { 195 //Transform from world space to viewport space 196 var centerx = overlaycanvas.width / 2; 197 var centery = overlaycanvas.height / 2; 198 var radius = (overlaycanvas.height) / 2; 199 200 //Draw latitudes 201 ctx.setLineDash([5, 10]); 202 for(latitude in latitudes) { 203 ctx.beginPath(); 204 ctx.arc(centerx, centery, radius * latitudes[latitude], 0, 2 * Math.PI); 205 ctx.stroke(); 206 ctx.font = 'bold ' + String(options.getfieldvalue('colorbarfontsize', 18))+'px "Lato", Helvetica, Arial, sans-serif'; 207 ctx.fillStyle = options.getfieldvalue('colorbarfontcolor','black'); 208 ctx.strokeStyle = options.getfieldvalue('colorbarfontcolor','black'); 209 ctx.textAlign = 'center'; 210 ctx.textBaseline = 'middle'; 211 ctx.fillText(latitude, centerx, centery + radius * latitudes[latitude]); 212 ctx.strokeText(latitude, centerx, centery + radius * latitudes[latitude]); 213 } 214 //Draw longitudes 215 ctx.setLineDash([1, 0]); 216 for (longitude in longitudes) { 217 ctx.beginPath(); 218 ctx.moveTo(centerx, centery); 219 ctx.lineTo(centerx + radius * Math.sin(longitudes[longitude] * DEG2RAD), centery + radius * Math.cos(longitudes[longitude] * DEG2RAD)); 220 ctx.stroke(); 221 } 222 } 223 } //}}} 224 if (options.exist('textlabels')) { 162 overlaycanvas = canvas.overlaycanvas; 163 ctx = overlaycanvas.getContext('2d'); 164 165 if (options.exist('textlabels')) {//{{{ 225 166 //Attatch new overlay handler to display text labels 226 167 var textLabels = options.getfieldvalue('textlabels',[]); … … 236 177 237 178 }; 238 179 239 180 // function declared in slr-gfm sim-front-end-controller.js 240 181 // if labels are behind the globe sphere then skip iteartion and do not display them 241 if ( VESL.UI.isLabelVisible(textLabel)) {182 if (vesl.ui.isLabelVisible(textLabel)) { 242 183 //Transform from world space to viewport space 243 184 var screenPoint = vec3.transformMat4(vec3.create(), textLabel.position, canvas.camera.vpMatrix); 244 185 var x = (screenPoint[0] + 1.0) * (canvas.width / 2) + canvas.selector.offset().left; 245 186 var y = (-screenPoint[1] + 1.0) * (canvas.height / 2) + canvas.selector.offset().top; 246 187 247 188 //Draw text 248 189 ctx.font = 'bold ' + String(textLabel.fontSize) + 'px Arial Black, sans-serif'; … … 256 197 } 257 198 } 258 } //}}} 199 }//}}} 200 259 201 //{{{ additional rendering nodes 260 202 if (options.exist('render')) { … … 275 217 276 218 var renderObjects = options.getfieldvalue('render',{}); 219 277 220 for (var renderObject in renderObjects) { 278 221 //Modify renderObejct? … … 289 232 color: defaultFor(object.color, 'black'), //Diffuse color of object 290 233 height: defaultFor(object.height, 25000), //Height of object along y axis, currently for clouds only 291 range: defaultFor(object.range, 120000), //Range of sz plane to spawn object, currently for clouds only 292 quantity: defaultFor(object.quantity, 15) //Quantity of objects to display, currently for clouds only 234 range: defaultFor(object.range, 120000), //Range of sz plane to spawn object, currently for clouds only 235 quantity: defaultFor(object.quantity, 15), //Quantity of objects to display, currently for clouds only 236 source: defaultFor(object.source, 'NY'), //Quantity of objects to display, currently for clouds only 237 targets: defaultFor(object.targets, ['NY']) //Quantity of objects to display, currently for clouds only 293 238 }; 294 239 if (!object.enabled) { continue; } … … 367 312 node.geometryShader('Mesh', mesh, 'Vertices', [object.x, object.y, object.z], 'Indices', object.indices); 368 313 } 369 if ('axis' === renderObject && !('axis' in canvas.nodes)) { 314 if ('axis' === renderObject && !('axis' in canvas.nodes)) { 370 315 node = new Node( 371 316 'canvas', canvas, … … 382 327 node.patch('Vertices', [object.x, object.y, object.z], 'FaceColor', 'none'); 383 328 } 384 if ('city' === renderObject ) {329 if ('city' === renderObject && !vesl.helpers.isEmptyOrUndefined(overlaycanvas)) { 385 330 //city 386 331 var mesh = GL.Mesh.sphere({size: object.size}); … … 413 358 } 414 359 if ('clouds' === renderObject && !('clouds0' in canvas.nodes)) { 415 //clouds 360 //clouds 416 361 var mesh = GL.Mesh.fromURL(canvas.assetsPath + '/obj/cloud.obj'); 417 362 for (var i = 0; i < object.quantity; i++) { 418 363 //TODO: More options, less magic numbers. Add animation. Better shading. 419 var offset = [randomizeAxis(translation[0], object.range), 420 randomizeCloudHeight(translation[1], object), 364 var offset = [randomizeAxis(translation[0], object.range), 365 randomizeCloudHeight(translation[1], object), 421 366 randomizeAxis(translation[2], object.range)]; 422 367 var randomSize = randomizeCloudSize(object.scale); … … 436 381 } 437 382 } 383 if ('citylines' === renderObject) { 384 //city 385 node = new Node( 386 'canvas', canvas, 387 'options', options, 388 'renderObject', object, 389 'name', 'citylines', 390 'shaderName', 'ColoredDiffuse', 391 'drawMode', gl.LINES, 392 'diffuseColor', object.color, 393 'lineWidth', options.getfieldvalue('linewidth', 1), 394 'scale', [object.scale, object.scale, object.scale], 395 'rotation', [0, 0, 0] 396 ); 397 398 //For each target city, calculate the shortest line across the earth by performing a quaternion slerp. 399 //Treat source and target city as vectors to rotate to from the north pole. 400 //Then, slerp between the two rotations, and generate points across equidistance points on the earth to create the line. 401 var north = vec3.fromValues(0, 1, 0); 402 var source = object.source; 403 var sourceXYZ = vec3.fromValues(xcity[source], zcity[source], -ycity[source]); 404 var radius = vec3.length(sourceXYZ); 405 var lineSteps = 50; 406 var lineX = []; 407 var lineY = []; 408 var lineZ = []; 409 var lineXYZ = vec3.create(); 410 411 for (var i = 0; i < object.targets.length; i++) { 412 var target = object.targets[i]; 413 var targetXYZ = vec3.fromValues(xcity[target], zcity[target], -ycity[target]); 414 var axis = vec3.cross(vec3.create(), sourceXYZ, targetXYZ); 415 vec3.normalize(axis, axis); 416 417 //Get the total angle between the two cities. 418 var sourceXYZAxis = vec3.normalize(vec3.create(), sourceXYZ); 419 var targetXYZAxis = vec3.normalize(vec3.create(), targetXYZ); 420 var dotProduct = vec3.dot(sourceXYZAxis, targetXYZAxis); 421 var totalAngle = Math.acos(dotProduct); //theta = arccos(u . v / (||u|| * ||v||); in this case, ||u|| and ||v|| are 1, since u and v are unit vectors. 422 423 var lineQuat = quat.create(); 424 for (var j = 1; j <= lineSteps; j++) { 425 //Calculate the partial rotation to obtain points on the line between the two cities. 426 var angle = j / lineSteps * totalAngle; 427 quat.setAxisAngle(lineQuat, axis, angle); 428 quat.normalize(lineQuat, lineQuat); 429 vec3.transformQuat(lineXYZ, sourceXYZ, lineQuat); 430 //GL.LINES needs 2 points for each line - at the beginning, just use the sourceXYZ. 431 //TODO: Eliminate this if statement. 432 if (j === 1) { 433 lineX.push(sourceXYZ[0]); 434 lineY.push(sourceXYZ[1]); 435 lineZ.push(sourceXYZ[2]); 436 } else { 437 lineX.push(lineX[lineX.length - 1]); 438 lineY.push(lineY[lineY.length - 1]); 439 lineZ.push(lineZ[lineZ.length - 1]); 440 } 441 lineX.push(lineXYZ[0]); 442 lineY.push(lineXYZ[1]); 443 lineZ.push(lineXYZ[2]); 444 } 445 } 446 node.patch('Vertices', [lineX, lineY, lineZ]); 447 } 438 448 } 439 449 } //}}} … … 445 455 var minHeigth = object.height - 7000; 446 456 var randomHeight = (Math.random() * (maxHeight - minHeigth)) + minHeigth; 447 457 448 458 return canvasGroundHeight + randomHeight; 449 459 } … … 451 461 // assumes that originAxisValue is the mid-value between min and max. 452 462 function randomizeAxis(originAxisValue, range) { 453 return originAxisValue + (Math.random() - 0.5) * (range * 2); 463 return originAxisValue + (Math.random() - 0.5) * (range * 2); 454 464 } 455 465 … … 457 467 var maxResize = 1.3; 458 468 var minResize = 0.5; 459 var randomizationFactor = Math.random() * (maxResize - minResize) + minResize; 469 var randomizationFactor = Math.random() * (maxResize - minResize) + minResize; 460 470 return scale * randomizationFactor; 461 471 }
Note:
See TracChangeset
for help on using the changeset viewer.