primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 80+ 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) • 1.75 kB
JavaScript
import*as t from"react";import{useUnmountEffect as e}from"primereact/hooks";import{ObjectUtils as n,classNames as r}from"primereact/utils";function u(){return u=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},u.apply(this,arguments)}var a=function(){try{return Chart}catch(t){return null}}(),i=t.memo(t.forwardRef((function(c,l){var o=t.useRef(null),s=t.useRef(null),f=t.useRef(null),p=function(){h();var t={type:c.type,data:c.data,options:c.options,plugins:c.plugins};a?s.current=new a(f.current,t):import("chart.js/auto").then((function(e){h(),e&&(s.current=e.default?new e.default(f.current,t):new e(f.current,t))}))},h=function(){s.current&&(s.current.destroy(),s.current=null)};t.useImperativeHandle(l,(function(){return{props:c,getCanvas:function(){return f.current},getChart:function(){return s.current},getBase64Image:function(){return s.current.toBase64Image()},getElement:function(){return o.current},generateLegend:function(){return s.current&&s.current.generateLegend()},refresh:function(){return s.current&&s.current.update()}}})),t.useEffect((function(){p()})),e((function(){h()}));var d=n.findDiffKeys(c,i.defaultProps),g=r("p-chart",c.className),m=Object.assign({width:c.width,height:c.height},c.style);return t.createElement("div",u({id:c.id,ref:o,style:m,className:g},d),t.createElement("canvas",{ref:f,width:c.width,height:c.height}))})),(function(t,e){return t.data===e.data&&t.options===e.options&&t.type===e.type}));i.displayName="Chart",i.defaultProps={__TYPE:"Chart",id:null,type:null,data:null,options:null,plugins:null,width:null,height:null,style:null,className:null};export{i as Chart};