Skip to content

Commit

Permalink
avod duplicate columns
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Nov 17, 2018
1 parent cbea9f0 commit 32ede10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/builder/DataBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,20 @@ export default class DataBuilder extends LineUpBuilder {
* @returns {LocalDataProvider}
*/
buildData() {
const columns = this.columns.map((d) => typeof d === 'function' ? d(this.data) : d);
// last come survived separted by label to be able to override columns
const columns: IColumnDesc[] = [];
const contained = new Set<string>();
for (const col of this.columns) {
const c = typeof col === 'function' ? col(this.data) : col;
const key = `${c.type}@${c.label}`;
if (!contained.has(key)) {
columns.push(c);
contained.add(key);
continue;
}
const oldPos = columns.findIndex((d) => key === `${d.type}@${d.label}`);
columns.splice(oldPos, 1, c); // replace with new one
}
if (this._deriveColors) {
deriveColors(columns);
}
Expand Down
4 changes: 2 additions & 2 deletions src/builder/adapter/lineup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ export class Adapter {
this.prevColumns = ctx;
const columns = ctx.columns.map((d) => Object.assign({}, d)); // work on copy
if (ctx.deriveColumns) {
const labels = new Set(columns.map((d) => d.label));
const labels = new Set(columns.map((d) => `${d.type}@${d.label}`));
const derived = deriveColumnDescriptions(data, {columns: ctx.deriveColumnNames});
for (const derive of derived) {
if (labels.has(derive.label)) { // skip same name
if (labels.has(`${derive.type}@${derive.label}`)) { // skip same name
continue;
}
columns.push(derive);
Expand Down

0 comments on commit 32ede10

Please sign in to comment.