Skip to content
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(sunburst): add sunburst demo #5854

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
},
"devDependencies": {
"@antv/data-set": "^0.11.8",
"@antv/g-pattern": "^1.2.19",
"@antv/g-plugin-3d": "^1.9.26",
"@antv/g-plugin-control": "^1.9.17",
"@antv/g-plugin-rough-canvas-renderer": "^1.9.22",
Expand All @@ -91,6 +92,7 @@
"@antv/g-webgl": "^1.9.29",
"@antv/g2-extension-3d": "^0.1.3",
"@antv/g2-extension-ava": "^0.1.1",
"@antv/g2-extension-plot": "^0.1.0",
"@antv/translator": "^1.0.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^17.8.1",
Expand Down
1 change: 1 addition & 0 deletions site/.dumi/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (window) {
(window as any).G2 = (window as any).g2;
(window as any).g2Extension3d = require('@antv/g2-extension-3d');
(window as any).g2ExtensionAva = require('@antv/g2-extension-ava');
(window as any).g2ExtensionPlot = require('@antv/g2-extension-plot');
(window as any).s2 = require('@antv/s2');
(window as any).d3Hierarchy = require('d3-hierarchy');
(window as any).d3ScaleChromatic = require('d3-scale-chromatic');
Expand Down
56 changes: 56 additions & 0 deletions site/examples/general/sunburst/demo/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"title": {
"zh": "中文分类",
"en": "Category"
},
"demos": [
{
"filename": "sunburst-default.ts",
"title": {
"zh": "旭日图",
"en": "Sunburst Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*-aInRJfa4-8AAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "sunburst-label.ts",
"title": {
"zh": "旭日图带标签",
"en": "Sunburst Label Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*GBxdT697NYQAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "sunburst-color.ts",
"title": {
"zh": "旭日图自定义颜色通道",
"en": "Sunburst ColorField Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7L4tQ4F61ZkAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "sunburst-style.ts",
"title": {
"zh": "旭日图自定义样式",
"en": "Sunburst Style Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*BP7zQ6SMiKcAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "sunburst-pattern.ts",
"title": {
"zh": "旭日图自定义纹理",
"en": "Sunburst Pattern Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*rVCgTqydP5kAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "sunburst-interaction.ts",
"title": {
"zh": "旭日图交互配置",
"en": "Sunburst Interaction Config Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7C0NQK9_TfwAAAAAAAAAAAAADmJ7AQ/original"
}
]
}
20 changes: 20 additions & 0 deletions site/examples/general/sunburst/demo/sunburst-color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { plotlib } from '@antv/g2-extension-plot';
pearmini marked this conversation as resolved.
Show resolved Hide resolved
import { Runtime, corelib, extend } from '@antv/g2';

const Chart = extend(Runtime, { ...corelib(), ...plotlib() });

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.sunburst()
.data({
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/sunburst.json',
})
.encode('value', 'sum')
.encode('color', 'label');

chart.render();
20 changes: 20 additions & 0 deletions site/examples/general/sunburst/demo/sunburst-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { plotlib } from '@antv/g2-extension-plot';
import { Runtime, corelib, extend } from '@antv/g2';

const Chart = extend(Runtime, { ...corelib(), ...plotlib() });

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.sunburst()
.data({
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antfincdn/ryp44nvUYZ/coffee.json',
})
.animate('enter', { type: 'waveIn' })
.coordinate({ type: 'polar', innerRadius: 0 });

chart.render();
47 changes: 47 additions & 0 deletions site/examples/general/sunburst/demo/sunburst-interaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { plotlib } from '@antv/g2-extension-plot';
import { Runtime, corelib, extend } from '@antv/g2';

const Chart = extend(Runtime, { ...corelib(), ...plotlib() });

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.sunburst()
.data({
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/sunburst.json',
})
.encode('value', 'sum')
.label({
text: 'name',
transform: [
{
type: 'overflowHide',
},
],
})
.interaction({
drillDown: {
breadCrumb: {
rootText: '起始',
style: {
fontSize: '18px',
fill: '#333',
},
active: {
fill: 'red',
},
},
// FixedColor default: true, true -> drillDown update scale, false -> scale keep.
fixedColor: false,
},
})
.state({
active: { zIndex: 2, stroke: 'red' },
inactive: { zIndex: 1, stroke: '#fff' },
});

chart.render();
27 changes: 27 additions & 0 deletions site/examples/general/sunburst/demo/sunburst-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { plotlib } from '@antv/g2-extension-plot';
import { Runtime, corelib, extend } from '@antv/g2';

const Chart = extend(Runtime, { ...corelib(), ...plotlib() });

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.sunburst()
.data({
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/sunburst.json',
})
.encode('value', 'sum')
.label({
text: 'name',
transform: [
{
type: 'overflowHide',
},
],
});

chart.render();
37 changes: 37 additions & 0 deletions site/examples/general/sunburst/demo/sunburst-pattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { lines } from '@antv/g-pattern';
import { plotlib } from '@antv/g2-extension-plot';
import { Runtime, corelib, extend } from '@antv/g2';

const Chart = extend(Runtime, { ...corelib(), ...plotlib() });

const colors = ['#e8c1a0', '#f47560', '#f1e15b', '#e8a838', '#61cdbb'];

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.sunburst()
.data({
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/sunburst.json',
})
.encode('value', 'sum')
.style({
fill: (_, idx) => {
return {
image: lines({
backgroundColor: colors[idx % colors.length],
backgroundOpacity: 0.65,
stroke: colors[idx % colors.length],
lineWidth: 4,
spacing: 5,
}),
repetition: 'repeat',
transform: 'rotate(30deg)',
};
},
});

chart.render();
25 changes: 25 additions & 0 deletions site/examples/general/sunburst/demo/sunburst-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { plotlib } from '@antv/g2-extension-plot';
import { Runtime, corelib, extend } from '@antv/g2';

const Chart = extend(Runtime, { ...corelib(), ...plotlib() });

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.sunburst()
.data({
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/sunburst.json',
})
.encode('value', 'sum')
.style({
fill: (v) => {
if (v['path'] === '类别 3') return 'red';
if (v['name'] === '类别 2.1.1') return 'red';
},
});

chart.render();
4 changes: 4 additions & 0 deletions site/examples/general/sunburst/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Sunburst
order: 16
---
4 changes: 4 additions & 0 deletions site/examples/general/sunburst/index.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: 旭日图
order: 16
---
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@antv/g-webgl": "^1.9.29",
"@antv/g2-extension-3d": "^0.1.3",
"@antv/g2-extension-ava": "^0.2.0",
"@antv/g2-extension-plot": "^0.1.0",
"@antv/s2": "^1.52.0",
"antd": "^4.24.14",
"d3-array": "^3.2.4",
Expand Down
Loading