<commit_before>(function() {
    'use strict';

    function SiteBoxService($rootScope, THREE, sitesservice, CameraService, SceneService) {
        var me = this;

        var raycaster;
        this.mouse = {
            x: 0,
            y: 0
        };

        this.siteBoxList = [];
        this.referenceFrame = null;

        this.init = function(referenceFrame, mouse) {
            me.referenceFrame = referenceFrame;
            raycaster = new THREE.Raycaster();
            raycaster.params = {
                "PointCloud" : {
                    threshold : 0.1
                }
            };

            me.mouse = mouse;
        };

        this.onSitesChanged = function(sites) {
            if(sitesservice.isLoaded){
                me.siteBoxList = [];
                for(i=0; i<sites.features.length; i++){
                    me.siteBoxList.push(me.createSiteBox(sites.features[i]));
                }
            }
        };

        $rootScope.$watch(function() {
            return sitesservice.all;
        }, this.onSitesChanged);

        this.hoverOver = function(siteBox) {
            siteBox.material.color.setHex(0x99FFFF);
        };

        this.hoverOut = function(siteBox) {
            siteBox.material.color.setHex(0xFF99CC);
        };

        this.listenTo = function(element) {
            element.addEventListener('dblclick', this.selectSite, false);
        };

        this.selectSite = function(event) {
            var selectedSiteBox = me.siteBoxSelection(me.mouse.x, me.mouse.y);
            if (selectedSiteBox) {
                if (selectedSiteBox.hasOwnProperty('textLabel')) {
                    me.toggleTextLabel(selectedSiteBox);
                } else {
                    me.addTextLabel(selectedSiteBox);
                }
            }
        };

        this.toggleTextLabel = function(siteBox) {
            // toggle visibility of textLabel
            siteBox.textLabel.visible = !siteBox.textLabel.visible;
        };

        this.addTextLabel = function( siteBox ){
            // parameters
            var canvas_size = 1000; // pt != on-screen pixels
            var fontsize = 40; // pt (same as canvas size)
            var textBoxPadding = fontsize/2; // pt
            var textBoxBorderWidth = 1; // pt
            var textBoxBorderColor = "rgba(0,0,0, 0.8)";
            var textBoxFillColor = "rgba(255,255,255, 0.8)";
            var fontColor = "rgb(0,0,0)";

            var x = siteBox.position.x;
            var y = siteBox.position.y;
            var z = siteBox.position.z;


            var canvas = document.createElement('canvas');
            // keep canvas square to avoid stretching problems (see sprite size
            // below as well):
            canvas.width = canvas_size;
            canvas.height = canvas_size;
            var context = canvas.getContext('2d');


            // background color
            //context.fillStyle   = "rgba(" + backgroundColor.r + "," + backgroundColor.g + ","
            //+ backgroundColor.b + "," + backgroundColor.a + ")";

            //context.strokeStyle = "rgba(" + borderColor.r + "," + borderColor.g + ","
            //+ borderColor.b + "," + borderColor.a + ")";

            //context.lineWidth = borderThickness;
            //roundRect(context, borderThickness/2, borderThickness/2, messageWidth + borderThickness, fontsize * 1.4 + borderThickness, 6);
            // 1.4 is extra height factor for text below baseline: g,j,p,q.

            // text color
            //context.fillStyle = "rgba(0, 0, 0, 1.0)";

            //context.fillText(message, borderThickness, fontsize + borderThickness);

            context.font = fontsize + "pt Calibri";
            context.textAlign = "right";

            // the text we want to write
            var message = siteBox.site.properties.description;
                          // "SiteBox #" + siteBox.site.id + "\n" +
                          // "description: " + siteBox.site.properties.description + "\n" +
                          // "site_context: " + siteBox.site.properties.site_context + "\n" +
                          // "site_interpretation: " + siteBox.site.properties.site_interpretation + "\n" +
                          // "condition: " + siteBox.site.properties.condition + "\n";
            // get size data (height depends only on font size)
            var messageWidth = context.measureText( message ).width;

            // a placeholder box around the text, pending final design by Lode
            var textBoxWidth = messageWidth + 2*textBoxPadding;
            var textBoxHeight = fontsize + 2*textBoxPadding;
            context.fillStyle = textBoxBorderColor;
            context.fillRect(canvas.width - (textBoxWidth + 2*textBoxBorderWidth), 0, textBoxWidth + 2*textBoxBorderWidth, textBoxHeight + 2*textBoxBorderWidth);
            context.fillStyle = textBoxFillColor;
            context.fillRect(canvas.width - (textBoxWidth + textBoxBorderWidth), textBoxBorderWidth, textBoxWidth, textBoxHeight);

            // The two fillText number arguments are canvas-coordinates, so
            // depend on the size of the canvas defined above. The y-coordinate
            // is set to fontsize, otherwise the words fall off the top of the
            // canvas.
            context.fillStyle = fontColor;
            context.fillText(message, canvas_size - textBoxPadding, fontsize + textBoxPadding);
            // canvas contents will be used for a texture
            var texture = new THREE.Texture(canvas)
            texture.needsUpdate = true;

            var spriteMaterial = new THREE.SpriteMaterial({
                map: texture,
                useScreenCoordinates: false,
                // transparent: true,
                depthTest: false, 
                depthWrite: false,
            });
            var sprite = new THREE.Sprite( spriteMaterial );

            // set scale based on sitebox size (add a certain minimum perhaps?)
            var depth = siteBox.geometry.parameters.depth;
            var height = siteBox.geometry.parameters.height;
            var width = siteBox.geometry.parameters.width;<commit_msg>Moved SiteBox TextLabel to below object<commit_after>(function() {
    'use strict';

    function SiteBoxService($rootScope, THREE, sitesservice, CameraService, SceneService) {
        var me = this;

        var raycaster;
        this.mouse = {
            x: 0,
            y: 0
        };

        this.siteBoxList = [];
        this.referenceFrame = null;

        this.init = function(referenceFrame, mouse) {
            me.referenceFrame = referenceFrame;
            raycaster = new THREE.Raycaster();
            raycaster.params = {
                "PointCloud" : {
                    threshold : 0.1
                }
            };

            me.mouse = mouse;
        };

        this.onSitesChanged = function(sites) {
            if(sitesservice.isLoaded){
                me.siteBoxList = [];
                for(i=0; i<sites.features.length; i++){
                    me.siteBoxList.push(me.createSiteBox(sites.features[i]));
                }
            }
        };

        $rootScope.$watch(function() {
            return sitesservice.all;
        }, this.onSitesChanged);

        this.hoverOver = function(siteBox) {
            siteBox.material.color.setHex(0x99FFFF);
        };

        this.hoverOut = function(siteBox) {
            siteBox.material.color.setHex(0xFF99CC);
        };

        this.listenTo = function(element) {
            element.addEventListener('dblclick', this.selectSite, false);
        };

        this.selectSite = function(event) {
            var selectedSiteBox = me.siteBoxSelection(me.mouse.x, me.mouse.y);
            if (selectedSiteBox) {
                if (selectedSiteBox.hasOwnProperty('textLabel')) {
                    me.toggleTextLabel(selectedSiteBox);
                } else {
                    me.addTextLabel(selectedSiteBox);
                }
            }
        };

        this.toggleTextLabel = function(siteBox) {
            // toggle visibility of textLabel
            siteBox.textLabel.visible = !siteBox.textLabel.visible;
        };

        this.addTextLabel = function( siteBox ){
            // parameters
            var canvas_size = 1000; // pt != on-screen pixels
            var fontsize = 40; // pt (same as canvas size)
            var textBoxPadding = fontsize/2; // pt
            var textBoxBorderWidth = 1; // pt
            var textBoxBorderColor = "rgba(0,0,0, 0.8)";
            var textBoxFillColor = "rgba(255,255,255, 0.8)";
            var fontColor = "rgb(0,0,0)";

            var x = siteBox.position.x;
            var y = siteBox.position.y;
            var z = siteBox.position.z;


            var canvas = document.createElement('canvas');
            // keep canvas square to avoid stretching problems (see sprite size
            // below as well):
            canvas.width = canvas_size;
            canvas.height = canvas_size;
            var context = canvas.getContext('2d');


            // background color
            //context.fillStyle   = "rgba(" + backgroundColor.r + "," + backgroundColor.g + ","
            //+ backgroundColor.b + "," + backgroundColor.a + ")";

            //context.strokeStyle = "rgba(" + borderColor.r + "," + borderColor.g + ","
            //+ borderColor.b + "," + borderColor.a + ")";

            //context.lineWidth = borderThickness;
            //roundRect(context, borderThickness/2, borderThickness/2, messageWidth + borderThickness, fontsize * 1.4 + borderThickness, 6);
            // 1.4 is extra height factor for text below baseline: g,j,p,q.

            // text color
            //context.fillStyle = "rgba(0, 0, 0, 1.0)";

            //context.fillText(message, borderThickness, fontsize + borderThickness);

            context.font = fontsize + "pt Calibri";
            context.textAlign = "center";

            // the text we want to write
            var message = siteBox.site.properties.description;
                          // "SiteBox #" + siteBox.site.id + "\n" +
                          // "description: " + siteBox.site.properties.description + "\n" +
                          // "site_context: " + siteBox.site.properties.site_context + "\n" +
                          // "site_interpretation: " + siteBox.site.properties.site_interpretation + "\n" +
                          // "condition: " + siteBox.site.properties.condition + "\n";
            // get size data (height depends only on font size)
            var messageWidth = context.measureText( message ).width;

            // a placeholder box around the text, pending final design by Lode
            var textBoxWidth = messageWidth + 2*textBoxPadding;
            var textBoxHeight = fontsize + 2*textBoxPadding;
            context.fillStyle = textBoxBorderColor;
            context.fillRect(canvas.width/2 - (textBoxWidth/2 + textBoxBorderWidth), canvas_size - fontsize - textBoxPadding*2 - textBoxBorderWidth*2, textBoxWidth + 2*textBoxBorderWidth, textBoxHeight + 2*textBoxBorderWidth);
            context.fillStyle = textBoxFillColor;
            context.fillRect(canvas.width/2 - (textBoxWidth/2), canvas_size - fontsize - textBoxPadding*2 - textBoxBorderWidth, textBoxWidth, textBoxHeight);

            // The two fillText number arguments are canvas-coordinates, so
            // depend on the size of the canvas defined above. The y-coordinate
            // is set to fontsize, otherwise the words fall off the top of the
            // canvas.
            context.fillStyle = fontColor;
            context.fillText(message, canvas_size/2 , canvas_size - fontsize/2 - textBoxPadding/2 - textBoxBorderWidth/2);
            // canvas contents will be used for a texture
            var texture = new THREE.Texture(canvas)
            texture.needsUpdate = true;

            var spriteMaterial = new THREE.SpriteMaterial({
                map: texture,
                useScreenCoordinates: false,
                // transparent: true,
                depthTest: false, 
                depthWrite: false,
            });
            var sprite = new THREE.Sprite( spriteMaterial );

            // set scale based on sitebox size (add a certain minimum perhaps?)
            var depth = siteBox.geometry.parameters.depth;
            var height = siteBox.geometry.parameters.height;
            var width = siteBox.geometry.parameters.width;
{'fraction_non_alphanumeric': 0.10686290193569029, 'fraction_numerical': 0.009838425851863702, 'mean_word_length': 1.7115593146822814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3301444', 'n_tokens_mistral': 3402, 'n_tokens_neox': 3196, 'n_words': 748}