UNPKG

dbl-components

Version:

Framework based on bootstrap 5

2 lines 8.6 kB
function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return}finally{if(o)throw n}}return a}}function _arrayWithHoles(r){if(Array.isArray(r))return r}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e))}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t})()}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t)}:p}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value}},_get.apply(null,arguments)}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},_getPrototypeOf(t)}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e)}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},_setPrototypeOf(t,e)}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}import{createRef}from"react";import PropTypes from"prop-types";import{Doughnut,Bar,Bubble,Chart,Line,Pie,PolarArea,Radar,Scatter}from"react-chartjs-2";import{eventHandler}from"dbl-utils";import ProportionalContainer from"../containers/proportional-container";import Icons from"../media/icons";var graphs={Doughnut:Doughnut,Bar:Bar,Bubble:Bubble,Chart:Chart,Line:Line,Pie:Pie,PolarArea:PolarArea,Radar:Radar,Scatter:Scatter};export var addGraphs=function addGraphs(moreGraphs){return Object.assign(graphs,moreGraphs)};var Chartjs=/*#__PURE__*/function(_ProportionalContaine){function Chartjs(props){var _this;_classCallCheck(this,Chartjs);_this=_callSuper(this,Chartjs,[props]);_defineProperty(_this,"events",[]);_this.refChart=/*#__PURE__*/createRef();_this.events.push(["ready."+_this.props.name,_this.onReadyElement.bind(_this)],["resize."+_this.props.name,_this.onResizeElement.bind(_this)]);Object.assign(_this.state,{});return _this}_inherits(Chartjs,_ProportionalContaine);return _createClass(Chartjs,[{key:"componentDidMount",value:function componentDidMount(){var _this2=this;this.events.forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),e=_ref2[0],cb=_ref2[1];return eventHandler.subscribe(e,cb,_this2.name)});_superPropGet(Chartjs,"componentDidMount",this,3)([])}},{key:"componentWillUnmount",value:function componentWillUnmount(){var _this3=this;_superPropGet(Chartjs,"componentWillUnmount",this,3)([]);this.events.forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,1),e=_ref4[0];return eventHandler.unsubscribe(e,_this3.name)});clearTimeout(this.timeoutUpdate)}},{key:"onReadyElement",value:function onReadyElement(obj){}},{key:"onResizeElement",value:function onResizeElement(resize){if(this.refChart.current)this.refChart.current.update()}},{key:"content",value:function content(){var _this4=this;var children=arguments.length>0&&arguments[0]!==undefined?arguments[0]:this.props.children;var options=_objectSpread({},this.props.options);options.aspectRatio=1/((typeof ratio==="undefined"?"undefined":_typeof(ratio))==="object"?this.props.ratio[this.breakpoint]:this.props.ratio);var attribs={data:this.props.data,options:options,plugins:this.props.plugins,redraw:false,datasetIdKey:this.props.datasetIdKey,fallbackContent:this.props.fallbackContent,updateMode:this.props.updateMode,ref:function ref(_ref5){_this4.refChart.current=_ref5;if(_this4.props.ref)_this4.props.ref.current=_ref5}};var Graph=graphs[this.props.graph];var proportional=_superPropGet(Chartjs,"content",this,3)([/*#__PURE__*/React.createElement(React.Fragment,null,!this.props.loading?/*#__PURE__*/React.createElement(Graph,attribs):/*#__PURE__*/React.createElement(Icons,{icon:"spinner",classes:"spinner"}),children)]);return proportional}}])}(ProportionalContainer);_defineProperty(Chartjs,"jsClass","Chartjs");_defineProperty(Chartjs,"propTypes",_objectSpread(_objectSpread({},ProportionalContainer.propTypes),{},{data:PropTypes.oneOfType([PropTypes.array,PropTypes.object]).isRequired,ratio:PropTypes.oneOfType([PropTypes.number,PropTypes.objectOf(PropTypes.number)]),options:PropTypes.object,plugins:PropTypes.array,datasetIdKey:PropTypes.string,fallbackContent:PropTypes.node,updateMode:PropTypes.oneOf(["active","hide","none","normal","reset","resize","show"]),graph:PropTypes.string}));_defineProperty(Chartjs,"defaultProps",_objectSpread(_objectSpread({},ProportionalContainer.defaultProps),{},{ratio:1,options:{},plugins:[],datasetIdKey:"label",fallbackContent:null,graph:"Bar"}));export{Chartjs as default}; //# sourceMappingURL=_chartjs.js.map