cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
One of the requests that have come up is the ability to show percentages on a tree map without needing to hover over the widget with a tooltip.
The following code overwrites the 'name' displayed with 'name'  + percentage to three decimal places:
  • The percentage is calculated based on the values on the widget at present, and supports nested levels.
  • Obviously, datastructure[j]['name'] could also be replaced by  name + value, or  name + value +percentage.
widget.on('processresult', function(sender, e) {

 

function typecheck(item) {
 if (item instanceof Array) {
 result = 'Array'
 } else {
 if (item instanceof Object) {
 result = 'Object'
 }

}
 return result;
 }


 function loop(datastructure) {


 levelSize = 0
 if (typecheck(datastructure) == 'Array') {
 for (var i = 0; i < datastructure.length; i++) {
 if (typecheck(datastructure[i]) == 'Object') {
 levelSize = levelSize + datastructure[i]['size'];
 if (datastructure[i]['_depth'] == 1) {
 topSize = levelSize
 }
 }
 }
 for (var j = 0; j < datastructure.length; j++) {
 if (typecheck(datastructure[j]) == 'Object') {
 datastructure[j]['levelsize'] = levelSize;
 datastructure[j]['levelpercentage'] = datastructure[j]['size'] / topSize;
 levelpc100 = datastructure[j]['levelpercentage'] * 100
 datastructure[j]['name'] = datastructure[j]['data'] + ' - ' + levelpc100.toLocaleString({
 style: 'percent',
 maximumSignificantDigits: 2
 }) + ' %'
 }
 }
 for (var k = 0; k < datastructure.length; k++) {
 if (typeof(datastructure[k]['children']) !== 'undefined') {
 datastructure[k]['children'] = loop(datastructure[k]['children'])
 }

}

return datastructure;
 }
 }


loop(e.result.children)


})
Comments
TJT
7 - Data Storage
7 - Data Storage

Latest upgrade L2023.3.0.201 has partially broken the script.

Now it's taking the dimensional field and contribution as one text, when filtering from widget.

TJT_0-1680691399049.png

 

This was not the case before. Adding Contribution using script was not impacting the actual data in the column.

 

 

 

 

Version history
Last update:
‎03-02-2023 09:22 AM
Updated by:
Contributors
Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Developers Group:

Product Feedback Forum:

Need additional support?:

Submit a Support Request

The Legal Stuff

Have a question about the Sisense Community?

Email [email protected]

Share this page: