Skip to content

Commit

Permalink
dump categorical labels and alternative way to describe category desc
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Oct 13, 2016
1 parent 481deab commit 7900d6c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,13 +1265,19 @@ export class CategoricalColumn extends ValueColumn<string> implements ICategoric
labels = d3.map<string>();
desc.categories.forEach((cat, i) => {
if (typeof cat === 'string') {
//just the category value
cats.push(cat);
} else {
cats.push(cat.name);
//the name or value of the category
cats.push(cat.name || cat.value);
//optional label mapping
if (cat.label) {
labels.set(cat.name, cat.label);
}
cols[i] = cat.color;
//optional color
if (cat.color) {
cols[i] = cat.color;
}
}
});
this.catLabels = labels;
Expand Down Expand Up @@ -1362,6 +1368,9 @@ export class CategoricalColumn extends ValueColumn<string> implements ICategoric
range: this.colors.range(),
separator: this.separator
};
if (this.catLabels !== null && !this.catLabels.empty()) {
r.labels = this.catLabels.entries();
}
return r;
}

Expand All @@ -1371,6 +1380,10 @@ export class CategoricalColumn extends ValueColumn<string> implements ICategoric
if (dump.colors) {
this.colors.domain(dump.colors.domain).range(dump.colors.range);
}
if (dump.labels) {
this.catLabels = d3.map<string>();
dump.labels.forEach((e) => this.catLabels.set(e.key, e.value));
}
this.separator = dump.separator || this.separator;
}

Expand Down

0 comments on commit 7900d6c

Please sign in to comment.