latest changes--

This commit is contained in:
2026-06-03 17:47:30 +05:30
parent b709add3b6
commit 16a7fba7cf
2 changed files with 107 additions and 107 deletions
+106 -106
View File
@@ -13,20 +13,20 @@ import vegaEmbed, {
type Result, type Result,
} from "vega-embed"; } from "vega-embed";
import * as XLSX from "xlsx"; // import * as XLSX from "xlsx";
import { saveAs } from "file-saver"; // import { saveAs } from "file-saver";
import jsPDF from "jspdf"; // import jsPDF from "jspdf";
import html2canvas from "html2canvas"; // import html2canvas from "html2canvas";
import { import {
AlertTriangle, AlertTriangle,
Download, // Download,
FileSpreadsheet, // FileSpreadsheet,
FileText, // FileText,
ImageIcon, // ImageIcon,
RefreshCcw, RefreshCcw,
Sparkles, Sparkles,
CheckCircle2, CheckCircle2,
@@ -424,8 +424,8 @@ function VegaLiteArtifact({
const [renderError, setRenderError] = useState(""); const [renderError, setRenderError] = useState("");
const [vegaResult, setVegaResult] = // const [vegaResult, setVegaResult] =
useState<Result | null>(null); // useState<Result | null>(null);
const [activeTab, setActiveTab] = useState< const [activeTab, setActiveTab] = useState<
"answer" | "chart" | "sql" "answer" | "chart" | "sql"
@@ -492,7 +492,7 @@ function VegaLiteArtifact({
); );
} }
setVegaResult(result); // setVegaResult(result);
} catch (finalError) { } catch (finalError) {
console.error( console.error(
"FINAL VEGA ERROR =>", "FINAL VEGA ERROR =>",
@@ -520,143 +520,143 @@ function VegaLiteArtifact({
GET VALUES GET VALUES
===================================================== */ ===================================================== */
const getValues = () => { // const getValues = () => {
const data = (safeSpec as any)?.data; // const data = (safeSpec as any)?.data;
if ( // if (
!data?.values || // !data?.values ||
!Array.isArray(data.values) // !Array.isArray(data.values)
) { // ) {
return []; // return [];
} // }
return data.values; // return data.values;
}; // };
/* ===================================================== /* =====================================================
EXPORT EXCEL EXPORT EXCEL
===================================================== */ ===================================================== */
const downloadExcel = () => { // const downloadExcel = () => {
const values = getValues(); // const values = getValues();
if (!values.length) { // if (!values.length) {
alert("No data available"); // alert("No data available");
return; // return;
} // }
const worksheet = // const worksheet =
XLSX.utils.json_to_sheet(values); // XLSX.utils.json_to_sheet(values);
const workbook = // const workbook =
XLSX.utils.book_new(); // XLSX.utils.book_new();
XLSX.utils.book_append_sheet( // XLSX.utils.book_append_sheet(
workbook, // workbook,
worksheet, // worksheet,
"Chart Data", // "Chart Data",
); // );
const excelBuffer = XLSX.write( // const excelBuffer = XLSX.write(
workbook, // workbook,
{ // {
bookType: "xlsx", // bookType: "xlsx",
type: "array", // type: "array",
}, // },
); // );
const blob = new Blob( // const blob = new Blob(
[excelBuffer], // [excelBuffer],
{ // {
type: // type:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
}, // },
); // );
saveAs(blob, "chart-data.xlsx"); // saveAs(blob, "chart-data.xlsx");
}; // };
/* ===================================================== /* =====================================================
EXPORT CSV EXPORT CSV
===================================================== */ ===================================================== */
const downloadCSV = () => { // const downloadCSV = () => {
const values = getValues(); // const values = getValues();
if (!values.length) { // if (!values.length) {
alert("No data available"); // alert("No data available");
return; // return;
} // }
const headers = Object.keys( // const headers = Object.keys(
values[0], // values[0],
); // );
const csvRows = [ // const csvRows = [
headers.join(","), // headers.join(","),
...values.map((row: any) => // ...values.map((row: any) =>
headers // headers
.map((field) => row[field]) // .map((field) => row[field])
.join(","), // .join(","),
), // ),
]; // ];
const blob = new Blob( // const blob = new Blob(
[csvRows.join("\n")], // [csvRows.join("\n")],
{ // {
type: "text/csv", // type: "text/csv",
}, // },
); // );
saveAs(blob, "chart-data.csv"); // saveAs(blob, "chart-data.csv");
}; // };
/* ===================================================== /* =====================================================
EXPORT PDF EXPORT PDF
===================================================== */ ===================================================== */
const downloadPDF = async () => { // const downloadPDF = async () => {
if (!chartRef.current) return; // if (!chartRef.current) return;
const canvas = // const canvas =
await html2canvas( // await html2canvas(
chartRef.current, // chartRef.current,
); // );
const image = // const image =
canvas.toDataURL("image/png"); // canvas.toDataURL("image/png");
const pdf = new jsPDF( // const pdf = new jsPDF(
"landscape", // "landscape",
); // );
pdf.addImage( // pdf.addImage(
image, // image,
"PNG", // "PNG",
10, // 10,
10, // 10,
270, // 270,
150, // 150,
); // );
pdf.save("chart-report.pdf"); // pdf.save("chart-report.pdf");
}; // };
/* ===================================================== /* =====================================================
EXPORT PNG EXPORT PNG
===================================================== */ ===================================================== */
const downloadPNG = async () => { // const downloadPNG = async () => {
if (!vegaResult) return; // if (!vegaResult) return;
const imageURL = // const imageURL =
await vegaResult.view.toImageURL( // await vegaResult.view.toImageURL(
"png", // "png",
); // );
saveAs(imageURL, "chart.png"); // saveAs(imageURL, "chart.png");
}; // };
/* ===================================================== /* =====================================================
RETRY RETRY
+1 -1
View File
@@ -154,7 +154,7 @@ export default function Login() {
text-transparent text-transparent
" "
> >
GenBI Yoda
</h1> </h1>
<p className="mt-2 text-sm text-slate-500"> <p className="mt-2 text-sm text-slate-500">