Skip to content

Add interactive layer stack diagram to docs - #233

Open
jackgdsf wants to merge 1 commit into
gdsfactory:mainfrom
jackgdsf:add-layer-stack-docs
Open

Add interactive layer stack diagram to docs#233
jackgdsf wants to merge 1 commit into
gdsfactory:mainfrom
jackgdsf:add-layer-stack-docs

Conversation

@jackgdsf

@jackgdsf jackgdsf commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds .github/write_layer_stack.py that generates docs/layer_stack.md with interactive SVG/JS visualizations
  • Layer Stack diagram with Uniform/To Scale toggle
  • Cross-Section diagram showing waveguide profiles
  • Interactive: hover tooltips, Ctrl+scroll zoom, drag pan, double-click reset
  • Integrated into make docs
  • Nav updated in docs config

Closes #232

Reminder

⚠️ AI-created PR — requires human review of the actual code changes before merge.

Test plan

  • Run make docs locally and verify docs/layer_stack.md is generated
  • Open the built docs and check the Layer Stack page renders correctly
  • Verify layer stack and cross-section diagrams display correctly
  • Test Uniform/To Scale toggle, tooltips, pan+zoom
  • Verify CI passes

🤖 Generated with Claude Code

Summary by Sourcery

Generate an interactive layer stack documentation page and integrate it into the docs build.

New Features:

  • Add a script to generate docs/layer_stack.md with interactive SVG-based layer stack and cross-section visualizations from the PDK.
  • Expose a new Layer Stack page in the documentation navigation.

Build:

  • Hook the layer stack generation script into docs-related Makefile targets so it runs during docs builds.

Add .github/write_layer_stack.py that generates docs/layer_stack.md
with interactive SVG/JS visualizations of the layer stack and
cross-sections.

Features: Uniform/To Scale toggle, cross-section profiles, tooltips,
pan+zoom. Runs during `make docs`.

Closes gdsfactory#232

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@sourcery-ai

sourcery-ai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a generated, interactive layer stack documentation page wired into the docs build, including SVG/JS visualizations of PDK layers and cross-sections, plus navigation updates.

Flow diagram for generating interactive layer_stack.md in docs build

flowchart LR
  A[make docs / docs-pdf / docs-serve] --> B[uv run python .github/write_layer_stack.py]
  B --> C[main]
  C --> D[PDK.activate]
  C --> E[_extract_layers]
  E --> F[_compute_layout]
  C --> G[_extract_cross_sections]
  F --> H[_render_layer_stack]
  G --> I[_render_cross_sections]
  H --> J[assemble Markdown content]
  I --> J
  J --> K[write docs/layer_stack.md]
  K --> L[mkdocs / zensical build]
Loading

File-Level Changes

Change Details Files
Introduce script to generate interactive layer stack and cross-section visualizations into docs/layer_stack.md from the PDK layer_stack and cross_sections.
  • Add .github/write_layer_stack.py that queries PDK.layer_stack and PDK.cross_sections, computes layout info, and emits a markdown file with embedded SVG and inline JS for interactive visuals.
  • Implement helper functions for material color selection, layer-type inference, GDS layer extraction, nice tick step calculation, and cross-section data resolution.
  • Render two main visualizations: a layer stack diagram with Uniform vs To Scale layout modes and a cross-section diagram showing waveguide profiles, both with hover tooltips, pan/zoom, and reset behaviors.
.github/write_layer_stack.py
Integrate auto-generation of docs/layer_stack.md into the docs build and expose it in navigation.
  • Hook write_layer_stack.py into docs, docs-pdf, and docs-serve Makefile targets so docs/layer_stack.md is produced before building or serving docs.
  • Add a Layer Stack entry to docs/zensical.toml navigation pointing at layer_stack.md.
Makefile
docs/zensical.toml

Assessment against linked issues

Issue Objective Addressed Explanation
#232 Create an interactive docs page layer_stack.md with SVG/JS visualizations of the layer stack and waveguide cross-sections, including Uniform/To Scale toggle, tooltips (GDS, material, z-range, thickness), and pan/zoom interactions.
#232 Integrate generation of layer_stack.md into the documentation build pipeline and expose it in the docs navigation.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • The zoom/pan and tooltip logic is duplicated between the layer-stack and cross-section SVGs; consider extracting this into a small reusable JS helper or shared snippet to reduce repetition and keep future behavior changes in one place.
  • The Makefile currently runs .github/write_layer_stack.py separately for docs, docs-pdf, and docs-serve; you could instead factor this into a single phony target (e.g. layer-stack) that all three depend on to avoid duplication and keep the doc-generation pipeline easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The zoom/pan and tooltip logic is duplicated between the layer-stack and cross-section SVGs; consider extracting this into a small reusable JS helper or shared snippet to reduce repetition and keep future behavior changes in one place.
- The Makefile currently runs `.github/write_layer_stack.py` separately for `docs`, `docs-pdf`, and `docs-serve`; you could instead factor this into a single phony target (e.g. `layer-stack`) that all three depend on to avoid duplication and keep the doc-generation pipeline easier to maintain.

## Individual Comments

### Comment 1
<location path=".github/write_layer_stack.py" line_range="264-273" />
<code_context>
+    d = json.dumps(layers, separators=(",", ": "))
</code_context>
<issue_to_address>
**🚨 issue (security):** Escape JSON when embedding into inline <script> blocks to avoid '</script>' breakage or XSS edge cases.

Since this JSON is embedded directly into a `<script>` block (e.g. `const data={d}`), it should be escaped to avoid prematurely closing the script with sequences like `</script>` and to reduce XSS risk if these values ever become user-controlled. Consider wrapping `json.dumps` with a helper that post-processes the output (for example, `json.dumps(...).replace('</', '<\/')`).
</issue_to_address>

