Skip to content

Commit 7895161

Browse files
committed
wip
1 parent 21459e7 commit 7895161

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

.github/img/0.png

18 KB
Loading

.github/img/1.png

18 KB
Loading

.github/img/2.png

31.8 KB
Loading

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,31 @@ composer require brendt/php-sparkline
1717
## Usage
1818

1919
```php
20+
$sparkLine = SparkLine::new($days);
21+
22+
$total = $sparkLine->getTotal();
23+
$period = $sparkLine->getPeriod();
24+
$svg = $sparkLine->make();
25+
```
26+
27+
![](./.github/img/0.png)
28+
29+
```php
30+
$sparkLine = SparkLine::new($days)->withColors('#4285F4', '#31ACF2', '#2BC9F4');
2031
```
2132

33+
![](./.github/img/1.png)
34+
35+
```php
36+
$sparkLine = SparkLine::new($days)
37+
->withStrokeWidth(4)
38+
->withDimensions(500, 100)
39+
->withMaxItemAmount(100)
40+
->withMaxValue(20);
41+
```
42+
43+
![](./.github/img/2.png)
44+
2245
## Testing
2346

2447
```bash

src/SparkLine.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
final class SparkLine
1313
{
1414
private Collection $days;
15+
1516
private int $maxValue;
17+
1618
private int $maxItemAmount;
19+
1720
private int $width = 155;
21+
1822
private int $height = 30;
23+
1924
private int $strokeWidth = 2;
25+
2026
private array $colors = ['#c82161', '#fe2977', '#b848f5', '#b848f5'];
2127

2228
public static function new(Collection $days): self
@@ -39,10 +45,14 @@ public function getTotal(): int
3945
return $this->days->sum(fn (SparkLineDay $day) => $day->count) ?? 0;
4046
}
4147

42-
public function getPeriod(): Period
48+
public function getPeriod(): ?Period
4349
{
44-
$start = $this->days->first()->day;
45-
$end = $this->days->last()->day;
50+
$start = $this->days->first()?->day;
51+
$end = $this->days->last()?->day;
52+
53+
if (! $start || ! $end) {
54+
return null;
55+
}
4656

4757
return Period::make(
4858
$start,

0 commit comments

Comments
 (0)