mirror of https://github.com/apache/superset.git
fix: Respecting max/min opacities, and adding tests. (#20555)
* Respecting max/min opacities, and adding tests. * revising tests * Adding missing test case for maximum coverage :) * removing unnecessary logic and test * adding another unit test for (hopefully) full coverage. * no more ternary operator * New approach with Math.min - take THAT codecov. * one more stab at making codecov happy... ignoring the file next. * lint fixes
This commit is contained in:
parent
f5f8ddec3e
commit
ac8e502228
|
@ -37,16 +37,21 @@ export const getOpacity = (
|
|||
extremeValue: number,
|
||||
minOpacity = MIN_OPACITY_BOUNDED,
|
||||
maxOpacity = MAX_OPACITY,
|
||||
) =>
|
||||
extremeValue === cutoffPoint
|
||||
? maxOpacity
|
||||
: round(
|
||||
Math.abs(
|
||||
((maxOpacity - minOpacity) / (extremeValue - cutoffPoint)) *
|
||||
(value - cutoffPoint),
|
||||
) + minOpacity,
|
||||
2,
|
||||
);
|
||||
) => {
|
||||
if (extremeValue === cutoffPoint) {
|
||||
return maxOpacity;
|
||||
}
|
||||
return Math.min(
|
||||
maxOpacity,
|
||||
round(
|
||||
Math.abs(
|
||||
((maxOpacity - minOpacity) / (extremeValue - cutoffPoint)) *
|
||||
(value - cutoffPoint),
|
||||
) + minOpacity,
|
||||
2,
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
export const getColorFunction = (
|
||||
{
|
||||
|
|
|
@ -50,6 +50,9 @@ describe('getOpacity', () => {
|
|||
expect(getOpacity(100, 100, 50)).toEqual(0.05);
|
||||
expect(getOpacity(100, 100, 100, 0, 0.8)).toEqual(0.8);
|
||||
expect(getOpacity(100, 100, 50, 0, 1)).toEqual(0);
|
||||
expect(getOpacity(999, 100, 50, 0, 1)).toEqual(1);
|
||||
expect(getOpacity(100, 100, 50, 0.99, 1)).toEqual(0.99);
|
||||
expect(getOpacity(99, 100, 50, 0, 1)).toEqual(0.02);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue