@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
179 lines (178 loc) • 8.31 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);
};
import React from 'react';
import { observer } from 'mobx-react';
import { includes } from 'lodash';
import { computed } from 'mobx';
import { Selector } from '@qn-pandora/pandora-component';
import bind from '../../../utils/bind';
import MetricItem from '../MetricItem';
import NameItem from '../NameItem';
import AxisTypePanel, { IAxisTypePanelProperty } from '../AxisTypePanel';
import { Form } from '../../../components/Common';
import errorBoundary from '../../../hocs/errorBoundary';
import { BaseLocale } from '../../../constants/language/base/type';
import { formatString } from '../../../services/language';
import { AxisTypeOptions, ValueAxisTypeOptions } from '../../../constants/chart-style';
import { yEmptyValueModes, lineYEmptyValueModes } from '../../ChartStyleConfig/constants';
import { scatterCharts, barCharts } from './constant';
var Item = Form.Item;
export var formItemLayout = {
labelCol: { span: 8 },
wrapperCol: { span: 16 }
};
var YPanelContent = /** @class */ (function (_super) {
__extends(YPanelContent, _super);
function YPanelContent() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(YPanelContent.prototype, "scaleOptions", {
get: function () {
var chartType = this.props.chartType;
if (chartType && includes(scatterCharts, chartType)) {
return AxisTypeOptions;
}
return ValueAxisTypeOptions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(YPanelContent.prototype, "axisProperty", {
get: function () {
var _a;
var chartType = this.props.chartType;
if (chartType && includes(barCharts, chartType)) {
return _a = {}, _a[IAxisTypePanelProperty.ValueMode] = false, _a;
}
return undefined;
},
enumerable: false,
configurable: true
});
Object.defineProperty(YPanelContent.prototype, "isMultipleMode", {
get: function () {
var isMulChoices = this.props.isMulChoices;
return isMulChoices !== null && isMulChoices !== void 0 ? isMulChoices : true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(YPanelContent.prototype, "yEmptyValueModes", {
get: function () {
return this.props.showLineYEmptyValueMode
? lineYEmptyValueModes
: yEmptyValueModes;
},
enumerable: false,
configurable: true
});
Object.defineProperty(YPanelContent.prototype, "metricOptions", {
get: function () {
var _a = this.props, _b = _a.disabledShowFields, disabledShowFields = _b === void 0 ? [] : _b, fields = _a.dataset.fields;
var result = [];
fields.forEach(function (f) {
if (!includes(disabledShowFields, f.key)) {
result.push(f.key);
}
});
return result;
},
enumerable: false,
configurable: true
});
YPanelContent.prototype.handleOnChange = function (value) {
var setFields = this.props.crossAxis.setFields;
setFields(value);
};
YPanelContent.prototype.handleCrossAxisNameChange = function (e) {
var setName = this.props.crossAxis.setName;
if (setName) {
setName(e.target.value);
}
};
YPanelContent.prototype.render = function () {
var _a = this.props, crossAxis = _a.crossAxis, showProperty = _a.showProperty;
var fields = crossAxis.fields, name = crossAxis.name, nameMode = crossAxis.nameMode, setNameMode = crossAxis.setNameMode, displayFields = crossAxis.displayFields, setDisplayFields = crossAxis.setDisplayFields;
return (React.createElement("div", null,
React.createElement(MetricItem, { label: this.props.metricLabel || BaseLocale.field, onChange: this.handleOnChange, metricOptions: this.metricOptions, metrics: fields, isMultipleMode: this.isMultipleMode, allowClear: true, placeholder: "" + formatString(BaseLocale.select) + (formatString(this.props.metricLabel) ||
formatString(BaseLocale.field)), formItemCol: formItemLayout }),
React.createElement(NameItem, __assign({ label: BaseLocale.name, name: name, nameMode: nameMode, setNameMode: setNameMode, handleNameChange: this.handleCrossAxisNameChange }, formItemLayout)),
React.createElement(AxisTypePanel, __assign({ axis: crossAxis, axisOptions: this.scaleOptions, showProperty: showProperty, yEmptyValueModes: this.yEmptyValueModes }, formItemLayout)),
React.createElement(Item, __assign({ label: formatString(BaseLocale.y.display_fields) }, formItemLayout),
React.createElement(Selector, { value: displayFields, mode: "multiple", onChange: setDisplayFields, options: this.metricOptions, allowClear: true, showSearch: true }))));
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], YPanelContent.prototype, "scaleOptions", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], YPanelContent.prototype, "axisProperty", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], YPanelContent.prototype, "isMultipleMode", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], YPanelContent.prototype, "yEmptyValueModes", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], YPanelContent.prototype, "metricOptions", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], YPanelContent.prototype, "handleOnChange", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], YPanelContent.prototype, "handleCrossAxisNameChange", null);
YPanelContent = __decorate([
observer
], YPanelContent);
return YPanelContent;
}(React.Component));
export { YPanelContent };
export default errorBoundary(YPanelContent);