<commit_before>var GENEMAP = GENEMAP || {};


GENEMAP.GeneAnnotations = function (userConfig) {
  var defaultConfig = {
    border: false,
    labelRectangles: false,
    onAnnotationSelectFunction: $.noop(),
    onExpandClusterFunction: $.noop(),
    longestChromosome: 100,
    layout: {
      width: 10,
      height: 100,
      x: 0,
      y: 0,
    },
    chromosomeWidth: 20,
    annotationMarkerSize: 5,
    annotationLabelSize: 5,
    showAnnotationLabels: true,
    infoBoxManager: GENEMAP.InfoBox(),
    nClusters: 6,
    doClustering: true,
    maxAnnotationLayers: 3,
  };

  var config = _.merge({}, defaultConfig, userConfig);

  var buildYScale = function () {
    return d3.scale.linear().range([0, config.layout.height]).domain([0, config.longestChromosome]);
  };

  // adds the gene annotations to the annotations group within it, uses the data
  // bound to the annotationsGroup to generate the annotation elements
  var setupGeneAnnotations = function (annotationGroup, chromosome) {
    log.trace('setupGeneAnnotations');

   var y = buildYScale();

    // Enter + Update elements
    // Use a key function so that the correct mapping between graphical objects
    // and data points is maintained even when clustering changes
    var geneAnnotations = annotationGroup.selectAll('g.gene-annotation').data(
        chromosome.layout.nodes, function(d){return d.data.id});

    var geneAnnotationsEnterGroup = geneAnnotations.enter()
      .append('g').classed('gene-annotation', true);

    geneAnnotationsEnterGroup.append('line').classed('midpoint-line', true);
    geneAnnotationsEnterGroup.append('path').classed('link', true);

    if (config.labelRectangles) {
      geneAnnotationsEnterGroup.append('rect').classed('labella', true);
    }

    //geneAnnotationsEnterGroup.append('polygon').classed('infobox', true);
    geneAnnotationsEnterGroup.append('text');

    geneAnnotations.attr('id', function (d) {
      return 'feature_' + d.data.id;
    });

    geneAnnotations.classed('selected', function(d){ return d.data.selected; });

    geneAnnotations.select('line.midpoint-line').attr({
      x1: -(config.chromosomeWidth * 0.5),
      y1: function (d) { return y(d.data.midpoint); },
      y2: function (d) { return y(d.data.midpoint); },
      x2: 0,
    });

    config.infoBoxManager.setupInfoboxOnSelection(geneAnnotations);

    geneAnnotations.on('click', function (d) {
      //If user clicks on a gene, toggle gene selection
      if (d.data.type == "gene") {
        log.info('gene annotation click');
        d.data.selected = !d.data.selected;
        config.onAnnotationSelectFunction();
      }

      //If user clicks on a cluster of genes, expand that cluster
      if (d.data.type == "geneslist") {
        log.info('geneslist annotation click');
        config.onExpandClusterFunction(chromosome, d.data);
      }
    });

    // generate  markers
    var pointsFn = function (d) {
      var points = [];

      var a = config.annotationMarkerSize;
      //genes represented by triangles
      if (d.data.type == "gene") {

        var h = Math.sqrt(Math.pow(a, 2) - Math.pow((a / 2), 2));
        h = h * 1.5; // stretch the width of the triangle

        points.push([d.x, d.y]);
        points.push([d.x + h, d.y - a / 2]);
        points.push([d.x + h, d.y + a / 2]);

      }
      //gene clusters represented by squares
      else if (d.data.type == "geneslist") {
        points.push([d.x , d.y + a / 2]);
        points.push([d.x , d.y - a / 2]);
        points.push([d.x + a , d.y - a / 2]);
        points.push([d.x + a , d.y + a / 2]);
      }

      return points.join(' ');
    };

    geneAnnotations.select('polygon').attr({
      points: pointsFn,
    }).style({
      fill: function (d) {
        return d.data.color;
      },
    });

    geneAnnotations.select('path.link')
      .attr({
        d: function (d) { return d.data.path ;}
      });

    // draw the labella labels as rectangles, useful for debugging
    if (config.labelRectangles) {
      geneAnnotations.select('rect.labella').attr({
          fill: 'green',
          stroke: 'none',
          x: function (d) { return d.x; },
          y: function (d) {
            return d.y - d.dy / 2;
          },
          width: function (d) { return d.dx; },
          height: function (d) { return d.dy; },
        });
    }

    geneAnnotations.select('text').attr({
      x: function (d) { return d.x + 0.1 * config.annotationLabelSize; },
      y: function (d) { return d.y + 0.4 * config.annotationLabelSize; },
    }).style({
      'font-size': config.annotationLabelSize + 'px',
      visibility: function (d) {
        if (d.data.showLabel === 'show') {
          return 'visible';
        } else if (d.data.showLabel === 'hide') {
          return 'visible';
        }

        return config.showAnnotationLabels ? 'visible' : 'visible';
      },
    })
      .attr( { fill: function (d) { return d.data.color; } })
      .text(function (d) {
      if (d.data.type == "gene") {
        return d.data.label;
      }
      else if (d.data.type == "geneslist"){
        return "(" + d.data.genesList.length + ")";
      }
    });

    var exitGroup = geneAnnotations.exit()
    //avoid any orphaned popovers
    exitGroup.each( function(d){
      $('.infobox', this).popover('hide') ;
    } );<commit_msg>Format gene labels<commit_after>var GENEMAP = GENEMAP || {};


GENEMAP.GeneAnnotations = function (userConfig) {
  var defaultConfig = {
    border: false,
    labelRectangles: false,
    onAnnotationSelectFunction: $.noop(),
    onExpandClusterFunction: $.noop(),
    longestChromosome: 100,
    layout: {
      width: 10,
      height: 100,
      x: 0,
      y: 0,
    },
    chromosomeWidth: 20,
    annotationMarkerSize: 5,
    annotationLabelSize: 5,
    showAnnotationLabels: true,
    infoBoxManager: GENEMAP.InfoBox(),
    nClusters: 6,
    doClustering: true,
    maxAnnotationLayers: 3,
  };

  var config = _.merge({}, defaultConfig, userConfig);

  var buildYScale = function () {
    return d3.scale.linear().range([0, config.layout.height]).domain([0, config.longestChromosome]);
  };

  // adds the gene annotations to the annotations group within it, uses the data
  // bound to the annotationsGroup to generate the annotation elements
  var setupGeneAnnotations = function (annotationGroup, chromosome) {
    log.trace('setupGeneAnnotations');

   var y = buildYScale();

    // Enter + Update elements
    // Use a key function so that the correct mapping between graphical objects
    // and data points is maintained even when clustering changes
    var geneAnnotations = annotationGroup.selectAll('g.gene-annotation').data(
        chromosome.layout.nodes, function(d){return d.data.id});

    var geneAnnotationsEnterGroup = geneAnnotations.enter()
      .append('g').classed('gene-annotation', true);

    geneAnnotationsEnterGroup.append('line').classed('midpoint-line', true);
    geneAnnotationsEnterGroup.append('path').classed('link', true);

    if (config.labelRectangles) {
      geneAnnotationsEnterGroup.append('rect').classed('labella', true);
    }

    //geneAnnotationsEnterGroup.append('polygon').classed('infobox', true);
    geneAnnotationsEnterGroup.append('text');

    geneAnnotations.attr('id', function (d) {
      return 'feature_' + d.data.id;
    });

    geneAnnotations.classed('selected', function(d){ return d.data.selected; });

    geneAnnotations.select('line.midpoint-line').attr({
      x1: -(config.chromosomeWidth * 0.5),
      y1: function (d) { return y(d.data.midpoint); },
      y2: function (d) { return y(d.data.midpoint); },
      x2: 0,
    });

    config.infoBoxManager.setupInfoboxOnSelection(geneAnnotations);

    geneAnnotations.on('click', function (d) {
      //If user clicks on a gene, toggle gene selection
      if (d.data.type == "gene") {
        log.info('gene annotation click');
        d.data.selected = !d.data.selected;
        config.onAnnotationSelectFunction();
      }

      //If user clicks on a cluster of genes, expand that cluster
      if (d.data.type == "geneslist") {
        log.info('geneslist annotation click');
        config.onExpandClusterFunction(chromosome, d.data);
      }
    });

    // generate  markers
    var pointsFn = function (d) {
      var points = [];

      var a = config.annotationMarkerSize;
      //genes represented by triangles
      if (d.data.type == "gene") {

        var h = Math.sqrt(Math.pow(a, 2) - Math.pow((a / 2), 2));
        h = h * 1.5; // stretch the width of the triangle

        points.push([d.x, d.y]);
        points.push([d.x + h, d.y - a / 2]);
        points.push([d.x + h, d.y + a / 2]);

      }
      //gene clusters represented by squares
      else if (d.data.type == "geneslist") {
        points.push([d.x , d.y + a / 2]);
        points.push([d.x , d.y - a / 2]);
        points.push([d.x + a , d.y - a / 2]);
        points.push([d.x + a , d.y + a / 2]);
      }

      return points.join(' ');
    };

    geneAnnotations.select('polygon').attr({
      points: pointsFn,
    }).style({
      fill: function (d) {
        return d.data.color;
      },
    });

    geneAnnotations.select('path.link')
      .attr({
        d: function (d) { return d.data.path ;}
      });

    // draw the labella labels as rectangles, useful for debugging
    if (config.labelRectangles) {
      geneAnnotations.select('rect.labella').attr({
          fill: 'green',
          stroke: 'none',
          x: function (d) { return d.x; },
          y: function (d) {
            return d.y - d.dy / 2;
          },
          width: function (d) { return d.dx; },
          height: function (d) { return d.dy; },
        });
    }

    geneAnnotations.select('text').attr({
      x: function (d) { return d.x + 0.1 * config.annotationLabelSize; },
      y: function (d) { return d.y + 0.4 * config.annotationLabelSize; },
    }).style({
      'stroke': function(d){ return (d.data.selected ? d.color : 'none' ) },
      'font-size': function(d){ return (d.data.selected ? 0.2 : 0 ) + config.annotationLabelSize + 'px'},
      'font-weight' : function(d){ return d.data.selected ? 'bold' : 'normal'},
      'background-color' : function(d){ return d.data.selected ? 'white' : 'none'},
    })
      .attr( { fill: function (d) { return d.data.color; } })
      .text(function (d) {
      if (d.data.type == "gene") {
        return d.data.label;
      }
      else if (d.data.type == "geneslist"){
        return "(" + d.data.genesList.length + ")";
      }
    });

    var exitGroup = geneAnnotations.exit()
    //avoid any orphaned popovers
    exitGroup.each( function(d){
      $('.infobox', this).popover('hide') ;
    } );
{'fraction_non_alphanumeric': 0.15247432306255837, 'fraction_numerical': 0.008123249299719889, 'mean_word_length': 2.473086900129702, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1116759', 'n_tokens_mistral': 3518, 'n_tokens_neox': 3283, 'n_words': 797}