public buildEnumerationObjects()

in packages/attribute-slicer-powerbi/src/state/index.ts [161:238]


	public buildEnumerationObjects(
		objectName: string,
		dataView: powerbiVisualsApi.DataView,
	): powerbiVisualsApi.VisualObjectInstanceEnumeration {
		const settings = <PowerBISettings>PowerBISettings.getDefault();

		// Construct a settings object from our internal state 
		settings.display.displayValueLabels = this.displayValueLabels;
		settings.display.hideEmptyItems = this.hideEmptyItems;
		settings.display.horizontal = this.horizontal;
		settings.display.labelDisplayUnits = this.labelDisplayUnits;
		settings.display.labelPrecision = this.labelPrecision;
		settings.display.overflowValueLabels = this.overflowValueLabels;
		settings.display.valueColumnWidth = this.valueColumnWidth;

		settings.general.itemTextColor = this.itemTextColor;
		settings.general.leftAlignText = this.leftAlignText;
		settings.general.showOptions = this.showOptions;
		settings.general.showSearch = this.showSearch;
		settings.general.textSize = pixelConverter.toPoint(
			this.textSize ? this.textSize : DEFAULT_STATE.textSize,
		);

		// Always override this
		settings.general.version = BUILD_VERSION;

		settings.selection.brushMode = this.brushMode;
		settings.selection.showSelections = this.showSelections;
		settings.selection.singleSelect = this.singleSelect;

		if (dataSupportsColorizedInstances(dataView)) {
			settings.dataPoint.colorMode = this.colors.colorMode;
			settings.dataPoint.reverseOrder = dataSupportsValueSegments(dataView)
				? this.colors.reverseOrder
				: undefined;

			if (this.colors.colorMode === ColorMode.Gradient) {
				if (dataSupportsGradients(dataView)) {
					settings.dataPoint.startColor = this.colors.gradient.startColor;
					settings.dataPoint.endColor = this.colors.gradient.endColor;
					settings.dataPoint.startValue = this.colors.gradient.startValue;
					settings.dataPoint.endValue = this.colors.gradient.endValue;
				}
			}
		} else {
			settings.dataPoint = undefined;
		}

		const instances = PowerBISettings.enumerateObjectInstances(settings, {
			objectName,
		});

		// Handle these specifically, DataViewObjectsParser does not support instancing like this
		if (
			this.colors.colorMode !== ColorMode.Gradient &&
			dataSupportsColorizedInstances(dataView)
		) {
			const colorInstances = this.colors.instanceColors.map((c, idx) => {
				const instanceColor = colors[idx] || "#ccc";
				const finalColor = c.color || instanceColor;
				return {
					displayName: c.name,
					selector: c.identity.getSelector(),
					properties: {
						fill: finalColor,
					},
				};
			});

			if (Array.isArray(instances)) {
				instances.push(...(<any>colorInstances));
			} else {
				instances.instances.push(...(<any>colorInstances));
			}
		}

		return instances;
	}