GetWidthPos.php in Length Indicator 8
File
src/GetWidthPos.php
View source
<?php
namespace Drupal\length_indicator;
class GetWidthPos {
public function getWidthAndPosition($optimin, $optimax, $tolerance) {
$indicators = [];
$min = $optimin - $tolerance;
$max = $optimax + $tolerance;
$total = $max + $min;
$width = $min / $total * 100;
$indicators[0]['width'] = $width;
$indicators[0]['pos'] = 0;
$indicators[0]['class'] = 'length-indicator__indicator--bad';
$indicators[4]['width'] = $width;
$indicators[4]['pos'] = $max + 1;
$indicators[4]['class'] = 'length-indicator__indicator--bad';
$last = $width;
$width = $optimin / $total * 100;
$indicators[1]['width'] = $width - $last;
$indicators[1]['pos'] = $min;
$indicators[1]['class'] = 'length-indicator__indicator--ok';
$last = $width;
$width = $optimax / $total * 100;
$indicators[2]['width'] = $width - $last;
$indicators[2]['pos'] = $optimin;
$indicators[2]['class'] = 'length-indicator__indicator--good';
$last = $width;
$width = $max / $total * 100;
$indicators[3]['width'] = $width - $last;
$indicators[3]['pos'] = $optimax + 1;
$indicators[3]['class'] = 'length-indicator__indicator--ok';
ksort($indicators);
return $indicators;
}
}