@woosh/meep-engine 2.134.5 → 2.135.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 (155) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/editor/tools/v2/TransformControlsGizmo.js +1 -1
  4. package/editor/view/node-graph/NodeGraphEditorView.js +2 -2
  5. package/package.json +1 -1
  6. package/src/core/assert.d.ts +0 -2
  7. package/src/core/assert.d.ts.map +1 -1
  8. package/src/core/assert.js +0 -6
  9. package/src/core/color/Color.d.ts +0 -5
  10. package/src/core/color/Color.d.ts.map +1 -1
  11. package/src/core/color/Color.js +1 -7
  12. package/src/core/geom/2d/hash-grid/SpatialHashGrid.js +386 -386
  13. package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_2d.js +1 -1
  14. package/src/core/geom/2d/quad-tree-binary/QuadTree.js +714 -714
  15. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +160 -160
  16. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +96 -96
  17. package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +1 -1
  18. package/src/core/geom/packing/max-rect/findBestContainer.js +4 -4
  19. package/src/core/geom/packing/max-rect/packOneBox.js +2 -2
  20. package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.js +1 -1
  21. package/src/core/graph/layout/box/BoxLayouter.js +7 -7
  22. package/src/core/graph/layout/box/position_box_next_to_box.js +6 -6
  23. package/src/core/math/computeWholeDivisorLow.js +33 -33
  24. package/src/core/math/linalg/eigen/eigen_values_find_spectral_gap.d.ts.map +1 -0
  25. package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts +10 -0
  26. package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts.map +1 -0
  27. package/src/core/{graph → math/linalg}/eigen/matrix_eigenvalues_in_place.js +8 -7
  28. package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts.map +1 -0
  29. package/src/core/{graph → math/linalg}/eigen/matrix_householder_in_place.js +11 -5
  30. package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts +15 -0
  31. package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts.map +1 -0
  32. package/src/core/{graph → math/linalg}/eigen/matrix_qr_in_place.js +8 -2
  33. package/src/core/{graph → math/linalg}/eigen/matrix_top_eigenvector_power_iteration.d.ts +0 -3
  34. package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts.map +1 -0
  35. package/src/core/{graph → math/linalg}/eigen/matrix_top_eigenvector_power_iteration.js +0 -3
  36. package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts +19 -0
  37. package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts.map +1 -0
  38. package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.js +161 -0
  39. package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts +15 -0
  40. package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts.map +1 -0
  41. package/src/core/math/linalg/polynomial_real_roots_in_interval.js +200 -0
  42. package/src/core/math/solveCubic.d.ts +15 -0
  43. package/src/core/math/solveCubic.d.ts.map +1 -0
  44. package/src/core/math/solveCubic.js +82 -0
  45. package/src/core/math/spline/spline3_hermite_bounds_t.d.ts +23 -0
  46. package/src/core/math/spline/spline3_hermite_bounds_t.d.ts.map +1 -0
  47. package/src/core/math/spline/spline3_hermite_bounds_t.js +109 -0
  48. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts +25 -0
  49. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts.map +1 -0
  50. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.js +44 -0
  51. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts +16 -0
  52. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts.map +1 -0
  53. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.js +120 -0
  54. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts +11 -0
  55. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts.map +1 -0
  56. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.js +451 -0
  57. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts +12 -0
  58. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts.map +1 -0
  59. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.js +339 -0
  60. package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts +15 -0
  61. package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts.map +1 -0
  62. package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.js +21 -0
  63. package/src/core/math/spline/spline3_hermite_to_monomial.d.ts +24 -0
  64. package/src/core/math/spline/spline3_hermite_to_monomial.d.ts.map +1 -0
  65. package/src/core/math/spline/spline3_hermite_to_monomial.js +37 -0
  66. package/src/core/math/spline/v3_computeCatmullRomSplineUniformDistance.js +1 -1
  67. package/src/core/model/node-graph/visual/NodeGraphVisualData.js +1 -1
  68. package/src/core/model/reactive/model/util/createRandomReactiveExpression.js +185 -185
  69. package/src/core/process/delay.js +16 -16
  70. package/src/engine/animation/async/TimeSeries.js +300 -300
  71. package/src/engine/animation/curve/AnimationCurve.d.ts +0 -4
  72. package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
  73. package/src/engine/animation/curve/AnimationCurve.js +1 -6
  74. package/src/engine/animation/curve/draw/position_canvas_to_curve.js +2 -2
  75. package/src/engine/animation/curve/draw/position_curve_to_canvas.js +2 -2
  76. package/src/engine/ecs/fow/shader/FogOfWarRenderer.js +145 -145
  77. package/src/engine/ecs/gui/position/ViewportPositionSystem.js +2 -2
  78. package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
  79. package/src/engine/ecs/transform/Transform.d.ts +0 -10
  80. package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
  81. package/src/engine/ecs/transform/Transform.js +0 -12
  82. package/src/engine/graphics/composit/CompositLayer.js +254 -254
  83. package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.js +1 -1
  84. package/src/engine/graphics/ecs/path/tube/build/build_geometry_linear.js +2 -2
  85. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +3 -3
  86. package/src/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +201 -201
  87. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  88. package/src/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +2 -2
  89. package/src/engine/graphics/render/forward_plus/LightManager.js +1226 -1226
  90. package/src/engine/graphics/render/forward_plus/model/PointLight.js +1 -1
  91. package/src/engine/graphics/sh3/lpv/lpv_obtain_storage_cached_volume.js +1 -1
  92. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +2 -2
  93. package/src/engine/graphics/texture/atlas/TextureAtlasDebugger.js +1 -1
  94. package/src/engine/graphics/texture/sampler/HarmonicDiffusionGrid.js +145 -145
  95. package/src/engine/graphics/texture/sampler/serialization/TextureBinaryBufferSerializer.js +2 -2
  96. package/src/engine/intelligence/behavior/ecs/BehaviorComponent.d.ts +2 -6
  97. package/src/engine/intelligence/behavior/ecs/BehaviorComponent.d.ts.map +1 -1
  98. package/src/engine/intelligence/behavior/ecs/BehaviorComponent.js +0 -10
  99. package/src/engine/intelligence/mcts/MonteCarlo.js +275 -275
  100. package/src/engine/navigation/ecs/path_following/PathFollower.js +222 -222
  101. package/src/generation/grid/GridData.js +220 -220
  102. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +385 -385
  103. package/src/view/elements/image/SvgImageView.js +1 -1
  104. package/src/view/elements/windrose/WindRoseDiagram.js +369 -369
  105. package/src/view/minimap/gl/MinimapFogOfWar.js +3 -3
  106. package/src/view/util/DomSizeObserver.js +1 -1
  107. package/src/core/binary/clz32.d.ts +0 -6
  108. package/src/core/binary/clz32.d.ts.map +0 -1
  109. package/src/core/binary/clz32.js +0 -5
  110. package/src/core/binary/type/dataTypeFromTypedArray.d.ts +0 -8
  111. package/src/core/binary/type/dataTypeFromTypedArray.d.ts.map +0 -1
  112. package/src/core/binary/type/dataTypeFromTypedArray.js +0 -11
  113. package/src/core/collection/array/computeHashIntegerArray.d.ts +0 -1
  114. package/src/core/collection/array/computeHashIntegerArray.d.ts.map +0 -1
  115. package/src/core/collection/array/computeHashIntegerArray.js +0 -7
  116. package/src/core/collection/array/typed/typedArrayToDataType.d.ts +0 -6
  117. package/src/core/collection/array/typed/typedArrayToDataType.d.ts.map +0 -1
  118. package/src/core/collection/array/typed/typedArrayToDataType.js +0 -6
  119. package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.d.ts +0 -6
  120. package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.d.ts.map +0 -1
  121. package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.js +0 -7
  122. package/src/core/graph/eigen/eigen_values_find_spectral_gap.d.ts.map +0 -1
  123. package/src/core/graph/eigen/matrix_eigenvalues_in_place.d.ts +0 -8
  124. package/src/core/graph/eigen/matrix_eigenvalues_in_place.d.ts.map +0 -1
  125. package/src/core/graph/eigen/matrix_householder_in_place.d.ts.map +0 -1
  126. package/src/core/graph/eigen/matrix_qr_in_place.d.ts +0 -9
  127. package/src/core/graph/eigen/matrix_qr_in_place.d.ts.map +0 -1
  128. package/src/core/graph/eigen/matrix_top_eigenvector_power_iteration.d.ts.map +0 -1
  129. package/src/core/math/spline/cubicCurve.d.ts +0 -6
  130. package/src/core/math/spline/cubicCurve.d.ts.map +0 -1
  131. package/src/core/math/spline/cubicCurve.js +0 -6
  132. package/src/core/math/spline/spline_bezier2.d.ts +0 -6
  133. package/src/core/math/spline/spline_bezier2.d.ts.map +0 -1
  134. package/src/core/math/spline/spline_bezier2.js +0 -6
  135. package/src/core/math/spline/spline_bezier3.d.ts +0 -6
  136. package/src/core/math/spline/spline_bezier3.d.ts.map +0 -1
  137. package/src/core/math/spline/spline_bezier3.js +0 -6
  138. package/src/core/math/spline/spline_bezier3_bounds.d.ts +0 -6
  139. package/src/core/math/spline/spline_bezier3_bounds.d.ts.map +0 -1
  140. package/src/core/math/spline/spline_bezier3_bounds.js +0 -6
  141. package/src/core/math/spline/spline_hermite3.d.ts +0 -6
  142. package/src/core/math/spline/spline_hermite3.d.ts.map +0 -1
  143. package/src/core/math/spline/spline_hermite3.js +0 -6
  144. package/src/core/math/spline/spline_hermite3_bounds.d.ts +0 -6
  145. package/src/core/math/spline/spline_hermite3_bounds.d.ts.map +0 -1
  146. package/src/core/math/spline/spline_hermite3_bounds.js +0 -6
  147. package/src/core/math/spline/spline_hermite3_to_bezier.d.ts +0 -2
  148. package/src/core/math/spline/spline_hermite3_to_bezier.d.ts.map +0 -1
  149. package/src/core/math/spline/spline_hermite3_to_bezier.js +0 -6
  150. package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.d.ts +0 -37
  151. package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.d.ts.map +0 -1
  152. package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.js +0 -70
  153. /package/src/core/{graph → math/linalg}/eigen/eigen_values_find_spectral_gap.d.ts +0 -0
  154. /package/src/core/{graph → math/linalg}/eigen/eigen_values_find_spectral_gap.js +0 -0
  155. /package/src/core/{graph → math/linalg}/eigen/matrix_householder_in_place.d.ts +0 -0
