@allurereport/web-commons 3.0.0-beta.16 → 3.0.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import type { SeverityLevel, TestStatus } from "@allurereport/core-api";
2
+ export declare const statusColors: Record<TestStatus, string>;
3
+ export declare const severityColors: Record<SeverityLevel, string>;
@@ -0,0 +1,14 @@
1
+ export const statusColors = {
2
+ failed: "var(--bg-support-capella)",
3
+ broken: "var(--bg-support-atlas)",
4
+ passed: "var(--bg-support-castor)",
5
+ skipped: "var(--bg-support-rau)",
6
+ unknown: "var(--bg-support-skat)",
7
+ };
8
+ export const severityColors = {
9
+ blocker: "var(--bg-support-capella)",
10
+ critical: "var(--bg-support-atlas)",
11
+ normal: "var(--bg-support-castor)",
12
+ minor: "var(--bg-support-rau)",
13
+ trivial: "var(--bg-support-skat)",
14
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./utils.js";
2
+ export type * from "./types.js";
3
+ export * from "./colors.js";
@@ -0,0 +1,2 @@
1
+ export * from "./utils.js";
2
+ export * from "./colors.js";
@@ -0,0 +1,48 @@
1
+ import type { BaseTrendSliceMetadata, ChartDataType, ChartId, ChartMode, ChartType, PieSlice, TrendPointId, TrendSlice, TrendSliceId } from "@allurereport/core-api";
2
+ export interface Point {
3
+ x: Date | string | number;
4
+ y: number;
5
+ }
6
+ export interface TrendChartItem {
7
+ id: string;
8
+ data: Point[];
9
+ color: string;
10
+ }
11
+ export interface ResponseTrendChartData<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> {
12
+ type: ChartType.Trend;
13
+ dataType: ChartDataType;
14
+ mode: ChartMode;
15
+ title?: string;
16
+ min: number;
17
+ max: number;
18
+ points: Record<TrendPointId, Point>;
19
+ slices: Record<TrendSliceId, TrendSlice<Metadata>>;
20
+ series: Record<SeriesType, TrendPointId[]>;
21
+ }
22
+ export type ChartsResponse<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = Record<ChartId, ResponseTrendChartData<SeriesType, Metadata>>;
23
+ export interface ResponsePieChartData {
24
+ type: ChartType.Pie;
25
+ title?: string;
26
+ percentage: number;
27
+ slices: PieSlice[];
28
+ }
29
+ export interface ResponseComingSoonChartData {
30
+ type: ChartType.HeatMap | ChartType.Bar | ChartType.Funnel | ChartType.TreeMap;
31
+ title?: string;
32
+ }
33
+ export interface UITrendChartData<Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> {
34
+ type: ChartType.Trend;
35
+ dataType: ChartDataType;
36
+ mode: ChartMode;
37
+ min: number;
38
+ max: number;
39
+ items: TrendChartItem[];
40
+ slices: TrendSlice<Metadata>[];
41
+ title?: string;
42
+ }
43
+ export type UIPieChartData = ResponsePieChartData;
44
+ export type UIComingSoonChartData = ResponseComingSoonChartData;
45
+ export type ChartData<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = ResponseTrendChartData<SeriesType, Metadata> | ResponsePieChartData | ResponseComingSoonChartData;
46
+ export type UIChartData<Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = UITrendChartData<Metadata> | UIPieChartData | UIComingSoonChartData;
47
+ export type ChartsData<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = Record<ChartId, ChartData<SeriesType, Metadata>>;
48
+ export type UIChartsData<Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = Record<ChartId, UIChartData<Metadata>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ChartId, SeverityLevel, TestStatus } from "@allurereport/core-api";
2
+ import type { ChartsData, ChartsResponse, ResponseTrendChartData, UIChartData, UITrendChartData } from "./types.js";
3
+ export declare const createTrendChartData: <T extends TestStatus | SeverityLevel>(getChart: () => ResponseTrendChartData | undefined, getGroups: () => readonly T[], getColor: (group: T) => string) => UITrendChartData | undefined;
4
+ export declare const createStatusTrendChartData: (chartId: ChartId, res: ChartsResponse) => UITrendChartData | undefined;
5
+ export declare const createSeverityTrendChartData: (chartId: ChartId, res: ChartsResponse) => UITrendChartData | undefined;
6
+ export declare const createaTrendChartData: (chartId: string, chartData: ResponseTrendChartData, res: ChartsData) => UITrendChartData | undefined;
7
+ export declare const createCharts: (res: ChartsData) => Record<ChartId, UIChartData>;
@@ -0,0 +1,59 @@
1
+ import { ChartDataType, ChartType, severityLevels, statusesList } from "@allurereport/core-api";
2
+ import { severityColors, statusColors } from "./colors.js";
3
+ export const createTrendChartData = (getChart, getGroups, getColor) => {
4
+ const chart = getChart();
5
+ if (!chart) {
6
+ return undefined;
7
+ }
8
+ const items = getGroups().reduce((acc, group) => {
9
+ const pointsByGroupBy = chart.series[group]?.map((pointId) => {
10
+ const point = chart.points[pointId];
11
+ return {
12
+ x: point.x,
13
+ y: point.y,
14
+ };
15
+ }) ?? [];
16
+ if (pointsByGroupBy.length) {
17
+ acc.push({
18
+ id: group.charAt(0).toUpperCase() + group.slice(1),
19
+ data: pointsByGroupBy,
20
+ color: getColor(group),
21
+ });
22
+ }
23
+ return acc;
24
+ }, []);
25
+ return {
26
+ type: chart.type,
27
+ dataType: chart.dataType,
28
+ mode: chart.mode,
29
+ title: chart.title,
30
+ items,
31
+ slices: Object.values(chart.slices),
32
+ min: chart.min,
33
+ max: chart.max,
34
+ };
35
+ };
36
+ export const createStatusTrendChartData = (chartId, res) => createTrendChartData(() => res[chartId], () => statusesList, (status) => statusColors[status]);
37
+ export const createSeverityTrendChartData = (chartId, res) => createTrendChartData(() => res[chartId], () => severityLevels, (severity) => severityColors[severity]);
38
+ export const createaTrendChartData = (chartId, chartData, res) => {
39
+ if (chartData.dataType === ChartDataType.Status) {
40
+ return createStatusTrendChartData(chartId, res);
41
+ }
42
+ else if (chartData.dataType === ChartDataType.Severity) {
43
+ return createSeverityTrendChartData(chartId, res);
44
+ }
45
+ };
46
+ export const createCharts = (res) => {
47
+ return Object.entries(res).reduce((acc, [chartId, chart]) => {
48
+ if (chart.type === ChartType.Trend) {
49
+ const chartData = createaTrendChartData(chartId, chart, res);
50
+ if (chartData) {
51
+ acc[chartId] = chartData;
52
+ }
53
+ }
54
+ else if ([ChartType.Pie, ChartType.HeatMap, ChartType.Bar, ChartType.Funnel, ChartType.TreeMap].includes(chart.type)) {
55
+ acc[chartId] = chart;
56
+ }
57
+ return acc;
58
+ }, {});
59
+ };
package/dist/data.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export const ALLURE_LIVE_RELOAD_HASH_STORAGE_KEY = "__allure_report_live_reload_hash__";
2
2
  export const createReportDataScript = (reportFiles = []) => {
3
- if (reportFiles.length === 0) {
3
+ if (!reportFiles?.length) {
4
4
  return `
5
5
  <script async>
6
6
  window.allureReportDataReady = true;
package/dist/index.d.ts CHANGED
@@ -3,8 +3,4 @@ export * from "./static.js";
3
3
  export * from "./attachments.js";
4
4
  export * from "./i18n.js";
5
5
  export * from "./strings.js";
6
- export * from "./charts.js";
7
- export * from "./charts/getPieChart.js";
8
- export * from "./charts/getPieChartDashboard.js";
9
- export * from "./charts/getSeverityTrendData.js";
10
- export * from "./charts/getStatusTrendData.js";
6
+ export * from "./charts/index.js";
package/dist/index.js CHANGED
@@ -3,8 +3,4 @@ export * from "./static.js";
3
3
  export * from "./attachments.js";
4
4
  export * from "./i18n.js";
5
5
  export * from "./strings.js";
6
- export * from "./charts.js";
7
- export * from "./charts/getPieChart.js";
8
- export * from "./charts/getPieChartDashboard.js";
9
- export * from "./charts/getSeverityTrendData.js";
10
- export * from "./charts/getStatusTrendData.js";
6
+ export * from "./charts/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/web-commons",
3
- "version": "3.0.0-beta.16",
3
+ "version": "3.0.0-beta.18",
4
4
  "description": "Collection of utilities used across the web Allure reports",
5
5
  "keywords": [
6
6
  "allure",
@@ -23,18 +23,16 @@
23
23
  "clean": "rimraf ./dist"
24
24
  },
25
25
  "dependencies": {
26
- "@allurereport/core-api": "3.0.0-beta.16"
26
+ "@allurereport/core-api": "3.0.0-beta.18"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@stylistic/eslint-plugin": "^2.6.1",
30
- "@types/d3-shape": "^3.1.6",
31
30
  "@types/eslint": "^8.56.11",
32
31
  "@typescript-eslint/eslint-plugin": "^8.0.0",
33
32
  "@typescript-eslint/parser": "^8.0.0",
34
33
  "@vitest/runner": "^2.1.9",
35
- "allure-js-commons": "^3.0.9",
36
- "allure-vitest": "^3.0.9",
37
- "d3-shape": "^3.2.0",
34
+ "allure-js-commons": "^3.3.0",
35
+ "allure-vitest": "^3.3.0",
38
36
  "eslint": "^8.57.0",
39
37
  "eslint-config-prettier": "^9.1.0",
40
38
  "eslint-plugin-import": "^2.29.1",
@@ -1,10 +0,0 @@
1
- import type { Statistic, TestStatus } from "@allurereport/core-api";
2
- export type TestResultSlice = {
3
- status: TestStatus;
4
- count: number;
5
- };
6
- export type TestResultChartData = {
7
- percentage: number;
8
- slices: TestResultSlice[];
9
- };
10
- export declare const getPieChartData: (stats: Statistic) => TestResultChartData;
@@ -1,20 +0,0 @@
1
- import { statusesList } from "@allurereport/core-api";
2
- import { d3Arc, d3Pie, getPercentage } from "../charts.js";
3
- export const getPieChartData = (stats) => {
4
- const convertedStatuses = statusesList
5
- .filter((status) => !!stats?.[status])
6
- .map((status) => ({
7
- status,
8
- count: stats[status],
9
- }));
10
- const arcsData = d3Pie(convertedStatuses);
11
- const slices = arcsData.map((arcData) => ({
12
- d: d3Arc(arcData),
13
- ...arcData.data,
14
- }));
15
- const percentage = getPercentage(stats.passed ?? 0, stats.total);
16
- return {
17
- slices,
18
- percentage,
19
- };
20
- };
@@ -1,3 +0,0 @@
1
- import type { Statistic } from "@allurereport/core-api";
2
- import type { PieChartData, PieChartOptions } from "../charts.js";
3
- export declare const getPieChartDataDashboard: (stats: Statistic, chartOptions: PieChartOptions) => PieChartData;
@@ -1,22 +0,0 @@
1
- import { statusesList } from "@allurereport/core-api";
2
- import { d3Arc, d3Pie, getPercentage } from "../charts.js";
3
- export const getPieChartDataDashboard = (stats, chartOptions) => {
4
- const convertedStatuses = statusesList
5
- .filter((status) => !!stats?.[status])
6
- .map((status) => ({
7
- status,
8
- count: stats[status],
9
- }));
10
- const arcsData = d3Pie(convertedStatuses);
11
- const slices = arcsData.map((arcData) => ({
12
- d: d3Arc(arcData),
13
- ...arcData.data,
14
- }));
15
- const percentage = getPercentage(stats.passed ?? 0, stats.total);
16
- return {
17
- type: chartOptions.type,
18
- title: chartOptions?.title,
19
- slices,
20
- percentage,
21
- };
22
- };
@@ -1,3 +0,0 @@
1
- import type { HistoryDataPoint, TestResult } from "@allurereport/core-api";
2
- import type { SeverityTrendChartData, TrendChartOptions } from "../charts.js";
3
- export declare const getSeverityTrendData: (testResults: TestResult[], reportName: string, historyPoints: HistoryDataPoint[], chartOptions: TrendChartOptions) => SeverityTrendChartData;
@@ -1,47 +0,0 @@
1
- import { severityLabelName, severityLevels } from "@allurereport/core-api";
2
- import { createEmptySeries, createEmptyStats, getTrendDataGeneric, mergeTrendDataGeneric, normalizeStatistic, } from "../charts.js";
3
- export const getSeverityTrendData = (testResults, reportName, historyPoints, chartOptions) => {
4
- const { limit } = chartOptions;
5
- const historyLimit = limit && limit > 0 ? Math.max(0, limit - 1) : undefined;
6
- const limitedHistoryPoints = historyLimit !== undefined ? historyPoints.slice(-historyLimit) : historyPoints;
7
- const firstOriginalIndex = historyLimit !== undefined ? Math.max(0, historyPoints.length - historyLimit) : 0;
8
- const convertedHistoryPoints = limitedHistoryPoints.map((point, index) => {
9
- const originalIndex = firstOriginalIndex + index;
10
- return {
11
- name: point.name,
12
- originalIndex,
13
- statistic: Object.values(point.testResults).reduce((stat, test) => {
14
- const severityLabel = test.labels?.find((label) => label.name === severityLabelName);
15
- const severity = severityLabel?.value?.toLowerCase();
16
- if (severity) {
17
- stat[severity] = (stat[severity] ?? 0) + 1;
18
- }
19
- return stat;
20
- }, createEmptyStats(severityLevels)),
21
- };
22
- });
23
- const currentSeverityStats = testResults.reduce((acc, test) => {
24
- const severityLabel = test.labels.find((label) => label.name === severityLabelName);
25
- const severity = severityLabel?.value?.toLowerCase();
26
- if (severity) {
27
- acc[severity] = (acc[severity] ?? 0) + 1;
28
- }
29
- return acc;
30
- }, createEmptyStats(severityLevels));
31
- const currentTrendData = getTrendDataGeneric(normalizeStatistic(currentSeverityStats, severityLevels), reportName, historyPoints.length + 1, severityLevels, chartOptions);
32
- const historicalTrendData = convertedHistoryPoints.reduce((acc, historyPoint) => {
33
- const trendDataPart = getTrendDataGeneric(normalizeStatistic(historyPoint.statistic, severityLevels), historyPoint.name, historyPoint.originalIndex + 1, severityLevels, chartOptions);
34
- return mergeTrendDataGeneric(acc, trendDataPart, severityLevels);
35
- }, {
36
- type: chartOptions.type,
37
- dataType: chartOptions.dataType,
38
- mode: chartOptions.mode,
39
- title: chartOptions.title,
40
- points: {},
41
- slices: {},
42
- series: createEmptySeries(severityLevels),
43
- min: Infinity,
44
- max: -Infinity,
45
- });
46
- return mergeTrendDataGeneric(historicalTrendData, currentTrendData, severityLevels);
47
- };
@@ -1,3 +0,0 @@
1
- import type { HistoryDataPoint, Statistic } from "@allurereport/core-api";
2
- import type { StatusTrendChartData, TrendChartOptions } from "../charts.js";
3
- export declare const getStatusTrendData: (currentStatistic: Statistic, reportName: string, historyPoints: HistoryDataPoint[], chartOptions: TrendChartOptions) => StatusTrendChartData;
@@ -1,38 +0,0 @@
1
- import { statusesList } from "@allurereport/core-api";
2
- import { createEmptySeries, createEmptyStats, getTrendDataGeneric, mergeTrendDataGeneric, normalizeStatistic, } from "../charts.js";
3
- export const getStatusTrendData = (currentStatistic, reportName, historyPoints, chartOptions) => {
4
- const { limit } = chartOptions;
5
- const historyLimit = limit && limit > 0 ? Math.max(0, limit - 1) : undefined;
6
- const limitedHistoryPoints = historyLimit !== undefined ? historyPoints.slice(-historyLimit) : historyPoints;
7
- const firstOriginalIndex = historyLimit !== undefined ? Math.max(0, historyPoints.length - historyLimit) : 0;
8
- const convertedHistoryPoints = limitedHistoryPoints.map((point, index) => {
9
- const originalIndex = firstOriginalIndex + index;
10
- return {
11
- name: point.name,
12
- originalIndex,
13
- statistic: Object.values(point.testResults).reduce((stat, test) => {
14
- if (test.status) {
15
- stat[test.status] = (stat[test.status] ?? 0) + 1;
16
- stat.total = (stat.total ?? 0) + 1;
17
- }
18
- return stat;
19
- }, { total: 0, ...createEmptyStats(statusesList) }),
20
- };
21
- });
22
- const currentTrendData = getTrendDataGeneric(normalizeStatistic(currentStatistic, statusesList), reportName, historyPoints.length + 1, statusesList, chartOptions);
23
- const historicalTrendData = convertedHistoryPoints.reduce((acc, historyPoint) => {
24
- const trendDataPart = getTrendDataGeneric(normalizeStatistic(historyPoint.statistic, statusesList), historyPoint.name, historyPoint.originalIndex + 1, statusesList, chartOptions);
25
- return mergeTrendDataGeneric(acc, trendDataPart, statusesList);
26
- }, {
27
- type: chartOptions.type,
28
- dataType: chartOptions.dataType,
29
- mode: chartOptions.mode,
30
- title: chartOptions.title,
31
- points: {},
32
- slices: {},
33
- series: createEmptySeries(statusesList),
34
- min: Infinity,
35
- max: -Infinity,
36
- });
37
- return mergeTrendDataGeneric(historicalTrendData, currentTrendData, statusesList);
38
- };
package/dist/charts.d.ts DELETED
@@ -1,110 +0,0 @@
1
- import type { SeverityLevel, TestResult, TestStatus } from "@allurereport/core-api";
2
- import type { PieArcDatum } from "d3-shape";
3
- export type BasePieSlice = Pick<PieSlice, "status" | "count">;
4
- export declare const DEFAULT_CHART_HISTORY_LIMIT = 10;
5
- export declare const d3Arc: import("d3-shape").Arc<any, PieArcDatum<BasePieSlice>>;
6
- export declare const d3Pie: import("d3-shape").Pie<any, BasePieSlice>;
7
- export declare const getPercentage: (value: number, total: number) => number;
8
- export declare enum ChartType {
9
- Trend = "trend",
10
- Pie = "pie"
11
- }
12
- export declare enum ChartDataType {
13
- Status = "status",
14
- Severity = "severity"
15
- }
16
- export declare enum ChartMode {
17
- Raw = "raw",
18
- Percent = "percent"
19
- }
20
- export type ChartId = string;
21
- export type ExecutionIdFn = (executionOrder: number) => string;
22
- export type ExecutionNameFn = (executionOrder: number) => string;
23
- export type TrendMetadataFnOverrides = {
24
- executionIdAccessor?: ExecutionIdFn;
25
- executionNameAccessor?: ExecutionNameFn;
26
- };
27
- export type TrendChartOptions = {
28
- type: ChartType.Trend;
29
- dataType: ChartDataType;
30
- mode?: ChartMode;
31
- title?: string;
32
- limit?: number;
33
- metadata?: TrendMetadataFnOverrides;
34
- };
35
- export type TrendPointId = string;
36
- export type TrendSliceId = string;
37
- export type BaseMetadata = Record<string, unknown>;
38
- export interface BaseTrendSliceMetadata extends Record<string, unknown> {
39
- executionId: string;
40
- executionName: string;
41
- }
42
- export type TrendSliceMetadata<Metadata extends BaseMetadata> = BaseTrendSliceMetadata & Metadata;
43
- export type TrendPoint = {
44
- x: string;
45
- y: number;
46
- };
47
- export type TrendSlice<Metadata extends BaseMetadata> = {
48
- min: number;
49
- max: number;
50
- metadata: TrendSliceMetadata<Metadata>;
51
- };
52
- export type GenericTrendChartData<Metadata extends BaseMetadata, SeriesType extends string> = {
53
- type: ChartType.Trend;
54
- dataType: ChartDataType;
55
- mode: ChartMode;
56
- title?: string;
57
- points: Record<TrendPointId, TrendPoint>;
58
- slices: Record<TrendSliceId, TrendSlice<Metadata>>;
59
- series: Record<SeriesType, TrendPointId[]>;
60
- min: number;
61
- max: number;
62
- };
63
- export interface StatusMetadata extends BaseTrendSliceMetadata {
64
- }
65
- export type StatusTrendSliceMetadata = TrendSliceMetadata<StatusMetadata>;
66
- export type StatusTrendSlice = TrendSlice<StatusTrendSliceMetadata>;
67
- export type StatusTrendChartData = GenericTrendChartData<StatusTrendSliceMetadata, TestStatus>;
68
- export interface SeverityMetadata extends BaseTrendSliceMetadata {
69
- }
70
- export type SeverityTrendSliceMetadata = TrendSliceMetadata<SeverityMetadata>;
71
- export type SeverityTrendSlice = TrendSlice<SeverityTrendSliceMetadata>;
72
- export type SeverityTrendChartData = GenericTrendChartData<SeverityTrendSliceMetadata, SeverityLevel>;
73
- export type TrendChartData = StatusTrendChartData | SeverityTrendChartData;
74
- export type PieChartOptions = {
75
- type: ChartType.Pie;
76
- title?: string;
77
- };
78
- export type PieSlice = {
79
- status: TestStatus;
80
- count: number;
81
- d: string | null;
82
- };
83
- export type PieChartData = {
84
- type: ChartType.Pie;
85
- title?: string;
86
- slices: PieSlice[];
87
- percentage: number;
88
- };
89
- export type GeneratedChartData = TrendChartData | PieChartData;
90
- export type GeneratedChartsData = Record<ChartId, GeneratedChartData>;
91
- export type ChartOptions = TrendChartOptions | PieChartOptions;
92
- export type DashboardOptions = {
93
- reportName?: string;
94
- singleFile?: boolean;
95
- logo?: string;
96
- theme?: "light" | "dark";
97
- reportLanguage?: "en" | "ru";
98
- layout?: ChartOptions[];
99
- filter?: (testResult: TestResult) => boolean;
100
- };
101
- export type TrendDataType = TestStatus | SeverityLevel;
102
- export type TrendCalculationResult<T extends TrendDataType> = {
103
- points: Record<TrendPointId, TrendPoint>;
104
- series: Record<T, TrendPointId[]>;
105
- };
106
- export declare const createEmptyStats: <T extends TrendDataType>(items: readonly T[]) => Record<T, number>;
107
- export declare const createEmptySeries: <T extends TrendDataType>(items: readonly T[]) => Record<T, string[]>;
108
- export declare const normalizeStatistic: <T extends TrendDataType>(statistic: Partial<Record<T, number>>, itemType: readonly T[]) => Record<T, number>;
109
- export declare const mergeTrendDataGeneric: <M extends BaseTrendSliceMetadata, T extends TrendDataType>(trendData: GenericTrendChartData<M, T>, trendDataPart: GenericTrendChartData<M, T>, itemType: readonly T[]) => GenericTrendChartData<M, T>;
110
- export declare const getTrendDataGeneric: <M extends BaseTrendSliceMetadata, T extends TrendDataType>(stats: Record<T, number>, reportName: string, executionOrder: number, itemType: readonly T[], chartOptions: TrendChartOptions) => GenericTrendChartData<M, T>;
package/dist/charts.js DELETED
@@ -1,124 +0,0 @@
1
- import { arc, pie } from "d3-shape";
2
- export const DEFAULT_CHART_HISTORY_LIMIT = 10;
3
- export const d3Arc = arc().innerRadius(40).outerRadius(50).cornerRadius(2).padAngle(0.03);
4
- export const d3Pie = pie()
5
- .value((d) => d.count)
6
- .padAngle(0.03)
7
- .sortValues((a, b) => a - b);
8
- export const getPercentage = (value, total) => Math.floor((value / total) * 10000) / 100;
9
- export var ChartType;
10
- (function (ChartType) {
11
- ChartType["Trend"] = "trend";
12
- ChartType["Pie"] = "pie";
13
- })(ChartType || (ChartType = {}));
14
- export var ChartDataType;
15
- (function (ChartDataType) {
16
- ChartDataType["Status"] = "status";
17
- ChartDataType["Severity"] = "severity";
18
- })(ChartDataType || (ChartDataType = {}));
19
- export var ChartMode;
20
- (function (ChartMode) {
21
- ChartMode["Raw"] = "raw";
22
- ChartMode["Percent"] = "percent";
23
- })(ChartMode || (ChartMode = {}));
24
- export const createEmptyStats = (items) => items.reduce((acc, item) => ({ ...acc, [item]: 0 }), {});
25
- export const createEmptySeries = (items) => items.reduce((acc, item) => ({ ...acc, [item]: [] }), {});
26
- export const normalizeStatistic = (statistic, itemType) => {
27
- return itemType.reduce((acc, item) => {
28
- acc[item] = statistic[item] ?? 0;
29
- return acc;
30
- }, {});
31
- };
32
- const calculateRawValues = (stats, executionId, itemType) => {
33
- const points = {};
34
- const series = createEmptySeries(itemType);
35
- itemType.forEach((item) => {
36
- const pointId = `${executionId}-${item}`;
37
- const value = stats[item] ?? 0;
38
- points[pointId] = {
39
- x: executionId,
40
- y: value,
41
- };
42
- series[item].push(pointId);
43
- });
44
- return { points, series };
45
- };
46
- const calculatePercentValues = (stats, executionId, itemType) => {
47
- const points = {};
48
- const series = createEmptySeries(itemType);
49
- const values = Object.values(stats);
50
- const total = values.reduce((sum, value) => sum + value, 0);
51
- if (total === 0) {
52
- return { points, series };
53
- }
54
- itemType.forEach((item) => {
55
- const pointId = `${executionId}-${item}`;
56
- const value = stats[item] ?? 0;
57
- points[pointId] = {
58
- x: executionId,
59
- y: value / total,
60
- };
61
- series[item].push(pointId);
62
- });
63
- return { points, series };
64
- };
65
- export const mergeTrendDataGeneric = (trendData, trendDataPart, itemType) => {
66
- return {
67
- ...trendData,
68
- points: {
69
- ...trendData.points,
70
- ...trendDataPart.points,
71
- },
72
- slices: {
73
- ...trendData.slices,
74
- ...trendDataPart.slices,
75
- },
76
- series: Object.entries(trendDataPart.series).reduce((series, [group, pointIds]) => {
77
- if (Array.isArray(pointIds)) {
78
- return {
79
- ...series,
80
- [group]: [...(trendData.series?.[group] || []), ...pointIds],
81
- };
82
- }
83
- return series;
84
- }, trendData.series || createEmptySeries(itemType)),
85
- min: Math.min(trendData.min ?? Infinity, trendDataPart.min),
86
- max: Math.max(trendData.max ?? -Infinity, trendDataPart.max),
87
- };
88
- };
89
- export const getTrendDataGeneric = (stats, reportName, executionOrder, itemType, chartOptions) => {
90
- const { type, dataType, title, mode = ChartMode.Raw, metadata = {} } = chartOptions;
91
- const { executionIdAccessor, executionNameAccessor } = metadata;
92
- const executionId = executionIdAccessor ? executionIdAccessor(executionOrder) : `execution-${executionOrder}`;
93
- const { points, series } = mode === ChartMode.Percent
94
- ? calculatePercentValues(stats, executionId, itemType)
95
- : calculateRawValues(stats, executionId, itemType);
96
- const slices = {};
97
- const pointsAsArray = Object.values(points);
98
- const pointsCount = pointsAsArray.length;
99
- const values = pointsAsArray.map((point) => point.y);
100
- const min = pointsCount ? Math.min(...values) : 0;
101
- const max = pointsCount ? Math.max(...values) : 0;
102
- if (pointsCount > 0) {
103
- const executionName = executionNameAccessor ? executionNameAccessor(executionOrder) : reportName;
104
- slices[executionId] = {
105
- min,
106
- max,
107
- metadata: {
108
- executionId,
109
- executionName,
110
- },
111
- };
112
- }
113
- return {
114
- type,
115
- dataType,
116
- mode,
117
- title,
118
- points,
119
- slices,
120
- series,
121
- min,
122
- max,
123
- };
124
- };