|
1 | 1 | import {create, cross, difference, groups, InternMap, select} from "d3";
|
2 | 2 | import {Axes, autoAxisTicks, autoScaleLabels} from "./axes.js";
|
3 | 3 | import {Channel, channelSort} from "./channel.js";
|
4 |
| -import {Decoration} from "./decoration.js"; |
| 4 | +import {defined} from "./defined.js"; |
5 | 5 | import {Dimensions} from "./dimensions.js";
|
6 | 6 | import {Legends, exposeLegends} from "./legends.js";
|
7 | 7 | import {arrayify, isOptions, keyword, range, first, second, where} from "./options.js";
|
@@ -99,7 +99,8 @@ export function plot(options = {}) {
|
99 | 99 | for (const mark of marks) {
|
100 | 100 | const channels = markChannels.get(mark) ?? [];
|
101 | 101 | const values = applyScales(channels, scales);
|
102 |
| - const index = mark.filter(markIndex.get(mark), channels, values); |
| 102 | + let index = markIndex.get(mark); |
| 103 | + if (mark.filter != null) index = mark.filter(index, channels, values); |
103 | 104 | const node = mark.render(index, scales, values, dimensions, axes);
|
104 | 105 | if (node != null) svg.appendChild(node);
|
105 | 106 | }
|
@@ -136,15 +137,25 @@ export function plot(options = {}) {
|
136 | 137 | return figure;
|
137 | 138 | }
|
138 | 139 |
|
139 |
| -export class Mark extends Decoration { |
| 140 | +function defaultFilter(index, channels, values) { |
| 141 | + for (const [name, {filter = defined}] of channels) { |
| 142 | + if (name !== undefined && filter !== null) { |
| 143 | + const value = values[name]; |
| 144 | + index = index.filter(i => filter(value[i])); |
| 145 | + } |
| 146 | + } |
| 147 | + return index; |
| 148 | +} |
| 149 | + |
| 150 | +export class Mark { |
140 | 151 | constructor(data, channels = [], options = {}, defaults) {
|
141 |
| - super(); |
142 | 152 | const {facet = "auto", sort, dx, dy, clip} = options;
|
143 | 153 | const names = new Set();
|
144 | 154 | this.data = data;
|
145 | 155 | this.sort = isOptions(sort) ? sort : null;
|
146 | 156 | this.facet = facet == null || facet === false ? null : keyword(facet === true ? "include" : facet, "facet", ["auto", "include", "exclude"]);
|
147 | 157 | const {transform} = basic(options);
|
| 158 | + this.filter = defaults?.filter === undefined ? defaultFilter : defaults.filter; |
148 | 159 | this.transform = transform;
|
149 | 160 | if (defaults !== undefined) channels = styles(this, options, channels, defaults);
|
150 | 161 | this.channels = channels.filter(channel => {
|
@@ -321,7 +332,8 @@ class Facet extends Mark {
|
321 | 332 | for (let i = 0; i < marks.length; ++i) {
|
322 | 333 | const mark = marks[i];
|
323 | 334 | const values = marksValues[i];
|
324 |
| - const index = mark.filter(marksFacetIndex[i], marksChannels[i], values); |
| 335 | + let index = marksFacetIndex[i]; |
| 336 | + if (mark.filter != null) mark.filter(index, marksChannels[i], values); |
325 | 337 | const node = mark.render(index, scales, values, subdimensions);
|
326 | 338 | if (node != null) this.appendChild(node);
|
327 | 339 | }
|
|
0 commit comments