@geode/opengeodeweb-front 10.44.0-rc.3 → 10.44.0-rc.4

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 (106) hide show
  1. package/.build/server/utils/microservices.js +9 -85
  2. package/.build/server/utils/microservices_process.js +85 -0
  3. package/app/components/ClippingPlanes.vue +16 -82
  4. package/app/components/DragAndDrop.vue +1 -74
  5. package/app/components/ThresholdCard.vue +205 -0
  6. package/app/components/ThresholdFilter.vue +77 -216
  7. package/app/components/ViewToolbar.vue +15 -231
  8. package/app/components/Viewer/EdgedCurve/SpecificEdgesColoring.vue +209 -0
  9. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +3 -191
  10. package/app/components/Viewer/Generic/Mesh/CellsColoring.vue +228 -0
  11. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +3 -210
  12. package/app/components/Viewer/Generic/Mesh/EdgesColoring.vue +211 -0
  13. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +3 -192
  14. package/app/components/Viewer/Generic/Mesh/PolygonsColoring.vue +234 -0
  15. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +3 -215
  16. package/app/components/Viewer/Generic/Mesh/PolyhedraColoring.vue +221 -0
  17. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +3 -203
  18. package/app/components/Viewer/Generic/Model/ComponentPointsOptions.vue +2 -18
  19. package/app/components/Viewer/Generic/Model/CornerComponentOptions.vue +145 -0
  20. package/app/components/Viewer/Generic/Model/CornersOptions.vue +13 -294
  21. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +173 -0
  22. package/app/components/Viewer/Generic/Model/LineComponentOptions.vue +218 -0
  23. package/app/components/Viewer/Generic/Model/LinesOptions.vue +13 -425
  24. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +229 -0
  25. package/app/components/Viewer/Options/AttributeSelector.vue +26 -133
  26. package/app/components/Viewer/Options/ColoringTypeSelector.vue +36 -74
  27. package/app/components/Viewer/Options/NoDataColorInfo.vue +56 -0
  28. package/app/components/Viewer/Solid/SpecificPolyhedraColoring.vue +217 -0
  29. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +4 -199
  30. package/app/components/Viewer/Surface/PolygonsColoring.vue +231 -0
  31. package/app/components/Viewer/Surface/PolygonsOptions.vue +3 -213
  32. package/app/composables/attribute_selector.ts +126 -0
  33. package/app/composables/clipping_slices.ts +166 -0
  34. package/app/composables/view_toolbar_options.ts +126 -0
  35. package/app/composables/view_toolbar_tool_options.ts +115 -0
  36. package/app/composables/view_toolbar_tools.ts +108 -0
  37. package/app/composables/virtual_tree.ts +20 -138
  38. package/app/composables/virtual_tree_flatten.ts +86 -0
  39. package/app/composables/virtual_tree_types.ts +81 -0
  40. package/app/stores/app.ts +8 -55
  41. package/app/stores/app_helpers/registry.ts +69 -0
  42. package/app/stores/menu.ts +1 -124
  43. package/app/stores/menu_helpers/menus_data.ts +127 -0
  44. package/app/stores/viewer.ts +17 -78
  45. package/app/stores/viewer_helpers/actions.ts +68 -0
  46. package/app/stores/viewer_helpers/request.ts +61 -0
  47. package/app/utils/clipping_planes.ts +4 -132
  48. package/app/utils/clipping_planes_scene.ts +131 -0
  49. package/app/utils/coloring_styles.ts +101 -0
  50. package/app/utils/default_styles/mesh_components.ts +168 -0
  51. package/app/utils/default_styles/meshes.ts +13 -153
  52. package/app/utils/default_styles/model_components.ts +170 -0
  53. package/app/utils/default_styles/models.ts +16 -153
  54. package/app/utils/drag_and_drop.ts +80 -0
  55. package/app/utils/model_component_coloring.ts +46 -0
  56. package/app/utils/threshold.ts +33 -0
  57. package/app/utils/threshold_sources.ts +51 -0
  58. package/internal/stores/data_style/mesh/cells/cell.ts +27 -150
  59. package/internal/stores/data_style/mesh/cells/cell_attribute.ts +74 -0
  60. package/internal/stores/data_style/mesh/cells/cell_config.ts +152 -0
  61. package/internal/stores/data_style/mesh/cells/vertex.ts +26 -157
  62. package/internal/stores/data_style/mesh/cells/vertex_attribute.ts +80 -0
  63. package/internal/stores/data_style/mesh/cells/vertex_config.ts +152 -0
  64. package/internal/stores/data_style/mesh/edges/edge.ts +27 -150
  65. package/internal/stores/data_style/mesh/edges/edge_attribute.ts +74 -0
  66. package/internal/stores/data_style/mesh/edges/edge_config.ts +152 -0
  67. package/internal/stores/data_style/mesh/edges/vertex.ts +26 -157
  68. package/internal/stores/data_style/mesh/edges/vertex_attribute.ts +80 -0
  69. package/internal/stores/data_style/mesh/edges/vertex_config.ts +152 -0
  70. package/internal/stores/data_style/mesh/points/vertex.ts +26 -157
  71. package/internal/stores/data_style/mesh/points/vertex_attribute.ts +80 -0
  72. package/internal/stores/data_style/mesh/points/vertex_config.ts +152 -0
  73. package/internal/stores/data_style/mesh/polygons/polygon.ts +27 -152
  74. package/internal/stores/data_style/mesh/polygons/polygon_attribute.ts +80 -0
  75. package/internal/stores/data_style/mesh/polygons/polygon_config.ts +148 -0
  76. package/internal/stores/data_style/mesh/polygons/vertex.ts +26 -157
  77. package/internal/stores/data_style/mesh/polygons/vertex_attribute.ts +80 -0
  78. package/internal/stores/data_style/mesh/polygons/vertex_config.ts +152 -0
  79. package/internal/stores/data_style/mesh/polyhedra/polyhedron.ts +27 -160
  80. package/internal/stores/data_style/mesh/polyhedra/polyhedron_attribute.ts +82 -0
  81. package/internal/stores/data_style/mesh/polyhedra/polyhedron_config.ts +157 -0
  82. package/internal/stores/data_style/mesh/polyhedra/vertex.ts +26 -157
  83. package/internal/stores/data_style/mesh/polyhedra/vertex_attribute.ts +80 -0
  84. package/internal/stores/data_style/mesh/polyhedra/vertex_config.ts +152 -0
  85. package/internal/stores/data_style/model/blocks/apply_coloring.ts +173 -0
  86. package/internal/stores/data_style/model/blocks/coloring_groups.ts +18 -0
  87. package/internal/stores/data_style/model/blocks/index.ts +12 -140
  88. package/internal/stores/data_style/model/common.ts +10 -119
  89. package/internal/stores/data_style/model/common_mutations.ts +184 -0
  90. package/internal/stores/data_style/model/lines/apply_coloring.ts +154 -0
  91. package/internal/stores/data_style/model/lines/coloring_groups.ts +18 -0
  92. package/internal/stores/data_style/model/lines/index.ts +10 -134
  93. package/internal/stores/data_style/model/surfaces/apply_coloring.ts +186 -0
  94. package/internal/stores/data_style/model/surfaces/coloring_groups.ts +18 -0
  95. package/internal/stores/data_style/model/surfaces/index.ts +16 -160
  96. package/internal/stores/data_style/model/visibility.ts +3 -156
  97. package/internal/stores/data_style/model/visibility_dispatch.ts +160 -0
  98. package/internal/stores/data_style/state.ts +1 -181
  99. package/internal/stores/data_style/state_shared.ts +191 -0
  100. package/internal/stores/hybrid_viewer/camera.ts +7 -161
  101. package/internal/stores/hybrid_viewer/camera_helpers.ts +120 -0
  102. package/internal/stores/hybrid_viewer/camera_orientation.ts +60 -0
  103. package/internal/stores/hybrid_viewer/filters.ts +54 -11
  104. package/package.json +1 -1
  105. package/server/utils/microservices.ts +10 -109
  106. package/server/utils/microservices_process.ts +127 -0
