@geode/opengeodeweb-front 12.2.0-rc.2 → 12.2.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build/tests/browser/helpers/image.js +25 -0
- package/.build/tests/browser/suites/image/raster_image.js +33 -0
- package/.build/tests/browser/suites/index.js +2 -0
- package/app/components/Viewer/Image/ImageOptions.vue +67 -0
- package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +3 -2
- package/app/composables/hover_highlight.ts +6 -5
- package/app/composables/use_overlapping_picker.ts +6 -1
- package/app/stores/data_style.ts +12 -1
- package/app/stores/menu_helpers/image.ts +11 -0
- package/app/stores/menu_helpers/menus_data.ts +2 -0
- package/app/types/identifiers.ts +8 -0
- package/app/utils/default_styles/images.ts +16 -0
- package/app/utils/default_styles/index.ts +3 -2
- package/app/utils/threshold_sources.ts +5 -1
- package/internal/stores/data_style/image/index.ts +107 -0
- package/package.json +1 -1
- package/tests/browser/helpers/image.ts +33 -0
- package/tests/browser/suites/image/raster_image.ts +40 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { waitForActionSettled } from "./wait_for_action_settled.js";
|
|
2
|
+
import { moveMouseOutOfTheWay } from "./app_interaction.js";
|
|
3
|
+
import { openDataContextMenu } from "./object_trees/main_object_tree.js";
|
|
4
|
+
import { ensureMenuOpen } from "./viewer_menu.js";
|
|
5
|
+
import "./viewer_interaction.js";
|
|
6
|
+
//#region tests/browser/helpers/image.ts
|
|
7
|
+
const IMAGE_MENU_TEST_ID = "imageMenu";
|
|
8
|
+
async function openImageMenu(window, geodeObjectType, dataName) {
|
|
9
|
+
await openDataContextMenu(window, geodeObjectType, dataName);
|
|
10
|
+
await ensureMenuOpen(window, IMAGE_MENU_TEST_ID);
|
|
11
|
+
}
|
|
12
|
+
async function setImageOpacity(window, opacity) {
|
|
13
|
+
await ensureMenuOpen(window, IMAGE_MENU_TEST_ID);
|
|
14
|
+
const track = window.getByTestId("imageOpacitySlider").locator(".v-slider").first();
|
|
15
|
+
const box = await track.boundingBox();
|
|
16
|
+
if (!box) throw new Error("Could not get bounding box of the image opacity slider");
|
|
17
|
+
await track.click({ position: {
|
|
18
|
+
x: box.width * opacity,
|
|
19
|
+
y: box.height / 2
|
|
20
|
+
} });
|
|
21
|
+
await moveMouseOutOfTheWay(window);
|
|
22
|
+
await waitForActionSettled(window);
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { IMAGE_MENU_TEST_ID, openImageMenu, setImageOpacity };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __exportAll } from "../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { closeAllMenus } from "../../helpers/app_interaction.js";
|
|
3
|
+
import { expandMainObjectTree } from "../../helpers/object_trees/main_object_tree.js";
|
|
4
|
+
import { setVisibilityGeneric } from "../../helpers/viewer_menu.js";
|
|
5
|
+
import "../../helpers/viewer_interaction.js";
|
|
6
|
+
import { IMAGE_MENU_TEST_ID, openImageMenu, setImageOpacity } from "../../helpers/image.js";
|
|
7
|
+
//#region tests/browser/suites/image/raster_image.ts
|
|
8
|
+
var raster_image_exports = /* @__PURE__ */ __exportAll({ registerTests: () => registerTests });
|
|
9
|
+
const inputFilename = "test_texture.png";
|
|
10
|
+
const dataName = "test_texture";
|
|
11
|
+
const geodeObjectType = "RasterImage2D";
|
|
12
|
+
const halfOpacity = .5;
|
|
13
|
+
function registerTests({ test, loadTestDatas }) {
|
|
14
|
+
test.describe.configure({ mode: "serial" });
|
|
15
|
+
test("load shows the image colors", async ({ window }) => {
|
|
16
|
+
await loadTestDatas(window, [inputFilename]);
|
|
17
|
+
await expandMainObjectTree(window);
|
|
18
|
+
});
|
|
19
|
+
test("image menu", async ({ window }) => {
|
|
20
|
+
await openImageMenu(window, geodeObjectType, dataName);
|
|
21
|
+
});
|
|
22
|
+
test("image opacity", async ({ window }) => {
|
|
23
|
+
await setImageOpacity(window, halfOpacity);
|
|
24
|
+
});
|
|
25
|
+
test("image hidden", async ({ window }) => {
|
|
26
|
+
await setVisibilityGeneric(window, IMAGE_MENU_TEST_ID, "imageVisibilitySwitch", false);
|
|
27
|
+
});
|
|
28
|
+
test("close image menu", async ({ window }) => {
|
|
29
|
+
await closeAllMenus(window);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { raster_image_exports, registerTests };
|
|
@@ -2,6 +2,7 @@ import { crs_exports } from "./crs.js";
|
|
|
2
2
|
import { crs_harmonize_exports } from "./crs_harmonize.js";
|
|
3
3
|
import { crs_shortlist_exports } from "./crs_shortlist.js";
|
|
4
4
|
import { grid_scale_exports } from "./grid_scale.js";
|
|
5
|
+
import { raster_image_exports } from "./image/raster_image.js";
|
|
5
6
|
import { edged_curve_exports } from "./mesh/edged_curve.js";
|
|
6
7
|
import { grid2d_exports } from "./mesh/grid2d.js";
|
|
7
8
|
import { grid3d_exports } from "./mesh/grid3d.js";
|
|
@@ -31,6 +32,7 @@ const suites = Object.fromEntries(Object.entries(/* @__PURE__ */ Object.assign({
|
|
|
31
32
|
"./crs_harmonize.ts": crs_harmonize_exports,
|
|
32
33
|
"./crs_shortlist.ts": crs_shortlist_exports,
|
|
33
34
|
"./grid_scale.ts": grid_scale_exports,
|
|
35
|
+
"./image/raster_image.ts": raster_image_exports,
|
|
34
36
|
"./mesh/edged_curve.ts": edged_curve_exports,
|
|
35
37
|
"./mesh/grid2d.ts": grid2d_exports,
|
|
36
38
|
"./mesh/grid3d.ts": grid3d_exports,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { Opacity, Visibility } from "@geode/opengeodeweb-viewer/schema_types";
|
|
3
|
+
import ViewerContextMenuItem, {
|
|
4
|
+
type ItemProps,
|
|
5
|
+
} from "@ogw_front/components/Viewer/ContextMenu/ContextMenuItem.vue";
|
|
6
|
+
import type { ImageId } from "@ogw_front/types/identifiers";
|
|
7
|
+
import ViewerOptionsOpacitySlider from "@ogw_front/components/Viewer/Options/Sliders/Opacity.vue";
|
|
8
|
+
import ViewerOptionsVisibilitySwitch from "@ogw_front/components/Viewer/Options/VisibilitySwitch.vue";
|
|
9
|
+
import { useBatchStyle } from "@ogw_front/composables/batch_style";
|
|
10
|
+
import { useDataStyleStore } from "@ogw_front/stores/data_style";
|
|
11
|
+
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
|
|
12
|
+
|
|
13
|
+
const dataStyleStore = useDataStyleStore();
|
|
14
|
+
const hybridViewerStore = useHybridViewerStore();
|
|
15
|
+
const { applyBatchStyle } = useBatchStyle();
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
itemProps: ItemProps & { index: number };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { itemProps } = defineProps<Props>();
|
|
22
|
+
|
|
23
|
+
const dataId = toRef(() => itemProps.id);
|
|
24
|
+
|
|
25
|
+
const visibility = computed<Visibility | undefined>({
|
|
26
|
+
get: () => dataStyleStore.imageVisibility(dataId.value),
|
|
27
|
+
set: async (newValue) => {
|
|
28
|
+
if (newValue === undefined) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
await applyBatchStyle(dataId.value, (imageId: ImageId) =>
|
|
32
|
+
dataStyleStore.setImageVisibility(imageId, newValue),
|
|
33
|
+
);
|
|
34
|
+
hybridViewerStore.remoteRender();
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const opacity = computed<Opacity | undefined>({
|
|
38
|
+
get: () => dataStyleStore.imageOpacity(dataId.value),
|
|
39
|
+
set: async (newValue) => {
|
|
40
|
+
if (newValue === undefined) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await applyBatchStyle(dataId.value, (imageId: ImageId) =>
|
|
44
|
+
dataStyleStore.setImageOpacity(imageId, newValue),
|
|
45
|
+
);
|
|
46
|
+
hybridViewerStore.remoteRender();
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<ViewerContextMenuItem
|
|
53
|
+
data-testid="imageMenu"
|
|
54
|
+
:index="itemProps.index"
|
|
55
|
+
:itemProps="itemProps"
|
|
56
|
+
tooltip="Image options"
|
|
57
|
+
btnIcon="ph-image"
|
|
58
|
+
>
|
|
59
|
+
<template #options>
|
|
60
|
+
<ViewerOptionsVisibilitySwitch data-testid="imageVisibilitySwitch" v-model="visibility" />
|
|
61
|
+
<template v-if="visibility">
|
|
62
|
+
<v-divider class="my-2" />
|
|
63
|
+
<ViewerOptionsOpacitySlider data-testid="imageOpacitySlider" v-model="opacity" />
|
|
64
|
+
</template>
|
|
65
|
+
</template>
|
|
66
|
+
</ViewerContextMenuItem>
|
|
67
|
+
</template>
|
|
@@ -185,7 +185,8 @@ function handleHoverEnter({
|
|
|
185
185
|
}): void {
|
|
186
186
|
const actualItem = item.raw || item;
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
// Images are not pickable: the viewer has nothing to highlight
|
|
189
|
+
if (!actualItem.viewer_object_type || actualItem.viewer_object_type === "image") {
|
|
189
190
|
return;
|
|
190
191
|
}
|
|
191
192
|
|
|
@@ -209,7 +210,7 @@ function handleHoverEnter({
|
|
|
209
210
|
|
|
210
211
|
function handleHoverLeave({ item }: { item: TreeGroupItem }): void {
|
|
211
212
|
const actualItem = item.raw || item;
|
|
212
|
-
if (!actualItem.viewer_object_type) {
|
|
213
|
+
if (!actualItem.viewer_object_type || actualItem.viewer_object_type === "image") {
|
|
213
214
|
return;
|
|
214
215
|
}
|
|
215
216
|
if (treeviewStore.hoveredModelId === actualItem.id) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
|
|
2
|
+
import type { HighlightableObjectType } from "@ogw_front/types/identifiers";
|
|
2
3
|
import type { ParamsOf } from "@ogw_shared/utils/types";
|
|
3
4
|
import type { ViewerId } from "@geode/opengeodeweb-viewer/schema_types";
|
|
4
|
-
import type { ViewerObjectType } from "@geode/opengeodeweb-microservice/data_types";
|
|
5
5
|
import { consola } from "consola";
|
|
6
6
|
import { useDataStore } from "@ogw_front/stores/data";
|
|
7
7
|
import { useViewerStore } from "@ogw_front/stores/viewer";
|
|
@@ -9,7 +9,8 @@ import vtk_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_sc
|
|
|
9
9
|
|
|
10
10
|
const HOVER_DELAY = 200;
|
|
11
11
|
|
|
12
|
-
type HighlightSchema =
|
|
12
|
+
type HighlightSchema =
|
|
13
|
+
(typeof vtk_schemas)["opengeodeweb_viewer"][HighlightableObjectType]["highlight"];
|
|
13
14
|
type BlockIdsProvider =
|
|
14
15
|
| readonly ViewerId[]
|
|
15
16
|
| (() => readonly ViewerId[] | Promise<readonly ViewerId[]>);
|
|
@@ -37,12 +38,12 @@ function useHoverhighlight(): {
|
|
|
37
38
|
// Item hovered last, whose highlight may still be pending
|
|
38
39
|
let currentId: DataId | undefined = undefined;
|
|
39
40
|
// Item the viewer was asked to highlight, the only one to unhighlight
|
|
40
|
-
let highlighted: { dataId: DataId; type:
|
|
41
|
+
let highlighted: { dataId: DataId; type: HighlightableObjectType } | undefined = undefined;
|
|
41
42
|
|
|
42
43
|
function onHoverEnter(
|
|
43
44
|
dataId: DataId,
|
|
44
45
|
block_ids_provider: BlockIdsProvider = [],
|
|
45
|
-
type:
|
|
46
|
+
type: HighlightableObjectType = "model",
|
|
46
47
|
immediate = false,
|
|
47
48
|
): void {
|
|
48
49
|
if (timer) {
|
|
@@ -109,7 +110,7 @@ function useHoverhighlight(): {
|
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
async function unhighlightAction(
|
|
112
|
-
type:
|
|
113
|
+
type: HighlightableObjectType,
|
|
113
114
|
dataId: DataId,
|
|
114
115
|
request: {
|
|
115
116
|
schema: HighlightSchema;
|
|
@@ -112,7 +112,12 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
async function getViewableIds(): Promise<string[]> {
|
|
115
|
-
|
|
115
|
+
// Images are not pickable
|
|
116
|
+
const activeIds = new Set(
|
|
117
|
+
dataItems.value
|
|
118
|
+
.filter((i: DataItem) => i.viewer_object_type !== "image")
|
|
119
|
+
.map((i: DataItem) => i.data_id),
|
|
120
|
+
);
|
|
116
121
|
const visibleStyleIds = Object.keys(dataStyleStore.styles).filter(
|
|
117
122
|
(styleId) => activeIds.has(styleId) && dataStyleStore.objectVisibility(styleId) === true,
|
|
118
123
|
);
|
package/app/stores/data_style.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { getDefaultStyle } from "@ogw_front/utils/default_styles";
|
|
|
14
14
|
import { useAttributeTimeStepStyle } from "@ogw_internal/stores/data_style/time_step";
|
|
15
15
|
import { useDataStore } from "@ogw_front/stores/data";
|
|
16
16
|
import { useDataStyleState } from "@ogw_internal/stores/data_style/state";
|
|
17
|
+
import { useImageStyle } from "@ogw_internal/stores/data_style/image/index";
|
|
17
18
|
import { useMeshStyle } from "@ogw_internal/stores/data_style/mesh/index";
|
|
18
19
|
import { useModelStyle } from "@ogw_internal/stores/data_style/model/index";
|
|
19
20
|
import { useSceneStyle } from "@ogw_internal/stores/data_style/scene";
|
|
@@ -44,6 +45,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
44
45
|
// oxlint-disable-next-line max-lines-per-function
|
|
45
46
|
export const useDataStyleStore = defineStore("dataStyle", () => {
|
|
46
47
|
const dataStyleState = useDataStyleState();
|
|
48
|
+
const imageStyleStore = useImageStyle();
|
|
47
49
|
const meshStyleStore = useMeshStyle();
|
|
48
50
|
const modelStyleStore = useModelStyle();
|
|
49
51
|
const sceneStyleStore = useSceneStyle();
|
|
@@ -76,6 +78,9 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
|
|
|
76
78
|
|
|
77
79
|
const { viewer_object_type } = item;
|
|
78
80
|
|
|
81
|
+
if (viewer_object_type === "image") {
|
|
82
|
+
return imageStyleStore.setImageVisibility(dataId, visibility);
|
|
83
|
+
}
|
|
79
84
|
if (viewer_object_type === "mesh") {
|
|
80
85
|
return meshStyleStore.setMeshVisibility(dataId, visibility);
|
|
81
86
|
}
|
|
@@ -93,6 +98,9 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
|
|
|
93
98
|
|
|
94
99
|
const { viewer_object_type } = item;
|
|
95
100
|
|
|
101
|
+
if (viewer_object_type === "image") {
|
|
102
|
+
return imageStyleStore.applyImageStyle(dataId);
|
|
103
|
+
}
|
|
96
104
|
if (viewer_object_type === "mesh") {
|
|
97
105
|
return meshStyleStore.applyMeshStyle(dataId);
|
|
98
106
|
}
|
|
@@ -158,7 +166,9 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
|
|
|
158
166
|
return;
|
|
159
167
|
}
|
|
160
168
|
const viewerObjectType = meta.viewer_object_type;
|
|
161
|
-
if (viewerObjectType === "
|
|
169
|
+
if (viewerObjectType === "image") {
|
|
170
|
+
await imageStyleStore.applyImageStyle(dataId);
|
|
171
|
+
} else if (viewerObjectType === "mesh") {
|
|
162
172
|
await meshStyleStore.applyMeshStyle(dataId);
|
|
163
173
|
} else if (viewerObjectType === "model") {
|
|
164
174
|
await modelStyleStore.applyModelStyle(dataId);
|
|
@@ -177,6 +187,7 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
|
|
|
177
187
|
applyAllStylesFromState,
|
|
178
188
|
...dataStyleState,
|
|
179
189
|
...attributeTimeStepStyle,
|
|
190
|
+
...imageStyleStore,
|
|
180
191
|
...meshStyleStore,
|
|
181
192
|
...modelStyleStore,
|
|
182
193
|
...sceneStyleStore,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ImageOptions from "@ogw_front/components/Viewer/Image/ImageOptions.vue";
|
|
2
|
+
import type { MenuItems } from "./types.js";
|
|
3
|
+
|
|
4
|
+
const Image_menu = [ImageOptions];
|
|
5
|
+
|
|
6
|
+
const imageMenus: Record<string, MenuItems> = {
|
|
7
|
+
RasterImage2D: Image_menu,
|
|
8
|
+
RasterImage3D: Image_menu,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { imageMenus };
|
|
@@ -3,12 +3,14 @@ import type { MenuItems } from "./types.js";
|
|
|
3
3
|
import { basemapMenus } from "./basemap.js";
|
|
4
4
|
import { edgedCurveMenus } from "./mesh/edged_curve.js";
|
|
5
5
|
import { gridMenus } from "./mesh/grid.js";
|
|
6
|
+
import { imageMenus } from "./image.js";
|
|
6
7
|
import { pointSetMenus } from "./mesh/point_set.js";
|
|
7
8
|
import { sceneMenus } from "./scene.js";
|
|
8
9
|
import { solidMenus } from "./mesh/solid.js";
|
|
9
10
|
import { surfaceMenus } from "./mesh/surface.js";
|
|
10
11
|
|
|
11
12
|
const menusData: Record<string, Record<string, MenuItems>> = {
|
|
13
|
+
image: imageMenus,
|
|
12
14
|
mesh: {
|
|
13
15
|
...edgedCurveMenus,
|
|
14
16
|
...gridMenus,
|
package/app/types/identifiers.ts
CHANGED
|
@@ -7,12 +7,18 @@ import type {
|
|
|
7
7
|
// Id of a component of a model (a corner, a line, a surface or a block): its geode_id
|
|
8
8
|
type ModelComponentId = GeodeId;
|
|
9
9
|
|
|
10
|
+
// The data of an image, the data an image style applies to
|
|
11
|
+
type ImageId = DataId;
|
|
12
|
+
|
|
10
13
|
// The data of a mesh, the data a mesh style applies to
|
|
11
14
|
type MeshId = DataId;
|
|
12
15
|
|
|
13
16
|
// The data of a model, the data a model style or a model component applies to
|
|
14
17
|
type ModelId = DataId;
|
|
15
18
|
|
|
19
|
+
// The viewer objects the viewer can highlight: images are not pickable
|
|
20
|
+
type HighlightableObjectType = Exclude<ViewerObjectType, "image">;
|
|
21
|
+
|
|
16
22
|
// A corner of a model, by its id in the model
|
|
17
23
|
type CornerId = ModelComponentId;
|
|
18
24
|
|
|
@@ -52,6 +58,8 @@ export type {
|
|
|
52
58
|
DataIdentified,
|
|
53
59
|
GeodeIdentified,
|
|
54
60
|
GeodeObjectTyped,
|
|
61
|
+
HighlightableObjectType,
|
|
62
|
+
ImageId,
|
|
55
63
|
LineId,
|
|
56
64
|
MeshId,
|
|
57
65
|
ModelComponentId,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Opacity, Visibility } from "@geode/opengeodeweb-viewer/schema_types";
|
|
2
|
+
|
|
3
|
+
interface ImageStyle {
|
|
4
|
+
visibility: Visibility;
|
|
5
|
+
opacity: Opacity;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function imageDefaultStyle(): ImageStyle {
|
|
9
|
+
return {
|
|
10
|
+
visibility: true,
|
|
11
|
+
opacity: 1,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { imageDefaultStyle };
|
|
16
|
+
export type { ImageStyle };
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from "./meshes";
|
|
23
23
|
import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types";
|
|
24
24
|
import type { SceneStyle } from "@ogw_internal/stores/data_style/types";
|
|
25
|
+
import { imageDefaultStyle } from "./images";
|
|
25
26
|
|
|
26
27
|
function default_styles(): Record<string, unknown> {
|
|
27
28
|
return {
|
|
@@ -40,8 +41,8 @@ function default_styles(): Record<string, unknown> {
|
|
|
40
41
|
PolygonalSurface2D: surfaceDefaultStyle(),
|
|
41
42
|
PolygonalSurface3D: surfaceDefaultStyle(),
|
|
42
43
|
PolyhedralSolid3D: solidDefaultStyle(),
|
|
43
|
-
RasterImage2D:
|
|
44
|
-
RasterImage3D:
|
|
44
|
+
RasterImage2D: imageDefaultStyle(),
|
|
45
|
+
RasterImage3D: imageDefaultStyle(),
|
|
45
46
|
RegularGrid2D: grid2dDefaultStyle(),
|
|
46
47
|
RegularGrid3D: grid3dDefaultStyle(),
|
|
47
48
|
Section: sectionDefaultStyle(),
|
|
@@ -32,7 +32,11 @@ async function fetchSources(
|
|
|
32
32
|
dataId: DataId,
|
|
33
33
|
): Promise<AttributeSource[]> {
|
|
34
34
|
const item = await dataStore.item(dataId);
|
|
35
|
-
|
|
35
|
+
// An image shows its own colors: it has no attribute to threshold
|
|
36
|
+
if (item.viewer_object_type === "image") {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
if (item.viewer_object_type === "mesh") {
|
|
36
40
|
return ["vertex", MESH_ELEMENT_KINDS[item.geode_object_type]]
|
|
37
41
|
.filter((kind): kind is string => kind !== undefined)
|
|
38
42
|
.map((kind) => attributeSource(kind, "", { id: dataId }));
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Opacity, Visibility } from "@geode/opengeodeweb-viewer/schema_types";
|
|
2
|
+
import type { ImageId } from "@ogw_front/types/identifiers";
|
|
3
|
+
// Third party imports
|
|
4
|
+
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
|
|
5
|
+
|
|
6
|
+
// Local imports
|
|
7
|
+
import { useDataStyleState } from "@ogw_internal/stores/data_style/state";
|
|
8
|
+
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
|
|
9
|
+
import { useViewerStore } from "@ogw_front/stores/viewer";
|
|
10
|
+
import { whenDefined } from "@ogw_internal/stores/data_style/when_defined";
|
|
11
|
+
|
|
12
|
+
// Local constants
|
|
13
|
+
const imageSchemas = viewer_schemas.opengeodeweb_viewer.image;
|
|
14
|
+
|
|
15
|
+
interface ImageStyleStore {
|
|
16
|
+
imageVisibility: (imageId: ImageId) => Visibility | undefined;
|
|
17
|
+
setImageVisibility: (imageId: ImageId, visibility: Visibility) => Promise<unknown>;
|
|
18
|
+
imageOpacity: (imageId: ImageId) => Opacity | undefined;
|
|
19
|
+
setImageOpacity: (imageId: ImageId, opacity: Opacity) => Promise<unknown>;
|
|
20
|
+
applyImageStyle: (imageId: ImageId) => Promise<unknown[]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// An image shows its own colors: only its visibility and its opacity are styled
|
|
24
|
+
// oxlint-disable-next-line max-lines-per-function
|
|
25
|
+
export function useImageStyle(): ImageStyleStore {
|
|
26
|
+
const hybridViewerStore = useHybridViewerStore();
|
|
27
|
+
const viewerStore = useViewerStore();
|
|
28
|
+
const dataStyleState = useDataStyleState();
|
|
29
|
+
|
|
30
|
+
function imageVisibility(imageId: ImageId): Visibility | undefined {
|
|
31
|
+
return dataStyleState.getStyle(imageId).visibility;
|
|
32
|
+
}
|
|
33
|
+
async function setImageVisibility(imageId: ImageId, visibility: Visibility): Promise<unknown> {
|
|
34
|
+
const params = { id: imageId, visibility };
|
|
35
|
+
const result = await viewerStore.request(
|
|
36
|
+
{
|
|
37
|
+
schema: imageSchemas.visibility,
|
|
38
|
+
params,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
response_function: async () => {
|
|
42
|
+
hybridViewerStore.setVisibility(imageId, visibility);
|
|
43
|
+
const mutatedId = await dataStyleState.mutateStyle(imageId, { visibility });
|
|
44
|
+
return mutatedId;
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function imageOpacity(imageId: ImageId): Opacity | undefined {
|
|
52
|
+
// oxlint-disable-next-line no-unsafe-type-assertion -- opacity shape is defined by the data style schema.
|
|
53
|
+
return dataStyleState.getStyle(imageId).opacity as Opacity | undefined;
|
|
54
|
+
}
|
|
55
|
+
async function setImageOpacity(imageId: ImageId, opacity: Opacity): Promise<unknown> {
|
|
56
|
+
const params = { id: imageId, opacity };
|
|
57
|
+
const result = await viewerStore.request(
|
|
58
|
+
{
|
|
59
|
+
schema: imageSchemas.opacity,
|
|
60
|
+
params,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
response_function: async () => {
|
|
64
|
+
const mutatedId = await dataStyleState.mutateStyle(imageId, { opacity });
|
|
65
|
+
return mutatedId;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function applyImageStyle(imageId: ImageId): Promise<unknown[]> {
|
|
73
|
+
const style = dataStyleState.getStyle(imageId);
|
|
74
|
+
const promise_array: unknown[] = [];
|
|
75
|
+
for (const key of Object.keys(style)) {
|
|
76
|
+
if (key === "visibility") {
|
|
77
|
+
promise_array.push(
|
|
78
|
+
whenDefined(imageVisibility(imageId), async (visibility) => {
|
|
79
|
+
const applied = await setImageVisibility(imageId, visibility);
|
|
80
|
+
return applied;
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
} else if (key === "opacity") {
|
|
84
|
+
promise_array.push(
|
|
85
|
+
whenDefined(imageOpacity(imageId), async (opacity) => {
|
|
86
|
+
const applied = await setImageOpacity(imageId, opacity);
|
|
87
|
+
return applied;
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
} else if (key === "data_id") {
|
|
91
|
+
continue;
|
|
92
|
+
} else {
|
|
93
|
+
throw new Error(`Unknown image key: ${key}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const results = await Promise.all(promise_array);
|
|
97
|
+
return results;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
imageVisibility,
|
|
102
|
+
setImageVisibility,
|
|
103
|
+
imageOpacity,
|
|
104
|
+
setImageOpacity,
|
|
105
|
+
applyImageStyle,
|
|
106
|
+
};
|
|
107
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Third party imports
|
|
2
|
+
import type { Page } from "@playwright/test";
|
|
3
|
+
|
|
4
|
+
// Local imports
|
|
5
|
+
import { ensureMenuOpen, moveMouseOutOfTheWay } from "./viewer_interaction";
|
|
6
|
+
import { openDataContextMenu } from "./object_trees/main_object_tree";
|
|
7
|
+
import { waitForActionSettled } from "./wait_for_action_settled";
|
|
8
|
+
|
|
9
|
+
const IMAGE_MENU_TEST_ID = "imageMenu";
|
|
10
|
+
|
|
11
|
+
// Images are not pickable: their menu opens from the object tree
|
|
12
|
+
async function openImageMenu(
|
|
13
|
+
window: Page,
|
|
14
|
+
geodeObjectType: string,
|
|
15
|
+
dataName: string,
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
await openDataContextMenu(window, geodeObjectType, dataName);
|
|
18
|
+
await ensureMenuOpen(window, IMAGE_MENU_TEST_ID);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function setImageOpacity(window: Page, opacity: number): Promise<void> {
|
|
22
|
+
await ensureMenuOpen(window, IMAGE_MENU_TEST_ID);
|
|
23
|
+
const track = window.getByTestId("imageOpacitySlider").locator(".v-slider").first();
|
|
24
|
+
const box = await track.boundingBox();
|
|
25
|
+
if (!box) {
|
|
26
|
+
throw new Error("Could not get bounding box of the image opacity slider");
|
|
27
|
+
}
|
|
28
|
+
await track.click({ position: { x: box.width * opacity, y: box.height / 2 } });
|
|
29
|
+
await moveMouseOutOfTheWay(window);
|
|
30
|
+
await waitForActionSettled(window);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { IMAGE_MENU_TEST_ID, openImageMenu, setImageOpacity };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Local imports
|
|
2
|
+
import { IMAGE_MENU_TEST_ID, openImageMenu, setImageOpacity } from "#browser_helpers/image";
|
|
3
|
+
import type { SuiteRuntime } from "#browser_helpers/suite_runtime";
|
|
4
|
+
import { closeAllMenus } from "#browser_helpers/app_interaction";
|
|
5
|
+
import { expandMainObjectTree } from "#browser_helpers/object_trees/main_object_tree";
|
|
6
|
+
import { setVisibilityGeneric } from "#browser_helpers/viewer_interaction";
|
|
7
|
+
|
|
8
|
+
// Constants
|
|
9
|
+
const inputFilename = "test_texture.png";
|
|
10
|
+
const dataName = "test_texture";
|
|
11
|
+
const geodeObjectType = "RasterImage2D";
|
|
12
|
+
const halfOpacity = 0.5;
|
|
13
|
+
|
|
14
|
+
// Shared with the apps built on this layer: each one runs it with its own test fixture and data loader
|
|
15
|
+
function registerTests({ test, loadTestDatas }: SuiteRuntime): void {
|
|
16
|
+
test.describe.configure({ mode: "serial" });
|
|
17
|
+
|
|
18
|
+
test("load shows the image colors", async ({ window }) => {
|
|
19
|
+
await loadTestDatas(window, [inputFilename]);
|
|
20
|
+
await expandMainObjectTree(window);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("image menu", async ({ window }) => {
|
|
24
|
+
await openImageMenu(window, geodeObjectType, dataName);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("image opacity", async ({ window }) => {
|
|
28
|
+
await setImageOpacity(window, halfOpacity);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("image hidden", async ({ window }) => {
|
|
32
|
+
await setVisibilityGeneric(window, IMAGE_MENU_TEST_ID, "imageVisibilitySwitch", false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("close image menu", async ({ window }) => {
|
|
36
|
+
await closeAllMenus(window);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { registerTests };
|