@webviz/subsurface-viewer 0.0.1-alpha.1 → 0.0.2-alpha.2

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 (177) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/package.json +5 -2
  5. package/package.json +6 -3
  6. package/dist/DashSubsurfaceViewer.d.ts +0 -56
  7. package/dist/DashSubsurfaceViewer.js +0 -160
  8. package/dist/DashSubsurfaceViewer.js.map +0 -1
  9. package/src/DashSubsurfaceViewer.tsx +0 -270
  10. package/src/SubsurfaceViewer.stories.tsx +0 -449
  11. package/src/SubsurfaceViewer.test.tsx +0 -98
  12. package/src/SubsurfaceViewer.tsx +0 -356
  13. package/src/__snapshots__/SubsurfaceViewer.test.tsx.snap +0 -178
  14. package/src/assets/glTF/north_arrow/scene.bin +0 -0
  15. package/src/assets/glTF/north_arrow/scene.gltf +0 -315
  16. package/src/assets/glTF/north_arrow/textures/Arrow5_baseColor.png +0 -0
  17. package/src/assets/glTF/north_arrow/textures/Arrow5_metallicRoughness.png +0 -0
  18. package/src/assets/glTF/north_arrow/textures/Arrow5_normal.png +0 -0
  19. package/src/components/ColorLegend.test.tsx +0 -32
  20. package/src/components/ColorLegend.tsx +0 -80
  21. package/src/components/ColorLegends.test.tsx +0 -97
  22. package/src/components/ColorLegends.tsx +0 -46
  23. package/src/components/DistanceScale.stories.tsx +0 -28
  24. package/src/components/DistanceScale.test.tsx +0 -36
  25. package/src/components/DistanceScale.tsx +0 -84
  26. package/src/components/InfoCard.test.tsx +0 -110
  27. package/src/components/InfoCard.tsx +0 -263
  28. package/src/components/Map.test.tsx +0 -142
  29. package/src/components/Map.tsx +0 -1435
  30. package/src/components/StatusIndicator.test.tsx +0 -14
  31. package/src/components/StatusIndicator.tsx +0 -38
  32. package/src/components/ViewAnnotation.tsx +0 -16
  33. package/src/components/ViewFooter.test.tsx +0 -12
  34. package/src/components/ViewFooter.tsx +0 -30
  35. package/src/components/__snapshots__/ColorLegends.test.tsx.snap +0 -15
  36. package/src/components/__snapshots__/DistanceScale.test.tsx.snap +0 -33
  37. package/src/components/__snapshots__/InfoCard.test.tsx.snap +0 -561
  38. package/src/components/__snapshots__/Map.test.tsx.snap +0 -119
  39. package/src/components/__snapshots__/StatusIndicator.test.tsx.snap +0 -3
  40. package/src/components/__snapshots__/ViewFooter.test.tsx.snap +0 -7
  41. package/src/components/settings/DrawModeSelector.test.tsx +0 -45
  42. package/src/components/settings/DrawModeSelector.tsx +0 -58
  43. package/src/components/settings/DrawModeSelector_performance.test.tsx +0 -35
  44. package/src/components/settings/LayerProperty.test.tsx +0 -35
  45. package/src/components/settings/LayerProperty.tsx +0 -153
  46. package/src/components/settings/LayerProperty_performance.test.tsx +0 -39
  47. package/src/components/settings/LayerSettingsButton.test.tsx +0 -133
  48. package/src/components/settings/LayerSettingsButton.tsx +0 -95
  49. package/src/components/settings/LayersButton.test.tsx +0 -102
  50. package/src/components/settings/LayersButton.tsx +0 -97
  51. package/src/components/settings/NumericInput.test.tsx +0 -25
  52. package/src/components/settings/NumericInput.tsx +0 -67
  53. package/src/components/settings/Settings.tsx +0 -71
  54. package/src/components/settings/SliderInput.test.tsx +0 -28
  55. package/src/components/settings/SliderInput.tsx +0 -71
  56. package/src/components/settings/ToggleButton.test.tsx +0 -25
  57. package/src/components/settings/ToggleButton.tsx +0 -53
  58. package/src/components/settings/__snapshots__/DrawModeSelector.test.tsx.snap +0 -124
  59. package/src/components/settings/__snapshots__/LayerProperty.test.tsx.snap +0 -124
  60. package/src/components/settings/__snapshots__/LayerSettingsButton.test.tsx.snap +0 -36
  61. package/src/components/settings/__snapshots__/LayersButton.test.tsx.snap +0 -83
  62. package/src/components/settings/__snapshots__/NumericInput.test.tsx.snap +0 -123
  63. package/src/components/settings/__snapshots__/SliderInput.test.tsx.snap +0 -244
  64. package/src/components/settings/__snapshots__/ToggleButton.test.tsx.snap +0 -182
  65. package/src/custom.d.ts +0 -9
  66. package/src/index.ts +0 -5
  67. package/src/inputSchema/ColorTables.json +0 -51
  68. package/src/inputSchema/FaultPolygons.json +0 -80
  69. package/src/inputSchema/Grid.json +0 -39
  70. package/src/inputSchema/PieChart.json +0 -72
  71. package/src/inputSchema/WellLog.json +0 -126
  72. package/src/inputSchema/WellLogTemplate.json +0 -136
  73. package/src/inputSchema/WellLogs.json +0 -5
  74. package/src/inputSchema/Wells.json +0 -106
  75. package/src/inputSchema/schemaValidationUtil.tsx +0 -55
  76. package/src/inputSchema/validator.tsx +0 -72
  77. package/src/inputSchema/wellCompletions.json +0 -108
  78. package/src/layers/BoxSelectionLayer/boxSelectionLayer.stories.tsx +0 -172
  79. package/src/layers/BoxSelectionLayer/boxSelectionLayer.tsx +0 -136
  80. package/src/layers/axes/axes-fragment.glsl.ts +0 -15
  81. package/src/layers/axes/axesLayer.stories.tsx +0 -87
  82. package/src/layers/axes/axesLayer.ts +0 -692
  83. package/src/layers/axes/boxLayer.ts +0 -71
  84. package/src/layers/axes/grid-vertex.glsl.ts +0 -14
  85. package/src/layers/axes2d/axes2DLayer.stories.tsx +0 -150
  86. package/src/layers/axes2d/axes2DLayer.ts +0 -841
  87. package/src/layers/axes2d/font-atlas.png +0 -0
  88. package/src/layers/axes2d/label-fragment.glsl.js +0 -37
  89. package/src/layers/axes2d/label-vertex.glsl.js +0 -20
  90. package/src/layers/axes2d/line-fragment.glsl.js +0 -14
  91. package/src/layers/axes2d/line-vertex.glsl.js +0 -13
  92. package/src/layers/colormap/colormap.fs.glsl.ts +0 -42
  93. package/src/layers/colormap/colormapLayer.ts +0 -247
  94. package/src/layers/drawing/drawingLayer.tsx +0 -256
  95. package/src/layers/fault_polygons/faultPolygonsLayer.ts +0 -54
  96. package/src/layers/grid3d/fragment.fs.glsl.ts +0 -109
  97. package/src/layers/grid3d/fragment_lines.glsl.ts +0 -21
  98. package/src/layers/grid3d/grid3dLayer.stories.tsx +0 -172
  99. package/src/layers/grid3d/grid3dLayer.ts +0 -248
  100. package/src/layers/grid3d/privateLayer.ts +0 -292
  101. package/src/layers/grid3d/vertex.glsl.ts +0 -43
  102. package/src/layers/grid3d/vertex_lines.glsl.ts +0 -15
  103. package/src/layers/grid3d/webworker.ts +0 -173
  104. package/src/layers/hillshading2d/hillshading2d.fs.glsl.ts +0 -62
  105. package/src/layers/hillshading2d/hillshading2dLayer.ts +0 -172
  106. package/src/layers/index.ts +0 -35
  107. package/src/layers/intersection/intersectionView.stories.tsx +0 -294
  108. package/src/layers/intersection/unfoldedGeoJsonLayer.ts +0 -92
  109. package/src/layers/map/fragment.fs.glsl.ts +0 -127
  110. package/src/layers/map/fragment_lines.glsl.ts +0 -21
  111. package/src/layers/map/mapLayer.stories.tsx +0 -1369
  112. package/src/layers/map/mapLayer.ts +0 -470
  113. package/src/layers/map/privateMapLayer.ts +0 -317
  114. package/src/layers/map/vertex.glsl.ts +0 -45
  115. package/src/layers/map/vertex_lines.glsl.ts +0 -15
  116. package/src/layers/map/webworker.ts +0 -479
  117. package/src/layers/northarrow/northArrow.stories.tsx +0 -108
  118. package/src/layers/northarrow/northArrow3DLayer.ts +0 -204
  119. package/src/layers/northarrow/northarrow-fragment.glsl.js +0 -14
  120. package/src/layers/northarrow/northarrow-vertex.glsl.js +0 -13
  121. package/src/layers/piechart/fragment.glsl.js +0 -42
  122. package/src/layers/piechart/pieChartLayer.ts +0 -246
  123. package/src/layers/piechart/vertex.glsl.js +0 -42
  124. package/src/layers/points/pointsLayer.stories.tsx +0 -141
  125. package/src/layers/points/pointsLayer.ts +0 -143
  126. package/src/layers/polylines/polylinesLayer.stories.tsx +0 -144
  127. package/src/layers/polylines/polylinesLayer.ts +0 -263
  128. package/src/layers/selectable_geojson/selectableGeoJsonLayer.ts +0 -25
  129. package/src/layers/shader_modules/decoder.fs.glsl.ts +0 -41
  130. package/src/layers/shader_modules/decoder.ts +0 -46
  131. package/src/layers/shader_modules/index.ts +0 -1
  132. package/src/layers/terrain/map3DLayer.stories.tsx +0 -340
  133. package/src/layers/terrain/map3DLayer.ts +0 -556
  134. package/src/layers/terrain/terrainMapLayer.ts +0 -334
  135. package/src/layers/terrain/terrainmap.fs.glsl.ts +0 -134
  136. package/src/layers/triangle/fragment.fs.glsl.ts +0 -126
  137. package/src/layers/triangle/fragment_lines.glsl.ts +0 -21
  138. package/src/layers/triangle/privateTriangleLayer.ts +0 -203
  139. package/src/layers/triangle/test_data/surfacePoints.ts +0 -4344
  140. package/src/layers/triangle/test_data/surfaceTriangles.ts +0 -7392
  141. package/src/layers/triangle/triangleLayer.stories.tsx +0 -191
  142. package/src/layers/triangle/triangleLayer.ts +0 -273
  143. package/src/layers/triangle/vertex.glsl.ts +0 -35
  144. package/src/layers/triangle/vertex_lines.glsl.ts +0 -15
  145. package/src/layers/triangle/webworker.ts +0 -165
  146. package/src/layers/utils/glsl.d.ts +0 -4
  147. package/src/layers/utils/layerTools.ts +0 -182
  148. package/src/layers/utils/propertyMapTools.ts +0 -43
  149. package/src/layers/wells/utils/spline.ts +0 -318
  150. package/src/layers/wells/wellsLayer.stories.tsx +0 -625
  151. package/src/layers/wells/wellsLayer.ts +0 -1377
  152. package/src/redux/actions.ts +0 -8
  153. package/src/redux/reducer.ts +0 -43
  154. package/src/redux/store.ts +0 -15
  155. package/src/redux/types.ts +0 -114
  156. package/src/storybook/SubsurfaceViewer.stories.jsx +0 -644
  157. package/src/storybook/components/InfoCard.stories.jsx +0 -39
  158. package/src/storybook/components/colorLegends/ContinuousLegend.stories.jsx +0 -32
  159. package/src/storybook/components/colorLegends/DiscreteLegend.stories.jsx +0 -33
  160. package/src/storybook/components/colorLegends/IndividualScaleForMap.stories.jsx +0 -99
  161. package/src/storybook/components/colorLegends/SingleScaleForMap.stories.jsx +0 -120
  162. package/src/storybook/components/settings/LayerSettingsButton.stories.jsx +0 -34
  163. package/src/storybook/components/settings/NumericInput.stories.jsx +0 -17
  164. package/src/storybook/components/settings/ToggleButton.stories.jsx +0 -16
  165. package/src/storybook/schemaValidation/sampleData.js +0 -177
  166. package/src/storybook/schemaValidation/schemaValidation.stories.jsx +0 -91
  167. package/src/test/TestWrapper.tsx +0 -13
  168. package/src/utils/configuration.ts +0 -61
  169. package/src/utils/fit-bounds.js +0 -85
  170. package/src/utils/measurement.ts +0 -61
  171. package/src/utils/northArrow.ts +0 -4
  172. package/src/utils/specExtractor.ts +0 -36
  173. package/src/viewports/index.js +0 -1
  174. package/src/viewports/intersectionViewport.ts +0 -137
  175. package/src/views/index.js +0 -1
  176. package/src/views/intersectionView.ts +0 -38
  177. package/tsconfig.json +0 -7
