Skip to content

Render a trace as an interactive Gantt chart with plotly - #406

Merged
Paebbels merged 7 commits into
devfrom
claude/tracing-plotly-renderer
Oct 25, 2026
Merged

Paebbels merged 7 commits into
devfrom
claude/tracing-plotly-renderer

Conversation

@pytooling-claude

@pytooling-claude pytooling-claude Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Note

Rebased onto dev (#405 is merged). GanttLayout.Duration is a timedelta there, so the renderer reads DurationInSeconds (b8a5b50); doc/Dependency.rst renders the diagram extra with dependency-table already.

Ported onto dev. #404 merged as a renderer class, so the plotly renderer is now PlotlyRenderer(Renderer[Figure]) instead of the functions RenderGantt/WriteGantt. The legend functions the first version moved into pyTooling.Tracing.Render are already there as Renderer's methods, so that part is gone from this pull-request.

A chart of a big pipeline is hard to navigate as a static image: GHDL's master pipeline has 209 rows without steps and 1575 with the executed ones. This pull-request adds a second renderer, based on plotly, which writes the same Gantt chart as an interactive HTML page - zoomable, with hover texts and a legend that hides or shows categories.

New Features

  • pyTooling.Tracing.Render.Plotly.PlotlyRenderer
    • PlotlyRenderer(layout, *, title, width, rowHeight, fontSize, includePlotlyJS) draws a GanttLayout with the same rows as the matplotlib renderer: labels indented by depth, the pipeline and called workflows as lines (dashed while running), jobs as bars colored by category, waiting bars in light gray, running bars hatched, and very short bars widened to a visible minimum.
    • The chart can be zoomed and panned. Hovering a bar or line shows the timespan's name, its absolute begin and end with time zone, its duration, and its category or state. A click on a legend entry hides or shows a category's bars.
    • Colors, title and legend come from the Renderer base-class, so the legend shows the same statistics as the matplotlib chart: started and finished, wall time, runner time, and per category the number of jobs with minimum, average and maximum waiting and running times.
    • The time axis is a date axis starting at TIME_AXIS_ORIGIN (1970-01-01): its ticks show the time since the trace began as hh:mm:ss and adapt when zooming.
    • Write(file) writes an HTML page (.html) or plotly's JSON (.json), see FORMATS. includePlotlyJS takes a PlotlyJavaScript: Embedded (the default) embeds plotly's JavaScript library (about 4 MiB), so the page works offline, e.g. downloaded from a pipeline's artifacts; CDN loads it from plotly's CDN.
    • Every parameter is checked: None → ValueError, type → TypeError, a non-positive size → ValueError.
    • Names are escaped (&, <, > by str.replace), because plotly interprets HTML tags like <b> in titles, labels and hover texts.
  • pyTooling.Tracing.Render.Plotly.PlotlyJavaScript - a StringEnum of how an HTML page loads plotly's JavaScript library.
  • pyTooling.Tracing.Render.QUEUED_LEGEND_LABEL - waiting for a runner - joins LINE_LEGEND_LABEL, and both renderers use it.
  • pyTooling.Tracing.Render.Matplotlib.MatplotlibRenderer checks every parameter of its constructor the same way (width, rowHeight and fontSize in one loop); it checked only that width, rowHeight, fontSize and dpi are positive, and fontFamilies, legendLocation, collapsible and collapsedKinds not at all.
  • The extra pyTooling[diagram] installs plotly >= 6.0 in addition to matplotlib. MSYS2 needs no pacboy mapping: plotly is pure Python and installs from PyPI there.

Documentation

  • doc/Tracing.rst gains a section Interactive HTML, and the matplotlib paragraph points to it.
  • doc/News.rst lists the plotly renderer.
  • doc/Glossary.rst gains the terms matplotlib and plotly - :term:matplotlib`` was used since Render a trace as a Gantt chart with matplotlib #404 without an entry.

Unit Tests

  • tests/unit/Tracing/Render.py:
    • Legend, 3 testcases: Renderer.FormatSeconds, Renderer.FormatTime, and a legend title and label whose columns align - through a renderer drawing nothing, so they run without matplotlib or plotly.
    • Plotly, 13 testcases: the figure's title, rows, legend and time axis; bar positions, lengths, hover fields, the waiting bar on the job's row and the hatched running bar; solid and dashed lines; escaping; an HTML page with embedded and with CDN-loaded library; JSON; the errors for an unsupported suffix, a wrong file type and a wrong layout type; and every check of width, rowHeight, fontSize and includePlotlyJS.
    • Matplotlib.test_ParameterChecks: the new checks of MatplotlibRenderer's parameters.
  • tests/unit/requirements.txt adds plotly >= 6.0.

HTML pages were also generated from real runs - pyTooling/Actions run 34937615362 and ghdl/ghdl run 34887302325, each without steps and with the executed steps.

Known Issues

  • For a trace longer than a day, the time axis starts again at 00:00:00.
  • Rows can't be collapsed as in the collapsible SVG of Write a collapsible Gantt chart as SVG #405; the legend hides categories, not sub-rows.
  • No static SVG or PNG from plotly: that needs kaleido, which isn't a dependency. The matplotlib renderer writes static files.
  • Tested with plotly 7.1.0; the lower bound 6.0 wasn't tested.

Related Issues and Pull-Requests

@pytooling-claude pytooling-claude Bot added this to the v10.1 milestone Sep 15, 2026
@pytooling-claude pytooling-claude Bot added Documentation Improvements or additions to documentation Feature Request Unit Tests Tracing pyTooling.Tracing - Software execution tracing. labels Sep 15, 2026
@codacy-production

codacy-production Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 4 minor

Alerts:
⚠ 4 issues (≤ 0 issues of at least minor severity)

Results:
4 new issues

Category Results
Documentation 4 minor

View in Codacy

🟢 Metrics 86 complexity · 0 duplication

Metric Results
Complexity 86
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.59%. Comparing base (2a43ca9) to head (a3fbc45).
⚠️ Report is 11 commits behind head on dev.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
pyTooling/Tracing/Render/Matplotlib.py 77.04% 8 Missing and 6 partials ⚠️
pyTooling/Tracing/Render/Plotly.py 98.52% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #406      +/-   ##
==========================================
+ Coverage   89.53%   89.59%   +0.06%     
==========================================
  Files          63       64       +1     
  Lines       16809    16999     +190     
  Branches     2581     2620      +39     
==========================================
+ Hits        15050    15231     +181     
- Misses       1341     1345       +4     
- Partials      418      423       +5     
Flag Coverage Δ
unittests 89.59% <92.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch from 52b108d to 51f9842 Compare September 19, 2026 00:10
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch from 6a78597 to 8c524f1 Compare September 19, 2026 00:10
@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch from 51f9842 to 024a917 Compare September 19, 2026 08:40
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch from 8c524f1 to 2298ac8 Compare September 19, 2026 08:41
@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch 2 times, most recently from af5698a to 40fff2d Compare September 19, 2026 09:15
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch 2 times, most recently from 48cea1d to 3e6ee1d Compare September 19, 2026 09:17
@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch from 40fff2d to 62493ac Compare September 19, 2026 12:04
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch 2 times, most recently from ff24b14 to e26a301 Compare September 19, 2026 12:18
@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch 2 times, most recently from 4a7bbe7 to b3168a2 Compare September 19, 2026 13:22
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch from e26a301 to 0140633 Compare September 19, 2026 13:22
@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch from b3168a2 to f48c306 Compare September 19, 2026 14:09
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch from 0140633 to 193df3c Compare September 19, 2026 14:09
@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch from f48c306 to e5560d1 Compare September 19, 2026 14:31
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch 2 times, most recently from 40d9730 to 9fccd99 Compare September 19, 2026 14:42
@Paebbels
Paebbels force-pushed the claude/tracing-collapsible-svg branch from e5560d1 to 149adf5 Compare September 19, 2026 14:42
@Paebbels
Paebbels force-pushed the claude/tracing-plotly-renderer branch from 9fccd99 to 808edbe Compare September 19, 2026 15:30
Comment thread doc/Dependency.rst Resolved
Comment thread pyTooling/Tracing/Render/Plotly.py Resolved
Comment thread pyTooling/Tracing/Render/Plotly.py Resolved
Comment thread pyTooling/Tracing/Render/Plotly.py Resolved
Comment thread pyTooling/Tracing/Render/Plotly.py Resolved
claude-code and others added 4 commits October 25, 2026 17:53
PlotlyRenderer draws a GanttLayout with plotly and writes it as an HTML page or as plotly's JSON: zoomable, with
hover texts and legend entries hiding a category's bars. It takes the colors and the legend's text from the Renderer
base-class, so both renderers show the same statistics; 'waiting for a runner' becomes QUEUED_LEGEND_LABEL next to
LINE_LEGEND_LABEL. plotly joins the extra 'pyTooling[diagram]'; the glossary gains 'matplotlib', which was already
referenced, and 'plotly'.

Ported onto the renderer class of #404: RenderGantt/WriteGantt became PlotlyRenderer.Render/Write, and the legend
functions of the first version are the base-class' methods now, tested through a renderer drawing nothing.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
…tionInSeconds'.

'GanttLayout.Duration' is a timedelta on dev.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
…tring replacement for escaping.

Review:
- '_text', '_preformatted' and '_time' are the static methods '_EscapeText', '_Preformatted' and '_TimeAxisPosition'.
- Each parameter is checked in its own chain: None -> ValueError, type -> TypeError, value -> ValueError. The loop
  over (name, value) pairs checked no type, so 'width="800"' failed with a TypeError of the '>' operator.
- Escaping with 'str.replace' instead of 'html.escape': 'import html' costs 5-6 ms (cumulative, with
  'html.entities'); a call is 11-25 % faster (24 characters: 136 -> 103 ns on 3.15, 143 -> 109 ns on 3.13).
- 'includePlotlyJS' takes the new 'PlotlyJavaScript' enumeration (Embedded, CDN, DEFAULT) instead of 'True'/'cdn'.
- Rules: no composed tuple assignments in 'Render', aligned assignment runs, one import statement and column, the
  non-breaking space written as '\u00a0', ASCII copyright line, the file written with 'open'.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Review (same pattern as in PlotlyRenderer): the loop over (name, value) pairs checked only that a value is
positive. Every parameter is checked in its own chain now - None -> ValueError, type -> TypeError, value ->
ValueError - including 'fontFamilies', 'legendLocation', 'collapsible' and 'collapsedKinds', which weren't checked.
':raises:' has one field per condition.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Comment thread pyTooling/Tracing/Render/Matplotlib.py Resolved
Comment thread pyTooling/Tracing/Render/Plotly.py Resolved
Comment thread pyTooling/Tracing/Render/Plotly.py Resolved
…der an outer 'if'

Patrick, on both renderers:

* MatplotlibRenderer: 'width', 'rowHeight' and 'fontSize' had three copies of
  the same chain (None, 'float' or 'int', positive). They are checked in one
  loop over '(name, value)' pairs, as in pyEDAA.Reports' LLVM 'Segment', and
  the ':raises:' fields name the three parameters per condition.
* PlotlyRenderer: the nullable 'width' is checked under an outer
  'if width is not None:'. 'rowHeight' and 'fontSize' share a loop; for that,
  'rowHeight' accepts a 'float' as well (default '20.0'), like 'fontSize' and
  like all three sizes of the matplotlib renderer. Plotly takes a fractional
  pixel height.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Comment thread pyTooling/Tracing/Render/Matplotlib.py Resolved
…n a loop

Patrick: a loop shares the code, not the documentation. 'width', 'rowHeight'
and 'fontSize' (MatplotlibRenderer) and 'rowHeight' and 'fontSize'
(PlotlyRenderer) get their three fields each again.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Comment thread pyTooling/Tracing/Render/Plotly.py Resolved
Patrick: a3fbc45 widened 'rowHeight' to 'float' only to let it share a loop with
'fontSize' - a type changed for the sake of the checks. It is an 'int' again
(default '20'), checked in its own chain; 'fontSize' keeps its own chain too,
as both differ in type. The outer 'if width is not None:' stays.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Feature Request Tracing pyTooling.Tracing - Software execution tracing. Unit Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants