Not sure how to use "expressions" #1608
-
|
I'm trying to use the expressions argument of the view instance. Since I couldn't find any documentation for expressions, I don't have enough information about the usage, syntax and the limitations of this feature. One of the things I want to know is, while creating aggregations via expressions, is it possible to create "stateful" expressions? For example, let's say we want to calculate the average of the last three values t, t-1 and t-2... Any help would be appreciated, thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Expression documentation is something I am working on right now. The syntax for the language itself is a slightly-modified version of ExprTK, the main difference being double-quoted strings to refer to Columns and single-quoted strings to refer to string-literals, and the use of comment For now, the best way to play with expressions is to use the built-in // Copy to clipboard
copy(await document.querySelector("perspective-viewer").save());I've been working on some examples for this as well, the most complex currently is this Mandelbrot demo which calculates the popular fractal in an expression column and // color
var c := float("iterations");
var x := floor("index" / "height");
var y := "index" % "height";
var cx := "xmin" + (("xmax" - "xmin") * x) / ("width" - 1);
var cy := "ymin" + (("ymax" - "ymin") * y) / ("height" - 1);
var vx := 0;
var vy := 0;
var vxx := 0;
var vyy := 0;
var vxy := 0;
for (var ii := 0; ii < float("iterations"); ii += 1) {
if (vxx + vyy <= float(4)) {
vxy := vx * vy;
vxx := vx * vx;
vyy := vy * vy;
vx := vxx - vyy + cx;
vy := vxy + vxy + cy;
c -= 1;
}
};
c
|
Beta Was this translation helpful? Give feedback.
Expression documentation is something I am working on right now. The syntax for the language itself is a slightly-modified version of ExprTK, the main difference being double-quoted strings to refer to Columns and single-quoted strings to refer to string-literals, and the use of comment
//fields in the first line to rename/alias.For now, the best way to play with expressions is to use the built-in
monacoeditor by clicking theNew Columnbutton in the column selector. It has (somewhat rough) autocompletion for all built-in functions and your dataset's column names, and will highlight any syntax or type errors in red (though we're working on making this feedback stronger). If you're fami…