Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0
message: "Si usas este software, por favor cítalo así. / If you use this software, please cite it as below."
title: "Vector editor: in-browser cloning simulator with REBASE enzymes"
type: software
version: 0.3.0
version: 0.3.1
authors:
- family-names: "Quintero López"
given-names: "Oscar Alexis"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oquinterol/vector-editor",
"version": "0.3.0",
"version": "0.3.1",
"description": "In-browser cloning simulator: choose commercial or custom restriction enzymes, digest and ligate, and get a live FASTA and plasmid map.",
"license": "MIT",
"author": "Oscar Alexis Quintero López (https://oquinterol.com)",
Expand Down
42 changes: 40 additions & 2 deletions src/ui/FastaView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useRef } from 'react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
import type { Site } from '../core'

export interface Region {
Expand All @@ -23,6 +23,7 @@ interface Props {
range: SeqRange | null
rangeSource: RangeSource | null
onRange: (range: SeqRange) => void
/** Fixed bases per line; by default it fits the panel width (multiples of 10). */
width?: number
label: string
}
Expand All @@ -34,8 +35,45 @@ export function inRange(range: SeqRange, i: number): boolean {
}

/** The FASTA of the plasmid with every base coloured by what it belongs to. */
export function FastaView({ header, seq, regions, sites, range, rangeSource, onRange, width = 60, label }: Props) {
export function FastaView({
header,
seq,
regions,
sites,
range,
rangeSource,
onRange,
width: fixedWidth,
label
}: Props) {
const box = useRef<HTMLDivElement>(null)
const [fitWidth, setFitWidth] = useState(60)
const width = fixedWidth ?? fitWidth

// Fit whole blocks of ten bases to the panel, so lines never scroll sideways.
useEffect(() => {
const element = box.current
if (!element || fixedWidth || typeof ResizeObserver === 'undefined') return
const probe = document.createElement('span')
probe.textContent = 'ACGTACGTAC'
probe.style.cssText = 'position:absolute;visibility:hidden;white-space:pre'
element.appendChild(probe)
const measure = () => {
const charWidth = probe.getBoundingClientRect().width / 10
const style = getComputedStyle(element)
const inner = element.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight)
const gutter = charWidth * 8 // position column + gap
const blocks = Math.floor((inner - gutter) / (charWidth * 10))
if (charWidth > 0) setFitWidth(Math.min(80, Math.max(20, blocks * 10)))
}
measure()
const observer = new ResizeObserver(measure)
observer.observe(element)
return () => {
observer.disconnect()
probe.remove()
}
}, [fixedWidth])

// Per-base region kind and recognition-site mask, recomputed only when the plasmid changes.
const { kind, site } = useMemo(() => {
Expand Down
Loading