UNPKG

@allurereport/plugin-classic

Version:

The classic version of Allure HTML report

27 lines (26 loc) 880 B
import { statusesList } from "@allurereport/core-api"; import { arc, pie } from "d3-shape"; export const d3Arc = arc().innerRadius(40).outerRadius(50).cornerRadius(2).padAngle(0.03); export const d3Pie = pie() .value((d) => d.count) .padAngle(0.03) .sortValues((a, b) => a - b); export const getPercentage = (value, total) => Math.floor((value / total) * 10000) / 100; export const getChartData = (stats) => { const convertedStatuses = statusesList .filter((status) => !!stats?.[status]) .map((status) => ({ status, count: stats[status], })); const arcsData = d3Pie(convertedStatuses); const slices = arcsData.map((arcData) => ({ d: d3Arc(arcData), ...arcData.data, })); const percentage = getPercentage(stats.passed ?? 0, stats.total); return { slices, percentage, }; };