UNPKG

ze-react-component-library

Version:
188 lines (173 loc) 5.08 kB
import "antd/es/tooltip/style"; import _Tooltip from "antd/es/tooltip"; var __assign = this && this.__assign || function () { __assign = Object.assign || function (t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } } return t; }; return __assign.apply(this, arguments); }; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; } if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { memo } from "react"; import { SizeMe } from "react-sizeme"; import { QuestionCircleOutlined } from "@ant-design/icons"; // @ts-ignore import GuageSvg from "./guage.svg"; import Chart from "../../../components/Chart"; var GuageChart = /*#__PURE__*/memo(function (props) { var data = props.result, userOption = props.option, eventsDict = props.eventsDict, style = props.style, isMobile = props.isMobile, restProps = __rest(props, ["result", "option", "eventsDict", "style", "isMobile"]); var columnProperties = ((data === null || data === void 0 ? void 0 : data.columnProperties) || []).filter(function (p) { return p.type === "percentage"; }); var getChartOption = function getChartOption(d) { return { legend: { show: false }, tooltip: { show: false }, series: { color: "#1890ff", name: d.name, min: -2, max: 2, type: "gauge", radius: "80%", progress: { show: true, width: 18 }, axisLine: { lineStyle: { width: 18 } }, axisTick: { show: false }, splitLine: { length: 10, lineStyle: { width: 2, color: "#999" } }, axisLabel: { formatter: function formatter(v) { return "" + v * 100; }, distance: 25, color: "#999" }, anchor: { show: true, showAbove: true, size: 25, itemStyle: { borderColor: "#1890ff", borderWidth: 10 } }, title: { show: false }, detail: { show: false } } }; }; return /*#__PURE__*/React.createElement("div", { style: { display: "flex", height: "100%" } }, columnProperties.map(function (d) { return /*#__PURE__*/React.createElement(SizeMe, { monitorHeight: true, key: d.name }, function (_a) { var _b, _c; var _d = _a.size, width = _d.width, height = _d.height; return /*#__PURE__*/React.createElement("div", { style: { width: 1 / columnProperties.length * 100 + "%", position: "relative" } }, /*#__PURE__*/React.createElement(Chart, __assign({}, restProps, { result: data, chartOption: getChartOption(d), userOption: userOption, eventsDict: eventsDict, style: style, isMobile: isMobile })), /*#__PURE__*/React.createElement("div", { style: { position: "absolute", left: "50%", top: height && width ? height > width ? height * 0.5 + width * 0.3 : height * 0.5 + height * 0.3 : "80%", transform: "translateX(-50%)", textAlign: "center" } }, /*#__PURE__*/React.createElement("div", { style: { fontSize: 24, fontWeight: "bolder", whiteSpace: "nowrap" } }, (((_c = (_b = data.result) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c[d.name]) * 100).toFixed(2), " %"), /*#__PURE__*/React.createElement("div", { style: { fontSize: 16 } }, d.name, d.description && /*#__PURE__*/React.createElement(_Tooltip, { title: d.description }, /*#__PURE__*/React.createElement(QuestionCircleOutlined, { style: { marginLeft: 4 } }))))); }); })); }); var Guage = { key: "guage", title: "仪表盘", icon: GuageSvg, tip: "搜索结果需为数值列且展示类型为百分比", type: "basic", component: function component(props) { return /*#__PURE__*/React.createElement(GuageChart, __assign({}, props)); }, valid: function valid(result) { if (!result) return false; var columnProperties = result.columnProperties; if ((columnProperties || []).every(function (p) { return p.type === "percentage"; })) { return true; } return false; } }; export default Guage;