Skip to content

Commit

Permalink
Rename TopographicMap => SubsurfaceMap. Add global colorscale
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Sep 13, 2023
1 parent 6147245 commit 620d90f
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 14 deletions.
24 changes: 24 additions & 0 deletions frontend/src/modules/SubsurfaceMap/_utils/color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { colorTablesObj } from "@emerson-eps/color-tables";
import { ColorScale } from "@lib/utils/ColorScale";

import { formatRgb } from "culori";

function rgbStringToArray(rgbString: string): number[] | null {
const match = rgbString.match(/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/);
if (match) {
return [parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10)];
}
return null;
}
export function createContinuousColorScaleForMap(colorScale: ColorScale): colorTablesObj[] {
const hexColors = colorScale.getPlotlyColorScale();
const rgbArr: [number, number, number, number][] = [];
hexColors.forEach((color) => {
const rgbString: string = formatRgb(color[1]) as string;
const rgb = rgbStringToArray(rgbString);
if (rgb) {
rgbArr.push([color[0], rgb[0], rgb[1], rgb[2]]);
}
});
return [{ name: "Continuous", discrete: false, colors: rgbArr }];
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export {
createWellBoreHeaderLayer,
} from "./subsurfaceMap";
export type { SurfaceMeta, SurfaceMeshLayerSettings, ViewSettings } from "./subsurfaceMap";
export { createContinuousColorScaleForMap } from "./color";
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const defaultSurfaceSettings: SurfaceMeshLayerSettings = {
smoothShading: false,
material: false,
};

export function createNorthArrowLayer(visible?: boolean): Record<string, unknown> {
return {
"@@type": "NorthArrow3DLayer",
Expand Down Expand Up @@ -74,7 +75,7 @@ export function createSurfaceMeshLayer(
gridLines: surfaceSettings.gridLines,
material: surfaceSettings.material,
smoothShading: surfaceSettings.smoothShading,
colorMapName: "Physics",
colorMapName: "Continuous",
};
}
export function createSurfacePolygonsLayer(surfacePolygons: PolygonData_api[]): Record<string, unknown> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const defaultState: state = {
viewSettings: null,
};

const module = ModuleRegistry.initModule<state>("TopographicMap", defaultState, {
const module = ModuleRegistry.initModule<state>("SubsurfaceMap", defaultState, {
meshSurfaceAddress: { deepCompare: true },
propertySurfaceAddress: { deepCompare: true },
polygonsAddress: { deepCompare: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { SyncSettingKey } from "@framework/SyncSettings";
import { state } from "./state";

ModuleRegistry.registerModule<state>({
moduleName: "TopographicMap",
defaultTitle: "Topographic Map",
moduleName: "SubsurfaceMap",
defaultTitle: "Subsurface Map",
syncableSettingKeys: [
SyncSettingKey.ENSEMBLE,
SyncSettingKey.SURFACE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SurfAddr } from "./SurfaceAddress";
import { SurfacePolygonsAddress } from "./SurfacePolygonsAddress";
import { SurfaceMeshLayerSettings, ViewSettings } from "./_utils/";
import { SurfaceMeshLayerSettings, ViewSettings } from "./_utils";

export interface state {
meshSurfaceAddress: SurfAddr | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ import { SyncSettingKey, SyncSettingsHelper } from "@framework/SyncSettings";
import { Wellbore } from "@framework/Wellbore";
import { Button } from "@lib/components/Button";
import { CircularProgress } from "@lib/components/CircularProgress";
import { ColorScaleGradientType } from "@lib/utils/ColorScale";
import { ViewAnnotation } from "@webviz/subsurface-viewer/dist/components/ViewAnnotation";

import {
useGetFieldWellsTrajectories,
usePolygonsDataQueryByAddress,
usePropertySurfaceDataByQueryAddress,
useSurfaceDataQueryByAddress,
} from "././queryHooks";
import {
SurfaceMeta,
createAxesLayer,
createContinuousColorScaleForMap,
createNorthArrowLayer,
createSurfaceMeshLayer,
createSurfacePolygonsLayer,
createWellBoreHeaderLayer,
createWellboreTrajectoryLayer,
} from "./_utils";
import { SyncedSubsurfaceViewer } from "./components/SyncedSubsurfaceViewer";
import {
useGetFieldWellsTrajectories,
usePolygonsDataQueryByAddress,
usePropertySurfaceDataByQueryAddress,
useSurfaceDataQueryByAddress,
} from "./queryHooks";
import { state } from "./state";

const jsonParseWithUndefined = (arrString: string): number[] => {
Expand Down Expand Up @@ -60,7 +62,7 @@ const updateViewPortBounds = (
return existingViewPortBounds;
};
//-----------------------------------------------------------------------------------------------------------
export function view({ moduleContext, workbenchServices }: ModuleFCProps<state>) {
export function view({ moduleContext, workbenchSettings, workbenchServices }: ModuleFCProps<state>) {
const myInstanceIdStr = moduleContext.getInstanceIdString();
console.debug(`${myInstanceIdStr} -- render TopographicMap view`);
const viewIds = {
Expand All @@ -81,7 +83,10 @@ export function view({ moduleContext, workbenchServices }: ModuleFCProps<state>)
const [viewportBounds, setviewPortBounds] = React.useState<[number, number, number, number] | undefined>(undefined);
const syncedSettingKeys = moduleContext.useSyncedSettingKeys();
const syncHelper = new SyncSettingsHelper(syncedSettingKeys, workbenchServices);

const surfaceColorScale = workbenchSettings.useContinuousColorScale({
gradientType: ColorScaleGradientType.Sequential,
});
const colorTables = createContinuousColorScaleForMap(surfaceColorScale);
const show3D: boolean = viewSettings?.show3d ?? true;

const meshSurfDataQuery = useSurfaceDataQueryByAddress(meshSurfAddr, true);
Expand Down Expand Up @@ -228,6 +233,7 @@ export function view({ moduleContext, workbenchServices }: ModuleFCProps<state>)
id={viewIds.view3D}
bounds={viewportBounds}
layers={newLayers}
colorTables={colorTables}
toolbar={{ visible: true }}
views={{
layout: [1, 1],
Expand All @@ -245,6 +251,8 @@ export function view({ moduleContext, workbenchServices }: ModuleFCProps<state>)
>
<ViewAnnotation id={viewIds.annotation3D}>
<ContinuousLegend
colorTables={colorTables}
colorName="Continuous"
min={colorRange ? colorRange[0] : undefined}
max={colorRange ? colorRange[1] : undefined}
cssLegendStyles={{ bottom: "0", right: "0" }}
Expand All @@ -258,6 +266,7 @@ export function view({ moduleContext, workbenchServices }: ModuleFCProps<state>)
id={viewIds.view2D}
bounds={viewportBounds}
layers={newLayers}
colorTables={colorTables}
toolbar={{ visible: true }}
views={{
layout: [1, 1],
Expand All @@ -275,6 +284,8 @@ export function view({ moduleContext, workbenchServices }: ModuleFCProps<state>)
>
<ViewAnnotation id={viewIds.annotation2D}>
<ContinuousLegend
colorTables={colorTables}
colorName="Continuous"
min={colorRange ? colorRange[0] : undefined}
max={colorRange ? colorRange[1] : undefined}
cssLegendStyles={{ bottom: "0", right: "0" }}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/registerAllModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import "./Sensitivity/registerModule";
import "./SimulationTimeSeries/registerModule";
import "./SimulationTimeSeriesMatrix/registerModule";
import "./SimulationTimeSeriesSensitivity/registerModule";
import "./SubsurfaceMap/registerModule";
import "./TimeSeriesParameterDistribution/registerModule";
import "./TopographicMap/registerModule";
import "./WellCompletion/registerModule";

if (isDevMode()) {
Expand Down

0 comments on commit 620d90f

Please sign in to comment.