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) 3.38 kB
this.primevue=this.primevue||{},this.primevue.chart=function(t,e,n){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=r(t),o=e.useStyle("\n.p-chart {\n position: relative;\n}\n",{name:"chart",manual:!0}),a={name:"Chart",extends:{name:"BaseChart",extends:i.default,props:{type:String,data:null,options:null,plugins:null,width:{type:Number,default:300},height:{type:Number,default:150},canvasProps:{type:null,default:null}},css:{classes:{root:"p-chart"},loadStyle:o.load},provide:function(){return{$parentInstance:this}}},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),n=this.chart.getElementsAtEventForMode(t,"dataset",{intersect:!0},!1);e&&e[0]&&n&&this.$emit("select",{originalEvent:t,element:e[0],dataset:n})}},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 u(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function s(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?u(Object(n),!0).forEach((function(e){l(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function l(t,e,n){return(e=h(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function h(t){var e=f(t,"string");return"symbol"===c(e)?e:String(e)}function f(t,e){if("object"!==c(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!==c(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var p=["width","height"];return a.render=function(t,e,r,i,o,a){return n.openBlock(),n.createElementBlock("div",n.mergeProps({class:t.cx("root")},t.ptm("root"),{"data-pc-name":"chart"}),[n.createElementVNode("canvas",n.mergeProps({ref:"canvas",width:t.width,height:t.height,onClick:e[0]||(e[0]=function(t){return a.onCanvasClick(t)})},s(s({},t.canvasProps),t.ptm("canvas"))),null,16,p)],16)},a}(primevue.basecomponent,primevue.usestyle,Vue);