-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gauge): 仪表盘添加tooltip 文档 单测 和demo
- Loading branch information
1 parent
e80e185
commit 4bb3170
Showing
5 changed files
with
143 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Gauge } from '../../../../src'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('gauge', () => { | ||
it('default tooltip', () => { | ||
const gauge = new Gauge(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
percent: 0.75, | ||
}); | ||
|
||
gauge.render(); | ||
// @ts-ignore | ||
expect(gauge.chart.options.tooltip).toBe(false); | ||
expect(gauge.chart.getComponents().find((co) => co.type === 'tooltip')).toBe(undefined); | ||
|
||
gauge.update({ | ||
tooltip: {}, | ||
}); | ||
// @ts-ignore | ||
expect(gauge.chart.options.tooltip).toMatchObject({ | ||
showMarkers: false, | ||
showTitle: false, | ||
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>', | ||
domStyles: { | ||
'g2-tooltip': { | ||
padding: '4px 8px', | ||
fontSize: '10px', | ||
}, | ||
}, | ||
}); | ||
|
||
gauge.destroy(); | ||
}); | ||
|
||
it('custom tooltip', () => { | ||
const customContent = (x, data) => { | ||
return `${(Number(data?.[0]?.value || 0) * 100).toFixed(2)}%`; | ||
}; | ||
|
||
const gauge = new Gauge(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
percent: 0.75, | ||
tooltip: { | ||
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list">2131231</div></div>', | ||
domStyles: { | ||
'g2-tooltip': { | ||
padding: '40px', | ||
fontSize: '40px', | ||
}, | ||
}, | ||
customContent, | ||
}, | ||
}); | ||
|
||
gauge.render(); | ||
|
||
// @ts-ignore | ||
expect(gauge.chart.options.tooltip).toMatchObject({ | ||
showMarkers: false, | ||
showTitle: false, | ||
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list">2131231</div></div>', | ||
domStyles: { | ||
'g2-tooltip': { | ||
padding: '40px', | ||
fontSize: '40px', | ||
}, | ||
}, | ||
customContent, | ||
}); | ||
|
||
gauge.destroy(); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -119,3 +119,6 @@ order: 5 | |
|
||
`markdown:docs/common/statistic.zh.md` | ||
|
||
#### tooltip | ||
|
||
`markdown:docs/common/tooltip.zh.md` |
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,53 @@ | ||
import { Gauge } from '@antv/g2plot'; | ||
|
||
const gauge = new Gauge('container', { | ||
tooltip: { | ||
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>', | ||
domStyles: { | ||
'g2-tooltip': { | ||
padding: '4px 8px', | ||
fontSize: '10px', | ||
}, | ||
}, | ||
customContent: (x, data) => { | ||
return `${(Number(data?.[0]?.value || 0) * 100).toFixed(2)}%`; | ||
}, | ||
}, | ||
percent: 0.75, | ||
range: { | ||
color: '#30BF78', | ||
}, | ||
indicator: { | ||
pointer: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
}, | ||
}, | ||
pin: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
}, | ||
}, | ||
}, | ||
axis: { | ||
label: { | ||
formatter(v) { | ||
return Number(v) * 100; | ||
}, | ||
}, | ||
subTickLine: { | ||
count: 3, | ||
}, | ||
}, | ||
statistic: { | ||
content: { | ||
formatter: ({ percent }) => `Rate: ${(percent * 100).toFixed(0)}%`, | ||
style: { | ||
color: 'rgba(0,0,0,0.65)', | ||
fontSize: 48, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
gauge.render(); |