Skip to content

Commit

Permalink
Add _hasMeasurementColor attr and coloring for measurements coloring
Browse files Browse the repository at this point in the history
Adds a new attr and boolean type coloring `_hasMeasurementColor` to
the tree so that it can be used to filter to only tips that are
colored by the measurements coloring.
  • Loading branch information
joverlee521 committed Jan 9, 2025
1 parent e52f48d commit 972ed91
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/actions/measurements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ interface Query extends MeasurementsQuery {
[key: string]: string | string[]
}


const hasMeasurementColorAttr = "_hasMeasurementColor";
const hasMeasurementColorValue = "true";
interface MeasurementsNodeAttrs {
[strain: string]: {
[measurementsColorBy: string]: {
value: number
[key: string]: {
// number for the average measurements value
// 'true' for the presence of measurements coloring
value: number | typeof hasMeasurementColorValue
}
[hasMeasurementColorAttr]: {
value: typeof hasMeasurementColorValue
}
}
}
Expand Down Expand Up @@ -666,6 +674,9 @@ function createMeasurementsColoringData(
nodeAttrs[strain] = {
[measurementColorBy]: {
value: averageMeasurementValue
},
[hasMeasurementColorAttr]: {
value: hasMeasurementColorValue
}
};
}
Expand All @@ -687,6 +698,10 @@ function createMeasurementsColoringData(
title: `Measurements (${groupingValue})`,
type: "continuous",
scale: measurementsColorScale,
},
[hasMeasurementColorAttr]: {
title: `Has measurements for ${groupingValue}`,
type: "boolean",
}
}
};
Expand Down Expand Up @@ -726,7 +741,7 @@ function updateMeasurementsColorData(
}
dispatch({
type: REMOVE_METADATA,
nodeAttrsToRemove: [encodeMeasurementColorBy(oldColorGrouping)],
nodeAttrsToRemove: [hasMeasurementColorAttr, encodeMeasurementColorBy(oldColorGrouping)],
})
}
/* If there is a valid new color grouping, then add the measurement metadata and coloring */
Expand All @@ -748,7 +763,7 @@ export const applyMeasurementsColorBy = (
*/
batch(() => {
if (controls.measurementsColorGrouping !== undefined) {
dispatch({type: REMOVE_METADATA, nodeAttrsToRemove: [encodeMeasurementColorBy(controls.measurementsColorGrouping)]});
dispatch({type: REMOVE_METADATA, nodeAttrsToRemove: [hasMeasurementColorAttr, encodeMeasurementColorBy(controls.measurementsColorGrouping)]});
}
if (controls.measurementsColorGrouping !== groupingValue) {
dispatch({type: CHANGE_MEASUREMENTS_COLOR_GROUPING, controls:{measurementsColorGrouping: groupingValue}});
Expand Down

0 comments on commit 972ed91

Please sign in to comment.