<commit_before>/*
 * This file is part of the nivo project.
 *
 * Copyright 2016-present, <NAME>.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
import _ from 'lodash'
import { spring } from 'react-motion'
import {
    scaleOrdinal,
    schemeCategory10,
    schemeCategory20,
    schemeCategory20b,
    schemeCategory20c,
    rgb,
} from 'd3'
import {
    schemeAccent,
    schemeDark2,
    schemePaired,
    schemePastel1,
    schemePastel2,
    schemeSet1,
    schemeSet2,
    schemeSet3,
} from 'd3-scale-chromatic'

export const getColorGenerator = instruction => {
    if (instruction === 'none') {
        return 'none'
    }

    if (_.isFunction(instruction)) {
        return instruction
    }

    if (instruction === 'inherit') {
        return d => d.color || d.data.color
    }

    const inheritMatches = instruction.match(
        /inherit:(darker|brighter)\(([0-9.]+)\)/
    )
    if (inheritMatches) {
        const method = inheritMatches[1]
        const amount = inheritMatches[2]

        return d => rgb(d.color || d.data.color)[method](parseFloat(amount))
    }

    return instruction
}

export const getColorStyleObject = (instruction, property) => {
    const style = {}

    const color = getColorGenerator(instruction)
    if (color !== 'none') {
        style[property] = color
    }

    return style
}

export const extractRGB = (_color, springConfig) => {
    const color = rgb(_color)

    if (!springConfig) {
        return {
            colorR: color.r,
            colorG: color.g,
            colorB: color.b,
        }
    }

    return {
        colorR: spring(
            color.r,
            Object.assign({}, springConfig, { precision: 1 })
        ),
        colorG: spring(<commit_msg>feat(colors): default to given value for getColorGenerator()<commit_after>/*
 * This file is part of the nivo project.
 *
 * Copyright 2016-present, <NAME>.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
import _ from 'lodash'
import { spring } from 'react-motion'
import {
    scaleOrdinal,
    schemeCategory10,
    schemeCategory20,
    schemeCategory20b,
    schemeCategory20c,
    rgb,
} from 'd3'
import {
    schemeAccent,
    schemeDark2,
    schemePaired,
    schemePastel1,
    schemePastel2,
    schemeSet1,
    schemeSet2,
    schemeSet3,
} from 'd3-scale-chromatic'

export const getColorGenerator = instruction => {
    if (instruction === 'none') {
        return 'none'
    }

    if (_.isFunction(instruction)) {
        return instruction
    }

    if (instruction === 'inherit') {
        return d => d.color || d.data.color
    }

    const inheritMatches = instruction.match(
        /inherit:(darker|brighter)\(([0-9.]+)\)/
    )
    if (inheritMatches) {
        const method = inheritMatches[1]
        const amount = inheritMatches[2]

        return d => rgb(d.color || d.data.color)[method](parseFloat(amount))
    }

    return () => instruction
}

export const getColorStyleObject = (instruction, property) => {
    const style = {}

    const color = getColorGenerator(instruction)
    if (color !== 'none') {
        style[property] = color
    }

    return style
}

export const extractRGB = (_color, springConfig) => {
    const color = rgb(_color)

    if (!springConfig) {
        return {
            colorR: color.r,
            colorG: color.g,
            colorB: color.b,
        }
    }

    return {
        colorR: spring(
            color.r,
            Object.assign({}, springConfig, { precision: 1 })
        ),
        colorG: spring(
{'fraction_non_alphanumeric': 0.11514494716878895, 'fraction_numerical': 0.0135464643727987, 'mean_word_length': 2.359417652411283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '5128963', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1085, 'n_words': 285}