| 118120 | // First collect all unique pivot field values. |
| 118121 | // Then generate aggregate fields for each output pivot field. |
| 118122 | function aggregateParams(_, pulse) { |
| 118123 | const key = _.field, value = _.value, op = (_.op === "count" ? "__count__" : _.op) || "sum", fields = (0, _vegaUtil.accessorFields)(key).concat((0, _vegaUtil.accessorFields)(value)), keys = pivotKeys(key, _.limit || 0, pulse); // if data stream content changes, pivot fields may change |
| 118124 | // flag parameter modification to ensure re-initialization |
| 118125 | if (pulse.changed()) _.set("__pivot__", null, null, true); |
| 118126 | return { |
| 118127 | key: _.key, |
| 118128 | groupby: _.groupby, |
| 118129 | ops: keys.map(()=>op), |
| 118130 | fields: keys.map((k)=>get(k, key, value, fields)), |
| 118131 | as: keys.map((k)=>k + ""), |
| 118132 | modified: _.modified.bind(_) |
| 118133 | }; |
| 118134 | } // Generate aggregate field accessor. |
| 118135 | // Output NaN for non-existent values; aggregator will ignore! |
| 118136 | function get(k, key, value, fields) { |
| 118137 | return (0, _vegaUtil.accessor)((d)=>key(d) === k ? value(d) : NaN, fields, k + ""); |