Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
max-yilang committed Dec 9, 2019
0 parents commit 05d9b72
Show file tree
Hide file tree
Showing 16 changed files with 2,291 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.idea
/vendor
/node_modules
package-lock.json
composer.phar
composer.lock
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Brian Dillingham <[email protected]>

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.
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Nova Apex Chart

[![Latest Version on Packagist](https://img.shields.io/packagist/v/digital-creative/nova-apex-chart)](https://packagist.org/packages/digital-creative/nova-apex-chart)
[![Total Downloads](https://img.shields.io/packagist/dt/digital-creative/nova-apex-chart)](https://packagist.org/packages/digital-creative/nova-apex-chart)
[![License](https://img.shields.io/packagist/l/digital-creative/nova-apex-chart)](https://github.com/dcasia/nova-apex-chart/blob/master/LICENSE)

A Laravel Nova ApexCharts Component

[ApexCharts Documentation](https://apexcharts.com/docs/series/#)

![SliderFilter in Action](https://raw.githubusercontent.com/dcasia/nova-apex-chart/master/screenshot.png)

# Installation

You can install the package via composer:

```
composer require digital-creative/nova-apex-chart
```

## Basic Usage

```php
class ExampleNovaResource extends Resource
{

public function cards(Request $request)
{

return [
(new NovaApexChart())
->type('bar')
->series(
[
new DataOnlySeries([ 400, 430, 448, 470, 540, 580, 690, 1100, 1200, 1380 ])
])
->options([
'xaxis' => [
'categories' => [ 'Jan', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct' ]
],
'tooltip' => [
'y' => [
'formatter' => new BasicFormatter('$', 'USD')
]
]
])
];
}

}
```

Create basic series by calling
```php
use DigitalCreative\NovaApexChart\BasicSeries;
new BasicSeries('title', [ 400, 430, 448, 470, 540, 580, 690, 1100, 1200, 1380 ]);
```

Create data only series by calling
```php
use DigitalCreative\NovaApexChart\DataOnlySeries;
new DataOnlySeries([ 400, 430, 448, 470, 540, 580, 690, 1100, 1200, 1380 ]);
```

Create custom formatter
```php
use DigitalCreative\NovaApexChart\BasicFormatter;
new BasicFormatter('$', 'USD');
```

## License

The MIT License (MIT). Please see [License File](https://raw.githubusercontent.com/dcasia/nova-slider-filter/master/LICENSE) for more information.
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "digital-creative/nova-apex-chart",
"description": "A Laravel Nova Apex Chart Component.",
"keywords": [
"laravel",
"nova",
"apex chart",
"chart"
],
"license": "MIT",
"require": {
"php": ">=7.1.0"
},
"autoload": {
"psr-4": {
"DigitalCreative\\NovaApexChart\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"DigitalCreative\\NovaApexChart\\CardServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
1,882 changes: 1,882 additions & 0 deletions dist/js/card.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"/js/nova-apex-chart.js": "/js/nova-apex-chart.js"
}
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.0.0",
"laravel-mix": "^5.0.0",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"apexcharts": "^3.10.1",
"vue": "^2.5.0",
"vue-apexcharts": "^1.5.1"
}
}
58 changes: 58 additions & 0 deletions resources/js/components/NovaApexChart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<card class="p-10">
<apexchart :type="card.type" :options="options" :series="card.series"></apexchart>
</card>
</template>

<script>
import VueApexCharts from 'vue-apexcharts'
export default {
components: {
'apexchart': VueApexCharts
},
props: [
'card'
// The following props are only available on resource detail cards...
// 'resource',
// 'resourceId',
// 'resourceName',
],
methods: {
handleFormatter(options) {
Object.keys(options).forEach(key => {
if (key === 'formatter') {
const prefix = options[ key ].prefix || ''
const suffix = options[ key ].suffix || ''
options[ key ] = function (val) {
return `${ prefix } ${ val } ${ suffix }`
}
}
if (typeof options[ key ] === 'object') {
this.handleFormatter(options[ key ])
}
})
}
},
computed: {
options() {
const options = this.card.options
this.handleFormatter(options)
return options
}
}
}
</script>

<style lang="scss" scoped>
.p-10 {
padding: 2.5rem;
}
</style>
5 changes: 5 additions & 0 deletions resources/js/nova-apex-chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import NovaApexChart from './components/NovaApexChart'

Nova.booting((Vue, router, store) => {
Vue.component('nova-apex-chart', NovaApexChart)
})
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/BasicFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace DigitalCreative\NovaApexChart;

use JsonSerializable;
use Laravel\Nova\Card;

class BasicFormatter implements JsonSerializable {


/**
* @var string
*/
private string $prefix;
private string $suffix;

public function __construct(string $prefix, string $suffix)
{
$this->prefix = $prefix;
$this->suffix = $suffix;
}

public function jsonSerialize()
{
return [
'prefix' => $this->prefix,
'suffix' => $this->suffix,
];
}
}
30 changes: 30 additions & 0 deletions src/BasicSeries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace DigitalCreative\NovaApexChart;

use JsonSerializable;
use Laravel\Nova\Card;

class BasicSeries implements JsonSerializable {


/**
* @var string
*/
private string $name;
private $data;

public function __construct(string $name, $data)
{
$this->name = $name;
$this->data = is_callable($data) ? call_user_func($data) : $data;
}

public function jsonSerialize()
{
return [
'name' => $this->name,
'data' => $this->data,
];
}
}
33 changes: 33 additions & 0 deletions src/CardServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace DigitalCreative\NovaApexChart;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;

class CardServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Nova::serving(function (ServingNova $event) {
Nova::script('nova-apex-chart', __DIR__.'/../dist/js/card.js');
});
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
24 changes: 24 additions & 0 deletions src/DataOnlySeries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace DigitalCreative\NovaApexChart;

use JsonSerializable;
use Laravel\Nova\Card;

class DataOnlySeries implements JsonSerializable {


private $data;

public function __construct($data)
{
$this->data = is_callable($data) ? call_user_func($data) : $data;
}

public function jsonSerialize()
{
return [
'data' => $this->data,
];
}
}
Loading

0 comments on commit 05d9b72

Please sign in to comment.