Skip to content
Snippets Groups Projects
Commit c9a3254b authored by Alexander Rose's avatar Alexander Rose
Browse files

fix partial marker average calculation

parent bad6d030
Branches
Tags
No related merge requests found
...@@ -76,6 +76,7 @@ namespace Visual { ...@@ -76,6 +76,7 @@ namespace Visual {
const { tMarker, dMarkerType, uMarker, markerAverage, markerStatus, uGroupCount, instanceCount } = renderObject.values; const { tMarker, dMarkerType, uMarker, markerAverage, markerStatus, uGroupCount, instanceCount } = renderObject.values;
const count = uGroupCount.ref.value * instanceCount.ref.value; const count = uGroupCount.ref.value * instanceCount.ref.value;
const { array } = tMarker.ref.value; const { array } = tMarker.ref.value;
const currentStatus = markerStatus.ref.value as MarkerInfo['status'];
if (!isEveryLoci(loci)) { if (!isEveryLoci(loci)) {
let intervalSize = 0; let intervalSize = 0;
...@@ -90,9 +91,9 @@ namespace Visual { ...@@ -90,9 +91,9 @@ namespace Visual {
let average = -1; let average = -1;
let status: MarkerInfo['status'] = -1; let status: MarkerInfo['status'] = -1;
if (isEveryLoci(loci)) { if (isEveryLoci(loci)) {
const info = getMarkerInfo(action, markerStatus.ref.value); const info = getMarkerInfo(action, currentStatus);
if (info.status !== -1) { if (info.status !== -1) {
changed = markerStatus.ref.value !== info.status; changed = currentStatus !== info.status;
if (changed) setMarkerValue(array, info.status, count); if (changed) setMarkerValue(array, info.status, count);
} else { } else {
changed = applyMarkerAction(array, Interval.ofLength(count), action); changed = applyMarkerAction(array, Interval.ofLength(count), action);
...@@ -102,13 +103,13 @@ namespace Visual { ...@@ -102,13 +103,13 @@ namespace Visual {
} else { } else {
changed = lociApply(loci, interval => applyMarkerAction(array, interval, action), true); changed = lociApply(loci, interval => applyMarkerAction(array, interval, action), true);
if (changed) { if (changed) {
average = getPartialMarkerAverage(action, markerStatus.ref.value); average = getPartialMarkerAverage(action, currentStatus);
if (previous && previous.status !== -1 && average === -1 && if (previous && previous.status !== -1 && average === -1 &&
MarkerActions.isReverse(previous.action, action) && MarkerActions.isReverse(previous.action, action) &&
Loci.areEqual(loci, previous.loci) Loci.areEqual(loci, previous.loci)
) { ) {
status = previous.status; status = previous.status;
average = status === 0 ? 0 : 1; average = status === 0 ? 0 : 0.5;
} }
} }
} }
...@@ -120,7 +121,7 @@ namespace Visual { ...@@ -120,7 +121,7 @@ namespace Visual {
if (previous) { if (previous) {
previous.action = action; previous.action = action;
previous.loci = loci; previous.loci = loci;
previous.status = markerStatus.ref.value as MarkerInfo['status']; previous.status = currentStatus;
} }
ValueCell.updateIfChanged(uMarker, status); ValueCell.updateIfChanged(uMarker, status);
if (status === -1) ValueCell.update(tMarker, tMarker.ref.value); if (status === -1) ValueCell.update(tMarker, tMarker.ref.value);
......
...@@ -153,7 +153,7 @@ export interface MarkerInfo { ...@@ -153,7 +153,7 @@ export interface MarkerInfo {
status: 0 | 1 | 2 | 3 | -1 status: 0 | 1 | 2 | 3 | -1
} }
export function getMarkerInfo(action: MarkerAction, currentStatus: number): MarkerInfo { export function getMarkerInfo(action: MarkerAction, currentStatus: MarkerInfo['status']): MarkerInfo {
let average: MarkerInfo['average'] = -1; let average: MarkerInfo['average'] = -1;
let status: MarkerInfo['status'] = -1; let status: MarkerInfo['status'] = -1;
switch (action) { switch (action) {
...@@ -224,52 +224,45 @@ export function getMarkerInfo(action: MarkerAction, currentStatus: number): Mark ...@@ -224,52 +224,45 @@ export function getMarkerInfo(action: MarkerAction, currentStatus: number): Mark
* Assumes the action is applied to a partial set that is * Assumes the action is applied to a partial set that is
* neither the empty set nor the full set. * neither the empty set nor the full set.
*/ */
export function getPartialMarkerAverage(action: MarkerAction, currentStatus: number): MarkerInfo['average'] { export function getPartialMarkerAverage(action: MarkerAction, currentStatus: MarkerInfo['status']) {
switch (action) { switch (action) {
case MarkerAction.Highlight: case MarkerAction.Highlight:
return 1; return 0.5;
case MarkerAction.RemoveHighlight: case MarkerAction.RemoveHighlight:
if (currentStatus === 0) { if (currentStatus === 0) {
return 0; return 0;
} else if (currentStatus === 1) {
return -1;
} else if (currentStatus === 2 || currentStatus === 3) { } else if (currentStatus === 2 || currentStatus === 3) {
return 1; return 0.5;
} else { // 1 | -1
return -1;
} }
return -1;
case MarkerAction.Select: case MarkerAction.Select:
return 1; return 0.5;
case MarkerAction.Deselect: case MarkerAction.Deselect:
if (currentStatus === 1 || currentStatus === 3) { if (currentStatus === 1 || currentStatus === 3) {
return 1; return 0.5;
} else if (currentStatus === 0) { } else if (currentStatus === 0) {
return 0; return 0;
} else if (currentStatus === 2) { } else { // 2 | -1
return -1; return -1;
} }
return -1;
case MarkerAction.Toggle: case MarkerAction.Toggle:
if (currentStatus === 1) { if (currentStatus === -1) {
return 1; return -1;
} else if (currentStatus === 2) { } else { // 0 | 1 | 2 | 3
return 1; return 0.5;
} else if (currentStatus === 3) {
return 1;
} else if (currentStatus === 0) {
return 1;
} }
return -1;
case MarkerAction.Clear: case MarkerAction.Clear:
if (currentStatus === 1) { if (currentStatus === -1) {
return 1; return -1;
} else if (currentStatus === 2) {
return 1;
} else if (currentStatus === 3) {
return 1;
} else if (currentStatus === 0) { } else if (currentStatus === 0) {
return 0; return 0;
} else { // 1 | 2 | 3
return 0.5;
} }
case MarkerAction.None:
return -1; return -1;
default:
assertUnreachable(action);
} }
return -1;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment