From b9d22117ad12ab892b2edb94e3ca1cee92fcc394 Mon Sep 17 00:00:00 2001 From: Anatoliy Babushka Date: Tue, 12 Mar 2019 22:36:50 +0100 Subject: [PATCH] Minor improvements and PHP7.3 support --- .editorconfig | 12 ++++ .github/ISSUE_TEMPLATE.md | 8 +++ .gitignore | 7 ++- .travis.yml | 8 ++- LICENSE | 2 +- README.md | 121 -------------------------------------- composer.json | 6 +- docs/examples.md | 85 ++++++++++++++++++++++++++ docs/extend.md | 7 +++ docs/readme.md | 57 ++++++++++++++++++ docs/usage.md | 66 +++++++++++++++++++++ 11 files changed, 250 insertions(+), 129 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 README.md create mode 100644 docs/examples.md create mode 100644 docs/extend.md create mode 100644 docs/readme.md create mode 100644 docs/usage.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2e7acaf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..54fab55 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,8 @@ +* PHP: v7.0.0 +* Laravel: v5.5.0 + + +### Description: + + +### Steps To Reproduce: diff --git a/.gitignore b/.gitignore index 0dca145..2ded77b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -/vendor/ -.idea +/vendor +/.idea +composer.phar +.DS_Store +Thumbs.db diff --git a/.travis.yml b/.travis.yml index adbf2a0..4574d35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ -install: composer install language: php + php: - '7.1' - '7.2' - - nightly \ No newline at end of file + - '7.3' + +install: travis_retry composer install --no-interaction --prefer-dist --no-suggest + +script: vendor/bin/phpunit --verbose diff --git a/LICENSE b/LICENSE index faebcd6..c7b6b31 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Anatoliy Babushka +Copyright (c) 2019 Anatoliy Babushka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md deleted file mode 100644 index 0feb5e3..0000000 --- a/README.md +++ /dev/null @@ -1,121 +0,0 @@ -# ChartJS-PHP - -

-Total Downloads -Latest Stable Version -License -License -

