equinor / webviz-subsurface-components

Custom subsurface visualizations for use in Webviz and/or Dash.
https://github.com/orgs/equinor/projects/24
Mozilla Public License 2.0
33 stars 38 forks source link

[NGRM] - In SyncLogViewer initial mount sometimes has wrong zoom when sync scale by controllers #2108

Open mirisb opened 1 week ago

mirisb commented 1 week ago

While mounting the component we fetch data from server which takes some. while the data is being fetched we first pass an empty log in the props:

const emptyLog : WellLog = {
      header: { startIndex: 0, endIndex: 1, step: 1 },
      curves: [
        {
          name: "MD",
          unit: "m",
          dimensions: 1,
        },
        {
          name: "Empty",
        },
      ],
      data: [
        [0, null],
        [1, null],
      ],
    };

Once fetching from server is complete the props are replaced with the real props that contain real logs from several wells.

We sync scales between different controllers in SLV using onContentRescale callback from the component (usually this function is only called when use flattening and want to apply our own logic for track positioning):

   const onContentRescale = React.useCallback(
     (iView: number) => {
       if (controllers.length <= iView) {
         return;
       }

       // we want to mantain the same aspect ratio - thus we take the scale from the affected well and apply it to all the wells
       const scale = controllers[iView].getContentScale();
       if (!isFinite(scale)) {
         return;
       }

       controllers.forEach(controller => {
         if (controller == controllers[iView]) {
           return; // skip controller which caused the onContentRescale
         }
        controller.setContentScale(scale);
       });
    },
    [controllers]
  );

The problem occurs when sometimes when calling controller.setContentScale we get the correct scale however the zoom itself is calculated according to the size of the overlay, in function getContentBaseScale () in WellLogView.ts (in Webviz codebase). When this function is called, the overlay has not yet become visible, its size not yet calculated and it contains a bogus height which causes it to give wrong results which leads to calculation of wrong zoom.

image

This is easily recreated in Viz storybook by mounting story "Two Wells Same Log" and after it is mounted correctly switch to story "Two Wells Different Log". Since this bug depends on timing and fetching data from server, to recreate the storybook must be reloaded from scratch to clear caches.

mirisb commented 1 week ago

@Vladimir-Kokin , maybe a solution would be to add a query to the controller to make sure that it is fully rendered.

In debugger I was able to display the overlay and see that it is not visible: image

If the controller has a query function to make sure it is rendered, we could test it before trying to change the scale...