@antv/g2 5.0.9 → 5.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +3 -3
  3. package/esm/api/chart.d.ts +1 -0
  4. package/esm/api/chart.js +5 -1
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/composition/geoPath.d.ts +1 -0
  7. package/esm/api/composition/geoPath.js +1 -0
  8. package/esm/api/composition/geoPath.js.map +1 -1
  9. package/esm/api/mark/index.d.ts +3 -1
  10. package/esm/api/mark/index.js +2 -1
  11. package/esm/api/mark/index.js.map +1 -1
  12. package/esm/api/mark/mark.d.ts +7 -1
  13. package/esm/api/mark/mark.js +9 -0
  14. package/esm/api/mark/mark.js.map +1 -1
  15. package/esm/api/node.d.ts +1 -0
  16. package/esm/api/node.js +5 -1
  17. package/esm/api/node.js.map +1 -1
  18. package/esm/api/utils.d.ts +1 -1
  19. package/esm/api/utils.js +10 -6
  20. package/esm/api/utils.js.map +1 -1
  21. package/esm/geo/geoPath.js +2 -1
  22. package/esm/geo/geoPath.js.map +1 -1
  23. package/esm/index.d.ts +1 -1
  24. package/esm/index.js +3 -1
  25. package/esm/index.js.map +1 -1
  26. package/esm/interaction/event.js +5 -2
  27. package/esm/interaction/event.js.map +1 -1
  28. package/esm/mark/area.js +1 -1
  29. package/esm/mark/area.js.map +1 -1
  30. package/esm/mark/heatmap.d.ts +7 -0
  31. package/esm/mark/heatmap.js +36 -0
  32. package/esm/mark/heatmap.js.map +1 -0
  33. package/esm/mark/index.d.ts +2 -0
  34. package/esm/mark/index.js +1 -0
  35. package/esm/mark/index.js.map +1 -1
  36. package/esm/mark/line.js +1 -1
  37. package/esm/mark/line.js.map +1 -1
  38. package/esm/mark/text.js +0 -2
  39. package/esm/mark/text.js.map +1 -1
  40. package/esm/mark/utils.d.ts +1 -0
  41. package/esm/mark/utils.js +1 -1
  42. package/esm/mark/utils.js.map +1 -1
  43. package/esm/runtime/plot.js +12 -10
  44. package/esm/runtime/plot.js.map +1 -1
  45. package/esm/runtime/render.d.ts +2 -2
  46. package/esm/runtime/render.js +7 -3
  47. package/esm/runtime/render.js.map +1 -1
  48. package/esm/runtime/scale.js +11 -9
  49. package/esm/runtime/scale.js.map +1 -1
  50. package/esm/runtime/types/component.d.ts +2 -2
  51. package/esm/runtime/types/options.d.ts +6 -0
  52. package/esm/shape/heatmap/heatmap.d.ts +4 -0
  53. package/esm/shape/heatmap/heatmap.js +70 -0
  54. package/esm/shape/heatmap/heatmap.js.map +1 -0
  55. package/esm/shape/heatmap/renderer/gradient.d.ts +5 -0
  56. package/esm/shape/heatmap/renderer/gradient.js +13 -0
  57. package/esm/shape/heatmap/renderer/gradient.js.map +1 -0
  58. package/esm/shape/heatmap/renderer/index.d.ts +6 -0
  59. package/esm/shape/heatmap/renderer/index.js +122 -0
  60. package/esm/shape/heatmap/renderer/index.js.map +1 -0
  61. package/esm/shape/heatmap/renderer/types.d.ts +36 -0
  62. package/esm/shape/heatmap/renderer/types.js +2 -0
  63. package/esm/shape/heatmap/renderer/types.js.map +1 -0
  64. package/esm/shape/image/image.js +8 -3
  65. package/esm/shape/image/image.js.map +1 -1
  66. package/esm/shape/index.d.ts +2 -0
  67. package/esm/shape/index.js +1 -0
  68. package/esm/shape/index.js.map +1 -1
  69. package/esm/spec/component.d.ts +1 -1
  70. package/esm/spec/composition.d.ts +9 -6
  71. package/esm/spec/mark.d.ts +2 -1
  72. package/esm/stdlib/index.js +3 -3
  73. package/esm/stdlib/index.js.map +1 -1
  74. package/esm/utils/lru.d.ts +4 -0
  75. package/esm/utils/lru.js +18 -0
  76. package/esm/utils/lru.js.map +1 -0
  77. package/lib/api/chart.d.ts +1 -0
  78. package/lib/api/chart.js +5 -1
  79. package/lib/api/chart.js.map +1 -1
  80. package/lib/api/composition/geoPath.d.ts +1 -0
  81. package/lib/api/composition/geoPath.js +1 -0
  82. package/lib/api/composition/geoPath.js.map +1 -1
  83. package/lib/api/mark/index.d.ts +3 -1
  84. package/lib/api/mark/index.js +1 -0
  85. package/lib/api/mark/index.js.map +1 -1
  86. package/lib/api/mark/mark.d.ts +7 -1
  87. package/lib/api/mark/mark.js +10 -1
  88. package/lib/api/mark/mark.js.map +1 -1
  89. package/lib/api/node.d.ts +1 -0
  90. package/lib/api/node.js +5 -1
  91. package/lib/api/node.js.map +1 -1
  92. package/lib/api/utils.d.ts +1 -1
  93. package/lib/api/utils.js +10 -6
  94. package/lib/api/utils.js.map +1 -1
  95. package/lib/geo/geoPath.js +2 -1
  96. package/lib/geo/geoPath.js.map +1 -1
  97. package/lib/index.d.ts +1 -1
  98. package/lib/index.js +3 -1
  99. package/lib/index.js.map +1 -1
  100. package/lib/interaction/event.js +5 -2
  101. package/lib/interaction/event.js.map +1 -1
  102. package/lib/mark/area.js +1 -1
  103. package/lib/mark/area.js.map +1 -1
  104. package/lib/mark/heatmap.d.ts +7 -0
  105. package/lib/mark/heatmap.js +40 -0
  106. package/lib/mark/heatmap.js.map +1 -0
  107. package/lib/mark/index.d.ts +2 -0
  108. package/lib/mark/index.js +3 -1
  109. package/lib/mark/index.js.map +1 -1
  110. package/lib/mark/line.js +1 -1
  111. package/lib/mark/line.js.map +1 -1
  112. package/lib/mark/text.js +0 -2
  113. package/lib/mark/text.js.map +1 -1
  114. package/lib/mark/utils.d.ts +1 -0
  115. package/lib/mark/utils.js +2 -1
  116. package/lib/mark/utils.js.map +1 -1
  117. package/lib/runtime/plot.js +12 -10
  118. package/lib/runtime/plot.js.map +1 -1
  119. package/lib/runtime/render.d.ts +2 -2
  120. package/lib/runtime/render.js +7 -3
  121. package/lib/runtime/render.js.map +1 -1
  122. package/lib/runtime/scale.js +11 -9
  123. package/lib/runtime/scale.js.map +1 -1
  124. package/lib/runtime/types/component.d.ts +2 -2
  125. package/lib/runtime/types/options.d.ts +6 -0
  126. package/lib/shape/heatmap/heatmap.d.ts +4 -0
  127. package/lib/shape/heatmap/heatmap.js +74 -0
  128. package/lib/shape/heatmap/heatmap.js.map +1 -0
  129. package/lib/shape/heatmap/renderer/gradient.d.ts +5 -0
  130. package/lib/shape/heatmap/renderer/gradient.js +17 -0
  131. package/lib/shape/heatmap/renderer/gradient.js.map +1 -0
  132. package/lib/shape/heatmap/renderer/index.d.ts +6 -0
  133. package/lib/shape/heatmap/renderer/index.js +126 -0
  134. package/lib/shape/heatmap/renderer/index.js.map +1 -0
  135. package/lib/shape/heatmap/renderer/types.d.ts +36 -0
  136. package/lib/shape/heatmap/renderer/types.js +3 -0
  137. package/lib/shape/heatmap/renderer/types.js.map +1 -0
  138. package/lib/shape/image/image.js +8 -3
  139. package/lib/shape/image/image.js.map +1 -1
  140. package/lib/shape/index.d.ts +2 -0
  141. package/lib/shape/index.js +3 -1
  142. package/lib/shape/index.js.map +1 -1
  143. package/lib/spec/component.d.ts +1 -1
  144. package/lib/spec/composition.d.ts +9 -6
  145. package/lib/spec/mark.d.ts +2 -1
  146. package/lib/stdlib/index.js +1 -1
  147. package/lib/stdlib/index.js.map +1 -1
  148. package/lib/utils/lru.d.ts +4 -0
  149. package/lib/utils/lru.js +25 -0
  150. package/lib/utils/lru.js.map +1 -0
  151. package/package.json +4 -1
  152. package/src/api/chart.ts +4 -1
  153. package/src/api/composition/geoPath.ts +2 -0
  154. package/src/api/mark/index.ts +3 -0
  155. package/src/api/mark/mark.ts +12 -0
  156. package/src/api/node.ts +6 -1
  157. package/src/api/utils.ts +17 -6
  158. package/src/geo/geoPath.ts +3 -1
  159. package/src/index.ts +10 -1
  160. package/src/interaction/event.ts +7 -2
  161. package/src/mark/area.ts +1 -1
  162. package/src/mark/heatmap.ts +48 -0
  163. package/src/mark/index.ts +2 -0
  164. package/src/mark/line.ts +1 -1
  165. package/src/mark/text.ts +0 -1
  166. package/src/mark/utils.ts +1 -1
  167. package/src/runtime/plot.ts +30 -13
  168. package/src/runtime/render.ts +9 -7
  169. package/src/runtime/scale.ts +14 -9
  170. package/src/runtime/types/component.ts +2 -1
  171. package/src/runtime/types/options.ts +6 -0
  172. package/src/shape/heatmap/heatmap.ts +85 -0
  173. package/src/shape/heatmap/renderer/gradient.ts +16 -0
  174. package/src/shape/heatmap/renderer/index.ts +193 -0
  175. package/src/shape/heatmap/renderer/types.ts +38 -0
  176. package/src/shape/image/image.ts +9 -3
  177. package/src/shape/index.ts +2 -0
  178. package/src/spec/component.ts +2 -1
  179. package/src/spec/composition.ts +24 -8
  180. package/src/spec/mark.ts +2 -0
  181. package/src/stdlib/index.ts +4 -0
  182. package/src/utils/lru.ts +25 -0
