@jbrowse/plugin-canvas 4.0.4 → 4.1.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.
@@ -1 +1 @@
1
- export declare function drawChevrons(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, strand: number, color: string, spacing?: number, size?: number): void;
1
+ export declare function drawChevrons(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, strand: number, color: string, canvasWidth: number, spacing?: number, size?: number): void;
@@ -1,4 +1,4 @@
1
- export function drawChevrons(ctx, x, y, width, strand, color, spacing = 40, size = 4) {
1
+ export function drawChevrons(ctx, x, y, width, strand, color, canvasWidth, spacing = 40, size = 4) {
2
2
  if (strand === 0 || width < spacing) {
3
3
  return;
4
4
  }
@@ -10,6 +10,9 @@ export function drawChevrons(ctx, x, y, width, strand, color, spacing = 40, size
10
10
  const startOffset = (width - numChevrons * spacing) / 2 + spacing / 2;
11
11
  for (let i = 0; i < numChevrons; i++) {
12
12
  const cx = x + startOffset + i * spacing;
13
+ if (cx + halfSize < 0 || cx - halfSize > canvasWidth) {
14
+ continue;
15
+ }
13
16
  if (strand === 1) {
14
17
  ctx.moveTo(cx - halfSize, y - halfSize);
15
18
  ctx.lineTo(cx + halfSize, y);
@@ -14,9 +14,9 @@ export const boxGlyph = {
14
14
  },
15
15
  layout(args) {
16
16
  const { feature, bpPerPx, reversed, configContext } = args;
17
- const { config, displayMode, featureHeight } = configContext;
17
+ const { config, featureHeight, heightMultiplier } = configContext;
18
18
  const height = readCachedConfig(featureHeight, config, 'height', feature);
19
- const baseHeight = displayMode === 'compact' ? height / 2 : height;
19
+ const baseHeight = height * heightMultiplier;
20
20
  const width = (feature.get('end') - feature.get('start')) / bpPerPx;
21
21
  const isTopLevel = !feature.parent?.();
22
22
  const strand = feature.get('strand');
@@ -12,9 +12,9 @@ export const cdsGlyph = {
12
12
  },
13
13
  layout(args) {
14
14
  const { feature, bpPerPx, configContext } = args;
15
- const { config, displayMode, featureHeight } = configContext;
15
+ const { config, featureHeight, heightMultiplier } = configContext;
16
16
  const height = readCachedConfig(featureHeight, config, 'height', feature);
17
- const baseHeight = displayMode === 'compact' ? height / 2 : height;
17
+ const baseHeight = height * heightMultiplier;
18
18
  const width = (feature.get('end') - feature.get('start')) / bpPerPx;
19
19
  return {
20
20
  feature,
@@ -14,9 +14,9 @@ export function getStrandArrowPadding(strand, reversed) {
14
14
  }
15
15
  export function layoutChild(child, parentFeature, args, glyphType = 'Box') {
16
16
  const { bpPerPx, reversed, configContext } = args;
17
- const { config, displayMode, featureHeight } = configContext;
17
+ const { config, featureHeight, heightMultiplier } = configContext;
18
18
  const heightPx = readCachedConfig(featureHeight, config, 'height', child);
19
- const baseHeightPx = displayMode === 'compact' ? heightPx / 2 : heightPx;
19
+ const baseHeightPx = heightPx * heightMultiplier;
20
20
  const childStart = child.get('start');
21
21
  const childEnd = child.get('end');
22
22
  const parentStart = parentFeature.get('start');
@@ -110,7 +110,7 @@ export function drawSegmentedFeature(ctx, layout, dc, boxGlyph, cdsGlyph) {
110
110
  const strand = feature.get('strand');
111
111
  if (strand) {
112
112
  const effectiveStrand = reversed ? -strand : strand;
113
- drawChevrons(ctx, left, top + height / 2, width, effectiveStrand, strokeColor);
113
+ drawChevrons(ctx, left, top + height / 2, width, effectiveStrand, strokeColor, canvasWidth);
114
114
  }
115
115
  }
116
116
  for (const childLayout of children) {
@@ -56,11 +56,11 @@ export const matureProteinRegionGlyph = {
56
56
  },
57
57
  layout(args) {
58
58
  const { feature, bpPerPx, configContext } = args;
59
- const { config, displayMode, featureHeight, subfeatureLabels } = configContext;
59
+ const { config, featureHeight, heightMultiplier, subfeatureLabels } = configContext;
60
60
  const start = feature.get('start');
61
61
  const end = feature.get('end');
62
62
  const heightPx = readCachedConfig(featureHeight, config, 'height', feature);
63
- const baseHeightPx = displayMode === 'compact' ? heightPx / 2 : heightPx;
63
+ const baseHeightPx = heightPx * heightMultiplier;
64
64
  const widthPx = (end - start) / bpPerPx;
65
65
  const matureProteins = getMatureProteinChildren(feature);
66
66
  const children = matureProteins.map(child => layoutChild(child, feature, args));
@@ -20,11 +20,11 @@ export const processedTranscriptGlyph = {
20
20
  },
21
21
  layout(args) {
22
22
  const { feature, bpPerPx, reversed, configContext } = args;
23
- const { config, displayMode, featureHeight } = configContext;
23
+ const { config, featureHeight, heightMultiplier } = configContext;
24
24
  const start = feature.get('start');
25
25
  const end = feature.get('end');
26
26
  const heightPx = readCachedConfig(featureHeight, config, 'height', feature);
27
- const baseHeightPx = displayMode === 'compact' ? heightPx / 2 : heightPx;
27
+ const baseHeightPx = heightPx * heightMultiplier;
28
28
  const widthPx = (end - start) / bpPerPx;
29
29
  const strand = feature.get('strand');
30
30
  const arrowPadding = getStrandArrowPadding(strand, reversed);
@@ -33,11 +33,11 @@ export const repeatRegionGlyph = {
33
33
  },
34
34
  layout(args) {
35
35
  const { feature, bpPerPx, reversed, configContext } = args;
36
- const { config, displayMode, featureHeight } = configContext;
36
+ const { config, featureHeight, heightMultiplier } = configContext;
37
37
  const start = feature.get('start');
38
38
  const end = feature.get('end');
39
39
  const heightPx = readCachedConfig(featureHeight, config, 'height', feature);
40
- const baseHeightPx = displayMode === 'compact' ? heightPx / 2 : heightPx;
40
+ const baseHeightPx = heightPx * heightMultiplier;
41
41
  const widthPx = (end - start) / bpPerPx;
42
42
  const strand = feature.get('strand');
43
43
  const arrowPadding = getStrandArrowPadding(strand, reversed);
@@ -32,11 +32,11 @@ export const segmentsGlyph = {
32
32
  },
33
33
  layout(args) {
34
34
  const { feature, bpPerPx, reversed, configContext } = args;
35
- const { config, displayMode, featureHeight } = configContext;
35
+ const { config, featureHeight, heightMultiplier } = configContext;
36
36
  const start = feature.get('start');
37
37
  const end = feature.get('end');
38
38
  const heightPx = readCachedConfig(featureHeight, config, 'height', feature);
39
- const baseHeightPx = displayMode === 'compact' ? heightPx / 2 : heightPx;
39
+ const baseHeightPx = heightPx * heightMultiplier;
40
40
  const widthPx = (end - start) / bpPerPx;
41
41
  const strand = feature.get('strand');
42
42
  const arrowPadding = getStrandArrowPadding(strand, reversed);
@@ -41,13 +41,13 @@ export const subfeaturesGlyph = {
41
41
  },
42
42
  layout(args) {
43
43
  const { feature, bpPerPx, reversed, configContext } = args;
44
- const { config, displayMode, featureHeight, geneGlyphMode, transcriptTypes, } = configContext;
44
+ const { config, featureHeight, heightMultiplier, geneGlyphMode, transcriptTypes, } = configContext;
45
45
  const featureBp = {
46
46
  start: feature.get('start'),
47
47
  end: feature.get('end'),
48
48
  };
49
49
  const heightPx = readCachedConfig(featureHeight, config, 'height', feature);
50
- const baseHeightPx = displayMode === 'compact' ? heightPx / 2 : heightPx;
50
+ const baseHeightPx = heightPx * heightMultiplier;
51
51
  const widthPx = (featureBp.end - featureBp.start) / bpPerPx;
52
52
  let subfeatures = [...(feature.get('subfeatures') || [])];
53
53
  const codingStatus = new Map(subfeatures.map(f => [f.id(), hasCodingSubfeature(f)]));
@@ -2,7 +2,7 @@ import { readConfObject } from '@jbrowse/core/configuration';
2
2
  import { createJBrowseTheme } from '@jbrowse/core/ui';
3
3
  import { bpToPx } from '@jbrowse/core/util';
4
4
  import Flatbush from '@jbrowse/core/util/flatbush';
5
- import { checkStopToken2, createStopTokenChecker, } from '@jbrowse/core/util/stopToken';
5
+ import { checkStopToken2 } from '@jbrowse/core/util/stopToken';
6
6
  import { drawFeature } from "./drawFeature.js";
7
7
  import { buildChildrenIndex, convertToCanvasCoords, } from "./layout/layoutUtils.js";
8
8
  function buildFlatbush(coords, count) {
@@ -19,7 +19,7 @@ function buildFlatbush(coords, count) {
19
19
  return fb;
20
20
  }
21
21
  export function makeImageData({ ctx, layoutRecords, canvasWidth, renderArgs, configContext, }) {
22
- const { bpPerPx, regions, theme: configTheme, stopToken, layout, peptideDataMap, colorByCDS, pluginManager, } = renderArgs;
22
+ const { bpPerPx, regions, theme: configTheme, stopTokenCheck, layout, peptideDataMap, colorByCDS, pluginManager, } = renderArgs;
23
23
  const region = regions[0];
24
24
  const theme = createJBrowseTheme(configTheme);
25
25
  const drawContext = {
@@ -38,7 +38,6 @@ export function makeImageData({ ctx, layoutRecords, canvasWidth, renderArgs, con
38
38
  ctx.textBaseline = 'top';
39
39
  ctx.textAlign = 'left';
40
40
  const { subfeatureLabels, transcriptTypes, config } = configContext;
41
- const lastCheck = createStopTokenChecker(stopToken);
42
41
  for (const record of layoutRecords) {
43
42
  const { feature, layout: featureLayout, topPx: recordTopPx, label, description, } = record;
44
43
  const featureStartBp = feature.get(region.reversed ? 'end' : 'start');
@@ -78,7 +77,7 @@ export function makeImageData({ ctx, layoutRecords, canvasWidth, renderArgs, con
78
77
  labelColor: theme.palette.text.primary,
79
78
  parentTooltip: tooltip,
80
79
  });
81
- checkStopToken2(lastCheck);
80
+ checkStopToken2(stopTokenCheck);
82
81
  }
83
82
  return {
84
83
  flatbush: buildFlatbush(coords, items.length).data,
@@ -22,5 +22,6 @@ export interface RenderConfigContext {
22
22
  labelAllowed: boolean;
23
23
  geneGlyphMode: string;
24
24
  displayDirectionalChevrons: boolean;
25
+ heightMultiplier: number;
25
26
  }
26
27
  export declare function createRenderConfigContext(config: AnyConfigurationModel): RenderConfigContext;
@@ -12,6 +12,12 @@ function createCachedConfig(config, key, defaultValue) {
12
12
  const value = isCallback ? defaultValue : readConfObject(config, key);
13
13
  return { value, isCallback };
14
14
  }
15
+ function getHeightMultiplier(displayMode) {
16
+ if (displayMode === 'compact') {
17
+ return 0.5;
18
+ }
19
+ return 1;
20
+ }
15
21
  export function createRenderConfigContext(config) {
16
22
  const displayMode = readConfObject(config, 'displayMode');
17
23
  return {
@@ -31,5 +37,6 @@ export function createRenderConfigContext(config) {
31
37
  featureHeight: createCachedConfig(config, 'height', 10),
32
38
  fontHeight: createCachedConfig(config, ['labels', 'fontSize'], 12),
33
39
  labelAllowed: displayMode !== 'collapse',
40
+ heightMultiplier: getHeightMultiplier(displayMode),
34
41
  };
35
42
  }
@@ -1,7 +1,7 @@
1
1
  import type { RenderConfigContext } from './renderConfig.ts';
2
2
  import type PluginManager from '@jbrowse/core/PluginManager';
3
3
  import type { AnyConfigurationModel } from '@jbrowse/core/configuration';
4
- import type { Feature, Region } from '@jbrowse/core/util';
4
+ import type { Feature, LastStopTokenCheck, Region } from '@jbrowse/core/util';
5
5
  import type { BaseLayout } from '@jbrowse/core/util/layouts';
6
6
  import type { Theme } from '@mui/material';
7
7
  export interface SequenceData {
@@ -90,6 +90,7 @@ export interface RenderArgs {
90
90
  theme: Record<string, any>;
91
91
  highResolutionScaling?: number;
92
92
  stopToken?: string;
93
+ stopTokenCheck?: LastStopTokenCheck;
93
94
  peptideDataMap?: Map<string, PeptideData>;
94
95
  colorByCDS?: boolean;
95
96
  pluginManager?: PluginManager;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-canvas",
3
- "version": "4.0.4",
3
+ "version": "4.1.3",
4
+ "type": "module",
4
5
  "description": "JBrowse 2 plugin for canvas features",
5
6
  "keywords": [
6
7
  "jbrowse",
@@ -21,13 +22,13 @@
21
22
  ],
22
23
  "dependencies": {
23
24
  "@jbrowse/mobx-state-tree": "^5.5.0",
24
- "@mui/material": "^7.3.6",
25
+ "@mui/material": "^7.3.7",
25
26
  "g2p_mapper": "^2.0.0",
26
27
  "mobx": "^6.15.0",
27
28
  "mobx-react": "^9.2.1",
28
29
  "rxjs": "^7.8.2",
29
- "@jbrowse/core": "^4.0.4",
30
- "@jbrowse/plugin-linear-genome-view": "^4.0.4"
30
+ "@jbrowse/core": "^4.1.3",
31
+ "@jbrowse/plugin-linear-genome-view": "^4.1.3"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "react": ">=18.0.0"