private syncFacets()

in src/FacetsVisual.ts [310:345]


    private syncFacets() {
        // update new group and Other count with more|Less buttons
        this.data.facetsData.forEach((groupData: any) => {
            const key = groupData.key;
            const group = this.facets._getGroup(key);
            if (group) {
                const numVisibleFacets = group.facets.length;
                const allFacets = this.getFacetGroup(key).allFacets;
                const moreInitialFacets = numVisibleFacets < this.settings.facetCount.initial
                    ? allFacets.slice(numVisibleFacets, this.settings.facetCount.initial)
                    : [];
                const newNumVisibleFacets = numVisibleFacets + moreInitialFacets.length;
                const remaining = Math.max(allFacets.length - newNumVisibleFacets, 0);
                const hasMoreThanInitial = newNumVisibleFacets > this.settings.facetCount.initial;
                let more = remaining && [
                        { label: otherLabelTemplate(remaining), class: 'other', clickable: false },
                        { label: 'More', class: 'more', clickable: true },
                    ];
                hasMoreThanInitial && more
                    ? more.splice(1, 0,
                    { label: 'Less', class: 'less', clickable: true },
                    { label: '|', class: 'seperator', clickable: false }
                )
                    : [{ label: 'Less', class: 'less', clickable: true }];
                this.facets.append([{
                    key: key,
                    facets: moreInitialFacets,
                    more: more,
                }]);
                this.data.hasHighlight && moreInitialFacets.length > 0 && this.facets.select(this.data.facetsSelectionData);
            } else {
                this.facets.append([groupData]);
                this.data.hasHighlight && this.facets.select(this.data.facetsSelectionData);
            }
        });
    }