60 lines
3.5 KiB
PHP
60 lines
3.5 KiB
PHP
@props([
|
|
'chart', // ['curves'=>[['name','plot'=>[...]],...], 'xMax', 'yMax']
|
|
'q' => null, // zadane Q - pionowa linia robocza
|
|
'xLabel' => 'Q [m³/h]',
|
|
'yLabel' => 'H [m]',
|
|
])
|
|
|
|
@php
|
|
$w = 760; $h = 360; $padL = 52; $padR = 16; $padT = 16; $padB = 34;
|
|
$plotW = $w - $padL - $padR; $plotH = $h - $padT - $padB;
|
|
$xMax = max(0.0001, (float) $chart['xMax']);
|
|
$yMax = max(0.0001, (float) $chart['yMax']);
|
|
$sx = fn ($x) => $padL + ($x / $xMax) * $plotW;
|
|
$sy = fn ($y) => $padT + $plotH - ($y / $yMax) * $plotH;
|
|
$fmt = fn ($v) => $v >= 100 ? number_format($v, 0, ',', ' ')
|
|
: ($v >= 10 ? number_format($v, 1, ',', '') : number_format($v, 2, ',', ''));
|
|
@endphp
|
|
|
|
<svg viewBox="0 0 {{ $w }} {{ $h }}" class="w-full h-auto select-none" xmlns="http://www.w3.org/2000/svg">
|
|
{{-- Siatka + etykiety osi --}}
|
|
@for ($g = 0; $g <= 4; $g++)
|
|
@php $gy = $padT + $plotH * $g / 4; $vy = $yMax * (1 - $g / 4); @endphp
|
|
<line x1="{{ $padL }}" y1="{{ round($gy, 1) }}" x2="{{ $padL + $plotW }}" y2="{{ round($gy, 1) }}" stroke="var(--chart-grid)" stroke-width="1"/>
|
|
<text x="{{ $padL - 6 }}" y="{{ round($gy + 3, 1) }}" font-size="9" fill="var(--chart-tick)" text-anchor="end">{{ $fmt($vy) }}</text>
|
|
@endfor
|
|
@for ($g = 0; $g <= 5; $g++)
|
|
@php $gx = $padL + $plotW * $g / 5; $vx = $xMax * $g / 5; @endphp
|
|
<line x1="{{ round($gx, 1) }}" y1="{{ $padT }}" x2="{{ round($gx, 1) }}" y2="{{ $padT + $plotH }}" stroke="var(--chart-grid)" stroke-width="1"/>
|
|
<text x="{{ round($gx, 1) }}" y="{{ $padT + $plotH + 14 }}" font-size="9" fill="var(--chart-tick)" text-anchor="middle">{{ $fmt($vx) }}</text>
|
|
@endfor
|
|
|
|
{{-- Osie --}}
|
|
<line x1="{{ $padL }}" y1="{{ $padT }}" x2="{{ $padL }}" y2="{{ $padT + $plotH }}" stroke="var(--chart-axis)" stroke-width="1"/>
|
|
<line x1="{{ $padL }}" y1="{{ $padT + $plotH }}" x2="{{ $padL + $plotW }}" y2="{{ $padT + $plotH }}" stroke="var(--chart-axis)" stroke-width="1"/>
|
|
|
|
{{-- Linia robocza przy zadanym Q --}}
|
|
@if ($q !== null && $q > 0 && $q <= $xMax)
|
|
<line x1="{{ round($sx($q), 1) }}" y1="{{ $padT }}" x2="{{ round($sx($q), 1) }}" y2="{{ $padT + $plotH }}"
|
|
stroke="var(--color-secondary)" stroke-width="1.5" stroke-dasharray="4 3"/>
|
|
<text x="{{ round($sx($q), 1) }}" y="{{ $padT - 4 }}" font-size="9" fill="var(--color-secondary)" text-anchor="middle">Q = {{ $fmt($q) }}</text>
|
|
@endif
|
|
|
|
{{-- Nałożone krzywe H wszystkich dopasowanych pomp (kolorowe segmenty stref Q) --}}
|
|
@foreach ($chart['curves'] as $curve)
|
|
@foreach ($curve['plot']['segments'] as $seg)
|
|
@php $poly = collect($seg['points'])->map(fn ($p) => round($sx($p['x']), 1).','.round($sy($p['y']), 1))->implode(' '); @endphp
|
|
<polyline points="{{ $poly }}" fill="none" stroke="{{ $seg['color'] }}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" opacity="0.85"/>
|
|
@endforeach
|
|
{{-- Nazwa pompy przy końcu krzywej --}}
|
|
@php $last = collect($curve['plot']['raw'])->last(); @endphp
|
|
@if ($last)
|
|
<text x="{{ round($sx($last->x) + 3, 1) }}" y="{{ round($sy($last->y), 1) }}" font-size="8" fill="var(--chart-label)">{{ $curve['name'] }}</text>
|
|
@endif
|
|
@endforeach
|
|
|
|
{{-- Etykiety osi --}}
|
|
<text x="{{ $padL - 6 }}" y="{{ $padT - 5 }}" font-size="10" fill="var(--chart-label)">{{ $yLabel }}</text>
|
|
<text x="{{ $padL + $plotW }}" y="{{ $h - 4 }}" font-size="10" fill="var(--chart-label)" text-anchor="end">{{ $xLabel }}</text>
|
|
</svg>
|