UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

120 lines (119 loc) 7 kB
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); }; import React from 'react'; import { action } from 'mobx'; import { Row, Col, Input, InputNumber } from 'antd'; import { isNull, toNumber, isEmpty, toString } from 'lodash'; import { ColorPicker } from '@qn-pandora/pandora-app-component'; import { AutoComplete } from '@qn-pandora/pandora-component'; import { Selector } from '../../../../components/Common'; import bind from '../../../../utils/bind'; import { ChartType, EBaseLineType } from '../../../../constants/chart-style'; import errorBoundary from '../../../../hocs/errorBoundary'; import { formatString } from '../../../../services/language'; import { BaseLocale } from '../../../../constants/language/base/type'; import DeleteIcon from '../../DeleteIcon'; import LineTypePicker from './LineTypePicker'; import { LineBarModes, ModeCharts, ScatterModes } from '../constants'; import * as style from './style.mless'; var BaseLine = /** @class */ (function (_super) { __extends(BaseLine, _super); function BaseLine() { return _super !== null && _super.apply(this, arguments) || this; } BaseLine.prototype.handleChange = function (prop, newValue) { var _a; var _b = this.props, value = _b.value, source = _b.source, onChange = _b.onChange; onChange(__assign(__assign({}, value), (_a = {}, _a[prop] = newValue, _a)), source); }; BaseLine.prototype.handleValueChange = function (e) { if (!isEmpty(e) && !this.props.fields.find(function (field) { return (field === null || field === void 0 ? void 0 : field.value) === e; }) && !isNaN(toNumber(e))) { this.props.onChange(__assign(__assign({}, this.props.value), { value: toNumber(e), type: EBaseLineType.NUMBER }), this.props.source); } else { this.props.onChange(__assign(__assign({}, this.props.value), { value: e, type: EBaseLineType.DYNAMIC }), this.props.source); } }; BaseLine.prototype.handleDelete = function () { var _a = this.props, source = _a.source, onDelete = _a.onDelete; onDelete(source); }; BaseLine.prototype.render = function () { var _this = this; var _a = this.props.value, lineType = _a.lineType, name = _a.name, color = _a.color, value = _a.value, mode = _a.mode; var chartType = this.props.chartType; var showMode = ModeCharts.includes(chartType); return (React.createElement("div", { className: style.lineItem }, React.createElement(Row, { gutter: 4 }, React.createElement(Col, { span: showMode ? 6 : 10 }, React.createElement(Input, { className: style.nameInput, placeholder: formatString(BaseLocale.base_line_name_placeholder), value: name, onChange: function (e) { return _this.handleChange('name', e.target.value); }, addonAfter: React.createElement(ColorPicker, { value: color || this.props.defaultColor[0], onChange: function (e) { return _this.handleChange('color', e); } }) })), React.createElement(Col, { span: 3 }, React.createElement(LineTypePicker, { value: lineType, color: color || this.props.defaultColor[0], onChange: function (lineType) { return _this.handleChange('lineType', lineType); }, getPopupContainer: this.props.getPopupContainer })), React.createElement(Col, { span: showMode ? 7 : 9 }, chartType === ChartType.Scatter || chartType === ChartType.Bubble ? (React.createElement(InputNumber, { value: value, onChange: function (e) { return _this.handleChange('value', isNull(e) ? 0 : e); }, placeholder: formatString(BaseLocale.base_line_number_value_placeholder) })) : (React.createElement(AutoComplete, { value: value === 0 ? toString(0) : value, showSearch: true, onChange: this.handleValueChange, dataSource: this.props.fields, getPopupContainer: this.props.getPopupContainer }))), showMode && (React.createElement(Col, { span: 6 }, React.createElement(Selector, { value: mode, onChange: function (value) { return _this.handleChange('mode', value); }, options: chartType === ChartType.LineBarY2 || chartType === ChartType.LineY2 ? LineBarModes : ScatterModes }))), React.createElement(Col, { span: 2 }, React.createElement(DeleteIcon, { onClick: this.handleDelete }))))); }; __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], BaseLine.prototype, "handleChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], BaseLine.prototype, "handleValueChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], BaseLine.prototype, "handleDelete", null); return BaseLine; }(React.Component)); export { BaseLine }; export default errorBoundary(BaseLine);