UNPKG

saydata

Version:

Saydata seamlessly integrates AI-driven analytics for your customers into your app. Designed for beautiful visualization. Engineered for simplicity.

56 lines (55 loc) 2.54 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; import { useEffect, useState } from "react"; import CustomBar from "./Bar"; import CustomPie from "./Pie"; import CustomArea from "./Area"; import CustomLine from "./Line"; var Graphs = function (_a) { var options = _a.options, rows = _a.rows; var _b = useState(options), chartOptions = _b[0], setChartOptions = _b[1]; var _c = useState([]), formattedRows = _c[0], setFormattedRows = _c[1]; useEffect(function () { var _a; var newChartOptions = __assign({}, options); (_a = newChartOptions === null || newChartOptions === void 0 ? void 0 : newChartOptions.yCols) === null || _a === void 0 ? void 0 : _a.forEach(function (yCol) { var quantities = rows === null || rows === void 0 ? void 0 : rows.map(function (row) { return row === null || row === void 0 ? void 0 : row[yCol === null || yCol === void 0 ? void 0 : yCol.yCol]; }); yCol.min = Math.min.apply(Math, quantities); yCol.max = Math.max.apply(Math, quantities); }); setChartOptions(newChartOptions); var newRows = rows === null || rows === void 0 ? void 0 : rows.map(function (obj) { var newObj = __assign({}, obj); for (var key in newObj) { if (!isNaN(newObj[key])) { newObj[key] = parseFloat(newObj[key]); } } return newObj; }); setFormattedRows(newRows); }, [rows, options]); switch (chartOptions === null || chartOptions === void 0 ? void 0 : chartOptions.chartType) { case "line": return _jsx(CustomLine, { rows: formattedRows, chartOptions: chartOptions }); case "area": return _jsx(CustomArea, { rows: formattedRows, chartOptions: chartOptions }); case "bar": return _jsx(CustomBar, { rows: formattedRows, chartOptions: chartOptions }); case "pie": return _jsx(CustomPie, { rows: formattedRows, chartOptions: chartOptions }); default: return _jsx(_Fragment, {}); } }; export default Graphs;