Skip to content

Commit

Permalink
Upgrade annotation feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Rosenau authored and Nick Rosenau committed Nov 27, 2023
1 parent ea558f2 commit 06c228e
Show file tree
Hide file tree
Showing 69 changed files with 115 additions and 7 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,35 @@ The name of the sequence/plasmid. Shown at the center of the circular viewer.

An array of `Annotation`s to render. Each `Annotation` requires 0-based start (inclusive) and end (exclusive) indexes. `name`s are rendered on top of the annotations. Set the annotation's direction to `1` for forward arrows and `-1` for reverse arrows.

Optional Parameters:
- Annotation border styling: `"dashed" | "dotted" | "bold"`
```js
annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: "dashed"},
];
```
- Annotation font styling; user can change font family, font weight, or font color:
```js
annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: "dashed", font: {"fontFamily": "Times New Roman", "fontWeight": 800, "fontSize": 17, "fontColor": "red"}},
];
```
- Adding an svg icon to annotation; the available icons are part of the SBOL library and can be viewed in the `assets` folder under `src/assets/`, the name of the desired icon must exactly match the filename of the icon in the `assets` folder:
```js
annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: "dashed", font: {"fontFamily": "Times New Roman", "fontWeight": 800, "fontSize": 17, "fontColor": "red"}},
svg: 'promoter'
];
```
here `promoter` matches the name of the promoter icon file `promoter.png`
- Annotation background color gradient. User can enter a starting color and stopping color:
```js
annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: "dashed", font: {"fontFamily": "Times New Roman", "fontWeight": 800, "fontSize": 17, "fontColor": "red"}},
svg: 'promoter', gradient: {start: 'lightblue', stop: 'green'}
];
```

