From a68685d89501505b4c7f62ba254ef81b6236f289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 23 Nov 2021 12:42:38 +0100 Subject: [PATCH] warn about ignored indices for #493 #536 --- src/defined.js | 9 ++++++++- src/marks/dot.js | 3 +-- src/marks/text.js | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/defined.js b/src/defined.js index b62f97d8b2..44f7484f8a 100644 --- a/src/defined.js +++ b/src/defined.js @@ -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; } diff --git a/src/marks/dot.js b/src/marks/dot.js index 2fdb88a3e7..be3e0a2106 100644 --- a/src/marks/dot.js +++ b/src/marks/dot.js @@ -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) diff --git a/src/marks/text.js b/src/marks/text.js index 7666df16e3..060830b0a1 100644 --- a/src/marks/text.js +++ b/src/marks/text.js @@ -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")