-
Notifications
You must be signed in to change notification settings - Fork 45
fix: Component for displaying performance metrics #2535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nilscb
wants to merge
8
commits into
equinor:master
Choose a base branch
from
nilscb:MetricsComponent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
50afdbc
fix: Component for displaying performance metrics
nilscb 7245bab
warning fix.
nilscb 28205d1
Code comment fixes.
nilscb 906ba60
typecheck
nilscb 83128fe
smoke
nilscb 22f7b6f
smoke
nilscb 9faedc7
smoke
nilscb 4f51d15
smoke
nilscb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
typescript/packages/subsurface-viewer/src/components/Metrics.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import React, { useState } from "react"; | ||
| import { forwardRef, useImperativeHandle } from "react"; | ||
| import type { DeckMetrics } from "../SubsurfaceViewer"; | ||
|
|
||
| export const Metrics = forwardRef((_props, ref) => { | ||
| const [metrics, setMetrics] = useState<DeckMetrics>(); | ||
|
|
||
| const publicRef = { | ||
| updateMetrics: (m: DeckMetrics) => { | ||
| setMetrics({ ...m }); | ||
| }, | ||
| }; | ||
|
|
||
| useImperativeHandle(ref, () => publicRef); | ||
|
|
||
| const isDefined = typeof metrics === "object"; | ||
| if (!isDefined) { | ||
| return null; | ||
| } | ||
|
|
||
| const tableRows = []; | ||
| for (const key in metrics) { | ||
| if (Object.prototype.hasOwnProperty.call(metrics, key)) { | ||
| const typedKey = key as keyof DeckMetrics; | ||
| tableRows.push( | ||
| <tr key={typedKey}> | ||
| <td> {typedKey} </td> | ||
| <td> {metrics[typedKey]?.toFixed(1)} </td> | ||
| </tr> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| alignItems: "flex-end", | ||
| justifyContent: "right", | ||
| position: "absolute", | ||
| top: "10px", | ||
| right: "30px", | ||
| zIndex: 200, | ||
| backgroundColor: "rgba(255, 255, 255, 0.8)", | ||
| }} | ||
| > | ||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <th align="left"> {"Metrics"} </th> | ||
| </tr> | ||
| {tableRows} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| Metrics.displayName = "MetricsComponent"; | ||
| export default Metrics; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,12 @@ import { ClipExtension } from "@deck.gl/extensions"; | |
| import type { SubsurfaceViewerProps } from "../../SubsurfaceViewer"; | ||
| import SubsurfaceViewer from "../../SubsurfaceViewer"; | ||
| import InfoCard from "../../components/InfoCard"; | ||
| import Metrics from "../../components/Metrics"; | ||
| import type { DeckMetrics } from "../../SubsurfaceViewer"; | ||
| import type { | ||
| BoundingBox2D, | ||
| BoundingBox3D, | ||
| BoundsAccessor, | ||
| ViewsType, | ||
| } from "../../components/Map"; | ||
| import { useHoverInfo } from "../../components/Map"; | ||
|
|
@@ -315,9 +318,47 @@ export const BigMap: StoryObj<typeof SubsurfaceViewer> = { | |
| }, | ||
| }; | ||
|
|
||
| export const BigMap3d: StoryObj<typeof SubsurfaceViewer> = { | ||
| interface BigMapComponentProps { | ||
| showMetrics: boolean; | ||
| layers: Array<Record<string, unknown>>; // Array of layer objects | ||
| bounds: BoundingBox2D | BoundsAccessor | undefined; // Can be 2D or 3D bounding box | ||
| views: ViewsType; // Type for views | ||
| } | ||
|
|
||
| const BigMapComponent: React.FC<BigMapComponentProps> = ( | ||
| props: BigMapComponentProps | ||
| ) => { | ||
| const metricsComponentRef = React.useRef<{ | ||
| updateMetrics?: (m: DeckMetrics) => void; | ||
| } | null>(null); | ||
| const updateMetrics = (m: DeckMetrics) => { | ||
| if (!metricsComponentRef.current) { | ||
| return; | ||
| } | ||
| if ("updateMetrics" in metricsComponentRef.current) { | ||
| metricsComponentRef.current.updateMetrics?.(m); | ||
| } | ||
| }; | ||
|
|
||
| const onMetrics = (m: DeckMetrics) => { | ||
| updateMetrics(m); | ||
| }; | ||
|
Comment on lines
+331
to
+345
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest creating an exported custom React hook that returns
I think it will be a more versatile and easier to use approach. I agree with @w1nklr that the ref shouldn't be necessary. I think it's at least worth a try. |
||
|
|
||
| return ( | ||
| <div> | ||
| <SubsurfaceViewer | ||
| id={"test"} | ||
| onMetrics={onMetrics} | ||
| {...props} | ||
| ></SubsurfaceViewer> | ||
| {props.showMetrics ? <Metrics ref={metricsComponentRef} /> : null} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export const BigMap3d: StoryObj<typeof BigMapComponent> = { | ||
| args: { | ||
| id: "map", | ||
| showMetrics: false, | ||
| layers: [huginAxes3DLayer, hugin5mKhNetmapMapLayer, northArrowLayer], | ||
| bounds: hugin2DBounds, | ||
| views: default3DViews, | ||
|
|
@@ -330,6 +371,7 @@ export const BigMap3d: StoryObj<typeof SubsurfaceViewer> = { | |
| }, | ||
| }, | ||
| }, | ||
| render: (args) => <BigMapComponent {...args} />, | ||
| }; | ||
|
|
||
| const axes_small = { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.