Skip to content

Commit

Permalink
absolute timeline draft with hardcoded date
Browse files Browse the repository at this point in the history
  • Loading branch information
Domobaerchen committed Feb 27, 2024
1 parent a646110 commit 46bfbf1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
43 changes: 28 additions & 15 deletions packages/cbioportal-clinical-timeline/src/TickAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const TickAxis: React.FunctionComponent<ITickAxisProps> = observer(function({
startPoint = tick.start;
}

var startDate = new Date('01/01/1960');

const majorTickPosition = store.getPosition({
start: startPoint,
});
Expand All @@ -98,17 +100,12 @@ const TickAxis: React.FunctionComponent<ITickAxisProps> = observer(function({

let majorLabel: string = '';

if (count < 0) {
majorLabel = `${count}${unit}`;
}

if (count === 0) {
majorLabel = '0';
}

if (count > 0) {
majorLabel = `${count}${unit}`;
}
startDate.setMonth(startDate.getMonth() + count);
majorLabel =
startDate.getMonth() +
1 +
'/' +
startDate.getFullYear();

content = (
<>
Expand Down Expand Up @@ -165,13 +162,29 @@ const TickAxis: React.FunctionComponent<ITickAxisProps> = observer(function({
: `${count + 1}${unit}`;
minorLabel =
count === -1
? `-${minorCount}m`
: `${majorLabel} ${minorCount}m`;
? startDate.getMonth() +
minorCount +
1 +
'/' +
startDate.getFullYear()
: startDate.getMonth() +
minorCount +
1 +
'/' +
startDate.getFullYear();
} else {
minorLabel =
count === 0
? `${minorCount}m`
: `${majorLabel} ${minorCount}m`;
? startDate.getMonth() +
minorCount +
1 +
'/' +
startDate.getFullYear()
: startDate.getMonth() +
minorCount +
1 +
'/' +
startDate.getFullYear();
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/cbioportal-clinical-timeline/src/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ const Timeline: React.FunctionComponent<ITimelineProps> = observer(function({
}: ITimelineProps) {
const tracks = store.data;
const SCROLLBAR_PADDING = 15;
var dateType = false;
let height =
TICK_AXIS_HEIGHT +
_.sumBy(tracks, t => {
Expand Down Expand Up @@ -354,6 +355,17 @@ const Timeline: React.FunctionComponent<ITimelineProps> = observer(function({
className={'tl-timeline-wrapper'}
id={store.uniqueId}
>
<div className={'tl-timeline-zoom-info'}>
<button
className={'btn btn-xs'}
onClick={() => {
dateType = !dateType;
console.log(dateType);
}}
>
<i className={'fa fa-search-minus'} /> toggle date type
</button>
</div>
<div className={'tl-timeline-reset-buttons'}>
<div className={'tl-timeline-zoom-info'}>
{store.zoomBounds && (
Expand Down
11 changes: 10 additions & 1 deletion packages/cbioportal-clinical-timeline/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ export function sortNestedTracks(tracks: TimelineTrackSpecification[]) {
}

export function formatDate(dayCount: number) {
var startDate = new Date('01/01/1960');
startDate.setDate(startDate.getDate() + dayCount);

let negative = dayCount < 0;
dayCount = Math.abs(dayCount);

Expand All @@ -218,7 +221,13 @@ export function formatDate(dayCount: number) {
arr.push(`${days} day${days === 1 ? '' : 's'}`);

const formattedDate = arr.join(', ');
return `${negative ? '-' : ''}${formattedDate}`;
return (
startDate.getDate() +
'/' +
(startDate.getMonth() + 1) +
'/' +
startDate.getFullYear()
);
}

function getAllDescendantData(
Expand Down

0 comments on commit 46bfbf1

Please sign in to comment.