diff --git a/projects/ui/src/lib/components/po-chart-new/po-chart-grid-utils.ts b/projects/ui/src/lib/components/po-chart-new/po-chart-grid-utils.ts index c123a59b5..51631761e 100644 --- a/projects/ui/src/lib/components/po-chart-new/po-chart-grid-utils.ts +++ b/projects/ui/src/lib/components/po-chart-new/po-chart-grid-utils.ts @@ -28,6 +28,7 @@ export class PoChartGridUtils { fontFamily: this.component.getCSSVariable('--font-family-grid', '.po-chart'), fontSize: tokenFontSizeGrid || 12, fontWeight: Number(this.component.getCSSVariable('--font-weight-grid', '.po-chart')), + color: this.component.getCSSVariable('--color-legend', '.po-chart'), rotate: this.component.options?.axis?.rotateLegend, interval: 0, width: 72, @@ -50,6 +51,7 @@ export class PoChartGridUtils { margin: 10, fontFamily: this.component.getCSSVariable('--font-family-grid', '.po-chart'), fontSize: tokenFontSizeGrid || 12, + color: this.component.getCSSVariable('--color-legend', '.po-chart'), fontWeight: Number(this.component.getCSSVariable('--font-weight-grid', '.po-chart')) }, splitLine: { @@ -134,10 +136,48 @@ export class PoChartGridUtils { color: color }; serie.emphasis = { focus: 'series' }; + serie.blur = { + itemStyle: { opacity: 0.4 } + }; this.component.boundaryGap = true; } } + setListTypePie() { + let radius = '85%'; + let positionHorizontal; + if (this.component.options?.legend === false) { + radius = '95%'; + positionHorizontal = '50%'; + } else { + positionHorizontal = this.component.options?.legendVerticalPosition === 'top' ? '54%' : '46%'; + } + this.component.listTypePie = [ + { + type: 'pie', + center: ['50%', positionHorizontal], + radius: radius, + emphasis: { focus: 'self' }, + data: [], + blur: { itemStyle: { opacity: 0.4 } } + } + ]; + } + + setSerieTypePie(serie: any, color: string) { + if (this.component.listTypePie?.length) { + const borderWidth = this.resolvePx('--border-width-sm'); + const borderColor = this.component.getCSSVariable('--border-color', '.po-chart'); + const seriePie = { + name: serie.name, + value: serie.data, + itemStyle: { borderWidth: borderWidth, borderColor: borderColor, color: color }, + label: { show: false } + }; + this.component.listTypePie[0].data.push(seriePie); + } + } + resolvePx(size: string, selector?: string): number { const token = this.component.getCSSVariable(size, selector); if (token.endsWith('px')) { diff --git a/projects/ui/src/lib/components/po-chart-new/po-chart-grid.utils.spec.ts b/projects/ui/src/lib/components/po-chart-new/po-chart-grid.utils.spec.ts index f7b0836c8..8de56171b 100644 --- a/projects/ui/src/lib/components/po-chart-new/po-chart-grid.utils.spec.ts +++ b/projects/ui/src/lib/components/po-chart-new/po-chart-grid.utils.spec.ts @@ -85,4 +85,57 @@ describe('PoChartGridUtils', () => { expect(option.xAxis['axisLabel'].overflow).toBe('break'); }); }); + + describe('setListPie', () => { + it('should set pie config with radius 95% and center 50% 50% when legend is false', () => { + utils['component'].options = { legend: false } as any; + + utils.setListTypePie(); + + expect(utils['component'].listTypePie).toEqual([ + { + type: 'pie', + center: ['50%', '50%'], + radius: '95%', + emphasis: { focus: 'self' }, + data: [], + blur: { itemStyle: { opacity: 0.4 } } + } + ]); + }); + + it('should set pie config with center 50% 54% when legendVerticalPosition is top', () => { + utils['component'].options = { legend: true, legendVerticalPosition: 'top' } as any; + + utils.setListTypePie(); + + expect(utils['component'].listTypePie).toEqual([ + { + type: 'pie', + center: ['50%', '54%'], + radius: '85%', + emphasis: { focus: 'self' }, + data: [], + blur: { itemStyle: { opacity: 0.4 } } + } + ]); + }); + + it('should set pie config with center 50% 46% when legendVerticalPosition is not top', () => { + utils['component'].options = { legend: true, legendVerticalPosition: 'bottom' } as any; + + utils.setListTypePie(); + + expect(utils['component'].listTypePie).toEqual([ + { + type: 'pie', + center: ['50%', '46%'], + radius: '85%', + emphasis: { focus: 'self' }, + data: [], + blur: { itemStyle: { opacity: 0.4 } } + } + ]); + }); + }); }); diff --git a/projects/ui/src/lib/components/po-chart-new/po-chart-new.component.html b/projects/ui/src/lib/components/po-chart-new/po-chart-new.component.html index 42413894f..875555055 100644 --- a/projects/ui/src/lib/components/po-chart-new/po-chart-new.component.html +++ b/projects/ui/src/lib/components/po-chart-new/po-chart-new.component.html @@ -1,7 +1,11 @@