<commit_before>/*
 * Copyright 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var GROUP_TYPE_COLUMN = 0;
var GROUP_VALUE_COLUMN = 1;
var DAY_COLUMN = 2;


function getSelectedGroupType() {
  return $('input:radio[name=\'chart1\']:checked').val();
}


function getSelectedGroupValues() {
  return $.makeArray(
    $('.group-value-checkbox:checked').map(function(index, el) {
      return $(el).val();
    }));
}


function getIsNormalized() {
  return $('input:checkbox[name=\'normalize\']:checked').val();
}


function getIsWeekly() {
  return $('input:checkbox[name=\'weekly\']:checked').val();
}


function createGroupTypeRadios(groupTypes) {
  var vizDiv = $('#viz_group_type1');
  vizDiv.empty();

  // Guess that whichever group type has only one value and that value is
  // empty will be the topline data.
  var checkedType = null;
  $.each(groupTypes, function(key, value) {
    if (value.length == 1 && value[0] === '') {
      checkedType = key;
    }
  });

  var i = 0;
  $.each(groupTypes, function(key, value) {
    var radioId = 'group_type_radio1_' + (i++);
    var useRadio = $('<input type="radio">')
        .addClass('group-type-radio')
        .attr('id', radioId)
        .attr('name', 'chart1')
        .attr('value', key);

    // Select the default group type.
    if (!!checkedType && checkedType === key) {
      useRadio.attr('checked', 'checked');
    }

    var container = $('<div>');
    container.append(useRadio);
    container.append($('<label>').attr('for', radioId).text(key));

    vizDiv.append(container);
  });

  // Register event handlers
  $('.group-type-radio').click(function() {
    createGroupValueCheckboxes(groupTypes);
    $(document).trigger('cohorts.viz');
  });
}


function createGroupValueCheckboxes(groupTypes) {
  var type = getSelectedGroupType();
  var values = groupTypes[type];
  if (!values) {
    $.error('Bad group type: ' + type);
  }

  var valuesDiv = $('#viz_group_value1');
  valuesDiv.empty();

  // Forces the multi-column view to look good for a small number of values.
  if (values.length < 10) {
    valuesDiv.addClass('section-small');
  } else {
    valuesDiv.removeClass('section-small');
  }

  // Special case for group types that only have a single, empty value.
  if (values.length == 1 && values[0] === '') {
    return;
  }

  valuesDiv.append(
      $('<div class="section-header">')
          .text('Included group values'));

  var sectionContent = $('<div class="section-content">');

  var i = 0;
  $.each(values, function(key, value) {
    var checkboxId = 'group_value_checkbox1_' + (i++);
    var container = $('<div>');
    container.append(
        $('<input type="checkbox" class="group-value-checkbox" checked>')
        .attr('value', value)
        .attr('id', checkboxId));
    container.append(
        $('<label>').attr('for', checkboxId).text(value));
    sectionContent.append(container);
  });
  valuesDiv.append(sectionContent);

  // Register event handlers
  $('.group-value-checkbox').click(function() {
    $(document).trigger('cohorts.viz');
  });
}


function createLegend(rowsWithHeader) {
  var columnNames = rowsWithHeader[0].slice(3);
  var container = $('#viz_legend');
  container.empty();

  var legendTable = $('<div class="legend-table inactive">');

  var color = d3.scale.category20();
  $.each(columnNames, function(index, value) {
    var row = $('<div class="legend-row">')
        .attr('data-state-name', value);
    $('<div class="legend-box">')
        .attr('style', 'background-color: ' + color(index))
        .appendTo(row);
    $('<div class="legend-label">')
        .text(value)
        .appendTo(row);
    $('<div class="legend-value">')
        .appendTo(row);
    $('<div class="legend-percentage">')
        .appendTo(row);
    // Reverse order to match graph stacking.
    legendTable.prepend(row);
  });

  // Add a row for the totals
  var row = $('<div class="legend-total">');
  $('<div class="legend-box">').appendTo(row);
  $('<div class="legend-label">')
      .text('Total')
      .appendTo(row);
  $('<div class="legend-value">')
      .appendTo(row);
  $('<div class="legend-percentage">')
      .appendTo(row);
  legendTable.append(row);

  container.append(legendTable);
}<commit_msg>Fixing column adjustment based on number of unique states<commit_after>/*
 * Copyright 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var GROUP_TYPE_COLUMN = 0;
var GROUP_VALUE_COLUMN = 1;
var DAY_COLUMN = 2;


function getSelectedGroupType() {
  return $('input:radio[name=\'chart1\']:checked').val();
}


function getSelectedGroupValues() {
  return $.makeArray(
    $('.group-value-checkbox:checked').map(function(index, el) {
      return $(el).val();
    }));
}


function getIsNormalized() {
  return $('input:checkbox[name=\'normalize\']:checked').val();
}


function getIsWeekly() {
  return $('input:checkbox[name=\'weekly\']:checked').val();
}


function createGroupTypeRadios(groupTypes) {
  var vizDiv = $('#viz_group_type1');
  vizDiv.empty();

  // Guess that whichever group type has only one value and that value is
  // empty will be the topline data.
  var checkedType = null;
  $.each(groupTypes, function(key, value) {
    if (value.length == 1 && value[0] === '') {
      checkedType = key;
    }
  });

  var i = 0;
  $.each(groupTypes, function(key, value) {
    var radioId = 'group_type_radio1_' + (i++);
    var useRadio = $('<input type="radio">')
        .addClass('group-type-radio')
        .attr('id', radioId)
        .attr('name', 'chart1')
        .attr('value', key);

    // Select the default group type.
    if (!!checkedType && checkedType === key) {
      useRadio.attr('checked', 'checked');
    }

    var container = $('<div>');
    container.append(useRadio);
    container.append($('<label>').attr('for', radioId).text(key));

    vizDiv.append(container);
  });

  // Register event handlers
  $('.group-type-radio').click(function() {
    createGroupValueCheckboxes(groupTypes);
    $(document).trigger('cohorts.viz');
  });
}


function createGroupValueCheckboxes(groupTypes) {
  var type = getSelectedGroupType();
  var values = groupTypes[type];
  if (!values) {
    $.error('Bad group type: ' + type);
  }

  var valuesDiv = $('#viz_group_value1');
  valuesDiv.empty();

  // Special case for group types that only have a single, empty value.
  if (values.length == 1 && values[0] === '') {
    return;
  }

  valuesDiv.append(
      $('<div class="section-header">')
          .text('Included group values'));

  var sectionContent = $('<div class="section-content">');

  var i = 0;
  $.each(values, function(key, value) {
    var checkboxId = 'group_value_checkbox1_' + (i++);
    var container = $('<div>');
    container.append(
        $('<input type="checkbox" class="group-value-checkbox" checked>')
        .attr('value', value)
        .attr('id', checkboxId));
    container.append(
        $('<label>').attr('for', checkboxId).text(value));
    sectionContent.append(container);
  });
  valuesDiv.append(sectionContent);

  // Register event handlers
  $('.group-value-checkbox').click(function() {
    $(document).trigger('cohorts.viz');
  });
}


function createLegend(rowsWithHeader) {
  var columnNames = rowsWithHeader[0].slice(3);
  var container = $('#viz_legend');
  container.empty();

  var legendTable = $('<div class="legend-table inactive">');

  var color = d3.scale.category20();
  $.each(columnNames, function(index, value) {
    var row = $('<div class="legend-row">')
        .attr('data-state-name', value);
    $('<div class="legend-box">')
        .attr('style', 'background-color: ' + color(index))
        .appendTo(row);
    $('<div class="legend-label">')
        .text(value)
        .appendTo(row);
    $('<div class="legend-value">')
        .appendTo(row);
    $('<div class="legend-percentage">')
        .appendTo(row);
    // Reverse order to match graph stacking.
    legendTable.prepend(row);
  });

  // Add a row for the totals
  var row = $('<div class="legend-total">');
  $('<div class="legend-box">').appendTo(row);
  $('<div class="legend-label">')
      .text('Total')
      .appendTo(row);
  $('<div class="legend-value">')
      .appendTo(row);
  $('<div class="legend-percentage">')
      .appendTo(row);
  legendTable.append(row);

  container.append(legendTable);


  // Forces the multi-column view to look good for a small number of states.
  $('.section').removeClass('section-small');
  if (columnNames.length < 10) {
    $('.section').addClass('section-small');
  }
}
{'fraction_non_alphanumeric': 0.17559244179977032, 'fraction_numerical': 0.006263701847792045, 'mean_word_length': 3.4745446053246147, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4953498', 'n_tokens_mistral': 3084, 'n_tokens_neox': 2934, 'n_words': 731}