- -The package helps you to generate [ChartJS](http://www.chartjs.org/ "ChartJS") -element directly in PHP and translate it to JSON. - -## Install -`composer require bbsnly/chartjs-php` - -## Test -`composer test` - -## Requirements -* `php >= 7.0` -* `ChartJS >= 2.0` - -## Charts -* [Line](http://www.chartjs.org/docs/latest/charts/line.html) -* [Bar](http://www.chartjs.org/docs/latest/charts/bar.html) -* [Radar](http://www.chartjs.org/docs/latest/charts/radar.html) -* [Doughnut](http://www.chartjs.org/docs/latest/charts/doughnut.html) -* [Pie](http://www.chartjs.org/docs/latest/charts/doughnut.html) -* [Polar Area](http://www.chartjs.org/docs/latest/charts/polar.html) -* [Bubble](http://www.chartjs.org/docs/latest/charts/bubble.html) -* [Scatter](http://www.chartjs.org/docs/latest/charts/scatter.html) -* [Mixed](http://www.chartjs.org/docs/latest/charts/mixed.html) - -Also it is possible to use the package with [New Charts](http://www.chartjs.org/docs/latest/developers/charts.html) -using the `Chart` class - -## How To -### Create -``` -$chart = new Chart; -$chart->type = 'line'; -$chart->toJson(); -``` -and -``` -$chart = new LineChart; -$chart->toJson(); -``` -provides the same result. - -### Usage -To personalize your chart you have three options: -* Using arrays -* Using attributes -* Using methods - -#### Examples -Using arrays -``` -$chart->data([ - 'labels' => ['Red', 'Green', 'Blue'], - 'datasets' => [{ - 'data' => [5, 10, 20] - }] -]); - -$chart->options([ - 'responsive' => true -]); -``` -Using attributes -``` -$data = new Data(); - -$data->labels = ['Red', 'Green', 'Blue']; - -$dataset = new Dataset(); -$dataset->data = [5, 10, 20]; -$data->datasets[] = $dataset->data; - -$chart->data($data); - -$options = new Options(); -$options->responsive = true; -$chart->options($options); -``` -Using methods -``` -$data = new Data; - -$data->datasets([ - (new Dataset)->data([5, 10, 20]) -])->labels(['Red', 'Green', 'Blue']); - -$chart->data($data); - -$options = new Options(); -$options->responsive(true); -$chart->options($options); -``` -### Config class -To configure your chart you can use the `Config` class directly or helpers -like `Dataset` or `Options`. - -You can extend it and add a helper for wherever you need (ex. `Scales`). - -If you decide to override the `Config` class you should implement -the `ConfigInterface` to be sure about the compatibility. - -## Code Examples -You can find some examples -[here](https://github.com/bbsnly/chartjs-php/tree/master/tests/examples "ChartJS PHP Examples") - -## Contributing - -Thank you for considering contributing to the ChartJS PHP! - -## License - -The ChartJS PHP is open-sourced software licensed under the -[MIT license](http://opensource.org/licenses/MIT). \ No newline at end of file diff --git a/composer.json b/composer.json index 3b59276..c9f24e5 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "homepage": "https://github.com/bbsnly/chartjs-php", "type": "package", - "version": "1.2.1", + "version": "1.2.2", "license": "MIT", "authors": [ { @@ -19,7 +19,7 @@ "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^6.2" + "phpunit/phpunit": "^7.5" }, "autoload": { "psr-4": { @@ -39,4 +39,4 @@ "config": { "sort-packages": true } -} \ No newline at end of file +} diff --git a/docs/examples.md b/docs/examples.md new file mode 100644 index 0000000..82a0746 --- /dev/null +++ b/docs/examples.md @@ -0,0 +1,85 @@ +# Examples + +## Table of Contents +- [Std Chart](#std-chart) +- [Helper class](#helper-class) +- [Begin At Zero](#begin-at-zero) +- [Mixed Chart Type](#mixed-chart-type) + + +#### Std Chart +```php +$chart = app(Bbsnly\ChartJs\Chart::class); + +$chart->type = 'bar'; + +$data = new Data; + +$datasets = [ + (new Dataset)->data([10, 20, 30, 40])->label('Bar Dataset'), + (new Dataset)->data([50, 50, 50, 50])->label('Line Dataset'), +]; + +$data->datasets($datasets)->labels(['January', 'February', 'March', 'April']); + +$chart->data($data); +``` + + +#### Helper class +```php +$chart = new Bbsnly\ChartJs\BarChart; + +$data = new Data; + +$datasets = [ + (new Dataset)->data([10, 20, 30, 40])->label('Bar Dataset'), + (new Dataset)->data([50, 50, 50, 50])->label('Line Dataset'), +]; + +$data->datasets($datasets)->labels(['January', 'February', 'March', 'April']); + +$chart->data($data); +``` + + +#### Begin At Zero +```php +$chart = app(Bbsnly\ChartJs\Chart::class); + +$chart->type = 'bar'; + +$data = new Data; + +$datasets = [ + (new Dataset)->data([10, 20, 30, 40])->label('Bar Dataset'), + (new Dataset)->data([50, 50, 50, 50])->label('Line Dataset'), +]; + +$data->datasets($datasets)->labels(['January', 'February', 'March', 'April']); + +$chart->data($data); + +$chart->beginAtZero(); +``` + + +#### Mixed Chart Type +```php +$chart = new app(Bbsnly\ChartJs\Chart::class); + +$chart->type = 'bar'; + +$data = new Data; + +$datasets = [ + (new Dataset)->data([10, 20, 30, 40])->label('Bar Dataset'), + (new Dataset)->data([50, 50, 50, 50])->label('Line Dataset')->type('line'), +]; + +$data->datasets($datasets)->labels(['January', 'February', 'March', 'April']); + +$chart->data($data); + +$chart->get(); +``` diff --git a/docs/extend.md b/docs/extend.md new file mode 100644 index 0000000..e4e5556 --- /dev/null +++ b/docs/extend.md @@ -0,0 +1,7 @@ +# Extend +To configure your chart you can use the `Config` class directly or helpers +like `Dataset` or `Options`. + +You can extend it and add a helper you need (ex. `Scales`). + +You should implement the `ConfigInterface` when creating a new config helper. diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..1b7b177 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,57 @@ +# ChartJS-PHP + +

+Total Downloads +Latest Stable Version +License +License +

+ +This package helps you to generate [ChartJS](http://www.chartjs.org/ "ChartJS") element directly in PHP. + + +## Table of Contents +- [Install](#install) +- [Requirements](#requirements) +- [Charts](#charts) +- [Usage](usage.md) +- [Examples](examples.md) +- [Extend](extend.md) +- [Contributing](#contributing) +- [License](#license) + + +## Install +Require this package with composer. +```shell +composer require bbsnly/chartjs-php +``` + + +## Requirements +* `php >= 7.1` +* `ChartJS >= 2.0` + + +## Charts +* [Line](http://www.chartjs.org/docs/latest/charts/line.html) +* [Bar](http://www.chartjs.org/docs/latest/charts/bar.html) +* [Radar](http://www.chartjs.org/docs/latest/charts/radar.html) +* [Doughnut](http://www.chartjs.org/docs/latest/charts/doughnut.html) +* [Pie](http://www.chartjs.org/docs/latest/charts/doughnut.html) +* [Polar Area](http://www.chartjs.org/docs/latest/charts/polar.html) +* [Bubble](http://www.chartjs.org/docs/latest/charts/bubble.html) +* [Scatter](http://www.chartjs.org/docs/latest/charts/scatter.html) +* [Mixed](http://www.chartjs.org/docs/latest/charts/mixed.html) + +Also it is possible to use the package with [New Charts](http://www.chartjs.org/docs/latest/developers/charts.html) +using the `Chart` class + + +## Contributing +Thank you for considering contributing to the ChartJS PHP! + + +## License +The ChartJS PHP is open-sourced software licensed under the +[MIT license](http://opensource.org/licenses/MIT). diff --git a/docs/usage.md b/docs/usage.md new file mode 100644 index 0000000..45afff8 --- /dev/null +++ b/docs/usage.md @@ -0,0 +1,66 @@ +# Usage + +## Table of Contents +- [Using arrays](#using-arrays) +- [Using attributes](#using-attributes) +- [Using methods](#using-methods) + +All data and options element are dynamic so you can create tthe exact configuration you need. + + +#### Using arrays +```php +$chart = app(Bbsnly\ChartJs\Chart::class); + +$chart->type = 'bar'; + +$chart->data([ + 'labels' => ['Red', 'Green', 'Blue'], + 'datasets' => [ + [ + 'data' => [5, 10, 20] + ] + ] +]); + +$chart->options([ + 'responsive' => true +]); +``` +#### Using attributes +```php +$chart = app(Bbsnly\ChartJs\Chart::class); + +$chart->type = 'line'; + +$data = new Data(); +$data->labels = ['Red', 'Green', 'Blue']; + +$dataset = new Dataset(); +$dataset->data = [5, 10, 20]; +$data->datasets[] = $dataset->data; + +$chart->data($data); + +$options = new Options(); +$options->responsive = true; +$chart->options($options); +``` +#### Using methods +```php +$chart = app(Bbsnly\ChartJs\Chart::class); + +$chart->type = 'bar'; + +$data = new Data; + +$data->datasets([ + (new Dataset)->data([5, 10, 20]) +])->labels(['Red', 'Green', 'Blue']); + +$chart->data($data); + +$options = new Options(); +$options->responsive(true); +$chart->options($options); +```