UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime

2 lines (1 loc) 2.57 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),r=require("primereact/componentbase"),n=require("primereact/hooks"),u=require("primereact/utils");function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=a(e),s=r.ComponentBase.extend({defaultProps:{__TYPE:"Chart",id:null,type:null,data:null,options:null,plugins:null,width:null,height:null,style:null,className:null,children:void 0},css:{classes:{root:"p-chart"},inlineStyles:{root:function(e){var t=e.props;return Object.assign({width:t.width,height:t.height},t.style)}},styles:"\n @layer primereact {\n .p-chart {\n position: relative\n }\n }\n "}}),o=function(){try{return Chart}catch(e){return null}}(),c=i.memo(i.forwardRef((function(e,c){var l=n.useMergeProps(),p=i.useContext(t.PrimeReactContext),f=s.getProps(e,p),d=s.setMetaData({props:f}),h=d.ptm,g=d.cx,m=d.sx;r.useHandleStyle(s.css.styles,d.isUnstyled,{name:"chart"});var y=i.useRef(null),v=i.useRef(null),b=i.useRef(null),w=function(){P();var e={type:f.type,data:f.data,options:f.options,plugins:f.plugins};o?v.current=new o(b.current,e):Promise.resolve().then((function(){return a(require("chart.js/auto"))})).then((function(t){P(),b.current&&t&&(v.current=t.default?new t.default(b.current,e):new t(b.current,e))}))},P=function(){v.current&&(v.current.destroy(),v.current=null)};i.useImperativeHandle(c,(function(){return{props:f,getCanvas:function(){return b.current},getChart:function(){return v.current},getBase64Image:function(){return v.current.toBase64Image()},getElement:function(){return y.current},generateLegend:function(){return v.current&&v.current.generateLegend()},refresh:function(){return v.current&&v.current.update()}}})),i.useEffect((function(){w()})),n.useUnmountEffect((function(){P()}));var C=f.ariaLabel||f.options&&f.options.plugins&&f.options.plugins.title&&f.options.plugins.title.text,O=l({id:f.id,ref:y,style:m("root"),className:u.classNames(f.className,g("root"))},s.getOtherProps(f),h("root")),j=l({ref:b,width:f.width,height:f.height,role:"img","aria-label":C},h("canvas"));return i.createElement("div",O,i.createElement("canvas",j))})),(function(e,t){return e.data===t.data&&e.options===t.options&&e.type===t.type}));c.displayName="Chart",exports.Chart=c;