gg4py 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. gg4py-0.1.0/.gitignore +68 -0
  2. gg4py-0.1.0/LICENSE +21 -0
  3. gg4py-0.1.0/PKG-INFO +170 -0
  4. gg4py-0.1.0/README.md +120 -0
  5. gg4py-0.1.0/pixi.toml +526 -0
  6. gg4py-0.1.0/pyproject.toml +82 -0
  7. gg4py-0.1.0/src/gg4py/__init__.py +96 -0
  8. gg4py-0.1.0/src/gg4py/diff.py +25 -0
  9. gg4py-0.1.0/src/gg4py/io.py +27 -0
  10. gg4py-0.1.0/src/gg4py/ir.py +25 -0
  11. gg4py-0.1.0/src/ggcore/__init__.py +57 -0
  12. gg4py-0.1.0/src/ggcore/aes.py +314 -0
  13. gg4py-0.1.0/src/ggcore/align.py +986 -0
  14. gg4py-0.1.0/src/ggcore/annotations.py +416 -0
  15. gg4py-0.1.0/src/ggcore/arrow.py +184 -0
  16. gg4py-0.1.0/src/ggcore/axis.py +1085 -0
  17. gg4py-0.1.0/src/ggcore/axis_guide.py +2083 -0
  18. gg4py-0.1.0/src/ggcore/build.py +1607 -0
  19. gg4py-0.1.0/src/ggcore/cli/__init__.py +23 -0
  20. gg4py-0.1.0/src/ggcore/components.py +190 -0
  21. gg4py-0.1.0/src/ggcore/composition.py +2057 -0
  22. gg4py-0.1.0/src/ggcore/contour.py +430 -0
  23. gg4py-0.1.0/src/ggcore/coord.py +2435 -0
  24. gg4py-0.1.0/src/ggcore/data.py +285 -0
  25. gg4py-0.1.0/src/ggcore/device.py +120 -0
  26. gg4py-0.1.0/src/ggcore/eval.py +997 -0
  27. gg4py-0.1.0/src/ggcore/facet.py +2084 -0
  28. gg4py-0.1.0/src/ggcore/fills.py +445 -0
  29. gg4py-0.1.0/src/ggcore/geom/__init__.py +237 -0
  30. gg4py-0.1.0/src/ggcore/geom/annotation.py +253 -0
  31. gg4py-0.1.0/src/ggcore/geom/bar.py +545 -0
  32. gg4py-0.1.0/src/ggcore/geom/base.py +620 -0
  33. gg4py-0.1.0/src/ggcore/geom/boxplot.py +431 -0
  34. gg4py-0.1.0/src/ggcore/geom/dist.py +859 -0
  35. gg4py-0.1.0/src/ggcore/geom/interval.py +397 -0
  36. gg4py-0.1.0/src/ggcore/geom/line.py +413 -0
  37. gg4py-0.1.0/src/ggcore/geom/point.py +260 -0
  38. gg4py-0.1.0/src/ggcore/geom/polygon.py +491 -0
  39. gg4py-0.1.0/src/ggcore/geom/rect.py +395 -0
  40. gg4py-0.1.0/src/ggcore/geom/scene.py +3023 -0
  41. gg4py-0.1.0/src/ggcore/geom/segment.py +425 -0
  42. gg4py-0.1.0/src/ggcore/geom/sf.py +590 -0
  43. gg4py-0.1.0/src/ggcore/geom/smooth.py +118 -0
  44. gg4py-0.1.0/src/ggcore/geom/stat2d.py +98 -0
  45. gg4py-0.1.0/src/ggcore/geom/text.py +834 -0
  46. gg4py-0.1.0/src/ggcore/grobs.py +2572 -0
  47. gg4py-0.1.0/src/ggcore/gtable.py +684 -0
  48. gg4py-0.1.0/src/ggcore/guide.py +4110 -0
  49. gg4py-0.1.0/src/ggcore/hexbin.py +222 -0
  50. gg4py-0.1.0/src/ggcore/io.py +597 -0
  51. gg4py-0.1.0/src/ggcore/ir/__init__.py +95 -0
  52. gg4py-0.1.0/src/ggcore/ir/_cbor.py +205 -0
  53. gg4py-0.1.0/src/ggcore/ir/codec.py +581 -0
  54. gg4py-0.1.0/src/ggcore/ir/demo.py +101 -0
  55. gg4py-0.1.0/src/ggcore/ir/errors.py +28 -0
  56. gg4py-0.1.0/src/ggcore/ir/nodes.py +1248 -0
  57. gg4py-0.1.0/src/ggcore/kde2d.py +159 -0
  58. gg4py-0.1.0/src/ggcore/layer.py +289 -0
  59. gg4py-0.1.0/src/ggcore/legend_draw.py +480 -0
  60. gg4py-0.1.0/src/ggcore/loess.py +522 -0
  61. gg4py-0.1.0/src/ggcore/map_data.py +225 -0
  62. gg4py-0.1.0/src/ggcore/map_data_usa.py +7277 -0
  63. gg4py-0.1.0/src/ggcore/metrics/__init__.py +100 -0
  64. gg4py-0.1.0/src/ggcore/metrics/catalog.py +147 -0
  65. gg4py-0.1.0/src/ggcore/metrics/data/metrics_table_v2.bin +0 -0
  66. gg4py-0.1.0/src/ggcore/metrics/data/metrics_table_v2.json +214 -0
  67. gg4py-0.1.0/src/ggcore/metrics/data/rules.json +62 -0
  68. gg4py-0.1.0/src/ggcore/metrics/data/scripts.json +795 -0
  69. gg4py-0.1.0/src/ggcore/metrics/faces.py +212 -0
  70. gg4py-0.1.0/src/ggcore/metrics/fallback.py +171 -0
  71. gg4py-0.1.0/src/ggcore/metrics/provider.py +220 -0
  72. gg4py-0.1.0/src/ggcore/metrics/rules.py +43 -0
  73. gg4py-0.1.0/src/ggcore/metrics/runs.py +216 -0
  74. gg4py-0.1.0/src/ggcore/metrics/table.py +299 -0
  75. gg4py-0.1.0/src/ggcore/munch.py +33 -0
  76. gg4py-0.1.0/src/ggcore/palette_data.py +676 -0
  77. gg4py-0.1.0/src/ggcore/palettes.py +895 -0
  78. gg4py-0.1.0/src/ggcore/perf.py +521 -0
  79. gg4py-0.1.0/src/ggcore/plot.py +513 -0
  80. gg4py-0.1.0/src/ggcore/plot_gtable.py +1011 -0
  81. gg4py-0.1.0/src/ggcore/plotmath.py +450 -0
  82. gg4py-0.1.0/src/ggcore/plotspec.py +668 -0
  83. gg4py-0.1.0/src/ggcore/png.py +52 -0
  84. gg4py-0.1.0/src/ggcore/position.py +1226 -0
  85. gg4py-0.1.0/src/ggcore/registry.py +1850 -0
  86. gg4py-0.1.0/src/ggcore/scale_specs.py +228 -0
  87. gg4py-0.1.0/src/ggcore/scales.py +3476 -0
  88. gg4py-0.1.0/src/ggcore/scales_date.py +662 -0
  89. gg4py-0.1.0/src/ggcore/script.py +332 -0
  90. gg4py-0.1.0/src/ggcore/sf.py +1427 -0
  91. gg4py-0.1.0/src/ggcore/sf_stat.py +140 -0
  92. gg4py-0.1.0/src/ggcore/stat.py +1806 -0
  93. gg4py-0.1.0/src/ggcore/stat2d.py +805 -0
  94. gg4py-0.1.0/src/ggcore/stat_longtail.py +2024 -0
  95. gg4py-0.1.0/src/ggcore/theme.py +2654 -0
  96. gg4py-0.1.0/src/ggcore/units.py +1010 -0
  97. gg4py-0.1.0/src/ggcore/viewport.py +1415 -0
  98. gg4py-0.1.0/src/ggdiff/__init__.py +37 -0
  99. gg4py-0.1.0/src/ggdiff/cli.py +353 -0
  100. gg4py-0.1.0/src/ggdiff/compare.py +148 -0
  101. gg4py-0.1.0/src/ggdiff/image.py +59 -0
  102. gg4py-0.1.0/src/ggdiff/raster.py +100 -0
  103. gg4py-0.1.0/src/ggdiff/report.py +79 -0
  104. gg4py-0.1.0/src/ggdiff/svgimage.py +144 -0
  105. gg4py-0.1.0/src/ggdiff/svgtext.py +313 -0
  106. gg4py-0.1.0/src/ggio/__init__.py +13 -0
  107. gg4py-0.1.0/src/ggio/csv.py +114 -0
  108. gg4py-0.1.0/src/ggio/frame.py +487 -0
  109. gg4py-0.1.0/src/ggshape/__init__.py +13 -0
  110. gg4py-0.1.0/src/ggshape/harfbuzz.py +157 -0
  111. gg4py-0.1.0/src/ggskia/__init__.py +75 -0
  112. gg4py-0.1.0/src/ggskia/cli/__init__.py +1 -0
  113. gg4py-0.1.0/src/ggskia/cli/ggsave.py +189 -0
  114. gg4py-0.1.0/src/ggskia/cli/render.py +150 -0
  115. gg4py-0.1.0/src/ggskia/curves.py +431 -0
  116. gg4py-0.1.0/src/ggskia/pch.py +225 -0
  117. gg4py-0.1.0/src/ggskia/skia.py +1434 -0
  118. gg4py-0.1.0/src/ggskia/text.py +389 -0
