density.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var __rest = (this && this.__rest) || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  4. t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  6. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  8. t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import { path as d3path } from 'd3-path';
  13. import { Path } from '@antv/g';
  14. import { applyStyle, getShapeTheme } from '../utils';
  15. import { select } from '../../utils/selection';
  16. /**
  17. * Draw density shape.
  18. */
  19. export const Density = (options) => {
  20. const style = __rest(options, []);
  21. return (points, value, coordinate, theme) => {
  22. const { mark, shape, defaultShape, transform } = value;
  23. const _a = getShapeTheme(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  24. const { color = defaultColor } = value;
  25. const [first, ...p] = points;
  26. // todo smooth, hollow
  27. const path = d3path();
  28. path.moveTo(...first);
  29. p.forEach(([x, y]) => {
  30. path.lineTo(x, y);
  31. });
  32. path.closePath();
  33. return select(new Path())
  34. .call(applyStyle, shapeTheme)
  35. .style('d', path.toString())
  36. .style('stroke', color || defaultColor) // Always has stroke color.
  37. .style('fill', color || defaultColor)
  38. .style('fillOpacity', 0.4)
  39. .style('transform', transform)
  40. .call(applyStyle, style)
  41. .node();
  42. };
  43. };
  44. Density.props = {
  45. defaultMarker: 'square',
  46. defaultEnterAnimation: 'fadeIn',
  47. defaultUpdateAnimation: 'morphing',
  48. defaultExitAnimation: 'fadeOut',
  49. };
  50. //# sourceMappingURL=density.js.map