UNPKG

@antv/t8

Version:

T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative JSON Schema syntax that can be used to describe the content of data interpretation reports.

46 lines (44 loc) 1.45 kB
/** * Generates an SVG arc path representing a proportion of a circle * Used to create pie/circle segments for proportion visualization * * @param size - The diameter of the circle * @param data - The proportion value (between 0 and 1) * @returns An SVG path string for the arc */ function getArcPath(size, data) { // Calculate center coordinates var cx = size / 2; var cy = size / 2; // Calculate radius var r = size / 2; // Convert proportion to angle in radians var angle = normalizeProportion(data) * 2 * Math.PI; // Calculate end point coordinates using trigonometry var dx = cx + r * Math.sin(angle); var dy = cy - r * Math.cos(angle); // Create SVG path: // M - Move to top center of circle // A - Draw an arc // L - Draw line to center // Z - Close path var path = "\n M".concat(cx, " ").concat(0, "\n A ").concat(cx, " ").concat(cy, " 0 ").concat(angle > Math.PI ? 1 : 0, " 1 ").concat(dx, " ").concat(dy, "\n L ").concat(cx, " ").concat(cy, " Z\n "); return path; } /** * Ensures the proportion value is between 0 and 1 * * @param data - Input proportion value * @returns Normalized value between 0 and 1 */ function normalizeProportion(data) { if (typeof data !== 'number') return 0; if (data > 1) return 1; if (data < 0) return 0; return data; } export { getArcPath }; //# sourceMappingURL=getArcPath.js.map