Skip to content

Commit be2734f

Browse files
authored
New build (#15)
1 parent 46133b5 commit be2734f

File tree

2 files changed

+164
-2
lines changed

2 files changed

+164
-2
lines changed

dist/vue3-chartjs.es.js

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,163 @@
1-
var e=Object.defineProperty,t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,n=(t,r,a)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[r]=a,o=(e,o)=>{for(var p in o||(o={}))r.call(o,p)&&n(e,p,o[p]);if(t)for(var p of t(o))a.call(o,p)&&n(e,p,o[p]);return e};import{defineComponent as p,ref as s,onMounted as l,h as i}from"vue";import{Chart as u,ArcElement as d,LineElement as f,BarElement as c,PointElement as h,BarController as y,BubbleController as b,DoughnutController as g,LineController as v,PieController as m,PolarAreaController as P,RadarController as D,ScatterController as O,CategoryScale as j,LinearScale as U,LogarithmicScale as w,RadialLinearScale as R,TimeScale as S,TimeSeriesScale as z,Decimation as C,Filler as E,Legend as I,Title as J,Tooltip as L}from"chart.js";const _=["install","start","stop","beforeInit","afterInit","beforeUpdate","afterUpdate","beforeElementsUpdate","reset","beforeDatasetsUpdate","afterDatasetsUpdate","beforeDatasetUpdate","afterDatasetUpdate","beforeLayout","afterLayout","afterLayout","beforeRender","afterRender","resize","destroy","uninstall","afterTooltipDraw","beforeTooltipDraw"];u.register(d,f,c,h,y,b,g,v,m,P,D,O,j,U,w,R,S,z,C,E,I,J,L);const q=p({name:"Vue3ChartJs",props:{type:{type:String,required:!0},data:{type:Object,required:!0},options:{type:Object,default:()=>({})},plugins:{type:Array,default:()=>[]}},emits:_,setup(e,{emit:t}){const r=s(null),a={chart:null,plugins:[_.reduce(((e,a)=>{const n=function(e,t=null){return{type:e,chartRef:t,preventDefault(){this._defaultPrevented=!0},isDefaultPrevented(){return!this._defaultPrevented},_defaultPrevented:!1}}(a,r);return o(o({},e),function(e,t){return{[t.type]:()=>(e(t.type,t),t.isDefaultPrevented())}}(t,n))}),{id:"Vue3ChartJsEventHookPlugin"}),...e.plugins],props:o({},e)},n=()=>a.chart?a.chart.update():a.chart=new u(r.value.getContext("2d"),{type:a.props.type,data:a.props.data,options:a.props.options,plugins:a.plugins});return l((()=>n())),{chartJSState:a,chartRef:r,render:n,resize:()=>a.chart&&a.chart.resize(),update:(e=750)=>{a.chart.data=o(o({},a.chart.data),a.props.data),a.chart.options=o(o({},a.chart.options),a.props.options),a.chart.update(e)},destroy:()=>{a.chart&&(a.chart.destroy(),a.chart=null)}}},render:()=>i("canvas",{ref:"chartRef"})});q.registerGlobalPlugins=e=>{u.register(...e)},q.install=(e,t={})=>{var r;e.component(q.name,q),(null==(r=null==t?void 0:t.plugins)?void 0:r.length)&&q.registerGlobalPlugins(t.plugins)};export{q as default};
1+
var __defProp = Object.defineProperty;
2+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3+
var __hasOwnProp = Object.prototype.hasOwnProperty;
4+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
5+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6+
var __spreadValues = (a, b) => {
7+
for (var prop in b || (b = {}))
8+
if (__hasOwnProp.call(b, prop))
9+
__defNormalProp(a, prop, b[prop]);
10+
if (__getOwnPropSymbols)
11+
for (var prop of __getOwnPropSymbols(b)) {
12+
if (__propIsEnum.call(b, prop))
13+
__defNormalProp(a, prop, b[prop]);
14+
}
15+
return a;
16+
};
17+
import { defineComponent, ref, onMounted, h } from "vue";
18+
import { Chart, ArcElement, LineElement, BarElement, PointElement, BarController, BubbleController, DoughnutController, LineController, PieController, PolarAreaController, RadarController, ScatterController, CategoryScale, LinearScale, LogarithmicScale, RadialLinearScale, TimeScale, TimeSeriesScale, Decimation, Filler, Legend, Title, Tooltip } from "chart.js";
19+
const chartJsEventNames = [
20+
"install",
21+
"start",
22+
"stop",
23+
"beforeInit",
24+
"afterInit",
25+
"beforeUpdate",
26+
"afterUpdate",
27+
"beforeElementsUpdate",
28+
"reset",
29+
"beforeDatasetsUpdate",
30+
"afterDatasetsUpdate",
31+
"beforeDatasetUpdate",
32+
"afterDatasetUpdate",
33+
"beforeLayout",
34+
"afterLayout",
35+
"afterLayout",
36+
"beforeRender",
37+
"afterRender",
38+
"resize",
39+
"destroy",
40+
"uninstall",
41+
"afterTooltipDraw",
42+
"beforeTooltipDraw"
43+
];
44+
function generateEventObject(type, chartRef = null) {
45+
return {
46+
type,
47+
chartRef,
48+
preventDefault() {
49+
this._defaultPrevented = true;
50+
},
51+
isDefaultPrevented() {
52+
return !this._defaultPrevented;
53+
},
54+
_defaultPrevented: false
55+
};
56+
}
57+
function generateChartJsEventListener(emit, event) {
58+
return {
59+
[event.type]: () => {
60+
emit(event.type, event);
61+
return event.isDefaultPrevented();
62+
}
63+
};
64+
}
65+
Chart.register(ArcElement, LineElement, BarElement, PointElement, BarController, BubbleController, DoughnutController, LineController, PieController, PolarAreaController, RadarController, ScatterController, CategoryScale, LinearScale, LogarithmicScale, RadialLinearScale, TimeScale, TimeSeriesScale, Decimation, Filler, Legend, Title, Tooltip);
66+
const Vue3ChartJs = defineComponent({
67+
name: "Vue3ChartJs",
68+
props: {
69+
type: {
70+
type: String,
71+
required: true
72+
},
73+
height: {
74+
type: Number,
75+
required: false,
76+
default: null
77+
},
78+
width: {
79+
type: Number,
80+
required: false,
81+
default: null
82+
},
83+
data: {
84+
type: Object,
85+
required: true
86+
},
87+
options: {
88+
type: Object,
89+
default: () => ({})
90+
},
91+
plugins: {
92+
type: Array,
93+
default: () => []
94+
}
95+
},
96+
emits: chartJsEventNames,
97+
setup(props, { emit }) {
98+
const chartRef = ref(null);
99+
const chartJsEventsPlugin = chartJsEventNames.reduce((reduced, eventType) => {
100+
const event = generateEventObject(eventType, chartRef);
101+
return __spreadValues(__spreadValues({}, reduced), generateChartJsEventListener(emit, event));
102+
}, { id: "Vue3ChartJsEventHookPlugin" });
103+
const chartJSState = {
104+
chart: null,
105+
plugins: [
106+
chartJsEventsPlugin,
107+
...props.plugins
108+
],
109+
props: __spreadValues({}, props)
110+
};
111+
const destroy = () => {
112+
if (chartJSState.chart) {
113+
chartJSState.chart.destroy();
114+
chartJSState.chart = null;
115+
}
116+
};
117+
const update = (animateSpeed = 750) => {
118+
chartJSState.chart.data = __spreadValues(__spreadValues({}, chartJSState.chart.data), chartJSState.props.data);
119+
chartJSState.chart.options = __spreadValues(__spreadValues({}, chartJSState.chart.options), chartJSState.props.options);
120+
chartJSState.chart.update(animateSpeed);
121+
};
122+
const resize = () => chartJSState.chart && chartJSState.chart.resize();
123+
const render = () => {
124+
if (chartJSState.chart) {
125+
return chartJSState.chart.update();
126+
}
127+
return chartJSState.chart = new Chart(chartRef.value.getContext("2d"), {
128+
type: chartJSState.props.type,
129+
data: chartJSState.props.data,
130+
options: chartJSState.props.options,
131+
plugins: chartJSState.plugins
132+
});
133+
};
134+
onMounted(() => render());
135+
return {
136+
chartJSState,
137+
chartRef,
138+
render,
139+
resize,
140+
update,
141+
destroy
142+
};
143+
},
144+
render(props) {
145+
return h("canvas", {
146+
ref: "chartRef",
147+
height: props.height,
148+
width: props.width
149+
});
150+
}
151+
});
152+
const _sfc_main = Vue3ChartJs;
153+
_sfc_main.registerGlobalPlugins = (plugins) => {
154+
Chart.register(...plugins);
155+
};
156+
_sfc_main.install = (app, options = {}) => {
157+
var _a;
158+
app.component(_sfc_main.name, _sfc_main);
159+
if ((_a = options == null ? void 0 : options.plugins) == null ? void 0 : _a.length) {
160+
_sfc_main.registerGlobalPlugins(options.plugins);
161+
}
162+
};
163+
export { _sfc_main as default };

dist/vue3-chartjs.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)