feat: add Chart.js-powered data chart layouts + cohort retention heatmap - #48
Merged
Conversation
Adds 11 new layouts for data-driven graphics: line, bar, grouped bar, horizontal bar, stacked bar, grouped stacked bar, stacked area, pie, donut, sankey, and a Mixpanel-style cohort retention heatmap. Chart.js v4 and chartjs-chart-sankey are vendored under modern_graphics/assets/vendor so PNG export works offline. Playwright waits on window.__chartReady (set in the animation.onComplete hook) before screenshotting so canvases finish rendering. CLI gains --labels, --series-json, --links-json, --cohorts-json, --nodes, --period-labels, --subtitle, --x-label, --y-label, --no-legend. JSON flags accept inline strings or @path/to/file.json. MCP and suggest_layout auto-discover the new layouts via the registry. README and docs/DIAGRAM_TYPES.md updated with galleries and CLI recipes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
line-chart,bar-chart,grouped-bar-chart,horizontal-bar-chart,stacked-bar-chart,grouped-stacked-bar-chart,stacked-area-chart,pie-chart,donut-chart,sankey-chart, and a Mixpanel-stylecohort-chartretention heatmap.modern_graphics/assets/vendor/so PNG export works offline with no network dependency.export.pywaits onwindow.__chartReady(set by Chart.jsanimation.onComplete) before capturing a screenshot.--labels,--series-json,--links-json,--cohorts-json,--nodes,--period-labels,--subtitle,--x-label,--y-label,--no-legend. JSON flags accept inline strings or@path/to/file.json.suggest_layoutautomatically pick up the new layouts via the registry;generate_graphic's description is updated with per-layout input shapes.docs/DIAGRAM_TYPES.mdget galleries + CLI recipes. All 11 chart PNGs committed underexamples/output/showcase/charts/.examples/chart_*.pyscripts, one per chart type.Test plan
python3 examples/chart_bar.pythroughchart_sankey.pyandchart_cohort.py— each produces HTML + PNG inexamples/output/generated/modern-graphics create --layout bar-chart --labels "A,B,C" --values "10,20,15" --output /tmp/bar.htmlmodern-graphics create --layout line-chart --labels "Q1,Q2,Q3,Q4" --series-json '[{"name":"2024","values":[10,14,18,22]}]' --output /tmp/line.htmlmodern-graphics create --layout sankey-chart --links-json '[{"from":"A","to":"B","value":10}]' --output /tmp/sankey.htmlmodern-graphics create --layout cohort-chart --cohorts-json '[{"date":"Jan 1","size":100,"values":[95,40,30]}]' --output /tmp/cohort.htmlmodern-graphics create --layout <chart> --pngproduces a valid PNG (validates__chartReadywait + Playwright integration)@path/to/file.jsonloading works for the three JSON flagslist_layouts/suggest_layout(MCP) return all 11 new layoutsdocs/DIAGRAM_TYPES.mdrender correctly on GitHub (images resolve fromexamples/output/showcase/charts/)🤖 Generated with Claude Code