Group.prototype.append = function()

in lib/@uncharted.software/stories-facets/src/components/group.js [300:352]


Group.prototype.append = function (groupSpec) {
	var existingFacet;

	/* remove event handlers */
	this._removeHandlers();

	groupSpec.more = groupSpec.more || 0;
	this._updateMore(groupSpec.more);

	// make sure the group is not collapsed (so the append effect is visible)
	this.collapsed = false;

	if (groupSpec.total) {
		this._ownsTotal = true;
		this._total = groupSpec.total;
	}

	// update all the facets (the group total most likely changed)
	groupSpec.facets.forEach(function (facetSpec) {
		if (!this._ownsTotal && !('histogram' in facetSpec) && !('placeholder' in facetSpec)) { // it's not a horizontal facet
			this._total += facetSpec.count;
		}
		existingFacet = this._getFacet(facetSpec.value);
		if (existingFacet) {
			facetSpec.count += existingFacet.count;
			existingFacet.updateSpec(facetSpec);
		} else {
			var facet = this._createNewFacet(facetSpec, groupSpec.key, true);
			if (facet instanceof FacetHorizontal) {
				this.horizontalFacets.push(facet);
			} else {
				this.verticalFacets.push(facet);
			}
			this.facets.push(facet);
			facet.visible = true;
			/* forward all the events from this facet */
			this.forward(facet);
		}
	}, this);

	// Update facet totals so they can rescale their bars
	this.facets.forEach(function (facet) {
		facet.total = this._total;
	}, this);

	/* collapsed state */
	if (groupSpec.collapsed) {
		this.collapsed = true;
	}

	// re-register handlers to ensure newly added elements respond to events
	this._addHandlers();
};