UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

254 lines (230 loc) 11.1 kB
import { PolarSeries } from "../polar/polar"; import { SeriesTypeEnum } from "../interface/type"; import { correlationSeriesMark } from "./constant"; import { registerDataSetInstanceTransform, registerDataSetInstanceParser } from "../../data/register"; import { correlation } from "../../data/transforms/correlation"; import { correlationCenter } from "../../data/transforms/correlation-center"; import { Bounds, isValid } from "@visactor/vutils"; import { registerSymbolMark } from "../../mark/symbol"; import { DEFAULT_DATA_INDEX } from "../../constant/data"; import { AttributeLevel } from "../../constant/attribute"; import { LayoutZIndex } from "../../constant/layout"; import { DataView, DataSet, dataViewParser } from "@visactor/vdataset"; import { STATE_VALUE_ENUM } from "../../compile/mark/interface"; import { registerRippleMark } from "../../mark/ripple"; import { CORRELATION_X, CORRELATION_Y, CORRELATION_SIZE } from "../../constant/correlation"; import { animationConfig, userAnimationConfig } from "../../animation/utils"; import { Factory } from "../../core/factory"; import { registerCorrelationAnimation } from "./animation"; import { CorrelationSeriesSpecTransformer } from "./correlation-transformer"; import { CompilableData } from "../../compile/data"; import { correlation as correlationTheme } from "../../theme/builtin/common/series/correlation"; export class CorrelationSeries extends PolarSeries { constructor() { super(...arguments), this.type = SeriesTypeEnum.correlation, this.transformerConstructor = CorrelationSeriesSpecTransformer, this._viewBox = new Bounds; } getCategoryField() { return this._categoryField; } setCategoryField(f) { return this._categoryField = f, this._categoryField; } getValueField() { return this._valueField; } setValueField(f) { return this._valueField = f, this._valueField; } getSeriesField() { return this._seriesField; } setSeriesField(field) { isValid(field) && (this._seriesField = field); } getSizeField() { return this._sizeField; } setSizeField(field) { isValid(field) && (this._sizeField = field); } getSizeRange() { return this._sizeRange; } setSizeRange(range) { isValid(range) && (this._sizeRange = range); } setAttrFromSpec() { super.setAttrFromSpec(), this.setCategoryField(this._spec.categoryField), this.setValueField(this._spec.valueField), this.setSeriesField(this._spec.seriesField), this.setSizeField(this._spec.sizeField), this.setSizeRange(this._spec.sizeRange); } initData() { var _a, _b, _c; if (super.initData(), !this._data) return; registerDataSetInstanceTransform(this._dataSet, "correlation", correlation); const centerDataSet = new DataSet; registerDataSetInstanceParser(centerDataSet, "dataview", dataViewParser), registerDataSetInstanceTransform(centerDataSet, "correlationCenter", correlationCenter); const centerDataView = new DataView(centerDataSet, { name: `${this.type}_${this.id}_center` }); centerDataView.parse([ this.getViewData() ], { type: "dataview" }), centerDataView.transform({ type: "correlationCenter", options: { keyword: null !== (_c = null === (_b = null === (_a = this._spec.centerLabel) || void 0 === _a ? void 0 : _a.style) || void 0 === _b ? void 0 : _b.text) && void 0 !== _c ? _c : "", categoryField: this._spec.categoryField } }), this._centerSeriesData = new CompilableData(this._option, centerDataView); } compileData() { var _a; super.compileData(), null === (_a = this._centerSeriesData) || void 0 === _a || _a.compile(); } _statisticViewData() { super._statisticViewData(), this._data.getDataView().transform({ type: "correlation", options: { view: () => ({ x0: this._viewBox.x1, x1: this._viewBox.x2, y0: this._viewBox.y1, y1: this._viewBox.y2 }), field: this._spec.valueField, radiusRange: this._spec.sizeRange, radiusField: this._spec.sizeField, center: [ this._spec.centerX, this._spec.centerY ], innerRadius: this._spec.innerRadius, outerRadius: this._spec.outerRadius, startAngle: this._spec.startAngle, endAngle: this._spec.endAngle } }); } initMark() { const nodePointMark = this._createMark(CorrelationSeries.mark.nodePoint, { groupKey: this._seriesField, isSeriesMark: !0, key: DEFAULT_DATA_INDEX }); nodePointMark && (nodePointMark.setMarkConfig({ zIndex: LayoutZIndex.Node }), this._nodePointMark = nodePointMark); const ripplePointMark = this._createMark(CorrelationSeries.mark.ripplePoint, { key: DEFAULT_DATA_INDEX, dataView: this._centerSeriesData.getDataView(), dataProductId: this._centerSeriesData.getProductId() }); ripplePointMark && (this._ripplePointMark = ripplePointMark); const centerPointMark = this._createMark(CorrelationSeries.mark.centerPoint, { key: DEFAULT_DATA_INDEX, dataView: this._centerSeriesData.getDataView(), dataProductId: this._centerSeriesData.getProductId() }); centerPointMark && (centerPointMark.setMarkConfig({ zIndex: LayoutZIndex.Node }), this._centerPointMark = centerPointMark); } initMarkStyle() { this._initNodePointMarkStyle(), this._initRipplePointMarkStyle(), this._initCenterPointMarkStyle(); } _initNodePointMarkStyle() { var _a, _b, _c, _d; const nodePointMark = this._nodePointMark; if (!nodePointMark) return; const nodePointStyle = null !== (_b = null === (_a = this._spec.nodePoint) || void 0 === _a ? void 0 : _a.style) && void 0 !== _b ? _b : {}; this.setMarkStyle(nodePointMark, { x: datum => datum[CORRELATION_X], y: datum => datum[CORRELATION_Y], size: datum => datum[CORRELATION_SIZE], fill: null !== (_c = nodePointStyle.fill) && void 0 !== _c ? _c : this.getColorAttribute(), fillOpacity: null !== (_d = nodePointStyle.fillOpacity) && void 0 !== _d ? _d : 1, lineWidth: 0 }, STATE_VALUE_ENUM.STATE_NORMAL, AttributeLevel.Series); } _initRipplePointMarkStyle() { var _a, _b, _c, _d, _e; const ripplePointMark = this._ripplePointMark; if (!ripplePointMark) return; const ripplePointStyle = null !== (_b = null === (_a = this._spec.ripplePoint) || void 0 === _a ? void 0 : _a.style) && void 0 !== _b ? _b : {}; this.setMarkStyle(ripplePointMark, { x: () => { var _a; return null !== (_a = this._spec.centerX) && void 0 !== _a ? _a : (this._viewBox.x1 + this._viewBox.x2) / 2; }, y: () => { var _a; return null !== (_a = this._spec.centerY) && void 0 !== _a ? _a : (this._viewBox.y1 + this._viewBox.y2) / 2; }, size: () => Math.max(this._viewBox.x2 - this._viewBox.x1, this._viewBox.y2 - this._viewBox.y1) / 2, fill: null !== (_c = ripplePointStyle.fill) && void 0 !== _c ? _c : this.getColorAttribute(), opacity: null !== (_d = ripplePointStyle.fillOpacity) && void 0 !== _d ? _d : .2, ripple: null !== (_e = ripplePointStyle.ripple) && void 0 !== _e ? _e : 0 }, STATE_VALUE_ENUM.STATE_NORMAL, AttributeLevel.Series); } _initCenterPointMarkStyle() { var _a, _b, _c, _d, _e, _f; const centerPointMark = this._centerPointMark; centerPointMark && this.setMarkStyle(centerPointMark, { x: () => { var _a; return null !== (_a = this._spec.centerX) && void 0 !== _a ? _a : (this._viewBox.x1 + this._viewBox.x2) / 2; }, y: () => { var _a; return null !== (_a = this._spec.centerY) && void 0 !== _a ? _a : (this._viewBox.y1 + this._viewBox.y2) / 2; }, size: () => .2 * Math.max(this._viewBox.x2 - this._viewBox.x1, this._viewBox.y2 - this._viewBox.y1) / 2, fill: null !== (_c = null === (_b = null === (_a = this._spec.centerPoint) || void 0 === _a ? void 0 : _a.style) || void 0 === _b ? void 0 : _b.fill) && void 0 !== _c ? _c : this.getColorAttribute(), fillOpacity: null !== (_f = null === (_e = null === (_d = this._spec.centerPoint) || void 0 === _d ? void 0 : _d.style) || void 0 === _e ? void 0 : _e.fillOpacity) && void 0 !== _f ? _f : 1 }, STATE_VALUE_ENUM.STATE_NORMAL, AttributeLevel.Series); } initTooltip() { super.initTooltip(), this._nodePointMark && this._tooltipHelper.activeTriggerSet.mark.add(this._nodePointMark); } initLabelMarkStyle(labelMark) { labelMark && this.setMarkStyle(labelMark, { fill: this.getColorAttribute(), text: datum => datum[this._categoryField], z: this.dataToPositionZ.bind(this) }, STATE_VALUE_ENUM.STATE_NORMAL, AttributeLevel.Series); } initAnimation() { var _a, _b; const appearPreset = null === (_a = this._spec.animationAppear) || void 0 === _a ? void 0 : _a.preset; this._nodePointMark.setAnimationConfig(animationConfig(null === (_b = Factory.getAnimationInKey("correlation")) || void 0 === _b ? void 0 : _b({}, appearPreset), userAnimationConfig("nodePoint", this._spec, this._markAttributeContext))); } getGroupFields() { return []; } getStackGroupFields() { return []; } getStackValueField() { return ""; } getActiveMarks() { return [ this._nodePointMark, this._centerPointMark ]; } getDimensionField() { return [ this._categoryField ]; } getMeasureField() { return [ this._valueField ]; } onLayoutEnd() { super.onLayoutEnd(), this._viewBox.set(0, 0, this._region.getLayoutRect().width, this._region.getLayoutRect().height), this._rawData.reRunAllTransform(), this.getViewData().reRunAllTransform(); } } CorrelationSeries.type = SeriesTypeEnum.correlation, CorrelationSeries.mark = correlationSeriesMark, CorrelationSeries.builtInTheme = { correlation: correlationTheme }, CorrelationSeries.transformerConstructor = CorrelationSeriesSpecTransformer; export const registerCorrelationSeries = () => { registerSymbolMark(), registerRippleMark(), Factory.registerSeries(CorrelationSeries.type, CorrelationSeries), registerCorrelationAnimation(); }; //# sourceMappingURL=correlation.js.map