Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Oct 17, 2024
1 parent 553aa51 commit 8bf4d8b
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 42 deletions.
8 changes: 8 additions & 0 deletions frontend/src/lib/utils/ColorScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export class ColorScale {
getColorForValue(value: number): string {
let color = "";

// Clamp colors
if (value < this._min) {
value = this._min;
}
if (value > this._max) {
value = this._max;
}

if (this._type === ColorScaleType.Discrete) {
const colors = this.sampleColors(this._steps);
const normalizedValue = this.calcNormalizedValue(value, this._min, this._max);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ export class SettingsContextDelegate<TSettings extends Settings, TKey extends ke
}
}

private async fetchData(): Promise<boolean> {
private async fetchData(): Promise<void> {
this.setLoadingState(SettingsContextLoadingState.LOADING);
const result = await this._parentContext.fetchData(this._cachedValues, this._values);
if (result) {
this.setLoadingState(SettingsContextLoadingState.LOADED);
} else {
this.setLoadingState(SettingsContextLoadingState.FAILED);
}
return result;
}

private setLoadingState(loadingState: SettingsContextLoadingState): void {
Expand Down Expand Up @@ -138,10 +137,7 @@ export class SettingsContextDelegate<TSettings extends Settings, TKey extends ke
}

if (!isEqual(this._cachedValues, this._values)) {
this.fetchData().then((result) => {
if (!result) {
return;
}
this.fetchData().then(() => {
if (this._onSettingsChanged) {
this._onSettingsChanged(this._cachedValues, this._values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@ export class DrilledWellTrajectoriesContext implements SettingsContext<DrilledWe
return this._contextDelegate.getSettings();
}

async fetchData(
oldValues: DrilledWellTrajectoriesSettings,
newValues: DrilledWellTrajectoriesSettings
): Promise<boolean> {
if (
isEqual(oldValues[SettingType.ENSEMBLE], newValues[SettingType.ENSEMBLE]) &&
newValues[SettingType.ENSEMBLE] !== null
) {
return true;
}
async fetchData(oldValues: DrilledWellTrajectoriesSettings): Promise<boolean> {
const queryClient = this.getDelegate().getLayerManager().getQueryClient();

const settings = this.getDelegate().getSettings();
Expand Down Expand Up @@ -83,6 +74,7 @@ export class DrilledWellTrajectoriesContext implements SettingsContext<DrilledWe
gcTime: CACHE_TIME,
});
} catch (e) {
this._contextDelegate.setAvailableValues(SettingType.SMDA_WELLBORE_HEADERS, []);
settings[SettingType.SMDA_WELLBORE_HEADERS].getDelegate().setLoadingState(false);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { SurfaceTimeType_api } from "@api";
import { SurfaceMetaSet_api, SurfaceTimeType_api } from "@api";
import { apiService } from "@framework/ApiService";
import { SettingsContextDelegate } from "@modules/2DViewer/layers/delegates/SettingsContextDelegate";
import { CACHE_TIME, STALE_TIME } from "@modules/2DViewer/layers/queryConstants";
import { SettingType } from "@modules/2DViewer/layers/settingsTypes";

import { isEqual } from "lodash";
import { SurfaceMetaSet } from "src/api/models/SurfaceMetaSet";

import { ObservedSurfaceSettings } from "./types";

Expand All @@ -17,7 +16,7 @@ import { TimeOrInterval } from "../../settings/TimeOrInterval";

export class ObservedSurfaceContext implements SettingsContext<ObservedSurfaceSettings> {
private _contextDelegate: SettingsContextDelegate<ObservedSurfaceSettings>;
private _fetchDataCache: SurfaceMetaSet | null = null;
private _fetchDataCache: SurfaceMetaSet_api | null = null;

constructor() {
this._contextDelegate = new SettingsContextDelegate<ObservedSurfaceSettings, keyof ObservedSurfaceSettings>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { SurfaceTimeType_api } from "@api";
import { SurfaceMetaSet_api, SurfaceTimeType_api } from "@api";
import { apiService } from "@framework/ApiService";
import { SettingsContextDelegate } from "@modules/2DViewer/layers/delegates/SettingsContextDelegate";
import { CACHE_TIME, STALE_TIME } from "@modules/2DViewer/layers/queryConstants";
import { SettingType } from "@modules/2DViewer/layers/settingsTypes";

import { isEqual } from "lodash";
import { SurfaceMetaSet } from "src/api/models/SurfaceMetaSet";

import { RealizationSurfaceSettings } from "./types";

Expand All @@ -18,7 +17,7 @@ import { TimeOrInterval } from "../../settings/TimeOrInterval";

export class RealizationSurfaceContext implements SettingsContext<RealizationSurfaceSettings> {
private _contextDelegate: SettingsContextDelegate<RealizationSurfaceSettings>;
private _fetchDataCache: SurfaceMetaSet | null = null;
private _fetchDataCache: SurfaceMetaSet_api | null = null;

constructor() {
this._contextDelegate = new SettingsContextDelegate<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { SurfaceTimeType_api } from "@api";
import { SurfaceMetaSet_api, SurfaceTimeType_api } from "@api";
import { apiService } from "@framework/ApiService";
import { Ensemble as FrameworkEnsemble } from "@framework/Ensemble";
import { CACHE_TIME, STALE_TIME } from "@modules/2DViewer/layers/queryConstants";

import { isEqual } from "lodash";
import { SurfaceMetaSet } from "src/api/models/SurfaceMetaSet";

import { StatisticalSurfaceSettings } from "./types";

Expand All @@ -20,7 +19,7 @@ import { TimeOrInterval } from "../../settings/TimeOrInterval";

export class StatisticalSurfaceContext implements SettingsContext<StatisticalSurfaceSettings> {
private _contextDelegate: SettingsContextDelegate<StatisticalSurfaceSettings>;
private _fetchDataCache: SurfaceMetaSet | null = null;
private _fetchDataCache: SurfaceMetaSet_api | null = null;

constructor() {
this._contextDelegate = new SettingsContextDelegate<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class StatisticalSurfaceLayer
}

// If realizations are filtered, update the address
let allRealizations = currentEnsemble?.getRealizations() ?? [];
const allRealizations = currentEnsemble?.getRealizations() ?? [];
if (!isEqual([...allRealizations], [...filteredRealizations])) {
addrBuilder.withStatisticRealizations([...filteredRealizations]);
}
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/modules/2DViewer/view/components/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button } from "@lib/components/Button";
import { HoldPressedIntervalCallbackButton } from "@lib/components/HoldPressedIntervalCallbackButton/holdPressedIntervalCallbackButton";
import { Toolbar as GenericToolbar, ToolBarDivider } from "@modules/_shared/components/Toolbar";
import { Add, FilterCenterFocus, Remove } from "@mui/icons-material";
import { Toolbar as GenericToolbar } from "@modules/_shared/components/Toolbar";
import { FilterCenterFocus } from "@mui/icons-material";

export type ToolbarProps = {
onFitInView: () => void;
Expand Down
23 changes: 13 additions & 10 deletions frontend/src/modules/2DViewer/view/utils/layerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PolygonData_api, SurfaceDef_api, WellborePick_api, WellboreTrajectory_api } from "@api";
import { PolygonData_api, SurfaceDataPng_api, SurfaceDef_api, WellborePick_api, WellboreTrajectory_api } from "@api";
import { Layer } from "@deck.gl/core";
import { GeoJsonLayer } from "@deck.gl/layers";
import { defaultColorPalettes } from "@framework/utils/colorPalettes";
Expand All @@ -10,7 +10,6 @@ import { ColormapLayer, Grid3DLayer, WellsLayer } from "@webviz/subsurface-viewe

import { Rgb, parse } from "culori";
import { Feature, FeatureCollection, GeoJsonProperties, Geometry } from "geojson";
import { SurfaceDataPng } from "src/api/models/SurfaceDataPng";

import { DrilledWellTrajectoriesLayer } from "../../layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer";
import { DrilledWellborePicksLayer } from "../../layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksLayer";
Expand Down Expand Up @@ -129,7 +128,7 @@ function createMapFloatLayer(layerData: SurfaceDataFloat_trans, id: string): Map
*/

function createMapImageLayer(
layerData: SurfaceDataPng,
layerData: SurfaceDataPng_api,
id: string,
name: string,
colorScale?: ColorScaleWithName
Expand All @@ -141,14 +140,12 @@ function createMapImageLayer(
bounds: _calcBoundsForRotationAroundUpperLeftCorner(layerData.surface_def),
rotDeg: layerData.surface_def.rot_deg,
valueRange: [layerData.value_min, layerData.value_max],
colorMapRange: colorScale
? [colorScale.getMin(), colorScale.getMax()]
: [layerData.value_min, layerData.value_max],
colorMapRange: [layerData.value_min, layerData.value_max],
colorMapName: "Physics",
parameters: {
depthWriteEnabled: false,
},
colorMapFunction: makeColorMapFunction(colorScale),
colorMapFunction: makeColorMapFunction(colorScale, layerData.value_min, layerData.value_max),
});
}

Expand Down Expand Up @@ -336,20 +333,26 @@ export function makeGrid3DLayer(
colorMapName: "Physics",
colorMapClampColor: true,
colorMapRange: [gridParameterData.min_grid_prop_value, gridParameterData.max_grid_prop_value],
colorMapFunction: makeColorMapFunction(colorScale),
colorMapFunction: makeColorMapFunction(
colorScale,
gridParameterData.min_grid_prop_value,
gridParameterData.max_grid_prop_value
),
});
return grid3dLayer as unknown as WorkingGrid3dLayer;
}

function makeColorMapFunction(
colorScale: ColorScaleWithName | undefined
colorScale: ColorScaleWithName | undefined,
valueMin: number,
valueMax: number
): ((value: number) => [number, number, number]) | undefined {
if (!colorScale) {
return undefined;
}

return (value: number) => {
const nonNormalizedValue = value * (colorScale.getMax() - colorScale.getMin()) + colorScale.getMin();
const nonNormalizedValue = value * (valueMax - valueMin) + valueMin;
const interpolatedColor = colorScale.getColorForValue(nonNormalizedValue);
const color = parse(interpolatedColor) as Rgb;
if (color === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from "react";
import { WellboreHeader_api } from "@api";
import { Button } from "@lib/components/Button";
import { CollapsibleGroup } from "@lib/components/CollapsibleGroup";
import { Dropdown } from "@lib/components/Dropdown";
import { Label } from "@lib/components/Label";
import { Select, SelectOption } from "@lib/components/Select";
import { useValidArrayState } from "@lib/hooks/useValidArrayState";
Expand All @@ -16,6 +15,7 @@ export type WellboreSelectorProps = {
};

export function WellboreSelector(props: WellboreSelectorProps): React.ReactNode {
const { onSelectedWellboreUuidsChange } = props;
const availableWellboreStatuses = Array.from(new Set(props.wellboreHeaders.map((header) => header.wellboreStatus)));
const availableWellborePurposes = Array.from(
new Set(props.wellboreHeaders.map((header) => header.wellborePurpose))
Expand All @@ -29,14 +29,14 @@ export function WellboreSelector(props: WellboreSelectorProps): React.ReactNode
validStateArray: availableWellborePurposes,
});
React.useEffect(() => {
props.onSelectedWellboreUuidsChange(
onSelectedWellboreUuidsChange(
props.wellboreHeaders
.filter((header) => selectedWellborePurposes.includes(header.wellborePurpose))
.filter((header) => selectedWellboreStatuses.includes(header.wellboreStatus))
// .filter((header) => props.selectedWellboreUuids.includes(header.wellboreUuid))
.map((header) => header.wellboreUuid)
);
}, [selectedWellborePurposes, selectedWellboreStatuses]);
}, [selectedWellborePurposes, selectedWellboreStatuses, onSelectedWellboreUuidsChange, props.wellboreHeaders]);

function handleSelectAll() {
props.onSelectedWellboreUuidsChange(
Expand Down

0 comments on commit 8bf4d8b

Please sign in to comment.