Skip to content

Commit

Permalink
fix frequencies category matching bug. Closes #540
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshadfield committed Apr 16, 2018
1 parent c19fff6 commit c505945
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/actions/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const processSelectedTip = (d, tree, treeToo) => {
* [0, 0]: reset. [undefined, undefined]: do nothing
* @param {object} tipSelected
* @param {int} idxOfInViewRootNodeTreeToo
= * @return {null} side effects: a single action
* @return {null} side effects: a single action
*/
export const updateVisibleTipsAndBranchThicknesses = (
{root = [undefined, undefined], tipSelected = undefined} = {}
Expand Down
1 change: 1 addition & 0 deletions src/util/colorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const calcColorScale = (colorBy, controls, tree, treeToo, metadata) => {
legendValues = colorBy === "lbi" ?
[0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7] :
genericDomain.map((d) => parseFloat((minMax[0] + d*spread).toFixed(dp)));
if (legendValues[0] === -0) legendValues[0] = 0; /* hack to avoid bugs */
/* sort out ranges */
const len = legendValues.length;
legendBounds = {};
Expand Down
19 changes: 14 additions & 5 deletions src/util/processFrequencies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

export const unassigned_label = "unassigned";

/**
* assign a given node to a category
* Find the colorBy value of the node and, using the colorScale and the provided categories,
* assign the correct category.
* @return {string} category or the unassigned label
*/
const assignCategory = (colorScale, categories, node, colorBy, isGenotype) => {
if (isGenotype) return node.currentGt;
const value = node.attr[colorBy];
Expand All @@ -10,11 +16,15 @@ const assignCategory = (colorScale, categories, node, colorBy, isGenotype) => {
if (!colorScale.continuous) return value;

for (let i = 0; i < categories.length; i++) {
/* same logic as the determineLegendMatch function */
const lowerBound = colorScale.legendBounds[categories[i]][0];
const upperBound = colorScale.legendBounds[categories[i]][1];
/* roughly the same logic as the determineLegendMatch function */
const category = categories[i];
if (category === unassigned_label) {
return unassigned_label;
}
const lowerBound = colorScale.legendBounds[category][0];
const upperBound = colorScale.legendBounds[category][1];
if (value <= upperBound && value > lowerBound) {
return categories[i];
return category;
}
}
console.error("Could not assign", value, "to a category");
Expand All @@ -29,7 +39,6 @@ export const computeMatrixFromRawData = (data, pivots, nodes, visibility, colorS
const matrix = {}; /* SHAPE: rows: categories (colorBys), columns: pivots */
const pivotsLen = pivots.length;
categories.forEach((x) => {matrix[x] = new Array(pivotsLen).fill(0);});

// let debugTipsSeen = 0;
const debugPivotTotals = new Array(pivotsLen).fill(0);
data.forEach((d) => {
Expand Down

0 comments on commit c505945

Please sign in to comment.