gg4py-0.1.0/.gitignore ADDED
@@ -0,0 +1,68 @@
1
+ .pixi
2
+ node_modules/
3
+ __pycache__/
4
+ *.pyc
5
+ .ruff_cache/
6
+ .pytest_cache/
7
+ # pytest-benchmark 的自动存档(`pixi run bench`)
8
+ .benchmarks/
9
+ # `pixi run audit:gallery` 的 35 图产物(M2-13 / SIL-744,不入库)
10
+ .gallery-audit/
11
+
12
+ # 案例的渲染产物与按需拉取的上游参考图(纳管策略见 docs/notes/snapshot-policy.md)
13
+ docs/cases/*/current/
14
+ docs/cases/*/expected/
15
+ # `pixi run diff <case>` 的默认报告与热图(issue 约定的路径;运行时产物,不入库)
16
+ docs/cases/*/diff_report.md
17
+ docs/cases/*/diff_heatmap.png
18
+ docs/cases/*/diff_report_heatmap.png
19
+ # generated network assets for the E1 spike (recreated by `pixi run spike:assets`)
20
+ docs/spike/e1_coldstart/static/
21
+ # Playwright browser downloads for the E1 spike (read-only $HOME in the runtime)
22
+ .playwright-browsers/
23
+ # `pixi run gate:metrics` 的中间产物与报告(每次重跑覆盖,不入库)
24
+ .gate-metrics/
25
+ # `pixi run cases:matrix` 的运行时报告(红绿 + 差多少),每次重跑覆盖,不入库
26
+ .cases-matrix/
27
+ # G10a(SIL-817)的临时量尺产物:`tools/upstream/g10_measure.py` 把候选 plot.py
28
+ # 复制成三文件 case 跑 render/diff,产物落在 .g10/(不入库)
29
+ .g10/
30
+ # `pixi run snapshots:fetch` 按 pin 拉下来的 ggplot2 源码包与解压目录(清单入库,
31
+ # SVG 本体按需拉取;处置见 tools/upstream/snapshots.toml)
32
+ .upstream-gg/
33
+ # `pixi run gate:pyodide` 的两侧产物(IR 字节 + 元数据),每次重跑覆盖,不入库
34
+ .gate-pyodide/
35
+ # `pixi run metrics:advance` 的 hinted/linear 推进报告(每次重跑覆盖,不入库)
36
+ .metrics-advance/
37
+
38
+ # M1-5 等比例测量的运行时产物(`pixi run cases:coord`)
39
+ .coord-aspect/
40
+ # M1-13 浏览器查看器:tsc 产物与手测素材都不入库(`pixi run viewer:build` /
41
+ # `pixi run viewer:sample` 重新生成)
42
+ web/viewer/dist/
43
+ web/viewer/samples/
44
+ # 查看器的受管字体副本与 @font-face(`pixi run viewer:build` 从 rules.json 重建)
45
+ web/viewer/fonts/
46
+ web/viewer/fonts.css
47
+ web/viewer/src/fonts.generated.ts
48
+ # `pixi run viewer:shot` 的截图产物
49
+ .viewer-shot/
50
+ # `pixi run viewer:cases` 的逐 case 产物与报告
51
+ .viewer-cases/
52
+
53
+ # `pixi run viewer:cases` 的 gallery 资产(卡片链接按 viewer 根目录解析)
54
+ web/viewer/gallery/
55
+
56
+ # M1 出口复现件(`scripts/exit_report.py` / `.R`)的产物:随用随生成,不入库
57
+ dist/
58
+ # SIL-824:浏览器运行时的自托管资产(`pixi run pyodide:assets` 生成)与实测产物
59
+ web/runtime/vendor/
60
+ .pyodide-runtime/
61
+ # SIL-830:brotli 预压缩的内容寻址缓存(wasm 的 q11 要 20 s,重建时复用这一份)
62
+ .pyodide-cache/
63
+
64
+ # SIL-826:浏览器代码编辑器。CodeMirror 的 esbuild 产物与验收产物都不入库
65
+ # (`pixi run editor:build` / `pixi run editor:check` 重新生成)。
66
+ web/editor/dist/
67
+ .editor-check/
68
+ uv.lock
gg4py-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sylens Wong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
gg4py-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.5
2
+ Name: gg4py
3
+ Version: 0.1.0
4
+ Summary: A Python port of ggplot2 4.0.3: the grammar of graphics, its own IR, skia and DOM SVG renderers
5
+ Project-URL: Homepage, https://github.com/SilenWang/gg4py
6
+ Project-URL: Repository, https://github.com/SilenWang/gg4py
7
+ Project-URL: Issues, https://github.com/SilenWang/gg4py/issues
8
+ Project-URL: Documentation, https://github.com/SilenWang/gg4py/blob/main/docs/README.md
9
+ Author: Sylens Wong
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ggplot2,grammar-of-graphics,plotting,skia,visualization
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Visualization
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: cbor2<7,>=6.1.5
21
+ Requires-Dist: contourpy<1.4,>=1.3.3
22
+ Requires-Dist: numpy<3,>=2.5.4
23
+ Provides-Extra: all
24
+ Requires-Dist: pandas<4,>=3.1; extra == 'all'
25
+ Requires-Dist: pillow<14,>=11; extra == 'all'
26
+ Requires-Dist: pyarrow<27,>=26; extra == 'all'
27
+ Requires-Dist: skia-python<145,>=144.1; extra == 'all'
28
+ Requires-Dist: uharfbuzz<0.58,>=0.57; extra == 'all'
29
+ Provides-Extra: data
30
+ Requires-Dist: pandas<4,>=3.1; extra == 'data'
31
+ Requires-Dist: pyarrow<27,>=26; extra == 'data'
32
+ Provides-Extra: dev
33
+ Requires-Dist: build<2,>=1.3; extra == 'dev'
34
+ Requires-Dist: pandas<4,>=3.1; extra == 'dev'
35
+ Requires-Dist: pillow<14,>=11; extra == 'dev'
36
+ Requires-Dist: playwright<2,>=1.64.1; extra == 'dev'
37
+ Requires-Dist: pyarrow<27,>=26; extra == 'dev'
38
+ Requires-Dist: pytest-benchmark<6,>=5.2; extra == 'dev'
39
+ Requires-Dist: pytest<10,>=9.2; extra == 'dev'
40
+ Requires-Dist: ruff<0.18,>=0.17.3; extra == 'dev'
41
+ Requires-Dist: skia-python<145,>=144.1; extra == 'dev'
42
+ Requires-Dist: twine<8,>=7; extra == 'dev'
43
+ Requires-Dist: uharfbuzz<0.58,>=0.57; extra == 'dev'
44
+ Provides-Extra: diff
45
+ Requires-Dist: pillow<14,>=11; extra == 'diff'
46
+ Provides-Extra: render
47
+ Requires-Dist: skia-python<145,>=144.1; extra == 'render'
48
+ Requires-Dist: uharfbuzz<0.58,>=0.57; extra == 'render'
49
+ Description-Content-Type: text/markdown
50
+
51
+ # gg4py
52
+
53
+ A Python port of **ggplot2 4.0.3** — the grammar of graphics rebuilt from scratch, with its
54
+ own intermediate representation and its own renderers (skia → PNG/SVG/PDF on the desktop,
55
+ TypeScript + DOM SVG in the browser). It is **not** a wrapper around matplotlib, plotnine or
56
+ any other plotting system: the grammar core depends on `numpy` alone.
57
+
58
+ 中文版:[README.zh-CN.md](README.zh-CN.md)
59
+
60
+ ## Install and first plot
61
+
62
+ Dependencies, environments and tasks are managed by [pixi](https://pixi.sh) (`pixi.toml`),
63
+ so there is nothing to `pip install`. Linux x86-64 for now.
64
+
65
+ ```bash
66
+ pixi install
67
+ pixi run ggsave examples/heatmap/plot.py:plot my-first-plot.png
68
+ ```
69
+
70
+ `ggsave` picks the device from the extension (`.png`, `.svg`, `.pdf`). The same plot from
71
+ Python — the data is any dict of columns, a pandas DataFrame or an Arrow table. One import
72
+ brings in the whole `library(ggplot2)` surface:
73
+
74
+ ```python
75
+ import gg4py # ggplot, aes, every geom_*/stat_*/scale_*, from_*, ggsave
76
+
77
+ df = gg4py.from_dict({"wt": [1.9, 2.6, 3.2, 3.5, 4.1], "mpg": [31, 26, 21, 18, 15]})
78
+ p = (
79
+ gg4py.ggplot(df, gg4py.aes(x="wt", y="mpg"))
80
+ + gg4py.geom_point(size=2)
81
+ + gg4py.labs(title="First plot")
82
+ )
83
+ gg4py.ggsave(p, "first-plot.png", width=6, height=4, dpi=150)
84
+ ```
85
+
86
+ Module boundaries — `gg4py.io` / `gg4py.ir` / `gg4py.diff` for IR, codecs and diffing —
87
+ are spelled out in [`docs/notes/public-api.md`](docs/notes/public-api.md); the old
88
+ `from ggcore.plot import …` paths keep working unchanged.
89
+
90
+ ## What it draws
91
+
92
+ Four examples, each a self-contained `plot.py` using nothing but gg4py itself
93
+ (`pixi run examples:<name>` regenerates the files below). Skipped references and the
94
+ capabilities they need are listed in [`docs/examples.md`](docs/examples.md).
95
+
96
+ **[Heatmap](examples/heatmap/plot.py)** — `geom_tile` + a viridis gradient over a
97
+ 12-month × 8-year grid of synthetic temperatures.
98
+
99
+ ![Heatmap](examples/heatmap/heatmap.png)
100
+
101
+ **[Bump chart](examples/bump-chart/plot.py)** — `geom_line` + `geom_point` with
102
+ `scale_y_reverse()`, so rank 1 sits at the top and crossings stay readable.
103
+
104
+ ![Bump chart](examples/bump-chart/bump-chart.png)
105
+
106
+ **[Circular barplot with groups](examples/circular-barplot/plot.py)** — bars on a continuous
107
+ axis with a gap between groups, rolled into a ring by `coord_polar()`.
108
+
109
+ ![Circular barplot](examples/circular-barplot/circular-barplot.png)
110
+
111
+ **[Mirrored density](examples/mirrored-density/plot.py)** — two densities sharing a zero
112
+ baseline: one drawn from `after_stat("density")`, the other from `after_stat("-density")`.
113
+
114
+ ![Mirrored density](examples/mirrored-density/mirrored-density.png)
115
+
116
+ ## How it works
117
+
118
+ | Layer | Responsibility |
119
+ | --- | --- |
120
+ | `src/ggcore/` | The grammar: aes, stats, geoms, scales, coords, facets, guides, themes. Pure Python + numpy, no pandas, no plotting library. Also runs in the browser under Pyodide. |
121
+ | IR (`ggcore.ir`) | Resolved geometry in float32 buffers, serialized as canonical CBOR. The single hand-off between the core and every renderer. |
122
+ | `src/ggio/` | Input adapters: pandas / Arrow / dict of arrays → one columnar table. |
123
+ | `src/ggskia/` | skia-python device → PNG / SVG / PDF for desktop and server rendering. |
124
+ | `web/viewer/` | TypeScript + DOM SVG viewer for the browser — no wasm, no bundler. |
125
+ | `web/editor/` | Browser code editor: CodeMirror 6 + Pyodide execution + the same DOM SVG renderer, plus SVG / PNG / JPG export. One static page, no backend ([docs/notes/editor.md](docs/notes/editor.md)). |
126
+ | `src/ggdiff/` | Differential testing: R reference vs. our output, one rasterizer (resvg), pixel and ink metrics. |
127
+
128
+ The core is checked, not just claimed: X1 gates forbid any import outside
129
+ `numpy`/stdlib/`contourpy` inside `ggcore`, and the same plot produces byte-identical IR on
130
+ CPython and Pyodide. Rendering parity is measured against 311 upstream SVG snapshots
131
+ generated by ggplot2 4.0.3 itself, plus the browser viewer's DOM output.
132
+
133
+ ## Development
134
+
135
+ ```bash
136
+ pixi run check # lint + tests + gates + viewer parity (what CI runs)
137
+ pixi run test # pytest
138
+ pixi run lint # ruff check + ruff format --check
139
+ ```
140
+
141
+ Layout, environments and the full task catalogue: [`docs/dev/layout.md`](docs/dev/layout.md).
142
+ User guide (one page per module, every snippet executed by `pixi run docs:guide`):
143
+ [`docs/guide/`](docs/guide/index.md) — start with the
144
+ [R → Python mapping](docs/guide/r-to-python.md) if you come from ggplot2.
145
+ Reference reading (module-by-module contracts, gates, snapshot policy): [`docs/README.md`](docs/README.md).
146
+
147
+ ## How this was built
148
+
149
+ Every design decision, line of code, test and doc page here was produced by a **single
150
+ model — DeepSeek** ([deepseek-ai](https://github.com/deepseek-ai)) — working through
151
+ open-source agent tooling:
152
+
153
+ - [OpenCode](https://github.com/anomalyco/opencode) — terminal coding agent
154
+ - [Reasonix](https://github.com/esengine/DeepSeek-Reasonix) — coding agent
155
+ - [Codex](https://github.com/openai/codex) — OpenAI's terminal coding agent
156
+ - [Multica](https://github.com/multica-ai/multica) — issue board and agent orchestration
157
+
158
+ ## License
159
+
160
+ MIT — see [`LICENSE`](LICENSE). © 2026 Sylens Wong.
161
+
162
+ ## Attribution
163
+
164
+ gg4py is a Python port of [ggplot2](https://github.com/tidyverse/ggplot2) **4.0.3**
165
+ (commit `cc1444c10edb87650fbe0cb31d56f0da1a255634`, tag `v4.0.3`), © 2025 ggplot2 core
166
+ developer team, MIT. The grammar semantics, the R-side reference fixtures and the reference
167
+ plots in `docs/cases/` are ported from or generated by that project; its copyright notice is
168
+ reproduced here, as the MIT license requires. Third-party asset inventory:
169
+ [`docs/notes/licenses.md`](docs/notes/licenses.md) (fonts, wasm and browsers are fetched at
170
+ build time by pixi / npm, never committed).
gg4py-0.1.0/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # gg4py
2
+
3
+ A Python port of **ggplot2 4.0.3** — the grammar of graphics rebuilt from scratch, with its
4
+ own intermediate representation and its own renderers (skia → PNG/SVG/PDF on the desktop,
5
+ TypeScript + DOM SVG in the browser). It is **not** a wrapper around matplotlib, plotnine or
6
+ any other plotting system: the grammar core depends on `numpy` alone.
7
+
8
+ 中文版:[README.zh-CN.md](README.zh-CN.md)
9
+
10
+ ## Install and first plot
11
+
12
+ Dependencies, environments and tasks are managed by [pixi](https://pixi.sh) (`pixi.toml`),
13
+ so there is nothing to `pip install`. Linux x86-64 for now.
14
+
15
+ ```bash
16
+ pixi install
17
+ pixi run ggsave examples/heatmap/plot.py:plot my-first-plot.png
18
+ ```
19
+
20
+ `ggsave` picks the device from the extension (`.png`, `.svg`, `.pdf`). The same plot from
21
+ Python — the data is any dict of columns, a pandas DataFrame or an Arrow table. One import
22
+ brings in the whole `library(ggplot2)` surface:
23
+
24
+ ```python
25
+ import gg4py # ggplot, aes, every geom_*/stat_*/scale_*, from_*, ggsave
26
+
27
+ df = gg4py.from_dict({"wt": [1.9, 2.6, 3.2, 3.5, 4.1], "mpg": [31, 26, 21, 18, 15]})
28
+ p = (
29
+ gg4py.ggplot(df, gg4py.aes(x="wt", y="mpg"))
30
+ + gg4py.geom_point(size=2)
31
+ + gg4py.labs(title="First plot")
32
+ )
33
+ gg4py.ggsave(p, "first-plot.png", width=6, height=4, dpi=150)
34
+ ```
35
+
36
+ Module boundaries — `gg4py.io` / `gg4py.ir` / `gg4py.diff` for IR, codecs and diffing —
37
+ are spelled out in [`docs/notes/public-api.md`](docs/notes/public-api.md); the old
38
+ `from ggcore.plot import …` paths keep working unchanged.
39
+
40
+ ## What it draws
41
+
42
+ Four examples, each a self-contained `plot.py` using nothing but gg4py itself
43
+ (`pixi run examples:<name>` regenerates the files below). Skipped references and the
44
+ capabilities they need are listed in [`docs/examples.md`](docs/examples.md).
45
+
46
+ **[Heatmap](examples/heatmap/plot.py)** — `geom_tile` + a viridis gradient over a
47
+ 12-month × 8-year grid of synthetic temperatures.
48
+
49
+ ![Heatmap](examples/heatmap/heatmap.png)
50
+
51
+ **[Bump chart](examples/bump-chart/plot.py)** — `geom_line` + `geom_point` with
52
+ `scale_y_reverse()`, so rank 1 sits at the top and crossings stay readable.
53
+
54
+ ![Bump chart](examples/bump-chart/bump-chart.png)
55
+
56
+ **[Circular barplot with groups](examples/circular-barplot/plot.py)** — bars on a continuous
57
+ axis with a gap between groups, rolled into a ring by `coord_polar()`.
58
+
59
+ ![Circular barplot](examples/circular-barplot/circular-barplot.png)
60
+
61
+ **[Mirrored density](examples/mirrored-density/plot.py)** — two densities sharing a zero
62
+ baseline: one drawn from `after_stat("density")`, the other from `after_stat("-density")`.
63
+
64
+ ![Mirrored density](examples/mirrored-density/mirrored-density.png)
65
+
66
+ ## How it works
67
+
68
+ | Layer | Responsibility |
69
+ | --- | --- |
70
+ | `src/ggcore/` | The grammar: aes, stats, geoms, scales, coords, facets, guides, themes. Pure Python + numpy, no pandas, no plotting library. Also runs in the browser under Pyodide. |
71
+ | IR (`ggcore.ir`) | Resolved geometry in float32 buffers, serialized as canonical CBOR. The single hand-off between the core and every renderer. |
72
+ | `src/ggio/` | Input adapters: pandas / Arrow / dict of arrays → one columnar table. |
73
+ | `src/ggskia/` | skia-python device → PNG / SVG / PDF for desktop and server rendering. |
74
+ | `web/viewer/` | TypeScript + DOM SVG viewer for the browser — no wasm, no bundler. |
75
+ | `web/editor/` | Browser code editor: CodeMirror 6 + Pyodide execution + the same DOM SVG renderer, plus SVG / PNG / JPG export. One static page, no backend ([docs/notes/editor.md](docs/notes/editor.md)). |
76
+ | `src/ggdiff/` | Differential testing: R reference vs. our output, one rasterizer (resvg), pixel and ink metrics. |
77
+
78
+ The core is checked, not just claimed: X1 gates forbid any import outside
79
+ `numpy`/stdlib/`contourpy` inside `ggcore`, and the same plot produces byte-identical IR on
80
+ CPython and Pyodide. Rendering parity is measured against 311 upstream SVG snapshots
81
+ generated by ggplot2 4.0.3 itself, plus the browser viewer's DOM output.
82
+
83
+ ## Development
84
+
85
+ ```bash
86
+ pixi run check # lint + tests + gates + viewer parity (what CI runs)
87
+ pixi run test # pytest
88
+ pixi run lint # ruff check + ruff format --check
89
+ ```
90
+
91
+ Layout, environments and the full task catalogue: [`docs/dev/layout.md`](docs/dev/layout.md).
92
+ User guide (one page per module, every snippet executed by `pixi run docs:guide`):
93
+ [`docs/guide/`](docs/guide/index.md) — start with the
94
+ [R → Python mapping](docs/guide/r-to-python.md) if you come from ggplot2.
95
+ Reference reading (module-by-module contracts, gates, snapshot policy): [`docs/README.md`](docs/README.md).
96
+
97
+ ## How this was built
98
+
99
+ Every design decision, line of code, test and doc page here was produced by a **single
100
+ model — DeepSeek** ([deepseek-ai](https://github.com/deepseek-ai)) — working through
101
+ open-source agent tooling:
102
+
103
+ - [OpenCode](https://github.com/anomalyco/opencode) — terminal coding agent
104
+ - [Reasonix](https://github.com/esengine/DeepSeek-Reasonix) — coding agent
105
+ - [Codex](https://github.com/openai/codex) — OpenAI's terminal coding agent
106
+ - [Multica](https://github.com/multica-ai/multica) — issue board and agent orchestration
107
+
108
+ ## License
109
+
110
+ MIT — see [`LICENSE`](LICENSE). © 2026 Sylens Wong.
111
+
112
+ ## Attribution
113
+
114
+ gg4py is a Python port of [ggplot2](https://github.com/tidyverse/ggplot2) **4.0.3**
115
+ (commit `cc1444c10edb87650fbe0cb31d56f0da1a255634`, tag `v4.0.3`), © 2025 ggplot2 core
116
+ developer team, MIT. The grammar semantics, the R-side reference fixtures and the reference
117
+ plots in `docs/cases/` are ported from or generated by that project; its copyright notice is
118
+ reproduced here, as the MIT license requires. Third-party asset inventory:
119
+ [`docs/notes/licenses.md`](docs/notes/licenses.md) (fonts, wasm and browsers are fetched at
120
+ build time by pixi / npm, never committed).