├── .php_cs.dist.php ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── assets └── banner.png ├── codecov.yml ├── composer.json ├── phpstan-baseline.neon ├── phpstan.neon.dist ├── resources └── views │ └── components │ ├── chart.blade.php │ ├── colorscheme.blade.php │ ├── entry.blade.php │ ├── label.blade.php │ ├── legend.blade.php │ ├── stylesheet.blade.php │ └── table.blade.php ├── src ├── Appearance │ ├── Colorscheme │ │ ├── Color.php │ │ ├── ColorContract.php │ │ ├── Colorscheme.php │ │ ├── ColorschemeContract.php │ │ └── RowColor.php │ ├── CustomModification.php │ ├── DataSpacing.php │ ├── DatasetsSpacing.php │ ├── Exceptions │ │ └── OutOfRangeException.php │ ├── HideData.php │ ├── HideLabel.php │ ├── LabelsAlignCenter.php │ ├── LabelsAlignEnd.php │ ├── LabelsAlignStart.php │ ├── Modification.php │ ├── Modifications.php │ ├── Multiple.php │ ├── RangeModification.php │ ├── ReverseData.php │ ├── ReverseDatasets.php │ ├── ReverseOrientation.php │ ├── ShowDataAxes.php │ ├── ShowDataOnHover.php │ ├── ShowHeading.php │ ├── ShowLabels.php │ ├── ShowPrimaryAxis.php │ ├── ShowSecondaryAxes.php │ └── Stacked.php ├── AreaChart.php ├── BarChart.php ├── Chart.php ├── ChartscssServiceProvider.php ├── Commands │ └── MakeChartCommand.php ├── Components │ ├── Colorscheme.php │ ├── Entry.php │ ├── Heading.php │ ├── Label.php │ ├── Legend.php │ ├── Stylesheet.php │ └── Table.php ├── Configuration │ ├── Configuration.php │ ├── ConfigurationContract.php │ ├── SmartConfiguration.php │ └── Specifications │ │ ├── Directives.php │ │ ├── HasColorscheme.php │ │ ├── HasHeading.php │ │ ├── HasLabels.php │ │ └── NeedsStartingPoint.php ├── Data │ ├── Axes │ │ ├── Axes.php │ │ ├── AxesContract.php │ │ └── NullAxes.php │ ├── Dataset │ │ └── Statistics │ │ │ ├── HighestEntryStatistic.php │ │ │ └── SumStatistic.php │ ├── Datasets │ │ ├── CalculatedDataset.php │ │ ├── CalculatedDatasets.php │ │ ├── Dataset.php │ │ ├── DatasetContract.php │ │ ├── Datasets.php │ │ ├── DatasetsContract.php │ │ ├── InvertedDatasets.php │ │ ├── PercentageStackedDatasets.php │ │ ├── SimpleStackedDatasets.php │ │ ├── StartingPointDataset.php │ │ ├── StartingPointDatasets.php │ │ └── Statistics │ │ │ ├── HighestDatasetSumStatistic.php │ │ │ └── HighestEntryStatistic.php │ ├── Entries │ │ ├── CalculatedEntry.php │ │ ├── Entry.php │ │ ├── EntryContract.php │ │ ├── NullEntry.php │ │ ├── StartingPointEntry.php │ │ ├── Tooltip │ │ │ ├── NullTooltip.php │ │ │ ├── Tooltip.php │ │ │ └── TooltipContract.php │ │ └── Value │ │ │ ├── ColorfulValue.php │ │ │ ├── NullValue.php │ │ │ ├── SizedValue.php │ │ │ ├── StartValue.php │ │ │ ├── Value.php │ │ │ └── ValueContract.php │ ├── Label │ │ ├── AlignedLabel.php │ │ ├── HiddenLabel.php │ │ ├── Label.php │ │ ├── LabelContract.php │ │ └── NullLabel.php │ └── Specifications │ │ ├── HasDatasetLabels.php │ │ ├── HasEntryLabels.php │ │ ├── HasMultiple.php │ │ └── IsStacked.php ├── Declarations │ ├── ColorDeclaration.php │ ├── DeclarationContract.php │ ├── Declarations.php │ ├── LabelAlignmentDeclaration.php │ ├── RowColorDeclaration.php │ ├── SizeDeclaration.php │ └── StartDeclaration.php ├── Examples │ ├── Area │ │ ├── AreaExample1.php │ │ ├── AreaExample10.php │ │ ├── AreaExample11.php │ │ ├── AreaExample12.php │ │ ├── AreaExample13.php │ │ ├── AreaExample14.php │ │ ├── AreaExample15.php │ │ ├── AreaExample16.php │ │ ├── AreaExample17.php │ │ ├── AreaExample3.php │ │ ├── AreaExample4.php │ │ ├── AreaExample5.php │ │ ├── AreaExample6.php │ │ └── AreaExample7.php │ ├── Axes │ │ ├── AxesExample1.php │ │ ├── AxesExample10.php │ │ ├── AxesExample11.php │ │ ├── AxesExample12.php │ │ ├── AxesExample2.php │ │ ├── AxesExample3.php │ │ ├── AxesExample4.php │ │ ├── AxesExample5.php │ │ ├── AxesExample6.php │ │ ├── AxesExample7.php │ │ ├── AxesExample8.php │ │ └── AxesExample9.php │ ├── Bar │ │ ├── BarExample1.php │ │ ├── BarExample10.php │ │ ├── BarExample11.php │ │ ├── BarExample12.php │ │ ├── BarExample13.php │ │ ├── BarExample14.php │ │ ├── BarExample15.php │ │ ├── BarExample16.php │ │ ├── BarExample17.php │ │ ├── BarExample18.php │ │ ├── BarExample19.php │ │ ├── BarExample2.php │ │ ├── BarExample20.php │ │ ├── BarExample21.php │ │ ├── BarExample22.php │ │ ├── BarExample23.php │ │ ├── BarExample24.php │ │ ├── BarExample25.php │ │ ├── BarExample3.php │ │ ├── BarExample4.php │ │ ├── BarExample5.php │ │ ├── BarExample6.php │ │ └── BarExample7.php │ ├── Colors │ │ ├── ColorsExample1.php │ │ ├── ColorsExample10.php │ │ ├── ColorsExample2.php │ │ ├── ColorsExample3.php │ │ ├── ColorsExample4.php │ │ ├── ColorsExample5.php │ │ ├── ColorsExample6.php │ │ ├── ColorsExample7.php │ │ ├── ColorsExample8.php │ │ └── ColorsExample9.php │ ├── Column │ │ ├── ColumnExample1.php │ │ ├── ColumnExample10.php │ │ ├── ColumnExample11.php │ │ ├── ColumnExample12.php │ │ ├── ColumnExample13.php │ │ ├── ColumnExample14.php │ │ ├── ColumnExample15.php │ │ ├── ColumnExample16.php │ │ ├── ColumnExample17.php │ │ ├── ColumnExample18.php │ │ ├── ColumnExample19.php │ │ ├── ColumnExample2.php │ │ ├── ColumnExample20.php │ │ ├── ColumnExample21.php │ │ ├── ColumnExample22.php │ │ ├── ColumnExample23.php │ │ ├── ColumnExample24.php │ │ ├── ColumnExample25.php │ │ ├── ColumnExample3.php │ │ ├── ColumnExample4.php │ │ ├── ColumnExample5.php │ │ ├── ColumnExample6.php │ │ └── ColumnExample7.php │ ├── Data │ │ ├── DataExample2.php │ │ ├── DataExample3.php │ │ ├── DataExample4.php │ │ ├── DataExample5.php │ │ └── DataExample6.php │ ├── Datasets │ │ ├── DatasetsExample1.php │ │ ├── DatasetsExample2.php │ │ ├── DatasetsExample3.php │ │ └── DatasetsExample4.php │ ├── Heading │ │ ├── HeadingExample1.php │ │ └── HeadingExample2.php │ ├── Labels │ │ ├── LabelsExample1.php │ │ ├── LabelsExample2.php │ │ ├── LabelsExample3.php │ │ ├── LabelsExample5.php │ │ └── LabelsExample6.php │ ├── Legend │ │ ├── LegendExample1.php │ │ ├── LegendExample2.php │ │ ├── LegendExample3.php │ │ ├── LegendExample4.php │ │ ├── LegendExample5.php │ │ ├── LegendExample6.php │ │ ├── LegendExample7.php │ │ └── LegendExample8.php │ ├── Line │ │ ├── LineExample1.php │ │ ├── LineExample10.php │ │ ├── LineExample11.php │ │ ├── LineExample12.php │ │ ├── LineExample13.php │ │ ├── LineExample14.php │ │ ├── LineExample15.php │ │ ├── LineExample16.php │ │ ├── LineExample17.php │ │ ├── LineExample3.php │ │ ├── LineExample4.php │ │ ├── LineExample5.php │ │ ├── LineExample6.php │ │ └── LineExample7.php │ ├── Orientation │ │ ├── OrientationExample1.php │ │ ├── OrientationExample2.php │ │ ├── OrientationExample3.php │ │ ├── OrientationExample4.php │ │ ├── OrientationExample5.php │ │ └── OrientationExample6.php │ ├── ReverseOrder │ │ ├── ReverseOrderExample1.php │ │ ├── ReverseOrderExample2.php │ │ ├── ReverseOrderExample3.php │ │ ├── ReverseOrderExample4.php │ │ ├── ReverseOrderExample5.php │ │ └── ReverseOrderExample6.php │ ├── Spacing │ │ ├── SpacingExample1.php │ │ └── SpacingExample2.php │ ├── Stacked │ │ ├── StackedExample1.php │ │ ├── StackedExample2.php │ │ ├── StackedExample3.php │ │ └── StackedExample4.php │ └── Tooltips │ │ └── TooltipsExample1.php ├── Identity │ └── Identity.php ├── Legend │ ├── Appearance │ │ ├── Circle.php │ │ ├── Ellipse.php │ │ ├── Inline.php │ │ ├── Line.php │ │ ├── Rectangle.php │ │ ├── Rhombus.php │ │ └── Square.php │ └── Legend.php ├── LineChart.php ├── Statistics │ ├── CustomStatistic.php │ └── StatisticContract.php ├── Stylesheets │ ├── JSDelivrStylesheet.php │ ├── NullStylesheet.php │ ├── StylesheetContract.php │ ├── StylesheetFactory.php │ └── UnpkgStylesheet.php └── Types │ ├── Area.php │ ├── Bar.php │ ├── ChartType.php │ ├── ChartTypeModificationAdapter.php │ ├── Column.php │ └── Line.php └── stubs └── chart.stub /.php_cs.dist.php: -------------------------------------------------------------------------------- 1 | in([ 5 | __DIR__ . '/src', 6 | __DIR__ . '/tests', 7 | ]) 8 | ->name('*.php') 9 | ->notName('*.blade.php') 10 | ->ignoreDotFiles(true) 11 | ->ignoreVCS(true); 12 | 13 | return (new PhpCsFixer\Config()) 14 | ->setRules([ 15 | '@PSR12' => true, 16 | 'array_syntax' => ['syntax' => 'short'], 17 | 'ordered_imports' => ['sort_algorithm' => 'alpha'], 18 | 'no_unused_imports' => true, 19 | 'not_operator_with_successor_space' => true, 20 | 'trailing_comma_in_multiline' => true, 21 | 'phpdoc_scalar' => true, 22 | 'unary_operator_spaces' => true, 23 | 'binary_operator_spaces' => true, 24 | 'blank_line_before_statement' => [ 25 | 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], 26 | ], 27 | 'phpdoc_single_line_var_spacing' => true, 28 | 'phpdoc_var_without_name' => true, 29 | 'class_attributes_separation' => [ 30 | 'elements' => [ 31 | 'method' => 'one', 32 | ], 33 | ], 34 | 'method_argument_space' => [ 35 | 'on_multiline' => 'ensure_fully_multiline', 36 | 'keep_multiple_spaces_after_comma' => true, 37 | ], 38 | 'single_trait_insert_per_statement' => true, 39 | ]) 40 | ->setFinder($finder); 41 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-charts-css` will be documented in this file. 4 | 5 | ## Unreleased 6 | 7 | ## 2.0.0 - 2022-04-05 8 | 9 | ### Added 10 | 11 | - Support for Laravel 9. 12 | 13 | ### Changed 14 | 15 | - Make use of `maartenpaauw/laravel-specification-pattern` package. 16 | 17 | ### Removed 18 | 19 | - Support for PHP `7.4`. 20 | 21 | ## 1.2.3 - 2021-08-13 22 | 23 | ### Fixed 24 | 25 | - Bugfix for area and line charts. 26 | 27 | ## 1.2.2 - 2021-07-31 28 | 29 | ### Fixed 30 | 31 | - Area charts, with multiple datasets given, will be displayed correctly. 32 | 33 | ## 1.2.1 - 2021-07-31 34 | 35 | ### Fixed 36 | 37 | - `HighestEntryStatistic` will return zero when passing datasets without entries. 38 | 39 | ## 1.2.0 - 2021-07-17 40 | 41 | ### Added 42 | 43 | - Added support for simple stacked and percentage stacked datasets. 44 | 45 | ## 1.1.0 - 2021-07-08 46 | 47 | ### Added 48 | 49 | - Added abstract `AreaChart`, `BarChart` and `LineChart` classes. 50 | 51 | ## 1.0.0 - 2021-07-05 52 | 53 | - initial release 54 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) maartenpaauw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /assets/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maartenpaauw/laravel-charts-css/1df3a1c10c0b9c6d9743e692f7d591a111b66fb9/assets/banner.png -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 1 3 | 4 | status: 5 | project: 6 | default: 7 | threshold: 1% 8 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "maartenpaauw/laravel-charts-css", 3 | "description": "Laravel components to create beautifully Charts.css charts.", 4 | "keywords": [ 5 | "maartenpaauw", 6 | "laravel", 7 | "laravel-charts-css" 8 | ], 9 | "homepage": "https://github.com/maartenpaauw/laravel-charts-css", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Maarten Paauw", 14 | "email": "maartenpaauw@gmail.com", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8.0", 20 | "illuminate/contracts": "^8.37|^9.6", 21 | "maartenpaauw/laravel-specification-pattern": "^1.1", 22 | "spatie/laravel-package-tools": "^1.11" 23 | }, 24 | "require-dev": { 25 | "ext-tidy": "*", 26 | "brianium/paratest": "^6.2", 27 | "nunomaduro/collision": "^5.3|^6.1", 28 | "nunomaduro/larastan": "^1.0", 29 | "orchestra/testbench": "^6.15", 30 | "phpstan/extension-installer": "^1.1", 31 | "phpstan/phpstan-deprecation-rules": "^1.0", 32 | "phpstan/phpstan-phpunit": "^1.0", 33 | "phpunit/phpunit": "^9.3", 34 | "spatie/phpunit-snapshot-assertions": "^4.2" 35 | }, 36 | "autoload": { 37 | "psr-4": { 38 | "Maartenpaauw\\Chartscss\\": "src" 39 | } 40 | }, 41 | "autoload-dev": { 42 | "psr-4": { 43 | "Maartenpaauw\\Chartscss\\Tests\\": "tests" 44 | } 45 | }, 46 | "scripts": { 47 | "phpstan": "vendor/bin/phpstan analyse", 48 | "test": "./vendor/bin/testbench package:test --parallel --no-coverage", 49 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 50 | }, 51 | "config": { 52 | "sort-packages": true, 53 | "allow-plugins": { 54 | "phpstan/extension-installer": true 55 | } 56 | }, 57 | "extra": { 58 | "laravel": { 59 | "providers": [ 60 | "Maartenpaauw\\Chartscss\\ChartscssServiceProvider" 61 | ] 62 | } 63 | }, 64 | "minimum-stability": "dev", 65 | "prefer-stable": true 66 | } 67 | -------------------------------------------------------------------------------- /phpstan-baseline.neon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maartenpaauw/laravel-charts-css/1df3a1c10c0b9c6d9743e692f7d591a111b66fb9/phpstan-baseline.neon -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - phpstan-baseline.neon 3 | 4 | parameters: 5 | level: 9 6 | paths: 7 | - resources 8 | - src 9 | - tests 10 | tmpDir: build/phpstan 11 | checkOctaneCompatibility: true 12 | checkModelProperties: true 13 | -------------------------------------------------------------------------------- /resources/views/components/chart.blade.php: -------------------------------------------------------------------------------- 1 | @hasColorscheme($configuration) 2 | 3 | @endhasColorscheme 4 | 5 | @hasLabels($configuration) 6 | <{{ $tag }} id="{{ $id }}"> 7 | 8 | 9 | 10 | @else 11 | 12 | @endhasLabels 13 | -------------------------------------------------------------------------------- /resources/views/components/colorscheme.blade.php: -------------------------------------------------------------------------------- 1 | @push('charts.css') 2 | @hasLabels($configuration) {{ $id }} ul, {{ $id }} table @else {{ $id }} @endhasLabels { 3 | @foreach($declarations as $declaration) 4 | {!! $declaration !!} 5 | @endforeach 6 | } 7 | @endpush 8 | -------------------------------------------------------------------------------- /resources/views/components/entry.blade.php: -------------------------------------------------------------------------------- 1 | 2 | @if($value){!! $value !!}@endif 3 | @if($tooltip){!! $tooltip !!}@endif 4 | 5 | -------------------------------------------------------------------------------- /resources/views/components/label.blade.php: -------------------------------------------------------------------------------- 1 | @if($label){!! $label !!}@endif 2 | -------------------------------------------------------------------------------- /resources/views/components/legend.blade.php: -------------------------------------------------------------------------------- 1 | <{{ $tag }} {{ $attributes->class(['charts-css', 'legend'])->class($classes) }}> 2 | @foreach ($labels as $label) 3 |
  • {{ $label }}
  • 4 | @endforeach 5 | 6 | -------------------------------------------------------------------------------- /resources/views/components/stylesheet.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | @if($href)@endif 4 | -------------------------------------------------------------------------------- /resources/views/components/table.blade.php: -------------------------------------------------------------------------------- 1 | class(['charts-css'])->class($configuration->modifications()->classes()) }}> 2 | @hasHeading($configuration) 3 | 4 | @endhasHeading 5 | @if($datasets->axes()->primary() || $datasets->axes()->data()) 6 | 7 | 8 | 9 | @foreach($datasets->axes()->data() as $axis) 10 | 11 | @endforeach 12 | 13 | 14 | @endif 15 | 16 | @foreach($datasets->toArray() as $dataset) 17 | @if((new \Maartenpaauw\Chartscss\Data\Specifications\HasMultiple())->isSatisfiedBy($datasets)) 18 | 19 | 20 | @foreach($dataset->entries() as $entry) 21 | 22 | @endforeach 23 | 24 | @else 25 | @foreach($dataset->entries() as $entry) 26 | 27 | 28 | 29 | 30 | @endforeach 31 | @endif 32 | @endforeach 33 | 34 |
    {{ $datasets->axes()->primary() }}{{ $axis }}
    35 | -------------------------------------------------------------------------------- /src/Appearance/Colorscheme/Color.php: -------------------------------------------------------------------------------- 1 | value = $value; 15 | } 16 | 17 | public function value(): string 18 | { 19 | return $this->value; 20 | } 21 | 22 | public function declaration(): DeclarationContract 23 | { 24 | return new ColorDeclaration($this->value()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Appearance/Colorscheme/ColorContract.php: -------------------------------------------------------------------------------- 1 | colors = $colors; 18 | } 19 | 20 | public function add(ColorContract $color): ColorschemeContract 21 | { 22 | return new self(array_merge($this->colors, [$color])); 23 | } 24 | 25 | /** 26 | * @return ColorContract[] 27 | */ 28 | public function colors(): array 29 | { 30 | if (count($this->colors) <= 1) { 31 | return $this->colors; 32 | } 33 | 34 | return array_map(function (ColorContract $color, int $row) { 35 | return new RowColor($color, $row); 36 | }, $this->colors, range(1, count($this->colors))); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Appearance/Colorscheme/ColorschemeContract.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 17 | $this->row = $row; 18 | } 19 | 20 | public function value(): string 21 | { 22 | return $this->origin->value(); 23 | } 24 | 25 | public function declaration(): DeclarationContract 26 | { 27 | return new RowColorDeclaration($this->value(), $this->row); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Appearance/CustomModification.php: -------------------------------------------------------------------------------- 1 | class = $class; 12 | } 13 | 14 | public function classes(): array 15 | { 16 | return [$this->class]; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Appearance/DataSpacing.php: -------------------------------------------------------------------------------- 1 | validate($spacing); 17 | 18 | $this->spacing = $spacing; 19 | } 20 | 21 | protected function max(): int 22 | { 23 | return 20; 24 | } 25 | 26 | public function classes(): array 27 | { 28 | return ["data-spacing-{$this->spacing}"]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Appearance/DatasetsSpacing.php: -------------------------------------------------------------------------------- 1 | validate($spacing); 17 | 18 | $this->spacing = $spacing; 19 | } 20 | 21 | protected function max(): int 22 | { 23 | return 20; 24 | } 25 | 26 | public function classes(): array 27 | { 28 | return ["datasets-spacing-{$this->spacing}"]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Appearance/Exceptions/OutOfRangeException.php: -------------------------------------------------------------------------------- 1 | modifications = $modifications; 18 | } 19 | 20 | public function add(Modification $modification): self 21 | { 22 | return new self(array_merge($this->modifications, [$modification])); 23 | } 24 | 25 | public function classes(): array 26 | { 27 | return array_reduce($this->modifications, function (array $classes, Modification $modification) { 28 | return array_merge($classes, $modification->classes()); 29 | }, []); 30 | } 31 | 32 | /** 33 | * @return Modification[] 34 | */ 35 | public function toArray(): array 36 | { 37 | return $this->modifications; 38 | } 39 | 40 | public function toString(): string 41 | { 42 | return implode(' ', $this->classes()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Appearance/Multiple.php: -------------------------------------------------------------------------------- 1 | min() > $value || $value > $this->max()) { 25 | throw new OutOfRangeException($value, $this->min(), $this->max()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Appearance/ReverseData.php: -------------------------------------------------------------------------------- 1 | validate($axes); 17 | 18 | $this->axes = $axes; 19 | } 20 | 21 | public function classes(): array 22 | { 23 | return ["show-{$this->axes}-secondary-axes"]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Appearance/Stacked.php: -------------------------------------------------------------------------------- 1 | name('laravel-charts-css') 26 | ->hasViews() 27 | ->hasCommand(MakeChartCommand::class) 28 | ->hasViewComponent('charts-css', Colorscheme::class) 29 | ->hasViewComponent('charts-css', Entry::class) 30 | ->hasViewComponent('charts-css', Heading::class) 31 | ->hasViewComponent('charts-css', Label::class) 32 | ->hasViewComponent('charts-css', Legend::class) 33 | ->hasViewComponent('charts-css', Stylesheet::class) 34 | ->hasViewComponent('charts-css', Table::class); 35 | 36 | (new Directives()) 37 | ->register(new HasColorscheme(), 'hasColorscheme') 38 | ->register(new HasHeading(), 'hasHeading') 39 | ->register(new HasLabels(), 'hasLabels'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Commands/MakeChartCommand.php: -------------------------------------------------------------------------------- 1 | isCustomNamespace()) { 17 | return $rootNamespace; 18 | } 19 | 20 | return sprintf('%s\View\Components', $rootNamespace); 21 | } 22 | 23 | protected function getStub(): string 24 | { 25 | return sprintf('%s/../../stubs/chart.stub', __DIR__); 26 | } 27 | 28 | protected function replaceClass($stub, $name): string 29 | { 30 | return Str::replace( 31 | ['dummy-id', 'Dummy Heading'], 32 | [$this->id(), $this->heading()], 33 | parent::replaceClass($stub, $name), 34 | ); 35 | } 36 | 37 | private function id(): string 38 | { 39 | return Str::kebab($this->className()); 40 | } 41 | 42 | private function heading(): string 43 | { 44 | $words = preg_split('/(?=[A-Z])/', $this->className()); 45 | 46 | if ($words === false) { 47 | return ''; 48 | } 49 | 50 | return trim(implode(' ', $words)); 51 | } 52 | 53 | private function className(): string 54 | { 55 | return Str::afterLast($this->getNameInput(), '/'); 56 | } 57 | 58 | private function isCustomNamespace(): bool 59 | { 60 | return Str::contains($this->getNameInput(), '/'); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Components/Colorscheme.php: -------------------------------------------------------------------------------- 1 | configuration = $configuration; 17 | } 18 | 19 | private function id(): string 20 | { 21 | return sprintf('#%s', $this->configuration->identity()->id()); 22 | } 23 | 24 | /** 25 | * @return string[] 26 | */ 27 | private function declarations(): array 28 | { 29 | return array_map(function (ColorContract $color) { 30 | return $color->declaration()->toString(); 31 | }, $this->configuration->colorscheme()->colors()); 32 | } 33 | 34 | public function render(): View 35 | { 36 | return view('charts-css::components.colorscheme', [ 37 | 'id' => $this->id(), 38 | 'configuration' => $this->configuration, 39 | 'declarations' => $this->declarations(), 40 | ]); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Components/Entry.php: -------------------------------------------------------------------------------- 1 | entry = $entry; 16 | } 17 | 18 | public function render(): View 19 | { 20 | return view('charts-css::components.entry', [ 21 | 'styling' => $this->entry->value()->declarations()->toString(), 22 | 'tooltip' => $this->entry->tooltip()->content(), 23 | 'value' => $this->entry->value()->display(), 24 | ]); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Components/Heading.php: -------------------------------------------------------------------------------- 1 | heading = $heading; 14 | } 15 | 16 | public function render(): string 17 | { 18 | return "{$this->heading}"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Components/Label.php: -------------------------------------------------------------------------------- 1 | label = $label; 16 | } 17 | 18 | public function render(): View 19 | { 20 | return view('charts-css::components.label', [ 21 | 'classes' => $this->label->modifications()->toString(), 22 | 'label' => $this->label->value(), 23 | 'styling' => $this->label->declarations()->toString(), 24 | ]); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Components/Legend.php: -------------------------------------------------------------------------------- 1 | configuration = $configuration; 16 | } 17 | 18 | public function render(): View 19 | { 20 | return view('charts-css::components.legend', [ 21 | 'labels' => $this->configuration->legend()->labels(), 22 | 'classes' => $this->configuration->legend()->classes(), 23 | 'tag' => $this->configuration->legend()->tag(), 24 | ]); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Components/Stylesheet.php: -------------------------------------------------------------------------------- 1 | strategy = $factory->create($cdn); 17 | } 18 | 19 | public function render(): View 20 | { 21 | return view('charts-css::components.stylesheet', [ 22 | 'href' => $this->strategy->href(), 23 | ]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Components/Table.php: -------------------------------------------------------------------------------- 1 | datasets = $datasets; 19 | $this->configuration = $configuration; 20 | } 21 | 22 | public function render(): View 23 | { 24 | return view('charts-css::components.table', [ 25 | 'datasets' => $this->datasets, 26 | 'configuration' => $this->configuration, 27 | ]); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Configuration/Configuration.php: -------------------------------------------------------------------------------- 1 | identity = $identity; 27 | $this->legend = $legend; 28 | $this->modifications = $modifications; 29 | $this->colorscheme = $colorscheme; 30 | } 31 | 32 | public function identity(): Identity 33 | { 34 | return $this->identity; 35 | } 36 | 37 | public function legend(): Legend 38 | { 39 | return $this->legend; 40 | } 41 | 42 | public function modifications(): Modifications 43 | { 44 | return $this->modifications; 45 | } 46 | 47 | public function colorscheme(): ColorschemeContract 48 | { 49 | return $this->colorscheme; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Configuration/ConfigurationContract.php: -------------------------------------------------------------------------------- 1 | $specification 13 | */ 14 | public function register(Specification $specification, string $name): self 15 | { 16 | Blade::if($name, function (ConfigurationContract $configuration) use ($specification) { 17 | return $specification->isSatisfiedBy($configuration); 18 | }); 19 | 20 | return $this; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Configuration/Specifications/HasColorscheme.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class HasColorscheme extends CompositeSpecification 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | public function isSatisfiedBy($candidate): bool 17 | { 18 | return count($candidate->colorscheme()->colors()) !== 0; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Configuration/Specifications/HasHeading.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class HasHeading extends CompositeSpecification 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | public function isSatisfiedBy($candidate): bool 17 | { 18 | return $candidate->identity()->description() !== ''; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Configuration/Specifications/HasLabels.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class HasLabels extends CompositeSpecification 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | public function isSatisfiedBy($candidate): bool 17 | { 18 | return count($candidate->legend()->labels()) !== 0; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Configuration/Specifications/NeedsStartingPoint.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | class NeedsStartingPoint extends CompositeSpecification 14 | { 15 | /** 16 | * @var string[] 17 | */ 18 | private array $types; 19 | 20 | public function __construct() 21 | { 22 | $this->types = [ 23 | (new Area())->toString(), 24 | (new Line())->toString(), 25 | ]; 26 | } 27 | 28 | public function isSatisfiedBy($candidate): bool 29 | { 30 | return in_array( 31 | $candidate->identity()->type()->toString(), 32 | $this->types, 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Data/Axes/Axes.php: -------------------------------------------------------------------------------- 1 | primary = $primary; 20 | $this->data = is_string($data) ? [$data] : $data; 21 | } 22 | 23 | public function primary(): string 24 | { 25 | return $this->primary; 26 | } 27 | 28 | public function data(): array 29 | { 30 | return $this->data; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Data/Axes/AxesContract.php: -------------------------------------------------------------------------------- 1 | dataset = $dataset; 16 | } 17 | 18 | public function result(): float 19 | { 20 | return max( 21 | array_merge( 22 | [0], 23 | array_map( 24 | fn (EntryContract $entry) => $entry->value()->raw(), 25 | $this->dataset->entries(), 26 | ), 27 | ), 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Data/Dataset/Statistics/SumStatistic.php: -------------------------------------------------------------------------------- 1 | dataset = $dataset; 16 | } 17 | 18 | public function result(): float 19 | { 20 | return array_sum( 21 | array_map( 22 | fn (EntryContract $entry) => $entry->value()->raw(), 23 | $this->dataset->entries(), 24 | ), 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Data/Datasets/CalculatedDataset.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 19 | $this->maximum = $maximum; 20 | } 21 | 22 | public function entries(): array 23 | { 24 | return array_map(function (EntryContract $entry) { 25 | return new CalculatedEntry($entry, $this->maximum); 26 | }, $this->origin->entries()); 27 | } 28 | 29 | public function label(): LabelContract 30 | { 31 | return $this->origin->label(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Data/Datasets/CalculatedDatasets.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 15 | } 16 | 17 | public function axes(): AxesContract 18 | { 19 | return $this->origin->axes(); 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return array_map(function (DatasetContract $dataset) { 25 | return new CalculatedDataset($dataset, new HighestEntryStatistic($this->origin)); 26 | }, $this->origin->toArray()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Data/Datasets/Dataset.php: -------------------------------------------------------------------------------- 1 | entries = $entries; 26 | $this->label = $label ?? new NullLabel(); 27 | } 28 | 29 | public function entries(): array 30 | { 31 | return $this->entries; 32 | } 33 | 34 | public function label(): LabelContract 35 | { 36 | return $this->label; 37 | } 38 | 39 | public function add(EntryContract $entry): self 40 | { 41 | return new self( 42 | array_merge($this->entries, [$entry]), 43 | $this->label, 44 | ); 45 | } 46 | 47 | public function hideLabel(): self 48 | { 49 | return new self( 50 | $this->entries, 51 | new HiddenLabel($this->label), 52 | ); 53 | } 54 | 55 | public function alignLabel(string $alignment): self 56 | { 57 | return new self( 58 | $this->entries, 59 | new AlignedLabel($this->label, $alignment), 60 | ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Data/Datasets/DatasetContract.php: -------------------------------------------------------------------------------- 1 | axes = $axes; 19 | $this->datasets = $datasets; 20 | } 21 | 22 | public function axes(): AxesContract 23 | { 24 | return $this->axes; 25 | } 26 | 27 | public function toArray(): array 28 | { 29 | return $this->datasets; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Data/Datasets/DatasetsContract.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 15 | } 16 | 17 | public function axes(): AxesContract 18 | { 19 | return $this->origin->axes(); 20 | } 21 | 22 | /** 23 | * @inheritDoc 24 | */ 25 | public function toArray(): array 26 | { 27 | if ((new HasMultiple())->not()->isSatisfiedBy($this->origin)) { 28 | return $this->origin->toArray(); 29 | } 30 | 31 | return array_reduce($this->origin->toArray(), function (array $datasets, DatasetContract $dataset) { 32 | foreach (array_values($dataset->entries()) as $index => $entry) { 33 | if (array_key_exists($index, $datasets)) { 34 | $datasets[$index] = $datasets[$index]->add($entry); 35 | } else { 36 | $datasets[$index] = new Dataset([$entry]); 37 | } 38 | } 39 | 40 | return $datasets; 41 | }, array_map(fn (DatasetContract $dataset) => new Dataset([], $dataset->label()), $this->origin->toArray())); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Data/Datasets/PercentageStackedDatasets.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 15 | } 16 | 17 | public function axes(): AxesContract 18 | { 19 | return $this->origin->axes(); 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return array_map(function (DatasetContract $dataset) { 25 | return new CalculatedDataset($dataset, new SumStatistic($dataset)); 26 | }, $this->origin->toArray()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Data/Datasets/SimpleStackedDatasets.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 15 | } 16 | 17 | public function axes(): AxesContract 18 | { 19 | return $this->origin->axes(); 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return array_map(function (DatasetContract $dataset) { 25 | return new CalculatedDataset($dataset, new HighestDatasetSumStatistic($this->origin)); 26 | }, $this->origin->toArray()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Data/Datasets/StartingPointDataset.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 19 | $this->maximum = $maximum; 20 | } 21 | 22 | public function entries(): array 23 | { 24 | if (count($this->origin->entries()) <= 1) { 25 | return $this->origin->entries(); 26 | } 27 | 28 | $entries = array_values($this->origin->entries()); 29 | $first = array_shift($entries); 30 | 31 | return array_merge([$first], array_map(function (EntryContract $entry, int $key) use ($first, $entries) { 32 | return new StartingPointEntry($entry, $entries[--$key] ?? $first, $this->maximum); 33 | }, $entries, array_keys($entries))); 34 | } 35 | 36 | public function label(): LabelContract 37 | { 38 | return $this->origin->label(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Data/Datasets/StartingPointDatasets.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 15 | } 16 | 17 | public function axes(): AxesContract 18 | { 19 | return $this->origin->axes(); 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return array_map(function (DatasetContract $dataset) { 25 | return new StartingPointDataset($dataset, new HighestEntryStatistic($this->origin)); 26 | }, $this->origin->toArray()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Data/Datasets/Statistics/HighestDatasetSumStatistic.php: -------------------------------------------------------------------------------- 1 | datasets = $datasets; 17 | } 18 | 19 | public function result(): float 20 | { 21 | $datasets = $this->datasets->toArray(); 22 | 23 | if (count($datasets) === 0) { 24 | return 0; 25 | } 26 | 27 | return max( 28 | array_map( 29 | fn (DatasetContract $dataset) => (new SumStatistic($dataset))->result(), 30 | $datasets, 31 | ), 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Data/Datasets/Statistics/HighestEntryStatistic.php: -------------------------------------------------------------------------------- 1 | datasets = $datasets; 17 | } 18 | 19 | public function result(): float 20 | { 21 | return max( 22 | array_merge( 23 | [0], 24 | array_map( 25 | fn (DatasetContract $dataset) => (new HighestDatasetEntryStatistic($dataset))->result(), 26 | $this->datasets->toArray(), 27 | ), 28 | ), 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Data/Entries/CalculatedEntry.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 20 | $this->maximum = $maximum; 21 | } 22 | 23 | public function value(): ValueContract 24 | { 25 | return new SizedValue( 26 | $this->origin->value(), 27 | $this->maximum->result(), 28 | ); 29 | } 30 | 31 | public function label(): LabelContract 32 | { 33 | return $this->origin->label(); 34 | } 35 | 36 | public function tooltip(): TooltipContract 37 | { 38 | return $this->origin->tooltip(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Data/Entries/Entry.php: -------------------------------------------------------------------------------- 1 | value = $value; 27 | $this->label = $label ?? new NullLabel(); 28 | $this->tooltip = $tooltip ?? new NullTooltip(); 29 | } 30 | 31 | public function value(): ValueContract 32 | { 33 | return $this->value; 34 | } 35 | 36 | public function label(): LabelContract 37 | { 38 | return $this->label; 39 | } 40 | 41 | public function tooltip(): TooltipContract 42 | { 43 | return $this->tooltip; 44 | } 45 | 46 | public function color(ColorContract $color): Entry 47 | { 48 | return new self( 49 | new ColorfulValue($this->value, $color), 50 | $this->label, 51 | ); 52 | } 53 | 54 | public function start(float $start): Entry 55 | { 56 | return new self( 57 | new StartValue($this->value, $start), 58 | $this->label, 59 | ); 60 | } 61 | 62 | public function hideLabel(): Entry 63 | { 64 | return new self( 65 | $this->value, 66 | new HiddenLabel($this->label), 67 | ); 68 | } 69 | 70 | public function alignLabel(string $alignment): Entry 71 | { 72 | return new self( 73 | $this->value, 74 | new AlignedLabel($this->label, $alignment), 75 | ); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Data/Entries/EntryContract.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 22 | $this->previous = $previous; 23 | $this->maximum = $maximum; 24 | } 25 | 26 | public function value(): ValueContract 27 | { 28 | return new StartValue( 29 | $this->origin->value(), 30 | $this->previous->value()->raw(), 31 | $this->maximum->result(), 32 | ); 33 | } 34 | 35 | public function label(): LabelContract 36 | { 37 | return $this->origin->label(); 38 | } 39 | 40 | public function tooltip(): TooltipContract 41 | { 42 | return $this->origin->tooltip(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Data/Entries/Tooltip/NullTooltip.php: -------------------------------------------------------------------------------- 1 | content = $content; 12 | } 13 | 14 | public function content(): string 15 | { 16 | return $this->content; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Data/Entries/Tooltip/TooltipContract.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 17 | $this->color = $color; 18 | } 19 | 20 | public function raw(): float 21 | { 22 | return $this->origin->raw(); 23 | } 24 | 25 | public function display(): string 26 | { 27 | return $this->origin->display(); 28 | } 29 | 30 | public function declarations(): Declarations 31 | { 32 | return $this->origin 33 | ->declarations() 34 | ->add($this->color->declaration()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Data/Entries/Value/NullValue.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 18 | $this->declaration = new SizeDeclaration($origin->raw(), $max); 19 | } 20 | 21 | public function raw(): float 22 | { 23 | return $this->origin->raw(); 24 | } 25 | 26 | public function display(): string 27 | { 28 | return $this->origin->display(); 29 | } 30 | 31 | public function declarations(): Declarations 32 | { 33 | return $this->origin 34 | ->declarations() 35 | ->add($this->declaration); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Data/Entries/Value/StartValue.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 18 | $this->declaration = new StartDeclaration($value, $max); 19 | } 20 | 21 | public function raw(): float 22 | { 23 | return $this->origin->raw(); 24 | } 25 | 26 | public function display(): string 27 | { 28 | return $this->origin->display(); 29 | } 30 | 31 | public function declarations(): Declarations 32 | { 33 | return $this->origin 34 | ->declarations() 35 | ->add($this->declaration); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Data/Entries/Value/Value.php: -------------------------------------------------------------------------------- 1 | raw = $raw; 18 | $this->display = $display ?? strval($raw); 19 | $this->declarations = $declarations ?? new Declarations(); 20 | } 21 | 22 | public function raw(): float 23 | { 24 | return $this->raw; 25 | } 26 | 27 | public function display(): string 28 | { 29 | return $this->display; 30 | } 31 | 32 | public function declarations(): Declarations 33 | { 34 | return $this->declarations; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Data/Entries/Value/ValueContract.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 18 | $this->alignment = $alignment; 19 | } 20 | 21 | public function value(): string 22 | { 23 | return $this->origin->value(); 24 | } 25 | 26 | public function modifications(): Modifications 27 | { 28 | return $this->origin->modifications(); 29 | } 30 | 31 | public function declarations(): Declarations 32 | { 33 | return $this->origin 34 | ->declarations() 35 | ->add(new LabelAlignmentDeclaration($this->alignment)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Data/Label/HiddenLabel.php: -------------------------------------------------------------------------------- 1 | origin = $origin; 16 | } 17 | 18 | public function value(): string 19 | { 20 | return $this->origin->value(); 21 | } 22 | 23 | public function modifications(): Modifications 24 | { 25 | return $this->origin 26 | ->modifications() 27 | ->add(new HideLabel()); 28 | } 29 | 30 | public function declarations(): Declarations 31 | { 32 | return $this->origin->declarations(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Data/Label/Label.php: -------------------------------------------------------------------------------- 1 | value = $value; 19 | $this->modifications = $modifications ?? new Modifications(); 20 | $this->declarations = $declarations ?? new Declarations(); 21 | } 22 | 23 | public function value(): string 24 | { 25 | return $this->value; 26 | } 27 | 28 | public function modifications(): Modifications 29 | { 30 | return $this->modifications; 31 | } 32 | 33 | public function declarations(): Declarations 34 | { 35 | return $this->declarations; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Data/Label/LabelContract.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class HasDatasetLabels extends CompositeSpecification 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | public function isSatisfiedBy($candidate): bool 17 | { 18 | foreach ($candidate->toArray() as $dataset) { 19 | if ($dataset->label()->value() !== '') { 20 | return true; 21 | } 22 | } 23 | 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Data/Specifications/HasEntryLabels.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class HasEntryLabels extends CompositeSpecification 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | public function isSatisfiedBy($candidate): bool 17 | { 18 | foreach ($candidate->toArray() as $dataset) { 19 | foreach ($dataset->entries() as $entry) { 20 | if ($entry->label()->value() !== '') { 21 | return true; 22 | } 23 | } 24 | } 25 | 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Data/Specifications/HasMultiple.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class HasMultiple extends CompositeSpecification 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | public function isSatisfiedBy($candidate): bool 17 | { 18 | return count($candidate->toArray()) > 1; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Data/Specifications/IsStacked.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | class IsStacked extends CompositeSpecification 14 | { 15 | /** 16 | * @inheritDoc 17 | */ 18 | public function isSatisfiedBy($candidate): bool 19 | { 20 | return in_array(get_class($candidate), [ 21 | SimpleStackedDatasets::class, 22 | PercentageStackedDatasets::class, 23 | ]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Declarations/ColorDeclaration.php: -------------------------------------------------------------------------------- 1 | color = $color; 12 | } 13 | 14 | public function toString(): string 15 | { 16 | return "--color: {$this->color};"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Declarations/DeclarationContract.php: -------------------------------------------------------------------------------- 1 | declarations = $declarations; 18 | } 19 | 20 | public function add(DeclarationContract $declaration): self 21 | { 22 | return new self(array_merge($this->declarations, [$declaration])); 23 | } 24 | 25 | public function merge(Declarations $declarations): self 26 | { 27 | return new self(array_merge($this->toArray(), $declarations->toArray())); 28 | } 29 | 30 | public function toString(): string 31 | { 32 | return implode(' ', array_map(function (DeclarationContract $declaration) { 33 | return $declaration->toString(); 34 | }, $this->declarations)); 35 | } 36 | 37 | /** 38 | * @return DeclarationContract[] 39 | */ 40 | public function toArray(): array 41 | { 42 | return $this->declarations; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Declarations/LabelAlignmentDeclaration.php: -------------------------------------------------------------------------------- 1 | alignment = $alignment === 'center' ? $alignment : "flex-{$alignment}"; 12 | } 13 | 14 | public function toString(): string 15 | { 16 | return "--labels-align: {$this->alignment};"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Declarations/RowColorDeclaration.php: -------------------------------------------------------------------------------- 1 | color = $color; 14 | $this->row = $row; 15 | } 16 | 17 | public function toString(): string 18 | { 19 | return "--color-{$this->row}: {$this->color};"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Declarations/SizeDeclaration.php: -------------------------------------------------------------------------------- 1 | value = $value; 14 | $this->max = $max; 15 | } 16 | 17 | public function toString(): string 18 | { 19 | return "--size: calc({$this->value} / {$this->max});"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Declarations/StartDeclaration.php: -------------------------------------------------------------------------------- 1 | value = $value; 14 | $this->max = $max; 15 | } 16 | 17 | public function toString(): string 18 | { 19 | return "--start: calc({$this->value} / {$this->max});"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Examples/Area/AreaExample1.php: -------------------------------------------------------------------------------- 1 | start(0.2), 36 | new Entry(new Value(0.8, '$80k')), 37 | new Entry(new Value(0.6, '$60k')), 38 | new Entry(new Value(1, '$100k')), 39 | new Entry(new Value(0.3, '$30k')), 40 | ]), 41 | ); 42 | } 43 | 44 | protected function configuration(): ConfigurationContract 45 | { 46 | return new Configuration( 47 | $this->identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new HideData()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Area/AreaExample3.php: -------------------------------------------------------------------------------- 1 | start(0.2), 37 | new Entry(new Value(0.8, '')), 38 | new Entry(new Value(0.6, '')), 39 | new Entry(new Value(1, '')), 40 | new Entry(new Value(0.3, '')), 41 | ]), 42 | ); 43 | } 44 | 45 | protected function configuration(): ConfigurationContract 46 | { 47 | return new Configuration( 48 | $this->identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new HideData()) 59 | ->add(new ReverseOrientation()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Area/AreaExample4.php: -------------------------------------------------------------------------------- 1 | start(0.2), 34 | new Entry(new Value(0.8, '')), 35 | new Entry(new Value(0.6, '')), 36 | new Entry(new Value(1, '')), 37 | new Entry(new Value(0.3, '')), 38 | ]), 39 | ); 40 | } 41 | 42 | protected function modifications(): Modifications 43 | { 44 | return parent::modifications() 45 | ->add(new HideData()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample1.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowLabels()) 59 | ->add(new ShowPrimaryAxis()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample11.php: -------------------------------------------------------------------------------- 1 | identity(), 51 | $this->legend(), 52 | $this->modifications(), 53 | $this->colorscheme(), 54 | ); 55 | } 56 | 57 | protected function modifications(): Modifications 58 | { 59 | return parent::modifications() 60 | ->add(new ShowLabels()) 61 | ->add(new ShowPrimaryAxis()) 62 | ->add(new ShowDataAxes()) 63 | ->add(new ShowSecondaryAxes(4)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample2.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowLabels()) 60 | ->add(new ReverseOrientation()) 61 | ->add(new ShowPrimaryAxis()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample3.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowLabels()) 59 | ->add(new ShowPrimaryAxis()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample4.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowLabels()) 60 | ->add(new ReverseOrientation()) 61 | ->add(new ShowPrimaryAxis()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample5.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowLabels()) 60 | ->add(new ShowPrimaryAxis()) 61 | ->add(new ShowSecondaryAxes(2)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample7.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowLabels()) 60 | ->add(new ShowPrimaryAxis()) 61 | ->add(new ShowSecondaryAxes(4)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Axes/AxesExample9.php: -------------------------------------------------------------------------------- 1 | identity(), 51 | $this->legend(), 52 | $this->modifications(), 53 | $this->colorscheme(), 54 | ); 55 | } 56 | 57 | protected function modifications(): Modifications 58 | { 59 | return parent::modifications() 60 | ->add(new ShowLabels()) 61 | ->add(new ShowPrimaryAxis()) 62 | ->add(new ShowDataAxes()) 63 | ->add(new ShowSecondaryAxes(4)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample1.php: -------------------------------------------------------------------------------- 1 | identity(), 45 | $this->legend(), 46 | $this->modifications(), 47 | $this->colorscheme(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample10.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ShowLabels()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample11.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowPrimaryAxis()) 59 | ->add(new ShowLabels()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample12.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowPrimaryAxis()) 60 | ->add(new ShowSecondaryAxes(4)) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample13.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowPrimaryAxis()) 60 | ->add(new ShowSecondaryAxes(10)) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample14.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowDataAxes()) 59 | ->add(new ShowLabels()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample15.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowDataAxes()) 60 | ->add(new ShowSecondaryAxes(4)) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample16.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowPrimaryAxis()) 60 | ->add(new ShowDataAxes()) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample17.php: -------------------------------------------------------------------------------- 1 | identity(), 51 | $this->legend(), 52 | $this->modifications(), 53 | $this->colorscheme(), 54 | ); 55 | } 56 | 57 | protected function modifications(): Modifications 58 | { 59 | return parent::modifications() 60 | ->add(new ShowPrimaryAxis()) 61 | ->add(new ShowDataAxes()) 62 | ->add(new DataSpacing(10)) 63 | ->add(new ShowLabels()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample2.php: -------------------------------------------------------------------------------- 1 | identity(), 47 | $this->legend(), 48 | $this->modifications(), 49 | $this->colorscheme(), 50 | ); 51 | } 52 | 53 | protected function modifications(): Modifications 54 | { 55 | return parent::modifications() 56 | ->add(new ReverseOrientation()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample20.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ShowLabels()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample21.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ReverseData()) 59 | ->add(new ShowLabels()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample3.php: -------------------------------------------------------------------------------- 1 | identity(), 45 | $this->legend(), 46 | $this->modifications(), 47 | $this->colorscheme(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample5.php: -------------------------------------------------------------------------------- 1 | identity(), 55 | $this->legend(), 56 | $this->modifications(), 57 | $this->colorscheme(), 58 | ); 59 | } 60 | 61 | protected function modifications(): Modifications 62 | { 63 | return parent::modifications() 64 | ->add(new DataSpacing(3)) 65 | ->add(new Multiple()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample6.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ShowLabels()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Bar/BarExample7.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowLabels()) 59 | ->add(new ReverseOrientation()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample1.php: -------------------------------------------------------------------------------- 1 | identity(), 45 | $this->legend(), 46 | $this->modifications(), 47 | $this->colorscheme(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample10.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ShowLabels()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample11.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowPrimaryAxis()) 59 | ->add(new ShowLabels()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample12.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowPrimaryAxis()) 60 | ->add(new ShowSecondaryAxes(4)) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample13.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowPrimaryAxis()) 60 | ->add(new ShowSecondaryAxes(10)) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample14.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowDataAxes()) 59 | ->add(new ShowLabels()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample15.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowDataAxes()) 60 | ->add(new ShowSecondaryAxes(4)) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample16.php: -------------------------------------------------------------------------------- 1 | identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new ShowPrimaryAxis()) 60 | ->add(new ShowDataAxes()) 61 | ->add(new ShowLabels()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample17.php: -------------------------------------------------------------------------------- 1 | identity(), 51 | $this->legend(), 52 | $this->modifications(), 53 | $this->colorscheme(), 54 | ); 55 | } 56 | 57 | protected function modifications(): Modifications 58 | { 59 | return parent::modifications() 60 | ->add(new ShowPrimaryAxis()) 61 | ->add(new ShowDataAxes()) 62 | ->add(new DataSpacing(20)) 63 | ->add(new ShowLabels()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample2.php: -------------------------------------------------------------------------------- 1 | identity(), 47 | $this->legend(), 48 | $this->modifications(), 49 | $this->colorscheme(), 50 | ); 51 | } 52 | 53 | protected function modifications(): Modifications 54 | { 55 | return parent::modifications() 56 | ->add(new ReverseOrientation()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample20.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ShowLabels()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample21.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ReverseData()) 59 | ->add(new ShowLabels()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample3.php: -------------------------------------------------------------------------------- 1 | identity(), 45 | $this->legend(), 46 | $this->modifications(), 47 | $this->colorscheme(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample5.php: -------------------------------------------------------------------------------- 1 | identity(), 55 | $this->legend(), 56 | $this->modifications(), 57 | $this->colorscheme(), 58 | ); 59 | } 60 | 61 | protected function modifications(): Modifications 62 | { 63 | return parent::modifications() 64 | ->add(new DataSpacing(3)) 65 | ->add(new Multiple()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample6.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ShowLabels()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Column/ColumnExample7.php: -------------------------------------------------------------------------------- 1 | identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ShowLabels()) 59 | ->add(new ReverseOrientation()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Data/DataExample2.php: -------------------------------------------------------------------------------- 1 | identity(), 45 | $this->legend(), 46 | $this->modifications(), 47 | $this->colorscheme(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Examples/Data/DataExample3.php: -------------------------------------------------------------------------------- 1 | identity(), 45 | $this->legend(), 46 | $this->modifications(), 47 | $this->colorscheme(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Examples/Data/DataExample4.php: -------------------------------------------------------------------------------- 1 | add(new HideData()); 47 | } 48 | 49 | protected function configuration(): ConfigurationContract 50 | { 51 | return new Configuration( 52 | $this->identity(), 53 | $this->legend(), 54 | $this->modifications(), 55 | $this->colorscheme(), 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Examples/Data/DataExample5.php: -------------------------------------------------------------------------------- 1 | add(new ShowDataOnHover()); 47 | } 48 | 49 | protected function configuration(): ConfigurationContract 50 | { 51 | return new Configuration( 52 | $this->identity(), 53 | $this->legend(), 54 | $this->modifications(), 55 | $this->colorscheme(), 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Examples/Data/DataExample6.php: -------------------------------------------------------------------------------- 1 | identity(), 33 | $this->legend(), 34 | $this->modifications(), 35 | $this->colorscheme(), 36 | ); 37 | } 38 | 39 | protected function datasets(): DatasetsContract 40 | { 41 | return new Datasets( 42 | new NullAxes(), 43 | new Dataset([ 44 | (new Entry(new Value(0.4, '$40k'))) 45 | ->start(0.2), 46 | new Entry(new Value(0.8, '$80k')), 47 | new Entry(new Value(0.6, '$60k')), 48 | new Entry(new Value(1, '$100k')), 49 | new Entry(new Value(0.3, '$30k')), 50 | ]), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new HideData()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Heading/HeadingExample1.php: -------------------------------------------------------------------------------- 1 | identity(), 46 | $this->legend(), 47 | $this->modifications(), 48 | $this->colorscheme(), 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Examples/Heading/HeadingExample2.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ShowHeading()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Line/LineExample1.php: -------------------------------------------------------------------------------- 1 | start(0), 36 | new Entry(new Value(0.2, '$ 20k')), 37 | new Entry(new Value(0.6, '$ 60k')), 38 | new Entry(new Value(0.4, '$ 40k')), 39 | new Entry(new Value(0.8, '$ 80k')), 40 | new Entry(new Value(0.6, '$ 60k')), 41 | new Entry(new Value(1, '$ 100k')), 42 | ]), 43 | ); 44 | } 45 | 46 | protected function configuration(): ConfigurationContract 47 | { 48 | return new Configuration( 49 | $this->identity(), 50 | $this->legend(), 51 | $this->modifications(), 52 | $this->colorscheme(), 53 | ); 54 | } 55 | 56 | protected function modifications(): Modifications 57 | { 58 | return parent::modifications() 59 | ->add(new HideData()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Examples/Line/LineExample3.php: -------------------------------------------------------------------------------- 1 | start(0), 37 | new Entry(new Value(0.2, '$ 20k')), 38 | new Entry(new Value(0.6, '$ 60k')), 39 | new Entry(new Value(0.4, '$ 40k')), 40 | new Entry(new Value(0.8, '$ 80k')), 41 | new Entry(new Value(0.6, '$ 60k')), 42 | new Entry(new Value(1, '$ 100k')), 43 | ]), 44 | ); 45 | } 46 | 47 | protected function configuration(): ConfigurationContract 48 | { 49 | return new Configuration( 50 | $this->identity(), 51 | $this->legend(), 52 | $this->modifications(), 53 | $this->colorscheme(), 54 | ); 55 | } 56 | 57 | protected function modifications(): Modifications 58 | { 59 | return parent::modifications() 60 | ->add(new HideData()) 61 | ->add(new ReverseOrientation()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Examples/Line/LineExample4.php: -------------------------------------------------------------------------------- 1 | start(0), 34 | new Entry(new Value(0.2, '$ 20k')), 35 | new Entry(new Value(0.6, '$ 60k')), 36 | new Entry(new Value(0.4, '$ 40k')), 37 | new Entry(new Value(0.8, '$ 80k')), 38 | new Entry(new Value(0.6, '$ 60k')), 39 | new Entry(new Value(1, '$ 100k')), 40 | ]), 41 | ); 42 | } 43 | 44 | protected function modifications(): Modifications 45 | { 46 | return parent::modifications() 47 | ->add(new HideData()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Examples/Orientation/OrientationExample1.php: -------------------------------------------------------------------------------- 1 | identity(), 46 | $this->legend(), 47 | $this->modifications(), 48 | $this->colorscheme(), 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Examples/Orientation/OrientationExample2.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ReverseOrientation()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Orientation/OrientationExample3.php: -------------------------------------------------------------------------------- 1 | identity(), 46 | $this->legend(), 47 | $this->modifications(), 48 | $this->colorscheme(), 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Examples/Orientation/OrientationExample4.php: -------------------------------------------------------------------------------- 1 | identity(), 48 | $this->legend(), 49 | $this->modifications(), 50 | $this->colorscheme(), 51 | ); 52 | } 53 | 54 | protected function modifications(): Modifications 55 | { 56 | return parent::modifications() 57 | ->add(new ReverseOrientation()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Examples/Orientation/OrientationExample5.php: -------------------------------------------------------------------------------- 1 | start(0.2), 35 | new Entry(new Value(0.8, ''), new Label('2017')), 36 | new Entry(new Value(0.6, ''), new Label('2018')), 37 | new Entry(new Value(1, ''), new Label('2019')), 38 | new Entry(new Value(0.3, ''), new Label('2020')), 39 | ]), 40 | ); 41 | } 42 | 43 | protected function configuration(): ConfigurationContract 44 | { 45 | return new Configuration( 46 | $this->identity(), 47 | $this->legend(), 48 | $this->modifications(), 49 | $this->colorscheme(), 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Examples/Orientation/OrientationExample6.php: -------------------------------------------------------------------------------- 1 | start(0.2), 37 | new Entry(new Value(0.8, ''), new Label('2017')), 38 | new Entry(new Value(0.6, ''), new Label('2018')), 39 | new Entry(new Value(1, ''), new Label('2019')), 40 | new Entry(new Value(0.3, ''), new Label('2020')), 41 | ]), 42 | ); 43 | } 44 | 45 | protected function configuration(): ConfigurationContract 46 | { 47 | return new Configuration( 48 | $this->identity(), 49 | $this->legend(), 50 | $this->modifications(), 51 | $this->colorscheme(), 52 | ); 53 | } 54 | 55 | protected function modifications(): Modifications 56 | { 57 | return parent::modifications() 58 | ->add(new ReverseOrientation()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Identity/Identity.php: -------------------------------------------------------------------------------- 1 | id = $id; 18 | $this->description = $description; 19 | $this->type = $type; 20 | } 21 | 22 | public function id(): string 23 | { 24 | return $this->id; 25 | } 26 | 27 | public function description(): string 28 | { 29 | return $this->description; 30 | } 31 | 32 | public function type(): ChartType 33 | { 34 | return $this->type; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Legend/Appearance/Circle.php: -------------------------------------------------------------------------------- 1 | value = $value; 12 | } 13 | 14 | public function result(): float 15 | { 16 | return $this->value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Statistics/StatisticContract.php: -------------------------------------------------------------------------------- 1 | new JSDelivrStylesheet(), 11 | 'unpkg' => new UnpkgStylesheet(), 12 | default => new NullStylesheet(), 13 | }; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Stylesheets/UnpkgStylesheet.php: -------------------------------------------------------------------------------- 1 | chartType = $chartType; 14 | } 15 | 16 | public function classes(): array 17 | { 18 | return [$this->chartType->toString()]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Types/Column.php: -------------------------------------------------------------------------------- 1 |