-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linear Map View #251
Open
isaacguerreir
wants to merge
1
commit into
develop
Choose a base branch
from
feat/linear-map
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Linear Map View #251
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I use functional components @jjti ou should I maintain the class components being used throughout the project?