Skip to content

Commit

Permalink
fix: Rename callback to more descriptive name. Also callback should b…
Browse files Browse the repository at this point in the history
…e… (#1668)

* fix: Rename calback to more descriptive name. Also callback should be triggered when deck.gl receives an empty layer list.

* New wellsLayer property: "simplifiedRendering".  Default false. ([#1653](#1653)) ([baffae1](baffae1))

* Code review comments fixes.

---------

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
  • Loading branch information
nilscb and semantic-release-bot committed Sep 27, 2023
1 parent c0a9938 commit 0c1baee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ ViewStateSynchronization.argTypes = {
},
};

export const IsLoadedCallback = (args: SubsurfaceViewerProps) => {
export const IsRenderedCallback = (args: SubsurfaceViewerProps) => {
const [layers, setLayers] = React.useState([defaultWellsLayer] as [
WellsLayer,
MapLayer?,
Expand All @@ -515,15 +515,17 @@ export const IsLoadedCallback = (args: SubsurfaceViewerProps) => {
const handleChange = () => {
if (layers.length === 1) {
setLayers([defaultWellsLayer, meshMapLayerBig]);
} else if (layers.length === 2) {
setLayers([]);
} else {
setLayers([defaultWellsLayer]);
}
};

const props = {
...args,
isLoadedCallback: (isLoaded: boolean) => {
console.log("isLoadedCallback", isLoaded);
isRenderedCallback: (isLoaded: boolean) => {
console.log("isRenderedCallback", isLoaded);
setLabel(isLoaded ? "LOADED" : "NOT LOADED");
return;
},
Expand All @@ -542,7 +544,7 @@ export const IsLoadedCallback = (args: SubsurfaceViewerProps) => {
);
};

IsLoadedCallback.args = {
IsRenderedCallback.args = {
id: "DeckGL-Map",
layers: [meshMapLayerBig, defaultWellsLayer],
bounds: [432150, 6475800, 439400, 6481501],
Expand All @@ -557,12 +559,12 @@ IsLoadedCallback.args = {
},
};

IsLoadedCallback.parameters = {
IsRenderedCallback.parameters = {
docs: {
inlineStories: false,
iframeHeight: 500,
description: {
story: "IsLoadedCallback will report in console when triggered",
story: "IsRenderedCallback will report in console when triggered",
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export interface SubsurfaceViewerProps {
getCameraPosition?: (input: ViewStateType) => void;

/**
* Will be called after all layers have finished loading data.
* Will be called after all layers have rendered data.
*/
isLoadedCallback?: (arg: boolean) => void;
isRenderedCallback?: (arg: boolean) => void;

onDragStart?: (info: PickingInfo, event: MjolnirGestureEvent) => void;
onDragEnd?: (info: PickingInfo, event: MjolnirGestureEvent) => void;
Expand Down Expand Up @@ -154,7 +154,7 @@ const SubsurfaceViewer: React.FC<SubsurfaceViewerProps> = ({
getTooltip,
cameraPosition,
getCameraPosition,
isLoadedCallback,
isRenderedCallback: isRenderedCallback,
onDragStart,
onDragEnd,
triggerHome,
Expand Down Expand Up @@ -240,7 +240,7 @@ const SubsurfaceViewer: React.FC<SubsurfaceViewerProps> = ({
getTooltip={getTooltip}
cameraPosition={cameraPosition}
getCameraPosition={getCameraPosition}
isLoadedCallback={isLoadedCallback}
isRenderedCallback={isRenderedCallback}
onDragStart={onDragStart}
onDragEnd={onDragEnd}
triggerHome={triggerHome}
Expand Down
18 changes: 12 additions & 6 deletions typescript/packages/subsurface-viewer/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ export interface MapProps {
getCameraPosition?: (input: ViewStateType) => void;

/**
* Will be called after all layers have finished loading data.
* Will be called after all layers have rendered data.
*/
isLoadedCallback?: (arg: boolean) => void;
isRenderedCallback?: (arg: boolean) => void;

onDragStart?: (info: PickingInfo, event: MjolnirGestureEvent) => void;
onDragEnd?: (info: PickingInfo, event: MjolnirGestureEvent) => void;
Expand Down Expand Up @@ -578,7 +578,7 @@ const Map: React.FC<MapProps> = ({
getTooltip = defaultTooltip,
cameraPosition,
getCameraPosition,
isLoadedCallback,
isRenderedCallback: isLoadedCallback,
onDragStart,
onDragEnd,
triggerHome,
Expand Down Expand Up @@ -708,6 +708,7 @@ const Map: React.FC<MapProps> = ({
// Empty layers array makes deck.gl set deckRef to undefined (no opengl context).
// Hence insert dummy layer.
const dummy_layer = new LineLayer({
id: "webviz_internal_dummy_layer",
visible: false,
});
layers.push(dummy_layer);
Expand Down Expand Up @@ -917,13 +918,18 @@ const Map: React.FC<MapProps> = ({
const [isLoaded, setIsLoaded] = useState<boolean>(false);
const onAfterRender = useCallback(() => {
if (deckGLLayers) {
const state = deckGLLayers.every((layer) => {
const loadedState = deckGLLayers.every((layer) => {
return (layer as Layer).isLoaded;
});
setIsLoaded(state);

const emptyLayers = // There will always be a dummy layer. Deck.gl does not like empty array of layers.
deckGLLayers.length == 1 &&
(deckGLLayers[0] as LineLayer).id ===
"webviz_internal_dummy_layer";

setIsLoaded(loadedState || emptyLayers);
if (typeof isLoadedCallback !== "undefined") {
isLoadedCallback(state);
isLoadedCallback(loadedState);
}
}
}, [deckGLLayers, isLoadedCallback]);
Expand Down

0 comments on commit 0c1baee

Please sign in to comment.