figureone 0.15.10 → 1.0.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.
Files changed (159) hide show
  1. package/figureone.min.js +1 -1
  2. package/index.js +79167 -0
  3. package/package.json +15 -1
  4. package/types/index.d.ts +132 -0
  5. package/types/js/figure/Animation/Animation.d.ts +36 -0
  6. package/types/js/figure/Animation/AnimationBuilder.d.ts +173 -0
  7. package/types/js/figure/Animation/AnimationManager.d.ts +392 -0
  8. package/types/js/figure/Animation/AnimationStep/CustomStep.d.ts +99 -0
  9. package/types/js/figure/Animation/AnimationStep/DelayStep.d.ts +24 -0
  10. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ColorAnimationStep.d.ts +203 -0
  11. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/OpacityAnimationStep.d.ts +220 -0
  12. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PositionAnimationStep.d.ts +124 -0
  13. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseAnimationStep.d.ts +137 -0
  14. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseTransformAnimationStep.d.ts +52 -0
  15. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/RotationAnimationStep.d.ts +119 -0
  16. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScaleAnimationStep.d.ts +93 -0
  17. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScenarioAnimationStep.d.ts +204 -0
  18. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/TransformAnimationStep.d.ts +163 -0
  19. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep.d.ts +56 -0
  20. package/types/js/figure/Animation/AnimationStep/ParallelAnimationStep.d.ts +70 -0
  21. package/types/js/figure/Animation/AnimationStep/SerialAnimationStep.d.ts +84 -0
  22. package/types/js/figure/Animation/AnimationStep/TriggerStep.d.ts +106 -0
  23. package/types/js/figure/Animation/AnimationStep.d.ts +110 -0
  24. package/types/js/figure/DrawContext2D.d.ts +9 -0
  25. package/types/js/figure/DrawingObjects/DrawingObject.d.ts +45 -0
  26. package/types/js/figure/DrawingObjects/GLObject/GLObject.d.ts +146 -0
  27. package/types/js/figure/DrawingObjects/HTMLObject/HTMLObject.d.ts +29 -0
  28. package/types/js/figure/DrawingObjects/TextObject/TextObject.d.ts +94 -0
  29. package/types/js/figure/DrawingObjects/TextObject/glyphMeasures.d.ts +7 -0
  30. package/types/js/figure/DrawingObjects/VertexObject/VertexGeneric.d.ts +21 -0
  31. package/types/js/figure/DrawingObjects/VertexObject/VertexObject.d.ts +0 -0
  32. package/types/js/figure/DrawingObjects/VertexObject/VertexText.d.ts +34 -0
  33. package/types/js/figure/Element.d.ts +1212 -0
  34. package/types/js/figure/Equation/Elements/BaseAnnotationFunction.d.ts +118 -0
  35. package/types/js/figure/Equation/Elements/BaseEquationFunction.d.ts +20 -0
  36. package/types/js/figure/Equation/Elements/Bounds.d.ts +49 -0
  37. package/types/js/figure/Equation/Elements/Color.d.ts +7 -0
  38. package/types/js/figure/Equation/Elements/Container.d.ts +5 -0
  39. package/types/js/figure/Equation/Elements/Element.d.ts +95 -0
  40. package/types/js/figure/Equation/Elements/Fraction.d.ts +5 -0
  41. package/types/js/figure/Equation/Elements/Lines.d.ts +5 -0
  42. package/types/js/figure/Equation/Elements/Matrix.d.ts +5 -0
  43. package/types/js/figure/Equation/Elements/Offset.d.ts +5 -0
  44. package/types/js/figure/Equation/Elements/Scale.d.ts +5 -0
  45. package/types/js/figure/Equation/Equation.d.ts +984 -0
  46. package/types/js/figure/Equation/EquationForm.d.ts +139 -0
  47. package/types/js/figure/Equation/EquationFunctions.d.ts +3367 -0
  48. package/types/js/figure/Equation/EquationSymbols.d.ts +1646 -0
  49. package/types/js/figure/Equation/HTMLEquation.d.ts +56 -0
  50. package/types/js/figure/Equation/Symbols/AngleBracket.d.ts +6 -0
  51. package/types/js/figure/Equation/Symbols/Arrow.d.ts +17 -0
  52. package/types/js/figure/Equation/Symbols/Bar.d.ts +6 -0
  53. package/types/js/figure/Equation/Symbols/Box.d.ts +11 -0
  54. package/types/js/figure/Equation/Symbols/Brace.d.ts +6 -0
  55. package/types/js/figure/Equation/Symbols/Bracket.d.ts +8 -0
  56. package/types/js/figure/Equation/Symbols/Division.d.ts +8 -0
  57. package/types/js/figure/Equation/Symbols/Integral.d.ts +7 -0
  58. package/types/js/figure/Equation/Symbols/Line.d.ts +5 -0
  59. package/types/js/figure/Equation/Symbols/Product.d.ts +6 -0
  60. package/types/js/figure/Equation/Symbols/Radical.d.ts +9 -0
  61. package/types/js/figure/Equation/Symbols/SquareBracket.d.ts +6 -0
  62. package/types/js/figure/Equation/Symbols/Strike.d.ts +8 -0
  63. package/types/js/figure/Equation/Symbols/Sum.d.ts +6 -0
  64. package/types/js/figure/Equation/Symbols/SymbolNew.d.ts +15 -0
  65. package/types/js/figure/Equation/Symbols/Vinculum.d.ts +6 -0
  66. package/types/js/figure/Figure.d.ts +711 -0
  67. package/types/js/figure/FigureCollections/Angle.d.ts +766 -0
  68. package/types/js/figure/FigureCollections/Axis.d.ts +517 -0
  69. package/types/js/figure/FigureCollections/Axis3.d.ts +118 -0
  70. package/types/js/figure/FigureCollections/Button.d.ts +195 -0
  71. package/types/js/figure/FigureCollections/EquationLabel.d.ts +77 -0
  72. package/types/js/figure/FigureCollections/FigureCollections.d.ts +122 -0
  73. package/types/js/figure/FigureCollections/Legend.d.ts +270 -0
  74. package/types/js/figure/FigureCollections/Line.d.ts +587 -0
  75. package/types/js/figure/FigureCollections/Plot.d.ts +558 -0
  76. package/types/js/figure/FigureCollections/PolyLine.d.ts +487 -0
  77. package/types/js/figure/FigureCollections/Rectangle.d.ts +235 -0
  78. package/types/js/figure/FigureCollections/SlideNavigator.d.ts +255 -0
  79. package/types/js/figure/FigureCollections/Slider.d.ts +155 -0
  80. package/types/js/figure/FigureCollections/Text.d.ts +307 -0
  81. package/types/js/figure/FigureCollections/Toggle.d.ts +185 -0
  82. package/types/js/figure/FigureCollections/Trace.d.ts +237 -0
  83. package/types/js/figure/FigurePrimitives/FigureElementPrimitive2DText.d.ts +119 -0
  84. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGLText.d.ts +94 -0
  85. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGesture.d.ts +536 -0
  86. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveMorph.d.ts +175 -0
  87. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes.d.ts +788 -0
  88. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes2D.d.ts +1324 -0
  89. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes3D.d.ts +1105 -0
  90. package/types/js/figure/FigurePrimitives/FigurePrimitives.d.ts +173 -0
  91. package/types/js/figure/FigurePrimitives/Generic.d.ts +5 -0
  92. package/types/js/figure/FigurePrimitives/Text.d.ts +17 -0
  93. package/types/js/figure/FontManager.d.ts +113 -0
  94. package/types/js/figure/Gesture.d.ts +39 -0
  95. package/types/js/figure/Recorder/Recorder.d.ts +291 -0
  96. package/types/js/figure/Recorder/parseState.d.ts +3 -0
  97. package/types/js/figure/Recorder/recorder.worker.d.ts +1 -0
  98. package/types/js/figure/Recorder/state.d.ts +7 -0
  99. package/types/js/figure/SlideNavigator.d.ts +606 -0
  100. package/types/js/figure/TimeKeeper.d.ts +174 -0
  101. package/types/js/figure/geometries/arc.d.ts +18 -0
  102. package/types/js/figure/geometries/arrow.d.ts +215 -0
  103. package/types/js/figure/geometries/buffer.d.ts +4 -0
  104. package/types/js/figure/geometries/copy/copy.d.ts +178 -0
  105. package/types/js/figure/geometries/ellipse.d.ts +17 -0
  106. package/types/js/figure/geometries/line.d.ts +13 -0
  107. package/types/js/figure/geometries/lines/corners.d.ts +7 -0
  108. package/types/js/figure/geometries/lines/dashes.d.ts +23 -0
  109. package/types/js/figure/geometries/lines/lines.d.ts +31 -0
  110. package/types/js/figure/geometries/polygon/polygon.d.ts +12 -0
  111. package/types/js/figure/geometries/rectangle.d.ts +19 -0
  112. package/types/js/figure/geometries/triangle.d.ts +27 -0
  113. package/types/js/figure/webgl/Atlas.d.ts +42 -0
  114. package/types/js/figure/webgl/shaders.d.ts +143 -0
  115. package/types/js/figure/webgl/target.d.ts +9 -0
  116. package/types/js/figure/webgl/webgl.d.ts +54 -0
  117. package/types/js/tools/FunctionMap.d.ts +69 -0
  118. package/types/js/tools/color.d.ts +11 -0
  119. package/types/js/tools/colorNames.d.ts +2 -0
  120. package/types/js/tools/d2/polygon.d.ts +60 -0
  121. package/types/js/tools/d2/triangles.d.ts +0 -0
  122. package/types/js/tools/d3/cone.d.ts +57 -0
  123. package/types/js/tools/d3/cube.d.ts +26 -0
  124. package/types/js/tools/d3/cylinder.d.ts +45 -0
  125. package/types/js/tools/d3/line3.d.ts +55 -0
  126. package/types/js/tools/d3/prism.d.ts +49 -0
  127. package/types/js/tools/d3/revolve.d.ts +87 -0
  128. package/types/js/tools/d3/sphere.d.ts +33 -0
  129. package/types/js/tools/d3/surface.d.ts +47 -0
  130. package/types/js/tools/g2.d.ts +242 -0
  131. package/types/js/tools/geometry/Bounds.d.ts +446 -0
  132. package/types/js/tools/geometry/Line.d.ts +314 -0
  133. package/types/js/tools/geometry/Path.d.ts +67 -0
  134. package/types/js/tools/geometry/Plane.d.ts +201 -0
  135. package/types/js/tools/geometry/Point.d.ts +359 -0
  136. package/types/js/tools/geometry/Rect.d.ts +115 -0
  137. package/types/js/tools/geometry/Transform.d.ts +623 -0
  138. package/types/js/tools/geometry/angle.d.ts +105 -0
  139. package/types/js/tools/geometry/common.d.ts +9 -0
  140. package/types/js/tools/geometry/coordinates.d.ts +30 -0
  141. package/types/js/tools/geometry/deceleration.d.ts +13 -0
  142. package/types/js/tools/geometry/polygon.d.ts +4 -0
  143. package/types/js/tools/geometry/quaternion.d.ts +15 -0
  144. package/types/js/tools/geometry/scene.d.ts +282 -0
  145. package/types/js/tools/geometry/tools.d.ts +8 -0
  146. package/types/js/tools/geometry/types.d.ts +2 -0
  147. package/types/js/tools/getCssColors.d.ts +1 -0
  148. package/types/js/tools/getCssVariables.d.ts +4 -0
  149. package/types/js/tools/getImageData.d.ts +1 -0
  150. package/types/js/tools/getScssColors.d.ts +2 -0
  151. package/types/js/tools/htmlGenerator.d.ts +85 -0
  152. package/types/js/tools/m2.d.ts +24 -0
  153. package/types/js/tools/m3.d.ts +71 -0
  154. package/types/js/tools/math.d.ts +112 -0
  155. package/types/js/tools/morph.d.ts +651 -0
  156. package/types/js/tools/styleSheets.d.ts +3 -0
  157. package/types/js/tools/tools.d.ts +281 -0
  158. package/types/js/tools/types.d.ts +305 -0
  159. package/figureone.worker.js +0 -1
