iep-ui
Version:
An enterprise-class UI design language and Vue-based implementation
124 lines (118 loc) • 3.73 kB
JavaScript
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: 'IepNightingaleChart',
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,
title: _extends({
text: e.data.name,
left: 'center',
align: 'center',
top: 'middle',
textStyle: {
fontWeight: 400,
fontSize: 14,
color: theme === 'light' ? '#333' : '#fff'
}
}, e.data.title),
legend: {
position: 'bottom',
itemHeight: 14,
itemWidth: 14,
bottom: 4,
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: [{
name: e.data.name,
type: 'pie',
radius: e.data.radius ? e.data.radius : [40, 120],
center: e.data.center ? e.data.center : ['50%', '50%'],
roseType: 'area',
data: e.data.value,
label: {
show: true,
color: theme === 'dark' ? '#fff' : '#000',
formatter: function formatter(val) {
return val.name + ' ' + val.percent + '%';
}
}
}],
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);
}
}
};