forked from equinor/webviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea5d0c5
commit 2ca6abf
Showing
8 changed files
with
441 additions
and
23 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
frontend/src/modules/2DViewer/layers/FaultPolygonLayer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { PolygonData_api } from "@api"; | ||
import { apiService } from "@framework/ApiService"; | ||
import { EnsembleIdent } from "@framework/EnsembleIdent"; | ||
import { defaultColorPalettes } from "@framework/utils/colorPalettes"; | ||
import { ColorSet } from "@lib/utils/ColorSet"; | ||
import { BaseLayer, BoundingBox, LayerTopic } from "@modules/_shared/layers/BaseLayer"; | ||
import { LayerManager } from "@modules/_shared/layers/LayerManager"; | ||
import { QueryClient } from "@tanstack/query-core"; | ||
|
||
import { isEqual } from "lodash"; | ||
|
||
const STALE_TIME = 60 * 1000; | ||
const CACHE_TIME = 60 * 1000; | ||
|
||
export type FaultPolygonLayerSettings = { | ||
ensembleIdent: EnsembleIdent | null; | ||
realizationNum: number | null; | ||
polygonName: string | null; | ||
attribute: string | null; | ||
}; | ||
|
||
export class FaultPolygonLayer extends BaseLayer<FaultPolygonLayerSettings, PolygonData_api[]> { | ||
private _colorSet: ColorSet; | ||
|
||
constructor(name: string, layerManager: LayerManager) { | ||
const defaultSettings = { | ||
ensembleIdent: null, | ||
realizationNum: null, | ||
polyline: { | ||
polylineUtmXy: [], | ||
actualSectionLengths: [], | ||
}, | ||
polygonName: null, | ||
attribute: null, | ||
}; | ||
super(name, defaultSettings, layerManager); | ||
|
||
this._colorSet = new ColorSet(defaultColorPalettes[0]); | ||
} | ||
|
||
getColorSet(): ColorSet { | ||
return this._colorSet; | ||
} | ||
|
||
setColorSet(colorSet: ColorSet): void { | ||
this._colorSet = colorSet; | ||
this.notifySubscribers(LayerTopic.DATA); | ||
} | ||
|
||
private makeBoundingBox(): void { | ||
if (!this._data) { | ||
return; | ||
} | ||
|
||
const minX = Number.MAX_VALUE; | ||
const maxX = Number.MIN_VALUE; | ||
const minY = Number.MAX_VALUE; | ||
const maxY = Number.MIN_VALUE; | ||
|
||
super.setBoundingBox({ | ||
x: [minX, maxX], | ||
y: [minY, maxY], | ||
z: [0, 0], | ||
}); | ||
} | ||
|
||
getBoundingBox(): BoundingBox | null { | ||
const bbox = super.getBoundingBox(); | ||
if (bbox) { | ||
return bbox; | ||
} | ||
|
||
this.makeBoundingBox(); | ||
return super.getBoundingBox(); | ||
} | ||
|
||
protected areSettingsValid(): boolean { | ||
return ( | ||
this._settings.ensembleIdent !== null && | ||
this._settings.attribute !== null && | ||
this._settings.polygonName !== null && | ||
this._settings.realizationNum !== null | ||
); | ||
} | ||
|
||
protected doSettingsChangesRequireDataRefetch( | ||
prevSettings: FaultPolygonLayerSettings, | ||
newSettings: FaultPolygonLayerSettings | ||
): boolean { | ||
return ( | ||
!isEqual(prevSettings.polygonName, newSettings.polygonName) || | ||
prevSettings.attribute !== newSettings.attribute || | ||
prevSettings.realizationNum !== newSettings.realizationNum || | ||
!isEqual(prevSettings.ensembleIdent, newSettings.ensembleIdent) | ||
); | ||
} | ||
|
||
protected async fetchData(queryClient: QueryClient): Promise<PolygonData_api[]> { | ||
// super.setBoundingBox(null); | ||
|
||
const queryKey = [ | ||
"getPolygonsData", | ||
this._settings.ensembleIdent?.getCaseUuid() ?? "", | ||
this._settings.ensembleIdent?.getEnsembleName() ?? "", | ||
this._settings.realizationNum ?? 0, | ||
this._settings.polygonName ?? "", | ||
this._settings.attribute ?? "", | ||
]; | ||
this.registerQueryKey(queryKey); | ||
|
||
return queryClient.fetchQuery({ | ||
queryKey, | ||
queryFn: () => | ||
apiService.polygons.getPolygonsData( | ||
this._settings.ensembleIdent?.getCaseUuid() ?? "", | ||
this._settings.ensembleIdent?.getEnsembleName() ?? "", | ||
this._settings.realizationNum ?? 0, | ||
this._settings.polygonName ?? "", | ||
this._settings.attribute ?? "" | ||
), | ||
staleTime: STALE_TIME, | ||
gcTime: CACHE_TIME, | ||
}); | ||
} | ||
} | ||
|
||
export function isFaultPolygonLayer(layer: BaseLayer<any, any>): layer is FaultPolygonLayer { | ||
return layer instanceof FaultPolygonLayer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
export enum LayerType { | ||
SURFACE = "surface", | ||
WELLBORE_SMDA = "wellbore_drilled", | ||
FAULT_POLYGON = "fault_polygon", | ||
POLYGON = "polygon", | ||
} | ||
|
||
export const LAYER_TYPE_TO_STRING_MAPPING = { | ||
[LayerType.SURFACE]: "Surface", | ||
[LayerType.WELLBORE_SMDA]: "Wells (Drilled)", | ||
[LayerType.FAULT_POLYGON]: "Fault Polygons", | ||
[LayerType.POLYGON]: "Polygons", | ||
}; |
Oops, something went wrong.