manim-web 0.23.0 → 0.25.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/dist/export/SlideDeckExporter.d.ts +210 -0
- package/dist/export/SlideDeckExporter.d.ts.map +1 -0
- package/dist/export/index.d.ts +1 -0
- package/dist/export/index.d.ts.map +1 -1
- package/dist/html2canvas-DECPJJGt.js +4025 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es-BiZp4vgJ.js +5753 -0
- package/dist/index.js +3 -3
- package/dist/integrations/react.js +17 -17
- package/dist/integrations/vue.js +16 -16
- package/dist/jspdf.es.min-CvMJL6nS.js +18228 -0
- package/dist/manim-web.browser.js +5532 -3742
- package/dist/mobjects/graph/ForceDirectedLayout.d.ts +65 -0
- package/dist/mobjects/graph/ForceDirectedLayout.d.ts.map +1 -0
- package/dist/mobjects/graph/GenericGraph.d.ts +11 -0
- package/dist/mobjects/graph/GenericGraph.d.ts.map +1 -1
- package/dist/mobjects/graph/SankeyDiagram.d.ts +122 -0
- package/dist/mobjects/graph/SankeyDiagram.d.ts.map +1 -0
- package/dist/mobjects/graph/index.d.ts +4 -1
- package/dist/mobjects/graph/index.d.ts.map +1 -1
- package/dist/mobjects/graph/layoutAlgorithms.d.ts +54 -0
- package/dist/mobjects/graph/layoutAlgorithms.d.ts.map +1 -1
- package/dist/mobjects/graph/sankeyLayout.d.ts +97 -0
- package/dist/mobjects/graph/sankeyLayout.d.ts.map +1 -0
- package/dist/mobjects/graphing/BoxPlot.d.ts +99 -0
- package/dist/mobjects/graphing/BoxPlot.d.ts.map +1 -0
- package/dist/mobjects/graphing/CandlestickChart.d.ts +191 -0
- package/dist/mobjects/graphing/CandlestickChart.d.ts.map +1 -0
- package/dist/mobjects/graphing/DomainColoring.d.ts +114 -0
- package/dist/mobjects/graphing/DomainColoring.d.ts.map +1 -0
- package/dist/mobjects/graphing/FourierEpicycles.d.ts +149 -0
- package/dist/mobjects/graphing/FourierEpicycles.d.ts.map +1 -0
- package/dist/mobjects/graphing/FourierSeries.d.ts +60 -0
- package/dist/mobjects/graphing/FourierSeries.d.ts.map +1 -0
- package/dist/mobjects/graphing/Histogram.d.ts +71 -0
- package/dist/mobjects/graphing/Histogram.d.ts.map +1 -0
- package/dist/mobjects/graphing/ScatterPlot.d.ts +66 -0
- package/dist/mobjects/graphing/ScatterPlot.d.ts.map +1 -0
- package/dist/mobjects/graphing/ViolinPlot.d.ts +83 -0
- package/dist/mobjects/graphing/ViolinPlot.d.ts.map +1 -0
- package/dist/mobjects/graphing/fourier.d.ts +104 -0
- package/dist/mobjects/graphing/fourier.d.ts.map +1 -0
- package/dist/mobjects/graphing/index.d.ts +10 -0
- package/dist/mobjects/graphing/index.d.ts.map +1 -1
- package/dist/mobjects/graphing/stats.d.ts +128 -0
- package/dist/mobjects/graphing/stats.d.ts.map +1 -0
- package/dist/purify.es-MUrypqLF.js +864 -0
- package/dist/serialization/index.d.ts +2 -0
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/urlState.d.ts +127 -0
- package/dist/serialization/urlState.d.ts.map +1 -0
- package/dist/{src-BRT6RDfk.js → src-Dq6hmMfV.js} +3347 -1557
- package/dist/typeof-CcP5rTWg.js +11 -0
- package/package.json +2 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { VGroup } from '../../core/VGroup';
|
|
2
|
+
import { VMobject } from '../../core/VMobject';
|
|
3
|
+
import { Rectangle } from '../geometry/Rectangle';
|
|
4
|
+
import { Line } from '../geometry/Line';
|
|
5
|
+
import { NumberLine } from './NumberLine';
|
|
6
|
+
/**
|
|
7
|
+
* One open/high/low/close data point for a CandlestickChart.
|
|
8
|
+
*/
|
|
9
|
+
export interface OHLC {
|
|
10
|
+
/** Opening price. */
|
|
11
|
+
open: number;
|
|
12
|
+
/** Highest price in the period. */
|
|
13
|
+
high: number;
|
|
14
|
+
/** Lowest price in the period. */
|
|
15
|
+
low: number;
|
|
16
|
+
/** Closing price. */
|
|
17
|
+
close: number;
|
|
18
|
+
/** Optional date or category label for the x-axis. */
|
|
19
|
+
date?: string;
|
|
20
|
+
/** Optional free-form label for the x-axis (overrides date). */
|
|
21
|
+
label?: string;
|
|
22
|
+
/** Optional traded volume, shown when showVolume is true. */
|
|
23
|
+
volume?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Options for creating a CandlestickChart.
|
|
27
|
+
*/
|
|
28
|
+
export interface CandlestickChartOptions {
|
|
29
|
+
/** Array of OHLC data points, left to right. */
|
|
30
|
+
data: OHLC[];
|
|
31
|
+
/** Fill/stroke color for bullish candles (close >= open). Default: GREEN. */
|
|
32
|
+
bullishColor?: string;
|
|
33
|
+
/** Fill/stroke color for bearish candles (close < open). Default: RED. */
|
|
34
|
+
bearishColor?: string;
|
|
35
|
+
/** Width of each candle body. Default: 0.5 */
|
|
36
|
+
candleWidth?: number;
|
|
37
|
+
/** Gap between adjacent candles. Default: 0.2 */
|
|
38
|
+
candleSpacing?: number;
|
|
39
|
+
/** Stroke width of the high/low wick line. Default: 2 */
|
|
40
|
+
wickWidth?: number;
|
|
41
|
+
/** Stroke width of the candle body outline. Default: 1.5 */
|
|
42
|
+
bodyStrokeWidth?: number;
|
|
43
|
+
/** Fill opacity of the candle body. Default: 0.9 */
|
|
44
|
+
bodyFillOpacity?: number;
|
|
45
|
+
/** Y-axis (price) range as [min, max, step]. Default: auto-scaled from data. */
|
|
46
|
+
yRange?: [number, number, number];
|
|
47
|
+
/** Visual height of the price area. Default: 5 */
|
|
48
|
+
height?: number;
|
|
49
|
+
/** Visual width of the chart area. Default: 8 */
|
|
50
|
+
width?: number;
|
|
51
|
+
/** Color for the axes and labels. Default: WHITE */
|
|
52
|
+
axisColor?: string;
|
|
53
|
+
/** Whether to include y-axis tick marks. Default: true */
|
|
54
|
+
includeYTicks?: boolean;
|
|
55
|
+
/** Whether to include y-axis price labels. Default: true */
|
|
56
|
+
includeYLabels?: boolean;
|
|
57
|
+
/** Font size for y-axis labels. Default: 20 */
|
|
58
|
+
yLabelFontSize?: number;
|
|
59
|
+
/** Explicit x-axis labels (overrides date/label on the data). Default: [] */
|
|
60
|
+
xLabels?: string[];
|
|
61
|
+
/** Font size for x-axis labels. Default: 20 */
|
|
62
|
+
xLabelFontSize?: number;
|
|
63
|
+
/** Whether to draw volume bars below the price area. Default: false */
|
|
64
|
+
showVolume?: boolean;
|
|
65
|
+
/** Visual height of the volume area. Default: 1 */
|
|
66
|
+
volumeHeight?: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* CandlestickChart - A financial candlestick / OHLC chart mobject.
|
|
70
|
+
*
|
|
71
|
+
* Renders each period as a body rectangle that spans open to close, plus a
|
|
72
|
+
* high/low wick line. Bullish periods (close >= open) and bearish periods
|
|
73
|
+
* (close < open) use separate colors. The price y-axis auto-scales to the data
|
|
74
|
+
* unless an explicit range is given. Optional volume bars render below.
|
|
75
|
+
*
|
|
76
|
+
* The chart is a VGroup, so Create and FadeIn animate it directly.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const chart = new CandlestickChart({
|
|
81
|
+
* data: [
|
|
82
|
+
* { open: 10, high: 15, low: 8, close: 14, date: 'Mon' },
|
|
83
|
+
* { open: 14, high: 16, low: 11, close: 12, date: 'Tue' },
|
|
84
|
+
* ],
|
|
85
|
+
* showVolume: true,
|
|
86
|
+
* });
|
|
87
|
+
* scene.play(new Create(chart));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare class CandlestickChart extends VGroup {
|
|
91
|
+
/** The candle VGroups (each holds a body Rectangle and a wick Line). */
|
|
92
|
+
candles: VGroup;
|
|
93
|
+
/** The volume bars, when showVolume is enabled. */
|
|
94
|
+
volumeBars: VGroup;
|
|
95
|
+
/** The price y-axis. */
|
|
96
|
+
yAxis: NumberLine;
|
|
97
|
+
/** The x-axis baseline. */
|
|
98
|
+
xAxisLine: VMobject;
|
|
99
|
+
/** X-axis labels. */
|
|
100
|
+
xLabels: VGroup;
|
|
101
|
+
/** Y-axis labels. */
|
|
102
|
+
yLabels: VGroup;
|
|
103
|
+
protected _data: OHLC[];
|
|
104
|
+
protected _bullishColor: string;
|
|
105
|
+
protected _bearishColor: string;
|
|
106
|
+
protected _candleWidth: number;
|
|
107
|
+
protected _candleSpacing: number;
|
|
108
|
+
protected _wickWidth: number;
|
|
109
|
+
protected _bodyStrokeWidth: number;
|
|
110
|
+
protected _bodyFillOpacity: number;
|
|
111
|
+
protected _yRange: [number, number, number];
|
|
112
|
+
protected _height: number;
|
|
113
|
+
protected _width: number;
|
|
114
|
+
protected _axisColor: string;
|
|
115
|
+
protected _includeYTicks: boolean;
|
|
116
|
+
protected _includeYLabels: boolean;
|
|
117
|
+
protected _yLabelFontSize: number;
|
|
118
|
+
protected _xLabelTexts: string[];
|
|
119
|
+
protected _xLabelFontSize: number;
|
|
120
|
+
protected _showVolume: boolean;
|
|
121
|
+
protected _volumeHeight: number;
|
|
122
|
+
constructor(options: CandlestickChartOptions);
|
|
123
|
+
/** Whether a period is bullish (close at or above open). */
|
|
124
|
+
private _isBullish;
|
|
125
|
+
/** Color for a period, by direction. */
|
|
126
|
+
private _candleColor;
|
|
127
|
+
/**
|
|
128
|
+
* Auto-scale the price range from the data lows and highs.
|
|
129
|
+
*/
|
|
130
|
+
private _calculateYRange;
|
|
131
|
+
/**
|
|
132
|
+
* Convert a price to its y-coordinate within the price area.
|
|
133
|
+
*/
|
|
134
|
+
priceToY(price: number): number;
|
|
135
|
+
/**
|
|
136
|
+
* X-coordinate of the center column for candle i.
|
|
137
|
+
*/
|
|
138
|
+
private _candleCenterX;
|
|
139
|
+
/**
|
|
140
|
+
* Create the price y-axis.
|
|
141
|
+
*/
|
|
142
|
+
private _createYAxis;
|
|
143
|
+
/**
|
|
144
|
+
* Create the x-axis baseline at the bottom of the price area.
|
|
145
|
+
*/
|
|
146
|
+
private _createXAxisLine;
|
|
147
|
+
/**
|
|
148
|
+
* Build one candle (body rectangle + wick line) per data point.
|
|
149
|
+
*/
|
|
150
|
+
private _createCandles;
|
|
151
|
+
/**
|
|
152
|
+
* Build volume bars below the price area.
|
|
153
|
+
*/
|
|
154
|
+
private _createVolumeBars;
|
|
155
|
+
/**
|
|
156
|
+
* Create x-axis labels from the explicit option or the data date/label.
|
|
157
|
+
*/
|
|
158
|
+
private _createXLabels;
|
|
159
|
+
/**
|
|
160
|
+
* Create y-axis price labels.
|
|
161
|
+
*/
|
|
162
|
+
private _createYLabels;
|
|
163
|
+
/** Get all candle VGroups. */
|
|
164
|
+
getCandles(): VGroup[];
|
|
165
|
+
/**
|
|
166
|
+
* Get a single candle VGroup by index.
|
|
167
|
+
* @returns The candle, or undefined when out of range.
|
|
168
|
+
*/
|
|
169
|
+
getCandle(index: number): VGroup | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Get the body rectangle of candle i.
|
|
172
|
+
* @returns The body, or undefined when out of range.
|
|
173
|
+
*/
|
|
174
|
+
getBody(index: number): Rectangle | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* Get the wick line of candle i.
|
|
177
|
+
* @returns The wick, or undefined when out of range.
|
|
178
|
+
*/
|
|
179
|
+
getWick(index: number): Line | undefined;
|
|
180
|
+
/** Get all volume bars (empty when showVolume is off). */
|
|
181
|
+
getVolumeBars(): Rectangle[];
|
|
182
|
+
/** Get the price (y-axis) range as [min, max, step]. */
|
|
183
|
+
getYRange(): [number, number, number];
|
|
184
|
+
/** Get the data points. */
|
|
185
|
+
getData(): OHLC[];
|
|
186
|
+
/** Get the visual height of the price area. */
|
|
187
|
+
getChartHeight(): number;
|
|
188
|
+
/** Get the visual width of the chart area. */
|
|
189
|
+
getChartWidth(): number;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=CandlestickChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CandlestickChart.d.ts","sourceRoot":"","sources":["../../../src/mobjects/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AAI,SAAS,EAAE;IAI5B,wDAAwD;IACxD,SAAS,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAIrC,2BAA2B;IAC3B,OAAO,IAAI,IAAI,EAAE;IAIjB,+CAA+C;IAC/C,cAAc,IAAI,MAAM;IAIxB,8CAA8C;IAC9C,aAAa,IAAI,MAAM;CAGxB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Vector3Tuple } from '../../core/Mobject';
|
|
2
|
+
import { Mobject3D } from '../three-d/Mobject3D';
|
|
3
|
+
import { Complex } from './ComplexPlane';
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
/** A complex function w = f(z), mapping one complex number to another. */
|
|
6
|
+
export type ComplexFunction = (z: Complex) => Complex;
|
|
7
|
+
/**
|
|
8
|
+
* How the modulus |f(z)| drives brightness.
|
|
9
|
+
*
|
|
10
|
+
* - `smooth`: brightness rises monotonically with the modulus, dark at zeros
|
|
11
|
+
* and bright at poles.
|
|
12
|
+
* - `banded`: brightness oscillates over each octave (power of two) of the
|
|
13
|
+
* modulus, giving the dark/light contour bands of a Wegert phase portrait.
|
|
14
|
+
*/
|
|
15
|
+
export type BrightnessScheme = 'smooth' | 'banded';
|
|
16
|
+
/** Options for creating a {@link DomainColoring}. */
|
|
17
|
+
export interface DomainColoringOptions {
|
|
18
|
+
/** The complex function w = f(z) to visualize. */
|
|
19
|
+
func: ComplexFunction;
|
|
20
|
+
/** Real-axis range [min, max]. Default: [-5, 5] */
|
|
21
|
+
reRange?: [number, number];
|
|
22
|
+
/** Imaginary-axis range [min, max]. Default: [-5, 5] */
|
|
23
|
+
imRange?: [number, number];
|
|
24
|
+
/** Pixel grid size per axis, or [width, height]. Default: 256 */
|
|
25
|
+
resolution?: number | [number, number];
|
|
26
|
+
/** Brightness scheme for the modulus. Default: 'banded' */
|
|
27
|
+
scheme?: BrightnessScheme;
|
|
28
|
+
/** Color saturation from 0 to 1. Default: 1 */
|
|
29
|
+
saturation?: number;
|
|
30
|
+
/** Darken thin lines where the modulus crosses a power of two. Default: false */
|
|
31
|
+
contourLines?: boolean;
|
|
32
|
+
/** Opacity from 0 to 1. Default: 1 */
|
|
33
|
+
opacity?: number;
|
|
34
|
+
/** Center position [x, y, z]. Default: [0, 0, 0] */
|
|
35
|
+
center?: Vector3Tuple;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Map an evaluated value w = f(z) to an `[r, g, b]` float color (0..1).
|
|
39
|
+
*
|
|
40
|
+
* The hue encodes arg(w): the positive real axis is hue 0, and a quarter turn
|
|
41
|
+
* toward the positive imaginary axis shifts the hue by 90 degrees. The modulus
|
|
42
|
+
* |w| drives brightness through the chosen scheme. The result is always a valid
|
|
43
|
+
* color: a pole (|w| not finite) reads bright, a zero reads dark, and any
|
|
44
|
+
* non-finite channel becomes 0, so poles and zeros never produce NaN colors.
|
|
45
|
+
*/
|
|
46
|
+
export declare function phasePortraitColor(w: Complex, scheme: BrightnessScheme, saturation: number, contourLines: boolean): [number, number, number];
|
|
47
|
+
/**
|
|
48
|
+
* DomainColoring - a phase portrait of a complex function f: C -> C.
|
|
49
|
+
*
|
|
50
|
+
* The region of the complex plane is sampled on a regular pixel grid. Each
|
|
51
|
+
* pixel's complex value w = f(z) is turned into a color by {@link
|
|
52
|
+
* phasePortraitColor}: the hue encodes arg(w) and the brightness encodes |w|.
|
|
53
|
+
* The pixels are written to an RGBA buffer that is uploaded as a texture on a
|
|
54
|
+
* flat quad spanning `reRange` x `imRange`, mirroring the way {@link HeatMap}
|
|
55
|
+
* renders a sampled scalar field.
|
|
56
|
+
*
|
|
57
|
+
* The pixel buffer is computed in plain TypeScript, so it is deterministic and
|
|
58
|
+
* readable without a browser. In a browser the buffer becomes a
|
|
59
|
+
* `THREE.CanvasTexture`; without a DOM it becomes an equivalent
|
|
60
|
+
* `THREE.DataTexture`.
|
|
61
|
+
*
|
|
62
|
+
* Pixel layout: row 0 is the top (im = imMax), the last row is the bottom
|
|
63
|
+
* (im = imMin); column 0 is the left (re = reMin), the last column is the
|
|
64
|
+
* right (re = reMax).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // The identity f(z) = z
|
|
69
|
+
* const portrait = new DomainColoring({
|
|
70
|
+
* func: (z) => z,
|
|
71
|
+
* reRange: [-2, 2],
|
|
72
|
+
* imRange: [-2, 2],
|
|
73
|
+
* resolution: 256,
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare class DomainColoring extends Mobject3D {
|
|
78
|
+
private _func;
|
|
79
|
+
private _reRange;
|
|
80
|
+
private _imRange;
|
|
81
|
+
private _width;
|
|
82
|
+
private _height;
|
|
83
|
+
private _scheme;
|
|
84
|
+
private _saturation;
|
|
85
|
+
private _contourLines;
|
|
86
|
+
private _centerPoint;
|
|
87
|
+
constructor(options: DomainColoringOptions);
|
|
88
|
+
/** The complex number z sampled at pixel column `col`, row `row`. */
|
|
89
|
+
pixelToComplex(col: number, row: number): Complex;
|
|
90
|
+
/** Sample the function over the grid into an RGBA buffer (row 0 at the top). */
|
|
91
|
+
getPixelData(): Uint8ClampedArray;
|
|
92
|
+
/** The pixel grid size as [width, height]. */
|
|
93
|
+
getResolution(): [number, number];
|
|
94
|
+
/** The hex color the portrait assigns to the complex number `z`. */
|
|
95
|
+
colorAt(z: Complex): string;
|
|
96
|
+
/** Build a texture from the pixel buffer, preferring a canvas when a DOM exists. */
|
|
97
|
+
private _buildTexture;
|
|
98
|
+
/** Build the textured quad spanning reRange x imRange. */
|
|
99
|
+
private _buildGeometry;
|
|
100
|
+
protected _createThreeObject(): THREE.Object3D;
|
|
101
|
+
protected _syncMaterialToThree(): void;
|
|
102
|
+
/** Rebuild the geometry and texture after the function or options change. */
|
|
103
|
+
private _update;
|
|
104
|
+
/** Get the complex function. */
|
|
105
|
+
getFunc(): ComplexFunction;
|
|
106
|
+
/** Set the complex function and rebuild. */
|
|
107
|
+
setFunc(func: ComplexFunction): this;
|
|
108
|
+
/** The brightness scheme in use. */
|
|
109
|
+
getScheme(): BrightnessScheme;
|
|
110
|
+
/** Set the brightness scheme and rebuild. */
|
|
111
|
+
setScheme(scheme: BrightnessScheme): this;
|
|
112
|
+
copy(): DomainColoring;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=DomainColoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DomainColoring.d.ts","sourceRoot":"","sources":["../../../src/mobjects/graphing/DomainColoring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnD,qDAAqD;AACrD,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,IAAI,EAAE,eAAe,CAAC;IACtB,mDAAmD;IACnD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,wDAAwD;IACxD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,2DAA2D;IAC3D,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sCAAsC;IACtC,OAAO,CAAC,EAA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oCAAoC;IACpC,SAAS,IAAI,gBAAgB;IAI7B,6CAA6C;IAC7C,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAMhC,IAAI,IAAI,cAAc;CAehC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Group } from '../../core/Group';
|
|
2
|
+
import { VMobject } from '../../core/VMobject';
|
|
3
|
+
import { Vector3Tuple } from '../../core/Mobject';
|
|
4
|
+
import { ValueTracker } from '../value-tracker/ValueTracker';
|
|
5
|
+
import { Complex } from './ComplexPlane';
|
|
6
|
+
import { FourierCoefficient, FourierOrder } from './fourier';
|
|
7
|
+
/** A parametric complex path: `func(t)` for `t` over `tRange` (default `[0, 1]`). */
|
|
8
|
+
export interface ComplexPathFunction {
|
|
9
|
+
/** Maps a parameter to a complex plane point. */
|
|
10
|
+
func: (t: number) => Complex;
|
|
11
|
+
/** Parameter range as `[min, max]`. Default `[0, 1]`. */
|
|
12
|
+
tRange?: [number, number];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The path an epicycle chain approximates. One of:
|
|
16
|
+
* - `number[][]`: equally spaced samples, each `[x, y]` read as the complex point `x + i·y`.
|
|
17
|
+
* - {@link VMobject}: sampled along its arc length into complex points.
|
|
18
|
+
* - {@link ComplexPathFunction}: a parametric complex function sampled over its range.
|
|
19
|
+
*/
|
|
20
|
+
export type FourierPathInput = number[][] | VMobject | ComplexPathFunction;
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link FourierEpicycles}.
|
|
23
|
+
*/
|
|
24
|
+
export interface FourierEpicyclesOptions {
|
|
25
|
+
/** The path to approximate. */
|
|
26
|
+
path: FourierPathInput;
|
|
27
|
+
/** Number of rotating vectors to show. Default: all coefficients. */
|
|
28
|
+
numTerms?: number;
|
|
29
|
+
/** Samples taken from a {@link VMobject} or {@link ComplexPathFunction}. Default `256`. */
|
|
30
|
+
numSamples?: number;
|
|
31
|
+
/** Origin of the vector chain (the fixed tail of the first vector). Default `[0, 0, 0]`. */
|
|
32
|
+
center?: Vector3Tuple;
|
|
33
|
+
/** Vector chain ordering. Default `'frequency'` (the iconic `0, +1, -1, +2, -2, …`). */
|
|
34
|
+
order?: FourierOrder;
|
|
35
|
+
/** Color of the rotating vectors (arrows). Default `'#58c4dd'`. */
|
|
36
|
+
color?: string;
|
|
37
|
+
/** Whether to draw the circles behind the vectors. Default `true`. */
|
|
38
|
+
showCircles?: boolean;
|
|
39
|
+
/** Color of the circles. Default `'#888888'`. */
|
|
40
|
+
circleColor?: string;
|
|
41
|
+
/** Opacity of the circles' stroke. Default `0.5`. */
|
|
42
|
+
circleOpacity?: number;
|
|
43
|
+
/** Color of the traced output curve. Default `'#ffff00'`. */
|
|
44
|
+
traceColor?: string;
|
|
45
|
+
/** Stroke width of the traced curve. Default `3`. */
|
|
46
|
+
traceWidth?: number;
|
|
47
|
+
/** Stroke width of the vectors. Default `2`. */
|
|
48
|
+
strokeWidth?: number;
|
|
49
|
+
/** Arrow tip length for the vectors. Default `0.15`. */
|
|
50
|
+
tipLength?: number;
|
|
51
|
+
/** Whether to show a pen dot at the chain tip. Default `true`. */
|
|
52
|
+
showPen?: boolean;
|
|
53
|
+
/** Cycles per second advanced by the internal updater. Default `0.2`. */
|
|
54
|
+
speed?: number;
|
|
55
|
+
/** Install an updater that advances time each frame. Default `true`. */
|
|
56
|
+
animate?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Optional tracker that drives time instead of the internal clock. When set,
|
|
59
|
+
* `time` is read from the tracker each frame (one period spans value `0 → 1`).
|
|
60
|
+
*/
|
|
61
|
+
tracker?: ValueTracker;
|
|
62
|
+
/** Maximum number of accumulated trace points before the oldest are dropped. Default `2000`. */
|
|
63
|
+
maxTracePoints?: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* FourierEpicycles - the rotating-vector ("epicycle") approximation of a path.
|
|
67
|
+
*
|
|
68
|
+
* Given a path and a number of terms `N`, this builds the chain of `N` rotating
|
|
69
|
+
* vectors (and their circles) whose tip-to-tail sum tracks the path, plus the
|
|
70
|
+
* curve traced by the final tip. An updater rotates each vector at its own
|
|
71
|
+
* frequency and extends the traced curve over time, reproducing the iconic
|
|
72
|
+
* 3Blue1Brown Fourier-series animation.
|
|
73
|
+
*
|
|
74
|
+
* The geometry is deterministic: {@link setTime} fully determines every vector,
|
|
75
|
+
* circle, and the tip for a given normalized time `t`.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Approximate a square wave path with 50 rotating vectors.
|
|
80
|
+
* const path: number[][] = [];
|
|
81
|
+
* for (let i = 0; i < 256; i++) {
|
|
82
|
+
* const a = (2 * Math.PI * i) / 256;
|
|
83
|
+
* path.push([Math.cos(a), Math.sin(3 * a) / 3]);
|
|
84
|
+
* }
|
|
85
|
+
* const epicycles = new FourierEpicycles({ path, numTerms: 50 });
|
|
86
|
+
* scene.add(epicycles);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare class FourierEpicycles extends Group {
|
|
90
|
+
private _coefficients;
|
|
91
|
+
private _center;
|
|
92
|
+
private _speed;
|
|
93
|
+
private _tracker;
|
|
94
|
+
private _maxTracePoints;
|
|
95
|
+
private _showPen;
|
|
96
|
+
private _circlesGroup;
|
|
97
|
+
private _vectorsGroup;
|
|
98
|
+
private _tracedPath;
|
|
99
|
+
private _circles;
|
|
100
|
+
private _vectors;
|
|
101
|
+
private _pen;
|
|
102
|
+
private _time;
|
|
103
|
+
private _tracePoints;
|
|
104
|
+
private _lastTip;
|
|
105
|
+
private _sourceSamples;
|
|
106
|
+
private _options;
|
|
107
|
+
constructor(options: FourierEpicyclesOptions);
|
|
108
|
+
/**
|
|
109
|
+
* Resolve a {@link FourierPathInput} into equally spaced complex samples.
|
|
110
|
+
*/
|
|
111
|
+
private static _resolveSamples;
|
|
112
|
+
/**
|
|
113
|
+
* Advance the internal clock by `dt` seconds (scaled by `speed`), reposition
|
|
114
|
+
* the chain, and extend the traced curve. When a tracker drives time, its
|
|
115
|
+
* value is used directly instead of the internal clock.
|
|
116
|
+
*/
|
|
117
|
+
private _advance;
|
|
118
|
+
private _appendTracePoint;
|
|
119
|
+
private _rebuildTrace;
|
|
120
|
+
/**
|
|
121
|
+
* Position every vector and circle for normalized time `t` and move the pen
|
|
122
|
+
* to the chain tip. One full period spans `t ∈ [0, 1)`. Pure positioning:
|
|
123
|
+
* this does not extend the traced curve.
|
|
124
|
+
*
|
|
125
|
+
* @param t - Normalized time.
|
|
126
|
+
* @returns The chain tip as `[x, y, z]`, equal to the `numTerms` partial sum.
|
|
127
|
+
*/
|
|
128
|
+
setTime(t: number): Vector3Tuple;
|
|
129
|
+
/** Current normalized time of the internal clock. */
|
|
130
|
+
getTime(): number;
|
|
131
|
+
/** The chain tip computed at the most recent {@link setTime}. */
|
|
132
|
+
getTipPoint(): Vector3Tuple;
|
|
133
|
+
/** The ordered coefficients actually shown (length equals the vector count). */
|
|
134
|
+
getCoefficients(): FourierCoefficient[];
|
|
135
|
+
/** The number of rotating vectors (equals the requested, clamped, term count). */
|
|
136
|
+
getNumTerms(): number;
|
|
137
|
+
/** The group of rotating-vector arrows. */
|
|
138
|
+
getVectors(): Group;
|
|
139
|
+
/** The group of circles (empty when `showCircles` is `false`). */
|
|
140
|
+
getCircles(): Group;
|
|
141
|
+
/** The VMobject holding the traced output curve. */
|
|
142
|
+
getTracedPath(): VMobject;
|
|
143
|
+
/** The accumulated trace points, oldest first. */
|
|
144
|
+
getTracePoints(): number[][];
|
|
145
|
+
/** Clear the accumulated traced curve. */
|
|
146
|
+
clearTrace(): this;
|
|
147
|
+
copy(): FourierEpicycles;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=FourierEpicycles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FourierEpicycles.d.ts","sourceRoot":"","sources":["../../../src/mobjects/graphing/FourierEpicycles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAA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;IAIjB,iEAAiE;IACjE,WAAW,IAAI,YAAY;IAI3B,gFAAgF;IAChF,eAAe,IAAI,kBAAkB,EAAE;IAIvC,kFAAkF;IAClF,WAAW,IAAI,MAAM;IAIrB,2CAA2C;IAC3C,UAAU,IAAI,KAAK;IAInB,kEAAkE;IAClE,UAAU,IAAI,KAAK;IAInB,oDAAoD;IACpD,aAAa,IAAI,QAAQ;IAIzB,kDAAkD;IAClD,cAAc,IAAI,MAAM,EAAE,EAAE;IAI5B,0CAA0C;IAC1C,UAAU,IAAI,IAAI;IAMT,IAAI,IAAI,gBAAgB;CAQlC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FunctionGraph, FunctionGraphOptions } from './FunctionGraph';
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link FourierSeries}.
|
|
4
|
+
*/
|
|
5
|
+
export interface FourierSeriesOptions {
|
|
6
|
+
/** The target real periodic function to approximate, `y = f(x)`. */
|
|
7
|
+
func: (x: number) => number;
|
|
8
|
+
/** Number of harmonics kept, chosen by amplitude. Default: all sampled terms. */
|
|
9
|
+
numTerms?: number;
|
|
10
|
+
/** Length of one period of {@link func}. Default `2π`. */
|
|
11
|
+
period?: number;
|
|
12
|
+
/** Start of the sampled period. Default: the graph's `xRange[0]`, else `0`. */
|
|
13
|
+
periodStart?: number;
|
|
14
|
+
/** Samples used to compute the Fourier coefficients. Default `256`. */
|
|
15
|
+
coefficientSamples?: number;
|
|
16
|
+
/** X range for the plotted curve as `[min, max]`. */
|
|
17
|
+
xRange?: [number, number];
|
|
18
|
+
/** Stroke color. Default `'#58c4dd'`. */
|
|
19
|
+
color?: string;
|
|
20
|
+
/** Stroke width in pixels. Default `2`. */
|
|
21
|
+
strokeWidth?: number;
|
|
22
|
+
/** Samples used to draw the curve. Default `200`. */
|
|
23
|
+
numSamples?: number;
|
|
24
|
+
/** Reference axes for coordinate transformation. */
|
|
25
|
+
axes?: FunctionGraphOptions['axes'];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* FourierSeries - the truncated Fourier partial sum of a function, as a graph.
|
|
29
|
+
*
|
|
30
|
+
* Computes the discrete Fourier coefficients of a real periodic function,
|
|
31
|
+
* keeps the `numTerms` largest harmonics, and plots the resulting partial-sum
|
|
32
|
+
* approximation `y = f_N(x)` like a {@link FunctionGraph}. As `numTerms` grows,
|
|
33
|
+
* the curve converges to the target function.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Approximate a square wave with 7 harmonics over [-π, π].
|
|
38
|
+
* const square = (x: number) => (Math.sin(x) >= 0 ? 1 : -1);
|
|
39
|
+
* const series = new FourierSeries({
|
|
40
|
+
* func: square,
|
|
41
|
+
* numTerms: 7,
|
|
42
|
+
* period: 2 * Math.PI,
|
|
43
|
+
* xRange: [-Math.PI, Math.PI],
|
|
44
|
+
* axes,
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class FourierSeries extends FunctionGraph {
|
|
49
|
+
private _targetFunc;
|
|
50
|
+
private _numTerms;
|
|
51
|
+
private _period;
|
|
52
|
+
constructor(options: FourierSeriesOptions);
|
|
53
|
+
/** The target function this series approximates. */
|
|
54
|
+
getTargetFunction(): (x: number) => number;
|
|
55
|
+
/** The number of harmonics requested (`undefined` means all sampled terms). */
|
|
56
|
+
getNumTerms(): number | undefined;
|
|
57
|
+
/** The period used to compute the coefficients. */
|
|
58
|
+
getPeriod(): number;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=FourierSeries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FourierSeries.d.ts","sourceRoot":"","sources":["../../../src/mobjects/graphing/FourierSeries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG3E;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,oEAAoE;IACpE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qDAAqD;IACrD,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,IAAI,CAAC,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,aAAc,SAAQ,aAAa;IAC9C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,oBAAoB;IAyBzC,oDAAoD;IACpD,iBAAiB,IAAI,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM;IAI1C,+EAA+E;IAC/E,WAAW,IAAI,MAAM,GAAG,SAAS;IAIjC,mDAAmD;IACnD,SAAS,IAAI,MAAM;CAGpB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Group } from '../../core/Group';
|
|
2
|
+
import { VGroup } from '../../core/VGroup';
|
|
3
|
+
import { Rectangle } from '../geometry/Rectangle';
|
|
4
|
+
import { Axes } from './Axes';
|
|
5
|
+
import { HistogramBin } from './stats';
|
|
6
|
+
/** Options for creating a Histogram. */
|
|
7
|
+
export interface HistogramOptions {
|
|
8
|
+
/** The raw data values to bin. */
|
|
9
|
+
data: number[];
|
|
10
|
+
/** Number of equal-width bins. Ignored when binEdges is given. Default: 10 */
|
|
11
|
+
bins?: number;
|
|
12
|
+
/** Explicit bin edges (length n+1 for n bins). Overrides bins. */
|
|
13
|
+
binEdges?: number[];
|
|
14
|
+
/** Plot bar height as probability density instead of count. Default: false */
|
|
15
|
+
density?: boolean;
|
|
16
|
+
/** Plot bar height as relative frequency (count / N). Ignored if density. Default: false */
|
|
17
|
+
normalize?: boolean;
|
|
18
|
+
/** Fill color for the bars. Default: Manim's blue */
|
|
19
|
+
color?: string;
|
|
20
|
+
/** Fill opacity for the bars. Default: 0.75 */
|
|
21
|
+
fillOpacity?: number;
|
|
22
|
+
/** Stroke width for the bar outlines. Default: 1 */
|
|
23
|
+
strokeWidth?: number;
|
|
24
|
+
/** An existing Axes to draw onto. When omitted, one is built from the bins. */
|
|
25
|
+
axes?: Axes;
|
|
26
|
+
/** Visual length of the x-axis when auto-building axes. Default: 8 */
|
|
27
|
+
xLength?: number;
|
|
28
|
+
/** Visual length of the y-axis when auto-building axes. Default: 6 */
|
|
29
|
+
yLength?: number;
|
|
30
|
+
/** Color for the axes when auto-building. Default: '#ffffff' */
|
|
31
|
+
axisColor?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Histogram - bars over an x-axis from binned raw data.
|
|
35
|
+
*
|
|
36
|
+
* The raw data is binned into equal-width bins (or the given explicit edges).
|
|
37
|
+
* Bar height is the bin count, the relative frequency, or the probability
|
|
38
|
+
* density. When no Axes is supplied, one is built to fit the bins.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const hist = new Histogram({
|
|
43
|
+
* data: [1, 2, 2, 3, 3, 3, 4, 4, 5],
|
|
44
|
+
* bins: 5,
|
|
45
|
+
* density: true,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class Histogram extends Group {
|
|
50
|
+
/** The coordinate system the bars are drawn on. */
|
|
51
|
+
axes: Axes;
|
|
52
|
+
/** The rectangular bars, one per bin, left to right. */
|
|
53
|
+
bars: VGroup;
|
|
54
|
+
protected _data: number[];
|
|
55
|
+
protected _bins: HistogramBin[];
|
|
56
|
+
constructor(options: HistogramOptions);
|
|
57
|
+
/** Map a bin to its bar height given the count/frequency/density mode. */
|
|
58
|
+
private _barHeight;
|
|
59
|
+
/** Get the coordinate system. */
|
|
60
|
+
getAxes(): Axes;
|
|
61
|
+
/** Get the group of bars. */
|
|
62
|
+
getBars(): VGroup;
|
|
63
|
+
/** Get a single bar by bin index, or undefined when out of range. */
|
|
64
|
+
getBar(index: number): Rectangle | undefined;
|
|
65
|
+
/** Get the computed bins (edges, counts, density). */
|
|
66
|
+
getBins(): HistogramBin[];
|
|
67
|
+
/** The number of bins. */
|
|
68
|
+
get numBins(): number;
|
|
69
|
+
copy(): Histogram;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=Histogram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Histogram.d.ts","sourceRoot":"","sources":["../../../src/mobjects/graphing/Histogram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1E,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4FAA4F;IAC5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