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: radial bar color demo #1845

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 1 deletion __tests__/unit/plots/radial-bar/utils-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('utils of radial-bar', () => {
const starArr = antvStar.map((item) => item[yField]);
const maxValue = Math.max(...starArr);
it('getScaleMax: normal', () => {
expect(getScaleMax(300, yField, antvStar)).toBe((maxValue * 360) / 300);
expect(getScaleMax(360, yField, antvStar)).toBe(maxValue);
expect(getScaleMax(-300, yField, antvStar)).toBe((maxValue * 360) / 300);
expect(getScaleMax(660, yField, antvStar)).toBe((maxValue * 360) / 300);
});
Expand Down
38 changes: 38 additions & 0 deletions examples/radial-bar/basic/demo/color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { RadialBar } from '@antv/g2plot';

const data = [
{ name: 'X6', star: 297 },
{ name: 'G', star: 506 },
{ name: 'AVA', star: 805 },
{ name: 'G2Plot', star: 1478 },
{ name: 'L7', star: 2029 },
{ name: 'G6', star: 7100 },
{ name: 'F2', star: 7346 },
{ name: 'G2', star: 10178 },
];

const bar = new RadialBar('container', {
width: 400,
height: 300,
data,
xField: 'name',
yField: 'star',
maxAngle: 360, //最大旋转角度,
radius: 0.8,
innerRadius: 0.2,
tooltip: {
formatter: (datum) => {
return { name: 'star数', value: datum.star };
},
},
colorField: 'star',
color: ({ star }) => {
if (star > 10000) {
return 'red';
} else if (star > 1000) {
return 'orange';
}
return 'green';
},
});
bar.render();
10 changes: 9 additions & 1 deletion examples/radial-bar/basic/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
"zh": "玉珏图",
"en": "basic Radial-Bar chart"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*wmldRZZj9lIAAAAAAAAAAABkARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*GTDCRYkg6V4AAAAAAAAAAABkARQnAQ"
},
{
"filename": "color.ts",
"title": {
"zh": "玉珏图 - 自定义颜色",
"en": "basic Radial-Bar chart"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*GTDCRYkg6V4AAAAAAAAAAABkARQnAQ"
}
]
}
2 changes: 2 additions & 0 deletions src/plots/radial-bar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export interface RadialBarOptions extends Options {
readonly radius?: number;
/** 圆内半径 */
readonly innerRadius?: number;
/** 颜色字段 */
readonly colorField?: string;
hustcc marked this conversation as resolved.
Show resolved Hide resolved
}