allotaxonometer-ui 0.1.18 → 0.1.20
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.
- package/README.md +88 -126
- package/dist/allotax_wasm-I2pQx5pw.js +437 -0
- package/dist/allotaxonometer_wasm-CxvpCYab.js +371 -0
- package/dist/index.js +458 -159
- package/dist/ssr/assets/allotax_wasm-Bt0zsC7H.js +364 -0
- package/dist/ssr/index.js +595 -497
- package/dist/style.css +13 -2
- package/package.json +2 -2
- package/dist/allotaxonometer_wasm-g-Vv3OVu.js +0 -371
package/README.md
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
2
|
# Allotaxonometer UI
|
|
4
3
|
|
|
5
|
-
|
|
6
4
|
<img width="50%" alt="pipeline" src="https://github.com/user-attachments/assets/41375b5f-e942-499f-aea4-bca004767e52">
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
Headless UI components for allotaxonometer visualizations built with **Svelte 5**.
|
|
9
7
|
|
|
10
8
|
- Visit our [single-page web application](https://vermont-complex-systems.github.io/complex-stories/allotaxonometry) to try it out online.
|
|
11
|
-
- Use [
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
Headless UI components for allotaxonometer visualizations built with Svelte 5.
|
|
9
|
+
- Use [allotaxonometer-core](https://github.com/jstonge/allotaxonometer-core) for Rust/Python server-side computation.
|
|
10
|
+
- See the original [py-allotax](https://github.com/compstorylab/py-allotax) for the Python-only implementation.
|
|
15
11
|
|
|
16
12
|
## Installation
|
|
17
13
|
|
|
@@ -19,146 +15,112 @@ Headless UI components for allotaxonometer visualizations built with Svelte 5.
|
|
|
19
15
|
npm install allotaxonometer-ui
|
|
20
16
|
```
|
|
21
17
|
|
|
22
|
-
##
|
|
18
|
+
## Usage
|
|
23
19
|
|
|
24
|
-
-
|
|
25
|
-
- Running multiple or larger scale analyses: we recommend using the py-allotax, which details its install instructions, details the required data format, and provides examples in its repo.
|
|
20
|
+
### Client-side pipeline (Allotaxonograph class)
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
Compute everything in the browser using the built-in JS/WASM pipeline:
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+
```svelte
|
|
25
|
+
<script>
|
|
26
|
+
import { Allotaxonograph, Dashboard } from 'allotaxonometer-ui';
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
const instance = new Allotaxonograph(elem1, elem2, {
|
|
29
|
+
alpha: 0.58,
|
|
30
|
+
title: ['System 1', 'System 2']
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
let dat = $derived(instance?.dat);
|
|
34
|
+
let barData = $derived(instance?.barData);
|
|
35
|
+
let balanceData = $derived(instance?.balanceData);
|
|
36
|
+
</script>
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
| 3 | George | 4458 | 1161 | 0.0402 |
|
|
47
|
-
| 4 | Charles | 4061 | 1161 | 0.0366 |
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## Paper data
|
|
51
|
-
|
|
52
|
-
#### Babynames data
|
|
53
|
-
|
|
54
|
-
The original babyname dataset for boys and girls can be found on the [catalog.data.gov](https://catalog.data.gov/dataset?tags=baby-names) website. But we use the dataset [here](http://pdodds.w3.uvm.edu/permanent-share/pocs-babynames.zip) to replicate the original paper. You can find a 5-years aggregated version used in the `Observable` version in `data/`. The original dataset includes each year from 1880–2018, which have 5 or more applications. You can convert the original folder into the formatted `.json` file using R with the following command:
|
|
55
|
-
|
|
56
|
-
```R
|
|
57
|
-
read_and_write_babyname_dat <- function(fname, gender) {
|
|
58
|
-
d <- readr::read_csv(fname,
|
|
59
|
-
col_names = c("types", "gender", "counts"),
|
|
60
|
-
col_select = c("types", "counts"),
|
|
61
|
-
col_types = c("c", "i"))
|
|
62
|
-
|
|
63
|
-
d$probs <- d$counts / sum(d$counts)
|
|
64
|
-
d$total_unique <- nrow(d)
|
|
65
|
-
return(d)
|
|
66
|
-
}
|
|
67
|
-
# You need to be in the folder above `data/`, which is the unzip folder contained in
|
|
68
|
-
# http://pdodds.w3.uvm.edu/permanent-share/pocs-babynames.zip
|
|
69
|
-
purrr::map(
|
|
70
|
-
list.files("data/", pattern = "names-boys*"),
|
|
71
|
-
~read_and_write_babyname_dat(paste("data", .x, sep = "/"), "boys")
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
purrr::map(
|
|
75
|
-
list.files("data/", pattern = "names-girls*"),
|
|
76
|
-
~read_and_write_babyname_dat(paste("data", .x, sep = "/"), "girls")
|
|
77
|
-
)
|
|
38
|
+
<Dashboard {dat} {barData} {balanceData}
|
|
39
|
+
divnorm={instance.rtd.normalization}
|
|
40
|
+
alpha={0.58}
|
|
41
|
+
maxlog10={instance.maxlog10}
|
|
42
|
+
title={['System 1', 'System 2']}
|
|
43
|
+
/>
|
|
78
44
|
```
|
|
79
45
|
|
|
80
|
-
|
|
46
|
+
### Server-computed data (API adapter)
|
|
81
47
|
|
|
82
|
-
|
|
48
|
+
When using a backend that computes allotax results (e.g. via `allotaxonometer-core`), use `adaptDisplayResult` to map the API response to component-ready props:
|
|
83
49
|
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
cd storywrangling
|
|
87
|
-
pip install -e .
|
|
88
|
-
```
|
|
50
|
+
```js
|
|
51
|
+
import { adaptDisplayResult } from 'allotaxonometer-ui';
|
|
89
52
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
from storywrangling import Storywrangler
|
|
94
|
-
from datetime import datetime
|
|
95
|
-
import json
|
|
96
|
-
from pathlib import Path
|
|
97
|
-
|
|
98
|
-
def get_ngram(yr, month, day, fname=False):
|
|
99
|
-
storywrangler = Storywrangler()
|
|
100
|
-
ngram_zipf = storywrangler.get_zipf_dist(
|
|
101
|
-
date=datetime(yr, month, day),
|
|
102
|
-
lang="en", ngrams="1grams",
|
|
103
|
-
max_rank=10000, rt=False
|
|
104
|
-
).reset_index()\
|
|
105
|
-
.rename(columns={
|
|
106
|
-
"ngram":"types", "count":"counts", "count_no_rt":"counts_no_rt",
|
|
107
|
-
"rank":"rank", "rank_no_rt":"rank_no_rt", "freq":"probs", "freq_no_rt":"probs_no_rt"
|
|
108
|
-
})\
|
|
109
|
-
.dropna()\
|
|
110
|
-
.assign(totalunique = lambda x: x.shape[0])\
|
|
111
|
-
.loc[:, ["types", "counts", "totalunique", "probs"]]\
|
|
112
|
-
.to_dict(orient="index")
|
|
113
|
-
|
|
114
|
-
ngram_zipf = { f"{yr}_{month}_{day}": [_ for _ in ngram_zipf.values()] }
|
|
115
|
-
|
|
116
|
-
if fname:
|
|
117
|
-
if Path(fname).exists():
|
|
118
|
-
with open(fname) as f:
|
|
119
|
-
old_dat = json.load(f)
|
|
120
|
-
|
|
121
|
-
ngram_zipf.update(old_dat)
|
|
122
|
-
|
|
123
|
-
with open(fname, 'w') as f:
|
|
124
|
-
json.dump(ngram_zipf, f)
|
|
125
|
-
else:
|
|
126
|
-
return ngram_zipf
|
|
53
|
+
const apiResult = await fetch('/allotax?...').then(r => r.json());
|
|
54
|
+
const display = adaptDisplayResult(apiResult);
|
|
55
|
+
// display.dat, display.barData, display.balanceData, display.divnorm, display.maxlog10, etc.
|
|
127
56
|
```
|
|
128
57
|
|
|
129
|
-
|
|
58
|
+
### Multi-alpha (recommended for API usage)
|
|
130
59
|
|
|
131
|
-
|
|
60
|
+
Fetch all alpha values at once and switch instantly on the client:
|
|
132
61
|
|
|
133
|
-
|
|
62
|
+
```svelte
|
|
63
|
+
<script>
|
|
64
|
+
// Fetch once with all alphas — no refetch when alpha slider changes
|
|
65
|
+
const data = await fetch('/allotax?alphas=0,0.08,0.17,...').then(r => r.json());
|
|
66
|
+
// data.balance — shared across alphas
|
|
67
|
+
// data.alpha_results[i] — { diamond_counts, wordshift, normalization, alpha }
|
|
68
|
+
</script>
|
|
134
69
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
library(dplyr)
|
|
138
|
-
library("rlist")
|
|
139
|
-
library(jsonlite)
|
|
70
|
+
{@const slice = data.alpha_results[alphaIndex]}
|
|
71
|
+
{@const dat = { counts: slice.diamond_counts, deltas: [] }}
|
|
140
72
|
|
|
141
|
-
|
|
73
|
+
<Dashboard
|
|
74
|
+
{dat}
|
|
75
|
+
barData={slice.wordshift}
|
|
76
|
+
balanceData={data.balance}
|
|
77
|
+
divnorm={slice.normalization}
|
|
78
|
+
alpha={slice.alpha}
|
|
79
|
+
/>
|
|
80
|
+
```
|
|
142
81
|
|
|
82
|
+
## Components
|
|
143
83
|
|
|
84
|
+
| Component | Description |
|
|
85
|
+
|-----------|-------------|
|
|
86
|
+
| `Dashboard` | Main orchestrating component combining all visualizations |
|
|
87
|
+
| `Diamond` | Rank-rank scatter plot showing relationships between systems |
|
|
88
|
+
| `Wordshift` | Horizontal bar chart showing type contributions to divergence |
|
|
89
|
+
| `DivergingBarChart` | Bar chart for positive/negative shifts |
|
|
90
|
+
| `Legend` | Color and size legends |
|
|
144
91
|
|
|
145
|
-
|
|
92
|
+
## Data Input
|
|
146
93
|
|
|
94
|
+
The allotaxonometer expects 2 datasets with `types` and `counts`. The `totalunique` and `probs` fields are **optional** and will be calculated automatically if not provided.
|
|
147
95
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
count_df['probs']<-count_df['counts'] / nrow(alive_census)
|
|
157
|
-
tree_data[[i]] <- count_df
|
|
158
|
-
}
|
|
96
|
+
### Minimal Format (Recommended)
|
|
97
|
+
```javascript
|
|
98
|
+
const data = [{
|
|
99
|
+
types: ['John', 'William', 'James', 'George', 'Charles'],
|
|
100
|
+
counts: [8502, 7494, 5097, 4458, 4061]
|
|
101
|
+
// totalunique and probs calculated automatically!
|
|
102
|
+
}];
|
|
103
|
+
```
|
|
159
104
|
|
|
160
|
-
|
|
105
|
+
### Full Format
|
|
106
|
+
```javascript
|
|
107
|
+
const data = [{
|
|
108
|
+
types: ['John', 'William', 'James', 'George', 'Charles'],
|
|
109
|
+
counts: [8502, 7494, 5097, 4458, 4061],
|
|
110
|
+
totalunique: 1161,
|
|
111
|
+
probs: [0.0766, 0.0675, 0.0459, 0.0402, 0.0366]
|
|
112
|
+
}];
|
|
113
|
+
```
|
|
161
114
|
|
|
162
|
-
|
|
163
|
-
|
|
115
|
+
## Development
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm run build # Build library (includes WASM)
|
|
119
|
+
npm run build:wasm # Build Rust/WASM module only
|
|
120
|
+
npm run test:run # Run all tests once
|
|
121
|
+
npm test # Run tests in watch mode
|
|
164
122
|
```
|
|
123
|
+
|
|
124
|
+
## WASM Acceleration
|
|
125
|
+
|
|
126
|
+
The `rank_turbulence_divergence` computation is implemented in Rust/WASM for 3-4x speedup on datasets with 10K+ types. WASM loads eagerly but falls back to JavaScript if unavailable. See [WASM_IMPLEMENTATION.md](WASM_IMPLEMENTATION.md) for details.
|