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 user to customize x-axis (months survival) in survival plot #2884

Merged
merged 2 commits into from
Nov 25, 2019
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 60 additions & 3 deletions src/pages/resultsView/survival/SurvivalChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PatientSurvival } from "../../../shared/model/PatientSurvival";
import {action, computed, observable, runInAction} from "mobx";
import { Popover, Table } from 'react-bootstrap';
import styles from "./styles.module.scss";
import "./styles.scss";
import { sleep } from "../../../shared/lib/TimeUtils";
import * as _ from 'lodash';
import {
Expand All @@ -27,6 +28,8 @@ import classnames from "classnames";
import {ClinicalAttribute} from "../../../shared/api/generated/CBioPortalAPI";
import DefaultTooltip from "../../../public-lib/components/defaultTooltip/DefaultTooltip";
import TruncatedTextWithTooltipSVG from "../../../shared/components/TruncatedTextWithTooltipSVG";
import Slider from 'react-rangeslider'
import { EditableSpan, pluralize } from 'cbioportal-frontend-commons';

export enum LegendLocation {
TOOLTIP = "tooltip",
Expand Down Expand Up @@ -57,7 +60,7 @@ export interface ISurvivalChartProps {
showNaPatientsHiddenToggle?:boolean;
showLogRankPVal?:boolean;
showDownloadButtons?: boolean;
disableZoom?: boolean;
showSlider?: boolean;
styleOpts?: any; // see victory styles, and styleOptsDefaultProps for examples
className?: string;
showCurveInTooltip?:boolean;
Expand All @@ -73,6 +76,7 @@ export default class SurvivalChart extends React.Component<ISurvivalChartProps,
@observable.ref tooltipModel: any;
@observable scatterFilter: SurvivalPlotFilters;
@observable highlightedCurve = "";
@observable public sliderValue = this.maximumDataMonthValue;
// The denominator should be determined based on the plot width and height.
private isTooltipHovered: boolean = false;
private tooltipCounter: number = 0;
Expand Down Expand Up @@ -221,7 +225,7 @@ export default class SurvivalChart extends React.Component<ISurvivalChartProps,

public static defaultProps: Partial<ISurvivalChartProps> = {
showTable: true,
disableZoom: false,
showSlider: true,
legendLocation: LegendLocation.CHART,
showLogRankPVal: true,
showNaPatientsHiddenToggle: false,
Expand Down Expand Up @@ -410,6 +414,26 @@ export default class SurvivalChart extends React.Component<ISurvivalChartProps,
return this.victoryLegendData.length > 0;
}

@computed get maximumDataMonthValue() {
return _.chain(this.sortedGroupedSurvivals)
.map((survivals) => survivals[survivals.length - 1].months)
.max()
.ceil()
.value();
}

@autobind
Copy link
Collaborator

Choose a reason for hiding this comment

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

@action
onSliderChange(value: number) {
this.sliderValue = value;
}

@autobind
Copy link
Collaborator

Choose a reason for hiding this comment

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

@action
onSliderTextChange(text: string) {
this.sliderValue = Number.parseFloat(text);
}

@computed
get chart() {
return (
Expand All @@ -427,8 +451,41 @@ export default class SurvivalChart extends React.Component<ISurvivalChartProps,
/>
}

{
(this.props.showSlider) && (
<div className="small" style={{display: "flex", alignItems: "center", marginLeft: 60}}>
<span>X-Axis Max:</span>
<div
className={"RangeSliderContainer"}
style={{
width: 300,
marginLeft: 10,
marginRight: 10
}}
>
<Slider
min={0}
max={this.maximumDataMonthValue}
value={this.sliderValue}
onChange={this.onSliderChange}
tooltip={false}
step={1}
/>
</div>
<EditableSpan
className={styles["XmaxNumberInput"]}
value={this.sliderValue.toString()}
setValue={this.onSliderTextChange}
numericOnly={true}
/>
<span>{pluralize("Month", this.sliderValue)} Survival</span>
</div>
)
}

<VictoryChart containerComponent={<VictoryZoomContainer responsive={false}
disable={this.props.disableZoom}
disable={true}
zoomDomain={{x: [0, this.sliderValue]}}
onZoomDomainChange={_.debounce((domain: any) => {
this.scatterFilter = domain as SurvivalPlotFilters;
}, 1000)}
Expand Down
9 changes: 9 additions & 0 deletions src/pages/resultsView/survival/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@
text-align: center;
margin: 20px 0;
}

.XmaxNumberInput {
margin-right: 5px;
cursor: auto !important;
border: 1px inset;
height: 18px;
padding: 0 5px 0 5px;
display: inline-block;
}
21 changes: 21 additions & 0 deletions src/pages/resultsView/survival/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.RangeSliderContainer {
width: 300;
margin-left: 10;
margin-right: 10;
.rangeslider {
margin: 0;
.rangeslider__handle {
height:10px;
width:10px;
&:after {
display:none;
}
}
.rangeslider__fill {
background-image: -webkit-linear-gradient(top,#89cdef 0,#81bfde 100%);
background-image: -o-linear-gradient(top,#89cdef 0,#81bfde 100%);
background-image: linear-gradient(to bottom,#89cdef 0,#81bfde 100%);
background-repeat: repeat-x;
}
}
}
2 changes: 1 addition & 1 deletion src/pages/studyView/charts/ChartContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export class ChartContainer extends React.Component<IChartContainerProps, {}> {
xLabelWithEventTooltip="Time of death"
xLabelWithoutEventTooltip="Time of last observation"
showDownloadButtons={false}
disableZoom={true}
showSlider={false}
showTable={false}
styleOpts={{
width: getWidthByDimension(this.props.dimension, this.borderWidth),
Expand Down