--- /dev/null
+export enum HealthPieColor {
+ // Names inspired by https://encycolorpedia.com
+ MEDIUM_LIGHT_SHADE_PINK_RED = '#ff7592',
+ MEDIUM_DARK_SHADE_CYAN_BLUE = '#1d699d',
+ LIGHT_SHADE_BROWN = '#fcd0a1',
+ MEDIUM_DARK_SHADE_BLUE_MAGENTA = '#564d65',
+ SHADE_GREEN_CYAN = '#2cda9d'
+}
expect(component.chart.chartType).toEqual('pie');
});
+
+ it('Remove slice border if there is only one slice with non zero value', () => {
+ component.chart.dataset[0].data = [48, 0, 0, 0];
+ component.ngOnChanges();
+
+ expect(component.chart.dataset[0].borderWidth).toEqual(0);
+ });
+
+ it('Keep slice border if there is more than one slice with non zero value', () => {
+ component.chart.dataset[0].data = [48, 0, 1, 0];
+ component.ngOnChanges();
+
+ expect(component.chart.dataset[0].borderWidth).toEqual(1);
+ });
});
} from '@angular/core';
import * as Chart from 'chart.js';
+import * as _ from 'lodash';
import { ChartTooltip } from '../../../shared/models/chart-tooltip';
import { DimlessBinaryPipe } from '../../../shared/pipes/dimless-binary.pipe';
+import { HealthPieColor } from './health-pie-color.enum';
@Component({
selector: 'cd-health-pie',
tooltips: {
enabled: false
}
- },
- colors: [
- {
- borderColor: 'transparent'
- }
- ]
+ }
};
constructor(private dimlessBinary: DimlessBinaryPipe) {}
this.chart.options.legend.display = this.displayLegend;
- const redColor = '#FF6384';
- const blueColor = '#36A2EB';
- const yellowColor = '#FFCD56';
- const greenColor = '#4BC0C0';
this.chart.colors = [
{
- backgroundColor: [redColor, blueColor, yellowColor, greenColor]
+ backgroundColor: [
+ HealthPieColor.MEDIUM_LIGHT_SHADE_PINK_RED,
+ HealthPieColor.MEDIUM_DARK_SHADE_CYAN_BLUE,
+ HealthPieColor.LIGHT_SHADE_BROWN,
+ HealthPieColor.SHADE_GREEN_CYAN,
+ HealthPieColor.MEDIUM_DARK_SHADE_BLUE_MAGENTA
+ ]
}
];
ngOnChanges() {
this.prepareFn.emit([this.chart, this.data]);
+
+ this.setChartSliceBorderWidth(this.chart.dataset[0]);
}
private getChartTooltipBody(body) {
this.chart.chartType = chartTypes[0];
}
}
+
+ private setChartSliceBorderWidth(dataset) {
+ let nonZeroValueSlices = 0;
+ _.forEach(dataset.data, function(slice) {
+ if (slice > 0) {
+ nonZeroValueSlices += 1;
+ }
+ });
+
+ if (nonZeroValueSlices > 1) {
+ this.chart.dataset[0].borderWidth = 1;
+ }
+ }
}