Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstatic get nova chartjs settings #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ php artisan migrate

After setup, your model should include the `KirschbaumDevelopment\NovaChartjs\Traits\HasChart` trait and you must implement the `KirschbaumDevelopment\NovaChartjs\Contracts\Chartable` Contract.

You must also define a static `getNovaChartjsSettings` function in the model which should return the required settings for the Chart. All other required methods and relationship defined in the contract are already defined for you in the included trait. You can also override these trait methods directly on your model.
You must also define a `getNovaChartjsSettings` function in the model which should return the required settings for the Chart. All other required methods and relationship defined in the contract are already defined for you in the included trait. You can also override these trait methods directly on your model.

```php
use KirschbaumDevelopment\NovaChartjs\Traits\HasChart;
Expand All @@ -48,7 +48,7 @@ class Employee extends Model implements Chartable
*
* @return array
*/
public static function getNovaChartjsSettings(): array
public function getNovaChartjsSettings(): array
{
return [
'default' => [
Expand Down Expand Up @@ -277,7 +277,7 @@ class Employee extends Model implements Chartable
*
* @return array
*/
public static function getNovaChartjsSettings(): array
public function getNovaChartjsSettings(): array
{
return [
'default' => [
Expand Down Expand Up @@ -340,7 +340,7 @@ You can add or remove any model to comparison to checkout how models are stacked

## Changing Comparison Data

Chart comparison data is fetched through trait using a static function `getNovaChartjsComparisonData`. You can override this function in your model to change the comparison data.
Chart comparison data is fetched through trait using a function `getNovaChartjsComparisonData`. You can override this function in your model to change the comparison data.
```php
namespace App;

Expand All @@ -359,7 +359,7 @@ class Employee extends Model implements Chartable
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public static function getNovaChartjsComparisonData(): array
public function getNovaChartjsComparisonData(): array
{
return static::with('novaChartjsMetricValue')
->has('novaChartjsMetricValue')
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/Chartable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function novaChartjsMetricValue(): MorphMany;
*
* @return array
*/
public static function getNovaChartjsSettings(): array;
public function getNovaChartjsSettings(): array;

/**
* Return a list of all models available for comparison to root model.
Expand All @@ -25,7 +25,7 @@ public static function getNovaChartjsSettings(): array;
*
* @return array
*/
public static function getNovaChartjsComparisonData($chartName = 'default'): array;
public function getNovaChartjsComparisonData($chartName = 'default'): array;

/**
* Return a list of additional datasets added to chart.
Expand Down
4 changes: 2 additions & 2 deletions src/NovaChartjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function resolve($resource, $attribute = null)
}

if (! empty($resource)) {
$settings = data_get($resource::getNovaChartjsSettings(), $this->getChartName(), []);
$settings = data_get($resource->getNovaChartjsSettings(), $this->getChartName(), []);

$this->withMeta([
'settings' => $settings,
'comparison' => $resource::getNovaChartjsComparisonData($this->getChartName()),
'comparison' => $resource->getNovaChartjsComparisonData($this->getChartName()),
'additionalDatasets' => data_get($resource->getAdditionalDatasets(), $this->getChartName(), []),
'model' => Str::singular(Str::title(Str::snake(class_basename($resource), ' '))),
'title' => $this->getChartableProp($resource, $settings['titleProp'] ?? $resource->getKeyName()),
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function setNovaChartjsMetricValueAttribute($value): void
*
* @return array
*/
public static function getNovaChartjsComparisonData($chartName = 'default'): array
public function getNovaChartjsComparisonData($chartName = 'default'): array
{
return static::with('novaChartjsMetricValue')
->has('novaChartjsMetricValue')
Expand Down