UNPKG

iep-ui

Version:

An enterprise-class UI design language and Vue-based implementation

121 lines (115 loc) 3.61 kB
import _extends from 'babel-runtime/helpers/extends'; import PropTypes from '../_util/vue-types'; import ChartTemplate from '../chart-template'; import { mergeProps } from '../_util/props-util'; import { isEmpty, omit } from 'lodash'; export default { name: 'IepPieChart', props: mergeProps({ data: PropTypes.object.def(function () {}), unit: PropTypes.array.def(function () { return []; }), theme: PropTypes.oneOf(['dark', 'light']).def('dark'), mixinOptions: PropTypes.object.def(function () {}) }, ChartTemplate.props), data: function data() { return { chartOptions: {}, themeColor: ['#0F6EFF', '#34D59B', '#FF9540', '#A36AFF', '#FFD240', '#80D8FF', '#FB4848', '#B8C32C', '#FF7BB8', '#82A8FF'] }; }, computed: { factor: function factor() { var _$props = this.$props, data = _$props.data, axis = _$props.axis, loading = _$props.loading, theme = _$props.theme; return { data: data, axis: axis, loading: loading, theme: theme }; } }, watch: { factor: { handler: function handler(e) { var _$props2 = this.$props, theme = _$props2.theme, mixinOptions = _$props2.mixinOptions; var tooltip = isEmpty(e.data.value) ? {} : { show: true, className: 'iep-chart-tooltip-' + theme }; this.chartOptions = _extends({}, omit(this.$props, ['data', 'axis', 'mixinOptions', 'theme']), { theme: theme, loading: e.loading, options: _extends({ color: this.themeColor, legend: { position: 'bottom', itemHeight: 14, itemWidth: 14, bottom: 10, data: isEmpty(e.data.value) ? ['--'] : e.data.value.map(function (item) { return item.name; }), selectedMode: isEmpty(e.data.value) ? false : true, itemStyle: { color: isEmpty(e.data.value) ? '#e5e5e5' : 'inherit' }, textStyle: { color: isEmpty(e.data.value) ? '#e5e5e5' : theme === 'light' ? '#000' : '#fff' } }, grid: [{ top: '6%', bottom: '16%', left: '6%', right: '6%', containLabel: true }], series: [_extends({ name: e.data.name, type: 'pie', radius: e.data.radius ? e.data.radius : '50%', center: e.data.center ? e.data.center : ['50%', '50%'], itemStyle: { borderColor: '#fff', borderWidth: 2 }, data: e.data.value, emphasis: { itemStyle: { borderWidth: 0 } }, label: { show: true, color: theme === 'dark' ? '#fff' : '#000', formatter: function formatter(val) { return val.name + ' ' + val.percent + '%'; } } }, mixinOptions.label)], tooltip: tooltip }, mixinOptions) }); }, immediate: true, deep: true } }, render: function render() { var h = arguments[0]; var chartOptions = this.chartOptions; if (!isEmpty(chartOptions)) { return h(ChartTemplate, { props: _extends({}, chartOptions) }); } else { return h(ChartTemplate); } } };