From 57d67f24f1e97a48cc43344831f2b7b57b381a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 9 Mar 2021 18:15:30 +0100 Subject: [PATCH] {filter, transform} closes #138 supersedes #194 --- src/mark.js | 8 ++++++-- src/marks/area.js | 3 ++- src/marks/bar.js | 3 ++- src/marks/dot.js | 3 ++- src/marks/line.js | 3 ++- src/marks/link.js | 3 ++- src/marks/rect.js | 3 ++- src/marks/rule.js | 3 ++- src/marks/text.js | 3 ++- src/marks/tick.js | 3 ++- 10 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/mark.js b/src/mark.js index a2aa0c38bd..fc98346596 100644 --- a/src/mark.js +++ b/src/mark.js @@ -7,8 +7,12 @@ const TypedArray = Object.getPrototypeOf(Uint8Array); const objectToString = Object.prototype.toString; export class Mark { - constructor(data, channels = [], transform) { - if (transform == null) transform = undefined; + constructor(data, channels = [], {filter, transform} = {}) { + if (filter != null) transform = maybeTransform({transform}, (data, facets) => ({ + data, + index: facets.map(I => I.filter(i => filter(data[i], i, take(data, I)))) + })); + const names = new Set(); this.data = arrayify(data); this.transform = transform; diff --git a/src/marks/area.js b/src/marks/area.js index 7613dde2f2..12abe2d97d 100644 --- a/src/marks/area.js +++ b/src/marks/area.js @@ -21,6 +21,7 @@ export class Area extends Mark { curve, tension, sort, + filter, transform = maybeSort(sort), ...style } = {} @@ -41,7 +42,7 @@ export class Area extends Mark { {name: "fill", value: vfill, scale: "color", optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); this.curve = Curve(curve, tension); Style(this, { diff --git a/src/marks/bar.js b/src/marks/bar.js index 741629d2dc..4cf0eb1cab 100644 --- a/src/marks/bar.js +++ b/src/marks/bar.js @@ -20,6 +20,7 @@ export class AbstractBar extends Mark { insetLeft = inset, rx, ry, + filter, transform, ...style } = {} @@ -35,7 +36,7 @@ export class AbstractBar extends Mark { {name: "fill", value: vfill, scale: "color", optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); Style(this, {fill: cfill, stroke: cstroke, ...style}); this.insetTop = number(insetTop); diff --git a/src/marks/dot.js b/src/marks/dot.js index 812303d219..0bb6485058 100644 --- a/src/marks/dot.js +++ b/src/marks/dot.js @@ -15,6 +15,7 @@ export class Dot extends Mark { title, fill, stroke, + filter, transform, ...style } = {} @@ -33,7 +34,7 @@ export class Dot extends Mark { {name: "fill", value: vfill, scale: "color", optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); this.r = cr; Style(this, { diff --git a/src/marks/line.js b/src/marks/line.js index 2c31a32f44..348a6214a5 100644 --- a/src/marks/line.js +++ b/src/marks/line.js @@ -19,6 +19,7 @@ export class Line extends Mark { curve, tension, sort, + filter, transform = maybeSort(sort), ...style } = {} @@ -37,7 +38,7 @@ export class Line extends Mark { {name: "fill", value: vfill, scale: "color", optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); this.curve = Curve(curve, tension); Style(this, { diff --git a/src/marks/link.js b/src/marks/link.js index 8b74bcf5e8..fdeef9a176 100644 --- a/src/marks/link.js +++ b/src/marks/link.js @@ -15,6 +15,7 @@ export class Link extends Mark { z, title, stroke, + filter, transform, ...style } = {} @@ -31,7 +32,7 @@ export class Link extends Mark { {name: "title", value: title, optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); Style(this, {stroke: cstroke, ...style}); } diff --git a/src/marks/rect.js b/src/marks/rect.js index 1d41be45a0..de545b93a2 100644 --- a/src/marks/rect.js +++ b/src/marks/rect.js @@ -23,6 +23,7 @@ export class Rect extends Mark { insetLeft = inset, rx, ry, + filter, transform, ...style } = {} @@ -41,7 +42,7 @@ export class Rect extends Mark { {name: "fill", value: vfill, scale: "color", optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); Style(this, {fill: cfill, stroke: cstroke, ...style}); this.insetTop = number(insetTop); diff --git a/src/marks/rule.js b/src/marks/rule.js index 922be78918..9253a5b9b4 100644 --- a/src/marks/rule.js +++ b/src/marks/rule.js @@ -14,6 +14,7 @@ export class RuleX extends Mark { z, title, stroke, + filter, transform, ...style } = {} @@ -29,7 +30,7 @@ export class RuleX extends Mark { {name: "title", value: title, optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); Style(this, {stroke: cstroke, ...style}); } diff --git a/src/marks/text.js b/src/marks/text.js index c07ca27680..263a72ab64 100644 --- a/src/marks/text.js +++ b/src/marks/text.js @@ -14,6 +14,7 @@ export class Text extends Mark { text = indexOf, title, fill, + filter, transform, textAnchor, fontFamily, @@ -37,7 +38,7 @@ export class Text extends Mark { {name: "title", value: title, optional: true}, {name: "fill", value: vfill, scale: "color", optional: true} ], - transform + {filter, transform} ); Style(this, {fill: cfill, ...style}); this.textAnchor = string(textAnchor); diff --git a/src/marks/tick.js b/src/marks/tick.js index dc7b1ef1b4..f9c48899cc 100644 --- a/src/marks/tick.js +++ b/src/marks/tick.js @@ -12,6 +12,7 @@ class AbstractTick extends Mark { z, title, stroke, + filter, transform, ...style } = {} @@ -25,7 +26,7 @@ class AbstractTick extends Mark { {name: "title", value: title, optional: true}, {name: "stroke", value: vstroke, scale: "color", optional: true} ], - transform + {filter, transform} ); Style(this, {stroke: cstroke, ...style}); }