-
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: html label supported * chore: fix ci * chore: update screenshot * docs: add 4 examples for label * docs: update label document
- Loading branch information
Showing
20 changed files
with
324 additions
and
20 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.
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,41 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function alphabetIntervalHtmlLabel(): G2Spec { | ||
return { | ||
type: 'interval', | ||
transform: [{ type: 'sortX', by: 'y', reverse: true }], | ||
data: { | ||
type: 'fetch', | ||
value: 'data/alphabet.csv', | ||
}, | ||
axis: { | ||
y: { labelFormatter: '.0%' }, | ||
}, | ||
encode: { | ||
x: 'letter', | ||
y: 'frequency', | ||
color: 'steelblue', | ||
}, | ||
labels: [ | ||
{ | ||
text: 'frequency', | ||
transform: [ | ||
{ | ||
type: 'overlapHide', | ||
}, | ||
], | ||
className: 'alphabet-labels', | ||
render: ( | ||
_, | ||
datum, | ||
) => `<div style="left:-50%;top:-16px;position:relative;font-size:12px;"> | ||
<span style="color: blue">${ | ||
datum.letter | ||
}</span>:<span style="color: black">${datum.frequency.toFixed( | ||
2, | ||
)}</span> | ||
</div>`, | ||
}, | ||
], | ||
}; | ||
} |
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,32 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
chart | ||
.interval() | ||
.data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/alphabet.json', | ||
}) | ||
.encode('x', 'letter') | ||
.encode('y', 'frequency') | ||
.encode('color', 'letter') | ||
.label({ | ||
text: 'frequency', | ||
position: 'inside', | ||
formatter: '.0%', | ||
fill: '#000', | ||
transform: [ | ||
{ | ||
type: 'contrastReverse', | ||
threshold: 21, | ||
palette: ['#000', '#fff'], // Use full color string to avoid screenshot error. | ||
}, | ||
], | ||
}); | ||
|
||
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,39 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
const data = [ | ||
{ repo: 'G', star: 918 }, | ||
{ repo: 'G2', star: 11688 }, | ||
{ repo: 'G6', star: 10045 }, | ||
{ repo: 'L7', star: 3125 }, | ||
{ repo: 'F2', star: 7820 }, | ||
{ repo: 'S2', star: 1231 }, | ||
{ repo: 'X6', star: 4755 }, | ||
]; | ||
|
||
chart | ||
.interval() | ||
.data(data) | ||
.encode('x', 'repo') | ||
.encode('y', 'star') | ||
.encode('color', 'repo') | ||
.label({ | ||
text: 'star', | ||
render: (text, datum) => { | ||
return ` | ||
<div style="left:-50%;top:-20px;position:relative;font-size:14px;"> | ||
<span>${datum.repo}</span> | ||
: | ||
<a href="https://github.com/antvis/${datum.repo}" target="_blank">${datum.star}</a> | ||
</div> | ||
`; | ||
}, | ||
}) | ||
.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,40 @@ | ||
{ | ||
"title": { | ||
"zh": "中文分类", | ||
"en": "Category" | ||
}, | ||
"demos": [ | ||
{ | ||
"filename": "overlapHide.ts", | ||
"title": { | ||
"zh": "数据标签碰撞隐藏", | ||
"en": "Overlap Hide" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*clZ2SbxuHloAAAAAAAAAAAAADmJ7AQ/original" | ||
}, | ||
{ | ||
"filename": "overflowHide.ts", | ||
"title": { | ||
"zh": "数据标签超出隐藏", | ||
"en": "Overflow Hide" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*EMy1RqEBmm4AAAAAAAAAAAAADmJ7AQ/original" | ||
}, | ||
{ | ||
"filename": "contrastReverse.ts", | ||
"title": { | ||
"zh": "数据标签颜色反转", | ||
"en": "Contrast Reverse" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*CUyIT4Bxx9wAAAAAAAAAAAAADmJ7AQ/original" | ||
}, | ||
{ | ||
"filename": "htmlLabel.ts", | ||
"title": { | ||
"zh": "HTML 标签", | ||
"en": "HTML Label" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*rUexRKH7czsAAAAAAAAAAAAADmJ7AQ/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,27 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
width: 800, | ||
autoFit: false, | ||
}); | ||
|
||
chart | ||
.interval() | ||
.data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/alphabet.json', | ||
}) | ||
.encode('x', 'letter') | ||
.encode('y', 'frequency') | ||
.encode('color', 'steelblue') | ||
.axis('y', { labelFormatter: '.0%' }) | ||
.label({ | ||
text: 'frequency', | ||
position: 'inside', | ||
formatter: '.0%', | ||
transform: [{ type: 'overflowHide' }], | ||
}); | ||
|
||
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,26 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
chart | ||
.line() | ||
.data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/aapl.json', | ||
}) | ||
.encode('x', (d) => new Date(d.date)) | ||
.encode('y', 'close') | ||
.label({ | ||
text: 'close', | ||
transform: [ | ||
{ | ||
type: 'overlapHide', | ||
}, | ||
], | ||
}); | ||
|
||
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: Label | ||
order: 3 | ||
--- |
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: 3 | ||
--- |
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.