< Summary

Information
Class: OzonOrdersWeb.Areas.Studio2.ViewHelpers.StatusColorContrast
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/ViewHelpers/StatusColorContrast.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 41
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetTextColor(...)0%156120%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/ViewHelpers/StatusColorContrast.cs

#LineLine coverage
 1namespace OzonOrdersWeb.Areas.Studio2.ViewHelpers;
 2
 3public static class StatusColorContrast
 4{
 5  /// <summary>Контрастный цвет текста для плашки статуса на заданном фоне.</summary>
 6  public static string GetTextColor(string? hexColor)
 7  {
 08    if (string.IsNullOrWhiteSpace(hexColor)
 09        || string.Equals(hexColor.Trim(), "transparent", StringComparison.OrdinalIgnoreCase))
 10    {
 011      return "#0F172A";
 12    }
 13
 014    var hex = hexColor.Trim().TrimStart('#').ToLowerInvariant();
 015    if (hex.Length == 3)
 16    {
 017      hex = string.Concat(hex[0], hex[0], hex[1], hex[1], hex[2], hex[2]);
 18    }
 19
 020    if (hex.Length != 6)
 21    {
 022      return "#0F172A";
 23    }
 24
 25    try
 26    {
 027      var r = Convert.ToInt32(hex.Substring(0, 2), 16);
 028      var g = Convert.ToInt32(hex.Substring(2, 2), 16);
 029      var b = Convert.ToInt32(hex.Substring(4, 2), 16);
 030      var luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
 31
 032      if (luminance > 0.72) return "#020617";
 033      if (luminance > 0.5) return "#0F172A";
 034      return "#FFFFFF";
 35    }
 036    catch
 37    {
 038      return "#0F172A";
 39    }
 040  }
 41}

Methods/Properties

GetTextColor(System.String)