point.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Point = void 0;
  4. const utils_1 = require("./utils");
  5. /**
  6. * Convert value for each channel to point shapes.
  7. * Calc the bbox of each point based on x, y and r.
  8. * This is for allowing their radius can be affected by coordinate(e.g. fisheye).
  9. */
  10. const Point = (options) => {
  11. return (index, scale, value, coordinate) => {
  12. const { x: X, y: Y, x1: X1, y1: Y1, size: S, dx: DX, dy: DY } = value;
  13. const [width, height] = coordinate.getSize();
  14. const offset = (0, utils_1.createBandOffset)(scale, value, options);
  15. const xy = (i) => {
  16. const dx = +((DX === null || DX === void 0 ? void 0 : DX[i]) || 0);
  17. const dy = +((DY === null || DY === void 0 ? void 0 : DY[i]) || 0);
  18. const x = X1 ? (+X[i] + +X1[i]) / 2 : +X[i];
  19. const y = Y1 ? (+Y[i] + +Y1[i]) / 2 : +Y[i];
  20. const cx = x + dx;
  21. const cy = y + dy;
  22. return [cx, cy];
  23. };
  24. const P = S
  25. ? Array.from(index, (i) => {
  26. const [cx, cy] = xy(i);
  27. const r = +S[i];
  28. const a = r / width;
  29. const b = r / height;
  30. const p1 = [cx - a, cy - b];
  31. const p2 = [cx + a, cy + b];
  32. return [
  33. coordinate.map(offset(p1, i)),
  34. coordinate.map(offset(p2, i)),
  35. ];
  36. })
  37. : Array.from(index, (i) => [coordinate.map(offset(xy(i), i))]);
  38. return [index, P];
  39. };
  40. };
  41. exports.Point = Point;
  42. const shapes = [
  43. 'hollow',
  44. 'hollowDiamond',
  45. 'hollowHexagon',
  46. 'hollowSquare',
  47. 'hollowTriangleDown',
  48. 'hollowTriangle',
  49. 'hollowBowtie',
  50. 'point',
  51. 'plus',
  52. 'diamond',
  53. 'square',
  54. 'triangle',
  55. 'hexagon',
  56. 'cross',
  57. 'bowtie',
  58. 'hyphen',
  59. 'line',
  60. 'tick',
  61. 'triangleDown',
  62. ];
  63. exports.Point.props = {
  64. defaultShape: 'hollow',
  65. defaultLabelShape: 'label',
  66. composite: false,
  67. channels: [
  68. ...(0, utils_1.baseGeometryChannels)({ shapes }),
  69. { name: 'x', required: true },
  70. { name: 'y', required: true },
  71. { name: 'series', scale: 'band' },
  72. { name: 'size', scale: 'sqrt' },
  73. { name: 'dx', scale: 'identity' },
  74. { name: 'dy', scale: 'identity' },
  75. ],
  76. preInference: [
  77. ...(0, utils_1.basePreInference)(),
  78. { type: 'maybeZeroY' },
  79. { type: 'maybeZeroX' },
  80. ],
  81. postInference: [
  82. ...(0, utils_1.basePostInference)(),
  83. { type: 'maybeSize' },
  84. ...(0, utils_1.tooltip2d)(),
  85. ],
  86. };
  87. //# sourceMappingURL=point.js.map