Changeset 20025


Ignore:
Timestamp:
01/29/16 17:42:25 (9 years ago)
Author:
dlcheng
Message:

CHG (javascript): Implementing textlabels rendering.

Location:
issm/trunk-jpl/src/m/plot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/applyoptions.js

    r19992 r20025  
    3333                        var ccontext,ccanvas,ccanvasid,ccanvashtml;
    3434                        var colorbarorientiation = options.getfieldvalue('colorbarorientation','vertical');
    35                         var cheightoffset = options.getfieldvalue('colorbarfontsize',16);
    36                         var cwidthoffset = options.getfieldvalue('colorbarfontsize',16)*3;
     35                        var cheightoffset = options.getfieldvalue('colorbarfontsize',18);
     36                        var cwidthoffset = options.getfieldvalue('colorbarfontsize',18)*3;
    3737                        var y;
    3838                        var x;
     
    119119                                        ccontext.lineTo(cwidth,y+cheightoffset);
    120120                                        ccontext.stroke();
    121                                         ccontext.font=String(options.getfieldvalue('colorbarfontsize',16))+'px Arial';
     121                                        ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
    122122                                        ccontext.fillStyle='black';
    123123                                        ccontext.textAlign='left';
     
    125125                                }
    126126                                if (options.exist('colorbartitle')) {
    127                                         ccontext.font=String(options.getfieldvalue('colorbarfontsize',16))+'px Arial';
     127                                        ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
    128128                                        ccontext.fillStyle='black';
    129129                                        ccontext.textAlign='left';
     
    192192                                        ccontext.lineTo(x+cwidthoffset,cheight+cheightoffset);
    193193                                        ccontext.stroke();
    194                                         ccontext.font=String(options.getfieldvalue('colorbarfontsize',16))+'px Arial';
     194                                        ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
    195195                                        ccontext.fillStyle='black';
    196196                                        ccontext.textAlign='center';
     
    198198                                }
    199199                                if (options.exist('colorbartitle')) {
    200                                         ccontext.font=String(options.getfieldvalue('colorbarfontsize',16))+'px Arial';
     200                                        ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
    201201                                        ccontext.fillStyle='black';
    202202                                        ccontext.textAlign='center';
     
    393393                node['buffers'] = initBuffers(gl, node['arrays']);
    394394        } //}}}
     395       
     396        //text display //{{{
     397        if (options.exist('textlabels')) {
     398                var textcanvas,textcanvasid;   
     399                textcanvasid = options.getfieldvalue('textcanvasid',options.getfieldvalue('canvasid')+'-text');
     400                textcanvas = $('#'+textcanvasid);
     401                textcanvas.textlabels = options.getfieldvalue('textlabels',[]);
     402               
     403                //setup drawing function for text canvas draw calls
     404                textcanvas.draw = function(canvas) {
     405                        var textcontext,textlabels,textlabel,textcanvaswidth,textcanvasheight,textcoordinates; 
     406                        var textposition = vec3.create();
     407                        var mvpMatrix = mat4.create();
     408                       
     409                        //ensure correct canvas coordinate scaling
     410                        textcanvaswidth = this[0].clientWidth;
     411                        textcanvasheight = this[0].clientHeight;
     412                        this[0].width  = textcanvaswidth;
     413                        this[0].height = textcanvasheight;
     414                       
     415                        textcontext = this[0].getContext('2d');
     416                        textlabels = options.getfieldvalue('textlabels',[]);
     417                        textcontext.clearRect(0, 0, textcanvaswidth, textcanvasheight);
     418                       
     419                        //worldspace to screenspace transformation for text
     420                        for (text in textlabels) {
     421                                textlabel = textlabels[text];
     422                                mat4.multiply(mvpMatrix, canvas.cameraMatrix, canvas.nodes['overlay']['modelMatrix']);
     423                                textposition = vec3.transformMat4(textposition, textlabel['pos'], mvpMatrix);
     424                                if (textposition[2] > 1) { //clip coordinates with z > 1
     425                                        continue;
     426                                }
     427                                textcoordinates = [(textposition[0]+1.0)/2.0*textcanvaswidth, (-textposition[1]+1.0)/2.0*textcanvasheight]; //NDC to screenspace
     428                                textcontext.font = String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
     429                                textcontext.fillStyle = 'black';
     430                                textcontext.strokeStyle = 'black';
     431                                textcontext.textAlign = 'center';
     432                                textcontext.textBaseline = 'middle';
     433                                textcontext.fillText(textlabel['text'], textcoordinates[0], textcoordinates[1]);
     434                                textcontext.strokeText(textlabel['text'], textcoordinates[0], textcoordinates[1]);
     435                        }
     436                }
     437                canvas.textcanvas = textcanvas;
     438        } //}}}
    395439}
  • issm/trunk-jpl/src/m/plot/webgl.js

    r19992 r20025  
    465465        }
    466466       
     467        if (canvas.textcanvas) {
     468                canvas.textcanvas.draw(canvas);
     469        }
     470
    467471        // Set clear color to black, fully opaque
    468472        var backgroundcolor=new RGBColor(options.getfieldvalue('backgroundcolor','lightcyan'));
Note: See TracChangeset for help on using the changeset viewer.