UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 1.97 kB
"use strict";var t=require("vue");function e(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var r={name:"Chart",emits:["select"],props:{type:String,data:null,options:null,width:{type:Number,default:300},height:{type:Number,default:150}},chart:null,mounted(){this.initChart()},beforeUnmount(){this.chart&&(this.chart.destroy(),this.chart=null)},watch:{data(){this.reinit()},type(){this.reinit()},options(){this.reinit()}},methods:{initChart(){Promise.resolve().then((function(){return e(require("chart.js"))})).then((t=>{t&&t.default&&(this.chart=new t.default(this.$refs.canvas,{type:this.type,data:this.data,options:this.options}))}))},getCanvas(){return this.$canvas},getBase64Image(){return this.chart.toBase64Image()},refresh(){this.chart&&this.chart.update()},reinit(){this.chart&&(this.chart.destroy(),this.initChart())},onCanvasClick(t){if(this.chart){const e=this.chart.getElementAtEvent(t),r=this.chart.getDatasetAtEvent(t);e&&e[0]&&r&&this.$emit("select",{originalEvent:t,element:e[0],dataset:r})}},generateLegend(){if(this.chart)return this.chart.generateLegend()}}};const i={class:"p-chart"};!function(t,e){void 0===e&&(e={});var r=e.insertAt;if(t&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===r&&i.firstChild?i.insertBefore(n,i.firstChild):i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}("\n.p-chart {\n position: relative;\n}\n"),r.render=function(e,r,n,a,s,h){return t.openBlock(),t.createBlock("div",i,[t.createVNode("canvas",{ref:"canvas",width:n.width,height:n.height,onClick:r[1]||(r[1]=t=>h.onCanvasClick(t))},null,8,["width","height"])])},module.exports=r;