UNPKG

@cainiaofe/cn-ui-charts

Version:
185 lines 5.57 kB
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; var _excluded = ["autoFit", "data", "children"]; import { FeaturePosition } from "../../types/feature-position"; import { getJSExpressionPrototype, getFirstOptions, isArrayNotEmpty } from "../util/util"; import { getMixedSetterSnippet } from "../setter/statistic-setter"; import set from 'lodash/set'; export var componentLoopMap = {}; var summary = { title: '中心结果汇总', value: 'summary', position: [FeaturePosition.pie], getDefaultProps: function getDefaultProps() { return { title: '共计' }; }, getPrototypeList: function getPrototypeList(position, config) { return [{ title: '汇总标题', name: 'title', setter: 'CnI18nSetter' }]; }, handleFeature: function handleFeature(config) { var _ref = config || {}, featureItemConfig = _ref.featureItemConfig, props = _ref.props, options = _ref.options, position = _ref.position; var _ref2 = featureItemConfig || {}, itemOptions = _ref2.options; var statics = [{ type: "text", style: { text: (itemOptions === null || itemOptions === void 0 ? void 0 : itemOptions.title) || '共计', x: "50%", y: "50%", dy: -10, fontSize: 20, textAlign: "center", textBaseline: "middle", fontWeight: "bold" } }, { type: "text", data: { transform: [{ type: "custom", callback: function callback(d) { var sum = d.reduce(function (r, curr) { var _options$encode; var key = (options === null || options === void 0 ? void 0 : (_options$encode = options.encode) === null || _options$encode === void 0 ? void 0 : _options$encode.y) || 'value'; r += curr[key]; return r; }, 0); return [sum]; } }] }, encode: { text: function text(d) { return d; } }, style: { x: "50%", y: "50%", fontSize: 16, dy: 10, textAlign: "center", textBaseline: "top", fontWeight: "bold" } }]; var _ref3 = options || {}, autoFit = _ref3.autoFit, data = _ref3.data, children = _ref3.children, rest = _objectWithoutPropertiesLoose(_ref3, _excluded); var result = {}; if (autoFit) { result.autoFit = autoFit; } if (data) { result.data = data; } if (isArrayNotEmpty(children)) { result.children = [].concat(children, statics); } else { result.children = [rest].concat(statics); } return result; } }; var loop = { title: '图表轮询', value: 'loop', position: [FeaturePosition.pie, FeaturePosition.line, FeaturePosition.column, FeaturePosition.statisticCard], getDefaultProps: function getDefaultProps() { return {}; }, getPrototypeList: function getPrototypeList(position, config) { return [{ name: 'interval', title: '轮询间隔时间(单位秒)', display: 'inline', setter: 'NumberSetter' }, { name: 'needLoading', title: '展示loading效果', display: 'inline', defaultValue: false, setter: 'BoolSetter' }]; }, handleFeature: function handleFeature(config) { var _ref4 = config || {}, featureItemConfig = _ref4.featureItemConfig, props = _ref4.props, sendRequest = _ref4.sendRequest; var _ref5 = props || {}, _nodeId = _ref5._nodeId; var _ref6 = featureItemConfig || {}, active = _ref6.active, options = _ref6.options; var _ref7 = options || {}, interval = _ref7.interval, needLoading = _ref7.needLoading; if (active && _nodeId && typeof interval === 'number' && interval >= 2 && componentLoopMap[_nodeId] === undefined) { componentLoopMap[_nodeId] = setInterval(function () { sendRequest === null || sendRequest === void 0 ? void 0 : sendRequest({ needLoading: needLoading }); }, interval * 1000); } } }; var labelFilter = { title: 'x轴标签过滤', value: 'labelFilter', position: [FeaturePosition.line, FeaturePosition.column], getDefaultProps: function getDefaultProps() { return {}; }, getPrototypeList: function getPrototypeList(position, config) { return [{ title: '开启过滤(x轴过密时开启)', name: 'labelFilter', setter: getMixedSetterSnippet({ setters: [{ componentName: 'BoolSetter', title: '是/否' }, getJSExpressionPrototype({ type: 'base' })] }) }]; }, handleFeature: function handleFeature(config) { var _ref8 = config || {}, featureItemConfig = _ref8.featureItemConfig, props = _ref8.props, options = _ref8.options, position = _ref8.position; var _ref9 = featureItemConfig || {}, itemOptions = _ref9.options; var _ref10 = itemOptions || {}, labelFilter = _ref10.labelFilter; if (labelFilter === true) { var firstOptions = getFirstOptions(options); if (firstOptions) { set(firstOptions, 'axis.x.labelFilter', function (item, index, data) { var dl = data === null || data === void 0 ? void 0 : data.length; return index % Math.ceil(dl / 10) === 0; }); } } return options; } }; export var componentMap = { summary: summary, loop: loop, labelFilter: labelFilter };