} from '@angular/core';
import * as Chart from 'chart.js';
-import * as _ from 'lodash';
+import _ from 'lodash';
import { PluginServiceGlobalRegistrationAndOptions } from 'ng2-charts';
-import { ChartTooltip } from '../../../shared/models/chart-tooltip';
-import { DimlessBinaryPipe } from '../../../shared/pipes/dimless-binary.pipe';
-import { DimlessPipe } from '../../../shared/pipes/dimless.pipe';
+import { ChartTooltip } from '~/app/shared/models/chart-tooltip';
+import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
+import { DimlessPipe } from '~/app/shared/pipes/dimless.pipe';
+import styles from '~/styles.scss';
@Component({
selector: 'cd-health-pie',
colors: [
{
backgroundColor: [
- '--color-green',
- '--color-yellow',
- '--color-orange',
- '--color-red',
- '--color-blue'
+ styles.chartHealthColorGreen,
+ styles.chartHealthColorYellow,
+ styles.chartHealthColorOrange,
+ styles.chartHealthColorRed,
+ styles.chartHealthColorBlue
]
}
],
tooltips: {
enabled: true,
displayColors: false,
- backgroundColor: 'rgba(0,0,0,0.8)',
+ backgroundColor: styles.chartHealthTootlipBgColor,
cornerRadius: 0,
bodyFontSize: 14,
bodyFontStyle: '600',
{
id: 'center_text',
beforeDraw(chart: Chart) {
- const defaultFontColorA = '#151515';
- const defaultFontColorB = '#72767B';
const defaultFontFamily = 'Helvetica Neue, Helvetica, Arial, sans-serif';
Chart.defaults.global.defaultFontFamily = defaultFontFamily;
const ctx = chart.ctx;
ctx.textBaseline = 'middle';
ctx.font = `24px ${defaultFontFamily}`;
- ctx.fillStyle = defaultFontColorA;
+ ctx.fillStyle = styles.chartHealthCenterTextColor;
ctx.fillText(label[0], centerX, centerY - 10);
if (label.length > 1) {
ctx.font = `14px ${defaultFontFamily}`;
- ctx.fillStyle = defaultFontColorB;
+ ctx.fillStyle = styles.chartHealthCenterTextDescriptionColor;
ctx.fillText(label[1], centerX, centerY + 10);
}
ctx.restore();
_.merge(this.chartConfig, this.config);
- this.setColorsFromCssVars();
-
this.prepareFn.emit([this.chartConfig, this.data]);
}
this.setChartSliceBorderWidth();
}
- private setColorsFromCssVars() {
- this.chartConfig.colors.forEach(
- (colorEl: { backgroundColor: string[] }, colorIndex: number) => {
- colorEl.backgroundColor.forEach((bgColor: string, bgColorIndex: number) => {
- if (bgColor.startsWith('--')) {
- this.chartConfig.colors[colorIndex].backgroundColor[bgColorIndex] = this.getCssVar(
- bgColor
- );
- }
- });
- }
- );
- }
-
- private getCssVar(name: string): string {
- return getComputedStyle(document.querySelector('.chart-container')).getPropertyValue(name);
- }
-
private getChartTooltipBody(body: string[]) {
const bodySplit = body[0].split(': ');