### Comment 2
<location path=".github/write_layer_stack.py" line_range="334-335" />
<code_context>
+  gL.addEventListener("mousemove",e=>{{
+    const g=e.target.closest("g[data-idx]");if(!g){{tip.style.display="none";return}}
+    const d=data[+g.dataset.idx];
+    tip.innerHTML=`<b>${{d.name}}</b><br>GDS: ${{d.gds??"N/A"}}<br>Material: ${{d.material}}<br>Type: ${{d.type}}<br>z: ${{d.zmin}}–${{d.zmax}} µm<br>Thickness: ${{d.thickness}} µm`;
+    const r=root.getBoundingClientRect();tip.style.display="block";
+    tip.style.left=(e.clientX-r.left+12)+"px";tip.style.top=(e.clientY-r.top+12)+"px";
+  }});
</code_context>
<issue_to_address>
**🚨 issue (security):** Avoid directly injecting unescaped data into innerHTML for tooltips.

`tip.innerHTML` is built from raw `d.name`, `d.material`, etc. If these ever contain `<`, `&`, or other HTML, the tooltip can be malformed or expose HTML injection/XSS risk. Please either escape these values before concatenation or build the tooltip via DOM APIs (using `textContent` for text nodes) to avoid relying on HTML parsing.
</issue_to_address>

### Comment 3
<location path=".github/write_layer_stack.py" line_range="466-335" />
<code_context>
+  root.querySelector("svg").addEventListener("mousemove",e=>{{
+    const g=e.target.closest("g[data-idx]");if(!g){{tip.style.display="none";return}}
+    const d=data[+g.dataset.idx];
+    tip.innerHTML=`<b>${{d.name}}</b><br>Material: ${{d.material}}${{d.width!=null?`<br>Width: ${{d.width}} µm`:""}}<br>GDS: ${{d.gds??"N/A"}}<br>z: ${{d.zmin}}–${{d.zmax}} µm<br>Thickness: ${{d.thickness}} µm`;
+    const r=root.getBoundingClientRect();tip.style.display="block";
+    tip.style.left=(e.clientX-r.left+12)+"px";tip.style.top=(e.clientY-r.top+12)+"px";
+  }});
</code_context>
<issue_to_address>
**🚨 issue (security):** Apply the same HTML-escaping considerations to cross-section tooltips.

This tooltip also sets `innerHTML` from raw `d.name` / `d.material`. For consistency and to avoid XSS-style issues, please escape these values or construct the tooltip via DOM nodes using `textContent` instead.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +264 to +273
d = json.dumps(layers, separators=(",", ": "))
t = json.dumps(ticks, separators=(",", ": "))
m = json.dumps(margin, separators=(",", ": "))

return f'''<div id="{svg_id}" style="position:relative;display:inline-block;font-family:system-ui,sans-serif;padding:10px 10px 40px 10px">
<div style="margin-bottom:6px">
<button class="sv-btn" data-mode="uniform" style="font-size:12px;padding:3px 10px;cursor:pointer;border:1px solid #aaa;border-radius:3px;background:#e0e0e0">Uniform</button>
<button class="sv-btn" data-mode="scale" style="font-size:12px;padding:3px 10px;cursor:pointer;border:1px solid #aaa;border-radius:3px;background:#fff;margin-left:4px">To Scale</button>
</div>
<svg width="{svg_w}" height="{svg_h}" xmlns="http://www.w3.org/2000/svg" font-family="system-ui,sans-serif" font-size="11">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Escape JSON when embedding into inline <script> blocks to avoid '</script>' breakage or XSS edge cases.

Since this JSON is embedded directly into a <script> block (e.g. const data={d}), it should be escaped to avoid prematurely closing the script with sequences like </script> and to reduce XSS risk if these values ever become user-controlled. Consider wrapping json.dumps with a helper that post-processes the output (for example, json.dumps(...).replace('</', '<\/')).

Comment on lines +334 to +335
tip.innerHTML=`<b>${{d.name}}</b><br>GDS: ${{d.gds??"N/A"}}<br>Material: ${{d.material}}<br>Type: ${{d.type}}<br>z: ${{d.zmin}}–${{d.zmax}} µm<br>Thickness: ${{d.thickness}} µm`;
const r=root.getBoundingClientRect();tip.style.display="block";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Avoid directly injecting unescaped data into innerHTML for tooltips.

tip.innerHTML is built from raw d.name, d.material, etc. If these ever contain <, &, or other HTML, the tooltip can be malformed or expose HTML injection/XSS risk. Please either escape these values before concatenation or build the tooltip via DOM APIs (using textContent for text nodes) to avoid relying on HTML parsing.

const g=e.target.closest("g[data-idx]");if(!g){{tip.style.display="none";return}}
const d=data[+g.dataset.idx];
tip.innerHTML=`<b>${{d.name}}</b><br>GDS: ${{d.gds??"N/A"}}<br>Material: ${{d.material}}<br>Type: ${{d.type}}<br>z: ${{d.zmin}}–${{d.zmax}} µm<br>Thickness: ${{d.thickness}} µm`;
const r=root.getBoundingClientRect();tip.style.display="block";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Apply the same HTML-escaping considerations to cross-section tooltips.

This tooltip also sets innerHTML from raw d.name / d.material. For consistency and to avoid XSS-style issues, please escape these values or construct the tooltip via DOM nodes using textContent instead.

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.

Add interactive layer stack cross-section diagram to docs

1 participant