Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tag_meged_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: xdebug
tools: composer:v2

Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/test_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
tools: composer:v2

- name: Checkout code
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.1', '8.2', '8.3', '8.4']

steps:
- name: Set up PHP
Expand All @@ -65,7 +65,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '14.x'
node-version: '20.x'

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -88,10 +88,10 @@ jobs:
- name: Neon Lint
run: ./vendor/nette/neon/bin/neon-lint conf

- name: PHP MD
run: |
./vendor/bin/phpmd --version
./vendor/bin/phpmd ./src/ ./examples/ ./tests/ text phpmd.xml
#- name: PHP MD
# run: |
# ./vendor/bin/phpmd --version
# ./vendor/bin/phpmd ./src/ ./examples/ ./tests/ text phpmd.xml

- name: PHP Code Sniffer
run: |
Expand All @@ -115,7 +115,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1']
php: ['8.3']

steps:
- name: Set up PHP
Expand All @@ -128,7 +128,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '14.x'
node-version: '20.x'

- name: Checkout code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
composer.lock
.php-version
.tool-versions
/vendor
/.phpunit.cache
.phpunit.result.cache
Expand Down
1 change: 1 addition & 0 deletions PHP_VERSIONS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
8.4
8.3
8.2
8.1
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Transparent background is also supported.

- PHP 8.1 or later
- Imagick PHP Extension

Check with commands:
```bash
php -i | grep imagick
```
- Composer

## 4. Installation
Expand Down Expand Up @@ -545,6 +550,6 @@ You can set transparent background like this.

*Document created: 2023/05/28*

*Document updated: 2024/04/18*
*Document updated: 2025/01/02*

Copyright 2023 - 2024 macocci7
Copyright 2023 - 2025 macocci7
48 changes: 7 additions & 41 deletions bin/TestAndLint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/bash

# Script to Test and Lint
# - for the repository: macocci7/php-boxplot
# requirement:
# - phpenv/phpenv
# - https://github.com/jdx/mise installed
# - PHP versions defined in ../PHP_VERSIONS installed

CMD=phpenv
CMD=mise
$CMD -v &> /dev/null
if [ $? -ne 0 ]; then
echo "command [${CMD}] not found!"
Expand All @@ -20,46 +19,13 @@ if [ $? -ne 0 ]; then
exit 1
fi

