Skip to content
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

CLN-32135: Fixed linearView start and end Axis text position #11

Merged
merged 1 commit into from
Oct 20, 2021
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
1 change: 1 addition & 0 deletions src/LinearView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class _LinearView extends React.Component {
...RowItemProps
}}
row={rowData[0]}
isLinearView
/>
</div>
</Draggable>
Expand Down
5 changes: 5 additions & 0 deletions src/LinearView/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 22 additions & 17 deletions src/RowItem/Axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { divideBy3 } from "../utils/proteinUtils";
import { view } from "@risingstack/react-easy-state";
import { getVisibleStartEnd } from "../utils/getVisibleStartEnd";

let Axis = function (props) {
let {
const Axis = function (props) {
const {
row,
tickSpacing,
bpsPerRow,
Expand All @@ -19,12 +19,13 @@ let Axis = function (props) {
getGaps,
scrollData,
isProtein,
style
style,
isLinearView
} = props;
const noRows = row.start === 0 && row.end === 0;
/* eslint-disable react-hooks/exhaustive-deps */
//memoize this function because it does the heavy lifting
let tickMarkPositions = useMemo(() => {
const tickMarkPositions = useMemo(() => {
if (noRows) return [];
return calculateTickMarkPositionsForGivenRange({
tickSpacing,
Expand All @@ -33,7 +34,7 @@ let Axis = function (props) {
isProtein
}).map((tickMarkPosition) => {
const gaps = getGaps ? getGaps(tickMarkPosition).gapsBefore : 0;
let xCenter =
const xCenter =
(tickMarkPosition - (isProtein ? 1 : 0) + gaps) * charWidth +
charWidth / 2;
return {
Expand All @@ -54,7 +55,7 @@ let Axis = function (props) {
if (noRows) {
return null;
}
let { xStart, width } = getXStartAndWidthOfRangeWrtRow({
const { xStart, width } = getXStartAndWidthOfRangeWrtRow({
row,
range: row,
charWidth,
Expand All @@ -63,7 +64,7 @@ let Axis = function (props) {
});
//this function should take in a desired tickSpacing (eg 10 bps between tick mark)
//and output an array of tickMarkPositions for the given row (eg, [0, 10, 20])
let xEnd = xStart + width;
const xEnd = xStart + width;
let visibleStart, visibleEnd;
if (scrollData) {
const val = getVisibleStartEnd({
Expand All @@ -75,10 +76,10 @@ let Axis = function (props) {
visibleEnd = val.visibleEnd + 400;
}

let yStart = 0;
let yEnd = annotationHeight / 3;
const yStart = 0;
const yEnd = annotationHeight / 3;

let tickMarkSVG = [];
const tickMarkSVG = [];

tickMarkPositions.forEach(function ({ tickMarkPosition, xCenter }, i) {
// const xCenterPlusXStart = xCenter + xStart;
Expand All @@ -100,18 +101,22 @@ let Axis = function (props) {

const positionLength = position.toString().length * 4;
const textInner = divideBy3(position + (isProtein ? 1 : 0), isProtein);

let x = xCenter;
if (!isLinearView) {
x =
i === 0 //if first label in row, or last label in row, we add checks to make sure the axis number labels don't go outside of the width of the row
? Math.max(positionLength, xCenter)
: i === tickMarkPositions.length - 1
? Math.min(bpsPerRow * charWidth - positionLength, xCenter)
: xCenter;
}
tickMarkSVG.push(
<text
data-tick-mark={textInner}
key={"axisTickMarkText " + i + " " + tickMarkPosition}
stroke="black"
x={
i === 0 //if first label in row, or last label in row, we add checks to make sure the axis number labels don't go outside of the width of the row
? Math.max(positionLength, xCenter)
: i === tickMarkPositions.length - 1
? Math.min(bpsPerRow * charWidth - positionLength, xCenter)
: xCenter
}
x={x}
y={annotationHeight}
style={{ textAnchor: "middle", fontSize: 10, fontFamily: "Verdana" }}
>
Expand Down
6 changes: 5 additions & 1 deletion src/RowItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class RowItem extends React.PureComponent {
externalLabels,
scrollData,
onlyShowLabelsThatDoNotFit,
labelLineIntensity
labelLineIntensity,
isLinearView
} = this.props;

const {
Expand Down Expand Up @@ -127,7 +128,9 @@ export class RowItem extends React.PureComponent {

if (!width) {
width = bpsPerRow * charWidth;
if (isLinearView) width -= (charWidth * bpsPerRow.toString().length) / 2;
} else {
if (isLinearView) width -= (charWidth * bpsPerRow.toString().length) / 2;
charWidth = width / Math.max(bpsPerRow, 1);
}
const rowContainerStyle = {
Expand Down Expand Up @@ -617,6 +620,7 @@ export class RowItem extends React.PureComponent {
annotationHeight={axisHeight}
marginTop={axisMarginTop}
{...annotationCommonProps}
isLinearView={isLinearView}
/>
)}
{caretPosition > -1 && (
Expand Down