From 443b9f512e154fdf005053685f111c17e924cb12 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 8 Apr 2024 18:51:37 -0400 Subject: [PATCH 1/2] initial commit --- packages/ott-vis-panel/src/colors.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/ott-vis-panel/src/colors.ts b/packages/ott-vis-panel/src/colors.ts index 6490f91e2..6a663f306 100644 --- a/packages/ott-vis-panel/src/colors.ts +++ b/packages/ott-vis-panel/src/colors.ts @@ -1,12 +1,23 @@ +import * as d3 from "d3"; + class ColorProvider { + private color: d3.ScaleOrdinal; + private assignments: Map; + + constructor() { + this.color = d3.scaleOrdinal(d3.schemeCategory10); + this.assignments = new Map(); + } + public assign(thing: string): string { - // TODO: implement - return ""; + if (!this.assignments.has(thing)) { + this.assignments.set(thing, this.color(thing)); + } + return this.assignments.get(thing) as string; } - public assignments(): Map { - // TODO: implement - return new Map(); + public getAssignments(): Map { + return this.assignments; } } From d7a29bf570635a56e9493527da58f05c6469c85c Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 8 Apr 2024 19:10:36 -0400 Subject: [PATCH 2/2] requested changes --- packages/ott-vis-panel/src/colors.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/ott-vis-panel/src/colors.ts b/packages/ott-vis-panel/src/colors.ts index 6a663f306..27a424350 100644 --- a/packages/ott-vis-panel/src/colors.ts +++ b/packages/ott-vis-panel/src/colors.ts @@ -1,19 +1,14 @@ import * as d3 from "d3"; class ColorProvider { - private color: d3.ScaleOrdinal; - private assignments: Map; - - constructor() { - this.color = d3.scaleOrdinal(d3.schemeCategory10); - this.assignments = new Map(); - } + private color = d3.scaleOrdinal(d3.schemeCategory10); + private assignments: Map = new Map(); public assign(thing: string): string { if (!this.assignments.has(thing)) { this.assignments.set(thing, this.color(thing)); } - return this.assignments.get(thing) as string; + return this.assignments.get(thing)!; } public getAssignments(): Map {