-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
190 lines (159 loc) · 6.42 KB
/
script.js
File metadata and controls
190 lines (159 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Navbar Start
window.onscroll = function() {
var navbar = document.getElementById("navbar");
if (document.body.scrollTop > 5|| document.documentElement.scrollTop > 50) {
navbar.style.backgroundColor = "lightblue"; // Warna saat scroll
} else {
navbar.style.backgroundColor = "transparent"; // Warna awal
}
};
document.addEventListener("DOMContentLoaded", () => {
const hamburgerIcon = document.querySelector('.hamburger i');
const hamburgerMenu = document.querySelector('.hamburger_menu');
hamburgerIcon.addEventListener('click', () => {
hamburgerMenu.classList.toggle('active');
if (hamburgerMenu.classList.contains('active')) {
hamburgerIcon.classList.replace('bx-menu', 'bx-x');
} else {
hamburgerIcon.classList.replace('bx-x', 'bx-menu');
}
});
});
// Navbar End
// Notifikasi
const messages = [
{ text: "Status energi: Tingkat energi sedang tinggi.", color: "green" },
{ text: "Status energi: Konsumsi energi meningkat.", color: "blue" },
{ text: "Status energi: Pasokan energi stabil.", color: "yellow" },
{ text: "Status energi: Gangguan pasokan energi.", color: "red" },
];
const recommendations = [
"Rekomendasi: Gunakan sumber energi alternatif.",
"Rekomendasi: Kurangi konsumsi energi Anda.",
"Rekomendasi: Matikan perangkat yang tidak perlu.",
"Rekomendasi: Hindari penggunaan listrik pada jam sibuk.",
];
function showNotification() {
const notification = document.getElementById("notification");
const message = document.getElementById("message");
const recommendation = document.getElementById("recommendation");
const randomMessage = messages[Math.floor(Math.random() * messages.length)];
message.textContent = randomMessage.text;
recommendation.textContent = recommendations[Math.floor(Math.random() * recommendations.length)];
notification.className = `notification ${randomMessage.color}`;
notification.classList.add("show");
setTimeout(() => {
notification.classList.remove("show");
}, 10000);
}
window.onload = showNotification;
// Notif End
// Start Hero
let text = document.getElementById('text');
let taka = document.getElementById('taka');
let taki = document.getElementById('taki');
let boltangka = document.getElementById('boltangka');
let boltangki = document.getElementById('boltangki');
let pohon = document.getElementById('pohon');
let bangunan = document.getElementById('bangunan');
let logo = document.getElementById('logo');
window.addEventListener('scroll', () => {
let value = window.scrollY;
text.style.marginTop = value * 1 + 'px';
taka.style.left = value * -2.5 + 'px';
taki.style.left = value * 2.5 + 'px';
boltangka.style.top = value * -2.5 + 'px';
boltangki.style.top = value * -2.5 + 'px';
pohon.style.left = value * 2.5 + 'px';
bangunan.style.left = value * -2.5 + 'px';
logo.style.marginTop = value * -2.5 + 'px';
});
// end Hero
// Half Donut Grafik
const energiDihasilkan = 70; // dalam persen
const energiDigunakan = 30; // dalam persen
const ctx = document.getElementById('myHalfDonutChart').getContext('2d');
const myHalfDonutChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Laut', 'Sungai'],
datasets: [{
data: [energiDihasilkan, energiDigunakan],
backgroundColor: ['#0000FF', '#00FFFF'],
hoverOffset: 4
}]
},
options: {
cutout: '70%', // Membuat efek donut
rotation: Math.PI, // Memutar grafik 180 derajat untuk half donut
plugins: {
tooltip: {
callbacks: {
label: function(tooltipItem) {
return tooltipItem.label + ': ' + tooltipItem.raw + '%';
}
}
},
legend: {
display: true,
position: 'top',
}
}
}
});
// End Half donut grafik
// Start Dashboard
let usagePercent = 75;
let pricePercent = 50;
let anomalyPercent = 20;
let totalCleanPercent = 90;
document.getElementById("usageValue").textContent = usagePercent + "%";
document.getElementById("priceValue").textContent = pricePercent + "%";
document.getElementById("anomalyValue").textContent = anomalyPercent + "%";
document.getElementById("totalCleanValue").textContent = totalCleanPercent + "%";
const ct = document.getElementById('lineChart').getContext('2d');
const lineChart = new Chart(ct, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [
{ label: 'Penggunaan Air', data: [60, 65, 70, 75, 80, usagePercent], borderColor: 'blue', fill: false },
{ label: 'Harga Air', data: [40, 45, 50, 55, 60, pricePercent], borderColor: 'green', fill: false },
{ label: 'Kelainan Air', data: [15, 17, 20, 23, 25, anomalyPercent], borderColor: 'red', fill: false },
{ label: 'Total Air Bersih', data: [85, 87, 90, 92, 95, totalCleanPercent], borderColor: 'purple', fill: false }
]
},
options: { responsive: true, scales: { x: { beginAtZero: true }, y: { beginAtZero: true, max: 100 } } }
});
// Chat functionality
function sendMessage() {
const chatInput = document.getElementById("chatInput");
const chatBox = document.getElementById("chatBox");
if (chatInput.value.trim() !== "") {
const messageDiv = document.createElement("div");
messageDiv.classList.add("message");
messageDiv.innerHTML = `<h4>Anda</h4><p>${chatInput.value}</p>`;
chatBox.appendChild(messageDiv);
// Scroll to the bottom of the chat box
chatBox.scrollTop = chatBox.scrollHeight;
// Clear the input field
chatInput.value = "";
}
}
// End Dashboard
// KARYA
const karyaImgs = document.querySelectorAll(".karya_img");
const boxKaryaImg = document.querySelector(".showGambar")
const karyaImg = document.getElementById("imgimg")
karyaImgs.forEach(karya => {
karya.addEventListener("click", function(e){
var gambar = karya.getAttribute("value")
boxKaryaImg.style.transform = "translateY(0%)"
console.log(karyaImg.src)
karyaImg.src="img/"+gambar
})
});
boxKaryaImg.addEventListener("click", function(){
boxKaryaImg.style.transform = "translateY(100%)"
})
// END KARYA