Skip to content

Commit

Permalink
Merge branch 'master' into multiColorLegend
Browse files Browse the repository at this point in the history
  • Loading branch information
hkfb authored Jan 18, 2023
2 parents 319201c + 5359393 commit 42e0c2c
Show file tree
Hide file tree
Showing 19 changed files with 676 additions and 378 deletions.
121 changes: 121 additions & 0 deletions examples/deckgl_annotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import numpy as np
import xtgeo
import dash
import webviz_subsurface_components as wsc

from utils.xtgeo_surface_to_float32 import get_surface_float32
from utils.xtgeo_polygons_to_json import xtgeo_polygons_to_polylines_geojson

# Import a depth surface and a property surface using xtgeo
depth_surface = xtgeo.surface_from_file("examples/example-data/topvolantis_depth.gri")
property_surface = xtgeo.surface_from_file(
"examples/example-data/topvolantis_seismic_attribute.gri"
)
polygons = xtgeo.polygons_from_file(
"examples/example-data/topvolantis_faultpolygons.pol"
)

app = dash.Dash(__name__)

app.layout = wsc.SubsurfaceViewerDashWrapper(
id="deckgl-map",
layers=[
{
"@@type": "AxesLayer",
"id": "axes-layer",
"bounds": [
depth_surface.xmin,
depth_surface.ymin,
-np.nanmax(depth_surface.values),
depth_surface.xmax,
depth_surface.ymax,
np.nanmin(depth_surface.values),
],
},
{
"@@type": "MapLayer",
"id": "mesh-layer",
"meshUrl": "/map/mesh",
"frame": {
"origin": [depth_surface.xori, depth_surface.yori],
"count": [depth_surface.ncol, depth_surface.nrow],
"increment": [depth_surface.xinc, depth_surface.yinc],
"rotDeg": depth_surface.rotation,
},
"contours": [0, 20],
"isContoursDepth": True,
"gridLines": False,
"material": True,
"colorMapName": "Physics",
"name": "mesh",
},
{
"@@type": "MapLayer",
"id": "mesh-and-property-layer",
"meshUrl": "/map/mesh",
"propertiesUrl": "/map/property",
"frame": {
"origin": [depth_surface.xori, depth_surface.yori],
"count": [depth_surface.ncol, depth_surface.nrow],
"increment": [depth_surface.xinc, depth_surface.yinc],
"rotDeg": depth_surface.rotation,
},
"isContoursDepth": True,
"gridLines": False,
"material": True,
"colorMapName": "Seismic",
"name": "mesh",
},
{
"@@type": "FaultPolygonsLayer",
"id": "fault-layer",
"data": "/faults/faults.json",
"refine": False,
},
],
views={
"layout": [1, 2],
"showLabel": True,
"viewports": [
{
"id": "view_1",
"show3D": False,
"name": "Depth surface",
"layerIds": ["axes-layer", "mesh-layer"],
"isSync": True,
},
{
"id": "view_2",
"show3D": False,
"name": "Property mapped on depth surface",
"layerIds": [
"fault-layer",
"axes-layer",
"mesh-and-property-layer",
],
"isSync": True,
},
],
},
children=[
wsc.ViewAnnotation(id="view_1", children=[wsc.ViewFooter(children="Hugin")]),
wsc.ViewAnnotation(id="view_2", children=[wsc.ViewFooter(children="sdfsfd")]),
],
)


@app.server.route("/map/<map_name>")
def send_map(map_name: str):
if map_name == "mesh":
return get_surface_float32(depth_surface)
if map_name == "property":
return get_surface_float32(property_surface)


@app.server.route("/faults/faults.json")
def send_faults():
return xtgeo_polygons_to_polylines_geojson(polygons, xy_only=True)


if __name__ == "__main__":
app.run_server(debug=True)
69 changes: 35 additions & 34 deletions react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"deck.gl": "^8.8.11",
"deep-equal": "^2.0.5",
"fast-json-patch": "^3.0.0-1",
"gl-matrix": "^3.4.3",
"jsonschema": "^1.4.0",
"jsverify": "^0.8.4",
"leaflet": "^1.6.0",
Expand Down
1 change: 1 addition & 0 deletions react/src/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare module "*.svg" {
const src: string;
export default src;
}
declare module "*.png";
declare module "addon-redux/withRedux";
declare module "addon-redux/enhancer";
declare module "@emerson-eps/color-tables";

This file was deleted.

33 changes: 12 additions & 21 deletions react/src/lib/components/DeckGLMap/SubsurfaceViewerDashWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,18 @@ export interface SubsurfaceViewerDashWrapperProps {
cameraPosition?: ViewStateType | undefined;

children?: React.ReactNode;

/**
* A mapping associating annotation components to view ids.
* Example: {"view_1": <ColorLegend/>}
*/
annotation?: Record<string, unknown>;
}

function mapAnnotation(annotation: Record<string, unknown>) {
return Object.entries(annotation).map(([viewId, annotation]) => (
// @ts-expect-error This is demonstrated to work with js, but with ts it gives error
<View key={viewId} id={viewId}>
{annotation}
</View>
));
function mapAnnotation(annotationContainers: React.ReactNode) {
return React.Children.map(annotationContainers, (annotationContainer) => {
const viewId = (annotationContainer as React.ReactElement).key;
return (
// @ts-expect-error This is demonstrated to work with js, but with ts it gives error
<View key={viewId} id={viewId}>
{annotationContainer}
</View>
);
});
}

const SubsurfaceViewerDashWrapper: React.FC<
Expand All @@ -105,7 +102,6 @@ const SubsurfaceViewerDashWrapper: React.FC<
triggerHome,
triggerResetMultipleWells,
children,
annotation = {},
}: SubsurfaceViewerDashWrapperProps) => {
const mapArgs: DeckGLMapProps = {
id: id,
Expand All @@ -127,10 +123,9 @@ const SubsurfaceViewerDashWrapper: React.FC<
getCameraPosition: getCameraPosition,
triggerHome: triggerHome,
triggerResetMultipleWells: triggerResetMultipleWells,
children: children,
};

return <DeckGLMap {...mapArgs}>{mapAnnotation(annotation)}</DeckGLMap>;
return <DeckGLMap {...mapArgs}>{mapAnnotation(children)}</DeckGLMap>;
};

SubsurfaceViewerDashWrapper.defaultProps = {
Expand Down Expand Up @@ -265,11 +260,7 @@ SubsurfaceViewerDashWrapper.propTypes = {
*/
onMouseEvent: PropTypes.func,

/**
* A mapping associating annotation components to view ids.
* Example: {"view_1": <ColorLegend/>}
*/
annotation: PropTypes.any,
children: PropTypes.any,
};

export default SubsurfaceViewerDashWrapper;
Loading

0 comments on commit 42e0c2c

Please sign in to comment.