{"size": 1271, "ext": "js", "max_stars_repo_path": "src/fields/categorical/index.js", "max_stars_repo_name": "chartshq-eng/datamodel-deprecated", "max_stars_repo_stars_event_min_datetime": "2020-07-23T12:55:33.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-23T12:55:33.000Z", "max_issues_repo_path": "src/fields/categorical/index.js", "max_issues_repo_name": "chartshq-eng/datamodel-deprecated", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fields/categorical/index.js", "max_forks_repo_name": "chartshq-eng/datamodel-deprecated", "max_forks_repo_forks_event_min_datetime": "2021-02-17T06:27:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-17T06:27:38.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 25.42, "max_line_length": 95, "alphanum_fraction": 0.5806451613}
import { rowDiffsetIterator } from '../../operator/row-diffset-iterator';
import { DimensionSubtype } from '../../enums';
import Dimension from '../dimension';
import CategoricalParser from '../parsers/categorical-parser';
/**
 * Represents categorical field subtype.
 *
 * @public
 * @class
 * @extends Dimension
 */
export default class Categorical extends Dimension {
    /**
     * Returns the subtype of the field.
     *
     * @public
     * @override
     * @return {string} Returns the subtype of the field.
     */
    subtype () {
        return DimensionSubtype.CATEGORICAL;
    }

    /**
     * Calculates the corresponding field domain.
     *
     * @public
     * @override
     * @return {Array} Returns the unique values.
     */
    calculateDataDomain () {
        const hash = new Set();
        const domain = [];

        // here don't use this.data() as the iteration will be occurred two times on same data.
        rowDiffsetIterator(this.rowDiffset, (i) => {
            const datum = this.partialField.data[i];
            if (!hash.has(datum)) {
                hash.add(datum);
                domain.push(datum);
            }
        });
        return domain;
    }

    static parser() {
        return new CategoricalParser();
    }
}
