<commit_before>var View = require('./view');
var template = require('./templates/oncovis');
var FeatureMatrix2 = require('../models/featureMatrix2');

module.exports = View.extend({
    model:FeatureMatrix2,
    template:template,
    label:"Oncovis",
    className: "row-fluid",

    events:{
        "click .reset-sliders":"resetSliders"
    },

    initialize:function () {
        _.bindAll(this, 'renderGraph', 'initControls', 'render', 'resetSliders');
    },

    afterRender:function () {
        var _this = this;
        this.initControls();
        this.model.on('load', _this.renderGraph);
    },

    initControls:function () {
        console.log("initControls:start");

        this.$el.find(".slider_barheight").oncovis_range({ storageId:"slider_barheight", min:10, max:50, initialStep:20 });
        this.$el.find(".slider_rowspacing").oncovis_range({ storageId:"slider_rowspacing", min:10, max:50, initialStep:20 });
        this.$el.find(".slider_barwidth").oncovis_range({ storageId:"slider_barwidth", min:1, max:10, initialStep:5 });
        this.$el.find(".slider_barspacing").oncovis_range({ storageId:"slider_barspacing", min:0, max:10, initialStep:2 });
        this.$el.find(".slider_clusterspacing").oncovis_range({ storageId:"slider_clusterspacing", min:0, max:50, initialStep:10 });
        this.$el.find(".slider_fontsize").oncovis_range({ storageId:"slider_fontsize", min:5, max:21, initialStep:14 });

        var oncovis_container = this.$el.find(".oncovis-container");
        var visrangeFn = function (property) {
            return function (event, value) {
                console.log("visrangeFn(" + property + "=" + value + ")");
                var dim = {};
                dim[property] = value;
                oncovis_container.update(dim);
            }
        };

        this.$el.find(".slider_barheight").on("slide-to", visrangeFn("bar_height"));
        this.$el.find(".slider_rowspacing").on("slide-to", visrangeFn("row_spacing"));
        this.$el.find(".slider_barwidth").bind("slide-to", visrangeFn("bar_width"));
        this.$el.find(".slider_barspacing").bind("slide-to", visrangeFn("column_spacing"));
        this.$el.find(".slider_clusterspacing").bind("slide-to", visrangeFn("cluster_spacing"));
        this.$el.find(".slider_fontsize").bind("slide-to", visrangeFn("label_fontsize"));

        console.log("initControls:end");
    },

    renderGraph:function () {
        console.log("renderGraph:start");

        var rowLabels = this.model.dims.getRowLabels();
        var clusterGroups = {};

        var columns = this.model.COLUMNS;
        var cluster_idx = this.model.ROWS.indexOf(this.model.dims.getClusterProperty());
        _.each(this.model.DATA[cluster_idx], function(cell, idx) {
            cell = cell.trim();
            if (!clusterGroups[cell]) clusterGroups[cell] = [];
            clusterGroups[cell].push(this.model.COLUMNS[idx]);
        }, this);

        var columns_by_cluster = {};
        var _this = this;
        _.each(clusterGroups, function(column_idxs, cluster) {
            columns_by_cluster[cluster] = _.sortBy(column_idxs, function(column_idx) {
                return _.map(rowLabels, function(rowLabel) {
                    var row_idx = _this.model.ROWS.indexOf(rowLabel);
                    var value = _this.model.DATA[row_idx][column_idx];
                    return (value && value.toLowerCase) ? value.toLowerCase() : value;
                });
            });
        });

        var data = {};
        var categories_by_rowlabel = {};
        _.each(rowLabels, function(rowLabel) {
            categories_by_rowlabel[rowLabel] = {};

            var row_idx = _this.model.ROWS.indexOf(rowLabel);
            _.each(_this.model.DATA[row_idx], function(cell, cellIdx) {
                var columnLabel = _this.model.COLUMNS[cellIdx];
                if (!data[columnLabel]) data[columnLabel] = {};
                categories_by_rowlabel[rowLabel][cell] = true;
                data[columnLabel][rowLabel] = { "value":cell, "row": rowLabel, "label":columnLabel + "\n" + rowLabel + "\n" + cell };
            });
        });

        var colorscales_by_rowlabel = { overrides: {} };
        _.each(categories_by_rowlabel, function(obj, rowLabel) {
            var categories = _.keys(obj);
            colorscales_by_rowlabel[rowLabel] = d3.scale.ordinal()
                                                          .domain(categories)
                                                          .range(d3.range(categories.length)
                                                          .map(d3.scale.linear().domain([0, categories.length - 1])
                                                          .range(["yellow", "blue"])
                                                          .interpolate(d3.interpolateLab)));
        });

        var optns = {
            plot_width:3000,
            plot_height:3000,
            label_width:70,
            highlight_fill:colorbrewer.RdYlGn[3][2],
            color_fn:function (d) {
                if (d) {
                    return colorscales_by_rowlabel[d.row](d.value);
                }
                return "white";
            },
            columns_by_cluster:clusterGroups,
            cluster_labels: _.keys(clusterGroups),
            row_labels:rowLabels,<commit_msg>correcting sort on oncovis<commit_after>var View = require('./view');
var template = require('./templates/oncovis');
var FeatureMatrix2 = require('../models/featureMatrix2');

module.exports = View.extend({
    model:FeatureMatrix2,
    template:template,
    label:"Oncovis",
    className: "row-fluid",

    events:{
        "click .reset-sliders":"resetSliders"
    },

    initialize:function () {
        _.bindAll(this, 'renderGraph', 'initControls', 'render', 'resetSliders');
    },

    afterRender:function () {
        var _this = this;
        this.initControls();
        this.model.on('load', _this.renderGraph);
    },

    initControls:function () {
        console.log("initControls:start");

        this.$el.find(".slider_barheight").oncovis_range({ storageId:"slider_barheight", min:10, max:50, initialStep:20 });
        this.$el.find(".slider_rowspacing").oncovis_range({ storageId:"slider_rowspacing", min:10, max:50, initialStep:20 });
        this.$el.find(".slider_barwidth").oncovis_range({ storageId:"slider_barwidth", min:1, max:10, initialStep:5 });
        this.$el.find(".slider_barspacing").oncovis_range({ storageId:"slider_barspacing", min:0, max:10, initialStep:2 });
        this.$el.find(".slider_clusterspacing").oncovis_range({ storageId:"slider_clusterspacing", min:0, max:50, initialStep:10 });
        this.$el.find(".slider_fontsize").oncovis_range({ storageId:"slider_fontsize", min:5, max:21, initialStep:14 });

        var oncovis_container = this.$el.find(".oncovis-container");
        var visrangeFn = function (property) {
            return function (event, value) {
                console.log("visrangeFn(" + property + "=" + value + ")");
                var dim = {};
                dim[property] = value;
                oncovis_container.update(dim);
            }
        };

        this.$el.find(".slider_barheight").on("slide-to", visrangeFn("bar_height"));
        this.$el.find(".slider_rowspacing").on("slide-to", visrangeFn("row_spacing"));
        this.$el.find(".slider_barwidth").bind("slide-to", visrangeFn("bar_width"));
        this.$el.find(".slider_barspacing").bind("slide-to", visrangeFn("column_spacing"));
        this.$el.find(".slider_clusterspacing").bind("slide-to", visrangeFn("cluster_spacing"));
        this.$el.find(".slider_fontsize").bind("slide-to", visrangeFn("label_fontsize"));

        console.log("initControls:end");
    },

    renderGraph:function () {
        console.log("renderGraph:start");

        var rowLabels = this.model.dims.getRowLabels();
        var cluster_property = this.model.dims.getClusterProperty();
        var cluster_idx = this.model.ROWS.indexOf(cluster_property);

        var _this = this;
        var column_data = {};

        var appendFn = function(rowLabel, cells) {
            _.each(cells, function(cell, columnIdx) {
                if (!column_data[columnIdx]) {
                    column_data[columnIdx] = { "colIdx": columnIdx };
                }
                column_data[columnIdx][rowLabel] = cell;
            });
        };

        appendFn(cluster_property, this.model.DATA[cluster_idx]);
        _.each(rowLabels, function(rowLabel) {
            var row_idx = _this.model.ROWS.indexOf(rowLabel);
            appendFn(rowLabel, _this.model.DATA[row_idx]);
        });

        _.each(rowLabels, function(rowLabel) {
            column_data = _.sortBy(column_data, rowLabel);
        });
        column_data = _.sortBy(column_data, cluster_property);

        var columns_by_cluster = {};
        _.each(column_data, function(column_item) {
            var cluster_value = column_item[cluster_property].trim();
            if (!columns_by_cluster[cluster_value]) columns_by_cluster[cluster_value] = [];
            columns_by_cluster[cluster_value].push(_this.model.COLUMNS[column_item.colIdx]);
        });

        var data = {};
        var categories_by_rowlabel = {};
        _.each(rowLabels, function(rowLabel) {
            categories_by_rowlabel[rowLabel] = {};

            var row_idx = _this.model.ROWS.indexOf(rowLabel);
            _.each(_this.model.DATA[row_idx], function(cell, cellIdx) {
                var columnLabel = _this.model.COLUMNS[cellIdx];
                if (!data[columnLabel]) data[columnLabel] = {};
                categories_by_rowlabel[rowLabel][cell] = true;
                data[columnLabel][rowLabel] = { "value":cell, "row": rowLabel, "label":columnLabel + "\n" + rowLabel + "\n" + cell };
            });
        });

        var colorscales_by_rowlabel = { overrides: {} };
        _.each(categories_by_rowlabel, function(obj, rowLabel) {
            var categories = _.keys(obj);
            colorscales_by_rowlabel[rowLabel] = d3.scale.ordinal()
                                                          .domain(categories)
                                                          .range(d3.range(categories.length)
                                                          .map(d3.scale.linear().domain([0, categories.length - 1])
                                                          .range(["yellow", "blue"])
                                                          .interpolate(d3.interpolateLab)));
        });

        var optns = {
            plot_width:3000,
            plot_height:3000,
            label_width:70,
            highlight_fill:colorbrewer.RdYlGn[3][2],
            color_fn:function (d) {
                if (d) {
                    return colorscales_by_rowlabel[d.row](d.value);
                }
                return "white";
            },
            columns_by_cluster:columns_by_cluster,
            cluster_labels: _.keys(columns_by_cluster),
            row_labels:rowLabels,
{'fraction_non_alphanumeric': 0.14412296564195298, 'fraction_numerical': 0.00922242314647378, 'mean_word_length': 2.1931293302540418, 'pattern_counts': {'":': 9, '<': 3, '<?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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3710794', 'n_tokens_mistral': 3195, 'n_tokens_neox': 3075, 'n_words': 434}