Spaces:
Running
Running
show error message on invalid column type combo
Browse files- index.html +47 -0
index.html
CHANGED
|
@@ -364,6 +364,43 @@
|
|
| 364 |
(xIsNumeric || yIsNumeric));
|
| 365 |
}
|
| 366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
// Handle X axis selection
|
| 368 |
document.getElementById('xColSelect').addEventListener('change', async function(e) {
|
| 369 |
const xCol = e.target.value;
|
|
@@ -371,6 +408,11 @@
|
|
| 371 |
|
| 372 |
if (isValidCombination(xCol, yCol)) {
|
| 373 |
await renderVisualization(xCol, yCol, 'scatter');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
}
|
| 375 |
});
|
| 376 |
|
|
@@ -381,6 +423,11 @@
|
|
| 381 |
|
| 382 |
if (isValidCombination(xCol, yCol)) {
|
| 383 |
await renderVisualization(xCol, yCol, 'scatter');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
}
|
| 385 |
});
|
| 386 |
|
|
|
|
| 364 |
(xIsNumeric || yIsNumeric));
|
| 365 |
}
|
| 366 |
|
| 367 |
+
// Get error message for invalid column combination
|
| 368 |
+
function getInvalidCombinationError(xCol, yCol) {
|
| 369 |
+
if (!xCol || !yCol) {
|
| 370 |
+
return 'Please select both X and Y columns';
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
if (xCol === yCol) {
|
| 374 |
+
return 'Cannot visualize a column against itself. Please select different columns for X and Y axes';
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
const xColInfo = columnInfo.find(c => c.name === xCol);
|
| 378 |
+
const yColInfo = columnInfo.find(c => c.name === yCol);
|
| 379 |
+
|
| 380 |
+
if (!xColInfo || !yColInfo) {
|
| 381 |
+
return 'Selected column not found';
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
const xIsNumeric = isNumericType(xColInfo.type);
|
| 385 |
+
const xIsText = isTextType(xColInfo.type);
|
| 386 |
+
const yIsNumeric = isNumericType(yColInfo.type);
|
| 387 |
+
const yIsText = isTextType(yColInfo.type);
|
| 388 |
+
|
| 389 |
+
if (xIsText && yIsText) {
|
| 390 |
+
return `Cannot visualize text × text. At least one axis must be numeric. X: ${xColInfo.type}, Y: ${yColInfo.type}`;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
if (!xIsNumeric && !xIsText) {
|
| 394 |
+
return `X column type "${xColInfo.type}" is not supported. Please select a numeric or text column`;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
if (!yIsNumeric && !yIsText) {
|
| 398 |
+
return `Y column type "${yColInfo.type}" is not supported. Please select a numeric or text column`;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
return 'Invalid column combination';
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
// Handle X axis selection
|
| 405 |
document.getElementById('xColSelect').addEventListener('change', async function(e) {
|
| 406 |
const xCol = e.target.value;
|
|
|
|
| 408 |
|
| 409 |
if (isValidCombination(xCol, yCol)) {
|
| 410 |
await renderVisualization(xCol, yCol, 'scatter');
|
| 411 |
+
} else if (xCol || yCol) {
|
| 412 |
+
// Show error and clear visualization
|
| 413 |
+
const errorMsg = getInvalidCombinationError(xCol, yCol);
|
| 414 |
+
setStatus(errorMsg, 'error');
|
| 415 |
+
document.getElementById('vizContainer').innerHTML = '';
|
| 416 |
}
|
| 417 |
});
|
| 418 |
|
|
|
|
| 423 |
|
| 424 |
if (isValidCombination(xCol, yCol)) {
|
| 425 |
await renderVisualization(xCol, yCol, 'scatter');
|
| 426 |
+
} else if (xCol || yCol) {
|
| 427 |
+
// Show error and clear visualization
|
| 428 |
+
const errorMsg = getInvalidCombinationError(xCol, yCol);
|
| 429 |
+
setStatus(errorMsg, 'error');
|
| 430 |
+
document.getElementById('vizContainer').innerHTML = '';
|
| 431 |
}
|
| 432 |
});
|
| 433 |
|