funnel.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. var __rest = (this && this.__rest) || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  5. t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  7. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  8. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  9. t[p[i]] = s[p[i]];
  10. }
  11. return t;
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.Funnel = void 0;
  15. const g_1 = require("@antv/g");
  16. const d3_shape_1 = require("d3-shape");
  17. const coordinate_1 = require("../../utils/coordinate");
  18. const selection_1 = require("../../utils/selection");
  19. const utils_1 = require("../utils");
  20. /**
  21. * Adjust and return the new `points`.
  22. */
  23. function getFunnelPoints(points, nextPoints, coordinate) {
  24. const [p0, p1, p2, p3] = points;
  25. if ((0, coordinate_1.isTranspose)(coordinate)) {
  26. const newP1 = [nextPoints ? nextPoints[0][0] : p1[0], p1[1]];
  27. const newP2 = [nextPoints ? nextPoints[3][0] : p2[0], p2[1]];
  28. return [p0, newP1, newP2, p3];
  29. }
  30. const newP1 = [p1[0], nextPoints ? nextPoints[0][1] : p1[1]];
  31. const newP2 = [p2[0], nextPoints ? nextPoints[3][1] : p2[1]];
  32. return [p0, newP1, newP2, p3];
  33. }
  34. /**
  35. * Render funnel in different coordinate and using color channel for stroke and fill attribute.
  36. */
  37. const Funnel = (options) => {
  38. const { adjustPoints = getFunnelPoints } = options, style = __rest(options, ["adjustPoints"]);
  39. return (points, value, coordinate, theme, point2d, ...args) => {
  40. const { index, mark, shape, defaultShape } = value;
  41. const _a = (0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), { defaultColor } = _a, defaults = __rest(_a, ["defaultColor"]);
  42. const nextPoints = point2d[index + 1];
  43. const funnelPoints = adjustPoints(points, nextPoints, coordinate);
  44. const tpShape = !!(0, coordinate_1.isTranspose)(coordinate);
  45. const [p0, p1, p2, p3] = tpShape ? (0, utils_1.reorder)(funnelPoints) : funnelPoints;
  46. const { color = defaultColor, opacity } = value;
  47. const b = (0, d3_shape_1.line)().curve(d3_shape_1.curveLinearClosed)([p0, p1, p2, p3]);
  48. return (0, selection_1.select)(new g_1.Path({}))
  49. .call(utils_1.applyStyle, defaults)
  50. .style('path', b)
  51. .style('fill', color)
  52. .style('fillOpacity', opacity)
  53. .call(utils_1.applyStyle, style)
  54. .node();
  55. };
  56. };
  57. exports.Funnel = Funnel;
  58. exports.Funnel.props = {
  59. defaultMarker: 'square',
  60. };
  61. //# sourceMappingURL=funnel.js.map