diff --git a/website/src/icons/ChartBarIcon.tsx b/website/src/icons/ChartBarIcon.tsx new file mode 100644 index 0000000..e313228 --- /dev/null +++ b/website/src/icons/ChartBarIcon.tsx @@ -0,0 +1,21 @@ +import IconProps from "./type"; + +export default function (props: IconProps) { + return ( + + + + ); +} diff --git a/website/src/icons/DocumentMagnify.tsx b/website/src/icons/DocumentMagnify.tsx new file mode 100644 index 0000000..aecc4dc --- /dev/null +++ b/website/src/icons/DocumentMagnify.tsx @@ -0,0 +1,21 @@ +import IconProps from "./type"; + +export default function (props: IconProps) { + return ( + + + + ); +} diff --git a/website/src/pages/Histori.tsx b/website/src/pages/Histori.tsx index adfe18b..6e4aaee 100644 --- a/website/src/pages/Histori.tsx +++ b/website/src/pages/Histori.tsx @@ -1,16 +1,23 @@ import { createSignal, onMount } from "solid-js"; import Table from "../components/Table"; -import { Histori } from "../types/Histori"; +import { Histori, PerubahanKomposisi } from "../types/Histori"; import supabase from "../utils/supabase"; import { getDates } from "../utils/dates"; import TrashIcon from "../icons/TrashIcon"; import { KondisiTapai } from "../types/KondisiTapai"; import ClockIcon from "../icons/ClockIcon"; +import ChartBarIcon from "../icons/ChartBarIcon"; +import { Chart, registerables } from "chart.js"; export default function () { + let canvas: any; const [items, setItems] = createSignal([]); const [dataPengujianAwal, setDataPengujianAwal] = createSignal(); + const [showDetail, setShowDetail] = createSignal(false); + const [dataKomposisi, setDataKomposisi] = + createSignal(); + const [chartDetail, setChartDetail] = createSignal(); const getData = async () => { const { data } = await supabase @@ -30,7 +37,7 @@ export default function () { }; const deleteHistory = async (id: any) => { - const isOk = confirm("Anda yakin menghapus history?"); + const isOk = confirm("Anda yakin menghapus histori terpilih?"); if (isOk) { await supabase.from("histori_fermentasi").delete().eq("id", id); @@ -38,57 +45,194 @@ export default function () { } }; + const renderChart = async (berhasil: boolean) => { + let labels: any[] = []; + let values: any[] = []; + + dataKomposisi()?.forEach((item) => { + labels.push(item.jam_ke); + values.push(item.kadar_gas); + }); + + chartDetail()?.destroy(); + + const chart = new Chart(canvas, { + type: "line", + data: { + labels: labels, + datasets: [ + { + label: "Kadar Gas", + data: values, + borderColor: berhasil ? "lightgreen" : "red", + cubicInterpolationMode: "monotone", + tension: 0.4, + }, + ], + }, + options: { + responsive: true, + scales: { + x: { + display: true, + title: { + display: true, + }, + }, + y: { + display: true, + title: { + display: true, + text: "Kadar Gas Alkohol", + }, + min: 0, + max: 10, + ticks: { + callback: (val) => { + return val + "%"; + }, + }, + }, + }, + plugins: { + tooltip: { + callbacks: { + title(_) { + return ""; + }, + label(tooltipItem) { + return ( + tooltipItem.dataset.label + + ": " + + tooltipItem.parsed.y.toFixed(2) + + "%" + ); + }, + }, + }, + }, + }, + }); + + setChartDetail(chart); + }; + onMount(async () => { await getData(); + Chart.register(...registerables); }); return ( -
-
-
Histori
-

- Menampilkan hasil fermentasi yang telah dilakukan. -

-
- -
: Proses sedang berlangsung
-
- [ - getDates(item.created_at), - Math.round((item.waktu_akhir - item.waktu_awal) / 3600) + " Jam", - item.rentang_suhu, - +
+
+
Histori
+

+ Menampilkan hasil fermentasi yang telah dilakukan. +

+
+ +
: Proses sedang berlangsung
+
+
{ + let sedangBerlangsung: boolean = false; + if ( + !!dataPengujianAwal() && + dataPengujianAwal()!.created_time <= item.waktu_akhir + ) { + sedangBerlangsung = true; } - > - {item.berhasil ? "SUKSES" : "GAGAL"} - , - !!dataPengujianAwal() && - dataPengujianAwal()!.created_time <= item.waktu_akhir ? ( - - ) : ( - - ), - ])} - class="my-5" - >
+ + return [ + sedangBerlangsung ? ( +
+ +
+ ) : ( + "" + ), + getDates(item.created_at), + Math.round((item.waktu_akhir - item.waktu_awal) / 3600) + + " Jam", + item.rentang_suhu, + + {item.berhasil ? "SUKSES" : "GAGAL"} + , +
+ + {sedangBerlangsung ? ( + "" + ) : ( + + )} +
, + ]; + })} + class="my-5" + > +
- + + + ); } diff --git a/website/src/pages/Pengujian.tsx b/website/src/pages/Pengujian.tsx index 4993b84..42b6611 100644 --- a/website/src/pages/Pengujian.tsx +++ b/website/src/pages/Pengujian.tsx @@ -111,7 +111,7 @@ export default function () { display: true, title: { display: true, - text: "Nilai", + text: "Kadar Gas Alkohol", }, min: 0, max: 10, diff --git a/website/src/types/Histori.ts b/website/src/types/Histori.ts index 0f4e6b5..1fadef6 100644 --- a/website/src/types/Histori.ts +++ b/website/src/types/Histori.ts @@ -1,3 +1,8 @@ +export type PerubahanKomposisi = { + kadar_gas: number; + jam_ke: number; +}; + export interface Histori { id: number; waktu_awal: number; @@ -6,4 +11,5 @@ export interface Histori { berhasil: boolean; created_at: string; selesai: boolean; + perubahan_komposisi: PerubahanKomposisi[]; } \ No newline at end of file