Skip to content

Commit 8063273

Browse files
Merge pull request #63 from ArielMejiaDev/issue-40
fix issues-40 & add improvements in default chart styles
2 parents 9e1f7e0 + 7e7897c commit 8063273

35 files changed

+798
-9
lines changed

config/larapex-charts.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
|
1212
*/
1313

14-
'font_family' => 'Nunito',
14+
'font_family' => 'Helvetica, Arial, sans-serif',
1515

1616
'font_color' => '#373d3f',
1717

stubs/Console/Commands/ChartMakeCommand.php src/Console/ChartMakeCommand.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?php
22

3-
namespace App\Console\Commands;
3+
namespace ArielMejiaDev\LarapexCharts\Console;
44

5+
use ArielMejiaDev\LarapexCharts\Traits\WithModelStub;
56
use Illuminate\Console\GeneratorCommand;
67
use Symfony\Component\Console\Input\InputArgument;
78
use Symfony\Component\Console\Input\InputOption;
89

910
class ChartMakeCommand extends GeneratorCommand
1011
{
12+
use WithModelStub;
13+
1114
protected $chartTypes = [
1215
'Pie Chart' => 'PieChart',
1316
'Donut Chart' => 'DonutChart',
@@ -76,7 +79,9 @@ protected function getStub(): string
7679
$directory = 'Json';
7780
}
7881

79-
return base_path("stubs/charts/{$directory}/{$this->selectedChart}.stub");
82+
$stub = "{$directory}/{$this->selectedChart}.stub";
83+
84+
return $this->resolveStubPath($stub);
8085
}
8186

