@antv/g2 5.0.10 → 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.
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +1 -0
- package/esm/api/chart.js +5 -1
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/geoPath.d.ts +1 -0
- package/esm/api/composition/geoPath.js +1 -0
- package/esm/api/composition/geoPath.js.map +1 -1
- package/esm/api/mark/index.d.ts +3 -1
- package/esm/api/mark/index.js +2 -1
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +7 -1
- package/esm/api/mark/mark.js +9 -0
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/node.d.ts +1 -0
- package/esm/api/node.js +5 -1
- package/esm/api/node.js.map +1 -1
- package/esm/api/utils.d.ts +1 -1
- package/esm/api/utils.js +10 -6
- package/esm/api/utils.js.map +1 -1
- package/esm/geo/geoPath.js +2 -1
- package/esm/geo/geoPath.js.map +1 -1
- package/esm/interaction/event.js +5 -2
- package/esm/interaction/event.js.map +1 -1
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/heatmap.d.ts +7 -0
- package/esm/mark/heatmap.js +36 -0
- package/esm/mark/heatmap.js.map +1 -0
- package/esm/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/line.js +1 -1
- package/esm/mark/line.js.map +1 -1
- package/esm/mark/text.js +0 -2
- package/esm/mark/text.js.map +1 -1
- package/esm/mark/utils.d.ts +1 -0
- package/esm/mark/utils.js +1 -1
- package/esm/mark/utils.js.map +1 -1
- package/esm/runtime/plot.js +12 -10
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.d.ts +2 -2
- package/esm/runtime/render.js +7 -3
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/scale.js +11 -9
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/types/component.d.ts +2 -2
- package/esm/runtime/types/options.d.ts +6 -0
- package/esm/shape/heatmap/heatmap.d.ts +4 -0
- package/esm/shape/heatmap/heatmap.js +70 -0
- package/esm/shape/heatmap/heatmap.js.map +1 -0
- package/esm/shape/heatmap/renderer/gradient.d.ts +5 -0
- package/esm/shape/heatmap/renderer/gradient.js +13 -0
- package/esm/shape/heatmap/renderer/gradient.js.map +1 -0
- package/esm/shape/heatmap/renderer/index.d.ts +6 -0
- package/esm/shape/heatmap/renderer/index.js +122 -0
- package/esm/shape/heatmap/renderer/index.js.map +1 -0
- package/esm/shape/heatmap/renderer/types.d.ts +36 -0
- package/esm/shape/heatmap/renderer/types.js +2 -0
- package/esm/shape/heatmap/renderer/types.js.map +1 -0
- package/esm/shape/image/image.js +8 -3
- package/esm/shape/image/image.js.map +1 -1
- package/esm/shape/index.d.ts +2 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/spec/component.d.ts +1 -1
- package/esm/spec/composition.d.ts +9 -6
- package/esm/spec/mark.d.ts +2 -1
- package/esm/stdlib/index.js +3 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/utils/lru.d.ts +4 -0
- package/esm/utils/lru.js +18 -0
- package/esm/utils/lru.js.map +1 -0
- package/lib/api/chart.d.ts +1 -0
- package/lib/api/chart.js +5 -1
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/geoPath.d.ts +1 -0
- package/lib/api/composition/geoPath.js +1 -0
- package/lib/api/composition/geoPath.js.map +1 -1
- package/lib/api/mark/index.d.ts +3 -1
- package/lib/api/mark/index.js +1 -0
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +7 -1
- package/lib/api/mark/mark.js +10 -1
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/node.d.ts +1 -0
- package/lib/api/node.js +5 -1
- package/lib/api/node.js.map +1 -1
- package/lib/api/utils.d.ts +1 -1
- package/lib/api/utils.js +10 -6
- package/lib/api/utils.js.map +1 -1
- package/lib/geo/geoPath.js +2 -1
- package/lib/geo/geoPath.js.map +1 -1
- package/lib/interaction/event.js +5 -2
- package/lib/interaction/event.js.map +1 -1
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/heatmap.d.ts +7 -0
- package/lib/mark/heatmap.js +40 -0
- package/lib/mark/heatmap.js.map +1 -0
- package/lib/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/line.js +1 -1
- package/lib/mark/line.js.map +1 -1
- package/lib/mark/text.js +0 -2
- package/lib/mark/text.js.map +1 -1
- package/lib/mark/utils.d.ts +1 -0
- package/lib/mark/utils.js +2 -1
- package/lib/mark/utils.js.map +1 -1
- package/lib/runtime/plot.js +12 -10
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.d.ts +2 -2
- package/lib/runtime/render.js +7 -3
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/scale.js +11 -9
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/types/component.d.ts +2 -2
- package/lib/runtime/types/options.d.ts +6 -0
- package/lib/shape/heatmap/heatmap.d.ts +4 -0
- package/lib/shape/heatmap/heatmap.js +74 -0
- package/lib/shape/heatmap/heatmap.js.map +1 -0
- package/lib/shape/heatmap/renderer/gradient.d.ts +5 -0
- package/lib/shape/heatmap/renderer/gradient.js +17 -0
- package/lib/shape/heatmap/renderer/gradient.js.map +1 -0
- package/lib/shape/heatmap/renderer/index.d.ts +6 -0
- package/lib/shape/heatmap/renderer/index.js +126 -0
- package/lib/shape/heatmap/renderer/index.js.map +1 -0
- package/lib/shape/heatmap/renderer/types.d.ts +36 -0
- package/lib/shape/heatmap/renderer/types.js +3 -0
- package/lib/shape/heatmap/renderer/types.js.map +1 -0
- package/lib/shape/image/image.js +8 -3
- package/lib/shape/image/image.js.map +1 -1
- package/lib/shape/index.d.ts +2 -0
- package/lib/shape/index.js +3 -1
- package/lib/shape/index.js.map +1 -1
- package/lib/spec/component.d.ts +1 -1
- package/lib/spec/composition.d.ts +9 -6
- package/lib/spec/mark.d.ts +2 -1
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/utils/lru.d.ts +4 -0
- package/lib/utils/lru.js +25 -0
- package/lib/utils/lru.js.map +1 -0
- package/package.json +4 -1
- package/src/api/chart.ts +4 -1
- package/src/api/composition/geoPath.ts +2 -0
- package/src/api/mark/index.ts +3 -0
- package/src/api/mark/mark.ts +12 -0
- package/src/api/node.ts +6 -1
- package/src/api/utils.ts +17 -6
- package/src/geo/geoPath.ts +3 -1
- package/src/interaction/event.ts +7 -2
- package/src/mark/area.ts +1 -1
- package/src/mark/heatmap.ts +48 -0
- package/src/mark/index.ts +2 -0
- package/src/mark/line.ts +1 -1
- package/src/mark/text.ts +0 -1
- package/src/mark/utils.ts +1 -1
- package/src/runtime/plot.ts +30 -13
- package/src/runtime/render.ts +9 -7
- package/src/runtime/scale.ts +14 -9
- package/src/runtime/types/component.ts +2 -1
- package/src/runtime/types/options.ts +6 -0
- package/src/shape/heatmap/heatmap.ts +85 -0
- package/src/shape/heatmap/renderer/gradient.ts +16 -0
- package/src/shape/heatmap/renderer/index.ts +193 -0
- package/src/shape/heatmap/renderer/types.ts +38 -0
- package/src/shape/image/image.ts +9 -3
- package/src/shape/index.ts +2 -0
- package/src/spec/component.ts +2 -1
- package/src/spec/composition.ts +24 -8
- package/src/spec/mark.ts +2 -0
- package/src/stdlib/index.ts +4 -0
- 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
|
+
};
|
package/src/shape/image/image.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
};
|
package/src/shape/index.ts
CHANGED
|
@@ -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';
|
package/src/spec/component.ts
CHANGED
package/src/spec/composition.ts
CHANGED
|
@@ -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 {
|
|
10
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
legend?:
|
|
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>;
|
package/src/stdlib/index.ts
CHANGED
|
@@ -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,
|
package/src/utils/lru.ts
ADDED
|
@@ -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
|
+
}
|