@visactor/vchart
Version:
charts lib based @visactor/VGrammar
224 lines (217 loc) • 11.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.registerCorrelationSeries = exports.CorrelationSeries = void 0;
const polar_1 = require("../polar/polar"), type_1 = require("../interface/type"), constant_1 = require("./constant"), register_1 = require("../../data/register"), correlation_1 = require("../../data/transforms/correlation"), correlation_center_1 = require("../../data/transforms/correlation-center"), vutils_1 = require("@visactor/vutils"), symbol_1 = require("../../mark/symbol"), data_1 = require("../../constant/data"), attribute_1 = require("../../constant/attribute"), layout_1 = require("../../constant/layout"), vdataset_1 = require("@visactor/vdataset"), interface_1 = require("../../compile/mark/interface"), ripple_1 = require("../../mark/ripple"), correlation_2 = require("../../constant/correlation"), utils_1 = require("../../animation/utils"), factory_1 = require("../../core/factory"), animation_1 = require("./animation"), correlation_transformer_1 = require("./correlation-transformer"), data_2 = require("../../compile/data"), correlation_3 = require("../../theme/builtin/common/series/correlation");
class CorrelationSeries extends polar_1.PolarSeries {
constructor() {
super(...arguments), this.type = type_1.SeriesTypeEnum.correlation, this.transformerConstructor = correlation_transformer_1.CorrelationSeriesSpecTransformer,
this._viewBox = new vutils_1.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) {
(0, vutils_1.isValid)(field) && (this._seriesField = field);
}
getSizeField() {
return this._sizeField;
}
setSizeField(field) {
(0, vutils_1.isValid)(field) && (this._sizeField = field);
}
getSizeRange() {
return this._sizeRange;
}
setSizeRange(range) {
(0, vutils_1.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;
(0, register_1.registerDataSetInstanceTransform)(this._dataSet, "correlation", correlation_1.correlation);
const centerDataSet = new vdataset_1.DataSet;
(0, register_1.registerDataSetInstanceParser)(centerDataSet, "dataview", vdataset_1.dataViewParser),
(0, register_1.registerDataSetInstanceTransform)(centerDataSet, "correlationCenter", correlation_center_1.correlationCenter);
const centerDataView = new vdataset_1.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 data_2.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: data_1.DEFAULT_DATA_INDEX
});
nodePointMark && (nodePointMark.setMarkConfig({
zIndex: layout_1.LayoutZIndex.Node
}), this._nodePointMark = nodePointMark);
const ripplePointMark = this._createMark(CorrelationSeries.mark.ripplePoint, {
key: data_1.DEFAULT_DATA_INDEX,
dataView: this._centerSeriesData.getDataView(),
dataProductId: this._centerSeriesData.getProductId()
});
ripplePointMark && (this._ripplePointMark = ripplePointMark);
const centerPointMark = this._createMark(CorrelationSeries.mark.centerPoint, {
key: data_1.DEFAULT_DATA_INDEX,
dataView: this._centerSeriesData.getDataView(),
dataProductId: this._centerSeriesData.getProductId()
});
centerPointMark && (centerPointMark.setMarkConfig({
zIndex: layout_1.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_2.CORRELATION_X],
y: datum => datum[correlation_2.CORRELATION_Y],
size: datum => datum[correlation_2.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
}, interface_1.STATE_VALUE_ENUM.STATE_NORMAL, attribute_1.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
}, interface_1.STATE_VALUE_ENUM.STATE_NORMAL, attribute_1.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
}, interface_1.STATE_VALUE_ENUM.STATE_NORMAL, attribute_1.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)
}, interface_1.STATE_VALUE_ENUM.STATE_NORMAL, attribute_1.AttributeLevel.Series);
}
initAnimation() {
var _a, _b;
const appearPreset = null === (_a = this._spec.animationAppear) || void 0 === _a ? void 0 : _a.preset;
this._nodePointMark.setAnimationConfig((0, utils_1.animationConfig)(null === (_b = factory_1.Factory.getAnimationInKey("correlation")) || void 0 === _b ? void 0 : _b({}, appearPreset), (0,
utils_1.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();
}
}
exports.CorrelationSeries = CorrelationSeries, CorrelationSeries.type = type_1.SeriesTypeEnum.correlation,
CorrelationSeries.mark = constant_1.correlationSeriesMark, CorrelationSeries.builtInTheme = {
correlation: correlation_3.correlation
}, CorrelationSeries.transformerConstructor = correlation_transformer_1.CorrelationSeriesSpecTransformer;
const registerCorrelationSeries = () => {
(0, symbol_1.registerSymbolMark)(), (0, ripple_1.registerRippleMark)(), factory_1.Factory.registerSeries(CorrelationSeries.type, CorrelationSeries),
(0, animation_1.registerCorrelationAnimation)();
};
exports.registerCorrelationSeries = registerCorrelationSeries;
//# sourceMappingURL=correlation.js.map