Piechart threshold is smarter now

This commit is contained in:
skyanth 2019-06-06 17:22:55 +02:00
parent 647bd8271f
commit db5791920b

View File

@ -19,8 +19,8 @@
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:call-template name="displayErrorText"> <xsl:call-template name="displayErrorText">
<xsl:with-param name="string">Pie chart can only be generated when <xsl:with-param name="string">Pie chart can only be generated when there are
there are findings in the report. Get to work! ;)</xsl:with-param> findings in the report. Get to work! ;)</xsl:with-param>
</xsl:call-template> </xsl:call-template>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
@ -33,7 +33,6 @@
<xsl:param name="pieElem" select="@pieElem"/> <xsl:param name="pieElem" select="@pieElem"/>
<xsl:param name="pieHeight" as="xs:integer" select="200"/> <xsl:param name="pieHeight" as="xs:integer" select="200"/>
<xsl:param name="status" select="@status"/> <xsl:param name="status" select="@status"/>
<xsl:param name="threshold" select="2"/>
<xsl:variable name="statusSequence" as="item()*"> <xsl:variable name="statusSequence" as="item()*">
<xsl:for-each select="$status"> <xsl:for-each select="$status">
<xsl:for-each select="tokenize(., ' ')"> <xsl:for-each select="tokenize(., ' ')">
@ -146,12 +145,27 @@
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<xsl:variable name="threshold" as="xs:integer">
<!-- threshold is usually 2 (everything below it gets thrown in 'other' bin if they get too numerous)
sometimes it's three if the 2-type slices also get too numerous and take up too much space -->
<xsl:choose>
<!-- -->
<xsl:when test="(count($sortedPieTable/pieEntry) > 16) and (count($sortedPieTable/pieEntry/pieEntryCount[. = 2]) &gt; 5) and ((1 div $pieTotal * 100) &lt; 2.5) and (sum($sortedPieTable/pieEntry/pieEntryCount[. &lt; 3]) div $pieTotal * 100 &lt; 50)">3</xsl:when>
<xsl:otherwise>2</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sumBelowThreshold"> <xsl:variable name="sumBelowThreshold">
<xsl:value-of select="sum($sortedPieTable/pieEntry/pieEntryCount[. &lt; $threshold])"/> <xsl:value-of select="sum($sortedPieTable/pieEntry/pieEntryCount[. &lt; $threshold])"/>
</xsl:variable> </xsl:variable>
<xsl:variable name="pieTable_thresholdApplied"> <xsl:variable name="pieTable">
<xsl:choose> <xsl:choose>
<xsl:when test="not($pieAttr = 'threatLevel') and $sumBelowThreshold > 4"> <xsl:when
test="(not($pieAttr = 'threatLevel') and $sumBelowThreshold > 4 and (1 div $pieTotal * 100) &lt; 5 and ($sumBelowThreshold div $pieTotal * 100) &lt; 50) or (not($pieAttr = 'threatLevel') and count($sortedPieTable/pieEntry) > 16)">
<!-- Group below-threshold pie slices into 'Other' if:
- there are more than 4 single-type slices and
- they are small percentages (i.e. 1 single-type slice is less than 5%) and
- they take up less than 50% of the chart
(otherwise just print them out) -->
<xsl:for-each <xsl:for-each
select="$sortedPieTable/pieEntry[child::pieEntryCount &gt;= $threshold]"> select="$sortedPieTable/pieEntry[child::pieEntryCount &gt;= $threshold]">
<pieEntry> <pieEntry>
@ -168,10 +182,8 @@
<xsl:copy-of select="$sortedPieTable" copy-namespaces="no"/> <xsl:copy-of select="$sortedPieTable" copy-namespaces="no"/>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> <xsl:if
<xsl:variable name="pieTable"> test="(not($pieAttr = 'threatLevel') and $sumBelowThreshold > 4 and (1 div $pieTotal * 100) &lt; 5 and ($sumBelowThreshold div $pieTotal * 100) &lt; 50) or (not($pieAttr = 'threatLevel') and count($sortedPieTable/pieEntry) > 16)">
<xsl:copy-of select="$pieTable_thresholdApplied" copy-namespaces="no"/>
<xsl:if test="not($pieAttr = 'threatLevel') and $sumBelowThreshold > 4">
<pieEntry> <pieEntry>
<pieEntryLabel> <pieEntryLabel>
<xsl:text>Other</xsl:text> <xsl:text>Other</xsl:text>
@ -259,7 +271,8 @@
<xsl:variable name="d" <xsl:variable name="d"
select="concat($middle, ' ', $first_line, ' ', 'a ', $radius, ',', $radius, ' ', $arc_move, ' ', $x, ',', $radius - $y, ' ', 'z')"/> select="concat($middle, ' ', $first_line, ' ', 'a ', $radius, ',', $radius, ' ', $arc_move, ' ', $x, ',', $radius - $y, ' ', 'z')"/>
<!--put it all together--> <!--put it all together-->
<path xmlns="http://www.w3.org/2000/svg" stroke="white" stroke-width="1" stroke-linejoin="round"> <path xmlns="http://www.w3.org/2000/svg" stroke="white" stroke-width="1"
stroke-linejoin="round">
<xsl:attribute name="fill"> <xsl:attribute name="fill">
<xsl:call-template name="selectColor"> <xsl:call-template name="selectColor">
<xsl:with-param name="position" select="$position"/> <xsl:with-param name="position" select="$position"/>
@ -319,7 +332,8 @@
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<path xmlns="http://www.w3.org/2000/svg" stroke="black" stroke-width="1" stroke-linejoin="round"> <path xmlns="http://www.w3.org/2000/svg" stroke="black" stroke-width="1"
stroke-linejoin="round">
<xsl:attribute name="fill">none</xsl:attribute> <xsl:attribute name="fill">none</xsl:attribute>
<xsl:attribute name="d"> <xsl:attribute name="d">
<xsl:value-of <xsl:value-of