primevue
Version:
PrimeVue is an open source UI library for Vue 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 PrimeBloc
2 lines (1 loc) • 3.13 kB
JavaScript
import t from"primevue/basecomponent";import e from"primevue/chart/style";import{openBlock as r,createElementBlock as n,mergeProps as i,createElementVNode as o}from"vue";var a={name:"Chart",extends:{name:"BaseChart",extends:t,props:{type:String,data:null,options:null,plugins:null,width:{type:Number,default:300},height:{type:Number,default:150},canvasProps:{type:null,default:null}},style:e,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["select","loaded"],chart:null,watch:{data:{handler:function(){this.reinit()},deep:!0},type:function(){this.reinit()},options:function(){this.reinit()}},mounted:function(){this.initChart()},beforeUnmount:function(){this.chart&&(this.chart.destroy(),this.chart=null)},methods:{initChart:function(){var t=this;import("chart.js/auto").then((function(e){t.chart&&(t.chart.destroy(),t.chart=null),e&&e.default&&(t.chart=new e.default(t.$refs.canvas,{type:t.type,data:t.data,options:t.options,plugins:t.plugins})),t.$emit("loaded",t.chart)}))},getCanvas:function(){return this.$canvas},getChart:function(){return this.chart},getBase64Image:function(){return this.chart.toBase64Image()},refresh:function(){this.chart&&this.chart.update()},reinit:function(){this.initChart()},onCanvasClick:function(t){if(this.chart){var e=this.chart.getElementsAtEventForMode(t,"nearest",{intersect:!0},!1),r=this.chart.getElementsAtEventForMode(t,"dataset",{intersect:!0},!1);e&&e[0]&&r&&this.$emit("select",{originalEvent:t,element:e[0],dataset:r})}},generateLegend:function(){if(this.chart)return this.chart.generateLegend()}}};function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function s(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?s(Object(r),!0).forEach((function(e){h(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function h(t,e,r){var n;return(e="symbol"==c(n=l(e,"string"))?n:String(n))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t,e){if("object"!=c(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var f=["width","height"];a.render=function(t,e,a,c,s,h){return r(),n("div",i({class:t.cx("root"),style:t.sx("root")},t.ptmi("root")),[o("canvas",i({ref:"canvas",width:t.width,height:t.height,onClick:e[0]||(e[0]=function(t){return h.onCanvasClick(t)})},u(u({},t.canvasProps),t.ptm("canvas"))),null,16,f)],16)};export{a as default};