Skip to content

Commit

Permalink
fixing bug where some layouts crashed the cluster coord calculation, …
Browse files Browse the repository at this point in the history
…refs #29623
  • Loading branch information
maximilianh committed Jul 8, 2022
1 parent 673da67 commit 2b1690f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/cbPyLib/cellbrowser/cbWeb/js/cellBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3293,20 +3293,8 @@ var cellbrowser = function() {
// console.log(metaInfo);

console.time("cluster centers");
var calc = {};
for (var i = 0, I = values.length; i < I; i++) {
if (names) {
var label = names[values[i]];
} else {
var label = metaInfo.origVals[i].toFixed(2);
}
if (calc[label] === undefined) {
calc[label] = [[], [], 0]; // all X, all Y, count
}
calc[label][0].push(coords[i * 2]);
calc[label][1].push(coords[i * 2 + 1]);
calc[label][2] += 1;
}
var calc = renderer.calcMedian(coords, values, names, metaInfo.origVals);

labelCoords = [];
for (label in calc) {
var midX = selectMedian(calc[label][0]);
Expand Down
31 changes: 31 additions & 0 deletions src/cbPyLib/cellbrowser/cbWeb/js/maxPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function MaxPlot(div, top, left, width, height, args) {
// In rare instances, coordinates are saved but should not be shown. This way of implementing hiding
// may look hacky, but it simplifies the logic and improves performance.

// export this special value so other part of the code can use it
this.hiddenCoord = HIDCOORD;

var self = this; // 'this' has two conflicting meanings in javascript.
// I use 'self' to refer to object variables, so I can use 'this' to refer to the caller context

Expand Down Expand Up @@ -2234,6 +2237,34 @@ function MaxPlot(div, top, left, width, height, args) {
return self.width;
}

this.calcMedian = function(coords, values, names, numNames) {
/* given an array of coordinates (x at even positions, y at odd positions) and an array of names for each of them
* return the median for each name as an object name -> array of [x, y, count]
* if names is undefined, will use numNames and convert to two decimals
* */
var calc = {};
for (var i = 0, I = values.length; i < I; i++) {
var label = null;
if (names) {
label = names[values[i]];
} else {
label = numNames[i].toFixed(2);
}
if (calc[label] === undefined) {
calc[label] = [[], [], 0]; // all X, all Y, count
}
var x = coords[i * 2];
var y = coords[i * 2 + 1];

if (isHidden(x, y))
continue;

calc[label][0].push(x);
calc[label][1].push(y);
calc[label][2] += 1;
}
}

// object constructor code
self.initCanvas(div, top, left, width, height);
self.initPlot(args);
Expand Down

0 comments on commit 2b1690f

Please sign in to comment.