@alicloud/cloud-charts
Version:

74 lines (63 loc) • 2.15 kB
JavaScript
;
import _extends from "@babel/runtime/helpers/extends";
import { merge, customFormatter } from './common';
/**
* rectYAxis 直角坐标系的单个Y轴配置
*
* @param {this} ctx 组件实例 this 指针
* @param {Chart} chart 图表实例
* @param {Object} config 配置项
* @param {string} yField 数据映射字段
* @param {Object} defaultConfig 组件的自定义配置
* */
export default function (ctx, chart, config, yField, defaultConfig) {
if (yField === void 0) {
yField = 'y';
}
if (config.yAxis === false || config.yAxis && config.yAxis.visible === false) {
chart.axis(yField, false);
} else {
var _ref = config.yAxis || {},
alias = _ref.alias,
_ref$autoRotate = _ref.autoRotate,
autoRotate = _ref$autoRotate === void 0 ? false : _ref$autoRotate,
rotate = _ref.rotate,
autoHide = _ref.autoHide,
autoEllipsis = _ref.autoEllipsis,
label = _ref.label,
labelFormatter = _ref.labelFormatter,
customConfig = _ref.customConfig;
var yConfig = _extends({}, defaultConfig, {
title: null,
// 不展示坐标轴的标题
label: label === undefined ? {
autoRotate: autoRotate,
rotate: rotate,
autoHide: autoHide,
autoEllipsis: autoEllipsis,
formatter: labelFormatter || customFormatter(config.yAxis || {})
} : label
}); // // 关闭了X轴,需要显示第一条grid
// if (config.xAxis === false || (config.xAxis && config.xAxis.visible === false)) {
// yConfig.grid = {
// hideFirstLine: false,
// };
// }
// 开启坐标轴标题
if (alias) {
yConfig.title = {};
if (yField === 'y1') {
// @ts-ignore G2 文档中没有出现的属性,传入角度值,手动设置转动角度
yConfig.title.rotate = Math.PI / 2;
} // yConfig.label.textStyle = {
// rotate: 0,
// };
} // if (componentConfig) {
// Object.assign(yConfig, componentConfig);
// }
if (customConfig) {
merge(yConfig, customConfig);
}
chart.axis(yField, yConfig);
}
}