gum-jsx 0.4__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.
- gum_jsx-0.4/PKG-INFO +148 -0
- gum_jsx-0.4/README.md +138 -0
- gum_jsx-0.4/gum/__init__.py +6 -0
- gum_jsx-0.4/gum/__main__.py +18 -0
- gum_jsx-0.4/gum/dem.py +431 -0
- gum_jsx-0.4/gum/gen.py +286 -0
- gum_jsx-0.4/gum/gum-jsx/fonts/IBMPlexMono-Regular.ttf +0 -0
- gum_jsx-0.4/gum/gum-jsx/fonts/IBMPlexSans-Variable.ttf +0 -0
- gum_jsx-0.4/gum/gum-jsx/gum.js +38586 -0
- gum_jsx-0.4/gum/gum.py +149 -0
- gum_jsx-0.4/gum/utl.py +299 -0
- gum_jsx-0.4/gum/viz.py +132 -0
- gum_jsx-0.4/gum_jsx.egg-info/PKG-INFO +148 -0
- gum_jsx-0.4/gum_jsx.egg-info/SOURCES.txt +16 -0
- gum_jsx-0.4/gum_jsx.egg-info/dependency_links.txt +1 -0
- gum_jsx-0.4/gum_jsx.egg-info/top_level.txt +1 -0
- gum_jsx-0.4/pyproject.toml +27 -0
- gum_jsx-0.4/setup.cfg +4 -0
gum_jsx-0.4/PKG-INFO
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gum-jsx
|
|
3
|
+
Version: 0.4
|
|
4
|
+
Summary: Python wrapper for gum.jsx, a language for creating vector graphics
|
|
5
|
+
Author: Douglas Hanley
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/CompendiumLabs/gum.py
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
<img src="image/logo.svg" alt="gum.py" width="500" />
|
|
13
|
+
<br/>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div align="center">
|
|
17
|
+
<img src="image/nexus.svg" alt="nexus" width="250" />
|
|
18
|
+
<br/><br/>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
A Python wrapper for [gum.js](https://github.com/CompendiumLabs/gum.js), a language for creating visualizations using a React-like JSX dialect that evaluates to SVG. Designed for general graphics, plots, graphs, and network diagrams.
|
|
22
|
+
|
|
23
|
+
Head to **[compendiumlabs.ai/gum](https://compendiumlabs.ai/gum)** for a live demo and documentation on the underlying gum.js library. Or see the [gum.js](https://github.com/CompendiumLabs/gum.js) repository.
|
|
24
|
+
|
|
25
|
+
# Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install gum-py
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Requires Node.js to be installed for the gum.js backend.
|
|
32
|
+
|
|
33
|
+
# Usage
|
|
34
|
+
|
|
35
|
+
Create visualizations using Python syntax that generates JSX:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import gum
|
|
39
|
+
from gum import C
|
|
40
|
+
from gum.gen import Plot, SymLine
|
|
41
|
+
|
|
42
|
+
# create a simple sine wave plot
|
|
43
|
+
plot = Plot(
|
|
44
|
+
SymLine(fy=C.sin, stroke=C.blue, stroke_width=2),
|
|
45
|
+
xlim=(0, 2*C.pi), ylim=(-1, 1), grid=True, margin=0.2, aspect=2,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# display in terminal (requires chafa)
|
|
49
|
+
gum.display(plot) # or just `plot` if you're in IPython or Jupyter
|
|
50
|
+
|
|
51
|
+
# or get the SVG string
|
|
52
|
+
svg = gum.evaluate(plot)
|
|
53
|
+
|
|
54
|
+
# or get the JSX code
|
|
55
|
+
jsx = str(plot)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
If you're in IPython or Jupyter, you don't even need to call `display`. Just type `plot` and it will automatically display the visualization inline.
|
|
59
|
+
|
|
60
|
+
## Pandas Integration
|
|
61
|
+
|
|
62
|
+
Plot DataFrames directly with high-level functions:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import pandas as pd
|
|
66
|
+
import numpy as np
|
|
67
|
+
from gum import lines, points, bars
|
|
68
|
+
|
|
69
|
+
# line plot from DataFrame
|
|
70
|
+
th = np.linspace(0, 2*np.pi, 100)
|
|
71
|
+
df = pd.DataFrame({ 'sin': np.sin(th), 'cos': np.cos(th) })
|
|
72
|
+
lines(df, margin=0.15)
|
|
73
|
+
|
|
74
|
+
# bar chart from Series
|
|
75
|
+
bars(pd.Series({'A': 3, 'B': 8, 'C': 5}))
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Symbolic Expressions
|
|
79
|
+
|
|
80
|
+
Use `C` for constants and `V` for variables:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from gum import C, V
|
|
84
|
+
from gum.gen import Plot, SymLine, SymPoints
|
|
85
|
+
|
|
86
|
+
# C references gum.js constants and functions
|
|
87
|
+
C.sin, C.cos, C.pi, C.blue, C.red
|
|
88
|
+
|
|
89
|
+
# build symbolic expressions
|
|
90
|
+
decay = lambda x: C.exp(-x/2) * C.sin(3*x)
|
|
91
|
+
|
|
92
|
+
# V creates named variables bound to data
|
|
93
|
+
theta = V.theta(np.linspace(0, 2*np.pi, 100))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
# CLI
|
|
97
|
+
|
|
98
|
+
Display gum visualizations directly in the terminal using `chafa`. Requires a terminal with image support, such as `ghostty`.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# run a built-in demo
|
|
102
|
+
python -m gum -d plot -s 50
|
|
103
|
+
|
|
104
|
+
# pipe JSX code
|
|
105
|
+
cat input.jsx | python -m gum
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
CLI options:
|
|
109
|
+
|
|
110
|
+
| Option | Description | Default |
|
|
111
|
+
|--------|-------------|---------|
|
|
112
|
+
| `-d, --demo <name>` | Run a named demo | - |
|
|
113
|
+
| `-s, --size <size>` | Terminal display size | 50 |
|
|
114
|
+
| `-t, --theme <theme>` | Theme: `light` or `dark` | dark |
|
|
115
|
+
|
|
116
|
+
Available demos: `plot`, `barplot`, `network`, `symline`, `grid`, `stack`, `text`, and more (see `gum/dem.py`).
|
|
117
|
+
|
|
118
|
+
# Jupyter Support
|
|
119
|
+
|
|
120
|
+
`gum.py` automatically renders SVG in IPython console and Jupyter notebooks:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from gum import Plot, SymLine, C
|
|
124
|
+
|
|
125
|
+
# this will display inline in Jupyter
|
|
126
|
+
Plot(
|
|
127
|
+
SymLine(fy=C.sin),
|
|
128
|
+
xlim=(0, 2*C.pi), ylim=(-1, 1), grid=True,
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
# Components
|
|
133
|
+
|
|
134
|
+
gum.py wraps all gum.js components. Key ones include:
|
|
135
|
+
|
|
136
|
+
**Layout**: `Box`, `Frame`, `Stack`, `HStack`, `VStack`, `Grid`, `Points`
|
|
137
|
+
|
|
138
|
+
**Shapes**: `Rect`, `Ellipse`, `Circle`, `Line`, `Shape`, `Spline`
|
|
139
|
+
|
|
140
|
+
**Text**: `Text`, `TextFrame`, `Latex`, `Equation`
|
|
141
|
+
|
|
142
|
+
**Plotting**: `Plot`, `Graph`, `Axis`, `HAxis`, `VAxis`, `BarPlot`
|
|
143
|
+
|
|
144
|
+
**Symbolic**: `SymLine`, `SymPoints`, `SymShape`, `SymSpline`, `SymFill`, `SymField`
|
|
145
|
+
|
|
146
|
+
**Network**: `Node`, `Edge`, `Network`, `Arrow`
|
|
147
|
+
|
|
148
|
+
See the [gum.js documentation](https://compendiumlabs.ai/gum/docs) for detailed component reference.
|
gum_jsx-0.4/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="image/logo.svg" alt="gum.py" width="500" />
|
|
3
|
+
<br/>
|
|
4
|
+
</div>
|
|
5
|
+
|
|
6
|
+
<div align="center">
|
|
7
|
+
<img src="image/nexus.svg" alt="nexus" width="250" />
|
|
8
|
+
<br/><br/>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
A Python wrapper for [gum.js](https://github.com/CompendiumLabs/gum.js), a language for creating visualizations using a React-like JSX dialect that evaluates to SVG. Designed for general graphics, plots, graphs, and network diagrams.
|
|
12
|
+
|
|
13
|
+
Head to **[compendiumlabs.ai/gum](https://compendiumlabs.ai/gum)** for a live demo and documentation on the underlying gum.js library. Or see the [gum.js](https://github.com/CompendiumLabs/gum.js) repository.
|
|
14
|
+
|
|
15
|
+
# Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install gum-py
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires Node.js to be installed for the gum.js backend.
|
|
22
|
+
|
|
23
|
+
# Usage
|
|
24
|
+
|
|
25
|
+
Create visualizations using Python syntax that generates JSX:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import gum
|
|
29
|
+
from gum import C
|
|
30
|
+
from gum.gen import Plot, SymLine
|
|
31
|
+
|
|
32
|
+
# create a simple sine wave plot
|
|
33
|
+
plot = Plot(
|
|
34
|
+
SymLine(fy=C.sin, stroke=C.blue, stroke_width=2),
|
|
35
|
+
xlim=(0, 2*C.pi), ylim=(-1, 1), grid=True, margin=0.2, aspect=2,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# display in terminal (requires chafa)
|
|
39
|
+
gum.display(plot) # or just `plot` if you're in IPython or Jupyter
|
|
40
|
+
|
|
41
|
+
# or get the SVG string
|
|
42
|
+
svg = gum.evaluate(plot)
|
|
43
|
+
|
|
44
|
+
# or get the JSX code
|
|
45
|
+
jsx = str(plot)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you're in IPython or Jupyter, you don't even need to call `display`. Just type `plot` and it will automatically display the visualization inline.
|
|
49
|
+
|
|
50
|
+
## Pandas Integration
|
|
51
|
+
|
|
52
|
+
Plot DataFrames directly with high-level functions:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import pandas as pd
|
|
56
|
+
import numpy as np
|
|
57
|
+
from gum import lines, points, bars
|
|
58
|
+
|
|
59
|
+
# line plot from DataFrame
|
|
60
|
+
th = np.linspace(0, 2*np.pi, 100)
|
|
61
|
+
df = pd.DataFrame({ 'sin': np.sin(th), 'cos': np.cos(th) })
|
|
62
|
+
lines(df, margin=0.15)
|
|
63
|
+
|
|
64
|
+
# bar chart from Series
|
|
65
|
+
bars(pd.Series({'A': 3, 'B': 8, 'C': 5}))
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Symbolic Expressions
|
|
69
|
+
|
|
70
|
+
Use `C` for constants and `V` for variables:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from gum import C, V
|
|
74
|
+
from gum.gen import Plot, SymLine, SymPoints
|
|
75
|
+
|
|
76
|
+
# C references gum.js constants and functions
|
|
77
|
+
C.sin, C.cos, C.pi, C.blue, C.red
|
|
78
|
+
|
|
79
|
+
# build symbolic expressions
|
|
80
|
+
decay = lambda x: C.exp(-x/2) * C.sin(3*x)
|
|
81
|
+
|
|
82
|
+
# V creates named variables bound to data
|
|
83
|
+
theta = V.theta(np.linspace(0, 2*np.pi, 100))
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
# CLI
|
|
87
|
+
|
|
88
|
+
Display gum visualizations directly in the terminal using `chafa`. Requires a terminal with image support, such as `ghostty`.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# run a built-in demo
|
|
92
|
+
python -m gum -d plot -s 50
|
|
93
|
+
|
|
94
|
+
# pipe JSX code
|
|
95
|
+
cat input.jsx | python -m gum
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
CLI options:
|
|
99
|
+
|
|
100
|
+
| Option | Description | Default |
|
|
101
|
+
|--------|-------------|---------|
|
|
102
|
+
| `-d, --demo <name>` | Run a named demo | - |
|
|
103
|
+
| `-s, --size <size>` | Terminal display size | 50 |
|
|
104
|
+
| `-t, --theme <theme>` | Theme: `light` or `dark` | dark |
|
|
105
|
+
|
|
106
|
+
Available demos: `plot`, `barplot`, `network`, `symline`, `grid`, `stack`, `text`, and more (see `gum/dem.py`).
|
|
107
|
+
|
|
108
|
+
# Jupyter Support
|
|
109
|
+
|
|
110
|
+
`gum.py` automatically renders SVG in IPython console and Jupyter notebooks:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from gum import Plot, SymLine, C
|
|
114
|
+
|
|
115
|
+
# this will display inline in Jupyter
|
|
116
|
+
Plot(
|
|
117
|
+
SymLine(fy=C.sin),
|
|
118
|
+
xlim=(0, 2*C.pi), ylim=(-1, 1), grid=True,
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
# Components
|
|
123
|
+
|
|
124
|
+
gum.py wraps all gum.js components. Key ones include:
|
|
125
|
+
|
|
126
|
+
**Layout**: `Box`, `Frame`, `Stack`, `HStack`, `VStack`, `Grid`, `Points`
|
|
127
|
+
|
|
128
|
+
**Shapes**: `Rect`, `Ellipse`, `Circle`, `Line`, `Shape`, `Spline`
|
|
129
|
+
|
|
130
|
+
**Text**: `Text`, `TextFrame`, `Latex`, `Equation`
|
|
131
|
+
|
|
132
|
+
**Plotting**: `Plot`, `Graph`, `Axis`, `HAxis`, `VAxis`, `BarPlot`
|
|
133
|
+
|
|
134
|
+
**Symbolic**: `SymLine`, `SymPoints`, `SymShape`, `SymSpline`, `SymFill`, `SymField`
|
|
135
|
+
|
|
136
|
+
**Network**: `Node`, `Edge`, `Network`, `Arrow`
|
|
137
|
+
|
|
138
|
+
See the [gum.js documentation](https://compendiumlabs.ai/gum/docs) for detailed component reference.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from .gum import chafa, evaluate, display, display_file, restart, display as D, GumError, GumErrorType
|
|
2
|
+
from .utl import Var, Con, Element, DisplayMixin, DataGroup, Group, stringify
|
|
3
|
+
from .gen import V, C, GumData
|
|
4
|
+
from .viz import lines, points, bars, test_data
|
|
5
|
+
from .dem import demo
|
|
6
|
+
from . import gen as G
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# main entry point
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import argparse
|
|
5
|
+
from .dem import demo
|
|
6
|
+
from .gum import display
|
|
7
|
+
|
|
8
|
+
if __name__ == '__main__':
|
|
9
|
+
# parse command line arguments
|
|
10
|
+
parser = argparse.ArgumentParser()
|
|
11
|
+
parser.add_argument('-d', '--demo', type=str, help='the demo to run', default=None)
|
|
12
|
+
parser.add_argument('-s', '--size', type=int, help='the size of the display', default=50)
|
|
13
|
+
parser.add_argument('-t', '--theme', type=str, help='the theme to use', default='dark')
|
|
14
|
+
args = parser.parse_args()
|
|
15
|
+
|
|
16
|
+
# dispatch commands
|
|
17
|
+
elem = demo(args.demo) if args.demo is not None else sys.stdin.read()
|
|
18
|
+
display(elem, size=args.size, theme=args.theme)
|