@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
160 lines (159 loc) • 7.78 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import React from 'react';
import { observer } from 'mobx-react';
import { computed } from 'mobx';
import { Collapse } from 'antd';
import { InputNumber } from '@qn-pandora/pandora-component';
import BasicComponent from '../../../../Base/BasicComponent';
import { SingleTextSettings, SolidRadioItem } from '../../../../Base';
import { BaseLocale } from '../../../../../constants/language/base/type';
import { OtherLocale } from '../../../../../constants/language/other/type';
import { Form } from '../../../../Common';
import bind from '../../../../../utils/bind';
import { switchOptions } from '../../../constants';
import * as style from './style.mless';
import { isUndefined } from 'lodash';
var Panel = Collapse.Panel;
var Item = Form.Item;
var formItemLayout = {
labelCol: { span: 6 },
wrapperCol: { span: 18 }
};
var MetricStyle = /** @class */ (function (_super) {
__extends(MetricStyle, _super);
function MetricStyle() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(MetricStyle.prototype, "defaultContentFontStyle", {
get: function () {
var themeOption = this.props.themeOption;
var itemStyle = themeOption.statusPanel.itemStyle;
return (itemStyle === null || itemStyle === void 0 ? void 0 : itemStyle.fontSize) || 0;
},
enumerable: false,
configurable: true
});
MetricStyle.prototype.getPrefixAndSuffix = function (metricStyle) {
var themeOption = this.props.themeOption;
var prefix = metricStyle.prefix, suffix = metricStyle.suffix;
var _a = themeOption.gauge.singleValue, prefixStyle = _a.prefixStyle, suffixStyle = _a.suffixStyle;
var prefixFont = __assign({}, prefix.font);
prefixFont.fontSize = prefixFont.fontSize || prefixStyle.fontSize;
prefixFont.fontColor = prefixFont.fontColor || prefixStyle.color;
var suffixFont = __assign({}, suffix.font);
suffixFont.fontSize = suffixFont.fontSize || suffixStyle.fontSize;
suffixFont.fontColor = suffixFont.fontColor || suffixStyle.color;
return {
prefix: { value: prefix.value, font: prefixFont },
suffix: { value: suffix.value, font: suffixFont }
};
};
MetricStyle.prototype.handleChange = function (key, value, index) {
var _a;
var onChange = this.props.onChange;
var styles = __spread(this.props.styles);
styles[index] = __assign(__assign({}, styles[index]), (_a = {}, _a[key] = value, _a));
onChange(styles);
};
MetricStyle.prototype.render = function () {
var _this = this;
var _a = this.props, _b = _a.styles, styles = _b === void 0 ? [] : _b, getPopupContainer = _a.getPopupContainer;
return (React.createElement("div", { className: style.root },
React.createElement(Collapse, { bordered: false }, styles.map(function (item, index) {
if (item.metric && item.metric === '') {
return null;
}
var showName = isUndefined(item.showMetricName)
? true
: item.showMetricName;
return (React.createElement(Panel, { className: style.panel, key: item.metric, header: item.metric },
React.createElement("div", null,
React.createElement(Item, __assign({ label: BaseLocale.title.font_title }, formItemLayout),
React.createElement(InputNumber, { value: item.fontSize || _this.defaultContentFontStyle, onChange: function (value) {
return _this.handleChange('fontSize', value, index);
} })),
React.createElement(SolidRadioItem, __assign({ label: OtherLocale.status.show_metric_name, options: switchOptions, value: showName, onChange: function (value) {
return _this.handleChange('showMetricName', value, index);
} }, formItemLayout)),
React.createElement(SingleTextSettings, __assign({}, _this.getPrefixAndSuffix(item), formItemLayout, { getPopupContainer: getPopupContainer, setPrefix: function (value) {
return _this.handleChange('prefix', value, index);
}, setSuffix: function (value) {
return _this.handleChange('suffix', value, index);
} })))));
}))));
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricStyle.prototype, "defaultContentFontStyle", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], MetricStyle.prototype, "getPrefixAndSuffix", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Number]),
__metadata("design:returntype", void 0)
], MetricStyle.prototype, "handleChange", null);
MetricStyle = __decorate([
observer
], MetricStyle);
return MetricStyle;
}(BasicComponent));
export default MetricStyle;