diff --git a/.eslintrc.js b/.eslintrc.js index 28c80f415..0a7c901bb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -79,8 +79,7 @@ module.exports = { 'unicorn/consistent-destructuring': 'off', 'unicorn/filename-case': 'off', 'unicorn/no-array-for-each': 'off', - 'unicorn/no-empty-file': 'off', - 'unicorn/no-new-array': 'off', + 'unicorn/no-empty-file': 'off', // False positives 'unicorn/no-null': 'off', 'unicorn/prefer-array-some': 'off', 'unicorn/prefer-module': 'off', diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts index 1b9937a77..ed1c9b2db 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts @@ -97,50 +97,52 @@ export class CanonicalGeneGlyph extends Glyph { const cdsCount = [...(mrna.children ?? [])].filter( ([, exonOrCDS]) => exonOrCDS.type === 'CDS', ).length - // eslint-disable-next-line unicorn/no-useless-undefined - new Array(cdsCount).fill(undefined).forEach(() => { - mrna.children?.forEach((exon: AnnotationFeatureI) => { - if (exon.type !== 'exon') { - return - } - const offsetPx = (exon.start - feature.min) / bpPerPx - const widthPx = exon.length / bpPerPx - const startPx = reversed - ? xOffset - offsetPx - widthPx - : xOffset + offsetPx - const top = (row + currentCDS) * rowHeight - const utrTop = top + (rowHeight - utrHeight) / 2 - ctx.fillStyle = theme?.palette.text.primary ?? 'black' - ctx.fillRect(startPx, utrTop, widthPx, utrHeight) - if (widthPx > 2) { - ctx.clearRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2) - ctx.fillStyle = 'rgb(211,211,211)' - ctx.fillRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2) - if (forwardFill && backwardFill && strand) { - const reversal = reversed ? -1 : 1 - const [topFill, bottomFill] = - strand * reversal === 1 - ? [forwardFill, backwardFill] - : [backwardFill, forwardFill] - ctx.fillStyle = topFill - ctx.fillRect( - startPx + 1, - utrTop + 1, - widthPx - 2, - (utrHeight - 2) / 2, - ) - ctx.fillStyle = bottomFill - ctx.fillRect( - startPx + 1, - utrTop + 1 + (utrHeight - 2) / 2, - widthPx - 2, - (utrHeight - 2) / 2, - ) + Array.from({ length: cdsCount }) + // eslint-disable-next-line unicorn/no-useless-undefined + .fill(undefined) + .forEach(() => { + mrna.children?.forEach((exon: AnnotationFeatureI) => { + if (exon.type !== 'exon') { + return } - } + const offsetPx = (exon.start - feature.min) / bpPerPx + const widthPx = exon.length / bpPerPx + const startPx = reversed + ? xOffset - offsetPx - widthPx + : xOffset + offsetPx + const top = (row + currentCDS) * rowHeight + const utrTop = top + (rowHeight - utrHeight) / 2 + ctx.fillStyle = theme?.palette.text.primary ?? 'black' + ctx.fillRect(startPx, utrTop, widthPx, utrHeight) + if (widthPx > 2) { + ctx.clearRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2) + ctx.fillStyle = 'rgb(211,211,211)' + ctx.fillRect(startPx + 1, utrTop + 1, widthPx - 2, utrHeight - 2) + if (forwardFill && backwardFill && strand) { + const reversal = reversed ? -1 : 1 + const [topFill, bottomFill] = + strand * reversal === 1 + ? [forwardFill, backwardFill] + : [backwardFill, forwardFill] + ctx.fillStyle = topFill + ctx.fillRect( + startPx + 1, + utrTop + 1, + widthPx - 2, + (utrHeight - 2) / 2, + ) + ctx.fillStyle = bottomFill + ctx.fillRect( + startPx + 1, + utrTop + 1 + (utrHeight - 2) / 2, + widthPx - 2, + (utrHeight - 2) / 2, + ) + } + } + }) + currentCDS += 1 }) - currentCDS += 1 - }) }) currentCDS = 0 feature.children?.forEach((mrna: AnnotationFeatureI) => { diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts index 9dae538b8..0d271e96d 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts @@ -90,52 +90,64 @@ export class ImplicitExonGeneGlyph extends Glyph { const cdsCount = [...(mrna.children ?? [])].filter( ([, exonOrCDS]) => exonOrCDS.type === 'CDS', ).length - // eslint-disable-next-line unicorn/no-useless-undefined - new Array(cdsCount).fill(undefined).forEach(() => { - mrna.children?.forEach((cdsOrUTR: AnnotationFeatureI) => { - const isCDS = cdsOrUTR.type === 'CDS' - const isUTR = cdsOrUTR.type.endsWith('UTR') - if (!(isCDS || isUTR)) { - return - } - const offsetPx = (cdsOrUTR.start - feature.min) / bpPerPx - const widthPx = cdsOrUTR.length / bpPerPx - const startPx = reversed - ? xOffset - offsetPx - widthPx - : xOffset + offsetPx - ctx.fillStyle = theme?.palette.text.primary ?? 'black' - const top = (row + currentMRNA) * rowHeight - const height = isCDS ? cdsHeight : utrHeight - const cdsOrUTRTop = top + (rowHeight - height) / 2 - ctx.fillRect(startPx, cdsOrUTRTop, widthPx, height) - if (widthPx > 2) { - ctx.clearRect(startPx + 1, cdsOrUTRTop + 1, widthPx - 2, height - 2) - ctx.fillStyle = isCDS ? 'rgb(255,165,0)' : 'rgb(211,211,211)' - ctx.fillRect(startPx + 1, cdsOrUTRTop + 1, widthPx - 2, height - 2) - if (forwardFill && backwardFill && strand) { - const reversal = reversed ? -1 : 1 - const [topFill, bottomFill] = - strand * reversal === 1 - ? [forwardFill, backwardFill] - : [backwardFill, forwardFill] - ctx.fillStyle = topFill - ctx.fillRect( + Array.from({ length: cdsCount }) + // eslint-disable-next-line unicorn/no-useless-undefined + .fill(undefined) + .forEach(() => { + mrna.children?.forEach((cdsOrUTR: AnnotationFeatureI) => { + const isCDS = cdsOrUTR.type === 'CDS' + const isUTR = cdsOrUTR.type.endsWith('UTR') + if (!(isCDS || isUTR)) { + return + } + const offsetPx = (cdsOrUTR.start - feature.min) / bpPerPx + const widthPx = cdsOrUTR.length / bpPerPx + const startPx = reversed + ? xOffset - offsetPx - widthPx + : xOffset + offsetPx + ctx.fillStyle = theme?.palette.text.primary ?? 'black' + const top = (row + currentMRNA) * rowHeight + const height = isCDS ? cdsHeight : utrHeight + const cdsOrUTRTop = top + (rowHeight - height) / 2 + ctx.fillRect(startPx, cdsOrUTRTop, widthPx, height) + if (widthPx > 2) { + ctx.clearRect( startPx + 1, cdsOrUTRTop + 1, widthPx - 2, - (height - 2) / 2, + height - 2, ) - ctx.fillStyle = bottomFill + ctx.fillStyle = isCDS ? 'rgb(255,165,0)' : 'rgb(211,211,211)' ctx.fillRect( startPx + 1, - cdsOrUTRTop + 1 + (height - 2) / 2, + cdsOrUTRTop + 1, widthPx - 2, - (height - 2) / 2, + height - 2, ) + if (forwardFill && backwardFill && strand) { + const reversal = reversed ? -1 : 1 + const [topFill, bottomFill] = + strand * reversal === 1 + ? [forwardFill, backwardFill] + : [backwardFill, forwardFill] + ctx.fillStyle = topFill + ctx.fillRect( + startPx + 1, + cdsOrUTRTop + 1, + widthPx - 2, + (height - 2) / 2, + ) + ctx.fillStyle = bottomFill + ctx.fillRect( + startPx + 1, + cdsOrUTRTop + 1 + (height - 2) / 2, + widthPx - 2, + (height - 2) / 2, + ) + } } - } + }) }) - }) currentMRNA += 1 }) const { apolloSelectedFeature } = session diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts index 067eee6b6..03209c1df 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts @@ -102,7 +102,7 @@ export function layoutsModelFactory( if (rowsForFeature.length < rowCount) { for (let i = 0; i < rowCount - rowsForFeature.length; i++) { const newRowNumber = rows.length - rows[newRowNumber] = new Array(max - min) + rows[newRowNumber] = Array.from({ length: max - min }) featureLayout.set(newRowNumber, []) } rowsForFeature = rows.slice(startingRow, startingRow + rowCount) diff --git a/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts b/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts index 56faaca8b..7e0741f0b 100644 --- a/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts +++ b/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts @@ -285,7 +285,7 @@ export function stateModelFactory( const rowCount = 6 for (let i = 0; i < rowCount; i++) { const newRowNumber = rows.length - rows[newRowNumber] = new Array(max - min) + rows[newRowNumber] = Array.from({ length: max - min }) featureLayout.set(newRowNumber, []) } for (const feature of [...featuresForRefSeq.values()].sort(