<fim-prefix>          showPanel();
                }

                var xVals = data.map(getPos('x')).filter(notUndef);
                var yVals = data.map(getPos('y')).filter(notUndef);
                minX = Math.min.apply(null, xVals);
                maxX = Math.max.apply(null, xVals);
                var midX = ((maxX - minX)/2) + minX;
                minY = Math.min.apply(null, yVals);
                maxY = Math.max.apply(null, yVals);

                // Resize the well_birds_eye according to extent of field positions...
                var whRatio = 1;
                if (maxX !== minX || maxY !== minY) {
                    whRatio = (maxX - minX) / (maxY - minY);
                }
                var width = 200;
                var height = 200;
                var top = 4;
                if (whRatio > 1) {
                    height = 200/whRatio;
                    top = ((200 - height) / 2) + 4;
                } else {
                    width = whRatio * 200;
                }
                $well_birds_eye.css({'width': width + 'px', 'height': height + 'px', 'top': top + 'px'});

                // Add images, positioned by percent...
                var html = data.map(function(ws){
                    // check if min===max to avoid zero-division error
                    var x = (maxX === minX) ? 0.5 : (ws.position.x.value - minX)/(maxX - minX);
                    var y = (maxY === minY) ? 0.5 : (ws.position.y.value - minY)/(maxY - minY);
                    // BUG: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
                    // return '<img style="left: ' + (x * 100) + '%; top: ' + (y * 100) + '%" title="' + ws.name + '" data-imageId="' + ws.id + '" />';
                    // FIXED: 
<fim-middle>                    return '<img style="left: ' + (x * 100) + '%; top: ' + (y * 100) + '%" title="' + ws.name.escapeHTML() + '" data-imageId="' + ws.id + '" />';
                }, "");
               <fix-suffix> $well_birds_eye.append(html.join(""));
            }
        }
    };

    // Used by WellIndexForm in forms.py
    window.changeField = function changeField(field) {

        var datatree = $.jstree.reference('#dataTree');
        var $container = $("#content_details");

        var containerType = $container.data('type');
        var containerId = $container.data('id');
        var containerPath = $container.data('path');
        containerPath = JSON.parse(containerPath);
        var containerNode = datatree.find_omepath(containerPath);

        if (!containerNode) {
            console.log('WARNING: Had to guess container');
            containerNode = OME.getTreeBestGuess(containerType, containerId);
        }

        // Set the field for that node in the tree and reload the tree section
        datatree.set_field(containerNode, field);

        // Reselect the same node to trigger update
        datatree.deselect_all(true);
        datatree.select_node(containerNode);

        r<|endoftext|>