<commit_before>/**
 * Class to render the d3js volcano plot, coupling it to a dataTable
 * such that the dataTable displays the selections made in the plot
 * and vice-versa.
 */
function VolcanoPlot() {

    var self = this;
    self.scatterPlot = null;

    /**
     * Trigger the rendering of the plot.
     *
     * @param plotElName: el where the plot should be rendered
     * @param data: data from dataTable, but in original form (json)
     * @param dataTable: dataTable item to be updated when selections are made in plot
     * @param miniOnco: miniOnco item to be updated when plot item is clicked
     */

    this.render = function(orTable){
        self.orTable = orTable;
        self.miniOnco = orTable.miniOnco;

        var plotDataAttr = {
            min_x: 0,
            max_x: 0,
            min_y: 0,
            max_y: 0,
            abs_max_x: 0,
            abs_max_y: 0
        };

        // prepare the data
        var dataTrace = createDataTrace(orTable.originalData, plotDataAttr)

        //draw the plot with the prepared x,y coordinates data:
        drawPlot(dataTrace, null, orTable.plot_div, plotDataAttr);
    }

    // create data trace based on data and fill plotDataAttr with min and max values
    function createDataTrace(data, plotDataAttr){
        var xValues=[], yValues=[], labels=[];

        //build up plots x,y coordinates list based on data columns "Log Ratio" and "p-Value" received:
        //TODO this could be made generic to support also other data with different column names (perhaps add a presenter layer that makes the translation of the specific column names to the generic ones to be supported here)
        for (var i = 0; i < data.length; i++){
            var xValue = parseFloat(data[i]["Log Ratio"].replace("<","").replace(">","")); //remove < and > from <-10 or >10 scenarios
            var yValue = -Math.log10(data[i]["p-Value"]);
            if (xValue < plotDataAttr.min_x) {
                plotDataAttr.min_x = xValue;
            }
            if (xValue > plotDataAttr.max_x){
                plotDataAttr.max_x = xValue;
            }
            if (yValue < plotDataAttr.min_y){
                plotDataAttr.min_y = yValue;
            }
            if (yValue > plotDataAttr.max_y) {
                plotDataAttr.max_y = yValue;
            }

            xValues.push(xValue);
            yValues.push(yValue);
            labels.push(data[i]["Gene"]);
        }

        // store abs max values
        if(Math.abs(plotDataAttr.min_x)>Math.abs(plotDataAttr.max_x)){
            plotDataAttr.abs_max_x = Math.abs(plotDataAttr.min_x);
        }
        else{
            plotDataAttr.abs_max_x = Math.abs(plotDataAttr.max_x);
        }

        if(Math.abs(plotDataAttr.min_y)>Math.abs(plotDataAttr.max_y)){
            plotDataAttr.abs_max_y = Math.abs(plotDataAttr.min_y);
        }
        else{
            plotDataAttr.abs_max_y = Math.abs(plotDataAttr.max_y);
        }

        var dataTrace = {
            x: xValues,
            y: yValues,
            text: labels
        }
        return dataTrace;
    }

    function addPlotLayoutOptions(){
        var axisOptions = {
            xaxis:{
                title: 'log Ratio'
            },
            yaxis:{
                title: '-log10 p-value'
            },
            yaxis2:{
                title: 'significance &#8594;', // &#8594; is code for -->
                titlefont: {
                    color: 'black',
                },
                showgrid: false,
                showticklabels: false,
                zeroline: false,
                showline: false,
                autotick: false,
                ticks: '',
                overlaying: 'y',
                side: 'right',
            }
        }
        self.scatterPlot.addPlotLayoutOptions(axisOptions);
    }

    function drawPlot(dataTrace, model, plotElName, plotDataOptions) {

        var axisMargin=1.25;
        var minX = -1*plotDataOptions.abs_max_x;
        var maxX = plotDataOptions.abs_max_x;
        var pVal = -Math.log10(orAnalysis.settings.p_val_threshold);

        // create the plot and add extra layout options for the axis
        self.scatterPlot = new ScatterPlotlyTest(plotElName, dataTrace);
        addPlotLayoutOptions();

        // create pVal trace (the dotted line in the plot) and add it
        var pValTrace = {
            x:[minX*axisMargin, maxX*axisMargin],
            y:[pVal, pVal],
            mode: 'lines',
            hoverinfo: 'none',
            marker:{
                color: 'black'
            },
            line: {<commit_msg>bugfix for IE<commit_after>/**
 * Class to render the d3js volcano plot, coupling it to a dataTable
 * such that the dataTable displays the selections made in the plot
 * and vice-versa.
 */
function VolcanoPlot() {

    var self = this;
    self.scatterPlot = null;

    /**
     * Trigger the rendering of the plot.
     *
     * @param plotElName: el where the plot should be rendered
     * @param data: data from dataTable, but in original form (json)
     * @param dataTable: dataTable item to be updated when selections are made in plot
     * @param miniOnco: miniOnco item to be updated when plot item is clicked
     */

    this.render = function(orTable){
        self.orTable = orTable;
        self.miniOnco = orTable.miniOnco;

        var plotDataAttr = {
            min_x: 0,
            max_x: 0,
            min_y: 0,
            max_y: 0,
            abs_max_x: 0,
            abs_max_y: 0
        };

        // prepare the data
        var dataTrace = createDataTrace(orTable.originalData, plotDataAttr)

        //draw the plot with the prepared x,y coordinates data:
        drawPlot(dataTrace, null, orTable.plot_div, plotDataAttr);
    }

    // create data trace based on data and fill plotDataAttr with min and max values
    function createDataTrace(data, plotDataAttr){
        var xValues=[], yValues=[], labels=[];

        //build up plots x,y coordinates list based on data columns "Log Ratio" and "p-Value" received:
        //TODO this could be made generic to support also other data with different column names (perhaps add a presenter layer that makes the translation of the specific column names to the generic ones to be supported here)
        for (var i = 0; i < data.length; i++){
            var xValue = parseFloat(data[i]["Log Ratio"].replace("<","").replace(">","")); //remove < and > from <-10 or >10 scenarios
            var yValue = -Math.log10(data[i]["p-Value"]);
            if (xValue < plotDataAttr.min_x) {
                plotDataAttr.min_x = xValue;
            }
            if (xValue > plotDataAttr.max_x){
                plotDataAttr.max_x = xValue;
            }
            if (yValue < plotDataAttr.min_y){
                plotDataAttr.min_y = yValue;
            }
            if (yValue > plotDataAttr.max_y) {
                plotDataAttr.max_y = yValue;
            }

            xValues.push(xValue);
            yValues.push(yValue);
            labels.push(data[i]["Gene"]);
        }

        // store abs max values
        if(Math.abs(plotDataAttr.min_x)>Math.abs(plotDataAttr.max_x)){
            plotDataAttr.abs_max_x = Math.abs(plotDataAttr.min_x);
        }
        else{
            plotDataAttr.abs_max_x = Math.abs(plotDataAttr.max_x);
        }

        if(Math.abs(plotDataAttr.min_y)>Math.abs(plotDataAttr.max_y)){
            plotDataAttr.abs_max_y = Math.abs(plotDataAttr.min_y);
        }
        else{
            plotDataAttr.abs_max_y = Math.abs(plotDataAttr.max_y);
        }

        var dataTrace = {
            x: xValues,
            y: yValues,
            text: labels
        }
        return dataTrace;
    }

    function addPlotLayoutOptions(){
        var axisOptions = {
            xaxis:{
                title: 'log Ratio'
            },
            yaxis:{
                title: '-log10 p-value'
            },
            yaxis2:{
                title: 'significance &#8594;', // &#8594; is code for -->
                titlefont: {
                    color: 'black',
                },
                showgrid: false,
                showticklabels: false,
                zeroline: false,
                showline: false,
                autotick: false,
                ticks: '',
                overlaying: 'y',
                side: 'right',
            }
        }
        self.scatterPlot.addPlotLayoutOptions(axisOptions);
    }

    // for IE compatibility
    Math.log10 = function (x) {
        return Math.log(x) / Math.LN10;
    };

    function drawPlot(dataTrace, model, plotElName, plotDataOptions) {

        var axisMargin=1.25;
        var minX = -1*plotDataOptions.abs_max_x;
        var maxX = plotDataOptions.abs_max_x;
        var pVal = -Math.log10(orAnalysis.settings.p_val_threshold);

        // create the plot and add extra layout options for the axis
        self.scatterPlot = new ScatterPlotlyTest(plotElName, dataTrace);
        addPlotLayoutOptions();

        // create pVal trace (the dotted line in the plot) and add it
        var pValTrace = {
            x:[minX*axisMargin, maxX*axisMargin],
            y:[pVal, pVal],
            mode: 'lines',
            hoverinfo: 'none',
            marker:{
                color: 'black'
            },
            line: {
{'fraction_non_alphanumeric': 0.09835188356164383, 'fraction_numerical': 0.007063356164383561, 'mean_word_length': 1.7071263035921205, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '1697849', 'n_tokens_mistral': 2814, 'n_tokens_neox': 2647, 'n_words': 737}