<commit_before>var igv = (function (igv) {

    var maxViewportHeight = 400;

    igv.TrackView = function (track, browser) {

        this.browser = browser;
        this.track = track;
        this.order = track.order || 0;
        this.marginBottom = 10;

        var foo,
            viewportHeight,
            viewportDiv,
            trackDiv,
            controlDiv,
            contentHeight,
            contentDiv,
            canvas,
            contentWidth,
            closeButton,
            labelButton,
            trackFilterButtonDiv;

        viewportHeight = track.height;

        // track
        trackDiv = document.createElement("div");
        browser.trackContainerDiv.appendChild(trackDiv);
        trackDiv.className = "igv-track-div";
        trackDiv.style.top = browser.rootHeight + "px";
        trackDiv.style.height = viewportHeight + "px";
        trackDiv.title = track.label;

        this.trackDiv = trackDiv;

        // controls
        controlDiv = document.createElement("div");
        trackDiv.appendChild(controlDiv);
        controlDiv.className = "igv-control-div";

        this.controlDiv = controlDiv;

       // if (browser.type === "GTEX") {
            var controlWidth = controlDiv.clientWidth;
            var controlHeight = controlDiv.clientHeight;

            var controlCanvas = document.createElement('canvas');
            controlDiv.appendChild(controlCanvas);
            controlCanvas.style.position = 'absolute';
            controlCanvas.style.width = controlWidth + "px";
            controlCanvas.style.height = controlHeight + "px";
            controlCanvas.setAttribute('width', controlWidth);
            controlCanvas.setAttribute('height', controlHeight);
            this.controlCanvas = controlCanvas;
            this.controlCtx = controlCanvas.getContext("2d");


    //    }

        // TODO - dat - this is so nothing breaks that is dependent on igv.controlPanelWidth
        igv.controlPanelWidth = controlDiv.clientWidth;

        // The viewport
        viewportDiv = document.createElement("div");
        trackDiv.appendChild(viewportDiv);
        viewportDiv.className = "igv-viewport-div";
        viewportDiv.style.left = controlDiv.clientWidth + "px";
        viewportDiv.style.height = viewportHeight + "px";

        this.viewportDiv = viewportDiv;

        // Content
        contentHeight = track.height;
        contentDiv = document.createElement("div");
        viewportDiv.appendChild(contentDiv);  // Note, must do this before getting width for canvas
        contentDiv.className = "igv-content-div";
        contentDiv.style.height = contentHeight + "px";

        this.contentDiv = contentDiv;

        contentWidth = contentDiv.clientWidth;

        canvas = document.createElement('canvas');
        contentDiv.appendChild(canvas);
        canvas.style.position = 'absolute';
        canvas.style.width = contentWidth + "px";
        canvas.style.height = contentHeight + "px";
        canvas.setAttribute('width', contentWidth);    //Must set the width & height of the canvas
        canvas.setAttribute('height', contentHeight);

        // filter  -- CURSOR only for now
        if (browser.type === "CURSOR") {

//            this.track.cursorHistogram = new cursor.CursorHistogram(this.track.height, this.track.max);
            this.track.cursorHistogram = new cursor.CursorHistogram(controlDiv.clientHeight, this.track.max);
            this.track.cursorHistogram.createMarkupWithTrackPanelDiv(this);

        }

        var nextButtonTop = 5;
        if (browser.type === "CURSOR") {

            var sortButton = document.createElement("i");
            controlDiv.appendChild(sortButton);
            sortButton.className = "fa fa-bar-chart-o";
            sortButton.style.color = "black";
            sortButton.style.position = "absolute";
            sortButton.style.top = nextButtonTop + "px";
            sortButton.style.left = "5px";
            sortButton.style.cursor = "pointer";
            nextButtonTop += 18;

            track.sortButton = sortButton;
            sortButton.onclick = function () {

                var spinner = igv.getSpinner(viewportDiv);   // Start a spinner
                // Delay 100 ms to give spinner a chance to spin up (we are single threaded)
                setTimeout(function () {
                    browser.cursorModel.sortRegions(track.featureSource, track.sortDirection, function (regions) {
                        spinner.stop();
                        browser.update();
                        track.sortDirection *= -1;

                    });
                }, 100);

                browser.trackPanels.forEach(function (trackPanel) {
                    if (track !== trackPanel.track) {
                        trackPanel.track.sortButton.className = "fa fa-bar-chart-o";
                        trackPanel.track.sortButton.style.color = "black";
                    }
                });

                sortButton.className = "fa fa-signal";
                sortButton.style.color = "red";

            };


            //
            trackFilterButtonDiv = document.createElement("div");
            controlDiv.appendChild(trackFilterButtonDiv);

            trackFilterButtonDiv.id = "filterButtonDiv_" + igv.guid();
            trackFilterButtonDiv.className = "igv-filter-histogram-button-div";
            trackFilterButtonDiv.style.top = nextButtonTop + "px";
            trackFilterButtonDiv.style.left = "5px";

//            this.track.trackFilter = new igv.TrackFilter(this);
//            this.track.trackFilter.createTrackFilterWidgetWithParentElement(trackFilterButtonDiv);

            this.track.trackFilter = new igv.TrackFilter(this);
            this.track.trackFilter.createTrackFilterWidgetWithParentElement(trackFilterButtonDiv);

            nextButtonTop += 18;

        }

        // Close button
        if (!track.disableButtons) {

            closeButton = document.createElement("i");
            contentDiv.appendChild(closeButton);
            closeButton.style.color = "black";
            closeButton.className = "fa fa-times-circle";
            closeButton.style.position = "absolute";
            closeButton.style.top = "5px";
            closeButton.style.right = "5px";
            closeButton.style.cursor = "pointer";
            closeButton.onclick = function () {

//                removeTrackPanel(trackPanel);
                browser.removeTrack(track);

                // We removed a track. This removes it's filter. Must update filter chain application
                if (browser.type === "CURSOR") {
                    browser.cursorModel.filterRegions();
                }

            };

            if (track.label) {

                labelButton = document.createElement("button");
                viewportDiv.appendChild(labelButton);
                labelButton.className = "btn btn-xs btn-cursor-deselected";
                labelButton.style.position = "absolute";
                labelButton.style.top = "10px";
                labelButton.style.left = "10px";
                labelButton.innerHTML = track.label;
                track.labelButton = labelButton;

                labelButton.onclick = function () {

                    if(browser.cursorModel) {
                        track.featureSource.allFeatures(function (featureList) {

                            browser.referenceFrame.start = 0;
                            browser.cursorModel.setRegions(featureList);
//                        browser.update();


                        });


                        browser.trackPanels.forEach(function (trackPanel) {
                            if (track !== trackPanel.track) {
                                trackPanel.track.labelButton.className = "btn btn-xs btn-cursor-deselected";
                            }
                        });
                    }
                    labelButton.className = "btn btn-xs btn-cursor-selected";

                }


            }
        }


        browser.rootHeight += viewportHeight + this.marginBottom;

        browser.div.style.height = browser.rootHeight + 165 + "px";

        this.canvas = canvas;
        this.ctx = canvas.getContext("2d");

        addTrackHandlers(this);

        function removeTrackPanel(trackPanel) {

            var array = browser.trackPanels;
            array.splice(array.indexOf(trackPanel), 1);

            browser.trackContainerDiv.removeChild(trackPanel.trackDiv);

            browser.rootHeight = 0;
            browser.trackPanels.forEach(function (panel) {
                panel.trackDiv.style.top = browser.rootHeight + "px";
                browser.rootHeight += panel.trackDiv.clientHeight;

                browser.div.style.height = browser.rootHeight + 165 + "px";
            });

            // We removed a track. This removes it's filter. Must
            // now update filter chain application
            if (browser.type === "CURSOR") {
                browser.cursorModel.filterRegions();
            }
        }

        function addTrackHandlers(trackPanel) {

            var canvas = trackPanel.canvas;
            var isMouseDown = false;
            var mouseDownX = undefined;
            var lastMouseX = undefined;
            var referenceFrame = trackPanel.browser.referenceFrame;

            canvas.onmousedown = function (e) {

                var dx = e.clientX - $(canvas).offset().left;

                isMouseDown = true;

                mouseDownX = e.clientX;
                lastMouseX = dx;

            };

            canvas.onmousemove = throttle(function (e) {
                var dx = e.clientX - $(canvas).offset().left;


                if (isMouseDown) {

                    if (lastMouseX) {

                        referenceFrame.shiftPixels(lastMouseX - dx);

                        if (referenceFrame.start < 0) {
                            referenceFrame.start = 0;
                        }

//                        if (igv.genome) {
//                            var chromosome = igv.genome.getChromosome(igv.referenceFrame.chr);
//                            var widthBP = Math.round((igv.trackWidth - igv.labelWidth) * igv.referenceFrame.bpPerPixel);
//                            var endBP = igv.referenceFrame.start + widthBP;
//                            if (chromosome && endBP > chromosome.bpLength) {
//                                if (endBP > chromosome.length) {
//                                    igv.referenceFrame.start = chromosome.bpLength - widthBP;
//                                }
//                            }
//                        }
                    }

                    lastMouseX = dx;


                    trackPanel.browser.repaint();
                }

            }, /*20*/1);

            canvas.onmouseup = function (e) {

                if (e.clientX === mouseDownX) {

                    $(trackPanel.trackDiv).qtip({
                        content: {
                            title: {
                                text: "Genomic Gymnastics",
                                button: true
                            },
                            text: "Track " + trackPanel.trackDiv.title + " location " + igv.numberFormatter(1 + trackPanel.genomicCoordinateWithEventTap(e))
                        },
                        show: {
                            event: 'click'
                        },
                        hide: {
                            delay: 100,
                            fixed: true
                        },
                        position: {
                            target: 'mouse',
                            viewport: $(window),
                            adjust: {
//                                method: 'flip shift',
                                mouse: false
                            }
                        },

                        style: {
                            width: 200,
                            height: 200,
                            tip: false,
                            widget: false
                        }
                    });

                }

                isMouseDown = false;
                lastMouseX = undefined;
            };

            canvas.onmouseout = function (e) {
                isMouseDown = false;
                lastMouseX = undefined;
            };

            canvas.ondblclick = function (e) {

                var mouseX = e.clientX - $(canvas).offset().left;
                var mouseY = e.clientY - $(canvas).offset().top;

                if (trackPanel.track.handleDblClick) {
                    trackPanel.track.handleDblClick(mouseX, mouseY, trackPanel.viewportDiv);
                }
                else {
                    var newCenter = Math.round(trackPanel.browser.referenceFrame.start + mouseX * trackPanel.browser.referenceFrame.bpPerPixel);
                    referenceFrame.bpPerPixel /= 2;
                    trackPanel.browser.goto(trackPanel.browser.referenceFrame.chr, newCenter);
                }
            };

//            canvas.onclick = function (e) {
//
//                var dx = e.clientX - $(canvas).offset().left;
//                console.log("movement " + (dx - lastMouseX));
//
//            };
        }

    };

    igv.TrackView.prototype.genomicCoordinateWithEventTap = function (event) {

        var pixels = event.clientX - $(this.canvas).offset().left;
        return Math.floor( (this.browser.referenceFrame.start) + this.browser.referenceFrame.toBP(pixels) );<commit_msg>qtip wrangling<commit_after>var igv = (function (igv) {

    var maxViewportHeight = 400;

    igv.TrackView = function (track, browser) {

        this.browser = browser;
        this.track = track;
        this.order = track.order || 0;
        this.marginBottom = 10;

        var foo,
            viewportHeight,
            viewportDiv,
            trackDiv,
            controlDiv,
            contentHeight,
            contentDiv,
            canvas,
            contentWidth,
            closeButton,
            labelButton,
            trackFilterButtonDiv;

        viewportHeight = track.height;

        // track
        trackDiv = document.createElement("div");
        browser.trackContainerDiv.appendChild(trackDiv);
        trackDiv.className = "igv-track-div";
        trackDiv.style.top = browser.rootHeight + "px";
        trackDiv.style.height = viewportHeight + "px";
        trackDiv.title = track.label;

        this.trackDiv = trackDiv;

        $(this.trackDiv).qtip({
            content: {
                title: {
                    text: "Genomic Gymnastics",
                    button: true
                },
                text: "hello"
            },
                        show: {
                            event: 'click'
                        },
            hide: {
                delay: 100,
                fixed: true
            },
            position: {
                target: 'mouse',
                viewport: $(window),
                adjust: {
//                                method: 'flip shift',
                    mouse: false
                }
            },

            style: {
                width: 200,
                height: 200,
                tip: false,
                widget: false
            }
        });



        // controls
        controlDiv = document.createElement("div");
        trackDiv.appendChild(controlDiv);
        controlDiv.className = "igv-control-div";

        this.controlDiv = controlDiv;

       // if (browser.type === "GTEX") {
            var controlWidth = controlDiv.clientWidth;
            var controlHeight = controlDiv.clientHeight;

            var controlCanvas = document.createElement('canvas');
            controlDiv.appendChild(controlCanvas);
            controlCanvas.style.position = 'absolute';
            controlCanvas.style.width = controlWidth + "px";
            controlCanvas.style.height = controlHeight + "px";
            controlCanvas.setAttribute('width', controlWidth);
            controlCanvas.setAttribute('height', controlHeight);
            this.controlCanvas = controlCanvas;
            this.controlCtx = controlCanvas.getContext("2d");


    //    }

        // TODO - dat - this is so nothing breaks that is dependent on igv.controlPanelWidth
        igv.controlPanelWidth = controlDiv.clientWidth;

        // The viewport
        viewportDiv = document.createElement("div");
        trackDiv.appendChild(viewportDiv);
        viewportDiv.className = "igv-viewport-div";
        viewportDiv.style.left = controlDiv.clientWidth + "px";
        viewportDiv.style.height = viewportHeight + "px";

        this.viewportDiv = viewportDiv;

        // Content
        contentHeight = track.height;
        contentDiv = document.createElement("div");
        viewportDiv.appendChild(contentDiv);  // Note, must do this before getting width for canvas
        contentDiv.className = "igv-content-div";
        contentDiv.style.height = contentHeight + "px";

        this.contentDiv = contentDiv;

        contentWidth = contentDiv.clientWidth;

        canvas = document.createElement('canvas');
        contentDiv.appendChild(canvas);
        canvas.style.position = 'absolute';
        canvas.style.width = contentWidth + "px";
        canvas.style.height = contentHeight + "px";
        canvas.setAttribute('width', contentWidth);    //Must set the width & height of the canvas
        canvas.setAttribute('height', contentHeight);

        // filter  -- CURSOR only for now
        if (browser.type === "CURSOR") {

//            this.track.cursorHistogram = new cursor.CursorHistogram(this.track.height, this.track.max);
            this.track.cursorHistogram = new cursor.CursorHistogram(controlDiv.clientHeight, this.track.max);
            this.track.cursorHistogram.createMarkupWithTrackPanelDiv(this);

        }

        var nextButtonTop = 5;
        if (browser.type === "CURSOR") {

            var sortButton = document.createElement("i");
            controlDiv.appendChild(sortButton);
            sortButton.className = "fa fa-bar-chart-o";
            sortButton.style.color = "black";
            sortButton.style.position = "absolute";
            sortButton.style.top = nextButtonTop + "px";
            sortButton.style.left = "5px";
            sortButton.style.cursor = "pointer";
            nextButtonTop += 18;

            track.sortButton = sortButton;
            sortButton.onclick = function () {

                var spinner = igv.getSpinner(viewportDiv);   // Start a spinner
                // Delay 100 ms to give spinner a chance to spin up (we are single threaded)
                setTimeout(function () {
                    browser.cursorModel.sortRegions(track.featureSource, track.sortDirection, function (regions) {
                        spinner.stop();
                        browser.update();
                        track.sortDirection *= -1;

                    });
                }, 100);

                browser.trackPanels.forEach(function (trackPanel) {
                    if (track !== trackPanel.track) {
                        trackPanel.track.sortButton.className = "fa fa-bar-chart-o";
                        trackPanel.track.sortButton.style.color = "black";
                    }
                });

                sortButton.className = "fa fa-signal";
                sortButton.style.color = "red";

            };


            //
            trackFilterButtonDiv = document.createElement("div");
            controlDiv.appendChild(trackFilterButtonDiv);

            trackFilterButtonDiv.id = "filterButtonDiv_" + igv.guid();
            trackFilterButtonDiv.className = "igv-filter-histogram-button-div";
            trackFilterButtonDiv.style.top = nextButtonTop + "px";
            trackFilterButtonDiv.style.left = "5px";

//            this.track.trackFilter = new igv.TrackFilter(this);
//            this.track.trackFilter.createTrackFilterWidgetWithParentElement(trackFilterButtonDiv);

            this.track.trackFilter = new igv.TrackFilter(this);
            this.track.trackFilter.createTrackFilterWidgetWithParentElement(trackFilterButtonDiv);

            nextButtonTop += 18;

        }

        // Close button
        if (!track.disableButtons) {

            closeButton = document.createElement("i");
            contentDiv.appendChild(closeButton);
            closeButton.style.color = "black";
            closeButton.className = "fa fa-times-circle";
            closeButton.style.position = "absolute";
            closeButton.style.top = "5px";
            closeButton.style.right = "5px";
            closeButton.style.cursor = "pointer";
            closeButton.onclick = function () {

//                removeTrackPanel(trackPanel);
                browser.removeTrack(track);

                // We removed a track. This removes it's filter. Must update filter chain application
                if (browser.type === "CURSOR") {
                    browser.cursorModel.filterRegions();
                }

            };

            if (track.label) {

                labelButton = document.createElement("button");
                viewportDiv.appendChild(labelButton);
                labelButton.className = "btn btn-xs btn-cursor-deselected";
                labelButton.style.position = "absolute";
                labelButton.style.top = "10px";
                labelButton.style.left = "10px";
                labelButton.innerHTML = track.label;
                track.labelButton = labelButton;

                labelButton.onclick = function () {

                    if(browser.cursorModel) {
                        track.featureSource.allFeatures(function (featureList) {

                            browser.referenceFrame.start = 0;
                            browser.cursorModel.setRegions(featureList);
//                        browser.update();


                        });


                        browser.trackPanels.forEach(function (trackPanel) {
                            if (track !== trackPanel.track) {
                                trackPanel.track.labelButton.className = "btn btn-xs btn-cursor-deselected";
                            }
                        });
                    }
                    labelButton.className = "btn btn-xs btn-cursor-selected";

                }


            }
        }


        browser.rootHeight += viewportHeight + this.marginBottom;

        browser.div.style.height = browser.rootHeight + 165 + "px";

        this.canvas = canvas;
        this.ctx = canvas.getContext("2d");

        addTrackHandlers(this);

        function removeTrackPanel(trackPanel) {

            var array = browser.trackPanels;
            array.splice(array.indexOf(trackPanel), 1);

            browser.trackContainerDiv.removeChild(trackPanel.trackDiv);

            browser.rootHeight = 0;
            browser.trackPanels.forEach(function (panel) {
                panel.trackDiv.style.top = browser.rootHeight + "px";
                browser.rootHeight += panel.trackDiv.clientHeight;

                browser.div.style.height = browser.rootHeight + 165 + "px";
            });

            // We removed a track. This removes it's filter. Must
            // now update filter chain application
            if (browser.type === "CURSOR") {
                browser.cursorModel.filterRegions();
            }
        }

        function addTrackHandlers(trackPanel) {

            var canvas = trackPanel.canvas;
            var isMouseDown = false;
            var mouseDownX = undefined;
            var lastMouseX = undefined;
            var referenceFrame = trackPanel.browser.referenceFrame;

            canvas.onmousedown = function (e) {

                var dx = e.clientX - $(canvas).offset().left;

                isMouseDown = true;

                mouseDownX = e.clientX;
                lastMouseX = dx;

            };

            canvas.onmousemove = throttle(function (e) {
                var dx = e.clientX - $(canvas).offset().left;


                if (isMouseDown) {

                    if (lastMouseX) {

                        referenceFrame.shiftPixels(lastMouseX - dx);

                        if (referenceFrame.start < 0) {
                            referenceFrame.start = 0;
                        }

//                        if (igv.genome) {
//                            var chromosome = igv.genome.getChromosome(igv.referenceFrame.chr);
//                            var widthBP = Math.round((igv.trackWidth - igv.labelWidth) * igv.referenceFrame.bpPerPixel);
//                            var endBP = igv.referenceFrame.start + widthBP;
//                            if (chromosome && endBP > chromosome.bpLength) {
//                                if (endBP > chromosome.length) {
//                                    igv.referenceFrame.start = chromosome.bpLength - widthBP;
//                                }
//                            }
//                        }
                    }

                    lastMouseX = dx;


                    trackPanel.browser.repaint();
                }

            }, 20);

            canvas.onmouseup = function (e) {

                if (e.clientX === mouseDownX) {

//                    $(trackPanel.trackDiv).qtip({
//                        content: {
//                            title: {
//                                text: "Genomic Gymnastics",
//                                button: true
//                            },
//                            text: "Track " + trackPanel.trackDiv.title + " location " + igv.numberFormatter(1 + trackPanel.genomicCoordinateWithEventTap(e))
//                        },
////                        show: {
////                            event: 'click'
////                        },
//                        hide: {
//                            delay: 100,
//                            fixed: true
//                        },
//                        position: {
//                            target: 'mouse',
//                            viewport: $(window),
//                            adjust: {
////                                method: 'flip shift',
//                                mouse: false
//                            }
//                        },
//
//                        style: {
//                            width: 200,
//                            height: 200,
//                            tip: false,
//                            widget: false
//                        }
//                    });

                }

                isMouseDown = false;
                lastMouseX = undefined;
                mouseDownX = undefined;
            };

            canvas.onmouseout = function (e) {
                isMouseDown = false;
                lastMouseX = undefined;
                mouseDownX = undefined;
            };

            canvas.ondblclick = function (e) {

                var mouseX = e.clientX - $(canvas).offset().left;
                var mouseY = e.clientY - $(canvas).offset().top;

                if (trackPanel.track.handleDblClick) {
                    trackPanel.track.handleDblClick(mouseX, mouseY, trackPanel.viewportDiv);
                }
                else {
                    var newCenter = Math.round(trackPanel.browser.referenceFrame.start + mouseX * trackPanel.browser.referenceFrame.bpPerPixel);
                    referenceFrame.bpPerPixel /= 2;
                    trackPanel.browser.goto(trackPanel.browser.referenceFrame.chr, newCenter);
                }
            };

//            canvas.onclick = function (e) {
//
//                var dx = e.clientX - $(canvas).offset().left;
//                console.log("movement " + (dx - lastMouseX));
//
//            };
        }

    };

    igv.TrackView.prototype.genomicCoordinateWithEventTap = function (event) {

        var pixels = event.clientX - $(this.canvas).offset().left;
        return Math.floor( (this.browser.referenceFrame.start) + this.browser.referenceFrame.toBP(pixels) );
{'fraction_non_alphanumeric': 0.10155143100028337, 'fraction_numerical': 0.00403797109662794, 'mean_word_length': 1.3451283329180164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2305671', 'n_tokens_mistral': 7140, 'n_tokens_neox': 6599, 'n_words': 1233}