<commit_before>// vim: set ts=2 sw=2 et colorcolumn=80 :

/**
 * Package "geochart_geojson"
 *
 * Provides GeoChart with GeoJSON support.
 *
 * Contains the GeoChart class with its subcomponent classes.
 */
var geochart_geojson = {};

(function(context) {


"use strict";


// Constants

// zIndex constants
// The selected (click) and highlighted (hover) features must have a zIndex
// higher than the other features. The tooltip must have a zIndex higher than
// the features and the selected and highlighted features.
var SELECTED_Z_INDEX = 999;
var HIGHLIGHTED_Z_INDEX = 1000;
var TOOLTIP_Z_INDEX = 2000;
// Tooltip constants
var TOOLTIP_STYLE = {
    borderStyle: "solid",
    borderWidth: "1px",
    borderColor: "#cccccc",
    backgroundColor: "#ffffff",
    padding: "4px"
};
var TOOLTIP_MARGIN = 2;
var TOOLTIP_OFFSET = 12;
// Legend constants
var LEGEND_WIDTH = 250;
var LEGEND_HEIGHT = 13;
var LEGEND_NUM_PADDING_VERT = 2;
var LEGEND_NUM_PADDING_HORIZ = 4;
var LEGEND_INDICATOR_SIZE = 12;
var LEGEND_INDICATOR_TOP_OFFSET = -8;
var LEGEND_INDICATOR_LEFT_OFFSET = -6;


// Auxiliary functions

// Process a Google Chart `textStyle` option
//
// Converts a Google Chart `textStyle` option into a valid CSS style object.
function processTextStyle_(textStyle) {
  var style = {};

  style.color = textStyle.color;
  style.fontFamily = textStyle.fontName;
  style.fontSize = textStyle.fontSize + "px";
  if (textStyle.bold) {
    style.fontWeight = "bold";
  }
  if (textStyle.italic) {
    style.fontStyle = "italic";
  }

  return style;
}

// Deep merge two objects
//
// The objects passed as params are kept intact.
function deepMerge_(obj1, obj2) {
  var obj = {};

  obj = JSON.parse(JSON.stringify(obj1));

  Object.entries(obj2).forEach(function(p) {
    if (p[0] in obj && typeof obj[p[0]] === "object" &&
        obj[p[0]] !== null && typeof p[1] === "object") {
      obj[p[0]] = deepMerge_(obj[p[0]], p[1]);
    } else {
      obj[p[0]] = p[1];
    }
  });

  return obj;
}


/**
 * GeoChart with GeoJSON support
 *
 * These charts are very similar to the Google Charts geochart, but with
 * GeoJSON support.
 *
 * Code based on Google Charts and Google Maps API guides and references.
 *
 * See:
 *
 * - https://developers.google.com/chart/interactive/docs/dev/
 * - https://developers.google.com/chart/interactive/docs/gallery/geochart
 * - https://developers.google.com/chart/interactive/docs/datatables_dataviews
 * - https://developers.google.com/chart/interactive/docs/reference
 * - https://developers.google.com/maps/documentation/javascript/
 *
 * Params:
 *
 * - container: The HTML container for the chart.
 */
var GeoChart = function(container) {
  this.container = container;

  // The inner datatable
  this.data_ = null;
  // The inner chart options
  this.options_ = null;
  // The inner Google Maps map object
  // This object will hold the GeoJSON map (in its overlay layer), the tooltip
  // overlay and the legend.
  // Optionally, it will also handle the underlying map layer (map, satellite
  // or simple map) and the map control (zoom, map drag). These features are
  // disabled by default.
  this.map_ = null;
  // Inner objects (`ColorAxis`, `Tooltip` and `Legend`)
  this.color_axis_ = null;
  this.tooltip_ = null;
  this.legend_ = null;
  // Min and max values of the DataTable rows
  this.min_ = 0;
  this.max_ = 0;
  // Feature selected by the user
  this.feature_selected_ = null;
};

// Default GeoChart options
// TODO Document each option.
GeoChart.prototype.DEFAULT_OPTIONS = {
  colorAxis: {
    colors: ["#efe6dc", "#109618"],
    strokeColors: ["#cccccc", "#888888"],
  },
  datalessRegionColor: "#f5f5f5",
  datalessRegionStrokeColor: "#cccccc",
  defaultColor: "#267114", // TODO Implement
  defaultStrokeColor: "#666666", // TODO Implement
  displayMode: "regions", // TODO Implement
  featureStyle: {
    fillOpacity: 1,
    strokeWeight: 1,
    strokeOpacity: 0.5
  },
  featureStyleHighlighted: {
    strokeWeight: 2,
    strokeOpacity: 1
  },
  geoJson: null,
  geoJsonOptions: null,
  // Set `legend` to `"none"` to disable the legend.
  legend: {
    // A position string. Valid options are `ControlPosition` locations in the
    // Google Maps API.
    // See: https://developers.google.com/maps/documentation/javascript/ \
    //     controls?hl=pt-br#ControlPositioning
    position: "LEFT_BOTTOM",
    textStyle: {
      color: "#000000",
      fontName: "Arial",
      fontSize: 14,
      bold: false,
      italic: false
    }
  },
  mapsOptions: null,
  mapsBackground: "none", // TODO Implement
  mapsControl: false, // TODO Implement
  tooltip: {
    textStyle: {
      color: "#000000",
      fontName: "Arial",
      fontSize: 13,
      bold: false,
      italic: false
    },
    trigger: "focus" // TODO Implement
  }
};

GeoChart.prototype.getMapsOptions_ = function() {
  var maps_options = this.options_.mapsOptions;

  if (this.options_.mapsBackground === "none") {
    maps_options.styles = [{
      "stylers": [{"visibility": "off"}]
    }];
    maps_options.backgroundColor = "none";
  } else {
    throw new Error("Invalid `mapsBackground` option");
  }

  if (! this.options_.mapsControl) {
    maps_options.disableDefaultUI = true;
    maps_options.scrollwheel = false;
    maps_options.draggable = false;
    maps_options.disableDoubleClickZoom = true;
  } else {
    throw new Error("Invalid `mapsControl` option");
  }

  return maps_options;
};

/**
 * Draw the chart
 *<commit_msg>Implementing the `backgroundColor` option<commit_after>// vim: set ts=2 sw=2 et colorcolumn=80 :

/**
 * Package "geochart_geojson"
 *
 * Provides GeoChart with GeoJSON support.
 *
 * Contains the GeoChart class with its subcomponent classes.
 */
var geochart_geojson = {};

(function(context) {


"use strict";


// Constants

// zIndex constants
// The selected (click) and highlighted (hover) features must have a zIndex
// higher than the other features. The tooltip must have a zIndex higher than
// the features and the selected and highlighted features.
var SELECTED_Z_INDEX = 999;
var HIGHLIGHTED_Z_INDEX = 1000;
var TOOLTIP_Z_INDEX = 2000;
// Tooltip constants
var TOOLTIP_STYLE = {
    borderStyle: "solid",
    borderWidth: "1px",
    borderColor: "#cccccc",
    backgroundColor: "#ffffff",
    padding: "4px"
};
var TOOLTIP_MARGIN = 2;
var TOOLTIP_OFFSET = 12;
// Legend constants
var LEGEND_WIDTH = 250;
var LEGEND_HEIGHT = 13;
var LEGEND_NUM_PADDING_VERT = 2;
var LEGEND_NUM_PADDING_HORIZ = 4;
var LEGEND_INDICATOR_SIZE = 12;
var LEGEND_INDICATOR_TOP_OFFSET = -8;
var LEGEND_INDICATOR_LEFT_OFFSET = -6;


// Auxiliary functions

// Process a Google Chart `textStyle` option
//
// Converts a Google Chart `textStyle` option into a valid CSS style object.
function processTextStyle_(textStyle) {
  var style = {};

  style.color = textStyle.color;
  style.fontFamily = textStyle.fontName;
  style.fontSize = textStyle.fontSize + "px";
  if (textStyle.bold) {
    style.fontWeight = "bold";
  }
  if (textStyle.italic) {
    style.fontStyle = "italic";
  }

  return style;
}

// Deep merge two objects
//
// The objects passed as params are kept intact.
function deepMerge_(obj1, obj2) {
  var obj = {};

  obj = JSON.parse(JSON.stringify(obj1));

  Object.entries(obj2).forEach(function(p) {
    if (p[0] in obj && typeof obj[p[0]] === "object" &&
        obj[p[0]] !== null && typeof p[1] === "object") {
      obj[p[0]] = deepMerge_(obj[p[0]], p[1]);
    } else {
      obj[p[0]] = p[1];
    }
  });

  return obj;
}


/**
 * GeoChart with GeoJSON support
 *
 * These charts are very similar to the Google Charts geochart, but with
 * GeoJSON support.
 *
 * Code based on Google Charts and Google Maps API guides and references.
 *
 * See:
 *
 * - https://developers.google.com/chart/interactive/docs/dev/
 * - https://developers.google.com/chart/interactive/docs/gallery/geochart
 * - https://developers.google.com/chart/interactive/docs/datatables_dataviews
 * - https://developers.google.com/chart/interactive/docs/reference
 * - https://developers.google.com/maps/documentation/javascript/
 *
 * Params:
 *
 * - container: The HTML container for the chart.
 */
var GeoChart = function(container) {
  this.container = container;

  // The inner datatable
  this.data_ = null;
  // The inner chart options
  this.options_ = null;
  // The inner Google Maps map object
  // This object will hold the GeoJSON map (in its overlay layer), the tooltip
  // overlay and the legend.
  // Optionally, it will also handle the underlying map layer (map, satellite
  // or simple map) and the map control (zoom, map drag). These features are
  // disabled by default.
  this.map_ = null;
  // Inner objects (`ColorAxis`, `Tooltip` and `Legend`)
  this.color_axis_ = null;
  this.tooltip_ = null;
  this.legend_ = null;
  // Min and max values of the DataTable rows
  this.min_ = 0;
  this.max_ = 0;
  // Feature selected by the user
  this.feature_selected_ = null;
};

// Default GeoChart options
// TODO Document each option.
GeoChart.prototype.DEFAULT_OPTIONS = {
  backgroundColor: "#ffffff",
  colorAxis: {
    colors: ["#efe6dc", "#109618"],
    strokeColors: ["#cccccc", "#888888"],
  },
  datalessRegionColor: "#f5f5f5",
  datalessRegionStrokeColor: "#cccccc",
  defaultColor: "#267114", // TODO Implement
  defaultStrokeColor: "#666666", // TODO Implement
  displayMode: "regions", // TODO Implement
  featureStyle: {
    fillOpacity: 1,
    strokeWeight: 1,
    strokeOpacity: 0.5
  },
  featureStyleHighlighted: {
    strokeWeight: 2,
    strokeOpacity: 1
  },
  geoJson: null,
  geoJsonOptions: null,
  // Set `legend` to `"none"` to disable the legend.
  legend: {
    // A position string. Valid options are `ControlPosition` locations in the
    // Google Maps API.
    // See: https://developers.google.com/maps/documentation/javascript/ \
    //     controls?hl=pt-br#ControlPositioning
    position: "LEFT_BOTTOM",
    textStyle: {
      color: "#000000",
      fontName: "Arial",
      fontSize: 14,
      bold: false,
      italic: false
    }
  },
  mapsOptions: null,
  mapsBackground: "none", // TODO Implement
  mapsControl: false, // TODO Implement
  tooltip: {
    textStyle: {
      color: "#000000",
      fontName: "Arial",
      fontSize: 13,
      bold: false,
      italic: false
    },
    trigger: "focus" // TODO Implement
  }
};

GeoChart.prototype.getMapsOptions_ = function() {
  var maps_options = this.options_.mapsOptions;

  maps_options.backgroundColor = this.options_.backgroundColor;

  if (this.options_.mapsBackground === "none") {
    maps_options.styles = [{
      "stylers": [{"visibility": "off"}]
    }];
  } else {
    throw new Error("Invalid `mapsBackground` option");
  }

  if (! this.options_.mapsControl) {
    maps_options.disableDefaultUI = true;
    maps_options.scrollwheel = false;
    maps_options.draggable = false;
    maps_options.disableDoubleClickZoom = true;
  } else {
    throw new Error("Invalid `mapsControl` option");
  }

  return maps_options;
};

/**
 * Draw the chart
 *
{'fraction_non_alphanumeric': 0.127356780275562, 'fraction_numerical': 0.01740391588107324, 'mean_word_length': 3.287990672366887, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 12, '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': '7423656', 'n_tokens_mistral': 3780, 'n_tokens_neox': 3590, 'n_words': 985}