From b80a10af4b55d67fd5d4403f3da26024f2470de7 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 14:30:24 +0100 Subject: [PATCH 01/11] fix(colormap): resolve implicit default colormap for geode_implicit_attribute on implicit models Add defaultAttributeColorMap so geode_implicit_attribute on ImplicitStructuralModel and ImplicitCrossSection defaults to the implicit preset instead of batlow (Geode-solutions/Vease#841). --- .../Viewer/Options/ColorMapPicker.vue | 8 +++- app/composables/attribute_coloring_style.ts | 3 +- app/utils/colormap.ts | 38 +++++++++++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/app/components/Viewer/Options/ColorMapPicker.vue b/app/components/Viewer/Options/ColorMapPicker.vue index b637a5415..57f590e41 100644 --- a/app/components/Viewer/Options/ColorMapPicker.vue +++ b/app/components/Viewer/Options/ColorMapPicker.vue @@ -3,7 +3,11 @@ import type { AttributeRangeMaximum, AttributeRangeMinimum, } from "@geode/opengeodeweb-viewer/schema_types"; -import { drawCanvasForPreset, getPresetsWithCurrentAtTop } from "@ogw_front/utils/colormap"; +import { + DEFAULT_COLORMAP, + drawCanvasForPreset, + getPresetsWithCurrentAtTop, +} from "@ogw_front/utils/colormap"; import type { AttributeColorMap } from "@ogw_front/types/attribute"; import ColorMapList from "./ColorMapList.vue"; import type { ColorMapPreset } from "@ogw_front/types/props/viewer/options"; @@ -16,7 +20,7 @@ interface Props { const { max, min } = defineProps(); const selectedPresetName = defineModel("selectedPresetName", { - default: "batlow", + default: DEFAULT_COLORMAP, }); const menuOpen = ref(false); diff --git a/app/composables/attribute_coloring_style.ts b/app/composables/attribute_coloring_style.ts index c710904e4..afbce7fe2 100644 --- a/app/composables/attribute_coloring_style.ts +++ b/app/composables/attribute_coloring_style.ts @@ -7,6 +7,7 @@ import type { } from "@ogw_front/types/attribute"; import { type AttributeInfo, getAttributeRange } from "@ogw_front/utils/attributes"; import { type AttributeSchemas, fetchAttributeRange } from "@ogw_front/utils/attribute_range"; +import { DEFAULT_COLORMAP } from "@ogw_front/utils/colormap"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import type { JsonRpcSchema } from "@ogw_shared/utils/types"; import type { ModelComponentId } from "@ogw_front/types/identifiers"; @@ -98,7 +99,7 @@ function useAttributeColoringStyle(colorings: Ref): Attribu const currentColormap = computed((): AttributeColorMap => { const [coloring] = colorings.value; if (!coloring) { - return "batlow"; + return DEFAULT_COLORMAP; } return String(coloring.read("ColorMap")); }); diff --git a/app/utils/colormap.ts b/app/utils/colormap.ts index a7c27758c..d86185c20 100644 --- a/app/utils/colormap.ts +++ b/app/utils/colormap.ts @@ -1,10 +1,33 @@ // oxlint-disable unicorn/prefer-export-from +import type { AttributeColorMap } from "@ogw_front/types/attribute"; +import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; import type { Pixels } from "@ogw_front/types/ui"; import colormaps from "@ogw_front/assets/colormaps.json"; - -import type { AttributeColorMap } from "@ogw_front/types/attribute"; import { newInstance as vtkColorTransferFunction } from "@kitware/vtk.js/Rendering/Core/ColorTransferFunction"; +const DEFAULT_COLORMAP: AttributeColorMap = "batlow"; +const IMPLICIT_COLORMAP: AttributeColorMap = "implicit"; +const IMPLICIT_ATTRIBUTE_NAME: AttributeName = "geode_implicit_attribute"; +const IMPLICIT_MODEL_TYPES: ReadonlySet = new Set([ + "ImplicitStructuralModel", + "ImplicitCrossSection", +]); + +function defaultAttributeColorMap( + geodeObjectType: GeodeObjectType | undefined, + attributeName: AttributeName | undefined, +): AttributeColorMap { + if ( + geodeObjectType !== undefined && + IMPLICIT_MODEL_TYPES.has(geodeObjectType) && + attributeName === IMPLICIT_ATTRIBUTE_NAME + ) { + return IMPLICIT_COLORMAP; + } + return DEFAULT_COLORMAP; +} + interface ColormapPreset { readonly Name: AttributeColorMap; readonly RGBPoints: readonly number[]; @@ -104,6 +127,15 @@ function drawCanvasForPreset( ctx.putImageData(imageData, 0, 0); } -export { drawCanvasForPreset, getRGBPointsFromPreset, getPresetByName, getPresetsWithCurrentAtTop }; +export { + DEFAULT_COLORMAP, + IMPLICIT_ATTRIBUTE_NAME, + IMPLICIT_COLORMAP, + defaultAttributeColorMap, + drawCanvasForPreset, + getPresetByName, + getPresetsWithCurrentAtTop, + getRGBPointsFromPreset, +}; export { default as colormaps } from "@ogw_front/assets/colormaps.json"; From 5385efac0529bb48be07c4e193f209a1f1513915 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 14:30:24 +0100 Subject: [PATCH 02/11] fix(AttributeSelector): use the attribute default colormap when none is stored Resolve the data geode_object_type and apply defaultAttributeColorMap for both single-target and group attribute selections while preserving any stored custom colormap. --- .../Viewer/Options/AttributeSelector.vue | 9 ++- app/composables/attribute_selector.ts | 80 +++++++++++++++++-- 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/app/components/Viewer/Options/AttributeSelector.vue b/app/components/Viewer/Options/AttributeSelector.vue index fd5adf95a..af4ec65ac 100644 --- a/app/components/Viewer/Options/AttributeSelector.vue +++ b/app/components/Viewer/Options/AttributeSelector.vue @@ -11,6 +11,7 @@ import { attributeItemOptions, attributeRangesPerTarget, attributeRequestParams, + useAttributeDefaultColorMap, useAttributeRangeBounds, useSeriesTimeStepCommit, } from "@ogw_front/composables/attribute_selector"; @@ -64,6 +65,7 @@ let rangesName: AttributeName | undefined = undefined; let rangesLoading: Promise = Promise.resolve(); const groupTargetIds = useBatchGroup(() => dataId); +const colorMaps = useAttributeDefaultColorMap(() => dataId, attributeName, attributeColorMap); const currentAttribute = computed(() => attributes.value.find((attr) => attr.attribute_name === attributeName.value), @@ -158,10 +160,11 @@ async function getGroupAttributes(targetIds: DataId[]): Promise { async function initGroupAttribute(name: AttributeName, item: AttributeItem): Promise { await loadRanges(name); + const colorMap = await colorMaps.resolveColorMap(name); if (attributeName.value !== name) { return; } - emit("update:attributeColorMap", attributeColorMap.value ?? "batlow"); + emit("update:attributeColorMap", colorMap); emit("ranges_per_data", attributeRangesPerTarget(rangesPerTarget.value, item)); } @@ -204,9 +207,7 @@ watch([attributeName, attributeItem, currentAttribute], async () => { if (groupTargetIds.value) { return; } - if (attributeColorMap.value === undefined) { - attributeColorMap.value = "batlow"; - } + await colorMaps.ensureColorMap(); if (attributeNoDataColor.value === undefined) { attributeNoDataColor.value = DEFAULT_NO_DATA_COLOR; } diff --git a/app/composables/attribute_selector.ts b/app/composables/attribute_selector.ts index 1693d41d8..c9d2a9fb2 100644 --- a/app/composables/attribute_selector.ts +++ b/app/composables/attribute_selector.ts @@ -1,20 +1,24 @@ +import type { + AttributeColorMap, + AttributeTimeStep, + AttributeTimeValue, + ValidAttributeRange, +} from "@ogw_front/types/attribute"; import type { AttributeItem, AttributeName, AttributeRangeMaximum, AttributeRangeMinimum, } from "@geode/opengeodeweb-viewer/schema_types"; -import type { - AttributeTimeStep, - AttributeTimeValue, - ValidAttributeRange, -} from "@ogw_front/types/attribute"; import type { Count, Title } from "@ogw_front/types/ui"; import type { AttributeRangeInfo } from "@ogw_front/utils/attribute_range"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; import type { ModelComponentId } from "@ogw_front/types/identifiers"; import type { NonEmptyArray } from "@ogw_front/utils/arrays"; +import { defaultAttributeColorMap } from "@ogw_front/utils/colormap"; import { getAttributeRange } from "@ogw_front/utils/attributes"; +import { useDataStore } from "@ogw_front/stores/data"; // The minimum and maximum of an attribute range: each one is clamped by the other function useAttributeRangeBounds(attributeRange: Ref<(number | undefined)[]>): { @@ -123,6 +127,70 @@ function attributeRequestParams( return { id: dataId, component_ids: componentIds }; } +// Resolves the default colormap of an attribute from its data's geode object type +function useDefaultAttributeColorMap( + dataId: () => DataId, +): (attributeName: AttributeName | undefined) => Promise { + const dataStore = useDataStore(); + let cachedId: DataId | undefined = undefined; + let cachedType: GeodeObjectType | undefined = undefined; + + async function resolveObjectType(): Promise { + const requestedId = dataId(); + if (cachedId === requestedId) { + return cachedType; + } + try { + const dataItem = await dataStore.item(requestedId); + if (requestedId === dataId()) { + cachedType = dataItem.geode_object_type; + cachedId = requestedId; + } + return dataItem.geode_object_type; + } catch { + return undefined; + } + } + + return async (attributeName) => { + const objectType = await resolveObjectType(); + return defaultAttributeColorMap(objectType, attributeName); + }; +} + +// Resolves and fills the default colormap of the selected attribute when none is stored yet +function useAttributeDefaultColorMap( + dataId: () => DataId, + attributeName: Readonly>, + attributeColorMap: Ref, +): { + resolveColorMap: (name: AttributeName) => Promise; + ensureColorMap: () => Promise; +} { + const defaultColorMapFor = useDefaultAttributeColorMap(dataId); + + async function resolveColorMap(name: AttributeName): Promise { + if (attributeColorMap.value !== undefined) { + return attributeColorMap.value; + } + const colorMap = await defaultColorMapFor(name); + return colorMap; + } + + async function ensureColorMap(): Promise { + const selectedName = attributeName.value; + if (attributeColorMap.value !== undefined || selectedName === undefined) { + return; + } + const defaultColorMap = await defaultColorMapFor(selectedName); + if (attributeName.value === selectedName && attributeColorMap.value === undefined) { + attributeColorMap.value = defaultColorMap; + } + } + + return { resolveColorMap, ensureColorMap }; +} + export type { AttributeInfo } from "@ogw_front/utils/attributes"; export { type AttributeItemOption, @@ -130,6 +198,8 @@ export { attributeItemOptions, attributeRequestParams, attributeRangesPerTarget, + useAttributeDefaultColorMap, useAttributeRangeBounds, + useDefaultAttributeColorMap, useSeriesTimeStepCommit, }; From eb2ec017191da38771b3590e2a4d1e05d6dc8f34 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 14:30:24 +0100 Subject: [PATCH 03/11] fix(physical_properties): use the attribute default colormap when coloring model properties --- app/composables/physical_property_coloring.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/composables/physical_property_coloring.ts b/app/composables/physical_property_coloring.ts index 978befdb5..7b3fd37f4 100644 --- a/app/composables/physical_property_coloring.ts +++ b/app/composables/physical_property_coloring.ts @@ -1,4 +1,3 @@ -import type { AttributeColorMap, ColoringType } from "@ogw_front/types/attribute"; import type { ComponentType, ElementType, @@ -6,13 +5,13 @@ import type { import type { ModelComponentId, ModelId } from "@ogw_front/types/identifiers"; import { type NonEmptyArray, isNonEmpty } from "@ogw_front/utils/arrays"; import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; +import type { ColoringType } from "@ogw_front/types/attribute"; import type { PhysicalPropertyNode } from "@ogw_front/utils/physical_properties_tree"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; +import { useDefaultAttributeColorMap } from "@ogw_front/composables/attribute_selector"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; -// The colormap the attribute selector starts with -const DEFAULT_COLOR_MAP: AttributeColorMap = "batlow"; // The coloring a component goes back to when the property coloring is removed const CONSTANT_COLORING: ColoringType = "constant"; @@ -104,6 +103,7 @@ export function usePhysicalPropertyColoring(modelId: ModelId): { } { const dataStyleStore = useDataStyleStore(); const hybridViewerStore = useHybridViewerStore(); + const defaultColorMapFor = useDefaultAttributeColorMap(() => modelId); function nodeMethods(node: PhysicalPropertyNode): ColoringMethods | undefined { return coloringMethods(dataStyleStore, node.component_type, node.element_type); @@ -132,12 +132,13 @@ export function usePhysicalPropertyColoring(modelId: ModelId): { await methods.setActiveColoring(modelId, componentIds, CONSTANT_COLORING); } else if (node.coloring !== undefined) { const { item, minimum, maximum } = node.coloring; + const colorMap = await defaultColorMapFor(node.attribute_name); await methods.setAttribute(modelId, componentIds, { name: node.attribute_name, item, minimum, maximum, - colorMap: DEFAULT_COLOR_MAP, + colorMap, }); await methods.setActiveColoring(modelId, componentIds, node.element_type); } From a40db466259599cc9a0bb26375bc8d0ab13287f0 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 14:30:24 +0100 Subject: [PATCH 04/11] test(colormap): cover implicit default colormap across helper, AttributeSelector, and physical properties --- .../AttributeSelectorColormap.nuxt.test.ts | 143 ++++++++++++++++++ .../physical_property_coloring.nuxt.test.ts | 33 ++++ tests/unit/utils/colormap.nuxt.test.ts | 51 +++++++ 3 files changed, 227 insertions(+) create mode 100644 tests/unit/components/AttributeSelectorColormap.nuxt.test.ts create mode 100644 tests/unit/utils/colormap.nuxt.test.ts diff --git a/tests/unit/components/AttributeSelectorColormap.nuxt.test.ts b/tests/unit/components/AttributeSelectorColormap.nuxt.test.ts new file mode 100644 index 000000000..cb65edf7c --- /dev/null +++ b/tests/unit/components/AttributeSelectorColormap.nuxt.test.ts @@ -0,0 +1,143 @@ +// Third party imports +import type { AttributeColorMap, AttributeRange } from "@ogw_front/types/attribute"; +import { type VueWrapper, flushPromises } from "@vue/test-utils"; +import { beforeEach, describe, expect, test, vi } from "vitest"; +import { mountSuspended } from "@nuxt/test-utils/runtime"; + +// Local imports +import AttributeSelector from "@ogw_front/components/Viewer/Options/AttributeSelector.vue"; +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; +import { vuetify } from "@ogw_tests/utils"; + +const ATTRIBUTE_RANGE: AttributeRange = [0, 1]; +const MODEL_VERTEX_SCHEMAS = { + names: back_schemas.opengeodeweb_back.model_component_vertex_attribute_names, + range: back_schemas.opengeodeweb_back.model_component_vertex_attribute_range, +}; +const ATTRIBUTES = [ + { + attribute_name: "geode_implicit_attribute", + attribute_id: "geode_implicit_attribute", + nb_items: 1, + time_steps: [], + }, + { + attribute_name: "depth", + attribute_id: "depth", + nb_items: 1, + time_steps: [], + }, +]; + +type BackRequest = ( + request: { schema: { $id: string } }, + options?: { response_function: (response: unknown) => void }, +) => unknown; + +const objectTypesById = new Map(); +const groupTargets = ref(undefined); + +vi.mock(import("@ogw_front/stores/back") as Promise, () => ({ + useBackStore: (): { request: unknown } => ({ + request: vi.fn().mockImplementation(({ schema }, options) => { + if (schema.$id.endsWith("attribute_range")) { + return { min_values: [0], max_values: [1], no_data: false }; + } + const response = { attributes: ATTRIBUTES }; + options?.response_function(response); + return response; + }), + }), +})); + +vi.mock(import("@ogw_front/stores/data") as Promise, () => ({ + useDataStore: (): { item: (id: DataId) => Promise<{ geode_object_type: GeodeObjectType }> } => ({ + item: async (id: DataId): Promise<{ geode_object_type: GeodeObjectType }> => { + await Promise.resolve(); + const geodeObjectType = objectTypesById.get(id); + if (geodeObjectType === undefined) { + throw new Error(`Item not found: ${id}`); + } + return { geode_object_type: geodeObjectType }; + }, + }), +})); + +vi.mock(import("@ogw_front/composables/batch_style") as Promise, () => ({ + useBatchGroup: (): Ref => groupTargets, +})); + +async function mountSelector( + dataId: DataId, + attributeName?: string, + attributeColorMap?: AttributeColorMap, +): Promise { + const wrapper = await mountSuspended(AttributeSelector, { + global: { plugins: [vuetify] }, + props: { + dataId, + componentIds: ["surface-1"], + schemas: MODEL_VERTEX_SCHEMAS, + attributeName, + attributeItem: 0, + attributeRange: ATTRIBUTE_RANGE, + attributeColorMap, + }, + }); + await flushPromises(); + return wrapper; +} + +describe("attributeSelector default colormap", () => { + beforeEach(() => { + objectTypesById.clear(); + groupTargets.value = undefined; + }); + + test.each(["ImplicitStructuralModel", "ImplicitCrossSection"])( + "defaults to the implicit colormap for geode_implicit_attribute on %s", + async (geodeObjectType) => { + objectTypesById.set("model-1", geodeObjectType); + const wrapper = await mountSelector("model-1", "geode_implicit_attribute"); + + expect(wrapper.emitted("update:attributeColorMap")?.at(-1)).toStrictEqual(["implicit"]); + }, + ); + + test("defaults to batlow for other attributes on an implicit model", async () => { + objectTypesById.set("model-1", "ImplicitStructuralModel"); + const wrapper = await mountSelector("model-1", "depth"); + + expect(wrapper.emitted("update:attributeColorMap")?.at(-1)).toStrictEqual(["batlow"]); + }); + + test.each(["StructuralModel", "CrossSection", "BRep"])( + "defaults to batlow for geode_implicit_attribute on %s", + async (geodeObjectType) => { + objectTypesById.set("model-1", geodeObjectType); + const wrapper = await mountSelector("model-1", "geode_implicit_attribute"); + + expect(wrapper.emitted("update:attributeColorMap")?.at(-1)).toStrictEqual(["batlow"]); + }, + ); + + test("keeps a custom colormap already stored for geode_implicit_attribute", async () => { + objectTypesById.set("model-1", "ImplicitStructuralModel"); + const wrapper = await mountSelector("model-1", "geode_implicit_attribute", "berlin"); + + expect(wrapper.emitted("update:attributeColorMap")).toBeUndefined(); + }); + + test("defaults to the implicit colormap for a group of implicit models", async () => { + objectTypesById.set("model-1", "ImplicitCrossSection"); + groupTargets.value = ["model-1", "model-2"]; + const wrapper = await mountSelector("model-1"); + + await wrapper.setProps({ attributeName: "geode_implicit_attribute" }); + await flushPromises(); + + expect(wrapper.emitted("update:attributeColorMap")?.at(-1)).toStrictEqual(["implicit"]); + }); +}); diff --git a/tests/unit/composables/physical_property_coloring.nuxt.test.ts b/tests/unit/composables/physical_property_coloring.nuxt.test.ts index 00c47a65f..95e0eeaef 100644 --- a/tests/unit/composables/physical_property_coloring.nuxt.test.ts +++ b/tests/unit/composables/physical_property_coloring.nuxt.test.ts @@ -3,6 +3,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest"; // Local imports +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; import type { PhysicalPropertyNode } from "@ogw_front/utils/physical_properties_tree"; import { usePhysicalPropertyColoring } from "@ogw_front/composables/physical_property_coloring"; @@ -10,10 +11,19 @@ const MODEL_ID = "model"; const BLOCK_IDS = ["block-1", "block-2"]; const style = { activeColoring: "constant", attributeName: "" }; +let modelObjectType: GeodeObjectType = "BRep"; const setAttribute = vi.fn<(modelId: string, ids: string[], input: unknown) => Promise>(); const setActiveColoring = vi.fn<(modelId: string, ids: string[], coloring: string) => void>(); const remoteRender = vi.fn<() => undefined>(); +vi.mock(import("@ogw_front/stores/data") as Promise, () => ({ + useDataStore: (): Record => ({ + item: async (): Promise<{ geode_object_type: GeodeObjectType }> => { + await Promise.resolve(); + return { geode_object_type: modelObjectType }; + }, + }), +})); vi.mock(import("@ogw_front/stores/data_style") as Promise, () => ({ useDataStyleStore: (): Record => ({ modelBlockActiveColoring: (): string => style.activeColoring, @@ -50,6 +60,7 @@ describe("physical property coloring", () => { beforeEach(() => { style.activeColoring = "constant"; style.attributeName = ""; + modelObjectType = "BRep"; vi.clearAllMocks(); }); @@ -91,4 +102,26 @@ describe("physical property coloring", () => { expect(isColoredBy(POROSITY_NODE)).toBe(false); }); + + test.each(["ImplicitStructuralModel", "ImplicitCrossSection"])( + "uses the implicit colormap for geode_implicit_attribute on %s", + async (geodeObjectType) => { + modelObjectType = geodeObjectType; + const implicitNode: PhysicalPropertyNode = { + ...POROSITY_NODE, + attribute_name: "geode_implicit_attribute", + }; + const { toggleColoring } = usePhysicalPropertyColoring(MODEL_ID); + + await toggleColoring(implicitNode); + + expect(setAttribute).toHaveBeenCalledWith(MODEL_ID, BLOCK_IDS, { + name: "geode_implicit_attribute", + item: 0, + minimum: 0.05, + maximum: 0.3, + colorMap: "implicit", + }); + }, + ); }); diff --git a/tests/unit/utils/colormap.nuxt.test.ts b/tests/unit/utils/colormap.nuxt.test.ts new file mode 100644 index 000000000..5e1706fb8 --- /dev/null +++ b/tests/unit/utils/colormap.nuxt.test.ts @@ -0,0 +1,51 @@ +// Third party imports +import { describe, expect, test } from "vitest"; + +// Local imports +import { + DEFAULT_COLORMAP, + IMPLICIT_ATTRIBUTE_NAME, + IMPLICIT_COLORMAP, + defaultAttributeColorMap, + getPresetByName, +} from "@ogw_front/utils/colormap"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; + +describe("default attribute colormap", () => { + test("provides the implicit colormap preset", () => { + const preset = getPresetByName(IMPLICIT_COLORMAP); + + expect(preset).toBeDefined(); + expect(preset?.RGBPoints.length).toBeGreaterThan(0); + }); + + test.each(["ImplicitStructuralModel", "ImplicitCrossSection"])( + "returns the implicit colormap for geode_implicit_attribute on %s", + (geodeObjectType) => { + expect(defaultAttributeColorMap(geodeObjectType, IMPLICIT_ATTRIBUTE_NAME)).toBe( + IMPLICIT_COLORMAP, + ); + }, + ); + + test.each(["ImplicitStructuralModel", "ImplicitCrossSection"])( + "returns the default colormap for other attributes on %s", + (geodeObjectType) => { + expect(defaultAttributeColorMap(geodeObjectType, "depth")).toBe(DEFAULT_COLORMAP); + expect(defaultAttributeColorMap(geodeObjectType, undefined)).toBe(DEFAULT_COLORMAP); + }, + ); + + test.each([ + "StructuralModel", + "CrossSection", + "BRep", + "Section", + "TriangulatedSurface3D", + undefined, + ])("returns the default colormap for geode_implicit_attribute on %s", (geodeObjectType) => { + expect(defaultAttributeColorMap(geodeObjectType, IMPLICIT_ATTRIBUTE_NAME)).toBe( + DEFAULT_COLORMAP, + ); + }); +}); From 933db727ad40e6fc361ba11a18e300d577d11285 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 15:35:22 +0100 Subject: [PATCH 05/11] fix(colormap): add isImplicitModelType helper --- app/utils/colormap.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/utils/colormap.ts b/app/utils/colormap.ts index d86185c20..640874cfa 100644 --- a/app/utils/colormap.ts +++ b/app/utils/colormap.ts @@ -14,15 +14,15 @@ const IMPLICIT_MODEL_TYPES: ReadonlySet = new Set([ "ImplicitCrossSection", ]); +function isImplicitModelType(geodeObjectType: GeodeObjectType | undefined): boolean { + return geodeObjectType !== undefined && IMPLICIT_MODEL_TYPES.has(geodeObjectType); +} + function defaultAttributeColorMap( geodeObjectType: GeodeObjectType | undefined, attributeName: AttributeName | undefined, ): AttributeColorMap { - if ( - geodeObjectType !== undefined && - IMPLICIT_MODEL_TYPES.has(geodeObjectType) && - attributeName === IMPLICIT_ATTRIBUTE_NAME - ) { + if (isImplicitModelType(geodeObjectType) && attributeName === IMPLICIT_ATTRIBUTE_NAME) { return IMPLICIT_COLORMAP; } return DEFAULT_COLORMAP; @@ -136,6 +136,7 @@ export { getPresetByName, getPresetsWithCurrentAtTop, getRGBPointsFromPreset, + isImplicitModelType, }; export { default as colormaps } from "@ogw_front/assets/colormaps.json"; From d50f3166907ec5a8fe125fc34b4c1a0e7952b853 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 15:35:22 +0100 Subject: [PATCH 06/11] fix(data_style): activate geode_implicit_attribute with implicit colormap on implicit models --- internal/stores/data_style/model/implicit.ts | 143 +++++++++++++++++++ internal/stores/data_style/model/index.ts | 8 +- 2 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 internal/stores/data_style/model/implicit.ts diff --git a/internal/stores/data_style/model/implicit.ts b/internal/stores/data_style/model/implicit.ts new file mode 100644 index 000000000..22060b8e0 --- /dev/null +++ b/internal/stores/data_style/model/implicit.ts @@ -0,0 +1,143 @@ +import { + IMPLICIT_ATTRIBUTE_NAME, + IMPLICIT_COLORMAP, + isImplicitModelType, +} from "@ogw_front/utils/colormap"; +import type { ModelComponentId, ModelId } from "@ogw_front/types/identifiers"; +import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import type { StyleValues } from "@ogw_internal/stores/data_style/types"; +import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; +import { consola } from "consola"; +import { fetchAttributeRange } from "@ogw_front/utils/attribute_range"; +import { getAttributeRange } from "@ogw_front/utils/attributes"; +import { useBackStore } from "@ogw_front/stores/back"; +import { useDataStore } from "@ogw_front/stores/data"; +import type { useModelBlocksStyle } from "./blocks"; +import type { useModelSurfacesStyle } from "./surfaces"; + +interface ImplicitComponentTarget { + getIds: (modelId: ModelId) => Promise; + mutateTypeColoring: (modelId: ModelId, values: StyleValues) => Promise; + mutateColoring: ( + modelId: ModelId, + componentIds: ModelComponentId[], + values: StyleValues, + ) => Promise; +} + +function buildImplicitColoring(minimum: number, maximum: number): StyleValues { + return { + active: "vertex", + vertex: { + name: IMPLICIT_ATTRIBUTE_NAME, + item: 0, + storedConfigs: { + [IMPLICIT_ATTRIBUTE_NAME]: { + lastItem: 0, + 0: { + minimum, + maximum, + colorMap: IMPLICIT_COLORMAP, + no_data_color: DEFAULT_NO_DATA_COLOR, + }, + }, + }, + }, + }; +} + +function candidateTargetsFor( + geodeObjectType: GeodeObjectType, + modelBlocksStyle: ReturnType, + modelSurfacesStyle: ReturnType, +): ImplicitComponentTarget[] { + const dataStore = useDataStore(); + const blockTarget: ImplicitComponentTarget = { + getIds: dataStore.getBlocksGeodeIds, + mutateTypeColoring: modelBlocksStyle.mutateModelBlocksTypeColoring, + mutateColoring: modelBlocksStyle.mutateModelBlocksColoring, + }; + const surfaceTarget: ImplicitComponentTarget = { + getIds: dataStore.getSurfacesGeodeIds, + mutateTypeColoring: modelSurfacesStyle.mutateModelSurfacesTypeColoring, + mutateColoring: modelSurfacesStyle.mutateModelSurfacesColoring, + }; + if (geodeObjectType === "ImplicitStructuralModel") { + return [blockTarget, surfaceTarget]; + } + return [surfaceTarget]; +} + +async function hasImplicitAttribute( + backStore: ReturnType, + namesSchema: (typeof back_schemas.opengeodeweb_back)["model_component_vertex_attribute_names"], + modelId: ModelId, + componentIds: ModelComponentId[], +): Promise { + const { attributes } = await backStore.request({ + schema: namesSchema, + params: { id: modelId, component_ids: componentIds }, + }); + return attributes.some((attribute) => attribute.attribute_name === IMPLICIT_ATTRIBUTE_NAME); +} + +async function applyImplicitTarget( + backStore: ReturnType, + modelId: ModelId, + target: ImplicitComponentTarget, +): Promise { + const backSchemas = back_schemas.opengeodeweb_back; + const componentIds = await target.getIds(modelId); + if (componentIds.length === 0) { + return false; + } + const hasAttribute = await hasImplicitAttribute( + backStore, + backSchemas.model_component_vertex_attribute_names, + modelId, + componentIds, + ); + if (!hasAttribute) { + return false; + } + const rangeInfo = await fetchAttributeRange( + backSchemas.model_component_vertex_attribute_range, + { id: modelId, component_ids: componentIds }, + IMPLICIT_ATTRIBUTE_NAME, + ); + const { min, max } = getAttributeRange(rangeInfo, 0); + const coloring = buildImplicitColoring(min, max); + await Promise.all([ + target.mutateTypeColoring(modelId, coloring), + target.mutateColoring(modelId, componentIds, coloring), + ]); + return true; +} + +// Activates geode_implicit_attribute with the implicit colormap on the implicit model's components +function useImplicitModelDefaultStyle( + modelBlocksStyle: ReturnType, + modelSurfacesStyle: ReturnType, +): (modelId: ModelId, geodeObjectType: GeodeObjectType) => Promise { + const backStore = useBackStore(); + + return async (modelId: ModelId, geodeObjectType: GeodeObjectType): Promise => { + if (!isImplicitModelType(geodeObjectType)) { + return; + } + try { + const targets = candidateTargetsFor(geodeObjectType, modelBlocksStyle, modelSurfacesStyle); + for (const target of targets) { + // oxlint-disable-next-line no-await-in-loop -- stop at the primary component type carrying the implicit attribute. + if (await applyImplicitTarget(backStore, modelId, target)) { + return; + } + } + } catch (error) { + consola.warn(`Unable to activate implicit attribute style on model ${modelId}:`, error); + } + }; +} + +export { useImplicitModelDefaultStyle }; diff --git a/internal/stores/data_style/model/index.ts b/internal/stores/data_style/model/index.ts index 10153f9ab..c7eb1c4be 100644 --- a/internal/stores/data_style/model/index.ts +++ b/internal/stores/data_style/model/index.ts @@ -2,6 +2,7 @@ import type { ModelId, TreeNodeId } from "@ogw_front/types/identifiers"; import type { ComputedRef } from "vue"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; +import { useImplicitModelDefaultStyle } from "./implicit"; import { useModelBlocksStyle } from "./blocks"; import { useModelColorStyle } from "./color"; import { useModelCornersStyle } from "./corners"; @@ -35,6 +36,10 @@ function useModelStyle(): UseModelStyleReturn { const modelLinesStyle = useModelLinesStyle(); const modelPointsStyle = useModelPointsStyle(); const modelSurfacesStyle = useModelSurfacesStyle(); + const applyImplicitDefaultStyle = useImplicitModelDefaultStyle( + modelBlocksStyle, + modelSurfacesStyle, + ); const componentStyleFunctions = { Corner: modelCornersStyle, @@ -74,7 +79,8 @@ function useModelStyle(): UseModelStyleReturn { } async function setModelMeshComponentsDefaultStyle(modelId: ModelId): Promise { - await dataStore.item(modelId); + const item = await dataStore.item(modelId); + await applyImplicitDefaultStyle(modelId, item.geode_object_type); const results = await Promise.all([ modelBlocksStyle.setModelBlocksDefaultStyle(modelId), modelSurfacesStyle.setModelSurfacesDefaultStyle(modelId), From 66b44b5069d09160ea1a9a5c04372f1f84c98873 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 15:35:22 +0100 Subject: [PATCH 07/11] fix(import): apply implicit model default attribute coloring on import --- app/utils/import_item.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/utils/import_item.ts b/app/utils/import_item.ts index 53487c5b7..01edeca68 100644 --- a/app/utils/import_item.ts +++ b/app/utils/import_item.ts @@ -2,6 +2,7 @@ import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; import { type NewDataItem, useDataStore } from "@ogw_front/stores/data"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import { isImplicitModelType } from "@ogw_front/utils/colormap"; import { isModel } from "@ogw_front/utils/viewer_object_type"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useFeedbackStore } from "@ogw_front/stores/feedback"; @@ -35,6 +36,9 @@ async function applyStyleWhenReady(item: NewDataItem, ready: Promise): if (!(await useDataStore().fetchIsViewable(item.data_id))) { return undefined; } + if (isImplicitModelType(item.geode_object_type)) { + await useDataStyleStore().setModelMeshComponentsDefaultStyle(item.data_id); + } return useDataStyleStore().applyDefaultStyle(item.data_id); } From 1258dc5f1ed3ee5645d6cb7e4c6517148fa6aac8 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 2 Dec 2026 15:35:22 +0100 Subject: [PATCH 08/11] test(data_style): verify automatic implicit attribute activation on implicit models --- .../data_style_implicit_model.nuxt.test.ts | 214 ++++++++++++++++++ tests/unit/utils/colormap.nuxt.test.ts | 9 + 2 files changed, 223 insertions(+) create mode 100644 tests/unit/stores/data_style_implicit_model.nuxt.test.ts diff --git a/tests/unit/stores/data_style_implicit_model.nuxt.test.ts b/tests/unit/stores/data_style_implicit_model.nuxt.test.ts new file mode 100644 index 000000000..2a8b9cd1f --- /dev/null +++ b/tests/unit/stores/data_style_implicit_model.nuxt.test.ts @@ -0,0 +1,214 @@ +// Third party imports +import { type Mock, beforeEach, describe, expect, test, vi } from "vitest"; +import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import { IMPLICIT_ATTRIBUTE_NAME, getRGBPointsFromPreset } from "@ogw_front/utils/colormap"; +import { mockAs, setupActivePinia } from "@ogw_tests/utils"; +import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import { importItem } from "@ogw_front/utils/import_item"; +import { useBackStore } from "@ogw_front/stores/back"; +import { useDataStore } from "@ogw_front/stores/data"; +import { useDataStyleStore } from "@ogw_front/stores/data_style"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useViewerStore } from "@ogw_front/stores/viewer"; + +vi.setConfig({ testTimeout: 10_000 }); + +const MODEL_GEODE_ID = "00000000-0000-0000-0000-000000000001"; +const BLOCK_ID = "00000000-0000-0000-0000-000000000010"; +const SURFACE_ID = "00000000-0000-0000-0000-000000000020"; +const BLOCK_VIEWER_ID = 2; +const SURFACE_VIEWER_ID = 1; +const IMPLICIT_MIN = -11.5; +const IMPLICIT_MAX = 6.75; +const backSchemas = back_schemas.opengeodeweb_back; +const viewerSchemas = viewer_schemas.opengeodeweb_viewer; + +function modelItemPayload( + dataId: string, + geodeObjectType: GeodeObjectType, + withBlocks: boolean, +): Parameters[0] { + const meshComponents = [ + { + geode_id: SURFACE_ID, + name: "Surface 0", + type: "Surface", + viewer_id: SURFACE_VIEWER_ID, + is_active: true, + }, + ]; + if (withBlocks) { + meshComponents.push({ + geode_id: BLOCK_ID, + name: "Block 0", + type: "Block", + viewer_id: BLOCK_VIEWER_ID, + is_active: true, + }); + } + return { + id: dataId, + geode_id: MODEL_GEODE_ID, + name: dataId, + viewer_object_type: "model", + geode_object_type: geodeObjectType, + is_viewable: true, + mesh_components: meshComponents, + collection_components: [], + }; +} + +type BackRequestFn = (args: { + schema: { $id: string }; + params?: { component_ids?: string[] }; +}) => unknown; +type ViewerRequestFn = (args: unknown) => Promise; + +function resolveNothing(): Mock<() => Promise> { + return vi.fn<() => Promise>().mockResolvedValue(undefined); +} + +function setupBackAndViewerMocks(attributesByComponentId: Record): { + backRequest: Mock; + viewerRequest: Mock; +} { + const backStore = useBackStore(); + const dataStore = useDataStore(); + const hybridViewerStore = useHybridViewerStore(); + const viewerStore = useViewerStore(); + + const backRequest = vi.fn(({ schema, params }) => { + if (schema.$id === backSchemas.model_component_vertex_attribute_names.$id) { + const componentId = params?.component_ids?.[0] ?? ""; + const names = attributesByComponentId[componentId] ?? []; + return { + attributes: names.map((attribute_name) => ({ + attribute_name, + attribute_id: attribute_name, + nb_items: 1, + time_steps: [], + })), + }; + } + if (schema.$id === backSchemas.model_component_vertex_attribute_range.$id) { + return { min_values: [IMPLICIT_MIN], max_values: [IMPLICIT_MAX], no_data: false }; + } + return {}; + }); + const viewerRequest = vi.fn().mockResolvedValue({}); + + backStore.request = mockAs(backRequest); + viewerStore.request = mockAs(viewerRequest); + dataStore.registerObject = mockAs(resolveNothing()); + dataStore.addComponentRelations = + mockAs(resolveNothing()); + dataStore.addPhysicalProperties = + mockAs(resolveNothing()); + hybridViewerStore.addItem = mockAs(resolveNothing()); + + return { backRequest, viewerRequest }; +} + +describe("implicit model default attribute style on import", () => { + setupActivePinia(); + + beforeEach(async () => { + await useDataStore().clear(); + await useDataStyleStore().clear(); + }); + + test("activates geode_implicit_attribute with implicit colormap on ImplicitStructuralModel blocks", async () => { + const modelId = "implicit-structural-model"; + const { viewerRequest } = setupBackAndViewerMocks({ [BLOCK_ID]: [IMPLICIT_ATTRIBUTE_NAME] }); + const dataStyleStore = useDataStyleStore(); + + await importItem(modelItemPayload(modelId, "ImplicitStructuralModel", true)); + + expect(dataStyleStore.modelBlockActiveColoring(modelId, BLOCK_ID)).toBe("vertex"); + expect(dataStyleStore.modelBlocksVertexAttributeName(modelId, BLOCK_ID)).toBe( + IMPLICIT_ATTRIBUTE_NAME, + ); + expect(dataStyleStore.modelBlocksVertexAttributeColorMap(modelId, BLOCK_ID)).toBe("implicit"); + expect(dataStyleStore.modelBlocksVertexAttributeRange(modelId, BLOCK_ID)).toStrictEqual([ + IMPLICIT_MIN, + IMPLICIT_MAX, + ]); + // oxlint-disable-next-line vitest/max-expects -- verifying surface coloring and viewer payload alongside block style. + expect(dataStyleStore.modelSurfaceActiveColoring(modelId, SURFACE_ID)).toBe("constant"); + // oxlint-disable-next-line vitest/max-expects -- verifying surface coloring and viewer payload alongside block style. + expect(viewerRequest).toHaveBeenCalledWith({ + schema: viewerSchemas.model.blocks.attribute.vertex.attribute, + params: { + id: modelId, + block_ids: [BLOCK_VIEWER_ID], + name: IMPLICIT_ATTRIBUTE_NAME, + item: 0, + points: [...getRGBPointsFromPreset("implicit")], + minimum: IMPLICIT_MIN, + maximum: IMPLICIT_MAX, + no_data_color: DEFAULT_NO_DATA_COLOR, + }, + }); + }); + + test("activates geode_implicit_attribute with implicit colormap on ImplicitCrossSection surfaces", async () => { + const modelId = "implicit-cross-section"; + const { viewerRequest } = setupBackAndViewerMocks({ + [SURFACE_ID]: [IMPLICIT_ATTRIBUTE_NAME], + }); + const dataStyleStore = useDataStyleStore(); + + await importItem(modelItemPayload(modelId, "ImplicitCrossSection", false)); + + expect(dataStyleStore.modelSurfaceActiveColoring(modelId, SURFACE_ID)).toBe("vertex"); + expect(dataStyleStore.modelSurfacesVertexAttributeName(modelId, SURFACE_ID)).toBe( + IMPLICIT_ATTRIBUTE_NAME, + ); + expect(dataStyleStore.modelSurfacesVertexAttributeColorMap(modelId, SURFACE_ID)).toBe( + "implicit", + ); + expect(dataStyleStore.modelSurfacesVertexAttributeRange(modelId, SURFACE_ID)).toStrictEqual([ + IMPLICIT_MIN, + IMPLICIT_MAX, + ]); + expect(viewerRequest).toHaveBeenCalledWith({ + schema: viewerSchemas.model.surfaces.attribute.vertex.attribute, + params: { + id: modelId, + block_ids: [SURFACE_VIEWER_ID], + name: IMPLICIT_ATTRIBUTE_NAME, + item: 0, + points: [...getRGBPointsFromPreset("implicit")], + minimum: IMPLICIT_MIN, + maximum: IMPLICIT_MAX, + no_data_color: DEFAULT_NO_DATA_COLOR, + }, + }); + }); + + test("keeps constant coloring when an implicit model has no geode_implicit_attribute", async () => { + const modelId = "implicit-without-attribute"; + setupBackAndViewerMocks({ [SURFACE_ID]: ["unique vertices"] }); + const dataStyleStore = useDataStyleStore(); + + await importItem(modelItemPayload(modelId, "ImplicitCrossSection", false)); + + expect(dataStyleStore.modelSurfaceActiveColoring(modelId, SURFACE_ID)).toBe("constant"); + expect(dataStyleStore.modelSurfacesVertexAttributeName(modelId, SURFACE_ID)).toBeUndefined(); + }); + + test("keeps constant coloring on non-implicit models even if they carry geode_implicit_attribute", async () => { + const modelId = "explicit-brep"; + const { backRequest } = setupBackAndViewerMocks({ [BLOCK_ID]: [IMPLICIT_ATTRIBUTE_NAME] }); + const dataStyleStore = useDataStyleStore(); + + await importItem(modelItemPayload(modelId, "BRep", true)); + + expect(dataStyleStore.modelBlockActiveColoring(modelId, BLOCK_ID)).toBe("constant"); + expect(backRequest).not.toHaveBeenCalled(); + }); +}); diff --git a/tests/unit/utils/colormap.nuxt.test.ts b/tests/unit/utils/colormap.nuxt.test.ts index 5e1706fb8..23def8724 100644 --- a/tests/unit/utils/colormap.nuxt.test.ts +++ b/tests/unit/utils/colormap.nuxt.test.ts @@ -8,6 +8,7 @@ import { IMPLICIT_COLORMAP, defaultAttributeColorMap, getPresetByName, + isImplicitModelType, } from "@ogw_front/utils/colormap"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; @@ -48,4 +49,12 @@ describe("default attribute colormap", () => { DEFAULT_COLORMAP, ); }); + + test("identifies implicit model types only", () => { + expect(isImplicitModelType("ImplicitStructuralModel")).toBe(true); + expect(isImplicitModelType("ImplicitCrossSection")).toBe(true); + expect(isImplicitModelType("StructuralModel")).toBe(false); + expect(isImplicitModelType("CrossSection")).toBe(false); + expect(isImplicitModelType(undefined)).toBe(false); + }); }); From bb90cefa6d149cb3db704d8aa600f62758bf8abc Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Thu, 3 Dec 2026 10:31:45 +0100 Subject: [PATCH 09/11] fix(colormap): rename the colormap resolver composables useDefaultAttributeColorMap and useAttributeDefaultColorMap had nearly the same name: they become useColorMapResolver and useSelectedAttributeColorMap. --- app/components/Viewer/Options/AttributeSelector.vue | 4 ++-- app/composables/attribute_selector.ts | 10 +++++----- app/composables/physical_property_coloring.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/components/Viewer/Options/AttributeSelector.vue b/app/components/Viewer/Options/AttributeSelector.vue index af4ec65ac..fbdb74730 100644 --- a/app/components/Viewer/Options/AttributeSelector.vue +++ b/app/components/Viewer/Options/AttributeSelector.vue @@ -11,8 +11,8 @@ import { attributeItemOptions, attributeRangesPerTarget, attributeRequestParams, - useAttributeDefaultColorMap, useAttributeRangeBounds, + useSelectedAttributeColorMap, useSeriesTimeStepCommit, } from "@ogw_front/composables/attribute_selector"; import type { AttributeItem, AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; @@ -65,7 +65,7 @@ let rangesName: AttributeName | undefined = undefined; let rangesLoading: Promise = Promise.resolve(); const groupTargetIds = useBatchGroup(() => dataId); -const colorMaps = useAttributeDefaultColorMap(() => dataId, attributeName, attributeColorMap); +const colorMaps = useSelectedAttributeColorMap(() => dataId, attributeName, attributeColorMap); const currentAttribute = computed(() => attributes.value.find((attr) => attr.attribute_name === attributeName.value), diff --git a/app/composables/attribute_selector.ts b/app/composables/attribute_selector.ts index c9d2a9fb2..0815cf018 100644 --- a/app/composables/attribute_selector.ts +++ b/app/composables/attribute_selector.ts @@ -128,7 +128,7 @@ function attributeRequestParams( } // Resolves the default colormap of an attribute from its data's geode object type -function useDefaultAttributeColorMap( +function useColorMapResolver( dataId: () => DataId, ): (attributeName: AttributeName | undefined) => Promise { const dataStore = useDataStore(); @@ -159,7 +159,7 @@ function useDefaultAttributeColorMap( } // Resolves and fills the default colormap of the selected attribute when none is stored yet -function useAttributeDefaultColorMap( +function useSelectedAttributeColorMap( dataId: () => DataId, attributeName: Readonly>, attributeColorMap: Ref, @@ -167,7 +167,7 @@ function useAttributeDefaultColorMap( resolveColorMap: (name: AttributeName) => Promise; ensureColorMap: () => Promise; } { - const defaultColorMapFor = useDefaultAttributeColorMap(dataId); + const defaultColorMapFor = useColorMapResolver(dataId); async function resolveColorMap(name: AttributeName): Promise { if (attributeColorMap.value !== undefined) { @@ -198,8 +198,8 @@ export { attributeItemOptions, attributeRequestParams, attributeRangesPerTarget, - useAttributeDefaultColorMap, useAttributeRangeBounds, - useDefaultAttributeColorMap, + useColorMapResolver, + useSelectedAttributeColorMap, useSeriesTimeStepCommit, }; diff --git a/app/composables/physical_property_coloring.ts b/app/composables/physical_property_coloring.ts index 7b3fd37f4..286c58226 100644 --- a/app/composables/physical_property_coloring.ts +++ b/app/composables/physical_property_coloring.ts @@ -8,8 +8,8 @@ import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; import type { ColoringType } from "@ogw_front/types/attribute"; import type { PhysicalPropertyNode } from "@ogw_front/utils/physical_properties_tree"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; +import { useColorMapResolver } from "@ogw_front/composables/attribute_selector"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; -import { useDefaultAttributeColorMap } from "@ogw_front/composables/attribute_selector"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; // The coloring a component goes back to when the property coloring is removed @@ -103,7 +103,7 @@ export function usePhysicalPropertyColoring(modelId: ModelId): { } { const dataStyleStore = useDataStyleStore(); const hybridViewerStore = useHybridViewerStore(); - const defaultColorMapFor = useDefaultAttributeColorMap(() => modelId); + const defaultColorMapFor = useColorMapResolver(() => modelId); function nodeMethods(node: PhysicalPropertyNode): ColoringMethods | undefined { return coloringMethods(dataStyleStore, node.component_type, node.element_type); From 948bc13e16e830928f0249ca3e0b58bcab632ff5 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Thu, 3 Dec 2026 10:31:45 +0100 Subject: [PATCH 10/11] fix(implicit_model): move implicit model type rules out of the colormap util isImplicitModelType, IMPLICIT_MODEL_TYPES and IMPLICIT_ATTRIBUTE_NAME describe object types, not colormaps: they move to utils/implicit_model.ts. --- app/utils/colormap.ts | 12 +--------- app/utils/implicit_model.ts | 15 +++++++++++++ app/utils/import_item.ts | 2 +- internal/stores/data_style/model/implicit.ts | 7 ++---- .../data_style_implicit_model.nuxt.test.ts | 3 ++- tests/unit/utils/colormap.nuxt.test.ts | 11 +--------- tests/unit/utils/implicit_model.nuxt.test.ts | 22 +++++++++++++++++++ 7 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 app/utils/implicit_model.ts create mode 100644 tests/unit/utils/implicit_model.nuxt.test.ts diff --git a/app/utils/colormap.ts b/app/utils/colormap.ts index 640874cfa..4264ee0c3 100644 --- a/app/utils/colormap.ts +++ b/app/utils/colormap.ts @@ -1,4 +1,5 @@ // oxlint-disable unicorn/prefer-export-from +import { IMPLICIT_ATTRIBUTE_NAME, isImplicitModelType } from "@ogw_front/utils/implicit_model"; import type { AttributeColorMap } from "@ogw_front/types/attribute"; import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; @@ -8,15 +9,6 @@ import { newInstance as vtkColorTransferFunction } from "@kitware/vtk.js/Renderi const DEFAULT_COLORMAP: AttributeColorMap = "batlow"; const IMPLICIT_COLORMAP: AttributeColorMap = "implicit"; -const IMPLICIT_ATTRIBUTE_NAME: AttributeName = "geode_implicit_attribute"; -const IMPLICIT_MODEL_TYPES: ReadonlySet = new Set([ - "ImplicitStructuralModel", - "ImplicitCrossSection", -]); - -function isImplicitModelType(geodeObjectType: GeodeObjectType | undefined): boolean { - return geodeObjectType !== undefined && IMPLICIT_MODEL_TYPES.has(geodeObjectType); -} function defaultAttributeColorMap( geodeObjectType: GeodeObjectType | undefined, @@ -129,14 +121,12 @@ function drawCanvasForPreset( export { DEFAULT_COLORMAP, - IMPLICIT_ATTRIBUTE_NAME, IMPLICIT_COLORMAP, defaultAttributeColorMap, drawCanvasForPreset, getPresetByName, getPresetsWithCurrentAtTop, getRGBPointsFromPreset, - isImplicitModelType, }; export { default as colormaps } from "@ogw_front/assets/colormaps.json"; diff --git a/app/utils/implicit_model.ts b/app/utils/implicit_model.ts new file mode 100644 index 000000000..f1a42f8b3 --- /dev/null +++ b/app/utils/implicit_model.ts @@ -0,0 +1,15 @@ +import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; + +// The vertex attribute holding the implicit function of an implicit model +const IMPLICIT_ATTRIBUTE_NAME: AttributeName = "geode_implicit_attribute"; +const IMPLICIT_MODEL_TYPES: ReadonlySet = new Set([ + "ImplicitStructuralModel", + "ImplicitCrossSection", +]); + +function isImplicitModelType(geodeObjectType: GeodeObjectType | undefined): boolean { + return geodeObjectType !== undefined && IMPLICIT_MODEL_TYPES.has(geodeObjectType); +} + +export { IMPLICIT_ATTRIBUTE_NAME, isImplicitModelType }; diff --git a/app/utils/import_item.ts b/app/utils/import_item.ts index 01edeca68..d8d9ba50c 100644 --- a/app/utils/import_item.ts +++ b/app/utils/import_item.ts @@ -2,7 +2,7 @@ import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; import { type NewDataItem, useDataStore } from "@ogw_front/stores/data"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; -import { isImplicitModelType } from "@ogw_front/utils/colormap"; +import { isImplicitModelType } from "@ogw_front/utils/implicit_model"; import { isModel } from "@ogw_front/utils/viewer_object_type"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useFeedbackStore } from "@ogw_front/stores/feedback"; diff --git a/internal/stores/data_style/model/implicit.ts b/internal/stores/data_style/model/implicit.ts index 22060b8e0..1afe7692f 100644 --- a/internal/stores/data_style/model/implicit.ts +++ b/internal/stores/data_style/model/implicit.ts @@ -1,11 +1,8 @@ -import { - IMPLICIT_ATTRIBUTE_NAME, - IMPLICIT_COLORMAP, - isImplicitModelType, -} from "@ogw_front/utils/colormap"; import type { ModelComponentId, ModelId } from "@ogw_front/types/identifiers"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import { IMPLICIT_ATTRIBUTE_NAME, isImplicitModelType } from "@ogw_front/utils/implicit_model"; +import { IMPLICIT_COLORMAP } from "@ogw_front/utils/colormap"; import type { StyleValues } from "@ogw_internal/stores/data_style/types"; import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; import { consola } from "consola"; diff --git a/tests/unit/stores/data_style_implicit_model.nuxt.test.ts b/tests/unit/stores/data_style_implicit_model.nuxt.test.ts index 2a8b9cd1f..e0186e4ea 100644 --- a/tests/unit/stores/data_style_implicit_model.nuxt.test.ts +++ b/tests/unit/stores/data_style_implicit_model.nuxt.test.ts @@ -4,10 +4,11 @@ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schem import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports -import { IMPLICIT_ATTRIBUTE_NAME, getRGBPointsFromPreset } from "@ogw_front/utils/colormap"; import { mockAs, setupActivePinia } from "@ogw_tests/utils"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import { IMPLICIT_ATTRIBUTE_NAME } from "@ogw_front/utils/implicit_model"; +import { getRGBPointsFromPreset } from "@ogw_front/utils/colormap"; import { importItem } from "@ogw_front/utils/import_item"; import { useBackStore } from "@ogw_front/stores/back"; import { useDataStore } from "@ogw_front/stores/data"; diff --git a/tests/unit/utils/colormap.nuxt.test.ts b/tests/unit/utils/colormap.nuxt.test.ts index 23def8724..a31ff55e7 100644 --- a/tests/unit/utils/colormap.nuxt.test.ts +++ b/tests/unit/utils/colormap.nuxt.test.ts @@ -4,13 +4,12 @@ import { describe, expect, test } from "vitest"; // Local imports import { DEFAULT_COLORMAP, - IMPLICIT_ATTRIBUTE_NAME, IMPLICIT_COLORMAP, defaultAttributeColorMap, getPresetByName, - isImplicitModelType, } from "@ogw_front/utils/colormap"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import { IMPLICIT_ATTRIBUTE_NAME } from "@ogw_front/utils/implicit_model"; describe("default attribute colormap", () => { test("provides the implicit colormap preset", () => { @@ -49,12 +48,4 @@ describe("default attribute colormap", () => { DEFAULT_COLORMAP, ); }); - - test("identifies implicit model types only", () => { - expect(isImplicitModelType("ImplicitStructuralModel")).toBe(true); - expect(isImplicitModelType("ImplicitCrossSection")).toBe(true); - expect(isImplicitModelType("StructuralModel")).toBe(false); - expect(isImplicitModelType("CrossSection")).toBe(false); - expect(isImplicitModelType(undefined)).toBe(false); - }); }); diff --git a/tests/unit/utils/implicit_model.nuxt.test.ts b/tests/unit/utils/implicit_model.nuxt.test.ts new file mode 100644 index 000000000..b1aa00375 --- /dev/null +++ b/tests/unit/utils/implicit_model.nuxt.test.ts @@ -0,0 +1,22 @@ +// Third party imports +import { describe, expect, test } from "vitest"; + +// Local imports +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import { isImplicitModelType } from "@ogw_front/utils/implicit_model"; + +describe("implicit model types", () => { + test.each(["ImplicitStructuralModel", "ImplicitCrossSection"])( + "identifies %s as an implicit model", + (geodeObjectType) => { + expect(isImplicitModelType(geodeObjectType)).toBe(true); + }, + ); + + test.each(["StructuralModel", "CrossSection", "BRep", undefined])( + "does not identify %s as an implicit model", + (geodeObjectType) => { + expect(isImplicitModelType(geodeObjectType)).toBe(false); + }, + ); +}); From f9e413725b52320197068010bd2ffc21c6676ea3 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Thu, 3 Dec 2026 10:31:50 +0100 Subject: [PATCH 11/11] fix(import): apply the implicit default style directly on import setModelMeshComponentsDefaultStyle is back to its generic form; import_item calls applyImplicitDefaultStyle for implicit models only, so the implicit model check happens once. --- app/utils/import_item.ts | 2 +- internal/stores/data_style/model/implicit.ts | 5 +---- internal/stores/data_style/model/index.ts | 9 +++++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/utils/import_item.ts b/app/utils/import_item.ts index d8d9ba50c..93440b0ce 100644 --- a/app/utils/import_item.ts +++ b/app/utils/import_item.ts @@ -37,7 +37,7 @@ async function applyStyleWhenReady(item: NewDataItem, ready: Promise): return undefined; } if (isImplicitModelType(item.geode_object_type)) { - await useDataStyleStore().setModelMeshComponentsDefaultStyle(item.data_id); + await useDataStyleStore().applyImplicitDefaultStyle(item.data_id, item.geode_object_type); } return useDataStyleStore().applyDefaultStyle(item.data_id); } diff --git a/internal/stores/data_style/model/implicit.ts b/internal/stores/data_style/model/implicit.ts index 1afe7692f..c8419ba95 100644 --- a/internal/stores/data_style/model/implicit.ts +++ b/internal/stores/data_style/model/implicit.ts @@ -1,7 +1,7 @@ import type { ModelComponentId, ModelId } from "@ogw_front/types/identifiers"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; -import { IMPLICIT_ATTRIBUTE_NAME, isImplicitModelType } from "@ogw_front/utils/implicit_model"; +import { IMPLICIT_ATTRIBUTE_NAME } from "@ogw_front/utils/implicit_model"; import { IMPLICIT_COLORMAP } from "@ogw_front/utils/colormap"; import type { StyleValues } from "@ogw_internal/stores/data_style/types"; import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -120,9 +120,6 @@ function useImplicitModelDefaultStyle( const backStore = useBackStore(); return async (modelId: ModelId, geodeObjectType: GeodeObjectType): Promise => { - if (!isImplicitModelType(geodeObjectType)) { - return; - } try { const targets = candidateTargetsFor(geodeObjectType, modelBlocksStyle, modelSurfacesStyle); for (const target of targets) { diff --git a/internal/stores/data_style/model/index.ts b/internal/stores/data_style/model/index.ts index c7eb1c4be..f5c0940ad 100644 --- a/internal/stores/data_style/model/index.ts +++ b/internal/stores/data_style/model/index.ts @@ -1,5 +1,6 @@ import type { ModelId, TreeNodeId } from "@ogw_front/types/identifiers"; import type { ComputedRef } from "vue"; +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; import { useImplicitModelDefaultStyle } from "./implicit"; @@ -24,6 +25,10 @@ type UseModelStyleReturn = ReturnType & visibleMeshComponents: (modelId: ModelId) => ComputedRef; applyModelStyle: (modelId: ModelId) => Promise; setModelMeshComponentsDefaultStyle: (modelId: ModelId) => Promise; + applyImplicitDefaultStyle: ( + modelId: ModelId, + geodeObjectType: GeodeObjectType, + ) => Promise; }; // oxlint-disable-next-line max-lines-per-function, max-statements @@ -79,8 +84,7 @@ function useModelStyle(): UseModelStyleReturn { } async function setModelMeshComponentsDefaultStyle(modelId: ModelId): Promise { - const item = await dataStore.item(modelId); - await applyImplicitDefaultStyle(modelId, item.geode_object_type); + await dataStore.item(modelId); const results = await Promise.all([ modelBlocksStyle.setModelBlocksDefaultStyle(modelId), modelSurfacesStyle.setModelSurfacesDefaultStyle(modelId), @@ -94,6 +98,7 @@ function useModelStyle(): UseModelStyleReturn { visibleMeshComponents, applyModelStyle, setModelMeshComponentsDefaultStyle, + applyImplicitDefaultStyle, ...modelColorStyle, ...modelVisibilityStyle, ...modelBlocksStyle,