1 | import { __assign, __extends } from "tslib";
|
2 | import { jsx, Component } from '@antv/f-engine';
|
3 | import { partition, hierarchy } from '../../deps/d3-hierarchy/src';
|
4 | import { Category } from '../../attr';
|
5 | import CoordController from '../../controller/coord';
|
6 | import { mix, isFunction } from '@antv/util';
|
7 | import Theme from '../../theme';
|
8 | function rootParent(data) {
|
9 | var d = data;
|
10 | while (d.depth > 1) {
|
11 | d = d.parent;
|
12 | }
|
13 | return d;
|
14 | }
|
15 | export default (function (View) {
|
16 | return function (_super) {
|
17 | __extends(Sunburst, _super);
|
18 | function Sunburst(props, context) {
|
19 | var _this = _super.call(this, props, context) || this;
|
20 | var color = props.color,
|
21 | data = props.data;
|
22 | _this.coord = new CoordController();
|
23 | _this.color = new Category(__assign(__assign({
|
24 | range: Theme.colors
|
25 | }, color), {
|
26 | data: data
|
27 | }));
|
28 | return _this;
|
29 | }
|
30 | Sunburst.prototype.willMount = function () {
|
31 | var _a = this,
|
32 | props = _a.props,
|
33 | coord = _a.coord,
|
34 | layout = _a.layout;
|
35 | var coordOption = props.coord;
|
36 | coord.updateLayout(layout);
|
37 | coord.create(coordOption);
|
38 | };
|
39 | Sunburst.prototype.didMount = function () {};
|
40 | Sunburst.prototype._mapping = function (children) {
|
41 | var _a = this,
|
42 | colorAttr = _a.color,
|
43 | coord = _a.coord;
|
44 | for (var i = 0, len = children.length; i < len; i++) {
|
45 | var node = children[i];
|
46 | var root = rootParent(node);
|
47 | var color = colorAttr.mapping(root.data[colorAttr.field]);
|
48 | node.color = color;
|
49 | var x0 = node.x0,
|
50 | x1 = node.x1,
|
51 | y0 = node.y0,
|
52 | y1 = node.y1;
|
53 | var rect = coord.getCoord().convertRect({
|
54 | x: [x0, x1],
|
55 | y: [y0, y1]
|
56 | });
|
57 | mix(node, rect);
|
58 |
|
59 | if (node.children && node.children.length) {
|
60 | this._mapping(node.children);
|
61 | }
|
62 | }
|
63 | };
|
64 | Sunburst.prototype.sunburst = function () {
|
65 | var props = this.props;
|
66 | var data = props.data,
|
67 | value = props.value,
|
68 | _a = props.sort,
|
69 | sort = _a === void 0 ? true : _a;
|
70 | var root = hierarchy({
|
71 | children: data
|
72 | }).sum(function (d) {
|
73 | return d[value];
|
74 | });
|
75 |
|
76 | if (sort === true || isFunction(sort)) {
|
77 | var sortFn = isFunction(sort) ? sort : function (a, b) {
|
78 | return b[value] - a[value];
|
79 | };
|
80 | root.sort(sortFn);
|
81 | }
|
82 | var nodes = partition()(root);
|
83 | var children = nodes.children;
|
84 | this._mapping(children);
|
85 | return nodes;
|
86 | };
|
87 | Sunburst.prototype.render = function () {
|
88 | var node = this.sunburst();
|
89 | var _a = this,
|
90 | coord = _a.coord,
|
91 | props = _a.props;
|
92 | return jsx(View, __assign({}, props, {
|
93 | coord: coord.getCoord(),
|
94 | node: node,
|
95 | triggerRef: this.triggerRef
|
96 | }));
|
97 | };
|
98 | return Sunburst;
|
99 | }(Component);
|
100 | }); |
\ | No newline at end of file |