ze-react-component-library
Version:
ZeroETP React Component Library
120 lines (105 loc) • 3.85 kB
JavaScript
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, useRef } from "react"; // @ts-ignore
import ScatterSvg from "./scatter.svg";
import { getNameProperty } from "zeroetp-api-sdk";
import Chart, { tooltipFormatter } from "../../../components/Chart";
import { getChartProperties, yAxisOptionForProperty } from "../../../components/Chart/util";
import { formatResultName } from "../../../util";
var ScatterChart = /*#__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 nameRef = useRef({});
var _a = getChartProperties(data),
dimensionProps = _a.dimensionProps,
measurementProps = _a.measurementProps;
var columnProperties = measurementProps.slice(0, 2);
var dimensionProp = dimensionProps[0];
var nameProp = (dimensionProp === null || dimensionProp === void 0 ? void 0 : dimensionProp.schema) ? getNameProperty(dimensionProp.schema) : undefined;
var col0 = columnProperties[0],
col1 = columnProperties[1];
var newResult = formatResultName(data); // 去掉不必要的参数
var mappedData = __assign(__assign({}, data), {
result: newResult === null || newResult === void 0 ? void 0 : newResult.map(function (i, index) {
var _a;
if (dimensionProp && nameProp) {
nameRef.current[index] = i[dimensionProp.name];
}
return _a = {}, _a[col0.name] = i[col0.name], _a[col1.name] = i[col1.name], _a;
}),
columnProperties: columnProperties
});
var chartOption = {
legend: {
show: false
},
tooltip: {
trigger: "item",
formatter: function formatter(params) {
return tooltipFormatter({
params: params,
properties: columnProperties,
defaultName: nameRef.current[params === null || params === void 0 ? void 0 : params.dataIndex]
});
}
},
// @ts-ignore
xAxis: __assign({
name: col0 === null || col0 === void 0 ? void 0 : col0.name
}, yAxisOptionForProperty(col0, mappedData)),
yAxis: __assign({
name: col1 === null || col1 === void 0 ? void 0 : col1.name
}, yAxisOptionForProperty(col1, mappedData)),
series: [{
type: "scatter",
symbolSize: 10
}]
};
return /*#__PURE__*/React.createElement(Chart, __assign({}, restProps, {
result: mappedData,
chartOption: chartOption,
userOption: userOption,
eventsDict: eventsDict,
style: style,
isMobile: isMobile
}));
});
var Scatter = {
key: "scatter",
title: "散点图",
icon: ScatterSvg,
tip: "搜索结果要有两个数值列",
type: "basic",
component: function component(props) {
return /*#__PURE__*/React.createElement(ScatterChart, __assign({}, props));
},
valid: function valid(result) {
var measurementProps = getChartProperties(result).measurementProps;
return measurementProps.length >= 2;
}
};
export default Scatter;