@@ -0,0 +1,193 @@
1
+ import { lru } from '../../../utils/lru';
2
+ import { parseGradient } from './gradient';
3
+ import {
4
+ HeatmapGradient,
5
+ HeatmapRendererData,
6
+ HeatmapRendererOptions,
7
+ } from './types';
8
+
9
+ function newCanvas(
10
+ createCanvas: () => HTMLCanvasElement,
11
+ width: number,
12
+ height: number,
13
+ ) {
14
+ const c = createCanvas ? createCanvas() : document.createElement('canvas');
15
+ c.width = width;
16
+ c.height = height;
17
+ return c;
18
+ }
19
+
20
+ /**
21
+ * Get a point with template.
22
+ * @param radius
23
+ * @param blurFactor
24
+ * @returns
25
+ */
26
+ const getPointTemplate = lru(
27
+ (
28
+ radius: number,
29
+ blurFactor: number,
30
+ createCanvas?: () => HTMLCanvasElement,
31
+ ) => {
32
+ const tplCanvas = newCanvas(createCanvas, radius * 2, radius * 2);
33
+ const tplCtx = tplCanvas.getContext('2d');
34
+ const x = radius;
35
+ const y = radius;
36
+
37
+ if (blurFactor === 1) {
38
+ tplCtx.beginPath();
39
+ tplCtx.arc(x, y, radius, 0, 2 * Math.PI, false);
40
+ tplCtx.fillStyle = 'rgba(0,0,0,1)';
41
+ tplCtx.fill();
42
+ } else {
43
+ const gradient = tplCtx.createRadialGradient(
44
+ x,
45
+ y,
46
+ radius * blurFactor,
47
+ x,
48
+ y,
49
+ radius,
50
+ );
51
+ gradient.addColorStop(0, 'rgba(0,0,0,1)');
52
+ gradient.addColorStop(1, 'rgba(0,0,0,0)');
53
+ tplCtx.fillStyle = gradient;
54
+ tplCtx.fillRect(0, 0, 2 * radius, 2 * radius);
55
+ }
56
+ return tplCanvas;
57
+ },
58
+ (radius) => `${radius}`,
59
+ );
60
+
61
+ /**
62
+ * Get a color palette with len = 256 base on gradient.
63
+ * @param gradientConfig
64
+ * @returns
65
+ */
66
+ function getColorPalette(gradientConfig: HeatmapGradient, createCanvas) {
67
+ const paletteCanvas = newCanvas(createCanvas, 256, 1);
68
+ const paletteCtx = paletteCanvas.getContext('2d');
69
+
70
+ const gradient = paletteCtx.createLinearGradient(0, 0, 256, 1);
71
+ parseGradient(gradientConfig).forEach(([r, c]) => {
72
+ gradient.addColorStop(r, c);
73
+ });
74
+
75
+ paletteCtx.fillStyle = gradient;
76
+ paletteCtx.fillRect(0, 0, 256, 1);
77
+
78
+ return paletteCtx.getImageData(0, 0, 256, 1).data;
79
+ }
80
+
81
+ /**
82
+ * Draw all circle with alpha.
83
+ */
84
+ function drawAlpha(
85
+ shadowCtx,
86
+ min: number,
87
+ max: number,
88
+ data: HeatmapRendererData[],
89
+ options: HeatmapRendererOptions,
90
+ createCanvas?: () => HTMLCanvasElement,
91
+ ) {
92
+ const { blur } = options;
93
+ let len = data.length;
94
+ while (len--) {
95
+ const { x, y, value: v, radius } = data[len];
96
+ // Ff value is bigger than max, use max as value.
97
+ const value = Math.min(v, max);
98
+ const rectX = x - radius;
99
+ const rectY = y - radius;
100
+
101
+ const tpl = getPointTemplate(radius, 1 - blur, createCanvas);
102
+ // Value from minimum / value range, => [0, 1].
103
+ const templateAlpha = (value - min) / (max - min);
104
+ // Small values are not visible because globalAlpha < .001 cannot be read from imageData.
105
+ shadowCtx.globalAlpha = Math.max(templateAlpha, 0.001);
106
+ shadowCtx.drawImage(tpl, rectX, rectY);
107
+ }
108
+ return shadowCtx;
109
+ }
110
+
111
+ function colorize(
112
+ shadowCtx,
113
+ maxWidth: number,
114
+ maxHeight: number,
115
+ palette,
116
+ options: HeatmapRendererOptions,
117
+ ) {
118
+ const { minOpacity, opacity, maxOpacity, useGradientOpacity } = options;
119
+ const x = 0;
120
+ const y = 0;
121
+ const width = maxWidth;
122
+ const height = maxHeight;
123
+
124
+ const img = shadowCtx.getImageData(x, y, width, height);
125
+ const imgData = img.data;
126
+ const len = imgData.length;
127
+
128
+ for (let i = 3; i < len; i += 4) {
129
+ const alpha = imgData[i];
130
+ const offset = alpha * 4;
131
+
132
+ if (!offset) {
133
+ continue;
134
+ }
135
+
136
+ // Should be in [min, max], min >= 0.
137
+ const finalAlpha =
138
+ opacity || Math.max(0, Math.min(maxOpacity, Math.max(minOpacity, alpha)));
139
+ // Update rgba.
140
+ imgData[i - 3] = palette[offset];
141
+ imgData[i - 2] = palette[offset + 1];
142
+ imgData[i - 1] = palette[offset + 2];
143
+ imgData[i] = useGradientOpacity ? palette[offset + 3] : finalAlpha;
144
+ }
145
+
146
+ return img;
147
+ }
148
+
149
+ /**
150
+ * Render a heatmap with canvas.
151
+ * See [heatmap.js](https://github.com/pa7/heatmap.js/blob/master/src/renderer/canvas2d.js).
152
+ */
153
+ export function HeatmapRenderer(
154
+ width: number,
155
+ height: number,
156
+ min: number,
157
+ max: number,
158
+ data: HeatmapRendererData[],
159
+ options: HeatmapRendererOptions,
160
+ createCanvas: () => HTMLCanvasElement,
161
+ ) {
162
+ const opts: HeatmapRendererOptions = {
163
+ blur: 0.85,
164
+ minOpacity: 0,
165
+ opacity: 0.6,
166
+ maxOpacity: 1,
167
+ gradient: [
168
+ [0.25, 'rgb(0,0,255)'],
169
+ [0.55, 'rgb(0,255,0)'],
170
+ [0.85, 'yellow'],
171
+ [1.0, 'rgb(255,0,0)'],
172
+ ],
173
+ ...options,
174
+ };
175
+ opts.minOpacity *= 255;
176
+ opts.opacity *= 255;
177
+ opts.maxOpacity *= 255;
178
+
179
+ const shadowCanvas = newCanvas(createCanvas, width, height);
180
+ const shadowCtx = shadowCanvas.getContext('2d');
181
+
182
+ const palette = getColorPalette(opts.gradient, createCanvas);
183
+
184
+ shadowCtx.clearRect(0, 0, width, height);
185
+ drawAlpha(shadowCtx, min, max, data, opts, createCanvas);
186
+ const img = colorize(shadowCtx, width, height, palette, opts);
187
+
188
+ const canvas = newCanvas(createCanvas, width, height);
189
+ const ctx = canvas.getContext('2d');
190
+ ctx.putImageData(img, 0, 0);
191
+
192
+ return ctx;
193
+ }
@@ -0,0 +1,38 @@
1
+ export type HeatmapGradientArray = Array<[number, string]>;
2
+ export type HeatmapGradient = string | HeatmapGradientArray;
3
+
4
+ export type HeatmapRendererOptions = {
5
+ /**
6
+ * An gradient string that represents the gradient (syntax: number string [0,1] : color string).
7
+ */
8
+ gradient?: HeatmapGradient;
9
+ /**
10
+ * A global opacity for the whole heatmap, default = 0.6.
11
+ * This overrides maxOpacity and minOpacity if set!
12
+ */
13
+ opacity?: number;
14
+ /**
15
+ * The maximal opacity the highest value in the heatmap will have. (will be overridden if opacity set).
16
+ */
17
+ maxOpacity?: number;
18
+ /**
19
+ * The minimum opacity the lowest value in the heatmap will have (will be overridden if opacity set).
20
+ */
21
+ minOpacity?: number;
22
+ /**
23
+ * The blur factor that will be applied to all datapoints, default = 0.85.
24
+ * The higher the blur factor is, the smoother the gradients will be.
25
+ */
26
+ blur?: number;
27
+ /**
28
+ * Use gradient opacity.
29
+ */
30
+ useGradientOpacity?: boolean;
31
+ };
32
+
33
+ export type HeatmapRendererData = {
34
+ x: number;
35
+ y: number;
36
+ value: number;
37
+ radius: number;
38
+ };
@@ -2,6 +2,7 @@ import { Image as GImage } from '@antv/g';
2
2
  import { ShapeComponent as SC } from '../../runtime';
