-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: violin plot * feat: 封装violin API * fix: delete useEffect * fix: delete .editor * fix: ignore .vscode * fix: delete .vscode & delete init * feat: ignore .vscode * fix: open api xField yField seriesField * fix: lint --------- Co-authored-by: zy371123 <zy371123@alibaba-inc.com> Co-authored-by: Joel Alan <31396322+lxfu1@users.noreply.github.com>
- Loading branch information
1 parent
1798094
commit 0834952
Showing
16 changed files
with
224 additions
and
4 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 |
---|---|---|
|
@@ -31,6 +31,7 @@ logs | |
#ide | ||
.idea/ | ||
.eslintcache | ||
.vscode/** | ||
|
||
# temp | ||
temp-gallery.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,12 @@ | ||
import React from 'react'; | ||
import { ViolinOptions } from '../../core'; | ||
import { CommonConfig } from '../../interface'; | ||
import { BaseChart } from '../base'; | ||
|
||
export type ViolinConfig = CommonConfig<ViolinOptions>; | ||
|
||
const ViolinChart = (props: ViolinConfig) => { | ||
return <BaseChart {...props} chartType="Violin" />; | ||
} | ||
|
||
export default ViolinChart; |
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,49 @@ | ||
import { flow, transformOptions, set } from '../../utils'; | ||
import { mark } from '../../components'; | ||
import type { Adaptor } from '../../types'; | ||
import type { ViolinOptions } from './type'; | ||
|
||
type Params = Adaptor<ViolinOptions>; | ||
|
||
/** | ||
* @param chart | ||
* @param options | ||
*/ | ||
export function adaptor(params: Params) { | ||
/** | ||
* 图表差异化处理 | ||
*/ | ||
const customTransform = (params: Params) => { | ||
const { options } = params; | ||
const { xField, yField, seriesField, children } = options; | ||
|
||
const newChildren = children?.map((item) => { | ||
return { | ||
...item, | ||
xField, | ||
yField, | ||
seriesField, | ||
colorField: seriesField, | ||
data: item.type === 'density' ? { | ||
transform: [ | ||
{ | ||
type: 'kde', | ||
field: yField, | ||
groupBy: [xField, seriesField], | ||
}, | ||
], | ||
} : item.data, | ||
} | ||
}).filter((item) => options.violinType !== 'density' || item.type === 'density'); | ||
set(options, 'children', newChildren); | ||
// 默认‘normal’类型数据格式 | ||
if (options.violinType === 'polar') { | ||
set(options, 'coordinate', { type: 'polar'}) | ||
} | ||
// 底层不消费violinType字段。 | ||
set(options, 'violinType', undefined); | ||
return params; | ||
} | ||
|
||
return flow(customTransform, transformOptions, mark)(params); | ||
} |
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,51 @@ | ||
import { Plot } from '../../base'; | ||
import type { Adaptor } from '../../types'; | ||
import { adaptor } from './adaptor'; | ||
import { ViolinOptions } from './type'; | ||
|
||
export type { ViolinOptions }; | ||
|
||
export class Violin extends Plot<ViolinOptions> { | ||
/** 图表类型 */ | ||
public type = 'violin'; | ||
|
||
/** | ||
* 获取 折线图 默认配置项 | ||
* 供外部使用 | ||
*/ | ||
static getDefaultOptions(): Partial<ViolinOptions> { | ||
return { | ||
type: 'view', | ||
children: [ | ||
{ | ||
type: 'density', | ||
sizeField: 'size', | ||
tooltip: false, | ||
}, | ||
{ | ||
type: 'boxplot', | ||
shapeField: 'violin', | ||
style: { | ||
opacity: 0.5, | ||
point: false, | ||
}, | ||
}, | ||
], | ||
animate: { enter: { type: 'fadeIn' } }, | ||
}; | ||
} | ||
|
||
/** | ||
* 获取 折线图 默认配置 | ||
*/ | ||
protected getDefaultOptions() { | ||
return Violin.getDefaultOptions(); | ||
} | ||
|
||
/** | ||
* 折线图适配器 | ||
*/ | ||
protected getSchemaAdaptor(): (params: Adaptor<ViolinOptions>) => void { | ||
return adaptor; | ||
} | ||
} |
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,5 @@ | ||
import type { BaseOptions, Options } from '../../types/common'; | ||
|
||
export type ViolinOptions = Options & BaseOptions & { | ||
violinType?: 'normal' | 'density' | 'polar' | ||
}; |
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,19 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Violin } from '@ant-design/plots'; | ||
|
||
const DemoViolin = () => { | ||
const config = { | ||
violinType: 'normal', | ||
data: { | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/species.json', | ||
}, | ||
xField: 'x', | ||
yField: 'y', | ||
seriesField: 'species' | ||
}; | ||
return <Violin {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoViolin />, document.getElementById('container')); |
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,19 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Violin } from '@ant-design/plots'; | ||
|
||
const DemoViolin = () => { | ||
const config = { | ||
violinType: 'density', | ||
data: { | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/species.json', | ||
}, | ||
xField: 'x', | ||
yField: 'y', | ||
seriesField: 'species' | ||
}; | ||
return <Violin {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoViolin />, document.getElementById('container')); |
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 @@ | ||
{ | ||
"title": { | ||
"zh": "中文分类", | ||
"en": "Category" | ||
}, | ||
"demos": [ | ||
{ | ||
"filename": "density.js", | ||
"title": { | ||
"zh": "和密度图", | ||
"en": "Density plot" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_lwk8lu/afts/img/A*pctXQbGFiBIAAAAAAAAAAAAADma_AQ/original" | ||
}, | ||
{ | ||
"filename": "basic.js", | ||
"title": { | ||
"zh": "基础小提琴图", | ||
"en": "Basic violin plot" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_lwk8lu/afts/img/A*vKc6SJjPY40AAAAAAAAAAAAADma_AQ/original" | ||
}, | ||
{ | ||
"filename": "polar.js", | ||
"title": { | ||
"zh": "极坐标小提琴图", | ||
"en": "Polar violin plot" | ||
}, | ||
"screenshot": "https://mdn.alipayobjects.com/huamei_lwk8lu/afts/img/A*LLm1S5RBXGIAAAAAAAAAAAAADma_AQ/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,19 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Violin } from '@ant-design/plots'; | ||
|
||
const DemoViolin = () => { | ||
const config = { | ||
violinType: 'polar', | ||
data: { | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/species.json', | ||
}, | ||
xField: 'x', | ||
yField: 'y', | ||
seriesField: 'species' | ||
}; | ||
return <Violin {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoViolin />, document.getElementById('container')); |
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: Violin | ||
order: 15 | ||
--- |
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: 15 | ||
--- |