Skip to content

Commit

Permalink
Merge pull request #13 from ninja5pizza/charts
Browse files Browse the repository at this point in the history
Add charts
  • Loading branch information
mvdnbrk authored Nov 30, 2024
2 parents 9155c84 + ba07a76 commit e83d9d0
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 8 deletions.
14 changes: 14 additions & 0 deletions app/Http/Resources/FloorPricesCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

class FloorPricesCollection extends ResourceCollection
{
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}
17 changes: 17 additions & 0 deletions app/Http/Resources/FloorPricesResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class FloorPricesResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'time' => $this->created_at->getTimeStamp(),
'value' => $this->price_in_sats / 100000000,
];
}
}
3 changes: 3 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Ninja5;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Resources\Json\JsonResource;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -18,5 +19,7 @@ public function boot(): void
View::share('ninja5', new Ninja5(
config('ninja5')
));

JsonResource::withoutWrapping();
}
}
127 changes: 127 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
},
"devDependencies": {
"autoprefixer": "^10.4.20",
"axios": "^1.7.8",
"laravel-vite-plugin": "^1.0.6",
"lightweight-charts": "^4.2.1",
"postcss": "^8.4.49",
"shiki": "^1.24.0",
"tailwindcss": "^3.4.15",
Expand Down
2 changes: 1 addition & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import './bootstrap';
import './bootstrap';

import { codeToHtml } from 'shiki'

Expand Down
45 changes: 45 additions & 0 deletions resources/js/chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createChart } from 'lightweight-charts';

const url = '/api/chart';
const response = await axios.get(url);

const chart = createChart(
document.getElementById('trading-view-charts'),
{
layout: {
background: { color: '#ff5400' },
textColor: '#fff',
},
grid: {
vertLines: { color: '#c2410c' },
horzLines: { color: '#c2410c' },
},
handleScroll: {
mouseWheel: false,
pressedMouseMove: false,
horzTouchDrag: false,
vertTouchDrag: false,
},
handleScale: {
mouseWheel: false,
pinch: false,
},
}
);

const priceFormatter = p => p.toFixed(2);

chart.applyOptions({
localization: {
priceFormatter: priceFormatter,
},
});

chart.timeScale().fitContent();

const areaSeries = chart.addAreaSeries({
lineColor: '#f97316', topColor: '#fb923c',
bottomColor: 'rgba(67, 20, 7, 0.28)',
});

areaSeries.setData(response.data);
4 changes: 4 additions & 0 deletions resources/svg/tradingview.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions resources/views/components/chart.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div id="trading-view-charts" class="w-full h-96">

</div>

<div class="w-full flex mt-4 pr-4 lg:pr-12 justify-end text-gray-600">
<span class="sr-only">Trading View Charts</span>
<a
href="https://www.tradingview.com"
target="_blank"
rel="noopener"
class="text-white hover:text-gray-200"
>
<x-icon-tradingview class="h-4 lg:h-6" />
</a>
</div>

@pushOnce('scripts')
@vite('resources/js/chart.js')
@endPushOnce
1 change: 1 addition & 0 deletions resources/views/components/layout/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<x-layout.footer/>

@vite('resources/js/app.js')
@stack('scripts')
</body>
</html>
2 changes: 2 additions & 0 deletions resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<x-stats/>

<x-chart/>

<div class="mx-auto max-w-7xl px-0 sm:px-4 lg:px-8">
<div class="mx-auto max-w-2xl">
<div class="mt-10 flex flex-col md:flex-row justify-center items-center mx-12">
Expand Down
20 changes: 14 additions & 6 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

use App\Http\Controllers\CollectionController;
use App\Models\FloorPrice;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\ContentController;
use App\Http\Controllers\DownloadSvgController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\HomepageController;
use App\Http\Controllers\InscriptionController;
use App\Http\Resources\FloorPricesCollection;
use App\Http\Controllers\CollectionController;
use App\Http\Controllers\PizzaNinjaController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\SearchController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DownloadSvgController;
use App\Http\Controllers\InscriptionController;

Route::get('/', HomepageController::class)
->name('home');
Expand Down Expand Up @@ -41,3 +43,9 @@
->name('download-svg');

Route::post('/search', SearchController::class)->name('search');

Route::get('/api/chart', function () {
return new FloorPricesCollection(
FloorPrice::take(1000)->latest()->get()->reverse()
);
});
Loading

0 comments on commit e83d9d0

Please sign in to comment.