iep-ui
Version:
An enterprise-class UI design language and Vue-based implementation
206 lines (188 loc) • 6.66 kB
JavaScript
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: 'IepSquareBar',
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 () {}),
secontAxisName: _vueTypes2['default'].string
}, _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,
unit = _$props.unit;
return {
data: data,
axis: axis,
loading: loading,
theme: theme,
unit: unit
};
}
},
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 (item) {
return 0;
}), emptyAxis.map(function (item) {
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)'
}
}
} : e.data.filter(function (item, index) {
return index < 2;
}).map(function (item, index) {
return {
type: 'value',
name: index < 2 && e.unit && e.unit[index],
nameTextStyle: {
color: item.color ? item.color.colorStops ? item.color.colorStops[0].color : item.color : _this.themeColor[index]
},
axisLabel: {
show: index < 2 ? true : false,
color: item.color ? item.color.colorStops ? item.color.colorStops[0].color : item.color : _this.themeColor[index]
},
splitLine: {
lineStyle: {
color: 'rgba(153, 153, 153, 0.2)'
}
}
};
});
this.chartOptions = (0, _extends3['default'])({}, (0, _lodash.omit)(this.$props, ['data', 'axis', 'unit', '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%',
yAxisIndex: _this.secontAxisName === item.name ? 1 : 0,
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']);
}
}
};
;