composer update

This commit is contained in:
2019-06-23 10:14:30 +00:00
parent a56db5ea2b
commit ec4506ebf4
790 changed files with 35767 additions and 7663 deletions
+2
View File
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
+1
View File
@@ -0,0 +1 @@
.DS_Store
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) Èrik Campobadal Forés <soc@erik.cat>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+28
View File
@@ -0,0 +1,28 @@
<p align="center"><a href="https://charts.erik.cat"><img src="https://i.gyazo.com/b33ab534d6fdfa7d4eba2abd91a155c3.png"></a></p>
<p align="center">
<a href="https://styleci.io/repos/69124179"><img src="https://styleci.io/repos/69124179/shield?branch=master&style=flat" alt="StyleCI Status"></a>
<a class="badge-align" href="https://www.codacy.com/app/consoletvs/Charts?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ConsoleTVs/Charts&amp;utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/b96ce6dd50de4a69ba191336a04a59e5"/></a>
<a href="https://styleci.io/repos/69124179"><img src="https://img.shields.io/badge/Built_for-Laravel-orange.svg" alt="Build For Laravel"></a>
<a href="https://packagist.org/packages/consoletvs/charts"><img src="https://poser.pugx.org/consoletvs/charts/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/consoletvs/charts"><img src="https://poser.pugx.org/consoletvs/charts/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/consoletvs/charts"><img src="https://poser.pugx.org/consoletvs/charts/license.svg" alt="License"></a>
</p>
## What is charts?
Charts is a PHP (Laravel) library to handle all the charts in your application. It supports multiple
charting libraries and they allow to be loaded over AJAX with a nice loading animation.
It uses a simple API to create all the JS logic for you. You just need to write a few PHP lines :)
## Documentation
The documentation for the latest version of charts can be found here by pressing the image below.
<p align="center"><a href="https://charts.erik.cat"><img height="250" src="https://i.imgur.com/F0PDyYE.png"></a></p>
## Example screenshot
A sample screenshot of a chartjs chart created using Charts.
<p align="center"><img src="https://image.prntscr.com/image/FDJCr7ywShKMUlFitEc_Ww.png"></p>
+31
View File
@@ -0,0 +1,31 @@
{
"name": "consoletvs/charts",
"description": "The laravel charting package",
"license": "MIT",
"type": "library",
"require": {
"php": ">=7.0",
"illuminate/support": "5.*",
"illuminate/console": "5.*",
"balping/json-raw-encoder": "^1.0"
},
"authors": [
{
"name": "Èrik Campobadal Forés ",
"email": "soc@erik.cat"
}
],
"autoload": {
"psr-4": {
"ConsoleTVs\\Charts\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"ConsoleTVs\\Charts\\ChartsServiceProvider"
]
}
},
"minimum-stability": "dev"
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace ConsoleTVs\Charts;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
class ChartsServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot(Router $router)
{
$this->publishes([
__DIR__.'/Config/charts.php' => config_path('charts.php'),
], 'charts_config');
$this->loadViewsFrom(__DIR__.'/Views', 'charts');
$this->publishes([
__DIR__.'/Views' => resource_path('views/vendor/charts'),
]);
if ($this->app->runningInConsole()) {
$this->commands([
\ConsoleTVs\Charts\Commands\ChartsCommand::class,
]);
}
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/Config/charts.php',
'charts'
);
}
}
+542
View File
@@ -0,0 +1,542 @@
<?php
namespace ConsoleTVs\Charts\Classes;
use Balping\JsonRaw\Encoder;
use Balping\JsonRaw\Raw;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\View;
class BaseChart
{
/**
* Stores the chart ID.
*
* @var string
*/
public $id;
/**
* Stores the chart datasets.
*
* @var array
*/
public $datasets = [];
/**
* Stores the dataset class to be used.
*
* @var object
*/
protected $dataset = DatasetClass::class;
/**
* Stores the chart labels.
*
* @var array
*/
public $labels = [];
/**
* Stores the chart container.
*
* @var string
*/
public $container = '';
/**
* Stores the chart options.
*
* @var array
*/
public $options = [];
/**
* Stores the plugins options.
*
* @var array
*/
public $plugins = [];
/**
* Stores the plugin views.
*
* @var array
*/
public $pluginsViews = [];
/**
* Stores the chart script.
*
* @var string
*/
public $script = '';
/**
* Stores the chart type.
*
* @var string
*/
public $type = '';
/**
* Stores the API url if the chart is loaded over API.
*
* @var string
*/
public $api_url = '';
/**
* Determines if the loader is show.
*
* @var bool
*/
public $loader = true;
/**
* Determines if the loader color.
*
* @var string
*/
public $loaderColor = '#22292F';
/**
* Stores the height of the chart.
*
* @var int
*/
public $height = 400;
/**
* Stores the width of the chart.
*
* @var int
*/
public $width = null;
/**
* Stores the available chart letters to create the ID.
*
* @var array
*/
public $scriptAttributes = [
'type' => 'text/javascript',
];
/**
* Stores the available chart letters to create the ID.
*
* @var string
*/
private $chartLetters = 'abcdefghijklmnopqrstuvwxyz';
/**
* Chart constructor.
*/
public function __construct()
{
$this->id = substr(str_shuffle(str_repeat($x = $this->chartLetters, ceil(25 / strlen($x)))), 1, 25);
}
/**
* Adds a new dataset to the chart.
*
* @param string $name
* @param array|Collection $data
*/
public function dataset(string $name, string $type, $data)
{
if ($data instanceof Collection) {
$data = $data->toArray();
}
$dataset = new $this->dataset($name, $type, $data);
array_push($this->datasets, $dataset);
return $dataset;
}
/**
* Set the chart labels.
*
* @param array|Collection $labels
*
* @return self
*/
public function labels($labels)
{
if ($labels instanceof Collection) {
$labels = $labels->toArray();
}
$this->labels = $labels;
return $this;
}
/**
* Set the chart options.
*
* @param array|Collection $options
* @param bool $overwrite
*
* @return self
*/
public function options($options, bool $overwrite = false)
{
if (!empty($options['plugins'])) {
$options['plugins'] = new Raw(trim(preg_replace('/\s\s+/', ' ', $options['plugins'])));
}
if ($options instanceof Collection) {
$options = $options->toArray();
}
if ($overwrite) {
$this->options = $options;
} else {
$this->options = array_replace_recursive($this->options, $options);
}
return $this;
}
/**
* Set the plugins options.
*
* @param array|Collection $options
* @param bool $overwrite
*
* @return self
*/
public function plugins($plugins, bool $overwrite = true)
{
if ($plugins instanceof Collection) {
$plugins = $plugins->toArray();
}
if ($overwrite) {
$this->plugins = $plugins;
} else {
$this->plugins = array_replace_recursive($this->plugins, $plugins);
}
return $this;
}
/**
* Set the chart container.
*
* @param string $container
*
* @return self
*/
public function container(string $container = null)
{
if (!$container) {
return View::make($this->container, ['chart' => $this]);
}
$this->container = $container;
return $this;
}
/**
* Set the chart script.
*
* @param string $script
*
* @return self
*/
public function script(string $script = null)
{
if (count($this->datasets) == 0 && !$this->api_url) {
throw new \Exception('No datasets provided, please provide at least one dataset to generate a chart');
}
if (!$script) {
return View::make($this->script, ['chart' => $this]);
}
$this->script = $script;
return $this;
}
/**
* Set the chart type.
*
* @param string $type
*
* @return self
*/
public function type(string $type)
{
$this->type = $type;
return $this;
}
/**
* Set the chart height.
*
* @param int $height
*
* @return self
*/
public function height(int $height)
{
$this->height = $height;
return $this;
}
/**
* Set the chart width.
*
* @param int $width
*
* @return self
*/
public function width(int $width)
{
$this->width = $width;
return $this;
}
/**
* Formats the type to be a correct output.
*
* @return string
*/
public function formatType()
{
return $this->type ? $this->type : $this->datasets[0]->type;
}
/**
* Formats the labels to be a correct output.
*
* @return string
*/
public function formatLabels()
{
return Encoder::encode($this->labels);
}
/**
* Formats the chart options.
*
* @param bool $strict
*
* @return string
*/
public function formatOptions(bool $strict = false, bool $noBraces = false)
{
if (!$strict && count($this->options) === 0) {
return '';
}
$options = Encoder::encode($this->options);
return $noBraces ? substr($options, 1, -1) : $options;
}
/**
* Formats the plugins options.
*
* @param bool $strict
*
* @return string
*/
public function formatPlugins(bool $strict = false, bool $noBraces = false)
{
if (!$strict && count($this->plugins) === 0) {
return '';
}
$plugins = str_replace('"', '', Encoder::encode($this->plugins));
return $noBraces ? substr($plugins, 1, -1) : $plugins;
}
/**
* Use this to pass values to json without any modification
* Useful for defining callbacks.
*
* @param string $value
*
* @return \Balping\JsonRaw\Raw
*/
public function rawObject(string $value)
{
return new Raw($value);
}
/**
* Reset the chart options.
*
* @return self
*/
public function reset()
{
return $this->options([], true);
}
/**
* Formats the datasets for the output.
*
* @return string
*/
public function formatDatasets()
{
// This little boy was commented because it's not compatible
// in laravel < 5.4
//
// return Collection::make($this->datasets)
// ->each
// ->matchValues(count($this->labels))
// ->map
// ->format($this->labels)
// ->toJson();
return Encoder::encode(
Collection::make($this->datasets)
->each(function ($dataset) {
$dataset->matchValues(count($this->labels));
})
->map(function ($dataset) {
return $dataset->format($this->labels);
})
->toArray()
);
}
/**
* Indicates that the chart information will be loaded over API.
*
* @param string $api_url
*
* @return self
*/
public function load(string $api_url)
{
$this->api_url = $api_url;
return $this;
}
/**
* Determines if the chart should show a loader.
*
* @param bool $loader
*
* @return self
*/
public function loader(bool $loader)
{
$this->loader = $loader;
return $this;
}
/**
* Determines the loader color.
*
* @param string $color
*
* @return self
*/
public function loaderColor(string $color)
{
$this->loaderColor = $color;
return $this;
}
/**
* Alias for the formatDatasets() method.
*
* @return string
*/
public function api()
{
return $this->formatDatasets();
}
/**
* Sets an HTML attribute the the script tag of the chart.
*
* @param string $key
* @param string $value
*
* @return self
*/
public function setScriptAttribute(string $key, string $value)
{
$this->scriptAttributes[$key] = $value;
return $this;
}
/**
* Returns the string formatting of the script attributes.
*
* @return string
*/
public function displayScriptAttributes(): string
{
$result = '';
foreach ($this->scriptAttributes as $key => $value) {
echo " {$key}=\"{$value}\"";
}
return $result;
}
/**
* Formats the container options.
*
* @param string $type
* @param bool $maxIfNull
*
* @return string
*/
public function formatContainerOptions(string $type = 'css', bool $maxIfNull = false)
{
$options = '';
$height = ($maxIfNull && !$this->height) ? '100%' : $this->height;
$width = ($maxIfNull && !$this->width) ? '100%' : $this->width;
switch ($type) {
case 'css':
$options .= " style='";
(!$height) ?: $options .= "height: {$height}px !important;";
(!$width) ?: $options .= "width: {$width}px !important;";
$options .= "' ";
break;
case 'js':
if ($height) {
if (is_int($height)) {
$options .= "height: {$height}, ";
} else {
$options .= "height: '{$height}', ";
}
}
if ($width) {
if (is_int($width)) {
$options .= "width: {$width}, ";
} else {
$options .= "width: '{$width}', ";
}
}
break;
default:
(!$height) ?: $options .= " height='{$this->height}' ";
(!$this->width) ?: $options .= " width='{$this->width}' ";
}
return $options;
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace ConsoleTVs\Charts\Classes\C3;
use ConsoleTVs\Charts\Classes\BaseChart;
use ConsoleTVs\Charts\Features\C3\Chart as ChartFeatures;
use Illuminate\Support\Collection;
class Chart extends BaseChart
{
use ChartFeatures;
/**
* C3 dataset class.
*
* @var object
*/
public $dataset = Dataset::class;
/**
* Initiates the C3 Line Chart.
*
* @return self
*/
public function __construct()
{
parent::__construct();
$this->container = 'charts::c3.container';
$this->script = 'charts::c3.script';
return $this;
}
/**
* Formats the datasets.
*
* @return void
*/
public function formatDatasets()
{
$datasets = Collection::make($this->datasets);
return json_encode([
'columns' => Collection::make($this->datasets)
->each(function ($dataset) {
$dataset->matchValues(count($this->labels));
})
->map(function ($dataset) {
return $dataset->format($this->labels);
})
->toArray(),
'type' => $datasets->first()->type,
'types' => $datasets->mapWithKeys(function ($d) {
return [$d->name => $d->type];
})->toArray(),
]);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace ConsoleTVs\Charts\Classes\C3;
use ConsoleTVs\Charts\Classes\DatasetClass;
use ConsoleTVs\Charts\Features\C3\Dataset as DatasetFeatures;
class Dataset extends DatasetClass
{
use DatasetFeatures;
/**
* Creates a new dataset with the given values.
*
* @param string $name
* @param string $type
* @param array $values
*/
public function __construct(string $name, string $type, array $values)
{
parent::__construct($name, $type, $values);
}
/**
* Formats the dataset for chartjs.
*
* @return array
*/
public function format()
{
return array_merge([$this->name], $this->values);
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace ConsoleTVs\Charts\Classes\Chartjs;
use ConsoleTVs\Charts\Classes\BaseChart;
use ConsoleTVs\Charts\Features\Chartjs\Chart as ChartFeatures;
class Chart extends BaseChart
{
use ChartFeatures;
/**
* Chartjs dataset class.
*
* @var object
*/
public $dataset = Dataset::class;
/**
* Initiates the Chartjs Line Chart.
*
* @return self
*/
public function __construct()
{
parent::__construct();
$this->container = 'charts::chartjs.container';
$this->script = 'charts::chartjs.script';
return $this->options([
'maintainAspectRatio' => false,
'scales' => [
'xAxes' => [],
'yAxes' => [
[
'ticks' => [
'beginAtZero' => true,
],
],
],
],
]);
}
}
@@ -0,0 +1,41 @@
<?php
namespace ConsoleTVs\Charts\Classes\Chartjs;
use ConsoleTVs\Charts\Classes\DatasetClass;
use ConsoleTVs\Charts\Features\Chartjs\Dataset as DatasetFeatures;
class Dataset extends DatasetClass
{
use DatasetFeatures;
/**
* Creates a new dataset with the given values.
*
* @param string $name
* @param string $type
* @param array $values
*/
public function __construct(string $name, string $type, array $values)
{
parent::__construct($name, $type, $values);
$this->options([
'borderWidth' => 2,
]);
}
/**
* Formats the dataset for chartjs.
*
* @return array
*/
public function format()
{
return array_merge($this->options, [
'data' => $this->values,
'label' => $this->name,
'type' => $this->type,
]);
}
}
+129
View File
@@ -0,0 +1,129 @@
<?php
namespace ConsoleTVs\Charts\Classes;
use Illuminate\Support\Collection;
class DatasetClass
{
/**
* Defines the name of the dataset.
*
* @var string
*/
public $name = 'Undefined';
/**
* Defines the dataset type.
*
* @var string
*/
public $type = '';
/**
* Stores the dataset values.
*
* @var array
*/
public $values = [];
/**
* Stores the dataset options.
*
* @var array
*/
public $options = [];
/**
* Defines the undefined color.
*
* @var string
*/
public $undefinedColor = '#22292F';
/**
* Creates a new dataset with the given values.
*
* @param string $name
* @param string $type
* @param array $values
*/
public function __construct(string $name, string $type, array $values)
{
$this->name = $name;
$this->type = $type;
$this->values = $values;
return $this;
}
/**
* Set the dataset type.
*
* @param string $type
*
* @return self
*/
public function type(string $type)
{
$this->type = $type;
return $this;
}
/**
* Set the dataset values.
*
* @param array|Collection $values
*
* @return self
*/
public function values($values)
{
if ($values instanceof Collection) {
$values = $values->toArray();
}
$this->values = $values;
return $this;
}
/**
* Set the dataset options.
*
* @param array|Collection $options
* @param bool $overwrite
*
* @return self
*/
public function options($options, bool $overwrite = false)
{
if ($overwrite) {
$this->options = $options;
} else {
$this->options = array_replace_recursive($this->options, $options);
}
return $this;
}
/**
* Matches the values of the dataset with the given number.
*
* @param int $values
* @param bool $strict
*
* @return void
*/
public function matchValues(int $values, bool $strict = false)
{
while (count($this->values) < $values) {
array_push($this->values, 0);
}
if ($strict) {
$this->values = array_slice($this->values, 0, $values);
}
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace ConsoleTVs\Charts\Classes\Echarts;
use ConsoleTVs\Charts\Classes\BaseChart;
use ConsoleTVs\Charts\Features\Echarts\Chart as ChartFeatures;
class Chart extends BaseChart
{
use ChartFeatures;
/**
* Chartjs dataset class.
*
* @var object
*/
public $dataset = Dataset::class;
/**
* Store the theme for the chart.
*
* @var string
*/
public $theme = 'default';
/**
* Initiates the Chartjs Line Chart.
*
* @return self
*/
public function __construct()
{
parent::__construct();
$this->container = 'charts::echarts.container';
$this->script = 'charts::echarts.script';
return $this->options([
'legend' => [
'show' => true,
],
'tooltip' => [
'show' => true,
],
'xAxis' => [
'show' => true,
],
'yAxis' => [
'show' => true,
],
]);
}
/**
* Formats the options.
*
* @return self
*/
public function formatOptions(bool $strict = false, bool $noBraces = false)
{
$this->options([
'xAxis' => [
'data' => json_decode($this->formatLabels()),
],
]);
return parent::formatOptions($strict, $noBraces);
}
}
@@ -0,0 +1,67 @@
<?php
namespace ConsoleTVs\Charts\Classes\Echarts;
use ConsoleTVs\Charts\Classes\DatasetClass;
use ConsoleTVs\Charts\Features\Echarts\Dataset as DatasetFeatures;
use Illuminate\Support\Collection;
class Dataset extends DatasetClass
{
use DatasetFeatures;
/**
* Store the private datasets that contains a special formating.
*
* @var array
*/
public $specialDatasets = ['pie'];
/**
* Creates a new dataset with the given values.
*
* @param string $name
* @param string $type
* @param array $values
*/
public function __construct(string $name, string $type, array $values)
{
parent::__construct($name, $type, $values);
}
/**
* Formats the dataset for chartjs.
*
* @return array
*/
public function format(array $labels = [])
{
return array_merge($this->options, [
'data' => $this->getValues($labels),
'name' => $this->name,
'type' => strtolower($this->type),
]);
}
/**
* Get the formated values.
*
* @param array $labels
*
* @return array
*/
protected function getValues(array $labels)
{
if (in_array(strtolower($this->type), $this->specialDatasets)) {
return Collection::make($this->values)
->map(function ($value, $key) use ($labels) {
return [
'name' => $labels[$key],
'value' => $value,
];
})->toArray();
}
return $this->values;
}
}
+85
View File
@@ -0,0 +1,85 @@
<?php
namespace ConsoleTVs\Charts\Classes\Frappe;
use ConsoleTVs\Charts\Classes\BaseChart;
use ConsoleTVs\Charts\Features\Frappe\Chart as ChartFeatures;
class Chart extends BaseChart
{
use ChartFeatures;
/**
* Frappe dataset class.
*
* @var object
*/
public $dataset = Dataset::class;
/**
* Stores the default colors.
*
* @var array
*/
public $default_colors = [
'#E3342F', '#F6993F', '#FFED4A', '#38C172', '#4DC0B5', '#3490DC', '#6574CD', '#9561E2', '#F66D9B',
];
/**
* Determines the special charts.
*
* @var array
*/
public $special_datasets = [
'pie', 'percentage',
];
/**
* Initiates the Frappe Chart.
*
* @return self
*/
public function __construct()
{
parent::__construct();
$this->container = 'charts::frappe.container';
$this->script = 'charts::frappe.script';
return $this->options([
'barOptions' => [
'spaceRatio' => 0.75,
],
]);
}
/**
* Format the datasets.
*
* @param bool $strict
* @param bool $noBraces
*
* @return self
*/
public function formatOptions(bool $strict = false, bool $noBraces = false)
{
$colors = [];
$default = 0;
foreach ($this->datasets as $dataset) {
$color = $this->default_colors[$default];
if (array_key_exists('color', $dataset->options)) {
$color = $dataset->options['color'];
unset($dataset->options['color']);
} else {
$default++;
}
array_push($colors, $color);
}
$this->options([
'colors' => $colors,
]);
return parent::formatOptions($strict, $noBraces);
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace ConsoleTVs\Charts\Classes\Frappe;
use ConsoleTVs\Charts\Classes\DatasetClass;
use ConsoleTVs\Charts\Features\Frappe\Dataset as DatasetFeatures;
class Dataset extends DatasetClass
{
use DatasetFeatures;
/**
* Creates a new dataset with the given values.
*
* @param string $name
* @param string $type
* @param array $values
*/
public function __construct(string $name, string $type, array $values)
{
parent::__construct($name, $type, $values);
$this->options([]);
}
/**
* Formats the dataset for chartjs.
*
* @return array
*/
public function format()
{
return array_merge($this->options, [
'values' => $this->values,
'name' => $this->name,
'chartType' => $this->type,
]);
}
}
@@ -0,0 +1,82 @@
<?php
namespace ConsoleTVs\Charts\Classes\Fusioncharts;
use ConsoleTVs\Charts\Classes\BaseChart;
use ConsoleTVs\Charts\Features\Fusioncharts\Chart as ChartFeatures;
use Illuminate\Support\Collection;
class Chart extends BaseChart
{
use ChartFeatures;
/**
* Chartjs dataset class.
*
* @var object
*/
public $dataset = Dataset::class;
/**
* Theese array stores the types that are maintained to fusioncharts.
*
* @var array
*/
public $keepType = ['pie2d', 'doughnut2d'];
/**
* Determines the combo type of chart.
*
* @var array
*/
public $comboType = 'mscombi2d';
/**
* Initiates the Chartjs Line Chart.
*
* @return self
*/
public function __construct()
{
parent::__construct();
$this->container = 'charts::fusioncharts.container';
$this->script = 'charts::fusioncharts.script';
return $this->options([
'bgColor' => '#ffffff',
'borderAlpha' => 0,
'canvasBorderAlpha' => 0,
'usePlotGradientColor' => false,
'plotBorderAlpha' => 0,
'divlineColor' => '#22292F',
'divLineIsDashed' => true,
'showAlternateHGridColor' => false,
'captionFontBold' => true,
'captionFontSize' => 14,
'subcaptionFontBold' => false,
'subcaptionFontSize' => 14,
'legendBorderAlpha' => 0,
'legendShadow' => 0,
'hoverfillcolor' => '#CCCCCC',
'piebordercolor' => '#FFFFFF',
'hoverfillcolor' => '#CCCCCC',
'use3DLighting' => false,
'showShadow' => false,
]);
}
/**
* Formats the labels for fusioncharts.
*
* @return string
*/
public function formatLabels()
{
return Collection::make($this->labels)
->map(function ($label) {
return ['label' => $label];
})
->toJson();
}
}
@@ -0,0 +1,98 @@
<?php
namespace ConsoleTVs\Charts\Classes\Fusioncharts;
use ConsoleTVs\Charts\Classes\DatasetClass;
use ConsoleTVs\Charts\Features\Fusioncharts\Dataset as DatasetFeatures;
use Illuminate\Support\Collection;
class Dataset extends DatasetClass
{
use DatasetFeatures;
/**
* Store the private datasets that contains a special formating.
*
* @var array
*/
public $specialDatasets = ['pie2d', 'doughnut2d'];
/**
* Creates a new dataset with the given values.
*
* @param string $name
* @param string $type
* @param array $values
*/
public function __construct(string $name, string $type, array $values)
{
parent::__construct($name, $type, $values);
}
/**
* Dataset representation.
*
* @var array
*/
public function format(array $labels = [])
{
return array_merge($this->options, [
'data' => $this->formatValues($labels),
'seriesName' => $this->name,
'renderAs' => strtolower($this->type),
]);
}
/**
* Formats the chart values.
*
* @param array $labels
*
* @return array
*/
protected function formatValues(array $labels)
{
$values = Collection::make($this->values);
if (in_array(strtolower($this->type), $this->specialDatasets)) {
$colors = $this->getColors($labels);
return $values->map(function ($value, $key) use ($colors, $labels) {
$val = [
'label' => $labels[$key],
'value' => $value,
];
if ($colors->count() > 0) {
$val['color'] = $colors->get($key);
}
return $val;
})->toArray();
}
return $values->map(function ($value) {
return [
'value' => $value,
];
})->toArray();
}
/**
* Get the chart colors.
*
* @param array $labels
*
* @return Collection
*/
protected function getColors(array $labels)
{
$colors = Collection::make(array_key_exists('color', $this->options) ? $this->options['color'] : []);
while ($colors->count() < count($labels)) {
$colors->push($this->undefinedColor);
}
return $colors;
}
}
@@ -0,0 +1,56 @@
<?php
namespace ConsoleTVs\Charts\Classes\Highcharts;
use ConsoleTVs\Charts\Classes\BaseChart;
use ConsoleTVs\Charts\Features\Highcharts\Chart as ChartFeatures;
class Chart extends BaseChart
{
use ChartFeatures;
/**
* Chartjs dataset class.
*
* @var object
*/
public $dataset = Dataset::class;
/**
* Initiates the Highcharts Line Chart.
*
* @return self
*/
public function __construct()
{
parent::__construct();
$this->container = 'charts::highcharts.container';
$this->script = 'charts::highcharts.script';
return $this->options([
'credits' => [
'enabled' => false,
],
'title' => [
'text' => null,
],
]);
}
/**
* Format the options for highcharts.
*
* @return string
*/
public function formatOptions(bool $strict = false, bool $noBraces = false)
{
$this->options([
'xAxis' => [
'categories' => json_decode($this->formatLabels()),
],
]);
return parent::formatOptions($strict, $noBraces);
}
}
@@ -0,0 +1,93 @@
<?php
namespace ConsoleTVs\Charts\Classes\Highcharts;
use ConsoleTVs\Charts\Classes\DatasetClass;
use ConsoleTVs\Charts\Features\Highcharts\Dataset as DatasetFeatures;
use Illuminate\Support\Collection;
class Dataset extends DatasetClass
{
use DatasetFeatures;
/**
* Store the private datasets that contains a special formating.
*
* @var array
*/
public $specialDatasets = ['pie'];
/**
* Creates a new dataset with the given values.
*
* @param string $name
* @param string $type
* @param array $values
*/
public function __construct(string $name, string $type, array $values)
{
parent::__construct($name, $type, $values);
}
/**
* Dataset representation.
*
* @var array
*/
public function format(array $labels = [])
{
return array_merge($this->options, [
'data' => $this->formatValues($labels),
'name' => $this->name,
'type' => strtolower($this->type),
]);
}
/**
* Formats the values.
*
* @param array $labels
*
* @return array
*/
protected function formatValues(array $labels)
{
if (in_array(strtolower($this->type), $this->specialDatasets)) {
$colors = $this->getColors($labels);
return Collection::make($this->values)
->map(function ($value, $key) use ($colors, $labels) {
$val = [
'name' => $labels[$key],
'y' => $value,
];
if ($colors->count() > 0) {
$val['color'] = $colors->get($key);
}
return $val;
})->toArray();
}
return $this->values;
}
/**
* Get the dataset colors;.
*
* @param array $labels
*
* @return Collection
*/
protected function getColors(array $labels)
{
$colors = Collection::make(array_key_exists('color', $this->options) ? $this->options['color'] : []);
while ($colors->count() < count($labels)) {
$colors->push($this->undefinedColor);
}
return $colors;
}
}
+3
View File
@@ -0,0 +1,3 @@
# Charts Classes
All the charts classes are located in this folder
+133
View File
@@ -0,0 +1,133 @@
<?php
namespace ConsoleTVs\Charts\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputArgument;
class ChartsCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:chart';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a new chart';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Chart';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/chart.stub';
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->line('[Charts] Creating chart...');
$this->handleParentMethodCall();
$name = $this->qualifyClass($this->getNameInput());
$path = $this->getPath($name);
$this->info("[Charts] Chart created! - Location: {$path}");
}
/**
* Build the class with the given name.
*
* @param string $name
*
* @return string
*/
protected function buildClass($name)
{
$stub = parent::buildClass($name);
return str_replace(
['Library'],
[$this->argument('library') ? ucfirst($this->argument('library')) : ucfirst(config('charts.default_library'))],
$stub
);
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Charts';
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the chart file'],
['library', InputArgument::OPTIONAL, 'Library of the chart'],
];
}
/**
* Calls the right parent method depending on laravel version.
* Adds support for Laravel v5.4.
*
* @return void
*/
protected function handleParentMethodCall()
{
if (!is_callable('parent::handle')) {
return parent::fire();
}
parent::handle();
}
/**
* Qualifies the class name by delegating to the right parent method.
*
* @param string $name
*
* @return string
*/
protected function qualifyClass($name)
{
if (!is_callable('parent::qualifyClass')) {
return parent::parseName($name);
}
return parent::qualifyClass($name);
}
}
+3
View File
@@ -0,0 +1,3 @@
# Charts Commands
All the charts commands are located in this folder
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace DummyNamespace;
use ConsoleTVs\Charts\Classes\Library\Chart;
class DummyClass extends Chart
{
/**
* Initializes the chart.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default library used in charts.
|--------------------------------------------------------------------------
|
| This value is used as the default chart library used when creating
| any chart in the command line. Feel free to modify it or set it up
| while creating the chart to ignore this value.
|
*/
'default_library' => 'Chartjs',
];
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace ConsoleTVs\Charts\Features\C3;
trait Chart
{
/**
* Determines if the chart legend will be displayed.
*
* @param bool $display
*
* @return self
*/
public function legend(bool $display)
{
return $this->options([
'legend' => [
'show' => $display,
],
]);
}
/**
* Determines if the chart grid will be shown.
*
* @param bool $display
*
* @return self
*/
public function grid(bool $display)
{
return $this->options([
'grid' => [
'x' => [
'show' => $display,
],
'y' => [
'show' => $display,
],
],
]);
}
/**
* Determines if the chart tooltip will be shown.
*
* @param bool $display
*
* @return self
*/
public function tooltip(bool $display)
{
return $this->options([
'tooltip' => [
'show' => $display,
],
]);
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace ConsoleTVs\Charts\Features\C3;
trait Dataset
{
//
}
+117
View File
@@ -0,0 +1,117 @@
<?php
namespace ConsoleTVs\Charts\Features\Chartjs;
trait Chart
{
/**
* Minalist chart display (Hide labels and axes).
*
* @return self
*/
public function minimalist(bool $display)
{
$this->displayLegend(!$display);
return $this->displayAxes(!$display);
}
/**
* Display the chart legend.
*
* @param bool $legend
*
* @return self
*/
public function displayLegend(bool $legend)
{
return $this->options([
'legend' => [
'display' => $legend,
],
]);
}
/**
* Display the chart axis.
*
* @param bool $axes
*
* @return self
*/
public function displayAxes(bool $axes, bool $strict = false)
{
if ($strict) {
return $this->options([
'scale' => [
'display' => $axes,
],
]);
}
return $this->options([
'scales' => [
'xAxes' => [
[
'display' => $axes,
],
],
'yAxes' => [
[
'display' => $axes,
],
],
],
]);
}
/**
* Set the bar width of the X Axis.
*
* @param float $width
*
* @return self
*/
public function barWidth(float $width)
{
return $this->options([
'scales' => [
'xAxes' => [
[
'barPercentage' => $width,
],
],
],
]);
}
/**
* Set the chart title.
*
* @param string $title
* @param int $font_size
* @param string $color
* @param string $font_weight
* @param string $font_family
*
* @return self
*/
public function title(
string $title,
int $font_size = 14,
string $color = '#666',
string $font_weight = 'bold',
string $font_family = "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"
) {
return $this->options([
'title' => [
'display' => true,
'fontFamily' => $font_family,
'fontSize' => $font_size,
'fontColor' => $color,
'fontStyle' => $font_weight,
'text' => $title,
],
]);
}
}
@@ -0,0 +1,86 @@
<?php
namespace ConsoleTVs\Charts\Features\Chartjs;
use Illuminate\Support\Collection;
trait Dataset
{
/**
* Set the dataset border color.
*
* @param string|array|Collection $color
*
* @return self
*/
public function color($color)
{
if ($color instanceof Collection) {
$color = $color->toArray();
}
return $this->options([
'borderColor' => $color,
]);
}
/**
* Set the dataset background color.
*
* @param string|array|Collection $color
*
* @return self
*/
public function backgroundColor($color)
{
if ($color instanceof Collection) {
$color = $color->toArray();
}
return $this->options([
'backgroundColor' => $color,
]);
}
/**
* Determines if the dataset is filled.
*
* @param bool $filled
*
* @return self
*/
public function fill(bool $filled)
{
return $this->options([
'fill' => $filled,
]);
}
/**
* Set the chart line tension.
*
* @param int $tension
*
* @return self
*/
public function lineTension(float $tension)
{
return $this->options([
'lineTension' => $tension,
]);
}
/**
* Set the line to a dashed line in the chart options.
*
* @param array $dashed
*
* @return self
*/
public function dashed(array $dashed = [5])
{
return $this->options([
'borderDash' => $dashed,
]);
}
}
+183
View File
@@ -0,0 +1,183 @@
<?php
namespace ConsoleTVs\Charts\Features\Echarts;
trait Chart
{
/**
* Show or hide the chart legend.
*
* @param bool $legend
*
* @return self
*/
public function displayLegend(bool $legend)
{
return $this->options([
'legend' => [
'show' => $legend,
],
]);
}
/**
* Show or hide the tooltip.
*
* @param bool $tooltip
*
* @return self
*/
public function tooltip(bool $tooltip)
{
return $this->options([
'tooltip' => [
'show' => $tooltip,
],
]);
}
/**
* Set the chart label.
*
* @param string $label
*
* @return self
*/
public function label(string $label)
{
return $this->options([
'yAxis' => [
'name' => $label,
'nameLocation' => 'middle',
],
]);
}
/**
* Show the minimalistic.
*
* @param bool $minimalist
*
* @return self
*/
public function minimalist(bool $minimalist = true)
{
$this->displayAxes(!$minimalist);
$this->displayLegend(!$minimalist);
return $this->options([
'xAxis' => [
'axisLabel' => [
'show' => !$minimalist,
],
'splitLine' => [
'show' => !$minimalist,
],
],
'yAxis' => [
'axisLabel' => [
'show' => !$minimalist,
],
'splitLine' => [
'show' => !$minimalist,
],
],
]);
}
/**
* Display the chart axes.
*
* @param bool $display
*
* @return self
*/
public function displayAxes(bool $display)
{
return $this->options([
'xAxis' => [
'show' => $display,
'axisLine' => [
'show' => $display,
],
'axisTick' => [
'show' => $display,
],
],
'yAxis' => [
'show' => $display,
'axisLine' => [
'show' => $display,
],
'axisTick' => [
'show' => $display,
],
],
]);
}
/**
* ALlow to export the chart.
*
* @return self
*/
public function export(bool $export = true, string $title = ' ')
{
return $this->options([
'toolbox' => [
'show' => true,
'feature' => [
'saveAsImage' => [
'title' => $title,
],
],
],
]);
}
/**
* Set the chart title.
*
* @param string $title
* @param int $font_size
* @param string $color
* @param bool $bold
* @param string $font_family
*
* @return self
*/
public function title(
string $title,
int $font_size = 14,
string $color = '#666',
bool $bold = true,
string $font_family = "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"
) {
return $this->options([
'title' => [
'show' => true,
'text' => $title,
'textStyle' => [
'fontFamily' => $font_family,
'fontSize' => $font_size,
'color' => $color,
'fontWeight' => $bold,
],
],
]);
}
/**
* Set the chart theme.
*
* @param string $theme
*
* @return self
*/
public function theme(string $theme)
{
$this->theme = $theme;
return $this;
}
}
@@ -0,0 +1,26 @@
<?php
namespace ConsoleTVs\Charts\Features\Echarts;
use Illuminate\Support\Collection;
trait Dataset
{
/**
* Set the dataset color.
*
* @param string|array|Collection $color
*
* @return void
*/
public function color($color)
{
if ($color instanceof Collection) {
$color = $color->toArray();
}
return $this->options([
'color' => $color,
]);
}
}
+128
View File
@@ -0,0 +1,128 @@
<?php
namespace ConsoleTVs\Charts\Features\Frappe;
trait Chart
{
/**
* Add a title to the Chart.
*
* @param string $title
*
* @return void
*/
public function title(string $title)
{
return $this->options([
'title' => $title,
]);
}
/**
* Determines the spaceRatio of the bars.
*
* @param float $space
*
* @return self
*/
public function spaceRatio(float $space = 0.75)
{
return $this->options([
'barOptions' => [
'spaceRatio' => $space,
],
]);
}
/**
* Determines if the bars are stacked.
*
* @param bool $stacked
*
* @return self
*/
public function stacked(bool $stacked)
{
return $this->options([
'barOptions' => [
'stacked' => $stacked,
],
]);
}
/**
* Makes the chart interactive with arrow keys and highlights the current active data point.
*
* @param bool $stacked
*
* @return self
*/
public function isNavigable(bool $value)
{
return $this->options([
'isNavigable' => $value,
]);
}
/**
* To display data values over bars or dots in an axis graph.
*
* @param bool $stacked
*
* @return self
*/
public function valuesOverPoints(bool $value)
{
return $this->options([
'valuesOverPoints' => $value,
]);
}
/**
* Determines if the lines will show a dot.
*
* @param bool $value
*
* @return self
*/
public function hideDots(bool $value)
{
return $this->options([
'lineOptions' => [
'hideDots' => $value,
],
]);
}
/**
* Determines if the line will be hidden.
*
* @param bool $value
*
* @return self
*/
public function hideLine(bool $value)
{
return $this->options([
'lineOptions' => [
'hideDots' => $value,
],
]);
}
/**
* Determines if the line will be a heatline.
*
* @param bool $value
*
* @return self
*/
public function heatline(bool $value)
{
return $this->options([
'lineOptions' => [
'heatline' => $value,
],
]);
}
}
@@ -0,0 +1,20 @@
<?php
namespace ConsoleTVs\Charts\Features\Frappe;
trait Dataset
{
/**
* Determines the color of the dataset.
*
* @param string $color
*
* @return self
*/
public function color(string $color)
{
return $this->options([
'color' => $color,
]);
}
}
@@ -0,0 +1,90 @@
<?php
namespace ConsoleTVs\Charts\Features\Fusioncharts;
trait Chart
{
/**
* Set the chart label.
*
* @param string $label
*
* @return self
*/
public function label(string $label)
{
return $this->options([
'yAxisName' => $label,
]);
}
/**
* Set the chart title.
*
* @param string $title
* @param int $font_size
* @param string $color
* @param bool $bold
* @param string $font_family
*
* @return self
*/
public function title(
string $title,
int $font_size = 16,
string $color = '#3D4852',
bool $bold = true,
string $font_family = "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"
) {
return $this->options([
'caption' => $title,
'captionFontSize' => $font_size,
'captionFontColor' => $color,
'captionFontBold' => $bold,
'captionFont' => $font_family,
]);
}
/**
* Set the chart subtitle.
*
* @param string $subtitle
* @param int $font_size
* @param string $color
* @param bool $bold
* @param string $font_family
*
* @return self
*/
public function subtitle(
string $subtitle,
int $font_size = 12,
string $color = '#3D4852',
bool $bold = true,
string $font_family = "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"
) {
return $this->options([
'subCaption' => $subtitle,
'subCaptionFontSize' => $font_size,
'subCaptionFontColor' => $color,
'subCaptionFontBold' => $bold,
'subCaptionFont' => $font_family,
]);
}
/**
* Determines if the chart should show the export button.
*
* @param bool $export
* @param bool $client
*
* @return self
*/
public function export(bool $export, bool $client = true)
{
return $this->options([
'exportenabled' => $export,
'exportatclient' => $client,
]);
}
}
@@ -0,0 +1,26 @@
<?php
namespace ConsoleTVs\Charts\Features\Fusioncharts;
use Illuminate\Support\Collection;
trait Dataset
{
/**
* Set the dataset color.
*
* @param string|array|Collection $color
*
* @return self
*/
public function color($color)
{
if ($color instanceof Collection) {
$color = $color->toArray();
}
return $this->options([
'color' => $color,
]);
}
}
@@ -0,0 +1,123 @@
<?php
namespace ConsoleTVs\Charts\Features\Highcharts;
trait Chart
{
/**
* Display the chart axes.
*
* @param bool $axes
*
* @return self
*/
public function displayAxes(bool $axes)
{
return $this->options([
'xAxis' => [
'visible' => $axes,
],
'yAxis' => [
'visible' => $axes,
],
]);
}
/**
* Display the legend.
*
* @param bool $legend
*
* @return self
*/
public function displayLegend(bool $legend)
{
return $this->options([
'legend' => [
'enabled' => $legend,
],
]);
}
/**
* Rotates the labels of the xAxis.
*
* @param float $angle
*
* @return self
*/
public function labelsRotation(float $angle)
{
return $this->options([
'xAxis' => [
'labels' => [
'rotation' => $angle,
],
],
]);
}
/**
* Set the chart style to minimalist.
*
* @param bool $display
*
* @return self
*/
public function minimalist(bool $display = false)
{
$this->displayLegend(!$display);
return $this->displayAxes(!$display);
}
/**
* Set the highcharts yAxis label.
*
* @param string $label
*
* @return self
*/
public function label(string $label)
{
return $this->options([
'yAxis' => [
'title' => [
'text' => $label,
],
],
]);
}
/**
* Set the chart title.
*
* @param string $title
*
* @return self
*/
public function title(string $title)
{
return $this->options([
'title' => [
'text' => $title,
],
]);
}
/**
* Shapes the pie chart into a doughnut.
*
* @return self
*/
public function doughnut(int $size = 50)
{
return $this->options([
'plotOptions' => [
'pie' => [
'innerSize' => "{$size}%",
],
],
]);
}
}
@@ -0,0 +1,26 @@
<?php
namespace ConsoleTVs\Charts\Features\Highcharts;
use Illuminate\Support\Collection;
trait Dataset
{
/**
* Set the dataset color.
*
* @param string|array $color
*
* @return self
*/
public function color($color)
{
if ($color instanceof Collection) {
$color = $color->toArray();
}
return $this->options([
'color' => $color,
]);
}
}
+3
View File
@@ -0,0 +1,3 @@
# Charts Views
All the charts views are located in this folder
@@ -0,0 +1,3 @@
<div id="{{ $chart->id }}" {!! $chart->formatContainerOptions('css') !!}>
</div>
@include('charts::loader')
+29
View File
@@ -0,0 +1,29 @@
<script {!! $chart->displayScriptAttributes() !!}>
function {{ $chart->id }}_create(data) {
{{ $chart->id }}_rendered = true;
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
window.{{ $chart->id }} = c3.generate({
bindto: '#{{ $chart->id }}',
data: data,
{!! $chart->formatOptions(false, true) !!}
});
}
@if ($chart->api_url)
let {{ $chart->id }}_refresh = function (url) {
document.getElementById("{{ $chart->id }}").style.display = 'none';
document.getElementById("{{ $chart->id }}_loader").style.display = 'flex';
if (typeof url !== 'undefined') {
{{ $chart->id }}_api_url = url;
}
fetch({{ $chart->id }}_api_url)
.then(data => data.json())
.then(data => {
{{ $chart->id }}.load(data);
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
});
};
@endif
@include('charts::init')
</script>
@@ -0,0 +1,2 @@
<canvas style="display: none;" id="{{ $chart->id }}" {!! $chart->formatContainerOptions('html') !!}></canvas>
@include('charts::loader')
@@ -0,0 +1,41 @@
@foreach ($chart->plugins as $plugin)
@include($chart->pluginsViews[$plugin]);
@endforeach
<script {!! $chart->displayScriptAttributes() !!}>
var ctvChart = document.getElementById('{{ $chart->id }}').getContext('2d');
function {{ $chart->id }}_create(data) {
{{ $chart->id }}_rendered = true;
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
window.{{ $chart->id }} = new Chart(document.getElementById("{{ $chart->id }}").getContext("2d"), {
type: {!! $chart->type ? "'{$chart->type}'" : 'data[0].type' !!},
data: {
labels: {!! $chart->formatLabels() !!},
datasets: data
},
options: {!! $chart->formatOptions(true) !!},
plugins: {!! $chart->formatPlugins(true) !!}
});
}
@if ($chart->api_url)
let {{ $chart->id }}_refresh = function (url) {
document.getElementById("{{ $chart->id }}").style.display = 'none';
document.getElementById("{{ $chart->id }}_loader").style.display = 'flex';
if (typeof url !== 'undefined') {
{{ $chart->id }}_api_url = url;
}
fetch({{ $chart->id }}_api_url)
.then(data => data.json())
.then(data => {
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
{{ $chart->id }}.data.datasets = data;
{{ $chart->id }}.update();
});
};
@endif
@include('charts::init')
</script>
@@ -0,0 +1,3 @@
<div id="{{ $chart->id }}" {!! $chart->formatContainerOptions('css') !!}>
</div>
@include('charts::loader')
@@ -0,0 +1,29 @@
<script {!! $chart->displayScriptAttributes() !!}>
function {{ $chart->id }}_create(data) {
{{ $chart->id }}_rendered = true;
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
window.{{ $chart->id }} = echarts.init(document.getElementById("{{ $chart->id }}"),'{{ $chart->theme }}');
window.{{ $chart->id }}.setOption({
series: data,
{!! $chart->formatOptions(false, true) !!}
});
}
@if ($chart->api_url)
let {{ $chart->id }}_refresh = function (url) {
document.getElementById("{{ $chart->id }}").style.display = 'none';
document.getElementById("{{ $chart->id }}_loader").style.display = 'flex';
if (typeof url !== 'undefined') {
{{ $chart->id }}_api_url = url;
}
fetch({{ $chart->id }}_api_url)
.then(data => data.json())
.then(data => {
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
{{ $chart->id }}.setOption({series: data});
});
};
@endif
@include('charts::init')
</script>
@@ -0,0 +1,3 @@
<div id="{{ $chart->id }}">
</div>
@include('charts::loader')
@@ -0,0 +1,44 @@
<script {!! $chart->displayScriptAttributes() !!}>
function {{ $chart->id }}_getType(data) {
var special_datasets = {!! json_encode($chart->special_datasets) !!};
for (var i = 0; i < special_datasets.length; i++) {
for (var k = 0; k < data.length; k++) {
if (special_datasets[i] == data[k].chartType) {
return special_datasets[i];
}
}
}
return 'axis-mixed';
}
function {{ $chart->id }}_create(data) {
{{ $chart->id }}_rendered = true;
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
window.{{ $chart->id }} = new frappe.Chart("#{{ $chart->id }}", {
{!! $chart->formatContainerOptions('js') !!}
labels: {!! $chart->formatLabels() !!},
type: {{ $chart->id }}_getType(data),
data: {
labels: {!! $chart->formatLabels() !!},
datasets: data
},
{!! $chart->formatOptions(false, true) !!}
});
}
@if ($chart->api_url)
let {{ $chart->id }}_refresh = function (url) {
document.getElementById("{{ $chart->id }}").style.display = 'none';
document.getElementById("{{ $chart->id }}_loader").style.display = 'flex';
if (typeof url !== 'undefined') {
{{ $chart->id }}_api_url = url;
}
fetch({{ $chart->id }}_api_url)
.then(data => data.json())
.then(data => {
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
{{ $chart->id }}.update({labels: {!! $chart->formatLabels() !!}, datasets: data});
});
};
@endif
@include('charts::init')
</script>
@@ -0,0 +1,3 @@
<div id="{{ $chart->id }}" {!! $chart->formatContainerOptions('css') !!}>
</div>
@include('charts::loader')
@@ -0,0 +1,48 @@
<script {!! $chart->displayScriptAttributes() !!}>
function {{ $chart->id }}_create(data) {
{{ $chart->id }}_rendered = true;
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
@if ($chart->type)
let {{ $chart->id }}_type = {{ $chart->type }}
@else
let {{ $chart->id }}_type = data[0].renderAs;
@endif
if (!{!! json_encode($chart->keepType) !!}.includes({{ $chart->id }}_type)) {
{{ $chart->id }}_type = "{{ $chart->comboType }}"
}
FusionCharts.ready(function () {
window.{{ $chart->id }} = new FusionCharts({
type: {{ $chart->id }}_type,
renderAt: "{{ $chart->id }}",
dataFormat: 'json',
{!! $chart->formatContainerOptions('js', true) !!}
dataSource: {
categories: [{
category: {!! $chart->formatLabels() !!}
}],
dataset: data,
chart: {!! $chart->formatOptions(true) !!}
}
}).render();
});
}
@if ($chart->api_url)
let {{ $chart->id }}_refresh = function (url) {
document.getElementById("{{ $chart->id }}").style.display = 'none';
document.getElementById("{{ $chart->id }}_loader").style.display = 'flex';
if (typeof url !== 'undefined') {
{{ $chart->id }}_api_url = url;
}
fetch({{ $chart->id }}_api_url)
.then(data => data.json())
.then(data => {
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
let chartData = {{ $chart->id }}.getChartData("json");
chartData.dataset = data;
{{ $chart->id }}.setChartData(chartData, "json");
});
};
@endif
@include('charts::init')
</script>
@@ -0,0 +1,3 @@
<div id="{{ $chart->id }}" {!! $chart->formatContainerOptions('css') !!}>
</div>
@include('charts::loader')
@@ -0,0 +1,27 @@
<script {!! $chart->displayScriptAttributes() !!}>
function {{ $chart->id }}_create(data) {
{{ $chart->id }}_rendered = true;
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
window.{{ $chart->id }} = new Highcharts.Chart("{{ $chart->id }}", {
series: data,
{!! $chart->formatOptions(false, true) !!}
});
}
@if ($chart->api_url)
let {{ $chart->id }}_refresh = function (url) {
document.getElementById("{{ $chart->id }}").style.display = 'none';
document.getElementById("{{ $chart->id }}_loader").style.display = 'flex';
if (typeof url !== 'undefined') {
{{ $chart->id }}_api_url = url;
}
fetch({{ $chart->id }}_api_url)
.then(data => data.json())
.then(data => {
document.getElementById("{{ $chart->id }}_loader").style.display = 'none';
document.getElementById("{{ $chart->id }}").style.display = 'block';
{{ $chart->id }}.update({series: data});
});
};
@endif
@include('charts::init')
</script>
+17
View File
@@ -0,0 +1,17 @@
let {{ $chart->id }}_rendered = false;
@if ($chart->api_url)
let {{ $chart->id }}_api_url = "{!! $chart->api_url !!}";
@endif
let {{ $chart->id }}_load = function () {
if (document.getElementById("{{ $chart->id }}") && !{{ $chart->id }}_rendered) {
@if ($chart->api_url)
fetch({{ $chart->id }}_api_url)
.then(data => data.json())
.then(data => { {{ $chart->id }}_create(data) });
@else
{{ $chart->id }}_create({!! $chart->formatDatasets() !!})
@endif
}
};
window.addEventListener("load", {{ $chart->id }}_load);
document.addEventListener("turbolinks:load", {{ $chart->id }}_load);
+40
View File
@@ -0,0 +1,40 @@
<div id="{{ $chart->id }}_loader" style="
display: flex;
justify-content: center;
opacity: {{ $chart->loader ? '1' : '0' }};
align-items: center;
{{ $chart->height ? 'height: ' . $chart->height . 'px;' : '' }}
{{ $chart->width ? 'width: ' . $chart->width . 'px;' : '' }}
">
<svg width="50" height="50" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient x1="8.042%" y1="0%" x2="65.682%" y2="23.865%" id="a">
<stop stop-color="{{ $chart->loaderColor }}" stop-opacity="0" offset="0%"/>
<stop stop-color="{{ $chart->loaderColor }}" stop-opacity=".631" offset="63.146%"/>
<stop stop-color="{{ $chart->loaderColor }}" offset="100%"/>
</linearGradient>
</defs>
<g fill="none" fill-rule="evenodd">
<g transform="translate(1 1)">
<path d="M36 18c0-9.94-8.06-18-18-18" id="Oval-2" stroke="url(#a)" stroke-width="2">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="0.9s"
repeatCount="indefinite" />
</path>
<circle fill="{{ $chart->loaderColor }}" cx="36" cy="18" r="1">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="0.9s"
repeatCount="indefinite" />
</circle>
</g>
</g>
</svg>
</div>