@@ -22,19 +22,101 @@ export type WindowReducerFunction = (values: any[]) => any;
2222export type WindowReducer = WindowReducerName | WindowReducerFunction ;
2323
2424export interface WindowOptions {
25- k ?: number ;
25+ /**
26+ * The size (number of consecutive values) in the window; includes the current
27+ * value.
28+ */
29+ k : number ;
30+
31+ /**
32+ * How to produce a summary statistic from the **k** values in the current
33+ * window. The reducer may be specified as:
34+ *
35+ * * *min* - the minimum
36+ * * *max* - the maximum
37+ * * *mean* (default) - the mean (average)
38+ * * *median* - the median
39+ * * *mode* - the mode (most common occurrence)
40+ * * *pXX* - the percentile value, where XX is a number in [00,99]
41+ * * *sum* - the sum of values
42+ * * *deviation* - the standard deviation
43+ * * *variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
44+ * * *difference* - the difference between the last and first window value
45+ * * *ratio* - the ratio of the last and first window value
46+ * * *first* - the first value
47+ * * *last* - the last value
48+ * * a function to be passed an array of **k** values
49+ */
2650 reduce ?: WindowReducer ;
51+
52+ /**
53+ * How to align the rolling window, placing the current value:
54+ *
55+ * * *start* - as the first element in the window
56+ * * *middle* (default) - in the middle of the window, rounding down if **k** is even
57+ * * *end* - as the last element in the window
58+ */
2759 anchor ?: "start" | "middle" | "end" ;
28- shift ?: "leading" | "centered" | "trailing" ; // deprecated!
60+
61+ /** @deprecated See **anchor**. */
62+ shift ?: "leading" | "centered" | "trailing" ;
63+
64+ /**
65+ * If true, the output start values or end values or both (depending on the
66+ * **anchor**) of each series may be undefined since there are not enough
67+ * elements to create a window of size **k**; output values may also be
68+ * undefined if some of the input values in the corresponding window are
69+ * undefined.
70+ *
71+ * If false (the default), the window will be automatically truncated as
72+ * needed, and undefined input values are ignored. For example, if **k** is 24
73+ * and **anchor** is *middle*, then the initial 11 values have effective
74+ * window sizes of 13, 14, 15, … 23, and likewise the last 12 values have
75+ * effective window sizes of 23, 22, 21, … 12. Values computed with a
76+ * truncated window may be noisy; if you would prefer to not show this data,
77+ * set the **strict** option to true.
78+ */
2979 strict ?: boolean ;
3080}
3181
82+ /**
83+ * Computes a moving window of *x*, *x1*, and *x2* channel values and then
84+ * derives a summary statistic from values in the current window, say to compute
85+ * a rolling average. The window options can be specified as the first argument,
86+ * or grouped with the *options*. For example, the following are equivalent:
87+ *
88+ * ```js
89+ * Plot.windowX(24, {x: "Anomaly", y: "Date"});
90+ * Plot.windowX({k: 24, reduce: "mean", x: "Anomaly", y: "Date"});
91+ * Plot.windowX({k: 24, reduce: "mean"}, {x: "Anomaly", y: "Date"});
92+ * ```
93+ */
3294export function windowX < T > ( options ?: T & WindowOptions ) : Transformed < T > ;
33-
3495export function windowX < T > ( windowOptions ?: WindowOptions | number , options ?: T ) : Transformed < T > ;
3596
97+ /**
98+ * Computes a moving window of *y*, *y1*, and *y2* channel values around and
99+ * then derives a summary statistic from values in the current window, say to
100+ * compute a rolling average. The window options can be specified as the first
101+ * argument, or grouped with the *options*. For example, the following are
102+ * equivalent:
103+ *
104+ * ```js
105+ * Plot.windowY(24, {x: "Date", y: "Anomaly"});
106+ * Plot.windowY({k: 24, reduce: "mean", x: "Date", y: "Anomaly"});
107+ * Plot.windowY({k: 24, reduce: "mean"}, {x: "Date", y: "Anomaly"});
108+ * ```
109+ */
36110export function windowY < T > ( options ?: T & WindowOptions ) : Transformed < T > ;
37-
38111export function windowY < T > ( windowOptions ?: WindowOptions | number , options ?: T ) : Transformed < T > ;
39112
113+ /**
114+ * Returns a window map method suitable for use with Plot.map. The options are
115+ * the window size *k*, or an object with properties *k*, *anchor*, *reduce*, or
116+ * *strict*.
117+ *
118+ * ```js
119+ * Plot.map({y: Plot.window(24)}, {x: "Date", y: "Close", stroke: "Symbol"})
120+ * ```
121+ */
40122export function window ( options ?: WindowOptions | number ) : Map ;
0 commit comments