ViannyCruz commited on
Commit
2378b9c
·
verified ·
1 Parent(s): 1225b42

Update web/index.html

Browse files
Files changed (1) hide show
  1. web/index.html +185 -183
web/index.html CHANGED
@@ -1048,193 +1048,195 @@
1048
  });
1049
 
1050
  function createOrUpdateChart(dates, totalConsultations, positiveCases, negativeCases) {
1051
- if (areaChartInstance && typeof areaChartInstance.destroy === 'function') {
1052
- try {
1053
- areaChartInstance.destroy();
1054
- areaChartInstance = null;
1055
- } catch (error) {
1056
- console.log('Error destruyendo grafico anterior:', error);
1057
- }
1058
- }
1059
-
1060
- const chartElement = document.querySelector("#areaChart");
1061
- if (!chartElement) {
1062
- console.error('Elemento #areaChart no encontrado');
1063
- return;
1064
- }
1065
 
1066
- chartElement.innerHTML = '';
 
 
 
 
1067
 
1068
- setTimeout(() => {
1069
- try {
1070
- const options = {
1071
- chart: {
1072
- type: 'area',
1073
- height: 350,
1074
- width: '100%',
1075
- toolbar: {
1076
- show: true,
1077
- tools: {
1078
- download: false,
1079
- selection: false,
1080
- zoom: false,
1081
- zoomin: false,
1082
- zoomout: false,
1083
- pan: false,
1084
- reset: false
1085
- }
1086
- },
1087
- animations: {
1088
- enabled: true,
1089
- easing: 'easeinout',
1090
- speed: 800
1091
- },
1092
- background: 'transparent'
1093
- },
1094
- colors: ['#2E93fA', '#FF9800', '#66DA26'],
1095
- // Convertir "YYYY-MM-DD" a timestamp UTC mediodia para evitar
1096
- // desfases de zona horaria que desplazan el dia al anterior
1097
- series: (function() {
1098
- function toTs(d) {
1099
- var p = d.split('-').map(Number);
1100
- return Date.UTC(p[0], p[1] - 1, p[2], 12, 0, 0);
1101
- }
1102
- function toSeries(vals) {
1103
- return dates.map(function(d, i) { return { x: toTs(d), y: vals[i] }; });
1104
- }
1105
- return [
1106
- { name: 'Total Consultas', data: toSeries(totalConsultations) },
1107
- { name: 'Con Retinopatía', data: toSeries(positiveCases) },
1108
- { name: 'Sin Retinopatía', data: toSeries(negativeCases) }
1109
- ];
1110
- })(),
1111
- xaxis: {
1112
- type: 'datetime',
1113
- labels: {
1114
- datetimeUTC: false,
1115
- datetimeFormatter: {
1116
- year: 'yyyy',
1117
- month: "MMM 'yy",
1118
- day: 'dd/MM',
1119
- hour: 'HH:mm'
1120
- },
1121
- style: {
1122
- fontSize: '12px',
1123
- fontFamily: 'inherit'
1124
- }
1125
- },
1126
- title: {
1127
- text: 'Fecha',
1128
- style: {
1129
- fontSize: '14px',
1130
- fontFamily: 'inherit'
1131
- }
1132
- }
1133
- },
1134
- yaxis: {
1135
- title: {
1136
- text: 'Número de Consultas',
1137
- style: {
1138
- fontSize: '14px',
1139
- fontFamily: 'inherit'
1140
- }
1141
- },
1142
- min: 0,
1143
- tickAmount: Math.max.apply(null, totalConsultations) || 1,
1144
- labels: {
1145
- formatter: function(val) { return Math.floor(val); },
1146
- style: {
1147
- fontSize: '12px',
1148
- fontFamily: 'inherit'
1149
- }
1150
- }
1151
- },
1152
- tooltip: {
1153
- shared: true,
1154
- intersect: false,
1155
- x: {
1156
- formatter: function(value) {
1157
- return new Date(value).toLocaleDateString('es-ES', {
1158
- weekday: 'long',
1159
- year: 'numeric',
1160
- month: 'long',
1161
- day: 'numeric'
1162
- });
1163
- }
1164
- },
1165
- y: {
1166
- formatter: function(value) {
1167
- return value + ' consulta' + (value !== 1 ? 's' : '');
1168
- }
1169
- }
1170
- },
1171
- stroke: {
1172
- curve: 'smooth',
1173
- width: 2
1174
- },
1175
- fill: {
1176
- type: 'gradient',
1177
- gradient: {
1178
- shadeIntensity: 1,
1179
- opacityFrom: 0.7,
1180
- opacityTo: 0.3,
1181
- stops: [0, 90, 100]
1182
- }
1183
- },
1184
- legend: {
1185
- position: 'top',
1186
- horizontalAlign: 'left',
1187
- labels: {
1188
- colors: '#9aa0ac'
1189
- }
1190
- },
1191
- grid: {
1192
- borderColor: '#f1f1f1',
1193
- strokeDashArray: 4,
1194
- xaxis: {
1195
- lines: {
1196
- show: true
1197
- }
1198
- },
1199
- yaxis: {
1200
- lines: {
1201
- show: true
1202
- }
1203
- }
1204
- },
1205
- dataLabels: {
1206
- enabled: false
1207
- },
1208
- responsive: [{
1209
- breakpoint: 768,
1210
- options: {
1211
- chart: {
1212
- height: 300
1213
- },
1214
- legend: {
1215
- position: 'bottom'
1216
- }
1217
- }
1218
- }]
1219
- };
1220
-
1221
- areaChartInstance = new ApexCharts(chartElement, options);
1222
-
1223
- areaChartInstance.render()
1224
- .then(() => {
1225
- console.log('Gráfico creado exitosamente');
1226
- })
1227
- .catch((error) => {
1228
- console.error('Error renderizando gráfico:', error);
1229
- createFallbackChart(chartElement, dates, totalConsultations, positiveCases, negativeCases);
1230
  });
1231
-
1232
- } catch (error) {
1233
- console.error('Error creando gráfico:', error);
1234
- createFallbackChart(chartElement, dates, totalConsultations, positiveCases, negativeCases);
 
 
1235
  }
1236
- }, 100);
1237
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1238
 
1239
  function createFallbackChart(chartElement, dates, totalConsultations, positiveCases, negativeCases) {
1240
  console.log('Creando grafico de respaldo...');
 
1048
  });
