<commit_before>/**
 *
 * This module provides routines for dealing with colors.
 *
 * @module dex/color
 *
 * @property {string[]} palette.c64Dark           - The commodore 64 dark palette.
 * @property {string[]} palette.c64Light          - The commodore 64 light palette.
 * @property {string[]} palette.divergingDark12   - Diverging dark colors.
 * @property {string[]} palette.divergingPastel12 - Diverging pastelles.
 * @property {string[]} palette.hueSoft128        - 128 colors with soft separation.
 * @property {string[]} palette.hueHard128        - 128 colors with hard separation.
 * @property {string[]} palette.crayola8          - The original 8 crayola colors.
 * @property {string[]} palette.crayola120        - 120 crayola colors.
 * @property {string[]} palette.YlGn              - Colorbrewer YlGn palettes 3-9.
 * @property {string[]} palette.YlGnBu            - Colorbrewer YlGnBu palettes 3-9.
 * @property {string[]} palette.GnBu              - Colorbrewer GnBu palettes 3-9.
 * @property {string[]} palette.BuGn              - Colorbrewer BuGn palettes 3-9.
 * @property {string[]} palette.PuBuGn            - Colorbrewer PuBuGn palettes 3-9.
 * @property {string[]} palette.PuBu              - Colorbrewer PuBu palettes 3-9.
 * @property {string[]} palette.BuPu              - Colorbrewer BuPu palettes 3-9.
 * @property {string[]} palette.RdPu              - Colorbrewer RdPu palettes 3-9.
 * @property {string[]} palette.PuRd              - Colorbrewer PuRd palettes 3-9.
 * @property {string[]} palette.OrRd              - Colorbrewer OrRd palettes 3-9.
 * @property {string[]} palette.YlOrRd            - Colorbrewer YlOrRd palettes 3-9.
 * @property {string[]} palette.YlOrBr            - Colorbrewer YlOrBr palettes 3-9.
 * @property {string[]} palette.Purples           - Colorbrewer Purples palettes 3-9.
 * @property {string[]} palette.Blues             - Colorbrewer Blues palettes 3-9.
 * @property {string[]} palette.Greens            - Colorbrewer Greens palettes 3-9.
 * @property {string[]} palette.Oranges           - Colorbrewer Oranges palettes 3-9.
 * @property {string[]} palette.Reds              - Colorbrewer Reds palettes 3-9.
 * @property {string[]} palette.Greys             - Colorbrewer Greys palettes 3-9.
 * @property {string[]} palette.PuOr              - Colorbrewer PuOr palettes 3-11.
 * @property {string[]} palette.BrBG              - Colorbrewer BrBG palettes 3-11.
 * @property {string[]} palette.PRGn              - Colorbrewer PRGn palettes 3-11.
 * @property {string[]} palette.PiYG              - Colorbrewer PiYG palettes 3-11.
 * @property {string[]} palette.RdBu              - Colorbrewer RdBu palettes 3-11.
 * @property {string[]} palette.RdGy              - Colorbrewer RdGy palettes 3-11.
 * @property {string[]} palette.RdYlBu            - Colorbrewer RdYlBu palettes 3-11.
 * @property {string[]} palette.Spectral          - Colorbrewer Spectral palettes 3-11.
 * @property {string[]} palette.RdYlGn            - Colorbrewer RdYlGn palettes 3-11.
 * @property {string[]} palette.Accent            - Colorbrewer Accent palettes 3-8.
 * @property {string[]} palette.Dark2             - Colorbrewer Dark2 palettes 3-8.
 * @property {string[]} palette.Paired            - Colorbrewer Paired palettes 3-12.
 * @property {string[]} palette.Pastel1           - Colorbrewer Pastel1 palettes 3-9.
 * @property {string[]} palette.Pastel2           - Colorbrewer Pastel2 palettes 3-8.
 * @property {string[]} palette.Set1              - Colorbrewer Set1 palettes 3-9.
 * @property {string[]} palette.Set2              - Colorbrewer Set2 palettes 3-8.
 * @property {string[]} palette.Set3              - Colorbrewer Set3 palettes 3-12.
 *
 */