@@ -0,0 +1,237 @@
1
+ import { Point } from '../../tools/g2';
2
+ import type { TypeParsablePoint } from '../../tools/g2';
3
+ import { FigureElementCollection, FigureElementPrimitive } from '../Element';
4
+ import type CollectionsAxis from './Axis';
5
+ import type { COL_Axis } from './Axis';
6
+ import type { OBJ_Line, OBJ_Polygon, OBJ_Star } from '../FigurePrimitives/FigurePrimitiveTypes2D';
7
+ import type { OBJ_LineStyleSimple, OBJ_Collection } from '../FigurePrimitives/FigurePrimitiveTypes';
8
+ import type { TypeColor, OBJ_Font_Fixed } from '../../tools/types';
9
+ import type { CPY_Steps } from '../geometries/copy/copy';
10
+ import type FigureCollections from './FigureCollections';
11
+ /**
12
+ * {@link CollectionsTrace} options object that extends {@link OBJ_Collection}
13
+ * options object (without `parent`).
14
+ *
15
+ * A plot trace is a set of (x, y) points associated with an
16
+ * x and y axis.
17
+ *
18
+ * The trace and can be drawn with either a set of
19
+ * `markers` at each point, or a `line` between each pair of adjacent points.
20
+ *
21
+ * The axes are used to plot the trace - the trace
22
+ * can only appear within the bounds of the axes, and the axes
23
+ * provide the mapping from axis value to draw space so the trace
24
+ * can be drawn. Points that lie outside the axis will not be draw,
25
+ * and lines between pairs of points where one is outside will be interpolated.
26
+ *
27
+ * While FigureOne isn't designed to process very large numbers of points,
28
+ * some steps can be taken to improve performance when large numbers of points
29
+ * are being used (tens of thousands or more):
30
+ * - Turn off corner interpolation between line segments in `line`:
31
+ * `{ line: { corner: 'none` } }`
32
+ * - Use `xSampleDistance` and `ySampleDistance` to not draw points that are
33
+ * too close to each other
34
+ * - If using markers, use polygons with smaller numbers of sides, and use fills
35
+ * instead of outlines
36
+ *
37
+ * Even using these methods, it can take up to a second to render a trace with
38
+ * hundreds of thousands of points (depending on the client device).
39
+ *
40
+ * @extends OBJ_Collection
41
+ *
42
+ * @property {Array<TypeParsablePoint>} points the x points of the trace
43
+ * @property {COL_Axis | string} [xAxis] The x axis associated with the trace,
44
+ * if this is a string, the trace must be part of a plot with an axis with the
45
+ * same name. In plots, this will default to the string `'x'`.
46
+ * @property {COL_Axis | string} [yAxis] The y axis associated with the trace,
47
+ * if this is a string, the trace must be part of a plot with an axis with the
48
+ * same name. In plots, this will default to the string `'y'`.
49
+ * @property {OBJ_LineStyleSimple} [line] line style of the trace - if neither `line` nor
50
+ * `markers` is defined, then `line` will default to a solid line. If `line`
51
+ * is not defined, but `markers` is, then only markers will be used to represent
52
+ * the line
53
+ * @property {OBJ_Polygon | OBJ_Star} [markers] marker style of the trace
54
+ * @property {TypeColor} [color] color of the trace
55
+ * @property {string} [name] name of the trace used in plot legends
56
+ * @property {number} [xSampleDistance] If x distance between points is less
57
+ * than this value, then the later point will not be plotted. By default this is
58
+ * 1/4000th the range of the x axis
59
+ * @property {number} [ySampleDistance] If y distance between points is less
60
+ * than this value, then the later point will not be plotted. By default this is
61
+ * 1/4000th the range of the y axis
62
+ *
63
+ * @see
64
+ * For more examples on using traces, see {@link CollectionsPlot}
65
+ *
66
+ * To test examples below, append them to the
67
+ * <a href="#drawing-boilerplate">boilerplate</a>.
68
+ *
69
+ * @interface
70
+ * @group Misc Shapes
71
+ */
72
+ export type COL_Trace = {
73
+ points: Array<TypeParsablePoint>;
74
+ xAxis?: COL_Axis | string;
75
+ yAxis?: COL_Axis | string;
76
+ x?: Array<TypeParsablePoint>;
77
+ y?: Array<TypeParsablePoint>;
78
+ line?: OBJ_LineStyleSimple;
79
+ markers?: OBJ_Polygon | OBJ_Star;
80
+ color?: TypeColor;
81
+ name?: string;
82
+ xSampleDistance?: number;
83
+ ySampleDistance?: number;
84
+ } & OBJ_Collection;
85
+ /**
86
+ * {@link FigureElementCollection} representing a trace.
87
+ *
88
+ * ![](./apiassets/advtrace_ex1.png)
89
+ * ![](./apiassets/advtrace_ex2.png)
90
+ *
91
+ * ![](./apiassets/advtrace_ex3.png)
92
+ * ![](./apiassets/advtrace_ex4.png)
93
+ *
94
+ * ![](./apiassets/advtrace_ex5.png)
95
+ * ![](./apiassets/advtrace_ex6.png)
96
+ *
97
+ * This object defines a trace in an {@link CollectionsPlot}.
98
+ *
99
+ * The trace includes all the points of the trace, and the axes that it
100
+ * should be drawn against and is defined using the {@link COL_PlotTrace}
101
+ * options object.
102
+ *
103
+ * To test examples below, append them to the
104
+ * <a href="#drawing-boilerplate">boilerplate</a>.
105
+ *
106
+ * All examples below also use this power function to generate the traces:
107
+ * ```javascript
108
+ * const pow = (pow = 2, start = 0, stop = 10, step = 0.05) => {
109
+ * const xValues = Fig.range(start, stop, step);
110
+ * return xValues.map(x => new Fig.Point(x, x ** pow));
111
+ * }
112
+ * ```
113
+ *
114
+ * @example
115
+ * // When plotting a single trace, just the points are required. By default
116
+ * // the line will be solid, and it will be plotted against the 'x' and 'y' axes.
117
+ * figure.add({
118
+ * name: 'plot',
119
+ * make: 'collections.plot',
120
+ * trace: pow(),
121
+ * });
122
+ *
123
+ * @example
124
+ * // Change the thickness and color of the line
125
+ * figure.add({
126
+ * name: 'plot',
127
+ * make: 'collections.plot',
128
+ * trace: {
129
+ * points: pow(),
130
+ * line: {
131
+ * width: 0.03,
132
+ * color: [0, 0.8, 0.4, 1],
133
+ * }
134
+ * },
135
+ * });
136
+ *
137
+ * @example
138
+ * // Default Markers
139
+ * figure.add({
140
+ * name: 'plot',
141
+ * make: 'collections.plot',
142
+ * trace: {
143
+ * points: pow(2, 0, 10, 1),
144
+ * markers: true,
145
+ * },
146
+ * });
147
+ *
148
+ * @example
149
+ * // Custom Markers
150
+ * figure.add({
151
+ * name: 'plot',
152
+ * make: 'collections.plot',
153
+ * trace: {
154
+ * points: pow(2, 0, 10, 1),
155
+ * markers: {
156
+ * radius: 0.035,
157
+ * sides: 20,
158
+ * line: { width: 0.01 },
159
+ * },
160
+ * },
161
+ * });
162
+ *
163
+ * @example
164
+ * // Line and markers
165
+ * figure.add({
166
+ * name: 'plot',
167
+ * make: 'collections.plot',
168
+ * trace: {
169
+ * points: pow(2, 0, 10, 1),
170
+ * line: { width: 0.01, dash: [0.02, 0.01] },
171
+ * markers: {
172
+ * radius: 0.035,
173
+ * sides: 20,
174
+ * },
175
+ * },
176
+ * });
177
+ *
178
+ * @example
179
+ * // Use names in trace definitions to customize legend
180
+ * figure.add({
181
+ * name: 'plot',
182
+ * make: 'collections.plot',
183
+ * trace: [
184
+ * pow(2),
185
+ * { points: pow(2.5), name: 'Power 2.5' },
186
+ * {
187
+ * points: pow(3, 0, 10, 1),
188
+ * name: 'Power 3',
189
+ * markers: { radius: 0.03 },
190
+ * line: { width: 0.01 },
191
+ * },
192
+ * ],
193
+ * legend: true,
194
+ * });
195
+ * @group Misc Shapes
196
+ */
197
+ declare class CollectionsTrace extends FigureElementCollection {
198
+ _line: FigureElementPrimitive | null | undefined;
199
+ points: Array<Point>;
200
+ drawPoints: Array<Point>;
201
+ polylines: Array<Array<Point>>;
202
+ xAxis: CollectionsAxis;
203
+ yAxis: CollectionsAxis;
204
+ line: OBJ_Line;
205
+ defaultFont: OBJ_Font_Fixed;
206
+ xSampleDistance: number;
207
+ ySampleDistance: number;
208
+ markers: (OBJ_Polygon | OBJ_Star) & {
209
+ copy: CPY_Steps;
210
+ };
211
+ name: string;
212
+ /**
213
+ * @hideconstructor
214
+ */
215
+ constructor(collections: FigureCollections, optionsIn: COL_Trace);
216
+ /**
217
+ * Update the trace with a new set of points.
218
+ * @param {Array<TypeParsablePoint>} points
219
+ */
220
+ update(points: Array<TypeParsablePoint>): void;
221
+ updateAxes(): void;
222
+ getY(xValue: number, precision?: number): number[];
223
+ getX(yValue: number, precision?: number): number[];
224
+ pointToDraw(p: Point): Point;
225
+ inAxes(p: Point): boolean;
226
+ intersect(p1: Point, p2: Point): {
227
+ result: boolean;
228
+ intersect?: Array<Point>;
229
+ };
230
+ updatePoints(): void;
231
+ addLine(options: OBJ_LineStyleSimple): void;
232
+ removeLine(): void;
233
+ removeMarkers(): void;
234
+ addMarkers(options: OBJ_Polygon | OBJ_Star): void;
235
+ _getStateProperties(options: Record<string, any>): string[];
236
+ }
237
+ export default CollectionsTrace;
@@ -0,0 +1,119 @@
1
+ import { FigureElementPrimitive } from '../Element';
2
+ import type { FigureElement } from '../Element';
3
+ import { Point, Rect } from '../../tools/g2';
4
+ import type { Transform } from '../../tools/g2';
5
+ import type Scene from '../../tools/geometry/scene';
6
+ import type { Type3DMatrix } from '../../tools/m3';
7
+ import DrawingObject from '../DrawingObjects/DrawingObject';
8
+ import { FigureFont } from '../DrawingObjects/TextObject/TextObject';
9
+ import type { OBJ_Font, TypeColor } from '../../tools/types';
10
+ import type { OBJ_Text, OBJ_SetText } from './FigurePrimitiveTypes';
11
+ import type DrawContext2D from '../DrawContext2D';
12
+ declare class TextObject extends DrawingObject {
13
+ drawContext2D: DrawContext2D;
14
+ scalingFactor: number;
15
+ lastDrawTransform: Array<number>;
16
+ bounds: Rect;
17
+ textBorder: Array<Array<Point>>;
18
+ text: Array<string>;
19
+ location: any;
20
+ alignedLocation: Array<Point>;
21
+ font: FigureFont;
22
+ xAlign: 'left' | 'center' | 'right';
23
+ yAlign: 'top' | 'bottom' | 'middle' | 'alphabetic' | 'baseline';
24
+ measure: {
25
+ ascent: number;
26
+ descent: number;
27
+ width: number;
28
+ top: number;
29
+ left: number;
30
+ bottom: number;
31
+ right: number;
32
+ border: Array<Array<Point>>;
33
+ };
34
+ measurements: Array<{
35
+ left: number;
36
+ right: number;
37
+ bottom: number;
38
+ top: number;
39
+ }>;
40
+ lastDraw: Array<{
41
+ x: number;
42
+ y: number;
43
+ width: number;
44
+ height: number;
45
+ }>;
46
+ adjustments: {
47
+ ascent: number;
48
+ descent: number;
49
+ width: number;
50
+ };
51
+ constructor(drawContext2D: DrawContext2D, options: OBJ_Text);
52
+ watch(callback: string | (() => void)): void;
53
+ getCanvas(): HTMLCanvasElement;
54
+ calcScalingFactor(): void;
55
+ setText(text: Array<string> | string | OBJ_SetText): void;
56
+ setFont(font: OBJ_Font): void;
57
+ measureText(ctx?: CanvasRenderingContext2D, scalingFactor?: number): {
58
+ ascent: number;
59
+ descent: number;
60
+ width: number;
61
+ top: number;
62
+ left: number;
63
+ bottom: number;
64
+ right: number;
65
+ border: Array<Array<Point>>;
66
+ };
67
+ calcBorder(): void;
68
+ drawWithTransformMatrix(scene: Scene, worldMatrix: Type3DMatrix, color?: TypeColor): void;
69
+ clear(): void;
70
+ _state(): Record<string, any>;
71
+ }
72
+ /**
73
+ * FigureElementPrimitive that handles drawing text on a 2D canvas.
74
+ * @group Misc Text
75
+ */
76
+ export default class FigureElementPrimitive2DText extends FigureElementPrimitive {
77
+ drawingObject: TextObject;
78
+ constructor(drawContext2D: DrawContext2D, options: OBJ_Text & {
79
+ parent: null | FigureElement;
80
+ transform: Transform;
81
+ color: TypeColor;
82
+ name: string;
83
+ });
84
+ /**
85
+ * Change the text in the primitive.
86
+ *
87
+ * @param {string | OBJ_SetText} text
88
+ */
89
+ setText(text: string | OBJ_SetText): void;
90
+ calcBorderAndBounds(): void;
91
+ calcBorder(): void;
92
+ calcTouchBorder(): void;
93
+ /**
94
+ * Change only the font of the text.
95
+ *
96
+ * @param {OBJ_Font} font
97
+ */
98
+ setFont(font: OBJ_Font): void;
99
+ /**
100
+ * Get the text shown by the primitive.
101
+ *
102
+ * @return {string}
103
+ */
104
+ getText(): string;
105
+ /**
106
+ * Get the font of the text.
107
+ *
108
+ * @return {FigureFont}
109
+ */
110
+ getFont(): FigureFont;
111
+ setColor(color: TypeColor, setDefault?: boolean): void;
112
+ stateSet(): void;
113
+ measureAndAlignText(): void;
114
+ _getStateProperties(options: {
115
+ ignoreShown?: boolean;
116
+ }): string[];
117
+ getFonts(): (string | boolean | FigureFont)[][];
118
+ }
119
+ export {};
@@ -0,0 +1,94 @@
1
+ import { FigureElementPrimitive } from '../Element';
2
+ import { Point } from '../../tools/g2';
3
+ import type GLObject from '../DrawingObjects/GLObject/GLObject';
4
+ import { FigureFont } from '../DrawingObjects/TextObject/TextObject';
5
+ import type { OBJ_Font, TypeColor } from '../../tools/types';
6
+ import Scene from '../../tools/geometry/scene';
7
+ import type { OBJ_Text_Fixed, OBJ_SetText } from './FigurePrimitiveTypes';
8
+ /**
9
+ * FigureElementPrimitive that handles drawing text in WebGL.
10
+ *
11
+ * WebGL text is rendered using a texture atlas of fonts - an image
12
+ * with all the glyphs, and a map of the locations, ascent, descent and width
13
+ * of each glyph.
14
+ * @group Misc Text
15
+ */
16
+ export default class FigureElementPrimitiveGLText extends FigureElementPrimitive {
17
+ text: Array<string>;
18
+ font: FigureFont;
19
+ atlas: Record<string, any>;
20
+ adjustments: {
21
+ width: number;
22
+ descent: number;
23
+ ascent: number;
24
+ };
25
+ measure: {
26
+ ascent: number;
27
+ descent: number;
28
+ width: number;
29
+ left: number;
30
+ right: number;
31
+ top: number;
32
+ bottom: number;
33
+ border: Array<Array<Point>>;
34
+ };
35
+ location: Array<Point>;
36
+ fontSize: number;
37
+ xAlign: 'left' | 'center' | 'right';
38
+ yAlign: 'top' | 'bottom' | 'middle' | 'alphabetic' | 'baseline';
39
+ drawingObject: GLObject;
40
+ atlasNotificationsID: number;
41
+ setup(options: OBJ_Text_Fixed): void;
42
+ createAtlas(sceneIn?: Scene): void;
43
+ /**
44
+ * Debug method - will replace the drawn text with the texture atlas so it
45
+ * can be reviewed.
46
+ *
47
+ * @param {number} dimension size of the texture atlas to draw (`1`)
48
+ */
49
+ showMap(dimension?: number): void;
50
+ /**
51
+ * Recreate texture atlas.
52
+ *
53
+ * This is useful if a font has changed after an atlas has been
54
+ * auto-generated. Recreating the atlas will use the new version of the
55
+ * font.
56
+ */
57
+ recreateAtlas(): void;
58
+ loaded(): void;
59
+ measureAndAlignText(): void;
60
+ /**
61
+ * Change the text in the primitive.
62
+ *
63
+ * @param {string | OBJ_SetText} text
64
+ */
65
+ setText(text: string | Array<string> | OBJ_SetText): void;
66
+ /**
67
+ * Get the text shown by the primitive.
68
+ *
69
+ * @return {string}
70
+ */
71
+ getText(): string;
72
+ /**
73
+ * Get the font of the text.
74
+ *
75
+ * @return {FigureFont}
76
+ */
77
+ getFont(): FigureFont;
78
+ /**
79
+ * Change only the font of the text.
80
+ *
81
+ * @param {OBJ_Font} font
82
+ */
83
+ setFont(font: OBJ_Font): void;
84
+ setColor(color: TypeColor, setDefault?: boolean): void;
85
+ calcBorderAndBounds(): void;
86
+ calcBorder(): void;
87
+ stateSet(): void;
88
+ cleanup(): void;
89
+ calcTouchBorder(): void;
90
+ _getStateProperties(options: {
91
+ ignoreShown?: boolean;
92
+ }): string[];
93
+ getFonts(): (string | boolean | FigureFont)[][];
94
+ }