@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
146 lines (145 loc) • 7.75 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 __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);
};
import * as React from 'react';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import { min, toNumber, get } from 'lodash';
import { computed, observable, action } from 'mobx';
import bind from '../../../../../utils/bind';
import { ESingleFieldPosition } from '../../../../../constants/chart-style';
import BasicComponent from '../../../../Base/BasicComponent';
import ScaleContent from '../../../../Base/ScaleContent';
import errorBoundary from '../../../../../hocs/errorBoundary';
import { formatString } from '../../../../../services/language';
import { BaseLocale } from '../../../../../constants/language/base/type';
import DisplayField from '../../DisplayField';
import ValueContent from '../ValueContent';
import TrendView from '../TrendView';
import * as styles from './style.mless';
var Singlet = /** @class */ (function (_super) {
__extends(Singlet, _super);
function Singlet() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.store = _this.props.store;
_this.scale = { scaleX: 1, scaleY: 1 };
return _this;
}
Object.defineProperty(Singlet.prototype, "displayData", {
get: function () {
var _a = this.store.chartStyleService, unitTransformer = _a.unitTransformer, gaugeEmptyValueMode = _a.gaugeEmptyValueMode;
var currentData = toNumber(this.store.currentData);
if (!isNaN(currentData)) {
return "" + unitTransformer(currentData);
}
if (!this.store.hasData) {
return gaugeEmptyValueMode === "0" /* Zero */
? "" + unitTransformer(0)
: formatString(BaseLocale.status.empty);
}
return this.store.currentData;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Singlet.prototype, "width", {
// 没有展示字段,只有趋势图的时候,希望趋势图可以展示万战
get: function () {
return this.store.displayField.fields.length === 0 && this.store.showTrend
? '100%'
: undefined;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Singlet.prototype, "style", {
get: function () {
var canClick = this.store.chartCanClick;
return {
cursor: canClick ? 'pointer' : 'default',
transform: "translate(-50%, -50%) scale(" + min([
this.scale.scaleX,
this.scale.scaleY
]) + ")",
width: this.width
};
},
enumerable: false,
configurable: true
});
Singlet.prototype.setScale = function (scale) {
this.scale = scale;
};
Singlet.prototype.render = function () {
var _a;
var _b = this.store, chartColors = _b.chartColors, displayField = _b.displayField, chartWidth = _b.chartWidth, chartHeight = _b.chartHeight, _c = _b.chartStyleOption, titleDataFont = _c.titleDataFont, suffix = _c.suffix, prefix = _c.prefix, chartType = _c.chartType, _d = _b.themeOption.gauge.singleValue, titleStyle = _d.titleStyle, prefixStyle = _d.prefixStyle, suffixStyle = _d.suffixStyle;
var fields = displayField.fields, position = displayField.position;
var defaulTitleStyle = get(titleDataFont, 'fontSize')
? titleDataFont
: titleStyle;
return (React.createElement("div", { className: classnames(styles.singleChartCurrent, (_a = {},
_a[styles.rightContainer] = fields.length > 0 && position === ESingleFieldPosition.Right,
_a)), style: this.style, onClick: this.store.handleDrillDown },
position === ESingleFieldPosition.Right && (React.createElement(ScaleContent, { containerWidth: this.store.chartWidth, containerHeight: this.store.chartHeight, onScale: this.setScale },
React.createElement("div", { className: styles.wrapper },
React.createElement(ValueContent, { chartColor: chartColors, displayData: this.displayData, suffix: suffix, prefix: prefix, prefixStyle: prefixStyle, suffixStyle: suffixStyle, defaulTitleStyle: defaulTitleStyle, trendView: React.createElement(TrendView, { store: this.store }), minWidth: this.width }),
React.createElement("div", { className: styles.singleDispleField },
React.createElement(DisplayField, { displayFiled: displayField, chartWidth: chartWidth, chartHeight: chartHeight, chartType: chartType }))))),
position === ESingleFieldPosition.Bottom && (React.createElement(React.Fragment, null,
React.createElement(ScaleContent, { containerWidth: this.store.chartWidth, containerHeight: this.store.chartHeight, onScale: this.setScale },
React.createElement(ValueContent, { chartColor: chartColors, displayData: this.displayData, suffix: suffix, prefix: prefix, prefixStyle: prefixStyle, suffixStyle: suffixStyle, defaulTitleStyle: defaulTitleStyle }),
React.createElement(DisplayField, { displayFiled: displayField, chartWidth: chartWidth, chartHeight: chartHeight, chartType: chartType }),
React.createElement(TrendView, { store: this.store }))))));
};
__decorate([
observable.ref,
__metadata("design:type", Object)
], Singlet.prototype, "scale", void 0);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Singlet.prototype, "displayData", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Singlet.prototype, "width", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Singlet.prototype, "style", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], Singlet.prototype, "setScale", null);
Singlet = __decorate([
observer
], Singlet);
return Singlet;
}(BasicComponent));
export { Singlet };
export default errorBoundary(Singlet);