Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
marco76tv committed Sep 12, 2023
1 parent 0e3424e commit d9bc1a0
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 67 deletions.
151 changes: 84 additions & 67 deletions Resources/views/tables/columns/chart-column.blade.php
Original file line number Diff line number Diff line change
@@ -1,82 +1,99 @@
<div style="width:100%">
@php
/*
dddx([
'this'=>get_class($this),
'obj'=>get_class($obj),
@php
//$color = $obj->getColor();
//$heading = $obj->getHeading();
//$description = $obj->getDescription();
//$filters = $obj->getFilters();
$color='red';
$heading='heading';
$description = 'description';
@endphp

'get_Defined_vars'=>get_defined_vars(),
]);
<pre>{{ print_r($obj->getCachedData(),true) }}</pre>
*/

@endphp

<canvas
x-data="{
chart: null,
init: function () {
let chart = this.initChart()
$wire.on('updateChartData', async ({ data }) => {
chart.data = this.applyColorToData(data)
chart.update('resize')
})
$wire.on('filterChartData', async ({ data }) => {
chart.destroy()
chart = this.initChart(data)
})
},
initChart: function (data = null) {
data = data ?? {{ json_encode($obj->getCachedData()) }}
return (this.chart = new Chart($el, {
type: '{{ $obj->getType() }}',
data: this.applyColorToData(data),
options: {{ json_encode($obj->getOptions()) }} ?? {},
}))
},
applyColorToData: function (data) {
data.datasets.forEach((dataset, datasetIndex) => {
if (! dataset.backgroundColor) {
data.datasets[datasetIndex].backgroundColor = getComputedStyle(
$refs.backgroundColorElement,
).color
}
if (! dataset.borderColor) {
data.datasets[datasetIndex].borderColor = getComputedStyle(
$refs.borderColorElement,
).color
}
})
return data
},
}"
<x-filament::section
:description="$description"
:heading="$heading"
class="fi-wi-chart"
>
{{--
@if ($filters)
<x-slot name="headerEnd">
<x-filament::input.wrapper
inline-prefix
wire:target="filter"
class="-my-2"
>
<x-filament::input.select
inline-prefix
wire:model.live="filter"
>
@foreach ($filters as $value => $label)
<option value="{{ $value }}">
{{ $label }}
</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
</x-slot>
@endif
--}}
<div
{{--
@if ($pollingInterval = $obj->getPollingInterval())
wire:poll.{{ $pollingInterval }}="updateChartData"
@endif
--}}
>
<div
ax-load
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('chart', 'filament/widgets') }}"
wire:ignore
@if ($maxHeight = $obj->getMaxHeight())
style="max-height: {{ $maxHeight }}"
@endif
x-data="chart({
cachedData: @js($obj->getCachedData()),
options: @js($obj->getOptions()),
type: @js($obj->getType()),
})"
x-ignore
@style([
\Filament\Support\get_color_css_variables($color, shades: [50, 400, 500]) => $color !== 'gray',
])
>
<canvas
x-ref="canvas"
@if ($maxHeight = $obj->getMaxHeight())
style="max-height: {{ $maxHeight }}"
@endif
></canvas>

<span
x-ref="backgroundColorElement"
@class([
'text-gray-50',
'dark:text-gray-300' => config('filament.dark_mode'),
match ($color) {
'gray' => 'text-gray-100 dark:text-gray-800',
default => 'text-custom-50 dark:text-custom-400/10',
},
])
></span>

<span
x-ref="borderColorElement"
@class([
'text-gray-500',
'dark:text-gray-200' => config('filament.dark_mode'),
match ($color) {
'gray' => 'text-gray-400',
default => 'text-custom-500 dark:text-custom-400',
},
])
></span>
</canvas>
</div>

<span
x-ref="gridColorElement"
class="text-gray-200 dark:text-gray-800"
></span>

<span
x-ref="textColorElement"
class="text-gray-500 dark:text-gray-400"
></span>
</div>
</div>
</x-filament::section>

82 changes: 82 additions & 0 deletions Resources/views/tables/columns/chart-column.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<div style="width:100%">
@php
/*
dddx([
'this'=>get_class($this),
'obj'=>get_class($obj),

'get_Defined_vars'=>get_defined_vars(),
]);
<pre>{{ print_r($obj->getCachedData(),true) }}</pre>
*/

@endphp

<canvas
x-data="{
chart: null,

init: function () {
let chart = this.initChart()

$wire.on('updateChartData', async ({ data }) => {
chart.data = this.applyColorToData(data)
chart.update('resize')
})

$wire.on('filterChartData', async ({ data }) => {
chart.destroy()
chart = this.initChart(data)
})
},

initChart: function (data = null) {
data = data ?? {{ json_encode($obj->getCachedData()) }}

return (this.chart = new Chart($el, {
type: '{{ $obj->getType() }}',
data: this.applyColorToData(data),
options: {{ json_encode($obj->getOptions()) }} ?? {},
}))
},

applyColorToData: function (data) {
data.datasets.forEach((dataset, datasetIndex) => {
if (! dataset.backgroundColor) {
data.datasets[datasetIndex].backgroundColor = getComputedStyle(
$refs.backgroundColorElement,
).color
}

if (! dataset.borderColor) {
data.datasets[datasetIndex].borderColor = getComputedStyle(
$refs.borderColorElement,
).color
}
})

return data
},
}"
wire:ignore
@if ($maxHeight = $obj->getMaxHeight())
style="max-height: {{ $maxHeight }}"
@endif
>
<span
x-ref="backgroundColorElement"
@class([
'text-gray-50',
'dark:text-gray-300' => config('filament.dark_mode'),
])
></span>

<span
x-ref="borderColorElement"
@class([
'text-gray-500',
'dark:text-gray-200' => config('filament.dark_mode'),
])
></span>
</canvas>
</div>

0 comments on commit d9bc1a0

Please sign in to comment.