-
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.
feat: add venn chart demo, tests (#5129)
* docs: add venn demo, tests * chore: build success * fix: sort data for occlusion
- Loading branch information
Showing
24 changed files
with
1,417 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,50 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function vennBasic(): G2Spec { | ||
return { | ||
type: 'view', | ||
width: 640, | ||
height: 480, | ||
children: [ | ||
{ | ||
type: 'path', | ||
data: { | ||
type: 'inline', | ||
value: [ | ||
{ sets: ['A'], value: 12, label: 'A' }, | ||
{ sets: ['B'], value: 12, label: 'B' }, | ||
{ sets: ['C'], value: 12, label: 'C' }, | ||
{ sets: ['A', 'B'], value: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], value: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], value: 2, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], value: 1 }, | ||
], | ||
transform: [ | ||
{ | ||
type: 'venn', | ||
size: 'value', | ||
}, | ||
], | ||
}, | ||
encode: { | ||
d: 'path', | ||
color: 'key', | ||
}, | ||
style: { | ||
fillOpacity: 0.8, | ||
}, | ||
labels: [ | ||
{ | ||
text: 'key', | ||
position: 'inside', | ||
style: { | ||
formatter: (_, datum) => `${datum.key}: ${datum.size}`, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
vennBasic.maxError = 100; |
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 { G2Spec } from '../../../src'; | ||
|
||
export function vennHollow(): G2Spec { | ||
return { | ||
type: 'view', | ||
width: 640, | ||
height: 480, | ||
children: [ | ||
{ | ||
type: 'path', | ||
data: { | ||
type: 'inline', | ||
value: [ | ||
{ sets: ['A'], value: 12, label: 'A' }, | ||
{ sets: ['B'], value: 12, label: 'B' }, | ||
{ sets: ['C'], value: 12, label: 'C' }, | ||
{ sets: ['A', 'B'], value: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], value: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], value: 2, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], value: 1 }, | ||
], | ||
transform: [ | ||
{ | ||
type: 'venn', | ||
size: 'value', | ||
padding: 10, | ||
}, | ||
], | ||
}, | ||
encode: { | ||
d: 'path', | ||
color: 'key', | ||
shape: 'hollow', | ||
}, | ||
style: { | ||
fillOpacity: 0.8, | ||
lineWidth: 6, | ||
}, | ||
labels: [ | ||
{ | ||
text: 'key', | ||
position: 'inside', | ||
style: { | ||
formatter: (_, datum) => `${datum.key}: ${datum.size}`, | ||
fill: '#000', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
vennHollow.maxError = 100; |
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,24 @@ | ||
import { Venn } from '../../../src/data/venn'; | ||
|
||
describe('Venn', () => { | ||
it('Venn({...}) returns function return layout venn data', async () => { | ||
const data = [ | ||
{ sets: ['A'], size: 102, label: 'A' }, | ||
{ sets: ['B'], size: 12, label: 'B' }, | ||
{ sets: ['C'], size: 12, label: 'C' }, | ||
{ sets: ['A', 'B'], size: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], size: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], size: 2, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], size: 1 }, | ||
]; | ||
const v = Venn({ | ||
sets: 'sets', | ||
size: 'size', | ||
as: ['_key', '_path'], | ||
}); | ||
const layout = await v(data); | ||
expect(layout.length).toBe(7); | ||
expect(layout[0]._path).toBeInstanceOf(Function); | ||
expect(layout[6]._key).toBe('A&B&C'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"title": { | ||
"zh": "中文分类", | ||
"en": "Category" | ||
}, | ||
"demos": [ | ||
{ | ||
"filename": "venn.ts", | ||
"title": { | ||
"zh": "韦恩图", | ||
"en": "Venn Chart" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*IZT9TJ3eVpwAAAAAAAAAAAAADmJ7AQ/original" | ||
}, | ||
{ | ||
"filename": "venn-hollow.ts", | ||
"title": { | ||
"zh": "空心韦恩图", | ||
"en": "Hollow Venn" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*5XyrQppBM9YAAAAAAAAAAAAADmJ7AQ/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,42 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
chart | ||
.path() | ||
.data({ | ||
type: 'inline', | ||
value: [ | ||
{ sets: ['A'], size: 15, label: 'A' }, | ||
{ sets: ['B'], size: 12, label: 'B' }, | ||
{ sets: ['C'], size: 10, label: 'C' }, | ||
{ sets: ['A', 'B'], size: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], size: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], size: 1, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], size: 1 }, | ||
], | ||
transform: [ | ||
{ | ||
type: 'venn', | ||
}, | ||
], | ||
}) | ||
.encode('d', 'path') | ||
.encode('color', 'key') | ||
.encode('shape', 'hollow') | ||
.label({ | ||
position: 'inside', | ||
text: (d) => d.label || '', | ||
style: { | ||
fill: '#000', | ||
}, | ||
}) | ||
.style('opacity', 0.6) | ||
.style('lineWidth', 8) | ||
.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,42 @@ | ||
/** | ||
* A recreation of this demo: http://benfred.github.io/venn.js/examples/intersection_tooltip.html | ||
*/ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
paddingLeft: 50, | ||
paddingRight: 50, | ||
}); | ||
|
||
chart | ||
.path() | ||
.data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/lastfm.json', | ||
transform: [ | ||
{ | ||
type: 'venn', | ||
padding: 8, | ||
sets: 'sets', | ||
size: 'size', | ||
as: ['key', 'path'], | ||
}, | ||
], | ||
}) | ||
.encode('d', 'path') | ||
.encode('color', 'key') | ||
.label({ | ||
position: 'inside', | ||
text: (d) => d.label || '', | ||
transform: [{ type: 'contrastReverse' }], | ||
}) | ||
.style('opacity', (d) => (d.sets.length > 1 ? 0.001 : 0.5)) | ||
.state('inactive', { opacity: 0.2 }) | ||
.state('active', { opacity: 0.8 }) | ||
.interaction('elementHighlight', true) | ||
.legend(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,4 @@ | ||
--- | ||
title: Venn | ||
order: 21 | ||
--- |
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: 21 | ||
--- |
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
Oops, something went wrong.