tree.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Tree = void 0;
  4. const util_1 = require("@antv/util");
  5. const helper_1 = require("../utils/helper");
  6. const tree_1 = require("../data/tree");
  7. const mark_1 = require("../utils/mark");
  8. const Tree = (options) => {
  9. const DEFAULT_LAYOUT_OPTIONS = {
  10. sortBy: (a, b) => b.value - a.value,
  11. };
  12. const DEFAULT_NODE_OPTIONS = {
  13. axis: false,
  14. legend: false,
  15. type: 'point',
  16. encode: {
  17. x: 'x',
  18. y: 'y',
  19. size: 2,
  20. shape: 'point',
  21. },
  22. };
  23. const DEFAULT_LINK_OPTIONS = {
  24. type: 'link',
  25. encode: {
  26. x: 'x',
  27. y: 'y',
  28. shape: 'smooth',
  29. },
  30. };
  31. const DEFAULT_LABEL_OPTIONS = {
  32. text: '',
  33. fontSize: 10,
  34. };
  35. return () => {
  36. const { data, encode = {}, scale = {}, style = {}, layout = {}, nodeLabels = [], linkLabels = [], animate = {}, tooltip = {}, } = options;
  37. const valueEncode = encode === null || encode === void 0 ? void 0 : encode.value;
  38. const { nodes, edges } = (0, tree_1.Tree)(Object.assign(Object.assign(Object.assign({}, DEFAULT_LAYOUT_OPTIONS), layout), { field: valueEncode }))(data);
  39. const nodeTooltip = (0, mark_1.subTooltip)(tooltip, 'node', {
  40. title: 'name',
  41. items: ['value'],
  42. }, true);
  43. const linkTooltip = (0, mark_1.subTooltip)(tooltip, 'link', {
  44. title: '',
  45. items: [
  46. (d) => ({ name: 'source', value: d.source.name }),
  47. (d) => ({ name: 'target', value: d.target.name }),
  48. ],
  49. });
  50. return [
  51. (0, util_1.deepMix)({}, DEFAULT_LINK_OPTIONS, {
  52. data: edges,
  53. encode: (0, helper_1.subObject)(encode, 'link'),
  54. scale: (0, helper_1.subObject)(scale, 'link'),
  55. labels: linkLabels,
  56. style: Object.assign({ stroke: '#999' }, (0, helper_1.subObject)(style, 'link')),
  57. tooltip: linkTooltip,
  58. animate: (0, mark_1.maybeAnimation)(animate, 'link'),
  59. }),
  60. (0, util_1.deepMix)({}, DEFAULT_NODE_OPTIONS, {
  61. data: nodes,
  62. scale: (0, helper_1.subObject)(scale, 'node'),
  63. encode: (0, helper_1.subObject)(encode, 'node'),
  64. labels: [
  65. Object.assign(Object.assign({}, DEFAULT_LABEL_OPTIONS), (0, helper_1.subObject)(style, 'label')),
  66. ...nodeLabels,
  67. ],
  68. style: Object.assign({}, (0, helper_1.subObject)(style, 'node')),
  69. tooltip: nodeTooltip,
  70. animate: (0, mark_1.maybeAnimation)(animate, 'node'),
  71. }),
  72. ];
  73. };
  74. };
  75. exports.Tree = Tree;
  76. exports.Tree.props = {};
  77. //# sourceMappingURL=tree.js.map