in src/Desktop/ColorContrastAnalyzer/ColorContrastRunner.cs [71:122]
internal ColorContrastResult OnRowEnd()
{
ColorContrastResult result = new ColorContrastResult();
CountMap<ColorPair> pairsWithSimilarTextColor = new CountMap<ColorPair>();
foreach (var exactPairOuter in countExactPairs)
{
foreach (var exactPairInner in countExactPairs)
{
if (exactPairOuter.Key.backgroundColor.Equals(exactPairInner.Key.backgroundColor))
{
if (exactPairOuter.Key.foregroundColor.IsSimilarColor(exactPairInner.Key.foregroundColor))
{
pairsWithSimilarTextColor.Increment(exactPairOuter.Key, exactPairInner.Value);
}
}
}
}
var sortedByValueAndContrast = pairsWithSimilarTextColor.OrderByDescending(x => x.Value)
.ThenByDescending(x => x.Key.ColorContrast());
if (!sortedByValueAndContrast.Any()) return result;
var resultPairs = new HashSet<ColorPair>();
var firstEntryCount = sortedByValueAndContrast.First().Value;
if (firstEntryCount < _colorContrastConfig.MinNumberColorTransitions) return result;
var firstEntryCountAdjusted = firstEntryCount / _colorContrastConfig.TransitionCountDominanceFactor;
foreach (var entry in sortedByValueAndContrast)
{
// Only Collect Pairs that have a reasonable occurence count.
if (entry.Value < firstEntryCountAdjusted) break;
resultPairs.Add(entry.Key);
}
foreach (var colorPair in resultPairs)
{
result.Add(colorPair);
}
countExactColors.Clear();
openTransitions.Clear();
return result;
}