heatmap.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.Heatmap = void 0;
  15. const d3_array_1 = require("d3-array");
  16. const g_1 = require("@antv/g");
  17. const utils_1 = require("../utils");
  18. const selection_1 = require("../../utils/selection");
  19. const renderer_1 = require("./renderer");
  20. function deleteKey(obj, fn) {
  21. const r = Object.assign({}, obj);
  22. return Object.keys(obj).reduce((r, k) => {
  23. const v = obj[k];
  24. if (!fn(v, k))
  25. r[k] = v;
  26. return r;
  27. }, {});
  28. }
  29. const Heatmap = (options) => {
  30. const { gradient, opacity, maxOpacity, minOpacity, blur, useGradientOpacity } = options, style = __rest(options, ["gradient", "opacity", "maxOpacity", "minOpacity", "blur", "useGradientOpacity"]);
  31. return (points, value, coordinate, theme, _, context) => {
  32. const { mark, shape, defaultShape, transform } = value;
  33. const shapeTheme = __rest((0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), []);
  34. const { createCanvas } = context;
  35. const [width, height] = coordinate.getSize();
  36. const data = points.map((p) => ({
  37. x: p[0],
  38. y: p[1],
  39. value: p[2],
  40. radius: p[3],
  41. }));
  42. const min = (0, d3_array_1.min)(points, (p) => p[2]);
  43. const max = (0, d3_array_1.max)(points, (p) => p[2]);
  44. const options = {
  45. gradient,
  46. opacity,
  47. minOpacity,
  48. maxOpacity,
  49. blur,
  50. useGradientOpacity,
  51. };
  52. const ctx = width && height
  53. ? (0, renderer_1.HeatmapRenderer)(width, height, min, max, data, deleteKey(options, (v) => v === undefined), createCanvas)
  54. : { canvas: null };
  55. return (0, selection_1.select)(new g_1.Image())
  56. .call(utils_1.applyStyle, shapeTheme)
  57. .style('x', 0)
  58. .style('y', 0)
  59. .style('width', width)
  60. .style('height', height)
  61. .style('src', ctx.canvas)
  62. .style('transform', transform)
  63. .call(utils_1.applyStyle, style)
  64. .node();
  65. };
  66. };
  67. exports.Heatmap = Heatmap;
  68. exports.Heatmap.props = {
  69. defaultMarker: 'point',
  70. defaultEnterAnimation: 'fadeIn',
  71. defaultUpdateAnimation: 'morphing',
  72. defaultExitAnimation: 'fadeOut',
  73. };
  74. //# sourceMappingURL=heatmap.js.map