Skip to content

Commit

Permalink
address second review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai committed Jan 8, 2024
1 parent c7ff3b5 commit f964259
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 216 deletions.
4 changes: 2 additions & 2 deletions src/pages/resultsView/ResultsViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ export class ResultsViewPageStore extends AnalysisStore

@observable _userSelectedStudiesToClinicalTracksColors: {
[studies: string]: {
[label: string]: {
[value: string]: RGBAColor;
[trackLabel: string]: {
[attributeValue: string]: RGBAColor;
};
};
} = { global: {} };
Expand Down
126 changes: 26 additions & 100 deletions src/pages/staticPages/tools/oncoprinter/Oncoprinter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ import { Modal } from 'react-bootstrap';
import ClinicalTrackColorPicker from 'shared/components/oncoprint/ClinicalTrackColorPicker';
import classnames from 'classnames';
import { getDefaultClinicalAttributeColoringForStringDatatype } from './OncoprinterToolUtils';
import { OncoprintColorModal } from 'shared/components/oncoprint/OncoprintColorModal';

interface IOncoprinterProps {
divId: string;
store: OncoprinterStore;
}

const DEFAULT_WHITE = [255, 255, 255, 1];
const DEFAULT_UNKNOWN_COLOR = [255, 255, 255, 1];
const DEFAULT_MIXED_COLOR = [220, 57, 18, 1];

@observer
export default class Oncoprinter extends React.Component<
Expand Down Expand Up @@ -420,6 +422,8 @@ export default class Oncoprinter extends React.Component<
this.trackKeySelectedForEdit = key;
}

