solarnetwork-api-core
    Preparing search index...

    Function aggregateNestedDataLayers

    • Combine the layers resulting from a d3.nest operation into a single, aggregated layer.

      This can be used to combine all sources of a single data type, for example to show all "power" sources as a single layer of chart data. The resulting object has the same structure as the input layerData parameter, with just a single layer of data.

      For example:

      const layerData = [
      { key : 'A', values : [{watts : 123, foo : 1}, {watts : 234, foo : 2}] },
      { key : 'B', values : [{watts : 345, foo : 3}, {watts : 456, foo : 4}] }
      ];

      const result = aggregateNestedDataLayers(layerData,
      'A and B', ['foo'], ['watts'], {'combined' : true});

      Then result would look like this:

      [
      { key : 'A and B', values : [{watts : 468, foo : 1, combined : true},
      {watts : 690, foo : 2, combined : true}] }
      ]

      Parameters

      • layerData: { key: string; values: Record<string, any>[] }[]

        An array of objects with key and values properties, as returned from d3.nest().entries()

      • resultKey: string

        The key property to assign to the returned layer.

      • OptionalcopyProperties: string[]

        An array of string property names to copy as-is from the first layer's data values.

      • OptionalsumProperties: string[]

        An array of string property names to add together from all layer data.

      • OptionalstaticProperties: Record<string, any>

        Static properties to copy as-is to all output data values.

      Returns { key: string; values: Record<string, any>[] }[]

      An array of objects with key and value properties, the same structure as the provided layerData argument