UNPKG

iep-ui

Version:

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

190 lines (172 loc) 5.88 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); var _vueTypes = require('../_util/vue-types'); var _vueTypes2 = _interopRequireDefault(_vueTypes); var _chartTemplate = require('../chart-template'); var _chartTemplate2 = _interopRequireDefault(_chartTemplate); var _propsUtil = require('../_util/props-util'); var _lodash = require('lodash'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } exports['default'] = { name: 'IepBarChart', props: (0, _propsUtil.mergeProps)({ data: _vueTypes2['default'].array.def(function () { return []; }), axis: _vueTypes2['default'].array.def(function () { return []; }), unit: _vueTypes2['default'].array.def(function () { return []; }), theme: _vueTypes2['default'].oneOf(['dark', 'light']).def('dark'), mixinOptions: _vueTypes2['default'].object.def(function () {}) }, _chartTemplate2['default'].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 _this = this; var _$props2 = this.$props, theme = _$props2.theme, mixinOptions = _$props2.mixinOptions; var emptyAxis = ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23: 00', '24:00']; var emptyData = [emptyAxis.map(function () { return 0; }), emptyAxis.map(function () { return 0; })]; var tooltip = (0, _lodash.isEmpty)(e.data) ? {} : { trigger: 'axis', axisPointer: { type: 'shadow' }, className: 'iep-chart-tooltip-' + theme }; var color = e.data.some(function (item) { return item.color !== undefined; }) ? e.data.map(function (item, index) { return item.color && item.color.colorStops ? item.color.colorStops[0].color : item.color ? item.color : _this.themeColor[index]; }) : this.themeColor.map(function (item, index) { return _this.themeColor[index]; }); var yAxisData = (0, _lodash.isEmpty)(e.data) ? { type: 'value', min: (0, _lodash.isEmpty)(e.data) && 400, splitLine: { lineStyle: { color: 'rgba(153, 153, 153, 0.2)' } } } : { type: 'value', splitLine: { lineStyle: { color: 'rgba(153, 153, 153, 0.2)' } } }; this.chartOptions = (0, _extends3['default'])({}, (0, _lodash.omit)(this.$props, ['data', 'axis', 'mixinOptions', 'theme']), { theme: theme, loading: e.loading, options: (0, _extends3['default'])({ tooltip: tooltip, color: color, legend: { data: (0, _lodash.isEmpty)(e.data) ? ['--'] : e.data.map(function (item) { return item.name; }), itemHeight: 14, itemWidth: 14, selectedMode: (0, _lodash.isEmpty)(e.data) ? false : true, itemStyle: { color: (0, _lodash.isEmpty)(e.data) ? '#e5e5e5' : 'inherit' }, textStyle: { color: (0, _lodash.isEmpty)(e.data) ? '#e5e5e5' : theme === 'light' ? '#000' : '#fff' } }, grid: [{ top: '16%', bottom: '6%', left: '6%', right: '6%', containLabel: true }], axisPointer: { link: { xAxisIndex: 'all' }, label: { backgroundColor: '#777' }, shadowStyle: { color: 'rgba(49,139,255,0.2)' } }, xAxis: { type: 'category', data: (0, _lodash.isEmpty)(e.data) ? emptyAxis : e.axis, axisTick: { show: false } }, yAxis: yAxisData, series: (0, _lodash.isEmpty)(e.data) ? [{ type: 'bar', name: '--', data: emptyData[0] }] : e.data.map(function (item, index) { return { type: 'bar', name: item.name, barCategoryGap: '60%', data: item.value.map(function (citem) { return { value: citem, itemStyle: (0, _extends3['default'])({ color: _this.themeColor[index] }, item) }; }) }; }) }, mixinOptions) }); }, immediate: true, deep: true } }, render: function render() { var h = arguments[0]; var chartOptions = this.chartOptions; if (!(0, _lodash.isEmpty)(chartOptions)) { return h(_chartTemplate2['default'], { props: (0, _extends3['default'])({}, chartOptions) }); } else { return h(_chartTemplate2['default']); } } };