Skip to content

Commit fb24d61

Browse files
mbostockchaichontat
authored andcommitted
remove duplicates from channel-derived domain (observablehq#1314)
1 parent f693303 commit fb24d61

File tree

4 files changed

+2240
-3
lines changed

4 files changed

+2240
-3
lines changed

src/channel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ascending, descending, rollup, sort} from "d3";
1+
import {ascending, descending, InternSet, rollup, sort} from "d3";
22
import {first, isColor, isEvery, isIterable, isOpacity, labelof, map, maybeValue, range, valueof} from "./options.js";
33
import {registry} from "./scales/index.js";
44
import {isSymbol, maybeSymbol} from "./symbols.js";
@@ -84,8 +84,8 @@ export function channelDomain(channels, facetChannels, data, options) {
8484
const [lo = 0, hi = Infinity] = isIterable(limit) ? limit : limit < 0 ? [limit] : [0, limit];
8585
if (y == null) {
8686
X.domain = () => {
87-
let domain = XV;
88-
if (reverse) domain = domain.slice().reverse();
87+
let domain = Array.from(new InternSet(XV)); // remove any duplicates
88+
if (reverse) domain = domain.reverse();
8989
if (lo !== 0 || hi !== Infinity) domain = domain.slice(lo, hi);
9090
return domain;
9191
};

0 commit comments

Comments
 (0)