pivot(pivotConfig) {
    pivotConfig = this.normalizePivotConfig(pivotConfig);
    let groupByXAxis = groupBy(({ xValues }) => this.axisValuesString(xValues));

    // eslint-disable-next-line no-unused-vars
    let measureValue = (row, measure, xValues) => row[measure];

    if (
      pivotConfig.fillMissingDates &&
      pivotConfig.x.length === 1 &&
      equals(
        pivotConfig.x,
        (this.loadResponse.query.timeDimensions || [])
          .filter(td => !!td.granularity)
          .map(td => ResultSet.timeDimensionMember(td))
      )
    ) {
      const series = this.timeSeries(this.loadResponse.query.timeDimensions[0]);
      if (series) {
        groupByXAxis = (rows) => {
          const byXValues = groupBy(
            ({ xValues }) => moment(xValues[0]).format(moment.HTML5_FMT.DATETIME_LOCAL_MS),
            rows
          );
          return series.map(d => ({ [d]: byXValues[d] || [{ xValues: [d], row: {} }] }))
            .reduce((a, b) => Object.assign(a, b), {});
        };

        // eslint-disable-next-line no-unused-vars
        measureValue = (row, measure, xValues) => row[measure] || 0;
      }
    }

    const xGrouped = pipe(
      map(row => this.axisValues(pivotConfig.x)(row).map(xValues => ({ xValues, row }))),
      unnest,
      groupByXAxis,
      toPairs
    )(this.timeDimensionBackwardCompatibleData());

    const allYValues = pipe(
      map(
        // eslint-disable-next-line no-unused-vars
        ([, rows]) => unnest(
          // collect Y values only from filled rows
          rows.filter(({ row }) => Object.keys(row).length > 0).map(({ row }) => this.axisValues(pivotConfig.y)(row))
        )
      ),
      unnest,
      uniq
    )(xGrouped);

    // eslint-disable-next-line no-unused-vars
    return xGrouped.map(([xValuesString, rows]) => {
      const { xValues } = rows[0];
      const yGrouped = pipe(
        map(({ row }) => this.axisValues(pivotConfig.y)(row).map(yValues => ({ yValues, row }))),
        unnest,
        groupBy(({ yValues }) => this.axisValuesString(yValues))
      )(rows);
      return {
        xValues,
        yValuesArray: unnest(allYValues.map(yValues => {
          const measure = pivotConfig.x.find(d => d === 'measures') ?
            ResultSet.measureFromAxis(xValues) :
            ResultSet.measureFromAxis(yValues);
          return (yGrouped[this.axisValuesString(yValues)] ||
            [{ row: {} }]).map(({ row }) => [yValues, measureValue(row, measure, xValues)]);
        }))
      };
    });
  }
/**
   * Base method for pivoting {@link ResultSet} data.
   * Most of the times shouldn't be used directly and {@link ResultSet#chartPivot}
   * or {@link ResultSet#tablePivot} should be used instead.
   *
   * You can find the examples of using the `pivotConfig` [here](#pivot-config)
   * ```js
   * // For query
   * {
   *   measures: ['Stories.count'],
   *   timeDimensions: [{
   *     dimension: 'Stories.time',
   *     dateRange: ['2015-01-01', '2015-03-31'],
   *     granularity: 'month'
   *   }]
   * }
   *
   * // ResultSet.pivot({ x: ['Stories.time'], y: ['measures'] }) will return
   * [
   *   {
   *     xValues: ["2015-01-01T00:00:00"],
   *     yValuesArray: [
   *       [['Stories.count'], 27120]
   *     ]
   *   },
   *   {
   *     xValues: ["2015-02-01T00:00:00"],
   *     yValuesArray: [
   *       [['Stories.count'], 25861]
   *     ]
   *   },
   *   {
   *     xValues: ["2015-03-01T00:00:00"],
   *     yValuesArray: [
   *       [['Stories.count'], 29661]
   *     ]
   *   }
   * ]
   * ```
   * @param {PivotConfig} [pivotConfig]
   * @returns {Array} of pivoted rows.
   */
Base method for pivoting  ResultSet data.
Most of the times shouldn't be used directly and  ResultSet#chartPivot
or  ResultSet#tablePivot should be used instead.




