Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix in contrastRatio function #3013

Merged
merged 4 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Fixed `EuiButton` and other textual components' disabled contrast ([#2874](https://github.com/elastic/eui/pull/2874))
- Fixed z-index conflict with cell popovers in `EuiDataGrid` while in full screen mode ([#2959](https://github.com/elastic/eui/pull/2959))
- Adjusted the header on `EuiDataGrid` to fix to the top within constrained containers and full screen mode ([#2959](https://github.com/elastic/eui/pull/2959))
- Fixed ContrastRatio function in src/global_styling/function/_colors.scss. ([#3013], (https://github.com/elastic/eui/pull/3013))

**Breaking changes**

Expand Down
71 changes: 45 additions & 26 deletions src/global_styling/functions/_math.scss
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
// Greatest common devisor
// From: http://rosettacode.org/wiki/Greatest_common_divisor#JavaScript
@function gcd($a, $b) {
@if ($b != 0) {
@return gcd($b, $a % $b);
} @else {
@return abs($a);
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow
@function pow($number, $power) {
@if ($power != $power or ($power != 0 and $power == $power / 2)) {
@return $power;
}
}

// Handles decimal exponents by trying to convert them into a fraction and then
// use a nthRoot-algorithm for parts of the calculation
@function pow($base, $exponent, $prec: 12) {
@if (floor($exponent) != $exponent) {
$prec2: pow(10, $prec);
$exponent: round($exponent * $prec2);
$denominator: gcd($exponent, $prec2);
@return nthRoot(pow($base, $exponent / $denominator), $prec2 / $denominator, $prec);
@if ($power == 1) {
@return $number;
}

$value: $base;
@if $exponent > 1 {
@for $i from 2 through $exponent {
$value: $value * $base;
@if ($power == 0) {
@return 1;
}
@if ($power < 0) {
@return 1 / pow($number, -$power);
}
@if (0 < $power and $power < 2) {
$hasLeadingOne: false;
@if (floor($power) == 1) {
$power: $power - 1;
$hasLeadingOne: true;
} @else {
$hasLeadingOne: false;
}
} @else if $exponent < 1 {
@for $i from 0 through -$exponent {
$value: $value / $base;
$doublePower: pow($number, $power * 2);
$fullPower: nthRoot($doublePower, 2);
@if ($hasLeadingOne) {
$fullPower: $fullPower * $number;
}
@return $fullPower;
} @else if (getDecimal($power) != 0) {
$wholePower: floor($power);
$decimalPower: getDecimal($power);
@return pow($number, $wholePower) * pow($number, $decimalPower);
} @else {
$hasTrailingOne: $power % 2 == 1;
@if ($hasTrailingOne) {
$power: $power - 1;
}
$halfPower: pow($number, floor($power / 2));
$fullPower: $halfPower * $halfPower;
@if ($hasTrailingOne) {
$fullPower: $fullPower * $number;
}
@return $fullPower;
}
}

@return $value;
@function getDecimal($number) {
@if ($number < 0) {
$number: -$number;
}
@return $number % 1;
}

// From: http://rosettacode.org/wiki/Nth_root#JavaScript
Expand Down