Skip to content

Commit e1f0de2

Browse files
committed
[TASK] Define chart type for each device-sensor
1 parent baa79c5 commit e1f0de2

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

app/Http/Controllers/GraphController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\Sensor;
88
use Illuminate\Http\Request;
99
use Illuminate\Support\Facades\Auth;
10+
use Illuminate\Support\Facades\DB;
1011

1112
class GraphController extends Controller
1213
{
@@ -52,9 +53,18 @@ public function show(Request $request)
5253
}
5354

5455
$points = collect([]);
56+
$chartType = 'LineSeries';
5557
if ($selectedDeviceId && $selectedSensorId) {
5658
$points = Point::where($constraints)
5759
->orderBy('added_on', 'asc')->get();
60+
61+
$chartType = DB::table('device_sensor')
62+
->where(
63+
[
64+
['device_id', $selectedDeviceId],
65+
['sensor_id', $selectedSensorId],
66+
]
67+
)->first()->chart_type;
5868
}
5969

6070
$averageValue = round($points->avg('value'), 2);
@@ -82,6 +92,7 @@ public function show(Request $request)
8292
'minValue' => $minValue,
8393
'maxValue' => $maxValue,
8494
'averageValue' => $averageValue,
95+
'chartType' => $chartType,
8596
]);
8697
}
8798
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('device_sensor', function (Blueprint $table) {
15+
$table->string('chart_type', 128)->default('LineSeries')->nullable();
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('device_sensor', function (Blueprint $table) {
25+
$table->dropColumn('chart_type');
26+
});
27+
}
28+
};

resources/views/partials/graph/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function generateDatas() {
283283
284284
// Add series
285285
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
286-
var series = chart.series.push(am5xy.LineSeries.new(root, {
286+
var series = chart.series.push(am5xy.{!! $chartType !!}.new(root, {
287287
name: "Series",
288288
xAxis: xAxis,
289289
yAxis: yAxis,

0 commit comments

Comments
 (0)