source: node_modules/d3-geo/src/path/index.js@ e4c61dd

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

Prototype 1.1

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import identity from "../identity.js";
2import stream from "../stream.js";
3import pathArea from "./area.js";
4import pathBounds from "./bounds.js";
5import pathCentroid from "./centroid.js";
6import PathContext from "./context.js";
7import pathMeasure from "./measure.js";
8import PathString from "./string.js";
9
10export default function(projection, context) {
11 let digits = 3,
12 pointRadius = 4.5,
13 projectionStream,
14 contextStream;
15
16 function path(object) {
17 if (object) {
18 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
19 stream(object, projectionStream(contextStream));
20 }
21 return contextStream.result();
22 }
23
24 path.area = function(object) {
25 stream(object, projectionStream(pathArea));
26 return pathArea.result();
27 };
28
29 path.measure = function(object) {
30 stream(object, projectionStream(pathMeasure));
31 return pathMeasure.result();
32 };
33
34 path.bounds = function(object) {
35 stream(object, projectionStream(pathBounds));
36 return pathBounds.result();
37 };
38
39 path.centroid = function(object) {
40 stream(object, projectionStream(pathCentroid));
41 return pathCentroid.result();
42 };
43
44 path.projection = function(_) {
45 if (!arguments.length) return projection;
46 projectionStream = _ == null ? (projection = null, identity) : (projection = _).stream;
47 return path;
48 };
49
50 path.context = function(_) {
51 if (!arguments.length) return context;
52 contextStream = _ == null ? (context = null, new PathString(digits)) : new PathContext(context = _);
53 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
54 return path;
55 };
56
57 path.pointRadius = function(_) {
58 if (!arguments.length) return pointRadius;
59 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
60 return path;
61 };
62
63 path.digits = function(_) {
64 if (!arguments.length) return digits;
65 if (_ == null) digits = null;
66 else {
67 const d = Math.floor(_);
68 if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
69 digits = d;
70 }
71 if (context === null) contextStream = new PathString(digits);
72 return path;
73 };
74
75 return path.projection(projection).digits(digits).context(context);
76}
Note: See TracBrowser for help on using the repository browser.