Skip to content

Commit

Permalink
fix: fix color
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 12, 2020
1 parent 9be886b commit 05d7a2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {AfterViewInit, Component, Input, OnInit} from '@angular/core';
import marked from 'marked';
import {ReporterChartModel} from '../model/reporter-chart.model';
import d3 from 'd3';

@Component({
selector: 'component-markdown-reporter',
Expand Down Expand Up @@ -28,6 +29,16 @@ export class MarkdownReporterComponent implements OnInit, AfterViewInit {
this.buildData(tokens);
}

private getColorByIndex(i: number) {
const length = 20;
// tslint: disable-next-line
const color = d3.scale.linear().domain([1, length])
.interpolate(d3.interpolateHcl as any)
.range([d3.rgb('#007AFF'), d3.rgb('#FFF500')]);

return color(i);
}

private buildData(tokens: marked.Token[]) {
for (const token of tokens) {
if (token.type === 'table') {
Expand All @@ -36,10 +47,13 @@ export class MarkdownReporterComponent implements OnInit, AfterViewInit {
title: token.header[0],
chartData: []
};
for (const cell of token.cells) {
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < token.cells.length; i++) {
const cell = token.cells[i];
chart.chartData.push({
name: cell[0],
value: parseFloat(cell[1])
value: parseFloat(cell[1]),
itemStyle: {color: this.getColorByIndex(i)}
});
}
this.charts.push(chart);
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/components/model/reporter-chart.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export interface ReporterChartModel {
chartData?: {
name: string;
value: number;
itemStyle: any;
}[];
}

0 comments on commit 05d7a2d

Please sign in to comment.