@@ -0,0 +1,51 @@
1
+ import {
2
+ MESH_ELEMENT_KINDS,
3
+ MODEL_COMPONENT_ATTRIBUTE_SCHEMAS,
4
+ MODEL_COMPONENT_KINDS,
5
+ } from "@ogw_front/utils/attributes";
6
+ import type { AttributeSource } from "@ogw_front/utils/threshold";
7
+ import { attributeSchemas } from "@ogw_front/composables/attribute_coloring_style";
8
+ import type { useDataStore } from "@ogw_front/stores/data";
9
+
10
+ function attributeSource(
11
+ kind: string,
12
+ title: string,
13
+ params: { id: string; component_ids?: string[] },
14
+ modelType?: string,
15
+ ): AttributeSource {
16
+ const schemas = attributeSchemas(modelType === undefined ? "" : "model_component_", kind);
17
+ return {
18
+ title: `${title}${kind} attribute`,
19
+ schemas,
20
+ timeStepKey:
21
+ modelType === undefined
22
+ ? schemas.names.$id
23
+ : (MODEL_COMPONENT_ATTRIBUTE_SCHEMAS[modelType]?.[kind]?.$id ?? schemas.names.$id),
24
+ params,
25
+ location: kind === "vertex" ? "point" : "cell",
26
+ };
27
+ }
28
+
29
+ async function fetchSources(
30
+ dataStore: ReturnType<typeof useDataStore>,
31
+ id: string,
32
+ ): Promise<AttributeSource[]> {
33
+ const item = await dataStore.item(id);
34
+ if (item.viewer_type !== "model") {
35
+ return ["vertex", MESH_ELEMENT_KINDS[item.geode_object_type]]
36
+ .filter((kind): kind is string => kind !== undefined)
37
+ .map((kind) => attributeSource(kind, "", { id }));
38
+ }
39
+ const modelSources = await Promise.all(
40
+ Object.entries(MODEL_COMPONENT_KINDS).map(async ([type, kinds]) => {
41
+ const component_ids = await dataStore.getMeshComponentGeodeIds(id, type);
42
+ if (component_ids.length === 0) {
43
+ return [];
44
+ }
45
+ return kinds.map((kind) => attributeSource(kind, `${type} `, { id, component_ids }, type));
46
+ }),
47
+ );
48
+ return modelSources.flat();
49
+ }
50
+
51
+ export { fetchSources };
@@ -4,148 +4,42 @@ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schem
4
4
  import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
