-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
167 lines (144 loc) · 5.7 KB
/
script.js
File metadata and controls
167 lines (144 loc) · 5.7 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
// Exemplo de dados (incluindo nomes)
let coordinates = [
{ name: "Los Angeles", lat: 34.0522, lon: -118.2437 },
{ name: "New York", lat: 40.7128, lon: -74.0060 },
{ name: "San Francisco", lat: 37.7749, lon: -122.4194 },
{ name: "San Francisco 2", lat: 37.7749, lon: -122.4194 },
];
// Exemplo de dados de fluxo de pesquisa ao longo da semana
const searchFlowData = {
labels: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
datasets: [{
label: 'Fluxo de Pesquisas',
data: [5, 10, 15, 7, 12, 20, 17], // Dados de exemplo
fill: false,
borderColor: 'rgba(75, 192, 192, 1)',
tension: 0.1 // Tensão do gráfico para suavizar a linha
}]
};
document.addEventListener("DOMContentLoaded", function() {
// Atualizar total de locais pesquisados
document.getElementById("total-locations").textContent = coordinates.length;
// Criar gráfico de linha
const ctx = document.getElementById("locationChart").getContext("2d");
const locationChart = new Chart(ctx, {
type: "line",
data: searchFlowData,
options: {
responsive: true,
plugins: {
legend: {
display: true,
},
tooltip: {
mode: 'index',
intersect: false,
},
},
scales: {
x: {
title: {
display: true,
text: 'Dias da Semana'
}
},
y: {
title: {
display: true,
text: 'Número de Pesquisas'
},
beginAtZero: true
}
}
}
});
// Adicionar coordenadas à tabela
renderTable();
});
// Função para renderizar a tabela com os dados de coordenadas
function renderTable() {
const tableBody = document.querySelector("#coordinate-table tbody");
tableBody.innerHTML = ""; // Limpar tabela antes de renderizar
coordinates.forEach(coord => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${coord.name}</td> <!-- Exibir o nome -->
<td>${coord.lat}</td>
<td>${coord.lon}</td>
<td class="actions">
<i class="fas fa-edit" onclick="editLocation('${coord.name}', ${coord.lat}, ${coord.lon})"></i>
<i class="fas fa-trash" onclick="deleteLocation('${coord.name}', ${coord.lat}, ${coord.lon})"></i>
</td>
`;
tableBody.appendChild(row);
});
}
// Função para voltar à página anterior
function goBack() {
window.history.back(); // Volta para a página anterior no histórico
}
// Funções para editar e deletar locais
let editedLocationIndex = null;
function editLocation(name, lat, lon) {
// Encontrar o índice do local a ser editado
editedLocationIndex = coordinates.findIndex(coord => coord.name === name && coord.lat === lat && coord.lon === lon);
// Carregar o nome e coordenadas no modal de edição
document.getElementById('editName').value = name;
document.getElementById('editLat').value = lat;
document.getElementById('editLon').value = lon;
// Abrir modal de edição
$('#editModal').modal('show');
}
function deleteLocation(name, lat, lon) {
// Armazenar informações do local a ser deletado
document.getElementById('deleteModal').setAttribute('data-name', name);
document.getElementById('deleteModal').setAttribute('data-lat', lat);
document.getElementById('deleteModal').setAttribute('data-lon', lon);
// Abrir modal de exclusão
$('#deleteModal').modal('show');
}
// Função para confirmar exclusão
function confirmDelete() {
const name = document.getElementById('deleteModal').getAttribute('data-name');
const lat = parseFloat(document.getElementById('deleteModal').getAttribute('data-lat'));
const lon = parseFloat(document.getElementById('deleteModal').getAttribute('data-lon'));
// Remover coordenada
coordinates = coordinates.filter(coord => !(coord.name === name && coord.lat === lat && coord.lon === lon));
// Atualizar a tabela
renderTable();
// Fechar modal
$('#deleteModal').modal('hide');
}
// Função para cancelar exclusão
function cancelDelete() {
$('#deleteModal').modal('hide');
}
// Função para salvar mudanças feitas no modal de edição
function saveChanges() {
const name = document.getElementById('editName').value;
const lat = parseFloat(document.getElementById('editLat').value);
const lon = parseFloat(document.getElementById('editLon').value);
// Atualizar as coordenadas no array
if (editedLocationIndex !== null) {
coordinates[editedLocationIndex] = { name, lat, lon };
}
// Atualizar a tabela
renderTable();
// Fechar modal
$('#editModal').modal('hide');
}
// Função para cancelar edição
function cancelEdit() {
$('#editModal').modal('hide');
}
// Função para exportar a tabela para CSV ou XLSX
document.getElementById('export-button').addEventListener('click', function() {
const wb = XLSX.utils.book_new();
const ws_data = [
["Nome", "Latitude", "Longitude"], // Cabeçalhos das colunas
...coordinates.map(coord => [coord.name, coord.lat, coord.lon]) // Dados das coordenadas
];
const ws = XLSX.utils.aoa_to_sheet(ws_data);
XLSX.utils.book_append_sheet(wb, ws, "Coordenadas");
XLSX.writeFile(wb, "coordenadas.xlsx"); // Exportar como XLSX
});