@vitessce/vega 2.0.3-beta.0 → 2.0.3

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.
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/vega",
3
- "version": "2.0.3-beta.0",
3
+ "version": "2.0.3",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -8,9 +8,10 @@
8
8
  "url": "git+https://github.com/vitessce/vitessce.git"
9
9
  },
10
10
  "license": "MIT",
11
- "main": "dist/index.js",
11
+ "main": "dist/index.mjs",
12
12
  "files": [
13
- "dist"
13
+ "dist",
14
+ "src"
14
15
  ],
15
16
  "dependencies": {
16
17
  "@material-ui/core": "~4.12.3",
@@ -28,8 +29,7 @@
28
29
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
29
30
  },
30
31
  "scripts": {
31
- "start": "tsc --watch",
32
- "build": "tsc",
32
+ "bundle": "pnpm exec vite build -c ../../scripts/vite.config.js",
33
33
  "test": "pnpm exec vitest --run -r ../../ --dir ."
34
34
  }
35
35
  }
File without changes
@@ -0,0 +1,62 @@
1
+ import React, { Suspense, useMemo } from 'react';
2
+ import { Handler } from 'vega-tooltip';
3
+ import ReactVega from './ReactVega';
4
+
5
+ // TODO: React.lazy is not working with Vitessce in the portal-ui.
6
+ // For now, we can work around this by not using React.lazy,
7
+ // but for performance benefits that come with lazy-loading
8
+ // we should eventually try to resolve this issue.
9
+ // const ReactVega = React.lazy(() => import('./ReactVega'));
10
+
11
+ export const DATASET_NAME = 'table';
12
+
13
+ function isVega(spec) {
14
+ return spec.$schema === 'https://vega.github.io/schema/vega/v5.json';
15
+ }
16
+
17
+ /**
18
+ * A wrapper around the react-vega Vega component.
19
+ * @param {object} props
20
+ * @param {object} spec A vega or vega-lite spec.
21
+ * @param {object[]} data The plot data as an array of objects.
22
+ * @param {object} signalListeners Vega signal listeners. Optional.
23
+ */
24
+ export function VegaPlot(props) {
25
+ const {
26
+ spec: partialSpec,
27
+ data,
28
+ signalListeners,
29
+ } = props;
30
+
31
+ const spec = useMemo(() => ({
32
+ ...partialSpec,
33
+ data: (isVega(partialSpec)
34
+ ? [
35
+ { name: DATASET_NAME },
36
+ ...partialSpec.data,
37
+ ]
38
+ : { name: DATASET_NAME }
39
+ ),
40
+ }), [partialSpec]);
41
+
42
+ const vegaComponent = useMemo(() => (
43
+ <ReactVega
44
+ spec={spec}
45
+ data={{
46
+ [DATASET_NAME]: data,
47
+ }}
48
+ signalListeners={signalListeners}
49
+ tooltip={new Handler().call}
50
+ renderer="canvas"
51
+ scaleFactor={3}
52
+ />
53
+ ), [spec, data, signalListeners]);
54
+
55
+ return (
56
+ spec && data && data.length > 0 ? (
57
+ <Suspense fallback={<div>Loading...</div>}>
58
+ {vegaComponent}
59
+ </Suspense>
60
+ ) : null
61
+ );
62
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { VegaPlot, DATASET_NAME } from './VegaPlot';
2
+ export { VEGA_THEMES } from './utils';
package/src/utils.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Vega-Lite themes that can be passed to the `config` property
3
+ * of the vega-lite spec.
4
+ */
5
+ export const VEGA_THEMES = {
6
+ dark: {
7
+ // The vega-themes dark theme.
8
+ // Reference: https://github.com/vega/vega-themes/blob/master/src/theme-dark.ts
9
+ background: null,
10
+ title: { color: '#fff' },
11
+ style: {
12
+ 'guide-label': {
13
+ fill: '#fff',
14
+ },
15
+ 'guide-title': {
16
+ fill: '#fff',
17
+ },
18
+ },
19
+ axis: {
20
+ domainColor: '#fff',
21
+ gridColor: '#888',
22
+ tickColor: '#fff',
23
+ },
24
+ },
25
+ light: {
26
+ // The default vega theme.
27
+ background: null,
28
+ },
29
+ };
package/dist/VegaPlot.js DELETED
@@ -1,36 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { Suspense, useMemo } from 'react';
3
- import { Handler } from 'vega-tooltip';
4
- import ReactVega from './ReactVega';
5
- // TODO: React.lazy is not working with Vitessce in the portal-ui.
6
- // For now, we can work around this by not using React.lazy,
7
- // but for performance benefits that come with lazy-loading
8
- // we should eventually try to resolve this issue.
9
- // const ReactVega = React.lazy(() => import('./ReactVega'));
10
- export const DATASET_NAME = 'table';
11
- function isVega(spec) {
12
- return spec.$schema === 'https://vega.github.io/schema/vega/v5.json';
13
- }
14
- /**
15
- * A wrapper around the react-vega Vega component.
16
- * @param {object} props
17
- * @param {object} spec A vega or vega-lite spec.
18
- * @param {object[]} data The plot data as an array of objects.
19
- * @param {object} signalListeners Vega signal listeners. Optional.
20
- */
21
- export function VegaPlot(props) {
22
- const { spec: partialSpec, data, signalListeners, } = props;
23
- const spec = useMemo(() => ({
24
- ...partialSpec,
25
- data: (isVega(partialSpec)
26
- ? [
27
- { name: DATASET_NAME },
28
- ...partialSpec.data,
29
- ]
30
- : { name: DATASET_NAME }),
31
- }), [partialSpec]);
32
- const vegaComponent = useMemo(() => (_jsx(ReactVega, { spec: spec, data: {
33
- [DATASET_NAME]: data,
34
- }, signalListeners: signalListeners, tooltip: new Handler().call, renderer: "canvas", scaleFactor: 3 })), [spec, data, signalListeners]);
35
- return (spec && data && data.length > 0 ? (_jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: vegaComponent })) : null);
36
- }
package/dist/utils.js DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * Vega-Lite themes that can be passed to the `config` property
3
- * of the vega-lite spec.
4
- */
5
- export const VEGA_THEMES = {
6
- dark: {
7
- // The vega-themes dark theme.
8
- // Reference: https://github.com/vega/vega-themes/blob/master/src/theme-dark.ts
9
- background: null,
10
- title: { color: '#fff' },
11
- style: {
12
- 'guide-label': {
13
- fill: '#fff',
14
- },
15
- 'guide-title': {
16
- fill: '#fff',
17
- },
18
- },
19
- axis: {
20
- domainColor: '#fff',
21
- gridColor: '#888',
22
- tickColor: '#fff',
23
- },
24
- },
25
- light: {
26
- // The default vega theme.
27
- background: null,
28
- },
29
- };