UNPKG

775 BPlain TextView Raw
1import React from 'react';
2import _isString from '@antv/util/lib/is-string';
3import _isBoolean from '@antv/util/lib/is-boolean';
4import _isObject from '@antv/util/lib/is-object';
5
6// plot visible 写法的快速转换
7export const visibleHelper = (cfg, defaultVisible: boolean = true) => {
8 if (_isString(cfg) || React.isValidElement(cfg)) {
9 return {
10 visible: true,
11 text: cfg,
12 };
13 }
14 if (_isBoolean(cfg)) {
15 return {
16 visible: cfg,
17 };
18 }
19 if (_isObject(cfg)) {
20 return {
21 visible: true,
22 ...cfg,
23 };
24 }
25 return {
26 visible: defaultVisible,
27 };
28};
29
30export const visibleHelperInvert = cfg => {
31 // @ts-ignore
32 if (_isObject(cfg) && cfg.visible !== false) {
33 // @ts-ignore
34 return cfg.text;
35 }
36 return cfg;
37};