5
5
 
6
6
  // Local imports
7
+ import {
8
+ type UseMeshCellsCellAttributeStyleReturn,
9
+ type ValidAttributeInput,
10
+ isMeshCellsCellAttributeValid,
11
+ } from "./cell_attribute";
12
+ import {
13
+ useMeshCellsCellAttributeConfig,
14
+ useMeshCellsCellAttributeConfigValues,
15
+ useMeshCellsCellAttributeConfigWriter,
16
+ } from "./cell_config";
7
17
  import { getRGBPointsFromPreset } from "@ogw_front/utils/colormap";
8
18
  import { useAttributeTimeStepStyle } from "@ogw_internal/stores/data_style/time_step";
9
- import { useMeshCellsCommonStyle } from "./common";
10
19
  import { useViewerStore } from "@ogw_front/stores/viewer";
11
20
 
12
21
  // Local constants
13
22
  const attributeNamesSchema = back_schemas.opengeodeweb_back.cell_attribute_names;
14
23
  const meshCellsCellAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.cells.attribute.cell;
15
24
 
16
- interface AttributeStoredConfig {
17
- minimum: number | undefined;
18
- maximum: number | undefined;
19
- colorMap: string | undefined;
20
- no_data_color: RGBAColor;
21
- }
22
-
23
- interface AttributeState {
24
- name?: string;
25
- item?: number;
26
- storedConfigs?: Record<string, { lastItem: number } & Record<string, AttributeStoredConfig>>;
27
- }
28
-
29
- interface AttributeInput {
30
- name: string | undefined;
31
- item: number | undefined;
32
- minimum: number | undefined;
33
- maximum: number | undefined;
34
- colorMap: string | undefined;
35
- no_data_color?: RGBAColor;
36
- }
37
-
38
- interface ValidAttributeInput {
39
- name: string;
40
- item: number;
41
- minimum: number;
42
- maximum: number;
43
- colorMap: string;
44
- no_data_color?: RGBAColor;
45
- }
46
-
47
- function isMeshCellsCellAttributeValid(input: AttributeInput): input is ValidAttributeInput {
48
- return (
49
- input.name !== undefined &&
50
- input.item !== undefined &&
51
- input.minimum !== undefined &&
52
- input.maximum !== undefined &&
53
- input.colorMap !== undefined
54
- );
55
- }
56
-
57
25
  // oxlint-disable-next-line max-lines-per-function
