Giter VIP home page Giter VIP logo

Comments (9)

danielpalme avatar danielpalme commented on May 18, 2024

I think I can help you. Give me some time, I will come back to you within the next days.

from reportgenerator.

arpitgold avatar arpitgold commented on May 18, 2024

Thanks for your quick and supportive response. 😄
Thanks for the help.

from reportgenerator.

danielpalme avatar danielpalme commented on May 18, 2024

@arpitgold:
I created a plugin for you, that renders the chart.
Please download this project, and place the compiled DLL next to ReportGenerator.exe. Then call ReportGenerator.exe with -reporttypes:HtmlChart.
This will create a single file report that contains the chart (and unfortunately the footer).

In Jenkins you can publish this file as an artifact or with the HTML Publisher Plugin.
Then you could create a simple HTML page, that embeds the charts from all of your projects as iframes.

This is the code of the plugin:

using System;
using System.Collections.Generic;
using System.Linq;
using Palmmedia.ReportGenerator.Parser.Analysis;
using Palmmedia.ReportGenerator.Properties;
using Palmmedia.ReportGenerator.Reporting;
using Palmmedia.ReportGenerator.Reporting.Rendering;

namespace MyCompany.CustomReportTypes
{
    /// <summary>
    /// Creates HTML with chart component only (no reports for classes are generated).
    /// </summary>
    [System.ComponentModel.Composition.Export(typeof(IReportBuilder))]
    public class HtmlChartReportBuilder : HtmlSummaryReportBuilder
    {
        /// <summary>
        /// Gets the report type.
        /// </summary>
        /// <value>
        /// The report type.
        /// </value>
        public override string ReportType
        {
            get { return "HtmlChart"; }
        }

        /// <summary>
        /// Creates the summary report.
        /// </summary>
        /// <param name="reportRenderer">The report renderer.</param>
        /// <param name="summaryResult">The summary result.</param>
        public override void CreateSummaryReport(IReportRenderer reportRenderer, SummaryResult summaryResult)
        {
            if (reportRenderer == null)
            {
                throw new ArgumentNullException("reportRenderer");
            }

            if (summaryResult == null)
            {
                throw new ArgumentNullException("summaryResult");
            }

            this.TargetDirectory = System.IO.Path.Combine(this.TargetDirectory, "chart");
            System.IO.Directory.CreateDirectory(this.TargetDirectory);

            reportRenderer.BeginSummaryReport(this.TargetDirectory, ReportResources.Summary);

            var historicCoverages = this.GetOverallHistoricCoverages(summaryResult.Assemblies.SelectMany(a => a.Classes));
            if (historicCoverages.Any(h => h.CoverageQuota.HasValue || h.BranchCoverageQuota.HasValue))
            {
                reportRenderer.Chart(historicCoverages);
            }

            reportRenderer.CustomSummary(summaryResult.Assemblies);

            reportRenderer.SaveSummaryReport(this.TargetDirectory);
        }

        /// <summary>
        /// Gets the overall historic coverages from all classes.
        /// </summary>
        /// <param name="classes">The classes.</param>
        /// <returns>
        /// The overall historic coverages from all classes.
        /// </returns>
        private IEnumerable<HistoricCoverage> GetOverallHistoricCoverages(IEnumerable<Class> classes)
        {
            var historicCoverages = classes
                .SelectMany(c => c.HistoricCoverages);

            var executionTimes = historicCoverages
                .Select(h => h.ExecutionTime)
                .Distinct();

            var result = new List<HistoricCoverage>();

            foreach (var executionTime in executionTimes)
            {
                var historicCoveragesOfExecutionTime = historicCoverages
                    .Where(h => h.ExecutionTime.Equals(executionTime))
                    .ToArray();

                result.Add(new HistoricCoverage(executionTime)
                {
                    CoveredLines = historicCoveragesOfExecutionTime.Sum(h => h.CoveredLines),
                    CoverableLines = historicCoveragesOfExecutionTime.Sum(h => h.CoverableLines),
                    CoveredBranches = historicCoveragesOfExecutionTime.Sum(h => h.CoveredBranches),
                    TotalBranches = historicCoveragesOfExecutionTime.Sum(h => h.TotalBranches),
                    TotalLines = historicCoveragesOfExecutionTime.Sum(h => h.TotalLines)
                });
            }

            return result;
        }
    }
}

from reportgenerator.

arpitgold avatar arpitgold commented on May 18, 2024

Thanks @danielpalme , 👍
A big thank for your support and fast response.
I will check it and get back to you if I need any further assistance.

from reportgenerator.

arpitgold avatar arpitgold commented on May 18, 2024

Hi @danielpalme,
It works as exactly as I required.
But the issue is I am calling as -reporttypes:Html;XmlSummary;HtmlChart .
Html and HtmlChart both creates index.htm. Html report's "index.htm" file get overriden.
Can we create seperate files for each report?

from reportgenerator.

danielpalme avatar danielpalme commented on May 18, 2024

Easiest solution would be, to save the HtmlChart report to a different directory.
Just add the following lines to the CreateSummaryReport method:

this.TargetDirectory = System.IO.Path.Combine(this.TargetDirectory, "chart");
System.IO.Directory.CreateDirectory(this.TargetDirectory);

from reportgenerator.

arpitgold avatar arpitgold commented on May 18, 2024

Thanks @danielpalme, its works like a charm.
Again thanks for all your support. 👍

from reportgenerator.

gsuttie avatar gsuttie commented on May 18, 2024

I am getting unknown Report Type - I added the dll MyCompany.ReportGeneratorExtensions.dll next to the ReportGenerator.exe - can you help?

from reportgenerator.

danielpalme avatar danielpalme commented on May 18, 2024

Please use latest version 2.3.2. Custom report types are only supported with version >2

from reportgenerator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.