@@ -1,841 +0,0 @@
1
- import {
2
- Layer,
3
- Viewport,
4
- LayerContext,
5
- project,
6
- OrthographicViewport,
7
- COORDINATE_SYSTEM,
8
- } from "@deck.gl/core/typed";
9
- import GL from "@luma.gl/constants";
10
- import { Model, Geometry } from "@luma.gl/engine";
11
- import labelVertexShader from "./label-vertex.glsl";
12
- import labelFragmentShader from "./label-fragment.glsl";
13
- import lineVertexShader from "./line-vertex.glsl";
14
- import lineFragmentShader from "./line-fragment.glsl";
15
- import { ExtendedLayerProps, Position3D } from "../utils/layerTools";
16
- import { load } from "@loaders.gl/core";
17
- import { Texture2D } from "@luma.gl/webgl";
18
- import { ImageLoader } from "@loaders.gl/images";
19
- import { vec4, mat4 } from "gl-matrix";
20
- import { Color } from "@deck.gl/core/typed";
21
- import fontAtlasPng from "./font-atlas.png";
22
-
23
- const DEFAULT_TEXTURE_PARAMETERS = {
24
- [GL.TEXTURE_MIN_FILTER]: GL.LINEAR_MIPMAP_LINEAR,
25
- [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
26
- [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
27
- [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
28
- };
29
-
30
- enum TEXT_ANCHOR {
31
- start = 0,
32
- middle = 1,
33
- end = 2,
34
- }
35
-
36
- enum ALIGNMENT_BASELINE {
37
- top = 1,
38
- center = 0,
39
- bottom = -1,
40
- }
41
-
42
- type LabelData = {
43
- label: string;
44
- pos: Position3D; // tick line start
45
- anchor?: TEXT_ANCHOR;
46
- aligment?: ALIGNMENT_BASELINE;
47
- //font_size: number; KEEP.
48
- };
49
-
50
- enum ViewSide {
51
- Left,
52
- Right,
53
- Bottom,
54
- Top,
55
- }
56
-
57
- const zDepthAxesBackground = 90;
58
- const zDepthAxesAxis = zDepthAxesBackground + 1;
59
- const zDepthAxesTicksAndLabels = zDepthAxesAxis + 1;
60
-
61
- export interface Axes2DLayerProps<D> extends ExtendedLayerProps<D> {
62
- marginH: number;
63
- marginV: number;
64
- labelColor?: Color;
65
- labelFontSize?: number;
66
- fontFamily?: string;
67
- axisColor?: Color;
68
- backgroundColor?: Color;
69
- isLeftRuler: boolean;
70
- isRightRuler: boolean;
71
- isBottomRuler: boolean;
72
- isTopRuler: boolean;
73
- }
74
-
75
- const defaultProps = {
76
- "@@type": "Axes2DLayer",
77
- name: "Axes2D",
78
- id: "axes2d-layer",
79
- visible: true,
80
- coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
81
- marginH: 80, // Horizontal margin (in pixles)
82
- marginV: 30, // Vertical margin (in pixles)
83
- isLeftRuler: true,
84
- isRightRuler: false,
85
- isBottomRuler: true,
86
- isTopRuler: false,
87
- };
88
-
89
- // FONT ATLAS
90
- const font_width = 86;
91
- const yh = 97;
92
- const fontInfo = {
93
- letterHeight: 92,
94
- spaceWidth: 0,
95
- spacing: -1,
96
- textureWidth: 1714,
97
- textureHeight: 200,
98
- glyphInfos: {
99
- A: { x: 0, y: 0, width: font_width },
100
- B: { x: font_width, y: 0, width: font_width },
101
- C: { x: 2 * font_width, y: 0, width: font_width },
102
- D: { x: 3 * font_width, y: 0, width: font_width },
103
- E: { x: 4 * font_width, y: 0, width: font_width },
104
- F: { x: 5 * font_width, y: 0, width: font_width },
105
- G: { x: 6 * font_width, y: 0, width: font_width },
106
- H: { x: 7 * font_width, y: 0, width: font_width },
107
- I: { x: 8 * font_width, y: 0, width: font_width },
108
- J: { x: 9 * font_width, y: 0, width: font_width },
109
- K: { x: 10 * font_width, y: 0, width: font_width },
110
- L: { x: 11 * font_width, y: 0, width: font_width },
111
- M: { x: 12 * font_width, y: 0, width: font_width },
112
- N: { x: 13 * font_width, y: 0, width: font_width },
113
- O: { x: 14 * font_width, y: 0, width: font_width },
114
- P: { x: 15 * font_width, y: 0, width: font_width },
115
- Q: { x: 16 * font_width, y: 0, width: font_width },
116
- R: { x: 17 * font_width, y: 0, width: font_width },
117
- S: { x: 18 * font_width, y: 0, width: font_width },
118
- T: { x: 19 * font_width, y: 0, width: font_width },
119
-
120
- U: { x: 0, y: yh, width: font_width },
121
- V: { x: font_width, y: yh, width: font_width },
122
- W: { x: 2 * font_width, y: yh, width: font_width },
123
- X: { x: 3 * font_width, y: yh, width: font_width },
124
- Y: { x: 4 * font_width, y: yh, width: font_width },
125
- Z: { x: 5 * font_width, y: yh, width: font_width },
126
- 0: { x: 6 * font_width, y: yh, width: font_width },
127
- 1: { x: 7 * font_width, y: yh, width: font_width },
128
- 2: { x: 8 * font_width, y: yh, width: font_width },
129
- 3: { x: 9 * font_width, y: yh, width: font_width },
130
- 4: { x: 10 * font_width, y: yh, width: font_width },
131
- 5: { x: 11 * font_width, y: yh, width: font_width },
132
- 6: { x: 12 * font_width, y: yh, width: font_width },
133
- 7: { x: 13 * font_width, y: yh, width: font_width },
134
- 8: { x: 14 * font_width, y: yh, width: font_width },
135
- 9: { x: 15 * font_width, y: yh, width: font_width },
136
- "+": { x: 16 * font_width, y: yh, width: font_width },
137
- "-": { x: 17 * font_width, y: yh, width: font_width },
138
- ".": { x: 18 * font_width, y: yh, width: font_width },
139
- ",": { x: 19 * font_width, y: yh, width: font_width },
140
- },
141
- };
142
-
143
- export default class Axes2DLayer extends Layer<Axes2DLayerProps<unknown>> {
144
- initializeState(context: LayerContext): void {
145
- const { gl } = context;
146
-
147
- const promise = load(fontAtlasPng, ImageLoader, {
148
- image: { type: "data" }, // Will load as ImageData.
149
- });
150
-
151
- promise.then((data: ImageData) => {
152
- const fontTexture = new Texture2D(gl, {
153
- width: data.width,
154
- height: data.height,
155
- format: GL.RGB,
156
- data,
157
- parameters: DEFAULT_TEXTURE_PARAMETERS,
158
- });
159
-
160
- this.setState({
161
- fontTexture,
162
- // Insert a dummy model initially.
163
- model: new Model(gl, {
164
- id: "dummy",
165
- vs: lineVertexShader,
166
- fs: lineFragmentShader,
167
- }),
168
- });
169
- });
170
- }
171
-
172
- GetTickLinesAndLabels(
173
- min: number,
174
- max: number,
175
- viewSide: ViewSide,
176
- pixel2world: number
177
- ): [number[], LabelData[]] {
178
- const ndecimals = 0;
179
- const n_minor_ticks = 3;
180
-
181
- const lines: number[] = [];
182
- const tick_labels = [];
183
-
184
- const mv = this.props.marginV * pixel2world;
185
- const mh = this.props.marginH * pixel2world;
186
-
187
- const vpBounds = this.context.viewport.getBounds();
188
- let start;
189
- let y_tick = 0;
190
- let x_tick = 0;
191
- if (viewSide === ViewSide.Top) {
192
- start = vpBounds[3] - mv;
193
- y_tick = start;
194
- } else if (viewSide === ViewSide.Bottom) {
195
- start = vpBounds[1] + mv;
196
- y_tick = start;
197
- } else if (viewSide === ViewSide.Left) {
198
- start = vpBounds[0] + mh;
199
- x_tick = start;
200
- } else if (viewSide === ViewSide.Right) {
201
- start = vpBounds[2] - mh;
202
- x_tick = start;
203
- }
204
-
205
- const m = 10; // Length in pixels
206
- const delta = m * pixel2world;
207
-
208
- const L = LineLengthInPixels(
209
- [min, 0, 0],
210
- [max, 0, 0],
211
- this.context.viewport
212
- );
213
-
214
- const isHorizontal =
215
- viewSide === ViewSide.Top || viewSide === ViewSide.Bottom;
216
-
217
- const ticks = GetTicks(min, max, L); // Note: this may be replaced by NiceTicks npm package.
218
-
219
- // z value of all lines and labels. In camera/view coordinates. This
220
- // ensures lines will be closer to camera than rest of model.
221
- const z_depth = zDepthAxesTicksAndLabels;
222
-
223
- const tick_length =
224
- viewSide === ViewSide.Left || viewSide === ViewSide.Bottom
225
- ? -delta
226
- : delta;
227
-
228
- for (let i = 0; i < ticks.length; i++) {
229
- const tick = ticks[i];
230
-
231
- const label = tick.toFixed(ndecimals);
232
- tick_labels.push(label);
233
-
234
- // tick line start
235
- if (isHorizontal) {
236
- lines.push(tick, y_tick, z_depth); // tick line start
237
- lines.push(tick, y_tick + tick_length, z_depth); // tick line end.
238
- } else {
239
- lines.push(x_tick, tick, z_depth);
240
- lines.push(x_tick + tick_length, tick, z_depth);
241
- }
242
- }
243
-
244
- // Add minor X ticks.
245
- if (ticks.length > 1) {
246
- const tick1 = ticks[0];
247
- const tick2 = ticks[1];
248
- const d = (tick2 - tick1) / (n_minor_ticks + 1);
249
- const tick_start = tick1;
250
-
251
- // up
252
- let i = 0;
253
- while (tick_start + (i + 1) * d < max) {
254
- const tick = tick_start + (i + 1) * d;
255
- tick_labels.push("");
256
- i++;
257
-
258
- if (isHorizontal) {
259
- lines.push(tick, y_tick, z_depth); // tick line start
260
- lines.push(tick, y_tick + 0.5 * tick_length, z_depth); // tick line end.
261
- } else {
262
- lines.push(x_tick, tick, z_depth);
263
- lines.push(x_tick + 0.5 * tick_length, tick, z_depth);
264
- }
265
- }
266
-
267
- // down
268
- i = 0;
269
- while (tick_start - (i + 1) * d > min) {
270
- const tick = tick_start - (i + 1) * d;
271
- tick_labels.push("");
272
- i++;
273
-
274
- if (isHorizontal) {
275
- lines.push(tick, y_tick, z_depth);
276
- lines.push(tick, y_tick + 0.5 * tick_length, z_depth);
277
- } else {
278
- lines.push(x_tick, tick, z_depth);
279
- lines.push(x_tick + 0.5 * tick_length, tick, z_depth);
280
- }
281
- }
282
- }
283
-
284
- const labels = this.makeLabelsData(lines, tick_labels);
285
-
286
- return [lines, labels];
287
- }
288
-
289
- GetBacgroundTriangleLinesHorizontal(
290
- x_min_w: number,
291
- x_max_w: number,
292
- isTop: boolean,
293
- pixel2world: number
294
- ): number[] {
295
- const mv = this.props.marginV * pixel2world;
296
-
297
- const vp_bounds = this.context.viewport.getBounds(); // [xmin, ymin, xmax, ymax]
298
-
299
- const y_max = isTop ? vp_bounds[3] : vp_bounds[1] + mv;
300
- const y_min = isTop ? vp_bounds[3] - mv : vp_bounds[1];
301
-
302
- const zDepth = zDepthAxesBackground;
303
-
304
- const p1 = [x_min_w, y_max, zDepth];
305
- const p2 = [x_max_w, y_max, zDepth];
306
- const p3 = [x_max_w, y_min, zDepth];
307
- const p4 = [x_min_w, y_min, zDepth];
308
-
309
- /*eslint-disable */
310
- const background_lines: number[] = [
311
- ...p1, ...p2, ...p4, // triangle 1
312
- ...p2, ...p4, ...p3, // triangle 2
313
- ];
314
- /*eslint-enable */
315
-
316
- return background_lines;
317
- }
318
-
319
- GetBacgroundTriangleLinesVertical(
320
- y_min_w: number,
321
- y_max_w: number,
322
- isLeft: boolean, // left or right ruler.
323
- pixel2world: number
324
- ): number[] {
325
- const mh = this.props.marginH * pixel2world;
326
-
327
- const vp_bounds = this.context.viewport.getBounds(); // [xmin, ymin, xmax, ymax]
328
-
329
- const x_max = isLeft ? vp_bounds[0] + mh : vp_bounds[2];
330
- const x_min = isLeft ? vp_bounds[0] : vp_bounds[2] - mh;
331
-
332
- const zDepth = zDepthAxesBackground;
333
- const p1 = [x_max, y_min_w, zDepth];
334
- const p2 = [x_max, y_max_w, zDepth];
335
- const p3 = [x_min, y_max_w, zDepth];
336
- const p4 = [x_min, y_min_w, zDepth];
337
-
338
- /*eslint-disable */
339
- const background_lines: number[] = [
340
- ...p1, ...p2, ...p4, // triangle 1
341
- ...p2, ...p4, ...p3, // triangle 2
342
- ];
343
- /*eslint-enable */
344
-
345
- return background_lines;
346
- }
347
-
348
- makeLabelsData(tick_lines: number[], tick_labels: string[]): LabelData[] {
349
- const labels: LabelData[] = [];
350
-
351
- for (let i = 0; i < tick_lines.length / 6; i++) {
352
- const from = [
353
- tick_lines[6 * i + 0],
354
- tick_lines[6 * i + 1],
355
- tick_lines[6 * i + 2],
356
- ];
357
- const to = [
358
- tick_lines[6 * i + 3],
359
- tick_lines[6 * i + 4],
360
- tick_lines[6 * i + 5],
361
- ];
362
- const label = tick_labels[i];
363
-
364
- const tick_vec = [
365
- to[0] - from[0],
366
- to[1] - from[1],
367
- to[2] - from[2],
368
- ];
369
- const s = 0.5;
370
- const pos: Position3D = [
371
- to[0] + s * tick_vec[0],
372
- to[1] + s * tick_vec[1],
373
- to[2] + s * tick_vec[2],
374
- ];
375
-
376
- let anchor = TEXT_ANCHOR.end;
377
- let aligment = ALIGNMENT_BASELINE.center;
378
- const is_xaxis = from[1] !== to[1];
379
- if (is_xaxis) {
380
- anchor = TEXT_ANCHOR.middle;
381
- aligment = ALIGNMENT_BASELINE.top;
382
- } else {
383
- const screen_from = this.context.viewport.project(from);
384
- const screen_to = this.context.viewport.project(to);
385
-
386
- if (screen_from[0] < screen_to[0]) {
387
- anchor = TEXT_ANCHOR.start;
388
- }
389
- }
390
-
391
- labels.push({ label, pos, anchor, aligment });
392
- }
393
-
394
- return labels;
395
- }
396
-
397
- draw({
398
- moduleParameters,
399
- uniforms,
400
- context,
401
- }: {
402
- moduleParameters: unknown;
403
- uniforms: unknown;
404
- context: LayerContext;
405
- }): void {
406
- const is_orthographic =
407
- this.context.viewport.constructor === OrthographicViewport;
408
- if (
409
- typeof this.state["fontTexture"] === "undefined" ||
410
- !is_orthographic
411
- ) {
412
- return;
413
- }
414
-
415
- const { gl } = context;
416
-
417
- super.draw({ moduleParameters, uniforms, context }); // For some reason this is neccessary.
418
-
419
- const { projectionMatrix } = this.context.viewport;
420
-
421
- //gl.disable(gl.DEPTH_TEST); KEEP for now.
422
-
423
- const { label_models, line_model, background_model } =
424
- this._getModels(gl);
425
-
426
- const fontTexture = this.state["fontTexture"];
427
- for (const model of label_models) {
428
- model.setUniforms({ projectionMatrix, fontTexture }).draw();
429
- }
430
-
431
- line_model.draw();
432
-
433
- // When both parameters are negative, (decreased depth), the mesh is pulled towards the camera (hence, gets in front).
434
- // When both parameters are positive, (increased depth), the mesh is pushed away from the camera (hence, gets behind).
435
- gl.enable(GL.POLYGON_OFFSET_FILL);
436
- gl.polygonOffset(1, 1);
437
- background_model.draw();
438
- gl.disable(GL.POLYGON_OFFSET_FILL);
439
-
440
- //gl.enable(gl.DEPTH_TEST);
441
- }
442
-
443
- _getModels(gl: WebGLRenderingContext): {
444
- label_models: Model[];
445
- line_model: Model;
446
- background_model: Model;
447
- } {
448
- // Make models for background, lines (tick marcs and axis) and labels.
449
-
450
- // Margins.
451
- const m = 100; // Length in pixels
452
- const world_from = this.context.viewport.unproject([0, 0, 0]);
453
- const world_to = this.context.viewport.unproject([0, m, 0]);
454
- const v = [
455
- world_from[0] - world_to[0],
456
- world_from[1] - world_to[1],
457
- world_from[2] - world_to[2],
458
- ];
459
-
460
- const pixel2world = Math.sqrt(v[0] * v[0] + v[1] * v[1]) / 100;
461
-
462
- const { viewMatrix } = this.context.viewport;
463
-
464
- const mh = this.props.marginH * pixel2world;
465
- const mv = this.props.marginV * pixel2world;
466
-
467
- const viewport_bounds_w = this.context.viewport.getBounds(); //bounds in world coordinates.
468
- const xMin = viewport_bounds_w[0];
469
- const xMax = viewport_bounds_w[2];
470
- const yMin = viewport_bounds_w[1];
471
- const yMax = viewport_bounds_w[3];
472
-
473
- let tick_and_axes_lines: number[] = [];
474
- let background_lines: number[] = [];
475
- let labelData: LabelData[] = [];
476
-
477
- const zDepth = zDepthAxesAxis;
478
-
479
- //- BOTTOM RULER ----------------------------------------
480
- if (this.props.isBottomRuler) {
481
- const axes = [xMin, yMin + mv, zDepth, xMax, yMin + mv, zDepth];
482
- const [ticks, labels] = this.GetTickLinesAndLabels(
483
- xMin,
484
- xMax,
485
- ViewSide.Bottom,
486
- pixel2world
487
- );
488
- const back_lines: number[] =
489
- this.GetBacgroundTriangleLinesHorizontal(
490
- xMin,
491
- xMax,
492
- false,
493
- pixel2world
494
- );
495
-
496
- tick_and_axes_lines = [...tick_and_axes_lines, ...axes, ...ticks];
497
- background_lines = [...background_lines, ...back_lines];
498
- labelData = [...labelData, ...labels];
499
- }
500
-
501
- //- TOP RULER ----------------------------------------
502
- if (this.props.isTopRuler) {
503
- const axes = [xMin, yMax - mv, zDepth, xMax, yMax - mv, zDepth];
504
- const [ticks, labels] = this.GetTickLinesAndLabels(
505
- xMin,
506
- xMax,
507
- ViewSide.Top,
508
- pixel2world
509
- );
510
-
511
- const back_lines = this.GetBacgroundTriangleLinesHorizontal(
512
- xMin,
513
- xMax,
514
- true, // isTop
515
- pixel2world
516
- );
517
-
518
- tick_and_axes_lines = [...tick_and_axes_lines, ...axes, ...ticks];
519
- background_lines = [...background_lines, ...back_lines];
520
- labelData = [...labelData, ...labels];
521
- }
522
-
523
- //- LEFT RULER ----------------------------------------
524
- if (this.props.isLeftRuler) {
525
- const ymin = this.props.isBottomRuler ? yMin + mv : yMin;
526
- const ymax = this.props.isTopRuler ? yMax - mv : yMax;
527
- const axes = [xMin + mh, ymin, zDepth, xMin + mh, ymax, zDepth];
528
- const [ticks, labels] = this.GetTickLinesAndLabels(
529
- ymin,
530
- yMax - mv,
531
- ViewSide.Left,
532
- pixel2world
533
- );
534
- const back_lines = this.GetBacgroundTriangleLinesVertical(
535
- ymin,
536
- ymax,
537
- true,
538
- pixel2world
539
- );
540
-
541
- tick_and_axes_lines = [...tick_and_axes_lines, ...axes, ...ticks];
542
- background_lines = [...background_lines, ...back_lines];
543
- labelData = [...labelData, ...labels];
544
- }
545
-
546
- //- RIGHT RULER ----------------------------------------
547
- if (this.props.isRightRuler) {
548
- const ymin = this.props.isBottomRuler ? yMin + mv : yMin;
549
- const ymax = this.props.isTopRuler ? yMax - mv : yMax;
550
- const axes = [xMax - mh, ymin, zDepth, xMax - mh, ymax, zDepth];
551
- const [ticks, labels] = this.GetTickLinesAndLabels(
552
- ymin,
553
- ymax,
554
- ViewSide.Right,
555
- pixel2world
556
- );
557
-
558
- const back_lines = this.GetBacgroundTriangleLinesVertical(
559
- ymin,
560
- ymax,
561
- false,
562
- pixel2world
563
- );
564
-
565
- tick_and_axes_lines = [...tick_and_axes_lines, ...axes, ...ticks];
566
- background_lines = [...background_lines, ...back_lines];
567
- labelData = [...labelData, ...labels];
568
- }
569
-
570
- // Line models. (axis line and tick lines)
571
- // Color on axes and text.
572
- let lineColor = [0.0, 0.0, 0.0, 1.0];
573
- if (typeof this.props.axisColor !== "undefined") {
574
- lineColor = this.props.axisColor as number[];
575
- if (lineColor.length === 3) {
576
- lineColor.push(255);
577
- }
578
- lineColor = lineColor.map((x) => (x ?? 0) / 255);
579
- }
580
-
581
- const line_model = new Model(gl, {
582
- id: `${this.props.id}-lines`,
583
- vs: lineVertexShader,
584
- fs: lineFragmentShader,
585
- uniforms: { uColor: lineColor },
586
- geometry: new Geometry({
587
- drawMode: GL.LINES,
588
- attributes: {
589
- positions: new Float32Array(tick_and_axes_lines),
590
- },
591
- vertexCount: tick_and_axes_lines.length / 3,
592
- }),
593
-
594
- modules: [project],
595
- isInstanced: false,
596
- });
597
-
598
- //-- Background model --
599
- // Color on axes background.
600
- let bColor = [1.0, 1.0, 1.0, 1.0];
601
- if (typeof this.props.backgroundColor !== "undefined") {
602
- bColor = this.props.backgroundColor as number[];
603
- if (bColor.length === 3) {
604
- bColor.push(255);
605
- }
606
- bColor = bColor.map((x) => (x ?? 0) / 255);
607
- }
608
-
609
- const background_model = new Model(gl, {
610
- id: `${this.props.id}-background`,
611
- vs: lineVertexShader,
612
- fs: lineFragmentShader,
613
- uniforms: { uColor: bColor },
614
- geometry: new Geometry({
615
- drawMode: GL.TRIANGLES,
616
- attributes: {
617
- positions: new Float32Array(background_lines),
618
- },
619
- vertexCount: background_lines.length / 3,
620
- }),
621
-
622
- modules: [project],
623
- isInstanced: false,
624
- });
625
-
626
- //-- Labels model--
627
- const label_models: Model[] = [];
628
-
629
- for (const item of labelData) {
630
- const x = item.pos[0];
631
- const y = item.pos[1];
632
- const z = item.pos[2];
633
- const label = item.label;
634
- const anchor = item.anchor ?? TEXT_ANCHOR.start;
635
- const aligment_baseline =
636
- item.aligment ?? ALIGNMENT_BASELINE.center;
637
-
638
- if (label === "") {
639
- continue;
640
- }
641
-
642
- const pos_w = vec4.fromValues(x, y, z, 1); // pos world
643
- const pos_view = word2view(viewMatrix, pos_w); // pos view
644
-
645
- const pixelScale = 8;
646
-
647
- const len = label.length;
648
- const numVertices = len * 6;
649
- const positions = new Float32Array(numVertices * 3);
650
- const texcoords = new Float32Array(numVertices * 2);
651
- const maxX = fontInfo.textureWidth;
652
- const maxY = fontInfo.textureHeight;
653
- let offset = 0;
654
- let offsetTexture = 0;
655
-
656
- let x1 = 0;
657
- if (anchor === TEXT_ANCHOR.end) {
658
- x1 = -len;
659
- } else if (anchor === TEXT_ANCHOR.middle) {
660
- x1 = -len / 2;
661
- }
662
-
663
- let y_aligment_offset = 0;
664
- if (aligment_baseline === ALIGNMENT_BASELINE.center) {
665
- y_aligment_offset = 0.5 * pixelScale;
666
- } else if (aligment_baseline === ALIGNMENT_BASELINE.top) {
667
- y_aligment_offset = 1 * pixelScale;
668
- }
669
-
670
- for (let ii = 0; ii < len; ++ii) {
671
- const letter = label[ii];
672
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
673
- // @ts-ignore
674
- const glyphInfo = fontInfo.glyphInfos[letter];
675
- if (glyphInfo) {
676
- // Unit square.
677
- const x2 = x1 + 1;
678
- const u1 = glyphInfo.x / maxX;
679
- const v1 = (glyphInfo.y + fontInfo.letterHeight - 1) / maxY;
680
- const u2 = (glyphInfo.x + glyphInfo.width - 1) / maxX;
681
- const v2 = glyphInfo.y / maxY;
682
-
683
- const h = 1;
684
- const x = pos_view[0];
685
- const y = pos_view[1] - y_aligment_offset;
686
- const z = pos_view[2];
687
-
688
- // 6 vertices per letter
689
- // t1
690
- positions[offset + 0] = x + x1 * pixelScale;
691
- positions[offset + 1] = y + 0 * pixelScale;
692
- positions[offset + 2] = z; // Note: may make these vertices 2D.
693
- texcoords[offsetTexture + 0] = u1;
694
- texcoords[offsetTexture + 1] = v1;
695
-
696
- positions[offset + 3] = x + x2 * pixelScale;
697
- positions[offset + 4] = y + 0 * pixelScale;
698
- positions[offset + 5] = z;
699
- texcoords[offsetTexture + 2] = u2;
700
- texcoords[offsetTexture + 3] = v1;
701
-
702
- positions[offset + 6] = x + x1 * pixelScale;
703
- positions[offset + 7] = y + h * pixelScale;
704
- positions[offset + 8] = z;
705
- texcoords[offsetTexture + 4] = u1;
706
- texcoords[offsetTexture + 5] = v2;
707
-
708
- // t2
709
- positions[offset + 9] = x + x1 * pixelScale;
710
- positions[offset + 10] = y + h * pixelScale;
711
- positions[offset + 11] = z;
712
- texcoords[offsetTexture + 6] = u1;
713
- texcoords[offsetTexture + 7] = v2;
714
-
715
- positions[offset + 12] = x + x2 * pixelScale;
716
- positions[offset + 13] = y + 0 * pixelScale;
717
- positions[offset + 14] = z;
718
- texcoords[offsetTexture + 8] = u2;
719
- texcoords[offsetTexture + 9] = v1;
720
-
721
- positions[offset + 15] = x + x2 * pixelScale;
722
- positions[offset + 16] = y + h * pixelScale;
723
- positions[offset + 17] = z;
724
- texcoords[offsetTexture + 10] = u2;
725
- texcoords[offsetTexture + 11] = v2;
726
-
727
- x1 += 1;
728
- offset += 18;
729
- offsetTexture += 12;
730
- } else {
731
- // we don't have this character so just advance
732
- x1 += 1;
733
- }
734
- }
735
-
736
- const id = `${this.props.id}-${label}`;
737
- const model = new Model(gl, {
738
- id,
739
- vs: labelVertexShader,
740
- fs: labelFragmentShader,
741
- uniforms: { uAxisColor: lineColor, uBackGroundColor: bColor },
742
- geometry: new Geometry({
743
- drawMode: GL.TRIANGLES,
744
- attributes: {
745
- positions,
746
- vTexCoord: {
747
- value: texcoords,
748
- size: 2,
749
- },
750
- },
751
- vertexCount: positions.length / 3,
752
- }),
753
-
754
- modules: [project],
755
- isInstanced: false,
756
- });
757
-
758
- label_models.push(model);
759
- }
760
-
761
- return { label_models, line_model, background_model };
762
- }
763
- }
764
-
765
- Axes2DLayer.layerName = "Axes2DLayer";
766
- Axes2DLayer.defaultProps = defaultProps;
767
-
768
- //-- Local help functions. -------------------------------------------------
769
-
770
- function word2view(
771
- viewMatrix: number[],
772
- pos_w: vec4
773
- ): [number, number, number] {
774
- const pos_v = vec4.transformMat4(
775
- vec4.create(),
776
- pos_w,
777
- mat4.fromValues(
778
- ...(viewMatrix.slice(0, mat4.fromValues.length) as Parameters<
779
- typeof mat4.fromValues
780
- >)
781
- )
782
- );
783
-
784
- return pos_v.slice(0, 3) as [number, number, number];
785
- }
786
-
787
- function LineLengthInPixels(
788
- p0: Position3D,
789
- p1: Position3D,
790
- viewport: Viewport
791
- ): number {
792
- const screen_from = viewport.project(p0);
793
- const screen_to = viewport.project(p1);
794
-
795
- const v = [
796
- screen_from[0] - screen_to[0],
797
- screen_from[1] - screen_to[1],
798
- screen_from[2] - screen_to[2],
799
- ];
800
- const L = Math.sqrt(v[0] * v[0] + v[1] * v[1]); // Length of axis on screen in pixles.
801
- return L;
802
- }
803
-
804
- function GetTicks(
805
- min: number,
806
- max: number,
807
- axis_pixel_length: number
808
- ): number[] {
809
- let step = Math.min(Math.round(axis_pixel_length / 100) + 1, 20);
810
- const range = max - min;
811
-
812
- const delta = Math.abs(range) / step;
813
- let decade = 1;
814
- if (delta >= 10) {
815
- const logde = Math.log10(delta);
816
- const pot = Math.floor(logde);
817
- decade = Math.pow(10.0, pot);
818
- }
819
- let scaled_delta = Math.round(delta / decade);
820
- if (scaled_delta == 3) scaled_delta = 2;
821
- else if (scaled_delta == 4 || scaled_delta == 6 || scaled_delta == 7)
822
- scaled_delta = 5;
823
- else if (scaled_delta > 7) scaled_delta = 10;
824
- else if (scaled_delta < 1) scaled_delta = 1;
825
-
826
- const incr = scaled_delta * decade;
827
- const start = Math.ceil(min / incr) * incr;
828
- const stop = Math.floor(max / incr) * incr;
829
- const calc_step = Math.floor(Math.abs(stop - start) / incr);
830
- step = calc_step > 0 ? calc_step : 0;
831
-
832
- const ticks: number[] = [];
833
-
834
- //ticks.push(min);
835
- for (let i = 0; i <= step; i++) {
836
- const x = start + i * incr;
837
- ticks.push(x);
838
- }
839
-
840
- return ticks;
841
- }