zhu-jiang-yi-yuan-bigscreen
Version:
南方医科大学珠江医院大屏端
148 lines (115 loc) • 5.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getAxis = exports.getFontSize = exports.getLineDash = exports.getPadding = exports.getLabelProps = exports.getTooltipTpl = void 0;
var _utils = require("../../utils");
var _nsnConst = require("nsn-const");
var _nsnUtil = require("nsn-util");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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; }
var getTooltipTpl = function getTooltipTpl(props) {
var title = props.title,
data = props.data,
_props$alias = props.alias,
alias = _props$alias === void 0 ? _nsnConst.NConst.EMPTY : _props$alias,
_props$suffix = props.suffix,
suffix = _props$suffix === void 0 ? _nsnConst.NConst.EMPTY : _props$suffix,
color = props.color;
var lis = data.map(function (item) {
var vtext = _nsnUtil.NNum.translate(item.value);
return "<li class=\"g2-tooltip-list-item\">\n <span class=\"g2-tooltip-marker\" style=\"background-color:".concat(color || (item === null || item === void 0 ? void 0 : item.color), "\"></span>\n <span class=\"g2-tooltip-name\">").concat(item === null || item === void 0 ? void 0 : item.name, "</span>:<span class=\"g2-tooltip-value\">").concat(vtext).concat(suffix, "</span>\n </li>");
});
return "<div class=\"g2-tooltip\">\n <div class=\"g2-tooltip-title\">".concat(title).concat(alias, "</div>\n <ul class=\"g2-tooltip-list\">\n ").concat(lis.join(''), "\n </ul>\n </div>");
};
exports.getTooltipTpl = getTooltipTpl;
var getLabelProps = function getLabelProps(calcRefresh, yName, showLabel, compareWidth, extra) {
// 小于 1024 不显示label
var docWidth = 0;
if (calcRefresh && typeof calcRefresh === 'number') {
docWidth = calcRefresh;
} else {
docWidth = calcRefresh === null || calcRefresh === void 0 ? void 0 : calcRefresh[0];
}
var labelProps = {}; // ?? 在大屏端,这个判断不生效
// if ((docWidth || 0) > (compareWidth || PxUtil.SMALL_WIDTH) && yName) {
// }
if (yName && showLabel) {
if (_nsnUtil.NType.isArray(extra)) {
labelProps.label = extra;
} else {
labelProps.label = [yName, _objectSpread(_objectSpread({}, extra || {}), {}, {
style: {
fontSize: getFontSize(docWidth),
fill: 'white'
}
})];
}
}
return labelProps;
};
exports.getLabelProps = getLabelProps;
var getPadding = function getPadding(top, right, bottom, left) {
//
var topNum = _utils.PxUtil.getCalcNumH(top);
var bottomNum = _utils.PxUtil.getCalcNumH(bottom || top); //
var rightNum = _utils.PxUtil.getCalcNumW(right || top);
var leftNum = _utils.PxUtil.getCalcNumW(left || right || top);
return [topNum, rightNum, bottomNum, leftNum];
};
exports.getPadding = getPadding;
var getLineDash = function getLineDash(docWidth) {
return [_utils.PxUtil.getCalcNumW(5, docWidth), _utils.PxUtil.getCalcNumW(10, docWidth)];
};
exports.getLineDash = getLineDash;
var getFontSize = function getFontSize(docWidth) {
return _utils.PxUtil.getCalcNumW(12, docWidth);
}; // 坐标轴
// https://www.yuque.com/antv/g2-docs/tutorial-axes
exports.getFontSize = getFontSize;
var getAxis = function getAxis(props) {
var name = props.name,
grid = props.grid,
verticalFactor = props.verticalFactor,
_props$lineWidth = props.lineWidth,
lineWidth = _props$lineWidth === void 0 ? 1 : _props$lineWidth,
docWidth = props.docWidth,
showTitle = props.showTitle;
var titleProps = {};
if (showTitle) {
titleProps.title = {
style: {
fontSize: getFontSize(docWidth),
fontWeight: 'bold',
fill: 'white'
}
};
}
var axisProps = _objectSpread({
name: name,
grid: grid,
verticalFactor: verticalFactor,
line: {
style: {
lineDash: getLineDash(docWidth),
stroke: _utils.Const.AXIS_COLOR,
lineWidth: lineWidth
}
},
tickLine: {
style: {
stroke: _utils.Const.AXIS_COLOR
}
},
label: {
style: {
fontSize: getFontSize(docWidth),
fontWeight: 'bold',
fill: 'white'
}
}
}, titleProps);
return axisProps;
};
exports.getAxis = getAxis;