Browse Source

Issue #836: auto-resize attribute added to 1D component

cycle20 1 year ago
parent
commit
10b1c31cbe
1 changed files with 13 additions and 3 deletions
  1. 13 3
      src/TmFv3DApp/tmdet-viewer/TmFv1DComponent.tsx

+ 13 - 3
src/TmFv3DApp/tmdet-viewer/TmFv1DComponent.tsx

@@ -14,7 +14,8 @@ type TmFv1DParams = {
     url: string,
     side1: string,
     trackWidth?: number,
-    rowTitleWidth?: number
+    rowTitleWidth?: number,
+    autoResize?: boolean
 };
 
 type TmFv1DState = {
@@ -42,8 +43,10 @@ export class TmFv1D extends React.Component<TmFv1DParams, TmFv1DState> {
             trackWidth: this.props.trackWidth
         });
 
-        new ResizeObserver(this.resize)
-            .observe(this.containerRef.current as Element);
+        if (this.props.autoResize) {
+            new ResizeObserver(this.resize)
+                .observe(this.containerRef.current as Element);
+        }
     }
 
     resize(entries: ResizeObserverEntry[], observer: ResizeObserver) {
@@ -84,6 +87,12 @@ export class TmFv1DElement extends HTMLElement {
             || calculatedWidth) - rowTitleWidth;
         console.log('Widths:', [ rowTitleWidth, trackWidth ]);
 
+        let autoResize = true;
+        if (this.hasAttribute("autoResize")) {
+            const value = this.getAttribute("autoResize");
+            autoResize = (value == "true");
+        }
+
         root.render(
             <TmFv1D
                 elementId={ elementId }
@@ -91,6 +100,7 @@ export class TmFv1DElement extends HTMLElement {
                 side1={ side1 }
                 trackWidth={ trackWidth }
                 rowTitleWidth={ rowTitleWidth }
+                autoResize={ autoResize }
             />
         );
     }