UNPKG

@verivox/tiny-donuts

Version:
1 lines 4.39 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TinyDonuts=e():t.TinyDonuts=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t){var e=t.color,n=t.length,r=t.size,o=t.start,i=t.thickness,s=t._document,u=void 0===s?document:s;if(this.backgroundColor="transparent",n>1||n<=0)throw Error("Please choose a value between 0 and 1");this.color=e,this.length=n,this.size=r,this.thickness=i,this.start=o,this.document=u}return t.prototype.getSVGElement=function(){var t=this.size/2-this.thickness/2,e=2*t*Math.PI,n=e/100,r=e-n*(100*this.start)+e/4,o=n*(100*this.length),i=this.document.createElementNS("http://www.w3.org/2000/svg","circle");return i.setAttributeNS("","r",t.toString()),i.setAttributeNS("","fill",this.backgroundColor),i.setAttributeNS("","cx",""+this.size/2),i.setAttributeNS("","cy",""+this.size/2),"transparent"===this.backgroundColor&&(i.setAttributeNS("","stroke",this.color),i.setAttributeNS("","stroke-width",this.thickness.toString()),i.setAttributeNS("","stroke-dashoffset",r.toString()),i.setAttributeNS("","stroke-dasharray",o+" "+(e-o))),i},t}();e.Segment=r},function(t,e,n){"use strict";function r(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),r(n(2)),r(n(0))},function(t,e,n){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},o=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(e,"__esModule",{value:!0});var i=n(0),s=function(){function t(t){var e=t.entries,n=t.thickness,r=void 0===n?3:n,o=t.spacing,i=void 0===o?.005:o,s=t._document,u=void 0===s?document:s;if(this.size=100,e.map((function(t){return t.value})).reduce((function(t,e){return t+e}),0)>1)throw new Error("The sum of entries can not be greater than 1");this.document=u,this.spacing="pie"===r?0:i,this.entries=e,this.thickness="pie"===r?this.size/2:r}return t.prototype.getSVGElement=function(){var t=this.constructSegments(),e=this.document.createElementNS("http://www.w3.org/2000/svg","svg");return e.setAttributeNS("","viewBox","0 0 "+this.size+" "+this.size),t.forEach((function(t){return e.appendChild(t.getSVGElement())})),e},t.prototype.constructSegments=function(){var t,e,n=this.correctSegmentsForSpacing({segments:this.entries,spacing:this.spacing}),r=0,s=[];try{for(var u=o(n),c=u.next();!c.done;c=u.next()){var a=c.value;s.push(new i.Segment({_document:this.document,color:a.color,length:a.value,size:this.size,start:r,thickness:this.thickness})),r+=a.value+this.spacing}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=u.return)&&e.call(u)}finally{if(t)throw t.error}}return s},t.prototype.correctSegmentsForSpacing=function(t){var e=t.segments,n=1-t.spacing*e.length;return e.map((function(t){return r(r({},t),{value:t.value*n})})).map((function(t){return r(r({},t),{value:parseFloat(t.value.toFixed(4))})}))},t}();e.Donut=s}])}));