1 | import Facet from './Facet';
|
2 | import {ingest, tupleid} from 'vega-dataflow';
|
3 | import {accessorFields, error, inherits} from 'vega-util';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export default function PreFacet(params) {
|
15 | Facet.call(this, params);
|
16 | }
|
17 |
|
18 | inherits(PreFacet, Facet, {
|
19 | transform(_, pulse) {
|
20 | const flow = _.subflow,
|
21 | field = _.field,
|
22 | subflow = t => this.subflow(tupleid(t), flow, pulse, t);
|
23 |
|
24 | if (_.modified('field') || field && pulse.modified(accessorFields(field))) {
|
25 | error('PreFacet does not support field modification.');
|
26 | }
|
27 |
|
28 | this.initTargets();
|
29 |
|
30 | if (field) {
|
31 | pulse.visit(pulse.MOD, t => {
|
32 | const sf = subflow(t);
|
33 | field(t).forEach(_ => sf.mod(_));
|
34 | });
|
35 |
|
36 | pulse.visit(pulse.ADD, t => {
|
37 | const sf = subflow(t);
|
38 | field(t).forEach(_ => sf.add(ingest(_)));
|
39 | });
|
40 |
|
41 | pulse.visit(pulse.REM, t => {
|
42 | const sf = subflow(t);
|
43 | field(t).forEach(_ => sf.rem(_));
|
44 | });
|
45 | } else {
|
46 | pulse.visit(pulse.MOD, t => subflow(t).mod(t));
|
47 | pulse.visit(pulse.ADD, t => subflow(t).add(t));
|
48 | pulse.visit(pulse.REM, t => subflow(t).rem(t));
|
49 | }
|
50 |
|
51 | if (pulse.clean()) {
|
52 | pulse.runAfter(() => this.clean());
|
53 | }
|
54 |
|
55 | return pulse;
|
56 | }
|
57 | });
|