flocc 0.5.18 → 0.5.21
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/dist/agents/Agent.d.ts +170 -33
- package/dist/environments/Environment.d.ts +133 -37
- package/dist/environments/GridEnvironment.d.ts +20 -6
- package/dist/flocc.es.js +1489 -488
- package/dist/flocc.js +1489 -488
- package/dist/helpers/KDTree.d.ts +2 -2
- package/dist/helpers/Network.d.ts +143 -67
- package/dist/helpers/NumArray.d.ts +1 -0
- package/dist/helpers/Rule.d.ts +58 -0
- package/dist/helpers/Terrain.d.ts +134 -27
- package/dist/helpers/Vector.d.ts +151 -22
- package/dist/renderers/ASCIIRenderer.d.ts +32 -3
- package/dist/renderers/AbstractRenderer.d.ts +17 -2
- package/dist/renderers/CanvasRenderer.d.ts +55 -0
- package/dist/renderers/Heatmap.d.ts +51 -6
- package/dist/renderers/TableRenderer.d.ts +94 -2
- package/dist/types/HeatmapAxis.d.ts +10 -0
- package/dist/utils/clamp.d.ts +9 -5
- package/dist/utils/distance.d.ts +15 -6
- package/dist/utils/gaussian.d.ts +9 -3
- package/dist/utils/gcd.d.ts +8 -0
- package/dist/utils/internal/copyArray.d.ts +1 -1
- package/dist/utils/lerp.d.ts +13 -4
- package/dist/utils/manhattanDistance.d.ts +15 -7
- package/dist/utils/max.d.ts +9 -0
- package/dist/utils/mean.d.ts +9 -3
- package/dist/utils/median.d.ts +10 -2
- package/dist/utils/min.d.ts +8 -0
- package/dist/utils/sample.d.ts +2 -0
- package/dist/version.d.ts +3 -0
- package/package.json +7 -3
- package/dist/helpers/Data.d.ts +0 -5
- package/dist/utils/internal/torusNormalize.d.ts +0 -1
package/dist/helpers/Vector.d.ts
CHANGED
|
@@ -1,54 +1,157 @@
|
|
|
1
1
|
/// <reference path="../src/types/Point.d.ts" />
|
|
2
2
|
/**
|
|
3
|
+
* A `Vector` contains multi-dimensional numeric data.
|
|
4
|
+
*
|
|
3
5
|
* @since 0.1.0
|
|
4
6
|
*/
|
|
5
7
|
declare class Vector implements Point {
|
|
6
8
|
data: Array<number>;
|
|
9
|
+
/**
|
|
10
|
+
* The dimension of this `Vector`, or the last index that has a value (plus one).
|
|
11
|
+
*
|
|
12
|
+
* ```js
|
|
13
|
+
* const a = new Vector(1, 1, 1);
|
|
14
|
+
* a.dimension; // 3
|
|
15
|
+
*
|
|
16
|
+
* const b = new Vector(1, 2, 3, 4, 5);
|
|
17
|
+
* b.dimension; // 5
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Dimensions can be dynamically updated after a `Vector` is created:
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* const v = new Vector(0);
|
|
24
|
+
* v.dimension; // 1
|
|
25
|
+
*
|
|
26
|
+
* v.set(3, 10);
|
|
27
|
+
* v.dimension; // 4 (indices start at 0)
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* */
|
|
7
31
|
dimension: number;
|
|
8
32
|
constructor(...data: Array<number>);
|
|
9
33
|
/**
|
|
34
|
+
* Retrieve a value from a `Vector` by its index. If the given index is greater than the
|
|
35
|
+
* `Vector`'s dimension, this returns `0` by default.
|
|
36
|
+
*
|
|
37
|
+
* ```js
|
|
38
|
+
* const v = new Vector(1, 2, 4);
|
|
39
|
+
*
|
|
40
|
+
* v.index(0); // returns 1
|
|
41
|
+
* v.index(2); // returns 4
|
|
42
|
+
* v.index(5); // returns 0
|
|
43
|
+
* ```
|
|
10
44
|
* @since 0.1.0
|
|
11
45
|
*/
|
|
12
|
-
index(
|
|
46
|
+
index(i: number): number;
|
|
13
47
|
/**
|
|
14
|
-
*
|
|
15
|
-
* the dimension will be increased to the dimensionality implied by the index.
|
|
16
|
-
* @param i
|
|
17
|
-
* @param value
|
|
48
|
+
* Set the value at a given index. If the index is greater than the {@linkcode dimension}
|
|
49
|
+
* of this `Vector`, the dimension will be increased to the dimensionality implied by the index.
|
|
50
|
+
* @param i The numerical index (0-based) or lowercase string value (e.g. `"x"`) to set.
|
|
51
|
+
* @param value The value to set at this index/position.
|
|
52
|
+
*
|
|
53
|
+
* ```js
|
|
54
|
+
* const vector = new Vector();
|
|
55
|
+
* vector.set(0, 10);
|
|
56
|
+
* vector.set('y', 2);
|
|
57
|
+
* vector.set(2, 4);
|
|
58
|
+
*
|
|
59
|
+
* vector.xyz; // [10, 2, 4]
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
18
62
|
* @since 0.1.0
|
|
19
63
|
*/
|
|
20
|
-
set(i: number |
|
|
64
|
+
set(i: number | "x" | "y" | "z" | "w" | "r" | "g" | "b" | "a", value: number): this;
|
|
65
|
+
/** @since 0.1.0 */
|
|
21
66
|
get x(): number;
|
|
67
|
+
/** @since 0.1.0 */
|
|
22
68
|
get y(): number;
|
|
69
|
+
/** @since 0.1.0 */
|
|
23
70
|
get z(): number;
|
|
71
|
+
/** @since 0.1.0 */
|
|
24
72
|
get w(): number;
|
|
25
|
-
|
|
26
|
-
get
|
|
27
|
-
|
|
28
|
-
get
|
|
73
|
+
/** @since 0.2.4 */
|
|
74
|
+
get xy(): [number, number];
|
|
75
|
+
/** @since 0.2.4 */
|
|
76
|
+
get xz(): [number, number];
|
|
77
|
+
/** @since 0.2.4 */
|
|
78
|
+
get yz(): [number, number];
|
|
79
|
+
/** @since 0.2.4 */
|
|
80
|
+
get xyz(): [number, number, number];
|
|
81
|
+
/**
|
|
82
|
+
* `r` for 'red' (the 1st value)
|
|
83
|
+
* @since 0.1.0
|
|
84
|
+
*/
|
|
29
85
|
get r(): number;
|
|
86
|
+
/**
|
|
87
|
+
* `g` for 'green' (the 2nd value)
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
30
90
|
get g(): number;
|
|
91
|
+
/**
|
|
92
|
+
* `b` for 'blue' (the 3rd value)
|
|
93
|
+
* @since 0.1.0
|
|
94
|
+
*/
|
|
31
95
|
get b(): number;
|
|
96
|
+
/**
|
|
97
|
+
* `a` for 'alpha' (the 4th value)
|
|
98
|
+
* @since 0.1.0
|
|
99
|
+
*/
|
|
32
100
|
get a(): number;
|
|
33
|
-
|
|
34
|
-
get
|
|
101
|
+
/** @since 0.2.4 */
|
|
102
|
+
get rgb(): [number, number, number];
|
|
103
|
+
/** @since 0.2.4 */
|
|
104
|
+
get rgba(): [number, number, number, number];
|
|
105
|
+
/** @since 0.1.0 */
|
|
35
106
|
set x(n: number);
|
|
107
|
+
/** @since 0.1.0 */
|
|
36
108
|
set y(n: number);
|
|
109
|
+
/** @since 0.1.0 */
|
|
37
110
|
set z(n: number);
|
|
111
|
+
/** @since 0.1.0 */
|
|
38
112
|
set w(n: number);
|
|
113
|
+
/**
|
|
114
|
+
* `r` for 'red' (the 1st value)
|
|
115
|
+
* @since 0.1.0
|
|
116
|
+
*/
|
|
39
117
|
set r(n: number);
|
|
118
|
+
/**
|
|
119
|
+
* `g` for 'green' (the 2nd value)
|
|
120
|
+
* @since 0.1.0
|
|
121
|
+
*/
|
|
40
122
|
set g(n: number);
|
|
123
|
+
/**
|
|
124
|
+
* `b` for 'blue' (the 3rd value)
|
|
125
|
+
* @since 0.1.0
|
|
126
|
+
*/
|
|
41
127
|
set b(n: number);
|
|
128
|
+
/**
|
|
129
|
+
* `a` for 'alpha' (the 4th value)
|
|
130
|
+
* @since 0.1.0
|
|
131
|
+
*/
|
|
42
132
|
set a(n: number);
|
|
43
133
|
/**
|
|
134
|
+
* Add another `Vector` to this `Vector`. This *does* mutate the `Vector` that calls this method.
|
|
44
135
|
* @since 0.1.0
|
|
45
136
|
*/
|
|
46
137
|
add(v: Vector): this;
|
|
47
138
|
/**
|
|
139
|
+
* Multiply this `Vector` by a scalar number. This *does* mutate the `Vector` that calls this method.
|
|
140
|
+
*
|
|
141
|
+
* ```js
|
|
142
|
+
* const v = new Vector(1, 2);
|
|
143
|
+
* v.multiplyScalar(5);
|
|
144
|
+
* v.xy; // returns [5, 10]
|
|
145
|
+
*
|
|
146
|
+
* v.multiplyScalar(-0.5);
|
|
147
|
+
* v.xy; // returns [-2.5, -5]
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
48
150
|
* @since 0.1.0
|
|
49
151
|
*/
|
|
50
152
|
multiplyScalar(n: number): this;
|
|
51
153
|
/**
|
|
154
|
+
* Add a scalar number to all of this `Vector`'s values'. This *does* mutate the `Vector` that calls this method.
|
|
52
155
|
* @since 0.1.0
|
|
53
156
|
*/
|
|
54
157
|
addScalar(n: number): this;
|
|
@@ -58,32 +161,58 @@ declare class Vector implements Point {
|
|
|
58
161
|
*/
|
|
59
162
|
length(): number;
|
|
60
163
|
/**
|
|
61
|
-
* Normalize the
|
|
62
|
-
*
|
|
164
|
+
* Normalize the `Vector` (turn it into a `Vector` with length = `1`). Has no effect on the 0 `Vector`. This *does* mutate the `Vector` that calls this method.
|
|
165
|
+
*
|
|
166
|
+
* ```js
|
|
167
|
+
* const v = new Vector(5, 3, -1);
|
|
168
|
+
* v.normalize();
|
|
169
|
+
* v.length(); // returns 1
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
63
172
|
* @since 0.1.0
|
|
64
173
|
*/
|
|
65
174
|
normalize(): this;
|
|
66
175
|
/**
|
|
176
|
+
* Create a copy of this `Vector`.
|
|
67
177
|
* @since 0.1.0
|
|
68
178
|
*/
|
|
69
179
|
clone(): Vector;
|
|
70
180
|
/**
|
|
71
|
-
* Rotate
|
|
72
|
-
*
|
|
181
|
+
* Rotate the `Vector` about the z-axis by `angle` radians (updating its `x` and `y` values). This *does* mutate the `Vector` that calls this method.
|
|
182
|
+
*
|
|
183
|
+
* ```js
|
|
184
|
+
* const v = new Vector(1, 0);
|
|
185
|
+
* v.rotateZ(Math.PI / 2); // rotate by PI / 2 radians = 90 degrees
|
|
186
|
+
*
|
|
187
|
+
* v.xy; // returns [0, 1]
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
73
190
|
* @since 0.2.2
|
|
74
191
|
*/
|
|
75
192
|
rotateZ(angle: number): this;
|
|
76
193
|
/**
|
|
77
|
-
* Get the dot product of this
|
|
78
|
-
* @
|
|
194
|
+
* Get the {@link https://en.wikipedia.org/wiki/Dot_product | dot product} of this `Vector` with another.
|
|
195
|
+
* @since 0.2.4
|
|
79
196
|
*/
|
|
80
197
|
dot(v: Vector): number;
|
|
81
198
|
/**
|
|
82
|
-
* Linearly interpolate between this
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
199
|
+
* Linearly interpolate between this `Vector` and another `Vector`. This *does not* mutate the original `Vector` that calls this method, but returns a new `Vector`.
|
|
200
|
+
*
|
|
201
|
+
* ```js
|
|
202
|
+
* const a = new Vector(1, 3, -5);
|
|
203
|
+
* const b = new Vector(4, -2);
|
|
204
|
+
*
|
|
205
|
+
* a.lerp(b, 0); // returns a clone of Vector a
|
|
206
|
+
* a.lerp(b, 1); // returns a clone of Vector b
|
|
207
|
+
*
|
|
208
|
+
* const mid = a.lerp(b, 0.5); // returns a Vector halfway between a and b
|
|
209
|
+
* mid.xyz; // returns [2.5, 0.5, -2.5]
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @param v - The other vector.
|
|
213
|
+
* @param t - The amount by which to interpolate (usually between `0` and `1`, although it can be any number).
|
|
86
214
|
* @returns {Vector} - The new, interpolated vector.
|
|
215
|
+
* @since 0.2.4
|
|
87
216
|
*/
|
|
88
217
|
lerp(v: Vector, t: number): Vector;
|
|
89
218
|
}
|
|
@@ -1,15 +1,44 @@
|
|
|
1
1
|
import { GridEnvironment } from "../environments/GridEnvironment";
|
|
2
2
|
import { AbstractRenderer } from "./AbstractRenderer";
|
|
3
3
|
/**
|
|
4
|
+
* An `ASCIIRenderer` renders the {@link Agent | `Agent`}s in
|
|
5
|
+
* a {@linkcode GridEnvironment}. `Agent`s are rendered
|
|
6
|
+
* using their `"value"` data (a single character).
|
|
7
|
+
* Since v0.4.0, this class has been **deprecated**, and it will be removed
|
|
8
|
+
* entirely in v0.6.0.
|
|
9
|
+
* ```js
|
|
10
|
+
* const renderer = new ASCIIRenderer(grid);
|
|
11
|
+
* renderer.mount("#container-id");
|
|
12
|
+
* ```
|
|
13
|
+
* @deprecated since 0.4.0
|
|
4
14
|
* @since 0.0.10
|
|
5
15
|
*/
|
|
6
16
|
declare class ASCIIRenderer extends AbstractRenderer {
|
|
7
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* @hidden
|
|
19
|
+
* @override
|
|
20
|
+
*/
|
|
21
|
+
width: null;
|
|
22
|
+
/**
|
|
23
|
+
* @hidden
|
|
24
|
+
* @override
|
|
25
|
+
*/
|
|
26
|
+
height: null;
|
|
27
|
+
/**
|
|
28
|
+
* Points to the {@linkcode GridEnvironment} that this
|
|
29
|
+
* `ASCIIRenderer` is tied to. This is automatically set when the
|
|
30
|
+
* `ASCIIRenderer` is created.
|
|
31
|
+
*/
|
|
8
32
|
environment: GridEnvironment;
|
|
9
|
-
/** @
|
|
33
|
+
/** @hidden */
|
|
10
34
|
pre: HTMLPreElement;
|
|
11
|
-
constructor(environment: GridEnvironment, opts?: Object);
|
|
12
35
|
/**
|
|
36
|
+
* Create a new `ASCIIRenderer` by passing in the
|
|
37
|
+
* {@linkcode GridEnvironment} you want to be rendered.
|
|
38
|
+
*/
|
|
39
|
+
constructor(environment: GridEnvironment);
|
|
40
|
+
/**
|
|
41
|
+
* Renders the contents of the `ASCIIRenderer`'s {@linkcode GridEnvironment}.
|
|
13
42
|
* @since 0.0.10
|
|
14
43
|
*/
|
|
15
44
|
render(): void;
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import type { Environment } from "../environments/Environment";
|
|
2
2
|
declare class AbstractRenderer {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Points to the {@linkcode Environment} that this
|
|
5
|
+
* renderer is tied to. This is automatically set when the
|
|
6
|
+
* renderer is created.
|
|
7
|
+
*/
|
|
4
8
|
environment: Environment;
|
|
9
|
+
/** @hidden */
|
|
5
10
|
canvas: HTMLCanvasElement;
|
|
11
|
+
/** @hidden */
|
|
6
12
|
context: CanvasRenderingContext2D;
|
|
7
13
|
width: number;
|
|
8
14
|
height: number;
|
|
9
15
|
render(): void;
|
|
10
16
|
/**
|
|
11
17
|
* Mount this renderer to a DOM element. Pass either a string representing a
|
|
12
|
-
* CSS selector matching the element
|
|
18
|
+
* CSS selector matching the element or the element itself.
|
|
19
|
+
*
|
|
20
|
+
* ```js
|
|
21
|
+
* // mounts the renderer to the element with the ID `container`
|
|
22
|
+
* renderer.mount('#container');
|
|
23
|
+
*
|
|
24
|
+
* // mounts the renderer to the element itself
|
|
25
|
+
* const container = document.getElementById('container');
|
|
26
|
+
* renderer.mount(container);
|
|
27
|
+
* ```
|
|
13
28
|
* @param {string | HTMLElement} el
|
|
14
29
|
*/
|
|
15
30
|
mount(el: string | HTMLElement): void;
|
|
@@ -2,16 +2,71 @@
|
|
|
2
2
|
import { AbstractRenderer } from "./AbstractRenderer";
|
|
3
3
|
import type { Environment } from "../environments/Environment";
|
|
4
4
|
/**
|
|
5
|
+
* A `CanvasRenderer` renders an {@linkcode Environment} spatially in two dimensions.
|
|
6
|
+
* Importantly, it expects that all {@linkcode Agent}s in the `Environment`
|
|
7
|
+
* have numeric `"x"` and `"y"` values associated with them.
|
|
8
|
+
*
|
|
9
|
+
* `CanvasRenderer`s will render all `Agent`s that are visible in the rendered `Environment` space,
|
|
10
|
+
* with the color of their `"color"` value (defaulting to black).
|
|
11
|
+
* Depending on the `"shape"` of the `Agent`, additional data might be needed. `Agent` `"shape"`s can be:
|
|
12
|
+
* - `"circle"` (default) — Draws a circle centered at the `Agent`'s `"x"` / `"y"` values.
|
|
13
|
+
* - If the `Agent` has a `"size"` value, uses that for the circle radius (defaults to 1px).
|
|
14
|
+
* - `"arrow"` — Draws an arrow centered at the `Agent`'s `"x"` / `"y"` values.
|
|
15
|
+
* - The arrow will point in the direction of the `Agent`s `"vx"` / `"vy"` values. For example, an `Agent` with `"vx" = 1` and `"vy" = 0` will be rendered as an arrow pointing to the right.
|
|
16
|
+
* - Also uses the `"size" value.
|
|
17
|
+
* - `"rect"` — Draws a rectangle with the upper-left corner at `"x"` / `"y"`.
|
|
18
|
+
* - Uses the `Agent`'s `"width"` and `"height"` values for the dimensions of the rectangle.
|
|
19
|
+
* - `"triangle"` — Draws a triangle centered at the `Agent`'s `"x"` / `"y"` values.
|
|
20
|
+
* - Also uses the `"size"` value.
|
|
21
|
+
*
|
|
5
22
|
* @since 0.0.11
|
|
6
23
|
*/
|
|
7
24
|
declare class CanvasRenderer extends AbstractRenderer {
|
|
25
|
+
/** @hidden */
|
|
8
26
|
opts: CanvasRendererOptions;
|
|
27
|
+
/** @hidden */
|
|
9
28
|
buffer: HTMLCanvasElement;
|
|
29
|
+
/** @hidden */
|
|
10
30
|
terrainBuffer: HTMLCanvasElement;
|
|
31
|
+
/**
|
|
32
|
+
* The first parameter must be the {@linkcode Environment} that this
|
|
33
|
+
* `CanvasRenderer` will render.
|
|
34
|
+
*
|
|
35
|
+
* The second parameter specifies options, which can include:
|
|
36
|
+
* - `autoPosition` (*boolean* = `false`) — For `Environment`s using a {@linkcode Network}, whether to automatically position the `Agent`s.
|
|
37
|
+
* - `background` (*string* = `"transparent"`) — The background color to draw before rendering any `Agent`s.
|
|
38
|
+
* - `connectionColor` (*string* = `"black"`) — For `Environment`s using a `Network`, the color of lines
|
|
39
|
+
* - `connectionOpacity` (*number* = `1`) — For `Environment`s using a `Network`, the opacity of lines
|
|
40
|
+
* - `connectionWidth` (*number* = `1`) — For `Environment`s using a `Network`, the width of lines
|
|
41
|
+
* - `height` (*number* = `500`) — The height, in pixels, of the canvas on which to render
|
|
42
|
+
* - `origin` (*{ x: number; y: number }* = `{ x: 0, y: 0 }`) — The coordinate of the upper-left point of the space to be rendered
|
|
43
|
+
* - `scale` (*number* = `1`) — The scale at which to render (the larger the scale, the smaller the size of the space that is actually rendered)
|
|
44
|
+
* - `trace` (*boolean* = `false`) — If `true`, the renderer will not clear old drawings, causing the `Agent`s to appear to *trace* their paths across space
|
|
45
|
+
* - `width` (*number* = `500`) — The width, in pixels, of the canvas on which to render
|
|
46
|
+
*/
|
|
11
47
|
constructor(environment: Environment, opts: CanvasRendererOptions);
|
|
48
|
+
/** @hidden */
|
|
12
49
|
x(v: number): number;
|
|
50
|
+
/** @hidden */
|
|
13
51
|
y(v: number): number;
|
|
52
|
+
/** @hidden */
|
|
14
53
|
createCanvas(): HTMLCanvasElement;
|
|
54
|
+
/** @hidden */
|
|
55
|
+
drawPath(points: [number, number][], dx?: number, dy?: number): void;
|
|
56
|
+
/** @hidden */
|
|
57
|
+
drawPathWrap(points: [number, number][]): void;
|
|
58
|
+
/** @hidden */
|
|
59
|
+
drawCircle(x: number, y: number, r: number): void;
|
|
60
|
+
/** @hidden */
|
|
61
|
+
drawCircleWrap(x: number, y: number, size: number): void;
|
|
62
|
+
/**
|
|
63
|
+
* Draw a rectangle centered at (x, y). Automatically calculates the offset
|
|
64
|
+
* for both width and height.
|
|
65
|
+
* @hidden
|
|
66
|
+
*/
|
|
67
|
+
drawRect(x: number, y: number, width: number, height: number): void;
|
|
68
|
+
/** @hidden */
|
|
69
|
+
drawRectWrap(x: number, y: number, w: number, h: number): void;
|
|
15
70
|
render(): void;
|
|
16
71
|
}
|
|
17
72
|
export { CanvasRenderer };
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
/// <reference path="../src/types/NRange.d.ts" />
|
|
3
3
|
import { AbstractRenderer } from "./AbstractRenderer";
|
|
4
4
|
import type { Environment } from "../environments/Environment";
|
|
5
|
-
|
|
6
|
-
buckets: number;
|
|
7
|
-
key: string;
|
|
8
|
-
}
|
|
5
|
+
import type HeatmapAxis from "../types/HeatmapAxis";
|
|
9
6
|
interface HeatmapOptions {
|
|
10
7
|
x: string | HeatmapAxis;
|
|
11
8
|
y: string | HeatmapAxis;
|
|
@@ -17,34 +14,82 @@ interface HeatmapOptions {
|
|
|
17
14
|
scale: "relative" | "fixed";
|
|
18
15
|
}
|
|
19
16
|
/**
|
|
17
|
+
* A `Heatmap` can be used to visualize the distribution of {@linkcode Agent}s across two metrics.
|
|
18
|
+
* While {@linkcode Histogram}s are useful for showing the distribution of `Agent`s along a single metric
|
|
19
|
+
* (or on multiple metrics using the same scale), a `Heatmap` can show how two metrics relate to one another —
|
|
20
|
+
* correlation, inverse correlation, in a nonlinear manner, randomly (no correlation), etc.
|
|
21
|
+
*
|
|
22
|
+
* <img src="https://cms.flocc.network/wp-content/uploads/2020/11/heatmap-basic.png" />
|
|
23
|
+
*
|
|
24
|
+
* Note above that, although the output appears similar to what a {@linkcode CanvasRenderer} might output, the `y` axis is reversed here — low values are at the bottom and high at the top, whereas on a `CanvasRenderer` high values are at the bottom and low at the top.
|
|
25
|
+
*
|
|
20
26
|
* @since 0.5.8
|
|
21
27
|
*/
|
|
22
28
|
declare class Heatmap extends AbstractRenderer {
|
|
29
|
+
/** @hidden */
|
|
23
30
|
opts: HeatmapOptions;
|
|
24
31
|
width: number;
|
|
25
32
|
height: number;
|
|
33
|
+
/** @hidden */
|
|
26
34
|
buckets: number[];
|
|
35
|
+
/** @hidden */
|
|
27
36
|
localMax: number;
|
|
37
|
+
/** @hidden */
|
|
28
38
|
lastUpdatedScale: Date;
|
|
39
|
+
/**
|
|
40
|
+
* The first parameter must be the {@linkcode Environment} that this
|
|
41
|
+
* `Heatmap` will render.
|
|
42
|
+
*
|
|
43
|
+
* The second parameter specifies options, which can include:
|
|
44
|
+
* - `from` (*string* = `"white"`) — The color (name, hex value, or RGB) to draw when a cell contains `0` {@linkcode Agent}s
|
|
45
|
+
* - `to` (*string* = `"black"`) — The color (name, hex value, or RGB) to draw when a cell contains the highest number of `Agent`s
|
|
46
|
+
* - `x` and `y` can be either:
|
|
47
|
+
* - *string* = `"x"`/`"y"` respectively — The name of `Agent` data to measure along the `x`/`y` axis
|
|
48
|
+
* - *{ buckets: number; key: string; min: number; max: number }* = `{ buckets: 10, key: 'x' | 'y', min: 0, max: 1 }` — Include the number of buckets to divide the range `min → max` into, along with the name of `Agent` data
|
|
49
|
+
* - `width` (*number* = `500`) — The width, in pixels, of the canvas on which to render
|
|
50
|
+
* - `height` (*number* = `500`) — The height, in pixels, of the canvas on which to render
|
|
51
|
+
* - `scale` (either `"relative"` or `"fixed"`, defaults to `"relative"`)
|
|
52
|
+
* - `"relative"` — The maximum number of `Agent`s in any single cell is automatically used as the highest value in the scale. This updates over time based on `Agent` distribution.
|
|
53
|
+
* - `"fixed"` — You supply the number to use as the maximum value (see `max` below).
|
|
54
|
+
* - `max` (optional, *number*) — If you use `scale = "fixed"`, then setting a `max` will cause cells with that number (or higher) of `Agent`s to be drawn using the `to` color.
|
|
55
|
+
*
|
|
56
|
+
* ```js
|
|
57
|
+
* // plots the correlation between age of agents (on the x-axis)
|
|
58
|
+
* // vs. their wealth (on the y-axis)
|
|
59
|
+
* const heatmap = new Heatmap(environment, {
|
|
60
|
+
* x: 'age',
|
|
61
|
+
* y: 'wealth'
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
29
65
|
constructor(environment: Environment, opts?: HeatmapOptions);
|
|
30
66
|
/**
|
|
31
67
|
* Map a value (on the range x-min to x-max) onto canvas space to draw it along the x-axis.
|
|
32
|
-
* @
|
|
68
|
+
* @hidden
|
|
33
69
|
*/
|
|
34
70
|
x(value: number): number;
|
|
35
71
|
/**
|
|
36
72
|
* Map a value (on the range y-min to y-max) onto canvas space to draw it along the y-axis.
|
|
37
|
-
* @
|
|
73
|
+
* @hidden
|
|
38
74
|
*/
|
|
39
75
|
y(value: number): number;
|
|
76
|
+
/** @hidden */
|
|
40
77
|
getKey(axis: "x" | "y"): string;
|
|
78
|
+
/** @hidden */
|
|
41
79
|
getBuckets(axis: "x" | "y"): number;
|
|
80
|
+
/** @hidden */
|
|
42
81
|
getMin(axis: "x" | "y"): number;
|
|
82
|
+
/** @hidden */
|
|
43
83
|
getMax(axis: "x" | "y"): number;
|
|
84
|
+
/** @hidden */
|
|
44
85
|
drawMarkers(): void;
|
|
86
|
+
/** @hidden */
|
|
45
87
|
updateScale(): void;
|
|
88
|
+
/** @hidden */
|
|
46
89
|
drawRectangles(): void;
|
|
90
|
+
/** @hidden */
|
|
47
91
|
resetBuckets(): void;
|
|
92
|
+
/** @hidden */
|
|
48
93
|
updateBuckets(): void;
|
|
49
94
|
render(): void;
|
|
50
95
|
}
|
|
@@ -12,27 +12,119 @@ interface TableRendererOptions {
|
|
|
12
12
|
type?: "csv" | "table";
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
+
* A `TableRenderer` renders an HTML table (for browsers only) or CSV (comma-separated value)
|
|
16
|
+
* representation of {@linkcode Agent} data.
|
|
17
|
+
*
|
|
18
|
+
* ```js
|
|
19
|
+
* for (let i = 0; i < 3; i++) {
|
|
20
|
+
* environment.addAgent(new Agent({
|
|
21
|
+
* x: i * 10,
|
|
22
|
+
* y: i - 2
|
|
23
|
+
* }));
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* const renderer = new TableRenderer(environment);
|
|
27
|
+
* renderer.columns = ['x', 'y'];
|
|
28
|
+
* renderer.mount('#container');
|
|
29
|
+
* environment.tick();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* The `TableRenderer` renders:
|
|
33
|
+
*
|
|
34
|
+
* |x |y |
|
|
35
|
+
* |----|----|
|
|
36
|
+
* |0 |-2 |
|
|
37
|
+
* |10 |-1 |
|
|
38
|
+
* |20 |0 |
|
|
39
|
+
*
|
|
15
40
|
* @since 0.5.0
|
|
16
41
|
*/
|
|
17
42
|
export declare class TableRenderer extends AbstractRenderer {
|
|
43
|
+
/**
|
|
44
|
+
* The `TableRenderer`s `columns` should be an array of the keys of `Agent`
|
|
45
|
+
* data that you want to render.
|
|
46
|
+
*
|
|
47
|
+
* ```js
|
|
48
|
+
* // Suppose Agents in the Environment have data that looks like:
|
|
49
|
+
* // {
|
|
50
|
+
* // "favor": number,
|
|
51
|
+
* // "oppose": number,
|
|
52
|
+
* // "neutral" number
|
|
53
|
+
* // }
|
|
54
|
+
*
|
|
55
|
+
* // order of columns is determined by order in the array
|
|
56
|
+
* renderer.columns = ['neutral', 'favor', 'oppose'];
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
18
60
|
columns: string[];
|
|
19
|
-
|
|
61
|
+
/** @hidden */
|
|
20
62
|
lastRendered: number;
|
|
63
|
+
/** @hidden */
|
|
21
64
|
opts: TableRendererOptions;
|
|
65
|
+
/** @hidden */
|
|
22
66
|
table: Element;
|
|
67
|
+
/**
|
|
68
|
+
* The first parameter must be the {@linkcode Environment} that this
|
|
69
|
+
* `TableRenderer` will render.
|
|
70
|
+
*
|
|
71
|
+
* The second parameter specifies options, which can include:
|
|
72
|
+
* - `"type"` (`"csv"` | `"table"` = `"table"`) — Whether to render output in CSV or HTML `<table>` format
|
|
73
|
+
* - `"filter"` — Include a function (`Agent` => `boolean`) to specify which rows to include in the output. For example, if you only want to include `Agent`s with an x value greater than 100:
|
|
74
|
+
* ```js
|
|
75
|
+
* const renderer = new TableRenderer(environment, {
|
|
76
|
+
* filter: agent => {
|
|
77
|
+
* return agent.get('x') > 100;
|
|
78
|
+
* }
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
* - `"limit"` (*number* = `Infinity`) — The maximum number of rows (`Agent`s) to render. If using a `filter` function, applies the `limit` *after* filtering.
|
|
82
|
+
* - `"sortKey"` (*string* = `null`) — Sort the `Agent` data by this key of data
|
|
83
|
+
* - `"order"` (`"asc"` | `"desc"` = `"desc"`) — When using a `"sortKey"`, specify whether `Agent`s should be listed in *asc*ending or *desc*ending order
|
|
84
|
+
* - `"precision"` (*number* = `3`) — For floating point values, the number of decimal places to display
|
|
85
|
+
* - `"refresh"` (*number* = `500`) — The number of milliseconds that should elapse between re-rendering (if this happens too quickly the effect can be visually jarring)
|
|
86
|
+
*/
|
|
23
87
|
constructor(environment: Environment, options?: TableRendererOptions);
|
|
24
88
|
/**
|
|
25
89
|
* Mount this renderer to a DOM element. Pass either a string representing a
|
|
26
|
-
* CSS selector matching the element
|
|
90
|
+
* CSS selector matching the element or the element itself.
|
|
91
|
+
*
|
|
92
|
+
* ```js
|
|
93
|
+
* // mounts the renderer to the element with the ID `container`
|
|
94
|
+
* renderer.mount('#container');
|
|
95
|
+
*
|
|
96
|
+
* // mounts the renderer to the element itself
|
|
97
|
+
* const container = document.getElementById('container');
|
|
98
|
+
* renderer.mount(container);
|
|
99
|
+
* ```
|
|
27
100
|
* @override
|
|
28
101
|
* @param {string | HTMLElement} el
|
|
29
102
|
*/
|
|
30
103
|
mount(el: string | HTMLElement): void;
|
|
104
|
+
/** @hidden */
|
|
31
105
|
serializeColumns(joiner: string, start?: string, end?: string, escape?: boolean): string;
|
|
106
|
+
/** @hidden */
|
|
32
107
|
serializeRows(cellJoiner: string, rowJoiner: string, start?: string, end?: string, rowStart?: string, rowEnd?: string, escape?: boolean): string;
|
|
108
|
+
/** @hidden */
|
|
33
109
|
renderCSV(): string;
|
|
110
|
+
/** @hidden */
|
|
34
111
|
renderHTMLTable(): string;
|
|
35
112
|
/**
|
|
113
|
+
* Returns the outer HTML of the table or the CSV data as a string. This can be useful for exporting data, particularly in a Node.js environment as opposed to in a browser. For instance, in a Node.js script, you could write the CSV data to a file as follows:
|
|
114
|
+
*
|
|
115
|
+
* ```js
|
|
116
|
+
* const fs = require('fs'); // import the file system module
|
|
117
|
+
*
|
|
118
|
+
* const environment = new Environment();
|
|
119
|
+
* for (let i = 0; i < 3; i++) environment.addAgent(new Agent({ i }));
|
|
120
|
+
*
|
|
121
|
+
* const renderer = new TableRenderer(environment, { type: 'csv' });
|
|
122
|
+
* renderer.columns = ['i'];
|
|
123
|
+
*
|
|
124
|
+
* // write the TableRenderer's output to a CSV file named data.csv
|
|
125
|
+
* fs.writeFileSync('./data.csv', renderer.output());
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
36
128
|
* @since 0.5.0
|
|
37
129
|
*/
|
|
38
130
|
output(): string;
|
package/dist/utils/clamp.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Given a `number` and `min` and `max` values, restrict the number
|
|
3
|
+
* to the range specified.
|
|
4
|
+
*
|
|
5
|
+
* ```js
|
|
6
|
+
* clamp(5, 1, 10); // returns 5
|
|
7
|
+
* clamp(5, 2, 4); // returns 4
|
|
8
|
+
* clamp(0, -4, -3); // returns -3
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
7
11
|
* @since 0.0.5
|
|
8
12
|
*/
|
|
9
13
|
export default function clamp(x: number, min: number, max: number): number;
|
package/dist/utils/distance.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
/// <reference path="../src/types/Point.d.ts" />
|
|
2
2
|
import { Agent } from "../agents/Agent";
|
|
3
3
|
/**
|
|
4
|
-
* Finds the distance between `p1` and `p2`.
|
|
5
|
-
*
|
|
6
|
-
* `x`, `y`, and/or `z`
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* Finds the distance between `p1` and `p2`.
|
|
5
|
+
*
|
|
6
|
+
* The inputs may be plain objects with `x`, `y`, and/or `z` keys, {@linkcode Vector}s,
|
|
7
|
+
* or {@linkcode Agent}s with `x`, `y`, and/or `z` data.
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* const a1 = new Agent();
|
|
11
|
+
* const a2 = new Agent({ x: 3, y: 4 });
|
|
12
|
+
* distance(a1, a2); // returns 5 (defaults to x = 0 and y = 0 for a1)
|
|
13
|
+
*
|
|
14
|
+
* const p1 = { x: 0, y: 2 };
|
|
15
|
+
* const p2 = { x: 0, y: 4 };
|
|
16
|
+
* distance(p1, p2); // returns 2
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
10
19
|
* @since 0.0.10
|
|
11
20
|
*/
|
|
12
21
|
export default function distance(p1: Point | Agent, p2: Point | Agent): number;
|