diff --git a/README.md b/README.md index 439ed29..446fe42 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,12 @@ Both methods return a file object of the newly created SVG chart for further use You may want to .. - change the thickness of the chart -- the spacing between the segments +- adjust spacing between the segments - add classes to the output SVG element +- use width & height instead of `viewBox` - make it a pie chart +- add `role` +- change background color .. here's how: @@ -75,13 +78,14 @@ You may want to .. $page->doDonut($data, $thickness, $spacing, $classes, $isPieChart); ``` -| Parameter | Type | Default | Description | -| ------------- | ------ | --------- | ---------------------------- | -| `$data` | array | - | data to be visualized | -| `$thickness` | float | see below | thickness of the chart | -| `$spacing` | float | see below | spacing between the segments | -| `$classes` | string | `''` | classes applied to chart | -| `$isPieChart` | bool | `false` | make it a pie chart | +| Parameter | Type | Default | Description | +| ------------------ | ------ | --------- | ---------------------------- | +| `$data` | array | - | data to be visualized | +| `$thickness` | float | see below | thickness of the chart | +| `$spacing` | float | see below | spacing between the segments | +| `$backgroundColor` | string | `''` | classes applied to chart | +| `$classes` | string | `''` | classes applied to chart | +| `$isPieChart` | bool | `false` | make it a pie chart | Attention: The field methods omits the `$data` argument (which is gathered from the structure field). @@ -89,13 +93,15 @@ Attention: The field methods omits the `$data` argument (which is gathered from #### Configuration You may also change certain options from your `config.php` globally (`'fundevogel.donuts.optionName'`): -| Option | Type | Default | Description | -| ------------- | ------ | --------- | -------------------------- | -| `'thickness'` | float | `3` | global default thickness | -| `'spacing'` | float | `0.005` | global default spacing | -| `'size'` | int | `100` | `viewBox` width & height | -| `'inline'` | bool | `false` | output inline SVG directly | -| `'template'` | string | `'donut'` | chart file template | +| Option | Type | Default | Description | +| ------------- | ------ | --------- | --------------------------------- | +| `'thickness'` | float | `3` | global default thickness | +| `'spacing'` | float | `0.005` | global default spacing | +| `'size'` | int | `100` | width & height dimensions | +| `'viewbox'` | bool | `true` | viewBox instead of width & height | +| `'role'` | string | `'img'` | role attribute | +| `'inline'` | bool | `false` | output inline SVG directly | +| `'template'` | string | `'donut'` | chart file template | ### Example diff --git a/composer.json b/composer.json index 2ddc146..0366965 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Kirby v3 wrapper for tiny-phpeanuts", "type": "kirby-plugin", "license": "MIT", - "version": "1.0.0", + "version": "1.1.0", "keywords": ["kirby3", "svg", "charts"], "homepage": "https://github.com/Fundevogel/kirby3-donuts#readme", "authors": [ @@ -20,7 +20,7 @@ "issues": "https://github.com/Fundevogel/kirby3-donuts/issues" }, "require": { - "fundevogel/tiny-phpeanuts": "0.3.0", + "fundevogel/tiny-phpeanuts": "^1.0.0", "getkirby/composer-installer": "^1.1" }, "require-dev": { diff --git a/index.php b/index.php index f8b917d..a0befd0 100644 --- a/index.php +++ b/index.php @@ -24,15 +24,25 @@ function render(Kirby\Cms\Page $page, array $data) $donut->setSize(option('fundevogel.donuts.size')); } + $donut->setPreferViewbox(option('fundevogel.donuts.viewbox')); + + if ($data['backgroundColor'] !== 'transparent') { + $donut->setBackgroundColor($data['backgroundColor']); + } + if ($data['classes'] !== '') { $donut->setClasses($data['classes']); } + if (option('fundevogel.donuts.role') !== 'img') { + $donut->setRole(option('fundevogel.donuts.role')); + } + if ($data['isPieChart'] === true) { $donut->setPieChart(true); } - $content = $donut->getSVGElement(); + $content = $donut->render(); $file = new File([ 'parent' => $page, @@ -67,6 +77,8 @@ function render(Kirby\Cms\Page $page, array $data) 'thickness' => 3, 'spacing' => 0.005, 'size' => 100, + 'viewbox' => true, + 'role' => 'img', 'inline' => false, 'template' => 'donut', ], @@ -81,6 +93,7 @@ function render(Kirby\Cms\Page $page, array $data) * @param float $spacing * @param string classes * @param bool $isPieChart + * @param string $backgroundColor * @return Kirby\Cms\File|string */ 'toDonut' => function ( @@ -88,7 +101,8 @@ function render(Kirby\Cms\Page $page, array $data) float $thickness = null, float $spacing = null, string $classes = '', - bool $isPieChart = false + bool $isPieChart = false, + string $backgroundColor = 'transparent' ) { try { $file = render($this, [ @@ -97,6 +111,7 @@ function render(Kirby\Cms\Page $page, array $data) 'spacing' => $spacing, 'classes' => $classes, 'isPieChart' => $isPieChart, + 'backgroundColor' => $backgroundColor, ]); } catch (Exception $e) { throw $e; @@ -112,6 +127,7 @@ function render(Kirby\Cms\Page $page, array $data) * @param float $spacing * @param string classes * @param bool $isPieChart + * @param string $backgroundColor * @return Kirby\Cms\File|string */ 'toDonut' => function ( @@ -119,8 +135,9 @@ function render(Kirby\Cms\Page $page, array $data) float $thickness = null, float $spacing = null, string $classes = '', - bool $isPieChart = false - ) { + bool $isPieChart = false, + string $backgroundColor = 'transparent' + ) { $page = $field->model(); $entries = $field->toStructure()->toArray(); @@ -131,6 +148,7 @@ function render(Kirby\Cms\Page $page, array $data) 'spacing' => $spacing, 'classes' => $classes, 'isPieChart' => $isPieChart, + 'backgroundColor' => $backgroundColor, ]); } catch (Exception $e) { throw $e;