58
- function useMeshCellsCellAttributeStyle(): {
59
- meshCellsCellAttributeName: (id: string) => string | undefined;
60
- meshCellsCellAttributeItem: (id: string) => number;
61
- meshCellsCellAttributeRange: (id: string) => [number | undefined, number | undefined];
62
- meshCellsCellAttributeTimeStep: (id: string) => number | undefined;
63
- setMeshCellsCellAttributeTimeStep: (id: string, timeStep: number) => Promise<unknown>;
64
- meshCellsCellAttributeColorMap: (id: string) => string | undefined;
65
- meshCellsCellAttributeStoredConfig: (
66
- id: string,
67
- name: string | undefined,
68
- item: number | undefined,
69
- ) => AttributeStoredConfig;
70
- setMeshCellsCellAttribute: (id: string, input: ValidAttributeInput) => Promise<unknown>;
71
- setMeshCellsCellAttributeName: (id: string, name: string) => Promise<unknown>;
72
- setMeshCellsCellAttributeItem: (id: string, item: number) => Promise<unknown>;
73
- setMeshCellsCellAttributeRange: (
74
- id: string,
75
- minimum: number,
76
- maximum: number,
77
- ) => Promise<unknown>;
78
- setMeshCellsCellAttributeColorMap: (id: string, colorMap: string | undefined) => Promise<unknown>;
79
- meshCellsCellAttributeNoDataColor: (id: string) => RGBAColor;
80
- setMeshCellsCellAttributeNoDataColor: (id: string, no_data_color: RGBAColor) => Promise<unknown>;
81
- } {
26
+ function useMeshCellsCellAttributeStyle(): UseMeshCellsCellAttributeStyleReturn {
82
27
  const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle();
83
28
  const viewerStore = useViewerStore();
84
- const meshCellsCommonStyle = useMeshCellsCommonStyle();
85
- function meshCellsCellAttribute(id: string): AttributeState {
86
- // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.cell shape is defined by the data style schema.
87
- return meshCellsCommonStyle.meshCellsColoring(id).cell as AttributeState;
88
- }
89
- function meshCellsCellAttributeStoredConfig(
90
- id: string,
91
- name: string | undefined,
92
- item: number | undefined,
93
- ): AttributeStoredConfig {
94
- const { storedConfigs } = meshCellsCellAttribute(id);
95
- const nameConfig = name === undefined ? undefined : storedConfigs?.[name];
96
- const itemConfig = item === undefined ? undefined : nameConfig?.[item];
97
- if (itemConfig !== undefined) {
98
- return itemConfig;
99
- }
100
- return {
101
- minimum: undefined,
102
- maximum: undefined,
103
- colorMap: undefined,
104
- no_data_color: DEFAULT_NO_DATA_COLOR,
105
- };
106
- }
107
- async function mutateMeshCellsCellStyle(
108
- id: string,
109
- values: Record<string, unknown>,
110
- ): Promise<string> {
111
- const result = await meshCellsCommonStyle.mutateMeshCellsStyle(id, {
112
- coloring: {
113
- cell: values,
114
- },
115
- });
116
- return result;
117
- }
118
- async function setMeshCellsCellAttributeStoredConfig(
119
- id: string,
120
- name: string | undefined,
121
- item: number | undefined,
122
- config: Partial<AttributeStoredConfig>,
123
- ): Promise<string> {
124
- const result = await mutateMeshCellsCellStyle(id, {
125
- storedConfigs: {
126
- [name ?? ""]: {
127
- lastItem: item,
128
- [item ?? 0]: config,
129
- },
130
- },
131
- });
132
- return result;
133
- }
134
- function meshCellsCellAttributeName(id: string): string | undefined {
135
- return meshCellsCellAttribute(id).name;
136
- }
137
- function meshCellsCellAttributeLastItem(id: string, name: string | undefined): number {
138
- const { storedConfigs } = meshCellsCellAttribute(id);
139
- const nameConfig = name === undefined ? undefined : storedConfigs?.[name];
140
- if (nameConfig !== undefined) {
141
- return nameConfig.lastItem;
142
- }
143
- return 0;
144
- }
145
- function meshCellsCellAttributeItem(id: string): number {
146
- const { item, name } = meshCellsCellAttribute(id);
147
- return item ?? meshCellsCellAttributeLastItem(id, name);
148
- }
29
+ const {
30
+ meshCellsCellAttribute,
31
+ meshCellsCellAttributeName,
32
+ meshCellsCellAttributeLastItem,
33
+ meshCellsCellAttributeItem,
34
+ meshCellsCellAttributeStoredConfig,
35
+ } = useMeshCellsCellAttributeConfig();
36
+ const {
37
+ meshCellsCellAttributeRange,
38
+ meshCellsCellAttributeColorMap,
39
+ meshCellsCellAttributeNoDataColor,
40
+ } = useMeshCellsCellAttributeConfigValues();
41
+ const { mutateMeshCellsCellStyle, setMeshCellsCellAttributeStoredConfig } =
42
+ useMeshCellsCellAttributeConfigWriter();
149
43
  function meshCellsCellAttributeTimeStep(id: string): number | undefined {
150
44
  return attributeTimeStep(id, attributeNamesSchema.$id, meshCellsCellAttribute(id).name);
151
45
  }
@@ -218,12 +112,6 @@ function useMeshCellsCellAttributeStyle(): {
218
112
  });
219
113
  return applyCellAttribute(id);
220
114
  }
