UNPKG

cucumber-html-report-generator

Version:

Generate beautiful cucumberjs html reports for multiple instances (browsers / devices)

69 lines 2.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HtmlScriptsFunctions = void 0; const chart_js_1 = require("chart.js"); const chartjs_plugin_datalabels_1 = __importDefault(require("chartjs-plugin-datalabels")); class HtmlScriptsFunctions { constructor(theme) { this.document = {}; this.graphOptions = () => ({ responsive: true, elements: {}, legend: { display: false }, maintainAspectRatio: true, plugins: { title: { display: true, text: 'Chart', color: this.theme === 'Dark' ? '#73879c' : '#73879c', padding: { bottom: 20, top: 3 } }, legend: { display: false }, datalabels: { color: '#ffffff', formatter: (value) => { return Number(value) > 0 ? value : ''; } } }, }); this.writeValueInCenter = () => ({ id: 'paint_number_in_center', beforeDraw: (chart) => { const { width } = chart; const { height } = chart; const ctx = chart.ctx; const textX = Math.round((width - ctx.measureText(chart.options.elements.text).width) / 2); const textY = (height + chart.chartArea.top) / 2; ctx.fillStyle = this.theme === 'Dark' ? '#73879c' : '#73879c'; ctx.fillText(chart.options.elements.text, textX, textY); ctx.save(); } }); this.generateChart = (chartName, chartData, graphOptions, chartCenterValue) => { const canvas = document.getElementById(chartName); const ctx = canvas.getContext('2d'); (graphOptions.elements).text = chartCenterValue; const chart = new chart_js_1.Chart(ctx, { data: chartData, options: graphOptions, plugins: [this.writeValueInCenter(), chartjs_plugin_datalabels_1.default], type: 'doughnut' }); return chart; }; this.theme = theme; } } exports.HtmlScriptsFunctions = HtmlScriptsFunctions; //# sourceMappingURL=html-charts-scripts-functions.js.map