heatmap.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { baseGeometryChannels, basePostInference, basePreInference, tooltip2d, } from './utils';
  2. /**
  3. * Draw heatmap with gradient.
  4. */
  5. export const Heatmap = (options) => {
  6. return (index, scale, value, coordinate) => {
  7. const { x: X, y: Y, size: S, color: C } = value;
  8. const P = Array.from(index, (i) => {
  9. // Default size = 40.
  10. const r = S ? +S[i] : 40;
  11. // Warning: x, y, value, radius.
  12. return [...coordinate.map([+X[i], +Y[i]]), C[i], r];
  13. });
  14. return [[0], [P]];
  15. };
  16. };
  17. const shapes = ['heatmap'];
  18. Heatmap.props = {
  19. defaultShape: 'heatmap',
  20. defaultLabelShape: 'label',
  21. composite: false,
  22. channels: [
  23. ...baseGeometryChannels({ shapes }),
  24. { name: 'x', required: true },
  25. { name: 'y', required: true },
  26. { name: 'color', scale: 'identity', required: true },
  27. { name: 'size' },
  28. ],
  29. preInference: [
  30. ...basePreInference(),
  31. { type: 'maybeZeroY' },
  32. { type: 'maybeZeroX' },
  33. ],
  34. postInference: [...basePostInference(), ...tooltip2d()],
  35. };
  36. //# sourceMappingURL=heatmap.js.map