221
- function meshCellsCellAttributeRange(id: string): [number | undefined, number | undefined] {
222
- const name = meshCellsCellAttributeName(id);
223
- const item = meshCellsCellAttributeItem(id);
224
- const storedConfig = meshCellsCellAttributeStoredConfig(id, name, item);
225
- return [storedConfig.minimum, storedConfig.maximum];
226
- }
227
115
  async function setMeshCellsCellAttributeTimeStep(id: string, timeStep: number): Promise<unknown> {
228
116
  const name = meshCellsCellAttributeName(id);
229
117
  if (name === undefined) {
@@ -245,12 +133,6 @@ function useMeshCellsCellAttributeStyle(): {
245
133
  });
246
134
  return applyCellAttribute(id);
247
135
  }
248
- function meshCellsCellAttributeColorMap(id: string): string | undefined {
249
- const name = meshCellsCellAttributeName(id);
250
- const item = meshCellsCellAttributeItem(id);
251
- const storedConfig = meshCellsCellAttributeStoredConfig(id, name, item);
252
- return storedConfig.colorMap;
253
- }
254
136
  async function setMeshCellsCellAttributeColorMap(
255
137
  id: string,
256
138
  colorMap: string | undefined,
@@ -262,12 +144,6 @@ function useMeshCellsCellAttributeStyle(): {
262
144
  });
