diff --git a/distributionbuilder.min.js b/distributionbuilder.min.js index bd3210f..e73460b 100644 --- a/distributionbuilder.min.js +++ b/distributionbuilder.min.js @@ -1,4 +1,4 @@ -!function(A){var e={};function n(t){if(e[t])return e[t].exports;var o=e[t]={i:t,l:!1,exports:{}};return A[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=A,n.c=e,n.d=function(A,e,t){n.o(A,e)||Object.defineProperty(A,e,{enumerable:!0,get:t})},n.r=function(A){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(A,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(A,"__esModule",{value:!0})},n.t=function(A,e){if(1&e&&(A=n(A)),8&e)return A;if(4&e&&"object"==typeof A&&A&&A.__esModule)return A;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:A}),2&e&&"string"!=typeof A)for(var o in A)n.d(t,o,function(e){return A[e]}.bind(null,o));return t},n.n=function(A){var e=A&&A.__esModule?function(){return A.default}:function(){return A};return n.d(e,"a",e),e},n.o=function(A,e){return Object.prototype.hasOwnProperty.call(A,e)},n.p="",n(n.s=23)}([function(A,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const t=n(1);n(1),n(7),n(11);var o=t.noConflict();n(22).default(o);e.default=class{constructor(A){let e=A||{};this.min=e.hasOwnProperty("minVal")?e.minVal:0,this.max=e.hasOwnProperty("maxVal")?e.maxVal:10,this.nBalls=e.hasOwnProperty("nBalls")?e.nBalls:10,this.nRows=e.hasOwnProperty("nRows")?e.nRows:10,this.nBuckets=e.hasOwnProperty("nBuckets")?e.nBuckets:10,this.onTouch=e.hasOwnProperty("onTouch")?e.onTouch:()=>{},this.onChange=e.hasOwnProperty("onChange")?e.onChange:()=>{},this.remainingBalls=this.nBalls,this.distribution=new Array(this.nBuckets).fill(0),this._$target=o("
")}render(A,e,n){n&&console.warn("The 'resize' argument has been deprecated."),this._$target&&(this._$target.html(""),this._$target.removeClass("distbuilder"));let t=o("#"+A),i={grid:this._createGrid(t),labels:this._createLabels(t),buttons:this._createButtons(t)},r=new RegExp("(buttons-grid-labels)|(grid-labels-buttons)|(labels-grid-buttons)|(labels-buttons-grid)|(grid-buttons-labels)|(buttons-labels-grid)","g");this._$target=t,t.addClass("distbuilder");let c=e||"grid-labels-buttons";if(!r.test(c))throw"The order '"+c+"' could not be understood. Make sure that the order is any combination of 'labels', 'grid', and 'button, separated by '-'.";c.split("-").forEach(A=>t.append(i[A]))}labelize(A){let e=A||{},n=[];if(e.hasOwnProperty("labels"))n=e.labels;else{let A=(this.max-this.min)/this.nBuckets;n=Array.from({length:this.nBuckets},(e,n)=>this.min+n*A+A/2)}let t=e.hasOwnProperty("prefix")?e.prefix:"",o=e.hasOwnProperty("suffix")?e.suffix:"",i=n.map(A=>t+A+o);this._setLabels(i)}isComplete(){return 0==this.remainingBalls}getRemainingBalls(){return this.remainingBalls}getDistribution(){return this.distribution.slice()}setDistribution(A){if(A.length!=this.nBuckets)throw"The length of the entered distribution does not match the number of buckets";let e=A.reduce((A,e)=>A+e);if(e>this.nBalls)throw"The number of balls in the distribution exceeds the number of balls.";if(A.reduce((A,e)=>A>=e?A:e)>this.nRows)throw"The number of balls in one or several buckets is greater than the number of rows.";A.map((A,e)=>this._$target.find(".distrow > .col"+e).slice(this.nRows-A,this.nRows).map((A,e)=>o(e).addClass("filled"))),this.distribution=A,this.remainingBalls=this.remainingBalls-e}_setLabels(A){A.forEach((A,e)=>{this._$target.find(".label"+e).html(A)})}_actionCreator(A){return"increment"==A?A=>()=>{if(this.onTouch(),this.distribution[A]