UNPKG

4.75 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var util_1 = require("@antv/util");
5var constant_1 = require("../constant");
6var facet_1 = require("../util/facet");
7var facet_2 = require("./facet");
8/**
9 * @ignore
10 * 镜像分面
11 */
12var Matrix = /** @class */ (function (_super) {
13 tslib_1.__extends(Matrix, _super);
14 function Matrix() {
15 return _super !== null && _super.apply(this, arguments) || this;
16 }
17 Matrix.prototype.getDefaultCfg = function () {
18 return (0, util_1.deepMix)({}, _super.prototype.getDefaultCfg.call(this), {
19 type: 'matrix',
20 showTitle: false,
21 columnTitle: tslib_1.__assign({}, _super.prototype.getDefaultTitleCfg.call(this)),
22 rowTitle: tslib_1.__assign({}, _super.prototype.getDefaultTitleCfg.call(this)),
23 });
24 };
25 Matrix.prototype.render = function () {
26 _super.prototype.render.call(this);
27 if (this.cfg.showTitle) {
28 this.renderTitle();
29 }
30 };
31 Matrix.prototype.afterEachView = function (view, facet) {
32 this.processAxis(view, facet);
33 };
34 Matrix.prototype.beforeEachView = function (view, facet) { };
35 Matrix.prototype.generateFacets = function (data) {
36 var _a = this.cfg, fields = _a.fields, type = _a.type;
37 // 矩阵中行列相等,等于指定的字段个数
38 var rowValuesLength = fields.length;
39 var columnValuesLength = rowValuesLength;
40 var rst = [];
41 for (var i = 0; i < columnValuesLength; i++) {
42 var columnField = fields[i];
43 for (var j = 0; j < rowValuesLength; j++) {
44 var rowField = fields[j];
45 var facet = {
46 type: type,
47 data: data,
48 region: this.getRegion(rowValuesLength, columnValuesLength, i, j),
49 columnValue: columnField,
50 rowValue: rowField,
51 columnField: columnField,
52 rowField: rowField,
53 columnIndex: i,
54 rowIndex: j,
55 columnValuesLength: columnValuesLength,
56 rowValuesLength: rowValuesLength,
57 };
58 rst.push(facet);
59 }
60 }
61 return rst;
62 };
63 /**
64 * 设置 x 坐标轴的文本、title 是否显示
65 * @param x
66 * @param axes
67 * @param option
68 * @param facet
69 */
70 Matrix.prototype.getXAxisOption = function (x, axes, option, facet) {
71 // 最后一行显示
72 if (facet.rowIndex !== facet.rowValuesLength - 1) {
73 return tslib_1.__assign(tslib_1.__assign({}, option), { label: null, title: null });
74 }
75 return option;
76 };
77 /**
78 * 设置 y 坐标轴的文本、title 是否显示
79 * @param y
80 * @param axes
81 * @param option
82 * @param facet
83 */
84 Matrix.prototype.getYAxisOption = function (y, axes, option, facet) {
85 // 第一列显示
86 if (facet.columnIndex !== 0) {
87 return tslib_1.__assign(tslib_1.__assign({}, option), { title: null, label: null });
88 }
89 return option;
90 };
91 /**
92 * facet title
93 */
94 Matrix.prototype.renderTitle = function () {
95 var _this = this;
96 (0, util_1.each)(this.facets, function (facet, facetIndex) {
97 var columnIndex = facet.columnIndex, rowIndex = facet.rowIndex, columnValuesLength = facet.columnValuesLength, rowValuesLength = facet.rowValuesLength, columnValue = facet.columnValue, rowValue = facet.rowValue, view = facet.view;
98 // top
99 if (rowIndex === 0) {
100 var formatter = (0, util_1.get)(_this.cfg.columnTitle, 'formatter');
101 var config = (0, util_1.deepMix)({
102 position: ['50%', '0%'],
103 content: formatter ? formatter(columnValue) : columnValue,
104 }, (0, facet_1.getFactTitleConfig)(constant_1.DIRECTION.TOP), _this.cfg.columnTitle);
105 view.annotation().text(config);
106 }
107 // right
108 if (columnIndex === columnValuesLength - 1) {
109 var formatter = (0, util_1.get)(_this.cfg.rowTitle, 'formatter');
110 var config = (0, util_1.deepMix)({
111 position: ['100%', '50%'],
112 content: formatter ? formatter(rowValue) : rowValue,
113 }, (0, facet_1.getFactTitleConfig)(constant_1.DIRECTION.RIGHT), _this.cfg.rowTitle);
114 view.annotation().text(config);
115 }
116 });
117 };
118 return Matrix;
119}(facet_2.Facet));
120exports.default = Matrix;
121//# sourceMappingURL=matrix.js.map
\No newline at end of file