Skip to main content

Draw, highlight, and erase annotations directly on JupyterLab notebook cells.

Project description

🖊️ Jupyter Annotation Tool for JupyterLab

Jupyter Annotation Tool (ipynbd) lets you draw annotations directly on top of notebook cells — using your mouse or stylus (including Apple Pencil).
It’s designed for teaching, demos, and visual note-taking inside .ipynb notebooks, while keeping all drawings stored in notebook metadata.

teaser


🚀 Current Status

Working features:

  • The extension installs successfully as a federated JupyterLab 4 plugin.
  • Adds a “Draw (cell)” button to the notebook toolbar.
  • Clicking the button toggles a canvas overlay for the active cell, where drawings are rendered.
  • Drawings persist in the notebook under cell.metadata.overlay_v1.
  • Fully integrated with JupyterLab’s reactive layout (auto-resizes with cells, supports zoom, dark mode, etc.).

🧩 Upcoming / In progress:

  • Persistent per-cell draw toggle and global “annotation mode”.
  • Better and more intuitive scaling/translation as cell dimensions change
  • Undo-redo stack
  • Annotation selection and moving
  • Pressure sensitivity
  • Exportable to PDF/HTML
  • Generally Better UI/UX
  • Integration beyond Jupyterlab (primarily vscode)
  • Live annotation in shared sessions
  • Annotation layers
  • Auto-theme color sync
  • Optional cell grid/line/dot underlays

🧠 Project Overview

This extension adds a thin, high-Z-index <canvas> to each cell’s DOM tree:

<div class="jp-Cell-content">
  ... existing cell content ...
  <canvas data-overlay="1" style="position:absolute; inset:0; z-index:1000"></canvas>
</div>

Each drawing is recorded as an array of normalized strokes:

{
  "overlay_v1": {
    "strokes": [
      {
        "tool": "pen",
        "color": "#ffffff",
        "width": 0.003,
        "points": [[0.12, 0.45], [0.13, 0.46], ...]
      }
    ]
  }
}

Normalization (0–1) means the drawing scales with cell size on resize or zoom.
On load, ResizeObserver re-renders from metadata.


📥 Installation

# Install the federated extension (Python + front-end assets)
pip install jupyter-annotation-tool-ipynbd

# (Optional) install straight from npm if you prefer front-end only
jupyter labextension install jupyter-annotation-tool-ipynbd
# For contributors: link your local checkout instead of installing from PyPI
pip install -e .

Prerequisites

  • Node.js ≥ 18
  • Python ≥ 3.10
  • JupyterLab ≥ 4.0

Create a virtual environment

python -m venv jlab-env
source jlab-env/bin/activate

Install dependencies

npm install
pip install -e .

Build & reload into JupyterLab

Use the provided build.sh script:

#!/bin/bash
set -e
echo "🔧 Building jupyter-annotation-tool-ipynbd..."
npm run build
pip install -e .
jupyter lab build
echo "✅ Done! Reload JupyterLab (Shift-Reload)."

Or manually:

npm run build && pip install -e . && jupyter lab build

Launch JupyterLab

jupyter lab

Then open your browser (e.g. http://localhost:8888/lab).


🧩 Code Structure

jupyter_annotation_tool_ipynbd/
├── src/
│   └── index.ts          # Main plugin logic (toolbar button, overlay system)
├── lib/                  # Compiled JS output
├── labextension/         # Federated build bundle for JupyterLab
├── package.json          # JS build + labextension metadata
├── pyproject.toml        # Python packaging (for pip install)
├── tsconfig.json         # TypeScript config
├── install.json          # JupyterLab manifest
└── build.sh              # Handy rebuild script

🧰 Technical Details

Event flow

  1. Clicking Draw (cell) toggles the overlay’s pointerEvents for the active cell.
  2. Pointer events (pointerdown, pointermove, pointerup) collect normalized stroke points.
  3. Strokes are rendered via 2D Canvas API and saved to cell metadata.
  4. On notebook reload or resize, metadata is re-drawn automatically.

TypeScript interfaces

type Stroke = {
  tool: 'pen' | 'highlighter';
  color: string;
  width: number;
  alpha?: number;
  points: [number, number][];
};

🧪 Debugging

To verify the plugin loads:

  1. Open DevTools → Console in JupyterLab.
  2. Look for:
    [jupyter-annotation-tool-ipynbd] plugin activate
    
  3. Toggle the button and confirm:
    [overlay] draw mode ON for active cell
    [overlay] pointerdown 123 456
    

If you see these logs, the extension is active and capturing input.


🧭 Roadmap

Feature Status Notes
Notebook toolbar button Working
Per-cell toolbar pen icon 🧩 In progress Right-aligned next to delete
Color picker / width selector 🧩 Planned Popover interface
Eraser / Undo / Clear 🧩 Planned Non-destructive metadata ops
Pencil support on iPad touchAction: 'none' ready
Global draw toggle 🧩 Planned One-click mode for all cells

🧑‍💻 Author

Created by William Theisen
Built for interactive teaching, annotation, and in-class demonstration notebooks.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyter_annotation_tool_ipynbd-0.1.5.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyter_annotation_tool_ipynbd-0.1.5-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_annotation_tool_ipynbd-0.1.5.tar.gz.

File metadata

File hashes

Hashes for jupyter_annotation_tool_ipynbd-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5ba1a406107cf1b3b20c3f6bb80fcc7d4babca066240372737621d1686afbc47
MD5 67626ea7ba30ee3301ed98a6c96ecd63
BLAKE2b-256 c7ef63113e05aad74d0cd8d104af8c85f4260e076e4be02e0e3d5fbd4f9780da

See more details on using hashes here.

File details

Details for the file jupyter_annotation_tool_ipynbd-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyter_annotation_tool_ipynbd-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b34eb806a07cc33b5436075dc344b2ac65e9dda5c7f41f6248b1af14a494b19c
MD5 b2ebaa628690ab0eec3e9fb91e50a980
BLAKE2b-256 81669d18a095f24158ddd8f745006205bd902b61b54dc2b5f09ad2ce888deb28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page