1 | import { i as initRange } from "./init-cc95ec8e.js";
|
2 | class InternMap extends Map {
|
3 | constructor(entries, key = keyof) {
|
4 | super();
|
5 | Object.defineProperties(this, { _intern: { value: new Map() }, _key: { value: key } });
|
6 | if (entries != null)
|
7 | for (const [key2, value] of entries)
|
8 | this.set(key2, value);
|
9 | }
|
10 | get(key) {
|
11 | return super.get(intern_get(this, key));
|
12 | }
|
13 | has(key) {
|
14 | return super.has(intern_get(this, key));
|
15 | }
|
16 | set(key, value) {
|
17 | return super.set(intern_set(this, key), value);
|
18 | }
|
19 | delete(key) {
|
20 | return super.delete(intern_delete(this, key));
|
21 | }
|
22 | }
|
23 | function intern_get({ _intern, _key }, value) {
|
24 | const key = _key(value);
|
25 | return _intern.has(key) ? _intern.get(key) : value;
|
26 | }
|
27 | function intern_set({ _intern, _key }, value) {
|
28 | const key = _key(value);
|
29 | if (_intern.has(key))
|
30 | return _intern.get(key);
|
31 | _intern.set(key, value);
|
32 | return value;
|
33 | }
|
34 | function intern_delete({ _intern, _key }, value) {
|
35 | const key = _key(value);
|
36 | if (_intern.has(key)) {
|
37 | value = _intern.get(key);
|
38 | _intern.delete(key);
|
39 | }
|
40 | return value;
|
41 | }
|
42 | function keyof(value) {
|
43 | return value !== null && typeof value === "object" ? value.valueOf() : value;
|
44 | }
|
45 | const implicit = Symbol("implicit");
|
46 | function ordinal() {
|
47 | var index = new InternMap(), domain = [], range = [], unknown = implicit;
|
48 | function scale(d) {
|
49 | let i = index.get(d);
|
50 | if (i === void 0) {
|
51 | if (unknown !== implicit)
|
52 | return unknown;
|
53 | index.set(d, i = domain.push(d) - 1);
|
54 | }
|
55 | return range[i % range.length];
|
56 | }
|
57 | scale.domain = function(_) {
|
58 | if (!arguments.length)
|
59 | return domain.slice();
|
60 | domain = [], index = new InternMap();
|
61 | for (const value of _) {
|
62 | if (index.has(value))
|
63 | continue;
|
64 | index.set(value, domain.push(value) - 1);
|
65 | }
|
66 | return scale;
|
67 | };
|
68 | scale.range = function(_) {
|
69 | return arguments.length ? (range = Array.from(_), scale) : range.slice();
|
70 | };
|
71 | scale.unknown = function(_) {
|
72 | return arguments.length ? (unknown = _, scale) : unknown;
|
73 | };
|
74 | scale.copy = function() {
|
75 | return ordinal(domain, range).unknown(unknown);
|
76 | };
|
77 | initRange.apply(scale, arguments);
|
78 | return scale;
|
79 | }
|
80 | export {
|
81 | ordinal as o
|
82 | };
|