@jbrowse/plugin-dotplot-view 4.1.3 → 4.1.4

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.
@@ -1,5 +1,5 @@
1
1
  import type PluginManager from '@jbrowse/core/PluginManager';
2
2
  export default function DotplotDisplayF(pm: PluginManager): void;
3
- export declare function configSchemaFactory(pm: any): import("node_modules/@jbrowse/core/src/configuration/configurationSchema.ts").ConfigurationSchemaType<{
3
+ export declare function configSchemaFactory(pm: any): import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
4
4
  renderer: import("@jbrowse/mobx-state-tree").IOptionalIType<any, [undefined]>;
5
- }, import("node_modules/@jbrowse/core/src/configuration/configurationSchema.ts").ConfigurationSchemaOptions<undefined, "displayId">>;
5
+ }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "displayId">>;
@@ -1,4 +1,4 @@
1
- declare const _default: import("node_modules/@jbrowse/core/src/configuration/configurationSchema").ConfigurationSchemaType<{
1
+ declare const _default: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
2
2
  color: {
3
3
  type: string;
4
4
  description: string;
@@ -36,5 +36,5 @@ declare const _default: import("node_modules/@jbrowse/core/src/configuration/con
36
36
  defaultValue: string[];
37
37
  description: string;
38
38
  };
39
- }, import("node_modules/@jbrowse/core/src/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
39
+ }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
40
40
  export default _default;
@@ -2,9 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { Dialog, ErrorMessage } from '@jbrowse/core/ui';
4
4
  import { getSession, useLocalStorage } from '@jbrowse/core/util';
5
- import { Button, Checkbox, CircularProgress, DialogActions, DialogContent, FormControlLabel, MenuItem, TextField, Typography, } from '@mui/material';
6
- function LoadingMessage() {
7
- return (_jsxs("div", { children: [_jsx(CircularProgress, { size: 20, style: { marginRight: 20 } }), _jsx(Typography, { display: "inline", children: "Creating SVG" })] }));
5
+ import { Button, Checkbox, CircularProgress, DialogActions, DialogContent, FormControlLabel, MenuItem, TextField, ToggleButton, ToggleButtonGroup, Typography, } from '@mui/material';
6
+ function LoadingMessage({ format }) {
7
+ return (_jsxs("div", { children: [_jsx(CircularProgress, { size: 20, style: { marginRight: 20 } }), _jsxs(Typography, { display: "inline", children: ["Creating ", format.toUpperCase()] })] }));
8
8
  }
9
9
  function TextField2({ children, ...rest }) {
10
10
  return (_jsx("div", { children: _jsx(TextField, { ...rest, children: children }) }));
@@ -18,11 +18,22 @@ export default function ExportSvgDialog({ model, handleClose, }) {
18
18
  const [rasterizeLayers, setRasterizeLayers] = useState(offscreenCanvas);
19
19
  const [loading, setLoading] = useState(false);
20
20
  const [error, setError] = useState();
21
+ const [format, setFormat] = useSvgLocal('format', 'svg');
21
22
  const [filename, setFilename] = useSvgLocal('file', 'jbrowse.svg');
22
23
  const [themeName, setThemeName] = useSvgLocal('theme', session.themeName || 'default');
23
- return (_jsxs(Dialog, { open: true, onClose: handleClose, title: "Export SVG", children: [_jsxs(DialogContent, { children: [error ? (_jsx(ErrorMessage, { error: error })) : loading ? (_jsx(LoadingMessage, {})) : null, _jsx(TextField2, { helperText: "filename", value: filename, onChange: event => {
24
- setFilename(event.target.value);
25
- } }), session.allThemes ? (_jsx(TextField2, { select: true, label: "Theme", value: themeName, onChange: event => {
24
+ return (_jsxs(Dialog, { open: true, onClose: handleClose, title: "Export image", children: [_jsxs(DialogContent, { children: [error ? (_jsx(ErrorMessage, { error: error })) : loading ? (_jsx(LoadingMessage, { format: format })) : null, _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8 }, children: [_jsx(TextField, { helperText: "filename", value: filename, onChange: event => {
25
+ setFilename(event.target.value);
26
+ } }), _jsxs(ToggleButtonGroup, { value: format, exclusive: true, onChange: (_event, value) => {
27
+ if (value) {
28
+ setFormat(value);
29
+ if (filename.endsWith('.svg') && value === 'png') {
30
+ setFilename(filename.replace(/\.svg$/, '.png'));
31
+ }
32
+ else if (filename.endsWith('.png') && value === 'svg') {
33
+ setFilename(filename.replace(/\.png$/, '.svg'));
34
+ }
35
+ }
36
+ }, size: "small", children: [_jsx(ToggleButton, { value: "svg", children: "SVG" }), _jsx(ToggleButton, { value: "png", children: "PNG" })] })] }), session.allThemes ? (_jsx(TextField2, { select: true, label: "Theme", value: themeName, onChange: event => {
26
37
  setThemeName(event.target.value);
27
38
  }, children: Object.entries(session.allThemes()).map(([key, val]) => (_jsx(MenuItem, { value: key, children: val.name || '(Unknown name)' }, key))) })) : null, offscreenCanvas ? (_jsx(FormControlLabel, { control: _jsx(Checkbox, { checked: rasterizeLayers, onChange: () => {
28
39
  setRasterizeLayers(val => !val);
@@ -34,6 +45,7 @@ export default function ExportSvgDialog({ model, handleClose, }) {
34
45
  try {
35
46
  await model.exportSvg({
36
47
  rasterizeLayers,
48
+ format,
37
49
  filename,
38
50
  themeName,
39
51
  });
@@ -7,6 +7,7 @@ import type { Instance, SnapshotIn } from '@jbrowse/mobx-state-tree';
7
7
  type Coord = [number, number];
8
8
  export interface ExportSvgOptions {
9
9
  rasterizeLayers?: boolean;
10
+ format?: 'svg' | 'png';
10
11
  filename?: string;
11
12
  Wrapper?: React.FC<{
12
13
  children: React.ReactNode;
@@ -355,7 +355,38 @@ export default function stateModelFactory(pm) {
355
355
  const { renderToSvg } = await import("./svgcomponents/SVGDotplotView.js");
356
356
  const html = await renderToSvg(self, opts);
357
357
  const { saveAs } = await import('file-saver-es');
358
- saveAs(new Blob([html], { type: 'image/svg+xml' }), opts.filename || 'image.svg');
358
+ if (opts.format === 'png') {
359
+ const img = new Image();
360
+ const svgBlob = new Blob([html], { type: 'image/svg+xml' });
361
+ const url = URL.createObjectURL(svgBlob);
362
+ await new Promise((resolve, reject) => {
363
+ img.onload = () => {
364
+ const canvas = document.createElement('canvas');
365
+ canvas.width = img.width;
366
+ canvas.height = img.height;
367
+ const ctx = canvas.getContext('2d');
368
+ ctx.drawImage(img, 0, 0);
369
+ URL.revokeObjectURL(url);
370
+ canvas.toBlob(blob => {
371
+ if (blob) {
372
+ saveAs(blob, opts.filename || 'image.png');
373
+ resolve();
374
+ }
375
+ else {
376
+ reject(new Error(`Failed to create PNG. The image may be too large (${img.width}x${img.height}). Try reducing the view size or use SVG format.`));
377
+ }
378
+ }, 'image/png');
379
+ };
380
+ img.onerror = () => {
381
+ URL.revokeObjectURL(url);
382
+ reject(new Error('Failed to load SVG for PNG conversion'));
383
+ };
384
+ img.src = url;
385
+ });
386
+ }
387
+ else {
388
+ saveAs(new Blob([html], { type: 'image/svg+xml' }), opts.filename || 'image.svg');
389
+ }
359
390
  },
360
391
  beforeDestroy() {
361
392
  const session = getSession(self);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-dotplot-view",
3
- "version": "4.1.3",
3
+ "version": "4.1.4",
4
4
  "type": "module",
5
5
  "description": "JBrowse 2 dotplot view",
6
6
  "keywords": [
@@ -22,15 +22,15 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@jbrowse/mobx-state-tree": "^5.5.0",
25
- "@mui/icons-material": "^7.3.7",
26
- "@mui/material": "^7.3.7",
27
- "@mui/x-data-grid": "^8.26.0",
25
+ "@mui/icons-material": "^7.3.8",
26
+ "@mui/material": "^7.3.8",
27
+ "@mui/x-data-grid": "^8.27.1",
28
28
  "@types/file-saver-es": "^2.0.3",
29
29
  "file-saver-es": "^2.0.5",
30
30
  "mobx": "^6.15.0",
31
31
  "mobx-react": "^9.2.1",
32
- "@jbrowse/plugin-alignments": "^4.1.3",
33
- "@jbrowse/core": "^4.1.3"
32
+ "@jbrowse/core": "^4.1.4",
33
+ "@jbrowse/plugin-alignments": "^4.1.4"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": ">=18.0.0",