Skip to content

Commit 94e68d2

Browse files
authored
Add php docstrings
1 parent 594b29a commit 94e68d2

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A tiny PHP library for creating SVG donut (and pie) charts.",
44
"type": "library",
55
"license": "MIT",
6-
"version": "1.0.1",
6+
"version": "1.0.2",
77
"keywords": ["svg", "charts"],
88
"homepage": "https://github.com/Fundevogel",
99
"scripts": {

lib/Donut.php

+54-17
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,27 @@
1111

1212
use Fundevogel\Helpers\Butler;
1313

14-
use SVG\SVG;
15-
use SVG\Nodes\Shapes\SVGCircle;
1614

1715
/**
1816
* Class Donut
1917
*
20-
* Creates a donut chart
18+
* Creates a {donut,pie} chart
2119
*
2220
* @package tiny-phpeanuts
2321
*/
2422
class Donut
2523
{
2624
/**
27-
* Current version number of tiny-phpeanuts
25+
* Current version
2826
*/
29-
const VERSION = '1.0.1';
27+
const VERSION = '1.0.2';
3028

3129

3230
/**
3331
* Data points being visualized
34-
* Each entry consists of
35-
* - a color string
36-
* - a value representing the share (between 0 and 1)
32+
* Each entry (= array) consists of two key-value pairs
33+
* - `color` => string
34+
* - `value` => float (between 0 and 1)
3735
*
3836
* @var array
3937
*/
@@ -104,6 +102,14 @@ class Donut
104102
private $isPieChart = false;
105103

106104

105+
/**
106+
* Constructor
107+
*
108+
* @param array $entries Array with data points to be rendered
109+
* @param float $thickness Chart thickness (ignored when enabling `pieChart`)
110+
* @param float $spacing Spacing between segments (= donut elements)
111+
* @return void
112+
*/
107113
public function __construct(
108114
array $entries,
109115
float $thickness = 3,
@@ -128,7 +134,7 @@ public function setSize(int $size)
128134
$this->size = $size;
129135
}
130136

131-
public function getSize()
137+
public function getSize(): int
132138
{
133139
return $this->size;
134140
}
@@ -138,7 +144,7 @@ public function setPreferViewbox(bool $preferViewbox)
138144
$this->preferViewbox = $preferViewbox;
139145
}
140146

141-
public function getPreferViewbox()
147+
public function getPreferViewbox(): bool
142148
{
143149
return $this->preferViewbox;
144150
}
@@ -148,7 +154,7 @@ public function setBackgroundColor(string $backgroundColor)
148154
$this->backgroundColor = $backgroundColor;
149155
}
150156

151-
public function getBackgroundColor()
157+
public function getBackgroundColor(): string
152158
{
153159
return $this->backgroundColor;
154160
}
@@ -158,7 +164,7 @@ public function setClasses(string $classes)
158164
$this->classes = $classes;
159165
}
160166

161-
public function getClasses()
167+
public function getClasses(): string
162168
{
163169
return $this->classes;
164170
}
@@ -168,7 +174,7 @@ public function setRole(string $role)
168174
$this->role = $role;
169175
}
170176

171-
public function getRole()
177+
public function getRole(): string
172178
{
173179
return $this->role;
174180
}
@@ -178,19 +184,24 @@ public function setPieChart(bool $isPieChart)
178184
$this->isPieChart = $isPieChart;
179185
}
180186

181-
public function getPieChart()
187+
public function getPieChart(): bool
182188
{
183189
return $this->isPieChart;
184190
}
185191

186192

187193
/**
188-
* Functionality
194+
* Methods
189195
*/
190196

197+
/**
198+
* Renders SVG chart
199+
*
200+
* @return string SVG chart as string
201+
*/
191202
public function render(): string
192203
{
193-
$svg = new SVG($this->size, $this->size);
204+
$svg = new \SVG\SVG($this->size, $this->size);
194205
$doc = $svg->getDocument();
195206

196207
# If enabled, remove replace width & height with viewBox
@@ -227,6 +238,12 @@ public function render(): string
227238
return $svg->toXMLString(false);
228239
}
229240

241+
242+
/**
243+
* Initiates construction of segments
244+
*
245+
* @return array
246+
*/
230247
private function constructSegments(): array
231248
{
232249
$thickness = $this->isPieChart ? $this->size / 2 : $this->thickness;
@@ -251,6 +268,15 @@ private function constructSegments(): array
251268
return $segments;
252269
}
253270

271+
272+
/**
273+
* Corrects segments according to spacing
274+
*
275+
* @param array $segments Build instructions for segments
276+
* @param float $spacing Spacing between segments
277+
*
278+
* @return array Constructed segments
279+
*/
254280
private function correctSegmentsForSpacing(array $segments, float $spacing): array
255281
{
256282
$totalLengthWithoutSpacing = 1 - $spacing * count($segments);
@@ -267,6 +293,17 @@ private function correctSegmentsForSpacing(array $segments, float $spacing): arr
267293
return $results;
268294
}
269295

296+
297+
/**
298+
* Constructs single segment
299+
*
300+
* @param string $color Segment color
301+
* @param float $length Segment value
302+
* @param float $thickness Chart thickness
303+
* @param float $start Segment starting position
304+
*
305+
* @return \SVG\Nodes\Shapes\SVGCircle
306+
*/
270307
private function constructSegment(
271308
string $color,
272309
float $length,
@@ -279,7 +316,7 @@ private function constructSegment(
279316
$offset = $circumference - ($base * ($start * 100)) + ($circumference / 4);
280317
$lengthOnCircle = $base * ($length * 100);
281318

282-
$circle = (new SVGCircle(
319+
$circle = (new \SVG\Nodes\Shapes\SVGCircle(
283320
$this->size / 2,
284321
$this->size / 2,
285322
$radius

lib/Helpers/Butler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Fundevogel\Helpers;
44

5+
56
/**
67
* Class Butler
78
*
89
* This class contains useful helper functions, pretty much like a butler
910
* Powered by https://getkirby.com
1011
*
11-
* @package PHPCBIS
12+
* @package tiny-phpeanuts
1213
*/
13-
1414
class Butler
1515
{
1616
/**

0 commit comments

Comments
 (0)