All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.grasshopper.pdf.chapter.summary.SummaryDonutCharts Maven / Gradle / Ivy

There is a newer version: 2.14.0
Show newest version
package tech.grasshopper.pdf.chapter.summary;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

import org.knowm.xchart.style.PieStyler;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import tech.grasshopper.pdf.component.chart.ChartComponent;
import tech.grasshopper.pdf.component.chart.ChartDisplayer;
import tech.grasshopper.pdf.component.chart.ReportDonutChart;
import tech.grasshopper.pdf.data.SummaryData;

@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public class SummaryDonutCharts extends ChartComponent {

	private SummaryData summaryData;

	@Override
	public void display() {
		summaryData = (SummaryData) displayData;
		createFeatureDonutChart();
		createScenarioDonutChart();
		createStepDonutChart();
	}

	private void createFeatureDonutChart() {
		Map data = createDonutChartDataMap(summaryData.getPassedFeatures(),
				summaryData.getFailedFeatures(), summaryData.getSkippedFeatures());
		createDonutChart(data, 40);
	}

	private void createScenarioDonutChart() {
		Map data = createDonutChartDataMap(summaryData.getPassedScenarios(),
				summaryData.getFailedScenarios(), summaryData.getSkippedScenarios());
		createDonutChart(data, 220);
	}

	private void createStepDonutChart() {
		Map data = createDonutChartDataMap(summaryData.getPassedSteps(), summaryData.getFailedSteps(),
				summaryData.getSkippedSteps());
		createDonutChart(data, 400);
	}

	private void createDonutChart(Map data, float xOffset) {
		ReportDonutChart chart = new ReportDonutChart(160, 160);
		updateChartStyler(chart.getStyler());
		chart.updateData(data);

		ChartDisplayer.builder().document(document).content(content).chart(chart).xBottomLeft(xOffset).yBottomLeft(430)
				.build().display();
	}

	private void updateChartStyler(PieStyler styler) {
		styler.setSumFontSize(20f);
		styler.setDonutThickness(0.5);
		styler.setSeriesColors(
				new Color[] { reportConfig.passedColor(), reportConfig.failedColor(), reportConfig.skippedColor() });
	}

	private Map createDonutChartDataMap(Number passed, Number failed, Number skipped) {
		Map data = new HashMap<>();
		data.put("Passed", passed);
		data.put("Failed", failed);
		data.put("Skipped", skipped);
		return data;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy