creative-web-solution/svg-chart-bundle
Symfony bundle to generate SVG charts (pie/donut and line) using meyfa/php-svg. Create charts from JSON-configured data and styles, including legend labels, slice colors, donut thickness, line connectors, dimensions, and offsets; returns SVG responses.
Response objects, dependency injection). While Laravel shares PHP/Symfony’s core principles, direct integration requires abstraction or middleware to adapt Symfony-specific components (e.g., SVGChart service) to Laravel’s service container and routing.Response or API routes). The dependency on meyfa/php-svg introduces a low-level SVG library that could be swapped for Laravel-compatible alternatives (e.g., bobthecow/phpmunger or native DOM manipulation).createPie(), createLines(), createBars()) is straightforward but assumes Symfony’s Response and service container. Laravel’s Response class is compatible, but dependency injection (e.g., for SVGChart) would need manual binding or a facade wrapper.Response with image/svg+xml header (directly compatible).meyfa/php-svg may conflict with Laravel’s Composer constraints or other SVG libraries (e.g., spatie/svg).EventDispatcher) could require polyfills or exclusion.chartjs/chart.js (client-side, interactive).floridof/laravel-chartjs (Chart.js wrapper).spatie/svg (more flexible but lower-level).id fields)?Response class supports image/svg+xml.EventDispatcher or Twig (if used internally) may require polyfills.bind() in AppServiceProvider).| Component | Laravel Equivalent | Notes |
|---|---|---|
Symfony Response |
Illuminate\Http\Response |
Directly replaceable. |
SVGChart service |
Facade or manually instantiated class | Bind to container or use static calls. |
| JSON config | Laravel’s json_encode()/json_decode() |
No changes needed. |
| SVG rendering | meyfa/php-svg (or swap for phpmunger) |
Test for conflicts. |
Phase 1: Proof of Concept (1–2 days)
composer require creative-web-solution/svg-chart-bundle meyfa/php-svg.Route::get('/chart', function () {
$config = json_decode(file_get_contents(public_path('pie_chart_data.json')));
return response(SVGChart::createPie($config->data, $config->styles), 200, [
'Content-Type' => 'image/svg+xml',
]);
});
Phase 2: Abstraction Layer (2–3 days)
SVGChart in a Laravel service:
// app/Services/SvgChartService.php
class SvgChartService {
public static function createPie(array $data, array $styles) {
return \Cws\Bundle\SVGChartBundle\SVGChart\SVGChart::createPie($data, $styles);
}
}
// AppServiceProvider
public function register() {
$this->app->bind(SvgChartService::class, function () {
return new SvgChartService();
});
}
// resources/views/components/svg-chart.blade.php
<img src="{{ route('generate.chart', ['type' => 'pie']) }}" alt="Chart">
Phase 3: Production Readiness (3–5 days)
$cacheKey = 'chart_' . md5(json_encode($config));
return Cache::remember($cacheKey, now()->addHours(1), function () use ($config) {
return response(SvgChartService::createPie(...), 200, ['Content-Type' => 'image/svg+xml']);
});
EventDispatcher is used internally, consider forking the package or replacing with Laravel’s Events system.dom, fileinfo, and gd extensions are enabled (required by meyfa/php-svg).SVGChart methods.meyfa/php-svg and svg-chart-bundle for breaking changes. Consider forking if theHow can I help you explore Laravel packages today?