Skip to content

Commit

Permalink
Merge pull request cBioPortal#89 from cBioPortal/custom-options-impro…
Browse files Browse the repository at this point in the history
…vements

improvements to custom track options
  • Loading branch information
adamabeshouse authored and alisman committed Jun 8, 2022
1 parent e923d2d commit d4e3b24
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
41 changes: 26 additions & 15 deletions packages/oncoprintjs/dist/oncoprint.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23556,7 +23556,7 @@ var SEPARATOR_CLASS = "oncoprintjs__track_options__separator";
var NTH_CLASS_PREFIX = "nth-";

var OncoprintTrackOptionsView = (function () {
function OncoprintTrackOptionsView($div, moveUpCallback, moveDownCallback, removeCallback, sortChangeCallback, unexpandCallback, custom_options) {
function OncoprintTrackOptionsView($div, moveUpCallback, moveDownCallback, removeCallback, sortChangeCallback, unexpandCallback) {
var position = $div.css('position');
if (position !== 'absolute' && position !== 'relative') {
console.log("WARNING: div passed to OncoprintTrackOptionsView must be absolute or relative positioned - layout problems will occur");
Expand All @@ -23567,7 +23567,6 @@ var OncoprintTrackOptionsView = (function () {
this.removeCallback = removeCallback; // function(track_id) { ... }
this.sortChangeCallback = sortChangeCallback; // function(track_id, dir) { ... }
this.unexpandCallback = unexpandCallback; // function(track_id)
this.custom_options = custom_options;

this.$div = $div;
this.$ctr = $('<div></div>').css({'position': 'absolute', 'overflow-y':'hidden', 'overflow-x':'hidden'}).appendTo(this.$div);
Expand Down Expand Up @@ -23669,14 +23668,20 @@ var OncoprintTrackOptionsView = (function () {
var $makeDropdownOption = function (text, weight, disabled, callback) {
var li = $('<li>').text(text).css({'font-weight': weight, 'font-size': 12, 'border-bottom': '1px solid rgba(0,0,0,0.3)'})
if (!disabled) {
li.css({'cursor': 'pointer'})
.click(callback)
.hover(function () {
$(this).css({'background-color': 'rgb(200,200,200)'});
}, function () {
$(this).css({'background-color': 'rgba(255,255,255,0)'});
});
if (callback) {
li.addClass("clickable");
li.css({'cursor': 'pointer'});
li.click(callback)
.hover(function () {
$(this).css({'background-color': 'rgb(200,200,200)'});
}, function () {
$(this).css({'background-color': 'rgba(255,255,255,0)'});
});
} else {
li.click(function(evt) { evt.stopPropagation(); });
}
} else {
li.addClass("disabled");
li.css({'color': 'rgb(200, 200, 200)', 'cursor': 'default'});
}
return li;
Expand Down Expand Up @@ -23825,13 +23830,19 @@ var OncoprintTrackOptionsView = (function () {
// Add custom options
var custom_options = model.getTrackCustomOptions(track_id);
if (custom_options && custom_options.length > 0) {
$dropdown.append($makeDropdownSeparator());
for (var i=0; i<custom_options.length; i++) {
var option = custom_options[i];
$dropdown.append($makeDropdownOption(option.label, option.weight || "normal", !!option.disabled, function (evt) {
evt.stopPropagation();
option.onClick(track_id);
}));
(function() {
// wrapped in function to prevent scope issues
var option = custom_options[i];
if (option.separator) {
$dropdown.append($makeDropdownSeparator());
} else {
$dropdown.append($makeDropdownOption(option.label || "", option.weight || "normal", !!option.disabled, option.onClick && function (evt) {
evt.stopPropagation();
option.onClick(track_id);
}));
}
})()
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/oncoprintjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ declare module "oncoprintjs"

export type ShapeSpec = any; // TODO

export type CustomTrackOption = { label:string, onClick:(id:TrackId)=>void, weight?:string, disabled?:boolean};
export type CustomTrackOption = {label?:string, separator?: boolean, onClick?:(id:TrackId)=>void, weight?:string, disabled?:boolean};

export type TrackSpec<D> = {
target_group?:TrackGroupIndex;
Expand Down
41 changes: 26 additions & 15 deletions packages/oncoprintjs/src/js/oncoprinttrackoptionsview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var SEPARATOR_CLASS = "oncoprintjs__track_options__separator";
var NTH_CLASS_PREFIX = "nth-";

var OncoprintTrackOptionsView = (function () {
function OncoprintTrackOptionsView($div, moveUpCallback, moveDownCallback, removeCallback, sortChangeCallback, unexpandCallback, custom_options) {
function OncoprintTrackOptionsView($div, moveUpCallback, moveDownCallback, removeCallback, sortChangeCallback, unexpandCallback) {
var position = $div.css('position');
if (position !== 'absolute' && position !== 'relative') {
console.log("WARNING: div passed to OncoprintTrackOptionsView must be absolute or relative positioned - layout problems will occur");
Expand All @@ -19,7 +19,6 @@ var OncoprintTrackOptionsView = (function () {
this.removeCallback = removeCallback; // function(track_id) { ... }
this.sortChangeCallback = sortChangeCallback; // function(track_id, dir) { ... }
this.unexpandCallback = unexpandCallback; // function(track_id)
this.custom_options = custom_options;

this.$div = $div;
this.$ctr = $('<div></div>').css({'position': 'absolute', 'overflow-y':'hidden', 'overflow-x':'hidden'}).appendTo(this.$div);
Expand Down Expand Up @@ -121,14 +120,20 @@ var OncoprintTrackOptionsView = (function () {
var $makeDropdownOption = function (text, weight, disabled, callback) {
var li = $('<li>').text(text).css({'font-weight': weight, 'font-size': 12, 'border-bottom': '1px solid rgba(0,0,0,0.3)'})
if (!disabled) {
li.css({'cursor': 'pointer'})
.click(callback)
.hover(function () {
$(this).css({'background-color': 'rgb(200,200,200)'});
}, function () {
$(this).css({'background-color': 'rgba(255,255,255,0)'});
});
if (callback) {
li.addClass("clickable");
li.css({'cursor': 'pointer'});
li.click(callback)
.hover(function () {
$(this).css({'background-color': 'rgb(200,200,200)'});
}, function () {
$(this).css({'background-color': 'rgba(255,255,255,0)'});
});
} else {
li.click(function(evt) { evt.stopPropagation(); });
}
} else {
li.addClass("disabled");
li.css({'color': 'rgb(200, 200, 200)', 'cursor': 'default'});
}
return li;
Expand Down Expand Up @@ -277,13 +282,19 @@ var OncoprintTrackOptionsView = (function () {
// Add custom options
var custom_options = model.getTrackCustomOptions(track_id);
if (custom_options && custom_options.length > 0) {
$dropdown.append($makeDropdownSeparator());
for (var i=0; i<custom_options.length; i++) {
var option = custom_options[i];
$dropdown.append($makeDropdownOption(option.label, option.weight || "normal", !!option.disabled, function (evt) {
evt.stopPropagation();
option.onClick(track_id);
}));
(function() {
// wrapped in function to prevent scope issues
var option = custom_options[i];
if (option.separator) {
$dropdown.append($makeDropdownSeparator());
} else {
$dropdown.append($makeDropdownOption(option.label || "", option.weight || "normal", !!option.disabled, option.onClick && function (evt) {
evt.stopPropagation();
option.onClick(track_id);
}));
}
})()
}
}
};
Expand Down

0 comments on commit d4e3b24

Please sign in to comment.