Skip to content

Commit

Permalink
fix(shiftedOpacity): Do not shift opacity values of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
bnmajor committed Nov 7, 2023
1 parent c601192 commit 0b2600b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/utils/vtk-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ export function getShiftedOpacityFromPreset(

const [xmin, xmax] = effectiveRange;
const width = xmax - xmin;
return points.map(([x, y]) => [(x - xmin) / width + shift, y - shiftAlpha]);
return points.map(([x, y]) => {
// Non-zero values should be affected by shift
// but preset values of zero should not
const shifted = y - shiftAlpha;
const yVal = y || shifted ? shifted : -1;
return [(x - xmin) / width + shift, yVal];
});
}
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/vtk/PiecewiseWidget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export function samplePiecewiseLinear(
} else if (slope === -Infinity) {
sampledPoints.push(0);
} else {
sampledPoints.push(slope * (sx - p1[0]) + (p1[1] - shiftAlpha));
// Non-zero values should be affected by shift
// but original values of zero should not
const shifted = p1[1] - shiftAlpha;
const y = p1[1] || shifted ? shifted : -1;
sampledPoints.push(slope * (sx - p1[0]) + y);
}
}
}
Expand Down

0 comments on commit 0b2600b

Please sign in to comment.