@compstats/core 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +110 -0
- package/LICENSE +21 -0
- package/README.md +310 -0
- package/dist/3d.d.ts +33 -0
- package/dist/3d.d.ts.map +1 -0
- package/dist/3d.js +1984 -0
- package/dist/3d.js.map +22 -0
- package/dist/core/arith.d.ts +133 -0
- package/dist/core/arith.d.ts.map +1 -0
- package/dist/core/frame.d.ts +98 -0
- package/dist/core/frame.d.ts.map +1 -0
- package/dist/core/histogram.d.ts +68 -0
- package/dist/core/histogram.d.ts.map +1 -0
- package/dist/core/kde.d.ts +106 -0
- package/dist/core/kde.d.ts.map +1 -0
- package/dist/core/logit.d.ts +109 -0
- package/dist/core/logit.d.ts.map +1 -0
- package/dist/core/matrix.d.ts +135 -0
- package/dist/core/matrix.d.ts.map +1 -0
- package/dist/core/moderation.d.ts +127 -0
- package/dist/core/moderation.d.ts.map +1 -0
- package/dist/core/ols.d.ts +76 -0
- package/dist/core/ols.d.ts.map +1 -0
- package/dist/core/pca.d.ts +99 -0
- package/dist/core/pca.d.ts.map +1 -0
- package/dist/core/precision.d.ts +10 -0
- package/dist/core/precision.d.ts.map +1 -0
- package/dist/core/pretty.d.ts +51 -0
- package/dist/core/pretty.d.ts.map +1 -0
- package/dist/core/regression.d.ts +68 -0
- package/dist/core/regression.d.ts.map +1 -0
- package/dist/core/rng.d.ts +206 -0
- package/dist/core/rng.d.ts.map +1 -0
- package/dist/core/sampling.d.ts +157 -0
- package/dist/core/sampling.d.ts.map +1 -0
- package/dist/core/special.d.ts +92 -0
- package/dist/core/special.d.ts.map +1 -0
- package/dist/core/tdist.d.ts +53 -0
- package/dist/core/tdist.d.ts.map +1 -0
- package/dist/core/ttest.d.ts +146 -0
- package/dist/core/ttest.d.ts.map +1 -0
- package/dist/data/moderationData.d.ts +40 -0
- package/dist/data/moderationData.d.ts.map +1 -0
- package/dist/data/pcaDegenerate.d.ts +18 -0
- package/dist/data/pcaDegenerate.d.ts.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4195 -0
- package/dist/index.js.map +47 -0
- package/dist/interactive/controls.d.ts +97 -0
- package/dist/interactive/controls.d.ts.map +1 -0
- package/dist/interactive/logit.d.ts +57 -0
- package/dist/interactive/logit.d.ts.map +1 -0
- package/dist/interactive/matrixInverse.d.ts +86 -0
- package/dist/interactive/matrixInverse.d.ts.map +1 -0
- package/dist/interactive/moderation3d.d.ts +103 -0
- package/dist/interactive/moderation3d.d.ts.map +1 -0
- package/dist/interactive/pca.d.ts +90 -0
- package/dist/interactive/pca.d.ts.map +1 -0
- package/dist/interactive/regression.d.ts +57 -0
- package/dist/interactive/regression.d.ts.map +1 -0
- package/dist/interactive/sampling.d.ts +78 -0
- package/dist/interactive/sampling.d.ts.map +1 -0
- package/dist/interactive/scatter3d.d.ts +124 -0
- package/dist/interactive/scatter3d.d.ts.map +1 -0
- package/dist/interactive/tTest.d.ts +69 -0
- package/dist/interactive/tTest.d.ts.map +1 -0
- package/dist/interactive/target.d.ts +132 -0
- package/dist/interactive/target.d.ts.map +1 -0
- package/dist/plot/axes.d.ts +128 -0
- package/dist/plot/axes.d.ts.map +1 -0
- package/dist/plot/draw.d.ts +46 -0
- package/dist/plot/draw.d.ts.map +1 -0
- package/dist/plot/format.d.ts +33 -0
- package/dist/plot/format.d.ts.map +1 -0
- package/dist/plot/logit.d.ts +68 -0
- package/dist/plot/logit.d.ts.map +1 -0
- package/dist/plot/matrixInverse.d.ts +62 -0
- package/dist/plot/matrixInverse.d.ts.map +1 -0
- package/dist/plot/moderation3d.d.ts +135 -0
- package/dist/plot/moderation3d.d.ts.map +1 -0
- package/dist/plot/pca.d.ts +79 -0
- package/dist/plot/pca.d.ts.map +1 -0
- package/dist/plot/plotly.d.ts +209 -0
- package/dist/plot/plotly.d.ts.map +1 -0
- package/dist/plot/regression.d.ts +52 -0
- package/dist/plot/regression.d.ts.map +1 -0
- package/dist/plot/sampleCi.d.ts +82 -0
- package/dist/plot/sampleCi.d.ts.map +1 -0
- package/dist/plot/sampling.d.ts +159 -0
- package/dist/plot/sampling.d.ts.map +1 -0
- package/dist/plot/scatter3d.d.ts +164 -0
- package/dist/plot/scatter3d.d.ts.map +1 -0
- package/dist/plot/tTest.d.ts +49 -0
- package/dist/plot/tTest.d.ts.map +1 -0
- package/dist/plot/target.d.ts +55 -0
- package/dist/plot/target.d.ts.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The controls the 3D components build, and the rule for where a slider may
|
|
3
|
+
* stand.
|
|
4
|
+
*
|
|
5
|
+
* Both 3D gadgets of the R package are panels of shiny inputs above a plot,
|
|
6
|
+
* and both need the same three things: a labeled slider that shows its own
|
|
7
|
+
* value, a labeled picker, and a line of text for what R would have written
|
|
8
|
+
* to the console. They are here so that the two components differ in what
|
|
9
|
+
* they control, not in how a control is made.
|
|
10
|
+
*
|
|
11
|
+
* The 2D components came first and built their controls inline. The reuse
|
|
12
|
+
* audit at the end of the port found the same builders written out again in
|
|
13
|
+
* each of them, so they share this module too: `interactiveTTest` and
|
|
14
|
+
* `interactiveMatrixInverse` for the slider and the standing rule,
|
|
15
|
+
* `interactiveSampling` for the picker.
|
|
16
|
+
*/
|
|
17
|
+
/** Where a slider may stand: R's `min`, `max` and `step`. */
|
|
18
|
+
export interface SliderRange {
|
|
19
|
+
readonly min: number;
|
|
20
|
+
readonly max: number;
|
|
21
|
+
readonly step: number;
|
|
22
|
+
}
|
|
23
|
+
/** A control, its label, and the element the component listens to. */
|
|
24
|
+
export interface BuiltSlider {
|
|
25
|
+
/** The label element that holds the caption, the value, and the input. */
|
|
26
|
+
readonly wrapper: HTMLElement;
|
|
27
|
+
readonly input: HTMLInputElement;
|
|
28
|
+
/** The element that shows the current value beside the caption. */
|
|
29
|
+
readonly readout: HTMLElement;
|
|
30
|
+
}
|
|
31
|
+
/** A picker, its label, and the element the component listens to. */
|
|
32
|
+
export interface BuiltSelect {
|
|
33
|
+
readonly wrapper: HTMLElement;
|
|
34
|
+
readonly input: HTMLSelectElement;
|
|
35
|
+
}
|
|
36
|
+
/** A line of text for what R writes to the console. */
|
|
37
|
+
export interface BuiltNote {
|
|
38
|
+
readonly element: HTMLElement;
|
|
39
|
+
/** Show a note, or take the line away when there is none. */
|
|
40
|
+
show(text: string | null): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Correct a starting value to something the slider can stand at.
|
|
44
|
+
*
|
|
45
|
+
* Three rules, in order, taken from the `validate()` of the
|
|
46
|
+
* `ion.rangeSlider.js` that ships inside shiny. A value that is not a number
|
|
47
|
+
* becomes the minimum; a value outside the range moves to the nearer bound; a
|
|
48
|
+
* value that misses the step moves to the nearest step, counted from the
|
|
49
|
+
* minimum.
|
|
50
|
+
*
|
|
51
|
+
* The third rule is not R's — R leaves the handle wherever it was asked to
|
|
52
|
+
* stand — but an HTML range input rounds a step-mismatched value by itself,
|
|
53
|
+
* so a component that kept the asked-for number would draw one picture and
|
|
54
|
+
* show a slider standing at another.
|
|
55
|
+
*
|
|
56
|
+
* @param given The value the caller asked for, or nothing.
|
|
57
|
+
* @param fallback The value R's own argument defaults to.
|
|
58
|
+
* @param range Where the slider may stand.
|
|
59
|
+
* @returns A value on the slider's own grid.
|
|
60
|
+
*/
|
|
61
|
+
export declare function startingSliderValue(given: number | undefined, fallback: number, range: SliderRange): number;
|
|
62
|
+
/**
|
|
63
|
+
* Build one labeled slider that shows its own value.
|
|
64
|
+
*
|
|
65
|
+
* @param owner The document to build in.
|
|
66
|
+
* @param name The name the component reads the event by.
|
|
67
|
+
* @param label R's own caption.
|
|
68
|
+
* @param range Where the slider may stand.
|
|
69
|
+
* @param value Where it starts. Pass a value `startingSliderValue` returned.
|
|
70
|
+
* @returns The wrapper to append, the input to listen to, and the readout.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildSlider(owner: Document, name: string, label: string, range: SliderRange, value: number): BuiltSlider;
|
|
73
|
+
/**
|
|
74
|
+
* Build one labeled picker.
|
|
75
|
+
*
|
|
76
|
+
* @param owner The document to build in.
|
|
77
|
+
* @param name The name the component reads the event by.
|
|
78
|
+
* @param label R's own caption.
|
|
79
|
+
* @param choices The options, in the order R lists them. A numeric choice
|
|
80
|
+
* reaches the DOM as its own text, which is how R's own numeric choices
|
|
81
|
+
* arrive there.
|
|
82
|
+
* @param selected The option to start on.
|
|
83
|
+
* @returns The wrapper to append, and the input to listen to.
|
|
84
|
+
*/
|
|
85
|
+
export declare function buildSelect(owner: Document, name: string, label: string, choices: readonly (string | number)[], selected: string | number): BuiltSelect;
|
|
86
|
+
/**
|
|
87
|
+
* Build the line that carries what R writes to the console.
|
|
88
|
+
*
|
|
89
|
+
* A library cannot write to a console, and the plot layer therefore returns
|
|
90
|
+
* its message instead of printing it. One element, whose text is replaced,
|
|
91
|
+
* so that a hundred redraws leave one sentence rather than a hundred.
|
|
92
|
+
*
|
|
93
|
+
* @param owner The document to build in.
|
|
94
|
+
* @returns The element to append, and the way to set its text.
|
|
95
|
+
*/
|
|
96
|
+
export declare function buildNote(owner: Document): BuiltNote;
|
|
97
|
+
//# sourceMappingURL=controls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../../src/interactive/controls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,6DAA6D;AAC7D,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC/B;AAED,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;CACnC;AAED,uDAAuD;AACvD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,6DAA6D;IAC7D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,GACjB,MAAM,CAqBR;AAOD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,MAAM,GACZ,WAAW,CAuBb;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EACrC,QAAQ,EAAE,MAAM,GAAG,MAAM,GACxB,WAAW,CAqBb;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAcpD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive logit: click to add an outcome, and watch the curve move.
|
|
3
|
+
*
|
|
4
|
+
* This is the port of `interactive_logit()` in
|
|
5
|
+
* `../compstatslib/R/logit_interactive.R`. R holds the points in a reactive
|
|
6
|
+
* value and calls `plot_logit()` on every change, forwarding its `...`
|
|
7
|
+
* arguments. This module does the same: it owns the points and the clicks, and
|
|
8
|
+
* it hands every draw to `plotLogit`. It contains no drawing code and no
|
|
9
|
+
* statistics.
|
|
10
|
+
*
|
|
11
|
+
* R's `runGadget()` blocks and returns the points when the user clicks "Done".
|
|
12
|
+
* A browser blocks at nothing, so this returns a handle at once. Read the
|
|
13
|
+
* points from `getPoints()`, or call `done()` to hand them to the `onDone`
|
|
14
|
+
* callback.
|
|
15
|
+
*/
|
|
16
|
+
import type { Point } from "../core/regression";
|
|
17
|
+
import type { PlotLogitOptions } from "../plot/logit";
|
|
18
|
+
import type { InteractiveTarget } from "./target";
|
|
19
|
+
/**
|
|
20
|
+
* What the component accepts.
|
|
21
|
+
*
|
|
22
|
+
* The options of `plotLogit` pass through to it unchanged. This is the
|
|
23
|
+
* equivalent of R's `...` forwarding.
|
|
24
|
+
*/
|
|
25
|
+
export interface InteractiveLogitOptions extends PlotLogitOptions {
|
|
26
|
+
/** Points to start from. R takes these as its `points` argument. */
|
|
27
|
+
readonly initialPoints?: readonly Point[];
|
|
28
|
+
/** What to run on `done()`. */
|
|
29
|
+
readonly onDone?: (points: readonly Point[]) => void;
|
|
30
|
+
}
|
|
31
|
+
/** What the caller holds after the component starts. */
|
|
32
|
+
export interface InteractiveLogitHandle {
|
|
33
|
+
/** Return the points collected so far, in click order. */
|
|
34
|
+
getPoints(): readonly Point[];
|
|
35
|
+
/** Drop every point and redraw. This drops the initial points too. */
|
|
36
|
+
reset(): void;
|
|
37
|
+
/** Hand the points to the `onDone` callback. */
|
|
38
|
+
done(): void;
|
|
39
|
+
/** Stop listening. The points stay readable. */
|
|
40
|
+
destroy(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Start an interactive logit on a target.
|
|
44
|
+
*
|
|
45
|
+
* The component draws at once, so an empty start shows empty axes. Each click
|
|
46
|
+
* inside the plot area adds one point and redraws. A click outside that area
|
|
47
|
+
* does nothing, because the world window ends at the edge of the area and a
|
|
48
|
+
* point beyond it would not appear.
|
|
49
|
+
*
|
|
50
|
+
* @param target A canvas, or a surface and an element. See `./target.ts`.
|
|
51
|
+
* @param options Points to start from, a done callback, and the options of
|
|
52
|
+
* `plotLogit`.
|
|
53
|
+
* @returns The handle to the running component.
|
|
54
|
+
* @throws Error If a canvas gives no 2D context.
|
|
55
|
+
*/
|
|
56
|
+
export declare function interactiveLogit(target: InteractiveTarget, options?: InteractiveLogitOptions): InteractiveLogitHandle;
|
|
57
|
+
//# sourceMappingURL=logit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logit.d.ts","sourceRoot":"","sources":["../../src/interactive/logit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,uBAAwB,SAAQ,gBAAgB;IAC/D,oEAAoE;IACpE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IAC1C,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,KAAK,IAAI,CAAC;CACtD;AAED,wDAAwD;AACxD,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,SAAS,IAAI,SAAS,KAAK,EAAE,CAAC;IAC9B,sEAAsE;IACtE,KAAK,IAAI,IAAI,CAAC;IACd,gDAAgD;IAChD,IAAI,IAAI,IAAI,CAAC;IACb,gDAAgD;IAChD,OAAO,IAAI,IAAI,CAAC;CACjB;AAYD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CAyExB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive matrix inverse: move the four sliders and watch the inverse
|
|
3
|
+
* answer.
|
|
4
|
+
*
|
|
5
|
+
* This is the port of `interactive_matrix_inverse()` in
|
|
6
|
+
* `../compstatslib/R/matrix_inverse_interactive.R`. R builds a miniUI gadget
|
|
7
|
+
* with four sliders, one for each entry of the matrix, and re-runs
|
|
8
|
+
* `plot_matrix_inverse()` whenever one moves. This module does the same: it
|
|
9
|
+
* owns the controls and the matrix in them, and hands every draw to
|
|
10
|
+
* `plotMatrixInverse`. It contains no drawing of the picture and no
|
|
11
|
+
* arithmetic.
|
|
12
|
+
*
|
|
13
|
+
* `plotMatrixInverse` takes no options, so there is nothing for this module to
|
|
14
|
+
* forward and the forwarding rule of CLAUDE.md is met by having nothing to
|
|
15
|
+
* pass. **A plot option added later must be threaded through here**, in the
|
|
16
|
+
* way `interactiveTTest` does it: pull the component's own fields out of the
|
|
17
|
+
* options object and pass the rest to the plot untouched.
|
|
18
|
+
*
|
|
19
|
+
* R's `runGadget()` blocks until "Done" and then returns nothing at all —
|
|
20
|
+
* `stopApp(NULL)`, from both Done and Cancel, and there is no Reset. Nothing
|
|
21
|
+
* blocks in a browser, so this returns a handle at once. `getValues()` reads
|
|
22
|
+
* the sliders and `getResult()` reads what was last drawn. `done()` reports
|
|
23
|
+
* the current matrix to the `onDone` callback: R hands back nothing, but a
|
|
24
|
+
* callback with no argument would only send the caller back to the handle for
|
|
25
|
+
* the values it just asked about.
|
|
26
|
+
*
|
|
27
|
+
* **The component draws one thing itself: the notice.** When the matrix has no
|
|
28
|
+
* inverse, `plotMatrixInverse` makes no drawing call at all, because R's
|
|
29
|
+
* `solve()` stops the R function before it draws. In R the user is not left
|
|
30
|
+
* looking at the last picture: shiny catches the error and prints it in the
|
|
31
|
+
* plot panel, which is not part of `plot_matrix_inverse`. So this module
|
|
32
|
+
* clears the surface and writes R's own message on it. That is the state of
|
|
33
|
+
* the gadget, reported to the user, and not a second way to draw a matrix.
|
|
34
|
+
*/
|
|
35
|
+
import type { Matrix2, MatrixInversion } from "../core/matrix";
|
|
36
|
+
import type { ControlTarget } from "./target";
|
|
37
|
+
/**
|
|
38
|
+
* Where the sliders start: R's `x1_init = 1, y1_init = 2, x2_init = 2,
|
|
39
|
+
* y2_init = 1`.
|
|
40
|
+
*
|
|
41
|
+
* The matrix inverts, and both of its columns and both columns of its inverse
|
|
42
|
+
* are inside the fixed window of the plot.
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_MATRIX_INVERSE_VALUES: Matrix2;
|
|
45
|
+
/**
|
|
46
|
+
* What the component accepts.
|
|
47
|
+
*
|
|
48
|
+
* The four entries are the starting positions of the sliders, named as R names
|
|
49
|
+
* the matrix. R calls its own arguments `x1_init` and so on, to keep them
|
|
50
|
+
* apart from the reactive inputs of the same name; an options object is
|
|
51
|
+
* already the starting state, so the suffix would say nothing here.
|
|
52
|
+
*
|
|
53
|
+
* A value outside the slider range, or one that misses its step, is corrected
|
|
54
|
+
* at construction. See `startingValue`.
|
|
55
|
+
*/
|
|
56
|
+
export interface InteractiveMatrixInverseOptions extends Partial<Matrix2> {
|
|
57
|
+
/** What to run on `done()`. */
|
|
58
|
+
readonly onDone?: (values: Matrix2) => void;
|
|
59
|
+
}
|
|
60
|
+
/** What the caller holds after the component starts. */
|
|
61
|
+
export interface InteractiveMatrixInverseHandle {
|
|
62
|
+
/** Return the matrix the sliders stand at now. */
|
|
63
|
+
getValues(): Matrix2;
|
|
64
|
+
/**
|
|
65
|
+
* Return what the last draw reported: the determinant, the inverse, and the
|
|
66
|
+
* singularity. The inverse is null exactly when the picture is a notice.
|
|
67
|
+
*/
|
|
68
|
+
getResult(): MatrixInversion;
|
|
69
|
+
/** Hand the current matrix to the `onDone` callback. */
|
|
70
|
+
done(): void;
|
|
71
|
+
/** Stop listening and take back the controls that were built. */
|
|
72
|
+
destroy(): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Start an interactive matrix inverse on a target.
|
|
76
|
+
*
|
|
77
|
+
* The component builds its controls, draws once, and redraws on every change.
|
|
78
|
+
*
|
|
79
|
+
* @param target A container element, or a surface and a controls host. See
|
|
80
|
+
* `./target.ts`.
|
|
81
|
+
* @param options Starting entries and a done callback.
|
|
82
|
+
* @returns The handle to the running component.
|
|
83
|
+
* @throws Error If the target is a canvas, or if a canvas gives no 2D context.
|
|
84
|
+
*/
|
|
85
|
+
export declare function interactiveMatrixInverse(target: ControlTarget, options?: InteractiveMatrixInverseOptions): InteractiveMatrixInverseHandle;
|
|
86
|
+
//# sourceMappingURL=matrixInverse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrixInverse.d.ts","sourceRoot":"","sources":["../../src/interactive/matrixInverse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAM/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,EAAE,OAK3C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,+BAAgC,SAAQ,OAAO,CAAC,OAAO,CAAC;IACvE,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C;AAED,wDAAwD;AACxD,MAAM,WAAW,8BAA8B;IAC7C,kDAAkD;IAClD,SAAS,IAAI,OAAO,CAAC;IACrB;;;OAGG;IACH,SAAS,IAAI,eAAe,CAAC;IAC7B,wDAAwD;IACxD,IAAI,IAAI,IAAI,CAAC;IACb,iEAAiE;IACjE,OAAO,IAAI,IAAI,CAAC;CACjB;AA8BD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,+BAAoC,GAC5C,8BAA8B,CAwFhC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive moderation surface: turn the wireframe and watch the twist
|
|
3
|
+
* of the interaction appear and disappear.
|
|
4
|
+
*
|
|
5
|
+
* This is the port of `interactive_moderation_3d()` in
|
|
6
|
+
* `../compstatslib/R/moderation_3d_interactive.R`. R builds a shiny gadget
|
|
7
|
+
* with two rotation sliders and re-runs `plot_moderation_3d()` whenever one
|
|
8
|
+
* moves. This module does the same: it owns the two sliders and hands every
|
|
9
|
+
* draw to `plotModeration3d`. It fits nothing and draws nothing itself.
|
|
10
|
+
*
|
|
11
|
+
* Three things are worth knowing before reading the code.
|
|
12
|
+
*
|
|
13
|
+
* **The sliders are kept, although a browser can drag the camera.** They are
|
|
14
|
+
* what R's help teaches with: "Try 0 to align the IV slope plane with the
|
|
15
|
+
* screen, or 270 to align the moderator slope plane." A free drag cannot name
|
|
16
|
+
* an angle, and those two angles are the lesson. Dragging still works, and
|
|
17
|
+
* the two live together: a drag is preserved until a slider asks for
|
|
18
|
+
* something else.
|
|
19
|
+
*
|
|
20
|
+
* **A slider must push the camera at the plot.** The plot layer sets a
|
|
21
|
+
* constant `uirevision`, which is what keeps a drag across a redraw. Plotly
|
|
22
|
+
* honours it literally: once the user has turned the plot, a later `react`
|
|
23
|
+
* carrying a different `scene.camera` is ignored, because the user's own edit
|
|
24
|
+
* wins. The sliders would then move nothing. So a rotation change is sent
|
|
25
|
+
* after the redraw as a `relayout`, which is an instruction rather than a
|
|
26
|
+
* preference. The alternative — changing the `uirevision` whenever a slider
|
|
27
|
+
* moves — would have to reach into the layout the plot layer owns, and would
|
|
28
|
+
* throw away the drag on every redraw whether or not the view changed.
|
|
29
|
+
* Nothing new is pushed when the rotations have not moved, so a redraw for
|
|
30
|
+
* any other reason leaves the user's own view alone. The one other push this
|
|
31
|
+
* component makes runs the opposite way: a camera the user drags to is
|
|
32
|
+
* written back into Plotly's stored layout (see `handleRelayout`), because
|
|
33
|
+
* the modebar's own buttons relayout the scene from that layout and would
|
|
34
|
+
* otherwise snap the view to the sliders' angles.
|
|
35
|
+
*
|
|
36
|
+
* **Done hands back the current view.** R returns `data`, which the caller
|
|
37
|
+
* already holds and which says nothing about the picture. The rotations do,
|
|
38
|
+
* and together with the model they reopen the same plot — the same choice the
|
|
39
|
+
* t-test component made for the same reason.
|
|
40
|
+
*
|
|
41
|
+
* There is no Reset: R has Done and Cancel only. There is no validation of
|
|
42
|
+
* the model here either. R's gadget opens and lets `plot_moderation_3d()`
|
|
43
|
+
* report a bad column in the plot pane; the port's equivalent is a rejected
|
|
44
|
+
* `rendered()`, so a caller that wants to hear about it must await.
|
|
45
|
+
*/
|
|
46
|
+
import type { DataFrame } from "../core/frame";
|
|
47
|
+
import type { ModerationOptions, ModerationSurface } from "../core/moderation";
|
|
48
|
+
import type { Moderation3dSpec, Moderation3dViewOptions, PlotModeration3dOptions } from "../plot/moderation3d";
|
|
49
|
+
import type { Plot3dTarget } from "./target";
|
|
50
|
+
/**
|
|
51
|
+
* Everything the panel holds: the two rotations, and the model behind the
|
|
52
|
+
* surface. Hand it back to `interactiveModeration3d` or to
|
|
53
|
+
* `plotModeration3d` to reopen the same picture.
|
|
54
|
+
*/
|
|
55
|
+
export interface Moderation3dValues extends ModerationOptions, Moderation3dViewOptions {
|
|
56
|
+
/** The turn about the vertical axis, in degrees. */
|
|
57
|
+
readonly zRot: number;
|
|
58
|
+
/** The tilt, in degrees. */
|
|
59
|
+
readonly xRot: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What the component accepts.
|
|
63
|
+
*
|
|
64
|
+
* Every option of `plotModeration3d` is a starting value, and anything the
|
|
65
|
+
* plot grows later reaches it untouched. The model itself — which column is
|
|
66
|
+
* the outcome, the IV and the moderator — is required, as it is by the plot.
|
|
67
|
+
*/
|
|
68
|
+
export interface InteractiveModeration3dOptions extends PlotModeration3dOptions {
|
|
69
|
+
/** What to run on `done()`. */
|
|
70
|
+
readonly onDone?: (values: Moderation3dValues) => void;
|
|
71
|
+
}
|
|
72
|
+
/** What the caller holds after the component starts. */
|
|
73
|
+
export interface InteractiveModeration3dHandle {
|
|
74
|
+
/** Return the rotations the sliders stand at, and the model being drawn. */
|
|
75
|
+
getValues(): Moderation3dValues;
|
|
76
|
+
/** Return the fit and the grid behind the last picture. */
|
|
77
|
+
getSurface(): ModerationSurface | null;
|
|
78
|
+
/** Return the traces, the layout, and the note of the last draw. */
|
|
79
|
+
getSpec(): Moderation3dSpec | null;
|
|
80
|
+
/** Wait for the drawing now in flight. Drawing is asynchronous. */
|
|
81
|
+
rendered(): Promise<void>;
|
|
82
|
+
/** Hand the current values to the `onDone` callback. */
|
|
83
|
+
done(): void;
|
|
84
|
+
/** Stop listening, purge the plot, and take back what was built. */
|
|
85
|
+
destroy(): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Start an interactive moderation surface on a target.
|
|
89
|
+
*
|
|
90
|
+
* The component builds its two sliders, draws once, and redraws on every
|
|
91
|
+
* change.
|
|
92
|
+
*
|
|
93
|
+
* @param target A container element, or a plot element and a controls host.
|
|
94
|
+
* See `./target.ts`.
|
|
95
|
+
* @param data The frame holding every column the model names.
|
|
96
|
+
* @param options The model, the starting rotations, a done callback, and the
|
|
97
|
+
* options of `plotModeration3d`.
|
|
98
|
+
* @returns The handle to the running component. Await `rendered()` for the
|
|
99
|
+
* first picture, and to hear about a model the data cannot carry.
|
|
100
|
+
* @throws Error If a canvas is passed as the container.
|
|
101
|
+
*/
|
|
102
|
+
export declare function interactiveModeration3d(target: Plot3dTarget, data: DataFrame, options: InteractiveModeration3dOptions): InteractiveModeration3dHandle;
|
|
103
|
+
//# sourceMappingURL=moderation3d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moderation3d.d.ts","sourceRoot":"","sources":["../../src/interactive/moderation3d.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAW9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;GAIG;AACH,MAAM,WAAW,kBACf,SAAQ,iBAAiB,EACvB,uBAAuB;IACzB,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,8BACf,SAAQ,uBAAuB;IAC/B,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACxD;AAED,wDAAwD;AACxD,MAAM,WAAW,6BAA6B;IAC5C,4EAA4E;IAC5E,SAAS,IAAI,kBAAkB,CAAC;IAChC,2DAA2D;IAC3D,UAAU,IAAI,iBAAiB,GAAG,IAAI,CAAC;IACvC,oEAAoE;IACpE,OAAO,IAAI,gBAAgB,GAAG,IAAI,CAAC;IACnC,mEAAmE;IACnE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,wDAAwD;IACxD,IAAI,IAAI,IAAI,CAAC;IACb,oEAAoE;IACpE,OAAO,IAAI,IAAI,CAAC;CACjB;AA4BD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,8BAA8B,GACtC,6BAA6B,CA6M/B"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive PCA: click to add a point, and watch the components turn.
|
|
3
|
+
*
|
|
4
|
+
* This is the port of `interactive_pca()` in
|
|
5
|
+
* `../compstatslib/R/pca_interactive.R`. R holds the points in a reactive
|
|
6
|
+
* value and calls `plot_pca()` on every change. This module does the same: it
|
|
7
|
+
* owns the points and the clicks, and it hands every draw to `plotPca`. It
|
|
8
|
+
* contains no drawing code and no statistics.
|
|
9
|
+
*
|
|
10
|
+
* R's `runGadget()` blocks and returns `list(points, pca)` when the user
|
|
11
|
+
* clicks "Done". A browser blocks at nothing, so this returns a handle at
|
|
12
|
+
* once. Read the two through `getPoints()` and `getFit()`, or call `done()` to
|
|
13
|
+
* hand both to the `onDone` callback.
|
|
14
|
+
*
|
|
15
|
+
* **A click is taken as it comes.** R appends `data.frame(x = click$x,
|
|
16
|
+
* y = click$y)` with no clamp, no rounding, and no test that the click landed
|
|
17
|
+
* inside the plot area — and shiny reports a coordinate for a click anywhere
|
|
18
|
+
* on the plot image, margins included. So this accepts a click anywhere on the
|
|
19
|
+
* surface and keeps the world coordinate whole. That is a deliberate
|
|
20
|
+
* difference from `interactiveRegression`, which ignores a click outside the
|
|
21
|
+
* plot area because its window ends there, and from `interactiveLogit`, which
|
|
22
|
+
* must clamp and round because its outcome is 0 or 1. Here a point outside the
|
|
23
|
+
* window is a real state, and the plot clips it out of sight while it goes on
|
|
24
|
+
* counting towards the components.
|
|
25
|
+
*/
|
|
26
|
+
import type { PcaResult } from "../core/pca";
|
|
27
|
+
import type { Point } from "../core/regression";
|
|
28
|
+
import type { PlotPcaOptions } from "../plot/pca";
|
|
29
|
+
import type { InteractiveTarget } from "./target";
|
|
30
|
+
/**
|
|
31
|
+
* What `done()` hands over: R's `list(points = ..., pca = ...)`.
|
|
32
|
+
*
|
|
33
|
+
* R's `pca` field is `fit` here. Inside a component that is already about
|
|
34
|
+
* PCA, a field called `pca` says nothing, and "the fit" is what this port
|
|
35
|
+
* calls the thing a plot computed from a set of points everywhere else —
|
|
36
|
+
* `plotRegression` and `plotLogit` both return one.
|
|
37
|
+
*/
|
|
38
|
+
export interface InteractivePcaResult {
|
|
39
|
+
/** The points collected, in click order. */
|
|
40
|
+
readonly points: readonly Point[];
|
|
41
|
+
/** What the last draw computed, or null below three points. */
|
|
42
|
+
readonly fit: PcaResult | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What the component accepts.
|
|
46
|
+
*
|
|
47
|
+
* The options of `plotPca` pass through to it unchanged. This is the
|
|
48
|
+
* equivalent of R's `...` forwarding, though R's own `interactive_pca()`
|
|
49
|
+
* exposes only `meancenter` and leaves the window at the `plot_pca` defaults.
|
|
50
|
+
*/
|
|
51
|
+
export interface InteractivePcaOptions extends PlotPcaOptions {
|
|
52
|
+
/** Points to start from. R starts from an empty data frame. */
|
|
53
|
+
readonly initialPoints?: readonly Point[];
|
|
54
|
+
/** What to run on `done()`. */
|
|
55
|
+
readonly onDone?: (result: InteractivePcaResult) => void;
|
|
56
|
+
}
|
|
57
|
+
/** What the caller holds after the component starts. */
|
|
58
|
+
export interface InteractivePcaHandle {
|
|
59
|
+
/** Return the points collected so far, in click order. */
|
|
60
|
+
getPoints(): readonly Point[];
|
|
61
|
+
/**
|
|
62
|
+
* Return what the last draw computed.
|
|
63
|
+
*
|
|
64
|
+
* Null below three points, which is `plot_pca`'s own guard: R's
|
|
65
|
+
* `pca_result` holds whatever the last `plot_pca()` returned, and that is
|
|
66
|
+
* NULL there too.
|
|
67
|
+
*/
|
|
68
|
+
getFit(): PcaResult | null;
|
|
69
|
+
/** Drop every point and redraw. This drops the initial points too. */
|
|
70
|
+
reset(): void;
|
|
71
|
+
/** Hand the points and the fit to the `onDone` callback. */
|
|
72
|
+
done(): void;
|
|
73
|
+
/** Stop listening. The points and the fit stay readable. */
|
|
74
|
+
destroy(): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Start an interactive PCA on a target.
|
|
78
|
+
*
|
|
79
|
+
* The component draws at once, so an empty start shows empty axes. Each click
|
|
80
|
+
* adds one point and redraws. From the third point the two component arrows
|
|
81
|
+
* appear and turn with every point after it.
|
|
82
|
+
*
|
|
83
|
+
* @param target A canvas, or a surface and an element. See `./target.ts`.
|
|
84
|
+
* @param options Points to start from, a done callback, and the options of
|
|
85
|
+
* `plotPca`.
|
|
86
|
+
* @returns The handle to the running component.
|
|
87
|
+
* @throws Error If a canvas gives no 2D context.
|
|
88
|
+
*/
|
|
89
|
+
export declare function interactivePca(target: InteractiveTarget, options?: InteractivePcaOptions): InteractivePcaHandle;
|
|
90
|
+
//# sourceMappingURL=pca.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pca.d.ts","sourceRoot":"","sources":["../../src/interactive/pca.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;CAChC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IAC1C,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC1D;AAED,wDAAwD;AACxD,MAAM,WAAW,oBAAoB;IACnC,0DAA0D;IAC1D,SAAS,IAAI,SAAS,KAAK,EAAE,CAAC;IAC9B;;;;;;OAMG;IACH,MAAM,IAAI,SAAS,GAAG,IAAI,CAAC;IAC3B,sEAAsE;IACtE,KAAK,IAAI,IAAI,CAAC;IACd,4DAA4D;IAC5D,IAAI,IAAI,IAAI,CAAC;IACb,4DAA4D;IAC5D,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,qBAA0B,GAClC,oBAAoB,CAyCtB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive regression: click to add a point, and watch the line move.
|
|
3
|
+
*
|
|
4
|
+
* This is the port of `interactive_regression()` in
|
|
5
|
+
* `../compstatslib/R/regression_interactive.R`. R holds the points in a
|
|
6
|
+
* reactive value and calls `plot_regression()` on every change, forwarding its `...`
|
|
7
|
+
* arguments. This module does the same: it owns the points and the clicks, and
|
|
8
|
+
* it hands every draw to `plotRegression`. It contains no drawing code and no
|
|
9
|
+
* statistics.
|
|
10
|
+
*
|
|
11
|
+
* R's `runGadget()` blocks and returns the points when the user clicks "Done".
|
|
12
|
+
* A browser blocks at nothing, so this returns a handle at once. Read the
|
|
13
|
+
* points from `getPoints()`, or call `done()` to hand them to the `onDone`
|
|
14
|
+
* callback.
|
|
15
|
+
*/
|
|
16
|
+
import type { Point } from "../core/regression";
|
|
17
|
+
import type { PlotRegressionOptions } from "../plot/regression";
|
|
18
|
+
import type { InteractiveTarget } from "./target";
|
|
19
|
+
/**
|
|
20
|
+
* What the component accepts.
|
|
21
|
+
*
|
|
22
|
+
* The options of `plotRegression` pass through to it unchanged. This is the
|
|
23
|
+
* equivalent of R's `...` forwarding.
|
|
24
|
+
*/
|
|
25
|
+
export interface InteractiveRegressionOptions extends PlotRegressionOptions {
|
|
26
|
+
/** Points to start from. R takes these as its `points` argument. */
|
|
27
|
+
readonly initialPoints?: readonly Point[];
|
|
28
|
+
/** What to run on `done()`. */
|
|
29
|
+
readonly onDone?: (points: readonly Point[]) => void;
|
|
30
|
+
}
|
|
31
|
+
/** What the caller holds after the component starts. */
|
|
32
|
+
export interface InteractiveRegressionHandle {
|
|
33
|
+
/** Return the points collected so far, in click order. */
|
|
34
|
+
getPoints(): readonly Point[];
|
|
35
|
+
/** Drop every point and redraw. This drops the initial points too. */
|
|
36
|
+
reset(): void;
|
|
37
|
+
/** Hand the points to the `onDone` callback. */
|
|
38
|
+
done(): void;
|
|
39
|
+
/** Stop listening. The points stay readable. */
|
|
40
|
+
destroy(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Start an interactive regression on a target.
|
|
44
|
+
*
|
|
45
|
+
* The component draws at once, so an empty start shows empty axes. Each click
|
|
46
|
+
* inside the plot area adds one point and redraws. A click outside the plot
|
|
47
|
+
* area does nothing, because the world window of the plot ends at the edge of
|
|
48
|
+
* that area and a point beyond it would not appear.
|
|
49
|
+
*
|
|
50
|
+
* @param target A canvas, or a surface and an element. See `./target.ts`.
|
|
51
|
+
* @param options Points to start from, a done callback, and the options of
|
|
52
|
+
* `plotRegression`.
|
|
53
|
+
* @returns The handle to the running component.
|
|
54
|
+
* @throws Error If a canvas gives no 2D context.
|
|
55
|
+
*/
|
|
56
|
+
export declare function interactiveRegression(target: InteractiveTarget, options?: InteractiveRegressionOptions): InteractiveRegressionHandle;
|
|
57
|
+
//# sourceMappingURL=regression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regression.d.ts","sourceRoot":"","sources":["../../src/interactive/regression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IACzE,oEAAoE;IACpE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IAC1C,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,KAAK,IAAI,CAAC;CACtD;AAED,wDAAwD;AACxD,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,SAAS,IAAI,SAAS,KAAK,EAAE,CAAC;IAC9B,sEAAsE;IACtE,KAAK,IAAI,IAAI,CAAC;IACd,gDAAgD;IAChD,IAAI,IAAI,IAAI,CAAC;IACb,gDAAgD;IAChD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,4BAAiC,GACzC,2BAA2B,CAuC7B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive sampling demonstration: press Sample and watch the
|
|
3
|
+
* distribution of the statistic fill in.
|
|
4
|
+
*
|
|
5
|
+
* This is the port of `interactive_sampling()` in
|
|
6
|
+
* `../compstatslib/R/sampling_interactive.R`. R builds a miniUI gadget with
|
|
7
|
+
* two selects and a button, and re-runs `plot_sampling()` when the button is
|
|
8
|
+
* pressed. This module does the same: it owns the controls, one generator, and
|
|
9
|
+
* the state that piles up between draws, and hands every draw to
|
|
10
|
+
* `plotSampling`. It contains no drawing code and no statistics.
|
|
11
|
+
*
|
|
12
|
+
* Three things set this gadget apart from the other three in the port:
|
|
13
|
+
*
|
|
14
|
+
* - **The button is the only thing that draws.** R wires the button to a
|
|
15
|
+
* trigger and isolates the selects (`shiny::isolate`), so moving a select
|
|
16
|
+
* changes what the *next* press will do and nothing more. A gadget that
|
|
17
|
+
* redrew on every change would resample ten thousand values each time a
|
|
18
|
+
* reader browsed the menu.
|
|
19
|
+
* - **It keeps drawing down one stream.** R reads one global generator, so
|
|
20
|
+
* each press carries on where the last stopped. One generator is built here
|
|
21
|
+
* when the component starts and used for every draw after.
|
|
22
|
+
* - **Done hands back the cache.** R's `stopApp(cache())` returns everything
|
|
23
|
+
* drawn so far; the t-test and logit gadgets return nothing at all.
|
|
24
|
+
*
|
|
25
|
+
* `reset()` has no counterpart in R, as in the other click-collectors. It
|
|
26
|
+
* empties the pile and redraws with no new samples, so the panels come back
|
|
27
|
+
* blank and the window is set again from the population.
|
|
28
|
+
*/
|
|
29
|
+
import type { PlotSamplingOptions, SamplingState } from "../plot/sampling";
|
|
30
|
+
import type { ControlTarget } from "./target";
|
|
31
|
+
/** Everything the panel of controls holds. */
|
|
32
|
+
export interface SamplingValues {
|
|
33
|
+
/** How many values each sample takes. R's `sample_size` select. */
|
|
34
|
+
readonly sampleSize: number;
|
|
35
|
+
/** How many samples the next press draws. R's `reps` select. */
|
|
36
|
+
readonly reps: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What the component accepts.
|
|
40
|
+
*
|
|
41
|
+
* The options of `plotSampling` pass through to it, and the sample size and
|
|
42
|
+
* repetition count double as the starting positions of the two selects. This
|
|
43
|
+
* is the equivalent of R's `...` forwarding.
|
|
44
|
+
*/
|
|
45
|
+
export interface InteractiveSamplingOptions extends PlotSamplingOptions {
|
|
46
|
+
/** What to run on `done()`. */
|
|
47
|
+
readonly onDone?: (state: SamplingState) => void;
|
|
48
|
+
}
|
|
49
|
+
/** What the caller holds after the component starts. */
|
|
50
|
+
export interface InteractiveSamplingHandle {
|
|
51
|
+
/** Return where the two selects stand now. */
|
|
52
|
+
getValues(): SamplingValues;
|
|
53
|
+
/** Return everything drawn so far — R's gadget cache. */
|
|
54
|
+
getState(): SamplingState;
|
|
55
|
+
/** Empty the pile and redraw with no samples. */
|
|
56
|
+
reset(): void;
|
|
57
|
+
/** Hand the accumulated state to the `onDone` callback. */
|
|
58
|
+
done(): void;
|
|
59
|
+
/** Stop listening and take back the controls that were built. */
|
|
60
|
+
destroy(): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Start an interactive sampling demonstration on a target.
|
|
64
|
+
*
|
|
65
|
+
* The component builds its controls, draws once, and redraws on every press
|
|
66
|
+
* of its button.
|
|
67
|
+
*
|
|
68
|
+
* @param target A container element, or a surface and a controls host. See
|
|
69
|
+
* `./target.ts`.
|
|
70
|
+
* @param population The values to sample from.
|
|
71
|
+
* @param options Starting values, a done callback, and the options of
|
|
72
|
+
* `plotSampling`.
|
|
73
|
+
* @returns The handle to the running component.
|
|
74
|
+
* @throws Error If a canvas is passed as the container, or gives no 2D
|
|
75
|
+
* context.
|
|
76
|
+
*/
|
|
77
|
+
export declare function interactiveSampling(target: ControlTarget, population: readonly number[], options?: InteractiveSamplingOptions): InteractiveSamplingHandle;
|
|
78
|
+
//# sourceMappingURL=sampling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampling.d.ts","sourceRoot":"","sources":["../../src/interactive/sampling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,OAAO,KAAK,EACV,mBAAmB,EAEnB,aAAa,EACd,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,8CAA8C;AAC9C,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACrE,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAClD;AAED,wDAAwD;AACxD,MAAM,WAAW,yBAAyB;IACxC,8CAA8C;IAC9C,SAAS,IAAI,cAAc,CAAC;IAC5B,yDAAyD;IACzD,QAAQ,IAAI,aAAa,CAAC;IAC1B,iDAAiD;IACjD,KAAK,IAAI,IAAI,CAAC;IACd,2DAA2D;IAC3D,IAAI,IAAI,IAAI,CAAC;IACb,iEAAiE;IACjE,OAAO,IAAI,IAAI,CAAC;CACjB;AAaD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,GAAE,0BAA+B,GACvC,yBAAyB,CAmH3B"}
|