-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
221 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import DataSet from '@antv/data-set'; | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
chart.data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/diamond.json', | ||
}); | ||
|
||
chart.scale('x', { nice: true, domainMin: -0.5 }); | ||
chart.scale('y', { nice: true, domainMin: -2000 }); | ||
chart.scale('color', { nice: true }); | ||
|
||
chart | ||
.heatmap() | ||
.data({ | ||
transform: [ | ||
{ | ||
type: 'custom', | ||
callback: (data) => { | ||
const dv = new DataSet.View().source(data); | ||
dv.transform({ | ||
type: 'kernel-smooth.density', | ||
fields: ['carat', 'price'], | ||
as: ['carat', 'price', 'density'], | ||
}); | ||
return dv.rows; | ||
}, | ||
}, | ||
], | ||
}) | ||
.encode('x', 'carat') | ||
.encode('y', 'price') | ||
.encode('color', 'density') | ||
.style({ | ||
opacity: 0.3, | ||
gradient: { | ||
'0': 'white', | ||
'0.2': 'blue', | ||
'0.4': 'cyan', | ||
'0.6': 'lime', | ||
'0.8': 'yellow', | ||
'0.9': 'red', | ||
}, | ||
}); | ||
|
||
chart.point().encode('x', 'carat').encode('y', 'price'); | ||
|
||
chart.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
padding: 0, | ||
}); | ||
|
||
chart.axis(false); | ||
|
||
chart | ||
.image() | ||
.data([0]) | ||
.encode( | ||
'src', | ||
'https://gw.alipayobjects.com/zos/rmsportal/NeUTMwKtPcPxIFNTWZOZ.png', | ||
) | ||
.style('x', '50%') | ||
.style('y', '50%') | ||
.style('width', '100%') | ||
.style('height', '100%') | ||
.tooltip(false); | ||
|
||
chart | ||
.heatmap() | ||
.data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/heatmap.json', | ||
}) | ||
.encode('x', 'g') | ||
.encode('y', 'l') | ||
.encode('color', 'tmp') | ||
.style('opacity', 0) | ||
.tooltip(false); | ||
|
||
chart.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"title": { | ||
"zh": "中文分类", | ||
"en": "Category" | ||
}, | ||
"demos": [ | ||
{ | ||
"filename": "heatmap.ts", | ||
"title": { | ||
"zh": "密度热力图", | ||
"en": "Heatmap" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*ze7gSYylw_QAAAAAAAAAAAAADmJ7AQ/original" | ||
}, | ||
{ | ||
"filename": "heatmap-density.ts", | ||
"title": { | ||
"zh": "散点分布热力", | ||
"en": "Heatmap Density" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*0AfVQpGgcsoAAAAAAAAAAAAADmJ7AQ/original" | ||
}, | ||
{ | ||
"filename": "mouse-heatmap.ts", | ||
"title": { | ||
"zh": "鼠标热力图", | ||
"en": "Mouse Heatmap" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*kC58R7TEdd0AAAAAAAAAAAAADmJ7AQ/original" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Chart } from '@antv/g2'; | ||
import { throttle } from 'lodash'; | ||
|
||
const data = {}; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
width: 640, | ||
height: 480, | ||
padding: 0, | ||
}); | ||
|
||
chart.style({ | ||
viewFill: '#4e79a7', | ||
}); | ||
|
||
chart.data([]); | ||
chart.axis(false); | ||
|
||
chart | ||
.heatmap() | ||
.encode('x', 'x') | ||
.encode('y', 'y') | ||
.encode('color', 'v') | ||
.scale('x', { domain: [0, 640] }) | ||
.scale('y', { domain: [0, 480], range: [0, 1] }) | ||
.style('opacity', 0); | ||
|
||
chart.render(); | ||
|
||
chart.on( | ||
'plot:pointermove', | ||
throttle((e) => { | ||
const { x, y } = e; | ||
|
||
const kx = Math.floor(x - (x % 8)); | ||
const ky = Math.floor(y - (y % 8)); | ||
|
||
if (!data[kx]) data[kx] = {}; | ||
if (!data[kx][ky]) data[kx][ky] = 0; | ||
|
||
data[kx][ky] += 1; | ||
|
||
const d = transform(data); | ||
|
||
chart.changeData(d); | ||
}), | ||
); | ||
|
||
function transform(dataMap) { | ||
const arr = []; | ||
Object.keys(dataMap).forEach((x) => { | ||
Object.keys(dataMap[x]).forEach((y) => { | ||
arr.push({ x, y, v: dataMap[x][y] }); | ||
}); | ||
}); | ||
return arr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Heatmap | ||
order: 20 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: 热力图 | ||
order: 20 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters