Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Flattening structure
Browse files Browse the repository at this point in the history
  • Loading branch information
S1SYPHOS committed Aug 9, 2020
1 parent e36aa42 commit 4483840
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 101 deletions.
5 changes: 0 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
"friendsofphp/php-cs-fixer": "^2.14",
"phpunit/phpunit": "^8.1"
},
"autoload": {
"psr-4": {
"Fundevogel\\": "lib/"
}
},
"autoload-dev": {
"psr-4": {
"Fundevogel\\Tests\\": "tests/"
Expand Down
51 changes: 46 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,48 @@

@include_once __DIR__ . '/vendor/autoload.php';

use Fundevogel\Chart;
use Fundevogel\Donut;

function saveSVG(Kirby\Cms\Page $page, array $data)
{
$thickness = $thickness ?? option('fundevogel.donuts.thickness');
$spacing = $spacing ?? option('fundevogel.donuts.spacing');

$donut = new Donut(
$data['entries'],
$data['thickness'],
$data['spacing']
);

$content = $donut->getSVGElement();

$file = new File([
'parent' => $page,
'filename' => 'chart-' . hash('md5', $content),
]);

$file->update([
'template' => option('fundevogel.donuts.template'),
]);

if (file_exists($file->root())) {
if (option('fundevogel.donuts.inline') === true) {
return svg($file);
}

return $file;
}

if (F::write($file->root(), $content)) {
if (option('fundevogel.donuts.inline') === true) {
return svg($file);
}

return $file;
}

throw new Exception('Couldn\'t create chart!');
}

Kirby::plugin('fundevogel/donuts', [
'options' => [
Expand All @@ -29,11 +70,11 @@
float $spacing = null
) {
try {
$file = (new Chart($this, [
$file = saveSVG($this, [
'entries' => $entries,
'thickness' => $thickness,
'spacing' => $spacing,
]))->render();
]);
} catch (Exception $e) {
throw $e;
}
Expand All @@ -57,11 +98,11 @@
$entries = $field->toStructure()->toArray();

try {
$file = (new Chart($page, [
$file = saveSVG($page, [
'entries' => $entries,
'thickness' => $thickness,
'spacing' => $spacing,
]))->render();
]);
} catch (Exception $e) {
throw $e;
}
Expand Down
91 changes: 0 additions & 91 deletions lib/Chart.php

This file was deleted.

0 comments on commit 4483840

Please sign in to comment.