filter/filter-sum-of-dimensions.js

/**
 * Copyright (c) 2019
 *
 * @summary chart class
 * @author Elitza Vasileva
 * @author Bernhard Pointner
 */
class FilterSumOfDimensions {
    constructor(_dimensions,_cat_identifier, _cat_identifier_start, _num_genres_per_row) {
        this.dimensions = _dimensions; // crossfilter dimensions list
        this.cat_identifier = _cat_identifier;
        this.cat_identifier_start = _cat_identifier_start;
        this.start = null;
        this.end = null;
        this.num_genres_per_row = _num_genres_per_row;
    }

    /**
     * Updates the brushing filter by setting a new start and end value
     * @param start   start value
     * @param end   end value
     */
    updateFilter(start,end) {
        this.start = start;
        this.end = end;
    }

    /**
     * Evaluates the row according to the start and end
     * @param row   the row to be evaluated
     * @param i
     * @returns {boolean}
     */
    evaluateRow(row,i) {
        if(this.start != null) {
            return this.num_genres_per_row[row.index] >= this.start && this.num_genres_per_row[row.index] <= this.end;
        } else {
            return true;
        }

        /*function sumUpDimensions(_this) {
            return _this.dimensions.map((dimension,i) => row[_this.cat_identifier + (i+_this.cat_identifier_start)]).reduce((a,b) => a + b, 0);
        }*/
    }

    /**
     * resets the filter
     */
    resetFilter() {
        this.start = null;
        this.end = null;
    }
}