test_and_lint() {
switch_version() {
echo "==========================================================="
echo "[PHP $1][phpenv local $1]"
phpenv local $1
if [ $? -ne 0 ]; then
echo "Failed to switch version to $i. skipped."
return 1
fi
echo "-----------------------------------------------------------"
echo "[PHP $1][php -v]"
php -v
echo "-----------------------------------------------------------"
echo "[PHP $1][parallel-lint]"
./vendor/bin/parallel-lint src tests examples
echo "-----------------------------------------------------------"
echo "[PHP $1][neon-lint]"
./vendor/nette/neon/bin/neon-lint conf
echo "-----------------------------------------------------------"
echo "[PHP $1][phpcs]"
./vendor/bin/phpcs --ignore=vendor \
--standard=phpcs.xml \
-p \
-s \
.
echo "-----------------------------------------------------------"
echo "[PHP $1][phpmd]"
./vendor/bin/phpmd \
./src/ ./examples/ ./tests/ text \
phpmd.xml
echo "-----------------------------------------------------------"
echo "[PHP $1][phpstan]"
./vendor/bin/phpstan analyze -c phpstan.neon
echo "-----------------------------------------------------------"
echo "[PHP $1][phpunit]"
./vendor/bin/phpunit ./tests/ \
--color=auto
echo "-----------------------------------------------------------"
echo "[PHP $1][Switching PHP version to $1]"
mise x php@$1 -- bash bin/TestAndLintSub.sh $1;
}

echo "[[TesAndLint.sh]]"
echo "[[TestAndLint.sh]]"

SUPPORTED_PHP_VERSIONS=PHP_VERSIONS
if [ ! -f $SUPPORTED_PHP_VERSIONS ]; then
Expand All @@ -74,6 +40,6 @@ if [ ! -r $SUPPORTED_PHP_VERSIONS ]; then
fi
STR_CMD=''
while read version ; do
STR_CMD="$STR_CMD test_and_lint $version;"
STR_CMD="$STR_CMD switch_version $version;"
done < $SUPPORTED_PHP_VERSIONS
eval $STR_CMD
34 changes: 34 additions & 0 deletions bin/TestAndLintSub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/bash

# Script to Test and Lint
# requirement:
# - PHP versions defined in ../PHP_VERSIONS installed

echo "-----------------------------------------------------------"
echo "[PHP $1][php -v]"
php -v
echo "-----------------------------------------------------------"
echo "[PHP $1][parallel-lint]"
./vendor/bin/parallel-lint src tests examples
echo "-----------------------------------------------------------"
echo "[PHP $1][neon-lint]"
./vendor/nette/neon/bin/neon-lint conf
echo "-----------------------------------------------------------"
echo "[PHP $1][phpcs]"
./vendor/bin/phpcs --ignore=vendor \
--standard=phpcs.xml \
-p \
-s \
.
#echo "-----------------------------------------------------------"
#echo "[PHP $1][phpmd]"
#./vendor/bin/phpmd \
# ./src/ ./examples/ ./tests/ text \
# phpmd.xml
echo "-----------------------------------------------------------"
echo "[PHP $1][phpstan]"
./vendor/bin/phpstan analyze -c phpstan.neon
echo "-----------------------------------------------------------"
echo "[PHP $1][phpunit]"
./vendor/bin/phpunit ./tests/
echo "-----------------------------------------------------------"
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"name": "macocci7/php-boxplot",
"version": "1.3.0",
"version": "1.3.1",
"description": "it's easy to use for creating boxplots.",
"type": "library",
"require": {
"php": ">=8.1",
"macocci7/php-frequency-table": "^1.4",
"fakerphp/faker": "^1.23",
"fakerphp/faker": "^1.24",
"nette/neon": "^3.4",
"macocci7/php-plotter2d": "^0.3"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.7",
"squizlabs/php_codesniffer": "^3.11",
"phpunit/phpunit": "^10.5",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan": "^2.1",
"php-parallel-lint/php-parallel-lint": "^1.4"
},
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion examples/class/CsvUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getDailyData($csvFileName)
if (!file_exists($csvFileName)) {
echo "CsvUtil::getDailyData(): '" . $csvFileName . "' does not exist.\n";
}
$csv = array_map('str_getcsv', file($csvFileName));
$csv = array_map(fn ($fn) => str_getcsv($fn, ",", "\"", "\\"), file($csvFileName));
$groupBy = $this->groupBy($csv, "game_date", "release_speed");
foreach ($groupBy as $index => $row) {
$groupBy[$index] = $this->convertString2IntegerInArray($row);
Expand Down
Binary file modified examples/img/AdjustDisplayByArray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/img/AdjustDisplayByMethods.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/img/AdjustDisplayByNeon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/img/BoxplotDetmersReid2023_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/img/BoxplotDetmersReid2023_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/img/BoxplotExampleCase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/img/MultipleDataSet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/img/TransparentBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 1 addition & 10 deletions src/Analyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Analyzer
/**
* @var array<string, mixed> $parsed
*/
public array $parsed;
public array $parsed = [];
protected int|float $limitUpper;
protected int|float $limitLower;
/**
Expand Down Expand Up @@ -150,9 +150,6 @@ public function getMean(array $data)
*/
public function getUcl()
{
if (!is_array($this->parsed)) {
return null;
}
if (!array_key_exists('ThirdQuartile', $this->parsed)) {
return null;
}
Expand All @@ -168,9 +165,6 @@ public function getUcl()
*/
public function getLcl()
{
if (!is_array($this->parsed)) {
return null;
}
if (!array_key_exists('FirstQuartile', $this->parsed)) {
return null;
}
Expand All @@ -186,9 +180,6 @@ public function getLcl()
*/
public function getOutliers()
{
if (!is_array($this->parsed)) {
return null;
}
if (!array_key_exists('data', $this->parsed)) {
return null;
}
Expand Down
1 change: 0 additions & 1 deletion src/Helpers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Config operator.
* @author macocci7 <macocci7@yahoo.co.jp>
* @license MIT
* @SuppressWarnings(PHPMD.ElseExpression)
*/
class Config
{
Expand Down
28 changes: 11 additions & 17 deletions src/Plotter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
* class for analysis
* @author macocci7 <macocci7@yahoo.co.jp>
* @license MIT
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
class Plotter extends Analyzer
{
Expand Down Expand Up @@ -192,10 +189,10 @@ private function adjustGridHeightPitch(float $gridHeightSpan): void
if (!$this->gridHeightPitch) {
$this->gridHeightPitch = 1;
if ($this->gridHeightPitch < 0.125 * $gridHeightSpan) {
$this->gridHeightPitch = ( (int) (0.125 * $gridHeightSpan * 10)) / 10;
$this->gridHeightPitch = (int) (( (int) (0.125 * $gridHeightSpan * 10)) / 10);
}
if ($this->gridHeightPitch > 0.2 * $gridHeightSpan) {
$this->gridHeightPitch = ( (int) (0.200 * $gridHeightSpan * 10)) / 10;
$this->gridHeightPitch = (int) (( (int) (0.200 * $gridHeightSpan * 10)) / 10);
}
}
}
Expand All @@ -211,12 +208,12 @@ private function createCanvas(): void
'height' => $this->canvasHeight,
],
viewport: $this->viewport,
plotarea: $this->plotarea,
plotarea: $this->plotarea, // @phpstan-ignore-line
backgroundColor: $this->canvasBackgroundColor,
);
$this->transformer = new Transformer(
viewport: $this->viewport,
plotarea: $this->plotarea,
plotarea: $this->plotarea, // @phpstan-ignore-line
);
}

Expand Down Expand Up @@ -637,7 +634,7 @@ private function plotJitter(int $index, int $legend)
*/
private function plotLabels()
{
if (!is_array($this->labels)) {
if (empty($this->labels)) {
return $this;
}
$offset = $this->plotarea['offset'];
Expand All @@ -648,8 +645,8 @@ private function plotLabels()
if (!is_string($label) && !is_numeric($label)) {
continue;
}
$x = (int) ($baseX + ($index + 0.5) * $gridSpanX);
$y = (int) ($baseY + $this->fontSize * 1.2);
$x = (int) round($baseX + ($index + 0.5) * $gridSpanX);
$y = (int) round($baseY + $this->fontSize * 1.2);
$this->canvas->drawText(
text: (string) $label,
x: $x,
Expand All @@ -673,8 +670,8 @@ private function plotLabelX()
$coord = $this->transformer->getCoord(0, 0);
$offset = $this->plotarea['offset'];
$baseY = $coord['y'] + $offset[1];
$x = (int) ($this->canvasWidth / 2);
$y = (int) ($baseY + (1 - $this->frameYRatio) * $this->canvasHeight / 3);
$x = (int) round($this->canvasWidth / 2);
$y = (int) round($baseY + (1 - $this->frameYRatio) * $this->canvasHeight / 3);
$this->canvas->drawText(
text: (string) $this->labelX,
x: $x,
Expand All @@ -696,8 +693,8 @@ private function plotLabelY()
{
$width = $this->canvasHeight;
$height = (int) ($this->canvasWidth * (1 - $this->frameXRatio) / 3);
$x = $width / 2;
$y = ($height + $this->fontSize) / 2;
$x = (int) round($width / 2);
$y = (int) round(($height + $this->fontSize) / 2);
$this->canvas->drawText(
text: (string) $this->labelY,
x: $x,
Expand Down Expand Up @@ -822,9 +819,6 @@ public function create(string $filePath)
if (strlen($filePath) === 0) {
throw new \Exception("empty string specified for file path.");
}
if (!is_array($this->dataSet)) {
throw new \Exception('Invalid type of property: Plotter::$data array expected.');
}
if (empty($this->dataSet)) {
throw new \Exception("Empty data specified.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/AttributeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait AttributeTrait
/**
* @var string[] $labels
*/
protected array $labels;
protected array $labels = [];
protected string $labelX;
protected string $labelY;
protected string $caption;
Expand Down
Loading