<commit_before>/*
 * The Gemma project
 * 
 * Copyright (c) 2008 University of British Columbia
 * 
 * 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.
 * 
 */

/**
 * @version $Id$
 * @author Kelsey
 */
var Heatmap = function() {

	// row labels
	var MAX_LABEL_LENGTH_PIXELS = 400;
	var MAX_LABEL_LENGTH_CHAR = 175;
	var EXPANDED_BOX_WIDTH = 10;
	var CLIP = 3; // contrast. TODO: make it adjustable in range 2-4?
	var NAN_COLOR = "grey";
	var SHOW_LABEL_MIN_SIZE = 9; // 6 is unreadable; 8 is almost okay.
	var MIN_BOX_HEIGHT_FOR_LABELS = 12;
	var MAX_BOX_HEIGHT = 16;
	var MIN_BOX_HEIGHT = 2;
	var MAX_ROWS_BEFORE_SCROLL = 30;
	var MIN_IMAGE_SIZE = 50;

	// column labels
	var MAX_SAMPLE_LABEL_HEIGHT_PIXELS = 220;
	var SAMPLE_LABEL_MAX_CHAR = 125;

	// extra space
	var TRIM = 5;

	var DEFAULT_ROW_LABEL = "&nbsp;";

	var DEFAULT_CONFIG = {
		label : false,
		maxBoxHeight : MAX_BOX_HEIGHT,
		allowTargetSizeAdjust : false
	};

	// black-red-orange-yellow-white
	var COLOR_16 = ["rgb(0, 0, 0)", "rgb(32, 0, 0)", "rgb(64, 0, 0)", "rgb(96, 0, 0)", "rgb(128, 0, 0)",
			"rgb(159, 32, 0)", "rgb(191, 64, 0)", "rgb(223, 96, 0)", "rgb(255, 128, 0)", "rgb(255, 159, 32)",
			"rgb(255, 191, 64)", "rgb(255, 223, 96)", "rgb(255, 255, 128)", "rgb(255, 255, 159)", "rgb(255, 255, 191)",
			"rgb(255, 255, 223)", "rgb(255, 255, 255)"];

	/**
	 * @param container
	 * @param data -
	 *            in form of VisualizationValueObject array with 'data' series.
	 * @param config
	 *            optional
	 * @param sampleLabels
	 *            optional.
	 */
	function HeatMap(container, data, config, sampleLabels) {

		if (!config) {
			config = DEFAULT_CONFIG;
		} else {
			config.label = config.label || false;
			config.maxBoxHeight = config.maxBoxHeight || MAX_BOX_HEIGHT;
			config.allowTargetSizeAdjust = config.allowTargetSizeAdjust || false;
		}

		drawMap(data, container, COLOR_16, config, sampleLabels);

		// Creates 1 canvas per row of the heat map
		function drawMap(vectorObjs, target, colors, config, sampleLabels) {

			if (target.getWidth() <= 0 || target.getHeight() <= 0) {
				return;
			}

			var binSize = (2 * CLIP) / colors.length;

			// Get dimensions of target to determine box size in heat map
			var panelWidth = target.getWidth() - TRIM;
			var panelHeight = target.getHeight() - TRIM;
			var numRows = vectorObjs.length;

			var rowLabelSizePixels = 0;

			if (config.label) {

				// Try to figure out the room needed for the row labels. note: this is confusing because the label
				// contains html. The actual displayed text is less, so we
				// check rawLabel.
				var maxRowLabelLength = 0;
				for (var i = 0; i < vectorObjs.length; i++) {
					if (vectorObjs[i].rawLabel) {
						labelLength = Math.min(vectorObjs[i].rawLabel.length, MAX_LABEL_LENGTH_CHAR);
						if (labelLength > maxRowLabelLength) {
							maxRowLabelLength = labelLength;
						}
					}
				}

				// multiplier is a guesstimate. Can get from ctx.measureText but we don't have that yet...
				rowLabelSizePixels = Math.min(MAX_LABEL_LENGTH_PIXELS, maxRowLabelLength * 8);
			}
<commit_msg>null check<commit_after>/*
 * The Gemma project
 * 
 * Copyright (c) 2008 University of British Columbia
 * 
 * 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.
 * 
 */

/**
 * @version $Id$
 * @author Kelsey
 */
var Heatmap = function() {

	// row labels
	var MAX_LABEL_LENGTH_PIXELS = 400;
	var MAX_LABEL_LENGTH_CHAR = 175;
	var EXPANDED_BOX_WIDTH = 10;
	var CLIP = 3; // contrast. TODO: make it adjustable in range 2-4?
	var NAN_COLOR = "grey";
	var SHOW_LABEL_MIN_SIZE = 9; // 6 is unreadable; 8 is almost okay.
	var MIN_BOX_HEIGHT_FOR_LABELS = 12;
	var MAX_BOX_HEIGHT = 16;
	var MIN_BOX_HEIGHT = 2;
	var MAX_ROWS_BEFORE_SCROLL = 30;
	var MIN_IMAGE_SIZE = 50;

	// column labels
	var MAX_SAMPLE_LABEL_HEIGHT_PIXELS = 220;
	var SAMPLE_LABEL_MAX_CHAR = 125;

	// extra space
	var TRIM = 5;

	var DEFAULT_ROW_LABEL = "&nbsp;";

	var DEFAULT_CONFIG = {
		label : false,
		maxBoxHeight : MAX_BOX_HEIGHT,
		allowTargetSizeAdjust : false
	};

	// black-red-orange-yellow-white
	var COLOR_16 = ["rgb(0, 0, 0)", "rgb(32, 0, 0)", "rgb(64, 0, 0)", "rgb(96, 0, 0)", "rgb(128, 0, 0)",
			"rgb(159, 32, 0)", "rgb(191, 64, 0)", "rgb(223, 96, 0)", "rgb(255, 128, 0)", "rgb(255, 159, 32)",
			"rgb(255, 191, 64)", "rgb(255, 223, 96)", "rgb(255, 255, 128)", "rgb(255, 255, 159)", "rgb(255, 255, 191)",
			"rgb(255, 255, 223)", "rgb(255, 255, 255)"];

	/**
	 * @param container
	 * @param data -
	 *            in form of VisualizationValueObject array with 'data' series.
	 * @param config
	 *            optional
	 * @param sampleLabels
	 *            optional.
	 */
	function HeatMap(container, data, config, sampleLabels) {

		if (!config) {
			config = DEFAULT_CONFIG;
		} else {
			config.label = config.label || false;
			config.maxBoxHeight = config.maxBoxHeight || MAX_BOX_HEIGHT;
			config.allowTargetSizeAdjust = config.allowTargetSizeAdjust || false;
		}

		drawMap(data, container, COLOR_16, config, sampleLabels);

		// Creates 1 canvas per row of the heat map
		function drawMap(vectorObjs, target, colors, config, sampleLabels) {

			if (target.getWidth() <= 0 || target.getHeight() <= 0 || vectorObjs.length == 0) {
				return;
			}

			var binSize = (2 * CLIP) / colors.length;

			// Get dimensions of target to determine box size in heat map
			var panelWidth = target.getWidth() - TRIM;
			var panelHeight = target.getHeight() - TRIM;
			var numRows = vectorObjs.length;

			var rowLabelSizePixels = 0;

			if (config.label) {

				// Try to figure out the room needed for the row labels. note: this is confusing because the label
				// contains html. The actual displayed text is less, so we
				// check rawLabel.
				var maxRowLabelLength = 0;
				for (var i = 0; i < vectorObjs.length; i++) {
					if (vectorObjs[i].rawLabel) {
						labelLength = Math.min(vectorObjs[i].rawLabel.length, MAX_LABEL_LENGTH_CHAR);
						if (labelLength > maxRowLabelLength) {
							maxRowLabelLength = labelLength;
						}
					}
				}

				// multiplier is a guesstimate. Can get from ctx.measureText but we don't have that yet...
				rowLabelSizePixels = Math.min(MAX_LABEL_LENGTH_PIXELS, maxRowLabelLength * 8);
			}

{'fraction_non_alphanumeric': 0.12063447892027271, 'fraction_numerical': 0.04577709753721998, 'mean_word_length': 3.317117117117117, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '6613743', 'n_tokens_mistral': 2897, 'n_tokens_neox': 2357, 'n_words': 777}