Skip to content

Commit

Permalink
feat: add top level vertical scale factor
Browse files Browse the repository at this point in the history
  • Loading branch information
hkfb committed Apr 15, 2024
1 parent 9e33148 commit 8d46746
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export interface SubsurfaceViewerProps {
lights?: LightsType;

children?: React.ReactNode;

/** A vertical scale factor, used to scale items in the view vertically */
verticalScale?: number;
}

const SubsurfaceViewer: React.FC<SubsurfaceViewerProps> = ({
Expand Down Expand Up @@ -162,6 +165,7 @@ const SubsurfaceViewer: React.FC<SubsurfaceViewerProps> = ({
triggerResetMultipleWells,
lights,
children,
verticalScale,
}: SubsurfaceViewerProps) => {
// Contains layers data received from map layers by user interaction
const [layerEditedData, setLayerEditedData] = React.useState(editedData);
Expand Down Expand Up @@ -240,6 +244,7 @@ const SubsurfaceViewer: React.FC<SubsurfaceViewerProps> = ({
triggerHome={triggerHome}
triggerResetMultipleWells={triggerResetMultipleWells}
lights={lights}
verticalScale={verticalScale}
>
{children}
</Map>
Expand Down
17 changes: 13 additions & 4 deletions typescript/packages/subsurface-viewer/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ export interface MapProps {
children?: React.ReactNode;

getTooltip?: TooltipCallback;

/** A vertical scale factor, used to scale items in the view vertically */
verticalScale?: number;
}

function defaultTooltip(info: PickingInfo) {
Expand Down Expand Up @@ -391,6 +394,7 @@ const Map: React.FC<MapProps> = ({
onDragEnd,
lights,
triggerResetMultipleWells,
verticalScale,
}: MapProps) => {
// From react doc, ref should not be read nor modified during rendering.
const deckRef = React.useRef<DeckGLRef>(null);
Expand Down Expand Up @@ -425,11 +429,12 @@ const Map: React.FC<MapProps> = ({
);

// Get vertical scaling factor defined in viewports.
const verticalScale = useVerticalScale(views?.viewports);
const viewportVerticalScale = useVerticalScale(views?.viewports);

// Used for scaling in z direction using arrow keys.
const { zScale: zReScale, divRef: zScaleRef } =
useHandleRescale(!!verticalScale);
const { zScale: zReScale, divRef: zScaleRef } = useHandleRescale(
!!(verticalScale ?? viewportVerticalScale)
);

const { shiftHeld, divRef: shiftHeldRef } = useShiftHeld();

Expand All @@ -438,7 +443,7 @@ const Map: React.FC<MapProps> = ({
shiftHeldRef
) as React.Ref<HTMLDivElement>;

const zScale = verticalScale ?? zReScale;
const zScale = verticalScale ?? viewportVerticalScale ?? zReScale;

// compute the viewport margins
const viewPortMargins = React.useMemo<MarginsType>(() => {
Expand Down Expand Up @@ -1086,6 +1091,9 @@ class ViewController {
state.deckSize != this.state_.deckSize));
const needUpdate = updateZScale || updateTarget || updateViewState;

console.log("getDeckGlViewState: viewsChanged: ", viewsChanged);
console.log("getDeckGlViewState: updateViewState: ", updateViewState);

const isCacheEmpty = isEmpty(this.result_.viewState);
if (!isCacheEmpty && !needUpdate) {
return this.result_.viewState;
Expand All @@ -1096,6 +1104,7 @@ class ViewController {
let viewState = prevViewState;

if (updateViewState || isCacheEmpty) {
console.log("getDeckGlViewState: buildDeckGlViewSTates");
viewState = buildDeckGlViewStates(
views,
state.viewPortMargins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ const Root = styled("div")({
},
});

const SIDE_CAMERA = {
rotationX: 0,
target: [],
rotationOrbit: 90,
zoom: -3,
};

const SQUARE = {
type: "Feature",
geometry: {
Expand Down Expand Up @@ -623,22 +630,9 @@ const ScaleVertical3dComponent = ({
id: "ScaleY",
bounds: volveWellsBounds,
layers: [huginAxes3DLayer, hugin25mDepthMapLayer],
views: {
layout: [1, 1],
viewports: [
{
id: "section",
verticalScale,
show3D: true,
},
],
},
cameraPosition: {
rotationX: 0,
target: [],
rotationOrbit: 90,
zoom: -3,
},
views: default3DViews,
cameraPosition: SIDE_CAMERA,
verticalScale,
};
return <SubsurfaceViewer {...viewerProps} />;
};
Expand Down
3 changes: 2 additions & 1 deletion typescript/packages/subsurface-viewer/src/views/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export interface ViewportType {
rotationX?: number;
rotationOrbit?: number;

/** A vertical scale factor, used to scale items in the viewport vertically */
/** @deprecated Please use top-level verticalScale instead for 3D and cameraPosition.zoom for 2D.
* A vertical scale factor, used to scale items in the viewport vertically. */
verticalScale?: number;

isSync?: boolean;
Expand Down

0 comments on commit 8d46746

Please sign in to comment.