Skip to content

Commit

Permalink
Add set_height method to set the height of the iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
j9ac9k committed Jan 13, 2025
1 parent 56d98c3 commit 437a9fb
Show file tree
Hide file tree
Showing 6 changed files with 969 additions and 865 deletions.
2 changes: 1 addition & 1 deletion eptium/nbextension/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion eptium/nbextension/index.js.map

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions eptium/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,42 @@ class Eptium(DOMWidget, ValueWidget):

# read-write attributes
src = Unicode('https://viewer.copc.io').tag(sync=True)
height = Unicode('400px').tag(sync=True)

def __init__(
self,
src="https://viewer.copc.io",
):
super().__init__()
self.src = src
self.height

def set_height(self, value: int | str):
"""Set the height of the Eptium View
Parameters
----------
value : int | str
Accepted values are used to set the ``height`` attribute
of an iframe.
Examples
--------
>>> widget.set_height('200px')
"""
if isinstance(value, int):
value = str(value)
self.height = value

def render(self, path: str | pathlib.Path):
"""Method to call to generate the Eptium View
Parameters
----------
path : str | pathlib.Path
Path to the asset that Eptium should display. Acceptable
values include local file paths, or URLs to
"""
if isinstance(path, pathlib.Path):
# not using os.fsdecode since we want forward-slashes
# even on windows
Expand Down
69 changes: 69 additions & 0 deletions examples/introduction.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import eptium"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8eece08bcb794136ae4749c6759ff79c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Eptium(value=None, height='200px', src='https://viewer.copc.io/?q=https://s3.amazonaws.com/hobu-lidar/autzen-c…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = eptium.Eptium()\n",
"w.render(\"https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz\")\n",
"w.set_height('200px')\n",
"w"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
10 changes: 9 additions & 1 deletion src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ export class EptiumView extends DOMWidgetView {
render() {
this._iframe = document.createElement('iframe');
this._iframe.width = '100%';
this._iframe.height = '400';
this._iframe.style.boxSizing = 'border-box';

// Get the right right
this._onHeightChanged();

// this.el is the DOM element associated with the view
this.el.appendChild(this._iframe);
this._onSrcChanged();

// Python -> TypeScript update
this.model.on('change:src', this._onSrcChanged, this);
this.model.on('change:height', this._onHeightChanged, this);
}

private _onSrcChanged() {
Expand All @@ -62,4 +65,9 @@ export class EptiumView extends DOMWidgetView {
this._iframe.src = resolvedUrl;
});
}

private _onHeightChanged() {
const height = this.model.get('height');
this._iframe.height = height;
}
}
Loading

0 comments on commit 437a9fb

Please sign in to comment.