3
3
  import { applyStyle, getShapeTheme } from '../utils';
4
4
  import { select } from '../../utils/selection';
5
+ import { p } from '../../mark/utils';
5
6
 
6
7
  export type ImageOptions = Record<string, any>;
7
8
 
@@ -16,9 +17,14 @@ export const Image: SC<ImageOptions> = (options) => {
16
17
  defaultShape,
17
18
  );
18
19
  const { color = defaultColor, src = '', size = 32, transform = '' } = value;
19
- const { width = size, height = size } = style;
20
+ let { width = size, height = size } = style;
20
21
  const [[x0, y0]] = points;
21
22
 
23
+ // Support percentage width, height.
24
+ const [w, h] = coordinate.getSize();
25
+ width = typeof width === 'string' ? p(width) * w : width;
26
+ height = typeof height === 'string' ? p(height) * h : height;
27
+
22
28
  const x = x0 - Number(width) / 2;
23
29
  const y = y0 - Number(height) / 2;
24
30
 
@@ -26,12 +32,12 @@ export const Image: SC<ImageOptions> = (options) => {
26
32
  .call(applyStyle, shapeTheme)
27
33
  .style('x', x)
28
34
  .style('y', y)
29
- .style('width', size)
30
- .style('height', size)
31
35
  .style('img', src)
32
36
  .style('stroke', color)
33
37
  .style('transform', transform)
34
38
  .call(applyStyle, style)
39
+ .style('width', width)
40
+ .style('height', height)
35
41
  .node();
36
42
  };
