From 4e95ca3c7bade2ab40f171cb40a2dc7cf1739f17 Mon Sep 17 00:00:00 2001 From: Anne-Catherine <57360138+accognet@users.noreply.github.com> Date: Thu, 13 Apr 2023 11:23:20 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B0541=20-=20Dashlets:=20Improve=20readabil?= =?UTF-8?q?ity=20when=20to=20much=20labels=20(pie=20chart)=20or=20too=20lo?= =?UTF-8?q?ng=20labels=20(bar=20chart)=20(#452)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N°541 - Dashlets: Improve readability when to much labels (pie chart) or too long labels (bar chart) --- application/displayblock.class.inc.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index f89172feb..1fff40f1f 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -1009,6 +1009,8 @@ EOF $iTotalCount = 0; $aValues = array(); $aURLs = array(); + $iMaxNbCharsInLabel = 0; + foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; @@ -1016,7 +1018,11 @@ EOF $aGroupBy[(int)$iRow] = (int) $aRow[$sFctVar]; $iTotalCount += $aRow['_itop_count_']; $aValues[] = array('label' => html_entity_decode(strip_tags($sHtmlValue), ENT_QUOTES, 'UTF-8'), 'label_html' => $sHtmlValue, 'value' => (int) $aRow[$sFctVar]); - + + if ($iMaxNbCharsInLabel < mb_strlen($sValue)) { + $iMaxNbCharsInLabel = mb_strlen($sValue); + } + // Build the search for this subset $oSubsetSearch = $this->m_oFilter->DeepClone(); $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($sValue)); @@ -1039,7 +1045,10 @@ EOF $sJson = json_encode($aValues); $oPage->add_ready_script( << 50) { + // Calculation of the number of legends line add to the height of the graph to have a maximum of 5 legend columns + $iNbLinesIncludedInChartHeight = 10; + $iNbLinesToAddForName = ceil(count($aNames) / 5) - $iNbLinesIncludedInChartHeight; + } $oPage->add_ready_script( <<