UNPKG

wcz-layout

Version:

211 lines (210 loc) • 5.36 kB
import { c } from "react/compiler-runtime"; import { Box } from "@mui/material"; import { jsx } from "react/jsx-runtime"; import { areaX, areaY, arrow, bandX, bandY, barX, barY, boxX, boxY, cell, colorLegend, crosshair, defineChart, differenceX, differenceY, dot, frame, hexagon, lineX, lineY, linearRegressionX, linearRegressionY, link, rect, ridgelineX, ridgelineY, ruleX, ruleY, text, tickX, tickY, vector, violinX, violinY, waffleX, waffleY } from "@tanstack/charts"; import { Chart } from "@tanstack/charts/react"; import { scaleBand } from "@tanstack/charts/scales/band"; import { scaleLinear } from "@tanstack/charts/scales/linear"; import { scalePoint } from "@tanstack/charts/scales/point"; import { tooltip } from "@tanstack/charts/tooltip"; // src/components/chat/generatedChart.tsx const marks = { areaX, areaY, arrow, bandX, bandY, barX, barY, boxX, boxY, cell, crosshair, differenceX, differenceY, dot, frame, hexagon, lineX, lineY, linearRegressionX, linearRegressionY, link, rect, ridgelineX, ridgelineY, ruleX, ruleY, text, tickX, tickY, vector, violinX, violinY, waffleX, waffleY }; const LIGHT = [ "#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#e87ba4", "#008300", "#6250d6", "#e34948" ]; const DARK = [ "#3987e5", "#d95926", "#199e70", "#c98500", "#d55181", "#008300", "#9085e9", "#e66767" ]; const SERIES = LIGHT.map((_, index) => `var(--ts-chart-${index + 1})`); const palette = (colors) => Object.fromEntries(colors.map((color, index) => [`--ts-chart-${index + 1}`, color])); const BARS = { maxThickness: 24, radius: { end: 4 } }; const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value); function positionScale(spec) { if (spec === null) return null; const { scale, padding, domain, ...options } = isRecord(spec) ? spec : {}; const gap = typeof padding === "number" ? padding : void 0; const make = () => { const made = scale === "band" ? scaleBand().padding(gap ?? .2) : scale === "point" ? scalePoint().padding(gap ?? .5) : scaleLinear(); return Array.isArray(domain) ? made.domain(domain) : made; }; return { ...options, scale: Array.isArray(domain) ? make() : make }; } function markOf(node) { if (!isRecord(node) || typeof node.type !== "string" || !Object.hasOwn(marks, node.type)) return []; const type = node.type; const { data, ...options } = isRecord(node.props) ? node.props : {}; const make = marks[type]; if (type === "crosshair" || type === "frame") return [make(options)]; return [make(Array.isArray(data) ? data : [], type === "barX" || type === "barY" ? { ...BARS, ...options } : options)]; } /** A `Chart` node: its mark children drawn on its scales, with the default tooltip. */ function GeneratedChart(t0) { const $ = c(25); const { node } = t0; let t1; if ($[0] !== node.props) { t1 = isRecord(node.props) ? node.props : {}; $[0] = node.props; $[1] = t1; } else t1 = $[1]; const props = t1; let ariaDescription; let ariaLabel; let aspectRatio; let height; let t2; if ($[2] !== node.children || $[3] !== props) { const { scales, color, ariaLabel: t3, ariaDescription: t4, height: t5, aspectRatio: t6, children, ...spec } = props; ariaLabel = t3; ariaDescription = t4; height = t5; aspectRatio = t6; let t7; if ($[9] !== scales) { t7 = isRecord(scales) ? scales : {}; $[9] = scales; $[10] = t7; } else t7 = $[10]; const { x, y } = t7; let t8; if ($[11] !== color) { t8 = isRecord(color) ? color : {}; $[11] = color; $[12] = t8; } else t8 = $[12]; const { legend, ...colors } = t8; const nodes = node.children ?? children; let t9; if ($[13] !== nodes) { t9 = Array.isArray(nodes) ? nodes : []; $[13] = nodes; $[14] = t9; } else t9 = $[14]; t2 = defineChart({ ...spec, marks: t9.flatMap(markOf), scales: { x: positionScale(x), y: positionScale(y) }, color: { range: SERIES, ...colors, ...legend ? { legend: colorLegend(isRecord(legend) ? legend : {}) } : {} }, tooltip }); $[2] = node.children; $[3] = props; $[4] = ariaDescription; $[5] = ariaLabel; $[6] = aspectRatio; $[7] = height; $[8] = t2; } else { ariaDescription = $[4]; ariaLabel = $[5]; aspectRatio = $[6]; height = $[7]; t2 = $[8]; } const definition = t2; const t3 = typeof ariaLabel === "string" ? ariaLabel : "Chart"; let t4; if ($[15] !== ariaDescription) { t4 = typeof ariaDescription === "string" && { ariaDescription }; $[15] = ariaDescription; $[16] = t4; } else t4 = $[16]; let t5; if ($[17] !== aspectRatio || $[18] !== height) { t5 = typeof aspectRatio === "number" ? { aspectRatio } : { height: typeof height === "number" ? height : 280 }; $[17] = aspectRatio; $[18] = height; $[19] = t5; } else t5 = $[19]; let t6; if ($[20] !== definition || $[21] !== t3 || $[22] !== t4 || $[23] !== t5) { t6 = /* @__PURE__ */ jsx(Box, { sx: _temp, children: /* @__PURE__ */ jsx(Chart, { definition, ariaLabel: t3, ...t4, ...t5 }) }); $[20] = definition; $[21] = t3; $[22] = t4; $[23] = t5; $[24] = t6; } else t6 = $[24]; return t6; } function _temp(theme) { return { ...palette(LIGHT), ...theme.applyStyles("dark", palette(DARK)) }; } export { GeneratedChart }; //# sourceMappingURL=generatedChart-k7NEdi5Z.mjs.map