Skip to content

Commit

Permalink
removed svg feature for annotions. Added borderColor parameter for an…
Browse files Browse the repository at this point in the history
…notations, updated README and updated webpack since we won't need to import images anymore.
  • Loading branch information
Nick Rosenau authored and Nick Rosenau committed Nov 29, 2023
1 parent 0224fb3 commit 728e854
Show file tree
Hide file tree
Showing 69 changed files with 29 additions and 49 deletions.
22 changes: 4 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ annotations = [
In the example above, the "Strong promoter" would span the first to twenty-second base pair.

Optional Annotation Parameters:
- Annotation border styling: `"dashed" | "dotted" | "bold"`
- Annotation border styling; user can customize border style and border color:
```js
annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: "dashed"},
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: {style: "dashed", borderColor: 'purple'},
];
```
- Annotation font styling; user can change font family, font weight, or font color:
Expand All @@ -166,13 +166,8 @@ annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: "dashed", font: {fontFamily: "Times New Roman", fontWeight: 800, fontSize: 17, fontColor: 'blue'}},
];
```
- 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. In this example `promoter` matches the name of the promoter icon file `promoter.png`:
```js
annotations = [
{ start: 0, end: 22, name: "Strong promoter", direction: 1, border: "dashed", font: {fontFamily: "Times New Roman", fontWeight: 800, fontSize: 17, fontColor: 'blue'}},
svg: 'promoter'
];
```
- Adding an svg icon to annotation: WIP
- Annotation background color gradient. User can enter a starting color and stopping color:
```js
annotations = [
Expand All @@ -181,15 +176,6 @@ annotations = [
];
```
Example result of using optional annotation parameters:
```js
annotation['border'] = 'dashed';
annotation['font'] = {fontFamily: "Times New Roman", fontWeight: 800, fontSize: 17, fontColor: 'blue'}
annotation['svg'] = 'promoter'
annotation['gradient'] = {start: 'lightblue', stop: 'green'}
```
<img src="./demo/public/annotations-example.png" width="500" />

#### `primers (=[])`
An array of `Primer`s to render. Each `Primer` requires 0-based start (inclusive) and end (exclusive) indexes. `name`s are rendered on top of the primers. Set the primer's direction to `1` for forward primer and `-1` for reverse primer.
Expand Down
30 changes: 14 additions & 16 deletions src/Linear/Annotations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ const SingleNamedElement = (props: {
// 0.591 is our best approximation of Roboto Mono's aspect ratio (width / height).
let fontSize = 12;
if (element.font?.fontSize) {
fontSize = element.font.fontSize;
// 19 is a subjective limit to fontSize that will fit inside bounds of annotation. If larger than 19, cap it.
if(element.font.fontSize > 19){
fontSize = 19;
}
else{
fontSize = element.font.fontSize;
}
}
const annotationCharacterWidth = 0.591 * fontSize;
const availableCharacters = Math.floor((width - 40) / annotationCharacterWidth);
Expand All @@ -204,8 +210,8 @@ const SingleNamedElement = (props: {
let strokeVal: string | null = null;
let strokeWidth: string | null = null;

if (element.border) {
switch (element.border) {
if (element.border?.style) {
switch (element.border.style) {
case "dashed":
strokeVal = "5, 5";
break;
Expand All @@ -217,6 +223,10 @@ const SingleNamedElement = (props: {
break;
}
}
let borderColor:string | null = null
if (element.border?.borderColor) {
borderColor = element.border.borderColor
}

let fontFamily: string | undefined = undefined;
let fontWeight: number = 400;
Expand All @@ -232,11 +242,6 @@ const SingleNamedElement = (props: {
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 */}
Expand All @@ -263,7 +268,7 @@ const SingleNamedElement = (props: {
d={linePath}
fill={element.gradient ? "url(#myGradient)" : color}
id={element.id}
stroke={color ? COLOR_BORDER_MAP[color] || darkerColor(color) : "gray"}
stroke={borderColor ? borderColor : color ? COLOR_BORDER_MAP[color] || darkerColor(color) : "gray"}
style={{ annotation }}
stroke-dasharray={strokeVal}
stroke-width={strokeWidth}
Expand All @@ -276,13 +281,6 @@ 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"
Expand Down
Binary file removed src/assets/aptamer.png
Binary file not shown.
Binary file removed src/assets/assembly-scar.png
Binary file not shown.
Binary file removed src/assets/association.png
Binary file not shown.
Binary file removed src/assets/blunt-restriction-site.png
Binary file not shown.
Binary file removed src/assets/cds-arrow.png
Binary file not shown.
Binary file removed src/assets/cds.png
Binary file not shown.
Binary file removed src/assets/chromosomal-locus.png
Binary file not shown.
Binary file removed src/assets/circular-plasmid.png
Binary file not shown.
Binary file removed src/assets/complex-sbgn.png
Binary file not shown.
Binary file removed src/assets/composite.png
Binary file not shown.
Binary file removed src/assets/control.png
Binary file not shown.
Binary file removed src/assets/degradation.png
Binary file not shown.
Binary file removed src/assets/dissociation.png
Binary file not shown.
Binary file removed src/assets/dna-stability-element.png
Binary file not shown.
Binary file removed src/assets/dsNA.png
Binary file not shown.
Binary file removed src/assets/engineered-region.png
Binary file not shown.
Binary file removed src/assets/five-prime-overhang.png
Binary file not shown.
Binary file removed src/assets/five-prime-sticky-restriction-site.png
Binary file not shown.
Binary file removed src/assets/generic-sbgn.png
Binary file not shown.
Binary file removed src/assets/halfround-rectangle.png
Binary file not shown.
Binary file removed src/assets/inert-dna-spacer.png
Binary file not shown.
Binary file removed src/assets/inhibition.png
Binary file not shown.
Binary file removed src/assets/insulator.png
Binary file not shown.
Binary file removed src/assets/intron.png
Binary file not shown.
Binary file removed src/assets/location-dna-no-top.png
Binary file not shown.
Binary file removed src/assets/location-dna.png
Diff not rendered.
Binary file removed src/assets/location-protein-no-top.png
Diff not rendered.
Binary file removed src/assets/location-protein.png
Diff not rendered.
Binary file removed src/assets/location-rna-no-top.png
Diff not rendered.
Binary file removed src/assets/location-rna.png
Diff not rendered.
Binary file removed src/assets/macromolecule.png
Diff not rendered.
Binary file removed src/assets/na-sbgn.png
Diff not rendered.
Binary file removed src/assets/ncrna.png
Diff not rendered.
Binary file removed src/assets/no-glyph-assigned.png
Diff not rendered.
Binary file removed src/assets/nuclease-site.png
Diff not rendered.
Binary file removed src/assets/omitted-detail.png
Diff not rendered.
Binary file removed src/assets/operator.png
Diff not rendered.
Binary file removed src/assets/origin-of-replication.png
Diff not rendered.
Binary file removed src/assets/origin-of-transfer.png
Diff not rendered.
Binary file removed src/assets/polyA.png
Diff not rendered.
Binary file removed src/assets/polypeptide-region.png
Diff not rendered.
Binary file removed src/assets/primer-binding-site.png
Diff not rendered.
Binary file removed src/assets/process.png
Diff not rendered.
Binary file removed src/assets/promoter.png
Diff not rendered.
Binary file removed src/assets/protease-site.png
Diff not rendered.
Binary file removed src/assets/protein-stability-element.png
Diff not rendered.
Binary file removed src/assets/protein.png
Diff not rendered.
Binary file removed src/assets/replacement-glyph.png
Diff not rendered.
Binary file removed src/assets/ribonuclease-site.png
Diff not rendered.
Binary file removed src/assets/ribosome-entry-site.png
Diff not rendered.
Binary file removed src/assets/rna-stability-element.png
Diff not rendered.
Binary file removed src/assets/signature.png
Diff not rendered.
Binary file removed src/assets/simple-chemical-circle.png
Diff not rendered.
Binary file removed src/assets/simple-chemical-hexagon.png
Diff not rendered.
Binary file removed src/assets/simple-chemical-pentagon.png
Diff not rendered.
Binary file removed src/assets/simple-chemical-triangle.png
Diff not rendered.
Binary file removed src/assets/specific-recombination-site.png
Diff not rendered.
Binary file removed src/assets/ssNA.png
Diff not rendered.
Binary file removed src/assets/stimulation.png
Diff not rendered.
Binary file removed src/assets/terminator.png
Diff not rendered.
Binary file removed src/assets/three-prime-overhang.png
Diff not rendered.
Binary file removed src/assets/three-prime-sticky-restriction-site.png
Diff not rendered.
Binary file removed src/assets/transcription-end.png
Diff not rendered.
Binary file removed src/assets/translation-end.png
Diff not rendered.
Binary file removed src/assets/unspecified-glyph.png
Diff not rendered.
17 changes: 10 additions & 7 deletions src/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ export interface NameRange extends Range {
color?: string;
id: string;
name: string;
border?: "dashed" | "dotted" | "bold";
border?: Border;
font?: Font;
svg?: string;
gradient?: Gradient;
}

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

interface Border {
style?: "dashed" | "dotted" | "bold"
borderColor?: string;
}

interface Gradient {
Expand All @@ -31,9 +35,8 @@ interface Gradient {
/** AnnotationProp is an annotation provided to SeqViz via the annotations prop. */
export interface AnnotationProp {
color?: string;
border?: "dashed" | "dotted" | "bold";
border?: Border;
font?: Font;
svg?: string;
gradient?: Gradient;
direction?: number | string;
end: number;
Expand Down
9 changes: 1 addition & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ const cdnBuild = {
module: {
rules: [
{ test: /\.(t|j)sx?$/, loader: "ts-loader", exclude: /node_modules/ },
{ test: /\.js$/, enforce: "pre", loader: "source-map-loader", exclude: /node_modules/ },
{
test: /\.(png|jpe?g|gif|jp2|webp)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
{ test: /\.js$/, enforce: "pre", loader: "source-map-loader", exclude: /node_modules/ }
],
},
optimization: {
Expand Down

0 comments on commit 728e854

Please sign in to comment.