area.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Area = void 0;
  4. const d3_array_1 = require("d3-array");
  5. const utils_1 = require("./utils");
  6. /*
  7. * Convert value for each channel to area shapes.
  8. *
  9. * ▲
  10. * │
  11. * │ y2
  12. * │
  13. * │ y1 xxxxxxxxxxxxx
  14. * │ xxxx x
  15. * │ xxx x
  16. * │ xxx x
  17. * │ y0 xxx x
  18. * │ xxxxxxx x
  19. * │ x x
  20. * │ xx x
  21. * │ x x
  22. * │ x x
  23. * │ x x
  24. * │ x x
  25. * │ x x
  26. * │ x x
  27. * │ x x
  28. * ────┼─────────x───────────────────────────────x──────────────►
  29. * │ y3 y4 y5
  30. */
  31. const Area = () => {
  32. return (index, scale, value, coordinate) => {
  33. var _a, _b;
  34. const { x: X, y: Y, y1: Y1, series: S } = value;
  35. const { x, y } = scale;
  36. // Group data by series field.
  37. const series = S ? Array.from((0, d3_array_1.group)(index, (i) => S[i]).values()) : [index];
  38. const I = series.map((group) => group[0]).filter((i) => i !== undefined);
  39. // A group of data corresponds to one area.
  40. const xoffset = (((_a = x === null || x === void 0 ? void 0 : x.getBandWidth) === null || _a === void 0 ? void 0 : _a.call(x)) || 0) / 2;
  41. const yoffset = (((_b = y === null || y === void 0 ? void 0 : y.getBandWidth) === null || _b === void 0 ? void 0 : _b.call(y)) || 0) / 2;
  42. const P = Array.from(series, (SI) => {
  43. const l = SI.length;
  44. const points = new Array(l * 2);
  45. for (let idx = 0; idx < SI.length; idx++) {
  46. const i = SI[idx];
  47. points[idx] = coordinate.map([+X[i] + xoffset, +Y[i] + yoffset]); // y1
  48. points[l + idx] = coordinate.map([+X[i] + xoffset, +Y1[i] + yoffset]); // y0
  49. }
  50. return points;
  51. });
  52. return [I, P, series];
  53. };
  54. };
  55. exports.Area = Area;
  56. const shapes = ['area', 'smooth', 'hvh', 'hv', 'vh'];
  57. exports.Area.props = {
  58. defaultShape: 'area',
  59. defaultLabelShape: 'label',
  60. composite: false,
  61. channels: [
  62. ...(0, utils_1.baseGeometryChannels)({ shapes }),
  63. { name: 'x', required: true },
  64. { name: 'y', required: true },
  65. { name: 'size' },
  66. { name: 'series', scale: 'identity' },
  67. ],
  68. preInference: [
  69. ...(0, utils_1.basePreInference)(),
  70. { type: 'maybeSeries' },
  71. { type: 'maybeZeroY1' },
  72. { type: 'maybeZeroPadding' },
  73. ],
  74. postInference: [...(0, utils_1.basePostInference)(), ...(0, utils_1.tooltip1d)()],
  75. interaction: {
  76. shareTooltip: true,
  77. seriesTooltip: true,
  78. crosshairs: true,
  79. },
  80. };
  81. //# sourceMappingURL=area.js.map