/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const FULL_BLOCK="\u2588";const HALF_ELEM="\u2588";const FOURTH_ELEM="\u258C";function Histo(oStats,width,oColors){this._maxWidth=width;this._Colors=oColors;this._colorMode=oColors.isColor();this._count=0;let sev,nums=[];for(sev in oStats){nums.push(oStats[sev])};this._total=_sum(nums);this._maxBar=this._barLengths(nums);this._factor=this._maxBar>1?this._maxWidth/this._maxBar:1;this._clrCounts=_barColors(nums.length)};Histo.prototype.bar=function(n){var ret,val=n/this._total*this._maxWidth;var colors=this._Colors;if(val>0.5&&val<1){ret=HALF_ELEM.repeat(this._factor)}else if(val===0){ret=""}else if(val<0.5){ret=FOURTH_ELEM.repeat(this._factor)}else{ret=FULL_BLOCK.repeat(val*this._factor)}if(this._colorMode){ret=++this._count<=this._clrCounts[0]?colors.RED(ret):this._count<=this._clrCounts[1]?colors.BRIGHTBLUE(ret):colors.GREEN(ret)}return ret};Histo.prototype._barLengths=function(nums){var i,max=0,n;for(i=0;i<nums.length;i++){n=nums[i]/this._total*this._maxWidth;if(n>max){max=n}}this._factor=max>1?this._maxWidth/max:1;return max};function _sum(nums){var t=0;nums.forEach(n=>{if(!isNaN(n)){t+=n}});return t};function _barColors(n){var a=[];if(n===5){a.push(2);a.push(4)}else if(n===4){a.push(2);a.push(3);a.push(4)}else if(n===3){a.push(1);a.push(2);a.push(3)}else if(n<=2){a.push(1);a.push(2)}else if(n===1){a.push(1)}return a}module.exports=Histo;