Function normalizeNestedStackDataByDate

  • Normalize the data arrays resulting from a d3.nest operation so that all group value arrays have the same number of elements, based on a Date property named date.

    The data values are assumed to be sorted by date already, and are modified in-place. This makes the data suitable to passing to d3.stack, which expects all stack data arrays to have the same number of values, for the same keys. When querying for data in SolarNetwork there might be gaps in the results, so this function can be used to "fill in" those gaps with "dummy" values so that there are no more gaps.

    Filled-in data objects are automatically populated with an appropriate date property and a sourceId property taken from the key of the layer the gap if found in. You can pass a fillTemplate object with static properties to also include on all filled-in data objects. You can also pass a fillFn function to populate the filled-in objects with dynamic data.

    For example, given:

    const layerData = [
    { key : 'A', values : [{date : new Date('2011-12-02 12:00')}, {date : new Date('2011-12-02 12:10')}] },
    { key : 'B', values : [{date : new Date('2011-12-02 12:00')}] }
    ];

    normalizeNestedStackDataByDate(layerData);

    The layerData would be modified in-place and look like this (notice the filled in second data value in the B group):

    [
    { key : 'A', values : [{date : new Date('2011-12-02 12:00')}, {date : new Date('2011-12-02 12:10')}] },
    { key : 'B', values : [{date : new Date('2011-12-02 12:00')}, {date : new Date('2011-12-02 12:10'), sourceId : 'B'}] }
    ]

    Parameters

    • layerData: {
          key: string;
          values: {
              date: Date;
          }[];
      }[]

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

    • Optional fillTemplate: Record<string, any>

      An object to use as a template for any filled-in data objects. The date property will be populated automatically, and a sourceId property will be populated by the layer's key.

    • Optional fillFn: ((datum, key, prevDatum?) => void)

      An optional function to populate filled-in data objects with. This function is invoked after populating any fillTemplate values.

        • (datum, key, prevDatum?): void
        • Parameters

          • datum: Record<string, any>
          • key: string
          • Optional prevDatum: Record<string, any>

          Returns void

    Returns void

Generated using TypeDoc