UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

161 lines (160 loc) 10.2 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 __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 { noop, get } from 'lodash'; import { Collapse } from 'antd'; import { observer } from 'mobx-react'; import { ColorPicker } from '@qn-pandora/pandora-app-component'; import { BaseLocale } from '../../../constants/language/base/type'; import { MapboxLocale } from '../../../constants/language/mapbox/type'; import { UnitLocale } from '../../../constants/language/unit/type'; import BasicComponent from '../../../components/Base/BasicComponent'; import bind from '../../../utils/bind'; import { MetricItem, NumberItem, UnitItem } from '../../../components/Base'; import { formatString } from '../../../services'; import { ChartType } from '../../../constants'; import { Form } from '../../Common'; import Selector from './Selectcor'; import MapConfig from './MapConfig'; import StyleElement from './StyleElement'; import { numberValidator, rangeValidator } from './utils'; var Panel = Collapse.Panel; var Item = Form.Item; var MapboxStyleConfigForm = /** @class */ (function (_super) { __extends(MapboxStyleConfigForm, _super); function MapboxStyleConfigForm() { return _super !== null && _super.apply(this, arguments) || this; } MapboxStyleConfigForm.prototype.moreThenOneValidator = function (value) { return Promise.all([numberValidator(value), rangeValidator(value, 1)]).then(noop); }; MapboxStyleConfigForm.prototype.minBubbleSizeValidator = function (value) { return Promise.all([ numberValidator(value), rangeValidator(value, 1), this.bubbleSizeValidator("min" /* Min */, value) ]).then(noop); }; MapboxStyleConfigForm.prototype.pointSizeValidator = function (value) { return Promise.all([numberValidator(value), rangeValidator(value, 1)]).then(noop); }; MapboxStyleConfigForm.prototype.maxBubbleSizeValidator = function (value) { return Promise.all([ numberValidator(value), rangeValidator(value, 1), this.bubbleSizeValidator("max" /* Max */, value) ]).then(noop); }; MapboxStyleConfigForm.prototype.lineSizeValidator = function (value) { return Promise.all([numberValidator(value), rangeValidator(value, 1)]).then(noop); }; MapboxStyleConfigForm.prototype.bubbleSizeValidator = function (type, value) { var _a = this.props.chartStyleService, minSize = _a.minSize, maxSize = _a.maxSize; if (type === "min" /* Min */) { return value > maxSize ? Promise.reject(BaseLocale.split.validate_splitter_4) : Promise.resolve(); } return value < minSize ? Promise.reject(BaseLocale.split.validate_splitter_2) : Promise.resolve(); }; MapboxStyleConfigForm.prototype.render = function () { var _a = this.props, dataset = _a.dataset, chartStyleService = _a.chartStyleService, themeOption = _a.themeService.themeOption; var longitudeField = chartStyleService.longitudeField, latitudeField = chartStyleService.latitudeField, currentMetrics = chartStyleService.currentMetrics, unit = chartStyleService.unit, displayFields = chartStyleService.displayFields, // 气泡 color = chartStyleService.color, setColor = chartStyleService.setColor, // 气泡 // 路径 pointColor = chartStyleService.pointColor, lineColor = chartStyleService.lineColor, setPointColor = chartStyleService.setPointColor, setLineColor = chartStyleService.setLineColor, // 路径 setLongitudeField = chartStyleService.setLongitudeField, setLatitudeField = chartStyleService.setLatitudeField, setCurrentMetrics = chartStyleService.setCurrentMetrics, setUnit = chartStyleService.setUnit, precision = chartStyleService.precision, setPrecision = chartStyleService.setPrecision, setDisplayFields = chartStyleService.setDisplayFields, chartType = chartStyleService.chartType; var mapboxOpts = get(themeOption, 'mapbox'); var bubbleStyle = get(mapboxOpts, 'bubbleStyle'); var bubbleDefaultColor = get(bubbleStyle, ['color']) || get(themeOption, ['color', 0]); var lineStyle = get(mapboxOpts, 'lineStyle'); var lineDefaultColor = get(lineStyle, ['color']) || get(themeOption, ['color', 0]); return (React.createElement(Form, { ref: this.setRootRef }, React.createElement(Collapse, { defaultActiveKey: ['1'], bordered: false, accordion: true }, React.createElement(Panel, { header: formatString(BaseLocale.title_data), key: "1" }, React.createElement(Selector, { label: formatString(MapboxLocale.longitudeField), value: longitudeField, options: dataset.fields.map(function (f) { return f.key; }), onChange: setLongitudeField }), React.createElement(Selector, { label: formatString(MapboxLocale.latitudeField), value: latitudeField, options: dataset.fields.map(function (f) { return f.key; }), onChange: setLatitudeField }), React.createElement(MetricItem, { label: BaseLocale.metric, isMultipleMode: false, metricOptions: dataset.fields.map(function (f) { return f.key; }), metrics: currentMetrics, onChange: setCurrentMetrics, getPopupContainer: this.getRootDOM }), React.createElement(Selector, { allowClear: true, isMultipleMode: true, label: formatString(MapboxLocale.displayFields), options: dataset.fields.map(function (f) { return f.key; }), value: displayFields, onChange: setDisplayFields }), React.createElement(UnitItem, { label: UnitLocale.title, onChange: setUnit, value: unit }), React.createElement(NumberItem, { label: BaseLocale.precision, value: precision, onChange: setPrecision })), React.createElement(Panel, { header: formatString(BaseLocale.chart_style), key: "2" }, React.createElement(StyleElement, { chartStyleService: chartStyleService })), React.createElement(Panel, { header: formatString(BaseLocale.color), key: "3" }, chartType === ChartType.MapboxBubble && (React.createElement(Item, { label: formatString(MapboxLocale.shapeColor.point) }, React.createElement(ColorPicker, { value: color || bubbleDefaultColor, onChange: setColor, getPopupContainer: this.getRootDOM }))), chartType === ChartType.MapboxPath && (React.createElement(React.Fragment, null, React.createElement(Item, { label: formatString(MapboxLocale.shapeColor.line) }, React.createElement(ColorPicker, { value: lineColor || lineDefaultColor, onChange: setLineColor, getPopupContainer: this.getRootDOM })), React.createElement(Item, { label: formatString(MapboxLocale.shapeColor.point) }, React.createElement(ColorPicker, { value: pointColor || bubbleDefaultColor, onChange: setPointColor, getPopupContainer: this.getRootDOM }))))), React.createElement(Panel, { header: formatString(MapboxLocale.config.title), key: "5" }, React.createElement(MapConfig, { chartStyleService: chartStyleService }))))); }; __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MapboxStyleConfigForm.prototype, "moreThenOneValidator", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MapboxStyleConfigForm.prototype, "minBubbleSizeValidator", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MapboxStyleConfigForm.prototype, "pointSizeValidator", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MapboxStyleConfigForm.prototype, "maxBubbleSizeValidator", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MapboxStyleConfigForm.prototype, "lineSizeValidator", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [String, Number]), __metadata("design:returntype", void 0) ], MapboxStyleConfigForm.prototype, "bubbleSizeValidator", null); MapboxStyleConfigForm = __decorate([ observer ], MapboxStyleConfigForm); return MapboxStyleConfigForm; }(BasicComponent)); export default MapboxStyleConfigForm;