```js
annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1 }, // [0, 22)
Expand Down
64 changes: 60 additions & 4 deletions src/Linear/Annotations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ const SingleNamedElement = (props: {
}

// 0.591 is our best approximation of Roboto Mono's aspect ratio (width / height).
const fontSize = 12;
let fontSize = 12;
if (element.font?.fontSize) {
fontSize = element.font.fontSize;
}
const annotationCharacterWidth = 0.591 * fontSize;
const availableCharacters = Math.floor((width - 40) / annotationCharacterWidth);

Expand All @@ -198,10 +201,54 @@ const SingleNamedElement = (props: {
}
}

let strokeVal: string | null = null;
let strokeWidth: string | null = null;

if (element.border) {
switch (element.border) {
case "dashed":
strokeVal = "5, 5";
break;
case "dotted":
strokeVal = "1, 5";
break;
case "bold":
strokeWidth = "2";
break;
}
}

let fontFamily: string | undefined = undefined;
let fontWeight: number = 400;
let fontColor: string = "rgb(42, 42, 42)";

if (element.font?.fontFamily) {
fontFamily = element.font.fontFamily;
}
if (element.font?.fontWeight) {
fontWeight = element.font.fontWeight;
}
if (element.font?.fontColor) {
fontColor = element.font.fontColor;
}

let svg: any = null;
if (element.svg) {
svg = require(`../assets/${element.svg}.png`);
}

return (
<g id={element.id} transform={`translate(${x}, ${0.1 * height})`}>
{/* <title> provides a hover tooltip on most browsers */}
<title>{name}</title>
{element.gradient && (
<defs>
<linearGradient id="myGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color={element.gradient.start} />
<stop offset="100%" stop-color={element.gradient.stop} />
</linearGradient>
</defs>
)}
<path
ref={inputRef(element.id, {
end: end,
Expand All @@ -214,10 +261,12 @@ const SingleNamedElement = (props: {
className={`${element.id} la-vz-annotation`}
cursor="pointer"
d={linePath}
fill={color}
fill={element.gradient ? "url(#myGradient)" : color}
id={element.id}
stroke={color ? COLOR_BORDER_MAP[color] || darkerColor(color) : "gray"}
style={annotation}
style={{ annotation }}
stroke-dasharray={strokeVal}
stroke-width={strokeWidth}
onBlur={() => {
// do nothing
}}
Expand All @@ -227,13 +276,20 @@ const SingleNamedElement = (props: {
onMouseOut={() => hoverOtherAnnotationRows(element.id, 0.7)}
onMouseOver={() => hoverOtherAnnotationRows(element.id, 1.0)}
/>
<image
href={svg ? String(svg.default.src) : undefined}
x={width / 2 - (width / 2) * 0.6}
y={height / 2 - 8}
width="15px"
height="15px"
/>
<text
className="la-vz-annotation-label"
cursor="pointer"
dominantBaseline="middle"
fontSize={fontSize}
id={element.id}
style={annotationLabel}
style={{ ...annotationLabel, fontFamily, fontWeight, fill: fontColor }}
textAnchor="middle"
x={width / 2}
y={height / 2 + 1}
Expand Down
Binary file added src/assets/aptamer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/assembly-scar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/association.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/blunt-restriction-site.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/cds-arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/cds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/chromosomal-locus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/circular-plasmid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/complex-sbgn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/composite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/degradation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/dissociation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/dna-stability-element.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/dsNA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/engineered-region.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/five-prime-overhang.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/five-prime-sticky-restriction-site.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/generic-sbgn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/halfround-rectangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/inert-dna-spacer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/inhibition.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/insulator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/intron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/location-dna-no-top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/location-dna.png
Binary file added src/assets/location-protein-no-top.png
Binary file added src/assets/location-protein.png
Binary file added src/assets/location-rna-no-top.png
Binary file added src/assets/location-rna.png
Binary file added src/assets/macromolecule.png
Binary file added src/assets/na-sbgn.png
Binary file added src/assets/ncrna.png
Binary file added src/assets/no-glyph-assigned.png
Binary file added src/assets/nuclease-site.png
Binary file added src/assets/omitted-detail.png
Binary file added src/assets/operator.png
Binary file added src/assets/origin-of-replication.png
Binary file added src/assets/origin-of-transfer.png
Binary file added src/assets/polyA.png
Binary file added src/assets/polypeptide-region.png
Binary file added src/assets/primer-binding-site.png
Binary file added src/assets/process.png
Binary file added src/assets/promoter.png
Binary file added src/assets/protease-site.png
Binary file added src/assets/protein-stability-element.png
Binary file added src/assets/protein.png
Binary file added src/assets/replacement-glyph.png
Binary file added src/assets/ribonuclease-site.png
Binary file added src/assets/ribosome-entry-site.png
Binary file added src/assets/rna-stability-element.png
Binary file added src/assets/signature.png
Binary file added src/assets/simple-chemical-circle.png
Binary file added src/assets/simple-chemical-hexagon.png
Binary file added src/assets/simple-chemical-pentagon.png
Binary file added src/assets/simple-chemical-triangle.png
Binary file added src/assets/specific-recombination-site.png
Binary file added src/assets/ssNA.png
Binary file added src/assets/stimulation.png
Binary file added src/assets/terminator.png
Binary file added src/assets/three-prime-overhang.png
Binary file added src/assets/three-prime-sticky-restriction-site.png
Binary file added src/assets/transcription-end.png
Binary file added src/assets/translation-end.png
Binary file added src/assets/unspecified-glyph.png
20 changes: 20 additions & 0 deletions src/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ export interface NameRange extends Range {
color?: string;
id: string;
name: string;
border?: "dashed" | "dotted" | "bold";
font?: Font;
svg?: string;
gradient?: Gradient;
}

interface Font {
fontFamily?: string;
fontSize: number;
fontWeight: number;
fontColor: string;
}

interface Gradient {
start: string;
stop: string;
}

/** AnnotationProp is an annotation provided to SeqViz via the annotations prop. */
export interface AnnotationProp {
color?: string;
border?: "dashed" | "dotted" | "bold";
font?: Font;
svg?: string;
gradient?: Gradient;
direction?: number | string;
end: number;
name: string;
Expand Down
9 changes: 6 additions & 3 deletions src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const svgText: CSS.Properties = {
MozUserSelect: "none",
WebkitUserSelect: "none",
background: "none",
fill: "rgb(42, 42, 42)",
fontFamily: "Roboto Mono, Monaco, monospace",
msUserSelect: "none",
userSelect: "none",
Expand Down Expand Up @@ -98,8 +97,6 @@ export const annotation: CSS.Properties = {

export const annotationLabel: CSS.Properties = {
...svgText,
color: "rgb(42, 42, 42)",
fontWeight: 400,
shapeRendering: "geometricPrecision",
strokeLinejoin: "round",
textRendering: "optimizeLegibility",
Expand Down Expand Up @@ -151,3 +148,9 @@ export const seqBlock: CSS.Properties = {
padding: 0,
width: "100%",
};

export const iconStyle: CSS.Properties = {
width: "25px",
height: "25px",
zIndex: 100,
};

0 comments on commit 06c228e

Please sign in to comment.