smart-webcomponents-react
Version:
[](https://jqwidgets.com/license/)
6 lines (4 loc) • 4.63 kB
JavaScript
/* Smart UI v23.0.8 (2025-05-13)
Copyright (c) 2011-2024 jQWidgets.
License: https://htmlelements.com/license/ */ //
Smart.Utilities.Assign("TickIntervalHandler",class{constructor(e,t,i,a,l,s,n){const r=this;r.context=e,r.minLabel=t,r.maxLabel=i,r.labelClass=a,r.dimension=l,r.logarithmic=n,e.customInterval?e.customTicks.length>0?r.labelsSize=r.getCustomTicksLabelSize():r.labelsSize={minLabelSize:0,minLabelOtherSize:0,maxLabelSize:0,maxLabelOtherSize:0}:r.labelsSize=r.getMinAndMaxLabelSize(),s?(r.getNiceInterval=r.getNiceIntervalInteger,r.getPossibleBiggerLabel=r.getPossibleBiggerLabelInteger):(r.getNiceInterval=r.getNiceIntervalFloatingPoint,r.getPossibleBiggerLabel=r.getPossibleBiggerLabelFloatingPoint)}getInterval(e,t,i,a){const l=this.context,s=l._measurements.innerRadius;let n,r,o=1;"radial"===e?(n=Math.max(this.labelsSize.minLabelSize,this.labelsSize.minLabelOtherSize,this.labelsSize.maxLabelSize,this.labelsSize.maxLabelOtherSize),o=1.35):(n=Math.max(this.labelsSize.minLabelSize,this.labelsSize.maxLabelSize),o=1.45),n*=o,r="radial"===e?function(){let e=2*Math.PI*s*(Math.abs(l.startAngle-l.endAngle)/360);return Math.round(e)}():l[this.dimension]-this.labelsSize.minLabelSize/2-this.labelsSize.maxLabelSize/2,r=Math.max(10,r);const m=Math.ceil(r/n),b="radial"===e?4*m:3*m;let h=this.getNiceInterval(t,i,m,!0),g=this.getNiceInterval(t,i,b);if(l._cachedLabelsSize=this.labelsSize,m>2&&!l.customInterval){const s=this.getPossibleBiggerLabel(m,h);if(s.length>Math.max(this.minLabel.length,this.maxLabel.length)){const n=this.minLabel;this.minLabel=s,this.labelsSize=this.getMinAndMaxLabelSize(),l._cachedLabelsSize=this.labelsSize;const r=this.getInterval(e,t,i,a);return this.minLabel=n,this.labelsSize=this.getMinAndMaxLabelSize(),r}}return{major:h,minor:g}}getNiceIntervalFloatingPoint(e,t,i,a){const l=t-e,s=Math.floor(Math.log10(l)-Math.log10(i));let n,r=Math.pow(10,s),o=i*r;n=l<2*o?1:l<3*o?2:l<7*o?5:10;let m=n*r;if(a&&this.context._range/m>i){switch(n){case 5:n=10;break;case 2:n=5;break;case 1:n=2}m=n*r}return this.nearestPowerOfTen=r,this.logarithmic&&a?Math.max(1,m):m}getPossibleBiggerLabelFloatingPoint(e,t){const i=this.context;let a,l,s=parseFloat(i.min-i._numericProcessor.getPreciseModulo(parseFloat(i.min),t)+parseFloat(t)),n=s;this.logarithmic&&(s=Math.pow(10,s)),a=i._formatLabel(s);for(let s=1;s<e&&(n+=t,!(n>=i._drawMax));s++)l=this.logarithmic?Math.pow(10,n):n,l=i._formatLabel(l),l.length>a.length&&(a=l);return a}getNiceIntervalInteger(e,t,i,a){const l=new Smart.Utilities.BigNumber(t).subtract(new Smart.Utilities.BigNumber(e)),s=Math.floor(Math.log10(l.toString())-Math.log10(i)),n=new Smart.Utilities.BigNumber(10).pow(new Smart.Utilities.BigNumber(s)),r=new Smart.Utilities.BigNumber(i).multiply(n);let o;o=-1===l.compare(new Smart.Utilities.BigNumber(2*r))?1:-1===l.compare(new Smart.Utilities.BigNumber(3*r))?2:-1===l.compare(new Smart.Utilities.BigNumber(7*r))?5:10;let m=new Smart.Utilities.BigNumber(o).multiply(n);if(a&&1===new Smart.Utilities.BigNumber(this.context._range).divide(m).compare(i)){switch(o){case 5:o=10;break;case 2:o=5;break;case 1:o=2}m=new Smart.Utilities.BigNumber(o).multiply(n)}return-1===m.compare(1)&&(m=new Smart.Utilities.BigNumber(1)),this.nearestPowerOfTen=n,m}getPossibleBiggerLabelInteger(e,t){const i=this.context,a=new Smart.Utilities.BigNumber(10);let l,s,n=new Smart.Utilities.BigNumber(i.min).subtract(new Smart.Utilities.BigNumber(i.min).mod(t)).add(t),r=n;this.logarithmic&&(n=a.pow(n)),l=i._formatLabel(n);for(let n=1;n<e&&(r=r.add(t),-1===r.compare(i._drawMax));n++)s=this.logarithmic?a.pow(r):r,s=i._formatLabel(s),s.length>l.length&&(l=s);return l}getMinAndMaxLabelSize(){const e=this,t=e.context,i=t.$.container,a=document.createElement("span");a.className=e.labelClass,a.style.position="absolute",a.style.visibility="hidden",i.appendChild(a),a.innerHTML=e.minLabel;const l=a[e.dimension],s=a[t._settings.otherSize];a.innerHTML=e.maxLabel;const n=a[e.dimension],r=a[t._settings.otherSize];return i.removeChild(a),{minLabelSize:l,minLabelOtherSize:s,maxLabelSize:n,maxLabelOtherSize:r}}getCustomTicksLabelSize(){const e=this,t=e.context,i=t.$.container,a=document.createElement("span"),l=t.customTicks;a.className=e.labelClass,a.style.position="absolute",a.style.visibility="hidden",i.appendChild(a),a.innerHTML=t._formatLabel(l[0]);let s=a[e.dimension],n=a[t._settings.otherSize];for(let i=1;i<t.customTicks.length;i++){a.innerHTML=t._formatLabel(t.customTicks[i]);const l=a[e.dimension],r=a[t._settings.otherSize];l>s&&(s=l),r>n&&(n=r)}return i.removeChild(a),{minLabelSize:s,minLabelOtherSize:n,maxLabelSize:s,maxLabelOtherSize:n}}});