1 | import {Transform} from 'vega-dataflow';
|
2 | import {inherits} from 'vega-util';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export default function Formula(params) {
|
14 | Transform.call(this, null, params);
|
15 | }
|
16 |
|
17 | Formula.Definition = {
|
18 | 'type': 'Formula',
|
19 | 'metadata': {'modifies': true},
|
20 | 'params': [
|
21 | { 'name': 'expr', 'type': 'expr', 'required': true },
|
22 | { 'name': 'as', 'type': 'string', 'required': true },
|
23 | { 'name': 'initonly', 'type': 'boolean' }
|
24 | ]
|
25 | };
|
26 |
|
27 | var prototype = inherits(Formula, Transform);
|
28 |
|
29 | prototype.transform = function(_, pulse) {
|
30 | var func = _.expr,
|
31 | as = _.as,
|
32 | mod = _.modified(),
|
33 | flag = _.initonly ? pulse.ADD
|
34 | : mod ? pulse.SOURCE
|
35 | : pulse.modified(func.fields) || pulse.modified(as) ? pulse.ADD_MOD
|
36 | : pulse.ADD;
|
37 |
|
38 | if (mod) {
|
39 |
|
40 | pulse = pulse.materialize().reflow(true);
|
41 | }
|
42 |
|
43 | if (!_.initonly) {
|
44 | pulse.modifies(as);
|
45 | }
|
46 |
|
47 | return pulse.visit(flag, t => t[as] = func(t, _));
|
48 | };
|