geneviewer-js 0.0.0-stage → 0.3.0
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/LICENSE-THIRD-PARTY.md +19 -0
- package/LICENSE.md +21 -0
- package/README.md +220 -2
- package/dist/SHA256SUMS +11 -0
- package/dist/geneviewer.core.js +9017 -0
- package/dist/geneviewer.css +387 -0
- package/dist/geneviewer.d.ts +195 -0
- package/dist/geneviewer.min.js +417 -0
- package/dist/geneviewer.min.js.map +7 -0
- package/dist/geneviewer.mjs +8996 -0
- package/dist/geneviewer.standalone.mjs +417 -0
- package/dist/geneviewer.standalone.mjs.map +7 -0
- package/dist/geneviewerwidget.js +67 -0
- package/dist/spec.d.ts +1807 -0
- package/dist/themes.json +806 -0
- package/package.json +78 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Third-party material
|
|
2
|
+
|
|
3
|
+
## Font Awesome Free icons
|
|
4
|
+
|
|
5
|
+
The toolbar's default icons (download, rotate-left, rotate-right, house,
|
|
6
|
+
magnifying-glass-minus) are glyphs of Font Awesome Free 6.5.2 (solid), by
|
|
7
|
+
Fonticons, Inc., https://fontawesome.com. They are drawn as inline SVG paths,
|
|
8
|
+
in `src/lib/icons.js` and the built files in `dist/`.
|
|
9
|
+
|
|
10
|
+
The icons are licensed under the Creative Commons Attribution 4.0
|
|
11
|
+
International license (CC BY 4.0):
|
|
12
|
+
https://creativecommons.org/licenses/by/4.0/. Font Awesome's licence notice:
|
|
13
|
+
https://fontawesome.com/license/free.
|
|
14
|
+
|
|
15
|
+
## D3
|
|
16
|
+
|
|
17
|
+
`geneviewer.min.js` and `geneviewer.standalone.mjs` include D3 7.8.5,
|
|
18
|
+
https://d3js.org, copyright Mike Bostock, under the ISC license:
|
|
19
|
+
https://github.com/d3/d3/blob/main/LICENSE.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 geneviewer authors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,221 @@
|
|
|
1
|
-
#
|
|
1
|
+
# geneviewer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Interactive gene cluster, transcript and genome alignment charts in the
|
|
4
|
+
browser, drawn with D3. The same library draws the charts of the
|
|
5
|
+
[geneviewer R package](https://github.com/nvelden/geneviewer) and its Shiny
|
|
6
|
+
app.
|
|
7
|
+
|
|
8
|
+
**Docs and examples:** https://nvelden.github.io/geneviewer-js/
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install geneviewer-js
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or load it from a CDN, with D3 included:
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<script src="https://cdn.jsdelivr.net/npm/geneviewer-js@0.3/dist/geneviewer.min.js"></script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## A first chart
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<div id="chart" style="width: 800px; height: 300px"></div>
|
|
26
|
+
<script src="https://cdn.jsdelivr.net/npm/geneviewer-js@0.3/dist/geneviewer.min.js"></script>
|
|
27
|
+
<script>
|
|
28
|
+
const chart = geneviewer.newChart("#chart", {
|
|
29
|
+
version: 1,
|
|
30
|
+
data: [
|
|
31
|
+
{ cluster: "A", name: "geneA", start: 100, end: 900, class: "kinase" },
|
|
32
|
+
{ cluster: "A", name: "geneB", start: 1200, end: 2000, class: "transporter" },
|
|
33
|
+
{ cluster: "B", name: "geneA", start: 300, end: 1100, class: "kinase" },
|
|
34
|
+
],
|
|
35
|
+
fields: { cluster: "cluster", group: "class" },
|
|
36
|
+
labels: { label: "name" },
|
|
37
|
+
title: { title: "Two clusters" },
|
|
38
|
+
});
|
|
39
|
+
chart.on("click", (event) => console.log(event.detail));
|
|
40
|
+
</script>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
With a bundler (Vite, webpack, ...), import the ES module; it imports `d3`
|
|
44
|
+
from npm:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { newChart } from "geneviewer-js";
|
|
48
|
+
|
|
49
|
+
const chart = newChart(document.getElementById("chart"), spec);
|
|
50
|
+
chart.update({ title: { title: "New title" } });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The chart spec has one key per part of the chart (`genes`, `labels`,
|
|
54
|
+
`links`, `scale`, `theme`, ...); see the API reference on the docs site and
|
|
55
|
+
`dist/spec.d.ts`. The library adds its stylesheet to the page; on pages
|
|
56
|
+
whose Content-Security-Policy blocks that, pass `{ injectStyles: false }`
|
|
57
|
+
and load `geneviewer-js/geneviewer.css`.
|
|
58
|
+
|
|
59
|
+
## Files
|
|
60
|
+
|
|
61
|
+
| File | For |
|
|
62
|
+
|------|-----|
|
|
63
|
+
| `dist/geneviewer.min.js` | Script tag, global `geneviewer`, D3 included |
|
|
64
|
+
| `dist/geneviewer.mjs` | ES module for bundlers (`import ... from "geneviewer-js"`), imports `d3` |
|
|
65
|
+
| `dist/geneviewer.standalone.mjs` | ES module with D3 included (`geneviewer-js/standalone`) |
|
|
66
|
+
| `dist/geneviewer.core.js` | Script tag using the page's `d3`, not minified (the R package) |
|
|
67
|
+
| `dist/geneviewer.css` | The stylesheet, when styles cannot be added by script |
|
|
68
|
+
| `dist/geneviewer.d.ts`, `dist/spec.d.ts` | Types |
|
|
69
|
+
|
|
70
|
+
# Development
|
|
71
|
+
|
|
72
|
+
## Source
|
|
73
|
+
|
|
74
|
+
| File | What it is |
|
|
75
|
+
|------|------------|
|
|
76
|
+
| `src/lib/index.js` | Entry of the bundle: the public API, what the global `geneviewer` holds |
|
|
77
|
+
| `src/lib/chart.js` | `geneviewer.newChart()`: the chart, with its toolbar, zoom, selection, drag and undo/redo |
|
|
78
|
+
| `src/lib/container.js` | The container of one chart part; `components/*.js` add a method to it for each part drawn (genes, labels, legend, ...) |
|
|
79
|
+
| `src/lib/*.js` | Shared helpers: `util`, `style`, `text`, `color`, `scale`, `links` (and colour bar), `export` (SVG/PNG, save menu) |
|
|
80
|
+
| `src/styles.css` | Chart styles |
|
|
81
|
+
| `src/htmlwidgets/geneviewerwidget.js` | htmlwidgets binding used by the R package: calls `newChart` and sends events to Shiny |
|
|
82
|
+
|
|
83
|
+
The sources are ES modules, bundled by esbuild (`scripts/files.mjs`). The
|
|
84
|
+
code uses `d3` as a global; the ES module and bundled builds import it from
|
|
85
|
+
the `d3` package instead (`src/d3.js`).
|
|
86
|
+
|
|
87
|
+
## Build
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npm run check # syntax-check the sources
|
|
91
|
+
npm run build # write dist/ and dist/SHA256SUMS
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`npm run build` needs the dev dependencies (`npm ci`). It writes the four
|
|
95
|
+
builds (see "Files" above), `geneviewer.css`, `themes.json`, the R binding,
|
|
96
|
+
the type definitions and `SHA256SUMS`. `geneviewer.core.js` is not
|
|
97
|
+
minified, so the R package can ship readable source, as CRAN expects;
|
|
98
|
+
esbuild does drop the comments.
|
|
99
|
+
|
|
100
|
+
## Chart spec schema
|
|
101
|
+
|
|
102
|
+
`schema/spec-v1.schema.json` (JSON Schema 2020-12) defines the chart spec:
|
|
103
|
+
one top-level key per `GC_*` function of the R package, one property per
|
|
104
|
+
argument, in camelCase. `schema/NAMING.md` lists every R argument and its
|
|
105
|
+
spec name; the names were approved for spec v1, which is frozen at 1.0.0.
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
npm run schema:check # validate the schema, NAMING.md and schema/examples/
|
|
109
|
+
npm run spec:check # validate the spec.json R recorded for each fixture
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Types
|
|
113
|
+
|
|
114
|
+
`npm run build` also writes `dist/geneviewer.d.ts`, from the JSDoc in
|
|
115
|
+
`src/lib/`, and `dist/spec.d.ts`, from the schema. The source stays plain
|
|
116
|
+
JavaScript.
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
npm run types:test # compile test/types/ against the .d.ts files (in npm test)
|
|
120
|
+
npm run types:src # type-check src/lib/ (jsconfig.json); some errors remain
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Tests
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
npm test # all tests, in Docker
|
|
127
|
+
npm run test:update # write new baselines (only when output should change)
|
|
128
|
+
npm run test:smoke # the packed package in a plain page, a Vite project and TypeScript
|
|
129
|
+
Rscript scripts/export-fixtures.R # re-export fixtures from the R package
|
|
130
|
+
Rscript test/coverage.R # update test/coverage.md
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **Fixtures** (`test/fixtures/`): 206 charts exported from the R package:
|
|
134
|
+
its help-page examples, its vignettes and `test/charts.R`. Each has the
|
|
135
|
+
R code, the spec R recorded, the payload R sends to the browser, and
|
|
136
|
+
`render.txt`, a canonical listing of the drawn chart. `npm test` draws
|
|
137
|
+
every fixture and compares.
|
|
138
|
+
- **compile()** (`npm run test:compile`, in `npm test`): `compile(spec)`
|
|
139
|
+
equals R's payload for every fixture, apart from the approved exceptions
|
|
140
|
+
(docs/roadmap.md).
|
|
141
|
+
- **Interaction tests** (`test/interaction/`): scripted zoom, selection,
|
|
142
|
+
drag and undo/redo, with the chart and its events recorded after each
|
|
143
|
+
step.
|
|
144
|
+
- **Three modes:** fixtures and interaction tests run against the same
|
|
145
|
+
baselines through the R binding, as R draws charts, with
|
|
146
|
+
`geneviewer.newChart()` and R's payload, and with `newChart()` and the
|
|
147
|
+
spec (`test/harness/mount.js`); the fixtures also with the min build.
|
|
148
|
+
- **Chart methods** (`test/methods.mjs`): `select()`, `getSelection()`,
|
|
149
|
+
`undo()`, `redo()` and `download()`.
|
|
150
|
+
- **Save, two-chart and site checks** (`test/save.cjs`,
|
|
151
|
+
`test/two-charts.cjs`, `test/site.cjs`): the save menu downloads a valid
|
|
152
|
+
SVG and PNG; two charts on a page keep their own selection and undo
|
|
153
|
+
history; every chart on the docs site draws without errors.
|
|
154
|
+
- **Coverage** (`test/coverage.md`): every documented argument of the `GC_*`
|
|
155
|
+
chart functions is used by at least one fixture.
|
|
156
|
+
- **Fixed environment:** the tests run in a Docker image (`docker/`) with
|
|
157
|
+
pinned Chromium (Playwright) and fonts, because chart layout depends on
|
|
158
|
+
text measures. The image runs natively on arm64: on Apple silicon
|
|
159
|
+
locally, and on GitHub's `ubuntu-24.04-arm` runners in CI. Chrome under
|
|
160
|
+
amd64 emulation misreads numbers, so emulation is not supported.
|
|
161
|
+
|
|
162
|
+
## Trying a change in the Shiny app
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
npm run try-app # build, start the app, run the app's tests
|
|
166
|
+
npm run try-app -- --no-tests # build and start the app only
|
|
167
|
+
npm run try-app -- --r-tests # also run the R package's tests on the copy
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
This runs the [geneviewer Shiny app](https://github.com/nvelden/geneviewer-shinylive)
|
|
171
|
+
with the JavaScript from this repo:
|
|
172
|
+
|
|
173
|
+
- **Isolated:** the R package is copied to a temporary folder and the built
|
|
174
|
+
files replace its JavaScript there, so neither the R repo nor your R library
|
|
175
|
+
changes.
|
|
176
|
+
- **Tests:** the app starts at <http://127.0.0.1:4849/> and the app's
|
|
177
|
+
`tests/testthat` and `tests/browser` suites run against it. The browser
|
|
178
|
+
tests need `puppeteer`.
|
|
179
|
+
- **Left running:** the app stays up afterwards so you can try it by hand; the
|
|
180
|
+
script prints the command that stops it.
|
|
181
|
+
|
|
182
|
+
Set the two repo locations in a `.try-app.env` file (ignored by git):
|
|
183
|
+
|
|
184
|
+
```sh
|
|
185
|
+
GENEVIEWER_R_DIR="/path/to/geneviewer"
|
|
186
|
+
GENEVIEWER_APP_DIR="/path/to/geneviewer-shinylive"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Set `PORT` to use a port other than 4849.
|
|
190
|
+
|
|
191
|
+
## Releases
|
|
192
|
+
|
|
193
|
+
1. Bump `version` in `package.json` and `src/lib/chart.js` (`npm run check`
|
|
194
|
+
compares them).
|
|
195
|
+
2. Commit, then tag and push: `git tag v0.3.1 && git push origin main v0.3.1`.
|
|
196
|
+
|
|
197
|
+
The publish workflow tests and builds, publishes to npm with provenance,
|
|
198
|
+
and attaches `dist/` to a GitHub release.
|
|
199
|
+
|
|
200
|
+
## Using a release in the R package
|
|
201
|
+
|
|
202
|
+
The R package vendors a release: its copies of the files are stored in the R
|
|
203
|
+
repo and shipped inside the package, so users never download JavaScript
|
|
204
|
+
separately. A maintainer pulls a new release with:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
curl -sSLO https://github.com/nvelden/geneviewer-js/releases/download/v0.3.0/{geneviewer.core.js,geneviewer.css,themes.json,geneviewerwidget.js,SHA256SUMS}
|
|
208
|
+
shasum -a 256 -c SHA256SUMS --ignore-missing
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
They then copy the files into `inst/htmlwidgets/`. Do not edit those copies in
|
|
212
|
+
the R repo; make changes here and cut a new release.
|
|
213
|
+
|
|
214
|
+
## Roadmap
|
|
215
|
+
|
|
216
|
+
See [docs/roadmap.md](docs/roadmap.md).
|
|
217
|
+
|
|
218
|
+
## Licence
|
|
219
|
+
|
|
220
|
+
MIT. Copyright (c) 2023 geneviewer authors. The toolbar icons are Font
|
|
221
|
+
Awesome Free (CC BY 4.0); see LICENSE-THIRD-PARTY.md.
|
package/dist/SHA256SUMS
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
e78728da421c9b7bf3002d853fecd4497e27d8be4331fb391caab93722b4b724 geneviewer.core.js
|
|
2
|
+
d96c80adea1ce9ebe5323e153e4f1e014816ef37d502c849741d68f7b3fa6575 geneviewer.css
|
|
3
|
+
3a363a3b443504da4589aaf3102b00d8f488df77b6f358721f640f7befbf6c28 geneviewer.d.ts
|
|
4
|
+
45815b9a041648042911b03214c71412e02c2a79192ec581100ceea08d3572bd geneviewer.min.js
|
|
5
|
+
f8541286b4ed988290501a507a70633a714cf243181569526c219fa7c868d331 geneviewer.min.js.map
|
|
6
|
+
039077a86bff0ba3dbbec37578f468ee4f71c54c44a2f9126ae691e83d5b7f91 geneviewer.mjs
|
|
7
|
+
cf000dfc911a3e3302f2007f3e1fee132da4dfafd2f94dcc9c884fa772a23975 geneviewer.standalone.mjs
|
|
8
|
+
1025a3defe0032717b7fdd571dfc0f90df9696846066818f8a94079e103a8b23 geneviewer.standalone.mjs.map
|
|
9
|
+
0bc331bce739358f3150af8b1ad3851a4c4cbbf6763cc122fe3b41008b230020 geneviewerwidget.js
|
|
10
|
+
3d9a1611127c02a515da15b88c46f9da30e0f8ade676919e7502244aef4dd000 spec.d.ts
|
|
11
|
+
65ebaa72b864ba74fabc06aa02d858a0a621e5579dadc0c5d9d7add1ba48f246 themes.json
|