UNPKG

@gitlab/ui

Version:
143 lines (129 loc) 3.38 kB
import echarts from 'echarts'; import theme, { themeName } from '../../../utils/charts/theme'; import { validRenderers, defaultHeight } from '../../../utils/charts/config'; import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js'; var script = { props: { options: { type: Object, required: true }, /** * Warning: this prop is deprecated and will soon be removed * Please do not utilize `disableTheme` for formatting * Use the `options` prop to set desired echarts formatting */ disableTheme: { type: Boolean, required: false, default: false }, width: { type: Number, required: false, default: null }, height: { type: Number, required: false, default: null }, groupId: { type: String, required: false, default: '' }, renderer: { type: String, required: false, default: 'svg', validator: function validator(renderer) { return validRenderers.includes(renderer); } } }, data: function data() { return { chart: null }; }, watch: { options: function options() { this.draw(); }, width: function width() { this.setChartSize(); }, height: function height() { this.setChartSize(); } }, created: function created() { if (!this.disableTheme) { echarts.registerTheme(themeName, theme); } }, mounted: function mounted() { this.chart = echarts.init(this.$refs.chart, this.disableTheme ? null : themeName, { renderer: this.renderer }); if (this.groupId.length) { this.chart.group = this.groupId; echarts.connect(this.groupId); } this.chart.on('click', this.clickHandler); this.$emit('created', this.chart); this.draw(); this.setChartSize(); }, beforeDestroy: function beforeDestroy() { this.chart.off('click', this.clickHandler); }, methods: { draw: function draw() { this.chart.setOption(this.options); this.$emit('updated', this.chart); }, setChartSize: function setChartSize() { this.chart.resize({ width: this.width || 'auto', height: this.height || defaultHeight }); }, clickHandler: function clickHandler(params) { this.$emit('chartItemClicked', { chart: this.chart, params: params }); } } }; /* script */ const __vue_script__ = script; /* template */ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{ref:"chart"})}; var __vue_staticRenderFns__ = []; /* style */ const __vue_inject_styles__ = undefined; /* scoped */ const __vue_scope_id__ = undefined; /* module identifier */ const __vue_module_identifier__ = undefined; /* functional template */ const __vue_is_functional_template__ = false; /* style inject */ /* style inject SSR */ /* style inject shadow dom */ const __vue_component__ = __vue_normalize__( { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ }, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined ); export default __vue_component__;