spectacular-charts 0.2.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.
- spectacular_charts-0.2.0/Cargo.lock +216 -0
- spectacular_charts-0.2.0/Cargo.toml +15 -0
- spectacular_charts-0.2.0/PKG-INFO +152 -0
- spectacular_charts-0.2.0/README.md +118 -0
- spectacular_charts-0.2.0/crates/spectacular/Cargo.toml +16 -0
- spectacular_charts-0.2.0/crates/spectacular/build.rs +11 -0
- spectacular_charts-0.2.0/crates/spectacular/src/colors.rs +43 -0
- spectacular_charts-0.2.0/crates/spectacular/src/describe.rs +961 -0
- spectacular_charts-0.2.0/crates/spectacular/src/lib.rs +81 -0
- spectacular_charts-0.2.0/crates/spectacular/src/main.rs +393 -0
- spectacular_charts-0.2.0/crates/spectacular/src/page.rs +61 -0
- spectacular_charts-0.2.0/crates/spectacular/src/table.rs +221 -0
- spectacular_charts-0.2.0/crates/spectacular/src/validate.rs +458 -0
- spectacular_charts-0.2.0/pyproject.toml +53 -0
- spectacular_charts-0.2.0/src/spectacular/__init__.py +65 -0
- spectacular_charts-0.2.0/src/spectacular/_cli.py +186 -0
- spectacular_charts-0.2.0/src/spectacular/_data.py +222 -0
- spectacular_charts-0.2.0/src/spectacular/_html.py +65 -0
- spectacular_charts-0.2.0/src/spectacular/_magic.py +59 -0
- spectacular_charts-0.2.0/src/spectacular/_native.py +80 -0
- spectacular_charts-0.2.0/src/spectacular/_spec.py +96 -0
- spectacular_charts-0.2.0/src/spectacular/_view.py +186 -0
- spectacular_charts-0.2.0/src/spectacular/data/bundle.lineage.csv +696 -0
- spectacular_charts-0.2.0/src/spectacular/data/bundle.rows.json +1 -0
- spectacular_charts-0.2.0/src/spectacular/datasets.py +115 -0
- spectacular_charts-0.2.0/src/spectacular/static/spectacular.js +4372 -0
- spectacular_charts-0.2.0/src/spectacular/static/spectacular.schema.json +871 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "bumpalo"
|
|
7
|
+
version = "3.20.3"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "cfg-if"
|
|
13
|
+
version = "1.0.5"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "chigutiro"
|
|
19
|
+
version = "0.2.0"
|
|
20
|
+
|
|
21
|
+
[[package]]
|
|
22
|
+
name = "chigutiro-wasm"
|
|
23
|
+
version = "0.2.0"
|
|
24
|
+
dependencies = [
|
|
25
|
+
"chigutiro",
|
|
26
|
+
"wasm-bindgen",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "equivalent"
|
|
31
|
+
version = "1.0.3"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
|
|
34
|
+
|
|
35
|
+
[[package]]
|
|
36
|
+
name = "foldhash"
|
|
37
|
+
version = "0.2.0"
|
|
38
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
39
|
+
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "hashbrown"
|
|
43
|
+
version = "0.17.1"
|
|
44
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
45
|
+
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
|
46
|
+
|
|
47
|
+
[[package]]
|
|
48
|
+
name = "indexmap"
|
|
49
|
+
version = "2.14.2"
|
|
50
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
51
|
+
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
|
|
52
|
+
dependencies = [
|
|
53
|
+
"equivalent",
|
|
54
|
+
"hashbrown",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[[package]]
|
|
58
|
+
name = "itoa"
|
|
59
|
+
version = "1.0.19"
|
|
60
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
61
|
+
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
|
62
|
+
|
|
63
|
+
[[package]]
|
|
64
|
+
name = "memchr"
|
|
65
|
+
version = "2.8.3"
|
|
66
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
67
|
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
68
|
+
|
|
69
|
+
[[package]]
|
|
70
|
+
name = "once_cell"
|
|
71
|
+
version = "1.21.4"
|
|
72
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
73
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
74
|
+
|
|
75
|
+
[[package]]
|
|
76
|
+
name = "proc-macro2"
|
|
77
|
+
version = "1.0.107"
|
|
78
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
79
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
80
|
+
dependencies = [
|
|
81
|
+
"unicode-ident",
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
[[package]]
|
|
85
|
+
name = "quote"
|
|
86
|
+
version = "1.0.47"
|
|
87
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
88
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
89
|
+
dependencies = [
|
|
90
|
+
"proc-macro2",
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
[[package]]
|
|
94
|
+
name = "rustversion"
|
|
95
|
+
version = "1.0.23"
|
|
96
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
97
|
+
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|
98
|
+
|
|
99
|
+
[[package]]
|
|
100
|
+
name = "serde"
|
|
101
|
+
version = "1.0.229"
|
|
102
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
103
|
+
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
104
|
+
dependencies = [
|
|
105
|
+
"serde_core",
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
[[package]]
|
|
109
|
+
name = "serde_core"
|
|
110
|
+
version = "1.0.229"
|
|
111
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
112
|
+
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
113
|
+
dependencies = [
|
|
114
|
+
"serde_derive",
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
[[package]]
|
|
118
|
+
name = "serde_derive"
|
|
119
|
+
version = "1.0.229"
|
|
120
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
121
|
+
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
122
|
+
dependencies = [
|
|
123
|
+
"proc-macro2",
|
|
124
|
+
"quote",
|
|
125
|
+
"syn",
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
[[package]]
|
|
129
|
+
name = "serde_json"
|
|
130
|
+
version = "1.0.154"
|
|
131
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
132
|
+
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
|
133
|
+
dependencies = [
|
|
134
|
+
"foldhash",
|
|
135
|
+
"indexmap",
|
|
136
|
+
"itoa",
|
|
137
|
+
"memchr",
|
|
138
|
+
"serde",
|
|
139
|
+
"serde_core",
|
|
140
|
+
"zmij",
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
[[package]]
|
|
144
|
+
name = "spectacular"
|
|
145
|
+
version = "0.2.0"
|
|
146
|
+
dependencies = [
|
|
147
|
+
"serde_json",
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
[[package]]
|
|
151
|
+
name = "syn"
|
|
152
|
+
version = "3.0.9"
|
|
153
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
154
|
+
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
|
155
|
+
dependencies = [
|
|
156
|
+
"proc-macro2",
|
|
157
|
+
"quote",
|
|
158
|
+
"unicode-ident",
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
[[package]]
|
|
162
|
+
name = "unicode-ident"
|
|
163
|
+
version = "1.0.27"
|
|
164
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
165
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
166
|
+
|
|
167
|
+
[[package]]
|
|
168
|
+
name = "wasm-bindgen"
|
|
169
|
+
version = "0.2.129"
|
|
170
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
171
|
+
checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409"
|
|
172
|
+
dependencies = [
|
|
173
|
+
"cfg-if",
|
|
174
|
+
"once_cell",
|
|
175
|
+
"rustversion",
|
|
176
|
+
"wasm-bindgen-macro",
|
|
177
|
+
"wasm-bindgen-shared",
|
|
178
|
+
]
|
|
179
|
+
|
|
180
|
+
[[package]]
|
|
181
|
+
name = "wasm-bindgen-macro"
|
|
182
|
+
version = "0.2.129"
|
|
183
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
184
|
+
checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535"
|
|
185
|
+
dependencies = [
|
|
186
|
+
"quote",
|
|
187
|
+
"wasm-bindgen-macro-support",
|
|
188
|
+
]
|
|
189
|
+
|
|
190
|
+
[[package]]
|
|
191
|
+
name = "wasm-bindgen-macro-support"
|
|
192
|
+
version = "0.2.129"
|
|
193
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
194
|
+
checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7"
|
|
195
|
+
dependencies = [
|
|
196
|
+
"bumpalo",
|
|
197
|
+
"proc-macro2",
|
|
198
|
+
"quote",
|
|
199
|
+
"syn",
|
|
200
|
+
"wasm-bindgen-shared",
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
[[package]]
|
|
204
|
+
name = "wasm-bindgen-shared"
|
|
205
|
+
version = "0.2.129"
|
|
206
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
207
|
+
checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6"
|
|
208
|
+
dependencies = [
|
|
209
|
+
"unicode-ident",
|
|
210
|
+
]
|
|
211
|
+
|
|
212
|
+
[[package]]
|
|
213
|
+
name = "zmij"
|
|
214
|
+
version = "1.0.23"
|
|
215
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
216
|
+
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[workspace]
|
|
2
|
+
resolver = "2"
|
|
3
|
+
members = ["crates/spectacular"]
|
|
4
|
+
|
|
5
|
+
[workspace.package]
|
|
6
|
+
version = "0.2.0"
|
|
7
|
+
edition = "2021"
|
|
8
|
+
authors = ["Kundai Farai Sachikonye"]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
repository = "https://github.com/fullscreen-triangle/spectacular"
|
|
11
|
+
|
|
12
|
+
[profile.release]
|
|
13
|
+
opt-level = 3
|
|
14
|
+
lto = true
|
|
15
|
+
codegen-units = 1
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spectacular-charts
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Classifier: Development Status :: 3 - Alpha
|
|
5
|
+
Classifier: Framework :: Jupyter
|
|
6
|
+
Classifier: Framework :: Jupyter :: JupyterLab
|
|
7
|
+
Classifier: Intended Audience :: Science/Research
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Programming Language :: Rust
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
13
|
+
Requires-Dist: anywidget>=0.9 ; extra == 'notebook'
|
|
14
|
+
Requires-Dist: playwright>=1.40 ; extra == 'render'
|
|
15
|
+
Requires-Dist: pytest ; extra == 'test'
|
|
16
|
+
Requires-Dist: anywidget>=0.9 ; extra == 'test'
|
|
17
|
+
Requires-Dist: numpy ; extra == 'test'
|
|
18
|
+
Requires-Dist: pandas ; extra == 'test'
|
|
19
|
+
Provides-Extra: notebook
|
|
20
|
+
Provides-Extra: render
|
|
21
|
+
Provides-Extra: test
|
|
22
|
+
Summary: Linked, crossfiltered charts in Jupyter, described in JSON instead of plotting code
|
|
23
|
+
Keywords: visualization,charts,crossfilter,jupyter,anywidget,webassembly,linked-views,brushing
|
|
24
|
+
Author: Kundai Farai Sachikonye
|
|
25
|
+
License-Expression: MIT
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
28
|
+
Project-URL: Changelog, https://github.com/fullscreen-triangle/spectacular/blob/rebuild/python/CHANGELOG.md
|
|
29
|
+
Project-URL: Documentation, https://fullscreen-triangle.github.io/spectacular/
|
|
30
|
+
Project-URL: Homepage, https://fullscreen-triangle.github.io/spectacular/
|
|
31
|
+
Project-URL: Issues, https://github.com/fullscreen-triangle/spectacular/issues
|
|
32
|
+
Project-URL: Source, https://github.com/fullscreen-triangle/spectacular/tree/rebuild
|
|
33
|
+
|
|
34
|
+
# spectacular-charts
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/spectacular-charts/)
|
|
37
|
+
[](https://pypi.org/project/spectacular-charts/)
|
|
38
|
+
[](https://fullscreen-triangle.github.io/spectacular/)
|
|
39
|
+
[](https://github.com/fullscreen-triangle/spectacular)
|
|
40
|
+
|
|
41
|
+
**Linked, crossfiltered charts for Python and Jupyter, described in JSON instead of
|
|
42
|
+
written as plotting code.**
|
|
43
|
+
|
|
44
|
+
Describe the charts you want, and the chart types follow from the columns. Then brush a
|
|
45
|
+
range in any chart and every other chart filters to the rows inside it. The filtering
|
|
46
|
+
runs in the browser, in a crossfilter written in Rust and compiled to WebAssembly, so it
|
|
47
|
+
stays interactive on large tables. Python reads back what you selected.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install "spectacular-charts[notebook]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import spectacular as sp
|
|
57
|
+
|
|
58
|
+
df = sp.datasets.plate() # 2,400 readings of a 96-well plate
|
|
59
|
+
|
|
60
|
+
w = sp.view({
|
|
61
|
+
"title": "A 96-well growth plate",
|
|
62
|
+
"labels": {"od600": "OD600", "time_h": "time (h)"},
|
|
63
|
+
"charts": [
|
|
64
|
+
{"x": "time_h", "y": "od600", "color": "medium"}, # two numbers: a scatter
|
|
65
|
+
{"x": "medium"}, # a category: bars
|
|
66
|
+
{"x": "rate", "bins": 40}, # a number: a histogram
|
|
67
|
+
{"x": "medium", "y": "rate"}, # a category and a number: a strip
|
|
68
|
+
],
|
|
69
|
+
}, data=df)
|
|
70
|
+
w
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Brush the histogram, click a bar, and then, in the next cell:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
w.selection # {"selected": 380, "rows": 2400, "filters": [{"view": ..., "field": "rate", "range": [0.52, 0.61]}, ...]}
|
|
77
|
+
w.selected_data() # the brushed rows of df
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or skip Python altogether: after `import spectacular`, a cell can hold only the
|
|
81
|
+
description.
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
%%spectacular df
|
|
85
|
+
{"charts": [{"x-axis": "time_h", "y-axis": "od600", "color": "medium"}, {"x": "rate"}]}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Why describe charts?
|
|
89
|
+
|
|
90
|
+
- **No plotting code.** A description is plain data. `"x-axis"`, `"X axis"` and
|
|
91
|
+
`"x_axis"` are one key, and `od600` finds the column `OD600`.
|
|
92
|
+
- **Mistakes come back at the key you wrote**, with a suggestion:
|
|
93
|
+
`/charts/0/y: no column "od60"; did you mean "od600"?`.
|
|
94
|
+
- **Programs and models can write it.** The JSON is easy to generate and check, and
|
|
95
|
+
`sp.validate` returns problems as `{"path", "message"}`.
|
|
96
|
+
- **Linked by default.** Every chart in a description filters every other one.
|
|
97
|
+
|
|
98
|
+
## Twelve chart types
|
|
99
|
+
|
|
100
|
+
| | | |
|
|
101
|
+
|:-:|:-:|:-:|
|
|
102
|
+
|  **scatter**: two numbers |  **histogram**: one number |  **bars**: a category, split by another |
|
|
103
|
+
|  **strip**: a number by a category |  **matrix**: two categories |  **interval**: low to high |
|
|
104
|
+
|  **density**: two numbers, millions of rows |  **scatter3d**: three numbers |  **sankey**: edges from → to |
|
|
105
|
+
|  **layers**: a pipeline of steps |  **arc**: nodes on a line |  **network3d**: a graph in 3D |
|
|
106
|
+
|
|
107
|
+
How the type is chosen, and a description for each picture:
|
|
108
|
+
[Chart types](https://fullscreen-triangle.github.io/spectacular/guide/chart-types/).
|
|
109
|
+
|
|
110
|
+
## Figures and pages
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
sp.render(description, "figure.pdf", data=df, width=85, unit="mm") # SVG, PDF or PNG at print size
|
|
114
|
+
sp.save_html(description, "plate.html", data=df) # one offline, interactive file
|
|
115
|
+
w.save_svg("brushed.svg") # what the charts show now
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Themes: `"light"`, `"dark"`, `"paper"` (for print) and `"auto"`. Colours: a column, one
|
|
119
|
+
colour, a list, or a column's own palette shared by every chart. Category order:
|
|
120
|
+
`domains`.
|
|
121
|
+
|
|
122
|
+
## Install
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
pip install spectacular-charts # descriptions, validation, offline pages, the CLI
|
|
126
|
+
pip install "spectacular-charts[notebook]" # + interactive charts in Jupyter (anywidget)
|
|
127
|
+
pip install "spectacular-charts[render]" # + figures; then: python -m playwright install chromium
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The import name is `spectacular`. Wheels for Linux, macOS and Windows carry the browser
|
|
131
|
+
runtime and a native `spectacular` command (compiled Rust) that compiles descriptions,
|
|
132
|
+
validates specs and writes pages without Node:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
spectacular compile chart.json --data readings.csv # the view spec a description makes
|
|
136
|
+
spectacular validate spec.json --json # problems by path; exit 1 if any
|
|
137
|
+
spectacular html chart.json --data readings.csv -o readings.html
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Documentation
|
|
141
|
+
|
|
142
|
+
- **[Documentation](https://fullscreen-triangle.github.io/spectacular/)**: quickstart, guide, reference
|
|
143
|
+
- [Describing charts](https://fullscreen-triangle.github.io/spectacular/guide/describing/) and [every key](https://fullscreen-triangle.github.io/spectacular/reference/keys/)
|
|
144
|
+
- [Brushing and selections](https://fullscreen-triangle.github.io/spectacular/guide/selections/)
|
|
145
|
+
- [Python API](https://fullscreen-triangle.github.io/spectacular/reference/python/)
|
|
146
|
+
- [For AI agents](https://fullscreen-triangle.github.io/spectacular/for-ai/): the description language on one page
|
|
147
|
+
- [Changelog](https://github.com/fullscreen-triangle/spectacular/blob/rebuild/python/CHANGELOG.md)
|
|
148
|
+
|
|
149
|
+
Source, issues and the full view-spec format:
|
|
150
|
+
[github.com/fullscreen-triangle/spectacular](https://github.com/fullscreen-triangle/spectacular)
|
|
151
|
+
(branch `rebuild`). MIT licence.
|
|
152
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# spectacular-charts
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/spectacular-charts/)
|
|
4
|
+
[](https://pypi.org/project/spectacular-charts/)
|
|
5
|
+
[](https://fullscreen-triangle.github.io/spectacular/)
|
|
6
|
+
[](https://github.com/fullscreen-triangle/spectacular)
|
|
7
|
+
|
|
8
|
+
**Linked, crossfiltered charts for Python and Jupyter, described in JSON instead of
|
|
9
|
+
written as plotting code.**
|
|
10
|
+
|
|
11
|
+
Describe the charts you want, and the chart types follow from the columns. Then brush a
|
|
12
|
+
range in any chart and every other chart filters to the rows inside it. The filtering
|
|
13
|
+
runs in the browser, in a crossfilter written in Rust and compiled to WebAssembly, so it
|
|
14
|
+
stays interactive on large tables. Python reads back what you selected.
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install "spectacular-charts[notebook]"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import spectacular as sp
|
|
24
|
+
|
|
25
|
+
df = sp.datasets.plate() # 2,400 readings of a 96-well plate
|
|
26
|
+
|
|
27
|
+
w = sp.view({
|
|
28
|
+
"title": "A 96-well growth plate",
|
|
29
|
+
"labels": {"od600": "OD600", "time_h": "time (h)"},
|
|
30
|
+
"charts": [
|
|
31
|
+
{"x": "time_h", "y": "od600", "color": "medium"}, # two numbers: a scatter
|
|
32
|
+
{"x": "medium"}, # a category: bars
|
|
33
|
+
{"x": "rate", "bins": 40}, # a number: a histogram
|
|
34
|
+
{"x": "medium", "y": "rate"}, # a category and a number: a strip
|
|
35
|
+
],
|
|
36
|
+
}, data=df)
|
|
37
|
+
w
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Brush the histogram, click a bar, and then, in the next cell:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
w.selection # {"selected": 380, "rows": 2400, "filters": [{"view": ..., "field": "rate", "range": [0.52, 0.61]}, ...]}
|
|
44
|
+
w.selected_data() # the brushed rows of df
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or skip Python altogether: after `import spectacular`, a cell can hold only the
|
|
48
|
+
description.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
%%spectacular df
|
|
52
|
+
{"charts": [{"x-axis": "time_h", "y-axis": "od600", "color": "medium"}, {"x": "rate"}]}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Why describe charts?
|
|
56
|
+
|
|
57
|
+
- **No plotting code.** A description is plain data. `"x-axis"`, `"X axis"` and
|
|
58
|
+
`"x_axis"` are one key, and `od600` finds the column `OD600`.
|
|
59
|
+
- **Mistakes come back at the key you wrote**, with a suggestion:
|
|
60
|
+
`/charts/0/y: no column "od60"; did you mean "od600"?`.
|
|
61
|
+
- **Programs and models can write it.** The JSON is easy to generate and check, and
|
|
62
|
+
`sp.validate` returns problems as `{"path", "message"}`.
|
|
63
|
+
- **Linked by default.** Every chart in a description filters every other one.
|
|
64
|
+
|
|
65
|
+
## Twelve chart types
|
|
66
|
+
|
|
67
|
+
| | | |
|
|
68
|
+
|:-:|:-:|:-:|
|
|
69
|
+
|  **scatter**: two numbers |  **histogram**: one number |  **bars**: a category, split by another |
|
|
70
|
+
|  **strip**: a number by a category |  **matrix**: two categories |  **interval**: low to high |
|
|
71
|
+
|  **density**: two numbers, millions of rows |  **scatter3d**: three numbers |  **sankey**: edges from → to |
|
|
72
|
+
|  **layers**: a pipeline of steps |  **arc**: nodes on a line |  **network3d**: a graph in 3D |
|
|
73
|
+
|
|
74
|
+
How the type is chosen, and a description for each picture:
|
|
75
|
+
[Chart types](https://fullscreen-triangle.github.io/spectacular/guide/chart-types/).
|
|
76
|
+
|
|
77
|
+
## Figures and pages
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
sp.render(description, "figure.pdf", data=df, width=85, unit="mm") # SVG, PDF or PNG at print size
|
|
81
|
+
sp.save_html(description, "plate.html", data=df) # one offline, interactive file
|
|
82
|
+
w.save_svg("brushed.svg") # what the charts show now
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Themes: `"light"`, `"dark"`, `"paper"` (for print) and `"auto"`. Colours: a column, one
|
|
86
|
+
colour, a list, or a column's own palette shared by every chart. Category order:
|
|
87
|
+
`domains`.
|
|
88
|
+
|
|
89
|
+
## Install
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install spectacular-charts # descriptions, validation, offline pages, the CLI
|
|
93
|
+
pip install "spectacular-charts[notebook]" # + interactive charts in Jupyter (anywidget)
|
|
94
|
+
pip install "spectacular-charts[render]" # + figures; then: python -m playwright install chromium
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The import name is `spectacular`. Wheels for Linux, macOS and Windows carry the browser
|
|
98
|
+
runtime and a native `spectacular` command (compiled Rust) that compiles descriptions,
|
|
99
|
+
validates specs and writes pages without Node:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
spectacular compile chart.json --data readings.csv # the view spec a description makes
|
|
103
|
+
spectacular validate spec.json --json # problems by path; exit 1 if any
|
|
104
|
+
spectacular html chart.json --data readings.csv -o readings.html
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Documentation
|
|
108
|
+
|
|
109
|
+
- **[Documentation](https://fullscreen-triangle.github.io/spectacular/)**: quickstart, guide, reference
|
|
110
|
+
- [Describing charts](https://fullscreen-triangle.github.io/spectacular/guide/describing/) and [every key](https://fullscreen-triangle.github.io/spectacular/reference/keys/)
|
|
111
|
+
- [Brushing and selections](https://fullscreen-triangle.github.io/spectacular/guide/selections/)
|
|
112
|
+
- [Python API](https://fullscreen-triangle.github.io/spectacular/reference/python/)
|
|
113
|
+
- [For AI agents](https://fullscreen-triangle.github.io/spectacular/for-ai/): the description language on one page
|
|
114
|
+
- [Changelog](https://github.com/fullscreen-triangle/spectacular/blob/rebuild/python/CHANGELOG.md)
|
|
115
|
+
|
|
116
|
+
Source, issues and the full view-spec format:
|
|
117
|
+
[github.com/fullscreen-triangle/spectacular](https://github.com/fullscreen-triangle/spectacular)
|
|
118
|
+
(branch `rebuild`). MIT licence.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "spectacular"
|
|
3
|
+
description = "The spectacular command: compiles chart descriptions to view specs, validates specs, writes standalone pages"
|
|
4
|
+
version.workspace = true
|
|
5
|
+
edition.workspace = true
|
|
6
|
+
authors.workspace = true
|
|
7
|
+
license.workspace = true
|
|
8
|
+
repository.workspace = true
|
|
9
|
+
|
|
10
|
+
[[bin]]
|
|
11
|
+
name = "spectacular"
|
|
12
|
+
path = "src/main.rs"
|
|
13
|
+
|
|
14
|
+
[dependencies]
|
|
15
|
+
# preserve_order: problems are reported in the order keys appear, as the TypeScript validator does.
|
|
16
|
+
serde_json = { version = "1", features = ["preserve_order"] }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Embeds the browser runtime (built by `npm run build:python`) so `spectacular html` can
|
|
2
|
+
// write standalone pages. Without it the binary still compiles and validates.
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
fn main() {
|
|
6
|
+
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../python/src/spectacular/static/spectacular.js");
|
|
7
|
+
let out = Path::new(&std::env::var("OUT_DIR").unwrap()).join("runtime.js");
|
|
8
|
+
println!("cargo:rerun-if-changed={}", src.display());
|
|
9
|
+
let runtime = std::fs::read_to_string(&src).unwrap_or_default();
|
|
10
|
+
std::fs::write(out, runtime).unwrap();
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//! The colours a spec may name, the same list as `packages/viz/src/colors.ts`.
|
|
2
|
+
|
|
3
|
+
/// CSS colour names.
|
|
4
|
+
pub const COLOR_NAMES: &[&str] = &[
|
|
5
|
+
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black",
|
|
6
|
+
"blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse",
|
|
7
|
+
"chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue",
|
|
8
|
+
"darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki",
|
|
9
|
+
"darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon",
|
|
10
|
+
"darkseagreen", "darkslateblue", "darkslategray", "darkslategrey", "darkturquoise",
|
|
11
|
+
"darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", "dodgerblue", "firebrick",
|
|
12
|
+
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod",
|
|
13
|
+
"gray", "green", "greenyellow", "grey", "honeydew", "hotpink", "indianred", "indigo",
|
|
14
|
+
"ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue",
|
|
15
|
+
"lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightgrey",
|
|
16
|
+
"lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
|
|
17
|
+
"lightslategrey", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
|
|
18
|
+
"maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
|
|
19
|
+
"mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
|
|
20
|
+
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite",
|
|
21
|
+
"navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod",
|
|
22
|
+
"palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink",
|
|
23
|
+
"plum", "powderblue", "purple", "rebeccapurple", "red", "rosybrown", "royalblue",
|
|
24
|
+
"saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver",
|
|
25
|
+
"skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen", "steelblue", "tan",
|
|
26
|
+
"teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", "whitesmoke",
|
|
27
|
+
"yellow", "yellowgreen",
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
/// Most categories a palette may hold; the point shaders keep ten colours.
|
|
31
|
+
pub const MAX_PALETTE: usize = 10;
|
|
32
|
+
|
|
33
|
+
/// Most colours a field's palette may hold; the point shaders keep this many.
|
|
34
|
+
pub const MAX_FIELD_PALETTE: usize = 32;
|
|
35
|
+
|
|
36
|
+
/// True for "#rgb", "#rrggbb" or a CSS colour name, in any letter case.
|
|
37
|
+
pub fn is_color(value: &str) -> bool {
|
|
38
|
+
if let Some(hex) = value.strip_prefix('#') {
|
|
39
|
+
return (hex.len() == 3 || hex.len() == 6) && hex.chars().all(|c| c.is_ascii_hexdigit());
|
|
40
|
+
}
|
|
41
|
+
let lower = value.to_ascii_lowercase();
|
|
42
|
+
COLOR_NAMES.contains(&lower.as_str())
|
|
43
|
+
}
|