module.exports = function color(dex) {

  return {
    /**
     *
     * Given a color, lighten or darken it by the requested percent.
     *
     * @param {string} color The color to modify.
     * @param {number} percent A floating point number in the range of [-1.0, 1.0].  Negative
     * values will lighten the color, positive values will darken it.
     *
     * @returns {string} The lightened or darkened color in the form of #ffffff.
     *
     */
    'shadeColor': function (color, percent) {
      var f = parseInt(color.slice(1), 16), t = percent < 0 ? 0 : 255,
        p = percent < 0 ? percent * -1 : percent,
        R = f >> 16, G = f >> 8 & 0x00FF, B = f & 0x0000FF;
      return "#" + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) *
        0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1);
    },

    /**
     *
     * Given two colors, blend them together.
     *
     * @param color1
     * @param color2
     * @param percent
     * @returns {string}
     *
     */
    'blendColors': function (color1, color2, percent) {
      var f = parseInt(color1.slice(1), 16), t = parseInt(color2.slice(1), 16),
        R1 = f >> 16, G1 = f >> 8 & 0x00FF,
        B1 = f & 0x0000FF, R2 = t >> 16,
        G2 = t >> 8 & 0x00FF, B2 = t & 0x0000FF;

      return "#" + (0x1000000 + (Math.round((R2 - R1) * percent) + R1) * 0x10000 +
        (Math.round((G2 - G1) * percent) + G1) * 0x100 +
        (Math.round((B2 - B1) * percent) + B1)).toString(16).slice(1);
    },
    /**
     *
     * Given an palette or array of colors and some optional color
     * assignmeents, create a colormap.
     *
     * @param {string[]} palette An array of colors within this colormap.
     * @param {object} presets An optional mapping of domain values and
     * preset color assignments.
     *
     * @returns {Function} Returns the colormap function.
     *
     * @example
     * // Assigns a colormap of red, white and blue
     * var usColormap = dex.color.colormap(['red', 'white', 'blue']);
     * @example
     * // Assigns a colormap of grey, brown and yellow and reserves red for
     * // Republicans and blue for Democrats.
     * var usPartyColors = dex.color.colormap(['grey', 'brown', 'yellow'],
     *   { 'Republican' : 'red', 'Democrat' : 'blue' });
     *
     */
    'colormap': function (palette, presets) {
      var numColors = palette.length;
      var data2Color = presets || {};
      var currentColor = 0;

      return function (d) {
        if (data2Color[d]) {
          //dex.console.log("Existing Color: " + d + " = " + data2Color[d]);
          return data2Color[d];
        }
        else {
          data2Color[d] = palette[currentColor % numColors];
          //dex.console.log("New Color[" + currentColor + "]: " + d + " = " + data2Color[d]);
          currentColor++;
          return data2Color[d];
        }
      };
    },
    /**
     *
     * Return the list of available named colormaps.
     *
     * @return {string[]} The list of available colormaps.
     *
     */
    'colormaps': function () {
      return Object.keys(dex.color.palette);
    },
    /**
     *<commit_msg>Added shortlist option to give shorter list of colormaps.<commit_after>/**
 *
 * This module provides routines for dealing with colors.
 *
 * @module dex/color
 *
 * @property {string[]} palette.c64Dark           - The commodore 64 dark palette.
 * @property {string[]} palette.c64Light          - The commodore 64 light palette.
 * @property {string[]} palette.divergingDark12   - Diverging dark colors.
 * @property {string[]} palette.divergingPastel12 - Diverging pastelles.
 * @property {string[]} palette.hueSoft128        - 128 colors with soft separation.
 * @property {string[]} palette.hueHard128        - 128 colors with hard separation.
 * @property {string[]} palette.crayola8          - The original 8 crayola colors.
 * @property {string[]} palette.crayola120        - 120 crayola colors.
 * @property {string[]} palette.YlGn              - Colorbrewer YlGn palettes 3-9.
 * @property {string[]} palette.YlGnBu            - Colorbrewer YlGnBu palettes 3-9.
 * @property {string[]} palette.GnBu              - Colorbrewer GnBu palettes 3-9.
 * @property {string[]} palette.BuGn              - Colorbrewer BuGn palettes 3-9.
 * @property {string[]} palette.PuBuGn            - Colorbrewer PuBuGn palettes 3-9.
 * @property {string[]} palette.PuBu              - Colorbrewer PuBu palettes 3-9.
 * @property {string[]} palette.BuPu              - Colorbrewer BuPu palettes 3-9.
 * @property {string[]} palette.RdPu              - Colorbrewer RdPu palettes 3-9.
 * @property {string[]} palette.PuRd              - Colorbrewer PuRd palettes 3-9.
 * @property {string[]} palette.OrRd              - Colorbrewer OrRd palettes 3-9.
 * @property {string[]} palette.YlOrRd            - Colorbrewer YlOrRd palettes 3-9.
 * @property {string[]} palette.YlOrBr            - Colorbrewer YlOrBr palettes 3-9.
 * @property {string[]} palette.Purples           - Colorbrewer Purples palettes 3-9.
 * @property {string[]} palette.Blues             - Colorbrewer Blues palettes 3-9.
 * @property {string[]} palette.Greens            - Colorbrewer Greens palettes 3-9.
 * @property {string[]} palette.Oranges           - Colorbrewer Oranges palettes 3-9.
 * @property {string[]} palette.Reds              - Colorbrewer Reds palettes 3-9.
 * @property {string[]} palette.Greys             - Colorbrewer Greys palettes 3-9.
 * @property {string[]} palette.PuOr              - Colorbrewer PuOr palettes 3-11.
 * @property {string[]} palette.BrBG              - Colorbrewer BrBG palettes 3-11.
 * @property {string[]} palette.PRGn              - Colorbrewer PRGn palettes 3-11.
 * @property {string[]} palette.PiYG              - Colorbrewer PiYG palettes 3-11.
 * @property {string[]} palette.RdBu              - Colorbrewer RdBu palettes 3-11.
 * @property {string[]} palette.RdGy              - Colorbrewer RdGy palettes 3-11.
 * @property {string[]} palette.RdYlBu            - Colorbrewer RdYlBu palettes 3-11.
 * @property {string[]} palette.Spectral          - Colorbrewer Spectral palettes 3-11.
 * @property {string[]} palette.RdYlGn            - Colorbrewer RdYlGn palettes 3-11.
 * @property {string[]} palette.Accent            - Colorbrewer Accent palettes 3-8.
 * @property {string[]} palette.Dark2             - Colorbrewer Dark2 palettes 3-8.
 * @property {string[]} palette.Paired            - Colorbrewer Paired palettes 3-12.
 * @property {string[]} palette.Pastel1           - Colorbrewer Pastel1 palettes 3-9.
 * @property {string[]} palette.Pastel2           - Colorbrewer Pastel2 palettes 3-8.
 * @property {string[]} palette.Set1              - Colorbrewer Set1 palettes 3-9.
 * @property {string[]} palette.Set2              - Colorbrewer Set2 palettes 3-8.
 * @property {string[]} palette.Set3              - Colorbrewer Set3 palettes 3-12.
 *
 */