@@ -1,369 +1,369 @@
1
- import { assert } from "../../../core/assert.js";
2
- import { isDefined } from "../../../core/process/matcher/isDefined.js";
3
- import LabelView from "../../common/LabelView.js";
4
- import SVG from "../../SVG.js";
5
- import View from "../../View.js";
6
- import EmptyView from "../EmptyView.js";
7
- import ImageView from "../image/ImageView.js";
8
-
9
- export class WindRoseDiagram extends View {
10
-
11
- /**
12
- *
13
- * @param {{name:string,icon?:(View|string),value?:number,tooltip?:function, tooltipContext?:*}[]} axes
14
- * @param {number} value_mark_stride
15
- * @param {number} angular_offset
16
- * @param {number} radius
17
- * @param {number} value_max
18
- * @param {DomTooltipManager} [tooltips]
19
- */
20
- constructor({
21
- axes,
22
- angular_offset = 0,
23
- radius_inner = 200,
24
- radius_outer = radius_inner,
25
- value_max = 10,
26
- value_mark_stride = value_max / 5,
27
-
28
- icon_size = 32,
29
-
30
- tooltips,
31
-
32
- backplate_stroke_width = 2,
33
- backplate_stroke_color = 'rgba(0,0,0,1)',
34
- backplate_fill_color = 'rgba(99,99,99,1)',
35
- display_backplate = true,
36
-
37
- graph_stroke_width = 1,
38
- graph_stroke_color = 'rgba(0,0,0,1)',
39
- graph_fill_color = 'rgba(0,0,0,0.1)',
40
-
41
- mark_stroke_width = 1,
42
- mark_stroke_color = 'rgba(0,0,0,0.13)',
43
- display_marks = true,
44
-
45
- origin_radius = 8,
46
- origin_stroke_width = 0,
47
- origin_stroke_color = 'transparent',
48
- origin_fill_color = 'red',
49
- display_origin = true,
50
- classList = []
51
- }) {
52
- super();
53
-
54
- this.__axes = axes;
55
- this.__settings_value_max = value_max;
56
- this.__settings_value_mark_stride = value_mark_stride;
57
- this.__settings_angular_offset = angular_offset;
58
- this.__settings_icon_size = icon_size;
59
-
60
- this.__settings_graph_stroke_width = graph_stroke_width;
61
- this.__settings_graph_stroke_color = graph_stroke_color;
62
- this.__settings_graph_fill_color = graph_fill_color;
63
-
64
- this.__settings_backplate_stroke_width = backplate_stroke_width;
65
- this.__settings_backplate_stroke_color = backplate_stroke_color;
66
- this.__settings_backplate_fill_color = backplate_fill_color;
67
- this.__settings_display_backplate = display_backplate;
68
-
69
- this.__settings_mark_stroke_width = mark_stroke_width;
70
- this.__settings_mark_stroke_color = mark_stroke_color;
71
- this.__settings_display_marks = display_marks;
72
-
73
- this.__settings_origin_radius = origin_radius;
74
- this.__settings_origin_stroke_width = origin_stroke_width;
75
- this.__settings_origin_stroke_color = origin_stroke_color;
76
- this.__settings_origin_fill_color = origin_fill_color;
77
- this.__settings_display_origin = display_origin;
78
-
79
- this.__settings_radius_inner = radius_inner;
80
- this.__settings_radius_outer = radius_outer;
81
-
82
- this.__tooltips = tooltips;
83
-
84
- this.__values = new Float32Array(axes.length);
85
-
86
- this.el = document.createElement('div');
87
- this.addClass('ui-wind-rose-diagram-view');
88
- this.addClasses(classList);
89
-
90
- const has_icons = axes.some(isDefined);
91
-
92
- const size = radius_outer * 2 + (has_icons ? icon_size * (Math.SQRT1_2 + 0.5) * 2 : 0);
93
-
94
- this.size.set(size, size);
95
-
96
-
97
- this.__vCanvas = new EmptyView({
98
- classList: ['canvas']
99
- });
100
-
101
- this.addChild(this.__vCanvas);
102
-
103
- this.__vGraph = new EmptyView({
104
- classList: ["graph"],
105
- el: SVG.createElement('svg'),
106
- attr: {
107
- width: this.size.x * 2,
108
- height: this.size.y * 2
109
- },
110
- css: {
111
- position: 'absolute',
112
- left: 0,
113
- top: 0,
114
- overflow: 'visible'
115
- }
116
- });
117
- this.addChild(this.__vGraph);
118
-
119
- this.__svg_graph_path = SVG.createElement('path');
120
- this.__svg_graph_path.classList.add('graph-path-main');
121
- this.__svg_graph_path.setAttribute('stroke-width', this.__settings_graph_stroke_width);
122
- this.__svg_graph_path.setAttribute('stroke', this.__settings_graph_stroke_color);
123
- this.__svg_graph_path.setAttribute('fill', this.__settings_graph_fill_color);
124
-
125
- this.__vGraph.el.appendChild(this.__svg_graph_path);
126
-
127
- this.on.linked.add(this.draw, this);
128
-
129
- // process input axes
130
- for (let i = 0; i < axes.length; i++) {
131
- const axis = axes[i];
132
-
133
- assert.defined(axis, 'axis');
134
- assert.notNull(axis, 'axis');
135
-
136
- if (axis.value !== undefined) {
137
- this.set_axis_value(i, axis.value);
138
- }
139
- }
140
- }
141
-
142
- /**
143
- *
144
- * @param {number} index
145
- * @param {number} value
146
- */
147
- set_axis_value(index, value) {
148
- assert.isNonNegativeInteger(index, 'index');
149
- assert.isFiniteNumber(value, 'value');
150
-
151
- assert.lessThan(index, this.__axes.length, 'index overflow');
152
-
153
- this.__values[index] = value;
154
- }
155
-
156
- draw() {
157
- this.draw_canvas();
158
- this.draw_values();
159
- }
160
-
161
- __get_axis_count() {
162
- return this.__axes.length;
163
- }
164
-
165
- __get_axis_angle(index) {
166
- const axis_count = this.__get_axis_count();
167
- return index * Math.PI * (2 / axis_count) + this.__settings_angular_offset - Math.PI * 0.5;
168
- }
169
-
170
- __create_loop_path(radius) {
171
- const axis_count = this.__get_axis_count();
172
- const offset_x = this.size.x * 0.5;
173
- const offset_y = this.size.y * 0.5;
174
-
175
- let path = 'M';
176
-
177
- for (let i = 0; i < axis_count; i++) {
178
-
179
- const angle = this.__get_axis_angle(i);
180
- const cos = Math.cos(angle);
181
- const sin = Math.sin(angle);
182
-
183
- path += cos * radius + offset_x;
184
- path += ','
185
- path += sin * radius + offset_y;
186
-
187
- if (i < axis_count - 1) {
188
- path += 'L'
189
- } else {
190
- path += 'Z';
191
- }
192
- }
193
-
194
- return path;
195
- }
196
-
197
- draw_canvas() {
198
- const container = this.__vCanvas;
199
- container.removeAllChildren();
200
-
201
- const axis_count = this.__get_axis_count();
202
- const offset_x = this.size.x * 0.5;
203
- const offset_y = this.size.y * 0.5;
204
-
205
-
206
- // draw background and marks
207
- const svg_main = SVG.createElement('svg');
208
- svg_main.setAttribute('width', String(this.size.x));
209
- svg_main.setAttribute('height', String(this.size.y));
210
-
211
- if (this.__settings_display_backplate) {
212
- const svg_path = SVG.createElement('path');
213
-
214
- svg_path.classList.add('backplate');
215
-
216
- svg_path.setAttribute('d', this.__create_loop_path(this.__settings_radius_outer + this.__settings_backplate_stroke_width / 2));
217
- svg_path.setAttribute('stroke-width', String(this.__settings_backplate_stroke_width));
218
- svg_path.setAttribute('stroke', this.__settings_backplate_stroke_color);
219
- svg_path.setAttribute('fill', this.__settings_backplate_fill_color);
220
-
221
- svg_main.appendChild(svg_path);
222
- }
223
-
224
- if (this.__settings_display_marks) {
225
- for (let i = this.__settings_value_mark_stride; i < this.__settings_value_max; i += this.__settings_value_mark_stride) {
226
- const svg_path = SVG.createElement('path');
227
- svg_path.classList.add('mark');
228
-
229
- const f = i / this.__settings_value_max;
230
-
231
- const radius = f * this.__settings_radius_inner;
232
-
233
- svg_path.setAttribute('d', this.__create_loop_path(radius));
234
- svg_path.setAttribute('fill', 'none');
235
- svg_path.setAttribute('stroke-width', this.__settings_mark_stroke_width);
236
- svg_path.setAttribute('stroke', this.__settings_mark_stroke_color);
237
-
238
- svg_main.appendChild(svg_path);
239
- }
240
- }
241
-
242
- if (this.__settings_display_origin) {
243
- const svg_path = SVG.createElement('path');
244
-
245
- svg_path.classList.add('origin');
246
-
247
- svg_path.setAttribute('d', this.__create_loop_path(this.__settings_origin_radius));
248
- svg_path.setAttribute('fill', this.__settings_origin_fill_color);
249
- svg_path.setAttribute('stroke-width', this.__settings_origin_stroke_width);
250
- svg_path.setAttribute('stroke', this.__settings_origin_stroke_color);
251
-
252
- svg_main.appendChild(svg_path);
253
- }
254
-
255
- const vSvgMain = new EmptyView({
256
- el: svg_main,
257
- css: {
258
- position: 'absolute',
259
- top: 0,
260
- left: 0
261
- }
262
- });
263
-
264
- container.addChild(vSvgMain);
265
-
266
- for (let i = 0; i < axis_count; i++) {
267
-
268
- // draw axis name
269
- const axis = this.__axes[i];
270
-
271
- if (axis === undefined) {
272
- continue;
273
- }
274
-
275
- const angle = this.__get_axis_angle(i);
276
- const cos = Math.cos(angle);
277
- const sin = Math.sin(angle);
278
-
279
- if (axis.name !== undefined) {
280
- const vName = new LabelView(axis.name, {
281
- classList: ['axis-name'],
282
- css: {
283
- position: "absolute",
284
- top: "0",
285
- left: "0"
286
- }
287
- });
288
-
289
- const label_offset = this.__settings_radius_inner;
290
- vName.position.set(
291
- cos * label_offset + offset_x,
292
- sin * label_offset + offset_y
293
- );
294
-
295
- if (this.__tooltips !== undefined && axis.tooltip !== undefined) {
296
- this.__tooltips.add(vName, axis.tooltip, axis.tooltipContext);
297
- }
298
-
299
- container.addChild(vName);
300
- }
301
-
302
- // process icon
303
- if (axis.icon !== undefined) {
304
- let vIcon;
305
- if (typeof axis.icon === "string") {
306
- vIcon = new ImageView(axis.icon);
307
- } else {
308
- vIcon = axis.icon;
309
- }
310
-
311
- const icon_size = this.__settings_icon_size;
312
- vIcon.css({
313
- position: 'absolute',
314
- left: `-${icon_size * 0.5}px`,
315
- top: `-${icon_size * 0.5}px`
316
- });
317
-
318
- const icon_offset = this.__settings_radius_outer + icon_size * Math.SQRT1_2;
319
-
320
- vIcon.position.set(
321
- cos * icon_offset + offset_x,
322
- sin * icon_offset + offset_y
323
- );
324
-
325
- vIcon.size.set(
326
- icon_size,
327
- icon_size
328
- );
329
-
330
- if (this.__tooltips !== undefined && axis.tooltip !== undefined) {
331
- this.__tooltips.add(vIcon, axis.tooltip, axis.tooltipContext);
332
- }
333
-
334
- container.addChild(vIcon);
335
- }
336
- }
337
- }
338
-
339
- draw_values() {
340
-
341
- const axis_count = this.__get_axis_count();
342
- const offset_x = this.size.x * 0.5;
343
- const offset_y = this.size.y * 0.5;
344
-
345
- let path = 'M';
346
-
347
- for (let i = 0; i < axis_count; i++) {
348
-
349
- const angle = this.__get_axis_angle(i);
350
- const cos = Math.cos(angle);
351
- const sin = Math.sin(angle);
352
-
353
- const f = this.__values[i] / this.__settings_value_max;
354
- const radius = this.__settings_radius_inner * f;
355
-
356
- path += cos * radius + offset_x;
357
- path += ','
358
- path += sin * radius + offset_y;
359
-
360
- if (i < axis_count - 1) {
361
- path += 'L'
362
- } else {
363
- path += 'Z';
364
- }
365
- }
366
-
367
- this.__svg_graph_path.setAttribute('d', path);
368
- }
369
- }
1
+ import { assert } from "../../../core/assert.js";
2
+ import { isDefined } from "../../../core/process/matcher/isDefined.js";
3
+ import LabelView from "../../common/LabelView.js";
4
+ import SVG from "../../SVG.js";
5
+ import View from "../../View.js";
6
+ import EmptyView from "../EmptyView.js";
7
+ import ImageView from "../image/ImageView.js";
8
+
9
+ export class WindRoseDiagram extends View {
10
+
11
+ /**
12
+ *
13
+ * @param {{name:string,icon?:(View|string),value?:number,tooltip?:function, tooltipContext?:*}[]} axes
14
+ * @param {number} value_mark_stride
15
+ * @param {number} angular_offset
16
+ * @param {number} radius
17
+ * @param {number} value_max
18
+ * @param {DomTooltipManager} [tooltips]
19
+ */
20
+ constructor({
21
+ axes,
22
+ angular_offset = 0,
23
+ radius_inner = 200,
24
+ radius_outer = radius_inner,
25
+ value_max = 10,
26
+ value_mark_stride = value_max / 5,
27
+
28
+ icon_size = 32,
29
+
30
+ tooltips,
31
+
32
+ backplate_stroke_width = 2,
33
+ backplate_stroke_color = 'rgba(0,0,0,1)',
34
+ backplate_fill_color = 'rgba(99,99,99,1)',
35
+ display_backplate = true,
36
+
37
+ graph_stroke_width = 1,
38
+ graph_stroke_color = 'rgba(0,0,0,1)',
39
+ graph_fill_color = 'rgba(0,0,0,0.1)',
40
+
41
+ mark_stroke_width = 1,
42
+ mark_stroke_color = 'rgba(0,0,0,0.13)',
43
+ display_marks = true,
44
+
45
+ origin_radius = 8,
46
+ origin_stroke_width = 0,
47
+ origin_stroke_color = 'transparent',
48
+ origin_fill_color = 'red',
49
+ display_origin = true,
50
+ classList = []
51
+ }) {
52
+ super();
53
+
54
+ this.__axes = axes;
55
+ this.__settings_value_max = value_max;
56
+ this.__settings_value_mark_stride = value_mark_stride;
57
+ this.__settings_angular_offset = angular_offset;
58
+ this.__settings_icon_size = icon_size;
59
+
60
+ this.__settings_graph_stroke_width = graph_stroke_width;
61
+ this.__settings_graph_stroke_color = graph_stroke_color;
62
+ this.__settings_graph_fill_color = graph_fill_color;
63
+
64
+ this.__settings_backplate_stroke_width = backplate_stroke_width;
65
+ this.__settings_backplate_stroke_color = backplate_stroke_color;
66
+ this.__settings_backplate_fill_color = backplate_fill_color;
67
+ this.__settings_display_backplate = display_backplate;
68
+
69
+ this.__settings_mark_stroke_width = mark_stroke_width;
70
+ this.__settings_mark_stroke_color = mark_stroke_color;
71
+ this.__settings_display_marks = display_marks;
72
+
73
+ this.__settings_origin_radius = origin_radius;
74
+ this.__settings_origin_stroke_width = origin_stroke_width;
75
+ this.__settings_origin_stroke_color = origin_stroke_color;
76
+ this.__settings_origin_fill_color = origin_fill_color;
77
+ this.__settings_display_origin = display_origin;
78
+
79
+ this.__settings_radius_inner = radius_inner;
80
+ this.__settings_radius_outer = radius_outer;
81
+
82
+ this.__tooltips = tooltips;
83
+
84
+ this.__values = new Float32Array(axes.length);
85
+
86
+ this.el = document.createElement('div');
87
+ this.addClass('ui-wind-rose-diagram-view');
88
+ this.addClasses(classList);
89
+
90
+ const has_icons = axes.some(isDefined);
91
+
92
+ const size = radius_outer * 2 + (has_icons ? icon_size * (Math.SQRT1_2 + 0.5) * 2 : 0);
93
+
94
+ this.size.set(size, size);
95
+
96
+
97
+ this.__vCanvas = new EmptyView({
98
+ classList: ['canvas']
99
+ });
100
+
101
+ this.addChild(this.__vCanvas);
102
+
103
+ this.__vGraph = new EmptyView({
104
+ classList: ["graph"],
105
+ el: SVG.createElement('svg'),
106
+ attr: {
107
+ width: this.size.x * 2,
108
+ height: this.size.y * 2
109
+ },
110
+ css: {
111
+ position: 'absolute',
112
+ left: 0,
113
+ top: 0,
114
+ overflow: 'visible'
115
+ }
116
+ });
117
+ this.addChild(this.__vGraph);
118
+
119
+ this.__svg_graph_path = SVG.createElement('path');
120
+ this.__svg_graph_path.classList.add('graph-path-main');
121
+ this.__svg_graph_path.setAttribute('stroke-width', this.__settings_graph_stroke_width);
122
+ this.__svg_graph_path.setAttribute('stroke', this.__settings_graph_stroke_color);
123
+ this.__svg_graph_path.setAttribute('fill', this.__settings_graph_fill_color);
124
+
125
+ this.__vGraph.el.appendChild(this.__svg_graph_path);
126
+
127
+ this.on.linked.add(this.draw, this);
128
+
129
+ // process input axes
130
+ for (let i = 0; i < axes.length; i++) {
131
+ const axis = axes[i];
132
+
133
+ assert.defined(axis, 'axis');
134
+ assert.notNull(axis, 'axis');
135
+
136
+ if (axis.value !== undefined) {
137
+ this.set_axis_value(i, axis.value);
138
+ }
139
+ }
140
+ }
141
+
142
+ /**
143
+ *
144
+ * @param {number} index
145
+ * @param {number} value
146
+ */
147
+ set_axis_value(index, value) {
148
+ assert.isNonNegativeInteger(index, 'index');
149
+ assert.isFinite(value, 'value');
150
+
151
+ assert.lessThan(index, this.__axes.length, 'index overflow');
152
+
153
+ this.__values[index] = value;
154
+ }
155
+
156
+ draw() {
157
+ this.draw_canvas();
158
+ this.draw_values();
159
+ }
160
+
161
+ __get_axis_count() {
162
+ return this.__axes.length;
163
+ }
164
+
165
+ __get_axis_angle(index) {
166
+ const axis_count = this.__get_axis_count();
167
+ return index * Math.PI * (2 / axis_count) + this.__settings_angular_offset - Math.PI * 0.5;
168
+ }
169
+
170
+ __create_loop_path(radius) {
171
+ const axis_count = this.__get_axis_count();
172
+ const offset_x = this.size.x * 0.5;
173
+ const offset_y = this.size.y * 0.5;
174
+
175
+ let path = 'M';
176
+
177
+ for (let i = 0; i < axis_count; i++) {
178
+
179
+ const angle = this.__get_axis_angle(i);
180
+ const cos = Math.cos(angle);
181
+ const sin = Math.sin(angle);
182
+
183
+ path += cos * radius + offset_x;
184
+ path += ','
185
+ path += sin * radius + offset_y;
186
+
187
+ if (i < axis_count - 1) {
188
+ path += 'L'
189
+ } else {
190
+ path += 'Z';
191
+ }
192
+ }
193
+
194
+ return path;
195
+ }
196
+
197
+ draw_canvas() {
198
+ const container = this.__vCanvas;
199
+ container.removeAllChildren();
200
+
201
+ const axis_count = this.__get_axis_count();
202
+ const offset_x = this.size.x * 0.5;
203
+ const offset_y = this.size.y * 0.5;
204
+
205
+
206
+ // draw background and marks
207
+ const svg_main = SVG.createElement('svg');
208
+ svg_main.setAttribute('width', String(this.size.x));
209
+ svg_main.setAttribute('height', String(this.size.y));
210
+
211
+ if (this.__settings_display_backplate) {
212
+ const svg_path = SVG.createElement('path');
213
+
214
+ svg_path.classList.add('backplate');
215
+
216
+ svg_path.setAttribute('d', this.__create_loop_path(this.__settings_radius_outer + this.__settings_backplate_stroke_width / 2));
217
+ svg_path.setAttribute('stroke-width', String(this.__settings_backplate_stroke_width));
218
+ svg_path.setAttribute('stroke', this.__settings_backplate_stroke_color);
219
+ svg_path.setAttribute('fill', this.__settings_backplate_fill_color);
220
+
221
+ svg_main.appendChild(svg_path);
222
+ }
223
+
224
+ if (this.__settings_display_marks) {
225
+ for (let i = this.__settings_value_mark_stride; i < this.__settings_value_max; i += this.__settings_value_mark_stride) {
226
+ const svg_path = SVG.createElement('path');
227
+ svg_path.classList.add('mark');
228
+
229
+ const f = i / this.__settings_value_max;
230
+
231
+ const radius = f * this.__settings_radius_inner;
232
+
233
+ svg_path.setAttribute('d', this.__create_loop_path(radius));
234
+ svg_path.setAttribute('fill', 'none');
235
+ svg_path.setAttribute('stroke-width', this.__settings_mark_stroke_width);
236
+ svg_path.setAttribute('stroke', this.__settings_mark_stroke_color);
237
+
238
+ svg_main.appendChild(svg_path);
239
+ }
240
+ }
241
+
242
+ if (this.__settings_display_origin) {
243
+ const svg_path = SVG.createElement('path');
244
+
245
+ svg_path.classList.add('origin');
246
+
247
+ svg_path.setAttribute('d', this.__create_loop_path(this.__settings_origin_radius));
248
+ svg_path.setAttribute('fill', this.__settings_origin_fill_color);
249
+ svg_path.setAttribute('stroke-width', this.__settings_origin_stroke_width);
250
+ svg_path.setAttribute('stroke', this.__settings_origin_stroke_color);
251
+
252
+ svg_main.appendChild(svg_path);
253
+ }
254
+
255
+ const vSvgMain = new EmptyView({
256
+ el: svg_main,
257
+ css: {
258
+ position: 'absolute',
259
+ top: 0,
260
+ left: 0
261
+ }
262
+ });
263
+
264
+ container.addChild(vSvgMain);
265
+
266
+ for (let i = 0; i < axis_count; i++) {
267
+
268
+ // draw axis name
269
+ const axis = this.__axes[i];
270
+
271
+ if (axis === undefined) {
272
+ continue;
273
+ }
274
+
275
+ const angle = this.__get_axis_angle(i);
276
+ const cos = Math.cos(angle);
277
+ const sin = Math.sin(angle);
278
+
279
+ if (axis.name !== undefined) {
280
+ const vName = new LabelView(axis.name, {
281
+ classList: ['axis-name'],
282
+ css: {
283
+ position: "absolute",
284
+ top: "0",
285
+ left: "0"
286
+ }
287
+ });
288
+
289
+ const label_offset = this.__settings_radius_inner;
290
+ vName.position.set(
291
+ cos * label_offset + offset_x,
292
+ sin * label_offset + offset_y
293
+ );
294
+
295
+ if (this.__tooltips !== undefined && axis.tooltip !== undefined) {
296
+ this.__tooltips.add(vName, axis.tooltip, axis.tooltipContext);
297
+ }
298
+
299
+ container.addChild(vName);
300
+ }
301
+
302
+ // process icon
303
+ if (axis.icon !== undefined) {
304
+ let vIcon;
305
+ if (typeof axis.icon === "string") {
306
+ vIcon = new ImageView(axis.icon);
307
+ } else {
308
+ vIcon = axis.icon;
309
+ }
310
+
311
+ const icon_size = this.__settings_icon_size;
312
+ vIcon.css({
313
+ position: 'absolute',
314
+ left: `-${icon_size * 0.5}px`,
315
+ top: `-${icon_size * 0.5}px`
316
+ });
317
+
318
+ const icon_offset = this.__settings_radius_outer + icon_size * Math.SQRT1_2;
319
+
320
+ vIcon.position.set(
321
+ cos * icon_offset + offset_x,
322
+ sin * icon_offset + offset_y
323
+ );
324
+
325
+ vIcon.size.set(
326
+ icon_size,
327
+ icon_size
328
+ );
329
+
330
+ if (this.__tooltips !== undefined && axis.tooltip !== undefined) {
331
+ this.__tooltips.add(vIcon, axis.tooltip, axis.tooltipContext);
332
+ }
333
+
334
+ container.addChild(vIcon);
335
+ }
336
+ }
337
+ }
338
+
339
+ draw_values() {
340
+
341
+ const axis_count = this.__get_axis_count();
342
+ const offset_x = this.size.x * 0.5;
343
+ const offset_y = this.size.y * 0.5;
344
+
345
+ let path = 'M';
346
+
347
+ for (let i = 0; i < axis_count; i++) {
348
+
349
+ const angle = this.__get_axis_angle(i);
350
+ const cos = Math.cos(angle);
351
+ const sin = Math.sin(angle);
352
+
353
+ const f = this.__values[i] / this.__settings_value_max;
354
+ const radius = this.__settings_radius_inner * f;
355
+
356
+ path += cos * radius + offset_x;
357
+ path += ','
358
+ path += sin * radius + offset_y;
359
+
360
+ if (i < axis_count - 1) {
361
+ path += 'L'
362
+ } else {
363
+ path += 'Z';
364
+ }
365
+ }
366
+
367
+ this.__svg_graph_path.setAttribute('d', path);
368
+ }
369
+ }