1049
 
1050
  function createOrUpdateChart(dates, totalConsultations, positiveCases, negativeCases) {
1051
+ if (areaChartInstance && typeof areaChartInstance.destroy === 'function') {
1052
+ try {
1053
+ areaChartInstance.destroy();
1054
+ areaChartInstance = null;
1055
+ } catch (error) {
1056
+ console.log('Error destruyendo grafico anterior:', error);
1057
+ }
1058
+ }
 
 
 
 
 
 
1059
 
1060
+ const chartElement = document.querySelector("#areaChart");
1061
+ if (!chartElement) {
1062
+ console.error('Elemento #areaChart no encontrado');
1063
+ return;
1064
+ }
1065
 
1066
+ chartElement.innerHTML = '';
1067
+
1068
+ setTimeout(() => {
1069
+ try {
1070
+ const options = {
1071
+ chart: {
1072
+ type: 'area',
1073
+ height: 350,
1074
+ width: '100%',
1075
+ toolbar: {
1076
+ show: true,
1077
+ tools: {
1078
+ download: false,
1079
+ selection: false,
1080
+ zoom: false,
1081
+ zoomin: false,
1082
+ zoomout: false,
1083
+ pan: false,
1084
+ reset: false
1085
+ }
1086
+ },
1087
+ animations: {
1088
+ enabled: true,
1089
+ easing: 'easeinout',
1090
+ speed: 800
1091
+ },
1092
+ background: 'transparent'
1093
+ },
1094
+ colors: ['#2E93fA', '#FF9800', '#66DA26'],
1095
+ series: (function() {
1096
+ function toTs(d) {
1097
+ var p = d.split('-').map(Number);
1098
+ return Date.UTC(p[0], p[1] - 1, p[2], 12, 0, 0);
1099
+ }
1100
+ function toSeries(vals) {
1101
+ return dates.map(function(d, i) { return { x: toTs(d), y: vals[i] }; });
1102
+ }
1103
+ return [
1104
+ { name: 'Total Consultas', data: toSeries(totalConsultations) },
1105
+ { name: 'Con Retinopatía', data: toSeries(positiveCases) },
1106
+ { name: 'Sin Retinopatía', data: toSeries(negativeCases) }
1107
+ ];
1108
+ })(),
1109
+ xaxis: {
1110
+ type: 'datetime',
1111
+ labels: {
1112
+ datetimeUTC: false,
1113
+ datetimeFormatter: {
1114
+ year: 'yyyy',
1115
+ month: "MMM 'yy",
1116
+ day: 'dd/MM',
1117
+ hour: 'HH:mm'
1118
+ },
1119
+ style: {
1120
+ fontSize: '12px',
1121
+ fontFamily: 'inherit',
1122
+ colors: '#212529'
1123
+ }
1124
+ },
1125
+ title: {
1126
+ text: 'Fecha',
1127
+ style: {
1128
+ fontSize: '14px',
1129
+ fontFamily: 'inherit',
1130
+ color: '#212529'
1131
+ }
1132
+ }
1133
+ },
1134
+ yaxis: {
1135
+ title: {
1136
+ text: 'Número de Consultas',
1137
+ style: {
1138
+ fontSize: '14px',
1139
+ fontFamily: 'inherit',
1140
+ color: '#212529'
1141
+ }
1142
+ },
1143
+ min: 0,
1144
+ tickAmount: Math.max.apply(null, totalConsultations) || 1,
1145
+ labels: {
1146
+ formatter: function(val) { return Math.floor(val); },
1147
+ style: {
1148
+ fontSize: '12px',
1149
+ fontFamily: 'inherit',
1150
+ colors: '#212529'
1151
+ }
1152
+ }
1153
+ },
1154
+ tooltip: {
1155
+ shared: true,
1156
+ intersect: false,
1157
+ x: {
1158
+ formatter: function(value) {
1159
+ return new Date(value).toLocaleDateString('es-ES', {
1160
+ weekday: 'long',
1161
+ year: 'numeric',
1162
+ month: 'long',
1163
+ day: 'numeric'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1164
  });
1165
+ }
1166
+ },
1167
+ y: {
1168
+ formatter: function(value) {
1169
+ return value + ' consulta' + (value !== 1 ? 's' : '');
1170
+ }
1171
  }
1172
+ },
1173
+ stroke: {
1174
+ curve: 'smooth',
1175
+ width: 2
1176
+ },
1177
+ fill: {
1178
+ type: 'gradient',
1179
+ gradient: {
1180
+ shadeIntensity: 1,
1181
+ opacityFrom: 0.7,
1182
+ opacityTo: 0.3,
1183
+ stops: [0, 90, 100]
1184
+ }
1185
+ },
1186
+ legend: {
1187
+ position: 'top',
1188
+ horizontalAlign: 'left',
1189
+ labels: {
1190
+ colors: '#9aa0ac'
1191
+ }
1192
+ },
1193
+ grid: {
1194
+ borderColor: '#f1f1f1',
1195
+ strokeDashArray: 4,
1196
+ xaxis: {
1197
+ lines: {
1198
+ show: true
1199
+ }
1200
+ },
1201
+ yaxis: {
1202
+ lines: {
1203
+ show: true
1204
+ }
1205
+ }
1206
+ },
1207
+ dataLabels: {
1208
+ enabled: false
1209
+ },
1210
+ responsive: [{
1211
+ breakpoint: 768,
1212
+ options: {
1213
+ chart: {
1214
+ height: 300
1215
+ },
1216
+ legend: {
1217
+ position: 'bottom'
1218
+ }
1219
+ }
1220
+ }]
1221
+ };
1222
+
1223
+ areaChartInstance = new ApexCharts(chartElement, options);
1224
+
1225
+ areaChartInstance.render()
1226
+ .then(() => {
1227
+ console.log('Gráfico creado exitosamente');
1228
+ })
1229
+ .catch((error) => {
1230
+ console.error('Error renderizando gráfico:', error);
1231
+ createFallbackChart(chartElement, dates, totalConsultations, positiveCases, negativeCases);
1232
+ });
1233
+
1234
+ } catch (error) {
1235
+ console.error('Error creando gráfico:', error);
1236
+ createFallbackChart(chartElement, dates, totalConsultations, positiveCases, negativeCases);
1237
+ }
1238
+ }, 100);
1239
+ }
1240
 
1241
  function createFallbackChart(chartElement, dates, totalConsultations, positiveCases, negativeCases) {
1242
  console.log('Creando grafico de respaldo...');