37
43
  };
@@ -49,6 +49,7 @@ export { Label } from './label/label';
49
49
  export { Path } from './path/path';
50
50
  export { Hollow as HollowPath } from './path/hollow';
51
51
  export { Density } from './density/density';
52
+ export { Heatmap } from './heatmap/heatmap';
52
53
  export { Shape } from './shape/shape';
53
54
 
54
55
  export type { RectOptions } from './interval/rect';
@@ -96,6 +97,7 @@ export type { ImageOptions } from './image/image';
96
97
  export type { PolygonOptions } from './polygon/polygon';
97
98
  export type { BoxOptions } from './box/box';
98
99
  export type { ViolinOptions } from './box/violin';
100
+ export type { HeatmapOptions } from './heatmap/heatmap';
99
101
 
100
102
  export type { LineOptions as LineXYOptions } from './lineXY/line';
101
103
  export type { ConnectorOptions } from './connector/connector';
@@ -78,7 +78,8 @@ export type TooltipComponent =
78
78
  items?: TooltipItem[] | null | false;
79
79
  [key: string]: any;
80
80
  }
81
- | null;
81
+ | null
82
+ | false;
82
83
 
83
84
  export type TooltipTitle =
84
85
  | string
@@ -5,9 +5,16 @@ import { Transform } from './transform';
5
5
  import { Scale } from './scale';
