Skip to content
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

Add width/height properties to web viewer #6636

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rerun_js/web-viewer-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This means that `@rerun-io/[email protected]` can only connect to a data s
import WebViewer from "@rerun-io/web-viewer-react";

export default function App() {
return <WebViewer rrd="...">
return <WebViewer width="800px" height="600px" rrd="...">
}
```

Expand All @@ -39,6 +39,10 @@ The `rrd` in the snippet above should be a URL pointing to either:
- A WebSocket connection to the SDK opened via the [`serve`](https://www.rerun.io/docs/reference/sdk-operating-modes#serve) API

If `rrd` is not set, the Viewer will display the same welcome screen as <https://app.rerun.io>.
This can be disabled by setting the `hide_welcome_screen` prop to `true`.

⚠ It's important to set the viewer's width and height, as without it the viewer may not display correctly.
Setting the values to empty strings is valid, as long as you style the canvas through other means.

ℹ️ Note:
This package only targets recent versions of browsers.
Expand Down
4 changes: 3 additions & 1 deletion rerun_js/web-viewer-react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class WebViewer extends React.Component {
const current = /** @type {HTMLDivElement} */ (this.#parent.current);
this.#handle.start(this.#recordings, current, {
hide_welcome_screen: this.#hide_welcome_screen,
width: "100%",
height: "100%",
});
}

Expand All @@ -61,7 +63,7 @@ export default class WebViewer extends React.Component {
}

render() {
const { width = "100%", height = "640px" } = this.props;
const { width = "640px", height = "360px" } = this.props;
return React.createElement("div", {
className: "rerun-web-viewer",
style: { width, height, position: "relative" },
Expand Down
6 changes: 5 additions & 1 deletion rerun_js/web-viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const rrd = "…";
const parentElement = document.body;

const viewer = new WebViewer();
await viewer.start(rrd, parentElement);
await viewer.start(rrd, parentElement, { width: "800px", height: "600px" });
// …
viewer.stop();
```
Expand All @@ -45,6 +45,10 @@ The `rrd` in the snippet above should be a URL pointing to either:
- A WebSocket connection to the SDK opened via the [`serve`](https://www.rerun.io/docs/reference/sdk-operating-modes#serve) API

If `rrd` is not set, the Viewer will display the same welcome screen as <https://app.rerun.io>.
This can be disabled by setting `hide_welcome_screen` to `true` in the options object of `viewer.start`.

⚠ It's important to set the viewer's width and height, as without it the viewer may not display correctly.
Setting the values to empty strings is valid, as long as you style the canvas through other means.

For a full example, see https://github.com/rerun-io/web-viewer-example.
You can open the example via CodeSandbox: https://codesandbox.io/s/github/rerun-io/web-viewer-example
Expand Down
5 changes: 5 additions & 0 deletions rerun_js/web-viewer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ interface WebViewerOptions {
render_backend?: Backend;
hide_welcome_screen?: boolean;
allow_fullscreen?: boolean;

width?: string;
height?: string;
}

interface FullscreenOptions {
Expand Down Expand Up @@ -107,6 +110,8 @@ export class WebViewer {
this.#state = "starting";

this.#canvas = document.createElement("canvas");
this.#canvas.style.width = options.width ?? "640px";
this.#canvas.style.height = options.height ?? "360px";
this.#canvas.id = this.#id;
parent.append(this.#canvas);

Expand Down
Loading