From 3a81ada8773a828e626893ce54c716f6abd6fc65 Mon Sep 17 00:00:00 2001 From: Lyq322 Date: Sun, 22 Oct 2023 13:29:47 -0500 Subject: [PATCH 01/10] Create custom colors for linear scaled charts Includes all bar charts, line chart, all area charts, bubble chart, heat map and calendar and box chart. --- .../ngx-charts/src/lib/common/color.helper.ts | 21 +++++- .../src/lib/heat-map/heat-map.component.ts | 3 +- src/app/app.component.html | 43 +++++++++++- src/app/app.component.ts | 30 +++++++- src/app/chartTypes.ts | 69 ++++++++++++------- src/app/data.ts | 24 +++---- 6 files changed, 147 insertions(+), 43 deletions(-) diff --git a/projects/swimlane/ngx-charts/src/lib/common/color.helper.ts b/projects/swimlane/ngx-charts/src/lib/common/color.helper.ts index f1aec711f..86b0ff2c8 100644 --- a/projects/swimlane/ngx-charts/src/lib/common/color.helper.ts +++ b/projects/swimlane/ngx-charts/src/lib/common/color.helper.ts @@ -27,10 +27,18 @@ export class ColorHelper { return cs.name === scheme; }); } - this.colorDomain = scheme.domain; + + this.customColors = customColors; + + if (this.customColors) { + this.colorDomain = this.customColors; + } + else { + this.colorDomain = scheme.domain; + } + this.scaleType = type; this.domain = domain; - this.customColors = customColors; this.scale = this.generateColorScheme(scheme, type, this.domain); } @@ -56,7 +64,13 @@ export class ColorHelper { break; case ScaleType.Linear: { - const colorDomain = [...scheme.domain]; + let colorDomain; + if (this.customColors) { + colorDomain = [...this.customColors]; + } + else { + colorDomain = [...scheme.domain]; + } if (colorDomain.length === 1) { colorDomain.push(colorDomain[0]); this.colorDomain = colorDomain; @@ -114,6 +128,7 @@ export class ColorHelper { .domain(this.domain as number[]) .range([0, 1]); + console.log(this.colorDomain); const colorValueScale = scaleBand().domain(this.colorDomain).range([0, 1]); const endColor = this.getColor(value); diff --git a/projects/swimlane/ngx-charts/src/lib/heat-map/heat-map.component.ts b/projects/swimlane/ngx-charts/src/lib/heat-map/heat-map.component.ts index 31bdc7a61..90e33f218 100644 --- a/projects/swimlane/ngx-charts/src/lib/heat-map/heat-map.component.ts +++ b/projects/swimlane/ngx-charts/src/lib/heat-map/heat-map.component.ts @@ -300,7 +300,8 @@ export class HeatMapComponent extends BaseChartComponent { } setColors(): void { - this.colors = new ColorHelper(this.scheme, this.scaleType, this.valueDomain); + console.log("heat", this.customColors); + this.colors = new ColorHelper(this.scheme, this.scaleType, this.valueDomain, this.customColors); } getLegendOptions(): LegendOptions { diff --git a/src/app/app.component.html b/src/app/app.component.html index 6dd4b53cc..95bc09f94 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -45,6 +45,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="single" [animations]="animations" [gradient]="gradient" @@ -82,6 +83,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="multi" [animations]="animations" [gradient]="gradient" @@ -120,6 +122,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="multi" [animations]="animations" [gradient]="gradient" @@ -158,6 +161,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="multi" [animations]="animations" [gradient]="gradient" @@ -194,6 +198,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="multi" [animations]="animations" [gradient]="gradient" @@ -230,6 +235,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="multi" [animations]="animations" [gradient]="gradient" @@ -264,6 +270,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="multi" [animations]="animations" [gradient]="gradient" @@ -297,6 +304,7 @@ class="chart-container" [view]="view" [scheme]="colorScheme" + [customColors]="customColorsNonlinear" [results]="single" [animations]="animations" [legend]="showLegend" @@ -320,6 +328,7 @@ class="chart-container" [view]="view" [scheme]="colorScheme" + [customColors]="customColorsNonlinear" [results]="single" [valueFormatting]="valueFormatting" [animations]="animations" @@ -336,6 +345,7 @@ class="chart-container" [view]="view" [scheme]="colorScheme" + [customColors]="customColorsNonlinear" [results]="single" [animations]="animations" [tooltipDisabled]="tooltipDisabled" @@ -351,6 +361,7 @@ class="chart-container" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="dateDataWithOrWithoutRange" [animations]="animations" [legend]="showLegend" @@ -391,6 +402,7 @@ class="chart-container" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="multi" [animations]="animations" [legend]="showLegend" @@ -440,6 +452,7 @@ [yScaleMax]="yScaleMax" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [roundDomains]="roundDomains" [tooltipDisabled]="tooltipDisabled" [minRadius]="minRadius" @@ -461,6 +474,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="dateData" [animations]="animations" [legend]="showLegend" @@ -500,6 +514,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="dateData" [animations]="animations" [legend]="showLegend" @@ -538,6 +553,7 @@ [view]="view" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="dateData" [animations]="animations" [legend]="showLegend" @@ -597,6 +613,7 @@ (select)="onSelect($event)" > + @@ -678,6 +698,7 @@ emptyColor="#1e222e" [results]="single" [animations]="animations" + [customColors]="customColorsNonlinear" (select)="select($event)" > @@ -738,6 +759,7 @@ class="chart-container" [view]="view" [scheme]="colorScheme" + [customColors]="customColorsNonlinear" cardColor="#232837" emptyColor="#1e222e" [results]="statusData" @@ -769,6 +791,7 @@ [margin]="margin ? [marginTop, marginRight, marginBottom, marginLeft] : null" [tooltipDisabled]="tooltipDisabled" [showText]="showText" + [customColors]="customColorsNonlinear" (select)="select($event)" (activate)="activate($event)" (deactivate)="deactivate($event)" @@ -785,6 +808,7 @@ [value]="gaugeValue" [previousValue]="gaugePreviousValue" [units]="gaugeUnits" + [customColors]="customColorsNonlinear" (select)="select($event)" > @@ -802,6 +826,7 @@ class="chart-container" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="plotData" [animations]="animations" [legend]="false" @@ -835,6 +860,7 @@ class="chart-container" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [results]="plotData" [animations]="animations" [legend]="false" @@ -886,6 +912,7 @@

[animations]="animations" [tooltipDisabled]="tooltipDisabled" [gradient]="gradient" + [customColors]="customColorsNonlinear" (select)="treemapSelect($event)" > @@ -922,6 +949,7 @@

[autoScale]="autoScale" [scheme]="colorScheme" [schemeType]="schemeType" + [customColors]="customColors" [roundDomains]="roundDomains" [tooltipDisabled]="tooltipDisabled" [minRadius]="minRadius" @@ -1194,7 +1222,7 @@

[hidden]="!colorVisible" style="margin-left: 10px" [ngModel]="schemeType" - (ngModelChange)="schemeType = $event" + (ngModelChange)="setSchemeType($event)" > @@ -1219,6 +1247,19 @@


+
+ +
+
+
+ +
+
+ +
- +
- +
-
- -
-
- -