Skip to content

Commit 6e29aeb

Browse files
committed
Almost completed. But needs to be checked.
1 parent de6fbea commit 6e29aeb

20 files changed

Lines changed: 2098 additions & 69 deletions

Outline.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
### Class:Scatterplot extends Plotter
66
- data
77
- layers
8-
- matrix
8+
- matrix: future version
99

1010
### Class:Plotter extends Analyzer
1111
- plot
1212
- regressionLine
1313
- regressionCurve
1414
- referenceLine
1515
- specificationLimit
16-
- create
16+
- create($path)
1717

1818
### Class:Analyzer
1919
- mean($data)

README.md

Lines changed: 294 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,294 @@
1-
# PHP-Scatterplot
1+
# PHP-Scatterplot
2+
3+
PHP-Scatterplot is a tool for creating scatter plots.
4+
5+
You can also retrieve parsed data:
6+
7+
Mean, Variance, Standard Deviation, Covariance,
8+
9+
Correlation Coefficient and Regression Line Formula.
10+
11+
<img src="example/img/ChangingProperties.png" width="400" />
12+
13+
## Contents
14+
15+
- [Installation](#installation)
16+
- [Usage](#usage)
17+
- [Basic Usage](#basic-usage)
18+
- [Using Layers](#using-layers)
19+
- [Changing Properties](#changing-properties)
20+
- [Example](#example)
21+
- [License](#license)
22+
23+
## Installation
24+
25+
```bash
26+
composer require macocci7/php-scatterplot
27+
```
28+
29+
## Usage
30+
31+
### Basic Usage
32+
33+
- PHP
34+
35+
```php
36+
<?php
37+
require('../vendor/autoload.php');
38+
39+
use Macocci7\PhpScatterplot\Scatterplot;
40+
41+
$sp = new Scatterplot();
42+
43+
$layers = [
44+
[
45+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
46+
'y' => [1,2,3,4,5,8,4,7,11,9,1],
47+
],
48+
];
49+
50+
$sp->layers($layers)
51+
->create('img/BasicUsage.png');
52+
```
53+
54+
- Result
55+
56+
<img src="example/img/BasicUsage.png" width="400" />
57+
58+
### Using Layers
59+
60+
- PHP
61+
62+
```php
63+
<?php
64+
require('../vendor/autoload.php');
65+
66+
use Macocci7\PhpScatterplot\Scatterplot;
67+
68+
$sp = new Scatterplot();
69+
70+
$layers = [
71+
'John' => [
72+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
73+
'y' => [1,2,3,4,5,8,4,7,11,9,1],
74+
],
75+
'Jake' => [
76+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
77+
'y' => [11,8,10,7,9,6,5,3,4,2,1],
78+
],
79+
'Hugo' => [
80+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
81+
'y' => [4,8,10,1,9,6,5,3,7,1,11],
82+
],
83+
'Alex' => [
84+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
85+
'y' => [3,5,11,4,8,2,9,10,1,11,7],
86+
],
87+
];
88+
89+
$legends = array_keys($layers);
90+
91+
$sp->layers($layers)
92+
->create('img/UsingLayers.png');
93+
```
94+
95+
- Result
96+
97+
<img src="example/img/UsingLayers.png" width="400" />
98+
99+
### Changing Properties
100+
101+
- PHP
102+
103+
```php
104+
<?php
105+
require('../vendor/autoload.php');
106+
107+
use Macocci7\PhpScatterplot\Scatterplot;
108+
109+
$sp = new Scatterplot();
110+
111+
$layers = [
112+
'John' => [
113+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
114+
'y' => [1,2,3,4,5,8,4,7,11,9,1],
115+
],
116+
'Jake' => [
117+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
118+
'y' => [11,8,10,7,9,6,5,3,4,2,1],
119+
],
120+
'Hugo' => [
121+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
122+
'y' => [4,8,10,1,9,6,5,3,7,1,11],
123+
],
124+
'Alex' => [
125+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
126+
'y' => [3,5,11,4,8,2,9,10,1,11,7],
127+
],
128+
];
129+
130+
$legends = array_keys($layers);
131+
132+
$sp->layers($layers)
133+
->limitX(0, 12)
134+
->limitY(0, 12)
135+
->gridXPitch(2)
136+
->gridYPitch(2)
137+
->bgcolor('#ccccff')
138+
->color('#ffffff')
139+
->plotSize(4)
140+
->fontColor('#333333')
141+
->grid(1, '#999999')
142+
->gridXOn()
143+
->gridYOn()
144+
->regressionLine(3, '#cc2222')
145+
->referenceLineX(1.5, 1, '#00ccff')
146+
->referenceLineY(1.5, 1, '#00ccff')
147+
->specificationLimitX(0.5, 11.5, 1, '#ff00ff')
148+
->specificationLimitY(0.5, 11.5, 1, '#ff00ff')
149+
->labelX('DATA X')
150+
->labelY('DATA Y')
151+
->caption('SCATTER PLOT')
152+
->legends($legends)
153+
->create('img/ChangingProperties.png');
154+
```
155+
156+
- Result
157+
158+
<img src="example/img/ChangingProperties.png" width="400" />
159+
160+
### Parsed Data
161+
162+
- PHP
163+
164+
```php
165+
<?php
166+
require('../vendor/autoload.php');
167+
168+
use Macocci7\PhpScatterplot\Scatterplot;
169+
170+
$sp = new Scatterplot();
171+
172+
$layers = [
173+
'John' => [
174+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
175+
'y' => [1,2,3,4,5,8,4,7,11,9,1],
176+
],
177+
'Jake' => [
178+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
179+
'y' => [11,8,10,7,9,6,5,3,4,2,1],
180+
],
181+
];
182+
183+
var_dump($sp->parse($layers));
184+
```
185+
186+
- Result
187+
188+
```bash
189+
array(2) {
190+
["John"]=>
191+
array(6) {
192+
["count"]=>
193+
int(11)
194+
["x"]=>
195+
array(5) {
196+
["Mean"]=>
197+
int(6)
198+
["Max"]=>
199+
int(11)
200+
["Min"]=>
201+
int(1)
202+
["Variance"]=>
203+
int(10)
204+
["StandardDeviation"]=>
205+
float(3.1622776601683795)
206+
}
207+
["y"]=>
208+
array(5) {
209+
["Mean"]=>
210+
int(5)
211+
["Max"]=>
212+
int(11)
213+
["Min"]=>
214+
int(1)
215+
["Variance"]=>
216+
float(10.181818181818182)
217+
["StandardDeviation"]=>
218+
float(3.1908961408698624)
219+
}
220+
["Covariance"]=>
221+
float(5.181818181818182)
222+
["CorrelationCoefficient"]=>
223+
float(0.5135343537364686)
224+
["RegressionLineFormula"]=>
225+
array(2) {
226+
["a"]=>
227+
float(0.5181818181818182)
228+
["b"]=>
229+
float(1.8909090909090907)
230+
}
231+
}
232+
["Jake"]=>
233+
array(6) {
234+
["count"]=>
235+
int(11)
236+
["x"]=>
237+
array(5) {
238+
["Mean"]=>
239+
int(6)
240+
["Max"]=>
241+
int(11)
242+
["Min"]=>
243+
int(1)
244+
["Variance"]=>
245+
int(10)
246+
["StandardDeviation"]=>
247+
float(3.1622776601683795)
248+
}
249+
["y"]=>
250+
array(5) {
251+
["Mean"]=>
252+
int(6)
253+
["Max"]=>
254+
int(11)
255+
["Min"]=>
256+
int(1)
257+
["Variance"]=>
258+
int(10)
259+
["StandardDeviation"]=>
260+
float(3.1622776601683795)
261+
}
262+
["Covariance"]=>
263+
float(-9.454545454545455)
264+
["CorrelationCoefficient"]=>
265+
float(-0.9454545454545453)
266+
["RegressionLineFormula"]=>
267+
array(2) {
268+
["a"]=>
269+
float(-0.9454545454545455)
270+
["b"]=>
271+
float(11.672727272727274)
272+
}
273+
}
274+
}
275+
```
276+
277+
## Example
278+
279+
- [BasicUsage.php](example/BasicUsage.php) >> results in [BasicUsage.md](example/BasicUsage.md)
280+
- [UsingLayers.php](example/UsingLayers.php) >> results in [UsingLayers.md](example/UsingLayers.md)
281+
- [ChangingProperties.php](example/ChangingProperties.php) >> results in [ChangingProperties.md](example/ChangingProperties.md)
282+
- [ParsedData.php](example/ParsedData.php) >> results in [ParsedData.txt](example/ParsedData.txt)
283+
284+
## License
285+
286+
[MIT](LICENSE)
287+
288+
***
289+
290+
*Document written: 2023/06/06*
291+
292+
*Document updated: 2023/06/06*
293+
294+
Copyright 2023 macocci7.

example/BasicUsage.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# PHP-Scatterplot : Basic Usage
2+
3+
<details><summary>Layer</summary>
4+
5+
|#|x|y|
6+
|:---:|:---:|:---:|
7+
|0|1|1|
8+
|1|2|2|
9+
|2|3|3|
10+
|3|4|4|
11+
|4|5|5|
12+
|5|6|8|
13+
|6|7|4|
14+
|7|8|7|
15+
|8|9|11|
16+
|9|10|9|
17+
|10|11|1|
18+
19+
</details>
20+
21+
<details><summary>Regression Line Formula</summary>
22+
23+
- y = 0.51818181818182 x + 1.8909090909091
24+
</details>
25+
26+
![BasicUsage.png](img/BasicUsage.png)

example/BasicUsage.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
require('../vendor/autoload.php');
3+
4+
use Macocci7\PhpScatterplot\Scatterplot;
5+
6+
$sp = new Scatterplot();
7+
8+
$layers = [
9+
[
10+
'x' => [1,2,3,4,5,6,7,8,9,10,11],
11+
'y' => [1,2,3,4,5,8,4,7,11,9,1],
12+
],
13+
];
14+
15+
$sp->layers($layers)
16+
->create('img/BasicUsage.png');
17+
18+
// Markdown -------------------------------------
19+
20+
// Headline
21+
echo "# PHP-Scatterplot : Basic Usage\n\n";
22+
23+
// Layers
24+
echo "<details><summary>Layer</summary>\n\n";
25+
$dataCount = count($layers[0]['x']);
26+
echo "|#|x|y|\n";
27+
echo "|:---:|:---:|:---:|\n";
28+
$xs = $layers[0]['x'];
29+
$ys = $layers[0]['y'];
30+
for ($i = 0; $i < $dataCount; $i++) {
31+
echo "|" . $i . "|" . $xs[$i] . "|" . $ys[$i] . "|\n";
32+
}
33+
echo "\n</details>\n\n";
34+
35+
// Regression Line Formula
36+
echo "<details><summary>Regression Line Formula</summary>\n\n";
37+
$formula = $sp->regressionLineFormula($xs, $ys);
38+
echo "- y = " . $formula['a'] . " x + " . $formula['b'] . "\n";
39+
echo "</details>\n\n";
40+
41+
// Scatter plot
42+
echo "![BasicUsage.png](img/BasicUsage.png)\n";

0 commit comments

Comments
 (0)