Base method for pivoting ResultSet data . Most of the times shouldn ' t be used directly and ResultSet#chartPivot or ResultSet#tablePivot should be used instead .
pivot(pivotConfig) {
    pivotConfig = this.normalizePivotConfig(pivotConfig);
    let groupByXAxis = groupBy(({ xValues }) => this.axisValuesString(xValues));
    let measureValue = (row, measure, xValues) => row[measure];
    if (
      pivotConfig.fillMissingDates &&
      pivotConfig.x.length === 1 &&
      equals(
        pivotConfig.x,
        (this.loadResponse.query.timeDimensions || [])
          .filter(td => !!td.granularity)
          .map(td => ResultSet.timeDimensionMember(td))
      )
    ) {
      const series = this.timeSeries(this.loadResponse.query.timeDimensions[0]);
      if (series) {
        groupByXAxis = (rows) => {
          const byXValues = groupBy(
            ({ xValues }) => moment(xValues[0]).format(moment.HTML5_FMT.DATETIME_LOCAL_MS),
            rows
          );
          return series.map(d => ({ [d]: byXValues[d] || [{ xValues: [d], row: {} }] }))
            .reduce((a, b) => Object.assign(a, b), {});
        };
        measureValue = (row, measure, xValues) => row[measure] || 0;
      }
    }
    const xGrouped = pipe(
      map(row => this.axisValues(pivotConfig.x)(row).map(xValues => ({ xValues, row }))),
      unnest,
      groupByXAxis,
      toPairs
    )(this.timeDimensionBackwardCompatibleData());
    const allYValues = pipe(
      map(
        ([, rows]) => unnest(
          rows.filter(({ row }) => Object.keys(row).length > 0).map(({ row }) => this.axisValues(pivotConfig.y)(row))
        )
      ),
      unnest,
      uniq
    )(xGrouped);
    return xGrouped.map(([xValuesString, rows]) => {
      const { xValues } = rows[0];
      const yGrouped = pipe(
        map(({ row }) => this.axisValues(pivotConfig.y)(row).map(yValues => ({ yValues, row }))),
        unnest,
        groupBy(({ yValues }) => this.axisValuesString(yValues))
      )(rows);
      return {
        xValues,
        yValuesArray: unnest(allYValues.map(yValues => {
          const measure = pivotConfig.x.find(d => d === 'measures') ?
            ResultSet.measureFromAxis(xValues) :
            ResultSet.measureFromAxis(yValues);
          return (yGrouped[this.axisValuesString(yValues)] ||
            [{ row: {} }]).map(({ row }) => [yValues, measureValue(row, measure, xValues)]);
        }))
      };
    });
  }
pivot ( pivotConfig ) { pivotConfig = this . normalizePivotConfig ( pivotConfig ) ; let groupByXAxis = groupBy ( ( { xValues } ) => this . axisValuesString ( xValues ) ) ; let measureValue = ( row , measure , xValues ) => row [ measure ] ; if ( pivotConfig . fillMissingDates && pivotConfig . x . length === 1 && equals ( pivotConfig . x , ( this . loadResponse . query . timeDimensions || [ ] ) . filter ( td => ! ! td . granularity ) . map ( td => ResultSet . timeDimensionMember ( td ) ) ) ) { const series = this . timeSeries ( this . loadResponse . query . timeDimensions [ 0 ] ) ; if ( series ) { groupByXAxis = ( rows ) => { const byXValues = groupBy ( ( { xValues } ) => moment ( xValues [ 0 ] ) . format ( moment . HTML5_FMT . DATETIME_LOCAL_MS ) , rows ) ; return series . map ( d => ( { [ d ] : byXValues [ d ] || [ { xValues : [ d ] , row : { } } ] } ) ) . reduce ( ( a , b ) => Object . assign ( a , b ) , { } ) ; } ; measureValue = ( row , measure , xValues ) => row [ measure ] || 0 ; } } const xGrouped = pipe ( map ( row => this . axisValues ( pivotConfig . x ) ( row ) . map ( xValues => ( { xValues , row } ) ) ) , unnest , groupByXAxis , toPairs ) ( this . timeDimensionBackwardCompatibleData ( ) ) ; const allYValues = pipe ( map ( ( [ , rows ] ) => unnest ( rows . filter ( ( { row } ) => Object . keys ( row ) . length > 0 ) . map ( ( { row } ) => this . axisValues ( pivotConfig . y ) ( row ) ) ) ) , unnest , uniq ) ( xGrouped ) ; return xGrouped . map ( ( [ xValuesString , rows ] ) => { const { xValues } = rows [ 0 ] ; const yGrouped = pipe ( map ( ( { row } ) => this . axisValues ( pivotConfig . y ) ( row ) . map ( yValues => ( { yValues , row } ) ) ) , unnest , groupBy ( ( { yValues } ) => this . axisValuesString ( yValues ) ) ) ( rows ) ; return { xValues , yValuesArray : unnest ( allYValues . map ( yValues => { const measure = pivotConfig . x . find ( d => d === 'measures' ) ? ResultSet . measureFromAxis ( xValues ) : ResultSet . measureFromAxis ( yValues ) ; return ( yGrouped [ this . axisValuesString ( yValues ) ] || [ { row : { } } ] ) . map ( ( { row } ) => [ yValues , measureValue ( row , measure , xValues ) ] ) ; } ) ) } ; } ) ; }
Base method for pivoting {@link ResultSet} data.
Base method for pivoting { @link ResultSet } data .
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars // collect Y values only from filled rows // eslint-disable-next-line no-unused-vars