Skip to content

Commit

Permalink
Fix colouring of numerical columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ckitsanelis committed Dec 14, 2023
1 parent 99b0e47 commit 45a6d67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/viewer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ export default class App extends React.Component<Props, State> {
else this.setState({ rules: newRules });
}

handleSelectDialog(selectedCols: boolean[], selectedColsMini: boolean[], isClose: boolean) {
handleSelectDialog(selectedColumns: boolean[], selectedColumnsMini: boolean[], isClose: boolean) {
if (isClose === true) {
this.setState({
selectedColumns: selectedCols,
selectedColumnsMini: selectedColsMini,
logFile: this.state.logFile.setSelectedColumns(selectedCols, selectedColsMini),
selectedColumns: selectedColumns,
selectedColumnsMini: selectedColumnsMini,
logFile: this.state.logFile.setSelectedColumns(selectedColumns, selectedColumnsMini),
showSelectDialog: false,
});
}
Expand Down
16 changes: 6 additions & 10 deletions src/viewer/LogFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ export default class LogFile {
logFile.copyDefaultColumnColors(this.columnsColors);
logFile.computeRulesValuesAndColors(rules);
return logFile.setSelectedColumns(updatedSelected, updatedSelectedMini);

// Old solution
// this.updateSelectedColumns(rules);
// this.updateHeaders(rules);
// this.computeRulesValuesAndColors(rules);
// return this;
}

updateSelectedColumns(rules: Rule[]) {
Expand Down Expand Up @@ -180,8 +174,10 @@ export default class LogFile {

private static computeColors(header: Header, values: string[]) {
let colorizer: (s: string) => string;
if (this.containsOnlyInts(values)) {
colorizer = scaleSequential().domain(extent(values)).interpolator(interpolateTurbo);
if (this.containsOnlyNumbers(values)) {
let uniqueValues = [...new Set(values)];
const sortedNumbers = uniqueValues.map(Number).sort(function(a,b) { return a - b;});
colorizer = scaleSequential().domain(extent(sortedNumbers)).interpolator(interpolateTurbo);
} else if (header.type === "string") {
const uniqueValues = [...new Set(values)].sort();
colorizer = (v) => interpolateTurbo(uniqueValues.indexOf(v) / uniqueValues.length);
Expand All @@ -190,9 +186,9 @@ export default class LogFile {
return values.map((l) => colorizer(l));
}

private static containsOnlyInts(items: string[]) {
private static containsOnlyNumbers(items: string[]) {
for (const i of items){
if (!Number(i))
if (!Number(+i) && (+i !== 0))
return false;
}
return true;
Expand Down

0 comments on commit 45a6d67

Please sign in to comment.