<commit_before>import {createHashMap} from "../hashmap.js";
import {getValueSources} from "../runtime/value.js";
import {getScale} from "../scales/index.js";
import {CONTINUOUS_SCALE, DISCRETE_SCALE} from "../scales/index.js";
import {isArray, unique, range as rangeOf, each} from "../util.js";

//Parse scale range
let parseScaleRange = function (context, scale, value) {
    //Check for string value
    if (typeof value === "string") {
        //Check for width range value
        if (value === "width") {
            return [0, context.draw.computed.width];
        }
        //Check for height range value
        else if (value === "height") {
            return [context.draw.computed.height, 0];
        }
    }
    //Check for array range object
    else if (isArray(value) === true) {
        //Parse each item of the range
        return value.map(function (v) {
            return context.value(v, v);
        });
    }
    //Other range value, return the provided value
    return value;
};

//Parse scale domain
let parseScaleDomain = function (context, scale, value) {
    //Check if provided domain is an array
    if (isArray(value) === true) {
        return value.map(function (v) {
            return context.value(v, v);
        });
    }
    //Check if the provided value is an object
    if (value !== null && typeof value === "object") {
        //Check for state data
        if (typeof value.state === "string") {
            return context.state[value.state];
        }
        //Get domain from data
        let data = context.source(value)[0];
        //Generate a function to extract the domain value of a datum
        let valueOf = function (datum) {
            return (typeof value.field === "string") ? datum[value.field] : datum;
        };
        //Check for continuous scale
        if (scale.category === CONTINUOUS_SCALE) {
            return rangeOf(data, valueOf);
        }<commit_msg>Fixed scale range and domain parsers. Minor fixes<commit_after>import {createHashMap} from "../hashmap.js";
import {getValueSources} from "../runtime/value.js";
import {getScale} from "../scales/index.js";
import {CONTINUOUS_SCALE, DISCRETE_SCALE} from "../scales/index.js";
import {isArray, isObject, unique, range as rangeOf, each} from "../util.js";

//Parse scale range
let parseScaleRange = function (context, scale, value) {
    //Check for array range object --> parse each item
    if (isArray(value) === true) {
        return value.map(function (v) {
            return context.value(v, null);
        });
    }
    //Check for object value
    else if (isObject(value) === true) {
        //Check for width range value
        if (typeof value["draw"] === "string" && value["draw"] === "width") {
            return [0, context.draw.computed.width];
        }
        //Check for height range value
        else if (typeof value["draw"] === "string" && value["draw"] === "height") {
            return [context.draw.computed.height, 0];
        }
        //Other type --> parse from value or state
        else {
            return context.value(value, null);
        }
    }
    //Other range value --> throw error
    throw new Error("Invalid range provided");
};

//Parse scale domain
let parseScaleDomain = function (context, scale, value) {
    //Check if provided domain is an array
    if (isArray(value) === true) {
        return value.map(function (v) {
            return context.value(v, null);
        });
    }
    //Check if the provided value is an object
    if (isObject(value) === true) {
        //Check for state data
        if (typeof value["state"] === "string") {
            return context.state[value["state"]];
        }
        //Check for manual domain
        else if (typeof value["value"] !== "undefined") {
            return value["value"]; //Return value data
        }
        //Get domain from data
        let data = context.source(value)[0];
        //Generate a function to extract the domain value of a datum
        let valueOf = function (datum) {
            return (typeof value["field"] === "string") ? datum[value["field"]] : datum;
        };
        //Check for continuous scale
        if (scale.category === CONTINUOUS_SCALE) {
            return rangeOf(data, valueOf);
        }
{'fraction_non_alphanumeric': 0.1362040720805055, 'fraction_numerical': 0.001404165691551603, 'mean_word_length': 2.2232277526395174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '4702393', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1174, 'n_words': 399}