mirror of
https://github.com/apache/superset.git
synced 2024-09-06 13:57:40 -04:00
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,
|
extremeValue: number,
|
||||||
minOpacity = MIN_OPACITY_BOUNDED,
|
minOpacity = MIN_OPACITY_BOUNDED,
|
||||||
maxOpacity = MAX_OPACITY,
|
maxOpacity = MAX_OPACITY,
|
||||||
) =>
|
) => {
|
||||||
extremeValue === cutoffPoint
|
if (extremeValue === cutoffPoint) {
|
||||||
? maxOpacity
|
return maxOpacity;
|
||||||
: round(
|
}
|
||||||
Math.abs(
|
return Math.min(
|
||||||
((maxOpacity - minOpacity) / (extremeValue - cutoffPoint)) *
|
maxOpacity,
|
||||||
(value - cutoffPoint),
|
round(
|
||||||
) + minOpacity,
|
Math.abs(
|
||||||
2,
|
((maxOpacity - minOpacity) / (extremeValue - cutoffPoint)) *
|
||||||
);
|
(value - cutoffPoint),
|
||||||
|
) + minOpacity,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const getColorFunction = (
|
export const getColorFunction = (
|
||||||
{
|
{
|
||||||
|
@ -50,6 +50,9 @@ describe('getOpacity', () => {
|
|||||||
expect(getOpacity(100, 100, 50)).toEqual(0.05);
|
expect(getOpacity(100, 100, 50)).toEqual(0.05);
|
||||||
expect(getOpacity(100, 100, 100, 0, 0.8)).toEqual(0.8);
|
expect(getOpacity(100, 100, 100, 0, 0.8)).toEqual(0.8);
|
||||||
expect(getOpacity(100, 100, 50, 0, 1)).toEqual(0);
|
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
Block a user