-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea558f2
commit e6794f1
Showing
6 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as React from "react"; | ||
import { indexLine, indexTick, indexTickLabel } from "../style"; | ||
import { useBuilder } from "./hooks/useBuilder"; | ||
import { Tick } from "./Tick"; | ||
|
||
|
||
/** | ||
* The Index component renders the Linear Map's: | ||
* 1. name (center or bottom) | ||
* 2. number of bps (center or bottom) | ||
* 3. index ticks and numbers along the Linear Map | ||
*/ | ||
|
||
export interface IndexProps { | ||
height: number | ||
width: number | ||
seqLength: number | ||
} | ||
|
||
export function Index(props: IndexProps) { | ||
const { ruler, ticks } = useBuilder(props) | ||
|
||
return ( | ||
<g> | ||
|
||
{/* The ticks and their index labels */} | ||
{ticks.map((tick: Tick) => ( | ||
<g key={`la-vz-tick-${tick.position}`}> | ||
<path | ||
className="la-vz-index-tick" | ||
d={tick.path} | ||
style={indexTick} | ||
/> | ||
<text | ||
className="la-vz-index-tick-label" | ||
style={indexTickLabel} | ||
textAnchor="middle" | ||
x={tick.text.x} | ||
y={tick.text.y} | ||
> | ||
{tick.position} | ||
</text> | ||
</g> | ||
)) | ||
} | ||
|
||
{/* The ruler is abstract line representing sequence length and giving relative references for other elements as Annotations, Cut sites, Primers, etc. */} | ||
<g> | ||
<path | ||
className="la-vz-index-line" | ||
d={ruler.path} | ||
style={indexLine} | ||
/> | ||
</g> | ||
</g> | ||
); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export class Ruler { | ||
readonly LATERAL_PADDING = 10 | ||
|
||
height: number | ||
width: number | ||
seqLength: number | ||
start: number | ||
end: number | ||
padByBp: number | ||
|
||
constructor( | ||
height: number, | ||
width: number, | ||
seqLength: number | ||
) { | ||
this.height = height/2 | ||
this.start = this.LATERAL_PADDING | ||
this.end = width - this.LATERAL_PADDING | ||
this.width = this.end - this.start | ||
this.seqLength = seqLength | ||
this.padByBp = this.width / seqLength | ||
} | ||
|
||
get path() { | ||
return ` | ||
M ${this.start} ${this.height} | ||
L ${this.end} ${this.height} | ||
` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Ruler } from "./Ruler" | ||
|
||
export class RulerTicks { | ||
private readonly HORIZONTAL_TICK_LENGTH = 10 | ||
private readonly TICK_COUNT = 6 | ||
private ruler: Ruler | ||
|
||
constructor(ruler: Ruler) { | ||
this.ruler = ruler | ||
} | ||
|
||
private getPadByPosition(bpPosition: number) { | ||
return this.ruler.start + this.ruler.padByBp * bpPosition | ||
} | ||
|
||
private getTickPath(position: number) { | ||
const pad = this.getPadByPosition(position) | ||
return ` | ||
M ${pad} ${this.ruler.height} | ||
L ${pad} ${this.ruler.height + this.HORIZONTAL_TICK_LENGTH} | ||
` | ||
} | ||
|
||
private getTickText(rightPad: number) { | ||
const TICK_TEXT_LINE = this.HORIZONTAL_TICK_LENGTH * 2 | ||
const textLineHeight = this.ruler.height + TICK_TEXT_LINE | ||
return { | ||
x: rightPad, | ||
y: textLineHeight | ||
} | ||
} | ||
|
||
private getTick(position: number): Tick { | ||
const rightPad = this.getPadByPosition(position) | ||
return { | ||
position, | ||
path: this.getTickPath(position), | ||
text: this.getTickText(rightPad) | ||
} | ||
} | ||
|
||
private buildTicks(positions: number[]) { | ||
return positions.map(position => this.getTick(position)) | ||
} | ||
|
||
get positions(): number[] { | ||
const increments = Math.floor(this.ruler.seqLength / this.TICK_COUNT); | ||
let indexInc = Math.max(+increments.toPrecision(2), 10); | ||
while (indexInc % 10 !== 0) indexInc += 1; | ||
// | ||
let ticks: number[] = []; | ||
for (let i = indexInc; i <= this.ruler.seqLength - indexInc; i += indexInc) { | ||
ticks.push(i === 0 ? 1 : i); | ||
} | ||
|
||
return ticks | ||
} | ||
|
||
get ticks(): Tick[] { | ||
return this.buildTicks(this.positions) | ||
} | ||
} | ||
|
||
|
||
export interface Tick { | ||
position: number | ||
path: string | ||
text: { | ||
x: number | ||
y: number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useMemo } from "react" | ||
import { IndexProps } from "../Index" | ||
import { Ruler } from "../Ruler" | ||
import { RulerTicks } from "../Tick" | ||
|
||
type BuilderProps = IndexProps | ||
export function useBuilder({ height, width, seqLength }: BuilderProps) { | ||
const { ruler, ticks } = useMemo(() => { | ||
const ruler = new Ruler(height, width, seqLength) | ||
const ticks = new RulerTicks(ruler).ticks | ||
return { | ||
ruler, | ||
ticks | ||
} | ||
}, [height, width, seqLength]) | ||
|
||
return { ruler, ticks } | ||
} |