zhu-jiang-yi-yuan-bigscreen
Version:
南方医科大学珠江医院大屏端
94 lines (80 loc) • 4.42 kB
JavaScript
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { Const, PxUtil } from '../../utils';
import { Axis, Chart, Legend, LineAdvance, Tooltip } from 'bizcharts';
import { NPix } from 'nsn-util';
import React, { useEffect, useState } from 'react';
import { getAxis, getLabelProps, getLineDash, getPadding } from './_util'; // 渐变色
// https://antv-g2.gitee.io/en/docs/api/shape/shape-attrs#%E6%B8%90%E5%8F%98%E8%89%B2
// https://bizcharts.net/product/BizCharts4/category/62/page/193
var LineChart = function LineChart(props) {
var color = props.color,
data = props.data,
axis = props.axis,
height = props.height,
calcRefresh = props.calcRefresh,
customContent = props.customContent,
label = props.label,
padding = props.padding;
var xName = axis.xName,
yName = axis.yName,
yAlias = axis.yAlias;
var docWidth = calcRefresh === null || calcRefresh === void 0 ? void 0 : calcRefresh[0];
var _useState = useState({}),
_useState2 = _slicedToArray(_useState, 2),
labelProps = _useState2[0],
setLabelProps = _useState2[1];
useEffect(function () {
return setLabelProps(getLabelProps(docWidth, yName, false, PxUtil.SMALL_WIDTH, label));
}, [docWidth]);
var scale = _defineProperty({}, yName, {
min: 0,
alias: yAlias || yName
});
var topColor = NPix.getHex("rgba(".concat(color, ",100%)"));
var midColor = NPix.getHex("rgba(".concat(color, ",70%)"));
var bottomColor = NPix.getHex("rgba(".concat(color, ",30%)")); // https://antv-g2.gitee.io/zh/docs/api/general/chart#chartcfgrenderer
return /*#__PURE__*/React.createElement(Chart, Object.assign({}, {
data: data,
scale: scale,
height: height
}, {
padding: padding || getPadding(20, 20, 80, 50),
autoFit: true,
renderer: "svg"
}), /*#__PURE__*/React.createElement(Axis, Object.assign({}, getAxis({
name: xName,
docWidth: docWidth
}))), /*#__PURE__*/React.createElement(Axis, Object.assign({}, getAxis({
name: yName,
docWidth: docWidth,
showTitle: true,
grid: {
line: {
style: {
stroke: Const.AXIS_COLOR,
lineDash: getLineDash(docWidth)
}
}
}
}))), /*#__PURE__*/React.createElement(Legend, {
visible: false
}), /*#__PURE__*/React.createElement(Tooltip, Object.assign({
shared: true,
showCrosshairs: true
}, {
customContent: customContent
})), /*#__PURE__*/React.createElement(LineAdvance, Object.assign({}, labelProps, {
position: "".concat(xName, "*").concat(yName),
point: true,
area: true,
shape: "smooth",
color: "l(90) 0:".concat(topColor, " .5:").concat(midColor, " 1:").concat(bottomColor)
})));
};
export { LineChart };