<commit_before>/**
 * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
 *
 * @author <NAME> <<EMAIL>>
 */

import { ColorScale, Color } from 'mol-util/color';
import { Location } from 'mol-model/location';
import { StructureElement, Link, Unit } from 'mol-model/structure';
import { OrderedSet } from 'mol-data/int';
import { ColorThemeProps, ColorTheme, LocationColor } from '../color';

const DefaultColor = Color(0xCCCCCC)

export function ElementIndexColorTheme(props: ColorThemeProps): ColorTheme {
    let color: LocationColor

    if (props.structure) {
        const { units } = props.structure
        const unitCount = units.length
        const cummulativeElementCount = new Map<number, number>()

        let elementCount = 0
        for (let i = 0; i < unitCount; ++i) {
            cummulativeElementCount.set(i, elementCount)
            elementCount += units[i].elements.length
        }
        const scale = ColorScale.create({ domain: [ 0, elementCount ] })

        color = (location: Location): Color => {
            if (StructureElement.isLocation(location)) {
                const unitIndex = Unit.findUnitById(location.unit.id, units)
                const unitElementIndex = OrderedSet.findPredecessorIndex(location.unit.elements, location.element)
                return scale.color(cummulativeElementCount.get(unitIndex) || 0 + unitElementIndex)
            } else if (Link.isLocation(location)) {
                const unitId = Unit.findUnitById(location.aUnit.id, units)
                return scale.color(cummulativeElementCount.get(unitId) || 0 + location.aIndex)
            }
            return DefaultColor
        }
    } else {
        color = () => DefaultColor<commit_msg>fixed element-index color-scheme<commit_after>/**
 * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
 *
 * @author <NAME> <<EMAIL>>
 */

import { ColorScale, Color } from 'mol-util/color';
import { Location } from 'mol-model/location';
import { StructureElement, Link } from 'mol-model/structure';
import { OrderedSet } from 'mol-data/int';
import { ColorThemeProps, ColorTheme, LocationColor } from '../color';

const DefaultColor = Color(0xCCCCCC)

export function ElementIndexColorTheme(props: ColorThemeProps): ColorTheme {
    let color: LocationColor

    if (props.structure) {
        const { units } = props.structure
        const unitCount = units.length
        const cummulativeElementCount = new Map<number, number>()
        const unitIdIndex = new Map<number, number>()

        let elementCount = 0
        for (let i = 0; i < unitCount; ++i) {
            cummulativeElementCount.set(i, elementCount)
            elementCount += units[i].elements.length
            unitIdIndex.set(units[i].id, i)
        }
        const scale = ColorScale.create({ domain: [ 0, elementCount - 1 ] })

        color = (location: Location): Color => {
            if (StructureElement.isLocation(location)) {
                const unitIndex = unitIdIndex.get(location.unit.id)!
                const unitElementIndex = OrderedSet.findPredecessorIndex(location.unit.elements, location.element)
                return scale.color(cummulativeElementCount.get(unitIndex)! + unitElementIndex)
            } else if (Link.isLocation(location)) {
                const unitIndex = unitIdIndex.get(location.aUnit.id)!
                return scale.color(cummulativeElementCount.get(unitIndex)! + location.aIndex)
            }
            return DefaultColor
        }
    } else {
        color = () => DefaultColor
{'fraction_non_alphanumeric': 0.11018595614765474, 'fraction_numerical': 0.00527338329170136, 'mean_word_length': 2.7580813347236703, 'pattern_counts': {'":': 0, '<': 14, '<?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': '1999411', 'n_tokens_mistral': 1006, 'n_tokens_neox': 956, 'n_words': 246}