// if trackKeySelectedForEdit is null ('Edit Colors' has not been selected in an individual track menu),
// selectedClinicalTrack will be undefined
@computed get selectedClinicalTrack() {
return _.find(
this.props.store.clinicalTracks,
Expand All @@ -440,126 +444,48 @@ export default class Oncoprinter extends React.Component<
}

@autobind
private getDefaultSelectedClinicalTrackColor(value: string) {
private getSelectedClinicalTrackDefaultColorForValue(
attributeValue: string
) {
if (!this.selectedClinicalTrack) {
return DEFAULT_WHITE;
return DEFAULT_UNKNOWN_COLOR;
}
switch (this.selectedClinicalTrack.datatype) {
case 'counts':
return MUTATION_SPECTRUM_FILLS[
_.indexOf(MUTATION_SPECTRUM_CATEGORIES, value)
_.indexOf(MUTATION_SPECTRUM_CATEGORIES, attributeValue)
];
case 'string':
// Mixed refers to when an event has multiple values (i.e. Sample Type for a patient event may have both Primary and Recurrence values)
if (value === 'Mixed') {
return [220, 57, 18, 1];
if (attributeValue === 'Mixed') {
return DEFAULT_MIXED_COLOR;
} else {
return this
.defaultClinicalAttributeColoringForStringDatatype[
value
attributeValue
];
}
default:
return DEFAULT_WHITE;
}
}

@computed get selectedClinicalTrackValues() {
if (this.selectedClinicalTrack) {
return getClinicalTrackValues(this.selectedClinicalTrack);
return DEFAULT_UNKNOWN_COLOR;
}
return [];
}

public render() {
return (
<div className="posRelative">
{this.selectedClinicalTrack && (
<Modal
show={true}
onHide={() => this.setTrackKeySelectedForEdit(null)}
>
<Modal.Header closeButton>
<Modal.Title>
Color Configuration:{' '}
{this.selectedClinicalTrack.label}
</Modal.Title>
</Modal.Header>
<Modal.Body>
<table className="table table-striped">
<thead>
<tr>
<th>Value</th>
<th>Color</th>
</tr>
</thead>
<tbody>
{this.selectedClinicalTrackValues.map(
value => (
<tr>
<td>{value}</td>
<td>
<ClinicalTrackColorPicker
handleClinicalTrackColorChange={
this
.handleSelectedClinicalTrackColorChange
}
clinicalTrackValue={
value
}
color={getClinicalTrackColor(
this
.selectedClinicalTrack!,
value as string
)}
/>
</td>
</tr>
)
)}
</tbody>
</table>
<button
className={classnames(
'btn',
'btn-default',
'btn-sm',
{
hidden: _.every(
this.selectedClinicalTrackValues,
v =>
rgbaToHex(
getClinicalTrackColor(
this
.selectedClinicalTrack!,
v as string
)
) ===
rgbaToHex(
this.getDefaultSelectedClinicalTrackColor(
v
) as RGBAColor
)
),
}
)}
data-test="resetColors"
style={{ marginTop: 5 }}
onClick={() => {
this.selectedClinicalTrackValues.forEach(
v => {
this.handleSelectedClinicalTrackColorChange(
v,
undefined
);
}
);
}}
>
Reset Colors
</button>
</Modal.Body>
</Modal>
<OncoprintColorModal
setTrackKeySelectedForEdit={
this.setTrackKeySelectedForEdit
}
selectedClinicalTrack={this.selectedClinicalTrack}
handleSelectedClinicalTrackColorChange={
this.handleSelectedClinicalTrackColorChange
}
getSelectedClinicalTrackDefaultColorForValue={
this.getSelectedClinicalTrackDefaultColorForValue
}
/>
)}
<div
className={classNames('oncoprintContainer', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,20 +521,24 @@ export function getClinicalTracks(
attr.countsCategories!.length ===
MUTATION_SPECTRUM_FILLS.length
) {
countsCategoryFills = MUTATION_SPECTRUM_FILLS.slice();
_.forEach(attr.countsCategories, (label, i) => {
if (
userSelectedClinicalTracksColors[attr.trackName] &&
userSelectedClinicalTracksColors[attr.trackName][
label
]
) {
countsCategoryFills[i] =
countsCategoryFills = attr.countsCategories!.map(
(label, i) => {
if (
userSelectedClinicalTracksColors[
attr.trackName
] &&
userSelectedClinicalTracksColors[
attr.trackName
][label]
) {
return userSelectedClinicalTracksColors[
attr.trackName
][label];
} else {
return MUTATION_SPECTRUM_FILLS[i];
}
}
});
);
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/staticPages/tools/oncoprinter/OncoprinterStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export default class OncoprinterStore {
@observable customDriverWarningHidden: boolean;

@observable _userSelectedClinicalTracksColors: {
[label: string]: {
[value: string]: RGBAColor;
[trackLabel: string]: {
[attributeValue: string]: RGBAColor;
};
} = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getDefaultClinicalAttributeColoringForStringDatatype(
const colorGetter = makeUniqueColorGetter(
_.values(RESERVED_CLINICAL_VALUE_COLORS)
);
let categoryToColor = _.cloneDeep(RESERVED_CLINICAL_VALUE_COLORS);
let categoryToColor: { [value: string]: string } = {};
for (const d of data) {
if (
(d.attr_val as string) !== '' &&
Expand All @@ -42,5 +42,9 @@ export function getDefaultClinicalAttributeColoringForStringDatatype(
categoryToColor[d.attr_val as string] = colorGetter();
}
}
categoryToColor = Object.assign(
categoryToColor,
RESERVED_CLINICAL_VALUE_COLORS
);
return categoryToColor;
}
107 changes: 107 additions & 0 deletions src/shared/components/oncoprint/OncoprintColorModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { action, makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { ClinicalTrackSpec } from './Oncoprint';
import {
getClinicalTrackColor,
getClinicalTrackValues,
} from './ResultsViewOncoprint';
import { Modal } from 'react-bootstrap';
import ClinicalTrackColorPicker from './ClinicalTrackColorPicker';
import { RGBAColor } from 'oncoprintjs';
import classnames from 'classnames';
import _ from 'lodash';
import { rgbaToHex } from 'shared/lib/Colors';

interface IOncoprintColorModalProps {
setTrackKeySelectedForEdit: (key: string | null) => void;
selectedClinicalTrack: ClinicalTrackSpec;
handleSelectedClinicalTrackColorChange: (
value: string,
color: RGBAColor | undefined
) => void;
getSelectedClinicalTrackDefaultColorForValue: (value: string) => number[];
}

export const OncoprintColorModal: React.FC<IOncoprintColorModalProps> = observer(
({
setTrackKeySelectedForEdit,
selectedClinicalTrack,
handleSelectedClinicalTrackColorChange,
getSelectedClinicalTrackDefaultColorForValue,
}: IOncoprintColorModalProps) => {
const clinicalTrackValues = getClinicalTrackValues(
selectedClinicalTrack
);

return (
<Modal show={true} onHide={() => setTrackKeySelectedForEdit(null)}>
<Modal.Header closeButton>
<Modal.Title>
Color Configuration: {selectedClinicalTrack.label}
</Modal.Title>
</Modal.Header>
<Modal.Body>
<table className="table table-striped">
<thead>
<tr>
<th>Value</th>
<th>Color</th>
</tr>
</thead>
<tbody>
{clinicalTrackValues.map(value => (
<tr>
<td>{value}</td>
<td>
<ClinicalTrackColorPicker
handleClinicalTrackColorChange={
handleSelectedClinicalTrackColorChange
}
clinicalTrackValue={value}
color={getClinicalTrackColor(
selectedClinicalTrack,
value as string
)}
/>
</td>
</tr>
))}
</tbody>
</table>
<button
className={classnames('btn', 'btn-default', 'btn-sm', {
hidden: _.every(
clinicalTrackValues,
v =>
rgbaToHex(
getClinicalTrackColor(
selectedClinicalTrack,
v as string
)
) ===
rgbaToHex(
getSelectedClinicalTrackDefaultColorForValue(
v
) as RGBAColor
)
),
})}
data-test="resetColors"
style={{ marginTop: 5 }}
onClick={() => {
clinicalTrackValues.forEach(v => {
handleSelectedClinicalTrackColorChange(
v,
undefined
);
});
}}
>
Reset Colors
</button>
</Modal.Body>
</Modal>
);
}
);
Loading

0 comments on commit f964259

Please sign in to comment.