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]0){let e=this.distribution[A];this._$target.find(".row"+e+">.col"+A).addClass("filled"),this.distribution[A]++,this.remainingBalls--,this.onChange()}}:A=>()=>{if(this.onTouch(),this.distribution[A]>0){this.distribution[A]--;let e=this.distribution[A];this._$target.find(".row"+e+">.col"+A).removeClass("filled"),this.remainingBalls++,this.onChange()}}}_createGrid(A){let e=this.nRows,n=this.nBuckets,t=o("
",{class:"grid"});for(let A=0;A",{class:"distrow row"+(e-A-1)});for(let A=0;A",{class:"cell col"+A}),n=o("
",{class:"ball col"+A});e.append(n),i.append(e)}t.append(i)}return t}_createButtons(A){let e=this._actionCreator("increment"),n=this._actionCreator("decrement"),t=o("
",{class:"distrow"}),i=o("
",{class:"buttons"});for(let A=0;A",{class:"buttongroup"}),r=o("",{class:"btn btn-default distbutton glyphicon glyphicon-plus"}),c=o("",{class:"btn btn-default distbutton glyphicon glyphicon-minus"});i.append(r.mousehold(200,100,e(A)).click(e(A))),i.append(c.mousehold(200,100,n(A)).click(n(A))),t.append(i)}return i.append(t),i}_createLabels(A){let e=o("
",{class:"labels"}),n=o("
",{class:"distrow"});for(let A=0;A",{class:"label label"+A});n.append(e)}return e.append(n),e}}},function(A,e,n){(function(e){A.exports=e.jQuery=n(5)}).call(this,n(2))},function(A,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(A){"object"==typeof window&&(n=window)}A.exports=n},function(A,e,n){var t={},o=function(A){var e;return function(){return void 0===e&&(e=A.apply(this,arguments)),e}}(function(){return window&&document&&document.all&&!window.atob}),i=function(A){var e={};return function(A){if("function"==typeof A)return A();if(void 0===e[A]){var n=function(A){return document.querySelector(A)}.call(this,A);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(A){n=null}e[A]=n}return e[A]}}(),r=null,c=0,s=[],a=n(10);function l(A,e){for(var n=0;n=0&&s.splice(e,1)}function u(A){var e=document.createElement("style");return void 0===A.attrs.type&&(A.attrs.type="text/css"),f(e,A.attrs),d(A,e),e}function f(A,e){Object.keys(e).forEach(function(n){A.setAttribute(n,e[n])})}function E(A,e){var n,t,o,i;if(e.transform&&A.css){if(!(i=e.transform(A.css)))return function(){};A.css=i}if(e.singleton){var s=c++;n=r||(r=u(e)),t=p.bind(null,n,s,!1),o=p.bind(null,n,s,!0)}else A.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(A){var e=document.createElement("link");return void 0===A.attrs.type&&(A.attrs.type="text/css"),A.attrs.rel="stylesheet",f(e,A.attrs),d(A,e),e}(e),t=function(A,e,n){var t=n.css,o=n.sourceMap,i=void 0===e.convertToAbsoluteUrls&&o;(e.convertToAbsoluteUrls||i)&&(t=a(t));o&&(t+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var r=new Blob([t],{type:"text/css"}),c=A.href;A.href=URL.createObjectURL(r),c&&URL.revokeObjectURL(c)}.bind(null,n,e),o=function(){B(n),n.href&&URL.revokeObjectURL(n.href)}):(n=u(e),t=function(A,e){var n=e.css,t=e.media;t&&A.setAttribute("media",t);if(A.styleSheet)A.styleSheet.cssText=n;else{for(;A.firstChild;)A.removeChild(A.firstChild);A.appendChild(document.createTextNode(n))}}.bind(null,n),o=function(){B(n)});return t(A),function(e){if(e){if(e.css===A.css&&e.media===A.media&&e.sourceMap===A.sourceMap)return;t(A=e)}else o()}}A.exports=function(A,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(e=e||{}).attrs="object"==typeof e.attrs?e.attrs:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=o()),e.insertInto||(e.insertInto="head"),e.insertAt||(e.insertAt="bottom");var n=g(A,e);return l(n,e),function(A){for(var o=[],i=0;i{},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]0){let e=this.distribution[A];this._$target.find(".row"+e+">.col"+A).addClass("filled"),this.distribution[A]++,this.remainingBalls--,this.onChange()}}:A=>()=>{if(this.onTouch(),this.distribution[A]>0){this.distribution[A]--;let e=this.distribution[A];this._$target.find(".row"+e+">.col"+A).removeClass("filled"),this.remainingBalls++,this.onChange()}}}_createGrid(A){let e=this.nRows,n=this.nBuckets,t=o("
",{class:"grid"});for(let A=0;A",{class:"distrow row"+(e-A-1)});for(let A=0;A",{class:"cell col"+A}),n=o("
",{class:"ball col"+A});e.append(n),i.append(e)}t.append(i)}return t}_createButtons(A){let e=this._actionCreator("increment"),n=this._actionCreator("decrement"),t=o("
",{class:"distrow"}),i=o("
",{class:"buttons"});for(let A=0;A",{class:"buttongroup"}),r=o("",{class:"btn btn-default distbutton glyphicon glyphicon-plus"}),c=o("",{class:"btn btn-default distbutton glyphicon glyphicon-minus"});i.append(r.mousehold(500,100,e(A)).click(e(A))),i.append(c.mousehold(500,100,n(A)).click(n(A))),t.append(i)}return i.append(t),i}_createLabels(A){let e=o("
",{class:"labels"}),n=o("
",{class:"distrow"});for(let A=0;A",{class:"label label"+A});n.append(e)}return e.append(n),e}}},function(A,e,n){(function(e){A.exports=e.jQuery=n(5)}).call(this,n(2))},function(A,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(A){"object"==typeof window&&(n=window)}A.exports=n},function(A,e,n){var t={},o=function(A){var e;return function(){return void 0===e&&(e=A.apply(this,arguments)),e}}(function(){return window&&document&&document.all&&!window.atob}),i=function(A){var e={};return function(A){if("function"==typeof A)return A();if(void 0===e[A]){var n=function(A){return document.querySelector(A)}.call(this,A);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(A){n=null}e[A]=n}return e[A]}}(),r=null,c=0,s=[],a=n(10);function l(A,e){for(var n=0;n=0&&s.splice(e,1)}function u(A){var e=document.createElement("style");return void 0===A.attrs.type&&(A.attrs.type="text/css"),f(e,A.attrs),d(A,e),e}function f(A,e){Object.keys(e).forEach(function(n){A.setAttribute(n,e[n])})}function E(A,e){var n,t,o,i;if(e.transform&&A.css){if(!(i=e.transform(A.css)))return function(){};A.css=i}if(e.singleton){var s=c++;n=r||(r=u(e)),t=p.bind(null,n,s,!1),o=p.bind(null,n,s,!0)}else A.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(A){var e=document.createElement("link");return void 0===A.attrs.type&&(A.attrs.type="text/css"),A.attrs.rel="stylesheet",f(e,A.attrs),d(A,e),e}(e),t=function(A,e,n){var t=n.css,o=n.sourceMap,i=void 0===e.convertToAbsoluteUrls&&o;(e.convertToAbsoluteUrls||i)&&(t=a(t));o&&(t+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var r=new Blob([t],{type:"text/css"}),c=A.href;A.href=URL.createObjectURL(r),c&&URL.revokeObjectURL(c)}.bind(null,n,e),o=function(){B(n),n.href&&URL.revokeObjectURL(n.href)}):(n=u(e),t=function(A,e){var n=e.css,t=e.media;t&&A.setAttribute("media",t);if(A.styleSheet)A.styleSheet.cssText=n;else{for(;A.firstChild;)A.removeChild(A.firstChild);A.appendChild(document.createTextNode(n))}}.bind(null,n),o=function(){B(n)});return t(A),function(e){if(e){if(e.css===A.css&&e.media===A.media&&e.sourceMap===A.sourceMap)return;t(A=e)}else o()}}A.exports=function(A,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(e=e||{}).attrs="object"==typeof e.attrs?e.attrs:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=o()),e.insertInto||(e.insertInto="head"),e.insertAt||(e.insertAt="bottom");var n=g(A,e);return l(n,e),function(A){for(var o=[],i=0;i', { class: "btn btn-default distbutton glyphicon glyphicon-plus" }); let $removeButton = $j('', { class: "btn btn-default distbutton glyphicon glyphicon-minus" }); $divButtons.append($addButton - .mousehold(200, 100, incrementAction(col)) + .mousehold(500, 100, incrementAction(col)) .click(incrementAction(col))); $divButtons.append($removeButton - .mousehold(200, 100, decrementAction(col)) + .mousehold(500, 100, decrementAction(col)) .click(decrementAction(col))); $lineDivButtons.append($divButtons); } diff --git a/src/distributionbuilder.ts b/src/distributionbuilder.ts index eb490b9..2d1a012 100644 --- a/src/distributionbuilder.ts +++ b/src/distributionbuilder.ts @@ -247,11 +247,11 @@ class DistributionBuilder { let $addButton = $j('', {class: "btn btn-default distbutton glyphicon glyphicon-plus"}); let $removeButton = $j('', {class: "btn btn-default distbutton glyphicon glyphicon-minus"}); $divButtons.append($addButton - .mousehold(200, 100, incrementAction(col)) + .mousehold(500, 100, incrementAction(col)) .click(incrementAction(col)) ); $divButtons.append($removeButton - .mousehold(200, 100, decrementAction(col)) + .mousehold(500, 100, decrementAction(col)) .click(decrementAction(col)) ); $lineDivButtons.append($divButtons);