{{-- SIBO gas curve. Rendered to a string and embedded as a data: URI , because wkhtmltopdf's WebKit ignores inline but does render SVG images. Kept to shapes Qt's SVG renderer supports: line, polyline, rect, circle, text. --}} @php $W = 700; $H = 250; $L = 58; $R = 655; $T = 34; $B = 196; $all = []; foreach ([$h2, $ch4] as $gas) { foreach (($gas['points'] ?? []) as $p) if ($p['value'] !== null) $all[] = $p['value']; } $all[] = $h2['cutoff'] ?? $h2['threshold']; $all[] = $ch4['threshold']; // Round the axis to a step that yields whole-number labels (0, 5, 10 ... ) rather // than whatever max/6 happens to be. $needed = max(30, max($all) * 1.15); $step = 5; foreach ([1, 2, 5, 10, 20, 25, 50, 100, 200] as $candidate) { $step = $candidate; if ($needed / $candidate <= 7) break; } $ticks = (int) ceil($needed / $step); $yMax = $ticks * $step; $xAt = fn ($i) => round($L + ($R - $L) * $i / 4, 1); $yAt = fn ($v) => round($B - ($B - $T) * ($v / $yMax), 1); $series = function (array $gas) use ($xAt, $yAt) { $pts = []; foreach (($gas['points'] ?? []) as $i => $p) { if ($p['value'] === null) continue; $pts[] = ['v' => $p['value'], 'x' => $xAt($i), 'y' => $yAt($p['value'])]; } return $pts; }; $h2Pts = $series($h2); $ch4Pts = $series($ch4); $poly = fn ($pts) => implode(' ', array_map(fn ($p) => $p['x'] . ',' . $p['y'], $pts)); $num = fn ($v) => $v === null ? '--' : rtrim(rtrim(number_format((float) $v, 2, '.', ''), '0'), '.'); $mins = [0, 30, 60, 75, 90]; $danger = '#E9473A'; $green = '#1FA345'; $orange = '#F5A623'; @endphp @for($g = 0; $g <= $ticks; $g++) @php $gv = $step * $g; $gy = $yAt($gv); @endphp {{ $gv }} @endfor @if($h2['cutoff'] !== null) @endif @foreach($mins as $i => $m) {{ $m }}{{ $i ? ' min' : '' }} @if($i === 0) (Baseline) @endif @endforeach Time (minutes) Gas Level (ppm) @if(count($ch4Pts) > 1) @endif @if(count($h2Pts) > 1) @endif @foreach($ch4Pts as $p) @endforeach @foreach($h2Pts as $p) {{ $num($p['v']) }} @endforeach H2 threshold ({{ $num($h2['cutoff'] ?? $h2['threshold']) }} ppm) H2 (ppm) CH4 threshold ({{ $num($ch4['threshold']) }} ppm) CH4 (ppm)