-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs(legend): 图例文档 * refactor(box): 使用 geometry adaptor 处理 box,优化 tooltip & 增加单测 * docs(box): 箱线图增加设置字段别名的 demo
- Loading branch information
Showing
7 changed files
with
166 additions
and
103 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 |
---|---|---|
@@ -1,51 +1,88 @@ | ||
import { Box } from '../../../../src'; | ||
import { boxData, groupBoxData } from '../../../data/box'; | ||
import { createDiv } from '../../../utils/dom'; | ||
import { createDiv, removeDom } from '../../../utils/dom'; | ||
|
||
describe('box tooltip', () => { | ||
it('x*y and tooltip', () => { | ||
const box = new Box(createDiv('box tooltip'), { | ||
width: 400, | ||
height: 500, | ||
data: boxData, | ||
xField: 'x', | ||
yField: ['low', 'q1', 'median', 'q3', 'high'], | ||
tooltip: { | ||
title: 'hello world', | ||
}, | ||
}); | ||
const div = createDiv(''); | ||
const box = new Box(div, { | ||
width: 400, | ||
height: 500, | ||
data: boxData, | ||
xField: 'x', | ||
yField: ['low', 'q1', 'median', 'q3', 'high'], | ||
tooltip: { | ||
title: 'hello world', | ||
}, | ||
}); | ||
|
||
box.render(); | ||
box.render(); | ||
|
||
it('tooltip: custom title', () => { | ||
// @ts-ignore | ||
expect(box.chart.options.tooltip.title).toBe('hello world'); | ||
const bbox = box.chart.geometries[0].elements[0].getBBox(); | ||
|
||
box.chart.showTooltip({ x: bbox.width / 2 + bbox.x, y: bbox.height / 2 + bbox.y }); | ||
expect(div.querySelectorAll('.g2-tooltip-list-item').length).toBe(5); | ||
box.chart.hideTooltip(); | ||
}); | ||
|
||
it('tooltip: fields', () => { | ||
box.update({ tooltip: { fields: ['low', 'q1', 'median'] } }); | ||
const bbox = box.chart.geometries[0].elements[0].getBBox(); | ||
|
||
box.chart.showTooltip({ x: bbox.width / 2 + bbox.x, y: bbox.height / 2 + bbox.y }); | ||
expect(div.querySelectorAll('.g2-tooltip-list-item').length).toBe(3); | ||
box.chart.hideTooltip(); | ||
}); | ||
|
||
it('tooltip: fields & customContent', () => { | ||
box.update({ | ||
...box.options, | ||
tooltip: false, | ||
tooltip: { | ||
fields: ['low', 'q1', 'median'], | ||
customContent: (text, items) => | ||
`<div>${items.map((item, idx) => `<div class="custom-tooltip-item-content">${idx}</div>`)}<div>`, | ||
}, | ||
}); | ||
// @ts-ignore | ||
expect(box.chart.options.tooltip).toBe(false); | ||
expect(box.chart.getComponents().find((co) => co.type === 'tooltip')).toBe(undefined); | ||
|
||
box.destroy(); | ||
const bbox = box.chart.geometries[0].elements[0].getBBox(); | ||
box.chart.showTooltip({ x: bbox.width / 2 + bbox.x, y: bbox.height / 2 + bbox.y }); | ||
expect(div.getElementsByClassName('custom-tooltip-item-content').length).toBe(3); | ||
|
||
// 设置hide | ||
box.chart.hideTooltip(); | ||
}); | ||
|
||
it('default toolip', () => { | ||
const box = new Box(createDiv('default tooltip'), { | ||
width: 400, | ||
height: 500, | ||
it('tooltip: groupField', () => { | ||
box.update({ | ||
data: groupBoxData, | ||
xField: 'type', | ||
yField: '_bin', | ||
groupField: 'Species', | ||
tooltip: { fields: undefined, customContent: undefined }, | ||
}); | ||
|
||
box.render(); | ||
// @ts-ignore | ||
expect(box.chart.options.tooltip.shared).toBe(true); | ||
// @ts-ignore 箱线图 默认不展示 crosshairs(ugly) | ||
expect(box.chart.options.tooltip.showCrosshairs).toBeUndefined(); | ||
|
||
const bbox = box.chart.geometries[0].elements[0].getBBox(); | ||
box.chart.showTooltip({ x: bbox.width / 2 + bbox.x, y: bbox.height / 2 + bbox.y }); | ||
|
||
expect(div.querySelectorAll('.g2-tooltip-list-item').length).toBe(3); | ||
expect((div.querySelector('.g2-tooltip-name') as HTMLElement).innerText).toBe('I. setosa'); | ||
box.chart.hideTooltip(); | ||
}); | ||
|
||
it('tooltip: false', () => { | ||
box.update({ tooltip: false }); | ||
// @ts-ignore | ||
expect(box.chart.options.tooltip.showCrosshairs).toBe(true); | ||
expect(box.chart.options.tooltip).toBe(false); | ||
expect(box.chart.getComponents().find((co) => co.type === 'tooltip')).toBe(undefined); | ||
}); | ||
|
||
afterAll(() => { | ||
box.destroy(); | ||
removeDom(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,48 @@ | ||
import { Box } from '@antv/g2plot'; | ||
|
||
const data = [ | ||
{ x: 'Oceania', low: 1, q1: 9, median: 16, q3: 22, high: 24 }, | ||
{ x: 'East Europe', low: 1, q1: 5, median: 8, q3: 12, high: 16 }, | ||
{ x: 'Australia', low: 1, q1: 8, median: 12, q3: 19, high: 26 }, | ||
{ x: 'South America', low: 2, q1: 8, median: 12, q3: 21, high: 28 }, | ||
{ x: 'North Africa', low: 1, q1: 8, median: 14, q3: 18, high: 24 }, | ||
{ x: 'North America', low: 3, q1: 10, median: 17, q3: 28, high: 30 }, | ||
{ x: 'West Europe', low: 1, q1: 7, median: 10, q3: 17, high: 22 }, | ||
{ x: 'West Africa', low: 1, q1: 6, median: 8, q3: 13, high: 16 }, | ||
]; | ||
|
||
const boxPlot = new Box('container', { | ||
width: 400, | ||
height: 500, | ||
data: data, | ||
xField: 'x', | ||
yField: ['low', 'q1', 'median', 'q3', 'high'], | ||
meta: { | ||
low: { | ||
alias: '最低值', | ||
}, | ||
q1: { | ||
alias: '下四分位数', | ||
}, | ||
median: { | ||
alias: '最低值', | ||
}, | ||
q3: { | ||
alias: '上四分位数', | ||
}, | ||
high: { | ||
alias: '最高值', | ||
}, | ||
}, | ||
tooltip: { | ||
fields: ['high', 'q3', 'median', 'q1', 'low'], | ||
}, | ||
boxStyle: { | ||
stroke: '#545454', | ||
fill: '#1890FF', | ||
fillOpacity: 0.3, | ||
}, | ||
animation: false, | ||
}); | ||
|
||
boxPlot.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
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