wordCloud.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. var __rest = (this && this.__rest) || function (s, e) {
  12. var t = {};
  13. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  14. t[p] = s[p];
  15. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  16. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  17. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  18. t[p[i]] = s[p[i]];
  19. }
  20. return t;
  21. };
  22. Object.defineProperty(exports, "__esModule", { value: true });
  23. exports.WordCloud = void 0;
  24. const util_1 = require("@antv/util");
  25. const size_1 = require("../utils/size");
  26. const data_1 = require("../data");
  27. function initializeData(data, encode) {
  28. const { text = 'text', value = 'value' } = encode;
  29. return data.map((d) => (Object.assign(Object.assign({}, d), { text: d[text], value: d[value] })));
  30. }
  31. const WordCloud = (options) => {
  32. return (viewOptions) => __awaiter(void 0, void 0, void 0, function* () {
  33. const { width, height } = (0, size_1.getBBoxSize)(viewOptions);
  34. const { data, encode = {}, scale, style = {}, layout = {} } = options, resOptions = __rest(options, ["data", "encode", "scale", "style", "layout"]);
  35. const DEFAULT_LAYOUT_OPTIONS = {
  36. size: [width, height],
  37. };
  38. const DEFAULT_OPTIONS = {
  39. axis: false,
  40. type: 'text',
  41. encode: {
  42. x: 'x',
  43. y: 'y',
  44. text: 'text',
  45. rotate: 'rotate',
  46. fontSize: 'size',
  47. },
  48. scale: {
  49. x: { domain: [0, width], range: [0, 1] },
  50. y: { domain: [0, height], range: [0, 1] },
  51. fontSize: { type: 'identity' },
  52. rotate: { type: 'identity' },
  53. },
  54. style: {
  55. textAlign: 'center',
  56. },
  57. };
  58. const initializedData = initializeData(data, encode);
  59. const transformData = yield (0, data_1.WordCloud)(Object.assign(Object.assign({}, DEFAULT_LAYOUT_OPTIONS), layout))(initializedData);
  60. return [
  61. (0, util_1.deepMix)({}, DEFAULT_OPTIONS, Object.assign(Object.assign({ data: transformData, encode,
  62. scale,
  63. style }, resOptions), { axis: false })),
  64. ];
  65. });
  66. };
  67. exports.WordCloud = WordCloud;
  68. exports.WordCloud.props = {};
  69. //# sourceMappingURL=wordCloud.js.map