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

Allow custom chart renderer to render portal on a target #41

Open
wants to merge 1 commit into
base: timeline-VAF
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions packages/cbioportal-clinical-timeline/src/CustomTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import classNames from 'classnames';

export type CustomTrackSpecification = {
renderHeader: (store: TimelineStore) => any; // any = react renderable, string or element or null or etc.
renderTrack: (store: TimelineStore) => React.ReactElement<SVGGElement>;
renderTrack: (
store: TimelineStore,
headerTargetEl: any
) => React.ReactElement<SVGGElement>;
height: (store: TimelineStore) => number;
labelForExport: string;
disableHover?: boolean;
uid: string;
};

export interface ICustomTrackProps {
Expand Down Expand Up @@ -44,7 +48,12 @@ const CustomTrack: React.FunctionComponent<ICustomTrackProps> = function({
height={specification.height(store)}
width={width}
/>
{specification.renderTrack(store)}
{specification.renderTrack(
store,
document.getElementsByClassName(
`tl-track-uid-${specification.uid}`
)[0]
)}
<line
x1={0}
x2={width}
Expand Down
12 changes: 8 additions & 4 deletions packages/cbioportal-clinical-timeline/src/CustomTrackHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ const CustomTrackHeader: React.FunctionComponent<ICustomTrackHeaderProps> = func
}: ICustomTrackHeaderProps) {
return (
<div
className={classNames('tl-custom-track-header', {
'tl-hover-disabled': disableHover,
})}
className={classNames(
'tl-custom-track-header',
`tl-track-uid-${specification.uid}`,
{
'tl-hover-disabled': disableHover,
}
)}
style={{ paddingLeft: 5, height: specification.height(store) }}
onMouseEnter={handleTrackHover}
onMouseLeave={handleTrackHover}
>
{specification.renderHeader(store)}
{specification.renderHeader && specification.renderHeader(store)}
</div>
);
};
Expand Down
160 changes: 91 additions & 69 deletions src/pages/patientView/timeline2/VAFChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface IVAFChartProps {
mutationProfileId: string;
coverageInformation: CoverageInformation;
sampleManager: SampleManager;
headerEl?: HTMLDivElement;
}

const HIGHLIGHT_LINE_STROKE_WIDTH = 6;
Expand Down Expand Up @@ -632,34 +633,36 @@ export default class VAFChart extends React.Component<IVAFChartProps, {}> {
renderTrack: () => this.sampeIconsGroupByTrack(sampleIds),
height: () => this.groupIndexToTrackHeight[index],
labelForExport: this.clinicalValuesForGrouping[index],
uid: `groupbytracks-${index}`,
});
});
this.props.wrapperStore.groupByTracks = tracks;
}

yAxisHeaderReaction = autorun(() => {
this.renderHeader(this.ticks);
});
// yAxisHeaderReaction = autorun(() => {
// this.renderHeader(this.ticks);
// });

groupByTracksReaction = autorun(() => {
this.setGroupByTracks(this.sampleGroups);
});

destroy() {
this.yAxisHeaderReaction();
// this.yAxisHeaderReaction();
this.groupByTracksReaction();
}

@action
renderHeader(ticks: { label: string; value: number; offset: number }[]) {
this.props.wrapperStore.vafPlotHeader = (store: TimelineStore) => (
<div className={'positionAbsolute'} style={{ right: -6 }}>
<VAFChartHeader
ticks={ticks}
legendHeight={this.props.wrapperStore.vafChartHeight}
/>
</div>
);
return null;
// this.props.wrapperStore.vafPlotHeader = (store: TimelineStore) => (
// <div className={'positionAbsolute'} style={{ right: -6 }}>
// <VAFChartHeader
// ticks={ticks}
// legendHeight={this.props.wrapperStore.vafChartHeight}
// />
// </div>
// );
}

