Skip to content

Commit 890e727

Browse files
committed
adopt InternMap
1 parent 7249153 commit 890e727

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"tape-await": "^0.1.2"
4444
},
4545
"dependencies": {
46-
"d3-array": "^2.8.0",
46+
"d3-array": "^2.10.0",
4747
"d3-axis": "^2.0.0",
4848
"d3-color": "^2.0.0",
4949
"d3-interpolate": "^2.0.1",

src/facet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {cross, groups} from "d3-array";
1+
import {cross, groups, InternMap} from "d3-array";
22
import {create} from "d3-selection";
33
import {Mark, first, second} from "./mark.js";
44

@@ -164,7 +164,7 @@ function facetMap(channels) {
164164

165165
class FacetMap {
166166
constructor() {
167-
this._ = new Map();
167+
this._ = new InternMap();
168168
}
169169
has(key) {
170170
return this._.has(key);
@@ -190,7 +190,7 @@ class FacetMap2 extends FacetMap {
190190
set([key1, key2], value) {
191191
const map = super.get(key1);
192192
if (map) map.set(key2, value);
193-
else super.set(key1, new Map([[key2, value]]));
193+
else super.set(key1, new InternMap([[key2, value]]));
194194
return this;
195195
}
196196
}

src/group.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
// Unlike d3.group, this implicitly coerces to a primitive value if possible via
2-
// valueOf; for example Date is coerced to a number. And, this returns an
3-
// iterable of subsets of the given index rather than a map.
1+
import {InternMap} from "d3-array";
2+
3+
// Like d3.group, but takes an array of values instead of accessor, only
4+
// supports one level of grouping, and returns an iterable of subsets of the
5+
// given index rather than a map.
46
export function group(index, values) {
5-
const groups = new Map();
7+
const groups = new InternMap();
68
for (const i of index) {
79
const value = values[i];
8-
const key = value !== null && typeof value === "object" ? value.valueOf() : value;
9-
const group = groups.get(key);
10-
if (group === undefined) groups.set(key, [i]);
10+
const group = groups.get(value);
11+
if (group === undefined) groups.set(value, [i]);
1112
else group.push(i);
1213
}
1314
return groups.values();

src/transforms/stack.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import {InternMap} from "d3-array";
12
import {valueof} from "../mark";
23

34
// TODO configurable series order
45
export function stackX(data, {x, y, ...options}) {
56
const X = valueof(data, x);
67
const Y = valueof(data, y);
78
const n = X.length;
8-
const X0 = new Map();
9+
const X0 = new InternMap();
910
const X1 = new Float64Array(n);
1011
const X2 = new Float64Array(n);
1112
for (let i = 0; i < n; ++i) {
12-
const k = Y[i] && Y[i].valueOf();
13+
const k = Y[i];
1314
const x1 = X1[i] = X0.has(k) ? X0.get(k) : 0;
1415
const x2 = X2[i] = x1 + +X[i];
1516
X0.set(k, isNaN(x2) ? x1 : x2);
@@ -22,11 +23,11 @@ export function stackY(data, {x, y, ...options}) {
2223
const X = valueof(data, x);
2324
const Y = valueof(data, y);
2425
const n = X.length;
25-
const Y0 = new Map();
26+
const Y0 = new InternMap();
2627
const Y1 = new Float64Array(n);
2728
const Y2 = new Float64Array(n);
2829
for (let i = 0; i < n; ++i) {
29-
const k = X[i] && X[i].valueOf();
30+
const k = X[i];
3031
const y1 = Y1[i] = Y0.has(k) ? Y0.get(k) : 0;
3132
const y2 = Y2[i] = y1 + +Y[i];
3233
Y0.set(k, isNaN(y2) ? y1 : y2);

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ cssstyle@^2.2.0:
326326
dependencies:
327327
cssom "~0.3.6"
328328

329-
d3-array@2, d3-array@>=2.5, d3-array@^2.3.0, d3-array@^2.8.0:
329+
d3-array@2, d3-array@>=2.5, d3-array@^2.10.0, d3-array@^2.3.0:
330330
version "2.10.0"
331331
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.10.0.tgz#dedf198fe55ea761d196ae40b15dd42e2deaf0b2"
332332
integrity sha512-TygE7/GvpL0092Pa/cS/kcyQ4E+I8KCkw3uCpQOFc4xi4IWNE67xST56H1Tz/FTYUqABULSEAmeLrGAmuLN8Xg==

0 commit comments

Comments
 (0)