1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var util_1 = require("@antv/util");
|
5 | var constant_1 = require("../constant");
|
6 | var facet_1 = require("../util/facet");
|
7 | var facet_2 = require("./facet");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var Matrix = (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 |
|
65 |
|
66 |
|
67 |
|
68 |
|
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 |
|
79 |
|
80 |
|
81 |
|
82 |
|
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 |
|
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 |
|
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 |
|
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));
|
120 | exports.default = Matrix;
|
121 |
|
\ | No newline at end of file |