FacetHorizontal.prototype.select = function()

in lib/@uncharted.software/stories-facets/src/components/facet/facetHorizontal.js [169:211]


FacetHorizontal.prototype.select = function(data) {
	if (data && 'selection' in data) {
		var selectionData = data.selection;

		if ('range' in selectionData) {
			var from = selectionData.range.from;
			var to = selectionData.range.to;

			var fromIsString = (typeof from === 'string' || (typeof from === 'object' && from.constructor === String));
			var toIsString = (typeof to === 'string' || (typeof to === 'object' && to.constructor === String));

			var bars = this._histogram.bars;
			for (var i = 0, n = bars.length; i < n && (fromIsString || toIsString); ++i) {
				var barMetadata = bars[i].metadata;

				for (var ii = 0, nn = barMetadata.length; ii < nn; ++ii) {
					var slice = barMetadata[ii];

					if (fromIsString && (slice.label === from || +slice.label === +from)) {
						from = i;
						fromIsString = false;
					}

					if (toIsString && (slice.toLabel === to || +slice.toLabel === +to)) {
						to = i;
						toIsString = false;
					}
				}
			}

			if (!fromIsString && !toIsString) {
				this._histogramFilter.setFilterBarRange({from: from, to: to});
			}
		} else {
			this._histogramFilter.setFilterPixelRange({ from: 0, to: this._histogram.totalWidth });
		}

		this._histogram.deselect();
		if ('slices' in selectionData) {
			this._histogram.select(selectionData.slices);
		}
	}
};