-
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: add density mark, violin shape and kde transform (#5043)
* feat: add violin mark and kde transform * feat: add density mark and kde * feat: add violin shape and test cases * chore: set default kde.size = 10 * chore: remove unused code * docs: add chart api and demos * docs: add documents for kde and density * chore: update documents * docs: fix typo
- Loading branch information
Showing
38 changed files
with
3,809 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,29 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function speciesDensityBasic(): G2Spec { | ||
return { | ||
type: 'density', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/species.json', | ||
transform: [ | ||
{ | ||
type: 'kde', | ||
field: 'y', | ||
groupBy: ['x', 'species'], | ||
size: 10, | ||
}, | ||
], | ||
}, | ||
encode: { | ||
x: 'x', | ||
y: 'y', | ||
series: 'species', | ||
color: 'species', | ||
size: 'size', | ||
}, | ||
tooltip: false, | ||
}; | ||
} | ||
|
||
speciesDensityBasic.maxError = 100; |
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 { G2Spec } from '../../../src'; | ||
|
||
export function speciesViolinBasicPolar(): G2Spec { | ||
return { | ||
type: 'view', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/species.json', | ||
}, | ||
coordinate: { | ||
type: 'polar', | ||
}, | ||
children: [ | ||
{ | ||
type: 'density', | ||
data: { | ||
transform: [ | ||
{ | ||
type: 'kde', | ||
field: 'y', | ||
groupBy: ['x', 'species'], | ||
}, | ||
], | ||
}, | ||
encode: { | ||
x: 'x', | ||
y: 'y', | ||
series: 'species', | ||
color: 'species', | ||
size: 'size', | ||
}, | ||
tooltip: false, | ||
}, | ||
{ | ||
type: 'boxplot', | ||
encode: { | ||
x: 'x', | ||
y: 'y', | ||
series: 'species', | ||
color: 'species', | ||
size: 8, | ||
shape: 'violin', | ||
}, | ||
style: { | ||
opacity: 0.5, | ||
point: false, | ||
}, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
speciesViolinBasicPolar.maxError = 100; |
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 { G2Spec } from '../../../src'; | ||
|
||
export function speciesViolinBasic(): G2Spec { | ||
return { | ||
type: 'view', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/species.json', | ||
}, | ||
children: [ | ||
{ | ||
type: 'density', | ||
data: { | ||
transform: [ | ||
{ | ||
type: 'kde', | ||
field: 'y', | ||
groupBy: ['x', 'species'], | ||
}, | ||
], | ||
}, | ||
encode: { | ||
x: 'x', | ||
y: 'y', | ||
series: 'species', | ||
color: 'species', | ||
size: 'size', | ||
}, | ||
transform: [{ type: 'dodgeX' }], | ||
tooltip: false, | ||
}, | ||
{ | ||
type: 'boxplot', | ||
encode: { | ||
x: 'x', | ||
y: 'y', | ||
series: 'species', | ||
color: 'species', | ||
size: 8, | ||
shape: 'violin', | ||
}, | ||
style: { | ||
opacity: 0.5, | ||
point: false, | ||
}, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
speciesViolinBasic.maxError = 100; |
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
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,6 @@ | ||
--- | ||
title: kde | ||
order: 1 | ||
--- | ||
|
||
<embed src="@/docs/spec/data/kde.zh.md"></embed> |
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,37 @@ | ||
--- | ||
title: kde | ||
order: 1 | ||
--- | ||
|
||
对指定的数据,进行核密度算法(Kernel Density Estimation)处理,底层使用开源库 [pdfast](https://www.npmjs.com/package/pdfast)。 | ||
|
||
## 开始使用 | ||
|
||
```ts | ||
chart.data({ | ||
type: 'inline', | ||
value: data, | ||
transform: [ | ||
{ | ||
type: 'kde', | ||
field: 'y', | ||
groupBy: ['x', 'species'], | ||
as: ['y', 'size'], | ||
}, | ||
], | ||
}); | ||
``` | ||
|
||
上述例子处理之后,数据会增加 y、size 字段,均为数字数组。 | ||
|
||
## 选项 | ||
|
||
| 属性 | 描述 | 类型 | 默认值 | | ||
| -------- | -------------------------------------------------- | ---------------------------- | ------------- | | ||
| field | 进行核密度算法的数据字段 | `string` | | | ||
| groupBy | 对数据进行分组的分组字段,可以指定多个 | `string[]` | | | ||
| as | 进行 KDE 处理之后,存储的字段 | `[number, number]` | `['y', 'size']` | | ||
| min | 指定处理范围的最小值 | `number` | 数据最小值 | | ||
| max | 指定处理范围的最大值 | `number` | 数据最小值 | | ||
| size | 算法最终生成数据的条数 | `number` | `10` | | ||
| width | 确定一个元素左右影响多少点,类似于 bandWidth | `number` | `2` | |
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,6 @@ | ||
--- | ||
title: density | ||
order: 1 | ||
--- | ||
|
||
<embed src="@/docs/spec/mark/density.zh.md"></embed> |
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,62 @@ | ||
--- | ||
title: density | ||
order: 1 | ||
--- | ||
|
||
接受核密度数据,一般用于用于绘制小提琴图。 | ||
|
||
## 开始使用 | ||
|
||
<img alt="density" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*S6O8QqpcRPMAAAAAAAAAAAAADmJ7AQ/original" width="600" /> | ||
|
||
```js | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
chart.data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/species.json', | ||
transform: [ | ||
{ | ||
type: 'kde', | ||
field: 'y', | ||
groupBy: ['x'], | ||
size: 20, | ||
}, | ||
], | ||
}); | ||
|
||
chart | ||
.density() | ||
.encode('x', 'x') | ||
.encode('y', 'y') | ||
.encode('color', 'x') | ||
.encode('size', 'size') | ||
.tooltip(false); | ||
|
||
chart.render(); | ||
|
||
``` | ||
|
||
## 选项 | ||
|
||
|
||
| 属性 | 描述 | 类型 | 默认值 | | ||
| -------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | ------------------------------ | | ||
| fill | 图形的填充色 | `string` \| `Function<string>` | - | | ||
| fillOpacity | 图形的填充透明度 | `number` \| `Function<number>` | - | | ||
| stroke | 图形的描边 | `string` \| `Function<string>` | - | | ||
| strokeOpacity | 描边透明度 | `number` \| `Function<number>` | - | | ||
| lineWidth | 图形描边的宽度 | `number` \| `Function<number>` | - | | ||
| lineDash | 描边的虚线配置,第一个值为虚线每个分段的长度,第二个值为分段间隔的距离。lineDash 设为[0, 0]的效果为没有描边。 | `[number,number]` \| `Function<[number, number]>` | - | | ||
| opacity | 图形的整体透明度 | `number` \| `Function<number>` | - | | ||
| shadowColor | 图形阴影颜色 | `string` \| `Function<string>` | - | | ||
| shadowBlur | 图形阴影的高斯模糊系数 | `number` \| `Function<number>` | - | | ||
| shadowOffsetX | 设置阴影距图形的水平距离 | `number` \| `Function<number>` | - | | ||
| shadowOffsetY | 设置阴影距图形的垂直距离 | `number` \| `Function<number>` | - | | ||
| cursor | 鼠标样式。同 css 的鼠标样式,默认 'default'。 | `string` \| `Function<string>` | 'default' | |
Oops, something went wrong.