Skip to content

Commit f4403cc

Browse files
jhonyeduardopo-ui-dev
authored andcommitted
feat(chart): adiciona gráfico do tipo donut
O gráfico do tipo Donut possui um formato de rosca que exibe os valores proporcionalmente ao valor total do gráfico. Fixes DTHFUI-1736
1 parent eb8c289 commit f4403cc

24 files changed

+1321
-802
lines changed

projects/ui/karma.conf.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ module.exports = function (config) {
3232
lines: 80,
3333
functions: 80,
3434
overrides: {
35+
'src/lib/components/po-chart/po-chart-types/po-chart-donut/po-chart-donut.component.ts': {
36+
branches: 50
37+
},
38+
'src/lib/components/po-chart/po-chart-types/po-chart-pie/po-chart-pie.component.ts': {
39+
branches: 50
40+
},
3541
'src/lib/components/po-chart/po-chart-types/po-chart-dynamic-type.component.ts': {
3642
branches: 50
3743
},

projects/ui/src/lib/components/po-chart/enums/po-chart-type.enum.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
*
44
* @description
55
*
6-
* *Enum* `PoChartType` para os tipos de gráficos.
6+
* *Enum* `PoChartType` para especificação dos tipos de gráficos.
77
*/
88
export enum PoChartType {
99

1010
/**
11-
* **Gráfico pizza:** utilizado para exibir proporções de valores a partir de um todo.
11+
* Exibe os dados em formato de rosca, dividindo em partes proporcionais.
12+
*/
13+
Donut = 'donut',
14+
15+
/**
16+
* Exibe os dados em formato circular, dividindo proporcionalmente em fatias.
1217
*/
1318
Pie = 'pie'
1419

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './enums/po-chart-type.enum';
2-
export * from './interfaces/po-chart-series.interface';
2+
export * from './po-chart-types/po-chart-donut/po-chart-donut-series.interface';
3+
export * from './po-chart-types/po-chart-pie/po-chart-pie-series.interface';
34
export * from './po-chart.component';
45

56
export * from './po-chart.module';

projects/ui/src/lib/components/po-chart/po-chart-base.component.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EventEmitter } from '@angular/core';
33
import { expectPropertiesValues } from './../../util-test/util-expect.spec';
44

55
import { PoChartBaseComponent } from './po-chart-base.component';
6+
import { PoChartType } from './enums/po-chart-type.enum';
67

78
class PoCharComponent extends PoChartBaseComponent {
89

@@ -54,18 +55,17 @@ describe('PoChartBaseComponent:', () => {
5455
expect(component.rebuildComponent).toHaveBeenCalled();
5556
});
5657

57-
// TODO quando aceitar types
58-
// it('p-type: should update property with valid values.', () => {
59-
// const validValues = (<any>Object).values(PoChartType);
58+
it('p-type: should update property with valid values.', () => {
59+
const validValues = (<any>Object).values(PoChartType);
6060

61-
// expectPropertiesValues(poChartBase, 'type', validValues, validValues);
62-
// });
61+
expectPropertiesValues(component, 'type', validValues, validValues);
62+
});
6363

64-
// it('p-type: should update property with `PoChartType.Pie` if contains invalid values', () => {
65-
// const invalidValues = [undefined, null, '', true, false, 0, 1, 'aa', [], {}];
64+
it('p-type: should update property with `PoChartType.Pie` if contains invalid values', () => {
65+
const invalidValues = [undefined, null, '', true, false, 0, 1, 'aa', [], {}];
6666

67-
// expectPropertiesValues(poChartBase, 'type', invalidValues, PoChartType.Pie);
68-
// });
67+
expectPropertiesValues(component, 'type', invalidValues, PoChartType.Pie);
68+
});
6969

7070
});
7171

projects/ui/src/lib/components/po-chart/po-chart-base.component.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ import { EventEmitter, Input, Output } from '@angular/core';
33
import { convertToInt, isTypeof } from '../../utils/util';
44

55
import { PoChartType } from './enums/po-chart-type.enum';
6-
import { PoPieChartSeries } from './interfaces/po-chart-series.interface';
6+
import { PoDonutChartSeries } from './po-chart-types/po-chart-donut/po-chart-donut-series.interface';
7+
import { PoPieChartSeries } from './po-chart-types/po-chart-pie/po-chart-pie-series.interface';
78

89
const poChartDefaultHeight = 400;
9-
const poChartTypeDefault = PoChartType.Pie;
1010
const poChartMinHeight = 200;
11+
const poChartTypeDefault = PoChartType.Pie;
1112

1213
/**
1314
* @description
1415
*
1516
* O `po-chart` é um componente para renderização de dados através de gráficos, com isso facilitando a compreensão e tornando a
1617
* visualização destes dados mais agradável.
1718
*
18-
* Este componente também possibilita a definição das seguintes propriedades: altura do gráfico; série(s) que irão compor o gráfico;
19-
* título do gráfico; e tipo de gráfico.
19+
* Este componente também possibilita a definição das seguintes propriedades:
20+
* - altura
21+
* - series
22+
* - tipo
23+
* - título
2024
*
2125
* Além das definições de propriedades, também é possível definir uma ação que será executada ao clicar em determinado elemento do gráfico
2226
* e outra que será executada ao passar o *mouse* sobre o elemento.
@@ -64,29 +68,35 @@ export abstract class PoChartBaseComponent {
6468
}
6569

6670
/**
67-
* Coleção de objetos que implementam a interface `PoPieChartSeries`, para definição dos elementos do gráfico que serão criados
68-
* dinâmicamente.
71+
* @description
72+
*
73+
* Define os elementos do gráfico que serão criados dinamicamente.
74+
*
75+
* > A coleção de objetos deve implementar alguma das interfaces abaixo:
76+
* - `PoDonutChartSeries`
77+
* - `PoPieChartSeries`
6978
*/
70-
@Input('p-series') series: Array<PoPieChartSeries>;
79+
@Input('p-series') series: Array<PoDonutChartSeries | PoPieChartSeries>;
7180

7281
/** Define o título do gráfico. */
7382
@Input('p-title') title?: string;
7483

75-
// TODO quando houver a necessidade de informar um type.
76-
// /**
77-
// * @optional
78-
// *
79-
// * @description
80-
// *
81-
// * Define o tipo de gráfico.
82-
// *
83-
// * > Veja os valores válidos no *enum* `PoChartType`.
84-
// *
85-
// * @default `PoChartType.Pie`
86-
// */
87-
// @Input('p-type') set type(value: PoChartType) {
88-
// this._type = (<any>Object).values(PoChartType).includes(value) ? value : poChartTypeDefault;
89-
// }
84+
/**
85+
* @optional
86+
*
87+
* @description
88+
*
89+
* Define o tipo de gráfico.
90+
*
91+
* > Veja os valores válidos no *enum* `PoChartType`.
92+
*
93+
* @default `PoChartType.Pie`
94+
*/
95+
@Input('p-type') set type(value: PoChartType) {
96+
this._type = (<any>Object).values(PoChartType).includes(value) ? value : poChartTypeDefault;
97+
98+
this.rebuildComponent();
99+
}
90100

91101
get type(): PoChartType {
92102
return this._type;

projects/ui/src/lib/components/po-chart/po-chart-colors.constant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ export const PoChartColors = [
1313
['#0C6C94', '#00BAD5', '#00A7C7', '#0197B8', '#0088AC', '#23789F', '#2B6992', '#315C87', '#364E7C', '#36436F', '#32285C'],
1414
['#0C6C94', '#00BAD5', '#00A7C7', '#0197B8', '#0088AC', '#23789F', '#2B6992', '#315C87', '#364E7C', '#36436F', '#333565', '#32285C'],
1515
];
16+
17+
// Cores que será utilizado texto preto
18+
export const PoSeriesTextBlack = [ '#94DAE2', '#C9ECF0' ];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface PoCircularChartSeries {
2+
3+
/** Define o valor da categoria do objeto. */
4+
category: string;
5+
6+
/** Define o valor do objeto. */
7+
value: number;
8+
9+
}

projects/ui/src/lib/components/po-chart/po-chart-types/po-chart-pie/po-chart-pie.constant.ts renamed to projects/ui/src/lib/components/po-chart/po-chart-types/po-chart-circular/po-chart-circular.constant.ts

File renamed without changes.

0 commit comments

Comments
 (0)