wordCloud.js 2.9 KB

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