salad-ui.chart
Version:
Reusable React UI Components Toolkit
1 lines • 27.6 kB
JavaScript
module.exports=function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t){e.exports=require("react")},function(e,t,r){e.exports=r(8)()},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=t.currencyToSymbol=function(e){switch(e){case"EUR":return"€";case"DKK":return"kr";case"GBP":return"£";case"USD":default:return"$"}},i=(t.formatCurrency=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(null!==e&&""!==e){"number"!=typeof e&&(e=parseFloat(e)),e=e.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g,"$1,");var r=o(t);switch(t){case"EUR":case"DKK":return""+r+e;case"USD":default:return""+r+e}return o(t)+" "+e}},t.formatNumber=function(e){var t=e.toString().split(".");return(t[0]+(t[1]?"."+t[1].slice(0,2):"")).replace(/\B(?=(\d{3})+(?!\d))/g,",")},t.numberToString=function(e){var t=parseFloat(e);return isNaN(t)?e:t>1e9?Math.round(t/1e8)/10+"B":t>1e7?Math.round(t/1e6)+"M":t>1e6?Math.round(t/1e5)/10+"M":t>1e4?Math.round(t/1e3)+"K":t>1e3?Math.round(t/100)/10+"K":Math.round(100*t)/100},t.mapList=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=t.map(function(t){return"object"===(void 0===t?"undefined":n(t))?l(e,t,r+1).value:t});if(0===o.length)return"none";var i="",a=0;for(a;a<=o.length-1;a++)i+=o[a],i+=a===o.length-1?"":a===o.length-2?" and ":", ";return i}),a=t.mapSum=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=t.map(function(t){return"object"===(void 0===t?"undefined":n(t))?l(e,t,r+1).value:t});if(0===o.length)return 0;var i=0,a=0;for(a;a<=o.length-1;a++)i+=parseFloat(o[a]);return i},l=t.readProperty=function e(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(!t||!t[o])return{value:"_invalid_key_",iteration:o};var l=void 0===r?"undefined":n(r);if("string"===l||"number"===l);else{if(t[o]&&t[o]in r)return o<t.length-1&&"object"===n(r[t[o]])?e(t,r[t[o]],o+1):{value:r[t[o]],iteration:o};if(~["all","first","sum","mean","random"].indexOf(t[o])&&r instanceof Array)switch(t[o]){case"first":return r[0]?e(t,r[0],o+1):{value:"_invalid_array_",iteration:o};case"random":return e(t,r[Math.floor(Math.random()*r.length)],o+1);case"all":return e(t,i(t,r,o),o);case"sum":return e(t,a(t,r,o),o);case"mean":case"avg":return e(t,a(t,r,o)/r.length,o)}}return{value:"_invalid_key_",iteration:o}};t.render=function(e,t){return e.replace(/([{}])\1|[{](.*?)(?:!(.+?))?[}]/g,function(e,r,n){var o=l(n.split("."),t).value;return"function"==typeof o?o():o})}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=r(0),a=function(e){return e&&e.__esModule?e:{default:e}}(i),l=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,i.Component),o(t,[{key:"render",value:function(){return a.default.createElement("svg",{className:"react-chart "+this.props.type,width:this.props.width,style:n({overflow:"visible",border:this.props.border},this.props.style),height:this.props.height},this.props.children)}}]),t}();l.defaultProps={border:"none",height:400,width:600,style:{}},t.default=l},function(e,t,r){e.exports=r(5)},function(e,t,r){"use strict";var n=function(e){return e&&e.__esModule?e:{default:e}}(r(6));e.exports=n.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(7)),i=n(r(13)),a=n(r(14)),l=n(r(15));t.default={Area:o.default,CirclePie:a.default,BarMetric:l.default,Bar:i.default}},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}Object.defineProperty(t,"__esModule",{value:!0});var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),s=r(0),u=n(s),p=n(r(1)),f=n(r(12)),d=r(2),c=n(r(3)),h=function(e){function t(){var e,r,n,o;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var a=arguments.length,l=Array(a),s=0;s<a;s++)l[s]=arguments[s];return r=n=i(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(l))),n.tipsData={},n.xAxisLabels=[],o=r,i(n,o)}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,s.Component),l(t,[{key:"describeLine",value:function(e,t,r,n,o,i,a){var l=this,s=0===o&&0===r;return e.map(function(e,n){return Math.max(0,(e.time-t)*i-l.props.strokeWidth)+","+(s?a:(o-(e.value-r))*a)}).join(" ")}},{key:"centerElement",value:function(e,t,r){arguments.length>3&&void 0!==arguments[3]&&arguments[3]&&e.setAttribute("width",r);var n=t-r/2;e.setAttribute("x",n)}},{key:"showPointTip",value:function(e,t){var r=this.refs[e.ref],n=r.getElementsByClassName("tip-background")[0],o=r.getElementsByClassName("tip-text-date")[0],i=r.getElementsByClassName("tip-text-value")[0];this.centerElement(o,this.tipsData[e.ref].xBase,o.getBBox().width),this.centerElement(i,this.tipsData[e.ref].xBase,i.getBBox().width),this.centerElement(n,this.tipsData[e.ref].xBase,Math.max(o.getBBox().width,i.getBBox().width)+2*this.props.tipsPadding,!0),r.style.display="block"}},{key:"hidePointTip",value:function(e,t){this.refs[e.ref].style.display="none"}},{key:"renderTipText",value:function(e,t){if("function"==typeof e)return e(t);if("string"==typeof e)return e.replace("{{date}}",(0,f.default)(t.date).format(t.dateFormat||"YYYY-MM-DD")).replace("{{date1}}",(0,f.default)(t.date1).format(t.dateFormat||"YYYY-MM-DD")).replace("{{date2}}",(0,f.default)(t.date2).format(t.dateFormat||"YYYY-MM-DD")).replace("{{value}}",(0,d.formatNumber)(t.value));throw new Error("Invalid labelTemplate type!")}},{key:"renderTips",value:function(e,t,r,n,o,i,a){var l=this,s=void 0,p=void 0,f="{{date}}",d=void 0,c=864e5,h=0===o&&0===r;if(0!==e.length)return s=1===e.length?0:e[1].time-e[0].time,n>220752e6?p="YYYY":n>23328e6?p="MMM":n>7*c?p="MMM Do":n<c&&(p="LT"),s>27*c&&s<32*c?p="MMMM":s>c?(p="MMM Do",f="{{date1}} through {{date2}}"):p=n<c?"LT":"MMM Do",e.map(function(n,c){if(0!==c&&c!==e.length-1||l.props.showFirstAndLastTip){d=e[c+1]?e[c+1].time:n.time+s,n.label||(n.label="{{value}} views");var b=(n.time-t)*i,y="point_"+c+"_tooltip",m=p,g=(h?a:(o-(n.value-r))*a)-l.props.tipsPadding/2,v=[b-l.props.tipStrokeWidth-12.5+","+(g-25+9),b-l.props.tipStrokeWidth+12.5+","+(g-25+9),b-l.props.tipStrokeWidth+","+(g-25+10+9)].join(" "),x=[b-l.props.tipStrokeWidth-12.5+","+(g-25+10),b-l.props.tipStrokeWidth+12.5+","+(g-25+10),b-l.props.tipStrokeWidth+","+(g-25+10+10)].join(" ");return l.tipsData[y]={xBase:b},new Date(n.time).getFullYear()!==(new Date).getFullYear()&&(m+=" YYYY"),u.default.createElement("g",{key:"point-"+c,ref:y,style:{display:"none",position:"relative",zIndex:4},className:"value-tip"},u.default.createElement("rect",{className:"tip-background",x:(n.time-t)*i-l.props.strokeWidth-l.props.tipsWidth/2,y:g-38-25,width:l.props.tipsWidth+l.props.tipsPadding,height:38+l.props.tipsPadding,style:{stroke:l.props.tipStrokeColor,strokeWidth:l.props.tipStrokeWidth,fill:l.props.tipsFill}}),u.default.createElement("polygon",{points:x,style:{stroke:l.props.tipStrokeColor,opacity:.5,strokeWidth:l.props.tipStrokeWidth}}),u.default.createElement("polygon",{points:v,style:{fill:l.props.tipsFill}}),u.default.createElement("text",{className:"tip-text-date",x:b-l.props.tipsWidth/2+2,y:g-l.props.strokeWidth-38-25+l.props.tipsPadding+10,style:{fontSize:14,fontWeight:"light"},dangerouslySetInnerHTML:{__html:l.renderTipText(f,{dateFormat:m,date:n.time,date1:n.time,date2:d,value:n.value})}}),u.default.createElement("text",{className:"tip-text-value",x:b-l.props.tipsWidth/2+2,y:g-l.props.strokeWidth-38-25+l.props.tipsPadding+30,style:{fontSize:16,fontWeight:"bold"},dangerouslySetInnerHTML:{__html:l.renderTipText(l.props.labelTemplate,{value:n.value,date:n.time})}}))}})}},{key:"renderPoints",value:function(e,t,r,n,o,i,a){var l=this,s=0===o&&0===r;return e.map(function(n,p){if(0!==p&&p!==e.length-1||l.props.showFirstAndLastTip)return u.default.createElement("circle",{key:"point-"+p,cx:(n.time-t)*i-l.props.strokeWidth/2,cy:s?a:(o-(n.value-r))*a,r:l.props.pointsRadius,onMouseOver:l.showPointTip.bind(l,{ref:"point_"+p+"_tooltip"}),onMouseLeave:l.hidePointTip.bind(l,{ref:"point_"+p+"_tooltip"}),style:{stroke:l.props.strokeColor,strokeWidth:l.props.strokeWidth,fill:"white",cursor:"default"}})})}},{key:"renderLabel",value:function(e,t){return e.x||("right"===this.props.yLabelsPosition?e.x=this.activeWidth+(this.props.yLabelsOutside?5:-1*(20+5*(e.txt.length||1))):e.x=20),e.ref||(e.ref="label."+t+","+e.x+","+e.y),u.default.createElement("text",{key:"graph.xAxis.label."+e.ref,x:e.x,y:e.y,ref:e.ref,fill:this.props.labelColor,style:{fontSize:this.props.labelFontSize,textShadow:this.props.labelTextShadow}},e.txt)}},{key:"renderYGridLine",value:function(e,t){return u.default.createElement("line",{key:"graph.ygridLine."+t,x1:"0",y1:e.y,x2:this.activeWidth-this.props.strokeWidth,y2:e.y,fill:this.props.labelColor,style:{stroke:this.props.gridColor,strokeWidth:1}})}},{key:"describeYAxis",value:function(e,t,r){function n(e,t){return t||(t=100),e>t&&n(e,5*t),Math.ceil(e/t)*t/10}var o=n(t,t/10),i=0===t&&0===e;return{gridLines:[1,2,3,4,5,6,7,8,9].map(function(e){return{y:i?r:(t-e*o)*r}}),labels:[0,1,2,3,4].map(function(n){var a=n*o*2;return{y:i?r:(t-n*o*2)*r,txt:(0,d.formatNumber)(Math.round(a+e))}})}}},{key:"reduceData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],r=arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:12,o=[];e.forEach(function(t,r){t.time||(e[r].time=t.id||0),o.push(t)});var i=parseFloat(t.format("x")),l=parseFloat(r.format("x"));if((o=o.filter(function(e){return e.time>=i&&e.time<=l})).length>n){var s=o.length/n,u=[];return o.forEach(function(e,t){var r=Math.floor(t/s),n=parseFloat(e.value);u[r]?u[r].value+=n:u[r]={value:n,label:"{{value}} "+e.label,time:e.time}}),"mean"===this.props.formula?u.map(function(e){return a({},e,{value:Math.round(100*e.value/s)/100})}):u}return o}},{key:"describeXAxis",value:function(e,t,r,n){var o=this,i=[1,2,3,4,5,6,7,8,9],a=(n.length,i.length,"ddd"),l=[];return e<1e4?{labels:[]}:(i.length>n.length&&(i=n.map(function(e,t){return t+1}),1),t>220752e6?a="YYYY":t>23328e6?a="MMM":t>6048e5?a="MMM D":t<864e5&&(a="LT"),i.forEach(function(n,s){var u=e+n*(t/i.length);s<i.length-1&&l.push({txt:(0,f.default)(u).format(a),time:u,x:(u-e)*r,y:o.activeHeight+30,ref:"xLabel."+s})}),this.xAxisLabels=l,{labels:l})}},{key:"centerXAxisLabelMarkers",value:function(){var e=this;this.xAxisLabels.forEach(function(t){var r=e.refs[t.ref];e.centerElement(r,t.x,r.getBBox().width)})}},{key:"componentDidMount",value:function(){this.centerXAxisLabelMarkers()}},{key:"componentDidUpdate",value:function(){this.centerXAxisLabelMarkers()}},{key:"render",value:function(){var e=this,t=this.props.data;this.activeWidth=this.props.width,this.activeHeight=this.props.height-50,t.forEach(function(e,r){e.time||(t[r].time=r),e.time instanceof Date||(t[r].time=new Date(t[r].time).getTime())}),t=t.sort(function(e,t){return e.time===t.time?0:e.time>t.time?1:-1});var r=Math.max.apply(Math,o(t.map(function(e,t){return e.time})).concat([t.length])),n=Math.min.apply(Math,o(t.map(function(e,t){return e.time})));-1!==this.props.maxPoints&&(t=this.reduceData(t,(0,f.default)(n),(0,f.default)(r),this.props.maxPoints),r=Math.max.apply(Math,o(t.map(function(e,t){return e.time})).concat([t.length])));var i=Math.max.apply(Math,o(t.map(function(e){return e.value}))),a=Math.pow(10,String(Math.round(i)).length-1),l=(this.props.yPadding,Math.max(Math.ceil(i/a)*a,1)),s=this.props.useDynamicYMin?Math.min.apply(Math,o(t.map(function(e){return e.value})))-l/5:0,p=r-n,d=l-s,h=this.activeWidth/(p||1),b=this.activeHeight/(d||1),y=this.describeLine(t,n,s,p,d,h,b),m="0,"+((x?b:d*b)-this.props.strokeWidth)+" "+y+" "+((r-n)*h-this.props.strokeWidth)+","+((x?b:d*b)-this.props.strokeWidth),g=this.describeYAxis(s,d,b),v=this.describeXAxis(n,p,h,t),x=0===d&&0===s;return t&&t.length?u.default.createElement(c.default,{width:this.props.width,height:this.props.height,type:"area"},g.gridLines.map(this.renderYGridLine.bind(this)),u.default.createElement("polygon",{points:m,style:{fill:this.props.fillColor,strokeWidth:0}}),u.default.createElement("polyline",{points:y,style:{stroke:this.props.strokeColor,strokeDasharray:this.props.strokeDasharray,strokeWidth:this.props.strokeWidth,fill:"none"}}),g.labels.map(this.renderLabel.bind(this)),v.labels.map(function(t,r){return u.default.createElement("line",{key:"graph.xAxis.label."+r,ref:t.ref+".marker",x1:t.x,x2:t.x,y1:e.activeHeight,y2:e.activeHeight+10,stroke:e.props.gridColor,strokeWidth:1})}),v.labels.map(this.renderLabel.bind(this)),this.renderPoints(t,n,s,p,d,h,b),this.renderTips(t,n,s,p,d,h,b)):null}}]),t}();h.propTypes={width:p.default.number,height:p.default.number,border:p.default.string,strokeWidth:p.default.number,useDynamicYMin:p.default.bool,strokeColor:p.default.string,strokeDasharray:p.default.number,pointsRadius:p.default.number,showFirstAndLastTip:p.default.bool,tipsWidth:p.default.number,tipsHeight:p.default.number,tipsPadding:p.default.number,tipStrokeWidth:p.default.number,tipStrokeColor:p.default.string,tipsFill:p.default.string,gridColor:p.default.string,labelFontSize:p.default.number,labelTextShadow:p.default.string,labelColor:p.default.string,fillColor:p.default.string,maxOverflow:p.default.number,maxPoints:p.default.number,yLabelsOutside:p.default.bool,yLabelsPosition:p.default.string,formula:p.default.string,yPadding:p.default.number,data:p.default.array},h.defaultProps={width:640,height:320,border:"none",strokeWidth:2,useDynamicYMin:!1,strokeColor:"#408AE5",strokeDasharray:0,pointsRadius:5,showFirstAndLastTip:!1,tipsWidth:240,tipsHeight:22,tipsPadding:10,tipStrokeWidth:1,tipStrokeColor:"#BBBBBB",tipsFill:"white",gridColor:"rgba(230,230,230,.5)",labelFontSize:12,labelTextShadow:"1px 1px #fff",labelColor:"#555",labelTemplate:"{{value}}",fillColor:"rgba(191, 216, 246, 0.3)",maxOverflow:20,yLabelsOutside:!1,yLabelsPosition:"left",yPadding:10,maxPoints:-1,formula:"sum",data:[]},t.default=h},function(e,t,r){"use strict";var n=r(9),o=r(10),i=r(11);e.exports=function(){function e(e,t,r,n,a,l){l!==i&&o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=n,r.PropTypes=r,r}},function(e,t,r){"use strict";function n(e){return function(){return e}}var o=function(){};o.thatReturns=n,o.thatReturnsFalse=n(!1),o.thatReturnsTrue=n(!0),o.thatReturnsNull=n(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(e){return e},e.exports=o},function(e,t,r){"use strict";var n=function(e){};e.exports=function(e,t,r,o,i,a,l,s){if(n(t),!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var p=[r,o,i,a,l,s],f=0;(u=new Error(t.replace(/%s/g,function(){return p[f++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}}},function(e,t,r){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t){e.exports=require("moment")},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=r(0),a=n(i),l=n(r(1)),s=r(2),u=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,i.Component),o(t,[{key:"formatValue",value:function(e){return"%"===this.props.metricName?Math.round(e):(0,s.formatNumber)(e)}},{key:"renderYGridLine",value:function(e,t){return a.default.createElement("line",{key:"graph.ygridLine."+t,x1:0,y1:e.y,x2:this.props.width,y2:e.y,style:{stroke:this.props.gridColor,strokeWidth:1}})}},{key:"describeYAxis",value:function(e,t,r){function n(e,t){return t||(t=100),e>t&&n(e,5*t),Math.ceil(e/t)*t/10}var o=this,i=n(t,t/10),a=0===t&&0===e;return{gridLines:[1,2,3,4,5,6,7,8,9].map(function(e){return{y:a?r:(t-e*i)*r}}),labels:[0,1,2,3,4].map(function(n){var l=n*i*2;return{y:a?r:(t-n*i*2)*r,txt:(0,s.formatNumber)(Math.round(l+e))+(o.props.isPercent?"%":"")}})}}},{key:"renderTip",value:function(e,t,r,n){[r-12.5+","+n-10,r+12.5+","+n-10,r+","+(n+10)-10].join(" "),[r-12.5+","+n-10,r+12.5+","+n-10,r+","+(n+10)-10].join(" ");return a.default.createElement("g",{key:"point."+e,ref:"point."+e},a.default.createElement("text",{x:r-14,y:n-7.5,style:{fontSize:16,fontWeight:"bold"}},t))}},{key:"renderLabel",value:function(e,t){return e.x||("right"===this.props.yLabelsPosition?e.x=this.activeWidth+(this.props.yLabelsOutside?5:-1*(20+5*(e.txt.length||1))):e.x=0),e.ref||(e.ref="label."+t+","+e.x+","+e.y),a.default.createElement("text",{key:"graph.yAxis.label."+e.ref,x:e.x,y:e.y,ref:e.ref,fill:this.props.labelColor,style:{fontSize:this.props.labelFontSize,textShadow:this.props.labelTextShadow,textAlign:"center"}},e.txt)}},{key:"render",value:function(){var e=this,t=this.props.height-this.props.bottomBarHeight,r=1.1*Math.max.apply(Math,function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(this.props.data.map(function(e){return e.value})))-0,n=t/(r||1),o=this.describeYAxis(0,r,n),i=this.props.width/this.props.data.length,l=-1===this.props.barSize?i:this.props.barSize;return this.props.data&&this.props.data.length?a.default.createElement("svg",{width:this.props.width,height:this.props.height},o.gridLines.map(this.renderYGridLine.bind(this)),this.props.data.map(function(r,o){return a.default.createElement("g",{key:"bar.item."+o},a.default.createElement("rect",{fill:e.props.barColor,width:l,height:r.value*n,y:t-r.value*n,x:o*i-l/2+i/2-l/2}),e.renderTip(o,r.value+(e.props.isPercent?"%":""),o*i-l/2+i/2,t-r.value*n))}),o.labels.map(this.renderLabel.bind(this)),this.props.data.map(function(r,n){return a.default.createElement("text",{key:"graph.xAxis.label."+n,x:n*i-l/2+i/2-5,y:t+e.props.bottomBarHeight,fill:e.props.labelColor,style:{fontSize:e.props.labelFontSize,textShadow:e.props.labelTextShadow}},r.label)})):null}}]),t}();u.defaultProps={data:[],metricName:"points",metricColor:"#777",barSize:20,barRailColor:null,barColor:"#408AE5",gridColor:"rgba(230,230,230,.5)",label:"N/A",width:400,height:200,bottomBarHeight:20,yLabelsOutside:!0,labelFontSize:12,labelTextShadow:"1px 1px #fff",labelColor:"#555",isPercent:!1,labelTemplate:"{{value}}"},u.propTypes={metricName:l.default.string,barSize:l.default.number,label:l.default.string,metricColor:l.default.string,barColor:l.default.string,barRailColor:l.default.string},t.default=u},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=r(0),a=n(i),l=n(r(1)),s=n(r(3)),u=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,i.Component),o(t,[{key:"polarToCartesian",value:function(e,t,r,n){var o=(n-90)*Math.PI/180;return{x:e+r*Math.cos(o),y:t+r*Math.sin(o)}}},{key:"describeArc",value:function(e,t,r,n,o){e&&t||console.error("x or y missing to describeArc");var i=this.polarToCartesian(e,t,r,o),a=this.polarToCartesian(e,t,r,n),l=o-n<=180?"0":"1";return["M",i.x,i.y,"A",r,r,0,l,0,a.x,a.y].join(" ")}},{key:"render",value:function(){var e=Math.min(this.props.percent||0,100),t=this.props.width/2-this.props.strokeWidth/2-this.props.padding,r=t+this.props.strokeWidth/2+this.props.padding,n=3.6*e,o=e+"%",i=3===o.length?-.6:-.95,l=this.describeArc(r,r,t,0,n-.001);return a.default.createElement(s.default,{width:this.props.width,style:this.props.style,height:this.props.height,border:this.props.border},a.default.createElement("circle",{cx:r,cy:r,r:t,fill:this.props.fillColor,stroke:this.props.railColor,strokeWidth:this.props.strokeWidth}),a.default.createElement("path",{fill:this.props.fillColor,stroke:this.props.strokeColor,strokeWidth:this.props.strokeWidth,d:l}),a.default.createElement("text",{x:r,y:r,dx:i+"em",dy:".35em",fill:this.props.labelColor,fontWeight:this.props.labelFontWeight,fontSize:this.props.labelFontSize},o))}}]),t}();u.propTypes={width:l.default.number,height:l.default.number,strokeWidth:l.default.number,strokeColor:l.default.string,labelFontWeight:l.default.string,labelFontSize:l.default.string,fillColor:l.default.string,startAngle:l.default.number,endAngle:l.default.number,radius:l.default.number,style:l.default.object},u.defaultProps={width:150,height:150,border:"none",strokeWidth:10,style:{},labelColor:"#408AE5",labelFontSize:"1.2em",labelFontWeight:"bold",strokeColor:"#408AE5",railColor:"#f5f5f5",fillColor:"none",percent:0,padding:0},t.default=u},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=n(r(0)),a=n(r(1)),l=r(2),s=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,i.default.Component),o(t,[{key:"formatValue",value:function(e){return"%"===this.props.metricName?Math.round(e):(0,l.formatNumber)(e)}},{key:"render",value:function(){return i.default.createElement("div",{style:{position:"relative",marginBottom:15}},i.default.createElement("div",{style:{fontSize:13,textTransform:"uppercase"}},this.props.label),i.default.createElement("div",{className:"bar-row"},i.default.createElement("div",{style:{backgroundColor:this.props.barRailColor,width:"100%",height:this.props.barHeight,display:"block",marginTop:4,position:"relative"}},i.default.createElement("div",{style:{width:this.props.percent+"%",height:this.props.barHeight,position:"absolute",backgroundColor:this.props.barColor,top:0,left:0,bottom:0,transition:"all .5s"}})),i.default.createElement("div",{style:{paddingLeft:this.props.metricPadding,fontSize:13,display:"inline-block",position:"absolute",right:0,top:0,fontWeight:"bold",color:this.props.metricColor,textAlign:"right"}},this.formatValue(this.props.value)+" "+this.props.metricName)))}}]),t}();s.defaultProps={metricName:"points",value:"0",percent:100,metricPadding:15,metricColor:"#777",barHeight:7,barRailColor:"#ddd",barColor:"#408AE5",label:"N/A"},s.propTypes={metricName:a.default.string,percent:a.default.number,barWidth:a.default.number,barHeight:a.default.number,metricPadding:a.default.number,label:a.default.string,metricColor:a.default.string,barColor:a.default.string,barRailColor:a.default.string},t.default=s}]);