diff --git a/__tests__/unit/adaptor/geometries/interval-spec.ts b/__tests__/unit/adaptor/geometries/interval-spec.ts new file mode 100644 index 0000000000..9f745a6ee9 --- /dev/null +++ b/__tests__/unit/adaptor/geometries/interval-spec.ts @@ -0,0 +1,62 @@ +import { interval, P, Params } from '../../../../src'; +import { IntervalGeometryOptions } from '../../../../src/adaptor/geometries'; +import { createDiv } from '../../../utils/dom'; + +describe('adaptor - interval', () => { + function adaptor(params: Params): Params { + const { chart, options } = params; + const { data } = options; + + chart.data(data); + + // 直接使用 geometry 进行测试 + interval({ + chart, + options: { + ...options, + interval: {}, + args: { columnBackground: options.columnBackground }, + }, + }); + return params; + } + + function getPlot() { + const plot = new P( + createDiv(), + { + width: 400, + height: 300, + data: [ + { type: '1', value: 10 }, + { type: '2', value: 12 }, + ], + appendPadding: 10, + xField: 'type', + yField: 'value', + mapping: {}, + }, + adaptor + ); + + plot.render(); + return plot; + } + + it('columnBackground', () => { + const plot = getPlot(); + expect(plot.chart.geometries[0].elements[0].shape.isGroup()).toBe(false); + + plot.update({ + columnBackground: { style: { fill: 'red' } }, + }); + expect(plot.options.columnBackground).toBeDefined(); + // @ts-ignore + const shapes = plot.chart.geometries[0].elements[0].shape.getChildren(); + expect(shapes.length).toBe(2); + expect(shapes[0].attr('fill')).toBe('red'); + + plot.update({ columnBackground: null }); + expect(plot.chart.geometries[0].elements[0].shape.isGroup()).toBe(false); + }); +}); diff --git a/__tests__/unit/plots/bar/index-spec.ts b/__tests__/unit/plots/bar/index-spec.ts index 1105c7ae58..24915f2aa1 100644 --- a/__tests__/unit/plots/bar/index-spec.ts +++ b/__tests__/unit/plots/bar/index-spec.ts @@ -366,7 +366,7 @@ describe('bar', () => { expect(theme.columnWidthRatio).toBe(0.1); }); - it('legend/tooltip reversed, grouped', () => { + function getBar(isGroup: boolean, isStack: boolean) { const bar = new Bar(createDiv('group'), { width: 300, height: 400, @@ -374,10 +374,15 @@ describe('bar', () => { yField: 'area', xField: 'sales', seriesField: 'series', - isGroup: true, + isGroup, + isStack, }); bar.render(); + return bar; + } + it('legend/tooltip reversed, grouped', () => { + const bar = getBar(true, false); // @ts-ignore expect(bar.chart.getOptions().legends['series'].reversed).toBe(true); // @ts-ignore @@ -385,20 +390,24 @@ describe('bar', () => { }); it('legend/tooltip reversed, stacked', () => { - const bar = new Bar(createDiv('group'), { - width: 300, - height: 400, - data: subSalesByArea, - yField: 'area', - xField: 'sales', - seriesField: 'series', - isStack: true, - }); - bar.render(); - + const bar = getBar(false, true); // @ts-ignore expect(bar.chart.getOptions().legends['series'].reversed).toBe(false); // @ts-ignore expect(bar.chart.getOptions().tooltip?.reversed).toBe(false); }); + + it('bar background', () => { + const bar = getBar(false, false); + expect(bar.options.barBackground).not.toBeDefined(); + expect(bar.chart.geometries[0].elements[0].shape.isGroup()).toBe(false); + + bar.update({ barBackground: { style: { fill: 'red' } } }); + expect(bar.options.barBackground).toBeDefined(); + expect(bar.chart.geometries[0].elements[0].shape.isGroup()).toBe(true); + //@ts-ignore + expect(bar.chart.geometries[0].elements[0].shape.getChildren()[0].attr('fill')).toBe('red'); + + bar.destroy(); + }); }); diff --git a/__tests__/unit/plots/column/index-spec.ts b/__tests__/unit/plots/column/index-spec.ts index 8c4aa7756c..fbfe780900 100644 --- a/__tests__/unit/plots/column/index-spec.ts +++ b/__tests__/unit/plots/column/index-spec.ts @@ -321,6 +321,29 @@ describe('column', () => { column.destroy(); }); + it('column background', () => { + const column = new Column(createDiv('with background'), { + width: 300, + height: 400, + data: subSalesByArea, + xField: 'sales', + yField: 'area', + }); + + column.render(); + + expect(column.options.columnBackground).not.toBeDefined(); + expect(column.chart.geometries[0].elements[0].shape.isGroup()).toBe(false); + + column.update({ columnBackground: { style: { fill: 'red' } } }); + expect(column.options.columnBackground).toBeDefined(); + expect(column.chart.geometries[0].elements[0].shape.isGroup()).toBe(true); + //@ts-ignore + expect(column.chart.geometries[0].elements[0].shape.getChildren()[0].attr('fill')).toBe('red'); + + column.destroy(); + }); + it('theme', () => { const column = new Column(createDiv('theme'), { width: 300, diff --git a/__tests__/unit/plots/radial-bar/index-spec.ts b/__tests__/unit/plots/radial-bar/index-spec.ts index 0ab516575e..b1736fc373 100644 --- a/__tests__/unit/plots/radial-bar/index-spec.ts +++ b/__tests__/unit/plots/radial-bar/index-spec.ts @@ -103,4 +103,30 @@ describe('radial-bar', () => { line.elements.forEach((ele, idx) => expect(ele.shape.attr('color')).toBe(point.elements[idx].shape.attr('color'))); bar.destroy(); }); + + it('bar background and does not work when type="line"', () => { + const bar = new RadialBar(createDiv(), { + width: 400, + height: 300, + data: antvStar, + xField, + yField, + color: (datum) => (datum[yField] < 800 ? 'red' : 'green'), + }); + bar.render(); + expect(bar.options.barBackground).not.toBeDefined(); + expect(bar.chart.geometries[0].elements[0].shape.isGroup()).toBe(false); + + bar.update({ barBackground: { style: { fill: 'red' } } }); + expect(bar.options.barBackground).toBeDefined(); + expect(bar.chart.geometries[0].elements[0].shape.isGroup()).toBe(true); + //@ts-ignore + expect(bar.chart.geometries[0].elements[0].shape.getChildren()[0].attr('fill')).toBe('red'); + + bar.update({ type: 'line' }); + expect(bar.options.barBackground).toBeDefined(); + expect(bar.chart.geometries[0].elements[0].shape.isGroup()).toBe(false); + + bar.destroy(); + }); }); diff --git a/docs/api/plots/bar.en.md b/docs/api/plots/bar.en.md index 5a6eaa595e..5f4deb5c13 100644 --- a/docs/api/plots/bar.en.md +++ b/docs/api/plots/bar.en.md @@ -57,23 +57,15 @@ Whether the plot is Percent Bar. When isPercent is `true`, isStack must be `true ### Graphic Style -#### barWidthRatio - -**optional** _number_ - -The ratio of bar width( Range:[0-1] ). - -#### minBarWidth - -**optional** _number_ +`markdown:docs/common/color.zh.md` -The min width of bar, pixel value。 +`markdown:docs/common/bar-style.en.md` -#### maxBarWidth +#### barWidthRatio **optional** _number_ -The max width of bar, pixel value。 +The ratio of bar width( Range:[0-1] ). #### marginRatio @@ -81,16 +73,6 @@ The max width of bar, pixel value。 The ratio of spacing between columns in groups( Range:[0-1] ), only for Grouped Bar. -#### barStyle - -**optional** _StyleAttr | Function_ - -Bar graphic Style. - -`markdown:docs/common/shape-style.en.md` - -`markdown:docs/common/color.en.md` - ### Plot Components `markdown:docs/common/component.en.md` diff --git a/docs/api/plots/bar.zh.md b/docs/api/plots/bar.zh.md index 4214e44a82..03dd50dabf 100644 --- a/docs/api/plots/bar.zh.md +++ b/docs/api/plots/bar.zh.md @@ -57,39 +57,22 @@ order: 3 ### 图形样式 -#### barWidthRatio - -**optional** _number_ +`markdown:docs/common/color.zh.md` -条形图宽度占比 [0-1]。 +`markdown:docs/common/bar-style.en.md` -#### minBarWidth +#### barWidthRatio **optional** _number_ -条形图最小宽度设置,像素值。 - -#### maxBarWidth - -**optional** _number_ +条形图宽度占比 [0-1]。 -条形图最大宽度设置,像素值。 #### marginRatio **optional** _number_ 分组中柱子之间的间距 [0-1],仅对分组条形图适用。 -#### barStyle - -**optional** _StyleAttr | Function_ - -柱子样式配置。 - -`markdown:docs/common/shape-style.zh.md` - -`markdown:docs/common/color.zh.md` - ### 图表组件 `markdown:docs/common/component.zh.md` diff --git a/docs/api/plots/column.en.md b/docs/api/plots/column.en.md index fc4a7a7414..bbc4e5fc1a 100644 --- a/docs/api/plots/column.en.md +++ b/docs/api/plots/column.en.md @@ -57,23 +57,15 @@ order: 2 ### Geometry Style -#### columnWidthRatio - -**optional** _number_ - -柱状图宽度占比 [0-1]。 - -#### minColumnWidth - -**optional** _number_ +`markdown:docs/common/color.en.md` -The min width of column, pixel value。 +`markdown:docs/common/column-style.en.md` -#### maxColumnWidth +#### columnWidthRatio **optional** _number_ -The max width of column, pixel value。 +柱状图宽度占比 [0-1]。 #### marginRatio @@ -81,16 +73,6 @@ The max width of column, pixel value。 分组中柱子之间的间距 [0-1],仅对分组柱状图适用。 -#### columnStyle - -**optional** _StyleAttr | Function_ - -柱子样式配置。 - -`markdown:docs/common/shape-style.en.md` - -`markdown:docs/common/color.en.md` - ### Plot Components `markdown:docs/common/component.en.md` diff --git a/docs/api/plots/column.zh.md b/docs/api/plots/column.zh.md index 2ad442851e..02e0197ae8 100644 --- a/docs/api/plots/column.zh.md +++ b/docs/api/plots/column.zh.md @@ -59,23 +59,15 @@ order: 2 ### 图形样式 -#### columnWidthRatio - -**optional** _number_ - -柱状图宽度占比 [0-1]。 - -#### minColumnWidth - -**optional** _number_ +`markdown:docs/common/color.zh.md` -柱状图最小宽度设置,像素值。 +`markdown:docs/common/column-style.zh.md` -#### maxColumnWidth +#### columnWidthRatio **optional** _number_ -柱状图最大宽度设置,像素值。 +柱状图宽度占比 [0-1]。 #### marginRatio @@ -83,16 +75,6 @@ order: 2 分组中柱子之间的间距 [0-1],仅对分组柱状图适用。 -#### columnStyle - -**optional** _StyleAttr | Function_ - -柱子样式配置。 - -`markdown:docs/common/shape-style.zh.md` - -`markdown:docs/common/color.zh.md` - ### 图表组件 `markdown:docs/common/component.zh.md` diff --git a/docs/api/plots/radial-bar.en.md b/docs/api/plots/radial-bar.en.md index b610149418..5528900bad 100644 --- a/docs/api/plots/radial-bar.en.md +++ b/docs/api/plots/radial-bar.en.md @@ -3,4 +3,68 @@ title: Radial Bar order: 25 --- -`markdown:docs/api/plots/radial-bar.zh.md` \ No newline at end of file +### Plot Container + +`markdown:docs/common/chart-options.zh.md` + +### Data Mapping + +#### data 📌 + +**required** _array object_ + +Configure the data source. The data source is a collection of objects. For example:`[{ time: '1991',value: 20 }, { time: '1992',value: 30 }]`. + +`markdown:docs/common/xy-field.zh.md` + +`markdown:docs/common/meta.zh.md` + +### Geometry Style + +#### radius + +**optional** _number_ _default:_ `1` + +Radius of Polar coordinate. Value can be: (0, 1] + +#### innerRadius + +**optional** _number_ + +InnerRadius of Polar coordinate. Value can be: (0, 1] + +#### maxAngle + +**optional** _number_ _default:_ `240` + +Specify the maximum rotation angle of the bar, determined by the maximum value in data. The maximum value is 360 degrees. + +#### type + +**optional** _string_ + +Display type of plot. You can specify `type: 'line'` to display a `Radial-Line` plot. + +`markdown:docs/common/bar-style.en.md` + +`markdown:docs/common/color.zh.md` + +### Plot Components + +`markdown:docs/common/component.zh.md` + +### Event + +`markdown:docs/common/events.zh.md` + +### Plot Method + +`markdown:docs/common/chart-methods.zh.md` + +### Plot Theme + +`markdown:docs/common/theme.zh.md` + +### Plot Interactions + +`markdown:docs/common/interactions.zh.md` diff --git a/docs/api/plots/radial-bar.zh.md b/docs/api/plots/radial-bar.zh.md index 88b2fba5f5..7c2f090d8d 100644 --- a/docs/api/plots/radial-bar.zh.md +++ b/docs/api/plots/radial-bar.zh.md @@ -11,59 +11,42 @@ order: 25 #### data 📌 -**必选**, _array object_ +**必选** _array|object_ 功能描述: 设置图表数据源 -默认配置: 无 - 数据源为对象集合,例如:`[{ time: '1991',value: 20 }, { time: '1992',value: 30 }]`。 `markdown:docs/common/xy-field.zh.md` `markdown:docs/common/meta.zh.md` -#### type - -**可选**, _string_ - -功能描述: 图表类型, 'line' 为线形图。 - -默认配置: 无 - ### 图形样式 - #### radius -**可选**, _string_ +**可选** _number_ _default:_ `1` 功能描述: 半径, 0 ~ 1。 -默认配置: `1` - #### innerRadius -**可选**, _number_; +**可选** _number_ 功能描述: 内径,0 ~ 1。 #### maxAngle -**可选**, _number_ +**可选** _number_ _default:_ `240` 功能描述: 最大旋转角度,由 data 中最大的数值决定,最大值是 360 度。 -默认配置: 240 - -#### barStyle - -**可选**, _StyleAttr | Function_ +#### type -功能描述: 样式配置 。 +**可选** _string_ -默认配置: 无 +功能描述: 图表类型, 'line' 为线形图。 -`markdown:docs/common/shape-style.zh.md` +`markdown:docs/common/bar-style.zh.md` `markdown:docs/common/color.zh.md` diff --git a/docs/common/bar-style.en.md b/docs/common/bar-style.en.md new file mode 100644 index 0000000000..abc1999d9b --- /dev/null +++ b/docs/common/bar-style.en.md @@ -0,0 +1,40 @@ + +#### minBarWidth + +**optional**, _number_ + +Specify the min width of bar, pixel value. Auto adapt by default. + +#### maxBarWidth + +**optional**, _number_ + +Specify the max width of bar, pixel value. Auto adapt by default. + +#### barStyle + +**optional** _StyleAttr | Function_ + +Bar graphic Style. + +`markdown:docs/common/shape-style.zh.md` + + +#### barBackground.style + +**optional** _StyleAttr_ + +Background style of bar graphic. **Attention**: It doesn't work when `type="line"` in Radial-bar plot. + +Example: + +```ts +{ + barBackground: { + style: { + fill: '#000', + fillOpacity: 0.25, + } + } +} +``` diff --git a/docs/common/bar-style.zh.md b/docs/common/bar-style.zh.md new file mode 100644 index 0000000000..6275191555 --- /dev/null +++ b/docs/common/bar-style.zh.md @@ -0,0 +1,40 @@ + +#### minBarWidth + +**可选**, _number_ + +功能描述: 柱子的最小宽度设置。 + +#### maxBarWidth + +**可选**, _number_ + +功能描述: 柱子的最大宽度设置。 + +#### barStyle + +**可选** _StyleAttr | Function_ + +功能描述: 样式配置 。 + +`markdown:docs/common/shape-style.zh.md` + + +#### barBackground.style + +**可选** _StyleAttr_ + +功能描述:柱子的背景样式配置 。 **注意**: 当玉珏图 `type="line"` 时,柱子背景设置不起作用。 + +Example: + +```ts +{ + barBackground: { + style: { + fill: '#000', + fillOpacity: 0.25, + } + } +} +``` diff --git a/docs/common/column-style.en.md b/docs/common/column-style.en.md new file mode 100644 index 0000000000..7fbad9d2d0 --- /dev/null +++ b/docs/common/column-style.en.md @@ -0,0 +1,40 @@ + +#### minColumnWidth + +**optional**, _number_ + +Specify the min width of column, pixel value. Auto adapt by default. + +#### maxColumnWidth + +**optional**, _number_ + +Specify the max width of column, pixel value. Auto adapt by default. + +#### columnStyle + +**optional** _StyleAttr | Function_ + +Column graphic Style. + +`markdown:docs/common/shape-style.zh.md` + + +#### columnBackground.style + +**optional** _StyleAttr_ + +Background style of column graphic + +Example: + +```ts +{ + columnBackground: { + style: { + fill: '#000', + fillOpacity: 0.25, + } + } +} +``` diff --git a/docs/common/column-style.zh.md b/docs/common/column-style.zh.md new file mode 100644 index 0000000000..cf3c5e373e --- /dev/null +++ b/docs/common/column-style.zh.md @@ -0,0 +1,40 @@ + +#### minColumnWidth + +**可选**, _number_ + +功能描述: 柱子的最小宽度设置。 + +#### maxColumnWidth + +**可选**, _number_ + +功能描述: 柱子的最大宽度设置。 + +#### columnStyle + +**可选** _StyleAttr | Function_ + +功能描述: 样式配置 。 + +`markdown:docs/common/shape-style.zh.md` + + +#### columnBackground.style + +**可选** _StyleAttr_ + +功能描述:柱子的背景样式配置 。 + +Example: + +```ts +{ + columnBackground: { + style: { + fill: '#000', + fillOpacity: 0.25, + } + } +} +``` diff --git a/examples/more-plots/radial-bar/demo/apple-watch-activity.ts b/examples/more-plots/radial-bar/demo/apple-watch-activity.ts new file mode 100644 index 0000000000..6556fd1e51 --- /dev/null +++ b/examples/more-plots/radial-bar/demo/apple-watch-activity.ts @@ -0,0 +1,56 @@ +import { RadialBar } from '@antv/g2plot'; + +const data = [ + { + name: 'activity1', + percent: 2370, + color: '#1ad5de', + icon: 'https://gw.alipayobjects.com/zos/antfincdn/ck11Y6aRrz/shangjiantou.png', + }, + { + name: 'activity2', + percent: 800, + color: '#a0ff03', + icon: 'https://gw.alipayobjects.com/zos/antfincdn/zY2JB7hhrO/shuangjiantou.png', + }, + { + name: 'activity3', + percent: 650, + color: '#e90b3a', + icon: 'https://gw.alipayobjects.com/zos/antfincdn/%24qBxSxdK05/jiantou.png', + }, +]; +const bar = new RadialBar('container', { + width: 400, + height: 244, + autoFit: false, + appendPadding: [50, 0, 50, 0], + data, + xField: 'name', + yField: 'percent', + // maxAngle: 90, //最大旋转角度, + radius: 0.8, + innerRadius: 0.2, + xAxis: false, + theme: 'dark', + barBackground: { style: { fill: 'rgba(255,255,255,0.45)' } }, + barStyle: { lineCap: 'round' }, + minBarWidth: 16, + maxBarWidth: 16, + colorField: 'name', + color: ({ name }) => { + return data.find((d) => d.name === name).color; + }, + annotations: data.map((d) => ({ + type: 'html', + position: [d.name, 0], + html: `
+ +
`, + })), +}); +bar.render(); diff --git a/examples/more-plots/radial-bar/demo/background.ts b/examples/more-plots/radial-bar/demo/background.ts new file mode 100644 index 0000000000..c6180e9500 --- /dev/null +++ b/examples/more-plots/radial-bar/demo/background.ts @@ -0,0 +1,55 @@ +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: 350, //最大旋转角度, + radius: 0.8, + innerRadius: 0.2, + tooltip: { + formatter: (datum) => { + return { name: 'star数', value: datum.star }; + }, + }, + colorField: 'star', + color: ({ star }) => { + if (star > 10000) { + return '#6349ec'; + } else if (star > 1000) { + return '#ff9300'; + } + return '#ff93a7'; + }, + barBackground: {}, + barStyle: { lineCap: 'round' }, + annotations: [ + { + type: 'html', + position: ['50%', '50%'], + html: (container, view) => { + const coord = view.getCoordinate(); + const w = coord.polarRadius * coord.innerRadius * 1.15; + return `
+ +
`; + }, + }, + ], +}); +bar.render(); diff --git a/examples/more-plots/radial-bar/demo/color.ts b/examples/more-plots/radial-bar/demo/color.ts index fb44e240b2..987dbf4301 100644 --- a/examples/more-plots/radial-bar/demo/color.ts +++ b/examples/more-plots/radial-bar/demo/color.ts @@ -1,4 +1,4 @@ -import { RadialBar } from '../../../relation/sankey/demo/node_modules/@antv/g2plot'; +import { RadialBar } from '@antv/g2plot'; const data = [ { name: 'X6', star: 297 }, @@ -17,7 +17,7 @@ const bar = new RadialBar('container', { data, xField: 'name', yField: 'star', - maxAngle: 360, //最大旋转角度, + maxAngle: 270, //最大旋转角度, radius: 0.8, innerRadius: 0.2, tooltip: { @@ -28,11 +28,11 @@ const bar = new RadialBar('container', { colorField: 'star', color: ({ star }) => { if (star > 10000) { - return 'red'; + return '#36c361'; } else if (star > 1000) { - return 'orange'; + return '#2194ff'; } - return 'green'; + return '#ff4d4f'; }, }); bar.render(); diff --git a/examples/more-plots/radial-bar/demo/meta.json b/examples/more-plots/radial-bar/demo/meta.json index c8870ed6ea..096db40b3f 100644 --- a/examples/more-plots/radial-bar/demo/meta.json +++ b/examples/more-plots/radial-bar/demo/meta.json @@ -8,25 +8,49 @@ "filename": "basic.ts", "title": { "zh": "玉珏图", - "en": "basic Radial-Bar chart" + "en": "Radial-Bar plot" }, - "screenshot": "https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*GTDCRYkg6V4AAAAAAAAAAABkARQnAQ" + "screenshot": "https://gw.alipayobjects.com/zos/antfincdn/b0lq5uRNpn/cb262279-a0ec-48de-9afc-267b9c5fda09.png" + }, + { + "filename": "round-corner.ts", + "title": { + "zh": "带圆角的玉珏图", + "en": "Radial-Bar plot with rounded corner" + }, + "screenshot": "https://gw.alipayobjects.com/zos/antfincdn/dGBD84g0sY/743e388d-f1e6-4d6b-ab8d-28101f35a609.png" }, { "filename": "color.ts", "title": { - "zh": "玉珏图 - 自定义颜色", - "en": "basic Radial-Bar chart" + "zh": "带自定义颜色的玉珏图", + "en": "Radial-Bar plot with custom color" + }, + "screenshot": "https://gw.alipayobjects.com/zos/antfincdn/l6uP5%26MiT7/385e3f80-52ec-49e9-9dfe-bd447e63203f.png" + }, + { + "filename": "background.ts", + "title": { + "zh": "带柱子背景的玉珏图", + "en": "Radial-Bar plot with background" }, - "screenshot": "https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*GTDCRYkg6V4AAAAAAAAAAABkARQnAQ" + "screenshot": "https://gw.alipayobjects.com/zos/antfincdn/A2Ik7iu%26YW/519113a4-f42e-48b2-a75d-1021add83c30.png" }, { "filename": "line.ts", "title": { "zh": "线形玉珏图", - "en": "Radial-line chart" + "en": "Radial-line plot" }, "screenshot": "https://gw.alipayobjects.com/mdn/rms_f5c722/afts/img/A*GC6wT4GQ-oMAAAAAAAAAAABkARQnAQ" + }, + { + "filename": "apple-watch-activity.ts", + "title": { + "zh": "健身: 活动记录", + "en": "Fitness: Activity record" + }, + "screenshot": "https://gw.alipayobjects.com/zos/antfincdn/6YIirgSj4E/4fb2dd39-0dfd-4130-a17a-bd3dc602573c.png" } ] } diff --git a/examples/more-plots/radial-bar/demo/round-corner.ts b/examples/more-plots/radial-bar/demo/round-corner.ts new file mode 100644 index 0000000000..4a22e6a003 --- /dev/null +++ b/examples/more-plots/radial-bar/demo/round-corner.ts @@ -0,0 +1,28 @@ +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: 270, //最大旋转角度, + radius: 0.8, + innerRadius: 0.2, + barStyle: { + lineCap: 'round', + }, +}); + +bar.render(); diff --git a/src/adaptor/geometries/interval.ts b/src/adaptor/geometries/interval.ts index 459f2237f8..fef136feb5 100644 --- a/src/adaptor/geometries/interval.ts +++ b/src/adaptor/geometries/interval.ts @@ -1,4 +1,4 @@ -import { Geometry, getTheme } from '@antv/g2'; +import { Geometry, getTheme, ShapeAttrs } from '@antv/g2'; import { isNil, isObject } from '@antv/util'; import { Params } from '../../core/adaptor'; import { deepAssign } from '../../utils'; @@ -24,7 +24,9 @@ export interface IntervalGeometryOptions extends GeometryOptions { readonly minColumnWidth?: number; /** 柱状图最大宽度(像素) */ readonly maxColumnWidth?: number; - /** 柱子样式配置 */ + /** 柱子的背景样式设置 */ + readonly columnBackground?: { style: ShapeAttrs }; + /** 柱子视觉通道配置(含 color、shape、size、style、tooltip) */ readonly interval?: MappingOptions; /** 分组字段,优先级高于 seriesField , isGroup: true 时会根据 groupField 进行分组。*/ readonly groupField?: string; @@ -80,7 +82,7 @@ function otherAdaptor(params: Params): Par export function interval(params: Params): Params { const { options } = params; - const { xField, yField, interval, seriesField, tooltip, minColumnWidth, maxColumnWidth } = options; + const { xField, yField, interval, seriesField, tooltip, minColumnWidth, maxColumnWidth, columnBackground } = options; const { fields, formatter } = getTooltipMapping(tooltip, [xField, yField, seriesField]); @@ -96,7 +98,7 @@ export function interval(params: Params): tooltip: formatter, ...interval, }, - args: { minColumnWidth, maxColumnWidth }, + args: { minColumnWidth, maxColumnWidth, background: columnBackground }, }, }) ) diff --git a/src/plots/bar/adaptor.ts b/src/plots/bar/adaptor.ts index 93150682ae..343b28cc94 100644 --- a/src/plots/bar/adaptor.ts +++ b/src/plots/bar/adaptor.ts @@ -86,6 +86,7 @@ export function adaptor(params: Params) { columnWidthRatio: barWidthRatio, minColumnWidth: minBarWidth, maxColumnWidth: maxBarWidth, + columnBackground: options.barBackground, // bar 调整数据顺序 data: data ? data.slice().reverse() : data, }, diff --git a/src/plots/bar/types.ts b/src/plots/bar/types.ts index 933fd92b70..e6ff530a21 100644 --- a/src/plots/bar/types.ts +++ b/src/plots/bar/types.ts @@ -9,4 +9,6 @@ export interface BarOptions readonly minBarWidth?: ColumnOptions['minColumnWidth']; /** 条形图最大宽度(像素) */ readonly maxBarWidth?: ColumnOptions['maxColumnWidth']; + /** 条形图柱子的背景 */ + readonly barBackground?: ColumnOptions['columnBackground']; } diff --git a/src/plots/column/types.ts b/src/plots/column/types.ts index 7d359a778f..91fc83345d 100644 --- a/src/plots/column/types.ts +++ b/src/plots/column/types.ts @@ -1,3 +1,4 @@ +import { ShapeAttrs } from '@antv/g2'; import { Options, StyleAttr } from '../../types'; import { OptionWithConversionTag } from '../../adaptor/conversion-tag'; import { OptionWithConnectedArea } from '../../adaptor/connected-area'; @@ -25,6 +26,8 @@ export interface ColumnOptions extends Options, OptionWithConversionTag, OptionW readonly minColumnWidth?: number; /** 柱状图最大宽度(像素) */ readonly maxColumnWidth?: number; + /** 柱状图柱子的背景 */ + readonly columnBackground?: { style?: ShapeAttrs }; /** 柱子样式配置,可选 */ readonly columnStyle?: StyleAttr; /** 分组字段,优先级高于 seriesField , isGroup: true 时会根据 groupField 进行分组。*/ diff --git a/src/plots/radial-bar/adaptor.ts b/src/plots/radial-bar/adaptor.ts index 6f07771b81..07a4377e8d 100644 --- a/src/plots/radial-bar/adaptor.ts +++ b/src/plots/radial-bar/adaptor.ts @@ -22,6 +22,10 @@ function geometry(params: Params): Params { color, shape: type === 'line' ? 'line' : 'intervel', }, + // 柱子的一些样式设置:柱子最小宽度、柱子最大宽度、柱子背景 + minColumnWidth: options.minBarWidth, + maxColumnWidth: options.maxBarWidth, + columnBackground: options.barBackground, }, }); interval(p); diff --git a/src/plots/radial-bar/index.ts b/src/plots/radial-bar/index.ts index 50eed5bbef..e61bf0147f 100644 --- a/src/plots/radial-bar/index.ts +++ b/src/plots/radial-bar/index.ts @@ -29,6 +29,8 @@ export class RadialBar extends Plot { line: null, }, maxAngle: 240, + // 默认先关闭动画 + animation: false, }); } diff --git a/src/plots/radial-bar/types.ts b/src/plots/radial-bar/types.ts index 99160b02c0..1ca49bfca3 100644 --- a/src/plots/radial-bar/types.ts +++ b/src/plots/radial-bar/types.ts @@ -1,8 +1,9 @@ import { ShapeAttrs } from '@antv/g-base'; import { Options } from '../../types'; +import { BarOptions } from '../bar'; /** 配置类型定义 */ -export interface RadialBarOptions extends Options { +export interface RadialBarOptions extends Options, Pick { /** x 轴字段 */ readonly xField?: string; /** y 轴字段 */