@computed get groupColor() {
Expand All @@ -672,44 +675,72 @@ export default class VAFChart extends React.Component<IVAFChartProps, {}> {

render() {
return (
<svg
width={this.props.store.pixelWidth}
height={this.recalculateTotalHeight()}
>
{this.renderData.lineData.map(
(data: IPoint[], index: number) => {
return data.map((d: IPoint, i: number) => {
let x1 = this.xPosition[d.sampleId],
x2;
let y1 = this.yPosition[d.y],
y2;

const nextPoint: IPoint = data[i + 1];
if (nextPoint) {
x2 = this.xPosition[nextPoint.sampleId];
y2 = this.yPosition[nextPoint.y];
}

let tooltipDatum: {
mutationStatus: MutationStatus;
sampleId: string;
vaf: number;
} = {
mutationStatus: d.mutationStatus,
sampleId: d.sampleId,
vaf: d.y,
};

const color = this.groupColor(d.sampleId);

return (
<g>
{x2 && y2 && (
<VAFPointConnector
x1={x1}
y1={y1}
x2={x2}
y2={y2}
<>
{this.props.headerEl && (
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we take the DOM element represening the header for the track and can render a header to it

<Portal node={this.props.headerEl}>
<div
className={'positionAbsolute'}
style={{ right: -6 }}
>
<VAFChartHeader
ticks={this.ticks}
legendHeight={
this.props.wrapperStore.vafChartHeight
}
/>
</div>
</Portal>
)}
<svg
width={this.props.store.pixelWidth}
height={this.recalculateTotalHeight()}
>
{this.renderData.lineData.map(
(data: IPoint[], index: number) => {
return data.map((d: IPoint, i: number) => {
let x1 = this.xPosition[d.sampleId],
x2;
let y1 = this.yPosition[d.y],
y2;

const nextPoint: IPoint = data[i + 1];
if (nextPoint) {
x2 = this.xPosition[nextPoint.sampleId];
y2 = this.yPosition[nextPoint.y];
}

let tooltipDatum: {
mutationStatus: MutationStatus;
sampleId: string;
vaf: number;
} = {
mutationStatus: d.mutationStatus,
sampleId: d.sampleId,
vaf: d.y,
};

const color = this.groupColor(d.sampleId);

return (
<g>
{x2 && y2 && (
<VAFPointConnector
x1={x1}
y1={y1}
x2={x2}
y2={y2}
color={color}
tooltipDatum={tooltipDatum}
mutation={d.mutation}
dataStore={this.props.dataStore}
wrapperStore={
this.props.wrapperStore
}
/>
)}
<VAFPoint
x={x1}
y={y1}
color={color}
tooltipDatum={tooltipDatum}
mutation={d.mutation}
Expand All @@ -718,26 +749,17 @@ export default class VAFChart extends React.Component<IVAFChartProps, {}> {
this.props.wrapperStore
}
/>
)}
<VAFPoint
x={x1}
y={y1}
color={color}
tooltipDatum={tooltipDatum}
mutation={d.mutation}
dataStore={this.props.dataStore}
wrapperStore={this.props.wrapperStore}
/>
</g>
);
});
}
)}
</g>
);
});
}
)}

{!this.groupingByIsSelected && this.sampleIcons()}
<Observer>{this.getHighlights}</Observer>
<Observer>{this.getTooltipComponent}</Observer>
</svg>
{!this.groupingByIsSelected && this.sampleIcons()}
<Observer>{this.getHighlights}</Observer>
<Observer>{this.getTooltipComponent}</Observer>
</svg>
</>
);
}

Expand Down
35 changes: 21 additions & 14 deletions src/pages/patientView/timeline2/VAFChartWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { RefObject, useEffect, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { CoverageInformation } from '../../resultsView/ResultsViewPageStoreUtils';
import { ClinicalEvent, Sample } from 'cbioportal-ts-api-client';
Expand All @@ -24,6 +24,7 @@ import {
} from 'pages/patientView/timeline2/helpers';
import { CustomTrackSpecification } from 'cbioportal-clinical-timeline/dist/CustomTrack';
import { downloadZippedTracks } from 'pages/patientView/timeline2/timelineDataUtils';
import { Portal } from 'react-overlays/lib';

export interface ISampleMetaDeta {
color: { [sampleId: string]: string };
Expand Down Expand Up @@ -102,24 +103,30 @@ const VAFChartWrapper: React.FunctionComponent<IVAFChartWrapperProps> = observer
const groupByTracks = wrapperStore.groupByTracks;

const vafPlotTrack = {
renderHeader: wrapperStore.vafPlotHeader,
renderTrack: (store: TimelineStore) => (
<VAFChart
dataStore={dataStore}
store={store}
wrapperStore={wrapperStore}
sampleMetaData={caseMetaData}
samples={samples}
mutationProfileId={mutationProfileId}
coverageInformation={coverageInformation}
sampleManager={sampleManager}
/>
),
//renderHeader: wrapperStore.vafPlotHeader,
renderTrack: (store: TimelineStore, headerEl?: HTMLDivElement) => {
return (
<>
<VAFChart
dataStore={dataStore}
store={store}
wrapperStore={wrapperStore}
sampleMetaData={caseMetaData}
samples={samples}
mutationProfileId={mutationProfileId}
coverageInformation={coverageInformation}
sampleManager={sampleManager}
headerEl={headerEl}
/>
</>
);
},
disableHover: true,
height: (store: TimelineStore) => {
return wrapperStore.vafChartHeight;
},
labelForExport: 'VAF',
uid: 'vafplot',
} as CustomTrackSpecification;

let customTracks = [vafPlotTrack].concat(wrapperStore.groupByTracks);
Expand Down