Skip to content

Conversation

@peter-gy
Copy link
Owner

@peter-gy peter-gy commented Apr 22, 2025

Enables usage such as:

%%d2 themeID=200
direction: right
x -> y { style.animated: true }
y -> z { style.animated: true }
z -> x { style.animated: true }
CleanShot.2025-04-22.at.14.11.45.mp4

@peter-gy peter-gy requested a review from Copilot April 22, 2025 11:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces support for using the D2 widget as an IPython extension by renaming the core widget to Widget and adding cell magic functionality. Key changes include:

  • Moving and renaming the widget class from D2Widget to Widget and updating all references.
  • Adding load/unload functions to register a new IPython cell magic command.
  • Updating project metadata and documentation to reflect these changes.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/d2_widget/_widget.py Added a new widget implementation wrapped around anywidget for D2 diagrams.
src/d2_widget/_version.py Provides version metadata using importlib.metadata.
src/d2_widget/_model.py Defines typed dictionaries for render and compile options for D2 diagrams.
src/d2_widget/init.py Reorganizes public API, removes the old D2Widget, and introduces IPython magic.
pyproject.toml Updates dependencies and minimum Python requirement to >=3.9.
example.ipynb Updates notebook examples to reflect the new Widget naming.
README.md Updates documentation examples to reference Widget instead of D2Widget.

@peter-gy peter-gy changed the title feat: support usage as IPython extension feat: support usage via %%d2 IPython cell magic Apr 22, 2025
@peter-gy peter-gy requested a review from Copilot April 22, 2025 12:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables users to render D2 diagrams using the new IPython cell magic (%%d2) and updates the API by renaming D2Widget to Widget. It also updates documentation, examples, and project configuration to reflect these changes.

  • Added a Widget class in _widget.py that wraps D2 diagram rendering for notebook environments.
  • Integrated an IPython cell magic in init.py to support usage via %%d2, updating the API and examples accordingly.
  • Updated project metadata (pyproject.toml), examples, and README documentation to align with the new API.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/d2_widget/_widget.py New Widget class implementation with traits support
src/d2_widget/_version.py Added version detection via importlib.metadata
src/d2_widget/_utils.py Utility function parse_magic_arguments for cell magic
src/d2_widget/_model.py Definitions for CompileOptions & RenderOptions
src/d2_widget/init.py Registration of IPython cell magic and API updates
pyproject.toml Dependency and Python version updates
example.ipynb Updated usage examples from D2Widget to Widget
README.md Documentation modifications to reflect Widget usage

@peter-gy peter-gy requested a review from Copilot April 22, 2025 13:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables support for using D2 diagram rendering via the IPython cell magic (%%d2) and unifies the widget API by renaming D2Widget to Widget. Key changes include:

  • Introduction of a new cell magic registration in init.py.
  • Renaming of D2Widget to Widget across the codebase, notebook examples, and documentation.
  • Minor adjustments in dependency requirements and Python version support.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/d2_widget/_widget.py Introduces Widget with default compile options and diagram rendering.
src/d2_widget/_version.py Provides versioning using importlib.metadata.
src/d2_widget/_utils.py Adds a function to parse IPython magic arguments.
src/d2_widget/_model.py Defines type-safe rendering and compile options.
src/d2_widget/init.py Registers the %%d2 cell magic and renames D2Widget to Widget.
pyproject.toml Updates dependency management and required Python version.
example.ipynb Updates usage examples to use the new Widget naming and cell magic support.
README.md Revises examples and documentation to reflect the Widget changes.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@peter-gy peter-gy requested a review from Copilot April 22, 2025 13:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for using D2 diagrams via an IPython cell magic by introducing the new Widget class and related utilities. Key changes include the implementation of the Widget class for rendering diagrams, the addition of the %%d2 cell magic registration and deregistration, and updates to documentation, examples, and project configuration.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/d2_widget/_widget.py New Widget class wrapping anywidget for D2 output.
src/d2_widget/_version.py Version extraction via importlib.metadata.
src/d2_widget/_utils.py Utility function for parsing magic arguments.
src/d2_widget/_model.py TypedDict definitions for compile and render options.
src/d2_widget/init.py Registration of cell magic and module re-exports.
pyproject.toml Updated Python requirement and dependency versions.
example.ipynb Updated example to use Widget and demonstrate %%d2 support.
README.md Documentation updated to reflect the new Widget and cell magic.

@peter-gy peter-gy merged commit fd27a40 into main Apr 22, 2025
2 checks passed
@peter-gy peter-gy deleted the feat/support-ipython-extension branch April 22, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants