source: node_modules/d3-scale/src/ordinal.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import {InternMap} from "d3-array";
2import {initRange} from "./init.js";
3
4export const implicit = Symbol("implicit");
5
6export default function ordinal() {
7 var index = new InternMap(),
8 domain = [],
9 range = [],
10 unknown = implicit;
11
12 function scale(d) {
13 let i = index.get(d);
14 if (i === undefined) {
15 if (unknown !== implicit) return unknown;
16 index.set(d, i = domain.push(d) - 1);
17 }
18 return range[i % range.length];
19 }
20
21 scale.domain = function(_) {
22 if (!arguments.length) return domain.slice();
23 domain = [], index = new InternMap();
24 for (const value of _) {
25 if (index.has(value)) continue;
26 index.set(value, domain.push(value) - 1);
27 }
28 return scale;
29 };
30
31 scale.range = function(_) {
32 return arguments.length ? (range = Array.from(_), scale) : range.slice();
33 };
34
35 scale.unknown = function(_) {
36 return arguments.length ? (unknown = _, scale) : unknown;
37 };
38
39 scale.copy = function() {
40 return ordinal(domain, range).unknown(unknown);
41 };
42
43 initRange.apply(scale, arguments);
44
45 return scale;
46}
Note: See TracBrowser for help on using the repository browser.