public enumerateObjectInstances()

in powerbi-visual-builder/src_visual/visual.ts [1085:1176]


    public enumerateObjectInstances(options) {
      const objectName = options.objectName as string;
      const objectEnumeration = [];
      const properties: { [name: string]: any } = {};
      const templateProperties = this.template.properties.filter(
        p => p.objectID === objectName.replace(propertyAndObjectNamePrefix, "")
      ) as PowerBIProperty[];

      if (objectName === SettingsNames.General) {
        objectEnumeration.push({
          objectName,
          properties: {
            decimalSeparator:
              this.properties.decimalSeparator || defaultDecimalSeparator,
            thousandSeparator:
              this.properties.thousandSeparator || defaultThousandSeparator,
            currency: this.properties.currency || defaultCurrency,
            group: this.properties.group || defaultGroup
          },
          selector: null
        });
      } else {
        for (const p of templateProperties) {
          if (this.properties[p.powerBIName] !== undefined) {
            if (
              p.displayName.indexOf("xData.categories") > -1 ||
              p.displayName.indexOf("yData.categories") > -1 ||
              p.displayName.indexOf("axis.categories") > -1
            ) {
              const values = this.chartContainer.getProperty(p.objectID, {
                property: (p.target.property as any).property,
                field: (p.target.property as any).field
              });
              if (values) {
                const a = values[0].toString();
                const b = values[(values as any[]).length - 1].toString();
                if (b.localeCompare(a) > -1) {
                  properties[p.powerBIName] = "ascending";
                } else {
                  properties[p.powerBIName] = "descending";
                }
              } else {
                properties[p.powerBIName] = "ascending";
              }
            } else {
              properties[p.powerBIName] = this.properties[p.powerBIName];
            }
          } else {
            if (this.chartContainer) {
              if (p.target.property) {
                properties[p.powerBIName] = this.chartContainer.getProperty(
                  p.objectID,
                  p.target.property
                );
              }
              if (p.target.attribute) {
                const mapping = this.chartContainer.getAttributeMapping(
                  p.objectID,
                  p.target.attribute
                );
                if (mapping.type == "value") {
                  properties[p.powerBIName] = (mapping as any).value;
                }
              }
            } else {
              if (p.target.property) {
                properties[
                  p.powerBIName
                ] = CharticulatorContainer.ChartTemplate.GetChartProperty(
                  this.template.specification,
                  p.objectID,
                  p.target.property
                );
              }
              if (p.target.attribute) {
                const mapping = CharticulatorContainer.ChartTemplate.GetChartAttributeMapping(
                  this.template.specification,
                  p.objectID,
                  p.target.attribute
                );
                if (mapping.type == "value") {
                  properties[p.powerBIName] = (mapping as any).value;
                }
              }
            }
          }
        }
        objectEnumeration.push({ objectName, properties, selector: null });
      }

      return objectEnumeration;
    }