density.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.Density = void 0;
  15. const d3_path_1 = require("d3-path");
  16. const g_1 = require("@antv/g");
  17. const utils_1 = require("../utils");
  18. const selection_1 = require("../../utils/selection");
  19. /**
  20. * Draw density shape.
  21. */
  22. const Density = (options) => {
  23. const style = __rest(options, []);
  24. return (points, value, coordinate, theme) => {
  25. const { mark, shape, defaultShape, transform } = value;
  26. const _a = (0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  27. const { color = defaultColor } = value;
  28. const [first, ...p] = points;
  29. // todo smooth, hollow
  30. const path = (0, d3_path_1.path)();
  31. path.moveTo(...first);
  32. p.forEach(([x, y]) => {
  33. path.lineTo(x, y);
  34. });
  35. path.closePath();
  36. return (0, selection_1.select)(new g_1.Path())
  37. .call(utils_1.applyStyle, shapeTheme)
  38. .style('d', path.toString())
  39. .style('stroke', color || defaultColor) // Always has stroke color.
  40. .style('fill', color || defaultColor)
  41. .style('fillOpacity', 0.4)
  42. .style('transform', transform)
  43. .call(utils_1.applyStyle, style)
  44. .node();
  45. };
  46. };
  47. exports.Density = Density;
  48. exports.Density.props = {
  49. defaultMarker: 'square',
  50. defaultEnterAnimation: 'fadeIn',
  51. defaultUpdateAnimation: 'morphing',
  52. defaultExitAnimation: 'fadeOut',
  53. };
  54. //# sourceMappingURL=density.js.map