Skip to content

Commit

Permalink
Merge pull request maximilianh#178 from mxposed/improve-selection
Browse files Browse the repository at this point in the history
Improve selection
  • Loading branch information
maximilianh committed Jun 5, 2020
2 parents 920ac12 + da22219 commit effb6c8
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 103 deletions.
104 changes: 54 additions & 50 deletions src/cbPyLib/cellbrowser/cbWeb/js/cellBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,11 @@ var cellbrowser = function() {
}


function onSelChange(cellIds) {
function onSelChange(selection) {
/* called each time when the selection has been changed */
var cellIds = [];
selection.forEach(function(x) {cellIds.push(x)});

if (cellIds.length===0 || cellIds===null) {
clearMetaAndGene();
clearSelectionState();
Expand All @@ -1095,6 +1098,22 @@ var cellbrowser = function() {
if ("geneSym" in gLegend)
buildViolinPlot();

var cols = renderer.col.arr;
var selectedLegends = {};
for (var i = 0; i < gLegend.rows.length; i++) {
selectedLegends[i] = 0;
}
selection.forEach(function(cellId) {
selectedLegends[cols[cellId]]++;
});
for (var i = 0; i < gLegend.rows.length; i++) {
if (selectedLegends[i] == gLegend.rows[i].count) {
$("#tpLegendCheckbox_" + i).prop("checked", true);
} else {
$("#tpLegendCheckbox_" + i).prop("checked", false);
}
}
updateLegendGrandCheckbox();
}

function onSaveAsClick() {
Expand Down Expand Up @@ -3298,6 +3317,7 @@ var cellbrowser = function() {
gLegend.rowType = "range";
gLegend.exprVec = exprVec; // raw expression values, e.g. floats
gLegend.decExprVec = decExprVec; // expression values as deciles, array of bytes
gLegend.selectionDirection = "all";
legendSetPalette(gLegend, "default");

var colors = legendGetColors(legendRows);
Expand Down Expand Up @@ -3843,6 +3863,7 @@ var cellbrowser = function() {
legend.rows = rows;
legend.isSortedByName = sortResult.isSortedByName;
legend.rowType = "category";
legend.selectionDirection = "all";
legendSetPalette(legend, "default");
return legend;
}
Expand Down Expand Up @@ -5082,49 +5103,9 @@ var cellbrowser = function() {
function onLegendLabelClick(ev) {
/* called when user clicks on legend entry. */

//function saveLabel() {
///* save the current labelEl text to the cart and update everything */
//$(".tooltip").remove(); // not sure why tooltips won't disappear here
//labelEl.removeAttr("contenteditable");
//var newLabel = labelEl.text(); // = strip the rich text tags possibly added through copy/paste
//var metaInfo = gLegend.metaInfo;
//cartFieldArrayUpdate(db, metaInfo, "shortLabels", legendId, newLabel);
//legendUpdateLabels(gLegend.metaInfo.name);
//rendererUpdateLabels(metaInfo);
//buildLegendBar();
//renderer.drawDots();
//}

var legendId = parseInt(ev.target.id.split("_")[1]);
var colorIndex = gLegend.rows[legendId].intKey;

//if (("lastClicked" in gLegend) && gLegend.lastClicked===legendId) {
// user clicked the same entry as before:
//gLegend.lastClicked = null;
//$('#tpLegend_'+legendId).removeClass('tpLegendSelect');
//renderer.selectClear();
//}
//else {
// clear the old selection
//if (!ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
//renderer.selectClear();
//$('.tpLegend').removeClass('tpLegendSelect');
//}
$("#tpLegendCheckbox_"+colorIndex).prop("checked", true);
renderer.selectByColor(colorIndex);
//menuBarShow("#tpFilterButton");
//menuBarShow("#tpOnlySelectedButton");
//$('#tpLegend_'+legendId).addClass('tpLegendSelect');
//gLegend.lastClicked=legendId;
clearSelectionState();
//if (gLegend.type==="meta" && gLegend.metaInfo.type==="enum") {
//let fieldName = gLegend.metaInfo.name;
//let fieldVal = gLegend.metaInfo.valCounts[colorIndex][0];
//let queryList = [{"m":fieldName, "eq":fieldVal}];
//saveQueryList(queryList);
//}
//}
renderer.drawDots();
$("#tpLegendCheckbox_" + colorIndex).click();
}

function onSortByClick (ev) {
Expand Down Expand Up @@ -5181,25 +5162,47 @@ var cellbrowser = function() {
function setLegendHeaders(type) {
/* set the headers of the right-hand legend */
if (type==="category") {
$('#tpLegendCol1').html('<span title="unselect all checkboxes below" id="tpLegendClear">&#9746;</span><span class="tpLegendHover" title="click to sort by name"> Name<span class="caret"></span></span>');
$('#tpLegendCol1').html('<span title="select all checkboxes below" id="tpLegendClear">&#9745;</span><span class="tpLegendHover" title="click to sort by name"> Name<span class="caret"></span></span>');
$('#tpLegendCol2').html('<span class="tpLegendHover" title="click to sort by frequency"> Frequency<span class="caret"></span></span>');
}
else {
$('#tpLegendCol1').html('<span title="unselect all checkboxes below" id="tpLegendClear">&#9746;</span> Range<span');
$('#tpLegendCol1').html('<span title="select all checkboxes below" id="tpLegendClear">&#9745;</span> Range<span');
$('#tpLegendCol2').html('Frequency');
}
activateTooltip("#tpLegendClear");
activateTooltip(".tpLegendHover");
}

function updateLegendGrandCheckbox() {
var checkbox = $("#tpLegendClear");
var total = renderer.getCount();
var selected = renderer.selCells.size;
if (gLegend.selectionDirection == "all" && total == selected) {
gLegend.selectionDirection = "none";
checkbox.html("&#9746;");
// from https://stackoverflow.com/questions/9501921/change-twitter-bootstrap-tooltip-content-on-click
checkbox.attr('title', "unselect all checkboxes below")
.bsTooltip('fixTitle')
.data('bs.tooltip')
.$tip.find('.tooltip-inner')
.text("unselect all checkboxes below");
} else if (gLegend.selectionDirection == "none" && selected === 0) {
gLegend.selectionDirection = "all";
checkbox.html("&#9745;");
checkbox.attr('title', "select all checkboxes below")
.bsTooltip('fixTitle')
.data('bs.tooltip')
.$tip.find('.tooltip-inner')
.text("select all checkboxes below");
}
}

function onLegendClearClick(ev) {
/* unselect all checkboxes in the legend and clear the selection */
renderer.selectClear();
renderer.drawDots();

var cboxes = document.getElementsByClassName("tpLegendCheckbox");
for (var i=0; i < cboxes.length; i++) {
cboxes[i].checked = false;
if (gLegend.selectionDirection == "all") {
onSelectAllClick()
} else {
onSelectNoneClick();
}
ev.stopPropagation();
}
Expand All @@ -5219,6 +5222,7 @@ var cellbrowser = function() {
renderer.unselectByColor(valIdx);
renderer.drawDots();
ev.stopPropagation();
$(this).blur();
}

function buildMinMaxPart(htmls) {
Expand Down

0 comments on commit effb6c8

Please sign in to comment.