263
145
  return applyCellAttribute(id);
264
146
  }
265
- function meshCellsCellAttributeNoDataColor(id: string): RGBAColor {
266
- const name = meshCellsCellAttributeName(id);
267
- const item = meshCellsCellAttributeItem(id);
268
- const storedConfig = meshCellsCellAttributeStoredConfig(id, name, item);
269
- return storedConfig.no_data_color;
270
- }
271
147
  async function setMeshCellsCellAttributeNoDataColor(
272
148
  id: string,
273
149
  no_data_color: RGBAColor,
@@ -298,4 +174,5 @@ function useMeshCellsCellAttributeStyle(): {
298
174
  setMeshCellsCellAttributeNoDataColor,
299
175
  };
300
176
  }
301
- export { isMeshCellsCellAttributeValid, useMeshCellsCellAttributeStyle };
177
+ export { useMeshCellsCellAttributeStyle };
178
+ export { isMeshCellsCellAttributeValid } from "./cell_attribute";
@@ -0,0 +1,74 @@
1
+ import type { RGBAColor } from "@ogw_front/utils/default_styles/constants";
2
+
3
+ interface AttributeStoredConfig {
4
+ minimum: number | undefined;
5
+ maximum: number | undefined;
6
+ colorMap: string | undefined;
7
+ no_data_color: RGBAColor;
8
+ }
9
+
10
+ interface AttributeState {
11
+ name?: string;
12
+ item?: number;
13
+ storedConfigs?: Record<string, { lastItem: number } & Record<string, AttributeStoredConfig>>;
14
+ }
15
+
16
+ interface AttributeInput {
17
+ name: string | undefined;
18
+ item: number | undefined;
19
+ minimum: number | undefined;
20
+ maximum: number | undefined;
21
+ colorMap: string | undefined;
22
+ no_data_color?: RGBAColor;
23
+ }
24
+
25
+ interface ValidAttributeInput {
26
+ name: string;
27
+ item: number;
28
+ minimum: number;
29
+ maximum: number;
30
+ colorMap: string;
31
+ no_data_color?: RGBAColor;
32
+ }
33
+
34
+ function isMeshCellsCellAttributeValid(input: AttributeInput): input is ValidAttributeInput {
35
+ return (
36
+ input.name !== undefined &&
37
+ input.item !== undefined &&
38
+ input.minimum !== undefined &&
39
+ input.maximum !== undefined &&
40
+ input.colorMap !== undefined
41
+ );
42
+ }
43
+
44
+ interface UseMeshCellsCellAttributeStyleReturn {
45
+ meshCellsCellAttributeName: (id: string) => string | undefined;
46
+ meshCellsCellAttributeItem: (id: string) => number;
47
+ meshCellsCellAttributeRange: (id: string) => [number | undefined, number | undefined];
48
+ meshCellsCellAttributeTimeStep: (id: string) => number | undefined;
49
+ setMeshCellsCellAttributeTimeStep: (id: string, timeStep: number) => Promise<unknown>;
50
+ meshCellsCellAttributeColorMap: (id: string) => string | undefined;
51
+ meshCellsCellAttributeStoredConfig: (
52
+ id: string,
53
+ name: string | undefined,
54
+ item: number | undefined,
55
+ ) => AttributeStoredConfig;
56
+ setMeshCellsCellAttribute: (id: string, input: ValidAttributeInput) => Promise<unknown>;
57
+ setMeshCellsCellAttributeName: (id: string, name: string) => Promise<unknown>;
58
+ setMeshCellsCellAttributeItem: (id: string, item: number) => Promise<unknown>;
59
+ setMeshCellsCellAttributeRange: (
60
+ id: string,
61
+ minimum: number,
62
+ maximum: number,
63
+ ) => Promise<unknown>;
64
+ setMeshCellsCellAttributeColorMap: (id: string, colorMap: string | undefined) => Promise<unknown>;
65
+ meshCellsCellAttributeNoDataColor: (id: string) => RGBAColor;
66
+ setMeshCellsCellAttributeNoDataColor: (id: string, no_data_color: RGBAColor) => Promise<unknown>;
67
+ }
68
+ export { isMeshCellsCellAttributeValid };
69
+ export type {
70
+ AttributeStoredConfig,
71
+ AttributeState,
72
+ ValidAttributeInput,
73
+ UseMeshCellsCellAttributeStyleReturn,
74
+ };
@@ -0,0 +1,152 @@
1
+ import type { AttributeState, AttributeStoredConfig } from "./cell_attribute";
2
+ import { DEFAULT_NO_DATA_COLOR, type RGBAColor } from "@ogw_front/utils/default_styles/constants";
3
+
4
+ // Local imports
5
+ import { useMeshCellsCommonStyle } from "./common";
6
+
7
+ interface UseMeshCellsCellAttributeConfigReturn {
8
+ meshCellsCellAttribute: (id: string) => AttributeState;
9
+ meshCellsCellAttributeName: (id: string) => string | undefined;
10
+ meshCellsCellAttributeLastItem: (id: string, name: string | undefined) => number;
11
+ meshCellsCellAttributeItem: (id: string) => number;
12
+ meshCellsCellAttributeStoredConfig: (
13
+ id: string,
14
+ name: string | undefined,
15
+ item: number | undefined,
16
+ ) => AttributeStoredConfig;
17
+ }
18
+
19
+ interface UseMeshCellsCellAttributeConfigWriterReturn {
20
+ mutateMeshCellsCellStyle: (id: string, values: Record<string, unknown>) => Promise<string>;
21
+ setMeshCellsCellAttributeStoredConfig: (
22
+ id: string,
23
+ name: string | undefined,
24
+ item: number | undefined,
25
+ config: Partial<AttributeStoredConfig>,
26
+ ) => Promise<string>;
27
+ }
28
+
29
+ function useMeshCellsCellAttributeConfig(): UseMeshCellsCellAttributeConfigReturn {
30
+ const meshCellsCommonStyle = useMeshCellsCommonStyle();
31
+ function meshCellsCellAttribute(id: string): AttributeState {
32
+ // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.cell shape is defined by the data style schema.
33
+ return meshCellsCommonStyle.meshCellsColoring(id).cell as AttributeState;
34
+ }
35
+ function meshCellsCellAttributeStoredConfig(
36
+ id: string,
37
+ name: string | undefined,
38
+ item: number | undefined,
39
+ ): AttributeStoredConfig {
40
+ const { storedConfigs } = meshCellsCellAttribute(id);
41
+ const nameConfig = name === undefined ? undefined : storedConfigs?.[name];
42
+ const itemConfig = item === undefined ? undefined : nameConfig?.[item];
43
+ if (itemConfig !== undefined) {
44
+ return itemConfig;
45
+ }
46
+ return {
47
+ minimum: undefined,
48
+ maximum: undefined,
49
+ colorMap: undefined,
50
+ no_data_color: DEFAULT_NO_DATA_COLOR,
51
+ };
52
+ }
53
+ function meshCellsCellAttributeName(id: string): string | undefined {
54
+ return meshCellsCellAttribute(id).name;
55
+ }
56
+ function meshCellsCellAttributeLastItem(id: string, name: string | undefined): number {
57
+ const { storedConfigs } = meshCellsCellAttribute(id);
58
+ const nameConfig = name === undefined ? undefined : storedConfigs?.[name];
59
+ if (nameConfig !== undefined) {
60
+ return nameConfig.lastItem;
61
+ }
62
+ return 0;
63
+ }
64
+ function meshCellsCellAttributeItem(id: string): number {
65
+ const { item, name } = meshCellsCellAttribute(id);
66
+ return item ?? meshCellsCellAttributeLastItem(id, name);
67
+ }
68
+ return {
69
+ meshCellsCellAttribute,
70
+ meshCellsCellAttributeName,
71
+ meshCellsCellAttributeLastItem,
72
+ meshCellsCellAttributeItem,
73
+ meshCellsCellAttributeStoredConfig,
74
+ };
75
+ }
76
+
77
+ interface UseMeshCellsCellAttributeConfigValuesReturn {
78
+ meshCellsCellAttributeRange: (id: string) => [number | undefined, number | undefined];
79
+ meshCellsCellAttributeColorMap: (id: string) => string | undefined;
80
+ meshCellsCellAttributeNoDataColor: (id: string) => RGBAColor;
81
+ }
82
+
83
+ function useMeshCellsCellAttributeConfigValues(): UseMeshCellsCellAttributeConfigValuesReturn {
84
+ const {
85
+ meshCellsCellAttributeName,
86
+ meshCellsCellAttributeItem,
87
+ meshCellsCellAttributeStoredConfig,
88
+ } = useMeshCellsCellAttributeConfig();
89
+ function meshCellsCellAttributeRange(id: string): [number | undefined, number | undefined] {
90
+ const name = meshCellsCellAttributeName(id);
91
+ const item = meshCellsCellAttributeItem(id);
92
+ const storedConfig = meshCellsCellAttributeStoredConfig(id, name, item);
93
+ return [storedConfig.minimum, storedConfig.maximum];
94
+ }
95
+ function meshCellsCellAttributeColorMap(id: string): string | undefined {
96
+ const name = meshCellsCellAttributeName(id);
97
+ const item = meshCellsCellAttributeItem(id);
98
+ const storedConfig = meshCellsCellAttributeStoredConfig(id, name, item);
99
+ return storedConfig.colorMap;
100
+ }
101
+ function meshCellsCellAttributeNoDataColor(id: string): RGBAColor {
102
+ const name = meshCellsCellAttributeName(id);
103
+ const item = meshCellsCellAttributeItem(id);
104
+ const storedConfig = meshCellsCellAttributeStoredConfig(id, name, item);
105
+ return storedConfig.no_data_color;
106
+ }
107
+ return {
108
+ meshCellsCellAttributeRange,
109
+ meshCellsCellAttributeColorMap,
110
+ meshCellsCellAttributeNoDataColor,
111
+ };
112
+ }
113
+
114
+ function useMeshCellsCellAttributeConfigWriter(): UseMeshCellsCellAttributeConfigWriterReturn {
115
+ const meshCellsCommonStyle = useMeshCellsCommonStyle();
116
+ async function mutateMeshCellsCellStyle(
117
+ id: string,
118
+ values: Record<string, unknown>,
119
+ ): Promise<string> {
120
+ const result = await meshCellsCommonStyle.mutateMeshCellsStyle(id, {
121
+ coloring: {
122
+ cell: values,
123
+ },
124
+ });
125
+ return result;
126
+ }
127
+ async function setMeshCellsCellAttributeStoredConfig(
128
+ id: string,
129
+ name: string | undefined,
130
+ item: number | undefined,
131
+ config: Partial<AttributeStoredConfig>,
132
+ ): Promise<string> {
133
+ const result = await mutateMeshCellsCellStyle(id, {
134
+ storedConfigs: {
135
+ [name ?? ""]: {
136
+ lastItem: item,
137
+ [item ?? 0]: config,
138
+ },
139
+ },
140
+ });
141
+ return result;
142
+ }
143
+ return {
144
+ mutateMeshCellsCellStyle,
145
+ setMeshCellsCellAttributeStoredConfig,
146
+ };
147
+ }
148
+ export {
149
+ useMeshCellsCellAttributeConfig,
150
+ useMeshCellsCellAttributeConfigValues,
151
+ useMeshCellsCellAttributeConfigWriter,
152
+ };