-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: violin #2593
Merged
feat: violin #2593
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
82ad1ea
feat(violin): 添加小提琴图 (#2569)
YiSiWang 802f994
fix(violin): 修复小提琴图轴重复
visiky 811f982
fix(violin): 修复小提琴图 axis, legend 问题
visiky feaee82
fix(violin): 修复小提琴图单测报错
visiky 5a65110
test(violin): 增加小提琴图 legend & axis 单测
visiky 6260b42
refactor(violin): 优化小提琴图 tooltip & 移除无用 series 字段
visiky 3d30d0f
chore: 增大包限制到 910kb
visiky 1c4ecbe
test(violin): 修复单测问题 & 增加单测覆盖
visiky fbb6f2d
feat(violin): 修改小提琴图动画和图形标注
visiky 2d88d2b
test(violin): 增加小提琴图 meta 单测 & 完善文档
visiky 8c8b0f3
test(violin): 增加单测
visiky 4db2233
refactor(violin): 删除无用的配置项
visiky e9bee38
fix(violin): 暂时修复下小提琴图的 legend 问题
visiky 755b1f5
docs: 优化组件文档,小提琴图没有 slider
visiky 7bf0533
chore: 升级 surge-preivew
visiky 4027526
docs: 小提琴图暂时不支持 label
visiky 682ed93
fix: 修复 violin 单测错误
visiky b5560fb
feat(violin): 小提琴图增加 box 配置
visiky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,85 @@ | ||
import { Violin } from '../../../../src'; | ||
import { BASE_VIOLIN_DATA } from '../../../data/violin'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('violin legend', () => { | ||
const violin = new Violin(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: BASE_VIOLIN_DATA, | ||
xField: 'type', | ||
yField: 'value', | ||
animation: { | ||
enter: { | ||
animation: 'fade-in', | ||
}, | ||
leave: { | ||
animation: 'fade-out', | ||
}, | ||
}, | ||
}); | ||
|
||
violin.render(); | ||
|
||
it('default', () => { | ||
// 新的 geometry violin 暂时未追加 | ||
expect(violin.chart.views[0].geometries[0].animateOption).toEqual({ | ||
enter: { | ||
animation: 'fade-in', | ||
}, | ||
leave: { | ||
animation: 'fade-out', | ||
}, | ||
}); | ||
|
||
// 追加默认的动画配置 | ||
expect(violin.chart.views[1].geometries[0].animateOption).toMatchObject({ | ||
appear: { | ||
duration: 450, | ||
easing: 'easeQuadOut', | ||
}, | ||
update: { | ||
duration: 400, | ||
easing: 'easeQuadInOut', | ||
}, | ||
enter: { | ||
duration: 400, | ||
easing: 'easeQuadInOut', | ||
animation: 'fade-in', | ||
}, | ||
leave: { | ||
duration: 350, | ||
easing: 'easeQuadIn', | ||
animation: 'fade-out', | ||
}, | ||
}); | ||
}); | ||
|
||
it('update', () => { | ||
violin.update({ | ||
animation: { | ||
appear: { | ||
animation: 'fade-in', | ||
}, | ||
leave: { | ||
animation: 'wave-out', | ||
}, | ||
}, | ||
}); | ||
expect(violin.chart.views[0].geometries[0].animateOption).toEqual({ | ||
appear: { | ||
animation: 'fade-in', | ||
}, | ||
enter: { | ||
animation: 'fade-in', | ||
}, | ||
leave: { | ||
animation: 'wave-out', | ||
}, | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
violin.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Violin } from '../../../../src'; | ||
import { BASE_VIOLIN_DATA } from '../../../data/violin'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('violin legend', () => { | ||
const violin = new Violin(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: BASE_VIOLIN_DATA, | ||
xField: 'type', | ||
yField: 'value', | ||
}); | ||
|
||
violin.render(); | ||
|
||
it('text annotation', () => { | ||
violin.update({ | ||
annotations: [ | ||
{ | ||
type: 'text', | ||
position: ['median', 'median'], | ||
content: '辅助文本', | ||
}, | ||
], | ||
}); | ||
|
||
const controller = violin.chart.views[0].getController('annotation'); | ||
expect(controller.getComponents().length).toBe(1); | ||
expect(controller.getComponents()[0].component.get('content')).toBe('辅助文本'); | ||
}); | ||
|
||
it('text annotation and line annotation', () => { | ||
violin.update({ | ||
...violin.options, | ||
annotations: [ | ||
{ | ||
type: 'text', | ||
position: ['min', 'median'], | ||
content: '辅助文本', | ||
offsetY: -4, | ||
style: { | ||
textBaseviolin: 'bottom', | ||
}, | ||
}, | ||
{ | ||
type: 'line', | ||
start: ['min', 'median'], | ||
end: ['max', 'median'], | ||
style: { | ||
stroke: 'red', | ||
violinDash: [2, 2], | ||
}, | ||
}, | ||
], | ||
}); | ||
const controller = violin.chart.views[0].getController('annotation'); | ||
expect(controller.getComponents().length).toBe(2); | ||
expect(controller.getComponents()[0].component.get('content')).toBe('辅助文本'); | ||
expect(controller.getComponents()[1].component.get('type')).toBe('line'); | ||
}); | ||
|
||
afterAll(() => { | ||
violin.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Violin } from '../../../../src'; | ||
import { BASE_VIOLIN_DATA } from '../../../data/violin'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('violin axis', () => { | ||
it('没有 seriesField', () => { | ||
const violin = new Violin(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: BASE_VIOLIN_DATA, | ||
xField: 'type', | ||
yField: 'value', | ||
}); | ||
|
||
violin.render(); | ||
|
||
let axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents().length).toBe(4); | ||
|
||
violin.update({ xAxis: { grid: null } }); | ||
axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents().length).toBe(3); | ||
|
||
violin.update({ xAxis: { title: { text: 'xx' } } }); | ||
axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents()[0].component.get('title').text).toBe('xx'); | ||
|
||
// 关闭 xAxis | ||
violin.update({ xAxis: false }); | ||
axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents().length).toBe(2); | ||
|
||
violin.destroy(); | ||
}); | ||
|
||
it('有 seriesField', () => { | ||
const violin = new Violin(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: BASE_VIOLIN_DATA, | ||
xField: 'type', | ||
yField: 'value', | ||
seriesField: 'species', | ||
}); | ||
|
||
violin.render(); | ||
let axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents().length).toBe(4); | ||
|
||
violin.update({ xAxis: { grid: null } }); | ||
axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents().length).toBe(3); | ||
|
||
violin.update({ xAxis: { title: { text: 'xx' } } }); | ||
axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents()[0].component.get('title').text).toBe('xx'); | ||
|
||
// 关闭 xAxis | ||
violin.update({ xAxis: false }); | ||
axisController = violin.chart.views[0].getController('axis'); | ||
expect(axisController.getComponents().length).toBe(2); | ||
|
||
violin.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Violin } from '../../../../src'; | ||
import { MIN_MAX_VIEW_ID, QUANTILE_VIEW_ID, MEDIAN_VIEW_ID } from '../../../../src/plots/violin/constant'; | ||
import { BASE_VIOLIN_DATA } from '../../../data/violin'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('violin', () => { | ||
it('renders box views.', () => { | ||
const violin = new Violin(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: BASE_VIOLIN_DATA, | ||
xField: 'type', | ||
yField: 'value', | ||
}); | ||
|
||
violin.render(); | ||
const minMaxView = violin.chart.views.find((view) => view.id === MIN_MAX_VIEW_ID); | ||
const quantileView = violin.chart.views.find((view) => view.id === QUANTILE_VIEW_ID); | ||
const medianView = violin.chart.views.find((view) => view.id === MEDIAN_VIEW_ID); | ||
|
||
expect(minMaxView.geometries[0].type).toBe('interval'); | ||
expect(quantileView.geometries[0].type).toBe('interval'); | ||
expect(medianView.geometries[0].type).toBe('point'); | ||
|
||
violin.destroy(); | ||
}); | ||
|
||
// 暂时不开放 box 配置 | ||
it("should not render box views when 'box' set to false.", () => { | ||
const violin = new Violin(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: BASE_VIOLIN_DATA, | ||
xField: 'type', | ||
yField: 'value', | ||
box: false, | ||
}); | ||
|
||
violin.render(); | ||
const minMaxView = violin.chart.views.find((view) => view.id === MIN_MAX_VIEW_ID); | ||
const quantileView = violin.chart.views.find((view) => view.id === QUANTILE_VIEW_ID); | ||
const medianView = violin.chart.views.find((view) => view.id === MEDIAN_VIEW_ID); | ||
|
||
expect(minMaxView).toBeUndefined(); | ||
expect(quantileView).toBeUndefined(); | ||
expect(medianView).toBeUndefined(); | ||
|
||
violin.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { group } from '@antv/util'; | ||
import { Violin } from '../../../../src'; | ||
import { VIOLIN_VIEW_ID } from '../../../../src/plots/violin/constant'; | ||
import { BASE_VIOLIN_DATA } from '../../../data/violin'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('violin change data', () => { | ||
it('renders new violins when data changed', () => { | ||
const violin = new Violin(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: BASE_VIOLIN_DATA, | ||
xField: 'type', | ||
yField: 'value', | ||
}); | ||
|
||
violin.render(); | ||
const g = violin.chart.views.find((view) => view.id === VIOLIN_VIEW_ID).geometries[0]; | ||
expect(g.elements.length).toBe(group(BASE_VIOLIN_DATA, 'type').length); | ||
|
||
const newData = BASE_VIOLIN_DATA.filter((data) => data.type !== 'PetalWidth'); | ||
|
||
violin.changeData(newData); | ||
const newG = violin.chart.views.find((view) => view.id === VIOLIN_VIEW_ID).geometries[0]; | ||
expect(violin.options.data).toEqual(newData); | ||
expect(newG.elements.length).toBe(group(newData, 'type').length); | ||
|
||
violin.destroy(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 annotation 是什么效果?
是不是应该加个 example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
图形标注(我不知道有什么应用场景)