Skip to content

Commit

Permalink
Sequential colouring of integers
Browse files Browse the repository at this point in the history
  • Loading branch information
ckitsanelis committed Dec 13, 2023
1 parent d7948c0 commit 99b0e47
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/viewer/LogFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,24 @@ export default class LogFile {

private static computeColors(header: Header, values: string[]) {
let colorizer: (s: string) => string;

if (header.name === "Line" || header.name === "Structure") {
colorizer = (v) => interpolateTurbo(values.indexOf(v) / values.length);
if (this.containsOnlyInts(values)) {
colorizer = scaleSequential().domain(extent(values)).interpolator(interpolateTurbo);
} else if (header.type === "string") {
const uniqueValues = [...new Set(values)].sort();
colorizer = (v) => interpolateTurbo(uniqueValues.indexOf(v) / uniqueValues.length);
} else if (header.type === "number") {
colorizer = scaleSequential().domain(extent(values)).interpolator(interpolateTurbo);
}
}

return values.map((l) => colorizer(l));
}

private static containsOnlyInts(items: string[]) {
for (const i of items){
if (!Number(i))
return false;
}
return true;
}

private getStaticHeadersSize() {
let size = this.contentHeaders.length;
if (!this.contentHeaders.includes("Line"))
Expand Down

0 comments on commit 99b0e47

Please sign in to comment.