Skip to content

Commit

Permalink
warn about ignored indices
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Nov 23, 2021
1 parent 2da25ec commit a68685d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/defined.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ export function nonempty(x) {
}

export function filter(index, ...channels) {
const ignored = [];
for (const c of channels) {
if (c) index = index.filter(i => defined(c[i]));
if (c) {
const test = typeof c === "function" ? c : i => defined(c[i]);
index = index.filter(i => test(i) || (ignored.push(i), false));
}
}
if (ignored.length > 0) {
console.warn(`ignored indices:`, ignored);
}
return index;
}
Expand Down
3 changes: 1 addition & 2 deletions src/marks/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class Dot extends Mark {
) {
const {x: X, y: Y, r: R} = channels;
const {dx, dy} = this;
let index = filter(I, X, Y);
if (R) index = index.filter(i => positive(R[i]));
const index = filter(I, X, Y, R && (i => positive(R[i])));
return create("svg:g")
.call(applyIndirectStyles, this)
.call(applyTransform, x, y, offset + dx, offset + dy)
Expand Down
2 changes: 1 addition & 1 deletion src/marks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Text extends Mark {
const {x: X, y: Y, rotate: R, text: T, fontSize: FS} = channels;
const {width, height, marginTop, marginRight, marginBottom, marginLeft} = dimensions;
const {rotate} = this;
const index = filter(I, X, Y, R).filter(i => nonempty(T[i]));
const index = filter(I, X, Y, R, i => nonempty(T[i]));
const cx = (marginLeft + width - marginRight) / 2;
const cy = (marginTop + height - marginBottom) / 2;
return create("svg:g")
Expand Down

0 comments on commit a68685d

Please sign in to comment.