templates.default.pie_chart.ftlh Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-report-generator Show documentation
Show all versions of cucumber-report-generator Show documentation
The part of the Cucumber Reports library directly responsible for
reports generation.
<#assign Math=statics['java.lang.Math'] >
<#assign scale = 0.2 >
<#assign centerScale = 3 >
<#function sum values>
<#assign result = 0>
<#list values as value>
<#assign result = result + value>
#list>
<#return result>
#function>
<#macro drawPieChart id width height values labels colors shadowColors pieThickness shift>
#macro>
<#macro drawPieBorders width height values colors pieVOffset shift>
<#assign total=sum(values)>
<#assign accumulated = 0 >
<#if total == 0>
<#return>
#if>
<#list values as value>
<#if value gt 0>
<#assign l_shift = shift>
<#if value?counter == total>
<#assign l_shift = 0>
#if>
<#assign startAngle = 2 * Math.PI * accumulated / total >
<#assign endAngle = 2 * Math.PI * (accumulated + value) / total >
<#assign shiftAngle = (startAngle + endAngle) / 2 >
<#assign centerX = width / centerScale + l_shift * Math.sin(shiftAngle)>
<#assign centerY = height / centerScale - l_shift * Math.cos(shiftAngle)>
<#assign startX = centerX + (scale * width) * Math.sin(startAngle)
+ shift * Math.sin(shiftAngle) >
<#assign startY = centerY - (scale * height) * Math.cos(startAngle)
- shift * Math.cos(shiftAngle) >
<#assign accumulated = accumulated + value >
#if>
#list>
<#assign accumulated = 0 >
<#list values as value>
<#assign startAngle = 2 * Math.PI * accumulated / total >
<#assign endAngle = 2 * Math.PI * (accumulated + value) / total >
<#assign shiftAngle = (startAngle + endAngle) / 2 >
<#assign centerX = width / centerScale + shift * Math.sin(shiftAngle)>
<#assign centerY = height / centerScale - shift * Math.cos(shiftAngle)>
<#assign endX = 0>
<#assign endY = 0>
<#if value?index lt (values?size - 1)>
<#assign endX = centerX + (scale * width) * Math.sin(endAngle) + shift * Math.sin(shiftAngle) >
<#assign endY = centerY - (scale * height) * Math.cos(endAngle) - shift * Math.cos(shiftAngle) >
<#else>
<#assign endX = centerX + shift * Math.sin(shiftAngle) >
<#assign endY = centerY - scale * height - shift * Math.cos(shiftAngle) >
#if>
<#assign accumulated = accumulated + value >
#list>
#macro>
<#macro drawPieLayers width height values colors pieVOffset shift>
<#assign total=sum(values)>
<#assign accumulated = 0 >
<#if total == 0>
<#return>
#if>
<#list values as value>
<#if value gt 0>
<#assign l_shift = shift>
<#if value?counter == total>
<#assign l_shift = 0>
#if>
<#assign startAngle = 2 * Math.PI * accumulated / total >
<#assign endAngle = 2 * Math.PI * (accumulated + value) / total >
<#assign shiftAngle = (startAngle + endAngle) / 2 >
<#assign centerX = width / centerScale + l_shift * Math.sin(shiftAngle)>
<#assign centerY = height / centerScale - l_shift * Math.cos(shiftAngle)>
<#assign radiusX = scale * width>
<#assign radiusY = scale * height>
<#assign pieParts = 5>
<#list 0..(pieParts - 1) as j>
<#assign angleDiff = endAngle - startAngle >
<#assign startX = centerX + (scale * width)
* Math.sin(startAngle + j * angleDiff / pieParts)
+ l_shift * Math.sin(shiftAngle) >
<#assign startY = centerY - (scale * height)
* Math.cos(startAngle + j * angleDiff / pieParts)
- l_shift * Math.cos(shiftAngle) >
<#assign endX = centerX + (scale * width)
* Math.sin(startAngle + (j + 1) * angleDiff / pieParts)
+ l_shift * Math.sin(shiftAngle) >
<#assign endY = centerY - (scale * height)
* Math.cos(startAngle + (j + 1) * angleDiff / pieParts)
- l_shift * Math.cos(shiftAngle) >
#list>
<#assign accumulated = accumulated + value >
#if>
#list>
#macro>