6
6
  import { Data } from './data';
7
7
  import { LabelTransform } from './labelTransform';
8
- import { Literal2Object, Padding } from './utils';
9
- import { TitleComponent } from './component';
10
- import { Mark } from './mark';
8
+ import { Closeable, Literal2Object, Padding } from './utils';
9
+ import {
10
+ AxisComponent,
11
+ LegendComponent,
12
+ ScrollbarComponent,
13
+ SliderComponent,
14
+ TitleComponent,
15
+ TooltipComponent,
16
+ } from './component';
17
+ import { AtheisticChanelTypes, Mark, PositionChannelTypes } from './mark';
11
18
 
12
19
  export type Composition =
13
20
  | ViewComposition
@@ -58,16 +65,25 @@ export type ViewComposition = {
58
65
  coordinate?: Coordinate;
59
66
  interaction?: Literal2Object<Interaction>;
60
67
  transform?: Transform[];
61
- title?: string | TitleComponent;
62
68
  theme?: Theme;
63
69
  children?: Mark[];
64
70
  scale?: Record<string, Scale>;
65
71
  frame?: boolean;
66
72
  labelTransform?: LabelTransform[];
67
- // @todo
68
- axis?: Record<string, any>;
69
- // @todo
70
- legend?: Record<string, any>;
73
+ axis?: Closeable<
74
+ Partial<Record<PositionChannelTypes, Closeable<AxisComponent>>>
75
+ >;
76
+ legend?: Closeable<
77
+ Partial<Record<AtheisticChanelTypes, Closeable<LegendComponent>>>
78
+ >;
79
+ tooltip?: TooltipComponent;
80
+ slider?: Closeable<
81
+ Partial<Record<PositionChannelTypes, Closeable<SliderComponent>>>
82
+ >;
83
+ scrollbar?: Closeable<
84
+ Partial<Record<PositionChannelTypes, Closeable<ScrollbarComponent>>>
85
+ >;
86
+ title?: string | TitleComponent;
71
87
  // @todo
72
88
  style?: Record<string, any>;
73
89
  clip?: boolean;
package/src/spec/mark.ts CHANGED
@@ -81,6 +81,7 @@ export type MarkTypes =
81
81
  | 'wordCloud'
82
82
  | 'gauge'
83
83
  | 'density'
84
+ | 'heatmap'
84
85
  | MarkComponent;
85
86
 
86
87
  export type ChannelTypes =
@@ -373,5 +374,6 @@ export type GaugeMark = BaseMark<
373
374
  >;
374
375
 
375
376
  export type DensityMark = BaseMark<'density', ChannelTypes | 'series'>;
377
+ export type HeatmapMark = BaseMark<'heatmap'>;
376
378
 
377
379
  export type CustomMark = BaseMark<MarkComponent, ChannelTypes>;
@@ -41,6 +41,7 @@ import {
41
41
  WordCloud as WordCloudGeometry,
42
42
  Density as DensityGeometry,
43
43
  Gauge,
44
+ Heatmap,
44
45
  } from '../mark';
45
46
  import { Category10, Category20 } from '../palette';
46
47
  import {
@@ -112,6 +113,7 @@ import {
112
113
  HollowPath,
113
114
  Density as DensityShape,
114
115
  Shape as CustomShape,
116
+ Heatmap as HeatmapShape,
115
117
  } from '../shape';
116
118
  import { Classic, ClassicDark, Academy } from '../theme';
117
119
  import {
@@ -356,6 +358,7 @@ export function createLibrary(): G2Library {
356
358
  'mark.tree': TreeGeometry,
357
359
  'mark.wordCloud': WordCloudGeometry,
358
360
  'mark.density': DensityGeometry,
361
+ 'mark.heatmap': Heatmap,
359
362
  'palette.category10': Category10,
360
363
  'palette.category20': Category20,
361
364
  'scale.linear': Linear,
@@ -432,6 +435,7 @@ export function createLibrary(): G2Library {
432
435
  'shape.path.path': PathShape,
433
436
  'shape.path.hollow': HollowPath,
434
437
  'shape.density.density': DensityShape,
438
+ 'shape.heatmap.heatmap': HeatmapShape,
435
439
  'theme.classic': Classic,
436
440
  'theme.classicDark': ClassicDark,
437
441
  'theme.academy': Academy,
@@ -0,0 +1,25 @@
1
+ import flru from 'flru';
2
+
3
+ const cache = flru(3);
4
+ /**
5
+ * A decorator to return new function with LRU cache.
6
+ */
7
+ export function lru<T = any, V = any>(
8
+ fn: (...args: T[]) => V,
9
+ keyFn: (...args: T[]) => string = (...args) => `${args[0]}`,
10
+ maxSize = 16,
11
+ ) {
12
+ const cache = flru(maxSize);
13
+
14
+ return (...args) => {
15
+ const key = keyFn(...args);
16
+ let v = cache.get(key);
17
+
18
+ if (cache.has(key)) return cache.get(key);
19
+
20
+ v = fn(...args);
21
+ cache.set(key, v);
22
+
23
+ return v;
24
+ };
25
+ }