<commit_before>/*
* BrainBrowser: Web-based Neurological Visualization Tools
* (https://brainbrowser.cbrain.mcgill.ca)
*
* Copyright (C) 2011
* The Royal Institution for the Advancement of Learning
* McGill University
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
* @author: <NAME>
* @author: <NAME>  <<EMAIL>> (http://tareksherif.ca/)
*/

/**
 * @doc function
 * @name BrainBrowser.static methods:createColorMap
 * @param {string}  data The color map data as a string.
 * 
 * @description
 * Factory function to produce color map object from a string of data. A given
 * color map is a set of colors to which intensity data can be mapped for display.
 */

(function() {
  "use strict";

  var BrainBrowser = window.BrainBrowser = window.BrainBrowser || {};

  BrainBrowser.createColorMap = function(data) {

    /**
    * @doc object
    * @name color_map
    * 
    * @description
    * Object representing the currently loaded color map.
    */
    var color_map = {

      /**
      * @doc function
      * @name color_map.color_map:createCanvas
      * @param {array} colors Array of color data.
      * 
      * @description
      * Create a canvas color_map from the given colors.
      */
      createCanvas: function(colors)  {
        var canvas;
        
        if (!colors) {
          colors = color_map.colors;
        }
        
        canvas = createCanvas(colors, 20, 20, false);

        return canvas;
      },

      /**
      * @doc function
      * @name color_map.color_map:createCanvasWithScale
      * @param {number} min Min value of the color data.
      * @param {number} max Max value of the color data.
      * @param {boolean} flip Array of color data.
      * 
      * @description
      * Create a canvas color_map from the given colors and provide the scale for it.
      */
      createCanvasWithScale: function(min, max, flip) {
        var canvas;
        var context;
        var colors = color_map.colors;
        
        canvas = createCanvas(colors, 20, 40, flip);
        context = canvas.getContext("2d");

        context.fillStyle = "#FFA000";

        //min mark
        context.fillRect(0.5, 20, 1, 10);
        context.fillText(min.toPrecision(3), 0.5, 40 );

        //quater mark
        context.fillRect(canvas.width/4.0, 20, 1, 10);
        context.fillText(((min+max)/4.0).toPrecision(3), canvas.width/4.0, 40);

        //middle mark
        context.fillRect(canvas.width/2.0, 20, 1, 10);
        context.fillText(((min+max)/2.0).toPrecision(3), canvas.width/2.0, 40);

        //3quater mark
        context.fillRect(3*(canvas.width/4.0), 20, 1, 10);
        context.fillText((3*((min+max)/4.0)).toPrecision(3), 3*(canvas.width/4.0), 40);


        //max mark
        context.fillRect(canvas.width-0.5, 20, 1, 10);
        context.fillText(max.toPrecision(3), canvas.width - 20, 40);

        return canvas;
      },

      /**
      * @doc function
      * @name color_map.color_map:mapColors
      * @param {array} values Original color values.
      * @param {object} options Options for the color mapping.<commit_msg>Fixed bug in color map canvas scale.<commit_after>/*
* BrainBrowser: Web-based Neurological Visualization Tools
* (https://brainbrowser.cbrain.mcgill.ca)
*
* Copyright (C) 2011
* The Royal Institution for the Advancement of Learning
* McGill University
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
* @author: <NAME>
* @author: <NAME>  <<EMAIL>> (http://tareksherif.ca/)
*/

/**
 * @doc function
 * @name BrainBrowser.static methods:createColorMap
 * @param {string}  data The color map data as a string.
 * 
 * @description
 * Factory function to produce color map object from a string of data. A given
 * color map is a set of colors to which intensity data can be mapped for display.
 */

(function() {
  "use strict";

  var BrainBrowser = window.BrainBrowser = window.BrainBrowser || {};

  BrainBrowser.createColorMap = function(data) {

    /**
    * @doc object
    * @name color_map
    * 
    * @description
    * Object representing the currently loaded color map.
    */
    var color_map = {

      /**
      * @doc function
      * @name color_map.color_map:createCanvas
      * @param {array} colors Array of color data.
      * 
      * @description
      * Create a canvas color_map from the given colors.
      */
      createCanvas: function(colors)  {
        var canvas;
        
        if (!colors) {
          colors = color_map.colors;
        }
        
        canvas = createCanvas(colors, 20, 20, false);

        return canvas;
      },

      /**
      * @doc function
      * @name color_map.color_map:createCanvasWithScale
      * @param {number} min Min value of the color data.
      * @param {number} max Max value of the color data.
      * @param {boolean} flip Array of color data.
      * 
      * @description
      * Create a canvas color_map from the given colors and provide the scale for it.
      */
      createCanvasWithScale: function(min, max, flip) {
        var canvas;
        var context;
        var colors = color_map.colors;
        var range = max - min;
        
        canvas = createCanvas(colors, 20, 40, flip);
        context = canvas.getContext("2d");

        context.fillStyle = "#FFA000";

        // Min mark
        context.fillRect(0.5, 20, 1, 10);
        context.fillText(min.toPrecision(3), 0.5, 40);

        // Quarter mark
        context.fillRect(canvas.width / 4, 20, 1, 10);
        context.fillText((min + 0.25 * range).toPrecision(3), 0.25 * canvas.width, 40);

        // Middle mark
        context.fillRect(canvas.width / 2, 20, 1, 10);
        context.fillText((min + 0.5 * range).toPrecision(3), 0.5 * canvas.width, 40);

        // Three-quarter mark
        context.fillRect(3 * canvas.width / 4, 20, 1, 10);
        context.fillText((min + 0.75 * range).toPrecision(3), 0.75 * canvas.width, 40);


        // Max mark
        context.fillRect(canvas.width - 0.5, 20, 1, 10);
        context.fillText(max.toPrecision(3), canvas.width - 20, 40);

        return canvas;
      },

      /**
      * @doc function
      * @name color_map.color_map:mapColors
      * @param {array} values Original color values.
      * @param {object} options Options for the color mapping.
{'fraction_non_alphanumeric': 0.11050167224080268, 'fraction_numerical': 0.023010033444816055, 'mean_word_length': 2.4853146853146852, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '7129523', 'n_tokens_mistral': 2341, 'n_tokens_neox': 2153, 'n_words': 747}