module.exports = function color(dex) {

  return {
    /**
     *
     * Given a color, lighten or darken it by the requested percent.
     *
     * @param {string} color The color to modify.
     * @param {number} percent A floating point number in the range of [-1.0, 1.0].  Negative
     * values will lighten the color, positive values will darken it.
     *
     * @returns {string} The lightened or darkened color in the form of #ffffff.
     *
     */
    'shadeColor': function (color, percent) {
      var f = parseInt(color.slice(1), 16), t = percent < 0 ? 0 : 255,
        p = percent < 0 ? percent * -1 : percent,
        R = f >> 16, G = f >> 8 & 0x00FF, B = f & 0x0000FF;
      return "#" + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) *
        0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1);
    },

    /**
     *
     * Given two colors, blend them together.
     *
     * @param color1
     * @param color2
     * @param percent
     * @returns {string}
     *
     */
    'blendColors': function (color1, color2, percent) {
      var f = parseInt(color1.slice(1), 16), t = parseInt(color2.slice(1), 16),
        R1 = f >> 16, G1 = f >> 8 & 0x00FF,
        B1 = f & 0x0000FF, R2 = t >> 16,
        G2 = t >> 8 & 0x00FF, B2 = t & 0x0000FF;

      return "#" + (0x1000000 + (Math.round((R2 - R1) * percent) + R1) * 0x10000 +
        (Math.round((G2 - G1) * percent) + G1) * 0x100 +
        (Math.round((B2 - B1) * percent) + B1)).toString(16).slice(1);
    },
    /**
     *
     * Given an palette or array of colors and some optional color
     * assignmeents, create a colormap.
     *
     * @param {string[]} palette An array of colors within this colormap.
     * @param {object} presets An optional mapping of domain values and
     * preset color assignments.
     *
     * @returns {Function} Returns the colormap function.
     *
     * @example
     * // Assigns a colormap of red, white and blue
     * var usColormap = dex.color.colormap(['red', 'white', 'blue']);
     * @example
     * // Assigns a colormap of grey, brown and yellow and reserves red for
     * // Republicans and blue for Democrats.
     * var usPartyColors = dex.color.colormap(['grey', 'brown', 'yellow'],
     *   { 'Republican' : 'red', 'Democrat' : 'blue' });
     *
     */
    'colormap': function (palette, presets) {
      var numColors = palette.length;
      var data2Color = presets || {};
      var currentColor = 0;

      return function (d) {
        if (data2Color[d]) {
          //dex.console.log("Existing Color: " + d + " = " + data2Color[d]);
          return data2Color[d];
        }
        else {
          data2Color[d] = palette[currentColor % numColors];
          //dex.console.log("New Color[" + currentColor + "]: " + d + " = " + data2Color[d]);
          currentColor++;
          return data2Color[d];
        }
      };
    },
    /**
     *
     * Return the list of available named colormaps.
     *
     * @return {string[]} The list of available colormaps.
     *
     */
    'colormaps': function (options) {
      var opts = options || {};
      if (opts.shortlist) {
        return [
          "category10", "category20b", "category20c", "category20", "c64Dark",
          "c64Light", "divergingDark12", "divergingPastel12", "hueSoft128",
          "hueHard128", "crayola8", "crayola120", "YlGn_9",
          "YlGnBu_9", "GnBu_9", "BuGn_9", "PuBuGn_9", "PuBu_9",
          "BuPu_9", "RdPu_9", "PuRd_9", "OrRd_9", "YlOrRd_9", "YlOrBr_9",
          "Purples_9", "Blues_9", "Greens_9", "Oranges_9", "Reds_9",
          "Greys_9", "PuOr_11", "BrBG_11", "PRGn_11", "PiYG_11",
          "RdBu_11", "RdGy_11", "RdYlBu_11",
          "Spectral_4", "Spectral_8", "Spectral_11",
          "RdYlGn_11", "Accent_8", "Dark2_8", "Paired_12",
          "Pastel1_9", "Pastel2_8", "Set1_9", "Set2_8", "Set3_12"
        ];
      }
      return Object.keys(dex.color.palette);
    },

    /**
     *
{'fraction_non_alphanumeric': 0.1359097127222982, 'fraction_numerical': 0.03953488372093023, 'mean_word_length': 2.2520017793594307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4505332', 'n_tokens_mistral': 5251, 'n_tokens_neox': 4770, 'n_words': 1298}