8287
/**

src/LarapexChart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct()
5656
$this->zoom = json_encode(['enabled' => true]);
5757
$this->dataLabels = json_encode(['enabled' => false]);
5858
$this->sparklines = json_encode(['enabled' => false]);
59-
$this->fontFamily = json_encode(config('larapex-charts.font_family'));
59+
$this->fontFamily = config('larapex-charts.font_family');
6060
$this->foreColor = config('larapex-charts.font_color');
6161
return $this;
6262
}

src/LarapexChartsServiceProvider.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public function register()
2222
});
2323

2424
$this->mergeConfigFrom($this->packageBasePath('config/larapex-charts.php'), 'larapex-charts');
25+
26+
$this->commands([
27+
\ArielMejiaDev\LarapexCharts\Console\ChartMakeCommand::class,
28+
]);
2529
}
2630

2731
/**
@@ -45,11 +49,9 @@ public function boot()
4549
$this->packageBasePath('config/larapex-charts.php') => base_path('config/larapex-charts.php')
4650
], 'larapex-charts-config');
4751

48-
// Publishing commands
49-
(new Filesystem)->copyDirectory(__DIR__.'/../stubs/Console/Commands', app_path('Console/Commands'));
50-
51-
// Publishing stubs
52-
(new Filesystem)->copyDirectory(__DIR__.'/../stubs/stubs', base_path('stubs'));
52+
$this->publishes([
53+
$this->packageBasePath('stubs/stubs') => base_path('stubs')
54+
], 'larapex-charts-stubs');
5355

5456
}
5557

src/Traits/WithModelStub.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace ArielMejiaDev\LarapexCharts\Traits;
4+
5+
trait WithModelStub
6+
{
7+
protected function resolveStubPath($stub)
8+
{
9+
$customPath = base_path("stubs/charts/{$stub}");
10+
11+
$packagePath = __DIR__ . "/../stubs/charts/{$stub}";
12+
13+
return file_exists($customPath) ? $customPath : $packagePath;
14+
}
15+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\AreaChart
17+
{
18+
return $this->chart->areaChart()
19+
->setTitle('Sales during 2021.')
20+
->setSubtitle('Physical sales vs Digital sales.')
21+
->addData('Physical sales', [40, 93, 35, 42, 18, 82])
22+
->addData('Digital sales', [70, 29, 77, 28, 55, 45])
23+
->setXAxis(['January', 'February', 'March', 'April', 'May', 'June']);
24+
}
25+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\BarChart
17+
{
18+
return $this->chart->barChart()
19+
->setTitle('San Francisco vs Boston.')
20+
->setSubtitle('Wins during season 2021.')
21+
->addData('San Francisco', [6, 9, 3, 4, 10, 8])
22+
->addData('Boston', [7, 3, 8, 2, 6, 4])
23+
->setXAxis(['January', 'February', 'March', 'April', 'May', 'June']);
24+
}
25+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\DonutChart
17+
{
18+
return $this->chart->donutChart()
19+
->setTitle('Top 3 scorers of the team.')
20+
->setSubtitle('Season 2021.')
21+
->addData([20, 24, 30])
22+
->setLabels(['Player 7', 'Player 10', 'Player 9']);
23+
}
24+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\HeatMapChart
17+
{
18+
return $this->chart->heatMapChart()
19+
->setTitle('Basic radar chart')
20+
->addData('Sales', [80, 50, 30, 40, 100, 20])
21+
->addHeat('Income', [70, 10, 80, 20, 60, 40])
22+
->setMarkers(['#FFA41B', '#4F46E5'], 7, 10)
23+
->setXAxis(['January', 'February', 'March', 'April', 'May', 'June']);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\HorizontalBar
17+
{
18+
return $this->chart->horizontalBarChart()
19+
->setTitle('Los Angeles vs Miami.')
20+
->setSubtitle('Wins during season 2021.')
21+
->setColors(['#FFC107', '#D32F2F'])
22+
->addData('San Francisco', [6, 9, 3, 4, 10, 8])
23+
->addData('Boston', [7, 3, 8, 2, 6, 4])
24+
->setXAxis(['January', 'February', 'March', 'April', 'May', 'June']);
25+
}
26+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\LineChart
17+
{
18+
return $this->chart->lineChart()
19+
->setTitle('Sales during 2021.')
20+
->setSubtitle('Physical sales vs Digital sales.')
21+
->addData('Physical sales', [40, 93, 35, 42, 18, 82])
22+
->addData('Digital sales', [70, 29, 77, 28, 55, 45])
23+
->setXAxis(['January', 'February', 'March', 'April', 'May', 'June']);
24+
}
25+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\PieChart
17+
{
18+
return $this->chart->pieChart()
19+
->setTitle('Top 3 scorers of the team.')
20+
->setSubtitle('Season 2021.')
21+
->addData([40, 50, 30])
22+
->setLabels(['Player 7', 'Player 10', 'Player 9']);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\PolarAreaChart
17+
{
18+
return $this->chart
19+
->polarAreaChart()
20+
->setTitle('Top 3 scorers of the team.')
21+
->setSubtitle('Season 2021.')
22+
->addData([20, 24, 30])
23+
->setLabels(['Player 7', 'Player 10', 'Player 9']);
24+
}
25+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\RadarChart
17+
{
18+
return $this->chart->radarChart()
19+
->setTitle('Individual Player Stats.')
20+
->setSubtitle('Season 2021.')
21+
->addData('Stats', [70, 93, 78, 97, 50, 90])
22+
->setXAxis(['Pass', 'Dribble', 'Shot', 'Stamina', 'Long shots', 'Tactical'])
23+
->setMarkers(['#303F9F'], 7, 10);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \ArielMejiaDev\LarapexCharts\RadialChart
17+
{
18+
return $this->chart->radialChart()
19+
->setTitle('Passing effectiveness.')
20+
->setSubtitle('Barcelona city vs Madrid sports.')
21+
->addData([75, 60])
22+
->setLabels(['Barcelona city', 'Madrid sports'])
23+
->setColors(['#D32F2F', '#03A9F4']);
24+
}
25+
}

src/stubs/charts/Json/AreaChart.stub

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use ArielMejiaDev\LarapexCharts\LarapexChart;
6+
7+
class {{ class }}
8+
{
9+
protected $chart;
10+
11+
public function __construct(LarapexChart $chart)
12+
{
13+
$this->chart = $chart;
14+
}
15+
16+
public function build(): \Illuminate\Http\JsonResponse
17+
{
18+
return $this->chart->areaChart()
19+
->setTitle('Sales during 2021.')
20+
->setSubtitle('Physical sales vs Digital sales.')
21+
->addData('Physical sales', [40, 93, 35, 42, 18, 82])
22+
->addData('Digital sales', [70, 29, 77, 28, 55, 45])
23+
->setXAxis(['January', 'February', 'March', 'April', 'May', 'June'])
24+
->toJson();
25+
}
26+
}

0 commit comments

Comments
 (0)